home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnuawk.zip / vms / gawkmisc.vms < prev    next >
Text File  |  1996-10-20  |  3KB  |  122 lines

  1. /*
  2.  * gawkmisc.vms --- miscellanious gawk routines that are OS specific.
  3.  */
  4.  
  5. /* 
  6.  * Copyright (C) 1986, 1988, 1989, 1991-1996 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 2 of the License, or
  14.  * (at your option) 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 this program; if not, write to the Free Software
  23.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
  24.  */
  25.  
  26. char quote = '\'';
  27. char *defpath = DEFPATH;
  28. char envsep  = ',';
  29.  
  30. /* gawk_name --- pull out the "gawk" part from how the OS called us */
  31.  
  32. char *
  33. gawk_name(filespec)
  34. const char *filespec;
  35. {
  36.     char *p, *q;
  37.  
  38.     /* "device:[root.][directory.subdir]GAWK.EXE;n" -> "GAWK" */
  39.     p = strrchr(filespec, ']');  /* directory punctuation */
  40.     q = strrchr(filespec, '>');  /* alternate <international> punct */
  41.  
  42.     if (p == NULL || q > p)
  43.         p = q;
  44.     p = strdup(p == NULL ? filespec : (p + 1));
  45.     if ((q = strrchr(p, '.')) != NULL)
  46.         *q = '\0';  /* strip .typ;vers */
  47.  
  48.     return p;
  49. }
  50.  
  51. /* os_arg_fixup --- fixup the command line */
  52.  
  53. void
  54. os_arg_fixup(argcp, argvp)
  55. int *argcp;
  56. char ***argvp;
  57. {
  58.     (void) vms_arg_fixup(argcp, argvp);
  59. }
  60.  
  61. /* os_devopen --- open special per-OS devices */
  62.  
  63. int
  64. os_devopen(name, flag)
  65. const char *name;
  66. int flag;
  67. {
  68.     return vms_devopen(name, flag);
  69. }
  70.  
  71. /* optimal_bufsize --- determine optimal buffer size */
  72.  
  73. int
  74. optimal_bufsize(fd, stb)
  75. int fd;
  76. struct stat *stb;
  77. {
  78.  
  79.     /* force all members to zero in case OS doesn't use all of them. */
  80.     memset(stb, '\0', sizeof(struct stat));
  81.  
  82.     /*
  83.      * These values correspond with the RMS multi-block count used by
  84.      * vms_open() in vms/vms_misc.c.
  85.      */
  86.     if (isatty(fd) > 0)
  87.         return BUFSIZ;
  88.     else if (fstat(fd, stb) < 0)
  89.         return 8*512;    /* conservative in case of DECnet access */
  90.     else
  91.         return 32*512;
  92. }
  93.  
  94. /* ispath --- return true if path has directory components */
  95.  
  96. int
  97. ispath(file)
  98. const char *file;
  99. {
  100.     for (; *file; file++) {
  101.         switch (*file) {
  102.         case ':':
  103.         case ']':
  104.         case '>':
  105.         case '/':
  106.             return 1;
  107.         }
  108.     }
  109.     return 0;
  110. }
  111.  
  112. /* isdirpunct --- return true if char is a directory separator */
  113.  
  114. int
  115. isdirpunct(c)
  116. int c;
  117. {
  118.     return (strchr(":]>/", c) != NULL);
  119. }
  120.  
  121.  
  122.