Date: Sat, 6 Jun 2009 18:22:00 -0700 From: Gary Kline <kline@thought.org> To: FreeBSD Mailing List <freebsd-questions@FreeBSD.ORG> Subject: enclose code and testfile. Message-ID: <20090607012158.GA14286@thought.org>
next in thread | raw e-mail | index | archive | help
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@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090607012158.GA14286>
