]> andersk Git - moira.git/blobdiff - regtape/employee.dc
added verify and finished sign
[moira.git] / regtape / employee.dc
index e0f7c9067962db1cdd8e7226c18a6f5a21f31a3a..75c754348d35d2087395d808de856dfae52f9405 100644 (file)
@@ -7,12 +7,13 @@
 #include <sys/time.h>
 #include <moira.h>
 #include <moira_site.h>
+EXEC SQL INCLUDE sqlca;
 
 
-##define WHO 11859             /* root */
-##define PROG "emp-tape"
+#define WHO 11859              /* root */
+#define PROG "emp-tape"
 
-#define MAX_ID_VALUE   32766
+#define MAX_ID_VALUE   31999
 #define MIN_ID_VALUE   101
 
 /* File format is:
@@ -69,13 +70,12 @@ struct entry {
 
 char *whoami;
 int newfinger = 0;
-int addxuser = 0;
 
 
 main(argc, argv)
 int argc;
 char **argv;
-##{
+{
     FILE *in;
     struct entry *e, *get_next_entry();
     int i, wait = 0;
@@ -94,10 +94,8 @@ char **argv;
          setenv("ING_SET", "set printqry");
        else if (!strcmp(argv[i], "-n"))
          newfinger++;
-       else if (!strcmp(argv[i], "-u"))
-         addxuser++;
        else if (file != NULL)
-         fprintf(stderr, "Usage: %s [-w] [-D] [-n] [-u] inputfile\n", whoami);
+         fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
        else
          file = argv[i];
     }
@@ -108,11 +106,14 @@ char **argv;
        exit(1);
     }
 
-##  ingres sms
-##  range of u is users
+    setlinebuf(stdout);
+    setlinebuf(stderr);
+
+    EXEC SQL CONNECT moira;
 
     while (e = get_next_entry(in)) {
        process_entry(e);
+       EXEC SQL COMMIT;
        if (wait) {
            printf("Next");
            fflush(stdout);
@@ -120,9 +121,8 @@ char **argv;
        }
     }
 
-##  exit
     exit(0);
-##}
+}
 
 
 char *substr(buf, key)
@@ -147,7 +147,7 @@ FILE *in;
     static char office[LEN_OFFICE+1], phone[LEN_PHONE+1], phone2[LEN_PHONE2+1];
     static char dept[LEN_DEPT+1], title[LEN_TITLE+1], username[LEN_USERNAME+1];
     static char host[LEN_HOST+1];
-    int ends_sr, ends_jr, ends_iii, ends_iv;
+    int ends_sr, ends_jr, ends_iii, ends_iv, ends_ii, ends_v;
     char *p;
 
     if (fgets(buf, sizeof(buf), in) == NULL)
@@ -186,11 +186,13 @@ FILE *in;
        e.first = "";
        e.middle = "";
     }
-    ends_sr = ends_jr = ends_iii = ends_iv = 0;
+    ends_sr = ends_jr = ends_iii = ends_iv = ends_ii = ends_v = 0;
     LookForSt(e.last);
     LookForO(e.last);
-    LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
-    LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
+    LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
+                   &ends_ii, &ends_v);
+    LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
+                   &ends_ii, &ends_v);
     FixCase(e.last);
     FixCase(e.first);
     FixCase(e.middle);
@@ -224,12 +226,15 @@ FILE *in;
 
 process_entry(e)
 struct entry *e;
-##{
+{
     int changed, nochange;
     char buf[BUFSIZ], *from, *to;
-##  char *first, *last, *eid, *sid, *name, *title, *phone2;
-##  char class[9], oaddr[25], ophone[17], dept[128];
-##  int id, status;
+    EXEC SQL BEGIN DECLARE SECTION;
+    char *first, *last, *eid, *sid, *name, *title, *phone2, *rdept, *rtitle;
+    char *raddr, *rhphone, *rophone;
+    char class[9], oaddr[25], ophone[17], dept[128];
+    int id, status;
+    EXEC SQL END DECLARE SECTION;
 
     first = e->first;
     if (strlen(first) > 16)
@@ -238,14 +243,25 @@ struct entry *e;
     if (strlen(last) > 16)
       last[16] = 0;
     eid = e->eid;
+    sid = e->id;
     id = 0;
-##  repeat retrieve (id = u.users_id, class = u.mit_year, oaddr = u.office_addr,
-##           ophone = u.office_phone, dept = u.mit_dept, status = u.#status)
-##     where u.#last = @last and u.#first = @first and u.mit_id = @eid
+
+    /* Get user info */
+    EXEC SQL SELECT users_id, mit_year, office_addr, office_phone, mit_dept, status
+      INTO :id, :class, :oaddr, :ophone, :dept, :status
+      FROM users
+      WHERE last = :last and first = :first and clearid = :sid;
     if (id == 0) {
-       newuser(e);
-       return;
+       EXEC SQL SELECT users_id, mit_year, office_addr, office_phone, mit_dept, status
+         INTO :id, :class, :oaddr, :ophone, :dept, :status
+         FROM users
+         WHERE last = :last and first = :first and clearid = :eid;
+       if (id == 0) {
+           newuser(e);
+           return;
+       }
     }
