// ################################################################# // 計算領域のセルIDとカット情報を設定する void IP_Step::setup(int* bcd, Control* R, const int NoMedium, const MediumList* mat, const int NoCompo, const CompoList* cmp, long long* cut, int* bid) { int mid_fluid; /// 流体 int mid_solid; /// 固体 // 流体 if ( (mid_fluid = FBUtility::findIDfromLabel(mat, NoMedium, m_fluid)) == 0 ) { Hostonly_ printf("\tLabel '%s' is not listed in MediumList\n", m_fluid.c_str()); Exit(0); } // 固体 if ( (mid_solid = FBUtility::findIDfromLabel(mat, NoMedium, m_solid)) == 0 ) { Hostonly_ printf("\tLabel '%s' is not listed in MediumList\n", m_solid.c_str()); Exit(0); } // ローカル int ix = size[0]; int jx = size[1]; int kx = size[2]; int gd = guide; REAL_TYPE dx = pitch[0]; //REAL_TYPE dy = pitch[1]; REAL_TYPE dz = pitch[2]; // ローカルな無次元位置 REAL_TYPE ox, oz; ox = origin[0]; oz = origin[2]; // step length 有次元値 REAL_TYPE len = G_origin[0] + width/R->RefLength; // グローバルな無次元位置 // step height 有次元値 REAL_TYPE ht = G_origin[2] + height/R->RefLength; // グローバルな無次元位置 #pragma omp parallel for firstprivate(ix, jx, kx, gd, mid_solid, ox, oz, dx, dz, len, ht) schedule(static) for (int k=1; k<=kx; k++) { for (int j=1; j<=jx; j++) { for (int i=1; i<=ix; i++) { size_t m = _F_IDX_S3D(i, j, k, ix, jx, kx, gd); REAL_TYPE x = ox + 0.5*dx + dx*(i-1); // position of cell center REAL_TYPE z = oz + 0.5*dz + dz*(k-1); // position of cell center REAL_TYPE s = (len - x)/dx; if ( z <= ht ) { if ( (x <= len) && (len < x+dx) ) { setBit5(bid[m], mid_solid, X_plus); int r = quantize9(s); setCut9(cut[m], r, X_plus); size_t m1 = _F_IDX_S3D(i+1, j, k, ix, jx, kx, gd); setBit5(bid[m1], mid_solid, X_minus); int rr = quantize9(1.0-s); setCut9(cut[m1], rr, X_minus); } else if ( (x-dx < len) && (len < x) ) { setBit5(bid[m], mid_solid, X_minus); int r = quantize9(-s); setCut9(cut[m], r, X_minus); size_t m1 = _F_IDX_S3D(i-1, j, k, ix, jx, kx, gd); setBit5(bid[m1], mid_solid, X_plus); int rr = quantize9(1.0+s); setCut9(cut[m1], rr, X_plus); } } } } } #pragma omp parallel for firstprivate(ix, jx, kx, gd, mid_solid, ox, oz, dx, dz, len, ht) schedule(static) for (int k=1; k<=kx; k++) { for (int j=1; j<=jx; j++) { for (int i=1; i<=ix; i++) { size_t m = _F_IDX_S3D(i, j, k, ix, jx, kx, gd); REAL_TYPE x = ox + 0.5*dx + dx*(i-1); // position of cell center REAL_TYPE z = oz + 0.5*dz + dz*(k-1); // position of cell center REAL_TYPE c = (ht - z)/dz; if ( x <= len ) { if ( (z <= ht) && (ht < z+dz) ) { setBit5(bid[m], mid_solid, Z_plus); int r = quantize9(c); setCut9(cut[m], r, Z_plus); size_t m1 = _F_IDX_S3D(i, j, k+1, ix, jx, kx, gd); setBit5(bid[m1], mid_solid, Z_minus); int rr = quantize9(1.0-c); setCut9(cut[m1], rr, Z_minus); } else if ( (z-dz < ht) && (ht < z) ) { setBit5(bid[m], mid_solid, Z_minus); int r = quantize9(-c); setCut9(cut[m], r, Z_minus); size_t m1 = _F_IDX_S3D(i, j, k-1, ix, jx, kx, gd); setBit5(bid[m1], mid_solid, Z_plus); int rr = quantize9(1.0+c); setCut9(cut[m1], rr, Z_plus); } } } } } // ステップ部のガイドセルの設定 // 隣接ランクのIDを取得 nID[6] const int* nID = paraMngr->GetNeighborRankID(procGrp); if ( nID[X_minus] < 0 ) { // デフォルトでガイドセルをSolidにする #pragma omp parallel for firstprivate(ix, jx, kx, gd, mid_solid) schedule(static) for (int k=1; k<=kx; k++) { for (int j=1; j<=jx; j++) { // 媒質エントリ size_t m = _F_IDX_S3D(0, j, k, ix, jx, kx, gd); setMediumID(bcd[m], mid_solid); // 交点 size_t l = _F_IDX_S3D(1 , j , k , ix, jx, kx, gd); int r = quantize9(0.5); setCut9(cut[l], r, X_minus); // 境界ID setBit5(bid[l], mid_solid, X_minus); } } // Channel #pragma omp parallel for firstprivate(ix, jx, kx, gd, mid_fluid, ht, oz, dz) schedule(static) for (int k=1; k<=kx; k++) { for (int j=1; j<=jx; j++) { REAL_TYPE z = oz + ( (REAL_TYPE)k-0.5 ) * dz; if ( z > ht ) { size_t m = _F_IDX_S3D(0, j, k, ix, jx, kx, gd); setMediumID(bcd[m], mid_fluid); size_t l = _F_IDX_S3D(1 , j , k , ix, jx, kx, gd); int r = quantize9(1.0); setCut9(cut[l], r, X_minus); setBit5(bid[l], 0, X_minus); } } } } }
void App::Run() { DisplayName = DISPLAY; #ifdef XNEST_DEBUG char* p = getenv("DISPLAY"); if (p && p[0]) { DisplayName = p; cout << "Using display name " << DisplayName << endl; } #endif // Read configuration and theme cfg.readConf(CFGFILE); string themebase = ""; string themefile = ""; string themedir = ""; themeName = ""; if (testing) { themeName = testtheme; } else { themebase = string(THEMESDIR) + "/"; themeName = cfg.getOption("current_theme"); string::size_type pos; if ((pos = themeName.find(",")) != string::npos) { // input is a set themeName = findValidRandomTheme(themeName); if (themeName == "") { themeName = "default"; } } } bool loaded = false; while (!loaded) { themedir = themebase + themeName; themefile = themedir + THEMESFILE; if (!cfg.readConf(themefile)) { if (themeName == "default") { cerr << APPNAME << ": Failed to open default theme file " << themefile << endl; exit(ERR_EXIT); } else { cerr << APPNAME << ": Invalid theme in config: " << themeName << endl; themeName = "default"; } } else { loaded = true; } } if (!testing) { // Create lock file LoginApp->GetLock(); // Start x-server setenv("DISPLAY", DisplayName, 1); signal(SIGQUIT, CatchSignal); signal(SIGTERM, CatchSignal); signal(SIGKILL, CatchSignal); signal(SIGINT, CatchSignal); signal(SIGHUP, CatchSignal); signal(SIGPIPE, CatchSignal); signal(SIGUSR1, User1Signal); signal(SIGALRM, AlarmSignal); #ifndef XNEST_DEBUG OpenLog(); if (cfg.getOption("daemon") == "yes") { daemonmode = true; } // Daemonize if (daemonmode) { if (daemon(0, 1) == -1) { cerr << APPNAME << ": " << strerror(errno) << endl; exit(ERR_EXIT); } } StartServer(); alarm(2); #endif } // Open display if((Dpy = XOpenDisplay(DisplayName)) == 0) { cerr << APPNAME << ": could not open display '" << DisplayName << "'" << endl; if (!testing) StopServer(); exit(ERR_EXIT); } // Get screen and root window Scr = DefaultScreen(Dpy); Root = RootWindow(Dpy, Scr); // for tests we use a standard window if (testing) { Window RealRoot = RootWindow(Dpy, Scr); Root = XCreateSimpleWindow(Dpy, RealRoot, 0, 0, 640, 480, 0, 0, 0); XMapWindow(Dpy, Root); XFlush(Dpy); } else { blankScreen(); } HideCursor(); // Create panel LoginPanel = new Panel(Dpy, Scr, Root, &cfg, themedir); // Start looping XEvent event; int panelclosed = 1; int Action; bool firstloop = true; // 1st time panel is shown (for automatic username) while(1) { if(panelclosed) { // Init root setBackground(themedir); // Close all clients if (!testing) { KillAllClients(False); KillAllClients(True); } // Show panel LoginPanel->OpenPanel(); } Action = WAIT; LoginPanel->GetInput()->Reset(); if (firstloop && cfg.getOption("default_user") != "") { LoginPanel->GetInput()->SetName(cfg.getOption("default_user") ); firstloop = false; } while(Action == WAIT) { XNextEvent(Dpy, &event); Action = LoginPanel->EventHandler(&event); } if(Action == FAIL) { panelclosed = 0; LoginPanel->ClearPanel(); XBell(Dpy, 100); } else { // for themes test we just quit if (testing) { Action = EXIT; } panelclosed = 1; LoginPanel->ClosePanel(); switch(Action) { case LOGIN: Login(); break; case CONSOLE: Console(); break; case REBOOT: Reboot(); break; case HALT: Halt(); break; case SUSPEND: Suspend(); break; case EXIT: Exit(); break; } } } }
void ColourPickerActivity::OnTryExit(ExitMethod method) { Exit(); }
void RecoverState(QHLP_PAR *qhlp) { ISI_DL snapshot; ISI_DL_SYS sys; QDPLUS_PKT pkt; struct { ISI_SEQNO seqno; UINT32 index; } beg, end; static char *fid = "RecoverState"; /* Get the current state of the disk loop */ if (!isidlSnapshot(qhlp->input.dl, &snapshot, &sys)) { LogMsg("%s: isidlSnapshot failed: %s", fid, strerror(errno)); Exit(MY_MOD_ID + 3); } /* If there isn't any preserved state, then configure to dump the entire QDP disk loop */ if (qhlp->qdplus->state != QDPLUS_STATE_OK) { LogMsg("no valid HLP state data found, default to oldest QDP data available"); history.nxtndx = snapshot.sys->index.oldest; history.endndx = snapshot.sys->index.yngest; if (!VerifyIndicies(&snapshot)) Exit(MY_MOD_ID + 4); qdplusSetLcqStateFlag(qhlp->qdplus, QDP_LCQ_STATE_PRODUCTION); LogMsg("going into production mode with nxtndx=0x%08x, endndx=0x%08x\n", history.nxtndx, history.endndx); return; } /* We have state... find the range of packets to preload */ if (!qdplusStateSeqnoLimits(qhlp->qdplus, &beg.seqno, &end.seqno)) { LogMsg("%s: qdplusStateSeqnoLimits: %s", fid, strerror(errno)); Exit(MY_MOD_ID + 5); } if (isiIsUndefinedSeqno(&beg.seqno) || isiIsUndefinedSeqno(&end.seqno)) { LogMsg("empty HLP state data found, default to oldest QDP data available"); history.nxtndx = snapshot.sys->index.oldest; history.endndx = snapshot.sys->index.yngest; if (!VerifyIndicies(&snapshot)) Exit(MY_MOD_ID + 6); qdplusSetLcqStateFlag(qhlp->qdplus, QDP_LCQ_STATE_PRODUCTION); LogMsg("going into production mode with nxtndx=0x%08x, endndx=0x%08x\n", history.nxtndx, history.endndx); return; } if (!isiIsAbsoluteSeqno(&beg.seqno) || !isiIsAbsoluteSeqno(&end.seqno)) { LogMsg("%s: unexpected non-absolute sequence numbers", fid); Exit(MY_MOD_ID + 7); } beg.index = isidlSearchDiskLoopForSeqno(&snapshot, &beg.seqno, ISI_UNDEFINED_INDEX, ISI_UNDEFINED_INDEX); LogMsg("beg.seqno = %s, beg.index = 0x%08x\n", isiSeqnoString(&beg.seqno, NULL), beg.index); end.index = isidlSearchDiskLoopForSeqno(&snapshot, &end.seqno, ISI_UNDEFINED_INDEX, ISI_UNDEFINED_INDEX); LogMsg("end.seqno = %s, end.index = 0x%08x\n", isiSeqnoString(&end.seqno, NULL), end.index); /* If we can't find the desired packets (disk loop overwritten?) then start with current data */ if (!isiIsValidIndex(beg.index) || !isiIsValidIndex(end.index)) { LogMsg("unable to locate dl indices for HLP state data, default to start with current QDP data"); history.nxtndx = snapshot.sys->index.yngest; history.endndx = snapshot.sys->index.yngest; if (!VerifyIndicies(&snapshot)) Exit(MY_MOD_ID + 8); qdplusSetLcqStateFlag(qhlp->qdplus, QDP_LCQ_STATE_PRODUCTION); LogMsg("going into production mode with nxtndx=0x%08x, endndx=0x%08x\n", history.nxtndx, history.endndx); return; } /* We know where to find the data to backfill, set up reader accordingly */ history.nxtndx = beg.index; history.endndx = end.index; if (!VerifyIndicies(&snapshot)) Exit(MY_MOD_ID + 9); /* Backfill the LCQ */ qdplusSetLcqStateFlag(qhlp->qdplus, QDP_LCQ_STATE_INITIALIZE); LogMsg("recovering state with data from indicies 0x%08x through 0x%08x", history.nxtndx, history.endndx); do { QuitOnShutdown(MY_MOD_ID + 9); ReadNextPacket(qhlp, &pkt); if (qdplusProcessPacket(qhlp->qdplus, &pkt) == NULL) { LogMsg("%s: qdplusProcessPacket failed: %s", fid, strerror(errno)); Exit(MY_MOD_ID + 10); } } while (history.status == DATA_AVAILABLE); qdplusSetLcqStateFlag(qhlp->qdplus, QDP_LCQ_STATE_PRODUCTION); LogMsg("state recovery complete"); }
void CMenuTeam::OnPrevious(void) { // Go to the previous screen Exit(MENUACTION_PREVIOUS); }
void main(int argc, char ** argv) { Circular_Buffer * cir_buffer; uint32 h_mem; sem_t s_procs_completed; char hello_world[STRING_LENGTH] = "Hello world"; int ct = 0; if (argc != 3) { Printf("Usage: "); Printf(argv[0]); Printf(" <handle_to_shared_memory_page> <handle_to_page_mapped_semaphore>\n"); Exit(); } // Convert the command-line strings into integers for use as handles h_mem = dstrtol(argv[1], NULL, 10); // The "10" means base 10 s_procs_completed = dstrtol(argv[2], NULL, 10); // Map shared memory page into this process's memory space if ((cir_buffer = (Circular_Buffer *)shmat(h_mem)) == NULL) { Printf("Could not map the virtual address to the memory in "); Printf(argv[0]); Printf(", exiting...\n"); Exit(); } while(ct < STRING_LENGTH){ // Get the lock if(lock_acquire(cir_buffer->buffer_lock) != SYNC_SUCCESS){ Printf("Get the lock failed !!!!!!!!!!!!!!!!!!\n"); Exit(); } /* Printf("Producer %d holds the lock %d, head = %d, tail = %d\n", getpid(), cir_buffer->buffer_lock, cir_buffer->head, cir_buffer->tail); */ // Producer an item to the buffer if((cir_buffer->head + 1) % BUFFERSIZE == cir_buffer->tail){ // The buffer is full, do nothing } else{ // Insert the character cir_buffer->space[cir_buffer->head] = hello_world[ct]; /* Printf("buffer lock: %d\n", cir_buffer->buffer_lock); */ Printf("Producer %d inserted: %c\n", getpid(), hello_world[ct]); // Update head and ct ct++; cir_buffer->head = (cir_buffer->head + 1) % BUFFERSIZE; } // Release the lock if(lock_release(cir_buffer->buffer_lock) != SYNC_SUCCESS){ Printf("Producer %d release the lock %d failed !!!!!!!!!!!!!!!!!!\n", getpid(), cir_buffer->buffer_lock); Exit(); } } // Signal the semaphore to tell the original process that we're done Printf("Producer: PID %d is complete.\n", getpid()); if(sem_signal(s_procs_completed) != SYNC_SUCCESS) { Printf("Bad semaphore s_procs_completed (%d) in ", s_procs_completed); Printf(argv[0]); Printf(", exiting...\n"); Exit(); } return; }
WizardExport WizardBooleanType ExportKeyring(int argc,char **argv, ExceptionInfo *exception) { #define DestroyKeyring() \ { \ for (i=0; i < (ssize_t) argc; i++) \ argv[i]=DestroyString(argv[i]); \ argv=(char **) RelinquishWizardMemory(argv); \ } #define ThrowKeyringException(asperity,tag,context) \ { \ (void) ThrowWizardException(exception,GetWizardModule(),asperity,tag, \ context); \ DestroyKeyring(); \ return(WizardFalse); \ } #define ThrowInvalidArgumentException(option,argument) \ { \ (void) ThrowWizardException(exception,GetWizardModule(),OptionError, \ "invalid argument: `%s': %s",argument,option); \ DestroyKeyring(); \ return(WizardFalse); \ } const char *filename, *keyring, *option; KeyringInfo *keyring_info; register ssize_t i; StringInfo *id; WizardBooleanType status; /* Parse command-line options. */ status=WizardFalse; keyring=(const char *) NULL; id=(StringInfo *) NULL; filename=argv[argc-1]; for (i=1; i < (ssize_t) (argc-1); i++) { option=argv[i]; if (IsWizardOption(option) != WizardFalse) switch (*(option+1)) { case 'd': { if (LocaleCompare(option,"-debug") == 0) { LogEventType event_mask; i++; if (i == (ssize_t) argc) ThrowKeyringException(OptionError,"missing log event mask: " "`%s'",option); event_mask=SetLogEventMask(argv[i]); if (event_mask == UndefinedEvents) ThrowKeyringException(OptionFatalError,"unrecognized log event " "type: `%s'",argv[i]); break; } ThrowKeyringException(OptionFatalError,"unrecognized option: `%s'", option); break; } case 'e': { if (LocaleCompare("export",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowKeyringException(OptionError,"missing key id: `%s'", option); id=HexStringToStringInfo(argv[i]); break; } ThrowKeyringException(OptionFatalError,"unrecognized option: `%s'", option); break; } case 'h': { if ((LocaleCompare("help",option+1) == 0) || (LocaleCompare("-help",option+1) == 0)) KeyringUsage(); ThrowKeyringException(OptionFatalError,"unrecognized option: `%s'", option); break; } case 'l': { if (LocaleCompare(option,"-list") == 0) { ssize_t list; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowKeyringException(OptionError,"missing list type: `%s'", option); if (LocaleCompare(argv[i],"configure") == 0) { (void) ListConfigureInfo((FILE *) NULL,exception); Exit(0); } list=ParseWizardOption(WizardListOptions,WizardFalse,argv[i]); if (list < 0) ThrowKeyringException(OptionFatalError,"unrecognized list " "type: `%s'",argv[i]); (void) ListWizardOptions((FILE *) NULL,(WizardOption) list, exception); Exit(0); break; } if (LocaleCompare("log",option+1) == 0) { if (*option == '+') break; i++; if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL)) ThrowKeyringException(OptionFatalError,"missing argument: `%s'", option); break; } ThrowKeyringException(OptionFatalError,"unrecognized option: `%s'", option); break; } case 'v': { if (LocaleCompare(option,"-version") == 0) { (void) fprintf(stdout,"Version: %s\n",GetWizardVersion( (size_t *) NULL)); (void) fprintf(stdout,"Copyright: %s\n\n",GetWizardCopyright()); exit(0); } ThrowKeyringException(OptionFatalError,"unrecognized option: `%s'", option); break; } default: { ThrowKeyringException(OptionFatalError,"unrecognized option: `%s'", option); break; } } /* Export key from keyring. */ keyring_info=AcquireKeyringInfo(keyring); SetKeyringId(keyring_info,id); if (ExportKeyringKey(keyring_info,exception) == WizardFalse) { char *hex_id; hex_id=StringInfoToHexString(id); (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, "no such key `%s': `%s'",hex_id,keyring); hex_id=DestroyString(hex_id); } else { SetKeyringPath(keyring_info,filename); status=ImportKeyringKey(keyring_info,exception); } id=DestroyStringInfo(id); keyring_info=DestroyKeyringInfo(keyring_info); } /* Free resources. */ DestroyKeyring(); return(status); }
/** * \brief Main function. */ int main(int argc, char **argv) { char *s,*t; int size,sizes,sizet; int i,j,k,P; int cond; int *simi,res,Paux; int *a,*b; FILE *f,*f2; fpos_t filepos; int my_rank,set; struct timeval ini, fi; struct timezone tz; bsp_begin(atoi(argv[1])); size = atoi(argv[1]); f=fopen(argv[2],"r"); if (f==NULL) Exit("Error: File %s not found\n",argv[2]); fscanf(f,"%d",&sizes); if (sizes%size != 0) Exit("Error: The sequences have to have multiple of " "processes quantity size"); f2=fopen(argv[3],"r"); if (f2==NULL) Exit("Error: File %s not found\n",argv[3]); fscanf(f2,"%d",&sizet); if (bsp_pid() == 0) if (sizet%size != 0) Exit("Error: The sequences have to have multiple of " "processes quantity size"); P = atoi(argv[4]); if (bsp_pid() == 0) printf("align %d %s %s %d\n",size,argv[2],argv[3],P); sizes /= size; sizet /= size; s = (char*) malloc (sizes*sizeof(char)); t = (char*) malloc (sizet*sizeof(char)); if (s == NULL || t == NULL) Exit("No memory\n"); a = (int*)malloc ((sizet+1)*sizeof(int)); b = (int*)malloc ((sizes+1)*sizeof(int)); if (a == NULL || b == NULL) Exit("No memory\n"); if (bsp_pid() == size-1) { simi = (int*) malloc(P*sizeof(int)); if (simi == NULL) Exit("No memory\n"); } Paux = 0; bsp_push_reg(s,sizes*sizeof(char)); bsp_push_reg(b,(sizes+1)*sizeof(int)); bsp_push_reg(&filepos,sizeof(long int)); bsp_push_reg(&i,sizeof(int)); bsp_sync(); gettimeofday(&ini,&tz); for (k = 0; k < P*size + size -1; k++) { if (k >= bsp_pid() && k <= P*size+bsp_pid()-1) cond = 1; else cond = 0; set = 0; if (cond==1 && (k-bsp_pid())%size == 0)/*start of a reading*/ { if (bsp_pid() == 0 && k < size); else if (bsp_pid() == 0) { bsp_get(size-1,&filepos,0,&filepos,sizeof(long int)); } else { bsp_get(bsp_pid()-1,&filepos,0,&filepos,sizeof(long int)); } set = 1; } bsp_sync(); if (cond==1 && (k-bsp_pid())%size == 0)/*start of a reading*/ { if (set == 1) fsetpos(f2,&filepos); for (i = 0; i < sizet; i++) { fscanf(f2,"%c",&t[i]); if (t[i] == 'A' ||t[i] == 'T' ||t[i] == 'C' ||t[i] == 'G'); else { if (t[i] == EOF) Exit("Error: End of file reached without" "read all sequence in %s\n",argv[3]); i--; } } fgetpos(f2,&filepos); for (i = 0; i <= sizet; i++) a[i] = (i+bsp_pid()*sizet)*gap; } if (cond==1) { if (bsp_pid() == 0) { for (i = 0; i < sizes; i++) { fscanf(f,"%c",&s[i]); if (s[i] == 'A' ||s[i] == 'T' ||s[i] == 'C' ||s[i] == 'G'); else { if (s[i] == EOF) Exit("Error: End of file reached without" "read all sequence in %s\n",argv[2]); i--; } } for (j = 0; j <= sizes; j++) b[j] = (j + (k%size)*sizes)*gap; } res = Similarity (s, sizes, t, sizet, a, b); if (bsp_pid() == size-1 && (k-bsp_pid()+1)%size == 0) { simi[Paux++] = res; } } if (cond) { if (bsp_pid() != size -1) { bsp_put(bsp_pid()+1,s,s,0,sizes*sizeof(char)); bsp_put(bsp_pid()+1,b,b,0,(sizes+1)*sizeof(int)); } } bsp_sync(); } gettimeofday(&fi,&tz); printf("process %d ended\n",bsp_pid()); fclose(f); fclose(f2); if (bsp_pid() == size-1) { printf("Similarities: "); for (i = 0; i < P; i++) printf("%d ",simi[i]); printf("\n"); } if (bsp_pid() == 0) { printf("Computation time: %f\n", (fi.tv_sec - ini.tv_sec + (double)(fi.tv_usec - ini.tv_usec)/1000000)/60); } bsp_pop_reg(&filepos); bsp_pop_reg(b); bsp_pop_reg(s); bsp_sync(); return 0; }
void main(int argc, char ** argv) { Circular_Buffer * cir_buffer; uint32 h_mem; sem_t s_procs_completed; int ct = 0; if (argc != 3) { Printf("Usage: "); Printf(argv[0]); Printf(" <handle_to_shared_memory_page> <handle_to_page_mapped_semaphore>\n"); Exit(); } // Convert the command-line strings into integers for use as handles h_mem = dstrtol(argv[1], NULL, 10); // The "10" means base 10 s_procs_completed = dstrtol(argv[2], NULL, 10); // Map shared memory page into this process's memory space if ((cir_buffer = (Circular_Buffer *)shmat(h_mem)) == NULL) { Printf("Could not map the virtual address to the memory in "); Printf(argv[0]); Printf(", exiting...\n"); Exit(); } while(ct < STRING_LENGTH){ // Get the lock if(lock_acquire(cir_buffer->buffer_lock) != SYNC_SUCCESS){ Printf("Get the lock failed !!!!!!!!!!!!!!!!!!\n"); Exit(); } /* Printf("Consumer %d holds the lock %d, head = %d, tail = %d\n", getpid(), cir_buffer->buffer_lock, cir_buffer->head, cir_buffer->tail); */ //Printf("Consumer, before checking if buffer empty.\n"); // Consume an item to the buffer while(cir_buffer->head == cir_buffer->tail){ // conditional wait when empty if(cond_wait(cir_buffer->buffer_cond) != SYNC_SUCCESS) { Printf("Consumer conditional wait not empty unsuccessful.\n"); Exit(); } } // Remove the character Printf("Consumer %d removed: %c\n", getpid(), cir_buffer->space[cir_buffer->tail]); if (cir_buffer->nitem == 5) { if(cond_signal(cir_buffer->buffer_cond) != SYNC_SUCCESS) { Printf("Consumer conditioanl signal not full unsuccessful.\n"); Exit(); } } // Update tail and ct ct++; cir_buffer->tail = (cir_buffer->tail + 1) % BUFFERSIZE; cir_buffer->nitem -= 1; // Release the lock if(lock_release(cir_buffer->buffer_lock) != SYNC_SUCCESS){ Printf("Consumer %d release the lock %d failed !!!!!!!!!!!!!!!!!!\n", getpid(), cir_buffer->buffer_lock); Exit(); } } // Signal the semaphore to tell the original process that we're done Printf("Consumer: PID %d is complete.\n", getpid()); if(sem_signal(s_procs_completed) != SYNC_SUCCESS) { Printf("Bad semaphore s_procs_completed (%d) in ", s_procs_completed); Printf(argv[0]); Printf(", exiting...\n"); Exit(); } return; }
bool DEncrypt(const char* filename) { //Open allocate/read a file into memory FILE *pFile; pFile = fopen (filename, "rb"); if(! pFile) Exit("Failed to open input file\n"); long lFileSize; //Size of input file unsigned char *pBuff; //Holds the input file contents unsigned char *pOutBuff; //Holds the output goodies // obtain file size. fseek (pFile , 0 , SEEK_END); lFileSize= ftell (pFile); rewind (pFile); // allocate memory to contain the whole file. pBuff = (unsigned char*) malloc (lFileSize); pOutBuff = (unsigned char*) malloc (lFileSize); if (pBuff == NULL || pOutBuff == NULL) { fclose(pFile); std::cout << "Could not allocate buffer" << std::endl; return false; } // copy the file into the buffer. fread (pBuff,1,lFileSize,pFile); //clean the output buffer memset(pOutBuff,NULL,lFileSize); fclose(pFile); //Lets start the ice goodies! IceKey ice( 0 ); // level 0 = 64bit key ice.set( (unsigned char*) g_ICEKey ); // set key int blockSize = ice.blockSize(); unsigned char *p1 = pBuff; unsigned char *p2 = pOutBuff; // encrypt data in 8 byte blocks int bytesLeft = lFileSize; while ( bytesLeft >= blockSize ) { if ( g_Encrypt ) ice.encrypt( p1, p2 ); else ice.decrypt( p1, p2 ); bytesLeft -= blockSize; p1+=blockSize; p2+=blockSize; } //The end chunk doesn't get an encryption? that sux... memcpy( p2, p1, bytesLeft ); size_t outLength = strlen(filename) + MAX_EXTENSION + 1; char *pOutPath = (char *)malloc(outLength); strncpy(pOutPath,filename,outLength); SetExtension(pOutPath, outLength, g_Extension); pFile = fopen (pOutPath , "wb"); if(pFile == NULL) { fprintf( stderr, "Was not able to open output file for writing.\n" ); free(pBuff); free(pOutBuff); free(pOutPath); return false; } fwrite (pOutBuff , 1 , lFileSize , pFile); fclose (pFile); free(pBuff); free(pOutBuff); free(pOutPath); return true; }
/* The entry point, see usage for I/O */ int main(int argc, char* argv[]) { if(argc < 2) { Usage(); exit( 0 ); } //By default we output .ctx strncpy( g_Extension, ".ctx",MAX_EXTENSION ); memset(g_ICEKey,0,MAX_ICE_KEY); int i = 1; while( i < argc ) { if( STRING_CMP( argv[i], "-h" ) == 0 ) { Usage(); exit( 0 ); } else if( STRING_CMP( argv[i], "-d" ) == 0 ) { g_Encrypt = false; } else if( STRING_CMP( argv[i], "-x" ) == 0 ) { //Extension i++; if ( strlen( argv[i] ) > MAX_EXTENSION ) { Exit("Your Extension is too big.\n"); } strncpy( g_Extension, argv[i], MAX_EXTENSION ); } else if( STRING_CMP( argv[i], "-k" ) == 0 ) { //Key i++; if ( strlen( argv[i] ) != MAX_ICE_KEY ) { Exit("Your ICE key needs to be 8 characters long.\n"); } strncpy( g_ICEKey, argv[i], MAX_ICE_KEY ); } else { break; } i++; } if(g_ICEKey[0] == '\0') { Exit("You need to specify a key.\n"); } //Parse files starting from current arg position if(argv[i] == NULL && (strlen(argv[i]) < 1)) Exit("Was not about to find a file to parse\n"); //Directory enumeration by Red Comet //Thanks Google and bvh for directory class if( strstr(argv[i],"*") != NULL ){ oslink::directory dir("."); //Create list of files inside current directory char* pch = strstr(argv[i],"."); //Get pointer to the '.' in the file extension we want char sExt[5] = ""; strncpy(sExt,pch,4); while (dir){ //Check each file to see if it matches wildcard std::string nFile; nFile = dir.next(); if( strstr(nFile.c_str(),sExt) != NULL ){ if(DEncrypt(nFile.c_str())) std::cout << "Handled file: " << nFile << " successfully." << std::endl; } } }else{ if(DEncrypt(argv[i])) std::cout << "Handled file: " << argv[i] << " successfully." << std::endl; } //End Red Comet code }
void TaskWindow::NotifyDone(Task * task) { if(closeOnDone) Exit(); done = true; }
func Intro_4() { npc_pyrit->Exit(); return ScheduleNext(30); }
int main(int argc, char *argv[]) { char *datafn, *s; int nSeg; void Initialise(void); void LoadFile(char *fn); void EstimateModel(void); void SaveModel(char *outfn); if(InitShell(argc,argv,hinit_version,hinit_vc_id)<SUCCESS) HError(2100,"HInit: InitShell failed"); InitMem(); InitLabel(); InitMath(); InitSigP(); InitWave(); InitAudio(); InitVQ(); InitModel(); if(InitParm()<SUCCESS) HError(2100,"HInit: InitParm failed"); InitTrain(); InitUtil(); if (!InfoPrinted() && NumArgs() == 0) ReportUsage(); if (NumArgs() == 0) Exit(0); SetConfParms(); CreateHMMSet(&hset,&gstack,FALSE); while (NextArg() == SWITCHARG) { s = GetSwtArg(); if (strlen(s)!=1) HError(2119,"HInit: Bad switch %s; must be single letter",s); switch(s[0]){ case 'e': epsilon = GetChkedFlt(0.0,1.0,s); break; case 'i': maxIter = GetChkedInt(0,100,s); break; case 'l': if (NextArg() != STRINGARG) HError(2119,"HInit: Segment label expected"); segLab = GetStrArg(); break; case 'm': minSeg = GetChkedInt(1,1000,s); break; case 'n': newModel = FALSE; break; case 'o': outfn = GetStrArg(); break; case 'u': SetuFlags(); break; case 'v': minVar = GetChkedFlt(0.0,10.0,s); break; case 'w': mixWeightFloor = MINMIX * GetChkedFlt(0.0,10000.0,s); break; case 'B': saveBinary = TRUE; break; case 'F': if (NextArg() != STRINGARG) HError(2119,"HInit: Data File format expected"); if((dff = Str2Format(GetStrArg())) == ALIEN) HError(-2189,"HInit: Warning ALIEN Data file format set"); break; case 'G': if (NextArg() != STRINGARG) HError(2119,"HInit: Label File format expected"); if((lff = Str2Format(GetStrArg())) == ALIEN) HError(-2189,"HInit: Warning ALIEN Label file format set"); break; case 'H': if (NextArg() != STRINGARG) HError(2119,"HInit: HMM macro file name expected"); AddMMF(&hset,GetStrArg()); break; case 'I': if (NextArg() != STRINGARG) HError(2119,"HInit: MLF file name expected"); LoadMasterFile(GetStrArg()); break; case 'L': if (NextArg()!=STRINGARG) HError(2119,"HInit: Label file directory expected"); labDir = GetStrArg(); break; case 'M': if (NextArg()!=STRINGARG) HError(2119,"HInit: Output macro file directory expected"); outDir = GetStrArg(); break; case 'T': if (NextArg() != INTARG) HError(2119,"HInit: Trace value expected"); trace = GetChkedInt(0,01777,s); break; case 'X': if (NextArg()!=STRINGARG) HError(2119,"HInit: Label file extension expected"); labExt = GetStrArg(); break; default: HError(2119,"HInit: Unknown switch %s",s); } } if (NextArg()!=STRINGARG) HError(2119,"HInit: source HMM file name expected"); hmmfn = GetStrArg(); Initialise(); do { if (NextArg()!=STRINGARG) HError(2119,"HInit: training data file name expected"); datafn = GetStrArg(); LoadFile(datafn); } while (NumArgs()>0); nSeg = NumSegs(segStore); if (nSeg < minSeg) HError(2121,"HInit: Too Few Observation Sequences [%d]",nSeg); if (trace&T_TOP) { printf("%d Observation Sequences Loaded\n",nSeg); fflush(stdout); } EstimateModel(); SaveModel(outfn); if (trace&T_TOP) printf("Output written to directory %s\n", outDir==NULL?"current":outDir); Exit(0); return (0); /* never reached -- make compiler happy */ }
int main(int argc, const char *argv[]) { const char **arg1, *a; char *mainwaitstring; char buff[10]; double rto; int i, argc0, result; struct utsname ubuf; int lockrc; if (mainwaitstring = getenv("SOCAT_MAIN_WAIT")) { sleep(atoi(mainwaitstring)); } diag_set('p', strchr(argv[0], '/') ? strrchr(argv[0], '/')+1 : argv[0]); /* we must init before applying options because env settings have lower priority and are to be overridden by options */ if (xioinitialize(XIO_MAYALL) != 0) { Exit(1); } xiosetopt('p', "%"); xiosetopt('o', ":"); argc0 = argc; /* save for later use */ arg1 = argv+1; --argc; while (arg1[0] && (arg1[0][0] == '-')) { switch (arg1[0][1]) { case 'V': socat_version(stdout); Exit(0); #if WITH_HELP case '?': case 'h': socat_usage(stdout); xioopenhelp(stdout, (arg1[0][2]=='?'||arg1[0][2]=='h') ? (arg1[0][3]=='?'||arg1[0][3]=='h') ? 2 : 1 : 0); Exit(0); #endif /* WITH_HELP */ case 'd': diag_set('d', NULL); break; #if WITH_FILAN case 'D': xioparams->debug = true; break; #endif case 'l': switch (arg1[0][2]) { case 'm': /* mixed mode: stderr, then switch to syslog; + facility */ diag_set('s', NULL); xiosetopt('l', "m"); xioparams->logopt = arg1[0][2]; xiosetopt('y', &arg1[0][3]); break; case 'y': /* syslog + facility */ diag_set(arg1[0][2], &arg1[0][3]); break; case 'f': /* to file, +filename */ case 'p': /* artificial program name */ if (arg1[0][3]) { diag_set(arg1[0][2], &arg1[0][3]); } else if (arg1[1]) { diag_set(arg1[0][2], arg1[1]); ++arg1, --argc; } else { Error1("option -l%c requires an argument; use option \"-h\" for help", arg1[0][2]); } break; case 's': /* stderr */ diag_set(arg1[0][2], NULL); break; case 'u': diag_set('u', NULL); break; case 'h': diag_set_int('h', true); break; default: Error1("unknown log option \"%s\"; use option \"-h\" for help", arg1[0]); break; } break; case 'v': xioparams->verbose = true; break; case 'x': xioparams->verbhex = true; break; case 'b': if (arg1[0][2]) { a = *arg1+2; } else { ++arg1, --argc; if ((a = *arg1) == NULL) { Error("option -b requires an argument; use option \"-h\" for help"); Exit(1); } } xioparams->bufsiz = strtoul(a, (char **)&a, 0); break; case 's': diag_set_int('e', E_FATAL); break; case 't': if (arg1[0][2]) { a = *arg1+2; } else { ++arg1, --argc; if ((a = *arg1) == NULL) { Error("option -t requires an argument; use option \"-h\" for help"); Exit(1); } } rto = strtod(a, (char **)&a); xioparams->closwait.tv_sec = rto; xioparams->closwait.tv_usec = (rto-xioparams->closwait.tv_sec) * 1000000; break; case 'T': if (arg1[0][2]) { a = *arg1+2; } else { ++arg1, --argc; if ((a = *arg1) == NULL) { Error("option -T requires an argument; use option \"-h\" for help"); Exit(1); } } rto = strtod(a, (char **)&a); xioparams->total_timeout.tv_sec = rto; xioparams->total_timeout.tv_usec = (rto-xioparams->total_timeout.tv_sec) * 1000000; break; case 'u': xioparams->lefttoright = true; break; case 'U': xioparams->righttoleft = true; break; case 'g': xioopts_ignoregroups = true; break; case 'L': if (socat_opts.lock.lockfile) Error("only one -L and -W option allowed"); if (arg1[0][2]) { socat_opts.lock.lockfile = *arg1+2; } else { ++arg1, --argc; if ((socat_opts.lock.lockfile = *arg1) == NULL) { Error("option -L requires an argument; use option \"-h\" for help"); Exit(1); } } break; case 'W': if (socat_opts.lock.lockfile) Error("only one -L and -W option allowed"); if (arg1[0][2]) { socat_opts.lock.lockfile = *arg1+2; } else { ++arg1, --argc; if ((socat_opts.lock.lockfile = *arg1) == NULL) { Error("option -W requires an argument; use option \"-h\" for help"); Exit(1); } } socat_opts.lock.waitlock = true; socat_opts.lock.intervall.tv_sec = 1; socat_opts.lock.intervall.tv_nsec = 0; break; #if WITH_IP4 || WITH_IP6 #if WITH_IP4 case '4': #endif #if WITH_IP6 case '6': #endif xioopts.default_ip = arg1[0][1]; xioopts.preferred_ip = arg1[0][1]; break; #endif /* WITH_IP4 || WITH_IP6 */ case 'c': switch (arg1[0][2]) { case 'S': xioparams->pipetype = XIOCOMM_SOCKETPAIRS; break; case 'P': case 'p': xioparams->pipetype = XIOCOMM_PIPES; break; case 's': xioparams->pipetype = XIOCOMM_SOCKETPAIR; break; case 'Y': xioparams->pipetype = XIOCOMM_PTYS; break; case 'y': xioparams->pipetype = XIOCOMM_PTY; break; case 't': xioparams->pipetype = XIOCOMM_TCP; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': xioparams->pipetype = atoi(&arg1[0][2]); break; default: Error1("bad chain communication type \"%s\"", &arg1[0][2]); } break; case '\0': case '-': /*! this is hardcoded "--" */ case ',': case ':': break; /* this "-" is a variation of STDIO or -- */ default: xioinqopt('p', buff, sizeof(buff)); if (arg1[0][1] == buff[0]) { break; } Error1("unknown option \"%s\"; use option \"-h\" for help", arg1[0]); Exit(1); } /* the leading "-" might be a form of the first address */ xioinqopt('p', buff, sizeof(buff)); if (arg1[0][0] == '-' && (arg1[0][1] == '\0' || arg1[0][1] == ':' || arg1[0][1] == ',' || arg1[0][1] == '-'/*!*/ || arg1[0][1] == buff[0])) break; ++arg1; --argc; } #if 0 Info1("%d address arguments", argc); #else if (argc != 2) { Error1("exactly 2 addresses required (there are %d); use option \"-h\" for help", argc); Exit(1); } #endif if (xioparams->lefttoright && xioparams->righttoleft) { Error("-U and -u must not be combined"); } xioinitialize2(); Info(copyright_socat); #if WITH_OPENSSL Info(copyright_openssl); Info(copyright_ssleay); #endif Debug2("socat version %s on %s", socatversion, timestamp); xiosetenv("VERSION", socatversion, 1); /* SOCAT_VERSION */ uname(&ubuf); /* ! here we circumvent internal tracing (Uname) */ Debug4("running on %s version %s, release %s, machine %s\n", ubuf.sysname, ubuf.version, ubuf.release, ubuf.machine); #if WITH_MSGLEVEL <= E_DEBUG for (i = 0; i < argc0; ++i) { Debug2("argv[%d]: \"%s\"", i, argv[i]); } #endif /* WITH_MSGLEVEL <= E_DEBUG */ /* not sure what signal should print a message */ Signal(SIGHUP, socat_signal); Signal(SIGINT, socat_signal); Signal(SIGQUIT, socat_signal); Signal(SIGILL, socat_signal); /* SIGABRT for assert; catching caused endless recursion on assert in libc (tzfile.c:498: __tzfile_compute: Assertion 'num_types == 1' failed.) */ /*Signal(SIGABRT, socat_signal);*/ Signal(SIGBUS, socat_signal); Signal(SIGFPE, socat_signal); Signal(SIGSEGV, socat_signal); Signal(SIGTERM, socat_signal); #if HAVE_SIGACTION { struct sigaction act; memset(&act, 0, sizeof(struct sigaction)); act.sa_flags = SA_NOCLDSTOP|SA_RESTART|SA_SIGINFO #ifdef SA_NOMASK |SA_NOMASK #endif ; act.sa_sigaction = xiosigaction_subaddr_ok; if (Sigaction(SIGUSR1, &act, NULL) < 0) { /*! Linux man does not explicitely say that errno is defined */ Warn1("sigaction(SIGUSR1, {&xiosigaction_subaddr_ok}, NULL): %s", strerror(errno)); } } #else /* !HAVE_SIGACTION */ if (Signal(SIGUSR1, xiosigaction_subaddr_ok) == SIG_ERR) { Warn1("signal(SIGCHLD, xiosigaction_subaddr_ok): %s", strerror(errno)); } #endif /* !HAVE_SIGACTION */ /* set xio hooks */ xiohook_newchild = &socat_newchild; if (lockrc = socat_lock()) { /* =0: goon; >0: locked; <0: error, printed in sub */ if (lockrc > 0) Error1("could not obtain lock \"%s\"", socat_opts.lock.lockfile); Exit(1); } Atexit(socat_unlock); result = socat(argc, arg1[0], arg1[1]); Notice1("exiting with status %d", result); Exit(result); return 0; /* not reached, just for gcc -Wall */ }
/* *---------------------------------------------------------- * StartUp-- * starts the window manager and setup global data. * Called from main() at startup. * * Side effects: * global data declared in main.c is initialized *---------------------------------------------------------- */ void StartUp(Bool defaultScreenOnly) { struct sigaction sig_action; int i, j, max; char **formats; Atom atom[wlengthof(atomNames)]; /* * Ignore CapsLock in modifiers */ w_global.shortcut.modifiers_mask = 0xff & ~LockMask; getOffendingModifiers(); /* * Ignore NumLock and ScrollLock too */ w_global.shortcut.modifiers_mask &= ~(_NumLockMask | _ScrollLockMask); memset(&wKeyBindings, 0, sizeof(wKeyBindings)); w_global.context.client_win = XUniqueContext(); w_global.context.app_win = XUniqueContext(); w_global.context.stack = XUniqueContext(); /* _XA_VERSION = XInternAtom(dpy, "VERSION", False); */ #ifdef HAVE_XINTERNATOMS XInternAtoms(dpy, atomNames, wlengthof(atomNames), False, atom); #else { int i; for (i = 0; i < wlengthof(atomNames); i++) atom[i] = XInternAtom(dpy, atomNames[i], False); } #endif w_global.atom.wm.state = atom[0]; w_global.atom.wm.change_state = atom[1]; w_global.atom.wm.protocols = atom[2]; w_global.atom.wm.take_focus = atom[3]; w_global.atom.wm.delete_window = atom[4]; w_global.atom.wm.save_yourself = atom[5]; w_global.atom.wm.client_leader = atom[6]; w_global.atom.wm.colormap_windows = atom[7]; w_global.atom.wm.colormap_notify = atom[8]; w_global.atom.wmaker.menu = atom[9]; w_global.atom.wmaker.state = atom[10]; w_global.atom.wmaker.wm_protocols = atom[11]; w_global.atom.wmaker.wm_function = atom[12]; w_global.atom.wmaker.noticeboard = atom[13]; w_global.atom.wmaker.command = atom[14]; w_global.atom.wmaker.icon_size = atom[15]; w_global.atom.wmaker.icon_tile = atom[16]; w_global.atom.gnustep.wm_attr = atom[17]; w_global.atom.gnustep.wm_miniaturize_window = atom[18]; w_global.atom.gnustep.titlebar_state = atom[19]; w_global.atom.wm.ignore_focus_events = atom[20]; #ifdef XDND wXDNDInitializeAtoms(); #endif /* cursors */ wPreferences.cursor[WCUR_NORMAL] = None; /* inherit from root */ wPreferences.cursor[WCUR_ROOT] = XCreateFontCursor(dpy, XC_left_ptr); wPreferences.cursor[WCUR_ARROW] = XCreateFontCursor(dpy, XC_top_left_arrow); wPreferences.cursor[WCUR_MOVE] = XCreateFontCursor(dpy, XC_fleur); wPreferences.cursor[WCUR_RESIZE] = XCreateFontCursor(dpy, XC_sizing); wPreferences.cursor[WCUR_TOPLEFTRESIZE] = XCreateFontCursor(dpy, XC_top_left_corner); wPreferences.cursor[WCUR_TOPRIGHTRESIZE] = XCreateFontCursor(dpy, XC_top_right_corner); wPreferences.cursor[WCUR_BOTTOMLEFTRESIZE] = XCreateFontCursor(dpy, XC_bottom_left_corner); wPreferences.cursor[WCUR_BOTTOMRIGHTRESIZE] = XCreateFontCursor(dpy, XC_bottom_right_corner); wPreferences.cursor[WCUR_VERTICALRESIZE] = XCreateFontCursor(dpy, XC_sb_v_double_arrow); wPreferences.cursor[WCUR_HORIZONRESIZE] = XCreateFontCursor(dpy, XC_sb_h_double_arrow); wPreferences.cursor[WCUR_WAIT] = XCreateFontCursor(dpy, XC_watch); wPreferences.cursor[WCUR_QUESTION] = XCreateFontCursor(dpy, XC_question_arrow); wPreferences.cursor[WCUR_TEXT] = XCreateFontCursor(dpy, XC_xterm); /* odd name??? */ wPreferences.cursor[WCUR_SELECT] = XCreateFontCursor(dpy, XC_cross); Pixmap cur = XCreatePixmap(dpy, DefaultRootWindow(dpy), 16, 16, 1); GC gc = XCreateGC(dpy, cur, 0, NULL); XColor black; memset(&black, 0, sizeof(XColor)); XSetForeground(dpy, gc, 0); XFillRectangle(dpy, cur, gc, 0, 0, 16, 16); XFreeGC(dpy, gc); wPreferences.cursor[WCUR_EMPTY] = XCreatePixmapCursor(dpy, cur, cur, &black, &black, 0, 0); XFreePixmap(dpy, cur); /* emergency exit... */ sig_action.sa_handler = handleSig; sigemptyset(&sig_action.sa_mask); sig_action.sa_flags = SA_RESTART; sigaction(SIGQUIT, &sig_action, NULL); /* instead of catching these, we let the default handler abort the * program. The new monitor process will take appropriate action * when it detects the crash. sigaction(SIGSEGV, &sig_action, NULL); sigaction(SIGBUS, &sig_action, NULL); sigaction(SIGFPE, &sig_action, NULL); sigaction(SIGABRT, &sig_action, NULL); */ sig_action.sa_handler = handleExitSig; /* Here we set SA_RESTART for safety, because SIGUSR1 may not be handled * immediately. -Dan */ sig_action.sa_flags = SA_RESTART; sigaction(SIGTERM, &sig_action, NULL); sigaction(SIGINT, &sig_action, NULL); sigaction(SIGHUP, &sig_action, NULL); sigaction(SIGUSR1, &sig_action, NULL); sigaction(SIGUSR2, &sig_action, NULL); /* ignore dead pipe */ /* Because POSIX mandates that only signal with handlers are reset * accross an exec*(), we do not want to propagate ignoring SIGPIPEs * to children. Hence the dummy handler. * Philippe Troin <*****@*****.**> */ sig_action.sa_handler = &dummyHandler; sig_action.sa_flags = SA_RESTART; sigaction(SIGPIPE, &sig_action, NULL); /* handle dead children */ sig_action.sa_handler = buryChild; sig_action.sa_flags = SA_NOCLDSTOP | SA_RESTART; sigaction(SIGCHLD, &sig_action, NULL); /* Now we unblock all signals, that may have been blocked by the parent * who exec()-ed us. This can happen for example if Window Maker crashes * and restarts itself or another window manager from the signal handler. * In this case, the new proccess inherits the blocked signal mask and * will no longer react to that signal, until unblocked. * This is because the signal handler of the proccess who crashed (parent) * didn't return, and the signal remained blocked. -Dan */ sigfillset(&sig_action.sa_mask); sigprocmask(SIG_UNBLOCK, &sig_action.sa_mask, NULL); /* handle X shutdowns a such */ XSetIOErrorHandler(handleXIO); /* set hook for out event dispatcher in WINGs event dispatcher */ WMHookEventHandler(DispatchEvent); /* initialize defaults stuff */ w_global.domain.wmaker = wDefaultsInitDomain("WindowMaker", True); if (!w_global.domain.wmaker->dictionary) wwarning(_("could not read domain \"%s\" from defaults database"), "WindowMaker"); /* read defaults that don't change until a restart and are * screen independent */ wReadStaticDefaults(w_global.domain.wmaker ? w_global.domain.wmaker->dictionary : NULL); /* check sanity of some values */ if (wPreferences.icon_size < 16) { wwarning(_("icon size is configured to %i, but it's too small. Using 16 instead"), wPreferences.icon_size); wPreferences.icon_size = 16; } /* init other domains */ w_global.domain.root_menu = wDefaultsInitDomain("WMRootMenu", False); if (!w_global.domain.root_menu->dictionary) wwarning(_("could not read domain \"%s\" from defaults database"), "WMRootMenu"); wDefaultsMergeGlobalMenus(w_global.domain.root_menu); w_global.domain.window_attr = wDefaultsInitDomain("WMWindowAttributes", True); if (!w_global.domain.window_attr->dictionary) wwarning(_("could not read domain \"%s\" from defaults database"), "WMWindowAttributes"); XSetErrorHandler((XErrorHandler) catchXError); #ifdef USE_XSHAPE /* ignore j */ w_global.xext.shape.supported = XShapeQueryExtension(dpy, &w_global.xext.shape.event_base, &j); #endif #ifdef USE_XRANDR w_global.xext.randr.supported = XRRQueryExtension(dpy, &w_global.xext.randr.event_base, &j); #endif #ifdef KEEP_XKB_LOCK_STATUS w_global.xext.xkb.supported = XkbQueryExtension(dpy, NULL, &w_global.xext.xkb.event_base, NULL, NULL, NULL); if (wPreferences.modelock && !w_global.xext.xkb.supported) { wwarning(_("XKB is not supported. KbdModeLock is automatically disabled.")); wPreferences.modelock = 0; } #endif if (defaultScreenOnly) max = 1; else max = ScreenCount(dpy); wScreen = wmalloc(sizeof(WScreen *) * max); w_global.screen_count = 0; /* Check if TIFF images are supported */ formats = RSupportedFileFormats(); if (formats) { for (i = 0; formats[i] != NULL; i++) { if (strcmp(formats[i], "TIFF") == 0) { wPreferences.supports_tiff = 1; break; } } } /* manage the screens */ for (j = 0; j < max; j++) { if (defaultScreenOnly || max == 1) { wScreen[w_global.screen_count] = wScreenInit(DefaultScreen(dpy)); if (!wScreen[w_global.screen_count]) { wfatal(_("it seems that there is already a window manager running")); Exit(1); } } else { wScreen[w_global.screen_count] = wScreenInit(j); if (!wScreen[w_global.screen_count]) { wwarning(_("could not manage screen %i"), j); continue; } } w_global.screen_count++; } InitializeSwitchMenu(); /* initialize/restore state for the screens */ for (j = 0; j < w_global.screen_count; j++) { int lastDesktop; lastDesktop = wNETWMGetCurrentDesktopFromHint(wScreen[j]); wScreenRestoreState(wScreen[j]); /* manage all windows that were already here before us */ if (!wPreferences.flags.nodock && wScreen[j]->dock) wScreen[j]->last_dock = wScreen[j]->dock; manageAllWindows(wScreen[j], wPreferences.flags.restarting == 2); /* restore saved menus */ wMenuRestoreState(wScreen[j]); /* If we're not restarting, restore session */ if (wPreferences.flags.restarting == 0 && !wPreferences.flags.norestore) wSessionRestoreState(wScreen[j]); if (!wPreferences.flags.noautolaunch) { /* auto-launch apps */ if (!wPreferences.flags.nodock && wScreen[j]->dock) { wScreen[j]->last_dock = wScreen[j]->dock; wDockDoAutoLaunch(wScreen[j]->dock, 0); } /* auto-launch apps in clip */ if (!wPreferences.flags.noclip) { int i; for (i = 0; i < w_global.workspace.count; i++) { if (w_global.workspace.array[i]->clip) { wScreen[j]->last_dock = w_global.workspace.array[i]->clip; wDockDoAutoLaunch(w_global.workspace.array[i]->clip, i); } } } /* auto-launch apps in drawers */ if (!wPreferences.flags.nodrawer) { WDrawerChain *dc; for (dc = wScreen[j]->drawers; dc; dc = dc->next) { wScreen[j]->last_dock = dc->adrawer; wDockDoAutoLaunch(dc->adrawer, 0); } } } /* go to workspace where we were before restart */ if (lastDesktop >= 0) wWorkspaceForceChange(wScreen[j], lastDesktop); else wSessionRestoreLastWorkspace(wScreen[j]); } if (w_global.screen_count == 0) { wfatal(_("could not manage any screen")); Exit(1); } #ifndef HAVE_INOTIFY /* setup defaults file polling */ if (!wPreferences.flags.nopolling && !wPreferences.flags.noupdates) WMAddTimerHandler(3000, wDefaultsCheckDomains, NULL); #endif }
strcpy(vName,"varFloor"); strcat(vName,num); fprintf(f,"~v %s\n",vName); if (fullcNeeded[s]) TriDiag2Vector(accs[s].squareSum.inv,v); else CopyVector(accs[s].fixed.var,v); for (i=1; i<=hset.swidth[s]; i++) v[i] *= vFloorScale; fprintf(f,"<Variance> %d\n",hset.swidth[s]); WriteVector(f,v,FALSE); FreeVector(&gstack,v); } fclose(f); if (trace&T_TOP) printf("Var floor macros output to file %s\n",outfn); } /* ---------------- Load Data and Accumulate Stats --------------- */ /* AccVar: update global accumulators with given observation */ void AccVar(Observation obs) { int x,y,s,V; float val; Vector v; totalCount++; for (s=1; s<=hset.swidth[0]; s++){ v = obs.fv[s]; V = hset.swidth[s]; for (x=1;x<=V;x++) { val=v[x]; accs[s].meanSum[x] += val; /* accumulate mean */ if (fullcNeeded[s]) { /* accumulate covar */ accs[s].squareSum.inv[x][x] += val*val; for (y=1;y<x;y++) accs[s].squareSum.inv[x][y] += val*v[y]; } else /* accumulate var */ accs[s].squareSum.var[x] += val*val; } } } /* CheckData: check data file consistent with HMM definition */ void CheckData(char *fn, BufferInfo info) { if (info.tgtVecSize!=hset.vecSize) HError(2050,"CheckData: Vector size in %s[%d] is incompatible with hmm %s[%d]", fn,info.tgtVecSize,hmmfn,hset.vecSize); if (info.tgtPK != hset.pkind) HError(2050,"CheckData: Parameterisation in %s is incompatible with hmm %s", fn,hmmfn); } /* LoadFile: load whole file or segments and accumulate variance */ void LoadFile(char *fn) { ParmBuf pbuf; BufferInfo info; char labfn[80]; Transcription *trans; long segStIdx,segEnIdx; int i,j,ncas,nObs; LLink p; if (segId == NULL) { /* load whole parameter file */ if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL) HError(2050,"LoadFile: Config parameters invalid"); GetBufferInfo(pbuf,&info); CheckData(fn,info); nObs = ObsInBuffer(pbuf); for (i=0; i<nObs; i++){ ReadAsTable(pbuf,i,&obs); AccVar(obs); } if (trace&T_LOAD) { printf(" %d observations loaded from %s\n",nObs,fn); fflush(stdout); } CloseBuffer(pbuf); } else { /* load segment of parameter file */ MakeFN(fn,labDir,labExt,labfn); trans = LOpen(&iStack,labfn,lff); ncas = NumCases(trans->head,segId); if ( ncas > 0) { if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL)
// ---------------------------------------------------- // CDbtestAppUi::HandleCommandL(TInt aCommand) // ?implementation_description // ---------------------------------------------------- // void CDbtestAppUi::HandleCommandL(TInt aCommand) { switch ( aCommand ) { case EAknSoftkeyBack: case EEikCmdExit: { Exit(); break; } case EdbtestCmdAppOBEX: //bt->transfer_logs(); break; case EdbtestCmdAppTest: { #if 0 if (!is_open) { User::LeaveIfError(sockserv.Connect()); User::LeaveIfError(sock.Open(sockserv, KAfInet, KSockStream, KUndefinedProtocol)); TInetAddr a(INET_ADDR(128, 214, 48, 81) , 80); TRequestStatus s; sock.Connect(a, s); User::WaitForRequest(s); status_change(_L("opened")); is_open=true; } else { sock.CancelAll(); sock.Close(); sockserv.Close(); status_change(_L("closed")); is_open=false; } #else # if 0 //transferer->log_gps(); /* TInetAddr a(INET_ADDR(128, 214, 48, 81) , 21); ftp->Connect(a, _L8("tkt_cntx"), _L8("dKFJmqBi")); current_state=CONNECTING; */ /* run(this); */ # else //wap->Connect(1, _L("http://db.cs.helsinki.fi/~mraento/cgi-bin/put.pl")); # endif #endif } break; case EdbtestCmdAppCommDb: { CCommDbDump* dump=CCommDbDump::NewL(); CleanupStack::PushL(dump); dump->DumpDBtoFileL(_L("c:\\commdb.txt")); CleanupStack::PopAndDestroy(); } break; case EdbtestCmdAppCert: { auto_ptr<CCertInstaller> i(CCertInstaller::NewL(AppContext())); i->InstallCertL(_L("c:\\hy.der")); } case EdbtestCmdAppDiscover: //discoverer->search(); break; case EdbtestCmdAppCtmGSM: { TBuf<40> s; RDevRecharger c; TInt ret=0; TInt u=0; bool done=false; while (!done) { ret=c.Open(u); if (ret==KErrNone) { done=true; } else { ++u; if (u==KNullUnit) done=true; } } if (ret!=KErrNone) { s.Format(_L("Open: %d"), ret); } else { TChargeInfoV1 i; i.iRawTemperature=i.iSmoothedTemperature=0; i.iChargeType=EChargeNone; TChargeInfoV1Buf b(i); c.ChargeInfo(b); s.Format(_L("%d r %d s %d t %d"), u, i.iRawTemperature, i.iSmoothedTemperature, i.iChargeType) ; } status_change(s); } break; case EdbtestCmdAppVibra: CFLDRingingTonePlayer* p; p=CFLDRingingTonePlayer::NewL(ETrue); p->SetVibra(ETrue); p->SetRingingType(0); //((MFLDFileProcessor*)p)->ProcessFileL(_L("c:\\nokia\\sounds\\simple\\silent.rng")); ((MFLDFileProcessor*)p)->ProcessFileL(_L("c:\\system\\apps\\context_log\\silent.rng")); break; default: break; } }
main(int argc, char *argv[]) #endif { char options[128] = "aAc:CdD::fhHI:l:L:m:M:n:p:P:qrsS:UvV-:Y:"; int arg, i, ret; int dont_fork = 0, do_help = 0; int log_set = 0; int uid = 0, gid = 0; int agent_mode = -1; char *cptr, **argvptr; char *pid_file = NULL; char option_compatability[] = "-Le"; #if HAVE_GETPID int fd; FILE *PID; #endif #ifndef WIN32 /* * close all non-standard file descriptors we may have * inherited from the shell. */ for (i = getdtablesize() - 1; i > 2; --i) { (void) close(i); } #endif /* #WIN32 */ /* * register signals ASAP to prevent default action (usually core) * for signals during startup... */ #ifdef SIGTERM DEBUGMSGTL(("signal", "registering SIGTERM signal handler\n")); signal(SIGTERM, SnmpdShutDown); #endif #ifdef SIGINT DEBUGMSGTL(("signal", "registering SIGINT signal handler\n")); signal(SIGINT, SnmpdShutDown); #endif #ifdef SIGHUP signal(SIGHUP, SIG_IGN); /* do not terminate on early SIGHUP */ #endif #ifdef SIGUSR1 DEBUGMSGTL(("signal", "registering SIGUSR1 signal handler\n")); signal(SIGUSR1, SnmpdDump); #endif #ifdef SIGPIPE DEBUGMSGTL(("signal", "registering SIGPIPE signal handler\n")); signal(SIGPIPE, SIG_IGN); /* 'Inline' failure of wayward readers */ #endif #ifdef SIGXFSZ signal(SIGXFSZ, SnmpdCatchRandomSignal); #endif #ifdef NETSNMP_NO_ROOT_ACCESS /* * Default to no. */ netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_NO_ROOT_ACCESS, 1); #endif /* * Default to NOT running an AgentX master. */ netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_AGENTX_MASTER, 0); netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_AGENTX_TIMEOUT, -1); netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_AGENTX_RETRIES, -1); netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_CACHE_TIMEOUT, 5); /* * Add some options if they are available. */ #if HAVE_UNISTD_H strcat(options, "g:u:"); #endif #if defined(USING_AGENTX_SUBAGENT_MODULE)|| defined(USING_AGENTX_MASTER_MODULE) strcat(options, "x:"); #endif #ifdef USING_AGENTX_SUBAGENT_MODULE strcat(options, "X"); #endif /* * This is incredibly ugly, but it's probably the simplest way * to handle the old '-L' option as well as the new '-Lx' style */ for (i=0; i<argc; i++) { if (!strcmp(argv[i], "-L")) argv[i] = option_compatability; } #ifdef WIN32 snmp_log_syslogname(app_name_long); #else snmp_log_syslogname(app_name); #endif netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE, app_name); /* * Now process options normally. */ while ((arg = getopt(argc, argv, options)) != EOF) { switch (arg) { case '-': if (strcasecmp(optarg, "help") == 0) { usage(argv[0]); } if (strcasecmp(optarg, "version") == 0) { version(); } handle_long_opt(optarg); break; case 'a': log_addresses++; break; case 'A': netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPEND_LOGFILES, 1); break; case 'c': if (optarg != NULL) { netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OPTIONALCONFIG, optarg); } else { usage(argv[0]); } break; case 'C': netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_READ_CONFIGS, 1); break; case 'd': snmp_set_dump_packet(++snmp_dump_packet); netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_VERBOSE, 1); break; case 'D': debug_register_tokens(optarg); snmp_set_do_debugging(1); break; case 'f': dont_fork = 1; break; #if HAVE_UNISTD_H case 'g': if (optarg != NULL) { netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_GROUPID, atoi(optarg)); } else { usage(argv[0]); } break; #endif case 'h': usage(argv[0]); break; case 'H': do_help = 1; break; case 'I': if (optarg != NULL) { add_to_init_list(optarg); } else { usage(argv[0]); } break; case 'l': printf("Warning: -l option is deprecated, use -Lf <file> instead\n"); if (optarg != NULL) { if (strlen(optarg) > PATH_MAX) { fprintf(stderr, "%s: logfile path too long (limit %d chars)\n", argv[0], PATH_MAX); exit(1); } snmp_enable_filelog(optarg, netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPEND_LOGFILES)); log_set = 1; } else { usage(argv[0]); } break; case 'L': if (snmp_log_options( optarg, argc, argv ) < 0 ) { usage(argv[0]); } log_set = 1; break; case 'm': if (optarg != NULL) { setenv("MIBS", optarg, 1); } else { usage(argv[0]); } break; case 'M': if (optarg != NULL) { setenv("MIBDIRS", optarg, 1); } else { usage(argv[0]); } break; case 'n': if (optarg != NULL) { app_name = optarg; netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE, app_name); } else { usage(argv[0]); } break; case 'P': printf("Warning: -P option is deprecated, use -p instead\n"); case 'p': if (optarg != NULL) { pid_file = optarg; } else { usage(argv[0]); } break; case 'q': snmp_set_quick_print(1); break; case 'r': netsnmp_ds_toggle_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_NO_ROOT_ACCESS); break; case 's': printf("Warning: -s option is deprecated, use -Lsd instead\n"); snmp_enable_syslog(); log_set = 1; break; case 'S': printf("Warning: -S option is deprecated, use -Ls <facility> instead\n"); if (optarg != NULL) { switch (*optarg) { case 'd': case 'D': Facility = LOG_DAEMON; break; case 'i': case 'I': Facility = LOG_INFO; break; case '0': Facility = LOG_LOCAL0; break; case '1': Facility = LOG_LOCAL1; break; case '2': Facility = LOG_LOCAL2; break; case '3': Facility = LOG_LOCAL3; break; case '4': Facility = LOG_LOCAL4; break; case '5': Facility = LOG_LOCAL5; break; case '6': Facility = LOG_LOCAL6; break; case '7': Facility = LOG_LOCAL7; break; default: fprintf(stderr, "invalid syslog facility: -S%c\n",*optarg); usage(argv[0]); } snmp_enable_syslog_ident(snmp_log_syslogname(NULL), Facility); log_set = 1; } else { fprintf(stderr, "no syslog facility specified\n"); usage(argv[0]); } break; case 'U': netsnmp_ds_toggle_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_LEAVE_PIDFILE); break; #if HAVE_UNISTD_H case 'u': if (optarg != NULL) { char *ecp; int uid; uid = strtoul(optarg, &ecp, 10); if (*ecp) { #if HAVE_GETPWNAM && HAVE_PWD_H struct passwd *info; info = getpwnam(optarg); if (info) { uid = info->pw_uid; } else { #endif fprintf(stderr, "Bad user id: %s\n", optarg); exit(1); #if HAVE_GETPWNAM && HAVE_PWD_H } #endif } netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_USERID, uid); } else { usage(argv[0]); } break; #endif case 'v': version(); case 'V': netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_VERBOSE, 1); break; #if defined(USING_AGENTX_SUBAGENT_MODULE)|| defined(USING_AGENTX_MASTER_MODULE) case 'x': if (optarg != NULL) { netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_X_SOCKET, optarg); } else { usage(argv[0]); } netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_AGENTX_MASTER, 1); break; #endif case 'X': #if defined(USING_AGENTX_SUBAGENT_MODULE) agent_mode = SUB_AGENT; #else fprintf(stderr, "%s: Illegal argument -X:" "AgentX support not compiled in.\n", argv[0]); usage(argv[0]); exit(1); #endif break; case 'Y': netsnmp_config_remember(optarg); break; default: usage(argv[0]); break; } } if (do_help) { netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_NO_ROOT_ACCESS, 1); init_agent(app_name); /* register our .conf handlers */ init_mib_modules(); init_snmp(app_name); fprintf(stderr, "Configuration directives understood:\n"); read_config_print_usage(" "); exit(0); } if (optind < argc) { /* * There are optional transport addresses on the command line. */ DEBUGMSGTL(("snmpd/main", "optind %d, argc %d\n", optind, argc)); for (i = optind; i < argc; i++) { char *c, *astring; if ((c = netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_PORTS))) { astring = malloc(strlen(c) + 2 + strlen(argv[i])); if (astring == NULL) { fprintf(stderr, "malloc failure processing argv[%d]\n", i); exit(1); } sprintf(astring, "%s,%s", c, argv[i]); netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_PORTS, astring); SNMP_FREE(astring); } else { netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_PORTS, argv[i]); } } DEBUGMSGTL(("snmpd/main", "port spec: %s\n", netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_PORTS))); } #ifdef NETSNMP_LOGFILE if (0 == log_set) snmp_enable_filelog(NETSNMP_LOGFILE, netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPEND_LOGFILES)); #endif /* * Initialize a argv set to the current for restarting the agent. */ argvrestartp = (char **)malloc((argc + 2) * sizeof(char *)); argvptr = argvrestartp; for (i = 0, ret = 1; i < argc; i++) { ret += strlen(argv[i]) + 1; } argvrestart = (char *) malloc(ret); argvrestartname = (char *) malloc(strlen(argv[0]) + 1); if (!argvrestartp || !argvrestart || !argvrestartname) { fprintf(stderr, "malloc failure processing argvrestart\n"); exit(1); } strcpy(argvrestartname, argv[0]); if (agent_mode == -1) { if (strstr(argvrestartname, "agentxd") != NULL) { netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, SUB_AGENT); } else { netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, MASTER_AGENT); } } else { netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, agent_mode); } for (cptr = argvrestart, i = 0; i < argc; i++) { strcpy(cptr, argv[i]); *(argvptr++) = cptr; cptr += strlen(argv[i]) + 1; } *cptr = 0; *argvptr = NULL; #ifdef BUFSIZ setvbuf(stdout, NULL, _IOLBF, BUFSIZ); #endif /* * Initialize the world. Detach from the shell. Create initial user. */ if(!dont_fork) { int quit = ! netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_QUIT_IMMEDIATELY); ret = netsnmp_daemonize(quit, snmp_stderrlog_status()); /* * xxx-rks: do we care if fork fails? I think we should... */ if(ret != 0) Exit(1); /* Exit logs exit val for us */ } SOCK_STARTUP; init_agent(app_name); /* do what we need to do first. */ init_mib_modules(); /* * start library */ init_snmp(app_name); if ((ret = init_master_agent()) != 0) { /* * Some error opening one of the specified agent transports. */ Exit(1); /* Exit logs exit val for us */ } #if HAVE_GETPID if (pid_file != NULL) { /* * unlink the pid_file, if it exists, prior to open. Without * doing this the open will fail if the user specified pid_file * already exists. */ unlink(pid_file); fd = open(pid_file, O_CREAT | O_EXCL | O_WRONLY, 0600); if (fd == -1) { snmp_log_perror(pid_file); if (!netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) { exit(1); } } else { if ((PID = fdopen(fd, "w")) == NULL) { snmp_log_perror(pid_file); exit(1); } else { fprintf(PID, "%d\n", (int) getpid()); fclose(PID); } close(fd); } } #endif #if HAVE_UNISTD_H cptr = get_persistent_directory(); mkdirhier( cptr, NETSNMP_AGENT_DIRECTORY_MODE, 0 ); uid = netsnmp_ds_get_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_USERID); gid = netsnmp_ds_get_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_GROUPID); #ifdef HAVE_CHOWN if ( uid != 0 || gid != 0 ) chown( cptr, uid, gid ); #endif #ifdef HAVE_SETGID if ((gid = netsnmp_ds_get_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_GROUPID)) != 0) { DEBUGMSGTL(("snmpd/main", "Changing gid to %d.\n", gid)); if (setgid(gid) == -1 #ifdef HAVE_SETGROUPS || setgroups(1, (gid_t *)&gid) == -1 #endif ) { snmp_log_perror("setgid failed"); if (!netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) { exit(1); } } } #endif #ifdef HAVE_SETUID if ((uid = netsnmp_ds_get_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_USERID)) != 0) { DEBUGMSGTL(("snmpd/main", "Changing uid to %d.\n", uid)); if (setuid(uid) == -1) { snmp_log_perror("setuid failed"); if (!netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) { exit(1); } } } #endif #endif /* * Store persistent data immediately in case we crash later. */ snmp_store(app_name); #ifdef SIGHUP DEBUGMSGTL(("signal", "registering SIGHUP signal handler\n")); signal(SIGHUP, SnmpdReconfig); #endif /* * Send coldstart trap if possible. */ send_easy_trap(0, 0); /* * We're up, log our version number. */ snmp_log(LOG_INFO, "NET-SNMP version %s\n", netsnmp_get_version()); #ifdef WIN32SERVICE agent_status = AGENT_RUNNING; #endif netsnmp_addrcache_initialise(); /* * Forever monitor the dest_port for incoming PDUs. */ DEBUGMSGTL(("snmpd/main", "We're up. Starting to process data.\n")); if (!netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_QUIT_IMMEDIATELY)) receive(); DEBUGMSGTL(("snmpd/main", "sending shutdown trap\n")); SnmpTrapNodeDown(); DEBUGMSGTL(("snmpd/main", "Bye...\n")); snmp_shutdown(app_name); #ifdef SHUTDOWN_AGENT_CLEANLY /* broken code */ /* these attempt to free all known memory, but result in double frees */ shutdown_master_agent(); shutdown_agent(); #endif if (!netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_LEAVE_PIDFILE) && (pid_file != NULL)) { unlink(pid_file); } #ifdef WIN32SERVICE agent_status = AGENT_STOPPED; #endif SNMP_FREE(argvrestartname); SNMP_FREE(argvrestart); SNMP_FREE(argvrestartp); SOCK_CLEANUP; return 0; } /* End main() -- snmpd */
int waitup(int echildok, int *retstatus) { Envy *e; int pid; int slot; Symtab *s; Word *w; Job *j; char buf[ERRMAX]; Bufblock *bp; int uarg = 0; int done; Node *n; Process *p; extern int runerrs; /* first check against the proces slist */ if(retstatus) for(p = phead; p; p = p->f) if(p->pid == *retstatus){ *retstatus = p->status; pdelete(p); return(-1); } again: /* rogue processes */ pid = waitfor(buf); if(pid == -1){ if(echildok > 0) return(1); else { fprint(2, "mk: (waitup %d) ", echildok); perror("mk wait"); Exit(); } } if(DEBUG(D_EXEC)) fprint(1, "waitup got pid=%d, status='%s'\n", pid, buf); if(retstatus && pid == *retstatus){ *retstatus = buf[0]? 1:0; return(-1); } slot = pidslot(pid); if(slot < 0){ if(DEBUG(D_EXEC)) fprint(2, "mk: wait returned unexpected process %d\n", pid); pnew(pid, buf[0]? 1:0); goto again; } j = events[slot].job; usage(); nrunning--; events[slot].pid = -1; if(buf[0]){ e = buildenv(j, slot); bp = newbuf(); shprint(j->r->recipe, e, bp); front(bp->start); fprint(2, "mk: %s: exit status=%s", bp->start, buf); freebuf(bp); for(n = j->n, done = 0; n; n = n->next) if(n->flags&DELETE){ if(done++ == 0) fprint(2, ", deleting"); fprint(2, " '%s'", n->name); delete(n->name); } fprint(2, "\n"); if(kflag){ runerrs++; uarg = 1; } else { jobs = 0; Exit(); } } for(w = j->t; w; w = w->next){ if((s = symlook(w->s, S_NODE, 0)) == 0) continue; /* not interested in this node */ update(uarg, s->u.ptr); } if(nrunning < nproclimit) sched(); return(0); }
WizardExport WizardBooleanType KeyringCommand(int argc,char **argv, ExceptionInfo *exception) { #define DestroyKeyring() \ { \ for (i=0; i < (ssize_t) argc; i++) \ argv[i]=DestroyString(argv[i]); \ argv=(char **) RelinquishWizardMemory(argv); \ } #define ThrowKeyringException(asperity,tag,context) \ { \ (void) ThrowWizardException(exception,GetWizardModule(),asperity,tag, \ context); \ DestroyKeyring(); \ return(WizardFalse); \ } #define ThrowInvalidArgumentException(option,argument) \ { \ (void) ThrowWizardException(exception,GetWizardModule(),OptionError, \ "invalid argument: `%s': %s",argument,option); \ DestroyKeyring(); \ return(WizardFalse); \ } BlobInfo *keyring_blob; const char *option; register ssize_t i; WizardBooleanType status; /* Parse command-line options. */ if (argc == 2) { option=argv[1]; if ((LocaleCompare("version",option+1) == 0) || (LocaleCompare("-version",option+1) == 0)) { (void) fprintf(stdout,"Version: %s\n",GetWizardVersion( (size_t *) NULL)); (void) fprintf(stdout,"Copyright: %s\n\n",GetWizardCopyright()); return(WizardTrue); } } if (argc < 2) KeyringUsage(); status=ExpandFilenames(&argc,&argv); if (status == WizardFalse) ThrowKeyringException(ResourceError,"memory allocation failed: `%s'", strerror(errno)); for (i=1; i < (argc-1); i++) { option=argv[i]; if (LocaleCompare(option+1,"export") == 0) { status=ExportKeyring(argc,argv,exception); DestroyKeyring(); return(status); } } keyring_blob=OpenBlob(argv[argc-1],WriteBinaryBlobMode,WizardTrue,exception); if (keyring_blob == (BlobInfo *) NULL) return(WizardFalse); (void) WriteBlobString(keyring_blob,"<?xml version=\"1.0\"?>\n"); (void) WriteBlobString(keyring_blob,"<rdf:RDF xmlns:rdf=\"" "http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"); (void) WriteBlobString(keyring_blob," xmlns:keyring=\"" "http://www.wizards-toolkit.org/keyring/1.0/\">\n"); for (i=1; i < (ssize_t) (argc-1); i++) { option=argv[i]; if (IsWizardOption(option) != WizardFalse) switch (*(option+1)) { case 'd': { if (LocaleCompare(option,"-debug") == 0) { LogEventType event_mask; i++; if (i == (ssize_t) argc) ThrowKeyringException(OptionError,"missing log event mask: " "`%s'",option); event_mask=SetLogEventMask(argv[i]); if (event_mask == UndefinedEvents) ThrowKeyringException(OptionFatalError,"unrecognized log event " "type: `%s'",argv[i]); break; } ThrowKeyringException(OptionFatalError,"unrecognized option: `%s'", option); break; } case 'h': { if ((LocaleCompare("help",option+1) == 0) || (LocaleCompare("-help",option+1) == 0)) KeyringUsage(); ThrowKeyringException(OptionFatalError,"unrecognized option: `%s'", option); break; } case 'l': { if (LocaleCompare(option,"-list") == 0) { ssize_t list; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowKeyringException(OptionError,"missing list type: `%s'", option); if (LocaleCompare(argv[i],"configure") == 0) { (void) ListConfigureInfo((FILE *) NULL,exception); Exit(0); } list=ParseWizardOption(WizardListOptions,WizardFalse,argv[i]); if (list < 0) ThrowKeyringException(OptionFatalError,"unrecognized list " "type: `%s'",argv[i]); (void) ListWizardOptions((FILE *) NULL,(WizardOption) list, exception); Exit(0); break; } if (LocaleCompare("log",option+1) == 0) { if (*option == '+') break; i++; if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL)) ThrowKeyringException(OptionFatalError,"missing argument: `%s'", option); break; } ThrowKeyringException(OptionFatalError,"unrecognized option: `%s'", option); break; } case 'v': { if (LocaleCompare(option,"-version") == 0) { (void) fprintf(stdout,"Version: %s\n",GetWizardVersion( (size_t *) NULL)); (void) fprintf(stdout,"Copyright: %s\n\n",GetWizardCopyright()); exit(0); } ThrowKeyringException(OptionFatalError,"unrecognized option: `%s'", option); break; } default: { ThrowKeyringException(OptionFatalError,"unrecognized option: `%s'", option); break; } } status=PrintKeyringProperties(argv[i],keyring_blob,exception); } if (argc == 2) status=PrintKeyringProperties((const char *) NULL,keyring_blob,exception); (void) WriteBlobString(keyring_blob,"</rdf:RDF>\n"); status=CloseBlob(keyring_blob); /* Free resources. */ DestroyKeyring(); return(status); }
void FileBrowserActivity::SelectSave(SaveFile * file) { if(callback) callback->FileSelected(new SaveFile(*file)); Exit(); }
void MissileType::Load(lua_State *l) { this->NumDirections = 1; this->Flip = true; // Ensure we don't divide by zero. this->SplashFactor = 100; // Parse the arguments std::string file; for (lua_pushnil(l); lua_next(l, 2); lua_pop(l, 1)) { const char *value = LuaToString(l, -2); if (!strcmp(value, "File")) { file = LuaToString(l, -1); } else if (!strcmp(value, "Size")) { if (!lua_istable(l, -1) || lua_rawlen(l, -1) != 2) { LuaError(l, "incorrect argument"); } lua_rawgeti(l, -1, 1); this->size.x = LuaToNumber(l, -1); lua_pop(l, 1); lua_rawgeti(l, -1, 2); this->size.y = LuaToNumber(l, -1); lua_pop(l, 1); } else if (!strcmp(value, "Frames")) { this->SpriteFrames = LuaToNumber(l, -1); } else if (!strcmp(value, "Flip")) { this->Flip = LuaToBoolean(l, -1); } else if (!strcmp(value, "NumDirections")) { this->NumDirections = LuaToNumber(l, -1); } else if (!strcmp(value, "Transparency")) { this->Transparency = LuaToNumber(l, -1); } else if (!strcmp(value, "FiredSound")) { this->FiredSound.Name = LuaToString(l, -1); } else if (!strcmp(value, "ImpactSound")) { this->ImpactSound.Name = LuaToString(l, -1); } else if (!strcmp(value, "ChangeVariable")) { const int index = UnitTypeVar.VariableNameLookup[LuaToString(l, -1)];// User variables if (index == -1) { fprintf(stderr, "Bad variable name '%s'\n", LuaToString(l, -1)); Exit(1); return; } this->ChangeVariable = index; } else if (!strcmp(value, "ChangeAmount")) { this->ChangeAmount = LuaToNumber(l, -1); } else if (!strcmp(value, "ChangeMax")) { this->ChangeMax = LuaToBoolean(l, -1); } else if (!strcmp(value, "Class")) { const char *className = LuaToString(l, -1); unsigned int i = 0; for (; MissileClassNames[i]; ++i) { if (!strcmp(className, MissileClassNames[i])) { this->Class = i; break; } } if (!MissileClassNames[i]) { LuaError(l, "Unsupported class: %s" _C_ value); } } else if (!strcmp(value, "NumBounces")) { this->NumBounces = LuaToNumber(l, -1); } else if (!strcmp(value, "Delay")) { this->StartDelay = LuaToNumber(l, -1); } else if (!strcmp(value, "Sleep")) { this->Sleep = LuaToNumber(l, -1); } else if (!strcmp(value, "Speed")) { this->Speed = LuaToNumber(l, -1); } else if (!strcmp(value, "TTL")) { this->TTL = LuaToNumber(l, -1); } else if (!strcmp(value, "Damage")) { this->Damage = LuaToNumber(l, -1); } else if (!strcmp(value, "DrawLevel")) { this->DrawLevel = LuaToNumber(l, -1); } else if (!strcmp(value, "Range")) { this->Range = LuaToNumber(l, -1); } else if (!strcmp(value, "ImpactMissile")) { this->Impact.Name = LuaToString(l, -1); } else if (!strcmp(value, "SmokeMissile")) { this->Smoke.Name = LuaToString(l, -1); } else if (!strcmp(value, "ImpactParticle")) { this->ImpactParticle = new LuaCallback(l, -1); } else if (!strcmp(value, "SmokeParticle")) { this->SmokeParticle = new LuaCallback(l, -1); } else if (!strcmp(value, "CanHitOwner")) { this->CanHitOwner = LuaToBoolean(l, -1); } else if (!strcmp(value, "AlwaysFire")) { this->AlwaysFire = LuaToBoolean(l, -1); } else if (!strcmp(value, "Pierce")) { this->Pierce = LuaToBoolean(l, -1); } else if (!strcmp(value, "PierceOnce")) { this->PierceOnce = LuaToBoolean(l, -1); } else if (!strcmp(value, "FriendlyFire")) { this->FriendlyFire = LuaToBoolean(l, -1); } else if (!strcmp(value, "SplashFactor")) { this->SplashFactor = LuaToNumber(l, -1); } else if (!strcmp(value, "CorrectSphashDamage")) { this->CorrectSphashDamage = LuaToBoolean(l, -1); } else { LuaError(l, "Unsupported tag: %s" _C_ value); } } if (!file.empty()) { this->G = CGraphic::New(file, this->Width(), this->Height()); } }
void FileBrowserActivity::OnMouseDown(int x, int y, unsigned button) { if (!(x > Position.X && y > Position.Y && y < Position.Y+Size.Y && x < Position.X+Size.X)) //Clicked outside window Exit(); }
void CWCheatEngine::Run() { CWCheatEngine cheats; exit2 = false; while (!exit2) { codes = cheats.GetCodesList(); // UI Member currentCode = 0; while (true) { std::vector<int> code = GetNextCode(); if (code.size() < 2) { Exit(); break; } int value; unsigned int comm = code[0]; int arg = code[1]; int addr = GetAddress(comm & 0x0FFFFFFF); switch (comm >> 28) { case 0: // 8-bit write. if (Memory::IsValidAddress(addr)){ Memory::Write_U8((u8) arg, addr); } break; case 0x1: // 16-bit write if (Memory::IsValidAddress(addr)){ Memory::Write_U16((u16) arg, addr); } break; case 0x2: // 32-bit write if (Memory::IsValidAddress(addr)){ Memory::Write_U32((u32) arg, addr); } break; case 0x3: // Increment/Decrement { addr = GetAddress(arg); value = 0; int increment = 0; // Read value from memory switch ((comm >> 20) & 0xF) { case 1: case 2: // 8-bit value = Memory::Read_U8(addr); increment = comm & 0xFF; break; case 3: case 4: // 16-bit value = Memory::Read_U16(addr); increment = comm & 0xFFFF; break; case 5: case 6: // 32-bit value = Memory::Read_U32(addr); code = GetNextCode(); if ( code[0] != NULL) { increment = code[0]; } break; } // Increment/Decrement value switch ((comm >> 20) & 0xF) { case 1: case 3: case 5: // increment value += increment; break; case 2: case 4: case 6: // Decrement value -= increment; break; } // Write value back to memory switch ((comm >> 20) & 0xF) { case 1: case 2: // 8-bit Memory::Write_U8((u8) value, addr); break; case 3: case 4: // 16-bit Memory::Write_U16((u16) value, addr); break; case 5: case 6: // 32-bit Memory::Write_U32((u32) value, addr); break; } break; } case 0x4: // 32-bit patch code code = GetNextCode(); if (code[0] != NULL) { int data = code[0]; int dataAdd = code[1]; int maxAddr = (arg >> 16) & 0xFFFF; int stepAddr = (arg & 0xFFFF) * 4; for (int a = 0; a < maxAddr; a++) { if (Memory::IsValidAddress(addr)) { Memory::Write_U32((u32) data, addr); } addr += stepAddr; data += dataAdd; } } break; case 0x5: // Memcpy command code = GetNextCode(); if (code[0] != NULL) { int destAddr = code[0]; if (Memory::IsValidAddress(addr) && Memory::IsValidAddress(destAddr)) { Memory::Memcpy(destAddr, Memory::GetPointer(addr), arg); } } break; case 0x6: // Pointer commands code = GetNextCode(); if (code[0] != NULL) { int arg2 = code[0]; int offset = code[1]; int baseOffset = (arg2 >> 20) * 4; int base = Memory::Read_U32(addr + baseOffset); int count = arg2 & 0xFFFF; int type = (arg2 >> 16) & 0xF; for (int i = 1; i < count; i ++ ) { if (i+1 < count) { code = GetNextCode(); int arg3 = code[0]; int arg4 = code[1]; int comm3 = arg3 >> 28; switch (comm3) { case 0x1: // type copy byte { int srcAddr = Memory::Read_U32(addr) + offset; int dstAddr = Memory::Read_U16(addr + baseOffset) + (arg3 & 0x0FFFFFFF); Memory::Memcpy(dstAddr, Memory::GetPointer(srcAddr), arg); type = -1; //Done break; } case 0x2: case 0x3: // type pointer walk { int walkOffset = arg3 & 0x0FFFFFFF; if (comm3 == 0x3) { walkOffset = -walkOffset; } base = Memory::Read_U32(base + walkOffset); int comm4 = arg4 >> 28; switch (comm4) { case 0x2: case 0x3: // type pointer walk walkOffset = arg4 & 0x0FFFFFFF; if (comm4 == 0x3) { walkOffset = -walkOffset; } base = Memory::Read_U32(base + walkOffset); break; } break; } case 0x9: // type multi address write base += arg3 & 0x0FFFFFFF; arg += arg4; break; } } } switch (type) { case 0: // 8 bit write Memory::Write_U8((u8) arg, base + offset); break; case 1: // 16-bit write Memory::Write_U16((u16) arg, base + offset); break; case 2: // 32-bit write Memory::Write_U32((u32) arg, base + offset); break; case 3: // 8 bit inverse write Memory::Write_U8((u8) arg, base - offset); break; case 4: // 16-bit inverse write Memory::Write_U16((u16) arg, base - offset); break; case 5: // 32-bit inverse write Memory::Write_U32((u32) arg, base - offset); break; case -1: // Operation already performed, nothing to do break; } } break; case 0x7: // Boolean commands. switch (arg >> 16) { case 0x0000: // 8-bit OR. if (Memory::IsValidAddress(addr)) { int val1 = (int) (arg & 0xFF); int val2 = (int) Memory::Read_U8(addr); Memory::Write_U8((u8) (val1 | val2), addr); } break; case 0x0002: // 8-bit AND. if (Memory::IsValidAddress(addr)) { int val1 = (int) (arg & 0xFF); int val2 = (int) Memory::Read_U8(addr); Memory::Write_U8((u8) (val1 & val2), addr); } break; case 0x0004: // 8-bit XOR. if (Memory::IsValidAddress(addr)) { int val1 = (int) (arg & 0xFF); int val2 = (int) Memory::Read_U8(addr); Memory::Write_U8((u8) (val1 ^ val2), addr); } break; case 0x0001: // 16-bit OR. if (Memory::IsValidAddress(addr)) { short val1 = (short) (arg & 0xFFFF); short val2 = (short) Memory::Read_U16(addr); Memory::Write_U16((u16) (val1 | val2), addr); } break; case 0x0003: // 16-bit AND. if (Memory::IsValidAddress(addr)) { short val1 = (short) (arg & 0xFFFF); short val2 = (short) Memory::Read_U16(addr); Memory::Write_U16((u16) (val1 & val2), addr); } break; case 0x0005: // 16-bit OR. if (Memory::IsValidAddress(addr)) { short val1 = (short) (arg & 0xFFFF); short val2 = (short) Memory::Read_U16(addr); Memory::Write_U16((u16) (val1 ^ val2), addr); } break; } break; case 0x8: // 8-bit and 16-bit patch code code = GetNextCode(); if (code[0] != NULL) { int data = code[0]; int dataAdd = code[1]; bool is8Bit = (data >> 16) == 0x0000; int maxAddr = (arg >> 16) & 0xFFFF; int stepAddr = (arg & 0xFFFF) * (is8Bit ? 1 : 2); for (int a = 0; a < maxAddr; a++) { if (Memory::IsValidAddress(addr)) { if (is8Bit) { Memory::Write_U8((u8) (data & 0xFF), addr); } else { Memory::Write_U16((u16) (data & 0xFFFF), addr); } } addr += stepAddr; data += dataAdd; } }
void FileBrowserActivity::OnTryExit(ExitMethod method) { Exit(); }
void ScanParamString(char *paramstr,int len) // Parses a parameter string { char *endptr=paramstr+len,*endstringptr; // Skip all white spaces while(paramstr<endptr) { if((*paramstr!=' ')&&(*paramstr!=',')&&(*paramstr!='\t')&& (*paramstr!='\r')&&(*paramstr!='\n')) break; paramstr++; } // Parse the delimiter string endstringptr=::ParseString(paramstr,endptr); if(endstringptr==NULL) { Error("First parameter in rep("); ErrorCont(paramstr,len); ErrorCont(") should be a string!"); Exit(); } // Store the delimiter string delimiter=paramstr+1; delimiterlen=endstringptr-delimiter; // Skip white spaces endstringptr++; while(endstringptr<endptr) { if((*endstringptr!=' ')&&(*endstringptr!=',')&&(*endstringptr!='\t')&& (*endstringptr!='\r')&&(*endstringptr!='\n')) break; endstringptr++; } // Next, there must be the compressor as a parameter subcompressor2=NULL; subcompressor=compressman.CreateCompressorInstance(endstringptr,endptr); if(subcompressor->IsRejecting()) { Error("Compressor '"); ErrorCont(endstringptr,endptr-endstringptr); ErrorCont("' must always accept the string!\n"); Exit(); } subuncompressor2=NULL; subuncompressor=compressman.CreateUncompressorInstance(endstringptr,endptr); // Skip white spaces while(endstringptr<endptr) { if((*endstringptr!=' ')&&(*endstringptr!=',')&&(*endstringptr!='\t')&& (*endstringptr!='\r')&&(*endstringptr!='\n')) break; endstringptr++; } // No additional tail compressor? if(*endstringptr==')') return; // Otherwise find the tail compressor subcompressor2=compressman.CreateCompressorInstance(endstringptr,endptr); subuncompressor2=compressman.CreateUncompressorInstance(endstringptr,endptr); // Skip white spaces while(endstringptr<endptr) { if((*endstringptr!=' ')&&(*endstringptr!=',')&&(*endstringptr!='\t')&& (*endstringptr!='\r')&&(*endstringptr!='\n')) break; endstringptr++; } // Last character must be ')' if(*endstringptr!=')') { Error("Missing closed parenthesis in '"); ErrorCont(paramstr,len); Exit(); } }
// ----------------------------------------------------------------------------- // CRhodesAppUi::HandleCommandL() // Takes care of command handling. // ----------------------------------------------------------------------------- // void CRhodesAppUi::HandleCommandL(TInt aCommand) { switch (aCommand) { case EEikCmdExit: case EAknSoftkeyExit: if ( iSyncEngineWrap ) iSyncEngineWrap->TerminateThread(); Exit(); break; case EHelp: { CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL(); HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf); } break; case EAbout: { CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog(); dlg->PrepareLC(R_ABOUT_QUERY_DIALOG); HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE); dlg->QueryHeading()->SetTextL(*title); CleanupStack::PopAndDestroy(); //title HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT); dlg->SetMessageTextL(*msg); CleanupStack::PopAndDestroy(); //msg dlg->RunLD(); } break; #ifdef ENABLE_RUBY_VM_STAT case EStat: { CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog(); dlg->PrepareLC(R_STAT_QUERY_DIALOG); HBufC* title = iEikonEnv->AllocReadResourceLC(R_STAT_DIALOG_TITLE); dlg->QueryHeading()->SetTextL(*title); CleanupStack::PopAndDestroy(); //title char buf[500] = {0}; sprintf( buf, "stat:\n___________________\n" "iceq stat:\n " "iseq binread: %u%s\n" "iseq marshal: %u%s\n" "require_compiled: %u%s\n" "httpd thread loaded: %d\n" "sync thread loaded: %d\n", g_iseq_binread_msec, "msec", g_iseq_marshal_load_msec, "msec", g_require_compiled_msec, "msec", g_httpd_thread_loaded, g_sync_thread_loaded); TPtrC8 ptr8((TUint8*)buf); HBufC *msg = HBufC::NewLC(ptr8.Length()); msg->Des().Copy(ptr8); dlg->SetMessageTextL(*msg); CleanupStack::PopAndDestroy(msg); dlg->RunLD(); } break; #endif default: iAppView->HandleCommandL(aCommand); break; } }
/** * @brief リスタート時の瞬時値ファイル読み込み * @param [in] fp ファイルポインタ * @param [out] flop 浮動小数点演算数 */ void FFV::RestartInstantaneous(FILE* fp, double& flop) { double time, r_time; const unsigned step = C.Restart_step; std::string fname; std::string fmt(C.file_fmt_ext); REAL_TYPE bp = ( C.Unit.Prs == Unit_Absolute ) ? C.BasePrs : 0.0; REAL_TYPE refD = C.RefDensity; REAL_TYPE refV = C.RefVelocity; // ガイド出力 int gs = C.GuideOut; // dummy unsigned i_dummy=0; double f_dummy=0.0; const int* m_div = paraMngr->GetDivNum(); // 自身の領域終点インデックス int tail[3]; for (int i=0;i<3;i++) tail[i]=head[i]+size[i]-1; // Pressure if ( DFI_IN_PRS->ReadData(d_p, step, guide, G_size, (int *)m_div, head, tail, r_time, true, i_dummy, f_dummy) != CIO::E_CIO_SUCCESS ) Exit(0); if ( d_p == NULL ) Exit(0); time = r_time; // 有次元の場合,無次元に変換する if ( C.Unit.File == DIMENSIONAL ) { REAL_TYPE bp = ( C.Unit.Prs == Unit_Absolute ) ? C.BasePrs : 0.0; U.convArrayPrsD2ND(d_p, size, guide, bp, C.RefDensity, C.RefVelocity, flop); } Hostonly_ printf ("\tPressure has read :\tstep=%d time=%e [%s]\n", step, time, (C.Unit.File == DIMENSIONAL)?"sec.":"-"); Hostonly_ fprintf(fp, "\tPressure has read :\tstep=%d time=%e [%s]\n", step, time, (C.Unit.File == DIMENSIONAL)?"sec.":"-"); // ここでタイムスタンプを得る if (C.Unit.File == DIMENSIONAL) time /= C.Tscale; CurrentStep = step; CurrentTime = time; // v00[]に値をセット copyV00fromRF(time); if ( DFI_IN_VEL->ReadData(d_wo, step, guide, G_size, (int *)m_div, head, tail, r_time, true, i_dummy, f_dummy) != CIO::E_CIO_SUCCESS ) Exit(0); if( d_wo == NULL ) Exit(0); REAL_TYPE refv = (C.Unit.File == DIMENSIONAL) ? refV : 1.0; REAL_TYPE u0[4]; u0[0] = v00[0]; u0[1] = v00[1]; u0[2] = v00[2]; u0[3] = v00[3]; Hostonly_ printf ("\tVelocity has read :\tstep=%d time=%e [%s]\n", step, time, (C.Unit.File == DIMENSIONAL)?"sec.":"-"); Hostonly_ fprintf(fp, "\tVelocity has read :\tstep=%d time=%e [%s]\n", step, time, (C.Unit.File == DIMENSIONAL)?"sec.":"-"); time = r_time; if (C.Unit.File == DIMENSIONAL) time /= C.Tscale; if ( time != CurrentTime ) { Hostonly_ printf ("\n\tTime stamp is different between files\n"); Hostonly_ fprintf(fp, "\n\tTime stamp is different between files\n"); Exit(0); } // indexの変換と無次元化 fb_vin_nijk_(d_v, size, &guide, d_wo, u0, &refv, &flop); if ( !C.isHeatProblem() ) return; // Instantaneous Temperature fields if ( DFI_IN_TEMP->ReadData(d_ws, C.Restart_step, guide, G_size, (int *)m_div, head, tail, r_time, true, i_dummy, f_dummy) != CIO::E_CIO_SUCCESS ) Exit(0); if( d_ws == NULL ) Exit(0); time = r_time; if (C.Unit.File == DIMENSIONAL) time /= C.Tscale; Hostonly_ printf ("\tTemperature has read :\tstep=%d time=%e [%s]\n", step, time, (C.Unit.File == DIMENSIONAL)?"sec.":"-"); Hostonly_ fprintf(fp, "\tTemperature has read :\tstep=%d time=%e [%s]\n", step, time, (C.Unit.File == DIMENSIONAL)?"sec.":"-"); if ( time != CurrentTime ) { Hostonly_ printf ("\n\tTime stamp is different between files\n"); Hostonly_ fprintf(fp, "\n\tTime stamp is different between files\n"); Exit(0); } if (C.Unit.File == DIMENSIONAL) { U.convArrayTmp2IE(d_ie, size, guide, d_ws, d_bcd, mat_tbl, C.BaseTemp, C.DiffTemp, true, flop); } else { U.convArrayTmp2IE(d_ie, size, guide, d_ws, d_bcd, mat_tbl, C.BaseTemp, C.DiffTemp, false, flop); } }
int work(Node *node, Node *p, Arc *parc) { Arc *a, *ra; int weoutofdate; int ready; int did = 0; /*print("work(%s) flags=0x%x time=%ld\n", node->name, node->flags, node->time); */ if(node->flags&BEINGMADE) return(did); if((node->flags&MADE) && (node->flags&PRETENDING) && p && outofdate(p, parc, 0)){ if(explain) fprint(1, "unpretending %s(%ld) because %s is out of date(%ld)\n", node->name, node->time, p->name, p->time); unpretend(node); } /* have a look if we are pretending in case someone has been unpretended out from underneath us */ if(node->flags&MADE){ if(node->flags&PRETENDING){ node->time = 0; }else return(did); } /* consider no prerequsite case */ if(node->prereqs == 0){ if(node->time == 0){ fprint(2, "mk: don't know how to make '%s' in %s\n", node->name, dir()); if(kflag){ node->flags |= BEINGMADE; runerrs++; } else Exit(); } else MADESET(node, MADE); return(did); } /* now see if we are out of date or what */ ready = 1; weoutofdate = aflag; ra = 0; for(a = node->prereqs; a; a = a->next) if(a->n){ did = work(a->n, node, a) || did; if(a->n->flags&(NOTMADE|BEINGMADE)) ready = 0; if(outofdate(node, a, 0)){ weoutofdate = 1; if((ra == 0) || (ra->n == 0) || (ra->n->time < a->n->time)) ra = a; } } else { if(node->time == 0){ if(ra == 0) ra = a; weoutofdate = 1; } } if(ready == 0) /* can't do anything now */ return(did); if(weoutofdate == 0){ MADESET(node, MADE); return(did); } /* can we pretend to be made? */ if((iflag == 0) && (node->time == 0) && (node->flags&(PRETENDING|CANPRETEND)) && p && ra->n && !outofdate(p, ra, 0)){ node->flags &= ~CANPRETEND; MADESET(node, MADE); if(explain && ((node->flags&PRETENDING) == 0)) fprint(1, "pretending %s has time %ld\n", node->name, node->time); node->flags |= PRETENDING; return(did); } /* node is out of date and we REALLY do have to do something. quickly rescan for pretenders */ for(a = node->prereqs; a; a = a->next) if(a->n && (a->n->flags&PRETENDING)){ if(explain) Bprint(&bout, "unpretending %s because of %s because of %s\n", a->n->name, node->name, ra->n? ra->n->name : "rule with no prerequisites"); unpretend(a->n); did = work(a->n, node, a) || did; ready = 0; } if(ready == 0) /* try later unless nothing has happened for -k's sake */ return(did || work(node, p, parc)); did = dorecipe(node) || did; return(did); }