Ejemplo n.º 1
0
static int
set_disq_comment_func(
        struct xuser_cnts_state *data,
        int user_id,
        const unsigned char *disq_comment)
{
    struct xuser_mongo_cnts_state *state = (struct xuser_mongo_cnts_state *) data;
    struct team_extra *extra = do_get_entry(state, user_id);
    if (!extra) return -1;
    if (!extra->disq_comment && !disq_comment) {
        return 0;
    }
    if (extra->disq_comment && !disq_comment) {
        ASSERT(ej_uuid_is_nonempty(extra->uuid));
        xfree(extra->disq_comment); extra->disq_comment = NULL;
        bson *doc = bson_new();
        bson_append_string(doc, "disq_comment", "", 0);
        bson_finish(doc);
        return do_update(state, extra, "$unset", doc);
    }
    if (extra->disq_comment && !strcmp(extra->disq_comment, disq_comment))
        return 0;
    xfree(extra->disq_comment);
    extra->disq_comment = xstrdup(disq_comment);
    if (ej_uuid_is_nonempty(extra->uuid)) {
        bson *doc = bson_new();
        bson_append_string(doc, "disq_comment", extra->disq_comment, strlen(extra->disq_comment));
        bson_finish(doc);
        return do_update(state, extra, NULL, doc);
    } else {
        return do_insert(state, extra);
    }
}
Ejemplo n.º 2
0
int
handle_transfer_command(struct thread_data_t * datum, char * args)
{
  long amount, balance;
  char * user, buffer[MAX_COMMAND_LENGTH];

  #ifndef NDEBUG
  if (*args == '\0') {
    fprintf(stderr,
            "[thread %lu] WARNING: [%s] arguments empty\n",
            datum->id, "transfer");
  } else {
    fprintf(stderr,
            "[thread %lu] INFO: [%s] '%s' (arguments)\n",
            datum->id, "transfer", args);
  }
  #endif
  amount = strtol(args, &args, 10);
  user = ++args;

  if (amount <= 0 || amount > MAX_TRANSACTION) {
    snprintf(buffer, MAX_COMMAND_LENGTH, "Invalid transfer amount.");
  } else if (datum->credentials.userlength
   && do_lookup(session_data.db_conn, NULL,
                datum->credentials.username,
                datum->credentials.userlength,
                &balance) == BANKING_SUCCESS) {
    if (balance < amount) {
      snprintf(buffer, MAX_COMMAND_LENGTH, "Insufficient funds.");
    } else if (do_update(session_data.db_conn, NULL,
               datum->credentials.username,
               datum->credentials.userlength,
               balance - amount)
            || do_lookup(session_data.db_conn, NULL,
               user, strnlen(user, MAX_COMMAND_LENGTH),
               &balance)
            || do_update(session_data.db_conn, NULL,
               user, strnlen(user, MAX_COMMAND_LENGTH),
               balance + amount)) {
      /* TODO atomic operation? */
      snprintf(buffer, MAX_COMMAND_LENGTH, "Cannot complete transfer.");
    } else {
      snprintf(buffer, MAX_COMMAND_LENGTH, "Transfered $%li to %s",
                                           amount, user);
    }
  } else {
    snprintf(buffer, MAX_COMMAND_LENGTH, "TRANSFER ERROR");
  }
  salt_and_pepper(buffer, NULL, &datum->buffet);
  encrypt_message(&datum->buffet, datum->credentials.key);
  send_message(&datum->buffet, datum->sock);

  return BANKING_SUCCESS;
}
Ejemplo n.º 3
0
static void select_items(int n) {
	int fsel = 0;

	while (42) {
		if (n > 0)
			print_item(fsel, STATUS_BG, STATUS_FG);

		switch (wait_any_key()) {
		case KEY_ENTER:
			setvar(V_sel_item, intobj[fsel]);
			goto exit_select;
		case KEY_ESCAPE:
			setvar(V_sel_item, 0xff);
			goto exit_select;
		case KEY_UP:
			if (fsel >= 2)
				fsel -= 2;
			break;
		case KEY_DOWN:
			if (fsel + 2 < n)
				fsel += 2;
			break;
		case KEY_LEFT:
			if (fsel % 2 == 1)
				fsel--;
			break;
		case KEY_RIGHT:
			if (fsel % 2 == 0 && fsel + 1 < n)
				fsel++;
			break;
		case BUTTON_LEFT:{
				int i = find_item();
				if (i >= 0 && i < n) {
					setvar(V_sel_item, intobj[fsel = i]);
					debugC(6, kDebugLevelInventory, "item found: %d", fsel);
					show_items();
					print_item(fsel, STATUS_BG, STATUS_FG);
					do_update();
					goto exit_select;
				}
				break;
			}
		default:
			break;
		}

		show_items();
		do_update();
	}

 exit_select:
	debugC(6, kDebugLevelInventory, "selected: %d", fsel);
}
Ejemplo n.º 4
0
    items::items(editor_resource_ptr res, QWidget* parent)
      : QFrame(parent)
      , resource_(res)
    {
      setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

      QGridLayout* l = new QGridLayout(this);
      l->setContentsMargins(0, 0, 0, 0);

      // Tablewidget
      data_ = new QTableWidget(this);

      data_->setColumnCount(3);
      data_->setHorizontalHeaderLabels(QStringList() << "Filename" << "Type" << "?");
      data_->setColumnWidth(0, 100);
      data_->setColumnWidth(1, 75);
      data_->setColumnWidth(2, 20);

      data_->verticalHeader()->setVisible(false);

      data_->setEditTriggers(QTableWidget::NoEditTriggers);
      data_->setSelectionMode(QTableWidget::SingleSelection);
      data_->setSelectionBehavior(QTableWidget::SelectRows);
      data_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

      l->addWidget(data_, 0, 0, 1, 2);

      // Buttons
      QPushButton* btn_edit = new QPushButton("Edit", this);
      btn_edit->setMaximumWidth(80);
      l->addWidget(btn_edit, 2, 0, Qt::AlignCenter);
      connect(btn_edit, SIGNAL(clicked()), SLOT(do_edit()));

      QPushButton* btn_add = new QPushButton("Add", this);
      btn_add->setMaximumWidth(80);
      l->addWidget(btn_add, 1, 0, Qt::AlignCenter);
      connect(btn_add, SIGNAL(clicked()), SLOT(do_add()));

      QPushButton* btn_remove = new QPushButton("Remove", this);
      btn_remove->setMaximumWidth(80);
      l->addWidget(btn_remove, 1, 1, Qt::AlignCenter);
      connect(btn_remove, SIGNAL(clicked()), SLOT(do_remove()));

      QPushButton* btn_generate = new QPushButton("Generate", this);
      btn_generate->setMaximumWidth(80);
      l->addWidget(btn_generate, 2, 1, Qt::AlignCenter);
      connect(btn_generate, SIGNAL(clicked()), SLOT(do_generate()));

      connect(resource_.data(), SIGNAL(sig_resource_updated()), SLOT(do_update()));
      do_update();
    }
