]> andersk Git - moira.git/blobdiff - clients/userreg/disable.c
second code style cleanup: void/void * usage, proper #includes. try to
[moira.git] / clients / userreg / disable.c
index 3e0c4cb7d306b0378717fb493b328a1ce3e77b0d..8b05567e92530ed175badf1b0c4595dc97289cc5 100644 (file)
@@ -1,21 +1,24 @@
-/* $Header$
+/* $Id $
  *
  * disabled: check to see if registration is enabled right now.  Most of this
  * code is stolen from the cron daemon.
  *
- *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
- *  For copying and distribution information, please see the file
- *  <mit-copyright.h>.
+ * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
  */
 
 #include <mit-copyright.h>
-#include <stdio.h>
+#include <moira.h>
+
 #include <ctype.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/file.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
 
-#define        LISTS   (2*BUFSIZ)
+#include "userreg.h"
+
+#define        LISTS   (2 * BUFSIZ)
 #define        MAXLIN  BUFSIZ
 
 #define        EXACT   100
 #define        RANGE   103
 #define        EOS     104
 
-#define FILENAME "disabled.times"
-
-time_t itime, time();
+time_t itime;
 struct tm *loct;
-struct tm *localtime();
-char   *malloc();
-char   *realloc();
 int    flag;
 char   *list;
 char   *listend;
 unsigned listsize;
 
-char *cmp();
+char *cmp(char *p, int v);
+void init(void);
+void append(char *fn);
+int number(char c, FILE *f);
 
 /* This routine will determine if registration is enabled at this time.  If
  * NULL is returned, registration is OK.  Otherwise, the string returned
  * will indicate the time that registration will be re-enabled.
  */
 
