示例#1
0
文件: rabin2.c 项目: KarjamP/radare2
static void __sdb_prompt(Sdb *sdb) {
	char *line;
	for (;(line = stdin_gets ());) {
		sdb_query (sdb, line);
		free (line);
	}
}
示例#2
0
文件: main.c 项目: codepongo/radare2
int main(int argc, const char **argv) {
	char *line;
	int i;

	if (argc<2) showusage (1);
	if (!strcmp (argv[1], "-d")) {
		if (argc == 4)
			return dbdiff (argv[2], argv[3]);
		showusage(0);
	} else
	if (!strcmp (argv[1], "-v")) showversion ();
	if (!strcmp (argv[1], "-h")) showusage (0);
	if (!strcmp (argv[1], "-j")) {
		if (argc>2)
			return sdb_dump (argv[2], 1);
		printf ("Missing database filename after -j\n");
		return 1;
	}
	if (!strcmp (argv[1], "-")) {
		argv[1] = "";
		if (argc == 2) {
			argv[2] = "-";
			argc++;
		}
	}
	if (argc == 2)
		return sdb_dump (argv[1], 0);
#if USE_MMAN
	signal (SIGINT, terminate);
	signal (SIGHUP, syncronize);
#endif
	if (!strcmp (argv[2], "="))
		return createdb (argv[1]);
	else if (!strcmp (argv[2], "-")) {
		if ((s = sdb_new (NULL, argv[1], 0))) {
			sdb_config (s, SDB_OPTION_FS | SDB_OPTION_NOSTAMP);
			for (;(line = stdin_gets ());) {
				save = sdb_query (s, line);
				free (line);
			}
		}
	} else {
		s = sdb_new (NULL, argv[1], 0);
		if (!s) return 1;
		sdb_config (s, SDB_OPTION_FS | SDB_OPTION_NOSTAMP);
		for (i=2; i<argc; i++)
			save = sdb_query (s, argv[i]);
	}
	terminate (0);
	return 0;
}
示例#3
0
文件: main.c 项目: djpohly/radare2
static int createdb(const char *f) {
	char *line, *eq;
	s = sdb_new (NULL, f, 0);
	if (!s || !sdb_create (s)) {
		fprintf (stderr, "Cannot create database\n");
		return 1;
	}
	for (;(line = stdin_gets ());) {
		if ((eq = strchr (line, '='))) {
			*eq = 0;
			sdb_append (s, line, eq+1);
		}
		free (line);
	}
	sdb_finish (s);
	return 0;
}
示例#4
0
文件: main.c 项目: codepongo/radare2
static int createdb(const char *f) {
	char *line, *eq;
	s = sdb_new (NULL, f, 0);
	if (!s || !sdb_disk_create (s)) {
		fprintf (stderr, "Cannot create database\n");
		return 1;
	}
	sdb_config (s, SDB_OPTION_FS | SDB_OPTION_NOSTAMP);
	for (;(line = stdin_gets ());) {
		if ((eq = strchr (line, '='))) {
			*eq = 0;
			sdb_disk_insert (s, line, eq+1);
		}
		free (line);
	}
	sdb_disk_finish (s);
	return 0;
}
示例#5
0
文件: main.c 项目: djpohly/radare2
int main(int argc, const char **argv) {
	char *line;
	int i;

	if (argc<2) showusage (1);
	if (!strcmp (argv[1], "-v")) showversion ();
	if (!strcmp (argv[1], "-h")) showusage (0);
	if (!strcmp (argv[1], "-")) {
		argv[1] = "";
		if (argc == 2) {
			argv[2] = "-";
			argc++;
		}
	}
	if (argc == 2)
		return sdb_dump (argv[1], 0);
#if USE_MMAN
	signal (SIGINT, terminate);
	signal (SIGHUP, syncronize);
#endif
	if (!strcmp (argv[2], "[]")) {
		return sdb_dump (argv[1], 1);
	} if (!strcmp (argv[2], "="))
		return createdb (argv[1]);
	else if (!strcmp (argv[2], "-")) {
		if ((s = sdb_new (NULL, argv[1], 0))) {
			for (;(line = stdin_gets ());) {
				save = sdb_query (s, line);
				free (line);
			}
		}
	} else {
		s = sdb_new (NULL, argv[1], 0);
		if (!s) return 1;
		for (i=2; i<argc; i++)
			save = sdb_query (s, argv[i]);
	}
	terminate (0);
	return 0;
}
示例#6
0
int main(int argc, const char **argv) {
	char *line;
	int i, ret, fmt = MODE_DFLT;
	int db0 = 1, argi = 1;
	int interactive = 0;

	/* terminate flags */
	if (argc<2) showusage (1);
	if (!strcmp (argv[1], "-d")) {
		if (argc == 4)
			return dbdiff (argv[2], argv[3]);
		showusage (0);
	}
	if (!strcmp (argv[1], "-v")) showversion ();
	if (!strcmp (argv[1], "-h")) showusage (2);
	if (!strcmp (argv[1], "-j")) {
		if (argc>2)
			return sdb_dump (argv[db0+1], MODE_JSON);
		eprintf ("Missing database filename after -j\n");
		return 1;
	}

	/* flags */
	if (!strcmp (argv[argi], "-0")) {
		fmt = MODE_ZERO;
		db0++;
		argi++;
	}
	if (!strcmp (argv[argi], "-")) {
		/* no database */
		argv[argi] = "";
		if (argc == db0+1) {
			interactive = 1;
			/* if no argument passed */
			argv[argi] = "-";
			argc++;
			argi++;
		}
	}
	if (argc-1 == db0)
		return sdb_dump (argv[db0], fmt);
#if USE_MMAN
	signal (SIGINT, terminate);
	signal (SIGHUP, syncronize);
#endif
	ret = 0;
	if (interactive || !strcmp (argv[db0+1], "-")) {
		if ((s = sdb_new (NULL, argv[db0], 0))) {
			save |= insertkeys (s, argv+3, argc-3, '-');
			sdb_config (s, SDB_OPTION_FS | SDB_OPTION_NOSTAMP);
			for (;(line = stdin_gets ());) {
				save |= sdb_query (s, line);
				if (fmt) {
					fflush (stdout);
					write (1, "", 1);
				}
				free (line);
			}
		}
	} else if (!strcmp (argv[db0+1], "=")) {
		ret = createdb (argv[db0], argv+db0+2, argc-(db0+2));
	} else {
		s = sdb_new (NULL, argv[db0], 0);
		if (!s) return 1;
		sdb_config (s, SDB_OPTION_FS | SDB_OPTION_NOSTAMP);
		for (i=db0+1; i<argc; i++) {
			save |= sdb_query (s, argv[i]);
			if (fmt) {
				fflush (stdout);
				write (1, "", 1);
			}
		}
	}
	terminate (0);
	return ret;
}