int main(int argc, char* argv[]) { int err; text_t text; err = (argc != 2); if (err) { printf("ERROR: Wrong number of arguments.\n"); exit(EXIT_FAILURE); } /* STACK TEST */ err = text_from_file(&text, argv[1]); if (err) { printf("ERROR: Error reading text file.\n"); exit(EXIT_FAILURE); } text_print(&text); text_free(&text, false); /* HEAP TEST */ text_t* textp = text_alloc(); err = text_from_file(textp, argv[1]); if (err) { printf("ERROR: Error reading text lines.\n"); exit(EXIT_FAILURE); } text_print(textp); text_free(textp, true); return EXIT_SUCCESS; }
static void dispStaticDraw(uint8_t buttons) //Рисует сепараторы, Рё РєРЅРѕРїРєРё. общая функция для всех модулей. { display_clear(); switch (buttons) { case 0: //обычный набор кнопок text_set_font(FONT_BOLD); text_print(5, 15, PSTR("выбрать"), 0); text_set_font(FONT_NORMAL); break; case 1: //Надпись Сохранить text_set_font(FONT_BOLD); text_print(5, 6, PSTR("сохранить"), 0); text_set_font(FONT_NORMAL); break; } }
static void ConfigDispSetup(uint8_t conftype) { dispStaticDraw(1); dispHead(PSTR("Настройка")); if (conftype) { //DispCursor(11,ROWSHIFT);//ставим РєСѓСЂСЃРѕСЂ //DispNumber(brCrumbs[level-1][1]); //text_unum(); } text_print(1, 11, header, 0); ConfigDispStatic(); }
int main() { int i,j; char str[20] = "do1.txt"; text_t * text = text_new(str); // if (text != NULL) //text_print(text); sentense_t * tmp = NULL; int flag = 0; for ( i = 0; i < text_sentence_count(text); i++) { tmp = text_get_sentence(text, i); for ( j = 0; j < sentence_word_count(tmp); j++) { flag = 0; while (strcmp(word_get_str(sentence_get_word(tmp, j)), "not") == 0) { j++; if (j == sentence_word_count(tmp)) break; flag = 1; } if (flag == 1) flag = 0; else { sentence_del_word(tmp, j); j--; } } } FILE * file_out = NULL; file_out = fopen("posle.txt", "w"); if (file_out == NULL) return 1; for ( i = 0; i < text_sentence_count(text); i++) { tmp = text_get_sentence(text, i); for ( j = 0; j < sentence_word_count(tmp); j++) { if (j < sentence_word_count(tmp) - 1) fprintf(file_out, "%s, ", word_get_str(sentence_get_word(tmp, j))); else fprintf(file_out, "%s\n", word_get_str(sentence_get_word(tmp, j))); } } text_print(text); text_free(text); fclose(file_out); return 0; }
//prog_char cur[] PROGMEM = "Текущее: "; static void ConfigDispStatic(void) { uint8_t x; PGM_P tek = PSTR("Тек. :"); switch (configLim[1]) { case 0: //значит что без ограничений x = text_print(2, 0, tek/*PSTR("Тек. :")*/, 0); text_clear_from(2, x); text_unum(2, 30, configLim[3], 0, 0); break; case 1: //значит что вырианты только да или нет if (configLim[3]) text_print(2, 0, PSTR("Тек. : Да "), 0); else text_print(2, 0, PSTR("Тек. : Нет "), 0); break; default: x = text_print(2, 0, tek/*PSTR("Тек. :")*/, 0); text_clear_from(2, x); text_unum(2, 30, configLim[3], 0, 0); x = text_print(3, 0, PSTR("Мин. :"), 0); text_clear_from(3, x); text_unum(3, 30, configLim[0], 0, 0); x = text_print(4, 0, PSTR("Макс.:"), 0); text_clear_from(4, x); text_unum(4, 30, configLim[1], 0, 0); break; } }
int bx_param_enum_c::text_ask(FILE *fpin, FILE *fpout) { fprintf(fpout, "\n"); const char *prompt = get_ask_format(); const char *help = get_description(); if (prompt == NULL) { // default prompt, if they didn't set an ask format string fprintf(fpout, "%s = ", get_name()); text_print(fpout); fprintf(fpout, "\n"); prompt = "Enter new value or '?' for help: [%s] "; } Bit32s n = (Bit32s)(get() - min); int status = ask_menu(prompt, help, (Bit32u)(max-min+1), choices, n, &n); if (status < 0) return status; n += (Bit32s)min; set(n); return 0; }
int bx_param_num_c::text_ask(FILE *fpin, FILE *fpout) { fprintf(fpout, "\n"); int status; const char *prompt = get_ask_format(); const char *help = get_description(); if (prompt == NULL) { // default prompt, if they didn't set an ask format string text_print(fpout); fprintf(fpout, "\n"); prompt = "Enter new value or '?' for help: [%d] "; if (base==16) prompt = "Enter new value in hex or '?' for help: [%x] "; } Bit32u n = get(); status = ask_uint(prompt, help, (Bit32u)min, (Bit32u)max, n, &n, base); if (status < 0) return status; set(n); return 0; }
int bx_param_string_c::text_ask(FILE *fpin, FILE *fpout) { fprintf(fpout, "\n"); int status; const char *prompt = get_ask_format(); if (prompt == NULL) { if (options & SELECT_FOLDER_DLG) { fprintf(fpout, "%s\n\n", get_label()); prompt = "Enter a path to an existing folder or press enter to cancel\n"; } else { // default prompt, if they didn't set an ask format string text_print(fpout); fprintf(fpout, "\n"); prompt = "Enter a new value, '?' for help, or press return for no change.\n"; } } while (1) { char buffer[1024]; status = ask_string(prompt, getptr(), buffer); if (status == -2) { fprintf(fpout, "\n%s\n", get_description()); continue; } if (status < 0) return status; int opts = options; char buffer2[1024]; strcpy(buffer2, buffer); if (status == 1 && opts & RAW_BYTES) { // copy raw hex into buffer status = parse_raw_bytes(buffer, buffer2, maxsize, separator); if (status < 0) { fprintf(fpout, "Illegal raw byte format. I expected something like 3A%c03%c12%c...\n", separator, separator, separator); continue; } } if (!equals(buffer)) set(buffer); return 0; } }
void js_print_jf(nvObj_t *nv) { text_print(nv, fmt_jf);} // TYPE_INT
void js_print_ej(nvObj_t *nv) { text_print(nv, fmt_ej);} // TYPE_INT
inline void dipslayCalib(uint8_t start) { text_set_font(FONT_BOLD); text_clear_from(5, 0); text_print(5, 25, start ? PSTR("старт") : PSTR("стоп"), 0); text_set_font(FONT_NORMAL); }
static void takePhoto(void) { display_clear(); text_print(3, 20, PSTR("Птичка!"), 0); IR_shot(3); }
static void displayPosition(uint8_t p) { uint8_t x; x = text_print(p, 0, PSTR("Поз. :"), 0); text_clear_from(p, x); text_unum(p, 30, A4988GetPos(), 0, 0); }
static void pageList(void) { char buff[(LCDCOL - 3) * 2]; char buff2[LCDCOL * 2]; uint8_t currs; uint8_t fstart; dispStaticDraw(0); //рисуем статику switch (fileData[0]) { case T_FOLDER: //обычная папка.. if ((brCrumbs[level][1] & LCDINVBITS)== ((fileData[2]) & LCDINVBITS))currs = (fileData[2]) & LCDBITS;//Это максимальное положение курсора на последней странице else currs = LCDBITS; fstart = fileData[1] + (brCrumbs[level][1] & LCDINVBITS);//номер файла для старта вывода. for (uint8_t i = 0; i <= currs; i++) {//пишем из массива для статических папок text_print(i + 1, 0, (PGM_P) pgm_read_word(&fileNames[i + fstart]), ((brCrumbs[level][1] & LCDBITS) == (i)) * 0xFF); } break; case T_DFOLDER: //динамическая папка if ((brCrumbs[level][1] & LCDINVBITS) == ((fileData[2]) & LCDINVBITS)) currs = (fileData[2]) & LCDBITS;//Это максимальное положение курсора на последней странице else currs = LCDBITS; strncpy_P(buff, (char*) pgm_read_word(&(fileNames[fileData[1]])), sizeof(buff));//читаем общее название buff[sizeof(buff) - 1] = '\0'; for (uint8_t i = 0; i <= currs; i++) { snprintf(buff2, sizeof(buff2), "%s %d", buff, (brCrumbs[level][1] & LCDINVBITS) + i); buff_print(i + 1, 0, buff2, ((brCrumbs[level][1] & LCDBITS) == (i)) * 0xFF); } break; case T_SFOLDER: //папка выбора параметра { uint8_t config_folder_view = pgm_read_byte( &fileStruct[FILEREW * fileData[1] + 1]);//читаем байт сдвига. uint8_t config_folder_data = ConfigRead( /*brCrumbs[level][0]+*/config_folder_view);//чтение значения выбора if (config_folder_data > fileData[2]) config_folder_data = fileData[2]; if (config_folder_view < 0) config_folder_view = 0; if (brCrumbs[level][2] == 0) { brCrumbs[level][1] = config_folder_data;//ставим курсор в выбранную позицию. brCrumbs[level][2] = 1; } if ((brCrumbs[level][1] & LCDINVBITS) == ((fileData[2]) & LCDINVBITS)) currs = (fileData[2]) & LCDBITS;//Это максимальное положение курсора на последней странице else currs = LCDBITS; fstart = fileData[1] + (brCrumbs[level][1] & LCDINVBITS);//номер файла для старта вывода. for (uint8_t i = 0; i <= currs; i++) { //пишем из массива для статических папок text_print(i + 1, 0, (PGM_P) pgm_read_word(&fileNames[i + fstart]), ((brCrumbs[level][1] & LCDBITS) == (i)) * 0xFF); } } break; } dispHead(header); // stringSelect(); }
static void dispHead(PGM_P head) { text_set_font(FONT_BOLD); text_print(0, 4, head, 0); text_set_font(FONT_NORMAL); }
/** * @brief ui_loop_ggs * * GGS main loop. Here the input from both the user and * GGS server is interpreted. * * @param ui User Interface. */ void ui_loop_ggs(UI *ui) { char *cmd = NULL, *param = NULL; Text text[1]; GGSClient *client = ui->ggs; ui->mode = 3; text_init(text); for (;;) { relax(10); /* look for a user event */ if (ui_event_peek(ui, &cmd, ¶m)) { /* stop the search */ if (strcmp(cmd, "stop") == 0) { if (ui->play[0].state == IS_THINKING) play_stop(ui->play); else if (ui->play[1].state == IS_THINKING) play_stop(ui->play + 1); /* repeat a cmd <n> times */ } else if (strcmp(cmd, "loop") == 0) { free(client->loop->cmd); errno = 0; client->loop->cmd = string_duplicate(parse_int(param, &client->loop->i)); if (errno) client->loop->i = 100; if (client->loop->i > 0) { info("<loop %d>\n", client->loop->i); --client->loop->i; ggs_client_send(client, "%s\n", client->loop->cmd); } /* exit from ggs */ } else if (strcmp(cmd, "quit") == 0 || strcmp(cmd, "q") == 0) { ggs_client_send(client, "tell .%s Bye bye!\n", client->me); ggs_client_send(client, "quit\n"); free(cmd); free(param); return; /* send the command to ggs */ } else { ggs_client_send(client, "%s %s\n", cmd, param); } } /* stay on line... */ ggs_client_refresh(client); /* look for a ggs event */ if (!ggs_event_peek(&client->event, text)) { continue; } text_print(text, stdout); if (ggs_log->f) text_print(text, ggs_log->f); /* login */ if (ggs_login(text)) { ggs_client_send(client, "%s\n", options.ggs_login); /* password */ } else if (ggs_password(text)) { ggs_client_send(client, "%s\n", options.ggs_password); ggs_client_send(client, "vt100 -\n"); ggs_client_send(client, "bell -t -tc -tg -n -nc -ng -ni -nn\n"); ggs_client_send(client, "verbose -news -faq -help -ack\n"); ggs_client_send(client, "chann %%\n"); ggs_client_send(client, "chann + .chat\n"); ggs_client_send(client, "chann + .%s\n", client->me); ggs_client_send(client, "tell .%s Hello!\n", client->me); /* os on */ } else if (ggs_os_on(text)) { printf("[received GGS_OS_ON]\n"); ggs_client_send(client, "tell /os trust +\n" ); ggs_client_send(client, "tell /os rated +\n" ); ggs_client_send(client, "tell /os request +\n" ); ggs_client_send(client, "tell /os client -\n" ); ggs_client_send(client, "tell /os open %d\n", options.ggs_open); ggs_client_send(client, "mso\n" ); /* os off */ } else if (ggs_os_off(text)) { printf("[received GGS_OS_OFF]\n"); /* match on */ } else if (ggs_match_on(client->match_on, text)) { if (ggs_has_player(client->match_on->player, client->me)) { printf("[received GGS_MATCH_ON]\n"); client->is_playing = true; ggs_client_send(client, "tell /os open 0\n" ); } else { printf("[received GGS_WATCH_ON]\n"); } /* match off */ } else if (ggs_match_off(client->match_off, text)) { if (ggs_has_player(client->match_off->player, client->me)) { printf("[received GGS_MATCH_OFF]\n"); if (!client->match_on->match_type->is_rand) { if (client->match_on->match_type->is_synchro) { printf("[store match #1]\n"); play_store(ui->play); printf("[store match #2]\n"); play_store(ui->play + 1); } else { printf("[store match]\n"); play_store(ui->play); } if (ui->book->need_saving) { book_save(ui->book, options.book_file); ui->book->need_saving = false; } } client->is_playing = false; ggs_client_send(client, "tell /os open %d\n", options.ggs_open); if (client->loop->i > 0) { info("<loop %d>\n", client->loop->i); --client->loop->i; client->loop->delay = 10000 + real_clock(); // wait 10 sec. } } else { printf("[received GGS_WATCH_OFF]\n"); } /* board join/update */ } else if (ggs_board(client->board, text)) { if (ggs_has_player(client->board->player, client->me)) { if (client->board->is_join) ui_ggs_join(ui); else ui_ggs_update(ui); } else { printf("[received GGS_WATCH_BOARD]\n"); } /* request */ } else if (ggs_request(client->request, text)) { printf("[received GGS_REQUEST]\n"); /* admin on */ } else if (ggs_admin(client->admin, text)) { printf("[received GGS_ADMIN_CMD]\n"); ggs_client_send(client, client->admin->command); ggs_client_send(client, "\ntell %s command processed\n", client->admin->name); /* To request Saio a game later */ } else if (ggs_saio_delay(text, &client->once->delay)) { printf("[received GGS_SAIO_DELAY]\n"); free(client->once->cmd); client->once->cmd = NULL; if (cmd != NULL && param != NULL) { if (strcmp(cmd, "loop") == 0) { client->once->cmd = string_duplicate(client->loop->cmd); } else { client->once->cmd = (char*) malloc(strlen(cmd) + strlen(param) + 3); sprintf(client->once->cmd, "%s %s\n", cmd, param); } printf("[received GGS_SAIO_DELAY, retry request in %.1f s]\n", 0.001 * (client->once->delay - real_clock())); } else { client->once->delay = 0; } /* READY */ } else if (ggs_ready(text)) { /* ALERT */ } else if (ggs_alert(text)) { printf("[received ALERT]\n"); /* Other messages */ } else { } text_free(text); } }