-char *disabled(msg)
-char **msg;
+char *disabled(char **msg)
 {
-    register char *cp;
-    int hit;
+  char *cp;
+  int hit;
 
-    *msg = 0;
-    init();
-    append(FILENAME);
-    *listend++ = EOS;
-    *listend++ = EOS;
+  *msg = 0;
+  init();
+  append(DISABLE_FILE);
+  *listend++ = EOS;
+  *listend++ = EOS;
 
-    (void) time(&itime);
-    itime -= localtime(&itime)->tm_sec;
-    loct = localtime(&itime);
-    loct->tm_mon++;             /* 1-12 for month */
-    if (loct->tm_wday == 0)
-      loct->tm_wday = 7;       /* sunday is 7, not 0 */
-    hit = 0;
-    for(cp = list; *cp != EOS;) {
-       flag = 0;
-       cp = cmp(cp, loct->tm_min);
-       cp = cmp(cp, loct->tm_hour);
-       cp = cmp(cp, loct->tm_mday);
-       cp = cmp(cp, loct->tm_mon);
-       cp = cmp(cp, loct->tm_wday);
-       if(flag == 0) {
-           *msg = cp;
-           hit++;
-           break;
+  time(&itime);
+  itime -= localtime(&itime)->tm_sec;
+  loct = localtime(&itime);
+  loct->tm_mon++;               /* 1-12 for month */
+  if (loct->tm_wday == 0)
+    loct->tm_wday = 7; /* sunday is 7, not 0 */
+  hit = 0;
+  for (cp = list; *cp != EOS;)
+    {
+      flag = 0;
+      cp = cmp(cp, loct->tm_min);
+      cp = cmp(cp, loct->tm_hour);
+      cp = cmp(cp, loct->tm_mday);
+      cp = cmp(cp, loct->tm_mon);
+      cp = cmp(cp, loct->tm_wday);
+      if (flag == 0)
+       {
+         *msg = cp;
+         hit++;
+         break;
        }
-       while(*cp++ != 0)
-         ;
+      while (*cp++)
+       ;
     }
-    if (!hit)
-      return(NULL);
-    while (hit) {
-       itime += 60;            /* add a minute */
-       loct = localtime(&itime);
-       loct->tm_mon++;         /* 1-12 for month */
-       if (loct->tm_wday == 0)
-         loct->tm_wday = 7;    /* sunday is 7, not 0 */
-       hit = 0;
-       for(cp = list; *cp != EOS;) {
-           flag = 0;
-           cp = cmp(cp, loct->tm_min);
-           cp = cmp(cp, loct->tm_hour);
-           cp = cmp(cp, loct->tm_mday);
-           cp = cmp(cp, loct->tm_mon);
-           cp = cmp(cp, loct->tm_wday);
-           if(flag == 0) {
-               hit++;
-               break;
+  if (!hit)
+    return NULL;
+  while (hit)
+    {
+      itime += 60;             /* add a minute */
+      loct = localtime(&itime);
+      loct->tm_mon++;          /* 1-12 for month */
+      if (loct->tm_wday == 0)
+       loct->tm_wday = 7;      /* sunday is 7, not 0 */
+      hit = 0;
+      for(cp = list; *cp != EOS;)
+       {
+         flag = 0;
+         cp = cmp(cp, loct->tm_min);
+         cp = cmp(cp, loct->tm_hour);
+         cp = cmp(cp, loct->tm_mday);
+         cp = cmp(cp, loct->tm_mon);
+         cp = cmp(cp, loct->tm_wday);
+         if (!flag)
+           {
+             hit++;
+             break;
            }
-           while(*cp++ != 0)
-             ;
+         while(*cp++ != 0)
+           ;
        }
     }
-    return(ctime(&itime));
+  return ctime(&itime);
 }
 
-static char *
-cmp(p, v)
-char *p;
+char *cmp(char *p, int v)
 {
-       register char *cp;
-
-       cp = p;
-       switch(*cp++) {
+  char *cp;
 
-       case EXACT:
-               if (*cp++ != v)
-                       flag++;
-               return(cp);
+  cp = p;
+  switch (*cp++)
+    {
+    case EXACT:
+      if (*cp++ != v)
+       flag++;
+      return cp;
 
-       case ANY:
-               return(cp);
+    case ANY:
+      return cp;
 
-       case LIST:
-               while(*cp != LIST)
-                       if(*cp++ == v) {
-                               while(*cp++ != LIST)
-                                       ;
-                               return(cp);
-                       }
-               flag++;
-               return(cp+1);
-
-       case RANGE:
-               if(*cp > v || cp[1] < v)
-                       flag++;
-               return(cp+2);
+    case LIST:
+      while (*cp != LIST)
+       {
+         if (*cp++ == v)
+           {
+             while (*cp++ != LIST)
+               ;
+             return cp;
+           }
        }
-       if(cp[-1] != v)
-               flag++;
-       return(cp);
+      flag++;
+      return cp + 1;
+
+    case RANGE:
+      if (*cp > v || cp[1] < v)
+       flag++;
+      return cp + 2;
+    }
+  if (cp[-1] != v)
+    flag++;
+  return cp;
 }
 
-static init()
+void init(void)
 {
-       /*
-        * Don't free in case was longer than LISTS.  Trades off
-        * the rare case of crontab shrinking vs. the common case of
-        * extra realloc's needed in append() for a large crontab.
-        */
-       if (list == 0) {
-               list = malloc(LISTS);
-               listsize = LISTS;
-       }
-       listend = list;
+  /*
+   * Don't free in case was longer than LISTS.  Trades off
+   * the rare case of crontab shrinking vs. the common case of
+   * extra realloc's needed in append() for a large crontab.
+   */
+  if (list == 0)
+    {
+      list = malloc(LISTS);
+      listsize = LISTS;
+    }
+  listend = list;
 }
 
-static append(fn)
-char *fn;
+void append(char *fn)
 {
-       register i, c;
-       register char *cp;
-       register char *ocp;
-       register int n;
-       FILE *f, *fopen();
+  int i, c;
+  char *cp;
+  char *ocp;
+  int n;
+  FILE *f;
 
-       if ((f = fopen(fn, "r")) == (FILE *) NULL)
-               return;
-       cp = listend;
+  if (!(f = fopen(fn, "r")))
+    return;
+  cp = listend;
 loop:
-       if(cp > list+listsize-MAXLIN) {
-               int length = cp - list;
+  if (cp > list + listsize - MAXLIN)
+    {
+      int length = cp - list;
 
-               listsize += LISTS;
-               list = realloc(list, listsize);
-               cp = list + length;
+      listsize += LISTS;
+      list = realloc(list, listsize);
+      cp = list + length;
+    }
+  ocp = cp;
+  for (i = 0; ; i++)
+    {
+      do
+       c = getc(f);
+      while(c == ' ' || c == '\t');
+      if (c == EOF || c == '\n')
+       goto ignore;
+      if (i == 5)
+       break;
+      if (c == '*')
+       {
+         *cp++ = ANY;
+         continue;
        }
-       ocp = cp;
-       for(i=0;; i++) {
-               do
-                       c = getc(f);
-               while(c == ' ' || c == '\t')
-                       ;
-               if(c == EOF || c == '\n')
-                       goto ignore;
-               if(i == 5)
-                       break;
-               if(c == '*') {
-                       *cp++ = ANY;
-                       continue;
-               }
-               if ((n = number(c, f)) < 0)
-                       goto ignore;
-               c = getc(f);
-               if(c == ',')
-                       goto mlist;
-               if(c == '-')
-                       goto mrange;
-               if(c != '\t' && c != ' ')
-                       goto ignore;
-               *cp++ = EXACT;
-               *cp++ = n;
-               continue;
-
-       mlist:
-               *cp++ = LIST;
-               *cp++ = n;
-               do {
-                       if ((n = number(getc(f), f)) < 0)
-                               goto ignore;
-                       *cp++ = n;
-                       c = getc(f);
-               } while (c==',');
-               if(c != '\t' && c != ' ')
-                       goto ignore;
-               *cp++ = LIST;
-               continue;
+      if ((n = number(c, f)) < 0)
+       goto ignore;
+      c = getc(f);
+      if(c == ',')
+       goto mlist;
+      if(c == '-')
+       goto mrange;
+      if(c != '\t' && c != ' ')
+       goto ignore;
+      *cp++ = EXACT;
+      *cp++ = n;
+      continue;
 
-       mrange:
-               *cp++ = RANGE;
-               *cp++ = n;
-               if ((n = number(getc(f), f)) < 0)
-                       goto ignore;
-               c = getc(f);
-               if(c != '\t' && c != ' ')
-                       goto ignore;
-               *cp++ = n;
+    mlist:
+      *cp++ = LIST;
+      *cp++ = n;
+      do
+       {
+         if ((n = number(getc(f), f)) < 0)
+           goto ignore;
+         *cp++ = n;
+         c = getc(f);
        }
-       while(c != '\n') {
-               if(c == EOF)
-                       goto ignore;
-               if(c == '%')
-                       c = '\n';
-               *cp++ = c;
-               c = getc(f);
-       }
-       *cp++ = '\n';
-       *cp++ = 0;
-       goto loop;
+      while (c == ',');
+      if (c != '\t' && c != ' ')
+       goto ignore;
+      *cp++ = LIST;
+      continue;
+
+    mrange:
+      *cp++ = RANGE;
+      *cp++ = n;
+      if ((n = number(getc(f), f)) < 0)
+       goto ignore;
+      c = getc(f);
+      if (c != '\t' && c != ' ')
+       goto ignore;
+      *cp++ = n;
+    }
+  while (c != '\n')
+    {
+      if (c == EOF)
+       goto ignore;
+      if (c == '%')
+       c = '\n';
+      *cp++ = c;
+      c = getc(f);
+    }
+  *cp++ = '\n';
+  *cp++ = 0;
+  goto loop;
 
 ignore:
-       cp = ocp;
-       while(c != '\n') {
-               if(c == EOF) {
-                       (void) fclose(f);
-                       listend = cp;
-                       return;
-               }
-               c = getc(f);
+  cp = ocp;
+  while (c != '\n')
+    {
+      if (c == EOF)
+       {
+         fclose(f);
+         listend = cp;
+         return;
        }
-       goto loop;
+      c = getc(f);
+    }
+  goto loop;
 }
 
-static number(c, f)
-register c;
-FILE *f;
+int number(char c, FILE *f)
 {
-       register n = 0;
+  int n = 0;
 
-       while (isdigit(c)) {
-               n = n*10 + c - '0';
-               c = getc(f);
-       }
-       (void) ungetc(c, f);
-       if (n>=100)
-               return(-1);
-       return(n);
+  while (isdigit(c))
+    {
+      n = n * 10 + c - '0';
+      c = getc(f);
+    }
+  ungetc(c, f);
+  if (n >= 100)
+    return -1;
+  return n;
 }
 
This page took 0.129558 seconds and 4 git commands to generate.