Author Topic: DLLC  (Read 28673 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Re: DLLC
« Reply #45 on: November 05, 2014, 02:47:56 PM »

both of these work:

Code: Script BASIC
  1.   lf="\n" & chr(0)
  2.   dl=";;"
  3.   fm="LLLLCCCRRRRR"
  4.   ' t=dllcall(AlignText,s,fm,dl,lf )
  5.  t=dllcall(AlignText,s,"LLLLCCCRRRRR",";;","\n" & chr(0) )
  6.   print t & "\n"
  7.  

JRS

  • Guest
Re: DLLC
« Reply #46 on: November 05, 2014, 02:54:26 PM »
Code: Script BASIC
  1. PRINT O2::ColumnAlign(quo, "LLLLCCCRRRRR", ";;", "\n" & CHR(0) & CHR(0))
  2.  

Still gives an exception error.

If you don't want to flood this thread with a debugging session, I'm on the AllBASIC IRC.

I put your code in O2.inc and still getting the exception error. I'm thinking it has something to do with the O2 source reacting differently using the virtual DLL method rather than a standard O2 compile.

Have you tried the SB method on your end?

« Last Edit: November 05, 2014, 03:12:07 PM by John »

Charles Pegge

  • Guest
Re: DLLC
« Reply #47 on: November 05, 2014, 04:11:06 PM »
John, I have your code working. I had to include the module inside testo2.sb. and change some filepaths to match my system.

Since I am launching by icon: line input u at the end

Code: Script BASIC
  1. MODULE O2
  2.  
  3. include "dllcinc.sb"
  4.  
  5. oxy=dllfile("/scriptbasic/modules/oxygen.dll")
  6.  
  7. o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  8. o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  9. o2_error = dllproc( oxy, "o2_error c*=()         " )
  10. o2_errno = dllproc( oxy, "o2_errno i =()         " )
  11. o2_len   = dllproc( oxy, "o2_len   i =()         " )
  12. o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )
  13.  
  14. dllcall o2_mode,1
  15.  
  16. OPEN "O2.src" FOR INPUT AS #1
  17. src = INPUT(LOF(1), 1)
  18. CLOSE(1)
  19.  
  20. a = oxygen(src)
  21. Finish  = dllproc(a,"Finish ()", dllcald(a,0))
  22. Reverse = dllproc(a,"Reverse (c*value)", dllcald(a,1))
  23. Words   = dllproc(a,"getword c* = (c* strraw, i* start)", dllcald(a,2))
  24. Align   = dllproc(a,"AlignText c* = (c* in, c* ju, C* dl, c* cr)", dllcald(a,3))
  25.  
  26. FUNCTION oxygen(src)
  27.   dllcall o2_basic,src
  28.   IF (dllcall(o2_errno)<> 0) THEN
  29.     dllprnt dllcall(o2_error)
  30.     a = 0
  31.   ELSE
  32.     a = dllcall(o2_exec,0)
  33.   END IF
  34.   oxygen = a
  35. END FUNCTION
  36.  
  37. FUNCTION Done
  38.   rtnval = dllcall(Finish)
  39.   dllfile
  40.   Done = rtnval
  41. END FUNCTION
  42.  
  43. ' SB wrapper functions
  44.  
  45. FUNCTION RevStr(strarg)
  46.   dllcall(Reverse, strarg)
  47.   RevStr = strarg
  48. END FUNCTION
  49.  
  50. FUNCTION GetWords(strarg, longarg)
  51.   GetWords = dllcall(Words, strarg, longarg)
  52. END FUNCTION
  53.  
  54. FUNCTION ColumnAlign(in_str, just_str, dlm_str, eol_str)
  55.   ColumnAlign = dllcall(Align, in_str, just_str, dlm_str, eol_str)
  56. END FUNCTION
  57.  
  58. END MODULE
  59.  
  60.  
  61.  
  62.  FOR x = 65 TO 90
  63.   alpha &= CHR(x)
  64.  NEXT
  65.  PRINT alpha,"\n"
  66.  PRINT O2::RevStr(alpha),"\n"
  67.  p = 1
  68.  Next_Word:
  69.   wd = O2::GetWords("abc(d[xx]+7/6,\"qwerty\")", p)
  70.   IF wd <> "" THEN
  71.     PRINT wd,"\n"
  72.     GOTO Next_Word
  73.   END IF
  74.  quo = """
  75. Given;;a;;text;;file;;of;;many;;lines,;;where;;fields;;within;;a;;line;;
  76. are;;delineated;;by;;a;;single;;'dollar';;character,;;write;;a;;program
  77. that;;aligns;;each;;column;;of;;fields;;by;;ensuring;;that;;words;;in;;each;;
  78. column;;are;;separated;;by;;at;;least;;one;;space.
  79. Further,;;allow;;for;;each;;word;;in;;a;;column;;to;;be;;either;;left;;
  80. justified,;;right;;justified,;;or;;center;;justified;;within;;its;;column.
  81. """
  82.  PRINT O2::ColumnAlign(quo, "LLLLCCCRRRRR", ";;", "\n"  )
  83.  
  84.  O2::Done()
  85.  
  86. line input u
  87.  

