Ejemplo n.º 1
0
int main(){
	insert(5);
	insert(7);
	insert(3);
	insert(8);
	insert(12);
	insert(14);
	insert(118);
	print_queue();
	
	printf("\nextractMax:\n");
	int max = extractMax();		
	printf("\nThe Max is %d.\n",max);
	print_queue();
	
	printf("\nincrease, index is [5] and value is [10]:\n");
	increase(5,10);
	print_queue();
	
	printf("\nChange value, index is [5] and value is [10]:\n");
	change(5,10);
	print_queue();
	return 0;
}
Ejemplo n.º 2
0
main ()
{
  long f1n1, f1n2, f2n1, f2n2;	/* File 1, line number 1; etc. */
  int result;			/* Result of readline. */

  for (;;)
    {
      result = readline (line, BUFSIZ, stdin);
      f1n2 = f2n2 = UNUSED;
      if
	(sscanf (line, "%ld,%ldc%ld,%ld\n", &f1n1, &f1n2, &f2n1, &f2n2) == 4 ||
	sscanf (line, "%ld,%ldc%ld\n", &f1n1, &f1n2, &f2n1) == 3 ||
	sscanf (line, "%ldc%ld,%ld\n", &f1n1, &f2n1, &f2n2) == 3 ||
	sscanf (line, "%ldc%ld\n", &f1n1, &f2n1) == 2)
	change (f1n1, f1n2, f2n1, f2n2);
      else if
	  (sscanf (line, "%ld,%ldd%ld\n", &f1n1, &f1n2, &f2n1) == 3 ||
	sscanf (line, "%ldd%ld\n", &f1n1, &f2n1) == 2)
	delete (f1n1, f1n2, f2n1);
      else if
	  (sscanf (line, "%lda%ld,%ld\n", &f1n1, &f2n1, &f2n2) == 3 ||
	sscanf (line, "%lda%ld\n", &f1n1, &f2n1) == 2)
	append (f1n1, f2n1, f2n2);
      else
	{
	  /* The line wasn't the start of a diff.  Copy it verbatim. */
	  fputs (line, stdout);
	  /* If it was a long line, copy the remainder. */
	  while (result == -1)
	    {
	      result = readline (line, BUFSIZ, stdin);
	      fputs (line, stdout);
	    }
	}
    }
}
Ejemplo n.º 3
0
void ImageViewer::wheelEvent(QWheelEvent *e)
{
    if(noPicture() || !rect().contains(e->pos())) //cursor is not in widget
        return;

    qreal scale_old = scale;

    switch(e->modifiers()){
    case Qt::ShiftModifier:
        zoomIn(e->delta() / qreal(2400)); //e->delta() is +120 or -120
        break;
    case Qt::ControlModifier:
        zoomIn(e->delta() / qreal(600));
        break;
    default:
        zoomIn(e->delta() / qreal(1200));
        break;
    }

    QPointF distance(rect().center() - e->pos());
    QPointF change(distance / scale_old * scale - distance);
    shift += change;    //to keep the cursor position, must after scale.
    updateShift();
}
Ejemplo n.º 4
0
std::vector<sf::Vector2f> Polygon::GetPoints() const
{
	//Used to find the change in x and y from original location to return the actual position of the points
	sf::Vector2f change(GetPosition().x - m_originalCentroidPosition.x, GetPosition().y -  m_originalCentroidPosition.y);

	//Container vector for the points
	std::vector<sf::Vector2f> result;
	sf::Vector2f currPoint;

	//Get number of points of the polygon
	unsigned int numberOfPoints = m_shape.getPointCount();

	//Add each point to the container vector
	for (unsigned int i = 0; i < numberOfPoints; ++i)
	{
		currPoint = m_shape.getPoint(i);
		currPoint.x += change.x;
		currPoint.y += change.y;

		result.push_back(currPoint);
	}

	return result;
}
Ejemplo n.º 5
0
	void change(bool mod)
	{
		change(mod, true);
	}
