Annotation of 43BSDReno/contrib/rcs/src/ident.c, revision 1.1

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

unix.superglobalmegacorp.com

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