|
Post by vovchik on Feb 5, 2020 15:35:15 GMT 1
Dear all, I included html_strip (all mods/enhancements welcome) and included weather, which can fetch a brief METAR weather report. More to come.... With kind regards, vovchik Attachments:bish-src.tar.gz (16.74 KB)
|
|
|
Post by alexfish on Feb 5, 2020 23:24:51 GMT 1
Hi Vovchik
Some stripper code .. now can not get complete as per previous post
Think bacon 4 has a problem with CHOP$ , so need to look further ' Peter ?
anyway the code to date
PS below takes into account <body></body> as per normal html so any example code needs this hence if not in the page then will have to rectify::
BR Alex
LOCAL t$ LOCAL Result$ LOCAL Result2$ LOCAL ex$ LOCAL tst1$ LOCAL tst2$ LOCAL st TYPE int LOCAL cann=0 TYPE int LOCAL ch$ LOCAL resline$ txt$= BLOAD("index.html")
txt$ = REPLACE$(txt$,"\n","") txt$ = REPLACE$(txt$,"\t","") txt$ = REPLACE$(txt$,"\r","") txt$ = REPLACE$(txt$,"<br />","<br>") txt$ = txt$ & "<"
LOCAL dimension TYPE int SPLIT txt$ BY "<" TO array$ SIZE dimension
txt$="" FOR x = 0 TO dimension-1 tst1$ = (array$[x]) IF LEFT$(tst1$,4)="body" THEN 'PRINT tst1$ st = 1 END IF
IF LEFT$(tst1$,5)="/body" THEN 'PRINT tst1$ st=0 END IF
'Result$=Result$ & t$ IF st THEN ' === IF LEN(tst1$) THEN IF LEFT$(tst1$,3) != "!--" THEN IF LEFT$(tst1$,3) != "-->" THEN IF LEFT$(tst1$,6) != "script" THEN IF LEFT$(tst1$,8) != "noscript" THEN IF LEFT$(tst1$,5) != "style" THEN IF LEFT$(tst1$,6) != "button" THEN IF LEFT$(tst1$,7) != "/script" THEN IF LEFT$(tst1$,9) != "/noscript" THEN tst1$=CHOP$(tst1$) txt$=txt$ & "<" & tst1$ ' PRINT tst1$ END IF END IF END IF END IF END IF END IF END IF END IF END IF ' === END IF
NEXT
txt$=REPLACE$(txt$,"</i>"," ") txt$=REPLACE$(txt$,"<i>"," ") 'txt$=REPLACE$(txt$,"<table>","\n<table>"); txt$=REPLACE$(txt$,"<tr>","\n<tr>") txt$=REPLACE$(txt$,"<dt>","\n<dt>") txt$=REPLACE$(txt$,"</ol>","</ol>\n") txt$=REPLACE$(txt$,"<ol>","\n<ol>") txt$=REPLACE$(txt$,"<ol ","\n<ol ") txt$=REPLACE$(txt$,"<ul>","\n<ul>") txt$=REPLACE$(txt$,"</ul>","</ul>\n") txt$=REPLACE$(txt$,"<ul ","\n<ul ") txt$=REPLACE$(txt$,"<li>","\n<li>") txt$=REPLACE$(txt$,"</li>","</li>\n") txt$=REPLACE$(txt$,"</tr>","</tr>\n") 'txt$=REPLACE$(txt$,"</dt>","</dt>\n"); txt$=REPLACE$(txt$,"<div>","\n<div>") txt$=REPLACE$(txt$,"</div>","</div>\n") txt$=REPLACE$(txt$,"<div ","\n<div\n") txt$=REPLACE$(txt$,"<p","\n<p") txt$=REPLACE$(txt$,"</table>","</table>\n") txt$=REPLACE$(txt$,"-->","<>")
SPLIT txt$ BY "\n" TO array2$ SIZE dimension
FOR x = 0 TO dimension-1
t$=array2$[x] '=== IF LEN(t$) THEN IF INSTR(t$,"<td") THEN
t$ = REPLACE$(t$,"<br>"," ") t$ = t$ & "\n" ELIF INSTR(t$,"<dt") THEN t$=REPLACE$(t$,"<br>"," ") ELSE t$=REPLACE$(t$,"<br>","\n ") END IF
FOR t = 1 TO LEN(t$)
ch$= MID$(t$,t,1) IF ch$ ="<" THEN cann=0 END IF
IF ch$ =">" THEN PRINT " "; cann=1 END IF
IF cann THEN
' PRINT ch$; resline$ = resline$ & ch$
END IF
NEXT ' From here convert each resline$ entities and so on ' looks like bacon got a CHOP problem resline$ = CHOP$(resline$) resline$ = REPLACE$(resline$,">"," ") resline$ = CHOP$(resline$,"\n",0) resline$ = CHOP$(resline$," ",0) PRINT resline$
resline$ = "" '=== END IF
NEXT
|
|
|
Post by vovchik on Feb 6, 2020 13:36:16 GMT 1
Dear Alex (and all), I will look at that now. Thanks. Bish (latest incarnation) now has a manual. A script in the archive will generate it, mostly using bish, and place it in the current directory. The script assumes bish is in the PATH. I quite like the little (and quick and dirty) weather function. With kind regards, vovchik UPDATED: Added the bitwise keyword - 6 Feb 2020. UPDATED: Added POSIX-like lcut and lgrep keywords - 8 Feb 2020. Attachments:bish-src.tar.gz (19.2 KB)
|
|
|
Post by bigbass on Feb 10, 2020 3:29:11 GMT 1
hello vovchik
Thanks for the updates of bish
we used a fltk terminal awhile back I was testing today and bish works with that fine
so if you want to give it a try here it is stand alone code
P.S I have bish in usr/bin
just to let you know we could easily mix it with fltk and keep it all light weight and simple or add it into a fltk GUI (it works there also )
this works in fltk GUI
'================================================== SUB DUMB_TERMIAL(Fl_Widget* dummy, void* ) '================================================== EXEC$("fltk-config --compile dumbterm.cxx") EXEC$("chmod a+x dumbterm") EXEC$("./dumbterm") END SUB
Joe
or just stand alone code compile and run with
fltk-config --compile dumbterm.cxx chmod a+x dumbterm ./dumbterm
#include <string.h> #include <stdio.h> #include <FL/Fl.H> #include <FL/Fl_Double_Window.H> #include <FL/Fl_Text_Editor.H> #ifdef _WIN32 #define popen _popen #define pclose _pclose #endif // // 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 // 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)); } }; int main() { Fl_Double_Window win(620,520,"Terminal Test"); MyTerminal edit(10,10,win.w()-20,win.h()-20); edit.append("Line one\nLine Two\nEnter a shell command: "); win.resizable(win); win.show(); return(Fl::run()); }
|
|
|
Post by alexfish on Feb 10, 2020 12:24:40 GMT 1
Hi Vovchik
RE: html-strip
Have re-installed BaCon Stable 3.8.1
Now getting required results, hence now in position to complete the html <tags> as regards formating and extraction of Links
I will be busy over next 2 weeks so hoping to post and update there-after.
BR Alex
|
|
|
Post by vovchik on Feb 12, 2020 17:09:36 GMT 1
Dear all,
I have placed the latest bish incarnation in the first post - and will do so in future. The latest has a few additional keywords (including BMI), and I found a way to generate an include file for bash with bish shortcuts, making the syntax in scripts a bit tidier (and more like BaCon itself). There is another script in the archive that generates a manual.
With kind regards, vovchik
|
|
|
Post by bigbass on Feb 13, 2020 6:10:52 GMT 1
hello vovchik
thanks for all the improvements!
having working snippets you can just copy and paste is a great way to demonstrate what the commands can do and inspire people to use the commands
the typical linux man pages are a big turn off a lot of talk and very few if no practical examples are ever given
------ P.S it gave me an excuse to play with m4 and convert your bish keywords using m4 the code is a modified tolower.m4 auto generated using your list of keywords
it may or may not be useful to you but it does work and is very fast and can be expanded easily (it follows what you were doing with mk_bishinc) there is a readme
Joe
|
|
|
Post by vovchik on Feb 13, 2020 23:03:08 GMT 1
Dear Joe, Thanks for that m4 example. It is certainly at least 5x faster than my bish-bash version. I haven't really done anything with m4, so maybe it's time to learn. With kind regards, vovchik
|
|
|
Post by bigbass on Feb 13, 2020 23:12:54 GMT 1
hello vovchik
really the thanks goes to you for your hard work on bish
I just wanted to play with the m4 and keywords and your project gave me a a reason to test some ideas here is a better version
there is still a lot that could be done with m4
the goal I want to make it that it translates bacon snippets to bish syntax it does remove the parenthesis but I need to figure out how ,in the read to just remove the commas but not globally I know I could do it with sed if forced to
Joe
|
|
|
Post by bigbass on Feb 14, 2020 18:21:09 GMT 1
Hello vovchik
I have a goal to help out by converting bacon demo code examples to bish compatible examples
and all done with m4 so I am just focusing on the bacon 2 bish syntax conversion only
It seems to be working correctly so far
lets say you have these real bacon examples
AMOUNT("a b c d \"e f\" g h i j") AMOUNT("Dog, Cat@@@Mouse ,Bird@@@123@@@456@@@789", "@@@") ASC("x") B64ENC("Encode me") CHANGE$("a b c d \"e f\" g h i j", 5, "OK") CHANGE$("a,b,c,d,e,f,g,h,i,j", 4, "123", ",")
after running bish.m4
you get automatically generated for you then we feed it into your bish program and get the results we expect
bish amount "a b c d \"e f\" g h i j" bish amount "Dog, Cat@@@Mouse ,Bird@@@123@@@456@@@789" "@@@" bish asc "x" bish b64enc "Encode me" bish change "a b c d \"e f\" g h i j" 5 "OK" bish change "a,b,c,d,e,f,g,h,i,j" 4 "123" ","
Joe
I just want to help out with the m4 part the end of the read me goes into a little detail
|
|
|
Post by vovchik on Feb 15, 2020 0:11:14 GMT 1
Dear Joe,
Thanks. I see what you are after. Once I learn m4, I will also try to be useful there. In the meantime, I have added a few more keywords to bish and updated the first post. I will try to produce a few more demos with bish, maybe revisions of some bash scripts I have been using to scrape info from websites, since string handling routines in bish will come in handy for many little jobs.
With kind regards, vovchik
|
|
|
Post by bigbass on Feb 15, 2020 7:36:06 GMT 1
hello vovchik first I want to say well done getting all those commands parsed that's a lot of patients I cant imagine doing all of those thats dedication P.S I finally have a working m4 file it does what I wanted it to do and that is to convert bacon code to bish syntax automatically bishm4-src-2-14-20.tar.gz (3.43 KB) I really like how easy it is to use bish once you get the hang of the syntax differences converting from bacon code I have a better understanding now of how to use bish and will be using a lot when I am in the terminal the help file really makes things clear and easy thanks I give you a two thumbs up rating as it is Joe
|
|
|
Post by vovchik on Feb 15, 2020 19:30:32 GMT 1
Dear Joe,
Thanks for the encouragement and testing. I have added a PRINT statement, which makes the bish.inc code look much more like bacon, and passwd, which shows asterisks as it grabs input...might be useful. The first post has the updates.
With kind regards, vovchik
|
|
|
Post by vovchik on Feb 16, 2020 23:19:16 GMT 1
Dear all,
Another update of bish in the first post. Added one or two keywords, including the convenience function UTF8_BLOCK, and fixed up a few help texts.
With kind regards, vovchik
|
|
|
Post by bigbass on Feb 17, 2020 2:35:27 GMT 1
Hello vovchik
you were having troubles with SETENVIRON I can see why its more complex from a child shell of the main app
I got this working (plugging it into your code) however it still may be useful for you getting some values seen inside the bash part of the shell
of course you have to make it fit your way with the syntax but that's the idea
Joe
PRAGMA INCLUDE <stdlib.h> PROTO setenv
CASE "setenviron" DECLARE selected TYPE STRING DECLARE ENV_VAR2 TYPE STRING selected = var$[2] & "=" & CHR$(34) & var$[3] & CHR$(34) PRINT "selected ",selected ENV_VAR2 = (char*)var$[2] setenv("ENV_VAR2",selected,1) PRINT cmd_result$ = EXEC$("echo $ENV_VAR2") PRINT "the real setenv " ,cmd_result$ CASE "sgn"
TERMINAL OUT
./bish setenviron "BISH" "v1" selected BISH="v1"
the real setenv BISH="v1"
BISH="v1"
|
|