JRS

  • Guest
Re: DLLC
« Reply #48 on: November 05, 2014, 04:17:02 PM »
What does this O2 statement do?

AlignedText atxt

Please send me your working SB version to try here. I need to run out for a bit but I'll try it as soon as I get back.

Thanks for all the help!!!


JRS

  • Guest
Re: DLLC
« Reply #49 on: November 05, 2014, 04:26:54 PM »
Your code also exception errors. I'm wondering if this has something to do with the new Oxygen.dll I'm using.

Got to go, I'm late.

Charles Pegge

  • Guest
Re: DLLC
« Reply #50 on: November 05, 2014, 04:47:17 PM »
My version with DLLC and Oxygen attached:

.

JRS

  • Guest
Re: DLLC
« Reply #51 on: November 05, 2014, 07:45:57 PM »
My problem might have been I was using an older copy of the source that didn't have the new Align Text code.  ::)

testo2.sb
Code: Script BASIC
  1. IMPORT O2.inc
  2.  
  3. FOR x = 65 TO 90
  4.   alpha &= CHR(x)
  5. NEXT
  6. PRINT alpha,"\n"
  7. PRINT O2::RevStr(alpha),"\n"
  8. p = 1
  9. Next_Word:
  10.   wd = O2::GetWords("abc(d[xx]+7/6,\"qwerty\")", p)
  11.   IF wd <> "" THEN
  12.     PRINT wd,"\n"
  13.     GOTO Next_Word
  14.   END IF
  15. q = """
  16. Given;;a;;text;;file;;of;;many;;lines,;;where;;fields;;within;;a;;line;;
  17. are;;delineated;;by;;a;;single;;'dollar';;character,;;write;;a;;program
  18. that;;aligns;;each;;column;;of;;fields;;by;;ensuring;;that;;words;;in;;each;;
  19. column;;are;;separated;;by;;at;;least;;one;;space.
  20. Further,;;allow;;for;;each;;word;;in;;a;;column;;to;;be;;either;;left;;
  21. justified,;;right;;justified,;;or;;center;;justified;;within;;its;;column.
  22. """
  23. PRINT O2::ColumnAlign(q, "LLLLCCCRRRRR", ";;", "\n")
  24.  
  25. O2::Done()
  26.  

