void HandleCommand(char *line,int* curPos,opcode thisOpcode,char* label) { BinaryMachineCode bmc; int decimal; char *binaryValue=NULL,*base12code=NULL,*param1=NULL,*param2=NULL; int addressingType1=NULL,addressingType2=NULL; enum Boolean errorFound=FALSE; Cmd tempCommand; char* errmsg=NULL; switch(thisOpcode.operand_count) { case 0: param1=ReadWord(line,curPos,' '); if(param1==NULL) FIX_NULL_STRING(param1); param1=StringTrim(param1); if(strlen(param1)>0 && IsDelimiter(param1[0],' ')==FALSE) { ALLOCATE_STRING(errmsg,50); strcpy(errmsg,thisOpcode.op); strcat(errmsg," - too many arguments for command "); ErrorHandler(CompilingError,errmsg); printf("b"); return; } decimal=OctalToDecimal(thisOpcode.value_8); FIX_NULL_STRING(binaryValue); strcpy(binaryValue,ConvertIntToCharByBase(0,ConversionToBmcType,2)); bmc = CreateBmcCode(binaryValue); bmc=AlterBmcValue(BmcOperationCode,OctalToDecimal(thisOpcode.value_8),bmc); /*strcpy(,convertBinaryMachineCodeToString(bmc,PrintStyle)); strcpy(binaryValue,ConvertIntToCharByBase(decimal,ConversionToBmcType,2)); ALLOCATE_STRING(bmcString,BMC_LENGTH+2); strcpy(bmcString,binaryValue); for(i=strlen(binaryValue);i<BMC_LENGTH;i++) bmcString[i]='0'; bmcString[i]='\0'; */ FIX_NULL_STRING(label); /*bmc=CreateBmcCode(bmcString);*/ FIX_NULL_STRING(base12code); strcpy(base12code,ConvertBinaryStringToBase12(convertBinaryMachineCodeToString(bmc,BmcStyle))); tempCommand=CreateCmdObject(label,ConvertIntToCharByBase(IC,ConversionToAddress,10),ConvertIntToCharByBase(IC,ConversionToAddress,12),thisOpcode.op,"",bmc,base12code,'a'); IC++; CmdQueue_AddRecord(tempCommand,computerLanguage); break; case 1: param2=ReadWord(line,curPos,' '); if(param2==NULL) { ALLOCATE_STRING(errmsg,50); strcpy(errmsg,thisOpcode.op); strcat(errmsg," - too few arguments for command "); ErrorHandler(CompilingError,errmsg); return; } addressingType2=IdentifyAddressing(param2); if(IsAddressingAllowedForCommand(addressingType2, thisOpcode.adddressing_type_dst)==FALSE) { ErrorHandler(CompilingError,"operand is not allowed for this command"); errorFound=TRUE; return; } param1=ReadWord(line,curPos,' '); if(param1!=NULL && strlen(param1)>0) { ALLOCATE_STRING(errmsg,50); strcpy(errmsg,thisOpcode.op); strcat(errmsg," - too many arguments for command "); ErrorHandler(CompilingError,errmsg); return; } CreateBmcForCommand(line,label,thisOpcode,param1,param2,NULL,addressingType2); break; case 2: param1=ReadWord(line,curPos,' '); param2=ReadWord(line,curPos,' '); if(param1==NULL || param2==NULL) { ALLOCATE_STRING(errmsg,50); strcpy(errmsg,thisOpcode.op); strcat(errmsg," - too few arguments for command: "); ErrorHandler(CompilingError,errmsg); return; } if(ReadWord(line,curPos,' ') !=NULL) { ALLOCATE_STRING(errmsg,50); strcpy(errmsg,thisOpcode.op); strcat(errmsg," - too many arguments for command: "); ErrorHandler(CompilingError,errmsg); return; } addressingType1=IdentifyAddressing(param1);/* source */ addressingType2=IdentifyAddressing(param2);/* destination */ if(IsAddressingAllowedForCommand(addressingType1, thisOpcode.adddressing_type_src)==FALSE) { ErrorHandler(CompilingError,"operand is not allowed for this command"); errorFound=TRUE; } if(IsAddressingAllowedForCommand(addressingType2, thisOpcode.adddressing_type_dst)==FALSE) { errorFound=TRUE; ErrorHandler(CompilingError,"operand is not allowed for this command"); } if(errorFound==TRUE) return; CreateBmcForCommand(line,label,thisOpcode,param1,param2,addressingType1,addressingType2); break; default: break; } }
/*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; } }
void MkfsOptions::ParseCommandLine(int argc, char** argv) { // Parse general options and retrieve unregistered options for own parsing. vector<string> options = Options::ParseCommandLine(argc, argv); // Read Volume URL from command line. po::positional_options_description p; p.add("mrc_volume_url", 1); po::options_description positional_options("Create Volume URL"); positional_options.add_options() ("mrc_volume_url", po::value(&xtreemfs_url), "volume to create"); // Parse command line. po::options_description all_descriptions; all_descriptions.add(positional_options).add(mkfs_descriptions_); po::variables_map vm; try { po::store(po::command_line_parser(options) .options(all_descriptions) .positional(p) .style(style::default_style & ~style::allow_guessing) .run(), vm); po::notify(vm); } catch(const std::exception& e) { // Rethrow boost errors due to invalid command line parameters. throw InvalidCommandLineParametersException(string(e.what())); } // Do not check parameters if the help shall be shown. if (show_help || empty_arguments_list || show_version) { return; } // Extract information from command line. Options::ParseURL(kMRC); // Check for MRC host if(service_addresses.empty()) { throw InvalidCommandLineParametersException("missing MRC host."); } else if (service_addresses.IsAddressList()) { throw InvalidCommandLineParametersException( "more than one MRC host was specified."); } else { mrc_service_address = service_addresses.GetAddresses().front(); } // Check for required parameters. if (volume_name.empty()) { throw InvalidCommandLineParametersException("missing volume name."); } // Abort the user explicitly specified numeric ids as owner. if (CheckIfUnsignedInteger(owner_username)) { throw InvalidCommandLineParametersException("Do not use numeric IDs as " "owner. Use names instead, e.g. \"root\" instead of \"0\"."); } if (CheckIfUnsignedInteger(owner_groupname)) { throw InvalidCommandLineParametersException("Do not use numeric IDs as " "owner group. Use names instead, e.g. \"root\" instead of \"0\"."); } // Convert the mode from octal to decimal. volume_mode_decimal = OctalToDecimal(volume_mode_octal); if (boost::iequals(access_policy_type_string, "NULL")) { access_policy_type = xtreemfs::pbrpc::ACCESS_CONTROL_POLICY_NULL; } else if (boost::iequals(access_policy_type_string, "POSIX")) { access_policy_type = xtreemfs::pbrpc::ACCESS_CONTROL_POLICY_POSIX; } else if (boost::iequals(access_policy_type_string, "VOLUME")) { access_policy_type = xtreemfs::pbrpc::ACCESS_CONTROL_POLICY_VOLUME; } else { throw InvalidCommandLineParametersException("Unknown access policy (" + access_policy_type_string + ") specified."); } if (boost::iequals(default_striping_policy_type_string, "RAID0")) { default_striping_policy_type = xtreemfs::pbrpc::STRIPING_POLICY_RAID0; } else { throw InvalidCommandLineParametersException("Currently the RAID0 striping" "policy is the only one available. Set the stripe width (see -w) to 1" " to disable striping at all."); } // Process volume attributes shortcuts. if (chown_non_root) { volume_attributes_strings.push_back("chown_non_root=true"); } if (grid_auth_mode_globus) { volume_attributes_strings.push_back("globus_gridmap=true"); } if (grid_auth_mode_unicore) { volume_attributes_strings.push_back("unicore_uudb=true"); } // Parse list of volume attributes. for (size_t i = 0; i < volume_attributes_strings.size(); i++) { // Check if there is exactly one "=" delimiter. size_t first_match = volume_attributes_strings[i].find_first_of("="); if (first_match == string::npos) { throw InvalidCommandLineParametersException("The attribute key/value pair" " " + volume_attributes_strings[i] + " misses a \"=\"."); } size_t next_match = volume_attributes_strings[i].find_first_of( "=", first_match + 1); if (next_match != string::npos) { throw InvalidCommandLineParametersException("The attribute key/value pair" " " + volume_attributes_strings[i] + " must not contain" " multiple \"=\"."); } // Parse attribute. KeyValuePair* attribute = new KeyValuePair(); attribute->set_key(volume_attributes_strings[i].substr(0, first_match)); attribute->set_value(volume_attributes_strings[i].substr( min(first_match + 1, volume_attributes_strings[i].length()), max(static_cast<size_t>(0), volume_attributes_strings[i].length() - first_match))); volume_attributes.push_back(attribute); } }