1 #include <stdio.h>
2
main(int argc,char * argv[])3 int main(int argc, char *argv[])
4 {
5 char *date = argv[1];
6 char *fn = argv[2];
7 FILE *logfd;
8 char cmd[4096];
9 char buf[4096];
10 int gotrevmarker = 0;
11 int gotlocksline = 0;
12 int fileislocked = 0;
13
14 sprintf(cmd, "rlog \"-d>%s\" %s 2>/dev/null", date, fn);
15 logfd = popen(cmd, "r");
16 while (fgets(buf, sizeof(buf), logfd)) {
17 if (gotlocksline == 0) {
18 if (strncmp(buf, "locks:", 6) == 0) gotlocksline = 1;
19 }
20 else if (gotlocksline == 1) {
21 if (isspace(*buf)) fileislocked = 1;
22 gotlocksline = 2;
23 }
24
25 if (!gotrevmarker) {
26 gotrevmarker = (strcmp(buf, "----------------------------\n") == 0);
27 if (gotrevmarker) {
28 fprintf(stdout, "%s", fn);
29 if (fileislocked) fprintf(stdout, " (is being edited)");
30 fprintf(stdout, "\n");
31 fileislocked = 0;
32 }
33 }
34
35 if (gotrevmarker) fprintf(stdout, "%s", buf);
36 }
37 pclose(logfd);
38
39 if (fileislocked) {
40 /* Locked file, but we haven't shown anything yet */
41 fprintf(stdout, "%s", fn);
42 if (fileislocked) fprintf(stdout, " (is being edited)");
43 fprintf(stdout, "\n");
44 fprintf(stdout, "%s\n", "=============================================================================");
45 }
46
47 if (gotrevmarker || fileislocked) fprintf(stdout, "\n");
48
49 return 0;
50 }
51
52