bool Command::IsFlag(Tags::Type tag) const { return IsFlag(StaticName::ToString(tag)); }
_String* _CString::DecompressFrequency(void) { _String* theAlphabet = SelectAlpha (compressionType); if (!IsFlag(FREQCOMPRESSION)) { return nil; // wrong compression type nothing to do } unsigned char *codeMaps = new unsigned char [(*theAlphabet).sLength]; if (!codeMaps) { warnError( -108); // no memory } unsigned int i,j,k,l,t; // temporary vars // read in the alphabet encoding i=0; t=0; for (j=0; j<(*theAlphabet).sLength; j++, i+=5, t = i/8) { long leftover = 8-i%8; unsigned char value = sData[t]; if (leftover>=5) { switch (leftover) { case 5: value%=32; break; case 6: value=(value%64)/2; break; case 7: value=(value%128)/4; break; default: value=value/8; } } else { value=((unsigned char) sData[t])%realPowersOf2[leftover]*realPowersOf2[5-leftover]; value+=((unsigned char) sData[t+1])/realPowersOf2[3+leftover]; } codeMaps[value-1]=j; } if(i%8) { t++; //possible rounding error } // now read in the data // first we must guess the correct size of the string, but to be safe we'll just set it to // the maximum possible value (i.e. if all the bytes compressed to 1 bit) _String result (10,true); // k will count the actual length // j,l will be used for relative positions of 0's for (k=0,j=t*8;; ) { // go by bits l=j; // look for the next zero bit in the stream while (1) { for (i=8-l%8; i>0; i--) { if (!(sData[t]&realPowersOf2[i-1])) { break; } } if (i) { l+=(8-i)-l%8; break; } if (t<sLength-1) { t++; } else { l=0; break; } l=t*8; } if (!l) { break; } l++; _String addOn (theAlphabet->getChar(codeMaps[l-j-1])); result<<&addOn; if ((t=l/8)>=sLength) { break; } j=l; k++; } result.Finalize(); delete [] codeMaps; return (_String*)(_String (result.getStr())).makeDynamic(); }
CMainApp::Error_Codes CMainApp::ParseCommandLine(int argc, char ** argv) { char * pArgument; int count = 0; if(argc==1) m_dwFlags |= HELP; while(++count<argc) { pArgument = argv[count]; if(*pArgument=='/' || *pArgument=='-') { while(*(++pArgument)) { switch(*pArgument) { case 'a': // Append resources case 'A': { //Make sure no other conflicting flags are specified if(IsFlag(REPLACE) | IsFlag(UPDATE) | IsFlag(EXTRACT)) { Banner(); WriteCon(CONERR, "Please use -a without the -r, -u or -t option!"); return ERR_COMMAND_LINE; } // Make sure none of the next item is another option for(int c=1; c<=4; c++) if(argv[count+c]==NULL || *argv[count+c]=='/' || *argv[count+c]=='-') { Banner(); WriteCon(CONERR, "Not enough parameters specified for the -a option\r\n"\ " -a InputExeFile InputUSTokFile InputLOCTokFile OutputExeFile\r\n"); return ERR_COMMAND_LINE; }; m_dwFlags |= APPEND; // Get the input EXE file name m_strInExe = argv[++count]; // Get the source token file name m_strSrcTok = argv[++count]; // Get the target token file name m_strTgtTok = argv[++count]; // Get the output EXE file name m_strOutExe = argv[++count]; } break; case 'b': case 'B': m_dwFlags |= BITMAPS; break; case 'd': case 'D': // Default for unmappable characters m_unmappedChar = argv[++count][0]; break; case 'f': case 'F': m_dwFlags |= FONTS; break; case 'i': // Input language/sublanguage case 'I': m_dwFlags |= INPUT_LANG; m_usIPriLangId = GetLangID(argv[++count]); m_usISubLangId = GetLangID(argv[++count]); break; case '?': // Help case 'h': case 'H': m_dwFlags |= HELP; break; case 'n': case 'N': m_dwFlags |= NOLOGO; break; case 'o': // Output language/sublanguage case 'O': m_dwFlags |= OUTPUT_LANG; m_usOPriLangId = GetLangID(argv[++count]); m_usOSubLangId = GetLangID(argv[++count]); break; case 'p': // Code page case 'P': m_uiCodePage = GetCodePage(argv[++count]); break; case 'r': // Replace resources case 'R': { //Make sure no other conflicting flags are specified if(IsFlag(APPEND) | IsFlag(EXTRACT) | IsFlag(UPDATE)) { Banner(); WriteCon(CONERR, "Please use -r without the -a, -u or -t option!"); return ERR_COMMAND_LINE; } // Make sure none of the next item is another option for(int c=1; c<=3; c++) if(argv[count+c]==NULL || *argv[count+c]=='/' || *argv[count+c]=='-') { Banner(); WriteCon(CONERR, "Not enough parameters specified for the -r option\r\n"\ " -r InputExeFile InputLOCTokFile OutputExeFile\r\n"); return ERR_COMMAND_LINE; }; m_dwFlags |= REPLACE; // Get the input EXE file name m_strInExe = argv[++count]; // Get the target token file name m_strTgtTok = argv[++count]; // Get the output EXE file name m_strOutExe = argv[++count]; } break; case 'u': // Update resources case 'U': { //Make sure no other conflicting flags are specified if(IsFlag(APPEND) | IsFlag(EXTRACT) | IsFlag(REPLACE)) { Banner(); WriteCon(CONERR, "Please use -u without the -a, -r or -t option!"); return ERR_COMMAND_LINE; } // Make sure none of the next item is another option for(int c=1; c<=4; c++) if(argv[count+c]==NULL || *argv[count+c]=='/' || *argv[count+c]=='-') { Banner(); WriteCon(CONERR, "Not enough parameters specified for the -u option\r\n"\ " -u InputExeFile InputUSTokFile InputLOCTokFile OutputExeFile\r\n"); return ERR_COMMAND_LINE; }; m_dwFlags |= UPDATE; // Get the input EXE file name m_strInExe = argv[++count]; // Get the source token file name m_strSrcTok = argv[++count]; // Get the target token file name m_strTgtTok = argv[++count]; // Get the output EXE file name m_strOutExe = argv[++count]; } break; case 's': case 'S': m_dwFlags |= SPLIT; break; case 't': // Create token file case 'T': { //Make sure no other conflicting flags are specified if(IsFlag(APPEND) | IsFlag(REPLACE) | IsFlag(UPDATE)) { Banner(); WriteCon(CONERR, "Please use -t without the -a, -u or -r option!"); return ERR_COMMAND_LINE; } // Make sure none of the next item is another option for(int c=1; c<=2; c++) if(argv[count+c]==NULL || *argv[count+c]=='/' || *argv[count+c]=='-') { Banner(); WriteCon(CONERR, "Not enough parameters specified for the -t option\r\n"\ " -t InputExeFile OutputTokenFile\r\n"); return ERR_COMMAND_LINE; }; m_dwFlags |= EXTRACT; // Get the input EXE file name m_strInExe = argv[++count]; // Get the target token file name m_strTgtTok = argv[++count]; } break; case 'w': // Display warnings case 'W': m_dwFlags |= WARNING; break; default: break; } } } } // Do we want the banner if(!IsFlag(NOLOGO)) Banner(); // Before exiting make sure we display the help screen if requested if(IsFlag(HELP)) { Help(); return ERR_HELP_CHOOSE; } // Check if the code page we have is installed in this system if(!IsValidCodePage(m_uiCodePage)) { // Warn the user and get back the default CP m_uiCodePage = GetACP(); WriteCon(CONERR, "The code page specified is not installed in the system or is invalid! Using system default!\r\n"); } // Make sure the input file is there CFileStatus fs; if(!m_strInExe.IsEmpty()) { if(!CFile::GetStatus(m_strInExe, fs)) { WriteCon(CONERR, "File not found: %s\r\n", m_strInExe); return ERR_FILE_NOTFOUND; } } // Check if the tgt token file or exe are read only if(!m_strOutExe.IsEmpty()) { if(CFile::GetStatus(m_strOutExe, fs)) { if((fs.m_attribute & 0x1)==0x1) { WriteCon(CONERR, "File is read only: %s\r\n", m_strOutExe); return ERR_FILE_CREATE; } } } if(!m_strTgtTok.IsEmpty() && IsFlag(EXTRACT)) { if(CFile::GetStatus(m_strTgtTok, fs)) { if((fs.m_attribute & 0x1)==0x1) { WriteCon(CONERR, "File is read only: %s\r\n", m_strTgtTok); return ERR_FILE_CREATE; } } } // // Check the value specified for the output language. // If none has been specified, warn the user and default to neutral. // if(IsFlag(APPEND) | IsFlag(REPLACE)) { if(m_usOPriLangId==-1) { m_usOPriLangId = LANG_NEUTRAL; // set the PRI language ID to neutral WriteCon(CONERR, "Output language ID not specified, default to neutral(%d)\r\n", m_usOPriLangId); } if(m_usOSubLangId==-1) { m_usOSubLangId = SUBLANG_NEUTRAL; // set the SEC language ID to neutral WriteCon(CONERR, "Output sub-language ID not specified, default to neutral(%d)\r\n", m_usOSubLangId); } } WriteCon(CONWRN, "Code Page : %d\r\n", m_uiCodePage); WriteCon(CONWRN, "In Primary Language : %d (%d)\r\n", m_usIPriLangId, MAKELANGID(m_usIPriLangId,m_usISubLangId)); WriteCon(CONWRN, "In Secondary Language : %d (0x%x)\r\n", m_usISubLangId, MAKELANGID(m_usIPriLangId,m_usISubLangId)); WriteCon(CONWRN, "Out Primary Language : %d (%d)\r\n", m_usOPriLangId, MAKELANGID(m_usOPriLangId,m_usOSubLangId)); WriteCon(CONWRN, "Out Secondary Language : %d (0x%x)\r\n", m_usOSubLangId, MAKELANGID(m_usOPriLangId,m_usOSubLangId)); WriteCon(CONWRN, "Default unmapped char : %c \r\n", m_unmappedChar); return ERR_NOERROR; }
bool CRegionBase::IsGuarded() const { ADDTOCALLSTACK("CRegionBase::IsGuarded"); // Safe areas do not need guards. return( IsFlag( REGION_FLAG_GUARDED ) && ! IsFlag( REGION_FLAG_SAFE )); }
bool CRegionBase::r_WriteVal( LPCTSTR pszKey, CGString & sVal, CTextConsole * pSrc ) { ADDTOCALLSTACK("CRegionBase::r_WriteVal"); EXC_TRY("WriteVal"); bool fZero = false; int index = FindTableHeadSorted(pszKey, sm_szLoadKeys, COUNTOF(sm_szLoadKeys) - 1); if ( index < 0 ) return CScriptObj::r_WriteVal(pszKey, sVal, pSrc); switch ( index ) { case RC_ANNOUNCE: sVal.FormatVal( IsFlag(REGION_FLAG_ANNOUNCE)); break; case RC_ARENA: sVal.FormatVal( IsFlag(REGION_FLAG_ARENA)); break; case RC_BUILDABLE: sVal.FormatVal( ! IsFlag(REGION_FLAG_NOBUILDING)); break; case RC_CLIENTS: { int i = 0; size_t iClients = 0; for ( ; ; i++ ) { CSector *pSector = GetSector(i); if ( pSector == NULL ) break; iClients += pSector->m_Chars_Active.HasClients(); } sVal.FormatVal(static_cast<long>(iClients)); break; } case RC_EVENTS: m_Events.WriteResourceRefList( sVal ); break; case RC_ISEVENT: if ( pszKey[7] != '.' ) return( false ); pszKey += 8; sVal.FormatVal(m_Events.ContainsResourceName(RES_EVENTS, pszKey)); return( true ); case RC_FLAGS: sVal.FormatHex( GetRegionFlags() ); break; case RC_GATE: sVal.FormatVal( ! IsFlag(REGION_ANTIMAGIC_GATE)); break; case RC_GROUP: sVal = m_sGroup; break; case RC_GUARDED: sVal.FormatVal( IsFlag(REGION_FLAG_GUARDED)); break; case RC_MAGIC: sVal.FormatVal( ! IsFlag(REGION_ANTIMAGIC_ALL)); break; case RC_MAP: sVal.FormatVal( m_pt.m_map ); break; case RC_MARK: case RC_RECALLIN: sVal.FormatVal( ! IsFlag(REGION_ANTIMAGIC_RECALL_IN)); break; case RC_NAME: // The previous name was really the DEFNAME ??? sVal = GetName(); break; case RC_NOBUILD: sVal.FormatVal( IsFlag(REGION_FLAG_NOBUILDING)); break; case RC_NODECAY: sVal.FormatVal( IsFlag(REGION_FLAG_NODECAY)); break; case RC_NOPVP: sVal.FormatVal( IsFlag(REGION_FLAG_NO_PVP)); break; case RC_P: sVal = m_pt.WriteUsed(); break; case RC_RECALL: case RC_RECALLOUT: sVal.FormatVal( ! IsFlag(REGION_ANTIMAGIC_RECALL_OUT)); break; case RC_RECT: { size_t iQty = m_Rects.GetCount(); pszKey += 4; if ( *pszKey == '\0' ) { sVal.FormatVal( static_cast<long>(iQty)); return true; } SKIP_SEPARATORS( pszKey ); size_t iRect = Exp_GetVal( pszKey ); if ( iRect <= 0 ) { sVal = m_rectUnion.Write(); return true; } iRect -= 1; if ( !m_Rects.IsValidIndex( iRect ) ) { sVal.FormatVal( 0 ); return true; } sVal = m_Rects[iRect].Write(); return( true ); } case RC_SAFE: sVal.FormatVal( IsFlag(REGION_FLAG_SAFE)); break; case RC_TAGCOUNT: sVal.FormatVal( static_cast<long>(m_TagDefs.GetCount()) ); break; case RC_TAGAT: { pszKey += 5; // eat the 'TAGAT' if ( *pszKey == '.' ) // do we have an argument? { SKIP_SEPARATORS( pszKey ); size_t iQty = static_cast<size_t>( Exp_GetVal( pszKey ) ); if ( iQty >= m_TagDefs.GetCount() ) return( false ); // trying to get non-existant tag CVarDefCont * pTagAt = m_TagDefs.GetAt( iQty ); if ( !pTagAt ) return( false ); // trying to get non-existant tag SKIP_SEPARATORS( pszKey ); if ( ! *pszKey ) { sVal.Format("%s=%s", pTagAt->GetKey(), pTagAt->GetValStr()); return( true ); } else if ( !strnicmp( pszKey, "KEY", 3 )) // key? { sVal = pTagAt->GetKey(); return( true ); } else if ( !strnicmp( pszKey, "VAL", 3 )) // val? { sVal = pTagAt->GetValStr(); return( true ); } } return( false ); } break; case RC_TAG0: fZero = true; ++pszKey; // fall through case RC_TAG: // "TAG" = get/set a local tag. { if ( pszKey[3] != '.' ) return( false ); pszKey += 4; sVal = m_TagDefs.GetKeyStr( pszKey, fZero ); return( true ); } case RC_TYPE: { const CItemBase * pBase = NULL; const CItem * pItem = GetResourceID().ItemFind(); if (pItem != NULL) pBase = pItem->Item_GetDef(); if (pBase != NULL) sVal = pBase->GetResourceName(); else sVal = ""; } break; case RC_UID: // Allow use of UID.x.KEY on the REGION object if ( pszKey[3] == '.' ) return CScriptObj::r_WriteVal( pszKey, sVal, pSrc ); sVal.FormatHex( GetResourceID() ); break; case RC_UNDERGROUND: sVal.FormatVal( IsFlag(REGION_FLAG_UNDERGROUND)); break; default: return false; } return true; EXC_CATCH; EXC_DEBUG_START; g_Log.EventDebug("command '%s' ret '%s' [%p]\n", pszKey, static_cast<LPCTSTR>(sVal), static_cast<void *>(pSrc)); EXC_DEBUG_END; return false; }