MCPcopy Create free account
hub / github.com/F-Stack/f-stack / cli_script_process

Function cli_script_process

dpdk/examples/ip_pipeline/cli.c:6588–6641  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6586}
6587
6588int
6589cli_script_process(const char *file_name,
6590 size_t msg_in_len_max,
6591 size_t msg_out_len_max)
6592{
6593 char *msg_in = NULL, *msg_out = NULL;
6594 FILE *f = NULL;
6595
6596 /* Check input arguments */
6597 if ((file_name == NULL) ||
6598 (strlen(file_name) == 0) ||
6599 (msg_in_len_max == 0) ||
6600 (msg_out_len_max == 0))
6601 return -EINVAL;
6602
6603 msg_in = malloc(msg_in_len_max + 1);
6604 msg_out = malloc(msg_out_len_max + 1);
6605 if ((msg_in == NULL) ||
6606 (msg_out == NULL)) {
6607 free(msg_out);
6608 free(msg_in);
6609 return -ENOMEM;
6610 }
6611
6612 /* Open input file */
6613 f = fopen(file_name, "r");
6614 if (f == NULL) {
6615 free(msg_out);
6616 free(msg_in);
6617 return -EIO;
6618 }
6619
6620 /* Read file */
6621 for ( ; ; ) {
6622 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
6623 break;
6624
6625 printf("%s", msg_in);
6626 msg_out[0] = 0;
6627
6628 cli_process(msg_in,
6629 msg_out,
6630 msg_out_len_max);
6631
6632 if (strlen(msg_out))
6633 printf("%s", msg_out);
6634 }
6635
6636 /* Close file */
6637 fclose(f);
6638 free(msg_out);
6639 free(msg_in);
6640 return 0;
6641}
6642
6643static int
6644cli_rule_file_process(const char *file_name,

Callers 1

mainFunction · 0.70

Calls 4

mallocFunction · 0.85
cli_processFunction · 0.70
freeFunction · 0.50
printfFunction · 0.50

Tested by

no test coverage detected