void black_box (int type_of_box) { switch (type_of_box) { case ZERO: case ONE: case EPSILON: /* printf ("node_num:%d\n", node_num); */ add_node (node_num, node_num + 1, 0, 0, 0, 0, 0, 0); if (type_of_box == ZERO) { add_node (node_num, 0, node_num + 1, 0, 0, 0, 0, 0); } else if (type_of_box == ONE) { add_node (node_num, 0, 0, node_num + 1, 0, 0, 0, 0); } else if (type_of_box == EPSILON) { add_node (node_num, node_num + 1, 0, 0, 0, 0, 0, 0); } add_node (node_num, node_num + 1, 0, 0, 0, 0, 0, 0); cur_sub_section.start_node = node_num - 2 - 1; cur_sub_section.end_node = node_num + 3 - 2 - 1; break; case ASTERIX: if (prev_tok == RPAREN) { /* printf ("\t\t\t RPAREN, ASTERIX\n"); */ prev_sub_section.start_node = sub_section_queue[queue_ptr-1].start_node; prev_sub_section.end_node = sub_section_queue[queue_ptr-1].end_node; add_node (node_num, prev_sub_section.end_node, 0, 0, 0, 0, 0, 0); add_node (prev_sub_section.end_node, node_num+1, 0, 0, 0, 0, 0, 0); /* tricky part to deal with 'real' ASTERIX */ cur_sub_section.start_node = prev_sub_section.end_node; cur_sub_section.end_node = node_num; real_node_num_adjust--; debug_print_queue(); } else { /* printf ("\t\t\t just ASTERIX\n"); */ prev_sub_section.start_node = cur_sub_section.start_node; prev_sub_section.end_node = cur_sub_section.end_node; add_node (node_num, prev_sub_section.start_node, 0, 0, 0, 0, 0, 0); add_node (prev_sub_section.start_node, prev_sub_section.end_node + 2, 0, 0, 0, 0, 0, 0); /* tricky part to deal with 'real' ASTERIX */ cur_sub_section.start_node = prev_sub_section.start_node; cur_sub_section.end_node = prev_sub_section.end_node + 1; real_node_num_adjust--; debug_print_queue(); } break; case PLUS: if (prev_tok == RPAREN) { /* printf ("\t\t\t RPAREN, PLUS\n"); */ } else { /* printf ("\t\t\t just PLUS\n"); */ } /* * all this takes care of x + x + y, all the x's but not the last y !!! */ /* transition on E from previous node created to stack.end_node */ /* add_node (node_num, sub_section_stack[stack_ptr-1].end_node, 0, 0, 0, 0, 0, 0); */ /* add_node (nfa[node_num - 1].node_num, sub_section_stack[stack_ptr-1].end_node, 0, 0, 0, 0, 0, 0); */ /* * should also add a transition on E from stack.start_node to first */ debug_print_stack(); break; default: /* printf ("*** black_box() Error, bad type of black box specified\n"); */ exit (0); break; } /* printf ("black_box() completed. start_node=%d end_node=%d\n", cur_sub_section.start_node, cur_sub_section.end_node); */ }
/* event parsing loop freely stolen from Zarf's glk example code */ void debug_monitor() { char commandbuf[256], lastcommand[256]; char *cx, *cmd; int gotline, len, monitor, match; event_t ev; char *parser = "^([cfghlnoqsx])( +([0-9a-f]+))?"; // char *parser = "\\([cghlnqsx]\\)\\( 0\\)?"; char *matched; regex_t preg; size_t nmatch = 4; regmatch_t pmatch[4]; monitor = TRUE; while(monitor) { glk_put_string("\nmonitor>"); // if (cmd) // strncpy(lastcommand, cmd, 256); glk_request_line_event(mainwin, commandbuf, 255, 0); gotline = FALSE; while (!gotline) { glk_select(&ev); if (ev.type == evtype_LineInput) gotline = TRUE; } len = ev.val1; commandbuf[len] = '\0'; for (cx = commandbuf; *cx; cx++) { *cx = glk_char_to_lower(*cx); } /* strip whitespace */ for (cx = commandbuf; *cx == ' '; cx++) { }; cmd = cx; for (cx = commandbuf+len-1; cx >= cmd && *cx == ' '; cx--) { }; *(cx+1) = '\0'; if (*cmd == '\0') { monitor = FALSE; continue; } if ((match = regcomp(&preg, parser, REG_EXTENDED | REG_ICASE)) != 0) { fatal_error("Bad regex\n"); } if ((match = regexec(&preg, cmd, nmatch, pmatch, 0)) != 0) { glk_put_string("pardon? - try 'h' for help\n"); } else { if(match_command("c")) { monitor = FALSE; } else if (match_command("f")) { match_args_and_call(debug_print_callstack, 0xffff) } else if (match_command("g")) { match_args_and_call(debug_print_global, 0xff) } else if (match_command("h")) { debug_print_help(); } else if (match_command("l")) { match_args_and_call(debug_print_local, 0xff) } else if (match_command("n")) { monitor = FALSE; } else if (match_command("o")) { match_args_and_call(debug_print_object, 1); } else if (match_command("x")) { match_args_and_call(debug_print_memory, 0xdeadbeef) } else if (match_command("")) { match_args_and_call(debug_print_zstring, 0) } else if (match_command("q")) { fatal_error("Debugger terminated game."); } else if (match_command("s")) { debug_print_stack(); } else if (match_command("x")) { match_args_and_call(debug_print_memory, 0xdeadbeef) } } regfree(&preg); } }