summaryrefslogtreecommitdiff
blob: 978e24de805d0cc463d2c36c12e99fd2f4697fe0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
From 4b7f7a30c9ec593d68186b1dfef44d4e2bda735b Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 22 Jun 2020 08:39:59 +0200
Subject: [PATCH] build: fix compilation when configured with
 --disable-speller

Move two functions that are used by the formatter too
to between the proper #ifdef.

Problem existed since commit 8089f5ad from a month ago.

Backported to v4.9.3
Signed-off-by: Lars Wendler <polynomial-c@gentoo.org>
---
 src/text.c | 302 ++++++++++++++++++++++++++---------------------------
 1 file changed, 151 insertions(+), 151 deletions(-)

diff --git a/src/text.c b/src/text.c
index 93ad3704..c7690fd0 100644
--- a/src/text.c
+++ b/src/text.c
@@ -2011,8 +2011,159 @@ void construct_argument_list(char ***arguments, char *command, char *filename)
 	(*arguments)[count - 2] = filename;
 	(*arguments)[count - 1] = NULL;
 }
+
+/* Open the specified file, and if that succeeds, remove the text of the marked
+ * region or of the entire buffer and read the file contents into its place. */
+bool replace_buffer(const char *filename, undo_type action, const char *operation)
+{
+	linestruct *was_cutbuffer = cutbuffer;
+	int descriptor;
+	FILE *stream;
+
+	descriptor = open_file(filename, FALSE, &stream);
+
+	if (descriptor < 0)
+		return FALSE;
+
+	cutbuffer = NULL;
+
+#ifndef NANO_TINY
+	add_undo(COUPLE_BEGIN, operation);
+
+	/* Cut either the marked region or the whole buffer. */
+	add_undo(action, NULL);
+#endif
+	do_snip(FALSE, openfile->mark, openfile->mark == NULL, FALSE);
+#ifndef NANO_TINY
+	update_undo(action);
 #endif
 
+	/* Discard what was cut. */
+	free_lines(cutbuffer);
+	cutbuffer = was_cutbuffer;
+
+	/* Insert the spell-checked file into the cleared area. */
+	read_file(stream, descriptor, filename, TRUE);
+
+#ifndef NANO_TINY
+	add_undo(COUPLE_END, operation);
+#endif
+	return TRUE;
+}
+
+/* Execute the given program, with the given temp file as last argument. */
+const char *treat(char *tempfile_name, char *theprogram, bool spelling)
+{
+	ssize_t lineno_save = openfile->current->lineno;
+	size_t current_x_save = openfile->current_x;
+	size_t pww_save = openfile->placewewant;
+	bool was_at_eol = (openfile->current->data[openfile->current_x] == '\0');
+	struct stat fileinfo;
+	long timestamp_sec, timestamp_nsec;
+	static char **arguments = NULL;
+	pid_t thepid;
+	int program_status;
+	bool replaced = FALSE;
+
+	/* Get the timestamp and the size of the temporary file. */
+	stat(tempfile_name, &fileinfo);
+	timestamp_sec = (long)fileinfo.st_mtim.tv_sec;
+	timestamp_nsec = (long)fileinfo.st_mtim.tv_nsec;
+
+	/* If the number of bytes to check is zero, get out. */
+	if (fileinfo.st_size == 0)
+		return NULL;
+
+	/* Exit from curses mode to give the program control of the terminal. */
+	endwin();
+
+	construct_argument_list(&arguments, theprogram, tempfile_name);
+
+	/* Fork a child process and run the given program in it. */
+	if ((thepid = fork()) == 0) {
+		execvp(arguments[0], arguments);
+
+		/* Terminate the child if the program is not found. */
+		exit(9);
+	} else if (thepid < 0)
+		return _("Could not fork");
+
+	/* Block SIGWINCHes while waiting for the program to end,
+	 * so nano doesn't get pushed past the wait(). */
+	block_sigwinch(TRUE);
+	wait(&program_status);
+	block_sigwinch(FALSE);
+
+	/* Restore the terminal state and reenter curses mode. */
+	terminal_init();
+	doupdate();
+
+	if (!WIFEXITED(program_status) || WEXITSTATUS(program_status) > 2) {
+		statusline(ALERT, _("Error invoking '%s'"), arguments[0]);
+		return NULL;
+	} else if (WEXITSTATUS(program_status) != 0)
+		statusline(ALERT, _("Program '%s' complained"), arguments[0]);
+
+	/* Stat the temporary file again. */
+	stat(tempfile_name, &fileinfo);
+
+	/* When the temporary file wasn't touched, say so and leave. */
+	if ((long)fileinfo.st_mtim.tv_sec == timestamp_sec &&
+				(long)fileinfo.st_mtim.tv_nsec == timestamp_nsec) {
+		statusbar(_("Nothing changed"));
+		return NULL;
+	}
+
+#ifndef NANO_TINY
+	/* Replace the marked text (or entire text) with the corrected text. */
+	if (spelling && openfile->mark) {
+		ssize_t was_mark_lineno = openfile->mark->lineno;
+		bool upright = mark_is_before_cursor();
+
+		replaced = replace_buffer(tempfile_name, CUT, "spelling correction");
+
+		/* Adjust the end point of the marked region for any change in
+		 * length of the region's last line. */
+		if (upright)
+			current_x_save = openfile->current_x;
+		else
+			openfile->mark_x = openfile->current_x;
+
+		/* Restore the mark. */
+		openfile->mark = line_from_number(was_mark_lineno);
+	} else
+#endif
+	{
+		openfile->current = openfile->filetop;
+		openfile->current_x = 0;
+
+		replaced = replace_buffer(tempfile_name, CUT_TO_EOF,
+					/* TRANSLATORS: The next two go with Undid/Redid messages. */
+					(spelling ? N_("spelling correction") : N_("formatting")));
+	}
+
+	/* Go back to the old position. */
+	goto_line_posx(lineno_save, current_x_save);
+	if (was_at_eol || openfile->current_x > strlen(openfile->current->data))
+		openfile->current_x = strlen(openfile->current->data);
+
+#ifndef NANO_TINY
+	if (replaced)
+		update_undo(COUPLE_END);
+#endif
+
+	openfile->placewewant = pww_save;
+	adjust_viewport(STATIONARY);
+
+	if (spelling)
+		statusbar(_("Finished checking spelling"));
+	else
+		statusbar(_("Buffer has been processed"));
+
+	return NULL;
+}
+#endif /* ENABLE_SPELLER || ENABLE_COLOR */
+
 #ifdef ENABLE_SPELLER
 /* Let the user edit the misspelled word.  Return FALSE if the user cancels. */
 bool fix_spello(const char *word)
