void testMY_STRPOS(void){ char str[] = "testing"; if(temp_file != NULL){ CU_ASSERT(my_strpos(str, 'g') == 6); CU_ASSERT(my_strpos(NULL, 'g') == -1); CU_ASSERT(my_strpos(str, 'q') == -1); CU_ASSERT(my_strpos(str, 't') == 0); } }
const char PROGMEM *jsonParseValue(char **buffer, const t_json *currentStructure, uint8_t index) { char *buf = *buffer; buf = skipSpaces(buf); // DEBUG_PRINT("STARTING value parse :"); // DEBUG_PRINT(buf[0]); // DEBUG_PRINTLN(buf[1]); if (buf[0] == '[') { // DEBUG_PRINT("found array"); const char PROGMEM *res = jsonParseArray(&buf, currentStructure); if (res) { return res; } } else if (buf[0] == '{') { // DEBUG_PRINTLN("found OBJ"); const t_json *objStruct = (t_json *) pgm_read_word(¤tStructure->valueStruct); const char PROGMEM *res = jsonParseObject(&buf, objStruct, index); if (res) { return res; } } else { // parsing string or num value jsonHandleValue func = 0; if (currentStructure != 0) { func = (jsonHandleValue) pgm_read_word(¤tStructure->handleValue); } uint16_t len; const char PROGMEM *res = 0; if (buf[0] == '"') { buf = &buf[1]; len = my_strpos(buf, '"'); if (func) { res = func(buf, len, index); } buf = &buf[len + 1]; } else { len = findEndOfValue(buf); if (func) { res = func(buf, len, index); } buf = &buf[len]; } if (res) { return res; } } *buffer = buf; return 0; }
t_symbol_match* prompt_cmd_find_first_symbol(char *cmd) { char* special_symbols[] = PROMPT_SPECIAL_SYMBOLS; int current_position; int i; t_symbol_match* symbol; symbol = malloc(sizeof(*symbol)); if (symbol == NULL) { return (NULL); } // @note: setting default values symbol->is_pipe = false; symbol->is_redirect_input = false; symbol->is_redirect_output = false; symbol->position = -1; symbol->string = NULL; current_position = -1; for (i = 0; special_symbols[i] != NULL; i++) { current_position = my_strpos(cmd, special_symbols[i]); if (current_position > -1 && (symbol->position == -1 || current_position < symbol->position)) { symbol->position = current_position; symbol->string = special_symbols[i]; } } // Symbol recognition if (symbol->string != NULL) { if (my_strcmp(symbol->string, "|") == 0) { symbol->is_pipe = true; } if (my_strcmp(symbol->string, "<") == 0) { symbol->is_redirect_input = true; } if (my_strcmp(symbol->string, ">") == 0) { symbol->is_redirect_output = true; } } return (symbol); }
/* * Main file of myselect * Links everything together, and executes the program * * Precondition: argc > 1 * Postcondition: The elements are printed on the screen */ int main(int argc, char** argv) { int count; int bytes; char input[READMIN + 2]; if(argc < 2 || !my_strpos(argv[1], '*')) { my_str("No files found!\n"); exit(1); } signal(SIGWINCH, show_elems); //Get all the termcaps init_caps(); //Prepare the terminal init_terminal(); //Setup the elements setup_elems(argc - 1, &argv[1]); //Turn off the cursor tputs(gl_env.cursoroff, 0, my_termprint); //Print the elements for the first time show_elems(); //Main loop while(1) { bytes = read(0, &input, READMIN + 2); input[bytes] = '\0'; if(!gl_env.flag) { check_char(input); } } return 0; }
int main(int argc, char** argv){ int data; char input[READMIN + 2]; if(argc < 2){ my_str("Usage: ./myselect itemSelector\n"); exit(1); } if(my_strpos(argv[1], '*') == 0){ my_str("No files were found\n"); exit(1); } signal(SIGWINCH, show_elems); init_caps(); //Get the termcaps init_terminal(); //initilize the terminal setup_elems(argc - 1, &argv[1]); //Setup elems tputs(gl_env.cursoroff, 0, my_termprint); //Turn off cursor show_elems(); //actually show the elements while(1){ data = read(0, &input, READMIN + 2); input[data] = '\0'; if(!gl_env.flag){ check_char(input); } } return 0; }