home *** CD-ROM | disk | FTP | other *** search
- /* Peeker 2.22 copyright (c) 1988/89/90/91/92 by M. Kimes */
-
- #include "peeker.h"
-
- extern int _fastcall doswap (char far *, char far *);
-
- char * _fastcall myfgets (char *str,size_t num,int handle);
- int cdecl ffprintf (int handle,char *string,...);
- void hitreturn(void);
- void _fastcall cls (void);
- char _fastcall inkey (void);
- char _fastcall carrchk (void);
- char _fastcall fossil (char function, char arg);
- char _fastcall printm (char *text);
- char * _fastcall stripcr(char *);
- void cdecl deinitialize (void);
- char * genin (char length,char password,char caps,char hot,char type);
- ulong _fastcall getxbbstime(void);
- char * fidodate(void);
- char * getdttm(void);
- char _fastcall specialkey(char);
- char view (int,char *);
- void filesbbs(char *);
- void extract(char *);
- void _fastcall killall(void);
- int _fastcall findfile(char *,char *);
- int cdecl break_handler(void);
- char _fastcall readtext(char *,char *,int,char);
- char _fastcall printg(char *);
- char _fastcall skip_blanks(int fp);
- char _fastcall checkarchivers(char *);
- void chat(void);
- void printinfo(void);
- void cdecl bugprint(char *,...);
- void _fastcall spawnit(char *);
- int cdecl printfm(char *,...);
- char * _fastcall stristr(char *,char *);
- char _fastcall first_non_white (char *a);
- int _fastcall _wherex (void);
- int _fastcall _wherey (void);
- void _fastcall _sleep (int secs);
- void _fastcall cursor (int x, int y);
- void _fastcall curr_cursor (int *x, int *y);
- char * _fastcall avatar2ansi (int avatarcode);
- char * _fastcall assign (char *d,char *a);
- char * _fastcall add_backslash (char *d);
- void _fastcall stat_line (void);
- void _fastcall time_line (void);
- void _fastcall set_mtask(void);
- extern void _fastcall (*pause_mtask)(void);
- int _fastcall ansi_out(char *str);
- void _fastcall load_colors(void);
-
- struct _archiver {
- char ext[5];
- char move[41];
- char extract[41];
- char list[41];
- char error[41];
- char aname[13];
- char ename[13];
- char id[25];
- char pick[2];
- int skip;
- int errline;
- };
-
- struct _archiver *archiver;
-
- struct _directories {
- char *path;
- char *name;
- };
- struct _directories *dirs[200];
-
- char last_file[13]="";
- char graphics = 0;
- word timelimit = 30;
- word baud = 0;
- char pauser = 0;
- char numlines = 24;
- word lines = 0;
- int seclvl = 5;
- ulong startt = 0;
- char commport = 0;
- struct time starter;
- struct ffblk filestat;
- union REGS rg;
- char *directory = NULL;
- char *flsearch = NULL;
- char *xtract_dir = NULL;
- char *home_dir = NULL;
- char files_bbs[13] = "FILES.BBS";
- char jumped = 0;
- char tmpnm[7] = "";
- char exok = 0;
- char fbbs = 1;
- char help = 1;
- char exitstuff = 1;
- char username[36] = "I Dunno Who It Is";
- char width = 80;
- char track_dls = 0;
- char chatting = 0;
- char chatted = 0;
- char numarcs = 0;
- char numdirs = 0;
- char debug = 0;
- char *ctlfile = NULL;
- char *reader = NULL;
- char limittries = 0;
- char *peek_now = NULL;
- char useswapdisk = 'C';
- char LIMEMS = 0;
- char swap = 0;
- char buffer[256];
- long maxarc = 0;
- long totalsize = 0;
- char building = 0;
- char swapname[14];
- char cleanup = 1;
- int colors[] = {15,9,11,14,12,9,11,12,3,11,11,11,9,15,14,14,9,14,12,14,15,
- 14,12,14,13,14};
-
- extern unsigned _Cdecl _stklen = 8192; /* Stack length */
-
-
-
- void cdecl main(int argc,char *argv[]) {
-
- char s[134];
- char dostring[256];
- char choice,settask = 0;
- char ext[5];
- char *p;
- int register x;
- int register y;
- int fp;
- FILE *fptr;
- struct stat f;
- char error = 0,amenu = 1,gmenu = 1;
-
-
- set_screensize(1);
- ansi_out("\x1b[0m\x1b[2J");
- gettime(&starter);
- ctrlbrk(break_handler);
-
- if (argc == 2 && !stricmp(argv[1],"H")) {
- GiveHelp:
- ansi_out("\x1b[0;1;37m\x1b[2J\r\nPeeker v2.22 -- an XBBS Utility.\x1b[0m");
- printinfo();
- ansi_out("\r\nUsage: PEEKER.EXE args...\r\n");
- ansi_out("! (turns on debug mode)\r\n");
- ansi_out("#<#> (limits # of tries on wildcard to <#> (0-255)) \r\n");
- ansi_out("L<screen lines>\r\n");
- ansi_out("W<screen width>\r\n");
- ansi_out("T<time in minutes>\r\n");
- ansi_out("D<D:\\Path to files directory>\r\n");
- ansi_out("F<name of files.bbs-type file>\r\n");
- ansi_out("A<name of flsearch.ctl-type file>\r\n");
- ansi_out("B<baudrate (0-38400...?)>\r\n");
- ansi_out("G<graphics (0 or 1)>\r\n");
- ansi_out("C<commport (0=COM1)>\r\n");
- ansi_out("S<security level>\r\n");
- ansi_out("X<D:\\Path to extraction directory>\r\n");
- ansi_out("H<D:\\Path to home directory>\r\n");
- ansi_out("R<track d/l's by timestamp (0 or 1)>\r\n");
- ansi_out("V<videomode (0 = direct video, 1 = BIOS)>\r\n");
- ansi_out("M (no multitasker timeslicing)\r\n");
- ansi_out("N<control file name>\r\n");
- ansi_out("E<Filename> (External reader to use locally)\r\n");
- ansi_out("P<Filename> (D:\\Path\\File to peek at on entry)\r\n");
- ansi_out("I<EMS or D:> (Activate swap to EMS or disk)\r\n");
- ansi_out("U<User_Name) (Set user's name if ONLINE.XBS/USERINFO.XBS not available)\r\n");
- ansi_out("Z<maxK> (Set Build archive's maximum component size--0 disables)\r\n");
- cleanup = 0;
- exit(0);
- }
-
- for (x = 1;x < argc;x++) {
- if(*argv[x] == '-' || *argv[x] == '/')
- memmove(argv[x],&argv[x][1],strlen(argv[x]));
- switch (toupper(*argv[x])) {
- case 'L': numlines = (char)atoi(&argv[x][1]);
- break;
-
- case 'W': width = (char)atoi(&argv[x][1]);
- break;
-
- case 'D': directory = assign(directory,&argv[x][1]);
- break;
-
- case 'F': strncpy(files_bbs,&argv[x][1],12);
- files_bbs[12] = 0;
- break;
-
- case 'A': flsearch = assign(flsearch,&argv[x][1]);
- break;
-
- case 'B': baud = (word)atoi(&argv[x][1]);
- break;
-
- case 'G': if(atoi(&argv[x][1])) graphics = 1;
- break;
-
- case 'C': commport = (char)atoi(&argv[x][1]);
- break;
-
- case 'S': seclvl = atoi(&argv[x][1]);
- break;
-
- case 'X': xtract_dir = assign(xtract_dir,&argv[x][1]);
- break;
-
- case 'H': home_dir = assign(home_dir,&argv[x][1]);
- break;
-
- case 'R': if (atoi(&argv[x][1])) track_dls = 1;
- break;
-
- case 'T': timelimit = atoi(&argv[x][1]);
- break;
-
- case '!': debug = 1;
- break;
-
- case 'V': usebios = atoi(&argv[x][1]);
- break;
-
- case 'M': settask = 1;
- break;
-
- case 'N': ctlfile = assign(ctlfile,&argv[x][1]);
- break;
-
- case 'E': reader = assign(reader,&argv[x][1]);
- break;
-
- case '#': limittries = (char)atoi(&argv[x][1]);
- break;
-
- case 'P': peek_now = assign(peek_now,&argv[x][1]);
- break;
-
- case 'I': if (!stricmp(&argv[x][1],"EMS")) LIMEMS = 1;
- else if (argv[x][1]) useswapdisk = argv[x][1];
- swap = 1;
- break;
-
- case 'U': strncpy(username,&argv[x][1],36);
- username[35] = 0;
- if((p = strchr(username,'_')) != NULL) p = " ";
- break;
-
- case 'Z': maxarc = (long)(atol(&argv[x][1]) * 1024L);
- break;
-
- case '?': goto GiveHelp;
-
- default: ansi_out("\r\nUnknown argument `");
- ansi_out(argv[x]);
- ansi_out("'\r\n");
- _sleep(1);
- }
- }
-
- if(!settask) set_mtask();
-
- fossil(INIT,0);
- atexit(deinitialize);
-
- stat_line();
-
- if(!ctlfile || !*ctlfile) ctlfile = assign(ctlfile,"PEEKER.CTL");
-
- if (directory && *directory) {
- if (directory[strlen(directory) - 1] == '\\') directory[strlen(directory) - 1] = 0;
- }
-
- if (xtract_dir && *xtract_dir) xtract_dir = add_backslash(xtract_dir);
-
- if (home_dir && *home_dir) home_dir = add_backslash(home_dir);
- if (!home_dir || !*home_dir) {
- getcurdir(0,s);
- sprintf(dostring,"%c:\\%s\\",getdisk() + 'A',s);
- home_dir = assign(home_dir,dostring);
- if(!home_dir) {
- bugprint("Out of memory");
- cleanup = 0;
- exit(1);
- }
- }
-
- load_colors();
-
- sprintf(dostring,"%sPEEKER.HLP",home_dir);
- help = stat(dostring,&f);
- if(help) if(searchpath("PEEKER.HLP") != NULL) help = 0;
-
- sprintf(dostring,"%s%s",home_dir,"PEEKER.MNU");
- amenu = stat(dostring,&f);
- if(amenu) if(searchpath("PEEKER.MNU") != NULL) amenu = 0;
-
- sprintf(dostring,"%s%s",home_dir,"PEEKER.MNG");
- gmenu = stat(dostring,&f);
- if(gmenu) if(searchpath("PEEKER.MNG") != NULL) gmenu = 0;
-
- sprintf(dostring,"%sPEEKER.EXT",home_dir);
- exitstuff = stat(dostring,&f);
- if(exitstuff) if(searchpath("PEEKER.EXT") != NULL) exitstuff = 0;
-
- if (directory && *directory) {
- sprintf(dostring,"%s\\%s",directory,files_bbs);
- }
- else strcpy(dostring,files_bbs);
- fbbs = stat(dostring,&f);
-
- if ((fp = _open("USERINFO.XBS",O_RDONLY | O_BINARY | O_DENYNONE)) != -1) {
- myfgets(username,36,fp);
- username[36] = 0;
- _close(fp);
- stripcr(username);
- }
- else {
- if ((fp = _open("ONLINE.XBS",O_RDONLY | O_BINARY | O_DENYNONE)) != -1) {
- myfgets(username,36,fp);
- username[36] = 0;
- _close(fp);
- }
- }
- if (!*username) strcpy(username,"I Dunno Who It Is");
- username[31] = 0;
-
- if (stat(ctlfile,&f)) {
- printm("\r\nControl file not found.");
- CtlError:
- bugprint("Error w/ Control file %s",ctlfile);
- printm("\r\nPlease notify the SysOp.\r\n");
- cleanup = 0;
- exit(3);
- }
-
- if (f.st_size % (long)sizeof(struct _archiver)) {
- printm("\r\nError in Control file");
- goto CtlError;
- }
- numarcs = (int)(f.st_size / (long)sizeof(struct _archiver));
- if(!numarcs) {
- printm("\r\nI don't seem to have access to any archive types!\r\n");
- cleanup = 0;
- exit(1);
- }
- if ((fp = _open(ctlfile,O_RDONLY | O_DENYNONE | O_BINARY)) == -1) {
- printm("\r\nUnable to open Control file");
- bugprint("Can't open \"%s\"",ctlfile);
- goto CtlError;
- }
- archiver = (struct _archiver *)malloc((word)(sizeof(struct _archiver) * numarcs));
- if(!archiver) {
- bugprint("Out of memory");
- cleanup = 0;
- exit(4);
- }
- if (_read(fp,archiver,sizeof(struct _archiver) * numarcs) != sizeof(struct _archiver) * numarcs) {
- printm("\r\nError reading Control file");
- goto CtlError;
- }
- _close(fp);
-
- PurgeIn();
- if (peek_now && *peek_now) {
- if(flsearch) free(flsearch);
- flsearch = NULL;
- p = strrchr(peek_now,'\\');
- if (p) {
- *p = 0;
- directory = assign(directory,peek_now);
- p++;
- strcpy(peek_now,p);
- }
- }
- if (directory && *directory) directory = add_backslash(directory);
- if (peek_now && *peek_now) {
- if(flsearch) free(flsearch);
- flsearch = NULL;
- }
-
- if (flsearch && *flsearch) {
- if ((fp = _open(flsearch,O_RDONLY | O_BINARY | O_DENYNONE)) != -1) {
- printm("\r\nReading directories...");
- while (!eof(fp) && numdirs < 200) {
- if (myfgets(dostring,256,fp) == NULL) break;
- dostring[256] = 0;
- if (*dostring == '\n' || *dostring == ';') continue;
- dirs[numdirs] = (struct _directories *)malloc(sizeof(struct _directories));
- if(!dirs[numdirs]) {
- bugprint("Out of memory");
- cleanup = 0;
- exit(4);
- }
- stripcr(dostring);
- dirs[numdirs]->path = strdup(strtok(dostring," "));
- if(!dirs[numdirs]->path) {
- free(dirs[numdirs]);
- bugprint("Out of memory");
- continue;
- }
- dirs[numdirs]->path = add_backslash(dirs[numdirs]->path);
- if ((word)atoi(strtok(0," ")) > seclvl) continue;
- dirs[numdirs]->name = strdup(strtok(0," "));
- if(!dirs[numdirs]->name) {
- free(dirs[numdirs]->path);
- free(dirs[numdirs]);
- bugprint("Out of memory");
- continue;
- }
- while((p = strchr(dirs[numdirs]->name,'_')) != NULL) *p = ' ';
- printm(".");
- numdirs++;
- }
- _close(fp);
- }
- else bugprint("Unable to open FLSEARCH file");
- }
-
- if (!numdirs && (!directory && !*directory)) {
- printm("\r\nYou don't have access to any directories.\r\n");
- bugprint("Check user's security level or pass a Ddir argument.");
- bugprint("PEEKER H for brief help, or RTFM if required.");
- cleanup = 0;
- exit(0);
- }
-
- if (xtract_dir && *xtract_dir) {
- if (xtract_dir[1] == ':') {
- setdisk(toupper(*xtract_dir) - 'A');
- if (xtract_dir[strlen(xtract_dir) - 1] == '\\') xtract_dir[strlen(xtract_dir) - 1] = 0;
- if (!chdir (xtract_dir)) {
- exok = 1;
- if (*xtract_dir) {
- xtract_dir = add_backslash(xtract_dir);
- }
- killall();
- }
- else {
- free(xtract_dir);
- xtract_dir = NULL;
- }
- }
- }
-
- getxbbstime();
- ansi_out("\x1b[0m");
- cls();
- if(graphics) printm(avatar2ansi(colors[0]));
- printm("\r\nPeeker v2.22 -- an XBBS Utility.");
- printinfo();
- if (debug) {
- bugprint("\b \b\x1b[1A\04Handling %d archivers",numarcs);
- if (numdirs) {
- bugprint("\b \b\x1b[1A\04Handling %d directories",numdirs);
- }
- }
-
- if (peek_now && *peek_now) {
- if(directory && *directory)
- sprintf(dostring,"%s%s",directory,peek_now);
- else strcpy(dostring,peek_now);
- if (!findfirst(dostring,&filestat,0)) {
- peek_now = assign(peek_now,filestat.ff_name);
- strcpy(s,peek_now);
- printfm("\r\nPeeking at %s...\r\n",peek_now);
- goto DoPeekNow;
- }
- printfm("\r\nCan't find file `%s'\r\n",peek_now);
- cleanup = 0;
- exit(0);
- }
-
- for(;;) {
- if (peek_now && *peek_now) {
- if(exok) {
- if(xtract_dir && *xtract_dir && exok) killall();
- if(!error) {
- printfm("\r\nExtract from %s? (y-N) ",peek_now);
- if(*genin(1,0,1,1,YESNO) == 'Y') {
- extract(peek_now);
- }
- }
- }
- if(error) {
- cleanup = 0;
- exit(99);
- }
- exit(0);
- }
-
- printm("\r\n");
- stat_line();
- if(graphics) printm(avatar2ansi(colors[1]));
- printfm("\r\n%u mins\r\n",(timelimit - (word)(getxbbstime()) / 60L));
- if(graphics) printm(avatar2ansi(colors[2]));
- printm(" ");
-
- if(!amenu) {
-
- char *menufile = "PEEKER.MNU";
-
- if(graphics && !gmenu) menufile = "PEEKER.MNG";
- if (exok) sprintf(s,"%s%s",home_dir,menufile);
- else strcpy(s,menufile);
- printm("\r\n");
- if (stat(s,&f)) {
- if(searchpath(menufile) != NULL) strcpy(s,searchpath(menufile));
- if (stat(s,&f)) {
- goto NoMenu;
- }
- }
- if (!f.st_size) {
- goto NoMenu;
- }
- if((fp = _open(s,O_RDONLY | O_BINARY | O_DENYNONE)) == -1) {
- goto NoMenu;
- }
- pauser = 0;
-
- while (!eof(fp)) {
- if (myfgets(s,131,fp) == NULL) break;
- s[131] = 0;
- stripcr(s);
- if(s[strlen(s) - 1] != ';') strcat(s,"\r\n");
- else s[strlen(s) - 1] = 0; /* strip off cr/lf on lines ending w/ ; */
- printm(s);
- }
- _close(fp);
- }
- else {
- NoMenu:
- if (!fbbs) printm("[L]ist files");
- printm(" [C]ontents");
- if (exok) printm(" [E]xtract");
- if (!help) printm(" [H]elp");
- if (maxarc) printm(" [B]uild");
- printm(" [A]NSI [Q]uit: [Q] ");
- }
-
- choice = *genin(1,0,1,1,ALPHA);
-
- switch (choice) {
- case 'A': graphics = 1 - graphics;
- printm("NSI ");
- graphics ? printm("on") : printm("off");
- if (!graphics) printm("\r\n\x1b[0m\b \b\b \b\b \b\b \b");
- break;
-
- case 'L': if (!fbbs) {
- printm("ist\r\n");
- filesbbs(files_bbs);
- if (xtract_dir && *xtract_dir) killall();
- }
- else printm(BACKSPACE);
- break;
-
- case 'C': printm("ontents\r\nFile to list: ");
- *last_file = 0;
- if (findfile(dostring,s)) break;
- DoPeekNow:
- if (!stricmp(s,"FILES.BBS") || !stricmp(s,files_bbs)) {
- printm("\r\nThat's not an archive; try [L]ist.\r\n");
- break;
- }
- strcpy(tmpnm,"XXXXXX");
- if (mktemp(tmpnm) == NULL) {
- printm("\r\nUnable to create temporary file.\r\n");
- break;
- }
- *ext = 0;
- if ((p = strrchr(s,'.')) != NULL) strcpy(ext,&p[1]);
- for(x = 0;x < numarcs;x++) if (!stricmp(ext,archiver[x].ext)) break;
- if (x == numarcs) x = 0;
- if (!checkarchivers(archiver[x].aname)) break;
- if (xtract_dir && *xtract_dir) {
- if (!stat(s,&f)) {
- sprintf(dostring,"%s %s",archiver[x].list,s);
- }
- else if(directory)
- sprintf(dostring,"%s %s%s",archiver[x].list,directory,s);
- else sprintf(dostring,"%s %s",archiver[x].list,s);
- }
- else if(directory)
- sprintf(dostring,"%s %s%s",archiver[x].list,directory,s);
- else sprintf(dostring,"%s %s",archiver[x].list,s);
- SkipDir:
- printm("\r\nHold on, getting contents...");
- if((fptr = freopen(tmpnm,"w",stdout)) == NULL) {
- printm("\r\nFatal error...bye now...\r\n");
- bugprint("Aw, shit, can't redirect stdout\r\n");
- exit(1);
- }
- spawnit(dostring);
- fclose(fptr);
- freopen("CON","w",stdout);
- setbuf(stdout,NULL);
- for (y = 0;y < 28;y++) printm(BACKSPACE);
- strcpy(last_file,s);
- error = view(x,s);
- break;
-
- case 0: printm("Q");
- case 'Q': printm("uit\r\n");
- exit(0);
-
- case 'H': if (!help) {
- printm("elp\r\n");
- if (exok) sprintf(s,"%sPEEKER.HLP",home_dir);
- else strcpy(s,"PEEKER.HLP");
- printm("\r\n");
- if (stat(s,&f)) {
- if(searchpath("PEEKER.HLP") != NULL) strcpy(s,searchpath("PEEKER.HLP"));
- if (stat(s,&f)) {
- NoHelp:
- printm("Sorry, no help available...\r\n");
- break;
- }
- }
- if (!f.st_size) goto NoHelp;
- if((fp = _open(s,O_RDONLY | O_BINARY | O_DENYNONE)) == -1)
- goto NoHelp;
- if(graphics) printm(avatar2ansi(colors[3]));
- pauser = 1;
-
- while ((inkey() != ' ') && (!eof(fp))) {
- if (myfgets(s,81,fp) == NULL) break;
- s[80] = 0;
- stripcr(s);
- if (strlen(s) >= width) lines++;
- strcat(s,"\r\n");
- if (printm(s)) break;
- }
- pauser = 0;
- _close(fp);
- }
- else printm(BACKSPACE);
- break;
-
- case 'E': if (exok && xtract_dir && *xtract_dir) {
- printm("xtract\r\n");
- extract(NULL);
- }
- else printm(BACKSPACE);
- break;
-
- case 'B':
- if (exok && maxarc && xtract_dir && *xtract_dir) {
- killall();
- printm("uild\r\n");
- building = 1;
- extract(NULL);
- building = 0;
- }
- else printm(BACKSPACE);
- break;
-
- default: printm(BACKSPACE);
- }
- }
- }
-
-
- void cdecl bugprint (char *text,...)
-
- {
-
- va_list ap;
- va_start(ap,text);
- vsprintf(buffer,text,ap);
- va_end(ap);
- ansi_out("\r\n\04");
- ansi_out(buffer);
- ansi_out("\r\n");
-
- }
-
-
-
- void printinfo (void)
-
- {
- bugprint("Copyright (c) 1988/89/90/91/92 by M. Kimes");
- bugprint("Compiled: %s %s",__DATE__,__TIME__);
- }
-
-
-
- char _fastcall checkarchivers (char *fname)
-
- {
-
- if (!searchpath(fname)) {
- printm("\r\nSorry, I don't have access to that archiver/dearchiver.\r\n");
- return 0;
- }
- return 1;
- }
-
-
-
- int _fastcall findfile (char *dostring,char *s) {
-
- struct ffblk f;
- char smart[40]="\r\nDid you mean ";
- word register x=0;
- char temp[13];
- char numtries=0;
- char temporary;
-
-
- if (numdirs) directory = assign(directory,dirs[0]->path);
-
- if(*last_file) printfm("[%s] ",last_file);
- strcpy(s,genin(13,0,1,0,FLEW));
- if (!*s) {
- if(!*last_file) return 1;
- strcpy(s,last_file);
- }
- if ((strchr(s,'.') == NULL) && (strlen(s) < 9)) {
- if ((strlen(s) < 8) && (s[strlen(s) - 1] != '*')) {
- strcat(s,"*.*");
- printm("*.*");
- }
- else {
- strcat(s,".*");
- printm(".*");
- }
- }
- strcpy(temp,s);
- if (!findfirst(s,&f,0) && xtract_dir && *xtract_dir && !building) {
- if ((strchr(s,'?')) || (strchr(s,'*'))) {
- if (!stricmp(f.ff_name,"FILES.BBS") || !stricmp(f.ff_name,files_bbs)) goto ReTry;
- if(directory) sprintf(dostring,"%s%s",directory,f.ff_name);
- else strcpy(dostring,f.ff_name);
- printfm("%s%s? (Y-n)",smart,f.ff_name);
- temporary = *genin(1,0,1,1,YESNO);
- if (temporary == 'Y') {
- strcpy(s,f.ff_name);
- return 0;
- }
- }
- else {
- strcpy(s,f.ff_name);
- return 0;
- }
- }
- else if (xtract_dir && *xtract_dir && !building) killall();
- ReTry:
- if(directory) sprintf(dostring,"%s%s",directory,temp);
- else strcpy(dostring,temp);
- if (findfirst(dostring,&f,0)) {
- if (++x<numdirs) {
- directory = assign(directory,dirs[x]->path);
- numtries=0;
- goto ReTry;
- }
- else {
- if (!stricmp(smart,"\r\nHow about ")) goto Cant2;
- if(graphics) printm(avatar2ansi(colors[4]));
- printfm("\r\nCan't find %s\r\n",temp);
- return 1;
- }
- }
- else if (numdirs) {
- if(graphics) printm(avatar2ansi(colors[5]));
- printfm("\r\nIn Area: %s",dirs[x]->name);
- if(graphics) printm(avatar2ansi(colors[6]));
- }
- if ((strchr(dostring,'?')) || (strchr(dostring,'*'))) {
- FindLoop:
- if (!stricmp(f.ff_name,"FILES.BBS") || !stricmp(f.ff_name,files_bbs)) goto SkipIt;
- strcpy(s,f.ff_name);
- if(directory) sprintf(dostring,"%s%s",directory,s);
- else strcpy(dostring,s);
- printfm("%s%s? (Y-n-q) ",smart,s);
- temporary = *genin(1,0,1,1,YESNOQ);
- if (temporary == 'Q') return 1;
- if (temporary == 'N') {
- SkipIt:
- if (findnext(&f)) {
- if (++x<numdirs) {
- directory = assign(directory,dirs[x]->path);
- numtries = 0;
- goto ReTry;
- }
- else {
- Cant2:
- if(graphics) printm(avatar2ansi(colors[7]));
- printm("\r\nNo more matching files.\r\n");
- return 1;
- }
- }
- numtries++;
- if ((limittries) && (numtries>limittries)) {
- printm("\r\nWell, try to be a little more specific.\r\n");
- return 1;
- }
- strcpy(smart,"\r\nHow about ");
- goto FindLoop;
- }
- }
- return 0;
- }
-
-
- int cdecl break_handler(void) {
-
- deinitialize();
- return 0;
- }
-
-
- void extract (char *file) {
-
- char fname[14];
- char s[81];
- char dostring[256];
- char ext[5];
- char extfiles[10][14];
- int register x;
- int fp;
- char temp = 0;
- char arcstring[37] = "";
- int type = 0;
- struct ffblk f;
- char *p;
-
- ReDo:
- extfiles[9][0] = 0;
- if(file == NULL) {
- if(graphics) printm(avatar2ansi(colors[8]));
- if(building) printfm("\r\n%ld bytes total component size allowed.",maxarc);
- if(building && totalsize) {
- printfm("\r\n%ld bytes extracted so far.",totalsize);
- printm("\r\nHit [Enter] alone to create archive.");
- *last_file = 0;
- }
- printm("\r\nFile to extract from: ");
- if (findfile(dostring,s)) {
- if(building && totalsize) {
- if(!*s) goto DoneBuilding;
- else goto ReDo;
- }
- return;
- }
- if (!stricmp(s,"FILES.BBS")) {
- printm("\r\nFILES.BBS isn't an archive.\r\n");
- if(building)goto ReDo;
- else return;
- }
- } else strcpy(s,file);
- totalsize = 0;
- strcpy(fname,s);
- if(graphics) printm(avatar2ansi(colors[9]));
- printm("\r\nYou may specify up to nine files to extract (wildcards acceptable).\r\n");
- printm("\r\nHit [Enter] alone when finished.\r\n");
- for (x = 0;x < 9;x++) {
- printfm("\r\nFilename #%d: ",x+1);
- strcpy(extfiles[x],genin(13,0,1,0,FLEW));
- if (!*extfiles[x]) {
- break;
- }
- }
- if (!*extfiles[0] || extfiles[x] == NULL) {
- if(building) goto ReDo;
- else return;
- }
- if(graphics) printm(avatar2ansi(colors[10]));
- printm("\r\nHang on, extracting files...\r\n");
-
- *ext = 0;
- if ((p = strrchr(fname,'.')) != NULL) strcpy(ext,&p[1]);
- *dostring = 0;
-
- for (x = 0;x < numarcs;x++) if (!stricmp(ext,archiver[x].ext)) break;
- if (x == numarcs) type = 0;
- else type = x;
- if (!checkarchivers(archiver[type].ename)) return;
- if (xtract_dir && *xtract_dir) if (!findfirst(fname,&f,0)) {
- sprintf(dostring,"%s %s",archiver[type].extract,fname);
- goto SkipCurDir;
- }
- if(directory)
- sprintf(dostring,"%s %s%s",archiver[type].extract,directory,fname);
- else sprintf(dostring,"%s %s",archiver[type].extract,fname);
- SkipCurDir:
- for (x = 0;x < 9;x++) {
- if (!*extfiles[x] || !extfiles[x]) break;
- strcat(dostring," ");
- strcat(dostring,extfiles[x]);
- if (strlen(dostring) > 132) {
- dostring[132] = 0;
- printm("\r\nString overflowed DOS command line limit...all files may not extract\r\n");
- break;
- }
- }
- spawnit(dostring);
- if (xtract_dir && *xtract_dir) unlink(fname);
- if(graphics) printm(avatar2ansi(colors[11]));
- x = findfirst("*.*",&filestat,0);
- if (x) {
- printm("\r\nAttempt failed.\r\n");
- if(building)goto ReDo;
- else return;
- }
- sprintf(dostring,"%sXBBS.LOG",home_dir);
- if((fp=_open(dostring,O_RDWR | O_BINARY | O_DENYWRITE | O_APPEND))==-1)
- fp = creat(dostring,S_IWRITE);
- if(fp != -1) {
- temp++;
- lseek(fp,0L,SEEK_END);
- }
- printm("\r\nExtracted files");
- if(building) printm(" so far");
- printm(":\r\n");
- if (temp) ffprintf(fp,"Extracted files:\r\r\n");
- while (!x) {
- printfm("%-13s -- %lu bytes\r\n",filestat.ff_name,filestat.ff_fsize);
- if (temp) ffprintf(fp,"%-13s -- %lu bytes\r\n",filestat.ff_name,filestat.ff_fsize);
- totalsize += filestat.ff_fsize;
- x = findnext(&filestat);
- }
- if(totalsize && temp)ffprintf(fp,"%lu bytes total\r\n",totalsize);
- if(temp)_close(fp);
- if(!building)totalsize=0;
- else {
- if(totalsize<maxarc) goto ReDo;
- else printm("\r\nMaxed out for this trip...\r\n");
- }
- DoneBuilding:
- unlink("PEEKAT.ME");
- if((fp=_open("PEEKAT.ME",O_RDWR | O_BINARY | O_DENYWRITE))==-1)
- fp=creat("PEEKAT.ME",S_IWRITE);
- if(fp!=-1) {
- ffprintf(fp,"This is your PEEKER-prepared archive extracted from ");
- if(!building)ffprintf(fp,fname);
- else ffprintf(fp,"various files");
- ffprintf(fp,".\r\n");
- _close(fp);
- }
-
- strset(arcstring,0);
- printm("\r\n\r\nDo you want your files:\r\n");
- for (x=0;x<numarcs;x++) {
- if (searchpath(archiver[x].aname) && *archiver[x].pick) {
- if(*archiver[x].id && *archiver[x].pick && *archiver[x].pick!=' ') {
- printm(archiver[x].id);
- strcat(arcstring,archiver[x].pick);
- printm("\r\n");
- }
- }
- }
- strcat(arcstring,"Q");
- printm(" -> ");
- ReTryThat:
- x = (*genin(1,0,1,1,ALPHANUM));
- if (x == 'Q') {
- printm("uit\r\n");
- killall();
- return;
- }
- if (!x) x = archiver[0].pick[0];
- type = x;
- for (x = 0;x < numarcs;x++) {
- if (type == archiver[x].pick[0]) {
- type = x;
- break;
- }
- }
- if (type >= numarcs) {
- if (debug) bugprint("Can't find selected archiver!");
- printm("\07\r\nTry again: ");
- goto ReTryThat;
- }
- sprintf(dostring,"%s XFILE.%s *.*",archiver[type].move,archiver[type].ext);
- if(graphics) printm(avatar2ansi(colors[12]));
- printm("\r\nPlease hold, recombining files...\r\n");
- spawnit(dostring);
- if (findfirst("XFILE.*",&filestat,0)) {
- printm("\r\nAttempt failed.\r\n");
- killall();
- return;
- }
- if(graphics) printm(avatar2ansi(colors[13]));
- printfm("\07\r\n%s (%lu bytes) is now ready for downloading.\r\n",filestat.ff_name,filestat.ff_fsize);
- if (exitstuff) hitreturn();
- if (!exitstuff) {
- sprintf(dostring,"%sPEEKER.EXT",home_dir);
- if((fp = _open(dostring,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
- if(searchpath("PEEKER.EXT") != NULL) strcpy(dostring,searchpath("PEEKER.EXT"));
- if((fp = _open(dostring,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
- bugprint("Can't open %s",dostring);
- hitreturn();
- cleanup = 0;
- exit(100);
- }
- }
- myfgets(s,81,fp);
- if (strlen(s)) s[strlen(s) - 1] = 0;
- if (strlen(s)>36) s[36] = 0;
- strcpy(arcstring,s);
- while (!eof(fp) && myfgets(s,81,fp)) printm(s);
- _close(fp);
- if (!*arcstring) {
- hitreturn();
- cleanup = 0;
- exit (100);
- }
- printm("\r\nPlease select: ");
- TryAgain:
- x = (*genin(1,0,1,1,ALPHANUM));
- if ((strchr(arcstring,x) == NULL) || (!x)) {
- printm(BACKSPACE);
- printm("\07");
- goto TryAgain;
- }
- cleanup = 0;
- exit((char)x);
- }
- cleanup = 0;
- exit (100);
- }
-
-
-
- void _fastcall spawnit (char *a) {
-
- char *e[26];
- char *p;
- char *pp;
- register word x;
- int level = 0;
- union REGS r;
- struct time dos_time;
-
-
- if (debug) bugprint(a);
- {
- int oldx,oldy;
-
- curr_cursor(&oldx,&oldy);
- cursor(0,maxy - 1);
- ansi_out("\x1b[0m\x1b[K");
- cursor(oldx,oldy);
- }
- if (swap) {
- p = strtok(a," ");
- if (!p) return;
- if (!strchr(p,':') && !strchr(p,'\\')) p = searchpath(a);
- if (!p) {
- bugprint("No filename to execute.");
- return;
- }
- if(!strchr(p,'.')) {
- bugprint("No extension on filename.");
- return;
- }
- pp = strchr(p,'.');
- if(stricmp(pp,".COM") && stricmp(pp,".EXE")) {
- bugprint("Invalid filename extension.");
- return;
- }
- pp = strtok(0,"\r\n");
- if (!pp) pp = "";
- gettime(&dos_time);
- sprintf(swapname,"%02u%02u%02uPE.EKR",dos_time.ti_hour,dos_time.ti_min,dos_time.ti_sec);
- level = doswap(p,pp);
- if (level != (-1)) goto Getlevel;
- else {
- if(!debug) bugprint("Couldn't swap");
- for (x = 0;x < 26;x++) e[x]=NULL;
- e[0] = p;
- e[1] = strtok(pp," ");
- for(x = 2;(e[x] = strtok(0," "));x++) if(x == 25) break;
- goto DoSpawn;
- }
- }
- for (x = 0;x < 26;x++) e[x] = NULL;
- e[0] = strtok(a," ");
- for (x = 1;(e[x] = strtok(0," "));x++) if (x == 25) break;
- DoSpawn:
- level = (int)spawnvp(P_WAIT,a,e);
- Getlevel:
- if (!level) {
- r.h.ah = 77;
- int86(33,&r,&r);
- level = (int)r.h.al;
- }
- Nolevel:
- set_screensize(1);
- validate_cursor();
- stat_line();
- if (debug) {
- bugprint("Exit status: %hu",level);
- }
- }
-
-
-
- void _fastcall killall (void) {
-
- char killstring[133];
- char tempstring[142];
- struct ffblk f;
-
-
- if (xtract_dir && *xtract_dir) {
- sprintf(killstring,"%s*.*",xtract_dir);
- while (!findfirst(killstring,&f,0)) {
- sprintf(tempstring,"%s%s",xtract_dir,f.ff_name);
- unlink(tempstring);
- }
- }
-
- }
-
-
- ulong _fastcall getxbbstime (void) {
-
- int hour,min,sec;
- struct time dos_time;
- static ulong xbbs_time = 1L,lasttime = 0L;
- static int warned;
-
-
- gettime(&dos_time);
- hour = dos_time.ti_hour - starter.ti_hour;
- min = dos_time.ti_min - starter.ti_min;
- sec = dos_time.ti_sec - starter.ti_sec;
- if (dos_time.ti_hour < starter.ti_hour) hour += 24;
- xbbs_time = (long)((long)hour * 3600L) + ((long)min * 60L) + (long)sec;
-
- if(lasttime != xbbs_time) {
- lasttime = xbbs_time;
-
- if (warned && (((long)timelimit * 60L) > ((xbbs_time + 1L) + 120L)))
- warned = 0;
- else if(!warned) {
- if ((((long)timelimit * 60L) < (xbbs_time + 120L))) {
-
- char tempause;
-
- warned++;
- tempause = pauser;
- pauser = 2;
- printfm("\r\nWARNING: %ld minutes remaining.\r\n",((long)timelimit - (xbbs_time) / 60L));
- pauser = tempause;
- }
- }
-
- if (((long)timelimit * 60L) < (xbbs_time + 1L)) {
- timelimit = (word)(xbbs_time / 60L) + 4;
- pauser = 0;
- printm("\r\nSorry, time to logoff...\r\n");
- FlushOut();
- _sleep(1);
- exit(0);
- }
-
- time_line();
- }
-
- juststarting:
-
- return xbbs_time;
- }
-
-
- void hitreturn(void) {
-
- int register x;
-
-
- startt = getxbbstime();
- lines = 0;
- printm("\r\n[Enter] to continue...");
- while ((getxbbstime() - startt) < 241) {
- if (inkey() == '\r') goto HeDid;
- (*pause_mtask)();
- }
- bugprint("User time-out...");
- exit (2);
- HeDid:
-
- lines = 0;
- }
-