|
Post by vovchik on Jan 26, 2020 13:08:29 GMT 1
Dear all, I have long wished to be able to use BaCon functions easily in shell scripts. Unfortunately, compiling a little prog for one-off use is clumsy and time-consuming. I therefore though of making a little program that would make most BaCon commands available in the shell via direct and piped invocations. This is what I came up with: bish (BaCon In SHell). There are now 147 keywords available. Some commands - like html2text - still need work, but I think I have a starting point for a useful little utility. If you have mods or suggestions, please post them. With kind regards, vovchik PS. I am still implementing the self-contained help for individual commands, so most of the help output is incomplete, but you will get the idea. Run and inspect the script bishtest to get and idea about the syntax. UPDATE 12 FEB 2020: I will be placing bish updates here. 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. UPDATE 15 FEB 2020: Added a few keywords - including GETKEY, INPUT and EXEC. I can't seem to get SETENVIRON and CHANGEDIR to work, since bish is executed as a child process of a bash script and can't alter the environment of the parent process. Any idea whether this might be possible? UPDATE 15 FEB 2020 (evening): Another day, another update. Added PRINT, EPRINT and PASSWD, amongst some other things. UPDATE 16 FEB 2020 (evening): Added UTF8_BLOCK and fixed some help text. UPDATE 19 FEB 2020 (afternoon): Added CLIP_COPY and CLIP_PASTE. They rely on xsel or xclip. I tested using xsel. This is a poor man's version of IPC. UPDATE 21 FEB 2020 (afternoon): Added EXCERPT amd modified CLIP_COPY and CLIP_PASTE, eliminating dependencies (xsel/xclip). UPDATE 22 FEB 2020 (afternoon): ADDED UNITS, which provides convenient units of measure conversions. It is not yet complete, but you will get the idea. UPDATE 25 FEB 2020 (evening): Added ASCTAB, which generates, for reference purposes and convenience, an ASCII table of chars 32 to 126. UPDATE 26 FEB 2020 (afternoon): ADDED WC, which functions like LINUX/UNIX wc, just for convenience. UPDATE 27 FEB 2020 (afternoon): ADDED a few meteo functions: METEO_FEELSLIKE, METEO_HUMIDEX and METEO_WINDCHILL. UPDATE 28 FEB 2020 (evening): Fixed error in METEO_WINDCHILL calculation. UPDATE 6 MARCH 2020 (afternoon): Added PAD keywords, which prepends white space to strings. UPDATE 8 MARCH 2020 (morning): Added TIME_UTC keyword, which queries a NIST server and returns either the UTC time or date. UPDATE 8 MARCH 2020 (afternoon): Added COMP_NUM and COMP_STR keywords. They are useful in scripts for comparisons. For syntax, see 'bish help comp_num' and 'bish help comp_str'. The script (in the bish archive) alias-elif-comp shows a bit of usage. UPDATE 9 MARCH 2020 (evening): Fixed a bug in MID when arg3 was either 0 or missing. UPDATE 12 MARCH 2020 (afternoon): Added RM_EXTRA function/keyword. UPDATE 10 FJAN 2021: renamed internal MATCH function to avoid Peter's new native MATCH function (now in fossil beta). Attachments:bish-src.tar.gz (44.89 KB)
|
|
|
Post by Pjot on Jan 26, 2020 18:41:19 GMT 1
Thanks vovchik, Interesting concept! Compiles and runs fine on my 64-bit system. Some functions indeed come handy, like the delimited string functions. I sometimes wished they are available in shell, and now they are BR Peter
|
|
|
Post by bigbass on Jan 27, 2020 6:15:27 GMT 1
Hello vovchik I like it ! looking at things from another perspective having a linux shell that allows us to customize the functions and use bacon's functions as lower case text and remove the parenthesis is a nice way to test ideas and mix bacon with other bash commands I copied the bish executable to /usr/bin so we dont need the ./ prefix a lot of work went into doing bish congratulations! on a side note sometimes I use perl for the same reasons now I will have another great tool in the toolbox with bish thanks Joe P.S great to hear you got a raspi 4 and hope all is well with you !
|
|
|
Post by rikky on Jan 28, 2020 17:02:20 GMT 1
I'm sorry. Somehow I cannot get it to work. I'm using : BaCon version 4.0 on Linux armv7l - (c) Peter van Eerten - MIT License. some Fossil from about a weak ago. Or so I think, for I am messing around with new OS'es a lot. downloaded the bish.bac.tar.gz to some folder. unpacked it. bacon /home/pi/Downloads/New/bish.bac WARNING: 1 temporary files found! Do you want to delete them ([y]/n)? Ohw, that's nasty, that is the tar.gz package itself. Removed it. bacon /home/pi/Downloads/New/bish.bac Converting '/home/pi/Downloads/New/bish.bac'... done, 1169 lines were processed in 1.534 seconds. Analyzing dependencies... align amount append base64 between binary change chop chr concat count curdir cut datename dec delstr delimstr delimengine dirname error eval exchange explode extract filelen filetime filetype fill first flatten getenviron hasdelim hash head hex host hostname insert instring instrrev istoken last lcase left load malloc memcheck merge mid minmax os proper regex replace revstr reverse right rip rotate sortnr sortdelim sortstr spc str tab tail tally time token ucase uniq utf8 wait walk Warning: no FREE for the memory address 'cmd_result__b2c__string_var' at line 821 in file '/home/pi/Downloads/New/bish.bac'! Compiling '/home/pi/Downloads/New/bish.bac'... cc -c bish.bac.c Makefile.bacon:6: recipe for target 'bish.bac.o' failed
INFO: see full error report (y/[n])? y In file included from bish.bac.h:2:0, from bish.bac.c:2: bish.bac.generic.h:22:25: fatal error: openssl/ssl.h: No such file or directory #include <openssl/ssl.h> ^ compilation terminated. make: *** [bish.bac.o] Error 1
hmmm, ?? line 821 is: cmd_result$ = B64ENC$(BLOAD(var$[2]), FILELEN(var$[2]))
the 'no FREE for the memory address error' is like something I do not understand for this one. And openssl is installed. I don't know where, but It doesnt make sens to find it out, for there is no #include <openssl/ssl.h> In the whole program to be found. Rik.
|
|
|
Post by rikky on Jan 28, 2020 17:42:06 GMT 1
Cracked it I solved this kind of things before. I should have remembered. openssl was installed, ... but not openssl-dev. Now it compiles. I'll come back later to say what I think of it. Thanks. Rik.
|
|
|
Post by rikky on Jan 28, 2020 22:30:48 GMT 1
Well ja, it works a lot quicker then the bash 4 dummies script. For the compiling part is skipped. Personally I have made a lot of these bacon commands as stand alones, like RIGHT$ TOKEN$ etc BaCon doesn't compile RIGHT$. bac off course, for it stroempels over the $ in the name, but you can rename them afterwards. I don't know what is better. Anyway they seem to work, and are quick. Thanks. Rik.
|
|
|
Post by vovchik on Jan 28, 2020 23:19:23 GMT 1
Dear Rik,
Thanks for testing - also thanks to Peter and Joe. I am glad you got it working. It compiles fine on my RP4 with Buster and on Mint 19.2. Your "bash 4 dummies" was the inspiration, so thanks. I wanted a single binary in the end, not too large, that could handle all those commands, and it seems to be working. I am now trying to get all the help info incorporated, and have added a few more commands. I will post that once that work is done. If you have some routines that might give bish more useful functionality, please post them. It might be nice to have IIF, IIF$ and LOOP$ available, too, and some kind of xml, ini/conf and json parsing. I am just thinking out loud.
With kind regards, vovchik
|
|
|
Post by alexfish on Jan 29, 2020 21:15:54 GMT 1
Hi Vovchik
Interesting Idea
Hence thought about html2text
but came a cropper on the new bacon 4
theory tells me this should work
LOCAL txt$
txt$= BLOAD("index.html")
txt$= REPLACE$(txt$,"\n","") txt$= REPLACE$(txt$,"<","\n@") 'chop not working txt$=CHOP$(txt$) txt$=REPLACE$(txt$,">","\n") LOCAL dimension TYPE int SPLIT txt$ BY "/n" TO array$ SIZE dimension LOCAL x TYPE int LOCAL y TYPE int
FOR x = 0 TO dimension-1 'left$ not working IF ( LEFT$ (array$[x],1) == "@") THEN 'bug y=1 ELSE PRINT array$[x] END IF
NEXT
any ideas
+ once passed these bits need to look at converting Hex entities to DEC (ASCII)
BR Alex
|
|
|
Post by alexfish on Jan 29, 2020 22:06:57 GMT 1
Hi Vovchik
this is the original since above code was chopped about
LOCAL txt$
txt$= BLOAD("index.html")
txt$= REPLACE$(txt$,"\n","") txt$= REPLACE$(txt$,"<","\n@")
txt$=REPLACE$(txt$,">","\n") txt$ = CHOP$(txt$) LOCAL dimension TYPE int SPLIT txt$ BY "\n" TO array$ SIZE dimension LOCAL x TYPE int LOCAL y TYPE int
FOR x = 0 TO dimension-1 PRINT LEFT$(array$[x],1) IF ( LEFT$ (array$[x],1) = "@") THEN PRINT array$[x] END IF
NEXT
& to clarify
LOCAL txt$
txt$= BLOAD("index.html")
txt$= REPLACE$(txt$,"\n","") txt$= REPLACE$(txt$,"<","\n@")
txt$=REPLACE$(txt$,">","\n") txt$ = CHOP$(txt$) LOCAL dimension TYPE int SPLIT txt$ BY "\n" TO array$ SIZE dimension LOCAL x TYPE int LOCAL y TYPE int
FOR x = 0 TO dimension-1 PRINT LEFT$(array$[x],1) IF ( LEFT$ (array$[x],1) = "@") THEN
ELSE PRINT array$[x]
END IF NEXT
BR Alex
|
|
|
Post by bigbass on Feb 4, 2020 17:14:34 GMT 1
Hello Alex
I took some time to see what was happening with LEFT$
and tried many things until it's solved here using just "your code" your code looked good to me and in "C" I enclose in parenthesis when using "if" so to remove them was not natural for my thinking also ... but bacon doesn't need them
the enclosing parenthesis and LOAD$ was changed
hope that could be helpful
P.S I was parsing a lot of text to html (the other way around) yesterday and today and wanted to see what was happening with your code Joe
LOCAL txt$
txt$= LOAD$("index.html")
txt$= REPLACE$(txt$,"\n","") txt$= REPLACE$(txt$,"<","\n@")
txt$=REPLACE$(txt$,">","\n") txt$ = CHOP$(txt$) LOCAL dimension TYPE int SPLIT txt$ BY "\n" TO array$ SIZE dimension LOCAL x TYPE int LOCAL y TYPE int
FOR x = 0 TO dimension-1 PRINT LEFT$(array$[x],1) IF LEFT$ (array$[x],1) = "@" THEN PRINT array$[x] END IF
NEXT
|
|
|
Post by vovchik on Feb 4, 2020 18:16:31 GMT 1
Dear all, Here is a little update of bish. I have now done all the help, and you can see it by typing 'bish help keyword'. You get a list of keywords either by typing 'bish' alone or 'bish help'. A few keywords have been added, and I put Alex's html cleaner into html2text. Examples are provided for each keyword. A few 'non-native' functions still need some work...but I see light at the end of the tunnel. With kind regards, vovchik Attachments:bish-src.tar.gz (16.03 KB)
|
|
|
Post by bigbass on Feb 4, 2020 19:45:30 GMT 1
Hello vovchik
Very impressive work ! a big thanks for all your time spent doing the help that really puts the icing on the cake you gave us here on the forum
it is obvious you spent a lot of time to put it all together and a well deserved very big thank you
and congratulations for a great new and very useful tool from your old friend
Joe
just a test how its done using the help
./bish help replace
COMMAND: replace PURPOSE: Substitutes a substring needle (arg2) in haystack (arg1) with replacement (arg3) and returns the result. The replacement does not necessarily need to be of the same size as the substring. With the optional flag set to 1 the needle (arg2) should be taken as a regular expression. With the optional flag set to 2, replace will behave as a translate, meaning that the characters in needle (arg2) will be replaced by the successive characters in replacement (arg3). USAGE: replace string string string number ARGUMENT(S): 4 EXAMPLE: bish replace "Goodbye <all>" "<.*>" "123" 1
|
|
|
Post by alexfish on Feb 4, 2020 22:30:56 GMT 1
Hi Vovchik
although the html2text was a spin from earlier work and then switched to cpp and then used lib tidy
I now have a good cpp version working in about one 100 lines of code (no lib tidy) // not good at tables but output is very readable
and now in process of converting to Bacon. and possible looking at same amount of code
below output is from the fully functional text browser, and will look the same in BaCon.
BR Alex
enter quit to exit: or enter uri: http://basic-converter.proboards.com
host=basic-converter.proboards.com path=/ port=80 Continue y/n: y Connect : basic-converter.proboards.com http address size 4 Send : GET / HTTP/1.1 User-Agent: Mozilla/5.0 Cache-Control: no-cache Host: basic-converter.proboards.com:80 Connection: close
done [0] The BAsic CONverter Forum
[1] Skip Navigation [2] [3] Home [4] Help [5] Search [6] Goto the BaCon website Welcome Guest. Please [7] Login or [8] Register .
[9] The BAsic CONverter Forum
[10] Home
[11] General [12] News [13] Documentation [14] Code Projects [15] Troubleshooting area [16] Bugs, features
[17] General
Board Threads Posts Last Post [18] News
News and announcements Moderator: [19] Pjot 98 861 [20] Upcoming BaCon 4.0 by [21] Pjot [22] Jan 15, 2020 7:31:41 GMT 1
[23] Documentation - 1 Viewing
Tutorials & demonstrations Moderator: [24] Pjot 135 1,886 [25] Embedding external libraries - GTK demo by [26] bigbass [27] Jan 24, 2020 20:13:06 GMT 1
[28] Code Projects - 2 Viewing
Programs, challenges, competitions Moderator: [29] Pjot 211 4,475 [30] BaCon in Shell by [31] bigbass [32] Feb 4, 2020 19:45:30 GMT 1
[33] Troubleshooting area
Problems, issues, tips & tricks Moderator: [34] Pjot 402 2,935 [35] Easy way to squeeze chars from many to one ? by [36] pebau [37] Jan 24, 2020 15:48:53 GMT 1
[38] Bugs, features
Report a bug, request a feature Moderator: [39] Pjot 251 2,343 [40] DELETE RECURSIVE fails, if two times in a row. by [41] rikky [42] Jan 25, 2020 17:06:55 GMT 1
Legend
New Posts No New Posts
Forum Information & Statistics
Threads and Posts Total Threads: 1,097 Total Posts: 12,500
Last Updated: [43] BaCon in Shell by [44] bigbass ( [45] Feb 4, 2020 19:45:30 GMT 1 )
[46] Recent Threads - [47] Recent Posts - [48] RSS Feed
Members Total Members: 108
Newest Member: [49] rooftop
Most Users Online: 144 ( [50] Aug 22, 2013 23:04:29 GMT 1 )
[51] View today's birthdays
Users Online 0 Staff, 1 Member, 3 Guests.
[52] vovchik
Users Online in the Last 24 Hours 1 Staff, [53] 6 Members , 82 Guests.
[54] bigbass , [55] ptitjoz , [56] Pjot , [57] pebau , [58] rikky , [59] axelmoe
[60] Click here to remove banner ads from this forum.
This Forum Is Hosted For FREE By [61] ProBoards Get Your Own [62] Free Forum !
[63] Terms of Service | [64] Privacy | [65] Cookies | [66] FTC Disclosure | [67] Report Abuse | [68] Report Ad | [69] Consent
enter quit to exit: or enter uri:
|
|
|
Post by alexfish on Feb 4, 2020 22:37:20 GMT 1
Hi joe
yes there are some quirks to latest BaCon . but have found a work around and should have the bits working soon
Results from a lib free cpp is above, the parser as mentioned = Bacon version will look the same
BR Alex
|
|
|
Post by vovchik on Feb 4, 2020 22:40:18 GMT 1
Dear Joe and Alex, Thanks for the encouragement and kind words - and for testing. Alex, I see that your html stripper is very clean. I think we could replace my routine with yours in bish, and improve wget. For bish testing purposes, perhaps we could call yours, once it is ready, html_strip (HTML_STRIP$) before junking the existing html2text. I like it. With kind regards, your old friend vovchik
|
|