*** spell.c	Tue Sep 21 14:20:59 1993
--- spell.c.old	Tue Sep 21 14:20:46 1993
***************
*** 37,42 ****
--- 37,46 ----
  static char *wordArray[10];
  static boolean expertMode;
  
+ /* flags to account for variations in ispell behavior */
+ static boolean isvers_extranewlines = FALSE; /* in ispell 3, there were extra newlines on things. */
+ static boolean isvers_noaccept = FALSE; /* in ispell 4, there is no way to accept or add words in -a mode. */
+ 
  /* Process handling stuff. Copied verbatim from compile.c */
  
  #define READFD 0	/* The pipe index from which you can do a read. */
***************
*** 143,155 ****
  
      int i;
  
      while (*choices == ' ')
          choices++;
      for (i = 0; *choices != '\0' && (i < 10); i++) {
          sprintf(buffer, "%d) ", i);
          buffer += strlen(buffer);
          wordArray[i] = choices;
!         while (*choices && *choices != ' ')
              *buffer++ = *choices++;
  	if (!*choices) break;
          *choices++ = '\0';
--- 147,168 ----
  
      int i;
  
+     if(isvers_extranewlines) {
+ 	char *t;
+ 	if (t = (char*) index(choices, ':')) {
+ 	    choices = t + 2;
+ 	}
+     }
+     else {
      while (*choices == ' ')
          choices++;
+     }
+ 
      for (i = 0; *choices != '\0' && (i < 10); i++) {
          sprintf(buffer, "%d) ", i);
          buffer += strlen(buffer);
          wordArray[i] = choices;
!         while (*choices && *choices != ',' && *choices != ' ' && *choices != '\n')
              *buffer++ = *choices++;
  	if (!*choices) break;
          *choices++ = '\0';
***************
*** 158,164 ****
              choices++;
      }
      *buffer = '\0';
!     return i - 1;
  }
  
  /* Actually spell check an entire document starting at the current cursor
--- 171,177 ----
              choices++;
      }
      *buffer = '\0';
!     return i + 1;
  }
  
  /* Actually spell check an entire document starting at the current cursor
***************
*** 171,177 ****
      long rock;
  {
  
!     int pos = textview_GetDotPosition(self), savePos = pos, saveLength = textview_GetDotLength(self);
      struct text *text;
      struct mark *tempMark;
      struct process *speller;
--- 184,190 ----
      long rock;
  {
  
!     int pos = textview_GetDotPosition(self), savePos = pos, saveLength = textview_GetDotLength(self), c;
      struct text *text;
      struct mark *tempMark;
      struct process *speller;
***************
*** 192,203 ****
  	return;
      }
  
  /* Do an initial rendezvous to ensure that process actually started. */
      if (fputs("the\n", outFile) == EOF || fflush(outFile) == EOF ||
!         fgets(testBuf, sizeof(testBuf), inFile) == NULL || *testBuf != '*') {
          message_DisplayString(self, 0, "Could not start ispell. Spell checking may not be supported at this site.");
          return;
      }
  
      while (pos<(textlen=text_GetLength(text))) {
  
--- 205,236 ----
  	return;
      }
  
+     *testBuf = (char) 0;
  /* Do an initial rendezvous to ensure that process actually started. */
+ #define EatNewLine() fgets(testBuf, sizeof(testBuf), inFile)
+ 
      if (fputs("the\n", outFile) == EOF || fflush(outFile) == EOF ||
!         fgets(testBuf, sizeof(testBuf), inFile) == NULL || *testBuf == '\0') {
          message_DisplayString(self, 0, "Could not start ispell. Spell checking may not be supported at this site.");
          return;
      }
