head 1.10; access ; symbols ; locks ; comment @ * @; 1.10 date 89.06.15.21.24.10; author pkern; state Exp; branches ; next 1.9; 1.9 date 89.03.23.13.28.40; author pkern; state Exp; branches ; next 1.8; 1.8 date 89.03.23.13.25.12; author pkern; state Exp; branches ; next 1.7; 1.7 date 89.03.01.12.32.54; author pkern; state Exp; branches ; next 1.6; 1.6 date 89.02.06.13.38.19; author pkern; state Exp; branches ; next 1.5; 1.5 date 89.02.03.15.53.46; author pkern; state Exp; branches ; next 1.4; 1.4 date 89.01.31.14.09.23; author pkern; state Exp; branches ; next 1.3; 1.3 date 89.01.31.14.08.19; author pkern; state Exp; branches ; next 1.2; 1.2 date 89.01.31.13.29.52; author pkern; state Exp; branches ; next 1.1; 1.1 date 89.01.05.16.34.59; author pkern; state Exp; branches ; next ; desc @@ 1.10 log @*** empty log message *** @ text @/* * main.c: * main() and some misc. routines * * Copyright (c) 1989 University of Toronto. All rights reserved. * Anyone may use or copy this software, except that it may not be * sold for profit, that this copyright notice remain intact, and that * credit is given where it is due. The University of Toronto and the * author make no warranty and accept no liability for this software. */ static char rcsid[] = "$Header: main.c,v 1.9 89/03/23 13:28:40 pkern Exp $"; #include #include #include #include #include #include "cterm.h" char *program; /* * initialize the world and run the terminal ... * ... then reset the world and exit. */ main(argc, argv) int argc; char *argv[]; { char *s; uchar iflag=0; int n, boom(); program = argv[0]; while (--argc) { argv++; if (argv[0][0] == '-') switch (argv[0][1]) { case 'i': if (getdefs(argv[1]) < 0) { perror(argv[1]); exit(1); } argv++; iflag++; break; default: break; } } if (!iflag) { /* no .ini file given in args */ s = FINIT; /* check default .ini file */ if (getdefs(s) < 0 && (*s == '/' || *s == '\\')) /* give it another shot */ if (getdefs(++s) < 0 && *program) { /* ok, try again (for DOS 3.0 & up). * use program name as .ini template. */ char buf[MAXPATH], *strrchr(); strcpy(buf, program); s = strrchr(buf, '.'); /* replace .EXE or .COM with .INI */ strcpy(s, ".INI"); getdefs(buf); } } ctrlbrk(boom); /* for safety sake */ init_sys(); init_kbd(); init_scr(); curs_xy(1, 1); eos_erase(1, 1); init_prt(); pr_init(); term(); boom(1); } boom(sw) int sw; { #ifdef debug extern int regs[]; #endif counter(0); reset_prt(); reset_kbd(); reset_scr(); pr_reset(); #ifdef debug if (sw) cprintf("**ZAP**\r\n res:%04x\r\n", regs[13]); #else if (sw) cputs("**ZAP**"); #endif return(0); } /* * some miscellaneous OS-dependent routines */ /* * counter(), cntdn, timer_int(): * attempt to simulate time-outs (eg. signals on UNIX) */ unsigned int cntdn=0; static uchar f_timer=0; void interrupt (*o_timer)(); void interrupt timer_int() { if (cntdn) cntdn--; } /* * install or reset timer_int ISR * allows cntdn to be used as a count-down clock. * (see kermit.c or xmodem.c for counter/cntdn usage examples) */ #include MACHINE_H counter(sw) int sw; { #ifdef TIMER if (sw) { /* install timer_int ISR */ if (f_timer) return; o_timer = getvect(TIMER); disable(); setvect(TIMER, timer_int); enable(); f_timer = 1; } else { /* restore old ISR */ if (!f_timer) return; disable(); setvect(TIMER, o_timer); enable(); f_timer = 0; } #endif /* TIMER */ } /* * sysconfig, init_sys(): * get and save system configuration */ unsigned int sysconfig=0; init_sys() { union REGS r; #ifdef CFG_INT int86(CFG_INT, &r, &r); sysconfig = r.x.ax; #endif } /* run cmd in dos */ /* * please excuse the tortured code but both system() and * spawnl() refused to exit properly (Turbo C 1.0) */ docmd(cmd) char *cmd; { #if (__TURBOC__ == 0x0100) int i; union REGS r; char *av[] = { "", "", (char *)0 }; char buf[128], cpath[128], *getenv(); strcpy(cpath, getenv("COMSPEC")); for(i=strlen(cpath)-1; i>0; i--) if (cpath[i]=='\\' || cpath[i]=='/' || cpath[i]==':') { i++; break; } strcpy(buf, &cpath[i]); av[0] = buf; av[1] = buf + strlen(buf); r.x.ax = 0x3700; intdos(&r, &r); /* get switchar */ sprintf(av[1], " %cC %s", r.h.dl, cmd); /* phew! ok, now do it */ if (spawnv(P_WAIT, cpath, av) < 0) perror(cmd); #else if (system(cmd) < 0) perror(cmd); #endif } /* mkargs: split flat buffer into an argv */ mkargs(name, buf, avp) char *name, *buf, ***avp; { int ac, n, plen; struct ffblk ff; char path[MAXPATH]; char fn[MAXFILE], ex[MAXEXT]; char drv[MAXDRIVE], dir[MAXDIR]; char *p, *s, *strtok(); char *malloc(), *realloc(); if ((p = malloc(2 * sizeof(p))) == NULL) return(-1); *avp = (char **)p; if ((p = malloc(strlen(name))) == NULL) return(-1); strcpy(p, name); (*avp)[0] = p; ac = 1; s = strtok(buf, " \t"); while (s != NULL) { if (findfirst(s, &ff, ~FA_LABEL & ~FA_DIREC) < 0) { /* no match */ if ((p = malloc(strlen(s))) == NULL) return(-1); strcpy(p, s); (*avp)[ac++] = p; if ((p = realloc(*avp, (ac+1) * sizeof(p))) == NULL) return(-1); *avp = (char **)p; s = strtok(NULL, " \t"); continue; } /* expand globs */ fnsplit(s, drv, dir, fn, ex); fnmerge(path, drv, dir, "", ""); plen = strlen(path); do { if ((p = malloc(plen + strlen(ff.ff_name))) == NULL) return(-1); fnmerge(p, drv, dir, ff.ff_name, ""); (*avp)[ac++] = p; if ((p = realloc(*avp, (ac+1) * sizeof(p))) == NULL) return(-1); *avp = (char **)p; } while (!findnext(&ff)); s = strtok(NULL, " \t"); } (*avp)[ac] = NULL; return(ac); } dumpav(ac, avp) int ac; char ***avp; { while (--ac) free((*avp)[ac]); free(*avp); } /* wrscrn: * write current screen contents to file */ wrscrn(fn, ltop, lbot) char *fn; int ltop, lbot; { char buf[256]; int i=ltop, n=0, fd=0; if ((fd = open(fn, O_WRONLY|O_CREAT|O_APPEND|O_BINARY, 0664)) < 0) { perror(fn); return(1); } while (i <= lbot && (n = scgets(buf, 254, i++)) >= 0) { buf[n++] = '\n'; buf[n] = NUL; write(fd, buf, n); } close(fd); return(0); } @ 1.9 log @system configuration call added for figuring out what's available on the system at run-time. @ text @d11 1 a11 1 static char rcsid[] = "$Header: main.c,v 1.8 89/03/23 13:25:12 pkern Exp $"; d21 1 d35 2 d57 12 a68 1 getdefs(++s); /* give it another shot */ d88 1 d175 1 d193 4 d262 1 a262 1 wrscrn(fn) d264 1 d267 1 a267 1 int i=0, n=0, fd=0; d269 1 a269 1 if ((fd = open(fn, O_WRONLY|O_CREAT|O_BINARY, 0664)) < 0) { d273 1 a273 1 while ((n = scgets(buf, 254, ++i)) >= 0) { d279 1 @ 1.8 log @more generic argv[] builder added @ text @d11 1 a11 1 static char rcsid[] = "$Header: main.c,v 1.7 89/03/01 12:32:54 pkern Exp $"; @ 1.7 log @timer flag added for safety. @ text @d11 1 a11 1 static char rcsid[] = "$Header: main.c,v 1.6 89/02/06 13:38:19 pkern Exp $"; d57 1 d137 5 d143 9 d179 3 a181 6 /* doxpnd: expand name if it contains glob chars */ /* (lazy version ... uses Turbo C's findfirst/findnext routines) */ doxpnd(ac, av) int *ac; char ***av; d183 1 a183 1 int n, plen; d188 2 a189 1 char *p, *malloc(), *realloc(); d191 34 a224 21 p = (*av)[*ac - 1]; #ifdef debug cprintf("%d: %s\r\n", *ac, (*av)[*ac-1]); #endif if (findfirst(p, &ff, ~FA_LABEL & ~FA_DIREC) < 0) return(*ac); fnsplit(p, drv, dir, fn, ex); fnmerge(path, drv, dir, "", ""); plen = strlen(path); free((*av)[*ac - 1]); (*av)[*ac - 1] = malloc(plen + strlen(ff.ff_name)); fnmerge((*av)[*ac - 1], drv, dir, ff.ff_name, ""); while (!findnext(&ff)) { (*av)[*ac] = malloc(plen + strlen(ff.ff_name)); fnmerge((*av)[*ac], drv, dir, ff.ff_name, ""); #ifdef debug cprintf("%d: %s\r\n", *ac, (*av)[*ac]); #endif *ac += 1; if (p = realloc(*av, (*ac + 1) * sizeof(p))) *av = (char **)p; d226 13 a238 2 return(*ac); /* return new arg count */ } @ 1.6 log @wrscrn() now less hardware dependent. @ text @d5 5 a9 1 * copyright (c) University of Toronto, 1988. d11 1 a11 1 static char rcsid[] = "$Header: main.c,v 1.5 89/02/03 15:53:46 pkern Exp $"; d97 1 d119 1 d124 1 d127 1 d131 1 @ 1.5 log @*** empty log message *** @ text @d7 1 a7 1 static char rcsid[] = "$Header: main.c,v 1.4 89/01/31 14:09:23 pkern Exp $"; d199 2 a200 4 int fd; char buf[96]; register int i, j; extern char o_scrn[SCRSIZE]; d206 4 a209 5 strcpy(&buf[80], "\n"); for (j = 0; j < SCRSIZE; ) { for (i = 0; i < 80; i++, j++) buf[i] = (o_scrn[j]) ? o_scrn[j] : ' '; write(fd, buf, 81); @ 1.4 log @another clean-up @ text @d7 1 a7 1 static char rcsid[] = "$Header: main.c,v 1.3 89/01/31 14:08:19 pkern Exp $"; d139 1 a139 1 char buf[128], cpath[128]; d148 1 a148 1 sprintf(av[1], "%cC %s", r.h.dl, cmd); a161 1 char *p; d167 1 @ 1.3 log @*** empty log message *** @ text @d7 1 a7 1 static char rcsid[] = "$Header$"; d15 1 a15 2 #include "common.h" #include "tipro.h" a16 1 static uchar iflag=0; a17 1 d27 1 d84 1 a84 1 * some misc. routines a104 1 * (see tipro.h for difference between TIMER and TICKER) d107 2 d112 1 d124 1 d131 1 a131 1 * spawnl() refused to exit properly (version 1.0 Turbo C) @ 1.2 log @minor comments added @ text @d7 1 a7 1 static char *ID = "main.c Oct/88 Univ. of Toronto"; @ 1.1 log @Initial revision @ text @d49 2 a50 2 if (!iflag) { s = FINIT; d52 1 a52 1 getdefs(++s); @