enclose code and testfile.

Gary Kline kline at thought.org
Sun Jun 7 01:22:06 UTC 2009


	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  kline at thought.org  http://www.thought.org  Public Service Unix
        http://jottings.thought.org   http://transfinite.thought.org
       For FBSD list: http://transfinite.thought.org/slicejourney.php



More information about the freebsd-questions mailing list