home *** CD-ROM | disk | FTP | other *** search
- /*
-
- CSHELL --- add pipes and batch files to ZCPR3 and C80.
-
- Edward Schram
- 1609 Valle Vista
- Vallejo, Ca, 94589
- (707)557-1424
- */
-
- #define ZCPR3
- #include<stdio.h>
-
- char cmd[191];
- int cmdptr;
- main()
- {
- static char *prompt="$> ";
- char shname[13],c;
- int du,i;
- struct fcb *efcb;
-
- /* Initialize the Z-System pointers */
-
- t_init();
-
- /* See if possible to run a Z-Shell */
-
- if(!envptr)
- error("ZCPR3: required to run pipe shell.");
-
- if(!c_get_sh())
- error("ZCPR3 SHELL STACK: required to run.");
-
- /* Okay to run the program see if set up needs to be done. */
-
- if(qshell() != 1)
- {
-
- /* Yes setup the shell entry */
-
- /* Set the fcb pointer to the external fcb if there else default */
-
- if((efcb = gefcb()) == 0)
- efcb = 0x80;
-
- /* Plug the default name in the default buffer in case it's used */
-
- makfcb("CSHELL.COM",0x80);
-
- /* Try to find the thing in the path */
-
- if((du = pfnd(efcb,1)) == -1)
- error("Can't find program.");
-
- /* Stick in the disk and user */
-
- shname[0] = (du >> 8) + 'A';
- du &= 0xff;
- shname[1] = du / 10 + '0';
- shname[2] = du % 10 + '0';
-
- /* and a colon must be there */
-
- shname[3] = ':';
-
- /* and now for the name */
-
- for(i=0;i<8;++i)
- {
- if((c = (efcb->filename[i] & 0x7f)) == ' ')
- break;
- shname[4+i] = c;
- }
-
- /* Remember to end with 0 */
-
- shname[4+i] = '\0';
-
- /* and push the entry */
-
- if(shpsh(shname))
- error("SHELL PUSH: Stack full or length error.");
-
- puts("\nShell Stack entry pushed.\n\n");
- }
-
- /* The entire main() is initialization these routines simply
- get the command parse it and send it to ZCPR3 */
-
- cmdptr=0;
- /* print DU:DIRNAME> */
- cpm_prompt();
- /* Read the cmd from the console or $$$.SUB or <FILE */
- get_cmd(cmd,190);
- /* Parse (filter it) */
- parse();
- /* and send it */
- putcl(cmd);
- }
-
- /* This took me a long time fiqure it out and let me know
- how I finally managed to do it */
-
- parse()
- {
- int i,x;
- char cmmds[20][10],args[20][128];
- char flag[20];
-
- i=0;
-
- while(getwrd(cmd,&cmdptr,cmmds[i]))
- {
- while((cmd[cmdptr] == ' ') || (cmd[cmdptr]== '\t'))
- cmdptr++;
-
- x= 0;
- while((cmd[cmdptr] != ';') && (cmd[cmdptr] != '|') && (cmd[cmdptr]) && (cmd[cmdptr] != '\n'))
- args[i][x++] = cmd[cmdptr++];
-
-
- flag[i] = cmd[cmdptr++];
- args[i++][x] = '\0';
- }
- cmmds[i][0] = 0;
-
- for(i=0;i<190;i++)
- cmd[i]='\0';
-
- i=0;
-
- while(cmmds[i][0])
- {
- strcat(cmd,cmmds[i]);
- strcat(cmd," ");
- if(args[i][0])
- {
- strcat(cmd,args[i]);
- strcat(cmd," ");
- }
- if (i != 0)
- if(flag[i-1] == '|')
- {
- strcat(cmd,"<");
- strcat(cmd,cmmds[i]);
- strcat(cmd," ");
- }
- if(flag[i] == '|' && cmmds[i+1][0])
- {
- strcat(cmd,">");
- strcat(cmd,cmmds[i+1]);
- strcat(cmd," ");
- }
- strcat(cmd,";");
- if(i != 0)
- if(flag[i-1] == '|')
- {
- strcat(cmd,"era ");
- strcat(cmd,cmmds[i]);
- strcat(cmd,";");
- }
- i++;
- }
- }
-
- /* I admit it the following code is stolen right out of the
- source code of ZCPR3.. I didn't want to reinvent the wheel */
-
-
- get_cmd(line,len)
- char *line;
- int len;
- {
- int disk,user,du,x;
- char buff[128];
- struct fcb submit;
-
- setmem(line,len,0);
-
- disk=getdsk();
- user=getuser();
-
- makfcb("$$$.SUB",&submit);
- if((du = pfnd(&submit,1)) == -1)
- return(gets(line,len));
-
- setdsk(du>>8);
- setusr(du & 0x1f);
-
- if(!bopen(&submit))
- return(err_sub(disk,user,line,len));
-
- submit.rec = submit.rec_count-1;
- if(!rran(&submit,buff))
- return(err_sub(disk,user,line,len));
-
- /* Why are these 2 lines needed?????????
- Submit adds garbage to the front of the command in the record. */
-
- x=0;
- while(buff[x++] < ' '+1);
-
- strcpy(line,&buff[x-1]);
- submit.s2 = '\0';
- submit.rec_count--;
-
- if(!bclose(&submit))
- return(err_sub(disk,user,line,len));
-
- puts("\b:BATCH_MODE>");
- setdsk(disk);
- setusr(user);
- puts(cmd);
- }
-
- err_sub(disk,user,line,len)
- int disk,user;
- char *line;
- int len;
- {
- unlink("$$$.SUB");
- setusr(user);
- setdsk(disk);
- return(gets(line,len));
- }
-
- rran()
- {
- #asm
- pop h
- pop b ; b= buffer area
- pop d ; d= fcb
- push d
- push b
- push h
- push d
- mov e,c
- mov d,b
- mvi c,26
- call 5
- pop d
- mvi c,20
- call 5
- ora a
- lxi h,1
- rz
- dcx h
- #endasm
- }