| gnu\wdiff-0.5\wdiff.c | | new\wdiff\wdiff.c | |
| | | | |
| | skipping to change at line 6 | | skipping to change at line 6 | |
| 6 | it under the terms of the GNU General Public License as published by | | it under the terms of the GNU General Public License as published by | 6 |
| 7 | the Free Software Foundation; either version 2, or (at your option) | | the Free Software Foundation; either version 2, or (at your option) | 7 |
| 8 | any later version. | | any later version. | 8 |
| 9 | | | | 9 |
| 10 | This program is distributed in the hope that it will be useful, | | This program is distributed in the hope that it will be useful, | 10 |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 |
| 13 | GNU General Public License for more details. | | GNU General Public License for more details. | 13 |
| 14 | | | | 14 |
| 15 | You should have received a copy of the GNU General Public License | | You should have received a copy of the GNU General Public License | 15 |
| 16 | along with this program; if not, write to the Free Software | | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 |
| 17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | | */ | 17 |
| | | | // Modifed for Windows by David Ireland <www.di-mgt.com.au/contact/> | 18 |
| 18 | | | | 19 |
| 19 | #if HAVE_CONFIG_H | | //#if HAVE_CONFIG_H | 20 |
| 20 | # include <config.h> | | # include "config.h" | 21 |
| 21 | #endif | | //#endif | 22 |
| 22 | | | | 23 |
| 23 | /* Exit codes values. */ | | /* Exit codes values. */ | 24 |
| 24 | #define EXIT_NO_DIFFERENCES 0 /* no differences found */ | | #define EXIT_NO_DIFFERENCES 0 /* no differences found */ | 25 |
| 25 | #define EXIT_ANY_DIFFERENCE 1 /* some differences found */ | | #define EXIT_ANY_DIFFERENCE 1 /* some differences found */ | 26 |
| 26 | #define EXIT_OTHER_REASON 2 /* any other reason for exit */ | | #define EXIT_OTHER_REASON 2 /* any other reason for exit */ | 27 |
| 27 | | | | 28 |
| 28 | /* It is mandatory that some `diff' program is selected for use. The | | /* It is mandatory that some `diff' program is selected for use. The | 29 |
| 29 | following definition may also include the complete path. */ | | following definition may also include the complete path. */ | 30 |
| 30 | #ifndef DIFF_PROGRAM | | #ifndef DIFF_PROGRAM | 31 |
| 31 | # define DIFF_PROGRAM "diff" | | # define DIFF_PROGRAM "diff" | 32 |
| 32 | #endif | | #endif | 33 |
| 33 | | | | 34 |
| | | | // Edited by David Ireland [DAI] <www.di-mgt.com.au/contact/> | 35 |
| | | | // for compiling on Windows using MSVC 12.0 and MinGW | 36 |
| | | | // (Our deletions and comments marked with "//") | 37 |
| | | | #define PRODUCT "GNU wdiff (for Windows)" | 38 |
| | | | #define VERSION "0.5.1W" | 39 |
| | | | // Fixes old insecure tmpnam() to use a more secure implementation | 40 |
| | | | #include "tmpfileplus.h" | 41 |
| | | | // Added error.h not in the original | 42 |
| | | | #include "error.h" | 43 |
| | | | // Windows-specific | 44 |
| | | | #include <io.h> | 45 |
| | | | // If _STDC_ is set (which it is not) then these _xxx forms become compulsory in MSVC. | 46 |
| | | | // (keep this just in case) | 47 |
| | | | //#define isatty _isatty | 48 |
| | | | //#define unlink _unlink | 49 |
| | | | //#define fileno _fileno | 50 |
| | | | //#define S_IFMT _S_IFMT | 51 |
| | | | //#define S_IFDIR _S_IFDIR | 52 |
| | | | ¶ | 53 |
| | | | // readpipe() and writepipe() now in `pipe1.c` | 54 |
| | | | FILE *readpipe (const char *, ...); | 55 |
| | | | FILE *writepipe (const char *, ...); | 56 |
| | | | ¶ | 57 |
| | | | // -----END [DAI] ADDITIONS---- | 58 |
| | | | ¶ | 59 |
| | | | ¶ | 60 |
| 34 | /* One may also, optionnaly, define a default PAGER_PROGRAM. This might | | /* One may also, optionnaly, define a default PAGER_PROGRAM. This might | 61 |
| 35 | be done from the Makefile. If PAGER_PROGRAM is undefined and the | | be done from the Makefile. If PAGER_PROGRAM is undefined and the | 62 |
| 36 | PAGER environment variable is not set, none will be used. */ | | PAGER environment variable is not set, none will be used. */ | 63 |
| 37 | | | | 64 |
| 38 | /* Define the separator lines when output is inhibited. */ | | /* Define the separator lines when output is inhibited. */ | 65 |
| 39 | #define SEPARATOR_LINE \ | | #define SEPARATOR_LINE \ | 66 |
| 40 | "======================================================================" | | "======================================================================" | 67 |
| 41 | | | | 68 |
| 42 | /* Library declarations. */ | | /* Library declarations. */ | 69 |
| 43 | | | | 70 |
| | | | |
| | skipping to change at line 52 | | skipping to change at line 79 | |
| 52 | # include <string.h> | | # include <string.h> | 79 |
| 53 | #else | | #else | 80 |
| 54 | # if HAVE_STRING_H | | # if HAVE_STRING_H | 81 |
| 55 | # include <string.h> | | # include <string.h> | 82 |
| 56 | # else | | # else | 83 |
| 57 | # include <strings.h> | | # include <strings.h> | 84 |
| 58 | # define strrchr rindex | | # define strrchr rindex | 85 |
| 59 | # endif | | # endif | 86 |
| 60 | #endif | | #endif | 87 |
| 61 | | | | 88 |
| 62 | char *strstr (); | | //char *strstr (); | 89 |
| 63 | | | | 90 |
| 64 | #if HAVE_TPUTS | | #if HAVE_TPUTS | 91 |
| 65 | # if HAVE_TERMCAP_H | | # if HAVE_TERMCAP_H | 92 |
| 66 | # include <termcap.h> | | # include <termcap.h> | 93 |
| 67 | # else | | # else | 94 |
| 68 | const char *tgetstr (); | | const char *tgetstr (); | 95 |
| 69 | # endif | | # endif | 96 |
| 70 | #endif | | #endif | 97 |
| 71 | | | | 98 |
| 72 | #include <sys/types.h> | | #include <sys/types.h> | 99 |
| | | | |
| | skipping to change at line 88 | | skipping to change at line 115 | |
| 88 | #endif | | #endif | 115 |
| 89 | | | | 116 |
| 90 | #include "getopt.h" | | #include "getopt.h" | 117 |
| 91 | | | | 118 |
| 92 | #ifdef PROTOTYPES | | #ifdef PROTOTYPES | 119 |
| 93 | # define _(Args) Args | | # define _(Args) Args | 120 |
| 94 | #else | | #else | 121 |
| 95 | # define _(Args) () | | # define _(Args) () | 122 |
| 96 | #endif | | #endif | 123 |
| 97 | | | | 124 |
| 98 | char *getenv (); | | //char *getenv (); | 125 |
| 99 | FILE *readpipe _((const char *, ...)); | | //FILE *readpipe _((const char *, ...)); | 126 |
| 100 | FILE *writepipe _((const char *, ...)); | | //FILE *writepipe _((const char *, ...)); | 127 |
| 101 | char *tmpnam (); | | //char *tmpnam (); | 128 |
| 102 | void error (); | | //void error (); | 129 |
| 103 | | | | 130 |
| 104 | /* Declarations. */ | | /* Declarations. */ | 131 |
| 105 | | | | 132 |
| 106 | /* Option variables. */ | | /* Option variables. */ | 133 |
| 107 | | | | 134 |
| 108 | struct option const longopts[] = | | struct option const longopts[] = | 135 |
| 109 | { | | { | 136 |
| 110 | {"copyright" , 0, NULL, 'C'}, | | {"copyright" , 0, NULL, 'C'}, | 137 |
| 111 | {"version" , 0, NULL, 'V'}, | | {"version" , 0, NULL, 'v'}, | 138 |
| 112 | {"no-deleted" , 0, NULL, '1'}, | | {"no-deleted" , 0, NULL, '1'}, | 139 |
| 113 | {"no-inserted" , 0, NULL, '2'}, | | {"no-inserted" , 0, NULL, '2'}, | 140 |
| 114 | {"no-common" , 0, NULL, '3'}, | | {"no-common" , 0, NULL, '3'}, | 141 |
| 115 | {"help" , 0, NULL, 'h'}, | | {"help" , 0, NULL, 'h'}, | 142 |
| 116 | {"ignore-case" , 0, NULL, 'i'}, | | {"ignore-case" , 0, NULL, 'i'}, | 143 |
| 117 | {"printer" , 0, NULL, 'p'}, | | {"printer" , 0, NULL, 'p'}, | 144 |
| 118 | {"statistics" , 0, NULL, 's'}, | | {"statistics" , 0, NULL, 's'}, | 145 |
| 119 | {"terminal" , 0, NULL, 't'}, | | {"terminal" , 0, NULL, 't'}, | 146 |
| 120 | {"start-delete", 1, NULL, 'w'}, | | {"start-delete", 1, NULL, 'w'}, | 147 |
| 121 | {"end-delete" , 1, NULL, 'x'}, | | {"end-delete" , 1, NULL, 'x'}, | 148 |
| 122 | {"start-insert", 1, NULL, 'y'}, | | {"start-insert", 1, NULL, 'y'}, | 149 |
| 123 | {"end-insert" , 1, NULL, 'z'}, | | {"end-insert" , 1, NULL, 'z'}, | 150 |
| 124 | {NULL , 0, NULL, 0} | | {NULL , 0, NULL, 0} | 151 |
| 125 | }; | | }; | 152 |
| 126 | | | | 153 |
| 127 | static char const copyright[] = | | static char const copyright[] = | 154 |
| 128 | "Copyright (C) 1992 Free Software Foundation, Inc."; | | "Copyright (C) 1992 Free Software Foundation, Inc."; | 155 |
| | | | static char const nowarranty[] = | 156 |
| | | | "This is free software; see the source for copying conditions. There is NO\n" | 157 |
| | | | "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."; | 158 |
| | | | static char const author[] = | 159 |
| | | | "Written by Franc,ois Pinard <pinard@iro.umontreal.ca>.\n" | 160 |
| | | | "Modifed for Windows by David Ireland <www.di-mgt.com.au/contact/>."; | 161 |
| 129 | | | | 162 |
| 130 | const char *program_name; /* name of executing program */ | | const char *program_name; /* name of executing program */ | 163 |
| 131 | | | | 164 |
| 132 | int inhibit_left; /* inhibit display of left side words */ | | int inhibit_left; /* inhibit display of left side words */ | 165 |
| 133 | int inhibit_right; /* inhibit display of left side words */ | | int inhibit_right; /* inhibit display of left side words */ | 166 |
| 134 | int inhibit_common; /* inhibit display of common words */ | | int inhibit_common; /* inhibit display of common words */ | 167 |
| 135 | int ignore_case; /* ignore case in comparisons */ | | int ignore_case; /* ignore case in comparisons */ | 168 |
| 136 | int show_statistics; /* if printing summary statistics */ | | int show_statistics; /* if printing summary statistics */ | 169 |
| 137 | int no_wrapping; /* end/restart strings at end of lines */ | | int no_wrapping; /* end/restart strings at end of lines */ | 170 |
| 138 | int autopager; /* if calling the pager automatically */ | | int autopager; /* if calling the pager automatically */ | 171 |
| | | | |
| | skipping to change at line 155 | | skipping to change at line 188 | |
| 155 | { | | { | 188 |
| 156 | COPY_NORMAL, /* copy text unemphasized */ | | COPY_NORMAL, /* copy text unemphasized */ | 189 |
| 157 | COPY_DELETED, /* copy text underlined */ | | COPY_DELETED, /* copy text underlined */ | 190 |
| 158 | COPY_INSERTED /* copy text bolded */ | | COPY_INSERTED /* copy text bolded */ | 191 |
| 159 | } | | } | 192 |
| 160 | copy_mode; | | copy_mode; | 193 |
| 161 | | | | 194 |
| 162 | jmp_buf signal_label; /* where to jump when signal received */ | | jmp_buf signal_label; /* where to jump when signal received */ | 195 |
| 163 | int interrupted; /* set when some signal has been received */ | | int interrupted; /* set when some signal has been received */ | 196 |
| 164 | | | | 197 |
| 165 | /* Guarantee some value for L_tmpnam. */ | | // /* Guarantee some value for L_tmpnam. */ | 198 |
| 166 | #ifndef L_tmpnam | | // NOT USED: use ANSI standard FILENAME_MAX below | 199 |
| 167 | # include "pathmax.h" | | //#ifndef L_tmpnam | 200 |
| 168 | # define L_tmpnam PATH_MAX | | //# include "pathmax.h" | 201 |
| 169 | #endif | | //# define L_tmpnam PATH_MAX | 202 |
| | | | //#endif | 203 |
| 170 | | | | 204 |
| 171 | typedef struct side SIDE; /* all variables for one side */ | | typedef struct side SIDE; /* all variables for one side */ | 205 |
| 172 | struct side | | struct side | 206 |
| 173 | { | | { | 207 |
| 174 | const char *filename; /* original input file name */ | | const char *filename; /* original input file name */ | 208 |
| 175 | FILE *file; /* original input file */ | | FILE *file; /* original input file */ | 209 |
| 176 | int position; /* number of words read so far */ | | int position; /* number of words read so far */ | 210 |
| 177 | int character; /* one character look ahead */ | | int character; /* one character look ahead */ | 211 |
| 178 | char temp_name[L_tmpnam]; /* temporary file name */ | | //char temp_name[L_tmpnam]; /* temporary file name */ | 212 |
| | | | char temp_name[FILENAME_MAX]; /* temporary file name */ | 213 |
| 179 | FILE *temp_file; /* temporary file */ | | FILE *temp_file; /* temporary file */ | 214 |
| 180 | }; | | }; | 215 |
| 181 | SIDE side_array[2]; /* area for holding side descriptions */ | | SIDE side_array[2]; /* area for holding side descriptions */ | 216 |
| 182 | SIDE *left_side = &side_array[0]; | | SIDE *left_side = &side_array[0]; | 217 |
| 183 | SIDE *right_side = &side_array[1]; | | SIDE *right_side = &side_array[1]; | 218 |
| 184 | | | | 219 |
| 185 | FILE *input_file; /* stream being produced by diff */ | | FILE *input_file; /* stream being produced by diff */ | 220 |
| 186 | int character; /* for reading input_file */ | | int character; /* for reading input_file */ | 221 |
| 187 | char directive; /* diff directive character */ | | char directive; /* diff directive character */ | 222 |
| 188 | int argument[4]; /* four diff directive arguments */ | | int argument[4]; /* four diff directive arguments */ | 223 |
| | | | |
| | skipping to change at line 216 | | skipping to change at line 251 | |
| 216 | `----------------------------*/ | | `----------------------------*/ | 251 |
| 217 | | | | 252 |
| 218 | static void | | static void | 253 |
| 219 | setup_signals (void) | | setup_signals (void) | 254 |
| 220 | { | | { | 255 |
| 221 | interrupted = 0; | | interrupted = 0; | 256 |
| 222 | | | | 257 |
| 223 | /* Intercept willingful requests for stopping. */ | | /* Intercept willingful requests for stopping. */ | 258 |
| 224 | | | | 259 |
| 225 | signal (SIGINT, signal_handler); | | signal (SIGINT, signal_handler); | 260 |
| 226 | signal (SIGPIPE, signal_handler); | | // signal (SIGPIPE, signal_handler); | 261 |
| 227 | signal (SIGTERM, signal_handler); | | signal (SIGTERM, signal_handler); | 262 |
| 228 | } | | } | 263 |
| 229 | | | | 264 |
| 230 | | | | 265 |
| 231 | /* Terminal initialization. */ | | /* Terminal initialization. */ | 266 |
| 232 | | | | 267 |
| 233 | static void | | static void | 268 |
| 234 | initialize_strings (void) | | initialize_strings (void) | 269 |
| 235 | { | | { | 270 |
| 236 | #if HAVE_TPUTS | | #if HAVE_TPUTS | 271 |
| | | | |
| | skipping to change at line 559 | | skipping to change at line 594 | |
| 559 | /* Open files. */ | | /* Open files. */ | 594 |
| 560 | | | | 595 |
| 561 | if (side->filename == NULL) | | if (side->filename == NULL) | 596 |
| 562 | { | | { | 597 |
| 563 | | | | 598 |
| 564 | /* Select a file name, use it for opening a temporary file and | | /* Select a file name, use it for opening a temporary file and | 599 |
| 565 | unlink it right away. Then, copy the whole standard input on | | unlink it right away. Then, copy the whole standard input on | 600 |
| 566 | this temporary local file. Once done, prepare it for reading. | | this temporary local file. Once done, prepare it for reading. | 601 |
| 567 | We do not need the file name itself anymore. */ | | We do not need the file name itself anymore. */ | 602 |
| 568 | | | | 603 |
| 569 | tmpnam (side->temp_name); | | // [DAI] Fix up tmpnam | 604 |
| 570 | side->file = fopen (side->temp_name, "w+"); | | //tmpnam (side->temp_name); | 605 |
| | | | //side->file = fopen (side->temp_name, "w+"); | 606 |
| | | | //if (side->file == NULL) | 607 |
| | | | // error (EXIT_OTHER_REASON, errno, side->temp_name); | 608 |
| | | | //if (unlink (side->temp_name) != 0) | 609 |
| | | | // error (EXIT_OTHER_REASON, errno, side->temp_name); | 610 |
| | | | | 611 |
| | | | // [DAI] Returns fp directly, file auto deleted when closed | 612 |
| | | | side->file = tmpfileplus_f(NULL, "wd1-", side->temp_name, sizeof(side->temp_name), 0); | 613 |
| 571 | if (side->file == NULL) | | if (side->file == NULL) | 614 |
| 572 | error (EXIT_OTHER_REASON, errno, side->temp_name); | | error (EXIT_OTHER_REASON, errno, "Failed to create temp file"); | 615 |
| 573 | if (unlink (side->temp_name) != 0) | | while (side->character = getchar(), side->character != EOF) | 616 |
| 574 | error (EXIT_OTHER_REASON, errno, side->temp_name); | | | |
| 575 | while (side->character = getchar (), side->character != EOF) | | | |
| 576 | putc (side->character, side->file); | | putc (side->character, side->file); | 617 |
| 577 | rewind (side->file); | | rewind (side->file); | 618 |
| 578 | } | | } | 619 |
| 579 | else | | else | 620 |
| 580 | { | | { | 621 |
| 581 | | | | 622 |
| 582 | /* Check and diagnose if the file name is a directory. Or else, | | /* Check and diagnose if the file name is a directory. Or else, | 623 |
| 583 | prepare the file for reading. */ | | prepare the file for reading. */ | 624 |
| 584 | | | | 625 |
| 585 | if (stat (side->filename, &stat_buffer) != 0) | | if (stat (side->filename, &stat_buffer) != 0) | 626 |
| 586 | error (EXIT_OTHER_REASON, errno, side->filename); | | error (EXIT_OTHER_REASON, errno, side->filename); | 627 |
| 587 | if ((stat_buffer.st_mode & S_IFMT) == S_IFDIR) | | if ((stat_buffer.st_mode & S_IFMT) == S_IFDIR) | 628 |
| 588 | error (EXIT_OTHER_REASON, 0, "Directories not supported"); | | error (EXIT_OTHER_REASON, 0, "Directories not supported"); | 629 |
| 589 | side->file = fopen (side->filename, "r"); | | side->file = fopen (side->filename, "r"); | 630 |
| 590 | if (side->file == NULL) | | if (side->file == NULL) | 631 |
| 591 | error (EXIT_OTHER_REASON, errno, side->filename); | | error (EXIT_OTHER_REASON, errno, side->filename); | 632 |
| 592 | } | | } | 633 |
| 593 | side->character = getc (side->file); | | side->character = getc (side->file); | 634 |
| 594 | side->position = 0; | | side->position = 0; | 635 |
| 595 | | | | 636 |
| 596 | tmpnam (side->temp_name); | | //tmpnam (side->temp_name); | 637 |
| 597 | side->temp_file = fopen (side->temp_name, "w"); | | //side->temp_file = fopen (side->temp_name, "w"); | 638 |
| | | | //if (side->temp_file == NULL) | 639 |
| | | | // error (EXIT_OTHER_REASON, errno, side->temp_name); | 640 |
| | | | | 641 |
| | | | // [DAI] We need to keep this temp file for later (when it must have been closed) | 642 |
| | | | side->temp_file = tmpfileplus_f(NULL, "wd2-", side->temp_name, sizeof(side->temp_name), TMPFILE_KEEP); | 643 |
| 598 | if (side->temp_file == NULL) | | if (side->temp_file == NULL) | 644 |
| 599 | error (EXIT_OTHER_REASON, errno, side->temp_name); | | error(EXIT_OTHER_REASON, errno, "Failed to create temp file"); | 645 |
| 600 | | | | 646 |
| 601 | /* Complete splitting input file into words on output. */ | | /* Complete splitting input file into words on output. */ | 647 |
| 602 | | | | 648 |
| 603 | while (side->character != EOF) | | while (side->character != EOF) | 649 |
| 604 | { | | { | 650 |
| 605 | if (interrupted) | | if (interrupted) | 651 |
| 606 | longjmp (signal_label, 1); | | longjmp (signal_label, 1); | 652 |
| 607 | | | | 653 |
| 608 | skip_whitespace (side); | | skip_whitespace (side); | 654 |
| 609 | if (side->character == EOF) | | if (side->character == EOF) | 655 |
| | | | |
| | skipping to change at line 886 | | skipping to change at line 932 | |
| 886 | /*-------------------------. | | /*-------------------------. | 932 |
| 887 | | Lauch the diff program. | | | | Lauch the diff program. | | 933 |
| 888 | `-------------------------*/ | | `-------------------------*/ | 934 |
| 889 | | | | 935 |
| 890 | static void | | static void | 936 |
| 891 | launch_input_program (void) | | launch_input_program (void) | 937 |
| 892 | { | | { | 938 |
| 893 | /* Launch the diff program. */ | | /* Launch the diff program. */ | 939 |
| 894 | | | | 940 |
| 895 | if (ignore_case) | | if (ignore_case) | 941 |
| 896 | input_file = readpipe (DIFF_PROGRAM, "-c", left_side->temp_name, | | // [DAI] Old diff option "-c" replaced by "-i" for case-insensitive | 942 |
| | | | input_file = readpipe (DIFF_PROGRAM, "-i", left_side->temp_name, | 943 |
| 897 | right_side->temp_name, NULL); | | right_side->temp_name, NULL); | 944 |
| 898 | else | | else | 945 |
| 899 | input_file = readpipe (DIFF_PROGRAM, left_side->temp_name, | | input_file = readpipe (DIFF_PROGRAM, left_side->temp_name, | 946 |
| 900 | right_side->temp_name, NULL); | | right_side->temp_name, NULL); | 947 |
| 901 | if (!input_file) | | if (!input_file) | 948 |
| 902 | error (EXIT_OTHER_REASON, errno, DIFF_PROGRAM); | | error (EXIT_OTHER_REASON, errno, DIFF_PROGRAM); | 949 |
| 903 | character = getc (input_file); | | character = getc (input_file); | 950 |
| 904 | } | | } | 951 |
| 905 | | | | 952 |
| 906 | /*----------------------------. | | /*----------------------------. | 953 |
| 907 | | Complete the diff program. | | | | Complete the diff program. | | 954 |
| 908 | `----------------------------*/ | | `----------------------------*/ | 955 |
| 909 | | | | 956 |
| 910 | static void | | static void | 957 |
| 911 | complete_input_program (void) | | complete_input_program (void) | 958 |
| 912 | { | | { | 959 |
| 913 | fclose (input_file); | | // fclose (input_file); | 960 |
| 914 | wait (NULL); | | // wait (NULL); | 961 |
| | | | _pclose(input_file); | 962 |
| 915 | } | | } | 963 |
| 916 | | | | 964 |
| 917 | /*---------------------------------. | | /*---------------------------------. | 965 |
| 918 | | Launch the output pager if any. | | | | Launch the output pager if any. | | 966 |
| 919 | `---------------------------------*/ | | `---------------------------------*/ | 967 |
| 920 | | | | 968 |
| 921 | static void | | static void | 969 |
| 922 | launch_output_program (void) | | launch_output_program (void) | 970 |
| 923 | { | | { | 971 |
| 924 | char *program; /* name of the pager */ | | char *program; /* name of the pager */ | 972 |
| 925 | char *basename; /* basename of the pager */ | | char *basename; /* basename of the pager */ | 973 |
| 926 | | | | 974 |
| 927 | /* Check if a output program should be called, and which one. Avoid | | /* Check if a output program should be called, and which one. Avoid | 975 |
| 928 | all paging if only statistics are needed. */ | | all paging if only statistics are needed. */ | 976 |
| 929 | | | | 977 |
| 930 | if (autopager && isatty (fileno (stdout)) | | if (autopager && isatty (fileno (stdout)) | 978 |
| 931 | && !(inhibit_left && inhibit_right && inhibit_common)) | | && !(inhibit_left && inhibit_right && inhibit_common)) | 979 |
| 932 | { | | { | 980 |
| 933 | program = getenv ("PAGER"); | | program = (char *)getenv ("PAGER"); | 981 |
| 934 | #ifdef PAGER_PROGRAM | | #ifdef PAGER_PROGRAM | 982 |
| 935 | if (program == NULL) | | if (program == NULL) | 983 |
| 936 | program = PAGER_PROGRAM; | | program = PAGER_PROGRAM; | 984 |
| 937 | #endif | | #endif | 985 |
| 938 | } | | } | 986 |
| 939 | else | | else | 987 |
| 940 | program = NULL; | | program = NULL; | 988 |
| 941 | | | | 989 |
| 942 | /* Use stdout as default output. */ | | /* Use stdout as default output. */ | 990 |
| 943 | | | | 991 |
| | | | |
| | skipping to change at line 957 | | skipping to change at line 1005 | |
| 957 | /* If we should use a pager, launch it. */ | | /* If we should use a pager, launch it. */ | 1005 |
| 958 | | | | 1006 |
| 959 | if (program && *program) | | if (program && *program) | 1007 |
| 960 | { | | { | 1008 |
| 961 | output_file = writepipe (program, NULL); | | output_file = writepipe (program, NULL); | 1009 |
| 962 | if (!output_file) | | if (!output_file) | 1010 |
| 963 | error (EXIT_OTHER_REASON, errno, program); | | error (EXIT_OTHER_REASON, errno, program); | 1011 |
| 964 | | | | 1012 |
| 965 | /* If we are paging to less, use printer mode, not display mode. */ | | /* If we are paging to less, use printer mode, not display mode. */ | 1013 |
| 966 | | | | 1014 |
| 967 | if (basename = strrchr ("less", '/'), basename) | | // [DAI] fix error in original (even though it's never called) | 1015 |
| | | | //if (basename = strrchr ("less", '/'), basename) | 1016 |
| | | | if (basename = strrchr(program, '/')) | 1017 |
| 968 | basename++; | | basename++; | 1018 |
| 969 | else | | else | 1019 |
| 970 | basename = program; | | basename = program; | 1020 |
| 971 | | | | 1021 |
| 972 | if (strstr (basename, "less")) | | if (strstr (basename, "less")) | 1022 |
| 973 | { | | { | 1023 |
| 974 | find_termcap = 0; | | find_termcap = 0; | 1024 |
| 975 | overstrike = 1; | | overstrike = 1; | 1025 |
| 976 | overstrike_for_less = 1; | | overstrike_for_less = 1; | 1026 |
| 977 | } | | } | 1027 |
| | | | |
| | skipping to change at line 1005 | | skipping to change at line 1055 | |
| 1005 | default: | | default: | 1055 |
| 1006 | abort (); | | abort (); | 1056 |
| 1007 | } | | } | 1057 |
| 1008 | | | | 1058 |
| 1009 | /* Let the user play at will inside the pager, until s/he exits, before | | /* Let the user play at will inside the pager, until s/he exits, before | 1059 |
| 1010 | proceeding any further. */ | | proceeding any further. */ | 1060 |
| 1011 | | | | 1061 |
| 1012 | if (output_file && output_file != stdout) | | if (output_file && output_file != stdout) | 1062 |
| 1013 | { | | { | 1063 |
| 1014 | fclose (output_file); | | fclose (output_file); | 1064 |
| 1015 | wait (NULL); | | // wait (NULL); | 1065 |
| 1016 | } | | } | 1066 |
| 1017 | | | | 1067 |
| 1018 | /* Ensure the termcap termination string is sent to stdout, never to | | /* Ensure the termcap termination string is sent to stdout, never to | 1068 |
| 1019 | the pager. Moreover, the pager has terminated already. */ | | the pager. Moreover, the pager has terminated already. */ | 1069 |
| 1020 | | | | 1070 |
| 1021 | #if HAVE_TPUTS | | #if HAVE_TPUTS | 1071 |
| 1022 | if (termcap_end_string) | | if (termcap_end_string) | 1072 |
| 1023 | { | | { | 1073 |
| 1024 | output_file = stdout; | | output_file = stdout; | 1074 |
| 1025 | tputs (termcap_end_string, 0, putc_for_tputs); | | tputs (termcap_end_string, 0, putc_for_tputs); | 1075 |
| | | | |
| | skipping to change at line 1070 | | skipping to change at line 1120 | |
| 1070 | | | | 1120 |
| 1071 | /* Main control. */ | | /* Main control. */ | 1121 |
| 1072 | | | | 1122 |
| 1073 | /*-----------------------------------. | | /*-----------------------------------. | 1123 |
| 1074 | | Prints a more detailed Copyright. | | | | Prints a more detailed Copyright. | | 1124 |
| 1075 | `-----------------------------------*/ | | `-----------------------------------*/ | 1125 |
| 1076 | | | | 1126 |
| 1077 | static void | | static void | 1127 |
| 1078 | print_copyright (void) | | print_copyright (void) | 1128 |
| 1079 | { | | { | 1129 |
| 1080 | fprintf (stderr, "\ | | fprintf (stderr, "%s\n%s\n\n%s\n\n", copyright, author, nowarranty); | 1130 |
| 1081 | This program is free software; you can redistribute it and/or modify\n\ | | | |
| 1082 | it under the terms of the GNU General Public License as published by\n\ | | | |
| 1083 | the Free Software Foundation; either version 2, or (at your option)\n\ | | | |
| 1084 | any later version.\n\ | | | |
| 1085 | \n\ | | | |
| 1086 | This program is distributed in the hope that it will be useful,\n\ | | | |
| 1087 | but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ | | | |
| 1088 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ | | | |
| 1089 | GNU General Public License for more details.\n\ | | | |
| 1090 | \n\ | | | |
| 1091 | You should have received a copy of the GNU General Public License\n\ | | | |
| 1092 | along with this program; if not, write to the Free Software\n\ | | | |
| 1093 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\ | | | |
| 1094 | \n"); | | | |
| 1095 | } | | } | 1131 |
| 1096 | | | | 1132 |
| 1097 | /*-----------------------------. | | /*-----------------------------. | 1133 |
| 1098 | | Tell how to use, then exit. | | | | Tell how to use, then exit. | | 1134 |
| 1099 | `-----------------------------*/ | | `-----------------------------*/ | 1135 |
| 1100 | | | | 1136 |
| 1101 | static void | | static void | 1137 |
| 1102 | usage (int status) | | usage (int status) | 1138 |
| 1103 | { | | { | 1139 |
| 1104 | if (status != 0) | | if (status != 0) | 1140 |
| 1105 | fprintf (stderr, "Try `%s --help' for more information.\n", program_name); | | fprintf (stderr, "Try `%s --help' for more information.\n", program_name); | 1141 |
| 1106 | else | | else | 1142 |
| 1107 | { | | { | 1143 |
| 1108 | printf ("\ | | printf ("\ | 1144 |
| 1109 | Usage: %s [OPTION]... FILE1 FILE2\n", program_name); | | Usage: %s [OPTION]... FILE1 FILE2\n", program_name); | 1145 |
| 1110 | printf ("\ | | printf ("\ | 1146 |
| 1111 | Mandatory arguments to long options are mandatory for short options too.\n\ | | Mandatory arguments to long options are mandatory for short options too.\n\ | 1147 |
| 1112 | \n\ | | \n\ | 1148 |
| 1113 | -C, --copyright print Copyright then exit\n\ | | -C, --copyright print Copyright then exit\n\ | 1149 |
| 1114 | -V, --version print program version then exit\n\ | | -v, --version print program version then exit\n\ | 1150 |
| 1115 | -1, --no-deleted inhibit output of deleted words\n\ | | -1, --no-deleted inhibit output of deleted words\n\ | 1151 |
| 1116 | -2, --no-inserted inhibit output of inserted words\n\ | | -2, --no-inserted inhibit output of inserted words\n\ | 1152 |
| 1117 | -3, --no-common inhibit output of common words\n\ | | -3, --no-common inhibit output of common words\n\ | 1153 |
| 1118 | -a, --auto-pager automatically calls a pager\n\ | | -a, --auto-pager automatically calls a pager\n\ | 1154 |
| 1119 | -h, --help print this help\n\ | | -h, --help print this help\n\ | 1155 |
| 1120 | -i, --ignore-case fold character case while comparing\n\ | | -i, --ignore-case fold character case while comparing\n\ | 1156 |
| 1121 | -l, --less-mode variation of printer mode for \"less\"\n\ | | -l, --less-mode variation of printer mode for \"less\"\n\ | 1157 |
| 1122 | -n, --avoid-wraps do not extend fields through newlines\n\ | | -n, --avoid-wraps do not extend fields through newlines\n\ | 1158 |
| 1123 | -p, --printer overstrike as for printers\n\ | | -p, --printer overstrike as for printers\n\ | 1159 |
| 1124 | -s, --statistics say how many words deleted, inserted etc.\n\ | | -s, --statistics say how many words deleted, inserted etc.\n\ | 1160 |
| | | | |
| | skipping to change at line 1166 | | skipping to change at line 1202 | |
| 1166 | term_insert_end = NULL; | | term_insert_end = NULL; | 1202 |
| 1167 | copy_mode = COPY_NORMAL; | | copy_mode = COPY_NORMAL; | 1203 |
| 1168 | | | | 1204 |
| 1169 | count_total_left = 0; | | count_total_left = 0; | 1205 |
| 1170 | count_total_right = 0; | | count_total_right = 0; | 1206 |
| 1171 | count_isolated_left = 0; | | count_isolated_left = 0; | 1207 |
| 1172 | count_isolated_right = 0; | | count_isolated_right = 0; | 1208 |
| 1173 | count_changed_left = 0; | | count_changed_left = 0; | 1209 |
| 1174 | count_changed_right = 0; | | count_changed_right = 0; | 1210 |
| 1175 | | | | 1211 |
| 1176 | while (option_char = getopt_long (argc, argv, "123CVahidlnpstw:x:y:z:", | | while (option_char = getopt_long (argc, argv, "123Cvahidlnpstw:x:y:z:", | 1212 |
| 1177 | longopts, NULL), | | longopts, NULL), | 1213 |
| 1178 | option_char != EOF) | | option_char != EOF) | 1214 |
| 1179 | switch (option_char) | | switch (option_char) | 1215 |
| 1180 | { | | { | 1216 |
| 1181 | case '1': | | case '1': | 1217 |
| 1182 | inhibit_left = 1; | | inhibit_left = 1; | 1218 |
| 1183 | break; | | break; | 1219 |
| 1184 | | | | 1220 |
| 1185 | case '2': | | case '2': | 1221 |
| 1186 | inhibit_right = 1; | | inhibit_right = 1; | 1222 |
| | | | |
| | skipping to change at line 1188 | | skipping to change at line 1224 | |
| 1188 | | | | 1224 |
| 1189 | case '3': | | case '3': | 1225 |
| 1190 | inhibit_common = 1; | | inhibit_common = 1; | 1226 |
| 1191 | break; | | break; | 1227 |
| 1192 | | | | 1228 |
| 1193 | case 'C': | | case 'C': | 1229 |
| 1194 | print_copyright (); | | print_copyright (); | 1230 |
| 1195 | exit (0); | | exit (0); | 1231 |
| 1196 | | | | 1232 |
| 1197 | case 'v': | | case 'v': | 1233 |
| 1198 | printf ("GNU %s %s\n%s\n", PRODUCT, VERSION, copyright); | | printf("%s %s\n", PRODUCT, VERSION); | 1234 |
| 1199 | exit (0); | | exit (0); | 1235 |
| 1200 | | | | 1236 |
| 1201 | case 'a': | | case 'a': | 1237 |
| 1202 | autopager = 1; | | autopager = 1; | 1238 |
| 1203 | break; | | break; | 1239 |
| 1204 | | | | 1240 |
| 1205 | case 'h': | | case 'h': | 1241 |
| 1206 | usage (0); | | usage (0); | 1242 |
| 1207 | | | | 1243 |
| 1208 | case 'i': | | case 'i': | 1244 |
| | | | |
| End of changes. 12 change blocks. |
| 52 lines changed or deleted | | 88 lines changed or added | |
| |