Announcement

Collapse
No announcement yet.

error driving me insane - but can't see what's wrong

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • error driving me insane - but can't see what's wrong

    I have three files with the following values:

    file 1 contains:
    <span>192.168.100.1</span><br>
    <span>192.168.100.2</span><br>

    file 2 contains:
    <span>192.168.100.1</span><br>
    <span>192.168.100.1</span><br>

    file 3 is just empty:


    Code:
    --try reading last Folder from Registry
    LastFolder = Application.LoadValue("MultiThief", "LastFolder");
    checkforfolder = Folder.DoesExist(LastFolder);
    
    if checkforfolder == true then
    --do nothing
    elseif checkforfolder == false then
      LastFolder = _DesktopFolder;
    end;
    
    target_table = {};    --Creates a table whose values are empty
    sections2 = {};    --Creates a table whose values are empty
    
    webpage = Dialog.FileBrowse(true, "Locate File", LastFolder, "All Files (*.*)|*.*|", "", ".*", false, false);
    
    if (webpage[1] == "CANCEL") then
    Application.ExitScript();
    --removehtml()
    elseif (webpage[1] ~= "CANCEL") then
    mystring = TextFile.ReadToString(webpage[1]);
    --removehtml()
    end
    
    startposition = "0"
    
    regex = "<span>" .. '[0-9+\.]+' .. "</span>"
    	find1 = string.match(mystring, regex,startposition) --find the ip address in a string
    
    function strip()
       strip0 = String.Replace(find1, "<span>", "", false); -- remove <span> from the start of string
       strip1 = String.Replace(strip0, "</span>", "", false); -- remove </span> from the string so we are left with the IP
       result1 = String.Find(mystring, find1, 1, false); --get the start position of the IP
       nextposition = result1+1 --store the found address then add 1 so we can find the next ip address from this position
       Table.Insert(target_table, Table.Count(target_table)+1, strip1); -- count the previous entries in our table then add our new string to the last entry.
    end
    
    
    if find1 == nil then
        Dialog.Message("Notice", "No IP addresses found", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1); --prevent error message if no IP addresses were found
        Application.ExitScript(); --no point carrying on if no IP addresses are found.
        elseif find1 ~= nil then
        strip()
    end
    
    
    while( find1 ~= nil)  --do a loop to check for more IP's
    do
    	find1 = string.match(mystring, regex, nextposition) --find the ip address in a string
    if find1 == nil then
       break -- exit out of loop
       elseif find1 ~= nil then
       strip()
    end
    end
    --------------------------------------
    --error above here
    --------------------------------------
    
    filename = "AutoPlay\\Docs\\Config\\reaper.ini"
    sections2 = INIFile.GetSectionNames(filename);
    filestart = "/files/"
    
    table_values = Table.Concat(target_table, "\r\n", 1, TABLE_ALL);
    choice = Dialog.Message("IP's Found - would you like to download", table_values, MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);
    then some unimportant code under that...


    If file1 gets checked - I don't get any errors
    If file3 gets checked - I don't get any errors

    If file 2 gets checked - the app freezes with no errors, I know it's because both IP addresses found are the same but I don't know why it's freezing the app, does anyone have any idea? I have been at this for about 6 hours now and am no further forward that when I was when I begun.

    Cheers.

  • #2
    First note I can see here is that lua uses "Lua patterns" not regex so maybe you have to check that your patten is the corect format for lua, even it been the same ip shouldn't brake it.

    One of the whiles/loops could be creating a lock up its the only thing that makes sense as there is no other code in there what's really hard on AMS
    Plugins or Sources MokoX
    BunnyHop Here

    Comment


    • #3
      I think this part is stuck in an infinite loop:

      Code:
      while( find1 ~= nil)  --do a loop to check for more IP's
      do
      	find1 = string.match(mystring, regex, nextposition) --find the ip address in a string
      if find1 == nil then
         break -- exit out of loop
         elseif find1 ~= nil then
         strip()
      end
      end
      I think when it finds the duplicate IP it just keeps repeating -and reading that same IP over and over, but how would I put a check in here so it only reads once then continues to the next position in the file it's checking?

      Comment


      • #4
        Originally posted by mrdude View Post
        I think this part is stuck in an infinite loop:

        Code:
        while( find1 ~= nil)  --do a loop to check for more IP's
        do
        	find1 = string.match(mystring, regex, nextposition) --find the ip address in a string
        if find1 == nil then
           break -- exit out of loop
           elseif find1 ~= nil then
           strip()
        end
        end
        I think when it finds the duplicate IP it just keeps repeating -and reading that same IP over and over, but how would I put a check in here so it only reads once then continues to the next position in the file it's checking?
        This While is a little clearner don't need to check if its not nil again if you already know it does not = nil in the first place.

        Code:
        while( find1 ~= nil) do
        	find1 = string.match(mystring, regex, nextposition)
        	if find1 == nil then
        		break
        	else
        		strip()
        	end
        end
        I would say try looking at the Patten again maybe, if you could post a example of what your doing when I have 2 mins I can see if it does it this end and see if I can make it work with my brain that I don't have much of lol
        Plugins or Sources MokoX
        BunnyHop Here

        Comment


        • #5
          Thanks, if I change the strip function to this:

          Code:
          function strip()
             strip0 = String.Replace(find1, "<span>", "", false); -- remove <span> from the start of string
             strip1 = String.Replace(strip0, "</span>", "", false); -- remove </span> from the string so we are left with the IP
             result1 = String.Find(mystring, find1, 1, false); --get the start position of the IP
             nextposition = result1+1 --store the found address then add 1 so we can find the next ip address from this position   
             ---put check for dupe here:
             Dialog.Message("Notice", nextposition, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
             --end of check:  
             Table.Insert(target_table, Table.Count(target_table)+1, strip1); -- count the previous entries in our table then add our new string to the last entry.
          end
          and then the add a break in here:

          Code:
          while( find1 ~= nil) do
          	find1 = string.match(mystring, regex, nextposition)
          	if find1 == nil then
          		break
          	else
          	strip()
          	break
          	end
          end
          I can see that if a there are more than 1 IP address found that is the same it always returns to the same address (this is causing the infinite loop), I need to somehow get if to store that first found address and then ignore it and move on, it works ok if the string it searches doesn't have matching IP's in the file, so it's nothing to do with the search pattern I'm using.

          Cheers.

          Comment


          • #6
            If I change the while loop to this:

            Code:
            while( find1 ~= nil) do
            	find1 = string.match(mystring, regex, nextposition)
            	if find1 == nil then
            		break
            	else
            	result = Table.Count(target_table);
            	if result >= 10 then
            	Dialog.Message("Notice", "This page contains duplicate IP addresses\r\n" .. "Breaking out of a loop now\r\n" .. "Please check manually", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
            	break
            	else	
            	strip()
            end
            end
            end
            It breaks out once the table generated is equal or greater than 10 - If the search string doesn't contain identical IP's it put's them in the table until the table reaches 10 entries - if there is more than 1 identical address - every table entry is filled with that one IP.
            That shows where my problem is

            Comment


            • #7
              Originally posted by mrdude View Post
              If I change the while loop to this:

              Code:
              while( find1 ~= nil) do
              	find1 = string.match(mystring, regex, nextposition)
              	if find1 == nil then
              		break
              	else
              	result = Table.Count(target_table);
              	if result >= 10 then
              	Dialog.Message("Notice", "This page contains duplicate IP addresses\r\n" .. "Breaking out of a loop now\r\n" .. "Please check manually", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
              	break
              	else	
              	strip()
              end
              end
              end
              It breaks out once the table generated is equal or greater than 10 - If the search string doesn't contain identical IP's it put's them in the table until the table reaches 10 entries - if there is more than 1 identical address - every table entry is filled with that one IP.
              That shows where my problem is
              I know it will be a pain but have it do a dialog on each IP but add a count in the while so each time to adds one and make that the Dialogs title so you know its grabbing the IP's and finding them right lets see where its going wrong mabe that function does not return nil you see so try this maybe also fomate your code lol


              Code:
              MeCount = 0;
              
              while( find1 ~= nil) do
              	find1 = string.match(mystring, regex, nextposition);
              	if find1 == nil then
              		break
              	else
              		MeCount = MeCount +1;
              		
              		Dialog.Message("IP Found No:"..MeCount, "I found: "..find1, MB_OK, MB_ICONNONE, MB_DEFBUTTON1);
              		
              		result = Table.Count(target_table);
              		if result >= 10 then
              			Dialog.Message("Notice", "This page contains duplicate IP addresses\r\n" .. "Breaking out of a loop now\r\n" .. "Please check manually", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
              			break
              		else	
              			strip()
              		end
              	end
              end
              Try that to see what you get on the 3ed loop like I said you might not return nil it might be "" or -1
              Plugins or Sources MokoX
              BunnyHop Here

              Comment


              • #8
                Originally posted by kingzooly View Post
                I know it will be a pain but have it do a dialog on each IP but add a count in the while so each time to adds one and make that the Dialogs title so you know its grabbing the IP's and finding them right lets see where its going wrong mabe that function does not return nil you see so try this maybe also fomate your code lol


                Code:
                MeCount = 0;
                
                while( find1 ~= nil) do
                	find1 = string.match(mystring, regex, nextposition);
                	if find1 == nil then
                		break
                	else
                		MeCount = MeCount +1;
                		
                		Dialog.Message("IP Found No:"..MeCount, "I found: "..find1, MB_OK, MB_ICONNONE, MB_DEFBUTTON1);
                		
                		result = Table.Count(target_table);
                		if result >= 10 then
                			Dialog.Message("Notice", "This page contains duplicate IP addresses\r\n" .. "Breaking out of a loop now\r\n" .. "Please check manually", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
                			break
                		else	
                			strip()
                		end
                	end
                end
                Try that to see what you get on the 3ed loop like I said you might not return nil it might be "" or -1
                Thanks look at post #5 I already found the fault, when the string was getting search it was always starting from 0 so when it found a duplicate IP it always had the same address and filled a table with that address (and got stuck in a loop), now I know what the problem is I can fix it easily. Thanks again though for your help as I appreciate it.

                Comment


                • #9
                  Originally posted by mrdude View Post
                  Thanks look at post #5 I already found the fault, when the string was getting search it was always starting from 0 so when it found a duplicate IP it always had the same address and filled a table with that address (and got stuck in a loop), now I know what the problem is I can fix it easily. Thanks again though for your help as I appreciate it.
                  Not a problem, I would say use the debug tool but it always crashs on me so what I do these days is throw a dialog box in there testing easy part so I know its doing what I should glad you found it and I really glad you came back and explained witch part you found and fixed not many do that, hope your project success.
                  Plugins or Sources MokoX
                  BunnyHop Here

                  Comment

                  Working...
                  X