O2.inc
Code: Script BASIC
  1. MODULE O2
  2.  
  3. include "dllcinc.sb"
  4.  
  5. oxy=dllfile("/scriptbasic/Debugger/modules/oxygen.dll")
  6.  
  7. o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  8. o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  9. o2_error = dllproc( oxy, "o2_error c*=()         " )
  10. o2_errno = dllproc( oxy, "o2_errno i =()         " )
  11. o2_len   = dllproc( oxy, "o2_len   i =()         " )
  12. o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )
  13.  
  14. dllcall o2_mode,1
  15.  
  16. OPEN "/scriptbasic/Debugger/include/O2.src" FOR INPUT AS #1
  17. src = INPUT(LOF(1), 1)
  18. CLOSE(1)
  19.  
  20. a = oxygen(src)
  21. Finish  = dllproc(a,"Finish ()", dllcald(a,0))
  22. Reverse = dllproc(a,"Reverse (c*value)", dllcald(a,1))
  23. Words   = dllproc(a,"getword c* = (c* strraw, i* start)", dllcald(a,2))
  24. ColAlign   = dllproc(a,"AlignText c* = (c* in, c* ju, C* dl, c* cr)", dllcald(a,3))
  25.  
  26. FUNCTION oxygen(src)
  27.   dllcall o2_basic,src
  28.   IF (dllcall(o2_errno)<> 0) THEN
  29.     dllprnt dllcall(o2_error)
  30.     a = 0
  31.   ELSE
  32.     a = dllcall(o2_exec,0)
  33.   END IF
  34.   oxygen = a
  35. END FUNCTION
  36.  
  37. FUNCTION Done
  38.   rtnval = dllcall(Finish)
  39.   dllfile
  40.   Done = rtnval
  41. END FUNCTION
  42.  
  43. ' SB wrapper functions
  44.  
  45. FUNCTION RevStr(strarg)
  46.   dllcall(Reverse, strarg)
  47.   RevStr = strarg
  48. END FUNCTION
  49.  
  50. FUNCTION GetWords(strarg, longarg)
  51.   GetWords = dllcall(Words, strarg, longarg)
  52. END FUNCTION
  53.  
  54. FUNCTION ColumnAlign(in_str, just_str, dlm_str, eol_str)
  55.   ColumnAlign = dllcall(ColAlign, in_str, just_str, dlm_str, eol_str)
  56. END FUNCTION
  57.  
  58. END MODULE
  59.  

