gokernel
(usa Linux Mint)
Enviado em 16/04/2010 - 17:52h
Depois de muitas tentativas...
E obrigado pela intenção de ajudar.
O CODIGO LEGIVEL AQUI, ARQUIVO(functions.c):
http://www.4shared.com/account/dir/24056491/7a5bc050/sharing.html?rnd=93
THE CODE:
//-------------------------------------------------------------------
//
// Demonstracao programa... extraindo funcoes em uma STRING.
//
// E GLORIA A DEUS EM CRISTO JESUS.
//
// BY: gokernel - gokernel@hotmail.com
//-------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
char *text_code =
"//########################################################\n"
"void func1 (int v) {\n"
" for(v=1; v < 10; v++){\n"
" }\n"
"}\n"
"\nint funcao_segunda (void){\n"
" return 0;\n"
"}\n"
"\nvoid terceira ()\n"
"{\n"
" int c;\n"
" for (c=1; c<10; c++) {\n"
"\n"
" }\n"
"}\n"
"\nint main (int argc, char *argv[]) {\n"
"\n"
" return 0;\n"
"}\n"
"//########################################################\n";
void display_func_in_code(){
char *find = text_code;
for(;;){
find = strstr (find, "{");
if(find){
int pos = strlen(text_code) - strlen(find);
int backup = pos;
char *text = text_code;
if(text_code[pos-1]==')' || // "){"
text_code[pos-2]==')' // ") {" or ")\n{"
){
int v=0;
char *str = find;
while(*str){
if(*str=='{') v++;
if(*str=='}') v--;
if(v==0) { find = str; break; }
*str++;
}
v=0;
while(text[pos]){
if(text[pos]=='(') v=1;
if(v && text[pos]=='\n'){ // The start of line
//------------------------------------------------------
// AQUI EU ADICIONARIA EM UM MENU... AGORA EH COMIGO :).
//------------------------------------------------------
for(v=pos; v!=backup+1; v++){
if(text[v] != '\n')
printf("%c", text[v]);
}
printf("\n");
break;
}
pos--;
}
}
find++;
}
else break;
}
}
int main (void) {
printf("\nEXIBINDO O CODIGO DE UM PROGRAMA\n");
printf(text_code);
printf("\nEXIBINDO TODAS AS FUNCOES NO CODIGO\n");
printf("----------------------------------------\n");
display_func_in_code();
printf("----------------------------------------\n");
return 0;
}