int main(int argc, const char** argv) { if (argc > 1) { if (strcmp("v", argv[1]) == 0) { gVerbose = true; argc--; argv = &argv[1]; } Log("Verbosity test %s\n", "foo"); bool search = StrStartsWith(argv[1], "search"); if (search) { FastPathSearch(argc, argv); goto exit_main; } } // Fall through to lua handling InitLua(); lua_getfield(gLuaState, LUA_GLOBALSINDEX, "main"); for (int i = 0; i < argc; i++) { lua_pushstring(gLuaState, argv[i]); } ReportedDoCall(gLuaState, argc,0); exit_main: return 0; }
bool SolveSpace::LoadEntitiesFromFile(char *file, EntityList *le, SMesh *m, SShell *sh) { SSurface srf; ZERO(&srf); SCurve crv; ZERO(&crv); fh = fopen(file, "rb"); if(!fh) return false; le->Clear(); memset(&sv, 0, sizeof(sv)); char line[1024]; while(fgets(line, (int)sizeof(line), fh)) { char *s = strchr(line, '\n'); if(s) *s = '\0'; // We should never get files with \r characters in them, but mailers // will sometimes mangle attachments. s = strchr(line, '\r'); if(s) *s = '\0'; if(*line == '\0') continue; char *e = strchr(line, '='); if(e) { *e = '\0'; char *key = line, *val = e+1; LoadUsingTable(key, val); } else if(strcmp(line, "AddGroup")==0) { // Don't leak memory; these get allocated whether we want them // or not. sv.g.remap.Clear(); } else if(strcmp(line, "AddParam")==0) { } else if(strcmp(line, "AddEntity")==0) { le->Add(&(sv.e)); memset(&(sv.e), 0, sizeof(sv.e)); } else if(strcmp(line, "AddRequest")==0) { } else if(strcmp(line, "AddConstraint")==0) { } else if(strcmp(line, "AddStyle")==0) { } else if(strcmp(line, VERSION_STRING)==0) { } else if(StrStartsWith(line, "Triangle ")) { STriangle tr; ZERO(&tr); unsigned int rgb = 0; if(sscanf(line, "Triangle %x %x " "%lf %lf %lf %lf %lf %lf %lf %lf %lf", &(tr.meta.face), &rgb, &(tr.a.x), &(tr.a.y), &(tr.a.z), &(tr.b.x), &(tr.b.y), &(tr.b.z), &(tr.c.x), &(tr.c.y), &(tr.c.z)) != 11) { oops(); } tr.meta.color = RgbColor::FromPackedInt((uint32_t)rgb); m->AddTriangle(&tr); } else if(StrStartsWith(line, "Surface ")) { unsigned int rgb = 0; if(sscanf(line, "Surface %x %x %x %d %d", &(srf.h.v), &rgb, &(srf.face), &(srf.degm), &(srf.degn)) != 5) { oops(); } srf.color = RgbColor::FromPackedInt((uint32_t)rgb); } else if(StrStartsWith(line, "SCtrl ")) { int i, j; Vector c; double w; if(sscanf(line, "SCtrl %d %d %lf %lf %lf Weight %lf", &i, &j, &(c.x), &(c.y), &(c.z), &w) != 6) { oops(); } srf.ctrl[i][j] = c; srf.weight[i][j] = w; } else if(StrStartsWith(line, "TrimBy ")) { STrimBy stb; ZERO(&stb); int backwards; if(sscanf(line, "TrimBy %x %d %lf %lf %lf %lf %lf %lf", &(stb.curve.v), &backwards, &(stb.start.x), &(stb.start.y), &(stb.start.z), &(stb.finish.x), &(stb.finish.y), &(stb.finish.z)) != 8) { oops(); } stb.backwards = (backwards != 0); srf.trim.Add(&stb); } else if(strcmp(line, "AddSurface")==0) { sh->surface.Add(&srf); ZERO(&srf); } else if(StrStartsWith(line, "Curve ")) { int isExact; if(sscanf(line, "Curve %x %d %d %x %x", &(crv.h.v), &(isExact), &(crv.exact.deg), &(crv.surfA.v), &(crv.surfB.v)) != 5) { oops(); } crv.isExact = (isExact != 0); } else if(StrStartsWith(line, "CCtrl ")) { int i; Vector c; double w; if(sscanf(line, "CCtrl %d %lf %lf %lf Weight %lf", &i, &(c.x), &(c.y), &(c.z), &w) != 5) { oops(); } crv.exact.ctrl[i] = c; crv.exact.weight[i] = w; } else if(StrStartsWith(line, "CurvePt ")) { SCurvePt scpt; int vertex; if(sscanf(line, "CurvePt %d %lf %lf %lf", &vertex, &(scpt.p.x), &(scpt.p.y), &(scpt.p.z)) != 4) { oops(); } scpt.vertex = (vertex != 0); crv.pts.Add(&scpt); } else if(strcmp(line, "AddCurve")==0) { sh->curve.Add(&crv); ZERO(&crv); } else { oops(); } } fclose(fh); return true; }
BOOL CALLBACK DlgProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { // case WM_INITDIALOG: // break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_COMBO_COMMAND: { if (HIWORD(wParam) == CBN_SELCHANGE) { int i = SendDlgItemMessage(hWnd, IDC_COMBO_COMMAND, CB_GETCURSEL, 0, 0); if (i != CB_ERR && i >= 0 && i < giCmdData && gpCmdData[i]->bHasArgs) { ShowWindow(GetDlgItem(hWnd, IDC_STATIC_ARGS_DESCRIPTION), SW_SHOW); ShowWindow(GetDlgItem(hWnd, IDC_STATIC_ARGS), SW_SHOW); ShowWindow(GetDlgItem(hWnd, IDC_EDIT_ARGS), SW_SHOW); SetDlgItemText(hWnd, IDC_STATIC_ARGS_DESCRIPTION, gpCmdData[i]->szArgsDesc); } else { ShowWindow(GetDlgItem(hWnd, IDC_STATIC_ARGS_DESCRIPTION), SW_HIDE); ShowWindow(GetDlgItem(hWnd, IDC_STATIC_ARGS), SW_HIDE); ShowWindow(GetDlgItem(hWnd, IDC_EDIT_ARGS), SW_HIDE); } } break; } case IDC_CMD_EDIT: { char szFileName[MAX_PATH+1]; GetDlgItemText(hWnd, IDC_EDIT_FILE, szFileName, MAX_PATH); char *szFile = findfile(szFileName); if (!szFile) { szFile = new char[MAX_PATH+1]; wsprintf(szFile, "%s%s", gszUserScripts, szFileName); } char szViewer[MAX_PATH+1]; char temp[MAX_PATH]; GetTempPath(MAX_PATH, temp); lstrcat(temp, "sitemp.txt"); HANDLE hFile = CreateFile(temp, 0, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); DWORD err = GetLastError(); if (hFile != INVALID_HANDLE_VALUE) { FindExecutable(temp, NULL, szViewer); CloseHandle(hFile); if (err != ERROR_ALREADY_EXISTS) DeleteFile(temp); } if (!*szViewer) { lstrcpy(szViewer, "notepad.exe"); } SHELLEXECUTEINFO se = { 0 }; se.cbSize = sizeof(SHELLEXECUTEINFO); se.fMask = SEE_MASK_DOENVSUBST | SEE_MASK_NOCLOSEPROCESS; se.lpVerb = "Open"; se.lpFile = szViewer; se.lpParameters = szFile; se.lpDirectory = NULL; se.nShow = SW_SHOWNORMAL; ShellExecuteEx(&se); break; } case IDC_CMD_BROWSE: char *buf = new char[MAX_PATH+1]; *buf = 0; OPENFILENAME ofn = {0}; ofn.lStructSize = sizeof(OPENFILENAME); ofn.hInstance = ghInstance; ofn.hwndOwner = hWnd; // "Lua Files\0*.lua\0All Files\0*.*\0"; char *filter = new char[256]; char *end = filter; lstrcpy(end, STR(LUA_FILES)); end += lstrlen(end) + 1; lstrcpy(end, "*.lua"); end += lstrlen(end) + 1; lstrcpy(end, STR(ALL_FILES)); end += lstrlen(end) + 1; lstrcpy(end, "*.*"); end += lstrlen(end) + 1; *end = 0; char szFile[MAX_PATH+1]; GetDlgItemText(hWnd, IDC_EDIT_FILE, szFile, MAX_PATH); ofn.lpstrFile = szFile; ofn.lpstrInitialDir = (char *)gszUserScripts; ofn.lpstrFilter = filter; ofn.lpstrFile = buf; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_PATHMUSTEXIST | OFN_LONGNAMES | OFN_EXPLORER; if (GetOpenFileName(&ofn)) { if ( StrStartsWith(buf, (char *)gszUserScripts) ) { SetDlgItemText(hWnd, IDC_EDIT_FILE, buf + lstrlen((char *)gszUserScripts)); } else if ( StrStartsWith(buf, (char *)gszGlobalScripts) ) { SetDlgItemText(hWnd, IDC_EDIT_FILE, buf + lstrlen((char *)gszGlobalScripts)); } else { SetDlgItemText(hWnd, IDC_EDIT_FILE, buf); } // clear the dropdown SendDlgItemMessage(hWnd, IDC_COMBO_COMMAND, CB_RESETCONTENT, 0, 0); DeleteScriptDetails((s_commandData **) &gpCmdData, giCmdData); giCmdData = GetScriptDetails(buf, (s_commandData **) &gpCmdData); if (giCmdData > 0) { // populate the dropdown for (int i = 0; i<giCmdData; i++) AddCombo(hWnd, IDC_COMBO_COMMAND, gpCmdData[i]->szCmdName, gpCmdData[i]->szCmdName); SendDlgItemMessage(hWnd, IDC_COMBO_COMMAND, CB_SETCURSEL, 0, 0); ShowWindow(GetDlgItem(hWnd, IDC_STATIC_COMMAND), SW_SHOW); ShowWindow(GetDlgItem(hWnd, IDC_COMBO_COMMAND), SW_SHOW); } else { ShowWindow(GetDlgItem(hWnd, IDC_STATIC_COMMAND), SW_HIDE); ShowWindow(GetDlgItem(hWnd, IDC_COMBO_COMMAND), SW_HIDE); } // show/hide the args depending on the selection SendMessage(hWnd, WM_COMMAND, MAKELONG(IDC_COMBO_COMMAND, CBN_SELCHANGE), (LPARAM) GetDlgItem(hWnd, IDC_COMBO_COMMAND)); } delete filter; delete buf; } break; case WM_CLOSE: DestroyWindow(hWnd); break; default: return FALSE; } return TRUE; }
bool SolveSpace::LoadFromFile(char *filename) { allConsistent = false; fileLoadError = false; fh = fopen(filename, "rb"); if(!fh) { Error("Couldn't read from file '%s'", filename); return false; } ClearExisting(); memset(&sv, 0, sizeof(sv)); sv.g.scale = 1; // default is 1, not 0; so legacy files need this char line[1024]; while(fgets(line, (int)sizeof(line), fh)) { char *s = strchr(line, '\n'); if(s) *s = '\0'; // We should never get files with \r characters in them, but mailers // will sometimes mangle attachments. s = strchr(line, '\r'); if(s) *s = '\0'; if(*line == '\0') continue; char *e = strchr(line, '='); if(e) { *e = '\0'; char *key = line, *val = e+1; LoadUsingTable(key, val); } else if(strcmp(line, "AddGroup")==0) { SK.group.Add(&(sv.g)); ZERO(&(sv.g)); sv.g.scale = 1; // default is 1, not 0; so legacy files need this } else if(strcmp(line, "AddParam")==0) { // params are regenerated, but we want to preload the values // for initial guesses SK.param.Add(&(sv.p)); ZERO(&(sv.p)); } else if(strcmp(line, "AddEntity")==0) { // entities are regenerated } else if(strcmp(line, "AddRequest")==0) { SK.request.Add(&(sv.r)); ZERO(&(sv.r)); } else if(strcmp(line, "AddConstraint")==0) { SK.constraint.Add(&(sv.c)); ZERO(&(sv.c)); } else if(strcmp(line, "AddStyle")==0) { SK.style.Add(&(sv.s)); ZERO(&(sv.s)); } else if(strcmp(line, VERSION_STRING)==0) { // do nothing, version string } else if(StrStartsWith(line, "Triangle ") || StrStartsWith(line, "Surface ") || StrStartsWith(line, "SCtrl ") || StrStartsWith(line, "TrimBy ") || StrStartsWith(line, "Curve ") || StrStartsWith(line, "CCtrl ") || StrStartsWith(line, "CurvePt ") || strcmp(line, "AddSurface")==0 || strcmp(line, "AddCurve")==0) { // ignore the mesh or shell, since we regenerate that } else { fileLoadError = true; } } fclose(fh); if(fileLoadError) { Error("Unrecognized data in file. This file may be corrupt, or " "from a new version of the program."); // At least leave the program in a non-crashing state. if(SK.group.n == 0) { NewFile(); } } return true; }
int GetScriptDetails(char *szFileName, s_commandData **pCmdData) { if (!szFileName) return 0; int iCmdData = NULL; FILE *pFile; pFile = fopen (szFileName, "r"); if (pFile != NULL) { char szLine[1024+1]; BOOL bInitLine; do { fgets (szLine, 1024, pFile); char *c = szLine; // strip off any trailing newline characters while ( *c && '\n' != *c && '\r' != *c) c++; if (*c) *c = '\0'; if( StrStartsWith(szLine, "--!SI:") ) { bInitLine = TRUE; char *szArgsDesc = NULL; char *szCmdName = NULL; char *szCmdData = NULL; char *szData = szLine + lstrlen("--!SI:"); // check for @ArgsDescription if (*szData == '@') { szArgsDesc = szData + 1; szCmdName = strchr(szArgsDesc, ':'); if ( szCmdName ) { *szCmdName = 0; szCmdName++; } } else szCmdName = szData; // check for Name:Command szCmdData = strchr(szCmdName, ':'); if ( szCmdData ) { *szCmdData='\0'; // null terminate the 'data' szCmdData++; // skip past the ':' pCmdData[iCmdData] = new s_commandData; pCmdData[iCmdData]->bHasArgs = (szArgsDesc != NULL); pCmdData[iCmdData]->szArgsDesc = mstrdup(szArgsDesc); pCmdData[iCmdData]->szCmdData = mstrdup(szCmdData); pCmdData[iCmdData]->szCmdName = mstrdup(szCmdName); iCmdData++; } } else { bInitLine = FALSE; } } while(bInitLine); fclose (pFile); } return iCmdData; }