diff --git a/stamp-vti b/stamp-vti index c5a45c5..2296c11 100644 --- a/stamp-vti +++ b/stamp-vti @@ -1 +1 @@ -Sun Nov 6 03:05:33 EST 1994 +Sun Jan 6 10:55:48 EST 2008 diff --git a/version.texi b/version.texi index 0a5175d..56e527f 100644 --- a/version.texi +++ b/version.texi @@ -1,3 +1,3 @@ @set EDITION 0.5 address@hidden UPDATED November 1994 address@hidden UPDATED January 2008 @set VERSION 0.5 diff --git a/wdiff.c b/wdiff.c index b3a85e0..20df9ed 100644 --- a/wdiff.c +++ b/wdiff.c @@ -116,6 +116,7 @@ struct option const longopts[] = {"no-common" , 0, NULL, '3'}, {"auto-pager" , 0, NULL, 'a'}, {"help" , 0, NULL, 'h'}, + {"html" , 0, NULL, 'H'}, {"ignore-case" , 0, NULL, 'i'}, {"less-mode" , 0, NULL, 'l'}, {"avoid-wraps" , 0, NULL, 'n'}, @@ -143,6 +144,11 @@ int no_wrapping; /* end/restart strings at end of lines */ int autopager; /* if calling the pager automatically */ int overstrike; /* if using printer overstrikes */ int overstrike_for_less; /* if output aimed to the "less" program */ +int html; /* if outputting in html format */ +const char *user_header; /* user specified string for start of output */ +const char *user_footer; /* user specified string for end of output */ +const char *user_newline; /* user specified string for newline */ +const char *user_separator; /* user specified string for separator line */ const char *user_delete_start; /* user specified string for start of delete */ const char *user_delete_end; /* user specified string for end of delete */ const char *user_insert_start; /* user specified string for start of insert */ @@ -280,6 +286,26 @@ initialize_strings (void) if (!term_insert_end && !user_insert_end) user_insert_end = "+}"; } + + if (html) + { + user_header = "\n\n" + "Document Differences\n" + "\n" + "\n" + "\n"; + user_footer = "\n\n"; + user_newline = "
\n"; + user_separator = "\n\n
\n\n"; + user_delete_start = ""; + user_delete_end = ""; + user_insert_start = ""; + user_insert_end = ""; + } } @@ -438,7 +464,10 @@ copy_whitespace (SIDE *side, FILE *file) switch (copy_mode) { case COPY_NORMAL: - putc (side->character, file); + if (side->character == '\n') + fputs (user_newline, file); + else + putc (side->character, file); break; case COPY_DELETED: @@ -450,7 +479,7 @@ copy_whitespace (SIDE *side, FILE *file) if (term_delete_end) tputs (term_delete_end, 0, putc_for_tputs); #endif - putc ('\n', output_file); + fputs (user_newline, output_file); #if HAVE_TPUTS if (term_delete_start) tputs (term_delete_start, 0, putc_for_tputs); @@ -477,7 +506,7 @@ copy_whitespace (SIDE *side, FILE *file) if (term_insert_end) tputs (term_insert_end, 0, putc_for_tputs); #endif - putc ('\n', output_file); + fputs (user_newline, output_file); #if HAVE_TPUTS if (term_insert_start) tputs (term_insert_start, 0, putc_for_tputs); @@ -543,6 +572,19 @@ copy_word (SIDE *side, FILE *file) putc (side->character, output_file); break; } + else if (html) + { + if (side->character == '<') + fputs ("<", file); + else if (side->character == '>') + fputs (">", file); + else if (side->character == '&') + fputs ("&", file); + else if (side->character == '"') + fputs (""", file); + else + putc (side->character, file); + } else putc (side->character, file); @@ -735,6 +777,9 @@ reformat_diff_output (void) int resync_left; /* word position for left resynchronisation */ int resync_right; /* word position for rigth resynchronisation */ + if (user_header) + fputs (user_header, output_file); + /* Rewind input files. */ rewind (left_side->file); @@ -824,10 +869,10 @@ reformat_diff_output (void) if (inhibit_left && inhibit_right) { if (!inhibit_common) - fprintf (output_file, "\n%s\n", SEPARATOR_LINE); + fprintf (output_file, user_separator); } else if (inhibit_common) - fprintf (output_file, "\n%s\n", SEPARATOR_LINE); + fprintf (output_file, user_separator); /* Show any deleted code. */ @@ -866,7 +911,7 @@ reformat_diff_output (void) if (inhibit_common) { if (!inhibit_left || !inhibit_right) - fprintf (output_file, "\n%s\n", SEPARATOR_LINE); + fprintf (output_file, user_separator); } else if (!inhibit_left && inhibit_right) { @@ -883,6 +928,9 @@ reformat_diff_output (void) fclose (left_side->file); fclose (right_side->file); + + if (user_footer) + fputs (user_footer, output_file); } @@ -1128,6 +1176,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\ -3, --no-common inhibit output of common words\n\ -a, --auto-pager automatically calls a pager\n\ -h, --help print this help\n\ + -H, --html format the output as a web page\n\ -i, --ignore-case fold character case while comparing\n\ -l, --less-mode variation of printer mode for \"less\"\n\ -n, --avoid-wraps do not extend fields through newlines\n\ @@ -1165,6 +1214,11 @@ main (int argc, char *const argv[]) autopager = 0; overstrike = 0; overstrike_for_less = 0; + html = 0; + user_header = NULL; + user_footer = NULL; + user_newline = "\n"; + user_separator = SEPARATOR_LINE; user_delete_start = NULL; user_delete_end = NULL; user_insert_start = NULL; @@ -1216,6 +1270,10 @@ main (int argc, char *const argv[]) case 'h': usage (0); + case 'H': + html = 1; + break; + case 'i': ignore_case = 1; break; @@ -1271,6 +1329,13 @@ main (int argc, char *const argv[]) if (optind + 2 != argc) usage (EXIT_OTHER_REASON); + if (html) + { + no_wrapping = 1; + overstrike = 0; + find_termcap = 0; + } + /* If find_termcap still undecided, consider it unset. However, set if autopager is set while stdout is directed to a terminal, but this decision will be reversed later if the pager happens to be "less". */