Beispiel #1
0
int print_response (const char *cp, CTL_RESPONSE * rp)
{
    syslog (LOG_DEBUG, "%s: %s: %s, id %d",
            cp,
            _xlat_num (rp->type, message_types, NITEMS (message_types)),
            _xlat_num (rp->answer, answers, NITEMS (answers)), ntohl (rp->id_num));
    return 0;
}
Beispiel #2
0
int print_request (const char *cp, CTL_MSG * mp)
{
    syslog (LOG_DEBUG, "%s: %s: id %d, l_user %s, r_user %s, r_tty %s",
            cp, _xlat_num (mp->type, message_types, NITEMS (message_types)),
            mp->id_num, mp->l_name, mp->r_name, mp->r_tty);
    return 0;
}
/*
 * Setup a directory entry that references a samples/pixel array of ``type''
 * values and (potentially) write the associated indirect values.  The source
 * data from TIFFGetField() for the specified tag must be returned as double.
 */
static int
TIFFWritePerSampleAnys(TIFF* tif,
    TIFFDataType type, ttag_t tag, TIFFDirEntry* dir)
{
	double buf[10], v;
	double* w = buf;
	int i, status;
	int samples = (int) tif->tif_dir.td_samplesperpixel;

	if (samples > NITEMS(buf))
		w = (double*) _TIFFmalloc(samples * sizeof (double));
	TIFFGetField(tif, tag, &v);
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
	for (i = 0; i < samples; i++)
		w[i] = v;
	status = TIFFWriteAnyArray(tif, type, tag, dir, samples, w);
	if (w != buf)
		_TIFFfree(w);
	return (status);
}
/*
 * Setup a directory entry that references a
 * samples/pixel array of SHORT values and
 * (potentially) write the associated indirect
 * values.
 */
