home *** CD-ROM | disk | FTP | other *** search
- /* **************************************************************** */
- /* sspell - similar to Unix spell */
- /* version 1.1 */
- /* */
- /* Author: Maurice Castro */
- /* Release Date: 26 Jan 1992 */
- /* Bug Reports: maurice@bruce.cs.monash.edu.au */
- /* */
- /* This code has been placed by the Author into the Public Domain. */
- /* The code is NOT covered by any warranty, the user of the code is */
- /* solely responsible for determining the fitness of the program */
- /* for their purpose. No liability is accepted by the author for */
- /* the direct or indirect losses incurred through the use of this */
- /* program. */
- /* */
- /* Segments of this code may be used for any purpose that the user */
- /* deems appropriate. It would be polite to acknowledge the source */
- /* of the code. If you modify the code and redistribute it please */
- /* include a message indicating your changes and how users may */
- /* contact you for support. */
- /* */
- /* The author reserves the right to issue the official version of */
- /* this program. If you have useful suggestions or changes for the */
- /* code, please forward them to the author so that they might be */
- /* incorporated into the official version */
- /* */
- /* Please forward bug reports to the author via Internet. */
- /* */
- /* **************************************************************** */
-
- #include "cache.h"
- #include "file.h"
- #include <stdio.h>
- #include "config.h"
- #include "check.h"
- #include <signal.h>
- #include "error.h"
-
- FILE *fout;
- int prtderive;
- int prtroot;
- char progname[MAXSTR];
- char ftmp1[MAXSTR];
- char ftmp2[MAXSTR];
-
- void emergencyshutdown();
-
-
- void errormesg(mesg,val)
- char *mesg;
- int val;
- {
- fprintf(stderr,"%s: %s\n",progname, mesg);
- exit(val);
- }
-
- void usage()
- {
- fprintf(stderr,"%s: Usage:\n",progname);
- fprintf(stderr,"%s [-v] [-x] [-D dict] [-I index] [-R rule] [-C cachesize] [file] ...\n",progname);
- emergencyshutdown();
- exit(1);
- }
-
- void emergencyshutdown()
- {
- FILE *f;
- if (fout != NULL) fclose(fout);
- f = fopen(ftmp1,"rt");
- if (f != NULL)
- {
- fclose(f);
- unlink(ftmp1);
- }
- f = fopen(ftmp2,"rt");
- if (f != NULL)
- {
- fclose(f);
- unlink(ftmp2);
- }
- exit(-10);
- }
-
- void main(argc, argv)
- int argc;
- char *argv[];
- {
- char ssys[MAXSTR];
- char tstr1[MAXSTR];
- char tstr2[MAXSTR];
- int cachesize;
- char rule[MAXSTR];
- char index[MAXSTR];
- char dictionary[MAXSTR];
- int pt;
- FILE *f;
-
- /* setup */
- strcpy(ftmp1,"");
- strcpy(ftmp2,"");
- #if defined(pyr) || defined(__TURBOC__)
- signal(SIGABRT, emergencyshutdown);
- #endif
- signal(SIGINT, emergencyshutdown);
- signal(SIGTERM, emergencyshutdown);
- #ifdef __TURBOC__
- atexit(emergencyshutdown);
- #endif
- prtderive = 0;
- prtroot = 0;
- strcpy(progname,argv[0]);
-
- /* make the temporary file name */
- strcpy(ftmp1, ROOTNAME);
- strcat(ftmp1,"1");
- strcat(ftmp1,"XXXXXX");
- mktemp(ftmp1);
- strcpy(ftmp2, ROOTNAME);
- strcat(ftmp2,"2");
- strcat(ftmp2,"XXXXXX");
- mktemp(ftmp2);
- fout = fopen(ftmp1,"wt");
- if (fout == NULL)
- {
- errormesg("Unable to open temporary file. Aborting",-1);
- }
-
- /* startup */
- strcpy(dictionary, DICTIONARY);
- strcpy(rule, RULE);
- strcpy(index, INDEX);
- cachesize = CACHESIZE;
-
- pt = 1;
- while ((pt < argc) && (*(argv[pt]) == '-'))
- {
- if (!strcmp(argv[pt], "-v"))
- {
- prtderive = 1;
- pt++;
- continue;
- }
- if (!strcmp(argv[pt], "-x"))
- {
- prtroot = 1;
- pt++;
- continue;
- }
- if (!strcmp(argv[pt], "-D"))
- {
- pt++;
- if (pt == argc) usage();
- strcpy(dictionary,argv[pt]);
- pt++;
- continue;
- }
- if (!strcmp(argv[pt], "-R"))
- {
- pt++;
- if (pt == argc) usage();
- strcpy(rule,argv[pt]);
- pt++;
- continue;
- }
- if (!strcmp(argv[pt], "-I"))
- {
- pt++;
- if (pt == argc) usage();
- strcpy(index,argv[pt]);
- pt++;
- continue;
- }
- if (!strcmp(argv[pt], "-C"))
- {
- pt++;
- if (pt == argc) usage();
- cachesize = atoi(argv[pt]);
- if (cachesize < 1) cachesize = 1;
- pt++;
- continue;
- }
- usage();
- }
-
- initcache(cachesize);
- initfile(dictionary);
- initroot(rule);
-
- if (FAIL == readindex(index))
- {
- buildindex();
- writeindex(index);
- }
-
- /* check spelling for each file */
- if (pt < argc)
- while (pt < argc)
- {
- f = fopen(argv[pt],"rt");
- if (f == NULL)
- {
- fprintf(stderr,"Unable to open file: %s\n",argv[pt]);
- pt++;
- continue;
- }
- checkspell(f);
- fclose(f);
- pt++;
- }
- else
- checkspell(stdin);
-
- /* close down */
- closefile();
- fclose(fout);
-
- /* We have made the wordlist now sort it using systems provided sort */
- strcpy(ssys, SORT);
- strcat(ssys, " < ");
- strcat(ssys, ftmp1);
- strcat(ssys, " > ");
- strcat(ssys, ftmp2);
- system(ssys);
- unlink(ftmp1);
-
- /* Output preventing duplication */
- fout = fopen(ftmp2,"rt");
- strcpy(tstr2,"");
- while (!feof(fout))
- {
- if (fgets(tstr1,MAXSTR-1,fout)==NULL)
- break;
- if (strcmp(tstr1, tstr2))
- printf("%s",tstr1);
- strcpy(tstr2, tstr1);
- }
- fclose(fout);
- unlink(ftmp2);
- }
-
-