diff options
Diffstat (limited to 'tests/bkupname.c')
-rw-r--r-- | tests/bkupname.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/bkupname.c b/tests/bkupname.c new file mode 100644 index 0000000..6187146 --- /dev/null +++ b/tests/bkupname.c | |||
@@ -0,0 +1,79 @@ | |||
1 | /* wordsplit - a word splitter | ||
2 | Copyright (C) 2009, 2010 Sergey Poznyakoff | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License as published by the | ||
6 | Free Software Foundation; either version 3 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include <config.h> | ||
18 | #include "wydawca.h" | ||
19 | |||
20 | char *progname; | ||
21 | |||
22 | void | ||
23 | usage (int code) | ||
24 | { | ||
25 | FILE *fp = code ? stderr : stdout; | ||
26 | |||
27 | fprintf (fp, "usage: %s [-no] [-simple] [-existing] [-numbered] [-suffix=S] FILE\n", | ||
28 | progname); | ||
29 | exit (code); | ||
30 | } | ||
31 | |||
32 | int | ||
33 | main (int argc, char **argv) | ||
34 | { | ||
35 | enum backup_type type = numbered_backups; | ||
36 | char *file = NULL; | ||
37 | char *backup; | ||
38 | |||
39 | progname = argv[0]; | ||
40 | while (--argc) | ||
41 | { | ||
42 | char *arg = *++argv; | ||
43 | if (strcmp (arg, "-no") == 0) | ||
44 | type = no_backups; | ||
45 | else if (strcmp (arg, "-simple") == 0) | ||
46 | type = simple_backups; | ||
47 | else if (strcmp (arg, "-existing") == 0) | ||
48 | type = numbered_existing_backups; | ||
49 | else if (strcmp (arg, "-numbered") == 0) | ||
50 | type = numbered_backups; | ||
51 | else if (strncmp (arg, "-suffix=", 8) == 0) | ||
52 | simple_backup_suffix = arg + 8; | ||
53 | else if (arg[0] == '-') | ||
54 | usage (2); | ||
55 | else | ||
56 | { | ||
57 | if (argc != 1) | ||
58 | usage (2); | ||
59 | file = arg; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | if (!file) | ||
64 | usage (2); | ||
65 | backup = find_backup_file_name (file, type); | ||
66 | if (!backup) | ||
67 | { | ||
68 | if (errno) | ||
69 | { | ||
70 | perror (file); | ||
71 | exit (1); | ||
72 | } | ||
73 | printf ("no backup\n"); | ||
74 | } | ||
75 | else | ||
76 | printf ("%s\n", backup); | ||
77 | free (backup); | ||
78 | exit (0); | ||
79 | } | ||