예제 #1
0
void hexedit_driver(struct hexedit *buf, int c)
{
	switch (c) {
	case HE_CURSOR_UP:
		cursor_up(buf);
		break;
	case HE_CURSOR_DOWN:
		cursor_down(buf);
		break;
	case HE_CURSOR_LEFT:
		cursor_left(buf);
		break;
	case HE_CURSOR_RIGHT:
		cursor_right(buf);
		break;
	case HE_CURSOR_PGUP:
		break;
	case HE_CURSOR_PGDN:
		break;
	case HE_BACKSPACE:
		do_backspace(buf);
		break;
	case HE_DELETE:
		do_delete(buf);
		break;
	default:
		do_edit(buf, c & 0xff);
		break;
	}

	hexedit_set_cursor(buf);
}
예제 #2
0
파일: version2.1.c 프로젝트: Eaeth/myNCCL
void do_choice(int choice)
{
	printf("is in the process of the first %d a choice \n", choice);

	switch (choice)
	{
		case INSERT :
			do_insert();
			break;
		case QUERY:
			do_query();
			break;
		case UPDATE:
			do_update();
			break;
		case DELETE:
			do_delete();
			break;
		case LIST:
			do_list_all();
			break;
		case QUIT:
			do_quit();
			break;
		default:
			break;
	}
}
예제 #3
0
	static inline void delete_(raw_ptr ptr)
	{
		do_delete(
			ptr,
			typename std::is_void<original_type>::type()
		);
	}
예제 #4
0
static void run_application(MYSQL &mysql,
			    Ndb_cluster_connection &cluster_connection,
			    const char* table,
			    const char* db)
{
  /********************************************
   * Connect to database via mysql-c          *
   ********************************************/
 char db_stmt[256];
 sprintf(db_stmt, "CREATE DATABASE %s\n", db);
  mysql_query(&mysql, db_stmt);
 sprintf(db_stmt, "USE %s", db);
  if (mysql_query(&mysql, db_stmt) != 0) MYSQLERROR(mysql);
  create_table(mysql, table);

  /********************************************
   * Connect to database via NdbApi           *
   ********************************************/
  // Object representing the database
  Ndb myNdb( &cluster_connection, db );
  if (myNdb.init()) APIERROR(myNdb.getNdbError());

  /*
   * Do different operations on database
   */
  do_insert(myNdb, table);
  do_update(myNdb, table);
  do_delete(myNdb, table);
  do_read(myNdb, table);
  /*
   * Drop the table
   */
  mysql_query(&mysql, db_stmt);
}
예제 #5
0
파일: change.c 프로젝트: ameenross/dex
static void reverse_change(struct change *change)
{
	if (buffer->views.count > 1)
		fix_cursors(change->offset, change->ins_count, change->del_count);

	block_iter_goto_offset(&view->cursor, change->offset);
	if (!change->ins_count) {
		// convert delete to insert
		do_insert(change->buf, change->del_count);
		if (change->move_after)
			block_iter_skip_bytes(&view->cursor, change->del_count);
		change->ins_count = change->del_count;
		change->del_count = 0;
		free(change->buf);
		change->buf = NULL;
	} else if (change->del_count) {
		// reverse replace
		long del_count = change->ins_count;
		long ins_count = change->del_count;
		char *buf = do_replace(del_count, change->buf, ins_count);

		free(change->buf);
		change->buf = buf;
		change->ins_count = ins_count;
		change->del_count = del_count;
	} else {
		// convert insert to delete
		change->buf = do_delete(change->ins_count);
		change->del_count = change->ins_count;
		change->ins_count = 0;
	}
}
예제 #6
0
static void run_application(MYSQL &mysql,
			    Ndb_cluster_connection &cluster_connection)
{
  /********************************************
   * Connect to database via mysql-c          *
   ********************************************/
  mysql_query(&mysql, "CREATE DATABASE TEST_DB_1");
  if (mysql_query(&mysql, "USE TEST_DB_1") != 0) MYSQLERROR(mysql);
  create_table(mysql);

  /********************************************
   * Connect to database via NdbApi           *
   ********************************************/
  // Object representing the database
  Ndb myNdb( &cluster_connection, "TEST_DB_1" );
  if (myNdb.init()) APIERROR(myNdb.getNdbError());

  /*
   * Do different operations on database
   */
  do_insert(myNdb);
  do_update(myNdb);
  do_delete(myNdb);
  do_read(myNdb);
  drop_table(mysql);
  mysql_query(&mysql, "DROP DATABASE TEST_DB_1");
}
예제 #7
0
void
delete_cb (GtkWidget * widget, gpointer data)
{
  sw_view * view = (sw_view *)data;
  sw_sample * s = view->sample;

  do_delete (s);
}
예제 #8
0
int
main(int argc, char *argv[])
{
	PGconn			*conn;
	StringInfoData	 conn_info;
	int				 num_options;

	num_options = pgut_getopt(argc, argv, options);

	/* command-line arguments is not necessary */
	if (num_options != argc)
		ereport(ERROR,
			(errcode(EINVAL),
			 errmsg("too many argumetns")));

	/* can't specified the mode two or more */
	if ((mode_list && (mode_size || mode_report || mode_snapshot || mode_delete)) ||
		(mode_size && (mode_report || mode_snapshot || mode_delete)) ||
		(mode_report && (mode_snapshot || mode_delete)) ||
		(mode_snapshot && mode_delete))
		ereport(ERROR,
			(errcode(EINVAL),
			 errmsg("can't specify two or more mode")));

	/* connect to database */
	initStringInfo(&conn_info);
	if (dbname && dbname[0])
		appendStringInfo(&conn_info, "dbname=%s ", dbname);
	if (host && host[0])
		appendStringInfo(&conn_info, "host=%s ", host);
	if (port && port[0])
		appendStringInfo(&conn_info, "port=%s ", port);
	if (username && username[0])
		appendStringInfo(&conn_info, "user=%s ", username);

	conn = pgut_connect(conn_info.data, prompt_password, ERROR);
	termStringInfo(&conn_info);

	/* execute a specified operation */
	if (mode_list)
		do_list(conn, instid);
	else if (mode_size)
		do_size(conn);
	else if (mode_report)
		do_report(conn, mode_report,
			instid, beginid, endid, begindate, enddate, output);
	else if (mode_snapshot)
		do_snapshot(conn, mode_snapshot);
	else if (mode_delete)
		do_delete(conn, mode_delete);
	else
		ereport(ERROR,
			(errcode(EINVAL),
			 errmsg("please specify operation option (-l, -s, -r, -S, -D)")));

	pgut_disconnect(conn);
	return 0;
}
예제 #9
0
END_TEST

