summaryrefslogtreecommitdiff
path: root/src/fl_load.c
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2012-05-13 19:50:19 +0200
committerYorhel <git@yorhel.nl>2012-05-13 19:50:19 +0200
commitab8ff0025bbfea14035ab457a6ac238fe1bf6bf5 (patch)
tree212a832949057bfbff194b8f649d807e592707ea /src/fl_load.c
parentf5692e4b3904f64f5edf0aacc96e80b9f1608ca1 (diff)
Programming style: typedef all structs with name_t and use those
This change is only partially because my own programming style has just changed a bit in this direction.* The other (and more practical) reason is that makeheaders already creates the typedefs automatically, I've just never used them. This automatic typedef creation was a bit problematic in makeheaders' dependency resolution. E.g. 'struct hub' was typedeffed to put the name 'hub' has a global type, but I also use 'hub' as a variable in various places. This conflict is not really a problem for plain C, as types and variables live in different namespaces, but makeheaders doesn't really know that, and considered the hub structure and its dependencies as a dependency of db.c, which uses the variable 'hub'. That's somewhat inefficient and messy... These changes where mostly made by some runs of sed. If there were any errors in these changes, I suspect the compiler would have found them. (That is not to say I haven't done any basic verification myself, but, you know, this change affects a *lot* of code >_>) *) Not entirely, though. I was going more in the direction of using the old struct names directly as typedefs, without the _t. This has the same downside as mentioned above, so doesn't really work. :-(
Diffstat (limited to 'src/fl_load.c')
-rw-r--r--src/fl_load.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/fl_load.c b/src/fl_load.c
index 1700b8e..4d30555 100644
--- a/src/fl_load.c
+++ b/src/fl_load.c
@@ -42,7 +42,7 @@
#define S_UNKNOWN 6 // In some tag we didn't recognize
#define S_END 7 // Received </FileListing>
-struct ctx {
+typedef struct ctx_t {
BZFILE *fh_bz;
FILE *fh_f;
gboolean eof;
@@ -54,14 +54,14 @@ struct ctx {
gboolean filehastth;
guint64 filesize;
gboolean dirincomplete;
- struct fl_list *root;
- struct fl_list *cur;
+ fl_list_t *root;
+ fl_list_t *cur;
int unknown_level;
-};
+} ctx_t;
static int readcb(void *context, char *buf, int len, GError **err) {
- struct ctx *x = context;
+ ctx_t *x = context;
if(x->fh_bz) {
if(x->eof)
@@ -88,7 +88,7 @@ static int readcb(void *context, char *buf, int len, GError **err) {
static int entitycb(void *context, int type, const char *arg1, const char *arg2, GError **err) {
- struct ctx *x = context;
+ ctx_t *x = context;
//printf("%d,%d: %s, %s\n", x->state, type, arg1, arg2);
switch(x->state) {
@@ -122,7 +122,7 @@ static int entitycb(void *context, int type, const char *arg1, const char *arg2,
return -1;
}
// Create the directory entry
- struct fl_list *new = fl_list_create(x->name, FALSE);
+ fl_list_t *new = fl_list_create(x->name, FALSE);
new->isfile = FALSE;
new->sub = g_ptr_array_new_with_free_func(fl_list_free);
fl_list_add(x->cur, new, -1);
@@ -200,7 +200,7 @@ static int entitycb(void *context, int type, const char *arg1, const char *arg2,
return -1;
}
// Create the file entry
- struct fl_list *new = fl_list_create(x->name, x->local);
+ fl_list_t *new = fl_list_create(x->name, x->local);
new->isfile = TRUE;
new->size = x->filesize;
new->hastth = TRUE;
@@ -255,8 +255,8 @@ static int entitycb(void *context, int type, const char *arg1, const char *arg2,
}
-static int ctx_open(struct ctx *x, const char *file, GError **err) {
- memset(x, 0, sizeof(struct ctx));
+static int ctx_open(ctx_t *x, const char *file, GError **err) {
+ memset(x, 0, sizeof(ctx_t));
// open file
x->fh_f = fopen(file, "r");
@@ -279,7 +279,7 @@ static int ctx_open(struct ctx *x, const char *file, GError **err) {
}
-static void ctx_close(struct ctx *x) {
+static void ctx_close(ctx_t *x) {
if(x->fh_bz) {
int bzerr;
BZ2_bzReadClose(&bzerr, x->fh_bz);
@@ -293,10 +293,10 @@ static void ctx_close(struct ctx *x) {
}
-struct fl_list *fl_load(const char *file, GError **err, gboolean local) {
+fl_list_t *fl_load(const char *file, GError **err, gboolean local) {
g_return_val_if_fail(err == NULL || *err == NULL, NULL);
- struct ctx x;
+ ctx_t x;
GError *ierr = NULL;
if(ctx_open(&x, file, &ierr))
goto end;
@@ -330,26 +330,26 @@ end:
// Async version of fl_load(). Performs the load in a background thread. Only
// used for non-local filelists.
-struct async_dat {
+typedef struct async_t {
char *file;
- void (*cb)(struct fl_list *, GError *, void *);
+ void (*cb)(fl_list_t *, GError *, void *);
void *dat;
GError *err;
- struct fl_list *fl;
-};
+ fl_list_t *fl;
+} async_t;
static gboolean async_d(gpointer dat) {
- struct async_dat *arg = dat;
+ async_t *arg = dat;
arg->cb(arg->fl, arg->err, arg->dat);
g_free(arg->file);
- g_slice_free(struct async_dat, arg);
+ g_slice_free(async_t, arg);
return FALSE;
}
static void async_f(gpointer dat, gpointer udat) {
- struct async_dat *arg = dat;
+ async_t *arg = dat;
arg->fl = fl_load(arg->file, &arg->err, FALSE);
g_idle_add(async_d, arg);
}
@@ -357,11 +357,11 @@ static void async_f(gpointer dat, gpointer udat) {
// Ownership of both the file list and the error is passed to the callback
// function.
-void fl_load_async(const char *file, void (*cb)(struct fl_list *, GError *, void *), void *dat) {
+void fl_load_async(const char *file, void (*cb)(fl_list_t *, GError *, void *), void *dat) {
static GThreadPool *pool = NULL;
if(!pool)
pool = g_thread_pool_new(async_f, NULL, 2, FALSE, NULL);
- struct async_dat *arg = g_slice_new0(struct async_dat);
+ async_t *arg = g_slice_new0(async_t);
arg->file = g_strdup(file);
arg->dat = dat;
arg->cb = cb;