@@ -2307,157 +2458,6 @@ const char *do_int_speller(const char *tempfile_name)
 	return NULL;
 }
 
-/* Open the specified file, and if that succeeds, remove the text of the marked
- * region or of the entire buffer and read the file contents into its place. */
-bool replace_buffer(const char *filename, undo_type action, const char *operation)
-{
-	linestruct *was_cutbuffer = cutbuffer;
-	int descriptor;
-	FILE *stream;
-
-	descriptor = open_file(filename, FALSE, &stream);
-
-	if (descriptor < 0)
-		return FALSE;
-
-	cutbuffer = NULL;
-
-#ifndef NANO_TINY
-	add_undo(COUPLE_BEGIN, operation);
-
-	/* Cut either the marked region or the whole buffer. */
-	add_undo(action, NULL);
-#endif
-	do_snip(FALSE, openfile->mark, openfile->mark == NULL, FALSE);
-#ifndef NANO_TINY
-	update_undo(action);
-#endif
-
-	/* Discard what was cut. */
-	free_lines(cutbuffer);
-	cutbuffer = was_cutbuffer;
-
-	/* Insert the spell-checked file into the cleared area. */
-	read_file(stream, descriptor, filename, TRUE);
-
-#ifndef NANO_TINY
-	add_undo(COUPLE_END, operation);
-#endif
-	return TRUE;
-}
-
-/* Execute the given program, with the given temp file as last argument. */
-const char *treat(char *tempfile_name, char *theprogram, bool spelling)
-{
-	ssize_t lineno_save = openfile->current->lineno;
-	size_t current_x_save = openfile->current_x;
-	size_t pww_save = openfile->placewewant;
-	bool was_at_eol = (openfile->current->data[openfile->current_x] == '\0');
-	struct stat fileinfo;
-	long timestamp_sec, timestamp_nsec;
-	static char **arguments = NULL;
-	pid_t thepid;
-	int program_status;
-	bool replaced = FALSE;
-
-	/* Get the timestamp and the size of the temporary file. */
-	stat(tempfile_name, &fileinfo);
-	timestamp_sec = (long)fileinfo.st_mtim.tv_sec;
-	timestamp_nsec = (long)fileinfo.st_mtim.tv_nsec;
-
-	/* If the number of bytes to check is zero, get out. */
-	if (fileinfo.st_size == 0)
-		return NULL;
-
-	/* Exit from curses mode to give the program control of the terminal. */
-	endwin();
-
-	construct_argument_list(&arguments, theprogram, tempfile_name);
-
-	/* Fork a child process and run the given program in it. */
-	if ((thepid = fork()) == 0) {
-		execvp(arguments[0], arguments);
-
-		/* Terminate the child if the program is not found. */
-		exit(9);
-	} else if (thepid < 0)
-		return _("Could not fork");
-
-	/* Block SIGWINCHes while waiting for the program to end,
-	 * so nano doesn't get pushed past the wait(). */
-	block_sigwinch(TRUE);
-	wait(&program_status);
-	block_sigwinch(FALSE);
-
-	/* Restore the terminal state and reenter curses mode. */
-	terminal_init();
-	doupdate();
-
-	if (!WIFEXITED(program_status) || WEXITSTATUS(program_status) > 2) {
-		statusline(ALERT, _("Error invoking '%s'"), arguments[0]);
-		return NULL;
-	} else if (WEXITSTATUS(program_status) != 0)
-		statusline(ALERT, _("Program '%s' complained"), arguments[0]);
-
-	/* Stat the temporary file again. */
-	stat(tempfile_name, &fileinfo);
-
-	/* When the temporary file wasn't touched, say so and leave. */
-	if ((long)fileinfo.st_mtim.tv_sec == timestamp_sec &&
-				(long)fileinfo.st_mtim.tv_nsec == timestamp_nsec) {
-		statusbar(_("Nothing changed"));
-		return NULL;
-	}
-
-#ifndef NANO_TINY
-	/* Replace the marked text (or entire text) with the corrected text. */
-	if (spelling && openfile->mark) {
-		ssize_t was_mark_lineno = openfile->mark->lineno;
-		bool upright = mark_is_before_cursor();
-
-		replaced = replace_buffer(tempfile_name, CUT, "spelling correction");
-
-		/* Adjust the end point of the marked region for any change in
-		 * length of the region's last line. */
-		if (upright)
-			current_x_save = openfile->current_x;
-		else
-			openfile->mark_x = openfile->current_x;
-
-		/* Restore the mark. */
-		openfile->mark = line_from_number(was_mark_lineno);
-	} else
-#endif
-	{
-		openfile->current = openfile->filetop;
-		openfile->current_x = 0;
-
-		replaced = replace_buffer(tempfile_name, CUT_TO_EOF,
-					/* TRANSLATORS: The next two go with Undid/Redid messages. */
-					(spelling ? N_("spelling correction") : N_("formatting")));
-	}
-
-	/* Go back to the old position. */
-	goto_line_posx(lineno_save, current_x_save);
-	if (was_at_eol || openfile->current_x > strlen(openfile->current->data))
-		openfile->current_x = strlen(openfile->current->data);
-
-#ifndef NANO_TINY
-	if (replaced)
-		update_undo(COUPLE_END);
-#endif
-
-	openfile->placewewant = pww_save;
-	adjust_viewport(STATIONARY);
-
-	if (spelling)
-		statusbar(_("Finished checking spelling"));
-	else
-		statusbar(_("Buffer has been processed"));
-
-	return NULL;
-}
-
 /* Spell check the current file.  If an alternate spell checker is
  * specified, use it.  Otherwise, use the internal spell checker. */
 void do_spell(void)
-- 
2.28.0