// Callbacks
void timer_callback(uint unused0, uint unused1) {
    use(unused0);
    use(unused1);
    time++;

    log_debug("Timer tick %d", time);

    if ((infinite_run != TRUE) && (time == simulation_ticks)) {
        simulation_handle_pause_resume(NULL);
        log_info("Simulation complete.\n");
        simulation_ready_to_read();
    }

    // Process the incoming spikes
    spike_t s;
    uint32_t nid;
    while (in_spikes_get_next_spike(&s)) {
        nid = (s & NEURON_ID_MASK);

        if (nid < N_COUNTERS) {
            counters[nid] += 1;
        } else {
            log_debug("Received spike from unknown neuron %d", nid);
        }
    }

    // Work out if there is any motion
    if ((time % sample_time) == 0) {

        // Do motion in pairs
        do_motion(MOTION_FORWARD, MOTION_BACK, "Forwards", "Backwards");
        do_motion(MOTION_LEFT, MOTION_RIGHT, "Left", "Right");
        do_motion(MOTION_CLOCKWISE, MOTION_C_CLOCKWISE, "Clockwise",
                  "Anti-clockwise");

        // Reset the counters
        for (uint32_t i = 0; i < N_COUNTERS; i++) {
            counters[i] = 0;
        }
    } else if ((time % update_time) == 0) {

        // Do updates in pairs
        do_update(MOTION_FORWARD, MOTION_BACK, "Forwards", "Backwards");
        do_update(MOTION_LEFT, MOTION_RIGHT, "Left", "Right");
        do_update(MOTION_CLOCKWISE, MOTION_C_CLOCKWISE, "Clockwise",
                  "Anti-clockwise");
    }
}
Ejemplo n.º 6
0
static void run_application(MYSQL &mysql,
			    Ndb_cluster_connection &cluster_connection)
{
  /********************************************
   * Connect to database via mysql-c          *
   ********************************************/
  mysql_query(&mysql, "CREATE DATABASE TEST_DB_1");
  if (mysql_query(&mysql, "USE TEST_DB_1") != 0) MYSQLERROR(mysql);
  create_table(mysql);

  /********************************************
   * Connect to database via NdbApi           *
   ********************************************/
  // Object representing the database
  Ndb myNdb( &cluster_connection, "TEST_DB_1" );
  if (myNdb.init()) APIERROR(myNdb.getNdbError());

  /*
   * Do different operations on database
   */
  do_insert(myNdb);
  do_update(myNdb);
  do_delete(myNdb);
  do_read(myNdb);
  drop_table(mysql);
  mysql_query(&mysql, "DROP DATABASE TEST_DB_1");
}
Ejemplo n.º 7
0
int done_jiqi(object me) {
	
	string msg;
	
	if (!me || me->is_ghost() || environment(me)!= this_object())
		return 1;
		
	if (me->query_temp("jiqi/num")>=3) {
		msg = HIR"
һ�������ֻ���������������������ȫ������֮�У�����һ����
ˮ���ڵ�����ת�������ޱȡ�ǡ��ˮ����ã��������ᣬ������ʮ��
����һһ���ƣ����Ǵ󹦸���ˡ�\n\n"NOR;
		me->delete_temp("jiqi");
		do_update(me);
		if (me->query("eff_kee")>me->query("max_kee")) me->set("eff_kee",me->query("max_kee"));
		if (me->query("eff_gin")>me->query("max_gin")) me->set("eff_gin",me->query("max_gin"));
		if (me->query("eff_sen")>me->query("max_sen")) me->set("eff_sen",me->query("eff_sen"));
		if (me->query("kee")>me->query("eff_kee")) me->set("kee",me->query("eff_kee"));
		if (me->query("gin")>me->query("eff_gin")) me->set("gin",me->query("eff_gin"));
		if (me->query("sen")>me->query("eff_sen")) me->set("sen",me->query("eff_sen"));
	} else {
		msg = YEL"
һ�������ֻ���������������������ȫ������֮�У�����һ����
ˮ���ڵ�����ת�������ޱȡ�\n\n"NOR;
		me->delete_temp("jiqi/in_tuna");
	}
	tell_object(me,msg);
	me->stop_busy();
	return 1;
}
Ejemplo n.º 8
0
static int
set_clar_status_func(
        struct xuser_cnts_state *data,
        int user_id,
        int clar_id,
        const ej_uuid_t *p_clar_uuid)
{
    struct xuser_mongo_cnts_state *state = (struct xuser_mongo_cnts_state *) data;
    struct team_extra *extra = do_get_entry(state, user_id);
    if (!extra) return -1;
    if (!p_clar_uuid) return -1;
    int r = team_extra_add_clar_uuid(extra, p_clar_uuid);
    if (r <= 0) return r;
    if (ej_uuid_is_nonempty(extra->uuid)) {
        bson *arr = ej_bson_unparse_array_uuid(extra->clar_uuids, extra->clar_uuids_size);
        bson *doc = bson_new();
        bson_append_array(doc, "clar_uuids", arr);
        bson_free(arr); arr = NULL;
        bson_finish(doc);
        return do_update(state, extra, NULL, doc);
    } else {
        return do_insert(state, extra);
    }
    return -1;
}
Ejemplo n.º 9
0
void do_choice(int choice)
{
	printf("is in the process of the first %d a choice \n", choice);

	switch (choice)
	{
		case INSERT :
			do_insert();
			break;
		case QUERY:
			do_query();
			break;
		case UPDATE:
			do_update();
			break;
		case DELETE:
			do_delete();
			break;
		case LIST:
			do_list_all();
			break;
		case QUIT:
			do_quit();
			break;
		default:
			break;
	}
}
Ejemplo n.º 10
0
short process_cmd(void) {
    char cmd[4];
    short ret = 0;

    RECV(STDIN, cmd, sizeof(cmd));

    if (0 == memcmp((void *)CMD_BUY, cmd, sizeof(CMD_BUY))) {
    	ret = do_buy();
    } else if (0 == memcmp((void *)CMD_CHECK, cmd, sizeof(CMD_CHECK))) {
    	ret = do_check();
    } else if (0 == memcmp((void *)CMD_ADD, cmd, sizeof(CMD_ADD))) {
    	ret = do_add();
    } else if (0 == memcmp((void *)CMD_RM, cmd, sizeof(CMD_RM))) {
    	ret = do_rm();
    } else if (0 == memcmp((void *)CMD_UPDATE, cmd, sizeof(CMD_UPDATE))) {
    	ret = do_update();
    } else if (0 == memcmp((void *)CMD_ONSALE, cmd, sizeof(CMD_ONSALE))) {
    	ret = do_onsale();
    } else if (0 == memcmp((void *)CMD_NOSALE, cmd, sizeof(CMD_NOSALE))) {
    	ret = do_nosale();
    } else if (0 == memcmp((void *)CMD_LIST, cmd, sizeof(CMD_LIST))) {
    	ret = do_list();
    } else if (0 == memcmp((void *)CMD_QUIT, cmd, sizeof(CMD_QUIT))) {
    	ret = -2;
    } else {
    	ret = -1;
    }

	return ret;
}
Ejemplo n.º 11
0
static void run_application(MYSQL &mysql,
			    Ndb_cluster_connection &cluster_connection,
			    const char* table,
			    const char* db)
{
  /********************************************
   * Connect to database via mysql-c          *
   ********************************************/
 char db_stmt[256];
 sprintf(db_stmt, "CREATE DATABASE %s\n", db);
  mysql_query(&mysql, db_stmt);
 sprintf(db_stmt, "USE %s", db);
  if (mysql_query(&mysql, db_stmt) != 0) MYSQLERROR(mysql);
  create_table(mysql, table);

  /********************************************
   * Connect to database via NdbApi           *
   ********************************************/
  // Object representing the database
  Ndb myNdb( &cluster_connection, db );
  if (myNdb.init()) APIERROR(myNdb.getNdbError());

  /*
   * Do different operations on database
   */
  do_insert(myNdb, table);
  do_update(myNdb, table);
  do_delete(myNdb, table);
  do_read(myNdb, table);
  /*
   * Drop the table
   */
  mysql_query(&mysql, db_stmt);
}
Ejemplo n.º 12
0
Archivo: istream.c Proyecto: macks/w3m
int
ISeos(InputStream stream)
{
    BaseStream base = &stream->base;
    if (!base->iseos && MUST_BE_UPDATED(base))
	do_update(base);
    return base->iseos;
}
Ejemplo n.º 13
0
void run_game(nstate *state)
{
	while(state->state == STATE_RUNNING) {
		GrGetNextEventTimeout(&state->event, timeout_delay(state));
		handle_event(state);
		if(state->state == STATE_PAUSED) do_pause(state);
		if(state->state == STATE_RUNNING) do_update(state);
	}
}
Ejemplo n.º 14
0
int
deposit_command(char * args)
{
  size_t len, i;
  char * username;
  const char * residue;
  long int amount, balance;

  /* Advance args to the first token, this is the username */
  len = strnlen(args, MAX_COMMAND_LENGTH);
  for (i = 0; *args == ' ' && i < len; ++i, ++args);
  for (username = args; *args != '\0' && i < len; ++i, ++args) {
    if (*args == ' ') { *args = '\0'; i = len; }
  }
  len = strnlen(username, (size_t)(args - username));

  /* We should now be at the addition amount */
  amount = strtol(args, (char **)(&residue), 10);
  #ifndef NDEBUG
  if (*residue != '\0') {
    fprintf(stderr,
            "WARNING: ignoring '%s' (argument residue)\n",
            residue);
  }
  #endif

  /* Ensure the transaction amount is sane, TODO better solution? */
  if (amount < -MAX_TRANSACTION || amount > MAX_TRANSACTION) {
    fprintf(stderr,
            "ERROR: amount (%li) exceeds maximum transaction (%i)\n",
            amount, MAX_TRANSACTION);
    return BANKING_SUCCESS;
  }

  /* Prepare and run actual queries */
  if (do_lookup(session_data.db_conn, &residue,
                username, len, &balance)) {
    fprintf(stderr, "ERROR: no account found for '%s'\n", username);
  } else if (do_update(session_data.db_conn, &residue,
                       username, len, balance + amount)) {
    fprintf(stderr,
            "ERROR: unable to complete request on ('%s', %li)\n",
            username, balance);
  } else {
    printf("A transaction of $%li brings %s's balance from $%li to $%li\n",
           amount, username, balance, balance + amount);
  }
  #ifndef NDEBUG
  if (*residue != '\0') {
    fprintf(stderr, "WARNING: ignoring '%s' (query residue)\n", residue);
  }
  #endif

  return BANKING_SUCCESS;
}
Ejemplo n.º 15
0
/*
 * update a single file.
 * parse the "tokens" and check the version
 * if the version is newer, update it from the website
 */
