コード例 #1
0
void edit_interface()
{
  field *p, *edit_fields;

  p = edit_fields = make_item("Room name: ",1,1,-1,-1);
  p = p->next = make_item("Room num : ",1,2,-1,-1);
  p = p->next = make_item("Exit 1   : ",1,3,-1,-1);
}
コード例 #2
0
ファイル: others.c プロジェクト: Csxy/SICP-Solutions
item setup_environment(){
	item initial_env = extend_environment(primitive_procedure_names(), primitive_procedure_objects(), the_empty_environment());
	item t, f;
	t.type = f.type = t_number;
	t.content.number = 1;
	f.content.number = 0;
	define_variable(make_item("true"), t, initial_env);
	define_variable(make_item("false"), f, initial_env);
	return initial_env;
}
コード例 #3
0
ファイル: others.c プロジェクト: Csxy/SICP-Solutions
item primitive_procedures(){
	item temp = list(10,
		list(2, make_item("car"), make_func(base_car)),
		list(2, make_item("cdr"), make_func(base_cdr)),
		list(2, make_item("cons"), make_func(base_cons)),
		list(2, make_item("list"), make_func(base_list)),
		list(2, make_item("set-car!"), make_func(base_set_car)),
		list(2, make_item("set-cdr!"), make_func(base_set_cdr)),
		list(2, make_item("+"), make_func(base_add)),
		list(2, make_item("-"), make_func(base_sub)),
		list(2, make_item("="), make_func(base_equal)),
		list(2, make_item("*"), make_func(base_multiply)));
	return temp;
}
コード例 #4
0
ファイル: list.c プロジェクト: gliubc/akaedu-quizzes
/* load dictionary */
queue *load_dict(const char *filename)
{
	FILE *fp;
	char word[32], translation[1024];
	item *pi;
	node *pn;
	queue *que;

	/* read file */
	fp = fopen(filename, "r");
	if (!fp) {
		printf("Open file %s failed!", filename);
		return;
	}

	que = malloc(sizeof(queue));
	init_queue(que);
	while (1) {
		if (fgets(word, sizeof(word), fp) == NULL)
			break;

		if (fgets(translation, sizeof(translation), fp) == NULL)
			break;

		/* make item */
		pi = make_item(word, translation);
		/* make node */
		pn = make_node(pi);
		/* enqueue */
		enqueue(que, pn);
	}

	fclose(fp);
	return que;
}
コード例 #5
0
ファイル: 2ASM_4_24.cpp プロジェクト: chenc10/FIT
void make_transaction(Transaction * T,int TransactionSeqNum, char * str)
{//read the data in a line into a Transaction
	//extract each 6 letters into a item
	T[TransactionSeqNum].PacketNum = (int *)malloc(5*sizeof(int));
	T[TransactionSeqNum].ItemArray = (Item **)malloc(5*sizeof(Item *));
	for( int i = 0; i < 5; i ++)
	{
		T[TransactionSeqNum].PacketNum[i] = 0;//initialize all the packetnumber into 0
		T[TransactionSeqNum].ItemArray[i] = 0;
	}
	
	for( int i = 0, j = 0; str[i*8] != 10 && j < 5; i ++)
		{
			if(str[i*8] == '!')
				{
					j ++;
					continue;
				}
			T[TransactionSeqNum].PacketNum[j]++;// record the length(number of items) of current Transaction
		}
	for( int i = 0; i < 5 && T[TransactionSeqNum].PacketNum[i]; i ++)
		T[TransactionSeqNum].ItemArray[i] = (Item *)malloc(sizeof(Item) * T[TransactionSeqNum].PacketNum[i]);
	for( int i = 0, j = 0, k = 0; str[i*8] != 10 && j < 5; i ++)
		{
			if(str[i*8] == '!')
				{
				j ++;//row ++
				k = 0;// column set to 0
				continue;
				}
			make_item((T[TransactionSeqNum].ItemArray[j]) + k,j,k, str + i*8);
			k ++;
		}
}
コード例 #6
0
ファイル: moves.c プロジェクト: Christopher-Bradshaw/chess
moves *royalty(board *n, int i, int limit) {
	moves *d, *u;
	d = diagonal(n, i, limit);
	u = up_down(n, i, limit);

	moves *m = make_item(27, i);

	memcpy(m->ends, d->ends, d->total * sizeof(d->ends[0]));
	memcpy(m->ends + d->total, u->ends, (u->total) * sizeof(u->ends[0]));

	m->total = d->total + u->total;

	free(d->ends);
	free(d);
	free(u->ends);
	free(u);

	// What about castling
	// If king and he hasn't moved
	if (limit == 1 && !(n->array[i] & 8)) {
		if (!(n->array[i + 1]) && !(n->array[i + 2]) && !(n->array[i + 3] & 8)) { // K side castle
			m->ends[m->total++] = 2;
		}
		if (!(n->array[i - 1]) && !(n->array[i - 2]) && !(n->array[i - 3]) && !(n->array[i - 4] & 8)) { // K side castle
			m->ends[m->total++] = 3;
		}
	}

	m->ends = realloc(m->ends, m->total * sizeof(m->ends[0]));
	return(m);
}
コード例 #7
0
ファイル: moves.c プロジェクト: Christopher-Bradshaw/chess
// No en passant
moves *pawn_moves(board *n, int i, int black) {
	moves *m = make_item(4, i);
	
	// If we are black we are going the other way...
	int _BW = BW;
	if (black) {
		_BW = -BW;
	}

	// Basic 1/2 move
	if (!(n->array[i + _BW])) {
		m->ends[m->total++] = i + _BW;
		if ( !(n->array[i] & 8) && !(n->array[i + 2*_BW])) {
			m->ends[m->total++] = i + 2*_BW;
		}
	}
	// Capturing
	if ( sq_state(n, i, i + _BW - 1) == 2) {
		m->ends[m->total++] = i + _BW - 1;
	}
	if ( sq_state(n, i, i + _BW + 1) == 2) {
		m->ends[m->total++] = i + _BW + 1;
	}
	// Terminate list	
	m->ends = realloc(m->ends, m->total * sizeof(m->ends[0]));
	return(m);
}
コード例 #8
0
ファイル: others.c プロジェクト: Csxy/SICP-Solutions
bool tagged_list(item exp, const char *tag)
{
	if (exp.type == t_pair){
		return eq(car(exp), make_item((char *)tag));
	}
	else return false;
}
コード例 #9
0
struct linked_list *
get_item(char *purpose, int type)
{
    struct object   *obj_p;

    if ((obj_p = get_object(pack, purpose, type, NULL)) == NULL)
        return(NULL);

    return(make_item(obj_p));
}
コード例 #10
0
static void
_got_videos_cb (RestProxyCall *call,
                const GError  *error,
                GObject       *weak_object,
                gpointer       user_data)
{
  SwYoutubeItemView *item_view = SW_YOUTUBE_ITEM_VIEW (weak_object);
  SwYoutubeItemViewPrivate *priv = GET_PRIVATE (item_view);
  SwService *service;
  RestXmlNode *root, *node;

  if (error) {
    g_message (G_STRLOC ": error from Youtube: %s", error->message);
    /* TODO: cleanup or something */
    return;
  }

  root = xml_node_from_call (call, "Youtube");
  if (!root)
    return;

  node = rest_xml_node_find (root, "channel");
  if (!node)
    return;

  /* Clean up the thumbnail mapping cache */
  g_hash_table_remove_all (priv->thumb_map);

  service = sw_item_view_get_service (SW_ITEM_VIEW (item_view));

  for (node = rest_xml_node_find (node, "item"); node; node = node->next) {
    SwItem *item;
    item = make_item (item_view, service, node);

    if (!sw_service_is_uid_banned (service, sw_item_get (item, "id"))) {
      sw_set_add (priv->set, (GObject *)item);
    }

    g_object_unref (item);
  }

  sw_item_view_set_from_set ((SwItemView *)item_view, priv->set);

  /* Save the results of this set to the cache */
  sw_cache_save (service,
                 priv->query,
                 priv->params,
                 priv->set);

  sw_set_empty (priv->set);

  rest_xml_node_unref (root);
}
コード例 #11
0
ファイル: ext.cpp プロジェクト: bitkeeper/sedna
SEDNA_SEQUENCE_ITEM *ExtFunction::get_ef_seq(const PPOpIn &inp)
{
	xqp_tuple t(inp.ts);

	inp.op->next(t);
	if (t.is_eos())
		return NULL;
	else
	{
		SEDNA_SEQUENCE_ITEM *first, *cur;
		first = make_item(t);
		cur = first;
		inp.op->next(t);
		while (!t.is_eos())
		{
			cur->next = make_item(t);
			cur = cur->next;
			inp.op->next(t);
		}
		return first;
	}
}
コード例 #12
0
ファイル: prop_widgets.c プロジェクト: GNOME/dia
static void
listprop_reset_widget(ListProperty *prop, WIDGET *widget)
{
  guint i;
  GList *items = NULL;
  gtk_list_clear_items(GTK_LIST(widget),0,-1);

  for (i = 0; i < prop->lines->len; i++) {
    items = g_list_append(items, make_item(g_ptr_array_index(prop->lines,i)));
  }
  gtk_list_append_items(GTK_LIST(widget),items);
  prop->w_selected = prop->selected;
  gtk_list_select_item(GTK_LIST(widget),prop->selected);
}
コード例 #13
0
ファイル: backpack.cpp プロジェクト: envamp/Augmentations
	void backpack(augs::entity_id e) {
		auto& container = *e += components::container();
		auto& item = make_item(e);
		
		inventory_slot slot_def;
		slot_def.space_available = 7;

		container.slots[slot_function::ITEM_DEPOSIT] = slot_def;

		item.dual_wield_accuracy_loss_multiplier = 1;
		item.dual_wield_accuracy_loss_percentage = 50;
		item.space_occupied_per_charge = 1;
		item.categories_for_slot_compatibility = item_category::SHOULDER_CONTAINER;
	}
