2 * Server-side utility functions
9 #include <libcitadel.h>
15 * strproc() - make a string 'nice'
17 void strproc(char *string)
21 if (string == NULL) return;
22 if (IsEmptyStr(string)) return;
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;
30 /* a is now the length of our string. */
31 /* Remove leading and trailing blanks */
32 while( (string[a-1]<33) && (!IsEmptyStr(string)) )
35 while( (string[b]<33) && (!IsEmptyStr(&string[b])) )
38 memmove(string,&string[b], a - b + 1);
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]);
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]);
63 * get a line of text from a file
64 * ignores lines starting with #
66 int getstring(FILE *fp, char *string)
81 } while(string[0]=='#');
82 return(strlen(string));
89 * mesg_locate() - locate a message or help file, case insensitive
91 void mesg_locate(char *targ, size_t n, const char *searchfor,
92 int numdirs, const char * const *dirs)
98 for (a=0; a<numdirs; ++a) {
99 snprintf(buf, sizeof buf, "%s/%s", dirs[a], searchfor);
100 if (!stat(buf, &test)) {
101 snprintf(targ, n, "%s/%s", dirs[a], searchfor);
109 #ifndef HAVE_STRERROR
111 * replacement strerror() for systems that don't have it
113 char *strerror(int e)
117 snprintf(buf,sizeof buf,"errno = %d",e);