@@ -282,20 +282,6 @@ libyang_verbclb(LY_LOG_LEVEL level, const char *msg, const char *data_path, cons
282282 fprintf (stderr , "libyang %s Memory allocation failed.\n" , levstr );
283283}
284284
285- static struct yl_schema_features *
286- get_features_not_applied (const struct ly_set * fset )
287- {
288- for (uint32_t u = 0 ; u < fset -> count ; ++ u ) {
289- struct yl_schema_features * sf = fset -> objs [u ];
290-
291- if (!sf -> applied ) {
292- return sf ;
293- }
294- }
295-
296- return NULL ;
297- }
298-
299285/**
300286 * @brief Create the libyang context.
301287 *
@@ -331,6 +317,22 @@ create_ly_context(const char *yang_lib_file, const char *searchpaths, struct ly_
331317 return 0 ;
332318}
333319
320+ static struct yl_schema_features *
321+ get_features_not_applied (const struct ly_set * fset )
322+ {
323+ struct yl_schema_features * sf ;
324+ uint32_t u ;
325+
326+ for (u = 0 ; u < fset -> count ; ++ u ) {
327+ sf = fset -> objs [u ];
328+ if (!sf -> applied ) {
329+ return sf ;
330+ }
331+ }
332+
333+ return NULL ;
334+ }
335+
334336/**
335337 * @brief Implement module if some feature has not been applied.
336338 *
@@ -339,7 +341,7 @@ create_ly_context(const char *yang_lib_file, const char *searchpaths, struct ly_
339341 * @return 0 on success.
340342 */
341343static int
342- apply_features (struct ly_set * schema_features , struct ly_ctx * ctx )
344+ apply_features (const struct ly_set * schema_features , struct ly_ctx * ctx )
343345{
344346 struct yl_schema_features * sf ;
345347 struct lys_module * mod ;
@@ -374,19 +376,19 @@ apply_features(struct ly_set *schema_features, struct ly_ctx *ctx)
374376 * @param[in] argv Strings from command line.
375377 * @param[in] optind Index to the first input file in @p argv.
376378 * @param[in] data_in_format Specified input data format.
377- * @param[in,out] ctx Context for libyang.
379+ * @param[in,out] ctx Context for libyang, is updated .
378380 * @param[in,out] yo Options for yanglint.
379381 * @return 0 on success.
380382 */
381383static int
382- fill_context_inputs (int argc , char * argv [], int optind , LYD_FORMAT data_in_format , struct ly_ctx * ctx ,
383- struct yl_opt * yo )
384+ process_files (int argc , char * argv [], int optind , LYD_FORMAT data_in_format , struct ly_ctx * ctx , struct yl_opt * yo )
384385{
385386 char * filepath = NULL ;
386387 LYS_INFORMAT format_schema ;
387388 LYD_FORMAT format_data ;
389+ int i ;
388390
389- for (int i = 0 ; i < argc - optind ; i ++ ) {
391+ for (i = 0 ; i < argc - optind ; i ++ ) {
390392 format_schema = LYS_IN_UNKNOWN ;
391393 format_data = data_in_format ;
392394
@@ -410,7 +412,7 @@ fill_context_inputs(int argc, char *argv[], int optind, LYD_FORMAT data_in_forma
410412 }
411413 }
412414
413- /* Check that all specified features were applied, apply now if possible. */
415+ /* check that all specified features were applied, apply now if possible */
414416 if (apply_features (& yo -> schema_features , ctx )) {
415417 return -1 ;
416418 }
@@ -456,12 +458,16 @@ set_debug_groups(char *groups, struct yl_opt *yo)
456458/**
457459 * @brief Process command line options and store the settings into the context.
458460 *
459- * return -1 in case of error;
460- * return 0 in case of success and ready to process
461- * return 1 in case of success, but expect to exit.
461+ * @param[in] argc Argument count.
462+ * @param[in] argv Argument array.
463+ * @param[out] yo Yanglint options to fill.
464+ * @param[out] ctx Created context.
465+ * @return -1 in case of error;
466+ * @return 0 in case of success and ready to process
467+ * @return 1 in case of success, but expect to exit.
462468 */
463469static int
464- fill_context (int argc , char * argv [], struct yl_opt * yo , struct ly_ctx * * ctx )
470+ process_args (int argc , char * argv [], struct yl_opt * yo , struct ly_ctx * * ctx )
465471{
466472 int opt , opt_index ;
467473 struct option options [] = {
@@ -495,7 +501,7 @@ fill_context(int argc, char *argv[], struct yl_opt *yo, struct ly_ctx **ctx)
495501 {"extended-leafref" , no_argument , NULL , 'X' },
496502 {"json-null" , no_argument , NULL , 'J' },
497503 {"debug" , required_argument , NULL , 'G' },
498- {NULL , 0 , NULL , 0 }
504+ {NULL , 0 , NULL , 0 }
499505 };
500506 uint8_t data_type_set = 0 ;
501507
@@ -720,18 +726,18 @@ fill_context(int argc, char *argv[], struct yl_opt *yo, struct ly_ctx **ctx)
720726 return -1 ;
721727 }
722728
723- /* Create the libyang context. */
729+ /* create the libyang context */
724730 if (create_ly_context (yo -> yang_lib_file , yo -> searchpaths , & yo -> schema_features , & yo -> ctx_options , ctx )) {
725731 return -1 ;
726732 }
727733
728- /* Set callback providing run-time extension instance data. */
734+ /* set callback providing run-time extension instance data */
729735 if (yo -> schema_context_filename ) {
730736 ly_ctx_set_ext_data_clb (* ctx , ext_data_clb , yo -> schema_context_filename );
731737 }
732738
733- /* Schema modules and data files are just checked and prepared into internal structures for further processing. */
734- if (fill_context_inputs (argc , argv , optind , yo -> data_in_format , * ctx , yo )) {
739+ /* schema modules are parsed, data files are just checked and prepared into internal structures for further processing */
740+ if (process_files (argc , argv , optind , yo -> data_in_format , * ctx , yo )) {
735741 return -1 ;
736742 }
737743
@@ -758,23 +764,19 @@ main_ni(int argc, char *argv[])
758764 int ret = EXIT_SUCCESS , r ;
759765 struct yl_opt yo = {0 };
760766 struct ly_ctx * ctx = NULL ;
761- char * features_output = NULL ;
762- struct ly_set set = {0 };
763767 uint32_t u ;
764768
765769 /* set callback for printing libyang messages */
766770 ly_set_log_clb (libyang_verbclb );
767771
768- r = fill_context (argc , argv , & yo , & ctx );
772+ r = process_args (argc , argv , & yo , & ctx );
769773 if (r < 0 ) {
770774 ret = EXIT_FAILURE ;
771775 }
772776 if (r ) {
773777 goto cleanup ;
774778 }
775779
776- /* do the required job - parse, validate, print */
777-
778780 if (yo .list ) {
779781 /* print the list of schemas */
780782 ret = cmd_list_exec (& ctx , & yo , NULL );
@@ -812,11 +814,7 @@ main_ni(int argc, char *argv[])
812814 }
813815
814816cleanup :
815- /* cleanup */
816817 yl_opt_erase (& yo );
817818 ly_ctx_destroy (ctx );
818- free (features_output );
819- ly_set_erase (& set , NULL );
820-
821819 return ret ;
822820}
0 commit comments