示例#1
0
int
main(int argc, char **argv)
{
    int ret;

    set_progname (argv[0]);

    create_and_write ("foo", "hej\n");

    ret = truncate ("foo", 0);
    if (ret < 0)
	err (1, "truncate(0)");

    check_size ("foo", 0);

    ret = unlink("foo");
    if (ret < 0)
	errx (1, "unlink");

    create_and_write ("bar", "hej\nhej\n");

    ret = truncate ("bar", 16);
    if (ret < 0)
	err (1, "truncate(16)");

    check_size ("bar", 16);

    ret = unlink("bar");
    if (ret < 0)
	errx (1, "unlink");

    return 0;
}
示例#2
0
文件: totextmode.c 项目: pexip/os-kbd
int
main(int argc, char *argv[]) {
	int fd, num;

	set_progname(argv[0]);
#ifndef __klibc__
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE_NAME, LOCALEDIR);
	textdomain(PACKAGE_NAME);
#endif

	if (argc == 2 && !strcmp(argv[1], "-V"))
		print_version_and_exit();

	if (argc != 2) {
		fprintf(stderr, _("usage: totextmode\n"));
		exit(1);
	}
	fd = getfd(NULL);
	num = atoi(argv[1]);
	if (ioctl(fd,KDSETMODE,KD_TEXT)) {
		perror("totextmode: KDSETMODE");
		exit(1);
	}
	exit(0);
}
示例#3
0
文件: setlogcons.c 项目: legionus/kbd
int main(int argc, char **argv)
{
	int fd, cons;
	struct {
		char fn, subarg;
	} arg;

	set_progname(argv[0]);

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE_NAME, LOCALEDIR);
	textdomain(PACKAGE_NAME);

	if (argc == 2)
		cons = atoi(argv[1]);
	else
		cons = 0; /* current console */

	if ((fd = getfd(NULL)) < 0)
		kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));

	arg.fn     = 11;   /* redirect kernel messages */
	arg.subarg = cons; /* to specified console */
	if (ioctl(fd, TIOCLINUX, &arg)) {
		kbd_error(EXIT_FAILURE, errno, "TIOCLINUX");
	}
	return EXIT_SUCCESS;
}
示例#4
0
文件: start_quip.c 项目: E-LLP/QuIP
void start_quip_with_menu(int argc, char **argv, Menu *initial_menu_p )
{
	Query_Stack *qsp;

    assert( initial_menu_p != NULL );
    
    set_progname(argv[0]);
	first_menu = initial_menu_p;

	//debug |= CTX_DEBUG_MASK;
	//debug |= GETBUF_DEBUG_MASK;

	qsp=init_first_query_stack();	// reads stdin?

	init_builtins();
	init_variables(SINGLE_QSP_ARG);	// specify dynamic variables
	declare_functions(SINGLE_QSP_ARG);

	//PUSH_MENU(quip);
	PUSH_MENU_PTR(initial_menu_p);

	set_args(QSP_ARG  argc,argv);
	rcfile(qsp,argv[0]);

	// If we have commands to create a widget in the startup file,
	// we get an error, so don't call exec_quip until after the appDelegate
	// has started...
	
} // end start_quip_with_menu
示例#5
0
int main(int argc, char *argv[])
{
	/* update progname from argv[0] */
	set_progname(argv[0]);

	const struct ap_Option options[] = {
		{'h', "help", ap_no, 0, 0},
		{'v', "version", ap_no, 0, 0},
		{0, 0, ap_no, 0, 0}
	};

	if (!ap_init(&parser, argc, (const char* const*) argv, options, 0))
		critx("could not allocate memory for option parser");
	if (ap_error(&parser)) {
		errx("%s", ap_error(&parser));
		usage(EXIT_FAILURE);
	}

	/* parse command line */
	for (int argind = 0; argind < ap_arguments(&parser); argind++) {
		const int code = ap_code(&parser, argind);

		switch (code) {
		case 0:
			break;
		case 'h':
			usage(EXIT_SUCCESS);
			break;
		case 'v':
			fprintf(stderr, "%s %s\n%s\n%s\n\n%s\n", progname,
				FLOWGRIND_VERSION, FLOWGRIND_COPYRIGHT,
				FLOWGRIND_COPYING, FLOWGRIND_AUTHORS);
			exit(EXIT_SUCCESS);
			break;
		default:
			errx("uncaught option: %s", ap_argument(&parser, argind));
			usage(EXIT_FAILURE);
			break;
		}
	}

	if (!ap_arguments(&parser)) {
		errx("no address given");
		usage(EXIT_FAILURE);
	}

	xmlrpc_env rpc_env;
	xmlrpc_env_init(&rpc_env);
	xmlrpc_client_setup_global_const(&rpc_env);

	for (int argind = 0; argind < ap_arguments(&parser); argind++)
		/* if non-option, it is an address */
		if (!ap_code(&parser, argind))
			stop_flows(ap_argument(&parser, argind));

	xmlrpc_env_clean(&rpc_env);
	xmlrpc_client_teardown_global_const();
	ap_free(&parser);
}
示例#6
0
int main(int argc, char **argv){

  char *optstr = "bClqtc:";
  char *usage = "nbspradinfo [-b] [-c <count> | -C] [-l] [-q] [-t] "
		"<file> | < file";
  int status = 0;
  int c;
  int opt_cC = 0;	/* c and C together is a conflict */

  set_progname(basename(argv[0]));

  while((status == 0) && ((c = getopt(argc, argv, optstr)) != -1)){
    switch(c){
    case 'b':
      g.opt_background = 1;
      break;
    case 'l':
      g.opt_lengthonly = 1;
      break;
    case 'q':
      g.opt_quiet_invalid_pdb = 1;
      break;
    case 't':
      g.opt_timeonly = 1;
      break;
    case 'C':
      ++opt_cC;
      g.opt_skipcount = CCB_SIZE;
      break;
    case 'c':
      ++opt_cC;
      status = strto_int(optarg, &g.opt_skipcount);
      if((status == 1) || (g.opt_skipcount <= 0)){
	log_errx(1, "Invalid argument to [-c] option.");
      }
      break;
    default:
      log_info(usage);
      exit(0);
      break;
    }
  }

  if(opt_cC > 1)
    log_errx(1, "Invalid combination of options: c and C.");

  if(g.opt_background == 1)
    set_usesyslog();

  if(optind < argc - 1)
    log_errx(1, "Too many arguments.");
  else if(optind == argc - 1)
    g.opt_inputfile = argv[optind++];

  atexit(cleanup);
  status = process_file();

  return(status != 0 ? 1 : 0);
}
示例#7
0
文件: deallocvt.c 项目: Bolel/kbd
int
main(int argc, char *argv[]) {
	int fd, num, i;

	if (argc < 1)		/* unlikely */
		exit(1);
	set_progname(argv[0]);

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE_NAME, LOCALEDIR);
	textdomain(PACKAGE_NAME);

	if (argc == 2 && !strcmp(argv[1], "-V"))
		print_version_and_exit();

	for (i = 1; i < argc; i++) {
		if (!isdigit(argv[i][0])) {
			fprintf(stderr, _("%s: unknown option\n"), progname);
			exit(1);
		}
	}

	fd = getfd(NULL);

	if (argc == 1) {
		/* deallocate all unused consoles */
		if (ioctl(fd,VT_DISALLOCATE,0)) {
			perror("VT_DISALLOCATE");
			fprintf(stderr,
				_("%s: deallocating all unused consoles failed\n"),
				progname);
			exit(1);
		}
	} else for (i = 1; i < argc; i++) {
		num = atoi(argv[i]);
		if (num == 0) {
			fprintf(stderr,
				_("%s: 0: illegal VT number\n"), progname);
			exit(1);
		} else if (num == 1) {
			fprintf(stderr,
				_("%s: VT 1 is the console and cannot be deallocated\n"),
				progname);
			exit(1);
		} else if (ioctl(fd,VT_DISALLOCATE,num)) {
			perror("VT_DISALLOCATE");
			fprintf(stderr,
				_("%s: could not deallocate console %d\n"),
				progname, num);
			exit(1);
		}
	}
	exit(0);
}
示例#8
0
文件: edfile.c 项目: bcherry/bcherry
int main( int argc, char **argv ){
   struct options options;
   list_ref list = NULL;
   bzero( &options, sizeof options );
   set_progname( argv[0] );
   progname = argv[0];
   scanoptions( &options, argc, argv );
   list = new_list();
   readFiles(list, &options);
   editfile( &options, list );
   free_list( list ); list = NULL;
   return get_exitcode();
}
示例#9
0
int
main(int argc, char **argv)
{
    const char *file = "blaha";

    set_progname (argv[0]);
    if (argc != 1 && argc != 2)
	errx (1, "usage: %s [file]", argv[0]);
    if (argc == 2)
	file = argv[1];
    doit (file);
    return 0;
}
示例#10
0
int
main(int argc, char **argv) {
	char *ep;
	int fd;
	struct kbkeycode a;

	set_progname(argv[0]);
#ifndef __klibc__
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE_NAME, LOCALEDIR);
	textdomain(PACKAGE_NAME);
