📄 safiles.c
字号:
} /* sa4out_p */
/* -------------------------------------------------------------------------- */
//
// output a waypoint read from gardown7 file or text file to
// a SA3/4/5 file.
//
// The representation normal waypoints in a SA Text string is:
//
// name;comment;icon display
//
// and for route waypoints:
//
// (rr:pp)name;comment;icon_display_style;route_name First Point
// (rr:pp)name;comment;icon_display_style all other points
//
// where rr is the 2 digit route number and pp is the 2 digit number representing
// the nth position in the route.
//
PROCX void sa3out_w()
{
char tbuf[25], buffer[256], icds[10], rtname[255], cmnt[255];
INT i, hold, hold1;
set_params(); // set object parameters to current values
sa3symbol.ItemNum=sa3number++;
set_sign();
sa3symbol.latR=to_diskLL(record.la);
sa3symbol.lonR=to_diskLL(-record.lo);
if(sa3symbol.Text != NULL) free(sa3symbol.Text);
sa3symbol.Const=0x8000;
sa3symbol.paramlen=0;
hold1=nameonly;
if(record.type=='I') {
strcpy(record.ident,"Icon");
nameonly=5;
}
trim(record.ident);
record.ident[15]=0;
trim(record.comment);
sa3symbol.ObjCode=to_sa3object(record.icon_smbl);
sprintf(icds,"%d",record.icon_dspl);
trim(icds);
strcpy(cmnt,record.comment);
trim(cmnt);
if(in_route) {
route_point++;
//==============================================================================
//INT nameonly=0; // Handles comment and symbol display options
//
// // 0 - suppress no fields
// // 1 - suppress comment on regular waypoints
// // 2 - suppress comment on route waypoints
// // 4 - suppress symbol display parameter
// // 8 - suppress route name on first route point
// // 16 - suppress the (nn:nn) on all route points
//
//==============================================================================
strcpy(rtname,route_comment);
trim(rtname);
sprintf(tbuf,"(%02d:%02d)",route_number,route_point);
if(nameonly != 0) {
if((nameonly&2) == 2) cmnt[0]=0;
if((nameonly&4) == 4) icds[0]=0;
if((nameonly&8) == 8) rtname[0]=0;
}
if((nameonly&16) == 16) tbuf[0]=0;
if(route_point==1) {
sprintf(buffer,"%s%s;%s;%s;%s",tbuf,record.ident,cmnt,icds,rtname);
}
else {
sprintf(buffer,"%s%s;%s;%s", tbuf,record.ident,cmnt,icds);
}
}
else { // not in a route
hold=noname;
if(draw_route_0_obj==0) {
if(wpt_in_route(record.ident,0)) {
noname=1;
}
}
if(draw_route_1_19_obj==0) {
if(wpt_in_route(record.ident,1)) {
noname=1;
}
}
if(noname) {
buffer[0]=0;
}
else {
if(record.type=='T') {
sprintf((char*)buffer,"%-6d",sa3number);
if(timeonsa3) {
strcat(buffer," ");
strcat(buffer,record.datetime);
}
}
else {
//===============================================================================
//INT nameonly=0; // Handles comment and symbol display options
//
// // 0 - suppress no fields
// // 1 - suppress comment on regular waypoints
// // 2 - suppress comment on route waypoints
// // 4 - suppress symbol display parameter
// // 8 - suppress route name on first route point
// // 16 - suppress the (nn:nn) on all route points
//===============================================================================
if(nameonly != 0) {
if((nameonly&1) == 1) cmnt[0]=0;
if((nameonly&4) == 4) icds[0]=0;
}
sprintf(buffer,"%s;%s;%s",record.ident,cmnt,icds);
}
}
}
trim(buffer);
while(buffer[i=strlen(buffer)-1] == ';') {
buffer[i]=0;
trim(buffer);
}
sa3symbol.Text=(unsigned char *)calloc(strlen(buffer)+1,1);
strcpy((char*)sa3symbol.Text,buffer);
sa3symbol.TextLen=strlen((char*)sa3symbol.Text);
/*
* output the record to the sa file
*/
fwrite(&two,2,1,out);
fwrite(&sa3symbol,26,1,out);
fwrite(sa3symbol.Text, sa3symbol.TextLen,1,out);
noname=hold;
nameonly=hold1;
} /* sa3out_w */
/* -------------------------------------------------------------------------- */
/*
* output a track line element to a SA4 file. This assumes the header
* and first point has already been written.
*/
PROCX void sa4out_t(void)
{
set_sign();
sa4mapline.latR=to_diskLL(record.la);
sa4mapline.lonR=to_diskLL(-record.lo);
fwrite(&sa4mapline,8,1,out);
} /* sa4out_t */
/* -------------------------------------------------------------------------- */
/*
* Output a Line header & first point of the track to an SA4 file
*/
PROCX void sa4out_th(INT draw_route_l)
{
INT ItemType=7;
sa4mapline.ItemNum=sa3number++;
set_sign();
sa4mapline.latR=to_diskLL(record.la);
sa4mapline.lonR=to_diskLL(-record.lo);
sa4mapline.Const1=0x8000;
sa4mapline.paramlen=0;
if(draw_route_l>=1) {
sa4mapline.LineColor=Route_LineColor;
sa4mapline.LineWidth=Route_LineWidth;
sa4mapline.LineStyle=Route_LineStyle;
sa4mapline.Points=draw_route_l;
}
else {
sa4mapline.LineColor=LineColor;
sa4mapline.LineWidth=LineWidth;
sa4mapline.LineStyle=LineStyle;
sa4mapline.Points=trks[trk_seg];
}
fwrite(&ItemType,2,1,out);
fwrite(&sa4mapline,21,1,out);
fwrite(&sa4mapline,8,1,out);
} /* sa4out_th */
/* -------------------------------------------------------------------------- */
PROCX void output_sa4_route0()
{
INT i;
char b[MAX_LENGTH];
char b1[MAX_LENGTH];
char *p, *p1, *all, *rest;
INT hdr,points;
in_route=hdr=1;
points=0;
/*
* Draw lines for the route if the output is SA5 or SA6. SA4 draws the
* lines for you. This must be done first because it is made up
* of draw objects and they must be sent to the sa file before the
* route 0 data
*/
if((s6o || s5o) && draw_route_0_line==1) {
for(i=1;i<=routeXpts[0];i++) {
if(route_push[0][i] == NULL) continue;
points++;
}
for(i=1;i<=routeXpts[0];i++) {
route_point=i-1;
if(route_push[0][i] == NULL) continue;
strcpy((char*)bin,route_push[0][i]);
if(i==1) fill_waypoint_from_push(i,ROUTE_1_WP,0);
else fill_waypoint_from_push(i,ROUTE_WP,0);
if(hdr) {
sa4out_th(points);
hdr=0;
}
else {
sa4out_t();
}
}
}
/*
* Handle route 0 as a SA4 route
*
* the route info is saved in array route_push[0][1-x]
'W;HW138;ROSEBURG HWY183;ROSEBURG TO WINSTON;Mon Jun 09 16:47:38 1997!43.215017;123.356743;12;0;3;1;2;2;'
'W;WINEXT;I5-WINSTON EXIT;Mon Jun 09 16:47:38 1997!43.167600;123.366990;12;0;3;1;2;2;'
'W;WINSTN;HWY99-HWY42;Mon Jun 09 16:47:38 1997!43.122100;123.413527;12;0;3;1;2;2;'
*/
if(s6o) MapConstM.u=0x8E7F;
else MapConstM.u=0x8E7E;
fwrite(&MapConstM,44,1,out);
strcpy(b,route_push[0][1]); // This point should be named: "Start"
record.type=b[0];
all=strtok3(b,";");
all=strtok3(NULL,";");
all=strtok3(NULL,"!");
rest=strtok3(NULL,"*");
p1=strdup(route_comment);
get_name_desc(all,1,0,0);
strcpy(route_comment,p1);
free(p1);
record.la=atof(strtok3(rest,";"));
record.lo=atof(strtok3(NULL,";"));
set_ns();
if(strlen(route_comment)==0) strcpy(route_comment," ");
sa4route.startLa=sa4route.startLa1=to_diskLL(record.la);
sa4route.startLo=sa4route.startLo1=to_diskLL(-record.lo);
sa4route.unk1=sa4route.unk2=sa4route.unk3=
sa4route.unk4=sa4route.unk5=sa4route.unk6=0;
sprintf(b1,"%s;%s;",record.ident,record.comment);
fwrite(&sa4route,28,1,out);
ZeroL=0;
if(s6o) fwrite(&ZeroL,4,1,out); //write an extra 4 0's
//
// Write the route name (route_comment) as the first field and the first waypoint name
// concatonated with the first waypoint comment i.e.: name;comment;
// in as the second field
//
ZeroL=strlen(route_comment);
fwrite(&ZeroL,4,1,out); // write comment length
fwrite(route_comment,(int)ZeroL,1,out); // Write route comment bytes
ZeroL=strlen(b1);
fwrite(&ZeroL,4,1,out); // write comment length
fwrite(b1,(int)ZeroL,1,out);
//
// do finish point
//
strcpy(b,route_push[0][route0]);
record.type=b[0];
all=strtok3(b,";");
all=strtok3(NULL,";");
all=strtok3(NULL,"!");
rest=strtok3(NULL,"*");
get_name_desc(all,0,0,0);
record.la=atof(strtok3(rest,";"));
record.lo=atof(strtok3(NULL,";"));
set_ns();
sa4route.startLa=sa4route.startLa1=to_diskLL(record.la);
sa4route.startLo=sa4route.startLo1=to_diskLL(-record.lo);
sa4route.unk1=sa4route.unk2=sa4route.unk3=
sa4route.unk4=sa4route.unk5=sa4route.unk6=0;
sprintf(b1,"%s;%s;",record.ident,record.comment);
fwrite(&sa4route,28,1,out);
if(s6o) fwrite(&ZeroL,4,1,out); //write an extra 4 0's
//
// Write the first field as the name;comment;
//
ZeroL=strlen(b1);
fwrite(&ZeroL,4,1,out);
fwrite(b1,(int)ZeroL,1,out);
//
// The 2nd field is zero, so the length word is all we need
//
ZeroL=0;
fwrite(&ZeroL,4,1,out);
//
// setup for internal points
//
ZeroL=(long)route0-2;
fwrite(&ZeroL,4,1,out);
ZeroL=0L;
//
// output each point.
//
for(i=2;i<route0;i++) {
strcpy(b,route_push[0][i]);
record.type=b[0];
p1=p=strdup(b);
p=strtok3(p,";");
p=strtok3(NULL,";");
p=strtok3(NULL,"!");
get_name_desc(p,0,0,0);
sprintf(b1,"%s;%s;",record.ident,record.comment);
free(p1);
all=strtok3(b,"!");
record.la=atof(strtok3(NULL,";"));
record.lo=atof(strtok3(NULL,";"));
set_ns();
sa4routepts.startLa=sa4routepts.startLa1=to_diskLL(record.la);
sa4routepts.startLo=sa4routepts.startLo1=to_diskLL(-record.lo);
sa4routepts.checksum=sa4routepts.startLa+sa4routepts.startLo;
sa4routepts.unk3=sa4routepts.unk4=sa4routepts.unk5=
sa4routepts.unk6=0;
// Route waypoint record
// W;0;226TRN;HWY 20-126;Mon Jul 27 05:06:06 1998!44.471303;122.135187;0;0;0;0;2;2;18;3;0;1;0;0;0;
p=strtok3(NULL,";"); // skip a bunch
p=strtok3(NULL,";"); // skip a bunch
p=strtok3(NULL,";"); // skip a bunch
p=strtok3(NULL,";"); // skip a bunch
p=strtok3(NULL,";"); // skip a bunch
p=strtok3(NULL,";"); // skip a bunch
p=strtok3(NULL,";"); // skip a bunch
p=strtok3(NULL,";"); // skip a bunch
p=strtok3(NULL,";"); // skip a bunch
p=strtok3(NULL,";"); // skip a bunch
p=strtok3(NULL,";"); // skip a bunch
p=strtok3(NULL,";"); // skip a bunch
via=0;
p=strtok3(NULL,";"); // get Via
if(p!=NULL) via=atol(p);
fwrite(&sa4routepts,28,1,out);
if(s6o) fwrite(&via,4,1,out); // Via or Stop?
trim(b1);
sa4routepts.st_name_l=strlen(b1);
fwrite(&sa4routepts.st_name_l,4,1,out);
fwrite(b1,(int)sa4routepts.st_name_l,1,out);
fwrite(&ZeroL,4,1,out);
}
fwrite(&MapConstM0,12,1,out);
} /* output_sa4_route0 */
/* -------------------------------------------------------------------------- */
PROCX void out_sa_route(INT rtno,INT type)
{
INT i,hdr,points;
in_route=hdr=1;
points=0;
for(i=1;i<=routeXpts[rtno];i++) {
route_point=i-1;
if(route_push[rtno][i] == NULL) continue;
points++;
strcpy((char*)bin,route_push[rtno][i]);
if(i==1) fill_waypoint_from_push(i,ROUTE_1_WP,0);
else fill_waypoint_from_push(i,ROUTE_WP,0);
if((type==0)&&(rtno==0)&&draw_route_0_obj) sa3out_w();
if((type==1)&&(rtno!=0)&&draw_route_1_19_obj) sa3out_w();
if((type==2)&&(draw_route_1_19_obj || draw_route_0_obj)) sa3out_w();
}
if(rtno!=0 && (s4o || s5o || s6o) && draw_route_1_19_lines) {
for(i=1;i<=routeXpts[rtno];i++) {
route_point=i-1;
if(route_push[rtno][i] == NULL) continue;
strcpy((char*)bin,route_push[rtno][i]);
if(i==1) fill_waypoint_from_push(i,ROUTE_1_WP,0);
else fill_waypoint_from_push(i,ROUTE_WP,0);
if(hdr) {
sa4out_th(points);
hdr=0;
}
else {
sa4out_t();
}
}
}
in_route=0;
} /* out_sa_route */
/* -------------------------------------------------------------------------- */
PROCX void output_sa4()
{
unsigned INT i;
INT nr;
long zero=0;
//
// Calculate the number of objects we're going to write to the file
//
nr=(draw_track_lines==1)*s4o_trk_recs+
icons +
(draw_waypoints==1)*waypoints +
(draw_route_1_19_obj==1)*routes -
((draw_route_0_obj==0)&&(draw_route_1_19_obj==1))*route0 +
((draw_route_1_19_obj==0) && (draw_route_0_obj==1))*route0 +
(draw_prox_circles==1)*proximityp +
(draw_route_1_19_lines==1)*route_lines;
if((s6o || s5o) && routeXpts[0]>1 && draw_route_0_line==1) nr++;
if(nr==0) {
fclose(out);
unlink(fname_out_all);
fprintf(stderr,"No output to: %s, file skipped.\n",fname_out_all);
return;
}
output_sa3hdr(); // opens file and outputs header string
fwrite(&nr,2,1,out);
if(icons) {
for(i=1;i<=icons;i++) {
fill_icon(i,(unsigned char *)"",0);
sa3out_w();
}
}
if(waypoints&&draw_waypoints) {
for(i=1;i<=waypoints;i++) {
fill_waypoint_from_push(i,NORMAL_WP,0);
sa3out_w();
}
}
if(proximityp&&draw_prox_circles) {
for(i=1;i<=proximityp;i++) {
fill_waypoint_from_push(i,PROX_WP,0);
sa4out_p();
}
}
trk_seg=0;
if(tracks&&draw_track_lines) {
for(i=1;i<=tracks;i++) {
fill_track(i,0); // also sets chch
if(chch=='N') {
if(cycle_track_colors) {
if(++MyColor>4) MyColor=0;
LineColor=MyColor;
}
trk_seg++;
sa4out_th(0);
}
else sa4out_t();
}
}
if(draw_route_0_obj==1) {
for(i=0;i<1;i++) {
route_number=i;
if(route_push[i][1]!=NULL) {
out_sa_route(i,0);
}
}
}
if(draw_route_1_19_obj==1 || draw_route_1_19_lines) {
for(i=1;i<=MAXROUTES;i++) {
route_number=i;
if(route_push[i][1]!=NULL) {
out_sa_route(i,1);
}
}
}
//
// route 0 must be done here
//
if((routeXpts[0]>0) && (draw_route_0==1)) {
output_sa4_route0();
}
else {
if(s6o) MapConstM.u=0x8E7F;
else MapConstM.u=0x8E7E;
fwrite(&MapConstM,44,1,out);
fwrite(&MapConstM0,44,1,out);
fwrite(&MapConstM0,44,1,out);
}
if(s5o || s6o) {
if(s6o) {
fwrite(&zero,4,1,out);
fwrite(&zero,4,1,out);
fwrite(&Trailersa6, 9, 1,out);
}
else {
fwrite(&Trailersa6, 9, 1,out);
// fwrite(&Trailer1a,26,1,out);
// fwrite(Trailer1,15,1,out);
// fwrite(&Trailer1x,22,1,out);
}
}
fclose(out);
} /* output_sa4 */
/* -------------------------------------------------------------------------- */
PROCX void output_sa3()
{
INT i,nr;
nr=(draw_track_lines==1)*tracks +
(draw_waypoints==1)*waypoints +
((draw_route_1_19_obj==1)||(draw_route_0==1))*routes;
if(nr==0) {
fclose(out);
unlink(fname_out_all);
fprintf(stderr,"No output to: %s, file skipped.\n",fname_out_all);
return;
}
output_sa3hdr(); // opens file and outputs header string
fwrite(&nr,2,1,out);
if(waypoints&&draw_waypoints) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -