Mailing list header changes (fuck you Google)
[citadel.git] / citadel / support.c
1 /*
2  * Server-side utility functions
3  */
4
5 #include "sysdep.h"
6 #include <stdio.h>
7 #include <string.h>
8 #include <sys/stat.h>
9 #include <libcitadel.h>
10
11 #include "citadel.h"
12 #include "support.h"
13
14 /*
15  * strproc()  -  make a string 'nice'
16  */
17 void strproc(char *string)
18 {
19         int a, b;
20
21         if (string == NULL) return;
22         if (IsEmptyStr(string)) return;
23
24         /* Convert non-printable characters to blanks */
25         for (a=0; !IsEmptyStr(&string[a]); ++a) {
26                 if (string[a]<32) string[a]=32;
27                 if (string[a]>126) string[a]=32;
28         }
29
30         /* a is now the length of our string. */
31         /* Remove leading and trailing blanks */
32         while( (string[a-1]<33) && (!IsEmptyStr(string)) )
33                 string[--a]=0;
34         b = 0;
35         while( (string[b]<33) && (!IsEmptyStr(&string[b])) )
36                 b++;
37         if (b > 0)
38                 memmove(string,&string[b], a - b + 1);
39
40         /* Remove double blanks */
41         for (a=0; !IsEmptyStr(&string[a]); ++a) {
42                 if ((string[a]==32)&&(string[a+1]==32)) {
43                         strcpy(&string[a],&string[a+1]);
44                         a=0;
45                 }
46         }
47
48         /* remove characters which would interfere with the network */
49         for (a=0; !IsEmptyStr(&string[a]); ++a) {
50                 while (string[a]=='!') strcpy(&string[a],&string[a+1]);
51                 while (string[a]=='@') strcpy(&string[a],&string[a+1]);
52                 while (string[a]=='_') strcpy(&string[a],&string[a+1]);
53                 while (string[a]==',') strcpy(&string[a],&string[a+1]);
54                 while (string[a]=='%') strcpy(&string[a],&string[a+1]);
55                 while (string[a]=='|') strcpy(&string[a],&string[a+1]);
56         }
57
58 }
59
60
61
62 /*
63  * get a line of text from a file
64  * ignores lines starting with #
65  */
66 int getstring(FILE *fp, char *string)
67 {
68         int a,c;
69         do {
70                 strcpy(string,"");
71                 a=0;
72                 do {
73                         c=getc(fp);
74                         if (c<0) {
75                                 string[a]=0;
76                                 return(-1);
77                                 }
78                         string[a++]=c;
79                         } while(c!=10);
80                         string[a-1]=0;
81                 } while(string[0]=='#');
82         return(strlen(string));
83 }