* es.po: the correct license for this file was supposed to be GPL v2-or-later, not...
[citadel.git] / citadel / support.c
blobb650c7ee8c2cfcbb5bbac65b999e08dee7fbcd88
1 /*
2 * $Id$
4 * Server-side utility functions
6 */
8 #include "sysdep.h"
9 #include <stdlib.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <unistd.h>
13 #include <ctype.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <libcitadel.h>
17 #include "citadel.h"
18 #include "server.h"
19 #include "support.h"
22 * strproc() - make a string 'nice'
24 void strproc(char *string)
26 int a, b;
28 if (string == NULL) return;
29 if (IsEmptyStr(string)) return;
31 /* Convert non-printable characters to blanks */
32 for (a=0; !IsEmptyStr(&string[a]); ++a) {
33 if (string[a]<32) string[a]=32;
34 if (string[a]>126) string[a]=32;
37 /* a is now the length of our string. */
38 /* Remove leading and trailing blanks */
39 while( (string[a-1]<33) && (!IsEmptyStr(string)) )
40 string[--a]=0;
41 b = 0;
42 while( (string[b]<33) && (!IsEmptyStr(&string[b])) )
43 b++;
44 if (b > 0)
45 memmove(string,&string[b], a - b + 1);
47 /* Remove double blanks */
48 for (a=0; !IsEmptyStr(&string[a]); ++a) {
49 if ((string[a]==32)&&(string[a+1]==32)) {
50 strcpy(&string[a],&string[a+1]);
51 a=0;
55 /* remove characters which would interfere with the network */
56 for (a=0; !IsEmptyStr(&string[a]); ++a) {
57 while (string[a]=='!') strcpy(&string[a],&string[a+1]);
58 while (string[a]=='@') strcpy(&string[a],&string[a+1]);
59 while (string[a]=='_') strcpy(&string[a],&string[a+1]);
60 while (string[a]==',') strcpy(&string[a],&string[a+1]);
61 while (string[a]=='%') strcpy(&string[a],&string[a+1]);
62 while (string[a]=='|') strcpy(&string[a],&string[a+1]);
70 * get a line of text from a file
71 * ignores lines starting with #
73 int getstring(FILE *fp, char *string)
75 int a,c;
76 do {
77 strcpy(string,"");
78 a=0;
79 do {
80 c=getc(fp);
81 if (c<0) {
82 string[a]=0;
83 return(-1);
85 string[a++]=c;
86 } while(c!=10);
87 string[a-1]=0;
88 } while(string[0]=='#');
89 return(strlen(string));
96 * mesg_locate() - locate a message or help file, case insensitive
98 void mesg_locate(char *targ, size_t n, const char *searchfor,
99 int numdirs, const char * const *dirs)
101 int a;
102 char buf[SIZ];
103 struct stat test;
105 for (a=0; a<numdirs; ++a) {
106 snprintf(buf, sizeof buf, "%s/%s", dirs[a], searchfor);
107 if (!stat(buf, &test)) {
108 snprintf(targ, n, "%s/%s", dirs[a], searchfor);
109 return;
112 strcpy(targ,"");
116 #ifndef HAVE_STRERROR
118 * replacement strerror() for systems that don't have it
120 char *strerror(int e)
122 static char buf[32];
124 snprintf(buf,sizeof buf,"errno = %d",e);
125 return(buf);
127 #endif