Esempio n. 1
0
void
AsCountTabs (
    char                    *Buffer,
    char                    *Filename)
{
    UINT32                  i;
    UINT32                  TabCount = 0;


    for (i = 0; Buffer[i]; i++)
    {
        if (Buffer[i] == '\t')
        {
            TabCount++;
        }
    }

    if (TabCount)
    {
        AsPrint ("Tabs found", TabCount, Filename);
        Gbl_Tabs += TabCount;
    }

    AsCountLines (Buffer, Filename);
}
void
AsCountNonAnsiComments (
    char                    *Buffer,
    char                    *Filename)
{
    char                    *SubBuffer = Buffer;
    UINT32                  CommentCount = 0;


    while (SubBuffer)
    {
        SubBuffer = strstr (SubBuffer, "//");
        if (SubBuffer)
        {
            CommentCount++;
            SubBuffer += 2;
        }
    }

    if (CommentCount)
    {
        AsPrint ("Non-ANSI Comments found", CommentCount, Filename);
        Gbl_NonAnsiComments += CommentCount;
    }
}
Esempio n. 3
0
void
AsTrimLines (
    char                    *Buffer,
    char                    *Filename)
{
    char                    *SubBuffer = Buffer;
    char                    *StartWhiteSpace = NULL;
    UINT32                  SpaceCount = 0;


    while (*SubBuffer)
    {
        while (*SubBuffer != '\n')
        {
            if (!*SubBuffer)
            {
                goto Exit;
            }

            if (*SubBuffer == ' ')
            {
                if (!StartWhiteSpace)
                {
                    StartWhiteSpace = SubBuffer;
                }
            }
            else
            {
                StartWhiteSpace = NULL;
            }

            SubBuffer++;
        }

        if (StartWhiteSpace)
        {
            SpaceCount += (SubBuffer - StartWhiteSpace);

            /* Remove the spaces */

            SubBuffer = AsRemoveData (StartWhiteSpace, SubBuffer);
            StartWhiteSpace = NULL;
        }

        SubBuffer++;
    }


Exit:
    if (SpaceCount)
    {
        Gbl_MadeChanges = TRUE;
        AsPrint ("Extraneous spaces removed", SpaceCount, Filename);
    }
}
Esempio n. 4
0
void
AsCountNonAnsiComments (
    char                    *Buffer,
    char                    *Filename)
{

    AsMatchValidToken (Buffer, Filename, 0, NULL);

    /* Error if any slash-slash comments found */

    if (NonAnsiCommentCount)
    {
        AsPrint ("Non-ANSI // Comments Found", NonAnsiCommentCount, Filename);
        Gbl_NonAnsiComments += NonAnsiCommentCount;
    }
}
Esempio n. 5
0
static char *
AsMatchValidToken (
    char                    *Buffer,
    char                    *Filename,
    char                    TargetChar,
    AS_SCAN_CALLBACK        Callback)
{
    char                    *SubBuffer = Buffer;
    char                    *StringStart;
    UINT32                  TotalLines;


    TotalLines = 1;
    NonAnsiCommentCount = 0;

    /* Scan from current position up to the end if necessary */

    while (*SubBuffer)
    {
        /* Skip normal comments */

        if ((*SubBuffer == '/') &&
            (*(SubBuffer + 1) == '*'))
        {
            /* Must maintain line count */

            SubBuffer += 2;
            while (strncmp ("*/", SubBuffer, 2))
            {
                if (*SubBuffer == '\n')
                {
                    TotalLines++;
                }
                SubBuffer++;
            }

            SubBuffer += 2;
            continue;
        }

        /* Skip single quoted chars */

        if (*SubBuffer == '\'')
        {
            SubBuffer++;
            if (!(*SubBuffer))
            {
                break;
            }

            if (*SubBuffer == '\\')
            {
                SubBuffer++;
            }

            SubBuffer++;
            continue;
        }

        /* Skip quoted strings */

        if (*SubBuffer == '"')
        {
            StringStart = SubBuffer;
            SubBuffer++;
            if (!(*SubBuffer))
            {
                break;
            }

            while (*SubBuffer != '"')
            {
                if ((*SubBuffer == '\n') ||
                    (!(*SubBuffer)))
                {
                    AsPrint ("Unbalanced quoted string",1, Filename);
                    printf ("    %.32s (line %u)\n", StringStart, TotalLines);
                    break;
                }

                /* Handle escapes within the string */

                if (*SubBuffer == '\\')
                {
                    SubBuffer++;
                }

                SubBuffer++;
            }

            SubBuffer++;
            continue;
        }

        /* Now we can check for a slash-slash comment */

        if ((*SubBuffer == '/') &&
            (*(SubBuffer + 1) == '/'))
        {
            NonAnsiCommentCount++;

            /* Skip to end-of-line */

            while ((*SubBuffer != '\n') &&
                (*SubBuffer))
            {
                SubBuffer++;
            }

            if (!(*SubBuffer))
            {
                break;
            }

            if (*SubBuffer == '\n')
            {
                TotalLines++;
            }

            SubBuffer++;
            continue;
        }

        /* Finally, check for a newline */

        if (*SubBuffer == '\n')
        {
            TotalLines++;
            SubBuffer++;
            continue;
        }

        /* Normal character, do the user actions */

        if (Callback)
        {
            SubBuffer = Callback (SubBuffer, Filename, TotalLines);
        }

        if (TargetChar && (*SubBuffer == TargetChar))
        {
            return (SubBuffer);
        }

        SubBuffer++;
    }

    return (NULL);
}
Esempio n. 6
0
void
AsTrimComments (
    char                    *Buffer,
    char                    *Filename)
{
    char                    *SubBuffer = Buffer;
    char                    *Ptr1;
    char                    *Ptr2;
    UINT32                  LineCount;
    UINT32                  ShortCommentCount = 0;


    while (1)
    {
        /* Find comment open, within procedure level */

        SubBuffer = strstr (SubBuffer, "    /*");
        if (!SubBuffer)
        {
            goto Exit;
        }

        /* Find comment terminator */

        Ptr1 = strstr (SubBuffer, "*/");
        if (!Ptr1)
        {
            goto Exit;
        }

        /* Find next EOL (from original buffer) */

        Ptr2 = strstr (SubBuffer, "\n");
        if (!Ptr2)
        {
            goto Exit;
        }

        /* Ignore one-line comments */

        if (Ptr1 < Ptr2)
        {
            /* Normal comment, ignore and continue; */

            SubBuffer = Ptr2;
            continue;
        }

        /* Examine multi-line comment */

        LineCount = 1;
        while (Ptr1 > Ptr2)
        {
            /* Find next EOL */

            Ptr2++;
            Ptr2 = strstr (Ptr2, "\n");
            if (!Ptr2)
            {
                goto Exit;
            }

            LineCount++;
        }

        SubBuffer = Ptr1;

        if (LineCount <= 3)
        {
            ShortCommentCount++;
        }
    }


Exit:

    if (ShortCommentCount)
    {
        AsPrint ("Short Comments found", ShortCommentCount, Filename);
    }
}
Esempio n. 7
0
void
AsRemoveEmptyBlocks (
    char                    *Buffer,
    char                    *Filename)
{
    char                    *SubBuffer;
    char                    *BlockStart;
    BOOLEAN                 EmptyBlock = TRUE;
    BOOLEAN                 AnotherPassRequired = TRUE;
    UINT32                  BlockCount = 0;


    while (AnotherPassRequired)
    {
        SubBuffer = Buffer;
        AnotherPassRequired = FALSE;

        while (*SubBuffer)
        {
            if (*SubBuffer == '{')
            {
                BlockStart = SubBuffer;
                EmptyBlock = TRUE;

                SubBuffer++;
                while (*SubBuffer != '}')
                {
                    if ((*SubBuffer != ' ') &&
                        (*SubBuffer != '\n'))
                    {
                        EmptyBlock = FALSE;
                        break;
                    }
                    SubBuffer++;
                }

                if (EmptyBlock)
                {
                    /* Find start of the first line of the block */

                    while (*BlockStart != '\n')
                    {
                        BlockStart--;
                    }

                    /* Find end of the last line of the block */

                    SubBuffer = AsSkipUntilChar (SubBuffer, '\n');
                    if (!SubBuffer)
                    {
                        break;
                    }

                    /* Remove the block */

                    SubBuffer = AsRemoveData (BlockStart, SubBuffer);
                    BlockCount++;
                    AnotherPassRequired = TRUE;
                    continue;
                }
            }

            SubBuffer++;
        }
    }

    if (BlockCount)
    {
        Gbl_MadeChanges = TRUE;
        AsPrint ("Code blocks deleted", BlockCount, Filename);
    }
}