Example #1
0
static int accept (const char *args) {
/*****************************************************************************
Read ("ACCEPT") a 2, 3, or 4 dimensional input coordinate.
******************************************************************************/
    T.a = parse_coord (args);
    if (T.verbosity > 3)
        fprintf (T.fout, "#  %s\n", args);
    T.dimensions_given_at_last_accept = T.dimensions_given;
    return 0;
}
Example #2
0
GHashTable*
parse_zone_tab                  (char           *filename)
{
  GHashTable *zones_hash;
  ZoneDescription *zone_desc;
  FILE *fp;
  char buf[4096];
  gchar **fields, *zone_name, *latitude, *longitude, *p;


  fp = fopen (filename, "r");
  if (!fp) {
    fprintf (stderr, "Couldn't open file: %s\n", filename);
    exit (1);
  }

  zones_hash = g_hash_table_new (g_str_hash, g_str_equal);

  while (fgets (buf, sizeof(buf), fp)) {
    if (*buf == '#') continue;

    g_strchomp (buf);
    fields = g_strsplit (buf,"\t", 4);

    if (strlen (fields[0]) != 2) {
      fprintf (stderr, "Invalid zone description line: %s\n", buf);
      exit (1);
    }

    zone_name = g_strdup (fields[2]);

    zone_desc = g_new (ZoneDescription, 1);
    zone_desc->country_code[0] = fields[0][0];
    zone_desc->country_code[1] = fields[0][1];
    zone_desc->comment = (fields[3] && fields[3][0]) ? g_strdup (fields[3])
      : NULL;

    /* Now parse the latitude and longitude. */
    latitude = fields[1];
    longitude = latitude + 1;
    while (*longitude != '+' && *longitude != '-')
      longitude++;

    parse_coord (latitude, longitude - latitude, zone_desc->latitude);
    parse_coord (longitude, strlen (longitude), zone_desc->longitude);

    g_hash_table_insert (zones_hash, zone_name, zone_desc);

#if 0
    g_print ("Found zone: %s %i %02i %02i,%i %02i %02i\n", zone_name,
             zone_desc->latitude[0], zone_desc->latitude[1],
             zone_desc->latitude[2],
             zone_desc->longitude[0], zone_desc->longitude[1],
             zone_desc->longitude[2]);
#endif
  }

  fclose (fp);

  return zones_hash;
}
Example #3
0
/*
 * Parses the config file.
 * 
 * Returns: 0 on success, -1 on error.
 */
