diff --git a/src/libgenders/genders.c b/src/libgenders/genders.c index 8f28000..a309b6c 100644 --- a/src/libgenders/genders.c +++ b/src/libgenders/genders.c @@ -191,21 +191,21 @@ genders_load_data(genders_t handle, const char *filename) (hash_del_f)list_destroy); if (_genders_open_and_parse(handle, - filename, - &handle->numattrs, - &handle->maxattrs, - &handle->maxnodelen, - &handle->maxattrlen, - &handle->maxvallen, - handle->nodeslist, - handle->attrvalslist, - handle->attrslist, + filename, + &handle->numattrs, + &handle->maxattrs, + &handle->maxnodelen, + &handle->maxattrlen, + &handle->maxvallen, + handle->nodeslist, + handle->attrvalslist, + handle->attrslist, &(handle->node_index), &(handle->node_index_size), &(handle->attr_index), &(handle->attr_index_size), - 0, - NULL) < 0) + 0, + NULL) < 0) goto cleanup; handle->numnodes = list_count(handle->nodeslist); @@ -308,7 +308,7 @@ int genders_set_flags(genders_t handle, unsigned int flags) { unsigned int mask = (GENDERS_FLAG_DEFAULT - | GENDERS_FLAG_RAW_VALUES); + | GENDERS_FLAG_RAW_VALUES); if (_genders_handle_error_check(handle) < 0) return -1; @@ -400,14 +400,14 @@ _genders_list_create(genders_t handle, char ***list, int len, int buflen) if (len > 0) { if (!list) - { - handle->errnum = GENDERS_ERR_PARAMETERS; - return -1; - } + { + handle->errnum = GENDERS_ERR_PARAMETERS; + return -1; + } __xmalloc(templist, char **, sizeof(char *) * len); for (i = 0; i < len; i++) - __xmalloc(templist[i], char *, buflen); + __xmalloc(templist[i], char *, buflen); *list = templist; } @@ -419,7 +419,7 @@ _genders_list_create(genders_t handle, char ***list, int len, int buflen) { int j; for (j = 0; j < i; j++) - free(templist[j]); + free(templist[j]); free(templist); } return -1; @@ -440,20 +440,20 @@ _genders_list_clear(genders_t handle, char **list, int len, int buflen) int i; if (!list) - { - handle->errnum = GENDERS_ERR_PARAMETERS; - return -1; - } + { + handle->errnum = GENDERS_ERR_PARAMETERS; + return -1; + } for (i = 0; i < len; i++) - { - if (!list[i]) - { - handle->errnum = GENDERS_ERR_NULLPTR; - return -1; - } - memset(list[i], '\0', buflen); - } + { + if (!list[i]) + { + handle->errnum = GENDERS_ERR_NULLPTR; + return -1; + } + memset(list[i], '\0', buflen); + } } handle->errnum = GENDERS_ERR_SUCCESS; @@ -475,13 +475,13 @@ _genders_list_destroy(genders_t handle, char **list, int len) int i; if (!list) - { - handle->errnum = GENDERS_ERR_PARAMETERS; - return -1; - } + { + handle->errnum = GENDERS_ERR_PARAMETERS; + return -1; + } for (i = 0; i < len; i++) - free(list[i]); + free(list[i]); free(list); } @@ -496,9 +496,9 @@ genders_nodelist_create(genders_t handle, char ***list) return -1; return _genders_list_create(handle, - list, - handle->numnodes, - handle->maxnodelen+1); + list, + handle->numnodes, + handle->maxnodelen+1); } int @@ -508,9 +508,9 @@ genders_nodelist_clear(genders_t handle, char **list) return -1; return _genders_list_clear(handle, - list, - handle->numnodes, - handle->maxnodelen+1); + list, + handle->numnodes, + handle->maxnodelen+1); } int @@ -520,8 +520,8 @@ genders_nodelist_destroy(genders_t handle, char **list) return -1; return _genders_list_destroy(handle, - list, - handle->numnodes); + list, + handle->numnodes); } int @@ -531,9 +531,9 @@ genders_attrlist_create(genders_t handle, char ***list) return -1; return _genders_list_create(handle, - list, - handle->numattrs, - handle->maxattrlen+1); + list, + handle->numattrs, + handle->maxattrlen+1); } int @@ -543,9 +543,9 @@ genders_attrlist_clear(genders_t handle, char **list) return -1; return _genders_list_clear(handle, - list, - handle->numattrs, - handle->maxattrlen+1); + list, + handle->numattrs, + handle->maxattrlen+1); } int @@ -555,8 +555,8 @@ genders_attrlist_destroy(genders_t handle, char **list) return -1; return _genders_list_destroy(handle, - list, - handle->numattrs); + list, + handle->numattrs); } int @@ -566,9 +566,9 @@ genders_vallist_create(genders_t handle, char ***list) return -1; return _genders_list_create(handle, - list, - handle->numattrs, - handle->maxvallen+1); + list, + handle->numattrs, + handle->maxvallen+1); } int @@ -578,9 +578,9 @@ genders_vallist_clear(genders_t handle, char **list) return -1; return _genders_list_clear(handle, - list, - handle->numattrs, - handle->maxvallen+1); + list, + handle->numattrs, + handle->maxvallen+1); } int @@ -590,8 +590,8 @@ genders_vallist_destroy(genders_t handle, char **list) return -1; return _genders_list_destroy(handle, - list, - handle->numattrs); + list, + handle->numattrs); } int @@ -649,18 +649,18 @@ genders_getnodes(genders_t handle, char *nodes[], int len, List l; if (!(l = hash_find(handle->attrval_index, val))) - { - /* No attributes with this value */ - handle->errnum = GENDERS_ERR_SUCCESS; - return 0; - } + { + /* No attributes with this value */ + handle->errnum = GENDERS_ERR_SUCCESS; + return 0; + } __list_iterator_create(itr, l); while ((n = list_next(itr))) - { - if (_genders_put_in_array(handle, n->name, nodes, index++, len) < 0) - goto cleanup; - } + { + if (_genders_put_in_array(handle, n->name, nodes, index++, len) < 0) + goto cleanup; + } } else if (attr) { @@ -669,40 +669,40 @@ genders_getnodes(genders_t handle, char *nodes[], int len, if (!handle->numattrs) { - /* No attributes, so no nodes have this attr */ - handle->errnum = GENDERS_ERR_SUCCESS; - return 0; + /* No attributes, so no nodes have this attr */ + handle->errnum = GENDERS_ERR_SUCCESS; + return 0; } if (!(l = hash_find(handle->attr_index, attr))) - { - /* No nodes have this attr */ - handle->errnum = GENDERS_ERR_SUCCESS; - return 0; - } + { + /* No nodes have this attr */ + handle->errnum = GENDERS_ERR_SUCCESS; + return 0; + } __list_iterator_create(itr, l); while ((n = list_next(itr))) - { - genders_attrval_t av; + { + genders_attrval_t av; - /* val could be NULL */ - if (_genders_find_attrval(handle, n, attr, val, &av) < 0) - goto cleanup; + /* val could be NULL */ + if (_genders_find_attrval(handle, n, attr, val, &av) < 0) + goto cleanup; - if (av && _genders_put_in_array(handle, n->name, nodes, index++, len) < 0) - goto cleanup; - } + if (av && _genders_put_in_array(handle, n->name, nodes, index++, len) < 0) + goto cleanup; + } } else { /* Case C: get every node */ __list_iterator_create(itr, handle->nodeslist); while ((n = list_next(itr))) - { - if (_genders_put_in_array(handle, n->name, nodes, index++, len) < 0) - goto cleanup; - } + { + if (_genders_put_in_array(handle, n->name, nodes, index++, len) < 0) + goto cleanup; + } } rv = index; @@ -714,10 +714,10 @@ genders_getnodes(genders_t handle, char *nodes[], int len, int genders_getattr(genders_t handle, - char *attrs[], - char *vals[], + char *attrs[], + char *vals[], int len, - const char *node) + const char *node) { ListIterator attrlist_itr = NULL; ListIterator attrvals_itr = NULL; @@ -756,20 +756,20 @@ genders_getattr(genders_t handle, __list_iterator_create(attrvals_itr, avc->attrvals); while ((av = list_next(attrvals_itr))) - { - if (_genders_put_in_array(handle, av->attr, attrs, index, len) < 0) - goto cleanup; - - if (vals && av->val) - { - char *valptr; - if (_genders_get_valptr(handle, n, av, &valptr, NULL) < 0) - goto cleanup; - if (_genders_put_in_array(handle, valptr, vals, index, len) < 0) - goto cleanup; - } - index++; - } + { + if (_genders_put_in_array(handle, av->attr, attrs, index, len) < 0) + goto cleanup; + + if (vals && av->val) + { + char *valptr; + if (_genders_get_valptr(handle, n, av, &valptr, NULL) < 0) + goto cleanup; + if (_genders_put_in_array(handle, valptr, vals, index, len) < 0) + goto cleanup; + } + index++; + } __list_iterator_destroy(attrvals_itr); } attrvals_itr = NULL; @@ -808,7 +808,7 @@ genders_getattr_all(genders_t handle, char *attrs[], int len) while ((attr = list_next(attrslist_itr))) { if (_genders_put_in_array(handle, attr, attrs, index++, len) < 0) - goto cleanup; + goto cleanup; } rv = index; @@ -820,10 +820,10 @@ genders_getattr_all(genders_t handle, char *attrs[], int len) int genders_testattr(genders_t handle, - const char *node, - const char *attr, + const char *node, + const char *attr, char *val, - int len) + int len) { genders_node_t n; genders_attrval_t av; @@ -860,22 +860,22 @@ genders_testattr(genders_t handle, if (av) { if (val) - { - if (av->val) - { - char *valptr; - if (_genders_get_valptr(handle, n, av, &valptr, NULL) < 0) - return -1; - if ((strlen(valptr) + 1) > len) - { - handle->errnum = GENDERS_ERR_OVERFLOW; - return -1; - } - strcpy(val, valptr); - } - else - memset(val, '\0', len); - } + { + if (av->val) + { + char *valptr; + if (_genders_get_valptr(handle, n, av, &valptr, NULL) < 0) + return -1; + if ((strlen(valptr) + 1) > len) + { + handle->errnum = GENDERS_ERR_OVERFLOW; + return -1; + } + strcpy(val, valptr); + } + else + memset(val, '\0', len); + } } handle->errnum = GENDERS_ERR_SUCCESS; @@ -884,9 +884,9 @@ genders_testattr(genders_t handle, int genders_testattrval(genders_t handle, - const char *node, + const char *node, const char *attr, - const char *val) + const char *val) { genders_node_t n; genders_attrval_t av; @@ -998,9 +998,9 @@ genders_isattrval(genders_t handle, const char *attr, const char *val) && !strcmp(handle->attrval_index_attr, attr)) { if (!hash_find(handle->attrval_index, val)) - rv = 0; + rv = 0; else - rv = 1; + rv = 1; handle->errnum = GENDERS_ERR_SUCCESS; return rv; @@ -1017,16 +1017,16 @@ genders_isattrval(genders_t handle, const char *attr, const char *val) __list_iterator_create(nodeslist_itr, l); while ((n = list_next(nodeslist_itr))) - { - if (_genders_find_attrval(handle, n, attr, val, &av) < 0) - goto cleanup; - if (av) - { - rv = 1; - handle->errnum = GENDERS_ERR_SUCCESS; - goto cleanup; - } - } + { + if (_genders_find_attrval(handle, n, attr, val, &av) < 0) + goto cleanup; + if (av) + { + rv = 1; + handle->errnum = GENDERS_ERR_SUCCESS; + goto cleanup; + } + } } out: @@ -1100,47 +1100,47 @@ genders_index_attrvals(genders_t handle, const char *attr) genders_attrval_t av; if (_genders_find_attrval(handle, n, attr, NULL, &av) < 0) - goto cleanup; + goto cleanup; if (av) - { - char *valptr; - - if (av->val) - { - if (_genders_get_valptr(handle, - n, - av, - &valptr, - &subst_occurred) < 0) - goto cleanup; - } - else - valptr = GENDERS_NOVALUE; - - if (!(l = hash_find(attrval_index, valptr))) - { - __list_create(l, NULL); - - /* If a substitution occurred, we cannot use the av->val - * pointer as the key, b/c the key contains some nonsense - * characters (i.e. %n). So we have to copy this buffer and - * store it somewhere to be freed later. - */ - if (subst_occurred) - { - __xstrdup(valbuf, valptr); - __list_append(attrval_buflist, valbuf); - valptr = valbuf; - valbuf = NULL; - } - - __hash_insert(attrval_index, valptr, l); - } - - __list_append(l, n); - l = NULL; - } + { + char *valptr; + + if (av->val) + { + if (_genders_get_valptr(handle, + n, + av, + &valptr, + &subst_occurred) < 0) + goto cleanup; + } + else + valptr = GENDERS_NOVALUE; + + if (!(l = hash_find(attrval_index, valptr))) + { + __list_create(l, NULL); + + /* If a substitution occurred, we cannot use the av->val + * pointer as the key, b/c the key contains some nonsense + * characters (i.e. %n). So we have to copy this buffer and + * store it somewhere to be freed later. + */ + if (subst_occurred) + { + __xstrdup(valbuf, valptr); + __list_append(attrval_buflist, valbuf); + valptr = valbuf; + valbuf = NULL; + } + + __hash_insert(attrval_index, valptr, l); + } + + __list_append(l, n); + l = NULL; + } } __xstrdup(attrval_index_attr, attr); @@ -1208,21 +1208,21 @@ genders_parse(genders_t handle, const char *filename, FILE *stream) (hash_del_f)list_destroy); if ((errcount = _genders_open_and_parse(handle, - filename, - &debugnumattrs, - &debugmaxattrs, - &debugmaxnodelen, - &debugmaxattrlen, - &debugmaxvallen, - debugnodeslist, - debugattrvalslist, - debugattrslist, + filename, + &debugnumattrs, + &debugmaxattrs, + &debugmaxnodelen, + &debugmaxattrlen, + &debugmaxvallen, + debugnodeslist, + debugattrvalslist, + debugattrslist, &(debugnode_index), &(debugnode_index_size), &(debugattr_index), &(debugattr_index_size), - 1, - stream)) < 0) + 1, + stream)) < 0) goto cleanup; rv = errcount; @@ -1282,12 +1282,12 @@ _genders_copy_nodeslist(genders_t handle, genders_t handlecopy) if (rv < 0) { if (newn) - { - free(newn->name); - __list_destroy(newn->attrlist); - __hash_destroy(newn->attrlist_index); - free(newn); - } + { + free(newn->name); + __list_destroy(newn->attrlist); + __hash_destroy(newn->attrlist_index); + free(newn); + } } __list_iterator_destroy(itr); return rv; @@ -1342,23 +1342,23 @@ _genders_copy_attrvalslist(genders_t handle, genders_t handlecopy) __list_iterator_create(attrvalsitr, avc->attrvals); __xmalloc(newavc, - genders_attrvals_container_t, - sizeof(struct genders_attrvals_container)); + genders_attrvals_container_t, + sizeof(struct genders_attrvals_container)); __list_create(newavc->attrvals, _genders_list_free_genders_attrval); newavc->index = avc->index; while ((av = list_next(attrvalsitr))) - { - __xmalloc(newav, genders_attrval_t, sizeof(struct genders_attrval)); - __xstrdup(newav->attr, av->attr); - if (av->val) - __xstrdup(newav->val, av->val); - else - newav->val = NULL; - newav->val_contains_subst = av->val_contains_subst; - __list_append(newavc->attrvals, newav); - newav = NULL; - } + { + __xmalloc(newav, genders_attrval_t, sizeof(struct genders_attrval)); + __xstrdup(newav->attr, av->attr); + if (av->val) + __xstrdup(newav->val, av->val); + else + newav->val = NULL; + newav->val_contains_subst = av->val_contains_subst; + __list_append(newavc->attrvals, newav); + newav = NULL; + } __list_append(handlecopy->attrvalslist, newavc); newavc = NULL; @@ -1369,16 +1369,16 @@ _genders_copy_attrvalslist(genders_t handle, genders_t handlecopy) if (rv < 0) { if (newav) - { - free(newav->attr); - free(newav->val); - free(newav); - } + { + free(newav->attr); + free(newav->val); + free(newav); + } if (newavc) - { - __list_destroy(newavc->attrvals); - free(newavc); - } + { + __list_destroy(newavc->attrvals); + free(newavc); + } } __list_iterator_destroy(attrvalslistitr); __list_iterator_destroy(attrvalsitr); @@ -1451,8 +1451,8 @@ static int _genders_copy_fill_attr_index(genders_t handle, genders_t handlecopy) */ static genders_attrvals_container_t _genders_copy_find_attrvals_container(genders_t handle, - genders_t handlecopy, - unsigned int index) + genders_t handlecopy, + unsigned int index) { ListIterator attrvalsitr = NULL; genders_attrvals_container_t rv = NULL; @@ -1462,10 +1462,10 @@ _genders_copy_find_attrvals_container(genders_t handle, while ((avc = list_next(attrvalsitr))) { if (avc->index == index) - { - rv = avc; - goto cleanup; - } + { + rv = avc; + goto cleanup; + } } cleanup: @@ -1481,9 +1481,9 @@ _genders_copy_find_attrvals_container(genders_t handle, */ static int _genders_copy_fill_node(genders_t handle, - genders_t handlecopy, - genders_node_t nodehandle, - genders_node_t nodecopy) + genders_t handlecopy, + genders_node_t nodehandle, + genders_node_t nodecopy) { ListIterator attrlistitr = NULL; ListIterator attrvalsitr = NULL; @@ -1497,29 +1497,29 @@ _genders_copy_fill_node(genders_t handle, genders_attrval_t av; if (!(tmpavc = _genders_copy_find_attrvals_container(handle, - handlecopy, - avc->index))) - goto cleanup; + handlecopy, + avc->index))) + goto cleanup; __list_append(nodecopy->attrlist, tmpavc); __list_iterator_create(attrvalsitr, tmpavc->attrvals); while ((av = list_next(attrvalsitr))) - { - List l; + { + List l; - __hash_insert(nodecopy->attrlist_index, - av->attr, - tmpavc); + __hash_insert(nodecopy->attrlist_index, + av->attr, + tmpavc); - if (!(l = hash_find(handlecopy->attr_index, av->attr))) - { - handle->errnum = GENDERS_ERR_INTERNAL; - goto cleanup; - } + if (!(l = hash_find(handlecopy->attr_index, av->attr))) + { + handle->errnum = GENDERS_ERR_INTERNAL; + goto cleanup; + } - __list_append(l, nodecopy); - } + __list_append(l, nodecopy); + } __list_iterator_destroy(attrvalsitr); attrvalsitr = NULL; @@ -1551,17 +1551,17 @@ _genders_copy_fill_node_data(genders_t handle, genders_t handlecopy) genders_node_t nodehandle; if (!(nodehandle = hash_find(handle->node_index, nodecopy->name))) - { - /* Shouldn't be possible to error here */ - handle->errnum = GENDERS_ERR_INTERNAL; - goto cleanup; - } + { + /* Shouldn't be possible to error here */ + handle->errnum = GENDERS_ERR_INTERNAL; + goto cleanup; + } if (_genders_copy_fill_node(handle, - handlecopy, - nodehandle, - nodecopy) < 0) - goto cleanup; + handlecopy, + nodehandle, + nodecopy) < 0) + goto cleanup; } rv = 0; @@ -1638,10 +1638,10 @@ genders_copy(genders_t handle) if (handle->attrval_index) { if (genders_index_attrvals(handlecopy, handle->attrval_index_attr) < 0) - { - handle->errnum = GENDERS_ERR_INTERNAL; - goto cleanup; - } + { + handle->errnum = GENDERS_ERR_INTERNAL; + goto cleanup; + } } handle->errnum = GENDERS_ERR_SUCCESS; diff --git a/src/libgenders/genders.h.in b/src/libgenders/genders.h.in index 3fb9b0c..b73cc17 100644 --- a/src/libgenders/genders.h.in +++ b/src/libgenders/genders.h.in @@ -297,10 +297,10 @@ int genders_getnodename(genders_t handle, char *node, int len); * Returns number of matches on success, -1 on failure */ int genders_getnodes(genders_t handle, - char *nodes[], - int len, + char *nodes[], + int len, const char *attr, - const char *val); + const char *val); /* * genders_getattr @@ -312,10 +312,10 @@ int genders_getnodes(genders_t handle, * Returns number of matches on success, -1 on failure */ int genders_getattr(genders_t handle, - char *attrs[], - char *vals[], + char *attrs[], + char *vals[], int len, - const char *node); + const char *node); /* * genders_getattr_all @@ -336,10 +336,10 @@ int genders_getattr_all(genders_t handle, char *attrs[], int len); * Returns 1=true, 0=false, -1=failure */ int genders_testattr(genders_t handle, - const char *node, + const char *node, const char *attr, - char *val, - int len); + char *val, + int len); /* * genders_testattrval @@ -350,9 +350,9 @@ int genders_testattr(genders_t handle, * Returns 1=true, 0=false, -1=failure */ int genders_testattrval(genders_t handle, - const char *node, + const char *node, const char *attr, - const char *val); + const char *val); /* * genders_isnode @@ -424,7 +424,7 @@ int genders_query(genders_t handle, char *nodes[], int len, const char *query); * Returns 1=true, 0=false, -1=failure */ int genders_testquery(genders_t handle, - const char *node, + const char *node, const char *query); /* diff --git a/src/libgenders/genders_parsing.c b/src/libgenders/genders_parsing.c index 17a4b80..3a29bb8 100644 --- a/src/libgenders/genders_parsing.c +++ b/src/libgenders/genders_parsing.c @@ -124,7 +124,7 @@ _insert_attrval(genders_t handle, genders_attrvals_container_t avc, char *attr, { __xstrdup(av->val, val); if (strstr(av->val, "%n") || strstr(av->val, "%%")) - av->val_contains_subst = 1; + av->val_contains_subst = 1; } else av->val = NULL; @@ -151,7 +151,7 @@ _insert_attrval(genders_t handle, genders_attrvals_container_t avc, char *attr, */ static int _insert_attr(genders_t handle, - List attrslist, + List attrslist, hash_t *attr_index, int *attr_index_size, char *attr) @@ -220,17 +220,17 @@ _attr_node_processing(genders_t handle, */ /* Check attribute already listed for this node and on same line */ if (hash_find(n->attrlist_index, av->attr) - || list_find_first(tmpattrlist, _genders_list_is_str, av->attr)) - { - if (line_num > 0) - { - fprintf(stream, "Line %d: duplicate attribute \"%s\" listed for node \"%s\"\n", - line_num, av->attr, n->name); - rv = 1; - } - handle->errnum = GENDERS_ERR_PARSE; - goto cleanup; - } + || list_find_first(tmpattrlist, _genders_list_is_str, av->attr)) + { + if (line_num > 0) + { + fprintf(stream, "Line %d: duplicate attribute \"%s\" listed for node \"%s\"\n", + line_num, av->attr, n->name); + rv = 1; + } + handle->errnum = GENDERS_ERR_PARSE; + goto cleanup; + } __list_append(tmpattrlist, av->attr); } @@ -245,16 +245,16 @@ _attr_node_processing(genders_t handle, * iteration by not using it. */ if (hash_find(n->attrlist_index, av->attr)) - { - if (line_num > 0) - { - fprintf(stream, "Line %d: duplicate attribute \"%s\" listed for node \"%s\"\n", - line_num, av->attr, n->name); - rv = 1; - } - handle->errnum = GENDERS_ERR_PARSE; - goto cleanup; - } + { + if (line_num > 0) + { + fprintf(stream, "Line %d: duplicate attribute \"%s\" listed for node \"%s\"\n", + line_num, av->attr, n->name); + rv = 1; + } + handle->errnum = GENDERS_ERR_PARSE; + goto cleanup; + } } list_iterator_reset(attrvals_itr); @@ -357,22 +357,22 @@ strsep (char **stringp, const char *delim) */ static int _parse_line(genders_t handle, - int *numattrs, - int *maxattrs, - int *maxnodelen, - int *maxattrlen, - int *maxvallen, - List nodeslist, - List attrvalslist, - List attrslist, + int *numattrs, + int *maxattrs, + int *maxnodelen, + int *maxattrlen, + int *maxvallen, + List nodeslist, + List attrvalslist, + List attrslist, hash_t *node_index, int *node_index_size, hash_t *attr_index, int *attr_index_size, char *line, - int line_num, - FILE *stream, - int *parsed_nodes) + int line_num, + FILE *stream, + int *parsed_nodes) { char *temp, *nodenames, *node = NULL; int max_n_subst_vallen = 0, line_maxnodelen = 0, rv = -1; @@ -389,9 +389,9 @@ _parse_line(genders_t handle, for (--temp; temp >= line; temp--) { if (isspace(*temp)) - *temp = '\0'; + *temp = '\0'; else - break; + break; } /* empty line */ @@ -416,39 +416,39 @@ _parse_line(genders_t handle, /* move forward to attributes */ while(isspace(*line)) - line++; + line++; /* *line == '\0' means line has no attributes */ if (*line != '\0') - { + { int insert_count; - if (strchr(line,' ') || strchr(line,'\t')) - { - if (line_num > 0) - { - fprintf(stream, "Line %d: white space in attribute list\n", line_num); - rv = 1; - } - handle->errnum = GENDERS_ERR_PARSE; - goto cleanup; - } - - __xmalloc(avc, - genders_attrvals_container_t, - sizeof(struct genders_attrvals_container)); - __list_create(avc->attrvals, _genders_list_free_genders_attrval); - avc->index = list_count(handle->attrvalslist); - - /* parse attributes */ - attr = strsep(&line, ","); - while (attr) - { - char *val = NULL; - - /* parse value out of attribute */ - if ((val = strchr(attr,'='))) - *val++ = '\0'; + if (strchr(line,' ') || strchr(line,'\t')) + { + if (line_num > 0) + { + fprintf(stream, "Line %d: white space in attribute list\n", line_num); + rv = 1; + } + handle->errnum = GENDERS_ERR_PARSE; + goto cleanup; + } + + __xmalloc(avc, + genders_attrvals_container_t, + sizeof(struct genders_attrvals_container)); + __list_create(avc->attrvals, _genders_list_free_genders_attrval); + avc->index = list_count(handle->attrvalslist); + + /* parse attributes */ + attr = strsep(&line, ","); + while (attr) + { + char *val = NULL; + + /* parse value out of attribute */ + if ((val = strchr(attr,'='))) + *val++ = '\0'; #if 0 /* Remove this check, we will leave this as a "feature" */ @@ -459,33 +459,33 @@ _parse_line(genders_t handle, fprintf(stream, "Line %d: value contains equal sign\n", line_num); rv = 1; } - handle->errnum = GENDERS_ERR_PARSE; - goto cleanup; + handle->errnum = GENDERS_ERR_PARSE; + goto cleanup; } #endif - if (!strlen(attr)) - { - if (line_num > 0) - { - fprintf(stream, "Line %d: empty string attribute listed\n", line_num); - rv = 1; - } - handle->errnum = GENDERS_ERR_PARSE; - goto cleanup; - } - - if (val && !strlen(val)) - { - if (line_num > 0) - { - fprintf(stream, "Line %d: no value specified for attribute \"%s\"\n", - line_num, attr); - rv = 1; - } - handle->errnum = GENDERS_ERR_PARSE; - goto cleanup; - } + if (!strlen(attr)) + { + if (line_num > 0) + { + fprintf(stream, "Line %d: empty string attribute listed\n", line_num); + rv = 1; + } + handle->errnum = GENDERS_ERR_PARSE; + goto cleanup; + } + + if (val && !strlen(val)) + { + if (line_num > 0) + { + fprintf(stream, "Line %d: no value specified for attribute \"%s\"\n", + line_num, attr); + rv = 1; + } + handle->errnum = GENDERS_ERR_PARSE; + goto cleanup; + } /* achu: No need to check if there are duplicate * attributes within this line of the file. Will be @@ -493,43 +493,43 @@ _parse_line(genders_t handle, * node below. */ - if (_insert_attrval(handle, avc, attr, val) < 0) - goto cleanup; + if (_insert_attrval(handle, avc, attr, val) < 0) + goto cleanup; if ((insert_count = _insert_attr(handle, - attrslist, + attrslist, attr_index, attr_index_size, attr)) < 0) goto cleanup; - if (!line_num) - { - (*numattrs) += insert_count; - (*maxattrlen) = GENDERS_MAX(strlen(attr), (*maxattrlen)); - - if (val) - { - if (strstr(val, "%n") && !strstr(val, "%%n")) - max_n_subst_vallen = strlen(val); - else - (*maxvallen) = GENDERS_MAX(strlen(val), (*maxvallen)); - } - } - - attr = strsep(&line, ","); - } - } + if (!line_num) + { + (*numattrs) += insert_count; + (*maxattrlen) = GENDERS_MAX(strlen(attr), (*maxattrlen)); + + if (val) + { + if (strstr(val, "%n") && !strstr(val, "%%n")) + max_n_subst_vallen = strlen(val); + else + (*maxvallen) = GENDERS_MAX(strlen(val), (*maxvallen)); + } + } + + attr = strsep(&line, ","); + } + } } #ifndef WITH_NON_SHORTENED_HOSTNAMES if (strchr(nodenames, '.')) { if (line_num > 0) - { - fprintf(stream, "Line %d: node not a shortened hostname\n", line_num); - rv = 1; - } + { + fprintf(stream, "Line %d: node not a shortened hostname\n", line_num); + rv = 1; + } handle->errnum = GENDERS_ERR_PARSE; goto cleanup; } @@ -540,10 +540,10 @@ _parse_line(genders_t handle, if (!hostlist_push(hl, nodenames)) { if (line_num > 0) - { - fprintf(stream, "Line %d: incorrectly specified nodename(s)\n", line_num); - rv = 1; - } + { + fprintf(stream, "Line %d: incorrectly specified nodename(s)\n", line_num); + rv = 1; + } handle->errnum = GENDERS_ERR_PARSE; goto cleanup; } @@ -555,43 +555,43 @@ _parse_line(genders_t handle, genders_node_t n; if (strlen(node) > GENDERS_MAXHOSTNAMELEN) - { - if (line_num > 0) - { - fprintf(stream, "Line %d: hostname too long\n", line_num); - rv = 1; - } - handle->errnum = GENDERS_ERR_PARSE; - goto cleanup; - } + { + if (line_num > 0) + { + fprintf(stream, "Line %d: hostname too long\n", line_num); + rv = 1; + } + handle->errnum = GENDERS_ERR_PARSE; + goto cleanup; + } if (!(n = _insert_node(handle, nodeslist, node_index, node_index_size, node))) - goto cleanup; + goto cleanup; if (avc) - { - if ((rv = _attr_node_processing(handle, + { + if ((rv = _attr_node_processing(handle, n, avc, attr_index, line_num, stream)) != 0) - goto cleanup; + goto cleanup; __list_append(n->attrlist, avc); - n->attrcount += list_count(avc->attrvals); - } + n->attrcount += list_count(avc->attrvals); + } if (!line_num) - { - (*maxattrs) = GENDERS_MAX(n->attrcount, (*maxattrs)); - (*maxnodelen) = GENDERS_MAX(strlen(node), (*maxnodelen)); - line_maxnodelen = GENDERS_MAX(strlen(node), line_maxnodelen); - } + { + (*maxattrs) = GENDERS_MAX(n->attrcount, (*maxattrs)); + (*maxnodelen) = GENDERS_MAX(strlen(node), (*maxnodelen)); + line_maxnodelen = GENDERS_MAX(strlen(node), line_maxnodelen); + } free(node); } @@ -600,7 +600,7 @@ _parse_line(genders_t handle, /* %n substitution found on this line, update maxvallen */ if (!line_num && max_n_subst_vallen) (*maxvallen) = GENDERS_MAX(max_n_subst_vallen - 2 + line_maxnodelen, - (*maxvallen)); + (*maxvallen)); /* Append at the very end, so cleanup area cleaner */ if (avc) @@ -624,21 +624,21 @@ _parse_line(genders_t handle, int _genders_open_and_parse(genders_t handle, - const char *filename, - int *numattrs, - int *maxattrs, - int *maxnodelen, - int *maxattrlen, - int *maxvallen, - List nodeslist, - List attrvalslist, - List attrslist, + const char *filename, + int *numattrs, + int *maxattrs, + int *maxnodelen, + int *maxattrlen, + int *maxvallen, + List nodeslist, + List attrvalslist, + List attrslist, hash_t *node_index, int *node_index_size, hash_t *attr_index, int *attr_index_size, - int debug, - FILE *stream) + int debug, + FILE *stream) { /* achu: 'parsed_nodes' is no longer needed, but leave it here if we * change our minds later concerning whether and empty genders file @@ -673,30 +673,30 @@ _genders_open_and_parse(genders_t handle, } if ((bug_count = _parse_line(handle, - numattrs, - maxattrs, - maxnodelen, - maxattrlen, - maxvallen, - nodeslist, - attrvalslist, - attrslist, + numattrs, + maxattrs, + maxnodelen, + maxattrlen, + maxvallen, + nodeslist, + attrvalslist, + attrslist, node_index, node_index_size, attr_index, attr_index_size, - buf, - (debug) ? line_count : 0, - stream, - &parsed_nodes)) < 0) - goto cleanup; + buf, + (debug) ? line_count : 0, + stream, + &parsed_nodes)) < 0) + goto cleanup; if (debug) - { - if (bug_count) - errcount++; - line_count++; - } + { + if (bug_count) + errcount++; + line_count++; + } } if (!feof(f)) @@ -708,11 +708,11 @@ _genders_open_and_parse(genders_t handle, if (len < 0) { if (debug && handle->errnum == GENDERS_ERR_OVERFLOW) - { - fprintf(stream, "Line %d: exceeds maximum allowed length\n", line_count); - rv = ++errcount; - handle->errnum = GENDERS_ERR_PARSE; - } + { + fprintf(stream, "Line %d: exceeds maximum allowed length\n", line_count); + rv = ++errcount; + handle->errnum = GENDERS_ERR_PARSE; + } goto cleanup; } @@ -726,16 +726,16 @@ _genders_open_and_parse(genders_t handle, if (list_count(nodeslist) == 0) { if (debug) - { - fprintf(stream, "No nodes successfully parsed\n"); - - /* Only increase the parse error count if the file is truly - * empty. - */ - if (!parsed_nodes) - errcount++; - rv = errcount; - } + { + fprintf(stream, "No nodes successfully parsed\n"); + + /* Only increase the parse error count if the file is truly + * empty. + */ + if (!parsed_nodes) + errcount++; + rv = errcount; + } handle->errnum = GENDERS_ERR_PARSE; goto cleanup; } diff --git a/src/libgenders/genders_parsing.h b/src/libgenders/genders_parsing.h index 9047e75..7b901f0 100644 --- a/src/libgenders/genders_parsing.h +++ b/src/libgenders/genders_parsing.h @@ -43,20 +43,20 @@ * Returns 0 on success, -1 on error */ int _genders_open_and_parse(genders_t handle, - const char *filename, - int *numattrs, - int *maxattrs, - int *maxnodelen, - int *maxattrlen, - int *maxvallen, - List nodeslist, - List attrvalslist, - List attrslist, + const char *filename, + int *numattrs, + int *maxattrs, + int *maxnodelen, + int *maxattrlen, + int *maxvallen, + List nodeslist, + List attrvalslist, + List attrslist, hash_t *node_index, int *node_index_size, hash_t *attr_index, int *attr_index_size, - int debug, - FILE *stream); + int debug, + FILE *stream); #endif /* _GENDERS_PARSING_H */ diff --git a/src/libgenders/genders_util.c b/src/libgenders/genders_util.c index c464dd1..d4e9a33 100644 --- a/src/libgenders/genders_util.c +++ b/src/libgenders/genders_util.c @@ -139,10 +139,10 @@ _genders_loaded_handle_error_check(genders_t handle) int _genders_put_in_array(genders_t handle, - char *str, - char **list, - int index, - int len) + char *str, + char **list, + int index, + int len) { if (index >= len) { @@ -162,10 +162,10 @@ _genders_put_in_array(genders_t handle, int _genders_get_valptr(genders_t handle, - genders_node_t n, - genders_attrval_t av, - char **val, - int *subst_occurred) + genders_node_t n, + genders_attrval_t av, + char **val, + int *subst_occurred) { char *valptr, *nodenameptr, *valbufptr; @@ -173,7 +173,7 @@ _genders_get_valptr(genders_t handle, || (handle->flags & GENDERS_FLAG_RAW_VALUES)) { if (subst_occurred) - *subst_occurred = 0; + *subst_occurred = 0; *val = av->val; return 0; } @@ -184,31 +184,31 @@ _genders_get_valptr(genders_t handle, while (*valptr != '\0') { if (*valptr == '%') - { - if ((*(valptr + 1)) == '%') - { - *(valbufptr)++ = '%'; - valptr++; - } - else if ((*(valptr + 1)) == 'n') - { - if ((strlen(av->val) - 2 + strlen(n->name)) > - (handle->maxvallen + 1)) - { - handle->errnum = GENDERS_ERR_INTERNAL; - return -1; - } - - nodenameptr = n->name; - while (*nodenameptr != '\0') - *(valbufptr)++ = *nodenameptr++; - valptr++; - } - else - *(valbufptr)++ = *valptr; - } + { + if ((*(valptr + 1)) == '%') + { + *(valbufptr)++ = '%'; + valptr++; + } + else if ((*(valptr + 1)) == 'n') + { + if ((strlen(av->val) - 2 + strlen(n->name)) > + (handle->maxvallen + 1)) + { + handle->errnum = GENDERS_ERR_INTERNAL; + return -1; + } + + nodenameptr = n->name; + while (*nodenameptr != '\0') + *(valbufptr)++ = *nodenameptr++; + valptr++; + } + else + *(valbufptr)++ = *valptr; + } else - *(valbufptr)++ = *valptr; + *(valbufptr)++ = *valptr; valptr++; } @@ -221,10 +221,10 @@ _genders_get_valptr(genders_t handle, int _genders_find_attrval(genders_t handle, - genders_node_t n, - const char *attr, - const char *val, - genders_attrval_t *avptr) + genders_node_t n, + const char *attr, + const char *val, + genders_attrval_t *avptr) { genders_attrvals_container_t avc; int retval = -1; @@ -236,28 +236,28 @@ _genders_find_attrval(genders_t handle, genders_attrval_t av; if ((av = list_find_first(avc->attrvals, - _genders_list_is_attr_in_attrvals, - (char *)attr))) - { - if (!val) - { - *avptr = av; + _genders_list_is_attr_in_attrvals, + (char *)attr))) + { + if (!val) + { + *avptr = av; goto out; - } - else if (av->val) - { - char *valptr; + } + else if (av->val) + { + char *valptr; - if (_genders_get_valptr(handle, n, av, &valptr, NULL) < 0) - goto cleanup; + if (_genders_get_valptr(handle, n, av, &valptr, NULL) < 0) + goto cleanup; - if (!strcmp(valptr, val)) - { - *avptr = av; + if (!strcmp(valptr, val)) + { + *avptr = av; goto out; - } - } - } + } + } + } } out: @@ -327,8 +327,8 @@ _genders_rehash(genders_t handle, int _genders_hash_copy(genders_t handle, - hash_t *hash_src, - hash_t *hash_dest) + hash_t *hash_src, + hash_t *hash_dest) { int hash_num; int retval = -1; diff --git a/src/libgenders/genders_util.h b/src/libgenders/genders_util.h index 196d912..5733b33 100644 --- a/src/libgenders/genders_util.h +++ b/src/libgenders/genders_util.h @@ -216,10 +216,10 @@ int _genders_loaded_handle_error_check(genders_t handle); * Return 0 on success, -1 on error */ int _genders_put_in_array(genders_t handle, - char *str, - char **list, - int index, - int len); + char *str, + char **list, + int index, + int len); /* * _genders_get_valptr @@ -229,10 +229,10 @@ int _genders_put_in_array(genders_t handle, * Return 0 on success, -1 on error */ int _genders_get_valptr(genders_t handle, - genders_node_t n, - genders_attrval_t av, - char **val, - int *subst_occurred); + genders_node_t n, + genders_attrval_t av, + char **val, + int *subst_occurred); /* * _genders_find_attrval @@ -242,10 +242,10 @@ int _genders_get_valptr(genders_t handle, * Return 0 on success, -1 on error */ int _genders_find_attrval(genders_t handle, - genders_node_t n, - const char *attr, - const char *val, - genders_attrval_t *avptr); + genders_node_t n, + const char *attr, + const char *val, + genders_attrval_t *avptr); /* * _genders_rehash @@ -267,7 +267,7 @@ int _genders_rehash(genders_t handle, * Returns 0 on success, -1 on error. */ int _genders_hash_copy(genders_t handle, - hash_t *hash_src, - hash_t *hash_dest); + hash_t *hash_src, + hash_t *hash_dest); #endif /* _GENDERS_COMMON_H */