1 /* #includes */ /*{{{C}}}*//*{{{*/
12 /* variables */ /*{{{*/
13 static const char * const month[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" };
16 /* namecmp -- compare two entries */ /*{{{*/
17 static int namecmp(const void *a, const void *b)
19 if (**((const char * const *)a)=='[') return -1;
20 return strcmp(*((const char * const *)a),*((const char * const *)b));
23 /* olddir -- old style output */ /*{{{*/
24 static void olddir(char **dirent, int entries)
26 int i,j,k,l,user,announce;
29 for (user=0; user<32; ++user)
31 for (i=l=0; i<entries; ++i)
33 if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%33)
37 printf("User %d\n",user);
40 if (l%4) printf(" : ");
41 for (j=2; dirent[i][j] && dirent[i][j]!='.'; ++j) putchar(toupper(dirent[i][j]));
42 k=j; while (k<11) { putchar(' '); ++k; }
43 if (dirent[i][j]=='.') ++j;
44 for (k=0; dirent[i][j]; ++j,++k) putchar(toupper(dirent[i][j]));
45 for (; k<3; ++k) putchar(' ');
48 if (l && (l%4)==0) putchar('\n');
50 if (l%4) putchar('\n');
51 if (announce==2) announce=1;
53 if (entries==0) printf("No files\n");
56 /* oldddir -- old style long output */ /*{{{*/
57 static void oldddir(char **dirent, int entries, struct cpmInode *ino)
60 struct cpmStat statbuf;
65 int i,j,k,l,announce,user;
67 qsort(dirent,entries,sizeof(char*),namecmp);
69 printf(" Name Bytes Recs Attr update create\n");
70 printf("------------ ------ ------ ---- ----------------- -----------------\n");
72 for (l=user=0; user<32; ++user)
74 for (i=0; i<entries; ++i)
78 if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%33)
82 printf("\nUser %d:\n\n",user);
83 printf(" Name Bytes Recs Attr update create\n");
84 printf("------------ ------ ------ ---- ----------------- -----------------\n");
87 for (j=2; dirent[i][j] && dirent[i][j]!='.'; ++j) putchar(toupper(dirent[i][j]));
88 k=j; while (k<10) { putchar(' '); ++k; }
90 if (dirent[i][j]=='.') ++j;
91 for (k=0; dirent[i][j]; ++j,++k) putchar(toupper(dirent[i][j]));
92 for (; k<3; ++k) putchar(' ');
94 cpmNamei(ino,dirent[i],&file);
95 cpmStat(&file,&statbuf);
96 printf(" %5.1ldK",(statbuf.size+buf.f_bsize-1)/buf.f_bsize*(buf.f_bsize/1024));
97 printf(" %6.1ld ",(long)(statbuf.size/128));
98 putchar(statbuf.mode&0200 ? ' ' : 'R');
99 putchar(statbuf.mode&01000 ? 'S' : ' ');
103 tmp=gmtime(&statbuf.mtime);
104 printf(" %02d-%s-%04d %02d:%02d",tmp->tm_mday,month[tmp->tm_mon],tmp->tm_year+1900,tmp->tm_hour,tmp->tm_min);
105 tmp=gmtime(&statbuf.ctime);
106 printf(" %02d-%s-%04d %02d:%02d",tmp->tm_mday,month[tmp->tm_mon],tmp->tm_year+1900,tmp->tm_hour,tmp->tm_min);
112 if (announce==2) announce=1;
114 printf("%5.1d Files occupying %6.1ldK",l,(buf.f_bused*buf.f_bsize)/1024);
115 printf(", %7.1ldK Free.\n",(buf.f_bfree*buf.f_bsize)/1024);
117 else printf("No files found\n");
120 /* old3dir -- old CP/M Plus style long output */ /*{{{*/
121 static void old3dir(char **dirent, int entries, struct cpmInode *ino)
123 struct cpmStatFS buf;
124 struct cpmStat statbuf;
125 struct cpmInode file;
129 int i,j,k,l,announce,user, attrib;
130 int totalBytes=0,totalRecs=0;
132 qsort(dirent,entries,sizeof(char*),namecmp);
135 for (l=0,user=0; user<32; ++user)
137 for (i=0; i<entries; ++i)
141 if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%33)
143 cpmNamei(ino,dirent[i],&file);
144 cpmStat(&file,&statbuf);
145 cpmAttrGet(&file, &attrib);
148 if (user) putchar('\n');
149 printf("Directory For Drive A: User %2.1d\n\n",user);
150 printf(" Name Bytes Recs Attributes Prot Update Create\n");
151 printf("------------ ------ ------ ------------ ------ -------------- --------------\n\n");
154 for (j=2; dirent[i][j] && dirent[i][j]!='.'; ++j) putchar(toupper(dirent[i][j]));
155 k=j; while (k<10) { putchar(' '); ++k; }
157 if (dirent[i][j]=='.') ++j;
158 for (k=0; dirent[i][j]; ++j,++k) putchar(toupper(dirent[i][j]));
159 for (; k<3; ++k) putchar(' ');
161 totalBytes+=statbuf.size;
162 totalRecs+=(statbuf.size+127)/128;
163 printf(" %5.1ldk",(statbuf.size+buf.f_bsize-1)/buf.f_bsize*(buf.f_bsize/1024));
164 printf(" %6.1ld ",(long)(statbuf.size/128));
165 putchar((attrib & CPM_ATTR_F1) ? '1' : ' ');
166 putchar((attrib & CPM_ATTR_F2) ? '2' : ' ');
167 putchar((attrib & CPM_ATTR_F3) ? '3' : ' ');
168 putchar((attrib & CPM_ATTR_F4) ? '4' : ' ');
169 putchar((statbuf.mode&(S_IWUSR|S_IWGRP|S_IWOTH)) ? ' ' : 'R');
170 putchar((attrib & CPM_ATTR_SYS) ? 'S' : ' ');
171 putchar((attrib & CPM_ATTR_ARCV) ? 'A' : ' ');
173 if (attrib & CPM_ATTR_PWREAD) printf("Read ");
174 else if (attrib & CPM_ATTR_PWWRITE) printf("Write ");
175 else if (attrib & CPM_ATTR_PWDEL) printf("Delete ");
176 else printf("None ");
177 tmp=gmtime(&statbuf.mtime);
178 printf("%02d/%02d/%02d %02d:%02d ",tmp->tm_mon+1,tmp->tm_mday,tmp->tm_year%100,tmp->tm_hour,tmp->tm_min);
179 tmp=gmtime(&statbuf.ctime);
180 printf("%02d/%02d/%02d %02d:%02d",tmp->tm_mon+1,tmp->tm_mday,tmp->tm_year%100,tmp->tm_hour,tmp->tm_min);
185 if (announce==2) announce=1;
187 printf("\nTotal Bytes = %6.1dk ",(totalBytes+1023)/1024);
188 printf("Total Records = %7.1d ",totalRecs);
189 printf("Files Found = %4.1d\n",l);
190 printf("Total 1k Blocks = %6.1ld ",(buf.f_bused*buf.f_bsize)/1024);
191 printf("Used/Max Dir Entries For Drive A: %4.1ld/%4.1ld\n",buf.f_files-buf.f_ffree,buf.f_files);
193 else printf("No files found\n");
196 /* ls -- UNIX style output */ /*{{{*/
197 static void ls(char **dirent, int entries, struct cpmInode *ino, int l, int c, int iflag)
199 int i,user,announce,any;
201 struct cpmStat statbuf;
202 struct cpmInode file;
205 qsort(dirent,entries,sizeof(char*),namecmp);
208 for (user=0; user<32; ++user)
211 for (i=0; i<entries; ++i) if (dirent[i][0]!='.')
213 if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%33)
217 if (any) putchar('\n');
218 printf("%d:\n",user);
224 cpmNamei(ino,dirent[i],&file);
225 cpmStat(&file,&statbuf);
227 if (iflag) printf("%4ld ",statbuf.ino);
232 putchar(S_ISDIR(statbuf.mode) ? 'd' : '-');
233 putchar(statbuf.mode&0400 ? 'r' : '-');
234 putchar(statbuf.mode&0200 ? 'w' : '-');
235 putchar(statbuf.mode&0100 ? 'x' : '-');
236 putchar(statbuf.mode&0040 ? 'r' : '-');
237 putchar(statbuf.mode&0020 ? 'w' : '-');
238 putchar(statbuf.mode&0010 ? 'x' : '-');
239 putchar(statbuf.mode&0004 ? 'r' : '-');
240 putchar(statbuf.mode&0002 ? 'w' : '-');
241 putchar(statbuf.mode&0001 ? 'x' : '-');
243 putchar(statbuf.flags&FLAG_PUBLIC ? 'p' : '-');
244 putchar(dir[i].flags&FLAG_SYSTEM ? 's' : '-');
245 printf(" %-2d ",dir[i].user);
247 printf("%8.1ld ",(long)statbuf.size);
248 tmp=gmtime(c ? &statbuf.ctime : &statbuf.mtime);
249 printf("%s %02d ",month[tmp->tm_mon],tmp->tm_mday);
250 if ((c ? statbuf.ctime : statbuf.mtime)<(now-182*24*3600)) printf("%04d ",tmp->tm_year+1900);
251 else printf("%02d:%02d ",tmp->tm_hour,tmp->tm_min);
253 printf("%s\n",dirent[i]+2);
259 /* lsattr -- output something like e2fs lsattr */ /*{{{*/
260 static void lsattr(char **dirent, int entries, struct cpmInode *ino)
262 int i,user,announce,any;
263 struct cpmStat statbuf;
264 struct cpmInode file;
267 qsort(dirent,entries,sizeof(char*),namecmp);
270 for (user=0; user<32; ++user)
273 for (i=0; i<entries; ++i) if (dirent[i][0]!='.')
275 if (dirent[i][0]=='0'+user/10 && dirent[i][1]=='0'+user%33)
279 if (any) putchar('\n');
280 printf("%d:\n",user);
285 cpmNamei(ino,dirent[i],&file);
286 cpmStat(&file,&statbuf);
287 cpmAttrGet(&file, &attrib);
289 putchar ((attrib & CPM_ATTR_F1) ? '1' : '-');
290 putchar ((attrib & CPM_ATTR_F2) ? '2' : '-');
291 putchar ((attrib & CPM_ATTR_F3) ? '3' : '-');
292 putchar ((attrib & CPM_ATTR_F4) ? '4' : '-');
293 putchar ((attrib & CPM_ATTR_SYS) ? 's' : '-');
294 putchar ((attrib & CPM_ATTR_ARCV) ? 'a' : '-');
295 putchar ((attrib & CPM_ATTR_PWREAD) ? 'r' : '-');
296 putchar ((attrib & CPM_ATTR_PWWRITE) ? 'w' : '-');
297 putchar ((attrib & CPM_ATTR_PWDEL) ? 'e' : '-');
299 printf(" %s\n",dirent[i]+2);
306 const char cmd[]="cpmls";
308 int main(int argc, char *argv[])
310 /* variables */ /*{{{*/
313 const char *format=FORMAT;
314 const char *devopts=NULL;
316 struct cpmSuperBlock drive;
317 struct cpmInode root;
323 static char starlit[2]="*";
324 static char * const star[]={starlit};
327 /* parse options */ /*{{{*/
328 while ((c=getopt(argc,argv,"cT:f:ih?dDFlA"))!=EOF) switch(c)
330 case 'f': format=optarg; break;
331 case 'T': devopts=optarg; break;
333 case '?': usage=1; break;
334 case 'd': style=1; break;
335 case 'D': style=2; break;
336 case 'F': style=3; break;
337 case 'l': style=4; break;
338 case 'A': style=5; break;
339 case 'c': changetime=1; break;
340 case 'i': inode=1; break;
343 if (optind==argc) usage=1;
344 else image=argv[optind++];
348 fprintf(stderr,"Usage: %s [-f format] [-T libdsk-type] [-d|-D|-F|-A|[-l][-c][-i]] image [file ...]\n",cmd);
352 /* open image */ /*{{{*/
353 if ((err=Device_open(&drive.dev,image,O_RDONLY,devopts)))
355 fprintf(stderr,"%s: can not open %s (%s)\n",cmd,image,err);
358 cpmReadSuper(&drive,&root,format);
360 if (optind<argc) cpmglob(optind,argc,argv,&root,&gargc,&gargv);
361 else cpmglob(0,1,star,&root,&gargc,&gargv);
362 if (style==1) olddir(gargv,gargc);
363 else if (style==2) oldddir(gargv,gargc,&root);
364 else if (style==3) old3dir(gargv,gargc,&root);
365 else if (style==5) lsattr(gargv, gargc, &root);
366 else ls(gargv,gargc,&root,style==4,changetime,inode);