-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmaclibunix.shar
1529 lines (1529 loc) · 37.7 KB
/
maclibunix.shar
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
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 1 (of 1)."
# Contents: MANIFEST Makefile README abort.c access.c chdir.c ctime.c
# del.c dir.h getbootvol.c getwd.c intercept.h localtime.c ls.c
# macdefs.h mkdir.c mov.c opendir.c perror.c pwd.c rename.c rmdir.c
# set_open_hook.c stat.c stat.h sync.c time.c time.h
# Wrapped by guido@dahlia.cwi.nl on Thu Jan 21 16:49:41 1993
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'MANIFEST' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(982 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X File Name Archive # Description
X-----------------------------------------------------------
X MANIFEST 1 This shipping list
X Makefile 1
X README 1
X abort.c 1
X access.c 1
X chdir.c 1
X ctime.c 1
X del.c 1
X dir.h 1
X getbootvol.c 1
X getwd.c 1
X intercept.h 1
X localtime.c 1
X ls.c 1
X macdefs.h 1
X mkdir.c 1
X mov.c 1
X opendir.c 1
X perror.c 1
X pwd.c 1
X rename.c 1
X rmdir.c 1
X set_open_hook.c 1
X stat.c 1
X stat.h 1
X sync.c 1
X time.c 1
X time.h 1
END_OF_FILE
if test 982 -ne `wc -c <'MANIFEST'`; then
echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(790 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
XCOptions= -g
X
Xall= abort.c.o ¶
X access.c.o ¶
X chdir.c.o ¶
X ctime.c.o ¶
X getbootvol.c.o ¶
X getwd.c.o ¶
X localtime.c.o ¶
X mkdir.c.o ¶
X opendir.c.o ¶
X perror.c.o ¶
X rename.c.o ¶
X rmdir.c.o ¶
X set_open_hook.c.o ¶
X stat.c.o ¶
X sync.c.o ¶
X time.c.o
X
X
Xlib.o Ä {all}
X lib -o lib.o -sn Main=unixemu {all}
X
Xlibes= {CLibraries}CInterface.o ¶
X {CLibraries}CRuntime.o ¶
X {CLibraries}CSANELib.o ¶
X {CLibraries}StdCLib.o
X
Xpobjs= pwd.c.o lib.o
Xpwd Ä {pobjs}
X link -ot MPST -oc 'MPS ' -p -o pwd {pobjs} {libes}
X
Xlobjs= ls.c.o dir.c.o stat.c.o
Xls Ä {lobjs}
X link -ot MPST -oc 'MPS ' -o ls {lobjs} {libes}
X
Xmobjs= mov.c.o rename.c.o perror.c.o
Xmov Ä {mobjs}
X link -ot MPST -oc 'MPS ' -o mov {mobjs} {libes}
X
Xdobjs= del.c.o rename.c.o perror.c.o
Xdel Ä {dobjs}
X link -ot MPST -oc 'MPS ' -o del {dobjs} {libes}
END_OF_FILE
echo shar: 23 control characters may be missing from \"'Makefile'\"
if test 790 -ne `wc -c <'Makefile'`; then
echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'README' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1959 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XHere's source code for a library of routines for users of MPW C and
XTHINK C (and possibly other C compilers) that makes it somewhat easier
Xto port Unix programs, or at least to write Unix programs that are
Xeasily portable to the Macintosh.
X
XMore-or-less Unix-compatible routines currently provided by this package:
X abort()
X access()
X chdir()
X ctime()
X getwd()
X mkdir()
X opendir(), readdir(), closedir()
X perror()
X rmdir()
X stat()
X sync()
X time(), localtime()
X
XNote: I've last used this with MPW version 2.0; MPW version 3.x may
Xinclude most of these in its own library. THINK C 5.0 includes
Xseveral, but these are still needed: chdir(), getwd(), mkdir(),
Xopendir() and friends, rmdir(), stat(), sync(). The same is true for
XTHINK C 4.0 (you may have to tweak the source in minor ways to get it
Xto compile there).
X
XI've also included a routine to get the name of the boot volume, and a
Xway to set a hook in MPW's open routine, which can be used to set the
Xtype of all files created to `TEXT'. This was also last tested in MPW
X2.0.
X
XFinally, there are two simple example programs (a columnizing `ls' and
X`pwd', both to be run as MPW tools) and a Makefile. Note that the
XMakefile contains non-ASCII characters and thus may be mangled by
Xmailers; it should however be easy enough to reconstruct it if you know
Xwhat an MPW Makefile should look like.
X
XAll routines work on MFS and HFS (but don't know about MFS folders); no
Xguarantees for Mac SE and Mac II although I don't expect problems (most
Xthings I do are just file system calls).
X
XI hope that the files are sufficiently commented, and moust routines are
Xsufficiently well-known, that no additional documentation is necessary.
X
XBeing sick and tired of copyright wars I hereby place this code in the
Xpublic domain, although it would still be nice if my name remained in
Xredistributed or changed copies of the source.
X
XGuido van Rossum
XCWI, dept. AA
XKruislaan 413
X1098 SJ Amsterdam
X
XE-mail: guido@cwi.nl
END_OF_FILE
if test 1959 -ne `wc -c <'README'`; then
echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'abort.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'abort.c'\"
else
echo shar: Extracting \"'abort.c'\" \(146 characters\)
sed "s/^X//" >'abort.c' <<'END_OF_FILE'
X/* Abort emulator.
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987). */
X
X#include "macdefs.h"
X
Xabort()
X{
X Debugger();
X exit(2);
X}
END_OF_FILE
if test 146 -ne `wc -c <'abort.c'`; then
echo shar: \"'abort.c'\" unpacked with wrong size!
fi
# end of 'abort.c'
fi
if test -f 'access.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'access.c'\"
else
echo shar: Extracting \"'access.c'\" \(953 characters\)
sed "s/^X//" >'access.c' <<'END_OF_FILE'
X/* Macintosh emulation of Unix 'access()' system call.
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
X
X This version ignores the mode flags; it assumes files can always
X be read or written when they exist. This is more or less true,
X except on write-protected volumes and maybe in a shared file system
X situation. Note that the Finder's 'locked' bit is ignored by
X the file system so you can still write such files from within
X an application.
X Execute permission might check the file type and return Yes
X if this is APPL, but I have no use for it right now anyway,
X so why bother. */
X
X#include "macdefs.h"
X
Xint
Xaccess(path, mode)
X char *path;
X int mode;
X{
X FileParam pb;
X char name[MAXPATH];
X
X strncpy(name, path, sizeof name);
X pb.ioNamePtr= (StringPtr) c2pstr(name);
X pb.ioVRefNum= 0;
X pb.ioFVersNum= 0;
X pb.ioFDirIndex= 0;
X if (PBGetFInfo(&pb, FALSE) != noErr) {
X errno= ENOENT;
X return -1;
X }
X return 0;
X}
END_OF_FILE
if test 953 -ne `wc -c <'access.c'`; then
echo shar: \"'access.c'\" unpacked with wrong size!
fi
# end of 'access.c'
fi
if test -f 'chdir.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'chdir.c'\"
else
echo shar: Extracting \"'chdir.c'\" \(505 characters\)
sed "s/^X//" >'chdir.c' <<'END_OF_FILE'
X/* Chdir for the Macintosh.
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
X Pathnames must be Macintosh paths, with colons as separators. */
X
X#include "macdefs.h"
X
X/* Change current directory. */
X
Xint
Xchdir(path)
X char *path;
X{
X WDPBRec pb;
X char name[MAXPATH];
X
X strncpy(name, path, sizeof name);
X name[MAXPATH-1]= EOS;
X pb.ioNamePtr= (StringPtr) c2pstr(name);
X pb.ioVRefNum= 0;
X pb.ioWDDirID= 0;
X if (PBHSetVol(&pb, FALSE) != noErr) {
X errno= ENOENT;
X return -1;
X }
X return 0;
X}
END_OF_FILE
if test 505 -ne `wc -c <'chdir.c'`; then
echo shar: \"'chdir.c'\" unpacked with wrong size!
fi
# end of 'chdir.c'
fi
if test -f 'ctime.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'ctime.c'\"
else
echo shar: Extracting \"'ctime.c'\" \(550 characters\)
sed "s/^X//" >'ctime.c' <<'END_OF_FILE'
X/* Ctime emulator.
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
X*/
X
X#include "macdefs.h"
X
Xstatic char dayname[]= "SunMonTueWedThuFriSat";
Xstatic char monthname[]= "JanFebMarAprMayJunJulAugSepOctNovDec";
X
Xchar *
Xctime(secs)
X long *secs;
X{
X DateTimeRec date;
X static char buffer[26];
X
X Secs2Date(*secs + TIMEDIFF, &date);
X sprintf(buffer, "%.3s %.3s %2d %02d:%02d:%02d %4d\n",
X dayname + 3*(date.dayOfWeek-1),
X monthname + 3*(date.month-1),
X date.day,
X date.hour,
X date.minute,
X date.second,
X date.year);
X return buffer;
X}
END_OF_FILE
if test 550 -ne `wc -c <'ctime.c'`; then
echo shar: \"'ctime.c'\" unpacked with wrong size!
fi
# end of 'ctime.c'
fi
if test -f 'del.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'del.c'\"
else
echo shar: Extracting \"'del.c'\" \(289 characters\)
sed "s/^X//" >'del.c' <<'END_OF_FILE'
X/* MPW tool to delete a file.
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987). */
X
Xmain(argc, argv)
X int argc;
X char **argv;
X{
X if (argc != 2) {
X printf("usage: %s file\n", argv[0]);
X exit(2);
X }
X if (unlink(argv[1]) != 0) {
X perror(argv[1]);
X exit(1);
X }
X exit(0);
X}
END_OF_FILE
if test 289 -ne `wc -c <'del.c'`; then
echo shar: \"'del.c'\" unpacked with wrong size!
fi
# end of 'del.c'
fi
if test -f 'dir.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'dir.h'\"
else
echo shar: Extracting \"'dir.h'\" \(357 characters\)
sed "s/^X//" >'dir.h' <<'END_OF_FILE'
X/*
X * "Dir.h" for the Macintosh.
X * Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
X */
X
X#define MAXNAMLEN 31
X#define MAXPATH 256
X
X#define DIR struct _dir
X
Xstruct _dir {
X long dirid;
X int nextfile;
X};
X
Xstruct direct {
X char d_name[MAXPATH];
X};
X
Xextern DIR *opendir(char *);
Xextern struct direct *readdir(DIR *);
Xextern void closedir(DIR *);
END_OF_FILE
if test 357 -ne `wc -c <'dir.h'`; then
echo shar: \"'dir.h'\" unpacked with wrong size!
fi
# end of 'dir.h'
fi
if test -f 'getbootvol.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'getbootvol.c'\"
else
echo shar: Extracting \"'getbootvol.c'\" \(336 characters\)
sed "s/^X//" >'getbootvol.c' <<'END_OF_FILE'
X/* Return the name of the boot volume (not the current directory).
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
X*/
X
X#include "macdefs.h"
X
Xchar *
Xgetbootvol()
X{
X short vrefnum;
X static char name[32];
X
X (void) GetVol(name, &vrefnum);
X /* Shouldn't fail; return ":" if it does */
X strcat(name, ":");
X return name;
X}
END_OF_FILE
if test 336 -ne `wc -c <'getbootvol.c'`; then
echo shar: \"'getbootvol.c'\" unpacked with wrong size!
fi
# end of 'getbootvol.c'
fi
if test -f 'getwd.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'getwd.c'\"
else
echo shar: Extracting \"'getwd.c'\" \(3404 characters\)
sed "s/^X//" >'getwd.c' <<'END_OF_FILE'
X/* Get full pathname of current working directory. The pathname is
X copied to the parameter array 'cwd', and a pointer to this array
X is also returned as function result. If an error occurred, however,
X the return value is NULL but 'cwd' is filled with an error message.
X
X BUG: expect spectacular crashes when called from a directory whose
X path would be over MAXPATH bytes long (files in such directories are
X not reachable by full pathname).
X
X Starting with the dir ID returned by PBHGetVol, we do successive
X PBGetCatInfo's to get a component of the path until we reach the
X root (recognized by a dir ID of 2). We move up along the path
X using the dir ID of the parent directory returned by PBGetCatInfo.
X
X Then we catenate the components found in reverse order with the volume
X name (already gotten from PBHGetVol), with intervening and trailing
X colons
X
X The code works correctly on MFS disks (where it always returns the
X volume name) by simply skipping the PBGetCatinfo calls in that case.
X There is a 'bug' in PBGetCatInfo when called for an MFS disk (with
X HFS running): it then seems to call PBHGetVInfo, which returns a
X larger parameter block. But we won't run into this problem because
X we never call PBGetCatInfo for the root (assuming that PBHGetVol
X still sets the root ID in this case).
X
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
X*/
X
X#include "macdefs.h"
X
X#define ROOTID 2 /* Root directory ID */
X
Xchar *
Xgetwd(cwd)
X char *cwd;
X{
X /* Universal parameter block. */
X union {
X#ifdef THINK_C
X HFileInfo f;
X DirInfo d;
X WDPBRec w;
X#else /* MPW */
X struct HFileInfo f;
X struct DirInfo d;
X struct WDPBRec w;
X#endif
X } pb;
X char buf[MAXPATH]; /* Buffer to store the name components */
X char *ecwd, *ebuf; /* Pointers to end of used part of cwd and buf */
X int err; /* Error code of last I/O call */
X
X /* First, get the default volume name and working directory ID. */
X
X pb.w.ioNamePtr= (unsigned char *)cwd;
X err= PBHGetVol(&pb.w, FALSE);
X if (err != noErr) {
X sprintf(cwd, "I/O error %d in PBHGetVol", err);
X return NULL;
X }
X ecwd= strchr(p2cstr((unsigned char*)cwd), EOS);
X ebuf= buf;
X *ebuf = EOS;
X
X /* Next, if at least we're running HFS, walk up the path. */
X
X if (hfsrunning()) {
X long dirid= pb.w.ioWDDirID;
X pb.d.ioVRefNum= pb.w.ioWDVRefNum;
X while (dirid != ROOTID) {
X pb.d.ioNamePtr= (unsigned char *) ++ebuf;
X pb.d.ioFDirIndex= -1;
X pb.d.ioDrDirID= dirid;
X err= PBGetCatInfo((CInfoPBPtr)&pb.d, FALSE);
X if (err != noErr) {
X sprintf(cwd, "I/O error %d in PBGetCatInfo", err);
X return NULL;
X }
X dirid= pb.d.ioDrParID;
X ebuf += strlen(p2cstr((unsigned char *)ebuf));
X /* Should check for buf overflow */
X }
X }
X
X /* Finally, reverse the list of components and append it to cwd.
X Ebuf points at the EOS after last component,
X and there is an EOS before the first component.
X If there are no components, ebuf equals buf (but there
X is still an EOS where it points).
X Ecwd points at the EOS after the path built up so far,
X initially the volume name.
X We break out of the loop in the middle, thus
X appending a colon at the end in all cases. */
X
X for (;;) {
X *ecwd++ = ':';
X if (ebuf == buf)
X break;
X do { } while (*--ebuf != EOS); /* Find component start */
X strcpy(ecwd, ebuf+1);
X ecwd= strchr(ecwd, EOS);
X }
X *ecwd= EOS;
X return cwd;
X}
END_OF_FILE
if test 3404 -ne `wc -c <'getwd.c'`; then
echo shar: \"'getwd.c'\" unpacked with wrong size!
fi
# end of 'getwd.c'
fi
if test -f 'intercept.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'intercept.h'\"
else
echo shar: Extracting \"'intercept.h'\" \(1322 characters\)
sed "s/^X//" >'intercept.h' <<'END_OF_FILE'
X/* The structure of the 'device switch' used by the standard I/O library.
X It is possible to install your own versions of selected routines
X by storing function pointers into this table. The structure of
X the control block for the dev_write function is also given.
X
X Careful! this information was gathered by disassembling parts
X of the library. There are no guarantees that the same code will
X work in future versions of MPW.
X Part of it has been tested with versions 1.0B1 trough 2.01.
X
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
X*/
X
Xtypedef int (*funcptr)(); /* Pointer to integer function */
X
Xstruct device {
X long dev_name; /* 'FSYS', 'CONS' or 'SYST' */
X funcptr dev_faccess;
X funcptr dev_close;
X funcptr dev_read;
X funcptr dev_write;
X funcptr dev_ioctl;
X};
X
Xextern struct device _StdDevs[];
X
X#define DEV_FSYS 0
X#define DEV_CONS 1
X#define DEV_SYST 2
X
X/* Control block for dev_write (arg 1 is a pointer to this).
X You might guess that dev_read is similar. */
X
Xstruct controlblock {
X long io_filler1; /* Flags? */
X long io_filler2; /* Some pointer */
X long io_filler3; /* Zero */
X long io_nbytes; /* Number of bytes to write */
X /* (Reset this to zero after writing) */
X char *io_data; /* Start of data buffer */
X};
X
X#define IO_OK 0 /* Return value from dev_write */
END_OF_FILE
if test 1322 -ne `wc -c <'intercept.h'`; then
echo shar: \"'intercept.h'\" unpacked with wrong size!
fi
# end of 'intercept.h'
fi
if test -f 'localtime.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'localtime.c'\"
else
echo shar: Extracting \"'localtime.c'\" \(454 characters\)
sed "s/^X//" >'localtime.c' <<'END_OF_FILE'
X/* Localtime emulator.
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
X*/
X
X#include "macdefs.h"
X#include "time.h"
X
Xstruct tm *
Xlocaltime(clock)
X long *clock;
X{
X DateTimeRec date;
X static struct tm t;
X
X Secs2Date(*clock + TIMEDIFF, &date);
X t.tm_sec= date.second;
X t.tm_min= date.minute;
X t.tm_hour= date.hour;
X t.tm_mday= date.day;
X t.tm_mon= date.month - 1;
X t.tm_wday= date.dayOfWeek - 1;
X t.tm_year= date.year - 1900;
X return &t;
X}
END_OF_FILE
if test 454 -ne `wc -c <'localtime.c'`; then
echo shar: \"'localtime.c'\" unpacked with wrong size!
fi
# end of 'localtime.c'
fi
if test -f 'ls.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'ls.c'\"
else
echo shar: Extracting \"'ls.c'\" \(3872 characters\)
sed "s/^X//" >'ls.c' <<'END_OF_FILE'
X/* An ls-like program for use as an MPW tool.
X Main improvement over the MPW built-in command Files is columnar
X output. Main disadvantage is the absence of a "-l" flag.
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
X*/
X
X#include <stdio.h>
X#include "dir.h"
X#include "stat.h"
X
X#include "macdefs.h"
X
Xchar *strcpy();
X
Xint
Xmain(argc, argv)
X int argc;
X char **argv;
X{
X setvbuf(stdout, (char*) NULL, _IOLBF, BUFSIZ);
X if (argc > 1)
X lslist(argc-1, argv+1);
X else
X lsdir(":");
X return 0;
X}
X
Xstruct item {
X char *name;
X long flags;
X};
X
X#define ISDIR 1 /* flag set for directory */
X
Xint
Xcompare(a, b)
X struct item *a, *b;
X{
X return IUMagString(a->name, b->name,
X strlen(a->name), strlen(b->name));
X}
X
Xoutsortedlist(listc, listv)
X int listc;
X struct item *listv;
X{
X qsort(listv, listc, sizeof(struct item), compare);
X outlist(listc, listv, 0, 0);
X}
X
Xoutlist(listc, listv, colwidth, screenwidth)
X int listc;
X struct item *listv;
X int colwidth;
X int screenwidth;
X{
X int i, j, ncols, nrows;
X char *p;
X
X if (colwidth <= 1) colwidth= 16;
X if (screenwidth <= 1) screenwidth= 72;
X ncols= screenwidth/colwidth;
X nrows= (listc+ncols-1) / ncols;
X
X for (i= 0; i < nrows; ++i) {
X for (j= i; j < listc; j += nrows) {
X if (listv[j].flags & ISDIR) {
X char buf[40];
X sprintf(buf, ":%s:", listv[j].name);
X p= buf;
X }
X else
X p= listv[j].name;
X if (j+nrows < listc)
X printf("%-*.*s ", colwidth, colwidth, p);
X else
X printf("%s\n", p);
X }
X }
X}
X
Xlslist(argc, argv)
X int argc;
X char **argv;
X{
X struct item *files= NULL;
X struct item *dirs= NULL;
X int nfiles= 0;
X int ndirs= 0;
X struct stat buf;
X int i;
X
X for (i= 0; i < argc; ++i) {
X if (isdir(argv[i]))
X addtolist(argv[i], &dirs, &ndirs, ISDIR);
X else if (stat(argv[i], &buf) >= 0)
X addtolist(argv[i], &files, &nfiles, 0);
X else
X fprintf(stderr, "Can't stat %s\n", argv[i]);
X }
X outsortedlist(nfiles, files);
X qsort(dirs, ndirs, sizeof(struct item), compare);
X for (i= 0; i < ndirs; ++i) {
X printf("\n%s\n", dirs[i]);
X lsdir(dirs[i]);
X }
X}
X
X/* "Intelligent" filename concatenation. Buf becomes path:name, but:
X insert a SEP only if path doesn't end in SEP and name doesn't
X begin with SEP; remove a SEP if path ends in SEP and name begins
X with SEP. Returns buf. */
X
Xchar *
Xmkpath(buf, path, name)
X char *buf;
X char *path;
X char *name;
X{
X char *p;
X
X strcpy(buf, path);
X p= buf + strlen(buf);
X if (p > buf) {
X if (p[-1] != SEP) {
X if (name[0] != SEP)
X *p++= SEP;
X }
X else if (name[0] == SEP)
X ++name;
X }
X strcpy(p, name);
X return buf;
X}
X
Xlsdir(dir)
X char *dir;
X{
X DIR *dirp= opendir(dir);
X struct direct *dp;
X struct item *listv= NULL;
X int listc= 0;
X char buf[256];
X
X if (dirp == NULL) {
X fprintf("can't open directory %s\n", dir);
X return -1;
X }
X while ((dp= readdir(dirp)) != NULL)
X addtolist(dp->d_name, &listv, &listc,
X isdir(mkpath(buf, dir, dp->d_name)) ? ISDIR : 0);
X closedir(dirp);
X if (listc > 0) {
X outsortedlist(listc, listv);
X while (--listc >= 0)
X freemem(listv[listc]);
X freemem((char*) listv);
X }
X}
X
Xchar *malloc();
Xchar **realloc();
X
Xchar *
Xgetmem(n)
X int n;
X{
X char *p= malloc((unsigned) n);
X
X if (p == 0)
X memexh();
X return p;
X}
X
Xregetmem(ps, n)
X char **ps;
X int n;
X{
X if (*ps == NULL)
X *ps= getmem(n);
X else {
X *ps= realloc(*ps, (unsigned) n);
X if (*ps == NULL)
X memexh();
X }
X}
X
Xfreemem(p)
X char *p;
X{
X free(p);
X}
X
Xmemexh()
X{
X fprintf(stderr, "out of memory\n");
X exit(3);
X}
X
Xchar *
Xstrdup(s)
X char *s;
X{
X char *p= getmem(strlen(s)+1);
X
X return strcpy(p, s);
X}
X
Xaddtolist(s, plistv, plistc, flags)
X char *s;
X struct item **plistv;
X int *plistc;
X int flags;
X{
X regetmem(& (char *) *plistv, (*plistc+1) * sizeof(**plistv));
X
X (*plistv)[*plistc].name= strdup(s);
X (*plistv)[*plistc].flags= flags;
X ++*plistc;
X}
X
Xisdir(path)
X char *path;
X{
X struct stat buf;
X
X return stat(path, &buf) == 0 && (buf.st_mode&S_IFMT) == S_IFDIR;
X}
END_OF_FILE
if test 3872 -ne `wc -c <'ls.c'`; then
echo shar: \"'ls.c'\" unpacked with wrong size!
fi
# end of 'ls.c'
fi
if test -f 'macdefs.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'macdefs.h'\"
else
echo shar: Extracting \"'macdefs.h'\" \(824 characters\)
sed "s/^X//" >'macdefs.h' <<'END_OF_FILE'
X/* Useful #includes and #defines for programming a set of Unix
X look-alike file system access functions on the Macintosh.
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
X*/
X
X#include <Types.h>
X#include <Files.h>
X#include <OSUtils.h>
X
X#include <pascal.h>
X
X#include <errno.h>
X#include <string.h>
X
X/* Difference in origin between Mac and Unix clocks: */
X#define TIMEDIFF ((unsigned long) \
X (((1970-1904)*365 + (1970-1904)/4) * 24 * 3600))
X
X/* Macro to find out whether we can do HFS-only calls: */
X#define FSFCBLen (* (short *) 0x3f6)
X#define hfsrunning() (FSFCBLen > 0)
X
X/* Universal constants: */
X#define MAXPATH 256
X#define TRUE 1
X#define FALSE 0
X#ifndef NULL
X#define NULL 0
X#endif
X#define EOS '\0'
X#define SEP ':'
X
X#if 0 // doesn't work
X/* Call Macsbug: */
Xpascal void Debugger() extern 0xA9FF;
X#endif
END_OF_FILE
if test 824 -ne `wc -c <'macdefs.h'`; then
echo shar: \"'macdefs.h'\" unpacked with wrong size!
fi
# end of 'macdefs.h'
fi
if test -f 'mkdir.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'mkdir.c'\"
else
echo shar: Extracting \"'mkdir.c'\" \(579 characters\)
sed "s/^X//" >'mkdir.c' <<'END_OF_FILE'
X/* Mkdir for the Macintosh.
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
X Pathnames must be Macintosh paths, with colons as separators. */
X
X#include "macdefs.h"
X
X/* Create a directory. */
X
Xint
Xmkdir(path, mode)
X char *path;
X int mode; /* Ignored */
X{
X HFileParam pb;
X char name[MAXPATH];
X
X if (!hfsrunning()) {
X errno= ENODEV;
X return -1;
X }
X strncpy(name, path, sizeof name);
X pb.ioNamePtr= (StringPtr) c2pstr(name);
X pb.ioVRefNum= 0;
X pb.ioDirID= 0;
X if (PBDirCreate((HParmBlkPtr)&pb, FALSE) != noErr) {
X errno= EACCES;
X return -1;
X }
X return 0;
X}
END_OF_FILE
if test 579 -ne `wc -c <'mkdir.c'`; then
echo shar: \"'mkdir.c'\" unpacked with wrong size!
fi
# end of 'mkdir.c'
fi
if test -f 'mov.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'mov.c'\"
else
echo shar: Extracting \"'mov.c'\" \(307 characters\)
sed "s/^X//" >'mov.c' <<'END_OF_FILE'
X/* MPW tool to move a file.
X Public domain by Guido van Rossum, CWI, Amsterdam (July 1987). */
X
Xmain(argc, argv)
X int argc;
X char **argv;
X{
X if (argc != 3) {
X printf("usage: %s oldname newname\n", argv[0]);
X exit(2);
X }
X if (rename(argv[1], argv[2]) != 0) {
X perror(argv[1]);
X exit(1);
X }
X exit(0);
X}
END_OF_FILE
if test 307 -ne `wc -c <'mov.c'`; then
echo shar: \"'mov.c'\" unpacked with wrong size!
fi
# end of 'mov.c'
fi
if test -f 'opendir.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'opendir.c'\"
else
echo shar: Extracting \"'opendir.c'\" \(1864 characters\)
sed "s/^X//" >'opendir.c' <<'END_OF_FILE'
X/*
X * Macintosh version of UNIX directory access package
X * (opendir, readdir, closedir).
X * Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
X */
X
X#include "dir.h"
X#include "macdefs.h"
X
Xstatic DIR opened;
X
X/*
X * Open a directory. This means calling PBOpenWD.
X * The value returned is always the address of opened, or NULL.
X * (I have as yet no use for multiple open directories; this could
X * be implemented by allocating memory dynamically.)
X */
X
XDIR *
Xopendir(path)
X char *path;
X{
X union {
X WDPBRec d;
X VolumeParam v;
X } pb;
X char ppath[MAXPATH];
X short err;
X
X if (opened.nextfile != 0) {