n_cst_sst.sru 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. $PBExportHeader$n_cst_sst.sru
  2. forward
  3. global type n_cst_sst from nonvisualobject
  4. end type
  5. type st_extsst_item from structure within n_cst_sst
  6. end type
  7. end forward
  8. type st_extsst_item from structure
  9. powerobject classdefinition
  10. unsignedinteger ii_relative_pos
  11. ulong il_absolute_pos
  12. end type
  13. global type n_cst_sst from nonvisualobject
  14. end type
  15. global n_cst_sst n_cst_sst
  16. type variables
  17. PUBLIC n_cst_unicode_hash_long invo_hash
  18. PUBLIC n_cst_unicode invo_unicode
  19. PUBLIC n_xls_subroutines invo_sub
  20. PUBLIC ULONG il_total_in_doc
  21. PUBLIC ULONG il_total_unique
  22. PUBLIC ULONG il_limit = 8224
  23. PUBLIC BLOB ib_st[]
  24. PUBLIC BLOB ib_extsst
  25. PUBLIC INTEGER ii_string_per_extsst = 8
  26. PRIVATE st_extsst_item i_extsst_items[]
  27. PUBLIC INTEGER ii_extsst_count
  28. end variables
  29. forward prototypes
  30. public function unsignedlong of_add_string (string as_value)
  31. public function unsignedlong of_add_string (blob ab_value)
  32. public function blob of_get_sst (unsignedlong al_offest)
  33. public function blob of_get_extsst ()
  34. end prototypes
  35. public function unsignedlong of_add_string (string as_value);return of_add_string(invo_unicode.of_ansi2unicode(as_value))
  36. end function
  37. public function unsignedlong of_add_string (blob ab_value);il_total_in_doc ++
  38. if invo_hash.of_key_exists(ab_value) then
  39. return invo_hash.of_get_value(ab_value) - 1
  40. else
  41. il_total_unique ++
  42. ib_st[il_total_unique] = ab_value
  43. invo_hash.of_set_value(ab_value, il_total_unique)
  44. return il_total_unique - 1
  45. end if
  46. end function
  47. public function blob of_get_sst (unsignedlong al_offest);blob lb_ret
  48. ulong ll_absolute_pos
  49. uint li_relative_pos
  50. ulong ll_i
  51. integer li_header_size = 12
  52. integer li_add_size
  53. uint li_new_size
  54. blob lb_cur_portion
  55. blob lb_header
  56. boolean lb_first_portion = true
  57. integer li_split_pos
  58. blob lb_first_part
  59. blob lb_last_part
  60. st_extsst_item l_emp[]
  61. i_extsst_items = l_emp
  62. ii_extsst_count = 0
  63. lb_cur_portion = blob("")
  64. lb_ret = blob("")
  65. ll_absolute_pos = li_header_size + al_offest
  66. li_relative_pos = li_header_size
  67. for ll_i = 1 to il_total_unique
  68. li_add_size = 3 + len(ib_st[ll_i])
  69. li_new_size = li_relative_pos + li_add_size
  70. if li_new_size > il_limit then
  71. if il_limit - li_relative_pos < 5 then
  72. if lb_first_portion then
  73. lb_header = invo_sub.of_pack("v", 252) + invo_sub.of_pack("v", len(lb_cur_portion) + 8) + invo_sub.of_pack("V", il_total_in_doc) + invo_sub.of_pack("V", il_total_unique)
  74. else
  75. lb_header = invo_sub.of_pack("v", 60) + invo_sub.of_pack("v", len(lb_cur_portion))
  76. end if
  77. lb_ret = lb_ret + lb_header + lb_cur_portion
  78. lb_first_portion = false
  79. li_header_size = 4
  80. lb_cur_portion = blob("")
  81. li_relative_pos = li_header_size
  82. ll_absolute_pos += li_header_size
  83. lb_cur_portion = lb_cur_portion + invo_sub.of_pack("v", integer(len(ib_st[ll_i]) / 2)) + invo_sub.of_pack("C", 1) + ib_st[ll_i]
  84. if mod(ll_i - 1, ii_string_per_extsst) = 0 then
  85. ii_extsst_count ++
  86. i_extsst_items[ii_extsst_count].il_absolute_pos = ll_absolute_pos
  87. i_extsst_items[ii_extsst_count].ii_relative_pos = li_relative_pos
  88. end if
  89. ll_absolute_pos += 3 + len(ib_st[ll_i])
  90. li_relative_pos = li_relative_pos + 3 + len(ib_st[ll_i])
  91. else
  92. li_split_pos = il_limit - li_relative_pos - 3
  93. if mod(li_split_pos, 2) = 1 then
  94. li_split_pos --
  95. end if
  96. lb_first_part = blobmid(ib_st[ll_i], 1, li_split_pos)
  97. lb_last_part = blobmid(ib_st[ll_i], li_split_pos + 1, len(ib_st[ll_i]) - li_split_pos)
  98. lb_cur_portion = lb_cur_portion + invo_sub.of_pack("v", integer(len(ib_st[ll_i]) / 2)) + invo_sub.of_pack("C", 1) + lb_first_part
  99. if mod(ll_i - 1, ii_string_per_extsst) = 0 then
  100. ii_extsst_count ++
  101. i_extsst_items[ii_extsst_count].il_absolute_pos = ll_absolute_pos
  102. i_extsst_items[ii_extsst_count].ii_relative_pos = li_relative_pos
  103. end if
  104. ll_absolute_pos += 3 + len(lb_first_part)
  105. li_relative_pos = li_relative_pos + 3 + len(lb_first_part)
  106. if lb_first_portion then
  107. lb_header = invo_sub.of_pack("v", 252) + invo_sub.of_pack("v", len(lb_cur_portion) + 8) + invo_sub.of_pack("V", il_total_in_doc) + invo_sub.of_pack("V", il_total_unique)
  108. else
  109. lb_header = invo_sub.of_pack("v", 60) + invo_sub.of_pack("v", len(lb_cur_portion))
  110. end if
  111. lb_ret = lb_ret + lb_header + lb_cur_portion
  112. lb_first_portion = false
  113. li_header_size = 4
  114. lb_cur_portion = blob("")
  115. li_relative_pos = li_header_size
  116. ll_absolute_pos += li_header_size
  117. lb_cur_portion = lb_cur_portion + invo_sub.of_pack("C", 1) + lb_last_part
  118. ll_absolute_pos += 1 + len(lb_last_part)
  119. li_relative_pos = li_relative_pos + 1 + len(lb_last_part)
  120. end if
  121. else
  122. lb_cur_portion = lb_cur_portion + invo_sub.of_pack("v", integer(len(ib_st[ll_i]) / 2)) + invo_sub.of_pack("C", 1) + ib_st[ll_i]
  123. if mod(ll_i - 1, ii_string_per_extsst) = 0 then
  124. ii_extsst_count ++
  125. i_extsst_items[ii_extsst_count].il_absolute_pos = ll_absolute_pos
  126. i_extsst_items[ii_extsst_count].ii_relative_pos = li_relative_pos
  127. end if
  128. ll_absolute_pos += 3 + len(ib_st[ll_i])
  129. li_relative_pos = li_relative_pos + 3 + len(ib_st[ll_i])
  130. end if
  131. next
  132. if len(lb_cur_portion) > 0 or lb_first_portion then
  133. if lb_first_portion then
  134. lb_header = invo_sub.of_pack("v", 252) + invo_sub.of_pack("v", len(lb_cur_portion) + 8) + invo_sub.of_pack("V", il_total_in_doc) + invo_sub.of_pack("V", il_total_unique)
  135. else
  136. lb_header = invo_sub.of_pack("v", 60) + invo_sub.of_pack("v", len(lb_cur_portion))
  137. end if
  138. lb_ret = lb_ret + lb_header + lb_cur_portion
  139. end if
  140. return lb_ret
  141. end function
  142. public function blob of_get_extsst ();blob lb_ret
  143. uint li_cnt
  144. uint li_i
  145. li_cnt = upperbound(i_extsst_items)
  146. lb_ret = invo_sub.of_pack("v", 255) + invo_sub.of_pack("v", li_cnt * 8 + 2) + invo_sub.of_pack("v", ii_string_per_extsst)
  147. if li_cnt > 0 then
  148. for li_i = 1 to li_cnt
  149. lb_ret = lb_ret + invo_sub.of_pack("V", i_extsst_items[li_i].il_absolute_pos) + invo_sub.of_pack("v", i_extsst_items[li_i].ii_relative_pos) + invo_sub.of_pack("v", 0)
  150. next
  151. end if
  152. return lb_ret
  153. end function
  154. on n_cst_sst.create
  155. call super::create
  156. TriggerEvent( this, "constructor" )
  157. end on
  158. on n_cst_sst.destroy
  159. TriggerEvent( this, "destructor" )
  160. call super::destroy
  161. end on
  162. event constructor;invo_hash = create n_cst_unicode_hash_long
  163. invo_sub = create n_xls_subroutines
  164. end event
  165. event destructor;destroy(invo_hash)
  166. destroy(invo_sub)
  167. end event