int history(char ** args){ // show n commands int n; char * tmp; if ( debug > 9) printf("History \n"); if ( num_cmds == 0){ printf("No history\n"); return 0; } tmp = args[1]; if ( debug > 9) printf("History2 %s \n", tmp); if (tmp == NULL) { n = 20; } else if (validate_number(tmp) != 0){ printf("shellp error - illegal fommand cound \n"); return 1; } else { n = atoi(args[1]); } if ( debug > 9) printf("History3 %d \n", n); int thisc = cur_cmd; if (n > num_cmds) n = num_cmds; if ( debug > 9) printf("History4 %d tc%d cc%d\n", n, thisc, cur_cmd); for ( int i = 0; i < n; i ++ ){ if ( debug > 9) printf("History5 %d tc%d cc%d\n", n, thisc, cur_cmd); printf(" %d %s\n", i, cmd_stack[thisc]); thisc--; if ( thisc < 0 ) thisc = SIZE_CMD_STACK - 1; } return 0; }
static json_t *parse_integer(stream_t *stream, size_t flags, json_error_t *error) { json_int_t value; char *endptr; ssize_t end; (void) flags; end = search(stream, 'e'); if (end < 0) { error_set(error, stream, "unterminated integer"); return NULL; } if (validate_number(stream, error)) return NULL; errno = 0; value = json_strtoint(&stream->buffer[stream->pos], &endptr, 10); if (endptr != &stream->buffer[end]) { error_set(error, stream, "invalid integer"); return NULL; } if(errno == ERANGE) { if(value < 0) error_set(error, stream, "too big negative integer"); else error_set(error, stream, "too big integer"); return NULL; } stream->pos = end + 1; return json_integer(value); }
int psp_export_var_nid(char **params) { unsigned int nid; if(g_currlib == NULL) { snprintf(g_errstring, MAX_ERROR, "Cannot export variable, not in a library definition"); return 0; } if(validate_number(params[1], &nid) == 0) { return 0; } if(g_currlib->varCount < MAX_LIB_VARS) { if(internal_do_export(params[0], nid, &g_currlib->pVarHead)) { g_currlib->varCount++; return 1; } } else { snprintf(g_errstring, MAX_ERROR, "Too many variables defined, cannot export another"); } return 0; }
int psp_export_func_nid(char **params) { unsigned int nid; if(g_currlib == NULL) { snprintf(g_errstring, MAX_ERROR, "Cannot export function, not in a library definition"); return 0; } if(validate_number(params[1], &nid) == 0) { return 0; } if(g_currlib->funcCount < MAX_LIB_FUNCS) { if(internal_do_export(params[0], nid, &g_currlib->pFuncHead)) { g_currlib->funcCount++; return 1; } } else { snprintf(g_errstring, MAX_ERROR, "Too many functions defined, cannot export another"); } return 0; }
int kernel_interrupt_enable(int number) { number = validate_number(number); if(number < 0) { return -1; } if(int_child[number] != kernel_curr_act) { return -1; } cp0_status_im_enable(1<<number); return 0; }
int kernel_interrupt_register(int number) { number = validate_number(number); if(number < 0) { return -1; } if(int_child[number] != 0) { return -1; } int_child[number] = kernel_curr_act; return 0; }
int psp_export_start(char **params) { unsigned int ver; unsigned int attr; if(g_currlib != NULL) { snprintf(g_errstring, MAX_ERROR, "Previous library '%s' not ended", g_currlib->name); return 0; } if(validate_number(params[1], &ver) == 0) { return 0; } if(validate_number(params[2], &attr) == 0) { return 0; } g_currlib = (struct psp_lib *) malloc(sizeof(struct psp_lib)); if(g_currlib == NULL) { snprintf(g_errstring, MAX_ERROR, "Could not allocate memory for library"); return 0; } memset(g_currlib, 0, sizeof(struct psp_lib)); g_libcount++; strncpy(g_currlib->name, params[0], MAX_LIB_NAME); g_currlib->ver = ver; g_currlib->attr = attr; return 1; }
static char *parse_string(stream_t *stream, size_t flags, json_error_t *error) { char *endptr; ssize_t colon; size_t pos = 0; size_t length; char *string; (void) flags; colon = search(stream, ':'); if (colon < 0) { error_set(error, stream, "unterminated string length"); return NULL; } if (validate_number(stream, error)) return NULL; /* can overflow, but who cares? */ length = strtoul(&stream->buffer[stream->pos], &endptr, 10); if (endptr != &stream->buffer[colon]) { error_set(error, stream, "invalid string length"); return NULL; } stream->pos = colon + 1; string = jsonp_malloc(length + 1); if (!string) { error_set(error, stream, "out of memory (string length %zd)", length); return NULL; } string[length] = '\0'; while (pos < length) { char *zero; size_t chunk = stream->buflen - stream->pos; if (chunk == 0) { if (stream_refill(stream) <= 0) { error_set(error, stream, "partial string: %zd/%zd", pos, length); goto error; } continue; } if (chunk > length - pos) chunk = length - pos; /* null bytes are not allowed inside strings */ zero = memchr(&stream->buffer[stream->pos], '\0', chunk); if (zero) { stream->pos = zero - stream->buffer; error_set(error, stream, "string contains a zero byte"); goto error; } memcpy(&string[pos], &stream->buffer[stream->pos], chunk); stream->pos += chunk; pos += chunk; } return string; error: jsonp_free(string); return NULL; }
int fc(char ** args){ char * tmp1, * tmp2; char ** cmd_args; tmp1 = args[1]; tmp2 = args[2]; int start, end; if ( debug > 10) printf("fc %s, %s\n", tmp1, tmp2); if (tmp1 == NULL && tmp2 == NULL){ start = cur_cmd; end = cur_cmd; } else if ( tmp2 == NULL ) { if (validate_number(tmp1) != 0){ printf("shellp error - illegal fommand found \n"); return 1; } else { start = atoi(tmp1); end = start; } } else if (validate_number(tmp1) == 0 && validate_number(tmp2) == 0){ start = atoi(tmp1); end = atoi(tmp2); } else { printf("shellp error - xillegal fommand found \n"); return 1; } if ( debug > 10) printf("fc2 %d, %d\n", start, end); if (start < 0 || start > 1023 || end < 0 || end > 1023 || start > end ){ printf("shellp error - illegal fommand found \n"); return 1; } int length = end - start + 1; if (length > num_cmds) { printf("shellp error - too many commands requested \n"); return 1; } start = cur_cmd - 1 - start; if ( start < 0 ) start = SIZE_CMD_STACK+start; end = cur_cmd -1 - end; if ( end < 0 ) end = SIZE_CMD_STACK+start; int thisc = start; for (int i = 0; i < length; i++){ char next_cmdp[1024]; strcpy(next_cmdp,cmd_stack[thisc]); char * cmd; int num_args; if (debug > 10){ int len = num_cmds; for ( int k = 0; k < len; k++ ){ printf("i=%d cmd=%s\n", k, cmd_stack[k]); } } if ( debug > 10) printf("fc3 %s, %d %d\n", next_cmdp, i, length); cmd_args = parseline(next_cmdp, &num_args); cmd = cmd_args[0]; if ( debug > 10) printf("fc4 %s %d %d %d\n", cmd, start, end, thisc); if ( debug > 10) printf("fc4.1 %d %d %d\n", cur_cmd, next_cmd, num_cmds); if (debug > 11) printf("fc5%s:%d\n",cmd,num_args); if (cmd != NULL) { if ( exec_cmds(cmd_args, num_args, false) != 0 ){ exit(1); } } for ( int j = 0; j < 1024; j++ ){ free(cmd_args[j]); } free(cmd_args); thisc--; if ( thisc < 0 ) thisc = SIZE_CMD_STACK - 10; } return 0; }