void WRITE(pin_t pin, bool s) { bool old_state = state[pin]; if (direction[pin] == out) { state[pin] = s; } if (s && !old_state) /* rising edge */ { switch (pin) { case X_STEP_PIN: x += state[X_DIR_PIN] ? 1 : -1; print_pos(); break; case Y_STEP_PIN: y += state[Y_DIR_PIN] ? 1 : -1; print_pos(); break; case Z_STEP_PIN: z += state[Z_DIR_PIN] ? 1 : -1; print_pos(); break; case E_STEP_PIN: e += state[E_DIR_PIN] ? 1 : -1; print_pos(); break; default: break; } } }
//每个listen_to_neighbor线程持续接收来自一个邻居的报文. 它将接收到的报文转发给SIP进程. //所有的listen_to_neighbor线程都是在到邻居的TCP连接全部建立之后启动的. void* listen_to_neighbor(void* arg) { int index = *(int *)arg; // printf("MSG: listen to neighbor node=%d\n", nt[index].nodeID); sip_pkt_t tmp; if (nt[index].conn == -1) { print_pos(); printf("ERROR: connect not set for node %d\n", nt[index].nodeID); pthread_exit(NULL); } while (1) { memset(&tmp, 0, sizeof(sip_pkt_t)); // recv a pkt from son // print_pos(); // printf("MSG: prepare to recvpkt from socket=%d\n", nt[index].conn); int result; result = recvpkt(&tmp, nt[index].conn); if (result == -1){ print_pos(); printf("ERROR: recvpkt from neighbor node=%d socket=%d failed\n", nt[index].nodeID, nt[index].conn); sleep(1); } // else printf("MSG: recvpkt sip_pkt_t ok, send to sip...\n"); // forward the pkt to sip result = forwardpktToSIP(&tmp, sip_conn); if (result == -1){ print_pos(); printf("ERROR: forward pkt to sip failed\n"); } // else printf("MSG: send to sip ok\n"); } pthread_exit(NULL); }
void print_pos (struct arvore * tree)//imprime em pos-ordem { if (tree==NULL) return; print_pos(tree->esq); print_pos(tree->dir); printf(" %d ",tree->chave); }
/* * mod_time_show * 参数:无 * 功能:显示时间 * 返回值:无 */ void mod_time_show() { char date_info[50] = "Date: "; int date_pos = 6; SetTimeInfo(cmos_info.DateCentury,2); // 世纪 SetTimeInfo(cmos_info.Year,2); // 年 date_info[date_pos++] = '-'; SetTimeInfo(cmos_info.Month,2); // 月 date_info[date_pos++] = '-'; SetTimeInfo(cmos_info.DayOfMonth,2); // 日 memcpy((void*)&date_info[date_pos],(void*)&day_of_week_table[cmos_info.DayOfWeek][0],13); // 星期 date_pos += 13; SetTimeInfo(cmos_info.Hours,2); // 时 date_info[date_pos++] = ':'; SetTimeInfo(cmos_info.Minutes,2); // 分 date_info[date_pos++] = ':'; SetTimeInfo(cmos_info.Seconds,2); // 秒 date_info[date_pos++] = '\n'; print_pos((char*)&date_info,24*160 + 86); }
static int print(char *str, int nbr, int size, int neg) { if (neg == 1) return (print_neg(str, nbr, size, neg)); else return (print_pos(str, nbr, size, neg)); }
int main(int argc, char **argv) { while ( !read_bits_psk() ) { // // read_bit_PSK: /* synch: ...,du,ud,du oder ...,ud,du,ud bit 0: ud,du oder du,ud bit 1: du,du oder ud,ud (phase shift) Header _uuddu udududduududduud udduudududududud duududduudduuddu (oder:) _dduud dududuudduduuddu duuddudududududu udduduudduudduud (invers) 0 0 0 1 1 0 0 1 0 0 1 0 0 1 1 1 1 1 0 0 1 0 0 0 0 0 */ // header_found // bits2byte // framebytes // if (option_raw) print_frame(); else print_pos(); } return 0; }
void unterminated_string(int s_lineno, char *s_line, char *s_cptr) { fprintf(stderr, "File \"%s\", line %d: unterminated string\n", virtual_input_file_name, s_lineno); print_pos(s_line, s_cptr); done(1); }
void illegal_character(char *c_cptr) { fprintf(stderr, "File \"%s\", line %d: illegal character\n", virtual_input_file_name, lineno); print_pos(line, c_cptr); done(1); }
void over_unionized(char *u_cptr) { fprintf(stderr, "File \"%s\", line %d: too many %%union declarations\n", virtual_input_file_name, lineno); print_pos(line, u_cptr); done(1); }
void illegal_tag(int t_lineno, char *t_line, char *t_cptr) { fprintf(stderr, "File \"%s\", line %d: illegal tag\n", virtual_input_file_name, t_lineno); print_pos(t_line, t_cptr); done(1); }
void unterminated_text(int t_lineno, char *t_line, char *t_cptr) { fprintf(stderr, "File \"%s\", line %d: unmatched %%{\n", virtual_input_file_name, t_lineno); print_pos(t_line, t_cptr); done(1); }
void unterminated_union(int u_lineno, char *u_line, char *u_cptr) { fprintf(stderr, "File \"%s\", line %d: unterminated %%union declaration\n", virtual_input_file_name, u_lineno); print_pos(u_line, u_cptr); done(1); }
void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) { fprintf(stderr, "File \"%s\", line %d: unmatched /*\n", virtual_input_file_name, c_lineno); print_pos(c_line, c_cptr); done(1); }
void syntax_error(int st_lineno, char *st_line, char *st_cptr) { fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n", myname, st_lineno, input_file_name); print_pos(st_line, st_cptr); done(1); }
// 接收来自STCP客户端的数据 // // 这个函数接收来自STCP客户端的数据. 你不需要在本实验中实现它. // int stcp_server_recv(int sockfd, void* buf, unsigned int length) { if (tcb[sockfd]->state == CONNECTED || tcb[sockfd]->state == CLOSEWAIT){ while (tcb[sockfd]->usedBufLen < length){ if (tcb[sockfd]->state == CLOSED) break; sleep(RECVBUF_POLLING_INTERVAL); } if (tcb[sockfd]->state != CLOSED){ pthread_mutex_lock(tcb[sockfd]->bufMutex); memcpy(buf, tcb[sockfd]->recvBuf, length); int i = length; for (; i < tcb[sockfd]->usedBufLen; i ++) tcb[sockfd]->recvBuf[i-length] = tcb[sockfd]->recvBuf[i]; tcb[sockfd]->usedBufLen -= length; pthread_mutex_unlock(tcb[sockfd]->bufMutex); return 1; //int z = 0; //for (; z < length; z ++) printf("recv %d: %c", z, ((char *)buf)[z]); //printf("\n"); } else { print_pos(); printf("RECV ERROR: get enough data failed\n"); return -1; } } else return -1; }
void unterminated_text(int t_lineno, char *t_line, char *t_cptr) { fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n", myname, t_lineno, input_file_name); print_pos(t_line, t_cptr); done(1); }
void unterminated_string(int s_lineno, char *s_line, char *s_cptr) { fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n", myname, s_lineno, input_file_name); print_pos(s_line, s_cptr); done(1); }
void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) { fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n", myname, c_lineno, input_file_name); print_pos(c_line, c_cptr); done(1); }
void syntax_error(int st_lineno, char *st_line, char *st_cptr) { fprintf(stderr, "File \"%s\", line %d: syntax error\n", virtual_input_file_name, st_lineno); print_pos(st_line, st_cptr); done(1); }
void WRITE(pin_t pin, bool s) { bool old_state = state[pin]; uint64_t nseconds = sim_runtime_ns(); sim_assert(pin < PIN_NB, "WRITE: Pin number out of range"); if (direction[pin] == out) { state[pin] = s; } if (old_state != s) { record_pin(TRACE_PINS + pin, s, nseconds); #ifdef TRACE_ALL_PINS fgreen(); for (int i = 0; i < PIN_NB; i++) { if (state[i]) bred(); else bblack(); fputc('A' + i, stdout); } fbreset(); printf("\n"); #else bred(); if (s) sim_tick('A' + pin); else sim_tick('a' + pin); fbreset(); #endif } if (s && !old_state) { /* rising edge */ int axis = AXIS_NONE; int dir; switch (pin) { case X_STEP_PIN: dir = state[X_DIR_PIN] ? 1 : -1; axis = X_AXIS; break; case Y_STEP_PIN: dir = state[Y_DIR_PIN] ? 1 : -1; axis = Y_AXIS; break; case Z_STEP_PIN: dir = state[Z_DIR_PIN] ? 1 : -1; axis = Z_AXIS; break; case E_STEP_PIN: dir = state[E_DIR_PIN] ? 1 : -1; axis = E_AXIS; break; default: break; } if ( axis != AXIS_NONE ) { pos[axis] += dir; record_pin(TRACE_POS + axis, pos[axis], nseconds); print_pos(); } } }
// son_recvpkt()函数由SIP进程调用, 其作用是接收来自SON进程的报文. // 参数son_conn是SIP进程和SON进程之间TCP连接的套接字描述符. // 报文通过SIP进程和SON进程之间的TCP连接发送, 使用分隔符!&和!#. // 为了接收报文, 这个函数使用一个简单的有限状态机FSM // PKTSTART1 -- 起点 // PKTSTART2 -- 接收到'!', 期待'&' // PKTRECV -- 接收到'&', 开始接收数据 // PKTSTOP1 -- 接收到'!', 期待'#'以结束数据的接收 // 如果成功接收报文, 返回1, 否则返回-1. int son_recvpkt(sip_pkt_t* pkt, int son_conn) { int r = recv_state_machine(pkt, sizeof(sip_pkt_t), son_conn); if (r < 0) return -1; print_pos(); printf("length = %d, \'%s\'\n", pkt -> header.length, pkt -> data); return 1; }
__dead void unterminated_string(const struct ainfo *a) { fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n", myname, a->a_lineno, input_file_name); print_pos(a->a_line, a->a_cptr); done(1); }
int getConnByNode(int id){ int ct = topology_getNbrNum(); int i; for (i = 0; i < ct; i++) if (nt[i].nodeID == id) return nt[i].conn; print_pos(); printf("ERROR: no such node, return conn = -1\n"); return -1; }
// 这个线程打开TCP端口CONNECTION_PORT, 等待节点ID比自己大的所有邻居的进入连接, // 在所有进入连接都建立后, 这个线程终止. in_addr_t getIPByNode(int id){ int ct = topology_getNbrNum(); int i; for (i = 0; i < ct; i ++) if (nt[i].nodeID == id) return nt[i].nodeIP; print_pos(); printf("ERROR: no such node, return ip = 0\n"); return 0; }
/*--------------------------------------------------------------------- * get_lcrs - Execute loop to get lcrs from outbound server. *---------------------------------------------------------------------*/ static void get_lcrs(myctx_t *ctx) { sword err = OCI_SUCCESS; ub4 startcnt = 0; void *lcr; ub1 lcrtype; oraub8 flag; ub1 flwm[OCI_LCR_MAX_POSITION_LEN]; ub2 flwm_len = 0; ub1 proclwm[OCI_LCR_MAX_POSITION_LEN]; ub2 proclwm_len = 0; sb4 rtncode = 0; oci_t *ocip = ctx->outbound_ocip; printf ("\n>>> get_lcrs -- Start\n"); ctx->lcrcnt = 0; while (err == OCI_SUCCESS) { startcnt = ctx->lcrcnt; /* if unsupported LCRs are returned, we need to ignore them and * continue */ while ((err = OCIXStreamOutLCRReceive(ocip->svcp, ocip->errp, &lcr, &lcrtype, &flag, flwm, &flwm_len, OCI_DEFAULT)) == OCI_STILL_EXECUTING) { /* print ID Key LCRs */ process_IDKeyLCR(ctx, lcr, lcrtype, flag); /* If LCR has chunked columns (i.e, has LOB/Long/XMLType columns) */ if (flag & OCI_XSTREAM_MORE_ROW_DATA) { /* Get all the chunks belonging to the current LCR. */ get_chunks(ctx); } } /* print lwm */ if (flwm_len > 0) { time_t tm; time(&tm); printf ("\n=== Current time = %s", ctime(&tm)); print_pos(ocip, flwm, flwm_len, (char *)"Outbound lwm"); } } if (err) { ocierror(ocip, (char *)"get_lcrs() encounters error", FALSE); } printf (">>> get_lcrs [DONE]\n\n"); }
void isolate(int r, int c) { Position p; init_pos(p); p.board[r][c] = {grey, empty, false}; print_pos(p); std::vector<Move> moves = moves_from(p); for(std::vector<Move>::const_iterator i=moves.begin(); i!=moves.end(); ++i) { printf("%d %d ---> %d %d\n", i->source.r, i->source.c, i->dest.r, i->dest.c); } }
/*** * Translating * This is a relative translation, from the p.o.v. of the camera ****/ void translate_eye(GLdouble x, GLdouble y, GLdouble z) { #ifdef DEBUG_FUNC static int translate_eye_count; translate_eye_count++; printf("Translate count: %i\n", translate_eye_count); #endif #ifdef DEBUG_VALUE printf("Relative translation by: %f %f %f\n", x, y, z); #endif // Calculate the player's directional axis in terms of the reference axis GLdouble x_axis[3] = {0,0,0}; GLdouble y_axis[3] = {0,0,0}; GLdouble z_axis[3] = {0,0,0}; get_rel_axis(x_axis, y_axis, z_axis); // multiply by how fast the player's moving to get the movement vector GLdouble x_move = x*x_axis[0] + y*y_axis[0] + z*z_axis[0]; GLdouble y_move = x*x_axis[1] + y*y_axis[1] + z*z_axis[1]; GLdouble z_move = x*x_axis[2] + y*y_axis[2] + z*z_axis[2]; // note the movements of the view if (x || y || z) { eye_pos[0] += x_move; eye_pos[1] += y_move; eye_pos[2] += z_move; chars[0]->position[0] = eye_pos[0]; chars[0]->position[1] = eye_pos[1]; chars[0]->position[2] = eye_pos[2]; center_pos[0] += x_move; center_pos[1] += y_move; center_pos[2] += z_move; up_pos[0] = y_axis[0]; up_pos[1] = y_axis[1]; up_pos[2] = y_axis[2]; } #ifdef DEBUG_VALUE printf("Translation vector: [%f %f %f]\n", x, y, z); printf("Char %d Position: %d %d %d\n",1,(int)chars[0]->position[0],(int)chars[0]->position[1],(int)chars[0]->position[2]); printf("Object %d Position: %d %d %d\n",1,(int)objects[0]->position[0],(int)objects[0]->position[1],(int)objects[0]->position[2]); #endif print_pos(); // Apply changes glPushAttrib(GL_MATRIX_MODE); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eye_pos[0],eye_pos[1],eye_pos[2], center_pos[0],center_pos[1],center_pos[2], up_pos[0],up_pos[1],up_pos[2]); glPopAttrib(); }
// 这个函数由SON进程调用, 其作用是接收数据结构sendpkt_arg_t. // 报文和下一跳的节点ID被封装进sendpkt_arg_t结构. // 参数sip_conn是在SIP进程和SON进程之间的TCP连接的套接字描述符. // sendpkt_arg_t结构通过SIP进程和SON进程之间的TCP连接发送, 使用分隔符!&和!#. // 为了接收报文, 这个函数使用一个简单的有限状态机FSM // PKTSTART1 -- 起点 // PKTSTART2 -- 接收到'!', 期待'&' // PKTRECV -- 接收到'&', 开始接收数据 // PKTSTOP1 -- 接收到'!', 期待'#'以结束数据的接收 // 如果成功接收sendpkt_arg_t结构, 返回1, 否则返回-1. int getpktToSend(sip_pkt_t* pkt, int* nextNode,int sip_conn) { sendpkt_arg_t packet; memset(&packet, 0, sizeof(packet)); int r = recv_state_machine(&packet, sizeof(packet), sip_conn); if (r < 0) return -1; print_pos(); printf("length = %d, \'%s\'\n", packet.pkt.header.length, packet.pkt.data); *nextNode = packet.nextNodeID; //int l = packet.pkt.header.length; memcpy(pkt, &(packet.pkt), sizeof(packet.pkt)); return 1; }
// forwardpktToSIP()函数是在SON进程接收到来自重叠网络中其邻居的报文后被调用的. // SON进程调用这个函数将报文转发给SIP进程. // 参数sip_conn是SIP进程和SON进程之间的TCP连接的套接字描述符. // 报文通过SIP进程和SON进程之间的TCP连接发送, 使用分隔符!&和!#, 按照'!& 报文 !#'的顺序发送. // 如果报文发送成功, 返回1, 否则返回-1. int forwardpktToSIP(sip_pkt_t* pkt, int sip_conn) { int r = send(sip_conn, begin, strlen(begin), MSG_NOSIGNAL); if (r == -1) return -1; int l = sizeof(sip_hdr_t) + pkt -> header.length; print_pos(); printf("actual length = %d\n", l); r = send(sip_conn, pkt, l, MSG_NOSIGNAL); if (r == -1) return -1; r = send(sip_conn, end, strlen(end), MSG_NOSIGNAL); if (r == -1) return -1; return 1; }
// get *length* bytes of data from *connfd* , // write to *content*, using the state machine. int recv_state_machine(void * content, int length, int connfd) { if (connfd < 0) { print_pos(); return -1; } int state = -1; char c; int len = 0, success = 0; char * fill = (char *)content; state = PKTSTART1; while ( recv(connfd, &c, 1, MSG_NOSIGNAL) > 0 ) { //putchar(c); switch (state) { case PKTSTART1: if (c == '!') state = PKTSTART2; // start state break; case PKTSTART2: if (c == '&') state = PKTRECV; // start state else state = PKTSTART1; break; case PKTRECV: if (c == '!') state = PKTSTOP1; // about to end? else if (len < length) fill[len++] = c; // recv data //else return -1; // size too long break; case PKTSTOP1: if (c == '!') { // the prev '!' is just data if (len < length) fill[len++] = c; // recv data //else return -1; // size too long } else if (c == '#') { // yes! success = 1; return 1; } else { // the prev '!' is just data, continue to recv state = PKTRECV; if (len+1 < length) { fill[len++] = '!'; fill[len++] = c; } //else return -1; // too long } break; default: break; } } if (success == 1) return 1; else return -1; }