-/* ------------------------------------------------\r
-Copyright 2014 AT&T Intellectual Property\r
- Licensed under the Apache License, Version 2.0 (the "License");\r
- you may not use this file except in compliance with the License.\r
- You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
- ------------------------------------------- */\r
-\r
-#include "parse_fta.h"\r
-#include "parse_schema.h"\r
-#include"generate_utils.h"\r
-\r
-#include <string>\r
-#include<set>\r
-\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <unistd.h>\r
-\r
-#include<errno.h>\r
-\r
-#define TMPSTRLEN 1000\r
-\r
-#ifndef PATH_DELIM\r
- #define PATH_DELIM '/'\r
-#endif\r
-\r
-char tmp_schema_str[10000];\r
-\r
-// Interface to FTA definition lexer and parser ...\r
-\r
-extern int FtaParserparse(void);\r
-extern FILE *FtaParserin;\r
-extern int FtaParserdebug;\r
-\r
-fta_parse_t *fta_parse_result;\r
-var_defs_t *fta_parse_defines;\r
-\r
-\r
-\r
-using namespace std;\r
-\r
-\r
-\r
-\r
-int main(int argc, char **argv){\r
- int s,t,f;\r
- char tmpstr[TMPSTRLEN];\r
-\r
-\r
-\r
-// set these to 1 to debug the parser\r
- FtaParserdebug = 0;\r
-\r
- FILE *table_schemas_in; // source tables definition file\r
-\r
- // -------------------------------\r
- // Handling of Input Arguments\r
- // -------------------------------\r
- const char *optstr = "C:";\r
- const char *usage_str = "Usage: %s [-C <config directory>] schema_file [operator name ...]\n"\r
- "\t[-C] : use <config directory> for definition files\n";\r
-\r
-\r
-// parameters gathered from command line processing\r
- string config_dir_path;\r
- set<string> operator_names;\r
- string schema_file_name;\r
-\r
- char chopt;\r
- while((chopt = getopt(argc,argv,optstr)) != -1){\r
- switch(chopt){\r
- case 'C':\r
- if(optarg != NULL)\r
- config_dir_path = string(optarg) + string("/");\r
- break;\r
- case '?':\r
- fprintf(stderr,"Error, argument %c not recognized.\n",optopt);\r
- fprintf(stderr,"%s\n", usage_str);\r
- exit(1);\r
- default:\r
- fprintf(stderr,"Invalid arguments\n");\r
- fprintf(stderr,"%s\n", usage_str);\r
- exit(1);\r
- }\r
- }\r
- argc -= optind;\r
- argv += optind;\r
- for (int i = 0; i < argc; ++i) {\r
- if(schema_file_name == ""){\r
- schema_file_name = argv[i];\r
- }else{\r
- operator_names.insert(argv[i]);\r
- }\r
- }\r
-\r
- if(schema_file_name == ""){\r
- fprintf(stderr,"%s\n", usage_str);\r
- exit(1);\r
- }\r
-\r
-\r
-// Open globally used file names.\r
-\r
- // prepend config directory to schema file\r
- schema_file_name = config_dir_path + schema_file_name;\r
-\r
- if((table_schemas_in = fopen(schema_file_name.c_str(), "r")) == NULL) {\r
- fprintf(stderr,"Can't open schema file %s\n%s\n",schema_file_name.c_str(),strerror(errno));\r
- exit(1);\r
- }\r
-\r
-\r
-\r
-\r
-// Get an initial Schema\r
- table_list *Schema;\r
-// Parse the table schema definitions.\r
- fta_parse_result = new fta_parse_t();\r
- FtaParser_setfileinput(table_schemas_in);\r
- if(FtaParserparse()){\r
- fprintf(stderr,"Table schema parse failed.\n");\r
- exit(1);\r
- }\r
- if(fta_parse_result->parse_type != TABLE_PARSE){\r
- fprintf(stderr,"ERROR, file %s is not a table definition file.\n",schema_file_name.c_str());\r
- exit(1);\r
- }\r
- Schema = fta_parse_result->tables;\r
-\r
-// Process schema field inheritance\r
- string err_str;\r
- int retval;\r
- retval = Schema->unroll_tables(err_str);\r
- if(retval){\r
- fprintf(stderr,"Error processing schema filed inheritance:\n %s\n", err_str.c_str() );\r
- exit(1);\r
- }\r
-\r
-// Open header, code files\r
-\r
- FILE *hdr_fl = fopen("operator_tuple_pack.h", "w");\r
- if(hdr_fl == NULL){\r
- fprintf(stderr,"Can't open output header file operator_tuple_pack.h\n%s\n",strerror(errno));\r
- exit(1);\r
- }\r
- FILE *code_fl = fopen("operator_tuple_pack.cc", "w");\r
- if(code_fl == NULL){\r
- fprintf(stderr,"Can't open output code file operator_tuple_pack.c\n%s\n",strerror(errno));\r
- exit(1);\r
- }\r
-\r
-\r
-\r
-\r
-\r
-// Generate code for the accessing the operator tuples.\r
-\r
- string header =\r
-"#ifndef __OPERATOR_TUPLE_PACK__\n"\r
-"#define __OPERATOR_TUPLE_PACK__\n"\r
-"\n"\r
-"#include \"host_tuple.h\"\n"\r
-"#include \"vstring.h\"\n"\r
-"#include \"byteswap.h\""\r
-"\n"\r
-"void *unpack_operator_params(void *buf, int buflen, char **param_list, int plist_len, int *params_found);\n"\r
-"\n"\r
-"\n";\r
-\r
- string code =\r
-"#include \"operator_tuple_pack.h\"\n"\r
-"#include <sys/param.h>\n"\r
-"#include \"fta.h\"\n"\r
-"#include \"lapp.h\"\n"\r
-"#include \"hfta_runtime_library.h\"\n"\r
-"\n"\r
-"void *unpack_operator_params(void *buf, int buflen, char **param_list, int plist_len, int *params_found){\n"\r
-" char *c=(char *)buf;\n"\r
-" int pno=0, pos=0;\n"\r
-" *params_found = 0;\n"\r
-"\n"\r
-" for(pos=0;pos<buflen;++pos){\n"\r
-" if(c[pos]=='\\n' || c[pos]=='\\0') return buf;\n"\r
-" if(c[pos]==':') break;\n"\r
-" }\n"\r
-" if(pos == buflen) return buf;\n"\r
-"\n"\r
-" pos++; \n"\r
-" param_list[pno]=c+pos;\n"\r
-" pno++;\n"\r
-" \n"\r
-" for(;pos<buflen;++pos){\n"\r
-" if(c[pos]==','){\n"\r
-" c[pos]='\\0';\n"\r
-" pos++;\n"\r
-" param_list[pno]=c+pos;\n"\r
-" pno++;\n"\r
-" }\n"\r
-" if(c[pos]=='\\n'){\n"\r
-" c[pos]='\\0';\n"\r
-" pos++;\n"\r
-" *params_found = pno;\n"\r
-" return c+pos;\n"\r
-" }\n"\r
-" }\n"\r
-" return buf;\n"\r
-"}\n"\r
-"\n"\r
-"\n";\r
-\r
- set<string> ufcns;\r
- vector<string> tbl_names = Schema->get_table_names();\r
- for(t=0;t<tbl_names.size();++t){\r
- if(operator_names.size()==0 || operator_names.count(tbl_names[t])>0){\r
- int tid = Schema->find_tbl(tbl_names[t]);\r
- if(Schema->get_schema_type(tid) == OPERATOR_VIEW_SCHEMA){\r
- table_def *optbl = Schema->get_table(tid);\r
- header += generate_host_name_tuple_struct(optbl);\r
- header += "int pack_"+tbl_names[t]+"_tuple(host_tuple *tup, char *buf, int len, struct "+generate_tuple_name(tbl_names[t])+" *s, unsigned char tuple_type);\n\n";\r
- code += generate_host_tuple_pack(optbl);\r
-\r
- header += "extern char *"+tbl_names[t]+"_Schema_def_;\n\n";\r
- code += "\tchar *"+tbl_names[t]+"_Schema_def_ = \n";\r
- string schema_str = "FTA{\n\n";\r
- schema_str += optbl->to_stream_string();\r
- schema_str +=\r
-"DEFINE{\n"\r
-"\tquery_name '"+tbl_names[t]+"';\n"\r
-"}\n"\r
-"\n"\r
-"Select";\r
- vector<field_entry *> flds = optbl->get_fields();\r
- for(f=0;f<flds.size();++f){\r
- if(f>0) schema_str+=",";\r
- schema_str += " " + flds[f]->get_name();\r
- }\r
- schema_str += "\nFrom "+tbl_names[t]+"\n}\n\n";\r
- code += make_C_embedded_string(schema_str)+";\n\n";\r
-\r
-\r
- vector<subquery_spec *> subq = Schema->get_subqueryspecs(tid);\r
- for(s=0;s<subq.size();++s){\r
- subquery_spec *sqs = subq[s];\r
- field_entry_list fel;\r
- for(f=0;f<sqs->types.size();++f){\r
- fel.append_field(new field_entry(sqs->types[f].c_str(), sqs->names[f].c_str(), "", sqs->modifiers[f],ufcns));\r
- }\r
- string subq_name = tbl_names[t]+"_subq_"+sqs->name;\r
- table_def std(subq_name.c_str(),NULL,NULL,&fel, STREAM_SCHEMA);\r
- header += generate_host_name_tuple_struct(&std);\r
- header += "struct "+subq_name+"_tuple *unpack_"+subq_name+"_tuple(host_tuple *tup);\n\n";\r
- code += generate_host_tuple_unpack(&std);\r
- }\r
- }else{\r
- if(operator_names.size()>0)\r
- fprintf(stderr,"WARNING: %s is not an operator, skipping.\n",tbl_names[t].c_str());\r
- }\r
- }\r
- }\r
-\r
- header += "\n#endif\n";\r
-\r
-\r
- fprintf(hdr_fl,"%s\n",header.c_str());\r
- fprintf(code_fl,"%s\n",code.c_str());\r
-\r
-///////////////////////////////////////////////////////////////////////\r
-\r
- return(0);\r
-}\r
-\r
+/* ------------------------------------------------
+Copyright 2014 AT&T Intellectual Property
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ------------------------------------------- */
+
+#include "parse_fta.h"
+#include "parse_schema.h"
+#include"generate_utils.h"
+
+#include <string>
+#include<set>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include<errno.h>
+
+#define TMPSTRLEN 1000
+
+#ifndef PATH_DELIM
+ #define PATH_DELIM '/'
+#endif
+
+char tmp_schema_str[10000];
+
+// Interface to FTA definition lexer and parser ...
+
+extern int FtaParserparse(void);
+extern FILE *FtaParserin;
+extern int FtaParserdebug;
+
+fta_parse_t *fta_parse_result;
+var_defs_t *fta_parse_defines;
+
+
+
+using namespace std;
+
+
+
+
+int main(int argc, char **argv){
+ int s,t,f;
+ char tmpstr[TMPSTRLEN];
+
+
+
+// set these to 1 to debug the parser
+ FtaParserdebug = 0;
+
+ FILE *table_schemas_in; // source tables definition file
+
+ // -------------------------------
+ // Handling of Input Arguments
+ // -------------------------------
+ const char *optstr = "C:";
+ const char *usage_str = "Usage: %s [-C <config directory>] schema_file [operator name ...]\n"
+ "\t[-C] : use <config directory> for definition files\n";
+
+
+// parameters gathered from command line processing
+ string config_dir_path;
+ set<string> operator_names;
+ string schema_file_name;
+
+ char chopt;
+ while((chopt = getopt(argc,argv,optstr)) != -1){
+ switch(chopt){
+ case 'C':
+ if(optarg != NULL)
+ config_dir_path = string(optarg) + string("/");
+ break;
+ case '?':
+ fprintf(stderr,"Error, argument %c not recognized.\n",optopt);
+ fprintf(stderr,"%s\n", usage_str);
+ exit(1);
+ default:
+ fprintf(stderr,"Invalid arguments\n");
+ fprintf(stderr,"%s\n", usage_str);
+ exit(1);
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ for (int i = 0; i < argc; ++i) {
+ if(schema_file_name == ""){
+ schema_file_name = argv[i];
+ }else{
+ operator_names.insert(argv[i]);
+ }
+ }
+
+ if(schema_file_name == ""){
+ fprintf(stderr,"%s\n", usage_str);
+ exit(1);
+ }
+
+
+// Open globally used file names.
+
+ // prepend config directory to schema file
+ schema_file_name = config_dir_path + schema_file_name;
+
+ if((table_schemas_in = fopen(schema_file_name.c_str(), "r")) == NULL) {
+ fprintf(stderr,"Can't open schema file %s\n%s\n",schema_file_name.c_str(),strerror(errno));
+ exit(1);
+ }
+
+
+
+
+// Get an initial Schema
+ table_list *Schema;
+// Parse the table schema definitions.
+ fta_parse_result = new fta_parse_t();
+ FtaParser_setfileinput(table_schemas_in);
+ if(FtaParserparse()){
+ fprintf(stderr,"Table schema parse failed.\n");
+ exit(1);
+ }
+ if(fta_parse_result->parse_type != TABLE_PARSE){
+ fprintf(stderr,"ERROR, file %s is not a table definition file.\n",schema_file_name.c_str());
+ exit(1);
+ }
+ Schema = fta_parse_result->tables;
+
+// Process schema field inheritance
+ string err_str;
+ int retval;
+ retval = Schema->unroll_tables(err_str);
+ if(retval){
+ fprintf(stderr,"Error processing schema filed inheritance:\n %s\n", err_str.c_str() );
+ exit(1);
+ }
+
+// Open header, code files
+
+ FILE *hdr_fl = fopen("operator_tuple_pack.h", "w");
+ if(hdr_fl == NULL){
+ fprintf(stderr,"Can't open output header file operator_tuple_pack.h\n%s\n",strerror(errno));
+ exit(1);
+ }
+ FILE *code_fl = fopen("operator_tuple_pack.cc", "w");
+ if(code_fl == NULL){
+ fprintf(stderr,"Can't open output code file operator_tuple_pack.c\n%s\n",strerror(errno));
+ exit(1);
+ }
+
+
+
+
+
+// Generate code for the accessing the operator tuples.
+
+ string header =
+"#ifndef __OPERATOR_TUPLE_PACK__\n"
+"#define __OPERATOR_TUPLE_PACK__\n"
+"\n"
+"#include \"host_tuple.h\"\n"
+"#include \"vstring.h\"\n"
+"#include \"byteswap.h\""
+"\n"
+"void *unpack_operator_params(void *buf, int buflen, char **param_list, int plist_len, int *params_found);\n"
+"\n"
+"\n";
+
+ string code =
+"#include \"operator_tuple_pack.h\"\n"
+"#include <sys/param.h>\n"
+"#include \"fta.h\"\n"
+"#include \"lapp.h\"\n"
+"#include \"hfta_runtime_library.h\"\n"
+"\n"
+"void *unpack_operator_params(void *buf, int buflen, char **param_list, int plist_len, int *params_found){\n"
+" char *c=(char *)buf;\n"
+" int pno=0, pos=0;\n"
+" *params_found = 0;\n"
+"\n"
+" for(pos=0;pos<buflen;++pos){\n"
+" if(c[pos]=='\\n' || c[pos]=='\\0') return buf;\n"
+" if(c[pos]==':') break;\n"
+" }\n"
+" if(pos == buflen) return buf;\n"
+"\n"
+" pos++; \n"
+" param_list[pno]=c+pos;\n"
+" pno++;\n"
+" \n"
+" for(;pos<buflen;++pos){\n"
+" if(c[pos]==','){\n"
+" c[pos]='\\0';\n"
+" pos++;\n"
+" param_list[pno]=c+pos;\n"
+" pno++;\n"
+" }\n"
+" if(c[pos]=='\\n'){\n"
+" c[pos]='\\0';\n"
+" pos++;\n"
+" *params_found = pno;\n"
+" return c+pos;\n"
+" }\n"
+" }\n"
+" return buf;\n"
+"}\n"
+"\n"
+"\n";
+
+ set<string> ufcns;
+ vector<string> tbl_names = Schema->get_table_names();
+ for(t=0;t<tbl_names.size();++t){
+ if(operator_names.size()==0 || operator_names.count(tbl_names[t])>0){
+ int tid = Schema->find_tbl(tbl_names[t]);
+ if(Schema->get_schema_type(tid) == OPERATOR_VIEW_SCHEMA){
+ table_def *optbl = Schema->get_table(tid);
+ header += generate_host_name_tuple_struct(optbl);
+ header += "int pack_"+tbl_names[t]+"_tuple(host_tuple *tup, char *buf, int len, struct "+generate_tuple_name(tbl_names[t])+" *s, unsigned char tuple_type);\n\n";
+ code += generate_host_tuple_pack(optbl);
+
+ header += "extern char *"+tbl_names[t]+"_Schema_def_;\n\n";
+ code += "\tchar *"+tbl_names[t]+"_Schema_def_ = \n";
+ string schema_str = "FTA{\n\n";
+ schema_str += optbl->to_stream_string();
+ schema_str +=
+"DEFINE{\n"
+"\tquery_name '"+tbl_names[t]+"';\n"
+"}\n"
+"\n"
+"Select";
+ vector<field_entry *> flds = optbl->get_fields();
+ for(f=0;f<flds.size();++f){
+ if(f>0) schema_str+=",";
+ schema_str += " " + flds[f]->get_name();
+ }
+ schema_str += "\nFrom "+tbl_names[t]+"\n}\n\n";
+ code += make_C_embedded_string(schema_str)+";\n\n";
+
+
+ vector<subquery_spec *> subq = Schema->get_subqueryspecs(tid);
+ for(s=0;s<subq.size();++s){
+ subquery_spec *sqs = subq[s];
+ field_entry_list fel;
+ for(f=0;f<sqs->types.size();++f){
+ fel.append_field(new field_entry(sqs->types[f].c_str(), sqs->names[f].c_str(), "", sqs->modifiers[f],ufcns));
+ }
+ string subq_name = tbl_names[t]+"_subq_"+sqs->name;
+ table_def std(subq_name.c_str(),NULL,NULL,&fel, STREAM_SCHEMA);
+ header += generate_host_name_tuple_struct(&std);
+ header += "struct "+subq_name+"_tuple *unpack_"+subq_name+"_tuple(host_tuple *tup);\n\n";
+ code += generate_host_tuple_unpack(&std);
+ }
+ }else{
+ if(operator_names.size()>0)
+ fprintf(stderr,"WARNING: %s is not an operator, skipping.\n",tbl_names[t].c_str());
+ }
+ }
+ }
+
+ header += "\n#endif\n";
+
+
+ fprintf(hdr_fl,"%s\n",header.c_str());
+ fprintf(code_fl,"%s\n",code.c_str());
+
+///////////////////////////////////////////////////////////////////////
+
+ return(0);
+}
+