home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / UUCPbb_2_1_src.lzh / UUCPBB21 / findent.c < prev    next >
Text File  |  1994-09-25  |  2KB  |  69 lines

  1. /*  findent.c   This routine tries to match a line in the passed file.
  2.     Copyright (C) 1990, 1993  Rick Adams and Bob Billson
  3.  
  4.     This file is part of the OS-9 UUCP package, UUCPbb.
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     The author of UUCPbb, Bob Billson, can be contacted at:
  21.     bob@kc2wz.bubble.org  or  uunet!kc2wz!bob  or  by snail mail:
  22.     21 Bates Way, Westfield, NJ 07090
  23. */
  24.  
  25. /* Find the first occurrence of a line in the passed file which matches 'key'.
  26.    TRUE is returned on success.  The matched line is put in the buffer pointed
  27.    by *line.  FALSE is returned if there is no match and the buffer contents
  28.    are undefined.  Lines beginning with a #, <space>, <tab> or <cr> character
  29.    are considered comment lines and ignored. */
  30.  
  31. #include "uucp.h"
  32.  
  33.  
  34. int findent (key, filename, line, length)
  35. char *key, *filename, *line;
  36. int length;
  37. {
  38.      char *p1, srchkey[80];
  39.      register char *p;
  40.      FILE *file;
  41.      int result = FALSE;
  42.  
  43.      if ((file = fopen (filename, "r")) == NULL)
  44.        {
  45.           printf ("findent: no file: %s\n", filename);          /* DEBUG */
  46.           return (FALSE);
  47.        }
  48.  
  49.      strcpy (srchkey, key);
  50.      p = line;
  51.      while (mfgets (p, length, file) != NULL)
  52.           if (ISCOMMENT (*p) == FALSE)
  53.             {
  54.                if ((p1 = strchr (p, ' ')) != NULL)
  55.                     *p1 = '\0';
  56.  
  57.                if (strcmp (p, srchkey) == 0)
  58.                  {
  59.                     if (p1 != NULL)
  60.                          *p1 = ' ';
  61.  
  62.                     result = TRUE;
  63.                     break;
  64.                  }
  65.             }
  66.      fclose (file);
  67.      return (result);
  68. }
  69.