MKDIR(get_out_dir().c_str());
string outdir = get_out_dir();
- std::string ns = program_->get_perl_package();
- if (ns.length() > 0) {
- outdir += ns + "/";
- MKDIR(outdir.c_str());
+ std::list<std::string> dirs;
+ perl_namespace_dirs(program_, dirs);
+ std::list<std::string>::iterator it;
+ for (it = dirs.begin(); it != dirs.end(); it++) {
+ outdir += *it + "/";
+ MKDIR(outdir.c_str());
}
// Make output file
// Print header
f_consts_ <<
autogen_comment() <<
- "package "<<( ns.empty() ? "" : ns+"::")<<"Constants;"<<endl<<
+ "package "<< perl_namespace(program_) <<"Constants;"<<endl<<
perl_includes() <<
endl;
}
#include <fstream>
#include <iostream>
#include <vector>
+#include <list>
#include "t_oop_generator.h"
"#\n";
}
+ void perl_namespace_dirs(t_program* p, std::list<std::string>& dirs) {
+ std::string ns = p->get_perl_package();
+ std::string::size_type loc;
+
+ if (ns.size() > 0) {
+ while ((loc = ns.find(".")) != std::string::npos) {
+ dirs.push_back(ns.substr(0, loc));
+ ns = ns.substr(loc+1);
+ }
+ }
+
+ if (ns.size() > 0) {
+ dirs.push_back(ns);
+ }
+ }
+
std::string perl_namespace(t_program* p) {
std::string ns = p->get_perl_package();
- return ns.empty() ? ns : (ns + "::");
+ std::string result = "";
+ std::string::size_type loc;
+
+ if (ns.size() > 0) {
+ while ((loc = ns.find(".")) != std::string::npos) {
+ result += ns.substr(0, loc);
+ result += "::";
+ ns = ns.substr(loc+1);
+ }
+
+ if (ns.size() > 0) {
+ result += ns + "::";
+ }
+ }
+
+ return result;
}
private: