/* Read the options in a scad file an option is either // optionname values ... or // optionname1 optionname2 values ... The program just prints the values */ #include #include #include #include #include #include #include #include #include #include using namespace std; /* Read each word of a line. If a word does not start with a -, it assume the word references an opts file in ~/.Slic3r/modes. It either executes the file or read it to get the slic3r options */ static void oscad_convert(const char *line) { const char *home = getenv("HOME"); vector words; int n = str_splitline(line,' ',words); for (int i=0; i int main (int argc, char *argv[]) { glocal int ret = -1; glocal const char *optname1 = NULL; glocal const char *optname2 = NULL; glocal bool splitline = false; glocal bool printdesc = false; glocal bool convert = false; glocal.ret = (argc,argv); setproginfo ("oscad-readopts","0.0" ,"Read and print options in scad files\n" "\n" "oscad-readopts -o name1 [ --optname2 name2 ] scadfile\n"); setarg ('c',"convert","Convert options by reading corresponding file",glocal.convert,false); setarg ('o',"optname1","option name 1",glocal.optname1,true); setarg (' ',"optname2","option name 2",glocal.optname2,false); setarg (' ',"splitline","Split the values on the option line",glocal.splitline,false); setarg (' ',"printdesc","Print the comment at the end of the line",glocal.printdesc,false); int ret = -1; if (argc != 1){ usage(); }else{ string tmp; if (glocal.optname2 != NULL){ const char *pt = strchr(glocal.optname2,':'); if (pt != NULL){ tmp = string (glocal.optname2,pt-glocal.optname2); glocal.optname2 = tmp.c_str(); } } (argv[0],true); const char *pt = str_skip(line); if (strncmp(pt,"//",2)==0){ string word; pt += 2; string tmp; string description; const char *comment = strstr(pt,"//"); if (comment != NULL){ description = str_skip(comment+2); tmp = string(pt,comment-pt); pt = tmp.c_str(); } pt = str_copyword(word,pt); if (strcmp(word.c_str(),glocal.optname1)==0){ if (glocal.optname2 != NULL){ pt = str_copyword(word,pt); vector tb; int n = str_splitline(word.c_str(),',',tb); for (int i=0; i tb; int n = str_splitline(pt,' ',tb); for (int i=0; i ret = 0; } return ret; return glocal.ret; }