Annotation of 43BSDTahoe/new/rcs/src/ident.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.