nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] A few internal spell check problems fixed


From: Rocco Corsi
Subject: [Nano-devel] A few internal spell check problems fixed
Date: Sat, 16 Mar 2002 20:16:07 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901

I found a few problems with the internal spell checker and also made some enhancements. I have worked on this for a few days and the changes are well tested. You may want to apply the changes to 1.0!

Problems:

1) Every time internal spell checking is called, an additional zombie spell process will remain in the process queue. These processes do get removed once nano terminates. The wait() was never reached.

2) When spell checker needs to return more than pipe_buff_size of data, word on buffer boundary will not be spell checked properly.

Enhancements:

1) Words returned from spell checker can end with \r or \n or \r\n or \n\r. This will make internal spell check work in environments other than Unix/Linux.

2) Last word returned from spell checker does not have to end with a \r or \n; a \0 is good enough.

Patch is attached.

Rocco
Index: nano.c
===================================================================
RCS file: /cvsroot/nano/nano/nano.c,v
retrieving revision 1.248
diff -u -r1.248 nano.c
--- nano.c      9 Mar 2002 20:05:26 -0000       1.248
+++ nano.c      17 Mar 2002 00:29:22 -0000
@@ -1487,11 +1487,10 @@
 int do_int_speller(char *tempfile_name)
 {
     char *read_buff, *read_buff_ptr, *read_buff_word;
-    long pipe_buff_size;
+    size_t pipe_buff_size, read_buff_size, read_buff_read, bytesread;
     int in_fd[2], tempfile_fd;
     int spell_status;
     pid_t pid_spell;
-    ssize_t bytesread;
 
     /* Create a pipe to spell program */
 
@@ -1560,40 +1559,48 @@
        return FALSE;
     }
 
-    read_buff = charalloc(pipe_buff_size + 1);
+    /* Read-in the returned spelling errors */
 
-    /* Process the returned spelling errors */
-
-    while ((bytesread = read(in_fd[0], read_buff, pipe_buff_size)) > 0) {
+    read_buff_read = 0;
+    read_buff_size = pipe_buff_size + 1;
+    read_buff = read_buff_ptr = charalloc(read_buff_size);
+
+    while ((bytesread = read(in_fd[0], read_buff_ptr, pipe_buff_size)) > 0) {
+
+       read_buff_read += bytesread;
+       read_buff_size += pipe_buff_size;
+       read_buff = read_buff_ptr = nrealloc(read_buff, read_buff_size);
+       read_buff_ptr += read_buff_read;
+    }
 
-       read_buff[bytesread] = (char) NULL;
-       read_buff_word = read_buff_ptr = read_buff;
+    *read_buff_ptr = (char) NULL;
+    close(in_fd[0]);
 
-       while (*read_buff_ptr != (char) NULL) {
+    /* Process the spelling errors */
 
-           /* Windows version may need to process additional char '\r' */
+    read_buff_word = read_buff_ptr = read_buff;
 
-           /* Possible problem here if last word not followed by '\n' */
+    while (*read_buff_ptr) {
 
-           if (*read_buff_ptr == '\n') {
-               *read_buff_ptr = (char) NULL;
+       if ((*read_buff_ptr == '\n') || (*read_buff_ptr == '\r')) {
+           *read_buff_ptr = (char) NULL;
+           if (read_buff_word != read_buff_ptr) {
                if (!do_int_spell_fix(read_buff_word)) {
-
-                   close(in_fd[0]);
-                   free(read_buff);
-                   replace_abort();
-
-                   return TRUE;
+                   read_buff_word = read_buff_ptr;
+                   break;
                }
-               read_buff_word = read_buff_ptr;
-               read_buff_word++;
            }
 
-           read_buff_ptr++;
+           read_buff_word = read_buff_ptr + 1;
        }
+
+       read_buff_ptr++;
     }
 
-    close(in_fd[0]);
+    /* special case where last word doesn't end with \n or \r */
+    if (read_buff_word != read_buff_ptr)
+       do_int_spell_fix(read_buff_word);
+
     free(read_buff);
     replace_abort();
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]