From c8b352cb74c6b4a4f885022e766a11f06dea71bc Mon Sep 17 00:00:00 2001 From: JSDurand Date: Wed, 12 Jul 2023 10:23:12 +0800 Subject: reformat some C functions I do not use a tool to automatically format the codes, so sometimes the codes look ugly. This commit reformats the codes so that they look better and shorter on each line. --- src/binding.c | 97 ++++++++++++++++++++++++++++++++++++----------------------- src/helper.h | 9 +++++- 2 files changed, 68 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/binding.c b/src/binding.c index 43f73ba..f1f9029 100644 --- a/src/binding.c +++ b/src/binding.c @@ -8,7 +8,8 @@ int plugin_is_GPL_compatible = 3; emacs_value -rep_new_parser(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *data) +rep_new_parser +(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *data) { char *buffer = NULL; ptrdiff_t len = 0; @@ -37,13 +38,15 @@ rep_new_parser(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *data) uint64_t error_length = from_big_endian(error_vec.len); if (error_length) { - error_data[0] = env->make_string(env, error_vec.data, (ptrdiff_t) error_length); + error_data[0] = + env->make_string(env, error_vec.data, (ptrdiff_t) error_length); clean_signed(&error_vec, 4); - env->non_local_exit_signal(env, env->intern(env, "error"), - env->funcall(env, env->intern(env, "list"), - 1, error_data)); + env->non_local_exit_signal + (env, env->intern(env, "error"), + env->funcall(env, env->intern(env, "list"), + 1, error_data)); return env->intern(env, "nil"); } @@ -52,7 +55,8 @@ rep_new_parser(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *data) } emacs_value -rep_parser_recognize(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *data) +rep_parser_recognize +(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *data) { struct parser *parser = env->get_user_ptr(env, *args); @@ -70,9 +74,10 @@ rep_parser_recognize(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *da error_data[0] = env->make_string (env, "INPUT should be a vector of integers", 36); - env->non_local_exit_signal(env, env->intern(env, "wrong-type-argument"), - env->funcall(env, env->intern(env, "list"), - 1, error_data)); + env->non_local_exit_signal + (env, env->intern(env, "wrong-type-argument"), + env->funcall(env, env->intern(env, "list"), + 1, error_data)); return env->intern(env, "nil"); } @@ -84,9 +89,10 @@ rep_parser_recognize(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *da if (buffer == NULL) { error_data[0] = env->make_string(env, "out of memory", 13); - env->non_local_exit_signal(env, env->intern(env, "error"), - env->funcall(env, env->intern(env, "list"), - 1, error_data)); + env->non_local_exit_signal + (env, env->intern(env, "error"), + env->funcall(env, env->intern(env, "list"), + 1, error_data)); return env->intern(env, "nil"); } @@ -118,20 +124,24 @@ rep_parser_recognize(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *da struct UnsignedVec input_vec = (struct UnsignedVec) { input_len, NULL, buffer }; - int result = parser_recognize(parser, &input_vec, &error_vec, (unsigned char) 1); + int result = + parser_recognize + (parser, &input_vec, &error_vec, (unsigned char) 1); free(buffer); uint64_t error_length = from_big_endian(error_vec.len); if (error_length) { - error_data[0] = env->make_string(env, error_vec.data, (ptrdiff_t) error_length); + error_data[0] = + env->make_string(env, error_vec.data, (ptrdiff_t) error_length); clean_signed(&error_vec, 4); - env->non_local_exit_signal(env, env->intern(env, "error"), - env->funcall(env, env->intern(env, "list"), - 1, error_data)); + env->non_local_exit_signal + (env, env->intern(env, "error"), + env->funcall(env, env->intern(env, "list"), + 1, error_data)); return env->intern(env, "nil"); } @@ -146,7 +156,8 @@ clean_forest(void *ptr) } emacs_value -rep_parser_parse(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *data) +rep_parser_parse +(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *data) { struct parser *parser = env->get_user_ptr(env, *args); @@ -164,9 +175,10 @@ rep_parser_parse(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *data) error_data[0] = env->make_string (env, "INPUT should be a vector of integers", 36); - env->non_local_exit_signal(env, env->intern(env, "wrong-type-argument"), - env->funcall(env, env->intern(env, "list"), - 1, error_data)); + env->non_local_exit_signal + (env, env->intern(env, "wrong-type-argument"), + env->funcall(env, env->intern(env, "list"), + 1, error_data)); return env->intern(env, "nil"); } @@ -178,9 +190,10 @@ rep_parser_parse(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *data) if (buffer == NULL) { error_data[0] = env->make_string(env, "out of memory", 13); - env->non_local_exit_signal(env, env->intern(env, "error"), - env->funcall(env, env->intern(env, "list"), - 1, error_data)); + env->non_local_exit_signal + (env, env->intern(env, "error"), + env->funcall(env, env->intern(env, "list"), + 1, error_data)); return env->intern(env, "nil"); } @@ -209,23 +222,26 @@ rep_parser_parse(emacs_env *env, ptrdiff_t narg, emacs_value *args, void *data) to_big_endian((uint64_t) len * 8, input_len); -struct UnsignedVec input_vec = (struct UnsignedVec) + struct UnsignedVec input_vec = (struct UnsignedVec) { input_len, NULL, buffer }; - struct UnsignedVec *result = parser_parse(parser, &input_vec, &error_vec, (unsigned char) 1); - + struct UnsignedVec *result = + parser_parse(parser, &input_vec, &error_vec, (unsigned char) 1); + free(buffer); uint64_t error_length = from_big_endian(error_vec.len); if (error_length) { - error_data[0] = env->make_string(env, error_vec.data, (ptrdiff_t) error_length); + error_data[0] = + env->make_string(env, error_vec.data, (ptrdiff_t) error_length); clean_signed(&error_vec, 4); - env->non_local_exit_signal(env, env->intern(env, "error"), - env->funcall(env, env->intern(env, "list"), - 1, error_data)); + env->non_local_exit_signal + (env, env->intern(env, "error"), + env->funcall(env, env->intern(env, "list"), + 1, error_data)); return env->intern(env, "nil"); } @@ -258,8 +274,9 @@ emacs_module_init(struct emacs_runtime *ert) "\n\n\(fn grammar_string)", NULL); - env->funcall(env, env->intern(env, "defalias"), - 2, (emacs_value[]){ env->intern(env, "rep-new-parser"), newfunc }); + env->funcall + (env, env->intern(env, "defalias"), 2, + (emacs_value[]){ env->intern(env, "rep-new-parser"), newfunc }); emacs_value recognizefunc = env->make_function (env, 2, 2, rep_parser_recognize, @@ -267,8 +284,11 @@ emacs_module_init(struct emacs_runtime *ert) "\n\n\(fn parser INPUT)", NULL); - env->funcall(env, env->intern(env, "defalias"), - 2, (emacs_value[]){ env->intern(env, "rep-recognize"), recognizefunc }); + env->funcall(env, env->intern(env, "defalias"), 2, + (emacs_value[]) + { + env->intern(env, "rep-recognize"), recognizefunc + }); emacs_value parsefunc = env->make_function (env, 2, 2, rep_parser_parse, @@ -276,8 +296,11 @@ emacs_module_init(struct emacs_runtime *ert) "\n\n\(fn parser input)", NULL); - env->funcall(env, env->intern(env, "defalias"), - 2, (emacs_value[]){ env->intern(env, "rep-parse"), parsefunc }); + env->funcall(env, env->intern(env, "defalias"), 2, + (emacs_value[]) + { + env->intern(env, "rep-parse"), parsefunc + }); env->funcall(env, env->intern(env, "provide"), 1, (emacs_value[]){ env->intern(env, "rep") }); diff --git a/src/helper.h b/src/helper.h index 8be7497..301d221 100644 --- a/src/helper.h +++ b/src/helper.h @@ -36,7 +36,7 @@ parser_parse (struct parser *parser, struct UnsignedVec *input_vec, struct SignedVec *error_vec, - unsigned char reset_p ); + unsigned char reset_p); struct UnsignedVec * parser_parse(struct parser *parser, @@ -72,4 +72,11 @@ struct Label read_label(unsigned char *ptr); void print_label(struct Label label); +// TODO: Add functions for verifying the format of the forest. +// +// And add functions to query the number from the terminal name, or +// the non-terminal name. +// +// And add functions for queryinf information from the forest. + #endif -- cgit v1.2.3-18-g5258