char *whoami;
+int newfinger = 0;
main(argc, 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)
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);
}
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];
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) {
*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;
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;
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);
## 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);
##}