home *** CD-ROM | disk | FTP | other *** search
- #include "crcpchdr.h"
-
- char *incptr(ptr) /* Increment pointer only if not pointing at NULL char */
- char *ptr;
- {
- return ((*ptr)?stpblk(++ptr):ptr);
- }
-
- int notnull(str)
- char *str;
- {
- for (;*str;str++) if (*str>' ') return 1;
- return 0; /* All spaces or control codes in [ASCII] string */
- }
-
- static char get_cmd(args)
- char *args;
- {
- struct cmd_list *search;
- char word[20];
-
- stptok(args,word,sizeof(word)," ");
- uppercase(word);
- for (search=commands;search!=NULL;search=search->next) {
- if (abbrev(search->name,word,search->abrl)) {
- if (search->class<=userclass) return(search->cmd_id);
- }
- }
- return('\0'); /* didnt find it */
- }
-
-
- init_vars()
- {
- tflag = deftflag;
- termtype = deftermtype;
- utwidth = defutwidth;
- utlength = defutlength;
- utcls[0] = '\0';
- maxconnect = defmaxconnect; /* Allow user on at max this many min.s */
- nousrto = FALSE; /* Also initialized by 'read_userfile()'*/
- nousrfort = FALSE; /* " " " " */
- noforcenow = TRUE; /* */
- beingforced = FALSE; /* But not doing it yet */
- beginner = defbeginner;
- termwidth = deftermwidth;
- duplex = defduplex;
- }
-
- char menu(retopts,retquiet)
- char **retopts;
- int *retquiet;
- {
- char c,d;
- char filename[15];
- char destfile[15];
- char *type;
- char *ftype;
- char *delete;
- int gnl_flag, quiet;
- static char inpbuff[LINESIZE+2];
- static char options[20];
- char *args, *getenv();
-
- if (!beginner) goto skipcrap;
- drawit:
- cls();
- output = TRUE;
- printf("\r\n%s %s - User: %s - %s %s\r\n\r\n",SYSNAME,SYSVER,user_id,date(),time());
- help(MENUFILE,"t");
- cr();
-
- skipcrap:
- gnl_flag = FALSE;
- forever {
- output = TRUE ;
- *retquiet = FALSE;
- *retopts = "";
- if (beingforced) {
- beingforced = FALSE;
- return('Y');
- }
- prompt();
- args = disp_reply("",inpbuff,LINESIZE);
- if (!dsr()) return('Q');
- uppercase(args); /* UPPERCASE ALL ARGUMENTS */
- c = get_cmd(args);
- args = strip_options(skptok(args),options);
- quiet = find_option(options,'q');
- *retquiet = quiet; /* Pass back to caller if 'Q' cmmd */
- *retopts = options; /* " */
- switch(c) { /* SWITCH */
- case '?': goto drawit;
- break; case '~': dossys(getenv(UTIL_PROG),FALSE);
- break; case '+': dossys(skptok(inpbuff),TRUE);
- break; case '=': dossys(skptok(inpbuff),FALSE);
- break; case '_': runfile(skptok(inpbuff),TRUE);
- break; case '-': runfile(skptok(inpbuff),FALSE);
- break; case '/': user_set(c,args,options);
- break; case '#': mk_dir(c,args,options);
- break; case '%': rm_dir(c,args,options);
- break; case '@': xfer_file(c,args,options);
- break; case '$': any_news(c,args,options);
- break; case '!': see_dtables(c,args,options);
- break; case '*': do_fort(c,args,options);
- break; case '"': dup_file(c,args,options);
- break; case 'A': ask_sysop(c,args,options);
- break; case 'B': buzz_sysop(c,args,options);
- break; case 'C': create_file(c,args,options);
- break; case 'D': disp_dir(c,args,options);
- break; case 'E': erase_file(c,args,options);
- break; case 'F': fork_board(c,args,options);
- break; case 'G': go_dir(c,args,options);
- break; case 'H': yell_help(c,args,options);
- break; case 'I': help(SYSINFO,options);
- break; case 'J': jump_dir(c,args,options);
- break; case 'K': kill_board(c,args,options);
- break; case 'L': list_file(c,args,options);
- break; case 'M': msg_sys(c,args,options);
- break; case 'N': change_password(c,args,options);
- break; case 'O': other_systems(c,args,options);
- break; case 'P': mail(c,args,options);
- break; case 'Q':
- if (find_option(options,'!')) c = 'Y';
- else if (!(c=args[0])) {
- if (!quiet && beginner)
- printf("You are about to leave this system.\r\n");
- c = *disp_reply("Are you sure ? ",filename,4);
- }
- c = toupper(c);
- if (stpchr("YQX",c)==NULL) {
- nothing_done();
- break;
- }
- if (c == 'Y') return c;
- else if (c == 'Q') return c;
- else if (c == 'X') {
- if (!strcmp(input_pw(9),exit_pw)) return c;
- }
- break; case 'R': rename_file(c,args,options);
- break; case 'S': smfile(c,args,options);
- break; case 'T': type_file(c,args,options);
- break; case 'U': user_data(c,args,options);
- break; case 'V': scan_events(c,args,options);
- break; case 'W': who_is(c,args,options);
- break; case 'X': beginner = !beginner; expertstatus();
- break; case 'Y': systat(c,args,options);
- break; case 'Z': ask_sysop(c,args,"qf");
- break; default: mputs("Type '?' for menu, type 'H' for help\r\n");
- } /* END SWITCH */
- sysdir(cur_dir,cur_root); /* Make sure on current directory */
- } /* FOR EVER */
- }
- /* END MENU */
-
- yell_help(c,args,opts)
- char c;
- char *args;
- char *opts;
- {
- int rc;
- strcat(opts,"u"); /* UPPERCASE; do not respect case for compare */
- rc = helplib(args,opts);
- if (rc==0) {
- if (!*args) printf("Enter \"HELP name\" using name from above list\r\n");
- }
- else if (rc==-1) printf("Nothing found.\r\n");
- else if (rc==1000) printf("* abort *\r\n");
- else printf("Help error: %d.\r\n",rc);
- }
-
- char *prompt_str(level)
- int level;
- {
- if (level) return("Enter command or ? for menu");
- else return(cur_dir);
- }
-
- /* NOTE: If DEFLT true, then NULL command defaults to loading DOS */
- static int dossys(str,deflt)
- char *str;
- int deflt;
- {
- char *getenv();
- int rc;
- char doscmd[LINESIZE];
-
- if (str==NULL) return(nothing_done());
- if (!*(str=stpblk(str))) {
- if (!deflt) return(nothing_done());
- if ((str=getenv(COMSPEC))==NULL) str = DEFLT_SYSCMD;
- disp_msg(50); /* Print default CMD instructions */
- }
- stccpy(doscmd,str,sizeof(doscmd)); /* In case DOS plays with this */
- rc = system(doscmd);
- if (rc) printf("R(%d);\n",rc);
- return(rc);
- }
-
- static int runfile(str,deflt)
- char *str;
- {
- char *offense;
-
- if (*str && (offense=stpbrk(str,INVDOSCMDCHR))!=NULL)
- return(bad_fn(*offense));
- return(dossys(str,deflt));
- }
-
- /* CHAT is called from bottom level routines MGETS and MPUTS */
- chat()
- {
- char line_buff[STR_SIZE+2];
-
- cls();
- printf("\r\n\nChat mode - Control-Z gets out\r\n\n");
- line_buff[0]=STR_SIZE+1;
- do {
- cgets(line_buff);
- printf("\n");
- } while(stpchr(&line_buff[2],CTLZ)==NULL);
- printf("\r\n\nReturning to previous task: \r\n\n");
- }
-
-
- eraselog() { if (!sysdir("",MAILBOX)) unlink(EVENT_LOG); }
-
-
- openlog()
- {
- if (nolog) event_fp=NULL;
- else {
- if (sysdir("",MAILBOX)) event_fp=NULL;
- else event_fp=fopen(EVENT_LOG,"a");
- if (event_fp==NULL) printf("NOTE: Event log could not be opened.\r\n");
- }
- }
-
-
- closelog()
- {
- if (event_fp!=NULL) {
- sysdir("",MAILBOX); /* DO WE NEED TO DO THIS ? */
- fclose(event_fp);
- event_fp = NULL;
- }
- }
-
-
- logevent(event)
- char event[];
- {
- char timestr[32];
- strcpy(timestr,timedate());
- strcat(timestr," ");
- if (event_fp==NULL) return;
- writeln2(event_fp,timestr,event);
- }
-
-
- /* These routines should later be removed to lower levels, such as -MD1 or MD2.
- (MAYBE EVEN -BOT)
- */
-
- char *timedate()
- {
- static char timebuff[20];
- int hh,mm,ss,ms;
- int mo,dy,yr;
- sysdate(&mo,&dy,&yr);
- systime(&hh,&mm,&ss,&ms);
- sprintf(timebuff,"%02d/%02d %02d:%02d",mo,dy,hh,mm);
- return(timebuff);
- }
-
-
-
- char *file_prompt(level,function)
- int level;
- char function[];
- {
- static char rb[LINESIZE+2];
- if (level) {
- sprintf(rb,"Enter name of file to %s: ",function);
- return(rb);
- }
- else return("File? ");
- }
-
-
- int test_password()
- {
- char *string;
-
- if (syspw[0]=='\0') return(TRUE); /* No password - let him on */
- else {
- printf("pw: ");
- string = input_pw(9);
- return(!strcmp(string,syspw));
- }
- }
-
-
- int finput(filename,opts)
- char filename[];
- char *opts;
- {
- FILE *fp;
- char c;
- char line[STR_SIZE+4];
- int eof, linect, rc;
- int quiet;
-
- quiet = find_option(opts,'q');
- if (*filename == '\0') return(nothing_done()&0+1);
- else if ((fp=fopen(filename,"r")) != NULL) {
- fclose(fp);
- if (find_option(opts,'a')) c = 'Y';
- else {
- printf("File already exists.\r\nWant to add lines to it ? ");
- c = *ltrim(lineinput(2));
- }
- if (toupper(c)!='Y') {
- printf("Use the ERASE command first.\r\n");
- return(nothing_done()&0+1);
- }
- }
- if ((fp=fopen(filename,"a")) == NULL) {
- not_open();
- return(2);
- }
- else {
- if (!quiet) mputs("Enter input lines below, terminate with CTL-Z followed by <CR>.\r\n");
- linect = 0;
- rc = 0;
- noforcenow = TRUE;
- do {
- strcpy(line,lineinput(STR_SIZE));
- if (!dsr()) break;
- eof = (stpchr(line,CTLZ)!=NULL);
- del_crlf(line);
- if (!eof) strcat(line,"\r\n"); /* Add text line end markers */
- if (fputs(line,fp)==EOF) {
- printf("DISK FULL or other error writing output file.\r\n");
- rc = 3;
- break;
- }
- else linect++;
- } while (!eof);
- noforcenow = FALSE;
- if (fclose(fp)) {
- printf("Error while closing file.\r\n");
- return(4);
- }
- if (!quiet) printf("\r\n%d lines written to file '%s'\r\n",linect,filename);
- return(rc);
- }
- }
-
-
- /* Parses normal "MM/DD/YY" form date into *PMO, *PDY, *PYR */
- extr_date(str,pmo,pdy,pyr)
- char *str;
- int *pmo, *pdy, *pyr;
- {
- char cmo[4], cdy[4], cyr[4];
-
- *cmo = *cdy = *cyr = '\0';
- if (str) str = stptok(stpblk(str),cmo,sizeof(cmo),"/. ");
- if (str) str = stptok(++str,cdy,sizeof(cdy),"/. ");
- if (str) str = stptok(++str,cyr,sizeof(cyr),"/. ");
- *pmo = stoi(cmo);
- *pdy = stoi(cdy);
- *pyr = stoi(cyr);
- }
-
-
- /* CREATE_LIST: We have already set up the DTA and issued a successsful
- FIND_FIRST call to it. We start allocating lines to it. */
- create_list()
- {
- int rc;
- rc = 0;
- while(!rc) {
- if (rc = add_list(&ftab_ptr->filedata)) ;
- else rc = mdos(NEXT_FILE);
- }
- }
-
- /*****************************************************************************
- * add_list: Add an 'element' (filedate/attrib/time/name info) to next *
- * (list_idx+1) element in string array. *
- *****************************************************************************/
- int add_list(elemt)
- struct fileinfo *elemt;
- {
- struct dir_entry *newptr;
-
- /* Obtain a memory for this elemt in the string array */
- if ((newptr=(struct dir_entry *)getmem(sizeof(**list)))==NULL) {
- warn_omem();
- return(100);
- }
- /* Error if cannot get memory, else move the elemt into its place */
- /* (move elemt into fileinfo structure (FILEDATA)) */
- else movmem((char *)elemt,(char *)&newptr->filedata,sizeof(*elemt));
-
- /* Put it in the array as next element, using LIST_IDX as index */
- list[list_idx++] = newptr;
-
- /* Initialize value field to numeric value of filetype */
- /* Read extension of file, taking numeric value from it */
- newptr->value = stoi(file_ext(newptr->filedata.filename_ext));
-
- /* Good return - element added to list */
- return(0);
- }
-
- /*****************************************************************************
- * drop_list: de-allocate the entire string array (use RLSMEM) *
- *****************************************************************************/
- drop_list()
- {
- while(list_idx--) {
- if (rlsmem((char *)list[list_idx],sizeof(**list)))
- printf("Error during RLSMEM\r\n");
- }
- list_idx = 0;
- }
-
- /*****************************************************************************
- * SORT_LIST: Sort the string array into ascending order, by VALUE. *
- *****************************************************************************/
- /* We have array in memory of pointers to structure type DIR_elemt.
- we must sort this array according to ascending values found
- in the 'value' variable in each structure.
- Note that since the data will be partially sorted, we will use the
- bubble sort to take advantage of the partial sorted order.
- (besides, its the only one i know by heart) */
-
- sort_list(list,n)
- struct dir_entry *list[];
- int n;
- {
- int j;
- int swapped;
- struct dir_entry *temp;
-
- swapped = TRUE;
- while(swapped) {
- swapped = FALSE;
- for (j=0;j<n-1;++j)
- if (list[j]->value>list[j+1]->value) {
- swapped = TRUE;
- temp = list[j];
- list[j] = list[j+1];
- list[j+1] = temp;
- }
- }
- }
-
-
- char *file_ext(fn)
- char *fn;
- {
- char *p;
-
- if ((p=stpchr(fn,'.'))==NULL) return("");
- else return(p+1);
- }
-
- char *get_name(dest,sourcefn)
- char *dest, *sourcefn;
- {
- char *p;
- int l;
-
- if ((p=stpchr(sourcefn,'.'))==NULL) strcpy(dest,sourcefn);
- else {
- l = p-sourcefn; /* Get num chars in name */
- if (l>0) { /* I Don't trust myself */
- movmem(sourcefn,dest,l); /* Move in just filename */
- }
- else l = 0;
- dest[l] = '\0'; /* Make printable string of it */
- }
- return(dest);
- }
-
- help(helpfile,opts)
- char helpfile[];
- char *opts;
- {
- char filename[DIRSIZE+17];
- prefix_dir(filename,helpfile,hpath);
- typefile(filename,opts);
- }
-
- long cnct_seconds()
- {
- int hh,mm,ss,ms;
- systime(&hh,&mm,&ss,&ms);
- return(time_diff(login_hh,login_mm,login_ss,hh,mm,ss));
- }
-
- print_cd()
- {
- printf("Current directory: %s\r\n",*cur_dir?cur_dir:"(node)");
- if (strcmp(user_root,cur_root) && *cur_root)
- printf("Current root: %s\r\n",cur_root);
- }
-