in src/couch_quickjs/c_src/couchjs.c [450:502]
int main(int argc, const char* argv[])
{
JSContext* view_cx = NULL;
JSContext* ddoc_cx = NULL;
couch_args args = {.stack_size = DEFAULT_STACK_SIZE};
parse_args(argc, argv, &args);
//load_bytecode(&args);
size_t linemax = BUF_SIZE;
char* line = malloc(linemax);
if (!line) {
BAIL("Could not allocate line buffer");
}
int len;
bool do_continue = true;
while (do_continue && (len = linein(&line, &linemax)) != -1) {
if (line[len - 1] != '\n') {
BAIL("linein() didn't end in newline");
}
line[--len] = '\0'; // don't care about the last \n so shorten the string
switch (parse_command(line, len)) {
case CMD_RESET:
view_cx = reset_cx(&args, view_cx);
do_continue = dispatch(view_cx, line, len);
break;
case CMD_DDOC:
if (ddoc_cx == NULL) {
ddoc_cx = reset_cx(&args, NULL);
}
do_continue = dispatch(ddoc_cx, line, len);
break;
case CMD_VIEW:
if (view_cx == NULL) {
view_cx = reset_cx(&args, NULL);
}
do_continue = dispatch(view_cx, line, len);
break;
case CMD_EMPTY:
do_continue = false;
break;
case CMD_LIST:
BAIL("unexpected list subcommand in the main command loop");
}
}
free_cx(view_cx);
free_cx(ddoc_cx);
free(line);
return EXIT_SUCCESS;
}