#endif

	if (argc == 2 && !strcmp(argv[1], "-V"))
		print_version_and_exit();

	if (argc % 2 != 1)
		usage(_("even number of arguments expected"));
	fd = getfd(NULL);

	while (argc > 2) {
		a.keycode = atoi(argv[2]);
		a.scancode = strtol(argv[1], &ep, 16);
		if (*ep)
			usage(_("error reading scancode"));
		if (a.scancode >= 0xe000) {
			a.scancode -= 0xe000;
			a.scancode += 128;	/* some kernels needed +256 */
		}
#if 0
		/* Test is OK up to 2.5.31--later kernels have more keycodes */
		if (a.scancode > 255 || a.keycode > 127)
			usage(_("code outside bounds"));

		/* Both fields are unsigned int, so can be large;
		   for current kernels the correct test might be
		     (a.scancode > 255 || a.keycode > 239)
		   but we can leave testing to the kernel. */
#endif
		if (ioctl(fd,KDSETKEYCODE,&a)) {
			perror("KDSETKEYCODE");
			fprintf(stderr,
				_("failed to set scancode %x to keycode %d\n"),
				a.scancode, a.keycode);
			exit(1);
		}
		argc -= 2;
		argv += 2;
	}
	return 0;
}
示例#11
0
文件: mapscrn.c 项目: Mirppc/twin
int
main(int argc, char *argv[]) {
	int fd;

	set_progname(argv[0]);

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	if (argc == 2 && !strcmp(argv[1], "-V"))
	    print_version_and_exit();

	if (argc > 1 && !strcmp(argv[1], "-v")) {
		verbose = 1;
		argc--;
		argv++;
	}

	fd = getfd();

	if (argc >= 3 && !strcmp(argv[1], "-o")) {
	    saveoldmap(fd, argv[2]);
	    argc -= 2;
	    argv += 2;
	    if (argc == 1)
	      exit(0);
	}
		
	if (argc != 2) {
		fprintf(stderr, _("usage: %s [-v] [-o map.orig] map-file\n"),
			progname);
		exit(1);
	}

    	if (!TwOpen(NULL)) {
	    fprintf(stderr, _("mapscrn: libTw error: %s\n"), TwStrError(TwErrno));
	    exit(1);
	}
	loadnewmap(fd, argv[1]);

	if (TwErrno) {
	    fprintf(stderr, _("mapscrn: libTw error: %s\n"), TwStrError(TwErrno));
	}
	TwClose();
	
	exit(0);
}
示例#12
0
int
main(int argc, char **argv) {
	int c;
	const char *file;
	FILE *fd;

	set_progname(argv[0]);

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE_NAME, LOCALEDIR);
	textdomain(PACKAGE_NAME);

	while ((c = getopt(argc, argv, "hV")) != EOF) {
		switch (c) {
			case 'V':
				print_version_and_exit();
				break;
			case 'h':
				usage(EXIT_SUCCESS);
				break;
		}
	}

	if (optind == argc)
		usage(EXIT_FAILURE);

	file = argv[optind];

	if (!strcmp(file, "vga")) {
		set_colormap(vga_colors);
		return EXIT_SUCCESS;

	} else if (!strcmp(file, "-")) {
		parse_file(stdin, "stdin");

	} else {
		if ((fd = fopen(file, "r")) == NULL)
			error(EXIT_FAILURE, errno, "fopen");

		parse_file(fd, file);
		fclose(fd);
	}

	set_colormap(cmap);
	free(cmap);

	return EXIT_SUCCESS;
}
示例#13
0
int
main(int argc, char *argv[]) {
	int fd, c;
	char *console = NULL;
	char *outfnam = NULL;
	char *infnam = "def.uni";

	set_progname(argv[0]);

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE_NAME, LOCALEDIR);
	textdomain(PACKAGE_NAME);

	if (argc == 2 &&
	    (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")))
		print_version_and_exit();

	while ((c = getopt(argc, argv, "C:o:")) != EOF) {
		switch (c) {
		case 'C':
			console = optarg;
			break;
		case 'o':
		     	outfnam = optarg;
			break;
		default:
			usage();
		}
	}

	if (argc > optind+1 || (argc == optind && !outfnam))
		usage();

	fd = getfd(console);

	if (outfnam) {
		saveunicodemap(fd, outfnam);
		if (argc == optind)
			exit(0);
	}

	if (argc == optind+1)
		infnam = argv[optind];
	loadunicodemap(fd, infnam);
	exit(0);
}
示例#14
0
int main(int argc, char **argv)
{
	unsigned int ometa, nmeta;
	struct meta *mp;

	set_progname(argv[0]);

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE_NAME, LOCALEDIR);
	textdomain(PACKAGE_NAME);

	if (argc == 2 && !strcmp(argv[1], "-V"))
		print_version_and_exit();

	if (ioctl(0, KDGKBMETA, &ometa)) {
		kbd_error(EXIT_FAILURE, errno, _("Error reading current setting. Maybe stdin is not a VT?: "
		                                 "ioctl KDGKBMETA"));
	}

	if (argc <= 1) {
		report(ometa);
		exit(EXIT_SUCCESS);
	}

	nmeta = 0; /* make gcc happy */
	for (mp = metas; (unsigned)(mp - metas) < SIZE(metas); mp++) {
		if (!strcmp(argv[1], mp->name)) {
			nmeta = mp->val;
			goto fnd;
		}
	}
	fprintf(stderr, _("unrecognized argument: _%s_\n\n"), argv[1]);
	usage();

fnd:
	printf(_("old state:    "));
	report(ometa);
	if (ioctl(0, KDSKBMETA, nmeta)) {
		kbd_error(EXIT_FAILURE, errno, "ioctl KDSKBMETA");
	}
	printf(_("new state:    "));
	report(nmeta);

	return EXIT_SUCCESS;
}
示例#15
0
int
main(int argc __attribute__ ((unused)), char *argv[]) {
    int fd;

    set_progname(argv[0]);

    fd = open("/dev/tty0", 0);
    if (fd < 0 && errno == ENOENT)
      fd = open("/dev/vc/0", 0);
    if (fd < 0)
      fd = 0;
    signal(SIGHUP, sighup);
    if (ioctl(fd, KDSIGACCEPT, (long) SIGHUP))
	kbd_error(EXIT_FAILURE, errno, "ioctl KDSIGACCEPT");
    while(1)
      sleep(3600);
    return EXIT_SUCCESS;
}
示例#16
0
文件: die_warn.c 项目: cjgd/cgrabbag
int main(int argc, char *argv[]) 
{
	FILE *f; 
	int c; 

	set_progname(argv[0]); 
	if (argc != 2)
		die("usage: $0 file"); 
	if ((f = fopen(argv[1], "r")) == NULL)
		die("$0: %s: $!", argv[1]); 
	while ((c = getc(f)) != EOF) 
		putchar(c); 
	if (ferror(f))
		die("error on %s: $!", argv[1]); 
	if (fclose(f) != 0)
		warn("can't close %s: $!", argv[1]); 
	exit(0); 
	return 0; 
}
示例#17
0
int main(int argc, char **argv){

  int status = 0;
  int c;
  char *optstr = "behi:";
  char *usage = "nbspsatinfo [-b] [-e] [-h] [-i] file";

  set_progname(basename(argv[0]));

  while((status == 0) && ((c = getopt(argc, argv, optstr)) != -1)){
    switch(c){
    case 'b':
      g.opt_background = 1;
      break;
    case 'e':
      g.opt_extended_info = 1;
      break;
    case 'i':
      g.opt_inputfile = optarg;
      break;
    case 'h':
    default:
      log_info(usage);
      exit(0);
      break;
    }
  }

  if(g.opt_background == 1)
    set_usesyslog();

  if((g.opt_inputfile == NULL) && (optind == argc - 1))
      g.opt_inputfile = argv[optind++];

  if(optind < argc)
    log_errx(1, "Too many arguments.");

  status = write_file_info(g.opt_inputfile);

  return(status != 0 ? 1 : 0);
}
示例#18
0
文件: rcfile.c 项目: jbmulligan/quip
void rcfile( Query_Stack *qsp, char* progname )
{
	char *s=NULL;
	int status;

	// Should we make sure that the qsp has already been initialized?
	set_progname(progname); 	/* this is for get_progfile */

//#ifndef BUILD_FOR_OBJC
#ifdef BUILD_FOR_CMD_LINE
	// For unix, the user can put their own startup in:
	// current directory, $STARTUP_DIRNAME, $HOME, and QUIP_DEFAULT_DIR (/usr/local/share/quip/macros/startup/)
	strip_fullpath(&progname);	/* strip leading components */

	s=try_cwd(QSP_ARG  progname);
	if( s == NULL ) s=try_user_spec(QSP_ARG  progname);
	if( s == NULL ) s=try_home(QSP_ARG  progname);
	if( s == NULL ) s=try_default(QSP_ARG  progname);
//#endif /* ! BUILD_FOR_OBJC */
#endif /* BUILD_FOR_CMD_LINE */

	/* Because these functions push the input but do not execute,
	 * this one is interpreted first, because it is pushed last.
	 * It would be better to execute right away, so that settings
	 * such as verbose and QUIPSTARTUPDIR could be put there and
	 * used here, but, when this is executed, no menus have been pushed...
	 * We could push the builtin menu?
	 */
	status = read_global_startup(QSP_ARG  progname);

	if( status < 0 && s == NULL ){
		advise("No startup file found");
	} else if( verbose ){
		/* How would verbose ever be set here? Only by changing compilation default? */
		// We may not want to print this message if we are using the global startup?
		if( s != NULL ){
			sprintf(ERROR_STRING,"Interpreting startup file %s",s);
			advise(ERROR_STRING);
		}
	}
}
示例#19
0
int main(int argc, char *argv[])
{
	struct sigaction sa;

	xmlrpc_env env;

	if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
		crit("could not ignore SIGPIPE");

	sa.sa_handler = sighandler;
	sa.sa_flags = 0;
	sigemptyset (&sa.sa_mask);
	sigaction (SIGHUP, &sa, NULL);
	sigaction (SIGALRM, &sa, NULL);
	sigaction (SIGCHLD, &sa, NULL);

	set_progname(argv[0]);
	parse_cmdline(argc, argv);
	logging_init();
#ifdef HAVE_LIBPCAP
	fg_pcap_init();
#endif /* HAVE_LIBPCAP */
	if (log_type == LOGTYPE_SYSLOG) {
		/* Need to call daemon() before creating the thread because
		 * it internally calls fork() which does not copy threads. */
		if (daemon(0, 0) == -1)
			crit("daemon() failed");
		logging_log(LOG_NOTICE, "flowgrindd daemonized");
	}

	if (cpu >= 0)
		set_affinity(cpu);

	create_daemon_thread();

	xmlrpc_env_init(&env);

	run_rpc_server(&env, port);

	critx("control should never reach end of main()");
}
示例#20
0
文件: rcfile.c 项目: E-LLP/QuIP
void rcfile( Query_Stack *qsp, char* progname )
{
	char *s=NULL;
	int status;

	// Should we make sure that the qsp has already been initialized?
	set_progname(progname); 	/* this is for get_progfile */

#ifndef BUILD_FOR_OBJC
	strip_fullpath(&progname);	/* strip leading components */

	s=try_cwd(QSP_ARG  progname);
	if( s == NULL ) s=try_user_spec(QSP_ARG  progname);
	if( s == NULL ) s=try_home(QSP_ARG  progname);
	if( s == NULL ) s=try_default(QSP_ARG  progname);
#endif /* ! BUILD_FOR_OBJC */

	// We probably don't want to print this message if we are using the global startup...


	/* Because these functions push the input but do not execute,
	 * this one is interpreted first, because it is pushed last.
	 * It would be better to execute right away, so that settings
	 * such as verbose and QUIPSTARTUPDIR could be put there and
	 * used here, but when this is executed no menus have been pushed...
	 * We could push the builtin menu?
	 */
	status = read_global_startup(SINGLE_QSP_ARG);

	if( status < 0 && s == NULL ){
		advise("No startup file found");
	} else if( verbose ){
		/* How would verbose ever be set here? Only by changing compilation default? */
		if( status == 0 ) advise("Interpreting global startup file $HOME/.coqrc");
		if( s != NULL ){
			sprintf(ERROR_STRING,"Interpreting startup file %s",s);
			advise(ERROR_STRING);
		}
	}
}
示例#21
0
int
main(int argc, char **argv)
{
    int ret = 0;
    int optind = 0;

    set_progname (argv[0]);

    verbose_flag = getenv ("VERBOSE") != NULL;

    if (agetarg (args, argc, argv, &optind, AARG_GNUSTYLE))
	usage (1);

    argc -= optind;
    argv += optind;

    if (argc != 0)
	usage (1);
    if (help_flag)
	usage (0);

    verbose_fp = fdopen (4, "w");
    if (verbose_fp == NULL) {
	verbose_fp = fopen ("/dev/null", "w");
	if (verbose_fp == NULL)
	    err (1, "fopen");
    }

    ret += test_it (getcwd, "getcwd", 3);
#ifdef __NR_getcwd
    ret += test_it (getcwd_syscall, "getcwd_syscall", 3);
#endif
    ret += test_it (getcwd_classic, "getcwd_classic", 0);
#if linux
    ret += test_it (getcwd_proc, "getcwd_proc", 0);
#endif
    return ret;
}
示例#22
0
文件: nbsp2ldm.c 项目: noaaport/nbsp
int main(int argc, char **argv){
  
  char *optstr = "bc:d:f:ghmno:p:q:s:S:v";
  int status = 0;

  set_progname(basename(argv[0]));

  process_args(argc, argv, optstr, 1);

  if(optind < argc - 1)
    log_errx(1, "Too many arguments.");
  else if(optind == argc - 1) {
    if(g.opt_filesize != 0) {
      log_errx(1, "Option [-S] is not valid when a file argument is given.");
    }
    g.input_fname = argv[optind++];
  } else if((g.opt_filesize != 0) && (g.opt_prodid == NULL))
      log_errx(1, "Option [-p] is mandatory if [-S] is given.");
  else if((g.opt_filesize == 0) && (g.opt_prodid != NULL))
      log_errx(1, "Option [-p] requires [-S] or a file argument");

  if(g.opt_background == 1)
    set_usesyslog();

  if(atexit(cleanup) != 0)
    log_err(1, "atexit");

  init();

  if(g.input_fname != NULL)
    status = process_file();
  else if(g.opt_filesize != 0)
    status = process_file();
  else
    status = process_stdin();

  return(status != 0 ? 1 : 0);
}
示例#23
0
/**
 * main関数
 *
 * @param[in] argc 引数の数
 * @param[in] argv コマンド引数・オプション引数
 * @return ステータス
 */