+
     if (strcmp(e->class, strtrim(class)) &&
        strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
        com_err(whoami, 0, "updating class for %s %s from %s to %s",
@@ -255,10 +271,12 @@ struct entry *e;
        if (status == US_ENROLL_NOT_ALLOWED && !strcmp(e->class, "FACULTY"))
          status = US_ENROLLED;
        strcpy(class, e->class);
-##     repeat replace u (mit_year = @class, #status = @status, ugdefault = 1,
-##                modtime = "now", modby = WHO, modwith = PROG)
-##         where u.users_id = @id
+       EXEC SQL UPDATE users
+         SET type = :class, status = :status, modtime = 'now',
+               modby = WHO, modwith = PROG
+         WHERE users_id = :id;
     }
+
     changed = nochange = 0;
     strcpy(buf, e->address);
     while (to = index(buf, ','))
@@ -312,47 +330,45 @@ struct entry *e;
        strncpy(dept, e->dept, 12);
        dept[12] = 0;
     }
+    sid = e->id;
+    name = e->name;
+    rdept = e->dept;
+    rtitle = e->title;
+    raddr = e->address;
+    rhphone = e->phone;
+    rophone = e->phone2;
     if (changed) {
        com_err(whoami, 0, "updating finger for %s %s", first, last);
-##     repeat replace u (office_addr = @oaddr, ugdefault = 1,
-##                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);
-       */
-    if (!changed) {
-##     repeat replace u (ugdefault = 1) where u.users_id = @id
-    }
-    if (addxuser) {
-       sid = e->id;
-       name = e->name;
-       strcpy(dept, e->dept);
-       title = e->title;
-       strcpy(oaddr, e->address);
-       phone2 = e->phone2;
-
-       status = 1;
-##     repeat retrieve (status = any(xuser.users_id
-##                      where xuser.users_id = @id))
-       if (!status) {
-##     append xuser (users_id = id, #id = sid, #name = name, #dept = dept,
-##                   #title = title, address = oaddr, #phone1 = ophone,
-##                   #phone2 = phone2, modtime = "now")
-       }
+       EXEC SQL REPEATED UPDATE users
+         SET office_addr = :oaddr, office_phone = :ophone, mit_dept = :dept,
+           fmodtime = 'now', fmodby = WHO, fmodwith = PROG,
+           xname = :name, xdept = :rdept, xtitle = :rtitle,
+           xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
+           xmodtime = 'now', mit_id = :sid
+         WHERE users_id = :id;
+    } else {
+       EXEC SQL REPEATED UPDATE users
+         SET xname = :name, xdept = :rdept, xtitle = :rtitle,
+           xaddress = :raddr, xphone1 = :rhphone, xphone2 = :rophone,
+           xmodtime = 'now', mit_id = :sid
+         WHERE users_id = :id;
     }
-##}
+}
 
 
 newuser(e)
 struct entry *e;
