/** * tests parse() */ static char * test_parse() { Logo good, bad; int ret, i; printf("Testing %s\n", __FUNCTION__); /* a good input structure */ good = setup(3, "{"); insert_line(good, "FD 30"); insert_line(good, "}"); /* free good->vars as parse() makes a new one */ free(good->vars); ret = parse(good); mu_assert("error, ret != 0", ret == 0); /* the input->vars should be initialised */ for (i=0; i<VARARY_SIZE; i++) { mu_assert("good->vars[i].used != 0", good->vars[i].used == 0); mu_assert("good->vars[i].used != 0", good->vars[i].data == 0); } tear_down(good); /* a bad input structure */ bad = setup(3, "}"); insert_line(bad, "FD 30"); insert_line(bad, "}"); /* free bad->vars as parse() makes a new one */ free(bad->vars); ret = parse(bad); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); tear_down(bad); return 0; }
/** * tests varnum() */ static char * test_varnum() { Logo good, b_var, b_number; int ret; printf("Testing %s\n", __FUNCTION__); /* good input */ good = setup(4, "20"); insert_line(good, "H"); /* decimals and negative numbers */ insert_line(good, "2.5"); insert_line(good, "-2.5"); /* bad input */ b_var = setup(1, "AB"); b_number = setup(1, "209x"); /* test them */ ret = varnum(good->lines[0], good); mu_assert("error, ret != 0", ret == 0); ret = varnum(good->lines[1], good); mu_assert("error, ret != 0", ret == 0); ret = varnum(good->lines[2], good); mu_assert("error, ret != 0", ret == 0); ret = varnum(good->lines[3], good); mu_assert("error, ret != 0", ret == 0); ret = varnum(b_var->lines[0], b_var); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); ret = varnum(b_number->lines[0], b_number); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); tear_down(good); tear_down(b_var); tear_down(b_number); return 0; }
/** * tests instruction() */ static char * test_instruction() { Logo fd, lt, rt, set, dologo, bad1, bad2, bad3; int ret; printf("Testing %s\n", __FUNCTION__); /* create Logo handles for all 5 instructions */ fd = setup(1, "FD 30"); lt = setup(1, "LT 30"); rt = setup(1, "RT 30"); set = setup(1, "SET A := 30 ;"); dologo = setup(3, "DO A FROM 1 TO 5 {"); insert_line(dologo, "FD 20"); insert_line(dologo, "}"); /* test them all */ ret = instruction(fd); mu_assert("error, ret != 0", ret == 0); ret = instruction(rt); mu_assert("error, ret != 0", ret == 0); ret = instruction(lt); mu_assert("error, ret != 0", ret == 0); ret = instruction(set); mu_assert("error, ret != 0", ret == 0); ret = instruction(dologo); mu_assert("error, ret != 0", ret == 0); bad1 = setup(1, "DOESNOTEXIST 123"); ret = instruction(bad1); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); /* test that if any of the <INSTRUCTION> such as fd are malformed, ret == PARSE_ERR */ bad2 = setup(1, "FD abc990"); ret = instruction(bad2); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); /* tests empty string */ bad3 = setup(1, ""); ret = instruction(bad3); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); tear_down(fd); tear_down(lt); tear_down(rt); tear_down(set); tear_down(dologo); tear_down(bad1); tear_down(bad2); tear_down(bad3); return 0; }
/** * tests varnum() */ static char * test_varnum() { Logo good, b_var, b_number; int ret; float op; printf("Testing %s\n", __FUNCTION__); /* good input */ good = setup(4, "20"); /* decimals and negative numbers */ insert_line(good, "2.5"); insert_line(good, "-2.5"); insert_line(good, "A"); /* bad input */ b_var = setup(3, "AB"); /* non existant var */ insert_line(b_var, "C"); insert_line(b_var, "3-"); b_number = setup(1, "209x"); /* test them */ ret = varnum(good->lines[0], good, &op); mu_assert("error, ret != 0", ret == 0); mu_assert("error, op not set correctly", op == 20); ret = varnum(good->lines[1], good, &op); mu_assert("error, ret != 0", ret == 0); mu_assert("error, op not set correctly", op == 2.5); ret = varnum(good->lines[2], good, &op); mu_assert("error, ret != 0", ret == 0); mu_assert("error, op not set correctly", op == -2.5); /* set the var A */ set_var("A", good->vars, 20); ret = varnum(good->lines[3], good, &op); mu_assert("error, ret != 0", ret == 0); mu_assert("error, op not set correctly", op == 20); ret = varnum(b_var->lines[0], b_var, &op); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); ret = varnum(b_var->lines[1], b_var, &op); mu_assert("error, ret != VAR_ERR", ret == VAR_ERR); ret = varnum(b_var->lines[2], b_var, &op); mu_assert("error, ret != VAR_ERR", ret == PARSE_ERR); ret = varnum(b_number->lines[0], b_number, &op); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); tear_down(good); tear_down(b_var); tear_down(b_number); return 0; }
/** * tests rt() */ static char * test_rt() { Logo good, b_varnum, b_inst; int ret; printf("Testing %s\n", __FUNCTION__); /* good input */ good = setup(2, "RT 20"); insert_line(good, "RT A"); /* bad varnum */ b_varnum = setup(1, "RT 2P"); /* bad instruction */ b_inst = setup(1, "LT 20"); ret = rt(good); mu_assert("error, ret != 0", ret == 0); good->counter = good->counter + 1; ret = rt(good); mu_assert("error, ret != 0", ret == 0); ret = rt(b_varnum); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); ret = rt(b_inst); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); tear_down(good); tear_down(b_varnum); tear_down(b_inst); return 0; }
INLINE void csi_L(ldat nr) { if (nr > (ldat)SizeY - Y) nr = (ldat)SizeY - Y; else if (!nr) nr = 1; insert_line(nr); }
int undo(struct level2_data *data) { int i; /* Cicrular buffer. Avoid overflows. Any data older than */ /* UNDO_DEPTH is lost */ if (undo_data[undo_head].type==CHANGE_SPRITE) { *(data->level_data[undo_data[undo_head].y]+undo_data[undo_head].x)= undo_data[undo_head].value; } if (undo_data[undo_head].type==INSERT_LINE) { delete_line(data,undo_data[undo_head].y); } if (undo_data[undo_head].type==DELETE_LINE) { /* Re-insert line */ insert_line(data,undo_data[undo_head].y); /* Restore data */ for(i=0;i<ROW_WIDTH;i++) { *(data->level_data[undo_data[undo_head].y]+i)=undo_data[undo_head].row[i]; } } if (undo_head!=undo_tail) { undo_head--; if (undo_head<0) undo_head=UNDO_DEPTH; } return 0; }
static void fz_flush_text_line(fz_context *ctx, fz_text_device *dev, fz_text_style *style) { append_span(ctx, &dev->cur_line, &dev->cur_span); insert_line(ctx, dev->page, &dev->cur_line); init_span(ctx, &dev->cur_span, style); init_line(ctx, &dev->cur_line); }
int insert_line_file(t_hs path, t_hs line) { if (file_creator(path) < 0) return (-1); if (insert_line(path, line) == -1) return (-1); return (0); }
environment_list *insert_paramcount(environment_list *previous){ environment_list *node=malloc(sizeof(environment_list)); node->name="Function"; node->previous=previous; node->locals=insert_line(node->locals,"paramcount",_integer_,"return",_NULL_); return node; }
void get_fstab_d_dir() { DIR *fstab_d = NULL; struct dirent *dentry; fstab_d = opendir(FSTAB_D); if(fstab_d == NULL) { fprintf(stderr, "%s: %s\n", strerror(errno), FSTAB_D); return; } while((dentry = readdir(fstab_d)) != NULL) { struct stat sbuf; char *fullname = NULL; FILE *file = NULL; char line[1024]; /* ignore dot-files */ if(dentry->d_name[0] == '.') continue; /* skipping directories */ asprintf(&fullname, "%s/%s", FSTAB_D, dentry->d_name); if(stat(fullname, &sbuf) == -1) { fprintf(stderr, "%s: %s\n", strerror(errno), fullname); continue; } if(!S_ISREG(sbuf.st_mode)) continue; file = fopen(fullname, "r"); if(file == NULL) { fprintf(stderr, "%s: %s\n", strerror(errno), fullname); continue; } while(fgets(line, 1024, file) != NULL) { char filesystem[1024]; sscanf(line, "%s %*s", filesystem); if(filesystem[0] == '/') { struct stat buf; if(stat(filesystem, &buf) != 0) { continue; } } insert_line(line); } fclose(file); free(fullname); } closedir(fstab_d); }
int main(int argc, char **argv) { char *tablefile; char *dbfile; sqlite3 *db; FILE *table; char line[128]; int len; int i = 1; if (argc != 3) { printf("Usage: %s TABLE_FILE DB_FILE\n", argv[0]); printf("\n"); printf("Build DB_FILE out of TABLE_FILE.\n"); return -1; } tablefile = argv[1]; dbfile = argv[2]; printf("Building database '%s' from table '%s'...\n", dbfile, tablefile); // Create the database sqlite3_open_v2(dbfile, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); sqlite3_exec(db, "PRAGMA foreign_keys = ON;", NULL, NULL, NULL); sqlite3_exec(db, "BEGIN", NULL, NULL, NULL); sqlite3_exec(db, create_vocab, NULL, NULL, NULL); table = fopen(tablefile, "r"); while(fgets(line, 128, table) != NULL) { if (line[0] == '#' || line[0] == '\n') { continue; } len = strlen(line); if (line[len-1] == '\n') { line[len-1] = '\0'; len -= 1; } insert_line(db, line, i); i += 1; } sqlite3_exec(db, "COMMIT", NULL, NULL, NULL); fclose(table); sqlite3_exec(db, "CREATE INDEX i1 on codes(version, code);", NULL, NULL, NULL); sqlite3_close(db); return CANGJIE_OK; }
/*Creates an empty text, whose length is 0*/ text_t * create_text(){ text_t * root=malloc(sizeof(text_t)); root->key=0; root->left=NULL; root->right=NULL; root->height=0; insert_line(root,1,"NULL"); return root; }
/* ** 'edit_line' is the main line editing routine. */ void edit_line(void) { if (basicvars.misc_flags.badprogram) error(ERR_BADPROG); clear_refs(); basicvars.misc_flags.validsaved = FALSE; /* If program is edited mark save area contents as bad */ if (isempty(thisline)) /* Empty line = delete line */ delete_line(get_lineno(thisline)); else { insert_line(thisline); } }
//! process cached data lines void ImportData::process_linedata() { if (!create_table()) return; for (slist_type::const_iterator line = m_linedata.begin(); line != m_linedata.end(); ++line) { if (insert_line(*line)) { ++m_count, ++m_total_count; } } }
int modify_level(struct level2_data *data,int x,int y,int type,int value) { int i; modified_since_save++; /* Protect if you've made more than 2billion changes */ /* Unlikely, but the fix is shorter than the comment */ /* I was originally going to make about "broken if you*/ /* change more than 2 billion things" */ if (modified_since_save<0) modified_since_save=1; /* Cicrular buffer. Avoid overflows. Any data older than */ /* UNDO_DEPTH is lost */ undo_head++; if (undo_head>=UNDO_DEPTH) undo_head=0; if (undo_head==undo_tail) { undo_tail=undo_head+1; if (undo_tail>=UNDO_DEPTH) undo_tail=0; } if (type==CHANGE_SPRITE) { undo_data[undo_head].type=CHANGE_SPRITE; undo_data[undo_head].x=x; undo_data[undo_head].y=y; undo_data[undo_head].value= *(data->level_data[y]+x); *(data->level_data[y]+x)=value; } if (type==DELETE_LINE) { undo_data[undo_head].type=DELETE_LINE; undo_data[undo_head].y=y; for(i=0;i<ROW_WIDTH;i++) undo_data[undo_head].row[i]=*(data->level_data[y]+i); delete_line(data,y); } if (type==INSERT_LINE) { undo_data[undo_head].type=INSERT_LINE; undo_data[undo_head].y=y; insert_line(data,y); } return 0; }
/** * tests instrctlst() */ static char * test_instrctlst() { Logo good, bad1, bad2; int ret; printf("Testing %s\n", __FUNCTION__); /* a good input structure. no need for opening { as thats dealt with by mainlogo() */ good = setup(3, "FD 30"); insert_line(good, "RT 30"); insert_line(good, "}"); ret = instrctlst(good); mu_assert("error, ret != 0", ret == 0); /* a bad input structure that fails because of bad <INSTRUCTION> */ bad1 = setup(3, "BAD"); insert_line(bad1, "FDA 123"); insert_line(bad1, "}"); ret = instrctlst(bad1); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); /* a bad input structure that fails because of missing '}' */ bad2 = setup(3, "LT 30"); insert_line(bad2, "FD 30"); insert_line(bad2, "RT 20"); ret = instrctlst(bad2); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); tear_down(good); tear_down(bad1); tear_down(bad2); return 0; }
/* Appends new line as new last line */ void append_line(text_t *txt, char * new_line){ if(txt==NULL){ //No tree return NULL; }else{ //Get total lines and insert as last line int total_line=length_text(txt); insert_line(txt,total_line+1,new_line); } }
/** * tests fd() as well as chk_inst() */ static char * test_fd() { Logo good, b_varnum, b_inst, b_chk_inst; char *buffer; int ret; printf("Testing %s\n", __FUNCTION__); /* good input */ good = setup(2, "FD 20"); insert_line(good, "FD A"); /* bad varnum */ b_varnum = setup(1, "FD AB"); /* bad instruction */ b_inst = setup(1, "RT 20"); /* test chk_inst error checking */ b_chk_inst = setup(1, "FD"); ret = fd(good); mu_assert("error, ret != 0", ret == 0); good->counter = good->counter + 1; /* set the variable */ set_var("A", good->vars, 30.0); ret = fd(good); mu_assert("error, ret != 0", ret == 0); tear_down(good); /* expect postscript and test the output file */ char str[STR_LENGTH] = ""; char tmp[LINE_LENGTH]; sprintf(tmp, "%.2f 0 rlineto\n", 20 * LOGO2PS_FACTOR); strcat(str, tmp); sprintf(tmp, "%.2f 0 rlineto\n", 30 * LOGO2PS_FACTOR); strcat(str, tmp); buffer = get_content(TEST_OUT); mu_assert("error, TEST_OUT is not as expected", strcmp(buffer, str) == 0); free(buffer); ret = fd(b_varnum); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); tear_down(b_varnum); ret = fd(b_inst); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); tear_down(b_inst); ret = fd(b_chk_inst); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); tear_down(b_chk_inst); return 0; }
/** * tests parse() */ static char * test_parse() { Logo good, bad; int ret; printf("Testing %s\n", __FUNCTION__); /* a good input structure */ good = setup(3, "{"); insert_line(good, "FD 30"); insert_line(good, "}"); ret = parse(good); mu_assert("error, ret != 0", ret == 0); /* a bad input structure */ bad = setup(3, "}"); insert_line(bad, "FD 30"); insert_line(bad, "}"); ret = parse(bad); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); tear_down(good); tear_down(bad); return 0; }
/** * tests mainlogo() */ static char * test_mainlogo() { Logo good, bad1, bad2, bad3; int ret; printf("Testing %s\n", __FUNCTION__); /* a good input structure */ good = setup(3, "{"); insert_line(good, "FD 30"); insert_line(good, "}"); ret = mainlogo(good); mu_assert("error, ret != 0", ret == 0); /* a bad input structure that fails because of starting bracket */ bad1 = setup(3, "}"); insert_line(bad1, "FD 30"); insert_line(bad1, "}"); ret = mainlogo(bad1); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); /* a bad input structure that fails because of bad <INSTRCTLST> */ bad2 = setup(3, "{"); insert_line(bad2, "BAD 30"); insert_line(bad2, "}"); ret = mainlogo(bad2); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); /* stuff after closing bracket */ bad3 = setup(4, "{"); insert_line(bad3, "FD 30"); insert_line(bad3, "}"); insert_line(bad3, "FD 30"); ret = mainlogo(bad3); mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR); tear_down(good); tear_down(bad1); tear_down(bad2); tear_down(bad3); return 0; }
static void fz_text_free_user(fz_device *dev) { fz_context *ctx = dev->ctx; fz_text_device *tdev = dev->user; append_span(ctx, &tdev->cur_line, &tdev->cur_span); insert_line(ctx, tdev->page, &tdev->cur_line); /* TODO: smart sorting of blocks in reading order */ /* TODO: unicode NFC normalization */ /* TODO: bidi logical reordering */ fixup_text_page(dev->ctx, tdev->page); fz_free(dev->ctx, tdev); }
int main(int argc, char *argv[]) { int argument = 10; if (argc == 2) argument = abs(atoi(argv[1])); if (argument == 0) argument = 10; char currentline[500]; init_lineholder(argument); while (getline1(currentline) > 0) { insert_line(currentline); } print_lines(); }
void File::undo_redo(Kontext* kontext, Undo* undo) { Position* spos = undo->start_pos; iLineList l = top.line2iLine(spos->zeile); switch(undo->type) { case UNDO_CHANGE_LINE: for (iLineList ll = undo->l.begin(); ll != undo->l.end(); ++ll) { l->swap(*ll); ++l; } break; case UNDO_INSERT_LINE: undo->type = UNDO_DELETE_LINE; undo->n = undo->l.size(); insert_line(l, &undo->l); undo->l.clear(); break; case UNDO_DELETE_LINE: delete_lines(l, undo->n); undo->type = UNDO_INSERT_LINE; break; case UNDO_LINEBREAK: undo->type = UNDO_LINEUNBREAK; { iLineList pl = l; ++l; append_line(pl, undo->l.begin()); undo_list.clear_lines(); delete_lines(l, 1); // verschiebt nach undo_list } break; case UNDO_LINEUNBREAK: undo->l.clear(); kontext->newline(); break; default: fprintf(stderr, "internal Error: bad undo type\n"); break; } modified = true; dirty = true; }
void append_line(text_t *txt,char *new_line) { tree_node_t *root_node; root_node = txt->searchtree; if (root_node->left == NULL) { list_t *string_element; string_element = get_string(); string_element->data = strdup(new_line); root_node->key = 1; root_node->left = (tree_node_t *) string_element; root_node->right = NULL; root_node->height = 0; } else { insert_line(txt,length_text(txt) + 1,new_line); } }
void editor_main(player *p,char *str) { if (!p->edit_info) { log("error","Editor called with no edit_info"); return; } if (*str=='/') { restore_flags(p); match_commands(p,str+1); save_flags(p); return; } if (*str=='.') { sub_command(p,str+1,editor_list); if (p->edit_info) do_prompt(p,"+"); return; } insert_line(p,str); do_prompt(p,"+"); }
void get_filesystems() { FILE *fmounts = NULL; char line[1024]; fmounts = fopen("/proc/mounts", "r"); if(fmounts == NULL) { fprintf(stderr, "%s: %s\n", strerror(errno), "/proc/mounts"); return; } while(fgets(line, 1024, fmounts) != NULL) { char mountpoint[1024]; sscanf(line, "%*s %s %*s", mountpoint); if (strstr(mountpoint, TARGET) != mountpoint) continue; insert_line(line); } fclose(fmounts); }
void setupnode( void ) { sentinel = ( struct line_node * ) malloc( sizeof( struct line_node ) ); sentinel->next = sentinel; sentinel->previous = sentinel; sentinel->text = NULL; #ifdef WANT_TO_USE_GRAPH sentinel->graph = NULL; #endif sentinel->wrap = NO; curline = ( struct line_node * ) malloc( sizeof( struct line_node ) ); curline->wrap = NO; curline->text = ( char * ) malloc( 1 ); *( curline->text ) = '\0'; #ifdef WANT_TO_USE_GRAPH curline->graph = NULL; #endif insert_line( sentinel, curline ); curpage = curline; loadtoline( curline->text ); }
table_element *insert_func(int is_defined,Node *aux, environment_list *env, environment_list *outter_table){ check_if_defined(aux,env); lower(aux->value.s);//value to lowercase table_element *nodeFuncDef = malloc(sizeof(table_element));//cria elemento que vai ser introduzido na tabela nodeFuncDef->name=aux->value.s; nodeFuncDef->type=_function_; nodeFuncDef->flag=""; nodeFuncDef->value=_NULL_; nodeFuncDef->header=malloc(sizeof(environment_list));//cria new table ligada ao elemento nodeFuncDef->header->defined=is_defined; nodeFuncDef->header->name="Function"; nodeFuncDef->header->previous=env; //Primeira linha da new table contem ID da function, tipo e flag //tipo da function está localizado em aux->next->next->value.s //insere primeira linha da new table tolower(aux->next->next->value.s); nodeFuncDef->header->locals=insert_line(nodeFuncDef->header->locals,aux->value.s,check_type(aux->next->next,env),"return",_NULL_); //insere o resto das linhas da new table nodeFuncDef->header=insert_table(aux->next,nodeFuncDef->header,env,outter_table); return nodeFuncDef; }
void get_swapspaces() { FILE *fswaps = NULL; char line[1024]; fswaps = fopen("/proc/swaps", "r"); if(fswaps == NULL) { fprintf(stderr, "%s: %s\n", strerror(errno), "/proc/swaps"); return; } while(fgets(line, 1024, fswaps) != NULL) { char filesystem[1024]; char *swline = NULL; if(line[0] != '/') continue; sscanf(line, "%s %*s %*s %*s %*s", filesystem); asprintf(&swline, "%s\tnone\tswap\tsw", filesystem); insert_line(swline); } fclose(fswaps); }