int main(int argc, char *argv[])
{
    dbglog("start");

    set_progname(argv[0]);

    /* シグナルハンドラ設定 */
    set_sig_handler();

    /* オプション引数 */
    parse_args(argc, argv);

    /* バッファリングしない */
    if (setvbuf(stdin, (char *)NULL, _IONBF, 0))
        outlog("setvbuf: stdin");
    if (setvbuf(stdout, (char *)NULL, _IONBF, 0))
        outlog("setvbuf: stdout");

    /* スレッド生成 */
    create_threads();

    exit(EXIT_SUCCESS);
    return EXIT_SUCCESS;
}
示例#24
0
int main(int argc, char **argv)
{
    int i;
    info_t my_info;
    char *masterhost = NULL;
    iwarp_status_t ret;
    iwarp_rnic_handle_t rnic_hndl;
    iwarp_prot_id prot_id;
    iwarp_cq_handle_t cq_hndl;
    iwarp_qp_attrs_t qp_attrs;
    iwarp_qp_handle_t qp_id;
    iwarp_stag_index_t send_stag_index;
    iwarp_mem_desc_t send_mem_region;
    iwarp_stag_index_t recv_stag_index;
    iwarp_mem_desc_t recv_mem_region;
    iwarp_sge_t send_sge;  /*scatter gather entry*/
    iwarp_sgl_t send_sgl;  /*the scatter gather list*/
    iwarp_sge_t recv_sge;  /*scatter gather entry*/
    iwarp_sgl_t recv_sgl;  /*the scatter gather list*/
    iwarp_wr_t swr;
    iwarp_wr_t rwr;
    int send_count;
    uint64_t wall_start, wall_end, start, stop;
    double PINGPONG[MAX_ITER];
    time_t seconds;
    char unique[20];
    char iter_str[7];
    char size_str[14];
    char filename[43];
    FILE *outputFile;
    double ping_latency, ping_pong_latency, total_size, stddev;
    volatile char *bufend;
    iwarp_work_completion_t wc;
    char *remote_private_data;

    /********************************************************/
    /*Parse out the arguments passed in so we can set stuff up*/
    /********************************************************/
     set_progname(argc, argv);
     my_info.am_server = -1;
     while (++argv, --argc > 0) {
	    const char *cp;
	    if (**argv == '-') switch ((*argv)[1]) {
		    case 'n':
			    cp = *argv + 2;
			    for (i = 1; *cp && *cp == "numiter"[i]; ++cp, ++i)  ;
			    if (*cp) usage();
			    if (++argv, --argc == 0) usage();
			    iters = parse_number(*argv);

			    if(iters > MAX_ITER){
				    OUTPUT("\n\nWARNING %d ITERATIONS TOO MANY USING ONLY %d ITERATIONS\n\n",
					    iters,MAX_ITER);
				    iters = MAX_ITER;
			    }

			    break;
		    case 's':
			    cp = *argv + 2;
			    for (i = 1; *cp && *cp == "size"[i]; ++cp, ++i);
			    if (*cp) usage();
			    if (++argv, --argc == 0) usage();
			    bufsize = parse_number(*argv);

			    if(bufsize > BUF_MAX){
				    OUTPUT("\n\nWARNING BUFFER OF %d BYTES TOO LARGE USING MAX SIZE = %d BYTES\n\n",
					    bufsize,BUF_MAX);
				    bufsize = BUF_MAX;
			    }
			    break;
		    case 'r':
			    my_info.am_server = 1;
			    masterhost = NULL;
			    VERBOSE("I am the server. ");
			    break;
		    case 'c':
			    my_info.am_server = 0;
			    if (++argv, --argc == 0) usage();
			    masterhost = *argv;
			    VERBOSE("I am the client. ");
			    VERBOSE("The server/master host is %s\n",masterhost);
			    break;
		    case 'p':
			    if (++argv, --argc == 0) usage();
			    port = atoi(*argv);
			    break;
		    //~ case 'm':
			    //~ VERBOSE("Changing trans mode....");
			    //~ trans_mode =  atoi(argv[1]);
			    //~ if(trans_mode != 1 && trans_mode != 2){
				    //~ fprintf(stderr,"Unknonw test type\n");
				    //~ exit(1);
			    //~ }
			    //~ break;
	    }

    }

    /************************/
    /*Now set up our buffers*/
    /************************/
    my_info.send_buf = malloc(bufsize);
    my_info.recv_buf = malloc(bufsize);

    if(!my_info.send_buf || !my_info.recv_buf){
	iwarp_untagged_err("Error - unable to allocate memory", -1);
    }

    if (my_info.am_server == -1)
		usage();

    /*********************/
    /*Set up iWARP stuff*/
    /*********************/
    ret = iwarp_rnic_open (0, PAGE_MODE, NULL, &rnic_hndl); /*open rnic*/

    if(ret != IWARP_OK)
	iwarp_untagged_err("RNIC open failed", ret);
    ret = iwarp_pd_allocate(rnic_hndl, &prot_id); /*allocate pd*/

    if(ret != IWARP_OK)
	iwarp_untagged_err("PD allocate failed", ret);
    ret = iwarp_cq_create(rnic_hndl, NULL, MAX_CQ_DEPTH / 2, &cq_hndl); /*create the completion queue*/

    if(ret != IWARP_OK)
	iwarp_untagged_err("Create CQ failed", ret);

    qp_attrs.sq_cq = cq_hndl;
    qp_attrs.rq_cq = cq_hndl;
    qp_attrs.sq_depth = MAX_WRQ;
    qp_attrs.rq_depth = MAX_WRQ ;
    qp_attrs.rdma_r_enable = TRUE;
    qp_attrs.rdma_w_enable = TRUE;
    qp_attrs.bind_mem_window_enable = FALSE;
    qp_attrs.send_sgl_max = MAX_S_SGL;
    qp_attrs.rdma_w_sgl_max = MAX_RDMA_W_SGL;
    qp_attrs.recv_sgl_max = MAX_R_SGL;
    qp_attrs.ord = MAX_ORD;
    qp_attrs.ird = MAX_IRD;
    qp_attrs.prot_d_id = prot_id;
    qp_attrs.zero_stag_enable = FALSE;

    /* XXX: for speed, turn off mpa crc and markers */
    qp_attrs.disable_mpa_markers = TRUE;
    qp_attrs.disable_mpa_crc = TRUE;

    ret = iwarp_qp_create(rnic_hndl, &qp_attrs, &qp_id); /*create the QP*/
    if(ret != IWARP_OK)
	iwarp_untagged_err("QP Create failed", ret);

    /*Register memory*/
    ret = iwarp_nsmr_register(rnic_hndl, VA_ADDR_T, my_info.send_buf, bufsize, prot_id, 0, REMOTE_READ|REMOTE_WRITE, &send_stag_index, &send_mem_region);
    if(ret != IWARP_OK)
	iwarp_untagged_err("Unable to regsiter memory", ret);

    ret = iwarp_nsmr_register(rnic_hndl, VA_ADDR_T, my_info.recv_buf, bufsize, prot_id, 0, REMOTE_READ|REMOTE_WRITE, &recv_stag_index, &recv_mem_region);
    if(ret != IWARP_OK)
	iwarp_untagged_err("Unable to regsiter memory", ret);

    /*set up the sgl*/
    ret = iwarp_create_sgl(rnic_hndl, &send_sgl);
    if(ret != IWARP_OK)
	iwarp_untagged_err("Unable to create SGL", ret);

    /*set up sge*/
    send_sge.length = bufsize;
    recv_sge.length = bufsize;
    send_sge.stag = send_stag_index;
    recv_sge.stag = recv_stag_index;
    send_sge.to = (uint64_t)(unsigned long)my_info.send_buf;
    recv_sge.to = (uint64_t)(unsigned long)my_info.recv_buf;

    /*add the sge to the sgl*/
    iwarp_create_sgl(rnic_hndl, &send_sgl);
    ret = iwarp_register_sge(rnic_hndl, &send_sgl, &send_sge);
    if(ret != IWARP_OK)
	iwarp_untagged_err("Unable to add sge to sgl", ret);

    iwarp_create_sgl(rnic_hndl, &recv_sgl);
    ret = iwarp_register_sge(rnic_hndl, &recv_sgl, &recv_sge);
    if(ret != IWARP_OK)
	iwarp_untagged_err("Unable to add sge to sgl", ret);

    /*build two work requests one for send one for recv*/
    swr.wr_id = (uint64_t)(unsigned long)&swr;
    swr.sgl = &send_sgl;
    swr.wr_type = IWARP_WR_TYPE_SEND;
    swr.cq_type = UNSIGNALED;

    rwr.wr_id = (uint64_t)(unsigned long)&rwr;
    rwr.sgl = &recv_sgl;
    rwr.wr_type = IWARP_WR_TYPE_SEND;
    rwr.cq_type = SIGNALED;

    VERBOSE("\nAll iWARP data structures initialized, trying connection\n");

    remote_private_data = malloc(512);
    if(my_info.am_server == 1){
	/*server*/
	memset(my_info.send_buf, 'R', bufsize);
	memset(my_info.recv_buf, '\0', bufsize);

	OUTPUT("waiting on connection.....");



	ret = iwarp_qp_passive_connect(rnic_hndl, port, qp_id, "Passive Side Priv Data", remote_private_data, 512);
	if(ret == IWARP_OK){
	    OUTPUT("Connection Made\n");
	}
	else{
	    iwarp_untagged_err("Connection Failed",ret);
	}




    }
    else{
	/*client*/
	memset(my_info.send_buf, 'C', bufsize); /*init send buffer only 1 time*/
	memset(my_info.recv_buf, '\0', bufsize); /*init recv buff*/

	ret = iwarp_qp_post_rq(rnic_hndl, qp_id, &rwr);   /*pre post the recv*/
	if(ret != IWARP_OK)
	    iwarp_untagged_err("Unable to post work request", ret);





	OUTPUT("connecting to %s.....", masterhost);
	ret = iwarp_qp_active_connect(rnic_hndl, port, masterhost, 300000, 1, qp_id, "Active Side Priv Data",
					remote_private_data, 512);

	if(ret == IWARP_OK){
	    OUTPUT("Connection Made\n");
	}
	else{
	    iwarp_untagged_err("Connection Failed", ret);
	}




    }



    VERBOSE("Received Private Data: %s\n", remote_private_data);





    /*******************************************/
    /*READY FOR MAIN BENCHMARK CODE*/
    /*******************************************/
    send_count = 1;

    if(my_info.am_server == 0) { /*client*/

	bufend = &my_info.recv_buf[bufsize-1];
	OUTPUT("Running....");
	for(i=0; i<iters; i++){
	    /*Wait for PING to arrive*/

	    ret = iwarp_cq_poll(rnic_hndl, cq_hndl, IWARP_INFINITY, 0, &wc); /*just assume it read CQ ok, we'll check the buff below to verify*/
	    if(ret != IWARP_OK)
		iwarp_untagged_err("Could not poll CQ", -1);

	    if (*bufend != 'R')
		iwarp_untagged_err("Corrupted Data", -1);

	    VERBOSE("Received the PING!\n");


	    /*send the pong*/
	    memset(my_info.recv_buf, '\0', bufsize); /*reset our recv buffer*/

	    //~ printf("before postig r-wrq queue has %d entries\n", rnic_ptr->recv_q.size);

	    ret = iwarp_qp_post_rq(rnic_hndl, qp_id, &rwr);  /*pre-post a recv buffer*/
	    if(ret != IWARP_OK){
		iwarp_untagged_err("Unable to post work request to catch the next pong", ret);
	    }



	    ret = iwarp_qp_post_sq(rnic_hndl, qp_id, &swr);  /*post a send*/
	    if(ret != IWARP_OK)
		iwarp_untagged_err("Unable to post to SQ", ret);
	    send_count++;

	    VERBOSE("Send PONG\n");



	}//end for loop
    }
    else{  /*server*/

	bufend = &my_info.recv_buf[bufsize-1];
	rdtsc(wall_start);
	for(i=0; i<iters; i++){
	    /*Send Ping*/
	    rdtsc(start);
	    memset(my_info.recv_buf, '\0', bufsize); /*reset our recv buffer*/
	    ret = iwarp_qp_post_rq(rnic_hndl, qp_id, &rwr);  /*pre-post a recv buffer*/
	    if(ret != IWARP_OK)
		iwarp_untagged_err("Unable to post work request to catch the ping", ret);


	    ret = iwarp_qp_post_sq(rnic_hndl, qp_id, &swr); /*post a send*/
	    if(ret != IWARP_OK)
		iwarp_untagged_err("Unable to post to SQ", ret);



	    send_count++;


	    VERBOSE("Sent PING\n");



	    /*Now check for PONG to complete*/
	    ret = iwarp_cq_poll(rnic_hndl, cq_hndl, IWARP_INFINITY, 0, &wc); /*just assume it read CQ ok, we'll check the buff below to verify*/
	    if(ret != IWARP_OK)
		iwarp_untagged_err("Could not poll CQ", -1);

	    if (*bufend != 'C'){
		printf("the char we got is %c\n", *bufend);
		iwarp_untagged_err("Corrupted Data", -1);

	    }


		rdtsc(stop);

	    VERBOSE("Got PONG\n");

	    //~ PINGPONG[i] = (double)(stop - start ) / mhz;
	    PINGPONG[i] =elapsed_wall_time(start, stop, MICROSECONDS);
	    VERBOSE("Ping Pong %d = %f uS\n", i, PINGPONG[i]);

	    //~ exit(0);

	} //end for loop
	rdtsc(wall_end);


	OUTPUT("All data gathered and collected....\n");
	DETAILED_OUTPUT("Bufsize = %d, #Iterations = %d\n",bufsize, iters);

	DETAILED_OUTPUT("#\tRTT/2\t\tPING-PONG\tBANDWIDTH\n");

	/*create the output files name*/
	if (outputfile) {
	    seconds = time(NULL);
	    sprintf(unique, "%ld", seconds);
	    sprintf(iter_str, "%d",iters);
	    sprintf(size_str, "%d", bufsize);
	    strcpy(filename,"untaggedRTTtest.");
	    strcat(filename, unique);
	    strcat(filename,".i_");
	    strcat(filename, iter_str);
	    strcat(filename,".s_");
	    strcat(filename, size_str);
	    strcat(filename,".txt");

	    /*create the output file*/
	    outputFile=fopen(filename, "w+");
	    if(outputFile == NULL){
		    fprintf(stderr,"Unable to create output file\n");
		    exit(-1);
	    }
	}
	ping_latency = 0.0;
	ping_pong_latency = 0.0;
	stddev = 0.;
	total_size = 2 * bufsize; /*total bytes*/
	total_size = total_size / (1024 * 1024); /*total in Megabytes*/
	total_size = total_size * 8; /*now total in Megabits*/

	if (iters > 0) {
	    for(i=0; i<iters; i++){
		ping_pong_latency += PINGPONG[i] / 2.;

		DETAILED_OUTPUT("%d\t%f\t%f\t%f\n",
			i+1,
			PINGPONG[i] / 2,
			PINGPONG[i],
			total_size / (double)(PINGPONG[i] / 1000000 )
		);

		if (outputfile)
		    fprintf(outputFile,"~\t%d\t%f\t%f\t%f\n",
			    i+1,
			    PINGPONG[i] / 2,
			    PINGPONG[i],
			    total_size / (double)(PINGPONG[i] / 1000000 )
		    );
	    }

	    ping_pong_latency /= iters;

	    if (iters > 1) {
		for (i=0; i<iters; i++) {
		    double diff = PINGPONG[i]/2. - ping_pong_latency;
		    stddev += diff * diff;
		}
		stddev /= (double) (iters - 1);
		stddev = sqrt(stddev);
	    }
	}
	/* OUTPUT("------------------------------------------------------------------------------\n"); */
	/* OUTPUT("AVERAGES\n"); */
	/* OUTPUT("------------------------------------------------------------------------------\n"); */

	total_size = total_size * iters;

	OUTPUT("RTT/2= %11.6f uS +- %11.6f\n", ping_pong_latency, stddev);
	/* OUTPUT("RTT= %f uS\n",ping_pong_latency / iters); */
	/* OUTPUT("Bandwidth= %f Mbps\n\n", total_size / (double)(ping_pong_latency / 1000000 )); */

	if (outputfile) {
	    fprintf(outputFile,"RTT/2= %f\n",(ping_pong_latency / 2) / iters);
	    /* fprintf(outputFile,"RTT= %f\n",ping_pong_latency / iters); */
	    /* fprintf(outputFile,"Bandwidth= %f\n", total_size / (double)(ping_pong_latency / 1000000 )); */
	    fprintf(outputFile,"SIZE= %d\n", bufsize);
	    fprintf(outputFile,"ITERS= %d\n", iters);
	}


	/*need a call to close connection verb!*/

    }

    OUTPUT("Completed successfully, closing connection!\n");

    ret = iwarp_qp_disconnect(rnic_hndl, qp_id);
    if(ret != IWARP_OK)
	    fprintf(stderr,"FAILED to disconnect QP\n");

    ret = iwarp_rnic_close(rnic_hndl);
    if(ret != IWARP_OK)
	    fprintf(stderr,"FAILED to close RNIC\n");


    return 0;
 }
