home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixlib_1 / !UnixLib37_netlib_netlib_c_readline < prev    next >
Encoding:
Text File  |  1996-07-28  |  898 b   |  53 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source$
  4.  * $Date$
  5.  * $Revision$
  6.  * $State$
  7.  * $Author$
  8.  *
  9.  * $Log$
  10.  ***************************************************************************/
  11.  
  12. static const char rcs_id[] = "$Id$";
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17.  
  18. #include <socketlib.h>
  19.  
  20. /*
  21.  * Read a line from a file, junking comments
  22.  */
  23. char *
  24. __socketlib_readline (FILE * file)
  25. {
  26.   static char line[256];
  27.  
  28.   char *hash;
  29.  
  30.   do
  31.     {
  32.       /* Read a line from the file */
  33.       if (fgets (line, 256, file) == NULL)
  34.     return NULL;
  35.  
  36.       /* Format the line */
  37.       if ((hash = strchr (line, '#')) != NULL)
  38.     {
  39.       /* Throw away any comments on the line */
  40.       *hash = '\0';
  41.     }
  42.       else
  43.     {
  44.       /* Remove the newline */
  45.       line[strlen (line) - 1] = '\0';
  46.     }
  47.     }
  48.   while (strlen (line) == 0);
  49.  
  50.   /* Return the line */
  51.   return line;
  52. }
  53.