+     else {
+ 	if(*testBuf != '*') { /* testBuf must contain the ispell3 version string */
+ 	    message_DisplayString(self, 10, testBuf);
+ 	    isvers_extranewlines = TRUE;
+ 	    EatNewLine();   /* eat '*' result from 'the' query */
+ 	    EatNewLine();   /* eat '\n' */
+ 	}
+ 	else {
+ 	    /* I assume that the extranewlines problem and the noaccept problem do not coexist in any one version of ispell. */
+ 	    fputs("@murglexxxnonexistentword\n", outFile);
+ 	    fflush(outFile);
+ 	    fgets(testBuf, sizeof(testBuf), inFile);
+ 	    if (*testBuf != '*') {
+ 		isvers_noaccept = TRUE;
+ 	    }
+ 	}
+     }
  
      while (pos<(textlen=text_GetLength(text))) {
  
***************
*** 219,224 ****
--- 252,261 ----
              *temp = '\0';
  
              fgets(buffer, sizeof(buffer), inFile);
+ 
+ 	    if (isvers_extranewlines) /* All queries in ispell3 end in a newline */
+ 		EatNewLine();
+ 
              temp = buffer;
              while (*temp == ' ' || *temp == '\n')
                  temp++;
***************
*** 288,298 ****
                                  break;
                              case 'a':
                              case 'A':
                                  fputs("@", outFile);
                                  fputs(thisWord, outFile);
                                  fputc('\n', outFile);
                                  fflush(outFile);
!                                 fgets(buffer, sizeof(buffer), inFile); /* Snag garbage... */
                                  message_DisplayString(self, 0, "Accepted for rest of session.");
                                  break;
                              case 'r':
--- 325,344 ----
                                  break;
                              case 'a':
                              case 'A':
+ 				if (isvers_noaccept) {
+ 				    message_DisplayString(self, 0, "Your ispell does not allow the 'accept' option. Press any key to continue.");
+ 				    im_GetCharacter(textview_GetIM(self));
+ 				    flag = 1;
+ 				    break;
+ 				}
                                  fputs("@", outFile);
                                  fputs(thisWord, outFile);
                                  fputc('\n', outFile);
                                  fflush(outFile);
! 				if (! isvers_extranewlines) {
! 				    /* Snag garbage... */
! 				    fgets(buffer, sizeof(buffer), inFile);
! 				}
                                  message_DisplayString(self, 0, "Accepted for rest of session.");
                                  break;
                              case 'r':
***************
*** 310,320 ****
                                  break;
                              case 'i':
                              case 'I':
                                  putc('*', outFile);
                                  fputs(thisWord, outFile);
                                  fputc('\n', outFile);
                                  fflush(outFile);
!                                 fgets(buffer, sizeof(buffer), inFile); /* Snag garbage... */
                                  message_DisplayString(self, 0, "Entered in private dict.");
                                  break;
                              case 'q':
--- 356,375 ----
                                  break;
                              case 'i':
                              case 'I':
+ 				if (isvers_noaccept) {
+ 				    message_DisplayString(self, 0, "Your ispell does not allow the 'insert' option. Press any key to continue.");
+ 				    im_GetCharacter(textview_GetIM(self));
+ 				    flag = 1;
+ 				    break;
+ 				}
                                  putc('*', outFile);
                                  fputs(thisWord, outFile);
                                  fputc('\n', outFile);
                                  fflush(outFile);
! 				if (! isvers_extranewlines) {
! 				    /* Snag garbage... */
! 				    fgets(buffer, sizeof(buffer), inFile);
! 				}
                                  message_DisplayString(self, 0, "Entered in private dict.");
                                  break;
                              case 'q':
***************
*** 324,329 ****
--- 379,385 ----
                                  message_DisplayString(self, 0, "Spell check terminated.");
                                  textview_SetDotPosition(self, savePos);
                                  textview_SetDotLength(self, saveLength);
+ 				textview_FrameDot(self, savePos);
                                  textview_WantUpdate(self, self);
                                  text_RemoveMark(text, tempMark);
                                  mark_Destroy(tempMark);
***************
*** 363,368 ****
--- 419,425 ----
      textview_SetDotPosition(self, savePos);
      textview_SetDotLength(self, saveLength);
      message_DisplayString(self, 0, "Spell check completed.");
+     textview_FrameDot(self, savePos);
      textview_WantUpdate(self, self);
  }
  