Ejemplo n.º 6
0
int nslcd_usermod(TFILE *fp, MYLDAP_SESSION *session, uid_t calleruid)
{
  int32_t tmpint32;
  int rc = LDAP_SUCCESS;
  char username[BUFLEN_NAME];
  int asroot, isroot;
  char password[BUFLEN_PASSWORD];
  int32_t param;
  char buffer[4096];
  size_t buflen = sizeof(buffer);
  size_t bufptr = 0;
  const char *value = NULL;
  const char *fullname = NULL, *roomnumber = NULL, *workphone = NULL;
  const char *homephone = NULL, *other = NULL, *homedir = NULL;
  const char *shell = NULL;
  const char *binddn = NULL; /* the user performing the modification */
  MYLDAP_ENTRY *entry;
  MYLDAP_SESSION *newsession;
  char errmsg[BUFLEN_MESSAGE];
  /* read request parameters */
  READ_STRING(fp, username);
  READ_INT32(fp, asroot);
  READ_STRING(fp, password);
  /* read the usermod parameters */
  while (1)
  {
    READ_INT32(fp, param);
    if (param == NSLCD_USERMOD_END)
      break;
    READ_BUF_STRING(fp, value);
    switch (param)
    {
      case NSLCD_USERMOD_FULLNAME:   fullname = value; break;
      case NSLCD_USERMOD_ROOMNUMBER: roomnumber = value; break;
      case NSLCD_USERMOD_WORKPHONE:  workphone = value; break;
      case NSLCD_USERMOD_HOMEPHONE:  homephone = value; break;
      case NSLCD_USERMOD_OTHER:      other = value; break;
      case NSLCD_USERMOD_HOMEDIR:    homedir = value; break;
      case NSLCD_USERMOD_SHELL:      shell = value; break;
      default: /* other parameters are silently ignored */ break;
    }
  }
  /* log call */
  log_setrequest("usermod=\"%s\"", username);
  log_log(LOG_DEBUG, "nslcd_usermod(\"%s\",%s,\"%s\")",
          username, asroot ? "asroot" : "asuser", *password ? "***" : "");
  if (fullname != NULL)
    log_log(LOG_DEBUG, "nslcd_usermod(fullname=\"%s\")", fullname);
  if (roomnumber != NULL)
    log_log(LOG_DEBUG, "nslcd_usermod(roomnumber=\"%s\")", roomnumber);
  if (workphone != NULL)
    log_log(LOG_DEBUG, "nslcd_usermod(workphone=\"%s\")", workphone);
  if (homephone != NULL)
    log_log(LOG_DEBUG, "nslcd_usermod(homephone=\"%s\")", homephone);
  if (other != NULL)
    log_log(LOG_DEBUG, "nslcd_usermod(other=\"%s\")", other);
  if (homedir != NULL)
    log_log(LOG_DEBUG, "nslcd_usermod(homedir=\"%s\")", homedir);
  if (shell != NULL)
    log_log(LOG_DEBUG, "nslcd_usermod(shell=\"%s\")", shell);
  /* write the response header */
  WRITE_INT32(fp, NSLCD_VERSION);
  WRITE_INT32(fp, NSLCD_ACTION_USERMOD);
  /* validate request */
  entry = validate_user(session, username, &rc);
  if (entry == NULL)
  {
    /* for user not found we just say no result, otherwise break the protocol */
    if (rc == LDAP_NO_SUCH_OBJECT)
    {
      WRITE_INT32(fp, NSLCD_RESULT_END);
    }
    return -1;
  }
  /* check if it is a modification as root */
  isroot = (calleruid == 0) && asroot;
  if (asroot)
  {
    if (nslcd_cfg->rootpwmoddn == NULL)
    {
      log_log(LOG_NOTICE, "rootpwmoddn not configured");
      /* we break the protocol */
      return -1;
    }
    binddn = nslcd_cfg->rootpwmoddn;
    /* check if rootpwmodpw should be used */
    if ((*password == '\0') && isroot && (nslcd_cfg->rootpwmodpw != NULL))
    {
      if (strlen(nslcd_cfg->rootpwmodpw) >= sizeof(password))
      {
        log_log(LOG_ERR, "nslcd_pam_pwmod(): rootpwmodpw will not fit in password");
        return -1;
      }
      strcpy(password, nslcd_cfg->rootpwmodpw);
    }
  }
  else
    binddn = myldap_get_dn(entry);
  WRITE_INT32(fp, NSLCD_RESULT_BEGIN);
  /* home directory change requires either root or valid directory */
  if ((homedir != NULL) && (!isroot) && !is_valid_homedir(homedir))
  {
    log_log(LOG_NOTICE, "invalid directory: %s", homedir);
    WRITE_INT32(fp, NSLCD_USERMOD_HOMEDIR);
    WRITE_STRING(fp, "invalid directory");
    homedir = NULL;
  }
  /* shell change requires either root or a valid shell */
  if ((shell != NULL) && (!isroot) && !is_valid_shell(shell))
  {
    log_log(LOG_NOTICE, "invalid shell: %s", shell);
    WRITE_INT32(fp, NSLCD_USERMOD_SHELL);
    WRITE_STRING(fp, "invalid shell");
    shell = NULL;
  }
  /* perform requested changes */
  newsession = get_session(binddn, myldap_get_dn(entry), password, &rc);
  if (newsession != NULL)
  {
    rc = change(newsession, myldap_get_dn(entry), homedir, shell);
    myldap_session_close(newsession);
  }
  /* return response to caller */
  if (rc != LDAP_SUCCESS)
  {
    log_log(LOG_WARNING, "%s: modification failed: %s",
            myldap_get_dn(entry), ldap_err2string(rc));
    mysnprintf(errmsg, sizeof(errmsg) - 1, "change failed: %s", ldap_err2string(rc));
    WRITE_INT32(fp, NSLCD_USERMOD_RESULT);
    WRITE_STRING(fp, errmsg);
    WRITE_INT32(fp, NSLCD_USERMOD_END);
    WRITE_INT32(fp, NSLCD_RESULT_END);
    return 0;
  }
  log_log(LOG_NOTICE, "changed information for %s", myldap_get_dn(entry));
  WRITE_INT32(fp, NSLCD_USERMOD_END);
  WRITE_INT32(fp, NSLCD_RESULT_END);
  return 0;
}
Ejemplo n.º 7
0
int main(int argc, char *argv[]){
	char buffer[64];
	char *c;

#if DEBUG
	printf("[DEBUG MODE]\n");
	printf("Compile: %s %s\n", __DATE__, __TIME__);
#endif

	printf("Version: %d.%d.%d\n", VER_REL, VER_MAJOR, VER_MINOR);
	printf("Database> ");
	dbfile_t *mdb = open_dbfile(get_input(buffer, 32, TRUE));
	commit_db(mdb);

	for(;;){
		printf("valca> ");

		c = get_input(buffer, 64, TRUE);
		if(!strcmp("quit", c)||!strcmp("exit", c)||!strcmp("\\q", c)){
			break;
		}
		if(!strcmp("help", c)){
			printf("COMMANDS:\n");
			printf("COMMIT        Commit file to disk\n");
			printf("COUNT         Show row count\n");
			printf("TRUNCATE      Delete all keys\n");
			printf("UPDATE        Update key value\n");
			printf("INSERT        Insert key\n");
			printf("DELETE \\\n");
			printf("  COLUMN      Delete column\n");
			printf("  ROW         Delete row\n");
			printf("ALTER \\\n");
			printf("  NAME        Change column name\n");
			printf("  LEFT        Shift column left\n");
			printf("  RIGHT       Shift column right\n");
			printf("SELECT        Select value from\n");
			printf("ADD \\\n");
			printf("  COLUMN      Add column\n");
			printf("SHOW \\\n");
			printf("  COLUMNS     Show all columns\n");
			printf("  TREE        Show storage tree\n");
			printf("  STATUS      Show database info\n");
			printf("  TABLE       Show dataset as table\n");
			printf("FREE \\\n");
			printf("  COLUMNS     Columns freelist\n");
			printf("  NODE        Node freelist\n");
			printf("  DATAFIELDS  Payload freelist\n");
			printf("EXIT          Quit the shell\n");
		}
		if(!strcmp("commit", c)){
			commit_db(mdb);
		}
		if(!strcmp("count", c)){
			printf("Total rows: %d\n", mdb->k_cnt);
		}
		if(!strcmp("truncate", c)){
			truncate_root(mdb);
		}
		if(!strcmp("update", c)){
			char tmp[32];
			printf(">psid: ");
			c = get_input(tmp, 32, FALSE);
			int key = atoi(tmp);
			char tmpcolname[32];
			printf(">column: ");
			c = get_input(tmpcolname, 32, FALSE);
			int idx = get_column_idx(mdb, tmpcolname);
			printf(">value: ");
			c = get_input(tmp, 32, FALSE);
			change(mdb, key, (void*)tmp, idx);
		}
		if(!strcmp("insert", c)){
			if(!mdb->c_cnt){
				printf("Cannot insert without column\n");
			}else{
				char tmp[32];
				printf(">psid[%d]: ", mdb->seq_cnt);
				c = get_input(tmp, 32, FALSE);
				int key;
				if(!strlen(tmp)){
					key = mdb->seq_cnt++;
				}else{
					key = atoi(tmp);
				}
				column_t col;
				read_column(mdb, mdb->data.c_root, &col);
				printf(">%s<%s(%d)>: ", col.name, get_datatype_name(col.d_type), col.maxsize);
				c = get_input(tmp, 32, FALSE);
				if(get_datatype(col.d_type).size == -1) tmp[col.maxsize] = '\0';
				if(col.usign) printf("<> %d\n", atoi(tmp));
					//if(atoi())
				if(insert_key(mdb, key, (void*)tmp) == SUCCESS){
					result_t rs = search_key(mdb, key);
					if(rs.rstat == SUCCESS){
						char tmp[32];
						int i = 1;
						while(col.c_next != EMPTY){
							read_column(mdb, col.c_next, &col);
							printf(">%s<%s(%d)>: ", col.name, get_datatype_name(col.d_type), col.maxsize);
							c = get_input(tmp, 32, FALSE);
							add_field(mdb, rs.fpos, rs.idx, (void*)tmp, i);
							i++;
						}
					}
				}
			}
		}
		if(!strcmp("delete", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("column", c)){
				char tmpcolname[32];
				printf(">column: ");
				c = get_input(tmpcolname, 32, FALSE);
				int idx = get_column_idx(mdb, tmpcolname);
				delete_column(mdb, idx);
			}
			if(!strcmp("row", c)){
				char tmp[32];
				printf(">psid: ");
				c = get_input(tmp, 32, FALSE);
				int key = atoi(tmp);
				result_t rs = search_key(mdb, key);
				if(rs.rstat == SUCCESS){
					int i;
					for(i=mdb->c_cnt; i>1; i--){
						delete_field(mdb, rs.fpos, rs.idx, (i-1));
					}
					delete_key(mdb, key);
				}
			}
		}
		if(!strcmp("alter", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("name", c)){
				printf(">column: ");
				char tmpcolname[32];
				c = get_input(tmpcolname, 32, FALSE);
				int idx = get_column_idx(mdb, tmpcolname);
				printf(">new name: ");
				c = get_input(tmpcolname, 32, FALSE);
				rename_column(mdb, tmpcolname, idx);
			}
			if(!strcmp("left", c)){
				char tmpcolname[32];
				printf(">column: ");
				c = get_input(tmpcolname, 32, FALSE);
				int idx = get_column_idx(mdb, tmpcolname);
				shift_column_left(mdb, idx);
			}
			if(!strcmp("right", c)){
				char tmpcolname[32];
				printf(">column: ");
				c = get_input(tmpcolname, 32, FALSE);
				int idx = get_column_idx(mdb, tmpcolname);
				shift_column_right(mdb, idx);
			}
		}
		if(!strcmp("select", c)){
			printf(">");
			char tmp[16];
			printf(">psid: ");
			c = get_input(tmp, 32, FALSE);
			int key = atoi(tmp);
			result_t rs = search_key(mdb, key);
			if(rs.rstat == SUCCESS){
				found(mdb, rs.fpos, rs.idx);
			}
		}
		if(!strcmp("add", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("column", c)){
				char colname[32];
				DTYPE type;
				int size;
				bool usign = FALSE;
				int idx;
				printf(">name: ");
				c = get_input(colname, 32, FALSE);
				printf(">type: ");
				char tmptype[32];
				c = get_input(tmptype, 32, FALSE);
				type = get_datatype_idx(tmptype);
				if(type == EMPTY){
					printf("Unkown datatype\n");
					continue;
				}
				size = get_datatype(type).size;
				if(size == EMPTY){
					printf(">size: ");
					char tmpsize[16];
					c = get_input(tmpsize, 16, FALSE);
					size = atoi(tmpsize);
				}
				if(get_datatype(type).signness){
					printf(">unsigned: ");
					char tmpsign[4];
					c = get_input(tmpsign, 4, FALSE);
					if(!strcmp("y", tmpsign)){
						usign = TRUE;
					}
				}
				printf(">before: ");
				char tmpcolname[32];
				c = get_input(tmpcolname, 32, FALSE);
				idx = get_column_idx(mdb, tmpcolname);
				add_column(mdb, colname, size, type, usign, idx);
			}
		}
		if(!strcmp("show", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("columns", c)){
				printf("Idx   Offset   Psid         Columnname  Size      Type    Unsigned    Next\n");
				printf("--------------------------------------------------------------------------\n");
				print_column(mdb, mdb->data.c_root, 0);
			}
			if(!strcmp("tree", c)){
				print_tree(mdb, mdb->data.n_root, 0);
			}
			if(!strcmp("status", c)){
				print_status(mdb);
			}
			if(!strcmp("table", c)){
				print_table(mdb);
			}
		}
		if(!strcmp("free", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("columns", c)){
				printf("Idx   Offset   Psid         Columnname  Size      Type    Unsigned    Next\n");
				printf("--------------------------------------------------------------------------\n");
				print_column(mdb, mdb->data.c_free, 0);
			}
			if(!strcmp("node", c)){
				print_tree(mdb, mdb->data.n_free, 0);
			}
			if(!strcmp("datafields", c)){
				print_datafield(mdb, mdb->data.d_free);
			}
		}
	}

	commit_db(mdb);
	close_dbfile(mdb->vfp);
	close_db(mdb);

	return 0;
}
Ejemplo n.º 8
0
int alloc_empty_btree(struct btree *btree)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	struct sb *sb = btree->sb;
	struct buffer_head *rootbuf = new_node(btree);
	if (IS_ERR(rootbuf))
		goto error;
	struct buffer_head *leafbuf = new_leaf(btree);
	if (IS_ERR(leafbuf))
		goto error_leafbuf;

	assert(!has_root(btree));
	struct bnode *rootnode = bufdata(rootbuf);
	block_t rootblock = bufindex(rootbuf);
	block_t leafblock = bufindex(leafbuf);
	trace("root at %Lx", rootblock);
	trace("leaf at %Lx", leafblock);
	bnode_init_root(rootnode, 1, leafblock, 0, 0);
	log_bnode_root(sb, rootblock, 1, leafblock, 0, 0);
	log_balloc(sb, leafblock, 1);

	mark_buffer_unify_non(rootbuf);
	blockput(rootbuf);
	mark_buffer_dirty_non(leafbuf);
	blockput(leafbuf);

	btree->root = (struct root){ .block = rootblock, .depth = 1 };
	tux3_mark_btree_dirty(btree);

	return 0;

