/* compile shaders and return their ids in a 2-vector */ glm::ivec2 loadShaders(std::string vertFile, std::string fragFile) { GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); /* read shader files into strings */ std::ifstream vfile(vertFile.c_str()); std::ifstream ffile(fragFile.c_str()); std::ostringstream vbuffer, fbuffer; vbuffer << vfile.rdbuf(); fbuffer << ffile.rdbuf(); std::string vertexString(vbuffer.str()); std::string fragmentString(fbuffer.str()); /* convert strings to c_strings and set as shader source */ char *vertexCString, *fragmentCString; vertexCString = new char[vertexString.length() + 1]; fragmentCString = new char[fragmentString.length() + 1]; strcpy(vertexCString, vertexString.c_str()); strcpy(fragmentCString, fragmentString.c_str()); glShaderSource(vertexShader, 1, (const char**)&vertexCString, 0); glShaderSource(fragmentShader, 1, (const char**)&fragmentCString, 0); delete vertexCString; delete fragmentCString; /* compile shaders and check for errors */ GLint status; glCompileShader(vertexShader); glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status); if(status != GL_TRUE) { char log[2048]; int len; glGetShaderInfoLog(vertexShader, 2048, (GLsizei*)&len, log); fprintf(stderr, "Vertex Shader: %s", log); glDeleteShader(vertexShader); glDeleteShader(fragmentShader); exit(1); } glCompileShader(fragmentShader); glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &status); if(status != GL_TRUE) { char log[2048]; int len; glGetShaderInfoLog(fragmentShader, 2048, (GLsizei*)&len, log); fprintf(stderr, "Fragment Shader: %s", log); glDeleteShader(vertexShader); glDeleteShader(fragmentShader); exit(1); } return glm::ivec2(vertexShader, fragmentShader); }
void FileKindTestCase::Socket() { int s = socket(PF_INET, SOCK_STREAM, 0); wxFile file(s); TestFd(file, false); file.Detach(); wxFFile ffile(fdopen(s, "r")); TestFILE(ffile, false); }
// test with an ordinary file // void FileKindTestCase::File() { TempFile tmp; // put first wxFile file; tmp.m_name = wxFileName::CreateTempFileName(wxT("wxft"), &file); TestFd(file, true); file.Close(); wxFFile ffile(tmp.m_name); TestFILE(ffile, true); }
void FileKindTestCase::Pipe() { int afd[2]; #ifdef __UNIX__ pipe(afd); #else _pipe(afd, 256, O_BINARY); #endif wxFile file0(afd[0]); wxFile file1(afd[1]); TestFd(file0, false); file0.Detach(); wxFFile ffile(fdopen(afd[0], "r")); TestFILE(ffile, false); }
void filter_set::read_filter_file() { ifstream ffile(ff_name.c_str()); string line; if( ffile.is_open() ){ while (! ffile.eof() ) { getline( ffile, line ); filter_file.push_back(line); } ffile.close(); } else { cerr << "Can't open input file: " << ff_name << endl; } }
void Connections::writeCSVs(){ QFile cfile("coords.csv"); cfile.open(QIODevice::WriteOnly); QTextStream out(&cfile); out << "id,label,x,y" << endl; for (int i = 0; i<nodes.length(); i++){ out << i << "," << i << "," << nodes.at(i).x() << "," << nodes.at(i).y() << endl; } cfile.close(); QFile ffile("cons.csv"); ffile.open(QIODevice::WriteOnly); QTextStream fout(&ffile); fout << "from,to,val" << endl; for (int i = 0; i<edges.length(); i++){ fout << nodes.indexOf(edges.at(i)->fn) << "," << nodes.indexOf(edges.at(i)->tn) << "," << 1 << endl; } ffile.close(); }
void FileKindTestCase::Pipe() { int afd[2]; int rc; #ifdef __UNIX__ rc = pipe(afd); #else rc = _pipe(afd, 256, O_BINARY); #endif CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to create pipe", 0, rc); wxFile file0(afd[0]); wxFile file1(afd[1]); TestFd(file0, false); file0.Detach(); wxFFile ffile(fdopen(afd[0], "r")); TestFILE(ffile, false); }
// Saves the players options... void Ultra1::App::PlayerOptions::Save( ) { std::string home; #ifdef WIN32 home = getenv("USERPROFILE"); #else home = getenv("HOME"); #endif std::fstream ffile((home + "/.ultrabear1/config/screen.dat").c_str( ), std::ios::out ); if(!ffile.is_open( )) throw Sim::Exception("Save", "Could not write to screen file"); if( fullscreen ) ffile << 1 << std::endl; else ffile << 0 << std::endl; ffile.close( ); std::fstream sfile((home + "/.ultrabear1/config/sound.dat").c_str( ), std::ios::out ); if(!sfile.is_open( )) throw Sim::Exception("Save", "Could not write to sound file"); if( sound ) sfile << 1 << std::endl; else sfile << 0 << std::endl; if( music ) sfile << 1 << std::endl; else sfile << 0 << std::endl; sfile.close( ); std::fstream kfile((home + "/.ultrabear1/config/keys.dat").c_str( ), std::ios::out ); if(!kfile.is_open( )) throw Sim::Exception("Save", "Could not write to keys file"); kfile << left << std::endl; kfile << right << std::endl; kfile << up << std::endl; kfile << down << std::endl; kfile << jump << std::endl; kfile << 0 << std::endl; kfile << pause << std::endl; kfile.close( ); }
/* * Execute the system finger and translate LF to CRLF. */ static void sys_finger(const char *l) { FILE *fp; char fn[1024]; char *p; if (ffile(l) == 0) exit(0); snprintf(fn, sizeof(fn), "exec %s %s", SYS_FINGER, l); if ((fp = safe_popen(fn, "r")) == NULL) { printf("popen: %s\r\n", strerror(errno)); exit(1); } while(fgets(fn, 1024, fp)) { if ((p = strchr(fn, '\n')) != NULL) *p = 0; fprintf(stdout, "%s\r\n", fn); } pclose(fp); exit(0); }
/* * Main program, either pmwho or fingerd. */ int main(int argc, char **argv) { CONF_SECTION *maincs, *cs; FILE *fp; struct radutmp rt; char inbuf[128]; char othername[256]; char nasname[1024]; char session_id[sizeof(rt.session_id)+1]; int fingerd = 0; int hideshell = 0; int showsid = 0; int rawoutput = 0; int radiusoutput = 0; /* Radius attributes */ char *p, *q; const char *portind; int c; unsigned int portno; char buffer[2048]; const char *user = NULL; int user_cmp = 0; time_t now = 0; uint32_t nas_port = ~0; uint32_t nas_ip_address = INADDR_NONE; int zap = 0; raddb_dir = RADIUS_DIR; while((c = getopt(argc, argv, "d:fF:nN:sSipP:crRu:U:Z")) != EOF) switch(c) { case 'd': raddb_dir = optarg; break; case 'f': fingerd++; showname = 0; break; case 'F': radutmp_file = optarg; break; case 'h': usage(0); break; case 'S': hideshell = 1; break; case 'n': showname = 0; break; case 'N': if (inet_pton(AF_INET, optarg, &nas_ip_address) < 0) { usage(1); } break; case 's': showname = 1; break; case 'i': showsid = 1; break; case 'p': showptype = 1; break; case 'P': nas_port = atoi(optarg); break; case 'c': showcid = 1; showname = 1; break; case 'r': rawoutput = 1; break; case 'R': radiusoutput = 1; now = time(NULL); break; case 'u': user = optarg; user_cmp = 0; break; case 'U': user = optarg; user_cmp = 1; break; case 'Z': zap = 1; break; default: usage(1); break; } /* * Be safe. */ if (zap && !radiusoutput) zap = 0; /* * zap EVERYONE, but only on this nas */ if (zap && !user && (~nas_port == 0)) { /* * We need to know which NAS to zap users in. */ if (nas_ip_address == INADDR_NONE) usage(1); printf("Acct-Status-Type = Accounting-Off\n"); printf("NAS-IP-Address = %s\n", hostname(buffer, sizeof(buffer), nas_ip_address)); printf("Acct-Delay-Time = 0\n"); exit(0); /* don't bother printing anything else */ } if (radutmp_file) goto have_radutmp; /* * Initialize mainconfig */ memset(&mainconfig, 0, sizeof(mainconfig)); mainconfig.radlog_dest = RADLOG_STDOUT; /* Read radiusd.conf */ snprintf(buffer, sizeof(buffer), "%.200s/radiusd.conf", raddb_dir); maincs = cf_file_read(buffer); if (!maincs) { fprintf(stderr, "%s: Error reading or parsing radiusd.conf.\n", argv[0]); exit(1); } /* Read the radutmp section of radiusd.conf */ cs = cf_section_find_name2(cf_section_sub_find(maincs, "modules"), "radutmp", NULL); if(!cs) { fprintf(stderr, "%s: No configuration information in radutmp section of radiusd.conf!\n", argv[0]); exit(1); } cf_section_parse(cs, NULL, module_config); /* Assign the correct path for the radutmp file */ radutmp_file = radutmpconfig.radutmp_fn; have_radutmp: /* * See if we are "fingerd". */ if (strstr(argv[0], "fingerd")) { fingerd++; eol = "\r\n"; if (showname < 0) showname = 0; } if (showname < 0) showname = 1; if (fingerd) { /* * Read first line of the input. */ fgets(inbuf, 128, stdin); p = inbuf; while(*p == ' ' || *p == '\t') p++; if (*p == '/' && *(p + 1)) p += 2; while(*p == ' ' || *p == '\t') p++; for(q = p; *q && *q != '\r' && *q != '\n'; q++) ; *q = 0; /* * See if we fingered a specific user. */ ffile("header"); if (*p) sys_finger(p); } /* * Show the users logged in on the terminal server(s). */ if ((fp = fopen(radutmp_file, "r")) == NULL) { fprintf(stderr, "%s: Error reading %s: %s\n", progname, radutmp_file, strerror(errno)); return 0; } /* * Don't print the headers if raw or RADIUS */ if (!rawoutput && !radiusoutput) { fputs(showname ? hdr1 : hdr2, stdout); fputs(eol, stdout); } /* * Read the file, printing out active entries. */ while (fread(&rt, sizeof(rt), 1, fp) == 1) { if (rt.type != P_LOGIN) continue; /* hide logout sessions */ /* * We don't show shell users if we are * fingerd, as we have done that above. */ if (hideshell && !strchr("PCS", rt.proto)) continue; /* * Print out sessions only for the given user. */ if (user) { /* only for a particular user */ if (((user_cmp == 0) && (strncasecmp(rt.login, user, strlen(user)) != 0)) || ((user_cmp == 1) && (strncmp(rt.login, user, strlen(user)) != 0))) { continue; } } /* * Print out only for the given NAS port. */ if (~nas_port != 0) { if (rt.nas_port != nas_port) continue; } /* * Print out only for the given NAS IP address */ if (nas_ip_address != INADDR_NONE) { if (rt.nas_address != nas_ip_address) continue; } memcpy(session_id, rt.session_id, sizeof(rt.session_id)); session_id[sizeof(rt.session_id)] = 0; if (!rawoutput && rt.nas_port > (showname ? 999 : 99999)) { portind = ">"; portno = (showname ? 999 : 99999); } else { portind = "S"; portno = rt.nas_port; } /* * Print output as RADIUS attributes */ if (radiusoutput) { memcpy(nasname, rt.login, sizeof(rt.login)); nasname[sizeof(rt.login)] = '\0'; fr_print_string(nasname, 0, buffer, sizeof(buffer)); printf("User-Name = \"%s\"\n", buffer); fr_print_string(session_id, 0, buffer, sizeof(buffer)); printf("Acct-Session-Id = \"%s\"\n", buffer); if (zap) printf("Acct-Status-Type = Stop\n"); printf("NAS-IP-Address = %s\n", hostname(buffer, sizeof(buffer), rt.nas_address)); printf("NAS-Port = %u\n", rt.nas_port); switch (rt.proto) { case 'S': printf("Service-Type = Framed-User\n"); printf("Framed-Protocol = SLIP\n"); break; case 'P': printf("Service-Type = Framed-User\n"); printf("Framed-Protocol = PPP\n"); break; default: printf("Service-type = Login-User\n"); break; } if (rt.framed_address != INADDR_NONE) { printf("Framed-IP-Address = %s\n", hostname(buffer, sizeof(buffer), rt.framed_address)); } /* * Some sanity checks on the time */ if ((rt.time <= now) && (now - rt.time) <= (86400 * 365)) { printf("Acct-Session-Time = %ld\n", now - rt.time); } if (rt.caller_id[0] != '\0') { memcpy(nasname, rt.caller_id, sizeof(rt.caller_id)); nasname[sizeof(rt.caller_id)] = '\0'; fr_print_string(nasname, 0, buffer, sizeof(buffer)); printf("Calling-Station-Id = \"%s\"\n", buffer); } printf("\n"); /* separate entries with a blank line */ continue; } /* * Show the fill name, or not. */ if (showname) { printf((rawoutput == 0? rfmt1: rfmt1r), rt.login, showcid ? rt.caller_id : (showsid? session_id : fullname(rt.login)), proto(rt.proto, rt.porttype), portind, portno, dotime(rt.time), hostname(nasname, sizeof(nasname), rt.nas_address), hostname(othername, sizeof(othername), rt.framed_address), eol); } else { printf((rawoutput == 0? rfmt2: rfmt2r), rt.login, portind, portno, proto(rt.proto, rt.porttype), dotime(rt.time), hostname(nasname, sizeof(nasname), rt.nas_address), hostname(othername, sizeof(othername), rt.framed_address), eol); } } fclose(fp); return 0; }
GLuint engine::loadshaders(std::string vertfile, std::string fragfile, std::vector<std::string> in_attributes, std::vector<std::string> out_attributes) { /* init glew and load compiled shaders */ glewInit(); if(!glewIsSupported("GL_VERSION_2_0 GL_ARB_multitexture GL_EXT_framebuffer_object")) { fprintf(stderr, "Required OpenGL extensions missing\n"); return -1; } GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); /* read shader files into strings */ std::ifstream vfile(vertfile.c_str()); std::ifstream ffile(fragfile.c_str()); if(!vfile) { std::cout << vertfile << " does not exist!\n"; exit(1); } if(!ffile) { std::cout << fragfile << " does not exist!\n"; exit(1); } std::ostringstream vbuffer, fbuffer; vbuffer << vfile.rdbuf(); fbuffer << ffile.rdbuf(); std::string vertexString(vbuffer.str()); std::string fragmentString(fbuffer.str()); /* convert strings to c_strings and set as shader source */ char *vertexCString, *fragmentCString; vertexCString = new char[vertexString.length() + 1]; fragmentCString = new char[fragmentString.length() + 1]; strcpy(vertexCString, vertexString.c_str()); strcpy(fragmentCString, fragmentString.c_str()); glShaderSource(vertexShader, 1, (const char**)&vertexCString, 0); glShaderSource(fragmentShader, 1, (const char**)&fragmentCString, 0); delete vertexCString; delete fragmentCString; /* compile shaders and check for errors */ GLint status; glCompileShader(vertexShader); glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status); if(status != GL_TRUE) { char log[2048]; int len; glGetShaderInfoLog(vertexShader, 2048, (GLsizei*)&len, log); fprintf(stderr, "Vertex Shader: %s", log); glDeleteShader(vertexShader); glDeleteShader(fragmentShader); exit(1); } glCompileShader(fragmentShader); glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &status); if(status != GL_TRUE) { char log[2048]; int len; glGetShaderInfoLog(fragmentShader, 2048, (GLsizei*)&len, log); fprintf(stderr, "Fragment Shader: %s", log); glDeleteShader(vertexShader); glDeleteShader(fragmentShader); exit(1); } /* create program, bind attributes, and link program */ int program = glCreateProgram(); glAttachShader(program, vertexShader); glAttachShader(program, fragmentShader); int num_in_attributes = in_attributes.size(); for(int i = 0; i < num_in_attributes; i++) { glBindAttribLocation(program, i, in_attributes.at(i).c_str()); } int num_out_attributes = out_attributes.size(); for(int i = 0; i < num_out_attributes; i++) { glBindFragDataLocation(program, i, out_attributes.at(i).c_str()); } glLinkProgram(program); GLint pstatus; glGetProgramiv(program, GL_LINK_STATUS, &pstatus); if(pstatus != GL_TRUE) { char log[2048]; int len; glGetProgramInfoLog(program, 2048, (GLsizei*)&len, log); fprintf(stderr, "%s", log); glDeleteProgram(program); return -1; } return program; }
int main(int argc, char** argv){ QStringList arg; for(int i=0; i<argc; ++i){ arg.append(argv[i]); } if(arg.length() != 4){ help(); return -1; } const QString sfile = arg[1]; QFile ffile(sfile); if(!ffile.open(QIODevice::ReadOnly)){ qerr << "Unable to open input file "<<sfile<<endl; help(); return -1; } QTextStream tfile(&ffile); const QString slfile = arg[2]; QFile flfile(slfile); if(!flfile.open(QIODevice::WriteOnly)){ qerr << "Unable to open input file "<<slfile<<endl; help(); return -1; } QTextStream lfile(&flfile); const QString sdfile = arg[3]; QFile fdfile(sdfile); if(!fdfile.open(QIODevice::WriteOnly)){ qerr << "Unable to open input file "<<sdfile<<endl; help(); return -1; } QTextStream dfile(&fdfile); // read in transactions from file QList<Transaction> tlist = readTransactionFile(tfile); // create a map of transactions searchable by name QHash<QString,Transaction> tname = mapNameTransaction(tlist); // create the intermediate transaction states QHash<TransactionStateHead,TransactionState> tstate = generateTransactionState(tlist); // create a map of dependencies QHash<TransactionStateHead,QSet<TransactionEdge> > tgraph = generateStateMap(tstate); // create a reveresed set of dependencies QHash<TransactionStateHead,QSet<TransactionEdge> > reverse = reverseStateMap(tgraph); // create a trimmed set of dependencies PeerMap trimLive = trimStateMapLive(tgraph, reverse); PeerMap trimDead = trimStateMapDead(tgraph, reverse); // printTransactions(qout, tlist); // printTransactionRoot(qout, tstate); printTransactionGraph(lfile, trimLive, true); printTransactionGraph(dfile, trimDead, false); ffile.close(); flfile.close(); fdfile.close(); return 0; }