Author Topic: text file scanner  (Read 5489 times)

0 Members and 1 Guest are viewing this topic.

Offline UOMaddog

  • Maddog
  • Elite
  • *
  • *
  • Posts: 1620
  • Activity:
    0%
  • Reputation Power: 22
  • UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...
  • Gender: Male
  • Biggest B@D@$$ of the Universe
  • Respect: +165
  • Referrals: 8
    • View Profile
    • My Website
Re: text file scanner
« Reply #15 on: April 13, 2011, 04:47:55 PM »
0
I'm scared to ask, but does it have the .NET framework installed on it?
There are 10 kinds of people in this world: those that understand binary and those that don't!

Windows:  A 64-bit tweak of a 32-bit extension to a 16-bit user interface for an 8-bit operating system based on a 4-bit architecture from a 2-bit company that can't stand 1 bit of competition!

Offline KhameleonTopic starter

  • Script Tester - Team Leader
  • Elite
  • *
  • *
  • Posts: 2568
  • Activity:
    0%
  • Reputation Power: 30
  • Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!
  • Gender: Male
  • Respect: +237
  • Referrals: 0
    • View Profile
Re: text file scanner
« Reply #16 on: April 13, 2011, 05:28:57 PM »
0
honestly couldn't tell you the truth.  I highly doubt it. ;(

Online Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5288
  • Activity:
    0%
  • Reputation Power: 60
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +386
  • Referrals: 1
    • View Profile
Re: text file scanner
« Reply #17 on: April 13, 2011, 05:57:35 PM »
0
could always write it in lua... :)  and install a version of openEUO on his work machine.  lol

I joke but it would work perfect.

Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline KhameleonTopic starter

  • Script Tester - Team Leader
  • Elite
  • *
  • *
  • Posts: 2568
  • Activity:
    0%
  • Reputation Power: 30
  • Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!
  • Gender: Male
  • Respect: +237
  • Referrals: 0
    • View Profile
Re: text file scanner
« Reply #18 on: April 13, 2011, 05:59:56 PM »
0
Does lua work without UO installed :P

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 12946
  • Activity:
    1.2%
  • Reputation Power: 150
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1331
  • Referrals: 32
    • View Profile
    • ScriptUO
Re: text file scanner
« Reply #19 on: April 14, 2011, 07:14:08 AM »
0
It sure does.  Lua is a general purpose scripting language used in other places in the world.  I actually have used it a few times stand-alone to parse data for my job.
Please read the ScriptUO site RULES
Come play RIFT with me!

Online Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5288
  • Activity:
    0%
  • Reputation Power: 60
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +386
  • Referrals: 1
    • View Profile
Re: text file scanner
« Reply #20 on: April 14, 2011, 08:40:11 AM »
0
It would be/should be pretty easy to knock out a file parser in lua.

If i understood what the hell you where trying to do .. Id help.  Heres some code to get you going

Code: [Select]
function LoadData(fn)    -- by Cheffe
  local f,e = openfile(fn,"r")          --r means read-only (default)
  if f then                             --anything other than nil/false evaluates to true
    local s = f:read("*a")              --*a means read all
    f:close()
    return s
  else                                  --if openfile fails it returns nil plus an error message
    error(e,2)                          --stack level 2, error should be reported
  end                                   --from where LoadData() was called!
end

function EN_StringToStringTable(s)   -- imperfect code but suffices
  local t = {}
  local NewLineAt = 0
  local line = ''  
  local EOL = string.char(10)
  s = s..EOL..'**THEEND**'
  --print(string.byte(string.sub(s,22,22)))
  repeat
    NewLineAt = string.find(s, EOL)
    line = string.sub(s, 1 , NewLineAt - 1)    
    table.insert(t, { Line=line })
    s = string.sub(s, NewLineAt + 1, string.len(s))
    --print(line)
  until s == '**THEEND**'
  return t
end

------
local sFile = LoadData('filename')  -- one big string of the files contents.
local sStringTable = EN_StringToStringTable(sFile)  --

for k=1,table.maxn(sStringTable) do
   print(sStringTable[k].Line)

Of course i didnt test any of the above... but should open file load as a string, convert to a table/array of strings/lines. Print each line.

Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline UOMaddog

  • Maddog
  • Elite
  • *
  • *
  • Posts: 1620
  • Activity:
    0%
  • Reputation Power: 22
  • UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...
  • Gender: Male
  • Biggest B@D@$$ of the Universe
  • Respect: +165
  • Referrals: 8
    • View Profile
    • My Website
