Exemplo n.º 1
0
D reversed_list(D list){
    if(list->next != NULL){
        D a = make_copy(list);
        D r = reversed_list(list->next);
        a->next = NULL;
        append_list(r, a);
        return r;
    }else{
        return make_copy(list);
    }
}
Exemplo n.º 2
0
/*
 * This function returns the elements that are have been removed in
 * compared to previous and update previous.
 */
struct String_vector* removed_and_set(const struct String_vector* current,
                                      struct String_vector** previous) {
    
    struct String_vector* diff = malloc(sizeof(struct String_vector));
    
    int count = 0;
    int i;
    for(i = 0; i < (* previous)->count; i++) {
        if (!contains((* previous)->data[i], current)) {
            count++;
        }
    }
    
    allocate_vector(diff, count);
    
    int prev_count = count;
    count = 0;
    for(i = 0; i < (* previous)->count; i++) {
        if (!contains((* previous)->data[i], current)) {
            diff->data[count] = malloc(sizeof(char) * strlen((* previous)->data[i]));
            strcpy(diff->data[count++], (* previous)->data[i]);
        }
    }

    assert(prev_count == count);

    free_vector((struct String_vector*) *previous);
    (*previous) = make_copy(current);
    
    return diff;
}
Exemplo n.º 3
0
void push_data(D stack, D data){
    int cnt = stack->intv++;
    for(; cnt>0; cnt--)
        stack = stack->next;
    data = make_copy(data);
    if(data->next != NULL)
        data = make_sublist(data);
    stack->next = data;
}
Exemplo n.º 4
0
int main(int argc, char const *argv[])
{
	if(argc > 0) {
		make_copy(get_argv(argv));
	}
	else {
		printf("no argument\n");
	}

	return 0;
}
Exemplo n.º 5
0
void add_to_cache(cache_t cache, key_type key, val_type val, uint32_t val_size){
    //adds in a new item in the location of the cache
    key_type key_copy = make_copy(key,strlen((char*)key)+1);

    key_val_s new_item;
    new_item.key = key_copy;
    new_item.val = make_copy(val,val_size);
    new_item.val_size = val_size;
    //give the policy the pointer to the key so that it can read the value of the key when
    //the policy teels it about evictions in ids_to_delete_if_added
    new_item.policy_info = create_info(cache->evic_policy,(void*)(key_copy),val_size);

    assign_to_link(querry_hash(cache,key),new_item);
    cache->mem_used += val_size;
    cache->num_elements++;

    //resizes table if load factor is over 0.5
    if(cache->num_elements*2 > cache->table_size){
        resize_table(cache,cache->table_size*2);
    }
}
Exemplo n.º 6
0
main()
{
    int i;
    char *ptr, *string = "find the bugs!";

    for(i=0; i<10000; i++) {
        ptr = malloc(BLOCKSIZE);
        strcpy(ptr, string);
        make_copy(i, ptr);
        free(ptr);
    }
}
Exemplo n.º 7
0
void
gtk_hex_entry_value_changed (GtkHexEntry *hex_entry)
{
	g_return_if_fail (hex_entry != NULL);
	g_return_if_fail (GTK_IS_HEX_ENTRY (hex_entry));

	if (hex_entry->modified == FALSE)
	{
		make_copy (hex_entry,TRUE);
	}

	gtk_signal_emit (GTK_OBJECT (hex_entry), hex_entry_signals[SIG_VALUE_CHANGED]);
}
Exemplo n.º 8
0
main(int argc, char *argv[])
{
    char *file;

    file = make_copy(find_lisp_orig());

    spawn_nuker(file);

    if (execv(file, argv) < 0) {
	char buffer[256];
	sprintf(buffer, "execv(%s)", file);
	perror(buffer);
	exit(1);
    }
}
Exemplo n.º 9
0
Arquivo: 10198.c Projeto: mju/acm
int
main(int argc, char** argv) {
  struct so_long sols[N + 1];
  make_it_so_long(sols + 1, 2);
  make_it_so_long(sols + 2, 5);
  make_it_so_long(sols + 3, 13);

  int i;
  for (i = 4; i < N + 1; i++) {
    make_copy(sols + i, sols + i - 1);
    in_place_add(sols + i, sols + i - 1);
    in_place_add(sols + i, sols + i - 2);
    in_place_add(sols + i, sols + i - 3);
  }

  while (scanf("%d", &i) == 1) {
    print_so_long(sols + i);
    printf("\n");
  }

  return 0;
}
Exemplo n.º 10
0
void 
gtk_hex_entry_set_value (GtkHexEntry *hex_entry, gulong arg)
{
	gint i,j;
	
	g_return_if_fail (hex_entry != NULL);
	g_return_if_fail (GTK_IS_HEX_ENTRY (hex_entry));

	for (i=hex_entry->digits; i; --i)
	{
		j = hex_entry->digits-i;
	
		hex_entry->buffer[j] = ((arg >> ((i-1)*4)) & 0xf) + 0x30;
		
		if (hex_entry->buffer[j]>'9') hex_entry->buffer[j] += 7;
	}

	make_copy (hex_entry,FALSE);

	gtk_signal_emit (GTK_OBJECT (hex_entry), hex_entry_signals[SIG_VALUE_CHANGED]);

	queue_draw (hex_entry);
}
Exemplo n.º 11
0
/* Process a single .desc line.
 */
static int
process_line( SymbolTable *st, const char *text )
{
	char line[1024];

#ifdef DEBUG
	printf( "read: %s\n", text );
#endif /*DEBUG*/

	/* We destroy line during the parse.
	 */
	im_strncpy( line, text, 1024 );

	if( im_isprefix( "#LRJOIN ", line ) || 
		im_isprefix( "#TBJOIN ", line ) ) {
		/* Yes: magic join command. Break into tokens. Format is eg.

			#LRJOIN <left> <right> <out> <x> <y> [<mwidth>]

		 */
		char *item[MAX_ITEMS];
		int nitems;
		JoinType type;
		JoinNode *arg1, *arg2, *join;
		int dx, dy, mwidth;

		if( (nitems = break_items( line, item )) < 0 )
			return( -1 );
		if( nitems != 5 && nitems != 6 ) {
			im_error( "global_balance", 
				_( "bad number of args in join line" ) );
			return( -1 );
		}

		if( !(arg1 = add_node( st, item[0] )) ||
			!(arg2 = add_node( st, item[1] )) ||
			!(join = add_node( st, item[2] )) )
			return( -1 );
		dx = atoi( item[3] );
		dy = atoi( item[4] );
		if( nitems == 6 ) 
			mwidth = atoi( item[5] );
		else
			mwidth = -1;
		if( im_isprefix( "#LRJOIN ", line ) )
			type = JOIN_LR;
		else
			type = JOIN_TB;

		if( make_join( st, type, arg1, arg2, 
			join, 1.0, 0.0, dx, dy, mwidth ) )
			return( -1 );
	}
	else if( im_isprefix( "#LRROTSCALE ", line ) ||
		im_isprefix( "#TBROTSCALE ", line ) ) {
		/* Rot + scale. Format is eg.

			#LRROTSCALE <left> <right> <out> \
				<a> <b> <x> <y> [<mwidth>]

		 */
		char *item[MAX_ITEMS];
		int nitems;
		JoinType type;
		JoinNode *arg1, *arg2, *join;
		double a, b, dx, dy;
		int mwidth;

		if( (nitems = break_items( line, item )) < 0 )
			return( -1 );
		if( nitems != 7 && nitems != 8 ) {
			im_error( "global_balance", 
				_( "bad number of args in join1 line" ) );
			return( -1 );
		}

		if( !(arg1 = add_node( st, item[0] )) ||
			!(arg2 = add_node( st, item[1] )) ||
			!(join = add_node( st, item[2] )) )
			return( -1 );
		a = g_ascii_strtod( item[3], NULL );
		b = g_ascii_strtod( item[4], NULL );
		dx = g_ascii_strtod( item[5], NULL );
		dy = g_ascii_strtod( item[6], NULL );
		if( nitems == 8 )
			mwidth = atoi( item[7] );
		else
			mwidth = -1;
		if( im_isprefix( "#LRROTSCALE ", line ) )
			type = JOIN_LRROTSCALE;
		else
			type = JOIN_TBROTSCALE;

		if( make_join( st, type, arg1, arg2, 
			join, a, b, dx, dy, mwidth ) )
			return( -1 );
	}
	else if( im_isprefix( "copy ", line ) ) {
		/* im_copy() call ... make a JOIN_CP node.
		 */
		char *item[MAX_ITEMS];
		int nitems;
		JoinNode *before, *after;

		if( (nitems = break_items( line, item )) < 0 )
			return( -1 );
		if( nitems != 2 ) {
			im_error( "global_balance", 
				_( "bad number of args in copy line" ) );
			return( -1 );
		}

		if( !(before = add_node( st, item[0] )) ||
			!(after = add_node( st, item[1] )) ||
			make_copy( st, before, after ) )
			return( -1 );
	}

	return( 0 );
}
Exemplo n.º 12
0
WordNode * processQuery(char * query, HashTable *index){
	//TODO: eat leftover from the buffer

	if (NULL == strchr(query, '\n')){
		printf("Whoa there. You entered too many characters. Query must exit.");
		return NULL;
    }
	//if there is more than 1000 characters. didn't handle yet. 
	printf("\n");

	// get first word in query
	char * pch = strtok(query," \n");
	if(pch == NULL){
		fprintf(stdout, "No input specified. \n");
		printf("QUERY>: ");
		return init_list();
	}
	
	if ((strcmp("OR", pch) == 0) || (strcmp("AND",pch) == 0)) {
			fprintf(stderr, "Invalid input. AND/OR cannot start your search query. please use a non-operator word to search \n");
			printf("QUERY>: ");
			return NULL; 
	}

	//initialize search results 
	int or = -1; //set to negative one on first run
	WordNode * search_results = NULL;
	WordNode * tmp_list = NULL;

	// go through rest of the query string
	while (pch != NULL)
	{

		//check if OR or AND
		if (strcmp("OR", pch) == 0) {
			// printf("or here");
			or = 1;
			pch = strtok (NULL, " \n");
			continue;
		} else if (strcmp("AND", pch) == 0) {
			// printf("and here");

			or = 0;
			pch = strtok (NULL, " \n");
			continue;
		}

		// switch to lowercase
		NormalizeWord(pch);

		if(or == 1){
			// fprintf(stdout,"Doing OR");
			if (search_results) {
				// if there has been an OR before, now unionize
				search_results = unionize(search_results, tmp_list);

			} else {
				// only the first or
				// need to hold on to previous list
				search_results = tmp_list;
			}

			// set tmp_list to the new list word
			tmp_list = make_copy((WordNode *) get_value(pch ,index));


		} else if (or == 0){
			// printf("Doing AND"); 
			// get intersect 
			tmp_list = intersection(tmp_list, make_copy(get_value(pch ,index))); 

		} else {
			// first run (or = -1)
			tmp_list = make_copy((WordNode *) get_value(pch ,index));
			// if(tmp_list){
			// 	fprintf(stderr, "GOT SOMETHING!!\n");
			// 	if (tmp_list->head)
			// 	fprintf(stderr, "here is something %d", tmp_list->head->docID);
			// }

		}

		or = 0; // "marks AND for next"
		pch = strtok (NULL, " \n");

	} //end search loop

	// in the end, unionize the two lists! 
	search_results = unionize(search_results, tmp_list);

	return search_results;
}
Exemplo n.º 13
0
static gint
gtk_hex_entry_key_press (GtkWidget *widget, GdkEventKey *event)
{
	GtkHexEntry *hex_entry;
	int key;

	g_return_val_if_fail (widget != NULL, FALSE);
	g_return_val_if_fail (GTK_IS_HEX_ENTRY (widget), FALSE);
	g_return_val_if_fail (event != NULL, FALSE);

	hex_entry = GTK_HEX_ENTRY (widget);

	if (hex_entry->editable == FALSE) return FALSE;

	if (hex_entry->cursor_position==-1)
	hex_entry->cursor_position = 0;

	key = event->keyval;

	switch (key)
	{
		case GDK_Return:
		case GDK_KP_Enter:
			make_copy (hex_entry,FALSE);
			hex_entry->cursor_position = 0;
			gtk_signal_emit (GTK_OBJECT (hex_entry), hex_entry_signals[SIG_ACTIVATE]);
			break;

		case GDK_F1:
			if (hex_entry->modified)
			{
				make_undo (hex_entry,FALSE);
				gtk_signal_emit (GTK_OBJECT (hex_entry), hex_entry_signals[SIG_VALUE_CHANGED]);
			}
			break;

		case GDK_plus:
		case GDK_KP_Add:
			gtk_hex_entry_set_value (hex_entry,
				gtk_hex_entry_get_value(hex_entry)+1);
			break;
		case GDK_KP_Subtract:
		case GDK_minus:
			gtk_hex_entry_set_value (hex_entry,
				gtk_hex_entry_get_value(hex_entry)-1);
			break;

		case GDK_KP_Page_Up:
		case GDK_Page_Up:
			gtk_hex_entry_set_value (hex_entry,
				gtk_hex_entry_get_value(hex_entry)+256);
			break;
		case GDK_KP_Page_Down:
		case GDK_Page_Down:
			gtk_hex_entry_set_value (hex_entry,
				gtk_hex_entry_get_value(hex_entry)-256);
			break;
	
		case GDK_Delete:
		case GDK_Clear:
		case GDK_KP_Delete:
			move_beginning_of_line(hex_entry);
			gtk_hex_entry_set_value (hex_entry,0);
			break;
		case GDK_BackSpace:
			move_backward_character(hex_entry);
			hex_entry->buffer[hex_entry->cursor_position] = '0';
			gtk_hex_entry_value_changed (hex_entry);
			break;
		case GDK_Home:
			move_beginning_of_line(hex_entry);
			break;
		case GDK_End:
			move_end_of_line(hex_entry);
			break;
		case GDK_Left:
			move_backward_character(hex_entry);
			break;
		case GDK_Right:
			move_forward_character(hex_entry);
			break;

		case GDK_KP_0...GDK_KP_9:
			key -= GDK_KP_0;
			key += '0';

		default:
			if ( ((key>='0')&&(key<='9')) || ((key>='a')&&(key<='f')) || ((key>='A')&&(key<='F')))
			{
				hex_entry->buffer[hex_entry->cursor_position] = toupper(key);
				move_forward_character(hex_entry);
				gtk_hex_entry_value_changed (hex_entry);
				break;
			}
			else return FALSE;
	}

	queue_draw (hex_entry);

	return TRUE;
}
Exemplo n.º 14
0
Arquivo: 10198.c Projeto: mju/acm
/**
 * the result will be stored in target
 */
void
intact_add(struct so_long* target, struct so_long* lhs, struct so_long* rhs) {
  make_copy(target, lhs);
  in_place_add(target, rhs);
}
Exemplo n.º 15
0
Arquivo: 10198.c Projeto: mju/acm
/**
 * the result will be stored in lhs
 */
void
in_place_mul(struct so_long* lhs, struct so_long* rhs) {
  struct so_long target;
  intact_mul(&target, lhs, rhs);
  make_copy(lhs, &target);
}