O2.src
Code: OxygenBasic
  1. ' O2 source
  2.  
  3. extern
  4.  
  5. function reverse(char*s)
  6. '=======================
  7.  addr ecx,s
  8.   mov edx,0
  9.  .rlen
  10.   mov al,[ecx]
  11.   cmp al,0
  12.   jz xlen
  13.   inc edx
  14.   inc ecx
  15.   jmp rlen
  16.  .xlen
  17.   ;
  18.   addr ecx,s
  19.   add  edx,ecx
  20.   dec ecx
  21.   ;
  22.  .rswap
  23.   inc ecx
  24.   dec edx
  25.   cmp edx,ecx
  26.   jle xswap
  27.   mov al,[ecx]
  28.   mov ah,[edx]
  29.   mov [ecx],ah
  30.   mov [edx],al
  31.   jmp rswap
  32.  .xswap
  33.   end function
  34.  
  35. function getword(char*ss,sys*b) as char*
  36. '=======================================
  37. if b=0 then b=1
  38. byte s at @ss
  39. byte c,d
  40. sys bb,bc
  41. static char z[128]
  42. a=0
  43. bb=b
  44.  
  45. 'SKIP LEADING SPACES
  46. do
  47.   c=s[b]
  48.   select c
  49.    case 33 to 255,0 : exit do 'SKIP SPACE
  50.  end select
  51.   b++
  52. end do
  53. bc=b
  54.  '
  55. 'QUOTES
  56. select c
  57.  case 34,39
  58.    do
  59.      b+=1
  60.      d=s[b]
  61.      if d=0 or d=c then b+=1 : jmp fwd done
  62.    end do
  63. end select
  64. 'WORDS AND SYMBOLS
  65. do
  66.   c=s[b]
  67.   select c
  68.   case 0 to 32    : exit do
  69.   case 35         : jmp fwd more
  70.   case 33 to 47   : 'symbols
  71.  case 48 to 57   : jmp fwd more 'numbers
  72.  case 58 to 64   : 'symbols
  73.  case 65 to 90   : jmp fwd more 'capitals
  74.  case 95         : jmp fwd more 'underscore
  75.  case 91 to 96   : 'symbols
  76.  case 97 to 122  : jmp fwd more 'lower case
  77.  case 123 to 127 : 'symbols
  78.  case 128 to 255 : jmp fwd more 'higher ascii
  79. end select
  80.  
  81. if b=bc then b++
  82.   exit do
  83.  
  84.   more:
  85.   b++
  86. end do
  87.  
  88. done:
  89.  
  90. if b > bb then
  91.   z=mid ss,bc,b-bc
  92. else
  93.   z = ""
  94. end if
  95. return z
  96.  
  97. end function
  98.  
  99. =================
  100. Class AlignedText
  101. =================
  102.  
  103. indexbase 1
  104.  
  105. string  buf, bufo, pr, cr, tab, jus, dlm
  106. sys     Cols, Rows, ColWidth[0x100], TotWidth, ColPad, ld
  107.  
  108. method SetText(char*s)
  109. ======================
  110. if not len cr then cr=chr(13,10)
  111. tab=chr(9)
  112. if not len jus then jus=string 200,"L"
  113. buf=s
  114. measure
  115. end method
  116.  
  117.  
  118. method measure()
  119. ================
  120. sys a, b, wa, wb, cm, c, cw
  121. a=1 : b=1
  122. Cols=0 : Rows=0 : ColPad=3
  123. ld=len dlm
  124. if not ld then dlm="," : ld=1 'default to comma
  125. do
  126.   wb=b
  127.   a=instr b,buf,cr
  128.   if a=0 then exit do
  129.   cm=0
  130.   c++
  131.   do
  132.     wa=instr wb,buf,dlm
  133.     if wa=0 or wa>a then exit do
  134.     cm++
  135.     if cm>cols then cols=cm
  136.     cw=wa-wb
  137.     if cw > ColWidth[cm] then ColWidth[cm]=cw
  138.     wb=wa+ld
  139.   end do
  140.   b=a+len cr
  141. end do
  142. rows=c
  143. '
  144. c=0
  145. for i=1 to cols
  146.   ColWidth[ i ]+=ColPad
  147.   c+=ColWidth[ i ]
  148. next
  149. TotWidth=c+len cr
  150. 'print ShowMetrics
  151. end method
  152.  
  153.  
  154. method ShowMetrics() as char*
  155. =============================
  156. pr="METRICS:" cr cr
  157. pr+=rows tab cols tab totwidth cr cr
  158. pr+="column" tab "spacing" cr
  159. for i=1 to cols
  160.   pr+=i tab ColWidth[ i ] cr
  161. next
  162. return pr
  163. end method
  164.  
  165.  
  166. method justify(char*j)
  167. ======================
  168. jus=j
  169. end method
  170.  
  171. method delimiter(char*j)
  172. ========================
  173. dlm=j
  174. end method
  175.  
  176. method endofline(char*j)
  177. ========================
  178. cr=j
  179. end method
  180.  
  181.  
  182. method layout() as char*
  183. ========================
  184. sys a, b, wa, wb, wl, cm, lpos, cpos
  185. bufo=space Rows*TotWidth
  186. a=1 : b=1
  187. do
  188.   wb=b
  189.   a=instr(b,buf,cr)
  190.   if a=0 then exit do
  191.   cm=0
  192.   cpos=1
  193.   do
  194.     wa=instr(wb,buf,dlm)
  195.     if wa=0 or wa>a then exit do
  196.     '
  197.    cm++
  198.     '
  199.    'JUSTIFICATION
  200.    '
  201.    wl=wa-wb
  202.     p=lpos+cpos 'default "L" LEFT ALIGN
  203.    '
  204.    select case asc(jus,cm)
  205.       case "R" : p=lpos+cpos+ColWidth[cm]-wl-Colpad
  206.       case "C" : p=lpos+cpos+( ColWidth[cm]-wl-Colpad )*.5
  207.     end select
  208.     '
  209.    mid bufo,p, mid buf,wb,wl
  210.     cpos+=colwidth[cm]
  211.     wb=wa+ld
  212.   end do
  213.   b=a+len cr
  214.   lpos+=TotWidth
  215.   if lpos<len(bufo) then mid bufo,lpos-1,cr
  216. end do
  217. return bufo
  218. end method
  219.  
  220. end class
  221.  
  222. '#recordof AlignedText
  223.  
  224. AlignedText atxt
  225.  
  226. function AlignText(char *in,*ju,*dl,*cr) as char*
  227. =================================================
  228. atxt.justify         ju
  229. atxt.delimiter       dl
  230. atxt.endofline       cr
  231. atxt.SetText         in
  232. return               atxt.layout
  233. end function
  234.  
  235. sub finish()
  236. '===========
  237.  terminate
  238. end sub
  239.  
  240. function link(sys n) as sys
  241. '==========================
  242.  select n
  243.   case 0 : return @finish
  244.   case 1 : return @reverse
  245.   case 2 : return @getword
  246.   case 3 : return @AlignText
  247.   end select
  248. end function
  249.  
  250. end extern
  251.  
  252. addr link
  253.  

