summaryrefslogtreecommitdiff
path: root/server/src/resumeparser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/resumeparser.cc')
-rw-r--r--server/src/resumeparser.cc122
1 files changed, 24 insertions, 98 deletions
diff --git a/server/src/resumeparser.cc b/server/src/resumeparser.cc
index 37b36f4..c80c2f0 100644
--- a/server/src/resumeparser.cc
+++ b/server/src/resumeparser.cc
@@ -31,110 +31,36 @@
#include "luaresume.h"
#include "configuration.h"
-static std::string resume_parser_format(Resume &r, Commit &commit)
+std::string resume_parser(Macro &macro, Commit &commit)
{
- const char* format = r.attributes["format"].c_str();
-
- std::string resume;
- std::string var;
+ LUAResume luaresume(commit);
- const char *p = format;
- const char *theend = p + strlen(format);
- while(p < theend) {
- switch(*p) {
- case '$':
- p++;
- switch(*p) {
- case '$':
- resume.append(1, *p);
- break;
+ std::string code;
- case '{':
- p++;
- var = "";
- // Parser
- while(p < theend && *p != '}') {
- var.append(1, *p);
- p++;
+ std::vector< Script >::iterator spi = macro.resume_scripts.begin();
+ while(spi != macro.resume_scripts.end()) {
+ if(spi->attributes.find("src") != spi->attributes.end()) {
+ std::string src = spi->attributes["src"];
+ std::string file =
+ Conf::xml_basedir + "/include/" + src;
+ FILE *fp = fopen(file.c_str(), "r");
+ if(fp) {
+ char buf[64];
+ size_t sz;
+ std::string inc;
+ while((sz = fread(buf, 1, sizeof(buf), fp)) != 0) {
+ inc.append(buf, sz);
}
- // p++;
- //printf("[%s]\n", var.c_str());
- // resume += "var(" + var + ")";
- resume += commit.fields[var];
- break;
-
- default:
- resume.append(1, *p);
- // printf("Illigal $ command\n");
- break;
- }
- p++;
- break;
-
- case '\\':
- p++;
- switch(*p) {
- case 't':
- resume.append(1, '\t');
- break;
- case 'n':
- resume.append(1, '\n');
- break;
- case 'r':
- resume.append(1, '\r');
- break;
- case '\\':
- default:
- resume.append(1, *p);
- break;
+ fclose(fp);
+ code += "\n-- BEGIN INCLUDE: '" + src + "'\n";
+ code += inc;
+ code += "\n-- END INCLUDE: '" + src + "'\n";
}
- p++;
- break;
-
- default:
- resume.append(1, *p);
- p++;
- break;
+ } else {
+ code += spi->code;
}
+ spi++;
}
- return resume;
-}
-
-static std::string resume_parser_lua(Macro &macro, Commit &commit)
-{
- LUAResume luaresume(commit);
- std::string lua;
- /*
- std::vector< ScriptInclude >::iterator spii =
- macro.script_includes.begin();
- while(spii != macro.script_includes.end()) {
- std::string file =
- Conf::xml_basedir + "/include/" + spii->attributes["file"];
- FILE *fp = fopen(file.c_str(), "r");
- if(fp) {
- char buf[64];
- size_t sz;
- std::string inc;
- while((sz = fread(buf, 1, sizeof(buf), fp)) != 0) {
- lua.append(buf, sz);
- }
- fclose(fp);
- }
- spii++;
- }
- */
- lua += macro.resume.attributes["format"];
-
- return luaresume.run(lua);
-}
-
-std::string resume_parser(Macro &macro, Commit &commit)
-{
- if(macro.resume.attributes["language"] == "lua") {
- return resume_parser_lua(macro, commit);
- }
-
- // Default to pracro format language.
- return resume_parser_format(macro.resume, commit);
+ return luaresume.run(code);
}