static void update_file(char *tokens)
{
   char *file = NULL;
   char *rev = NULL;
   char *curr = NULL;
   char *url = NULL;
   size_t i, n = 0;
   char *tok;
   char errbuf[ERR_MAX_LEN];
  
   DEBUG_MSG("update_file");

   /* count the number of tokens delimited by ' ' */
   for (i = 0; i < strlen(tokens); i++)
      if (tokens[i] == ' ')
         n++;

   /* the token is invalid */
   if (n != 2)
      return;
   
   /* split the tokens */
   file = strdup(ec_strtok(tokens, " ", &tok));
   rev = strdup(ec_strtok(NULL, " ", &tok));
   url = strdup(ec_strtok(NULL, " ", &tok));
   
   /* get the current revision */
   if (get_current_rev(file, &curr, errbuf) == 0) {
      fprintf(stdout, " + %-18s -> "EC_COLOR_RED"ERROR"EC_COLOR_END"  %s\n", file, errbuf);
   } else {
      fprintf(stdout, " + %-18s -> revision "EC_COLOR_BLUE"%-4s"EC_COLOR_END" updating to "EC_COLOR_CYAN"%-4s"EC_COLOR_END"... ", file, curr, rev );
      fflush(stdout);
  
      /* update it if the current rev is different (newer) */
      if (!strcmp(curr, rev))
         fprintf(stdout, EC_COLOR_GREEN"OK"EC_COLOR_END"\n");
      else if (strcmp(curr, rev) < 0) {
         if (GBL_OPTIONS->silent)
            fprintf(stdout, EC_COLOR_YELLOW"NEED UPDATE"EC_COLOR_END"\n");
         else { 
            if (do_update(file, url, errbuf))
               fprintf(stdout, EC_COLOR_YELLOW"UPDATED"EC_COLOR_END"\n");
            else
               fprintf(stdout, EC_COLOR_RED"ERROR"EC_COLOR_END"  %s\n", errbuf);
         }
      } else
         fprintf(stdout, EC_COLOR_RED"NEWER"EC_COLOR_END"  %s\n", errbuf);
         
   }
   
   SAFE_FREE(curr);
   SAFE_FREE(file);
   SAFE_FREE(rev);
   SAFE_FREE(url);
}
Ejemplo n.º 16
0
Archivo: istream.c Proyecto: macks/w3m
int
ISgetc(InputStream stream)
{
    BaseStream base;
    if (stream == NULL)
	return '\0';
    base = &stream->base;
    if (!base->iseos && MUST_BE_UPDATED(base))
	do_update(base);
    return POP_CHAR(base);
}
Ejemplo n.º 17
0
/**
 * del_node
 *
 * @param phandle
 */
