| @@ -1,202 +1,210 @@ | | | @@ -1,202 +1,210 @@ |
1 | $NetBSD: patch-files.c,v 1.1 2023/03/01 23:48:00 vins Exp $ | | 1 | $NetBSD: patch-files.c,v 1.2 2023/03/08 21:46:44 vins Exp $ |
2 | | | 2 | |
3 | Pull patches from Debian. | | 3 | Pull patches from Debian. |
4 | | | 4 | |
5 | --- files.c.orig 1994-05-19 02:01:06.000000000 +0000 | | 5 | --- files.c.orig 1994-05-19 02:01:06.000000000 +0000 |
6 | +++ files.c | | 6 | +++ files.c |
7 | @@ -1,9 +1,10 @@ | | 7 | @@ -1,9 +1,10 @@ |
8 | -#ifndef lint | | 8 | -#ifndef lint |
9 | -static char rcsid[] = "files.c,v 2.0 1994/05/19 02:01:06 dan Exp"; | | 9 | -static char rcsid[] = "files.c,v 2.0 1994/05/19 02:01:06 dan Exp"; |
10 | +#if 0 | | 10 | +#if 0 |
11 | +static char rcsid[] __attribute__((unused)) = "files.c,v 2.0 1994/05/19 02:01:06 dan Exp"; | | 11 | +static char rcsid[] __attribute__((unused)) = "files.c,v 2.0 1994/05/19 02:01:06 dan Exp"; |
12 | #endif | | 12 | #endif |
13 | | | 13 | |
14 | /* | | 14 | /* |
15 | * Copyright (c) 1994 Daniel Williams | | 15 | * Copyright (c) 1994 Daniel Williams |
16 | + * Copyright (c) 2003 Erik de Castro Lopo | | 16 | + * Copyright (c) 2003 Erik de Castro Lopo |
17 | * | | 17 | * |
18 | * The X Consortium, and any party obtaining a copy of these files from | | 18 | * The X Consortium, and any party obtaining a copy of these files from |
19 | * the X Consortium, directly or indirectly, is granted, free of charge, | | 19 | * the X Consortium, directly or indirectly, is granted, free of charge, |
20 | @@ -83,16 +84,18 @@ static void popup_cb (Widget w, XtPointe | | 20 | @@ -36,6 +37,7 @@ static char rcsid[] = "files.c,v 2.0 199 |
| | | 21 | #include <unistd.h> |
| | | 22 | #include <errno.h> |
| | | 23 | #include <sys/stat.h> |
| | | 24 | +#include <sys/types.h> |
| | | 25 | #include <ctype.h> |
| | | 26 | #include <assert.h> |
| | | 27 | |
| | | 28 | @@ -83,16 +85,18 @@ static void popup_cb (Widget w, XtPointe |
21 | */ | | 29 | */ |
22 | static int is_ascii_text (char *filename) | | 30 | static int is_ascii_text (char *filename) |
23 | { | | 31 | { |
24 | - int fd, bytes, i; | | 32 | - int fd, bytes, i; |
25 | + int fd, bytes, i, ch; | | 33 | + int fd, bytes, i, ch; |
26 | char buffer[1024]; | | 34 | char buffer[1024]; |
27 | | | 35 | |
28 | fd = open (filename, O_RDONLY); | | 36 | fd = open (filename, O_RDONLY); |
29 | bytes = read (fd, (void *) buffer, 1024); | | 37 | bytes = read (fd, (void *) buffer, 1024); |
30 | (void) close (fd); | | 38 | (void) close (fd); |
31 | | | 39 | |
32 | - for (i = 0; i < bytes; i++) | | 40 | - for (i = 0; i < bytes; i++) |
33 | - if (!isascii (buffer[i])) | | 41 | - if (!isascii (buffer[i])) |
34 | + for (i = 0; i < bytes; i++) { | | 42 | + for (i = 0; i < bytes; i++) { |
35 | + ch = buffer [i]; | | 43 | + ch = buffer [i]; |
36 | + if (!isallowed(ch)) | | 44 | + if (!isallowed(ch)) |
37 | return (0); | | 45 | return (0); |
38 | + } | | 46 | + } |
39 | return (1); | | 47 | return (1); |
40 | } | | 48 | } |
41 | | | 49 | |
42 | @@ -143,12 +146,13 @@ void werror (Widget parent, char *title, | | 50 | @@ -143,12 +147,13 @@ void werror (Widget parent, char *title, |
43 | XmString xms; | | 51 | XmString xms; |
44 | Arg args[2]; | | 52 | Arg args[2]; |
45 | | | 53 | |
46 | - (void) sprintf (buffer, "%s: %s", msg1, msg2); | | 54 | - (void) sprintf (buffer, "%s: %s", msg1, msg2); |
47 | + (void) snprintf (buffer, sizeof (buffer), "%s: %s", msg1, msg2); | | 55 | + (void) snprintf (buffer, sizeof (buffer), "%s: %s", msg1, msg2); |
48 | xms = XmStringCreateLtoR (buffer, XmSTRING_DEFAULT_CHARSET); | | 56 | xms = XmStringCreateLtoR (buffer, XmSTRING_DEFAULT_CHARSET); |
49 | XtSetArg (args[0], XmNmessageString, xms); | | 57 | XtSetArg (args[0], XmNmessageString, xms); |
50 | XtSetArg (args[1], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); | | 58 | XtSetArg (args[1], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); |
51 | dialog = XmCreateErrorDialog (parent, "werror", args, 2); | | 59 | dialog = XmCreateErrorDialog (parent, "werror", args, 2); |
52 | - XmStringFree (xms); | | 60 | - XmStringFree (xms); |
53 | + if (xms) | | 61 | + if (xms) |
54 | + XmStringFree (xms); | | 62 | + XmStringFree (xms); |
55 | XtVaSetValues (XtParent (dialog), XtNtitle, title, NULL); | | 63 | XtVaSetValues (XtParent (dialog), XtNtitle, title, NULL); |
56 | | | 64 | |
57 | XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_CANCEL_BUTTON)); | | 65 | XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_CANCEL_BUTTON)); |
58 | @@ -174,8 +178,10 @@ void werror_long (Widget parent, char *t | | 66 | @@ -174,8 +179,10 @@ void werror_long (Widget parent, char *t |
59 | xms1 = xms4; | | 67 | xms1 = xms4; |
60 | else { | | 68 | else { |
61 | xms2 = XmStringConcat (xms1, xms4); | | 69 | xms2 = XmStringConcat (xms1, xms4); |
62 | - XmStringFree (xms4); | | 70 | - XmStringFree (xms4); |
63 | - XmStringFree (xms1); | | 71 | - XmStringFree (xms1); |
64 | + if (xms4) | | 72 | + if (xms4) |
65 | + XmStringFree (xms4); | | 73 | + XmStringFree (xms4); |
66 | + if (xms1) | | 74 | + if (xms1) |
67 | + XmStringFree (xms1); | | 75 | + XmStringFree (xms1); |
68 | xms1 = xms2; | | 76 | xms1 = xms2; |
69 | } | | 77 | } |
70 | | | 78 | |
71 | @@ -183,16 +189,19 @@ void werror_long (Widget parent, char *t | | 79 | @@ -183,16 +190,19 @@ void werror_long (Widget parent, char *t |
72 | XmString xms3; | | 80 | XmString xms3; |
73 | | | 81 | |
74 | xms3 = XmStringConcat (xms1, sep); | | 82 | xms3 = XmStringConcat (xms1, sep); |
75 | - XmStringFree (xms1); | | 83 | - XmStringFree (xms1); |
76 | + if (xms1) | | 84 | + if (xms1) |
77 | + XmStringFree (xms1); | | 85 | + XmStringFree (xms1); |
78 | xms1 = xms3; | | 86 | xms1 = xms3; |
79 | } | | 87 | } |
80 | } | | 88 | } |
81 | - XmStringFree (sep); | | 89 | - XmStringFree (sep); |
82 | + if (sep) | | 90 | + if (sep) |
83 | + XmStringFree (sep); | | 91 | + XmStringFree (sep); |
84 | | | 92 | |
85 | XtSetArg (args[0], XmNmessageString, xms1); | | 93 | XtSetArg (args[0], XmNmessageString, xms1); |
86 | XtSetArg (args[1], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); | | 94 | XtSetArg (args[1], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); |
87 | dialog = XmCreateErrorDialog (parent, "werror", args, 2); | | 95 | dialog = XmCreateErrorDialog (parent, "werror", args, 2); |
88 | - XmStringFree (xms1); | | 96 | - XmStringFree (xms1); |
89 | + if (xms1) | | 97 | + if (xms1) |
90 | + XmStringFree (xms1); | | 98 | + XmStringFree (xms1); |
91 | XtVaSetValues (XtParent (dialog), XtNtitle, title, NULL); | | 99 | XtVaSetValues (XtParent (dialog), XtNtitle, title, NULL); |
92 | XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_CANCEL_BUTTON)); | | 100 | XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_CANCEL_BUTTON)); |
93 | XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON)); | | 101 | XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON)); |
94 | @@ -318,7 +327,7 @@ void open_both_files (Widget parent, cha | | 102 | @@ -318,7 +328,7 @@ void open_both_files (Widget parent, cha |
95 | Arg args[2]; | | 103 | Arg args[2]; |
96 | int i; | | 104 | int i; |
97 | char *dir; | | 105 | char *dir; |
98 | - XmString xms; | | 106 | - XmString xms; |
99 | + XmString xms = (XmString)0; | | 107 | + XmString xms = (XmString)0; |
100 | | | 108 | |
101 | shell = XtVaCreatePopupShell ("openfiles", xmDialogShellWidgetClass, parent, | | 109 | shell = XtVaCreatePopupShell ("openfiles", xmDialogShellWidgetClass, parent, |
102 | XmNallowShellResize, True, | | 110 | XmNallowShellResize, True, |
103 | @@ -349,7 +358,8 @@ void open_both_files (Widget parent, cha | | 111 | @@ -349,7 +359,8 @@ void open_both_files (Widget parent, cha |
104 | fsb1 = XmCreateFileSelectionBox (frame1a, "files1", args, i); | | 112 | fsb1 = XmCreateFileSelectionBox (frame1a, "files1", args, i); |
105 | if (dir) { | | 113 | if (dir) { |
106 | XtFree (dir); | | 114 | XtFree (dir); |
107 | - XmStringFree (xms); | | 115 | - XmStringFree (xms); |
108 | + if (xms) | | 116 | + if (xms) |
109 | + XmStringFree (xms); | | 117 | + XmStringFree (xms); |
110 | } | | 118 | } |
111 | | | 119 | |
112 | i = 0; | | 120 | i = 0; |
113 | @@ -360,7 +370,8 @@ void open_both_files (Widget parent, cha | | 121 | @@ -360,7 +371,8 @@ void open_both_files (Widget parent, cha |
114 | fsb2 = XmCreateFileSelectionBox (frame2a, "files2", args, i); | | 122 | fsb2 = XmCreateFileSelectionBox (frame2a, "files2", args, i); |
115 | if (dir) { | | 123 | if (dir) { |
116 | XtFree (dir); | | 124 | XtFree (dir); |
117 | - XmStringFree (xms); | | 125 | - XmStringFree (xms); |
118 | + if (xms) | | 126 | + if (xms) |
119 | + XmStringFree (xms); | | 127 | + XmStringFree (xms); |
120 | } | | 128 | } |
121 | | | 129 | |
122 | XtAddCallback (fsb1, XmNokCallback, filel_both_cb, shell); | | 130 | XtAddCallback (fsb1, XmNokCallback, filel_both_cb, shell); |
123 | @@ -424,7 +435,7 @@ void open_left_file (Widget parent, char | | 131 | @@ -424,7 +436,7 @@ void open_left_file (Widget parent, char |
124 | Arg args[2]; | | 132 | Arg args[2]; |
125 | int i; | | 133 | int i; |
126 | char *dir; | | 134 | char *dir; |
127 | - XmString xms; | | 135 | - XmString xms; |
128 | + XmString xms = (XmString)0; | | 136 | + XmString xms = (XmString)0; |
129 | | | 137 | |
130 | i = 0; | | 138 | i = 0; |
131 | XtSetArg (args[i], XmNdeleteResponse, XmDO_NOTHING); i++; | | 139 | XtSetArg (args[i], XmNdeleteResponse, XmDO_NOTHING); i++; |
132 | @@ -435,7 +446,8 @@ void open_left_file (Widget parent, char | | 140 | @@ -435,7 +447,8 @@ void open_left_file (Widget parent, char |
133 | dialog = XmCreateFileSelectionDialog (parent, "openfile", args, i); | | 141 | dialog = XmCreateFileSelectionDialog (parent, "openfile", args, i); |
134 | if (dir) { | | 142 | if (dir) { |
135 | XtFree (dir); | | 143 | XtFree (dir); |
136 | - XmStringFree (xms); | | 144 | - XmStringFree (xms); |
137 | + if (xms) | | 145 | + if (xms) |
138 | + XmStringFree (xms); | | 146 | + XmStringFree (xms); |
139 | } | | 147 | } |
140 | XtAddCallback (XtParent (dialog), XmNpopupCallback, popup_cb, parent); | | 148 | XtAddCallback (XtParent (dialog), XmNpopupCallback, popup_cb, parent); |
141 | XtAddCallback (dialog, XmNokCallback, file_left_cb, dialog); | | 149 | XtAddCallback (dialog, XmNokCallback, file_left_cb, dialog); |
142 | @@ -477,7 +489,7 @@ void open_right_file (Widget parent, cha | | 150 | @@ -477,7 +490,7 @@ void open_right_file (Widget parent, cha |
143 | Arg args[2]; | | 151 | Arg args[2]; |
144 | int i; | | 152 | int i; |
145 | char *dir; | | 153 | char *dir; |
146 | - XmString xms; | | 154 | - XmString xms; |
147 | + XmString xms = (XmString)0; | | 155 | + XmString xms = (XmString)0; |
148 | | | 156 | |
149 | i = 0; | | 157 | i = 0; |
150 | XtSetArg (args[i], XmNdeleteResponse, XmDO_NOTHING); i++; | | 158 | XtSetArg (args[i], XmNdeleteResponse, XmDO_NOTHING); i++; |
151 | @@ -488,7 +500,8 @@ void open_right_file (Widget parent, cha | | 159 | @@ -488,7 +501,8 @@ void open_right_file (Widget parent, cha |
152 | dialog = XmCreateFileSelectionDialog (parent, "openfile", args, XtNumber (args)); | | 160 | dialog = XmCreateFileSelectionDialog (parent, "openfile", args, XtNumber (args)); |
153 | if (dir) { | | 161 | if (dir) { |
154 | XtFree (dir); | | 162 | XtFree (dir); |
155 | - XmStringFree (xms); | | 163 | - XmStringFree (xms); |
156 | + if (xms) | | 164 | + if (xms) |
157 | + XmStringFree (xms); | | 165 | + XmStringFree (xms); |
158 | } | | 166 | } |
159 | | | 167 | |
160 | XtAddCallback (XtParent (dialog), XmNpopupCallback, popup_cb, parent); | | 168 | XtAddCallback (XtParent (dialog), XmNpopupCallback, popup_cb, parent); |
161 | @@ -533,7 +546,7 @@ static void file_save_cb (Widget w, XtPo | | 169 | @@ -533,7 +547,7 @@ static void file_save_cb (Widget w, XtPo |
162 | if (access (filename, W_OK) == 0) { /* file exists and can be written */ | | 170 | if (access (filename, W_OK) == 0) { /* file exists and can be written */ |
163 | char buffer[1024]; | | 171 | char buffer[1024]; |
164 | | | 172 | |
165 | - (void) sprintf (buffer, "Overwrite \"%s\"?", filename); | | 173 | - (void) sprintf (buffer, "Overwrite \"%s\"?", filename); |
166 | + (void) snprintf (buffer, sizeof (buffer), "Overwrite \"%s\"?", filename); | | 174 | + (void) snprintf (buffer, sizeof (buffer), "Overwrite \"%s\"?", filename); |
167 | if (modal_question (w, "Mgdiff Save Question", buffer)) { | | 175 | if (modal_question (w, "Mgdiff Save Question", buffer)) { |
168 | set_cursor (shell); | | 176 | set_cursor (shell); |
169 | if ((status = really_save_file (filename, (Block *) closure)) != 0) { | | 177 | if ((status = really_save_file (filename, (Block *) closure)) != 0) { |
170 | @@ -569,7 +582,7 @@ void save_file (Widget parent, Block *b, | | 178 | @@ -569,7 +583,7 @@ void save_file (Widget parent, Block *b, |
171 | Arg args[3]; | | 179 | Arg args[3]; |
172 | int i; | | 180 | int i; |
173 | char *dir; | | 181 | char *dir; |
174 | - XmString xms; | | 182 | - XmString xms; |
175 | + XmString xms = (XmString)0; | | 183 | + XmString xms = (XmString)0; |
176 | | | 184 | |
177 | i = 0; | | 185 | i = 0; |
178 | XtSetArg (args[i], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); i++; | | 186 | XtSetArg (args[i], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); i++; |
179 | @@ -582,7 +595,8 @@ void save_file (Widget parent, Block *b, | | 187 | @@ -582,7 +596,8 @@ void save_file (Widget parent, Block *b, |
180 | dialog = XmCreateFileSelectionDialog (parent, "savefile", args, i); | | 188 | dialog = XmCreateFileSelectionDialog (parent, "savefile", args, i); |
181 | if (dir) { | | 189 | if (dir) { |
182 | XtFree (dir); | | 190 | XtFree (dir); |
183 | - XmStringFree (xms); | | 191 | - XmStringFree (xms); |
184 | + if (xms) | | 192 | + if (xms) |
185 | + XmStringFree (xms); | | 193 | + XmStringFree (xms); |
186 | } | | 194 | } |
187 | | | 195 | |
188 | XtAddCallback (XtParent (dialog), XmNpopupCallback, popup_cb, parent); | | 196 | XtAddCallback (XtParent (dialog), XmNpopupCallback, popup_cb, parent); |
189 | @@ -618,18 +632,32 @@ static int really_save_file (char *filen | | 197 | @@ -618,18 +633,32 @@ static int really_save_file (char *filen |
190 | return (status); | | 198 | return (status); |
191 | } | | 199 | } |
192 | else if ((b->arr[LEFT].type == DIFF) && (b->arr[RIGHT].type == DIFF)) { | | 200 | else if ((b->arr[LEFT].type == DIFF) && (b->arr[RIGHT].type == DIFF)) { |
193 | - assert (b->selected != NEITHER); | | 201 | - assert (b->selected != NEITHER); |
194 | + switch (b->selected) { | | 202 | + switch (b->selected) { |
195 | + case BOTH: | | 203 | + case BOTH: |
196 | + fprintf (file, "<<<<<<< diff from left file\n"); | | 204 | + fprintf (file, "<<<<<<< diff from left file\n"); |
197 | + if ((status = write_chunk (file, &b->arr[LEFT])) != 0) | | 205 | + if ((status = write_chunk (file, &b->arr[LEFT])) != 0) |
198 | + return (status); | | 206 | + return (status); |
199 | + fprintf (file, "========\n"); | | 207 | + fprintf (file, "========\n"); |
200 | + if ((status = write_chunk (file, &b->arr[RIGHT])) != 0) | | 208 | + if ((status = write_chunk (file, &b->arr[RIGHT])) != 0) |
201 | + return (status); | | 209 | + return (status); |
202 | + fprintf (file, ">>>>>>> diff from right file\n"); | | 210 | + fprintf (file, ">>>>>>> diff from right file\n"); |
| @@ -212,27 +220,27 @@ Pull patches from Debian. | | | @@ -212,27 +220,27 @@ Pull patches from Debian. |
212 | + } | | 220 | + } |
213 | } | | 221 | } |
214 | else if ((b->arr[LEFT].type == INSERT) && (b->arr[RIGHT].type == BLANK)) { | | 222 | else if ((b->arr[LEFT].type == INSERT) && (b->arr[RIGHT].type == BLANK)) { |
215 | - assert (b->selected != NEITHER); | | 223 | - assert (b->selected != NEITHER); |
216 | if (b->selected == LEFT) | | 224 | if (b->selected == LEFT) |
217 | if ((status = write_chunk (file, &b->arr[LEFT])) != 0) | | 225 | if ((status = write_chunk (file, &b->arr[LEFT])) != 0) |
218 | return (status); | | 226 | return (status); |
219 | } | | 227 | } |
220 | else if ((b->arr[LEFT].type == BLANK) && (b->arr[RIGHT].type == INSERT)) { | | 228 | else if ((b->arr[LEFT].type == BLANK) && (b->arr[RIGHT].type == INSERT)) { |
221 | - assert (b->selected != NEITHER); | | 229 | - assert (b->selected != NEITHER); |
222 | if (b->selected == RIGHT) | | 230 | if (b->selected == RIGHT) |
223 | if ((status = write_chunk (file, &b->arr[RIGHT])) != 0) | | 231 | if ((status = write_chunk (file, &b->arr[RIGHT])) != 0) |
224 | return (status); | | 232 | return (status); |
225 | @@ -669,3 +697,45 @@ static int write_chunk (FILE *file, Chun | | 233 | @@ -669,3 +698,45 @@ static int write_chunk (FILE *file, Chun |
226 | | | 234 | |
227 | return (0); | | 235 | return (0); |
228 | } | | 236 | } |
229 | + | | 237 | + |
230 | +void save_as_filename (Widget parent, Block *closure, char *filename) | | 238 | +void save_as_filename (Widget parent, Block *closure, char *filename) |
231 | +{ | | 239 | +{ |
232 | + char *title = "Mgdiff Save Error"; | | 240 | + char *title = "Mgdiff Save Error"; |
233 | + int status; | | 241 | + int status; |
234 | + Widget shell = get_top_shell (parent); | | 242 | + Widget shell = get_top_shell (parent); |
235 | + | | 243 | + |
236 | + if (access (filename, W_OK) == 0) { | | 244 | + if (access (filename, W_OK) == 0) { |
237 | + /* file exists and can be written */ | | 245 | + /* file exists and can be written */ |
238 | + char buffer[1024]; | | 246 | + char buffer[1024]; |