Map dumps

This dumps the map in an ASCII file, that is exchangeable between different versions. The format has stabilized, so this isn�t strictly neccesary, but I left it in anyway. To save memory, this could be separated out.

I would prefer an xml based format. The export wouldn�t be very hard, but an xml parser on the palm seems very unlikely, so importing wouldn�t be possible. «*»= void dump(Map *map) int i,j,k; char vbuf[255],*buf,*sbuf; Item *it; VoidHand RecHandle; Ptr RecPointer; Section *sec; UInt index=0; LocalID id; DmOpenRef mapDB;

ensureAllSectionsLoaded(map);

StrPrintF(vbuf,"

if( (id=DmFindDatabase(0,vbuf)) != 0) FrmCustomAlert(ErrorDialog,"Database exists","",""); return;

if(DmCreateDatabase(0,vbuf,APPID,DumpDBType, false)) FrmCustomAlert(ErrorDialog,"Cant create Database","",""); return;

id=DmFindDatabase(0,vbuf); mapDB=DmOpenDatabase(0,id,dmModeReadWrite);

sbuf=buf=MemPtrNew(16384); StrPrintF(buf,"IFmapper buf+=StrLen(buf); StrPrintF(buf,"MAPmap->Name,map->sectionNum, map->version); buf+=StrLen(buf); for(j=0;j<map->sectionNum;j++) sec=&map->sections[j]; StrPrintF(buf,"SECbuf+=StrLen(buf); for(i=0;i<sec->itemNum;i++) it=&sec->items[i]; switch(it->type) case LOCATION: StrPrintF(buf,"LOCit->bounds.topLeft.x, it->bounds.topLeft.y, it->bounds.extent.x, it->bounds.extent.y, it->itemdata.loc.flags, it->itemdata.loc.Name); buf+=StrLen(buf); if(it->itemdata.loc.Desc != NULL && StrLen(it->itemdata.loc.Desc)>0) StrPrintF(buf,"LOCDESC buf+=StrLen(buf); break; case CONNECTION: StrPrintF(buf,"CON 0it->itemdata.con.flags, it->itemdata.con.linetype, it->itemdata.con.vertexnum); buf+=StrLen(buf); for(k=0;k<it->itemdata.con.vertexnum;k++) StrPrintF(buf,"KNOT it->itemdata.con.vertices[k].y); buf+=StrLen(buf); break; case TEXT: StrPrintF(buf,"TEXTit->itemdata.text.anchor.x, it->itemdata.text.anchor.y, it->itemdata.text.xoffset, it->itemdata.text.yoffset, it->itemdata.text.flags, it->itemdata.text.text,127); buf+=StrLen(buf); break; if(buf-sbuf>15000) RecHandle=DmNewRecord(mapDB,&index,buf-sbuf+1); RecPointer=MemHandleLock(RecHandle); DmWrite(RecPointer,0,sbuf,buf-sbuf+1); buf=sbuf; index++;

RecHandle=DmNewRecord(mapDB,&index,buf-sbuf+1); RecPointer=MemHandleLock(RecHandle); DmWrite(RecPointer,0,sbuf,buf-sbuf+1); MemHandleUnlock(RecHandle); DmReleaseRecord(mapDB,index,true);

MemPtrFree(sbuf); DmCloseDatabase(mapDB);

static char * FindEOL(char *s) return(StrChr(s,''));

static char * FindDelim(char *s) while(*s!=' ' && *s !='') s++; return(s);

static int ReadInt(char *s) char numbuf[20]; char *end;

end=FindDelim(s);

StrNCopy(numbuf,s,end-s); numbuf[end-s]=''; return(StrAToI(numbuf));

static char * ReadString(char *source, char *dest) char *end;

end=FindDelim(source); while(source < end) *dest=*source; source++; dest++; *dest=''; return(end);

Map * import(char *fname) char vbuf[255],*buf,*sbuf,testbuf[60]; Item *it=NULL; VoidHand RecHandle; Section *sec=NULL; UInt index=0,recnum,curvertex=0; LocalID id; DmOpenRef mapDB; Map *map=NULL; int cursec=-1; UInt version=0;

if( (id=DmFindDatabase(0,fname)) == 0) FrmCustomAlert(ErrorDialog,"Database",fname," not found"); return(NULL);

mapDB=DmOpenDatabase(0,id,dmModeReadWrite); recnum=DmNumRecords(mapDB);

for(index=0;index<recnum;index++) RecHandle=DmGetRecord(mapDB,index); buf=MemHandleLock(RecHandle); while(*buf!='') buf=ReadString(buf,vbuf)+1; if(StrCompare(vbuf,"IFmapper")==0) version=ReadInt(buf); buf=FindEOL(buf)+1; if(StrCompare(vbuf,"MAP")==0) map=MemPtrNew(sizeof(Map)); if(StrCompare(vbuf,"MAPNAME")==0) sbuf=FindEOL(buf); map->Name=MemPtrNew(sbuf-buf+1); StrNCopy(map->Name,buf,sbuf-buf); map->Name[sbuf-buf]=''; buf=sbuf+1; if(StrCompare(vbuf,"SECS")==0) map->sectionNum=ReadInt(buf); map->sections=MemPtrNew(map->sectionNum*sizeof(Section)); buf=FindEOL(buf)+1; if(StrCompare(vbuf,"VER")==0) map->version=ReadInt(buf)-1; buf=FindEOL(buf)+1; if(StrCompare(vbuf,"SEC")==0) ++cursec; sec=&map->sections[cursec]; sec->itemNum=0; sec->si.xoffset=0; sec->si.yoffset=0; sec->si.scale=8; sec->si.gridsize=2; if(StrCompare(vbuf,"SECNAME")==0) sbuf=FindEOL(buf); sec->Name=MemPtrNew(sbuf-buf+1); StrNCopy(sec->Name,buf,sbuf-buf); sec->Name[sbuf-buf]=''; buf=sbuf+1; if(StrCompare(vbuf,"ITEMS")==0) buf=FindEOL(buf)+1; if(StrCompare(vbuf,"LOC")==0) it=NewItem(sec);

StrPrintF(testbuf,"WinDrawChars(testbuf,StrLen(testbuf),10,120);

InitLocation(it); if(StrCompare(vbuf,"LOCBOUNDS")==0) it->bounds.topLeft.x=ReadInt(buf); buf=FindDelim(buf)+1; it->bounds.topLeft.y=ReadInt(buf); buf=FindDelim(buf)+1; it->bounds.extent.x=ReadInt(buf); buf=FindDelim(buf)+1; it->bounds.extent.y=ReadInt(buf); buf=FindEOL(buf)+1; if(StrCompare(vbuf,"LOCFLAGS")==0) it->itemdata.loc.flags=ReadInt(buf); buf=FindEOL(buf)+1; if(StrCompare(vbuf,"LOCNAME")==0) sbuf=FindEOL(buf); it->itemdata.loc.Name=MemPtrNew(sbuf-buf+1); StrNCopy(it->itemdata.loc.Name,buf,sbuf-buf); it->itemdata.loc.Name[sbuf-buf]=''; buf=sbuf+1; if(StrCompare(vbuf,"LOCDESC")==0) for(sbuf=buf;*sbuf!=127;sbuf++) ; it->itemdata.loc.Desc=MemPtrNew(sbuf-buf+1); StrNCopy(it->itemdata.loc.Desc,buf,sbuf-buf); it->itemdata.loc.Desc[sbuf-buf]=''; buf=sbuf+2; if(StrCompare(vbuf,"CON")==0) it=NewItem(sec); InitConnection(it); if(StrCompare(vbuf,"CONFLAGS")==0) it->itemdata.con.flags=ReadInt(buf); buf=FindEOL(buf)+1; if(StrCompare(vbuf,"LINETYPE")==0) it->itemdata.con.linetype=ReadInt(buf); buf=FindEOL(buf)+1; if(StrCompare(vbuf,"KNOTNUM")==0) it->itemdata.con.vertexnum=ReadInt(buf); buf=FindEOL(buf)+1; it->itemdata.con.vertices=MemPtrNew(it->itemdata.con.vertexnum*sizeof(Vertex)); curvertex=0; if(StrCompare(vbuf,"KNOT")==0) it->itemdata.con.vertices[curvertex].x=ReadInt(buf); buf=FindDelim(buf)+1; it->itemdata.con.vertices[curvertex].y=ReadInt(buf); buf=FindEOL(buf)+1; curvertex++; if(StrCompare(vbuf,"TEXT")==0) it=NewItem(sec); InitText(it); if(StrCompare(vbuf,"TEXTPOS")==0) it->itemdata.text.anchor.x=ReadInt(buf); buf=FindDelim(buf)+1; it->itemdata.text.anchor.y=ReadInt(buf); buf=FindEOL(buf)+1; if(StrCompare(vbuf,"TEXTOFF")==0) it->itemdata.text.xoffset=ReadInt(buf); buf=FindDelim(buf)+1; it->itemdata.text.yoffset=ReadInt(buf); buf=FindEOL(buf)+1; if(StrCompare(vbuf,"TTEXT")==0) for(sbuf=buf;*sbuf!=127;sbuf++) ; it->itemdata.text.text=MemPtrNew(sbuf-buf+1); StrNCopy(it->itemdata.text.text,buf,sbuf-buf); it->itemdata.text.text[sbuf-buf]=''; buf=sbuf+2; MemHandleUnlock(RecHandle); DmReleaseRecord(mapDB,index,true); DmCloseDatabase(mapDB); return(map); @