/* setup the flags and environment to read a new input saves the pointer to the command processing function to use it once the input is completed */ int SlwReadline::readline(const char *msg,cmd_process_t *proc,cmd_complete_t *comp) { ::notice(msg); // update_scroll(); color = PLAIN_COLOR; blank(); // putnch((char*)": ", 0, 0, 2); // SLsmg_gotorc(SLtt_Screen_Rows - 1,0); // SLsmg_write_string((char *)":"); // SLsmg_erase_eol(); memset(command,EOL,MAX_CMDLINE); cmd_process = proc; cmd_complete = comp; commandline = true; set_parser(COMMANDLINE); if(cmd_complete) (*cmd_complete)(env, command); cursor = strlen(command); return 1; }
int main(int argc, char **argv) { char *progname = argv[0]; char *file = NULL; struct grecs_node *tree; int flags = GRECS_NODE_FLAG_DEFAULT; int reduce = 0; int sort = 0; while (--argc) { char *arg = *++argv; if (strcmp(arg, "-locus") == 0) flags |= GRECS_NODE_FLAG_LOCUS; else if (strcmp(arg, "-nopath") == 0) flags &= ~GRECS_NODE_FLAG_PATH; else if (strcmp(arg, "-novalue") == 0) flags &= ~GRECS_NODE_FLAG_VALUE; else if (strncmp(arg, "-delim=", 7) == 0) flags |= arg[7]; else if (strcmp(arg, "-reduce") == 0) reduce = 1; else if (strcmp(arg, "-sort") == 0) sort = 1; else if (strcmp(arg, "-h") == 0) usage(progname, stdout, 0); else if (strcmp(arg, "-list") == 0) { grecs_enumerate_parsers(list_parser, NULL); exit(0); } else if (strncmp(arg, "-list=", 6) == 0) { grecs_enumerate_parsers(find_parser, arg + 6); exit(2); } else if (strncmp(arg, "-type=", 6) == 0) { if (set_parser(arg + 6)) usage(progname, stderr, 1); } else if (strncmp(arg, "-I", 2) == 0) grecs_preproc_add_include_dir(arg+2); else if (strncmp(arg, "-include=", 9) == 0) grecs_preproc_add_include_dir(arg+9); else if (strcmp(arg, "-x") == 0) grecs_gram_trace(1); else if (strcmp(arg, "-X") == 0) grecs_lex_trace(1); else if (arg[0] == '-') usage(progname, stderr, 1); else { file = arg; --argc; break; } } if (!grecs_parser_fun) { fprintf(stderr, "%s: requested type not supported", progname); exit(2); } if (!file) usage(progname, stderr, 1); tree = grecs_parse(file); if (!tree) exit(1); for (; argc; argc--) { char *arg = *++argv; struct grecs_node *node = grecs_parse(arg); if (!node) exit(1); if (grecs_tree_join(tree, node)) { fprintf(stderr, "join failed\n"); exit(1); } grecs_tree_free(node); } if (reduce) grecs_tree_reduce(tree, NULL, 0); if (sort) grecs_tree_sort(tree, node_ident_cmp); grecs_print_node(tree, flags, stdout); fputc('\n', stdout); grecs_tree_free(tree); exit(0); }
int main(int argc, char **argv) { char *progname = argv[0]; char *path = NULL; char *file = NULL; struct grecs_node *tree, *node; int flags = GRECS_NODE_FLAG_DEFAULT; int rc = 2; int reduce = 0; int match = 0; while (--argc) { char *arg = *++argv; if (strcmp(arg, "-locus") == 0) flags |= GRECS_NODE_FLAG_LOCUS; else if (strncmp(arg, "-delim=", 7) == 0) flags |= arg[7]; else if (strcmp(arg, "-reduce") == 0) reduce = 1; else if (strcmp(arg, "-match") == 0) match = 1; else if (strcmp(arg, "-nodesc") == 0) flags &= ~GRECS_NODE_FLAG_DESCEND; else if (strcmp(arg, "-nopath") == 0) flags &= ~GRECS_NODE_FLAG_PATH; else if (strncmp(arg, "-type=", 6) == 0) { if (set_parser(arg + 6)) usage(progname, stderr, 1); } else if (strcmp(arg, "-h") == 0) usage(progname, stdout, 0); else if (arg[0] == '-') usage(progname, stderr, 1); else if (file) { if (path) usage(progname, stderr, 1); else path = arg; } else file = arg; } if (!file || !path || argc) usage(progname, stderr, 1); tree = grecs_parse(file); if (!tree) exit(1); if (reduce) grecs_tree_reduce(tree, NULL, 0); if (match) { grecs_match_buf_t match_buf; for (node = grecs_match_first(tree, path, &match_buf); node; node = grecs_match_next(match_buf)) { rc = 0; grecs_print_node(node, flags, stdout); fputc('\n', stdout); } grecs_match_buf_free(match_buf); } else { for (node = tree; node; node = node->next) { node = grecs_find_node(node, path); if (!node) break; rc = 0; grecs_print_node(node, flags, stdout); fputc('\n', stdout); } } grecs_tree_free(tree); exit(rc); }
// read a command from commandline // handles completion and execution from function pointers previously setup bool SlwReadline::parser_commandline(int key) { int res, c; bool parsres = true; Entry *entr = NULL; commandline = true; // don't print statusline /* =============== console command input */ if(cursor>MAX_CMDLINE) { error("command too long, can't type more."); return(parsres); } //::func("input key: %i",key); // SLsmg_set_color(PLAIN_COLOR); color = PLAIN_COLOR; switch(key) { case SL_KEY_ENTER: case KEY_ENTER: // a blank commandline aborts the input if(command[0]==EOL || command[0]==EOT) { set_parser(DEFAULT); break; } // otherwise process the input res = (*cmd_process)(env,command); if(res<0) break; // reset the parser set_parser(DEFAULT); // save in commandline history entr = new Entry(); entr->data = strdup(command); history.append( entr ); if(history.len()>32) // histsize delete history.begin(); // cleanup the command memset(command, EOL, MAX_CMDLINE); break; case SL_KEY_UP: // pick from history entr = history.selected(); if(!entr) { // select the latest entr = history.end(); if(entr) entr->sel(true); } else { entr = entr->prev; if(entr) { history.sel(0); entr->sel(true); } } if(!entr) break; // no hist strncpy(command,(char*)entr->data,MAX_CMDLINE); // type the command on the consol cursor = strlen(command); // GOTO_CURSOR; break; case SL_KEY_DOWN: // pick from history if(!entr) break; if(!entr->next) break; entr = entr->next; strncpy(command,(char*)entr->data,MAX_CMDLINE); // type the command on the console cursor = strlen(command); // GOTO_CURSOR; break; case KEY_CTRL_G: set_parser(DEFAULT); // cleanup the command memset(command, EOL, MAX_CMDLINE); break; case KEY_TAB: if(!cmd_complete) break; if(command[0]=='\n') command[0]=0x0; res = (*cmd_complete)(env,command); if(!res) break; // else if(res==1) { // exact match! // putnch(command,3,0,0); // cursor = strlen(command); // } // update_scroll(); // type the command on the console cursor = strlen(command); // GOTO_CURSOR; break; case KEY_BACKSPACE: case KEY_BACKSPACE_APPLE: case KEY_BACKSPACE_SOMETIMES: if(!cursor) break; for(c=cursor;c<MAX_CMDLINE;c++) { command[c-1] = command[c]; if(command[c]==EOL) break; } cursor--; // putnch(command,3,0,cursor); // SLsmg_gotorc(SLtt_Screen_Rows - 1,cursor); break; /* the following ctrl combos are to imitate the Emacs commandline behaviour c-e goto end of line, c-d delete, c-k delete until end of line c-u delete previous until beginning of line */ case SL_KEY_LEFT: if(cursor) cursor--; // gotoxy(cursor,0); break; case SL_KEY_RIGHT: if(command[cursor]) cursor++; // gotoxy(cursor,0); break; case KEY_CTRL_D: for(c=cursor;command[c]!=EOL;c++) command[c] = command[c+1]; // putnch(command,1,0,0); // gotoxy(cursor,0); // GOTO_CURSOR; // SLsmg_write_string(&command[cursor]); // SLsmg_erase_eol(); // GOTO_CURSOR; break; case KEY_CTRL_A: case KEY_HOME: cursor=0; // gotoxy(cursor,0); break; case KEY_CTRL_E: while(command[cursor]!=EOL) cursor++; // gotoxy(cursor,0); break; case KEY_CTRL_K: for(c=cursor;command[c]!=EOL;c++) command[c] = EOL; // putnch(command,1,0,0); // gotoxy(cursor,0); break; case KEY_CTRL_U: for(c=0;command[cursor+c]!=EOL;c++) command[c] = command[cursor+c]; for(;command[c]!=EOL;c++) command[c] = EOL; cursor=0; // putnch(command,1,0,0); // gotoxy(cursor,0); break; default: parsres = false; break; } /* add char at cursor position insert mode FIX ME! must save temporarly the chars to advance */ if( key >= 32 && key < 127) { for(c=cursor;command[c]!=EOL;c++); // go to the EOL command[c+1] = EOL; // be sure we have a EOL for(;c>cursor;c--) command[c] = command[c-1]; // move backwards switching right command[cursor] = key; // insert new char cursor++; parsres = true; } // gotoxy(cursor+2,0); return(parsres); }
bool SlwReadline::parser_movelayer(int key) { bool res = true; commandline = false; // print statusline // get the one selected Layer *layer = (Layer*)env->screens.selected()->layers.selected(); if(!layer) { env->screens.selected()->layers.begin(); layer->sel(true); } switch(key) { // XXX(shammash): set zoom/rotate/position are closures so they don't get // executed immediately. zoom_x, zoom_y, rotate and so on might not contain a // value up-to-date // zoom case KEY_PLUS: layer->set_zoom( layer->zoom_x + 0.01, layer->zoom_y + 0.01); break; case KEY_MINUS: layer->set_zoom( layer->zoom_x - 0.01, layer->zoom_y - 0.01); break; case '.': layer->set_zoom(1,1); break; // rotation case '<': layer->set_rotate( layer->rotate + 0.5 ); break; case '>': layer->set_rotate( layer->rotate - 0.5 ); break; case ',': layer->set_rotate(0); break; case 'z': layer->antialias = !layer->antialias; break; case '8': case 'k': case SL_KEY_UP: layer->set_position(layer->geo.x,layer->geo.y-movestep); break; case '2': case 'j': case SL_KEY_DOWN: layer->set_position(layer->geo.x,layer->geo.y+movestep); break; case '4': case 'h': case SL_KEY_LEFT: layer->set_position(layer->geo.x-movestep,layer->geo.y); break; case '6': case 'l': case SL_KEY_RIGHT: layer->set_position(layer->geo.x+movestep,layer->geo.y); break; case '7': case 'y': // up+left layer->set_position(layer->geo.x-movestep,layer->geo.y-movestep); break; case '9': case 'u': // up+right layer->set_position(layer->geo.x+movestep,layer->geo.y-movestep); break; case '1': case 'b': // down+left layer->set_position(layer->geo.x-movestep,layer->geo.y+movestep); break; case '3': case 'n': // down+right layer->set_position(layer->geo.x+movestep,layer->geo.y+movestep); break; case '5': case KEY_SPACE: // place at the center layer->set_position ( (env->screens.selected()->geo.w - layer->geo.w)/2, (env->screens.selected()->geo.h - layer->geo.h)/2 ); break; case SL_KEY_ENTER: case KEY_ENTER: case KEY_CTRL_I: ::act("layer repositioned"); set_parser(DEFAULT); break; default: res = false; break; } return(res); }
bool SlwReadline::parser_default(int key) { Entry *le, *fe; bool res = true; commandline = false; // print statusline // ::func("pressed %u",key); if(env->screens.selected()->layers.len() > 0) { // there are layers // get the one selected le = env->screens.selected()->layers.selected(); if(!le) { env->screens.selected()->layers.begin(); le->sel(true); } fe = ((Layer*)le)->filters.selected(); // switch over operations and perform switch(key) { // case KEY_CTRL_M: { // Layer *l=((Layer*)le); // if (l->fps->get() > 0) // l->set_fps(0); // else // if (l->fps_old > 0) // l->set_fps(l->fps_old); // else // l->set_fps(env->fps_speed); // l->signal_feed(); // ::notice("Layer.set_fps(%f)", l->fps); // } // break; case KEY_CTRL_E: readline("add new Effect - press TAB for completion:", &console_filter_selection, &console_filter_completion); break; case KEY_CTRL_P: readline("set parameter - press TAB for completion:", &console_param_selection, &console_param_completion); break; case KEY_CTRL_B: readline("select Blit mode for the selected Layer - press TAB for completion:", &console_blit_selection, &console_blit_completion); break; case KEY_CTRL_V: readline("select Blit parameter value - press TAB for completion:", &console_blit_param_selection, &console_blit_param_completion); break; #if defined WITH_TEXTLAYER case KEY_CTRL_Y: if(((Layer*)le)->type == Layer::TEXT) readline("print a new word in Text Layer, type your words:", &console_print_text_layer,NULL); break; #endif case KEY_CTRL_A: set_parser(MOVELAYER); break; // case KEY_CTRL_J: // ::notice("JAZZ mode activated, press keys to pulse layers"); // parser = JAZZ; // break; default: // ((Layer*)le)->keypress( key ); break; } } switch(key) { case KEY_CTRL_H: case KEY_CTRL_H_APPLE: case '?': notice("Below are listed the Hotkeys available in FreeJ console"); act("pressing [Tab] in most situations lists choices and completes commands"); act("Arrow keys browse across Layers and Filters"); act("Space de/activates Layers and Filters selected"); act("+ and - move Layers and Effects up and down the chains"); act(" @ = Switch on/off screen cleanup (blank frame at every tick)"); act("ctrl+o = Open a File (will prompt for path to file)"); act("ctrl+g = Create a Generator (tab to list available)"); act("ctrl+t = Add a Text layer (will prompt for text)"); act("ctrl+a = Move Rotate and Zoom a Layer"); act("ctrl+e = Add a Filter to a Layer"); act("ctrl+p = Set Parameters for a Layer or Filter"); act("ctrl+b = Select the Blit for a Layer (tab completed)"); act("ctrl+v = Set Parameters for of a Layer's Blit"); act("ctrl+x = Execute a javascript command"); act("ctrl+j = Load and execute a javascript file"); act("ctrl+f = Switch Fullscreen on/off"); act("ctrl+c = Quit FreeJ"); break; /* case '!': env->osd.active = !env->osd.active; break; */ case '@': env->clear_all = !env->clear_all; break; /* case '<': // decrease global fps if(env->fps_speed>1) env->fps_speed--; else break; // env->set_fps_interval(env->fps_speed); // ::act("Frames per second decreased to %i",env->fps_speed); break; case '>': // increase global fps env->fps_speed++; // env->set_fps_interval(env->fps_speed); // ::act("Frames per second increased to %i",env->fps_speed); break; */ case KEY_CTRL_F: env->screens.selected()->fullscreen(); break; case KEY_CTRL_X: readline("execute javascript command:", &console_exec_script_command,NULL); break; case KEY_CTRL_J: readline("load and execute a javascript file:", &console_exec_script, &console_filebrowse_completion); break; case KEY_CTRL_O: readline("open a file in a new Layer:", &console_open_layer,&console_filebrowse_completion); break; case KEY_CTRL_G: readline("create a generator in a new Layer:", &console_generator_selection, &console_generator_completion); break; #if defined WITH_TEXTLAYER case KEY_CTRL_T: readline("create a new Text Layer, type your words:", &console_open_text_layer,NULL); break; #endif default: res = false; break; } return(res); }
/** * Test selection part of UI. Lists tests for this user * and awaits for selection. Runs test if it is found and * asks whether to rerun test or to quit or to return to main. * * @param user username to use for loading preferences * * @return TRUE if preferences were found and loaded */ gboolean run_test_selection(gchar* user) { user_preference* prefs = NULL; gchar* temp = (gchar*)g_try_malloc(TEMPLEN); gboolean rval = TRUE; // Load preferences for this user if((prefs = load_preferences(user))) { g_print("%d test%s loaded for %s:\n", g_sequence_get_length(prefs->tests), g_sequence_get_length(prefs->tests) > 1 ? "s " : "", prefs->username); gboolean loop = TRUE, rerun = FALSE; gchar tnumber = '\0'; // Run main loop for test selection while(loop) { gint idx = 0; GSequenceIter* iter = NULL; // If rerun of test was not selected print list of tests if(!rerun) { g_print("id\tname\tfiles\turl\n"); g_print("-------------------------------------------------------------------------------\n"); // Go through list of tests for(iter = g_sequence_get_begin_iter(prefs->tests); !g_sequence_iter_is_end(iter) ; iter = g_sequence_iter_next(iter)) { testcase* t = (testcase*)g_sequence_get(iter); // Is a test, print details if(t) { g_print(" %d\t%s\t%d\t%s\n",idx+1,t->name,g_hash_table_size(t->files),t->URL); idx++; } } g_print("\nSelect test id to run, q to quit, u to return to user selection: "); // get a char tnumber = getc(stdin); // Consume newline markers if(tnumber != '\n') temp = fgets(temp,TEMPLEN,stdin); } // Test rerun was selected else { g_print("Starting rerun of test %d\n",g_ascii_digit_value(tnumber)); rerun = FALSE; } // If input is a digit between [1...amount of tests] if(g_ascii_isdigit(tnumber) && g_ascii_digit_value(tnumber) <= g_sequence_get_length(prefs->tests) && g_ascii_digit_value(tnumber) > 0) { // Set default parser set_parser(prefs->parser); // Get iterator to at position in testlist GSequenceIter* testpos = g_sequence_get_iter_at_pos(prefs->tests, g_ascii_digit_value(tnumber)-1); // Get test testcase* test = (testcase*)g_sequence_get(testpos); g_print("Running test %c:\"%s\" to %s (with %d files)\n", tnumber,test->name,test->URL,g_hash_table_size(test->files)); // Initialize tests_initialize(test); // Run if(tests_run_test(prefs->username,test)) g_print("Test %s completed with failures.\n",test->name); else g_print("Test %s complete\n",test->name); // Clear and reset test tests_reset(test); g_print("Redo test (r) or quit (q) or go to main (m) or return to user selection (u): "); // Get char gchar response = getc(stdin); switch (response) { case 'r': rerun = TRUE; break; case 'q': loop = FALSE; break; case 'm': g_print("\n\n"); break; case 'u': loop = FALSE; rval = FALSE; break; default: g_print("Invalid selection. Return to main.\n"); rerun = FALSE; break; } // switch // Consume newline markers if(response != '\n') temp = fgets(temp,TEMPLEN,stdin); } // if else if(tnumber == 'q') loop = FALSE; else if(tnumber == 'u') { loop = FALSE; rval = FALSE; } else g_print("Invalid test id (%d)\n",g_ascii_digit_value(tnumber)); iter = NULL; } // while destroy_preferences(); } // if else { g_print("Preferences for user \"%s\" were not found\n",user); rval = FALSE; } g_free(temp); return rval; }
/* See doc string for svn_ra_neon__parsed_request. */ static svn_error_t * parsed_request(svn_ra_neon__request_t *req, svn_ra_neon__session_t *ras, const char *method, const char *url, const char *body, apr_file_t *body_file, void set_parser(ne_xml_parser *parser, void *baton), svn_ra_neon__startelm_cb_t startelm_cb, svn_ra_neon__cdata_cb_t cdata_cb, svn_ra_neon__endelm_cb_t endelm_cb, void *baton, apr_hash_t *extra_headers, int *status_code, svn_boolean_t spool_response, apr_pool_t *pool) { ne_xml_parser *success_parser = NULL; spool_reader_baton_t spool_reader_baton; if (body == NULL) SVN_ERR(svn_ra_neon__set_neon_body_provider(req, body_file)); /* ### use a symbolic name somewhere for this MIME type? */ ne_add_request_header(req->ne_req, "Content-Type", "text/xml"); /* create a parser to read the normal response body */ success_parser = svn_ra_neon__xml_parser_create(req, NULL, startelm_cb, cdata_cb, endelm_cb, baton); /* if our caller is interested in having access to this parser, call the SET_PARSER callback with BATON. */ if (set_parser != NULL) set_parser(success_parser, baton); /* Register the "main" accepter and body-reader with the request -- the one to use when the HTTP status is 2XX. If we are spooling the response to disk first, we use our custom spool reader. */ if (spool_response) { /* Blow the temp-file away as soon as we eliminate the entire request */ SVN_ERR(svn_io_open_unique_file3(&spool_reader_baton.spool_file, &spool_reader_baton.spool_file_name, NULL, svn_io_file_del_on_pool_cleanup, req->pool, pool)); spool_reader_baton.req = req; svn_ra_neon__add_response_body_reader(req, ne_accept_2xx, spool_reader, &spool_reader_baton); } else attach_ne_body_reader(req, ne_accept_2xx, cancellation_callback, get_cancellation_baton(req, ne_xml_parse_v, success_parser, pool)); /* run the request and get the resulting status code. */ SVN_ERR(svn_ra_neon__request_dispatch( status_code, req, extra_headers, body, (strcmp(method, "PROPFIND") == 0) ? 207 : 200, 0, pool)); if (spool_response) { /* All done with the temporary file we spooled the response into. */ (void) apr_file_close(spool_reader_baton.spool_file); /* The success parser may set an error value in req->err */ SVN_RA_NEON__REQ_ERR (req, parse_spool_file(ras, spool_reader_baton.spool_file_name, success_parser, req->pool)); if (req->err) { svn_error_compose(req->err, svn_error_createf (SVN_ERR_RA_DAV_REQUEST_FAILED, NULL, _("Error reading spooled %s request response"), method)); return req->err; } } SVN_ERR(svn_ra_neon__check_parse_error(method, success_parser, url)); return SVN_NO_ERROR; }