* wildmat.c, braindamage.c: added
[citadel.git] / webcit / tools.c
index 22e09a3533a5cb47928dec4cdbf0f6e25ed334b8..13fb0334259d325f97c430554baba3ce2fda306d 100644 (file)
@@ -9,14 +9,13 @@
 
 char *safestrncpy(char *dest, const char *src, size_t n)
 {
-  if (dest == NULL || src == NULL)
-    {
-      fprintf(stderr, "safestrncpy: NULL argument\n");
-      abort();
-    }
-  strncpy(dest, src, n);
-  dest[n - 1] = 0;
-  return dest;
+       if (dest == NULL || src == NULL) {
+               fprintf(stderr, "safestrncpy: NULL argument\n");
+               abort();
+       }
+       strncpy(dest, src, n);
+       dest[n - 1] = 0;
+       return dest;
 }
 
 
@@ -28,10 +27,11 @@ int num_parms(char *source)
        int a;
        int count = 1;
 
-       for (a=0; a<strlen(source); ++a) 
-               if (source[a]=='|') ++count;
-       return(count);
-       }
+       for (a = 0; a < strlen(source); ++a)
+               if (source[a] == '|')
+                       ++count;
+       return (count);
+}
 
 /*
  * extract()  -  extract a parameter from a series of "|" separated...
@@ -42,33 +42,35 @@ void extract(char *dest, char *source, int parmnum)
        int count = 0;
        int n;
 
-       if (strlen(source)==0) {
-               strcpy(dest,"");
+       if (strlen(source) == 0) {
+               strcpy(dest, "");
                return;
-               }
-
+       }
        n = num_parms(source);
 
        if (parmnum >= n) {
-               strcpy(dest,"");
+               strcpy(dest, "");
                return;
-               }
-       strcpy(buf,source);
-       if ( (parmnum == 0) && (n == 1) ) {
-               strcpy(dest,buf);
-               for (n=0; n<strlen(dest); ++n)
-                       if (dest[n]=='|') dest[n] = 0;
+       }
+       strcpy(buf, source);
+       if ((parmnum == 0) && (n == 1)) {
+               strcpy(dest, buf);
+               for (n = 0; n < strlen(dest); ++n)
+                       if (dest[n] == '|')
+                               dest[n] = 0;
                return;
-               }
-
-       while (count++ < parmnum) do {
-               strcpy(buf,&buf[1]);
-               } while( (strlen(buf)>0) && (buf[0]!='|') );
-       if (buf[0]=='|') strcpy(buf,&buf[1]);
-       for (count = 0; count<strlen(buf); ++count)
-               if (buf[count] == '|') buf[count] = 0;
-       strcpy(dest,buf);
        }
+       while (count++ < parmnum)
+               do {
+                       strcpy(buf, &buf[1]);
+               } while ((strlen(buf) > 0) && (buf[0] != '|'));
+       if (buf[0] == '|')
+               strcpy(buf, &buf[1]);
+       for (count = 0; count < strlen(buf); ++count)
+               if (buf[count] == '|')
+                       buf[count] = 0;
+       strcpy(dest, buf);
+}
 
 /*
  * extract_int()  -  extract an int parm w/o supplying a buffer
@@ -76,10 +78,10 @@ void extract(char *dest, char *source, int parmnum)
 int extract_int(char *source, int parmnum)
 {
        char buf[256];
-       
-       extract(buf,source,parmnum);
-       return(atoi(buf));
-       }
+
+       extract(buf, source, parmnum);
+       return (atoi(buf));
+}
 
 /*
  * extract_long()  -  extract an long parm w/o supplying a buffer
@@ -87,21 +89,23 @@ int extract_int(char *source, int parmnum)
 long extract_long(char *source, long int parmnum)
 {
        char buf[256];
-       
-       extract(buf,source,parmnum);
-       return(atol(buf));
-       }
+
+       extract(buf, source, parmnum);
+       return (atol(buf));
+}
 
 
 /*
  * check for the presence of a character within a string (returns count)
  */
-int haschar(st,ch)
+int haschar(st, ch)
 char st[];
-int ch; {
-        int a,b;
-        b=0;
-        for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
-        return(b);
-        }
-
+int ch;
+{
+       int a, b;
+       b = 0;
+       for (a = 0; a < strlen(st); ++a)
+               if (st[a] == ch)
+                       ++b;
+       return (b);
+}