4 * Server-side utility functions
10 #include <sys/types.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; a<strlen(string); ++a) {
33 if (string[a]<32) string[a]=32;
34 if (string[a]>126) string[a]=32;
37 /* Remove leading and trailing blanks */
38 while( (string[0]<33) && (!IsEmptyStr(string)) )
39 strcpy(string,&string[1]);
40 while( (string[strlen(string)-1]<33) && (!IsEmptyStr(string)) )
41 string[strlen(string)-1]=0;
43 /* Remove double blanks */
44 for (a=0; a<strlen(string); ++a) {
45 if ((string[a]==32)&&(string[a+1]==32)) {
46 strcpy(&string[a],&string[a+1]);
51 /* remove characters which would interfere with the network */
52 for (a=0; a<strlen(string); ++a) {
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]);
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]);
66 * get a line of text from a file
67 * ignores lines starting with #
69 int getstring(FILE *fp, char *string)
84 } while(string[0]=='#');
85 return(strlen(string));
90 * pattern2() - searches for patn within search string, returns pos
92 int pattern2(char *search, char *patn)
95 for (a=0; a<strlen(search); ++a) {
96 if (!strncasecmp(&search[a],patn,strlen(patn))) return(a);
103 * mesg_locate() - locate a message or help file, case insensitive
105 void mesg_locate(char *targ, size_t n, const char *searchfor,
106 int numdirs, const char * const *dirs)
112 for (a=0; a<numdirs; ++a) {
113 snprintf(buf, sizeof buf, "%s/%s", dirs[a], searchfor);
114 if (!stat(buf, &test)) {
115 snprintf(targ, n, "%s/%s", dirs[a], searchfor);
123 #ifndef HAVE_STRERROR
125 * replacement strerror() for systems that don't have it
127 char *strerror(int e)
131 snprintf(buf,sizeof buf,"errno = %d",e);