Beispiel #1
0
void frame_print(frame * i, int print_scope)
{
    char *flags[] = { 
        "ASTERPEND_CONTINUE",
        "ATPEND_CONTINUE",
        "ARGUMENT",
        "ELIPSIS_ARGUMENT",
        "ELIPSIS_ASTERPEND_CONTINUE",
        "ELIPSIS_ATPEND_CONTINUE",
        "EVALUATE",
        "CONTINUE",
        "APPLY_FUNCTION",
        "PREPARE_ARGUMENTS",
        "PAUSE",
        "HANDLE_SIGNALS"
    };

    printf(" --> ");
    printf("%s, ", flags[i->flag]);
    if (i->instruction)
        oyster_print(i->instruction);
    if (print_scope) {
        printf("\n Scope:\n");
        table_print(i->scope);
        printf("Upcoming scope:\n");
        table_print(i->scope_to_be);
    }
    printf("\n");
}
Beispiel #2
0
void
table_show(int ac, char *av[])
{
	int nbytes, nalloc = 1024;
	void *data = NULL;
	NEXT_ARG;
	if (isdigit(**av)) {
		nbytes = nalloc;
		while (nbytes >= nalloc) {
			nalloc = nalloc * 2 + 256;
			nbytes = nalloc;
			if (data == NULL) {
				if ((data = malloc(nbytes)) == NULL) {
					err(EX_OSERR, "malloc");
				}
			} else if ((data = realloc(data, nbytes)) == NULL) {
				err(EX_OSERR, "realloc");
			}
			/* store table id in the header of data */
			int *head = (int *)data;
			*head = atoi(*av);
			if (*head < 0 || *head > IPFW_TABLES_MAX - 1)
				errx(EX_USAGE, "table id `%d' invalid", *head);
			if (do_get_x(IP_FW_TABLE_SHOW, data, &nbytes) < 0)
				err(EX_OSERR, "do_get_x(IP_FW_TABLE_LIST)");
			struct ipfw_ioc_table *tbl;
			tbl = (struct ipfw_ioc_table *)data;
			table_print(tbl);
		}
	} else {
		errx(EX_USAGE, "ipfw3 table `%s' show invalid", *av);
	}
}
Beispiel #3
0
int main (int argc, char *argv[]) {
  if (argc != 2) {
    usage();
    exit(1);
  }

  char *infile  = argv[1];

  TreeNode *tree = huffman_build_tree(infile);
  if (tree == NULL) {
    printf("Could not build the tree!");
    usage();
    exit(1);
  }

  EncodeTable *etab = table_build(tree);
  if (etab == NULL) {
    printf("Could not build the table!");
    usage();
    exit(1);
  }  

  table_print(etab);

  table_free(etab);
  tree_free(tree);

  return 0;
}
Beispiel #4
0
// reg_get - returns the register to be used
reg* reg_get(){
	reg* res;
	reg* aux;
	int max=-1;
	if(registers==NULL || registers->length<1)
		return NULL;

	if(registers->free){
		// pop free register
		res=registers->first;
		while(res!=NULL && !strequal(res->next->name, "r0")){
			if(res->free==true) break;
			res=res->next;
		}
		registers->free--;
	} else {
		// findMaxNext
		res=(registers->first);
		aux=(registers->first);
		while(aux!=NULL && !strequal(aux->next->name, "r0")){
			if(((aux->dist<0) || (aux->dist)>max) && aux->dirty){
				max=aux->dist;
				res=aux;
			}
			aux=aux->next;
		}
		// recheck
		if(res==NULL){
			// for(...) check if is dirty, then do it.
			for(aux=(registers->first); aux!=NULL; aux=aux->next){
				if(aux->dirty && !strequal(aux->next->name, "r0")){
					max=aux->dist;
					res=aux;
				}
			}
		}
	}

	res->dirty=false;

	#ifdef VERBOSE
		printf(" [reg_get] returning ");
		if(res!=NULL)
			printf(" '%s'\n", res->name);
		else {
			printf(" null\n");
			table_print(registers);
		}
	#endif

	return res;
}
Beispiel #5
0
/*
 * Main function
 */
main(int argc, char *argv[]) {
     char *buf;

     pmacnet_init();
     pmacnet_collect();
     if (argc > 1)
	  buf = table_outtable(pmacnet_tab);
     else
	  buf = table_print(pmacnet_tab);
     puts(buf);
     nfree(buf);
     table_destroy(pmacnet_tab);
     exit(0);
}
Beispiel #6
0
/*
 * Main function
 */
main(int argc, char *argv[]) {
     char *buf;

     plinnames_init();
     plinnames_collect();
     if (argc > 1)
	  buf = table_outtable(tab);
     else
	  buf = table_print(tab);
     puts(buf);
     nfree(buf);
     table_destroy(tab);
     exit(0);
}
Beispiel #7
0
int main(int argc, char **argv)
{
     TABLE tab1;
     char *buf1;

     iiab_start("", argc, argv, "", test_cf);
     tab1 = cf_getstatus(iiab_cf);
     buf1 = table_print(tab1);
     printf("%s\n", buf1);
     nfree(buf1);
     table_destroy(tab1);
     iiab_stop();

     exit(0);
}
Beispiel #8
0
/*
 * Main function
 */
main(int argc, char *argv[]) {
     char *buf;

     iiab_start("", argc, argv, "", NULL);
     plinps_init();
     plinps_collect();
     if (argc > 1)
	  buf = table_outtable(plinps_tab);
     else
	  buf = table_print(plinps_tab);
     if (buf)
	  puts(buf);
     else
	  elog_die(FATAL, "plinps", 0, "no output produced");
     nfree(buf);
     table_destroy(plinps_tab);
     plinps_fini();
     iiab_stop();
     exit(0);
}
Beispiel #9
0
void machine_print(machine * m)
{
    frame *f = m->current_frame;
    printf("Now: ");
    frame_print(m->now, 0);
    if (m->now->instruction && !table_empty(oyster_bindings(m->now->instruction))) {
        printf(" with the bindings: \n");
        table_print(oyster_bindings(m->now->instruction));
    }
    while (f) {
        printf("frame: ");
        frame_print(f, 0);
        f = f->below;
    }
    if (m->accumulator) {
        printf("accum: ");
        oyster_print(m->accumulator);
    }
    printf
    ("\n--- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n\n\n\n");
}
Beispiel #10
0
struct symbol *gen_para_regs (struct symbol *parameters)
{
	char *registers[6] = {"rdi", "rsi", "rdx", "rcx", "r8", "r9"};
	int i=0;
	struct symbol *para_start = parameters;

	while (parameters != NULL) {
		if (i > 5) {
			not_supported ("more than 6 function parameters\n");
		}
		parameters->reg = strdup (registers[i++]);
		parameters = parameters->next;
	}

	#ifdef MY_DEBUG
	printf ("#-- ASSIGNING PARAMETER REGISTERS\n");
	table_print (para_start);
	printf ("\n");
	#endif

	return para_start;
}
Beispiel #11
0
int main()
{
#ifdef DEBUG
	logfile_create("stdout", 3);
#endif
	HashTable* ht;
	char key[64];
	int valuesize = 8;
	char val[64];
	unsigned int attrformat[3]   = {4, 3, 1};
	unsigned int attrarray[3][3] = { {8, 3, 1}, { 7, 2,1}, {6, 2, 1} }; 
	int num  = 200;
	int attrnum = 3;
	int ret;
	int i = 0;
    char *name = "test";
	char *conffile;
	conffile = "memlink.conf";
	DINFO("config file: %s\n", conffile);
	myconfig_create(conffile);

	my_runtime_create_common("memlink");
	ht = g_runtime->ht;

    ret = hashtable_create_table(ht, name, valuesize, attrformat, attrnum, 
                    MEMLINK_LIST, MEMLINK_VALUE_STRING);
    if (ret != MEMLINK_OK) {
        DERROR("create table error:%d\n", ret);
        return -1;
    }
    Table *tb = hashtable_find_table(ht, name);
	///////////begin test;
	//test1 : hashtable_add_info_attr - create key
	for (i = 0; i < num; i++) {
		sprintf(key, "heihei%03d", i);
		table_create_node(tb, key);
	}
	for (i = 0; i < num; i++) {
		sprintf(key, "heihei%03d", i);
		HashNode* pNode = table_find(tb, key);
		if (NULL == pNode) {
			DERROR("table_find error. can not find %s\n", key);
			return -1;
		}
	}

    //test : hashtable_add_attr insert num value
	DINFO("1 insert 1000 \n");

	int pos = 0;
	HashNode *node = NULL;
	DataBlock *dbk = NULL;
	char	 *item = NULL; 
	num = 200;

	for (i = 0; i < num; i++) {
		sprintf(val, "value%03d", i);
		pos = i;
		ret = hashtable_insert(ht, name, key, val, attrarray[i%3], 3, pos);
		if (ret < 0) {
			DERROR("hashtable_add_attr err! ret:%d, val:%s, pos:%d \n", ret, val, pos);
			return ret;
		}
	}

	DINFO("2 insert %d\n", num);
    
    MemLinkStat stat;
    ret = hashtable_stat(ht, name, key, &stat);
    if (ret != MEMLINK_OK) {
        DERROR("stat error!\n");
    }

    DINFO("blocks:%d, data_used:%d\n", stat.blocks, stat.data_used);

	for (i = 0; i < num; i++) {
		sprintf(val, "value%03d", i);
		ret = table_find_value(tb, key, val, &node, &dbk, &item);
		if (ret < 0) {
			DERROR("not found value: %d, %s\n", ret, val);
			return ret;
		}
	}
	
	//hashtable_print(g_runtime->ht, key);
	sprintf(val, "value%03d", 50);
	ret = hashtable_del(ht, name, key, val);
	if (ret < 0) {
		DERROR("del value: %d, %s\n", ret, val);
		return ret;
	}
    DINFO("deleted %s\n", val);	
	table_print(tb, key);

    ret = table_find_value(tb, key, val, &node, &dbk, &item);
    if (ret >= 0) {
        DERROR("found value: %d, %s\n", ret, val);
        return ret;
    }

	ret = hashtable_insert(ht, name, key, val, attrarray[2], attrnum, 100);
	if (ret < 0) {
		DERROR("add value err: %d, %s\n", ret, val);
		return ret;
	}

	ret = table_find_value(tb, key, val, &node, &dbk, &item);
	if (ret < 0) {
		DERROR("not found value: %d, %s\n", ret, val);
		return ret;
	}
	DINFO("test: insert ok!\n");

    table_print(tb, key);
    /////////// hashtable_del
	for (i = 0; i < num; i++) {
		sprintf(val, "value%03d", i);
		//pos = i;
		ret = hashtable_del(ht, name, key, val);
		if (ret < 0) {
			DERROR("hashtable_del err! ret:%d, val:%s \n", ret, val);
			return ret;
		}
	}
	DINFO("del %d!\n", num);

	for (i = 0; i < num; i++) {
		sprintf(val, "value%03d", i);
		ret = table_find_value(tb, key, val, &node, &dbk, &item);
		if (ret >= 0) {
			DERROR("err should not found value: %d, %s\n", ret, key);
			return ret;
		}
	}
	
	DINFO("test: del ok!\n");
	return 0;
}
Beispiel #12
0
int main(int c, char * argv[]){

	char  *player_name = (char*)malloc(sizeof(char) * 50);
	int    n_players;
	int    starting_amount;
	int    limit;
	int    check = 1;
	Table *table;
	
	srand(time(NULL));

	printf("Welcome to Poker! What's your name?\n");
	
	while(check){
		scanf("%[^\n]s", player_name);
		if(strlen(player_name)>0){
			check = 0;
		}
		else
			printf("Player name must be more than 0 characters.\n");
	}

	check = 1;

	user_letter();	

	printf("Choose between 2 and 4 players (including yourself).\n");

	while(check){
		n_players = user_letter();
		if(n_players != '2' && n_players != '3' && n_players != '4'){
			printf("Must select between 2 and 4 players\n");
		}
		else
			check = 0;
	} 
	
	if(n_players == '2')
		n_players = 2;
	if(n_players == '3')
		n_players = 3;
	if(n_players == '4')
		n_players = 4;
	
	check = 1;	

	printf("\n");
	printf("Please choose the amount each player will begin with and the limit for each bet.\n");
	printf("Note: Limits must be less than starting amounts and starting amounts should be a\n");
	printf("\tmultiple of the limit.\n\n");

	while(check){
		printf("Starting Amount: (recommended value 100)\n");
		scanf("%d", &starting_amount);
		printf("Limit: (recommended value 5)\n");
		scanf("%d", &limit);
		
		if(starting_amount < limit){
			printf("Limit is greater than starting amount.\n\n");
		}
		else if(starting_amount % limit != 0){
			printf("Starting amount should be a multiple of limit.\n\n");
		}
		else{
			check = 0;
		}
	}

	printf("Thanks %s!  Initializing your game now!\n\n", player_name);

	table = init_table(player_name, n_players, limit, starting_amount, 100000);

	while(table->n_players > 1){
		
		table->deck->shuffle(table->deck);
		printf("Press Enter to Begin Next Hand");
		user_letter();	
		printf("\n**********************************************************************************\n");
		printf("\nBeginning New Hand\n\n");
		printf("Current Standings:\n\n");	
		table_print(table, 0);
		printf("\n**********************************************************************************\n");
		printf("\n");
		sleep(WAIT);	
	
		table_unfold(table);
		
		table_deal(table);
	
		printf("Collecting Antes\n\n");	
		table_ante(table);

		sleep(WAIT);
		
		printf("\n**********************************************************************************\n\n");
		printf("Beginning First Round of Betting\n");
		table_bet(table);

		if(table->players_n_folded > 1){
			
			printf("\n**********************************************************************************\n");
			printf("\nExchanging Cards...\n\n");
			table_new_cards(table);
			
			printf("\n**********************************************************************************\n");
			printf("\nBeginning Second Round of Betting\n\n");
			table_bet(table);
		}

		printf("\n**********************************************************************************\n");
		printf("\nAll rounds of betting are complete.  Revealing final hands\n\n");
	
		sleep(2);

		table_print(table, 1);

		table_winner(table);
		
		printf("\n**********************************************************************************\n");
	
		table_return_cards(table);
		
		table_shift(table);
			
		table_remove_players(table);

	}		

	printf("%s has won the game!\n\n", table->players[0]->name);
	return 0;
} 
Beispiel #13
0
int main() {
	int i;
	struct timespec start, end, diff[8];
	table* t;
	int widths[] = { 20, 20, 20 };
	machine* server;
	half_long_string hl_str;

	config_server();

	deploy(machines[0], "./rpc_times_server");
	deploy(machines[2], "./rpc_times_server");
	deploy(machines[3], "./rpc_times_server");

	sleep(5);

	// 1028 bytes arg
	for (i = 0; i < 1024; i++) {
		hl_str.str1[i] = 65 + i % 26;
		hl_str.str2[i] = 65 + i % 26;
	}

	{
		// Local call 4 bytes
		printf("Calling Local (no RPC): 4 bytes");
		fflush(stdout);
		clock_gettime(CLOCK_REALTIME, &start);
		local_call_4(1000);
		clock_gettime(CLOCK_REALTIME, &end);
		diff[0].tv_nsec = end.tv_nsec - start.tv_nsec;
		diff[0].tv_sec = end.tv_sec - start.tv_sec;

		// Local call 2048 bytes
		printf(", 2048 bytes\t\tOK\n");
		clock_gettime(CLOCK_REALTIME, &start);
		local_call_2048(hl_str);
		clock_gettime(CLOCK_REALTIME, &end);
		diff[1].tv_nsec = end.tv_nsec - start.tv_nsec;
		diff[1].tv_sec = end.tv_sec - start.tv_sec;
	}
	{
		server = machines[4];
		// Remote call 4 bytes
		printf("Calling Local RPC: 4 bytes");
		clock_gettime(CLOCK_REALTIME, &start);
		rpc_call_4(server->ip, 1000);
		clock_gettime(CLOCK_REALTIME, &end);
		diff[2].tv_nsec = end.tv_nsec - start.tv_nsec;
		diff[2].tv_sec = end.tv_sec - start.tv_sec;

		// Remote call 2048 bytes
		printf(", 2048 bytes\t\tOK\n");
		clock_gettime(CLOCK_REALTIME, &start);
		rpc_call_2048(server->ip, hl_str);
		clock_gettime(CLOCK_REALTIME, &end);
		diff[3].tv_nsec = end.tv_nsec - start.tv_nsec;
		diff[3].tv_sec = end.tv_sec - start.tv_sec;
	}
	{
		server = machines[2];
		// Remote call 4 bytes (Remote: Fedora)
		printf("Calling Remote Homogeneous: 4 bytes");
		clock_gettime(CLOCK_REALTIME, &start);
		rpc_call_4(server->ip, 1000);
		clock_gettime(CLOCK_REALTIME, &end);
		diff[4].tv_nsec = end.tv_nsec - start.tv_nsec;
		diff[4].tv_sec = end.tv_sec - start.tv_sec;

		// Remote call 2048 bytes (Remote: Fedora)
		printf(", 2048 bytes\t\tOK\n");
		clock_gettime(CLOCK_REALTIME, &start);
		rpc_call_2048(server->ip, hl_str);
		clock_gettime(CLOCK_REALTIME, &end);
		diff[5].tv_nsec = end.tv_nsec - start.tv_nsec;
		diff[5].tv_sec = end.tv_sec - start.tv_sec;
	}
	{
		server = machines[2];
		// Remote call 4 bytes (Remote: Alpha)
		printf("Calling Remote heterogeneous: 4 bytes");
		clock_gettime(CLOCK_REALTIME, &start);
		rpc_call_4(server->ip, 1000);
		clock_gettime(CLOCK_REALTIME, &end);
		diff[6].tv_nsec = end.tv_nsec - start.tv_nsec;
		diff[6].tv_sec = end.tv_sec - start.tv_sec;

		// Remote call 2048 bytes (Remote: Alpha)
		printf(", 2048 bytes\t\tOK\n");
		clock_gettime(CLOCK_REALTIME, &start);
		rpc_call_2048(server->ip, hl_str);
		clock_gettime(CLOCK_REALTIME, &end);
		diff[7].tv_nsec = end.tv_nsec - start.tv_nsec;
		diff[7].tv_sec = end.tv_sec - start.tv_sec;
	}

	printf("\nResultados\n");
	printf("==========\n");

	// Initialize table
	t = table_initialize(3, widths);
	// Write row data
	table_add_row(t);
	table_add_data(t, 0, 0, "");
	table_add_data(t, 0, 1, "4b in, 4b out");
	table_add_data(t, 0, 2, "2x1024 in, 2048 out");

	// Write row data
	table_add_row(t);
	table_add_data(t, 1, 0, "Local call");
	table_add_data(t, 1, 1, "%lis %09li ns", diff[0].tv_sec, diff[0].tv_nsec);
	table_add_data(t, 1, 2, "%lis %09li ns", diff[1].tv_sec, diff[1].tv_nsec);

	// Write row data
	table_add_row(t);
	table_add_data(t, 2, 0, "RPC (local)");
	table_add_data(t, 2, 1, "%lis %09li ns", diff[2].tv_sec, diff[2].tv_nsec);
	table_add_data(t, 2, 2, "%lis %09li ns", diff[3].tv_sec, diff[3].tv_nsec);

	// Write row data
	table_add_row(t);
	table_add_data(t, 3, 0, "RPC (remota)");
	table_add_data(t, 3, 1, "%lis %09li ns", diff[4].tv_sec, diff[4].tv_nsec);
	table_add_data(t, 3, 2, "%lis %09li ns", diff[5].tv_sec, diff[5].tv_nsec);

	// Write row data
	table_add_row(t);
	table_add_data(t, 4, 0, "RPC (hetero)");
	table_add_data(t, 4, 1, "%lis %09li ns", diff[6].tv_sec, diff[6].tv_nsec);
	table_add_data(t, 4, 2, "%lis %09li ns", diff[7].tv_sec, diff[7].tv_nsec);

	// Print table
	table_print(t);

	return 0;
}
Beispiel #14
0
Datei: main.c Projekt: paswd/kp9
int main(void)
{
	Table *table = table_create();
	printf("-------------------------------------------\n");
	printf("Commands:\n");
	printf("a <key> <value> - push to table\n");
	printf("d <key> - delete from table\n");
	printf("s - sort table\n");
	printf("p - print table\n");
	printf("f <key> - find element by key\n");
	printf("c - clear table\n");
	printf("q - exit\n");
	printf("-------------------------------------------\n");
	size_t cnt = 0;
	char last_cmd = '\n';
	while (true) {
		if (!cnt || last_cmd == '\n')
			printf("> ");
		char cmd;
		bool is_finished = false;
		scanf("%c", &cmd);
		size_t pos;
		//LinearlistElement *this = NULL;
		Key *key = key_create();
		switch (cmd) {
			case 'q':
				is_finished = true;
				break;
			case 'a':
				table_push(table);
				break;
			case 'd':
				//scanf("%d", &pos);
				key_set_value_from_input(key);
				table_note_delete(table, key);
				break;
			case 's':
				table_sort(table);
				break;
			case 'p':
				table_print(table);
				break;
			case 'c':
				table_clear(table);
				break;
			case 'f':
				key_set_value_from_input(key);
				Note *found = table_search(table, key, &pos);
				if (found == NULL) {
					printf("There are no notes with this key in the table\n");
					break;
				}
				note_print(table, found);
				break;
			case '\n':
				break;
			default:
				printf("Invalid command `%c`\n", cmd);
				break;
		}
		last_cmd = cmd;
		key_destroy(&key);
		if (is_finished) break;

		cnt++;
		cnt %= 2;

		//printf("First: %lld\n", (long long) linearlist_get_value(linearlist_get_first(linearlist)));
		//printf("Last: %lld\n", (long long) linearlist_get_value(linearlist_get_last(linearlist)));
	}
	printf("Goodbye!\n");

	table_destroy(&table);

	return 0;
}
Beispiel #15
0
//Функция формирует данные для таблицы и выводит данные на экран
state print_records(void* data, void* param)
{
	//Данные для вывода
	phonebook_item_t** phonebook = (phonebook_item_t**)data;
	size_t* count = (size_t*)param;

	size_t i;
	table_t* table = table_create(0, *count);

	//Выделяем память под колонки
	size_t* n			= (size_t*)calloc(*count, sizeof(size_t));
	char** last_names	= (char**) calloc(*count, sizeof(char**));
	char** first_names	= (char**) calloc(*count, sizeof(char**));
	char** patronymics	= (char**) calloc(*count, sizeof(char**));
	char** streets		= (char**) calloc(*count, sizeof(char**));
	char** blds			= (char**) calloc(*count, sizeof(char**));
	char** aps			= (char**) calloc(*count, sizeof(char**));
	char** phones		= (char**) calloc(*count, sizeof(char**));

	//Добавляем колонки в таблицу
	table_add_column(table, Rus("№"),		n,			INTEGER,0, 5);
	table_add_column(table, Rus("ФАМИЛИЯ"),	last_names, STRING, 5, 0);
	table_add_column(table, Rus("ИМЯ"),		first_names,STRING, 5, 0);
	table_add_column(table, Rus("ОТЧЕСТВО"),patronymics,STRING, 5, 0);
	table_add_column(table, Rus("УЛИЦА"),	streets,	STRING, 5, 0);
	table_add_column(table, Rus("ДОМ"),		blds,		STRING, 3, 6);
	table_add_column(table, Rus("КВ."),		aps,		STRING, 3, 6);
	table_add_column(table, Rus("ТЕЛЕФОН"), phones,		STRING, 6, 7);

	//Заполняем колонки данными
	for (i = 0; i < *count; ++i)
	{
		*(n + i)			= (*phonebook + i)->id;
		*(last_names + i)	= (*phonebook + i)->last_name;
		*(first_names + i)	= (*phonebook + i)->first_name;
		*(patronymics + i)	= (*phonebook + i)->patronymic;
		*(streets + i)		= (*phonebook + i)->street;
		*(blds + i)			= (*phonebook + i)->bld;
		*(aps + i)			= (*phonebook + i)->ap;
		*(phones + i)		= (*phonebook + i)->phone;
	}

	//Получаем ширину консоли
	size_t sreen_width;
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	int ret;
	ret = GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
	if (ret)
	{
		sreen_width = csbi.dwSize.X - 4;
	} else {
		sreen_width = 110;
	}

	//Выводим таблицу
	table_print(table, sreen_width);

	//Освобождаем память
	free(n);
	free(last_names);
	free(first_names);
	free(patronymics);
	free(streets);
	free(blds);
	free(aps);
	free(phones);
	free(table);

	system("pause");
	return REDRAW;
}
Beispiel #16
0
IMAGE *process_pipeline(IMAGE *image){
	if(!image){
		/// "Не задано входное изображение"
		ERRX(_("No input image given"));
	}
	if(!farray || !farray_size){
		/// "Не заданы параметры конвейера"
		WARNX(_("No pipeline parameters given"));
	}
	size_t i;
	Filter **far = farray;
	IMAGE *in = copyFITS(image); // copy original image to leave it unchanged
	IMAGE *processed = NULL;
	for(i = 0; i < farray_size; ++i, ++far){
		Filter *f = *far;
		DBG("Got filter #%d: w=%d, h=%d, sx=%g, sy=%g\n", f->FilterType,
			f->w, f->h, f->sx, f->sy);
		printf("try filter %zd\n", i);
		Itmarray oarg = {NULL, 0};
		processed = f->imfunc(in, f, &oarg);
		/// "Ошибка в обработке конвейера"
		if(!processed) ERRX(_("Error on pipeline processing!"));
		// TODO: what should I do with oarg???
		if(oarg.size){
			size_t i, l = oarg.size;
			//if(verbose_level){
				green("got oarg: \n");
				for(i = 0; i < l; ++i){
					printf("%5zd: %g\n", i, oarg.data[i]);
				}
			//}
			char tabname[80];
			snprintf(tabname, 80, "%s_CONVERSION", f->name);
			FITStable *tab = table_new(processed, tabname);
			if(tab){
				table_column col = {
					.width = sizeof(int32_t),
					.repeat = l,
					.coltype = TINT
				};
				int32_t *levls = MALLOC(int32_t, l);
				for(i = 0; i < l; ++i) levls[i] = (int32_t) i;
				col.contents = levls;
				sprintf(col.colname, "level");
				*col.unit = 0;
				table_addcolumn(tab, &col);
				FREE(levls);
				col.contents = oarg.data;
				col.coltype = TDOUBLE;
				col.width = sizeof(double),
				sprintf(col.colname, "value");
				sprintf(col.unit, "ADU");
				table_addcolumn(tab, &col);
				printf("Create table:\n");
				table_print(tab);
			}
			FREE(oarg.data);
		}
		processed->keylist = in->keylist;
		char changes[FLEN_CARD];
		snprintf(changes, FLEN_CARD, "HISTORY modified by routine %s",  f->name);
		list_add_record(&(processed->keylist), changes);
		//list_print(processed->keylist);
		in->keylist = NULL; // prevent deleting global keylist
		imfree(&in);
		in = processed;
	}
	return processed;
}
Beispiel #17
0
void table_print_all(IMAGE *img){
	if(!img->tables || img->tables->amount < 1) return;
	size_t i, N = img->tables->amount;
	for(i = 0; i < N; ++i)
		table_print(img->tables->tables[i]);
}
Beispiel #18
0
static int list_images(int argc, char *argv[], void *userdata) {
        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
        _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
        _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
        _cleanup_(table_unrefp) Table *table = NULL;
        int r;

        r = acquire_bus(&bus);
        if (r < 0)
                return r;

        r = sd_bus_call_method(
                        bus,
                        "org.freedesktop.portable1",
                        "/org/freedesktop/portable1",
                        "org.freedesktop.portable1.Manager",
                        "ListImages",
                        &error,
                        &reply,
                        NULL);
        if (r < 0)
                return log_error_errno(r, "Failed to list images: %s", bus_error_message(&error, r));

        table = table_new("name", "type", "ro", "crtime", "mtime", "usage", "state");
        if (!table)
                return log_oom();

        r = sd_bus_message_enter_container(reply, 'a', "(ssbtttso)");
        if (r < 0)
                return bus_log_parse_error(r);

        for (;;) {
                const char *name, *type, *state;
                uint64_t crtime, mtime, usage;
                TableCell *cell;
                bool ro_bool;
                int ro_int;

                r = sd_bus_message_read(reply, "(ssbtttso)", &name, &type, &ro_int, &crtime, &mtime, &usage, &state, NULL);
                if (r < 0)
                        return bus_log_parse_error(r);
                if (r == 0)
                        break;

                r = table_add_many(table,
                                   TABLE_STRING, name,
                                   TABLE_STRING, type);
                if (r < 0)
                        return log_error_errno(r, "Failed to add row to table: %m");

                ro_bool = ro_int;
                r = table_add_cell(table, &cell, TABLE_BOOLEAN, &ro_bool);
                if (r < 0)
                        return log_error_errno(r, "Failed to add row to table: %m");

                if (ro_bool) {
                        r = table_set_color(table, cell, ansi_highlight_red());
                        if (r < 0)
                                return log_error_errno(r, "Failed to set table cell color: %m");
                }

                r = table_add_many(table,
                                   TABLE_TIMESTAMP, crtime,
                                   TABLE_TIMESTAMP, mtime,
                                   TABLE_SIZE, usage);
                if (r < 0)
                        return log_error_errno(r, "Failed to add row to table: %m");

                r = table_add_cell(table, &cell, TABLE_STRING, state);
                if (r < 0)
                        return log_error_errno(r, "Failed to add row to table: %m");

                if (!streq(state, "detached")) {
                        r = table_set_color(table, cell, ansi_highlight_green());
                        if (r < 0)
                                return log_error_errno(r, "Failed to set table cell color: %m");
                }
        }

        r = sd_bus_message_exit_container(reply);
        if (r < 0)
                return bus_log_parse_error(r);

        if (table_get_rows(table) > 1) {
                r = table_set_sort(table, (size_t) 0, (size_t) -1);
                if (r < 0)
                        return log_error_errno(r, "Failed to sort table: %m");

                table_set_header(table, arg_legend);

                r = table_print(table, NULL);
                if (r < 0)
                        return log_error_errno(r, "Failed to show table: %m");
        }

        if (arg_legend) {
                if (table_get_rows(table) > 1)
                        printf("\n%zu images listed.\n", table_get_rows(table) - 1);
                else
                        printf("No images.\n");
        }

        return 0;
}
Beispiel #19
0
/* ------------------------------------------------------------------------------------------ */
void checkInstruction(ins *p){
	reg *rz=NULL;
	reg *rx=NULL;
	reg *ry=NULL;
	reg *rt=NULL;	// temporary register (may or not be used)
	ins *ip=NULL;	// auxiliary instruction pointer (for other registers)
	ins *ti=NULL;	// temporary instruction pointer (to be used with the temporary register)
	ins *mi=NULL;	// main instruction pointer (used with the final instruction)


	/*
	 *  >> input: rz = rx <op> ry
	 *
	 *
	 *	rx = ARP + lookup(rx->value)
	 *    	rx = * rx
	 *    	ry = ARP + lookup(ry->value)
	 *    	ry = * ry
	 *    	rt = rx <op> ry
	 *    	rz = ARP + lookup(rz->value)
	 *	*rz = rt
	 */


	if(p == NULL)
		return;

	#ifdef VERBOSE
		printf("\n");
		table_print(registers);
		printf("[checkInstruction] ");
		printInstruction(p);
	#endif



// :: -------------------------------- ::   THE ALGORITHM   ::

// 1st step:  ensure that 'rx' and 'ry' have register
// --

	// checking 'rx'
	if((p->src1[0] != '\0') && !isNumeric(p->src1)){
		rx=reg_search(p->src1);
		if(rx==NULL){
	
			// allocates register
			rx=reg_ensure(p->src1);
			if(isVar(p->src1)){
				
				// loading the local variable from memory
				load(p->src1);
				
				ip = createInstruction(idx++);
				copy(ip->dst, rx->name);
				ip->arp=true;
				ip->offset=lookup(p->src1);
				append(ip);

				ip = createInstruction(idx++);
				copy(ip->dst, rx->name);
				ip->ops1='*';
				copy(ip->src1, rx->name);
				append(ip);
			}
			if(rx!=NULL){
				// set properties for register
				rx->dist=distance(p, rx->value);
				rx->dirty=false;
			}
		}
	} else rx=NULL;

	// checking 'ry'
	if((p->src2[0] != '\0') && !isNumeric(p->src2)){
		ry=reg_search(p->src2);
		if(ry==NULL){

			// allocates register
			ry=reg_ensure(p->src2);
			if(isVar(p->src2)){
				
				// loading the local variable 'ry' from memory
				load(p->src2);
				
				// loading the local variable 'ry' from memory
				ip = createInstruction(idx++);
				copy(ip->dst, ry->name);
				ip->arp=true;
				ip->offset=lookup(p->src2);
				append(ip);
	
				ip = createInstruction(idx++);
				copy(ip->dst, ry->name);
				ip->ops1='*';
				copy(ip->src1, ry->name);
				append(ip);
			}
			if(ry!=NULL){
				// set properties for register
				ry->dist=distance(p, ry->value);
				ry->dirty=true;
			}
		}
	} else ry=NULL;

// 2nd step: allocate the 'rt' temporary register; creates the 'ti' temporary instruction
// --

	ti = createInstruction(idx++);

	// get 'rx'
	if(isNumeric(p->src1))
		copy(ti->src1, p->src1);  // found a constant
	else if(rx!=NULL)
		copy(ti->src1, rx->name); // got the 'rx'

	// get the operator
	ti->ops2=p->ops2;

	// get 'ry'
	if(isNumeric(p->src2))
		copy(ti->src2, p->src2);  // found a constant
	else if(ry!=NULL)
		copy(ti->src2, ry->name); // got the 'ry'

	if((p->dst[0] != '\0') && !isNumeric(p->dst)){

		// allocate the 'rt' register ("r0" by default)
		rt=reg_search("store");
//		rt=reg_get();
		if(rt!=NULL)
			rt->dirty=false;
	} else rt=NULL; // this could lead to an error
	if(rt!=NULL)
		copy(ti->dst, rt->name);

	append(ti);

// 3rd step: frees if possible frees 'rx' and 'ry'
// --

	// free 'rx'
	if((rx!=NULL) && (rx->dist==MAXDIST || rx->dist==-2))
		reg_free(rx);
	// free 'ry'
	if((ry!=NULL) && (ry->dist==MAXDIST || ry->dist==-2))
		reg_free(ry);

// 4th step: allocate the 'rz' register and create the main instruction 'mi'
// --

	mi = createInstruction(idx++);

	// allocate the 'rz' register
	if((p->dst[0] != '\0') && !isNumeric(p->dst)){

		// store
		store(p->dst);
		rz=reg_search(p->dst);
		if(rz==NULL){
			
			// allocates register
			rz=reg_ensure(p->dst);

			if(isVar(p->dst)){
				// loads the local variable for store operation
				ip = createInstruction(idx++);
				copy(ip->dst, rz->name);
				ip->arp=true;
				ip->offset=lookup(p->dst);
				append(ip);
			}
			if(rz!=NULL){
				// set properties for register
				rz->dist=distance(p, rz->value);
				rz->dirty=false;
			}
		}
	} else rz=NULL; // this would be an error
	if(rz!=NULL)
		copy(mi->dst, rz->name);
	if(rt!=NULL)
		copy(mi->src1, rt->name);
	if(isVar(p->dst))
		mi->opd='*';
	append(mi);


// 5th step: frees 'rt'; if possible frees 'rz'
// --

	#ifdef VERBOSE
		if(rt!=NULL) printf(" [rt] store: %s :: (%s)\n", rt->name, rt->value);
		else printf(" [rt] is null\n");
		if(rz!=NULL) printf(" [rz] store: %s :: (%s)\n", rz->name, rz->value);
		else printf(" [rz] is null\n");
	#endif
	// free 'rt'
	if(rt!=NULL) reg_free(rt);
	// free 'rz'
	if((rz!=NULL) && (rz->dist==MAXDIST || rz->dist<0))
		reg_free(rz);

// 6th step: set the dirty property for the registers
// --
	// check 'rx'
	if(rx!=NULL)
		rx->dirty=true;
	// check 'ry'
	if(ry!=NULL)
		ry->dirty=true;
	// check 'rt'
	if(rt!=NULL)
		rt->dirty=true;
	// check 'rz'
	if(rz!=NULL)
		rz->dirty=false;

// nota: um registo e' dirty apenas quando o seu conteudo e' manipulado na memoria !!!!
//      (confirmar e corrigir se necessario o 6o passo)
//      mudar os valores de dirty para oposto:  'false' <-> 'true'

// :: -------------------------------- ::   THE END   ::

	#ifdef VERBOSE
		table_print(registers);
		printf("\n");
	#endif
	return;
}