void text_layout::layout() { unsigned num_lines = itemizer_.num_lines(); for (unsigned i = 0; i < num_lines; ++i) { std::pair<unsigned, unsigned> line_limits = itemizer_.line(i); text_line line(line_limits.first, line_limits.second); //Break line if neccessary if (wrap_char_ != ' ') { break_line(line, wrap_char_, wrap_width_ * scale_factor_, text_ratio_, wrap_before_, repeat_wrap_char_); } else { break_line(line, wrap_width_ * scale_factor_, text_ratio_, wrap_before_); } } init_auto_alignment(); // Find text origin. displacement_ = scale_factor_ * displacement_ + alignment_offset(); if (rotate_displacement_) displacement_ = displacement_.rotate(!orientation_); // Find layout bounds, expanded for rotation rotated_box2d(bounds_, orientation_, displacement_, width_, height_); }
static char read_tag(FILE *txt) { char c,var[256],set[256]; int i; i = fscanf(txt,"%[^> ] %c",var,&c); while(c<33 && i != EOF) c = i = fgetc(txt); if (c !='>') ungetc(c,txt); _strupr(var); if (!strcmp(var,PARAGRAPH)) { break_line(); break_line(); return 1; } if (!strcmp(var,BREAKLINE)) { break_line(); return 1; } if (!strcmp(var,IMAGE)) { char pic_name[50] =" "; char alig = 0; int line = 0,lsize = 0; while (c !='>') { c = read_set(txt,var,set); if (!strcmp(var,SRC)) strncpy(pic_name,set,49); else if (!strcmp(var,ALIGN)) { if (!strcmp(set,ALEFT)) alig = 1; else if (!strcmp(set,ARIGHT)) alig = 2; else if (!strcmp(set,ACENTER)) alig = 0; } else if (!strcmp(var,PIC_LINE)) sscanf(set,"%d",&line); else if (!strcmp(var,PIC_LSIZ)) sscanf(set,"%d",&lsize); } if (pic_name[0]!= 0) insert_picture(pic_name,alig,line,lsize); return 0; } if (!strcmp(var,CENTER1)) center++; else if (!strcmp(var,CENTER2)) { if (center>0) center--; } else if (!strcmp(var,DISTEND1)) distend++; else if (!strcmp(var,DISTEND2)) { if (distend>0) distend--; } return 0; }
/* Calculate the displayable length of the help-text line starting at ptr. */ size_t help_line_len(const char *ptr) { size_t wrapping_point = (COLS > 24) ? COLS - 1 : 24; /* The target width for wrapping long lines. */ ssize_t wrap_location; /* Actual position where the line can be wrapped. */ size_t length = 0; /* Full length of the line, until the first newline. */ /* Avoid overwide paragraphs in the introductory text. */ if (ptr < end_of_intro && COLS > 74) wrapping_point = 74; wrap_location = break_line(ptr, wrapping_point, TRUE); /* Get the length of the entire line up to a null or a newline. */ while (*(ptr + length) != '\0' && *(ptr + length) != '\n') length = move_mbright(ptr, length); /* If the entire line will just fit the screen, don't wrap it. */ if (strnlenpt(ptr, length) <= wrapping_point + 1) return length; else if (wrap_location > 0) return wrap_location; else return 0; }
/****************************************************************************** * * * * ******************************************************************************/ int load_csv_line(int csv) { char **b = NULL; int count, i, ret = TRUE; double num; int jul, secs; if ( csv < 0 || csv > _n_inf ) { fprintf(stderr, "Request for invalid csv file number\n"); exit(1); } b = break_line(read_line(csv_if[csv].f), &count); if ( b == NULL || count != csv_if[csv].n_cols ) ret = FALSE; else { if (csv_if[csv].tf != NULL) read_time_formatted(b[0], csv_if[csv].tf, &jul, &secs); else read_time_string(b[0], &jul, &secs); num = secs; num /= 86400.0; num += jul; csv_if[csv].curLine[0] = num; free(b[0]); for (i = 1; i < count; i++) { sscanf(b[i], "%lf", &csv_if[csv].curLine[i]); free(b[i]); } } if ( b != NULL ) free(b); return ret; }
/****************************************************************************** * * * * ******************************************************************************/ int open_csv_input(const char *fname, const char *timefmt) { FILE *f = NULL; int cols; if ( _n_inf >= MAX_IN_FILES ) { fprintf(stderr, "Too many csv_files open\n"); return -1; } if ( (f = fopen(fname, "r")) == NULL ) { fprintf(stderr, "Cannot find file \"%s\"\n", fname); return -1; } csv_if[_n_inf].f = f; csv_if[_n_inf].header = break_line( read_line(f), &cols ); csv_if[_n_inf].n_cols = cols; csv_if[_n_inf].curLine = malloc(sizeof(AED_REAL)*cols); if (timefmt != NULL) csv_if[_n_inf].tf = decode_time_format(timefmt); else csv_if[_n_inf].tf = NULL; load_csv_line(_n_inf); return _n_inf++; }
static int parse(struct options *opts, FILE *fp) { char *p, arg[MAX_LEN]; int line = 0, ret = 0, err = 0; memset(arg, 0, MAX_LEN); while (!feof(fp) && (ret = fscanf(fp, "\n%256[^\n]\n", arg)) != 0 && ret < MAX_LEN) { line++; if (is_comment(arg)) continue; p = strstr(arg, "="); if (p == NULL) break_line(ERR_SYNTAX, line); *p = '\0'; p++; p = trim(p); if (*p == 0) break_line(ERR_SYNTAX, line); err = try_set_value(p, trim(arg), opts); if (err > 0) break_line(err, line); } if (ret > MAX_LEN) { jlog(L_NOTICE, "option]> the line %i is longer than %i :: %s:%i", line, MAX_LEN, __FILE__, __LINE__); return ERR_ERRNO; } if (ret == EOF) { jlog(L_NOTICE, "option]> unexpected error %s :: %s:%i", strerror(errno), __FILE__, __LINE__); return ERR_ERRNO; } return 0; }
static int parse(struct options *opts, FILE *fp) { journal_strace("parse"); char *p, arg[MAX_LEN]; int line = 0, ret = 0, err = 0; memset(arg, 0, MAX_LEN); /* XXX What if a line is longer than 256 ? */ while (!feof(fp) && (ret = fscanf(fp, "\n%255[^\n]\n", arg)) != 0) { line++; if (is_comment(arg)) continue; p = strstr(arg, "="); if (p == NULL) break_line(ERR_SYNTAX, line); *p = '\0'; p++; p = trim(p); if (*p == 0) break_line(ERR_SYNTAX, line); err = try_set_value(p, trim(arg), opts); if (err > 0) break_line(err, line); } if (ret == 0) /* fscanf() failed */ return ERR_ERRNO; return 0; }
void main(int argc) { char input = 0; read(); while (1) { input = read_key(); /* blocking */ if (insert_mode == 1) { switch (input) { case '\n': insert_character(input); break_line(); break; case 0x7f: if (current_column > 0) { int current_char = 0; current_column -= 1; current_char = buffer[C(current_line, current_column)]; if (current_column >= 0 && current_char != EOF && current_char != EOL) { move_memory(buffer + C(current_line, current_column), -1, COLS - current_column - 1); buffer[C(current_line, COLS-1)] = 0; } } break; case 27: // esc insert_mode = 0; // set_string(notifications, "COMMAND"); break; default: if (input != 0) { insert_character(input); } break; } } else { if (interpret_command(input) == 1) { return 0; } } // update_notification_line(); send_display(buffer); /* give pointer to assembly function */ display(C(current_line, current_column), '_'); } }
void text_layout::layout() { unsigned num_lines = itemizer_.num_lines(); for (unsigned i = 0; i < num_lines; ++i) { // Break line if neccessary if (wrap_char_ != ' ') { break_line(itemizer_.line(i)); } else { break_line_icu(itemizer_.line(i)); } } init_auto_alignment(); // Find text origin. displacement_ = scale_factor_ * displacement_ + alignment_offset(); if (rotate_displacement_) displacement_ = displacement_.rotate(!orientation_); // Find layout bounds, expanded for rotation rotated_box2d(bounds_, orientation_, displacement_, width_, height_); }
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); }
Config * read_config (Config * conf) { char line[1024], fname[256], *p; char keyword[256], param[256], value[256]; struct stat sb; FILE *cfg; /* * make sure this is all null before we go open some unknown file */ memset (fname, 0, sizeof (fname)); memset (colors, 0, sizeof (colors)); set_window_defaults (); set_color_defaults (); if ((p = getenv ("MJSRC"))) strncpy (fname, p, sizeof (fname) - 1); else snprintf (fname, sizeof (fname) - 1, "%s/.mjsrc", getenv ("HOME")); memset (&sb, 0, sizeof (sb)); /* * dont follow symlinks */ if (((lstat (fname, &sb)) != 0) || S_ISLNK (sb.st_mode)) return conf; if ((cfg = fopen (fname, "r")) == NULL) return conf; while (fgets (line, sizeof (line), cfg)) { if (*line == COMMENT || *line == '\n') continue; memset (keyword, 0, sizeof (keyword)); memset (param, 0, sizeof (param)); memset (value, 0, sizeof (value)); if (break_line (line, keyword, param, value) < 3) continue; if (!strcasecmp (keyword, "set")) set_option (conf, param, value); else if (!strcasecmp (keyword, "color")) set_color (param, value); else if (!strcasecmp (keyword, "info")) set_window (info, param, value); else if (!strcasecmp (keyword, "files")) set_window (files, param, value); else if (!strcasecmp (keyword, "play")) set_window (play, param, value); else if (!strcasecmp (keyword, "menubar")) set_window (menubar, param, value); else if (!strcasecmp (keyword, "playback")) set_window (playback, param, value); } //defaults : if (conf->output[1]=='\0') strcpy(conf->output,"/dev/dsp\0"); if (conf->mpgpath[1]=='\0') strcpy(conf->mpgpath,"mpg123\0"); if (conf->mp3path[1]=='\0') strcpy(conf->mp3path,"/\0"); fclose (cfg); return conf; }