bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

merge sort temporary files


From: Jonathan Baker
Subject: merge sort temporary files
Date: 12 May 2004 17:16:58 -0700

Hi -

Sometimes when merge sorting very large files where the inputs are
FIFOs, I really don't want the big overhead of writing a temporary file
(sort currently does this because it is afraid one of the FIFOs might be
'cat OUTPUT').  So, here's a patch which adds a command-line option to
avoid this.

  --Jonathan


diff -Naur coreutils-5.2.1/src/sort.c coreutils-5.2.1-clobber/src/sort.c
--- coreutils-5.2.1/src/sort.c  2004-02-17 02:47:35.000000000 -0800
+++ coreutils-5.2.1-clobber/src/sort.c  2004-05-12 16:05:49.000000000 -0700
@@ -303,6 +303,7 @@
 Other options:\n\
 \n\
   -c, --check               check whether input is sorted; do not sort\n\
+  -C, --clobber             do not check for output overwriting input\n\
   -k, --key=POS1[,POS2]     start a key at POS1, end it at POS 2 (origin 1)\n\
   -m, --merge               merge already sorted files; do not sort\n\
   -o, --output=FILE         write result to FILE instead of standard output\n\
@@ -346,12 +347,13 @@
   exit (status);
 }
 
-#define COMMON_SHORT_OPTIONS "-bcdfgik:mMno:rsS:t:T:uz"
+#define COMMON_SHORT_OPTIONS "-bcCdfgik:mMno:rsS:t:T:uz"
 
 static struct option const long_options[] =
 {
   {"ignore-leading-blanks", no_argument, NULL, 'b'},
   {"check", no_argument, NULL, 'c'},
+  {"clobber", no_argument, NULL, 'C'},
   {"dictionary-order", no_argument, NULL, 'd'},
   {"ignore-case", no_argument, NULL, 'f'},
   {"general-numeric-sort", no_argument, NULL, 'g'},
@@ -2216,6 +2218,7 @@
   char const *s;
   int c = 0;
   bool checkonly = false;
+  bool clobber = false;
   bool mergeonly = false;
   int nfiles = 0;
   bool posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
@@ -2388,6 +2391,10 @@
          checkonly = true;
          break;
 
+       case 'C':
+         clobber = 1;
+         break;
+
        case 'k':
          key = new_key ();
 
@@ -2560,7 +2567,11 @@
 
   if (mergeonly)
     {
-      int max_merge = first_same_file (files, MIN (nfiles, NMERGE), outfile);
+      int max_merge = MIN ( nfiles, NMERGE );
+      if (!clobber)
+        {
+          max_merge = first_same_file (files, max_merge, outfile);
+        }
       merge (files, nfiles, max_merge, outfile);
     }
   else






reply via email to

[Prev in Thread] Current Thread [Next in Thread]