Example #1
0
BOOL CRenameDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);			// Set big icon
    SetIcon(m_hIcon, FALSE);		// Set small icon

    // TODO: Add extra initialization here
    ren_action.read_conf();
    m_cPickedDir.pick(ren_action.ren_info.dir_path);
//	m_cPickedDir.listFiles();

    //set list style
    m_cListFile.SetExtendedStyle(m_cListFile.GetStyle()|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);

    create_col();
    m_cEditPath.SetWindowText(ren_action.ren_info.dir_path);
    resize();
    refresh();

    return TRUE;  // return TRUE  unless you set the focus to a control
}
Example #2
0
void copy_col(TABLE *src,TABLE *dst,int col)
{
  char name[20];
  int type;
  char format[20];
  char unit[20];
  int id,i,n;
  
  get_col_name(src,col,name);

  get_col_info(src,col,&type,format,unit);
  
  id = create_col(dst,name,(short)type,'N',format,unit);

  switch(type)
    {
    case CHAR:
      {
	char *value;
	sscanf(format,"A%d",&n);
	value = (char *)malloc((n+1)*sizeof(char));

	for (i=0;i<src->row;i++) {
          RD_tbl(src,i,col,value);
          WR_tbl(dst,i,id,value);
        }
	free(value);
	break;
      }
    case SHORT:
      {
	short value;

	for (i=0;i<src->row;i++) {
          RD_tbl(src,i,col,&value);
          WR_tbl(dst,i,id,&value);
        }
	break;
      }
    case INT:
      {
	int value;
	
	for (i=0;i<src->row;i++) {
          RD_tbl(src,i,col,&value);
          WR_tbl(dst,i,id,&value);
        }
	break;
      }
    case LONG:
      {
	long value;
	
	for (i=0;i<src->row;i++) {
          RD_tbl(src,i,col,&value);
          WR_tbl(dst,i,id,&value);
        }
	break;
      }
    case FLOAT:
      {
	float value;
	
	for (i=0;i<src->row;i++) {
          RD_tbl(src,i,col,&value);
          WR_tbl(dst,i,id,&value);
        }
	break;
      }
    case DOUBLE:
      {
	double value;
	
	for (i=0;i<src->row;i++) {
          RD_tbl(src,i,col,&value);
          WR_tbl(dst,i,id,&value);
        }
	break;
      }
    }
}
Example #3
0
int
main(int argc, char **argv)
{
	int nocol_short, nocol_long, nocol_float, nocol_double;
	int status;
	char **argval, **arglabel;
	int i, nbrow = NBROW, nbcol=NBCOL, sel[NBROW];
	short sval, s_colbuf[NBROW], s_key;
	long lval, l_colbuf[NBROW];
	float fval, f_colbuf[NBROW];
	double dval, d_colbuf[NBROW];
	char ident[20];
	char selection[30];
	TABLE table;

						/*  init_session() checking */	


	printf("IOLIB environment routines :\n\n");
	fflush(stdout);
	init_session(argv,argc,&arglabel,&argval);
/* 	set_control_level(WARNING); */

	printf("Table creation ...");
	fflush(stdout);
	strcpy(ident,"Dummy table");
	create_table(&table,"chk_tbl_io",nbrow,nbcol,'W',ident);
	printf("Ok\n");
	fflush(stdout);
/*
	printf("Column creation ...(format Characters) ");
	fflush(stdout);
	nocol_char = create_col(&table,":TEXT",CHAR,'N',"A20",NULL);
	if (nocol_char < 0) {
		printf("Problem creating column TEXT, status returned = %d\n", nocol_char);
		exit (-1);
	}
	printf("Ok\n");
	fflush(stdout);

	printf("Writing into created column ...");
	fflush(stdout);
	for (i=0; i<nbrow; i++) {
		sprintf(text,"String no %2d",i);
		WR_tbl(&table,i,nocol_char,text);
	}
	printf("Ok\n");
	fflush(stdout);
*/
	printf("Column creation ...(format Short) ");
	fflush(stdout);
	nocol_short = create_col(&table,":SHORT",SHORT,'N',"I2",NULL);
	if (nocol_short < 0) {
		printf("Problem creating column SHORT, status returned = %d\n", nocol_short);
		exit (-1);
	}
	printf("Ok\n");
	fflush(stdout);

	printf("Writing into created column ...");
	fflush(stdout);
	for (i=0; i<nbrow; i++) {
		sval = (short)i;
		WR_tbl(&table,i,nocol_short,&sval);
	}
	printf("Ok\n");
	fflush(stdout);

	printf("Column creation ...(format Long) ");
	fflush(stdout);
	nocol_long = create_col(&table,":LONG",LONG,'N',"I4",NULL);
	if (nocol_long < 0) {
		printf("Problem creating column LONG, status returned = %d\n", nocol_long);
		exit (-1);
	}
	printf("Ok\n");
	fflush(stdout);

	printf("Writing into created column ...");
	fflush(stdout);
	for (i=0; i<nbrow; i++) {
		lval = (long)i;
		WR_tbl(&table,i,nocol_long,&lval);
	}
	printf("Ok\n");
	fflush(stdout);

	printf("Column creation ...(format Float) ");
	fflush(stdout);
	nocol_float = create_col(&table,":FLOAT",FLOAT,'N',"F9.6",NULL);
	if (nocol_float < 0) {
		printf("Problem creating column FLOAT, status returned = %d\n", nocol_float);
		exit (-1);
	}
	printf("Ok\n");
	fflush(stdout);

	printf("Writing into created column ...");
	fflush(stdout);
	for (i=0; i<nbrow; i++) {
		fval = (float)i;
		WR_tbl(&table,i,nocol_float,&fval);
	}
	printf("Ok\n");
	fflush(stdout);

	printf("Column creation ...(format Double) ");
	fflush(stdout);
	nocol_double = create_col(&table,":DOUBLE",DOUBLE,'N',"E15.5",NULL);
	if (nocol_double < 0) {
		printf("Problem creating column DOUBLE, status returned = %d\n", nocol_double);
		exit (-1);
	}
	printf("Ok\n");
	fflush(stdout);

	printf("Writing into created column ...");
	fflush(stdout);
	for (i=0; i<nbrow; i++) {
		dval = (double)i;
		WR_tbl(&table,i,nocol_double,&dval);
	}
	printf("Ok\n\n");
	fflush(stdout);

	for (i=0; i<nbrow; i++) {
		if (i%2 == 0)
			sel[i] = 0;
		else
			sel[i] = 1;
	}
	write_selection(&table,sel,"check_selection");

	printf("Saving created table ...");
	fflush(stdout);
	close_table(&table);
	printf("Ok\n");
	fflush(stdout);

	printf("Opening previous table ...");
	fflush(stdout);
	open_table(&table,"chk_tbl_io","I");
	printf("Ok\n");
	fflush(stdout);

	printf("Handling selection ...");
	fflush(stdout);
	handle_select_flag(&table,'W',selection);
	printf("Ok\n");
	fflush(stdout);

	printf("Reading columns info ...");
	fflush(stdout);
/*	nocol_char = get_col_ref(&table,":TEXT"); */
	nocol_short = get_col_ref(&table,":SHORT");
	nocol_long = get_col_ref(&table,":LONG");
	nocol_float = get_col_ref(&table,":FLOAT");
	nocol_double = get_col_ref(&table,":DOUBLE");
	printf("Ok\n");
	nbrow = table.row;
/*
	printf("Reading previous column ...(format Characters) ");
	fflush(stdout);
	RD_col(&table,nocol_char,c_colbuf);
	for (i=0; i<nbrow; i++) {
		sprintf(text,"String no %2d",i);
		if (strcmp(text,(c_colbuf+i*21)) != 0) {
			printf("FATAL : Unexpected values in table, line %d\n",i);
			return(-1);
		}
	}
	printf("Ok\n");

	printf("Reading previous column item by item  ...(format Characters) ");
	fflush(stdout);
	for (i=0; i<nbrow; i++) {
		RD_tbl(&table,i,nocol_char,Rtext);
		sprintf(text,"String no %2d",i);
		if (strcmp(text,Rtext) != 0) {
			printf("FATAL : Unexpected values in table, line %d\n",i);
			printf("*%s* is not *%s*\n", Rtext, text);
	 	return(-1); 
		}
	}
	printf("Ok\n");
*/
	printf("Reading previous column ...(format Short) ");
	fflush(stdout);
	s_colbuf[0] = 0;
	RD_col(&table,nocol_short,s_colbuf);
	printf("Ok\n");

	printf("Searching for no 501 ... ");
	fflush(stdout);
	
	s_key = 501;
	status = search_in_col(&table,nocol_short,&s_key);
	if (status >= 0)
		printf("Found in line %d\n",status);
	else {
		printf("Unable to find it\n");
		return(-1);
	}
	
	printf("Searching for no 500 ... ");
	fflush(stdout);
	
	s_key = 500;
	status = search_in_col(&table,nocol_short,&s_key);
	if (status >= 0)
		printf("Found in line %d\n",status);
	else {
		printf("Unable to find it (not selected)\n");
	}

	for (i=0; i<nbrow; i++) {
		if (s_colbuf[i] != (short)(2*i+1)) {
			printf("FATAL : Unexpected values in table, line %d\n",i);
			printf("Read %d, Expected %d\n",s_colbuf[i],2*i+1);
			return(-1);
		}
	}
	printf("Ok\n");
	printf("Reading previous column item by item ...(format Short) ");
	fflush(stdout);
	for (i=0; i<nbrow; i++) {
		RD_tbl(&table,i,nocol_short,&sval);
		if (sval != (short)(2*i+1)) {
			printf("FATAL : Unexpected values in table, line %d\n",i);
			return(-1);
		}
	}
	printf("Ok\n");

	printf("Reading previous column ..(format Long) ");
	fflush(stdout);
	RD_col(&table,nocol_long,l_colbuf);
	for (i=0; i<nbrow; i++) {
		if (l_colbuf[i] != (long)(2*i+1)) {
			printf("FATAL : Unexpected values in table, line %d\n",i);
			return(-1);
		}
	}
	printf("Ok\n");
	printf("Reading previous column item by item ...(format Long) ");
	fflush(stdout);
	for (i=0; i<nbrow; i++) {
		RD_tbl(&table,i,nocol_long,&lval);
		if (lval != (long)(2*i+1)) {
			printf("FATAL : Unexpected values in table, line %d\n",i);
			return(-1);
		}
	}
	printf("Ok\n");

	printf("Reading previous column ...(format Float) ");
	fflush(stdout);
	RD_col(&table,nocol_float,f_colbuf);
	for (i=0; i<nbrow; i++) {
		if (f_colbuf[i] != (float)(2*i+1)) {
			printf("FATAL : Unexpected values in table, line %d\n",i);
			return(-1);
		}
	}
	printf("Ok\n");
	printf("Reading previous column item by item ...(format Float) ");
	fflush(stdout);
	for (i=0; i<nbrow; i++) {
		RD_tbl(&table,i,nocol_float,&fval);
		if (fval != (float)(2*i+1)) {
			printf("FATAL : Unexpected values in table, line %d\n",i);
			return(-1);
		}
	}
	printf("Ok\n");

	printf("Reading previous column ..(format Double) ");
	fflush(stdout);
	RD_col(&table,nocol_double,d_colbuf);
	for (i=0; i<nbrow; i++) {
		if (ABS(d_colbuf[i] - (double)(2*i+1)) > 1e-8) {
			printf("FATAL : Unexpected values in table, line %d\n",i);
			return(-1);
		}
	}
	printf("Ok\n");
	printf("Reading previous column item by item ...(format Double) ");
	fflush(stdout);
	for (i=0; i<nbrow; i++) {
		RD_tbl(&table,i,nocol_double,&dval);
		if (ABS(dval - (double)(2*i+1)) > 1e-8) {
			printf("FATAL : Unexpected values in table, line %d\n",i);
			return(-1);
		}
	}
	printf("Ok\n");
	fflush(stdout);

	printf("Deleting previous table ...");
	fflush(stdout);
	delete_table(&table);
	printf("Ok\n");
	fflush(stdout);

	exit_session(0);
	return(0);
}
Example #4
0
int main(int args, char* argvs[])
{
    int result, col_length;
    char col_type[ITEM_TYPE_LEN], col_name[ITEM_NAME_LEN];
    struct msg_st string_item;
    int msgqid;
    char tb_name[TABLE_NAME_LEN];
    char tmp[10][ITEM_NAME_LEN];

    msgqid = msgget((key_t)3570, 0666 | IPC_CREAT);
    if (msgqid == -1) {
        ipc_msgget_failed(errno);
    }
    
    while (receive(0)) {
        switch (*string_item.text) {        
        case '0':
            result=receive(0);
            string_item.text[result]='\0';
	    strcpy(tb_name, string_item.text);
            create_table(string_item.text);
            result = 0;
            while ((result = receive(0)) != -1) {
                string_item.text[result]='\0';
                if (!strcmp(string_item.text, "TAIL"))
                    break;
                sscanf(string_item.text, "%s %s %s %d", tmp[0], col_type, col_name, &col_length);
                if (tmp[0][0] == '0')
                    create_col(col_name, col_type, col_length, 0);
                else create_col(col_name, col_type, col_length, 1);
            }
            
            if (-1 == result)
                ipc_msgrcv_failed(errno);
            create_table_on_close();
            printf("CATTYDB : database %s successfully created.\n",tb_name);
            break;
        case '1':
            result=receive(0);
            string_item.text[result]='\0';
            //printf("%s\n", string_item.text);
            describe_table(string_item.text);
            break;
        case '2':
            result = receive(0);
            string_item.text[result]='\0';
            //printf("%s\n", string_item.text);
            insert_on_open(string_item.text);
            while ((result=receive(0)) != -1) {
                string_item.text[result]='\0';
                if (!strcmp(string_item.text, "TAIL"))
                    break;
                insert_item(string_item.text);
            }
            if (-1 == result)
                ipc_msgrcv_failed(errno);
            insert_on_close();
            break;
        case '3':
            result = receive(0);
            string_item.text[result]='\0';
            //printf("%s\n", string_item.text);
            delete_on_open(string_item.text);
            int i = 0;
            while ((result = receive(0)) != -1) {
                string_item.text[result]='\0';
                if (!strcmp(string_item.text, "TAIL"))
                    break;
                delete(string_item.text);
                //strcpy(tmp[i++], string_item.text);
                //puts(tmp[i-1]);
            }
            if (-1 == result)
                ipc_msgrcv_failed(errno);
            puts("del suc!");
            break;
        case '6':
            puts("bye");
            exit(0);
        case '7':
            result = receive(0);
            string_item.text[result]='\0';
            printf("%s\n", string_item.text);
            show_table(string_item.text);
            break;
        case '8':
            result=receive(0);
            string_item.text[result]='\0';
            select_where_on_open(string_item.text, "tmp");
            
            result=receive(0);
            string_item.text[result]='\0';
            select_where(string_item.text);
            select_where_on_close();

            select_col_on_open("tmp", "tmp2");
            
            result = 0;
            while ((result = receive(0)) != -1) {
                string_item.text[result]='\0';
                if (!strcmp(string_item.text, "TAIL"))
                    break;
                select_col_get_pos(string_item.text);
            }
            if (-1 == result)
                ipc_msgrcv_failed(errno);

            select_col();
            select_col_on_close();
            show_table("tmp2");
            break;
        case '9':
            result = receive(0);
            string_item.text[result]='\0';
            update_on_open(string_item.text);
            result = receive(0);
            string_item.text[result]='\0';
            strcpy(tmp[0], string_item.text);
            result = receive(0);
            string_item.text[result]='\0';
            update(tmp[0], string_item.text); 
            break;
        case 'a':
            result = receive(0);
            string_item.text[result]='\0';
            strcpy(tmp[0], string_item.text);
            result = receive(0);
            string_item.text[result]='\0';
            equijoins_on_open(tmp[0], string_item.text, "tmp");
            result = receive(0);
            string_item.text[result]='\0';
            equijoins(string_item.text);
            equijoins_on_close();
            show_table("tmp");
        }
    }

    return 0;
}
Example #5
0
bool ExactCoverSolver::init (const int grid_size)
{
  GRID_SIZE_ = grid_size;
  ROW_OFFSET_ = 0;
  COL_OFFSET_ = pow (grid_size, 2);
  CELL_OFFSET_ = COL_OFFSET_ * 2;
  BOX_OFFSET_ = COL_OFFSET_ * 3;
  MAX_COLS_ = COL_OFFSET_ * 4;
  MAX_ROWS_ = COL_OFFSET_ * GRID_SIZE_;
  
  if (grid_size == 9)
  {
    COL_BOX_DIV_ = 3;
    ROW_BOX_DIV_ = 3;
  }
  else if (grid_size == 10)
  {
    COL_BOX_DIV_ = 2;
    ROW_BOX_DIV_ = 5;
  }
  else if (grid_size == 12)
  {
    COL_BOX_DIV_ = 4;
    ROW_BOX_DIV_ = 3;
  }
  else if (grid_size == 16)
  {
    COL_BOX_DIV_ = 4;
    ROW_BOX_DIV_ = 4;
  }
  else
  {
    return false;
  }
  
  Node<int>* matrix[MAX_ROWS_][MAX_COLS_];
  int row = 0;
  int tmp = 0;
  Node<int>* row_node = NULL;
  Node<int>* col_node = NULL;
  Node<int>* cell_node = NULL;
  Node<int>* box_node = NULL;
  //initialize matrix
   for (int i = 0; i < MAX_ROWS_; ++i)
   {
     for (int j = 0; j < MAX_COLS_; ++j)
     {
       matrix[i][j] = NULL;
     }
   }
    
  for (int i = 0; i < GRID_SIZE_; ++i)
  {
    for (int j = 0; j < GRID_SIZE_; ++j)
    {
      for (int k = 0; k < GRID_SIZE_; ++k)
      {
        row = (i * COL_OFFSET_ + j * GRID_SIZE_ + k);
        row_node = new Node<int> (i, j, k);
        matrix[row][ROW_OFFSET_ + (i * GRID_SIZE_ + k)] = row_node;
        
        col_node = new Node<int> (i, j, k);
        matrix[row][COL_OFFSET_ + (j * GRID_SIZE_ + k)] = col_node;
        
        cell_node = new Node<int> (i, j, k);
        matrix[row][CELL_OFFSET_ + (i * GRID_SIZE_ + j)] = cell_node;
        
        tmp = BOX_OFFSET_ + ((i / ROW_BOX_DIV_ + j / COL_BOX_DIV_ * COL_BOX_DIV_) * GRID_SIZE_ + k);
        box_node = matrix[row][tmp] = new Node<int> (i, j, k);
        /// Link nodes
        row_node->right_ = col_node;
        row_node->left_ = box_node;
        
        col_node->left_ = row_node;
        col_node->right_ = cell_node;
        
        cell_node->left_ = col_node;
        cell_node->right_ = box_node;
        
        box_node->left_ = cell_node;
        box_node->right_ = row_node;
      }
    }
  }
  
  Node<int>* next_col_header;
  Node<int>* next_col_row;
  /// Link columns to construct dancing links
  for (int j = 0; j < MAX_COLS_; ++j)
  {
    next_col_header = new Node<int>;
    next_col_header->header_ = true;
    next_col_header->top_ = next_col_header;
    next_col_header->bottom_ = next_col_header;
    next_col_header->left_ = next_col_header;
    next_col_header->right_ = next_col_header;
    next_col_header->col_header_ = next_col_header;
    next_col_row = next_col_header;
    for (int i = 0; i < MAX_ROWS_; ++i)
    {
      if (matrix[i][j] != NULL)
      {
        //search down rows to add to column
        matrix[i][j]->top_ = next_col_row;
        next_col_row->bottom_ = matrix[i][j];
        matrix[i][j]->bottom_ = next_col_header;
        next_col_header->top_ = matrix[i][j];
        matrix[i][j]->col_header_ = next_col_header;
        next_col_row = matrix[i][j];
      }
    }
    if (next_col_header->bottom_ == next_col_header)
    {
      return false;
    }
    
    if (!create_col (next_col_header))
    {
      /// Cleanup
      for (int i = 0; i < MAX_ROWS_; ++i)
      {
        for (int j = 0; j < MAX_COLS_; ++j)
        {
          if (matrix[i][j] != NULL)
          {
            delete matrix[i][j];  
          }
        }
      }
      return false;
    }
  }
  return true;
}