home *** CD-ROM | disk | FTP | other *** search
/ Between Heaven & Hell 2 / BetweenHeavenHell.cdr / 500 / 401 / shell.sci < prev    next >
Text File  |  1984-08-31  |  3KB  |  99 lines

  1. #
  2. # Small c Interpreter command shell
  3. #
  4. # The library functions:
  5. #
  6. putchar(c){return sys(c,1,1)}
  7. getchar(){return sys(0,2)}
  8. puts(b){return sys(b,1,3)}
  9. gets(b){return sys(b,80,0,4)}
  10. fputc(c,u){return sys(c,u,1)}
  11. fgetc(u){return sys(u,2)}
  12. fputs(b,u){return sys(b,u,3)}
  13. fgets(b,n,u){return sys(b,n,u,4)}
  14. sprintf(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9)
  15.    {return sys(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,5)}
  16. printf(a0,a1,a2,a3,a4,a5,a6,a7,a8)
  17.    {char b[128];sys(b,a0,a1,a2,a3,a4,a5,a6,a7,a8,5);puts(b)}
  18. sscanf(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9)
  19.    {return sys(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,6)}
  20. scanf(a0,a1,a2,a3,a4,a5,a6,a7,a8)
  21.    {char b[128];gets(b);sys(b,a0,a1,a2,a3,a4,a5,a6,a7,a8,6)}
  22. atoi(b){int v;sys(b,"%d",&v,6);return v}
  23. fopen(f,m){return sys(f,m,7)}
  24. fread(s,l,u){return sys(s,l,u,8)}
  25. fwrite(s,l,u){return sys(s,l,u,9)}
  26. fclose(u){return sys(u,10)}
  27. exit(){sys(11)}
  28. stmt(l,p,s){return sys(l,p,s,12)}
  29. totok(s,b){return sys(s,b,13)}
  30. untok(b,s){return sys(b,s,14)}
  31. edit(l,p){return sys(l,p,15)}
  32. strcmp(s,t){return sys(s,t,16)}
  33. strncmp(s,t,n){return sys(s,t,n,16)}
  34. memleft(){return sys(17)}
  35. malloc(n){return sys(n,18)}
  36. free(p){sys(p,19)}
  37. load(f,p){return sys(f,p,20)}
  38. save(f,p){return sys(f,p,21)}
  39. list(p,f,t){return sys(p,f,t,22)}
  40. trace(n){sys(n,23)}
  41.  
  42. #
  43. # Entry point to the shell. All globals defined before the "entry" keyword
  44. # are in the "library" and are accessible by user programs.
  45. #
  46. entry
  47.  
  48. int size,top;
  49. char line[80];
  50. char program[16000];
  51.  
  52. main()
  53. {
  54.    int from, to;
  55.  
  56.    top=16000;
  57.    program[0]='Z';    # This is an "End of program" token - required
  58.    size=1;
  59.  
  60.    # print sign-on message
  61.    printf("%s\nShell V1.2M, 13 Nov 1985\n",sys(0));
  62.  
  63.    while(1)
  64.    {
  65.       puts("> ");
  66.       if(gets(line))
  67.       {
  68.          if (!strncmp(line,"edit",4))
  69.             size = sys(atoi(line+5),program,15); # envoke the editor
  70.          else if (!strncmp(line,"list",4))
  71.          {
  72.             if(line[4])
  73.                sscanf(line+4,"%d %d",&from,&to);
  74.             else
  75.             {
  76.                from=1;
  77.                to=32765;
  78.             }
  79.             sys(program,from,to,22);             # list the program buffer
  80.          }
  81.          else if (!strncmp(line,"save",4))
  82.             sys(line+5,program,21);              # save the program buffer
  83.          else if (!strncmp(line,"load",4))
  84.             size = sys(line+5,program,20);       # load the program buffer
  85.          else if (!strncmp(line,"core",4))
  86.             printf("%d bytes free\n",top-size);  # show amount of free space
  87.          else
  88.          {
  89.             #
  90.             # attempt to parse the line as a small c statement. Note that
  91.             # we will display (non-zero) results of a statement, so you
  92.             # could enter something like: 2+2 and a 4 would be printed.
  93.             #
  94.             printf("\n%d\n",sys(line,program,12));
  95.          }
  96.       }
  97.    }
  98. }
  99.