home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gawk213s.lzh / GAWK213S / VMS_MISC.C < prev    next >
C/C++ Source or Header  |  1993-07-29  |  5KB  |  160 lines

  1. /*
  2.  * vms_misc.c -- sustitute code for missing/different run-time library routines.
  3.  */
  4.  
  5. /* 
  6.  * Copyright (C) 1991 the Free Software Foundation, Inc.
  7.  * 
  8.  * This file is part of GAWK, the GNU implementation of the
  9.  * AWK Progamming Language.
  10.  * 
  11.  * GAWK is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 1, or (at your option)
  14.  * any later version.
  15.  * 
  16.  * GAWK is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  * 
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with GAWK; see the file COPYING.  If not, write to
  23.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25.  
  26. #include "awk.h"        /* really "../awk.h" */
  27. #include <ssdef.h>
  28. #include <stsdef.h>
  29.  
  30.     /*
  31.      * VMS uses a completely different status scheme (odd => success,
  32.      * even => failure), so we'll trap calls to exit() and alter the
  33.      * exit status code.  [VAXC can't handle this as a macro.]
  34.      */
  35. #ifdef exit
  36. # undef exit
  37. #endif
  38. void
  39. vms_exit( int errno )        /* note: local override of global 'errno' */
  40. {
  41.     exit(errno == 0 ? SS$_NORMAL : (SS$_ABORT | STS$M_INHIB_MSG));
  42. }
  43. #define exit(v) vms_exit(v)
  44.  
  45.     /*
  46.      * In VMS's VAXCRTL, strerror() takes an optional second argument.
  47.      *  #define strerror(errnum) strerror(errnum,vaxc$errno)
  48.      * is all that's needed, but VAXC can't handle that (gcc can).
  49.      * [The 2nd arg is used iff errnum == EVMSERR.]
  50.      */
  51. #ifdef strerror
  52. # undef strerror
  53. #endif
  54. /* vms_strerror() -- convert numeric error code into text string */
  55. char *
  56. vms_strerror( int errnum )
  57. {
  58.     extern char *strerror( /* int, ... */ );
  59.     return ( errnum != EVMSERR ? strerror(errnum)
  60.                    : strerror(EVMSERR, vaxc$errno) );
  61. }
  62. # define strerror(v) vms_strerror(v)
  63.  
  64.     /*
  65.      * Miscellaneous utility routine, not part of the run-time library.
  66.      */
  67. /* vms_strdup() - allocate some new memory and copy a string into it */
  68. char *
  69. vms_strdup( const char *str )
  70. {
  71.     char *result;
  72.     int len = strlen(str);
  73.  
  74.     emalloc(result, char *, len+1, "strdup");
  75.     return strcpy(result, str);
  76. }
  77.  
  78.     /*
  79.      * VAXCRTL does not contain unlink().  This replacement has limited
  80.      * functionality which is sufficient for GAWK's needs.  It works as
  81.      * desired even when we have the file open.
  82.      */
  83. /* unlink(file) -- delete a file (ignore soft links) */
  84. int
  85. unlink( const char *file_spec ) {
  86.     char tmp[255+1];            /*(should use alloca(len+2+1)) */
  87.     extern int delete(const char *);
  88.  
  89.     strcpy(tmp, file_spec);        /* copy file name */
  90.     if (strchr(tmp, ';') == NULL)
  91.     strcat(tmp, ";0");        /* append version number */
  92.     return delete(tmp);
  93. }
  94.  
  95.     /*
  96.      * Check for attempt to (re-)open known file.
  97.      */
  98. /* vms_devopen() - check for "SYS$INPUT" or "SYS$OUTPUT" or "SYS$ERROR" */
  99. int
  100. vms_devopen( const char *name )
  101. {
  102.     FILE *file = NULL;
  103.  
  104.     if (strncasecmp(name, "SYS$", 4) == 0) {
  105.     name += 4;        /* skip "SYS$" */
  106.     if (strncasecmp(name, "INPUT", 5) == 0)
  107.         file = stdin,  name += 5;
  108.     else if (strncasecmp(name, "OUTPUT", 6) == 0)
  109.         file = stdout,  name += 6;
  110.     else if (strncasecmp(name, "ERROR", 5) == 0)
  111.         file = stderr,  name += 5;
  112.     if (*name == ':')  name++;    /* treat trailing colon as optional */
  113.     }
  114.     /* note: VAXCRTL stdio has extra level of indirection (*file) */
  115.     return (file && *file && *name == '\0') ? fileno(file) : -1;
  116. }
  117.  
  118.     /*
  119.      * VMS has no timezone support.
  120.      */
  121. /* these are global for use by missing/strftime.c */
  122. char   *tzname[2] = { "local", "" };
  123. int     daylight = 0;
  124.  
  125. /* dummy to satisfy linker */
  126. void tzset()
  127. {
  128.     return;
  129. }
  130.  
  131. #ifndef __GNUC__
  132. # ifdef bcopy
  133. #  undef bcopy
  134. # endif
  135. void bcopy( char *src, char *dst, int len )
  136. {
  137.     (void) OTS$MOVE3(len, src, dst);
  138. }
  139. #endif    /*!__GNUC__*/
  140.  
  141. /*----------------------------------------------------------------------*/
  142. #ifdef NO_VMS_ARGS      /* real code is in "vms/vms_args.c" */
  143. void vms_arg_fixup( int *argc, char ***argv ) { return; }    /* dummy */
  144. #endif
  145.  
  146. #ifdef NO_VMS_PIPES     /* real code is in "vms/vms_popen.c" */
  147. FILE *popen( const char *command, const char *mode ) {
  148.     fatal(" Cannot open pipe `%s' (not implemented)", command);
  149.     return NULL;
  150. }
  151. int pclose( FILE *current ) {
  152.     fatal(" Cannot close pipe #%d (not implemented)", fileno(current));
  153.     return -1;
  154. }
  155. int fork( void ) {
  156.     fatal(" Cannot fork process (not implemented)");
  157.     return -1;
  158. }
  159. #endif /*NO_VMS_PIPES*/
  160.