Check-in Number:
|
4863 | |
Date: |
2004-Nov-20 13:54:07 (local)
2004-Nov-20 12:54:07 (UTC) |
User: | rse |
Branch: | |
Comment: |
- Fixed cfg_test program by correctly passing the used number of
bytes in the buffer instead of the size of the buffer.
- Accept zero-length strings for parsing.
- Correctly handle end-of-file during plain text token scanning. |
Tickets: |
|
Inspections: |
|
Files: |
|
ossp-pkg/cfg/ChangeLog 1.18 -> 1.19
--- ChangeLog 2004/11/20 11:53:11 1.18
+++ ChangeLog 2004/11/20 12:54:07 1.19
@@ -10,6 +10,14 @@
Changes between 0.9.4 and 0.9.5 (31-Oct-2004 to xx-Nov-2004):
+ *) Fixed cfg_test program by correctly passing the used number of
+ bytes in the buffer instead of the size of the buffer.
+ [Ralf S. Engelschall <rse@engelschall.com>]
+
+ *) Accept zero-length strings for parsing. Correctly handle
+ end-of-file during plain text token scanning.
+ [Ralf S. Engelschall <rse@engelschall.com>]
+
*) Do not let Flex generate the unused yyunput() and yy_top_state()
functions in order to shut up compilation warnings.
[Ralf S. Engelschall <rse@engelschall.com>]
|
|
ossp-pkg/cfg/cfg_main.c 1.11 -> 1.12
--- cfg_main.c 2004/07/17 07:37:55 1.11
+++ cfg_main.c 2004/11/20 12:54:07 1.12
@@ -157,7 +157,7 @@
char error[1024];
cfg_node_t *root;
- if (cfg == NULL || in_ptr == NULL || in_len == 0)
+ if (cfg == NULL || in_ptr == NULL)
return CFG_ERR_ARG;
if (node == NULL)
node = cfg->root;
|
|
ossp-pkg/cfg/cfg_syn.c 1.18 -> 1.19
--- cfg_syn.c 2004/11/20 12:02:32 1.18
+++ cfg_syn.c 2004/11/20 12:54:07 1.19
@@ -60,7 +60,7 @@
void *yyscan;
/* argument sanity checking */
- if (node == NULL || in_ptr == NULL || in_len == 0)
+ if (node == NULL || in_ptr == NULL)
return CFG_ERR_ARG;
/* initialize scanner */
|
|
ossp-pkg/cfg/cfg_syn_parse.y 1.8 -> 1.9
--- cfg_syn_parse.y 2004/07/17 07:37:55 1.8
+++ cfg_syn_parse.y 2004/11/20 12:54:07 1.9
@@ -57,7 +57,8 @@
/* scanner state transition */
extern void cfg_syn_scan_push(cfg_syn_ctx_t *, const char *state);
-extern void cfg_syn_scan_pop(cfg_syn_ctx_t *);
+extern void cfg_syn_scan_pop (cfg_syn_ctx_t *);
+
%}
/* parser options */
|
|
ossp-pkg/cfg/cfg_syn_scan.l 1.19 -> 1.20
--- cfg_syn_scan.l 2004/11/20 11:42:21 1.19
+++ cfg_syn_scan.l 2004/11/20 12:54:07 1.20
@@ -56,11 +56,12 @@
yylloc->first = yylloc->last; \
yylloc->last += yyleng;
#define YY_USER_ACTION_ROLLBACK \
- yylloc->last = yylloc->first
+ yylloc->last = yylloc->first
static char closing_brace(char open);
static int hex_nibble(const char hex);
static int hex_sequence(char *out_ptr, size_t out_len, const char *in_ptr, size_t in_len);
+
%}
/* scanner options */
@@ -294,6 +295,17 @@
BEGIN(INITIAL);
return T_STRING;
}
+<SS_PT><<EOF>> {
+ *cpStr = '\0';
+ yylval->cpString = strdup(caStr);
+ BEGIN(INITIAL);
+ return T_STRING;
+}
+
+<INITIAL><<EOF>> {
+ /* end of scanning */
+ yyterminate();
+}
%%
|
|
ossp-pkg/cfg/cfg_test.c 1.15 -> 1.16
--- cfg_test.c 2004/11/20 11:48:39 1.15
+++ cfg_test.c 2004/11/20 12:54:07 1.16
@@ -44,6 +44,7 @@
cfg_rc_t rc;
char *im_ptr;
size_t im_size;
+ size_t im_used;
char *ex_ptr;
char *error;
cfg_t *cfg;
@@ -57,7 +58,7 @@
}
/* read configuration file into memory */
- if ((rc = cfg_util_readfile(argv[1], &im_ptr, &im_size)) != CFG_OK) {
+ if ((rc = cfg_util_readfile(argv[1], &im_ptr, &im_size, &im_used)) != CFG_OK) {
fprintf(stderr, "ERROR: reading file \"%s\"\n", argv[1]);
exit(1);
}
@@ -71,7 +72,7 @@
}
/* parse configuration */
- if ((rc = cfg_import(cfg, NULL, CFG_FMT_CFG, im_ptr, im_size)) != CFG_OK) {
+ if ((rc = cfg_import(cfg, NULL, CFG_FMT_CFG, im_ptr, im_used)) != CFG_OK) {
cfg_error(cfg, rc, &error);
fprintf(stderr, "ERROR: cfg_import: %s\n", error);
free(im_ptr);
|
|
ossp-pkg/cfg/cfg_util.c 1.4 -> 1.5
--- cfg_util.c 2004/07/17 07:37:55 1.4
+++ cfg_util.c 2004/11/20 12:54:07 1.5
@@ -37,7 +37,7 @@
#include "cfg_global.h"
#include "cfg_util.h"
-cfg_rc_t cfg_util_readfile(const char *filename, char **buf_ptr, size_t *buf_len)
+cfg_rc_t cfg_util_readfile(const char *filename, char **buf_ptr, size_t *buf_size, size_t *buf_used)
{
FILE *fp = NULL;
size_t n;
@@ -45,16 +45,16 @@
if (strcmp(filename, "-") == 0) {
/* file is given on stdin */
- (*buf_len) = 32;
- if ((*buf_ptr = (char *)malloc(*buf_len)) == NULL)
+ (*buf_size) = 32;
+ if ((*buf_ptr = (char *)malloc(*buf_size)) == NULL)
return CFG_ERR_SYS;
cp = *buf_ptr;
- while ((n = fread(cp, 1, (*buf_len)-(cp-(*buf_ptr)), stdin)) > 0) {
+ while ((n = fread(cp, 1, (*buf_size)-(cp-(*buf_ptr)), stdin)) > 0) {
cp += n;
- if (((*buf_ptr)+(*buf_len))-cp < (*buf_len)/8) {
- (*buf_len) *= 2;
+ if (((*buf_ptr)+(*buf_size))-cp < (*buf_size)/8) {
+ (*buf_size) *= 2;
n = cp-(*buf_ptr);
- if ((cp = (char *)realloc(*buf_ptr, *buf_len)) == NULL) {
+ if ((cp = (char *)realloc(*buf_ptr, *buf_size)) == NULL) {
free(*buf_ptr);
return CFG_ERR_SYS;
}
@@ -63,6 +63,7 @@
}
}
*cp = '\0';
+ *buf_used = (cp - *buf_ptr);
}
else {
/* file is given on filesystem */
@@ -81,11 +82,13 @@
return CFG_ERR_SYS;
}
(*buf_ptr)[n] = '\0';
- (*buf_len) = n+1;
+ (*buf_size) = n+1;
+ (*buf_used) = n;
}
else {
- (*buf_ptr) = strdup("");
- (*buf_len) = 1;
+ (*buf_ptr) = strdup("");
+ (*buf_size) = 1;
+ (*buf_used) = 0;
}
fclose(fp);
}
|
|
ossp-pkg/cfg/cfg_util.h 1.4 -> 1.5
--- cfg_util.h 2004/07/17 07:37:55 1.4
+++ cfg_util.h 2004/11/20 12:54:07 1.5
@@ -33,7 +33,7 @@
#include "cfg.h"
-cfg_rc_t cfg_util_readfile(const char *filename, char **buf_ptr, size_t *buf_len);
+cfg_rc_t cfg_util_readfile(const char *filename, char **buf_ptr, size_t *buf_size, size_t *buf_used);
#endif /* __CFG_UTIL_H__ */
|
|