-##{
+{
     char *from, *to;
-##  int id, uid, st;
-##  char *last, *first, *class, *middle, login[9], *eid, fullname[65];
-##  char oaddr[81], ophone[17], dept[128], *sid, *name, *title, phone2[17];
-
-
+    EXEC SQL BEGIN DECLARE SECTION;
+    int id, uid, st, who;
+    char *last, *first, *class, *middle, login[9], *sid, fullname[65], *prog;
+    char oaddr[81], ophone[17], dept[128], *name, *title, phone2[17];
+    char *rdept, *rhphone, *rophone;
+    EXEC SQL END DECLARE SECTION;
+
+    who = WHO;
+    prog = PROG;
     strncpy(oaddr, e->address, 16);
     oaddr[16] = 0;
     while (to = index(oaddr, ','))
@@ -377,7 +393,6 @@ struct entry *e;
     last = e->last;
     first = e->first;
     middle = e->middle;
-    eid = e->eid;
     class = e->class;
     if (*middle)
       sprintf(fullname, "%s %s %s", first, middle, last);
@@ -386,71 +401,60 @@ struct entry *e;
     st = US_NOT_ALLOWED;
     if (!strcmp(e->class, "FACULTY") || !strcmp(e->class, "STAFF"))
       st = US_NO_LOGIN_YET;
-    
-##  append users (#login = login, users_id = id, #uid = uid, shell = "/bin/csh",
-##               #last = last, #first = first, #middle = middle, status = st,
-##               #mit_id = eid, #mit_year = class, ugdefault = 1,
-##               modtime = "now", modby = WHO, modwith = PROG,
-##               #fullname = fullname, office_addr = oaddr,
-##               office_phone = ophone, #mit_dept = dept,
-##               fmodtime = "now", fmodby = WHO, fmodwith = PROG,
-##               potype = "NONE")
 
     sid = e->id;
     name = e->name;
-    strcpy(dept, e->dept);
+    rdept = e->dept;
     title = e->title;
-    FixCase(title);
-    strcpy(oaddr, e->address);
-    FixCase(oaddr);
-    from = e->phone2;
-    to = phone2;
-    while (*from) {
-       if (isdigit(*from))
-         *to++ = *from;
-       from++;
-    }
-    *to = 0;
-
-    if (addxuser) {
-##     append xuser (users_id = id, #id = sid, #name = fullname, #dept = dept,
-##               #title = title, address = oaddr, #phone1 = ophone,
-##               #phone2 = phone2, modtime = "now")
-    }
-    com_err(whoami, 0, "adding user %s %s", e->first, e->last);
-##}
+    rhphone = e->phone;
+    rophone = e->phone2;
+
+    EXEC SQL INSERT INTO users
+      (login, users_id, uid, shell, last, first, middle, status,
+       clearid, type, modtime, modby, modwith, fullname, office_addr,
+       office_phone, department, fmodtime, fmodby, fmodwith,
+       potype, xname, xdept, xtitle, xaddress, xphone1, xphone2, xmodtime)
+      VALUES (:login, :id, :uid, '/bin/csh', :last, :first, :middle, :st,
+             :sid, :class, 'now', :who, :prog, :fullname, :oaddr, :ophone,
+             :dept, 'now', :who, :prog, 'NONE', :name, :rdept,
+             :title, :oaddr, :rhphone, :rophone, 'now');
+}
 
 
 set_next_object_id(object, limit)
     char *object;
     int limit;
-##{
-##  char *name;
-##  int rowcount, exists, value;
+{
+    EXEC SQL BEGIN DECLARE SECTION;
+    char *name;
+    int rowcount, flag, value;
+    EXEC SQL END DECLARE SECTION;
 
     name = object;
-##  begin transaction
-##  repeat retrieve (value = values.#value) where values.#name = @name
-##  inquire_equel(rowcount = "rowcount")
-    if (rowcount != 1) {
-##     abort
-       return(0);
+    EXEC SQL SELECT value INTO :value FROM numvalues WHERE name = :name;
+    if (sqlca.sqlerrd[2] != 1) {
+       EXEC SQL ROLLBACK;
+       com_err(whoami, MR_INTERNAL, "values table inconsistancy");
+       exit(1);
     }
 
-##  retrieve (exists = any(users.name where users.name = value))
-##  inquire_equel(rowcount = "rowcount")
-    if (rowcount != 1) {
-##     abort
-       return(0);
-    }
-    while (exists) {
+    flag = 0;
+    EXEC SQL SELECT :name INTO :flag FROM users WHERE :name = :value;
+    if (sqlca.sqlerrd[2] == 0)
+      flag = 0;
+    while (flag) {
        value++;
        if (limit && value > MAX_ID_VALUE)
            value = MIN_ID_VALUE;
-##     retrieve (exists = any(users.name where users.name = value))
+       flag = 0;
+       EXEC SQL SELECT :name INTO :flag FROM users WHERE :name = :value;
+       if (sqlca.sqlerrd[2] == 0)
+         flag = 0;
     }
 
-##  repeat replace values (#value = @value) where values.#name = @name
-##  end transaction
+    value++;
+    if (limit && value > MAX_ID_VALUE)
+      value = MIN_ID_VALUE;
+    EXEC SQL REPEATED UPDATE numvalues SET value = :value WHERE name = :name;
     return(value);
-##}
+}
This page took 0.0445 seconds and 4 git commands to generate.