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

  1. /*
  2.  * gawkmisc.c --- miscellanious gawk routines that are OS specific.
  3.  */
  4.  
  5. /* 
  6.  * Copyright (C) 1986, 1988, 1989, 1991 - 96 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 envsep  = ';';
  28. #ifdef DEFPATH
  29. char *defpath = DEFPATH;
  30. #else
  31. char *defpath = ".;c:\\lib\\awk;c:\\gnu\\lib\\awk";
  32. #endif
  33.  
  34. /* gawk_name --- pull out the "gawk" part from how the OS called us */
  35.  
  36. char *
  37. gawk_name(filespec)
  38. const char *filespec;
  39. {
  40.     char *p, *q;
  41.  
  42.     p = (char *) filespec;  /* Sloppy... */
  43.  
  44.     /* OS/2 allows / for directory separator too */
  45.     if ((q = strrchr(p, '\\')) != NULL)
  46.         p = q + 1;
  47.     if ((q = strrchr(p, '/')) != NULL)
  48.         p = q + 1;
  49.     if ((q = strchr(p, '.')) != NULL)
  50.         *q = '\0';
  51.     return strlwr(p);
  52. }
  53.  
  54. /* os_arg_fixup --- fixup the command line */
  55.  
  56. void
  57. os_arg_fixup(argcp, argvp)
  58. int *argcp;
  59. char ***argvp;
  60. {
  61. #ifdef __EMX__
  62.     _response(argcp, argvp);
  63.     _wildcard(argcp, argvp);
  64.     setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
  65. #endif
  66.     return;
  67. }
  68.  
  69. /* os_devopen --- open special per-OS devices */
  70.  
  71. int
  72. os_devopen(name, flag)
  73. const char *name;
  74. int flag;
  75. {
  76.     /* no-op */
  77.     return -1;
  78. }
  79.  
  80. /* optimal_bufsize --- determine optimal buffer size */
  81.  
  82. int
  83. optimal_bufsize(fd, stb)
  84. int fd;
  85. struct stat *stb;
  86. {
  87.     /* force all members to zero in case OS doesn't use all of them. */
  88.     memset(stb, '\0', sizeof(struct stat));
  89.  
  90.     /*
  91.      * DOS doesn't have the file system block size in the
  92.      * stat structure. So we have to make some sort of reasonable
  93.      * guess. We use stdio's BUFSIZ, since that is what it was
  94.      * meant for in the first place.
  95.      */
  96. #define    DEFBLKSIZE    BUFSIZ
  97.  
  98.     if (isatty(fd))
  99.         return BUFSIZ;
  100.     if (fstat(fd, stb) == -1)
  101.         fatal("can't stat fd %d (%s)", fd, strerror(errno));
  102.     if (lseek(fd, (off_t)0, 0) == -1)    /* not a regular file */
  103.         return DEFBLKSIZE;
  104.     if (stb->st_size > 0 && stb->st_size < DEFBLKSIZE) /* small file */
  105.         return stb->st_size;
  106.     return DEFBLKSIZE;
  107. }
  108.  
  109. /* ispath --- return true if path has directory components */
  110.  
  111. int
  112. ispath(file)
  113. const char *file;
  114. {
  115.     for (; *file; file++) {
  116.         switch (*file) {
  117.         case '/':
  118.         case '\\':
  119.         case ':':
  120.             return 1;
  121.         }
  122.     }
  123.     return 0;
  124. }
  125.  
  126. /* isdirpunct --- return true if char is a directory separator */
  127.  
  128. int
  129. isdirpunct(c)
  130. int c;
  131. {
  132.     return (strchr(":\\/", c) != NULL);
  133. }
  134.  
  135.