4 * Server-side utility functions
20 * strproc() - make a string 'nice'
22 void strproc(char *string)
26 if (strlen(string)==0) return;
28 /* Convert non-printable characters to blanks */
29 for (a=0; a<strlen(string); ++a) {
30 if (string[a]<32) string[a]=32;
31 if (string[a]>126) string[a]=32;
34 /* Remove leading and trailing blanks */
35 while( (string[0]<33) && (strlen(string)>0) )
36 strcpy(string,&string[1]);
37 while( (string[strlen(string)-1]<33) && (strlen(string)>0) )
38 string[strlen(string)-1]=0;
40 /* Remove double blanks */
41 for (a=0; a<strlen(string); ++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; a<strlen(string); ++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));
87 * pattern2() - searches for patn within search string, returns pos
89 int pattern2(char *search, char *patn)
92 for (a=0; a<strlen(search); ++a) {
93 if (!strncasecmp(&search[a],patn,strlen(patn))) return(a);
100 * mesg_locate() - locate a message or help file, case insensitive
102 void mesg_locate(char *targ, char *searchfor, int numdirs, char **dirs)
108 for (a=0; a<numdirs; ++a) {
109 sprintf(buf,"cd %s; exec ls",dirs[a]);
110 ls = (FILE *) popen(buf,"r");
112 while(fgets(buf,255,ls)!=NULL) {
113 while (isspace(buf[strlen(buf)-1]))
114 buf[strlen(buf)-1] = 0;
115 if (!strcasecmp(buf,searchfor)) {
117 sprintf(targ,"%s/%s",dirs[a],buf);
128 #ifndef HAVE_STRERROR
130 * replacement strerror() for systems that don't have it
132 char *strerror(int e)
136 sprintf(buf,"errno = %d",e);