error_leafbuf:
	(btree->ops->bfree)(sb, bufindex(rootbuf), 1);
	blockput(rootbuf);
	rootbuf = leafbuf;
error:
	return PTR_ERR(rootbuf);
}

/* FIXME: right? and this should be done by btree_chop()? */
int free_empty_btree(struct btree *btree)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	struct btree_ops *ops = btree->ops;

	if (!has_root(btree))
		return 0;

	assert(btree->root.depth == 1);
	struct sb *sb = btree->sb;
	struct buffer_head *rootbuf = vol_bread(sb, btree->root.block);
	if (!rootbuf)
		return -EIO;
	assert(bnode_sniff(bufdata(rootbuf)));
	/* Make btree has no root */
	btree->root = no_root;
	tux3_mark_btree_dirty(btree);

	struct bnode *rootnode = bufdata(rootbuf);
	assert(bcount(rootnode) == 1);
	block_t leaf = be64_to_cpu(rootnode->entries[0].block);
	struct buffer_head *leafbuf = vol_find_get_block(sb, leaf);

	if (leafbuf && !leaf_need_redirect(sb, leafbuf)) {
		/*
		 * This is redirected leaf. So, in here, we can just
		 * cancel leaf_redirect by bfree(), instead of
		 * defered_bfree().
		 */
		bfree(sb, leaf, 1);
		log_leaf_free(sb, leaf);
		assert(ops->leaf_can_free(btree, bufdata(leafbuf)));
		blockput_free(sb, leafbuf);
	} else {
		defer_bfree(&sb->defree, leaf, 1);
		log_bfree(sb, leaf, 1);
		if (leafbuf) {
			assert(ops->leaf_can_free(btree, bufdata(leafbuf)));
			blockput(leafbuf);
		}
	}

	if (!bnode_need_redirect(sb, rootbuf)) {
		/*
		 * This is redirected bnode. So, in here, we can just
		 * cancel bnode_redirect by bfree(), instead of
		 * defered_bfree().
		 */
		bfree(sb, bufindex(rootbuf), 1);
		log_bnode_free(sb, bufindex(rootbuf));
		blockput_free_unify(sb, rootbuf);
	} else {
		defer_bfree(&sb->deunify, bufindex(rootbuf), 1);
		log_bfree_on_unify(sb, bufindex(rootbuf), 1);
		blockput(rootbuf);
	}

	return 0;
}

int replay_bnode_redirect(struct replay *rp, block_t oldblock, block_t newblock)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	struct sb *sb = rp->sb;
	struct buffer_head *newbuf, *oldbuf;
	int err = 0;

	newbuf = vol_getblk(sb, newblock);
	if (!newbuf) {
		err = -ENOMEM;	/* FIXME: error code */
		goto error;
	}
	oldbuf = vol_bread(sb, oldblock);
	if (!oldbuf) {
		err = -EIO;	/* FIXME: error code */
		goto error_put_newbuf;
	}
	assert(bnode_sniff(bufdata(oldbuf)));

	memcpy(bufdata(newbuf), bufdata(oldbuf), bufsize(newbuf));
	mark_buffer_unify_atomic(newbuf);

	blockput(oldbuf);
error_put_newbuf:
	blockput(newbuf);
error:
	return err;
}

int replay_bnode_root(struct replay *rp, block_t root, unsigned count,
		      block_t left, block_t right, tuxkey_t rkey)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	struct sb *sb = rp->sb;
	struct buffer_head *rootbuf;

	rootbuf = vol_getblk(sb, root);
	if (!rootbuf)
		return -ENOMEM;
	bnode_buffer_init(rootbuf);

	bnode_init_root(bufdata(rootbuf), count, left, right, rkey);

	mark_buffer_unify_atomic(rootbuf);
	blockput(rootbuf);

	return 0;
}

/*
 * Before this replay, replay should already dirty the buffer of src.
 * (e.g. by redirect)
 */
int replay_bnode_split(struct replay *rp, block_t src, unsigned pos,
		       block_t dst)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	struct sb *sb = rp->sb;
	struct buffer_head *srcbuf, *dstbuf;
	int err = 0;

	srcbuf = vol_getblk(sb, src);
	if (!srcbuf) {
		err = -ENOMEM;	/* FIXME: error code */
		goto error;
	}

	dstbuf = vol_getblk(sb, dst);
	if (!dstbuf) {
		err = -ENOMEM;	/* FIXME: error code */
		goto error_put_srcbuf;
	}
	bnode_buffer_init(dstbuf);

	bnode_split(bufdata(srcbuf), pos, bufdata(dstbuf));

	mark_buffer_unify_non(srcbuf);
	mark_buffer_unify_atomic(dstbuf);

	blockput(dstbuf);
error_put_srcbuf:
	blockput(srcbuf);
error:
	return err;
}

/*
 * Before this replay, replay should already dirty the buffer of bnodeblock.
 * (e.g. by redirect)
 */
static int replay_bnode_change(struct sb *sb, block_t bnodeblock,
			       u64 val1, u64 val2,
			       void (*change)(struct bnode *, u64, u64))
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	struct buffer_head *bnodebuf;

	bnodebuf = vol_getblk(sb, bnodeblock);
	if (!bnodebuf)
		return -ENOMEM;	/* FIXME: error code */

	struct bnode *bnode = bufdata(bnodebuf);
	change(bnode, val1, val2);

	mark_buffer_unify_non(bnodebuf);
	blockput(bnodebuf);

	return 0;
}

static void add_func(struct bnode *bnode, u64 child, u64 key)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	struct index_entry *entry = bnode_lookup(bnode, key) + 1;
	bnode_add_index(bnode, entry, child, key);
}

