Permalink
Browse files

The new INI parser is showing some signs of life

  • Loading branch information...
1 parent d0fbddc commit ab3beffad78160010a58d377e0d507c76e87e6c4 @zsuraski zsuraski committed Oct 29, 2000
Showing with 106 additions and 16 deletions.
  1. +2 −1 Zend/zend_alloc.h
  2. +2 −1 Zend/zend_ini.h
  3. +38 −14 Zend/zend_ini_parser.y
  4. +4 −0 Zend/zend_ini_scanner.h
  5. +60 −0 Zend/zend_ini_scanner.l
View
3 Zend/zend_alloc.h
@@ -64,10 +64,11 @@ typedef union _align_test {
#define PLATFORM_PADDING (((PLATFORM_ALIGNMENT-sizeof(zend_mem_header))%PLATFORM_ALIGNMENT+PLATFORM_ALIGNMENT)%PLATFORM_ALIGNMENT)
-ZEND_API char *zend_strndup(const char *s, unsigned int length);
BEGIN_EXTERN_C()
+ZEND_API char *zend_strndup(const char *s, unsigned int length);
+
ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
View
3 Zend/zend_ini.h
@@ -157,7 +157,8 @@ ZEND_API ZEND_INI_MH(OnUpdateStringUnempty);
#define ZEND_INI_STAGE_RUNTIME (1<<4)
/* INI parsing engine */
-int zend_parse_ini_file(zend_file_handle *fh, void (*zend_ini_parser_cb)(zval *arg1, zval *arg2, int callback_type));
+typedef void (*zend_ini_parser_cb_t)(zval *arg1, zval *arg2, int callback_type, void *arg);
+int zend_parse_ini_file(zend_file_handle *fh, zend_ini_parser_cb_t ini_parser_cb, void *arg);
#define ZEND_INI_PARSER_ENTRY 1
#define ZEND_INI_PARSER_SECTION 2
View
52 Zend/zend_ini_parser.y
@@ -33,16 +33,22 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winbase.h>
-//#include "win32/wfile.h"
#endif
-int ini_lex(zval *ini_lval);
+
+typedef struct _zend_ini_parser_param {
+ zend_ini_parser_cb_t ini_parser_cb;
+ void *arg;
+} zend_ini_parser_param;
#define YYSTYPE zval
+#define YYPARSE_PARAM ini_parser_param
-#define YYPARSE_PARAM zend_ini_parser_cb
+#define ZEND_INI_PARSER_CB ((zend_ini_parser_param *) ini_parser_param)->ini_parser_cb
+#define ZEND_INI_PARSER_ARG ((zend_ini_parser_param *) ini_parser_param)->arg
-#define ZEND_INI_PARSER_CB ((void (*)(zval *arg1, zval *arg2, int callback_type)) zend_ini_parser_cb)
+int ini_lex(zval *ini_lval);
+int ini_parse(void *ini_parser_param);
#define PARSING_MODE_CFG 0
#define PARSING_MODE_BROWSCAP 1
@@ -66,7 +72,7 @@ extern int ini_lineno;
extern void init_cfg_scanner(void);
#endif
-void do_cfg_op(char type, zval *result, zval *op1, zval *op2)
+void zend_ini_do_op(char type, zval *result, zval *op1, zval *op2)
{
int i_result;
int i_op1, i_op2;
@@ -107,7 +113,7 @@ void do_cfg_op(char type, zval *result, zval *op1, zval *op2)
}
-void do_cfg_get_constant(zval *result, zval *name)
+void zend_ini_get_constant(zval *result, zval *name)
{
zval z_constant;
@@ -143,6 +149,24 @@ static void ini_error(char *str)
}
+int zend_parse_ini_file(zend_file_handle *fh, zend_ini_parser_cb_t ini_parser_cb, void *arg)
+{
+ zend_ini_parser_param ini_parser_param;
+
+ ini_parser_param.ini_parser_cb = ini_parser_cb;
+ ini_parser_param.arg = arg;
+
+ if (zend_ini_open_file_for_scanning(fh)==FAILURE) {
+ return FAILURE;
+ }
+ if (ini_parse(&ini_parser_param)==0) {
+ return SUCCESS;
+ } else {
+ return FAILURE;
+ }
+}
+
+
%}
%pure_parser
@@ -166,10 +190,10 @@ statement:
#if DEBUG_CFG_PARSER
printf("'%s' = '%s'\n",$1.value.str.val,$3.value.str.val);
#endif
- ZEND_INI_PARSER_CB(&$1, &$3, ZEND_INI_PARSER_ENTRY);
+ ZEND_INI_PARSER_CB(&$1, &$3, ZEND_INI_PARSER_ENTRY, ZEND_INI_PARSER_ARG);
}
- | TC_STRING { ZEND_INI_PARSER_CB(&$1, NULL, ZEND_INI_PARSER_ENTRY); }
- | SECTION { ZEND_INI_PARSER_CB(&$1, NULL, ZEND_INI_PARSER_SECTION); }
+ | TC_STRING { ZEND_INI_PARSER_CB(&$1, NULL, ZEND_INI_PARSER_ENTRY, ZEND_INI_PARSER_ARG); }
+ | SECTION { ZEND_INI_PARSER_CB(&$1, NULL, ZEND_INI_PARSER_SECTION, ZEND_INI_PARSER_ARG); }
| '\n'
;
@@ -185,15 +209,15 @@ string_or_value:
expr:
constant_string { $$ = $1; }
- | expr '|' expr { do_cfg_op('|', &$$, &$1, &$3); }
- | expr '&' expr { do_cfg_op('&', &$$, &$1, &$3); }
- | '~' expr { do_cfg_op('~', &$$, &$2, NULL); }
- | '!' expr { do_cfg_op('!', &$$, &$2, NULL); }
+ | expr '|' expr { zend_ini_do_op('|', &$$, &$1, &$3); }
+ | expr '&' expr { zend_ini_do_op('&', &$$, &$1, &$3); }
+ | '~' expr { zend_ini_do_op('~', &$$, &$2, NULL); }
+ | '!' expr { zend_ini_do_op('!', &$$, &$2, NULL); }
| '(' expr ')' { $$ = $2; }
;
constant_string:
- TC_STRING { do_cfg_get_constant(&$$, &$1); }
+ TC_STRING { zend_ini_get_constant(&$$, &$1); }
;
/*
* Local variables:
View
4 Zend/zend_ini_scanner.h
@@ -11,6 +11,10 @@ class ZendIniFlexLexer : public yyFlexLexer
};
#endif /* ZTS && __cplusplus */
+BEGIN_EXTERN_C()
int zend_ini_scanner_get_lineno();
+int zend_ini_open_file_for_scanning(zend_file_handle *fh);
+int ini_lex(zval *ini_lval);
+END_EXTERN_C()
#endif /* _ZEND_INI_SCANNER_H */
View
60 Zend/zend_ini_scanner.l
@@ -22,6 +22,20 @@
#include "zend_ini_parser.h"
#include "zend_ini_scanner.h"
+#ifdef ZTS
+# ifdef HAVE_STDIOSTR_H
+# include <stdiostr.h>
+# endif
+# ifdef HAVE_STDIOSTREAM_H
+# include <stdiostream.h>
+# endif
+# ifdef ZEND_WIN32
+# include <strstrea.h>
+# else
+# include <strstream.h>
+# endif
+#endif
+
#undef YYSTYPE
#define YYSTYPE zval
@@ -59,9 +73,55 @@ int ini_lex(zval *ini_lval)
return CG(ini_scanner)->lex_scan(ini_lval);
}
+ZendIniFlexLexer::~ZendIniFlexLexer()
+{
+ if (yy_start_stack) {
+ yy_flex_free(yy_start_stack);
+ }
+}
+
+int yyFlexLexer::yylex()
+{
+ fprintf(stderr, "Error: yyFlexLexer::yylex() called\n");
+ return -1;
+}
+
#endif
+int zend_ini_open_file_for_scanning(zend_file_handle *fh)
+{
+ FILE *fp;
+ CLS_FETCH();
+
+ switch (fh->type) {
+ case ZEND_HANDLE_FP:
+ fp = fh->handle.fp;
+ break;
+ case ZEND_HANDLE_FILENAME:
+ fp = zend_fopen(fh->filename, NULL);
+ break;
+ default:
+ return FAILURE;
+ }
+
+#ifdef ZTS
+ if (!fp) {
+ return FAILURE;
+ }
+ fh->handle.is = new istdiostream(fp);
+ fh->type = ZEND_HANDLE_STDIOSTREAM;
+
+ CG(ini_scanner) = new ZendIniFlexLexer;
+ CG(ini_scanner)->switch_streams(fh->handle.is, &cout);
+#else
+ init_cfg_scanner();
+ yyin = fp;
+ yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
+#endif
+ return SUCCESS;
+}
+
%}
%option noyywrap

0 comments on commit ab3beff

Please sign in to comment.