int
parse_conf()
{
	FILE *fconf;
	char buffer[MAX_LINE_LEN + 1];
	int  c;
#ifndef TESTING
	char *config_file = get_home_config();
#else /* Not TESTING */
	char config_file[FILENAME_MAX];
#endif /* Not TESTING */
	
	
#ifndef TESTING
	strcat( config_file, "/rc.conf");
	
	if( (fconf = fopen( config_file, "r")) == NULL ) {
#endif /* TESTING */
		cpycat( config_file, DEFAULT_CONFIG);
		
		if( (fconf = fopen( config_file, "r")) == NULL ) {
			thor_errlog( LOG_ERR, "Opening config file");
#ifdef VERBOSE
			thor_log( LOG_DEBUG, "DEFAULT CONFIGURATION:");
			print_config();
#endif /* VERBOSE */
			return -1;
		}
#ifndef TESTING
	}
#endif /* TESTING */
	
	thor_log( LOG_DEBUG, "Config file: '%s'", config_file);
	
	if( inofd != -1 ) {
		if( inotify_add_watch( inofd, config_file, IN_MODIFY|IN_DELETE_SELF|IN_MOVE_SELF|IN_CLOSE_WRITE) == -1 )
			thor_ferrlog( LOG_ERR, "Installing Inotify watch on '%s'", config_file);
	}
	
	/** default values **/
	*config_default_theme = '\0';
	strcpy( config_default_font, CONFIG_DEFAULT_FONT);
	
	line = 0;
	while( (c = fgetline( fconf, buffer)) != -1 )
	{
		char *key, *value;
		
		
		line++;
		if( c != '\n') {
			if( !feof( fconf) ) {
				thor_log( LOG_ERR, "%s%d - line too long ( MAX = %d ).", log_msg, line, MAX_LINE_LEN);
				while( (c = fgetc( fconf)) != '\n' && c != EOF );
				continue;
			}
		}
		if( *buffer == '\0' )
			continue;
			
		/** get the key **/
		key = strtok_r( buffer, "=", &value);
		if( *key == '#' )     // comment
			continue;
		
		if( *value == '\0' ) {
			thor_log( LOG_ERR, "%s%d - missing value.", log_msg, line);
			continue;
		}
		
		if( strcmp( key, "use_argb") == 0 )
			parse_bool( value, &config_use_argb);
		else if( strcmp( key, "use_xshape") == 0 ) {
			if( strcmp( value, "whole") == 0 )
				config_use_xshape = 2;
			else
				parse_bool( value, &config_use_xshape);
		}
		else if( strcmp( key, "default_theme") == 0 )
			strncpy( config_default_theme, value, MAX_THEME_LEN);
		else if( strcmp( key, "default_font") == 0 )
			strncpy( config_default_font, value, MAX_FONT_LEN);
		else if( strcmp( key, "osd_default_timeout") == 0 ) {
			char   *endptr;
			double to = strtod( value, &endptr);
			
			if( *endptr == 0 )
				config_osd_default_timeout = to;
			else
				thor_log( LOG_ERR, "%s%d - '%s' is not a valid number.", log_msg, line, value);
		}
		else if( strcmp( key, "osd_default_x") == 0 )
			parse_coord( value, &config_osd_default_x);
		else if( strcmp( key, "osd_default_y") == 0 )
			parse_coord( value, &config_osd_default_y);
		else {
			thor_log( LOG_ERR, "%s%d - unknown key '%s'.", log_msg, line, key);
		}
	}
	fclose( fconf);
	
#ifdef VERBOSE
	thor_log( LOG_DEBUG, "CONFIGURATION:");
	print_config();
#endif /* VERBOSE */
	          
	return 0;
};
Example #4
0
static int expect (const char *args) {
/*****************************************************************************
Tell GIE what to expect, when transforming the ACCEPTed input
******************************************************************************/
    PJ_COORD ci, co, ce;
    double d;
    int expect_failure = 0;
    int expect_failure_with_errno = 0;

    if (0==strncmp (args, "failure", 7)) {
        expect_failure = 1;

        /* Option: Fail with an expected errno (syntax: expect failure errno -33) */
        if (0==strncmp (column (args, 2), "errno", 5))
            expect_failure_with_errno = errno_from_err_const (column (args, 3));
    }

    if (T.ignore==proj_errno(T.P))
        return another_skip ();

    if (nullptr==T.P) {
        /* If we expect failure, and fail, then it's a success... */
        if (expect_failure) {
            /* Failed to fail correctly? */
            if (expect_failure_with_errno && proj_errno (T.P)!=expect_failure_with_errno)
                return expect_failure_with_errno_message (expect_failure_with_errno, proj_errno(T.P));

            return another_succeeding_failure ();
        }

        /* Otherwise, it's a true failure */
        banner (T.operation);
        errmsg (3, "%sInvalid operation definition in line no. %d:\n       %s (errno=%s/%d)\n",
            delim, (int) T.operation_lineno, pj_strerrno(proj_errno(T.P)),
            err_const_from_errno (proj_errno(T.P)), proj_errno(T.P)
        );
        return another_failing_failure ();
    }

    /* We may still successfully fail even if the proj_create succeeded */
    if (expect_failure) {
        proj_errno_reset (T.P);

        /* Try to carry out the operation - and expect failure */
        ci = proj_angular_input (T.P, T.dir)? torad_coord (T.P, T.dir, T.a): T.a;
        co = expect_trans_n_dim (ci);

        if (expect_failure_with_errno) {
            if (proj_errno (T.P)==expect_failure_with_errno)
                return another_succeeding_failure ();
            fprintf (T.fout, "errno=%d, expected=%d\n", proj_errno (T.P), expect_failure_with_errno);
            return another_failing_failure ();
        }


        /* Succeeded in failing? - that's a success */
        if (co.xyz.x==HUGE_VAL)
            return another_succeeding_failure ();

        /* Failed to fail? - that's a failure */
        banner (T.operation);
        errmsg (3, "%sFailed to fail. Operation definition in line no. %d\n",
            delim, (int) T.operation_lineno
        );
        return another_failing_failure ();
    }


    if (T.verbosity > 3) {
        fprintf (T.fout, "%s\n", T.P->inverted? "INVERTED": "NOT INVERTED");
        fprintf (T.fout, "%s\n", T.dir== 1? "forward": "reverse");
        fprintf (T.fout, "%s\n", proj_angular_input (T.P, T.dir)?  "angular in":  "linear in");
        fprintf (T.fout, "%s\n", proj_angular_output (T.P, T.dir)? "angular out": "linear out");
        fprintf (T.fout, "left: %d   right:  %d\n", T.P->left, T.P->right);
    }

    tests++;
    T.e  =  parse_coord (args);
    if (HUGE_VAL==T.e.v[0])
        return expect_message_cannot_parse (args);


    /* expected angular values, probably in degrees */
    ce = proj_angular_output (T.P, T.dir)? torad_coord (T.P, T.dir, T.e): T.e;
    if (T.verbosity > 3)
        fprintf (T.fout, "EXPECTS  %.12f  %.12f  %.12f  %.12f\n",
                 ce.v[0],ce.v[1],ce.v[2],ce.v[3]);

    /* input ("accepted") values, also probably in degrees */
    ci = proj_angular_input (T.P, T.dir)? torad_coord (T.P, T.dir, T.a): T.a;
    if (T.verbosity > 3)
        fprintf (T.fout, "ACCEPTS  %.12f  %.12f  %.12f  %.12f\n",
                 ci.v[0],ci.v[1],ci.v[2],ci.v[3]);

    /* do the transformation, but mask off dimensions not given in expect-ation */
    co = expect_trans_n_dim (ci);
    if (T.dimensions_given < 4)
        co.v[3] = 0;
    if (T.dimensions_given < 3)
        co.v[2] = 0;

    /* angular output from proj_trans comes in radians */
    T.b = proj_angular_output (T.P, T.dir)? todeg_coord (T.P, T.dir, co): co;
    if (T.verbosity > 3)
        fprintf (T.fout, "GOT      %.12f  %.12f  %.12f  %.12f\n",
                 co.v[0],co.v[1],co.v[2],co.v[3]);

#if 0
    /* We need to handle unusual axis orders - that'll be an item for version 5.1 */
    if (T.P->axisswap) {
        ce = proj_trans (T.P->axisswap, T.dir, ce);
        co = proj_trans (T.P->axisswap, T.dir, co);
    }
#endif
    if (proj_angular_output (T.P, T.dir))
        d = proj_lpz_dist (T.P, ce, co);
    else
        d = proj_xyz_dist (co, ce);

    if (d > T.tolerance)
        return expect_message (d, args);
    succs++;

    another_success ();
    return 0;
}
Example #5
0
static void process_gpgga_token(void) {
    switch (token_nr) {
#if PARSE_GPS_TIME
    case 1:
        /* time
         * HHMMSS(.sssss)
         */
        parse_clock(&nmea_wip.gga.clock);
        break;
#endif
    case 2:
        /* latitude
         * BBBB.BBBB
         */
        parse_coord(&nmea_wip.gga.lat);
        break;
    case 3:
        /* orientation
         * N north
         * S south
         */
        if (token_buffer[0] == 'N') {
            nmea_wip.gga.flags |= (1<<NMEA_RMC_FLAGS_LAT_NORTH);
        } else {
            nmea_wip.gga.flags &= ~(1<<NMEA_RMC_FLAGS_LAT_NORTH);
        }
        break;
    case 4:
        /* longitude
         * LLLLL.LLLL
         */
        parse_coord(&nmea_wip.gga.lon);
        break;
    case 5:
        /* orientation
         * E east
         * W west
         */
        if (token_buffer[0] == 'E') {
            nmea_wip.gga.flags |= (1<<NMEA_RMC_FLAGS_LON_EAST);
        } else {
            nmea_wip.gga.flags &= ~(1<<NMEA_RMC_FLAGS_LON_EAST);
        }

        break;
    case 6:
        /* signal quality */
        nmea_wip.gga.quality = atoi(token_buffer);
        if (nmea_wip.gga.quality) {
            nmea_wip.gga.flags |= (1<<NMEA_RMC_FLAGS_STATUS_OK);
        } else {
            nmea_wip.gga.flags &= ~(1<<NMEA_RMC_FLAGS_STATUS_OK);
        }
        break;
    case 7:
        /* number of used satellites */
        nmea_wip.gga.sats = atoi(token_buffer);
        break;
#if PARSE_GPS_ALTITUDE
    case 9:
        /* altitude */
        parse_altitude(&nmea_wip.gga.alt);
        break;
#endif
    default:
        /* nothing to do */
        break;
    }
}
Example #6
0
static void process_gprmc_token(void) {
    switch (token_nr) {
#if !PARSE_GPS_NMEA_GGA /* avoid duplicate parsing code */
#if PARSE_GPS_TIME
    case 1:
        /* time
         * HHMMSS(.sssss)
         */
        parse_clock(&nmea_wip.rmc.clock);
        break;
#endif
    case 2:
        /* status
         * A OK
         * V Warning
         */
        if (token_buffer[0] == 'A') {
            nmea_wip.rmc.flags |= (1<<NMEA_RMC_FLAGS_STATUS_OK);
        } else {
            nmea_wip.rmc.flags &= ~(1<<NMEA_RMC_FLAGS_STATUS_OK);
        }
        break;
    case 3:
        /* latitude
         * BBBB.BBBB
         */
        parse_coord(&nmea_wip.rmc.lat);
        break;
    case 4:
        /* orientation
         * N north
         * S south
         */
        if (token_buffer[0] == 'N') {
            nmea_wip.rmc.flags |= (1<<NMEA_RMC_FLAGS_LAT_NORTH);
        } else {
            nmea_wip.rmc.flags &= ~(1<<NMEA_RMC_FLAGS_LAT_NORTH);
        }
        break;
    case 5:
        /* longitude
         * LLLLL.LLLL
         */
        parse_coord(&nmea_wip.rmc.lon);
        break;
    case 6:
        /* orientation
         * E east
         * W west
         */
        if (token_buffer[0] == 'E') {
            nmea_wip.rmc.flags |= (1<<NMEA_RMC_FLAGS_LON_EAST);
        } else {
            nmea_wip.rmc.flags &= ~(1<<NMEA_RMC_FLAGS_LON_EAST);
        }

        break;
#endif
    case 7:
        /* speed
         * GG.G
         */
        break;
    case 8:
        /* course
         * RR.R
         */
        break;
#if PARSE_GPS_TIME
    case 9:
        /* date
         * DDMMYY
         */
        parse_date(&nmea_wip.rmc.date);
        break;
#endif
    case 10:
        /* magnetic declination
         * M.M
         */
        break;
    case 11:
        /* sign of declination
         * E east
         * W west
         */
        break;
    case 12:
        /* signal integrity
         * A autonomous mode
         * D differential mode
         * E estimated mode
         * M manual input mode
         * S simulated mode
         * N data not valid
         */
        break;
    }
}