int replay_bnode_add(struct replay *rp, block_t parent, block_t child,
		     tuxkey_t key)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	return replay_bnode_change(rp->sb, parent, child, key, add_func);
}

static void update_func(struct bnode *bnode, u64 child, u64 key)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	struct index_entry *entry = bnode_lookup(bnode, key);
	assert(be64_to_cpu(entry->key) == key);
	entry->block = cpu_to_be64(child);
}

int replay_bnode_update(struct replay *rp, block_t parent, block_t child,
			tuxkey_t key)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	return replay_bnode_change(rp->sb, parent, child, key, update_func);
}

int replay_bnode_merge(struct replay *rp, block_t src, block_t dst)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	struct sb *sb = rp->sb;
	struct buffer_head *srcbuf, *dstbuf;
	int err = 0, ret;

	srcbuf = vol_getblk(sb, src);
	if (!srcbuf) {
		err = -ENOMEM;	/* FIXME: error code */
		goto error;
	}

	dstbuf = vol_getblk(sb, dst);
	if (!dstbuf) {
		err = -ENOMEM;	/* FIXME: error code */
		goto error_put_srcbuf;
	}

	ret = bnode_merge_nodes(sb, bufdata(dstbuf), bufdata(srcbuf));
	assert(ret == 1);

	mark_buffer_unify_non(dstbuf);
	mark_buffer_unify_non(srcbuf);

	blockput(dstbuf);
error_put_srcbuf:
	blockput(srcbuf);
error:
	return err;
}

static void del_func(struct bnode *bnode, u64 key, u64 count)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	struct index_entry *entry = bnode_lookup(bnode, key);
	assert(be64_to_cpu(entry->key) == key);
	bnode_remove_index(bnode, entry, count);
}

int replay_bnode_del(struct replay *rp, block_t bnode, tuxkey_t key,
		     unsigned count)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	return replay_bnode_change(rp->sb, bnode, key, count, del_func);
}

static void adjust_func(struct bnode *bnode, u64 from, u64 to)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	struct index_entry *entry = bnode_lookup(bnode, from);
	assert(be64_to_cpu(entry->key) == from);
	entry->key = cpu_to_be64(to);
}

