Beispiel #1
0
int main(int argc, char *argv[])
{
	int i;
	int j;
	int opt;
	int sockfd;
	struct addrinfo hints;
	struct addrinfo *res;
	struct timespec stp;
	struct timespec etp;

	while ((opt = getopt(argc, argv, "s:p:n:i:h?")) != -1) {
		switch (opt) {
		case 's':
			server = optarg;
			break;
		case 'p':
			server_port = optarg;
			break;
		case 'n':
			nr_pkts = atoi(optarg);
			break;
		case 'i':
			nr_iter = atoi(optarg);
			break;
		default:
			disp_usage();
		}
	}
	if (optind < 9)
		disp_usage();

	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_DGRAM;
	getaddrinfo(SERVER, SERVER_PORT, &hints, &res);

	sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);

	clock_gettime(CLOCK_MONOTONIC, &stp);
	for (j = 0; j < NR_ITER; j++) {
		srandom(getpid() + j);
		for (i = 0; i < NR_PKTS; i++) {
			int n = random() % 4;
			nr_bytes += sendto(sockfd, msgs[n], strlen(msgs[n]), 0,
					res->ai_addr, res->ai_addrlen);
			nsleep(NS_USEC * 30);
		}
	}
	clock_gettime(CLOCK_MONOTONIC, &etp);

	printf("Sent %d packets containing %lu bytes in %ums\n",
			NR_PKTS * NR_ITER, nr_bytes,
			(unsigned int)((etp.tv_sec * 1000 + etp.tv_nsec /
					NS_MSEC) -
				(stp.tv_sec * 1000 + stp.tv_nsec / NS_MSEC)));
	freeaddrinfo(res);

	exit(EXIT_SUCCESS);
}
Beispiel #2
0
main(int argc, char *argv[])
{

	int istat, narg, nchar;
	char process[MAXLINE];


	// set program name

	strcpy(prog_name, PNAME);


	// check command line for correct usage

	fprintf(stdout, "\n%s Arguments: ", prog_name);
	for (narg = 0; narg < argc; narg++)
		fprintf(stdout, "<%s> ", argv[narg]);
	fprintf(stdout, "\n");

	if (argc > 1)
		sscanf(argv[1], "%s", process);
	else
		strcpy(process, "");
	nchar = 0;
	while ( nchar < MAXLINE && (process[nchar] = toupper(process[nchar])) )
		nchar++;

	if (strcmp(process, "90CW") == 0) {
		if (argc < 4) {
			puterr("ERROR wrong number of command line arguments.");
			disp_usage(PNAME, "90CW <input_gridfile> <output_gridfile>");
			exit(-1);
		}
		if ((istat = Rotate90CW(argc, argv)) < 0) {
			puterr("ERROR doing Rotate 90CW process.");
			exit(-1);
		}
	} else {
		sprintf(MsgStr,
			"ERROR unrcognized process - <%s>.", process);
		puterr(MsgStr);
		disp_usage(PNAME, "90CW/... <arguments>");
		exit(-1);
	}


	exit(0);

}
Beispiel #3
0
static void
usage(char *name)
{
	MSG("Usage: %s [OPTION]...", name);
	MSG("Simple page-flip test, similar to 'modetest' but with option to use tiled buffers.");
	MSG("");
	disp_usage();
}
Beispiel #4
0
static void
usage(char *name)
{
	MSG("Usage: %s [OPTION]...", name);
	MSG("Test of buffer passing between v4l2 camera and display.");
	MSG("");
	MSG("viddec3test options:");
	MSG("\t-h, --help: Print this help and exit.");
	MSG("\t--multi <num>: Capture from <num> different devices.");
	MSG("\t\t\tEach device name and format would be parsed in the cmdline");
	MSG("");
	disp_usage();
	v4l2_usage();
}
Beispiel #5
0
int main(int argc, char** argv)
{

	int narg;
	int nPhases;


	/* set program name */

	strcpy(prog_name, PNAME);


	/* check command line for correct usage */

	fprintf(stdout, "%s Arguments: ", prog_name);
	for (narg = 0; narg < argc; narg++)
		fprintf(stdout, "<%s> ", argv[narg]);
	fprintf(stdout, "\n");

	if (argc < 5) {
		puterr("ERROR wrong number of command line arguments.");
		disp_usage(PNAME,
"<nll_hyp_target> <nll_hyp_phs_source> <nll_hyp_out> dist_max_fract");
		exit(0);
	}

	SetConstants();
	message_flag = 1;
	DispProgInfo();
	message_flag = 0;

	if ((nPhases = doFindEquivPhases(argc, argv)) < 0) {
		puterr("ERROR doing Phase Equivalence process.");
		exit(0);
	}



	exit(nPhases);

}
Beispiel #6
0
int main(int argc, char** argv)
{

	int istat, narg;


	/* set program name */

	strcpy(prog_name, PNAME);


	/* check command line for correct usage */

	fprintf(stdout, "%s Arguments: ", prog_name);
	for (narg = 0; narg < argc; narg++)
		fprintf(stdout, "<%s> ", argv[narg]);
	fprintf(stdout, "\n");

	if (argc < 5) {
		puterr("ERROR wrong number of command line arguments.");
		disp_usage(PNAME,
"hypfile1 hypfile2 time_tolerance nobs_tolerance");
		exit(-1);
	}

	SetConstants();
	message_flag = 1;
	DispProgInfo();
	message_flag = 0;

	if ((istat = DiffHypocenters(argc, argv)) < 0) {
		puterr("ERROR doing difference process.");
		exit(-1);
	}



	exit(0);

}
Beispiel #7
0
int main( int argc, char *argv[] )
/********************************/
{
    char    fname[ PATH_MAX ];
    FILE    *fi;
    FILE    *fo;
    char    *p;
    int     i;
    char    *line;
    char    *buff1;
    char    *buff2;
    char    *separators = " \t";
    
    i = process_cmdl( argc, argv );
    if( i == 0 ) {
        disp_usage();
        return( -1 );
    }
    strcpy( fname, argv[ i ] );
    if( strrchr( fname, '.' ) == NULL )
        strcat( fname, ".dlg" );
    fi = fopen( fname, "r" );
    if( fi == NULL ) {
        printf( "Could not open input file: %s\n", fname );
        return( -1 );
    }
    if( i + 1 < argc ) {
        strcpy( fname, argv[ i + 1 ] );
        if( strrchr( fname, '.' ) == NULL ) {
            strcat( fname, ".dlg" );
        }
    } else {
        strcpy( fname, "os2dlg.dlg" );
    }
    fo = fopen( fname, "w" );
    if( fo == NULL ) {
        printf( "Could not open input file: %s\n", fname );
        return( -1 );
    }
    
    alloc_statement( &dlg_hdr );
    alloc_statement( &dlg_item );

    line = malloc( MAX_LINE_LEN );
    
    buff1 = malloc( MAX_LINE_LEN );
    buff2 = malloc( MAX_LINE_LEN );
    
    my_fgets( line, MAX_LINE_LEN, fi );
    while( !feof( fi ) ) {
        while( !feof( fi ) ) {
            if( strstr( line, "DLGINCLUDE" ) != NULL ) {
                /**********************
                 * source file format:
                 *
                 * DLGINCLUDE
                 * BEGIN
                 * filename
                 * END
                 *
                 * converted to:
                 *
                 * DLGINCLUDE 1 filename
                 */
                p = malloc( MAX_LINE_LEN );
                strcpy( p, line );
                fprintf( fo, "%s 1 ", strtok( p, separators ) );
                my_fgets( line, MAX_LINE_LEN, fi );
                my_fgets( line, MAX_LINE_LEN, fi );
                strcpy( p, line );
                fprintf( fo, "%s\n", strtok( p, separators ) );
                free( p );
                my_fgets( line, MAX_LINE_LEN, fi );
                my_fgets( line, MAX_LINE_LEN, fi );
            } else if( strstr( line, "DIALOG" ) != NULL ) {
                p = malloc( MAX_LINE_LEN );
                strcpy( p, line );
                process_dialog_declaration( fi, fo, p );
                strcpy( line, p );
                free( p );
            } else if( strstr( line, "BEGIN" ) != NULL ) {
                my_fgets( line, MAX_LINE_LEN, fi );
                break;
            } else {
#if !defined( OLD_FORMAT )
                if( *line != '\0' )
#endif
                fprintf( fo, "%s\n", line );
                my_fgets( line, MAX_LINE_LEN, fi );
            }
        }
        p = "";
        while( !feof( fi ) && strcmp( p, "END" ) ) {
            while( my_fgets( buff1, MAX_LINE_LEN, fi ) != NULL ) {
                if( check_statement( buff1 ) )
                    break;
                strncat( line, skip_separator( buff1 ), MAX_LINE_LEN );
            }
            process_statement( line, fo );
            strcpy( line, buff1 );
            strcpy( buff2, buff1 );
            p = strtok( buff2, separators );
        }
        if( !feof( fi ) ) {
            fprintf( fo, "%sEND\n", STR_SPC );
        }
    }
    free( buff2 );
    free( buff1 );

    free( line );
    
    free_statement( &dlg_item );
    free_statement( &dlg_hdr );
    if( fi != NULL )
        fclose( fi );
    if( fo != NULL ) {
#if defined( OLD_FORMAT )
        fprintf( fo, "\n" );
#endif
        fclose( fo );
    }
    if( !opt.quiet )
        fprintf( stdout, "\nParsed %d dialogs.\n", dialogs_cnt );
    if( opt.flist_data ) {
        for( i = 0; i < opt.flist_cnt; i++ )
            free( opt.flist_data[ i ] );
        free( opt.flist_data );
    }
    return( 0 );
}
Beispiel #8
0
main(int argc, char *argv[])
{

	int istat, narg;
	char fngrid_control[MAXLINE], fn_input[MAXLINE], fn_outroot[MAXLINE];
	FILE *fp_grid_control, *fp_outroot, *fp_gmt;
	char filename[MAXLINE], fn_xy_out[MAXLINE];


	// set program name

	strcpy(prog_name, PNAME);


	// check command line for correct usage

	fprintf(stdout, "\n%s Arguments: ", prog_name);
	for (narg = 0; narg < argc; narg++)
		fprintf(stdout, "<%s> ", argv[narg]);
	fprintf(stdout, "\n");

	if (argc != 4)
	{
		puterr("ERROR wrong number of command line arguments.");
		disp_usage(PNAME, 
		    "<controlfile> <punfile> <outroot>");
		exit(-1);
	}


	// read command line arguments

	strcpy(fngrid_control, argv[1]);
	strcpy(fn_input, argv[2]);
	strcpy(fn_outroot, argv[3]);



	// set constants

	SetConstants();


	// read control file

	if ((fp_grid_control = fopen(fngrid_control, "r")) == NULL) {
		puterr("ERROR opening control file.");
		exit(EXIT_ERROR_FILEIO);
	}


	if ((istat = ReadPun2GMT_Input(fp_grid_control)) < 0) {
		puterr("ERROR reading control file.");
		exit(EXIT_ERROR_FILEIO);
	}


	// open GMT command file

	sprintf(filename, "%s.gmt", fn_outroot);
	if ((fp_gmt = fopen(filename, "w")) == NULL) {
		puterr("ERROR opening output GMT script file.");
		exit(EXIT_ERROR_FILEIO);
	}


	// convert .pun to xy

	ConvertPun2GMT(fn_input, "XZ", fn_outroot, fn_xy_out);
	fprintf(fp_gmt, 
		"psxy %s $JVAL $RVAL -W1/0/0/0 -M -K -O >> %s.ps\n\n",
		fn_xy_out, "${POSTSCRIPT_NAME}");
	ConvertPun2GMT(fn_input, "XY", fn_outroot, fn_xy_out);
	fprintf(fp_gmt, 
		"psxy %s $JVAL $RVAL -W1/0/0/0 -M -K -O >> %s.ps\n\n",
		fn_xy_out, "${POSTSCRIPT_NAME}");
	ConvertPun2GMT(fn_input, "ZY", fn_outroot, fn_xy_out);
	fprintf(fp_gmt, 
		"psxy %s $JVAL $RVAL -W1/0/0/0 -M -K -O >> %s.ps\n\n",
		fn_xy_out, "${POSTSCRIPT_NAME}");


	exit(0);

}
Beispiel #9
0
int32_t main(int32_t argc, char** argv) {
  FILE* infile = NULL;
  char* outname = NULL;
  uintptr_t column_sep = 2;
  uint32_t flags = 0;
  int32_t retval = 0;
  uintptr_t* col_widths = NULL;
  unsigned char* spacebuf = NULL;
  unsigned char* rjustify_buf = NULL;
  uintptr_t col_ct = 0;
  uint32_t infile_param_idx = 0;
  char* param_ptr;
#ifndef _WIN32
  char* cptr;
#endif
  uint32_t param_idx;
  uint32_t uii;
  int32_t ii;
  char cc;
  if (argc == 1) {
    goto main_ret_HELP;
  }
  for (param_idx = 1; param_idx < (uint32_t)argc; param_idx++) {
    if ((!strcmp(argv[param_idx], "--help")) || (!strcmp(argv[param_idx], "-help")) || (!strcmp(argv[param_idx], "-?")) || (!strcmp(argv[param_idx], "-h"))) {
      goto main_ret_HELP;
    }
  }

  if (argc > 10) {
    fputs("Error: Too many parameters.\n\n", stderr);
    goto main_ret_INVALID_CMDLINE_2;
  }
  for (param_idx = 1; param_idx < (uint32_t)argc; param_idx++) {
    if (argv[param_idx][0] != '-') {
      if (!infile_param_idx) {
	infile_param_idx = param_idx;
      } else if (!outname) {
	if (flags & FLAG_INPLACE) {
	  goto main_ret_INVALID_CMDLINE_3;
	}
        outname = argv[param_idx];
      } else {
	fputs("Error: Invalid parameter sequence.\n\n", stderr);
	goto main_ret_INVALID_CMDLINE_2;
      }
      continue;
    }
    param_ptr = &(argv[param_idx][1]);
    if (*param_ptr == '-') {
      // allow both single- and double-dash
      param_ptr++;
    }
    if (!strcmp(param_ptr, "inplace")) {
      if (outname) {
	goto main_ret_INVALID_CMDLINE_3;
      }
      flags |= FLAG_INPLACE;
    } else if ((!strcmp(param_ptr, "spacing")) || (!strcmp(param_ptr, "s"))) {
      if (++param_idx == (uint32_t)argc) {
	fputs("Error: Missing --spacing parameter.\n", stderr);
	goto main_ret_INVALID_CMDLINE;
      }
      ii = atoi(argv[param_idx]);
      if (ii < 1) {
	fprintf(stderr, "Error: Invalid --spacing parameter '%s'.\n", argv[param_idx]);
	goto main_ret_INVALID_CMDLINE;
      }
      column_sep = (uint32_t)ii;
    } else if (!strcmp(param_ptr, "ralign")) {
      flags |= FLAG_RJUSTIFY;
    } else if (!strcmp(param_ptr, "leading")) {
      flags |= FLAG_SPACES_BEFORE_FIRST;
    } else if (!strcmp(param_ptr, "extend-short")) {
      flags |= FLAG_PAD;
    } else if (!strcmp(param_ptr, "trailing")) {
      flags |= FLAG_SPACES_AFTER_LAST;
    } else if (!strcmp(param_ptr, "force-eoln")) {
      flags |= FLAG_FINAL_EOLN;
    } else if (!strcmp(param_ptr, "noblank")) {
      flags |= FLAG_STRIP_BLANK;
    } else {
      if ((argv[param_idx][1] != '-') && argv[param_idx][1]) {
	// permit abbreviated style
	while (1) {
	  cc = *param_ptr++;
	  if (!cc) {
	    break;
	  }
	  switch (cc) {
	  case 'i':
	    if (outname) {
	      goto main_ret_INVALID_CMDLINE_3;
	    }
	    flags |= FLAG_INPLACE;
	    break;
	  case 'r':
	    flags |= FLAG_RJUSTIFY;
	    break;
	  case 'l':
	    flags |= FLAG_SPACES_BEFORE_FIRST;
	    break;
	  case 'e':
	    flags |= FLAG_PAD;
	    break;
	  case 't':
	    flags |= FLAG_SPACES_AFTER_LAST;
	    break;
	  case 'f':
	    flags |= FLAG_FINAL_EOLN;
	    break;
	  case 'n':
	    flags |= FLAG_STRIP_BLANK;
	    break;
	  default:
            fprintf(stderr, "Error: Invalid flag '%s'.\n\n", argv[param_idx]);
	    goto main_ret_INVALID_CMDLINE_2;
	  }
	}
      } else {
	fprintf(stderr, "Error: Invalid flag '%s'.\n\n", argv[param_idx]);
	goto main_ret_INVALID_CMDLINE_2;
      }
    }
  }
  if (!infile_param_idx) {
    fputs("Error: No input filename.\n\n", stderr);
    goto main_ret_INVALID_CMDLINE_2;
  }
  if (flags & FLAG_INPLACE) {
    uii = strlen(argv[infile_param_idx]);
    outname = (char*)malloc(uii + 11);
    if (!outname) {
      goto main_ret_NOMEM;
    }
    memcpy(outname, argv[infile_param_idx], uii);
    memcpy(&(outname[uii]), "-temporary", 11);
  } else if (outname) {
#ifdef _WIN32
    uii = GetFullPathName(argv[infile_param_idx], FNAMESIZE, pathbuf, NULL);
    if ((!uii) || (uii > FNAMESIZE))
#else
    if (!realpath(argv[infile_param_idx], pathbuf))
#endif
    {
      fprintf(stderr, "Error: Failed to open %s.\n", argv[infile_param_idx]);
      goto main_ret_OPEN_FAIL;
    }
#ifdef _WIN32
    uii = GetFullPathName(outname, FNAMESIZE, &(pathbuf[FNAMESIZE + 64]), NULL);
    if (uii && (uii <= FNAMESIZE) && (!strcmp(pathbuf, &(pathbuf[FNAMESIZE + 64]))))
#else
    cptr = realpath(outname, &(pathbuf[FNAMESIZE + 64]));
    if (cptr && (!strcmp(pathbuf, &(pathbuf[FNAMESIZE + 64]))))
#endif
    {
      fputs("Error: Input and output files match.  Use --inplace instead.\n", stderr);
      goto main_ret_INVALID_CMDLINE;
    }
  }
  if (fopen_checked(&infile, argv[infile_param_idx], "rb")) {
    goto main_ret_OPEN_FAIL;
  }
  retval = scan_column_widths(infile, column_sep, &col_widths, &col_ct, &spacebuf, (flags & FLAG_RJUSTIFY)? (&rjustify_buf) : NULL);
  if (retval) {
    goto main_ret_1;
  }
  retval = pretty_write(infile, outname, flags, column_sep, col_widths, col_ct, spacebuf, rjustify_buf);
  if (retval) {
    goto main_ret_1;
  }
  fclose_null(&infile);
  if (flags & FLAG_INPLACE) {
    unlink(argv[infile_param_idx]);
    if (rename(outname, argv[infile_param_idx])) {
      fprintf(stderr, "Error: File rename failed.  Output is in %s instead of %s.\n", outname, argv[infile_param_idx]);
      goto main_ret_OPEN_FAIL;
    }
  }
  while (0) {
  main_ret_HELP:
    fputs(
"prettify v1.04 (21 Feb 2014)   Christopher Chang ([email protected])\n\n"
"Takes a tab-and/or-space-delimited text table, and generates a space-delimited\n"
"pretty-printed version.  Multibyte character encodings are not currently\n"
"supported.\n\n"
, stdout);
    disp_usage(stdout);
    fputs(
"\nTo perform the simplest reverse conversion (multiple spaces to one tab), you\n"
"can use\n"
"  cat [input filename] | tr -s ' ' '\\t' > [output filename]\n"
"For one-to-one conversion between spaces and tabs instead, omit the \"-s\".  And\n"
"to strip leading and trailing tabs and spaces, try\n"
"  cat [in] | sed 's/^[[:space:]]*//g' | sed 's/[[:space:]]*$//g' > [out]\n"
, stdout);
    retval = RET_HELP;
    break;
  main_ret_NOMEM:
    retval = RET_NOMEM;
    break;
  main_ret_OPEN_FAIL:
    retval = RET_OPEN_FAIL;
    break;
  main_ret_INVALID_CMDLINE_3:
    fputs("Error: --inplace cannot be used with an output filename.\n", stderr);
    retval = RET_INVALID_CMDLINE;
    break;
  main_ret_INVALID_CMDLINE_2:
    disp_usage(stderr);
  main_ret_INVALID_CMDLINE:
    retval = RET_INVALID_CMDLINE;
    break;
  }
 main_ret_1:
  free_cond(col_widths);
  fclose_cond(infile);
  dispmsg(retval);
  return retval;
}