Output

C:\scriptbasic\o2dev>scriba testo2.sb
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ZYXWVUTSRQPONMLKJIHGFEDCBA
abc
(
d
[
xx
]
+
7
/
6
,
"qwerty"
)

  Given        a            text         file       of       many        lines,        where   fields   within        a   line
  are          delineated   by           a        single    'dollar'   character,      write        a
  that         aligns       each         column     of       fields        by       ensuring     that    words       in   each
  column       are          separated    by         at       least        one
  Further,     allow        for          each      word        in          a          column       to       be   either   left
  justified,   right        justified,   or       center   justified     within          its

C:\scriptbasic\o2dev>
« Last Edit: November 05, 2014, 08:27:16 PM by John »

JRS

  • Guest
Re: DLLC
« Reply #52 on: November 05, 2014, 09:58:50 PM »
Charles,

This thread seems to have complementing functions to what we have already gathered. Do you think this should be included as well?


Charles Pegge

  • Guest
Re: DLLC
« Reply #53 on: November 06, 2014, 01:06:00 AM »
Hi John,

It has a different GetWord parser, adapted for plain text.

refactored for char*

Code: OxygenBasic
  1.   function GetTextWord(char*s, sys *i) as char*
  2.   =============================================
  3.   static string w
  4.   sys           a,j
  5.   byte          b at @s
  6.   j=i
  7.   i--
  8.   @b--
  9.   do
  10.     i++
  11.     @b++
  12.     select b
  13.     case 0            : exit do      'end of string
  14.    case 33 to 255    : exit do      'non white space
  15.    end select
  16.   end do
  17.   '
  18.  j=i
  19.   '
  20.  do
  21.     select b
  22.     case 0 to 32 : exit do
  23.     end select
  24.     i++
  25.     @b++
  26.   end do
  27.   '
  28.  if i>j
  29.     w=mid s,j,i-j
  30.     return w
  31.   else
  32.     return ""
  33.   end if
  34.   '
  35.  end function
  36.  

JRS

  • Guest
Re: DLLC
« Reply #54 on: November 06, 2014, 01:09:01 AM »
Nice!

I was thinking that the column align function could use a format option. Does O2 have a numeric format feature built into the syntax?

JRS

  • Guest
Re: DLLC
« Reply #55 on: November 06, 2014, 01:34:55 AM »
I'm getting a strange error with the new GetTextWord function.


C:\scriptbasic\o2dev>scriba testo2.sb
 ; ASM ERR:     >!!  Unidentified instruction: >
 ; AFTER:       ._here_
 ; LINE:        290

C:\scriptbasic\o2dev>


testo2.sb
Code: Script BASIC
  1. IMPORT O2.inc
  2.  
  3. FOR x = 65 TO 90
  4.   alpha &= CHR(x)
  5. NEXT
  6. PRINT alpha,"\n"
  7. PRINT O2::RevStr(alpha),"\n"
  8. p = 1
  9. Next_Word:
  10.   wd = O2::GetWords("abc(d[xx]+7/6,\"qwerty\")", p)
  11.   IF wd <> "" THEN
  12.     PRINT wd,"\n"
  13.     GOTO Next_Word
  14.   END IF
  15. q = """
  16. Given;;a;;text;;file;;of;;many;;lines,;;where;;fields;;within;;a;;line;;
  17. are;;delineated;;by;;a;;single;;'dollar';;character,;;write;;a;;program
  18. that;;aligns;;each;;column;;of;;fields;;by;;ensuring;;that;;words;;in;;each;;
  19. column;;are;;separated;;by;;at;;least;;one;;space.
  20. Further,;;allow;;for;;each;;word;;in;;a;;column;;to;;be;;either;;left;;
  21. justified,;;right;;justified,;;or;;center;;justified;;within;;its;;column.
  22. """
  23. PRINT O2::ColumnAlign(q, "LLLLCCCRRRRR", ";;", "\n")
  24. p = 1
  25. Next_Text_Word:
  26.   wd = O2::GetTextWords("The quick brown fox jumped over the lazy dog's back 1234567890 times.", p)
  27.   IF wd <> "" THEN
  28.     PRINT wd,"\n"
  29.     GOTO Next_Text_Word
  30.   END IF
  31.  
  32. O2::Done()
  33.  

