home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 1982, 1988, 1989 Walter Tichy
- Distributed under license by the Free Software Foundation, Inc.
-
- This file is part of RCS.
-
- RCS is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
- any later version.
-
- RCS is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with RCS; see the file COPYING. If not, write to
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
- Report problems and direct all questions to:
-
- rcs-bugs@cs.purdue.edu
-
- */
-
- /*
- * RCS identification operation
- */
- #ifndef lint
- static char rcsid[]=
- "$Header: /site/tmp/dosrcs/src/RCS/ident.c,v 5.3 90/07/15 20:23:52 lfk Release $Purdue CS";
- #endif
-
- /* $Log: ident.c,v $
- * Revision 5.3 90/07/15 20:23:52 lfk
- * Most major fixes added between rev 5.1 and rev 5.5:
- * signals fixed so they work on MS-DOS
- * Added MKS arguments code so argv can be large
- * added code to handle slashes a'la Unix
- * added more file extensions to system from MS-DOS
- *
- * Revision 5.2 90/07/15 11:31:31 ROOT_DOS
- * DOS version of RCS 4.0 checked in for MODS
- * by lfk@athena.mit.edu
- * Also update to MSC 6.0
- *
- * Revision 4.5 89/05/01 15:11:54 narten
- * changed copyright header to reflect current distribution rules
- *
- * Revision 4.4 87/10/23 17:09:57 narten
- * added exit(0) so exit return code would be non random
- *
- * Revision 4.3 87/10/18 10:23:55 narten
- * Updating version numbers. Changes relative to 1.1 are actually relative
- * to 4.1
- *
- * Revision 1.3 87/07/09 09:20:52 trinkle
- * Added check to make sure there is at least one arg before comparing argv[1]
- * with "-q". This necessary on machines that don't allow dereferncing null
- * pointers (i.e. Suns).
- *
- * Revision 1.2 87/03/27 14:21:47 jenkins
- * Port to suns
- *
- * Revision 1.1 84/01/23 14:50:03 kcs
- * Initial revision
- *
- * Revision 4.1 83/05/10 16:31:02 wft
- * Added option -q and input from reading stdin.
- * Marker matching is now done with trymatch() (independent of keywords).
- *
- * Revision 3.4 83/02/18 17:37:49 wft
- * removed printing of new line after last file.
- *
- * Revision 3.3 82/12/04 12:48:55 wft
- * Added LOCKER.
- *
- * Revision 3.2 82/11/28 18:24:17 wft
- * removed Suffix; added ungetc to avoid skipping over trailing KDELIM.
- *
- * Revision 3.1 82/10/13 15:58:51 wft
- * fixed type of variables receiving from getc() (char-->int).
- */
-
- #include "rcsbase.h"
- #define fflsbuf _flsbuf
- /* redefinition of _flsbuf in putc not needed */
- #ifndef lint
- static char rcsbaseid[] = RCSBASE;
- #endif
-
- extern enum markers trymatch();
-
- int quietflag;
-
- #ifdef MKS
- main(int argc, char *argv[], char *env[])
- #else
- main (argc, argv)
- int argc;
- char * argv[];
- #endif /* MKS */
- /* Ident searches the named files for all occurrences
- * of the pattern $keyword:...$, where the keywords are
- * Author, Date, Header, Id, Log, RCSfile, Revision, Source, and State.
- */
-
- {
- FILE *fp, *fopen();
- #ifdef MKS
- int z = 0;
- int ARGC = 0;
- char **tmp;
- char *env_name;
- # define MAXARGS 500 /* This means 500 items on the command line */
- if (!(tmp = (char **)malloc(sizeof(char *)*(MAXARGS+1)))) {
- fprintf(stderr, "%s: can't allocate space for arguments\n",argv[0]);
- exit(1);
- }
- for ( z = 0 ; env[z] != NULL; z++) { /* loop through environment */
- if (*env[z] == '~') { /* testing for entries begining with '~' */
- *++env[z]; /* increment pointer to delete '~' */
- tmp[ARGC++] = env[z]; /* add it to our new array */
- if (z >= MAXARGS) {
- fprintf(stderr, "%s: can't handle any more arguments\n", argv[0]);
- goto list;
- }
- }
- else if (*env[z] == '_') { /* testing for entries begining with _ */
- *++env[z] ; *++env[z]; /* move past the '_' and the '=' */
- env_name = env[z]; /* copy the name */
- }
- }
- list:
- if ( STREQ( (char *) argv[0] , env_name ) ) { /* test name against startup args */
- /* environment arguments meant for this program */
- # ifdef DEBUG
- printf("Using shell supplied args\n");
- # endif
- argc = ARGC;
- tmp[ARGC] = NULL; /* the terminal NULL */
- argv = tmp;
- }
- # ifdef DEBUG
- else
- printf("Using startup supplied args\n");
- # endif /* debug */
- #endif /* MKS */
-
- quietflag = false;
- if (argc > 1 && strcmp("-q",argv[1])==0) {
- quietflag = true;
- argc--; argv++;
- }
-
- if (argc<2) {
- if ((scanfile(stdin) == 0) && !quietflag)
- VOID fprintf(stderr, "ident warning: no id keywords in input\n");
- exit(0);
- }
-
- while ( --argc > 0 ) {
- #ifdef MSDOS
- if ( (fp = fopen(*++argv, "rb") ) == NULL ) {
- #else
- if ( (fp = fopen(*++argv, "r") ) == NULL ) {
- #endif
- VOID fprintf(stderr, "ident error: can't open %s\n", *argv);
- continue;
- } else {
- VOID printf( "%s:\n", *argv); /* print file name */
- if ((scanfile(fp) == 0) && !quietflag)
- VOID fprintf(stderr, "ident warning: no id keywords in %s\n", *argv);
- if (argc>1) putchar('\n');
- VOID fclose(fp);
- }
- }
- exit(0);
- }
-
-
- int scanfile(file)
- FILE * file;
- /* Function: scan an open file with descriptor file for keywords.
- * Returns the number of matches.
- */
- {
- register int matchcount;
- register int c;
-
-
- matchcount = 0;
- while( (c=getc(file)) != EOF) {
- if ( (char)c==KDELIM)
- matchcount += match(file);
- }
- return matchcount;
- }
-
-
-
- match(fp) /* group substring between two KDELIM's; then do pattern match */
- FILE *fp;
- {
- char line[keyvallength];
- register int c;
- register char * tp;
-
- tp = line;
- while( (c = getc(fp)) != KDELIM ) {
- *tp++ = c;
- if ( c==EOF || c=='\n' || tp>= line+keyvallength-2)
- return(0);
- }
- *tp++ = c; /*append trailing KDELIM*/
- *tp = '\0';
- if (trymatch(line,true)!=Nomatch) {
- VOID fprintf(stdout," $%s\n",line);
- return(1);
- } else {
- /* no match; put trailing KDELIM back into input */
- VOID ungetc(c,fp );
- return(0);
- }
- }
-