Sync usage with man page.
[netbsd-mini2440.git] / usr.bin / rcs / src / snoop.c
blobae78efc629735cd37e6aef109ad8aa6c7f4d9dd2
1 /*
2 * Logging of RCS commands co and ci
3 */
4 #ifndef lint
5 static char rcsid[]=
6 "$Header: /pub/NetBSD/misc/repositories/cvsroot/src/usr.bin/rcs/src/Attic/snoop.c,v 1.1 1993/03/21 09:58:10 cgd Exp $ Purdue CS";
7 #endif
8 /*******************************************************************
9 * This program appends argv[1] to the file SNOOPFILE.
10 * To avoid overlaps, it creates a lockfile with name lock in the same
11 * directory as SNOOPFILE. SNOOPFILE must be defined in the cc command.
12 * Prints an error message if lockfile doesn't get deleted after
13 * MAXTRIES tries.
14 *******************************************************************
17 /* Copyright (C) 1982, 1988, 1989 Walter Tichy
18 * All rights reserved.
20 * Redistribution and use in source and binary forms are permitted
21 * provided that the above copyright notice and this paragraph are
22 * duplicated in all such forms and that any documentation,
23 * advertising materials, and other materials related to such
24 * distribution and use acknowledge that the software was developed
25 * by Walter Tichy.
26 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 * Report all problems and direct all questions to:
31 * rcs-bugs@cs.purdue.edu
43 /* $Log: snoop.c,v $
44 * Revision 4.4 89/05/01 15:14:00 narten
45 * changed copyright header to reflect current distribution rules
47 * Revision 4.3 87/12/18 11:46:52 narten
48 * more lint cleanups (Guy Harris)
50 * Revision 4.2 87/10/18 10:41:47 narten
51 * Changing version numbers. Changes relative to 1.1 actually relative to
52 * 4.1
54 * Revision 1.2 87/09/24 14:01:41 narten
55 * Sources now pass through lint (if you ignore printf/sprintf/fprintf
56 * warnings)
58 * Revision 1.1 84/01/23 14:50:49 kcs
59 * Initial revision
61 * Revision 4.1 83/03/28 13:23:42 wft
62 * No change; just new revision number.
64 * Revision 3.2 82/12/04 17:14:31 wft
65 * Added rcsbase.h, changed SNOOPDIR to SNOOPFILE, reintroduced
66 * error message in case of permanent locking.
68 * Revision 3.1 82/10/18 21:22:03 wft
69 * Number of polls now 20, no error message if critical section can't
70 * be entered.
72 * Revision 2.3 82/07/01 23:49:28 wft
73 * changed copyright notice only.
75 * Revision 2.2 82/06/03 20:00:10 wft
76 * changed name from rcslog to snoop, replaced LOGDIR with SNOOPDIR.
78 * Revision 2.1 82/05/06 17:55:54 wft
79 * Initial revision
84 #include "rcsbase.h"
85 #ifdef _FSTDIO
86 #undef putc
87 #define putc __sputc
88 #define fflsbuf _flsbuf
89 #endif
90 /* undo redefinition of putc in rcsbase.h */
92 char lockfname[NCPPN];
93 FILE * logfile;
94 int lockfile;
96 #define MAXTRIES 20
98 main(argc,argv)
99 int argc; char * argv[];
100 /* writes argv[1] to SNOOPFILE and appends a newline. Invoked as follows:
101 * rcslog logmessage
103 { int tries;
104 register char * lastslash, *sp;
106 VOID strcpy(lockfname,(char *) SNOOPFILE);
107 lastslash = sp = lockfname;
108 while (*sp) if (*sp++ =='/') lastslash=sp; /* points beyond / */
109 VOID strcpy(lastslash,",lockfile");
110 tries=0;
111 while (((lockfile=creat(lockfname, 000)) == -1) && (tries<=MAXTRIES)) {
112 tries++;
113 sleep(5);
115 if (tries<=MAXTRIES) {
116 VOID close(lockfile);
117 if ((logfile=fopen(SNOOPFILE,"a")) ==NULL) {
118 VOID fprintf(stderr,"Can't open logfile %s\n",SNOOPFILE);
119 } else {
120 VOID fputs(argv[1],logfile);
121 VOID putc('\n',logfile);
122 VOID fclose(logfile);
124 VOID unlink(lockfname);
125 } else {
126 VOID fprintf(stderr,"RCS logfile %s seems permanently locked.\n",SNOOPFILE);
127 VOID fprintf(stderr,"Please alert system administrator\n");