O2.inc
Code: Script BASIC
  1. MODULE O2
  2.  
  3. include "dllcinc.sb"
  4.  
  5. oxy=dllfile("/scriptbasic/Debugger/modules/oxygen.dll")
  6.  
  7. o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  8. o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  9. o2_error = dllproc( oxy, "o2_error c*=()         " )
  10. o2_errno = dllproc( oxy, "o2_errno i =()         " )
  11. o2_len   = dllproc( oxy, "o2_len   i =()         " )
  12. o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )
  13.  
  14. dllcall o2_mode,1
  15.  
  16. OPEN "/scriptbasic/Debugger/include/O2.src" FOR INPUT AS #1
  17. src = INPUT(LOF(1), 1)
  18. CLOSE(1)
  19.  
  20. a = oxygen(src)
  21. Finish  = dllproc(a,"Finish ()", dllcald(a,0))
  22. Reverse = dllproc(a,"Reverse (c*value)", dllcald(a,1))
  23. Words   = dllproc(a,"getword c* = (c* strraw, i* start)", dllcald(a,2))
  24. ColAlign   = dllproc(a,"AlignText c* = (c* in, c* ju, C* dl, c* cr)", dllcald(a,3))
  25. Text = dllproc(a,"GetTextWord c* = (c* in_str, i* start)", dllcald(a,4))
  26.  
  27. FUNCTION oxygen(src)
  28.   dllcall o2_basic,src
  29.   IF (dllcall(o2_errno)<> 0) THEN
  30.     dllprnt dllcall(o2_error)
  31.     a = 0
  32.   ELSE
  33.     a = dllcall(o2_exec,0)
  34.   END IF
  35.   oxygen = a
  36. END FUNCTION
  37.  
  38. FUNCTION Done
  39.   rtnval = dllcall(Finish)
  40.   dllfile
  41.   Done = rtnval
  42. END FUNCTION
  43.  
  44. ' SB wrapper functions
  45.  
  46. FUNCTION RevStr(strarg)
  47.   dllcall(Reverse, strarg)
  48.   RevStr = strarg
  49. END FUNCTION
  50.  
  51. FUNCTION GetWords(strarg, longarg)
  52.   GetWords = dllcall(Words, strarg, longarg)
  53. END FUNCTION
  54.  
  55. FUNCTION ColumnAlign(in_str, just_str, dlm_str, eol_str)
  56.   ColumnAlign = dllcall(ColAlign, in_str, just_str, dlm_str, eol_str)
  57. END FUNCTION
  58.  
  59. FUNCTION GetTextWords(in_str, start)
  60.   GetTextWords = dllcall(Text, in_str, start)
  61. END FUNCTION
  62.  
  63. END MODULE
  64.  

