]> andersk Git - moira.git/blobdiff - gen/mailhub.dc
Fix allocation strategy in setup_ahst(); shouldn't be redefining the argv
[moira.git] / gen / mailhub.dc
index 9d3c97192448692df77dbee3fd728b6d9ff49f84..72efcfc0b81fa33f9a7a8d26b598476dcb5280e6 100644 (file)
@@ -27,7 +27,7 @@ char *pstrsave();
 char *divide = "##############################################################";
 
 #define ML_WID 72
-#define AL_MAX_WID 896
+#define AL_MAX_WID 592
 
 #define FALSE 0
 #define TRUE (!FALSE)
@@ -47,10 +47,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) {
@@ -122,6 +123,7 @@ struct member {
 struct list {
     char *name;
     char maillist;
+    char *description;
     char acl_t;
     int acl_id;
     struct member *m;
@@ -145,18 +147,23 @@ get_info()
     struct list *l, *memberlist;
     register struct member *m;
 
+    /* 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 modtime INTO :buf FROM users WHERE users_id = 0;
     EXEC SQL SELECT modtime INTO :buf FROM list WHERE list_id = 0;
 
     cnt = 0;
-    machines = create_hash(10);
+    machines = create_hash(1000);
 
     EXEC SQL DECLARE m_cursor CURSOR FOR
-      SELECT m.mach_id, m.name
-      FROM machine m, users u
-      WHERE m.mach_id = u.pop_id;
+      SELECT mach_id, name
+      FROM machine
+      WHERE status=1
+      ORDER BY mach_id;
     EXEC SQL OPEN m_cursor;
     while (1) {
        EXEC SQL FETCH m_cursor INTO :id, :name;
@@ -179,16 +186,17 @@ get_info()
     fprintf(stderr, "Loaded %d machines\n", cnt);
 
     cnt = 0;
-    strings = create_hash(4000);
+    strings = create_hash(11001);
 
     EXEC SQL DECLARE s_cursor CURSOR FOR
-      SELECT string_id, string
-      FROM strings;
+      SELECT string_id, trim(string)
+      FROM strings
+      ORDER BY string_id;
     EXEC SQL OPEN s_cursor;
     while (1) {
        EXEC SQL FETCH s_cursor INTO :id, :name;
        if (sqlca.sqlcode != 0) break;
-       if (hash_store(strings, id, pstrsave(strtrim(name))) < 0) {
+       if (hash_store(strings, id, pstrsave(name)) < 0) {
            fprintf(stderr, "Out of memory!\n");
            exit(MR_NO_MEM);
        }
@@ -199,12 +207,13 @@ get_info()
     fprintf(stderr, "Loaded %d strings\n", cnt);
 
     cnt = 0;
-    users = create_hash(12001);
+    users = create_hash(13001);
 
     EXEC SQL DECLARE u_cursor CURSOR FOR
       SELECT users_id, login, first, middle, last, potype, pop_id, box_id
       FROM users
-      WHERE status != 3;
+      WHERE status != 3
+      ORDER BY users_id;
     EXEC SQL OPEN u_cursor;
     while (1) {
         EXEC SQL FETCH u_cursor INTO :id, :name, :fname, :mname, :lname,
@@ -233,22 +242,25 @@ get_info()
        cnt++;
     }
     EXEC SQL CLOSE u_cursor;
+    EXEC SQL COMMIT;
     fprintf(stderr, "Loaded %d users\n", cnt);
 
     cnt = 0;
     lists = create_hash(15000);
 
     EXEC SQL DECLARE l_cursor CURSOR FOR
-      SELECT list_id, name, maillist, acl_type, acl_id
+      SELECT list_id, name, maillist, description, acl_type, acl_id
       FROM list
-      WHERE active != 0;
+      WHERE active != 0
+      ORDER BY list_id;
     EXEC SQL OPEN l_cursor;
     while (1) {
-        EXEC SQL FETCH l_cursor INTO :id, :name, :maillistp, :type, :acl;
+        EXEC SQL FETCH l_cursor INTO :id, :name, :maillistp, :buf, :type, :acl;
         if (sqlca.sqlcode != 0) break;
        l = (struct list *) perm_malloc(sizeof(struct list));
        l->name = pstrsave(strtrim(name));
        l->maillist = maillistp;
+       l->description = pstrsave(strtrim(buf));
        l->acl_t = type[0];
        l->acl_id = acl;
        l->m = (struct member *) NULL;
@@ -259,6 +271,7 @@ get_info()
        cnt++;
     }
     EXEC SQL CLOSE l_cursor;
+    EXEC SQL COMMIT;
     fprintf(stderr, "Loaded %d lists\n", cnt);
 
     cnt = 0;
@@ -266,7 +279,8 @@ get_info()
     EXEC SQL DECLARE m_cursor2 CURSOR FOR
       SELECT list_id, member_type, member_id
       FROM imembers
-      WHERE direct = 1;
+      WHERE direct = 1
+      ORDER BY list_id;
     EXEC SQL OPEN m_cursor2;
     while (1) {
         EXEC SQL FETCH m_cursor2 INTO :id, :type, :mid;
@@ -427,12 +441,12 @@ int copy;
 }
 
 
-/* Illegal chars: ! " % ( ) , / : ; < = > @ [ \ ] ^ { | } */
+/* Illegal chars: ! " % ( ) , / : ; < = > @ [ \ ] ^ { | } */
 
 static int illegalchars[] = {
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */
     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P - ^_ */
-    0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, /* SPACE - / */
+    0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, /* SPACE - / */
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, /* 0 - ? */
     1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ - O */
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, /* P - _ */
@@ -524,6 +538,7 @@ register struct list *l;
     register struct member *m;
     register struct user *u;
 
+    put_fill(out, l->description);
     if (l->acl_t ==  'L' &&
        (l1 = (struct list *) hash_lookup(lists, l->acl_id)))
       fprintf(out, "owner-%s: %s\n%s: ", l->name, l1->name, l->name);
@@ -583,6 +598,53 @@ register char *s;
 }
 
 
+put_fill(aliases, string)
+FILE *aliases;
+register char *string;
+{
+    register char *c;
+    register int lwid;
+    register int wwid;
+
+    if (string == 0 || *string == 0) return;
+    fputs("#  ", aliases);
+    lwid = 3;
+
+    while (1) {
+       while (*string && *string == ' ') string++;
+       c = (char *)index(string, ' ');
+       if (c == 0) {
+           wwid = strlen(string);
+       } else {
+           wwid = c - string;
+           *c = 0;
+       }
+
+       if ((lwid + wwid) > ML_WID) {
+           fputs("\n#  ", aliases);
+           lwid = 3;
+           fputs(string, aliases);
+       } else {
+           fputs(string, aliases);
+       }
+
+       if (c == (char *)0) break;
+       /* add a space after the word */
+       (void) fputc(' ', aliases);
+       wwid++;
+       lwid += wwid;
+       string += wwid;
+       /* add another if after a period */
+       if (*--c == '.') {
+           (void) fputc(' ', aliases);
+           lwid++;
+       }
+    }
+
+    (void) fputc('\n', aliases);
+}
+
+
 do_people()
 {
     incount = 0;
@@ -607,7 +669,7 @@ unsigned size;
     }
     ret = pool;
     pool += size;
-    pool = (char *)(((unsigned) (pool + 1)) & ~1);
+    pool = (char *)(((unsigned) (pool + 3)) & ~3);
     pool_size -= (pool - ret);
     return(ret);
 }
This page took 0.039104 seconds and 4 git commands to generate.