home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / pdp11 / k11hlp.mac < prev    next >
Text File  |  2020-01-01  |  14KB  |  462 lines

  1.     .title    k11hlp
  2.     .ident    /2.0.01/
  3.  
  4.  
  5. ;    Copyright (C) 1986 Brian Nelson
  6. ;
  7. ;    26-Mar-86  18:41:25
  8. ;
  9. ;     This is a complete rewrite of Kermit-11's help. It is a bit more
  10. ;    intelligent,  in that it understands wildcarding (ie, HELP SET *)
  11. ;    and can build subtopic prompting strings and process accordingly.
  12. ;     I had not planned to rewrite it, but after a few requests it was
  13. ;    only about half a days work to do.  This version  also happens to
  14. ;    be a lot more readable. Alas, it's probably larger. This does not
  15. ;    hurt anything as far as overlays go,  but I have no  idea at this
  16. ;    time how I'm going to get the  RT11 FB version to fit on a PDT150
  17. ;    RX01 system disk.
  18.  
  19.  
  20.  
  21.  
  22.  
  23.     .if ndf, K11INC
  24.     .ift
  25.     .include    /IN:K11MAC.MAC/
  26.     .endc
  27.  
  28.     .enabl    gbl
  29.  
  30.  
  31.     cvtarg    =    4 ! 10 ! 20 ! 40
  32.  
  33.  
  34.     .psect    $code    ,ro,i,lcl,rel,con
  35.     .save
  36.     .psect    rwdata    ,rw,d,lcl,rel,con
  37.     .even
  38. ptopic:    .asciz    / Topic ? /        ; For promtping
  39.     .even
  40. fill5:    .byte    40,40,40,40,40,0    ; More filler
  41. filler:    .byte    40,0            ; For formatting
  42. topics:    .blkw    20            ; List of topic/subtopic addresses
  43. topbuf:    .blkb    200            ; Pointers in TOPICS point into here
  44. hlpbuf:    .blkb    200            ; A read/write buffer for the file
  45. htopic:    .blkb    200            ; The current topic
  46. toplev:    .blkw    1            ; Level of current topic
  47. wild:    .blkw    1            ; If topic wildcarded
  48. idxbuf:    .blkb    200            ; Private buffer for HINDEX
  49. ttbuff:    .blkb    200            ; Terminal read buffer
  50. idxdmp:    .word    0            ; Index was dumped
  51. prbuff:    .blkb    200            ; Prompting buffer
  52.     .restore
  53.  
  54.  
  55.  
  56.  
  57.  
  58.     .sbttl    the HELP command
  59.     .psect    $code    ,ro,i,lcl,rel,con
  60.     .enabl    lsb
  61.  
  62. ;    Main loop is here.
  63. ;
  64. ;    (1) Try to open help file; failure --> print internal overlayed help
  65. ;    (2) Parse the command line, filling in the pointer array 'TOPICS'.
  66. ;    (3) Find and print (if found) the requested help topic+[subtopic(s)]
  67. ;    (4) If not found, build a new command line from the 'TOPICS' pointer
  68. ;        array, prompt and concatenate the requested topic.
  69. ;    (5) Go back to (2).
  70. ;    (6) When done, close help file as we don't have the buffer space to
  71. ;        keep it open.
  72.  
  73.  
  74.  
  75. c$help::call    hlpopn            ; Locate and open the help file
  76.     tst    r0            ; Did we ever find the help file?
  77.     beq    10$            ; Yes, process the command
  78.                     ; Error.
  79.     MESSAGE                ; opened. Sleep a moment and then
  80.     MESSAGE    <Printing default internal help>,cr
  81.     CALLS    suspend    ,<#4,#0>    ; Print some default text
  82.     call    defhlp            ; Simple to do    
  83.     jmp    100$            ; Exit now
  84.  
  85. 10$:    mov    argbuf    ,r5        ; Parse the help line
  86.     clr    idxdmp            ; Index has not been dumped yet
  87.     clr    wild            ; Clear the wildcarding flag next
  88.     clr    topics            ; Clear out the pointers
  89.     tstb    @r5            ; Anything passed on line?
  90.     beq    60$            ; No, dump root index
  91.     call    parse            ; And do so, setting up pointers
  92.     clr    cccnt            ; Clear the control C count flag
  93.     call    hfind            ; Now locate the desired text.
  94.     tst    r0            ; Did we find anything help text?
  95.     bmi    100$            ; We got a fatal RMS read error.
  96.     beq    20$            ; Yes, let's go and dump the text
  97.     dec    r0            ; Ok, was it a code of 1 or 2?
  98.     beq    50$            ; It returned 1, which means not found
  99.     mov    sp    ,wild        ; It returned 2, which means it found
  100.                     ; something, and it was wildcarded.
  101. 20$:    call    hprint            ; Dump the help text out now
  102.     br    70$            ; Exit
  103.  
  104. 50$:    MESSAGE    <Help not found for the requested topic>,cr
  105.     clr    topics            ; Clear out arg pointers
  106. 60$:    MESSAGE                ; An extra cr/lf
  107.     mov    #'1    ,-(sp)        ; Dump the index out now
  108.     call    hindex            ; Print it and return
  109.  
  110. 70$:    tst    idxdmp            ; Did we ever print topic/subtopic list
  111.     beq    100$            ; No, just exit
  112.     mov    #prbuff    ,r3        ; Prompt buffer address
  113.     mov    argbuf    ,r4        ; Yes, construct a prompt/parse buffer
  114.     mov    #topics    ,r5        ; Pointers into the parse pointers
  115.     clrb    @r3            ; Start off with an asciz string
  116. 75$:    mov    (r5)+    ,r2        ; Get the parsed argument
  117.     beq    80$            ; All done, exit
  118.     cmpb    (r2)    ,#'*        ; Wildcard argument ? If so, we are done
  119.     beq    80$            ; Done
  120.     STRCAT    r3    ,r2        ; Add in the previous topic/subtopic
  121.     STRCAT    r3    ,#filler    ; Add in a delimiter now.
  122.     br    75$            ; Next please
  123. 80$:    STRCPY    r4    ,r3        ; Copy the new command line
  124.     STRCAT    r3    ,#ptopic    ; Finish creating the prompt
  125.     MESSAGE                ; A cr/lf
  126.     PRINT    r3            ; Dump the prompt out now
  127.     CALLS    kbread    ,<#ttbuff>    ; Read a line from KB:
  128.     tst    r0            ; Successful terminal read?
  129.     bne    100$            ; No, exit asap
  130.     CALLS    cvt$$    ,<#ttbuff,r1,#CVTARG> ; Remove garbage, LC to UC.
  131.     tst    r0            ; Anything left over ?
  132.     beq    100$            ; No, exit please
  133.     clrb    ttbuff(r0)        ; It was successfull, insure .ASCIZ
  134.     STRCAT    r4    ,#ttbuff    ; Append the data just read please.
  135.     jmp    10$            ; And parse the command all over again
  136.                     ;
  137.                     ;
  138. 100$:    call    hlpclo            ; Close up the file and exit
  139.     return
  140.  
  141.  
  142.     .dsabl    lsb
  143.  
  144.  
  145.  
  146.     .sbttl    Parse HELP's command line
  147.  
  148.  
  149. ;    PARSE
  150. ;
  151. ;    Passed:    r5    Command line, minus 'HELP', assumed to be .asciz
  152. ;    Return:    In topics, addresses to each topic/subtopic
  153. ;
  154. ;    Extra imbedded spaces are removed
  155.  
  156.  
  157.  
  158. parse:    save    <r3,r4,r5>        ; Save temp please
  159.     mov    #topbuf    ,r4        ; Where to copy the text to
  160.     mov    #topics    ,r3        ; Where to place the pointers
  161.     clr    @r3            ; Assume nothing was passed
  162.                     ;
  163. 10$:    tstb    @r5            ; All done ?
  164.     beq    100$            ; Yes, exit this routine
  165.     cmpb    @r5    ,#40        ; While (*ch && *ch == 40) ch++ ;
  166.     bne    15$            ; Not a space, exit
  167.     inc    r5            ; A space found, check next one
  168.     br    10$            ; Next
  169. 15$:    mov    r4    ,(r3)+        ; Insert current address
  170.     clr    @r3            ; Insure NEXT is cleared out
  171. 20$:    tstb    @r5            ; All done with this line ?
  172.     beq    30$            ; Yes, exit
  173.     cmpb    @r5    ,#40        ; Space delimiter found ?
  174.     beq    30$            ; Yes, setup for next one
  175.     movb    (r5)+    ,(r4)+        ; No, copy some data over
  176.     br    20$            ; Next please
  177. 30$:    clrb    (r4)+            ; Insure .asciz please
  178.     br    10$            ; Next subtopic
  179. 100$:    unsave    <r5,r4,r3>        ; Pop registers and exit
  180.     return
  181.  
  182.  
  183.  
  184.  
  185.  
  186.     .sbttl    find the topic in the help file
  187.     .enabl    lsb
  188.  
  189. ;    Input:    topics    list of addresses of text to match
  190. ;    Return:    R0    zero for success, 1 for not found, else RMS error code
  191. ;            two  for match and wildcarded topic/subtopic
  192.  
  193.  
  194. hfind:    save    <r2,r3,r4,r5>        ; Save registers we may trash here
  195.     CALLS    rewind    ,<#LUN.IN>    ; Rewind to start of the file
  196.     mov    #topics    ,r5        ; Point to the help topic list
  197.     mov    #'1    ,r2        ; Current topic level
  198.     clrb    htopic            ; Clear header out
  199.                     ;
  200. 10$:    tst    @r5            ; Anything to look for ?
  201.     beq    100$            ; No, just leave pointing at beginning
  202.     mov    #hlpbuf    ,r4        ; Pointer to buffer to use
  203.     tst    cccnt            ; Control C typed?
  204.     bne    90$            ; Yes, please exit this loop
  205.     clrb    @r4            ; Preset to a null string
  206.     CALLS    getrec    ,<r4,#LUN.IN>    ; Read a record from the file
  207.     tst    r0            ; Errors on the read ?
  208.     beq    20$            ; no
  209.     cmp    r0    ,#ER$EOF    ; End of file reached ?
  210.     beq    90$            ; Yes, return(1)
  211. 20$:    clrb    hlpbuf(r1)        ; Insure .asciz please
  212.     cmpb    @r4    ,r2        ; Topic levels match up?
  213.     bne    80$            ; No, read another record then
  214.     inc    r4            ; Skip over the level flag now
  215. 30$:    tstb    @r4            ; End of the line
  216.     beq    80$            ; Yes, read another record
  217.     cmpb    @r4    ,#40        ; No, skip over spaces now
  218.     bne    40$            ; No more spaces, time to check topic
  219.     inc    r4            ; Spaces, skip over please
  220.     br    30$            ; Next please
  221. 40$:    mov    (r5)    ,r3        ; Get pointer to text to match up
  222.     cmpb    (r3)    ,#'*        ; Wildcarding ?
  223.     beq    85$            ; Yes, return(2)
  224.                     ;
  225. 50$:    tstb    (r3)            ; Found the end of the desired topic?
  226.     beq    70$            ; Yes, check for next level topic needed
  227.     tstb    (r4)            ; End of the line yet ?
  228.     beq    80$            ; Yes.
  229.     movb    (r4)+    ,r0        ; Convert to upper case
  230.     cmpb    r0    ,#'a!40        ; Is this a lower case letter
  231.     blo    55$            ; No
  232.     cmpb    r0    ,#'z!40        ; Keep checking...
  233.     bhi    55$            ; No
  234.     bicb    #40    ,r0        ; Convert to upper case
  235. 55$:    cmpb    (r3)+    ,r0        ; No, do the characters match up?
  236.     beq    50$            ; Yes, keep checking them
  237.     br    80$            ; No, read another record.
  238.                     ;
  239. 70$:    inc    r2            ; Match, increment level number and read
  240.     tst    (r5)+            ; another record from the help file.
  241.     STRCAT    #htopic    ,#hlpbuf+1    ; Build up a header record
  242. 80$:    br    10$            ; Next please
  243.  
  244.  
  245. 85$:    mov    #2    ,r0        ; Match with wildcarding
  246.     mov    r2    ,toplev        ; Save the topic level and exit
  247.     br    110$            ; Exit
  248.                     ;
  249. 90$:    mov    #1    ,r0        ; Not found (reached end of file)
  250.     br    110$            ; Exit
  251.                     ;
  252. 100$:    mov    r2    ,toplev        ; Save topic level
  253.     dec    toplev            ; It will be off by one
  254.     clr    r0            ; Found the topic
  255. 110$:    unsave    <r5,r4,r3,r2>        ; Pop registers and exit
  256.     return                ; Bye
  257.  
  258.  
  259.     .dsabl    lsb
  260.  
  261.  
  262.  
  263.     .sbttl    print help text already found by HFIND
  264.     .enabl    lsb
  265.  
  266.  
  267. ;    Return:    <0    Failure, the RMS error code
  268. ;         0    Success
  269. ;         1    Found subtopics to print out
  270. ;
  271. ;    Assumes:    That both PARSE and HFIND have been called already.
  272.  
  273. hprint:    save    <r2,r3,r4,r5>        ; Save these registers please
  274.     STRCPY    #ttbuff    ,#htopic    ; Get the default header string made
  275.                     ;
  276. 30$:    tst    cccnt            ; Control C interupt ?
  277.     bne    90$            ; Yes, exit please
  278.     mov    #hlpbuf    ,r4        ; Point to the buffer now
  279.     CALLS    getrec    ,<r4,#LUN.IN>    ; Read the next record
  280.     tst    r0            ; Error ?
  281.     bne    90$            ; Yes, exit
  282.     clrb    hlpbuf(r1)        ; Insure it's .asciz please
  283.     cmpb    (r4)    ,#40        ; Leading space ?
  284.     blos    60$            ; Yes, a normal line to print
  285.     cmpb    (r4)    ,toplev        ; Is this a lower, higher or same?
  286.     blo    90$            ; Lower level, thus we must exit.
  287.     beq    50$            ; Same level
  288.     movb    (r4)    ,-(sp)        ; Pass the level number please
  289.     call    hindex            ; And print out whats leftover.
  290.     tst    wild            ; If not wildcarded then exit.
  291.     beq    80$            ; Exit
  292.                     ;
  293. 50$:    tst    wild            ; Same level, wildcarded?
  294.     beq    90$            ; No, we must exit then.
  295.     inc    r4            ; Skip past the leading number in line
  296.     STRCPY    #ttbuff    ,#htopic    ; Build a header string up
  297.     STRCAT    #ttbuff    ,r4        ; Copy over the topic name.
  298.     dec    r4            ; Reset the pointer
  299.     clrb    @r4            ; Don't print this line.
  300.                     ;
  301. 60$:    tstb    ttbuff            ; Do we need to print the next topic?
  302.     beq    70$            ; No
  303.     MESSAGE                ; CrLf
  304.     PRINT    #ttbuff            ; Yes, dump it please
  305.     MESSAGE                ; Ditto...
  306.     clrb    ttbuff            ; Clear topic name out now
  307. 70$:    tstb    @r4            ; Don't print if NULL
  308.     beq    75$            ; ...
  309.     PRINT    r4            ; Ok to print, dump the text now
  310. 75$:    MESSAGE                ; A cr/lf please
  311.     br    30$            ; Next please
  312.  
  313.  
  314. 80$:    mov    #1    ,r0        ; Return(Sub_topic_found)
  315.     br    100$            ; Exit
  316.                     ;
  317. 90$:    clr    r0            ; Return(Success)
  318.     br    100$            ; Exit
  319.                     ;
  320. 100$:    unsave    <r5,r4,r3,r2>        ; Pop registers and exit
  321.     return                ; And finally exit
  322.  
  323.     .dsabl    lsb
  324.  
  325.  
  326.  
  327.  
  328.     .sbttl    print index out
  329.     .enabl    lsb
  330.  
  331. ;    Passed:    2(sp)    Level to look for
  332. ;
  333. ;    Assumption:    HLPBUF is already loaded with the current record
  334.  
  335. hindex:    save    <r2,r3,r4,r5>        ; We may overwrite these here
  336.     clr    -(sp)            ; Allocate some buffers
  337.     clr    -(sp)            ; Allocate some buffers
  338.     mov    sp    ,idxdmp        ; Flag that we have been here
  339.     mov    sp    ,r5        ; And a pointer to such
  340.     movb    2+<6*2>(sp),2(r5)    ; Get the topic level passed.
  341.     mov    #idxbuf    ,r3        ; Get a buffer to store names in
  342.     mov    #hlpbuf    ,r4        ; Point to the help buffer now
  343.     cmpb    2(r5)    ,#'1        ; Is this the MAIN menu today?
  344.     bhi    10$            ; No, don't reposition the file
  345.     CALLS    rewind    ,<#LUN.IN>    ; It is the main, reset the file
  346.     clrb    hlpbuf            ; Flag that nothings there
  347. 10$:    Message    <    Additional information is available on:>,cr
  348.     Message                ; An extra CR/LF
  349.     Message                ; CRLF please
  350.     STRCPY    r3    ,#fill5        ; Move over a bit
  351.     mov    #4    ,(r5)        ; Number of topic names per line
  352.     clr    cccnt            ; Insure control C count is zapped
  353.                     ;
  354. 30$:    tstb    @r4            ; Do we need to load the buffer?
  355.     bne    40$            ; No
  356.     CALLS    getrec    ,<r4,#LUN.IN>    ; Yes, preload the buffer now.
  357.     tst    r0            ; Did we reach end of file?
  358.     bne    80$            ; Yes, exit please
  359.     clrb    hlpbuf(r1)        ; Always .asciz please
  360. 40$:    tst    cccnt            ; If control C then exit
  361.     bne    90$            ; Exit then
  362.     cmpb    @r4    ,#40        ; Is this a null line or a text line?
  363.     blos    60$            ; If so, ignore it.
  364.     cmpb    @r4    ,2(r5)        ; Must be a topic line, check the level
  365.     bhi    60$            ; Higher level, ignore it
  366.     blo    80$            ; Lower level, we need to exit
  367.     clrb    21(r4)            ; Insure no more than 16 characters
  368.     inc    r4            ; Skip the level number on the line
  369.     STRCAT    r3    ,r4        ; Add on the current topic now
  370.     strlen    r4            ; Now compute the number of spaces
  371.     dec    r4            ; Fix the pointer up to startofline
  372.     mov    #22    ,r2        ; Assume worst case of 18 spaces needed
  373.     sub    r0    ,r2        ; We now have the number of spaces.
  374. 50$:    STRCAT    r3    ,#filler    ; Loop adding the spaces in
  375.     sob    r2    ,50$        ; Terribly inefficient, but so what.
  376.     dec    (r5)            ; Is there room left for the next one?
  377.     bne    60$            ; Yes, go and get some more
  378.     PRINT    r3            ; No, we have to dump and reset things
  379.     MESSAGE                ; A cr/lf
  380.     mov    #4    ,(r5)        ; Reset the counter now
  381.     STRCPY    r3    ,#fill5        ; Reset the line buffer
  382.                     ;
  383. 60$:    clrb    @r4            ; Force a read next time
  384.     br    30$            ; Next please
  385.  
  386.     
  387. 80$:    PRINT    r3            ; End of file, dump whats left over
  388.     MESSAGE                ; And exit.
  389.     clr    r0            ; Success
  390.     br    100$            ; Bye
  391.                     ;
  392. 90$:    mov    #-1    ,r0        ; Failure exit
  393.                     ;
  394. 100$:    cmp    (sp)+    ,(sp)+        ; Pop some local buffers...
  395.     unsave    <r5,r4,r3,r2>        ; Pop registers and exit
  396.     mov    (sp)+    ,(sp)        ; Pop return address up and exit
  397.     return                ; Exit now
  398.  
  399.  
  400.     .dsabl    lsb
  401.  
  402.  
  403.  
  404.     .sbttl    open and close the kermit-11 help file up
  405.     .enabl    lsb
  406.  
  407. ;    This code was taken verbatim from the old K11HLP.MAC
  408.  
  409.  
  410. hlpclo:    CALLS    close    ,<#lun.in>
  411.     return
  412.  
  413.  
  414. hlpopn:    call    getprv            ; seems to be needed
  415.     mov    #hnames    ,r1        ; the list of help file names
  416.     call    getsys            ; if this is RT11 use something
  417.     cmpb    r0    ,#sy$rt        ; reasonable please
  418.     bne    10$            ; not RT
  419.     mov    #rtname    ,r1        ; RT11, try DK: and SY:
  420. 10$:    mov    r1    ,r2        ; Save it
  421. 20$:    tst    @r1            ; end of the list as of yet ?
  422.     beq    70$            ; yes, can't find the help file
  423.     CALLS    fopen    ,<@r1,#lun.in,#text,#$HBUFS>; try to open help file
  424.     tst    r0            ; did it work ?
  425.     beq    100$            ; yes
  426.     tst    (r1)+            ; no, try the next help filename
  427.     br    20$            ; next please
  428. 70$:    MESSAGE    <%Kermit-11-W Cannot find the Kermit-11 help files or>,cr
  429.     MESSAGE    <the task image high limit prevents mutliblock reads.>,cr
  430.     MESSAGE    <Please put K11HLP in one of the following locations:>,cr
  431.     MESSAGE                ;
  432. 80$:    tst    @r2            ; Any more left
  433.     beq    90$            ; No
  434.     PRINT    @r2            ; Yes, print the name of the file
  435.     MESSAGE                ; A crlf
  436.     tst    (r2)+            ; Point to next
  437.     br    80$            ; Next please
  438. 90$:    mov    #ER$FNF    ,r0        ; return file not found
  439. 100$:    call    drpprv            ; please no more privs
  440.     return                ; return with it open or not found
  441.  
  442.  
  443.     .dsabl    lsb
  444.     .save
  445.     .psect    rodata    ,ro,d,lcl,rel,con
  446. hnames::.word    10$,20$,30$,40$,0
  447. 10$:    .asciz    /LB:[1,2]K11HLP.HLP/
  448. 20$:    .asciz    /SY:[1,2]K11HLP.HLP/
  449. 30$:    .asciz    /KERMIT:K11HLP.HLP/
  450. 40$:    .asciz    /HELP:K11HLP.HLP/
  451.     .even
  452.  
  453. rtname:    .word    10$,20$,0
  454. 10$:    .asciz    /DK:K11HLP.HLP/
  455. 20$:    .asciz    /SY:K11HLP.HLP/
  456.     .even
  457.     .restore
  458.  
  459.     global    <drpprv    ,getprv    ,getsys>
  460.     global    <$HBUFS>
  461.     .end
  462.