safiles.c

来自「这是经典的卫星编程应用程序」· C语言 代码 · 共 1,588 行 · 第 1/3 页

C
1,588
字号
		for(i=1;i<=waypoints;i++) {
			fill_waypoint_from_push(i,NORMAL_WP,0);
			sa3out_w();
		}
	}

	if(tracks&&draw_track_lines) {
		for(i=1;i<=tracks;i++) {
			fill_track(i,0);
			sa3out_w();
		}
	}
	if(draw_route_1_19_obj || draw_route_0_obj){
		for(i=0;i<=MAXROUTES;i++) {
			route_number=i;
			if(route_push[i][1]!=NULL) {
				out_sa_route(i,2);
			}
		}
	}
	fwrite(&Trailer,16,1,out);
	fclose(out);
} /* output_sa3 */

/* -------------------------------------------------------------------------- */
PROCX void readMapText(FILE *in)
{
	fread(&sa3text,13,1,in);
	if(sa3text.paramlen) {
		ChkFree(genConst);
		if((genConst=(unsigned char *)malloc(sa3text.paramlen+1)) == NULL) oomem("readMapText");
		fread(genConst,sa3text.paramlen,1,in);
	}
/*
 * read rest of text
 */
	fread(&sa3text.TextSize,5,1,in);

	record.la=fm_diskLL(sa3text.latR);
	record.lo=-fm_diskLL(sa3text.lonR);
	set_ns();

	record.type='W'; /* waypoints for all for now */
	ChkFree(sa3text.Text);
 	if((sa3text.Text=(unsigned char *)malloc(sa3text.TextLen+1)) ==NULL)  oomem("readMapText1");
	fread(sa3text.Text,sa3text.TextLen,1,in);
	sa3text.Text[sa3text.TextLen]=0;
	get_name_desc((char*)sa3text.Text,0,1,0);
	trim(record.ident);
	trim(record.comment);
	sprintf(Text,"%c;0;%s;%s",record.type,record.ident,record.comment);
	trim(Text);
	strupr(Text);
	push_waypoint();
} /* readMapText */

/* -------------------------------------------------------------------------- */
PROCX void readMapSymbol(FILE *in)
{
	char b[100],*p;
	INT i;

	symb=SA_SYMBOL;
	fread(&sa3symbol,13,1,in);
	if(sa3symbol.paramlen) {
		ChkFree(genConst);
		if((genConst=(unsigned char *)malloc(sa3symbol.paramlen+1)) == NULL) oomem("readMapSymbol");
		fread(genConst,sa3symbol.paramlen,1,in);
	}
/*
 * read rest of symbol
 */
	fread(&sa3symbol.ObjCode,13,1,in);
	record.la=sa3symbol.lat=fm_diskLL(sa3symbol.latR);
	record.lo=sa3symbol.lon=-fm_diskLL(sa3symbol.lonR);
	set_ns();

	record.icon_smbl=(short)from_sa3object((BYTE)ObjCode=(BYTE)sa3symbol.ObjCode);
	ObjSize=sa3symbol.ObjSize;
	ObjColor=sa3symbol.ObjColor;
	TextSize=sa3symbol.TextSize;
	TextColor=sa3symbol.TextColor;
	TextAlign=sa3symbol.TextAlign;
	record.icon_dspl=3;  // default to sym&name

	record.type='W'; /* waypoints for all for now */
	ChkFree(sa3symbol.Text);
 	if((sa3symbol.Text=(unsigned char *)malloc(sa3symbol.TextLen+1)) == NULL) oomem("readMapSymbol1");
	fread((char*)sa3symbol.Text,sa3symbol.TextLen,1,in);
	sa3symbol.Text[sa3symbol.TextLen]=0;
	strcpy(b,(char*)sa3symbol.Text);
	if(sa3symbol.Text[0]=='('&&sa3symbol.Text[6]==')' ) {

		p=strtok3(&b[1],":");
		route_number=atoi(p);

		p=strtok3(NULL,")");
		route_point=atoi(p)-1;
		if(route_point==0) i=1;
		else i=0;
		get_name_desc((char*)&sa3symbol.Text[7],i,0,1);
		trim(record.ident);
		trim(record.comment);
		sprintf(Text,"%c;0;%s;%s",record.type,record.ident,record.comment);
		strupr(Text);
		strcpy(b,Text);
		push_route();
		strcpy(Text,b);
		push_waypoint();
		return;
	}
	get_name_desc((char*)sa3symbol.Text,0,0,1);
	trim(record.ident);
	trim(record.comment);
	if(stricmp(record.ident,"Icon") == 0) {
		record.type='I';
		sprintf(Text,"%c;%d;%s;%s",record.type,20001+icons,record.ident,record.comment);
		strupr(Text);
		push_icon();
	}
	else {
		sprintf(Text,"%c;0;%s;%s",record.type,record.ident,record.comment);
		strupr(Text);
		push_waypoint();
	}
} /* readMapSymbol */

