X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/3f25f0f55bc447ad02999f26da36bde90190a411..564ed5a8e2cbe2868f33e0e28e55aaac1e047b8e:/gen/letter.dc diff --git a/gen/letter.dc b/gen/letter.dc index adb9044c..1ab107fd 100644 --- a/gen/letter.dc +++ b/gen/letter.dc @@ -40,10 +40,11 @@ char **argv; EXEC SQL END DECLARE SECTION; #ifsql INGRES - EXEC SQL CONNECT sms; + EXEC SQL CONNECT moira; + EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED; #endsql #ifsql INFORMIX - EXEC SQL DATABASE sms; + EXEC SQL DATABASE moira; #endsql if (argc == 2) { @@ -71,6 +72,10 @@ char **argv; init_letter(); + /* The following is declarative, not executed, + * and so is dependent on where it is in the file, + * not in the order of execution of statements. + */ EXEC SQL WHENEVER SQLERROR GOTO sqlerr; EXEC SQL SELECT secure INTO :lastrun FROM users WHERE users_id = 0; @@ -109,6 +114,7 @@ char **argv; } if (outf) fix_file(outf); + exit(MR_SUCCESS); sqlerr: @@ -161,7 +167,7 @@ int when; { register char *p; char buf[256], *a1, *a2, *d; - char *rindex(); + char *rindex(), *index(); /* split address into two lines. * First determine if postal or interdepartmental address. @@ -170,27 +176,32 @@ int when; */ strcpy(buf, addr); a1 = buf; - a2 = rindex(buf, ' '); /* before state & zip */ - if (a2 && isupper(a2[1]) && isupper(a2[2]) && - isdigit(a2[3]) && isdigit(a2[4]) && isdigit(a2[5]) && - isdigit(a2[6]) && isdigit(a2[7])) { - /* Must be postal address. */ - /* missing space between state & zip, fix */ - for (p = a2; *p; p++); /* find end of string */ - for (p--; isdigit(*p); p--) - p[2] = p[1]; - p[2] = p[1]; - p[1] = ' '; - /* Backup to previous space, start of state */ - for (; *a2 != ' '; a2--); - /* Backup to previous space, start of city */ - for (a2--; *a2 != ' '; a2--); - /* terminate first line, leave a2 pointing at second */ + if (a2 = index(buf, '|')) { *a2++ = 0; } else { - /* Must be interdepartmental */ - a2 = "MIT INTERDEPARTMENTAL MAIL"; + a2 = rindex(buf, ' '); /* before state & zip */ + if (a2 && isupper(a2[1]) && isupper(a2[2]) && + isdigit(a2[3]) && isdigit(a2[4]) && isdigit(a2[5]) && + isdigit(a2[6]) && isdigit(a2[7])) { + /* Must be postal address. */ + /* missing space between state & zip, fix */ + for (p = a2; *p; p++); /* find end of string */ + for (p--; isdigit(*p); p--) + p[2] = p[1]; + p[2] = p[1]; + p[1] = ' '; + /* Backup to previous space, start of state */ + for (; *a2 != ' '; a2--); + /* Backup to previous space, start of city */ + for (a2--; *a2 != ' '; a2--); + /* terminate first line, leave a2 pointing at second */ + *a2++ = 0; + } else { + /* Must be interdepartmental */ + a2 = "MIT INTERDEPARTMENTAL MAIL"; + } } + d = ctime(&when); d[strlen(d)-1] = 0;