home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / apl / ah.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-23  |  4.1 KB  |  267 lines

  1. #include "apl.h"
  2.  
  3. ex_immed()
  4. {
  5.     int i, *ip, j;
  6.     struct item *p;
  7.     struct nlist *n;
  8.     double f;
  9.     char fname[64];                        /* Array for filename */
  10.     char *cp, *vfname();
  11.  
  12.     i = *pcp++;
  13.     switch(i) {
  14.  
  15.     default:
  16.         error("immed B");
  17.  
  18.     case SCRIPT:
  19.         if(protofile > 0) close(protofile);
  20.         protofile = 0;
  21.         cp = vfname(fname);
  22.         if(equal(cp, "off")) return;
  23.         if((protofile = open(cp, 1)) > 0){
  24.             lseek(protofile, 0L, 2);    /* append to existing file */
  25.             printf("[appending]\n");
  26.         }
  27.         else {
  28.             /*
  29.              * create new file
  30.              */
  31.             protofile = opn(cp, 0644);
  32.             printf("[new file]\n");
  33.         }
  34.         write(protofile, "\t)script on\n", 12);
  35.         return;
  36.  
  37.     case DEBUG:
  38.         debug = ~debug;
  39.         return;
  40.  
  41.     case MEMORY:
  42.         memoryCheck();
  43.         return;
  44.  
  45.     case DIGITS:
  46.         i = topfix();
  47.         if(i < 1 || i > 20) error("digits D");
  48.         printf("was %d\n",thread.digits);
  49.         thread.digits = i;
  50.         return;
  51.  
  52.     case TRACE:
  53.         funtrace = 1;
  54.         return;
  55.  
  56.     case UNTRACE:
  57.         funtrace = 0;
  58.         return;
  59.  
  60.     case WRITE:
  61.         funwrite(0);
  62.         return;
  63.  
  64.     case DEL:
  65.     case EDITF:
  66.         sp[0] = sp[-1];        /*    duplicate top of stack  */
  67.         sp++;
  68.         funwrite(scr_file);
  69.         funedit(scr_file, i);
  70.         unlink(scr_file);
  71.         return;
  72.  
  73.  
  74.     case EDIT:
  75.         funedit(0, i);
  76.         return;
  77.  
  78.     case FUZZ:
  79.         i = topfix();
  80.         if(i <= 0) {
  81.             thread.fuzz = 0.;
  82.             return;
  83.         }
  84.         f = i;
  85.         thread.fuzz = exp(-f*2.3025851);
  86.         return;
  87.  
  88.     case ORIGIN:
  89.         printf("was %d\n",thread.iorg);
  90.         thread.iorg = topfix();
  91.         return;
  92.  
  93.     case WIDTH:
  94.         i = topfix();
  95.         if(i < 1) error("width D");
  96.         printf("was %d\n",thread.width);
  97.         thread.width = i;
  98.         return;
  99.  
  100.     case READ:
  101.         funread(0);
  102.         return;
  103.  
  104.     case ERASE:
  105.         p = sp[-1];
  106.         sp--;
  107.         erase(p);
  108.         return;
  109.  
  110.     case CONTIN:
  111.         i = opn("continue", 0644);
  112.         wssave(i, 0);
  113.         printf(" continue");
  114.  
  115.     case OFF:
  116.         term(0);
  117.  
  118.     case VARS:
  119.         for(n=nlist; n->namep; n++) {
  120.             if(n->itemp && n->use == DA && n->namep[0] != 'L') {
  121.                 if(column+8 >= thread.width) printf("\n\t");
  122.                 printf(n->namep);
  123.                 putchar('\t');
  124.             }
  125.         }
  126.         putchar('\n');
  127.         return;
  128.  
  129.     case FNS:
  130.         for(n=nlist; n->namep; n++) {
  131.             if(n->use == DF || n->use == MF || n->use == NF) {
  132.                 if(column+8 >= thread.width) printf("\n\t");
  133.                 printf(n->namep);
  134.                 putchar('\t');
  135.             }
  136.         }
  137.         putchar('\n');
  138.         return;
  139.  
  140.     case CODE:
  141.         n = (struct nlist *)sp[-1];
  142.         sp--;
  143.         switch(n->use){
  144.         default:
  145.             error("not a fn");
  146.         case NF:
  147.         case MF:
  148.         case DF:
  149.             if(n->itemp == 0) funcomp(n);
  150.             ip = (int *)n->itemp;
  151.             for(i=0; i <= *ip; i++){
  152.                 printf(" [%d] ", i);
  153.                 dump(ip[i+1], 0);
  154.             }
  155.             putchar('\n');
  156.         }
  157.         return;
  158.  
  159.     case RESET:
  160.         while(gsip) ex_ibr0();
  161.         longjmp(reset_env, 0);
  162.  
  163.     case SICOM:
  164.         tback(1);
  165.         return;
  166.  
  167.     case CLEAR:
  168.         clear();
  169.         printf("clear ws\n");
  170.         goto warp1;                /* four lines down, or so... */
  171.  
  172.     case LOAD:
  173.     case PLOAD:
  174.         j = opn(vfname(fname), 0);
  175.         clear();
  176.         if (i == LOAD) wsload(j, 0);
  177.         if (i == PLOAD) wsload(j, 1);
  178.         printf(" %s\n", fname);
  179.         evLlx();                /* possible latent expr evaluation */
  180. warp1:
  181.         /*
  182.          * this garbage is necessary because clear()
  183.          * does a brk(&end), and the normal return & cleanup
  184.          * procedures are guaranteed to fail (miserably).
  185.          *        --jjb 1/78
  186.          */
  187.         sp = stack;
  188.         longjmp(reset_env, 0);
  189.  
  190.     case LIB:
  191.         listdir();
  192.         return;
  193.  
  194.     case COPY:
  195.         if(gsip) error("si damage -- type ')reset'");
  196.         wsload(opn(vfname(fname),0), 0);
  197.         printf(" copy %s\n", fname);
  198.         return;
  199.  
  200.     case DROPC:
  201.         cp = vfname(fname);
  202.         if(unlink(cp) == -1) printf("[can't remove %s]\n", cp);
  203.         return;
  204.  
  205.     case SAVE:
  206.     case PSAVE:
  207.         j = opn(vfname(fname), 0644);
  208.         if (i == SAVE) wssave(j, 0);
  209.         if (i == PSAVE) wssave(j, 1);
  210.         printf(" saved %s\n", fname);
  211.         return;
  212.  
  213.     case VSAVE:
  214.         i = opn(vfname(fname), 0644);
  215.         vsave(i);
  216.         putchar('\n');
  217.         return;
  218.  
  219.     case SHELL:
  220.         ex_shell();
  221.         return;
  222.  
  223.     case LIST:
  224.         ex_list();
  225.         return;
  226.  
  227.     case PRWS:
  228.         ex_prws();
  229.         return;
  230.  
  231.     }
  232. }
  233.  
  234. char *
  235. vfname(array)
  236. char *array;
  237. {
  238.     struct nlist *n;
  239.     char *p;
  240.  
  241.     n = (struct nlist *)sp[-1];
  242.     sp--;
  243.     if(n->type != LV) error("save B");
  244.     p = n->namep;
  245.     while(*array++ = *p++);
  246.     return(n->namep);
  247.  
  248. }
  249.  
  250. /*
  251.  * check for latent expr., and evaluate it if it is there:
  252.  */
  253.  
  254. evLlx()
  255. {
  256.     struct nlist *n;
  257.     struct item *p;
  258.  
  259.     if((n=nlook("Llx")) && n->itemp->type == CH && n->itemp->size){
  260.         *sp++ = dupdat(n->itemp);
  261.         ex_meps();
  262.         p = sp[-1];
  263.         if(p->type != EL && p->type != DU) ex_print();
  264.         pop();
  265.     }
  266. }
  267.