home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / FALCON / ACC / OUTLINE.ACC / FILEIO.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  1.1 KB  |  65 lines

  1. /* fileio.c - i/o routines for extend.sys parser
  2.  * 900814 kbad
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <ctype.h>
  8. #include <ext.h>
  9.  
  10. #include "fileio.h"
  11.  
  12. static FILE    *infile;
  13.  
  14.  
  15. /*
  16.  * Open input file if input is not redirected.
  17.  */
  18. void
  19. xopen( char *name )
  20. {
  21.     if( !isatty( stdin->Handle ) )
  22.     {
  23.     infile = stdin;
  24.     }
  25.     else
  26.     {
  27.     infile = fopen( name, "r" );
  28.     }
  29. }
  30.  
  31. /*
  32.  * Get a line of up to LINE_MAX-1 chars from input file,
  33.  * convert all uppercase characters to lowercase,
  34.  * and discard chars beyond LINE_MAX-1.
  35.  * Return string in 'buf', with newline discarded.
  36.  */
  37. char *
  38. xgets( char *buf )
  39. {
  40.     char *s, *nl, temp[LINE_MAX];
  41.  
  42.     if( (s = fgets(buf, LINE_MAX, infile)) == NULL )
  43.     return NULL;
  44.  
  45.     nl = s;
  46.     while( *s && *s != '\n')
  47.     *nl++ = (isalpha(*s)) ? tolower(*s++) : *s++;
  48.     *nl++ = '\0';
  49.  
  50.     if( *s == '\n' )
  51.     while( (nl = fgets(temp, LINE_MAX, infile)) != NULL )
  52.     /* dump remainder of line */;
  53.  
  54.     return buf;
  55. }
  56.  
  57. void
  58. xclose( void )
  59. {
  60.     fclose( infile );
  61.     errno = 0;
  62. }
  63.  
  64.  
  65.