Example #1
0
void DirContent::gen_items(const std::vector<std::string> &str, bool is_dir)
{
  for (size_t i=0 ; i < str.size() ; ++i)
  {
    gen_items(str[i], is_dir);
  }
}
Example #2
0
void DirContent::file_alt(FAMEvent *ev)
{
  std::string fn(ev->filename);
  //cout << "file event: " << ev->code << " / "<< event_name(ev->code) << endl;
  switch (ev->code)
  {
    case FAMCreated:
    {
      cout << "file : " << fn << " be created" << endl;
      if (is_dir(dirname() + "/" + fn) )
      {
	emit create_file(gen_items(fn, true) );
      }
      else
        gen_items(fn, false);
      break;
    }
    case FAMDeleted:
    {
      cout << "file : " << fn << " be deleted" << endl;
      del_items(fn);
      emit del_file(fn);
/*
      if (is_dir(dn_ + "/" + fn) )
      {
        cout << "emit del_file(fn)" << endl;
      }
      */
      break;
    }
    case FAMChanged:
    {
      cout << "file : " << dn_ << " be changed" << endl;
      break;
    }
    default:
    {
      //cout << "I don't care" << endl;
      break;
    }

  }
}
Example #3
0
void DirContent::gen_dir_content(const std::string &dir_fp)
{
  qDebug("in gen_dirs_content(const std::string &dir_fp)");


  if (open_dir(dir_fp.c_str())==OPENDIR_FAIL) 
  { 
    opendir_=false;
    return;
  }
  opendir_=true;

  clear();
  gen_items(files_, false);
  gen_items(dirs_, true);


  set_dirname(dir_fp);
  qDebug("set_dirname: %s", dir_fp.c_str());
}
Example #4
0
int DirContent::gen_dir_content(QListViewItem *item)
{
  qDebug("in gen_dirs_content(QListViewItem *item)");
  if (item==0) 
  {
    opendir_=false;
    qDebug("no point a item");
    return -1;
  }

  FOListViewItem *cur_item=(FOListViewItem*)item;

  std::string opendir_fp=(cur_item->get_fullpath());
  return gen_dir_content(cur_item->get_fullpath());


  int open_dir_status=open_dir(opendir_fp.c_str());
  if (open_dir_status==OPENDIR_FAIL || open_dir_status==ALREADY_OPEN) 
  { 
    qDebug("OPENDIR_FAIL or ALREADY_OPEN");
    opendir_=false;
    return -2;
  }
  opendir_=true;

    dn_=cur_item->get_fullpath();

  // because clear() will delete all item, so after claer(),
  // don't use item object;
  clear();
  gen_items(files_, false);
  gen_items(dirs_, true);


  set_dirname(dn_);
  file_monitor_->monitor_file(dn_.c_str());
  qDebug("set_dirname: %s", dn_.c_str());
  emit cur_dir(dn_);
  return 0;
}
Example #5
0
int DirContent::gen_dir_content(const std::string &dir_fp)
{
  qDebug("in gen_dirs_content(const std::string &dir_fp)");


  int open_dir_status=open_dir(dir_fp.c_str());
  if (open_dir_status==OPENDIR_FAIL || open_dir_status==ALREADY_OPEN) 
  { 
    cout << "OPENDIR_FAIL or ALREADY_OPEN: " << open_dir_status << endl;
    opendir_=false;
    return -2;
  }

  clear();
  gen_items(files_, false);
  gen_items(dirs_, true);


  set_dirname(dir_fp);

  file_monitor_->monitor_file(dir_fp.c_str());
  qDebug("set_dirname: %s", dir_fp.c_str());
  return 0;
}
Example #6
0
int main()
{
        item Items[NUMITEMS];

        gen_items(Items, NUMITEMS);
        print_items(Items, NUMITEMS);

        int n, C;
        scanf("%d", &n);
        while (n--) {
                scanf("%d", &C);
                integer_knapsack(C, Items, NUMITEMS);
        }

        return 0;
}
Example #7
0
int main(int argc, char* argv[]) {
  struct stat st;

  /* For getoptlong(). */
  int c;

  init_common();

  if (argc < 2) {
    printf("Usage: %s -w # [-c #] [-i #] [-o #] [-s #] [-n #] [-d <str>]\n", argv[0]);
    printf("\n");
    printf("-w #\n");
    printf("\twarehouse cardinality\n");
    printf("-c #\n");
    printf("\tcustomer cardinality, default %d\n", CUSTOMER_CARDINALITY);
    printf("-i #\n");
    printf("\titem cardinality, default %d\n", ITEM_CARDINALITY);
    printf("-o #\n");
    printf("\torder cardinality, default %d\n", ORDER_CARDINALITY);
    printf("-n #\n");
    printf("\tnew-order cardinality, default %d\n", NEW_ORDER_CARDINALITY);
    printf("-d <path>\n");
    printf("\toutput path of data files\n");
    printf("--sapdb\n");
    printf("\tformat data for SAP DB\n");
    printf("--pgsql\n");
    printf("\tformat data for PostgreSQL\n");
    printf("--mysql\n");
    printf("\tformat data for MySQL\n");
    printf("--hyrise\n");  // patched for hyrise
    printf("\tformat data for HYRISE\n");  // SB270911
    return 1;
  }

  /* Parse command line arguments. */
  while (1) {
    int option_index = 0;
    static struct option long_options[] = {
        {"pgsql", no_argument, &mode_string, MODE_PGSQL},
        {"sapdb", no_argument, &mode_string, MODE_SAPDB},
        {"mysql", no_argument, &mode_string, MODE_MYSQL},
        {"hyrise", no_argument, &mode_string, MODE_HYRISE},  // patched for hyrise, SB270911
        {0, 0, 0, 0}};

    c = getopt_long(argc, argv, "c:d:i:n:o:w:", long_options, &option_index);
    if (c == -1) {
      break;
    }

    switch (c) {
      case 0:
        break;
      case 'c':
        customers = atoi(optarg);
        break;
      case 'd':
        strcpy(output_path, optarg);
        break;
      case 'i':
        items = atoi(optarg);
        break;
      case 'n':
        new_orders = atoi(optarg);
        break;
      case 'o':
        orders = atoi(optarg);
        break;
      case 'w':
        warehouses = atoi(optarg);
        break;
      default:
        printf("?? getopt returned character code 0%o ??\n", c);
        return 2;
    }
  }

  if (warehouses == 0) {
    printf("-w must be used\n");
    return 3;
  }

  if (strlen(output_path) > 0 && ((stat(output_path, &st) < 0) || (st.st_mode & S_IFMT) != S_IFDIR)) {
    printf("Output directory of data files '%s' not exists\n", output_path);
    return 3;
  }

  /* Set the correct delimiter. */
  if (mode_string == MODE_SAPDB) {
    delimiter = ',';
    strcpy(null_str, "\"nullptr\"");
  } else if (mode_string == MODE_PGSQL || mode_string == MODE_MYSQL) {
    delimiter = '\t';
    strcpy(null_str, "");
  } else if (mode_string == MODE_HYRISE) {  // patched for hyrise
    delimiter = '|';  //
    strcpy(null_str, "");  //
    loadHyriseLayouts();  // SB270911
  }

  printf("warehouses = %d\n", warehouses);
  printf("districts = %d\n", DISTRICT_CARDINALITY);
  printf("customers = %d\n", customers);
  printf("items = %d\n", items);
  printf("orders = %d\n", orders);
  printf("stock = %d\n", items);
  printf("new_orders = %d\n", new_orders);
  printf("\n");

  if (strlen(output_path) > 0) {
    printf("Output directory of data files: %s\n", output_path);
  } else {
    printf("Output directory of data files: current directory\n");
  }
  printf("\n");

  printf("Generating data files for %d warehouse(s)...\n", warehouses);

  gen_items();
  gen_warehouses();
  gen_stock();
  gen_districts();
  gen_customers();
  gen_history();
  gen_orders();
  gen_new_orders();

  return 0;
}
Example #8
0
void DirContent::gen_dir_content(QListViewItem *item)
{
  qDebug("in gen_dirs_content");
  if (item==0) 
  {
    opendir_=false;
    qDebug("no point a item");
    return;
  }

  FOListViewItem *cur_item=(FOListViewItem*)item;

  /*
  if ( cur_item -> is_open()) 
  {
    qDebug("already open");
    return;
  }
  */

  qDebug("dirname: %s", cur_item->dirname().c_str());
  qDebug("basename: %s", cur_item->basename().c_str());
  qDebug("qstring basename: %s", cur_item->text(0).ascii());


  std::string opendir_fp=(cur_item->get_fullpath());

  if (open_dir(opendir_fp.c_str())==OPENDIR_FAIL) 
  { 
    opendir_=false;
    return;
  }
  opendir_=true;

  /*
  if (cur_item->basename()=="../")
    dn_=cur_item->dirname();
  else
  */
    dn_=cur_item->get_fullpath();

  // because clear() will delete all item, so after claer(),
  // don't use item object;
  clear();
  gen_items(files_, false);
  gen_items(dirs_, true);


  set_dirname(dn_);
  qDebug("set_dirname: %s", dn_.c_str());
  emit cur_dir(dn_);

  //parent()->parent()->setCaption(dn.c_str()); // not yet convert to unicode
  //qApp->setCaption(dn.c_str()); // not yet convert to unicode


    //if (S_ISDIR(buf.st_mode))
     // qstr=qstr + "/";


#if 0
  DIR * dir;
  
  dir=opendir(opendir_fp.c_str());

  if (!dir)
  {
    qDebug("opendir fail: %s", opendir_fp.c_str());
    perror(opendir_fp.c_str());
    //dir_err_msg();
    return;
    //return -1;
  }


  //std::string s=cur_item->dirname() + "/" + cur_item->basename();
  std::string s=cur_item->get_fullpath();
  set_dirname(s);
  qDebug("set_dirname: %s", s.c_str());



  struct dirent *dir_ent;
  while((dir_ent=readdir(dir))!=0)
  {
    struct stat buf;
    if (strcmp(dir_ent->d_name,"?")==0)
    {
      qDebug("?");
      continue;
    }

    if (stat(std::string(opendir_fp  + "/" + dir_ent->d_name).c_str(), &buf)!=0)
    {
      qDebug("stat error");
      continue;
    }

    QString qstr;
    bool can_unicode=true;

    if (DS::big5str_to_qstr(dir_ent->d_name, qstr)!=0) // convert to unicode error
    {
       can_unicode=false;
       qstr="?";
    }

    if (S_ISDIR(buf.st_mode))
      qstr=qstr + "/";

    DirContentViewItem *node = new DirContentViewItem(this, qstr);
    if (can_unicode==false)
      node->save_fn(dir_ent->d_name);


    //dir_content.push_back(dir_ent->d_name);
  }
  closedir(dir);
#endif
}
Example #9
0
int main(int argc, char *argv[])
{
    struct stat st;

    /* For getoptlong(). */
    int c;

    init_common();

    if (argc < 2) {
        printf("Usage: %s -w # [-c #] [-i #] [-o #] [-s #] [-n #] [-d <str>]\n",
               argv[0]);
        printf("\n");
        printf("-w #\n");
        printf("\twarehouse cardinality\n");
        printf("-c #\n");
        printf("\tcustomer cardinality, default %d\n", CUSTOMER_CARDINALITY);
        printf("-i #\n");
        printf("\titem cardinality, default %d\n", ITEM_CARDINALITY);
        printf("-o #\n");
        printf("\torder cardinality, default %d\n", ORDER_CARDINALITY);
        printf("-n #\n");
        printf("\tnew-order cardinality, default %d\n", NEW_ORDER_CARDINALITY);
        printf("-d <path>\n");
        printf("\toutput path of data files\n");
        printf("--drizzle\n");
        printf("\tformat data for Drizzle\n");
        printf("--mysql\n");
        printf("--nuodb\n");
        printf("\tformat data for NuoDB\n");
        printf("\tformat data for MySQL\n");
        printf("--pgsql\n");
        printf("\tformat data for PostgreSQL\n");
        printf("--sapdb\n");
        printf("\tformat data for SAP DB\n");
        printf("--direct\n");
        printf("\tdon't generate flat files, load directly into database\n");
        return 1;
    }

    /* Parse command line arguments. */
    while (1) {
        int option_index = 0;
        static struct option long_options[] = {
            { "direct", no_argument, &mode_load, MODE_DIRECT },
            { "pgsql", no_argument, &mode_string, MODE_PGSQL },
            { "sapdb", no_argument, &mode_string, MODE_SAPDB },
            { "mysql", no_argument, &mode_string, MODE_MYSQL },
            { "nuodb", no_argument, &mode_string, MODE_NUODB },
            { "drizzle", no_argument, &mode_string, MODE_DRIZZLE },
            { 0, 0, 0, 0 }
        };

        c = getopt_long(argc, argv, "c:d:i:n:o:w:",
                        long_options, &option_index);
        if (c == -1) {
            break;
        }

        switch (c) {
        case 0:
            break;
        case 'c':
            customers = atoi(optarg);
            break;
        case 'd':
            strcpy(output_path, optarg);
            break;
        case 'i':
            items = atoi(optarg);
            break;
        case 'n':
            new_orders = atoi(optarg);
            break;
        case 'o':
            orders = atoi(optarg);
            break;
        case 'w':
            warehouses = atoi(optarg);
            break;
        default:
            printf("?? getopt returned character code 0%o ??\n", c);
            return 2;
        }
    }

    if (warehouses == 0) {
        printf("-w must be used\n");
        return 3;
    }

    if (strlen(output_path) > 0 && ((stat(output_path, &st) < 0) ||
                                    (st.st_mode & S_IFMT) != S_IFDIR)) {
        printf("Output directory of data files '%s' not exists\n", output_path);
        return 3;
    }

    /* Verify that datagen supports a direct load for the selected database. */
    if (mode_load == MODE_DIRECT) {
        switch (mode_string) {
        case MODE_SAPDB:
        case MODE_MYSQL:
        case MODE_NUODB:
        case MODE_DRIZZLE:
            printf("the rdbms select does not support direct loading\n");
            return 4;
        }
    }

    /* Set the correct delimiter. */
    if (mode_string == MODE_SAPDB) {
        delimiter = ',';
        strcpy(null_str, "\"NULL\"");
    } else if (mode_string == MODE_PGSQL || mode_string == MODE_MYSQL ||
               mode_string == MODE_DRIZZLE || mode_string == MODE_NUODB) {
        delimiter = '\t';
        strcpy(null_str, "");
    }

    printf("warehouses = %d\n", warehouses);
    printf("districts = %d\n", DISTRICT_CARDINALITY);
    printf("customers = %d\n", customers);
    printf("items = %d\n", items);
    printf("orders = %d\n", orders);
    printf("stock = %d\n", items);
    printf("new_orders = %d\n", new_orders);
    printf("\n");

    if (strlen(output_path) > 0) {
        printf("Output directory of data files: %s\n",output_path);
    } else {
        printf("Output directory of data files: current directory\n");
    }
    printf("\n");

    printf("Generating data files for %d warehouse(s)...\n", warehouses);

    gen_items();
    gen_warehouses();
    gen_stock();
    gen_districts();
    gen_customers();
    gen_history();
    gen_orders();
    gen_new_orders();

    return 0;
}
int main(int argc, char *argv[])
{
	FILE *sequence_sql;
	FILE *p;
	char pwd[256];
	char cmd[256];

	path[0] = '\0';

	if (process_options(argc, argv) == 0)
	{
		usage();
		return 1;
	}
        if (rdbms == SAPDB)
	{
		strcpy(field_deco, "\"");
		delimiter =  ',';
		strcpy(sequence_file, "../scripts/sapdb/create_sequence.sql");
		strcpy(exec_sql, "sql_execute");
	}
	else if (rdbms == PGSQL)
	{
		strcpy(field_deco, "");
		delimiter =  '\\';
		strcpy(sequence_file, "../scripts/pgsql/create_sequence.sql");
		strcpy(exec_sql, "");
	}

	if (items != 1000 && items != 10000 && items != 100000 &&
		items != 1000000 && items != 10000000)
	{
		printf("%d is an invalid item scale factor:\n", items);
		printf("\t1000\n");
		printf("\t10000\n");
		printf("\t100000\n");
		printf("\t1000000\n");
		printf("\t10000000\n");
		return 2;
	}

	p = popen("pwd", "r");
	fscanf(p, "%s", pwd);
	printf("%s\n", pwd);
	if (strcmp(path, ".") == 0 || path[0] == '\0' )
	{
		strcpy(path, pwd);
	}

	printf("item scale factor %10d\n", items);
	printf("user scale factor %10d\n", ebs);
	printf("data files are in %10s\n", path);

	printf("generating sequence creation file: %s\n", sequence_file);
	sequence_sql = fopen(sequence_file, "w");
	if (sequence_sql == NULL)
	{
		printf("cannot open %s\n", sequence_file);
		return 3;
	}
	if (rdbms == SAPDB)
	{
		fprintf(sequence_sql, "sql_connect dbt,dbt\n");
		fprintf(sequence_sql,
			"%s CREATE SEQUENCE custid INCREMENT BY 1 START WITH %d\n",
			exec_sql,
			2880 * ebs + 1);
	fprintf(sequence_sql,
			"%s CREATE SEQUENCE addrid INCREMENT BY 1 START WITH %d\n",
			exec_sql,
			ebs * 2880 * 2 + 1);
	fprintf(sequence_sql,
			"%s CREATE SEQUENCE scid INCREMENT BY 1 START WITH %d\n",
			exec_sql,
			(int) ((double) ebs * 2880.0 * 0.9 + 1.0));
	}
	else
	{
		fprintf(sequence_sql,
			"%s CREATE SEQUENCE custid INCREMENT 1 START %d;\n",
			exec_sql,
			2880 * ebs + 1);
		fprintf(sequence_sql, "commit;");
		fprintf(sequence_sql,
			"%s CREATE SEQUENCE addrid INCREMENT 1 START %d;\n",
			exec_sql,
			ebs * 2880 * 2 + 1);
		fprintf(sequence_sql, "commit;");
		fprintf(sequence_sql,
			"%s CREATE SEQUENCE scid INCREMENT 1 START %d;\n",
			exec_sql,
			(int) ((double) ebs * 2880.0 * 0.9 + 1.0));
		fprintf(sequence_sql, "commit;");
	}
	fclose(sequence_sql);

	dpath = (char *) malloc(sizeof(char) * 64);
	strcpy(dpath, "../wgen/grammar.tpcw");

	init_common();
	load_dists();
	printf("generating data files...\n");

	if (flag_item == 1) 
	{
		gen_items();
		sprintf(cmd, "ln -fs %s/item.data /tmp/item.data\n", path);
		popen(cmd, "r");
	}

	if (flag_cust == 1)
	{
		gen_customers();
		sprintf(cmd, "ln -fs %s/customer.data /tmp/customer.data", path);
		popen(cmd, "r");
	}

	if (flag_author == 1) 
	{
		gen_authors();
		sprintf(cmd, "ln -fs %s/author.data /tmp/author.data", path);
		popen(cmd, "r");
	}

	if (flag_address == 1)
	{
		gen_addresses();
		sprintf(cmd, "ln -fs %s/address.data /tmp/address.data", path);
		popen(cmd, "r");
	}

	if (flag_order == 1)
	{
		gen_orders();
		sprintf(cmd, "ln -fs %s/orders.data /tmp/orders.data", path);
		popen(cmd, "r");
		sprintf(cmd, "ln -fs %s/order_line.data /tmp/order_line.data",
			path);
		popen(cmd, "r");
		sprintf(cmd, "ln -fs %s/cc_xacts.data /tmp/cc_xacts.data", path);
		popen(cmd, "r");
	}

	if (rdbms == SAPDB)
	{
		sprintf(cmd, "ln -fs %s/country.data /tmp/country.data", pwd);
	}
	else if (rdbms == PGSQL)
	{
		sprintf(cmd, "ln -fs %s/country.data.pgsql /tmp/country.data", pwd);
	}
	popen(cmd, "r");

	free(dpath);
	return 0;
}