diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-13 10:21:43 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-13 10:33:34 +0300 |
commit | de3fbe3e8d4dd2a89f7755906d76055784c437cc (patch) | |
tree | 65356dd7b5a9010499550c468e960c93515a7e15 /src | |
parent | f569a6f2628b9ddef4dfb4424aff2dad644a8f19 (diff) | |
download | wydawca-de3fbe3e8d4dd2a89f7755906d76055784c437cc.tar.gz wydawca-de3fbe3e8d4dd2a89f7755906d76055784c437cc.tar.bz2 |
Drop gnulib.
* bootstrap: Rewrite.
* bootstrap.conf: Remove.
* configure.ac: Remove gl_EARLY/gl_INIT
* src/backup.c: New file.
* src/txtacc.c (txtacc_finish): Make sure a new entry is
appended only once to the list.
* (all sources): Use grecs memory allocation functions.
* src/wydawca.h" Include fnmatch.h and regex.h
(backup_type): New enum.
(simple_backup_suffix): New extern.
(find_backup_file_name): New proto.
* tests/bkupname.c: New file.
* tests/backup00.at: New file.
* tests/backup01.at: New file.
* tests/backup02.at: New file.
* tests/backup03.at: New file.
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Add new tests.
* grecs: Update.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/backup.c | 165 | ||||
-rw-r--r-- | src/builtin.c | 10 | ||||
-rw-r--r-- | src/config.c | 26 | ||||
-rw-r--r-- | src/dictionary.c | 11 | ||||
-rw-r--r-- | src/directive.c | 8 | ||||
-rw-r--r-- | src/diskio.c | 6 | ||||
-rw-r--r-- | src/exec.c | 2 | ||||
-rw-r--r-- | src/gpg.c | 7 | ||||
-rw-r--r-- | src/job.c | 2 | ||||
-rw-r--r-- | src/lock.c | 12 | ||||
-rw-r--r-- | src/mail.c | 14 | ||||
-rw-r--r-- | src/net.c | 4 | ||||
-rw-r--r-- | src/process.c | 4 | ||||
-rw-r--r-- | src/sql.c | 4 | ||||
-rw-r--r-- | src/timer.c | 5 | ||||
-rw-r--r-- | src/triplet.c | 17 | ||||
-rw-r--r-- | src/txtacc.c | 16 | ||||
-rw-r--r-- | src/verify.c | 4 | ||||
-rw-r--r-- | src/wydawca.c | 8 | ||||
-rw-r--r-- | src/wydawca.h | 20 |
21 files changed, 268 insertions, 82 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 8139849..3b524ba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -13,12 +13,13 @@ | |||
13 | # | 13 | # |
14 | # You should have received a copy of the GNU General Public License | 14 | # You should have received a copy of the GNU General Public License |
15 | # along with Wydawca. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with Wydawca. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | ||
17 | sbin_PROGRAMS=wydawca | 17 | sbin_PROGRAMS=wydawca |
18 | wydawca_SOURCES=\ | 18 | wydawca_SOURCES=\ |
19 | backup.c\ | ||
19 | builtin.c\ | 20 | builtin.c\ |
20 | builtin.h\ | 21 | builtin.h\ |
21 | cmdline.h\ | 22 | cmdline.h\ |
22 | config.c\ | 23 | config.c\ |
23 | dictionary.c\ | 24 | dictionary.c\ |
24 | directive.c\ | 25 | directive.c\ |
@@ -57,14 +58,14 @@ SUFFIXES=.opt .c .h | |||
57 | .opt.h: | 58 | .opt.h: |
58 | $(AM_V_GEN)m4 -s $(top_srcdir)/@GRECS_SUBDIR@/build-aux/getopt.m4 $< > $@ | 59 | $(AM_V_GEN)m4 -s $(top_srcdir)/@GRECS_SUBDIR@/build-aux/getopt.m4 $< > $@ |
59 | 60 | ||
60 | incdir=$(pkgdatadir)/$(VERSION)/include | 61 | incdir=$(pkgdatadir)/$(VERSION)/include |
61 | inc_DATA = $(PP_SETUP_FILE) | 62 | inc_DATA = $(PP_SETUP_FILE) |
62 | 63 | ||
63 | LDADD=../grecs/src/libgrecs.a ../gnu/libgnu.a @SQLLIB@ @GPGMELIB@ @MAILUTILS_LIBS@ | 64 | LDADD=../grecs/src/libgrecs.a @SQLLIB@ @GPGMELIB@ @MAILUTILS_LIBS@ |
64 | INCLUDES = -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/gnu -I../gnu @MAILUTILS_INCLUDES@ | 65 | INCLUDES = -I$(top_srcdir)/grecs/src/ @MAILUTILS_INCLUDES@ |
65 | AM_CPPFLAGS= \ | 66 | AM_CPPFLAGS= \ |
66 | -DSYSCONFDIR=\"$(sysconfdir)\"\ | 67 | -DSYSCONFDIR=\"$(sysconfdir)\"\ |
67 | -DLOCALSTATEDIR=\"$(localstatedir)\"\ | 68 | -DLOCALSTATEDIR=\"$(localstatedir)\"\ |
68 | -DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\ | 69 | -DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\ |
69 | -DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\ | 70 | -DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\ |
70 | -DDEFAULT_PREPROCESSOR="$(DEFAULT_PREPROCESSOR)" | 71 | -DDEFAULT_PREPROCESSOR="$(DEFAULT_PREPROCESSOR)" |
diff --git a/src/backup.c b/src/backup.c new file mode 100644 index 0000000..312375d --- /dev/null +++ b/src/backup.c | |||
@@ -0,0 +1,165 @@ | |||
1 | /* wydawca - automatic release submission daemon | ||
2 | Copyright (C) 2011 Sergey Poznyakoff | ||
3 | |||
4 | Wydawca 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 | Wydawca 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 wydawca. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include "wydawca.h" | ||
18 | |||
19 | char const *simple_backup_suffix = "~"; | ||
20 | |||
21 | static const char * | ||
22 | split_filename (char const *file, char **pdir) | ||
23 | { | ||
24 | const char *p = strrchr (file, '/'); | ||
25 | |||
26 | if (!p) | ||
27 | { | ||
28 | *pdir = grecs_strdup ("."); | ||
29 | p = file; | ||
30 | } | ||
31 | else | ||
32 | { | ||
33 | size_t len = p - file; | ||
34 | char *dir = grecs_malloc (len + 1); | ||
35 | memcpy (dir, file, len); | ||
36 | dir[len] = 0; | ||
37 | *pdir = dir; | ||
38 | p++; | ||
39 | } | ||
40 | return p; | ||
41 | } | ||
42 | |||
43 | #define MINSUFSIZE 8 | ||
44 | #define ISDIGIT(c) ('0' <= (c) && (c) <= '9') | ||
45 | |||
46 | static char * | ||
47 | get_backup_suffix (char const *file, enum backup_type type) | ||
48 | { | ||
49 | char *dirname; | ||
50 | const char *basename; | ||
51 | size_t baselen; | ||
52 | DIR *dir; | ||
53 | struct dirent *ent; | ||
54 | char *lastsuf = NULL; | ||
55 | size_t lastsuflen = 0; | ||
56 | size_t lastsufsize = 0; | ||
57 | int carry; | ||
58 | char *newsuf; | ||
59 | char *q; | ||
60 | |||
61 | if (type == simple_backups) | ||
62 | return grecs_strdup (simple_backup_suffix); | ||
63 | |||
64 | basename = split_filename (file, &dirname); | ||
65 | baselen = strlen (basename); | ||
66 | dir = opendir (dirname); | ||
67 | if (!dir) | ||
68 | { | ||
69 | int ec = errno; | ||
70 | free (dirname); | ||
71 | errno = ec; | ||
72 | return NULL; | ||
73 | } | ||
74 | |||
75 | while ((ent = readdir (dir))) | ||
76 | { | ||
77 | size_t len = strlen (ent->d_name); | ||
78 | const char *p; | ||
79 | size_t suflen; | ||
80 | |||
81 | if (len < baselen + 4 || memcmp (ent->d_name, basename, baselen)) | ||
82 | continue; | ||
83 | p = ent->d_name + baselen; | ||
84 | suflen = len - baselen; | ||
85 | if (p[0] == '.' && p[1] == '~' && p[suflen-1] == '~' && | ||
86 | (suflen > lastsuflen | ||
87 | || (suflen == lastsuflen && | ||
88 | memcmp (p, lastsuf, lastsuflen) > 0))) | ||
89 | { | ||
90 | carry = 1; | ||
91 | for (q = (char*) p + suflen - 2; q > p + 1 && ISDIGIT (*q); q--) | ||
92 | if (*q != '9') | ||
93 | carry = 0; | ||
94 | q++; | ||
95 | if (!ISDIGIT (*q)) | ||
96 | continue; | ||
97 | |||
98 | if (suflen > lastsufsize) | ||
99 | { | ||
100 | lastsufsize = suflen; | ||
101 | if (!lastsuf) | ||
102 | { | ||
103 | if (lastsufsize < MINSUFSIZE) | ||
104 | lastsufsize = MINSUFSIZE; | ||
105 | lastsuf = grecs_malloc (lastsufsize); | ||
106 | } | ||
107 | else | ||
108 | lastsuf = grecs_realloc (lastsuf, lastsufsize); | ||
109 | } | ||
110 | memcpy (lastsuf, p, suflen); | ||
111 | lastsuflen = suflen; | ||
112 | } | ||
113 | } | ||
114 | closedir (dir); | ||
115 | free (dirname); | ||
116 | |||
117 | if (lastsuf) | ||
118 | { | ||
119 | size_t newsuflen; | ||
120 | |||
121 | newsuflen = lastsuflen + carry; | ||
122 | newsuf = grecs_malloc (newsuflen + 1); | ||
123 | newsuf[0] = '.'; | ||
124 | newsuf[1] = '~'; | ||
125 | newsuf[2] = '0'; | ||
126 | memcpy (newsuf + 2 + carry, lastsuf + 2, lastsuflen - 3); | ||
127 | newsuf[newsuflen-1] = '~'; | ||
128 | newsuf[newsuflen] = 0; | ||
129 | |||
130 | for (q = newsuf + newsuflen - 2; *q == '9'; q--) | ||
131 | *q = '0'; | ||
132 | ++*q; | ||
133 | free (lastsuf); | ||
134 | } | ||
135 | else if (type == numbered_existing_backups) | ||
136 | newsuf = grecs_strdup (simple_backup_suffix); | ||
137 | else | ||
138 | newsuf = grecs_strdup (".~1~"); | ||
139 | return newsuf; | ||
140 | } | ||
141 | |||
142 | char * | ||
143 | find_backup_file_name (char const *file, enum backup_type type) | ||
144 | { | ||
145 | size_t flen; | ||
146 | char *suffix; | ||
147 | char *newname; | ||
148 | |||
149 | if (type == no_backups) | ||
150 | { | ||
151 | errno = 0; | ||
152 | return NULL; | ||
153 | } | ||
154 | |||
155 | suffix = get_backup_suffix (file, type); | ||
156 | if (!suffix) | ||
157 | return NULL; | ||
158 | flen = strlen (file); | ||
159 | newname = grecs_malloc (flen + strlen (suffix) + 1); | ||
160 | memcpy (newname, file, flen); | ||
161 | strcpy (newname + flen, suffix); | ||
162 | free (suffix); | ||
163 | /* FIXME: Check newname length */ | ||
164 | return newname; | ||
165 | } | ||
diff --git a/src/buil |