/* -------------------------------------------------------------------------- */
PROCX void readMapNote(FILE *in)
{
	INT i;
	fread(&sa3mapnote,13,1,in);
	if(sa3mapnote.paramlen) {
		ChkFree(genConst);
		if((genConst=(unsigned char *)malloc(sa3mapnote.paramlen+1)) == NULL) oomem("readMapNote");
		fread(genConst,sa3mapnote.paramlen,1,in);
	}
/*
 * read rest of mapnote
 */
	fread(&sa3mapnote.TextSize,11,1,in);

	record.la=sa3mapnote.lat=fm_diskLL(sa3mapnote.latR);
	record.lo=sa3mapnote.lon=-fm_diskLL(sa3mapnote.lonR);
	set_ns();

	record.type='W'; /* waypoints for all for now */
	ChkFree(sa3mapnote.Text);
 	if((sa3mapnote.Text=(unsigned char *)malloc(sa3mapnote.TextLen+1)) == NULL) oomem("readMapNote1");
	fread(sa3mapnote.Text,sa3mapnote.TextLen,1,in);
	sa3mapnote.Text[sa3mapnote.TextLen]=0;
	get_name_desc((char*)sa3mapnote.Text,0,1,1);
	trim(record.ident);
	trim(record.comment);
	sprintf(Text,"%c;0;%s;%s",record.type,record.ident,record.comment);
	for(i=0;i<(INT)strlen(Text);i++) if(Text[i]<32) Text[i]='-';
	strupr(Text);
	push_waypoint();
} /* readMapNote */

/* -------------------------------------------------------------------------- */
/*
 * sa4 lines are considered tracks by g7to
 */
PROCX void readMapLine(FILE *in)
{
	INT i;

	symb=SA_TRACK;
	fread(&sa4mapline,13,1,in);
	if(sa4mapline.paramlen) {
		ChkFree(genConst);
		if((genConst=(unsigned char *)malloc(sa4mapline.paramlen+1)) == NULL) oomem("readMapLine");
		fread(genConst,sa4mapline.paramlen,1,in);
	}
	fread(&sa4mapline.LineColor,8,1,in);

	record.la=fm_diskLL(sa4mapline.latR);
	record.lo=-fm_diskLL(sa4mapline.lonR);
	set_ns();

	LineColor=sa4mapline.LineColor;
	LineWidth=sa4mapline.LineWidth;
	LineStyle=sa4mapline.LineStyle;

	for(i=0;i<sa4mapline.Points;i++) {
		record.comment[0]=0;
		record.ident[0]=0;
		record.type='T'; /* lines are all Tracks for now */
		fread(&sa4mapline,8,1,in);
		record.la=fm_diskLL(sa4mapline.latR);
		record.lo=-fm_diskLL(sa4mapline.lonR);
		set_ns();
		if(i==0) {
			record.type='N';
		}
		sprintf(Text,"%c;0;%s;%s",record.type,record.ident,record.comment);
		trim(Text);
		strupr(Text);
		push_track();
	}
} /* readMapLine */

/* -------------------------------------------------------------------------- */
PROCX void readMapArea(FILE *in)
{
	INT i;

	symb=SA_TRACK;
	fread(&sa4maparea,13,1,in);
	if(sa4maparea.paramlen) {
		ChkFree(genConst);
		if((genConst=(unsigned char *)malloc(sa4maparea.paramlen+1)) == NULL) oomem("readMapArea");
		fread(genConst,sa4maparea.paramlen,1,in);
	}
	fread(&sa4maparea.area_draw_line,16,1,in);

	record.la=sa4maparea.lat=fm_diskLL(sa4maparea.latR);
	record.lo=sa4maparea.lon=-fm_diskLL(sa4maparea.lonR);
	set_ns();

	LineColor=sa4maparea.LineColor;
	LineWidth=sa4maparea.LineWidth;

	for(i=0;i<sa4maparea.Points;i++) {
		record.ident[0]=0;
		record.comment[0]=0;
		record.type='T'; /* lines are all Tracks for now */
		fread(&sa4maparea,8,1,in);
		record.la=fm_diskLL(sa4maparea.latR);
/*
 * swap E/W because SA stores long as + for W and - for E
 */
		record.lo=-fm_diskLL(sa4maparea.lonR);
		set_ns();
		if(i==0) {
			record.type='N';
		}
		sprintf(Text,"%c;0;%s;%s",record.type,record.ident,record.comment);
		trim(Text);
		strupr(Text);
		push_track();
	}
} /* readMapArea */