Re: text file scanner
« Reply #21 on: April 14, 2011, 09:39:12 AM »
0
Well while EN's on a roll, here's what I can tell from these files EN:

-Each time you have a line that contains a "(" and ")" it means a new tool, so print it out
-Each time you have a line that contains a "Z" it means a Z-coordinate (haven't seen any other Zs in other lines and oh well if you have a few extra lines), so print it out

I believe that's all he's looking for, but I'll read over his initial post again
There are 10 kinds of people in this world: those that understand binary and those that don't!

Windows:  A 64-bit tweak of a 32-bit extension to a 16-bit user interface for an 8-bit operating system based on a 4-bit architecture from a 2-bit company that can't stand 1 bit of competition!

Offline KhameleonTopic starter

  • Script Tester - Team Leader
  • Elite
  • *
  • *
  • Posts: 2568
  • Activity:
    0%
  • Reputation Power: 30
  • Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!
  • Gender: Male
  • Respect: +237
  • Referrals: 0
    • View Profile
Re: text file scanner
« Reply #22 on: April 14, 2011, 11:33:28 AM »
0
ya that's the Jist of it.. I'd like to Output something like this

Code: [Select]
Tool 1: Z 0
Tool 2: Z -4.5
Tool 3: z -.5
Ect.

in the case there are Multiple Z depths print the Farthest Z Depth.


So Far when I run the Script In LUA I get an error before I can do anything.
!C:\OpenEUO\scripts\cnc z depth.lua:34: 'end' expected (to close 'for' at line 33) near '<eof>'

Online Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5288
  • Activity:
    0%
  • Reputation Power: 60
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +386
  • Referrals: 1
    • View Profile
Re: text file scanner
« Reply #23 on: April 14, 2011, 12:45:41 PM »
0
Quote from: Khameleon link=topic=6725.msg63864#msg63864
in the case there are Multiple Z depths print the Farthest Z Depth.
[/quote

As in the LOWEST NUMBER ??
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline KhameleonTopic starter

  • Script Tester - Team Leader
  • Elite
  • *
  • *
  • Posts: 2568
  • Activity:
    0%
  • Reputation Power: 30
  • Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!
  • Gender: Male
  • Respect: +237
  • Referrals: 0
    • View Profile
Re: text file scanner
« Reply #24 on: April 14, 2011, 12:47:54 PM »
0
right. z 0 would be the the TOP of a part, as Z -2.000 means the Tool, usually a Drill will drill a hole -2.000 inches so to answer your question I'm looking for the Deepest Z per tool.

Online Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5288
  • Activity:
    0%
  • Reputation Power: 60
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +386
  • Referrals: 1
    • View Profile
Re: text file scanner
« Reply #25 on: April 14, 2011, 01:10:40 PM »
0
Right before i go any further... the code below makes the below output .. please examine the output and tell me if its

(a) Picking up the tools correctly
(b) Picking up all the Zs for a certain tool

Note: Right now it just prints all the z lines and Tool lines it doesnt parse out the values yet.

Code: [Select]
function LoadData(fn)    -- by Cheffe
  local f,e = openfile(fn,"r")          --r means read-only (default)
  if f then                             --anything other than nil/false evaluates to true
    local s = f:read("*a")              --*a means read all
    f:close()
    return s
  else                                  --if openfile fails it returns nil plus an error message
    error(e,2)                          --stack level 2, error should be reported
  end                                   --from where LoadData() was called!
end

function EN_StringToStringTable(s)   -- imperfect code but suffices
  local t = {}
  local NewLineAt = 0
  local line = ''  
  local EOL = string.char(10)
  s = s..EOL..'**THEEND**'
  --print(string.byte(string.sub(s,22,22)))
  repeat
    NewLineAt = string.find(s, EOL)
    line = string.sub(s, 1 , NewLineAt - 1)    
    table.insert(t, line )
    s = string.sub(s, NewLineAt + 1, string.len(s))
    --print(line)
  until s == '**THEEND**'
  return t
end

function DoIt(fn)
  local sFile = LoadData(fn)  -- one big string of the files contents.
  local sT = EN_StringToStringTable(sFile)  

  local tools = 0
  local z = {}
  for k=1,table.maxn(sT) do
     s = sT[k]
--     print(s)

     if string.match(s,'TOOL T')  then      
         tools = tools + 1
         print('TOOL '..tools..':= '..s)
         end
     if string.match(s,'Z') then
        print('         z:= '..s)
        z[tools] = tools
        end            
     end
    
--  for k=1,tools do
--     print('Tool '..k..': Z '..z[k])  
--     end
    
--  for k=1,table.maxn(sT) do print(sT[k]) end  
end

---------------
DoIt('cnc.nc')

Output from running against your file.
Code: [Select]
TOOL 1:= N13T1M06  *(---- TOOL T1  OFFSET H1---)
         z:= N16G43H1Z.1M07
         z:= N18G1Z0.F20.
         z:= N46G0Z.1
         z:= N48G0H0Z0.M09
TOOL 2:= N49T2M06  *---- (TOOL T2  OFFSET H2---)
         z:= N53G43H2Z.1M07
         z:= N55G1Z-.05F20.
         z:= N62G0Z.1
         z:= N65G1Z-.1F20.
         z:= N72G0Z.1
         z:= N75G1Z-.15F20.
         z:= N82G0Z.1
         z:= N85G1Z-.2F20.
         z:= N92G0Z.1
         z:= N95G1Z-.25F20.
         z:= N102G0Z.1
         z:= N105G1Z-.3F20.
         z:= N112G0Z.1
         z:= N115G1Z-.35F20.
         z:= N122G0Z.1
         z:= N125G1Z-.4F20.
         z:= N132G0Z.1
         z:= N135G1Z-.05F20.
         z:= N141G0Z.1
         z:= N144G1Z-.1F20.
         z:= N150G0Z.1
         z:= N153G1Z-.15F20.
         z:= N159G0Z.1
         z:= N162G1Z-.2F20.
         z:= N168G0Z.1
         z:= N171G1Z-.25F20.
         z:= N177G0Z.1
         z:= N180G1Z-.3F20.
         z:= N186G0Z.1
         z:= N189G1Z-.35F20.
         z:= N195G0Z.1
         z:= N198G1Z-.4F20.
         z:= N204G0Z.1
         z:= N206G0H0Z0.M09
TOOL 3:= N207T3M06  *---- (TOOL T3  OFFSET H3---)
         z:= N211G43H3Z.1M07
         z:= N213G1Z-.4F20.
         z:= N220G0Z.1
         z:= N223G1Z-.4F20.
         z:= N230G0Z.1
         z:= N233G1Z-.4F20.
         z:= N240G0Z.1
         z:= N242G0H0Z0.M09
TOOL 4:= N243T4M06  *---- (TOOL T4  OFFSET H4---)
         z:= N247G43H4Z.1M07
         z:= N249G99G81X-1.625Y-1.75Z-.23R0.1F6.
         z:= N252G0G80Z.1
         z:= N254G0H0Z0.M09
TOOL 5:= N255T5M06  *---- (TOOL T5  OFFSET H5---)
         z:= N259G43H5Z.1M07
         z:= N261G99G83X-1.625Y-1.75Z-.6R0.1Q.04F5.
         z:= N264G0G80Z.1
         z:= N266G0H0Z0.M09
TOOL 6:= N267T6M06  *---- (TOOL T6  OFFSET H6---)
         z:= N271G43H6Z.1M07
         z:= N273G99G83X-1.625Y-1.75Z-.3R0.1Q.04F4.
         z:= N276G0G80Z.1
         z:= N278G0H0Z0.M09
TOOL 7:= N279T7M06  *---- (TOOL T7  OFFSET H7---)
         z:= N283G43H7Z.1M07
         z:= N285G99G81X-1.625Y-.75Z-.11R0.1F6.
         z:= N289G0G80Z.1
         z:= N291G0H0Z0.M09
TOOL 8:= N292T8M06  *---- (TOOL T8  OFFSET H8---)
         z:= N296G43H8Z.1M07
         z:= N298G99G83X-1.625Y-.75Z-.6R0.1Q.04F5.
         z:= N302G0G80Z.1
         z:= N304G0H0Z0.M09
TOOL 9:= N305T9M06  *---- (TOOL T9  OFFSET H9---)
         z:= N309G43H9Z.5M07
         z:= N311G99G84X-1.625Y-.75Z-.5R0.5F350.Q.0313
         z:= N315G0G80Z.5
         z:= N317G0H0Z0.M09
TOOL 10:= N318T10M06  *---- (TOOL T10  OFFSET H10---)
         z:= N322G43H10Z.1M07
         z:= N325G1Z-.012F5.
         z:= N327G0Z.1
         z:= N329G0H0Z0.M09
TOOL 11:= N330T11M06  *---- (TOOL T11  OFFSET H11---)
         z:= N334G43H11Z.1M07
         z:= N336G1Z-.015F5.
         z:= N338G0Z.1
         z:= N341G1Z-.015
         z:= N347G0Z.1
         z:= N349G1Z-.015
         z:= N355G0Z.1
         z:= N358G1Z-.015
         z:= N360G0Z.1
         z:= N363G1Z-.015
         z:= N374G0Z.1
         z:= N377G1Z-.015
         z:= N388G0Z.1
         z:= N391G1Z-.015
         z:= N393G0Z.1
         z:= N395G0H0Z0.M09

« Last Edit: April 14, 2011, 01:14:44 PM by Endless Night »
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Online Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5288
  • Activity:
    0%
  • Reputation Power: 60
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +386
  • Referrals: 1
    • View Profile
Re: text file scanner
« Reply #26 on: April 14, 2011, 02:05:20 PM »
0
ALL DONE....
NOTE if you get a Z value of 1000 then a z value was never set.


Code: [Select]
function LoadData(fn)    -- by Cheffe
  local f,e = openfile(fn,"r")          --r means read-only (default)
  if f then                             --anything other than nil/false evaluates to true
    local s = f:read("*a")              --*a means read all
    f:close()
    return s
  else                                  --if openfile fails it returns nil plus an error message
    error(e,2)                          --stack level 2, error should be reported
  end                                   --from where LoadData() was called!
end

function EN_StringToStringTable(s)   -- imperfect code but suffices
  local t = {}
  local NewLineAt = 0
  local line = ''  
  local EOL = string.char(10)
  s = s..EOL..'**THEEND**'
  --print(string.byte(string.sub(s,22,22)))
  repeat
    NewLineAt = string.find(s, EOL)
    line = string.sub(s, 1 , NewLineAt - 1)    
    table.insert(t, line )
    s = string.sub(s, NewLineAt + 1, string.len(s))
    --print(line)
  until s == '**THEEND**'
  return t
end

function DoIt(fn)
  local sFile = LoadData(fn)  -- one big string of the files contents.
  local sT = EN_StringToStringTable(sFile)  

  local tools = 0
  local t = {}
  local z = {}
  for k=1,table.maxn(sT) do
     s = sT[k]
     -- Strip Comments
     if string.match(s, '*') then  s = string.sub(s, 1 , string.find(s, '*') - 1) end    

     if string.match(s,'M06')  then
         tools = tools + 1
         t[tools] = string.sub(s , string.find(s,'T') + 1, string.find(s,'M06')-1 ) -- Tool Number
         z[tools] = 1000
         end
     if string.match(s,'Z') then
        -- extact Z Value
        s = string.sub(s, string.find(s, 'Z') + 1, string.len(s))
        if string.find(s, "%a+") then  s = string.sub(s, 1, string.find(s, "%a+") - 1 ) end
        local y = tonumber(s)    
        if y < z[tools] then z[tools] = y end
        end            
     end
    
   for k=1,tools do
      print('Tool '..t[k]..': Z '..z[k])  
      end
    
--  for k=1,table.maxn(sT) do print(sT[k]) end  
end

---------------
DoIt('cnc.nc')

Output from above using test file
Code: [Select]
Tool 1: Z 0
Tool 2: Z -0.4
Tool 3: Z -0.4
Tool 4: Z -0.23
Tool 5: Z -0.6
Tool 6: Z -0.3
Tool 7: Z -0.11
Tool 8: Z -0.6
Tool 9: Z -0.5
Tool 10: Z -0.012
Tool 11: Z -0.015


Id advise that you test this against alot of test file to determine if works correctly in all circumstances... but it works correctly for the one test file i tried it against.
« Last Edit: April 14, 2011, 02:09:29 PM by Endless Night »
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline KhameleonTopic starter

  • Script Tester - Team Leader
  • Elite
  • *
  • *
  • Posts: 2568
  • Activity:
    0%
  • Reputation Power: 30
  • Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!
  • Gender: Male
  • Respect: +237
  • Referrals: 0
    • View Profile
Re: text file scanner
« Reply #27 on: April 14, 2011, 02:16:19 PM »
0
awesome.. that works great... I had to be a bug, but is there a way select a file sorta like an open file?

Online Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5288
  • Activity:
    0%
  • Reputation Power: 60
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +386
  • Referrals: 1
    • View Profile
Re: text file scanner
« Reply #28 on: April 14, 2011, 02:18:16 PM »
0
awesome.. that works great... I had to be a bug, but is there a way select a file sorta like an open file?

Glad it works great...   My skill in Lua sadly hasnt stretched to the GUI yet...  if i get time tommorrow ill take a look unless someone else cares to jump in at this point.
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Tags: