home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / HPFSLS.ZOO / lsprint.c < prev    next >
C/C++ Source or Header  |  1992-02-17  |  5KB  |  153 lines

  1. /*
  2.  * Stampa il nome del file con le informazioni scelte.
  3.  * (C)1990 by redmax@alessia.dei.unipd.it (Massimo A. Santin)
  4.  * $Log:    lsprint.c $
  5.  * Revision 1.1  91/05/08  20:02:29  Unknown
  6.  * Initial revision
  7.  * 
  8.  */
  9.  
  10. #include "ls.h"
  11.  
  12. static char rcsid[] = "$Header: d:/usr/utils/ls/rcs/lsprint.c 1.1 91/05/08 20:02:29 Unknown Exp $";
  13.  
  14. /* Decide se un file e` eseguibile oppure no */
  15. int is_executable(char* name)
  16. {
  17.    char *ext, *tok, *env;
  18.    char seps[] = ",;. \t\n";
  19.    char exe_exts[BUF_SIZE];
  20.  
  21.    ext = strrchr(name, '.');
  22.    if (ext == NULL)
  23.       return 0;
  24.    ext++;
  25.    if (strlen(ext) == 0)
  26.       return 0;
  27.    env = getenv("LS.EXE");
  28.    if (env == NULL)
  29.       strncpy(exe_exts, "cmd,exe,com", BUF_SIZE);
  30.    else
  31.       strncpy(exe_exts, env, BUF_SIZE);
  32.    tok = strtok(exe_exts, seps);
  33.    do {
  34.       if (STRCMP(tok, ext) == 0)
  35.          return 1;
  36.       tok = strtok(NULL, seps);
  37.    }
  38.    while (tok != NULL);
  39.    return 0;
  40. } /* is_executable */
  41.  
  42. /* stampa il nome del file */
  43. long print_name(PFILEFINDBUF pffbuf, option_type opt, int level)
  44. {
  45.    char attributes[] = "dsharwx";
  46.    char *ext, c = ' ';
  47.    int j, l;
  48.    static wide_counter = 0;
  49.  
  50.    if (! opt.all && pffbuf->achName[0] == '.')
  51.       return 0;
  52.    for (j = 0; j < level * 2; j++)
  53.       putchar(' ');
  54.  
  55.    if (opt.exeStar && is_executable(pffbuf->achName))
  56.       c = '*';
  57.    if (opt.dirSlash && (pffbuf->attrFile & FILE_DIRECTORY))
  58.       c = '\\';
  59.  
  60.    if (opt.attributes) {
  61.       attributes[DIR] = (pffbuf->attrFile & FILE_DIRECTORY) ? 'd' : '-';
  62.       attributes[SYSTEM] = (pffbuf->attrFile & FILE_SYSTEM) ? 's' : '-';
  63.       attributes[HIDDEN] = (pffbuf->attrFile & FILE_HIDDEN) ? 'h' : '-';
  64.       attributes[ARCHIVE] = (pffbuf->attrFile & FILE_ARCHIVED) ? 'a' : '-';
  65.       attributes[READABLE] = 'r';
  66.       attributes[WRITEABLE] = (pffbuf->attrFile & FILE_READONLY) ? '-' : 'w';
  67.  
  68.       if (is_executable(pffbuf->achName))
  69.          attributes[EXECUTABLE] = 'x';
  70.       else
  71.          attributes[EXECUTABLE] = '-';
  72.       printf("%s ", attributes);
  73.    }
  74.    if (opt.size) {
  75.       if (pffbuf->attrFile & FILE_DIRECTORY)
  76.          printf("%9s  ", " ");
  77.       else {
  78.           if (opt.effectiveSize) {
  79.              if (opt.k)
  80.                 printf(
  81.                    "%7ld.%1dK ",
  82.                    pffbuf->cbFileAlloc / BLOCK_SIZE,
  83.                    (pffbuf->cbFileAlloc % BLOCK_SIZE) / (BLOCK_SIZE / 10)
  84.                 );
  85.              else
  86.                printf("%9ld  ", pffbuf->cbFileAlloc);
  87.          }
  88.          else {
  89.              if (opt.k)
  90.                 printf(
  91.                    "%7ld.%1dK ",
  92.                   pffbuf->cbFile / BLOCK_SIZE,
  93.                   (pffbuf->cbFile % BLOCK_SIZE) / (BLOCK_SIZE / 10)
  94.                 );
  95.              else
  96.                printf("%9ld  ", pffbuf->cbFile);
  97.          }
  98.       }
  99.    }
  100.    if (opt.time) {
  101.       int d, m, y, h, mi;
  102.  
  103.       switch (opt.time) {
  104.          case CREATION:
  105.             d = pffbuf->fdateCreation.day;
  106.             m = pffbuf->fdateCreation.month;
  107.             y = pffbuf->fdateCreation.year + 1980;
  108.             h = pffbuf->ftimeCreation.hours;
  109.             mi = pffbuf->ftimeCreation.minutes;
  110.             break;
  111.          case LASTACCESS:
  112.             d = pffbuf->fdateLastAccess.day;
  113.             m = pffbuf->fdateLastAccess.month;
  114.             y = pffbuf->fdateLastAccess.year + 1980;
  115.             h = pffbuf->ftimeLastAccess.hours;
  116.             mi = pffbuf->ftimeLastAccess.minutes;
  117.             break;
  118.          case LASTWRITE:
  119.             d = pffbuf->fdateLastWrite.day;
  120.             m = pffbuf->fdateLastWrite.month;
  121.             y = pffbuf->fdateLastWrite.year + 1980;
  122.             h = pffbuf->ftimeLastWrite.hours;
  123.             mi = pffbuf->ftimeLastWrite.minutes;
  124.             break;
  125.          }
  126.       printf("%02d/%02d/%04d %2d:%02d ", d, m, y, h, mi);
  127.    }
  128.    #if 0 && defined(NOCASE)
  129.    if (pffbuf->attrFile & FILE_DIRECTORY)
  130.       strupr(pffbuf->achName);
  131.    else
  132.       strlwr(pffbuf->achName);
  133.    #endif
  134.    if (opt.wide) {
  135.       if ((l = strlen(pffbuf->achName)) > WIDE_LEN) {
  136.          l = WIDE_LEN - 1;
  137.          pffbuf->achName[WIDE_LEN] = '\0';
  138.       }
  139.       pffbuf->achName[l] = c;
  140.       pffbuf->achName[l + 1] = '\0';
  141.       printf("%-" WIDE_STR "s ", pffbuf->achName);
  142.       wide_counter++;
  143.       if (wide_counter % 5 == 0)
  144.          putchar('\n');
  145.    }
  146.    else
  147.       printf("%s%c\n", pffbuf->achName, c);
  148.    if (opt.ea) {
  149.       ls_ea(pffbuf->achName, level);
  150.    }
  151.    return 1;
  152. } /* print_name */
  153.