static void
del_node(unsigned int phandle)
{
    char *name = find_phandle(phandle);
    char delcmd[128] = "remove_node ";

    if (name == NULL)
        say(DEBUG, "Delete node error: Invalid phandle %8.8x", phandle);
    else {
        strcat(delcmd,name);
        do_update(delcmd, strlen(delcmd));
    }
}
Ejemplo n.º 18
0
 /** Returns the next value of the generator. */
 result_type operator()()
 {
     std::size_t short_index =
         (k < short_lag)?
         (k + long_lag - short_lag) :
         (k - short_lag);
     carry = do_update(k, short_index, carry);
     IntType result = x[k];
     ++k;
     if(k >= long_lag)
         k = 0;
     return result;
 }
Ejemplo n.º 19
0
/* len is in characters, not pixels!!
 */
void TextMan::blit_textbox(const char *p, int y, int x, int len) {
	/* if x | y = -1, then centre the box */
	int xoff, yoff, lin, h, w;
	char *msg, *m;

	debugC(3, kDebugLevelText, "x=%d, y=%d, len=%d", x, y, len);
	if (game.window.active)
		close_window();

	if (x == 0 && y == 0 && len == 0)
		x = y = -1;

	if (len <= 0 || len >= 40)
		len = 32;

	xoff = x * CHAR_COLS;
	yoff = y * CHAR_LINES;
	len--;

	m = msg = word_wrap_string(agi_sprintf(p), &len);

	for (lin = 1; *m; m++) {
		/* Test \r for MacOS 8 */
		if (*m == '\n' || *m == '\r')
			lin++;
	}

	if (lin * CHAR_LINES > GFX_HEIGHT)
		lin = (GFX_HEIGHT / CHAR_LINES);

	w = (len + 2) * CHAR_COLS;
	h = (lin + 2) * CHAR_LINES;

	if (xoff < 0)
		xoff = (GFX_WIDTH - w - CHAR_COLS) / 2;
	else
		xoff -= CHAR_COLS;

	if (yoff < 0)
		yoff = (GFX_HEIGHT - 3 * CHAR_LINES - h) / 2;

	draw_window(xoff, yoff, xoff + w - 1, yoff + h - 1);

	print_text2(2, msg, 0, CHAR_COLS + xoff, CHAR_LINES + yoff,
			len + 1, MSG_BOX_TEXT, MSG_BOX_COLOUR);

	free(msg);

	do_update();
}
Ejemplo n.º 20
0
/**
 * \brief Update the base_tweener of a given amount of time.
 * \param dt The duration of the update in time units since the last call.
 * \return The amount of extra time in dt after the end of the update.
 */
