nano.c:do_int_speller(), do_alt_speller() - Programs now return char *, also fix waitpid invocation and checking of WIFEXITED WEXITSTATUS calls

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1330 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2002-12-16 04:25:53 +00:00
parent 3e5ad6397c
commit 334a94049f
3 changed files with 51 additions and 35 deletions

View File

@ -19,6 +19,10 @@ CVS code -
redundant word list. [The only reason this is going in during redundant word list. [The only reason this is going in during
feature freeze is because the int speller is useless as is and should feature freeze is because the int speller is useless as is and should
either be improved or removed. I chose improved]. either be improved or removed. I chose improved].
do_int_speller(), do_alt_speller()
- Programs now return char *, NULL for successful completion,
otherwise the error string to display. This allows us to give
more useful feedback to the user when spell checking fails.
- winio.c: - winio.c:
do_credits() do_credits()
- Add David Benbennick to credits. (DLR) - Add David Benbennick to credits. (DLR)

78
nano.c
View File

@ -1678,8 +1678,9 @@ int do_int_spell_fix(const char *word)
return TRUE; return TRUE;
} }
/* Integrated spell checking using 'spell' program. */ /* Integrated spell checking using 'spell' program.
int do_int_speller(char *tempfile_name) Return value: NULL for normal termination, otherwise the error string */
char *do_int_speller(char *tempfile_name)
{ {
char *read_buff, *read_buff_ptr, *read_buff_word; char *read_buff, *read_buff_ptr, *read_buff_word;
size_t pipe_buff_size, read_buff_size, read_buff_read, bytesread; size_t pipe_buff_size, read_buff_size, read_buff_read, bytesread;
@ -1687,10 +1688,11 @@ int do_int_speller(char *tempfile_name)
pid_t pid_spell, pid_sort, pid_uniq; pid_t pid_spell, pid_sort, pid_uniq;
int spell_status, sort_status, uniq_status; int spell_status, sort_status, uniq_status;
char *pipe_msg = _("Could not create pipe");
/* Create a pipe to spell program */ /* Create a pipe to spell program */
if (pipe(spell_fd) == -1) if (pipe(spell_fd) == -1)
return FALSE; return pipe_msg;
statusbar(_("Creating misspelled word list, please wait...")); statusbar(_("Creating misspelled word list, please wait..."));
/* A new process to run spell in */ /* A new process to run spell in */
@ -1734,7 +1736,7 @@ int do_int_speller(char *tempfile_name)
close(spell_fd[1]); close(spell_fd[1]);
if (pipe(sort_fd) == -1) if (pipe(sort_fd) == -1)
return FALSE; return pipe_msg;
/* A new process to run sort in */ /* A new process to run sort in */
@ -1771,7 +1773,7 @@ int do_int_speller(char *tempfile_name)
/* And one more for uniq! */ /* And one more for uniq! */
if (pipe(uniq_fd) == -1) if (pipe(uniq_fd) == -1)
return FALSE; return pipe_msg;
/* A new process to run uniq in */ /* A new process to run uniq in */
@ -1808,14 +1810,14 @@ int do_int_speller(char *tempfile_name)
if (pid_spell < 0 || pid_sort < 0 || pid_uniq < 0) { if (pid_spell < 0 || pid_sort < 0 || pid_uniq < 0) {
close(uniq_fd[0]); close(uniq_fd[0]);
return FALSE; return _("Could not fork");
} }
/* Get system pipe buffer size */ /* Get system pipe buffer size */
if ((pipe_buff_size = fpathconf(uniq_fd[0], _PC_PIPE_BUF)) < 1) { if ((pipe_buff_size = fpathconf(uniq_fd[0], _PC_PIPE_BUF)) < 1) {
close(uniq_fd[0]); close(uniq_fd[0]);
return FALSE; return _("Could not get size of pipe buffer");
} }
/* Read-in the returned spelling errors */ /* Read-in the returned spelling errors */
@ -1864,23 +1866,26 @@ int do_int_speller(char *tempfile_name)
/* Process end of spell process */ /* Process end of spell process */
waitpid(pid_spell, &spell_status, WNOHANG); waitpid(pid_spell, &spell_status, 0);
waitpid(pid_sort, &sort_status, WNOHANG); waitpid(pid_sort, &sort_status, 0);
waitpid(pid_uniq, &uniq_status, WNOHANG); waitpid(pid_uniq, &uniq_status, 0);
if (WIFEXITED(spell_status) && WIFEXITED(sort_status) if (WIFEXITED(spell_status) == 0 || WEXITSTATUS(spell_status))
&& WIFEXITED(uniq_status)) { return _("Error invoking \"spell\"");
if (WEXITSTATUS(spell_status) != 0 || WEXITSTATUS(sort_status) != 0
|| WEXITSTATUS(uniq_status) != 0)
return FALSE;
} else
return FALSE;
return TRUE; if (WIFEXITED(sort_status) == 0 || WEXITSTATUS(sort_status))
return _("Error invoking \"sort -f\"");
if (WIFEXITED(uniq_status) == 0 || WEXITSTATUS(uniq_status))
return _("Error invoking \"uniq\"");
/* Otherwise... */
return NULL;
} }
/* External spell checking. */ /* External spell checking.
int do_alt_speller(char *tempfile_name) Return value: NULL for normal termination, otherwise the error string */
char *do_alt_speller(char *tempfile_name)
{ {
int alt_spell_status, lineno_cur = current->lineno; int alt_spell_status, lineno_cur = current->lineno;
int x_cur = current_x, y_cur = current_y, pww_cur = placewewant; int x_cur = current_x, y_cur = current_y, pww_cur = placewewant;
@ -1929,13 +1934,20 @@ int do_alt_speller(char *tempfile_name)
/* Could not fork?? */ /* Could not fork?? */
if (pid_spell < 0) if (pid_spell < 0)
return FALSE; return _("Could not fork");
/* Wait for alternate speller to complete */ /* Wait for alternate speller to complete */
wait(&alt_spell_status); wait(&alt_spell_status);
if (!WIFEXITED(alt_spell_status) || WEXITSTATUS(alt_spell_status) != 0) if (!WIFEXITED(alt_spell_status) || WEXITSTATUS(alt_spell_status) != 0) {
return FALSE; char *altspell_error = NULL;
char *invoke_error = _("Could not invoke \"%s\"");
int msglen = strlen(invoke_error) + strlen(alt_speller) + 2;
altspell_error = charalloc(msglen);
snprintf(altspell_error, msglen, invoke_error, alt_speller);
return altspell_error;
}
refresh(); refresh();
free_filestruct(fileage); free_filestruct(fileage);
@ -1959,7 +1971,7 @@ int do_alt_speller(char *tempfile_name)
clearok(topwin, FALSE); clearok(topwin, FALSE);
titlebar(NULL); titlebar(NULL);
return TRUE; return NULL;
} }
#endif #endif
@ -1969,8 +1981,7 @@ int do_spell(void)
nano_disabled_msg(); nano_disabled_msg();
return (TRUE); return (TRUE);
#else #else
char *temp; char *temp, *spell_msg = _("Generic error");
int spell_res;
if ((temp = safe_tempnam(0, "nano.")) == NULL) { if ((temp = safe_tempnam(0, "nano.")) == NULL) {
statusbar(_("Could not create a temporary filename: %s"), statusbar(_("Could not create a temporary filename: %s"),
@ -1991,19 +2002,20 @@ int do_spell(void)
#endif #endif
if (alt_speller) if (alt_speller)
spell_res = do_alt_speller(temp); spell_msg = do_alt_speller(temp);
else else
spell_res = do_int_speller(temp); spell_msg = do_int_speller(temp);
remove(temp); remove(temp);
if (spell_res) if (spell_msg == NULL) {
statusbar(_("Finished checking spelling")); statusbar(_("Finished checking spelling"));
else return 1;
statusbar(_("Spell checking failed")); } else {
statusbar(_("Spell checking failed: %s"), spell_msg);
return 0;
}
free(temp); free(temp);
return spell_res;
#endif #endif
} }

View File

@ -260,8 +260,8 @@ int do_wrap(filestruct *inptr);
#endif #endif
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
int do_int_spell_fix(const char *word); int do_int_spell_fix(const char *word);
int do_int_speller(char *tempfile_name); char *do_int_speller(char *tempfile_name);
int do_alt_speller(char *tempfile_name); char *do_alt_speller(char *tempfile_name);
#endif #endif
int do_spell(void); int do_spell(void);
#if !defined(DISABLE_WRAPPING) && !defined(NANO_SMALL) || !defined(DISABLE_JUSTIFY) #if !defined(DISABLE_WRAPPING) && !defined(NANO_SMALL) || !defined(DISABLE_JUSTIFY)