示例#25
0
文件: main.c 项目: CazYokoyama/wrfv3
int main (int argc, char **argv)
{
    int i, j, n;
    List *files = NULL;
    char *s, *srcfile;
    Dependency *dep;
    List *deplist = NULL;   /* Dependencies */
    List *modlist = NULL;   /* Defined modules */
    List *extradeps = NULL; /* "Extra" dependencies (given by the '-d' option */
    List *rules = NULL;  /* List of rules to be added to all dependency lines */
    List *fspecrules = NULL; /* FileSpecific rules */
    List *obj = NULL;
    List *macrolist = NULL;  /* -D MACRO */
    Module *mod;
    List *h1, *h2;

    set_progname(argv[0]);

    if (argc == 1)  {
        printf ("%s", helpstring);
        exit (EXIT_SUCCESS);
    }

    /* Set a few option defaults */
    options.warn_missing = false;
    options.modfile_fmt = (char *)MODFILE_FMT_DEFAULT;
    options.src_fmt = SUFFIX;
    options.create_obj = false;
    options.exe_name = NULL;
    options.link_rule = (char *)LINK_RULE_DEFAULT;
    options.coco = false;
    options.obj_dir_set = false;
    options.obj_dir = "";
    options.src_dep = true;
    options.ignore_mods = NULL;
    options.src_path = NULL;

    /* Parse command line arguments */
    for (i = 1; i < argc; i++) {
        if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
            printf ("%s", helpstring);
            exit (EXIT_SUCCESS);

        } else if (strcmp(argv[i], "-V") == 0 
               || strcmp(argv[i], "--version") == 0) {
            printf("%s\n", ver);
            printf("%s\n", license);
            exit (EXIT_SUCCESS);

        } else if (strcmp(argv[i], "-W") == 0 
                   || strcmp(argv[i], "-Wmissing") == 0) {
            options.warn_missing = true;

        } else if (strcmp(argv[i], "-Wconfused") == 0) {
            options.warn_confused = true;

        } else if (strncmp(argv[i], "-m", 2) == 0) {
            if (strlen(argv[i]) == 2) {
                if (i == argc-1)  fatal_error("Option '-m' needs argument");
                options.modfile_fmt = xstrdup(argv[++i]);
            } else
                options.modfile_fmt = xstrdup(&(argv[i][2]));

        } else if (strncmp (argv[i], "-u", 2) == 0) {
            if (strlen(argv[i]) == 2) {
                if (i == argc-1)  fatal_error("Option '-u' needs argument");
                s = xstrdup(argv[++i]);
            } else
                s = xstrdup(&(argv[i][2]));

            if (!list_find(options.ignore_mods, s, COMP_FUN(&strcasecmp)))
                options.ignore_mods = list_prepend(options.ignore_mods, s);

        } else if (strcmp(argv[i], "-fixed") == 0) {
            options.src_fmt = FIXED;

        } else if (strcmp(argv[i], "-free") == 0) {
            options.src_fmt = FREE;

        } else if (strncmp(argv[i], "-d", 2) == 0) {
            if (strlen(argv[i]) == 2) {
                if (i == argc-1)  fatal_error("Option '-d' needs argument");
                s = xstrdup(argv[++i]);
            } else
                s = xstrdup(&(argv[i][2]));

            if (!list_find(extradeps, s, COMP_FUN(&strcasecmp)))
                extradeps = list_prepend(extradeps, s);

        } else if (strncmp(argv[i], "-r", 2) == 0) {
            if (strlen(argv[i]) == 2) {
                if (i == argc-1)  fatal_error ("Option '-r' needs argument");
                s = xstrdup(argv[++i]);
            } else
                s = xstrdup(&(argv[i][2]));

            if (!list_find(rules, s, COMP_FUN(&strcasecmp)))
                rules = list_append(rules, s);
        
        } else if (strncmp(argv[i], "-R", 2) == 0) {
            Fsr *h;
            h = (Fsr *) xmalloc(sizeof(Fsr));
            if (strlen(argv[i]) == 2) {
                if (i == argc-1)  fatal_error("Option '-R' needs 2 arguments");
                h->file = xstrdup(argv[++i]);
            } else
                h->file = xstrdup(&(argv[i][2]));

            if (i == argc-1) fatal_error("Option '-R' needs 2 arguments");
            h->rule = xstrdup (argv[++i]);
            fspecrules = list_append(fspecrules, h);

        } else if (strncmp(argv[i], "-o", 2) == 0) {
            options.create_obj = true;
            if (strlen(argv[i]) == 2) {
                if (i == argc-1)  fatal_error("Option '-o' needs argument");
                options.exe_name = xstrdup(argv[++i]);
            } else
                options.exe_name = xstrdup(&(argv[i][2]));

        } else if (strncmp(argv[i], "-l", 2) == 0) {
            if (strlen(argv[i]) == 2) {
                if (i == argc-1)  fatal_error("Option '-l' needs argument");
                options.link_rule = xstrdup(argv[++i]);
            } else
                options.link_rule = xstrdup(&(argv[i][2]));

        } else if (strcmp(argv[i], "-coco") == 0) {
            options.coco = true;
            options.src_fmt = FREE;
                
        } else if (strncmp(argv[i], "-D", 2) == 0) {
            Macro *mac;
            char *eq;
            char *s;

            /* Copy the argument of -D (ignoring any '=definition') to a
             * 'Macro' and add it to 'macrolist'. */
            mac = macro_new ();
            if (strlen(argv[i]) == 2) {
                char *eq;
                char *s;

                if (i == argc-1)  fatal_error("Option '-D' needs argument");
                i++;

                eq = strchr(argv[i], '=');
                if (eq != NULL)
                    s = xstrndup(argv[i], eq - argv[i]);
                else
                    s = xstrdup(argv[i]);
                
                macro_setname(mac, s);
            } else {
                eq = strchr(&argv[i][2], '=');
                if (eq != NULL)
                    s = xstrndup(&argv[i][2], eq - argv[i] - 2);
                else
                    s = xstrdup(&argv[i][2]);
                
                macro_setname(mac, s);
            }
            if (!list_find(macrolist, mac, &macrocmp))
                macrolist = list_prepend(macrolist, mac);

        } else if (strncmp(argv[i], "-b", 2) == 0) {
            if (strlen(argv[i]) == 2) {
                if (i == argc - 1) fatal_error("Option '-b' needs argument");
                options.obj_dir = xstrdup(argv[++i]);
            } else
                if (argv[i][2] == '=') {
                    options.obj_dir = xstrdup(&(argv[i][3]));
                } else
                    options.obj_dir = xstrdup(&(argv[i][2]));

            n = strlen(options.obj_dir);
            if (n > 0 && options.obj_dir[n - 1] != '/') {
                options.obj_dir = xrealloc(options.obj_dir, n+2);
                strcat(options.obj_dir, "/");
            }

            options.obj_dir_set = true;

        } else if (strncmp(argv[i], "-I", 2) == 0) {
            int jp;

            if (strlen(argv[i]) == 2) {
                if (i == argc - 1) fatal_error("Option '-I' needs argument");
                s = xstrdup(argv[++i]);
            } else
                if (argv[i][2] == '=' ) {
                    s = xstrdup(&(argv[i][3]));
                } else
                    s = xstrdup(&(argv[i][2]));

            n = strlen(s);
            jp = 0;
            for(j = 0;j < n; j++){
               if (s[j] == ' ' || s[j]==':') {
                 options.src_path = list_append(options.src_path, 
                                                xstrndup(s+jp, j-jp));
                 jp = j + 1;
               } else if (j == n-1) {
                 options.src_path = list_append(options.src_path,xstrdup(s+jp));
               }
            }

        } else if (strcmp(argv[i], "-nosrc") == 0) {
            options.src_dep = false;

        /*
         * Add new options here
         */

        } else if (*argv[i] == '-') {
            fatal_error("Unknown Option '%s'", argv[i]);

        } else {
            /* Gee, we got a filename! */
            if (!list_find(files, argv[i], COMP_FUN(&strcasecmp)))
                files = list_prepend(files, argv[i]);
        }
    }

    /* Parse the files, creating target and dependency lists. */
    for (h1 = files; h1; h1 = h1->next) {
        char *tmp;

        dep = dependency_new();
        srcfile = (char *)h1->data;
        if (find_dep(srcfile, dep, &modlist, macrolist)) {
            dep->sourcefile = srcfile;

            tmp = replace_suffix(srcfile, ".o");
            if (!list_find(dep->targets, tmp, COMP_FUN(&strcasecmp)))
                dep->targets = list_prepend(dep->targets, tmp);
            else
                free(tmp);

            if (options.src_dep)
                dep->includes = list_prepend(dep->includes, srcfile);

            if (options.coco) {
                char *setfile;
                struct stat blah;

                setfile = replace_suffix(srcfile, ".set");
                if (stat(setfile, &blah) == 0) {
                    if (!list_find(dep->includes,setfile,COMP_FUN(&strcasecmp)))
                        dep->includes = list_append(dep->includes, setfile);
                } else if (stat("coco.set", &blah) == 0) {
                    free(setfile);
                    setfile = xstrdup("coco.set");
                    if (!list_find(dep->includes,setfile,COMP_FUN(&strcasecmp)))
                        dep->includes = list_append(dep->includes, setfile);
                } else
                    free(setfile);
            }

            deplist = list_prepend(deplist, dep);
        } else
            free(dep);

        if (options.create_obj)
            obj = list_prepend(obj, replace_suffix(srcfile, ".o"));
    }

    /* Print FOBJ macro and linking dependecy-line + rule. */
    if (options.create_obj) {
        printf("FOBJ=");
        for (h1 = obj; h1; h1 = h1->next)
            if (options.obj_dir_set)
                printf("%s ", set_path(h1->data, options.obj_dir));
            else
                printf("%s ", (char *)h1->data);
        printf("\n\n%s: $(FOBJ)\n\t%s\n\n", options.exe_name,options.link_rule);
    }

    /* Print the 'target: dependency' lists. */
    for (h1 = deplist; h1; h1 = h1->next) {
        bool byR = false;

        dep = (Dependency *)h1->data;

        /* If there are no dependencys, there is no need to output anything */
        if (list_length(dep->includes) + list_length(dep->modules) == 0)
            continue;

        /* Targets */
        for (h2 = dep->targets; h2; h2 = h2->next)  
            if (options.obj_dir_set)
                printf("%s ", set_path(h2->data, options.obj_dir));
            else
                printf("%s ", (char *)h2->data);

        printf(": ");;

        /* Includes */
        for (h2 = dep->includes; h2; h2 = h2->next)  
            printf("%s ", (char *)h2->data);

        /* Modules */
        for (h2 = dep->modules; h2; h2 = h2->next) {
            List *l;
            s = (char *)h2->data;

            if (!(l = list_find(modlist, s, &modstrcmp))) {
                /* Don't write *.mod-file to dependency list if its definition 
                 * isn't found. */
                if (options.warn_missing)  warning("Module '%s' not found", s);

            } else {
                mod = (Module *)l->data;
                if (strcasecmp(mod->sourcefile, dep->sourcefile) == 0) {
                    /* Dont' write *.mod-file to the dependency list if it 
                     * defined in the same file it is USEd from. */
                } else {
                    if (options.obj_dir_set)
                        printf("%s ", 
                               set_path(mod->modfile_name, options.obj_dir));
                    else
                        printf("%s ", mod->modfile_name);
                }
            }

        }

        /* Extra dependencies (given with the '-d' option */
        for (h2 = extradeps; h2; h2 = h2->next)  
            printf("%s ", (char *)h2->data);

        putchar('\n');

        /* Print -R rules (if there are any) */
        for (h2 = fspecrules; h2; h2 = h2->next) {
            Fsr *h = (Fsr *)h2->data;

            if (fsr_strcmp(dep->sourcefile, h) == 0) {
                char *tmp = expand_rule(h->rule, dep->sourcefile);
                printf("%s\n", tmp);
                free(tmp);
                byR = true;
            }
        }
            
        /* If the file wasn't given any rules by the -R option, print -r rules*/
        if (!byR) {
            for (h2 = rules; h2; h2 = h2->next) {
                char *tmp = expand_rule((char *)h2->data, dep->sourcefile);
                printf("%s\n", tmp);
                free(tmp);
            }
        }

    }

    exit(EXIT_SUCCESS);
}
示例#26
0
int main(int argc,char *argv[])
{
   int retval;
   unsigned long len;

   if (argc > 1)
   {
      mfprintf (stderr, "%s called with an argument.\n", argv[0]);      
      return EXIT_FAILURE;
   }

   /* test program name */
   retval = set_progname (argv[0]);
   if (retval != 0)
   {
      mfprintf (stderr, "Failed to init messenger: %s.\n", argv[0]);      
      return EXIT_FAILURE;      
   }

   retval = add_name_2_progname (argv[0]);
   if (retval != 0)
   {
      mfprintf (stderr, "Failed to add name to program name: %s.\n", argv[0]);
      return EXIT_FAILURE;      
   }

   len = mprintf ("%s\n", get_progname());
   if (len != ((strlen (argv[0]) * 2) + 2))
   {
      mfprintf (stderr, "Failed to get program name: %s.\n", argv[0]);
      return EXIT_FAILURE;      
   }

   len = get_progname_len();
   if (len != ((strlen (argv[0]) * 2) + 1))
   {
      mfprintf (stderr, "Failed to get program name length: %s.\n", argv[0]);
      return EXIT_FAILURE;      
   }

   if (THROW_ERROR_MSG ("%s is %d test. Don%ct worry!", "This", 1, '\'') < 0)
   {
      mfprintf (stderr, "Failed to print error message: %s\n", argv[0]);
      return EXIT_FAILURE;
   }

   set_error_msg_func (alt_msgr);
   THROW_ERROR_MSG ("Hello chap!");

   if (THROW_WARN_MSG ("Now testing %d %s.", 1, "Warning") < 0)
   {
      mfprintf (stderr, "Failed to print error message: %s\n", argv[0]);
      return EXIT_FAILURE;
   }


   set_warn_msg_func (alt_msgr);
   THROW_WARN_MSG ("Hello bloke!");

   free_progname();

   FREE_MEMORY_MANAGER;

   return EXIT_SUCCESS;
}
示例#27
0
文件: corb.c 项目: marcom/corb
int main(int argc,char *argv[])
{
   Str* tool = NULL;
   struct gengetopt_args_info crb_args;
   int retval = 0;

   if (set_progname ("corb"))
   {
      return EXIT_FAILURE;
   }

   crb_cmdline_parser_init (&crb_args);
   retval = crb_cmdline_parser (argc, argv, &crb_args);
   
   if (retval == 0)
   {
      retval = crb_cmdline_parser_required(&crb_args, get_progname());
   }   

   /* post-process parsed options */
   if (crb_args.inputs_num != 1)
   {
      THROW_ERROR_MSG ("Exactly one application string is needed, try "
                       "`%s --help` for more information.",
                       get_progname());
      retval = 1;
   }

   /* parse toolname from command string */
   if (retval == 0)
   {
      tool = parse_toolname (crb_args.inputs[0]);
      if (tool == NULL)
      {
         THROW_ERROR_MSG ("No application name found in string provided: "
                          "\"%s\", try %s --help` for more information.",
                          crb_args.inputs[0], get_progname());
         retval = 1;
      }
   }

   /* inspect tool chosen */
   if (retval == 0)
   {
      retval = verify_tool (tool);
   }

   if (retval == 0)
   {
      retval = add_name_2_progname (str_get (tool));
   }

   /* start tool */
   if (retval == 0)
   {
      if (str_compare_cstr (tool, "brot") == 0)
      {
         retval = brot_main(crb_args.inputs[0]/*  + str_length (tool) */);
      }
      else if (str_compare_cstr (tool, "fold") == 0)
      {
         retval = fold_main(crb_args.inputs[0]);
      }
      else if (str_compare_cstr (tool, "er2de") == 0)
      {
         retval = er2de_main(crb_args.inputs[0]);
      }      
   }

   /* finalise */
   crb_cmdline_parser_free (&crb_args);
   str_delete (tool);
   free_progname();
   FREE_MEMORY_MANAGER;

   if (retval == 0)
   {
      return EXIT_SUCCESS;
   }
   else
   {
      return EXIT_FAILURE;
   }
}
示例#28
0
int main(int argc, char **argv)
{
	int c, n, cols, rows, nr, i, j, k;
	int mode;
	const char *space, *sep;
	char *console = NULL;
	int list[64], lth, info = 0, verbose = 0;

	set_progname(argv[0]);

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE_NAME, LOCALEDIR);
	textdomain(PACKAGE_NAME);

	if (argc == 2 &&
	    (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")))
		print_version_and_exit();

	while ((c = getopt(argc, argv, "ivC:")) != EOF) {
		switch (c) {
			case 'i':
				info = 1;
				break;
			case 'v':
				verbose = 1;
				break;
			case 'C':
				console = optarg;
				break;
			default:
				usage();
		}
	}

	if (optind != argc)
		usage();

	if ((fd = getfd(console)) < 0)
		kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));

	if (ioctl(fd, KDGKBMODE, &mode)) {
		kbd_warning(errno, "ioctl KDGKBMODE");
		leave(EXIT_FAILURE);
	}
	if (mode == K_UNICODE)
		space = "\xef\x80\xa0"; /* U+F020 (direct-to-font space) */
	else
		space = " ";

	if (info) {
		nr = rows = cols = 0;
		n                = getfont(fd, NULL, &nr, &rows, &cols);
		if (n != 0)
			leave(EXIT_FAILURE);

		if (verbose) {
			printf(_("Character count: %d\n"), nr);
			printf(_("Font width     : %d\n"), rows);
			printf(_("Font height    : %d\n"), cols);
		} else
			printf("%dx%dx%d\n", rows, cols, nr);
		leave(EXIT_SUCCESS);
	}

	settrivialscreenmap();
	getoldunicodemap();

	n = getfontsize(fd);
	if (verbose)
		printf(_("Showing %d-char font\n\n"), n);
	cols = ((n > 256) ? 32 : 16);
	nr   = 64 / cols;
	rows = (n + cols - 1) / cols;
	sep  = ((cols == 16) ? "%1$s%1$s" : "%1$s");

	for (i = 0; i < rows; i++) {
		if (i % nr == 0) {
			lth = 0;
			for (k = i; k < i + nr; k++)
				for (j              = 0; j < cols; j++)
					list[lth++] = k + j * rows;
			setnewunicodemap(list, lth);
		}
		printf("%1$s%1$s%1$s%1$s", space);
		for (j = 0; j < cols && i + j * rows < n; j++) {
			putchar(BASE + (i % nr) * cols + j);
			printf(sep, space);
			if (j % 8 == 7)
				printf(sep, space);
		}
		putchar('\n');
		if (i % 8 == 7)
			putchar('\n');
		fflush(stdout);
	}

	leave(EXIT_SUCCESS);
	return EXIT_SUCCESS;
}
示例#29
0
int
main (int argc, char **argv) {
  int verbose = 1;
  int c;

  set_progname (argv[0]);

  while ((c = getopt_long (argc, argv, shortopts, longopts, NULL)) >= 0)
    switch (c) {
    case 'q':
      verbose = 0;
      break;

    case 0:
      /* This indicates an automatically handled long option: do nothing.  */
      break;

    default:
      nerrors++;
      show_help = 1;
      break;
      }

  if (show_version || show_help) {
    if (show_version)
      print_version ("trapfilt", "Jg");

    if (show_help)
      printf ("Usage: %s [-q | --quiet | --silent] [vector...]\n", progname);
    }
  else {
    load_trapnumbers ();

    if (optind == argc) {
      char line[2048];

      while (fgets (line, sizeof line, stdin)) {
	unsigned int hex, oct;
	const char *name;
	char *nl = strchr (line, '\n');
	if (nl)  *nl = '\0';
	if (sscanf (line, "%*x:%x%o", &hex, &oct) == 2 && hex == oct
	    && (name = lookup (hex)) != NULL)
	  printf ("%s <%s>\n", line, name);
	else
	  puts (line);
	}
      }
    else
      for (; optind < argc; optind++) {
	/* If it's unparsable, strtoul returns 0, which will not be found.  */
	const char *name = lookup (strtoul (argv[optind], NULL, 0));
	if (verbose) {
	  printf ("%s", argv[optind]);
	  if (name)  printf (" <%s>", name);
	  printf ("\n");
	  }
	else {
	  if (name)
	    printf ("%s\n", name);
	  else
	    error ("no trap name found for '%s'", argv[optind]);
	  }
	}

    free_trapnumbers ();
    }

  return (nerrors == 0)? EXIT_SUCCESS : EXIT_FAILURE;
  }
