int ft_vlprintf(const char *format, va_list ap) { t_printf_special_function print_format[NB_SPECIAL_FUNCTION]; t_printf_set_function set_mode[NB_MODE_FUNCTION]; t_printf_mode mode; int length; long int tlength; init_print(print_format); init_set(set_mode); tlength = 0; while (*format) { length = print_no_format(format); tlength += length; if (!*(format += length)) break ; ft_bzero((void *)&mode, sizeof(t_printf_mode)); mode.precision = -1; if (*(format += set_format_mode(format, &mode, set_mode, ap))) format++; tlength += print_format[get_special_index(SPECIAL_CSET, \ mode.special)](mode, ap); } return (tlength); }
/** * Creates a new set and adds it to the set set. * @arg mgr The manager to add to * @arg set_name The name of the set * @arg config The configuration for the set * @arg is_hot Is the set hot. False for existing. * @arg delta Should a delta entry be added, or the primary tree updated. * This is usually 0, except during initialization when it is safe to update * the primary tree. * @return 0 on success, -1 on error */ static int add_set(hlld_setmgr *mgr, char *set_name, hlld_config *config, int is_hot, int delta) { // Create the set hlld_set_wrapper *set = calloc(1, sizeof(hlld_set_wrapper)); set->is_active = 1; set->is_hot = is_hot; set->should_delete = 0; pthread_rwlock_init(&set->rwlock, NULL); // Set the custom set if its not the same if (mgr->config != config) { set->custom = config; } // Try to create the underlying set. Only discover if it is hot. int res = init_set(config, set_name, is_hot, &set->set); if (res != 0) { free(set); return -1; } // Check if we are adding a delta value or directly updating ART tree if (delta) create_delta_update(mgr, CREATE, set); else art_insert(mgr->set_map, set_name, strlen(set_name)+1, set); return 0; }
int init() { int i, u, v; int max = 0; for (i = 0; i < MAXN; i++) { vetexs[i].next = -1; vetexs[i].valid = 0; } n_vetex = 6; begin = 0; memset(deg, 0, sizeof(deg)); memset(used, 0, sizeof(used)); memset(stack, 0, sizeof(stack)); top = 0; n_idx = 0; n_edge = 0; init_set(); scanf("%d", &max); for(i = 1; i <= max; i++) { scanf("%d %d", &u, &v); add_edge(u, v, POS, i); add_edge(v, u, NEG, i); deg[u]++; deg[v]++; setsets(u, v); begin = u; n_idx++; } return max; }
int ov3640_sensor_init(void) { dprintk("=======%s:%d\n", __FUNCTION__, __LINE__); ov3640_set_mclk(0); ov3640_reset(); init_set(ov3640_sensor_desc.client); return 0; }
void init() { // std::cout << "@Counter#init" << std::endl; for ( auto& m : memo ) m.clear(); // std::fill(std::begin(memo), std::end(memo), -1); N = in->N; std::copy(std::begin(in->A), std::begin(in->A) + in->N, std::begin(A)); std::sort(std::begin(A), std::begin(A) + N, std::greater<Int>()); init_set(); }
Datum count_distinct_append(PG_FUNCTION_ARGS) { element_set_t *eset; /* info for anyelement */ Oid element_type = get_fn_expr_argtype(fcinfo->flinfo, 1); Datum element = PG_GETARG_DATUM(1); /* memory contexts */ MemoryContext oldcontext; MemoryContext aggcontext; /* * If the new value is NULL, we simply return the current aggregate state * (it might be NULL, so check it). */ if (PG_ARGISNULL(1) && PG_ARGISNULL(0)) PG_RETURN_NULL(); else if (PG_ARGISNULL(1)) PG_RETURN_DATUM(PG_GETARG_DATUM(0)); /* from now on we know the new value is not NULL */ /* switch to the per-group hash-table memory context */ GET_AGG_CONTEXT("count_distinct_append", fcinfo, aggcontext); oldcontext = MemoryContextSwitchTo(aggcontext); /* init the hash table, if needed */ if (PG_ARGISNULL(0)) { int16 typlen; bool typbyval; char typalign; /* get type information for the second parameter (anyelement item) */ get_typlenbyvalalign(element_type, &typlen, &typbyval, &typalign); /* we can't handle varlena types yet or values passed by reference */ if ((typlen < 0) || (! typbyval)) elog(ERROR, "count_distinct handles only fixed-length types passed by value"); eset = init_set(typlen, typalign, aggcontext); } else eset = (element_set_t *)PG_GETARG_POINTER(0); /* add the value into the set */ add_element(eset, (char*)&element); MemoryContextSwitchTo(oldcontext); PG_RETURN_POINTER(eset); }
void kruskal() { qsort(paths, edge_num, sizeof(edge), cmp_edge); init_set(); int min = 0, k = 0, i; for (i = 0; i < edge_num; i++) { if (union_set(paths[i].u, paths[i].v)) { min += paths[i].w; mst[k++] = i; } if (k == n-1) break; } free_set(); }
//factor void factor(int toksig[]) { int i; int setpaso[NOTOKENS]; //conjunto de paso por valor test(tokinifact,toksig,24); //error(24): Una expresión no puede empezar con este símbolo while (tokinifact[token]==1) { //mientras el token sea un símbolo inicial de factor... if (token==ident) { i=posicion(); if (i==0) { copia_set(setpaso,toksig); setpaso[parenc]=1; //setpaso=parenc+toksig funcion(setpaso); //error(11); //error 11: Identificador no declarado }else if (buscarElemento(i) -> tipo==PROCEDIMIENTO) error(21); //error 21: Una expresión no debe contener un identificador de procedimiento obtoken(); } else if (token == entero || token == real) obtoken(); else if (token==parena) { obtoken(); copia_set(setpaso,toksig); setpaso[parenc]=1; //setpaso=parenc+toksig expresion(setpaso); if (token==parenc) obtoken(); else error(22); //error 22: Falta un paréntesis de cierre }; init_set(setpaso); //conjunto vacío setpaso[parena]=1; //setpaso=parena test(toksig,setpaso,23); //error(23): El factor anterior no puede ir seguido de este simbolo o falta un punto y coma } }
//bloque //da inicio el análisis sintáctico void bloque (int toksig[]) { int temp; int setpaso[NOTOKENS]; //conjunto de paso por valor int vacio[NOTOKENS]; //conjunto vacío init_set(vacio); do { if (token==consttok) { obtoken(); //do-while:equivale a insertar una coma do { declaracionconst(); //llamada a función que checa que la constante esté bien definida. */ //si lo está, se coloca el identificador en la TDS while (token==coma) { obtoken(); declaracionconst(); } if (token==puntoycoma) obtoken(); else error(5); //error 5: falta una coma o un punto y coma } while (token==ident); } if (token==vartok) { obtoken(); //análogo al "do" de arriba do { declaracionvar(); //llamada a función que checa que la variable esté bien declarada. */ //si lo está, se coloca el identificador en la TDS while (token==coma) { obtoken(); declaracionvar(); } if (token==puntoycoma) obtoken(); else error(5); //error 5: Falta una coma o un punto y coma } while (token==ident); } while (token==proctok) { obtoken(); if (token==ident) { poner(PROCEDIMIENTO); obtoken(); } else error(4); //error 4: Const, Var y Procedure deben ir seguidos de un identificador if (token==puntoycoma) obtoken(); else error(5); //error 5: falta una coma o un punto y coma temp=it; copia_set(setpaso,toksig); setpaso[puntoycoma]=1; //setpaso=puntoycoma+toksig bloque(setpaso); //sucesor+símbolos de cajón it=temp; if (token==puntoycoma) { obtoken(); copia_set(setpaso,tokiniinst); setpaso[ident]=setpaso[proctok]=1; //setpaso=tokiniinst+ident+proctok test(setpaso,toksig,6); //¿símbolo incorrecto después de un procedimiento? } else error(5); } copia_set(setpaso,tokiniinst); setpaso[ident]=1; //setpaso=tokiniinst+ident test(setpaso,tokinidecl,7); //se espera una instrucción } while (tokinidecl[token]==1); //salir cuando el token ya no sea de declaración copia_set(setpaso,toksig); setpaso[puntoycoma]=setpaso[endtok]=1; //setpaso=puntoycoma+end+toksig instruccion(setpaso); //aquí viene el chequeo explícito de que el token que viene a continuación //está en el conjunto de sucesores correctos (los sucesores de bloque) copia_set(setpaso,toksig); test(setpaso,vacio,8); //símbolo incorrecto detrás de las instrucciones de un bloque }
//instruccion void instruccion(int toksig[]) { int i; int setpaso[NOTOKENS]; //conjunto de paso por valor int vacio[NOTOKENS]; //conjunto vacío init_set(vacio); if (token==ident) { if (esFuncion()) { copia_set(setpaso,toksig); funcion(setpaso); } else { //ve a buscarlo a la tabla de símbolos i=posicion(); if (i==0) { error(11); //error 11: identificador no declarado } else if (buscarElemento(i) -> tipo != VARIABLE) error(12); //error 12: no están permitidas las asignaciones a constantes o a procedimientos obtoken(); if (token==asignacion) obtoken(); else error(13); //error 13: se esperaba el operador de asignación copia_set(setpaso,toksig); expresion(setpaso); } } else if (token==calltok) { obtoken(); if (token!=ident) error(14); //error 14: "CALL" debe ir seguido de un identificador else { //buscar el nombre del procedimiento en la tabla de símbolos i=posicion(); if (i==0) error(11); //error 11: Identificador no declarado else if (buscarElemento(i) -> tipo!=PROCEDIMIENTO) error(15); //error 15 : No tiene sentido llamar a una constante o a una variable obtoken(); } } else if (token==iftok) { obtoken(); copia_set(setpaso,toksig); setpaso[thentok]=setpaso[dotok]=1; //setpaso=thentok+dotok+toksig condicion(setpaso); if (token==thentok) obtoken(); else error(16); //error 16: Se esperaba un "THEN" copia_set(setpaso,toksig); instruccion(toksig); } else if (token==begintok) { obtoken(); copia_set(setpaso,toksig); setpaso[puntoycoma]=setpaso[endtok]=1; //setpaso=puntoycoma+endtok+toksig instruccion(setpaso); while (token==puntoycoma || token==calltok || token==begintok || token==iftok || token==whiletok || token == fortok) { //aquí el while 'inserta' el punto y coma para continuar compilando cuando no lo encuentre //el compilador detecta la omisión clásica del punto y coma if (token==puntoycoma) obtoken(); else error(10); //error 10: Falta un punto y coma entre instrucciones copia_set(setpaso,toksig); setpaso[puntoycoma]=setpaso[endtok]=1; //setpaso=puntoycoma+endtok+toksig instruccion(setpaso); } if (token==endtok) obtoken(); else error(17); //error 17: Se esperaba un "END" o un punto y coma } else if (token==whiletok) { obtoken(); copia_set(setpaso,toksig); setpaso[dotok]=1;//setpaso=dotok+toksig condicion(setpaso); if (token==dotok) obtoken(); else error(18); //error 18: Se esperaba un "DO" copia_set(setpaso,toksig); instruccion(setpaso); } else if (token == fortok) { obtoken(); copia_set(setpaso,toksig); setpaso[dotok]=1;//setpaso=dotok+toksig if (token == ident) { i = posicion(); if (i == 0) { // no se encontro el identificador error(11); // identificador no declarado } else if (buscarElemento(i) -> tipo==PROCEDIMIENTO) { error(21); //error 21: identificador de procedimiento } else { // era un identificador valido obtoken(); if (token == intok) { obtoken(); if (token == entero) { obtoken(); if (token == dospuntos) { obtoken(); if (token == entero) { obtoken(); if (token == dotok) { obtoken(); copia_set(setpaso,toksig); instruccion(setpaso); } else { error(18); } } else { error(38); // se esperaba un numero entero } } else { error(39); // se esperaban dos puntos } } else { error(38); // se esperaba un numero entero } } else { error(29); // se esperaba un IN despues del FOR } } } else error(28); } else if (token == booleantok) { obtoken(); declaracionboolean(); } else if (token == codigoptok) { obtoken(); declaracioninline(); } //comprobación explícita de que los tokens que viene son sucesores de instrucción copia_set(setpaso,toksig); test(setpaso,vacio,19); //error(19): Un simbolo incorrecto sigue a una instrucción }
static void DefDomain(struct net_object *netobj, struct net_object *unf_netobj) { struct place_object *place; char *great_domain, *class_name = UNCOLORED_CLASS_NAME; list curr=NULL, l=NULL; int i=1; int cardinality; ClassObjPTR c; DomainObjPTR d; markPTR m; init_list(&gListDomain); init_list(&gListMarking); for( place = netobj->places; place != NULL; place = place->next) { YACCobj_name = place->tag; /* definizione dominio */ if((great_domain = READ_DOMAIN(place)) != NULL) // se dominio colorato { LEXtoParsifyString = NewStringCat("~w ", great_domain); EraseFinalCR(LEXtoParsifyString); yyparse(); #if DEBUG_UNFOLD // TEST PLACE DOMAIN curr = NULL; printf("\n%s) ", YACCparsedDomain->place_name); while ( (curr = list_iterator(YACCparsedDomain->class_list, curr)) != NULL ){ printf("%s ", ((ClassObjPTR) DATA(curr))->name); } printf("\n"); #endif cardinality =1; curr = NULL; while ( (curr = list_iterator(YACCparsedDomain->class_list, curr)) != NULL ) cardinality *= ((ClassObjPTR) DATA(curr))->num_el; init_set(YACCparsedDomain->create_place, cardinality); append(&gListDomain, (generic_ptr) YACCparsedDomain); if(place->cmark!=NULL) { YACCobj_name = place->cmark->tag; LEXtoParsifyString = NewStringCat("~m ",place->cmark->text); EraseFinalCR(LEXtoParsifyString); yyparse(); YACCparsedMarking->place = place; // evalMarking(YACCparsedMarking, &p_MS); append(&gListMarking, (generic_ptr) YACCparsedMarking); #if DEBUG_UNFOLD printf("Marking: %s\n", PrintMarking(YACCparsedMarking)); // printMultiset(p_MS); #endif } } else { // dominio non colorato init_list(&l); if((find_key(gListClasses, (generic_ptr) class_name, CmpClassName, &curr))==ERROR) Error(CLASS_DEF_ERR, "DefDomain", NULL); else { head_insert(&l, DATA(curr)); YACCparsedDomain = NewDomain(place->tag, l, 1); init_set(YACCparsedDomain->create_place, 1); append(&gListDomain, (generic_ptr) YACCparsedDomain); } #if DEBUG_UNFOLD // TEST PLACE DOMAIN curr = NULL; printf("\n%s) ", YACCparsedDomain->place_name); while ( (curr = list_iterator(YACCparsedDomain->class_list, curr)) != NULL ){ printf("%s ", ((ClassObjPTR) DATA(curr))->name); } printf("\n"); #endif if(place->mpar!=NULL){ YACCparsedMarking = NewMarking(place->mpar->tag, (generic_ptr) place->mpar); YACCparsedMarking->type = 1; } else{ YACCobj_name = ""; LEXtoParsifyString = EmptyString(); sprintf(LEXtoParsifyString, "~m <%d S>",place->m0); yyparse(); YACCparsedMarking->type = 0; } YACCparsedMarking->place = place; // evalMarking(YACCparsedMarking, &p_MS); head_insert(&gListMarking, (generic_ptr) YACCparsedMarking); } } }
int main(int argc, char *argv[]) { //usage error check if(argc < 2) { printf("usage : ./server <port number>\n"); exit(1); } //make port number int server_port = atoi(argv[1]); //socket variables int chat_sd; int game_sd; int listen_sd; struct sockaddr_in addr; struct timeval timeout; fd_set select_result; int on=1; //pthread variables pthread_t thr; //etc variables int i, j, buf_len, rc; int x, y, winner; char buffer[4096]; char smbuf[5]; //server init listen_sd = socket(AF_INET, SOCK_STREAM, 0); if(listen_sd<0){printf("socket error\n"); exit(2);} rc = setsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); if(rc<0){printf("setsockopt error\n"); exit(2);} memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_port = htons(server_port); rc = bind(listen_sd, (struct sockaddr *)&addr, sizeof(addr)); if(rc < 0){printf("bind error\n"); exit(3);} rc = listen(listen_sd, 32); if(rc < 0){printf("listen error\n"); exit(4);} init_set(); add_to_set(fileno(stdin)); add_to_set(listen_sd); //timeval init timeout.tv_sec = 3*60; timeout.tv_usec = 0; //Waiting client printf("Waiting client\n"); chat_sd = accept(listen_sd, (struct sockaddr *)NULL, NULL); add_to_set(chat_sd); printf("accept chat_sd\n"); game_sd = accept(listen_sd, (struct sockaddr *)NULL, NULL); add_to_set(game_sd); printf("accept game_sd\n"); //game init initlog(); init_board(); while(1) { //your turn addlog(" < YOUR TURN > ", 3, 1); //make thread to check time pipe(pipefd); add_to_set(pipefd[0]); pthread_create(&thr, NULL, thr_time, NULL); while(1) { printboard(1); printlog(); memcpy(&select_result, &master_set, sizeof(master_set)); rc = select(max_sd+1,&select_result, NULL,NULL, &timeout); if(rc<0) exit(5); if(rc==0) exit(6); //timecheck error if(FD_ISSET(game_sd, &select_result)) w_exit(-1); else if(FD_ISSET(fileno(stdin), &select_result)) //stdin { fgets(buffer,4096,stdin); if(buffer[0] == 58) //special command { if(buffer[2]==' ' && buffer[4]=='\n') { if(buffer[1]<78 && buffer[1]>64) buffer[1] = buffer[1] + 32; if(buffer[3]<78 && buffer[3]>64) buffer[3] = buffer[3] + 32; if(buffer[1]<110 && buffer[1]>96 && buffer[3]<110 && buffer[3]>96) { y = buffer[1] - 96; x = buffer[3] - 96; if(is_33(y, x)) addlog("3x3 not allowed", 3, 1); else if(board[y][x]!=0) addlog("try again", 3,1); else { pthread_cancel(thr); board[y][x] = 1; smbuf[0] = y; smbuf[1] = x; smbuf[2] = '\0'; send(game_sd, smbuf, 2, 0); if(winner = finish_board()) w_exit(winner); break; } } } else if(buffer[1]=='q' && buffer[2]=='\n') { printf("\rdissconnected\n"); exit(0); } } else { buffer[strlen(buffer)-1] ='\0'; send(chat_sd, buffer,strlen(buffer),0); addlog(buffer, 1, 1); } } else if(FD_ISSET(chat_sd, &select_result)) { rc = recv(chat_sd, buffer, 4096, 0); if(rc<0) exit(7); //recv error if(rc == 0) w_exit(-1); //disconnected buffer[rc]='\0'; addlog(buffer, 2, 1); } else if(FD_ISSET(pipefd[0], &select_result)) { send(game_sd, "t",1,0); break; } } remove_from_set(pipefd[0]); //opp turn while(1) { printboard(2); printlog(); memcpy(&select_result, &master_set, sizeof(master_set)); rc = select(max_sd+1, &select_result, NULL,NULL,&timeout); if(rc<0) exit(5); if(rc==0) exit(6); //timeout; if(FD_ISSET(fileno(stdin), &select_result)) { fgets(buffer,4096,stdin); if(buffer[0] != ':') { buffer[strlen(buffer)-1]='\0'; send(chat_sd, buffer, strlen(buffer),0); addlog(buffer,1, 2); } else if(buffer[1] == 'q' && buffer[2] == '\n') { printf("\rdisconnected\n"); exit(0); } } else if(FD_ISSET(game_sd, &select_result)) { rc = recv(game_sd, smbuf,2 ,0); if(rc<0) exit(7); //recv error if(rc==0) w_exit(-1); //disconnected if(smbuf[0] == 't') { addlog("Opponent timeout", 3, 2); break; } else { y = smbuf[0]; x = smbuf[1]; board[y][x] = 2; if(winner = finish_board()) w_exit(winner); break; } } else if(FD_ISSET(chat_sd, &select_result)) { rc = recv(chat_sd, buffer, 4096,0); if(rc<0) exit(7); if(rc == 0) w_exit(-1); buffer[rc]= '\0'; addlog(buffer, 2, 2); } } } exit(0); }
Datum count_distinct_elements_append(PG_FUNCTION_ARGS) { int i; element_set_t *eset = NULL; /* info for anyarray */ Oid input_type; Oid element_type; /* array data */ ArrayType *input; int ndims; int *dims; int nitems; bits8 *null_bitmap; char *arr_ptr; Datum element; /* memory contexts */ MemoryContext oldcontext; MemoryContext aggcontext; /* * If the new value is NULL, we simply return the current aggregate state * (it might be NULL, so check it). In this case we don't really care about * the types etc. * * We may still get NULL elements in the array, but to check that we would * have to walk the array, which does not qualify as cheap check. Also we * assume that there's at least one non-NULL element, and we'll walk the * array just once. It's possible we'll get empty set this way. */ if (PG_ARGISNULL(1) && PG_ARGISNULL(0)) PG_RETURN_NULL(); else if (PG_ARGISNULL(1)) PG_RETURN_DATUM(PG_GETARG_DATUM(0)); /* from now on we know the new value is not NULL */ /* get the type of array elements */ input_type = get_fn_expr_argtype(fcinfo->flinfo, 1); element_type = get_element_type(input_type); /* * parse the array contents (we know we got non-NULL value) */ input = PG_GETARG_ARRAYTYPE_P(1); ndims = ARR_NDIM(input); dims = ARR_DIMS(input); nitems = ArrayGetNItems(ndims, dims); null_bitmap = ARR_NULLBITMAP(input); arr_ptr = ARR_DATA_PTR(input); /* make sure we're running as part of aggregate function */ GET_AGG_CONTEXT("count_distinct_elements_append", fcinfo, aggcontext); oldcontext = MemoryContextSwitchTo(aggcontext); /* add all array elements to the set */ for (i = 0; i < nitems; i++) { /* ignore nulls */ if (null_bitmap && !(null_bitmap[i / 8] & (1 << (i % 8)))) continue; /* init the hash table, if needed */ if (eset == NULL) { if (PG_ARGISNULL(0)) { int16 typlen; bool typbyval; char typalign; /* get type information for the second parameter (anyelement item) */ get_typlenbyvalalign(element_type, &typlen, &typbyval, &typalign); /* we can't handle varlena types yet or values passed by reference */ if ((typlen < 0) || (! typbyval)) elog(ERROR, "count_distinct_elements handles only arrays of fixed-length types passed by value"); eset = init_set(typlen, typalign, aggcontext); } else eset = (element_set_t *)PG_GETARG_POINTER(0); } element = fetch_att(arr_ptr, true, eset->item_size); add_element(eset, (char*)&element); /* advance array pointer */ arr_ptr = att_addlength_pointer(arr_ptr, eset->item_size, arr_ptr); arr_ptr = (char *) att_align_nominal(arr_ptr, eset->typalign); } MemoryContextSwitchTo(oldcontext); if (eset == NULL) PG_RETURN_NULL(); else PG_RETURN_POINTER(eset); }
int main(int argc, char *argv[]) { //usage error check if(argc < 2) { printf("usage : ./server <port number>\n"); exit(1); } //make port number int server_port = atoi(argv[1]); //socket variables int chat_sd; int game_sd; int listen_sd; struct sockaddr_in addr; struct timeval timeout; fd_set select_result; int on=1; //pthread variables pthread_t thr; //etc variables int i, j, buf_len, rc; int x, y, winner; char buffer[4096]; char smbuf[5]; //server init listen_sd = socket(AF_INET, SOCK_STREAM, 0); if(listen_sd<0){printf("socket error\n"); exit(2);} rc = setsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); if(rc<0){printf("setsockopt error\n"); exit(2);} memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_port = htons(server_port); rc = bind(listen_sd, (struct sockaddr *)&addr, sizeof(addr)); if(rc < 0){printf("bind error\n"); exit(3);} rc = listen(listen_sd, 32); if(rc < 0){printf("listen error\n"); exit(4);} init_set(); add_to_set(listen_sd); //timeval init timeout.tv_sec = 3*60; timeout.tv_usec = 0; //Waiting client printf("Waiting client\n"); chat_sd = accept(listen_sd, (struct sockaddr *)NULL, NULL); add_to_set(chat_sd); printf("accept chat_sd\n"); game_sd = accept(listen_sd, (struct sockaddr *)NULL, NULL); add_to_set(game_sd); printf("accept game_sd\n"); //ncurses init window=initscr(); keypad(stdscr,TRUE); mousemask(BUTTON1_RELEASED, NULL); //game init initlog(); init_board(); while(1) { //your turn addlog(" < YOUR TURN > ", 3, 1); //make thread to check mouse pipe(pipefd); add_to_set(pipefd[0]); pthread_create(&thr, NULL, thr_mouse, NULL); while(1) { printall(1); memcpy(&select_result, &master_set, sizeof(master_set)); rc = select(max_sd+1,&select_result, NULL,NULL, &timeout); if(rc<0) s_exit(5); if(rc==0) s_exit(6); //timecheck error if(FD_ISSET(game_sd, &select_result)) w_exit(-1); else if(FD_ISSET(pipefd[0],&select_result)) { read(pipefd[0],smbuf,2); pthread_cancel(thr); y=smbuf[0]; x=smbuf[1]; board[y][x] = 1; send(game_sd,smbuf,2,0); if(winner = finish_board()) w_exit(winner); break; } else if(FD_ISSET(chat_sd, &select_result)) { rc = recv(chat_sd, buffer, 4096, 0); if(rc<0) s_exit(7); //recv error if(rc == 0) w_exit(-1); //disconnected buffer[rc]='\0'; addlog(buffer, 2, 1); } } //opp turn while(1) { printall(2); memcpy(&select_result, &master_set, sizeof(master_set)); rc = select(max_sd+1, &select_result, NULL,NULL,&timeout); if(rc<0) s_exit(5); if(rc==0) s_exit(6); //timeout; if(FD_ISSET(game_sd, &select_result)) { rc = recv(game_sd, smbuf,2 ,0); if(rc<0) s_exit(7); //recv error if(rc==0) w_exit(-1); //disconnected if(smbuf[0] == 't') { addlog("Opponent timeout", 3, 2); break; } else { y = smbuf[0]; x = smbuf[1]; board[y][x] = 2; if(winner = finish_board()) w_exit(winner); break; } } else if(FD_ISSET(chat_sd, &select_result)) { rc = recv(chat_sd, buffer, 4096,0); if(rc<0) s_exit(7); if(rc == 0) w_exit(-1); buffer[rc]= '\0'; addlog(buffer, 2, 2); } } } s_exit(0); }
int main(int argc, char **argv) { int i, j; unsigned *current_permutation, *tmp_permutation; pid_t signal_helper = -1; drm_fd = drm_open_any(); devid = intel_get_drm_devid(drm_fd); parse_options(argc, argv); /* start our little helper early before too may allocations occur */ signal(SIGUSR1, SIG_IGN); if (options.use_signal_helper) signal_helper = fork_signal_helper(); init(); check_render_copyfunc(); tile_permutation = malloc(num_total_tiles*sizeof(uint32_t)); current_permutation = malloc(num_total_tiles*sizeof(uint32_t)); tmp_permutation = malloc(num_total_tiles*sizeof(uint32_t)); assert(tile_permutation); assert(current_permutation); assert(tmp_permutation); fan_out(); for (i = 0; i < options.total_rounds; i++) { printf("round %i\n", i); if (i % 64 == 63) { fan_in_and_check(); printf("everything correct after %i rounds\n", i + 1); } target_set = (current_set + 1) & 1; init_set(target_set); for (j = 0; j < num_total_tiles; j++) current_permutation[j] = j; permute_array(current_permutation, num_total_tiles, exchange_uint); copy_tiles(current_permutation); memcpy(tmp_permutation, tile_permutation, sizeof(unsigned)*num_total_tiles); /* accumulate the permutations */ for (j = 0; j < num_total_tiles; j++) tile_permutation[j] = current_permutation[tmp_permutation[j]]; current_set = target_set; } fan_in_and_check(); fprintf(stderr, "num failed tiles %u, max incoherent bytes %lu\n", stats.num_failed, stats.max_failed_reads*sizeof(uint32_t)); intel_batchbuffer_free(batch); drm_intel_bufmgr_destroy(bufmgr); close(drm_fd); if (signal_helper != -1) kill(signal_helper, SIGQUIT); return 0; }
void load_builtins() { duplicate_rule( "Always" , bind_builtin( "ALWAYS" , builtin_flags, T_FLAG_TOUCHED, 0 ) ); duplicate_rule( "Depends" , bind_builtin( "DEPENDS" , builtin_depends, 0, 0 ) ); duplicate_rule( "echo" , duplicate_rule( "Echo" , bind_builtin( "ECHO" , builtin_echo, 0, 0 ) ) ); { char * args[] = { "message", "*", ":", "result-value", "?", 0 }; duplicate_rule( "exit" , duplicate_rule( "Exit" , bind_builtin( "EXIT" , builtin_exit, 0, args ) ) ); } { char * args[] = { "directories", "*", ":", "patterns", "*", ":", "case-insensitive", "?", 0 }; duplicate_rule( "Glob" , bind_builtin( "GLOB" , builtin_glob, 0, args ) ); } { char * args[] = { "patterns", "*", 0 }; bind_builtin( "GLOB-RECURSIVELY" , builtin_glob_recursive, 0, args ); } duplicate_rule( "Includes" , bind_builtin( "INCLUDES" , builtin_depends, 1, 0 ) ); { char * args[] = { "targets", "*", ":", "targets-to-rebuild", "*", 0 }; bind_builtin( "REBUILDS" , builtin_rebuilds, 0, args ); } duplicate_rule( "Leaves" , bind_builtin( "LEAVES" , builtin_flags, T_FLAG_LEAVES, 0 ) ); duplicate_rule( "Match" , bind_builtin( "MATCH" , builtin_match, 0, 0 ) ); duplicate_rule( "NoCare" , bind_builtin( "NOCARE" , builtin_flags, T_FLAG_NOCARE, 0 ) ); duplicate_rule( "NOTIME" , duplicate_rule( "NotFile" , bind_builtin( "NOTFILE" , builtin_flags, T_FLAG_NOTFILE, 0 ) ) ); duplicate_rule( "NoUpdate" , bind_builtin( "NOUPDATE" , builtin_flags, T_FLAG_NOUPDATE, 0 ) ); duplicate_rule( "Temporary" , bind_builtin( "TEMPORARY" , builtin_flags, T_FLAG_TEMP, 0 ) ); { char * args[] = { "targets", "*", 0 }; bind_builtin( "ISFILE", builtin_flags, T_FLAG_ISFILE, 0 ); } duplicate_rule( "HdrMacro" , bind_builtin( "HDRMACRO" , builtin_hdrmacro, 0, 0 ) ); /* FAIL_EXPECTED is used to indicate that the result of a target build */ /* action should be inverted (ok <=> fail) this can be useful when */ /* performing test runs from Jamfiles.. */ bind_builtin( "FAIL_EXPECTED" , builtin_flags, T_FLAG_FAIL_EXPECTED, 0 ); bind_builtin( "RMOLD" , builtin_flags, T_FLAG_RMOLD, 0 ); { char * args[] = { "targets", "*", 0 }; bind_builtin( "UPDATE", builtin_update, 0, args ); } { char * args[] = { "string", "pattern", "replacements", "+", 0 }; duplicate_rule( "subst" , bind_builtin( "SUBST" , builtin_subst, 0, args ) ); } { char * args[] = { "module", "?", 0 }; bind_builtin( "RULENAMES" , builtin_rulenames, 0, args ); } { char * args[] = { "module", "?", 0 }; bind_builtin( "VARNAMES" , builtin_varnames, 0, args ); } { char * args[] = { "module", "?", 0 }; bind_builtin( "DELETE_MODULE" , builtin_delete_module, 0, args ); } { char * args[] = { "source_module", "?", ":", "source_rules", "*", ":", "target_module", "?", ":", "target_rules", "*", ":", "localize", "?", 0 }; bind_builtin( "IMPORT" , builtin_import, 0, args ); } { char * args[] = { "module", "?", ":", "rules", "*", 0 }; bind_builtin( "EXPORT" , builtin_export, 0, args ); } { char * args[] = { "levels", "?", 0 }; bind_builtin( "CALLER_MODULE" , builtin_caller_module, 0, args ); } { char * args[] = { "levels", "?", 0 }; bind_builtin( "BACKTRACE" , builtin_backtrace, 0, args ); } { char * args[] = { 0 }; bind_builtin( "PWD" , builtin_pwd, 0, args ); } { char * args[] = { "target", "*", ":", "path", "*", 0 }; bind_builtin( "SEARCH_FOR_TARGET", builtin_search_for_target, 0, args ); } { char * args[] = { "modules_to_import", "+", ":", "target_module", "?", 0 }; bind_builtin( "IMPORT_MODULE", builtin_import_module, 0, args ); } { char * args[] = { "module", "?", 0 }; bind_builtin( "IMPORTED_MODULES", builtin_imported_modules, 0, args ); } { char * args[] = { "instance_module", ":", "class_module", 0 }; bind_builtin( "INSTANCE", builtin_instance, 0, args ); } { char * args[] = { "sequence", "*", 0 }; bind_builtin( "SORT", builtin_sort, 0, args ); } { char * args[] = { "path_parts", "*", 0 }; bind_builtin( "NORMALIZE_PATH", builtin_normalize_path, 0, args ); } { char * args[] = { "args", "*", 0 }; bind_builtin( "CALC", builtin_calc, 0, args ); } { char * args[] = { "module", ":", "rule", 0 }; bind_builtin( "NATIVE_RULE", builtin_native_rule, 0, args ); } { char * args[] = { "module", ":", "rule", ":", "version", 0 }; bind_builtin( "HAS_NATIVE_RULE", builtin_has_native_rule, 0, args ); } { char * args[] = { "module", "*", 0 }; bind_builtin( "USER_MODULE", builtin_user_module, 0, args ); } { char * args[] = { 0 }; bind_builtin( "NEAREST_USER_LOCATION", builtin_nearest_user_location, 0, args ); } { char * args[] = { "file", 0 }; bind_builtin( "CHECK_IF_FILE", builtin_check_if_file, 0, args ); } #ifdef HAVE_PYTHON { char * args[] = { "python-module", ":", "function", ":", "jam-module", ":", "rule-name", 0 }; bind_builtin( "PYTHON_IMPORT_RULE", builtin_python_import_rule, 0, args ); } #endif # if defined( OS_NT ) || defined( OS_CYGWIN ) { char * args[] = { "key_path", ":", "data", "?", 0 }; bind_builtin( "W32_GETREG", builtin_system_registry, 0, args ); } { char * args[] = { "key_path", ":", "result-type", 0 }; bind_builtin( "W32_GETREGNAMES", builtin_system_registry_names, 0, args ); } # endif { char * args[] = { "command", ":", "*", 0 }; bind_builtin( "SHELL", builtin_shell, 0, args ); bind_builtin( "COMMAND", builtin_shell, 0, args ); } /* Initialize builtin modules */ init_set(); init_path(); init_regex(); init_property_set(); init_sequence(); init_order(); }
/* * APOLLO_init * * initialises window to occupy current window */ APOLLO_init() { pad_$window_desc_t window; int size, prefx, prefy, prefxs, prefys, x, y, w, h; short i; pad_$set_scale(stream_$stdout, 1, 1, status); pad_$inq_windows(stream_$stdout, window_info, 10, n_windows, status); w = window_info[0].width; h = window_info[0].height; x = window_info[0].left; y = window_info[0].top; getprefposandsize(&prefx, &prefy, &prefxs, &prefys); if (prefx > -1) { x = prefx; y = prefy; } if (prefxs > -1) { w = prefxs; h = prefys; } size = MIN(w, h); vdevice.sizeX = vdevice.sizeY = size - 1; vdevice.sizeSx = w - 1; vdevice.sizeSy = h - 1; init_bitmap_size.x_size = w; init_bitmap_size.y_size = h; source.window_base.x_coord = source.window_base.y_coord = 0; source.window_size.x_size = init_bitmap_size.x_size; source.window_size.y_size = init_bitmap_size.y_size; dest_pos.x_coord = dest_pos.y_coord = 0; /* * Inquire about the actual display .... */ gpr_$inq_disp_characteristics(mode, stream_$stdout, (short)60, disp, disp_len, status); vdevice.depth = disp.n_planes; hi_plane_id = disp.n_planes - 1; if (prefx == -1 && prefxs == -1) { stream_id = stream_$stdout; } else { window.top = y; window.left = x; window.width = w; window.height = h; pad_$create_window("", 0, pad_$transcript, 1, window, stream_id, status ); pad_$set_auto_close(stream_id, 1, true, status); } gpr_$init(mode, stream_id, init_bitmap_size, hi_plane_id, front_bitmap, status); current_bitmap = front_bitmap; gpr_$set_auto_refresh(true, status); gpr_$set_cursor_active(false,status); /* Set up all the character stuff */ first_time = 1; /* create a key set for the event interupts */ lib_$init_set(keys, (short)256); lib_$init_set(mouse_keys, (short)6); lib_$add_to_set(mouse_keys, (short)6, KBD_$M1D); lib_$add_to_set(mouse_keys, (short)6, KBD_$M2D); lib_$add_to_set(mouse_keys, (short)6, KBD_$M3D); lib_$add_to_set(mouse_keys, (short)6, KBD_$M1U); lib_$add_to_set(mouse_keys, (short)6, KBD_$M2U); lib_$add_to_set(mouse_keys, (short)6, KBD_$M3U); for (i = 0; i < 128; i++) lib_$add_to_set(keys, (short)256, (short)i); gpr_$enable_input(gpr_$keystroke, keys, status); gpr_$enable_input(gpr_$buttons, keys, status); gpr_$enable_input(gpr_$locator, keys, status); /* set default color (colour) */ if (disp.n_planes > 1) { gpr_$inq_color_map(0L, (short)MAXCOLORS, old_color_value, status); gpr_$inq_color_map(0L, (short)MAXCOLORS, color_value, status); color_value[0] = COLOR_ENTRY(0,0,0); /* color--black */ color_value[1] = COLOR_ENTRY(255,0,0); /* color--red */ color_value[2] = COLOR_ENTRY(0,255,0); /* color--green */ color_value[3] = COLOR_ENTRY(255,255,0); /* color--yellow */ color_value[4] = COLOR_ENTRY(0,0,255); /* color--blue */ color_value[5] = COLOR_ENTRY(255,0,255); /* color--magenta */ color_value[6] = COLOR_ENTRY(0,255,255); /* color--cyan */ color_value[7] = COLOR_ENTRY(255,255,255); /* color--white */ /* modify color table */ gpr_$acquire_display(status); gpr_$set_color_map((long)0, (short)MAXCOLORS, color_value, status); gpr_$release_display(status); } back_used = 0; return(1); }