home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OS9000 / APPS / rcs.lzh / rcs1 / ident.c < prev    next >
C/C++ Source or Header  |  1996-04-20  |  5KB  |  172 lines

  1. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  2.    Distributed under license by the Free Software Foundation, Inc.
  3.  
  4. This file is part of RCS.
  5.  
  6. RCS 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 1, or (at your option)
  9. any later version.
  10.  
  11. RCS 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 RCS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. Report problems and direct all questions to:
  21.  
  22.     rcs-bugs@cs.purdue.edu
  23.  
  24. */
  25.  
  26. /*
  27.  *                     RCS identification operation
  28.  */
  29. #ifndef lint
  30. static char rcsid[]=
  31. "$Id: ident.c_v 1.1 93/04/02 01:16:55 hiro Exp $Purdue CS";
  32. #endif
  33.  
  34. /* $Log:    ident.c_v $
  35.  * Revision 1.1  93/04/02  01:16:55  hiro
  36.  * Initial revision
  37.  * 
  38.  * Revision 1.1  90/07/19  15:20:05  momo
  39.  * Initial revision
  40.  * 
  41.  * Revision 4.5  89/05/01  15:11:54  narten
  42.  * changed copyright header to reflect current distribution rules
  43.  * 
  44.  * Revision 4.4  87/10/23  17:09:57  narten
  45.  * added exit(0) so exit return code would be non random
  46.  * 
  47.  * Revision 4.3  87/10/18  10:23:55  narten
  48.  * Updating version numbers. Changes relative to 1.1 are actually relative
  49.  * to 4.1
  50.  * 
  51.  * Revision 1.3  87/07/09  09:20:52  trinkle
  52.  * Added check to make sure there is at least one arg before comparing argv[1]
  53.  * with "-q".  This necessary on machines that don't allow dereferncing null
  54.  * pointers (i.e. Suns).
  55.  * 
  56.  * Revision 1.2  87/03/27  14:21:47  jenkins
  57.  * Port to suns
  58.  * 
  59.  * Revision 1.1  84/01/23  14:50:03  kcs
  60.  * Initial revision
  61.  * 
  62.  * Revision 4.1  83/05/10  16:31:02  wft
  63.  * Added option -q and input from reading stdin.
  64.  * Marker matching is now done with trymatch() (independent of keywords).
  65.  * 
  66.  * Revision 3.4  83/02/18  17:37:49  wft
  67.  * removed printing of new line after last file.
  68.  *
  69.  * Revision 3.3  82/12/04  12:48:55  wft
  70.  * Added LOCKER.
  71.  *
  72.  * Revision 3.2  82/11/28  18:24:17  wft
  73.  * removed Suffix; added ungetc to avoid skipping over trailing KDELIM.
  74.  *
  75.  * Revision 3.1  82/10/13  15:58:51  wft
  76.  * fixed type of variables receiving from getc() (char-->int).
  77. */
  78.  
  79. #include  "rcsbase.h"
  80. #define fflsbuf _flsbuf
  81. /* redefinition of _flsbuf in putc not needed */
  82. #ifndef lint
  83. static char rcsbaseid[] = RCSBASE;
  84. #endif
  85.  
  86. extern enum markers trymatch();
  87.  
  88. int quietflag;
  89.  
  90. main(argc, argv)
  91. int  argc; char  *argv[];
  92. /*  Ident searches the named files for all occurrences
  93.  *  of the pattern $keyword:...$, where the keywords are
  94.  *  Author, Date, Header, Id, Log, RCSfile, Revision, Source, and State.
  95.  */
  96.  
  97. {
  98.    FILE *fp, *fopen();
  99.  
  100.    quietflag = false;
  101.    if (argc > 1 && strcmp("-q",argv[1])==0) {
  102.         quietflag = true;
  103.         argc--; argv++;
  104.    }
  105.  
  106.    if (argc<2) {
  107.      if ((scanfile(stdin) == 0) && !quietflag)
  108.         VOID fprintf(stderr, "ident warning: no id keywords in input\n");
  109.     exit(0);
  110.    }
  111.  
  112.    while ( --argc > 0 ) {
  113.       if ( (fp = fopen(*++argv, "r") ) == NULL ) {
  114.          VOID fprintf(stderr,  "ident error: can't open %s\n", *argv);
  115.          continue;
  116.       } else {
  117.          VOID printf( "%s:\n", *argv);   /*  print file name  */
  118.      if ((scanfile(fp) == 0) && !quietflag)
  119.         VOID fprintf(stderr, "ident warning: no id keywords in %s\n", *argv);
  120.      if (argc>1) putchar('\n');
  121.      VOID fclose(fp);
  122.       }
  123.    }
  124.    exit(0);
  125. }
  126.  
  127.  
  128. int scanfile(file)
  129. FILE * file;
  130. /* Function: scan an open file with descriptor file for keywords.
  131.  * Returns the number of matches.
  132.  */
  133. {
  134.    register int matchcount;
  135.    register int c;
  136.  
  137.  
  138.    matchcount = 0;
  139.    while( (c=getc(file)) != EOF) {
  140.       if ( (char)c==KDELIM)
  141.      matchcount += match(file);
  142.    }
  143.    return matchcount;
  144. }
  145.  
  146.  
  147.  
  148. match(fp)   /* group substring between two KDELIM's; then do pattern match */
  149. FILE *fp;
  150. {
  151.    char line[keyvallength];
  152.    register int c;
  153.    register char * tp;
  154.  
  155.    tp = line;
  156.    while( (c = getc(fp)) != KDELIM ) {
  157.       *tp++ = c;
  158.       if ( c==EOF || c=='\n' || tp>= line+keyvallength-2)
  159.          return(0);
  160.    }
  161.    *tp++ = c;     /*append trailing KDELIM*/
  162.    *tp   = '\0';
  163.    if (trymatch(line,true)!=Nomatch) {
  164.         VOID fprintf(stdout,"     $%s\n",line);
  165.         return(1);
  166.    } else {
  167.       /* no match; put trailing KDELIM back into input */
  168.       VOID ungetc(c,fp );
  169.       return(0);
  170.    }
  171. }
  172.