Skip to content

Commit

Permalink
Merge branch 'master' of github.com:orangeduck/mpc
Browse files Browse the repository at this point in the history
  • Loading branch information
orangeduck committed Sep 17, 2016
2 parents d6375f8 + 724e9a3 commit 37c12b1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions mpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,37 @@ static mpc_input_t *mpc_input_new_string(const char *filename, const char *strin
return i;
}

static mpc_input_t *mpc_input_new_nstring(const char *filename, const char *string, size_t length) {

mpc_input_t *i = malloc(sizeof(mpc_input_t));

i->filename = malloc(strlen(filename) + 1);
strcpy(i->filename, filename);
i->type = MPC_INPUT_STRING;

i->state = mpc_state_new();

i->string = malloc(length + 1);
strncpy(i->string, string, length);
i->string[length] = '\0';
i->buffer = NULL;
i->file = NULL;

i->suppress = 0;
i->backtrack = 1;
i->marks_num = 0;
i->marks_slots = MPC_INPUT_MARKS_MIN;
i->marks = malloc(sizeof(mpc_state_t) * i->marks_slots);
i->lasts = malloc(sizeof(char) * i->marks_slots);
i->last = '\0';

i->mem_index = 0;
memset(i->mem_full, 0, sizeof(char) * MPC_INPUT_MEM_NUM);

return i;

}

static mpc_input_t *mpc_input_new_pipe(const char *filename, FILE *pipe) {

mpc_input_t *i = malloc(sizeof(mpc_input_t));
Expand Down Expand Up @@ -1223,6 +1254,14 @@ int mpc_parse(const char *filename, const char *string, mpc_parser_t *p, mpc_res
return x;
}

int mpc_nparse(const char *filename, const char *string, size_t length, mpc_parser_t *p, mpc_result_t *r) {
int x;
mpc_input_t *i = mpc_input_new_nstring(filename, string, length);
x = mpc_parse_input(i, p, r);
mpc_input_delete(i);
return x;
}

int mpc_parse_file(const char *filename, FILE *file, mpc_parser_t *p, mpc_result_t *r) {
int x;
mpc_input_t *i = mpc_input_new_file(filename, file);
Expand Down
1 change: 1 addition & 0 deletions mpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct mpc_parser_t;
typedef struct mpc_parser_t mpc_parser_t;

int mpc_parse(const char *filename, const char *string, mpc_parser_t *p, mpc_result_t *r);
int mpc_nparse(const char *filename, const char *string, size_t length, mpc_parser_t *p, mpc_result_t *r);
int mpc_parse_file(const char *filename, FILE *file, mpc_parser_t *p, mpc_result_t *r);
int mpc_parse_pipe(const char *filename, FILE *pipe, mpc_parser_t *p, mpc_result_t *r);
int mpc_parse_contents(const char *filename, mpc_parser_t *p, mpc_result_t *r);
Expand Down

0 comments on commit 37c12b1

Please sign in to comment.