]> andersk Git - moira.git/commitdiff
changed argument parsing; how it decides to update finger info
authormar <mar>
Fri, 19 Jan 1990 14:31:10 +0000 (14:31 +0000)
committermar <mar>
Fri, 19 Jan 1990 14:31:10 +0000 (14:31 +0000)
regtape/students.dc

index 11a3154d8ebf4e0f61167acc7355c73dd02fedb1..1edc53f99dfe590d91854b45ca1342c24804991d 100644 (file)
@@ -73,6 +73,7 @@ struct entry {
 
 
 char *whoami;
+int newfinger = 0;
 
 
 main(argc, argv)
@@ -81,8 +82,8 @@ char **argv;
 ##{
     FILE *in;
     struct entry *e, *get_next_entry();
-    int status, wait = 0;
-    char buf[BUFSIZ];
+    int i, wait = 0;
+    char buf[BUFSIZ], *file = NULL;
 
     whoami = rindex(argv[0], '/');
     if (whoami)
@@ -90,12 +91,22 @@ char **argv;
     else
       whoami = argv[0];
 
-    if (argc > 2)
-      wait++;
+    for (i = 1; i < argc; i++) {
+       if (!strcmp(argv[i], "-w"))
+         wait++;
+       else if (!strcmp(argv[i], "-D"))
+         setenv("ING_SET", "set printqry");
+       else if (!strcmp(argv[i], "-n"))
+         newfinger++;
+       else if (file != NULL)
+         fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
+       else
+         file = argv[i];
+    }
 
-    in = fopen(argv[1], "r");
+    in = fopen(file, "r");
     if (in == NULL) {
-       fprintf(stderr, "Unable to open %s for input\n", argv[1]);
+       fprintf(stderr, "Unable to open %s for input\n", file);
        exit(1);
     }
 
@@ -198,7 +209,7 @@ FILE *in;
 process_entry(e)
 struct entry *e;
 ##{
-    int status, changed;
+    int changed, nochange;
     char buf[BUFSIZ], *from, *to;
 ##  char *first, *last, *eid;
 ##  char class[9], haddr[81], hphone[17], ophone[13], dept[13];
@@ -217,13 +228,14 @@ struct entry *e;
        return;
     }
     if (strcmp(e->class, strtrim(class))) {
-       com_err(whoami, 0, "updating class for user %s %s", first, last);
+       com_err(whoami, 0, "updating class for user %s %s from %s to %s",
+               first, last, class, e->class);
        strcpy(class, e->class);
 ##     repeat replace u (mit_year = @class,
 ##                modtime = "now", modby = WHO, modwith = PROG)
 ##         where u.users_id = id
     }
-    changed = 0;
+    changed = nochange = 0;
     strcpy(buf, strtrim(e->address));
     e->dorm = strtrim(e->dorm);
     if (*e->dorm) {
@@ -245,9 +257,18 @@ struct entry *e;
       *to = ';';
     while (to = index(buf, ':'))
       *to = ';';
-    if (strncmp(strtrim(haddr), buf, 80)) {
-       changed++;
+    if (newfinger) {
+       if (haddr[0] == ' ') {
+           strncpy(haddr, buf, 80);
+           haddr[80] = 0;
+           changed++;
+       } else if (strncmp(strtrim(haddr), buf, 80))
+         nochange++;
+    } else {
+       if (strncmp(strtrim(haddr), buf, 80))
+         changed++;
        strncpy(haddr, buf, 80);
+       haddr[80] = 0;
     }
     from = e->dphone;
     to = buf;
@@ -257,9 +278,17 @@ struct entry *e;
        from++;
     }
     *to = 0;
-    if (strncmp(strtrim(hphone), buf, 16)) {
-       changed++;
+    if (newfinger) {
+       if (hphone[0] == ' ') {
+           strncpy(hphone, buf, 16);
+           hphone[16] = 0;
+       } else if (strncmp(strtrim(hphone), buf, 16))
+         nochange++;
+    } else {
+       if (strncmp(strtrim(hphone), buf, 16))
+         changed++;
        strncpy(hphone, buf, 16);
+       hphone[16] = 0;
     }
     from = e->mphone;
     to = buf;
@@ -269,14 +298,30 @@ struct entry *e;
        from++;
     }
     *to = 0;
-    if (strncmp(strtrim(ophone), buf, 12)) {
-       changed++;
+    if (newfinger) {
+       if (ophone[0] == ' ') {
+           strncpy(ophone, buf, 12);
+           ophone[12] = 0;
+       } else if (strncmp(strtrim(ophone), buf, 12))
+         nochange++;
+    } else {
+       if (strncmp(strtrim(ophone), buf, 12))
+         changed++;
        strncpy(ophone, buf, 12);
+       ophone[12] = 0;
     }
     e->course = strtrim(e->course);
-    if (strncmp(strtrim(dept), e->course, 12)) {
-       changed++;
+    if (newfinger) {
+       if (dept[0] == ' ') {
+           strncpy(dept, e->course, 12);
+           dept[12] = 0;
+       } else if (strncmp(strtrim(dept), e->course, 11))
+         nochange++;
+    } else {
+       if (strncmp(strtrim(dept), e->course, 11))
+         changed++;
        strncpy(dept, e->course, 12);
+       dept[12] = 0;
     }
     if (changed) {
        com_err(whoami, 0, "updating finger for %s %s", first, last);
@@ -284,7 +329,8 @@ struct entry *e;
 ##                office_phone = @ophone, #mit_dept = @dept,
 ##                fmodtime = "now", fmodby = WHO, fmodwith = PROG)
 ##         where u.users_id = @id
-    }
+    } else if (nochange)
+      com_err(whoami, 0, "NOT updating finger for %s %s", first, last);
 ##}
 
 
This page took 0.048961 seconds and 5 git commands to generate.