Subversion Repositories SvarDOS

Rev

Rev 2204 | Rev 2206 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2204 Rev 2205
Line 148... Line 148...
148
static void dir_print_dirof(const char *p, unsigned short *availrows, unsigned char pagination) {
148
static void dir_print_dirof(const char *p, unsigned short *availrows, unsigned char pagination) {
149
  unsigned char t, lastbkslash;
149
  unsigned char t, lastbkslash;
150
  char buff[2] = {0, 0};
150
  char buff[2] = {0, 0};
151
  const char *dirof = svarlang_str(37,20); /* Directory of % */
151
  const char *dirof = svarlang_str(37,20); /* Directory of % */
152
 
152
 
-
 
153
  outputnl("");
-
 
154
  if (pagination) dir_pagination(availrows);
-
 
155
 
153
  /* print string until % */
156
  /* print string until % */
154
  while ((*dirof != 0) && (*dirof != '%')) {
157
  while ((*dirof != 0) && (*dirof != '%')) {
155
    *buff = *dirof;
158
    *buff = *dirof;
156
    output(buff);
159
    output(buff);
157
    dirof++;
160
    dirof++;
Line 586... Line 589...
586
    nls_outputnl(37,9); /* "    D by date                G group dirs first       - prefix to reverse order" */
589
    nls_outputnl(37,9); /* "    D by date                G group dirs first       - prefix to reverse order" */
587
    outputnl("");
590
    outputnl("");
588
    nls_outputnl(37,10); /* "/S Displays files in specified directory and all subdirectories" */
591
    nls_outputnl(37,10); /* "/S Displays files in specified directory and all subdirectories" */
589
    nls_outputnl(37,11); /* "/B Uses bare format (no heading information or summary)" */
592
    nls_outputnl(37,11); /* "/B Uses bare format (no heading information or summary)" */
590
    nls_outputnl(37,12); /* "/L Uses lowercases" */
593
    nls_outputnl(37,12); /* "/L Uses lowercases" */
591
    goto OK;
594
    goto GAMEOVER;
592
  }
595
  }
593
 
596
 
594
  /* allocate buf */
597
  /* allocate buf */
595
  buf = calloc(sizeof(*buf), 1);
598
  buf = calloc(sizeof(*buf), 1);
596
  if (buf == NULL) {
599
  if (buf == NULL) {
597
    nls_output_err(255, 8); /* insufficient memory */
600
    nls_output_err(255, 8); /* insufficient memory */
598
    goto FAIL;
601
    goto GAMEOVER;
599
  }
602
  }
600
 
603
 
601
  /* zero out glob_sortcmp_dat and init the collation table */
604
  /* zero out glob_sortcmp_dat and init the collation table */
602
  bzero(&glob_sortcmp_dat, sizeof(glob_sortcmp_dat));
605
  bzero(&glob_sortcmp_dat, sizeof(glob_sortcmp_dat));
603
  for (i = 0; i < 256; i++) {
606
  for (i = 0; i < 256; i++) {
Line 689... Line 692...
689
    cmd_explode(buf->buff64, dircmd, argvptrs);
692
    cmd_explode(buf->buff64, dircmd, argvptrs);
690
    if ((dir_parse_cmdline(&req, argvptrs) != 0) || (req.filespecptr != NULL)) {
693
    if ((dir_parse_cmdline(&req, argvptrs) != 0) || (req.filespecptr != NULL)) {
691
      nls_output(255, 10);/* bad environment */
694
      nls_output(255, 10);/* bad environment */
692
      output(" - ");
695
      output(" - ");
693
      outputnl("DIRCMD");
696
      outputnl("DIRCMD");
694
      goto FAIL;
697
      goto GAMEOVER;
695
    }
698
    }
696
  }
699
  }
697
  }
700
  }
698
 
701
 
699
  /* parse user's command line */
702
  /* parse user's command line */
700
  if (dir_parse_cmdline(&req, p->argv) != 0) goto FAIL;
703
  if (dir_parse_cmdline(&req, p->argv) != 0) goto GAMEOVER;
701
 
704
 
702
  /*** PARSING COMMAND LINE DONE *********************************************/
