- if (tflg) {
- if (f2->fmtime == f1->fmtime)
- return (0);
- if (f2->fmtime > f1->fmtime)
- return (rflg);
- return (-rflg);
- }
- return (rflg * strcmp(f1->fname, f2->fname));
-}
-
-char *
-cat(dir, file)
- char *dir, *file;
-{
- static char dfile[BUFSIZ];
-
- if (strlen(dir)+1+strlen(file)+1 > BUFSIZ) {
- fprintf(stderr, "ls: filename too long\n");
- exit(1);
- }
- if (!strcmp(dir, "") || !strcmp(dir, ".")) {
- (void) strcpy(dfile, file);
- return (dfile);
- }
- (void) strcpy(dfile, dir);
- if (dir[strlen(dir) - 1] != '/' && *file != '/')
- (void) strcat(dfile, "/");
- (void) strcat(dfile, file);
- return (dfile);
-}
-
-char *
-savestr(str)
- char *str;
-{
- char *cp = malloc(strlen(str) + 1);
-
- if (cp == NULL) {
- fprintf(stderr, "ls: out of memory\n");
- exit(1);
- }
- (void) strcpy(cp, str);
- return (cp);
-}
-
-char *fmtinum(), *fmtsize(), *fmtlstuff(), *fmtmode();
-
-char *
-fmtentry(fp)
- register struct afile *fp;
-{
- static char fmtres[BUFSIZ];
- register char *cp, *dp;
-
- (void) sprintf(fmtres, "%s%s%s",
- iflg ? fmtinum(fp) : "",
- sflg ? fmtsize(fp) : "",
- lflg ? fmtlstuff(fp) : "");
- dp = &fmtres[strlen(fmtres)];
- for (cp = fp->fname; *cp; cp++)
- if (qflg && (*cp < ' ' || *cp >= 0177))
- *dp++ = '?';
- else
- *dp++ = *cp;
- if (Fflg) {
- if (fp->ftype == 'd')
- *dp++ = '/';
- else if (fp->ftype == 'l')
- *dp++ = '@';
- else if (fp->fflags & 0111)
- *dp++ = '*';
- }
- if (lflg && fp->flinkto) {
- (void) strcpy(dp, " -> "); dp += 4;
- for (cp = fp->flinkto; *cp; cp++)
- if (qflg && (*cp < ' ' || *cp >= 0177))
- *dp++ = '?';
- else
- *dp++ = *cp;
- }
- *dp++ = 0;
- return (fmtres);
-}
-
-char *
-fmtinum(p)
- register struct afile *p;
-{
- static char inumbuf[8];
-
- (void) sprintf(inumbuf, "%5d ", p->fnum);
- return (inumbuf);