// --------------------------------------------------------------------------- // From class MWlanBgScanProvider. // CWlanBgScan::NotifyChangedSettings // --------------------------------------------------------------------------- // void CWlanBgScan::NotifyChangedSettings( MWlanBgScanProvider::TWlanBgScanSettings& aSettings ) { DEBUG6( "CWlanBgScan::NotifyChangedSettings( interval: %u, psm srv mode: %u, peak start: %04u, peak end: %04u, peak: %u, off-peak: %u )", aSettings.backgroundScanInterval, aSettings.psmServerMode, aSettings.bgScanPeakStartTime, aSettings.bgScanPeakEndTime, aSettings.bgScanIntervalPeak, aSettings.bgScanIntervalOffPeak); // validate settings and use default values if needed MWlanBgScanProvider::TWlanBgScanSettings settingsToUse; CheckSettings( settingsToUse, aSettings ); // Note: Any PSM server mode value is allowed. // store settings for later use iBgScanSettings = settingsToUse; IntervalChanged(); if( iCurrentPsmServerMode != iBgScanSettings.psmServerMode ) { if( AwsPresence() == CWlanBgScan::EAwsPresent ) { DEBUG( "CWlanBgScan::NotifyChangedSettings() - sending power mode command to AWS" ); MWlanBgScanAwsComms::TAwsMessage msg = { MWlanBgScanAwsComms::ESetPowerSaveMode, iBgScanSettings.psmServerMode }; iAwsComms->SendOrQueueAwsCommand( msg ); } // remember current psm server mode iCurrentPsmServerMode = iBgScanSettings.psmServerMode; } }
void Compatibility::Load(const std::string &gameID) { Clear(); { IniFile compat; // This loads from assets. if (compat.LoadFromVFS("compat.ini")) { CheckSettings(compat, gameID); } } { IniFile compat2; // This one is user-editable. Need to load it after the system one. std::string path = GetSysDirectory(DIRECTORY_SYSTEM) + "compat.ini"; if (compat2.Load(path)) { CheckSettings(compat2, gameID); } } }
engine * setup1_qm::CreateEngineByIndex(i32u eng_index) { if (eng_index >= GetEngineCount()) { cout << "setup1_qm::CreateEngineByIndex() failed!" << endl; return NULL; } GetModel()->UpdateIndex(); UpdateSetupInfo(); bool test = CheckSettings(this); if (!test) return NULL; i32s engtype1 = (eng_id_tab[eng_index] & 0xff00); i32s engtype2 = (eng_id_tab[eng_index] & 0x00ff); switch (engtype1) { #ifdef ENABLE_MOPAC7 case ENG1_QM_MOPAC: if (eng1_qm_mopac::GetLock() != NULL) { GetModel()->ErrorMessage("MOPAC lock failed!!!\nCan't run multiple MOPAC calculations."); return NULL; } else return new eng1_qm_mopac(this, 1, engtype2); #endif // ENABLE_MOPAC7 #ifdef ENABLE_MPQC case ENG1_QM_MPQC: return new eng1_qm_mpqc(this, 1, engtype2); #endif // ENABLE_MPQC default: cout << "fatal error at setup1_qm::CreateEngineByIndex()" << endl; return NULL; } }
//================================================================================================ //--------------------------------------------------==-+++--> Entry Point of Program Using WinMain: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wndclass; HWND hwndMain; MSG msg; int updated; (void)hPrevInstance; (void)nCmdShow; #if defined(__GNUC__) && defined(_DEBUG) # ifdef _WIN64 # define LoadExcHndl() LoadLibraryExA("dbg\\64\\exchndl", NULL, LOAD_WITH_ALTERED_SEARCH_PATH) # else # define LoadExcHndl() LoadLibraryExA("dbg\\exchndl", NULL, LOAD_WITH_ALTERED_SEARCH_PATH) # endif #else # define LoadExcHndl() #endif LoadExcHndl(); // LOAD_WITH_ALTERED_SEARCH_PATH works :P At least since Win2k g_instance = hInstance; if(LoadClockAPI("misc/T-Clock" ARCH_SUFFIX, &api)){ MessageBox(NULL, "Error loading: T-Clock" ARCH_SUFFIX ".dll", "API error", MB_OK|MB_ICONERROR); return 2; } chdir(api.root); // make sure we've got the right working directory // Make sure we're running Windows 2000 and above if(!api.OS) { MessageBox(NULL,"T-Clock requires Windows 2000 or newer","old OS",MB_OK|MB_ICONERROR); return 1; } // make sure ObjectBar isn't running -> From Original Code/Unclear if This is Still a Conflict. (test suggested not really.. no crash but no clock either :P) if(FindWindow("ObjectBar Main","ObjectBar")) { MessageBox(NULL,"ObjectBar and T-Clock can't be run together","ObjectBar detected!",MB_OK|MB_ICONERROR); return 1; } // Load ALL of the Global Resources g_hIconTClock = LoadIcon(api.hInstance, MAKEINTRESOURCE(IDI_MAIN)); g_hIconPlay = LoadImage(g_instance, MAKEINTRESOURCE(IDI_PLAY), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); g_hIconStop = LoadImage(g_instance, MAKEINTRESOURCE(IDI_STOP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); g_hIconDel = LoadImage(g_instance, MAKEINTRESOURCE(IDI_DEL), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); // FindTrayServer(hwndMain); // Make sure we're not running 32bit on 64bit OS / start the other one #ifndef _WIN64 if(IsWow64()){ hwndMain = FindWindow(g_szClassName, NULL); if(hwndMain) { // send commands to existing instance ProcessCommandLine(hwndMain,lpCmdLine); }else{ // start new instance char clock64[MAX_PATH]; memcpy(clock64, api.root, api.root_len+1); add_title(clock64,"Clock" ARCH_SUFFIX_64 ".exe"); api.Exec(clock64,lpCmdLine,NULL); } return 0; } #endif // _WIN64 // Do Not Allow the Program to Execute Twice! updated = 25; /**< wait up to 5 sec in 1/5th seconds for other instance */ do{ HANDLE processlock=CreateMutex(NULL,FALSE,g_szClassName); // we leak handle here, but Windows closes on process exit anyway (so why do it manually?) if(processlock && GetLastError()==ERROR_ALREADY_EXISTS){ CloseHandle(processlock); hwndMain = FindWindow(g_szClassName, NULL); if(hwndMain) { // This One Sends Commands to the Instance ProcessCommandLine(hwndMain,lpCmdLine); // That is Currently Running. return 0; } Sleep(200); continue; } break; }while(updated--); // Update settings if required and setup defaults if((updated=CheckSettings())<0){ return 1; } CancelAllTimersOnStartUp(); // Message of the taskbar recreating - Special thanks to Mr.Inuya g_WM_TaskbarCreated = RegisterWindowMessage("TaskbarCreated"); // register a window class wndclass.style = 0; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = g_instance; wndclass.hIcon = g_hIconTClock; wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)(intptr_t)(COLOR_WINDOW+1); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = g_szClassName; g_atomTClock = RegisterClass(&wndclass); if(api.OS >= TOS_VISTA) { // allow non elevated processes to send control messages (eg, App with admin rights, explorer without) #define MSGFLT_ADD 1 #define MSGFLT_REMOVE 2 typedef BOOL (WINAPI* ChangeWindowMessageFilter_t)(UINT message,DWORD dwFlag); ChangeWindowMessageFilter_t ChangeWindowMessageFilter=(ChangeWindowMessageFilter_t)GetProcAddress(GetModuleHandle("user32"), "ChangeWindowMessageFilter"); if(ChangeWindowMessageFilter){ int msgid; ChangeWindowMessageFilter(g_WM_TaskbarCreated,MSGFLT_ADD); ChangeWindowMessageFilter(WM_COMMAND,MSGFLT_ADD); for(msgid=WM_MOUSEFIRST; msgid<=WM_MOUSELAST; ++msgid) ChangeWindowMessageFilter(msgid,MSGFLT_ADD); for(msgid=MAINMFIRST; msgid<=MAINMLAST; ++msgid) ChangeWindowMessageFilter(msgid,MSGFLT_ADD); } } // create a hidden window g_hwndTClockMain = hwndMain = CreateWindowEx(WS_EX_NOACTIVATE, MAKEINTATOM(g_atomTClock),NULL, 0, 0,0,0,0, NULL,NULL,g_instance,NULL); // This Checks for First Instance Startup Options ProcessCommandLine(hwndMain,lpCmdLine); GetHotKeyInfo(hwndMain); if(api.OS > TOS_2000) { if(api.GetInt("Desktop", "MonOffOnLock", 0)) RegisterSession(hwndMain); } if(updated==1){ PostMessage(hwndMain,WM_COMMAND,IDM_SHOWPROP,0); } while(GetMessage(&msg, NULL, 0, 0)) { if(!(g_hwndSheet && IsWindow(g_hwndSheet) && PropSheet_IsDialogMessage(g_hwndSheet,&msg)) && !(g_hDlgTimer && IsWindow(g_hDlgTimer) && IsDialogMessage(g_hDlgTimer,&msg)) && !(g_hDlgTimerWatch && IsWindow(g_hDlgTimerWatch) && IsDialogMessage(g_hDlgTimerWatch,&msg)) && !(g_hDlgStopWatch && IsWindow(g_hDlgStopWatch) && IsDialogStopWatchMessage(g_hDlgStopWatch,&msg))){ TranslateMessage(&msg); DispatchMessage(&msg); } } UnregisterHotKey(hwndMain, HOT_TIMER); UnregisterHotKey(hwndMain, HOT_WATCH); UnregisterHotKey(hwndMain, HOT_STOPW); UnregisterHotKey(hwndMain, HOT_PROPR); UnregisterHotKey(hwndMain, HOT_CALEN); UnregisterHotKey(hwndMain, HOT_TSYNC); UnregisterSession(hwndMain); EndNewAPI(NULL); return (int)msg.wParam; }
int main(int argc, char* argv[]) #endif { #ifdef _XBOX int argc = 1; char *argv[] = {"default.xbe"}; #endif g_argc = argc; g_argv = argv; /* Set up arch hooks first. This may set up crash handling. */ HOOKS = MakeArchHooks(); CString g_sErrorString = ""; #if !defined(DEBUG) /* Always catch RageExceptions; they should always have distinct strings. */ try { /* RageException */ /* Tricky: for other exceptions, we want a backtrace. To do this in Windows, * we need to catch the exception and force a crash. The call stack is still * there, and gets picked up by the crash handler. (If we don't catch it, we'll * get a generic, useless "abnormal termination" dialog.) In Linux, if we do this * we'll only get main() on the stack, but if we don't catch the exception, it'll * just work. So, only catch generic exceptions in Windows. */ #if defined(_WINDOWS) try { /* exception */ #endif #endif /* Almost everything uses this to read and write files. Load this early. */ FILEMAN = new RageFileManager( argv[0] ); FILEMAN->MountInitialFilesystems(); /* Set this up next. Do this early, since it's needed for RageException::Throw. */ LOG = new RageLog(); /* Whew--we should be able to crash safely now! */ // // load preferences and mount any alternative trees. // PREFSMAN = new PrefsManager; ApplyLogPreferences(); WriteLogHeader(); /* Set up alternative filesystem trees. */ if( PREFSMAN->m_sAdditionalFolders != "" ) { CStringArray dirs; split( PREFSMAN->m_sAdditionalFolders, ",", dirs, true ); for( unsigned i=0; i < dirs.size(); i++) FILEMAN->Mount( "dir", dirs[i], "" ); } if( PREFSMAN->m_sAdditionalSongFolders != "" ) { CStringArray dirs; split( PREFSMAN->m_sAdditionalSongFolders, ",", dirs, true ); for( unsigned i=0; i < dirs.size(); i++) FILEMAN->Mount( "dir", dirs[i], "Songs" ); } MountTreeOfZips( ZIPS_DIR ); /* One of the above filesystems might contain files that affect preferences, eg Data/Static.ini. * Re-read preferences. */ PREFSMAN->ReadGlobalPrefsFromDisk(); ApplyLogPreferences(); #if defined(HAVE_SDL) SetupSDL(); #endif /* This needs PREFSMAN. */ Dialog::Init(); // // Create game objects // GAMESTATE = new GameState; /* This requires PREFSMAN, for PREFSMAN->m_bShowLoadingWindow. */ LoadingWindow *loading_window = MakeLoadingWindow(); if( loading_window == NULL ) RageException::Throw( "Couldn't open any loading windows." ); loading_window->Paint(); srand( time(NULL) ); // seed number generator /* Do this early, so we have debugging output if anything else fails. LOG and * Dialog must be set up first. It shouldn't take long, but it might take a * little time; do this after the LoadingWindow is shown, since we don't want * that to appear delayed. */ HOOKS->DumpDebugInfo(); #if defined(HAVE_TLS) LOG->Info( "TLS is %savailable", RageThread::GetSupportsTLS()? "":"not " ); #endif if( PREFSMAN->m_bFirstRun ) OnFirstRun(); CheckSettings(); GAMEMAN = new GameManager; THEME = new ThemeManager; ANNOUNCER = new AnnouncerManager; NOTESKIN = new NoteSkinManager; /* Set up the theme and announcer. */ ReadGamePrefsFromDisk(); if( PREFSMAN->m_iSoundWriteAhead ) LOG->Info( "Sound writeahead has been overridden to %i", PREFSMAN->m_iSoundWriteAhead ); SOUNDMAN = new RageSoundManager; SOUNDMAN->Init( PREFSMAN->GetSoundDrivers() ); SOUNDMAN->SetPrefs( PREFSMAN->m_fSoundVolume ); SOUND = new GameSoundManager; BOOKKEEPER = new Bookkeeper; LIGHTSMAN = new LightsManager(PREFSMAN->m_sLightsDriver); INPUTFILTER = new InputFilter; INPUTMAPPER = new InputMapper; INPUTQUEUE = new InputQueue; SONGINDEX = new SongCacheIndex; BANNERCACHE = new BannerCache; /* depends on SONGINDEX: */ SONGMAN = new SongManager(); SONGMAN->InitAll( loading_window ); // this takes a long time CRYPTMAN = new CryptManager; // need to do this before ProfileMan MEMCARDMAN = new MemoryCardManager; PROFILEMAN = new ProfileManager; PROFILEMAN->Init(); // must load after SONGMAN UNLOCKMAN = new UnlockSystem; NSMAN = new NetworkSyncManager( loading_window ); delete loading_window; // destroy this before init'ing Display ProcessArgsFirst(); DISPLAY = CreateDisplay(); DISPLAY->ChangeCentering( PREFSMAN->m_iCenterImageTranslateX, PREFSMAN->m_iCenterImageTranslateY, PREFSMAN->m_fCenterImageScaleX, PREFSMAN->m_fCenterImageScaleY ); TEXTUREMAN = new RageTextureManager(); TEXTUREMAN->SetPrefs( RageTextureManagerPrefs( PREFSMAN->m_iTextureColorDepth, PREFSMAN->m_iMovieColorDepth, PREFSMAN->m_bDelayedTextureDelete, PREFSMAN->m_iMaxTextureResolution, PREFSMAN->m_bForceMipMaps ) ); MODELMAN = new ModelManager; MODELMAN->SetPrefs( ModelManagerPrefs( PREFSMAN->m_bDelayedModelDelete ) ); StoreActualGraphicOptions( true ); SONGMAN->PreloadSongImages(); /* This initializes objects that change the SDL event mask, and has other * dependencies on the SDL video subsystem, so it must be initialized after DISPLAY. */ INPUTMAN = new RageInput; // These things depend on the TextureManager, so do them after! FONT = new FontManager; SCREENMAN = new ScreenManager; /* People may want to do something else while songs are loading, so do * this after loading songs. */ BoostAppPri(); ResetGame(); CodeDetector::RefreshCacheItems(); /* Initialize which courses are ranking courses here. */ SONGMAN->UpdateRankingCourses(); /* Run the second argcheck, you can do your other options here */ ProcessArgsSecond(); /* Run the main loop. */ GameLoop(); PREFSMAN->SaveGlobalPrefsToDisk(); SaveGamePrefsToDisk(); #if !defined(DEBUG) } catch( const RageException &e ) { /* Gracefully shut down. */ g_sErrorString = e.what(); } #endif SAFE_DELETE( SCREENMAN ); SAFE_DELETE( NSMAN ); /* Delete INPUTMAN before the other INPUTFILTER handlers, or an input * driver may try to send a message to INPUTFILTER after we delete it. */ SAFE_DELETE( INPUTMAN ); SAFE_DELETE( INPUTQUEUE ); SAFE_DELETE( INPUTMAPPER ); SAFE_DELETE( INPUTFILTER ); SAFE_DELETE( MODELMAN ); SAFE_DELETE( PROFILEMAN ); // PROFILEMAN needs the songs still loaded SAFE_DELETE( UNLOCKMAN ); SAFE_DELETE( CRYPTMAN ); SAFE_DELETE( MEMCARDMAN ); SAFE_DELETE( SONGMAN ); SAFE_DELETE( BANNERCACHE ); SAFE_DELETE( SONGINDEX ); SAFE_DELETE( SOUND ); /* uses GAMESTATE, PREFSMAN */ SAFE_DELETE( PREFSMAN ); SAFE_DELETE( GAMESTATE ); SAFE_DELETE( GAMEMAN ); SAFE_DELETE( NOTESKIN ); SAFE_DELETE( THEME ); SAFE_DELETE( ANNOUNCER ); SAFE_DELETE( BOOKKEEPER ); SAFE_DELETE( LIGHTSMAN ); SAFE_DELETE( SOUNDMAN ); SAFE_DELETE( FONT ); SAFE_DELETE( TEXTUREMAN ); SAFE_DELETE( DISPLAY ); Dialog::Shutdown(); SAFE_DELETE( LOG ); SAFE_DELETE( FILEMAN ); #if !defined(DEBUG) && defined(_WINDOWS) } catch( const exception &e ) { /* This can be things like calling std::string::reserve(-1), or out of memory. * This can also happen if we throw a RageException during a ctor, in which case * we want a crash dump. */ FAIL_M( e.what() ); } #endif if( g_sErrorString != "" ) HandleException( g_sErrorString ); SAFE_DELETE( HOOKS ); #ifndef _XBOX return 0; #endif }
main(int argc, char *argv[]) { ListNode *Curr, *Next; int OverrideType=TYPE_NONE; char *Tempstr=NULL; int result; //HTTPSetFlags(HTTP_NOCOMPRESS); StdIn=STREAMFromFD(0); STREAMSetTimeout(StdIn,0); ParseEnvironmentVariables(); DownloadQueue=ListCreate(); Tempstr=MCopyStr(Tempstr,"Movgrab ",Version,NULL); HTTPSetUserAgent(Tempstr); FormatPreference=CopyStr(FormatPreference,"mp4,flv,webm,m4v,mov,mpg,mpeg,wmv,avi,3gp,reference,mp3,m4a,wma,m3u8,m3u8-stream"); AddOutputFile("", TRUE); ParseCommandLine(argc, argv, DownloadQueue, &OverrideType); CheckSettings(); if (StrLen(Proxy)) { if (! SetGlobalConnectionChain(Proxy)) { printf("ERROR: Failed to set proxy settings to '%s'\n",Proxy); exit(1); } } if (Flags & FLAG_PRINT_USAGE) PrintUsage(); else if (Flags & FLAG_PRINT_VERSION) PrintVersion(); else if (! (Flags & FLAG_STDIN)) { if (ListSize(DownloadQueue)==0) PrintUsage(); } while (1) { if ((Flags & FLAG_STDIN) && (ListSize(DownloadQueue)==0) ) { Tempstr=STREAMReadLine(Tempstr,StdIn); StripTrailingWhitespace(Tempstr); ListAddItem(DownloadQueue,CopyStr(NULL,Tempstr)); } Curr=ListGetNext(DownloadQueue); while (Curr) { if (Flags & FLAG_TEST_SITES) { fprintf(stderr,"Checking %-20s ",Curr->Tag); fflush(NULL); } result=GrabMovie((char *) Curr->Item,OverrideType); Next=ListGetNext(Curr); //must do this after grab movie //incase more items added while grabbing if (Flags & FLAG_TEST_SITES) { if (result) fprintf(stderr," okay\n"); else fprintf(stderr," BROKEN\n"); } ListDeleteNode(Curr); Curr=Next; } if (Flags & FLAG_TEST_SITES) break; if (! (Flags & FLAG_STDIN)) break; } }
int main( int argc, char *argv[] ) { int fd = 0; int opt, opt_index; int result = -1; long bufSize = 0; // long writtenSize; int writtenSize = 0; long writtenSize_long = 0; char *bufTop = NULL; CNCL_P_SETTINGS Settings; char jobID[CN_START_JOBID_LEN]; char libPathBuf[CN_LIB_PATH_LEN]; void *libclss = NULL; struct option long_opt[] = { { "version", required_argument, NULL, OPT_VERSION }, { "filterpath", required_argument, NULL, OPT_FILTERPATH }, { "papersize", required_argument, NULL, OPT_PAPERSIZE }, { "mediatype", required_argument, NULL, OPT_MEDIATYPE }, { "grayscale", required_argument, NULL, OPT_COLORMODE }, { "duplexprint", required_argument, NULL, OPT_DUPLEXPRINT }, { "jobid", required_argument, NULL, OPT_JOBID }, { "uuid", required_argument, NULL, OPT_UUID }, { 0, 0, 0, 0 }, }; const char *p_ppd_name = getenv("PPD"); uint8_t *xmlBuf = NULL; int xmlBufSize; int retSize; char *tmpBuf = NULL; char uuid[UUID_LEN + 1]; DEBUG_PRINT( "[tocanonij] start tocanonij\n" ); /* init CNCL API */ GETSETCONFIGURATIONCOMMAND = NULL; GETSENDDATAPWGRASTERCOMMAND = NULL; GETPRINTCOMMAND = NULL; GETSTRINGWITHTAGFROMFILE = NULL; GETSETPAGECONFIGUARTIONCOMMAND = NULL; MAKEBJLSETTIMEJOB = NULL; GetProtocol = NULL; ParseCapabilityResponsePrint_HostEnv=NULL; MakeCommand_StartJob3 = NULL; ParseCapabilityResponsePrint_DateTime = NULL; MakeCommand_SetJobConfiguration = NULL; /* Init Settings */ memset( &Settings, 0x00, sizeof(CNCL_P_SETTINGS) ); InitpSettings( &Settings ); memset( uuid, '\0', sizeof(uuid) ); while( (opt = getopt_long( argc, argv, "0:", long_opt, &opt_index )) != -1) { switch( opt ) { case OPT_VERSION: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); break; case OPT_FILTERPATH: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); snprintf( libPathBuf, CN_LIB_PATH_LEN, "%s%s", optarg, CN_CNCL_LIBNAME ); break; case OPT_PAPERSIZE: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); Settings.papersize = ConvertStrToID( optarg, papersizeTbl ); if ( IsBorderless( optarg ) ){ Settings.borderlessprint = CNCL_PSET_BORDERLESS_ON; } else { Settings.borderlessprint = CNCL_PSET_BORDERLESS_OFF; } break; case OPT_MEDIATYPE: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); Settings.mediatype = ConvertStrToID( optarg, mediatypeTbl ); DEBUG_PRINT2( "[tocanonij] media : %d\n", Settings.mediatype ); break; #if 0 case OPT_BORDERLESSPRINT: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); if ( IsBorderless( optarg ) ){ Settings.borderlessprint = CNCL_PSET_BORDERLESS_ON; } else { Settings.borderlessprint = CNCL_PSET_BORDERLESS_OFF; } break; #endif case OPT_COLORMODE: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); Settings.colormode = ConvertStrToID( optarg, colormodeTbl ); break; case OPT_DUPLEXPRINT: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); //Settings.duplexprint = CNCL_PSET_DUPLEX_OFF; Settings.duplexprint = ConvertStrToID( optarg, duplexprintTbl); break; case OPT_UUID: strncpy( uuid, optarg, strlen(optarg) ); break; case OPT_JOBID: if( strlen( uuid ) == 0 ){ strncpy( uuid, optarg, strlen(optarg) ); } break; case '?': fprintf( stderr, "Error: invalid option %c:\n", optopt); break; default: break; } } /* dlopen */ /* Make progamname with path of execute progname. */ //snprintf( libPathBuf, CN_LIB_PATH_LEN, "%s%s", GetExecProgPath(), CN_CNCL_LIBNAME ); DEBUG_PRINT2( "[tocanonij] libPath : %s\n", libPathBuf ); if ( access( libPathBuf, R_OK ) ){ strncpy( libPathBuf, CN_CNCL_LIBNAME, CN_LIB_PATH_LEN ); } DEBUG_PRINT2( "[tocanonij] libPath : %s\n", libPathBuf ); libclss = dlopen( libPathBuf, RTLD_LAZY ); if ( !libclss ) { fprintf( stderr, "Error in dlopen\n" ); goto onErr1; } GETSETCONFIGURATIONCOMMAND = dlsym( libclss, "CNCL_GetSetConfigurationCommand" ); if ( dlerror() != NULL ) { fprintf( stderr, "Error in CNCL_GetSetConfigurationCommand. API not Found.\n" ); goto onErr2; } GETSENDDATAPWGRASTERCOMMAND = dlsym( libclss, "CNCL_GetSendDataPWGRasterCommand" ); if ( dlerror() != NULL ) { fprintf( stderr, "Error in CNCL_GetSendDataPWGRasterCommand\n" ); goto onErr2; } GETPRINTCOMMAND = dlsym( libclss, "CNCL_GetPrintCommand" ); if ( dlerror() != NULL ) { fprintf( stderr, "Error in CNCL_GetPrintCommand\n" ); goto onErr2; } GETSTRINGWITHTAGFROMFILE = dlsym( libclss, "CNCL_GetStringWithTagFromFile" ); if ( dlerror() != NULL ) { fprintf( stderr, "Error in CNCL_GetStringWithTagFromFile\n" ); goto onErr2; } GETSETPAGECONFIGUARTIONCOMMAND = dlsym( libclss, "CNCL_GetSetPageConfigurationCommand" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_GetSetPageConfigurationCommand\n" ); goto onErr2; } MAKEBJLSETTIMEJOB = dlsym( libclss, "CNCL_MakeBJLSetTimeJob" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_MakeBJLSetTimeJob\n" ); goto onErr2; } GetProtocol = dlsym( libclss, "CNCL_GetProtocol" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_MakeBJLSetTimeJob\n" ); goto onErr2; } ParseCapabilityResponsePrint_HostEnv = dlsym( libclss, "CNCL_ParseCapabilityResponsePrint_HostEnv" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_ParseCapabilityResponsePrint_HostEnv\n" ); goto onErr2; } MakeCommand_StartJob3 = dlsym( libclss, "CNCL_MakeCommand_StartJob3" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_MakeCommand_StartJob3\n" ); goto onErr2; } ParseCapabilityResponsePrint_DateTime = dlsym( libclss, "CNCL_ParseCapabilityResponsePrint_DateTime" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_ParseCapabilityResponsePrint_DateTime\n" ); goto onErr2; } MakeCommand_SetJobConfiguration = dlsym( libclss, "CNCL_MakeCommand_SetJobConfiguration" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_MakeCommand_SetJobConfiguration\n" ); goto onErr2; } /* Check Settings */ if ( CheckSettings( &Settings ) != 0 ) goto onErr2; #if 1 /* Dump Settings */ DumpSettings( &Settings ); #endif // const char *p_ppd_name = getenv("PPD"); CAPABILITY_DATA capability; memset(&capability, '\0', sizeof(CAPABILITY_DATA)); if( ! GetCapabilityFromPPDFile(p_ppd_name, &capability) ){ goto onErr3; } int prot = GetProtocol( (char *)capability.deviceID, capability.deviceIDLength ); if( prot == 2 ){ xmlBufSize = GETSTRINGWITHTAGFROMFILE( p_ppd_name, CNCL_FILE_TAG_CAPABILITY, (int *)CNCL_DECODE_EXEC, &xmlBuf ); unsigned short hostEnv = 0; hostEnv = ParseCapabilityResponsePrint_HostEnv( xmlBuf, xmlBufSize ); /* Set JobID */ strncpy( jobID, CN_START_JOBID2, sizeof(CN_START_JOBID2) ); /* Allocate Buffer */ bufSize = sizeof(char) * CN_BUFSIZE; if ( (bufTop = malloc( bufSize )) == NULL ) goto onErr2; /* Write StartJob Command */ int ret = 0; ret = MakeCommand_StartJob3( hostEnv, uuid, jobID, bufTop, bufSize, &writtenSize ); if ( ret != 0 ) { fprintf( stderr, "Error in CNCL_GetPrintCommand\n" ); goto onErr2; } /* WriteData */ if ( (retSize = write( 1, bufTop, writtenSize )) != writtenSize ) goto onErr2; char dateTime[15]; memset(dateTime, '\0', sizeof(dateTime)); ret = ParseCapabilityResponsePrint_DateTime( xmlBuf, xmlBufSize ); if( ret == 2 ){ time_t timer = time(NULL); struct tm *date = localtime(&timer); sprintf(dateTime, "%d%02d%02d%02d%02d%02d", date->tm_year+1900, date->tm_mon+1, date->tm_mday, date->tm_hour, date->tm_min, date->tm_sec); if ( (tmpBuf = malloc( bufSize )) == NULL ) goto onErr2; ret = MakeCommand_SetJobConfiguration( jobID, dateTime, tmpBuf, bufSize, &writtenSize ); /* WriteData */ if ( (retSize = write( 1, tmpBuf, writtenSize )) != writtenSize ) goto onErr2; // writtenSize += tmpWrittenSize; } } else{ /* Set JobID */ strncpy( jobID, CN_START_JOBID, sizeof(CN_START_JOBID) ); /* OutputSetTime */ if ( OutputSetTime( 1, jobID ) != 0 ) goto onErr2; /* Allocate Buffer */ bufSize = sizeof(char) * CN_BUFSIZE; if ( (bufTop = malloc( bufSize )) == NULL ) goto onErr2; /* Write StartJob Command */ if ( GETPRINTCOMMAND( bufTop, bufSize, &writtenSize_long, jobID, CNCL_COMMAND_START1 ) != 0 ) { fprintf( stderr, "Error in CNCL_GetPrintCommand\n" ); goto onErr2; } /* WriteData */ if ( (retSize = write( 1, bufTop, writtenSize_long )) != writtenSize_long ) goto onErr2; } /* Write SetConfiguration Command */ if ( (xmlBufSize = GETSTRINGWITHTAGFROMFILE( p_ppd_name, CNCL_FILE_TAG_CAPABILITY, (int*)CNCL_DECODE_EXEC, &xmlBuf )) < 0 ){ DEBUG_PRINT2( "[tocanonij] p_ppd_name : %s\n", p_ppd_name ); DEBUG_PRINT2( "[tocanonij] xmlBufSize : %d\n", xmlBufSize ); fprintf( stderr, "Error in CNCL_GetStringWithTagFromFile\n" ); goto onErr3; } if ( GETSETCONFIGURATIONCOMMAND( &Settings, jobID, bufSize, (void *)xmlBuf, xmlBufSize, bufTop, &writtenSize_long ) != 0 ){ fprintf( stderr, "Error in CNCL_GetSetConfigurationCommand\n" ); goto onErr3; } /* WriteData */ retSize = write( 1, bufTop, writtenSize_long ); /* Write Page Data */ while ( 1 ) { int readBytes = 0; int writeBytes; char *pCurrent; CNDATA CNData; long readSize = 0; unsigned short next_page; memset( &CNData, 0, sizeof(CNDATA) ); /* read magic number */ readBytes = read( fd, &CNData, sizeof(CNDATA) ); if ( readBytes > 0 ){ if ( CNData.magic_num != MAGIC_NUMBER_FOR_CNIJPWG ){ fprintf( stderr, "Error illeagal MagicNumber\n" ); goto onErr3; } if ( CNData.image_size < 0 ){ fprintf( stderr, "Error illeagal dataSize\n" ); goto onErr3; } } else if ( readBytes < 0 ){ if ( errno == EINTR ) continue; fprintf( stderr, "DEBUG:[tocanonij] tocnij read error, %d\n", errno ); goto onErr3; } else { DEBUG_PRINT( "DEBUG:[tocanonij] !!!DATA END!!!\n" ); break; /* data end */ } /* Write Next Page Info */ if ( CNData.next_page ) { next_page = CNCL_PSET_NEXTPAGE_ON; } else { next_page = CNCL_PSET_NEXTPAGE_OFF; } if ( GETSETPAGECONFIGUARTIONCOMMAND( jobID, next_page, bufTop, bufSize, &writtenSize_long ) != 0 ) { fprintf( stderr, "Error in CNCL_GetPrintCommand\n" ); goto onErr3; } /* WriteData */ if ( (retSize = write( 1, bufTop, writtenSize_long )) != writtenSize_long ) goto onErr3; /* Write SendData Command */ memset( bufTop, 0x00, bufSize ); readSize = CNData.image_size; if ( GETSENDDATAPWGRASTERCOMMAND( jobID, readSize, bufSize, bufTop, &writtenSize_long ) != 0 ) { DEBUG_PRINT( "Error in CNCL_GetSendDataJPEGCommand\n" ); goto onErr3; } /* WriteData */ retSize = write( 1, bufTop, writtenSize_long ); while( readSize ){ pCurrent = bufTop; if ( readSize - bufSize > 0 ){ readBytes = read( fd, bufTop, bufSize ); DEBUG_PRINT2( "[tocanonij] PASS tocanonij READ1<%d>\n", readBytes ); if ( readBytes < 0 ) { if ( errno == EINTR ) continue; } readSize -= readBytes; } else { readBytes = read( fd, bufTop, readSize ); DEBUG_PRINT2( "[tocanonij] PASS tocanonij READ2<%d>\n", readBytes ); if ( readBytes < 0 ) { if ( errno == EINTR ) continue; } readSize -= readBytes; } do { writeBytes = write( 1, pCurrent, readBytes ); DEBUG_PRINT2( "[tocanonij] PASS tocanonij WRITE<%d>\n", writeBytes ); if( writeBytes < 0){ if ( errno == EINTR ) continue; goto onErr3; } readBytes -= writeBytes; pCurrent += writeBytes; } while( writeBytes > 0 ); } } /* CNCL_GetPrintCommand */ if ( GETPRINTCOMMAND( bufTop, bufSize, &writtenSize_long, jobID, CNCL_COMMAND_END ) != 0 ) { DEBUG_PRINT( "Error in CNCL_GetPrintCommand\n" ); goto onErr3; } /* WriteData */ retSize = write( 1, bufTop, writtenSize_long ); DEBUG_PRINT( "[tocanonij] to_cnijf <end>\n" ); result = 0; onErr3: if ( xmlBuf != NULL ){ free( xmlBuf ); } onErr2: if ( bufTop != NULL ){ free( bufTop ); } onErr1: if ( libclss != NULL ) { dlclose( libclss ); } if( tmpBuf != NULL ){ free(tmpBuf); } return result; }