Пример #1
0
/* ToDo: move the code inside to CET library */
static char *
psp_read_str(gbfile *fin)
{
	int len;
	gbint16 *buff;
	char *res;
	
	len = (unsigned char)gbfgetc(fin);
	if (len == 0) return NULL;
	
	buff = xmalloc(len * sizeof(*buff));
	gbfread(buff, sizeof(*buff), len, fin);
	res = cet_str_uni_to_utf8(buff, len);
	xfree(buff);

	return res;
}
Пример #2
0
static char *
mmo_readstr(void)
{
	char *res;
	int len;
	
	len = (unsigned)gbfgetc(fin);
	if (len == 0xFF) {
		len = gbfgetint16(fin);
		if (len < 0) fatal(MYNAME ": Invalid string length (%d)!\n", len);
	}
	res = xmalloc(len + 1);
	res[len] = '\0';
	if (len) {
		gbfread(res, len, 1, fin);
		if (len != strlen(res)) fatal(MYNAME ": Error in file structure!\n");
	}

	return res;
}
Пример #3
0
static void
mmo_read_CObjRoute(mmo_data_t *data, const waypoint *add)
{
#ifdef MMO_DBG
	const char *sobj = "CObjRoute";
#endif
	int rtept;
	route_head *rte;
	char buf[16];
	int ux;

	DBG((sobj, ":-----------------------------------------------------\n"));
	DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n", 
		data->name, data->visible ? "yes" : "NO", data->objid));

	data->data = rte = route_head_alloc();
	rte->rte_name = xstrdup(data->name);
	route_add_head(rte);

	ux = gbfgetc(fin);		/* line label */
	DBG((sobj, "line label = %d\n", ux));

	data->left = rtept = gbfgetint16(fin);
	DBG((sobj, "route has %d point(s)\n", rtept));

	if ((data->left <= 0) && (mmo_version >= 0x12)) {
		mmo_fillbuf(buf, 7, 1);
	}

	if (add) {	/* waypoint loaded before route */
		route_add_wpt(rte, waypt_dupe(add));
		data->left--;
	}
	
	while (data->left > 0) {
		(void) mmo_read_object(NULL);
	}
	
	if ((mmo_version > 0x11) && (data->done > 0)) mmo_end_of_route(data);
}
Пример #4
0
static mmo_data_t *
mmo_read_object(const waypoint *add)
{
	int objid;
	mmo_data_t *data = NULL;

	objid = gbfgetuint16(fin);
	if (objid == 0xFFFF) {
		gbuint16 version;
		char *sobj;
		int len;
		
		objid = mmo_object_id++;

		version = gbfgetuint16(fin);
		is_fatal(version != mmo_version, MYNAME ": Invalid version identifier!\n");
		
		len = gbfgetint16(fin);
		
		sobj = xmalloc(len + 1);
		sobj[len] = '\0';
		gbfread(sobj, len, 1, fin);
		
		if (strcmp(sobj, "CObjIcons") == 0) ico_object_id = objid;
		else if (strcmp(sobj, "CCategory") == 0) cat_object_id = objid;
		else if (strcmp(sobj, "CObjWaypoint") == 0) wpt_object_id = objid;
		else if (strcmp(sobj, "CObjRoute") == 0) rte_object_id = objid;
		else if (strcmp(sobj, "CObjTrack") == 0) trk_object_id = objid;
		else if (strcmp(sobj, "CObjCurrentPosition") == 0) pos_object_id = objid;
		else if (strcmp(sobj, "CObjText") == 0) txt_object_id = objid;
		else
			fatal(MYNAME ": Unknown Object \"%s\"!\n", sobj);
		xfree(sobj);
	}

	if (objid & 0x8000) {

		data = mmo_register_object(mmo_object_id++, NULL, 0);
		data->name = mmo_readstr();

		if (objid != cat_object_id) {
			data->ctime = gbfgetuint32(fin);
			data->mtime = gbfgetuint32(fin);
			data->locked = gbfgetc(fin);
			data->visible = gbfgetc(fin);
			(void) gbfgetuint16(fin);
			(void) gbfgetuint16(fin);
		
			if (objid != ico_object_id) mmo_read_category(data);
		}

		if (objid == cat_object_id) ; 	/* do nothing */		
		else if (objid == ico_object_id) mmo_read_CObjIcons(data);
		else if (objid == trk_object_id) {
			data->type = trkdata;
			mmo_read_CObjTrack(data);
		}
		else if (objid == wpt_object_id) {
			data->type = wptdata;
			mmo_read_CObjWaypoint(data);
		}
		else if (objid == rte_object_id) {
			data->type = rtedata;
			mmo_read_CObjRoute(data, add);
		}
		else if (objid == pos_object_id) mmo_read_CObjCurrentPosition(data);
		else if (objid == txt_object_id) mmo_read_CObjText(data);
		else
			fatal(MYNAME ": Unregistered Object-ID 0x%04X\n", objid);
	}
	else data = mmo_get_object(objid);
	
	return data;
}
Пример #5
0
static void
mmo_read_CObjTrack(mmo_data_t *data)
{
#ifdef MMO_DBG
	const char *sobj = "CObjTrack";
#endif
	int tp, ctp;
	route_head *trk;

	DBG((sobj, ":-----------------------------------------------------\n"));
	DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n", 
		data->name, data->visible ? "yes" : "NO", data->objid));

	trk = route_head_alloc();
	trk->rte_name = xstrdup(data->name);
	track_add_head(trk);

	tp = gbfgetint16(fin);
	DBG((sobj, "track has %d point(s)\n", tp));

	for (ctp = 0; ctp < tp; ctp++) {
		waypoint *wpt;
		char unk;
		
		wpt = waypt_new();
		
		wpt->latitude = gbfgetdbl(fin);
		wpt->longitude = gbfgetdbl(fin);
		unk = gbfgetc(fin);
		
		wpt->creation_time = gbfgetint32(fin);
		wpt->altitude = gbfgetflt(fin);

		if (unk != 0) {
			gbuint16 ux;
			ux = gbfgetuint16(fin);
			DBG((sobj, "u16 = %04X (%d)\n", ux, ux));
			if (unk > 1) {
				gbuint16 ux;
				ux = gbfgetuint16(fin);
				DBG((sobj, "u16 = %04X (%d)\n", ux, ux));
			}
		}
		track_add_wpt(trk, wpt);
	}
	
	if (mmo_version > 0) {
		gbuint32 u32;
		
		u32 = gbfgetuint32(fin); 	/* Min. update interval */
		DBG((sobj, "min. update interval = %d\n", u32));
		u32 = gbfgetuint32(fin); 	/* unknown */
//		DBG((sobj, "unknown value = 0x%8X (%d)\n", u32, u32));
		u32 = gbfgetuint32(fin); 	/* unknown */
//		DBG((sobj, "unknown value = 0x%8X (%d)\n", u32, u32));
		u32 = gbfgetuint32(fin); 	/* unknown */
		DBG((sobj, "min. update distance = %d\n", u32));
		u32 = gbfgetuint32(fin); 	/* unknown */
		DBG((sobj, "track partition interval = %d\n", u32 / 60));
		u32 = gbfgetuint32(fin); 	/* unknown */
//		DBG((sobj, "unknown value = 0x%8X (%d)\n", u32, u32));
		u32 = gbfgetuint32(fin); 	/* unknown */
		DBG((sobj, "tick interval = %d\n", u32 / 60));
		trk->line_color.bbggrr = gbfgetuint32(fin); 	/* rgb color */
		trk->line_color.opacity = 255;
		DBG((sobj, "color = 0x%06X\n", trk->line_color.bbggrr));
	}

	if (mmo_version >= 0x12) {
		char u8;
		
		u8 = gbfgetc(fin);
		DBG((sobj, "line width = %d - (since 0x12)\n", u8));
		u8 = gbfgetc(fin);
		DBG((sobj, "line style = %d - (since 0x12)\n", u8));
		u8 = gbfgetc(fin);
		DBG((sobj, "transparency = %d - (since 0x12)\n", u8));
		trk->line_color.opacity = 255 - (u8 * 51);

		if (mmo_version >= 0x16) {
			char u8;
			gbuint16 u16;
			
			u8 = gbfgetc(fin);
//			DBG((sobj, "u8 = 0x%X (since 0x16)\n", u8));
			u16 = gbfgetuint16(fin);
//			DBG((sobj, "u16 = 0x%X (since 0x16)\n", u16));
			u16 = gbfgetuint16(fin);
//			DBG((sobj, "u16 = 0x%X (since 0x16)\n", u16));
		}
	}
	
	if (trk->rte_waypt_ct == 0) {
		track_del_head(trk);
		data->data = NULL;
	}
}
Пример #6
0
static gbuint16
format_garmin_xt_rd_st_attrs(char *p_trk_name, gbuint8 *p_track_color)
{
	int		method = 0;
	gbuint16	trackbytes = 0, TrackPoints = 0;
	gbuint8	spam = 0;
	gbint32		TrackMaxLat = 0, TrackMaxLon = 0, TrackMinLat = 0, TrackMinLon = 0;
	char		trk_name[30]="";
	// TODO: SHIFT - can't test behaviour, do not have appropriate files
	//int		ii;

	// get the option for the processing the track name
	if ( opt_trk_header )
	{
		method = atoi(opt_trk_header);
		// if method is out of range set to default
		if ((method < 0) || (method > 1))
		{
			method = 0;
		}
	}
	// set to RED if not specified
	*p_track_color=9;

	trackbytes = gbfgetuint16(fin);
	TrackPoints = gbfgetuint16(fin);

	switch (method)
	{
		case 1:	break; // IGNORE
			/* TODO: SHIFT - can't test behaviour, do not have appropriate files
			   case 2: { // SHIFTED method
			   spam = gbfgetc(fin);
			   gbfread(&trk_name, 30, DATABLOCKSIZE, fin);
			   gbfseek(fin, -1, SEEK_CUR);
			   for (ii = 0; ii<29; ii++)
			   {
			   trk_name[ii] = (trk_name[ii] >> 2) + ( trk_name[ii+1] % 4 ) * 64;
			   }	
			   }
			   break;
			   */
		default: { // NORMAL
			         spam = gbfgetc(fin);
				 gbfread(&trk_name, 30, DATABLOCKSIZE, fin);
				 gbfseek(fin, -1, SEEK_CUR);
			 }
			break;
	}
	spam = gbfgetc(fin);

	gbfread(&TrackMaxLat, 3, DATABLOCKSIZE, fin);
	gbfread(&spam, 1, DATABLOCKSIZE, fin);
	gbfread(&TrackMaxLon, 3, DATABLOCKSIZE, fin);
	gbfread(&spam, 1, DATABLOCKSIZE, fin);
	gbfread(&TrackMinLat, 3, DATABLOCKSIZE, fin);
	gbfread(&spam, 1, DATABLOCKSIZE, fin);
	gbfread(&TrackMinLon, 3, DATABLOCKSIZE, fin);
	gbfread(p_track_color, 1, DATABLOCKSIZE, fin);
	gbfread(&spam, 1, DATABLOCKSIZE, fin);

	strcpy( p_trk_name, trk_name );
	return trackbytes;
}