705
  /*** PARSING COMMAND LINE DONE *********************************************/
703
 
706
 
704
  /* if no filespec provided, then it's about the current directory */
707
  /* if no filespec provided, then it's about the current directory */
705
  if (req.filespecptr == NULL) req.filespecptr = ".";
708
  if (req.filespecptr == NULL) req.filespecptr = ".";
Line 717... Line 720...
717
  } else {
720
  } else {
718
    i = file_truename(req.filespecptr, buf->path);
721
    i = file_truename(req.filespecptr, buf->path);
719
  }
722
  }
720
  if (i != 0) {
723
  if (i != 0) {
721
    nls_outputnl_doserr(i);
724
    nls_outputnl_doserr(i);
722
    goto FAIL;
725
    goto GAMEOVER;
723
  }
726
  }
724
 
727
 
725
  /* volume label and serial */
728
  /* volume label and serial */
726
  if (req.format != DIR_OUTPUT_BARE) {
729
  if (req.format != DIR_OUTPUT_BARE) {
727
    drv = buf->path[0];
730
    drv = buf->path[0];
Line 755... Line 758...
755
 
758
 
756
  /* if no file match then abort */
759
  /* if no file match then abort */
757
  if (i != 0) {
760
  if (i != 0) {
758
    if (req.flags & DIR_FLAG_RECUR) goto CHECK_RECURS;
761
    if (req.flags & DIR_FLAG_RECUR) goto CHECK_RECURS;
759
    nls_outputnl_doserr(i);
762
    nls_outputnl_doserr(i);
760
    goto FAIL;
763
    goto GAMEOVER;
761
  }
764
  }
762
 
765
 
763
  /* if sorting is involved, then let's buffer all results (and sort them) */
766
  /* if sorting is involved, then let's buffer all results (and sort them) */
764
  if (req.flags & DIR_FLAG_SORT) {
767
  if (req.flags & DIR_FLAG_SORT) {
765
    /* allocate a memory buffer - try several sizes until one succeeds */
768
    /* allocate a memory buffer - try several sizes until one succeeds */
Line 772... Line 775...
772
    }
775
    }
773
    /* printf("max_dta_bufcount = %u\n", max_dta_bufcount); */
776
    /* printf("max_dta_bufcount = %u\n", max_dta_bufcount); */
774
 
777
 
775
    if (dtabuf == NULL) {
778
    if (dtabuf == NULL) {
776
      nls_outputnl_doserr(8); /* out of memory */
779
      nls_outputnl_doserr(8); /* out of memory */
777
      goto FAIL;
780
      goto GAMEOVER;
778
    }
781
    }
779
 
782
 
780
    /* remember the address so I can free it afterwards */
783
    /* remember the address so I can free it afterwards */
781
    glob_sortcmp_dat.dtabuf_root = dtabuf;
784
    glob_sortcmp_dat.dtabuf_root = dtabuf;
782
 
785
 
Line 805... Line 808...
805
 
808
 
806
    /* no match? kein gluck! (this can happen when filtering attribs with /A:xxx
809
    /* no match? kein gluck! (this can happen when filtering attribs with /A:xxx
807
     * because while findfirst() succeeds, all entries can be rejected) */
810
     * because while findfirst() succeeds, all entries can be rejected) */
808
    if (dtabufcount == 0) {
811
    if (dtabufcount == 0) {
809
      nls_outputnl_doserr(2); /* "File not found" */
812
      nls_outputnl_doserr(2); /* "File not found" */
810
      goto FAIL;
813
      goto GAMEOVER;
811
    }
814
    }
812
 
815
 
813
    /* sort the list - the tricky part is that my array is a far address while
816
    /* sort the list - the tricky part is that my array is a far address while
814
     * qsort works only with near pointers, so I have to use an ugly (and
817
     * qsort works only with near pointers, so I have to use an ugly (and
815
     * global) auxiliary table */
818
     * global) auxiliary table */
Line 919... Line 922...
919
  }
922
  }
920
 
923
 
921
  /* print out summary (unless bare output mode) */
924
  /* print out summary (unless bare output mode) */
