Exemplo n.º 1
0
/*
 * returns true if the user's program must use this var as an empty var
 * this is usefull for arrays
 */
int v_isempty(var_t *var) {
  switch (var->type) {
  case V_STR:
    return (strlen(var->v.p.ptr) == 0);
  case V_INT:
    return (var->v.i == 0);
  case V_MAP:
    return map_is_empty(var);
  case V_PTR:
    return (var->v.ap.p == 0);
  case V_NUM:
    return (var->v.n == 0.0);
  case V_ARRAY:
    return (var->v.a.size == 0);
  case V_REF:
    return v_isempty(var->v.ref);
  }

  return 1;
}
Exemplo n.º 2
0
/*
 * cs_next --
 *	Retrieve the next character.
 *
 * PUBLIC: int cs_next __P((SCR *, VCS *));
 */
int
cs_next(SCR *sp, VCS *csp)
{
	CHAR_T *p;

	switch (csp->cs_flags) {
	case CS_EMP:				/* EMP; get next line. */
	case CS_EOL:				/* EOL; get next line. */
		if (db_get(sp, ++csp->cs_lno, 0, &p, &csp->cs_len)) {
			--csp->cs_lno;
			csp->cs_flags = CS_EOF;
		} else {
			csp->cs_bp = p;
			if (csp->cs_len == 0 ||
			    v_isempty(csp->cs_bp, csp->cs_len)) {
				csp->cs_cno = 0;
				csp->cs_flags = CS_EMP;
			} else {
				csp->cs_flags = 0;
				csp->cs_ch = csp->cs_bp[csp->cs_cno = 0];
			}
		}
		break;
	case 0:
		if (csp->cs_cno == csp->cs_len - 1)
			csp->cs_flags = CS_EOL;
		else
			csp->cs_ch = csp->cs_bp[++csp->cs_cno];
		break;
	case CS_EOF:				/* EOF. */
		break;
	default:
		abort();
		/* NOTREACHED */
	}
	return (0);
}
Exemplo n.º 3
0
int debugThread(void *data) {
  int port = ((intptr_t) data);
  socket_t socket = net_listen(port);
  char buf[OS_PATHNAME_SIZE + 1];

  if (socket == -1) {
    signalTrace(SDL_FALSE, SDL_TRUE);
    return -1;
  }

  while (socket != -1) {
    int size = net_input(socket, buf, sizeof(buf), "\r\n");
    if (size > 0) {
      char cmd = buf[0];
      switch (cmd) {
      case 'n':
        // step over next line
        signalTrace(SDL_TRUE);
        break;
      case 'c':
        // continue
        signalTrace(SDL_FALSE);
        break;
      case 'l':
        // current line number
        SDL_LockMutex(g_lock);
        net_printf(socket, "%d\n", g_debugLine);
        SDL_UnlockMutex(g_lock);
        break;
      case 'v':
        // variables
        SDL_LockMutex(g_lock);
        if (!runtime->isRunning()) {
          net_printf(socket, "\n");
        } else {
          net_print(socket, "Variables:\n");
          for (unsigned i = SYSVAR_COUNT; i < prog_varcount; i++) {
            if (!v_isempty(tvar[i])) {
              pv_writevar(tvar[i], PV_NET, socket);
              net_print(socket, "\n");
            }
          }
          net_print(socket, "Stack:\n");
          dumpStack(socket);
          net_print(socket, "\1");
        }
        SDL_UnlockMutex(g_lock);
        break;
      case 'b':
        // set breakpoint
        SDL_LockMutex(g_lock);
        g_breakPoints.add(new int(atoi(buf + 2)));
        SDL_UnlockMutex(g_lock);
        break;
      case 'q':
        // quit
        signalTrace(SDL_FALSE, SDL_TRUE);
        g_breakPoints.removeAll();
        net_disconnect(socket);
        socket = -1;
        break;
      case 'h':
        net_print(socket, "SmallBASIC debugger\n");
        break;
      default:
        // unknown command
        net_printf(socket, "Unknown command '%s'\n", buf);
        break;
      };
    }
  }
  return 0;
}