4 * Server-side utility functions
10 #include <sys/types.h>
16 #include <libcitadel.h>
22 * strproc() - make a string 'nice'
24 void strproc(char *string)
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)) )
42 while( (string[b]<33) && (!IsEmptyStr(&string[b])) )
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]);
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)
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)
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);
116 #ifndef HAVE_STRERROR
118 * replacement strerror() for systems that don't have it
120 char *strerror(int e)
124 snprintf(buf,sizeof buf,"errno = %d",e);