#
# Small c Interpreter command shell
#
char _nr, _nc, _ro, _co, *_cp, *_el, _mhz;

putchar(c){return sys(c,2,1)}
getchar(){return sys(1,2)}
puts(b){return sys(b,2,3)}
putd(n){return printf("%d\n",n)}
putx(n){return printf("%x\n",n)}
puto(n){return printf("%o\n",n)}
gets(b){return sys(b,80,1,4)}
fputc(c,u){return sys(c,u,1)}
fgetc(u){return sys(u,2)}
fputs(b,u){return sys(b,u,3)}
fgets(b,n,u){return sys(b,n,u,4)}
sprintf(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9){sys(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,5)}
printf(a0,a1,a2,a3,a4,a5,a6,a7,a8)
{char b[128];sys(b,a0,a1,a2,a3,a4,a5,a6,a7,a8,5);puts(b)}
sscanf(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9){sys(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,6)}
scanf(a0,a1,a2,a3,a4,a5,a6,a7,a8)
{char b[128];gets(b);sys(b,a0,a1,a2,a3,a4,a5,a6,a7,a8,6)}
atoi(b){int v;sys(b,"%d",&v,6);return v}
fopen(f,m){return sys(f,m,7)}
fread(s,l,u){return sys(s,l,u,8)}
fwrite(s,l,u){return sys(s,l,u,9)}
fclose(u){return sys(u,10)}
fseek(u,o,w){return sys(u,o,w,11)}
ftell(u){return sys(u,12)}
bdos(a,b){return sys(a,b,13)}
system(s){return sys(s,14)}
exit(){sys(15)}
strcmp(s,t){return sys(s,t,20)}
strncmp(s,t,n){return sys(s,t,n,20)}
strcpy(s,t){return sys(s,t,21)}
strncpy(s,t,n){return sys(s,t,n,21)}
strlen(s){return sys(s,22)}
malloc(n){return sys(n,23)}
free(p){sys(p,24)}
trace(n){sys(n,28)}
dirscan(p,f){return sys(p,f,29)}

entry

char ln[80];
char pr[20000];

main()
{
   int f, t;

   puts(sys(0));
   puts("\nShell V1.3 15Mar86 Copyright (C) 1986 Bob Brodt\n");
   _nr=25; _nc=80;
   _ro=_co=1;
   _cp="\033[%d;%dH";
   _el="\033[K";
   _mhz=5; 
   *pr='Z';

   for(;;) {
      puts("> ");
      ln[5]=0;
      if(gets(ln)) {
         if (!strncmp(ln,"edit",4))
            sys(atoi(ln+4),pr,19);
         else if (!strncmp(ln,"list",4)) {
            f=1;
            t=32765;
            if(ln[4])
               sscanf(ln+4,"%d %d",&f,&t);
            sys(pr,f,t,27);
         }
         else if (!strncmp(ln,"save",4))
            sys(ln+5,pr,26);
         else if (!strncmp(ln,"load",4))
            sys(ln+5,pr,25);
         else if (!strcmp(ln,"exit"))
            exit();
         else
            printf("\n%d\n",sys(ln,pr,16));
      }
   }
}
