#include <string>
#include <stdio.h>
#include <map>
#include <Base64.h>
#include <Uid.h>
#include <vector>
#include "rowo.h"
#include "robotworld.h"
Include dependency graph for parser.cpp:
Go to the source code of this file.
Functions | |
void | parse_file (const std::string &filename) |
const std::string & | GetCodestr () |
std::map< std::string, int > & | GetCodemap () |
std::vector< VARIABLE * > & | GetVariables () |
bool | GetFailed () |
std::string | GetMyUid () |
int | main (int argc, char *argv[]) |
std::map<std::string, int>& GetCodemap | ( | ) |
const std::string& GetCodestr | ( | ) |
bool GetFailed | ( | ) |
std::string GetMyUid | ( | ) |
Definition at line 18 of file parser.cpp.
References fil.
Referenced by main().
00019 { 00020 std::string myuid; 00021 FILE *fil; 00022 if ((fil = fopen("myuid.txt","rt")) != NULL) 00023 { 00024 char slask[1000]; 00025 fgets(slask,1000,fil); 00026 slask[strlen(slask) - 1] = 0; 00027 fclose(fil); 00028 myuid = slask; 00029 } 00030 else 00031 { 00032 Uid uid; 00033 myuid = uid.GetUid(); 00034 fil = fopen("myuid.txt","wt"); 00035 fprintf(fil,"%s\n",myuid.c_str()); 00036 fclose(fil); 00037 } 00038 return myuid; 00039 }
std::vector<VARIABLE *>& GetVariables | ( | ) |
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 41 of file parser.cpp.
References fil, GetCodemap(), GetCodestr(), GetFailed(), GetMyUid(), GetVariables(), and parse_file().
00042 { 00043 std::string myuid = GetMyUid(); 00044 00045 if (argc < 2) 00046 printf("Usage: %s <.r file(s)>\n",*argv); 00047 for (int i = 1; i < argc; i++) 00048 { 00049 std::string filename = argv[i]; 00050 unsigned char buf[10000]; 00051 if (filename.substr(filename.size() - 2) != ".r") 00052 { 00053 printf("'%s' is not a .r file\n",argv[i]); 00054 } 00055 else 00056 { 00057 std::string robot_name = filename.substr(0,filename.size() - 2); 00058 parse_file(argv[i]); 00059 00060 if (!GetFailed()) 00061 { 00062 size_t proglen = GetCodestr().size() / 2; 00063 for (size_t i = 0; i < GetCodestr().size(); i += 2) 00064 { 00065 char c1 = GetCodestr()[i]; 00066 char c2 = GetCodestr()[i + 1]; 00067 buf[i / 2] = (c1 - 48 - ((c1 > '9') ? 7:0) - ((c1 > 'F') ? 32:0)) * 16 + 00068 (c2 - 48 - ((c2 > '9') ? 7:0) - ((c2 > 'F') ? 32:0)); 00069 } 00070 Base64 bb; 00071 std::string codestr64; 00072 bb.encode(buf, proglen, codestr64, false); 00073 00074 // save robot xml 00075 FILE *fil; 00076 filename = robot_name + ".xml"; 00077 if ((fil = fopen(filename.c_str(),"wt")) != NULL) 00078 { 00079 fprintf(fil,"<?xml version='1.0'?>\n"); 00080 fprintf(fil,"<robot>\n"); 00081 fprintf(fil,"<name value='%s' />\n",robot_name.c_str()); 00082 fprintf(fil,"<owner value='%s' />\n",myuid.c_str()); 00083 fprintf(fil,"<code value=\"%s\" />\n",codestr64.c_str()); 00084 fprintf(fil,"<methods>\n"); 00085 for (std::map<std::string,int>::iterator it = GetCodemap().begin(); it != GetCodemap().end(); it++) 00086 { 00087 std::string method = (*it).first; 00088 int ptr = (*it).second; 00089 fprintf(fil,"<method name='%s' entry='%d' />\n",method.c_str(),ptr); 00090 } 00091 fprintf(fil,"</methods>\n"); 00092 fprintf(fil,"<variables>\n"); 00093 for (std::vector<VARIABLE *>::iterator it = GetVariables().begin(); it != GetVariables().end(); it++) 00094 { 00095 VARIABLE *p = *it; 00096 fprintf(fil,"<variable name='%s' type='%d' index='%d' />\n", 00097 p -> name.c_str(),p -> type,p -> nr); 00098 } 00099 fprintf(fil,"</variables>\n"); 00100 // 00101 fprintf(fil,"</robot>\n"); 00102 fclose(fil); 00103 } 00104 } // if (!failed) 00105 } 00106 } 00107 }
void parse_file | ( | const std::string & | filename | ) |
Definition at line 427 of file rowo.cpp.
References codemap, codestr, failed, fil, line, the_ptr, the_str, uniq, variables, and yyparse().
Referenced by main().
00428 { 00429 *the_str = 0; 00430 the_ptr = 0; 00431 line = 0; 00432 uniq = 1; 00433 codestr = ""; 00434 failed = false; 00435 while (codemap.size()) 00436 { 00437 codemap.erase(codemap.begin()); 00438 } 00439 while (variables.size()) 00440 { 00441 variables.erase(variables.begin()); 00442 } 00443 if ((fil = fopen(filename.c_str(), "rt")) != NULL) 00444 { 00445 yyparse(); 00446 fclose(fil); 00447 } 00448 else 00449 { 00450 fprintf(stderr, "Couldn't open '%s'...\n", filename.c_str()); 00451 failed = true; 00452 } 00453 }