home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / tnylib.lzh / MAKEFNM.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-11-21  |  4.0 KB  |  184 lines

  1. include compiler.inc
  2.  
  3.     ttl    MAKFNM, 1.05, 11-04-86, jwk
  4.  
  5. ; makes filename by merging default values from TMPL into SRC and
  6. ;   putting result at DST. handles drive, path, name, and extension.
  7.  
  8.     dseg
  9.     cseg
  10.  
  11. incptr    macro    bump
  12. ifdef    bump&_v
  13.     inc    word ptr bump&_v
  14. else
  15.     inc    word ptr bump
  16. endif
  17.     endm
  18.  
  19. subptr    macro    cnt,bump
  20. ifdef    bump&_v
  21.     sub    cnt,word ptr bump&_v
  22. else
  23.     sub    cnt,word ptr bump
  24. endif
  25.     endm
  26.  
  27. addptr    macro    bump,cnt
  28. ifdef    bump&_v
  29.     add    word ptr bump&_v,cnt
  30. else
  31.     add    word ptr bump,cnt
  32. endif
  33.     endm
  34.  
  35.     xtfs    <rindex, strncpy, strcpy>
  36.  
  37.     procdef    makefnm, <<src, ptr>, <tmpl, ptr>, <dst, ptr>>
  38.     locs    <<temp, ptr>>
  39.     pushds
  40.     pushreg            ; save index regs
  41.     mov    ax, ':'        ; look in SRC for drivespec
  42.     callit    rindex, <<ax, reg>, <src, ptr>>
  43.     svptr    ax, temp, dx
  44.     or    ax, ax
  45.     jz    tdrv        ; none there, try TMPL
  46.     subptr    ax, src        ; got one, calc length
  47.     inc    ax
  48.     push    ax        ; save the length
  49.     callit    strncpy, <<ax, reg>, <src, ptr>, <dst,ptr>>
  50.     pop    ax        ; get length back
  51.     addptr    dst, ax        ; and adjust DST
  52.     ldptr    ax, temp, dx    ; now adjust SRC also
  53.     inc    ax
  54.     svptr    ax, src, dx
  55.     mov    ax, ':'        ; and step over any in TMPL
  56.     callit    rindex, <<ax, reg>, <tmpl, ptr>>
  57.     svptr    ax, temp, dx
  58.     or    ax, ax
  59.     jz    spath        ; none there, look for path
  60.     inc    ax
  61.     svptr    ax, tmpl, dx    ; else adjust TMPL too
  62.     jmp    short spath
  63.  
  64. tdrv:    mov    ax, ':'        ; look for drivespec in TMPL
  65.     callit    rindex, <<ax, reg>, <tmpl, ptr>>
  66.     svptr    ax, temp, dx
  67.     or    ax, ax
  68.     jz    spath        ; none there either, look for path
  69.     subptr    ax, tmpl
  70.     inc    ax
  71.     push    ax
  72.     callit    strncpy, <<ax, reg>, <tmpl, ptr>, <dst, ptr>>
  73.     pop    ax
  74.     addptr    dst, ax
  75.     ldptr    ax, temp, dx    ; adjust TMPL after copy
  76.     inc    ax
  77.     svptr    ax, tmpl, dx
  78.  
  79. spath:    mov    ax, '\'        ; look for pathspec in SRC
  80.     callit    rindex, <<ax, reg>, <src, ptr>>
  81.     svptr    ax, temp, dx
  82.     or    ax, ax
  83.     jz    tpath        ; none there, try TMPL
  84.     subptr    ax, src
  85.     inc    ax
  86.     push    ax
  87.     callit    strncpy, <<ax, reg>, <src, ptr>, <dst, ptr>>
  88.     pop    ax
  89.     addptr    dst, ax
  90.     ldptr    ax, temp, dx
  91.     inc    ax
  92.     svptr    ax, src, dx
  93.     mov    ax, '\'
  94.     callit    rindex, <<ax, reg>, <tmpl, ptr>>
  95.     svptr    ax, temp, dx
  96.     or    ax, ax
  97.     jz    sname
  98.     inc    ax
  99.     svptr    ax, tmpl, dx
  100.     jmp    short sname
  101.  
  102. tpath:    mov    ax, '\'        ; look for pathspec in TMPL
  103.     callit    rindex, <<ax, reg>, <tmpl, ptr>>
  104.     svptr    ax, temp, dx
  105.     or    ax, ax
  106.     jz    sname        ; none there either, look for name
  107.     subptr    ax, tmpl
  108.     inc    ax
  109.     push    ax
  110.     callit    strncpy, <<ax, reg>, <tmpl, ptr>, <dst, ptr>>
  111.     pop    ax
  112.     addptr    dst, ax
  113.     ldptr    ax, temp, dx
  114.     inc    ax
  115.     svptr    ax, tmpl, dx
  116.  
  117. sname:    mov    ax, '.'        ; look for filename in SRC
  118.     callit    rindex, <<ax, reg>, <src, ptr>>
  119.     svptr    ax, temp, dx
  120.     or    ax, ax
  121.     jnz    snam1        ; no ext so try for EOS
  122.     callit    rindex, <<ax, reg>, <src, ptr>>
  123.     svptr    ax, temp, dx
  124. snam1:    
  125.     ldptr    si,src
  126.     cmp    ax, si        ; find anything?
  127.     jz    tname        ; no, try TMPL
  128.     subptr    ax, src
  129.     push    ax
  130.     callit    strncpy, <<ax, reg>, <src, ptr>, <dst, ptr>>
  131.     pop    ax
  132.     addptr    dst, ax
  133.     ldptr    ax, temp, dx
  134.     svptr    ax, src, dx
  135.     mov    ax, '.'
  136.     callit    rindex, <<ax, reg>, <tmpl, ptr>>
  137.     svptr    ax, temp, dx
  138.     or    ax, ax
  139.     jnz    snam2
  140.     callit    rindex, <<ax, reg>, <tmpl, ptr>>
  141. snam2:    svptr    ax, tmpl, dx
  142.     jmp    short endnam
  143.  
  144. tname:    mov    ax, '.'        ; look for filename in TMPL
  145.     callit    rindex, <<ax, reg>, <tmpl, ptr>>
  146.     svptr    ax, temp, dx
  147.     or    ax, ax
  148.     jnz    tnam1        ; no extension, try for EOS
  149.     callit    rindex, <<ax, reg>, <tmpl, ptr>>
  150.     svptr    ax, temp, dx
  151. tnam1:    
  152.     ldptr    si,tmpl
  153.     cmp    ax, si        ; find anything?
  154.     jz    endnam        ; no, all done
  155.     subptr    ax, tmpl
  156.     push    ax
  157.     callit    strncpy, <<ax, reg>, <tmpl, ptr>, <dst, ptr>>
  158.     pop    ax
  159.     addptr    dst, ax
  160.     ldptr    ax, temp, dx
  161.     svptr    ax, tmpl, dx
  162.  
  163. endnam:    ldptr    si, dst        ; set EOS into DST
  164.     xor    ax, ax
  165.     mov    [si], al
  166.  
  167.     ldptr    si, src        ; now check for extension
  168.     mov    al, [si]
  169.     cmp    al, '.'
  170.     jnz    ext2        ; none in SRC, try TMPL
  171.     callit    strcpy, <<src, ptr>, <dst, ptr>>
  172.     jmp    short alldun
  173.  
  174. ext2:    ldptr    si, tmpl
  175.     mov    al, [si]
  176.     cmp    al, '.'
  177.     jnz    alldun        ; none in TMPL either
  178.     callit    strcpy, <<tmpl, ptr>, <dst, ptr>>
  179.  
  180. alldun:    pret            ; restore regs and return
  181.     pend makefnm
  182.  
  183.     finish
  184.