home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 3 / FREEWARE.BIN / ms_dos / dsort / dstoptn.asm < prev    next >
Assembly Source File  |  1980-01-02  |  27KB  |  1,015 lines

  1.     page    96,132
  2. ;§∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞§
  3. ;§                                                                          §
  4. ;§              ディレクトリエントリ  ソート  ユーティリティ                §
  5. ;§                                                                          §
  6. ;§                                     DSORT.EXE  Ver1.11    §
  7. ;§                                                                          §
  8. ;§                   Copyright (C) by 福地 邦雄 1991. All rights reserved.  §
  9. ;§∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞§
  10.     .MODEL  SMALL,C
  11. ;
  12.     public  options,usageout,dirlist,dirfind,strcopywild
  13.     extrn   sweep:word,sortexec:word,recursive:word,dirgather:word
  14.     extrn   dta:dword,srchname:dword,namebuff:dword,namebuffsiz:word
  15.     extrn   dirtype:word,fattype:word,attribute:word,clustcount:word
  16.     extrn   driveno:word,clustsize:word,fatsize:word,dirsize:word
  17.     extrn   fatbuff:word,dirbuff:word,sortbuff:word,sortcount:word
  18.     extrn   drvinf:byte,clustsect:word,subsearch:word
  19.     extrn   sortfuncs:word,subchain:word,wildcard:byte,pathbuff:byte
  20.     extrn   usagemsg:byte,_msgsize:abs
  21.     extrn   abort:near
  22.     extrn   errorno:word
  23. ;
  24.     PUBLIC  setsortfunc,setsortobj,cmpdummy,cmpdirf,cmpfull,cmpname
  25.     PUBLIC  cmpextn,cmpsize,cmpdate,cmptime,strncmp,chrtypes,pathsep
  26. ;
  27. REVERSE equ 1
  28. NORMAL  equ 0
  29. TAIL    equ 1
  30. HEAD    equ 0
  31. YES     equ 1
  32. NO      equ 0
  33. TAB     equ 9
  34. CR      equ 0dh
  35. LF      equ 0ah
  36. DEFAULT equ 031h
  37. ARCHIVE equ 020h
  38. SUBDIR  equ 010h
  39. VOLUME  equ 008h
  40. HIDDEN  equ 004h
  41. SYSTEM  equ 002h
  42. RDONLY  equ 001h
  43. ;
  44.     .code
  45. ;
  46. ;------------------------------------------------------------------------------
  47. ;
  48. ;   options
  49. ;       オプション指定の評価とディレクトリのリストを取る
  50. ;
  51. ;   TYPE    near call
  52. ;   IN  AX アーギュメント数
  53. ;       SS:BP アーギュメントポインタリストの先頭アドレス
  54. ;   OUT 特になし
  55. ;   保存レジスタ    ds
  56. ;
  57. ;------------------------------------------------------------------------------
  58. ;
  59. options proc
  60. ;
  61.     cld
  62.     push    ax
  63.     mov     ah,2fh                  ; Disk Transfer Address 取得
  64.     int     21h
  65.     lea     bx,[bx+1eh]             ; DTAのファイル名オフセット
  66.     mov     word ptr dta,bx
  67.     mov     word ptr dta+2,es
  68.     pop     bx
  69.     mov     sortfuncs,offset _text:cmpdummy ; ダミーのソート比較関数セット
  70.     mov     word ptr sortfuncs+2,NORMAL
  71.     mov     si,offset sortfuncs+4
  72.     mov     attribute,DEFAULT       ; ソート対象属性のデフォルトセット
  73. ;   @do until
  74. @d0001:
  75.         les     di,[bp]
  76. ;       @cbegin
  77. ;       @case (byte ptr es:[di],=,'-'),S
  78.           cmp   byte ptr es:[di],'-'
  79.           jne   @c0002
  80.             call    setsortfunc
  81. ;       @case (byte ptr es:[di],=,'+'),S
  82.           jmp short @c0001
  83. @c0002:
  84.           cmp   byte ptr es:[di],'+'
  85.           jne   @c0003
  86.             call    setsortobj
  87. ;       @other
  88.           jmp short @c0001
  89. @c0003:
  90.             mov     word ptr srchname,di    ; ディレクトリ名リストの作成
  91.             mov     word ptr srchname+2,es
  92.             call    dirlist
  93. ;       @cend
  94. @c0001:
  95.         add     bp,4                ; 次のアーギュメントへ
  96.         dec     bx
  97. ;   @doend (zf,on)
  98.       jnz   @d0001
  99. ;   @if (si,=,offset sortfuncs+4)
  100.       cmp   si,offset sortfuncs+4
  101.       jne   @i0001
  102.         mov     word ptr [si],offset cmpfull    ; デフォルトの比較関数セット
  103.         mov     word ptr [si+2],NORMAL
  104.         lea     si,[si+4]
  105. ;   @ifend
  106. @i0001:
  107.     not     attribute               ; ソート対象属性を反転させたものを使う
  108.     mov     word ptr [si],0         ; ソート比較関数リストのエンドマーク
  109.     les     di,namebuff             ; ディレクトリ名リストのエンドマーク
  110.     mov     word ptr es:[di],0
  111. ;   @if (word ptr es:[0],=,0)
  112.       cmp   word ptr es:[0],0
  113.       jne   @i0002
  114.         jmp     usageout            ; ディレクトリ無しの時、ヘルプ表示
  115. ;   @ifend
  116. @i0002:
  117.     ret
  118. ;
  119. options endp
  120. ;
  121. ;------------------------------------------------------------------------------
  122. ;
  123. ;   usageout
  124. ;       ヘルプメッセージを表示して終了
  125. ;
  126. ;   TYPE    near call
  127. ;   IN  なし
  128. ;   OUT なし
  129. ;   保存レジスタ    なし
  130. ;
  131. ;------------------------------------------------------------------------------
  132. ;
  133. usageout    proc
  134. ;
  135.     mov     errorno,1
  136.     mov     dx,offset usagemsg
  137.     mov     cx,_msgsize
  138.     jmp     abort
  139. ;
  140. usageout    endp
  141. ;
  142. ;------------------------------------------------------------------------------
  143. ;
  144. ;   setsortfunc
  145. ;       ソート機能指定オプションの評価と、比較関数リストの作成
  146. ;
  147. ;   TYPE    near call
  148. ;   IN      AL アーギュメント文字
  149. ;           DS:SI 比較関数リストアドレス
  150. ;   OUT     SI += 4 
  151. ;   保存レジスタ    bx,cx,dx,di,bp,ds,es
  152. ;
  153. ;------------------------------------------------------------------------------
  154. ;
  155. setsortfunc proc
  156. ;
  157.     inc     di
  158. ;   @do repeat
  159. @d0002:
  160.         mov     al,es:[di]
  161.         inc     di
  162. ;       @if (al,=,0)
  163.           or    al,al
  164.           jne   @i0003
  165. ;           @doexit
  166.               jmp   @d0003
  167. ;       @ifend
  168. @i0003:
  169. ;       @if (al,>=,'a'),S           ; 昇順
  170.           cmp   al,'a'
  171.           jb    @i0004
  172.             mov     word ptr [si+2],NORMAL
  173.             sub     al,'a'-'A'
  174. ;       @else                       ; 降順
  175.           jmp short @i0005
  176. @i0004:
  177.             mov     word ptr [si+2],REVERSE
  178. ;       @ifend
  179. @i0005:
  180. ;       @cbegin
  181. ;       @case (al,=,'D'),S          ; 最終更新日付
  182.           cmp   al,'D'
  183.           jne   @c0005
  184.             mov     ax,offset _text:cmpdate
  185. ;       @case (al,=,'E'),S          ; 拡張子 3バイト
  186.           jmp short @c0004
  187. @c0005:
  188.           cmp   al,'E'
  189.           jne   @c0006
  190.             mov     ax,offset _text:cmpextn
  191. ;       @case (al,=,'F'),S          ; フルネーム 11バイト
  192.           jmp short @c0004
  193. @c0006:
  194.           cmp   al,'F'
  195.           jne   @c0007
  196.             mov     ax,offset _text:cmpfull
  197. ;       @case (al,=,'N'),S          ; ファイル名 8バイト
  198.           jmp short @c0004
  199. @c0007:
  200.           cmp   al,'N'
  201.           jne   @c0008
  202.             mov     ax,offset _text:cmpname
  203. ;       @case (al,=,'S'),S          ; ファイルサイズ
  204.           jmp short @c0004
  205. @c0008:
  206.           cmp   al,'S'
  207.           jne   @c0009
  208.             mov     ax,offset _text:cmpsize
  209. ;       @case (al,=,'T'),S          ; 最終更新時刻
  210.           jmp short @c0004
  211. @c0009:
  212.           cmp   al,'T'
  213.           jne   @c0010
  214.             mov     ax,offset _text:cmptime
  215. ;       @other
  216.           jmp short @c0004
  217. @c0010:
  218.             jmp     usageout
  219. ;       @cend
  220. @c0004:
  221.         mov     [si],ax
  222.         lea     si,[si+4]
  223. ;   @doend
  224.       jmp   @d0002
  225. @d0003:
  226.     ret
  227. ;
  228. setsortfunc endp
  229. ;
  230. ;------------------------------------------------------------------------------
  231. ;
  232. ;   setsortobj
  233. ;       ソート対象選択オプション評価
  234. ;
  235. ;   TYPE    near call
  236. ;   IN  AL アーギュメント文字
  237. ;   OUT なし
  238. ;   保存レジスタ    AX以外
  239. ;
  240. ;------------------------------------------------------------------------------
  241. ;
  242. setsortobj  proc
  243. ;
  244.     inc     di
  245. ;   @do repeat
  246. @d0004:
  247.         mov     al,es:[di]
  248.         inc     di
  249. ;       @if (al,=,0)
  250.           or    al,al
  251.           jne   @i0006
  252. ;           @doexit
  253.               jmp   @d0005
  254. ;       @ifend
  255. @i0006:
  256. ;       @if (al,>=,'a'),S           ; 先頭に
  257.           cmp   al,'a'
  258.           jb    @i0007
  259.             mov     dirgather,HEAD
  260.             sub     al,'a'-'A'
  261. ;       @else                       ; 末尾に
  262.           jmp short @i0008
  263. @i0007:
  264.             mov     dirgather,TAIL
  265. ;       @ifend
  266. @i0008:
  267. ;       @cbegin
  268. ;       @case (al,=,'G'),S          ; ディレクトリの扱い
  269.           cmp   al,'G'
  270.           jne   @c0012
  271.             mov     sortfuncs,offset _text:cmpdirf
  272.             mov     ax,dirgather
  273.             mov     sortfuncs+2,ax
  274. ;       @case (al,=,'T'),S          ; 再帰呼び出し
  275.           jmp short @c0011
  276. @c0012:
  277.           cmp   al,'T'
  278.           jne   @c0013
  279.             mov     recursive,YES
  280. ;       @case (al,=,'N'),S          ; ソート無し
  281.           jmp short @c0011
  282. @c0013:
  283.           cmp   al,'N'
  284.           jne   @c0014
  285.             mov     sortexec,NO
  286. ;       @case (al,=,'F'),S          ; 掃き寄せ無し
  287.           jmp short @c0011
  288. @c0014:
  289.           cmp   al,'F'
  290.           jne   @c0015
  291.             mov     sweep,NO
  292. ;       @case (al,=,'A'),S          ; アーカイブ属性
  293.           jmp short @c0011
  294. @c0015:
  295.           cmp   al,'A'
  296.           jne   @c0016
  297.             xor     attribute,ARCHIVE
  298. ;       @case (al,=,'D'),S          ; ディレクトリ
  299.           jmp short @c0011
  300. @c0016:
  301.           cmp   al,'D'
  302.           jne   @c0017
  303.             xor     attribute,SUBDIR
  304. ;       @case (al,=,'V'),S          ; ボリュームラベル
  305.           jmp short @c0011
  306. @c0017:
  307.           cmp   al,'V'
  308.           jne   @c0018
  309.             xor     attribute,VOLUME
  310. ;       @case (al,=,'S'),S          ; システムファイル
  311.           jmp short @c0011
  312. @c0018:
  313.           cmp   al,'S'
  314.           jne   @c0019
  315.             xor     attribute,SYSTEM
  316. ;       @case (al,=,'H'),S          ; 隠しファイル
  317.           jmp short @c0011
  318. @c0019:
  319.           cmp   al,'H'
  320.           jne   @c0020
  321.             xor     attribute,HIDDEN
  322. ;       @case (al,=,'R'),S          ; 読み出しのみ可能
  323.           jmp short @c0011
  324. @c0020:
  325.           cmp   al,'R'
  326.           jne   @c0021
  327.             xor     attribute,RDONLY
  328. ;       @other
  329.           jmp short @c0011
  330. @c0021:
  331.             jmp     usageout
  332. ;       @cend
  333. @c0011:
  334. ;   @doend
  335.       jmp   @d0004
  336. @d0005:
  337.     ret
  338. ;
  339. setsortobj  endp
  340. ;
  341. ;------------------------------------------------------------------------------
  342. ;
  343. ;   cmpdummy
  344. ;       ダミー比較ルーチン 必ず = で終了
  345. ;
  346. ;   TYPE    near call
  347. ;   IN  なし
  348. ;   OUT AX=0 ZERO FLAG=1
  349. ;   保存レジスタ    AX以外
  350. ;
  351. ;------------------------------------------------------------------------------
  352. ;
  353. cmpdummy    proc
  354. ;
  355.     xor     ax,ax
  356.     ret
  357. ;
  358. cmpdummy    endp
  359. ;
  360. ;------------------------------------------------------------------------------
  361. ;
  362. ;   cmpdirf
  363. ;       ディレクトリ属性比較
  364. ;
  365. ;   TYPE    near call
  366. ;   IN      DS:SI エントリ1アドレス
  367. ;           ES:DI エントリ2アドレス
  368. ;   OUT     AX ディレクトリ:通常= -1  通常:ディレクトリ= 1  その他 0
  369. ;   保存レジスタ    AX以外
  370. ;
  371. ;------------------------------------------------------------------------------
  372. ;
  373. cmpdirf proc
  374. ;
  375.     mov     al,[si+0bh]             ; 属性バイトの取り出し
  376.     mov     ah,[di+0bh]
  377.     and     ax,01010h
  378.     cmp     al,ah
  379.     ja      dirfhead                ; Dir:File
  380.     jb      dirftail                ; File:Dir
  381.     xor     ax,ax                   ; 同じ属性
  382.     ret
  383. dirfhead:
  384.     mov     ax,-1
  385.     ret
  386. dirftail:
  387.     mov     ax,1
  388.     ret
  389. ;
  390. cmpdirf endp
  391. ;
  392. ;------------------------------------------------------------------------------
  393. ;
  394. ;   cmpfull
  395. ;       フルネーム比較
  396. ;
  397. ;   TYPE    near call
  398. ;   IN      DS:SI エントリ1アドレス
  399. ;           ES:DI エントリ2アドレス
  400. ;   OUT     AX エントリ1<エントリ2= -1  エントリ1=エントリ2= 0  エントリ1>エントリ2= 1
  401. ;   保存レジスタ    bx,dx,si,di,bp,ds,es
  402. ;
  403. ;------------------------------------------------------------------------------
  404. ;
  405. cmpfull proc
  406. ;
  407.     mov     cx,11
  408.     call    strncmp
  409.     ret
  410. ;
  411. cmpfull endp
  412. ;
  413. ;------------------------------------------------------------------------------
  414. ;
  415. ;   cmpname
  416. ;       ファイル名比較
  417. ;
  418. ;   TYPE    near call
  419. ;   IN      DS:SI エントリ1アドレス
  420. ;           ES:DI エントリ2アドレス
  421. ;   OUT     AX エントリ1<エントリ2= -1  エントリ1=エントリ2= 0  エントリ1>エントリ2= 1
  422. ;   保存レジスタ    bx,dx,si,di,bp,ds,es
  423. ;
  424. ;------------------------------------------------------------------------------
  425. ;
  426. cmpname proc
  427. ;
  428.     mov     cx,8
  429.     call    strncmp
  430.     ret
  431. ;
  432. cmpname endp
  433. ;
  434. ;------------------------------------------------------------------------------
  435. ;
  436. ;   cmpextn
  437. ;       拡張子比較
  438. ;
  439. ;   TYPE    near call
  440. ;   IN      DS:SI エントリ1アドレス
  441. ;           ES:DI エントリ2アドレス
  442. ;   OUT     AX エントリ1<エントリ2= -1  エントリ1=エントリ2= 0  エントリ1>エントリ2= 1
  443. ;   保存レジスタ    bx,dx,si,di,bp,ds,es
  444. ;
  445. ;------------------------------------------------------------------------------
  446. ;
  447. cmpextn proc    uses bx si di
  448. ;
  449.     lea     si,[si+8]               ; 拡張子位置
  450.     lea     di,[di+8]
  451.     mov     cx,3
  452.     call    strncmp
  453.     ret
  454. ;
  455. cmpextn endp
  456. ;
  457. ;------------------------------------------------------------------------------
  458. ;
  459. ;   cmpsize
  460. ;       ファイルサイズ比較
  461. ;
  462. ;   TYPE    near call
  463. ;   IN  DS:SI エントリ1アドレス
  464. ;       ES:DI エントリ2アドレス
  465. ;   OUT AX エントリ1<エントリ2= -1  エントリ1=エントリ2= 0  エントリ1>エントリ2= 1
  466. ;   保存レジスタ    bx,dx,si,di,bp,ds,es
  467. ;
  468. ;------------------------------------------------------------------------------
  469. ;
  470. cmpsize proc
  471. ;
  472.     mov     ax,[si+1ch]             ; エントリ1のファイルサイズ4バイト
  473.     mov     cx,[si+1eh]
  474.     cmp     cx,[di+1eh]             ; エントリ2と比較
  475.     ja      sizeabove
  476.     jb      sizebelow
  477.     cmp     ax,[di+1ch]
  478.     ja      sizeabove
  479.     jb      sizebelow
  480.     xor     ax,ax
  481.     ret
  482. sizeabove:
  483.     mov     ax,1
  484.     ret
  485. sizebelow:
  486.     mov     ax,-1
  487.     ret
  488. ;
  489. cmpsize endp
  490. ;
  491. ;------------------------------------------------------------------------------
  492. ;
  493. ;   cmpdate
  494. ;       最終更新日付比較
  495. ;
  496. ;   TYPE    near call
  497. ;   IN  DS:SI エントリ1アドレス
  498. ;       ES:DI エントリ2アドレス
  499. ;   OUT AX エントリ1<エントリ2= -1  エントリ1=エントリ2= 0  エントリ1>エントリ2= 1
  500. ;   保存レジスタ    bx,dx,si,di,bp,ds,es
  501. ;
  502. ;------------------------------------------------------------------------------
  503. ;
  504. cmpdate proc
  505. ;
  506.     mov     ax,[si+18h]
  507.     cmp     ax,[di+18h]
  508.     ja      dateabove
  509.     jb      datebelow
  510.     xor     ax,ax
  511.     ret
  512. dateabove:
  513.     mov     ax,1
  514.     ret
  515. datebelow:
  516.     mov     ax,-1
  517.     ret
  518. ;
  519. cmpdate endp
  520. ;
  521. ;------------------------------------------------------------------------------
  522. ;
  523. ;   cmptime
  524. ;       最終更新時刻比較
  525. ;
  526. ;   TYPE    near call
  527. ;   IN  DS:SI エントリ1アドレス
  528. ;       ES:DI エントリ2アドレス
  529. ;   OUT AX エントリ1<エントリ2= -1  エントリ1=エントリ2= 0  エントリ1>エントリ2= 1
  530. ;   保存レジスタ    bx,dx,si,di,bp,ds,es
  531. ;
  532. ;------------------------------------------------------------------------------
  533. ;
  534. cmptime proc
  535. ;
  536.     mov     ax,[si+16h]
  537.     cmp     ax,[di+16h]
  538.     ja      timeabove
  539.     jb      timebelow
  540.     xor     ax,ax
  541.     ret
  542. timeabove:
  543.     mov     ax,1
  544.     ret
  545. timebelow:
  546.     mov     ax,-1
  547.     ret
  548. ;
  549. cmptime endp
  550. ;
  551. ;------------------------------------------------------------------------------
  552. ;
  553. ;   strncmp
  554. ;       文字列比較 漢字対応 漢字はANKより大きい
  555. ;
  556. ;   TYPE    near call
  557. ;   IN  CX 比較サイズ
  558. ;       DS:SI エントリ1アドレス
  559. ;       ES:DI エントリ2アドレス
  560. ;   OUT AX エントリ1<エントリ2= -1  エントリ1=エントリ2= 0  エントリ1>エントリ2= 1
  561. ;   保存レジスタ    bx,dx,si,di,bp,ds,es
  562. ;
  563. ;------------------------------------------------------------------------------
  564. ;
  565. strncmp proc    uses bx si di
  566. ;
  567.     cld
  568. ;   @do until
  569. @d0006:
  570.         dec     cx
  571.         mov     ax,[si]             ; エントリ1 1文字取得
  572.         inc     si
  573.         call    chrtypes
  574. ;       @if (zf,off)
  575.           jz    @i0009
  576.             dec     cx
  577.             inc     si
  578. ;       @ifend
  579. @i0009:
  580. ;
  581.         mov     bx,ax
  582.         mov     ax,[di]             ; エントリ2 1文字取得
  583.         inc     di
  584.         call    chrtypes
  585. ;       @if (zf,off)
  586.           jz    @i0010
  587.             inc     di
  588. ;       @ifend
  589. @i0010:
  590.         cmp     bx,ax               ; 比較
  591.         ja      strabove
  592.         jb      strbelow
  593.         or      cx,cx
  594. ;   @doend (zf,on),or,(sf,on)
  595.       jz    @d0007
  596.       js    @d0007
  597.       jmp   @d0006
  598. @d0007:
  599. ;
  600.     xor     ax,ax
  601. streturn:
  602.     ret
  603. ;
  604. strabove:
  605.     mov     ax,1
  606.     jmp     streturn
  607. strbelow:
  608.     mov     ax,-1
  609.     jmp     streturn
  610. ;
  611. strncmp endp
  612. ;
  613. ;------------------------------------------------------------------------------
  614. ;
  615. ;   chrtypes
  616. ;       漢字判定
  617. ;
  618. ;   TYPE    near call
  619. ;   IN  AX 文字コード AL=第一バイト
  620. ;   OUT AX 判定後コード ANK:AH=0
  621. ;       ZERO FLAG AHのTEST結果
  622. ;   保存レジスタ    AX以外
  623. ;
  624. ;------------------------------------------------------------------------------
  625. ;
  626. chrtypes    proc
  627. ;
  628.     cmp     al,081h
  629.     jb      chrank
  630.     cmp     al,0a0h
  631.     jb      chrsjis
  632.     cmp     al,0e0h
  633.     jb      chrank
  634.     cmp     al,0fch
  635.     jbe     chrsjis
  636. chrank:
  637.     xor     ah,ah
  638.     ret
  639. chrsjis:
  640.     xchg    ah,al
  641.     test    ah,ah
  642.     ret
  643. ;
  644. chrtypes    endp
  645. ;
  646. ;------------------------------------------------------------------------------
  647. ;
  648. ;   dirlist
  649. ;       全てのディレクトリ名を検索して、そのパス名をバッファに格納する
  650. ;       ワイルドカード対応  FUNCTION    4EH,4FH
  651. ;
  652. ;   TYPE    near call
  653. ;   IN  検索情報構造体
  654. ;   OUT ディレクションフラグ アップ方向
  655. ;   保存レジスタ    bp,ds
  656. ;
  657. ;------------------------------------------------------------------------------
  658. ;
  659. dirlist    proc uses bx si
  660.         local copysiz,fnamsiz,saveds
  661. ;
  662.     mov     saveds,ds               ;DS セーブ
  663.     les     di,srchname             ;パス名の長さと、最終位置を獲得
  664.     mov     cx,0ffffh
  665.     cld
  666.     xor     al,al
  667.   repne scasb
  668.     not     cx
  669.     dec     cx
  670.     mov     fnamsiz,cx
  671.     mov     di,word ptr srchname
  672.     call    pathsep                 ; パス名中の最後の'\'位置を獲得
  673.     mov     copysiz,cx              ; バッファへの共通コピーサイズをセット
  674.     mov     di,word ptr srchname
  675.     mov     dx,es:[di]
  676. ;   @cbegin
  677. ;   @case (zf,on)                   ; セパレータなし
  678.       jnz   @c0023
  679. ;       @if (dx,=,'.'),or,(dx,=,'..')   ; カレント/親?
  680.           cmp   dx,'.'
  681.           je    @i0011
  682.           cmp   dx,'..'
  683.           jne   @i0012
  684. @i0011:
  685.             jmp parentdir
  686. ;       @ifend
  687. @i0012:
  688. ;   @case (fnamsiz,=,1),and,(dl,=,'\'),S ; ルート指定か?
  689.       jmp   @c0022
  690. @c0023:
  691.       cmp   fnamsiz,1
  692.       jne   @c0024
  693.       cmp   dl,'\'
  694.       jne   @c0024
  695.         mov     ah,19h              ; カレントドライブ取得
  696.         int     21h
  697.         add     al,'A'              ; ドライブ名作成
  698.         mov     ah,':'
  699.         jmp     rootpath
  700. ;   @case (cx,=,2),S                ; カレント/親 指定か?
  701.       jmp short @c0022
  702. @c0024:
  703.       cmp   cx,2
  704.       jne   @c0025
  705. ;       @if (dh,=,':')
  706.           cmp   dh,':'
  707.           jne   @i0013
  708. ;           @if (fnamsiz,=,2)
  709.               cmp   fnamsiz,2
  710.               jne   @i0014
  711.                 sub     namebuffsiz,4   ; ディレクトリ名バッファサイズチェック
  712. ;               @if (cf,on)
  713.                   jnc   @i0015
  714.                     add     namebuffsiz,4
  715.                     jmp     srchout
  716. ;               @ifend
  717. @i0015:
  718.                 cld
  719.                 les     di,namebuff
  720.                 mov     ax,dx           ; ドライブ名
  721.                 stosw
  722.                 mov     ax,'.'          ; カレントディレクトリ指定
  723.                 stosw
  724.                 mov     word ptr namebuff,di    ; 新オフセット設定
  725.                 jmp     srchout
  726. ;           @ifend
  727. @i0014:
  728. ;           @if (fnamsiz,<=,4)
  729.               cmp   fnamsiz,4
  730.               ja    @i0016
  731.                 mov ax,es:[di+2]
  732. ;               @if (ax,=,'.'),or,(ax,=,'..')
  733.                   cmp   ax,'.'
  734.                   je    @i0017
  735.                   cmp   ax,'..'
  736.                   jne   @i0018
  737. @i0017:
  738.                     jmp parentdir
  739. ;               @ifend
  740. @i0018:
  741. ;           @ifend
  742. @i0016:
  743. ;       @ifend
  744. @i0013:
  745. ;   @case (fnamsiz,=,3),and,(word ptr es:[di+1],=,'\:'),S ; ルート指定か?
  746.       jmp short @c0022
  747. @c0025:
  748.       cmp   fnamsiz,3
  749.       jne   @c0026
  750.       cmp   word ptr es:[di+1],'\:'
  751.       jne   @c0026
  752.         mov     ax,dx
  753. rootpath:
  754.         sub     namebuffsiz,3       ; バッファ残りサイズ確認
  755. ;       @if (cf,on)
  756.           jnc   @i0019
  757.             add     namebuffsiz,3
  758.             jmp     srchout
  759. ;       @ifend
  760. @i0019:
  761.         cld
  762.         les     di,namebuff         ; ドライブ名のみセット
  763.         stosw
  764.         xor     al,al
  765.         stosb
  766.         mov     word ptr namebuff,di
  767.         jmp     srchout
  768. ;   @cend
  769. @c0022:
  770. @c0026:
  771. ;
  772.     mov     ah,4eh                  ;最初のファイル名検索ファンクション
  773.     mov     cx,037h                 ;ボリュームラベル以外すべて
  774.     lds     dx,srchname
  775.     int     21h
  776. ;   @do while,(cf,off)
  777. @d0008:
  778.       jc    @d0009
  779.         mov     ds,saveds           ; DS 復元
  780.         les     di,dta
  781. ;       @if (byte ptr es:[di-9],on,10h) ;ディレクトリかどうかのチェック
  782.           test  byte ptr es:[di-9],10h
  783.           jz    @i0020
  784.             mov     dx,es:[di]      ; 再帰処理のさいに '.' '..' を外す
  785. ;           @if (subsearch,=,YES)
  786.               cmp   subsearch,YES
  787.               jne   @i0021
  788. ;               @if (dx,=,'.'),or,(dx,=,'..')
  789.                   cmp   dx,'.'
  790.                   je    @i0022
  791.                   cmp   dx,'..'
  792.                   jne   @i0023
  793. @i0022:
  794.                     jmp     skipperiod
  795. ;               @ifend
  796. @i0023:
  797. ;           @ifend
  798. @i0021:
  799.             mov     cx,13           ;DTA上のファイル名から、長さを獲得
  800.             xor     al,al
  801.             cld
  802.           repne scasb
  803.             sub     cx,13
  804.             neg     cx
  805.             mov     fnamsiz,cx      ;ファイル名長さをセーブ
  806.             add     cx,copysiz      ;残りバッファサイズのチェックと更新
  807.             sub     namebuffsiz,cx
  808. ;           @if (cf,on)
  809.               jnc   @i0024
  810.                 add     namebuffsiz,cx  ;不足
  811.                 jmp     short   srchout
  812. ;           @ifend
  813. @i0024:
  814.             les     di,namebuff     ;共通パス名のコピー
  815.             lds     si,srchname
  816.             mov     cx,copysiz
  817.           rep   movsb
  818.             mov     ds,saveds       ;ファイル名のコピー
  819.             lds     si,dta
  820.             mov     cx,fnamsiz
  821.             rep     movsb
  822.             mov     ds,saveds
  823.             mov     word ptr namebuff,di    ;新オフセットの設定
  824. ;       @ifend
  825. @i0020:
  826. skipperiod:
  827.         mov     ah,4fh              ;次のファイル名検索ファンクション
  828.         lds     dx,srchname
  829.         mov     cx,037h
  830.         int     21h                 ;見つかればパス名セーブ
  831. ;   @doend
  832.       jmp   @d0008
  833. @d0009:
  834.     mov ds,saveds
  835. srchout:
  836.     ret
  837. ;
  838. parentdir:
  839.     cld                             ; パス名長さを調べる
  840.     les     di,srchname
  841.     xor     ax,ax
  842.     mov     cx,-1
  843.   repne scasb
  844.     not     cx
  845.     sub     namebuffsiz,cx
  846. ;   @if (cf,on)
  847.       jnc   @i0025
  848.         add     namebuffsiz,cx      ;不足
  849.         jmp     short   srchout
  850. ;   @ifend
  851. @i0025:
  852.     les     di,namebuff             ;ファイル名のコピー
  853.     lds     si,srchname
  854.   rep movsb
  855.     mov     ds,saveds               ; DS 復元
  856.     mov     word ptr namebuff,di    ;新オフセットの設定
  857.     jmp     short   srchout
  858. ;
  859. dirlist    endp
  860. ;
  861. ;------------------------------------------------------------------------------
  862. ;
  863. ;   pathsep
  864. ;       パス名を調べて一番最後の':'か'\'までのバイト数を通知する
  865. ;
  866. ;   TYPE    near call
  867. ;   IN  CX      パス名長さ
  868. ;       ES:DI   パス名の先頭アドレス
  869. ;   OUT CX & ZERO FLAG 最後の':'or'\'までのバイト数 及び 0か?
  870. ;       DIR FLAG アップ方向
  871. ;   保存レジスタ    bx,si,bp,ds,es
  872. ;
  873. ;------------------------------------------------------------------------------
  874. ;
  875. pathsep     proc
  876. ;
  877. ;   @if (cx,/=,0)                   ; 0 でない時
  878.       or    cx,cx
  879.       je    @i0026
  880.         push    cx                  ; 長さをセーブ
  881.         xor     dx,dx               ; 位置を初期化
  882. ;       @do until
  883. @d0010:
  884.             mov     al,es:[di]      ; 文字獲得
  885.             inc     di
  886. ;           @cbegin
  887. ;           @case (al,=,':'),or,(al,=,'\'),S ; セパレータならば位置を記憶
  888.               cmp   al,':'
  889.               je    @c0028
  890.               cmp   al,'\'
  891.               jne   @c0029
  892. @c0028:
  893.                 mov     dx,cx
  894. ;           @case (al,<,81h),or,(al,>,0fch),S ; α/N なにもしない
  895.               jmp short @c0027
  896. @c0029:
  897.               cmp   al,81h
  898.               jb    @c0030
  899.               cmp   al,0fch
  900.               jbe   @c0031
  901. @c0030:
  902. ;           @case (al,>=,0a0h),and,(al,<=,0dfh),S ; カナ なにもしない
  903.               jmp short @c0027
  904. @c0031:
  905.               cmp   al,0a0h
  906.               jb    @c0032
  907.               cmp   al,0dfh
  908.               ja    @c0032
  909. ;           @other                  ; 漢字 第二バイト分を進める
  910.               jmp short @c0027
  911. @c0032:
  912.                 inc     di
  913.                 dec     cx          ; 残り0なら終了
  914.                 jz      analysend
  915. ;           @cend
  916. @c0027:
  917.             dec     cx              ; 残り0なら終了
  918. ;       @doend (zf,on)
  919.           jnz   @d0010
  920. analysend:
  921.         pop     cx                  ; パス名長を復元
  922. ;       @if (dx,/=,0),S             ; セパレータが有った時
  923.           or    dx,dx
  924.           je    @i0027
  925.             dec     dx              ; DX にはパス名最後からのオフセット
  926.             sub     cx,dx           ; 先頭からのオフセットに直す
  927. ;       @else
  928.           jmp short @i0028
  929. @i0027:
  930.             xor     cx,cx           ; セパレータが無い時は0
  931. ;       @ifend
  932. @i0028:
  933. ;   @ifend
  934. @i0026:
  935.     ret
  936. ;
  937. pathsep     endp
  938. ;
  939. ;------------------------------------------------------------------------------
  940. ;
  941. ;   dirfind
  942. ;       パス名をもとにディレクトリかを調べ、ディレクトリの開始クラスタ
  943. ;       と、存在するドライブ番号を通知する
  944. ;
  945. ;   TYPE    near call
  946. ;   IN  ES:DI パス名の先頭アドレス
  947. ;   OUT AX ディレクトリの開始クラスタ番号
  948. ;       DL ドライブ番号
  949. ;       CARRY FLAG ディレクトリ属性 0:DIR 1:OTHERまたはルートでファイル無し
  950. ;   保存レジスタ    bp,ds
  951. ;
  952. ;------------------------------------------------------------------------------
  953. ;
  954. dirfind     proc
  955. ;
  956.     call    strcopywild             ; 検索用パス名の作成
  957. ;
  958.     mov     ah,2fh                  ; DTA 取得
  959.     int     21h
  960. ;
  961.     mov     ah,4eh                  ; ファイル検索
  962.     mov     cx,3fh
  963.     int     21h
  964. ;   @if (cf,off)                    ; 見つかった
  965.       jc    @i0029
  966.         mov     ax,es:[bx+0fh]      ; ディレクトリの開始クラスタ取得
  967.         xor     dx,dx
  968.         mov     dl,es:[bx]          ; ディレクトリのドライブ番号取得
  969. ;   @ifend
  970. @i0029:
  971.     ret
  972. ;
  973. dirfind     endp
  974. ;
  975. ;------------------------------------------------------------------------------
  976. ;
  977. ;   strcopywild
  978. ;       指定されたパス名をPATHBUFFにコピーし、ワイルドカードを付加する
  979. ;
  980. ;   TYPE    near call
  981. ;   IN  ES:DI パス名の先頭アドレス
  982. ;   OUT PATHBUFF
  983. ;       ES:DI PATHBUFFのアドレス
  984. ;   保存レジスタ    bp,ds
  985. ;
  986. ;------------------------------------------------------------------------------
  987. ;
  988. strcopywild proc
  989. ;
  990.     cld                             ; パス名長さを調べる
  991.     mov     cx,-1
  992.     xor     ax,ax
  993.     mov     si,di
  994.   repne     scasb
  995.     not     cx
  996.     dec     cx
  997.     mov     ax,ds                   ; パス名をPATHBUFFにコピー
  998.     mov     dx,es
  999.     mov     ds,dx
  1000.     mov     es,ax
  1001.     mov     di,offset pathbuff
  1002.     mov     dx,di
  1003.     rep     movsb
  1004.     mov     ds,ax                   ; ワイルドカード指定を付加
  1005.     mov     cx,5
  1006.     mov     si,offset wildcard
  1007.     rep     movsb
  1008. ;
  1009.     mov     di,offset pathbuff
  1010.     ret
  1011. ;
  1012. strcopywild endp
  1013. ;
  1014.     end
  1015.