|
BASM
Dec 7, 2014 10:09:33 GMT 1
Post by vovchik on Dec 7, 2014 10:09:33 GMT 1
Dear John, Here is a test with HUG lib, using the same png image as in the previous archive. It works, although I don't yet know how to code the PROPERTY import yet. BASM doesn't seem to like something related to GTK fonts, since I cannot see the BUTTON label, which is a child of the BUTTON widget. Setting the BUTTON widget font did not help, as you can see. And STOCK did not give us a button image but text. If set again, it shows the text but not the image. With kind regards, vovchik ' create hug.so like this: bacon -f hug.bac in working dir
' *********************** ' IMPORTS ' ***********************
DECLARE FUNCTION INIT LIB "./hug.so" ALIAS "INIT" () AS VOID DECLARE FUNCTION QUIT LIB "./hug.so" ALIAS "QUIT" () AS VOID DECLARE FUNCTION DISPLAY LIB "./hug.so" ALIAS "DISPLAY" () AS VOID DECLARE FUNCTION WINDOW LIB "./hug.so" ALIAS "WINDOW" (w AS STRING, width AS INTEGER, height AS INTEGER) AS INTEGER 'DECLARE FUNCTION BUTTON LIB "./hug.so" ALIAS "BUTTON" (t AS STRING, w AS INTEGER, h AS INTEGER) AS INTEGER DECLARE FUNCTION ATTACH LIB "./hug.so" ALIAS "ATTACH" (p AS INTEGER, c AS INTEGER, x AS INTEGER, y AS INTEGER) AS VOID DECLARE FUNCTION HUG_CALLBACK LIB "./hug.so" ALIAS "CALLBACK" (w AS INTEGER, c AS INTEGER) AS VOID DECLARE FUNCTION MARK LIB "./hug.so" ALIAS "MARK" (t AS STRING, w AS INTEGER, h AS INTEGER) AS INTEGER DECLARE FUNCTION IMAGE LIB "./hug.so" ALIAS "IMAGE" (t AS STRING, w AS INTEGER, h AS INTEGER) AS INTEGER DECLARE FUNCTION FONT LIB "./hug.so" ALIAS "FONT" (w AS INTEGER, f AS STRING) AS VOID DECLARE FUNCTION TEXT LIB "./hug.so" ALIAS "TEXT" (w AS INTEGER, f AS STRING) AS VOID DECLARE FUNCTION WINICON LIB "libgtk-x11-2.0.so.0" ALIAS "gtk_window_set_icon_name" (w AS INTEGER, i AS STRING) AS VOID DECLARE FUNCTION STOCK LIB "./hug.so" ALIAS "STOCK" (t AS STRING, w AS INTEGER, h AS INTEGER) AS INTEGER
' *********************** ' END IMPORTS ' ***********************
' *********************** ' INITIALIZATION ' ***********************
' declare widgets DIM win AS INTEGER DIM but1 AS INTEGER DIM but2 AS INTEGER DIM but3 AS INTEGER DIM lab1 AS INTEGER DIM lab2 AS INTEGER DIM img AS INTEGER ' declare other vars DIM win_w AS INTEGER DIM win_h AS INTEGER DIM lab_text1$ AS STRING DIM lab_text2$ AS STRING ' initialize vars win_w = 300 win_h = 350 lab_text1$ = "<span color='red' font='Sans Bold 32'>A LABEL</span>" lab_text2$ = "<span color='blue' font='Sans Bold 32'>AN IMAGE</span>"
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ SUB HUG_TEST() ' ------------------ PRINT "WE are going to invoke BaCon HUG as a lib now." END SUB
' ------------------ SUB MYCLICK() ' ------------------ PRINT "You pressed a button, so we are quitting." QUIT() END SUB
' ------------------ SUB MK_GUI() ' ------------------ INIT() win = WINDOW("BASM HUG test", win_w, 350) WINICON(win, "gtk-info") but1 = STOCK("gtk-exit", 80, 30) but2 = STOCK("gtk-exit", 80, 30) but3 = STOCK("gtk-exit", 80, 30) lab1 = MARK(lab_text1$, win_w, 80) lab2 = MARK(lab_text2$, win_w, 80) img = IMAGE("nobugs07.png", 128, 128) ATTACH(win, but1, win_w - 90, win_h - 40) ATTACH(win, but2, 10, win_h - 40) ATTACH(win, but3, (win_w/2) - 40, win_h - 40) ATTACH(win, lab1, 0, 0) ATTACH(win, lab2, 0, 240) ATTACH(win, img, 150 - 64, 90) 'FONT(but2, "Sans Bold 10") TEXT(but1, "Exit") TEXT(but2, "Exit") TEXT(but3, "Close") FONT(but2, "Sans Bold 10") FONT(but3, "Sans Bold 10") 'FONT(but1, "Sans Bold 10") HUG_CALLBACK(but1, CALLBACK(MYCLICK)) HUG_CALLBACK(but2, CALLBACK(MYCLICK)) HUG_CALLBACK(but3, CALLBACK(MYCLICK)) DISPLAY() END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
HUG_TEST() MK_GUI()
' *********************** ' END MAIN ' ***********************
Attachments:
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 7, 2014 10:24:24 GMT 1
Post by Deleted on Dec 7, 2014 10:24:24 GMT 1
I need to digest and run your example but I think you're saying your making progress on the label text front. AIR is also looking at it.
Here is a reworked String.inc that seems to work. Replace needs a second look. If you can give this a good test before I post it to the repo, that would be great.
' String.inc - String functions ' Original: Library for KoolB by Brian Becker ' 20141206 AIR/JRS - Rework for Linux 32
' $IfNDef Stringinc ' $Define Stringinc
' $Include "System.inc" ' $Include "Type.inc"
Declare Function Len Lib "libc.so.6" Alias "strlen" (S As String) As Integer Declare Function strcpy Lib "libc.so.6" Alias "strcpy" (byref S1 As String, byval S2 As String) As String Declare Function ToLower Lib "libc.so.6" Alias "tolower" Call C (Char As Integer) As Integer Declare Function ToUpper Lib "libc.so.6" Alias "toupper" Call C (Char As Integer) As Integer
Function Mid$(S As String, Start As Integer, Length As Integer) As String If Start < 1 Then Start = 1 End If
If Start > Len(S) Then Result = "" End If $Asm extern strncpy extern calloc MOV EBX,dword[EBP+8] ;EBX = S MOV ESI,dword[EBP+12] ;ESI = Start MOV EDI,dword[EBP+16] ;EDI = Length DEC ESI ;Convert to zero-based INC EDI ADD EBX,ESI ;Move Ptr to Start ADD ESI,EDI INC ESI ccall calloc,ESI,1 DEC ESI DEC EDI ccall strncpy,EAX,EBX,EDI MOV dword[EBP-4],EAX $End Asm End Function
Function Instr(Start As Integer, S As String, Find As String) As Integer Dim Found As Integer, Length As Integer, SearchableLength As Integer If Start < 1 Then Start = 1 End If Length = Len(Find) Found = 0 SearchableLength = Len(S) While Start <= SearchableLength And Found = 0 If Mid$(S, Start, Length) = Find Then Found = 1 Result = Start End If Start = Start + 1 WEnd If Found = 0 Then Result = 0 End If End Function
Function Space$(Size As Integer) As String Dim Counter As Integer Dim RtnStr As String Counter = 1 RtnStr = "" While Counter <= Size RtnStr = RtnStr + " " Counter = Counter + 1 WEnd Result = RtnStr End Function
Function Asc(S As String) As Integer $Asm MOV EAX,dword[EBP+8] MOVSX EAX,byte[EAX] MOV dword[EBP-4],EAX $End Asm End Function
Function Chr$(ASCII As Integer) As String $Asm extern malloc ccall malloc, 2 MOV EBX,EAX MOV AH,byte[EBP+8] MOV byte[EBX],AH MOV byte[EBX+1],0 MOV dword[EBP-4],EBX $End ASM End Function
Function LCase$(S As String) As String Result = "" Index& = 1 tmp$="" Length& = Len(S) While Index& <= Length& tmp$ = tmp$ + Chr$(ToLower(Asc(Mid$(S, Index&, 1)))) Index& = Index& + 1 WEnd Result = tmp$ End Function
Function UCase$(S As String) As String Result = "" Index& = 1 Length& = Len(S) + 1 While Index& < Length& Result = Result + Chr$(ToUpper(Asc(Mid$(S, Index&, 1)))) Index& = Index& + 1 WEnd End Function
Function Left$(S As String, N As Integer) As String Result = Mid$(S, 1, N) End Function
Function Right$ (S As String, N As Integer) As String ' Result = Mid$(S, N, Len(S)) Result = Mid$(S, Len(S) - N + 1, Len(s)) End Function
Function LTrim$(S As String) As String Dim Length As Integer, Index As Integer, Found As Integer Index = 1 Length = Len(S) Found = 0 While Index < Length And Found = 0 If Mid$(S, Index, 1) <> " " Then Found = 1 End If Index = Index + 1 WEnd Index = Index - 1 'Counter act last increment Result = Mid$(S, Index, Len(S) - Index + 1) End Function
Function RTrim$(S As String) As String Dim Index As Integer, Found As Integer Index = Len(S) Found = 0 While Index >= 1 And Found = 0 If Mid$(S, Index, 1) <> " " Then Found = 1 End If Index = Index - 1 WEnd Index = Index + 1 'Counter act last increment Result = Mid$(S, 1, Index) End Function
Function String$(Number As Integer, S As String) As String Dim Index As Integer Index = 1 While Index <= Number Result = Result + Mid$(S, 1, 1) Index = Index + 1 WEnd End Function
' Broken - loops forever if more than one match. Function Replace(Source As String, ToReplace As String, Replacement As String) As String Dim Index As Integer Dim T As String T = Source Index = InStr(1, T, ToReplace) While Index > 0 T = Left$(T, Index - 1) + Replacement + Right$(T, Index + Len(ToReplace)) Index = InStr(1, T, ToReplace) ' Print T WEnd Result = T End Function
Function InstrRev(Start As Integer, S As String, Find As String) As Integer Dim Found As Integer, Length As Integer, SearchableLength As Integer If Start = 0 Then Start = Len(S) - Len(Find) End If Length = Len(Find) Found = 0 While Start >= 1 And Found = 0 If Mid$(S, Start, Length) = Find Then Found = 1 Result = Start' + Len(Find) End If Start = Start - 1 WEnd If Found = 0 Then Result = 0 End If End Function
Function Reverse$(S As String) As String Dim Length As Integer, Index As Integer Index = 1 Length = Len(S) While Index <= Length Result = Mid$(S, Index, 1) + Result Index = Index + 1 WEnd End Function
Function DelStr$(S As String, Start As Integer, Length As Integer) As String Result = Mid$(S, 1, Start - 1) + Mid$(S, Start + Length, Len(S)) End Function
Function Tally(Search As String, Match As String) As Integer Dim Position As Integer Dim AtEnd As Integer Dim SumIt As Integer SumIt = 0 Position = 1 AtEnd = 0 While AtEnd = 0 Position = Instr(Position, Search, Match) If Position = 0 Then AtEnd = 1 Else Position = Position + 1 SumIt = SumIt + 1 End If Wend Result = SumIt End Function
' *** TESTING ***
DIM s$ AS STRING
s$ = "abcdefghijklmnopqrstuvwxyz" PRINT MID$(s$, 13, 1) PRINT LEN(SPACE$(20)) PRINT ASC("A") PRINT CHR$(65) PRINT LCASE$("THIS sHoUlD BE LOWER CASE") PRINT UCASE$("this sHoUlD be upper case") PRINT LEFT$(s$, 3) PRINT RIGHT$(s$, 3) PRINT "|";LTRIM$(" Test "),"|" PRINT "|";RTRIM$(" Test "),"|" PRINT STRING$(5,"#") PRINT REPLACE("BOT", "B", "R") PRINT INSTRREV(26, s$, "t") PRINT REVERSE$("REVERSE") PRINT DELSTR$("xyz", 2, 1) PRINT TALLY("Seattle", "e")
jrs@laptop:~/BASM64/Inc$ ./String m 20 65 A this should be lower case THIS SHOULD BE UPPER CASE abc xyz |Test | | Test| ##### ROT 20 ESREVER xz 2 jrs@laptop:~/BASM64/Inc$
|
|
|
BASM
Dec 7, 2014 12:16:10 GMT 1
Post by vovchik on Dec 7, 2014 12:16:10 GMT 1
Dear John, Here is AIR's set of string functions with a "somewhat" working REPLACE$ (still needs work) and a TRIM$. I also standardized INSTR and INSTRREV in terms of the order of arguments. With kind regards, vovchik PS. I have also included some source with a workaround for the buttons anomaly. A true kluge. PPS. STRING vars cannot contain a "%". If you want to print out such a string you have to use "%%", but that doesn't help if you are reading in texts that use a single var. LEN also reports an end of var at the single "%".
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 7, 2014 18:40:49 GMT 1
Post by Deleted on Dec 7, 2014 18:40:49 GMT 1
vovchik - Good morning from Anacortes, WA. Thanks for the attachments and I'll look at them now. This font thing is a real mystery. Gut tells me the answer is in the gtk.h file. Can you reproduce the effect in C? What is IUP doing different that BASM missed? BTW: BASM uses % as a INTEGER variable designator. $ for strings and # for doubles. You may not have to DIM a variable if you use the type suffix. (need checking in to) Underline is another character you need to be careful with in BASM. You can't start a variable with it. It's meant to be a line continuation character.
|
|
|
BASM
Dec 7, 2014 19:24:39 GMT 1
Post by vovchik on Dec 7, 2014 19:24:39 GMT 1
Dear John, Nothing I have done in C with GTK caused that very funny font issue. And button fonts work in HUG and they work in BaCon when I simply use PROTO/PRAGMA directly (straight C functions from GTK and GDK). And the straight GTK imports in BASM also work - except that button fonts don't show. VERY WEIRD. I will scratch my head a bit and hope it helps. It would be nice to have a few more types available to BASM (e.g. char, unsigned char) With kind regards, vovchik PS. PST is UTC-8 and I am UTC+2 at the moment...so the mutual consciousness window is indeed small.
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 7, 2014 20:16:29 GMT 1
Post by Deleted on Dec 7, 2014 20:16:29 GMT 1
Here is an update of the String.inc library. AIR, vovchik and I worked on converting the Windows version to work with Linux. MID$() was a PITA but AIR nailed it. Thanks vovchik for the testing and syntax realignment. (argument standardization) I will be pushing this to Bitbucket and refreshing the BASM 32 source. vovchik - Can you do the same with your Math.inc library and I'll refresh Bitbucket (BASM 64/32) with the library. Update: The code has been updated with vovchik's REPLACE enhancements. ' String.inc - String functions ' Original: Library for KoolB by Brian Becker ' 2014-12-06 AIR/JRS/vovchik - Rework for Linux 32
DECLARE FUNCTION LEN LIB "libc.so.6" ALIAS "strlen" (S AS STRING) AS INTEGER DECLARE FUNCTION strcpy LIB "libc.so.6" ALIAS "strcpy" (BYREF S1 AS STRING, BYVAL S2 AS STRING) AS STRING DECLARE FUNCTION TO_LOWER LIB "libc.so.6" ALIAS "tolower" CALL C(Char AS INTEGER) AS INTEGER DECLARE FUNCTION TO_UPPER LIB "libc.so.6" ALIAS "toupper" CALL C(Char AS INTEGER) AS INTEGER
' ------------------ FUNCTION MID$(S AS STRING, Start AS INTEGER, Length AS INTEGER) AS STRING ' ------------------ IF Start < 1 THEN Start = 1 END IF IF Start > LEN(S) THEN result = "" END IF $ASM extern strncpy extern calloc MOV EBX,dword[EBP+8] ;EBX = S MOV ESI,dword[EBP+12] ;ESI = Start MOV EDI,dword[EBP+16] ;EDI = Length DEC ESI ;Convert to zero-based INC EDI ADD EBX,ESI ;Move Ptr to Start ADD ESI,EDI INC ESI ccall calloc,ESI,1 DEC ESI DEC EDI ccall strncpy,EAX,EBX,EDI MOV dword[EBP-4],EAX $END ASM END FUNCTION
' ------------------ FUNCTION INSTR(S AS STRING, Find AS STRING, Start AS INTEGER) AS INTEGER ' ------------------ DIM Found AS INTEGER, Length AS INTEGER, SearchableLength AS INTEGER IF Start < 1 THEN Start = 1 END IF Length = LEN(Find) Found = 0 SearchableLength = LEN(S) WHILE Start <= SearchableLength AND Found = 0 IF MID$(S, Start, Length) = Find THEN Found = 1 result = Start END IF Start = Start + 1 WEND IF Found = 0 THEN result = 0 END IF END FUNCTION
' ------------------ FUNCTION SPACE$(Size AS INTEGER) AS STRING ' ------------------ DIM Counter AS INTEGER DIM RtnStr AS STRING Counter = 1 RtnStr = "" WHILE Counter <= Size RtnStr = RtnStr + " " Counter = Counter + 1 WEND result = RtnStr END FUNCTION
' ------------------ FUNCTION ASC(S AS STRING) AS INTEGER ' ------------------ $ASM MOV EAX,dword[EBP+8] MOVSX EAX,byte[EAX] MOV dword[EBP-4],EAX $END ASM END FUNCTION
' ------------------ FUNCTION CHR$(ASCII AS INTEGER) AS STRING ' ------------------ $ASM extern malloc ccall malloc, 2 MOV EBX,EAX MOV AH,byte[EBP+8] MOV byte[EBX],AH MOV byte[EBX+1],0 MOV dword[EBP-4],EBX $END ASM END FUNCTION
' ------------------ FUNCTION LCASE$(S AS STRING) AS STRING ' ------------------ result = "" Index& = 1 tmp$="" Length& = LEN(S) WHILE Index& <= Length& tmp$ = tmp$ + CHR$(TO_LOWER(ASC(MID$(S, Index&, 1)))) Index& = Index& + 1 WEND result = tmp$ END FUNCTION
' ------------------ FUNCTION UCASE$(S AS STRING) AS STRING ' ------------------ result = "" Index& = 1 Length& = LEN(S) + 1 WHILE Index& < Length& result = result + CHR$(TO_UPPER(ASC(MID$(S, Index&, 1)))) Index& = Index& + 1 WEND END FUNCTION
' ------------------ FUNCTION LEFT$(S AS STRING, N AS INTEGER) AS STRING ' ------------------ result = MID$(S, 1, N) END FUNCTION
' ------------------ FUNCTION RIGHT$(S AS STRING, N AS INTEGER) AS STRING ' ------------------ ' result = MID$(S, N, LEN(S)) result = MID$(S, LEN(S) - N + 1, LEN(s)) END FUNCTION
' ------------------ FUNCTION LTRIM$(S AS STRING) AS STRING ' ------------------ DIM Length AS INTEGER, Index AS INTEGER, Found AS INTEGER Index = 1 Length = LEN(S) Found = 0 WHILE Index < Length AND Found = 0 IF MID$(S, Index, 1) <> " " THEN Found = 1 END IF Index = Index + 1 WEND Index = Index - 1 'Counter act last increment result = MID$(S, Index, LEN(S) - Index + 1) END FUNCTION
' ------------------ FUNCTION RTRIM$(S AS STRING) AS STRING ' ------------------ DIM Index AS INTEGER, Found AS INTEGER Index = LEN(S) Found = 0 WHILE Index >= 1 AND Found = 0 IF MID$(S, Index, 1) <> " " THEN Found = 1 END IF Index = Index - 1 WEND Index = Index + 1 'Counter act last increment result = MID$(S, 1, Index) END FUNCTION
' ------------------ FUNCTION TRIM$(S AS STRING) AS STRING ' ------------------ DIM tmp$ AS STRING tmp$ = LTRIM$(S) tmp$ = RTRIM$(tmp$) result = tmp$ END FUNCTION
' ------------------ FUNCTION STRING$(Number AS INTEGER, S AS STRING) AS STRING ' ------------------ DIM Index AS INTEGER Index = 1 WHILE Index <= Number result = result + MID$(S, 1, 1) Index = Index + 1 WEND END FUNCTION
' ------------------ FUNCTION REPLACE$(strOriginal AS STRING, strRemoveTxt AS STRING, strReplaceTxt AS STRING) AS STRING ' ------------------ DIM intPos AS INTEGER DIM str_txt$ AS STRING IF strRemoveTxt = "" THEN result = strOriginal END IF str_txt$ = strOriginal intPos = INSTR(str_txt$, strRemoveTxt, 1) WHILE intPos <> 0 str_txt$ = LEFT$(str_txt$, intPos - 1) + strReplaceTxt + MID$(str_txt$, intPos + LEN(strRemoveTxt), LEN(str_txt$)) intPos = INSTR(str_txt$, strRemoveTxt, 1) result = str_txt$ WEND END FUNCTION
' ------------------ FUNCTION INSTRREV(S AS STRING, Find AS STRING, Start AS INTEGER) AS INTEGER ' ------------------ DIM Found AS INTEGER, Length AS INTEGER, SearchableLength AS INTEGER IF Start = 0 THEN Start = LEN(S) - LEN(Find) END IF Length = LEN(Find) Found = 0 WHILE Start >= 1 AND Found = 0 IF MID$(S, Start, Length) = Find THEN Found = 1 result = Start' + LEN(Find) END IF Start = Start - 1 WEND IF Found = 0 THEN result = 0 END IF END FUNCTION
' ------------------ FUNCTION REVERSE$(S AS STRING) AS STRING ' ------------------ DIM Length AS INTEGER, Index AS INTEGER Index = 1 Length = LEN(S) WHILE Index <= Length result = MID$(S, Index, 1) + result Index = Index + 1 WEND END FUNCTION
' ------------------ FUNCTION DELSTR$(S AS STRING, Start AS INTEGER, Length AS INTEGER) AS STRING ' ------------------ result = MID$(S, 1, Start - 1) + MID$(S, Start + Length, LEN(S)) END FUNCTION
' ------------------ FUNCTION TALLY(Search AS STRING, Match AS STRING) AS INTEGER ' ------------------ DIM Position AS INTEGER DIM AtEND AS INTEGER DIM SumIt AS INTEGER SumIt = 0 Position = 1 AtEND = 0 WHILE AtEND = 0 Position = INSTR(Search, Match, Position) IF Position = 0 THEN AtEND = 1 ELSE Position = Position + 1 SumIt = SumIt + 1 END IF WEND result = SumIt END FUNCTION
' TESTING
DIM s$ AS STRING
s$ = "abcdefghijklmnopqrstuvwxyz" PRINT MID$(s$, 13, 1) PRINT LEN(SPACE$(20)) PRINT ASC("A") PRINT CHR$(65) PRINT LCASE$("THIS sHoUlD BE LOWER CASE") PRINT UCASE$("this sHoUlD be upper case") PRINT LEFT$(s$, 3) PRINT RIGHT$(s$, 3) PRINT "|";LTRIM$(" Test "),"|" PRINT "|";RTRIM$(" Test "),"|" PRINT STRING$(5,"#") PRINT REPLACE$("BOT", "B", "R") PRINT INSTRREV(s$, "t", 26) PRINT REVERSE$("REVERSE") PRINT DELSTR$("xyz", 2, 1) PRINT TALLY("Seattle", "e") PRINT "|";TRIM$(" Test "),"|" PRINT INSTR("BASM FUN", "UN", 1) PRINT REPLACE$("TALLY TALLY", "L", "B")
jrs@laptop:~/BASM64/vovchik$ BASM String.inc
BASM Linux 64 (i386 output) - Version 1.0 Build 2 Currently compiling "String.inc": - Compile time -> 0.015701 seconds - Assemble time -> 0.000544 seconds - Linking time -> 0.000169 seconds ------------------------------- - Total time -> 0.016506 seconds jrs@laptop:~/BASM64/vovchik$ ./String m 20 65 A this should be lower case THIS SHOULD BE UPPER CASE abc xyz |Test | | Test| ##### ROT 20 ESREVER xz 2 |Test| 7 TABBY TABBY jrs@laptop:~/BASM64/vovchik$
|
|
|
BASM
Dec 7, 2014 20:38:34 GMT 1
Post by vovchik on Dec 7, 2014 20:38:34 GMT 1
Dear John, I think I now have fixed REPLACE$ properly for multiple instances. It's in the archive... With kind regards, vovchik UPDATE: And I now added the following code... (archive updated). ' ------------------ FUNCTION WORD$(var$ AS STRING, p$ AS STRING, index AS INTEGER) AS STRING ' ------------------ ' WORD$() returns the nth delimited word/substring, where ' var$ = string to search ' p$ = a delimiter between words/substrings (usually a space ' but it could be anything, e.g. newline when reading a text file) ' index = the nth word/substring to return DIM lp AS INTEGER DIM bak AS INTEGER DIM x AS INTEGER DIM c AS INTEGER lp = LEN(p$) bak = 1 x = 1 index = index + 1 WHILE x > 0 x = INSTR(var$ & p$, p$, bak + 1) IF x THEN c = c + 1 IF c = index THEN result = MID$(var$, bak, x - bak) END IF bak = x + lp END IF WEND END FUNCTION
PRINT WORD$("this|THAT|AND THE OTHER", "|", 1) PRINT WORD$("this|THAT|AND THE OTHER", "|", 2) PRINT WORD$("this|THAT|AND THE OTHER", "|", 3) PRINT WORD$("this|THAT|AND THE OTHER", "|", 4)
Attachments:airstrings4.bas.tar.gz (2.05 KB)
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 8, 2014 0:21:25 GMT 1
Post by Deleted on Dec 8, 2014 0:21:25 GMT 1
Nice!
jrs@laptop:~/BASM64/vovchik$ BASM String.inc
BASM Linux 64 (i386 output) - Version 1.0 Build 2 Currently compiling "String.inc": - Compile time -> 0.025387 seconds - Assemble time -> 0.000808 seconds - Linking time -> 0.000208 seconds ------------------------------- - Total time -> 0.026506 seconds jrs@laptop:~/BASM64/vovchik$ ./String m 20 65 A this should be lower case THIS SHOULD BE UPPER CASE abc xyz |Test | | Test| ##### ROT 20 ESREVER xz 2 |Test| 7 TABBY TABBY this THAT AND THE OTHER
jrs@laptop:~/BASM64/vovchik$
I'm going to release a Build 2 (Windows & Linux) once I get your Math.inc library.
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 8, 2014 3:58:41 GMT 1
Post by Deleted on Dec 8, 2014 3:58:41 GMT 1
What if we create a BASMGtk.so that would link in Gtk dynamically but would include gtk.h so everything is initialized to the defaults. In a BASM program "./BASMGtk.so" would be the shared object for Gtk related stuff.
|
|
|
BASM
Dec 8, 2014 9:22:07 GMT 1
Post by vovchik on Dec 8, 2014 9:22:07 GMT 1
Dear John, The GTK wrapper would be a rather big undertaking - but not impossible. It would be much easier in the interim to do a HUG.so wrapper, which is manageable but I have to get PROPERTY to work and figure out why we have the font problem. Here is the math lib. Note that FLOOR, when run directly gives that weird result but performs properly when it is called in other FUNCTIONS. Also, BASE actually returns what FLOOR ought to return and does nothing more than call FLOOR. Weird. The short-term workaround is to use BASE and not FLOOR, but keep floor in because it is needed for many things when it is called. With kind regards, vovchik
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 8, 2014 9:32:35 GMT 1
Post by Deleted on Dec 8, 2014 9:32:35 GMT 1
I agree that we should use hug.so as our Gtk base. The nm command shows the Gtk direct commands and HUG wrapper functions as exported. I'm building the latest BaCon 32 on in my Ubuntu 32 bit VirtualBox as it's a PITA doing it under 64 bit. (chicken/egg thing) Does button text (labels) work calling Gtk direct functions via the hug.so library? Thanks for the Math.inc library! We are going to have to change your name from vovchik to Mr. Include.
|
|
Deleted
Deleted Member
Posts: 0
|
BASM
Dec 8, 2014 11:36:30 GMT 1
Post by Deleted on Dec 8, 2014 11:36:30 GMT 1
It doesn't look like we can call Gtk functions directly from the hug.so. We also need a FORMAT() function to format numerical data. I wonder if this would help. pango_font_description_from_string("Sans Bold 12").
|
|
|
BASM
Dec 8, 2014 14:35:11 GMT 1
Post by alexfish on Dec 8, 2014 14:35:11 GMT 1
Hi John Vovchik and All
RE SET-PROPERTY ETC
have not looked at all the file RE Gtk only Vochik's example top of
did not notice any import lines for g_object
The SETPROPERTY & SETPROPERTY are macro functions within hug
also need to call the correct lib functions within hug to access gtk etc libs
have not got hug at present but here be an example from lib gfx , so will have to examine the hug.bac
the gxf example imports now these go below other IMPORTS
REM ------------------------------------------------------------------------------------------------------------------ hug_Gobject$ = GFXLIB("gobject") IMPORT "g_object_set(long,char*,...)" FROM hug_Gobject$ TYPE void IMPORT "g_object_get(long,char*,...)" FROM hug_Gobject$ TYPE void IMPORT "g_object_set_data(long,char*,...)" FROM hug_Gobject$ TYPE void IMPORT "g_object_get_data(long,char*,...)" FROM hug_Gobject$ TYPE char* IMPORT "g_object_unref(long)" FROM hug_Gobject$ TYPE void PROTO PROPERTY DEF FN PROPERTY(widget, name, ...) = g_object_set(widget, name, __VA_ARGS__, NULL) PROTO SETPROPERTY DEF FN SETPROPERTY(widget, name, ...) = g_object_set(widget, name, __VA_ARGS__, NULL) PROTO GETPROPERTY DEF FN GETPROPERTY(widget, name, ...) = g_object_get(widget, name, __VA_ARGS__, NULL) hug_Gdk$=GFXLIB("gdk") IMPORT "gdk_screen_get_width(long)" FROM hug_Gdk$ TYPE int IMPORT "gdk_screen_height(long)" FROM hug_Gdk$ TYPE int IMPORT "gdk_screen_get_default" FROM hug_Gdk$ TYPE long
REM ------------------------------------------------------------------------------------------------------------------
@ Vovchik if stuck on this one can post the bits , to see what can do with the Properties.
Added , in hug_elm libs there is a work around for the __VA_ARGS__
long winded but only way could get set property to match elm requirements , here looking at var args as (C)
or possible pass as void , BR Alex
Also forgot to mention I posted a Nasm gtk example somewhere on the forum, see if can find the link
Added :: just looked in basm sources there be a MACRO.INC in there...
|
|
|
BASM
Dec 8, 2014 16:10:48 GMT 1
Post by vovchik on Dec 8, 2014 16:10:48 GMT 1
Dear Alex,
Thanks. I tried g_object_set and g_object_set_property (single property/value pairs) directly but am stuck trying to get basm to handle the value argument, which is an opaque GValue structure that can accommodate ints (booleans), doubles and strings. Any ideas?
With kind regards, vovchik
|
|
|
BASM
Dec 8, 2014 17:08:24 GMT 1
Post by alexfish on Dec 8, 2014 17:08:24 GMT 1
Hi Vovchik
If can remember at experimental Elementary we casting as long but any direct functions need to be cast as per object Struct
so can remember making a separate .so to communicate with the widget , since can not pass long as struct U + possible have to BE as in 64Bit
if can post the sources you be using + and example of the button and only those bits , have now got the new hug , see what best approach be
in Simple terms Widget *the_actual ... hence reason possible use void as in *void , they may work via the macro if not then may be .so will
Added .. think about the callback function it works in hug and that works via the g_object.
If By reason , not yet proved
then should be able to reach by the (object, "clicked",*first_property_name,NULL)
So can U confirm the Callback function is working or not.
BR Alex
Added. got the gtk demo up and running
will now start looking . so here is hoping ... since callback does work
|
|