HMS

Home Media Server for Roku Players
git clone https://www.brianlane.com/git/HMS
Log | Files | Refs | README | LICENSE

debugUtils.brs (2821B)


      1 '********************************************************************
      2 '**  Home Media Server Application - Debug functions
      3 '**  Copyright (c) 2022 Brian C. Lane All Rights Reserved.
      4 '********************************************************************
      5 
      6 '******************************************************
      7 'Dump the bytes of a string
      8 '******************************************************
      9 Sub DumpString(str As String)
     10     print "DUMP STRING"
     11     print "---------------------------"
     12     print str
     13     print "---------------------------"
     14     l = Len(str)-1
     15     i = 0
     16     for i = 0 to l
     17         c = Mid(str, i)
     18         val = Asc(c)
     19         print itostr(val)
     20     next
     21     print "---------------------------"
     22 End Sub
     23 
     24 
     25 '******************************************************
     26 'Walk a list and print it
     27 '******************************************************
     28 Sub PrintList(list as Object)
     29     print "---- list ----"
     30     PrintAnyList(0, list)
     31     print "--------------"
     32 End Sub
     33 
     34 
     35 '******************************************************
     36 'Print an associativearray
     37 '******************************************************
     38 Sub PrintAnyAA(depth As Integer, aa as Object)
     39     for each e in aa
     40         PrintAny(depth, e + ": ", aa[e])
     41     next
     42 End Sub
     43 
     44 
     45 '******************************************************
     46 'Print a list with indent depth
     47 '******************************************************
     48 Sub PrintAnyList(depth As Integer, list as Object)
     49     i = 0
     50     for each e in list
     51         PrintAny(depth, "List(" + itostr(i) + ")= ", e)
     52         i = i + 1
     53     next
     54 End Sub
     55 
     56 
     57 '******************************************************
     58 'Print anything
     59 '******************************************************
     60 Sub PrintAny(depth As Integer, prefix As String, any As Dynamic)
     61     if depth >= 10
     62         print "**** TOO DEEP " + itostr(5)
     63         return
     64     endif
     65     prefix = string(depth*2," ") + prefix
     66     depth = depth + 1
     67     str = AnyToString(any)
     68     if str <> invalid
     69         print prefix + str
     70         return
     71     endif
     72     if type(any) = "roAssociativeArray"
     73         print prefix + "(assocarr)..."
     74         PrintAnyAA(depth, any)
     75         return
     76     endif
     77     if islist(any) = true
     78         print prefix + "(list of " + itostr(any.Count()) + ")..."
     79         PrintAnyList(depth, any)
     80         return
     81     endif
     82 
     83     print prefix + "?" + type(any) + "?"
     84 End Sub
     85 
     86 
     87 '******************************************************
     88 'Print an object as a string for debugging. If it is
     89 'very long print the first 500 chars.
     90 '******************************************************
     91 Sub Dbg(pre As Dynamic, o=invalid As Dynamic)
     92     p = AnyToString(pre)
     93     if p = invalid p = ""
     94     if o = invalid o = ""
     95     s = AnyToString(o)
     96     if s = invalid s = "???: " + type(o)
     97     if Len(s) > 4000
     98         s = Left(s, 4000)
     99     endif
    100     print p + s
    101 End Sub
    102 
    103 
    104