/* a method that handels "LABELS:" in a given line*/ char *HandleLabel(char* label,char *line,int* loc) { char *temp,*address_10=NULL,*address_12=NULL; enum Directive dir; label[strlen(label)-1]='\0'; temp=line+(*loc); temp=StringTrim(temp); /*ALLOCATE_STRING(address_10,1); ALLOCATE_STRING(address_12,1);*/ FIX_NULL_STRING(address_10); FIX_NULL_STRING(address_12); if(strlen(temp)==0) /* Label only */ { strcpy(address_10,ConvertIntToCharByBase(IC,ConversionToAddress,10)); strcpy(address_12,ConvertIntToCharByBase(IC,ConversionToAddress,12)); AddLabelItem(_labels,label,address_10,address_12,'c'); IC++; } else if(temp[0]=='.') /* Label with Directive */ { dir=WhatDirective(temp); temp=StringMoveToNextItem(temp); temp=StringTrim(temp); switch(dir) { case STRING: strcpy(address_10,ConvertIntToCharByBase(DC,ConversionToAddress,10)); strcpy(address_12,ConvertIntToCharByBase(DC,ConversionToAddress,12)); AddLabelItem(_labels,label,address_10,address_12,'d'); break; break; case DATA: strcpy(address_10,ConvertIntToCharByBase(DC,ConversionToAddress,10)); strcpy(address_12,ConvertIntToCharByBase(DC,ConversionToAddress,12)); AddLabelItem(_labels,label,address_10,address_12,'d'); break; case EXTERN: case ENTRY: FIX_NULL_STRING(label); break; case NONE: strcpy(address_10,ConvertIntToCharByBase(IC,ConversionToAddress,10)); strcpy(address_12,ConvertIntToCharByBase(IC,ConversionToAddress,12)); AddLabelItem(_labels,label,address_10,address_12,'c'); return NULL; break; default: break; } } else { AnalyzeCommand(line); *loc=strlen(line); } return label; }
bool TinyConfig::Load(const char* cfile) { if(!cfile) return false; std::ifstream fs(cfile); if(!fs.is_open()) return false; std::string str; while(std::getline(fs, str)) { str = StringTrim(str); if(str.empty() || str[0] == comment) continue; size_t pos = str.find(separator); if(std::string::npos != pos) { std::string left(str.substr(0, pos)); std::string right(str.substr(pos + 1, str.length() - pos - 1)); left = StringTrim(left); right = StringTrim(right); AddEntry(left, right, false); } } fs.close(); return true; }
/** * Reads the auto message */ void read_automessage() { GetSession()->bout.NewLine(); std::unique_ptr<WStatus> status(GetApplication()->GetStatusManager()->GetStatus()); bool bAutoMessageAnonymous = status->IsAutoMessageAnonymous(); WTextFile autoMessageFile(syscfg.gfilesdir, AUTO_MSG, "rt"); std::string line; if (!autoMessageFile.IsOpen() || !autoMessageFile.ReadLine(&line)) { GetSession()->bout << "|#3No auto-message.\r\n"; GetSession()->bout.NewLine(); return; } std::string authorName = StringTrimEnd(line); if (bAutoMessageAnonymous) { if (getslrec(GetSession()->GetEffectiveSl()).ability & ability_read_post_anony) { std::stringstream ss; ss << "<<< " << line << " >>>"; authorName = ss.str(); } else { authorName = ">UNKNOWN<"; } } GetSession()->bout << "\r\n|#9Auto message by: |#2" << authorName << "|#0\r\n\n"; int nLineNumber = 0; while (autoMessageFile.ReadLine(&line) && nLineNumber++ < 10) { StringTrim(line); GetSession()->bout.Color(9); GetSession()->bout << "|#9" << line << wwiv::endl; } GetSession()->bout.NewLine(); }
TError TCgroup::GetBool(const std::string &knob, bool &value) const { std::string string; TError error = Get(knob, string); if (!error) value = StringTrim(string) != "0"; return error; }
char *ReadWord_by_value(char *text,int curLoc,char specificDelimiter) { char *tempItem=NULL,*tempText=NULL; enum Boolean delimiterFound=FALSE,inQuotes=FALSE; int i; /* if(specificDelimiter==NULL) specificDelimiter=' ';*/ tempText = StringTrim(text+curLoc); if(strlen(tempText)==0) return NULL; for(i=0;delimiterFound==FALSE;i++) { if(tempText[i]=='\"') if(inQuotes==TRUE) inQuotes=FALSE; else inQuotes=TRUE; else if(IsDelimiter(tempText[i],specificDelimiter)==TRUE) { delimiterFound=TRUE; if(i==0) { delimiterFound=FALSE; break; } if(tempText[i]==':') { tempItem=(char*)realloc(tempItem,(i+1)*sizeof(char)); tempItem[i]=tempText[i]; i++; } else if(tempText[i]==' ' && inQuotes==TRUE) { delimiterFound=FALSE; tempItem=(char*)realloc(tempItem,(i+1)*sizeof(char)); tempItem[i]=tempText[i]; continue; } tempItem=(char*)realloc(tempItem,(i+1)*sizeof(char)); tempItem[i]='\0'; break; } if(delimiterFound==FALSE) { tempItem=(char*)realloc(tempItem,(i+1)*sizeof(char)); tempItem[i]=tempText[i]; } } return tempItem; }
static string SubTypeFromText(const std::string& text) { string subtype = text; StringTrim(&subtype); if (subtype.back() == '\0') subtype.pop_back(); if (subtype.size() > 7) { return ""; } return subtype; }
bool HttpRequest::ParseStartLine(const StringPiece& data, HttpMessage::ErrorCode* error) { ErrorCode error_placeholder; if (error == NULL) error = &error_placeholder; static const size_t kMinHttpMethodLength = 3; size_t pos = data.find(' ', kMinHttpMethodLength); if (pos == StringPiece::npos) { *error = ERROR_START_LINE_NOT_COMPLETE; return false; } StringPiece method = data.substr(0, pos); StringTrim(&method); m_method = GetMethodByName(method); if (m_method == METHOD_UNKNOWN) { *error = ERROR_METHOD_NOT_FOUND; return false; } size_t prev_pos = pos + 1; pos = data.find(' ', prev_pos); StringPiece uri; if (pos == StringPiece::npos) { uri = data.substr(prev_pos); } else { uri = data.substr(prev_pos, pos - prev_pos); } StringTrim(&uri); uri.copy_to_string(&m_uri); if (pos != StringPiece::npos) { StringPiece version = data.substr(pos); StringTrim(&version); if (!ParseVersion(version)) { *error = ERROR_VERSION_UNSUPPORTED; return false; } } return true; }
TEST(StrUtilTest, Ops) { string str(" Hello World "); StringTrimLeft(&str); EXPECT_EQ("Hello World ", str); StringTrimRight(&str); EXPECT_EQ("Hello World", str); StringToLower(&str); EXPECT_EQ("hello world", str); string str2(" Hello World "); StringTrim(&str2); EXPECT_EQ("Hello World", str2); }
std::string ModifyKey(const std::string & str) { std::string key = StringTrim(StringLower(str)); // remove multiple space std::string::iterator it = std::unique(key.begin(), key.end(), SpaceCompare); key.resize(it - key.begin()); // change space std::replace_if(key.begin(), key.end(), ::isspace, 0x20); return key; }
static rc_t aws_extract_key_value_pair ( const String *source, String *key, String *val ) { String k, v; const char *start = source -> addr; const char *end = start + source -> size; char *eql = string_chr ( start, source -> size, '=' ); if ( eql == NULL ) return RC ( rcKFG, rcChar, rcSearching, rcFormat, rcInvalid ); /* key */ StringInit ( &k, start, eql - start, string_len ( start, eql - start ) ); StringTrim ( key, &k ); start = eql + 1; /* value */ StringInit ( &v, start, end - start, string_len ( start, end - start ) ); StringTrim ( val, &v ); return 0; }
// Freezer TError TFreezerSubsystem::WaitState(TCgroup &cg, const std::string &state) const { uint64_t deadline = GetCurrentTimeMs() + config().daemon().freezer_wait_timeout_s() * 1000; std::string cur; TError error; do { error = cg.Get("freezer.state", cur); if (error || StringTrim(cur) == state) return error; } while (!WaitDeadline(deadline)); return TError(EError::Unknown, "Freezer " + cg.Name + " timeout waiting " + state); }
bool ArchiveZip::existsDir(const Path& path) { Array<Path> dirs; enumerateDirs(dirs); Path normalized = PathNormalize(path); for(auto& i : dirs) { auto& dir = StringTrim(i, "/"); if(dir == normalized) return true; } return false; }
bool HttpHeaders::Parse(const StringPiece& data, int* error) { int error_placeholder; if (error == NULL) error = &error_placeholder; m_headers.clear(); std::vector<std::string> lines; SplitLines(data, &lines); if (lines.size() < 1 || !lines[lines.size() - 1].empty()) { *error = HttpMessage::ERROR_MESSAGE_NOT_COMPLETE; return false; } // Skip the head line and the last line(empty but '\n') for (int i = 0; i < static_cast<int>(lines.size() - 1); ++i) { std::string::size_type pos = lines[i].find(":"); if (pos != std::string::npos) { m_headers.push_back(std::pair<std::string, std::string>( StringTrim(lines[i].substr(0, pos)), StringTrim(lines[i].substr(pos + 1)))); } else { if (!lines[i].empty()) { VLOG(3) << "Invalid http header" << lines[i] << ", ignore"; } else { *error = HttpMessage::ERROR_FIELD_NOT_COMPLETE; m_headers.clear(); return false; } } } *error = HttpMessage::SUCCESS; return true; }
Phobos::UInt32_t Phobos::Game::Physics::Settings::DecodeCollisionMask(const String_t &config) { UInt32_t flags = 0; String_t stringFlag; size_t pos = 0; while(StringSplitBy(stringFlag, config, '|', pos, &pos)) { StringTrim(stringFlag, STRING_TRIM_BOTH); flags |= pclCollisionGroups_gl->GetInt(stringFlag); } return flags; }
char *StringMoveToNextItem(char* text) { char* temp=NULL; int i=0,sizeOfNewString=0; text=StringTrim(text); for(;text[i]!=' ' && text[i]!=':';i++); i++; while(text[i]!='\0') { temp=(char*)realloc(temp,(++sizeOfNewString)*sizeof(char)); temp[sizeOfNewString-1]=text[i]; i++; } temp=(char*)realloc(temp,(++sizeOfNewString)*sizeof(char)); temp[sizeOfNewString-1]='\0'; return temp; }
void write_inet_addr(const char *pszInternetEmailAddress, int nUserNumber) { if (!nUserNumber) { return; /*NULL;*/ } WFile inetAddrFile(syscfg.datadir, INETADDR_DAT); inetAddrFile.Open(WFile::modeReadWrite | WFile::modeBinary | WFile::modeCreateFile, WFile::shareUnknown, WFile::permReadWrite); long lCurPos = 80L * static_cast<long>(nUserNumber); inetAddrFile.Seek(lCurPos, WFile::seekBegin); inetAddrFile.Write(pszInternetEmailAddress, 80L); inetAddrFile.Close(); char szDefaultUserAddr[ 255 ]; sprintf(szDefaultUserAddr, "USER%d", nUserNumber); GetSession()->SetNetworkNumber(getnetnum("FILEnet")); if (GetSession()->GetNetworkNumber() != -1) { set_net_num(GetSession()->GetNetworkNumber()); WTextFile in(GetSession()->GetNetworkDataDirectory(), ACCT_INI, "rt"); WTextFile out(syscfgovr.tempdir, ACCT_INI, "wt+"); if (in.IsOpen() && out.IsOpen()) { char szLine[ 260 ]; while (in.ReadLine(szLine, 255)) { char szSavedLine[ 260 ]; bool match = false; strcpy(szSavedLine, szLine); char* ss = strtok(szLine, "="); if (ss) { StringTrim(ss); if (wwiv::strings::IsEqualsIgnoreCase(szLine, szDefaultUserAddr)) { match = true; } } if (!match) { out.WriteFormatted(szSavedLine); } } out.WriteFormatted("\nUSER%d = %s", nUserNumber, pszInternetEmailAddress); in.Close(); out.Close(); } WFile::Remove(in.GetFullPathName()); copyfile(out.GetFullPathName(), in.GetFullPathName(), false); WFile::Remove(out.GetFullPathName()); } }
void ReadFile(int index) { long fileSize=0; char *tempInputCommand; fileSize=GetFileSize(_FilesList[index]); do{ tempInputCommand=ReadLineFromFile(_FilesList[index],fileSize); if(tempInputCommand==NULL) break; tempInputCommand= StringTrim(tempInputCommand); if(AnalyzeText(tempInputCommand)==TRUE) /*analyze line */ { AsmQueue_AddRecord(tempInputCommand,_AssemblerCommandsQueue[index]); } } while(1); }
static bool ParseCalloutFile(std::map<uint16_t, net_call_out_rec>* node_config_map, const string network_dir) { TextFile node_config_file(network_dir, CALLOUT_NET, "rt"); if (!node_config_file.IsOpen()) { return false; } // A line will be of the format @node host:port [password]. string line; while (node_config_file.ReadLine(&line)) { StringTrim(&line); net_call_out_rec node_config{}; if (ParseCalloutNetLine(line, &node_config)) { // Parsed a line correctly. node_config.ftn_address = StrCat("20000:20000/", node_config.sysnum); node_config_map->emplace(node_config.sysnum, node_config); } } return true; }
bool ReadSubcriberFile(const std::string& dir, const std::string& filename, std::set<uint16_t>& subscribers) { subscribers.clear(); TextFile file(dir, filename, "rt"); if (!file.IsOpen()) { return false; } string line; while (file.ReadLine(&line)) { StringTrim(&line); uint16_t s = StringToUnsignedShort(line); if (s > 0) { subscribers.insert(s); } } return true; }
// static void Logger::Init(int argc, char** argv) { string filename(argv[0]); if (ends_with(filename, ".exe") || ends_with(filename, ".EXE")) { filename = filename.substr(0, filename.size() - 4); } int last_slash = filename.rfind(File::pathSeparatorChar); if (last_slash != string::npos) { filename = filename.substr(last_slash + 1); } set_filename("I", StrCat(filename, ".log")); time_t t = time(nullptr); string l(asctime(localtime(&t))); StringTrim(&l); Logger() << filename << " version " << wwiv_version << beta_version << " (" << wwiv_date << ")"; Logger() << filename << " starting at " << l; exit_filename = filename; }
std::vector<RMInfo> RMInfo::getHARMInfo(const Yarn::Config & conf, const char* name) { std::vector<RMInfo> retval; /* * Read config and create a vector of RM address. */ try{ std::string strHA = StringTrim(conf.getString(std::string(name))); std::vector<std::string> strRMs = StringSplit(strHA, ","); retval.resize(strRMs.size()); for (size_t i = 0; i < strRMs.size(); ++i) { std::vector<std::string> rm = StringSplit(strRMs[i], ":"); retval[i].setHost(rm[0]); retval[i].setPort(rm[1]); } } catch (const Yarn::YarnConfigNotFound &e) { LOG(INFO, "Yarn RM HA is not configured."); } return retval; }
MenuDescriptions::MenuDescriptions(const std::string& menupath) :menupath_(menupath) { TextFile file(menupath, DESCRIPT_ION, "rt"); if (file.IsOpen()) { string s; while (file.ReadLine(&s)) { StringTrim(&s); if (s.empty()) { continue; } string::size_type space = s.find(' '); if (space == string::npos) { continue; } string menu_name = s.substr(0, space); string description = s.substr(space + 1); StringLowerCase(&menu_name); StringLowerCase(&description); descriptions_.emplace(menu_name, description); } } }
std::set<FidoAddress> ReadFidoSubcriberFile(const std::string& dir, const std::string& filename) { TextFile file(dir, filename, "rt"); if (!file.IsOpen()) { return{}; } std::set<FidoAddress> subscribers; string line; while (file.ReadLine(&line)) { StringTrim(&line); if (line.empty()) { continue; } try { subscribers.insert(FidoAddress(line)); } catch (const bad_fidonet_address& e) { LOG(ERROR) << e.what(); } } return subscribers; }
TEST(Common, StringTrim) { EXPECT_EQ("Hello, World", StringTrim(" \t Hello, World\t\t ")); EXPECT_EQ("Hello, World", StringTrim("Hello, World \t ")); EXPECT_EQ("Hello, World", StringTrim(" \t Hello, World")); EXPECT_EQ("", StringTrim("")); }
static void aws_parse_file ( const KFile *self, KConfigNode *aws_node, char *buffer, size_t buf_size, bool isCredentialsFile ) { char *sep; const char *start = buffer; const char *end = start + buf_size; for ( ; start < end; start = sep + 1 ) { rc_t rc; String string, trim; String key, value; sep = string_chr ( start, end - start, '\n' ); if ( sep == NULL ) sep = ( char * ) end; StringInit ( &string, start, sep - start, string_len ( start, sep - start ) ); StringTrim ( &trim, &string ); /* check for comment line and skip */ if ( StringLength ( & trim ) != 0 && trim . addr [ 0 ] == '#' ) continue; /* check for key/value pairs and skip if none found */ rc = aws_extract_key_value_pair ( &trim, &key, &value ); if ( rc != 0 ) continue; /* now check keys we are looking for and populate the node*/ if ( isCredentialsFile ) { String access_key_id, secret_access_key; CONST_STRING ( &access_key_id, "aws_access_key_id" ); CONST_STRING ( &secret_access_key, "aws_secret_access_key" ); if ( StringCaseEqual ( &key, &access_key_id ) ) { rc = aws_KConfigNodeUpdateChild ( aws_node, &key, &value ); if ( rc != 0 ) return; } if ( StringCaseEqual ( &key, &secret_access_key ) ) { rc = aws_KConfigNodeUpdateChild ( aws_node, &key, &value ); if ( rc != 0 ) return; } } else { String region, output; CONST_STRING ( ®ion, "region" ); CONST_STRING ( &output, "output" ); if ( StringCaseEqual ( &key, ®ion ) ) { rc = aws_KConfigNodeUpdateChild ( aws_node, &key, &value ); if ( rc != 0 ) return; } if ( StringCaseEqual ( &key, &output ) ) { rc = aws_KConfigNodeUpdateChild ( aws_node, &key, &value ); if ( rc != 0 ) return; } } } }
/** * Removes spaces from the beginning and the end of the string s. * @param s the string from which to remove spaces * @return s with spaces removed. */ void StringTrim(char *pszString) { string s(pszString); StringTrim(&s); strcpy(pszString, s.c_str()); }
void AIClasses::Init() { assert(!initialized); const std::map<std::string, std::string>& info = callbackHandler->GetMyInfo(); const std::map<std::string, std::string>::const_iterator it = info.find("supportedMods"); // NOTE: use GetModShortName and GetModVersion()? const std::string& modArchvName = callbackHandler->GetModName(); const std::string& modHumanName = callbackHandler->GetModHumanName(); if (it != info.end()) { const std::string& mods = it->second; size_t i = 0; size_t j = 0; size_t p = 0, q = 0; std::string s; while (!initialized) { i = mods.find_first_of('(', i); j = mods.find_first_of(')', j); if (i == std::string::npos || j == std::string::npos) { break; } // extract a "(shortName, longName, minVersion, maxVersion)" tuple s = mods.substr(i + 1, j - i - 1); q = s.find_first_of(',', p); std::string shortName = StringTrim(s.substr(p, q - p)); p = q + 1; q = s.find_first_of(',', p); std::string longName = StringTrim(s.substr(p, q - p)); p = q + 1; // q = s.find_first_of(',', p); std::string minVersion = StringTrim(s.substr(p, q - p)); p = q + 1; // std::string maxVersion = StringTrim(s.substr(p, q - p)); // to determine whether the current mod is supported, test if // 1. one of the "shortName" values is a substring of the mod archive-name, or // 2. one of the "longName" values is a substring of the mod human-name // // we do it this way because // 1. AI's can not retrieve the mod version (except by "looking" for it in the archive- or // human-name strings) nor the real short-name, so the alternatives are comparing mod // (archive- or human-)names directly or matching hashes // 2. a mod can unknowingly or deliberately break AI support when going from v0.1 to v0.2 // 3. the archive- and human-names of any given mod can be completely unrelated // 4. storing the exact human-name of every supported mod in AIInfo is a maintenance PITA // (since these typically change with every mod release, and mods are updated frequently) // 5. mod hashes are even more unfriendly to keep in AIInfo and also version-dependent // 6. comparing names without the version parts means greater flexibility for end-users if (modArchvName.find(shortName) != std::string::npos) { initialized = true; } if (modHumanName.find(longName ) != std::string::npos) { initialized = true; } i += 1; j += 1; p = 0; q = 0; } } if (!initialized) { return; } activeUnits.resize(MAX_UNITS, NULL); unitIDs.resize(MAX_UNITS, -1); for (int i = 0; i < MAX_UNITS; i++) { activeUnits[i] = new CUNIT(this); activeUnits[i]->uid = i; } logHandler = new CLogger(callbackHandler); luaConfigParser = new LuaParser(); commandTracker = new CCommandTracker(this); mathHandler = new CMaths(this); unitTable = new CUnitTable(this); metalMap = new CMetalMap(this); pathFinder = new CPathFinder(this); threatMap = new CThreatMap(this); unitHandler = new CUnitHandler(this); defenseMatrix = new CDefenseMatrix(this); ecoTracker = new CEconomyTracker(this); buildupHandler = new CBuildUp(this); attackHandler = new CAttackHandler(this); dgunControllerHandler = new CDGunControllerHandler(this); metalMap->Init(); unitTable->Init(); pathFinder->Init(); }
enum Boolean AnalyzeText(char *tempInputCommand) { enum Boolean labelFound=FALSE,firstField=TRUE,handleLineDone=FALSE; char *directive=NULL; enum ItemType type; char *tempItem=NULL; char *label=NULL,*command=NULL,*operands=NULL; int loc=0; enum Directive currentDirective; int *curLoc,stringLength; curLoc=&loc; stringLength=strlen(tempInputCommand); if(strlen(tempInputCommand)==0 || strcmp(tempInputCommand,"")==0) return FALSE; if(tempInputCommand[0]==';') return FALSE; while((*curLoc)<stringLength && handleLineDone==FALSE) { tempItem=ReadWord(tempInputCommand,curLoc,' '); tempItem=StringTrim(tempItem); if(tempItem[strlen(tempItem)-1]==':') { type=TLabel; labelFound=TRUE; } else if(tempItem[0]=='.') type=TDirective; else type=TCommand; switch(type) { case TDirective: /*directive*/ ALLOCATE_STRING(directive,strlen(tempItem)); strcpy(directive,tempItem); /* Create BMC */ CreateBmc(tempInputCommand+(*curLoc),directive,type,label,command,operands); handleLineDone=TRUE; currentDirective=WhatDirective(directive); if(currentDirective!=EXTERN && currentDirective !=ENTRY) HandleDirective(tempInputCommand,label,directive); else { operands=ReadWord(tempInputCommand,curLoc,' '); operands=StringTrim(operands); FIX_NULL_STRING(operands); AddLinkageItem(&Linkage_List,currentDirective,operands,"?"); } break; case TCommand: AnalyzeCommand(tempInputCommand); handleLineDone=TRUE; break; case TLabel: label=(char*)malloc(sizeof(char)); label=HandleLabel(tempItem,tempInputCommand,curLoc); break; default: /* cosmetics only*/ break; } firstField=FALSE; } return TRUE; }
/*function creates binary machine code for a command*/ void CreateBmcForCommand(char* line,char* label,opcode thisOpcode,char* paramSrc,char* paramDst,int addressingTypeSrc, int addressingTypeDst) { BinaryMachineCode bmc; int curLoc=0,curLocForSubItem=0,*pToCurloc; char *binaryValue=NULL,*bmcString=NULL,*tmpCharNum=NULL,*tmpOperands=NULL,*base_12_value=NULL,*subOperand,*tmpOpVar,*base_10=NULL; enum Boolean stopLoop=FALSE; Cmd tempCommand; pToCurloc=&curLoc; FIX_NULL_STRING(binaryValue); FIX_NULL_STRING(bmcString); FIX_NULL_STRING(base_12_value); FIX_NULL_STRING(base_10); strcpy(binaryValue,ConvertIntToCharByBase(0,ConversionToBmcType,2)); bmc = CreateBmcCode(binaryValue); bmc=AlterBmcValue(BmcOperationCode,OctalToDecimal(thisOpcode.value_8),bmc); bmc=AlterBmcValue(BmcSrcAddType,addressingTypeSrc,bmc); bmc=AlterBmcValue(BmcDstAddType,addressingTypeDst,bmc); if(addressingTypeSrc==4) /* register */ { ALLOCATE_STRING(tmpCharNum,2); tmpCharNum[0]=paramSrc[1]; tmpCharNum[1]='\0'; bmc=AlterBmcValue(BmcSrcReg,ConvertCharToInt(tmpCharNum),bmc); } if(addressingTypeDst==4) /* register */ { ALLOCATE_STRING(tmpCharNum,2); tmpCharNum[0]=paramDst[1]; tmpCharNum[1]='\0'; bmc=AlterBmcValue(BmcDstReg,ConvertCharToInt(tmpCharNum),bmc); } strcpy(base_12_value,ConvertBinaryStringToBase12(convertBinaryMachineCodeToString(bmc,BmcStyle))); /*FIX_NULL_STRING(tmpOperands);*/ ALLOCATE_STRING(tmpOperands,100); if(paramSrc!=NULL) /* when the function being called with two operands */ { strcpy(tmpOperands,paramSrc); strcat(tmpOperands,","); strcat(tmpOperands,paramDst); } else/* when the function being called with one operand */ strcpy(tmpOperands,paramDst); FIX_NULL_STRING(label); tempCommand=CreateCmdObject(label,ConvertIntToCharByBase(IC,ConversionToAddress,10),ConvertIntToCharByBase(IC,ConversionToAddress,12),thisOpcode.op,tmpOperands,bmc,base_12_value,'a'); CmdQueue_AddRecord(tempCommand,computerLanguage); IC++; label=""; for(;;) /* write additional operands */ { if(strlen(tmpOperands+curLoc)==0) break; subOperand=ReadWord(tmpOperands,pToCurloc,'['); if(subOperand==NULL) break; if(strcmp(subOperand,tmpOperands)==0) stopLoop=TRUE; if(strlen(subOperand)==0) break; subOperand=StringTrim(subOperand); if(IsMachineRegister(subOperand)==TRUE) continue; for(;;) { curLocForSubItem=0; pToCurloc=&curLocForSubItem; tmpOpVar=ReadWord(subOperand,pToCurloc,']'); tmpOpVar=StringTrim(tmpOpVar); if(IsMachineRegister(tmpOpVar)==TRUE) { if(*pToCurloc>=strlen(subOperand)) break; else continue; } if(tmpOpVar[0]=='#') { if(IsLegalNumber(tmpOpVar+1)==FALSE) { ErrorHandler(CompilingError,"operand errornous"); return; } strcpy(binaryValue,ConvertIntToCharByBase(ConvertCharToInt(tmpOpVar+1),ConversionToBmcType,2)); bmc=CreateBmcCode(binaryValue); strcpy(base_12_value,ConvertBinaryStringToBase12(binaryValue)); ALLOCATE_STRING(base_10,5); strcpy(base_10,ConvertIntToCharByBase(IC,ConversionToAddress,10)); tempCommand=CreateCmdObject(label,ConvertIntToCharByBase(IC,ConversionToAddress,10),ConvertIntToCharByBase(IC,ConversionToAddress,12),"","",bmc,base_12_value,' '); } else { strcpy(binaryValue,ConvertIntToCharByBase(0,ConversionToBmcType,2)); bmc=CreateBmcCode(binaryValue); strcpy(base_12_value,ConvertBinaryStringToBase12(binaryValue)); ALLOCATE_STRING(base_10,5); strcpy(base_10,ConvertIntToCharByBase(IC,ConversionToAddress,10)); tempCommand=CreateCmdObject(label,ConvertIntToCharByBase(IC,ConversionToAddress,10),ConvertIntToCharByBase(IC,ConversionToAddress,12),"?",tmpOpVar,bmc,base_12_value,' '); } CmdQueue_AddRecord(tempCommand,computerLanguage); IC++; if(*pToCurloc>=strlen(subOperand)) break; } pToCurloc=&curLoc; if(stopLoop==TRUE) break; } }
/* this function creates the binary machine code for all its given parameters*/ void CreateBmc(char* inputCommand,char* directive,enum ItemType type,char *label,char* command,char* operands) { enum Directive dir; char *tempWord=NULL; char *tempInputString=StringTrim(inputCommand); BinaryMachineCode bmc; char *base_12_value=NULL; char bmcCreator[BMC_LENGTH+1]={0}; char newBmc[BMC_LENGTH+1]={0},kind; int curLoc=0,castingInteger=0,number_of_items=0,i,*pToCurloc; Cmd tempCommand; pToCurloc=&curLoc; FIX_NULL_STRING(base_12_value); switch(type) { case TCommand: AnalyzeCommand(inputCommand); break; case TDirective: dir=WhatDirective(directive); switch(dir) { case STRING: kind=' '; newBmc[0]='\0'; tempWord=ReadWord(tempInputString,pToCurloc,' '); for(i=0;i<strlen(tempWord);i++) { if(tempWord[i]=='\"') continue; castingInteger=(int)tempWord[i]; strcpy(base_12_value,ConvertIntToCharByBase(castingInteger,ConversionToBase_12_Code,12)); strcpy(bmcCreator,ConvertIntToCharByBase(castingInteger,ConversionToBmcType,2)); for(curLoc=0;curLoc<(BMC_LENGTH-strlen(bmcCreator));curLoc++) { newBmc[curLoc]='0'; } newBmc[curLoc]='\0'; strcat(newBmc,bmcCreator); newBmc[BMC_LENGTH]='\0'; bmc=CreateBmcCode(newBmc); FIX_NULL_STRING(label); tempCommand=CreateCmdObject(label,ConvertIntToCharByBase(DC,ConversionToAddress,10),ConvertIntToCharByBase(DC,ConversionToAddress,12),directive,tempInputString,bmc,base_12_value,'d'); CmdQueue_AddRecord(tempCommand,computerLanguage); label=""; directive=""; tempInputString=""; DC++; } castingInteger=0; strcpy(bmcCreator,ConvertIntToCharByBase(0,ConversionToBmcType,2)); strcpy(base_12_value,ConvertIntToCharByBase(castingInteger,ConversionToBase_12_Code,12)); for(curLoc=0;curLoc<(BMC_LENGTH-strlen(bmcCreator));curLoc++) { newBmc[curLoc]='0'; } newBmc[curLoc]='\0'; strcat(newBmc,bmcCreator); bmc=CreateBmcCode(newBmc); tempCommand=CreateCmdObject(label,ConvertIntToCharByBase(DC,ConversionToAddress,10),ConvertIntToCharByBase(DC,ConversionToAddress,12),"","",bmc,base_12_value,'d'); CmdQueue_AddRecord(tempCommand,computerLanguage); DC++; break; case DATA: while(tempWord=ReadWord(tempInputString,pToCurloc,' ')) { if(tempWord==NULL) break; newBmc[0]='\0'; kind=' '; number_of_items++; if(IsLegalNumber(tempWord)==FALSE) { ErrorHandler(CompilingError,"One or more Not-a-number in .data array"); return; } castingInteger=ConvertCharToInt(tempWord); if(tempInputString[curLoc]==',') curLoc++; /* Single BMC creation - added to multi BMC link */ strcpy(bmcCreator, ConvertIntToCharByBase(castingInteger,ConversionToBmcType,2)); if(tempWord[0]=='-') bmcCreator[BMC_LENGTH]='\0'; for(i=0;i<(BMC_LENGTH-strlen(bmcCreator));i++) { newBmc[i]='0'; } newBmc[i]='\0'; FIX_NULL_STRING(label); strcat(newBmc,bmcCreator); newBmc[BMC_LENGTH]='\0'; bmc=CreateBmcCode(newBmc); FIX_NULL_STRING((base_12_value)); strcpy(base_12_value,ConvertIntToCharByBase(castingInteger,ConversionToBase_12_Code,12)); tempCommand=CreateCmdObject(label,ConvertIntToCharByBase(DC,ConversionToAddress,10),ConvertIntToCharByBase(DC,ConversionToAddress,12),directive,inputCommand,bmc,base_12_value,'d'); CmdQueue_AddRecord(tempCommand,computerLanguage); label=""; DC++; inputCommand=""; directive=""; } break; case NONE: break; default: break; } default: break; } }