/* -------------------------------------------------------------------------- */
PROCX void readMapCircle(FILE *in)
{
	double h1,h2;

	fread(&sa4mapcircle,13,1,in);
	if(sa4mapcircle.paramlen>0) {
		ChkFree(genConst);
		if((genConst=(unsigned char *)malloc(sa4mapcircle.paramlen+1)) == NULL) oomem("readMapCircle");
		fread(genConst,sa4mapcircle.paramlen,1,in);
	}
	fread(&sa4mapcircle.area_draw_line,32,1,in);
	symb=SA_CIRCLE;

	mapCir++;
	sprintf(record.ident,"PROX%02d",mapCir);
	record.ident[15]=0;
	record.la=fm_diskLL(sa4mapcircle.latR);
	record.lo=-fm_diskLL(sa4mapcircle.lonR);
	set_ns();
	h1=fm_diskLL(sa4mapcircle.latPnt);
	h2=fm_diskLL(sa4mapcircle.lonPnt);
//
// I believe the fudge factor is necessary because SA4 appears to
//   have 1 minute of latitude be equal to approximately 1855.32 meters,
//   not 1852 meters
//
	record.ProxDist=
		distance(h1,h2,record.la,record.lo)*1855.322236;
	g45type=PROXIMITY;
	proximity=1;
	record.comment[0]=0;
	record.type='P'; 
/*
 * swap E/W because SA stores long as + for W and - for E
 */
	CirLineDraw=sa4mapcircle.area_draw_line;
	CirFillArea=sa4mapcircle.area_draw_fill;
	CirLineColor=sa4mapcircle.LineColor;
	CirLineWidth=sa4mapcircle.LineWidth;
	CirFillColor=sa4mapcircle.area_fill_color;
	CirFillStyle=sa4mapcircle.area_fill_style;
	sprintf(Text,"%c;0;%s;%s",'P',record.ident,record.comment);
	trim(Text);
	strupr(Text);
	push_proximity();
} /* readMapCircle */

/* -------------------------------------------------------------------------- */
/*
 * read a SA4/SA5 route 0
 *
 */