int replay_bnode_adjust(struct replay *rp, block_t bnode, tuxkey_t from,
			tuxkey_t to)
{
	if(DEBUG_MODE_K==1)
	{
		printf("\t\t\t\t%25s[K]  %25s  %4d  #in\n",__FILE__,__func__,__LINE__);
	}
	return replay_bnode_change(rp->sb, bnode, from, to, adjust_func);
}
Ejemplo n.º 9
0
void GraphicsMan::updateScreen(Graphics::Surface *source) {
	_vm->_system->copyRectToScreen((byte *)source->getBasePtr(0, 0), 640, 0, 80, 640, 320);
	change();
}
Ejemplo n.º 10
0
int main(int argc, char* argv[])
{
	int i, j, b;

	if (argc < 2) {
		help();
		exit(EXIT_SUCCESS);
	}

	if (strcmp(argv[1], "generate") == 0) {
		int disk, file, size;

		if (argc != 6) {
			/* LCOV_EXCL_START */
			help();
			exit(EXIT_FAILURE);
			/* LCOV_EXCL_STOP */
		}

		seed = atoi(argv[2]);
		disk = atoi(argv[3]);
		file = atoi(argv[4]);
		size = atoi(argv[5]);

		for(i=0;i<disk;++i) {
			for(j=0;j<file;++j) {
				if (j == 0)
					generate(i+1, size);
				else if (j == 1)
					generate(i+1, 0);
				else
					generate(i+1, rnd(size));
			}
		}
	} else if (strcmp(argv[1], "damage") == 0 || strcmp(argv[1], "write") == 0) {
		int fail, size;
		int silent_error = strcmp(argv[1], "damage") == 0;

		if (argc < 6) {
			/* LCOV_EXCL_START */
			help();
			exit(EXIT_FAILURE);
			/* LCOV_EXCL_STOP */
		}

		seed = atoi(argv[2]);
		fail = atoi(argv[3]);
		size = atoi(argv[4]);
		b = 5;

		/* sort the file names */
		qsort(&argv[b], argc - b,  sizeof(argv[b]), qsort_strcmp);

		for(i=b;i<argc;++i) {
			for(j=0;j<fail;++j) {
				writ(argv[i], rndnotzero(size), silent_error);
			}
		}
	} else if (strcmp(argv[1], "append") == 0) {
		int size;

		if (argc < 5) {
			/* LCOV_EXCL_START */
			help();
			exit(EXIT_FAILURE);
			/* LCOV_EXCL_STOP */
		}

		seed = atoi(argv[2]);
		size = atoi(argv[3]);
		b = 4;

		/* sort the file names */
		qsort(&argv[b], argc - b,  sizeof(argv[b]), qsort_strcmp);

		for(i=b;i<argc;++i) {
			append(argv[i], rndnotzero(size));
		}
	} else if (strcmp(argv[1], "truncate") == 0) {
		int size;

		if (argc < 5) {
			/* LCOV_EXCL_START */
			help();
			exit(EXIT_FAILURE);
			/* LCOV_EXCL_STOP */
		}

		seed = atoi(argv[2]);
		size = atoi(argv[3]);
		b = 4;

		/* sort the file names */
		qsort(&argv[b], argc - b,  sizeof(argv[b]), qsort_strcmp);

		for(i=b;i<argc;++i) {
			truncat(argv[i], rnd(size));
		}
	} else if (strcmp(argv[1], "change") == 0) {
		int size;

		if (argc < 5) {
			/* LCOV_EXCL_START */
			help();
			exit(EXIT_FAILURE);
			/* LCOV_EXCL_STOP */
		}

		seed = atoi(argv[2]);
		size = atoi(argv[3]);
		b = 4;

		/* sort the file names */
		qsort(&argv[b], argc - b,  sizeof(argv[b]), qsort_strcmp);

		for(i=b;i<argc;++i) {
			change(argv[i], rnd(size));
		}
	} else {
		/* LCOV_EXCL_START */
		help();
		exit(EXIT_FAILURE);
		/* LCOV_EXCL_STOP */
	}

	return 0;
}
Ejemplo n.º 11
0
void RKSettingsModuleOutput::boxChanged () {
	RK_TRACE (SETTINGS);
	change ();
	auto_raise_box->setEnabled (auto_show_box->isChecked ());
	graphics_jpg_quality_box->setEnabled (graphics_type_box->itemData (graphics_type_box->currentIndex ()).toString () == "\"JPG\"");
}
Ejemplo n.º 12
0
double perform_trial(int numpoints, int dimension, position *node_location) {

  init_heap_vars(numpoints, (numpoints * (numpoints - 1)) / 2);  // initialize the heap variables
  node *heap = (node *) malloc(sizeof(node) * numpoints);  // create heap
  int location[numpoints];  // create array, indexed by name, that remembers the index of each element in the heap
  node *graph = (node *) malloc(sizeof(node) * numpoints);  // initialize graph
    
  /*
   * (i)     create struct node for each graph node
   * (ii)    intialize distance values 
   * (iii)   create V-S list
   * (iv)    initialize heap to empty
   * (v)     initialize array to hold distnace values
   */
     
  for(int i = 0; i < numpoints; i++) {   
    graph[i].name = i;  // name each node
    graph[i].dist = -1;  // here all edges are positive so we'll let -1 = infinity
    insert_list(i);  // initially every node is in V-S, list.c maintains a LL with V-S
    location[i] = -1;  // initially no node is in the heap
    heap[i].dist = 100000;  // set heap to empty
    heap[i].name = 100000;
  }  
    
  
  graph[0].dist = 0;  // set distance to first node to 0
  insert(graph[0], heap, location);  // insert first node into the heap

  while(size_heap() != 0) {
    node v = delete_min(heap, location);  // take smallest node from the heap
    // ensure heap wasn't somehow empty
    if(v.dist == -100.) {
      break;
    } 
    delete_list(v.name);  // delete the node from V-S
    list_node *ptr = get_head();  // get head node from V-S
    while(ptr != NULL) {
      int current_name = ptr->name;  // get name of current element
            
      // found a node, check for update
       double check_val = 0;
      // just generate a random edge since each edge is only examined once
      if(dimension == 1) {
        //check_val = (double)rand()/(double)RAND_MAX;
        check_val = fabs(node_location[v.name].x-node_location[current_name].x);
      } else if(dimension == 2) {
        double parameter = pow((node_location[v.name].x-node_location[current_name].x), 2.)
                           + pow((node_location[v.name].y-node_location[current_name].y), 2.);
        check_val = sqrt(parameter);
      } else if(dimension == 3) {
        double parameter = pow((node_location[v.name].x-node_location[current_name].x), 2.)
                           + pow((node_location[v.name].y-node_location[current_name].y), 2.)
                           + pow((node_location[v.name].z-node_location[current_name].z), 2.);
        check_val = sqrt(parameter);
      } else if(dimension == 4) {
        double parameter = pow((node_location[v.name].x-node_location[current_name].x), 2.)
                           + pow((node_location[v.name].y-node_location[current_name].y), 2.)
                           + pow((node_location[v.name].z-node_location[current_name].z), 2.)
                           + pow((node_location[v.name].w-node_location[current_name].w), 2.);
        check_val = sqrt(parameter);
      }
                
      // check if we need to update
      if(((graph[current_name].dist > check_val) || graph[current_name].dist == -1)) {
        // perform update
        graph[current_name].dist = check_val;
        // insert/update element in the heap
        node change_node = graph[current_name];
        change(change_node, heap, location);
      }
      ptr = ptr->next;
    }  
  }

  // sum and print the edges in the MST
  double sum = sum_MST(numpoints, graph);

  free(heap);  // free heap
  free(graph);  // free graph
  free_list();  // free list

  return sum;

}
Ejemplo n.º 13
0
void Blink1Input::setArg2(const QString &arg2)
{
    marg2 = arg2;
    emit change();
}
Ejemplo n.º 14
0
void Blink1Input::setArg1(const QString &arg1)
{
    marg1 = arg1;
    emit change();
}
Ejemplo n.º 15
0
void Blink1Input::setType(const QString &type)
{
    mtype = type;
    emit change();
}
Ejemplo n.º 16
0
int main(int argc, char * argv[]) {
    nameOfFile = argv[1];
    data = fopen(nameOfFile, "a+");
    if (data == NULL)
        perror("Error");
    phBook.size = 0;
    phBook.contact = malloc(phBook.size * sizeof(Note));
    freeInd.top = 0;
    freeInd.size = 1;
    freeInd.num = (int *)malloc(freeInd.size * sizeof(int));
    rewind(data);
    int id;
    while (fscanf(data, "%d ", &id) == 1) {
        phBook.size++;
        phBook.contact = realloc(phBook.contact, phBook.size * sizeof(Note));
        phBook.contact[phBook.size - 1].id = id;
        phBook.contact[phBook.size - 1].name = getword(data);
        phBook.contact[phBook.size - 1].nmbr = getword(data);
    }
    if (phBook.size == 0)
        currentID = 1;
    else
        currentID = phBook.contact[phBook.size - 1].id + 1;
    char *cmd, *name, *number, *input;
    while (42) {
        cmd = getword(stdin);
        if (!strcmp(cmd, "find")) {
            input = getword(stdin);
            if (inputIsCorrect(input))
                find(input);
            free(input);
        }
        else if (!strcmp(cmd, "create")) {
            name = getword(stdin);
            number = getword(stdin);
            if (inputIsCorrect(name) && inputIsCorrect(number))
                create(name, number);
        }
        else if (!strcmp(cmd, "delete")) {
            scanf("%d\n", &id);
            del(id);
        }
        else if (!strcmp(cmd, "change")) {
            scanf("%d ", &id);
            cmd = getword(stdin);
            input = getword(stdin);
            if (inputIsCorrect(input))
                change(id, cmd, input);
            free(input);
        }
        else if (!strcmp(cmd, "exit")) {
            fclose(data);
            free(phBook.contact);
            free(freeInd.num);
            return 0;
        }
        else {
            printf("Unknown command.\n");
        }
        free(cmd);
        fflush(stdout);
    }
}
Ejemplo n.º 17
0
void LayerPropertyEdit::undo(const LayerRef &layer)
{
	change(layer);
}
Ejemplo n.º 18
0
void PageCache::pruneToSizeNow(unsigned size, PruningReason pruningReason)
{
    TemporaryChange<unsigned> change(m_maxSize, size);
    prune(pruningReason);
}
Ejemplo n.º 19
0
task main(){
  checkBTLinkConnected();
  StartTask(sendMessages);
  change(6,8,6,8,100,150,100,200);
  wait1Msec(3000);
  change(10,13,6,8,200,0,100,200);
  wait1Msec(1000);
  change(6,8,6,8,100,150,100,200);
  wait1Msec(1000);
  change(6,13,6,8,200,0,100,200);
  wait1Msec(1000);
  change(6,8,6,8,100,150,100,200);
  wait1Msec(1000);
  change(3,13,6,8,200,0,100,200);
  wait1Msec(1000);

  change(6,8,6,8,100,150,100,200);
  wait1Msec(1500);

  change(6,8,10,13,100,150,200,255);
  wait1Msec(1000);
  change(6,8,6,8,100,150,100,200);
  wait1Msec(1000);
  change(6,8,6,13,100,150,200,255);
  wait1Msec(1000);
  change(6,8,6,8,100,150,100,200);
  wait1Msec(1000);
  change(6,8,3,13,100,150,200,255);
  wait1Msec(1000);

  change(6,8,6,8,100,0,100,200);
  wait1Msec(2000);
  PlaySound(soundDownwardTones);
  change(6,10,6,10,100,0,100,255);
  wait1Msec(1500);
  for(int i = 0; i<=10; ++i){
    change(12,10,12,10,200,0,200,255);
    wait1Msec(1000);
    change(6,10,6,10,100,0,100,255);
    wait1Msec(1000);
  }

  change(0,8,0,8,200,0,200,0);
  wait1Msec(5000);
}
Ejemplo n.º 20
0
void
TileMap::change_at(const Vector& pos, uint32_t newtile)
{
  Vector xy = (pos - offset) / 32;
  change(int(xy.x), int(xy.y), newtile);
}
Ejemplo n.º 21
0
LH_CursorController::LH_CursorController()
{
    updating_link_data_ = false;
    setup_link_json_data_ = new LH_Qt_QString(this, "Cursor Data", "", LH_FLAG_NOSAVE_DATA | LH_FLAG_NOSINK | LH_FLAG_READONLY | LH_FLAG_HIDEVALUE /*| LH_FLAG_HIDDEN*/);
    setup_link_json_data_->setHelp("<p>This field holds the data for this cursor; all cursor objects by default link themselves to \"Primary Cursor\".</p>"
                                   "<p>You only need change the name of this link if your layout needs more than one cursor.");

    setup_link_postback_ = new LH_Qt_QString(this, "Cursor Postback", "", LH_FLAG_NOSAVE_DATA | LH_FLAG_NOSOURCE | LH_FLAG_READONLY | LH_FLAG_HIDDEN);

    setup_link_current_pos = new LH_Qt_QString(this, "Cursor Position", "", LH_FLAG_NOSAVE_DATA | LH_FLAG_NOSINK | LH_FLAG_READONLY  /* | LH_FLAG_HIDDEN*/);
    setup_link_current_pos->setHelp("<p>Displays the coordinates of the cursor at present, as well as whether the controller is currently active:</p>"
                                    "<p>(x,y) [active]</p>"
                                    "<p>This is mainly provided for advanced layout designers if they want to link something to the current cursor position.</p>");

    setup_link_selected_pos = new LH_Qt_QString(this, "Selected Position", "", LH_FLAG_NOSAVE_DATA | LH_FLAG_NOSINK | LH_FLAG_READONLY  /* | LH_FLAG_HIDDEN*/);
    setup_link_selected_pos->setHelp("<p>Displays the coordinates of the selected point at present, as well as whether the controller is currently active:</p>"
                                     "<p>(x,y) [active]</p>"
                                     "<p>This is mainly provided for advanced layout designers if they want to link something to the current selection position.</p>");

    //setup_link_postback_->setLinkFilter("CursorPostback");
    //setup_link_json_data_->setLinkFilter("Cursors");

    setup_cursor_active_ = new LH_Qt_bool(this, "Active", cursor_data_.active, LH_FLAG_NOSAVE_DATA | LH_FLAG_NOSINK | LH_FLAG_READONLY | LH_FLAG_HIDDEN);
    setup_cursor_sel_x_ = new LH_Qt_int(this, "X (Selected)", cursor_data_.x, LH_FLAG_NOSAVE_DATA | LH_FLAG_NOSINK | LH_FLAG_READONLY | LH_FLAG_HIDDEN);
    setup_cursor_sel_y_ = new LH_Qt_int(this, "Y (Selected)", cursor_data_.y, LH_FLAG_NOSAVE_DATA | LH_FLAG_NOSINK | LH_FLAG_READONLY | LH_FLAG_HIDDEN);
    setup_cursor_x_ = new LH_Qt_int(this, "X (Current)", cursor_data_.x, LH_FLAG_NOSAVE_DATA | LH_FLAG_NOSINK | LH_FLAG_READONLY | LH_FLAG_HIDDEN);
    setup_cursor_y_ = new LH_Qt_int(this, "Y (Current)", cursor_data_.y, LH_FLAG_NOSAVE_DATA | LH_FLAG_NOSINK | LH_FLAG_READONLY | LH_FLAG_HIDDEN);

    new LH_Qt_QString(this, "hr1", "<hr>", LH_FLAG_NOSOURCE | LH_FLAG_NOSINK | LH_FLAG_HIDETITLE, lh_type_string_html );

    setup_coordinate_ = new LH_Qt_QString(this, "Coordinate", "1,1", LH_FLAG_NOSAVE_DATA | LH_FLAG_READONLY | LH_FLAG_FIRST | LH_FLAG_HIDDEN);
    setup_coordinate_->setHelp("The current cursor location.");

    cursorModes.append((cursorMode){smSelectDeselect, true , "Activate, Move & Select / Deselect"});
    cursorModes.append((cursorMode){smSelect        , true , "Activate, Move & Select Only (one is always selected)"});
    cursorModes.append((cursorMode){smNone          , true , "Activate & Move Only (Highlighted option is selected)"});
    cursorModes.append((cursorMode){smNone          , false, "Move Only (Highlighted option is selected, always activated)"});
    cursorModes.append((cursorMode){smSelectDeselect, false, "Move & Select / Deselect Only (Always activated)"});
    cursorModes.append((cursorMode){smSelect        , false, "Move & Select Only (Always activated)"});

    //cursor_data_ = (cursorData){1,1,false,0,0,false,0,0,false,false,0,0,(bounds){(minmax){0,0},(minmax){0,0}}};

    QStringList modeNames = QStringList();
    foreach(cursorMode cm, cursorModes) modeNames.append(cm.description);
    setup_mode_ = new LH_Qt_QStringList(this,"Cursor Mode",modeNames,LH_FLAG_AUTORENDER);
    setup_mode_->setHelp("This allows the user to select how the cursor should behave. Each cursor mode is a combination of several options:<br/>"
                         "<br/>"
                         "<ul>"
                         "<li><b>Activate</b></br>"
                         "If a mode includes \"activation\" then in it's default state the cursor is hidden and nothing happens when using the movement or selection keys. Insetad the user must first press the activation key to display the cursor. Whilst active the cursor is visible, can be moved and, if appropriate, items can be selected and deselected. If activation is not included in the mode, then the cursor is assumed to always be active.</li>"
                         "<li><b>Select</b></br>"
                         "For modes that include selecting, the user must first move the cursor over the desired option and then press the select key before anything happens. If a mode does not include selection, then simply moving the cursor changes the selection immediately.</li>"
                         "</li>"
                         "<li><b>Deselect</b></br>"
                         "Some modes have select/deselect behaviour, specified by this option. With this ability the user can \"turn off\" everything; without it there will always be one item selected.</li>"
                         "</li>"
                         "</ul>");
    connect( setup_mode_, SIGNAL(changed()), this, SLOT(changeMode()) );

    setup_boundry_ = new LH_Qt_QString(this,"Boundries","1,1,3,3",0);
    setup_boundry_->setHelp("This box should contain the borders of the \"box\" the cusror can move in.</br></br>The format is [left],[top],[right],[bottom] <br/><br/>e.g.:<br/>\"1,1,1,4\" would denote a box one column wide and four rows high<br/>\"1,1,3,3\" would be a square of three columns and three rows.");
    connect( setup_boundry_, SIGNAL(changed()), this, SLOT(changeBounds()) );
    setup_boundry_loop_ = new LH_Qt_bool(this, "Loop at edges", false);
    setup_boundry_loop_->setHelp("By default when at the furthest edge of the box the cursor stops. Ticking this however will change that so that moving off one edge will bring the cursor back in on the opposite side.");

    setup_invalid_coordinates_ = new LH_Qt_QString(this,"Invalid Points\n(x,y;x,y;x,y)","",0);
    setup_invalid_coordinates_->setHelp("If you wish to create a \"void\" in the cusrsor space, this allows you to do so. List all the points here that the cursor is not allowed to land on and it will be prevented from doing so either by jumping over the invlid points to the next valid one or simply by blocking its movement.<br/><br/>The format is [x1],[y1];[x2],[y2];[x3][y3]; etc...<br/>e.g.: for the boundry \"1,1,2,5\" the invalid points \"1,2;1,3;1,4\" would prevent the cursor landing on any of the top three middle cells, creating a \"U\"-like shape.");
    setup_jump_invalid_ = new LH_Qt_bool(this, "Jump over invalid points", true);
    setup_jump_invalid_->setHelp("By default when the cursor tries to move onto an invlid point it \"jumps\" the cell in question, and keeps moving in the same direction until reaching one where it is allowed to be. Alternatively, checking this box will prevent this, turning invalid points into \"walls\" that have to be moved around manually.");

    setup_move_up_ = new LH_Qt_InputState(this,"Up","",0);
    setup_move_up_->setHelp("The key used to move the cursor up, usually the up key from the LCD control");
    connect( setup_move_up_, SIGNAL(input(QString,int,int)), this, SLOT(doMoveUp(QString,int,int)) );

    setup_move_down_ = new LH_Qt_InputState(this,"Down","",0);
    setup_move_down_->setHelp("The key used to move the cursor down, usually the down key from the LCD control");
    connect( setup_move_down_, SIGNAL(input(QString,int,int)), this, SLOT(doMoveDown(QString,int,int)) );

    setup_move_left_ = new LH_Qt_InputState(this,"Left","",0);
    setup_move_left_->setHelp("The key used to move the cursor left, usually the left key from the LCD control");
    connect( setup_move_left_, SIGNAL(input(QString,int,int)), this, SLOT(doMoveLeft(QString,int,int)) );

    setup_move_right_ = new LH_Qt_InputState(this,"Right","",0);
    setup_move_right_->setHelp("The key used to move the cursor right, usually the right key from the LCD control");
    connect( setup_move_right_, SIGNAL(input(QString,int,int)), this, SLOT(doMoveRight(QString,int,int)) );

    setup_select_ = new LH_Qt_InputState(this,"Select","",0);
    setup_select_->setHelp("The key used to select the currently highlighted option, usually the Ok key from the LCD control");
    connect( setup_select_, SIGNAL(input(QString,int,int)), this, SLOT(doSelect(QString,int,int)) );

    setup_reselect_ = new LH_Qt_InputState(this,"Reselect","",0);
    setup_reselect_->setHelp("The key used to reselect the previously selected highlighted option. Usually this is unused, but is very useful for menu layouts where it acts as a \"return to last layout\" (or cancel) command");
    connect( setup_reselect_, SIGNAL(input(QString,int,int)), this, SLOT(doReselect(QString,int,int)) );

    setup_activate_ = new LH_Qt_InputState(this,"Enable","",0);
    setup_activate_->setHelp("The key used to activate the cursor control");
    connect( setup_activate_, SIGNAL(input(QString,int,int)), this, SLOT(doActivate(QString,int,int)) );

    setup_persistent_ = new LH_Qt_bool(this,"Persistent Selection",false);
    setup_persistent_->setHelp("Ticking this box will cause the system to automatically recall the cursor's last position whether you save the layout or not.<br/><br/>This is mainly of use within menu layouts and allows the menu to open with the last selected option still highlighted.");
    setup_persistent_autoselect_ = new LH_Qt_bool(this,"Auto-reselect",false, LH_FLAG_HIDDEN);
    setup_persistent_autoselect_->setHelp("When recovering a persited selection, this option determins if the option is merely highlighed (i.e. the cursor is positioned on it) or if the option is actually selected.");
    setup_persistent_file_ = new LH_Qt_QFileInfo(this, "Persistence File", QFileInfo(), LH_FLAG_HIDDEN);
    setup_persistent_file_->setHelp("The file in which to save the persisted location.<br/><br/>Note that you can use this to make serveral layouts work together as though they were all parts of the same layout by pointing them all to this file, thus causing the cursor position to persist accross them.");

#ifdef ENABLE_VIRTUAL_CURSOR_KEYS
    setup_virtual_keys_ = new LH_Qt_html(this, 0, LH_FLAG_NOSOURCE | LH_FLAG_NOSINK | LH_FLAG_LAST );
    setup_virtual_keys_->setTitle("<hr><center><table>"
                                 "<tr><td>  </td><td style='background-color:silver;'><center><a href='up'>[  Up  ]</a></center></td><td>  </td><td>         </td><td style='background-color:silver;'><center><a href='act'>[ Act ]</a></center></td></tr>"
                                 "<tr><td style='background-color:silver;'><center><a href='left'>[Left]</a></center></td><td style='background-color:silver;'><center><a href='sel'>[  OK  ]</a></center></td><td style='background-color:silver;'><center><a href='right'>[Right]</a></center></td><td>  </td></tr>"
                                 "<tr><td>  </td><td style='background-color:silver;'><center><a href='down'>[Down]</a></center></td><td>  </td><td>  </td><td style='background-color:silver;'><center><a href='resel'>[  Re  ]</a></center></td></tr>"
                                 "</table></center>");
    connect(setup_virtual_keys_, SIGNAL(change(QString)), this, SLOT(virtualKeyPress(QString)) );
#endif

    connect(setup_link_postback_,SIGNAL(set()),this,SLOT(processPostback()));
    connect(setup_link_postback_,SIGNAL(changed()),this,SLOT(processPostback()));
    connect(setup_persistent_, SIGNAL(changed()), this, SLOT(changePersistent()));
    connect(setup_persistent_file_, SIGNAL(changed()), this, SLOT(loadPersistedSelection()));

    connect(setup_cursor_active_, SIGNAL(changed()), this, SLOT(changeCursorData()));
    connect(setup_cursor_sel_x_, SIGNAL(changed()), this, SLOT(changeCursorData()));
    connect(setup_cursor_sel_y_, SIGNAL(changed()), this, SLOT(changeCursorData()));
    connect(setup_cursor_x_, SIGNAL(changed()), this, SLOT(changeCursorData()));
    connect(setup_cursor_y_, SIGNAL(changed()), this, SLOT(changeCursorData()));

    connect(setup_cursor_active_, SIGNAL(set()), this, SLOT(changeCursorData()));
    connect(setup_cursor_sel_x_, SIGNAL(set()), this, SLOT(changeCursorData()));
    connect(setup_cursor_sel_y_, SIGNAL(set()), this, SLOT(changeCursorData()));
    connect(setup_cursor_x_, SIGNAL(set()), this, SLOT(changeCursorData()));
    connect(setup_cursor_y_, SIGNAL(set()), this, SLOT(changeCursorData()));

    connect(this, SIGNAL(initialized()), this, SLOT(initialiseLinking()));

    updateLocation(0,0);

#ifdef LH_CF
    add_cf_target(setup_cursor_active_);
    add_cf_source(setup_cursor_active_);
    add_cf_target(setup_cursor_sel_x_);
    add_cf_source(setup_cursor_sel_x_);
    add_cf_target(setup_cursor_sel_y_);
    add_cf_source(setup_cursor_sel_y_);
    add_cf_target(setup_cursor_x_);
    add_cf_source(setup_cursor_x_);
    add_cf_target(setup_cursor_y_);
    add_cf_source(setup_cursor_y_);
#endif

}
Ejemplo n.º 22
0
void Sudoku::transform(){
    change();
    printOut(false);
}
Ejemplo n.º 23
0
void solution()
{
    int c=a+1;
    int d=a+b+1;
    int e=1;
    for(int i=1;i<=a;++i)
    {
        int ok=0;
        if(x[i]==3)
        {
            for(int j=d;j<=N;++j)
                if(x[j]==1)
                {
                    ok=1;
                    y[e]=i;
                    y[e+1]=j;
                    e=e+2;
                    change(i,j);
                    d=1+j;
                    ++s;
                    break;
                }
            if(ok==0)
            {
                for(int j=c;j<=a+b;++j)
                    if(x[j]==1)
                    {
                        y[e]=i;
                        y[e+1]=j;
                        e=e+2;
                        change(i,j);
                        c=1+j;
                        ++s;
                        break;
                    }
            }
 
        }
        if(x[i]==2)
        {
            for(int j=c;j<=a+b;++j)
                if(x[j]==1)
                {
                    ok=1;
                    y[e]=i;
                    y[e+1]=j;
                    e=e+2;
                    change(i,j);
                    c=1+j;
                    ++s;
                    break;
                }
            if(ok==0)
            {
                for(int j=d;j<=N;++j)
                if(x[j]==1)
                {
                    y[e]=i;
                    y[e+1]=j;
                    e=e+2;
                    change(i,j);
                    d=1+j;
                    ++s;
                    break;
                }
            }
        }
    }
    int f=a+b+1;
    for(int i=a+1;i<=a+b;++i)
    {
        if(x[i]==3)
            for(int j=f;j<=N;++j)
                if(x[j]==2)
                {
                    y[e]=i;
                    y[e+1]=j;
                    e=e+2;
                    change(i,j);
                    f=1+j;
                    ++s;
                    break;
                }
    }
}
Ejemplo n.º 24
0
void QgraphicsItemTable::SetX(qreal x)
    {
        change(x,y(),width(),height());
    }
