Changeset b4dadda in freewrt
- Timestamp:
- Feb 25, 2007, 2:36:31 AM (19 years ago)
- Children:
- c41c20f
- Parents:
- 757c610
- Location:
- tools/nfotizer
- Files:
-
- 7 edited
-
Makefile (modified) (1 diff)
-
filedefs.c (modified) (4 diffs)
-
hash.c (modified) (5 diffs)
-
interpret.c (modified) (1 diff)
-
main.c (modified) (1 diff)
-
nfotizer.h (modified) (3 diffs)
-
parse.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tools/nfotizer/Makefile
r757c610 rb4dadda 2 2 OBJECTS= $(patsubst %.c,%.o,$(wildcard *.c)) 3 3 HEADERS= $(wildcard *.h) 4 CFLAGS?= -Wall 4 CFLAGS+= -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 5 11 CC?= gcc 6 12 7 13 ifneq (${DEBUG},) 8 CFLAGS+= -g -DDEBUG14 CFLAGS+= -g 9 15 else 10 16 CFLAGS+= -Os 11 17 endif 12 18 13 all: $(TARGET) 19 ifneq (${VERBOSE},) 20 CFLAGS+= -DDEBUG 21 endif 22 23 all: ${TARGET} 14 24 15 25 debug: 16 26 make DEBUG=1 27 17 28 clean: 18 -rm -f $ (OBJECTS)29 -rm -f ${OBJECTS} 19 30 20 31 distclean: clean 21 -rm -f $ (TARGET) $(TESTS)32 -rm -f ${TARGET} ${TESTS} 22 33 23 $(TARGET): $(OBJECTS) 24 $(CC) -o $@ $^ 25 26 %.o: %.c $(HEADERS) 27 $(CC) $(CFLAGS) -c $< 34 ${TARGET}: ${OBJECTS} 35 ${CC} ${LDFLAGS} -o $@ $^ 28 36 29 37 .PHONY: all debug clean distclean -
tools/nfotizer/filedefs.c
r757c610 rb4dadda 5 5 * Field 1: The name of the file. 6 6 * Field 2: The format of the file. */ 7 c har *ipkg[] = { "#", "#NAME#.control",7 const char *ipkg[] = { "#", "#NAME#.control", 8 8 "Package: #NAME#\n" 9 9 "Priority: #PRIO#\n" … … 12 12 "Description: #DESCR_LINE#\n" 13 13 }; 14 c har *config[] = { "#", "Config.in",14 const char *config[] = { "#", "Config.in", 15 15 "config #SYM#\n" 16 16 "\t#SYM_SCOPE# \"#NAME# .......................... #DESCR_LINE#\"\n" … … 19 19 "#DESCR#\n" 20 20 }; 21 c har *makefile[] = { "@", "vars.mk",21 const char *makefile[] = { "@", "vars.mk", 22 22 "PKG_NAME:= @NAME@\n" 23 23 "PKG_VERSION:= @VERSION@\n" … … 29 29 "PKG_SOURCE:= @SRC_NAME@\n" 30 30 }; 31 31 32 /* To enable generating of a file defined above, add it to this variable: */ 32 char **filedefs[] = { ipkg, config, makefile, NULL}; 33 33 const char **filedefs[] = { ipkg, config, makefile, NULL }; -
tools/nfotizer/hash.c
r757c610 rb4dadda 1 1 #include "nfotizer.h" 2 #include <stdlib.h> /* malloc */ 3 #include <string.h> /* strcmp */ 2 4 3 5 /* Create a new hash table. 4 6 * This initially holds size elements, 5 7 * but is dynamically growing. */ 6 htab *htab_create(int size) 8 struct htab * 9 htab_create(int size) 7 10 { 8 htab *table = malloc(sizeof(htab));11 struct htab *table = malloc(sizeof(struct htab)); 9 12 table->size = size; 10 table->data = calloc(size, sizeof( entry));13 table->data = calloc(size, sizeof(struct entry)); 11 14 table->items = 0; 12 15 return table; … … 14 17 15 18 /* destroy a hash table, freeing it's space */ 16 void htab_destroy(htab *tab) 19 void 20 htab_destroy(struct htab *tab) 17 21 { 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); 20 29 } 21 30 22 31 /* return the index of key in the hash table tab or -1 if not found */ 23 int htab_indexof(char *key, htab tab) 32 int 33 htab_indexof(char *key, struct htab tab) 24 34 { 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); 29 39 return i; 30 40 } … … 34 44 35 45 /* return the value of key in tab */ 36 char *htab_get(char *key, htab tab) 46 char * 47 htab_get(char *key, struct htab tab) 37 48 { 38 49 int i; 39 if ((i=htab_indexof(key, tab))>=0)50 if ((i = htab_indexof(key, tab)) >= 0) 40 51 return strdup(tab.data[i].val); 41 52 else … … 44 55 45 56 /* insert key with value val into tab */ 46 int htab_put(char *key, char *val, htab *tab) 57 int 58 htab_put(char *key, char *val, struct htab *tab) 47 59 { 48 if (htab_indexof(key, *tab)>=0)60 if (htab_indexof(key, *tab) >= 0) 49 61 return -1; 50 if (tab->items == tab->size) {62 if (tab->items == tab->size) { 51 63 tab->size = tab->size << 2; 52 debug("resizing haash to %i items\n", tab->size);64 DBG("resizing hash to %i items", tab->size); 53 65 tab->data = realloc(tab->data, tab->size); 54 66 } 55 67 tab->data[tab->items].key = strdup(key); 56 68 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); 58 71 tab->items++; 59 72 return 0; … … 61 74 62 75 /* print the whole hash table tab */ 63 void htab_print(htab tab) 76 void 77 htab_print(struct htab tab) 64 78 { 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); 68 82 } 69 -
tools/nfotizer/interpret.c
r757c610 rb4dadda 1 1 #include "nfotizer.h" 2 #include <stdlib.h> /* calloc */ 3 #include <string.h> /* strlen */ 4 #include <stdbool.h> /* bool */ 2 5 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 ) 18 8 19 9 /* Interpret the string fmt. 20 10 * idid is the separator used for variables in fmt. 21 11 * The values for the variables found are taken from htable. */ 22 char *interpret(char *idid, char *fmt, htab *htable) 12 char * 13 interpret(const char *idid, const char *fmt, struct htab *htable) 23 14 { 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; 29 18 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) 34 32 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); 38 36 continue; 39 37 } 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 } 44 48 } 45 return(myfmt); 49 free(fmtdup); 50 return myfmt; 46 51 } 52 53 /* allocating strcat */ 54 char * 55 my_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 1 1 #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 */ 6 5 7 char *my_dirname(char *path) 6 int nfotizer(char *); 7 int writefile(char *, char *); 8 9 int 10 main(int argc, char **argv) 8 11 { 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); 17 17 } 18 return ""; 18 19 while (i < argc) { 20 if (nfotizer(argv[i++])) 21 ret = 1; 22 } 23 24 exit(ret); 19 25 } 20 26 21 int main(int argc, char **argv) 27 int 28 nfotizer(char *nfofile) 22 29 { 23 30 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; 26 34 int i; 27 35 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; 35 39 } 36 40 37 dirname = my_dirname(argv[1]);38 41 htable = htab_create(100); 42 if (parse(fp, htable)) { 43 PERR("parsing \'%s\' failed", nfofile); 44 fclose(fp); 45 return 2; 46 } 39 47 40 if(parse(fp, htable)) {41 puts("parse failed");42 exit(3);43 }44 48 fclose(fp); 45 46 49 #ifdef DEBUG 47 printf("\nItems in table:\n");50 PINFO("\nItems in table:"); 48 51 htab_print(*htable); 49 52 puts(""); 50 53 #endif 51 filename = temp = filecontent = 0;52 f or(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 f close(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); 67 70 } 68 71 htab_destroy(htable); 69 exit(0);72 return 0; 70 73 } 74 75 /* overwrite content of file at fname with content given */ 76 int 77 writefile(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 */ 4 3 5 4 #define DIRSEP '/' 5 #define MAXTHREADS 5 6 6 7 7 #ifdef DEBUG 8 #define debug(...) printf(__VA_ARGS__)8 #define DBG(x, ...) fprintf(stderr, x "\n", ## __VA_ARGS__) 9 9 #else 10 #define debug(...)10 #define DBG(x, ...) /* empty */ 11 11 #endif 12 12 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 13 20 /* struct entry defines an htab item */ 14 typedef struct{21 struct entry { 15 22 char *key; 16 23 char *val; 17 } entry;24 }; 18 25 19 26 /* struct htab defines a hash table 20 27 * size: size of entry[] 21 28 * items: count of items in entry[] */ 22 typedef struct{29 struct htab { 23 30 int size; 24 31 int items; 25 entry *data;26 } htab;32 struct entry *data; 33 }; 27 34 28 35 /* struct pline holding information about a parsed line … … 31 38 * bs_end: backslash at end present 32 39 * key, val: key and value (if given) */ 33 typedef struct{40 struct pline { 34 41 enum { 35 42 TYPE_COMMENT = 0, … … 39 46 int bs_end; 40 47 char *key, *val; 41 } pline;48 }; 42 49 43 50 /* parse.c */ 44 int parse(FILE *, htab *);51 int parse(FILE *, struct htab *); 45 52 46 /* semantics.c */53 /* interpret.c */ 47 54 char *my_strcat(char *, char *); 48 char *interpret(c har *, char *,htab *);55 char *interpret(const char *, const char *, struct htab *); 49 56 50 57 /* 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);58 struct htab *htab_create(int); 59 void htab_destroy(struct htab *); 60 int htab_indexof(char *, struct htab); 61 char *htab_get(char *, struct htab); 62 int htab_put(char *, char *, struct htab *); 63 void htab_print(struct htab); 57 64 58 65 /* filedefs.c */ 59 extern c har **filedefs[];66 extern const char **filedefs[]; -
tools/nfotizer/parse.c
r757c610 rb4dadda 1 1 #include "nfotizer.h" 2 #include <string.h> /* memset */ 3 #include <stdlib.h> /* calloc */ 2 4 3 int parse_line(FILE *, long, pline *);5 int parse_line(FILE *, long, struct pline *); 4 6 long findchar(FILE *, char); 5 7 long findend(FILE *); … … 8 10 * Each parsed key-value pair is consecutively 9 11 * inserted into the hash table at tab. */ 10 int parse(FILE * fd, htab *tab)12 int parse(FILE * fd, struct htab * tab) 11 13 { 12 pline pl;14 struct pline pl; 13 15 long newline; 14 16 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; 17 22 fseek(fd, 0, SEEK_SET); 18 23 19 while(1) { 20 memset(&pl, 0, sizeof(pline)); 24 while (1) { 25 zap(pl.key); 26 zap(pl.val); 21 27 newline = findchar(fd, '\n'); 22 if (parse_line(fd, newline, &pl))28 if (parse_line(fd, newline, &pl)) 23 29 return 1; 24 switch (pl.type) {30 switch (pl.type) { 25 31 case TYPE_COMMENT: 26 32 break; 27 33 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); 30 37 return 1; 31 38 } 32 if (!bs_end) {39 if (!bs_end) { 33 40 /* append a newline to the old value part 34 41 * 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); 37 43 free(val); 38 44 val = tmp; 39 45 } 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); 42 47 free(val); 43 48 val = tmp; 44 49 break; 45 50 case TYPE_KEY: 46 if (key && strlen(key)) {51 if (key && strlen(key)) { 47 52 htab_put(key, val, tab); 48 53 } 49 if(key) free(key);50 if(val) free(val);54 zap(key); 55 zap(val); 51 56 key = strdup(pl.key); 52 57 val = strdup(pl.val); 53 58 break; 54 59 } 55 / / store backslash state, so we can check for it in the next iteration56 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) 57 62 bs_end = pl.bs_end; 58 63 59 64 fseek(fd, newline + 1, SEEK_SET); 60 65 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)) 64 69 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); 67 74 return 0; 68 75 } … … 73 80 * end must point right after the end of the string. 74 81 * pl is filled with the data scanned. */ 75 int parse_line(FILE * fd, long end, pline *pl)82 int parse_line(FILE * fd, long end, struct pline * pl) 76 83 { 77 84 char c; … … 79 86 int i; 80 87 start = ftell(fd); 81 debug("parse_line(): called at pos %ld\n", start); 88 89 DBG("parse_line(): called at pos %ld", start); 82 90 #if defined(DEBUG) 83 if (start != 0) {91 if (start != 0) { 84 92 fseek(fd, -1, SEEK_CUR); 85 93 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!"); 88 96 return 1; 89 97 } 90 98 } 91 99 #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)) == ' ') { 94 104 } 95 105 start = ftell(fd) - 1L; 96 106 97 switch (c) {107 switch (c) { 98 108 case '\n': 99 / / FALL THROUGH109 /* FALLTHROUGH */ 100 110 case '#': 101 111 pl->type = TYPE_COMMENT; … … 107 117 pl->type = TYPE_KEY; 108 118 109 / / find the end of the key119 /* find the end of the key */ 110 120 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!"); 113 123 return 1; 114 124 } 115 125 116 / / scan the key126 /* scan the key */ 117 127 len = tmp - start; 118 pl->key = calloc(len +1, sizeof(char));128 pl->key = calloc(len + 1, sizeof(char)); 119 129 fseek(fd, -1, SEEK_CUR); 120 for (i=0; i<len; i++)130 for (i = 0; i < len; i++) 121 131 pl->key[i] = fgetc(fd); 122 132 pl->key[i] = '\0'; … … 124 134 /* recheck if pos is right after the key 125 135 * 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"); 128 138 return 1; 129 139 } … … 135 145 * because after scanning the key, fd is at the right pos */ 136 146 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++) 139 149 pl->val[i] = fgetc(fd); 140 150 141 if (pl->val[i-1] == '\\') {151 if (pl->val[i - 1] == '\\') { 142 152 pl->bs_end = 1; 143 153 i--; … … 153 163 * char is returned, the position of c else. 154 164 * The file offset is not being altered. */ 155 long findchar(FILE * fd, char c)165 long findchar(FILE * fd, char c) 156 166 { 157 167 long i; 158 168 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)) 161 171 break; 162 172 } 163 173 fseek(fd, start, SEEK_SET); 164 return start +i;174 return start + i; 165 175 } 166 176 … … 168 178 * This returns the position after the last 169 179 * char. The file offset is not being altered. */ 170 long findend(FILE * fd)180 long findend(FILE * fd) 171 181 { 172 182 long start = ftell(fd); … … 177 187 return end; 178 188 } 179
Note:
See TracChangeset
for help on using the changeset viewer.
