]> code.citadel.org Git - citadel.git/blobdiff - citadel/support.c
* The size constant "256" which shows up everywhere as a buffer size has now
[citadel.git] / citadel / support.c
index 896797617c43b0f8c832621718d6d6cc627ea7f9..c876ca218c630fe5c2756614af7660b5e3c89356 100644 (file)
@@ -1,30 +1,19 @@
+/*
+ * $Id$
+ *
+ * Server-side utility functions
+ *
+ */
+
+#include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <ctype.h>
 #include <stdio.h>
-#include <pthread.h>
+#include <string.h>
 #include "citadel.h"
 #include "server.h"
-#include "proto.h"
-
-/*
- * struncmp()  -  case-insensitive version of strncmp()
- *                citadel.h will #define a strucmp() based on this
- */
-int struncmp(char *lstr, char *rstr, int len)
-{
-       int pos = 0;
-       char lc,rc;
-       while (pos<len) {
-               lc=tolower(lstr[pos]);
-               rc=tolower(rstr[pos]);
-               if ((lc==0)&&(rc==0)) return(0);
-               if (lc<rc) return(-1);
-               if (lc>rc) return(1);
-               pos=pos+1;
-               }
-       return(0);
-       }
+#include "support.h"
 
 
 /*
@@ -70,80 +59,6 @@ void strproc(char *string)
 
 
 
-/*
- * num_parms()  -  discover number of parameters...
- */
-int num_parms(char *source)
-{
-       int a;
-       int count = 1;
-
-       for (a=0; a<strlen(source); ++a) 
-               if (source[a]=='|') ++count;
-       return(count);
-       }
-
-/*
- * extract()  -  extract a parameter from a series of "|" separated...
- */
-void extract(char *dest, char *source, int parmnum)
-{
-       char buf[256];
-       int count = 0;
-       int n;
-
-       if (strlen(source)==0) {
-               strcpy(dest,"");
-               return;
-               }
-
-       n = num_parms(source);
-
-       if (parmnum >= n) {
-               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;
-               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);
-       }
-
-/*
- * extract_int()  -  extract an int parm w/o supplying a buffer
- */
-int extract_int(char *source, int parmnum)
-{
-       char buf[256];
-       
-       extract(buf,source,parmnum);
-       return(atoi(buf));
-       }
-
-/*
- * extract_long()  -  extract an long parm w/o supplying a buffer
- */
-long extract_long(char *source, long int parmnum)
-{
-       char buf[256];
-       
-       extract(buf,source,parmnum);
-       return(atol(buf));
-       }
-
-
-
 /*
  * get a line of text from a file
  * ignores lines starting with #
@@ -175,7 +90,7 @@ int pattern2(char *search, char *patn)
 {
        int a;
        for (a=0; a<strlen(search); ++a) {
-               if (!struncmp(&search[a],patn,strlen(patn))) return(a);
+               if (!strncasecmp(&search[a],patn,strlen(patn))) return(a);
                }
        return(-1);
        }
@@ -187,7 +102,7 @@ int pattern2(char *search, char *patn)
 void mesg_locate(char *targ, char *searchfor, int numdirs, char **dirs)
 {
        int a;
-       char buf[256];
+       char buf[SIZ];
        FILE *ls;
 
        for (a=0; a<numdirs; ++a) {
@@ -197,7 +112,7 @@ void mesg_locate(char *targ, char *searchfor, int numdirs, char **dirs)
                        while(fgets(buf,255,ls)!=NULL) {
                                while (isspace(buf[strlen(buf)-1]))
                                        buf[strlen(buf)-1] = 0;
-                               if (!strucmp(buf,searchfor)) {
+                               if (!strcasecmp(buf,searchfor)) {
                                        pclose(ls);
                                        sprintf(targ,"%s/%s",dirs[a],buf);
                                        return;
@@ -210,12 +125,12 @@ void mesg_locate(char *targ, char *searchfor, int numdirs, char **dirs)
        }
 
 
-#ifdef NO_STRERROR
+#ifndef HAVE_STRERROR
 /*
  * replacement strerror() for systems that don't have it
  */
-char *strerror(e)
-int e; {
+char *strerror(int e)
+{
        static char buf[32];
 
        sprintf(buf,"errno = %d",e);