Ejemplo n.º 25
0
void
SectorParser::parse_old_format(const ReaderMapping& reader)
{
  m_sector.name = "main";
  reader.get("gravity", m_sector.gravity);

  std::string backgroundimage;
  if (reader.get("background", backgroundimage) && (backgroundimage != "")) {
    if (backgroundimage == "arctis.png") backgroundimage = "arctis.jpg";
    if (backgroundimage == "arctis2.jpg") backgroundimage = "arctis.jpg";
    if (backgroundimage == "ocean.png") backgroundimage = "ocean.jpg";
    backgroundimage = "images/background/" + backgroundimage;
    if (!PHYSFS_exists(backgroundimage.c_str())) {
      log_warning << "Background image \"" << backgroundimage << "\" not found. Ignoring." << std::endl;
      backgroundimage = "";
    }
  }

  float bgspeed = .5;
  reader.get("bkgd_speed", bgspeed);
  bgspeed /= 100;

  Color bkgd_top, bkgd_bottom;
  int r = 0, g = 0, b = 128;
  reader.get("bkgd_red_top", r);
  reader.get("bkgd_green_top",  g);
  reader.get("bkgd_blue_top",  b);
  bkgd_top.red = static_cast<float> (r) / 255.0f;
  bkgd_top.green = static_cast<float> (g) / 255.0f;
  bkgd_top.blue = static_cast<float> (b) / 255.0f;

  reader.get("bkgd_red_bottom",  r);
  reader.get("bkgd_green_bottom", g);
  reader.get("bkgd_blue_bottom", b);
  bkgd_bottom.red = static_cast<float> (r) / 255.0f;
  bkgd_bottom.green = static_cast<float> (g) / 255.0f;
  bkgd_bottom.blue = static_cast<float> (b) / 255.0f;

  if(backgroundimage != "") {
    auto background = std::make_shared<Background>();
    background->set_image(backgroundimage, bgspeed);
    m_sector.add_object(background);
  } else {
    auto gradient = std::make_shared<Gradient>();
    gradient->set_gradient(bkgd_top, bkgd_bottom);
    m_sector.add_object(gradient);
  }

  std::string particlesystem;
  reader.get("particle_system", particlesystem);
  if(particlesystem == "clouds")
    m_sector.add_object(std::make_shared<CloudParticleSystem>());
  else if(particlesystem == "snow")
    m_sector.add_object(std::make_shared<SnowParticleSystem>());
  else if(particlesystem == "rain")
    m_sector.add_object(std::make_shared<RainParticleSystem>());

  Vector startpos(100, 170);
  reader.get("start_pos_x", startpos.x);
  reader.get("start_pos_y", startpos.y);

  auto spawn = std::make_shared<SpawnPoint>();
  spawn->pos = startpos;
  spawn->name = "main";
  m_sector.spawnpoints.push_back(spawn);

  m_sector.music = "chipdisko.ogg";
  // skip reading music filename. It's all .ogg now, anyway
  /*
    reader.get("music", music);
  */
  m_sector.music = "music/" + m_sector.music;

  int width = 30, height = 15;
  reader.get("width", width);
  reader.get("height", height);

  std::vector<unsigned int> tiles;
  if(reader.get("interactive-tm", tiles)
     || reader.get("tilemap", tiles)) {
    auto tileset = TileManager::current()->get_tileset(m_sector.level->get_tileset());
    auto tilemap = std::make_shared<TileMap>(tileset);
    tilemap->set(width, height, tiles, LAYER_TILES, true);

    // replace tile id 112 (old invisible tile) with 1311 (new invisible tile)
    for(size_t x=0; x < tilemap->get_width(); ++x) {
      for(size_t y=0; y < tilemap->get_height(); ++y) {
        uint32_t id = tilemap->get_tile_id(x, y);
        if(id == 112)
          tilemap->change(x, y, 1311);
      }
    }

    if (height < 19) tilemap->resize(width, 19);
    m_sector.add_object(tilemap);
  }

  if(reader.get("background-tm", tiles)) {
    auto tileset = TileManager::current()->get_tileset(m_sector.level->get_tileset());
    auto tilemap = std::make_shared<TileMap>(tileset);
    tilemap->set(width, height, tiles, LAYER_BACKGROUNDTILES, false);
    if (height < 19) tilemap->resize(width, 19);
    m_sector.add_object(tilemap);
  }

  if(reader.get("foreground-tm", tiles)) {
    auto tileset = TileManager::current()->get_tileset(m_sector.level->get_tileset());
    auto tilemap = std::make_shared<TileMap>(tileset);
    tilemap->set(width, height, tiles, LAYER_FOREGROUNDTILES, false);

    // fill additional space in foreground with tiles of ID 2035 (lightmap/black)
    if (height < 19) tilemap->resize(width, 19, 2035);

    m_sector.add_object(tilemap);
  }

  // read reset-points (now spawn-points)
  ReaderMapping resetpoints;
  if(reader.get("reset-points", resetpoints)) {
    auto iter = resetpoints.get_iter();
    while(iter.next()) {
      if(iter.get_key() == "point") {
        Vector sp_pos;
        if(reader.get("x", sp_pos.x) && reader.get("y", sp_pos.y))
        {
          auto sp = std::make_shared<SpawnPoint>();
          sp->name = "main";
          sp->pos = sp_pos;
          m_sector.spawnpoints.push_back(sp);
        }
      } else {
        log_warning << "Unknown token '" << iter.get_key() << "' in reset-points." << std::endl;
      }
    }
  }

  // read objects
  ReaderCollection objects;
  if(reader.get("objects", objects)) {
    for(auto const& obj : objects.get_objects())
    {
      auto object = parse_object(obj.get_name(), obj.get_mapping());
      if(object) {
        m_sector.add_object(object);
      } else {
        log_warning << "Unknown object '" << obj.get_name() << "' in level." << std::endl;
      }
    }
  }

  // add a camera
  auto camera_ = std::make_shared<Camera>(&m_sector, "Camera");
  m_sector.add_object(camera_);

  m_sector.update_game_objects();

  if (m_sector.solid_tilemaps.empty()) {
    log_warning << "sector '" << m_sector.name << "' does not contain a solid tile layer." << std::endl;
  }

  fix_old_tiles();
  m_sector.update_game_objects();
}
Ejemplo n.º 26
0
void QgraphicsItemTable::SetY(qreal y)
    {
        change(x(),y,width(),height());
    }
