static void print_1sdiff_line (char const *const *left, char sep, char const *const *right) { FILE *out = outfile; size_t hw = sdiff_half_width; size_t c2o = sdiff_column2_offset; size_t col = 0; bool put_newline = false; bool color_to_reset = false; if (sep == '<') { set_color_context (DELETE_CONTEXT); color_to_reset = true; } else if (sep == '>') { set_color_context (ADD_CONTEXT); color_to_reset = true; } if (left) { put_newline |= left[1][-1] == '\n'; col = print_half_line (left, 0, hw); } if (sep != ' ') { col = tab_from_to (col, (hw + c2o - 1) / 2) + 1; if (sep == '|' && put_newline != (right[1][-1] == '\n')) sep = put_newline ? '/' : '\\'; putc (sep, out); } if (right) { put_newline |= right[1][-1] == '\n'; if (**right != '\n') { col = tab_from_to (col, c2o); print_half_line (right, col, hw); } } if (put_newline) putc ('\n', out); if (color_to_reset) set_color_context (RESET_CONTEXT); }
void print_context_header (struct file_data inf[], char const *const *names, bool unidiff) { set_color_context (HEADER_CONTEXT); if (unidiff) { print_context_label ("---", &inf[0], names[0], file_label[0]); print_context_label ("+++", &inf[1], names[1], file_label[1]); } else { print_context_label ("***", &inf[0], names[0], file_label[0]); print_context_label ("---", &inf[1], names[1], file_label[1]); } set_color_context (RESET_CONTEXT); }
/*ARGSUSED*/ void unset(Char **v, struct command *c) { int did_roe, did_edit; USE(c); did_roe = adrof(STRrecognize_only_executables) != NULL; did_edit = adrof(STRedit) != NULL; unset1(v, &shvhed); #if defined(FILEC) && defined(TIOCSTI) if (adrof(STRfilec) == 0) filec = 0; #endif /* FILEC && TIOCSTI */ if (adrof(STRhistchars) == 0) { HIST = '!'; HISTSUB = '^'; } if (adrof(STRignoreeof) == 0) numeof = 0; if (adrof(STRpromptchars) == 0) { PRCH = '>'; PRCHROOT = '#'; } if (adrof(STRhistlit) == 0) HistLit = 0; if (adrof(STRloginsh) == 0) loginsh = 0; if (adrof(STRwordchars) == 0) word_chars = STR_WORD_CHARS; if (adrof(STRedit) == 0) editing = 0; if (adrof(STRbackslash_quote) == 0) bslash_quote = 0; if (adrof(STRcompat_expr) == 0) compat_expr = 0; if (adrof(STRsymlinks) == 0) symlinks = 0; if (adrof(STRimplicitcd) == 0) implicit_cd = 0; if (adrof(STRkillring) == 0) SetKillRing(0); if (did_edit && noediting && adrof(STRedit) == 0) noediting = 0; if (did_roe && adrof(STRrecognize_only_executables) == 0) tw_cmd_free(); #ifdef COLOR_LS_F if (adrof(STRcolor) == 0) set_color_context(); #endif /* COLOR_LS_F */ #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE) update_dspmbyte_vars(); #endif #ifdef NLS_CATALOGS nlsclose(); nlsinit(); #endif /* NLS_CATALOGS */ }
static void update_vars(Char *vp) { if (eq(vp, STRpath)) { struct varent *p = adrof(STRpath); if (p == NULL) stderror(ERR_NAME | ERR_UNDVAR); else { exportpath(p->vec); dohash(NULL, NULL); } } else if (eq(vp, STRnoclobber)) { struct varent *p = adrof(STRnoclobber); if (p == NULL) stderror(ERR_NAME | ERR_UNDVAR); else no_clobber = set_noclobber(p->vec); } else if (eq(vp, STRhistchars)) { Char *pn = varval(vp); HIST = *pn++; if (HIST) HISTSUB = *pn; else HISTSUB = HIST; } else if (eq(vp, STRpromptchars)) { Char *pn = varval(vp); PRCH = *pn++; if (PRCH) PRCHROOT = *pn; else PRCHROOT = PRCH; } else if (eq(vp, STRhistlit)) { HistLit = 1; } else if (eq(vp, STRuser)) { tsetenv(STRKUSER, varval(vp)); tsetenv(STRLOGNAME, varval(vp)); } else if (eq(vp, STRgroup)) { tsetenv(STRKGROUP, varval(vp)); } else if (eq(vp, STRwordchars)) { word_chars = varval(vp); } else if (eq(vp, STRloginsh)) { loginsh = 1; } else if (eq(vp, STRanyerror)) { anyerror = 1; } else if (eq(vp, STRsymlinks)) { Char *pn = varval(vp); if (eq(pn, STRignore)) symlinks = SYM_IGNORE; else if (eq(pn, STRexpand)) symlinks = SYM_EXPAND; else if (eq(pn, STRchase)) symlinks = SYM_CHASE; else symlinks = 0; } else if (eq(vp, STRterm)) { Char *cp = varval(vp); tsetenv(STRKTERM, cp); #ifdef DOESNT_WORK_RIGHT cp = getenv("TERMCAP"); if (cp && (*cp != '/')) /* if TERMCAP and not a path */ Unsetenv(STRTERMCAP); #endif /* DOESNT_WORK_RIGHT */ GotTermCaps = 0; if (noediting && Strcmp(cp, STRnetwork) != 0 && Strcmp(cp, STRunknown) != 0 && Strcmp(cp, STRdumb) != 0) { editing = 1; noediting = 0; setNS(STRedit); } ed_Init(); /* reset the editor */ } else if (eq(vp, STRhome)) { Char *cp, *canon; cp = Strsave(varval(vp)); /* get the old value back */ cleanup_push(cp, xfree); /* * convert to cononical pathname (possibly resolving symlinks) */ canon = dcanon(cp, cp); cleanup_ignore(cp); cleanup_until(cp); cleanup_push(canon, xfree); setcopy(vp, canon, VAR_READWRITE); /* have to save the new val */ /* and now mirror home with HOME */ tsetenv(STRKHOME, canon); /* fix directory stack for new tilde home */ dtilde(); cleanup_until(canon); } else if (eq(vp, STRedit)) { editing = 1; noediting = 0; /* PWP: add more stuff in here later */ } else if (eq(vp, STRvimode)) { VImode = 1; update_wordchars(); } else if (eq(vp, STRshlvl)) { tsetenv(STRKSHLVL, varval(vp)); } else if (eq(vp, STRignoreeof)) { Char *cp; numeof = 0; for ((cp = varval(STRignoreeof)); cp && *cp; cp++) { if (!Isdigit(*cp)) { numeof = 0; break; } numeof = numeof * 10 + *cp - '0'; } if (numeof <= 0) numeof = 26; /* Sanity check */ } else if (eq(vp, STRbackslash_quote)) { bslash_quote = 1; } else if (eq(vp, STRcompat_expr)) { compat_expr = 1; } else if (eq(vp, STRdirstack)) { dsetstack(); } else if (eq(vp, STRrecognize_only_executables)) { tw_cmd_free(); } else if (eq(vp, STRkillring)) { SetKillRing((int)getn(varval(vp))); } else if (eq(vp, STRhistory)) { sethistory((int)getn(varval(vp))); } #ifndef HAVENOUTMP else if (eq(vp, STRwatch)) { resetwatch(); } #endif /* HAVENOUTMP */ else if (eq(vp, STRimplicitcd)) { implicit_cd = ((eq(varval(vp), STRverbose)) ? 2 : 1); } else if (eq(vp, STRcdtohome)) { cdtohome = 1; } #ifdef COLOR_LS_F else if (eq(vp, STRcolor)) { set_color_context(); } #endif /* COLOR_LS_F */ #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE) else if(eq(vp, CHECK_MBYTEVAR) || eq(vp, STRnokanji)) { update_dspmbyte_vars(); } #endif #ifdef NLS_CATALOGS else if (eq(vp, STRcatalog)) { nlsclose(); nlsinit(); } #if defined(FILEC) && defined(TIOCSTI) else if (eq(vp, STRfilec)) filec = 1; #endif #endif /* NLS_CATALOGS */ }
static void pr_unidiff_hunk (struct change *hunk) { lin first0, last0, first1, last1; lin i, j, k; struct change *next; char const *function; FILE *out; /* Determine range of line numbers involved in each file. */ if (! analyze_hunk (hunk, &first0, &last0, &first1, &last1)) return; /* Include a context's width before and after. */ i = - files[0].prefix_lines; first0 = MAX (first0 - context, i); first1 = MAX (first1 - context, i); if (last0 < files[0].valid_lines - context) last0 += context; else last0 = files[0].valid_lines - 1; if (last1 < files[1].valid_lines - context) last1 += context; else last1 = files[1].valid_lines - 1; /* If desired, find the preceding function definition line in file 0. */ function = NULL; if (function_regexp.fastmap) function = find_function (files[0].linbuf, first0); begin_output (); out = outfile; set_color_context (LINE_NUMBER_CONTEXT); fputs ("@@ -", out); print_unidiff_number_range (&files[0], first0, last0); fputs (" +", out); print_unidiff_number_range (&files[1], first1, last1); fputs (" @@", out); set_color_context (RESET_CONTEXT); if (function) print_context_function (out, function); putc ('\n', out); next = hunk; i = first0; j = first1; while (i <= last0 || j <= last1) { /* If the line isn't a difference, output the context from file 0. */ if (!next || i < next->line0) { char const *const *line = &files[0].linbuf[i++]; if (! (suppress_blank_empty && **line == '\n')) putc (initial_tab ? '\t' : ' ', out); print_1_line (NULL, line); j++; } else { /* For each difference, first output the deleted part. */ k = next->deleted; if (k) set_color_context (DELETE_CONTEXT); while (k--) { char const * const *line = &files[0].linbuf[i++]; putc ('-', out); if (initial_tab && ! (suppress_blank_empty && **line == '\n')) putc ('\t', out); print_1_line_nl (NULL, line, true); if (!k) set_color_context (RESET_CONTEXT); if (line[1][-1] == '\n') putc ('\n', out); } /* Then output the inserted part. */ k = next->inserted; if (k) set_color_context (ADD_CONTEXT); while (k--) { char const * const *line = &files[1].linbuf[j++]; putc ('+', out); if (initial_tab && ! (suppress_blank_empty && **line == '\n')) putc ('\t', out); print_1_line_nl (NULL, line, true); if (!k) set_color_context (RESET_CONTEXT); if (line[1][-1] == '\n') putc ('\n', out); } /* We're done with this hunk, so on to the next! */ next = next->link; } } }
static void pr_context_hunk (struct change *hunk) { lin first0, last0, first1, last1, i; char const *prefix; char const *function; FILE *out; /* Determine range of line numbers involved in each file. */ enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1); if (! changes) return; /* Include a context's width before and after. */ i = - files[0].prefix_lines; first0 = MAX (first0 - context, i); first1 = MAX (first1 - context, i); if (last0 < files[0].valid_lines - context) last0 += context; else last0 = files[0].valid_lines - 1; if (last1 < files[1].valid_lines - context) last1 += context; else last1 = files[1].valid_lines - 1; /* If desired, find the preceding function definition line in file 0. */ function = NULL; if (function_regexp.fastmap) function = find_function (files[0].linbuf, first0); begin_output (); out = outfile; fputs ("***************", out); if (function) print_context_function (out, function); putc ('\n', out); set_color_context (LINE_NUMBER_CONTEXT); fputs ("*** ", out); print_context_number_range (&files[0], first0, last0); fputs (" ****", out); set_color_context (RESET_CONTEXT); putc ('\n', out); if (changes & OLD) { struct change *next = hunk; if (first0 <= last0) set_color_context (DELETE_CONTEXT); for (i = first0; i <= last0; i++) { /* Skip past changes that apply (in file 0) only to lines before line I. */ while (next && next->line0 + next->deleted <= i) next = next->link; /* Compute the marking for line I. */ prefix = " "; if (next && next->line0 <= i) { /* The change NEXT covers this line. If lines were inserted here in file 1, this is "changed". Otherwise it is "deleted". */ prefix = (next->inserted > 0 ? "!" : "-"); } print_1_line_nl (prefix, &files[0].linbuf[i], true); if (i == last0) set_color_context (RESET_CONTEXT); if (files[0].linbuf[i + 1][-1] == '\n') putc ('\n', out); } } set_color_context (LINE_NUMBER_CONTEXT); fputs ("--- ", out); print_context_number_range (&files[1], first1, last1); fputs (" ----", out); set_color_context (RESET_CONTEXT); putc ('\n', out); if (changes & NEW) { struct change *next = hunk; if (first1 <= last1) set_color_context (ADD_CONTEXT); for (i = first1; i <= last1; i++) { /* Skip past changes that apply (in file 1) only to lines before line I. */ while (next && next->line1 + next->inserted <= i) next = next->link; /* Compute the marking for line I. */ prefix = " "; if (next && next->line1 <= i) { /* The change NEXT covers this line. If lines were deleted here in file 0, this is "changed". Otherwise it is "inserted". */ prefix = (next->deleted > 0 ? "!" : "+"); } print_1_line_nl (prefix, &files[1].linbuf[i], true); if (i == last1) set_color_context (RESET_CONTEXT); if (files[1].linbuf[i + 1][-1] == '\n') putc ('\n', out); } } }