Annotation of sbbs/sbbs2/execdos/execdos.c, revision 1.1.1.1

1.1       root        1: /* EXECDOS.C */
                      2: 
                      3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
                      4: 
                      5: /* Execute DOS external BBS programs from OS/2 BBS */
                      6: 
                      7: #include "sbbs.h"
                      8: 
                      9: extern unsigned _heaplen=2048;
                     10: 
                     11: extern uint riobp;
                     12: 
                     13: ulong user_misc;
                     14: 
                     15: /****************************************************************************/
                     16: /* Truncates white-space chars off end of 'str' and terminates at first tab */
                     17: /****************************************************************************/
                     18: void truncsp(char *str)
                     19: {
                     20:        uint c;
                     21: 
                     22: str[strcspn(str,"\t")]=0;
                     23: c=strlen(str);
                     24: while(c && (uchar)str[c-1]<=SP) c--;
                     25: str[c]=0;
                     26: }
                     27: 
                     28: void interrupt (*oldfunc)(void);
                     29: 
                     30: /*****************************************************************************/
                     31: /* Interrupt routine to expand WWIV Ctrl-C# codes into ANSI escape sequences */
                     32: /*****************************************************************************/
                     33: void interrupt wwiv_expand()
                     34: {
                     35:        char str[256],al;
                     36:        static int ctrl_c;
                     37:        int i,j;
                     38: 
                     39: al=_AL;
                     40: if(al!=3 && !ctrl_c)
                     41:        oldfunc();
                     42: else if(al!=3 && ctrl_c) {
                     43:        ctrl_c=0;
                     44:        if(user_misc&ANSI) {
                     45:                switch(al) {
                     46:                        default:
                     47:                                strcpy(str,"\x1b[0m");          /* low grey */
                     48:                                break;
                     49:                        case '1':
                     50:                                strcpy(str,"\x1b[0;1;36m");     /* high cyan */
                     51:                                break;
                     52:                        case '2':
                     53:                                strcpy(str,"\x1b[0;1;33m");     /* high yellow */
                     54:                                break;
                     55:                        case '3':
                     56:                                strcpy(str,"\x1b[0;35m");       /* low magenta */
                     57:                                break;
                     58:                        case '4':
                     59:                                strcpy(str,"\x1b[0;1;44m");     /* white on blue */
                     60:                                break;
                     61:                        case '5':
                     62:                                strcpy(str,"\x1b[0;32m");       /* low green */
                     63:                                break;
                     64:                        case '6':
                     65:                                strcpy(str,"\x1b[0;1;5;31m");   /* high blinking red */
                     66:                                break;
                     67:                        case '7':
                     68:                                strcpy(str,"\x1b[0;1;34m");     /* high blue */
                     69:                                break;
                     70:                        case '8':
                     71:                                strcpy(str,"\x1b[0;34m");       /* low blue */
                     72:                                break;
                     73:                        case '9':
                     74:                                strcpy(str,"\x1b[0;36m");       /* low cyan */
                     75:                                break; }
                     76:                j=strlen(str);
                     77:                for(i=0;i<j;i++) {
                     78:                        _AL=str[i];
                     79:                        oldfunc(); } } }
                     80: else
                     81:        ctrl_c=1;
                     82: }
                     83: 
                     84: int main(int argc, char **argv)
                     85: {
                     86:        char str[256],commandline[128],sbbsnode[81],sbbsnnum[81],msr[31]="0"
                     87:                ,user_name[LEN_NAME+1]
                     88:                ,user_alias[LEN_ALIAS+1]
                     89:                ,user_phone[LEN_PHONE+1]
                     90:                ,user_location[LEN_LOCATION+1]
                     91:                ,user_age
                     92:                ,user_sex
                     93:                ,user_level
                     94:                ,node_scrnlen
                     95:                ,*envvar[30],*arg[30],c,d;
                     96:        int i,file,base,com_base=0,com_irq,dte_rate,rmode,mode,node_num,col,row;
                     97:        FILE *stream;
                     98: 
                     99: if(argc<2) {
                    100:        printf("This program is for the internal use of Synchronet.\r\n");
                    101:        return(-1); }
                    102: 
                    103: sprintf(sbbsnode,"SBBSNODE=%s",argv[1]);
                    104: putenv(sbbsnode);
                    105: sprintf(str,"%sEXECDOS.DAT",argv[1]);
                    106: if((file=open(str,O_RDONLY|O_BINARY))!=-1) {
                    107:        stream=fdopen(file,"rb");
                    108:        str[0]=0;
                    109:        fgets(str,128,stream);
                    110:        truncsp(str);
                    111:        if(strcmp(str,"V1.00")) {
                    112:                printf("\7EXECDOS: SBBS VERSION MISMATCH!\7\r\n");
                    113:                delay(5000);
                    114:                return(-1); }
                    115:        str[0]=0;
                    116:        fgets(str,128,stream);
                    117:        com_base=strtoul(str,0,16);
                    118:        str[0]=0;
                    119:        fgets(str,128,stream);
                    120:        com_irq=atoi(str);
                    121:        str[0]=0;
                    122:        fgets(str,128,stream);
                    123:        dte_rate=atoi(str);
                    124:        str[0]=0;
                    125:     fgets(str,128,stream);
                    126:        rmode=strtoul(str,0,16);
                    127:        str[0]=0;
                    128:     fgets(str,128,stream);
                    129:        mode=strtoul(str,0,16);
                    130:        str[0]=0;
                    131:     fgets(str,128,stream);
                    132:        user_misc=strtoul(str,0,16);
                    133:        str[0]=0;
                    134:     fgets(str,128,stream);
                    135:        node_num=atoi(str);
                    136:        if(node_num) {
                    137:                sprintf(sbbsnnum,"SBBSNNUM=%u",node_num);
                    138:                putenv(sbbsnnum); }
                    139:        fgets(commandline,128,stream);
                    140:        truncsp(commandline);
                    141:        str[0]=0;
                    142:     fgets(str,128,stream);
                    143:        i=atoi(str);    /* total env vars */
                    144:        while(i--) {
                    145:                str[0]=0;
                    146:                fgets(str,128,stream);
                    147:                truncsp(str);
                    148:                if((envvar[i]=MALLOC(strlen(str)+1))!=NULL) {
                    149:                        strcpy(envvar[i],str);
                    150:                        putenv(envvar[i]); } }
                    151:        str[0]=0;
                    152:        fgets(str,128,stream);
                    153:        truncsp(str);
                    154:        sprintf(user_alias,"%.*s",LEN_ALIAS,str);
                    155:        str[0]=0;
                    156:        fgets(str,128,stream);
                    157:        truncsp(str);
                    158:        sprintf(user_name,"%.*s",LEN_NAME,str);
                    159:        str[0]=0;
                    160:        fgets(str,128,stream);
                    161:        user_level=atoi(str);
                    162:        str[0]=0;
                    163:        fgets(str,128,stream);
                    164:        user_age=atoi(str);
                    165:        str[0]=0;
                    166:        fgets(str,128,stream);
                    167:        user_sex=str[0];
                    168:        str[0]=0;
                    169:        fgets(str,128,stream);
                    170:        truncsp(str);
                    171:        sprintf(user_phone,"%.*s",LEN_PHONE,str);
                    172:        str[0]=0;
                    173:        fgets(str,128,stream);
                    174:        truncsp(str);
                    175:        sprintf(user_location,"%.*s",LEN_LOCATION,str);
                    176:        fclose(stream); }
                    177: 
                    178: printf("\nEXECDOS: %s\n",commandline);
                    179: 
                    180: if(rmode && com_base) {        /* Capture the port and intercept I/O */
                    181:        base=0xffff;
                    182:        switch(com_base) {
                    183:                case 0xb:
                    184:                        rioctl(I14PC);
                    185:                        break;
                    186:                case 0xffff:
                    187:                case 0xd:
                    188:                        rioctl(I14DB);
                    189:                        break;
                    190:                case 0xe:
                    191:                        rioctl(I14PS);
                    192:                        break;
                    193:                case 0xf:
                    194:                        rioctl(I14FO);
                    195:                        break;
                    196:                default:
                    197:                        base=com_base;
                    198:                        break; }
                    199: 
                    200:        if(rioini(base,com_irq)) {
                    201:                printf("\7EXECDOS: Error initializing COM port (%x,%d)\7\r\n"
                    202:                        ,base,com_irq);
                    203:                return(-1); }
                    204:        rioctl(IOSM|CTSCK|RTSCK|PAUSE|ABORT);
                    205:        rioctl(CPTON);  /* Cvt ^p to ^^ */
                    206: 
                    207:        sprintf(msr,"%lu",&riobp-1);
                    208: 
                    209:        sprintf(str,"%sINTRSBBS.DAT",argv[1]);
                    210:        if((stream=fopen(str,"wb"))!=NULL) {
                    211:                fprintf(stream,"%lu\r\n",&riobp-1);
                    212:                fclose(stream); } }
                    213: 
                    214: setbaud(dte_rate);
                    215: 
                    216: if(rmode) {
                    217:        ivhctl(rmode);
                    218: 
                    219:        if(mode&EX_WWIV) {      /* WWIV code expansion */
                    220:                rioctl(CPTOFF); /* turn off ctrl-p translation */
                    221:                oldfunc=getvect(0x29);
                    222:                setvect(0x29,wwiv_expand); } }
                    223: 
                    224: 
                    225: if(rmode&INT29L && user_alias[0]) {
                    226:        node_scrnlen=lclini(0xd<<8);      /* Tab expansion, no CRLF expansion */
                    227:        lclini(node_scrnlen-1);
                    228:        col=lclwx();
                    229:        row=lclwy();
                    230:        lclxy(1,node_scrnlen);
                    231:        lclatr(CYAN|HIGH|(BLUE<<4));
                    232:        lputs("  ");
                    233:        sprintf(str,"%-25.25s %02d %-25.25s  %02d %c %s"
                    234:                ,user_alias,user_level,user_name[0] ? user_name : user_location
                    235:                ,user_age
                    236:                ,user_sex ? user_sex : SP
                    237:                ,user_phone);
                    238:        lputs(str);
                    239:        lputc(CLREOL);
                    240:        lclatr(LIGHTGRAY);
                    241:        lclxy(col,row); }
                    242: 
                    243: /* separate args */
                    244: 
                    245: arg[0]=commandline; /* point to the beginning of the string */
                    246: for(c=0,d=1;commandline[c];c++)   /* Break up command line */
                    247:        if(commandline[c]==SP) {
                    248:                commandline[c]=0;               /* insert nulls */
                    249:                if(!strncmp(commandline+c+1,"%& ",3))
                    250:                        arg[d++]=msr;
                    251:                else                                    /* point to the beginning of the next arg */
                    252:                        arg[d++]=commandline+c+1; } 
                    253: arg[d]=0;
                    254: 
                    255: /* spawn it */
                    256: 
                    257: i=spawnvp(P_WAIT,arg[0],arg);
                    258: 
                    259: if(rmode) {
                    260:        rioctl(TXSYNC|(3<<8));
                    261:        rioctl(IOFB);
                    262:        if(mode&EX_WWIV)
                    263:                setvect(0x29,oldfunc);
                    264:        ivhctl(0);                      /* replace DOS output interrupt vectors */
                    265:        if(com_base)
                    266:                rioini(0,0); }  /* replace com port */
                    267: 
                    268: //if(i)                        // debug
                    269: //       getch();
                    270: return(i);
                    271: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.