Guys, 

        I'm encloseing a brief C program that skips over php delimiters and a
        74-byte test file.  After gdb "reminded" me that it eats the last byte, 
        I was able to complete this.  Am wondering if there is a better way.
        Obv'ly there are other way to get past "<?" and "?>"; but this was 
        already half-written.

// dephp.c

#include <stdio.h>

int
main(int argc, char *argv[])   // use: ./a.out testfile
{
        FILE *fp;

        *argv++;
        if ((fp = fopen(*argv, "r")) ==NULL)
                printf("[%s] not found\n", *argv);
        else
                foo(fp);
}

/*
 * read past any php <? and ?>
 */
int
foo (FILE *fp)
{
        int ch, ch2, ch3, ch4;

        while (( ch = getc(fp)) != EOF)
        {

                if (ch == '<' && (ch3 = getc(fp)) == '?')
                {
                        while ((ch2  = getc(fp)) != '?')
                        {
                                continue;
                        }

                        if (ch2 == '?' && (ch4 = getc(fp)) == '>')
                        {
                        }
                }
                else
                {
                        putchar (ch);
                }
        }
        return 0;
}
// the testfile:  
foo
bar
<?
baz
?>

blah, blah 
<
>
blah, blah
end of html src file HERE.

-- 
 Gary Kline  [email protected]  http://www.thought.org  Public Service Unix
        http://jottings.thought.org   http://transfinite.thought.org
       For FBSD list: http://transfinite.thought.org/slicejourney.php

_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[email protected]"

Reply via email to