From 9079928b0681ea2ed41ca2fe8509c72362ae88ef Mon Sep 17 00:00:00 2001 From: "selmer%netscape.com" Date: Tue, 12 Oct 1999 01:54:00 +0000 Subject: [PATCH] Created new Interpret.cpp & CInterpret class --- cck/driver/ProgDlgThread.cpp | 1 + cck/driver/WizardMachine.cpp | 365 +------------------------------- cck/driver/WizardMachine.h | 5 - cck/driver/WizardMachineDlg.cpp | 2 +- cck/driver/WizardUI.cpp | 6 +- cck/driver/makefile.win | 2 +- 6 files changed, 17 insertions(+), 364 deletions(-) diff --git a/cck/driver/ProgDlgThread.cpp b/cck/driver/ProgDlgThread.cpp index e900e81d8a4..f096f207595 100644 --- a/cck/driver/ProgDlgThread.cpp +++ b/cck/driver/ProgDlgThread.cpp @@ -23,6 +23,7 @@ #include "WizardMachine.h" #include "WizardMachineDlg.h" #include "ProgDlgThread.h" +#include "ProgressDialog.h" #ifdef _DEBUG #define new DEBUG_NEW diff --git a/cck/driver/WizardMachine.cpp b/cck/driver/WizardMachine.cpp index d532302d168..f243778984a 100644 --- a/cck/driver/WizardMachine.cpp +++ b/cck/driver/WizardMachine.cpp @@ -21,6 +21,7 @@ // #include "stdafx.h" +#include "afxmt.h" #include "WizardMachine.h" #include #include @@ -35,9 +36,9 @@ #include "NewConfigDialog.h" #include "ProgDlgThread.h" #include "PropSheet.h" +#include "WizardUI.h" +#include "Interpret.h" -// for CopyDir -#include "winbase.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -68,6 +69,7 @@ CWizardMachineApp::CWizardMachineApp() ///////////////////////////////////////////////////////////////////////////// // The one and only CWizardMachineApp object CPropSheet* PropertySheetDlg; +CInterpret *theInterpreter; CWizardMachineApp theApp; NODE *GlobalDefaults; @@ -119,6 +121,8 @@ BOOL CWizardMachineApp::InitInstance() //Check for comm existence //declare a tree for nodes + theInterpreter = new CInterpret(); + Path = GetModulePath(); strcpy(currDirPath, Path); @@ -773,355 +777,6 @@ void CWizardMachineApp::ExecuteAction(char action) } } -void CWizardMachineApp::CopyDir(CString from, CString to) -{ - WIN32_FIND_DATA data; - HANDLE d; - CString dot = "."; - CString dotdot = ".."; - CString fchild, tchild; - CString pattern = from + "\\*.*"; - int found; - DWORD tmp; - - d = FindFirstFile((const char *) to, &data); - if (d == INVALID_HANDLE_VALUE) - mkdir(to); - - d = FindFirstFile((const char *) pattern, &data); - found = (d != INVALID_HANDLE_VALUE); - - while (found) - { - if (data.cFileName != dot && data.cFileName != dotdot) - { - fchild = from + "\\" + data.cFileName; - tchild = to + "\\" + data.cFileName; - tmp = data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; - if (tmp == FILE_ATTRIBUTE_DIRECTORY) - CopyDir(fchild, tchild); - else - CopyFile((const char *) fchild, (const char *) tchild, FALSE); - } - - found = FindNextFile(d, &data); - } - - FindClose(d); -} - -void CWizardMachineApp::ExecuteCommand(char *command, int showflag) -{ - STARTUPINFO startupInfo; - PROCESS_INFORMATION processInfo; - - memset(&startupInfo, 0, sizeof(startupInfo)); - memset(&processInfo, 0, sizeof(processInfo)); - - startupInfo.cb = sizeof(STARTUPINFO); - startupInfo.dwFlags = STARTF_USESHOWWINDOW; - //startupInfo.wShowWindow = SW_SHOW; - startupInfo.wShowWindow = showflag; - - BOOL executionSuccessful = CreateProcess(NULL, command, NULL, NULL, TRUE, - NORMAL_PRIORITY_CLASS, NULL, NULL, - &startupInfo, &processInfo); - DWORD error = GetLastError(); - WaitForSingleObject(processInfo.hProcess, INFINITE); -} - -CString CWizardMachineApp::replaceVars(char *str, char *listval) -{ - char buf[MIN_SIZE]; - char *b = buf; - char *v; - CString v1; - - while (*str) - { - if (*str == '%') - { - char *n = ++str; - while (*str && *str != '%') - str++; - if (*str == '%') - { - *str = '\0'; - - if (listval && strlen(n) <= 0) - v = listval; - else - { - WIDGET *w = findWidget(n); - if (w) - { - if (w->control && w->control->m_hWnd) - { - v1 = CWizardUI::GetScreenValue(w); - v = (char *) (LPCSTR) v1; - } - else - v = (char *) (LPCSTR) w->value; - } - else - v = ""; - } - strcpy(b, v); - b += strlen(v); - } - else - { - CWnd myWnd; - myWnd.MessageBox("Improperly terminated globals reference", "Error", MB_OK); - exit(12); - } - str++; - } - else - *b++ = *str++; - } - *b = '\0'; - - return CString(buf); -} - -BOOL CWizardMachineApp::IterateListBox(char *parms) -{ - char *target = strtok(parms, ","); - char *showstr = strtok(NULL, ","); - char *cmd = strtok(NULL, ""); - WIDGET *w = findWidget(target); - char indices[MAX_SIZE]; - int showflag; - - if (!w || w->type != "ListBox") - return FALSE; - - if (w->control && w->control->m_hWnd) - { - // Widget is still visible on screen, get temporary copy of current value - // (from here, we depend on UpdataData() having been called somewhere upstream) - CString v = CWizardUI::GetScreenValue(w); - strcpy(indices, (char *) (LPCSTR) v); - } - else - strcpy(indices, w->value); - - if (strcmp(showstr, "SHOW") == 0) - showflag = SW_SHOWDEFAULT; - else if (strcmp(showstr, "HIDE") == 0) - showflag = SW_HIDE; - else - showflag = SW_SHOWDEFAULT; - - char *s = strtok(indices, ","); // Need to fix this, parm2 is a span rather than a literal!!! - for (; s; s=strtok(NULL, ",")) - { - char *cmd_copy = strdup(cmd); - CString command = replaceVars(cmd_copy, s); - free(cmd_copy); - ExecuteCommand((char *) (LPCSTR) command, showflag); - } - - return TRUE; -} - -BOOL CWizardMachineApp::interpret(CString cmds, WIDGET *curWidget) -{ - // Make modifiable copy of string's buffer - char buf[MAX_SIZE]; - strcpy(buf, (char *)(LPCTSTR) cmds); - - // Format of commandList is: ;;... - // Format of command is: (,,...) - int numCmds = 0; - char *cmdList[100]; - char *pcmdL = strtok(buf, ";"); - while (pcmdL) - { - cmdList[numCmds] = strdup(pcmdL); - pcmdL = strtok(NULL, ";"); - numCmds++; - if (numCmds >= 100) - { - fprintf(out, "Skipping command interpretation, too many commands.\n"); - return FALSE; - } - } - - int i; - for (i=0; inavControls->onNextAction) - if (!interpret(CurrentNode->navControls->onNextAction, NULL)) + if (!theInterpreter->interpret(CurrentNode->navControls->onNextAction, NULL)) return TRUE; //---------------------------------------------------------------------------------------------- @@ -1208,7 +863,7 @@ BOOL CWizardMachineApp::GoToNextNode() exit(10); } - if (!interpret(CurrentNode->navControls->onEnter, NULL)) + if (!theInterpreter->interpret(CurrentNode->navControls->onEnter, NULL)) return FALSE; return TRUE; @@ -1251,7 +906,7 @@ BOOL CWizardMachineApp::GoToPrevNode() if (!CurrentNode) 0;/*then what*/ - if (!interpret(CurrentNode->navControls->onEnter, NULL)) + if (!theInterpreter->interpret(CurrentNode->navControls->onEnter, NULL)) return FALSE; BOOL isAContainerNode; @@ -1393,7 +1048,7 @@ BOOL CWizardMachineApp::FillGlobalWidgetArray(CString file) value = CString(strtok(NULL,"=")); value.TrimRight(); if (value.Find("%") >= 0) - value=replaceVars((char *) (LPCSTR) value,NULL); + value=theInterpreter->replaceVars((char *) (LPCSTR) value,NULL); WIDGET* w = SetGlobal(name, value); if (w) diff --git a/cck/driver/WizardMachine.h b/cck/driver/WizardMachine.h index 797d5c3f6e7..14f9627974c 100644 --- a/cck/driver/WizardMachine.h +++ b/cck/driver/WizardMachine.h @@ -52,11 +52,6 @@ public: char* GetBufferElement(const char *buffer, int index); char* GetSectionBuffer(CString iniFile, CString section); void ExecuteAction(char action); - CString replaceVars(char *str, char *listval); - void CopyDir(CString from, CString to); - void ExecuteCommand(char *command, int showflag); - BOOL IterateListBox(char *parms); - BOOL interpret(CString cmd, WIDGET *curWidget); BOOL GoToNextNode(); BOOL GoToPrevNode(); void ExitApp(); diff --git a/cck/driver/WizardMachineDlg.cpp b/cck/driver/WizardMachineDlg.cpp index 6a219fe95e7..ac60c189731 100644 --- a/cck/driver/WizardMachineDlg.cpp +++ b/cck/driver/WizardMachineDlg.cpp @@ -22,7 +22,7 @@ #include "stdafx.h" #include "WizardMachine.h" #include "WizardMachineDlg.h" -//#include "ImageDialog.h" +#include "WizardUI.h" #include "ImgDlg.h" #ifdef _DEBUG diff --git a/cck/driver/WizardUI.cpp b/cck/driver/WizardUI.cpp index d0fdf2005e4..1d195052dcf 100644 --- a/cck/driver/WizardUI.cpp +++ b/cck/driver/WizardUI.cpp @@ -33,6 +33,7 @@ #include "ProgDlgThread.h" #include "PropSheet.h" #include "WizardUI.h" +#include "Interpret.h" #include #include @@ -50,6 +51,7 @@ static char THIS_FILE[] = __FILE__; ///////////////////////////////////////////////////////////////////////////// // CWizardUI property page extern CWizardMachineApp theApp; +extern CInterpret *theInterpreter; extern NODE *CurrentNode; extern HBITMAP hBitmap; extern CString Path; @@ -692,7 +694,7 @@ BOOL CWizardUI::OnCommand(WPARAM wParam, LPARAM lParam) if (curWidget->action.dll == "NULL") { if (curWidget->action.function == "command") - theApp.interpret(curWidget->action.parameters, curWidget); + theInterpreter->interpret(curWidget->action.parameters, curWidget); } else Progress(); @@ -1273,7 +1275,7 @@ BOOL CWizardUI::OnWizardFinish() UpdateGlobals(); if (CurrentNode->navControls->onNextAction) - if (!theApp.interpret(CurrentNode->navControls->onNextAction, NULL)) + if (!theInterpreter->interpret(CurrentNode->navControls->onNextAction, NULL)) return FALSE; return CPropertyPage::OnWizardFinish(); } diff --git a/cck/driver/makefile.win b/cck/driver/makefile.win index ec32bbd9ce2..487861a5978 100644 --- a/cck/driver/makefile.win +++ b/cck/driver/makefile.win @@ -42,12 +42,12 @@ LLFLAGS = \ INCS = -I. \ $(INCS) -# .\$(OBJDIR)\Interpret.obj \ OBJS = \ .\$(OBJDIR)\HelpDlg.obj \ .\$(OBJDIR)\ImageDialog.obj \ .\$(OBJDIR)\ImgDlg.obj \ + .\$(OBJDIR)\Interpret.obj \ .\$(OBJDIR)\NavText.obj \ .\$(OBJDIR)\NewConfigDialog.obj \ .\$(OBJDIR)\NewDialog.obj \