home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / list / ep-src.ark / PROCESS.MAC < prev    next >
Text File  |  1988-05-21  |  10KB  |  657 lines

  1.  
  2.     include    BDSYM.EQU
  3.     include    EPDATA
  4.  
  5.     .request STOWC
  6.     .request CSEQ
  7.     .request GOTOCOL
  8.     .request GSTR
  9.  
  10.     .comment    `
  11. /************************************************/
  12. /*    Process one input line of text.        */
  13. /************************************************/
  14.  
  15. processline()
  16. {    /* char pendc, hycorrect;*/
  17.  
  18.     bsflag = FALSE;
  19.     hycorrect = 0;
  20.     pendc = inbuf[inpoint];
  21.  
  22. /* Special actions at beginning of input line    */
  23.  
  24.     /* some might like run-off style    */
  25.     if (pendc == val['D'-'@']['C'-'@']) inbuf[inpoint] = pendc = ec;
  26.  
  27.     /* if ignoring, prevent beg. line action    */
  28.     if (mode & IGNORE) pendc = '\0';
  29.  
  30.     /* subsequent white space at beginning of line causes a break */
  31.     if (pendc == ' ' || pendc == '\t' || pendc == '\n')
  32.     {    brkflag = TRUE;
  33.         prtsbuf();
  34.          /* empty input line? then leave blank output line */
  35.         if (pendc == '\n')
  36.         {    inbuf[inpoint] = 0;
  37.             gstr();
  38.         }
  39.         else
  40.         while (pendc == ' '/* || pendc == SOFTSP*/)
  41.         {    /* if (pendc == ' ') */ lindent[cc] += PICA;
  42.             scrncol++;
  43.             pendc = inbuf[++inpoint];
  44.         }
  45.     }
  46.     else if (!co || nc) prtsbuf();
  47.  
  48.     /* indent in multiple column mode */
  49.     if (cc > 1 && lindent[cc]) gotocol(lindent[cc]);
  50.  
  51. /* Now the loop    */
  52.  
  53.     while (pendc = inbuf[inpoint++])
  54.  
  55.     { scrncol++;
  56.  
  57.       /* maybe time to start a new line?    */
  58. /* pendc <= ' ' is experimental */
  59.       if (pendc <= ' ' && glen+lindent[cc]+hycorrect > llength)
  60.          prtsbuf();
  61.  
  62. if (pendc == SOFTHY || pendc == SOFTHYA) putchar('&');
  63. else putchar(pendc);
  64.  
  65.     /* if ignoring, look only at braces    */
  66.     if ((mode & IGNORE) && pendc != '{' && pendc != '}') continue;
  67.  
  68.  
  69.     /* Escape character    */
  70.       if (pendc == ec)
  71.       {    if (pendc = cseq()) stowc(pendc);
  72.         continue;
  73.       }
  74.  
  75.  
  76.       switch (pendc) {
  77.  
  78.  
  79.     /* When concatenating, newline treated like
  80.         a space - otherwise, start a new line */
  81.         case '\n':
  82.         if (glen)
  83.             if (co && !nc)
  84.             { if (outbuf[outpoint-1] > ' ') stowc(' ');
  85.             }
  86.             /* else gstr();*/
  87.         scrncol = 0;
  88.         hycorrect = 0;
  89.         break;
  90.     
  91.     /* Tab        */
  92.         case '\t':
  93.         dotab();
  94.         hycorrect = 0;
  95.         break;
  96.  
  97.  
  98.     /* Soft hyphen -- correct for early line break    */
  99.         case SOFTHY:
  100.         case SOFTHYA:
  101.         stowc(SOFTHY);
  102.         hycorrect = widbuf[outpoint-1];
  103.         break;
  104.  
  105.     /* watch braces                */
  106.        case '}':
  107.         if (brccount || !modepop()) stowc(pendc);
  108.         if (brccount) brccount--;
  109.         break;
  110.  
  111.        case '{':
  112.         if (allmode)
  113.         {    brcstk[cc][brcpt[cc]++] = mode;
  114.             mode = allmode;
  115.         }
  116.         else
  117.         {    brccount++;
  118.             stowc(pendc);
  119.         }
  120.         break;
  121.  
  122.     /* Space -- reset hyphen correction    */
  123.         case ' ':
  124.         hycorrect = 0;
  125.     /* Not special -- put it in buffer    */
  126.         default:
  127.         stowc(pendc);
  128.  
  129.       } /* end switch */
  130.  
  131.     } /* end while */
  132.  
  133. }            `
  134.  
  135. processline::
  136.     push    b
  137. ;pendc in C
  138.  
  139. ;so can use ret's instead of jump's
  140.     lxi    h,.pLOOP
  141.     push    h
  142.  
  143. ;    bsflag = FALSE;
  144. ;    hycorrect = 0;
  145.  
  146.     xra    a
  147.     sta    bsflag
  148.     sta    hycorrect
  149.  
  150. ;    pendc = inbuf[inpoint];
  151.     call    inbch##
  152.     mov    c,a
  153.  
  154. ;
  155. ;/* Special actions at beginning of input line    */
  156. ;
  157. ;    /* some might like run-off style    */
  158. ;    if (pendc == val['D'-'@']['C'-'@']) inbuf[inpoint] = pendc = ec;
  159.  
  160. ;check for 'cm' char
  161.     lda    val + 54*('C'-'@') + 2*('M'-'@')
  162.     cmp    c
  163.     jz    .p31
  164.  
  165.     lda    val + 54*('D'-'@') + 2*('C'-'@')
  166.     cmp    c
  167.     jnz    .p1
  168.  
  169.     lda    ec
  170.     mov    c,a
  171.  
  172. ;    lhld    inpoint
  173. ;    lxi    d,inbuf
  174. ;    dad    d
  175. ;HL was set by inbch
  176. ;
  177. ;(in a $h or $f string, ec will replace dc permanently)
  178.     mov    m,c
  179. ;
  180. ;    /* if ignoring, prevent beg. line action    */
  181. ;    if (mode & IGNORE) pendc = '\0';
  182. .p1:    lda    mode+1
  183.     ani    IGNORE shr 8
  184.     jz    .p2
  185.  
  186.     mvi    c,0
  187. ;
  188. ;    /* subsequent white space at beginning of line causes a break */
  189. ;    if (pendc == ' ' || pendc == '\t' || pendc == '\n')
  190. .p2:
  191.     mov    a,c
  192.     cpi    ' '
  193.     jz    .p3
  194.     cpi    9
  195.     jz    .p3
  196.     cpi    0AH
  197.     jnz    .p6
  198.  
  199. ;    {    brkflag = TRUE;
  200. ;        prtsbuf();
  201. .p3:    mvi    a,1
  202.     sta    brkflag
  203.     call    prtsbuf##
  204. ;         /* empty input line? then leave blank output line */
  205. ;        if (pendc == '\n')
  206.     mov    a,c
  207.     cpi    0AH
  208.     jnz    .p4
  209. ;        {    inbuf[inpoint] = 0;
  210. ;            gstr();
  211. ;        }
  212. ;    lhld    inpoint
  213. ;    lxi    d,inbuf
  214. ;    dad    d
  215. ;I guess this is ok, since 0ah should never get into strings
  216.     call    inbch##
  217.     mvi    m,0
  218. ;;    call    gstr##
  219.     jmp    gstr##
  220. ;;    jmp    .p8
  221.  
  222. ;        else
  223. ;        while (pendc == ' ')
  224. .p4:
  225.     mov    a,c
  226.     cpi    ' '
  227. ;;    jnz    .p8
  228.     rnz
  229. ;        {    lindent[cc] += PICA;
  230. ;            scrncol++;
  231. ;            pendc = inbuf[++inpoint];
  232. ;        }
  233. ;    }
  234.  
  235.     call    getlindent##
  236.     push    h
  237.  
  238.     lhld    cw
  239.     mov    a,l
  240.     ora    a
  241.     jnz    $+6
  242.     lxi    h,PICA
  243.     dad    d
  244.  
  245.     xchg
  246.     pop    h
  247.     mov    m,d
  248.     dcx    h
  249.     mov    m,e
  250.  
  251.     call    nxspnt##
  252.     call    inbch##
  253.     mov    c,a
  254.  
  255.     jmp    .p4
  256.  
  257. ;    else if (!co || nc) prtsbuf();
  258. .p6:    lda    co
  259.     ora    a
  260. ;;    jz    .p7
  261.     jz    prtsbuf##
  262.     lda    nc
  263.     ora    a
  264. ;;    jz    .p8
  265.     rz
  266. ;;.p7:    call    prtsbuf##
  267.     jmp    prtsbuf##
  268.  
  269.  
  270.  
  271.  
  272. ;
  273. ;    /* indent in multiple column mode */
  274. ;    if (cc > 1 && lindent[cc]) gotocol(lindent[cc]);
  275.  
  276. ;(changed to subr. so can use \br to separate columns)
  277. .p8:
  278.     lda    cc
  279.     cpi    1+1
  280.     rc
  281. ;(make sure only once per column)
  282.     lhld    outpoint
  283.     mov    a,h
  284.     ora    l
  285.     rnz
  286.  
  287.     call    getlindent##
  288.     mov    a,d
  289.     ora    e
  290.     rz
  291.  
  292.     push    d
  293.     call    gotocol##
  294.     pop    d
  295.  
  296.     ret
  297.  
  298.  
  299. ;
  300. ;/* Now the loop    */
  301. ;
  302. ;    while (pendc = inbuf[inpoint++])
  303. .pLOOP:
  304. ;first push back self as ret
  305.     lxi    h,.pLOOP
  306.     push    h
  307.  
  308.     call    inbch##
  309.     mov    c,a
  310.  
  311. ;moved this up from below -- not clear that this is right
  312. ; (might make a difference for a 2nd ref. to =$$ in macro)
  313.     ora    a
  314.     jz    .p31
  315.  
  316.     call    nxspnt##
  317. ;
  318. ;    { scrncol++;
  319. ;(done in nxspnt)
  320.  
  321. ;
  322. ;      /* maybe time to start a new line?    */
  323. ;      if (pendc <= ' ' && glen+lindent[cc]+hycorrect > llength)
  324. ;         prtsbuf();
  325.  
  326. ;(according to this, can break at a space or any control character --
  327. ; a little too general; should be SP, LF, SOFTHY, SOFTHYA, and
  328. ; perhaps '-' as an option)
  329.     mov    a,c
  330.     cpi    ' '+1
  331.     jnc    .p13
  332.     call    chkbchar
  333. ;if not a real char, and not a break char, pass it to cseq
  334.     jnz    .p10
  335.  
  336.  
  337. ;back to here to reconsider a break when cseq returns a blank or softhy
  338. .pLENCHK:
  339.     call    getlindent##
  340.  
  341.     lhld    glen
  342.     dad    d
  343.  
  344.     lda    hycorrect
  345.     mov    e,a
  346.     mvi    d,0
  347.     dad    d
  348.  
  349.     lxi    d,8
  350.     lda    italcorrect
  351.     ora    a
  352.     jz    $+4
  353.     dad    d
  354.  
  355.     xchg
  356.     lhld    llength
  357.     call    agbu
  358.  
  359.     cc    prtsbuf##
  360. ;
  361. .p10:
  362.  
  363.  
  364. ;
  365. ;    /* if ignoring, look only at braces    */
  366. ;    if ((mode & IGNORE) && pendc != '{' && pendc != '}') continue;
  367. .p13:    lda    mode+1
  368.     ani    IGNORE shr 8
  369.     jz    .p14
  370.  
  371.     mov    a,c
  372.     cpi    '{'
  373.     jz    .p14
  374.     cpi    '}'
  375.     rnz        ;.pLOOP
  376. ;
  377. ;
  378. ;    /* Escape character    */
  379. ;      if (pendc == ec)
  380. .p14:
  381.     lda    ec
  382.     cmp    c
  383.     jnz    .p16
  384.     mvi    a,'\'
  385.  
  386. ;      {    if (pendc = cseq()) stowc(pendc);
  387. ;        continue;
  388. ;      }
  389. .p14.0:
  390.     call    cseq##
  391.     mov    a,l
  392.     mov    c,l
  393.     cpi    ' '
  394.     jz    .pLENCHK
  395.     cpi    SOFTHY
  396.     jz    .pLENCHK
  397.     ora    a
  398.     rz        ;.pLOOP
  399.  
  400. ;0ffh returned by cseq for comment
  401.     inr    a
  402.     jz    .psTERM
  403. .p14a:
  404.     jmp    .lstow
  405.  
  406.  
  407. chkbchar:
  408.     cpi    ' '
  409.     rz
  410.     cpi    newlin
  411.     rz
  412.     cpi    SOFTHY
  413.     rz
  414.     cpi    SOFTHYA
  415.     ret
  416.  
  417.  
  418. ;
  419. ;
  420. ;      switch (pendc) {
  421. .p16:
  422.     lda    tc
  423.     cmp    c
  424.     jnz    .p16a
  425.     lxi    h,$tbcmd
  426.     jmp    sdirect##
  427. $tbcmd:    db    '\tb\.',0
  428.  
  429. .p16a:
  430.     mov    a,c
  431.     cpi    0AH
  432.     jz    .p17
  433.     cpi    9
  434.     jz    .p19
  435.     cpi    SOFTHY
  436.     jz    .p20
  437.     cpi    SOFTHYA
  438.     jz    .p20
  439.     cpi    '}'
  440.     jz    .p21
  441.     cpi    '{'
  442.     jz    .p25
  443.     cpi    ' '
  444.     jz    .p28
  445.     jc    .p14.0
  446.     jmp    .p29
  447. ;
  448. ;
  449. ;    /* When concatenating, newline treated like
  450. ;        a space - otherwise, start a new line */
  451. ;        case '\n':
  452. ;        if (glen)
  453. ;            if (co && !nc)
  454. ;            { if (outbuf[outpoint-1] > ' ') stowc(' ');
  455. ;            }
  456. ;            /* else gstr();*/
  457. ;        scrncol = 0;
  458. ;        hycorrect = 0;
  459. ;        break;
  460. .p17:
  461.     lxi    h,.p18
  462.     push    h
  463.  
  464.     lhld    glen
  465.     mov    a,h
  466.     ora    l
  467.     rz
  468.  
  469.     lda    co
  470.     ora    a
  471.     rz
  472.  
  473.     lda    nc
  474.     ora    a
  475.     rnz
  476.  
  477.     lhld    outbuf
  478.     xchg
  479.     lhld    outpoint
  480. ;add check for outpoint = 0 (though maybe not possible)
  481.     mov    a,h
  482.     ora    l
  483.     rz
  484.     dcx    h
  485.     dad    d
  486.     mov    a,m
  487. ;now printable control characters are allowed, so this
  488. ; has to be different
  489. ;    cpi    ' '+1
  490. ;    jc    .p18
  491. ;rather, check only for SP and BS (add SPFLAG and HSFLAG?)
  492.     cpi    ' '
  493.     rz
  494.     cpi    8
  495.     rz
  496.  
  497.     pop    h    ;discard .p18 ret
  498.  
  499. ;;    lxi    h,' '
  500. ;;    push    h
  501. ;;    call    stowc##
  502. ;;    pop    d
  503.     mvi    l,' '
  504.     call    .lstow
  505.  
  506. .p18:    xra    a
  507.     sta    scrncol
  508.     sta    hycorrect
  509.     sta    italcorrect
  510.     ret
  511. ;    
  512. ;    /* Tab        */
  513. ;        case '\t':
  514. ;        dotab();
  515. ;        hycorrect = 0;
  516. ;        break;
  517. ;
  518. .p19:    call    dotab##
  519.     xra    a
  520.     sta    hycorrect
  521.     ret
  522. ;
  523. ;    /* Soft hyphen -- correct for early line break    */
  524. ;        case SOFTHY:
  525. ;        case SOFTHYA:
  526. ;        stowc(SOFTHY);
  527. ;        hycorrect = widbuf[outpoint-1];
  528. ;        break;
  529. .p20:
  530.  
  531.     mvi    l,SOFTHY
  532.     call    .lstow
  533.  
  534.     lhld    widbuf
  535.     xchg
  536.     lhld    outpoint
  537.     dcx    h
  538.     dad    h
  539.     dad    d
  540.     mov    a,m
  541.     sta    hycorrect
  542.     ret
  543. ;
  544. ;    /* watch braces                */
  545. ;       case '}':
  546. ;        if (brccount || !modepop()) stowc(pendc);
  547. ;        if (brccount) brccount--;
  548. ;        break;
  549. .p21:    lhld    brccount
  550.     mov    a,h
  551.     ora    l
  552.     jnz    .p22
  553.  
  554.     call    modepop##
  555.     mov    a,h
  556.     ora    l
  557.     jnz    .p23
  558.  
  559. .p22:
  560.     call    .cstow
  561.  
  562. .p23:    lhld    brccount
  563.     mov    a,h
  564.     ora    l
  565.     rz        ;.pLOOP
  566.  
  567.     dcx    h
  568.     shld    brccount
  569.     ret
  570. ;
  571. ;       case '{':
  572. ;        if (allmode)
  573. ;        {    brcstk[cc][brcpt[cc]++] = mode;
  574. ;            mode = allmode;
  575. ;        }
  576. ;        else
  577. ;        {    brccount++;
  578. ;            stowc(pendc);
  579. ;        }
  580. ;        break;
  581. .p25:    lhld    allmode
  582.     mov    a,h
  583.     ora    l
  584.     jz    .p26
  585.  
  586.     call    pshbrc##
  587.  
  588.     lhld    allmode
  589.     shld    mode
  590.     ret
  591.  
  592. .p26:    lhld    brccount
  593.     inx    h
  594.     shld    brccount
  595.     jmp    .cstow
  596.  
  597. ;
  598. ;    /* Space -- reset hyphen correction    */
  599. ;        case ' ':
  600. ;        hycorrect = 0;
  601. .p28:    mvi    a,0
  602.     sta    hycorrect
  603. ;    /* Not special -- put it in buffer    */
  604. ;        default:
  605. ;        stowc(pendc);
  606. ;
  607. ;      } /* end switch */
  608. ;
  609. ;    } /* end while */
  610. ;
  611. .cstow:
  612. .p29:
  613.  
  614. ;possibly do indentation in mc mode
  615.     call    .p8
  616.  
  617.     mov    l,c
  618. .lstow:
  619.     mvi    h,0
  620.     push    h
  621.     call    stowc##
  622.     pop    d
  623. ;;    lda    mode
  624. ;;    ani    ITALIC
  625. ;;    sta    italcorrect
  626.     lhld    mode
  627.     call    endcorr##
  628.     mov    a,e
  629.     sta    italcorrect
  630.     ret    ;.pLOOP
  631. ;}
  632.  
  633. .psTERM:
  634. ;terminate processing of string, if any
  635.     call    sddown##
  636. ;then exit (to get next line or to finish heading/footing)
  637.  
  638. .p31:
  639.     lxi    h,val + 54*('R'-'@') + 2*('L'-'@')
  640.     mov    a,m
  641.     ora    a
  642.     jz    .p31ns
  643.     dcr    m
  644.     jz    .p31ns
  645.     lhld    rlpoint
  646.     shld    inpoint
  647.     ret
  648. .p31ns:
  649.     pop    h    ;discard ret to .pLOOP
  650.     pop    b
  651.     ret
  652.  
  653. italcorrect:    db    0
  654.  
  655.     end
  656.  
  657.