Make the other modules use error.c
This commit is contained in:
parent
6bc3ffde5d
commit
a2f2e58353
7 changed files with 26 additions and 32 deletions
6
Makefile
6
Makefile
|
|
@ -10,9 +10,9 @@ all : $(PROGRAMS)
|
|||
install : $(PROGRAMS)
|
||||
cp $^ $(HOME)/bin/
|
||||
|
||||
dlight : dlight.o env.o http.o rss.o lockfile.o filter.o cconf.o dlhist.o
|
||||
dlight-compile : compile.o env.o lockfile.o filter.o cconf.o
|
||||
dlight-read-config : read-config.o env.o cconf.o
|
||||
dlight : dlight.o env.o http.o rss.o lockfile.o filter.o cconf.o dlhist.o error.o
|
||||
dlight-compile : compile.o env.o lockfile.o filter.o cconf.o error.o
|
||||
dlight-read-config : read-config.o env.o cconf.o error.o
|
||||
|
||||
dlight-% : %.o
|
||||
$(CC) $(LDFLAGS) -o $@ $^
|
||||
|
|
|
|||
|
|
@ -27,12 +27,11 @@
|
|||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include "env.h"
|
||||
#include "error.h"
|
||||
#include "cconf.h"
|
||||
#include "lockfile.h"
|
||||
#include "filter.h"
|
||||
|
||||
#define error(...) fprintf(stderr, "error: " __VA_ARGS__)
|
||||
|
||||
#define isalias(x) (isalnum(x) || (x) == '-')
|
||||
|
||||
#define MAXNAME 1024
|
||||
|
|
@ -252,8 +251,7 @@ static int parse_target(struct target *target) {
|
|||
if (!alias)
|
||||
return -1;
|
||||
if (!alias[0] && !dest_table_nr) {
|
||||
error("No destination found for target '%s'\n", src);
|
||||
return -1;
|
||||
return error("No destination found for target '%s'\n", src);
|
||||
}
|
||||
|
||||
target->src = strdup(src);
|
||||
|
|
|
|||
6
dlight.c
6
dlight.c
|
|
@ -3,14 +3,13 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "env.h"
|
||||
#include "error.h"
|
||||
#include "cconf.h"
|
||||
#include "dlhist.h"
|
||||
#include "filter.h"
|
||||
#include "http.h"
|
||||
#include "rss.h"
|
||||
|
||||
#define error(...) fprintf(stderr, "error: " __VA_ARGS__)
|
||||
|
||||
static void process_items(rss_t rss, struct target *t) {
|
||||
|
||||
int i;
|
||||
|
|
@ -29,8 +28,7 @@ static void process_items(rss_t rss, struct target *t) {
|
|||
|
||||
if (http_download_file(item.link, filter->dest) < 0 &&
|
||||
errno != EEXIST) {
|
||||
printf("download failed: %s\n",
|
||||
strerror(errno));
|
||||
error("download failed: %s\n", strerror(errno));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
15
filter.c
15
filter.c
|
|
@ -21,17 +21,18 @@
|
|||
#include <pcre.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "error.h"
|
||||
#include "filter.h"
|
||||
|
||||
static inline pcre* compile(const char *pattern) {
|
||||
|
||||
const char *error;
|
||||
const char *err;
|
||||
int eoffset;
|
||||
pcre *regex;
|
||||
|
||||
regex = pcre_compile(pattern, 0, &error, &eoffset, NULL);
|
||||
regex = pcre_compile(pattern, 0, &err, &eoffset, NULL);
|
||||
if (!regex) {
|
||||
fprintf(stderr, "Error compiling expression\n");
|
||||
error("Error compiling expression\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -48,14 +49,14 @@ static inline int match(pcre *pcre, const char *subject) {
|
|||
|
||||
int filter_check_syntax(const char *pattern) {
|
||||
|
||||
const char *error;
|
||||
const char *err;
|
||||
int eoffset;
|
||||
pcre *regex;
|
||||
|
||||
regex = pcre_compile(pattern, 0, &error, &eoffset, NULL);
|
||||
regex = pcre_compile(pattern, 0, &err, &eoffset, NULL);
|
||||
if (!regex) {
|
||||
fprintf(stderr, "filter: error in expression '%s': %s\n",
|
||||
pattern, error);
|
||||
error("filter: error in expression '%s': %s\n",
|
||||
pattern, err);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
|
|
|||
7
http.c
7
http.c
|
|
@ -25,6 +25,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
|
||||
static char* strnstrr(const char *str, const char *needle, size_t size) {
|
||||
|
|
@ -109,7 +110,7 @@ static size_t write_cb(void *src, size_t smemb, size_t nmemb, void *data) {
|
|||
|
||||
dest->block = realloc(dest->block, dest->len + size);
|
||||
if (dest->block == NULL) {
|
||||
printf("out of memory\n");
|
||||
error("out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
memcpy(dest->block + dest->len, src, size);
|
||||
|
|
@ -148,7 +149,7 @@ struct http_data* http_fetch_page(const char *url) {
|
|||
res = curl_easy_perform(handle);
|
||||
|
||||
if (res != CURLE_OK) {
|
||||
printf("curl: (%s) %s\n", url, curl_easy_strerror(res));
|
||||
error("curl: (%s) %s\n", url, curl_easy_strerror(res));
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
@ -184,7 +185,7 @@ int http_download_file(const char *url, const char *dir) {
|
|||
res = curl_easy_perform(handle);
|
||||
|
||||
if (res != CURLE_OK) {
|
||||
printf("curl: (%s) %s\n", url, curl_easy_strerror(res));
|
||||
error("curl: (%s) %s\n", url, curl_easy_strerror(res));
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
|
|||
12
lockfile.c
12
lockfile.c
|
|
@ -26,7 +26,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include "error.h"
|
||||
#include "lockfile.h"
|
||||
|
||||
#define locked(x) ((x)->fd >= 0)
|
||||
|
|
@ -95,13 +95,9 @@ int hold_lock(struct lockfile *lock, const char *filename, int force) {
|
|||
|
||||
lock->fd = open(lock->name, mask, 0600);
|
||||
if (lock->fd < 0) {
|
||||
if (errno == EEXIST) {
|
||||
fprintf(stderr, "'%s' is locked\n", lock->name);
|
||||
} else {
|
||||
fprintf(stderr, "unable to create lockfile '%s'",
|
||||
lock->name);
|
||||
}
|
||||
return -1;
|
||||
return error(errno == EEXIST ?
|
||||
"'%s' is locked\n" : "unable to create lockfile '%s'",
|
||||
lock->name);
|
||||
}
|
||||
lock->next = active_locks;
|
||||
active_locks = lock;
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@
|
|||
#include <string.h>
|
||||
#include "cconf.h"
|
||||
#include "env.h"
|
||||
#include "error.h"
|
||||
|
||||
static char *usage = "dlight-read-config [ <file> | -h ]\n";
|
||||
static char *usagestr = "dlight-read-config [ <file> | -h ]";
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
|
|
@ -33,8 +34,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
if (argc > 1) {
|
||||
if (!strcmp(argv[1], "-h")) {
|
||||
fprintf(stderr, usage);
|
||||
return 1;
|
||||
usage(usagestr);
|
||||
}
|
||||
strncpy(file, argv[1], sizeof(file));
|
||||
} else {
|
||||
|
|
|
|||
Reference in a new issue