home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / source / cref / src / acts.c next >
Encoding:
C/C++ Source or Header  |  1975-05-13  |  6.4 KB  |  485 lines

  1. #
  2. # include "../mcons.h"
  3. # include "../ccmn.h"
  4. # define SKIP 0
  5. # define COLLECT 1
  6. # define SKIP2 2
  7.  
  8. int    cross    1;
  9. int    order    1;
  10. char    mone    -1;
  11.  
  12. coll()
  13. {
  14.     cs = COLLECT;
  15.     temp[t1].beg = &line[l];
  16.     return;
  17. }
  18.  
  19. save()
  20. {
  21.     extern    wspace();
  22.  
  23.     line[l] = '\0';
  24.     temp[t1].ct = &line[l] - temp[t1].beg;
  25.     temp[t1].term = c;
  26.  
  27.     if((c == ' ' || c == '\t') && cflag) {
  28.         gch[++fl] = mone;
  29.         flag[fl] = &wspace;
  30.     } else {
  31.         sav1();
  32.     }
  33.     return;
  34. }
  35.  
  36. sav1()
  37. {
  38.     extern    only;
  39.     struct tempent    *ptr;
  40.     int    a,tt,val;
  41.  
  42.     if(cflag && c == '(' && level == 0)    csym();
  43.  
  44.     cs = SKIP;
  45.  
  46.     ptr = &temp[t1];
  47.     val = search(ptr->beg,ptr->ct,&itab,0);
  48.  
  49.     if(xsw) {
  50.         switch(val) {
  51.         case 0:
  52.             if((!level&&!hlevel)||(c == '(')||xtrn
  53.                 || ssw) {
  54.                 search(ptr->beg,ptr->ct,&xtab,1);
  55.                 goto yes;
  56.             } else {
  57.                 if(search(ptr->beg,ptr->ct,&xtab,0))
  58.                     goto yes;
  59.             }
  60.             goto no;
  61.  
  62.         case 1:
  63.             goto no;
  64.  
  65.         case 2:
  66.             xtrn = 1;
  67.             goto no;
  68.  
  69.         case 3:
  70.             if(hlevel)    type = 1;
  71.             if(!level&&!hlevel)    ssw = 1;
  72.             goto no;
  73.  
  74.         case 4:
  75.             if(hlevel)    type = 1;
  76.             goto no;
  77.         }
  78.     }
  79.  
  80.     if(hlevel && (val == 4 || val == 3))    type = 1;
  81.     if(!val == !only)    goto yes;
  82. no:
  83.     *(ptr->beg + ptr->ct) = ptr->term;
  84.     return(0);
  85. yes:
  86.     tt = t1;
  87.     while(tt)
  88.         if(comp(ptr->beg,temp[--tt].beg))    goto no;
  89.     t1++;
  90.     return(1);
  91. }
  92.  
  93. out()
  94. {
  95.     auto    i,ct;
  96.     if(cs == COLLECT)    save();
  97.  
  98.     ct = t1;
  99.     while(ct--)
  100.         temp[ct].beg[temp[ct].ct] = temp[ct].term;
  101.  
  102.     while(t1--) {
  103. /*printf("t1 = %d  beg = %d  ct = %d\n",t1,temp[t1].beg,temp[t1].ct); /* DEBUG */
  104.  
  105.         switch(order) {
  106.  
  107.             case 1:
  108.                 if(utmp)
  109.                     i = 0;
  110.                 else
  111.                     i = dfile(temp[t1].beg);
  112.  
  113.                 if((ct = temp[t1].ct) >= 8) {
  114.                     ct = 8;
  115.                     *curf = -1;
  116.                 } else {
  117.                     *curf = '\t';
  118.                 }
  119.  
  120.                 put(i,temp[t1].beg,ct);
  121.                 put(i,curf,curfl);
  122.                 if(cross)    put(i,curs,cursl);
  123.                 conf(lno,4,lbuf);
  124.                 put(i,lbuf,5);
  125.                 break;
  126.  
  127.             case 2:
  128.                 i = dfile(curf+1);
  129.                 put(i,curf+1,curfl-1);
  130.                 if(cross)    put(i,curs,cursl);
  131.                 else {
  132.                     conf(lno,4,lbuf);
  133.                     put(i,lbuf,5);
  134.                 }
  135.                 if((ct = temp[t1].ct) >= 8) {
  136.                     put(i,temp[t1].beg,8);
  137.                     put(i,&mone,1);
  138.                 } else {
  139.                     put(i,temp[t1].beg,ct);
  140.                     put(i,"\t",1);
  141.                 }
  142.                 if(cross) {
  143.                     conf(lno,4,lbuf);
  144.                     put(i,lbuf,5);
  145.                 }
  146.                 break;
  147.  
  148.             case 3:
  149.                 i = dfile(curs);
  150.                 put(i,curs,cursl);
  151.                 if((ct = temp[t1].ct) >= 8) {
  152.                     put(i,temp[t1].beg,8);
  153.                     *curf = -1;
  154.                 } else {
  155.                     put(i,temp[t1].beg,ct);
  156.                     *curf = '\t';
  157.                 }
  158.                 put(i,curf,curfl);
  159.                 conf(lno,4,lbuf);
  160.                 put(i,lbuf,5);
  161.         }
  162.         put(i,line,l + 1);
  163.  
  164.     }
  165.     t1 = 0;
  166.     l = -1;
  167.     lno++;
  168.     cs = SKIP;
  169.  
  170.     return;
  171. }
  172.  
  173.  
  174. asym()
  175. {
  176.     int    i;
  177.     char    *p;
  178.  
  179.     if(cs == COLLECT) {
  180.         if(cross) {
  181.             p = temp[t1].beg;
  182.             cursl = &line[l] - p;
  183.             cursl = cursl>8?8:cursl;
  184.             i = -1;
  185.             while(++i < cursl)
  186.                 curs[i] = *p++;
  187.             if(cursl < 8)
  188.                 curs[cursl++] = '\t';
  189.             else
  190.                 curs[cursl++] = -1;
  191.         }
  192.         save();
  193.     }
  194.     cs = SKIP;
  195. }
  196.  
  197. asw()
  198. {
  199.     switch(gch[fl]) {
  200.  
  201.         case 0:
  202.             if(cs == COLLECT)    save();
  203.             cs = SKIP;
  204.             flag[++fl] = &asw;
  205.             gch[fl] = c;
  206.             return(1);
  207.  
  208.         case '\'':
  209.             if(c == '\\') {
  210.                 gch[fl] = c;
  211.                 return(1);
  212.             }
  213.             break;
  214.  
  215.         case '"':
  216.             gch[fl] = '\'';
  217.  
  218.             if(c == '\\') {
  219.                 flag[++fl] = &asw;
  220.                 gch[fl] = c;
  221.                 return(1);
  222.             }
  223.             return(1);
  224.  
  225.         case '<':
  226.             if(c == '\n')    out();
  227.             if(c == '\\') {
  228.                 flag[++fl] = &asw;
  229.                 gch[fl] = c;
  230.                 return(1);
  231.             }
  232.             if(c != '>')    return(1);
  233.             break;
  234.  
  235.         case '/':
  236.             if(c != '\n')    return(1);
  237.  
  238.         case '\\': 
  239.             if(c == '\n')    out();
  240.  
  241.     }
  242.     fl--;
  243.     return(1);
  244.  
  245. }
  246.  
  247. csw()
  248. {
  249.     if(cs == COLLECT)    save();
  250.  
  251.     switch(gch[fl]) {
  252.  
  253.         case 0:
  254.             if(c == '*')
  255.                 if(line[l - 1] != '/')
  256.                     return(1);
  257.             gch[++fl] = c;
  258.             flag[fl] = &csw;
  259.             return(1);
  260.  
  261.         case '*':
  262.             if(c == '\n')    out();
  263.             if(c == '/' && line[l - 1] == '*')
  264.                 break;
  265.             return(1);
  266.  
  267.         case '\'':
  268.         case '"':
  269.             if(c == gch[fl])
  270.                 break;
  271.             if(c == '\\') {
  272.                 gch[++fl] = c;
  273.                 flag[fl] = &csw;
  274.             }
  275.             return(1);
  276.  
  277.         case '\\':
  278.             break;
  279.         }
  280.         fl--;
  281.         return(1);
  282. }
  283.  
  284. incl()
  285. {
  286. /*    printf("incl: l = %d hl = %d dl = %d\n",level,hlevel,dlevel);/*DEBUG*/
  287.     if(cs == COLLECT)    save();
  288.     if(hlevel) {
  289.         hlevel = 0;
  290.         level++;
  291.     } else {
  292.         dlevel++;
  293.     }
  294.  
  295.     cs = SKIP;
  296. }
  297.  
  298. decl()
  299. {
  300. /*    printf("decl: l = %d hl = %d dl = %d\n",level,hlevel,dlevel);/*DEBUG*/
  301.     if(cs == COLLECT)    save();
  302.     cs = SKIP;
  303.     if(dlevel) {
  304.         dlevel--;
  305.         return;
  306.     }
  307.     if(--level > 0)    return;
  308.     curs[0] = '_';
  309.     curs[1] = '\t';
  310.     cursl = 2;
  311.     level = 0;
  312.     return;
  313. }
  314.  
  315. csym()
  316. {
  317.     int    i;
  318.     char    *p;
  319.  
  320. /*    printf("csym: l = %d hl = %d dl = %d\n",level,hlevel,dlevel);/*DEBUG*/
  321.     p = temp[t1].beg;
  322.     if(cs == COLLECT && level == 0) {
  323.         if(cross) {
  324.             cursl = temp[t1].ct;
  325.             cursl = cursl>8?8:cursl;
  326.             i = -1;
  327.             while(++i < cursl)
  328.                 curs[i] = *p++;
  329.             if(cursl < 8)
  330.                 curs[cursl++] = '\t';
  331.             else
  332.                 curs[cursl++] = -1;
  333.         }
  334.         hlevel = 1;
  335.     }
  336.     cs = SKIP;
  337. }
  338.  
  339. dfile(a)
  340.     char    *a;
  341. {
  342.     if(*a < 'c')    return(0);
  343.     if(*a < 'h')    return(1);
  344.     if(*a < 'r')    return(2);
  345.     return(3);
  346. }
  347.  
  348.  
  349. sk2()
  350. {
  351.     cs = SKIP2;
  352. }
  353.  
  354. sk()
  355. {
  356.     cs = SKIP;
  357. }
  358.  
  359. tabs()
  360. {
  361.     if(l == 0)    l = -1;
  362. }
  363.  
  364.  
  365. search(symbol,length,params,install)
  366.     char    *symbol;
  367.     int    length;
  368.     struct    htab    *params;
  369.     int    install;
  370. {
  371.     char    *sp,*p;
  372.     static    int    curb,*hptr,hsiz,nsym,ssiz;
  373.     static    char    *symt;
  374.     auto    h,i,j,k;
  375.  
  376.     if(hptr != params->hptr) {
  377.         hptr = params->hptr;
  378.         hsiz = params->hsiz;
  379.         symt = params->symt;
  380.         ssiz = params->ssiz;
  381.         curb = params->curb;
  382.         nsym = params->nsym;
  383.     }
  384.  
  385.     symbol[length] = '\0';
  386.     sp = symbol;
  387.  
  388.     i = length;
  389.     h = 1;
  390.     while(i--)
  391.         h =* *sp++;
  392.  
  393.     if(h == 0100000) {
  394.         h = 1;
  395.     } else {
  396.         h = h<0?(-h)%hsiz:h%hsiz;
  397.     }
  398.     if(h == 0)    h++;
  399. /*        printf("%s %d\n",symbol,h);    /*DEBUG*/
  400.  
  401.     while((p = &symt[hptr[h]]) > symt) {
  402.         j = length + 2;
  403.         sp = symbol;
  404.         while(--j) {
  405.             if(*p++ != *sp++)    goto no;
  406.         }
  407.         return(*p);
  408. no:
  409.         h = (h + h)%hsiz;
  410.     }
  411.     if(install) {
  412.         if(++nsym >= hsiz) {
  413.             printf("Too many symbols.\n");
  414.             dexit();
  415.         }
  416.  
  417.         hptr[h] = curb;
  418.         length++;
  419.         if((curb + length) >= ssiz) {
  420.             printf("Too many characters in symbols.\n");
  421.             dexit();
  422.         }
  423.  
  424.         while(length--)
  425.             symt[curb++] = *symbol++;
  426.         symt[curb++] = install;
  427.         params->curb = curb;
  428.         params->nsym = nsym;
  429.     }
  430.     return(0);
  431. }
  432.  
  433. conf(n,width,buf) 
  434.     char    *buf;
  435. {
  436.     auto    i,a;
  437.  
  438.     i = width;
  439.     while(i--)    buf[i] = ' ';
  440.  
  441.     buf[(a = n/10)?conf(a,--width,buf):--width] = n%10 + '0';
  442.  
  443.     return(++width);
  444. }
  445.  
  446.  
  447. comp(a,b)
  448.     char    *a;
  449.     char    *b;
  450. {
  451.     a--;
  452.     b--;
  453.     while(*++a == *++b)
  454.         if(*a == '\0')    return(1);
  455.     return(0);
  456. }
  457.  
  458. semi()
  459. {
  460.     if(cs == COLLECT)    save();
  461.     if(only)    return;
  462.     xtrn = 0;
  463.     if(!level) {
  464.         ssw = 0;
  465.         if(!type) {
  466.             hlevel = 0;
  467.             curs[0] = '_';
  468.             curs[1] = '\t';
  469.             cursl = 2;
  470.         }
  471.         type = 0;
  472.     }
  473.     cs = SKIP;
  474. }
  475.  
  476. wspace()
  477. {
  478.     if(c == ' ' || c == '\t')
  479.         return(1);
  480.     sav1();
  481.     fl--;
  482.     return(0);
  483. }
  484.  
  485.