⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfls.c

📁 OXCC is a multipass, interpreting C compiler with several language extensions. It generates an Archi
💻 C
📖 第 1 页 / 共 5 页
字号:
     entries.  */

  for (i = 0, j = 0; i < files_index; i++)
    if (  !(files[i].filetype == arg_directory
         || (files[i].filetype == directory && thispend->list_patterns)))
      files[j++] = files[i];
  files_index = j;
}

/* Return non-zero if `name' doesn't end in `.' or `..'
   This is so we don't try to recurse on `././././. ...' */

int
is_not_dot_or_dotdot (name)
     char *name;

{
  char *t;

  t = rindex (name, '/');
  if (t)
    name = t + 1;

  if (name[0] == '.'
      && (name[1] == '\0'
    || (name[1] == '.' && name[2] == '\0')))
    return 0;

  return 1;
}

/* Sort the files now in the table.  */

void
sort_files ()

{
  int (*func) ();

  switch (sort_type)
  {
    case sort_none:
      return;
    case sort_time:
      switch (time_type)
      {
        case time_ctime:
          func = sort_reverse ? rev_cmp_ctime : compare_ctime;
          break;
        case time_mtime:
          func = sort_reverse ? rev_cmp_mtime : compare_mtime;
          break;
        case time_atime:
          func = sort_reverse ? rev_cmp_atime : compare_atime;
          break;
      }
      break;
    case sort_name:
      func = sort_reverse ? rev_cmp_name : compare_name;
      break;
    case sort_extension:
      func = sort_reverse ? rev_cmp_extension : compare_extension;
      break;
    case sort_size:
      func = sort_reverse ? rev_cmp_size : compare_size;
      break;
  }

  qsort (files, files_index, sizeof (struct file), func);
}

/* Comparison routines for sorting the files. */

int
compare_ctime (file1, file2)
     struct file *file1, *file2;

{
  return longdiff (file2->stats.st_ctime, file1->stats.st_ctime);
}

int
rev_cmp_ctime (file2, file1)
     struct file *file1, *file2;

{
  return longdiff (file2->stats.st_ctime, file1->stats.st_ctime);
}

int
compare_mtime (file1, file2)
     struct file *file1, *file2;

{
  return longdiff (file2->stats.st_mtime, file1->stats.st_mtime);
}

int
rev_cmp_mtime (file2, file1)
     struct file *file1, *file2;

{
  return longdiff (file2->stats.st_mtime, file1->stats.st_mtime);
}

int
compare_atime (file1, file2)
     struct file *file1, *file2;

{
  return longdiff (file2->stats.st_atime, file1->stats.st_atime);
}

int
rev_cmp_atime (file2, file1)
     struct file *file1, *file2;

{
  return longdiff (file2->stats.st_atime, file1->stats.st_atime);
}

int
compare_size (file1, file2)
     struct file *file1, *file2;

{
  return longdiff (file2->stats.st_size, file1->stats.st_size);
}

int
rev_cmp_size (file2, file1)
     struct file *file1, *file2;

{
  return longdiff (file2->stats.st_size, file1->stats.st_size);
}

int
compare_name (file1, file2)
     struct file *file1, *file2;

{
  return strcmp (file1->name, file2->name);
}

int
rev_cmp_name (file2, file1)
     struct file *file1, *file2;

{
  return strcmp (file1->name, file2->name);
}

/* Compare file extensions.  Files with no extension are `smallest'.
   If extensions are the same, compare by filenames instead. */

int
compare_extension (file1, file2)
     struct file *file1, *file2;

{
  register char *base1, *base2;
  register int cmp;

  base1 = rindex (file1->name, '.');
  base2 = rindex (file2->name, '.');
  if (base1 == NULL && base2 == NULL)
    return strcmp (file1->name, file2->name);
  if (base1 == NULL)
    return -1;
  if (base2 == NULL)
    return 1;
  cmp = strcmp (base1, base2);
  if (cmp == 0)
    return strcmp (file1->name, file2->name);
  return cmp;
}

int
rev_cmp_extension (file2, file1)
     struct file *file1, *file2;

{
  register char *base1, *base2;
  register int cmp;

  base1 = rindex (file1->name, '.');
  base2 = rindex (file2->name, '.');
  if (base1 == NULL && base2 == NULL)
    return strcmp (file1->name, file2->name);
  if (base1 == NULL)
    return -1;
  if (base2 == NULL)
    return 1;
  cmp = strcmp (base1, base2);
  if (cmp == 0)
    return strcmp (file1->name, file2->name);
  return cmp;
}

/* List all the files now in the table.  */

void
print_current_files ()

{
  register int i;

  switch (format)
  {
    case one_per_line:
      for (i = 0; i < files_index; i++)
      {
        print_file_name_and_frills (files + i);
        putchar ('\n');
      }
      break;

    case many_per_line:
      print_many_per_line ();
      break;

    case horizontal:
      print_horizontal ();
      break;

    case with_commas:
      print_with_commas ();
      break;

    case long_format:
      for (i = 0; i < files_index; i++)
      {
        print_long_format (files + i);
        putchar ('\n');
      }
      break;
  }
}

void
print_long_format (f)
     struct file *f;

{
  char modebuf[20];
  char timebuf[40];
  long when;
  unsigned long mode = f->stats.st_mode;

