Example #1
0
static char *
nmn4_concat(char *arg0, ...)
{
	va_list args;
	char *src, *res;
	
	res = NULL;
	va_start(args, arg0);
	src = (char *)arg0;

	while (src != NULL)
	{
		char *c = lrtrim(src);
		
	    	if (*c != '\0')
	    	{
			if (res == NULL)
				res = xstrdup(c);
			else
			{
				res = xstrappend(res, " ");
				res = xstrappend(res, c);
			}
	    	}
	    	xfree(src);
	    	src = va_arg(args, char *);
	}
	va_end(args);
	
	return res;
}
Example #2
0
static void
init_date_and_time_format(void)
{
    char *f, *c;

    f = get_option_val(opt_date_format, DEFAULT_DATE_FORMAT);
    date_time_format = convert_human_date_format(f);

    date_time_format = xstrappend(date_time_format, " ");

    f = get_option_val(opt_time_format, DEFAULT_TIME_FORMAT);
    c = convert_human_time_format(f);
    date_time_format = xstrappend(date_time_format, c);
    xfree(c);
}
Example #3
0
static char *
geoniche_geostuff(const waypoint *wpt)
{
	char *gs = NULL, *tmp1, *tmp2, *tmp3;
	char tbuf[10240];

	if (!wpt->gc_data->terr) {
		return NULL;
	}

	snprintf(tbuf, sizeof(tbuf), "\n%s by %s\n\n", gs_get_cachetype(wpt->gc_data->type), wpt->gc_data->placer);
	gs = xstrappend(gs, tbuf);

/*
 * 3 May 06: Removed duplicated information
 *
 * 	snprintf(tbuf, sizeof(tbuf), "Waypoint: %s %s\n", wpt->shortname, wpt->description);	
 *	gs = xstrappend(gs, tbuf);
 */

/*
 * 3 May 06: Added container type
 */
	snprintf(tbuf, sizeof(tbuf), "Container: %s\nDifficulty: %3.1f\nTerrain: %3.1f\n\n", gs_get_container(wpt->gc_data->container), wpt->gc_data->diff/10.0, wpt->gc_data->terr/10.0);
	gs = xstrappend(gs, tbuf);

	tmp1 = strip_html(&wpt->gc_data->desc_short);
	tmp2 = strip_html(&wpt->gc_data->desc_long);
	gs = xstrappend(gs, tmp1);
	gs = xstrappend(gs, tmp2);

	tmp3 = rot13(wpt->gc_data->hint);
	snprintf(tbuf, sizeof(tbuf), "\n\nHint: %s\n", tmp3);
	gs = xstrappend(gs, tbuf);

	xfree(tmp1);
	xfree(tmp2);
	xfree(tmp3);

	tmp1 = enscape(gs);
	xfree(gs);

	return tmp1;
}
Example #4
0
static char *stringify_fields(const struct list_head *field_head)
{
	char *field_str, *fields = NULL;
	struct field *field;

	list_for_each_entry(field, field_head, list) {
		field_str = stringify_field(field);
		xstrappend(&fields, field_str);
		free(field_str);
	}
Example #5
0
static char *stringify_fields(const struct field *field_head)
{
	char *field_str, *fields = NULL;

	for (const struct field *field = field_head; field; field = field->next) {
		field_str = stringify_field(field);
		xstrappend(&fields, field_str);
		free(field_str);
	}
	if (fields)
		xstrappend(&fields, "0\taction\t\taction\n0\tmethod\t\tmethod\n");
	else
		fields = xstrdup("");

	field_str = NULL;
	bytes_to_hex(fields, &field_str, strlen(fields));
	free(fields);

	return field_str;
}
Example #6
0
void wpt_desc(const char *args, const char **unused)
{
	if (args) {
		char *tmp, *c;
		
		tmp = xstrdup((char *)args);
		c = lrtrim(tmp);
		if (*c) {
			wpt_tmp->description = xstrappend(wpt_tmp->description, c);
		}
		xfree(tmp);
	}
}
Example #7
0
/* 
 * The magic here is to try to ensure that posnfilename is atomically
 * updated.
 */
static void
kml_wr_position_init(const char *fname)
{
	posnfilename = fname;;
	posnfilenametmp = xstrappend(xstrdup(fname), "-");
	realtime_positioning = 1;

	/*
	 * 30% of our output file is whitespace.  Since parse time
	 * matters in this mode, turn the pretty formatting off.
	 */
	do_indentation = 0;

	max_position_points = atoi(opt_max_position_points);
}
Example #8
0
static void
nmn4_read_data(void)
{
	char *buff;
	char *str, *c;
	int column;
	int line = 0;

	char *zip1, *zip2, *city, *street, *number;	
	route_head *route;
	waypoint *wpt;
	
	route = route_head_alloc();
	route_add_head(route);
	
	while ((buff = gbfgetstr(fin)))
	{
		if ((line++ == 0) && fin->unicode) cet_convert_init(CET_CHARSET_UTF8, 1);
		str = buff = lrtrim(buff);
		if (*buff == '\0') continue;
		
		nmn4_check_line(buff);

		/* for a quiet compiler */
		zip1 = zip2 = city = street = number = NULL;
	    
	    	wpt = waypt_new();
	    
	    	column = -1;
	    	c = csv_lineparse(str, "|", "", column++);
	    	while (c != NULL)
	    	{
			switch(column)
			{
		    		case  0: /* "-" */	/* unknown fields for the moment */
		    		case  1: /* "-" */
		    		case  2: /* "-" */
		    		case  3: /* "-" */
		    		case  9: /* "-" */
		    		case 10: /* "-" */
		    		case 13: /* "-" */
		    		case 14: /* "-" */
				case 15: /* "" */
					break;
		    
		    		case  4: 				/* ZIP Code */
					if (*c != '-') 
						zip1 = xstrdup(c);
					else
						zip1 = xstrdup("");
					break;
			
		    		case  5: 				/* City */
					if (*c != '-')
						city = xstrdup(c); 
					else
						city = xstrdup("");
					break;
			
		    		case  6: 				/* ZIP Code -2- */
					if (*c != '-') 
						zip2 = xstrdup(c); 
					else
						zip2 = xstrdup("");	
					break;
					
				case  7: 				/* Street */
					if (*c != '-')
						street = xstrdup(c); 
					else
						street = xstrdup("");
					break;
					
				case  8: 				/* Number */
					if (*c != '-')
						number = xstrdup(c); 
					else
						number = xstrdup("");

				/* 
			    	   This is our final index
				   All stuff for generating names or comments
				   is hold locally.
				   
				   We don't have fields for street, city or zip-code.
				   Instead we construct a description from that.
				*/
			
					if (strcmp(zip1, zip2) == 0) *zip2 = '\0';
					if (*city != '\0')
					{
			    			/* 
						   if any field following city has a value, add a comma to city 
						*/
			    			if ((*street != '\0') || (*number != '\0') || (*zip2 != '\0'))
							city = xstrappend(city, ",");
					}
										
					/* concats all fields to one string and release */
					wpt->description = nmn4_concat(zip1, city, street, number, zip2, NULL);
					break;
			
		    		case 11: 				/* longitude */
					sscanf(c, "%lf", &wpt->longitude);
					break;
			
				case 12: 				/* latitude */
					sscanf(c, "%lf", &wpt->latitude);
					break;
			
			}
			c = csv_lineparse(NULL, "|", "", column++);
		}
		route_add_wpt(route, wpt);
	}
}
Example #9
0
static waypoint*
parse_wpt(char *buff)
{
	int col = -1;
	char *c, *cx;
	waypoint *wpt = waypt_new();
	struct tm tm;
	memset(&tm, 0, sizeof(tm));
	int has_time = 0;

	c = strstr(buff, "A ");
	if (c == buff) col++;

	c = csv_lineparse(buff, " ", "", col++);
	while (c != NULL)
	{
		c = lrtrim(c);
		if (*c != '\0')
		{
#if 0
			printf(MYNAME "_read_wpt: col(%d)=%s\n", col, c);
#endif
			switch(col)
			{
				case 0:
					
					cx = c + strlen(c) - 1;		/* trim trailing underscores */
					while ((cx >= c) && (*cx == '_')) *cx-- = '\0';
					if (*c != '\0')
						wpt->shortname = xstrdup(c);
					break;
				case 2:
					human_to_dec(c, &wpt->latitude, NULL, 1);
					break;
				case 3:
					human_to_dec(c, NULL, &wpt->longitude, 2);
					break;
				// Older compegps used a dumb constant.
				// Report are that 2010-era writes a sensible
				// value here.
				/* always "27-MAR-62 00:00:00" */
				case 4:	
					if (strcmp(c, "27-MAR-62")) {
						has_time = 1;
						compegps_parse_date(c, &tm);
					}
					break;
				case 5:
					if (has_time) {
						compegps_parse_time(c, &tm);
						wpt->creation_time = mkgmtime(&tm);
					}
				case 6:
					wpt->altitude = atof(c);
					break;
				case 7:
					wpt->description = xstrdup(c);
					break;
				default:
					if (col > 7)
					{
						wpt->description = xstrappend(wpt->description, " ");
						wpt->description = xstrappend(wpt->description, c);
					}
			}
		}
		c = csv_lineparse(NULL, " ", "", col++);
	}
	fix_datum(&wpt->latitude, &wpt->longitude);
	return wpt;
}
Example #10
0
static void
geoniche_writewpt(const waypoint *wpt)
{
    int			vlen;
    char		*vdata;
    char		*title;
    struct tm		tm;
    char		datestr[10+1];
    char		timestr[8+1];
    char		*notes;
    int			id;
    time_t		tx;
    char 		*gs;

    if (rec_ct == 0) {
	pdb_write_rec(file_out, 0, 0, ct++, Rec0Magic, sizeof(Rec0Magic));
    }

    if ( wpt->description && wpt->description[0] )
	title = enscape(wpt->description);
    else
	title = enscape(wpt->shortname);

    id = gid2id(wpt->shortname);
    if (id < 0)
	id = rec_ct;
	
    tx = (wpt->creation_time != 0) ? wpt->creation_time : gpsbabel_time;
    if (tx == 0) {	/* maybe zero during testo (freezed time) */
	strcpy(datestr, "01/01/1904");	/* this seems to be the uninitialized date value for geoniche */
	strcpy(timestr, "00:00:00");
    }
    else  {
	tm = *localtime(&tx);
	strftime(datestr, sizeof(datestr), "%m/%d/%Y", &tm);
	strftime(timestr, sizeof(timestr), "%H:%M:%S", &tm);
    }

    /* Notes field MUST have soemthing in it */
    if (!wpt->notes || wpt->notes[0] == 0)
	notes = xstrdup(title);
    else
	notes = enscape(wpt->notes);
	
    gs = geoniche_geostuff(wpt);
    if (gs) {
	notes = xstrappend(notes, gs);
	xfree (gs);
    }
    /* last chance to fill notes with something */
    if (*notes == '\0') notes = xstrappend(notes, "(notes)");

    vlen = xasprintf(&vdata,
	    "Target,%d,%s,,%s,%f,%f,%f,%s,%s,,,,%d,,,,%s"
	    , id
	    , title
	    /* route ID */
	    , Arg_category ? Arg_category : "Cache"
	    , wpt->latitude
	    , wpt->longitude
	    , wpt->altitude
	    , datestr
	    , timestr
	    /* visited date */
	    /* visited time */
	    /* icon color R G B */
	    , wpt2icon(wpt)
	    /* unused1 */
	    /* unused2 */
	    /* unused3 */
	    , notes
	    );

    pdb_write_rec(file_out, 0, 0, ct++, vdata, vlen + 1);

    xfree(notes);
    xfree(title);
    xfree(vdata);

    rec_ct++;
}
Example #11
0
static void
mmo_write_wpt_cb(const waypoint *wpt)
{
	char *str, *cx;
	int objid;
	time_t time;
	int icon = 0;

	time = wpt->creation_time;
	if (time < 0) time = 0;
	
	if (mmo_datatype == trkdata) {
		gbfputdbl(wpt->latitude, fout);
		gbfputdbl(wpt->longitude, fout);
		gbfputc(0, fout);
		gbfputuint32(time, fout);
		if (wpt->altitude != unknown_alt) 
			gbfputflt(wpt->altitude, fout);
		else
			gbfputflt(0, fout);

		return;
	}

	objid = mmo_write_obj_head("CObjWaypoint",
		(wpt->shortname && *wpt->shortname) ? wpt->shortname : "Mark", time, wptdata);
	mmo_register_object(objid, wpt, wptdata);
	mmo_write_category("CCategory", (mmo_datatype == rtedata) ? "Waypoints" : "Marks");

	gbfputdbl(wpt->latitude, fout);
	gbfputdbl(wpt->longitude, fout);
	
	if (mmo_datatype == rtedata) {
		int i = mmo_get_objid(mmo_rte);
		gbfputuint16(1, fout); /* two extra bytes */
		gbfputuint16(i & 0x7FFF, fout);
	}
	else
		gbfputuint16(0, fout); /* extra bytes */

	if (wpt->url && *wpt->url) {
		str = xstrdup("_FILE_ ");
		str = xstrappend(str, wpt->url);
		str = xstrappend(str, "\n");
	}
	else str = xstrdup("");
	
	cx = wpt->notes;
	if (cx == NULL) cx = wpt->description;
	if (cx != NULL) {
		char *kml = NULL;
		
		if (strcmp(wpt->session->name, "kml") == 0) {
			utf_string tmp;

			tmp.utfstring = cx;
			tmp.is_html = 1;
			cx = kml = strip_html(&tmp);
		}
		str = xstrappend(str, cx);
		if (kml) xfree(kml);
	}
	mmo_writestr(str);
	xfree(str);
	
	gbfputuint32(0x01, fout);
	if WAYPT_HAS(wpt, proximity) gbfputflt((int) wpt->proximity, fout);
	else gbfputflt(0, fout);