diff options
| author | jvoisin | 2022-05-06 21:11:28 +0200 |
|---|---|---|
| committer | jvoisin | 2022-05-06 21:11:28 +0200 |
| commit | 924144799f380863aa3b13f444f478eb81dcef6c (patch) | |
| tree | 9d32bc6a004b8acb49783bdbeef73fecfb98af9d | |
| parent | d6c78df6c1b54ffbb081d6679bb2eda0005c1dc7 (diff) | |
Another constify pass
| -rw-r--r-- | src/sp_config_scanner.h | 6 | ||||
| -rw-r--r-- | src/sp_config_scanner.re | 13 |
2 files changed, 10 insertions, 9 deletions
diff --git a/src/sp_config_scanner.h b/src/sp_config_scanner.h index 3284713..8ce1fb7 100644 --- a/src/sp_config_scanner.h +++ b/src/sp_config_scanner.h | |||
| @@ -19,7 +19,7 @@ typedef struct { | |||
| 19 | } sp_parsed_keyword; | 19 | } sp_parsed_keyword; |
| 20 | 20 | ||
| 21 | zend_result sp_config_scan(char *data, zend_result (*process_rule)(sp_parsed_keyword*)); | 21 | zend_result sp_config_scan(char *data, zend_result (*process_rule)(sp_parsed_keyword*)); |
| 22 | zend_string *sp_get_arg_string(sp_parsed_keyword *kw); | 22 | zend_string *sp_get_arg_string(sp_parsed_keyword const *const kw); |
| 23 | zend_string *sp_get_textual_representation(sp_parsed_keyword *parsed_rule); | 23 | zend_string *sp_get_textual_representation(sp_parsed_keyword const *const parsed_rule); |
| 24 | 24 | ||
| 25 | #endif \ No newline at end of file | 25 | #endif |
diff --git a/src/sp_config_scanner.re b/src/sp_config_scanner.re index d7c9884..9f1ac2b 100644 --- a/src/sp_config_scanner.re +++ b/src/sp_config_scanner.re | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | #define cs_log_warning(fmt, ...) sp_log_warn("config", fmt, ##__VA_ARGS__) | 7 | #define cs_log_warning(fmt, ...) sp_log_warn("config", fmt, ##__VA_ARGS__) |
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | zend_string *sp_get_arg_string(sp_parsed_keyword *kw) { | 10 | zend_string *sp_get_arg_string(sp_parsed_keyword const *const kw) { |
| 11 | if (!kw || !kw->arg) { | 11 | if (!kw || !kw->arg) { |
| 12 | return NULL; | 12 | return NULL; |
| 13 | } | 13 | } |
| @@ -33,11 +33,10 @@ zend_string *sp_get_arg_string(sp_parsed_keyword *kw) { | |||
| 33 | return ret; | 33 | return ret; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | zend_string *sp_get_textual_representation(sp_parsed_keyword *parsed_rule) { | 36 | zend_string *sp_get_textual_representation(sp_parsed_keyword const *const parsed_rule) { |
| 37 | // a rule is "sp.keyword...keyword(arg);\0" | 37 | // a rule is "sp.keyword...keyword(arg);\0" |
| 38 | size_t len = 3; // sp + ; | 38 | size_t len = 3; // sp + ; |
| 39 | sp_parsed_keyword *kw; | 39 | for (const sp_parsed_keyword *kw = parsed_rule; kw->kw; kw++) { |
| 40 | for (kw = parsed_rule; kw->kw; kw++) { | ||
| 41 | len++; // . | 40 | len++; // . |
| 42 | len += kw->kwlen; | 41 | len += kw->kwlen; |
| 43 | if (kw->argtype == SP_ARGTYPE_EMPTY) { | 42 | if (kw->argtype == SP_ARGTYPE_EMPTY) { |
| @@ -47,10 +46,12 @@ zend_string *sp_get_textual_representation(sp_parsed_keyword *parsed_rule) { | |||
| 47 | len += kw->arglen; | 46 | len += kw->arglen; |
| 48 | } | 47 | } |
| 49 | } | 48 | } |
| 49 | |||
| 50 | zend_string *ret = zend_string_alloc(len, 1); | 50 | zend_string *ret = zend_string_alloc(len, 1); |
| 51 | char *ptr = ZSTR_VAL(ret); | 51 | char *ptr = ZSTR_VAL(ret); |
| 52 | |||
| 52 | memcpy(ptr, "sp", 2); ptr += 2; | 53 | memcpy(ptr, "sp", 2); ptr += 2; |
| 53 | for (kw = parsed_rule; kw->kw; kw++) { | 54 | for (const sp_parsed_keyword *kw = parsed_rule; kw->kw; kw++) { |
| 54 | *ptr++ = '.'; | 55 | *ptr++ = '.'; |
| 55 | memcpy(ptr, kw->kw, kw->kwlen); ptr += kw->kwlen; | 56 | memcpy(ptr, kw->kw, kw->kwlen); ptr += kw->kwlen; |
| 56 | if (kw->argtype == SP_ARGTYPE_EMPTY || kw->argtype == SP_ARGTYPE_STR || kw->argtype == SP_ARGTYPE_UNKNOWN) { | 57 | if (kw->argtype == SP_ARGTYPE_EMPTY || kw->argtype == SP_ARGTYPE_STR || kw->argtype == SP_ARGTYPE_UNKNOWN) { |
| @@ -322,4 +323,4 @@ zend_result sp_config_scan(char *data, zend_result (*process_rule)(sp_parsed_key | |||
| 322 | out: | 323 | out: |
| 323 | zend_hash_destroy(&vars); | 324 | zend_hash_destroy(&vars); |
| 324 | return ret; | 325 | return ret; |
| 325 | } \ No newline at end of file | 326 | } |