//int do_delete(const u64_t useridnr, const char * const user);
START_TEST(test_do_delete)
{
	int result;
	u64_t user_idnr;
	auth_user_exists("testadduser",&user_idnr);
	fail_unless(user_idnr > 0,"abort test_do_delete: can't find user_idnr");
	result = do_delete(user_idnr, "testadduser");
	fail_unless(result==0,"test_do_delete failed");
}
예제 #10
0
파일: hash-ay.c 프로젝트: ayourtch/libay
void h_do_delete(htable_t *ht, hash_entry_t *hen, hcallback_func_t *do_delete)
{
  // unconditional removal. Should not be called directly because does not know about iterators...
  if(do_delete) {
    do_delete(hen->key, hen->key_len, hen->data, NULL);
  }
  LIST_REMOVE(hen, entries);
  LIST_REMOVE(hen, all_entries);
  ht->total_items--;
  if(hen->destructor) {
    hen->destructor(hen->key, hen->key_len, hen->data, NULL);
  }
  free(hen->key);
  free(hen);
}
예제 #11
0
/********************************************************************/ /**
 * Deletes a picture from the database.
 */
int do_delete_cmd(int args, char* argv[])
{
    ARG_CHECK(args, 3);

    struct pictdb_file db_file;

    int ret = do_open(argv[1], "rb+", &db_file);
    if (ret == 0) {
        puts("Delete");
        ret = do_delete(&db_file, argv[2]);
    }
    do_close(&db_file);

    return ret;
}
예제 #12
0
int
main(int argc, char **argv)
{
	int rv = SUCCESS;

	(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
#define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it weren't */
#endif
	(void) textdomain(TEXT_DOMAIN);

	/* Running from within a non-global zone is not supported yet. */
	if (getzoneid() != GLOBAL_ZONEID) {
		(void) fprintf(stderr,
		    gettext("Error: Configuring KSSL from within a non-global "
		    "zone is not supported.\nPlease run the command from "
		    "the global zone.\n"));
		return (ERROR_USAGE);
	}

	if (argc < 2) {
		usage_all();
		return (ERROR_USAGE);
	}

	if (strcmp(argv[1], "create") == 0) {
		rv = do_create(argc, argv);
	} else if (strcmp(argv[1], "delete") == 0) {
		rv = do_delete(argc, argv);
	} else if (strcmp(argv[1], "-V") == 0) {
		(void) printf("%s\n", KSSLCFG_VERSION);
	} else if (strcmp(argv[1], "-?") == 0) {
		usage_all();
	} else {
		(void) fprintf(stderr,
		    gettext("Error: Unknown subcommand -- %s\n"), argv[1]);
		usage_all();
		rv = ERROR_USAGE;
	}

	return (rv);
}
예제 #13
0
파일: fsdiff.c 프로젝트: slachowsky/fsdiff
static int do_delete(struct dirent *d)
{
	int ret;
	struct stat sb;
	char realname[PATH_MAX];
	char savename[PATH_MAX];

	sprintf(realname, "%s%s/%s", base1, prefix, d->d_name);
	sprintf(savename, "%s%s/%s", "delete", prefix, d->d_name);

	if(d->d_type == DT_DIR) {
		DIR *dir;
		struct dirent *dp;
		int len = strlen(prefix);
		strcat(prefix, "/");
		strcat(prefix, d->d_name);
		dir = opendir(realname);
		while ((dp = readdir(dir)) != NULL) {
			if (!filter(dp))
				continue;
			do_delete(dp);
		}
		prefix[len] = 0;
	}

	fprintf(stderr, "%s/%s was deleted\n", prefix, d->d_name);
	if(!t) return 0;

	ret = lstat(realname, &sb);
	th_set_from_stat(t, &sb);
	th_set_path(t, savename);
	th_set_size(t, 0);
	th_finish(t);
	if(t->options & TAR_VERBOSE)
		th_print_long_ls(t);
	th_write(t);
}
예제 #14
0
void handle_delete_call(struct mg_connection* nc,
                        struct http_message* hm)
{
    char** result = init_result_array();
    char* tmp = init_tmp();
    if (result == NULL || tmp == NULL) {
        free(result);
        free(tmp);
        mg_error(nc, ERR_OUT_OF_MEMORY);
        return;
    }

    split(result, tmp, hm->query_string.p, "&=", hm->query_string.len);

    int err_check = -1;
    char* pict_id = NULL;
    parse_uri(result, &err_check, &pict_id);

    if (pict_id != NULL) {
        err_check = do_delete(db_file, pict_id);
        if (err_check == 0) {
            mg_printf(nc,
                      "HTTP/1.1 302 Found\r\n"
                      "Location: http://localhost:%s/index.html\r\n",
                      s_http_port);
            nc->flags |= MG_F_SEND_AND_CLOSE;
        }
    }

    if (err_check != 0) {
        mg_error(nc, err_check);
    }

    free(result);
    free(tmp);
}
예제 #15
0
파일: change.c 프로젝트: ameenross/dex
static void buffer_delete_bytes_internal(long len, bool move_after)
{
	view_reset_preferred_x(view);
	if (len == 0)
		return;

	// check if all newlines from EOF would be deleted
	if (would_delete_last_bytes(len)) {
		struct block_iter bi = view->cursor;
		unsigned int u;

		if (buffer_prev_char(&bi, &u) && u != '\n') {
			// no newline before cursor
			if (--len == 0) {
				begin_change(CHANGE_MERGE_NONE);
				return;
			}
		}
	}
	record_delete(do_delete(len), len, move_after);

	if (buffer->views.count > 1)
		fix_cursors(block_iter_get_offset(&view->cursor), len, 0);
}
예제 #16
0
void
editor(int descr, dbref player, const char *command)
{
	dbref program;
	int arg[MAX_ARG + 1];
	char buf[BUFFER_LEN];
	const char *word[MAX_ARG + 1];
	int i, j;					/* loop variables */

	program = PLAYER_CURR_PROG(player);

	/* check to see if we are insert mode */
	if (PLAYER_INSERT_MODE(player)) {
		insert(player, command);	/* insert it! */
		return;
	}
	/* parse the commands */
	for (i = 0; i <= MAX_ARG && *command; i++) {
		while (*command && isspace(*command))
			command++;
		j = 0;
		while (*command && !isspace(*command)) {
			buf[j] = *command;
			command++, j++;
		}

		buf[j] = '\0';
		word[i] = alloc_string(buf);
		if ((i == 1) && !string_compare(word[0], "def")) {
			if (word[1] && (word[1][0] == '.' || (word[1][0] >= '0' && word[1][0] <= '9'))) {
				notify(player, "Invalid macro name.");
				return;
			}
			while (*command && isspace(*command))
				command++;
			word[2] = alloc_string(command);
			if (!word[2])
				notify(player, "Invalid definition syntax.");
			else {
				if (insert_macro(word[1], word[2], player, &macrotop)) {
					notify(player, "Entry created.");
				} else {
					notify(player, "That macro already exists!");
				}
			}
			for (; i >= 0; i--) {
				if (word[i])
					free((void *) word[i]);
			}
			return;
		}
		arg[i] = atoi(buf);
		if (arg[i] < 0) {
			notify(player, "Negative arguments not allowed!");
			for (; i >= 0; i--) {
				if (word[i])
					free((void *) word[i]);
			}
			return;
		}
	}
	i--;
	while ((i >= 0) && !word[i])
		i--;
	if (i < 0) {
		return;
	} else {
		switch (word[i][0]) {
		case KILL_COMMAND:
			if (!Wizard(player)) {
				notify(player, "I'm sorry Dave, but I can't let you do that.");
			} else {
				if (kill_macro(word[0], player, &macrotop))
					notify(player, "Macro entry deleted.");
				else
					notify(player, "Macro to delete not found.");
			}
			break;
		case SHOW_COMMAND:
			list_macros(word, i, player, 1);
			break;
		case SHORTSHOW_COMMAND:
			list_macros(word, i, player, 0);
			break;
		case INSERT_COMMAND:
			do_insert(player, program, arg, i);
			notify(player, "Entering insert mode.");
			break;
		case DELETE_COMMAND:
			do_delete(player, program, arg, i);
			break;
		case QUIT_EDIT_COMMAND:
			do_quit(player, program);
			notify(player, "Editor exited.");
			break;
		case COMPILE_COMMAND:
			/* compile code belongs in compile.c, not in the editor */
			do_compile(descr, player, program, 1);
			notify(player, "Compiler done.");
			break;
		case LIST_COMMAND:
			do_list(player, program, arg, i);
			break;
		case EDITOR_HELP_COMMAND:
			spit_file(player, EDITOR_HELP_FILE);
			break;
		case VIEW_COMMAND:
			val_and_head(player, arg, i);
			break;
		case UNASSEMBLE_COMMAND:
			disassemble(player, program);
			break;
		case NUMBER_COMMAND:
			toggle_numbers(player, arg, i);
			break;
		case PUBLICS_COMMAND:
			list_publics(descr, player, arg, i);
			break;
		default:
			notify(player, "Illegal editor command.");
			break;
		}
	}
	for (; i >= 0; i--) {
		if (word[i])
			free((void *) word[i]);
	}
}
void AssemblyInstanceItem::slot_delete()
{
    if (m_project_builder.get_rendering_manager().is_rendering())
        schedule_delete();
    else do_delete();
}
예제 #18
0
/*===========================================================================*
 *				main                                         *
 *===========================================================================*/
PUBLIC int main(int argc, char **argv)
{
/* This is the main routine of this service. The main loop consists of 
 * three major activities: getting new work, processing the work, and
 * sending the reply. The loop never terminates, unless a panic occurs.
 */
  message m;
  int result;                 

  /* SEF local startup. */
  env_setargs(argc, argv);
  sef_local_startup();

  /* Main loop - get work and do it, forever. */         
  while (TRUE) {              

      /* Wait for incoming message, sets 'callnr' and 'who'. */
      get_work(&m);

      if (is_notify(callnr)) {
          printf("DS: warning, got illegal notify from: %d\n", m.m_source);
          result = EINVAL;
          goto send_reply;
      }

      switch (callnr) {
      case DS_PUBLISH:
          result = do_publish(&m);
          break;
      case DS_RETRIEVE:
	  result = do_retrieve(&m);
	  break;
      case DS_RETRIEVE_LABEL:
	  result = do_retrieve_label(&m);
	  break;
      case DS_DELETE:
	  result = do_delete(&m);
	  break;
      case DS_SUBSCRIBE:
	  result = do_subscribe(&m);
	  break;
      case DS_CHECK:
	  result = do_check(&m);
	  break;
      case DS_SNAPSHOT:
	  result = do_snapshot(&m);
	  break;
      case GETSYSINFO:
	  result = do_getsysinfo(&m);
	  break;
      default: 
          printf("DS: warning, got illegal request from %d\n", m.m_source);
          result = EINVAL;
      }

send_reply:
      /* Finally send reply message, unless disabled. */
      if (result != EDONTREPLY) {
          m.m_type = result;  		/* build reply message */
	  reply(who_e, &m);		/* send it away */
      }
  }
  return(OK);				/* shouldn't come here */
}
예제 #19
0
/*
 * Entry point of pg_arman command.
 */
int
main(int argc, char *argv[])
{
	const char	   *cmd = NULL;
	const char	   *range1 = NULL;
	const char	   *range2 = NULL;
	pgBackupRange	range;
	int				i;

	/* do not buffer progress messages */
	setvbuf(stdout, 0, _IONBF, 0);	/* TODO: remove this */

	/* initialize configuration */
	catalog_init_config(&current);

	/* overwrite configuration with command line arguments */
	i = pgut_getopt(argc, argv, options);

	for (; i < argc; i++)
	{
		if (cmd == NULL)
			cmd = argv[i];
		else if (range1 == NULL)
			range1 = argv[i];
		else if (range2 == NULL)
			range2 = argv[i];
		else
			elog(ERROR, "too many arguments");
	}

	/* command argument (backup/restore/show/...) is required. */
	if (cmd == NULL)
	{
		help(false);
		return 1;
	}

	/* get object range argument if any */
	if (range1 && range2)
		parse_range(&range, range1, range2);
	else if (range1)
		parse_range(&range, range1, "");
	else
		range.begin = range.end = 0;

	/* Read default configuration from file. */
	if (backup_path)
	{
		char	path[MAXPGPATH];
		/* Check if backup_path is directory. */
		struct stat stat_buf;
		int rc = stat(backup_path, &stat_buf);

		/* If rc == -1,  there is no file or directory. So it's OK. */
		if (rc != -1 && !S_ISDIR(stat_buf.st_mode))
			elog(ERROR, "-B, --backup-path must be a path to directory");

		join_path_components(path, backup_path, PG_RMAN_INI_FILE);
		pgut_readopt(path, options, ERROR);
	}

	/* BACKUP_PATH is always required */
	if (backup_path == NULL)
		elog(ERROR, "required parameter not specified: BACKUP_PATH (-B, --backup-path)");

	/* path must be absolute */
	if (backup_path != NULL && !is_absolute_path(backup_path))
		elog(ERROR, "-B, --backup-path must be an absolute path");
	if (pgdata != NULL && !is_absolute_path(pgdata))
		elog(ERROR, "-D, --pgdata must be an absolute path");
	if (arclog_path != NULL && !is_absolute_path(arclog_path))
		elog(ERROR, "-A, --arclog-path must be an absolute path");

	/* Sanity checks with commands */
	if (pg_strcasecmp(cmd, "delete") == 0 && arclog_path == NULL)
		elog(ERROR, "delete command needs ARCLOG_PATH (-A, --arclog-path) to be set");

	/* setup exclusion list for file search */
	for (i = 0; pgdata_exclude[i]; i++)		/* find first empty slot */
		;
	if (arclog_path)
		pgdata_exclude[i++] = arclog_path;

	/* do actual operation */
	if (pg_strcasecmp(cmd, "init") == 0)
		return do_init();
	else if (pg_strcasecmp(cmd, "backup") == 0)
	{
		pgBackupOption bkupopt;
		int res;
		bkupopt.smooth_checkpoint = smooth_checkpoint;
		bkupopt.keep_data_generations = keep_data_generations;
		bkupopt.keep_data_days = keep_data_days;

		/* Do the backup */
		res = do_backup(bkupopt);
		if (res != 0)
			return res;

		/* If validation has been requested, do it */
		range.begin = current.start_time;
		range.end = current.start_time + 1;
		if (backup_validate)
			do_validate(&range);
	}
	else if (pg_strcasecmp(cmd, "restore") == 0)
		return do_restore(target_time, target_xid,
					target_inclusive, target_tli);
	else if (pg_strcasecmp(cmd, "show") == 0)
		return do_show(&range, show_all);
	else if (pg_strcasecmp(cmd, "validate") == 0)
		return do_validate(&range);
	else if (pg_strcasecmp(cmd, "delete") == 0)
		return do_delete(&range);
	else
		elog(ERROR, "invalid command \"%s\"", cmd);

	return 0;
}
예제 #20
0
파일: destor.c 프로젝트: fdl66/chongshan
int main(int argc, char **argv) {

	destor_start();
	int job = DESTOR_BACKUP;
	int revision = -1;

	int opt = 0;
	while ((opt = getopt_long(argc, argv, short_options, long_options, NULL))
			!= -1) {
		switch (opt) {
		case 'r':
			job = DESTOR_RESTORE;
			revision = atoi(optarg);
			break;
		case 's':
			destor_stat();
			break;
		case 't':
			job = DESTOR_MAKE_TRACE;
			break;
		case 'h':
			usage();
			break;
		case 'p': {
			sds param = sdsnew(optarg);
			load_config_from_string(param);
			break;
		}
		default:
			return 0;
		}
	}
	sds path = NULL;
    

	switch (job) {
	case DESTOR_BACKUP:

		if (argc > optind) {
			path = sdsnew(argv[optind]);
		} else {
			fprintf(stderr, "backup job needs a protected path!\n");
			usage();
		}

		do_backup(path);


		/*
		 * The backup concludes.
		 * GC starts
		 * */
		if(destor.backup_retention_time >= 0
				&& jcr.id >= destor.backup_retention_time){
			NOTICE("GC is running!");
			do_delete(jcr.id - destor.backup_retention_time);
		}

		sdsfree(path);

		break;
	case DESTOR_RESTORE:
		if (revision < 0) {
			fprintf(stderr, "A job id is required!\n");
			usage();
		}
		if (argc > optind) {
			path = sdsnew(argv[optind]);
		} else {
			fprintf(stderr, "A target directory is required!\n");
			usage();
		}

		do_restore(revision, path[0] == 0 ? 0 : path);

		sdsfree(path);
		break;
	case DESTOR_MAKE_TRACE: {
		if (argc > optind) {
			path = sdsnew(argv[optind]);
		} else {
			fprintf(stderr, "A target directory is required!\n");
			usage();
		}

		make_trace(path);
		sdsfree(path);
		break;
	}
	default:
		fprintf(stderr, "Invalid job type!\n");
		usage();
	}
	destor_shutdown();

	return 0;
}
예제 #21
0
change_list
common(T &new_e, osm::db::OWLDatabase &d, io::Diff::Action action) {
  id_t id = new_e.id;
  change_list changes;

  // force deleted status on delete actions
  if (action == io::Diff::Delete) {
    new_e.visible = false;
  }

  if (T::db_exists(id, d)) {
    T old_e = T::db_load(id, d);

    // existing element - check the version
    version_t old_ver = old_e.version;
    version_t new_ver = new_e.version;

    /* not yet - we'll get around to this later...
       while (new_ver > old_ver + 1) {
       // get intervening versions from the API, updating old_ver.
       T mid_e;
      
       APIDatabase api_db;
       if (!mid_e.db_load(api_db, id, old_ver + 1)) {
       throw not_found("api database", id, old_ver + 1);
       }

       changes.splice(changes.end(), update(old_e, mid_e));
       old_e = mid_e;
       } 
    */
    if (new_ver <= old_ver) {
      if (new_ver == old_ver) {
        cout << "WARNING: Not applying change to " << T::type << " " << id 
             << ", at same version " << new_ver << "." << endl;
      } else {
        cout << "WARNING: Not applying downgrade to " << T::type << " " << id 
             << ", versions " << old_ver << " -> " << new_ver << "." << endl;
      }
    } else {
      if (new_ver > old_ver + 1) {
        cout << "WARNING: Skipping versions in " << T::type << " " << id 
             << ", versions " << old_ver << " -> " << new_ver << "." << endl;
      }

      // add changes to database.
      if (action == io::Diff::Delete) {
        splice_changes(changes, do_delete(old_e, new_e, d));
      } else {
        splice_changes(changes, update(old_e, new_e, d));
      }
      T::db_save(new_e, d);
    }

  } else {
    if (action == io::Diff::Delete) {
      if (new_e.version > 1) {
        cout << "WARNING: Not re-deleting " << T::type << " " << id 
             << ", is already deleted." << endl;
      }
    } else {
      // must be a new or undeleted element
      splice_changes(changes, create(new_e, d));
      T::db_save(new_e, d);
    }
  }

  return changes;
}
예제 #22
0
파일: mynano.c 프로젝트: mtawaken/gits
void do_backspace()
{
  do_left();
  do_delete();
}
예제 #23
0
static void
do_delete_test(uint32_t num_objs, uint32_t iters, uint32_t num_snaps)
{
	struct ZS_thread_state *thd_state;
	int i;
	uint32_t iter_print_cnt = 0;

	printf("============================= Snapshot object Delete Test =========================\n");
	fflush(stdout);
	ZSInitPerThreadState(zs_state, &thd_state);	
	open_stuff(thd_state, "cntr_2");

	snapshot_cnt = 0;

	/* Write the contents of snapshots */
	for (i = 0; i < num_snaps; i++) {
		printf("Iter: %u: Mputting %u objects\n", ++iter_print_cnt, 
		       num_objs);
		fflush(stdout);

		do_mput(thd_state, 0, num_objs, i, 0);

		printf("Creating Snapshot %u\n", i);
		fflush(stdout);
		create_snapshot(thd_state, i);
	}

#if 0
#include <string.h>
	printf("Waiting to get confirmation to proceed\n");
	getchar();
#endif

	/* After delete, validate if the latest data is reported
	 * not found and earlier snapshot still intact */
	do_delete(thd_state, 0, num_objs, ZS_SUCCESS);
	do_read_verify(thd_state, 0, num_objs, ZS_OBJECT_UNKNOWN);
	do_read_verify_snapshot(thd_state, 0, num_objs, num_snaps-1, 20);

	/* Do a range query (read/verify active snapshot) and 
	 * ensure that no objects are found */
	printf("Doing range query for latest update\n");
	do_read_verify_snapshot(thd_state, 0, 0, num_snaps, 20);

	/* Do delete on top of tombstone delete and ensure it
	 * says key not found */
	do_delete(thd_state, 0, num_objs, ZS_OBJECT_UNKNOWN);

	for (i = 0; i < num_snaps; i++) {
		printf("Deleting Snapshot %u\n", i+1);
		fflush(stdout);
		delete_snapshot(thd_state, i);
	}

	/* Do another round of insert on top of tombstoned one and
	 * delete them to see if we still see key not found */
	printf("Iter: %u: Mputting %u objects\n", ++iter_print_cnt, 
	       num_objs);
	fflush(stdout);
	do_mput(thd_state, 0, num_objs, iters++, 0);
	do_delete(thd_state, 0, num_objs, ZS_SUCCESS);
	do_read_verify(thd_state, 0, num_objs, ZS_OBJECT_UNKNOWN);
	free_stuff(thd_state);

	ZSReleasePerThreadState(&thd_state);
}
예제 #24
0
파일: client.c 프로젝트: actility/ong
int main(int argc, char **argv) {
	void		*tabpoll;
	dia_context_t	*dia;
	int result;
	char addr_str[200] = "::1";
	char port_str[10] = "5683";
	int opt;
	int log_level = 0;
	int count = 1, i;
	int group = 1;
	char loss = 0;

	while ((opt = getopt(argc, argv, "A:p:v:m:f:n:g:R:l")) != -1) {
		switch (opt) {
		case 'A' :
			strncpy(addr_str, optarg, 200-1);
			addr_str[200 - 1] = '\0';
			break;
		case 'p' :
			strncpy(port_str, optarg, 10-1);
			port_str[10 - 1] = '\0';
			break;
		case 'm' :
			strcpy (method, optarg);
			break;
		case 'R' :
			strcpy (reqEntity, optarg);
			break;
		case 'l' :
			loss = 1;
			break;
		case 'f' :
			strcpy (file, optarg);
			break;
		case 'n' :
			count = atoi(optarg);
			break;
		case 'g' :
			group = atoi(optarg);
			break;
		case 'v' :
			log_level = strtol(optarg, NULL, 10);
			break;
		default:
			usage();
			exit( 1 );
		}
	}

	if (optind == argc) {
		fprintf (stderr, "You must specify a targetID\n");
		usage();
		exit (1);
	}

	char *targetID	= argv[optind];

	dia = dia_createContext(&callbacks);
	if (!dia) {
		fprintf (stderr, "dia_createContext failed\n");
		usage();
		exit (1);
	}

	dia_withLoss (dia, loss);

	tabpoll = rtl_pollInit ();

	sock	= resolve_address(addr_str, &addr);
	addr.addr.sin.sin_port = htons(atoi(port_str));

	rtl_pollAdd (tabpoll, sock, network_input, network_request, dia, NULL);

	signal(SIGINT, handle_sigint);

	for	(i=0; i<count; i++) {
		if	(!strcmp(method, "create"))
			do_create (dia, targetID, group);
		else if	(!strcmp(method, "retrieve"))
			do_retrieve (dia, targetID, group);
		else if	(!strcmp(method, "update"))
			do_update (dia, targetID, group);
		else if	(!strcmp(method, "delete"))
			do_delete (dia, targetID, group);
		else {
			usage ();
			exit (1);
		}

		dIa_status (dia);

		while ( more ) {
			struct dia_timeval tv;
			dIa_nextTimer (dia, &tv);
			result = rtl_poll(tabpoll, (tv.tv_sec*1000) + (tv.tv_usec/1000));
		}

		dIa_status (dia);

		if	(quit)
			break;
	}

	return 0;
}
예제 #25
0
int main (int argc, char **argv)
#endif
{
  int test_fd, listen_fd, cli_fd;
  socklen_t  cliaddr_len;
  struct sockaddr_un test_addr, listen_addr, cli_addr;
  const int on = 1;
  int nbytes;
  struct ucred cli_cred;
  int ucred_len = sizeof(cli_cred);
  struct be_msg smsg, rmsg;
  struct stat listen_stat;

  openlog("pvc2684d",LOG_PERROR, LOG_DAEMON);

  bzero(group_head.name,MAX_GROUPNAME_LEN);
  group_head.head = NULL;
  group_head.next = NULL;

  bzero(&test_addr, sizeof(test_addr));
  test_addr.sun_family = AF_LOCAL;
  strncpy(test_addr.sun_path, BRPVC_SOCKPATH, sizeof(test_addr.sun_path) -1);
  memcpy(&listen_addr, &test_addr, sizeof(test_addr));

  if( (test_fd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) 
    do_error(LOG_ERR,"Couldn't create initial socket: %s",strerror(errno));

  /* Check for already running daemon  */

  if(connect(test_fd, (struct sockaddr *) &test_addr, sizeof(test_addr))) {
    if(errno == ECONNREFUSED)
      unlink(BRPVC_SOCKPATH);
  }
  close(test_fd);

  if( (listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0)
    do_error(LOG_ERR,"Couldn't create server socket: %s",strerror(errno));

  if( bind(listen_fd, (struct sockaddr *) &listen_addr, SUN_LEN(&listen_addr)) ) {
    do_error(LOG_WARNING,"Another b2684d is running");
    exit(-1);
  }
  
  
  if(stat(BRPVC_SOCKPATH, &listen_stat))
    do_error(LOG_ERR,"Can't fstat listen socket: %s",strerror(errno));

  if(chmod(BRPVC_SOCKPATH, listen_stat.st_mode | S_IWOTH))
    do_error(LOG_ERR,"Can't fchmod listen socket: %s",strerror(errno));

  if( listen(listen_fd, 5) )
    do_error(LOG_ERR,"listen() on server socket failed: %s",strerror(errno));
  
  while(1) {
    cliaddr_len = sizeof(cli_addr);
    if((cli_fd = accept(listen_fd, (struct sockaddr *) &cli_addr, &cliaddr_len)) < 0) {
      if(errno == EINTR)
	continue;
      else
	do_error(LOG_ERR,"accept() on server socket failed: %s",strerror(errno));
    }
    if( setsockopt(cli_fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)) < 0 )
      do_error(LOG_ERR,"setsockopt() on client socket failed: %s",strerror(errno));
    
    while((nbytes = recv(cli_fd, &rmsg, sizeof(rmsg), 0)) > 0) {
      switch (rmsg.msgtype) {
	
      case HELLO:
	
	if ( getsockopt(cli_fd, SOL_SOCKET, SO_PEERCRED, &cli_cred, &ucred_len) < 0 )
	  do_error(LOG_ERR,"getsockopt() for credentials failed: %s",strerror(errno));
	
	smsg.msgtype = OK;
	if( send(cli_fd, &smsg, sizeof(smsg), 0) < 0 )
	  do_error(LOG_ERR,"Couldn't send OK message to new client: %s",strerror(errno)); 

	break;
      
      case ADD:

	do_add(cli_fd,&rmsg,&cli_cred);
	break;
      
      case DELETE:

	do_delete(cli_fd,&rmsg,&cli_cred);
	break;
      
      case DELETE_GROUP:

	do_delete_group(cli_fd,rmsg.name,&cli_cred);
	break;
      
      case LIST_GROUP:
	 
	do_list_group(cli_fd,&rmsg);
	break;
      
      case LIST_ALL:

	do_list_all(cli_fd,&rmsg);
	break;

      case MEM_STATS:
	
	if( send(cli_fd, &memstat, sizeof(memstat), 0) < 0 )
	  do_error(LOG_ERR,"Couldn't send MEM_STAT message: %s",strerror(errno)); 
	break;
      
      default:
	smsg.msgtype = UNKNOWN_CMD;
	if( send(cli_fd, &smsg, sizeof(smsg), 0) < 0 )
	  do_error(LOG_ERR,"Couldn't send UNKNOWN_COMMAND message: %s",strerror(errno)); 
      }
    }
    close(cli_fd);
  }
}
예제 #26
0
파일: listen.cpp 프로젝트: A-eolus/mysql
int 
main(int argc, const char** argv){
  ndb_init();

  
  int _help = 0;
  const char* db = 0;
  const char* connectstring1 = 0;
  const char* connectstring2 = 0;

  struct getargs args[] = {
    { "connectstring1", 'c',
      arg_string, &connectstring1, "connectstring1", "" },
    { "connectstring2", 'C',
      arg_string, &connectstring2, "connectstring2", "" },
    { "database", 'd', arg_string, &db, "Database", "" },
    { "usage", '?', arg_flag, &_help, "Print help", "" }
  };
  int num_args = sizeof(args) / sizeof(args[0]);
  int optind = 0, i;
  char desc[] = 
    "<tabname>+ \nThis program listen to events on specified tables\n";
  
  if(getarg(args, num_args, argc, argv, &optind) ||
     argv[optind] == NULL || _help) {
    arg_printusage(args, num_args, argv[0], desc);
    return NDBT_ProgramExit(NDBT_WRONGARGS);
  }

  // Connect to Ndb
  Ndb_cluster_connection con(connectstring1);
  if(con.connect(12, 5, 1) != 0)
  {
    return NDBT_ProgramExit(NDBT_FAILED);
  }
  Ndb MyNdb( &con, db ? db : "TEST_DB" );

  if(MyNdb.init() != 0){
    ERR(MyNdb.getNdbError());
    return NDBT_ProgramExit(NDBT_FAILED);
  }

  // Connect to Ndb and wait for it to become ready
  while(MyNdb.waitUntilReady() != 0)
    ndbout << "Waiting for ndb to become ready..." << endl;

  Ndb_cluster_connection *con2 = NULL;
  Ndb *ndb2 =  NULL;
  if (connectstring2)
  {
    con2 = new Ndb_cluster_connection(connectstring2);

    if(con2->connect(12, 5, 1) != 0)
    {
      return NDBT_ProgramExit(NDBT_FAILED);
    }
    ndb2 = new Ndb( con2, db ? db : "TEST_DB" );

    if(ndb2->init() != 0){
      ERR(ndb2->getNdbError());
      return NDBT_ProgramExit(NDBT_FAILED);
    }

    // Connect to Ndb and wait for it to become ready
    while(ndb2->waitUntilReady() != 0)
      ndbout << "Waiting for ndb to become ready..." << endl;
  }

  int result = 0;
  
  NdbDictionary::Dictionary *myDict = MyNdb.getDictionary();
  Vector<NdbDictionary::Event*> events;
  Vector<NdbEventOperation*> event_ops;
  int sz = 0;
  for(i= optind; i<argc; i++)
  {
    const NdbDictionary::Table* table= myDict->getTable(argv[i]);
    if(!table)
    {
      ndbout_c("Could not find table: %s, skipping", argv[i]);
      continue;
    }

    BaseString name;
    name.appfmt("EV-%s", argv[i]);
    NdbDictionary::Event *myEvent= new NdbDictionary::Event(name.c_str());
    myEvent->setTable(table->getName());
    myEvent->addTableEvent(NdbDictionary::Event::TE_ALL); 
    for(int a = 0; a < table->getNoOfColumns(); a++){
      myEvent->addEventColumn(a);
    }

    if (myDict->createEvent(* myEvent))
    {
      if(myDict->getNdbError().classification == NdbError::SchemaObjectExists) 
      {
	g_info << "Event creation failed event exists. Removing...\n";
	if (myDict->dropEvent(name.c_str()))
	{
	  g_err << "Failed to drop event: " << myDict->getNdbError() << endl;
	  result = 1;
	  goto end;
	}
	// try again
	if (myDict->createEvent(* myEvent)) 
	{
	  g_err << "Failed to create event: " << myDict->getNdbError() << endl;
	  result = 1;
	  goto end;
	}
      }
      else
      {
	g_err << "Failed to create event: " << myDict->getNdbError() << endl;
	result = 1;
	goto end;
      }
    }
    
    events.push_back(myEvent);

    NdbEventOperation* pOp = MyNdb.createEventOperation(name.c_str());
    if ( pOp == NULL ) {
      g_err << "Event operation creation failed" << endl;
      result = 1;
      goto end;
    }

    event_values.push_back(Vector<NdbRecAttr *>());
    event_pre_values.push_back(Vector<NdbRecAttr *>());
    for (int a = 0; a < table->getNoOfColumns(); a++) 
    {
      event_values[sz].
        push_back(pOp->getValue(table->getColumn(a)->getName()));
      event_pre_values[sz].
        push_back(pOp->getPreValue(table->getColumn(a)->getName()));
    }
    event_ops.push_back(pOp);
    {
      struct Table_info ti;
      ti.id = sz;
      table_infos.push_back(ti);
    }
    pOp->setCustomData((void *)&table_infos[sz]);
    sz++;
  }

  for(i= 0; i<(int)event_ops.size(); i++)
  {
    if (event_ops[i]->execute())
    { 
      g_err << "operation execution failed: " << event_ops[i]->getNdbError()
	    << endl;
      result = 1;
      goto end;
    }
  }

  struct Trans_arg trans_arg;
  while(true)
  {
    while(MyNdb.pollEvents(100) == 0);
    
    NdbEventOperation* pOp= MyNdb.nextEvent();
    while(pOp)
    {
      Uint64 gci= pOp->getGCI();
      Uint64 cnt_i= 0, cnt_u= 0, cnt_d= 0;
      if (ndb2)
        do_begin(ndb2, trans_arg);
      do
      {
	switch(pOp->getEventType())
	{
	case NdbDictionary::Event::TE_INSERT:
	  cnt_i++;
          if (ndb2)
            do_insert(trans_arg, pOp);
	  break;
	case NdbDictionary::Event::TE_DELETE:
	  cnt_d++;
          if (ndb2)
            do_delete(trans_arg, pOp);
	  break;
	case NdbDictionary::Event::TE_UPDATE:
	  cnt_u++;
          if (ndb2)
            do_update(trans_arg, pOp);
	  break;
	case NdbDictionary::Event::TE_CLUSTER_FAILURE:
	  break;
	case NdbDictionary::Event::TE_ALTER:
	  break;
	case NdbDictionary::Event::TE_DROP:
	  break;
	case NdbDictionary::Event::TE_NODE_FAILURE:
	  break;
	case NdbDictionary::Event::TE_SUBSCRIBE:
	case NdbDictionary::Event::TE_UNSUBSCRIBE:
	  break;
	default:
	  /* We should REALLY never get here. */
	  ndbout_c("Error: unknown event type: %u", 
		   (Uint32)pOp->getEventType());
	  abort();
	}
      } while ((pOp= MyNdb.nextEvent()) && gci == pOp->getGCI());
      if (ndb2)
        do_commit(trans_arg);
      ndbout_c("GCI: %lld events: %lld(I) %lld(U) %lld(D)", gci, cnt_i, cnt_u, cnt_d);
    }
  }
end:
  for(i= 0; i<(int)event_ops.size(); i++)
    MyNdb.dropEventOperation(event_ops[i]);

  if (ndb2)
    delete ndb2;
  if (con2)
    delete con2;
  return NDBT_ProgramExit(NDBT_OK);
}
예제 #27
0
파일: annotate.c 프로젝트: dpl0/pkg
int
exec_annotate(int argc, char **argv)
{
	struct pkgdb	*db       = NULL;
	struct pkgdb_it	*it       = NULL;
	struct pkg	*pkg      = NULL;
	enum action	 action   = NONE;
	const char	*tag;
	const char	*value;
	const char	*pkgname;
	struct sbuf	*input    = NULL;
	int		 ch;
	int		 match    = MATCH_EXACT;
	int		 retcode;
	int		 exitcode = EX_OK;
	int		 flags = 0;

	struct option longopts[] = {
		{ "all",		no_argument,	NULL,	'a' },
		{ "add",		no_argument,	NULL,	'A' },
		{ "case-insensitive",	no_argument,	NULL,	'C' },
		{ "delete",		no_argument,	NULL,	'D' },
		{ "glob",		no_argument,	NULL,	'g' },
		{ "case-insensitive",	no_argument,	NULL,	'i' },
		{ "modify",		no_argument,	NULL,	'M' },
		{ "quiet",		no_argument,	NULL,	'q' },
		{ "show",		no_argument,	NULL,	'S' },
		{ "regex",		no_argument,	NULL,	'x' },
		{ "yes",		no_argument,	NULL,	'y' },
		{ NULL,			0,		NULL,	0   },
	};

        /* Set default case sensitivity for searching */
        pkgdb_set_case_sensitivity(
                pkg_object_bool(pkg_config_get("CASE_SENSITIVE_MATCH"))
                );

	while ((ch = getopt_long(argc, argv, "+aACDgiMqSxy", longopts, NULL))
	       != -1) {
		switch (ch) {
		case 'a':
			match = MATCH_ALL;
			break;
		case 'A':
			action = ADD;
			break;
		case 'C':
			pkgdb_set_case_sensitivity(true);
			break;
		case 'D':
			action = DELETE;
			break;
		case 'g':
			match = MATCH_GLOB;
			break;
		case 'i':
			pkgdb_set_case_sensitivity(false);
			break;
		case 'M':
			action = MODIFY;
			break;
		case 'q':
			quiet = true;
			break;
		case 'S':
			action = SHOW;
			flags |= PKG_LOAD_ANNOTATIONS;
			break;
		case 'x':
			match = MATCH_REGEX;
			break;
		case 'y':
			yes = true;
			break;
		default:
			usage_annotate();
			return (EX_USAGE);
		}
        }
	argc -= optind;
	argv += optind;

	if (action == NONE || 
	    (match == MATCH_ALL && argc < 1) ||
	    (match != MATCH_ALL && argc < 2)) {
		usage_annotate();
		return (EX_USAGE);
	}

	if (match == MATCH_ALL) {
		pkgname = NULL;
		tag     = argv[0];
		value   = (argc > 1) ? argv[1] : NULL;
	} else {
		pkgname = argv[0];
		tag     = argv[1];
		value   = (argc > 2) ? argv[2] : NULL;
	}

	if ((action == ADD || action == MODIFY) && value == NULL) {
		/* try and read data for the value from stdin. */
		input = read_input();
		value = sbuf_data(input);
	}

	retcode = pkgdb_access(PKGDB_MODE_READ|PKGDB_MODE_WRITE,
			       PKGDB_DB_LOCAL);
	if (retcode == EPKG_ENODB) {
		if (match == MATCH_ALL) {
			exitcode = EX_OK;
			goto cleanup;
		}
		if (!quiet)
			warnx("No packages installed.  Nothing to do!");
		exitcode = EX_OK;
		goto cleanup;
	} else if (retcode == EPKG_ENOACCESS) {
		warnx("Insufficient privileges to modify the package database");
		exitcode = EX_NOPERM;
		goto cleanup;
	} else if (retcode != EPKG_OK) {
		warnx("Error accessing the package database");
		exitcode = EX_SOFTWARE;
		goto cleanup;
	}

	retcode = pkgdb_open(&db, PKGDB_DEFAULT);
	if (retcode != EPKG_OK) {
		return (EX_IOERR);
	}

	if (pkgdb_obtain_lock(db, PKGDB_LOCK_EXCLUSIVE) != EPKG_OK) {
		pkgdb_close(db);
		warnx("Cannot get an exclusive lock on a database, it is locked by another process");
		return (EX_TEMPFAIL);
	}

	if ((it = pkgdb_query(db, pkgname, match)) == NULL) {
		exitcode = EX_IOERR;
		goto cleanup;
	}

	while ((retcode = pkgdb_it_next(it, &pkg, flags)) == EPKG_OK) {

		switch(action) {
		case NONE:	/* Should never happen */
			usage_annotate();
			exitcode = EX_USAGE;
			break;
		case ADD:
			retcode = do_add(db, pkg, tag, value);
			break;
		case MODIFY:
			retcode = do_modify(db, pkg, tag, value);
			break;
		case DELETE:
			retcode = do_delete(db, pkg, tag);
			break;
		case SHOW:
			retcode = do_show(pkg, tag);
			break;
		}

		if (retcode == EPKG_WARN)
			exitcode = EX_DATAERR;

		if (retcode != EPKG_OK && retcode != EPKG_WARN) {
			exitcode = EX_IOERR;
			goto cleanup;
		}
	}

cleanup:
	pkg_free(pkg);
	pkgdb_it_free(it);

	pkgdb_release_lock(db, PKGDB_LOCK_EXCLUSIVE);
	pkgdb_close(db);
	if (input != NULL)
		sbuf_delete(input);

	return (exitcode);
}
예제 #28
0
파일: fsdiff.c 프로젝트: slachowsky/fsdiff
static int cmpdir(const char* a, const char* b)
{
	struct dirent **namelist1, **namelist2;
	int n1, n2;
	int i1 = 0, i2 = 0;
	n1 = scandir(a, &namelist1, filter, alphasort);
	if (n1 < 0)
		perror("scandir");
	//printf("%d entries in %s\n", n1, a);
	n2 = scandir(b, &namelist2, filter, alphasort);
	if (n2 < 0)
		perror("scandir");
	//printf("%d entries in %s\n", n2, b);
	while (i1 < n1 || i2 < n2) {
		int ret; 
		if (i1 >= n1)
			ret = 1;
		else if (i2 >= n2)
			ret = -1;
		else
			ret = alphasort((const struct dirent **)namelist1+i1, (const struct dirent **)namelist2+i2);

		if (ret < 0) {
			do_delete(namelist1[i1]);
			free(namelist1[i1]);
			i1++;
		} else if (ret > 0) {
			do_add(namelist2[i2]);
			free(namelist2[i2]);
			i2++;
		} else {
			char buf1[1024], buf2[1024];
			//printf("%s match (recurse)\n", namelist1[i1]->d_name);
			sprintf(buf1, "%s/%s", a, namelist1[i1]->d_name);
			sprintf(buf2, "%s/%s", b, namelist2[i2]->d_name);
			if(namelist1[i1]->d_type != namelist2[i2]->d_type)
			{
				fprintf(stderr, "%s types differ, delete then add?\n", namelist1[i1]->d_name);
			} else if(namelist1[i1]->d_type == DT_LNK) {
				int len1, len2;
				len1 = readlink(buf1, buf1, 1024);
				len2 = readlink(buf2, buf2, 1024);
				//printf("SYMLINK %d %d\n", len1, len2);
				if(len1 != len2 || strncmp(buf1, buf2, len1)) {
					fprintf(stderr, "%s symlink target mismatch\n", namelist1[i1]->d_name);
				}
			} else if(namelist1[i1]->d_type == DT_DIR) {
				int len;
				len = strlen(prefix);
				strcat(prefix, "/");
				strcat(prefix, namelist1[i1]->d_name);
				cmpdir(buf1,buf2);
				prefix[len] = 0;
			} else {
				// stat files and compare
				struct stat sb1, sb2;
				ret = stat(buf1, &sb1);
				if(ret != 0)
					fprintf(stderr, "couldn't stat %s\n", buf1);
				ret = stat(buf2, &sb2);
				if(ret != 0)
					fprintf(stderr, "couldn't stat %s\n", buf2);
				if(sb1.st_size != sb2.st_size ||
						cmpfiles(buf1, buf2, sb1.st_size)) {
					 do_diff(namelist1[i1], namelist2[i2]);
				}
			}
			free(namelist1[i1]);
			free(namelist2[i2]);
			i1++, i2++;
		}
	}
	free(namelist1);
	free(namelist2);

	return 0;
}
예제 #29
0
void ObjectItem::slot_delete()
{
    if (m_project_builder.get_rendering_manager().is_rendering())
        schedule_delete();
    else do_delete();
}
예제 #30
0
int main(int argc, char *argv[])
{
	int rc;
	int opcount = 0;
	int insert_count = 0;
	int delete_count = 0;
	int ncount;
	int done = 0;
	char command[COMMAND + 1];
	int error;

	t = cp_multimap_create_by_option(COLLECTION_MODE_NOSYNC | 
								     COLLECTION_MODE_COPY |
					                 COLLECTION_MODE_DEEP, 
									 Employee_name, 
								     (cp_compare_fn) strcmp, 
									 (cp_copy_fn) Employee_dup, free);
	if (t == NULL)
	{
		perror("create");
		exit(1);
	}

	number_index = 
		cp_multimap_create_index(t, CP_UNIQUE, Employee_number, numcmp, &rc);
	if (number_index == NULL)
	{
		fprintf(stderr, "received error %d\n", rc);
		exit(rc);
	}

	title_index = 
		cp_multimap_create_index(t, CP_MULTIPLE, Employee_title, 
		                         (cp_compare_fn) strcmp, &rc);
	if (title_index == NULL)
	{
		fprintf(stderr, "received error %d\n", rc);
		exit(rc);
	}

	print_command_summary(argv[0]);
	while (!done)
	{
		error = 1;
		printf("> ");
		fgets(command, COMMAND, stdin);
		ltrim(command);
		chomp(command);
		if (strlen(command) == 0) continue;
		if (strcmp(command, "q") == 0 || strcmp(command, "Q") == 0) break;
		if (command[1] == 0x20 || command[1] == '\0')
		{
			error = 0;
			switch (tolower(command[0]))
			{
				case 'a': do_add(command); break;
				case 'd': do_delete(command); break;
				case 'e': do_edit(command); break;
				case 'h': print_command_summary(argv[0]); break;
				case 'k': do_key(command); break;
				case 'l': do_list(command); break;
				default: error = 1;
			}
		}
		if (error)
			printf("unrecognized command: [%s]. Enter 'h' for a list of commands or 'q' to quit.\n", command);
	}

	cp_multimap_destroy(t);
	return 0;
}