2 * Server-side utility functions
13 #include <libcitadel.h>
19 * strproc() - make a string 'nice'
21 void strproc(char *string)
25 if (string == NULL) return;
26 if (IsEmptyStr(string)) return;
28 /* Convert non-printable characters to blanks */
29 for (a=0; !IsEmptyStr(&string[a]); ++a) {
30 if (string[a]<32) string[a]=32;
31 if (string[a]>126) string[a]=32;
34 /* a is now the length of our string. */
35 /* Remove leading and trailing blanks */
36 while( (string[a-1]<33) && (!IsEmptyStr(string)) )
39 while( (string[b]<33) && (!IsEmptyStr(&string[b])) )
42 memmove(string,&string[b], a - b + 1);
44 /* Remove double blanks */
45 for (a=0; !IsEmptyStr(&string[a]); ++a) {
46 if ((string[a]==32)&&(string[a+1]==32)) {
47 strcpy(&string[a],&string[a+1]);
52 /* remove characters which would interfere with the network */
53 for (a=0; !IsEmptyStr(&string[a]); ++a) {
54 while (string[a]=='!') strcpy(&string[a],&string[a+1]);
55 while (string[a]=='@') strcpy(&string[a],&string[a+1]);
56 while (string[a]=='_') strcpy(&string[a],&string[a+1]);
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]);
67 * get a line of text from a file
68 * ignores lines starting with #
70 int getstring(FILE *fp, char *string)
85 } while(string[0]=='#');
86 return(strlen(string));
93 * mesg_locate() - locate a message or help file, case insensitive
95 void mesg_locate(char *targ, size_t n, const char *searchfor,
96 int numdirs, const char * const *dirs)
102 for (a=0; a<numdirs; ++a) {
103 snprintf(buf, sizeof buf, "%s/%s", dirs[a], searchfor);
104 if (!stat(buf, &test)) {
105 snprintf(targ, n, "%s/%s", dirs[a], searchfor);
113 #ifndef HAVE_STRERROR
115 * replacement strerror() for systems that don't have it
117 char *strerror(int e)
121 snprintf(buf,sizeof buf,"errno = %d",e);