1 /* Citadel/UX support routines */
11 #include <sys/types.h>
12 #include <sys/ioctl.h>
25 void sttybbs(int cmd);
26 void newprompt(char *prompt, char *str, int len);
27 void val_user(char *user);
28 int intprompt(char *prompt, int ival, int imin, int imax);
29 void formout(char *name);
30 void logoff(int code);
31 void set_keepalives(int s);
32 void strprompt(char *prompt, char *str, int len);
33 void newprompt(char *prompt, char *str, int len);
34 void color(int colornum);
36 #define IFAIDE if(axlevel>=6)
37 #define IFNAIDE if (axlevel<6)
39 extern unsigned userflags;
40 extern char *axdefs[7];
41 extern char sigcaught;
42 extern struct CtdlServInfo serv_info;
43 extern char rc_floor_mode;
45 int struncmp(char *lstr, char *rstr, int len)
50 lc=tolower(lstr[pos]);
51 rc=tolower(rstr[pos]);
52 if ((lc==0)&&(rc==0)) return(0);
53 if (lc<rc) return(-1);
62 * check for the presence of a character within a string (returns count)
64 int haschar(char *st, int ch)
68 for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
74 * num_parms() - discover number of parameters...
76 int num_parms(char *source)
81 for (a=0; a<strlen(source); ++a)
82 if (source[a]=='|') ++count;
87 * extract() - extract a parameter from a series of "|" separated...
89 void extract(char *dest, char *source, int parmnum)
95 n = num_parms(source);
102 if ( (parmnum == 0) && (n == 1) ) {
107 while (count++ < parmnum) do {
109 } while( (strlen(buf)>0) && (buf[0]!='|') );
110 if (buf[0]=='|') strcpy(buf,&buf[1]);
111 for (count = 0; count<strlen(buf); ++count)
112 if (buf[count] == '|') buf[count] = 0;
117 * extract_int() - extract an int parm w/o supplying a buffer
119 int extract_int(char *source, int parmnum)
123 extract(buf,source,parmnum);
128 * extract_long() - extract a long parm w/o supplying a buffer
130 long extract_long(char *source, int parmnum)
134 extract(buf,source,parmnum);
138 void back(int spaces) /* Destructive backspace */
141 for (a=1; a<=spaces; ++a) {
142 putc(8,stdout); putc(32,stdout); putc(8,stdout);
146 void hit_any_key(void) { /* hit any key to continue */
149 printf("%s\r",serv_info.serv_moreprompt);
152 for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
156 if (b==NEXT_KEY) sigcaught = SIGINT;
157 if (b==STOP_KEY) sigcaught = SIGQUIT;
161 * change a user's access level
168 newprompt("User name: ",who,25);
169 sprintf(buf,"QUSR %s",who);
173 printf("%s\n",&buf[4]);
181 int set_attr(int sval, char *prompt, unsigned int sbit)
188 printf("%45s [", prompt);
190 printf("%3s", ((temp&sbit) ? "Yes":"No"));
194 a=yesno_d(temp&sbit);
197 if (!a) temp=(temp^sbit);
202 * modes are: 0 - .EC command, 1 - .EC for new user,
203 * 2 - toggle Xpert mode 3 - toggle floor mode
205 void enter_config(int mode)
207 int width,height,flags;
214 printf("%s\n",&buf[4]);
218 width = extract_int(&buf[4],0);
219 height = extract_int(&buf[4],1);
220 flags = extract_int(&buf[4],2);
222 if ((mode==0)||(mode==1)) {
224 width = intprompt("Enter your screen width",width,20,255);
225 height = intprompt("Enter your screen height",height,3,255);
227 flags = set_attr(flags,
228 "Are you an experienced Citadel user",US_EXPERT);
229 if ( ((flags&US_EXPERT)==0) && (mode==1))
231 flags = set_attr(flags,
232 "Print last old message on New message request",US_LASTOLD);
233 if ((flags&US_EXPERT)==0) formout("unlisted");
234 flags = set_attr(flags,"Be unlisted in userlog",US_UNLISTED);
235 flags = set_attr(flags,"Suppress message prompts",US_NOPROMPT);
236 if ((flags & US_NOPROMPT)==0)
237 flags = set_attr(flags,"Use 'disappearing' prompts",US_DISAPPEAR);
238 flags = set_attr(flags,
239 "Pause after each screenful of text",US_PAGINATOR);
240 if (rc_floor_mode == RC_DEFAULT) {
241 flags = set_attr(flags,
242 "View rooms by floor",US_FLOORS);
247 if (flags & US_EXPERT) {
248 flags = (flags ^ US_EXPERT);
249 printf("Expert mode now OFF\n");
252 flags = (flags | US_EXPERT);
253 printf("Expert mode now ON\n");
258 if (flags & US_FLOORS) {
259 flags = (flags ^ US_FLOORS);
260 printf("Floor mode now OFF\n");
263 flags = (flags | US_FLOORS);
264 printf("Floor mode now ON\n");
268 sprintf(buf,"SETU %d|%d|%d",width,height,flags);
271 if (buf[0]!='2') printf("%s\n",&buf[4]);
276 * getstring() - get a line of text from a file
277 * ignores lines beginning with "#"
279 int getstring(FILE *fp, char *string)
294 } while(string[0]=='#');
295 return(strlen(string));
298 int pattern(char *search, char *patn) /* Searches for patn in search string */
303 for (a=0; a<strlen(search); ++a)
304 { b=struncmp(&search[a],patn,strlen(patn));
310 void interr(int errnum) /* display internal error as defined in errmsgs */
312 printf("*** INTERNAL ERROR %d\n",errnum);
313 printf("(Press any key to continue)\n");
321 * Check to see if we need to pause at the end of a screen.
322 * If we do, we have to disable server keepalives during the pause because
323 * we are probably in the middle of a server operation and the NOOP command
324 * would confuse everything.
326 int checkpagin(int lp, int pagin, int height)
328 if (pagin!=1) return(0);
329 if (lp>=(height-1)) {
330 set_keepalives(KA_NO);
332 set_keepalives(KA_YES);
339 void strproc(char *string)
343 if (strlen(string)==0) return;
345 /* Convert non-printable characters to blanks */
346 for (a=0; a<strlen(string); ++a) {
347 if (string[a]<32) string[a]=32;
348 if (string[a]>126) string[a]=32;
351 /* Remove leading and trailing blanks */
352 while(string[0]<33) strcpy(string,&string[1]);
353 while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;
355 /* Remove double blanks */
356 for (a=0; a<strlen(string); ++a) {
357 if ((string[a]==32)&&(string[a+1]==32)) {
358 strcpy(&string[a],&string[a+1]);
363 /* remove characters which would interfere with the network */
364 for (a=0; a<strlen(string); ++a) {
365 if (string[a]=='!') strcpy(&string[a],&string[a+1]);
366 if (string[a]=='@') strcpy(&string[a],&string[a+1]);
367 if (string[a]=='_') strcpy(&string[a],&string[a+1]);
368 if (string[a]==',') strcpy(&string[a],&string[a+1]);
369 if (string[a]=='%') strcpy(&string[a],&string[a+1]);
370 if (string[a]=='|') strcpy(&string[a],&string[a+1]);
376 #ifndef HAVE_STRERROR
378 * replacement strerror() for systems that don't have it
380 char *strerror(int e)
384 sprintf(buf,"errno = %d",e);
390 void progress(long int curr, long int cmax)
392 static long dots_printed;
396 printf(".......................................");
397 printf(".......................................\r");
401 else if (curr==cmax) {
402 printf("\r%79s\n","");
405 a=(curr * 100) / cmax;
407 while (dots_printed < a) {
417 * NOT the same locate_host() in locate_host.c. This one just does a
418 * 'who am i' to try to discover where the user is...
420 void locate_host(char *hbuf)
426 who = (FILE *)popen("who am i","r");
428 strcpy(hbuf,serv_info.serv_fqdn);
435 for (a=0; a<strlen(buf); ++a) {
436 if ((buf[a]=='(')||(buf[a]==')')) ++b;
439 strcpy(hbuf,serv_info.serv_fqdn);
443 for (a=0; a<strlen(buf); ++a) {
445 strcpy(buf,&buf[a+1]);
448 for (a=0; a<strlen(buf); ++a) {
449 if (buf[a]==')') buf[a] = 0;
452 if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
453 else strncpy(hbuf,buf,24);
457 * miscellaneous server commands (testing, etc.)
459 void misc_server_cmd(char *cmd) {
466 while (serv_gets(buf), strcmp(buf,"000")) {
473 newprompt("> ",buf,255);
475 } while(strcmp(buf,"000"));
482 * compute the checksum of a file
484 int file_checksum(char *filename)
490 fp = fopen(filename,"r");
491 if (fp == NULL) return(0);
493 /* yes, this algorithm may allow cksum to overflow, but that's ok
494 * as long as it overflows consistently, which it will.
496 while (ch=getc(fp), ch>=0) {
497 cksum = (cksum + ch);
505 * nuke a directory and its contents
507 int nukedir(char *dirname)
513 dp = opendir(dirname);
518 while (d = readdir(dp), d != NULL) {
519 sprintf(filename, "%s/%s", dirname, d->d_name);
524 return(rmdir(dirname));