//Close all open routers. If router type is system, skip it. // If the router type is 'dribble' then close the dribble file. // If the router type is 'user', the issue a '(close <router>)' command. int CloseAllRouters(void) { struct WebCLIPSRouter *pWCRouter; //Close the standard routers first pWCRouter = g_pStdWebCLIPSRouter; while(pWCRouter) { if(pWCRouter->cRouterType == WCRouter_System || pWCRouter->cRouterType == WCRouter_Userdefined) { fclose(pWCRouter->fp); pWCRouter->fp = NULL; } if(pWCRouter->cRouterType == WCRouter_Dribble) { if(DribbleOff() == 0) { ProcessErrorCode("DRBL0003", pWCRouter->szRouterFileName, 'n', 'n'); return(-1); } } //Next router pWCRouter = pWCRouter->pNextRouter; } //Now do the User defined routers pWCRouter = g_pUDFWebCLIPSRouter; while(pWCRouter) { if(pWCRouter->cRouterType == WCRouter_System || pWCRouter->cRouterType == WCRouter_Userdefined) { fclose(pWCRouter->fp); pWCRouter->fp = NULL; } if(pWCRouter->cRouterType == WCRouter_Dribble) { if(DribbleOff() == 0) { ProcessErrorCode("DRBL0003", pWCRouter->szRouterFileName, 'n', 'n'); return(-1); } } //Next router pWCRouter = pWCRouter->pNextRouter; } return(0); }
bool DribbleOn( Environment *theEnv, const char *fileName) { /*==============================*/ /* If a dribble file is already */ /* open, then close it. */ /*==============================*/ if (FileCommandData(theEnv)->DribbleFP != NULL) { DribbleOff(theEnv); } /*========================*/ /* Open the dribble file. */ /*========================*/ FileCommandData(theEnv)->DribbleFP = GenOpen(theEnv,fileName,"w"); if (FileCommandData(theEnv)->DribbleFP == NULL) { OpenErrorMessage(theEnv,"dribble-on",fileName); return false; } /*============================*/ /* Create the dribble router. */ /*============================*/ AddRouter(theEnv,"dribble",40, QueryDribbleCallback,WriteDribbleCallback, ReadDribbleCallback,UnreadDribbleCallback, ExitDribbleCallback,NULL); FileCommandData(theEnv)->DribbleCurrentPosition = 0; /*================================================*/ /* Call the dribble status function. This is used */ /* by some of the machine specific interfaces to */ /* do things such as changing the wording of menu */ /* items from "Turn Dribble On..." to */ /* "Turn Dribble Off..." */ /*================================================*/ if (FileCommandData(theEnv)->DribbleStatusFunction != NULL) { (*FileCommandData(theEnv)->DribbleStatusFunction)(theEnv,true); } /*=====================================*/ /* Return true to indicate the dribble */ /* file was successfully opened. */ /*=====================================*/ return true; }
/******************************************************************* * OpenDribbleFile: Function will display the common file dialog and * will open a dribble file. ******************************************************************/ void OpenDribbleFile ( HWND hMain, WORD wParam ) { extern HANDLE hInst; OPENFILENAME ofn; char File[256], FileTitle[256], Filter[256]; UINT i, cbString; char Replace; HMENU hMenu = GetMenu(hMain); if ( !DribbleActive() ) { File[0] = '\0'; memset ( &ofn,0, sizeof (OPENFILENAME)); ofn.lpstrTitle = "Select CLIPS Dribble File"; if ((cbString = LoadString ( (HINSTANCE) hInst, IDS_DRIBBLE, Filter, sizeof (Filter))) == 0 ) return; Replace = Filter[cbString-1]; for (i=0; Filter[i] != '\0'; i++) if ( Filter[i] == Replace) Filter[i] = '\0'; ofn.lStructSize = sizeof ( OPENFILENAME ); ofn.hwndOwner = hMain; ofn.lpstrFilter = Filter; ofn.nFilterIndex = 1; ofn.lpstrFile = File; ofn.nMaxFile = sizeof (File ); ofn.lpstrFileTitle = FileTitle; ofn.nMaxFileTitle = sizeof (FileTitle); ofn.lpstrInitialDir = NULL; ofn.Flags = OFN_OVERWRITEPROMPT; if ( GetSaveFileName ( &ofn ) ) { UpdateCursor ( WAIT_CURSOR ); ModifyMenu (hMenu, wParam, MF_BYCOMMAND, wParam, "Turn Dribble Off"); DribbleOn ( ofn.lpstrFile ); } } else { UpdateCursor ( WAIT_CURSOR ); ModifyMenu (hMenu, wParam, MF_BYCOMMAND, wParam, "Turn Dribble On..."); DribbleOff( ); } }