O2.src
Code: OxygenBasic
  1. ' O2 source
  2.  
  3. extern
  4.  
  5. function reverse(char*s)
  6. '=======================
  7.  addr ecx,s
  8.   mov edx,0
  9.  .rlen
  10.   mov al,[ecx]
  11.   cmp al,0
  12.   jz xlen
  13.   inc edx
  14.   inc ecx
  15.   jmp rlen
  16.  .xlen
  17.   ;
  18.   addr ecx,s
  19.   add  edx,ecx
  20.   dec ecx
  21.   ;
  22.  .rswap
  23.   inc ecx
  24.   dec edx
  25.   cmp edx,ecx
  26.   jle xswap
  27.   mov al,[ecx]
  28.   mov ah,[edx]
  29.   mov [ecx],ah
  30.   mov [edx],al
  31.   jmp rswap
  32.  .xswap
  33.   end function
  34.  
  35. function getword(char*ss,sys*b) as char*
  36. '=======================================
  37. if b=0 then b=1
  38. byte s at @ss
  39. byte c,d
  40. sys bb,bc
  41. static char z[128]
  42. a=0
  43. bb=b
  44.  
  45. 'SKIP LEADING SPACES
  46. do
  47.   c=s[b]
  48.   select c
  49.    case 33 to 255,0 : exit do 'SKIP SPACE
  50.  end select
  51.   b++
  52. end do
  53. bc=b
  54.  '
  55. 'QUOTES
  56. select c
  57.  case 34,39
  58.    do
  59.      b+=1
  60.      d=s[b]
  61.      if d=0 or d=c then b+=1 : jmp fwd done
  62.    end do
  63. end select
  64. 'WORDS AND SYMBOLS
  65. do
  66.   c=s[b]
  67.   select c
  68.   case 0 to 32    : exit do
  69.   case 35         : jmp fwd more
  70.   case 33 to 47   : 'symbols
  71.  case 48 to 57   : jmp fwd more 'numbers
  72.  case 58 to 64   : 'symbols
  73.  case 65 to 90   : jmp fwd more 'capitals
  74.  case 95         : jmp fwd more 'underscore
  75.  case 91 to 96   : 'symbols
  76.  case 97 to 122  : jmp fwd more 'lower case
  77.  case 123 to 127 : 'symbols
  78.  case 128 to 255 : jmp fwd more 'higher ascii
  79. end select
  80.  
  81. if b=bc then b++
  82.   exit do
  83.  
  84.   more:
  85.   b++
  86. end do
  87.  
  88. done:
  89.  
  90. if b > bb then
  91.   z=mid ss,bc,b-bc
  92. else
  93.   z = ""
  94. end if
  95. return z
  96.  
  97. end function
  98.  
  99. =================
  100. Class AlignedText
  101. =================
  102.  
  103. indexbase 1
  104.  
  105. string  buf, bufo, pr, cr, tab, jus, dlm
  106. sys     Cols, Rows, ColWidth[0x100], TotWidth, ColPad, ld
  107.  
  108. method SetText(char*s)
  109. ======================
  110. if not len cr then cr=chr(13,10)
  111. tab=chr(9)
  112. if not len jus then jus=string 200,"L"
  113. buf=s
  114. measure
  115. end method
  116.  
  117.  
  118. method measure()
  119. ================
  120. sys a, b, wa, wb, cm, c, cw
  121. a=1 : b=1
  122. Cols=0 : Rows=0 : ColPad=3
  123. ld=len dlm
  124. if not ld then dlm="," : ld=1 'default to comma
  125. do
  126.   wb=b
  127.   a=instr b,buf,cr
  128.   if a=0 then exit do
  129.   cm=0
  130.   c++
  131.   do
  132.     wa=instr wb,buf,dlm
  133.     if wa=0 or wa>a then exit do
  134.     cm++
  135.     if cm>cols then cols=cm
  136.     cw=wa-wb
  137.     if cw > ColWidth[cm] then ColWidth[cm]=cw
  138.     wb=wa+ld
  139.   end do
  140.   b=a+len cr
  141. end do
  142. rows=c
  143. '
  144. c=0
  145. for i=1 to cols
  146.   ColWidth[ i ]+=ColPad
  147.   c+=ColWidth[ i ]
  148. next
  149. TotWidth=c+len cr
  150. 'print ShowMetrics
  151. end method
  152.  
  153.  
  154. method ShowMetrics() as char*
  155. =============================
  156. pr="METRICS:" cr cr
  157. pr+=rows tab cols tab totwidth cr cr
  158. pr+="column" tab "spacing" cr
  159. for i=1 to cols
  160.   pr+=i tab ColWidth[ i ] cr
  161. next
  162. return pr
  163. end method
  164.  
  165.  
  166. method justify(char*j)
  167. ======================
  168. jus=j
  169. end method
  170.  
  171. method delimiter(char*j)
  172. ========================
  173. dlm=j
  174. end method
  175.  
  176. method endofline(char*j)
  177. ========================
  178. cr=j
  179. end method
  180.  
  181.  
  182. method layout() as char*
  183. ========================
  184. sys a, b, wa, wb, wl, cm, lpos, cpos
  185. bufo=space Rows*TotWidth
  186. a=1 : b=1
  187. do
  188.   wb=b
  189.   a=instr(b,buf,cr)
  190.   if a=0 then exit do
  191.   cm=0
  192.   cpos=1
  193.   do
  194.     wa=instr(wb,buf,dlm)
  195.     if wa=0 or wa>a then exit do
  196.     '
  197.    cm++
  198.     '
  199.    'JUSTIFICATION
  200.    '
  201.    wl=wa-wb
  202.     p=lpos+cpos 'default "L" LEFT ALIGN
  203.    '
  204.    select case asc(jus,cm)
  205.       case "R" : p=lpos+cpos+ColWidth[cm]-wl-Colpad
  206.       case "C" : p=lpos+cpos+( ColWidth[cm]-wl-Colpad )*.5
  207.     end select
  208.     '
  209.    mid bufo,p, mid buf,wb,wl
  210.     cpos+=colwidth[cm]
  211.     wb=wa+ld
  212.   end do
  213.   b=a+len cr
  214.   lpos+=TotWidth
  215.   if lpos<len(bufo) then mid bufo,lpos-1,cr
  216. end do
  217. return bufo
  218. end method
  219.  
  220. end class
  221.  
  222. '#recordof AlignedText
  223.  
  224. AlignedText atxt
  225.  
  226. function AlignText(char *in,*ju,*dl,*cr) as char*
  227. =================================================
  228. atxt.justify         ju
  229. atxt.delimiter       dl
  230. atxt.endofline       cr
  231. atxt.SetText         in
  232. return               atxt.layout
  233. end function
  234.  
  235. function GetTextWord(char*s, sys *i) as char*
  236. =============================================
  237. static string w
  238. sys           a,j
  239. byte          b at @s
  240. j=i
  241. i--
  242. @b--
  243. do
  244.   i++
  245.   @b++
  246.   select b
  247.   case 0            : exit do      'end of string
  248.  case 33 to 255    : exit do      'non white space
  249.  end select
  250. end do
  251. '
  252. j=i
  253. '
  254. do
  255.   select b
  256.   case 0 to 32 : exit do
  257.   end select
  258.   i++
  259.   @b++
  260. end do
  261. '
  262. if i>j
  263.   w=mid s,j,i-j
  264.   return w
  265. else
  266.   return ""
  267. end if
  268. '
  269. end function
  270.  
  271. sub finish()
  272. '===========
  273.  terminate
  274. end sub
  275.  
  276. function link(sys n) as sys
  277. '==========================
  278.  select n
  279.   case 0 : return @finish
  280.   case 1 : return @reverse
  281.   case 2 : return @getword
  282.   case 3 : return @AlignText
  283.   case 4 : return @GetTextWord
  284.   end select
  285. end function
  286.  
  287. end extern
  288.  
  289. addr link
  290.  

