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

  1.     .title    k11cvt    misc data/filename conversions for Kermit-11
  2.     .ident    /1.0.01/
  3.  
  4.  
  5. ;    20-Mar-84  11:31:06 Brian Nelson
  6. ;
  7. ;    Copyright (C) 1984  Change Software, Inc.
  8. ;
  9. ;
  10. ;     Attempt to parse filespecifications that may include DECNET
  11. ;    remote node name and  directories  in  a  manner  compatible
  12. ;    with RSTS, RSX and RT11. 
  13. ;
  14. ;     This was  first  implemented using the host executives file
  15. ;    name parsing services, ie for RSTS using the .FSS  directive
  16. ;    and   for   RSX   using   CSI   and   .PARSE   to   get  the
  17. ;    filespecification converted into rad50 and  then  converting
  18. ;    back  to  ascii.  The  problem with doing it that way, apart
  19. ;    from being a hack, is that we could not process DECNET  node
  20. ;    file  specifications  as the format of remote file names can
  21. ;    never be expected to be compatible  with  the  host  system.
  22. ;    Bob  Denny  wrote  a  new  one  for  RSX  which avoided this
  23. ;    problem,  and  this  version  should  work  on   all   PDP11
  24. ;    operating systems. 
  25. ;
  26. ;     This  is implemented using a  transition state table driver
  27. ;    thus allowing simple modification to accomodate the  various
  28. ;    types of node filenames that may come up in the future.
  29. ;
  30. ;
  31. ;    For the time being, this routine will be placed in the over-
  32. ;    lay region  ERRDVR, since  as of now it is  only called from
  33. ;    K11PAK and then only once for  each file send  to the remote
  34. ;    system or micro.
  35.  
  36.  
  37.  
  38.  
  39.     .if ndf, K11INC
  40.     .ift
  41.     .include    /IN:K11MAC.MAC/
  42.     .endc
  43.  
  44.     .iif ndf, k11inc, .error ; missing INCLUDE for IN:K11MAC.MAC
  45.  
  46.  
  47.  
  48.  
  49.  
  50.     .sbttl    generate character class table for filename state parsing
  51.  
  52.     .psect
  53.  
  54.     .macro    chtype    ch    ,val
  55.  
  56.     .save
  57.     .if ndf    ,chtype
  58.     .ift
  59.     .psect    chtype    ,ro,d,lcl,rel,ovr
  60. chtype:    .rept    128.
  61.     .byte    0
  62.     .endr
  63.     .endc
  64.     .psect    chtype
  65.     . = chtype + ch
  66.     .byte    val
  67.     .restore
  68.  
  69.     .endm    chtype
  70.  
  71.     chtype     0    ,1        ; exit on null
  72.     chtype    15    ,1        ; exit on <cr>
  73.     chtype    73    ,1        ; exit on ';'
  74.     chtype    '[    ,2        ; start of a directory or uic
  75.     chtype    '(    ,2        ; start of a rsts style ppn
  76.     chtype    '<    ,2        ; start of a TOPS-20 directory
  77.     chtype    ']    ,3        ; end of a directory
  78.     chtype    ')    ,3        ; end of a ppn
  79.     chtype    '>    ,3        ; end of a tops-20 directory
  80.     chtype    ':    ,4        ; end of a device or node
  81.     chtype    '.    ,5        ; part of a filename or directory
  82.     chtype    54    ,6        ; part of a uic or ppn (',')
  83.     chtype    40    ,7        ; spaces can be anywhere
  84.     chtype    '#    ,0        ; ignore rsts equivalent for [1,0]
  85.     chtype    '$    ,0        ; ignore rsts/rsx equivalent for system
  86.     chtype    '!    ,0        ; ignore rsts equivalent for [1,3]
  87.     chtype    '%    ,0        ; ignore rsts equivalent for [1,4]
  88.     chtype    '&    ,0        ; ignore rsts equivalent for [1,5]
  89.     chtype    '@    ,0        ; ignore rsts equivalent for assign ppn
  90.     chtype    '0    ,7        ; digits are ok most anywhere
  91.     chtype    '1    ,7
  92.     chtype    '2    ,7
  93.     chtype    '3    ,7
  94.     chtype    '4    ,7
  95.     chtype    '5    ,7
  96.     chtype    '6    ,7
  97.     chtype    '7    ,7
  98.     chtype    '8    ,7
  99.     chtype    '9    ,7
  100.  
  101.  
  102.     $ch    =    'A&137        ; letters also please
  103.     .rept    32
  104.     chtype    $ch    ,7
  105.     $ch    =    $ch + 1
  106.     .endr
  107.     $ch    =    'a!40
  108.     .rept    32
  109.     chtype    $ch    ,7
  110.     $ch    =    $ch + 1
  111.     .endr
  112.  
  113.  
  114.     .sbttl    state transition table
  115.  
  116.  
  117.     .psect    $pdata
  118.  
  119. ptable:
  120.  
  121. ; note: '<' , '(' are mapped the same as '['
  122. ;    '>' , ')' are mapped the same as ']'
  123. ; all characters that map to zero are ignored by the parser
  124. ;
  125. ; char    other    ,null    ,'[    ,']    ,':    ,'.    ,',    ,Let/Dig
  126.  
  127. .byte    1    ,30.    ,2    ,-1    ,11.    ,21.    ,-1    ,21.    ; init
  128. .byte    2    ,30.    ,-1    ,3    ,-1    ,2    ,2    ,2    ; [ ]
  129. .byte    3    ,30.    ,-1    ,-1    ,14.    ,23.    ,3    ,23.    ; [ ]xxx
  130. .byte    4    ,30.    ,30.    ,-1    ,-1    ,24.    ,-1    ,24.    ; xx.xx
  131. .even
  132.  
  133. paction:.word    null    ,init    ,copy    ,fin
  134.  
  135.     .psect    $code
  136.  
  137.  
  138.     .sbttl    namcvt    parse filename to get only filename.type
  139.  
  140. ;    input:    @r5    address of source filespecification
  141. ;        2(r5)    resultant string address
  142. ;    output:    r0    error code, if any
  143. ;
  144. ;
  145. ;    internal register usage
  146. ;
  147. ;    r0    =   action index
  148. ;    r1    =   current state
  149. ;    r2    =   input string pointer
  150. ;    r4    --> resultant string
  151.     
  152.  
  153. namcvt::save    <r1,r2,r3,r4>        ; save these in case we use them
  154.     mov    @r5    ,r2        ; point to the input string
  155.     mov    2(r5)    ,r4        ; point to the output string
  156.     clrb    @r4            ; init output to be .asciz
  157.     mov    #1    ,r1        ; initialize current state
  158.     tst    rawfil            ; /54/ Really string stuff?
  159.     beq    10$            ; /54/ Yes
  160.     STRCPY    r4    ,r2        ; /54/ No, copy as is.
  161.     clr    r0            ; /54/ No errors
  162.     br    100$            ; /54/ And exit
  163.  
  164. 10$:    tst    r1            ; current state is zero ?
  165.     beq    80$            ; yes, exit then
  166.     clr    r3            ; get the next ch please
  167.     bisb    (r2)+    ,r3        ; simple
  168.     bic    #^C177    ,r3        ; insure in range 0..127
  169.     dec    r1            ; use previous state to get the
  170.     mul    #10    ,r1        ; index into the state table
  171.     movb    chtype(r3),r0
  172.     add    r0    ,r1        ; add in the character class
  173.     movb    ptable(r1),r1        ; and get the new state of system
  174.     beq    80$            ; all done if new state is zero
  175.     bmi    90$            ; error exit if < 0
  176.     clr    r0            ; now mask off the action index from
  177.     div    #10.    ,r0        ; the new state
  178.     asl    r0            ; action index times 2 for addressing
  179.     jsr    pc    ,@paction(r0)    ; simple
  180.     br    10$            ; next please
  181.  
  182. 80$:    clr    r0            ; no errors
  183.     clrb    @r4            ; .asciz for output
  184.     br    100$            ; bye
  185.  
  186. 90$:    mov    #-1    ,r0        ; error, bye
  187. 100$:    unsave    <r4,r3,r2,r1>        ; pop registers and exit
  188.     return
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.     .sbttl    action routines for the filename parser
  196.  
  197. null:    return
  198.  
  199.  
  200. init:    mov    2(r5)    ,r4        ; re-init the output string address
  201.     return
  202.  
  203.  
  204. copy:    movb    r3    ,(r4)+        ; copy a byte
  205.     clrb    @r4            ; terminate the string
  206.     return                ; next please
  207.  
  208.  
  209. fin:    save    <r0,r3>            ; all done, look for a '.'
  210.     mov    2(r5)    ,r0        ; if there isn't any, add one at
  211. 10$:    tstb    @r0            ; end of the line yet ?
  212.     beq    20$            ; yes
  213.     cmpb    @r0    ,#'.        ; a dot hanging around today?
  214.     beq    30$            ; yes, exit
  215.     inc    r0            ; no, try again please
  216.     br    10$
  217. 20$:    movb    #'.    ,r3        ; no dot, stuff one in please
  218.     call    copy            ; simple
  219. 30$:    unsave    <r3,r0>            ; pop temps and exit
  220.     return
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.     .sbttl    check_extension      check filetype to presume binary file
  229.  
  230. ;    C H K E X T
  231. ;
  232. ;    input:    @r5    filename
  233. ;    output:    r0    =  0 assume not a binary file
  234. ;        r0    <> 0 assume it's a binary file
  235. ;
  236. ;    side effects:    call to NAMCVT to get Kermit 'normal' filename
  237.  
  238.     .enabl    lsb
  239.  
  240. chkext::save    <r1,r2,r3,r4>        ; save scratch registers we will use
  241.     sub    #100    ,sp        ; allocate a temp buffer for the
  242.     mov    sp    ,r1        ; parsed filename and point to it.
  243.     calls    namcvt    ,<@r5,r1>    ; convert host name to normal name.
  244.     strlen    r1            ; how much is left ?
  245.     tst    r0            ; if nothing, then presume not binary
  246.     beq    290$            ; nothing to do, exit
  247.     add    r0    ,r1        ; point to the end of the filename
  248. 210$:    cmpb    -(r1)    ,#'.        ; look for a dot which will delimit the
  249.     beq    220$            ; filetype
  250.     sob    r0    ,210$        ; not found, try again please
  251.     br    290$            ; never found a '.' (can't happen)
  252. 220$:    strlen    r1            ; how many chars are in the filetype?
  253.     cmp    r0    ,#4        ; must be exactly four to match?
  254.     bne    290$            ; no, exit without binary mode
  255.     mov    bintyp    ,r2        ; ok, get listhead of filetypes
  256. 230$:    mov    r2    ,r3        ; get next filetype address
  257.     tstb    @r3            ; end of the list ?
  258.     beq    290$            ; if null, then all done
  259.     mov    r1    ,r4        ; not done, get pointer to passed type
  260.     call    310$            ; convert to upper case please
  261.     cmpb    r0    ,(r3)+        ; look for match on filetype
  262.     bne    240$            ; not today
  263.     call    310$            ; convert to upper case please
  264.     cmpb    r0    ,(r3)+        ; again please
  265.     bne    240$            ; not bloody likely
  266.     call    310$            ; convert to upper case please
  267.     cmpb    r0    ,(r3)+        ; and so on
  268.     bne    240$            ; you know
  269.     call    310$            ; convert to upper case please
  270.     cmpb    r0    ,(r3)+        ; one more time
  271.     beq    280$            ; a match, return (BINARY)
  272. 240$:    add    #4    ,r2        ; get the next one please
  273.     br    230$            ; no match, try the next one
  274.     
  275.  
  276.  
  277. 280$:    mov    #1    ,r0        ; return (BINARY)
  278.     br    300$            ; and exit
  279. 290$:    clr    r0            ; not binary
  280. 300$:    add    #100    ,sp        ; pop local buffer and exit
  281.     unsave    <r4,r3,r2,r1>        ; pop registers that we used
  282.     return                ; and exit
  283.  
  284.  
  285. 310$:    movb    (r4)+    ,r0        ; get the next character and convert to
  286.     cmpb    r0    ,#'A!40        ; upper case
  287.     blo    320$            ; no
  288.     cmpb    r0    ,#'Z!40        ; well......?
  289.     bhi    320$            ; not lower case
  290.     bicb    #40    ,r0        ; lower, convert to upper
  291. 320$:    return
  292.  
  293.  
  294.     .dsabl    lsb
  295.  
  296.  
  297.  
  298.     .sbttl    filetypes that are likely to be binary
  299.  
  300. binini::strcpy    bintyp    ,#binl
  301.     return
  302.  
  303.     global    <bintyp>
  304.  
  305.  
  306. ;    list of filetypes that will almost always be binary for all exec's
  307.  
  308.     .save
  309.     .psect    $pdata
  310.     .dsabl    lc    
  311.  
  312.  
  313. binl:    .ascii    /.TSK/            ; rsx/ias/rsts tasks
  314. 420$:    .ascii    /.SAV/            ; rt11/rsts save images
  315. 430$:    .ascii    /.OBJ/            ; compiler/mac output
  316. 440$:    .ascii    /.STB/            ; tkb/link symbol tables
  317. 450$:    .ascii    /.CRF/            ; tkb/link cross reference files
  318. 460$:    .ascii    /.TSD/            ; 'time shared dibol' for rt11
  319. 470$:    .ascii    /.BAC/            ; rsts basic+ 'compiled' files
  320. 480$:    .ascii    /.OLB/            ; rsx/ias/rsts object libraries
  321. 490$:    .ascii    /.MLB/            ; rsx/ias/rsts macro libraries
  322. 500$:    .ascii    /.RTS/            ; rsts/e run time systems
  323. 510$:    .ascii    /.EXE/            ; vms executable
  324. 530$:    .ascii    /.BIN/            ; xxdp+ and perhaps micros and others?
  325. 540$:    .ascii    /.SML/            ; system macro libs
  326. 550$:    .ascii    /.ULB/            ; rsts/rsx universal libs
  327. 560$:    .ascii    /.HLB/            ; help libs ala VMS style ?
  328. 570$:    .ascii    /.SYS/            ; RT11 drivers
  329. 580$:    .ascii    /.LIB/            ; RSTS/E reslibs
  330. 600$:    .byte    0,0,0,0            ; end of it all
  331.     .even
  332.     .restore
  333.  
  334.  
  335.  
  336.  
  337.     .sbttl    fixfilename    convert bad filename chars to something else
  338.  
  339. ;    FIXFILE    (srcstring,dststring)
  340. ;
  341. ;    Convert invalid characters to something reasonable, like 'X'
  342. ;
  343. ;    Input:    0(r5)    source string, .asciz
  344. ;        2(r5)    destination string, .asciz at end
  345. ;    Output:    R0    zero if nothing, else nonzero (for warnings)
  346. ;
  347. ;    The main reason for this is to protect ourselves against the
  348. ;    filenaming conventions used for TOPS20 and VMS V4 so we  can
  349. ;    not die on a bad filename.
  350.  
  351.  
  352.     .save
  353.     .psect    $pdata
  354. defchr::.byte    'X&137
  355.     .restore
  356.  
  357.  
  358. fixfil::save    <r1,r2,r3>        ; save whatever we may use
  359.     mov    @r5    ,r1        ; src string
  360.     mov    2(r5)    ,r2        ; dst string
  361.     clr    r3            ; assume no mods made to filename
  362. 10$:    tstb    @r1            ; end of the src filename ?
  363.     beq    35$            ; yes, exit
  364.     scan    @r1    ,#okchr        ; check for invalid characters
  365.     tst    r0            ; did we find one yet
  366.     bne    20$            ; no (we checked for legit chars)
  367.     mov    sp    ,r3        ; flag that we found a bad character
  368.     movb    defchr    ,@r2        ; and insert the fixup character
  369.     br    30$            ; exit
  370. 20$:    movb    @r1    ,@r2        ; character is ok, stuff it in
  371. 30$:    inc    r1            ; advance to next src char
  372.     inc    r2            ; advance to next dst char
  373.     br    10$            ; next char in filename please
  374.  
  375.                     ; Following for RT11 added /51/
  376. 35$:    call    getsys            ; Check if RT11
  377.     cmpb    r0    ,#SY$RT        ; If RT11, then truncate names
  378.     bne    100$            ; Not RT, just take simple exit
  379.                     ;
  380.     sub    #FILSIZ    ,sp        ; RT11, allocate a buffer
  381.     mov    sp    ,r1        ; And get a temporary copy
  382.     mov    2(r5)    ,r2        ; The destination string
  383.     STRCPY    r1    ,r2        ; Copy the formatted string
  384.     mov    #6    ,r0        ; Setup to truncate FILENAME
  385.                     ;
  386. 40$:    cmpb    (r1)    ,#'.        ; End of FILENAME field?
  387.     beq    70$            ; Yes, skip to FILETYPE Copy.
  388.     movb    (r1)+    ,(r2)+        ; Copy the character
  389.     beq    90$            ; And exit on a NULL
  390. 50$:    sob    r0    ,40$        ; Next please
  391.                     ;
  392. 60$:    tstb    (r1)            ; Loop for looking for NULL or '.'
  393.     beq    90$            ; Null, end of string then.
  394.     cmpb    (r1)    ,#'.        ; We may have truncated the name
  395.     beq    70$            ; So look for a DOT for FILETYPE
  396.     mov    sp    ,r3        ; And flag that we altered name
  397.     inc    r1            ; Next please
  398.     br    60$            ; Go to it
  399.                     ;
  400. 70$:    mov    #4    ,r0        ; At most 4 characters in FILETYPE
  401. 80$:    movb    (r1)+    ,(r2)+        ; Finish off with the filetype
  402.     sob    r0    ,80$        ; Next please
  403.                     ;
  404. 90$:    clrb    (r2)+            ; Insure .asciz
  405.     add    #FILSIZ    ,sp        ; Pop local buffer
  406.                     ; End of RT11 filename truncation.
  407.                     ;
  408. 100$:    mov    r3    ,r0        ; return status
  409.     clrb    @r2            ; insure .asciz return
  410.     unsave    <r3,r2,r1>        ; pop registers and exit
  411.     return
  412.  
  413.  
  414.     .save
  415.     .psect    $pdata
  416.     .even
  417.     .enabl    lc
  418. okchr:    .ascii    /0123456789./
  419.     .ascii    /abcdefghijklmnopqrstuvwxyz/
  420.     .ascii    /ABCDEFGHIJKLMNOPQRSTUVWXYZ/
  421.     .byte    0
  422.     .even
  423.     .restore
  424.  
  425.  
  426.     .sbttl    PRSARG
  427.  
  428.  
  429. ;    Convert strings of form abcde<15>  or  abcde\015
  430. ;    to binary format.
  431.  
  432.  
  433.  
  434. prsarg::save    <r1,r2,r3,r4>        ; /45/ Save regs
  435.     mov    argbuf    ,r3        ; /41/ Argbuf address
  436.     mov    r0    ,r4        ; /41/ Where to return parsed string
  437. 10$:    movb    (r3)+    ,r2        ; /41/ While ( *argbuf )
  438.     beq    100$            ; /41/ Exit with success
  439.     cmpb    r2    ,#'\        ; /45/ "C" style notation?
  440.     beq    50$            ; /45/ Yes
  441.     cmpb    r2    ,#'<        ; /41/ Start of an octal sequence?
  442.     bne    40$            ; /41/ No.
  443.     clr    r1            ; /41/ Init accumulator
  444. 20$:    movb    (r3)+    ,r2        ; /41/ While ( *argbuf++ )
  445.     beq    90$            ; /41/ Error, No terminator
  446.     cmpb    r2    ,#'>        ; /41/ Octal number terminator?
  447.     beq    30$            ; /41/ Yes, exit loop
  448.     cmpb    r2    ,#'0        ; /41/ Check for legitimate value
  449.     blo    90$            ; /41/ Not an octal digit, error
  450.     cmpb    r2    ,#'7        ; /41/ Check again please
  451.     bhi    90$            ; /41/ Not legit, error
  452.     sub    #'0    ,r2        ; /41/ Yes, convert to octal until '>'
  453.     asl    r1            ; /41/ Shift over a bit
  454.     asl    r1            ; /41/ ..shift
  455.     asl    r1            ; /41/ ....shift, total of 3 bits
  456.     add    r2    ,r1        ; /41/ Add in current digit
  457.     br    20$            ; /41/ No
  458. 30$:    mov    r1    ,r2        ; /41/ Yes, get set to insert value
  459. 40$:    movb    r2    ,(r4)+        ; /41/ Place current char or value in
  460.     br    10$            ; /41/ Next please
  461.  
  462. 50$:    clr    r1            ; /45/ "C" style notation 
  463.     clr    -(sp)            ; /45/ Trip counter
  464. 60$:    movb    (r3)    ,r2        ; /45/ Copy a character
  465.     beq    70$            ; /45/ EOS, exit next time
  466.     cmpb    r2    ,#'0        ; /45/ Octal characters?
  467.     blo    70$            ; /45/ No, exit this loop
  468.     cmpb    r2    ,#'7        ; /45/ ...
  469.     bhi    70$            ; /45/ Copy the character
  470.     inc    (sp)            ; /45/ Been here at least once
  471.     sub    #'0    ,r2        ; /45/ Yes, convert to octal
  472.     asl    r1            ; /45/ Shift over a bit
  473.     asl    r1            ; /45/ ..shift
  474.     asl    r1            ; /45/ ....shift, total of 3 bits
  475.     add    r2    ,r1        ; /45/ Add in current digit
  476.     inc    r3            ; /45/ Next please
  477.     br    60$            ; /45/ Do it
  478. 70$:    tst    (sp)+            ; /45/ Did we really get a number?
  479.     beq    75$            ; /45/ No, ignore then
  480.     movb    r1    ,(r4)+        ; /45/ Done, copy the data
  481.     br    80$            ; /45/ And get next please
  482. 75$:    tstb    r2            ; /45/ No number, perhaps "\\" or
  483.     beq    80$            ; /45/ or "\<" was present?
  484.     movb    r2    ,(r4)+        ; /45/ Must have had "\x"
  485.     inc    r3            ; /45/ Point to NEXT please
  486. 80$:    br    10$            ; /45/ Next please
  487.  
  488. 90$:    mov    #-1    ,r0        ; /41/ Failed
  489.     br    110$            ; /41/ exit
  490. 100$:    clr    r0            ; /41/ Success
  491. 110$:    clrb    @r4            ; /41/ Insure LOGSTR is .asciz
  492.     unsave    <r4,r3,r2,r1>        ; /45/ Pop
  493.     return
  494.  
  495.  
  496.  
  497.     .sbttl    Unfmts    Inverse of PRSARG
  498.  
  499.     .Save
  500.     .psect    UDATA,RW,D,LCL,REL,CON
  501. ubuf:    .blkb    80.
  502.     .Restore
  503.  
  504.  
  505. Unfmts::Save    <r1,r2,r3,r4,r5>    ; Save registers please
  506.     mov    r0    ,r5        ; Copy the address of the data
  507.     mov    #ubuf    ,r4        ; Target buffer
  508. 10$:    movb    (r5)+    ,r1        ; Get the data
  509.     beq    100$            ; All done
  510.     cmpb    r1    ,#40        ; Control character?
  511.     blo    20$            ; Yes
  512.     movb    r1    ,(r4)+        ; No, just copy as is
  513.     br    40$            ; And do the next one
  514. 20$:    movb    #'\    ,(r4)+        ; Control character, insert '\'
  515.     clr    r0            ; Get setup for conversion
  516.     div    #10    ,r0        ; Got it
  517.     movb    r1    ,r2        ; Save the LSB
  518.     mov    r0    ,r1        ; And get the last two out
  519.     clr    r0            ; ....
  520.     div    #10    ,r0        ; Do it
  521.     add    #'0    ,r0        ; Convert to ascii
  522.     add    #'0    ,r1        ; ..Ditto
  523.     add    #'0    ,r2        ; ....Ditto
  524.     movb    r0    ,(r4)+        ; Insert the data
  525.     movb    r1    ,(r4)+        ; Insert the data
  526.     movb    r2    ,(r4)+        ; Insert the data
  527. 40$:    br    10$            ; Next please
  528. 100$:    clrb    @r4            ; Insure .ASCIZ
  529.     mov    #ubuf    ,r0        ; Return a buffer address
  530.     Unsave    <r5,r4,r3,r2,r1>    ; Pop registers and exit
  531.     return                ; Bye
  532.  
  533.  
  534.     .end
  535.