@@ -101,21 +101,30 @@ String^ findVarValue(String^ input, VarType retAsVartype, String^% VarString) {
101101 return " NULL/ something go wrong in resolve index" ;
102102 }
103103 if (Information::IsNumeric (ArrayIndexValue)) { // / if it's resolved as int value then we used it
104+ if ((int )Str2duint (ArrayIndexValue) > ScriptFunList::VarList[indexofVar]->arrayLength -1 ) { // -1 because array begin from 0
105+ return " NULL/ value beggier than array index" ;
106+ }
104107 if (retAsVartype == VarType::str) {// / if we need ret var value as string it will back as str no need to change the value
105108 return ScriptFunList::VarList[indexofVar]->varvalue [(int )Str2duint (ArrayIndexValue)];
106109 }
107110 else // // but if the retAsVartype (ret value of the var) is int so we need to resolve it as int because array hold string
108111 {
109112 String^ intValue; // / we ret the int value from the array item
113+ if (ScriptFunList::VarList[indexofVar]->varvalue [(int )Str2duint (ArrayIndexValue)] == nullptr ) {
114+ return " NULL/ no value for this cell in the array" ;
115+ }
110116 if (CheckHexIsValid (ScriptFunList::VarList[indexofVar]->varvalue [(int )Str2duint (ArrayIndexValue)], intValue) == 0 ) { // / /// check the value of the vra if it's not Numeric then if could be Hex
111117 return " NULL/ array value is not Numeric" ;// / that something wrong in the index of the array
112118 }
113119 else {
114- return intValue;
120+ return intValue;
115121 }
116122 }
117123 }
118124 String^ intValue;
125+ if ((int )Str2duint (ArrayIndexValue) > ScriptFunList::VarList[indexofVar]->arrayLength - 1 ) { // -1 because array begin from 0
126+ return " NULL/ value beggier than array index" ;
127+ }
119128 if (CheckHexIsValid (ArrayIndexValue, intValue) == 0 ) { // / /// check if array index is not Numeric then if could be Hex
120129 return " NULL/ array index is not Numeric" ;// / that something wrong in the index of the array
121130 }
@@ -237,13 +246,13 @@ String^ ForWard(String^ input, int tokenindex, String^% VarString) { /// tokenin
237246 {
238247 temp = temp->Substring (tokenindex, temp->Length - tokenindex); // get value after token
239248 int i1 = 0 ;
240- if (i1 + 1 < temp->Length ) {
241- while (temp->Substring (i1 + 1 , 1 ) == " " ) // / count how many spaces
242- {
243- VarString = " " + VarString;
244- if (i1 + 1 > input->Length ) { break ; } // if we reach the begin of the string
245- i1 += 1 ;
246- }
249+ if (i1 + 1 < temp->Length ) {
250+ while (temp->Substring (i1 + 1 , 1 ) == " " ) // / count how many spaces
251+ {
252+ VarString = " " + VarString;
253+ if (i1 + 1 > input->Length ) { break ; } // if we reach the begin of the string
254+ i1 += 1 ;
255+ }
247256 }
248257 temp = temp->Trim (); // / remove all spaces after token like >> 55 + 10
249258 int i = 0 ;
@@ -254,7 +263,7 @@ String^ ForWard(String^ input, int tokenindex, String^% VarString) { /// tokenin
254263 if (i + 1 > temp->Length ) { break ; } // if we reach the begin of the string
255264 }
256265 if (value_ == " " ) {
257- value_ = temp;
266+ value_ = temp;
258267 }
259268
260269 VarString = value_ + VarString;
@@ -709,11 +718,12 @@ String^ GetArgValueByType(String^ argument, VarType type_) { /// return value b
709718 }
710719 else {
711720 // / as it's str we return the int value to hex value
712- String^ oldv= " " ;
713- if (CheckHexIsValid (tempInput, oldv)) {
714- if (!tempInput->StartsWith (" 0x" )) {
721+ String^ oldv = " " ;
722+ if (CheckHexIsValid (tempInput, oldv)) {
723+ /* if (!tempInput->StartsWith("0x")) {
715724 tempInput = "0x" + tempInput->Trim();
716- }
725+ }*/
726+ tempInput = tempInput->Trim ();
717727 }
718728 argument = ReplaceAtIndex (argument, oldValue, tempInput);
719729 }
@@ -730,16 +740,90 @@ String^ GetArgValueByType(String^ argument, VarType type_) { /// return value b
730740 return argument;
731741}
732742
743+ String^ returnSpaces(int SpaceNum) { // / used for replaceValueBetweenBrackets to fill the gaps with spaces
744+ String^ temp;
745+ for (int i = 0 ; i < SpaceNum; i++)
746+ {
747+ temp = temp + " " ;
748+ }
749+ return temp;
750+ }
751+
752+ // / used in cases $x[$z[3]] nasted variables (array)
753+ String^ replaceValueBetweenBrackets(String^ input_) {
754+ String^ tempstr;
755+ if ((input_->Contains (" [" )) && (input_->Contains (" ]" ))) {
756+ // / setx $c,$x[$z[3]]
757+ String^ Tinput = input_;
758+ int beginB = input_->LastIndexOf (" [" ) + 1 ;
759+ tempstr = input_->Substring (beginB, input_->Length - beginB);
760+ int EndB = tempstr->IndexOf (" ]" );
761+ tempstr = tempstr->Substring (0 , EndB);
762+
763+ while (beginB > 0 )
764+ {
765+ if (tempstr->Trim ()->StartsWith (" $" )) {
766+ String^ newValue = StrAnalyze (tempstr, VarType::int_); // / we get int value after Analyze so we should make it hex
767+ if (newValue->Contains (" NULL/" )) {
768+ return " NULL/" ;
769+ }
770+ if ((Information::IsNumeric (newValue))) {
771+ input_ = ReplaceAtIndex (input_, tempstr, str2Hex (newValue,VarType::int_,false ));
772+ Tinput = ReplaceAtIndex (Tinput, " [" + tempstr + " ]" , returnSpaces ((Tinput, " [" + tempstr + " ]" )->Length ));
773+ }
774+ }
775+ else
776+ {
777+ Tinput = ReplaceAtIndex (Tinput, " [" + tempstr + " ]" , returnSpaces ((Tinput, " [" + tempstr + " ]" )->Length ));
778+ }
779+ int beginB = Tinput->LastIndexOf (" [" ) + 1 ;
780+ if (beginB <= 0 )
781+ break ;
782+ tempstr = Tinput->Substring (beginB, Tinput->Length - beginB);
783+ int EndB = tempstr->IndexOf (" ]" );
784+ tempstr = input_->Substring (beginB, EndB);
785+
786+ }
787+ }
788+ // while ((input_->Contains("[")) && (input_->Contains("]")))
789+ // {
790+ // /// setx $c,$x[$z[3]]
791+ // int beginB = input_->LastIndexOf("[")+1; //
792+ // String^ tempstr = input_->Substring(beginB, input_->Length - beginB);
793+ // int EndB = tempstr->IndexOf("]");
794+ // tempstr = tempstr->Substring(0, EndB); //
795+ // String^ newValue = StrAnalyze(tempstr, VarType::int_);
796+ // if ((!Information::IsNumeric(newValue))) {
797+ // return "NULL/";
798+ // }
799+ // else
800+ // {
801+ // input_=ReplaceAtIndex(input_, tempstr, newValue);
802+ // }
803+
804+ // }
805+
806+ return input_;
807+ }
808+
733809String^ StrAnalyze(String^ input, VarType type_) { // / in case it int all value should be int , other wise it would be str and we add str to gather
734810 array <String^>^ breaks = { " *" ," /" ," +" ," -" ," $" ," " , " {" , " }" , " \" " };
735811 array <String^>^ token_ = { " *" ," /" ," +" ," -" };
736812 array <String^>^ vars_ = { " $" ," " , " {" , " \" " };
737813 Generic::List <String^>^ StrHolderList = gcnew Generic::List <String^>;
738- String^ temp =" " ;
814+ String^ temp = " " ;
739815 int begin_ = 0 ;
740816 if (input == " " ) {
741817 return input;
742818 }
819+ // / in cases like this
820+ // / setx $c,$x[$z[3]] here we have nested
821+ String^ retvalue = replaceValueBetweenBrackets (input);
822+ if (!retvalue->Contains (" NULL/" ))
823+ input = retvalue;
824+ else
825+ return " NULL/" ;
826+ // /
743827 if (Array::IndexOf (vars_, input->Substring (0 , 1 )) >= 0 ) {// / if (i=0) begin with vars defenations this we need to add it
744828
745829 if (input->Substring (0 , 1 ) == " " ) { // / in case calc str or array we need spaces
@@ -803,7 +887,7 @@ String^ StrAnalyze(String^ input, VarType type_) { /// in case it int all value
803887 }
804888
805889 }
806-
890+
807891 for (int i = begin_; i < input->Length ; i++)
808892 {
809893 if (Array::IndexOf (breaks, input->Substring (i, 1 )) < 0 ) {
@@ -891,7 +975,7 @@ String^ StrAnalyze(String^ input, VarType type_) { /// in case it int all value
891975 }
892976 }
893977 if (Array::IndexOf (token_, input->Substring (i, 1 )) >= 0 ) {
894- if ((temp != " " )|| ((temp == nullptr )) ) {
978+ if ((temp != " " ) || ((temp == nullptr ))) {
895979 StrHolderList->Add (temp);
896980 }
897981 StrHolderList->Add (input->Substring (i, 1 ));
@@ -904,7 +988,7 @@ String^ StrAnalyze(String^ input, VarType type_) { /// in case it int all value
904988 temp = " " ;
905989 }
906990 }
907- if (temp->Length ==1 ) { // case enter 1 special char
991+ if (temp->Length == 1 ) { // case enter 1 special char
908992 StrHolderList->Add (temp);
909993 temp = " " ; // / rest temp
910994 }
@@ -935,16 +1019,16 @@ String^ StrAnalyze(String^ input, VarType type_) { /// in case it int all value
9351019 case str:
9361020 {
9371021 for (int i = 0 ; i < StrHolderList->Count ; i++)
938- {
939- if (Array::IndexOf (token_, StrHolderList[i]) < 0 ) {
940- StrHolderList[i] = GetArgValueByType (StrHolderList[i], VarType::str);
941- StrHolder = StrHolder + StrHolderList[i];
942- }
943- else
944- {
945- StrHolder = StrHolder + StrHolderList[i];
946- }
947-
1022+ {
1023+ if (Array::IndexOf (token_, StrHolderList[i]) < 0 ) {
1024+ StrHolderList[i] = GetArgValueByType (StrHolderList[i], VarType::str);
1025+ StrHolder = StrHolder + StrHolderList[i];
1026+ }
1027+ else
1028+ {
1029+ StrHolder = StrHolder + StrHolderList[i];
1030+ }
1031+
9481032 }
9491033 break ;
9501034 }
0 commit comments