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

  1.     .title    KRTCVT    File name and misc data conversions
  2.     .ident    "V03.63"
  3.  
  4. ; /63/    27-Sep-97  Billy Youdelman  V03.63
  5. ;
  6. ;    fixfil now fixes unix leading dot ".file" names, also ".x.", etc.
  7. ;    cleaned up chkext
  8. ;    move unfmts to KRTSUB so KRTMDM can use this overlay ...
  9.  
  10. ; /62/    27-Jul-93  Billy Youdelman  V03.62
  11. ;
  12. ;    increase size of fixfil stack buffer to SVID limit
  13.  
  14. ; /BBS/     1-Dec-91  Billy Youdelman  V03.61
  15. ;
  16. ;    added useful RT-11/TSX+ binary file types
  17. ;    modified chkext to handle file types of less than 3 chars
  18. ;    fixfil - parse a device name in filespec, fixed termination bug
  19. ;    namcvt now catches unix "/" and pc "\" directory delimiters
  20. ;    namcvt fixed to not output a "." on a null input file name
  21.  
  22. ;    Copyright 1984 Change Software, Inc.
  23. ;
  24. ;    20-Mar-84  11:31:06 Brian Nelson
  25. ;
  26. ;     Attempt to parse filespecifications that may include DECNET
  27. ;    remote node name and  directories  in  a  manner  compatible
  28. ;    with RSTS, RSX and RT-11.
  29. ;
  30. ;     This was  first  implemented using the host executives file
  31. ;    name parsing services, ie for RSTS using the .FSS  directive
  32. ;    and   for   RSX   using   CSI   and   .PARSE   to   get  the
  33. ;    filespecification converted into rad50 and  then  converting
  34. ;    back  to  ascii.  The  problem with doing it that way, apart
  35. ;    from being a hack, is that we could not process DECNET  node
  36. ;    file  specifications  as the format of remote file names can
  37. ;    never be expected to be compatible  with  the  host  system.
  38. ;    Bob  Denny  wrote  a  new  one  for  RSX  which avoided this
  39. ;    problem,  and  this  version  should  work  on   all  PDP-11
  40. ;    operating systems.
  41. ;
  42. ;     This  is implemented using a  transition state table driver
  43. ;    thus allowing simple modification to accommodate the various
  44. ;    types of node file names that may come up in the future.
  45. ;
  46. ;     For the time being this routine will be placed in the over-
  47. ;    lay region  ERRDVR, since  as of now it is  only called from
  48. ;    KRTPAK and then only once for  each file send  to the remote
  49. ;    system or micro.
  50.  
  51.  
  52.     .include "IN:KRTMAC.MAC"
  53.     .iif ndf  KRTINC  .error    <; .include for IN:KRTMAC.MAC failed>
  54.  
  55.  
  56.     .macro    chtype    ch ,val        ; /62/ work around "n/df" hosing .LST
  57.     .if nb    ch
  58.     . = chtype+ch            ; put in the buffer, according to its
  59.     .byte    val            ; ascii value as an offset into it
  60.     .iff
  61.     . = chtype+128.            ; /63/ if no args, restore pc
  62.     .endc
  63.     .endm    chtype
  64.  
  65.  
  66.     .sbttl    Local data        ; /63/ consolidate here..
  67.  
  68.     .psect    $rwdata    ,rw,d,lcl,rel,con
  69. chkbuf:    .byte    0 ,0 ,0 ,0 ,0 ,0    ; /BBS/ buff to pad extents <3 chars
  70.  
  71.     .psect    $pdata
  72. defchr:    .byte    'X&137            ; replace any bad name char with this
  73. okchr:    .asciz    "0123456789.:ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; /BBS/ allow device
  74.     .even                ; /E64/ just in case
  75.  
  76.  
  77.     .sbttl    BINARY-TYPES default list
  78.     .dsabl    lc            ; binl data MUST be UPPER case
  79.  
  80. ; /BBS/ space-pad to four bytes if file type is less than four bytes..
  81.  
  82. binl:    .ascii    ".BAC"            ; compiled BASIC files
  83.     .ascii    ".BAX"            ; /BBS/ double precision .BAC files
  84.     .ascii    ".BIN"            ; XXDP
  85.     .ascii    ".BOT"            ; /BBS/ RT-11 boot files
  86.     .ascii    ".BUP"            ; /62/ backup files
  87.     .ascii    ".CAL"            ; /62/ spreadsheet files
  88.     .ascii    ".CRF"            ; link cross reference files
  89.     .ascii    ".DEV"            ; /BBS/ old logical disk file
  90.     .ascii    ".DSK"            ; /BBS/ logical disk file
  91.     .ascii    ".EXE"            ; executable image only, no data
  92.     .ascii    ".LDA"            ; /62/ absolute load address images
  93.     .ascii    ".MLB"            ; macro libraries
  94.     .ascii    ".OBJ"            ; MACRO output files
  95.     .ascii    ".REL"            ; /BBS/ RT-11 relocatable programs
  96.     .ascii    ".RTS"            ; TSX+ run time systems
  97.     .ascii    ".SAV"            ; RT-11 saved images
  98.     .ascii    ".SML"            ; system macro libs
  99.     .ascii    ".STB"            ; LINK symbol tables
  100.     .ascii    ".SYS"            ; RT-11 monitors, drivers
  101.     .ascii    ".TSX"            ; /BBS/ TSX+ system files
  102.     .byte    0            ; /BBS/ end of it all
  103.     .even
  104.     .enabl    lc            ; /BBS/ restore
  105.  
  106.  
  107.     .sbttl    Generate character class table for file name state parsing
  108.  
  109. ;      character    class      operation    /63/ commented for clarity..
  110. ;      ---------    -----      ---------  
  111. ;         other     0      ignore, skip past adding nothing to output
  112. ;          nul     1      input string termination chars, must exit
  113. ;         < ( [     2      start of a dircetory, ppn or uic
  114. ;         > ) ]     3      end of a dircetory, ppn or uic
  115. ;         : / \     4      end of a device, directory or node
  116. ;          dot     5      part of a directory or file name
  117. ;         comma     6      part of a ppn or uic
  118. ;    alpha-numeric     7      any char that's ok in directory or file name
  119.  
  120. chtype:    .rept    128.        ; doing ascii 0. through 127.
  121.     .byte         0    ; init everything to being ignored
  122.     .endr
  123.  
  124.     chtype     0    ,1    ; exit on null
  125.     chtype    lf    ,1    ; /62/ exit on a line feed
  126.     chtype    cr    ,1    ; exit on <cr>
  127.     chtype    '(    ,2    ; start of a rsts style ppn
  128.     chtype    ')    ,3    ; end of a ppn
  129.     chtype    comma    ,6    ; part of a uic or ppn
  130.     chtype    dot    ,5    ; part of a file name or directory
  131.     chtype    '/    ,4    ; /BBS/ end of a unix directory
  132.      $ch =    '0        ; /62/ digits are ok most anywhere
  133.      .rept    10.
  134.      chtype    $ch    ,7
  135.      $ch =    $ch+1        ; do 0 through 9
  136.      .endr
  137.     chtype    '<    ,2    ; start of a TOPS-20 directory
  138.     chtype    ':    ,4    ; end of a device or node
  139.     chtype    scolon    ,1    ; exit on ";" version delimiter
  140.     chtype    '>    ,3    ; end of a TOPS-20 directory
  141.      $ch =    'A&137        ; letters are also ok most anywhere
  142.      .rept    32
  143.      chtype    $ch    ,7
  144.      $ch =    $ch+1        ; do A through Z
  145.      .endr
  146.     chtype    '[    ,2    ; start of a directory or uic
  147.     chtype    '\    ,4    ; /BBS/ end of a pc directory
  148.     chtype    ']    ,3    ; end of a directory
  149.     chtype            ; /63/ end of this list
  150.      $ch =    'a!40        ; don't forget lower case letters
  151.      .rept    32
  152.      chtype    $ch    ,7
  153.      $ch =    $ch+1        ; do a through z
  154.      .endr
  155.     chtype            ; /63/ restore the pc
  156.  
  157.  
  158.     .sbttl    NAMCVT state transition table
  159.  
  160. ptable:
  161.  
  162. ; char    other    null    '[    ']    ':    '.    ',   letter/digit
  163. ; class      0      1     2     3     4     5     6      7
  164.  
  165.   .byte      1    ,30.    ,2    ,-1    ,11.    ,21.    ,-1    ,21.  ; init
  166.   .byte      2    ,30.    ,-1    ,3    ,-1    ,2    ,2    ,2    ; [ ]
  167.   .byte      3    ,30.    ,-1    ,-1    ,14.    ,23.    ,3    ,23.  ; [ ]x.x
  168.   .byte      4    ,30.    ,30.    ,-1    ,-1    ,24.    ,-1    ,24.  ; x.x
  169.  
  170. paction:            ; action routines for file name parsing
  171.     .word    null        ; null process, do nothing, ignore input char
  172.     .word    init        ; start over, hosing everything done prior
  173.     .word    copy        ; copy a valid char into the output string
  174.     .word    fin        ; done, append a dot if needed and exit
  175.  
  176.  
  177.     .psect    $code
  178.     .sbttl    Parse file specification to extract only filnam.typ
  179.  
  180. ;    input:     (r5)    address of source file_spec
  181. ;        2(r5)    resultant string address
  182. ;    output:   r0    error code, if any
  183. ;
  184. ;    internal register usage:
  185. ;    r0    =   action index
  186. ;    r1    =   current state
  187. ;    r2    =   input string pointer
  188. ;    r4    --> resultant string
  189.  
  190. namcvt::save    <r1,r2,r3,r4>
  191.     mov    @r5    ,r2        ; point to the input string
  192.     mov    2(r5)    ,r4        ; point to the output string
  193.     clrb    @r4            ; init output to be .asciz
  194.     mov    #1    ,r1        ; initialize current state
  195.     tst    rawfil            ; /54/ really string stuff?
  196.     beq    10$            ; /54/ yes
  197.     strcpy    r4    ,r2        ; /54/ no, copy as is
  198.     clr    r0            ; /54/ no errors
  199.     br    40$            ; /54/ and exit
  200.  
  201. 10$:    tst    r1            ; current state is zero?
  202.     beq    20$            ; yes, exit then
  203.     clr    r3            ; get the next ch please
  204.     bisb    (r2)+    ,r3        ; simple
  205.     bic    #^c<177>,r3        ; ensure in range 0..127
  206.     dec    r1            ; use previous state to get the
  207.     mul    #10    ,r1        ; index into the state table  line
  208.     movb    chtype(r3),r0        ; /BBS/                       column
  209.     add    r0    ,r1        ; add in the character class  line+col
  210.     movb    ptable(r1),r1        ; and get the new state of system
  211.     beq    20$            ; all done if new state is zero
  212.     bmi    30$            ; error exit if < 0
  213.     clr    r0            ; now mask off the action index from
  214.     div    #10.    ,r0        ; the new state
  215.     asl    r0            ; word indexing to action routine
  216.     jsr    pc    ,@paction(r0)    ; simple
  217.     br    10$            ; next please
  218.  
  219. 20$:    clr    r0            ; no errors
  220.     clrb    @r4            ; .asciz for output
  221.     br    40$
  222.  
  223. 30$:    mov    #-1    ,r0        ; error, bye
  224. 40$:    unsave    <r4,r3,r2,r1>
  225.     return
  226.  
  227.  
  228.     .sbttl    Action routines for the file name parser
  229.  
  230. null:    return
  231.  
  232. init:    mov    2(r5)    ,r4        ; re-init the output string address
  233.     clrb    @r4            ; /BBS/ re-init the output buffer
  234.     return
  235.  
  236. copy:    movb    r3    ,(r4)+        ; copy a byte
  237.     clrb    @r4            ; (re)terminate the string
  238.     return                ; next please
  239.  
  240. fin:    save    <r0,r3>            ; all done, look for a dot
  241.     mov    2(r5)    ,r0        ; if there isn't any, add one
  242.     tstb    @r0            ; /BBS/ is there anything left?
  243.     beq    30$            ; /BBS/ don't add a dot to nothing
  244. 10$:    tstb    @r0            ; end of the line yet?
  245.     beq    20$            ; yes
  246.     cmpb    @r0    ,#'.        ; a dot hanging around today?
  247.     beq    30$            ; yes, exit
  248.     inc    r0            ; no, bump to next char
  249.     br    10$            ; and try again please
  250. 20$:    movb    #'.    ,r3        ; no dot, stuff one in please
  251.     call    copy            ; simple
  252. 30$:    unsave    <r3,r0>
  253.     return
  254.  
  255.  
  256.     .sbttl    Check file extent to determine its type
  257.  
  258. ;    C H K E X T
  259. ;
  260. ;    input:     (r5)    = file name
  261. ;    output:      r0    = if <>, assume it's a binary file
  262.  
  263. chkext::save    <r1,r2,r3,r4>
  264.     mov    @r5    ,r1        ; /BBS/ save copy of pointer
  265.     strlen    r1            ; how much is left?
  266.     tst    r0            ; if nothing, then presume not binary
  267.     beq    80$            ; nothing to do, exit
  268.     add    r0    ,r1        ; point to the end of the file name
  269. 10$:    cmpb    -(r1)    ,#'.        ; look for a dot which will delimit
  270.     beq    20$            ; the file type
  271.     sob    r0    ,10$        ; not found, try again please
  272.     br    80$            ; never found a dot (can't happen)
  273. 20$:    copyz    r1    ,#chkbuf,#5    ; /BBS/ make a copy so spaces aren't
  274.     mov    #chkbuf    ,r1        ; /BBS/ written into actual name buff!
  275.     strlen    r1            ; # chars in file type, including "."
  276.     mov    #4    ,r3        ; /BBS/ flip operands for positive num
  277.     sub    r0    ,r3        ; /BBS/ must be 4 chars or less
  278.     beq    40$            ; /BBS/ it's exactly 4, on to testing
  279.     blt    80$            ; /BBS/ it's greater than 4, bail out
  280.     mov    r1    ,r2        ; /BBS/ save copy of pointer
  281.     add    r0    ,r2        ; /BBS/ point to last char
  282. 30$:    movb    #space    ,(r2)+        ; /BBS/ space pad file extent
  283.     sob    r3    ,30$        ; /BBS/ until total length is 4
  284.     clrb    @r2            ; /BBS/ null terminate padded string
  285.  
  286. 40$:    mov    bintyp    ,r2        ; ok, get listhead of file types
  287.     upcase    r1            ; /63/ upper case chkbuf
  288.  
  289. 50$:    mov    r2    ,r3        ; get next file type address
  290.     tstb    @r3            ; end of the list?
  291.     beq    80$            ; if null, then all done
  292.     mov    r1    ,r4        ; not done, get pointer to passed type
  293.     cmpb    (r4)+    ,(r3)+        ; /63/ skip past the dots
  294.     cmpb    (r4)+    ,(r3)+        ; /63/ look for match on file type
  295.     bne    60$            ; not bloody likely
  296.     cmpb    (r4)+    ,(r3)+        ; /63/ and so on
  297.     bne    60$            ; you know
  298.     cmpb    (r4)+    ,(r3)+        ; /63/ one more time
  299.     beq    70$            ; a match, go say so..
  300. 60$:    add    #4    ,r2        ; no match, bump to next one please
  301.     br    50$            ; and go give it a try
  302.  
  303. 70$:    mov    #1    ,r0        ; flag it's a binary file
  304.     br    90$
  305. 80$:    clr    r0            ; not binary
  306. 90$:    unsave    <r4,r3,r2,r1>
  307.     return
  308.  
  309.  
  310.     .sbttl    Init BINARY-TYPES list
  311.  
  312. binini::strcpy    bintyp    ,#binl        ; copy list to buffer in high memory
  313.     return                ; so appending it is possible
  314.  
  315.  
  316.     .sbttl    Convert invalid characters to something reasonable
  317.  
  318. ;    F I X F I L E
  319. ;
  320. ;    Input:     (r5)    = source string, .asciz
  321. ;        2(r5)    = destination string, .asciz
  322. ;    Output:      r0    = zero if unmodified, else non-zero (for warnings)
  323. ;
  324. ;    The main reason for this is to protect ourselves against the
  325. ;    file naming conventions used for TOPS20 and VMS so we do not
  326. ;    die on a bad file name.
  327.  
  328. ; /63/    Modified to accomodate Unix file names, general clean-up too.
  329.  
  330. fixfil::save    <r1,r2,r3>
  331.     sub    #256.    ,sp        ; buffer so src string stays intact
  332.     mov    sp    ,r1        ; pointer to it
  333.     copyz    (r5)    ,r1  ,#255.    ; copy input string into it
  334.     upcase    r1            ; upper case the copy
  335.     clr    r3            ; no mods made yet to file name
  336.  
  337. 10$:    tstb    (r1)            ; this is the replace bad chars loop
  338.     beq    30$            ; null = end of source file spec
  339.     scan    (r1)    ,#okchr        ; check for invalid character
  340.     tst    r0            ; did we find one?
  341.     bne    20$            ; no (we checked for legit chars)
  342.     movb    defchr    ,(r1)        ; ya, insert the fixup character
  343.     mov    #er$fnm    ,r3        ; and flag name has been modified
  344. 20$:    inc    r1            ; advance to next src char
  345.     br    10$            ; and go check it
  346.  
  347. 30$:    mov    sp    ,r1        ; restore pointer to temp buffer
  348.     mov    2(r5)    ,r2        ; dst string buffer address
  349.     scan    #':    ,r1        ; look for a device delimiter
  350.     tst    r0            ; find one?
  351.     beq    50$            ; no..
  352. 40$:    movb    (r1)+    ,(r2)+        ; ya, copy the device name
  353.     sob    r0    ,40$        ; including the colon terminator
  354. 50$:    mov    #6    ,r0        ; RT-11 file name is 6 chars max
  355.  
  356. 60$:    tstb    (r1)            ; anything now left?
  357.     beq    70$            ; no, must have at least 1 char
  358.     cmpb    (r1)    ,#'.        ; end of file name field?
  359.     bne    90$            ; not yet
  360.     inc    r1            ; if a dot, bump pointer past it
  361. 70$:    cmp    r0    ,#6        ; anything at all in the name field?
  362.     bne    100$            ; something has been copied there
  363.     movb    defchr    ,(r2)+        ; no, it must have at least 1 char
  364. 80$:    mov    #er$fnm    ,r3        ; flag that we altered name
  365.     br    100$            ; then continue
  366.  
  367. 90$:    movb    (r1)+    ,(r2)+        ; copy the character
  368.     sob    r0    ,60$        ; next please
  369.     scan    #'.    ,r1        ; now find next dot in input string
  370.     add    r0    ,r1        ; bump ptr past it (no dot = no bump)
  371.     dec    r0            ; next char was dot or no dot at all?
  372.     bgt    80$            ; no, so something had to be tossed..
  373.  
  374. 100$:    movb    #'.    ,(r2)+        ; stuff a dot in output string
  375.     mov    #3    ,r0        ; at most 3 chars in file type
  376.  
  377. 110$:    cmpb    (r1)    ,#'.        ; another dot??  (for unix!)
  378.     beq    120$            ; ya
  379.     cmpb    (r1)    ,#':        ; just in case, is it a colon?
  380.     bne    130$            ; no    (colon is not fixed above..)
  381. 120$:    tstb    (r1)+            ; ya, skip past this char
  382.     mov    #er$fnm    ,r3        ; and flag name was altered..
  383.     br    110$
  384.  
  385. 130$:    movb    (r1)+    ,(r2)+        ; finish off with the file type
  386.     beq    140$            ; hit the end of input string
  387.     sob    r0    ,110$        ; next char please
  388.     clrb    (r2)            ; .asciz
  389.     tstb    (r1)            ; anything left over?
  390.     beq    140$            ; nope..
  391.     mov    #er$fnm    ,r3        ; ya, flag type was truncated..
  392.  
  393. 140$:    add    #256.    ,sp        ; release temp buffer
  394.     mov    r3    ,r0        ; return status
  395.     unsave    <r3,r2,r1>
  396.     return
  397.  
  398.  
  399.     .sbttl    Convert strings ala abcde<15> or abcde\015 to binary format
  400.  
  401. prsarg::save    <r1,r2,r3,r4>        ; /45/ save regs
  402.     mov    argbuf    ,r3        ; /41/ argbuf address
  403.     mov    r0    ,r4        ; /41/ where to return parsed string
  404. 10$:    movb    (r3)+    ,r2        ; /41/ while (*argbuf)
  405.     beq    110$            ; /41/ exit with success
  406.     cmpb    r2    ,#'\        ; /45/ "C" style notation?
  407.     beq    50$            ; /45/ yes
  408.     cmpb    r2    ,#'<        ; /41/ start of an octal sequence?
  409.     bne    40$            ; /41/ no
  410.     clr    r1            ; /41/ init accumulator
  411. 20$:    movb    (r3)+    ,r2        ; /41/ while (*argbuf++)
  412.     beq    100$            ; /41/ error, no terminator
  413.     cmpb    r2    ,#'>        ; /41/ octal number terminator?
  414.     beq    30$            ; /41/ yes, exit loop
  415.     cmpb    r2    ,#'0        ; /41/ check for legitimate value
  416.     blo    100$            ; /41/ not an octal digit, error
  417.     cmpb    r2    ,#'7        ; /41/ check again please
  418.     bhi    100$            ; /41/ not legit, error
  419.     sub    #'0    ,r2        ; /41/ yes, convert to octal until ">"
  420.     ash    #3    ,r1        ; /62/ shift left 3 bits
  421.     add    r2    ,r1        ; /41/ add in current digit
  422.     br    20$            ; /41/ no
  423. 30$:    mov    r1    ,r2        ; /41/ yes, get set to insert value
  424. 40$:    movb    r2    ,(r4)+        ; /41/ place current char or value in
  425.     br    10$            ; /41/ next please
  426.  
  427. 50$:    clr    r1            ; /45/ "C" style notation
  428.     clr    -(sp)            ; /45/ trip counter
  429. 60$:    movb    (r3)    ,r2        ; /45/ copy a character
  430.     beq    70$            ; /45/ EOS, exit next time
  431.     cmpb    r2    ,#'0        ; /45/ octal characters?
  432.     blo    70$            ; /45/ no, exit this loop
  433.     cmpb    r2    ,#'7        ; /45/ ...
  434.     bhi    70$            ; /45/ copy the character
  435.     inc    (sp)            ; /45/ been here at least once
  436.     sub    #'0    ,r2        ; /45/ yes, convert to octal
  437.     ash    #3    ,r1        ; /62/ shift left 3 bits
  438.     add    r2    ,r1        ; /45/ add in current digit
  439.     inc    r3            ; /45/ next please
  440.     br    60$            ; /45/ do it
  441. 70$:    tst    (sp)+            ; /45/ did we really get a number?
  442.     beq    80$            ; /45/ no, ignore then
  443.     movb    r1    ,(r4)+        ; /45/ done, copy the data
  444.     br    90$            ; /45/ and get next please
  445. 80$:    tstb    r2            ; /45/ no number, perhaps "\\" or
  446.     beq    90$            ; /45/ or "\<" was present?
  447.     movb    r2    ,(r4)+        ; /45/ must have had "\x"
  448.     inc    r3            ; /45/ point to next char please
  449. 90$:    br    10$            ; /45/ go get it
  450.  
  451. 100$:    mov    #-1    ,r0        ; /41/ failed
  452.     br    120$            ; /41/ exit
  453. 110$:    clr    r0            ; /41/ success
  454. 120$:    clrb    @r4            ; /41/ ensure string is .asciz
  455.     unsave    <r4,r3,r2,r1>        ; /45/ unsave regs
  456.     return
  457.  
  458.     .end
  459.