void rom_info_create(rom_info_t *m) { int x,y,i; memset(m,0,sizeof(rom_info_t)); m->info.type = G_WINDOW; x = m->info.x = 7; y = m->info.y = 30; m->info.w = 243; m->info.h = 120; m->info.draw = (drawfunc_t)rom_info_draw; m->info.event = (eventfunc_t)rom_info_event; button_create(&m->donebtn,"X",x+m->info.w-10,y,0); x += 3; y += 2 + 11; for(i=0; i<10; i++) { text_create(&m->labels[i],x,y,"A"); text_create(&m->labels[i+10],x+(10*6),y,"B"); y += 10; } }
void mappers_create(mappers_t *m) { int x,y; u8 dip = 0; memset(m,0,sizeof(mappers_t)); m->info.type = G_WINDOW; x = m->info.x = 20; y = m->info.y = 40; m->info.w = 200; m->info.h = 100; m->info.draw = (drawfunc_t)mappers_draw; m->info.event = (eventfunc_t)mappers_event; button_create(&m->donebtn,"Done",x+m->info.w-(6*6),124,0); x += 3; y += 2 + 11; text_create(&m->label,x,y,"Nothing to configure."); //mapper 105 controls text_create(&m->m105_label,x,y,"Time Limit"); checkbox_create(&m->m105_check[0],x,y+10*1,"DIP1",(dip >> 0) & 1,click_mapper105_check0); checkbox_create(&m->m105_check[1],x,y+10*2,"DIP2",(dip >> 1) & 1,click_mapper105_check1); checkbox_create(&m->m105_check[2],x,y+10*3,"DIP3",(dip >> 2) & 1,click_mapper105_check2); checkbox_create(&m->m105_check[3],x,y+10*4,"DIP4",(dip >> 3) & 1,click_mapper105_check3); }
static void setSentenceByIndex_hasOneAddedSentenceSettingNewSentenceInstead_testIfHasChanged(void **state){ text_t text = text_create(); text_addSentenceToEnd(text, "TEST1"); text_setSentenceByIndex(text, "REPLACED", 0); assert_string_equal(text_getSentence(text, 0), "REPLACED"); text_remove(text); }
static void deleteSentenceByIndex_hasOneAddedSentenceDeletingIt_zeroCount(void **state){ text_t text = text_create(); text_addSentenceToEnd(text, "TEST1"); text_deleteSentenceByIndex(text, 0); assert_int_equal(text_getSentenceAmount(text), 0); text_remove(text); }
static void msglogAction(Widget w, XtPointer client_data, XtPointer call_data) { int i; Widget text = text_create(US client_data, text_depth); uschar * fname = NULL; FILE * f = NULL; w = w; /* Keep picky compilers happy */ call_data = call_data; /* End up with the split version, so message looks right when non-exist */ for (i = 0; i < (spool_is_split ? 2:1); i++) { message_subdir[0] = i != 0 ? (US client_data)[5] : 0; fname = spool_fname(US"msglog", message_subdir, US client_data, US""); if ((f = fopen(CS fname, "r"))) break; } if (!f) text_showf(text, "%s: %s\n", fname, strerror(errno)); else { uschar buffer[256]; while (Ufgets(buffer, sizeof(buffer), f) != NULL) text_show(text, buffer); fclose(f); } }
static void headersAction(Widget w, XtPointer client_data, XtPointer call_data) { uschar buffer[256]; header_line *h, *next; Widget text = text_create(US client_data, text_depth); void *reset_point; w = w; /* Keep picky compilers happy */ call_data = call_data; /* Remember the point in the dynamic store so we can recover to it afterwards. Then use Exim's function to read the header. */ reset_point = store_get(0); sprintf(CS buffer, "%s-H", US client_data); if (spool_read_header(buffer, TRUE, FALSE) != spool_read_OK) { if (errno == ERRNO_SPOOLFORMAT) { struct stat statbuf; sprintf(CS big_buffer, "%s/input/%s", spool_directory, buffer); if (Ustat(big_buffer, &statbuf) == 0) text_showf(text, "Format error in spool file %s: size=%d\n", buffer, statbuf.st_size); else text_showf(text, "Format error in spool file %s\n", buffer); } else text_showf(text, "Read error for spool file %s\n", buffer); store_reset(reset_point); return; } if (sender_address != NULL) { text_showf(text, "%s sender: <%s>\n", f.sender_local ? "Local" : "Remote", sender_address); } if (recipients_list != NULL) { int i; text_show(text, US"Recipients:\n"); for (i = 0; i < recipients_count; i++) { text_showf(text, " %s %s\n", (tree_search(tree_nonrecipients, recipients_list[i].address) == NULL)? " ":"*", recipients_list[i].address); } text_show(text, US"\n"); } for (h = header_list; h != NULL; h = next) { next = h->next; text_showf(text, "%c ", h->type); /* Don't push h->text through a %s */ text_show(text, h->text); /* expansion as it may be v large */ } store_reset(reset_point); }
static void setSentenceByIndex__nullSentencePointer__putsNULL_POINTERtoStatus(void** state){ text_t text = text_create(); text_addSentenceToEnd(text, "TEST1"); text_setSentenceByIndex(text, NULL, 0); assert_int_equal(text_getStatus(text), NULL_POINTER); text_remove(text); }
static void getWordsAmountInText_hasSomeAddedSentences_returnsWordsCount(void **state){ text_t text = text_create(); text_addSentenceToEnd(text, "ababa ajjkasd"); text_addSentenceToEnd(text, "asd+sd"); text_addSentenceToEnd(text, "ababa gala&maga"); assert_int_equal(text_getWordsAmountInText(text), 7); text_remove(text); }
static void getSentenceAmount_hasThreeAddedSentences_returnsCount(void **state){ text_t text = text_create(); text_addSentenceToEnd(text, "TEST1"); text_addSentenceToEnd(text, "TEST2"); text_addSentenceToEnd(text, "TEST3"); assert_int_equal(text_getSentenceAmount(text), 3); text_remove(text); }
static void getText_hasThreeAddedSentences_returnsText(void** state){ text_t text = text_create(); text_addSentenceToEnd(text, "TEST1"); text_addSentenceToEnd(text, "TEST2"); text_addSentenceToEnd(text, "TEST3"); assert_string_equal(text_getText(text), "TEST1. TEST2. TEST3. "); text_remove(text); }
static void addSentenceByIndex_hasTwoAddedSentencesAddingOneNewSentenceToIndexOne_testIfWasAdded(void **state){ text_t text = text_create(); text_addSentenceToEnd(text, "TEST1"); text_addSentenceToEnd(text, "TEST2"); text_addSentenceByIndex(text, "TESTMIDDLE", 1); assert_string_equal(text_getSentence(text, 1), "TESTMIDDLE"); text_remove(text); }
int main (){ FILE *input; input = fopen("text.txt", "r"); char *str = strnew(); sentence_t *currSentence = sentence_create(); text_t *text = text_create(); while (1) { char c = fgetc(input); if (c == EOF || isspace(c) || c == ',' || c == '.' || c == '!' || c == '?' || c == ';') { if (strlen(str) != 0) { word_t *word = word_new(str); sentence_add(currSentence, word); free (str); word_free (word); str = strnew(); } } if (c == EOF || c == '.' || c == '!' || c == '?') { text_add (text, currSentence); sentence_free(currSentence); currSentence = sentence_create(); } if (c == EOF) break; if (isalpha(c)) { c = tolower(c); char *w = stradd(str, c); free (str); str = w; } } fclose (input); FILE *output; output = fopen("result.txt", "w"); input = fopen ("stopwords.txt", "r"); int stopCount, i; fscanf (input, "%d", &stopCount); for (i = 0; i < stopCount; i++) { char s[15]; fscanf (input, "%s", s); fprintf (output, "%s: %d\n", s, text_find (text, s)); } fclose (input); fclose (output); free (str); sentence_free(currSentence); text_free(text); return 0; }
END_TEST START_TEST (test_text_line) { text *text; int i; char buf[128]; const char *p; int ret; int len; text = text_create (); fail_unless (text != NULL); for (i = 0; i < 120; i++) { sprintf (buf, "Line nr %d", i); ret = text_add_line (text, buf); fail_unless (ret == i + 1); fail_unless (text_nr_of_lines (text) == i + 1); } for (i = 0; i < 120; i++) { sprintf (buf, "Line nr %d", i); p = text_get_line (text, i, &len); fail_unless (p != NULL); fail_unless (strlen (buf) == len); fail_unless (strcmp (p, buf) == 0); } p = text_get_line (text, 500, &len); fail_unless (p == NULL); p = text_get_line (text, -50, &len); fail_unless (p == NULL); text_clear (text); fail_unless (text_nr_of_lines (text) == 0); ret = text_add_line (text, "\001"); fail_unless (ret < 0); fail_unless (text_nr_of_lines (text) == 0); ret = text_add_line (text, "\t"); fail_unless (ret == 1); fail_unless (text_nr_of_lines (text) == 1); p = text_get_line (text, 0, &len); fail_unless (p != NULL); fail_unless (len == 2); fail_unless (strcmp (p, " ") == 0); text_free (text); }
struct view *text_new(void) { char dir[128], path[128]; const char *me, *home; time_t now = time(NULL); struct tm *gmt = gmtime(&now); fd_t fd = -1; struct view *view; if ((home = getenv("HOME"))) { sprintf(dir, "%s/.aoeui", home); fd = try_dir(path, dir, gmt); } if (fd < 0 && (me = getenv("LOGNAME"))) { sprintf(dir, "/tmp/aoeui-%s", me); fd = try_dir(path, dir, gmt); } #if !defined __APPLE__ && !defined BSD if (fd < 0 && (me = cuserid(NULL))) { sprintf(dir, "/tmp/aoeui-%s", me); fd = try_dir(path, dir, gmt); } #endif if (fd < 0) fd = try_dir(path, "/tmp/aoeui", gmt); if (fd < 0) fd = try_dir(path, "./aoeui", gmt); if (fd < 0) view = text_create("* New *", TEXT_EDITOR); else { view = text_create(path, TEXT_CREATED | TEXT_SCRATCH); view->text->fd = fd; } return view; }
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { /* make a test window */ tw = text_new(); if (!hPrevInstance) { HICON hicon = LoadIcon(NULL, IDI_APPLICATION); text_register_class(hicon); } text_font(tw, "Courier New", 10); text_size(tw, 80, 80); text_drag(tw, "(", ") run\r"); /* show the text window */ if (!text_create(tw, "Application Name", nCmdShow)) { /* do the real work here */ /* TESTING */ int ch; int len; char *line = new char[256]; while ( (len = text_read_line(tw, line, 256-1)) != 0 ) { text_write_buf(tw, line, len); } /* while ( text_gets(tw, line, 256-1) ) { text_puts(tw, line); } */ /* while ( (ch = text_getch(tw, )) != 4 ) text_putch(tw, ch); */ } else { } /* clean up */ text_destroy(tw); /* end program */ return 0; }
void sound_create(sound_t *m) { int x,y; u8 channels = config.soundchannels; memset(m,0,sizeof(sound_t)); m->info.type = G_WINDOW; x = m->info.x = 50; y = m->info.y = 50; m->info.w = 150; m->info.h = 93; m->info.draw = (drawfunc_t)sound_draw; m->info.event = (eventfunc_t)sound_event; button_create(&m->donebtn,"Done",x+m->info.w-(6*6),y + m->info.h - 15,0); x += 3; y += 3; checkbox_create(&m->enabled,x+2,y+12,"Enabled",config.soundenabled,click_soundenabled); y += 8 + 5; text_create(&m->tc,x+2,y+12+8*0,"Channels enabled:"); x += 5; checkbox_create(&m->sq1,x+2,y+12+9*1,"Square 1",(channels & 1) ? 1 : 0,click_sq1); checkbox_create(&m->sq2,x+2,y+12+9*2,"Square 2",(channels & 2) ? 1 : 0,click_sq2); checkbox_create(&m->tri,x+2,y+12+9*3,"Triangle",(channels & 4) ? 1 : 0,click_tri); checkbox_create(&m->noise,x+2,y+12+9*4,"Noise",(channels & 8) ? 1 : 0,click_noise); checkbox_create(&m->dmc,x+2,y+12+9*5,"DMC",(channels & 0x10) ? 1 : 0,click_dmc); checkbox_create(&m->ext,x+2,y+12+9*6,"External",(channels & 0x20) ? 1 : 0,click_ext); m->enabled.user = m; m->sq1.user = m; m->sq2.user = m; m->tri.user = m; m->noise.user = m; m->dmc.user = m; m->ext.user = m; x += 3; y += 2 + 11; }
/** * Initializes the timestamp library with a font file and face index. */ void subtitle_init(const char *font_file, long face_index, int points, int dpi) { if (text_id != -1) { text_destroy(text_id); } text_id = text_create( font_file, face_index, points, dpi ); text_set_stroke_color(text_id, 0x000000); text_set_letter_spacing(text_id, 1); text_set_color(text_id, 0xffffff); text_set_layout(text_id, LAYOUT_ALIGN_BOTTOM | LAYOUT_ALIGN_CENTER, // layout alignment for the box 0, // horizontal margin from the right edge 30); // vertical margin from the bottom edge text_set_align(text_id, TEXT_ALIGN_CENTER); // text alignment inside the box }
static void bodyAction(Widget w, XtPointer client_data, XtPointer call_data) { int i; Widget text = text_create(US client_data, text_depth); FILE *f = NULL; w = w; /* Keep picky compilers happy */ call_data = call_data; for (i = 0; i < (spool_is_split? 2:1); i++) { uschar * fname; message_subdir[0] = i != 0 ? (US client_data)[5] : 0; fname = spool_fname(US"input", message_subdir, US client_data, US"-D"); if ((f = fopen(CS fname, "r"))) break; } if (f == NULL) text_showf(text, "Failed to open file: %s\n", strerror(errno)); else { uschar buffer[256]; int count = 0; while (Ufgets(buffer, sizeof(buffer), f) != NULL) { text_show(text, buffer); count += Ustrlen(buffer); if (count > body_max) { text_show(text, US"\n*** Message length exceeds BODY_MAX ***\n"); break; } } fclose(f); } }
void about_create(about_t *m) { int i,x,y; memset(m,0,sizeof(about_t)); m->info.type = G_WINDOW; x = m->info.x = 40; y = m->info.y = 20; m->info.w = 201; m->info.h = 140; m->info.draw = (drawfunc_t)about_draw; m->info.event = (eventfunc_t)about_event; button_create(&m->donebtn,"Done",x+m->info.w-(6*6),y+m->info.h-15,0); memset(m->text,0,sizeof(text_t) * 12); for(i=0;lines[i];i++) text_create(&m->text[i],x+3,y+12+8*i,lines[i]); }
void text_create_and_render(Shader *shader, Font *font, int size, const char *fmt, ...) { char *string; va_list va; Text *text; va_start(va, fmt); string = ralloc_vasprintf(NULL, fmt, va); va_end(va); if (string == NULL) return; text = text_create(font, string, size); ralloc_free(string); if (text == NULL) return; text_upload_to_gpu(shader, text); text_render(shader, text); text_destroy(text); }
static void ActOnMessage(uschar *id, uschar *action, uschar *address_arg) { int pid; int pipe_fd[2]; int delivery = Ustrcmp(action + Ustrlen(action) - 2, "-M") == 0; uschar *quote = US""; uschar *at = US""; uschar *qualify = US""; uschar buffer[256]; queue_item *qq; Widget text = NULL; /* If the address arg is not empty and does not contain @ and there is a qualify domain, qualify it. (But don't qualify '<>'.)*/ if (address_arg[0] != 0) { quote = US"\'"; if (Ustrchr(address_arg, '@') == NULL && Ustrcmp(address_arg, "<>") != 0 && qualify_domain != NULL && qualify_domain[0] != 0) { at = US"@"; qualify = qualify_domain; } } sprintf(CS buffer, "%s %s %s %s %s %s%s%s%s%s", exim_path, (alternate_config == NULL)? US"" : US"-C", (alternate_config == NULL)? US"" : alternate_config, action, id, quote, address_arg, at, qualify, quote); /* If we know we are going to need the window, create it now. */ if (action_output || delivery) { text = text_create(id, text_depth); text_showf(text, "%s\n", buffer); } /* Create the pipe for output. Remember, on most systems pipe[0] is for reading and pipe[1] is for writing! Solaris, with its two-way pipes is a trap! */ if (pipe(pipe_fd) != 0) { if (text == NULL) { text = text_create(id, text_depth); text_showf(text, "%s\n", buffer); } text_show(text, US"*** Failed to create pipe ***\n"); return; } if ( fcntl(pipe_fd[0], F_SETFL, O_NONBLOCK) || fcntl(pipe_fd[1], F_SETFL, O_NONBLOCK)) { perror("set nonblocking on pipe"); exit(1); } /* Delivering a message can take some time, and we want to show the output as it goes along. This requires subprocesses and is coded below. For other commands, we can assume an immediate response, and so need not waste resources with subprocesses. If action_output is FALSE, don't show the output at all. */ if (!delivery) { int count, rc; int save_stdout = dup(1); int save_stderr = dup(2); close(1); close(2); dup2(pipe_fd[1], 1); dup2(pipe_fd[1], 2); close(pipe_fd[1]); rc = system(CS buffer); close(1); close(2); if (action_output || rc != 0) { if (text == NULL) { text = text_create(id, text_depth); text_showf(text, "%s\n", buffer); } while ((count = read(pipe_fd[0], buffer, 254)) > 0) { buffer[count] = 0; text_show(text, buffer); } } close(pipe_fd[0]); dup2(save_stdout, 1); dup2(save_stderr, 2); close(save_stdout); close(save_stderr); /* If action was to change the sender, and it succeeded, we have to update the in-store data. */ if (rc == 0 && Ustrcmp(action + Ustrlen(action) - 4, "-Mes") == 0) { queue_item *q = find_queue(id, queue_noop, 0); if (q) { if (q->sender) store_free(q->sender); q->sender = store_malloc(Ustrlen(address_arg) + 1); Ustrcpy(q->sender, address_arg); } } /* If configured, cause a display update and return */ if (action_queue_update) tick_queue_accumulator = 999999; return; } /* Message is to be delivered. Ensure that it is marked unfrozen, because nothing will get written to the log to show that this has happened. (Other freezing/unfreezings get logged and picked up from there.) */ qq = find_queue(id, queue_noop, 0); if (qq != NULL) qq->frozen = FALSE; /* New, asynchronous code runs in a subprocess for commands that will take some time. The main process does not wait. There is a SIGCHLD handler in the main program that cleans up any terminating sub processes. */ if ((pid = fork()) == 0) { close(1); close(2); dup2(pipe_fd[1], 1); dup2(pipe_fd[1], 2); close(pipe_fd[1]); system(CS buffer); close(1); close(2); close(pipe_fd[0]); _exit(0); } /* Main process - set up an item for the main ticker to watch. */ if (pid < 0) text_showf(text, "Failed to fork: %s\n", strerror(errno)); else { pipe_item *p = (pipe_item *)store_malloc(sizeof(pipe_item)); if (p == NULL) { text_show(text, US"Run out of store\n"); return; } p->widget = text; p->fd = pipe_fd[0]; p->next = pipe_chain; pipe_chain = p; close(pipe_fd[1]); } }
static void addSentenceToEnd_oneString_countOne(void **state){ text_t text = text_create(); text_addSentenceToEnd(text, "TEST"); assert_int_equal(text_getSentenceAmount(text), 1); text_remove(text); }
static void addSentenceToEnd__nullSentencePointer__putsNULL_POINTERtoStatus(void** state){ text_t text = text_create(); text_addSentenceToEnd(text, NULL); assert_int_equal(text_getStatus(text), NULL_POINTER); text_remove(text); }
struct view *view_open(const char *path0) { struct view *view; struct text *text; struct stat statbuf; char *path = fix_path(path0); if (!path) return NULL; for (text = text_list; text; text = text->next) if (text->path && !strcmp(text->path, path)) { for (view = text->views; view; view = view->next) if (!view->window) goto done; view = view_create(text); goto done; } view = text_create(path, 0); text = view->text; errno = 0; if (stat(path, &statbuf)) { if (errno != ENOENT) { message("%s: can't stat", path_format(path)); goto fail; } if (read_only) { message("%s: can't create in read-only mode", path_format(path)); goto fail; } errno = 0; text->fd = open(path, O_CREAT|O_TRUNC|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); if (text->fd < 0) { message("%s: can't create", path_format(path)); goto fail; } text->flags |= TEXT_CREATED; } else { if (!S_ISREG(statbuf.st_mode)) { message("%s: not a regular file", path_format(path)); goto fail; } if (!read_only) text->fd = open(path, O_RDWR); if (text->fd < 0) { errno = 0; text->flags |= TEXT_RDONLY; text->fd = open(path, O_RDONLY); if (text->fd < 0) { message("%s: can't open", path_format(path)); goto fail; } } clean_mmap(text, statbuf.st_size, PROT_READ); if (!text->clean) { text->buffer = buffer_create(path); if (old_fashioned_read(text) < 0) goto fail; grab_mtime(text); } view->bytes = text->buffer ? buffer_bytes(text->buffer) : text->clean_bytes; scan(view); text_forget_undo(text); } goto done; fail: view_close(view); view = NULL; done: RELEASE(path); return view; }
static void getStatus__addingNon_NULLsentenceToProperIndexToGetOKstatus__returnStatus(void** state){ text_t text = text_create(); text_addSentenceToEnd(text, "TEST"); assert_int_equal(text_getStatus(text), OK); text_remove(text); }
static void create_void_zeroCount(void **state){ text_t text = text_create(); assert_int_equal(text_getSentenceAmount(text), 0); text_remove(text); }
static void getStatus__callingNULL_POINTERerror__returnStatus(void **state){ text_t text = text_create(); text_addSentenceByIndex(text, NULL, 0); assert_int_equal(text_getStatus(text), NULL_POINTER); text_remove(text); }
static void setSentenceByIndex__NonExistingIndex__putsINDEX_OUT_OF_BOUNDtoStatus(void **state){ text_t text = text_create(); text_setSentenceByIndex(text, "NONEXISTINGINDEX", -100500); assert_int_equal(text_getStatus(text), INDEX_OUT_OF_BOUND); text_remove(text); }
static void deleteSentenceByIndex__DeletingNonExistingIndex__putsINDEX_OUT_OF_BOUNDtoStatus(void **state){ text_t text = text_create(); text_deleteSentenceByIndex(text, -100500); assert_int_equal(text_getStatus(text), INDEX_OUT_OF_BOUND); text_remove(text); }
static void getStatus__callingINDEX_OUT_OF_BOUNDerror__returnStatus(void **state){ text_t text = text_create(); text_addSentenceByIndex(text, "TEST", 100500); assert_int_equal(text_getStatus(text), INDEX_OUT_OF_BOUND); text_remove(text); }