Changeset b4dadda in freewrt


Ignore:
Timestamp:
Feb 25, 2007, 2:36:31 AM (19 years ago)
Author:
Phil Sutter <n0-1@…>
Children:
c41c20f
Parents:
757c610
Message:
  • propset on testpkg to ignore generated files
  • many fixes, thx to tg@
  • dynamic mem mgmt fixed using valgrind

git-svn-id: svn://www.freewrt.org/trunk/freewrt@2096 afb5a338-a214-0410-bd46-81f09a774fd1

Location:
tools/nfotizer
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • tools/nfotizer/Makefile

    r757c610 rb4dadda  
    22OBJECTS=        $(patsubst %.c,%.o,$(wildcard *.c))
    33HEADERS=        $(wildcard *.h)
    4 CFLAGS?=        -Wall
     4CFLAGS+=        -Wall -Wextra -Wunused -Wdeclaration-after-statement -Wundef \
     5                -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast \
     6                -Wcast-qual -Wcast-align -Wwrite-strings -Wstrict-prototypes \
     7                -Wold-style-definition -Wmissing-prototypes -Winline \
     8                -Wmissing-declarations -Wmissing-noreturn -pedantic -std=gnu99 \
     9                -Wmissing-format-attribute -Wredundant-decls
     10#               -Wno-variadic-macros -Werror
    511CC?=            gcc
    612
    713ifneq (${DEBUG},)
    8 CFLAGS+=        -g -DDEBUG
     14CFLAGS+=        -g
    915else
    1016CFLAGS+=        -Os
    1117endif
    1218
    13 all: $(TARGET)
     19ifneq (${VERBOSE},)
     20CFLAGS+=        -DDEBUG
     21endif
     22
     23all: ${TARGET}
    1424
    1525debug:
    1626        make DEBUG=1
     27
    1728clean:
    18         -rm -f $(OBJECTS)
     29        -rm -f ${OBJECTS}
    1930
    2031distclean: clean
    21         -rm -f $(TARGET) $(TESTS)
     32        -rm -f ${TARGET} ${TESTS}
    2233
    23 $(TARGET): $(OBJECTS)
    24         $(CC) -o $@ $^
    25 
    26 %.o: %.c $(HEADERS)
    27         $(CC) $(CFLAGS) -c $<
     34${TARGET}: ${OBJECTS}
     35        ${CC} ${LDFLAGS} -o $@ $^
    2836
    2937.PHONY: all debug clean distclean
  • tools/nfotizer/filedefs.c

    r757c610 rb4dadda  
    55 * Field 1: The name of the file.
    66 * Field 2: The format of the file. */
    7 char *ipkg[] = { "#", "#NAME#.control",
     7const char *ipkg[] = { "#", "#NAME#.control",
    88        "Package: #NAME#\n"
    99        "Priority: #PRIO#\n"
     
    1212        "Description: #DESCR_LINE#\n"
    1313};
    14 char *config[] = { "#", "Config.in",
     14const char *config[] = { "#", "Config.in",
    1515        "config #SYM#\n"
    1616        "\t#SYM_SCOPE# \"#NAME# .......................... #DESCR_LINE#\"\n"
     
    1919        "#DESCR#\n"
    2020};
    21 char *makefile[] = { "@", "vars.mk",
     21const char *makefile[] = { "@", "vars.mk",
    2222        "PKG_NAME:=             @NAME@\n"
    2323        "PKG_VERSION:=          @VERSION@\n"
     
    2929        "PKG_SOURCE:=           @SRC_NAME@\n"
    3030};
     31
    3132/* To enable generating of a file defined above, add it to this variable: */
    32 char **filedefs[] = { ipkg, config, makefile, NULL};
    33 
     33const char **filedefs[] = { ipkg, config, makefile, NULL };
  • tools/nfotizer/hash.c

    r757c610 rb4dadda  
    11#include "nfotizer.h"
     2#include <stdlib.h>             /* malloc */
     3#include <string.h>             /* strcmp */
    24
    35/* Create a new hash table.
    46 * This initially holds size elements,
    57 * but is dynamically growing. */
    6 htab *htab_create(int size)
     8struct htab *
     9htab_create(int size)
    710{
    8         htab *table = malloc(sizeof(htab));
     11        struct htab *table = malloc(sizeof(struct htab));
    912        table->size = size;
    10         table->data = calloc(size, sizeof(entry));
     13        table->data = calloc(size, sizeof(struct entry));
    1114        table->items = 0;
    1215        return table;
     
    1417
    1518/* destroy a hash table, freeing it's space */
    16 void htab_destroy(htab *tab)
     19void
     20htab_destroy(struct htab *tab)
    1721{
    18         free(tab->data);
    19         free(tab);
     22        int i = 0;
     23        for (; i < tab->size; i++) {
     24                zap(tab->data[i].key);
     25                zap(tab->data[i].val);
     26        }
     27        zap(tab->data);
     28        zap(tab);
    2029}
    2130
    2231/* return the index of key in the hash table tab or -1 if not found */
    23 int htab_indexof(char *key, htab tab)
     32int
     33htab_indexof(char *key, struct htab tab)
    2434{
    25         int i=0;
    26         for(;i<tab.items;i++) {
    27                 if(!strcmp(key, tab.data[i].key)) {
    28                         //debug("htab_indexof(): found \"%s\" at %i\n", key, i);
     35        int i = 0;
     36        for (; i < tab.items; i++) {
     37                if (!strcmp(key, tab.data[i].key)) {
     38                        DBG("struct htab_indexof(): found \"%s\" at %i", key, i);
    2939                        return i;
    3040                }
     
    3444
    3545/* return the value of key in tab */
    36 char *htab_get(char *key, htab tab)
     46char *
     47htab_get(char *key, struct htab tab)
    3748{
    3849        int i;
    39         if((i=htab_indexof(key, tab))>=0)
     50        if ((i = htab_indexof(key, tab)) >= 0)
    4051                return strdup(tab.data[i].val);
    4152        else
     
    4455
    4556/* insert key with value val into tab */
    46 int htab_put(char *key, char *val, htab *tab)
     57int
     58htab_put(char *key, char *val, struct htab *tab)
    4759{
    48         if(htab_indexof(key, *tab)>=0)
     60        if (htab_indexof(key, *tab) >= 0)
    4961                return -1;
    50         if(tab->items == tab->size) {
     62        if (tab->items == tab->size) {
    5163                tab->size = tab->size << 2;
    52                 debug("resizing haash to %i items\n", tab->size);
     64                DBG("resizing hash to %i items", tab->size);
    5365                tab->data = realloc(tab->data, tab->size);
    5466        }
    5567        tab->data[tab->items].key = strdup(key);
    5668        tab->data[tab->items].val = strdup(val);
    57         //debug("inserted item: %s: %s\n", tab->data[tab->items].key, tab->data[tab->items].val);
     69        DBG("inserted item: %s: %s", tab->data[tab->items].key,
     70              tab->data[tab->items].val);
    5871        tab->items++;
    5972        return 0;
     
    6174
    6275/* print the whole hash table tab */
    63 void htab_print(htab tab)
     76void
     77htab_print(struct htab tab)
    6478{
    65         int i;
    66         for(i=0;i<tab.items;i++)
    67                 printf("%s: %s\n", tab.data[i].key, tab.data[i].val);
     79        int i=0;
     80        for (; i < tab.items; i++)
     81                PINFO("%s: %s", tab.data[i].key, tab.data[i].val);
    6882}
    69 
  • tools/nfotizer/interpret.c

    r757c610 rb4dadda  
    11#include "nfotizer.h"
     2#include <stdlib.h>             /* calloc */
     3#include <string.h>             /* strlen */
     4#include <stdbool.h>            /* bool */
    25
    3 /* toggle an int */
    4 #define TOGGLE(x)       ( x = ((x==1) ? 0 : 1) )
    5 
    6 /* allocating strcat */
    7 char *my_strcat(char *dest, char *src)
    8 {
    9         int newlen = strlen(dest) + strlen(src) + 1;
    10         char *ret = calloc(newlen, sizeof(char));
    11         if(sprintf(ret, "%s%s", dest, src) < 0)
    12                 return NULL;
    13 //      why not??
    14 //      free(dest);
    15 //      free(src);
    16         return ret;
    17 }
     6/* toggle a boolean */
     7#define TOGGLE(x)       ( x = !x )
    188
    199/* Interpret the string fmt.
    2010 * idid is the separator used for variables in fmt.
    2111 * The values for the variables found are taken from htable. */
    22 char *interpret(char *idid, char *fmt, htab *htable)
     12char *
     13interpret(const char *idid, const char *fmt, struct htab *htable)
    2314{
    24         int myfmt_len = strlen(fmt);
    25         char *myfmt = calloc(myfmt_len, sizeof(char));
    26         char *fullstr = strdup(fmt);
    27         char *result, *token;
    28         int is_id = (*fmt == *idid) ? 1 : 0;
     15        int myfmt_len;
     16        char *myfmt, *fmtdup, *fmtduptmp, *result = 0, *token, *tmp;
     17        bool is_id;
    2918
    30         for(;;fullstr = NULL, TOGGLE(is_id)) {
    31                 token = strtok(fullstr, idid);
    32                 debug("next token is \"%s\"\n", token);
    33                 if(token == NULL)
     19        if (!idid || !fmt)
     20                return NULL;
     21
     22        myfmt_len = strlen(fmt);
     23        myfmt = calloc(myfmt_len, sizeof(char));
     24        fmtdup = strdup(fmt);
     25        fmtduptmp = fmtdup;
     26        is_id = (*fmt == *idid);
     27
     28        for (;; fmtduptmp = NULL, TOGGLE(is_id)) {
     29                token = strtok(fmtduptmp, idid);
     30                DBG("next token is \"%s\"", token);
     31                if (token == NULL)
    3432                        break;
    35                 if(is_id) {
    36                         if((result=htab_get(token, *htable)) == NULL) {
    37                                 printf("ERROR: identifier %s not found in hash table\n", token);
     33                if (is_id) {
     34                        if ((result = htab_get(token, *htable)) == NULL) {
     35                                PERR("key %s not found in hash table", token);
    3836                                continue;
    3937                        }
    40                         if((myfmt = my_strcat(myfmt, result)) == NULL)
    41                                 return NULL;
    42                 } else if((myfmt = my_strcat(myfmt, token)) == NULL)
    43                         return NULL;
     38                        asprintf(&tmp, "%s%s", myfmt, result);
     39                        zap(myfmt);
     40                        zap(result);
     41                        myfmt = tmp;
     42                } else {
     43                        asprintf(&tmp, "%s%s", myfmt, token);
     44                        zap(myfmt);
     45                        /* zap(token); */
     46                        myfmt = tmp;
     47                }
    4448        }
    45         return(myfmt);
     49        free(fmtdup);
     50        return myfmt;
    4651}
     52
     53/* allocating strcat */
     54char *
     55my_strcat(char *dest, char *src)
     56{
     57        char *ret = NULL;
     58        if (asprintf(&ret, "%s%s", dest, src) < 0)
     59                return NULL;
     60
     61        return ret;
     62}
     63
  • tools/nfotizer/main.c

    r757c610 rb4dadda  
    11#include "nfotizer.h"
    2 #include <unistd.h>
    3 #include <sys/types.h>
    4 #include <sys/stat.h>
    5 #include <fcntl.h>
     2#include <stdlib.h>             /* exit */
     3#include <string.h>             /* strlen */
     4#include <libgen.h>             /* dirname */
    65
    7 char *my_dirname(char *path)
     6int nfotizer(char *);
     7int writefile(char *, char *);
     8
     9int
     10main(int argc, char **argv)
    811{
    9         int i;
    10         char *p = strdup(path);
    11         for(i=strlen(p);i>=0;i--) {
    12                 if(p[i] == DIRSEP) {
    13                         p[i] = '\0';
    14                         debug("found dirname %s\n", p);
    15                         return p;
    16                 }
     12        int i = 1, ret = 0;
     13
     14        if (argc < 2) {
     15                PINFO("Usage: %s filename [filename ...]", argv[0]);
     16                exit(1);
    1717        }
    18         return "";
     18
     19        while (i < argc) {
     20                if (nfotizer(argv[i++]))
     21                        ret = 1;
     22        }
     23
     24        exit(ret);
    1925}
    2026
    21 int main(int argc, char **argv)
     27int
     28nfotizer(char *nfofile)
    2229{
    2330        FILE *fp;
    24         htab *htable;
    25         char *dirname, *filename, *temp, *filecontent;
     31        struct htab *htable;
     32        const char **fdef;
     33        char *dname, *fname, *temp, *fcontent;
    2634        int i;
    2735
    28         if(argc < 2) {
    29                 printf("Usage: %s filename\n", argv[0]);
    30                 exit(1);
    31         }
    32         if((fp=fopen(argv[1], "r")) == NULL) {
    33                 puts("file doesnt exist");
    34                 exit(2);
     36        if ((fp = fopen(nfofile, "r")) == NULL) {
     37                PERR("file \'%s\' doesnt exist", nfofile);
     38                return 1;
    3539        }
    3640
    37         dirname = my_dirname(argv[1]);
    3841        htable = htab_create(100);
     42        if (parse(fp, htable)) {
     43                PERR("parsing \'%s\' failed", nfofile);
     44                fclose(fp);
     45                return 2;
     46        }
    3947
    40         if(parse(fp, htable)) {
    41                 puts("parse failed");
    42                 exit(3);
    43         }
    4448        fclose(fp);
    45 
    4649#ifdef DEBUG
    47         printf("\nItems in table:\n");
     50        PINFO("\nItems in table:");
    4851        htab_print(*htable);
    4952        puts("");
    5053#endif
    51         filename = temp = filecontent = 0;
    52         for(i=0; filedefs[i] != NULL; i++) {
    53                 filename = interpret(filedefs[i][0], filedefs[i][1], htable);
    54                 filecontent = interpret(filedefs[i][0], filedefs[i][2], htable);
    55                 if(strlen(dirname)) {
    56                         temp = realloc(temp, strlen(filename)+strlen(dirname)+2);
    57                         sprintf(temp, "%s/%s", dirname, filename);
    58                         filename = temp;
    59                 }
    60                 if((fp=fopen(filename, "w")) == NULL) {
    61                         printf("could not open file %s for writing.\n",filename);
    62                         continue;
    63                 }
    64                 if(fputs(filecontent, fp) == EOF)
    65                         printf("error writing file %s.\n",filename);
    66                 fclose(fp);
     54        dname = dirname(nfofile);
     55        fname = 0;
     56        temp = 0;
     57        fcontent = 0;
     58        for (i = 0; filedefs[i] != NULL; i++) {
     59                fdef = filedefs[i];
     60                fname = interpret(fdef[0], fdef[1], htable);
     61                fcontent = interpret(fdef[0], fdef[2], htable);
     62
     63                asprintf(&temp, "%s/%s", dname, fname);
     64                free(fname);
     65                fname = temp;
     66
     67                writefile(fname, fcontent);
     68                free(fname);
     69                free(fcontent);
    6770        }
    6871        htab_destroy(htable);
    69         exit(0);
     72        return 0;
    7073}
     74
     75/* overwrite content of file at fname with content given */
     76int
     77writefile(char *fname, char *content)
     78{
     79        FILE *fp;
     80        int ret = 0;
     81        if ((fp = fopen(fname, "w")) == NULL) {
     82                PERR("could not open file \'%s\' for writing", fname);
     83                return 1;
     84        }
     85        if (fputs(content, fp) == EOF) {
     86                PERR("error writing file %s", fname);
     87                ret = 2;
     88        }
     89        fclose(fp);
     90        return ret;
     91}
  • tools/nfotizer/nfotizer.h

    r757c610 rb4dadda  
    1 #include <stdio.h>      /* fopen() and co. */
    2 #include <stdlib.h>     /* exit() */
    3 #include <string.h>     /* strlen(), strdup() */
     1#define _GNU_SOURCE             /* asprintf */
     2#include <stdio.h>              /* FILE */
    43
    54#define DIRSEP          '/'
     5#define MAXTHREADS      5
    66
    77#ifdef DEBUG
    8 #define debug(...)      printf(__VA_ARGS__)
     8#define DBG(x, ...)     fprintf(stderr, x "\n", ## __VA_ARGS__)
    99#else
    10 #define debug(...)
     10#define DBG(x, ...)             /* empty */
    1111#endif
    1212
     13#define PINFO(x, ...)   fprintf(stdout, x "\n", ## __VA_ARGS__)
     14#define PWARN(x, ...)   fprintf(stderr, "Warning: " x "\n", ## __VA_ARGS__)
     15#define PERR(x, ...)    fprintf(stderr, "Error: " x "\n", ## __VA_ARGS__)
     16
     17/* conditional free */
     18#define zap(x)          if (x) { free(x); x = NULL; }
     19
    1320/* struct entry defines an htab item */
    14 typedef struct {
     21struct entry {
    1522        char *key;
    1623        char *val;
    17 } entry;
     24};
    1825
    1926/* struct htab defines a hash table
    2027 * size: size of entry[]
    2128 * items: count of items in entry[] */
    22 typedef struct {
     29struct htab {
    2330        int size;
    2431        int items;
    25         entry *data;
    26 } htab;
     32        struct entry *data;
     33};
    2734
    2835/* struct pline holding information about a parsed line
     
    3138 * bs_end:   backslash at end present
    3239 * key, val: key and value (if given) */
    33 typedef struct {
     40struct pline {
    3441        enum {
    3542                TYPE_COMMENT = 0,
     
    3946        int bs_end;
    4047        char *key, *val;
    41 } pline;
     48};
    4249
    4350/* parse.c */
    44 int parse(FILE *, htab *);
     51int parse(FILE *, struct htab *);
    4552
    46 /* semantics.c */
     53/* interpret.c */
    4754char *my_strcat(char *, char *);
    48 char *interpret(char *, char *, htab *);
     55char *interpret(const char *, const char *, struct htab *);
    4956
    5057/* hash.c */
    51 htab *htab_create(int);
    52 void htab_destroy(htab *);
    53 int htab_indexof(char *, htab);
    54 char *htab_get(char *, htab);
    55 int htab_put(char *, char *, htab *);
    56 void htab_print(htab);
     58struct htab *htab_create(int);
     59void htab_destroy(struct htab *);
     60int htab_indexof(char *, struct htab);
     61char *htab_get(char *, struct htab);
     62int htab_put(char *, char *, struct htab *);
     63void htab_print(struct htab);
    5764
    5865/* filedefs.c */
    59 extern char **filedefs[];
     66extern const char **filedefs[];
  • tools/nfotizer/parse.c

    r757c610 rb4dadda  
    11#include "nfotizer.h"
     2#include <string.h>             /* memset */
     3#include <stdlib.h>             /* calloc */
    24
    3 int parse_line(FILE *, long, pline *);
     5int parse_line(FILE *, long, struct pline *);
    46long findchar(FILE *, char);
    57long findend(FILE *);
     
    810 * Each parsed key-value pair is consecutively
    911 * inserted into the hash table at tab. */
    10 int parse(FILE *fd, htab *tab)
     12int parse(FILE * fd, struct htab * tab)
    1113{
    12         pline pl;
     14        struct pline pl;
    1315        long newline;
    1416        char *key, *val, *tmp;
    15         int bs_end=0;
    16         key = val = NULL;
     17        int bs_end = 0;
     18        pl.key = 0;
     19        pl.val = 0;
     20        key = 0;
     21        val = 0;
    1722        fseek(fd, 0, SEEK_SET);
    1823
    19         while(1) {
    20                 memset(&pl, 0, sizeof(pline));
     24        while (1) {
     25                zap(pl.key);
     26                zap(pl.val);
    2127                newline = findchar(fd, '\n');
    22                 if(parse_line(fd, newline, &pl))
     28                if (parse_line(fd, newline, &pl))
    2329                        return 1;
    24                 switch(pl.type) {
     30                switch (pl.type) {
    2531                case TYPE_COMMENT:
    2632                        break;
    2733                case TYPE_SUBVAL:
    28                         if(!key) {
    29                                 printf("parse(): scanned subvalue without key!\n");
     34                        if (!key) {
     35                                PERR("parsed subvalue \'%s\' without key!",
     36                                     pl.val);
    3037                                return 1;
    3138                        }
    32                         if(!bs_end) {
     39                        if (!bs_end) {
    3340                                /* append a newline to the old value part
    3441                                 * before the new one is appended. */
    35                                 tmp = calloc(strlen(val) + 2, sizeof(char));
    36                                 snprintf(tmp, strlen(val) + 2, "%s\n", val);
     42                                asprintf(&tmp, "%s\n", val);
    3743                                free(val);
    3844                                val = tmp;
    3945                        }
    40                         tmp = calloc(strlen(val) + strlen(pl.val) + 1, sizeof(char));
    41                         snprintf(tmp, strlen(val) + strlen(pl.val) + 1, "%s%s", val, pl.val);
     46                        asprintf(&tmp, "%s%s", val, pl.val);
    4247                        free(val);
    4348                        val = tmp;
    4449                        break;
    4550                case TYPE_KEY:
    46                         if(key && strlen(key)) {
     51                        if (key && strlen(key)) {
    4752                                htab_put(key, val, tab);
    4853                        }
    49                         if(key) free(key);
    50                         if(val) free(val);
     54                        zap(key);
     55                        zap(val);
    5156                        key = strdup(pl.key);
    5257                        val = strdup(pl.val);
    5358                        break;
    5459                }
    55                 // store backslash state, so we can check for it in the next iteration
    56                 if(pl.type != TYPE_COMMENT)
     60                /* store backslash state, so we can check for it in the next iteration */
     61                if (pl.type != TYPE_COMMENT)
    5762                        bs_end = pl.bs_end;
    5863
    5964                fseek(fd, newline + 1, SEEK_SET);
    6065
    61                 // check for EOF lately, so no data is lost when newline is missing at EOF.
    62                 if(ftell(fd) >= findend(fd)) {
    63                         if(key && strlen(key))
     66                /* check for EOF lately, so no data is lost when newline is missing at EOF. */
     67                if (ftell(fd) >= findend(fd)) {
     68                        if (key && strlen(key))
    6469                                htab_put(key, val, tab);
    65                         if(key) free(key);
    66                         if(val) free(val);
     70                        zap(key);
     71                        zap(val);
     72                        zap(pl.key);
     73                        zap(pl.val);
    6774                        return 0;
    6875                }
     
    7380 * end must point right after the end of the string.
    7481 * pl is filled with the data scanned. */
    75 int parse_line(FILE *fd, long end, pline *pl)
     82int parse_line(FILE * fd, long end, struct pline * pl)
    7683{
    7784        char c;
     
    7986        int i;
    8087        start = ftell(fd);
    81         debug("parse_line(): called at pos %ld\n", start);
     88
     89        DBG("parse_line(): called at pos %ld", start);
    8290#if defined(DEBUG)
    83         if(start != 0) {
     91        if (start != 0) {
    8492                fseek(fd, -1, SEEK_CUR);
    8593                c = fgetc(fd);
    86                 if(c != '\n') {
    87                         printf("parse_line(): error: not being called at start of line!\n");
     94                if (c != '\n') {
     95                        PERR("parse_line(): not called at start of line!");
    8896                        return 1;
    8997                }
    9098        }
    9199#endif
    92         // allow leading whitespaces (not tabs!)
    93         while((c=fgetc(fd)) == ' ') {
     100        pl->bs_end = 0;
     101
     102        /* allow leading whitespaces (not tabs!) */
     103        while ((c = fgetc(fd)) == ' ') {
    94104        }
    95105        start = ftell(fd) - 1L;
    96106
    97         switch(c) {
     107        switch (c) {
    98108        case '\n':
    99                 // FALL THROUGH
     109                /* FALLTHROUGH */
    100110        case '#':
    101111                pl->type = TYPE_COMMENT;
     
    107117                pl->type = TYPE_KEY;
    108118
    109                 // find the end of the key
     119                /* find the end of the key */
    110120                tmp = findchar(fd, '\t');
    111                 if(tmp >= end) {
    112                         printf("parse_line(): error: key with missing tab scanned!\n");
     121                if (tmp >= end) {
     122                        PERR("parse_line(): key with missing tab scanned!");
    113123                        return 1;
    114124                }
    115125
    116                 // scan the key
     126                /* scan the key */
    117127                len = tmp - start;
    118                 pl->key = calloc(len+1, sizeof(char));
     128                pl->key = calloc(len + 1, sizeof(char));
    119129                fseek(fd, -1, SEEK_CUR);
    120                 for(i=0; i<len; i++)
     130                for (i = 0; i < len; i++)
    121131                        pl->key[i] = fgetc(fd);
    122132                pl->key[i] = '\0';
     
    124134                /* recheck if pos is right after the key
    125135                 * beware of removal: this increments pos! */
    126                 if(fgetc(fd) != '\t') {
    127                         printf("parse_line(): error: something is strange here\n");
     136                if (fgetc(fd) != '\t') {
     137                        PERR("parse_line(): something is strange here");
    128138                        return 1;
    129139                }
     
    135145         * because after scanning the key, fd is at the right pos */
    136146        len = end - ftell(fd);
    137         pl->val = calloc(len+1, sizeof(char));
    138         for(i=0; i<len; i++)
     147        pl->val = calloc(len + 1, sizeof(char));
     148        for (i = 0; i < len; i++)
    139149                pl->val[i] = fgetc(fd);
    140150
    141         if(pl->val[i-1] == '\\') {
     151        if (pl->val[i - 1] == '\\') {
    142152                pl->bs_end = 1;
    143153                i--;
     
    153163 * char is returned, the position of c else.
    154164 * The file offset is not being altered. */
    155 long findchar(FILE *fd, char c)
     165long findchar(FILE * fd, char c)
    156166{
    157167        long i;
    158168        long start = ftell(fd);
    159         for(i=0;;i++) {
    160                 if(fgetc(fd) == c || feof(fd))
     169        for (i = 0;; i++) {
     170                if (fgetc(fd) == c || feof(fd))
    161171                        break;
    162172        }
    163173        fseek(fd, start, SEEK_SET);
    164         return start+i;
     174        return start + i;
    165175}
    166176
     
    168178 * This returns the position after the last
    169179 * char. The file offset is not being altered. */
    170 long findend(FILE *fd)
     180long findend(FILE * fd)
    171181{
    172182        long start = ftell(fd);
     
    177187        return end;
    178188}
    179 
Note: See TracChangeset for help on using the changeset viewer.