Exemplo n.º 1
0
 public override AbstractCommandEntryData Duplicate()
 {
     IfCommandData toret = new IfCommandData();
     toret.Result = Result;
     return toret;
 }
Exemplo n.º 2
0
 public override void Execute(CommandEntry entry)
 {
     IfCommandData data = new IfCommandData();
     data.Result = 0;
     entry.Data = data;
     CommandEntry IfEntry = null;
     CommandEntry Holder = entry.Queue.LastCommand;
     while (IfEntry == null && Holder != null)
     {
         if (Holder.BlockOwner == entry.BlockOwner)
         {
             if (Holder.Command.Name == "if" || Holder.Command.Name == "else")
             {
                 IfEntry = Holder;
             }
             break;
         }
         Holder = Holder.BlockOwner;
     }
     if (IfEntry == null)
     {
         entry.Bad("Else invalid: IF command did not preceed!");
         return;
     }
     if (((IfCommandData)IfEntry.Data).Result == 1)
     {
         entry.Good("Else continuing, IF passed.");
         return;
     }
     if (entry.Arguments.Count >= 1)
     {
         string ifbit = entry.GetArgument(0);
         if (ifbit.ToLower() != "if")
         {
             ShowUsage(entry);
             return;
         }
         else
         {
             List<string> parsedargs = new List<string>(entry.Arguments.Count);
             for (int i = 1; i < entry.Arguments.Count; i++)
             {
                 parsedargs.Add(entry.GetArgument(i));
             }
             bool success = IfCommand.TryIf(parsedargs);
             if (entry.Block != null)
             {
                 if (success)
                 {
                     entry.Good("Else if is true, executing...");
                     data.Result = 1;
                     entry.Queue.AddCommandsNow(entry.Block);
                 }
                 else
                 {
                     entry.Good("Else If is false, doing nothing!");
                 }
             }
         }
     }
     else
     {
         if (entry.Block != null)
         {
             entry.Good("Else is valid, executing...");
             data.Result = 1;
             entry.Queue.AddCommandsNow(entry.Block);
         }
         else
         {
             entry.Bad("Else invalid: No block follows!");
         }
     }
 }
Exemplo n.º 3
0
 public override void Execute(CommandEntry entry)
 {
     IfCommandData data = new IfCommandData();
     data.Result = 0;
     entry.Data = data;
     if (entry.Arguments.Count < 1)
     {
         ShowUsage(entry);
     }
     else
     {
         if (entry.Arguments[0] == "\0CALLBACK")
         {
             return;
         }
         if (entry.Block == null)
         {
             entry.Bad("If invalid: No block follows!");
             return;
         }
         List<string> parsedargs = new List<string>(entry.Arguments.Count);
         for (int i = 0; i < entry.Arguments.Count; i++)
         {
             parsedargs.Add(entry.GetArgument(i));
         }
         bool success = TryIf(parsedargs);
         if (success)
         {
             entry.Good("If is true, executing...");
             data.Result = 1;
             entry.Block.Add(new CommandEntry("if \0CALLBACK", null, entry,
                 this, new List<string> { "\0CALLBACK" }, "if", 0));
             entry.Queue.AddCommandsNow(entry.Block);
         }
         else
         {
             entry.Good("If is false, doing nothing!");
         }
     }
 }