922
  if (req.format != DIR_OUTPUT_BARE) {
925
  if (req.format != DIR_OUTPUT_BARE) {
923
    dir_print_summary_files(buf->buff64, uint32maxlen, summary_totsz, summary_fcount, &availrows, req.flags, &(buf->nls));
926
    dir_print_summary_files(buf->buff64, uint32maxlen, summary_totsz, summary_fcount, &availrows, req.flags, &(buf->nls));
924
    /* extra linefeed if /S mode */
-
 
925
    if (req.flags & DIR_FLAG_RECUR) {
-
 
926
      outputnl("");
-
 
927
      dir_pagination(&availrows);
-
 
928
    }
-
 
929
  }
927
  }
930
 
928
 
931
  /* update global counters in case /s is used */
929
  /* update global counters in case /s is used */
932
  summary_recurs_fcount += summary_fcount;
930
  summary_recurs_fcount += summary_fcount;
933
  summary_recurs_totsz += summary_totsz;
931
  summary_recurs_totsz += summary_totsz;
Line 977... Line 975...
977
 
975
 
978
  /* print out disk space available (unless bare output mode) */
976
  /* print out disk space available (unless bare output mode) */
979
  if (req.format != DIR_OUTPUT_BARE) {
977
  if (req.format != DIR_OUTPUT_BARE) {
980
    /* if /s mode then print also global stats */
978
    /* if /s mode then print also global stats */
981
    if (req.flags & DIR_FLAG_RECUR) {
979
    if (req.flags & DIR_FLAG_RECUR) {
-
 
980
      if (summary_recurs_fcount == 0) {
-
 
981
        file_truename(req.filespecptr, buf->path);
-
 
982
        dir_print_dirof(buf->path, &availrows, req.flags & DIR_FLAG_PAUSE);
-
 
983
        nls_outputnl_doserr(2); /* "File not found" */
-
 
984
        goto GAMEOVER;
-
 
985
      } else {
-
 
986
        outputnl("");
-
 
987
        if (req.flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
982
      nls_outputnl(37,25); /* Total files listed: */
988
        nls_outputnl(37,25); /* Total files listed: */
983
      if (req.flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
989
        if (req.flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
984
      dir_print_summary_files(buf->buff64, uint32maxlen, summary_recurs_totsz, summary_recurs_fcount, &availrows, req.flags, &(buf->nls));
990
        dir_print_summary_files(buf->buff64, uint32maxlen, summary_recurs_totsz, summary_recurs_fcount, &availrows, req.flags, &(buf->nls));
-
 
991
      }
985
    }
992
    }
986
    /* xxxx bytes free */
993
    /* xxxx bytes free */
987
    i = cmd_dir_df(&summary_totsz, drv);
994
    i = cmd_dir_df(&summary_totsz, drv);
988
    if (i != 0) nls_outputnl_doserr(i);
995
    if (i != 0) nls_outputnl_doserr(i);
989
    memset(buf->buff64, ' ', summary_alignpos + 8 + uint32maxlen); /* align the freebytes value to same column as totbytes */
996
    memset(buf->buff64, ' ', summary_alignpos + 8 + uint32maxlen); /* align the freebytes value to same column as totbytes */
Line 992... Line 999...
992
    output(" ");
999
    output(" ");
993
    nls_outputnl(37,24); /* "bytes free" */
1000
    nls_outputnl(37,24); /* "bytes free" */
994
    if (req.flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
1001
    if (req.flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
995
  }
1002
  }
996
 
1003
 
-
 
1004
  GAMEOVER:
-
 
1005
 
997
  /* free the buffer memory (if used) */
1006
  /* free the buffer memory (if used) */
998
  if (glob_sortcmp_dat.dtabuf_root != NULL) _ffree(glob_sortcmp_dat.dtabuf_root);
1007
  if (glob_sortcmp_dat.dtabuf_root != NULL) _ffree(glob_sortcmp_dat.dtabuf_root);
999
 
1008
 
1000
  FAIL:
-
 
1001
  free(buf);
-
 
1002
  return(CMD_FAIL);
-
 
1003
 
-
 
1004
  OK:
-
 
1005
  free(buf);
1009
  free(buf);
1006
  return(CMD_OK);
1010
  return(CMD_OK);
1007
}
1011
}