double claw::tween::base_tweener::update( double dt )
{
    CLAW_PRECOND( dt >= 0 );

    const double result = do_update(dt);

    if ( is_finished() )
        notify_finished();

    CLAW_POSTCOND( result <= dt );
    CLAW_POSTCOND( result >= 0 );

    return result;
} // base_tweener::update()
Ejemplo n.º 21
0
Archivo: istream.c Proyecto: macks/w3m
Str
StrmyISgets(InputStream stream)
{
    BaseStream base;
    StreamBuffer sb;
    Str s = NULL;
    int i, len;

    if (stream == NULL)
	return '\0';
    base = &stream->base;
    sb = &base->stream;

    while (!base->iseos) {
	if (MUST_BE_UPDATED(base)) {
	    do_update(base);
	}
	else {
	    if (s && Strlastchar(s) == '\r') {
		if (sb->buf[sb->cur] == '\n')
		    Strcat_char(s, (char)sb->buf[sb->cur++]);
		return s;
	    }
	    for (i = sb->cur;
		 i < sb->next && sb->buf[i] != '\n' && sb->buf[i] != '\r';
		 i++) ;
	    if (i < sb->next) {
		len = i - sb->cur + 1;
		if (s == NULL)
		    s = Strnew_size(len + MARGIN_STR_SIZE);
		Strcat_charp_n(s, (char *)&sb->buf[sb->cur], len);
		sb->cur = i + 1;
		if (sb->buf[i] == '\n')
		    return s;
	    }
	    else {
		if (s == NULL)
		    s = Strnew_size(sb->next - sb->cur + MARGIN_STR_SIZE);
		Strcat_charp_n(s, (char *)&sb->buf[sb->cur],
			       sb->next - sb->cur);
		sb->cur = sb->next;
	    }
	}
    }

    if (s == NULL)
	return Strnew();
    return s;
}
Ejemplo n.º 22
0
/*{{{  update -- update an obscured window*/
void update(WINDOW *win, rect *clipp)
{
  /* generate clip list */

  if (!(W(flags) & W_CLIPDONE)) {
    if (W(clip_list) != NULL) /* free old list (we could reuse it) */
      zap_cliplist(win);
    gen_list(win);
    W(flags) |= W_CLIPDONE;
  }

  /* update the window */

  do_update(win, clipp); /* do the update */
}
Ejemplo n.º 23
0
void TextMan::erase_textbox() {
	if (!game.window.active) {
		debugC(3, kDebugLevelText, "no window active");
		return;
	}

	debugC(4, kDebugLevelText, "x1=%d, y1=%d, x2=%d, y2=%d", game.window.x1,
			game.window.y1, game.window.x2, game.window.y2);

	restore_block(game.window.x1, game.window.y1,
			game.window.x2, game.window.y2, game.window.buffer);

	free(game.window.buffer);
	game.window.active = false;

	do_update();
}
Ejemplo n.º 24
0
bool
SkinMeme::apply_delt()
{
   // Nothing to do:
   if (_delt.is_null())
      return false;

   // Compute displaced location
//    _update = loc() + _delt;
//    _delt = Wvec::null();

   // trying this out: ignore computed _delta,
   // instead base new location on computed track point
   // (which was recomputed in compute_delt())
   return do_update();
//    return apply_update();
}
Ejemplo n.º 25
0
int
handle_withdraw_command(struct thread_data_t * datum, char * args)
{
  long balance, amount;
  char buffer[MAX_COMMAND_LENGTH];

  #ifndef NDEBUG
  if (*args == '\0') {
    fprintf(stderr,
            "[thread %lu] WARNING: [%s] arguments empty\n",
            datum->id, "withdraw");
  } else {
    fprintf(stderr,
            "[thread %lu] INFO: [%s] '%s' (arguments)\n",
            datum->id, "withdraw", args);
  }
  #endif
  amount = strtol(args, &args, 10);

  if (amount <= 0 || amount > MAX_TRANSACTION) {
    snprintf(buffer, MAX_COMMAND_LENGTH, "Invalid withdrawal amount.");
  } else if (datum->credentials.userlength
   && do_lookup(session_data.db_conn, NULL,
                datum->credentials.username,
                datum->credentials.userlength,
                &balance) == BANKING_SUCCESS) {
    if (balance < amount) {
      snprintf(buffer, MAX_COMMAND_LENGTH, "Insufficient funds.");
    } else if (do_update(session_data.db_conn, NULL,
               datum->credentials.username,
               datum->credentials.userlength,
               balance - amount)) {
      snprintf(buffer, MAX_COMMAND_LENGTH, "Cannot complete withdrawal.");
    } else {
      snprintf(buffer, MAX_COMMAND_LENGTH, "Withdrew $%li", amount);
    }
  } else {
    snprintf(buffer, MAX_COMMAND_LENGTH, "WITHDRAW ERROR");
  }
  salt_and_pepper(buffer, NULL, &datum->buffet);
  encrypt_message(&datum->buffet, datum->credentials.key);
  send_message(&datum->buffet, datum->sock);

  return BANKING_SUCCESS;
}
Ejemplo n.º 26
0
/** anchor update main */
int main(int argc, char** argv)
{
	int retcode = 1;
	if(argc == 1) {
		usage();
	}
	argc--;
	argv++;
	while(argc > 0) {
		int r = do_update(argv[0], argv[1]);
		if(r == 0) retcode = 0;

		/* next */
		argc-=2;
		argv+=2;
	}
	return retcode;
}
Ejemplo n.º 27
0
static void process_cmd_fifo(void)
{
	int len;
	struct update_param p;
	struct omap_dss_device *dssdev;
	unsigned long flags;

	if (atomic_inc_return(&rfbi.cmd_pending) != 1)
		return;

	while (true) {
		spin_lock_irqsave(rfbi.cmd_fifo->lock, flags);

		len = __kfifo_get(rfbi.cmd_fifo, (unsigned char *)&p,
				  sizeof(struct update_param));
		if (len == 0) {
			DSSDBG("nothing more in fifo\n");
			atomic_set(&rfbi.cmd_pending, 0);
			spin_unlock_irqrestore(rfbi.cmd_fifo->lock, flags);
			break;
		}

		/* DSSDBG("fifo full %d\n", rfbi.cmd_fifo_full.counter);*/

		spin_unlock_irqrestore(rfbi.cmd_fifo->lock, flags);

		BUG_ON(len != sizeof(struct update_param));
		BUG_ON(p.rfbi_module > 1);

		dssdev = rfbi.dssdev[p.rfbi_module];

		if (p.cmd == RFBI_CMD_UPDATE) {
			if (do_update(dssdev, &p.par.r))
				break; /* async op */
		} else if (p.cmd == RFBI_CMD_SYNC) {
			DSSDBG("Signaling SYNC done!\n");
			complete(p.par.sync);
		} else
			BUG();
	}

	signal_fifo_waiters();
}
Ejemplo n.º 28
0
static int
set_status_func(
        struct xuser_cnts_state *data,
        int user_id,
        int status)
{
    struct xuser_mongo_cnts_state *state = (struct xuser_mongo_cnts_state *) data;
    struct team_extra *extra = do_get_entry(state, user_id);
    if (!extra) return -1;
    if (extra->status == status) return 0;
    extra->status = status;
    if (ej_uuid_is_nonempty(extra->uuid)) {
        bson *doc = bson_new();
        bson_append_int32(doc, "status", status);
        bson_finish(doc);
        return do_update(state, extra, NULL, doc);
    } else {
        return do_insert(state, extra);
    }
}
Ejemplo n.º 29
0
Archivo: istream.c Proyecto: macks/w3m
Str
StrISgets(InputStream stream)
{
    BaseStream base;
    StreamBuffer sb;
    Str s = NULL;
    uchar *p;
    int len;

    if (stream == NULL)
	return '\0';
    base = &stream->base;
    sb = &base->stream;

    while (!base->iseos) {
	if (MUST_BE_UPDATED(base)) {
	    do_update(base);
	}
	else {
	    if ((p = memchr(&sb->buf[sb->cur], '\n', sb->next - sb->cur))) {
		len = p - &sb->buf[sb->cur] + 1;
		if (s == NULL)
		    s = Strnew_size(len);
		Strcat_charp_n(s, (char *)&sb->buf[sb->cur], len);
		sb->cur += len;
		return s;
	    }
	    else {
		if (s == NULL)
		    s = Strnew_size(sb->next - sb->cur + MARGIN_STR_SIZE);
		Strcat_charp_n(s, (char *)&sb->buf[sb->cur],
			       sb->next - sb->cur);
		sb->cur = sb->next;
	    }
	}
    }

    if (s == NULL)
	return Strnew();
    return s;
}
Ejemplo n.º 30
0
static void interpret_cycle() {
	int old_sound, old_score;

	if (game.player_control)
		game.vars[V_ego_dir] = game.view_table[0].direction;
	else
		game.view_table[0].direction = game.vars[V_ego_dir];

	check_all_motions();

	old_score = game.vars[V_score];
	old_sound = getflag(F_sound_on);

	game.exit_all_logics = false;
	while (run_logic(0) == 0 && !game.quit_prog_now) {
		game.vars[V_word_not_found] = 0;
		game.vars[V_border_touch_obj] = 0;
		game.vars[V_border_code] = 0;
		old_score = game.vars[V_score];
		setflag(F_entered_cli, false);
		game.exit_all_logics = false;
		reset_controllers();
	}
	reset_controllers();

	game.view_table[0].direction = game.vars[V_ego_dir];

	if (game.vars[V_score] != old_score || getflag(F_sound_on) != old_sound)
		_text->write_status();

	game.vars[V_border_touch_obj] = 0;
	game.vars[V_border_code] = 0;
	setflag(F_new_room_exec, false);
	setflag(F_restart_game, false);
	setflag(F_restore_just_ran, false);

	if (game.gfx_mode) {
		update_viewtable();
		do_update();
	}
}