static void sig_complete_erase(WINDOW_REC *window, const char *word, const char *linestart) { const char *cmdchars; char *line, *cmd, *args, *signal; if (*linestart == '\0') return; /* we only want to check for commands */ cmdchars = settings_get_str("cmdchars"); cmdchars = strchr(cmdchars, *linestart); if (cmdchars == NULL) return; /* check if there's aliases */ line = linestart[1] == *cmdchars ? g_strdup(linestart+2) : expand_aliases(linestart+1); cmd = line_get_command(line, &args, FALSE); if (cmd == NULL) { g_free(line); return; } signal = g_strconcat("complete erase command ", cmd, NULL); signal_emit(signal, 3, window, word, args); g_free(signal); g_free(cmd); g_free(line); }
void process_userinput(char *_line) { static char *line,*line2,*match = "./BitcoinDarkd SuperNET '"; char plugin[512],ipaddr[1024],method[512],*cmdstr,*retstr; cJSON *json; int len,timeout,broadcastflag = 0; len = (int32_t)strlen(match); if ( _line[strlen(_line)-1] == '\'' && strncmp(_line,match,len) == 0 ) { _line[strlen(_line)-1] = 0; _line += len; } if ( (json= cJSON_Parse(_line)) != 0 ) { char *process_nn_message(int32_t sock,char *jsonstr); free_json(json); char *SuperNET_JSON(char *jsonstr); retstr = SuperNET_JSON(_line); //retstr = process_nn_message(-1,line); //retstr = nn_loadbalanced((uint8_t *)line,(int32_t)strlen(line)+1); fprintf(stderr,"console.(%s) -> (%s)\n",_line,retstr); return; } else printf("cant parse.(%s)\n",line); printf("[%s]\n",_line); if ( line == 0 ) line = calloc(1,65536), line2 = calloc(1,65536); expand_aliases(line,line2,65536,_line); if ( (line= localcommand(line)) == 0 ) return; if ( line[0] == '!' ) broadcastflag = 1, line++; settoken(ipaddr,line); printf("expands to: %s [%s] %s\n",broadcastflag != 0 ? "broadcast": "",line,ipaddr); if ( is_ipaddr(ipaddr) != 0 ) { line += strlen(ipaddr) + 1; if ( (cmdstr = parse_expandedline(plugin,sizeof(plugin),method,&timeout,line,broadcastflag)) != 0 ) { printf("ipaddr.(%s) (%s)\n",ipaddr,line); //retstr = nn_direct(ipaddr,(uint8_t *)line,(int32_t)strlen(line)+1); printf("deprecated (%s) -> (%s)\n",line,cmdstr); free(cmdstr); } return; } if ( (cmdstr= parse_expandedline(plugin,sizeof(plugin),method,&timeout,line,broadcastflag)) != 0 ) { retstr = process_user_json(plugin,method,cmdstr,broadcastflag,timeout != 0 ? timeout : SUPERNET.PLUGINTIMEOUT); printf("CONSOLE (%s) -> (%s) -> (%s)\n",line,cmdstr,retstr); free(cmdstr); } }
void process_userinput(char *_line) { static char *line,*line2; char plugin[512],ipaddr[1024],method[512],*cmdstr,*retstr; cJSON *json; int timeout,broadcastflag = 0; printf("[%s]\n",_line); if ( line == 0 ) line = calloc(1,65536), line2 = calloc(1,65536); expand_aliases(line,line2,65536,_line); if ( (line= localcommand(line)) == 0 ) return; if ( line[0] == '!' ) broadcastflag = 1, line++; if ( (json= cJSON_Parse(line)) != 0 ) { char *process_nn_message(int32_t sock,char *jsonstr); free_json(json); retstr = process_nn_message(-1,line); //retstr = nn_loadbalanced((uint8_t *)line,(int32_t)strlen(line)+1); printf("console.(%s) -> (%s)\n",line,retstr); return; } settoken(ipaddr,line); printf("expands to: %s [%s] %s\n",broadcastflag != 0 ? "broadcast": "",line,ipaddr); if ( is_ipaddr(ipaddr) != 0 ) { line += strlen(ipaddr) + 1; if ( (cmdstr = parse_expandedline(plugin,method,&timeout,line,broadcastflag)) != 0 ) { printf("ipaddr.(%s) (%s)\n",ipaddr,line); //retstr = nn_direct(ipaddr,(uint8_t *)line,(int32_t)strlen(line)+1); printf("deprecated (%s) -> (%s)\n",line,cmdstr); free(cmdstr); } return; } if ( (cmdstr= parse_expandedline(plugin,method,&timeout,line,broadcastflag)) != 0 ) { retstr = process_user_json(plugin,method,cmdstr,broadcastflag,timeout != 0 ? timeout : SUPERNET.PLUGINTIMEOUT); printf("CONSOLE (%s) -> (%s) -> (%s)\n",line,cmdstr,retstr); free(cmdstr); } }
char *dealias_command( char *command, Alias *aliases ) { List *commands; List *entry; char *aliased_cmd; char *result = strdup( "" ); /* Split the command into a list of simple commands. Expand any aliases in each of these, and accumulate all of these into a single string.*/ commands = split_into_simple_commands( command ); for ( entry = commands; entry != NULL; entry = entry->next ) { aliased_cmd = expand_aliases( strdup( entry->contents ), 0, aliases ); result = append_dup_string( result, aliased_cmd ); free( aliased_cmd ); } return result; }
// // This is the main entry point for RedBoot // void cyg_start(void) { int res = 0; bool prompt = true; static char line[CYGPKG_REDBOOT_MAX_CMD_LINE]; char *command; struct cmd *cmd; int cur; struct init_tab_entry *init_entry; // Make sure the channels are properly initialized. diag_init_putc(_mon_write_char); hal_if_diag_init(); // Force console to output raw text - but remember the old setting // so it can be restored if interaction with a debugger is // required. cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL); #ifdef CYGPKG_REDBOOT_ANY_CONSOLE console_selected = false; #endif console_echo = true; CYGACC_CALL_IF_DELAY_US((cyg_int32)2*100000); ram_start = (unsigned char *)CYGMEM_REGION_ram; ram_end = (unsigned char *)(CYGMEM_REGION_ram+CYGMEM_REGION_ram_SIZE); #ifdef HAL_MEM_REAL_REGION_TOP { unsigned char *ram_end_tmp = ram_end; ram_end = HAL_MEM_REAL_REGION_TOP( ram_end_tmp ); } #endif #ifdef CYGMEM_SECTION_heap1 workspace_start = (unsigned char *)CYGMEM_SECTION_heap1; workspace_end = (unsigned char *)(CYGMEM_SECTION_heap1+CYGMEM_SECTION_heap1_SIZE); workspace_size = CYGMEM_SECTION_heap1_SIZE; #else workspace_start = (unsigned char *)CYGMEM_REGION_ram; workspace_end = (unsigned char *)(CYGMEM_REGION_ram+CYGMEM_REGION_ram_SIZE); workspace_size = CYGMEM_REGION_ram_SIZE; #endif if ( ram_end < workspace_end ) { // when *less* SDRAM is installed than the possible maximum, // but the heap1 region remains greater... workspace_end = ram_end; workspace_size = workspace_end - workspace_start; } bist(); for (init_entry = __RedBoot_INIT_TAB__; init_entry != &__RedBoot_INIT_TAB_END__; init_entry++) { (*init_entry->fun)(); } user_ram_start = workspace_start; user_ram_end = workspace_end; do_version(0,0); #ifdef CYGFUN_REDBOOT_BOOT_SCRIPT # ifdef CYGDAT_REDBOOT_DEFAULT_BOOT_SCRIPT if (!script) { script = CYGDAT_REDBOOT_DEFAULT_BOOT_SCRIPT; # ifndef CYGSEM_REDBOOT_FLASH_CONFIG script_timeout = CYGNUM_REDBOOT_BOOT_SCRIPT_DEFAULT_TIMEOUT; # endif } # endif if (script) { // Give the guy a chance to abort any boot script unsigned char *hold_script = script; int script_timeout_ms = script_timeout * CYGNUM_REDBOOT_BOOT_SCRIPT_TIMEOUT_RESOLUTION; diag_printf("== Executing boot script in %d.%03d seconds - enter ^C to abort\n", script_timeout_ms/1000, script_timeout_ms%1000); script = (unsigned char *)0; res = _GETS_CTRLC; // Treat 0 timeout as ^C while (script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) { res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT); if (res >= _GETS_OK) { diag_printf("== Executing boot script in %d.%03d seconds - enter ^C to abort\n", script_timeout_ms/1000, script_timeout_ms%1000); continue; // Ignore anything but ^C } if (res != _GETS_TIMEOUT) break; script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT; } if (res == _GETS_CTRLC) { script = (unsigned char *)0; // Disable script } else { script = hold_script; // Re-enable script } } #endif while (true) { if (prompt) { diag_printf("RedBoot> "); prompt = false; } #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0 cmd_history = true; // Enable history collection #endif res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT); #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0 cmd_history = false; // Enable history collection #endif if (res == _GETS_TIMEOUT) { // No input arrived } else { #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS if (res == _GETS_GDB) { int dbgchan; hal_virtual_comm_table_t *__chan; int i; // Special case of '$' - need to start GDB protocol gdb_active = true; // Mask interrupts on all channels for (i = 0; i < CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS; i++) { CYGACC_CALL_IF_SET_CONSOLE_COMM(i); __chan = CYGACC_CALL_IF_CONSOLE_PROCS(); CYGACC_COMM_IF_CONTROL( *__chan, __COMMCTL_IRQ_DISABLE ); } CYGACC_CALL_IF_SET_CONSOLE_COMM(cur); #ifdef HAL_ARCH_PROGRAM_NEW_STACK HAL_ARCH_PROGRAM_NEW_STACK(breakpoint); #else breakpoint(); // Get GDB stubs started, with a proper environment, etc. #endif dbgchan = CYGACC_CALL_IF_SET_DEBUG_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); CYGACC_CALL_IF_SET_CONSOLE_COMM(dbgchan); } else #endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS { expand_aliases(line, sizeof(line)); command = (char *)&line; if ((*command == '#') || (*command == '=')) { // Special cases if (*command == '=') { // Print line on console diag_printf("%s\n", &line[2]); } } else { while (strlen(command) > 0) { if ((cmd = parse(&command, &argc, &argv[0])) != (struct cmd *)0) { (cmd->fun)(argc, argv); } else { diag_printf("** Error: Illegal command: \"%s\"\n", argv[0]); } } } prompt = true; } } } }
static void sig_complete_word(GList **list, WINDOW_REC *window, const char *word, const char *linestart, int *want_space) { const char *newword, *cmdchars; char *signal, *cmd, *args, *line; g_return_if_fail(list != NULL); g_return_if_fail(word != NULL); g_return_if_fail(linestart != NULL); /* check against "completion words" list */ newword = completion_find(word); if (newword != NULL) { *list = g_list_append(*list, g_strdup(newword)); signal_stop(); return; } /* command completion? */ cmdchars = settings_get_str("cmdchars"); if (strchr(cmdchars, *word) && *linestart == '\0') { /* complete /command */ *list = completion_get_commands(word+1, *word); if (*list != NULL) signal_stop(); return; } /* check only for /command completions from now on */ cmdchars = strchr(cmdchars, *linestart); if (cmdchars == NULL) return; /* check if there's aliases */ line = linestart[1] == *cmdchars ? g_strdup(linestart+2) : expand_aliases(linestart+1); cmd = line_get_command(line, &args, FALSE); if (cmd == NULL) { g_free(line); return; } /* we're completing -option? */ if (*word == '-') { *list = completion_get_options(cmd, word+1); g_free(cmd); g_free(line); return; } /* complete parameters */ signal = g_strconcat("complete command ", cmd, NULL); signal_emit(signal, 5, list, window, word, args, want_space); if (command_have_sub(line)) { /* complete subcommand */ g_free(cmd); cmd = g_strconcat(line, " ", word, NULL); *list = g_list_concat(completion_get_subcommands(cmd), *list); if (*list != NULL) signal_stop(); } g_free(signal); g_free(cmd); g_free(line); }
char *expand_aliases( char *command, int depth, Alias *aliases ) { int ends_with_space; size_t length; char *result; char *cmd; char *args; int i; List *words; char *alias_value; char *aliased_command; char *prev_cmd; List *new_command_list; List *new_words; int new_command_list_length; // fprintf( stderr, "expand_aliases (%s),%d ... \n", command, depth ); /* If tcsh detects a loop in the aliases then it prints "Alias loop", but we simply stop expanding aliases at a certain depth. This is unlikely to affect any real alias expansion. */ if ( depth >= 20 ) { result = strdup( command ); } else if ( is_empty( command ) ) { result = strdup( command ); } else { /* If the command ends with a space, then we will eventually make sure that the final result also ends with a space. */ length = strlen( command ); if ( (length > 0) && (command[length-1] == ' ') ) { ends_with_space = 1; } else { ends_with_space = 0; } /* Split the string at the first white space. The first entry on the list is then the "command" and the second contains all the arguments. */ words = split_after_first_word( command ); if ( list_length( words ) > 0 ) { cmd = get_nth_word( words, 0 ); args = get_nth_word( words, 1 ); free_list( words ); /* If the command matches a defined alias, get the text which is is supposed to expand to. */ alias_value = lookup_alias( cmd, aliases ); if ( alias_value != NULL ) { prev_cmd = strdup( cmd ); /* Replace refernces to the "history" with values from the original command and arguments. */ aliased_command = replace_history( alias_value, cmd, args ); free( alias_value ); free( cmd ); /* Expanding the alias may very well have generated a number of sub-commands, so we must again split into simple commands. */ new_command_list = split_into_simple_commands( aliased_command ); new_command_list_length = list_length( new_command_list ); result = get_nth_word( new_command_list, 0 ); /* If the process so far has changed the command, then we need to see whether this new command is itself an alias. The simplest way to do this is to recursively call resolve_alias, but we include an explicit "depth" parameter so that we can avoid an infinite loop. */ new_words = split_after_first_word( aliased_command ); cmd = get_nth_word( new_words, 0 ); if ( strcmp( cmd, prev_cmd ) != 0 ) { result = expand_aliases( result, depth+1, aliases ); } free_list( new_words ); free( aliased_command ); free( cmd ); free( prev_cmd ); /* Recursively expand any aliases in the rest of the simple commands. */ for ( i = 1; i < new_command_list_length; i++ ) { result = append_dup_string( result, " " ); cmd = expand_aliases( get_nth_word( new_command_list, i ), depth+1, aliases ); result = append_dup_string( result, cmd ); free( cmd ); } free_list( new_command_list ); /* If the original command ended with a space, make sure that the result does as well. */ if ( ends_with_space ) { result = append_dup_string( result, " " ); } } else { /* The first word wasn't actually an alias. */ free( cmd ); result = strdup( command ); } } else { result = strdup( "" ); } } free( command ); // fprintf( stderr, "expand_aliases returns (%s)\n", result ); return result; }
// // This is the main entry point for RedBoot // void cyg_start(void) { int res = 0; bool prompt = true; static char line[CYGPKG_REDBOOT_MAX_CMD_LINE]; char *command; struct cmd *cmd; int cur; struct init_tab_entry *init_entry; extern char RedBoot_version[]; #if CYGBLD_REDBOOT_MAX_MEM_SEGMENTS > 1 int seg; #endif // Export version information CYGACC_CALL_IF_MONITOR_VERSION_SET(RedBoot_version); CYGACC_CALL_IF_MONITOR_RETURN_SET(return_to_redboot); // Make sure the channels are properly initialized. diag_init_putc(_mon_write_char); hal_if_diag_init(); // Force console to output raw text - but remember the old setting // so it can be restored if interaction with a debugger is // required. cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL); #ifdef CYGPKG_REDBOOT_ANY_CONSOLE console_selected = false; #endif console_echo = true; CYGACC_CALL_IF_DELAY_US((cyg_int32)2*100000); ram_start = (unsigned char *)CYGMEM_REGION_ram; ram_end = (unsigned char *)(CYGMEM_REGION_ram+CYGMEM_REGION_ram_SIZE); #ifdef HAL_MEM_REAL_REGION_TOP { unsigned char *ram_end_tmp = ram_end; ram_end = HAL_MEM_REAL_REGION_TOP( ram_end_tmp ); } #endif #ifdef CYGMEM_SECTION_heap1 workspace_start = (unsigned char *)CYGMEM_SECTION_heap1; workspace_end = (unsigned char *)(CYGMEM_SECTION_heap1+CYGMEM_SECTION_heap1_SIZE); #else workspace_start = (unsigned char *)CYGMEM_REGION_ram; workspace_end = (unsigned char *)(CYGMEM_REGION_ram+CYGMEM_REGION_ram_SIZE); #endif if ( ram_end < workspace_end ) { // when *less* SDRAM is installed than the possible maximum, // but the heap1 region remains greater... workspace_end = ram_end; } // Nothing has ever been loaded into memory entry_address = (unsigned long)NO_MEMORY; bist(); #if defined(CYGPRI_REDBOOT_ZLIB_FLASH) && defined(CYGOPT_REDBOOT_FIS_ZLIB_COMMON_BUFFER) fis_zlib_common_buffer = workspace_end -= CYGNUM_REDBOOT_FIS_ZLIB_COMMON_BUFFER_SIZE; #endif #ifdef CYGFUN_REDBOOT_BOOT_SCRIPT script_timeout = CYGNUM_REDBOOT_BOOT_SCRIPT_DEFAULT_TIMEOUT; #endif for (init_entry = __RedBoot_INIT_TAB__; init_entry != &__RedBoot_INIT_TAB_END__; init_entry++) { (*init_entry->fun)(); } mem_segments[0].start = workspace_start; mem_segments[0].end = workspace_end; #if CYGBLD_REDBOOT_MAX_MEM_SEGMENTS > 1 for (seg = 1; seg < CYGBLD_REDBOOT_MAX_MEM_SEGMENTS; seg++) { cyg_plf_memory_segment(seg, &mem_segments[seg].start, &mem_segments[seg].end); } #endif #ifdef CYGSEM_REDBOOT_PLF_STARTUP cyg_plf_redboot_startup(); #endif do_version(0,0); #ifdef CYGFUN_REDBOOT_BOOT_SCRIPT # ifdef CYGDAT_REDBOOT_DEFAULT_BOOT_SCRIPT if (!script) { script = CYGDAT_REDBOOT_DEFAULT_BOOT_SCRIPT; } # endif if (script) { // Give the guy a chance to abort any boot script unsigned char *hold_script = script; int script_timeout_ms = script_timeout * CYGNUM_REDBOOT_BOOT_SCRIPT_TIMEOUT_RESOLUTION; diag_printf("== Executing boot script in %d.%03d seconds - enter ^C to abort\n", script_timeout_ms/1000, script_timeout_ms%1000); script = (unsigned char *)0; res = _GETS_CTRLC; // Treat 0 timeout as ^C while (script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) { res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT); if (res >= _GETS_OK) { diag_printf("== Executing boot script in %d.%03d seconds - enter ^C to abort\n", script_timeout_ms/1000, script_timeout_ms%1000); continue; // Ignore anything but ^C } if (res != _GETS_TIMEOUT) break; script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT; } if (res == _GETS_CTRLC) { script = (unsigned char *)0; // Disable script } else { script = hold_script; // Re-enable script } } #endif while (true) { if (prompt) { diag_printf("RedBoot> "); prompt = false; } #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0 cmd_history = true; // Enable history collection #endif res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT); #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0 cmd_history = false; // Enable history collection #endif if (res == _GETS_TIMEOUT) { // No input arrived } else { #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS if (res == _GETS_GDB) { int dbgchan; hal_virtual_comm_table_t *__chan; int i; // Special case of '$' - need to start GDB protocol gdb_active = true; // Mask interrupts on all channels for (i = 0; i < CYGNUM_HAL_VIRTUAL_VECTOR_NUM_CHANNELS; i++) { CYGACC_CALL_IF_SET_CONSOLE_COMM(i); __chan = CYGACC_CALL_IF_CONSOLE_PROCS(); CYGACC_COMM_IF_CONTROL( *__chan, __COMMCTL_IRQ_DISABLE ); } CYGACC_CALL_IF_SET_CONSOLE_COMM(cur); // set up a temporary context that will take us to the trampoline HAL_THREAD_INIT_CONTEXT((CYG_ADDRESS)workspace_end, breakpoint, trampoline, 0); // switch context to trampoline (get GDB stubs started) HAL_THREAD_SWITCH_CONTEXT(&saved_context, &workspace_end); gdb_active = false; dbgchan = CYGACC_CALL_IF_SET_DEBUG_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); CYGACC_CALL_IF_SET_CONSOLE_COMM(dbgchan); } else #endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS { #ifdef CYGSEM_REDBOOT_FLASH_ALIASES expand_aliases(line, sizeof(line)); #endif command = (char *)&line; if ((*command == '#') || (*command == '=')) { // Special cases if (*command == '=') { // Print line on console diag_printf("%s\n", &line[2]); } } else { while (strlen(command) > 0) { if ((cmd = parse(&command, &argc, &argv[0])) != (struct cmd *)0) { // Try to handle aborts - messy because of the stack unwinding... __mem_fault_handler = error_handler; if (hal_setjmp(error_jmpbuf)) { diag_printf("** command abort - illegal memory access?\n"); } else { (cmd->fun)(argc, argv); } __mem_fault_handler = 0; } else { diag_printf("** Error: Illegal command: \"%s\"\n", argv[0]); } } } prompt = true; } } } }