⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 visual.c

📁 一个用在mips体系结构中的操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:
          * User-specific closing too ?          */         conn->sd = 0;         conn->id = 0;                  for (j = 0; j < VISUAL_MAXSTREAM; j++) {            if (conn->stream[j].sd) {                close(conn->stream[j].sd);               conn->stream[j].sd = 0;            }         }         return;      }            conn->buf[conn->pos++] = readBuffer;      if (readBuffer == '\n') {               conn->buf[conn->pos] = '\0';         if (Tcl_CommandComplete(conn->buf)) {            result = VisualRPC(conn,conn->buf);            SIM_DEBUG(('v', "VisualRPC -> %s\n",result));            if (!*result) {                result  = "OK";            }            PushString(conn->sd,result);            return;         }      }   }}   /* * VisualControl */static bool VisualControl(void) {  fd_set reads;  int i;  bool return_val;  struct timeval timeout;  static int width = -1;  /* debug subsystem needs to poll its incoming connection at a    * similar frequency as visual, let's use the same select() call   */  int debug_fd;  timeout.tv_sec = 0;  timeout.tv_usec = 0;  if (!visualState.listenSD) {     return FALSE;  }  FD_ZERO(&reads );  FD_SET (visualState.listenSD, &reads );  for (i=0;i<VISUAL_MAXCONN;i++) {     if (visualState.conn[i].sd) {        FD_SET(visualState.conn[i].sd,&reads);     }  }  debug_fd = Simdebug_pollfd();  if (debug_fd != -1) {     FD_SET(debug_fd,&reads);  }  if (width < 0) {      width = getdtablesize();  }  i  = select( width, &reads, NULL, NULL,&timeout );  if (i<0) {     perror("VisualControl select");     return FALSE;  } else if (i == 0) {     return FALSE;  }  /* return value TRUE indicates go around the loop again.   * we can't do this in the case of calling the debugger   * because the pending data might not get sucked in here.   */  return_val = TRUE;  if (FD_ISSET( visualState.listenSD, &reads ) ) {     VisualAccept(visualState.listenSD);  }   for (i=0;i<VISUAL_MAXCONN;i++) {     if (visualState.conn[i].sd &&          FD_ISSET(visualState.conn[i].sd,&reads)) {         VisualCmd(&visualState.conn[i]);     }  }  if (FD_ISSET( debug_fd, &reads)) {     Simdebug_fdactive();     pauseSimulation = FALSE; /* PZ: this is a topsy hack. 			       * setting pauseSimulation to TRUE from			       * simos.init will ensure that SimOS waits			       * for gdb before executing the first			       * instruction. */     return_val = FALSE;  }  return return_val;}/*  * VisualContext. * This keeps track and restores the context of execution of the currently * interpreted script.  * The context of an annotation is inherenited from the context that installed * it */int VisualGetContext(void){   return visualState.context;}int VisualSetContext(int context , int *old){   int i;   if (old) {      *old = visualState.context;   }      if (context > 0) {       for(i=0;i<VISUAL_MAXCONN;i++) {          if (visualState.conn[i].id == context) {            visualState.context = context;            return 1;         }      }      return 0;   }      visualState.context = context;   return 1;}static intPushString(int sd, char *string){   int len = strlen(string);   char strl[16];   int nc = PrintLLD(strl,(uint64)len);   sprintf(strl+nc, " ");   if( write(sd,strl,8)!=8) {      perror("PushString-len");      return 0;   }   if (write(sd,string,len) != len) {      perror("PushString");      return 0;   }    return len;}void VisualPushString(char *string){   int sd = VisualGetStream("log");   if (sd <= 0) {       CPUWarning("VISUAL: Trying to push string to non-opened stream: %s\n",                 string);      return;   }   PushString(sd, string);   SIM_DEBUG(('v', "VisualPushString: %s ", string));}static struct Connection *VisualGetConnection(void){   int i;   int ctxt = VisualGetContext();   for (i=0;i<VISUAL_MAXCONN;i++) {      if (ctxt == visualState.conn[i].id) {         return &(visualState.conn[i]);      }   }   return NULL;}static int VisualOpenStream(char *name, char *hostname, int portnumber){   int s, sd;   struct hostent *dest_host;   struct sockaddr_in dest_socket;   struct Connection *conn = VisualGetConnection();   if (conn == NULL) {       CPUWarning("Must issue visual command from remote connection\n");      return 0;   }   if (VisualGetStream(name) > 0) {      CPUWarning("Stream %s is already open\n", name);      return 0;   }   for (s = 0; (s < VISUAL_MAXSTREAM) && (conn->stream[s].sd > 0); s++) {}   if (s == VISUAL_MAXSTREAM) {      CPUWarning("Cannot open any more streams on this connection\n");      return 0;   }      dest_host = gethostbyname(hostname);   if( dest_host == NULL ) {      CPUWarning("Error resolving stream host name\n");      return 0;   }      dest_socket.sin_family = dest_host->h_addrtype;   dest_socket.sin_port   = (u_short) portnumber;   bcopy((void*)dest_host->h_addr_list[0],          (void*)&dest_socket.sin_addr,         dest_host->h_length);    sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);   if (connect(sd, (struct sockaddr *)&dest_socket, sizeof(dest_socket))) {      CPUWarning("Error connecting to data stream socket\n");      return 0;   }   ASSERT(sd >= 0);   conn->stream[s].sd = sd;   strcpy(conn->stream[s].name, name);   CPUWarning("Connecting to data stream socket '%s' on %s:%d\n",              name, hostname, portnumber);   return sd;}intVisualGetStream(char *name){   int s;   struct Connection *conn = VisualGetConnection();   if (conn == NULL) {       CPUWarning("Must issue visual command from remote connection\n");      return 0;   }   for (s = 0; s < VISUAL_MAXSTREAM; s++) {      if (!strcmp(conn->stream[s].name, name)) {         return conn->stream[s].sd;      }   }   return 0;}static intVisualCloseStream(char *name){   int s;   struct Connection *conn = VisualGetConnection();   if (conn == NULL) {       CPUWarning("Must issue visual command from remote connection\n");      return 0;   }   for (s = 0; s < VISUAL_MAXSTREAM; s++) {      if (!strcmp(conn->stream[s].name, name)) {         close(conn->stream[s].sd);         conn->stream[s].sd = 0;         return 1;      }   }   CPUWarning("Cannot close nonexistent stream %s\n", name);   return 0;}intVisualOpenCmd(Tcl_Interp *interp, int argc, char *argv[]){   char *name;   char *hostname;   int portnumber;   name = argv[2];   hostname = argv[3];   if (Tcl_GetInt(interp, argv[4], &portnumber) != TCL_OK) {      return TCL_ERROR;   }   if (VisualOpenStream(name, hostname, portnumber) == 0) {      CPUWarning("Error opening stream %s\n", name);      return TCL_ERROR;   }   return TCL_OK;}intVisualCloseCmd(Tcl_Interp *interp, int argc, char *argv[]){   if (VisualCloseStream(argv[2])) {      return TCL_OK;   } else {      return TCL_ERROR;   }}intVisualPutsCmd(Tcl_Interp *interp, int argc, char *argv[]){   char *name = argv[2];   char *string = argv[3];   int sd = VisualGetStream(name);   if (sd == 0) {      CPUWarning("visual puts: invalid stream identifier %s\n", name);      return TCL_ERROR;   }   if (PushString(sd, string) == 0) {      /*return TCL_ERROR;*/      return TCL_OK;   } else {      return TCL_OK;   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -