Exemplo n.º 1
0
static void hitachi_workaround(void)
{
	if (lge_bd_rev <= LGE_REV_E) {
		/* Use workaround code for 1st cut LCD.
		 * 2010-04-22, [email protected]
		 */
		display_table(mddi_hitachi_2c,
					  sizeof(mddi_hitachi_2c) / sizeof(struct display_table));
	}
	/* Add code to prevent LCD shift.
	 * 2010-05-18, [email protected]
	 */
	display_table(mddi_hitachi_position_table,
				  sizeof(mddi_hitachi_position_table) / sizeof(struct display_table));
}
void read_table(int sock, char buffer[]) {
	char temp[10];
	char *token;
	int n, i, first = 1;
	char delimiter[2] = " ";
	token = strtok(buffer, delimiter);
	token = strtok(NULL, delimiter);
	for (i = 0; i < 5; i++) {

		token = strtok(NULL, delimiter);
		if (token != NULL) {
			strcpy(temp, token);
			table[i].id = atoi(temp);
			token = strtok(NULL, delimiter);
			strcpy(table[i].host_name, token);
			token = strtok(NULL, delimiter);
			strcpy(table[i].ip_address, token);
			token = strtok(NULL, delimiter);
			strcpy(temp, token);
			table[i].portno = atoi(temp);

		}
	}
	display_table();
	write(sock, "RECEIVED UPDATED LIST", 50);		         //notify the server

}
Exemplo n.º 3
0
void print_columns(const struct string_list *list, unsigned int colopts,
		   const struct column_options *opts)
{
	struct column_options nopts;

	if (!list->nr)
		return;
	assert((colopts & COL_ENABLE_MASK) != COL_AUTO);

	memset(&nopts, 0, sizeof(nopts));
	nopts.indent = opts && opts->indent ? opts->indent : "";
	nopts.nl = opts && opts->nl ? opts->nl : "\n";
	nopts.padding = opts ? opts->padding : 1;
	nopts.width = opts && opts->width ? opts->width : term_columns() - 1;
	if (!column_active(colopts)) {
		display_plain(list, "", "\n");
		return;
	}
	switch (COL_LAYOUT(colopts)) {
	case COL_PLAIN:
		display_plain(list, nopts.indent, nopts.nl);
		break;
	case COL_ROW:
	case COL_COLUMN:
		display_table(list, colopts, &nopts);
		break;
	default:
		die("BUG: invalid layout mode %d", COL_LAYOUT(colopts));
	}
}
static int mddi_novatek_lcd_off(struct platform_device *pdev)
{
	display_table(mddi_novatek_sleep_mode_on_data, sizeof(mddi_novatek_sleep_mode_on_data)/sizeof(struct display_table));
	mddi_novatek_lcd_panel_poweroff();
	is_lcd_on = FALSE;
	return 0;
}
Exemplo n.º 5
0
int main() {
   Table *table_ptr;
   int x, y, table_size = 5;
   void *value;

   /***** Starting memory checking *****/
   start_memory_check();
   /***** Starting memory checking *****/

   create_table(&table_ptr, table_size, NULL);
   x = 2;
   put(table_ptr, "Peggy", &x);
   y = 1;
   put(table_ptr, "John", &y);

   printf("Table size: %d\n", get_table_size(table_ptr));
   if (is_empty(table_ptr)) {
      printf("Empty table\n");
   } else {
      printf("Not empty\n");
   }
   get_value(table_ptr, "John", &value);
   printf("Value for John %d\n", *(int *) value);

   printf("Removing Peggy: %d\n", remove_entry(table_ptr, "Peggy"));
   printf("Displaying Table\n");
   display_table(table_ptr);

   clear_table(table_ptr);
   printf("After clearing\n");
   if (is_empty(table_ptr)) {
      printf("Empty table\n");
   } else {
      printf("Not empty\n");
   }
   printf("Displaying Table\n");
   display_table(table_ptr);

   destroy_table(table_ptr);

   /****** Gathering memory checking info *****/
   stop_memory_check();
   /****** Gathering memory checking info *****/

   return 0;
}
Exemplo n.º 6
0
/* imprime clientes entrando */
void insert_client(int client_id) {
	int i;  

	if(eating == 1) {
		for(i=0; i<NO_OF_CUSTOMERS; i++) {
			usleep(TIMER);
			display_table(client_id); 
		}
		active[client_id] = 1;
	}
	else {
		for(i=0; i<(NO_OF_CUSTOMERS); i++) {
			usleep(TIMER);
			display_table(client_id); 
		}
		active[client_id] = 1;
	}
}
void client_register(char msg[], int sockfd) {
	int i, portno;
	char* token, hostname;
	char ip[15];

	char delimiter[2] = " ";
	token = strtok(msg, ":");
	token = strtok(NULL, delimiter);

	strcpy(ip, token);
	token = strtok(NULL, delimiter);

	portno = atoi(token);

	/////checking for duplicate connection////
	for (i = 1; i < 5; i++) {

		if ((strcmp(table[i].ip_address, ip) == 0)
				&& (table[i].portno == portno)) {
			write(table[i].clientfd, "DUPLICATE CONNECTION", 18);
			return;

		}
	}

	/*****finding empty entry*******/
	for (i = 1; i < 5; i++) {
		if (table[i].id == -1)
			break;
	}
	/*******************************/

	/*******checking if server list full*****/

	if (i == 5) {
		///means table full
		write(sockfd, "SERVER FULL", 40); //if full send message full
		return;

	}

	/*****************************************/

	/*adding the new client to list*/
	table[i].id = i + 1;
	table[i].clientfd = sockfd;
	token = strtok(NULL, delimiter);
	strcpy(table[i].host_name, token);
	strcpy(table[i].ip_address, ip);
	table[i].portno = portno;
	/******************************/

	/*******displaying the updated table********/
	display_table();
	write(sockfd, "REGISTRATION COMPLETE", 40);
	send_table(); //sending the updated table to all existing clients
}
Exemplo n.º 8
0
/*Test4 tests inserting a large number of keys, chekcing key_count, deleting a few, rechecking the
key_count, then clearing the entire table. We will then reinsert some keys.*/
static int test4(){
   int x = 1, y =2, z = 3, w =4, k = 5, a =6, b =7
   , c =8, d = 9, e = 10, f = 11, g = 12;
   Table *t;

   /*Creates table and adds 13 keys to it.*/
   create_table(&t, z, NULL);
   put(t, "Krabs", &a);
   put(t, "Larry", &b);
   put(t, "Herminator", &c);
   put(t, "Brian", &d);
   put(t, "Steve", &e);
   put(t, "Nelson", &f);
   put(t, "Corwin", &g);
   put(t, "Spongebob", &x);
   put(t, "Patrick", &y);
   put(t, "Squidward", &z);
   put(t, "Sandy", &w);
   put(t, "Art thou feeling it now,", NULL);
   put(t, "Mr. Krabs?", &k);
   printf("%d\n", get_key_count(t));
   display_table(t);
   /*Removes two keys from the table, then rechekcs key_count and
   displays the state of the table.*/
   remove_entry(t,"Mr. Krabs?");
   remove_entry(t,"Art thou feeling it now,");
   printf("%d\n", get_key_count(t));
   display_table(t);

   /*Clears the table, then rechecks the key_count.*/
   clear_table(t);
   printf("%d\n", get_key_count(t));
   /*Reinserts 7 keys, then checks the state of the table again.*/
   put(t, "A1", &a);
   put(t, "A2", &b);
   put(t, "A3", &c);
   put(t, "A4", &d);
   put(t, "A5", &e);
   put(t, "A6", &f);
   put(t, "A7", &g);
   display_table(t);
   destroy_table(t);
   return SUCCESS;
}
Exemplo n.º 9
0
static int mddi_hitachi_lcd_on(struct platform_device *pdev)
{
	EPRINTK("%s: started.\n", __func__);

#if defined(CONFIG_MACH_MSM7X27_THUNDERG) || defined(CONFIG_MACH_MSM7X27_THUNDERC) || defined(CONFIG_MACH_MSM7X27_THUNDERA)
	if (system_state == SYSTEM_BOOTING && mddi_hitachi_pdata->initialized) {
		hitachi_workaround();
		is_lcd_on = TRUE;
		return 0;
	}
#endif
	// LCD HW Reset
	mddi_hitachi_lcd_panel_poweron();
#if defined(CONFIG_MACH_MSM7X27_THUNDERG)
	if (lge_bd_rev <= LGE_REV_E) {
		EPRINTK("ThunderG ==> lge_bd_rev = %d : 1st LCD initial\n", lge_bd_rev);
		display_table(mddi_hitachi_initialize_1st, sizeof(mddi_hitachi_initialize_1st)/sizeof(struct display_table));
		display_table(mddi_hitachi_display_on_1st, sizeof(mddi_hitachi_display_on_1st) / sizeof(struct display_table));
	} else {
		EPRINTK("ThunderG ==> lge_bd_rev = %d : 3rd LCD initial\n", lge_bd_rev);
		display_table(mddi_hitachi_initialize_3rd_p500, sizeof(mddi_hitachi_initialize_3rd_p500)/sizeof(struct display_table));
		display_table(mddi_hitachi_display_on_3rd, sizeof(mddi_hitachi_display_on_3rd) / sizeof(struct display_table));
	}
#elif defined(CONFIG_MACH_MSM7X27_THUNDERA)
	display_table(mddi_hitachi_initialize_1st, 
			sizeof(mddi_hitachi_initialize_1st)/sizeof(struct display_table));
	display_table(mddi_hitachi_display_on_1st,
			sizeof(mddi_hitachi_display_on_1st) / sizeof(struct display_table));
#else
	if (lge_bd_rev <= LGE_REV_D) {
		EPRINTK("ThunderC ==> lge_bd_rev = %d : 1st LCD initial\n", lge_bd_rev);
		display_table(mddi_hitachi_initialize_1st, sizeof(mddi_hitachi_initialize_1st)/sizeof(struct display_table));
		display_table(mddi_hitachi_display_on_1st, sizeof(mddi_hitachi_display_on_1st) / sizeof(struct display_table));
	} else {
		EPRINTK("ThunderC ==> lge_bd_rev = %d : 3rd LCD initial\n", lge_bd_rev);
		display_table(mddi_hitachi_initialize_3rd_vs660, sizeof(mddi_hitachi_initialize_3rd_vs660)/sizeof(struct display_table));
		display_table(mddi_hitachi_display_on_3rd, sizeof(mddi_hitachi_display_on_3rd) / sizeof(struct display_table));
	}
#endif
	is_lcd_on = TRUE;
	return 0;
}
Exemplo n.º 10
0
static int mddi_hitachi_lcd_store_on(void)
{
	EPRINTK("%s: started.\n", __func__);

#if defined(CONFIG_MACH_MSM7X27_THUNDERG) || defined(CONFIG_MACH_MSM7X27_THUNDERC) || defined(CONFIG_MACH_MSM7X27_THUNDERA)
	if (system_state == SYSTEM_BOOTING && mddi_hitachi_pdata->initialized) {
		is_lcd_on = TRUE;
		return 0;
	}
#endif
	// LCD HW Reset
	mddi_hitachi_lcd_panel_store_poweron();
#if defined(CONFIG_MACH_MSM7X27_THUNDERG)
	if (lge_bd_rev <= LGE_REV_E) {
		display_table(mddi_hitachi_initialize_1st, sizeof(mddi_hitachi_initialize_1st)/sizeof(struct display_table));
		mdelay(10);
		display_table(mddi_hitachi_display_on_1st, sizeof(mddi_hitachi_display_on_1st) / sizeof(struct display_table));
	} else {
		display_table(mddi_hitachi_initialize_3rd_p500, sizeof(mddi_hitachi_initialize_3rd_p500)/sizeof(struct display_table));
		mdelay(10);
		display_table(mddi_hitachi_display_on_3rd, sizeof(mddi_hitachi_display_on_3rd) / sizeof(struct display_table));
	}
#elif defined(CONFIG_MACH_MSM7X27_THUNDERA)
	display_table(mddi_hitachi_initialize_1st,
			sizeof(mddi_hitachi_initialize_1st)/sizeof(struct display_table));
	mdelay(10);
	display_table(mddi_hitachi_display_on_1st,
			sizeof(mddi_hitachi_display_on_1st) / sizeof(struct display_table));
#else
	if (lge_bd_rev <= LGE_REV_D) {
		display_table(mddi_hitachi_initialize_1st, sizeof(mddi_hitachi_initialize_1st)/sizeof(struct display_table));
		mdelay(10);
		display_table(mddi_hitachi_display_on_1st, sizeof(mddi_hitachi_display_on_1st) / sizeof(struct display_table));
	} else {
		display_table(mddi_hitachi_initialize_3rd_vs660, sizeof(mddi_hitachi_initialize_3rd_vs660)/sizeof(struct display_table));
		mdelay(10);
		display_table(mddi_hitachi_display_on_3rd, sizeof(mddi_hitachi_display_on_3rd) / sizeof(struct display_table));
	}
#endif
	is_lcd_on = TRUE;
	return 0;
}
Exemplo n.º 11
0
int main(int argc, char *argv[])
{
	
	FILE* fwrite = fopen("topology","w+");
	FILE* fdraw = fopen("draw_combine.dot","w+");

	struct dirent *pDirEntry = NULL;
    DIR *pDir = NULL;
    if( (pDir = opendir("./")) == NULL )
    {
		printf("opendir failed!\n");
		return 1;
	}
    else
    {
		
		
		
		while( pDirEntry = readdir(pDir) )
		{
			
			if ( strstr(pDirEntry->d_name, "out")
				&& pDirEntry->d_name[0]=='o'
				&& pDirEntry->d_name[1]=='u'
				&& pDirEntry->d_name[2]=='t')
			{
                printf("输入文件:%s \n",pDirEntry->d_name);
				
				load_edge(pDirEntry->d_name);
			
				printf("------------------------------------\n");
			}
		}
		closedir(pDir);

	}       
	
	fprintf(fdraw, "digraph G {\n\t rankdir=LR;\n");
	
	display_table(fwrite,fdraw);
	
	print_router(fdraw);
	
	fprintf(fdraw, "}");
	
	fclose(fwrite);
	fclose(fdraw);
	
	cluster();
	
	return 0;
}
int main()
{
	int hash_table[m];
	char buffer[128];
	char response;
	int value;
	int i;
	for(i=0; i<m; i++)
		hash_table[i] = NIL_VALUE;
	
	do
	{
		printf("Enter a to insert, s to search, d to delete, f to display the hash table and e to exit\n");
		fgets(buffer, 128, stdin);
		sscanf(buffer, "%c", &response);
		switch(response)
		{
			case 'a':
				printf("Enter value to insert: ");
				fgets(buffer, 128, stdin);
				sscanf(buffer, "%d", &value);
				insert_in_table(hash_table, value);
				break;
			case 's':
				printf("Enter value to search: ");
				fgets(buffer, 128, stdin);
				sscanf(buffer, "%d", &value);
				if(search_in_table(hash_table, value) != -1)
					printf("%d is present\n", value);
				else
					printf("%d is not present\n", value);
				break;
			/*case 'd':
				printf("Enter value to delete: ");
				fgets(buffer, 128, stdin);
				sscanf(buffer, "%d", &value);
				delete_from_table(hash_table, value);
				break;*/
			case 'f':
				display_table(hash_table);
				break;
			case 'e':
				break;
			default:
				printf("Wrong option\n");
				break;
		}
	}
	while(response != 'e');
	return 1;
}
Exemplo n.º 13
0
int
main(void)
{
      double sales[NUM_SALES_PEOPLE][NUM_QUARTERS]; /* table of sales */
      double person_totals[NUM_SALES_PEOPLE];       /* row totals */
      double quarter_totals[NUM_QUARTERS];          /* column totals */
      int    status;

      status = scan_table(sales, NUM_SALES_PEOPLE);
      if (status == 1) {
            sum_rows(person_totals, sales, NUM_SALES_PEOPLE);
            sum_columns(quarter_totals, sales, NUM_SALES_PEOPLE);
            display_table(sales, person_totals, quarter_totals, 
                          NUM_SALES_PEOPLE);
      } 
      return (0);
}
static int mddi_novatek_lcd_on(struct platform_device *pdev)
{
	EPRINTK("%s: started.\n", __func__);

	if(is_lcd_on == -1) {
		is_lcd_on = TRUE;
		return 0;
	}
	if (system_state == SYSTEM_BOOTING && mddi_novatek_pdata->initialized) {
		is_lcd_on = TRUE;
	}

#ifdef CONFIG_MACH_MSM7X27_THUNDERC_SPRINT
	ts_set_vreg(1);
#endif

	// LCD HW Reset
	mddi_novatek_lcd_panel_poweron();	
	display_table(mddi_novatek_initialize, sizeof(mddi_novatek_initialize)/sizeof(struct display_table));
	// display_table(mddi_novatek_display_on, sizeof(mddi_novatek_display_on) / sizeof(struct display_table));
	is_lcd_on = TRUE;
	return 0;
}
Exemplo n.º 15
0
/* imprime clientes saindo */
void remove_client(int client_id) {

	int i, n_clients = 0;

	for(i=0; i<NO_OF_CUSTOMERS; i++) {
		if(active[i] != 0)
			n_clients++;
	}

	if(n_clients != 5) {
		for(i=0; i<NO_OF_CUSTOMERS; i++) {
			if(state[i] == L) {
				active[i] = 0;
				leaving--;
			}
		}
	}
	else {
		if(leaving == 5) {
			all_leaving = 1;

			for(i=0; i<NO_OF_CUSTOMERS; i++) {
				usleep(TIMER);
				display_table(client_id);
			}

			all_leaving = 0;

			leaving = 0;

			for(i=0; i<NO_OF_CUSTOMERS; i++) {
				active[i] = 0;
			}
		}
	}
}
Exemplo n.º 16
0
/*Tests creating a table, placing key/value pairs in it, getting values from the table,
 clearing the entire table, then reinserting some key/value pairs and getting 
 their values. Also tests get_table_size */
static int test2() {
   int table_size = 4, x = 1, y = 3, z = 4, w = 5,
   a = 10, b = 2, c = 7, d = 8, e = 9, f = 12, g = 13;
   Table *t;
   void *value1, *value2, *value3, *value4, *value5, *value6,
    *value7, *value8, *value9, *value10, *value11;

   create_table(&t, table_size, NULL);
   /*Insert 4 keys into the table.*/
   put(t, "Spongebob", &x);
   put(t, "Patrick", &y);
   put(t, "Squidward", &z);
   put(t, "Sandy", &w);
   /*Check that each key has the correct value, and that get_value is
   operating correctly.*/
   get_value(t, "Spongebob", &value1);
   get_value(t, "Patrick", &value2);
   get_value(t, "Squidward", &value3);
   get_value(t, "Sandy", &value4);
   printf("Value for Spongebob: %d\n", *(int *) value1);
   printf("Value for Patrick: %d\n", *(int *) value2);
   printf("Value for Squidward: %d\n", *(int *) value3);
   printf("Value for Sandy: %d\n", *(int *) value4);
   printf("\n");
   /*Check the State of the entire table.*/
   display_table(t);
   /*Clear the entire table.*/
   clear_table(t);
   /*Check that get_table_size and get_key_count are workign correctly.*/
   if(get_table_size(t) != 4 || get_key_count(t) != 0){
      return FAILURE;
   }
   /*Make sure the table is empty.*/
   display_table(t);
   /*Reinsert 7 keys.*/
   put(t, "Krabs", &a);
   put(t, "Larry", &b);
   put(t, "Herminator", &c);
   put(t, "Brian", &d);
   put(t, "Steve", &e);
   put(t, "Nelson", &f);
   put(t, "Corwin", &g);
   /*Check that these keys have the correct values associated witht hem.*/
   get_value(t, "Krabs", &value5);
   get_value(t, "Larry", &value6);
   get_value(t, "Herminator", &value7);
   get_value(t, "Brian", &value8);
   get_value(t, "Steve", &value9);
   get_value(t, "Nelson", &value10);
   get_value(t, "Corwin", &value11);
   printf("Value for Krabs: %d\n", *(int *) value5);
   printf("Value for Larry: %d\n", *(int *) value6);
   printf("Value for Herminator: %d\n", *(int *) value7);
   printf("Value for Brian: %d\n", *(int *) value8);
   printf("Value for Steve: %d\n", *(int *) value9);
   printf("Value for Nelson: %d\n", *(int *) value10);
   printf("Value for Corwin: %d\n", *(int *) value11);
   /*Check the state of the entire table, especially to see if any keys from 
   before clear_table was called are left over. */
   display_table(t);
   printf("\n\n");

   destroy_table(t);
   return SUCCESS;
}
Exemplo n.º 17
0
void* sushi_bar(void* arg) { 
	int client_id = *(int *) arg;

	while(1){

		pthread_mutex_lock(&mutex);

		if(must_wait) { 
			waiting+=1;

			/* CLIENTE ESPERANDO */
			state[client_id] = W;
			display_table(client_id);

			/* MUTEX LIBERADO */
			pthread_mutex_unlock(&mutex);

			sem_wait(&block);
			waiting -= 1;
		} 
		eating+=1;
		must_wait = (eating == 5);

		/* muda o estado do cliente para SITTING */
		state[client_id] = S;
		insert_client(client_id);

		/* muda estado do cliente para COMENDO */
		state[client_id] = E;
		display_table(client_id);


		/* MUTEX LIBERADO */
		if(waiting && !must_wait) 
			sem_post(&block);
		else
			pthread_mutex_unlock(&mutex);

		/* Sleep randomico para cada thread comer */
		sleep(rand() % 10 + 1);

		pthread_mutex_lock(&mutex);
		eating-=1;
		state[client_id] = L;

		/* CLIENTE SAINDO */
		display_table(client_id);
		leaving++;
		remove_client(client_id);

		if(eating == 0)
			must_wait = 0;

		/* Muda o estado do cliente para OUT (saiu do Sushi Bar) */
		state[client_id] = O;
		if(waiting && !must_wait)
			sem_post(&block);
		else
			pthread_mutex_unlock(&mutex);

		/* cliente espera 3s fora do bar */
		sleep(3);
	} 
} 
Exemplo n.º 18
0
int mddi_hitachi_position(void)
{
	display_table(mddi_hitachi_position_table, ARRAY_SIZE(mddi_hitachi_position_table));
	return 0;
}
Exemplo n.º 19
0
int main()
{
	int i,j,len,bs,state,pos;
	char str[MAX];
	char id[MAX];
	bs = 0;
	printf("\nEnter the string : \n");
	gets(str);
	printf("\n");
	state =0;

	for(i=0; i<strlen(str); i++)
	{
		if(isalpha(str[i]))
		{
		   switch(state)
		   {	
				//int,if,for,case,while
				case 0:
					if(str[i]=='i' || str[i]=='f' || str[i]=='c' || str[i]=='w')
						state = 1;
					else
					{
						state = 0;
						id[0] = str[i];
						printf("Identifier - %c\n",str[i]);
						insert("identifier",id);						
					}
					break;
				
				case 1 :
					if(str[i]=='n' || str[i]=='o' || str[i]=='a' || str[i]=='h')
						state = 2;
					else if(str[i] =='f')
					{
						state = 0;
						printf("Keyword - if \n");
						insert("keyword","if");	
					}
					else
					{
						state = 0;
						id[0] = 'i';
						printf("Identifier - i%c\n",str[i]);
						insert("identifier",id);						
					}
					break;
					
				case 2:
					if(str[i]=='t')
					{
						state = 0;
						printf("Keyword - int \n");
						insert("keyword","int");
					}
					else if(str[i]=='r')
					{
						state = 0;
						printf("Keyword - for \n");
						insert("keyword","for");
					}
					else if(str[i]=='s' || str[i]=='i')
						state = 3;
					break;
				
				case 3:
					if(str[i]=='e')
					{
						state = 0;
						printf("Keyword - case \n");
						insert("keyword","case");
					}
					else if(str[i]=='l')
						state = 4;
					break;
				
				case 4:
					if(str[i]=='e')
					{
						state = 0;
						printf("Keyword - while \n");
						insert("keyword","while");
					}
			}
			
			if(state == 1 && !isalpha(str[i+1]))
			{
				state = 0;
				id[0] = 'i';
				printf("Identifier - i \n");
				insert("identifier",id);
			}
		}
		
		else
		{
			switch(str[i])
			{
				case ' ':
					printf("Blank Space \n");
					bs++;
					break;
					
				case '<':
					printf("Relational Operator < \n");
					insert("operator","<");
					break;
					
				case '>':
					printf("Relational Operator > \n");
					insert("operator",">");
					break;
					
				case '=':
					printf("Assignment Operator = \n");
					insert("operator","=");
					break;
					
				case '!':
					if(str[i+1] == '=')
					{
						printf("Relational Operator != \n");
						//insert("operator","!=");
						i++;
					}
					else
					{
						printf("Unary Operator ! \n");
						insert("operator","!");
					}
					break;
				
				case '+':
					printf("Arithmetic Operator + \n");
					insert("operator","+");
					break;	
					
				case '-':
					printf("Arithmetic Operator - \n");
					insert("operator","-");
					break;	
					
				default:
					if(str[i]=='0' || str[i]=='1' || str[i]=='2' || str[i]=='3' || str[i]=='4' || str[i]=='5' || str[i]=='6' || 
					   str[i]=='7' || str[i]=='8' || str[i]=='9')
					{
						printf("Constant %c \n",str[i]);
						id[0] = str[i];
						insert("constant",id);
					}
					else
						printf("Undefined Default Character \n");
			}
		}
	}
	printf("Number of blank spaces = %d  \n",bs);
	display_table();
	return 0;
}
Exemplo n.º 20
0
static void mdp_dma2_update_lcd(struct msm_fb_data_type *mfd)
{
	MDPIBUF *iBuf = &mfd->ibuf;
	int mddi_dest = FALSE;
	uint32 outBpp = iBuf->bpp;
	uint32 dma2_cfg_reg;
	uint8 *src;
	uint32 mddi_ld_param;
	uint16 mddi_vdo_packet_reg;
	struct msm_fb_panel_data *pdata =
	    (struct msm_fb_panel_data *)mfd->pdev->dev.platform_data;
	uint32 ystride = mfd->fbi->fix.line_length;
	uint32 mddi_pkt_desc;

	dma2_cfg_reg = DMA_PACK_ALIGN_LSB |
		    DMA_OUT_SEL_AHB | DMA_IBUF_NONCONTIGUOUS;

#ifdef CONFIG_FB_MSM_MDP22
	dma2_cfg_reg |= DMA_PACK_TIGHT;
#endif

#ifdef CONFIG_FB_MSM_MDP30
	/*
	 * Software workaround:  On 7x25/7x27, the MDP will not
	 * respond if dma_w is 1 pixel.  Set the update width to
	 * 2 pixels and adjust the x offset if needed.
	 */
	if (iBuf->dma_w == 1) {
		iBuf->dma_w = 2;
		if (iBuf->dma_x == (iBuf->ibuf_width - 2))
			iBuf->dma_x--;
	}
#endif

	if (mfd->fb_imgType == MDP_BGR_565)
		dma2_cfg_reg |= DMA_PACK_PATTERN_BGR;
	else if (mfd->fb_imgType == MDP_RGBA_8888)
		dma2_cfg_reg |= DMA_PACK_PATTERN_BGR;
	else
		dma2_cfg_reg |= DMA_PACK_PATTERN_RGB;

	if (outBpp == 4) {
		dma2_cfg_reg |= DMA_IBUF_C3ALPHA_EN;
		dma2_cfg_reg |= DMA_IBUF_FORMAT_xRGB8888_OR_ARGB8888;
	}

	if (outBpp == 2)
		dma2_cfg_reg |= DMA_IBUF_FORMAT_RGB565;

	mddi_ld_param = 0;
	mddi_vdo_packet_reg = mfd->panel_info.mddi.vdopkt;

	if ((mfd->panel_info.type == MDDI_PANEL) ||
	    (mfd->panel_info.type == EXT_MDDI_PANEL)) {
		dma2_cfg_reg |= DMA_OUT_SEL_MDDI;
		mddi_dest = TRUE;

		if (mfd->panel_info.type == MDDI_PANEL) {
			mdp_total_vdopkts++;
			if (mfd->panel_info.pdest == DISPLAY_1) {
				dma2_cfg_reg |= DMA_MDDI_DMAOUT_LCD_SEL_PRIMARY;
				mddi_ld_param = 0;
#ifdef MDDI_HOST_WINDOW_WORKAROUND
				mddi_window_adjust(mfd, iBuf->dma_x,
						   iBuf->dma_w - 1, iBuf->dma_y,
						   iBuf->dma_h - 1);
#endif
			} else {
				dma2_cfg_reg |=
				    DMA_MDDI_DMAOUT_LCD_SEL_SECONDARY;
				mddi_ld_param = 1;
#ifdef MDDI_HOST_WINDOW_WORKAROUND
				mddi_window_adjust(mfd, iBuf->dma_x,
						   iBuf->dma_w - 1, iBuf->dma_y,
						   iBuf->dma_h - 1);
#endif
			}
		} else {
			dma2_cfg_reg |= DMA_MDDI_DMAOUT_LCD_SEL_EXTERNAL;
			mddi_ld_param = 2;
		}
	} else {
		if (mfd->panel_info.pdest == DISPLAY_1) {
			dma2_cfg_reg |= DMA_AHBM_LCD_SEL_PRIMARY;
			outp32(MDP_EBI2_LCD0, mfd->data_port_phys);
		} else {
			dma2_cfg_reg |= DMA_AHBM_LCD_SEL_SECONDARY;
			outp32(MDP_EBI2_LCD1, mfd->data_port_phys);
		}
	}

	dma2_cfg_reg |= DMA_DITHER_EN;

	src = (uint8 *) iBuf->buf;
	/* starting input address */
	src += iBuf->dma_x * outBpp + iBuf->dma_y * ystride;

	mdp_curr_dma2_update_width = iBuf->dma_w;
	mdp_curr_dma2_update_height = iBuf->dma_h;

#if defined(CONFIG_FB_MSM_MDDI_NOVATEK_HITACHI_HVGA)
	if (g_mddi_lcd_probe== 0) {
		hitachi_display_table(mddi_hitachi_position_table,
			sizeof(mddi_hitachi_position_table) / 
			sizeof(struct hitachi_display_table));
	}
	else {
		display_table(mddi_novatek_position_table, 
			sizeof(mddi_novatek_position_table) / 
			sizeof(struct display_table));
	}
#elif defined(CONFIG_FB_MSM_MDDI_HITACHI_HVGA) 
#if defined(CONFIG_MACH_MSM7X27_THUNDERG) || defined(CONFIG_MACH_MSM7X27_THUNDERC)
	hitachi_display_table(mddi_hitachi_position_table,
			sizeof(mddi_hitachi_position_table) / 
			sizeof(struct hitachi_display_table));
#elif defined(CONFIG_MACH_MSM7X27_THUNDERA)
	hitachi_display_table(mddi_hitachi_2c,
			sizeof(mddi_hitachi_2c) / 
			sizeof(struct hitachi_display_table));
#endif
#elif CONFIG_FB_MSM_MDDI_NOVATEK_HVGA
	display_table(mddi_novatek_position_table, 
		sizeof(mddi_novatek_position_table) / 
		sizeof(struct display_table));
#endif /* CONFIG_FB_MSM_MDDI_NOVATEK_HITACHI_HVGA */

	/* MDP cmd block enable */
	mdp_pipe_ctrl(MDP_CMD_BLOCK, MDP_BLOCK_POWER_ON, FALSE);

#ifdef CONFIG_FB_MSM_MDP22
	MDP_OUTP(MDP_CMD_DEBUG_ACCESS_BASE + 0x0184,
			(iBuf->dma_h << 16 | iBuf->dma_w));
	MDP_OUTP(MDP_CMD_DEBUG_ACCESS_BASE + 0x0188, src);
	MDP_OUTP(MDP_CMD_DEBUG_ACCESS_BASE + 0x018C, ystride);
#else
	MDP_OUTP(MDP_BASE + 0x90004, (iBuf->dma_h << 16 | iBuf->dma_w));
	MDP_OUTP(MDP_BASE + 0x90008, src);
	MDP_OUTP(MDP_BASE + 0x9000c, ystride);
#endif

	if (mfd->panel_info.bpp == 18) {
		mddi_pkt_desc = MDDI_VDO_PACKET_DESC;
		dma2_cfg_reg |= DMA_DSTC0G_6BITS |	/* 666 18BPP */
		    DMA_DSTC1B_6BITS | DMA_DSTC2R_6BITS;
	} else if (mfd->panel_info.bpp == 24) {
		mddi_pkt_desc = MDDI_VDO_PACKET_DESC_24;
		dma2_cfg_reg |= DMA_DSTC0G_8BITS |      /* 888 24BPP */
			DMA_DSTC1B_8BITS | DMA_DSTC2R_8BITS;
	} else {
		mddi_pkt_desc = MDDI_VDO_PACKET_DESC_16;
		dma2_cfg_reg |= DMA_DSTC0G_6BITS |	/* 565 16BPP */
		    DMA_DSTC1B_5BITS | DMA_DSTC2R_5BITS;
	}

	if (mddi_dest) {
#ifdef CONFIG_FB_MSM_MDP22
		MDP_OUTP(MDP_CMD_DEBUG_ACCESS_BASE + 0x0194,
			 (iBuf->dma_y << 16) | iBuf->dma_x);
		MDP_OUTP(MDP_CMD_DEBUG_ACCESS_BASE + 0x01a0, mddi_ld_param);

#if defined(CONFIG_FB_MSM_MDDI_NOVATEK_HITACHI_HVGA)		
		if (g_mddi_lcd_probe == 0) { /* Hitachi LCD */
			MDP_OUTP(MDP_CMD_DEBUG_ACCESS_BASE + 0x01a4,
				(MDDI_VDO_PACKET_DESC << 16) | mddi_vdo_packet_reg);
		}
		else { /* Novatek LCD */
			MDP_OUTP(MDP_CMD_DEBUG_ACCESS_BASE + 0x01a4,
				(mddi_pkt_desc << 16) | mddi_vdo_packet_reg);
		}
#elif defined (CONFIG_FB_MSM_MDDI_HITACHI_HVGA)		
		MDP_OUTP(MDP_CMD_DEBUG_ACCESS_BASE + 0x01a4,
			(MDDI_VDO_PACKET_DESC << 16) | mddi_vdo_packet_reg);
#else
		MDP_OUTP(MDP_CMD_DEBUG_ACCESS_BASE + 0x01a4,
			(mddi_pkt_desc << 16) | mddi_vdo_packet_reg);
#endif
#else /* !CONFIG_FB_MSM_MDP22 */
		MDP_OUTP(MDP_BASE + 0x90010, (iBuf->dma_y << 16) | iBuf->dma_x);
		MDP_OUTP(MDP_BASE + 0x00090, mddi_ld_param);

#if defined(CONFIG_FB_MSM_MDDI_NOVATEK_HITACHI_HVGA)		
		if (g_mddi_lcd_probe == 1) {
			MDP_OUTP(MDP_BASE + 0x00094,
				(0x5565 /*MDDI_VDO_PACKET_DESC*/ << 16) | 
				mddi_vdo_packet_reg);
		}
		else {
			MDP_OUTP(MDP_BASE + 0x00094,
				(MDDI_VDO_PACKET_DESC << 16) | mddi_vdo_packet_reg);
		}
#elif defined(CONFIG_FB_MSM_MDDI_NOVATEK_HVGA)
		MDP_OUTP(MDP_BASE + 0x00094,
			 (0x5565 /*MDDI_VDO_PACKET_DESC*/ << 16) | mddi_vdo_packet_reg);
#elif defined (CONFIG_FB_MSM_MDDI_HITACHI_HVGA)
		MDP_OUTP(MDP_BASE + 0x00094,
			(MDDI_VDO_PACKET_DESC << 16) | mddi_vdo_packet_reg);
#else
		MDP_OUTP(MDP_BASE + 0x00094,
			(mddi_pkt_desc << 16) | mddi_vdo_packet_reg);
#endif
#endif /* CONFIG_FB_MSM_MDP22 */
	} else {
		/* setting EBI2 LCDC write window */
		pdata->set_rect(iBuf->dma_x, iBuf->dma_y, iBuf->dma_w,
				iBuf->dma_h);
	}

	/* dma2 config register */
#ifdef MDP_HW_VSYNC
	MDP_OUTP(MDP_BASE + 0x90000, dma2_cfg_reg);

	if ((mfd->use_mdp_vsync) &&
	    (mfd->ibuf.vsync_enable) && (mfd->panel_info.lcd.vsync_enable)) {
		uint32 start_y;

		if (vsync_start_y_adjust <= iBuf->dma_y)
			start_y = iBuf->dma_y - vsync_start_y_adjust;
		else
			start_y =
			    (mfd->total_lcd_lines - 1) - (vsync_start_y_adjust -
							  iBuf->dma_y);

		/*
		 * MDP VSYNC clock must be On by now so, we don't have to
		 * re-enable it
		 */
		MDP_OUTP(MDP_BASE + 0x210, start_y);
		MDP_OUTP(MDP_BASE + 0x20c, 1);	/* enable prim vsync */
	} else {
		MDP_OUTP(MDP_BASE + 0x20c, 0);	/* disable prim vsync */
	}
#else
#ifdef CONFIG_FB_MSM_MDP22
	MDP_OUTP(MDP_CMD_DEBUG_ACCESS_BASE + 0x0180, dma2_cfg_reg);
#else
	MDP_OUTP(MDP_BASE + 0x90000, dma2_cfg_reg);
#endif
#endif /* MDP_HW_VSYNC */

	/* MDP cmd block disable */
	mdp_pipe_ctrl(MDP_CMD_BLOCK, MDP_BLOCK_POWER_OFF, FALSE);
}
Exemplo n.º 21
0
int main(int argc, char *argv[])
{
	int dev_from_class = 0, write_cnt;
	int fd;
	static struct sysfs_names *names;
	struct rc_device	  rc_dev;

	argp_parse(&argp, argc, argv, 0, 0, 0);

	/* Just list all devices */
	if (!clear && !read && !keys.next && !ch_proto && !cfg.next) {
		static struct sysfs_names *names, *cur;

		names = find_device(NULL);
		if (!names)
			return -1;
		for (cur = names; cur->next; cur = cur->next) {
			if (cur->name) {
				if (get_attribs(&rc_dev, cur->name))
					return -1;
				fprintf(stderr, "Found %s (%s) with:\n",
					rc_dev.sysfs_name,
					rc_dev.input_name);
				fprintf(stderr, "\tDriver %s, %s decoder, table %s\n",
					rc_dev.drv_name,
					(rc_dev.type == SOFTWARE_DECODER) ?
						"raw software" : "hardware",
					rc_dev.keytable_name);
				fprintf(stderr, "\tSupported protocols: ");
				show_proto(rc_dev.supported);
				fprintf(stderr, "\t");
				display_proto(&rc_dev);
			}
		}
		return 0;
	}

	if (cfg.next && (clear || keys.next || ch_proto || devname)) {
		fprintf (stderr, "Auto-mode can be used only with --read, --debug and --sysdev options\n");
		return -1;
	}
	if (!devname) {
		names = find_device(devclass);
		if (!names)
			return -1;
		rc_dev.sysfs_name = names->name;
		if (get_attribs(&rc_dev, names->name)) {
			free_names(names);
			return -1;
		}
		names->name = NULL;
		free_names(names);

		devname = rc_dev.input_name;
		dev_from_class++;
	}

	if (cfg.next) {
		struct cfgfile *cur;
		char *fname, *name;
		int rc;

		for (cur = &cfg; cur->next; cur = cur->next) {
			if (strcasecmp(cur->driver, rc_dev.drv_name) && strcasecmp(cur->driver, "*"))
				continue;
			if (strcasecmp(cur->table, rc_dev.keytable_name) && strcasecmp(cur->table, "*"))
				continue;
			break;
		}

		if (!cur->next) {
			if (debug)
				fprintf(stderr, "Table for %s, %s not found. Keep as-is\n",
				       rc_dev.drv_name, rc_dev.keytable_name);
			return 0;
		}
		if (debug)
			fprintf(stderr, "Table for %s, %s is on %s file.\n",
				rc_dev.drv_name, rc_dev.keytable_name,
				cur->fname);
		if (cur->fname[0] == '/' || ((cur->fname[0] == '.') && strchr(cur->fname, '/'))) {
			fname = cur->fname;
		} else {
			fname = malloc(strlen(cur->fname) + strlen(CFGDIR) + 2);
			strcpy(fname, CFGDIR);
			strcat(fname, "/");
			strcat(fname, cur->fname);
		}
		rc = parse_keyfile(fname, &name);
		if (rc < 0 || !keys.next) {
			fprintf(stderr, "Can't load %s table or empty table\n", fname);
			return -1;
		}
		clear = 1;
	}

	if (debug)
		fprintf(stderr, "Opening %s\n", devname);
	fd = open(devname, O_RDONLY);
	if (fd < 0) {
		perror(devname);
		return -1;
	}
	if (dev_from_class)
		free(devname);

	/*
	 * First step: clear, if --clear is specified
	 */
	if (clear) {
		clear_table(fd);
		fprintf(stderr, "Old keytable cleared\n");
	}

	/*
	 * Second step: stores key tables from file or from commandline
	 */
	write_cnt = add_keys(fd);
	if (write_cnt)
		fprintf(stderr, "Wrote %d keycode(s) to driver\n", write_cnt);

	/*
	 * Third step: change protocol
	 */
	if (ch_proto) {
		rc_dev.current = ch_proto;
		if (set_proto(&rc_dev))
			fprintf(stderr, "Couldn't change the IR protocols\n");
		else {
			fprintf(stderr, "Protocols changed to ");
			show_proto(rc_dev.current);
			fprintf(stderr, "\n");
		}
	}

	/*
	 * Fourth step: display current keytable
	 */
	if (read)
		display_table(&rc_dev, fd);

	return 0;
}
Exemplo n.º 22
0
int main(int argc, char *argv[])
{
	int dev_from_class = 0, write_cnt;
	int fd;
	static struct sysfs_names *names;
	struct rc_device	  rc_dev;

	argp_parse(&argp, argc, argv, 0, 0, 0);

	/* Just list all devices */
	if (!clear && !readtable && !keys.next && !ch_proto && !cfg.next && !test && !delay && !period) {
		if (devicename) {
			fd = open(devicename, O_RDONLY);
			if (fd < 0) {
				perror("Can't open device");
				return -1;
			}
			device_info(fd, "");
			close(fd);
			return 0;
		}
		if (show_sysfs_attribs(&rc_dev))
			return -1;

		return 0;
	}

	if (cfg.next && (clear || keys.next || ch_proto || devicename)) {
		fprintf (stderr, "Auto-mode can be used only with --read, --debug and --sysdev options\n");
		return -1;
	}
	if (!devicename) {
		names = find_device(devclass);
		if (!names)
			return -1;
		rc_dev.sysfs_name = names->name;
		if (get_attribs(&rc_dev, names->name)) {
			free_names(names);
			return -1;
		}
		names->name = NULL;
		free_names(names);

		devicename = rc_dev.input_name;
		dev_from_class++;
	}

	if (cfg.next) {
		struct cfgfile *cur;
		char *fname, *name;
		int rc;

		for (cur = &cfg; cur->next; cur = cur->next) {
			if ((!rc_dev.drv_name || strcasecmp(cur->driver, rc_dev.drv_name)) && strcasecmp(cur->driver, "*"))
				continue;
			if ((!rc_dev.keytable_name || strcasecmp(cur->table, rc_dev.keytable_name)) && strcasecmp(cur->table, "*"))
				continue;
			break;
		}

		if (!cur->next) {
			if (debug)
				fprintf(stderr, "Table for %s, %s not found. Keep as-is\n",
				       rc_dev.drv_name, rc_dev.keytable_name);
			return 0;
		}
		if (debug)
			fprintf(stderr, "Table for %s, %s is on %s file.\n",
				rc_dev.drv_name, rc_dev.keytable_name,
				cur->fname);
		if (cur->fname[0] == '/' || ((cur->fname[0] == '.') && strchr(cur->fname, '/'))) {
			fname = cur->fname;
			rc = parse_keyfile(fname, &name);
			if (rc < 0) {
				fprintf(stderr, "Can't load %s table\n", fname);
				return -1;
			}
		} else {
			fname = malloc(strlen(cur->fname) + strlen(IR_KEYTABLE_USER_DIR) + 2);
			strcpy(fname, IR_KEYTABLE_USER_DIR);
			strcat(fname, "/");
			strcat(fname, cur->fname);
			rc = parse_keyfile(fname, &name);
			if (rc != 0) {
				fname = malloc(strlen(cur->fname) + strlen(IR_KEYTABLE_SYSTEM_DIR) + 2);
				strcpy(fname, IR_KEYTABLE_SYSTEM_DIR);
				strcat(fname, "/");
				strcat(fname, cur->fname);
				rc = parse_keyfile(fname, &name);
			}
			if (rc != 0) {
				fprintf(stderr, "Can't load %s table from %s or %s\n", cur->fname, IR_KEYTABLE_USER_DIR, IR_KEYTABLE_SYSTEM_DIR);
				return -1;
			}
		}
		if (!keys.next) {
			fprintf(stderr, "Empty table %s\n", fname);
			return -1;
		}
		clear = 1;
	}

	if (debug)
		fprintf(stderr, "Opening %s\n", devicename);
	fd = open(devicename, O_RDONLY);
	if (fd < 0) {
		perror(devicename);
		return -1;
	}
	if (dev_from_class)
		free(devicename);
	if (get_input_protocol_version(fd))
		return -1;

	/*
	 * First step: clear, if --clear is specified
	 */
	if (clear) {
		clear_table(fd);
		fprintf(stderr, "Old keytable cleared\n");
	}

	/*
	 * Second step: stores key tables from file or from commandline
	 */
	write_cnt = add_keys(fd);
	if (write_cnt)
		fprintf(stderr, "Wrote %d keycode(s) to driver\n", write_cnt);

	/*
	 * Third step: change protocol
	 */
	if (ch_proto) {
		rc_dev.current = ch_proto;
		if (set_proto(&rc_dev))
			fprintf(stderr, "Couldn't change the IR protocols\n");
		else {
			fprintf(stderr, "Protocols changed to ");
			show_proto(rc_dev.current);
			fprintf(stderr, "\n");
		}
	}

	/*
	 * Fourth step: display current keytable
	 */
	if (readtable)
		display_table(&rc_dev, fd);

	/*
	 * Fiveth step: change repeat rate/delay
	 */
	if (delay || period) {
		unsigned int new_delay, new_period;
		get_rate(fd, &new_delay, &new_period);
		if (delay)
			new_delay = delay;
		if (period)
			new_period = period;
		set_rate(fd, new_delay, new_period);
	}

	if (test)
		test_event(fd);

	return 0;
}
Exemplo n.º 23
0
void show_info_from_system_file(char *file, meminfo_p meminfo, int meminfo_rows, int tok_offset) {
	// Setup and init table
	vtab_t table;
	int header_rows = 2 - compatibility_mode;
	int header_cols = 1;
	// Add an extra data column for a total column
	init_table(&table, header_rows, header_cols, meminfo_rows, num_nodes + 1);
	int total_col_ix = header_cols + num_nodes;
	// Insert token mapping in hash table and assign left header column label for each row in table
	init_hash_table();
	for (int row = 0; (row < meminfo_rows); row++) {
		hash_insert(meminfo[row].token, meminfo[row].index);
		if (compatibility_mode) {
			string_assign(&table, (header_rows + row), 0, meminfo[row].token);
		} else {
			string_assign(&table, (header_rows + row), 0, meminfo[row].label);
		}
	}
	// printf("There are %d table hash collisions.\n", hash_collisions);
	// Set left header column width and left justify it
	set_col_width(&table, 0, 16);
	set_col_justification(&table, 0, COL_JUSTIFY_LEFT);
	// Open /sys/devices/system/node/node?/<file> for each node and store data
	// in table.  If not compatibility_mode, do approximately first third of
	// this loop also for (node_ix == num_nodes) to get "Total" column header.
	for (int node_ix = 0; (node_ix < (num_nodes + (1 - compatibility_mode))); node_ix++) {
		int col = header_cols + node_ix;
		// Assign header row label and horizontal line for this column...
		string_assign(&table, 0, col, node_header[node_ix]);
		if (!compatibility_mode) {
			repchar_assign(&table, 1, col, '-');
			int decimal_places = 2;
			if (compress_display) {
				decimal_places = 0;
			}
			set_col_decimal_places(&table, col, decimal_places);
		}
		// Set column width and right justify data
		set_col_width(&table, col, 16);
		set_col_justification(&table, col, COL_JUSTIFY_RIGHT);
		if (node_ix == num_nodes) {
			break;
		}
		// Open /sys/.../node<N>/numstast file for this node...
		char buf[SMALL_BUF_SIZE];
		char fname[64];
		snprintf(fname, sizeof(fname), "/sys/devices/system/node/node%d/%s", node_ix_map[node_ix], file);
		FILE *fs = fopen(fname, "r");
		if (!fs) {
			sprintf(buf, "cannot open %s", fname);
			perror(buf);
			exit(EXIT_FAILURE);
		}
		// Get table values for this node...
		while (fgets(buf, SMALL_BUF_SIZE, fs)) {
			char *tok[64];
			int tokens = 0;
			const char *delimiters = " \t\r\n:";
			char *p = strtok(buf, delimiters);
			if (p == NULL) {
				continue;	// Skip blank lines;
			}
			while (p) {
				tok[tokens++] = p;
				p = strtok(NULL, delimiters);
			}
			// example line from numastat file: "numa_miss 16463"
			// example line from meminfo  file: "Node 3 Inactive:  210680 kB"
			int index = hash_lookup(tok[0 + tok_offset]);
			if (index < 0) {
				printf("Token %s not in hash table.\n", tok[0]);
			} else {
				double value = (double)atol(tok[1 + tok_offset]);
				if (!compatibility_mode) {
					double multiplier = 1.0;
					if (tokens < 4) {
						multiplier = page_size_in_bytes;
					} else if (!strncmp("HugePages", tok[2], 9)) {
						multiplier = huge_page_size_in_bytes;
					} else if (!strncmp("kB", tok[4], 2)) {
						multiplier = KILOBYTE;
					}
					value *= multiplier;
					value /= (double)MEGABYTE;
				}
				double_assign(&table, header_rows + index, col, value);
				double_addto(&table, header_rows + index, total_col_ix, value);
			}
		}
		fclose(fs);
	}
	// Crompress display column widths, if requested
	if (compress_display) {
		for (int col = 0; (col < header_cols + num_nodes + 1); col++) {
			auto_set_col_width(&table, col, 4, 16);
		}
	}
	// Optionally sort the table data
	if (sort_table) {
		int sort_col;
		if ((sort_table_node < 0) || (sort_table_node >= num_nodes)) {
			sort_col = total_col_ix;
		} else {
			sort_col = header_cols + node_ix_map[sort_table_node];
		}
		sort_rows_descending_by_col(&table, header_rows, header_rows + meminfo_rows - 1, sort_col);
	}
	// Actually display the table now, doing line-folding as necessary
	display_table(&table, screen_width, 0, 0, show_zero_data, show_zero_data);
	free_table(&table);
}
int mddi_novatek_position(void)
{
	display_table(mddi_novatek_position_table, 
			ARRAY_SIZE(mddi_novatek_position_table));
	return 0;
}
Exemplo n.º 25
0
int main() {

	// Make a matrix for the board
	int board[LENGTH];

	// Tracker of current player, 0 for P1, 1 for P2
	int whoseTurn;

	// Stores user's last inputted x and y, variable to store output of check_table_full
	int x, y, fullTable;

	// User input of whether they want to play again or not. 
	char again;

	// Prompts user with explanatory but kind of unhelpful text.
	printf("This program plays the game of tic-tac-toe");


	for(;;) {
		whoseTurn = 0;

		// Clear matrix
		create_clear_table(board, LENGTH);

		fullTable = check_table_full(board, LENGTH);

		while( !check_three_in_a_row(board, LENGTH, whoseTurn) && !fullTable ) { // Not three in a row, not full
			// Display table
			display_table(board, LENGTH);

			// Ask appropriate user for x and y coordinates
			printf("Enter the section of %c for Player %d [row,col]:", (whoseTurn == 0)?'O':'X', (whoseTurn == 0)?1:2);
			scanf("%d,%d", &y, &x);
			while(check_legal_option(board, LENGTH, x, y)) { // Ask user while they have not inputted a legal option
				printf("Invalid selection\nEnter the section of %c for Player %d [row,col]: ", (whoseTurn == 0)?'O':'X', (whoseTurn == 0)?1:2);
				scanf("%d,%d", &y, &x);
			}

			update_table(board, LENGTH, x, y, whoseTurn);

			// Change whoseTurn
			whoseTurn = !whoseTurn;

			// Check again for looping back; just so I don't have to do an extra function call for the win/lose/tie case at the end
			fullTable = check_table_full(board, LENGTH);

		}

		// Win case or lose case or tie case
		display_table(board, LENGTH);
		if(fullTable) { // Tie case
			printf("Game over, no player wins.\n");
		}
		else { // Win case
			printf("Congratulations, Player %d wins! \n", whoseTurn + 1);
		}

		printf("Would you like to play again?\n"); 
		scanf(" %c", &again);

		if(again == 'n' || again == 'N') { // Will by default play again; this catches all plausible variations of "no", including "nah", "neh", "nahhhh" etc.
			return 0;
		}
	}
}
Exemplo n.º 26
0
void show_process_info() {
	vtab_t table;
	int header_rows = 2;
	int header_cols = 1;
	int data_rows;
	int show_sub_categories = (verbose || (num_pids == 1));
	if (show_sub_categories) {
		data_rows = PROCESS_MEMINFO_ROWS;
	} else {
		data_rows = num_pids;
	}
	// Add two extra rows for a horizontal rule followed by a total row
	// Add one extra data column for a total column
	init_table(&table, header_rows, header_cols, data_rows + 2, num_nodes + 1);
	int total_col_ix = header_cols + num_nodes;
	int total_row_ix = header_rows + data_rows + 1;
	string_assign(&table, total_row_ix, 0, "Total");
	if (show_sub_categories) {
		// Assign left header column label for each row in table
		for (int row = 0; (row < PROCESS_MEMINFO_ROWS); row++) {
			string_assign(&table, (header_rows + row), 0, process_meminfo[row].label);
		}
	} else {
		string_assign(&table, 0, 0, "PID");
		repchar_assign(&table, 1, 0, '-');
		printf("\nPer-node process memory usage (in MBs)\n");
	}
	// Set left header column width and left justify it
	set_col_width(&table, 0, 16);
	set_col_justification(&table, 0, COL_JUSTIFY_LEFT);
	// Set up "Node <N>" column headers over data columns, plus "Total" column
	for (int node_ix = 0; (node_ix <= num_nodes); node_ix++) {
		int col = header_cols + node_ix;
		// Assign header row label and horizontal line for this column...
		string_assign(&table, 0, col, node_header[node_ix]);
		repchar_assign(&table, 1, col, '-');
		// Set column width, decimal places, and right justify data
		set_col_width(&table, col, 16);
		int decimal_places = 2;
		if (compress_display) {
			decimal_places = 0;
		}
		set_col_decimal_places(&table, col, decimal_places);
		set_col_justification(&table, col, COL_JUSTIFY_RIGHT);
	}
	// Initialize data in table to all zeros
	zero_table_data(&table, CELL_TYPE_DOUBLE);
	// If (show_sub_categories), show individual process tables for each PID,
	// Otherwise show one big table of process total lines from all the PIDs.
	for (int pid_ix = 0; (pid_ix < num_pids); pid_ix++) {
		int pid = pid_array[pid_ix];
		if (show_sub_categories) {
			printf("\nPer-node process memory usage (in MBs) for PID %d (%s)\n", pid, command_name_for_pid(pid));
			if (pid_ix > 0) {
				// Re-initialize show_sub_categories table, because we re-use it for each PID.
				zero_table_data(&table, CELL_TYPE_DOUBLE);
			}
		} else {
			// Put this row's "PID (cmd)" label in left header column for this PID total row
			char tmp_buf[64];
			snprintf(tmp_buf, sizeof(tmp_buf), "%d (%s)", pid, command_name_for_pid(pid));
			char *p = strdup(tmp_buf);
			if (p == NULL) {
				perror("malloc failed line: " STRINGIFY(__LINE__));
				exit(EXIT_FAILURE);
			}
			string_assign(&table, header_rows + pid_ix, 0, p);
			set_cell_flag(&table, header_rows + pid_ix, 0, CELL_FLAG_FREEABLE);
		}
		// Open numa_map for this PID to get per-node data
		char fname[64];
		snprintf(fname, sizeof(fname), "/proc/%d/numa_maps", pid);
		char buf[BUF_SIZE];
		FILE *fs = fopen(fname, "r");
		if (!fs) {
			sprintf(buf, "Can't read /proc/%d/numa_maps", pid);
			perror(buf);
			continue;
		}
		// Add up sub-category memory used from each node.  Must go line by line
		// through the numa_map figuring out which category memory, node, and the
		// amount.
		while (fgets(buf, BUF_SIZE, fs)) {
			int category = PROCESS_PRIVATE_INDEX;	// init category to the catch-all...
			const char *delimiters = " \t\r\n";
			char *p = strtok(buf, delimiters);
			while (p) {
				// If the memory category for this line is still the catch-all
				// (i.e.  private), then see if the current token is a special
				// keyword for a specific memory sub-category.
				if (category == PROCESS_PRIVATE_INDEX) {
					for (int ix = 0; (ix < PROCESS_PRIVATE_INDEX); ix++) {
						if (!strncmp(p, process_meminfo[ix].token, strlen(process_meminfo[ix].token))) {
							category = ix;
							break;
						}
					}
				}
				// If the current token is a per-node pages quantity, parse the
				// node number and accumulate the number of pages in the specific
				// category (and also add to the total).
				if (p[0] == 'N') {
					int node_num = (int)strtol(&p[1], &p, 10);
					if (p[0] != '=') {
						perror("node value parse error");
						exit(EXIT_FAILURE);
					}
					double value = (double)strtol(&p[1], &p, 10);
					double multiplier = page_size_in_bytes;
					if (category == PROCESS_HUGE_INDEX) {
						multiplier = huge_page_size_in_bytes;
					}
					value *= multiplier;
					value /= (double)MEGABYTE;
					// Add value to data cell, total_col, and total_row
					int tmp_row;
					if (show_sub_categories) {
						tmp_row = header_rows + category;
					} else {
						tmp_row = header_rows + pid_ix;
					}
					int tmp_col = header_cols + node_num;
					double_addto(&table, tmp_row, tmp_col, value);
					double_addto(&table, tmp_row, total_col_ix, value);
					double_addto(&table, total_row_ix, tmp_col, value);
					double_addto(&table, total_row_ix, total_col_ix, value);
				}
				// Get next token on the line
				p = strtok(NULL, delimiters);
			}
		}
		// Currently, a non-root user can open some numa_map files successfully
		// without error, but can't actually read the contents -- despite the
		// 444 file permissions.  So, use ferror() to check here to see if we
		// actually got a read error, and if so, alert the user so they know
		// not to trust the zero in the table.
		if (ferror(fs)) {
			sprintf(buf, "Can't read /proc/%d/numa_maps", pid);
			perror(buf);
		}
		fclose(fs);
		// If showing individual tables, or we just added the last total line,
		// prepare the table for display and display it...
		if ((show_sub_categories) || (pid_ix + 1 == num_pids)) {
			// Crompress display column widths, if requested
			if (compress_display) {
				for (int col = 0; (col < header_cols + num_nodes + 1); col++) {
					auto_set_col_width(&table, col, 4, 16);
				}
			} else {
				// Since not compressing the display, allow the left header
				// column to be wider.  Otherwise, sometimes process command
				// name instance numbers can be truncated in an annoying way.
				auto_set_col_width(&table, 0, 16, 24);
			}
			// Put dashes above Total line...
			set_row_flag(&table, total_row_ix - 1, COL_FLAG_ALWAYS_SHOW);
			for (int col = 0; (col < header_cols + num_nodes + 1); col++) {
				repchar_assign(&table, total_row_ix - 1, col, '-');
			}
			// Optionally sort the table data
			if (sort_table) {
				int sort_col;
				if ((sort_table_node < 0) || (sort_table_node >= num_nodes)) {
					sort_col = total_col_ix;
				} else {
					sort_col = header_cols + node_ix_map[sort_table_node];
				}
				sort_rows_descending_by_col(&table, header_rows, header_rows + data_rows - 1, sort_col);
			}
			// Actually show the table
			display_table(&table, screen_width, 0, 0, show_zero_data, show_zero_data);
		}
	}			// END OF FOR_EACH-PID loop
	free_table(&table);
}				// show_process_info()