-q, --quiet, --silent inhibit messages about irreversible recodings\n\
-f, --force force recodings even when not reversible\n\
-t, --touch touch the recoded files after replacement\n\
- --sequence=memory use memory buffers for sequencing passes\n\
+ -i, -p, --sequence=STRATEGY ignored for backwards compatibility\n\
"),
stdout);
-#if HAVE_PIPE
- fputs (_("\
- -p, --sequence=pipe use pipe machinery for sequencing passes\n\
-"),
- stdout);
-#else
- fputs (_("\
- -p, --sequence=pipe same as -i (on this system)\n\
-"),
- stdout);
-#endif
fputs (_("\
\n\
Fine tuning:\n\
stdout);
fputs (_("\
\n\
-If none of -i and -p are given, presume -p if no FILE, else -i.\n\
Each FILE is recoded over itself, destroying the original. If no\n\
FILE is specified, then act as a filter and recode stdin to stdout.\n"),
stdout);
memset (&task_option, 0, sizeof (struct recode_task));
request_option.diaeresis_char = '"';
- task_option.strategy = RECODE_STRATEGY_UNDECIDED;
task_option.fail_level = RECODE_AMBIGUOUS_OUTPUT;
task_option.abort_level = RECODE_AMBIGUOUS_OUTPUT;
usage (EXIT_FAILURE, 0);
break;
+ /* Ignore for backwards compatibility with version 3.6. */
case 0:
case 1:
- task_option.strategy = RECODE_SEQUENCE_IN_MEMORY;
- break;
-
case 2:
- task_option.strategy = RECODE_SEQUENCE_WITH_PIPE;
break;
default:
break;
case 'i':
- task_option.strategy = RECODE_SEQUENCE_IN_MEMORY;
+ /* Ignore for backwards compatibility with version 3.6. */
break;
case 'k':
break;
case 'p':
- task_option.strategy = RECODE_SEQUENCE_WITH_PIPE;
+ /* Ignore for backwards compatibility with version 3.6. */
break;
case 'q':
RECODE_TASK task;
task = recode_new_task (request);
- task->strategy = task_option.strategy;
task->fail_level = task_option.fail_level;
task->abort_level = task_option.fail_level;
if (optind < argc)
{
- /* When reading and writing files, unless the user selected
- otherwise, avoid forking and use memory. */
-
- if (task->strategy == RECODE_STRATEGY_UNDECIDED)
- task->strategy = RECODE_SEQUENCE_IN_MEMORY;
-
/* In case files are recoded over themselves and there is no
recoding step at all, do not even try to touch the files. */
}
else
{
- /* When reading stdin and writing stdout, unless the user selected
- otherwise, fork processes interconnected with pipes. */
-
- if (task->strategy == RECODE_STRATEGY_UNDECIDED)
- task->strategy = RECODE_SEQUENCE_WITH_PIPE;
-
task->input.name = "";
task->output.name = "";
if (!(*processor) (task))
`---------------------------------------------------------------------*/
static bool
-perform_sequence (RECODE_TASK task, enum recode_sequence_strategy strategy)
+perform_sequence (RECODE_TASK task)
{
RECODE_CONST_REQUEST request = task->request;
struct recode_subtask subtask_block;
subtask->output.cursor = subtask->output.buffer;
#if HAVE_PIPE
- if (strategy == RECODE_SEQUENCE_WITH_PIPE)
- {
- /* Create all subprocesses, from the first to the last, and
- interconnect them. */
+ /* Create all subprocesses, from the first to the last, and
+ interconnect them. */
- if (pipe (pipe_pair) < 0)
- {
- recode_perror (NULL, "pipe ()");
- recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
- SUBTASK_RETURN (subtask);
- }
- xset_binary_mode (pipe_pair[0], O_BINARY);
- xset_binary_mode (pipe_pair[1], O_BINARY);
- if (child_process = fork (), child_process < 0)
- {
- recode_perror (NULL, "fork ()");
- recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
- SUBTASK_RETURN (subtask);
- }
- if (child_process == 0)
- {
- /* The child executes its recoding step, reading from the
- current input file and writing to the pipe; then it exits. */
-
- if (close (pipe_pair[0]) < 0)
- {
- recode_perror (NULL, "close ()");
- recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
- }
- if (subtask->output.file = fdopen (pipe_pair[1], "w"),
- subtask->output.file == NULL)
- {
- recode_perror (NULL, "fdopen ()");
- recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
- }
- }
- else
- {
- /* The parent saves the read end of the pipe for the next step. */
-
- if (input.file = fdopen (pipe_pair[0], "r"),
- input.file == NULL)
- {
- recode_perror (NULL, "fdopen ()");
- recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
- close (pipe_pair[0]);
- close (pipe_pair[1]);
- SUBTASK_RETURN (subtask);
- }
- if (close (pipe_pair[1]) < 0)
- {
- recode_perror (NULL, "close ()");
- recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
- close (pipe_pair[0]);
- fclose (input.file);
- SUBTASK_RETURN (subtask);
- }
- }
+ if (pipe (pipe_pair) < 0)
+ {
+ recode_perror (NULL, "pipe ()");
+ recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
+ SUBTASK_RETURN (subtask);
+ }
+ xset_binary_mode (pipe_pair[0], O_BINARY);
+ xset_binary_mode (pipe_pair[1], O_BINARY);
+ if (child_process = fork (), child_process < 0)
+ {
+ recode_perror (NULL, "fork ()");
+ recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
+ SUBTASK_RETURN (subtask);
+ }
+ if (child_process == 0)
+ {
+ /* The child executes its recoding step, reading from the
+ current input file and writing to the pipe; then it exits. */
+
+ if (close (pipe_pair[0]) < 0)
+ {
+ recode_perror (NULL, "close ()");
+ recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
+ }
+ if (subtask->output.file = fdopen (pipe_pair[1], "w"),
+ subtask->output.file == NULL)
+ {
+ recode_perror (NULL, "fdopen ()");
+ recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
+ }
+ }
+ else
+ {
+ /* The parent saves the read end of the pipe for the next step. */
+
+ if (input.file = fdopen (pipe_pair[0], "r"),
+ input.file == NULL)
+ {
+ recode_perror (NULL, "fdopen ()");
+ recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
+ close (pipe_pair[0]);
+ close (pipe_pair[1]);
+ SUBTASK_RETURN (subtask);
+ }
+ if (close (pipe_pair[1]) < 0)
+ {
+ recode_perror (NULL, "close ()");
+ recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
+ close (pipe_pair[0]);
+ fclose (input.file);
+ SUBTASK_RETURN (subtask);
+ }
}
#endif
}
subtask->step = step;
(*step->transform_routine) (subtask);
- if (strategy == RECODE_SEQUENCE_WITH_PIPE)
- break; /* child/top-level process: escape from loop */
-
+#if HAVE_PIPE
+ break; /* child/top-level process: escape from loop */
+#else
/* Post-step clean up for memory sequence. */
if (subtask->input.file)
output = input;
input = subtask->output;
}
+#endif
}
if (sequence_index + 1 == (unsigned)request->sequence_length)
}
#if HAVE_PIPE
- if (strategy == RECODE_SEQUENCE_WITH_PIPE)
- {
- /* Child process exits here. */
+ /* Child process exits here. */
- if (child_process == 0)
- exit (task->error_so_far < task->fail_level ? EXIT_SUCCESS
- : EXIT_FAILURE);
- else
- {
- /* Wait on all children, mainly to avoid synchronisation problems on
- output file contents, but also to reduce the number of zombie
- processes in case the user recodes many files at once. */
+ if (child_process == 0)
+ exit (task->error_so_far < task->fail_level ? EXIT_SUCCESS
+ : EXIT_FAILURE);
+ else
+ {
+ /* Wait on all children, mainly to avoid synchronisation problems on
+ output file contents, but also to reduce the number of zombie
+ processes in case the user recodes many files at once. */
- while (wait (&wait_status) > 0)
- {
- /* Diagnose and abort on any abnormally terminating child. */
+ while (wait (&wait_status) > 0)
+ {
+ /* Diagnose and abort on any abnormally terminating child. */
- if (!(WIFEXITED (wait_status)
- || (WIFSIGNALED (wait_status)
- && WTERMSIG (wait_status) == SIGPIPE)))
- {
- recode_error (NULL, _("Child process wait status is 0x%0.2x"),
- wait_status);
- recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
- SUBTASK_RETURN (subtask);
- }
+ if (!(WIFEXITED (wait_status)
+ || (WIFSIGNALED (wait_status)
+ && WTERMSIG (wait_status) == SIGPIPE)))
+ {
+ recode_error (NULL, _("Child process wait status is 0x%0.2x"),
+ wait_status);
+ recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
+ SUBTASK_RETURN (subtask);
+ }
- /* Check for a nonzero exit from the terminating child. */
-
- if (WIFEXITED (wait_status)
- ? WEXITSTATUS (wait_status) != 0
- : WTERMSIG (wait_status) != 0)
- /* FIXME: It is not very clear what happened in sub-processes. */
- if (task->error_so_far < task->fail_level)
- {
- task->error_so_far = task->fail_level;
- task->error_at_step = request->sequence_array + (unsigned)request->sequence_length - 1;
- }
- }
+ /* Check for a nonzero exit from the terminating child. */
+
+ if (WIFEXITED (wait_status)
+ ? WEXITSTATUS (wait_status) != 0
+ : WTERMSIG (wait_status) != 0)
+ /* FIXME: It is not very clear what happened in sub-processes. */
+ if (task->error_so_far < task->fail_level)
+ {
+ task->error_so_far = task->fail_level;
+ task->error_at_step = request->sequence_array + (unsigned)request->sequence_length - 1;
+ }
+ }
- if (recode_interrupted)
- /* FIXME: It is not very clear what happened in sub-processes. */
- if (task->error_so_far < task->fail_level)
- {
- task->error_so_far = task->fail_level;
- task->error_at_step = request->sequence_array + (unsigned)request->sequence_length - 1;
- }
- }
+ if (recode_interrupted)
+ /* FIXME: It is not very clear what happened in sub-processes. */
+ if (task->error_so_far < task->fail_level)
+ {
+ task->error_so_far = task->fail_level;
+ task->error_at_step = request->sequence_array + (unsigned)request->sequence_length - 1;
+ }
}
- else
+#else
+ free (input.buffer);
+ free (output.buffer);
#endif
- {
- free (input.buffer);
- free (output.buffer);
- }
task->output = subtask->output;
SUBTASK_RETURN (subtask);
return NULL;
task->request = request;
- task->strategy = RECODE_STRATEGY_UNDECIDED;
task->fail_level = RECODE_NOT_CANONICAL;
task->abort_level = RECODE_USER_ERROR;
task->error_so_far = RECODE_NO_ERROR;
}
/*------------------------------------------------------------------------.
-| Execute the conversion sequence for a recoding TASK, using the selected |
-| strategy whenever more than one conversion step is needed. If no |
-| conversion are needed, merely copy the input onto the output. Returns |
-| zero if the recoding has been found to be non-reversible. Tell what |
-| goes on if VERBOSE. |
+| Execute the conversion sequence for a recoding TASK. If no conversions |
+| are needed, merely copy the input onto the output. |
+| Returns zero if the recoding has been found to be non-reversible. |
+| Tell what goes on if VERBOSE. |
`------------------------------------------------------------------------*/
-/* If some sequencing strategies are missing, this routine automatically
- uses fallback strategies. */
-
bool
recode_perform_task (RECODE_TASK task)
{
- /* Leave task->strategy alone, as the same task may be used many
- times differently, and the fact the strategy is undecided is a
- clue we want to preserve between calls. */
- enum recode_sequence_strategy strategy = task->strategy;
-
- switch (strategy)
- {
- case RECODE_SEQUENCE_WITH_PIPE:
-#if !HAVE_PIPE
- strategy = RECODE_SEQUENCE_IN_MEMORY;
-#endif
- case RECODE_SEQUENCE_IN_MEMORY:
- break;
-
- default: /* This should not happen, but if it does, try to recover. */
- case RECODE_STRATEGY_UNDECIDED:
- strategy = RECODE_SEQUENCE_IN_MEMORY;
- break;
- }
-
/* Switch stdin and stdout to binary mode unless they are ttys, as this has
nasty side-effects on several DOSish systems. For example, the Ctrl-Z
character is no longer interpreted as EOF, and thus the poor user cannot
if (task->output.name && !*task->output.name && !isatty (fileno (stdout)))
xset_binary_mode (fileno (stdout), O_BINARY);
- return perform_sequence (task, strategy);
+ return perform_sequence (task);
}