From a51787d899920a394968f713689307c826068c79 Mon Sep 17 00:00:00 2001 From: Armando Rivera Date: Wed, 31 Oct 2018 23:49:20 -0400 Subject: [PATCH 1/8] Add GRAB$ to find and extract strings between two delimiters --- runtime.inc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/runtime.inc b/runtime.inc index fb17571..561a926 100644 --- a/runtime.inc +++ b/runtime.inc @@ -242,3 +242,11 @@ ENDFUNCTION FUNCTION INT VAL (CSTRING str) BEGIN RETURN atoi(str.c_str()); ENDFUNCTION + +FUNCTION CSTRING GRAB$(CONSTANT CSTRING &src, CONSTANT CSTRING &start, CONSTANT CSTRING &stop) { + DIM AS size_t begin = src.find(start); + DIM AS size_t end = (begin + start.length()); + DIM AS size_t term = src.find(stop); + + return src.substr(end, (term - end)); +} \ No newline at end of file From 0aeb962a4e92ac5a1cea8ef9a3f2e4f5485bffc3 Mon Sep 17 00:00:00 2001 From: Armando Rivera Date: Thu, 1 Nov 2018 00:35:43 -0400 Subject: [PATCH 2/8] Preliminary libcurl support --- header.inc | 2 ++ jade.h | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/header.inc b/header.inc index 469f7e6..11aaf5b 100644 --- a/header.inc +++ b/header.inc @@ -33,6 +33,7 @@ #define ENDFUNCTION } #define DIM #define AS +#define DEF #define SUB void #define ENDSUB } #define BEGIN { @@ -70,6 +71,7 @@ #define INTEGER int #define UINT unsigned int #define VECTOR std::vector +#define ARRAY std::vector #define MAP std::map #define CHAR char #define ENUM enum { diff --git a/jade.h b/jade.h index bd15518..76950f2 100644 --- a/jade.h +++ b/jade.h @@ -1,3 +1,8 @@ #include "header.inc" #include "runtime.inc" +#ifdef USE_CURL + #include "curl.inc" +#endif + + From b204d34e86edbe8b9de5cdec0a390f56586d6083 Mon Sep 17 00:00:00 2001 From: Armando Rivera Date: Thu, 1 Nov 2018 04:02:31 -0400 Subject: [PATCH 3/8] Finished CURL, added REGEX support --- header.inc | 4 +++- runtime.inc | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/header.inc b/header.inc index 11aaf5b..f5cd747 100644 --- a/header.inc +++ b/header.inc @@ -24,6 +24,7 @@ #include #include #include +#include /* DEFINES */ #define MAIN int main (int argc, char** argv) { @@ -88,7 +89,8 @@ #define NEXT } #define STRARRAY VECTOR #define LEN(x) x.size() - +#define REGQUERY std::regex +#define REGMATCH std::smatch diff --git a/runtime.inc b/runtime.inc index 561a926..ef01591 100644 --- a/runtime.inc +++ b/runtime.inc @@ -18,6 +18,16 @@ DECLARE FUNCTION CSTRING FORMAT$ (CONSTANT CSTRING fmt, ...); DECLARE FUNCTION VECTOR SPLIT (CONSTANT CSTRING input, CONSTANT CSTRING separators, BOOL remove_empty = TRUE); DECLARE SUB PRINT (CSTRING); DECLARE SUB SAVEFILE(CSTRING src, CSTRING fname); +DECLARE FUNCTION CSTRING REGEX (CSTRING src, CSTRING query); + +FUNCTION CSTRING REGEX (CSTRING src, CSTRING query) { + CSTRING result; + REGMATCH match; + REGQUERY term(query); + if (regex_search(src, match, term) == true) + result = match[1]; + return result; +ENDFUNCTION FUNCTION VECTOR SPLIT (CONSTANT CSTRING input, CONSTANT CSTRING separators, BOOL remove_empty) BEGIN DIM VECTOR lst; @@ -127,7 +137,7 @@ ENDFUNCTION FUNCTION CSTRING MCASE$ (CSTRING S) BEGIN DIM AS CSTRING tmpStr(S); DIM AS bool capFlag = FALSE; - DIM AS register size_t i; + DIM AS size_t i; std::transform(tmpStr.begin(),tmpStr.end(),tmpStr.begin(),::tolower); From 22a35536522fc5ad358aec8bdb095c0ddbe06b0c Mon Sep 17 00:00:00 2001 From: Armando Rivera Date: Thu, 1 Nov 2018 04:19:32 -0400 Subject: [PATCH 4/8] ADDED CLS and PRINTNL --- header.inc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/header.inc b/header.inc index f5cd747..788a5e2 100644 --- a/header.inc +++ b/header.inc @@ -61,6 +61,7 @@ #define _TO_ ... #define ENDCASE break; #define CASE_ELSE default +#define CLS printf("\33[2J\33[H") #define ENDSELECT } #define WHILE while #define WEND } @@ -91,6 +92,8 @@ #define LEN(x) x.size() #define REGQUERY std::regex #define REGMATCH std::smatch +#define PRINTNL printf("\n") +#define NL std::endl From 8f695e047994d31fe8dc66fea1c4a86ccf0385fe Mon Sep 17 00:00:00 2001 From: Armando Rivera Date: Thu, 1 Nov 2018 04:20:09 -0400 Subject: [PATCH 5/8] Added CURL module --- curl.inc | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 curl.inc diff --git a/curl.inc b/curl.inc new file mode 100644 index 0000000..f9a39ea --- /dev/null +++ b/curl.inc @@ -0,0 +1,63 @@ + +#ifdef USE_CURL + #include + + typedef int (*JADE_PROGRESS_CALLBACK)(void*,double,double,double,double); + typedef int (*JADE_WRITE_CALLBACK)(void*,long,long,void*); + + void downloadFile(CSTRING url, CSTRING downloadFileName, void *progress_callback); + void downloadPage(CSTRING url, CSTRING buffer, void *write_callback); + + + + + int jade_curl_progress_callback(void* clientp, double dltotal, double dlnow, double ultotal, double ulnow ) { + printf("Downloaded %d of %d bytes\r",(int)dlnow,(int)dltotal); + return 0; + } + + int jade_curl_write_data_callback (void* content, long size, long nmemb, void* stream) { + ((std::string*)stream)->append((char*)content, size * nmemb); + return size * nmemb; + } + + std::string downloadPage(CSTRING url,JADE_WRITE_CALLBACK write_callback = jade_curl_write_data_callback) { + void* handle; + int success; + std::string buffer$; + + handle = curl_easy_init(); + curl_easy_setopt(handle, CURLOPT_URL, url.c_str()); + curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION,1); + curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_callback); + curl_easy_setopt(handle, CURLOPT_WRITEDATA, &buffer$); + + + success = curl_easy_perform(handle); + + curl_easy_cleanup(handle); + + return buffer$; + } + void downloadFile(CSTRING url, CSTRING downloadFileName, JADE_PROGRESS_CALLBACK progress_callback=jade_curl_progress_callback) { + void* handle; + int success; + FILE *fp; + + handle = curl_easy_init(); + if ((fp = fopen(downloadFileName.c_str(), "wb+"))) { + curl_easy_setopt(handle, CURLOPT_URL, url.c_str()); + curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION,1); + curl_easy_setopt(handle, CURLOPT_WRITEDATA, fp); + curl_easy_setopt(handle, CURLOPT_NOPROGRESS,0); + curl_easy_setopt(handle, CURLOPT_PROGRESSDATA,downloadFileName.c_str()); + curl_easy_setopt(handle, CURLOPT_PROGRESSFUNCTION,progress_callback); + + success = curl_easy_perform(handle); + fclose(fp); + } + curl_easy_cleanup(handle); + printf("\n\nDownload of '%s' Complete.\n\n", downloadFileName.c_str()); + } + +#endif From 38e80da075a465c29d132aa97dada5dc315e775e Mon Sep 17 00:00:00 2001 From: Armando Rivera Date: Fri, 2 Nov 2018 20:54:15 -0400 Subject: [PATCH 6/8] misc cleanup --- Keywords.txt | 13 +++++++++++++ Prototypes.txt | 4 +++- header.inc | 3 ++- runtime.inc | 4 +++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Keywords.txt b/Keywords.txt index cd08620..8172163 100644 --- a/Keywords.txt +++ b/Keywords.txt @@ -1,5 +1,6 @@ ADDR AND +ARRAY AS BEGIN BOOL @@ -10,10 +11,12 @@ CASE_ELSE CHAR CLASS CLASS +CLS CONSTANT CONSTRUCTOR DECLARE DECR +DEF DIM DO ELSE @@ -34,12 +37,15 @@ FALSE FOR FORMAT$ FUNCTION +GRAB$ IF INCR INSTR INT +INTEGER LCASE$ LEFT$ +LEN( LOADFILE$ LPCHAR LTRIM$ @@ -48,10 +54,15 @@ MAP MCASE$ MID$ NEXT +NL NOT OR PRINT +PRINTNL PTR +REGEX +REGMATCH +REGQUERY REPLACE$ RETURN REVERSE$ @@ -64,6 +75,8 @@ SPLIT SPLITPATH$ STEP STR$ +STR$ +STRARRAY SUB THEN TO diff --git a/Prototypes.txt b/Prototypes.txt index 7e13fe5..e88cba4 100644 --- a/Prototypes.txt +++ b/Prototypes.txt @@ -1,5 +1,6 @@ ENC$ (CSTRING A, INT L, INT R) -FORMAT$ (CONSTANT CSTRING &fmt, ...) +FORMAT$ (CONSTANT CSTRING fmt, ...) +GRAB$(CONSTANT CSTRING &src, CONSTANT CSTRING &start, CONSTANT CSTRING &stop) INSTR (CSTRING s,CSTRING match, size_t offset) LCASE$ (CSTRING str) LEFT$ (CSTRING s, INT length) @@ -8,6 +9,7 @@ LTRIM$ (CSTRING s) MCASE$ (CSTRING S) MID$ (CSTRING s, INT start, INT length) PRINT (CSTRING A="") +REGEX (CSTRING src, CSTRING query) REPLACE$ (CSTRING subject, CONSTANT CSTRING& search, CONSTANT CSTRING& replace) REVERSE$ (CSTRING src) RIGHT$ (CSTRING s, INT length) diff --git a/header.inc b/header.inc index 788a5e2..1f18d94 100644 --- a/header.inc +++ b/header.inc @@ -67,7 +67,8 @@ #define WEND } #define RETURN return #define CONSTANT const -#define STR$( x ) dynamic_cast< std::ostringstream & >( ( std::ostringstream() << std::dec << x ) ).str() +// #define STR$( x ) dynamic_cast< std::ostringstream & >( ( std::ostringstream() << std::dec << x ) ).str() +#define STR$(x) std::to_string(x) #define BOOL bool #define INT int #define INTEGER int diff --git a/runtime.inc b/runtime.inc index ef01591..208208e 100644 --- a/runtime.inc +++ b/runtime.inc @@ -24,8 +24,10 @@ FUNCTION CSTRING REGEX (CSTRING src, CSTRING query) { CSTRING result; REGMATCH match; REGQUERY term(query); - if (regex_search(src, match, term) == true) + if (regex_search(src, match, term,std::regex_constants::match_any) == true){ + std::cout << match.size() << std::endl; result = match[1]; + } return result; ENDFUNCTION From edc01b6367c555e58f927e631599103b998eb20a Mon Sep 17 00:00:00 2001 From: Armando Rivera Date: Fri, 2 Nov 2018 21:35:04 -0400 Subject: [PATCH 7/8] updated STR --- header.inc | 2 ++ jade.h | 1 + 2 files changed, 3 insertions(+) diff --git a/header.inc b/header.inc index 1f18d94..ad52029 100644 --- a/header.inc +++ b/header.inc @@ -115,3 +115,5 @@ typedef std::string CSTRING; char LF [2]= {10,0}; // Line Feed + + diff --git a/jade.h b/jade.h index 76950f2..be8ff78 100644 --- a/jade.h +++ b/jade.h @@ -5,4 +5,5 @@ #include "curl.inc" #endif +template From 4a7ce5829f75c4822f054c33d48f7bdb5cce1bae Mon Sep 17 00:00:00 2001 From: Armando Rivera Date: Fri, 2 Nov 2018 21:37:42 -0400 Subject: [PATCH 8/8] Adding Templates for some testing --- jade.h | 1 + 1 file changed, 1 insertion(+) diff --git a/jade.h b/jade.h index be8ff78..78bc053 100644 --- a/jade.h +++ b/jade.h @@ -6,4 +6,5 @@ #endif template +template