[comp.text.tex] Spelling TeXing

mathas_a@maths.su.oz.au (andrew) (05/27/90)

To compile it use the command:
    cc -Oo prespell prespell.c
where you have dumped the code below into a file called 
"prespell.c". To use it type
    prespell < filename.tex | spell 
[If you're using csh, you can alias this nicely as:
    alias check 'prespell < \!*.tex | spell'
and then just type "check filename" ...]

Andrew            - who needs silly quotes anyway

#################################################################

#include <stdio.h>

#define WORDLENGTH 100
#define NOTFOUND -1

int instr(char s[], char t[]);
int readword(void);

main()
{
    int ch;   

    while ((ch = getchar()) != EOF)
    {
        if (ch == '\\')
            ch = readword();
        putchar(ch);
    }
        return 0;
}


int readword(void)
{
    int ch,i;
    char word[WORDLENGTH];

    for (i = 0; (word[i] = ch = getchar()) != EOF; i++)
    {
        if (ch == ' ' || ch == '\t')
            return ch = ' ';
        else if (ch == '\n')
            return ch;
        else if (ch == '{')
        {
            word[i+1] = '\0';
            if (instr("new", word) != NOTFOUND ||   
                instr("begin", word) != NOTFOUND || 
                instr("end", word) != NOTFOUND ||   
                instr("def", word) != NOTFOUND ||   
                instr("label", word) != NOTFOUND ||   
                instr("ref", word) != NOTFOUND ||   
                instr("cite", word) != NOTFOUND ||   
                instr("include", word) != NOTFOUND)
            {
                 while ((ch = getchar()) != EOF && ch != '}') 
                    ;
                return ch = ' ';
            }
        }
    }
    return ch = NULL;    
}

int instr(char s[], char t[])
{
    int spos, tpos;
        
    if (s[0] == '\0')
        return 0;
    
    for (tpos = 0; t[tpos] != '\0'; tpos++)
    {
        for (; s[0] != t[tpos] && t[tpos] != '\0'; tpos++)
            ;
        if (t[tpos] == '\0')
            return NOTFOUND;
        for (spos = 0; s[spos] == t[spos+tpos] && s[spos] != '\0' && t[spos+tpos] != '\0'; spos++)
            ;
        if (s[spos] == '\0')
            return tpos;
    }
    return NOTFOUND;
}                                                

mathas_a@maths.su.oz.au (andrew) (05/27/90)

   So yes, the code can be improved and tidied up, but I'll
Message-ID: <1990May27.032527.22410@metro.ucc.su.OZ.AU>
Date: 27 May 90 03:25:27 GMT
Sender: news@metro.ucc.su.OZ.AU (news)
Organization: Uni Computing Service, Uni of Sydney, Australia
Lines: 87

To compile it use the command:
    cc -Oo prespell prespell.c
where you have dumped the code below into a file called 
"prespell.c". To use it type
    prespell < filename.tex | spell 
[If you're using csh, you can alias this nicely as:
    alias check 'prespell < \!*.tex | spell'
and then just type "check filename" ...]

Andrew            - who needs silly quotes anyway

#################################################################

#include <stdio.h>

#define WORDLENGTH 100
#define NOTFOUND -1

int instr(char s[], char t[]);
int readword(void);

main()
{
    int ch;   

    while ((ch = getchar()) != EOF)
    {
        if (ch == '\\')
            ch = readword();
        putchar(ch);
    }
        return 0;
}


int readword(void)
{
    int ch,i;
    char word[WORDLENGTH];

    for (i = 0; (word[i] = ch = getchar()) != EOF; i++)
    {
        if (ch == ' ' || ch == '\t')
            return ch = ' ';
        else if (ch == '\n')
            return ch;
        else if (ch == '{')
        {
            word[i+1] = '\0';
            if (instr("new", word) != NOTFOUND ||   
                instr("begin", word) != NOTFOUND || 
                instr("end", word) != NOTFOUND ||   
                instr("def", word) != NOTFOUND ||   
                instr("label", word) != NOTFOUND ||   
                instr("ref", word) != NOTFOUND ||   
                instr("cite", word) != NOTFOUND ||   
                instr("include", word) != NOTFOUND)
            {
                 while ((ch = getchar()) != EOF && ch != '}') 
                    ;
                return ch = ' ';
            }
        }
    }
    return ch = NULL;    
}

int instr(char s[], char t[])
{
    int spos, tpos;
        
    if (s[0] == '\0')
        return 0;
    
    for (tpos = 0; t[tpos] != '\0'; tpos++)
    {
        for (; s[0] != t[tpos] && t[tpos] != '\0'; tpos++)
            ;
        if (t[tpos] == '\0')
            return NOTFOUND;
        for (spos = 0; s[spos] == t[spos+tpos] && s[spos] != '\0' && t[spos+tpos] != '\0'; spos++)
            ;
        if (s[spos] == '\0')
            return tpos;
    }
    return NOTFOUND;
}