  if(mode & M_CHUNK)
  	strcpy(modebuf, "Chunk");
  else if(mode & M_VALUE)
    strcpy(modebuf, "Value");
  else if(mode & (M_TREEDIR|M_HASHDIR))
    strcpy(modebuf, "Node ");
  else modebuf[0] = 0;
  switch (time_type)
  {
    case time_ctime:
      when = f->stats.st_ctime;
      break;
    case time_mtime:
      when = f->stats.st_mtime;
      break;
    case time_atime:
      when = f->stats.st_atime;
      break;
  }
  if(when > 0)
  {
	  strcpy (timebuf, (char *)ctime (&when));
	  if (current_time - when > 6L * 30L * 24L * 60L * 60L
	      || current_time - when < 0L)
	  {
	      /* The file is fairly old or in the future.
	   POSIX says the cutoff is 6 months old;
	   approximate this by 6*30 days.
	   Show the year instead of the time of day.  */
	    strcpy (timebuf + 11, timebuf + 19);
	  }
  } else strcpy (timebuf, "      No Date   ");
  timebuf[16] = 0;

  if (print_inode)
#ifndef PCDOS
    printf ("%6u ", f->stats.st_ino);
#else
    printf ("%5u ", f->stats.st_ino);
#endif
  if (print_block_size)
  {
    printf ("%*u ", block_size_size, convert_blocks (ST_NBLOCKS (&f->stats),
               kilobyte_blocks));/* used blocks */
  }

  printf("%s ", modebuf);

  printf ("%8lu ", f->stats.st_size);

  printf ("%s ", timebuf + 4);

  print_name_with_quoting (f->name);

  if (f->filetype == symbolic_link)
  {

    if (f->linkname)
    {
      fputs (" -> ", stdout);
      print_name_with_quoting (f->linkname);
      if (indicator_style != none)
        print_type_indicator (f->linkmode);
    }

  }
  else if (indicator_style != none)
    print_type_indicator (f->stats.st_mode);

}

void
print_name_with_quoting (p)
     register char *p;

{
  register unsigned char c;

  if (quote_as_string)
    putchar ('"');

  while (c = *p++)
  {
    if (quote_funny_chars)
    {
      switch (c)
      {
        case '\\':
          printf ("\\\\");
          break;

        case '\n':
          printf ("\\n");
          break;

        case '\b':
          printf ("\\b");
          break;

        case '\r':
          printf ("\\r");
          break;

        case '\t':
          printf ("\\t");
          break;

        case '\f':
          printf ("\\f");
          break;

        case ' ':
          printf ("\\ ");
          break;

        case '"':
          printf ("\\\"");
          break;

        default:
          if (c > 040 && c < 0177)
            putchar (c);
          else
            printf ("\\%03o", (unsigned int) c);
      }
    }
    else
    {
      if (c >= 040 && c < 0177)
        putchar (c);
      else if (!qmark_funny_chars)
        putchar (c);
      else
        putchar ('?');
    }
  }

  if (quote_as_string)
    putchar ('"');
}

/* Print the file name of `f' with appropriate quoting.
   Also print file size, inode number, and filetype indicator character,
   as requested by switches.  */

void
print_file_name_and_frills (f)
     struct file *f;

{
  if (print_inode)
#ifndef PCDOS
    printf ("%6u ", f->stats.st_ino);
#else
    printf ("%5u ", f->stats.st_ino);
#endif
  if (print_block_size)
  {
    printf ("%*u ",block_size_size, convert_blocks (ST_NBLOCKS (&f->stats),
                 kilobyte_blocks));/* used blocks */
  }
#ifdef PCDOS
  if(format == many_per_line)
  {
    strupr(f->name);
    if((f->stats.st_mode & S_IFMT) == S_IFDIR)
      putchar('[');
  }
#endif

  print_name_with_quoting (f->name);

#ifdef PCDOS
  if(format == many_per_line)
    if((f->stats.st_mode & S_IFMT) == S_IFDIR)
      putchar(']');
#endif

  if (indicator_style != none)
    print_type_indicator (f->stats.st_mode);
}

void
print_type_indicator (mode)
     unsigned int mode;

{
  switch (mode & S_IFMT)
  {
    case S_IFDIR:
#ifdef PCDOS
      if(format != many_per_line)
#endif
        putchar ('/');
      break;

#ifdef S_IFLNK
    case S_IFLNK:
      putchar ('@');
      break;
#endif

#ifdef S_IFIFO
    case S_IFIFO:
      putchar ('|');
      break;
#endif

#ifdef S_IFSOCK
    case S_IFSOCK:
      putchar ('=');
      break;
#endif

    case S_IFREG:
      if (indicator_style == all
    && (mode & (S_IEXEC | S_IEXEC >> 3 | S_IEXEC >> 6)))
        putchar ('*');
      break;
  }
}

int
length_of_file_name_and_frills (f)
     struct file *f;

{
  register char *p = f->name;
  register char c;
  register int len = 0;
  unsigned filetype = f->stats.st_mode & S_IFMT;

  if (print_inode)
  {
#ifndef PCDOS
    len += 7;
#else
    len += 6;
#endif
  }

  if (print_block_size)
    len += 1 + block_size_size;

  if (quote_as_string)
    len += 2;

  while (c = *p++)
  {
    if (quote_funny_chars)
    {
      switch (c)
      {
        case '\\':
        case '\n':
        case '\b':
        case '\r':
        case '\t':
        case '\f':
        case ' ':
          len += 2;
          break;

        case '"':
          if (quote_as_string)
            len += 2;
          else
            len += 1;
          break;

        default:
          if (c >= 040 && c < 0177)
            len += 1;
          else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -