home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 6 File
/
06-File.zip
/
HPFSLS.ZOO
/
lsprint.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-17
|
5KB
|
153 lines
/*
* Stampa il nome del file con le informazioni scelte.
* (C)1990 by redmax@alessia.dei.unipd.it (Massimo A. Santin)
* $Log: lsprint.c $
* Revision 1.1 91/05/08 20:02:29 Unknown
* Initial revision
*
*/
#include "ls.h"
static char rcsid[] = "$Header: d:/usr/utils/ls/rcs/lsprint.c 1.1 91/05/08 20:02:29 Unknown Exp $";
/* Decide se un file e` eseguibile oppure no */
int is_executable(char* name)
{
char *ext, *tok, *env;
char seps[] = ",;. \t\n";
char exe_exts[BUF_SIZE];
ext = strrchr(name, '.');
if (ext == NULL)
return 0;
ext++;
if (strlen(ext) == 0)
return 0;
env = getenv("LS.EXE");
if (env == NULL)
strncpy(exe_exts, "cmd,exe,com", BUF_SIZE);
else
strncpy(exe_exts, env, BUF_SIZE);
tok = strtok(exe_exts, seps);
do {
if (STRCMP(tok, ext) == 0)
return 1;
tok = strtok(NULL, seps);
}
while (tok != NULL);
return 0;
} /* is_executable */
/* stampa il nome del file */
long print_name(PFILEFINDBUF pffbuf, option_type opt, int level)
{
char attributes[] = "dsharwx";
char *ext, c = ' ';
int j, l;
static wide_counter = 0;
if (! opt.all && pffbuf->achName[0] == '.')
return 0;
for (j = 0; j < level * 2; j++)
putchar(' ');
if (opt.exeStar && is_executable(pffbuf->achName))
c = '*';
if (opt.dirSlash && (pffbuf->attrFile & FILE_DIRECTORY))
c = '\\';
if (opt.attributes) {
attributes[DIR] = (pffbuf->attrFile & FILE_DIRECTORY) ? 'd' : '-';
attributes[SYSTEM] = (pffbuf->attrFile & FILE_SYSTEM) ? 's' : '-';
attributes[HIDDEN] = (pffbuf->attrFile & FILE_HIDDEN) ? 'h' : '-';
attributes[ARCHIVE] = (pffbuf->attrFile & FILE_ARCHIVED) ? 'a' : '-';
attributes[READABLE] = 'r';
attributes[WRITEABLE] = (pffbuf->attrFile & FILE_READONLY) ? '-' : 'w';
if (is_executable(pffbuf->achName))
attributes[EXECUTABLE] = 'x';
else
attributes[EXECUTABLE] = '-';
printf("%s ", attributes);
}
if (opt.size) {
if (pffbuf->attrFile & FILE_DIRECTORY)
printf("%9s ", " ");
else {
if (opt.effectiveSize) {
if (opt.k)
printf(
"%7ld.%1dK ",
pffbuf->cbFileAlloc / BLOCK_SIZE,
(pffbuf->cbFileAlloc % BLOCK_SIZE) / (BLOCK_SIZE / 10)
);
else
printf("%9ld ", pffbuf->cbFileAlloc);
}
else {
if (opt.k)
printf(
"%7ld.%1dK ",
pffbuf->cbFile / BLOCK_SIZE,
(pffbuf->cbFile % BLOCK_SIZE) / (BLOCK_SIZE / 10)
);
else
printf("%9ld ", pffbuf->cbFile);
}
}
}
if (opt.time) {
int d, m, y, h, mi;
switch (opt.time) {
case CREATION:
d = pffbuf->fdateCreation.day;
m = pffbuf->fdateCreation.month;
y = pffbuf->fdateCreation.year + 1980;
h = pffbuf->ftimeCreation.hours;
mi = pffbuf->ftimeCreation.minutes;
break;
case LASTACCESS:
d = pffbuf->fdateLastAccess.day;
m = pffbuf->fdateLastAccess.month;
y = pffbuf->fdateLastAccess.year + 1980;
h = pffbuf->ftimeLastAccess.hours;
mi = pffbuf->ftimeLastAccess.minutes;
break;
case LASTWRITE:
d = pffbuf->fdateLastWrite.day;
m = pffbuf->fdateLastWrite.month;
y = pffbuf->fdateLastWrite.year + 1980;
h = pffbuf->ftimeLastWrite.hours;
mi = pffbuf->ftimeLastWrite.minutes;
break;
}
printf("%02d/%02d/%04d %2d:%02d ", d, m, y, h, mi);
}
#if 0 && defined(NOCASE)
if (pffbuf->attrFile & FILE_DIRECTORY)
strupr(pffbuf->achName);
else
strlwr(pffbuf->achName);
#endif
if (opt.wide) {
if ((l = strlen(pffbuf->achName)) > WIDE_LEN) {
l = WIDE_LEN - 1;
pffbuf->achName[WIDE_LEN] = '\0';
}
pffbuf->achName[l] = c;
pffbuf->achName[l + 1] = '\0';
printf("%-" WIDE_STR "s ", pffbuf->achName);
wide_counter++;
if (wide_counter % 5 == 0)
putchar('\n');
}
else
printf("%s%c\n", pffbuf->achName, c);
if (opt.ea) {
ls_ea(pffbuf->achName, level);
}
return 1;
} /* print_name */