int main // MAIN-LINE ( int arg_count // - # arg.s , char const * args[] ) // - arguments { int retn = 0; if( arg_count != 4 ) { helpInfo(); retn = 1; } else { in = fopen( args[1], "rt" ); if( NULL == in ) { errmsg( "cannot open" , args[1] , NULL ); retn = 2; } else { tgt = fopen( args[2], "rt" ); if( 0 == tgt ) { notemsg( "creating" , args[2] , NULL ); tgt_write = TRUE; } else { readTgt(); } readSrc(); for( ; ; ) { if( ! have_src ) break; if( ! tgt_write ) { if( have_tgt ) { if( src_size == strlen( target ) && 0 == memcmp( target, src_rec, src_size ) ) { readTgt(); } else { notemsg( "replacing" , args[2] , NULL ); tgt_write = TRUE; } } else { tgt_write = TRUE; } } if( ! storeSrc() ) { errmsg( "ran out of memory", NULL ); retn = 2; break; } readSrc(); } if( have_tgt ) { tgt_write = TRUE; } fclose( in ); if( NULL != tgt ) { fclose( tgt ); } if( 0 == retn ) { struct stat src_stats; struct utimbuf mod_times; stat( args[1], &src_stats ); mod_times.actime = src_stats.st_mtime; mod_times.modtime = src_stats.st_mtime; if( tgt_write && retn == 0 ) { tgt = fopen( args[2], "wt" ); if( 0 == tgt ) { errmsg( "cannot write file" , args[2] , NULL ); retn = 2; } else { record* rec = recordsList; while( NULL != rec ) { if( NULL == fputs( rec->_data, tgt ) ) { errmsg( "i/o error writing file" , args[2] , NULL ); retn = 2; break; } rec = rec->_next; } fclose( tgt ); if( 0 == retn ) { utime( args[2], &mod_times ); retn = setTimeFile( args[3], &mod_times ); } } } else { retn = setTimeFile( args[3], &mod_times ); } } } remove( args[1] ); } return retn; }
bool Shader::create(const std::string &vertFile, const std::string &fragFile) { GLenum err; idVertex = glCreateShader(GL_VERTEX_SHADER); if(idVertex == 0) { err = glGetError(); printf("\n\n**************************************************\n"); printf("idVertex = glCreateShader(GL_VERTEX_SHADER); %s\n", gluErrorString(err)); printf("**************************************************\n\n"); } idFragment = glCreateShader(GL_FRAGMENT_SHADER); if(idFragment == 0) { err = glGetError(); printf("\n\n**************************************************\n"); printf("idFragment = glCreateShader(GL_FRAGMENT_SHADER); %s\n", gluErrorString(err)); printf("**************************************************\n\n"); } char *vertexSrc = readSrc(vertFile); if(vertexSrc == NULL) { delete[] vertexSrc; printf("Could not read vertex source %s\n", vertFile.c_str()); return false; } char *fragSrc = readSrc(fragFile); if(fragSrc == NULL) { delete[] fragSrc; printf("Could not read fragment source %s\n", fragFile.c_str()); return false; } glShaderSource(idVertex, 1, (const char **)&vertexSrc, NULL); err = glGetError(); if(err != GL_NO_ERROR) { printf("\n\n**************************************************\n"); printf("glShaderSource(idVertex, 1, (const char **)&vertexSrc, NULL); %s\n", gluErrorString(err)); printf("**************************************************\n\n"); delete[] vertexSrc; delete[] fragSrc; return false; } glShaderSource(idFragment, 1, (const char **)&fragSrc, NULL); err = glGetError(); if(err != GL_NO_ERROR) { printf("\n\n**************************************************\n"); printf("glShaderSource(idFragment, 1, (const char **)&fragmentSrc, NULL); %s\n", gluErrorString(err)); printf("**************************************************\n\n"); delete[] vertexSrc; delete[] fragSrc; return false; } delete[] vertexSrc; delete[] fragSrc; glCompileShader(idVertex); int bVertexCompiled; glGetShaderiv(idVertex, GL_COMPILE_STATUS, &bVertexCompiled); if(bVertexCompiled == GL_FALSE) { err = glGetError(); printf("\n\n**************************************************\n"); printf("glCompileShader(idVertex); %s\n", gluErrorString(err)); printf("**************************************************\n\n"); return false; } glCompileShader(idFragment); int bFragmentCompiled; glGetShaderiv(idFragment, GL_COMPILE_STATUS, &bFragmentCompiled); if(bFragmentCompiled == GL_FALSE) { err = glGetError(); printf("\n\n**************************************************\n"); printf("glCompileShader(idFragment); %s\n", gluErrorString(err)); printf("**************************************************\n\n"); return false; } idProg = glCreateProgram(); if(idProg == 0) { err = glGetError(); printf("\n\n**************************************************\n"); printf("idProg = glCreateProgram(); %s\n", gluErrorString(err)); printf("**************************************************\n\n"); return false; } glAttachShader(idProg, idVertex); err = glGetError(); if(err != GL_NO_ERROR) { printf("\n\n**************************************************\n"); printf("glAttachShader(idProg, idVertex); %s\n", gluErrorString(err)); printf("**************************************************\n\n"); return false; } glAttachShader(idProg, idFragment); err = glGetError(); if(err != GL_NO_ERROR) { printf("\n\n**************************************************\n"); printf("glAttachShader(idProg, idFragment); %s\n", gluErrorString(err)); printf("**************************************************\n\n"); return false; } glLinkProgram(idProg); int bLinked; glGetProgramiv(idProg, GL_LINK_STATUS, &bLinked); if(bLinked == GL_FALSE) { err = glGetError(); printf("\n\n**************************************************\n"); printf(" glLinkProgram(idProg); %s\n", gluErrorString(err)); printf("**************************************************\n\n"); return false; } return true; }