]> andersk Git - moira.git/blobdiff - regtape/employee.pc
Use moira_schema.h
[moira.git] / regtape / employee.pc
index b4bf328b3057aa77f0c020c277e1a2a5c68fef11..3e4b159eff07cecafaa4026b2044ac66215e1121 100644 (file)
@@ -10,6 +10,7 @@
 #include <mit-copyright.h>
 #include <moira.h>
 #include <moira_site.h>
+#include <moira_schema.h>
 
 #include <ctype.h>
 #include <stdio.h>
@@ -97,7 +98,7 @@ int main(int argc, char **argv)
   FILE *in;
   struct entry *e;
   int i, wait = 0;
-  char buf[BUFSIZ], *file = NULL;
+  char buf[80], *file = NULL;
   EXEC SQL BEGIN DECLARE SECTION;
   char *db = "moira";
   EXEC SQL END DECLARE SECTION;
@@ -152,7 +153,7 @@ int main(int argc, char **argv)
        {
          printf("Next");
          fflush(stdout);
-         gets(buf);
+         fgets(buf, sizeof(buf), stdin);
        }
     }
 
@@ -258,24 +259,28 @@ struct entry *get_next_entry(FILE *in)
 void process_entry(struct entry *e)
 {
   int changed, nochange, encrypted;
-  char buf[BUFSIZ], *from, *to;
+  char buf[MAX_FIELD_WIDTH], *from, *to;
   EXEC SQL BEGIN DECLARE SECTION;
   char *first, *last, *middle, *eid, *sid, *name, *rdept;
   char *rtitle, *raddr, *rhphone, *rophone, *prog;
-  char class[9], oaddr[25], ophone[17], dept[128];
-  char dfirst[17], dlast[17], dmiddle[17];
+  char class[USERS_TYPE_SIZE], oaddr[USERS_OFFICE_ADDR_SIZE];
+  char ophone[USERS_OFFICE_PHONE_SIZE], dept[USERS_DEPARTMENT_SIZE];
+  char dfirst[USERS_FIRST_SIZE], dlast[USERS_LAST_SIZE];
+  char dmiddle[USERS_MIDDLE_SIZE];
   int id, status, who;
   EXEC SQL END DECLARE SECTION;
 
   who = WHO;
   prog = PROG;
   first = e->first;
-  if (strlen(first) > 16)
-    first[16] = '\0';
+  if (strlen(first) > USERS_FIRST_SIZE - 1)
+    first[USERS_FIRST_SIZE - 1] = '\0';
   last = e->last;
-  if (strlen(last) > 16)
-    last[16] = '\0';
+  if (strlen(last) > USERS_LAST_SIZE - 1)
+    last[USERS_LAST_SIZE - 1] = '\0';
   middle = e->middle;
+  if (strlen(middle) > USERS_MIDDLE_SIZE - 1)
+    middle[USERS_MIDDLE_SIZE - 1] = '\0';
   eid = e->eid;
   sid = e->id;
   id = 0;
@@ -370,19 +375,19 @@ void process_entry(struct entry *e)
     {
       if (oaddr[0] == ' ' && buf[0])
        {
-         strncpy(oaddr, buf, 16);
-         oaddr[16] = '\0';
+         strncpy(oaddr, buf, USERS_OFFICE_ADDR_SIZE - 1);
+         oaddr[USERS_OFFICE_ADDR_SIZE - 1] = '\0';
          changed++;
        }
-      else if (strncmp(strtrim(oaddr), buf, 15))
+      else if (strncmp(strtrim(oaddr), buf, USERS_OFFICE_ADDR_SIZE - 1))
        nochange++;
     }
   else
     {
-      if (strncmp(strtrim(oaddr), buf, 15))
+      if (strncmp(strtrim(oaddr), buf, USERS_OFFICE_ADDR_SIZE - 1))
        changed++;
-      strncpy(oaddr, buf, 16);
-      oaddr[16] = '\0';
+      strncpy(oaddr, buf, USERS_OFFICE_ADDR_SIZE - 1);
+      oaddr[USERS_OFFICE_ADDR_SIZE - 1] = '\0';
     }
   from = e->phone;
   to = buf;
@@ -397,18 +402,18 @@ void process_entry(struct entry *e)
     {
       if (ophone[0] == ' ')
        {
-         strncpy(ophone, buf, 16);
-         ophone[16] = '\0';
+         strncpy(ophone, buf, USERS_OFFICE_PHONE_SIZE - 1);
+         ophone[USERS_OFFICE_PHONE_SIZE - 1] = '\0';
        }
-      else if (strncmp(strtrim(ophone), buf, 11))
+      else if (strncmp(strtrim(ophone), buf, USERS_OFFICE_PHONE_SIZE - 1))
        nochange++;
     }
   else
     {
-      if (strncmp(strtrim(ophone), buf, 11))
+      if (strncmp(strtrim(ophone), buf, USERS_OFFICE_PHONE_SIZE - 1))
        changed++;
-      strncpy(ophone, buf, 16);
-      ophone[16] = '\0';
+      strncpy(ophone, buf, USERS_OFFICE_PHONE_SIZE - 1);
+      ophone[USERS_OFFICE_PHONE_SIZE - 1] = '\0';
     }
   FixCase(e->dept);
   FixCase(e->title);
@@ -416,18 +421,18 @@ void process_entry(struct entry *e)
     {
       if (dept[0] == ' ')
        {
-         strncpy(dept, e->dept, 12);
-         dept[12] = '\0';
+         strncpy(dept, e->dept, USERS_DEPARTMENT_SIZE - 1);
+         dept[USERS_DEPARTMENT_SIZE - 1] = '\0';
        }
-      else if (strncmp(strtrim(dept), e->dept, 11))
+      else if (strncmp(strtrim(dept), e->dept, USERS_DEPARTMENT_SIZE - 1))
        nochange++;
     }
   else
     {
-      if (strncmp(strtrim(dept), e->dept, 11))
+      if (strncmp(strtrim(dept), e->dept, USERS_DEPARTMENT_SIZE - 1))
        changed++;
-      strncpy(dept, e->dept, 12);
-      dept[12] = '\0';
+      strncpy(dept, e->dept, USERS_DEPARTMENT_SIZE - 1);
+      dept[USERS_DEPARTMENT_SIZE - 1] = '\0';
     }
   sid = e->id;
   name = e->name;
@@ -476,15 +481,17 @@ void newuser(struct entry *e)
   char *from, *to;
   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;
+  char *last, *first, *class, *middle, login[USERS_LOGIN_SIZE], *sid;
+  char fullname[USERS_FULLNAME_SIZE], *prog;
+  char oaddr[USERS_OFFICE_ADDR_SIZE], ophone[USERS_OFFICE_PHONE_SIZE];
+  char dept[USERS_DEPARTMENT_SIZE], *name, *title;
   char *rdept, *rhphone, *rophone;
   EXEC SQL END DECLARE SECTION;
 
   who = WHO;
   prog = PROG;
-  strncpy(oaddr, e->address, 16);
-  oaddr[16] = '\0';
+  strncpy(oaddr, e->address, USERS_OFFICE_ADDR_SIZE - 1);
+  oaddr[USERS_OFFICE_ADDR_SIZE - 1] = '\0';
   while ((to = strchr(oaddr, ',')))
     *to = ';';
   while ((to = strchr(oaddr, ':')))
@@ -499,8 +506,8 @@ void newuser(struct entry *e)
     }
   *to = '\0';
   FixCase(e->dept);
-  strncpy(dept, e->dept, 12);
-  dept[12] = '\0';
+  strncpy(dept, e->dept, USERS_DEPARTMENT_SIZE - 1);
+  dept[USERS_DEPARTMENT_SIZE] = '\0';
 
   id = set_next_users_id(0);
   uid = set_next_uid(e->highid);
This page took 0.049047 seconds and 4 git commands to generate.