static int
TIFFWritePerSampleShorts(TIFF* tif, ttag_t tag, TIFFDirEntry* dir)
{
	uint16 buf[10], v;
	uint16* w = buf;
	int i, status, samples = tif->tif_dir.td_samplesperpixel;

	if (samples > NITEMS(buf))
		w = (uint16*) _TIFFmalloc(samples * sizeof (uint16));
	TIFFGetField(tif, tag, &v);
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
	for (i = 0; i < samples; i++)
		w[i] = v;
	status = TIFFWriteShortArray(tif, TIFF_SHORT, tag, dir, samples, w);
	if (w != buf)
		_TIFFfree((char*) w);
	return (status);
}
Beispiel #5
0
int json_rtcm2_read(const char *buf,
		    char *path, size_t pathlen, struct rtcm2_t *rtcm2,
		    /*@null@*/ const char **endptr)
{

    static char *stringptrs[NITEMS(rtcm2->words)];
    static char stringstore[sizeof(rtcm2->words) * 2];
    static int stringcount;

/* *INDENT-OFF* */
#define RTCM2_HEADER \
	{"class",          t_check,    .dflt.check = "RTCM2"}, \
	{"type",           t_uinteger, .addr.uinteger = &rtcm2->type}, \
	{"device",         t_string,   .addr.string = path, \
	                                  .len = pathlen}, \
	{"station_id",     t_uinteger, .addr.uinteger = &rtcm2->refstaid}, \
	{"zcount",         t_real,     .addr.real = &rtcm2->zcount, \
			                  .dflt.real = NAN}, \
	{"seqnum",         t_uinteger, .addr.uinteger = &rtcm2->seqnum}, \
	{"length",         t_uinteger, .addr.uinteger = &rtcm2->length}, \
	{"station_health", t_uinteger, .addr.uinteger = &rtcm2->stathlth},

    int status = 0, satcount = 0;

    /*@ -fullinitblock @*/
    const struct json_attr_t rtcm1_satellite[] = {
	{"ident",     t_uinteger, STRUCTOBJECT(struct gps_rangesat_t, ident)},
/*
 * Setup a directory entry that references a
 * samples/pixel array of SHORT values and
 * (potentially) write the associated indirect
 * values.
 */
static int
TIFFWritePerSampleShorts(TIFF* tif, ttag_t tag, TIFFDirEntry* dir)
{
	uint16 buf[10], v;
	uint16* w = buf;
	uint16 i, samples = tif->tif_dir.td_samplesperpixel;
	int status;

	if (samples > NITEMS(buf)) {
		w = (uint16*) _TIFFmalloc(samples * sizeof (uint16));
		if (w == NULL) {
			TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
			    "No space to write per-sample shorts");
			return (0);
		}
	}
	TIFFGetField(tif, tag, &v);
	for (i = 0; i < samples; i++)
		w[i] = v;
	
	dir->tdir_tag = (uint16) tag;
	dir->tdir_type = (uint16) TIFF_SHORT;
	dir->tdir_count = samples;
	status = TIFFWriteShortArray(tif, dir, w);
	if (w != buf)
		_TIFFfree((char*) w);
	return (status);
}
Beispiel #7
0
/*
 * Setup a directory entry that references a samples/pixel array of ``type''
 * values and (potentially) write the associated indirect values.  The source
 * data from TIFFGetField() for the specified tag must be returned as double.
 */
static int
TIFFWritePerSampleAnys(TIFF* tif,
    TIFFDataType type, ttag_t tag, TIFFDirEntry* dir)
{
	double buf[10], v;
	double* w = buf;
	int i, status;
	int samples = (int) tif->tif_dir.td_samplesperpixel;

	if (samples > NITEMS(buf)) {
		w = (double*) _TIFFmalloc(samples * sizeof (double));
		if (w == NULL) {
			TIFFError(tif->tif_name,
			    "No space to write per-sample values");
			return (0);
		}
	}
	TIFFGetField(tif, tag, &v);
	for (i = 0; i < samples; i++)
		w[i] = v;
	status = TIFFWriteAnyArray(tif, type, tag, dir, samples, w);
	if (w != buf)
		_TIFFfree(w);
	return (status);
}
Beispiel #8
0
void
testfiles(FILE *idx)
{
	char *bad, *name, *fullname, *imgfile, *outfile, *errfile, *exitfile;
	char *newoutfile, *newerrfile;
	int exitval, failed, failures, testcount;
	size_t i;

	printf("running tests...\n");

	bad = NULL;
	testcount = 0;
	failures = 0;
	while ((name = nextname(TESTINDEX_PATH, idx)) != NULL) {
		for (i = 0; i < NITEMS(flags); i++) {
			fullname = strjoin(name, flags[i], (void *)NULL);
			imgfile = strjoin(name, ".img", (void *)NULL);
			outfile = strjoin(fullname, ".out", (void *)NULL);
			errfile = strjoin(fullname, ".err", (void *)NULL);
			exitfile = strjoin(fullname, ".exit", (void *)NULL);
			newoutfile = strjoin("test-", fullname, ".out", (void *)NULL);
			newerrfile = strjoin("test-", fullname, ".err", (void *)NULL);

			rmfile(newoutfile);
			rmfile(newerrfile);
			exitval = runtest(flags[i], imgfile,
			    newoutfile, newerrfile);
			failed = 0;

			if (!checkexitval(fullname, exitval, exitfile))
				failed = 1;
			if (!checkfiles(fullname, outfile, newoutfile, 0))
				failed = 1;
			if (!checkfiles(fullname, errfile, newerrfile, 1))
				failed = 1;

			testcount++;
			if (failed) {
				failures++;
				bad = appendname(bad, fullname);
			}

			free(fullname);
			free(imgfile);
			free(outfile);
			free(errfile);
			free(exitfile);
			free(newoutfile);
			free(newerrfile);
		}
	}

	printf("%d tests failed out of %d total.\n", failures, testcount);
	if (failures != 0) {
		printf("The following tests failed:\n  %s\n", bad);
		exit(EXIT_FAILURE);
	}
}
Beispiel #9
0
static void usage(void)
{
    fprintf(stderr,
	    "Usage: %s [-V] [-h] [-d] [-i timeout] [-f filename] [-m minmove]\n"
	    "\t[-e exportmethod] [server[:port:[device]]]\n\n"
	    "defaults to '%s -i 5 -e %s localhost:2947'\n",
	    progname, progname, (NITEMS(methods) > 0) ? methods[0].name : "(none)");
    exit(1);
}
Beispiel #10
0
void export_list(FILE *fp)
/* list known export methods */
{
    struct exportmethod_t *method;

    for (method = exportmethods;
	 method < exportmethods + NITEMS(exportmethods);
	 method++)
	(void)fprintf(fp, "%s: %s\n", method->name, method->description);
}
Beispiel #11
0
struct exportmethod_t *export_lookup(const char *name)
/* Look up an available export method by name */
{
    struct exportmethod_t *mp, *method = NULL;

    for (mp = exportmethods;
	 mp < exportmethods + NITEMS(exportmethods);
	 mp++)
	if (strcmp(mp->name, name) == 0)
	    method = mp;
    return method;
}
Beispiel #12
0
/*
 * Setup a directory entry that references a
 * samples/pixel array of SHORT values and
 * (potentially) write the associated indirect
 * values.
 */
static int
TIFFWritePerSampleShorts(TIFF* tif, ttag_t tag, TIFFDirEntry* dir)
{
        uint16 buf[10], v;
        uint16* w = buf;
        int i, status, samples = tif->tif_dir.td_samplesperpixel;

        if (samples > (int)NITEMS(buf))
                w = (uint16*) _TIFFmalloc(samples * sizeof (uint16));
        TIFFGetField(tif, tag, &v);
        for (i = 0; i < samples; i++)
                w[i] = v;
        status = TIFFWriteShortArray(tif, TIFF_SHORT, tag, dir, samples, w);
        if (w != buf)
                _TIFFfree((char*) w);
        return (status);
}
Beispiel #13
0
static void
print_param_prob (struct icmp6_hdr *icmp6)
{
  struct icmp_code_descr *p;

  printf ("Parameter problem: ");
  for (p = icmp_param_prob_desc;
       p < icmp_param_prob_desc + NITEMS (icmp_param_prob_desc); p++)
    {
      if (p->code == icmp6->icmp6_code)
	{
	  puts (p->diag);
	  return;
	}
    }

  printf ("Unknown code %d\n", icmp6->icmp6_code);
}
Beispiel #14
0
static void
print_time_exceeded (struct icmp6_hdr *icmp6)
{
  struct icmp_code_descr *p;

  printf ("Time exceeded: ");
  for (p = icmp_time_exceeded_desc;
       p < icmp_time_exceeded_desc + NITEMS (icmp_time_exceeded_desc); p++)
    {
      if (p->code == icmp6->icmp6_code)
	{
	  puts (p->diag);
	  return;
	}
    }

  printf ("Unknown code %d\n", icmp6->icmp6_code);
}
Beispiel #15
0
static void
print_dst_unreach (struct icmp6_hdr *icmp6)
{
  struct icmp_code_descr *p;

  printf ("Destination unreachable: ");
  for (p = icmp_dest_unreach_desc;
       p < icmp_dest_unreach_desc + NITEMS (icmp_dest_unreach_desc); p++)
    {
      if (p->code == icmp6->icmp6_code)
	{
	  puts (p->diag);
	  return;
	}
    }

  printf ("Unknown code %d\n", icmp6->icmp6_code);
}
Beispiel #16
0
void
regenfiles(FILE *idx)
{
	char *imgfile, *outfile, *errfile, *exitfile;
	int exitval;
	char *name;
	size_t i;

	while ((name = nextname(TESTINDEX_PATH, idx)) != NULL) {
		for (i = 0; i < NITEMS(flags); i++) {
			imgfile = strjoin(name, ".img", (void *)NULL);
			outfile = strjoin(name, flags[i], ".out", (void *)NULL);
			errfile = strjoin(name, flags[i], ".err", (void *)NULL);
			exitfile = strjoin(name, flags[i], ".exit", (void *)NULL);

			rmfile(outfile);
			rmfile(errfile);
			rmfile(exitfile);
			exitval = runtest(flags[i], imgfile, outfile, errfile);

			if (filesize(outfile) == 0)
				rmfile(outfile);
			if (filesize(errfile) == 0)
				rmfile(errfile);
			if (exitval != 0) {
				FILE *eh;

				if ((eh = fopen(exitfile, "w")) == NULL)
					fail("failed to open %s for writing",
					    exitfile);
				fprintf(eh, "%d\n", exitval);
				fclose(eh);
			}

			free(imgfile);
			free(outfile);
			free(errfile);
			free(exitfile);
		}
	}
}
Beispiel #17
0
void
cleanfiles(FILE *idx)
{
	char *name, *outfile, *errfile;
	size_t i;

	while ((name = nextname(TESTINDEX_PATH, idx)) != NULL) {
		printf("%s", RMFILE_DISPLAY);
		for (i = 0; i < NITEMS(flags); i++) {
			outfile = strjoin("test-", name, flags[i], ".out", (void *)NULL);
			errfile = strjoin("test-", name, flags[i], ".err", (void *)NULL);
			printf(" %s%s%s %s%s%s",
			    TESTDIR_PATH, DIRSEP_DISPLAY, outfile,
			    TESTDIR_PATH, DIRSEP_DISPLAY, errfile);
			rmfile(outfile);
			rmfile(errfile);
			free(outfile);
			free(errfile);
		}
		printf("\n");
	}
}
Beispiel #18
0
static void
print_icmp_error (struct sockaddr_in6 *from, struct icmp6_hdr *icmp6, int len)
{
  char *s;
  struct icmp_diag *p;

  s = ipaddr2str (from);
  printf ("%d bytes from %s: ", len, s);
  free (s);

  for (p = icmp_diag; p < icmp_diag + NITEMS (icmp_diag); p++)
    {
      if (p->type == icmp6->icmp6_type)
	{
	  p->func (icmp6);
	  return;
	}
    }

  /* This should never happen because of the ICMP6_FILTER set in
     ping_init(). */
  printf ("Unknown ICMP type: %d\n", icmp6->icmp6_type);
}
Beispiel #19
0
/*@-mustfreefresh -globstate@*/
int main(int argc, char **argv)
{
    int ch;
    bool daemonize = false;
    struct method_t *mp, *method = NULL;

    progname = argv[0];

    logfile = stdout;
    while ((ch = getopt(argc, argv, "dD:e:f:hi:lm:V")) != -1) {
	switch (ch) {
	case 'd':
	    openlog(basename(progname), LOG_PID | LOG_PERROR, LOG_DAEMON);
	    daemonize = true;
	    break;
#ifdef CLIENTDEBUG_ENABLE
	case 'D':
	    debug = atoi(optarg);
	    gps_enable_debug(debug, logfile);
	    break;
#endif /* CLIENTDEBUG_ENABLE */
	case 'e':
	    for (mp = methods;
		 mp < methods + NITEMS(methods);
		 mp++)
		if (strcmp(mp->name, optarg) == 0)
		    method = mp;
	    if (method == NULL) {
		(void)fprintf(stderr,
			      "%s: %s is not a known export method.\n",
			      progname, optarg);
		exit(1);
	    }
	    break;
       case 'f':       /* Output file name. */
            {
                char    fname[PATH_MAX];
                time_t  t;
                size_t  s;

                t = time(NULL);
                s = strftime(fname, sizeof(fname), optarg, localtime(&t));
                if (s == 0) {
                        syslog(LOG_ERR,
                            "Bad template \"%s\", logging to stdout.", optarg);
                        break;
                }
                logfile = fopen(fname, "w");
                if (logfile == NULL)
                        syslog(LOG_ERR,
                            "Failed to open %s: %s, logging to stdout.",
                            fname, strerror(errno));
                break;
            }
	case 'i':		/* set polling interfal */
	    timeout = (time_t) atoi(optarg);
	    if (timeout < 1)
		timeout = 1;
	    if (timeout >= 3600)
		fprintf(stderr,
			"WARNING: track timeout is an hour or more!\n");
	    break;
	case 'l':
	    for (method = methods;
		 method < methods + NITEMS(methods);
		 method++)
		(void)printf("%s: %s\n", method->name, method->description);
	    exit(0);
        case 'm':
	    minmove = (double )atoi(optarg);
	    break;
	case 'V':
	    (void)fprintf(stderr, "gpxlogger revision " REVISION "\n");
	    exit(0);
	default:
	    usage();
	    /* NOTREACHED */
	}
    }

    if (daemonize && logfile == stdout) {
	syslog(LOG_ERR, "Daemon mode with no valid logfile name - exiting.");
	exit(1);
    }

    if (optind < argc) {
	gpsd_source_spec(argv[optind], &source);
    } else
	gpsd_source_spec(NULL, &source);
#if 0
    (void)fprintf(logfile,"<!-- server: %s port: %s  device: %s -->\n",
		 source.server, source.port, source.device);
#endif

    /* initializes the some gpsdata data structure */
    gpsdata.status = STATUS_NO_FIX;
    gpsdata.satellites_used = 0;
    gps_clear_fix(&(gpsdata.fix));
    gps_clear_dop(&(gpsdata.dop));

    /* catch all interesting signals */
    (void)signal(SIGTERM, quit_handler);
    (void)signal(SIGQUIT, quit_handler);
    (void)signal(SIGINT, quit_handler);

    /*@-unrecog@*/
    /* might be time to daemonize */
    if (daemonize) {
	/* not SuS/POSIX portable, but we have our own fallback version */
	if (daemon(0, 0) != 0)
	    (void) fprintf(stderr,"demonization failed: %s\n", strerror(errno));
    }
    /*@+unrecog@*/

    //syslog (LOG_INFO, "---------- STARTED ----------");

    if (method != NULL) {
	exit((*method->method)());
    } else if (NITEMS(methods)) {
	exit((methods[0].method)());
    } else {
	(void)fprintf(stderr, "%s: no export methods.\n", progname);
	exit(1);
    }
}
Beispiel #20
0
struct exportmethod_t *export_default(void)
{
    return (NITEMS(exportmethods) > 0) ? &exportmethods[0] : NULL;
}