Permalink
Browse files

Final touches on the INI parser

  • Loading branch information...
1 parent ea6985a commit 9596255da8e5e82221fe0ce1daee5865de3af0f4 @zsuraski zsuraski committed Oct 30, 2000
Showing with 37 additions and 7 deletions.
  1. +2 −0 Zend/zend_globals.h
  2. +1 −1 Zend/zend_ini.h
  3. +12 −4 Zend/zend_ini_parser.y
  4. +3 −0 Zend/zend_ini_scanner.h
  5. +19 −2 Zend/zend_ini_scanner.l
View
@@ -107,6 +107,8 @@ struct _zend_compiler_globals {
zend_bool unclean_shutdown;
+ zend_bool ini_parser_unbuffered_errors;
+
zend_llist open_files;
#if defined(ZTS) && defined(__cplusplus)
ZendFlexLexer *ZFL;
View
@@ -158,7 +158,7 @@ ZEND_API ZEND_INI_MH(OnUpdateStringUnempty);
/* INI parsing engine */
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);
+int zend_parse_ini_file(zend_file_handle *fh, zend_bool unbuffered_errors, zend_ini_parser_cb_t ini_parser_cb, void *arg);
#define ZEND_INI_PARSER_ENTRY 1
#define ZEND_INI_PARSER_SECTION 2
@@ -59,7 +59,6 @@ extern HashTable browser_hash;
ZEND_API extern char *php_ini_path;
static HashTable *active_hash_table;
static zval *current_section;
-static char *currently_parsed_filename;
static int parsing_mode;
@@ -135,24 +134,32 @@ static void ini_error(char *str)
{
char *error_buf;
int error_buf_len;
+ char *currently_parsed_filename = zend_ini_scanner_get_filename();
+ CLS_FETCH();
error_buf_len = 128+strlen(currently_parsed_filename); /* should be more than enough */
error_buf = (char *) emalloc(error_buf_len);
sprintf(error_buf, "Error parsing %s on line %d\n", currently_parsed_filename, zend_ini_scanner_get_lineno());
+
+ if (CG(ini_parser_unbuffered_errors)) {
#ifdef PHP_WIN32
- MessageBox(NULL, error_buf, "PHP Error", MB_OK|MB_TOPMOST|0x00200000L);
+ MessageBox(NULL, error_buf, "PHP Error", MB_OK|MB_TOPMOST|0x00200000L);
#else
- fprintf(stderr, "PHP: %s", error_buf);
+ fprintf(stderr, "PHP: %s", error_buf);
#endif
+ } else {
+ zend_error(E_CORE_WARNING, error_buf);
+ }
efree(error_buf);
}
-int zend_parse_ini_file(zend_file_handle *fh, zend_ini_parser_cb_t ini_parser_cb, void *arg)
+int zend_parse_ini_file(zend_file_handle *fh, zend_bool unbuffered_errors, zend_ini_parser_cb_t ini_parser_cb, void *arg)
{
zend_ini_parser_param ini_parser_param;
int retval;
+ CLS_FETCH();
ini_parser_param.ini_parser_cb = ini_parser_cb;
ini_parser_param.arg = arg;
@@ -161,6 +168,7 @@ int zend_parse_ini_file(zend_file_handle *fh, zend_ini_parser_cb_t ini_parser_cb
return FAILURE;
}
+ CG(ini_parser_unbuffered_errors) = unbuffered_errors;
retval = ini_parse(&ini_parser_param);
zend_ini_close_file(fh);
@@ -8,11 +8,14 @@ class ZendIniFlexLexer : public yyFlexLexer
virtual ~ZendIniFlexLexer();
int lex_scan(zval *zendlval);
void BeginState(int state);
+
+ char *filename;
};
#endif /* ZTS && __cplusplus */
BEGIN_EXTERN_C()
int zend_ini_scanner_get_lineno();
+char *zend_ini_scanner_get_filename();
int zend_ini_open_file_for_scanning(zend_file_handle *fh);
void zend_ini_close_file(zend_file_handle *fh);
int ini_lex(zval *ini_lval);
@@ -46,6 +46,8 @@
#endif
#ifndef ZTS
+static char *ini_filename;
+
void init_ini_scanner()
{
ini_lineno=1;
@@ -57,6 +59,12 @@ int zend_ini_scanner_get_lineno()
return ini_lineno;
}
+
+char *zend_ini_scanner_get_filename()
+{
+ return ini_filename;
+}
+
#else /* ZTS */
int zend_ini_scanner_get_lineno()
@@ -66,6 +74,13 @@ int zend_ini_scanner_get_lineno()
return CG(ini_scanner)->lineno();
}
+char *zend_ini_scanner_get_filename()
+{
+ CLS_FETCH();
+
+ return CG(ini_scanner)->filename;
+}
+
int ini_lex(zval *ini_lval)
{
CLS_FETCH();
@@ -115,10 +130,12 @@ int zend_ini_open_file_for_scanning(zend_file_handle *fh)
CG(ini_scanner) = new ZendIniFlexLexer;
CG(ini_scanner)->switch_streams(fh->handle.is, &cout);
+ CG(ini_scanner)->filename = fh->filename;
#else
init_ini_scanner();
yyin = fp;
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
+ ini_filename = fh->filename;
#endif
return SUCCESS;
}
@@ -130,13 +147,13 @@ void zend_ini_close_file(zend_file_handle *fh)
case ZEND_HANDLE_FP:
fclose(fh->handle.fp);
break;
+#ifdef ZTS
case ZEND_HANDLE_STDIOSTREAM: {
CLS_FETCH();
-#ifdef ZTS
delete CG(ini_scanner);
-#endif
}
break;
+#endif
}
}

0 comments on commit 9596255

Please sign in to comment.