home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / TEXT / UTILITY / SSPELL11.ZIP / SSPELL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-26  |  6.3 KB  |  241 lines

  1. /* **************************************************************** */
  2. /*             sspell - similar to Unix spell                       */
  3. /*                        version 1.1                               */
  4. /*                                                                  */
  5. /* Author: Maurice Castro                                           */
  6. /* Release Date: 26 Jan 1992                                        */
  7. /* Bug Reports: maurice@bruce.cs.monash.edu.au                      */
  8. /*                                                                  */
  9. /* This code has been placed by the Author into the Public Domain.  */
  10. /* The code is NOT covered by any warranty, the user of the code is */
  11. /* solely responsible for determining the fitness of the program    */
  12. /* for their purpose. No liability is accepted by the author for    */
  13. /* the direct or indirect losses incurred through the use of this   */
  14. /* program.                                                         */
  15. /*                                                                  */
  16. /* Segments of this code may be used for any purpose that the user  */
  17. /* deems appropriate. It would be polite to acknowledge the source  */
  18. /* of the code. If you modify the code and redistribute it please   */
  19. /* include a message indicating your changes and how users may      */
  20. /* contact you for support.                                         */
  21. /*                                                                  */
  22. /* The author reserves the right to issue the official version of   */
  23. /* this program. If you have useful suggestions or changes for the  */
  24. /* code, please forward them to the author so that they might be    */
  25. /* incorporated into the official version                           */
  26. /*                                                                  */
  27. /* Please forward bug reports to the author via Internet.           */
  28. /*                                                                  */
  29. /* **************************************************************** */
  30.  
  31. #include "cache.h"
  32. #include "file.h"
  33. #include <stdio.h>
  34. #include "config.h"
  35. #include "check.h"
  36. #include <signal.h>
  37. #include "error.h"
  38.  
  39. FILE *fout;
  40. int prtderive;
  41. int prtroot;
  42. char progname[MAXSTR];
  43. char ftmp1[MAXSTR];
  44. char ftmp2[MAXSTR];
  45.  
  46. void emergencyshutdown();
  47.  
  48.  
  49. void errormesg(mesg,val)
  50. char *mesg;
  51. int val;
  52. {
  53.    fprintf(stderr,"%s: %s\n",progname, mesg);
  54.    exit(val);
  55.    }
  56.  
  57. void usage()
  58. {
  59.    fprintf(stderr,"%s: Usage:\n",progname);
  60.    fprintf(stderr,"%s [-v] [-x] [-D dict] [-I index] [-R rule] [-C cachesize] [file] ...\n",progname);
  61.    emergencyshutdown();
  62.    exit(1);
  63.    }
  64.  
  65. void emergencyshutdown()
  66. {
  67.    FILE *f;
  68.    if (fout != NULL) fclose(fout);
  69.    f = fopen(ftmp1,"rt");
  70.    if (f != NULL)
  71.    {
  72.       fclose(f);
  73.       unlink(ftmp1);
  74.       }
  75.    f = fopen(ftmp2,"rt");
  76.    if (f != NULL)
  77.    {
  78.       fclose(f);
  79.       unlink(ftmp2);
  80.       }
  81.    exit(-10);
  82.    }
  83.  
  84. void main(argc, argv)
  85. int argc;
  86. char *argv[];
  87. {
  88.    char ssys[MAXSTR];
  89.    char tstr1[MAXSTR];
  90.    char tstr2[MAXSTR];
  91.    int cachesize;
  92.    char rule[MAXSTR];
  93.    char index[MAXSTR];
  94.    char dictionary[MAXSTR];
  95.    int pt;
  96.    FILE *f;
  97.  
  98.    /* setup */
  99.    strcpy(ftmp1,"");
  100.    strcpy(ftmp2,"");
  101. #if defined(pyr) || defined(__TURBOC__)
  102.    signal(SIGABRT, emergencyshutdown);
  103. #endif
  104.    signal(SIGINT, emergencyshutdown);
  105.    signal(SIGTERM, emergencyshutdown); 
  106. #ifdef __TURBOC__
  107.    atexit(emergencyshutdown);
  108. #endif
  109.    prtderive = 0;
  110.    prtroot = 0;
  111.    strcpy(progname,argv[0]);
  112.  
  113.    /* make the temporary file name */
  114.    strcpy(ftmp1, ROOTNAME);
  115.    strcat(ftmp1,"1");
  116.    strcat(ftmp1,"XXXXXX");
  117.    mktemp(ftmp1);
  118.    strcpy(ftmp2, ROOTNAME);
  119.    strcat(ftmp2,"2");
  120.    strcat(ftmp2,"XXXXXX");
  121.    mktemp(ftmp2);
  122.    fout = fopen(ftmp1,"wt");
  123.    if (fout == NULL)
  124.    {
  125.        errormesg("Unable to open temporary file. Aborting",-1);
  126.        }
  127.  
  128.    /* startup */
  129.    strcpy(dictionary, DICTIONARY);
  130.    strcpy(rule, RULE);
  131.    strcpy(index, INDEX);
  132.    cachesize = CACHESIZE;
  133.  
  134.    pt = 1;
  135.    while ((pt < argc) && (*(argv[pt]) == '-'))
  136.    {
  137.        if (!strcmp(argv[pt], "-v"))
  138.        {
  139.           prtderive = 1;
  140.           pt++;
  141.           continue;
  142.           }
  143.        if (!strcmp(argv[pt], "-x"))
  144.        {
  145.           prtroot = 1;
  146.           pt++;
  147.           continue;
  148.           }
  149.        if (!strcmp(argv[pt], "-D"))
  150.        {
  151.           pt++;
  152.           if (pt == argc) usage();
  153.           strcpy(dictionary,argv[pt]);
  154.           pt++;
  155.           continue;
  156.           }
  157.        if (!strcmp(argv[pt], "-R"))
  158.        {
  159.           pt++;
  160.           if (pt == argc) usage();
  161.           strcpy(rule,argv[pt]);
  162.           pt++;
  163.           continue;
  164.           }
  165.        if (!strcmp(argv[pt], "-I"))
  166.        {
  167.           pt++;
  168.           if (pt == argc) usage();
  169.           strcpy(index,argv[pt]);
  170.           pt++;
  171.           continue;
  172.           }
  173.        if (!strcmp(argv[pt], "-C"))
  174.        {
  175.           pt++;
  176.           if (pt == argc) usage();
  177.           cachesize = atoi(argv[pt]);
  178.           if (cachesize < 1) cachesize = 1;
  179.           pt++;
  180.           continue;
  181.           }
  182.        usage();
  183.        }
  184.  
  185.    initcache(cachesize);
  186.    initfile(dictionary);
  187.    initroot(rule);
  188.    
  189.    if (FAIL == readindex(index))
  190.    {
  191.       buildindex();
  192.       writeindex(index);
  193.       }
  194.  
  195.    /* check spelling for each file */
  196.    if (pt < argc)
  197.       while (pt < argc)
  198.       {
  199.           f = fopen(argv[pt],"rt");
  200.           if (f == NULL)
  201.           {
  202.               fprintf(stderr,"Unable to open file: %s\n",argv[pt]);
  203.               pt++;
  204.               continue;
  205.               }
  206.           checkspell(f);
  207.           fclose(f);
  208.           pt++;
  209.           }
  210.    else
  211.        checkspell(stdin);
  212.  
  213.    /* close down */
  214.    closefile();
  215.    fclose(fout);
  216.  
  217.    /* We have made the wordlist now sort it using systems provided sort */
  218.    strcpy(ssys, SORT);
  219.    strcat(ssys, " < ");
  220.    strcat(ssys, ftmp1);
  221.    strcat(ssys, " > ");
  222.    strcat(ssys, ftmp2);
  223.    system(ssys);
  224.    unlink(ftmp1);
  225.  
  226.    /* Output preventing duplication */
  227.    fout = fopen(ftmp2,"rt");
  228.    strcpy(tstr2,"");
  229.    while (!feof(fout))
  230.    {
  231.        if (fgets(tstr1,MAXSTR-1,fout)==NULL)
  232.           break;
  233.        if (strcmp(tstr1, tstr2))
  234.           printf("%s",tstr1);
  235.        strcpy(tstr2, tstr1);
  236.        }
  237.    fclose(fout);
  238.    unlink(ftmp2);
  239.    }
  240.  
  241.