home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gnat-2.06-src.tgz / tar.out / fsf / gnat / ada / a-sysdep.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  8KB  |  202 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                         GNAT COMPILER COMPONENTS                         */
  4. /*                                                                          */
  5. /*                              A - S Y S D E P                             */
  6. /*                                                                          */
  7. /*                          C Implementation File                           */
  8. /*                                                                          */
  9. /*                            $Revision: 1.11 $                             */
  10. /*                                                                          */
  11. /*        Copyright (c) 1992,1993,1994,1995 NYU, All Rights Reserved        */
  12. /*                                                                          */
  13. /* The GNAT library is free software; you can redistribute it and/or modify */
  14. /* it under terms of the GNU Library General Public License as published by */
  15. /* the Free Software  Foundation; either version 2, or (at your option) any */
  16. /* later version.  The GNAT library is distributed in the hope that it will */
  17. /* be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty */
  18. /* of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU */
  19. /* Library  General  Public  License for  more  details.  You  should  have */
  20. /* received  a copy of the GNU  Library  General Public License  along with */
  21. /* the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free */
  22. /* Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        */
  23. /*                                                                          */
  24. /****************************************************************************/
  25.  
  26. /* This file contains system dependent symbols that are referenced in the
  27.    GNAT Run Time Library */
  28.  
  29. #include "config.h"
  30.  
  31. #ifdef WINNT
  32. #include <fcntl.h>
  33. #include <sys/types.h>
  34. #include <sys/stat.h>
  35. #include <errno.h>
  36. #endif
  37.  
  38. #include <stdio.h>
  39.  
  40. /*
  41.    mode_read_text
  42.    open text file for reading
  43.    rt for DOS and Windows NT, r for Unix
  44.  
  45.    mode_write_text
  46.    truncate to zero length or create text file for writing
  47.    wt for DOS and Windows NT, w for Unix
  48.  
  49.    mode_append_text
  50.    append; open or create text file for writing at end-of-file
  51.    at for DOS and Windows NT, a for Unix
  52.  
  53.    mode_read_binary
  54.    open binary file for reading
  55.    rb for DOS and Windows NT, r for Unix
  56.  
  57.    mode_write_binary
  58.    truncate to zero length or create binary file for writing
  59.    wb for DOS and Windows NT, w for Unix
  60.  
  61.    mode_append_binary
  62.    append; open or create binary file for writing at end-of-file
  63.    ab for DOS and Windows NT, a for Unix
  64.  
  65.    mode_read_text_plus
  66.    open text file for update (reading and writing)
  67.    r+t for DOS and Windows NT, r+ for Unix
  68.  
  69.    mode_write_text_plus
  70.    truncate to zero length or create text file for update
  71.    w+t for DOS and Windows NT, w+ for Unix
  72.  
  73.    mode_append_text_plus
  74.    append; open or create text file for update, writing at end-of-file
  75.    a+t for DOS and Windows NT, a+ for Unix
  76.  
  77.    mode_read_binary_plus
  78.    open binary file for update (reading and writing)
  79.    r+b for DOS and Windows NT, r+ for Unix
  80.  
  81.    mode_write_binary_plus
  82.    truncate to zero length or create binary file for update
  83.    w+b for DOS and Windows NT, w+ for Unix
  84.  
  85.    mode_append_binary_plus
  86.    append; open or create binary file for update, writing at end-of-file
  87.    a+b for DOS and Windows NT, a+ for Unix
  88.  
  89.    Notes:
  90.  
  91.    (1) Opening a file with read mode fails if the file does not exist or
  92.    cannot be read.
  93.  
  94.    (2) Opening a file with append mode causes all subsequent writes to the
  95.    file to be forced to the then current end-of-file, regardless of
  96.    intervening calls to the fseek function.
  97.  
  98.    (3) When a file is opened with update mode, both input and output may be
  99.    performed on the associated stream.  However, output may not be directly
  100.    followed by input without an intervening call to the fflush function or
  101.    to a file positioning function (fseek, fsetpos, or rewind), and input
  102.    may not be directly followed by output without an intervening call to a
  103.    file positioning function, unless the input operation encounters
  104.    end-of-file.
  105.  
  106.    The other target dependent declarations here are for the two functions
  107.    set_binary_mode and set_text_mode:
  108.  
  109.       void set_binary_mode (int handle);
  110.       void set_text_mode   (int handle);
  111.  
  112.    These functions have no effect in Unix (or similar systems where there is
  113.    no distinction between binary and text files), but in DOS (and similar
  114.    systems where text mode does CR/LF translation), these functions allow
  115.    the mode of the stream with the given handle (fileno can be used to get
  116.    the handle of a stream) to be changed dynamically. The returned result
  117.    is 0 if no error occurs and -1 if an error occurs.
  118.  
  119.    Finally there is a boolean (character) variable
  120.  
  121.       char text_translation_required;
  122.  
  123.    which is zero (false) in Unix mode, and one (true) in DOS mode, with a
  124.    true value indicating that text translation is required on text files
  125.    and that fopen supports the trailing t and b modifiers.
  126.  
  127. */
  128.  
  129. #if defined(WINNT) || defined (MSDOS) || defined (__EMX__)
  130.  
  131.   const char *mode_read_text = "rt";
  132.   const char *mode_write_text = "wt";
  133.   const char *mode_append_text = "at";
  134.   const char *mode_read_binary = "rb";
  135.   const char *mode_write_binary = "wb";
  136.   const char *mode_append_binary = "ab";
  137.   const char *mode_read_text_plus = "r+t";
  138.   const char *mode_write_text_plus = "w+t";
  139.   const char *mode_append_text_plus = "a+t";
  140.   const char *mode_read_binary_plus = "r+b";
  141.   const char *mode_write_binary_plus = "w+b";
  142.   const char *mode_append_binary_plus = "a+b";
  143.   const char text_translation_required = 1;
  144.  
  145.   /* for now these functions do nothing, must be fixed later ??? */
  146.   void set_binary_mode (int handle) { ; }
  147.   void set_text_mode   (int handle) { ; }
  148.  
  149. #else
  150.   const char *mode_read_text = "r";
  151.   const char *mode_write_text = "w";
  152.   const char *mode_append_text = "a";
  153.   const char *mode_read_binary = "r";
  154.   const char *mode_write_binary = "w";
  155.   const char *mode_append_binary = "a";
  156.   const char *mode_read_text_plus = "r+";
  157.   const char *mode_write_text_plus = "w+";
  158.   const char *mode_append_text_plus = "a+";
  159.   const char *mode_read_binary_plus = "r+";
  160.   const char *mode_write_binary_plus = "w+";
  161.   const char *mode_append_binary_plus = "a+";
  162.   const char text_translation_required = 0;
  163.  
  164.   /* these functions do nothing in non-DOS systems */
  165.   void set_binary_mode (FILE *stream) { ; }
  166.   void set_text_mode   (FILE *stream) { ; }
  167.  
  168. #endif
  169.  
  170. /* the following definitions are provided in NT to support Windows based
  171.    Ada programs */
  172.  
  173. #ifdef WINNT
  174.  
  175. #include <windows.h>                /* required for all Windows applications */
  176.  
  177. HANDLE hInstance_global;            /* current instance                      */
  178. HANDLE hPrevInstance_global;        /* previous instance            */
  179. LPSTR lpCmdLine_global;             /* command line                 */
  180. int nCmdShow_global;                /* show-window type (open/icon) */
  181.  
  182. extern int __argc;
  183. extern char **__argv;
  184. extern char **environ;
  185.  
  186. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  187. HANDLE hInstance;                   /* current instance             */
  188. HANDLE hPrevInstance;               /* previous instance            */
  189. LPSTR lpCmdLine;                    /* command line                 */
  190. int nCmdShow;                       /* show-window type (open/icon) */
  191. {
  192.  
  193.   hInstance_global = hInstance;
  194.   hPrevInstance_global = hPrevInstance;
  195.   lpCmdLine_global = lpCmdLine;
  196.   nCmdShow_global = nCmdShow;
  197.  
  198.   return main (__argc, __argv);  /* Should return value from PostQuitMessage */
  199. }
  200.  
  201. #endif /* WINNT */
  202.