int Flu_Button :: handle( int event ) { if( !active_r() ) return Fl_Button::handle( event ); switch( event ) { case FL_MOVE: { checkLink(); return 1; } case FL_ENTER: { if( active() ) { Fl_Button::color( fl_lighter( col ) ); Fl_Button::selection_color( fl_lighter( sCol ) ); } checkLink(); redraw(); return 1; } break; case FL_LEAVE: { Fl_Button::color( col ); Fl_Button::selection_color( sCol ); checkLink(); redraw(); return 1; break; } } if( retBtn ) { if( event == FL_SHORTCUT && (Fl::event_key() == FL_Enter || Fl::event_key() == FL_KP_Enter)) { do_callback(); return 1; } } return Fl_Button::handle( event ); }
static void createProgram(const char *vertProgFile, const char *fragProgFile) { GLuint fragShader = 0, vertShader = 0; program = glCreateProgram(); if (vertProgFile) { vertShader = glCreateShader(GL_VERTEX_SHADER); readShader(vertShader, vertProgFile); glAttachShader(program, vertShader); } if (fragProgFile) { fragShader = glCreateShader(GL_FRAGMENT_SHADER); readShader(fragShader, fragProgFile); glAttachShader(program, fragShader); } glLinkProgram(program); checkLink(program); glUseProgram(program); assert(glIsProgram(program)); assert(glIsShader(fragShader)); assert(glIsShader(vertShader)); checkError(__LINE__); { /*texture*/ GLuint texLoc = glGetUniformLocationARB(program, "srcTex"); glUniform1iARB(texLoc, 0); } { /*setup offsets */ float offsets[] = { 1.0 / texture.width, 1.0 / texture.height, 0.0 , 1.0 / texture.height, -1.0 / texture.width, 1.0 / texture.height, 1.0 / texture.width, 0.0, 0.0 , 0.0, -1.0 / texture.width, 0.0, 1.0 / texture.width, -1.0 / texture.height, 0.0 , -1.0 / texture.height, -1.0 / texture.width, -1.0 / texture.height }; GLuint offsetLoc = glGetUniformLocationARB(program, "Offset"); glUniform2fv(offsetLoc, 9, offsets); } setupConvolution(); checkError(__LINE__); }
/** * Searches in the "name" directory for the "find" file, * if file is found and the user wanted to find that filetype * the path is added to a list that will be printed at the end. * Also puts all directories found in a list for it to be * searched. */ bool searchForFile(char* name, char *find, int t, struct Node* list) { DIR *dir; struct dirent *ent; struct stat f_info; bool foundFile = false; if (openDir(&dir, name, &ent)) { do { if ((lstat(ent->d_name, &f_info)) < 0) { fprintf(stderr, "lstat error: "); perror(ent->d_name); } else { if (t == 0 && compareName(ent->d_name, find)) { foundFile = true; } else if (checkDir(t, f_info, ent->d_name, find)) { foundFile = true; } else if (checkReg(t, f_info, ent->d_name, find)) { foundFile = true; } else if (checkLink(t, f_info, ent->d_name, find)) { foundFile = true; } if (checkDirAndRights(f_info) && !isDot(ent->d_name)) { int l = strlen(name) + strlen(ent->d_name); char *str = calloc(1, sizeof(char[l + 2])); strcpy(str, name); strcat(str, "/"); strcat(str, ent->d_name); insert(list, str); } } } while ((ent = readdir(dir))); } closedir(dir); return foundFile; }
int main() { /* len=snprintf(in,1024,"%s","LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLOL"); printf("!%s!\n",aes64encrypt(in)); printf("!%s!\n",aes64decrypt(base64)); printf("2print:%s\n",aesdecrypt(aesencrypt("LLLLAAALALALALALALALALALALALALALALALALALLAALLALAALLALLALLALALA"))); */ printf("len=%d\r\n",strlen(genLink("*****@*****.**","looooooooooooongnicki"))+strlen(getHash())); printf("http://site.ru/?Link=%d\n",checkLink(getLink(),getHash())); printf("http://site.ru/?Link=%s\n",getMail()); printf("http://site.ru/?Link=%s\n",getLogin()); /* len=sprintf(in,"%s","loolag"); bin2hex(in,out,len); printf("out:%s\n",out); hex2bin(out,in,strlen(out)); printf("in:%s\n",in); */ return 0; }
task main() { ubyte msg=0; SensorType[TOUCH1]=sensorTouch; SensorType[TOUCH2]=sensorTouch; SensorType[TOUCH3]=sensorTouch; checkLink(); PlayTone(400,100); eraseDisplay(); while(true){ //do not attempt to do encoding until you know your bot // is able to communicate and send the simple incrementing number over // to the worker bot //msg=encodeByAdd(); //msg=encodeByBits(); msg = (msg<255 ? ++msg : 0); //simply just send 1, 2, ... up to 255, then recycle nxtDisplayCenteredTextLine(3,"%d", msg); sndOver(msg); wait1Msec(20); } }
bool SimulatedWorld::checkLink(PositionableEntity* linker,PositionableEntity* linked) { bool aux1,aux2; aux1=false; aux2=false; for(int i=0;i<Items.size();i++) { if(linker==Items[i])aux1=true; } for(int i=0;i<Items.size();i++) { if(linked==Items[i])aux2=true; } if((aux1==true)&&(aux2==true)) { if((linked->getOwner()==NULL)||(linker->getLinkedTo()==NULL)) return true; else if(linker->getOwner()!=linked->getOwner()) return false; else if(linker->getLinkedTo()==linked) return false; else if(linker->getOwner()!=linker->getLinkedTo()->getOwner()) return true; else checkLink(linker->getLinkedTo(),linked); } else return false; }
void solve() { memset(vis, 0, sizeof(vis)); //dfs(S, 0); //for (int i = 1; i <= 100; ++i) //if(idx[i] && low[i] == idx[i]) //{ // std::cerr << "ge : " << i << std::endl; //} std::cerr << std::endl; for (int i = 1; i <= 50; ++i) { if(!checkLink(S, T, i)) std::cerr << "GG : " << i << std::endl; } //for (int i = 1; i <= ret[0]; ++i) //if(idx[st[i]] && low[st[i]] == idx[st[i]]) //{ // std::cerr << st[i] << ' '; //} //std::cerr << std::endl; }
/* OpenGL Hello World ************************* This example draws a yellow rectangle on a blue background. If anything goes wrong it will display a red image and print errors to the console */ int main(int argc, char* argv[]){ //Create an OpenGL window and set up a context with proper debug output // This varies based on platform, we use a couple libraries to do it for us GLFWwindow* window = init(800,600,"OpenGL Hello World"); if(window == nullptr){ //initialization failed return -1; } //set the clear color to a nice blue :) glClearColor(0.1f,0.3f,0.6f,1.0f); //create a simple shader program which tells the GPU how to draw our data //first get the source for the vertex shader GLuint vertexShaderId = glCreateShader(GL_VERTEX_SHADER); std::string vertexSource = readContentsOfFile("simple.vert"); const char* vertexSourcePtr = vertexSource.c_str(); const GLint vertexSourceLength = vertexSource.size(); glShaderSource(vertexShaderId,1,&vertexSourcePtr,&vertexSourceLength); //Give OpenGL the source code //now we can compile it glCompileShader(vertexShaderId); if(!checkCompile(vertexShaderId)){ //check status & get any messages the shader compiler might have generated printf("compiling vertex shader failed :("); waitForExit(window); return -1; } //now the fragment shader GLuint fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER); std::string fragmentSource = readContentsOfFile("simple.frag"); const char* fragmentSourcePtr = fragmentSource.c_str(); const GLint fragmentSourceLength = fragmentSource.size(); glShaderSource(fragmentShaderId,1,&fragmentSourcePtr,&fragmentSourceLength); //compile it glCompileShader(fragmentShaderId); if(!checkCompile(fragmentShaderId)){ //check status & get any messages the shader compiler might have generated printf("compiling fragment shader failed :("); waitForExit(window); return -1; } //now we link the shaders together into a program GLuint shaderProgramId = glCreateProgram(); glAttachShader(shaderProgramId,vertexShaderId); glAttachShader(shaderProgramId,fragmentShaderId); //Tell OpenGL what input it should expect to the shader program, in this case one attribute with the position glBindAttribLocation(shaderProgramId,0,"in_Position"); //linking puts everything together so it's ready for use glLinkProgram(shaderProgramId); if(!checkLink(shaderProgramId)){//check status & get any messages the shader compiler might have generated printf("linking shader program failed :("); waitForExit(window); return -1; } //Now we need to make a rectangle for the GPU to draw GLuint vao; GLuint vbo; //create a vertex array object // A vertex array object holds OpenGL state related to vertex data glGenVertexArrays(1,&vao); //create a buffer object to hold some GPU data // we will use it to hold geometry data glGenBuffers(1, &vbo); glBindVertexArray(vao); //make the vertex array object active so we can modify it //bind the buffer object // GL_ARRAY_BUFFER holds per-vertex data, in this case a 3D position glBindBuffer(GL_ARRAY_BUFFER, vbo); //here's some points that make a rectangle, arranged like this: // (1)-----(2) // | / | // | / | // (3)-----(4) // We use a triangle strip so points 2 & 3 are part of both triangles float vertices[] = { -0.5,-0.5, 0.0,//x,y,z 0.5,-0.5, 0.0, -0.5, 0.5, 0.0, 0.5, 0.5, 0.0 }; //This downloads the data to the GPU into the buffer we bound to GL_ARRAY_BUFFER // GL_STATIC_DRAW is a hint to the GPU about what we're going to use the data for // STATIC means that we're going to keep it around for a while and use it multiple times // DRAW means it's data for drawing glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),vertices,GL_STATIC_DRAW); //This tells the GPU how the data is structured. // This is done for each attribute to be passed to the GPU glEnableVertexAttribArray(0); //We're specifying parameter 0, in_Position in the vertex shader glVertexAttribPointer(0, //We're specifying parameter 0, in_Position in the vertex shader 3, //Three components to the member since it's a 3D position, the vec3 type in GLSL GL_FLOAT, //Each component is a float GL_FALSE, //OpenGL can automatically normalize your data if you want 3 * sizeof(float), //This is the offset in the array between the beginning of each attribute // This makes it possible to pack multiple attributes into one buffer. // You can also bind multiple buffers each with different data 0); // This is the offset of the start of data in the buffer //Now that we're done we unbind our Vertex Array Object glBindVertexArray(0); //All our setup is done, now we can enter our normal draw loop while(!glfwWindowShouldClose(window)){ //first poll for events glfwPollEvents(); //clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //tell OpenGL to use the program we made earlier for drawing glUseProgram(shaderProgramId); //use our vertex data declared by the vertex array object for drawing glBindVertexArray(vao); //Draw! glDrawArrays(GL_TRIANGLE_STRIP, //We're using triangle strips 0, //start with the first vertex 4); //draw 4 vertices (all of the ones in our buffer in our case) //finally, update the screen with what we've drawn glfwSwapBuffers(window); } return 0; }
void work(struct serversocket* ss) { int server_sockfd = ss->sockfd; int client_sockfd; int len; int buf[BUFSIZE];//数据传输缓冲区 socklen_t sin_size = sizeof(struct sockaddr_in); struct sockaddr_in my_addr = ss->server_addr;//服务器端网络地址结构体 struct sockaddr_in remote_addr;//客户端网络地址结构体 // 创建一个epoll句柄 int epoll_fd = epoll_create(MAX_EVENTS); if(epoll_fd==-1) { perror("epoll_create failed"); writelog("创建epoll句柄失败"); exit(EXIT_FAILURE); } writelog("创建epoll句柄"); struct epoll_event ev;// epoll事件结构体 struct epoll_event events[MAX_EVENTS];// 事件监听队列 ev.events=EPOLLIN; ev.data.fd=server_sockfd; //向epoll注册server_sockfd监听事件 if(epoll_ctl(epoll_fd,EPOLL_CTL_ADD,server_sockfd,&ev)==-1) { perror("epll_ctl:server_sockfd register failed"); writelog("向epoll注册server_sockfd监听事件失败"); exit(EXIT_FAILURE); } writelog("向epoll注册server_sockfd监听事件"); int nfds;// epoll监听事件发生的个数 // 循环接受客户端请求 while(1) { // 等待事件发生 printf("服务器就绪...\n"); nfds=epoll_wait(epoll_fd,events,MAX_EVENTS,-1); if(nfds==-1) { perror("start epoll_wait failed"); writelog("start epoll_wait failed"); exit(EXIT_FAILURE); } printf("事件数量:%d\n", nfds); int i; for(i=0;i<nfds;i++) { if(events[i].data.fd == server_sockfd) { printf("客户端有新的连接请求\n"); // 等待客户端连接请求到达 int tmp_sockfd; if((tmp_sockfd=accept(server_sockfd,(struct sockaddr *)&remote_addr,&sin_size))<0) { perror("accept client_sockfd failed"); exit(EXIT_FAILURE); } printf("sockfd: %d\n服务端 accept 客户端\n", tmp_sockfd); char *ip = NULL; int port = 0; printf("判断客户端是否重复\n"); //printf("获取客户端ip和端口号\n"); if(getpeername(tmp_sockfd, (struct sockaddr*)&remote_addr, &sin_size) == 0) { ip = inet_ntoa(remote_addr.sin_addr); port = ntohs(remote_addr.sin_port); //printf("ip : %s\nport : %d\n", inet_ntoa(remote_addr.sin_addr), ntohs(remote_addr.sin_port)); } //printf("ip : %s\nport : %d\n", ip, port); if(checkLink(ip, port) == 1) { printf("连接已经存在\n"); close(tmp_sockfd); continue; } client_sockfd = tmp_sockfd; printf("保存客户端连接\n"); if(holdLink(client_sockfd, ip, port) == 0) {//添加连接到连接池 printf("保存失败\n"); continue; } // 向epoll注册client_sockfd监听事件 ev.events=EPOLLIN; ev.data.fd=client_sockfd; if(epoll_ctl(epoll_fd,EPOLL_CTL_ADD,client_sockfd,&ev)==-1) { perror("epoll_ctl:client_sockfd register failed"); exit(EXIT_FAILURE); } printf("accept client %s\n",inet_ntoa(remote_addr.sin_addr)); } // 客户端有数据发送过来 else if(events[i].events & EPOLLIN) { printf("发数据的客户端sockfd: %d\n", events[i].data.fd); client_sockfd = events[i].data.fd; buf[0] = buf[1] = INF; len = read(client_sockfd, &buf, sizeof(bao)); //len=recv(client_sockfd,buf,BUFSIZE,0); if(len<0) { perror( "receive from client failed"); epoll_ctl(epoll_fd,EPOLL_CTL_DEL, client_sockfd, &ev); exit(EXIT_FAILURE); } //客户端已经断开连接 if(len == 0) { deleteLink(client_sockfd); epoll_ctl(epoll_fd,EPOLL_CTL_DEL, client_sockfd, &ev); close(client_sockfd); printf("客户端断开连接\n"); continue; } printf("receive two numbers from client: %d %d\n",buf[0], buf[1]); int ans = buf[0] + buf[1]; //char str[] = "I have received your message."; write(client_sockfd, &ans, sizeof(ans)); //send(client_sockfd, str, sizeof(str),0); } // 服务器端发数据 else if(events[i].events & EPOLLOUT) { printf("Server send sum to %d\n", events[i].data.fd); //目前不需要该业务逻辑 } } } }