PROCX void readMapRoute(FILE * in)
{
	INT i,rtepts=0;
	char b[MAX_LENGTH];
	unsigned long NumObjsL;
	struct RECORD save;
	char *p;
/*
 * read the unknown 44 bytes before routes
 */
	i=fread(&MapConstM,44,1,in);
	if(i<1) return;

/*
 * read the first part of the route start/stop
 */
	if(intype==SA6) {
 		i=fread(&sa4route,32,1,in);
	}
	else {
 		i=fread(&sa4route,28,1,in);
	}
	if(i<1) return;
	if(sa4route.startLo == 0) {
		return;
	}
	record.la = fm_diskLL(sa4route.startLa);
	record.lo = -fm_diskLL(sa4route.startLo);
	set_ns();
	record.type='W';
	fread(&ZeroL,4,1,in);
	strcpy(record.comment,"ROUTE0 START");
/*
 * read start name/state
 */
	if(ZeroL) {
		fread(b,(int)ZeroL,1,in);
		strcpy(route_comment,trim(b));
	}
	else route_comment[0]=0;
	record.ident[0]=record.comment[0]=0;
	fread(&ZeroL,4,1,in);
	if(ZeroL) {
		fread(b,(int)ZeroL,1,in);
		p=strtok(b,";");
		if(p!=NULL) strncpy(record.ident,p,15);
		p=strtok(b,";");
		if(p!=NULL) strncpy(record.comment,p,40);
	}
//
//  save first route point as 'Start'
//
 	route_number=0;
	route_point=0;
	if(record.ident[0]==0) strcpy(record.ident,"START");
	sprintf(Text,"%c;0;%s;%s",record.type,record.ident,record.comment);
	trim(Text);
	set_record_icon();
	strcpy(b,Text);
	push_route();
	strcpy(Text,b);
	push_waypoint();
/*
 * read route finish data
 */
	if(intype==SA6) {
		i=fread(&sa4route.finishLo,32,1,in);
	}
	else {
		i=fread(&sa4route.finishLo,28,1,in);
	}
	record.la = fm_diskLL(sa4route.finishLa);
	record.lo = -fm_diskLL(sa4route.finishLo);
/*
 * read finish name/state
 */
	fread(&ZeroL,4,1,in);
	if(ZeroL) {
		fread(b,(int)ZeroL,1,in);
		p=strtok(b,";");
		if(p!=NULL) strncpy(record.ident,p,15);
		p=strtok(b,";");
		if(p!=NULL) strncpy(record.comment,p,40);

		strcpy(save.ident,record.ident);
		save.la=record.la;
		save.lo=record.lo;
		strcpy(save.comment,record.comment);
		strcpy(save.datetime,record.datetime);
		save.type=record.type;
	}
	fread(&ZeroL,4,1,in);
	if(ZeroL) {
		fread(b,(int)ZeroL,1,in);
	}
	fread(&sa4route.NumObjs,4,1,in);

	NumObjsL=sa4route.NumObjs;
/*
 * read intermediate points.
 */
	while(NumObjsL--) {
		rtepts++;
		i=fread(&sa4routepts,28,1,in);
		if(intype==SA6) {
			i=fread(&via,4,1,in);
		}
		fread(&ZeroL,4,1,in);
//
// read route point name
//
		if(ZeroL) {
			fread(b,(int)ZeroL,1,in);
			p=strtok(b,";");
			if(p!=NULL) strncpy(record.ident,p,15);
			p=strtok(b,";");
			if(p!=NULL) strncpy(record.comment,p,40);

			if(stricmp(record.ident,"No Name") == 0) strcpy(record.ident,"STOP");
			strupr(record.ident);
			strupr(record.comment);
		}
//
// read route point state name
//
		fread(&ZeroL,4,1,in);
		if(sa4routepts.st_st_name_l) {
			fread(b,(int)ZeroL,1,in);
		}
		i=0;
/*
 * print intermediate record
 */
		record.la = fm_diskLL(sa4routepts.startLa);
		record.lo = -fm_diskLL(sa4routepts.startLo);
		record.type='W';
		set_ns();
		if(strlen(record.ident)>0) {
			if(stricmp(record.ident,"STOP") ==0) {
				sprintf(record.ident,"S%05d",rtepts);
				strcpy(record.comment," ");
				Sused=rtepts;
				i=1;
			}
		}
		else {
			sprintf(record.ident,"S%05d",rtepts);
			strcpy(record.comment," ");
			Sused=rtepts;
			i=1;
		}
//
// check to see if the name already begins with 'Sxxxxx' where xxxxx is
//  a number.  If so, assume it's a converted STOP record and can be
//  renumbered.
//
		if(i!=1 && record.ident[0]=='S') {
			i=atoi(&record.ident[1]);
			if(i && i<rtepts) {
				sprintf(record.ident,"S%05d",rtepts);
				Sused=rtepts;
			}
		}
		sprintf(Text,"%c;0;%s;%s",record.type,record.ident,record.comment);
		trim(Text);
//		strupr(Text);
		set_record_icon();
		strcpy(b,Text);
		push_route();
		strcpy(Text,b);
		push_waypoint();
	}
//
//  save last route point as 'Start'
//
	strcpy(record.ident,save.ident);
	record.la=		save.la;
	record.lo=		save.lo;
	strcpy(record.comment,save.comment);
	strcpy(record.datetime,save.datetime);
	record.type=	save.type;

	sprintf(Text,"%c;0;%s;%s",record.type,record.ident,record.comment);
	set_ns();
	trim(Text);
	set_record_icon();
	strcpy(b,Text);
	push_route();
	strcpy(Text,b);
	push_waypoint();
} /* readMapRoute */

/* -------------------------------------------------------------------------- */
PROCX void read_sa3(FILE *in)
{
	INT i;
	unsigned char c;
/*
 * Start reading Items here
 */
	for(i=1;i<=NumObjs;i++) {
		set_record_icon();
		fread(&ItemType,2,1,in);
		switch(ItemType) {
			case 1: readMapText(in); break;
			case 2: readMapSymbol(in); break;
			case 3: readMapNote(in); break;
		   	case 7: 
					readMapLine(in); 
					break;
		   	case 8: readMapArea(in); break;
		   	case 9: readMapCircle(in); break;
		   	default:  {
			   fprintf(stderr,"Found a new SA Item: 0x%04x\n",ItemType);
			   for(i=0;i<300;i++) {
				if(fread(&c,1,1,in)==0) {
					fprintf(stderr,"\n");
					return;
				}
				fprintf(stderr,"%02x  ",c);
			   }
			   fprintf(stderr,"\n");
			   return;
		   	}
		}
	}
	if(intype==SA4 || intype==SA5 || intype==SA6) readMapRoute(in);
} /* read_sa3 */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?