Re: show subscripts in dump - help and ideas requested
- Posted by jmduro May 14, 2015
- 1762 views
Hi Pete,
Would this do the job?
symtab = . [1] 1 . [2] 0 . [3] 3 . [4] 4 . [5] 0 . [6] 0 . [7] 0 . [8] 8 . [9] 0 . [10] 0 . [11] 0 . [12] 12 . [13] 0 . [14] 0 . [15] 15 . [16] . . [1] "C:\Program Files (x86)\Phix\builtins\" . . [2] "C:\Program Files (x86)\Phix\" . . [3] "C:\Program Files (x86)\Phix\demo\misc\eubins-mingw32\" . [17] . . [1] . . . [1] 3 . . . [2] "someotherfile.exw" . . [2] . . . [1] 3 . . . [2] "somefile.e" . . [3] . . . [1] 1 . . . [2] "prtnid2.e" . . [4] . . . [1] 1 . . . [2] "psprint.e" . . [5] . . . [1] 1 . . . [2] "pprntf.e" . [18] 26 . [19] 2 . [20] {-1073741819,0,32463637,32017528,253,32049420,0,0} . [21] . . [1] -1 . . [2] 8 . . [3] 1 . . [4] 2304 . . [5] 0 . . [6] 253 . . [7] "P" . . [8] 0 . . [9] 0 . . [10] 0 . . [11] 32452560 . . [12] {0,-77,28,35,38,-1,41,46,-1,49,52,55,-1,58,-1,124,155,163,210,256,259,280,291,307,345,352,396,434,-1,436,478,483,-2,501,550,-1,561,-3,577,625,662,700,712,727,738,-1,744,782,790,808,852,890,905,950,-2,957,962,970,972,983,-2,991,1033,1038,1048} . . [13] 1 . . [14] 0 . [22] 0
You can even add a user-defined translation routine for whole or parts of the sequence
symtab = . [1] 1 . [2] 0 . [3] 3 . [4] 4 . [5] 0 . [6] 0 . [7] 0 . [8] 8 . [9] 0 . [10] 0 . [11] 0 . [12] 12 . [13] 0 . [14] 0 . [15] 15 . [FOLDERS] . . [1] "C:\Program Files (x86)\Phix\builtins\" . . [2] "C:\Program Files (x86)\Phix\" . . [3] "C:\Program Files (x86)\Phix\demo\misc\eubins-mingw32\" . [FILE_TABLE] . . [1] . . . [ID] 3 . . . [FILENAME] "someotherfile.exw" . . [2] . . . [ID] 3 . . . [FILENAME] "somefile.e" . . [3] . . . [ID] 1 . . . [FILENAME] "prtnid2.e" . . [4] . . . [ID] 1 . . . [FILENAME] "psprint.e" . . [5] . . . [ID] 1 . . . [FILENAME] "pprntf.e" . [18] 26 . [19] 2 . [20] {-1073741819,0,32463637,32017528,253,32049420,0,0} . [21] . . [1] -1 . . [2] 8 . . [3] 1 . . [4] 2304 . . [5] 0 . . [6] 253 . . [7] "P" . . [8] 0 . . [9] 0 . . [10] 0 . . [11] 32452560 . . [12] {0,-77,28,35,38,-1,41,46,-1,49,52,55,-1,58,-1,124,155,163,210,256,259,280,291,307,345,352,396,434,-1,436,478,483,-2,501,550,-1,561,-3,577,625,662,700,712,727,738,-1,744,782,790,808,852,890,905,950,-2,957,962,970,972,983,-2,991,1033,1038,1048} . . [13] 1 . . [14] 0 . [22] 0
Here is the code
include std/text.e include std/io.e include std/search.e global integer f_debug ------------------------------------------------------------------------------ global type string(object x) -- checks if a sequence is a string atom is_string if sequence(x) then is_string = 1 for i = 1 to length(x) do if sequence(x[i]) then is_string = 0 else if (x[i] < ' ') and (x[i] != 9) and (x[i] != 13) and (x[i] != 10) then is_string = 0 end if if x[i]> 254 then is_string = 0 end if end if end for else is_string = 0 end if return is_string end type ------------------------------------------------------------------------------ global function showPrintable(object s) -- returns only printable characters of a sequence -- non printable characters are replace by a dot sequence res res = "" for i = 1 to length(s) do if integer(s[i]) then if (s[i] > 31) and (s[i] < 255) then res &= s[i] elsif s[i] = 9 then res &= "\\t" elsif s[i] = 13 then res &= "\\r" elsif s[i] = 10 then res &= "\\n" else res &= "." end if else res &= "." end if end for return res end function ------------------------------------------------------------------------------ procedure analyzeSequence(object x, sequence Name, integer Output=1, integer translator=0, sequence path={}, integer level=0, sequence prefix="") -- prints a sequence structure in a human readable way integer subSequence sequence s, offset if level=0 then printf(Output, "%s = ", {Name}) end if offset = "" for i = 1 to level do offset &= ". " end for s = "" if integer(x) then s = sprintf(" %d", {x}) puts(Output, offset&prefix&s&"\n") elsif atom(x) then if (x >= 0) and (x = floor(x)) then s = sprintf(" %.0f", {x}) elsif (x < 0) and (x = floor(x+1)) then s = sprintf(" %.0f", {x}) else s = sprintf(" %f", {x}) end if puts(Output, offset&prefix&s&"\n") elsif string(x) then if length(x) = 0 then s = "\"\"" else s = sprintf(" \"%s\"", {showPrintable(x)}) end if puts(Output, offset&prefix&s&"\n") else subSequence = 0 for i=1 to length(x) do if sequence(x[i]) then subSequence = 1 exit end if end for if subSequence = 0 then s = sprintf(" %s", {sprint(x)}) puts(Output, offset&prefix&s&"\n") else if length(s) = 0 then puts(Output, offset&prefix&"\n") end if for i=1 to length(x) do if translator > 0 then prefix = sprintf("[%s]", { call_func(translator, {path, level, i}) }) else prefix = sprintf("[%d]", i) end if analyzeSequence(x[i], Name, Output, translator, path&sprintf("[%d]", i), level+1, prefix) end for end if end if if Output=f_debug then flush(f_debug) end if end procedure
Here is the test program
constant symtab = {1,0,3,4,0,0,0,8,0,0,0,12,0,0,15, {"C:\\Program Files (x86)\\Phix\\builtins\\", "C:\\Program Files (x86)\\Phix\\", "C:\\Program Files (x86)\\Phix\\demo\\misc\\eubins-mingw32\\"}, {{3, "someotherfile.exw"}, {3, "somefile.e"}, {1, "prtnid2.e"}, {1, "psprint.e"}, {1, "pprntf.e"}}, 26,2, {-1073741819,0,32463637,32017528,253,32049420,0,0}, {-1,8,1,2304,0,253, "P", 0,0,0,32452560, {0,-77,28,35,38,-1,41,46,-1,49,52, 55,-1,58,-1,124,155,163,210,256,259,280, 291,307,345,352,396,434,-1,436,478,483,-2,501,550, -1,561,-3,577,625,662,700,712,727,738,-1,744,782, 790,808,852,890,905,950,-2,957,962,970,972,983,-2, 991,1033,1038,1048}, 1,0}, 0} function identifySymtabComponents(sequence path, integer level, integer n) -- printf(f_debug, " path: '%s', level: %d, n: %d\n", {path, level, n}) if level = 0 then if n = 16 then return "FOLDERS" elsif n = 17 then return "FILE_TABLE" end if elsif (level = 2) and begins("[17]", path) then if n = 1 then return "ID" elsif n = 2 then return "FILENAME" end if end if return sprintf("%d",n) end function f_debug = open("ex.err", "w") puts(f_debug, "without translator routine\n") analyzeSequence(symtab, "symtab", f_debug, 0) puts(f_debug, "\nwith translator routine\n") analyzeSequence(symtab, "symtab", f_debug, routine_id("identifySymtabComponents")) close(f_debug)
Best Regards
Jean-Marc