Richard Lynch wrote:

>KHS wrote:
>
>  
>
>>Here is an example of the input:
>>#include FT_FREETYPE_H
>>#include <stdio.h>
>>#include "freetype/freetype.h"
>>
>>Here is a snip of my code:
>>$line = fgets($fp);
>>$line = trim($line);
>>$regexp = '^#include(:? | "| <)([^< >"]+)[> "]';
>>//$regexp = '^#include( <| "| )[^< >"]+[> "]'; //Same result as above
>>//$regexp = '^#include [< "]([^>" ]+)[> "]'; //Similar to above result
>>ereg($regexp, $line, $inclistings);
>>var_dump($inclistings);
>>
>>Here is the output I am getting:
>>#include FT_FREETYPE_H
>>
>>#include <stdio.h>
>>array(3) {
>>  [0]=>
>>  string(18) "#include <stdio.h>"
>>  [1]=>
>>  string(2) " <"
>>  [2]=>
>>  string(7) "stdio.h"
>>}
>>
>>#include "freetype/freetype.h"
>>array(3) {
>>  [0]=>
>>  string(30) "#include "freetype/freetype.h""
>>  [1]=>
>>  string(2) " ""
>>  [2]=>
>>  string(19) "freetype/freetype.h"
>>}
>>
>>Here is the output I want:
>>#include FT_FREETYPE_H
>>array(3) {
>>  [0]=>
>>  string(?) "#include FT_FREETYPE_H"
>>  [1]=>
>>  string(?) "FT_FREETYPE_H"
>>}
>>
>>#include <stdio.h>
>>array(3) {
>>  [0]=>
>>  string(18) "#include <stdio.h>"
>>  [1]=>
>>  string(7) "stdio.h"
>>}
>>
>>#include "freetype/freetype.h"
>>array(3) {
>>  [0]=>
>>  string(30) "#include "freetype/freetype.h""
>>  [1]=>
>>  string(19) "freetype/freetype.h"
>>}
>>
>>So how do I keep ereg() from thinking the first set of parentheses
>>is a substring to export. In addition, how do I craft the $regexp to
>>recognize the first input $line? I came up with the above $regexp lines
>>by using kregexpeditor in kde.
>>    
>>
>
>I think if you wrap an extra parentheses around the whole mess, you'll get
>what you want...  But that might only be with preg and friends...
>
>  
>
Tried that with no success.

>On the other hand, I think you could safely do:
>
>$regex = "^#include(.*)$";
>
>and get what you want by using trim on the captured expression.
>
>  
>
no this would leave me with <, >, and " marks.

>Unless you're trying to make sure it's kosher C syntax, as well as snag
>the included thing...
>
>  
>
I just want to extract the file name.

>Even then, you might be better off doing the above, and *THEN* deciding if
>the thing after #include is kosher or not.
>
>  
>
This is how I pick what lines to scan for extraction:
if((stristr($line, '#include')) === false){ //Search for "#include" in $line
    continue;
}

>Separting the capture of the text, from validating that it's kosher text
>can simplify your life immensely sometimes, even if it's "more code" to
>type.
>
>  
>
My script will only find '#include' statements.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to