|
Post by bigbass on Sept 20, 2019 19:15:22 GMT 1
showing typedef structs ported to bacon using dot member and -> member
we could get this info without the struct the demo shows how the members are declared and how to make or port code when we have a typedef
'--- typedef struct non pointer '--- using C stucts in BaCon! '--- undocumented tricks '--- by bigbass June 13 2013 '--- fixed in 2019 to compile in C and C++
PRAGMA INCLUDE <string.h> <stdio.h> PRAGMA LDFLAGS PRAGMA COMPILER gcc PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith PRAGMA BACONLIB OPTION PARSE FALSE
'---HERE is homemade typedef struct called stuff '--- another way to declare the struct members '--- and show how to place values or strings in a struct struct { \ char* release ; \ char* version; \ char* machine; \ char* kernel; \ char* extra;} (stuff)
'--- Current BaCon release result = EXEC$("bacon -v" ) stuff.release =(char*)result
PRINT stuff.release FORMAT "%s\n"
'--- hardware type the system is running on. result = EXEC$("uname -p" ) stuff.machine = (char*)result PRINT stuff.machine FORMAT "%s\n"
'--- kernel the system is running on. result = EXEC$("uname -r" ) stuff.kernel = (char*)result PRINT stuff.kernel FORMAT "%s\n"
----------------------------------------------------------------------------------
'--- typedef struct with pointer '--- using C stucts in BaCon! '--- undocumented tricks '--- by bigbass June 13 2013 '--- fixed in 2019 to compile in C and C++ '--- fixed april 28 2020 added stucture in memory
PRAGMA INCLUDE <stdio.h> PRAGMA INCLUDE <stdlib.h> PRAGMA INCLUDE <string.h> PRAGMA COMPILER gcc PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith
OPTION PARSE FALSE
'--- Here is homemade typedef struct called *stuff '--- another way to declare the struct members '--- and show how to place values or strings in a struct struct info { \ char* release ; \ char* version; \ char* machine; \ char* kernel; \ char* extra;} DECLARE info TYPE struct DECLARE stuff TYPE struct info*
struct info *stuff '--- Create structure in memory stuff = (struct info* )malloc(sizeof(struct info))
'--- Current BaCon release result = EXEC$("bacon -v" ) stuff->release = (char*)result
PRINT stuff->release FORMAT "%s\n"
'--- hardware type the system is running on result = EXEC$("uname -m" ) stuff->machine = (char*)result PRINT stuff->machine FORMAT "%s\n"
'--- kernel the system is running on result = EXEC$("uname -r" ) stuff->kernel = (char*)result PRINT stuff->kernel FORMAT "%s\n"
free(stuff)
TERMINAL OUTPUT for both
BaCon version 3.9.3 on Linux armv7l - (c) Peter van Eerten - MIT License.
armv7l
4.15.0-1040-raspi2
|
|
|
Post by bigbass on Sept 21, 2019 23:31:48 GMT 1
now to make it more bacon like using RECORD so that porting code will be easier when we have several examples
note the pkgconfig location is different on arm when we look for gtk2 and gtk3 arm-linux-gnueabihf
'--- using C structs to RECORD in BaCon! '--- undocumented tricks '--- by bigbass June 13 2013 '--- updated code 2019 to use RECORD and <gnu/libc-version.h>
PRAGMA INCLUDE <string.h> <stdio.h> <gnu/libc-version.h> PRAGMA LDFLAGS PRAGMA COMPILER gcc PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith 'PRAGMA BACONLIB OPTION PARSE FALSE
RECORD stuff LOCAL release TYPE STRING LOCAL libc TYPE STRING LOCAL gtk2version TYPE STRING LOCAL gtk3version TYPE STRING LOCAL machine TYPE STRING LOCAL kernel TYPE STRING LOCAL bash TYPE STRING END RECORD
DECLARE result$ TYPE STRING '--- Current BaCon release result$= EXEC$("bacon -v" ) stuff.release = result$ PRINT stuff.release FORMAT "%s\n"
result$ = gnu_get_libc_version() stuff.libc = result$ PRINT "LIBC ",stuff.libc FORMAT "%s%s\n"
'--- Current gtk2 version result$= EXEC$("cat /usr/lib/arm-linux-gnueabihf/pkgconfig/gtk+-2.0.pc | grep Version:" ) stuff.gtk2version = result$ PRINT "GTK2 ",stuff.gtk2version FORMAT "%s%s\n"
'--- Current gtk3 version result$= EXEC$("cat /usr/lib/arm-linux-gnueabihf/pkgconfig/gtk+-3.0.pc | grep Version:" ) stuff.gtk3version = result$ PRINT "GTK3 ", stuff.gtk3version FORMAT "%s%s\n"
'--- hardware type the system is running on. result$= EXEC$("uname -p" ) stuff.machine = result$ PRINT "machine ",stuff.machine FORMAT "%s%s\n"
'--- kernel the system is running on. result$= EXEC$("uname -r" ) stuff.kernel = result$ PRINT "kernel ",stuff.kernel FORMAT "%s%s\n"
'--- Bash version result$= EXEC$("bash --version | head -1") stuff.bash = result$ PRINT stuff.bash FORMAT "%s\n"
TERMINAL OUT
BaCon version 3.9.3 on Linux armv7l - (c) Peter van Eerten - MIT License.
LIBC 2.27 GTK2 Version: 2.24.32
GTK3 Version: 3.22.30
machine armv7l
kernel 4.15.0-1040-raspi2
GNU bash, version 4.4.19(1)-release (arm-unknown-linux-gnueabihf)
|
|
|
Post by bigbass on Feb 10, 2020 19:03:40 GMT 1
Hello bacon forum I wanted to port this c++ example with class for quite some time (a complex snippet) but gave it another try today and got it working ! now we have a bacon port of C++ fltk with a working example of the bacon CLASS will post the original source code link so that you could compare the changes needed seriss.com/people/erco/fltk/#SimpleTerminalPRAGMA LDFLAGS -lfltk -lpthread
PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -Wno-multichar PRAGMA INCLUDE <iostream> <string.h> PRAGMA INCLUDE <FL/Fl.H> <FL/Fl_Double_Window.H> <FL/Fl_Text_Editor.H> OPTION PARSE FALSE
ALIAS popen TO _popen ALIAS pclose TO _pclose '--- now using the official baconized CLASS ENDCLASS command '// Simple terminal simulator (PROOF OF CONCEPT) '// 1.00 erco 07/30/2009 -- initial implementation '// 1.10 erco 09/06/2009 -- use Fl::event_text() to handle non-ascii codes '// fltk-config --compile dumbterm.cxx '// ported to bacon by bigbass modified to use arrow operators -> 2-10-2020
CLASS MyTerminal : public Fl_Text_Editor Fl_Text_Buffer *buff; char cmd[1024]; public: MyTerminal(int X,int Y,int W,int H,const char* L=0) : Fl_Text_Editor(X,Y,W,H,L) { buff = new Fl_Text_Buffer(); buffer(buff); textfont(FL_COURIER); textsize(12); cmd[0] = 0; } // Append to buffer, keep cursor at end void append(const char*s) { buff->append(s); // Go to end of line insert_position(buffer()->length()); scroll(count_lines(0, buffer()->length(), 1), 0); } // Run the specified command in the shell, append output to terminal void RunCommand(const char *command) { append("\n"); fprintf(stderr, "EXECUTING: '%s'\n", command); FILE *fp = popen(command, "r"); if ( fp == 0 ) { append("Failed to execute: '"); append(command); append("'\n"); } else { char s[1024]; while ( fgets(s, sizeof(s)-1, fp) ) { append(s); } pclose(fp); } } // Handle events in the Fl_Text_Editor int handle(int e) { switch (e) { case FL_KEYUP: { int key = Fl::event_key(); if ( key == FL_Enter ) return(1); // hide Enter from editor if ( key == FL_BackSpace && cmd[0] == 0 ) return(0); break; } case FL_KEYDOWN: { int key = Fl::event_key(); // Enter key? Execute the command, clear command buffer if ( key == FL_Enter ) { // Execute your commands here strcat(cmd, " 2>&1"); // stderr + stdout RunCommand(cmd); cmd[0] = 0; append("\nEnter a shell command: "); return(1); // hide 'Enter' from text widget } if ( key == FL_BackSpace ) { // Remove a character from end of command buffer if ( cmd[0] ) { cmd[strlen(cmd)-1] = 0; break; } else { return(0); } } else { // Append text to our 'command' buffer strncat(cmd, Fl::event_text(), sizeof(cmd)-1); cmd[sizeof(cmd)-1] = 0; } break; } } return(Fl_Text_Editor::handle(e)); } ENDCLASS
'--- was difficult to port had to change to pointers '--- and arrows operators to get it to compile and run (bigbass) '--- but in the end its more portable with fltk now DECLARE win TYPE Fl_Double_Window* DECLARE edit TYPE MyTerminal* win = new Fl_Double_Window(620,520,"Terminal Test") edit = new MyTerminal(10,10,win->w()-20,win->h()-20) edit->append("Line one\nLine Two\nEnter a shell command: ") win->resizable(win) win->show() Fl::run()
|
|
|
Post by bigbass on Mar 16, 2020 6:07:40 GMT 1
Hello
we don't have much demo code for CLASS so here we go
I know there are a few that may like to see some demos because this one is undocumented it uses the "new" command to place the class in memory
Joe
PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -fpermissive
OPTION PARSE FALSE
'---The class does the declaring for you
CLASS Books public: const char* title; const char* author; const char* subject; int book_id; END CLASS
'---pointer to an object declaration (we use a class called Books) DECLARE Book1 TYPE Books* '--- finally got the correct syntax for class Book1 = new Books()
'--- initialize the strings const char* in c++ Book1->title = "C Programming to bacon " Book1->author = "anyone" Book1->subject ="RECORD Tutorial" Book1->book_id = 1234567
PRINT "Book title : " ,Book1->title FORMAT "%s%s\n" PRINT "Book author : ", Book1->author FORMAT "%s%s\n" PRINT "Book subject : ", Book1->subject FORMAT "%s%s\n" PRINT "Book book_id : ", Book1->book_id FORMAT "%s%d\n"
|
|
|
Post by alexfish on Mar 16, 2020 12:04:24 GMT 1
Hi Joe
on BaCon version 3.9.3
I had to add this line
PRAGMA LDFLAGS -lbacon++
BR Alex
|
|
|
Post by bigbass on Mar 16, 2020 20:34:22 GMT 1
Hello Alex
thanks for testing and the feedback fix
noticed you are using bacon 3.9.3 still. I'm sure you have a reason
(but the latest fossil as of today fixes some problems with RECORD) you might give it a try seems to be fine for what I have tested so far with gcc g++ clang and clang++
Joe
|
|
|
Post by bigbass on Mar 19, 2020 22:57:40 GMT 1
Hello another example with a difficult multiple typedef struct I converted it to a class so that I could take advantage of showing why the C++ "new command" allows us to make multiple references to the class type (typedef struct) these have always been a pain because of dot member vs arrow operator syntax I started out porting this www.codesdope.com/cpp-typedef/then used Bacon's CLASS And Bacon's Print and removed the c++ strcpy and namespace (any demo code example can save you hours when you have to port something) or just grasp the idea what needs to be done and the different options you have bacon can handle many different coding styles that makes it even more powerful! its easier now to mix this with fltk code without having to rewrite a lot of code Joe PRAGMA COMPILER g++ 'PRAGMA COMPILER clang++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -Wno-deprecated PRAGMA INCLUDE <iostream> PRAGMA INCLUDE <cstring> OPTION PARSE FALSE '---The class does the declaring for you
CLASS student public: int roll_no; const char* name; int phone_number; END CLASS
'---pointer to an object declaration (we use a class called student) '--- the "new command" allows multiple typedefs in memory DECLARE st1 TYPE student* DECLARE st2 TYPE student* DECLARE st3 TYPE student*
'--- correct syntax for class to typedef pointer st1 = new student() st2 = new student() st3 = new student() st1->roll_no = 1 st1->name = "Brown" st1->phone_number = 123443 st2->roll_no = 2 st2->name = "Sam" st2->phone_number = 1234567822
st3->roll_no = 3 st3->name = "Addy" st3->phone_number = 1234567844 PRINT "First Student" PRINT "roll no : ", st1->roll_no FORMAT "%s%d\n" PRINT "name : " , st1->name FORMAT "%s%s\n" PRINT "phone no : " , st1->phone_number FORMAT "%s%d\n" PRINT "Second Student" PRINT "roll no : " , st2->roll_no FORMAT "%s%d\n" PRINT "name : " , st2->name FORMAT "%s%s\n" PRINT "phone no : " , st2->phone_number FORMAT "%s%d\n" PRINT "Third Student" PRINT "roll no : " ,st3->roll_no FORMAT "%s%d\n" PRINT "name : ", st3->name FORMAT "%s%s\n" PRINT "phone no : " , st3->phone_number FORMAT "%s%d\n"
|
|
|
Post by vovchik on Mar 20, 2020 0:13:55 GMT 1
Dear Joe, Thanks for the example. It's very clear and straightforward. And thanks for posting - so we all know you are alive, thinking and productive - in these trying and uncertain times. I hope all of us on the forum are riding out this coronavirus threat OK. Your old friend, vovchik
|
|
|
Post by bigbass on Apr 27, 2020 2:05:36 GMT 1
how you could work with a CLASS
and test it
will use a "simulated" widget class I was thinking about mofit widgets in C++ its just a demo at this stage this looks like fltk syntax
PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -fpermissive -Wno-deprecated
OPTION PARSE FALSE
'---The class does the declaring for you '---and we dont need to end with \ CLASS XWINDOW public: char* type; char* name; char* title; int width; int height; char* parent; char* label; END CLASS
'---pointer to an object declaration (we use a class called XWINDOW) DECLARE XGUI TYPE XWINDOW* '--- the correct syntax for class in memory XGUI = new XWINDOW()
XGUI->type="window" XGUI->name="window" XGUI->title="Hello world application" XGUI->width=300 XGUI->height=200
PRINT "type ",XGUI->type FORMAT "%s%s\n" PRINT "name ", XGUI->name FORMAT "%s%s\n" PRINT "title ",XGUI->title FORMAT "%s%s\n" PRINT "width ", XGUI->width FORMAT "%s%d\n" PRINT "height ",XGUI->height FORMAT "%s%d\n"
'PRINT "now type gets assiged a new string " PRINT XGUI->type="formWidgetClass" PRINT "type ", XGUI->type FORMAT "%s%s\n"
'PRINT "now label gets assiged a new string " XGUI->name="label" XGUI->parent="form" XGUI->label="Hello world" PRINT "name ", XGUI->name FORMAT "%s%s\n" PRINT "parent ", XGUI->parent FORMAT "%s%s\n" PRINT "label ", XGUI->label FORMAT "%s%s\n"
TERMINAL OUT
type window name window title Hello world application width 300 height 200
type formWidgetClass name label parent form label Hello world
|
|
|
Post by bigbass on Apr 27, 2020 5:57:03 GMT 1
I had trouble with pointers in gcc above with bacon 4
I rewrote the code in c++ and class now it works
I know I can do this with less code the focus was a demo with CLASS then doing it memory
PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -Wno-deprecated
OPTION PARSE FALSE
CLASS STUFF public: const char* release ; const char* version; const char* machine; const char* kernel; const char* extra; END CLASS
'---pointer to an object declaration (we use a class called STUFF) DECLARE stuff TYPE STUFF* '--- the correct syntax for class in memory stuff = new STUFF()
DECLARE result TYPE const char* '--- Current BaCon release result = EXEC$("bacon -v" ) stuff->release = (const char*)result PRINT stuff->release FORMAT "%s\n"
'--- hardware type the system is running on result = EXEC$("uname -m" ) stuff->machine = (const char*)result PRINT stuff->machine FORMAT "%s\n"
'--- kernel the system is running on result = EXEC$("uname -r" ) stuff->kernel = (const char*)result PRINT stuff->kernel FORMAT "%s\n"
TERMINAL OUT
BaCon version 4.0.1 on Linux armv7l - (c) Peter van Eerten - MIT License.
armv7l
4.19.97-v7+
|
|
|
Post by Pjot on Apr 27, 2020 8:00:27 GMT 1
Hi Joe, As I mentioned in the other thread, you have to declare memory for the pointer or class. In your code above, you actually *do* allocate memory by using the "new" keyword of C++. Therefore this code does not crash. Also Valgrind does not report memory errors. BR Peter
|
|
|
Post by bigbass on Apr 29, 2020 3:29:04 GMT 1
Thanks Peter for your suggestions
I added memory to the c example code too so now works in c and c++
in c its more complex the fix but figured out how to do it now it works in two steps
'--- typedef struct with pointer '--- using C stucts in BaCon! '--- undocumented tricks '--- by bigbass June 13 2013 '--- fixed in 2019 to compile in C and C++ '--- fixed april 28 2020 added stucture in memory
PRAGMA INCLUDE <stdio.h> PRAGMA INCLUDE <stdlib.h> PRAGMA INCLUDE <string.h> PRAGMA COMPILER gcc PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith
OPTION PARSE FALSE
'--- Here is homemade typedef struct called *stuff '--- another way to declare the struct members '--- and show how to place values or strings in a struct struct info { \ char* release ; \ char* version; \ char* machine; \ char* kernel; \ char* extra;} DECLARE info TYPE struct DECLARE stuff TYPE struct info*
struct info *stuff '--- Create structure in memory stuff = (struct info* )malloc(sizeof(struct info))
'--- Current BaCon release result = EXEC$("bacon -v" ) stuff->release = (char*)result
PRINT stuff->release FORMAT "%s\n"
'--- hardware type the system is running on result = EXEC$("uname -m" ) stuff->machine = (char*)result PRINT stuff->machine FORMAT "%s\n"
'--- kernel the system is running on result = EXEC$("uname -r" ) stuff->kernel = (char*)result PRINT stuff->kernel FORMAT "%s\n"
free(stuff)
terminal out working again !
BaCon version 4.0.1 on Linux armv7l - (c) Peter van Eerten - MIT License.
armv7l
4.19.97-v7+
|
|
|
Post by bigbass on Jun 2, 2020 16:48:08 GMT 1
Remember that bacon has a command that allows us to use CLASS however since that uses c++ ideas you wont find many examples to test with www.basic-converter.org/documentation.html#CLASSI will show some example code how to port to bacon I modified the demo to be easier to adapt to other fltk examples and be compatible with fluid generated code source code reference seriss.com/people/erco/fltk/#PopupCopyPasteMenumy port of it below I plan to add this to something I'm doing and wanted to be transparent and show a stand alone demo first and at the same time give an example for bacon's CLASS command Joe PRAGMA LDFLAGS -lfltk -lfltk_images PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/Fl_Input.H> PRAGMA INCLUDE <FL/Fl_Box.H> PRAGMA INCLUDE <FL/Fl_Image.H> PRAGMA INCLUDE <FL/Fl_Button.H>
PRAGMA INCLUDE <FL/Fl_Menu.H>
DECLARE BOX TYPE Fl_Box* DECLARE BOX2 TYPE Fl_Box* DECLARE ENTRY TYPE Fl_Input* DECLARE WINDOW TYPE Fl_Double_Window* DECLARE BUTTON TYPE Fl_Button*
CLASS MyInput : public Fl_Input static void Copy_CB(Fl_Widget*, void *userdata) { printf("*** COPY ***\n"); MyInput *in = (MyInput*)userdata; in->copy(0); // text selection clipboard in->copy(1); // copy/paste clipboard } static void Paste_CB(Fl_Widget*, void *userdata) { printf("*** PASTE ***\n"); MyInput *in = (MyInput*)userdata; Fl::paste(*in, 1); // 09/03/2013 fix: added ",1" to help paste from e.g. notepad } public: int handle(int e) { switch (e) { case FL_PUSH: // RIGHT MOUSE PUSHED? Popup menu on right click if ( Fl::event_button() == FL_RIGHT_MOUSE ) { Fl_Menu_Item rclick_menu[] = { { "Copy", 0, Copy_CB, (void*)this }, { "Paste", 0, Paste_CB, (void*)this }, { 0 } }; const Fl_Menu_Item *m = rclick_menu->popup(Fl::event_x(), Fl::event_y(), 0, 0, 0); if ( m ) m->do_callback(0, m->user_data()); return(1); // (tells caller we handled this event) } break; case FL_RELEASE: // RIGHT MOUSE RELEASED? Mask it from Fl_Input if ( Fl::event_button() == FL_RIGHT_MOUSE ) { return(1); // (tells caller we handled this event) } break; } return(Fl_Input::handle(e)); // let Fl_Input handle all other events } MyInput(int X,int Y,int W,int H,const char*L=0):Fl_Input(X,Y,W,H,L) { } END CLASS
Fl::scheme("gleam") WINDOW = new Fl_Double_Window(400,45," Copy / Paste Popup") ENTRY = new MyInput(50,10,320,25,"Entry:") WINDOW->show() Fl::run()
|
|
|
Post by bigbass on Nov 3, 2020 7:34:03 GMT 1
adding arrays to a CLASS
make a macro for a c++ UBOUND equivalent called TOTAL_SIZE that will get the array size from inside the CLASS
use the TOTAL_SIZE() macro with the FOR loop also
some more testing with c++ and bacon
Joe
PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -fpermissive
OPTION PARSE FALSE
LOCAL arr[] = { 2, 4, 6, 8, 10 }
'---The class does the declaring for you
CLASS Books public: const char* title; const char* author; const char* subject; int book_id; int array[5] = { 2, 4, 6, 8, 10 }; const char* fruit[4] = {"Banana", "Orange", "Apple", "Mango"}; END CLASS
'--- an object declaration (we use a class called Books) DECLARE Book1 TYPE Books '--- the correct syntax for class Book1 = Books()
'--- initialize the strings const char* in c++ Book1.title = "C++ Programming to bacon " Book1.author = "anyone" Book1.subject ="RECORD Tutorial" Book1.book_id = 1234567
'--- get the array length from a class equivalent of UBOUND '--- make it look like closer to javascript long form manually array_length = SIZEOF(Book1.array) / SIZEOF(Book1.array[0]) fruit_length = SIZEOF(Book1.fruit) / SIZEOF(Book1.fruit[0])
'---make a macro for c++ UBOUND equivalent called TOTAL_SIZE DEF FN TOTAL_SIZE(x) = SIZEOF(x) / SIZEOF(x[0]) PRINT "-------------------------" PRINT TOTAL_SIZE(arr) PRINT TOTAL_SIZE(Book1.fruit) PRINT "-------------------------"
PRINT UBOUND(arr)
PRINT "-------------------------" PRINT array_length PRINT fruit_length
PRINT "Book title : " ,Book1.title FORMAT "%s%s\n" PRINT "Book author : ", Book1.author FORMAT "%s%s\n" PRINT "Book subject : ", Book1.subject FORMAT "%s%s\n" PRINT "Book book_id : ", Book1.book_id FORMAT "%s%d\n"
'--- simplify the syntax using class arrays with int FOR x = 0 TO TOTAL_SIZE(Book1.array) - 1 PRINT Book1.array[x] NEXT
'--- simplify the syntax using class arrays with strings FOR x = 0 TO TOTAL_SIZE(Book1.fruit) -1 PRINT Book1.fruit[x] FORMAT "%s\n" NEXT
|
|
|
Post by bigbass on Mar 3, 2021 5:09:46 GMT 1
working with json on websites can be tricky to parse and tricky to download the json file I just wanted to keep this simple This webpage has many APIs that use json data for testing you can have some fun with it mixedanalytics.com/blog/list-actually-free-open-no-auth-needed-apis/I did this also in node and javascript first experimental-coding.freeforums.net/post/686but since this is the bacon forum I also wrote a json parser for this demo in just bacon *I guess you can say its cheating using wget to some degree but it does what I want to do with little code needed Joe '---convert json to easily readable data '---shorten the code a lot using wget for a json data website SYSTEM " wget -N freegeoip.app/json " DECLARE txt$ TYPE STRING txt$ = LOAD$("json")
SPLIT txt$ BY "," TO array$ SIZE dimension FOR i = 0 TO dimension -1
array$[i] = REPLACE$(array$[i], "{" , "") array$[i] = REPLACE$(array$[i], "}" , "") array$[i] = REPLACE$(array$[i], "[" , "") array$[i] = REPLACE$(array$[i], "]" , "") '--- work around for http:// and https:// '--- we should not have a <|> in json so it '--- is used as a place holder then is returned again array$[i] = REPLACE$(array$[i], "://" , "<|>") array$[i] = REPLACE$(array$[i], ":" , " = ") array$[i] = REPLACE$(array$[i], "<|>" , "://") '---remove double quotes both sides array$[i] = REPLACE$(array$[i], "\"" , "") PRINT array$[i] NEXT
|
|