void setDeltaTWithPythonFunctionObject::readParameters(const dictionary &dict) { readCode(dict,"init",initCode_); readCode(dict,"deltaT",deltaTCode_); pythonInterpreterWrapper::executeCode( initCode_, false ); }
void writeAndEndPythonFunctionObject::readParameters(const dictionary &dict) { readCode(dict,"init",initCode_); readCode(dict,"condition",conditionCode_); pythonInterpreterWrapper::executeCode( initCode_, false ); }
bool pythonIntegrationFunctionObject::read(const dictionary& dict) { Pbug << "read" << endl; readCode(dict,"start",startCode_); readCode(dict,"end",endCode_); readCode(dict,"execute",executeCode_); readCode(dict,"write",writeCode_,false); #ifdef FOAM_FUNCTIONOBJECT_HAS_SEPARATE_WRITE_METHOD_AND_NO_START return start(); #else return true; #endif }
void writeIfPythonFunctionObject::readParameters(const dictionary &dict) { readCode(dict,"initVariables",initCode_); readCode(dict,"startWrite",writeCode_); if(writeControlMode()==scmWriteUntilSwitch) { readCode(dict,"stopWrite",stopWriteCode_); } if(cooldownMode()==cdmRetrigger) { readCode(dict,"stopCooldown",stopCooldownCode_); } pythonInterpreterWrapper::executeCode( initCode_, false ); }
/** Start of program. Accepts input from console with name of files to read and name of files to write. Checks files for reading/writing. Then, calls on other methods to read through the file and uncompress the file. @param argc - number of commands user submitted @param argv - string text for each command from user @return Sucessfull end of the program */ int main( int argc, char *argv[] ) { //Default file which contains the "dictionary" of words char *wordFile = "words.txt"; //Open file from agrs FILE *input; FILE *output; //Check to make sure user entered the correct number of arguments if ( argc < ( ARGS - 1 ) || argc > ARGS ){ fprintf(stderr, "usage: unpack <compressed.raw> <output.txt> [word_file.txt]\n" ); exit( EXIT_FAILURE ); } //Optional input. If user enters optional file name, program will use it if ( argc == ARGS ) { wordFile = argv[ ARGS - 1 ]; } //Create wordList for our "dictionary" WordList *wordList = readWordList( wordFile ); //Open file for reading. Procduces error if file cannot open. if ( ( input = fopen( argv[ 1 ], "r" ) ) == NULL ){ fprintf(stderr, "Can't open file: %s\n", argv[ 1 ] ); fprintf(stderr, "usage: unpack <compressed.raw> <output.txt> [word_file.txt]\n" ); exit( EXIT_FAILURE ); //Open file for writing. Produces error if file cannot open. } else if ( ( output = fopen( argv[ 2 ], "w" ) ) == NULL ){ fprintf(stderr, "Can't open file: %s\n", argv[ 2 ] ); fprintf(stderr, "usage: unpack <compressed.raw> <output.txt> [word_file.txt]\n" ); exit( EXIT_FAILURE ); } //Variable to hold leftover binary code PendingBits pending = { 0, 0 }; //Loop that runs through file, writting letters to the writer file int number; //Continues to call method until method returns -1 while ( (number = readCode( &pending, input ) ) != -1 ){ //Prints words unless number is -1 or -2 if ( number != -1 && number != -2 ){ fprintf(output, "%s", wordList->words[ number ] ); } } //free wordList freeWordList( wordList ); //Close file fclose( input ); fclose( output ); return EXIT_SUCCESS; }
void prompt(char *command) { char buffer[100] = {'\0'}; int i = 0; static bool blockCode = false; static int blocks = 0; if (blockCode == false && blocks == 0) { printf(">>> "); } else { printf("... "); } fgets (buffer, 100, stdin); if (strncmp(buffer, "exit()", 6) == 0) { int status; status = remove("./c_code_temp.c"); if (status == 1) { error("Failure to remove file"); } exit(1); } if (strncmp(buffer, "read()", 6) == 0) { readCode(); } if (strncmp(buffer, "help()", 6) == 0) { help(); } if (strchr(buffer, '{') != NULL) { blockCode = true; blocks++; } else if(strchr(buffer, '}') != NULL) { blockCode = false; blocks--; } for (i = 0; i < 100; i++) { command[i] = buffer[i]; } }
bool Playlist::play() { char playCode[CODE_LENGTH + 1]; bool ok = readCode(playIndex, playCode); if(ok) { playChirpCode(playCode); isFirst = false; } return ok; }
bool internalizeOneObjectFile(objectFileListType *objectFile) { FILE *objectFildes; int magic; int mode; addressType startAddress; addressType endAddress; currentFileName = objectFile->name; if ((objectFildes = fopen(objectFile->name, "r")) == NULL) { error(CANT_OPEN_OBJECT_FILE_ERROR, objectFile->name); perror("Unix says"); return(FALSE); } if (verbose) printf("internalizing %s:\n", objectFile->name); if ((magic = readWord(objectFildes, objectFile->name)) != 0xFFFF) { error(BAD_OBJECT_FILE_ERROR, objectFile->name); return(FALSE); } mode = MODE_ABSOLUTE; for (;;) { startAddress = readWord(objectFildes, objectFile->name); if (startAddress == 0xFFFF) { if (mode == MODE_ABSOLUTE) { mode = MODE_RELOCATABLE; continue; } else { break; } } endAddress = readWord(objectFildes, objectFile->name); readCode(startAddress, endAddress, mode, objectFile, objectFildes); } readReservations(objectFile, objectFildes); readReferences(objectFile, objectFildes); readSymbols(objectFile, objectFildes); readExpressions(objectFile, objectFildes); readFunctions(objectFile, objectFildes); instantiateExpressionAndSymbolPointers(objectFile); if (readExpressionEntryPoint) { pc = entryPointExpression; putSymbolPointersIntoExpression(); readExpressionEntryPoint = FALSE; haveExpressionEntryPoint = TRUE; } qsort(objectFile->symbolTable, objectFile->symbolCount, sizeof(symbolType *), compareSymbolValues); fclose(objectFildes); return(TRUE); }
int main(int argc, char* argv[]) { if (argc == 4) { int socketDescriptor = createInetStreamSocket(); connectToInetServer(socketDescriptor, PORT, argv[1]); printf("%sConnected successful.%s\n", BLUE, RESET_COLOR); Message message; strcpy(message, argv[2]); writeMessage(socketDescriptor, message, sizeof(message)); printf("I've requested for: \"%s\"\n", message); Code size = 4; readCode(socketDescriptor, &size); printf("Code: %d\n", size); if (size == FILE_NOT_FOUND) { printf("%sError, file not found.%s\n", RED, RESET_COLOR); } else { Message message; int fileDescriptor = creat(argv[3], 0777); while (size > 0) { int readCode = readMessage(socketDescriptor, &message, sizeof(message)); int writeCode = writeMessage(fileDescriptor, message, readCode); //write(1, message, readCode); size -= readCode; } close(fileDescriptor); } close(socketDescriptor); printf("%sServer connexion closed, socket closed.%s\n", RED, RESET_COLOR); } else { perror("Invalid sintax. Use: ClienteRemoto IP SERVER_FILE CLIENT_FILE\n"); exit(-1); } }
// IBridge初始化方法 void IBridge::Init(int _myArgc, char* _myArgv[]) { // 没有附加参数就进入命令行模式 if (_myArgc == 1) { cout << NEWLINE << "SSQL Interpreter v1.0" << NEWLINE << "Copyright Group 12 of CAS 2012 SYSU" << NEWLINE << "-----------------------------------------" << NEWLINE << endl; this->sourcePath = _myArgv[0]; this->iType = RunType::RUN_CONSOLE; } // 否则是读文件的情况 else { this->sourcePath = _myArgv[1]; this->iType = RunType::RUN_INFILE; this->sourceCode = readCode(this->sourcePath); } }
void Playlist::printAsScript() { char buffer[max(max(TIME_STRING_LENGTH, CODE_LENGTH), MAX_SCRIPT_ADDRESS_LENGTH) + 1]; AutoplayStructure autoplaySettings; getAutoplaySettings(&autoplaySettings); if(readScriptAddress(buffer)) { Serial.print('#'); Serial.println(buffer); Serial.print('#'); Serial.println(READ_FROM_PLAYLIST(updateFlags)); } Serial.println('~'); // clear list Serial.print(':'); bool porta = READ_FROM_PLAYLIST(porta) != 0; Serial.print(porta ? 'P' : 'U'); Serial.println(READ_FROM_PLAYLIST(volume)); if(autoplaySettings.count) { Serial.print('*'); minutesToString(autoplaySettings.startMinute, buffer); Serial.print(buffer); if(autoplaySettings.count > 1) { Serial.print(' '); minutesToString(autoplaySettings.repeatMinutes, buffer); Serial.print(buffer); Serial.print(' '); Serial.print(autoplaySettings.count); } Serial.println(); } Serial.print('.'); Serial.print(autoplaySettings.order); Serial.println(autoplaySettings.interval); for(uint8_t ch = 0; ch < nChirps; ch++) { readCode(ch, buffer); Serial.println(buffer); } }
/** * Create the shaders. * * @param fileName file name of shader. Path is assume to be the project. * @param shaderType Can either be vertex shader or fragment shader. The type * must correspond to the OpenGL shader types. * @param shaderid Shader identifier pointer. * @return 0 - if successful, -1 if error. */ int Shader::createShaderObj(char* fileName , int shaderType, GLuint *shaderid) { char *code = NULL; int rc = 0; // create a shader handle *shaderid = glCreateShader(shaderType); // read the code code = readCode(fileName); if (code == NULL) return(-1); // attach the source to the shaders glShaderSource(*shaderid, 1, &code, NULL); // compile the code glCompileShader(*shaderid); // check for errors glGetShaderiv(*shaderid, GL_COMPILE_STATUS, &rc); if (rc != GL_TRUE) { GLsizei length; GLsizei bufSize = 0; char *error = NULL; fprintf(stderr,"Error when creating a shader \n"); //fputs("Error when creating a shader \n",stderr); glGetShaderiv(*shaderid, GL_INFO_LOG_LENGTH, &bufSize); error = (char *) malloc(bufSize*sizeof(char)+1); if (error != NULL) { glGetShaderInfoLog(*shaderid, bufSize, &length, error); fprintf(stderr,"%s \n", error); } if (error != NULL) free(error); rc = -1; } else rc = 0; if (code != NULL) free(code); // free the source code of the shader return(rc); }
void inflate_data(State& ioState, uint8_t* ioOutputTab, const uint32_t iOutputSize) { uint32_t anOutputPos = 0; // Reading the const write size addition value needBits(ioState, 8); dropBits(ioState, 4); uint16_t aWriteSizeConstAdd = readBits(ioState, 4) + 1; dropBits(ioState, 4); // Declaring our HuffmanTrees HuffmanTree aHuffmanTreeSymbol; HuffmanTree aHuffmanTreeCopy; while (anOutputPos < iOutputSize) { // Resetting Huffmantrees memset(&aHuffmanTreeSymbol, 0, sizeof(HuffmanTree)); memset(&aHuffmanTreeCopy, 0, sizeof(HuffmanTree)); // Reading HuffmanTrees parseHuffmanTree(ioState, aHuffmanTreeSymbol); parseHuffmanTree(ioState, aHuffmanTreeCopy); // Reading MaxCount needBits(ioState, 4); uint32_t aMaxCount = (readBits(ioState, 4) + 1) << 12; dropBits(ioState, 4); uint32_t aCurrentCodeReadCount = 0; while ((aCurrentCodeReadCount < aMaxCount) && (anOutputPos < iOutputSize)) { ++aCurrentCodeReadCount; // Reading next code uint16_t aCode = 0; readCode(aHuffmanTreeSymbol, ioState, aCode); if (aCode < 0x100) { ioOutputTab[anOutputPos] = static_cast<uint8_t>(aCode); ++anOutputPos; continue; } // We are in copy mode ! // Reading the additional info to know the write size aCode -= 0x100; // write size div_t aCodeDiv4 = div(aCode, 4); uint32_t aWriteSize = 0; if (aCodeDiv4.quot == 0) { aWriteSize = aCode; } else if (aCodeDiv4.quot < 7) { aWriteSize = ((1 << (aCodeDiv4.quot - 1)) * (4 + aCodeDiv4.rem)); } else if (aCode == 28) { aWriteSize = 0xFF; } else { throw exception::Exception("Invalid value for writeSize code."); } //additional bits if (aCodeDiv4.quot > 1 && aCode != 28) { uint8_t aWriteSizeAddBits = aCodeDiv4.quot - 1; needBits(ioState, aWriteSizeAddBits); aWriteSize |= readBits(ioState, aWriteSizeAddBits); dropBits(ioState, aWriteSizeAddBits); } aWriteSize += aWriteSizeConstAdd; // write offset // Reading the write offset readCode(aHuffmanTreeCopy, ioState, aCode); div_t aCodeDiv2 = div(aCode, 2); uint32_t aWriteOffset = 0; if (aCodeDiv2.quot == 0) { aWriteOffset = aCode; } else if (aCodeDiv2.quot < 17) { aWriteOffset = ((1 << (aCodeDiv2.quot - 1)) * (2 + aCodeDiv2.rem)); } else { throw exception::Exception("Invalid value for writeOffset code."); } //additional bits if (aCodeDiv2.quot > 1) { uint8_t aWriteOffsetAddBits = aCodeDiv2.quot - 1; needBits(ioState, aWriteOffsetAddBits); aWriteOffset |= readBits(ioState, aWriteOffsetAddBits); dropBits(ioState, aWriteOffsetAddBits); } aWriteOffset += 1; uint32_t anAlreadyWritten = 0; while ((anAlreadyWritten < aWriteSize) && (anOutputPos < iOutputSize)) { ioOutputTab[anOutputPos] = ioOutputTab[anOutputPos - aWriteOffset]; ++anOutputPos; ++anAlreadyWritten; } } } }
/** Opens appropriate files and handles them @param argc number of command line arguments @param argv array of command line arguments @return the exit status of the program */ int main( int argc, char *argv[] ) { char *wordFile = "words.txt"; FILE *input; FILE *output; if ( argc < 3 || argc > 4 ) { fprintf( stderr, "usage: pack <input.txt> <compressed.raw> [wordfile.txt]\n" ); exit( 1 ); } input = fopen( argv[ 1 ], "rb" ); if ( !input ) { printf( "usage: readFile <input-file>\n" ); exit( 1 ); } output = fopen( argv[ 2 ], "rw" ); if ( !output ) { printf( "usage: readFile <input-file>\n" ); exit( 1 ); } if ( argc == 4 ) { wordFile = argv[ 3 ]; } WordList *wordList = readWordList( wordFile ); #ifdef DEBUG // Report the entire contents of the word list, once it's built. printf( "---- word list -----\n" ); for ( int i = 0; i < wordList->len; i++ ) printf( "%d == %s\n", i, wordList->words[ i ] ); printf( "--------------------\n" ); #endif // ... // Read the contents of the whole file into one big buffer. This could be more // efficient, but it simplifies the rest of the program. char *buffer = readFile( input ); // Write out codes for everything in the buffer. int pos = 0; PendingBits pending = { 0, 0 }; while ( buffer[ pos ] ) { // Get the next code. int code = bestCode( wordList, buffer + pos ); #ifdef DEBUG printf( "%d <- %s\n", code, wordList->words[ code ] ); #endif // Write it out and move ahead by the number of characters we just encoded. readCode( &pending, input ); pos += strlen( wordList->words[ code ] ); } // Write out any remaining bits in the last, partial byte. flushBits( &pending, output ); // ... fclose( input ); fclose( output ); return EXIT_SUCCESS; }
int main(int argc,char** argv) { int width; int height; const char* source; // Source code cl_platform_id platform; // Platform { CPU, GPU, FPGA } cl_device_id device; // Device { GPU_ID } cl_context context; // Context cl_command_queue queue; // Queue cl_int err; // for error checking cl_event event[NR_KERNELS-1]; // must be ok for second kernel to run cl_program program; // program cl_kernel kernels_code[NR_KERNELS]; cl_mem bufferIN; // data IN cl_mem bufferOUT; // data OUT int* inputImage; // input image int* outputImage; // output image cl_uint *ptr; // data to be shown size_t global_work_size; // work size // get platform, get device, create context clGetPlatformIDs(1,&platform,NULL); clGetDeviceIDs(platform,COMPUTE,1,&device,NULL); context=clCreateContext(NULL,1,&device,NULL,NULL,NULL); queue=clCreateCommandQueue(context,device,0,NULL); // read data from file, allocate memory & copy inputImage=input_image(INPUT_IMAGE,&width,&height); bufferIN=clCreateBuffer(context,CL_MEM_READ_WRITE,width*height *sizeof(int),NULL,NULL); clEnqueueWriteBuffer(queue,bufferIN,1,0,width * height * sizeof(int),inputImage,0,0,0); bufferOUT= clCreateBuffer(context,CL_MEM_READ_WRITE,width*height *sizeof(int),NULL,NULL); // read code from file / check code source=readCode(FILENAME); if(source==NULL) { printf("Error reading code. Exiting"); return 1; } // init OPENCL program program=clCreateProgramWithSource(context,1,&source,NULL,&err); check(err,program,device); check(clBuildProgram(program,1,&device,NULL,NULL,NULL)); // kernels for(int i=0;i<NR_KERNELS;i++) { kernels_code[i]=clCreateKernel(program,kernels[i],&err); check(err,program,device); } // pass args, execute OPENCL kernels global_work_size=width*height; for(int i=0;i<NR_KERNELS;i++) { if((i+1)%2==0){ check(clSetKernelArg(kernels_code[i],0,sizeof(bufferOUT),(void*)&bufferOUT)); check(clSetKernelArg(kernels_code[i],1,sizeof(bufferIN),(void*)&bufferIN)); check(clSetKernelArg(kernels_code[i],2,sizeof(int),(void*)&width)); check(clSetKernelArg(kernels_code[i],3,sizeof(int),(void*)&height)); } else { check(clSetKernelArg(kernels_code[i],0,sizeof(bufferIN),(void*)&bufferIN)); check(clSetKernelArg(kernels_code[i],1,sizeof(bufferOUT),(void*)&bufferOUT)); check(clSetKernelArg(kernels_code[i],2,sizeof(int),(void*)&width)); check(clSetKernelArg(kernels_code[i],3,sizeof(int),(void*)&height)); } } size_t global_work[2]; global_work[0]=width; global_work[1]=height; // enqueue / run all kernels (pipeline in this case) // start first kernel check(clEnqueueNDRangeKernel(queue,kernels_code[0],2,NULL,global_work,NULL,0,NULL,&event[0])); // run all the rest (n-2) for(int i=1;i<NR_KERNELS-1;i++) check(clEnqueueNDRangeKernel(queue,kernels_code[i],2,NULL,global_work,NULL,i,event,&event[i])); // start last kernel if(NR_KERNELS>2) check(clEnqueueNDRangeKernel(queue,kernels_code[NR_KERNELS-1],2,NULL,global_work,NULL,NR_KERNELS-1,event,NULL)); // finish queue check(clFinish(queue)); if(NR_KERNELS%2==1) outputImage= (int*)clEnqueueMapBuffer(queue,bufferOUT,CL_TRUE,CL_MAP_READ,0,width*height*sizeof(int),0,NULL,NULL,NULL); else outputImage= (int*)clEnqueueMapBuffer(queue,bufferIN,CL_TRUE,CL_MAP_READ,0,width*height*sizeof(int),0,NULL,NULL,NULL); output_image(OUTPUT_IMAGE,outputImage,width,height); return 0; }
void executeIfPythonFunctionObject::readParameters(const dictionary &dict) { readCode(dict,"condition",conditionCode_); }