|
k-dot-p 0.1
|
00001 /* 00002 * 00003 Copyright (C) 2009 Joseph Pingenot 00004 00005 This program is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU Affero General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU Affero General Public License for more details. 00014 00015 You should have received a copy of the GNU Affero General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 00018 */ 00019 #include <stdio.h> 00020 #include <stdlib.h> 00021 #include <glib.h> 00022 #include <gio/gio.h> 00023 #include <libmodelxx/matdb.h++> 00024 #include <libmodelxx/matdb-dotcode.h++> 00025 #include <libmodelxx/continuous_structure.h++> 00026 #include <libmodelxx/generic_structure.h++> 00027 #include <libmodelxx/function_specification.h++> 00028 #include "makestruct_argprocess.h++" 00029 00030 using namespace kdotp::libmodelxx::continuous_structure; 00031 using namespace kdotp::libmodelxx::structure; 00032 using namespace kdotp::libmodelxx::postprocessing; 00033 00034 void yyparse(); 00035 int yylex(); 00036 00037 extern struct continuous_structure* the_structure; 00038 extern GFileInputStream* instream; 00039 00040 int main(int argc, char* argv[]) { 00041 g_type_init(); 00042 /* 00043 int val; 00044 while((val=yylex()) != 0) { 00045 printf("Got token %d\n", val); 00046 } 00047 */ 00048 struct makestruct_args args; 00049 int err; 00050 err = parse_makestruct_args(argc, argv, &args); 00051 if(err != 0) exit(1); 00052 GString *mdb_file = g_string_new(args.matdb); 00053 struct matdb* mdb = read_matdb_dotcode(mdb_file, &err); 00054 if(mdb == NULL) {fprintf(stderr, "ERROR reading in the materials database %s: %d\n", args.matdb, err); return 1;} 00055 00056 GList* l; 00057 GError* gerr= NULL; 00058 GHashTable *gst = new_symbol_table(); 00059 for(l=(args.files); l != NULL; l=l->next) { 00060 gerr = NULL; 00061 instream = g_file_read((GFile*)(l->data), NULL, &gerr); 00062 if(gerr != NULL) { 00063 fprintf(stderr, "makestruct: ERROR reading in structure file (%s): %s\n", g_file_get_uri((GFile*)(l->data)), gerr->message); 00064 continue; 00065 } 00066 yyparse(); 00067 if(the_structure == NULL) { 00068 fprintf(stderr, "the_structure was NULL!\n"); 00069 exit(1); 00070 } 00071 struct generic_structure *s = postprocess_structure(the_structure, mdb, gst, &gerr); 00072 *s = *s; 00073 fprintf(stderr, "got structure!\n"); 00074 00075 /*Dump the file.*/ 00076 GFile* file = g_file_new_for_commandline_arg("teststruct.structdump"); 00077 gerr = generic_structure_dump(s, file); 00078 if(gerr != NULL){ 00079 fprintf(stderr, "unable to dump structure: %s\n", gerr->message); 00080 return 1; 00081 } 00082 00083 generic_structure_free(s); 00084 } 00085 return 0; 00086 }