diff -ru coreutils-4.5.3/man/split.1 coreutils-4.5.3-macrotron/man/split.1 --- coreutils-4.5.3/man/split.1 2002-10-13 16:04:51.000000000 +0200 +++ coreutils-4.5.3-macrotron/man/split.1 2002-12-31 17:39:35.000000000 +0100 @@ -16,6 +16,10 @@ \fB\-a\fR, \fB\-\-suffix\-length\fR=\fIN\fR use suffixes of length N (default 2) .TP +\fB\-s\fR, \fB\-\-script\fR=\fICMD\fR +Run script CMD between each file split. This is usefull when doing backups, +for example. The output file name is given as parameter to the script. +.TP \fB\-b\fR, \fB\-\-bytes\fR=\fISIZE\fR put SIZE bytes per output file .TP diff -ru coreutils-4.5.3/src/split.c coreutils-4.5.3-macrotron/src/split.c --- coreutils-4.5.3/src/split.c 2002-09-28 18:50:34.000000000 +0200 +++ coreutils-4.5.3-macrotron/src/split.c 2002-12-31 17:09:12.000000000 +0100 @@ -50,12 +50,15 @@ static char const *outbase; /* Name of output files. */ -static char *outfile; +static char *outfile; /* Pointer to the end of the prefix in OUTFILE. Suffixes are inserted here. */ static char *outfile_mid; +/* pointer so script to run between each file split */ +static char *command; + /* Length of OUTFILE's suffix. */ static size_t suffix_length = DEFAULT_SUFFIX_LENGTH; @@ -78,6 +81,7 @@ {"lines", required_argument, NULL, 'l'}, {"line-bytes", required_argument, NULL, 'C'}, {"suffix-length", required_argument, NULL, 'a'}, + {"script", required_argument, NULL, 's'}, {"verbose", no_argument, NULL, 2}, {GETOPT_HELP_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL}, @@ -106,6 +110,8 @@ "), stdout); fprintf (stdout, _("\ -a, --suffix-length=N use suffixes of length N (default %d)\n\ + -s, --script=CMD run script after each splittet file the\n\ + scripts gets the filename as first argument\n\ -b, --bytes=SIZE put SIZE bytes per output file\n\ -C, --line-bytes=SIZE put at most SIZE bytes of lines per output file\n\ -l, --lines=NUMBER put NUMBER lines per output file\n\ @@ -171,6 +177,27 @@ } } +/* runs command script of the -s parameter */ +static void +run_command (void) +{ + int command_ret; + char *command_string; + char *command_ptr; + + if ((command != NULL) & (outfile != NULL)) { + command_string=(char *)malloc(strlen(command)+strlen(outfile)+2); + if (command_string==NULL) { fprintf(stderr, "could not allocate more memory\n"); exit(1); } + command_ptr=strcpy(command_string, command); + command_ptr=strcpy(command_string+strlen(command_string), " "); + command_ptr=strcpy(command_string+strlen(command_string), outfile); + fprintf(stderr, command_string); + command_ret=system(command_string); + if (command_ret) { fprintf(stderr, "command exited with status %i", command_ret); exit(1); } + free(command_string); + } +} + /* Write BYTES bytes at BP to an output file. If NEW_FILE_FLAG is nonzero, open the next output file. Otherwise add to the same output file already in use. */ @@ -178,10 +205,14 @@ static void cwrite (int new_file_flag, const char *bp, int bytes) { + if (new_file_flag) { if (output_desc >= 0 && close (output_desc) < 0) error (EXIT_FAILURE, errno, "%s", outfile); + + /* if a script exist to handle the splitted file, execute it */ + run_command(); next_file_name (); if (verbose) @@ -387,19 +418,20 @@ textdomain (PACKAGE); atexit (close_stdout); - + /* Parse command line options. */ infile = "-"; outbase = "x"; - + command=NULL; + while (1) { /* This is the argv-index of the option we will read next. */ int this_optind = optind ? optind : 1; long int tmp_long; - c = getopt_long (argc, argv, "0123456789C:a:b:l:", longopts, NULL); + c = getopt_long (argc, argv, "0123456789C:a:b:l:s:", longopts, NULL); if (c == -1) break; @@ -486,6 +518,10 @@ case_GETOPT_HELP_CHAR; case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); + + case 's': + command=optarg; + break; default: usage (EXIT_FAILURE); @@ -568,6 +604,9 @@ abort (); } + /* run script after the last file, too. */ + run_command(); + if (close (input_desc) < 0) error (EXIT_FAILURE, errno, "%s", infile); if (output_desc >= 0 && close (output_desc) < 0)