コード例 #14
0
ファイル: vimeo-item-view.c プロジェクト: Artea/libsocialweb
static void
_got_videos_cb (RestProxyCall *call,
                const GError  *error,
                GObject       *weak_object,
                gpointer       user_data)
{
  SwVimeoItemView *item_view = SW_VIMEO_ITEM_VIEW (weak_object);
  SwVimeoItemViewPrivate *priv = GET_PRIVATE (item_view);
  SwService *service;
  RestXmlNode *root, *video_n;

  sw_call_list_remove (priv->calls, call);

  if (error) {
    g_message (G_STRLOC ": error from Vimeo: %s", error->message);
    /* TODO: cleanup or something */
    return;
  }

  SW_DEBUG (VIMEO, "Got videos");

  root = node_from_call (call);
  if (!root)
    return;

  SW_DEBUG (VIMEO, "Parsed videos");

  service = sw_item_view_get_service (SW_ITEM_VIEW (item_view));

  for (video_n = rest_xml_node_find (root, "video"); video_n; video_n = video_n->next) {
    SwItem *item;

    /* Vimeo is stupid and returns an empty <video> element if there are no
       videos, so check for this and skip it */
    if (rest_xml_node_find (video_n, "url") == NULL)
      continue;

    item = make_item (item_view, service, video_n);

    if (!sw_service_is_uid_banned (service, sw_item_get (item, "id"))) {
      sw_set_add (priv->set, (GObject *)item);
    }

    g_object_unref (item);
  }

  rest_xml_node_unref (root);

  _update_if_done (item_view);
}
コード例 #15
0
	void backpack(entity_handle e) {
		auto& container = e += components::container();
		auto& item = make_item(e);
		
		inventory_slot slot_def;
		slot_def.space_available = to_space_units("20");

		container.slots[slot_function::ITEM_DEPOSIT] = slot_def;

		item.dual_wield_accuracy_loss_multiplier = 1;
		item.dual_wield_accuracy_loss_percentage = 50;
		item.space_occupied_per_charge = to_space_units("1");
		item.categories_for_slot_compatibility.set(item_category::SHOULDER_CONTAINER);
	}