Charles Pegge

  • Guest
Re: DLLC
« Reply #56 on: November 06, 2014, 04:30:27 AM »
Does src require a null terminator?

JRS

  • Guest
Re: DLLC
« Reply #57 on: November 06, 2014, 09:31:15 AM »
Everything worked fine until I added the GetTextWord function.

Quote
Does src require a null terminator?

That's something you would have to ask the QxygenBasic author.  ???


Charles Pegge

  • Guest
Re: DLLC
« Reply #58 on: November 06, 2014, 09:44:03 AM »
I can't reproduce the error, John. It looks like junk at the end of the source, caused by an overrun.

JRS

  • Guest
Re: DLLC
« Reply #59 on: November 06, 2014, 10:02:35 AM »
Quote
I can't reproduce the error, John. It looks like junk at the end of the source, caused by an overrun.

Good to know! I'll see what I can do on this end to clean up the O2 source file.

1. Tabs to spaces
2. Remove trailing spaces.
3. Only one extra blank line at the end of the source.


C:\scriptbasic\o2dev>scriba testo2.sb
 ; ASM ERR:     ╕ m!!  Unidentified instruction: ╕
 ; AFTER:       ._here_
 ; LINE:        290


C:\scriptbasic\o2dev>


Is there a chance we have overrun your internal buffer with this new function addition?