#include <stdio.h>
#include <string>
#include <sys/types.h>
#include <dirent.h>
#include <vector>
#include <sys/stat.h>
#include <unistd.h>
#include <map>
#include "Parse.h"
#include "Token.h"
#include "MyParser.h"
#include "mydp.h"
#include "Scope.h"
Include dependency graph for mydp.cpp:
Go to the source code of this file.
Namespaces | |
namespace | ugly |
Defines | |
#define | DEB(x) |
Functions | |
void | read_makefile () |
void | print_parent (Scope *p) |
void | class_recursive (Scope *root) |
void | class_hierarchy (Scope *root) |
void | parse_file (const std::string &path, const std::string &filename) |
int | main (int argc, char *argv[]) |
Variables | |
config_m | config |
std::string | includes = "" |
|
File ......... mydp.cpp Published .... 2004-05-17 Author ....... grymse@alhem.net |
|
Definition at line 170 of file mydp.cpp. References class_recursive(). Referenced by parse_file().
00171 { 00172 class_recursive(root); 00173 } |
|
Definition at line 93 of file mydp.cpp. References Class, print_parent(), and Template. Referenced by class_hierarchy().
00094 { 00095 sequence_v::iterator it = root -> ScopeBegin(); 00096 Token *t = root -> GetFirstToken(); 00097 00098 if (t) 00099 { 00100 if (t -> GetCode() == Class) 00101 { 00102 print_parent( root -> GetParent() ); 00103 root -> Tab(); 00104 printf("%s",root -> GetExpr().c_str()); 00105 if (root -> IsExtern()) 00106 printf(" <extern>"); 00107 printf("\n"); 00108 root -> Tab(); 00109 printf("\tFile: %s:%d\n",root -> GetFile().c_str(),root -> GetLine()); 00110 printf("\n"); 00111 } 00112 else 00113 if (t -> GetCode() == Template) 00114 { 00115 token_v::iterator it = root -> Begin(); 00116 int lvl = 0; 00117 while (it != root -> End()) 00118 { 00119 Token *t = *it; 00120 if (t) 00121 { 00122 if (t -> GetCode() == '<') 00123 lvl++; 00124 else 00125 if (t -> GetCode() == '>') 00126 lvl--; 00127 else 00128 { 00129 if (!lvl && it != root -> Begin()) 00130 { 00131 if (t -> GetCode() == Class) 00132 { 00133 print_parent( root -> GetParent() ); 00134 root -> Tab(); 00135 printf("%s",root -> GetExpr().c_str()); 00136 if (root -> IsExtern()) 00137 printf(" <extern>"); 00138 printf("\n"); 00139 root -> Tab(); 00140 printf("\tFile: %s:%d\n",root -> GetFile().c_str(),root -> GetLine()); 00141 printf("\n"); 00142 } 00143 else 00144 { 00145 } 00146 break; 00147 } 00148 } 00149 } 00150 // 00151 it++; 00152 } 00153 } 00154 } 00155 00156 while (it != root -> ScopeEnd()) 00157 { 00158 Sequence *p = *it; 00159 Scope *scope = dynamic_cast<Scope *>(p); 00160 if (scope) 00161 { 00162 class_recursive( scope ); 00163 } 00164 // 00165 it++; 00166 } 00167 } |
|
Definition at line 241 of file mydp.cpp. References config, includes, parse_file(), and read_makefile().
00242 { 00243 char *args[] = {"-disp","-xml","-cpp",""}; 00244 read_makefile(); 00245 if (includes.size()) 00246 fprintf(stderr,"Using include path(s): %s\n",includes.c_str()); 00247 if (argc == 1) 00248 { 00249 fprintf(stderr,"Usage: %s [-cpp] [-disp] [-xml] file(s)\n",*argv); 00250 fprintf(stderr," -cpp Don't use cpp precompiler\n"); 00251 fprintf(stderr," -disp View parsed and formatted source code\n"); 00252 fprintf(stderr," -xml View parsed code as xml\n"); 00253 return 0; 00254 } 00255 for (int i = 1; i < argc; i++) 00256 { 00257 bool ok = false; 00258 bool more = false; 00259 int x = 0; 00260 while (*args[x]) 00261 { 00262 if (!strcmp(argv[i],args[x])) 00263 { 00264 ok = true; 00265 // check for more 00266 break; 00267 } 00268 else 00269 { 00270 x++; 00271 } 00272 } 00273 if (ok) 00274 { 00275 if (more) 00276 { 00277 config[argv[i]] = argv[i + 1]; 00278 i++; 00279 } 00280 else 00281 { 00282 config[argv[i]] = "true"; 00283 } 00284 } 00285 else 00286 { 00287 parse_file(".", argv[i]); 00288 } 00289 } 00290 } |
|
Definition at line 176 of file mydp.cpp. References class_hierarchy(), config, DEB, includes, and MyParser::Parser(). Referenced by main().
00177 { 00178 std::string cmd; 00179 std::string out; 00180 if (config["-cpp"] != "true") 00181 { 00182 out = path + "/" + filename + ".preprocessed"; 00183 cmd = "/usr/bin/cpp" 00184 " -C" 00185 " " + includes + 00186 " " + path + "/" + filename + " > " + out; 00187 fprintf(stderr,"%s\n", cmd.c_str()); 00188 if (system( cmd.c_str() ) == -1) 00189 { 00190 DEB( fprintf(stderr,"Command failed: '%s'...\n",cmd.c_str());) 00191 return; 00192 } 00193 } 00194 else 00195 { 00196 out = path + "/" + filename + ".preprocessed"; 00197 cmd = "cat" 00198 " " + path + "/" + filename + " > " + out; 00199 fprintf(stderr,"%s\n", cmd.c_str()); 00200 if (system( cmd.c_str() ) == -1) 00201 { 00202 DEB( fprintf(stderr,"Command failed: '%s'...\n",cmd.c_str());) 00203 return; 00204 } 00205 } 00206 00207 FILE *fil = fopen(out.c_str(),"rt"); 00208 if (fil) 00209 { 00210 MyParser p(path); 00211 std::string name; 00212 Scope *result; 00213 name = path + "/"; 00214 name += filename; 00215 result = p.Parser(fil,name); 00216 fclose(fil); 00217 unlink(out.c_str()); 00218 // 00219 if (config["-xml"] == "true") 00220 { 00221 printf("<?xml version=\"1.0\"?>\n"); 00222 printf("<code>\n"); 00223 result -> Display(); 00224 printf("</code>\n"); 00225 } 00226 else 00227 if (config["-disp"] == "true") 00228 result -> Display(); 00229 else 00230 class_hierarchy( result ); 00231 delete result; 00232 } 00233 else 00234 { 00235 fprintf(stderr,"Couldn't open '%s'...\n",filename.c_str()); 00236 return; 00237 } 00238 } |
|
Definition at line 80 of file mydp.cpp. Referenced by class_recursive().
00081 { 00082 if (!p) 00083 return; 00084 if (p -> GetParent()) 00085 { 00086 print_parent(p -> GetParent()); 00087 p -> Tab(); 00088 printf("%s\n",p -> GetExpr().c_str()); 00089 } 00090 } |
|
Definition at line 50 of file mydp.cpp. References Parse::getword(), and includes.
00051 { 00052 FILE *fil; 00053 if ((fil = fopen("Makefile","rt")) != NULL) 00054 { 00055 char slask[1000]; 00056 fgets(slask,1000,fil); 00057 while (!feof(fil)) 00058 { 00059 Parse pa(slask); 00060 strcpy(slask,pa.getword().c_str()); 00061 while (*slask) 00062 { 00063 if (!strncmp(slask,"-I",2)) 00064 { 00065 if (includes.size()) 00066 includes += " "; 00067 includes += slask; 00068 } 00069 // 00070 strcpy(slask,pa.getword().c_str()); 00071 } 00072 // 00073 fgets(slask,1000,fil); 00074 } 00075 fclose(fil); 00076 } 00077 } |
|
|
|
|