int main(int argc, char **argv) { if(CheckArguments(argc, argv)) return 0; KwmInit(); KWMMach.EventMask = ((1 << kCGEventKeyDown) | (1 << kCGEventKeyUp) | (1 << kCGEventMouseMoved)); KWMMach.EventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, KWMMach.EventMask, CGEventCallback, NULL); if(!KWMMach.EventTap || !CGEventTapIsEnabled(KWMMach.EventTap)) Fatal("ERROR: Could not create event-tap!"); CFRunLoopAddSource(CFRunLoopGetMain(), CFMachPortCreateRunLoopSource(kCFAllocatorDefault, KWMMach.EventTap, 0), kCFRunLoopCommonModes); CGEventTapEnable(KWMMach.EventTap, true); CreateWorkspaceWatcher(KWMMach.WorkspaceWatcher); // NOTE(koekeishiya): Initialize AXLIB // AXLibInit(&AXApplications); // AXLibRunningApplications(); NSApplicationLoad(); CFRunLoopRun(); return 0; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { register int i, n; register DOUBLE in, output, *input; if (nrhs >= 1 && mxIsChar(prhs[0])){ /* Ignore obsolete text cmds */ return; } if (CheckArguments(nlhs, plhs, nrhs, prhs) ){ mexErrMsgTxt("invsoscascade argument checking failed."); return ; } for (n=0; n<nSamples; n++){ output = 0; input = &inputData[n*nChannels]; for (i=nChannels-1; i>=0; i--){ if (gains) in = output + gains[i]*input[i]; else in = output + input[i]; output = a0[i] * in + state1[i]; state1[i] = a1[i] * in - b1[i] * output + state2[i]; state2[i] = a2[i] * in - b2[i] * output; } outputData[n] = output; } /* Assign output pointers */ plhs[0] = outputMatrix; }
void PartitionAsForest::Join (Set& s, Set& t) { PartitionTree& p = dynamic_cast<PartitionTree&> (s); PartitionTree& q = dynamic_cast<PartitionTree&> (t); CheckArguments (p, q); q.parent = &p; --count; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { char *ErrMessage ; register int i, j; if (nrhs >= 1 && mxIsChar(prhs[0])){ /* Ignore old text commands */ return; } if (CheckArguments(nlhs, plhs, nrhs, prhs)){ mexErrMsgTxt("AGC argument checking failed."); return ; } #ifdef INVERSE for (j=0; j<nSamples; j++){ agc(inputData + j*nChannels, outputData + j*nChannels, stateArray + (nStages-1)*nChannels, (double)agcParms[1+(nStages-1)*2], (double)agcParms[0+(nStages-1)*2], (int)nChannels); /* Target; Epsilon */ for (i=nStages-2; i>=0; i--){ agc(outputData + j*nChannels, outputData + j*nChannels, stateArray + i*nChannels, (double)agcParms[1+i*2], (double)agcParms[0+i*2], (int)nChannels); } } #else for (j=0; j<nSamples; j++){ agc(inputData + j*nChannels, outputData + j*nChannels, stateArray + 0*nChannels, (double)agcParms[1+0*2], (double)agcParms[0+0*2], (int)nChannels); /* Target; Epsilon */ for (i=1; i<nStages; i++){ agc(outputData + j*nChannels, outputData + j*nChannels, stateArray + i*nChannels, (double)agcParms[1+i*2], (double)agcParms[0+i*2], (int)nChannels); } } #endif /* Assign output pointers */ plhs[0] = outputMatrix; if (nlhs > 1) plhs[1] = stateMatrix; else mxDestroyArray(stateMatrix); }
// Gets the name of an object int _Scripting::ObjectGetName(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 1)) return 0; _Object *Object = (_Object *)(lua_touserdata(LuaObject, 1)); if(Object != NULL) lua_pushstring(LuaObject, Object->GetName().c_str()); return 1; }
// Stops an object's movement int _Scripting::ObjectStop(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 1)) return 0; // Stop object _Object *Object = (_Object *)(lua_touserdata(LuaObject, 1)); if(Object != NULL) Object->Stop(); return 0; }
// Sets the camera's yaw value int _Scripting::CameraSetPitch(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 1)) return 0; float Pitch = (float)lua_tonumber(LuaObject, 1); if(PlayState.GetCamera()) PlayState.GetCamera()->SetPitch(Pitch); return 0; }
// Deletes an object int _Scripting::ObjectDelete(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 1)) return 0; // Delete object _Object *Object = (_Object *)(lua_touserdata(LuaObject, 1)); if(Object != NULL) ObjectManager.DeleteObject(Object); return 0; }
// Sets the random seed int _Scripting::RandomSeed(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 1)) return 0; // Get parameter irr::u32 Seed = (irr::u32)lua_tointeger(LuaObject, 1); // Set seed Random.SetSeed(Seed); return 0; }
// Gets a template from a name int _Scripting::LevelGetTemplate(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 1)) return 0; // Get parameters std::string TemplateName = lua_tostring(LuaObject, 1); // Send template to Lua lua_pushlightuserdata(LuaObject, Level.GetTemplate(TemplateName)); return 1; }
// Gets a pointer to an object from a name int _Scripting::ObjectGetPointer(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 1)) return 0; // Get parameters std::string Name = lua_tostring(LuaObject, 1); _Object *Object = ObjectManager.GetObjectByName(Name); // Pass pointer lua_pushlightuserdata(LuaObject, (void *)Object); return 1; }
// Sets the tutorial text int _Scripting::GUITutorialText(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 2)) return 0; // Get parameters std::string Text(lua_tostring(LuaObject, 1)); float Length = (float)lua_tonumber(LuaObject, 2); // Show text Interface.SetTutorialText(Text, Length); return 0; }
int main(int argc, char* argv[]) { if (CheckArguments(argc, argv[1])) { if (argc == 4) { OnlyRewrite(argv[1], argv[2]); } else { ReplaceAndRewrite(argv[1], argv[2], argv[3], argv[4]); } } return 0; }
// Adds a timed callback int _Scripting::TimerDelayedFunction(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 2)) return 0; // Get parameters std::string FunctionName = lua_tostring(LuaObject, 1); float Time = (float)lua_tonumber(LuaObject, 2); // Add function to list Scripting.AddTimedCallback(FunctionName, Time); return 0; }
// Generates a random integer int _Scripting::RandomGetInt(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 2)) return 0; // Get parameters int Min = (int)lua_tointeger(LuaObject, 1); int Max = (int)lua_tointeger(LuaObject, 2); // Send random number to Lua lua_pushnumber(LuaObject, Random.GenerateRange(Min, Max)); return 1; }
// Sets the object's lifetime int _Scripting::ObjectSetLifetime(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 2)) return 0; // Get parameters _Object *Object = (_Object *)(lua_touserdata(LuaObject, 1)); float Lifetime = (float)lua_tonumber(LuaObject, 2); // Set lifetime if(Object != NULL) Object->SetLifetime(Lifetime); return 0; }
// Sets an object's angular velocity int _Scripting::ObjectSetAngularVelocity(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 4)) return 0; // Get parameters _Object *Object = (_Object *)(lua_touserdata(LuaObject, 1)); float X = (float)lua_tonumber(LuaObject, 2); float Y = (float)lua_tonumber(LuaObject, 3); float Z = (float)lua_tonumber(LuaObject, 4); if(Object != NULL) Object->SetAngularVelocity(btVector3(X, Y, Z)); return 0; }
/// <summary> /// Show the INodes and filenames of children of the specified INode. /// </summary> void DoShow(std::vector<std::string> cmd) { if (!CheckArguments("show", cmd, 1)) return; // Get the ID. std::istringstream ss(cmd[1]); int id; ss >> id; // Calculate position. uint32_t pos = OFFSET_FSINFO + (id * BSIZE_FILE); // Show hexidecimal contents of block. std::stringstream charcache; int a = 0; int b = 0; for (int i = 0; i < BSIZE_FILE; i++) { char hd; Program::FSStream->seekg(pos + i); AppLib::LowLevel::Endian::doR(Program::FSStream, &hd, 1); printf("%02X ", (unsigned char)hd); if (hd < 32 || hd == 127) charcache << " "; else charcache << (unsigned char)hd << " "; a += 1; if (a >= 16) { printf(" %s\n", charcache.str().c_str()); charcache.str(""); a = 0; } b += 1; if (b >= 16 * 16 && i != BSIZE_FILE - 1) { printf("Showing %04X to %04X (page %i of %i). Press any key to view next 256 bytes.", i + 1 - (16 * 16), i, ((i + 1 - (16 * 16)) / 256) + 1, 16); _getch(); printf("\n"); b = 0; } } }
/// <summary> /// Show the INodes and filenames of children of the specified INode. /// </summary> void GetChildren(std::vector<std::string> cmd) { if (!CheckArguments("children", cmd, 1)) return; // Get the ID. std::istringstream ss(cmd[1]); int id; ss >> id; // Loop through all of the children. std::vector<AppLib::LowLevel::INode> children = Program::FS->getChildrenOfDirectory(id); printf("Children of directory with INode %i:\n", id); for (int i = 0; i < children.size(); i += 1) { printf(" * %i (%s)\n", children[i].inodeid, Program::TypeNames[children[i].type].c_str()); } }
// Gets the object's position int _Scripting::ObjectGetPosition(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 1)) return 0; // Get object _Object *Object = (_Object *)(lua_touserdata(LuaObject, 1)); if(Object == NULL) return 0; // Send position to Lua lua_pushnumber(LuaObject, Object->GetPosition()[0]); lua_pushnumber(LuaObject, Object->GetPosition()[1]); lua_pushnumber(LuaObject, Object->GetPosition()[2]); return 3; }
// Sets the object's position int _Scripting::ObjectSetPosition(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 4)) return 0; // Get parameters _Object *Object = (_Object *)(lua_touserdata(LuaObject, 1)); float PositionX = (float)lua_tonumber(LuaObject, 2); float PositionY = (float)lua_tonumber(LuaObject, 3); float PositionZ = (float)lua_tonumber(LuaObject, 4); // Set position if(Object != NULL) Object->SetPosition(btVector3(PositionX, PositionY, PositionZ)); return 0; }
// Deactivates an orb int _Scripting::OrbDeactivate(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 3)) return 0; // Get parameters _Orb *Orb = (_Orb *)(lua_touserdata(LuaObject, 1)); std::string FunctionName = lua_tostring(LuaObject, 2); float Time = (float)lua_tonumber(LuaObject, 3); // Deactivate orb if(Orb != NULL && Orb->IsStillActive()) { Orb->StartDeactivation(FunctionName, Time); } return 0; }
// Creates a constraint int _Scripting::LevelCreateConstraint(lua_State *LuaObject) { // Validate arguments if(!CheckArguments(LuaObject, 4)) return 0; // Set up constraint struct ConstraintStruct Constraint; Constraint.Name = lua_tostring(LuaObject, 1); Constraint.Template = (TemplateStruct *)(lua_touserdata(LuaObject, 2)); Constraint.BodyA = (_Object *)(lua_touserdata(LuaObject, 3)); Constraint.BodyB = (_Object *)(lua_touserdata(LuaObject, 4)); // Create object _Object *Object = Level.CreateConstraint(Constraint); // Send new object to Lua lua_pushlightuserdata(LuaObject, static_cast<void *>(Object)); return 1; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { register int i; float x; int max_len = 6; int p; int ns0 = 29; static area_function *af0; if (CheckArguments(nlhs, plhs, nrhs, prhs) ){ mexErrMsgTxt("AMgetdata argument checking failed."); return ; } /* read nasal tract area function from the file */ //printf("Reading nasal tract file.\n"); read_af(NTAFpath , &nna, &afnt ); //printf("Finished Reading nasal tract file.\n"); /* Initialization */ //read_rad(); // update all constants and variables if((int)(pTCcfg[0]) == RL_CIRCUIT) rad_boundary = RL_CIRCUIT; else rad_boundary = SHORT_CIRCUIT; //printf("Rad_boundary[%d]\n",rad_boundary); if((int)(pTCcfg[1]) == YIELDING) wall = YIELDING; else wall = RIGID; //printf("wall[%d]\n",wall); if((int)(pTCcfg[2]) == ON) nasal_tract = ON; else nasal_tract = OFF; //printf("nasal_tract[%d]\n",nasal_tract); if((int)(pTCcfg[3]) == CLOSE) glt_boundary = CLOSE; else glt_boundary = OPEN; //printf("glt_boundary[%d]\n",glt_boundary); ro = (float)(pPCcfg[0]); //printf("Air density[%f]\n",ro); c = (float)(pPCcfg[1]); //printf("Sound velocity[%f]\n",c); wall_resi = (float)(pPCcfg[2]); //printf("wall_resi[%f]\n",wall_resi); wall_mass = (float)(pPCcfg[3]); //printf("wall_mass[%f]\n",wall_mass); wall_comp = (float)(pPCcfg[4]); //printf("wall_comp[%f]\n",wall_comp); for(i=0;i<7;i++) { AMpar[i] = (float)(pAMcfg[i]); //printf("AMpar[%d][%f]\n",i,AMpar[i]); } anc = (float)(pAMcfg[7]); //printf("nasal area[%f]\n",anc); /* Initialization */ read_model_spec(); af0 = (area_function *) calloc( ns0, sizeof(area_function) ); nph = 9; nbu = 8; nss = nbu + nph; afvt = (area_function *) calloc( nss, sizeof(area_function) ); convert_scale(); semi_polar(); oAf = mxCreateDoubleMatrix(2,nss, mxREAL); pAf = mxGetPr(oAf); /* Compute VT profile and area function, and plot them */ lam( AMpar ); /* profile */ sagittal_to_area( &ns0, af0 ); /* area function */ for(i=0;i<ns0;i++) { //printf("AreaNS0[%d][%f]\n",i,af0[i]); } appro_area_function( ns0, af0, nss, afvt); for(i=0;i<nss;i++) { //printf("AreaAF[%d][%f]\n",i,afvt[i]); pAf[2*i] = afvt[i].A; pAf[2*i+1] = afvt[i].x; } if( nasal_tract == ON ) { anc = (float) min( anc, afvt[nph].A ); afvt[nph].A -= anc; pAf[2*nph] = afvt[nph].A; pAf[2*nph+1] = afvt[nph].x; } calplot_tf_FBA(nfrmmax, frm, bw, amp, &nfrms, tfunc, &ntf); //printf("Finished calculations.\n"); oPdat1 = mxCreateDoubleMatrix(4,NP, mxREAL); pPdat1 = mxGetPr(oPdat1); for(i=0;i<NP;i++) { pPdat1[4*i] = ivt[i].x; pPdat1[4*i+1] = ivt[i].y; pPdat1[4*i+2] = evt[i].x; pPdat1[4*i+3] = evt[i].y; } oPdat2 = mxCreateDoubleMatrix(1,2,mxREAL); pPdat2 = mxGetPr(oPdat2); pPdat2[0] = lip_w; pPdat2[1] = lip_h; oTf = mxCreateDoubleMatrix(ntf, 1, mxREAL); pTf = mxGetPr(oTf); for(i=0;i<ntf;i++) { pTf[i] = tfunc[i]; } oFmt = mxCreateDoubleMatrix(nfrms, 1, mxREAL); pFmt = mxGetPr(oFmt); oBw = mxCreateDoubleMatrix(nfrms, 1, mxREAL); pBw = mxGetPr(oBw); oAmp = mxCreateDoubleMatrix(nfrms, 1, mxREAL); pAmp = mxGetPr(oAmp); for(i=0;i<nfrms;i++) { pFmt[i] = frm[i]; pBw[i] = bw[i]; pAmp[i] = amp[i]; } /* Assign output pointers */ plhs[0] = oAf; plhs[1] = oTf; plhs[2] = oFmt; plhs[3] = oBw; plhs[4] = oAmp; plhs[5] = oPdat1; plhs[6] = oPdat2; // do cleanup //free( rad_re ); //free( rad_im ); free( afnt ); free( af0 ); free( afvt ); }
/* ** int main(int argc, char *argv[]); ** ** Run command-line file compression program. ** ** Arguments: figure it out ** ** Returns: int - EXIT_SUCCESS if compression finished successfully, ** EXIT_FAILURE if not. ** ** Globals: none */ INT _CRTAPI1 main(INT argc, CHAR *argv[]) { INT iSourceFileName, fError, nTotalFiles = 0, nReturnCode = EXIT_SUCCESS; CHAR ARG_PTR pszDestFileName[MAX_PATH]; CHAR chTargetFileName[ MAX_PATH ]; LONG cblTotInSize = 0L, cblTotOutSize = 0L; PLZINFO pLZI; // Display sign-on banner. LoadString(NULL, SID_BANNER_TEXT, ErrorMsg, 1024); printf(ErrorMsg); // Parse command-line arguments. if (ParseArguments(argc, argv) != TRUE) return(EXIT_FAILURE); // Set up global target path name. pszTargetName = argv[iTarget]; if (bDisplayHelp == TRUE) { // User asked for help. LoadString(NULL, SID_INSTRUCTIONS, ErrorMsg, 1024); printf(ErrorMsg); LoadString(NULL, SID_INSTRUCTIONS2, ErrorMsg, 1024); printf(ErrorMsg); LoadString(NULL, SID_INSTRUCTIONS3, ErrorMsg, 1024); printf(ErrorMsg); return(EXIT_SUCCESS); } // Check for command line problems. if (CheckArguments() == FALSE) return(EXIT_FAILURE); // Set up ring buffer and I/O buffers. pLZI = InitGlobalBuffersEx(); if (!pLZI) { LoadString(NULL, SID_INSUFF_MEM, ErrorMsg, 1024); printf(ErrorMsg); return(EXIT_FAILURE); } // Process each source file. while ((iSourceFileName = GetNextFileArg(argv)) != FAIL) { // Set up global input file name. pszInFileName = _strlwr(argv[iSourceFileName]); // Set up global output file name. MakeDestFileName(argv, pszDestFileName); pszOutFileName = _strlwr(pszDestFileName); strcpy( chTargetFileName, pszOutFileName ); if ( bDoRename ) MakeCompressedName( chTargetFileName ); if (( ! bUpdateOnly ) || ( FileTimeIsNewer( pszInFileName, chTargetFileName ))) { if(DiamondCompressionType) { fError = DiamondCompressFile(ProcessNotification,pszInFileName, pszOutFileName,bDoRename,pLZI); } else { fError = Compress(ProcessNotification, pszInFileName, pszOutFileName, byteAlgorithm, bDoRename, pLZI); } if(fError != TRUE) // Deal with returned error codes. DisplayErrorMessage(nReturnCode = fError); else { nTotalFiles++; if (pLZI && pLZI->cblInSize && pLZI->cblOutSize) { // Keep track of cumulative statistics. cblTotInSize += pLZI->cblInSize; cblTotOutSize += pLZI->cblOutSize; // Display report for each file. LoadString(NULL, SID_FILE_REPORT, ErrorMsg, 1024); printf(ErrorMsg, pszInFileName, pLZI->cblInSize, pLZI->cblOutSize, (INT)(100 - 100 * pLZI->cblOutSize / pLZI->cblInSize)); } else { LoadString(NULL, SID_EMPTY_FILE_REPORT, ErrorMsg, 1024); printf(ErrorMsg, pszInFileName, 0, 0); } } // Separate individual file processing message blocks by a blank line. printf("\n"); } } // Free memory used by ring buffer and I/O buffers. FreeGlobalBuffers(pLZI); // Display cumulative report for multiple files. if (nTotalFiles > 1) { LoadString(NULL, SID_TOTAL_REPORT, ErrorMsg, 1024); printf(ErrorMsg, nTotalFiles, cblTotInSize, cblTotOutSize, (INT)(100 - 100 * cblTotOutSize / cblTotInSize)); } return(nReturnCode); }
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { HANDLE hPipe = INVALID_HANDLE_VALUE; HANDLE hEvents[2] = {NULL, NULL}; LPTSTR lpszPipeName = "\\\\.\\pipe\\ipcd"; OVERLAPPED os; BOOL bRet; DWORD cbRead; DWORD cbWritten; DWORD dwWait; SCBUF scIn; SCBUF scOut; #ifdef TERMINAL_SERVICE char *evtname; #endif /* TERMINAL_SERVICE */ // FreeConsole(); #ifdef TERMINAL_SERVICE int CheckWinVer(); #endif /* TERMINAL_SERVICE */ CheckArguments(lpCmdLine); if (CreateIpcTable()<0) ExitProcess(1); #ifdef TERMINAL_SERVICE if( osvi.dwMajorVersion >= 5 ) /* Windows 2000 */ evtname = "Global\\IPCDSTOP"; else evtname = "IPCDSTOP"; #endif /* TERMINAL_SERVICE */ hEvents[0] = CreateEvent( NULL, // no security attributes TRUE, // manual reset event FALSE, // not-signalled #ifdef TERMINAL_SERVICE evtname ); #else "IPCDSTOP"); // no name #endif /* TERMINAL_SERVICE */ if ( hEvents[0] == NULL) goto cleanup; hEvents[1] = CreateEvent( NULL, // no security attributes TRUE, // manual reset event FALSE, // not-signalled NULL); // no name if ( hEvents[1] == NULL) goto cleanup; hPipe = CreateNamedPipe( lpszPipeName, // name of pipe FILE_FLAG_OVERLAPPED | PIPE_ACCESS_DUPLEX, // pipe open mode PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, // pipe IO type 1, // number of instances 0, // size of outbuf (0 == allocate as necessary) 0, // size of inbuf 1000, // default time-out value NULL); // security attributes if (hPipe == INVALID_HANDLE_VALUE) { MessageBox(NULL, "Unable to create named pipe", "IPCD", MB_OK); goto cleanup; } while ( 1 ) { // init the overlapped structure // memset( &os, 0, sizeof(OVERLAPPED) ); os.hEvent = hEvents[1]; ResetEvent( hEvents[1] ); // wait for a connection... // ConnectNamedPipe(hPipe, &os); if ( GetLastError() == ERROR_IO_PENDING ) { dwWait = WaitForMultipleObjects( 2, hEvents, FALSE, INFINITE ); if ( dwWait != WAIT_OBJECT_0+1 ) // not overlapped i/o event - error occurred, break; // or ipcd stop signaled } // init the read, write structure scIn.cmd = 0; scIn.data = 0; scOut.cmd = 0; scOut.data = 0; // init the overlapped structure // memset( &os, 0, sizeof(OVERLAPPED) ); os.hEvent = hEvents[1]; ResetEvent( hEvents[1] ); // grab whatever's coming through the pipe... // bRet = ReadFile( hPipe, // file to read from (char *)&scIn, // address of input buffer sizeof(scIn), // number of bytes to read &cbRead, // number of bytes read &os); // overlapped stuff, not needed if ( !bRet && ( GetLastError() == ERROR_IO_PENDING ) ) { dwWait = WaitForMultipleObjects( 2, hEvents, FALSE, INFINITE ); if ( dwWait != WAIT_OBJECT_0+1 ) // not overlapped i/o event - error occurred, break; // or server stop signaled } switch (scIn.cmd) { case SNO_SHMGET : ShmgetService(scIn.data, &scOut); break; case SNO_SHMCTL : ShmctlService(scIn.data, &scOut); break; case SNO_SEMGET : SemgetService(scIn.data, &scOut); break; case SNO_SEMCTL : SemctlService(scIn.data, &scOut); break; default : scOut.cmd=SNO_ERROR; scOut.data=EINVAL; break; } // init the overlapped structure // memset( &os, 0, sizeof(OVERLAPPED) ); os.hEvent = hEvents[1]; ResetEvent( hEvents[1] ); // send it back out... // bRet = WriteFile( hPipe, // file to write to (char *)&scOut, // address of output buffer sizeof(scOut), // number of bytes to write &cbWritten, // number of bytes written &os); // overlapped stuff, not needed if ( !bRet && ( GetLastError() == ERROR_IO_PENDING ) ) { dwWait = WaitForMultipleObjects( 2, hEvents, FALSE, INFINITE ); if ( dwWait != WAIT_OBJECT_0+1 ) // not overlapped i/o event - error occurred, break; // or server stop signaled } // drop the connection... // DisconnectNamedPipe(hPipe); } cleanup: if (hShmIpcMutex) CloseHandle(hShmIpcMutex); if (hSemIpcMutex) CloseHandle(hSemIpcMutex); if (hShmPinfoMutex) CloseHandle(hShmPinfoMutex); if (hSemPinfoMutex) CloseHandle(hSemPinfoMutex); DestroyIpcTable(); if (hPipe != INVALID_HANDLE_VALUE ) CloseHandle(hPipe); if (hEvents[0]) // ipcd stop event CloseHandle(hEvents[0]); if (hEvents[1]) // overlapped i/o event CloseHandle(hEvents[1]); return TRUE; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { register int i; float x; int max_len = 6; int p; int ns0 = 29; float length = 0.0f; static area_function *af0; if (CheckArguments(nlhs, plhs, nrhs, prhs) ){ mexErrMsgTxt("AS2F argument checking failed."); return ; } /* read nasal tract area function from the file */ //printf("Reading nasal tract file.\n"); read_af(NTAFpath , &nna, &afnt ); //printf("Finished Reading nasal tract file.\n"); /* Initialization */ //read_rad(); // update all constants and variables if((int)(pTCcfg[0]) == RL_CIRCUIT) rad_boundary = RL_CIRCUIT; else rad_boundary = SHORT_CIRCUIT; //printf("Rad_boundary[%d]\n",rad_boundary); if((int)(pTCcfg[1]) == YIELDING) wall = YIELDING; else wall = RIGID; //printf("wall[%d]\n",wall); if((int)(pTCcfg[2]) == ON) nasal_tract = ON; else nasal_tract = OFF; //printf("nasal_tract[%d]\n",nasal_tract); if((int)(pTCcfg[3]) == CLOSE) glt_boundary = CLOSE; else glt_boundary = OPEN; //printf("glt_boundary[%d]\n",glt_boundary); ro = (float)(pPCcfg[0]); //printf("Air density[%f]\n",ro); c = (float)(pPCcfg[1]); //printf("Sound velocity[%f]\n",c); wall_resi = (float)(pPCcfg[2]); //printf("wall_resi[%f]\n",wall_resi); wall_mass = (float)(pPCcfg[3]); //printf("wall_mass[%f]\n",wall_mass); wall_comp = (float)(pPCcfg[4]); //printf("wall_comp[%f]\n",wall_comp); nss = (int)(pAFcfgmisc[0]); //printf("no. of sections[%d]\n",nss); anc = (float)(pAFcfgmisc[1]); //printf("nasal area[%f]\n",anc); /* Initialization */ af0 = (area_function *) calloc( size, sizeof(area_function) ); ns0 = size; //printf("Number of sections provided[%d]",ns0); length = 0.0f; for(i=0;i<ns0;i++) { af0[i].A = (float)(pAFcfg[2*i]); af0[i].x = (float)(pAFcfg[2*i+1]); length += af0[i].x; } //printf("Tube length[%.1f]",length); x = length/(float) nss; nph = (int)(9.0/x); /* nasal brantch point is 9 cm above glottis */ nbu = nss - nph; afvt = (area_function *) calloc( nss, sizeof(area_function) ); oAf = mxCreateDoubleMatrix(2,nss, mxREAL); pAf = mxGetPr(oAf); /* Compute VT profile and area function, and plot them */ appro_area_function( ns0, af0, nss, afvt); for(i=0;i<nss;i++) { //printf("AreaAF[%d][%f]\n",i,afvt[i]); pAf[2*i] = afvt[i].A; pAf[2*i+1] = afvt[i].x; } if( nasal_tract == ON ) { anc = (float) min( anc, afvt[nph].A ); afvt[nph].A -= anc; pAf[2*nph] = afvt[nph].A; pAf[2*nph+1] = afvt[nph].x; } calplot_tf_FBA(nfrmmax, frm, bw, amp, &nfrms, tfunc, &ntf); //printf("Finished calculations.\n"); oTf = mxCreateDoubleMatrix(ntf, 1, mxREAL); pTf = mxGetPr(oTf); for(i=0;i<ntf;i++) { pTf[i] = tfunc[i]; } oFmt = mxCreateDoubleMatrix(nfrms, 1, mxREAL); pFmt = mxGetPr(oFmt); oBw = mxCreateDoubleMatrix(nfrms, 1, mxREAL); pBw = mxGetPr(oBw); oAmp = mxCreateDoubleMatrix(nfrms, 1, mxREAL); pAmp = mxGetPr(oAmp); for(i=0;i<nfrms;i++) { pFmt[i] = frm[i]; pBw[i] = bw[i]; pAmp[i] = amp[i]; } /* Assign output pointers */ plhs[0] = oAf; plhs[1] = oTf; plhs[2] = oFmt; plhs[3] = oBw; plhs[4] = oAmp; // do cleanup //free( rad_re ); //free( rad_im ); free( afnt ); free( af0 ); free( afvt ); }
bool CheckArguments(std::string name, std::vector<std::string> args, int argcount) { return CheckArguments(name, args, argcount, argcount); }
/// <summary> /// Cleans out the filesystem, removing any unused or unneeded blocks. /// </summary> void DoClean(std::vector<std::string> cmd) { if (!CheckArguments("clean", cmd, 0)) return; std::pair<std::vector<uint32_t>, std::vector<uint32_t> > p = GetDataBlocks(Program::FS->getINodeByPosition(OFFSET_FSINFO).pos_root); std::vector<uint32_t> datablocks = p.first; std::vector<uint32_t> headerblocks = p.second; uint32_t pos = OFFSET_FSINFO; int failed = 0; int cleaned = 0; int cleaned_temporary = 0; int cleaned_invalid = 0; int cleaned_files = 0; int cleaned_directories = 0; int i = 0; while (true) { try { AppLib::LowLevel::INode node = Program::FS->getINodeByPosition(pos); if (!Program::FS->isBlockFree(pos)) { bool data = false; bool header = false; for (int a = 0; a < datablocks.size(); a += 1) if (datablocks[a] == pos) { data = true; break; } for (int a = 0; a < headerblocks.size(); a += 1) if (headerblocks[a] == pos) { header = true; break; } if (!data && !header) { // Check to see if we should 'free' it in the filesystem. switch (node.type) { case AppLib::LowLevel::INodeType::INT_TEMPORARY: if (Program::FS->resetBlock(pos) == AppLib::LowLevel::FSResult::E_SUCCESS) { cleaned += 1; cleaned_temporary += 1; } else failed += 1; break; case AppLib::LowLevel::INodeType::INT_INVALID: if (Program::FS->resetBlock(pos) == AppLib::LowLevel::FSResult::E_SUCCESS) { cleaned += 1; cleaned_invalid += 1;; } else failed += 1; break; case AppLib::LowLevel::INodeType::INT_FILEINFO: if (Program::FS->resetBlock(pos) == AppLib::LowLevel::FSResult::E_SUCCESS) { cleaned += 1; cleaned_files += 1;; } else failed += 1; break; case AppLib::LowLevel::INodeType::INT_DIRECTORY: if (Program::FS->resetBlock(pos) == AppLib::LowLevel::FSResult::E_SUCCESS) { cleaned += 1; cleaned_directories += 1;; } else failed += 1; break; default: // Do nothing? break; } } } pos += BSIZE_FILE; } catch (std::ifstream::failure e) { // End-of-file. Program::FSStream->clear(); printf("Cleaned %i blocks (%i temporary, %i invalid, %i files, %i directories).\n", cleaned, cleaned_temporary, cleaned_invalid, cleaned_files, cleaned_directories); if (failed > 0) printf("%i blocks could not be freed during cleaning.\n", failed); return; } } }
/// <summary> /// Show the structure of the disk image by showing the type of data in each 4096b segment. /// </summary> void DoSegments(std::vector<std::string> cmd) { if (!CheckArguments("segments", cmd, 0)) return; std::pair<std::vector<uint32_t>, std::vector<uint32_t> > p = GetDataBlocks(Program::FS->getINodeByPosition(OFFSET_FSINFO).pos_root); std::vector<uint32_t> datablocks = p.first; std::vector<uint32_t> headerblocks = p.second; printf("_ = free block F = file info S = segment info\n"); printf("# = data D = directory L = symbolic link\n"); printf("T = temporary data %% = freelist H = hard link\n"); printf("I = filesystem info ? = invalid = unset\n"); printf("! = inaccessible (will be removed by the clean operation)\n"); printf("\n"); printf("Header blocks: %i\n", headerblocks.size()); printf("Data blocks: %i\n", datablocks.size()); printf("\n"); printf("/===============================================================\\\n"); printf("|"); uint32_t pos = OFFSET_FSINFO; int i = 0; while (true) { try { AppLib::LowLevel::INode node = Program::FS->getINodeByPosition(pos); if (i == 16) { printf("\n"); printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+\n"); printf("|"); i = 1; } else i += 1; if (Program::FS->isBlockFree(pos)) printf(" _ |"); else { bool data = false; bool header = false; for (int a = 0; a < datablocks.size(); a += 1) if (datablocks[a] == pos) { data = true; break; } for (int a = 0; a < headerblocks.size(); a += 1) if (headerblocks[a] == pos) { header = true; break; } if (data) printf(" # |"); else if (node.type < 0 || node.type > 255 || Program::TypeChars[node.type] == 0) printf(" ? |"); else if (header || (node.type != AppLib::LowLevel::INodeType::INT_FILEINFO && node.type != AppLib::LowLevel::INodeType::INT_DIRECTORY)) printf(" %c |", Program::TypeChars[node.type]); else printf(" %c!|", Program::TypeChars[node.type]); } pos += BSIZE_FILE; } catch (std::ifstream::failure e) { // End-of-file. Program::FSStream->clear(); if (i == 16) printf("\n"); for (int a = i + 1; a <= 16; a += 1) { if (a == 16) printf(" |\n"); else printf(" "); } printf("\\===============================================================/\n"); return; } } }