Пример #1
0
struct ErrInfo *PushErr(const STRPTR Data, const ULONG Line,
                        const ULONG Column, const ULONG ErrLen,
                        const STRPTR LineCpy, struct Stack *Stk)
{
    struct ErrInfo      *ci;

    if((ci = malloc(sizeof(struct ErrInfo))))
    {
        if((ci->Data = strdup(Data)))
        {
            ci->File = CurStkName(&InputStack);
            ci->Line = Line;
            ci->ErrLen = ErrLen;
            ci->Column = Column;
            ci->LineBuf = LineCpy;
            ci->Flags = efNone;

            if(StkPush(ci, Stk))
                return(ci);
        }
        else
            PrintPrgErr(pmStrDupErr);
        free(ci);
    }

    return(NULL);
}
Пример #2
0
inline void InsertHash(const STRPTR a, struct Hash *h)
{
    struct HashEntry **he, *newhe;

    if(!h->Index)
    {
        ifn((h->Index = calloc(HASH_SIZE, sizeof(struct HashEntry *))))
        PrintPrgErr(pmWordListErr);
    }

    he = &h->Index[HashWord(a) % HASH_SIZE];

    if((newhe = malloc(sizeof(struct HashEntry))))
    {
        newhe->Next = *he;
        newhe->Str = a;
        *he = newhe;
    }
    else
        PrintPrgErr(pmWordListErr);
}
Пример #3
0
int PushFileName(const char *Name, struct Stack *stack)
{
    FILE *fh = NULL;
    static char NameBuf[BUFSIZ];

    if (Name && stack)
    {
        if (LocateFile(Name, NameBuf, ".tex", &TeXInputs))
        {
            if ((fh = fopen(NameBuf, "r")))
            {
                return (PushFile(NameBuf, fh, stack));
            }
        }
        PrintPrgErr(pmNoTeXOpen, Name);
    }
    return (FALSE);
}
Пример #4
0
char *FGetsStk(char *Dest, unsigned long len, struct Stack *stack)
{
    static short HasSeenLong = 0;
    struct FileNode *fn;
    char *Retval = NULL;
    size_t Retlen = 0;

    if ((fn = StkTop(stack)))
    {
        do
        {
            Retval = fgets(Dest, (int)len, fn->fh);
            if (Retval) {
                Retlen = strlen(Retval);

                if (Retval[Retlen-1] == '\n' || Retlen < len-1)
                    fn->Line++;
                /* We only want the long lines warning once per file */
                else if (!HasSeenLong)
                {
                    PrintPrgErr(pmLongLines, len-2);
                    HasSeenLong = 1;
                }
                break;
            }

            fn = StkPop(stack);
            fclose(fn->fh);
            /* Don't free the fn->Name field because it can be referenced in an
               error message */
            free(fn);
            HasSeenLong = 0;
        }
        while (!Retval && (fn = StkTop(stack)));
    }

    return (Retval);
}
Пример #5
0
BOOL PushFile(STRPTR Name, FILE *fh, struct Stack *stack)
{
    struct FileNode     *fn;

    if(Name && fh && stack)
    {
        if((fn = malloc(sizeof(struct FileNode))))
        {
            if((fn->Name = strdup(Name)))
            {
                fn->fh = fh;
                fn->Line = 0L;
                if(StkPush(fn, stack))
                    return(TRUE);
                free(fn->Name);
            }
            free(fn);
        }
        PrintPrgErr(pmNoStackMem);
    }

    return(FALSE);
}