Ejemplo n.º 27
0
void
HGtline(int x_1,
	int y_1)
{
  register int x_0 = lastx;
  register int y_0 = lasty;
  register int dx;
  register int dy;
  register int oldcoord;
  register int res1;
  register int visible;
  register int res2;
  register int xinc;
  register int yinc;
  register int dotcounter;

  if (linmod == SOLID) {
    line(x_1, y_1);
    return;
  }

  /* for handling different resolutions */
  dotcounter = linmod << dotshifter;

  xinc = 1;
  yinc = 1;
  if ((dx = x_1 - x_0) < 0) {
    xinc = -xinc;
    dx = -dx;
  }
  if ((dy = y_1 - y_0) < 0) {
    yinc = -yinc;
    dy = -dy;
  }
  res1 = 0;
  res2 = 0;
  visible = 0;
  if (dx >= dy) {
    oldcoord = y_0;
    while (x_0 != x_1) {
      if ((x_0 & dotcounter) && !visible) {
	change(x_0, y_0, 0);
	visible = 1;
      } else if (visible && !(x_0 & dotcounter)) {
	change(x_0 - xinc, oldcoord, 1);
	visible = 0;
      }
      if (res1 > res2) {
	oldcoord = y_0;
	res2 += dx - res1;
	res1 = 0;
	y_0 += yinc;
      }
      res1 += dy;
      x_0 += xinc;
    }
  } else {
    oldcoord = x_0;
    while (y_0 != y_1) {
      if ((y_0 & dotcounter) && !visible) {
	change(x_0, y_0, 0);
	visible = 1;
      } else if (visible && !(y_0 & dotcounter)) {
	change(oldcoord, y_0 - yinc, 1);
	visible = 0;
      }
      if (res1 > res2) {
	oldcoord = x_0;
	res2 += dy - res1;
	res1 = 0;
	x_0 += xinc;
      }
      res1 += dx;
      y_0 += yinc;
    }
  }
  if (visible)
    change(x_1, y_1, 1);
  else
    change(x_1, y_1, 0);
}
Ejemplo n.º 28
0
void QgraphicsItemTable::SetWidth(qreal width)
    {
        change(x(),y(),width,height());
    }
