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

Function cli_script_process

dpdk/examples/pipeline/cli.c:4050–4105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4048}
4049
4050int
4051cli_script_process(const char *file_name,
4052 size_t msg_in_len_max,
4053 size_t msg_out_len_max,
4054 void *obj)
4055{
4056 char *msg_in = NULL, *msg_out = NULL;
4057 FILE *f = NULL;
4058
4059 /* Check input arguments */
4060 if ((file_name == NULL) ||
4061 (strlen(file_name) == 0) ||
4062 (msg_in_len_max == 0) ||
4063 (msg_out_len_max == 0))
4064 return -EINVAL;
4065
4066 msg_in = malloc(msg_in_len_max + 1);
4067 msg_out = malloc(msg_out_len_max + 1);
4068 if ((msg_in == NULL) ||
4069 (msg_out == NULL)) {
4070 free(msg_out);
4071 free(msg_in);
4072 return -ENOMEM;
4073 }
4074
4075 /* Open input file */
4076 f = fopen(file_name, "r");
4077 if (f == NULL) {
4078 free(msg_out);
4079 free(msg_in);
4080 return -EIO;
4081 }
4082
4083 /* Read file */
4084 for ( ; ; ) {
4085 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
4086 break;
4087
4088 printf("%s", msg_in);
4089 msg_out[0] = 0;
4090
4091 cli_process(msg_in,
4092 msg_out,
4093 msg_out_len_max,
4094 obj);
4095
4096 if (strlen(msg_out))
4097 printf("%s", msg_out);
4098 }
4099
4100 /* Close file */
4101 fclose(f);
4102 free(msg_out);
4103 free(msg_in);
4104 return 0;
4105}

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