예제 #1
0
void sqlLoadCode(  const Database            &db        ,
                   const SqlApiBindProgramId &programid ,
                   int                        nr        ,
                   VirtualCode               &vc        ) {


  DataFile datafile  ( db, SYSTEM_CODEDATA_FNAME, DBFMODE_READONLY);
  KeyFile  indexfile ( db, SYSTEM_CODEKEY_FNAME , DBFMODE_READONLY);

  KeyFileDefinition keydef(indexfile);
  KeyType key;
  keydef.put(key,0,String(programid.m_fileName));
  keydef.put(key,1,nr);

  bool found = indexfile.searchMin( RELOP_EQ, key, 2);

#ifdef DEBUGMODULE
  _tprintf(_T("loading code for <%s>,%d\n"),programid.filename,nr);
#endif

  if(!found)
    throwSqlError(SQL_UNKNOWN_PROGRAMID,_T("Unknown programfile:<%s>"),programid.m_fileName);
  datafile.readRecord( keydef.getRecordAddr(key), &vc, sizeof(VirtualCode));

  if(_tcscmp(vc.getProgramId().m_timestamp,programid.m_timestamp) != 0)
    throwSqlError(SQL_TIMESTAMP_MISMATCH,_T("Timestamp mismatch on <%s>"),programid.m_fileName);
}
예제 #2
0
void Database::sysTabDbInsert(SysTableDbData &dbdef) {
  if(!DbFile::exist(SYSTEM_DBDATA_FNAME)) {
    createDbDb();
  }

  LogFile logFile(SYSTEM_DBLOG_FNAME);

  DataFile dataFile( SYSTEM_DBDATA_FNAME, DBFMODE_READWRITE, &logFile);
  KeyFile  indexFile(SYSTEM_DBKEY_FNAME,  DBFMODE_READWRITE, &logFile);

  logFile.begin();
  _tcsupr(dbdef.m_dbName);
  try {
    DbAddr addr = dataFile.insert(&dbdef, sizeof(SysTableDbData));

    KeyFileDefinition keydef(indexFile);
    KeyType key;
    keydef.put(key, 0, String(dbdef.m_dbName));
    keydef.putRecordAddr(key, addr);
    indexFile.insert(key);
  } catch(sqlca) {
    logFile.abort();
    throw;
  }
  logFile.commit();
}
const IndexDefinition &Database::getIndexDefinition(const String &indexName) const {
  if(indexName.length() > MAXINDEXNAME) {
    throwSqlError(SQL_INVALID_INDEXNAME,_T("Indexname <%s> is too long"), indexName.cstr() );
  }

  const String tmpName = toUpperCase(indexName);
  IndexDefinition **indexDefpp = m_indexDefIndexNameCache.get(tmpName);
  if(indexDefpp == NULL) {
    DataFile dataFile( *this,SYSTEM_INDEXDATA_FNAME, DBFMODE_READONLY);
    KeyFile  indexFile(*this,SYSTEM_INDEXKEY2_FNAME, DBFMODE_READONLY);

    KeyFileDefinition keydef(indexFile);
    KeyType key;
    keydef.put(key,0,tmpName);

    if(!indexFile.searchMin(RELOP_EQ, key, 1)) {
      throwSqlError(SQL_INVALID_INDEXNAME, _T("Index <%s> doesn't exist"),indexName.cstr());
    }

    SysTableIndexData indexData;
    dataFile.readRecord(keydef.getRecordAddr(key),&indexData, sizeof(indexData));
    getIndexDefinitions(indexData.m_tableName);
    indexDefpp = m_indexDefIndexNameCache.get(tmpName);
  }
  if(indexDefpp == NULL) {
    throwSqlError(SQL_INVALID_INDEXNAME, _T("Index <%s> doesn't exist"),indexName.cstr());
  }

  return **indexDefpp;
}
예제 #4
0
static bool codelookup( Database       &db,
                        const String   &filename,
                        int             nr) {

  KeyFile        indexfile(db, SYSTEM_CODEKEY_FNAME ,DBFMODE_READONLY);
  KeyFileDefinition keydef(indexfile);
  KeyType key;
  keydef.put(key,0,filename);
  keydef.put(key,1,nr);
  return indexfile.searchMin(RELOP_EQ, key, 2);
}
예제 #5
0
bool Database::searchDbName(const String &dbName, SysTableDbData &dbdef) {
  if(dbName.length() > SQLAPI_MAXDBNAME) {
    throwSqlError(SQL_DBNAME_TOO_LONG,_T("Database name <%s> too long"),dbName.cstr());
  }

  if(!DbFile::exist(SYSTEM_DBDATA_FNAME)) {
    return false;
  }

  DataFile dataFile(  SYSTEM_DBDATA_FNAME, DBFMODE_READONLY, NULL);
  KeyFile  indexFile( SYSTEM_DBKEY_FNAME,  DBFMODE_READONLY, NULL);
  KeyType  key;

  KeyFileDefinition keydef(indexFile);
  keydef.put(key, 0, toUpperCase(dbName));

  if(!indexFile.searchMin(RELOP_EQ, key, 1)) {
    return false;
  }

  dataFile.readRecord(keydef.getRecordAddr(key), &dbdef, sizeof(SysTableDbData));
  return true;
}
예제 #6
0
void Database::sysTabDbDelete(const String &dbName) {
  LogFile logFile(SYSTEM_DBLOG_FNAME);
  KeyType key;

  DataFile dataFile( SYSTEM_DBDATA_FNAME, DBFMODE_READWRITE, &logFile);
  KeyFile  indexFile(SYSTEM_DBKEY_FNAME,  DBFMODE_READWRITE, &logFile);

  KeyFileDefinition keydef(indexFile);
  keydef.put(key, 0, toUpperCase(dbName));

  if(!indexFile.searchMin(RELOP_EQ, key, 1)) {
    throwSqlError(SQL_DB_NOT_EXIST,_T("Database <%s> doesn't exist"),dbName.cstr());
  }

  logFile.begin();
  try {
    dataFile.remove(keydef.getRecordAddr(key));
    indexFile.remove(key);
  } catch(sqlca) {
    logFile.abort();
    throw;
  }
  logFile.commit();
}
void Database::readIndexDefinitions(const String &tableName, IndexArray &indexArray) const {
  const String tmpName = toUpperCase(tableName);
  indexArray.clear();

  const TableDefinition &tableDef = getTableDefinition(tmpName); /* just to check the tmpName */
  DataFile dataFile( *this, SYSTEM_INDEXDATA_FNAME, DBFMODE_READONLY);
  KeyFile  indexFile(*this, SYSTEM_INDEXKEY1_FNAME, DBFMODE_READONLY);

  KeyFileDefinition keydef(indexFile);
  KeyType key;
  keydef.put(key,0,tmpName);

  KeyCursor cursor(indexFile,
                   RELOP_EQ, &key, 1,
                   RELOP_EQ, &key, 1,
                   SORT_ASCENDING);

  while(cursor.hasNext()) {
    cursor.next(key);
    SysTableIndexData index;
    dataFile.readRecord(keydef.getRecordAddr(key),&index, sizeof(SysTableIndexData));
    indexArray.add(index);
  }
}
예제 #8
0
// AVS
// completelly rewrited to support new conceptions
int TMapLoader::Load(const char * filename, const char * szActiveEmul) {
	char buf[256];
	int bufLen;
	
	ifstream inpfile(filename);
	KeyTrans.DeleteAllDefs();
	Charmap.init();
	
	// it is an array for store [...] ... [end ...] parts from file
	stringArray SA(0,0,sizeof(string));
	int AllOk = 0;
	
	while ( inpfile ) {
		
		getline(inpfile, buf, 255);
		bufLen = strlen(buf);
		if ( !bufLen ) continue;
		
		if ( buf[0] == '[' && buf[bufLen-1] == ']' ) {
			// is a part splitter [...]
			string temps(buf);
			
			if (!normalizeSplitter(temps)) {
				printm(0, FALSE, MSG_KEYUNEXPLINE, temps.c_str());
				AllOk = 0;
				break;
			};
			// if a comment
			if ( stricmp(temps.c_str(),"[comment]") == 0 ) {
#ifdef KEYDEBUG
				printit(temps.c_str());
#endif
				if ( !getLongComment(inpfile, buf, sizeof(buf)) ) {
					printm(0, FALSE, MSG_KEYUNEXPEOF);
					break;
				};
#ifdef KEYDEBUG
				printit("\r          \r");
#endif
				continue;
			};
			
			
			string back = temps;
			// prepare line for make it as [end ...]
			// and check it
			if ( strnicmp(back.c_str(), "[global]", 8) == 0 ) {} // do nothing
			else if ( strnicmp(back.c_str(), "[keymap", 7) == 0 ) {
				// DJGPP also uses erase rather than remove (Paul Brannan 6/23/98)
#ifndef __BORLANDC__
				back.erase(7);
#else
				back.remove(7);
#endif
				back += "]";
			}
			else if ( strnicmp(back.c_str(), "[charmap", 8) == 0 ) {
				// Paul Brannan 6/23/98
#ifndef __BORLANDC__
				back.erase(8);
#else
				back.remove(8);
#endif
				back += "]";
			}
			else if ( strnicmp(back.c_str(), "[config", 7) == 0 ) {
				// Paul Brannan 6/23/98
#ifndef __BORLANDC__
				back.erase(7);
#else
				back.remove(7);
#endif
				back += "]";
			}
			else {
				//        cerr << "Unexpected token " << back << endl;
				printm(0, FALSE, MSG_KEYUNEXPTOK, back.c_str());
				break;
			};
			
			back.insert(1,"END "); // now it looks like [END ...]
#ifdef KEYDEBUG
			printit(temps.c_str());
#endif
			
			int ok = 0;
			// fetch it to temps
			while ( 1 ) {
				getline(inpfile, buf, sizeof(buf));
				bufLen = strlen(buf);
				if ( !bufLen ) break;
				if ( buf[0] == '[' && buf[bufLen-1] == ']' ) {
					string t(buf);
					if ( !normalizeSplitter(t) ) break;
					
					if ( stricmp(t.c_str(),back.c_str()) == 0 ) {
						ok = 1;
						break;
					};
					
					// AVS 31.12.97 fix [comment] block inside another block
					if ( stricmp(t.c_str(),"[comment]") == 0 &&
						getLongComment(inpfile, buf, sizeof(buf)) ) continue;
					
					break;
				};
				temps += "\n";
				temps += buf;
			};
			if ( !ok ) {
				//         cerr << "Unexpected end of file or token" << endl;
				printm(0, FALSE, MSG_KEYUNEXP);
				AllOk = 0;
				break;
			};
#ifdef KEYDEBUG
			printit("\r                                                                      \r");
#endif
			AllOk = SA.Add(temps);;
			if ( !AllOk ) break;
		} else {
			//       cerr << "Unexpected line '" << buf << "'\n";
			printm(0, FALSE, MSG_KEYUNEXPLINE, buf);
			AllOk = 0;
			break;
		};
	};
	
	inpfile.close();
	
	if ( !AllOk ) return 0;
	
	// now all file are in SA, comments are stripped
	
	int i = LookForPart(SA, "global", "");
	if ( i == INT_MAX ) {
		//     cerr << "No [GLOBAL] definition!" << endl;
		printm(0, FALSE, MSG_KEYNOGLOBAL);
		return 0;
	};
	if ( !LoadGlobal(SA[i]) ) {
		return 0;
	};
	
	// look for need configuration
	i = LookForPart(SA, "config", szActiveEmul);
	if ( i == INT_MAX ) {
		//     cerr << "No [CONFIG " << szActiveEmul << "]\n";
		printm(0, FALSE, MSG_KEYNOCONFIG, szActiveEmul);
		return 0;
	};
	//  cerr << "use configuration: " << szActiveEmul << endl;
	printm(0, FALSE, MSG_KEYUSECONFIG, szActiveEmul);
	BOOL hadKeys = FALSE;
	
	string config = SA[i];
	// parse it
	while ( config.length() ) {
		buf[0] = 0;
		getline(config,buf,sizeof(buf));
		bufLen = strlen(buf);
		if ( !bufLen || (buf[0] == '[' && buf[bufLen-1] == ']') ) continue;
		if ( strnicmp(buf,"keymap",6) == 0 ) {
			string orig(buf);
			printit("\t"); printit(buf); printit("\n");
			char * mapdef = strtok(buf,":");
			char * switchKey = strtok(NULL,"\n");
			
			if ( !KeyTrans.mapArray.IsEmpty() && switchKey == NULL ) {
				//            cerr << "no switch Key for '" << mapdef
				//                 << "'" << endl;
				printm(0, FALSE, MSG_KEYNOSWKEY, mapdef);
				break;
			};
			if ( KeyTrans.mapArray.IsEmpty() ) {
				if ( switchKey != NULL ) { // create default keymap
					//               cerr << "You cannot define switch key for default keymap -> ignored"
					//                    << endl;
					printm(0, FALSE, MSG_KEYCANNOTDEF);
				};
				TKeyDef empty;
				KeyTrans.mapArray.Add(KeyMap(string(mapdef)));
				KeyTrans.switchMap(empty); // set it as current keymap
				KeyTrans.mainKeyMap = KeyTrans.currentKeyMap;
			}
			else {
				string keydef(switchKey);
				keydef += " !*!*!*"; // just for check
				WORD vk_code;
				DWORD control;
				switchKey = ParseKeyDef(keydef.c_str(),vk_code,control);
				if ( switchKey != NULL ) {
					TKeyDef swi(NULL,control,vk_code);
					if ( KeyTrans.switchMap(swi) > 0 ) {
						//                  cerr << "Duplicate switching key\n";
						printm(0, FALSE, MSG_KEYDUPSWKEY);
						break;
					};
					KeyTrans.mapArray.Add(KeyMap(swi, orig));
					KeyTrans.switchMap(swi); // set it as current keymap
				}
			};
			mapdef+=7; // 'keymap '
			// now load defined keymaps to current
			while ((mapdef != NULL)&&
				(mapdef = strtok(mapdef,TOKEN_DELIMITERS)) != NULL ) {
				i = LookForPart(SA,"keymap",mapdef);
				if ( i == INT_MAX ) {
					//               cerr << "Unknown KEYMAP " << mapdef << endl;
					printm(0, FALSE, MSG_KEYUNKNOWNMAP, mapdef);
				} else {
					mapdef = strtok(NULL,"\n"); // strtok is used in LoadKeyMap
					// so - save pointer!
					hadKeys = LoadKeyMap(SA[i]); // load it
				};
			};
			
		}
		else if ( strnicmp(buf,"charmap",7) == 0 ) {
			printit("\t"); printit(buf); printit("\n");
			char * mapdef = buf + 8;// 'charmap '
			int SuccesLoaded = 0;
			// now load defined charmaps to current
			while ((mapdef != NULL)&&
				(mapdef = strtok(mapdef,TOKEN_DELIMITERS)) != NULL ) {
				i = LookForPart(SA,"charmap",mapdef);
				if ( i == INT_MAX ) {
					//               cerr << "Unknown KEYMAP " << mapdef << endl;
					printm(0, FALSE, MSG_KEYUNKNOWNMAP, mapdef);
				} else {
					mapdef = strtok(NULL,"\n"); // strtok is used in LoadKeyMap
					// so - save pointer!
					if (LoadCharMap(SA[i])) // load it
						SuccesLoaded++;
				};
			};
			if (!SuccesLoaded) {
				//            cerr << "No charmaps loaded\n";
				printm(0, FALSE, MSG_KEYNOCHARMAPS);
				Charmap.init();
			};
			/*         strtok(buf," ");
			
			  char* name = strtok(NULL," ");
			  if ( name == NULL ) {
			  cerr << "No name for CHARMAP" << endl;
			  } else {
			  i = LookForPart(SA,"charmap", name);
			  if ( i == INT_MAX ) {
			  cerr << "Unknown CHARMAP " << name << endl;
			  } else {
			  LoadCharMap(SA[i]);
			  };
			  };
			*/
		}
		else {
			//        cerr << "unexpected token in " << szActiveEmul << endl;
			printm(0, FALSE, MSG_KEYUNEXPTOKIN, szActiveEmul);
		}
	}

	if ( hadKeys) {
		TKeyDef empty;
		KeyTrans.switchMap(empty); // switch to default
		KeyTrans.mainKeyMap = KeyTrans.currentKeyMap; // save it's number
		//     cerr << "There are " << (KeyTrans.mapArray.GetItemsInContainer()) << " maps\n";
		char s[12]; // good enough for a long int (32-bit)
		itoa(KeyTrans.mapArray.GetItemsInContainer(), s, 10);
		printm(0, FALSE, MSG_KEYNUMMAPS, s);
		return 1;
	};
	return 0;
}