STATUS skip_comment(FILE *aFile,char *cbuff,char preprint) { STATUS ret_status = OK ; if ((preprint == FALSE) && (cbuff != NULL)) { append_line(cbuff,0); } do { if ((ret_status = read_fm_command(aFile)) == OK) { if ((sep_state&IN_COMMENT_STATE)||(sep_state_old&IN_COMMENT_STATE)) { append_line(buffer_1,0); } } } while ((sep_state_old&IN_COMMENT_STATE)&&(ret_status == OK)); if (preprint == TRUE) append_line(buffer_1,0); return (ret_status); } /* end of skip_comment */
/*---------------------------------------------------------------------------*/ line* text2lines( char* text ) { char* dup = strdup( text ); line* res = 0; char* s; char* b; char* b1; char buf[80]; s = dup; while( 1 ) { /* Up to the end of line */ bzero( buf, 80 ); strncpy( buf, s, 78 ); /* Last line */ if ( buf[77]==0) { /* last line */ res = append_line( res, create_line(buf) ); break; } /* Wrapping at word */ if ( buf[77]!=' ' ) { /* wrapping a word */ b = strrchr( buf, ' ' ); /* Find the lasy space */ if ( !b ) { /* long word */ res = append_line( res, create_line(buf) ); s+=78; continue; } s += (78-(strlen(b)-1)); /* Set new pointer to the beginning of the word */ *b = 0; strip( buf ); if ( strlen(buf) ) strcat(buf, " "); res = append_line( res, create_line(buf) ); continue; } /* Wrapping at space */ b = buf+76; strip( buf ); if ( strlen(buf) ) strcat(buf, " "); res = append_line( res, create_line(buf) ); s+=78; } while ( res->prev ) res = res->prev; free(dup); return res; }
/* Line state. */ int imap_state_line(struct account *a, struct fetch_ctx *fctx) { struct fetch_imap_data *data = a->data; struct mail *m = fctx->mail; char *line; size_t used, size, left; for (;;) { if (imap_getln(a, fctx, IMAP_RAW, &line) != 0) return (FETCH_ERROR); if (line == NULL) return (FETCH_BLOCK); if (data->flushing) continue; /* Check if this line would exceed the expected size. */ used = m->size + data->lines; size = strlen(line); if (used + size + 2 > data->size) break; if (append_line(m, line, size) != 0) { log_warnx("%s: failed to resize mail", a->name); return (FETCH_ERROR); } data->lines++; } /* * Calculate the number of bytes still needed. The current line must * include at least that much data. Some servers include UID or FLAGS * after the message: we don't care about these so just ignore them and * make sure there is a terminating ). */ left = data->size - used; if (line[size - 1] != ')' && size <= left) return (imap_invalid(a, line)); /* If there was data left, add it as a new line without trailing \n. */ if (left > 0) { if (append_line(m, line, left) != 0) { log_warnx("%s: failed to resize mail", a->name); return (FETCH_ERROR); } data->lines++; /* Wipe out the trailing \n. */ m->size--; } fctx->state = imap_state_mail; return (FETCH_AGAIN); }
static void readfile_cmd(char *line) { FILE *fp; FILE *tmpfp; FILE *tmpfp2; char *tfn; char *cp; for (cp = line + 2; *cp && (isspace((unsigned char) *cp)); cp++) continue; tfn = cp; for (; *cp && !(isspace((unsigned char) *cp)); cp++) continue; *cp = '\0'; if ((fp = fopen(tfn, "r")) == NULL) { fprintf(stderr, "Operating system error: Failed to open %s.\n", tfn); return; } tmpfp = rl_instream; tmpfp2 = rl_outstream; rl_instream = fp; rl_outstream = fopen("/dev/null", "w"); while ((line = readline("")) != NULL) { append_line(line); } rl_instream = tmpfp; fclose(rl_outstream); rl_outstream = tmpfp2; fclose(fp); fputc('\r', stdout); fflush(stdout); }
static void insert_line(fz_context *ctx, fz_text_page *page, fz_text_line *line) { if (line->len == 0) return; append_line(ctx, lookup_block_for_line(ctx, page, line), line); }
static void vi_cmd(const char *command) { char tmpfn[256]; FILE *fp; int i; char *sqlch; FILE *tmpfp; char *line; char foobuf[40]; int tmpfd; mode_t old_mask; strcpy(tmpfn, "/tmp/fisqlXXXXXX"); old_mask = umask(077); tmpfd = mkstemp(tmpfn); umask(old_mask); if (tmpfd < 0 || (fp = fdopen(tmpfd, "w")) == NULL) { perror("fisql"); reset_term(); dbexit(); exit(2); } if (ibuflines) { for (i = 0; i < ibuflines; i++) { fputs(ibuf[i], fp); fputc('\n', fp); free(ibuf[i]); } } else { for (i = 0; ((sqlch = dbgetchar(dbproc, i)) != NULL); i++) { fputc(*sqlch, fp); } } fclose(fp); edit(command, tmpfn); ibuflines = 0; fp = fopen(tmpfn, "r"); if (!fp) { perror("fisql"); reset_term(); dbexit(); exit(2); } tmpfp = rl_instream; rl_instream = fp; strcpy(foobuf, "1>> "); while ((line = readline(foobuf)) != NULL) { append_line(line); sprintf(foobuf, "%d>> ", ibuflines + 1); } rl_instream = tmpfp; fclose(fp); fputc('\r', stdout); fflush(stdout); unlink(tmpfn); }
/* ** close_log */ STATUS close_log() { STATUS ret_val = OK ; SYSTIME atime ; char buffer [TEST_LINE] ; char timestr [TEST_LINE] ; append_line((char *)ERx("\n"),(i4)1); TMnow(&atime); TMstr(&atime,timestr); STprintf(buffer,ERx("Ending at: %s"),timestr); append_line(buffer,1); SIclose(logptr); return (ret_val); }
STATUS create_canon_fe(SEPFILE *res_ptr) { STATUS ret_val = OK ; /* if OK, refresh FE screen */ char do_com_result ; #ifdef VMS if (SEPtcsubs < 4) PCsleep(1000); #endif show_cursor(); do_com_result = do_comments(); append_line(OPEN_CANON,1); switch (do_com_result) { case 'R': case 'r': append_sepfile(res_ptr); break; case 'E': case 'e': break; case 'I': case 'i': append_line(SKIP_SYMBOL,1); break; } append_line(CLOSE_CANON,1); kfe_ptr = kfebuffer; /* reset counter for key buffer */ if (canonAns == EOS) { disp_prompt(NULLSTR,NULL,NULL); /* erase prompt */ } else { CMnext(kfe_ptr); ret_val = FAIL; /* don't refresh FE screen */ } return (ret_val); }
STATUS create_canon(SEPFILE *res_ptr) { STATUS ret_val ; char do_com_result ; if ((ret_val = disp_res(res_ptr)) == OK) { put_message(statusW, NULLSTR); do_com_result = do_comments(); append_line(OPEN_CANON,1); switch (do_com_result) { case 'R': case 'r': append_sepfile(res_ptr); break; case 'E': case 'e': break; case 'I': case 'i': append_line(SKIP_SYMBOL,1); break; } append_line(CLOSE_CANON,1); if (canonAns == EOS) { disp_prompt(NULLSTR,NULL,NULL); } fix_cursor(); } return (ret_val); }
/* ** insert_comment () */ STATUS insert_comment () { STATUS ret_val ; OFFSET_TYPE size ; if ((ret_val = bld_cmtName(msg)) != OK) { disp_line(msg, 0, 0); } else if (SEP_LOexists(cmtLoc)) { LOsize(cmtLoc, &size); if (size > 0) { append_line(OPEN_COMMENT, 1); append_file(cmtName); append_line(CLOSE_COMMENT, 1); } del_floc(cmtLoc); } return (ret_val); } /* end of insert_comment */
bool Eval_If(char *commands[]) { STATUS eval_err ; char buffer [128] ; char *tokptr [12] ; register i4 tok_ctr = 0 ; i4 answer = TRUE ; for (tok_ctr=0; tok_ctr<12; tok_ctr++) tokptr[tok_ctr] = 0; *buffer = EOS; for (tok_ctr=2; commands[tok_ctr]; tok_ctr++) STcat(buffer, commands[tok_ctr]); /* Condense the expression. */ *msg = EOS; answer = SEP_Eval_If( buffer, &eval_err, msg); if (eval_err != OK) { testGrade = FAIL; if (*msg == EOS) { disp_line(STpolycat(4,ErrC,ERx("Evaluate Expresion <"),buffer, ERx(">"),msg),0,0); } else { disp_line(msg,0,0); } append_line(msg,1); return(FAIL); } if (answer == TRUE) { return (TRUE); } else { return (FALSE); } }
STATUS append_file(char *filename) { LOCATION fileloc ; FILE *fileptr = NULL ; char buffer [SCR_LINE] ; if (LOfroms(FILENAME & PATH,filename,&fileloc) == OK && SEP_LOexists(&fileloc) && SIopen(&fileloc,ERx("r"),&fileptr) == OK) { while (SIgetrec(buffer,SCR_LINE,fileptr) == OK) append_line(buffer,0); return(SIclose(fileptr)); } else return(FAIL); }
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; }
static char *read_file(const char *from) { char *line = NULL; char *contents = NULL; FILE *f = fopen(from, "r"); size_t len = 0, fulllen = 0; if (!f) return NULL; while (getline(&line, &len, f) != -1) { append_line(&contents, line, &fulllen); } fclose(f); if (contents) drop_trailing_newlines(contents); free(line); return contents; }
plc_t generate_code(unsigned int length, const char * name, const ld_line_t * program, plc_t p) { int rv = PLC_OK; rung_t r = mk_rung(name, p); int i = 0; for(; i < length && rv == PLC_OK; i++){ r->code = append_line(trunk_whitespace(program[i]->buf), r->code); if(program[i]->stmt != NULL && program[i]->stmt->tag == TAG_ASSIGNMENT) rv = gen_ass(program[i]->stmt, r); //clear_tree(program[i]->stmt); } p->status = rv; return p; }
void print_test_info(struct yaml_string * ys, char * name, char * input, char * expected, char * points){ char test_name[256]; sprintf(test_name, "%s:", name); append_line(ys, test_name, 0); append_line(ys, "input: |", INDENT); append_line(ys, input, INDENT * 2); append_line(ys, "expected: |", INDENT); append_line(ys, expected, INDENT * 2); append_line(ys, "points: |", INDENT); append_line(ys, points, INDENT * 2); flush_yaml(ys); }
//, const std::map<std::string, std::string> & definitions void ShaderParser::parse(std::istream & input_stream) { parse_header(input_stream); std::string line_buffer; while (input_stream.good()) { // Read one line: std::getline(input_stream, line_buffer); _line += 1; if (line_buffer.find("@geometry") == 0) { set_current_source(SourceType::GEOMETRY); } else if (line_buffer.find("@vertex") == 0) { set_current_source(SourceType::VERTEX); } else if (line_buffer.find("@fragment") == 0) { set_current_source(SourceType::FRAGMENT); } else { append_line(line_buffer); } } }
/*---------------------------------------------------------------------------*/ line* text2lines_old( char* text ) { /* an old version */ /* Just a simple implementation waiting for improvements! */ int len; int i; char* b; char* b1; char* s; line* res = 0; int c; char* dup; if ( !(*text) ) { /* Line is empty */ return create_line(""); } dup = strdup( text ); s = dup; while ( *s ) { len = strlen( s ); if ( len < 77 ) { res = append_line( res, create_line( s ) ); break; } b = s + 78; if ( *b!=' ' ) { c = *b; *b = 0; b1 = strrchr( s, ' ' ); *b = c; if ( !b1 ) { /* it's a one long word */ c = *(b-1); *(b-1) = 0; res = append_line( res, create_line( s ) ); /* strcat( res->text, "-" ); */ *(b-1) = c; s = b-1; continue; } c=*(b1+1); *(b1+1) = 0; res = append_line( res, create_line( s ) ); *(b1+1) = c; s = b1+1; continue; } c = *(b+1); *(b+1) = 0; res = append_line( res, create_line( s ) ); *(b+1) = c; s = b+1; } while ( res->prev ) res = res->prev; free( dup ); return res; }
i4 Is_it_If_statement(FILE *testFile,i4 *counter,bool Ignore_it) { char *cp1 = NULL ; char *cp2 = NULL ; i4 cmd ; bool yes_its_if = FALSE ; bool yes_its_tc = FALSE ; cmd = 0; if ((!shellMode)&&(SEP_CMstlen(lineTokens[0],0) > 1)&& (CMcmpcase(lineTokens[0],ERx(".")) == 0)) { cp1 = buffer_1 ; /* Fix the ".if" statement. */ cp2 = buffer_2 ; STcopy(buffer_1, holdBuf); CMcpyinc(cp1,cp2); CMcpychar(ERx(" "),cp2); CMnext(cp2); STcopy(cp1, cp2); STcopy(buffer_2, buffer_1); break_line(buffer_2, counter, lineTokens); } cmd = classify_cmmd(sepcmmds, lineTokens[1]); if (cmd == IF_CMMD || cmd == ELSE_CMMD || cmd == ENDIF_CMMD) { yes_its_if = TRUE; } else if (cmd == TEST_CASE_CMMD || cmd == TEST_CASE_END_CMMD) { yes_its_tc = TRUE; } if (yes_its_if || yes_its_tc) { append_line(holdBuf, 0); if (Ignore_it) ignore_silent == TRUE; if (yes_its_if) { process_if(testFile, lineTokens, cmd); } else if (yes_its_tc) { if (cmd == TEST_CASE_CMMD) { testcase_start(&lineTokens[1]); } else if (cmd == TEST_CASE_END_CMMD) { testcase_end(FALSE); } } if (Ignore_it) ignore_silent == FALSE; } else { cmd = 0; } return (cmd); }
gboolean ifnet_init (gchar * config_file) { GIOChannel *channel = NULL; gchar *line; /* Handle multiple lines with brackets */ gboolean complete = TRUE; gboolean openrc_style = TRUE; /* line buffer */ GString *buf; net_parser_data_changed = FALSE; conn_table = g_hash_table_new (g_str_hash, g_str_equal); global_settings_table = g_hash_table_new (g_str_hash, g_str_equal); functions_list = NULL; if (g_file_test (config_file, G_FILE_TEST_IS_REGULAR)) channel = g_io_channel_new_file (config_file, "r", NULL); if (channel == NULL) { nm_log_warn (LOGD_SETTINGS, "Can't open %s", config_file); return FALSE; } buf = g_string_new (NULL); while (g_io_channel_read_line (channel, &line, NULL, NULL, NULL) != G_IO_STATUS_EOF) { g_strstrip (line); /* convert multiple lines to a complete line and * pass it to init_block_by_line() */ if (is_function (line)) { strip_function (channel, line); continue; } // New openrc style, bash arrays are not allowed. We only care about '"' if (openrc_style && line[0] != '#' && line[0] != '\0' && !strchr (line, '(') && !strchr (line, ')')) { gchar *tmp = line; while ((tmp = strchr (tmp, '"')) != NULL) { complete = !complete; ++tmp; } append_line (buf, line); // Add "(separator) for routes. It will be easier for later parsing if (strstr (buf->str, "via")) g_string_append_printf (buf, "\""); if (!complete) continue; strip_string (buf->str, '"'); init_block_by_line (buf->str); g_string_free (buf, TRUE); buf = g_string_new (NULL); } // Old bash arrays for baselayout-1, to be deleted else if (line[0] != '#' && line[0] != '\0') { if (!complete) { complete = g_strrstr (line, ")") == NULL ? FALSE : TRUE; append_line (buf, line); if (!complete) { openrc_style = FALSE; continue; } else { openrc_style = TRUE; } } else { complete = (g_strrstr (line, "(") != NULL && g_strrstr (line, ")") != NULL) || g_strrstr (line, "(") == NULL; append_line (buf, line); if (!complete) { openrc_style = FALSE; continue; } else { openrc_style = TRUE; } } init_block_by_line (buf->str); g_string_free (buf, TRUE); buf = g_string_new (NULL); } else /* Blank line or comment line */ g_free (line); } g_string_free (buf, TRUE); g_io_channel_shutdown (channel, FALSE, NULL); g_io_channel_unref (channel); return TRUE; }
/* This function inserts the line before the line of number index, if such a line exists, to new line, renumbering all lines after that line. If no such line exists, it appends new line as new last line */ void insert_line(text_t *txt, int index, char * new_line) { text_t *tmp_node = txt; int finished; int count = index; if (txt->left == NULL) { txt->left = (text_t *) create_object(new_line); txt->key = 1; txt->right = NULL; txt->parent = NULL; txt->height = 0; } else if (index > (tmp_node->key)) { append_line(txt, new_line); } else { while(tmp_node->right != NULL) { (tmp_node->key)++; if (count <= tmp_node->left->key) { tmp_node = tmp_node->left; } else { count -= tmp_node->left->key; tmp_node = tmp_node->right; } } text_t *old_leaf, *new_leaf; old_leaf = get_node(); new_leaf = get_node(); old_leaf->left = tmp_node->left; old_leaf->key = 1; old_leaf->right = NULL; old_leaf->parent = tmp_node; old_leaf->height = 0; new_leaf->left = (text_t *) create_object(new_line); new_leaf->key = 1; new_leaf->right = NULL; new_leaf->parent = tmp_node; new_leaf->height = 0; tmp_node->right = old_leaf; tmp_node->left = new_leaf; (tmp_node->key)++; tmp_node->height = 0; finished = 0; while(!finished && tmp_node!=NULL) { int tmp_height, old_height; old_height = tmp_node->height; if (tmp_node->left->height - tmp_node->right->height == 2) { if (tmp_node->left->left->height - tmp_node->right->height == 1) { right_rotation(tmp_node); tmp_node->right->height = tmp_node->right->left->height + 1; tmp_node->height = tmp_node->right->height + 1; tmp_node->right->key = tmp_node->right->left->key + tmp_node->right->right->key; tmp_node->key = tmp_node->left->key + tmp_node->right->key; } else { left_rotation(tmp_node->left); right_rotation(tmp_node); tmp_height = tmp_node->left->left->height; tmp_node->left->height = tmp_height + 1; tmp_node->right->height = tmp_height + 1; tmp_node->height = tmp_height + 2; tmp_node->left->key = tmp_node->left->left->key + tmp_node->left->right->key; tmp_node->right->key = tmp_node->right->left->key + tmp_node->right->right->key; tmp_node->key = tmp_node->left->key + tmp_node->right->key; } } else if (tmp_node->left->height - tmp_node->right->height == -2) { if( tmp_node->right->right->height - tmp_node->left->height == 1) { left_rotation(tmp_node); tmp_node->left->height = tmp_node->left->right->height + 1; tmp_node->height = tmp_node->left->height + 1; tmp_node->left->key = tmp_node->left->left->key + tmp_node->left->right->key; tmp_node->key = tmp_node->left->key + tmp_node->right->key; } else { right_rotation(tmp_node->right); left_rotation(tmp_node); tmp_height = tmp_node->right->right->height; tmp_node->left->height = tmp_height + 1; tmp_node->right->height = tmp_height + 1; tmp_node->height = tmp_height + 2; tmp_node->right->key = tmp_node->right->left->key + tmp_node->right->right->key; tmp_node->left->key = tmp_node->left->left->key + tmp_node->left->right->key; tmp_node->key = tmp_node->left->key + tmp_node->right->key; } } else { if(tmp_node->left->height > tmp_node->right->height) { tmp_node->height = tmp_node->left->height + 1; } else { tmp_node->height = tmp_node->right->height + 1; } } if (tmp_node->height == old_height) { finished = 1; } tmp_node = tmp_node->parent; } } }
void insert_line(text_t *txt, int index, char * new_line) { text_t *tmp_node; int finished; text_t * path_stack[100]; int path_st_p; text_t *old_leaf, *new_leaf; int tmp_height, old_height; if( txt->left == NULL ){ txt->left = (text_t *)new_line; txt->key = 1; txt->height = 0; txt->right = NULL; return; }else{ path_st_p = 0; tmp_node = txt; //append or not if(index > txt->key) { append_line(txt, new_line); return; } while( tmp_node->right != NULL ){ path_stack[path_st_p++] = tmp_node; if(tmp_node->left->key >= index) { tmp_node = tmp_node->left; }else { index -= tmp_node->left->key; tmp_node = tmp_node->right; } } { old_leaf = get_node(); old_leaf->left = tmp_node->left; old_leaf->key = tmp_node->key; old_leaf->right = NULL; old_leaf->height = 0; new_leaf = get_node(); new_leaf->left = (text_t *)new_line; new_leaf->key = 1; new_leaf->right = NULL; new_leaf->height = 0; tmp_node->left = new_leaf; tmp_node->right = old_leaf; tmp_node->key = old_leaf->key + new_leaf->key; tmp_node->height = 1; } //rebalance */ finished = 0; while( path_st_p > 0 && !finished ){ tmp_node = path_stack[--path_st_p]; //update key here; tmp_node->key = tmp_node->left->key + tmp_node->right->key; old_height = tmp_node->height; if( tmp_node->left->height - tmp_node->right->height == 2 ){ if( tmp_node->left->left->height - tmp_node->right->height == 1 ){ right_rotation( tmp_node ); tmp_node->right->height = tmp_node->right->left->height + 1; tmp_node->height = tmp_node->right->height + 1; // update key tmp_node->key = tmp_node->right->key; tmp_node->right->key = tmp_node->right->left->key + tmp_node->right->right->key; }else{ // need change here !!!!!! or not left_rotation( tmp_node->left ); int switch_tmp = tmp_node->left->key; tmp_node->left->key = tmp_node->left->left->key; tmp_node->left->left->key = switch_tmp; right_rotation( tmp_node ); tmp_node->key = tmp_node->right->key; tmp_node->right->key = tmp_node->right->left->key + tmp_node->right->right->key; tmp_height = tmp_node->left->left->height; tmp_node->left->height = tmp_height + 1; tmp_node->right->height = tmp_height + 1; tmp_node->height = tmp_height + 2; } }else if ( tmp_node->left->height - tmp_node->right->height == -2 ){ if( tmp_node->right->right->height - tmp_node->left->height == 1 ){ left_rotation( tmp_node ); tmp_node->left->height = tmp_node->left->right->height + 1; tmp_node->height = tmp_node->left->height + 1; //add line to update key. tmp_node->key = tmp_node->left->key; tmp_node->left->key = tmp_node->left->left->key + tmp_node->left->right->key; }else{ right_rotation( tmp_node->right ); int switch_tmp = tmp_node->right->key; tmp_node->right->key = tmp_node->right->right->key; tmp_node->right->right->key = switch_tmp; left_rotation( tmp_node ); tmp_node->key = tmp_node->left->key; tmp_node->left->key = tmp_node->left->left->key + tmp_node->left->right->key; tmp_height = tmp_node->right->right->height; tmp_node->left->height = tmp_height + 1; tmp_node->right->height = tmp_height + 1; tmp_node->height = tmp_height + 2; } }else{ if( tmp_node->left->height > tmp_node->right->height ) tmp_node->height = tmp_node->left->height + 1; else tmp_node->height = tmp_node->right->height + 1; } if( tmp_node->height == old_height ) finished = 1; } while( path_st_p > 0){ tmp_node = path_stack[--path_st_p]; // add new line update key tmp_node->key = tmp_node->left->key + tmp_node->right->key; } } }
int add_to_history(char *word, char *history_file){ int errnum = append_line(word, history_file); return errnum; }
bool append_line(String & str) {return append_line(str, delem);}
STATUS append_sepfile(SEPFILE *sepptr) { STATUS ioerr ; char buffer [SCR_LINE] ; FILE *fptr = sepptr->_fptr ; char *endptr, prev_char=EOS ; i4 count, i ; #ifdef NT_GENERIC char *ptr = NULL; i4 buffCount, count2; bool more_found; #endif SEPrewind(sepptr, FALSE); /* ** special case if dealing with diff output because ** (a) lines are padded with spaces to TEST_LINE ** (b) do not have `\n' ** (c) first character of last line is SEPENDFILE ** because of the skewing of the canon & result files ** especially when special characters are found in those ** files, the SEPENDFILE character may NOT appear in the ** second character of a line after the slash '\'. */ if (sepptr == sepDiffer) { for (;;) { ioerr = SIread(fptr, TEST_LINE, &count, buffer); #ifdef VMS if (ioerr != OK) break; #endif #ifdef UNIX if (ioerr != OK && ioerr != ENDFILE) break; /* Detect EOF if we miss the trailing '\',0xFF */ if( count == 0 ) { ioerr = ENDFILE; break; } #endif #ifdef NT_GENERIC if (ioerr != OK && ioerr != ENDFILE) break; ptr = buffer; i = count = 0; count2 = TEST_LINE; more_found = TRUE; while ((more_found == TRUE) && (ioerr == OK || ioerr == ENDFILE)) { count2 = count2 + count; buffCount = 0; while (i != count2) { if (buffer[i] == SEP_ESCAPE) { CMnext(ptr); i++; if (i == count2) { if (fptr->_ptr[0] == SEP_ESCAPE) buffCount++; } else if (buffer[i] == SEP_ESCAPE) buffCount++; } if (i != count2) { i++; CMnext(ptr); } } if (buffCount > 0) ioerr = SIread(fptr, buffCount, &count, ptr); else more_found = FALSE; } if (ioerr != OK && ioerr != ENDFILE) break; #endif /* Detect EOF if '\', 0xFF split across two reads */ if( buffer[0] == SEPENDFILE && prev_char == '\\' ) { ioerr = ENDFILE; break; } prev_char = buffer[81]; /* Detect EOF if '\', 0xFF are in consecutive bytes in the buffer */ for(i=0, endptr=buffer; i < TEST_LINE; ++i, ++endptr) { if( i > 0 && *endptr == SEPENDFILE && *(endptr-1) == '\\' ) break; } if( i > 0 && *endptr == SEPENDFILE && *(endptr-1) == '\\' ) { ioerr = ENDFILE; break; } buffer[TEST_LINE] = '\0'; SEPtranslate(buffer, SCR_LINE); STtrmwhite(buffer); append_line(buffer, 1); } } else { while ((ioerr = SEPgetrec(buffer, sepptr)) == OK) append_line(buffer, 0); } return(ioerr == ENDFILE ? OK : FAIL); }
STATUS open_log(char *testPrefix,char *testSufix,char *username,char *errbuff) { SYSTIME atime ; char uname [20] ; char logFileName [MAX_LOC+1] ; char timestr [TEST_LINE] ; char buffer [MAX_LOC+1] ; char *dot = NULL ; char *cptr = NULL ; char year[5]; if (shellMode) STpolycat(3, testPrefix, ERx("."), testSufix, logFileName); else if (updateMode) STpolycat(2, testPrefix, ERx(".upd"), logFileName); else STpolycat(2, testPrefix, ERx(".log"), logFileName); if (outputDir) { if (outputDir_type == PATH) { STcopy(outputDir, buffer); LOfroms(PATH, buffer, &logloc); LOfstfile(logFileName, &logloc); LOtos(&logloc, &cptr); } else { LOtos(&outLoc,&cptr); } STcopy(cptr, logname); } else STcopy(logFileName, logname); if (LOfroms(FILENAME & PATH, logname, &logloc) != OK) { STprintf(errbuff,ERx("ERROR: could not get location for log file")); return(FAIL); } if (SIopen(&logloc,ERx("w"),&logptr) != OK) { STprintf(errbuff,ERx("ERROR: could not open log file")); return(FAIL); } if (!updateMode) { append_line(ERx("/*"),1); copyright_year(&year[0]); STprintf(buffer, ERx("Copyright (c) %s Ingres Corporation"), &year); append_line(buffer, 1); append_line(ERx(" "), 1); STprintf(buffer,ERx("\tTest Name: %s.%s"), testPrefix, testSufix); append_line(buffer,1); TMnow(&atime); TMstr(&atime,timestr); STprintf(buffer,ERx("\tTime: %s"),timestr); append_line(buffer,1); dot = uname; if (username == NULL || *username == '\0') IDname(&dot); else STcopy(username,uname); STprintf(buffer,ERx("\tUser Name: %s"),uname); append_line(buffer,1); STprintf(buffer, ERx("\tTerminal type: %s"), terminalType); append_line(buffer,1); append_line(ERx(" "),1); } return(OK); }
void BedShapePanel::build_panel(ConfigOptionPoints* default_pt) { // on_change(nullptr); auto box = new wxStaticBox(this, wxID_ANY, _(L("Shape"))); auto sbsizer = new wxStaticBoxSizer(box, wxVERTICAL); // shape options m_shape_options_book = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxSize(300, -1), wxCHB_TOP); sbsizer->Add(m_shape_options_book); auto optgroup = init_shape_options_page(_(L("Rectangular"))); ConfigOptionDef def; def.type = coPoints; def.default_value = new ConfigOptionPoints{ Pointf(200, 200) }; def.label = L("Size"); def.tooltip = L("Size in X and Y of the rectangular plate."); Option option(def, "rect_size"); optgroup->append_single_option_line(option); def.type = coPoints; def.default_value = new ConfigOptionPoints{ Pointf(0, 0) }; def.label = L("Origin"); def.tooltip = L("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle."); option = Option(def, "rect_origin"); optgroup->append_single_option_line(option); optgroup = init_shape_options_page(_(L("Circular"))); def.type = coFloat; def.default_value = new ConfigOptionFloat(200); def.sidetext = L("mm"); def.label = L("Diameter"); def.tooltip = L("Diameter of the print bed. It is assumed that origin (0,0) is located in the center."); option = Option(def, "diameter"); optgroup->append_single_option_line(option); optgroup = init_shape_options_page(_(L("Custom"))); Line line{ "", "" }; line.full_width = 1; line.widget = [this](wxWindow* parent) { auto btn = new wxButton(parent, wxID_ANY, _(L("Load shape from STL...")), wxDefaultPosition, wxDefaultSize); auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(btn); btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) { load_stl(); })); return sizer; }; optgroup->append_line(line); Bind(wxEVT_CHOICEBOOK_PAGE_CHANGED, ([this](wxCommandEvent e) { update_shape(); })); // right pane with preview canvas m_canvas = new Bed_2D(this); m_canvas->m_bed_shape = default_pt->values; // main sizer auto top_sizer = new wxBoxSizer(wxHORIZONTAL); top_sizer->Add(sbsizer, 0, wxEXPAND | wxLeft | wxTOP | wxBOTTOM, 10); if (m_canvas) top_sizer->Add(m_canvas, 1, wxEXPAND | wxALL, 10) ; SetSizerAndFit(top_sizer); set_shape(default_pt); update_preview(); }
void insert_line(tree_node *tree, int new_key, char *new_line){ //Inserts the line before the line of the number `new_key`, if such //a line exists, to `new_line` , renumbering all lines after that line. //If no such line exists, it `appends(new_line)` as last line. tree_node *temp_node; int finished; if(tree->left == NULL){ //empty tree. no children tree->left = (tree_node *) new_line; //tree->key = new_key; tree->key +=1; tree->height = 0; tree->right = NULL; } if(tree->key == 1){ //the root has one child tree_node *left_child, *right_child; left_child = get_node(); right_child = get_node(); left_child->left = tree->left; left_child->key = tree->key; right_child->left = (tree_node *) new_line; right_child->key += 1; tree->left = left_child; tree->right = right_child; tree->key += 1; } if (tree->key < new_key){ //go to the left branch append_line(tree, new_line); } else{ //go to the right branch tree_node *stack[STACK_MAX]; int stack_ptr = 0; temp_node = tree; while(temp_node->right != NULL){ stack[stack_ptr++] = temp_node; temp_node->key += 1; if (new_key <= temp_node->left->key){ temp_node = temp_node->left; } else{ new_key -= temp_node->left->key; temp_node = temp_node->right; } } tree_node *left_child, *right_child; left_child = get_node(); right_child = get_node(); left_child->left = temp_node->left; left_child->key = temp_node->key; right_child->left = (tree_node *) new_line; right_child->key += 1; temp_node->left = left_child; temp_node->right = right_child; temp_node->key += 1; temp_node->height = 1; //rebalance tree finished = 0; while(stack_ptr > 0 && !finished){ int temp_height , old_height; temp_node = stack[--stack_ptr]; old_height = temp_node->height; if(temp_node->left->height - temp_node->right->height == 2){ if (temp_node->left->left->height - temp_node->right->height == 1){ right_rotation(temp_node); temp_node->right->height = temp_node->right->left->height + 1; temp_node->height = temp_node->right->height + 1; } else{ left_rotation(temp_node->left); right_rotation(temp_node); temp_height = temp_node->left->left->height; temp_node->left->height = temp_height + 1; temp_node->right->height = temp_height + 1; temp_node->height = temp_height + 2; } } else if (temp_node->left->height - temp_node->right->height == -2){ if (temp_node->right->right->height - temp_node->left->height == 1){ left_rotation(temp_node); temp_node->left->height = temp_node->left->right->height + 1; temp_node->height = temp_node->left->height + 1; } else{ right_rotation(temp_node->right); left_rotation(temp_node); temp_height = temp_node->right->right->height; temp_node->left->height = temp_height + 1; temp_node->right->height = temp_height + 1; temp_node->height = temp_height + 2; } } else{ //if no rotation needed, update height if (temp_node->left->height > temp_node->right->height){ temp_node->height = temp_node->left->height + 1; } else{ temp_node->height = temp_node->right->height + 1; } } if (temp_node->height == old_height){ finished = 1; } } } }
int main(){ int i, tmp; tree_node *txt1, *txt2, *txt3; char *c; printf("starting \n"); txt1 = create_text(); txt2 = create_text(); txt3 = create_text(); append_line(txt1, "line one" ); if( (tmp = length_text(txt1)) != 1) { printf("Test 1: length should be 1, is %d\n", tmp); exit(-1); } append_line(txt1, "line hundred" ); insert_line(txt1, 2, "line ninetynine" ); insert_line(txt1, 2, "line ninetyeight" ); insert_line(txt1, 2, "line ninetyseven" ); insert_line(txt1, 2, "line ninetysix" ); insert_line(txt1, 2, "line ninetyfive" ); for( i = 2; i <95; i++ ) insert_line(txt1, 2, "some filler line between 1 and 95" ); if( (tmp = length_text(txt1)) != 100) { printf("Test 2: length should be 100, is %d\n", tmp); exit(-1); } printf("found at line 1: %s\n",get_line(txt1, 1)); printf("found at line 2: %s\n",get_line(txt1, 2)); printf("found at line 99: %s\n",get_line(txt1, 99)); printf("found at line 100: %s\n",get_line(txt1,100)); for(i=1; i<=10000; i++) { if( i%2==1 ) append_line(txt2, "A"); else append_line(txt2, "B"); } if( (tmp = length_text(txt2)) != 10000) { printf("Test 3: length should be 10000, is %d\n", tmp); exit(-1); } c = get_line(txt2, 9876 ); if( *c != 'B') { printf("Test 4: line 9876 of txt2 should be B, found %s\n", c); exit(-1); } for( i= 10000; i > 1; i-=2 ) { c = delete_line(txt2, i); if( *c != 'B') { printf("Test 5: line %d of txt2 should be B, found %s\n", i, c); exit(-1); } append_line( txt2, c ); } for( i=1; i<= 5000; i++ ) { c = get_line(txt2, i); if( *c != 'A') { printf("Test 6: line %d of txt2 should be A, found %s\n", i, c); exit(-1); } } for( i=1; i<= 5000; i++ ) delete_line(txt2, 1 ); for( i=1; i<= 5000; i++ ) { c = get_line(txt2, i); if( *c != 'B') { printf("Test 7: line %d of txt2 should be B, found %s\n", i, c); exit(-1); } } set_line(txt1, 100, "the last line"); for( i=99; i>=1; i-- ) delete_line(txt1, i ); printf("found at the last line: %s\n",get_line(txt1, 1)); for(i=0; i<1000000; i++) append_line(txt3, "line" ); if( (tmp = length_text(txt3)) != 1000000) { printf("Test 8: length should be 1000000, is %d\n", tmp); exit(-1); } for(i=0; i<500000; i++) delete_line(txt3, 400000 ); if( (tmp = length_text(txt3)) != 500000) { printf("Test 9: length should be 500000, is %d\n", tmp); exit(-1); } printf("End of tests\n"); return 0; }
STATUS disp_diff(STATUS acmmt,i4 canons) { STATUS ioerr ; STATUS up_canon = FAIL ; char cmmtfile [50] ; char canon_upd = '\0' ; char junk ; char menu_ans ; bool conditional_exp ; /* initialize diff window */ conditional_exp = FALSE; #ifndef NT_GENERIC TEwrite(CL,STlength(CL)); TEflush(); #endif diffW = TDnewwin(MAIN_ROWS,MAIN_COLS,FIRST_MAIN_ROW,FIRST_MAIN_COL); diffstW = TDnewwin(STATUS_ROWS,STATUS_COLS,FIRST_STAT_ROW,FIRST_MAIN_COL); TDrefresh(diffstW); TDrefresh(diffW); screenLine = 0; old_page = 0; bottom_page = 0; myPages = NULL; ioerr = OK; STprintf(cmmtfile,ERx("ct%s.stf"),SEPpidstr); diffPtr = sepDiffer->_fptr; /* ** display diff */ page_down(0); if (updateMode) up_canon = OK; for (;;) { if (updateMode) { if (editCAns == '\0') disp_prompt(DIFF_MENU_M,&menu_ans,DIFF_MENU_AM); else menu_ans = 'e'; } else disp_prompt(DIFF_MENU,&menu_ans,DIFF_MENU_A); switch (menu_ans) { case 'A': case 'a': ioerr = FAIL; break; case 'P': case 'p': page_up(); break; case 'N': case 'n': page_down(0); break; case 'C': case 'c': if (acmmt == FAIL && !updateMode) disp_prompt(ERx("no comments attached to this command"), &junk,NULL); else { edit_file(cmmtfile); TDtouchwin(diffW); TDrefresh(diffW); } break; case 'E': case 'e': if (up_canon == OK) { if (editCAns == '\0') { disp_prompt(UPD_CANON,&canon_upd,UPD_CANON_A); } else { canon_upd = editCAns; menu_ans = 'q'; } if (canon_upd == 'M' || canon_upd == 'A' || canon_upd == 'm' || canon_upd == 'a' ) conditional_exp = ask_for_conditional(diffstW, editCAns); up_canon = FAIL; } break; } if (menu_ans == 'Q' || menu_ans == 'q' || menu_ans == 'A' || menu_ans == 'a' || menu_ans == 'D' || menu_ans == 'd') { disp_prompt(NULLSTR,NULL,NULL); SEPdisconnect = (menu_ans == 'A' || menu_ans == 'a' || menu_ans == 'D' || menu_ans == 'd'); break; } } /* ** update test */ if (updateMode) { LOCATION cmmtloc; short count; /* add comments */ LOfroms(FILENAME & PATH,cmmtfile,&cmmtloc); if (SEP_LOexists(&cmmtloc)) { append_line(OPEN_COMMENT,1); append_file(cmmtfile); append_line(CLOSE_COMMENT,1); LOdelete(&cmmtloc); } /* add canons */ switch (canon_upd) { case 'I': case 'i': append_line(OPEN_CANON,1); append_line(SKIP_SYMBOL,1); append_line(CLOSE_CANON,1); break; case 'M': case 'm': SEPrewind(sepResults, FALSE); if (conditional_exp == TRUE) { append_line(OPEN_CANON,0); append_line(conditional_prompt,1); } else append_line(OPEN_CANON,1); append_sepfile(sepResults); append_line(CLOSE_CANON,1); append_sepfile(sepGCanons); break; case 'O': case 'o': SEPrewind(sepResults, FALSE); append_line(OPEN_CANON,1); append_sepfile(sepResults); append_line(CLOSE_CANON,1); break; case '\0': case 'E': case 'e': append_sepfile(sepGCanons); break; case 'A': case 'a': append_sepfile(sepGCanons); SEPrewind(sepResults, FALSE); if (conditional_exp == TRUE) { append_line(OPEN_CANON,0); append_line(conditional_prompt,1); } else append_line(OPEN_CANON,1); append_sepfile(sepResults); append_line(CLOSE_CANON,1); break; } } MEtfree(SEP_ME_TAG_PAGES); TDdelwin(diffW); TDdelwin(diffstW); return(ioerr); }