コード例 #16
0
ファイル: moves.c プロジェクト: Christopher-Bradshaw/chess
moves *knight(board *n, int i) {
	moves *m = make_item(9, i);
	
	// the 8 options availabe
	int options[] = {2,1, 1,2, -1,2, 2,-1, -2,1, 1,-2, -1,-2, -2,-1};

	for (int j = 0; j < 8; j++) {
		if (sq_state(n, i, i + (options[2*j] * BW) + options[(2*j)+1]) > 0) {
			m->ends[m->total++] = i + (options[2*j] * BW) + options[(2*j)+1];
		}
	}	

	m->ends = realloc(m->ends, m->total * sizeof(m->ends[0]));
	return(m);
}
コード例 #17
0
ファイル: main.c プロジェクト: choueric/tools
int main(int argc, char **argv)
{
    char word[LEN];
    char cognate[LEN];
    char similar[LEN];
    char synonym[LEN];

    FILE *fp1, *fp2;

    char *filename = "./output.txt";

    struct head *phead = NULL;
    struct item *pitem = NULL;

    bakeup();

    fp1 = stdin;

    phead = parse_file(filename);
    if (phead == NULL) {
        printf("parse_file failed\n");
        return 1;
    }
    print_list(phead);

    while (input_words(fp1, word, cognate, similar, synonym) == 0) {
        pitem = make_item(word, cognate, similar, synonym);
        if (pitem == NULL) {
            printf("make item failed\n");
            return 1;
        }
        insert_item(phead, pitem, phead->head, phead->tail);
        if (debug)
            printf("---> insert item %s\n", pitem->word);
        print_list(phead);
    }

    printf("---> after input, now output to file\n");
    fp2 = fopen("./output.txt", "w+");
    if (fp2 == NULL) {
        perror("open failed");
        return 1;
    }
    output_words(fp2, phead);
    fclose(fp2);

    return 0;
}
コード例 #18
0
ファイル: main.c プロジェクト: cherry-wb/quietheart
void make_icon_area(GtkWidget *fixed_base)
{
	GtkWidget *fixed;
	GtkWidget *fixed_item;
	gint item_count;
	gint i;

	fixed = fixed_base;
	item_count = sizeof(item_normal_imgs) / sizeof(item_normal_imgs[0]);

	for(i = 0; i < item_count; ++i)
	{
		fixed_item = make_item(i);
		gtk_fixed_put(GTK_FIXED(fixed), fixed_item, item_pos_x[i], item_pos_y);
	}
}
コード例 #19
0
ファイル: APETag.c プロジェクト: ljsebald/SonatinaTag
ST_FUNC ST_Error ST_APE_addItem(ST_APE *tag, const char *key,
                                const uint8_t *value, size_t len,
                                uint32_t flags) {
    ST_APE_item *tmp;
    ST_Error rv;

    if(!tag || !key || !value || tag->base.type != ST_TagType_APE)
        return ST_Error_InvalidArgument;

    if(!(tmp = make_item(value, len, flags)))
        return ST_Error_errno;

    if((rv = ST_Dict_add(tag->tags, key, tmp)) != ST_Error_None)
        free(tmp);

    return rv;
}
コード例 #20
0
ファイル: player.c プロジェクト: chameco/march
void initialize_player()
{
	PLAYER.x = PLAYER.y = 10;
	PLAYER.alive = true;
	PLAYER.glyph = '@';
	PLAYER.color.fg = COLOR_WHITE;
	PLAYER.color.bg = COLOR_BLACK;
	PLAYER.at = AI_NONE;
	PLAYER.stats[STAT_HP] = 10;
	PLAYER.stats[STAT_MAX_HP] = 10;
	PLAYER.stats[STAT_MP] = 10;
	PLAYER.stats[STAT_MAX_MP] = 10;
	PLAYER.stats[STAT_STR] = 10;
	PLAYER.stats[STAT_DEF] = 10;
	PLAYER.stats[STAT_DEX] = 10;
	memset(&PLAYER.inventory, ITEM_EMPTY_SLOT, sizeof(PLAYER.inventory));
	make_item(&PLAYER.inventory[0], ITEM_BOWIE_KNIFE);
	PLAYER.weapon_slot = 0;
	PLAYER.armor_slot = -1;

	memset(&PLAYER.components, COMPONENT_NULL, sizeof(PLAYER.components));
	PLAYER.components[0].type = COMPONENT_HEAD;
	PLAYER.components[0].wound_level = 0;

	PLAYER.components[1].type = COMPONENT_ARM;
	PLAYER.components[1].wound_level = 0;

	PLAYER.components[2].type = COMPONENT_ARM;
	PLAYER.components[2].wound_level = 0;

	PLAYER.components[3].type = COMPONENT_TORSO_UPPER;
	PLAYER.components[3].wound_level = 0;

	PLAYER.components[4].type = COMPONENT_TORSO_LOWER;
	PLAYER.components[4].wound_level = 0;

	PLAYER.components[5].type = COMPONENT_LEG;
	PLAYER.components[5].wound_level = 0;

	PLAYER.components[6].type = COMPONENT_LEG;
	PLAYER.components[6].wound_level = 0;

	gen_dispatch_map((level_descriptor *) &DISPATCH_MAP, 50, 50);
}
コード例 #21
0
ファイル: APETag.c プロジェクト: ljsebald/SonatinaTag
static ST_Error replace_tag(ST_APE *tag, const char *k, const uint8_t *v,
                            size_t len, uint32_t flags, ST_TextEncoding e) {
    ST_Error rv;
    ST_APE_item *c;

    if(!tag || !v || tag->base.type != ST_TagType_APE ||
       e != ST_TextEncoding_UTF8)
        return ST_Error_InvalidArgument;

    if(!(c = make_item(v, len, flags)))
        return ST_Error_errno;

    rv = ST_Dict_replace(tag->tags, k, 0, c);

    if(rv == ST_Error_NotFound)
        rv = ST_Dict_add(tag->tags, k, c);

    if(rv != ST_Error_None)
        free_item(c);

    return rv;
}
コード例 #22
0
ファイル: twitter.c プロジェクト: lcp/mojito
static void
tweets_cb (RestProxyCall *call,
           const GError  *error,
           GObject       *weak_object,
           gpointer       userdata)
{
  MojitoServiceTwitter *service = MOJITO_SERVICE_TWITTER (weak_object);
  RestXmlNode *root, *node;
  MojitoSet *set;

  if (error) {
    g_message ("Error: %s", error->message);
    return;
  }

  root = node_from_call (call);
  if (!root)
    return;

  set = mojito_item_set_new ();

  MOJITO_DEBUG (TWITTER, "Got tweets!");

  for (node = rest_xml_node_find (root, "status"); node; node = node->next) {
    MojitoItem *item;
    /* TODO: skip the user's own tweets */

    item = make_item (service, node);
    if (item)
      mojito_set_add (set, (GObject *)item);
  }

  mojito_service_emit_refreshed ((MojitoService *)service, set);

  /* TODO cleanup */

  rest_xml_node_unref (root);
}
コード例 #23
0
ファイル: moves.c プロジェクト: Christopher-Bradshaw/chess
// Does diagonal moves
// limit = MAX_INT -> infinite
moves *diagonal(board *n, int i, int limit) {
	moves *m = make_item(14, i);

	int options[] = { (1 + BW), (1 - BW) };
	int mult[] = {1, -1};

	int j, k;
	int step, tmp, flag;
	for (j=0; j < 2; j++) {
		for (k=0; k < 2; k++) {
			flag = 0;
			step = 1;
			while ( (tmp = sq_state(n, i, i + (options[j] * mult[k] * step))) && step <= limit) {

				if (tmp == -1) { // hit an ally
					if(limit != INT_MAX || flag) { // not looking for everythin
						break; // break
					}
					flag = 1;// next ally we don't care about
				}

				m->ends[m->total++] = i + (options[j] * mult[k] * step);
				if (tmp == 2) { // hit an enemy. Done
					if (limit == INT_MAX) {
						m->total--;
					}
					break;
				}
				step++;

			}
		}
	}
			
	// Terminate list
	m->ends = realloc(m->ends, m->total * sizeof(m->ends[0]));
	return(m);
}
コード例 #24
0
ファイル: others.c プロジェクト: Csxy/SICP-Solutions
item base_set_cdr(item argl){
	set_cdr(car(argl), car(cdr(argl)));
	return make_item("ok");
}
コード例 #25
0
ファイル: osutil.c プロジェクト: helloandre/cr48
static PyObject *_listdir(char *path, int plen, int wantstat, char *skip)
{
	PyObject *rval = NULL; /* initialize - return value */
	PyObject *list;
	HANDLE fh;
	WIN32_FIND_DATAA fd;
	char *pattern;

	/* build the path + \* pattern string */
	pattern = malloc(plen + 3); /* path + \* + \0 */
	if (!pattern) {
		PyErr_NoMemory();
		goto error_nomem;
	}
	strcpy(pattern, path);

	if (plen > 0) {
		char c = path[plen-1];
		if (c != ':' && c != '/' && c != '\\')
			pattern[plen++] = '\\';
	}
	strcpy(pattern + plen, "*");

	fh = FindFirstFileA(pattern, &fd);
	if (fh == INVALID_HANDLE_VALUE) {
		PyErr_SetFromWindowsErrWithFilename(GetLastError(), path);
		goto error_file;
	}

	list = PyList_New(0);
	if (!list)
		goto error_list;

	do {
		PyObject *item;

		if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
			if (!strcmp(fd.cFileName, ".")
			|| !strcmp(fd.cFileName, ".."))
				continue;

			if (skip && !strcmp(fd.cFileName, skip)) {
				rval = PyList_New(0);
				goto error;
			}
		}

		item = make_item(&fd, wantstat);
		if (!item)
			goto error;

		if (PyList_Append(list, item)) {
			Py_XDECREF(item);
			goto error;
		}

		Py_XDECREF(item);
	} while (FindNextFileA(fh, &fd));

	if (GetLastError() != ERROR_NO_MORE_FILES) {
		PyErr_SetFromWindowsErrWithFilename(GetLastError(), path);
		goto error;
	}

	rval = list;
	Py_XINCREF(rval);
error:
	Py_XDECREF(list);
error_list:
	FindClose(fh);
error_file:
	free(pattern);
error_nomem:
	return rval;
}
コード例 #26
0
ファイル: others.c プロジェクト: Csxy/SICP-Solutions
item helper_pri(item i){
	return list(2, make_item("primitive"), car(cdr(i)));
}
コード例 #27
0
ファイル: others.c プロジェクト: Csxy/SICP-Solutions
item make_lambda(item para, item body){
	return cons(make_item("lambda") , cons(para, body));
}
コード例 #28
0
ファイル: others.c プロジェクト: Csxy/SICP-Solutions
item make_procedure(item unev, item exp, item env){
	return list(4, make_item("procedure"), unev, exp, env);
}