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

  1. /*
  2.  * gawkmisc.atr --- 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. #include <string.h>
  27.  
  28. char quote = '\'';
  29. #ifndef DEFPATH
  30. char *defpath = ".,c:\\lib\\awk,c:\\gnu\\lib\\awk";
  31. #else
  32. char *defpath = DEFPATH;
  33. #endif
  34. char envsep  = ',';
  35.  
  36.  
  37. /* gawk_name --- pull out the "gawk" part from how the OS called us */
  38.  
  39. char *
  40. gawk_name(filespec)
  41. const char *filespec;
  42. {
  43.     char *p, *q;
  44.  
  45.     p = (char *)filespec;
  46.  
  47.     if ((q = strrchr(p, '\\')) != NULL)
  48.         p = q + 1;
  49.     if ((q = strrchr(p, '/')) != NULL)
  50.         p = q + 1;
  51.     if ((q = strchr(p, '.')) != NULL)
  52.         *q = '\0';
  53.     strlwr(p);
  54.  
  55.     return (p == NULL ? (char *)filespec : (char *)p);
  56. }
  57.  
  58. /* os_arg_fixup --- fixup the command line */
  59.  
  60. void
  61. os_arg_fixup(argcp, argvp)
  62. int *argcp;
  63. char ***argvp;
  64. {
  65.     /* no-op */
  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 INVALID_HANDLE;
  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.     /* The atari has the st_blksize structure, so we just use it. */
  91. #define DEFBLKSIZE    (stb->st_blksize ? stb->st_blksize : BUFSIZ)
  92.  
  93.     /*
  94.      * On ST redirected stdin does not have a name attached
  95.      * (this could be hard to do to) and fstat would fail
  96.      */
  97.     if (fd == 0 || isatty(fd))
  98.         return BUFSIZ;
  99.     if (fstat(fd, stb) == -1)
  100.         fatal("can't stat fd %d (%s)", fd, strerror(errno));
  101.     if (lseek(fd, (off_t)0, 0) == -1)    /* not a regular file */
  102.         return DEFBLKSIZE;
  103.     if (stb->st_size > 0 && stb->st_size < DEFBLKSIZE) /* small file */
  104.         return stb->st_size;
  105.     return DEFBLKSIZE;
  106. }
  107.  
  108. /* ispath --- return true if path has directory components */
  109.  
  110. int
  111. ispath(file)
  112. const char *file;
  113. {
  114.     return (strchr(file, '/') != NULL || strchr(file, '\\') != NULL);
  115. }
  116.  
  117. /* isdirpunct --- return true if char is a directory separator */
  118.  
  119. int
  120. isdirpunct(c)
  121. int c;
  122. {
  123.     return (c == '/' || c == '\\');
  124. }
  125.