-
Notifications
You must be signed in to change notification settings - Fork 1
/
ls.s
3112 lines (2727 loc) · 59.5 KB
/
ls.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
* ls - list directories and files
*
* Itagaki Fumihiko 03-Dec-92 Create.
* 1.0
* Itagaki Fumihiko 06-Dec-92 Debug and brush up.
* 1.1
* Itagaki Fumihiko 08-Dec-92 ボリューム・ラベルのブロック数も正しく計数
* Itagaki Fumihiko 16-Dec-92 / の最終更新時刻を 0-0-0 から 0-1-1 に変更
* Itagaki Fumihiko 23-Dec-92 -V オプションの追加
* Itagaki Fumihiko 10-Jan-93 GETPDB -> lea $10(a0),a0
* Itagaki Fumihiko 20-Jan-93 引数 - と -- の扱いの変更
* Itagaki Fumihiko 22-Jan-93 スタックを拡張
* 1.2
* Itagaki Fumihiko 04-Feb-93 LNDRV_realpathcpy->LNDRV_O_FILES を LNDRV_LINK_FILES に変更
* Itagaki Fumihiko 06-Feb-93 JOINされたドライブ内のサブディレクトリにも-Vが効くよう修正
* Itagaki Fumihiko 06-Feb-93 相対パスで設定されたシンボリック・リンクも正しく処理
* Itagaki Fumihiko 06-Feb-93 ループしたシンボリック・リンクも正しく処理
* Itagaki Fumihiko 07-Feb-93 引数の末尾に / が付いていれば,それがディレクトリへのシンボ
* リック・リンクであるときに,-l オプションや -v オプションが
* 指定されていてもディレクトリ引数として処理する
* 1.3
* Itagaki Fumihiko 03-Jan-94 lndrvが組み込まれていると,ls -ds . で . のブロックサイズが
* 0 と表示されてしまう不具合を修正
* Itagaki Fumihiko 03-Jan-94 -w <幅> は -w<幅> と書いても良い
* Itagaki Fumihiko 03-Jan-94 -V の処理の修正
* Itagaki Fumihiko 03-Jan-94 -V の処理の高速化
* Itagaki Fumihiko 04-Jan-94 引数に含まれるドライブ名を大文字に変換するのをやめた
* Itagaki Fumihiko 04-Jan-94 引数に含まれる‘\’を‘/’に変換するのをやめた
* Itagaki Fumihiko 04-Jan-94 TwentyOne +R に対応
* Itagaki Fumihiko 04-Feb-94 ソートの比較が符号付きになっていたのを符号無しに修正
* 1.4
* Itagaki Fumihiko 23-Dec-94 存在しないドライブはエラーになるようにした
* Itagaki Fumihiko 23-Dec-94 v1.3 で追加した『引数の末尾に / が付いていれば,それがディ
* レクトリへのシンボリック・リンクであるときに,-l オプション
* や -v オプションが指定されていてもディレクトリ引数として処
* 理する』機能が,-p オプションか -F オプションが指定されてい
* ないと効かない不具合を修正
* Itagaki Fumihiko 23-Dec-94 -P オプションを追加
* Itagaki Fumihiko 23-Dec-94 -E オプションを追加
* 1.5
*
* Usage: ls [ -1ABCDEFGLPQRSUVXabdeflmpqrstvx ] [ -w cols ] [ -- ] [ file ] ...
*
* オプションを追加するときは注意が必要,
* あちらこちらでフラグをチェックして、無駄な処理を省いている.
*
* 動いているものは覚悟していじるべし.
.include doscall.h
.include error.h
.include limits.h
.include stat.h
.include chrcode.h
.xref DecodeHUPAIR
.xref getlnenv
.xref issjis
.xref atou
.xref utoa
.xref utoao
.xref strlen
.xref strcmp
.xref stricmp
.xref strcpy
.xref stpcpy
.xref strchr
.xref strbot
.xref strfor1
.xref memmovi
.xref memset
.xref mulul
.xref divul
.xref contains_dos_wildcard
.xref strip_excessive_slashes
.xref find_slashes
.xref skip_root
.xref headtail
.xref suffix
.xref getenv
.xref printfi
REQUIRED_OSVER equ $200 * 2.00以降
BLOCKSIZE equ 1024
OLDEST_DATIME equ ((1<<5)|1)<<16
MAXRECURSE equ 64 * サブディレクトリを検索するために再帰する回数の上限.
* MAXDIR (パス名のディレクトリ部 "/1/2/3/../" の長さ)
* が 64 であるから、31で充分であるが,
* シンボリック・リンクを考慮して 64 とする.
* スタック量にかかわる.
DEFAULT_COLUMNS equ 80
LINEBUFSIZE equ 1024
FILELIST_UNIT equ 32 * 2のべき乗でなければならない
FATCHK_STATIC equ 256 * 静的バッファでfatchkできるようにしておくFATチェイン数
********************************
* ENTRY構造体
********************************
.offset 0
entry_name: ds.b MAXPATH+1
entry_flag: ds.b 1
entry_mode: ds.b 1
.even
entry_linkmode: ds.w 1
entry_drive: ds.w 1
entry_datime:
entry_date: ds.w 1
entry_time: ds.w 1
entry_size: ds.l 1
entry_nblocks: ds.l 1
entry_linkpath: ds.l 1
.even
entry_struct_size:
* entry_flag のビットの定義
FLAGBIT_SUBDIR equ 0
FLAGBIT_NOSTAT equ 1
FLAGBIT_IGNORE equ 2
FLAGBIT_ALLOC equ 3
LNDRV_O_CREATE equ 4*2
LNDRV_O_OPEN equ 4*3
LNDRV_O_DELETE equ 4*4
LNDRV_O_MKDIR equ 4*5
LNDRV_O_RMDIR equ 4*6
LNDRV_O_CHDIR equ 4*7
LNDRV_O_CHMOD equ 4*8
LNDRV_O_FILES equ 4*9
LNDRV_O_RENAME equ 4*10
LNDRV_O_NEWFILE equ 4*11
LNDRV_O_FATCHK equ 4*12
LNDRV_realpathcpy equ 4*16
LNDRV_LINK_FILES equ 4*17
LNDRV_OLD_LINK_FILES equ 4*18
LNDRV_link_nest_max equ 4*19
LNDRV_getrealpath equ 4*20
****************************************************************
.text
start:
bra.s start1
dc.b '#HUPAIR',0
start1:
lea stack_bottom,a7 * A7 := スタックの底
DOS _VERNUM
cmp.w #REQUIRED_OSVER,d0
bcs dos_version_mismatch
lea $10(a0),a0 * A0 : PDBアドレス
move.l a7,d0
sub.l a0,d0
move.l d0,-(a7)
move.l a0,-(a7)
DOS _SETBLOCK
addq.l #8,a7
*
* 時刻ではなく年を表示する範囲を決定する.
*
DOS _GETDATE
move.w d0,present_date
moveq #0,d1
move.w d0,d1
and.w #$fe00,d1 * 年
move.w d0,d2
and.w #$01ff,d2 * 月日
and.w #$01e0,d0 * 月
cmp.w #$00e0,d0 * 7月
blo six_month_ago_1
sub.w #$00c0,d2 * 月日-6月
add.l #$0200,d1 * +1年(ゲタ)
bra six_month_ago_ok
six_month_ago_1:
add.w #$00c0,d2 * 月日+6月
* ここで1年引かなければならないので
* +1年のゲタは相殺
six_month_ago_ok:
or.w d2,d1 * 年+1年-6月
move.l d1,cutoff_date
*
* 端末の幅を得る
*
lea word_COLUMNS(pc),a0
bsr getenv
beq columns_default
movea.l d0,a0
bsr atou
bne columns_default
move.l d1,d0
bne columns_ok
moveq #1,d0
bra columns_ok
columns_default:
move.l #DEFAULT_COLUMNS,d0
columns_ok:
move.l d0,columns
*
* 出力書式を決める
*
moveq #0,d1 * -1
moveq #1,d0 * 出力は
bsr is_chrdev * ブロック・デバイスか?
sne output_is_chrdev
beq set_default_format * -- ブロック・デバイスである
moveq #1,d1 * -C
set_default_format:
move.b d1,format
lea cmp_name(pc),a0
move.l a0,cmp_func
*
* lndrv常駐チェック
*
bsr getlnenv
move.l d0,lndrv
*
* 引数並び格納エリアを確保する
*
lea 1(a2),a0 * A0 := コマンドラインの文字列の先頭アドレス
bsr strlen * D0.L := コマンドラインの文字列の長さ
addq.l #1,d0
bsr malloc
bmi insufficient_memory
movea.l d0,a1 * A1 := 引数並び格納エリアの先頭アドレス
*
* 引数をデコードし,解釈する
*
bsr DecodeHUPAIR * 引数をデコードする
movea.l a1,a0 * A0 : 引数ポインタ
move.l d0,d7 * D7.L : 引数カウンタ
decode_opt_loop1:
tst.l d7
beq decode_opt_done
cmpi.b #'-',(a0)
bne decode_opt_done
tst.b 1(a0)
beq decode_opt_done
subq.l #1,d7
addq.l #1,a0
move.b (a0)+,d0
cmp.b #'-',d0
bne decode_opt_loop2
tst.b (a0)+
beq decode_opt_done
subq.l #1,a0
decode_opt_loop2:
cmp.b #'f',d0
beq opt_f
cmp.b #'e',d0
beq opt_e
cmp.b #'s',d0
beq opt_s
cmp.b #'V',d0
beq opt_V
cmp.b #'R',d0
beq opt_R
cmp.b #'L',d0
beq opt_L
cmp.b #'d',d0
beq opt_d
cmp.b #'Q',d0
beq opt_Q
cmp.b #'D',d0
beq opt_D
cmp.b #'r',d0
beq opt_r
cmp.b #'G',d0
beq opt_G
cmp.b #'v',d0
beq opt_v
cmp.b #'l',d0
beq opt_l
cmp.b #'B',d0
beq opt_B
cmp.b #'a',d0
beq opt_a
cmp.b #'A',d0
beq opt_A
cmp.b #'p',d0
beq opt_p
cmp.b #'P',d0
beq opt_P
cmp.b #'F',d0
beq opt_F
cmp.b #'E',d0
beq opt_E
moveq #1,d1
cmp.b #'q',d0
beq set_escape
moveq #2,d1
cmp.b #'b',d0
beq set_escape
moveq #0,d1
cmp.b #'1',d0
beq set_format
moveq #1,d1
cmp.b #'C',d0
beq set_format
moveq #2,d1
cmp.b #'x',d0
beq set_format
moveq #3,d1
cmp.b #'m',d0
beq set_format
clr.l a1
cmp.b #'U',d0
beq set_cmp_func
lea cmp_extention(pc),a1
cmp.b #'X',d0
beq set_cmp_func
lea cmp_time(pc),a1
cmp.b #'t',d0
beq set_cmp_func
lea cmp_size(pc),a1
cmp.b #'S',d0
beq set_cmp_func
cmp.b #'w',d0
beq parse_width
moveq #1,d1
tst.b (a0)
beq bad_option_1
bsr issjis
bne bad_option_1
moveq #2,d1
bad_option_1:
move.l d1,-(a7)
pea -1(a0)
move.w #2,-(a7)
lea msg_illegal_option(pc),a0
bsr werror_myname_and_msg
DOS _WRITE
lea 10(a7),a7
bra usage
parse_width:
tst.b (a0)
bne parse_width_1
subq.l #1,d7
bcs too_few_args
addq.l #1,a0
parse_width_1:
bsr atou
bne bad_width
tst.b (a0)+
bne bad_width
tst.l d1
beq bad_width
move.l d1,columns
bra decode_opt_loop1
set_escape:
move.b d1,escape
bra set_option_done
set_format:
move.b d1,format
bra set_option_done
set_cmp_func:
move.l a1,cmp_func
bra set_option_done
opt_f:
st fast
bra set_option_done
opt_e:
st exploration
bra set_option_done
opt_v:
st long_datime
bra set_long_format
opt_l:
sf long_datime
set_long_format:
st long_format
bra set_option_done
opt_Q:
st quote
bra set_option_done
opt_R:
st recurse
bra set_option_done
opt_L:
st replace_link
bra set_option_done
opt_a:
st show_all
opt_A:
st show_almost_all
bra set_option_done
opt_B:
st not_show_backfiles
bra set_option_done
opt_d:
st directory
bra set_option_done
opt_F:
st mark_exes
bra opt_p
opt_P:
st mark_links
opt_p:
st mark_dirs
bra set_option_done
opt_E:
st color
bra set_option_done
opt_D:
st case_insensitive
bra set_option_done
opt_r:
st reverse
bra set_option_done
opt_G:
st gather
bra set_option_done
opt_s:
st print_nblocks
bra set_option_done
opt_V:
st virtual_dir_size
set_option_done:
move.b (a0)+,d0
bne decode_opt_loop2
bra decode_opt_loop1
decode_opt_done:
movea.l a0,a1
*
* -fオプションの処理
*
tst.b fast
beq fast_flag_ok
clr.l cmp_func
st show_all
st exploration
sf not_show_backfiles
sf recurse
sf directory
sf replace_link
sf print_nblocks
sf mark_dirs
sf color
sf long_format
fast_flag_ok:
*
* ブロック・サイズを得る必要があるかどうか調べる
*
move.b print_nblocks,d0
or.b long_format,d0
sne needs_nblocks
*
* ‘.’と‘..’の stat を得る必要があるかどうか調べる
*
st needs_dots_stat
cmpi.l #cmp_time,cmp_func
beq needs_dots_stat_ok
cmpi.l #cmp_size,cmp_func
beq needs_dots_stat_ok
tst.b needs_nblocks
sne needs_dots_stat
needs_dots_stat_ok:
*
* -lオプションの処理
*
tst.b long_format
beq long_format_ok
sf mark_links
long_format_ok:
*
* -Eオプションの処理
*
tst.b color
beq color_ok
tst.b output_is_chrdev
beq unset_color
lea word_LSCOLORS(pc),a0
bsr getenv
beq color_ok
movea.l d0,a0
bsr strlen
addq.l #1,d0
bsr malloc
bmi insufficient_memory
move.l a1,-(a7)
movea.l a0,a1
movea.l d0,a0
bsr strcpy
lea colors(pc),a1
moveq #3,d1
set_color_loop:
move.l a0,(a1)+
moveq #':',d0
bsr strchr
beq set_color_continue
clr.b (a0)+
set_color_continue:
dbra d1,set_color_loop
movea.l (a7)+,a1
bra color_ok
unset_color:
sf color
color_ok:
*
* -L の効果をチェックする
*
move.b needs_dots_stat,d0
or.b mark_dirs,d0
or.b color,d0
or.b recurse,d0
bne replace_link_ok
sf replace_link * -L に効果は無い。退ける。
replace_link_ok:
*
* -V の効果をチェックする
*
tst.b long_format
bne virtual_dir_size_ok
cmpi.l #cmp_size,cmp_func
beq virtual_dir_size_ok
sf virtual_dir_size
virtual_dir_size_ok:
*
* ファイル引数を検査する
*
lea _linebuf(pc),a0
move.l a0,_bufp
move.l #LINEBUFSIZE,_buf_remain
tst.l d7
bne args_ok
lea default_arg(pc),a1
moveq #1,d7
args_ok:
*
* 引数をstatするループ
*
clr.w exitcode
clr.l entry_top
clr.l number_of_entry
clr.l number_of_subdir
st have_to_headtail
ls_args_loop:
movea.l a1,a0
bsr strfor1
exg a0,a1
bsr doname
subq.l #1,d7
bne ls_args_loop
*
* 出力
*
move.l number_of_entry,d0
beq exit_program_with_exitcode
movea.l entry_top,a0
bsr sort
sort_args_done:
tst.b directory
beq split_directory
*
* -d が指定されている ... 非ディレクトリとディレクトリをまとめて出力
*
movea.l entry_top,a0
move.l number_of_entry,d0
bsr output
bra exit_program_with_exitcode
split_directory:
*
* 非ディレクトリとディレクトリを分けて出力する
*
move.l number_of_entry,d3
sub.l number_of_subdir,d3 * D3.L : 非ディレクトリ引数の数
beq ls_dirargs
*
* 非ディレクトリをまとめて出力
*
move.l d3,d0
lsl.l #2,d0
bsr malloc
bmi insufficient_memory
movea.l d0,a0
movea.l entry_top,a2
movea.l a0,a1
move.l d3,d0
bra copy_nondir_list_continue
copy_nondir_list_high_loop:
swap d0
copy_nondir_list_loop:
movea.l (a2)+,a3
btst.b #FLAGBIT_SUBDIR,entry_flag(a3)
bne copy_nondir_list_loop
move.l a3,(a1)+
copy_nondir_list_continue:
dbra d0,copy_nondir_list_loop
swap d0
dbra d0,copy_nondir_list_high_loop
move.l d3,d0
bsr output
move.l a0,d0
bsr free
ls_dirargs:
*
* ディレクトリは個別にその内容を出力
*
move.b #1,print_dirheader * 1 : 改行してディレクトリ・ヘッダを出力する
tst.l d3 * D3.L == 非ディレクトリ引数の数
bne do_ls_dirargs
move.b #-1,print_dirheader * -1 : 改行せずにディレクトリ・ヘッダを出力する
move.l number_of_subdir,d0
subq.l #1,d0
bhi do_ls_dirargs
clr.b print_dirheader * 0 : ディレクトリ・ヘッダを出力しない
do_ls_dirargs:
sf have_to_headtail
bsr ls_subdir
exit_program_with_exitcode:
move.w exitcode,d0
exit_program:
move.w d0,-(a7)
DOS _EXIT2
bad_width:
lea msg_bad_width(pc),a0
bra werror_usage
too_few_args:
lea msg_too_few_args(pc),a0
werror_usage:
bsr werror_myname_and_msg
usage:
lea msg_usage(pc),a0
bsr werror
moveq #1,d0
bra exit_program
dos_version_mismatch:
lea msg_dos_version_mismatch(pc),a0
bra error_exit_3
insufficient_memory:
lea msg_no_memory(pc),a0
error_exit_3:
bsr werror_myname_and_msg
moveq #3,d0
bra exit_program
****************************************************************
* doname - 1つの引数を処理する
*
* CALL
* A0 引数の先頭アドレス
*
* RETURN
* D0.L 破壊
****************************************************************
doname:
movem.l d1-d3/a0-a5,-(a7)
movea.l a0,a5
sf slash
bsr strlen
subq.l #1,d0
bcs doname_1
cmpi.b #'/',(a0,d0.l)
seq slash
doname_1:
bsr strip_excessive_slashes
bsr strlen
cmp.l #MAXPATH,d0
bhi doname_too_long_path
bsr contains_dos_wildcard
bne doname_nofile
tst.b exploration
beq doname_nameck_lstat
movea.l a0,a4
movea.l a0,a2 * A2 : pathname scanning pointer
lea pathname(pc),a3 * A3 : pathname appending pointer
move.l #MAXPATH,d2 * D2.L : A3 の容量
cmpi.b #':',1(a2)
bne doname_drive_ok
subq.l #2,d2
bcs doname_too_long_path
move.b (a2)+,(a3)+
move.b (a2)+,(a3)+
doname_drive_ok:
cmpi.b #'/',(a2)
beq doname_dup_root
cmpi.b #'\',(a2)
bne doname_root_ok
doname_dup_root:
subq.l #1,d2
bcs doname_too_long_path
move.b (a2)+,(a3)+
doname_root_ok:
tst.b (a2)
beq doname_nameck_lstat
clr.b (a3)
movea.l a4,a0
doname_loop:
move.l a3,a4 * A4 : pathname のファイル名部
move.l d2,d3 * D3.L : ここまでの残り容量
movea.l a2,a0
bsr find_slashes
exg a0,a2
move.b (a2),d1
clr.b (a2)
bsr strlen
sub.l d0,d2
bcs doname_too_long_path
movea.l a0,a1
movea.l a3,a0
bsr stpcpy
movea.l a0,a3
move.l a1,a0
bsr is_reldir
move.b d1,(a2)
lea pathname(pc),a0
tst.w d0
bne doname_exp_pseudo
bsr lstat
bmi doname_nofile
movea.l a4,a3
move.l d3,d2
movea.l a0,a4 * A4 : 登録する名前の先頭
lea tmp_filesbuf+ST_NAME(pc),a0
bsr strlen
sub.l d0,d2
bcs doname_too_long_path
movea.l a0,a1
movea.l a3,a0
bsr stpcpy
movea.l a0,a3
movea.l a4,a0
movea.l a0,a1
tst.b (a2)
beq doname_done
bra doname_continue
doname_exp_pseudo:
tst.b (a2)
beq doname_nameck_lstat
doname_continue:
subq.l #1,d2
bcs doname_too_long_path
move.b (a2)+,(a3)+
bra doname_loop
doname_nameck_lstat:
lea nameck_buffer(pc),a1
bsr dirnameck
bpl doname_lstat
movea.l a0,a1
doname_lstat:
exg a0,a1
bsr lstat
exg a0,a1
bpl doname_done
tst.b (a1)
beq doname_nofile
exg a0,a1
move.l a1,-(a7)
bsr headtail
tst.b (a1)
movea.l (a7)+,a1
exg a0,a1
beq doname_nostat
doname_nofile:
movea.l a5,a0
bsr nofile
bra doname_return
doname_nostat:
bsr add_entry
bsr set_nostat
bsr test_subdir_bit
bra doname_return
doname_done:
move.l a1,-(a7)
bsr add_entry
lea tmp_filesbuf(pc),a2
bsr copy_stat
move.l (a7)+,a0
bsr do_test_link
cmpa.l #0,a0
beq doname_return
bsr set_block_size
*
* 引数がディレクトリならsubdirビットをONにする
*
btst.b #MODEBIT_DIR,entry_mode(a1)
bne doname_set_subdir_bit
*
* 引数がディレクトリへのシンボリック・リンクのときもsubdirビットをONにする
*
* ただし -l, -v オプションが指定されているときには,ファイル引数の末尾に /
* が付いていなければsubdirをONにしない
*
move.w entry_linkmode(a1),d0
bmi doname_return
btst #MODEBIT_DIR,d0
beq doname_return
tst.b long_format * -l, -v
beq doname_set_subdir_bit
tst.b slash
beq doname_return
doname_set_subdir_bit:
bset.b #FLAGBIT_SUBDIR,entry_flag(a1)
addq.l #1,number_of_subdir
doname_return:
movem.l (a7)+,d1-d3/a0-a5
rts
doname_too_long_path:
movea.l a5,a0
bsr too_long_path
bra doname_return
****************************************************************
* ls_subdir - ENTRY構造体アドレス配列からサブディレクトリを探し,
* そのサブディレクトリ下のファイルを出力する
*
* CALL
* entry_top ENTRY構造体アドレス配列の先頭アドレスが格納されている
* number_of_subdir ENTRY構造体のうちサブディレクトリの数
* print_dirheader 0 : ディレクトリ・ヘッダを出力しない
* 1 : 改行してディレクトリ・ヘッダを出力する
* -1 : 改行せずにディレクトリ・ヘッダを出力する
*
* RETURN
* none
*
* NOTE
* ENTRY構造体アドレス配列とその要素はすべてfreeされる.
*
* -Rオプション指定時には,ディレクトリの深さだけ再帰する.
* スタックに注意.
****************************************************************
ls_subdir:
movem.l d0-d3/a0-a4,-(a7)
lea pathname(pc),a3
bsr ls_subdir_recurse
movem.l (a7)+,d0-d3/a0-a4
rts
****************************************************************
* ls_onedir - ディレクトリをオープンして表示する
*
* CALL
* pathname ディレクトリのパスが格納されている
* 長さは MAXHEAD 未満であること
* 最後に余計な / が付いていないこと
*
* RETURN
* D0-D3/A0-A4 破壊
****************************************************************
ls_onedir:
clr.l entry_top
clr.l number_of_entry
clr.l number_of_subdir
lea pathname(pc),a0
movea.l a0,a3
bsr skip_root
exg a0,a3
movea.l a3,a4
beq ls_onedir_head_ok
exg a0,a3
bsr strbot
exg a0,a3
move.l a3,d0
sub.l a0,d0
cmp.l #MAXHEAD,d0
blo ls_onedir_1
too_long_path:
lea msg_too_long_path(pc),a2
error2:
bsr werror_myname_and_msg
movea.l a2,a0
bsr werror
move.w #2,exitcode
rts
ls_onedir_1:
movea.l a3,a4
move.b #'/',(a3)+
ls_onedir_head_ok:
lea str_dos_allfile(pc),a1
exg a0,a3
bsr strcpy
exg a0,a3
lea filesbuf(pc),a2
move.w #MODEVAL_ALL,-(a7)