7410e7cc23f9179c8c9693c35b36e2e914590f09
[citadel.git] / citadel / server / support.c
1 // Server-side utility functions
2 // Copyright (c) 1987-2022 by the citadel.org team
3 // This program is open source software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License, version 3.
5
6 #include "sysdep.h"
7 #include <stdio.h>
8 #include <string.h>
9 #include <sys/stat.h>
10 #include <libcitadel.h>
11
12 #include "citadel.h"
13 #include "support.h"
14
15 // strproc()  -  make a string 'nice'
16 void strproc(char *string) {
17         int a, b;
18
19         if (string == NULL) return;
20         if (IsEmptyStr(string)) return;
21
22         // Convert non-printable characters to blanks
23         for (a=0; !IsEmptyStr(&string[a]); ++a) {
24                 if (string[a]<32) string[a]=32;
25                 if (string[a]>126) string[a]=32;
26         }
27
28         // a is now the length of our string.
29         // Remove leading and trailing blanks
30         while( (string[a-1]<33) && (!IsEmptyStr(string)) )
31                 string[--a]=0;
32         b = 0;
33         while( (string[b]<33) && (!IsEmptyStr(&string[b])) )
34                 b++;
35         if (b > 0)
36                 memmove(string,&string[b], a - b + 1);
37
38         // Remove double blanks
39         for (a=0; !IsEmptyStr(&string[a]); ++a) {
40                 if ((string[a]==32)&&(string[a+1]==32)) {
41                         strcpy(&string[a],&string[a+1]);
42                         a=0;
43                 }
44         }
45
46         // remove characters which would interfere with the network
47         for (a=0; !IsEmptyStr(&string[a]); ++a) {
48                 while (string[a]=='!') strcpy(&string[a],&string[a+1]);
49                 while (string[a]=='@') strcpy(&string[a],&string[a+1]);
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         }
55
56 }
57
58
59 // get a line of text from a file
60 // ignores lines starting with #
61 int getstring(FILE *fp, char *string) {
62         int a,c;
63         do {
64                 strcpy(string,"");
65                 a=0;
66                 do {
67                         c=getc(fp);
68                         if (c<0) {
69                                 string[a]=0;
70                                 return(-1);
71                                 }
72                         string[a++]=c;
73                         } while(c!=10);
74                         string[a-1]=0;
75                 } while(string[0]=='#');
76         return(strlen(string));
77 }