X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fcheckpoint.c;h=54c2cd6048956b16ef782643036c0063146a1e13;hb=cd7bdd4076ca154575bbef85eb2157e59befcfe2;hp=5eaaea550cfa5e97d8695a6ae334e75b2caec2d7;hpb=17cbd4862c3d44e55248195421c59e41a55e9165;p=chaz%2Ftar diff --git a/src/checkpoint.c b/src/checkpoint.c index 5eaaea5..54c2cd6 100644 --- a/src/checkpoint.c +++ b/src/checkpoint.c @@ -1,19 +1,21 @@ /* Checkpoint management for tar. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright 2007, 2013 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 3, or (at your option) any later - version. + This file is part of GNU tar. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - Public License for more details. + GNU tar is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. - You should have received a copy of the GNU General Public License along - with this program. If not, see . */ + GNU tar is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #include #include "common.h" @@ -21,7 +23,9 @@ enum checkpoint_opcode { cop_dot, + cop_bell, cop_echo, + cop_ttyout, cop_sleep, cop_exec }; @@ -75,9 +79,11 @@ void checkpoint_compile_action (const char *str) { struct checkpoint_action *act; - + if (strcmp (str, ".") == 0 || strcmp (str, "dot") == 0) alloc_action (cop_dot); + else if (strcmp (str, "bell") == 0) + alloc_action (cop_bell); else if (strcmp (str, "echo") == 0) alloc_action (cop_echo); else if (strncmp (str, "echo=", 5) == 0) @@ -90,6 +96,11 @@ checkpoint_compile_action (const char *str) act = alloc_action (cop_exec); act->v.command = copy_string_unquote (str + 5); } + else if (strncmp (str, "ttyout=", 7) == 0) + { + act = alloc_action (cop_ttyout); + act->v.command = copy_string_unquote (str + 7); + } else if (strncmp (str, "sleep=", 6) == 0) { char *p; @@ -104,20 +115,20 @@ checkpoint_compile_action (const char *str) } void -checkpoint_finish_compile () +checkpoint_finish_compile (void) { if (checkpoint_option) { if (!checkpoint_action) /* Provide a historical default */ - checkpoint_compile_action ("echo"); + checkpoint_compile_action ("echo"); } else if (checkpoint_action) /* Otherwise, set default checkpoint rate */ checkpoint_option = DEFAULT_CHECKPOINT; } -char * +static char * expand_checkpoint_string (const char *input, bool do_write, unsigned cpn) { const char *opstr = do_write ? gettext ("write") : gettext ("read"); @@ -138,7 +149,7 @@ expand_checkpoint_string (const char *input, bool do_write, unsigned cpn) case 'u': outlen += cpslen - 2; break; - + case 's': outlen += opstrlen - 2; } @@ -155,11 +166,11 @@ expand_checkpoint_string (const char *input, bool do_write, unsigned cpn) case 'u': op = stpcpy (op, cps); break; - + case 's': op = stpcpy (op, opstr); break; - + default: *op++ = '%'; *op++ = *ip; @@ -178,6 +189,7 @@ static void run_checkpoint_actions (bool do_write) { struct checkpoint_action *p; + FILE *tty = NULL; for (p = checkpoint_action; p; p = p->next) { @@ -187,7 +199,17 @@ run_checkpoint_actions (bool do_write) fputc ('.', stdlis); fflush (stdlis); break; - + + case cop_bell: + if (!tty) + tty = fopen ("/dev/tty", "w"); + if (tty) + { + fputc ('\a', tty); + fflush (tty); + } + break; + case cop_echo: { char *tmp; @@ -195,16 +217,16 @@ run_checkpoint_actions (bool do_write) if (!str) { if (do_write) - /* TRANSLATORS: This is a ``checkpoint of write operation'', - *not* ``Writing a checkpoint''. - E.g. in Spanish ``Punto de comprobaci@'on de escritura'', - *not* ``Escribiendo un punto de comprobaci@'on'' */ + /* TRANSLATORS: This is a "checkpoint of write operation", + *not* "Writing a checkpoint". + E.g. in Spanish "Punto de comprobaci@'on de escritura", + *not* "Escribiendo un punto de comprobaci@'on" */ str = gettext ("Write checkpoint %u"); else - /* TRANSLATORS: This is a ``checkpoint of read operation'', - *not* ``Reading a checkpoint''. - E.g. in Spanish ``Punto de comprobaci@'on de lectura'', - *not* ``Leyendo un punto de comprobaci@'on'' */ + /* TRANSLATORS: This is a "checkpoint of read operation", + *not* "Reading a checkpoint". + E.g. in Spanish "Punto de comprobaci@'on de lectura", + *not* "Leyendo un punto de comprobaci@'on" */ str = gettext ("Read checkpoint %u"); } tmp = expand_checkpoint_string (str, do_write, checkpoint); @@ -212,11 +234,24 @@ run_checkpoint_actions (bool do_write) free (tmp); } break; - + + case cop_ttyout: + if (!tty) + tty = fopen ("/dev/tty", "w"); + if (tty) + { + char *tmp = expand_checkpoint_string (p->v.command, do_write, + checkpoint); + fprintf (tty, "%s", tmp); + fflush (tty); + free (tmp); + } + break; + case cop_sleep: sleep (p->v.time); break; - + case cop_exec: sys_exec_checkpoint_script (p->v.command, archive_name_cursor[0], @@ -224,6 +259,8 @@ run_checkpoint_actions (bool do_write) break; } } + if (tty) + fclose (tty); } void @@ -231,5 +268,4 @@ checkpoint_run (bool do_write) { if (checkpoint_option && !(++checkpoint % checkpoint_option)) run_checkpoint_actions (do_write); -} - +}