示例#30
0
文件: psfxtable.c 项目: legionus/kbd
int main(int argc, char **argv)
{
	const char *ifname, *ofname, *itname, *otname;
	FILE *ifil, *ofil, *itab, *otab;
	int psftype, charsize, fontlen, hastable, notable;
	int i;
	int width = 8, bytewidth, height;
	char *inbuf, *fontbuf;
	int inbuflth, fontbuflth;

	set_progname(argv[0]);

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE_NAME, LOCALEDIR);
	textdomain(PACKAGE_NAME);

	if (argc == 2 && !strcmp(argv[1], "-V"))
		print_version_and_exit();

	ifil = ofil = itab = otab = NULL;
	ifname = ofname = itname = otname = NULL;
	fontbuf                           = NULL;
	notable                           = 0;

	if (!strcmp(get_progname(), "psfaddtable")) {
		/* Do not send binary data to stdout without explicit "-" */
		if (argc != 4) {
			char *u = _("Usage:\n\t%s infont intable outfont\n");
			fprintf(stderr, u, get_progname());
			exit(EX_USAGE);
		}
		ifname = argv[1];
		itname = argv[2];
		ofname = argv[3];
	} else if (!strcmp(get_progname(), "psfgettable")) {
		if (argc < 2 || argc > 3) {
			char *u = _("Usage:\n\t%s infont [outtable]\n");
			fprintf(stderr, u, get_progname());
			exit(EX_USAGE);
		}
		ifname = argv[1];
		otname = (argc == 3) ? argv[2] : "-";
	} else if (!strcmp(get_progname(), "psfstriptable")) {
		/* Do not send binary data to stdout without explicit "-" */
		if (argc != 3) {
			char *u = _("Usage:\n\t%s infont outfont\n");
			fprintf(stderr, u, get_progname());
			exit(EX_USAGE);
		}
		ifname  = argv[1];
		ofname  = argv[2];
		notable = 1;
	} else {
		for (i = 1; i < argc; i++) {
			if ((!strcmp(argv[i], "-i") || !strcmp(argv[i], "-if")) && i < argc - 1)
				ifname = argv[++i];
			else if ((!strcmp(argv[i], "-o") || !strcmp(argv[i], "-of")) && i < argc - 1)
				ofname = argv[++i];
			else if (!strcmp(argv[i], "-it") && i < argc - 1)
				itname = argv[++i];
			else if (!strcmp(argv[i], "-ot") && i < argc - 1)
				otname = argv[++i];
			else if (!strcmp(argv[i], "-nt"))
				notable = 1;
			else
				break;
		}
		if (i < argc || argc <= 1) {
			char *u = _("Usage:\n\t%s [-i infont] [-o outfont] "
			            "[-it intable] [-ot outtable] [-nt]\n");
			fprintf(stderr, u, get_progname());
			exit(EX_USAGE);
		}
	}

	if (!ifname)
		ifname = "-";
	if (!strcmp(ifname, "-"))
		ifil = stdin;
	else {
		ifil = fopen(ifname, "r");
		if (!ifil) {
			perror(ifname);
			exit(EX_NOINPUT);
		}
	}

	if (!itname)
		/* nothing */;
	else if (!strcmp(itname, "-"))
		itab = stdin;
	else {
		itab = fopen(itname, "r");
		if (!itab) {
			perror(itname);
			exit(EX_NOINPUT);
		}
	}

	/* Refuse ifil == itab == stdin ? Perhaps not. */

	if (!ofname)
		/* nothing */;
	else if (!strcmp(ofname, "-"))
		ofil = stdout;
	else {
		ofil = fopen(ofname, "w");
		if (!ofil) {
			perror(ofname);
			exit(EX_CANTCREAT);
		}
	}

	if (!otname)
		/* nothing */;
	else if (!strcmp(otname, "-"))
		otab = stdout;
	else {
		otab = fopen(otname, "w");
		if (!otab) {
			perror(otname);
			exit(EX_CANTCREAT);
		}
	}

	if (readpsffont(ifil, &inbuf, &inbuflth, &fontbuf, &fontbuflth,
	                &width, &fontlen, 0,
	                itab ? NULL : &uclistheads) == -1) {
		char *u = _("%s: Bad magic number on %s\n");
		fprintf(stderr, u, get_progname(), ifname);
		exit(EX_DATAERR);
	}
	fclose(ifil);

	charsize  = fontbuflth / fontlen;
	bytewidth = (width + 7) / 8;
	if (!bytewidth)
		bytewidth = 1;
	height            = charsize / bytewidth;

	hastable = (uclistheads != NULL);

	if (PSF1_MAGIC_OK((unsigned char *)inbuf)) {
		psftype = 1;
	} else if (PSF2_MAGIC_OK((unsigned char *)inbuf)) {
		psftype = 2;
	} else {
		char *u = _("%s: psf file with unknown magic\n");
		fprintf(stderr, u, get_progname());
		exit(EX_DATAERR);
	}

	if (itab) {
		read_itable(itab, fontlen, &uclistheads);
		fclose(itab);
	}

	if (otab) {
		struct unicode_list *ul;
		struct unicode_seq *us;
		const char *sep;

		if (!hastable) {
			char *u = _("%s: input font does not have an index\n");
			fprintf(stderr, u, get_progname());
			exit(EX_DATAERR);
		}
		fprintf(otab,
		        "#\n# Character table extracted from font %s\n#\n",
		        ifname);
		for (i = 0; i < fontlen; i++) {
			fprintf(otab, "0x%03x\t", i);
			sep = "";
			ul  = uclistheads[i].next;
			while (ul) {
				us = ul->seq;
				while (us) {
					fprintf(otab, "%sU+%04x", sep, us->uc);
					us  = us->next;
					sep = ", ";
				}
				ul  = ul->next;
				sep = " ";
			}
			fprintf(otab, "\n");
		}
		fclose(otab);
	}

	if (ofil) {
		writepsffont(ofil, fontbuf, width, height, fontlen, psftype,
		             notable ? NULL : uclistheads);
		fclose(ofil);
	}

	return EX_OK;
}