Skip to content

Commit

Permalink
Read script file by fgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Shylock-Hg committed Aug 22, 2018
1 parent 48023d2 commit b0f7d75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
18 changes: 11 additions & 7 deletions src/at_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,23 @@ void at_cmd_execute_script(at_cmd_context_t * context, const char * file){
FILE * stream = fopen(file, "r");
//char * buffer = malloc(context->at_cmd_len + context->at_cmd_param_len + 47);
char buffer[1024] = {0};
size_t len = 0;
at_cmd_xrecord_queue_t * xrecords = queue_class_new(sizeof(at_cmd_xrecord_t));
/*
while(NULL != fgets(buffer,
context->at_cmd_len + context->at_cmd_param_len + 47, stream)){
while(NULL != fgets(buffer, sizeof(buffer)-1, stream)){
at_cmd_FSM_gen_xrecord_queue_4_record(context, xrecords, buffer);

//at_cmd_xrecord_queue_log(xrecords);
}
/*
do{
len = fread(buffer, sizeof(char), sizeof(buffer)-1, stream);
//printf("read %ld\n", len);
buffer[len] = '\0';
at_cmd_FSM_gen_xrecord_queue_4_record(context, xrecords, buffer);
at_cmd_xrecord_queue_log(xrecords);
}while((sizeof(buffer)-1) <= len);
*/
fread(buffer, sizeof(buffer), sizeof(buffer), stream);
at_cmd_FSM_gen_xrecord_queue_4_record(context, xrecords, buffer);

at_cmd_execute(context, xrecords);
queue_class_release(xrecords);

Expand Down
8 changes: 2 additions & 6 deletions stdlog
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ empty list
empty list
exec hello!
exec hi!
parameters :`1`-`;hello;
` `1`-`;wo;rld`!
parameters :`0`-`hi` `1`-`shy;lo
ck`!
parameters :`1`-`;hello;` `1`-`;wo;rld`!
parameters :`0`-`hi` `1`-`shy;lock`!
parameters :`0`-`hello` `0`-`world`!
read hello!
read hi!
read hello!
exec hello!
parameters :`0`-`hello` `0`-`world`!
parameters :`1`-`hah;ah
` `0`-`shylock`!
parameters :`0`-`hello` `0`-`world`!
exec hello!
read hello!
Expand Down
4 changes: 1 addition & 3 deletions test.at
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
AT+HELLO;+HI;+HELLO=";hello;
",";wo;rld";+HI=hi,"shy;lo
ck"
AT+HELLO;+HI;+HELLO=";hello;",";wo;rld";+HI=hi,"shy;lock"
AT+HELLO=hello,world;+HELLO?;+HI?
AT+HELLO?;+HELLO;+HI=?
AT+HELLO=?;+HELLO=?;+HELLO=hello,world;+HI="hah;ah
Expand Down

0 comments on commit b0f7d75

Please sign in to comment.