home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
gnu
/
ispell-4.0-src.lha
/
ispell-4.0
/
screen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-24
|
19KB
|
956 lines
/* Copyright (C) 1990, 1993 Free Software Foundation, Inc.
This file is part of GNU ISPELL.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdio.h>
#include <ctype.h>
#include <setjmp.h>
#include <signal.h>
#include "ispell.h"
#include "hash.h"
int reading_interactive_command;
jmp_buf command_loop;
extern struct sp_corrections corrections;
#ifdef __STDC__
static void copyout (char **, int, FILE *);
#else
static void copyout ();
#endif
extern int lflag;
extern int uflag;
extern int iflag;
extern FILE *sortf;
extern int Sflag;
extern int intr_typed;
char tempfile[100];
#define NOPARITY 0x7f
static void
giveihelp ()
{
erase ();
printf ("You have interrupted ISPELL. Commands are:\r\n");
printf ("\r\n");
printf ("SPACE Continue scanning the current file.\r\n");
printf ("Q Write changes so far, and ignore misspellings in\r\n");
printf (" the rest of the file.\r\n");
printf ("X Abandon changes to this file.\r\n");
printf ("! Shell escape.\r\n");
printf ("^L Redraw screen.\r\n");
printf ("\r\n\r\n");
printf ("-- Type space to continue --");
fflush (stdout);
getchar ();
}
static void
givehelp ()
{
erase ();
(void) printf ("Whenever a word is found that is not in the dictionary,\r\n");
(void) printf ("it is printed on the first line of the screen. If the dictionary\r\n");
(void) printf ("contains any similar words, they are listed with a single digit\r\n");
(void) printf ("next to each one. You have the option of replacing the word\r\n");
(void) printf ("completely, or choosing one of the suggested words.\r\n");
(void) printf ("\r\n");
(void) printf ("Commands are:\r\n\r\n");
(void) printf ("R Replace the misspelled word completely.\r\n");
(void) printf ("Space Accept the word this time only\r\n");
(void) printf ("A Accept the word for the rest of this file.\r\n");
(void) printf ("I Accept the word, and put it in your private dictionary.\r\n");
(void) printf ("0-9 Replace with one of the suggested words.\r\n");
(void) printf ("<NL> Recompute near misses. Use this if you interrupted\r\n");
(void) printf (" the near miss generator, and you want it to\r\n");
(void) printf (" again on this word.\r\n");
(void) printf ("Q Write the rest of this file, ignoring misspellings,\r\n");
(void) printf (" and start next file.\r\n");
(void) printf ("X Exit immediately. Asks for conformation.\r\n");
(void) printf (" Leaves file unchanged.\r\n");
(void) printf ("! Shell escape.\r\n");
(void) printf ("^L Redraw screen.\r\n");
(void) printf ("\r\n\r\n");
(void) printf ("-- Type space to continue --");
(void) fflush (stdout);
(void) getchar ();
}
char *getline ();
char firstbuf[BUFSIZ], secondbuf[BUFSIZ];
char gtoken[BUFSIZ + 10];
int quit;
char *currentfile = NULL;
static long filesize;
static FILE *filestream;
int changed;
void
dofile (filename)
char *filename;
{
int c;
FILE *in, *out;
void (*oldf) (NOARGS);
currentfile = filename;
if ((in = fopen (filename, "r")) == NULL)
{
(void) fprintf (stderr, "Can't open %s\r\n", filename);
return;
}
changed = 0;
filesize = lseek (fileno (in), 0l, 2);
(void) lseek (fileno (in), 0l, 0);
if (access (filename, 2) < 0)
{
(void) fprintf (stderr, "Can't write to %s\r\n", filename);
return;
}
(void) strcpy (tempfile, "/tmp/ispellXXXXXX");
(void) mktemp (tempfile);
if ((out = fopen (tempfile, "w")) == NULL)
{
(void) fprintf (stderr, "Can't create %s\r\n", tempfile);
return;
}
quit = 0;
checkfile (in, out, (long) 0);
(void) fclose (in);
(void) fclose (out);
if (changed == 0)
{
(void) unlink (tempfile);
tempfile[0] = 0;
return;
}
if ((in = fopen (tempfile, "r")) == NULL)
{
(void) fprintf (stderr, "tempoary file disappeared (%s)\r\n", tempfile);
(void) sleep (2);
return;
}
oldf = (void (*)(NOARGS)) signal (SIGINT, SIG_IGN);
if ((out = fopen (filename, "w")) == NULL)
{
(void) unlink (tempfile);
tempfile[0] = 0;
(void) fprintf (stderr, "can't create %s\r\n", filename);
(void) sleep (2);
return;
}
while ((c = getc (in)) != EOF)
putc (c, out);
fclose (in);
(void) fclose (out);
(void) unlink (tempfile);
tempfile[0] = 0;
signal (SIGINT, (RETSIGTYPE (*)()) oldf);
}
char *currentchar;
FILE *out;
void
checkfile (in, outx, end)
FILE *in, *outx;
long end;
{
char *p;
int maybe_troff;
char *cstart, *cend;
int i;
long lineoffset;
out = outx;
checkstart:
filestream = in;
secondbuf[0] = 0;
maybe_troff = 0;
while (1)
{
(void) strcpy (firstbuf, secondbuf);
if (quit)
{
if (out == NULL)
return;
while (fgets (secondbuf, sizeof secondbuf, in)
!= NULL)
(void) fputs (secondbuf, out);
break;
}
if (Sflag)
{
lineoffset = ftell (in);
if (end && lineoffset >= end)
break;
}
if (fgets (secondbuf, sizeof secondbuf, in) == NULL)
break;
/* uflag is on when emulating traditional spell
* if so, then follow troff commands '.so' and '.nx'
*/
if (uflag && !iflag && secondbuf[0] == '.')
{
int soflag = 0, nxflag = 0;
FILE *so;
char *n, *end;
if (strncmp (secondbuf, ".so", 3) == 0)
soflag = 1;
if (strncmp (secondbuf, ".nx", 3) == 0)
nxflag = 1;
if (soflag || nxflag)
{
n = secondbuf + 3;
while (isspace (*n))
n++;
end = n;
while (*end && !isspace (*end))
end++;
*end = 0;
if (strncmp (n, "/gnu/lib", 8) == 0)
continue;
if (nxflag)
{
if (freopen (n, "r", in) == NULL)
{
(void) fprintf (stderr, "can't open %s\n",
n);
return;
}
goto checkstart;
}
if ((so = fopen (n, "r")) == NULL)
{
(void) fprintf (stderr,
"can't open %s\n", n);
}
else
{
/* FIXME: gcc -Wall found the third argument missing in this call
to checkfile. The function isn't documented, so I have no idea what
it actually is supposed flag. My assumption is that it worked in most
instances because random junk on the stack would likely be non-zero.
--bson */
checkfile (so, (FILE *) NULL, (long) 1);
(void) fclose (so);
}
continue;
}
}
currentchar = secondbuf;
p = secondbuf + strlen (secondbuf) - 1;
if (*p == '\n')
*p = 0;
while (1)
{
if (skip_to_next_word (out) == 0)
break;
cstart = currentchar;
cend = cstart;
if (intr_typed)
{
if (lflag || Sflag)
return;
gtoken[0] = 0;
(void) correct (gtoken, sizeof gtoken,
cstart, cend, ¤tchar);
if (quit)
{
(void) fputs (currentchar, out);
break;
}
intr_typed = 0;
}
/* first letter is a lexletter, therefore,
* loop will execute at least once
*/
p = gtoken;
i = 0;
while (islexletter (*cend) && i < MAX_WORD_LEN - 5)
{
*p++ = *cend++;
i++;
}
/* flush quote if at end of word */
if (p[-1] == '\'')
{
p--;
cend--;
}
*p = 0;
currentchar = cend;
if (good (gtoken, strlen (gtoken), 0))
{
if (out)
(void) fputs (gtoken, out);
continue;
}
interaction_flag = 1;
/* word is bad */
if (uflag)
{
/* traditional spell compatability */
(v