Ejemplo n.º 29
0
	void create()
	{
		//Try to open the character table and populate the arrays
		std::ifstream chrtbl("sma3char.tbl");
		if(chrtbl.fail())
		{
			MessageWindow::critical(Window::none(), "Could not start program because sma3char.tbl is missing.\nEnsure that the file is in the same "
				"directory as the program and try again.");
			exit(1);
		}
		for(int i = 0; i < 256; i++)
			humanToGame[i] = 0;
		
		std::string temp;
		for(int i = 0; i < 256; i++)
		{
			getline(chrtbl, temp);
			gameToHuman[i] = temp[0];
			if(gameToHuman[i] != '#' && gameToHuman[i] != '@')
				humanToGame[static_cast<unsigned int>(gameToHuman[i])] = static_cast<char>(i);
		}
		chrtbl.close();
		
		Replaceables r;
		r.special = "\n";
		r.replacement = std::string("\xFE\x10\x00",3);
		rep.push_back(r);
		
		r.special = ". ";
		r.replacement = 0xF3;
		rep.push_back(r);
		
		//This one is just f'd up
		r.special = "_";
		r.replacement = std::string("\xFE\x20\x00",3);
		rep.push_back(r);
	
		change(false, false);
		setGeometry({128,128,640,480});
		
		//Set some common actions
		onClose = f_sortie.onActivate = [this]() { exit(*this); };
		
		//File menu
		file.setText("File");
		f_oROM.setText("Open ROM...");			f_oROM.onActivate = [this]() { OpenROMFile(*this); };
		f_sROM.setText("Save ROM");				f_sROM.onActivate = [this]() { SaveROMFile(); };
		f_sROMAs.setText("Save ROM As...");
		f_cROM.setText("Close ROM");			f_cROM.onActivate = [this]() { CloseROMFile(*this); };
		f_sortie.setText("Exit");
		file.append(f_oROM, f_sROM, f_sROMAs, sep, f_cROM, f_sortie);
		append(file);
		
		//Game menu
		game.setText("Game");
		g_names.setText("Edit Level Names...");	g_names.onActivate = []() { editlevelnames.show(); };
		//blah blha bkahg fujc
		g_other.setText("Edit Others...");		g_other.onActivate = []() { editother.show(); };
		game.append(g_names, g_other);
		append(game);
		
		//Technical menu
		tech.setText("Technicals");
		t_hex.setText("View Hex Data");			t_hex.onActivate = []() { new ViewHex(); };
		t_chr.setText("View Character Table");	t_chr.onActivate = []() { new ViewCharTable(); };
		tech.append(t_hex, t_chr);
		append(tech);
		
		//Final touches
		toggle(false);
		setMenuVisible();
		setVisible();
	}
Ejemplo n.º 30
0
void QgraphicsItemTable::SetHeight(qreal height)
    {
        change(x(),y(),width(),height);
    }