Scanning of maps and dumps

«*»= void ScanMaps() Err error; DmSearchStateType stateInfo; UInt card; LocalID dbID; UInt numPr=0; DmOpenRef mapDB; int sections,recnum; VoidHand RecHandle; Map *dbMap;

«Check how many maps are available» «Alloc memory for map entries» «Read map entries»

SortNamelist(MapList); @

This walks through the list of databases by repeatedly calling [[DmGetNextDatabaseByTypeCreator]] until an error is encountered (i.e. no more databases of appropriate type). «Check how many maps are available»= error=DmGetNextDatabaseByTypeCreator(true,&stateInfo, MapDBType,APPID, false, &card,&dbID);

while(error == 0) numPr++; error=DmGetNextDatabaseByTypeCreator(false,&stateInfo, MapDBType,APPID, false, &card,&dbID); @

First the old name list is freed, and then [[numPr]] entries are alloced. «Alloc memory for map entries»= FreeNameListMem(&MapList); MapList.numEntries=numPr; AllocNameListMem(&MapList); @

Now the second pass is started and the relevant information (map name, number of sections and number of objects) is picked up and saved in the [[MapList]]. «Read map entries»= if(numPr>0) numPr=0; while(DmGetNextDatabaseByTypeCreator((numPr==0),&stateInfo, MapDBType,APPID, false, &card,&dbID) ==0) «Read map name» «Read map info» @

The map name is read via [[DmDatabaseInfo]]. Note that almost all the parameters are [[NULL]], which is equivalent to ``don't care''. «Read map name»= DmDatabaseInfo(card,dbID,MapList.entries[numPr].name, NULL,NULL, NULL,NULL, NULL,NULL,NULL,NULL,NULL,NULL);

@

Nearly all the relevant info is in the first record (where the [[Map]] struct is saved). The number of section can be read directl and the number of objects can be calculated from the total number of records in the database: objects = records - sections - 1 (the -1 is the map record at the beginning) «Read map info»= mapDB=DmOpenDatabase(0,dbID,dmModeReadOnly); recnum=DmNumRecords(mapDB); RecHandle=DmGetRecord(mapDB,0); dbMap=MemHandleLock(RecHandle); sections=dbMap->sectionNum; MemHandleUnlock(RecHandle); DmReleaseRecord(mapDB,0,false); DmCloseDatabase(mapDB); recnum-=sections+1; MapList.entries[numPr].sections=sections; MapList.entries[numPr++].objects=recnum; @

«*»= void ScanDumps() Err error; DmSearchStateType stateInfo; UInt card; LocalID dbID; UInt numPr=0;

error=DmGetNextDatabaseByTypeCreator(true,&stateInfo, DumpDBType,APPID, false, &card,&dbID);

while(error == 0) numPr++; error=DmGetNextDatabaseByTypeCreator(false,&stateInfo, DumpDBType,APPID, false, &card,&dbID);

FreeNameListMem(&MapList); MapList.numEntries=numPr; AllocNameListMem(&MapList);

if(numPr>0) numPr=0; while(DmGetNextDatabaseByTypeCreator((numPr==0),&stateInfo, DumpDBType,APPID, false, &card,&dbID) ==0) DmDatabaseInfo(card,dbID,MapList.entries[numPr++].name, NULL,NULL, NULL,NULL, NULL,NULL,NULL,NULL,NULL,NULL);

SortNamelist(MapList); @