BaCon - Bash-based Basic-to-C converter/compiler

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#376 Post by big_bass »

I have been trying to get a backend conversion tool (a binary I could call )for BaCon and HUG keyword highlighting bacon2bb thats bacon to phpBB code the format we use in this forum
and I finally got one in Bacon

why ? so we can post some "pretty" code examples here in the forum
since the code thingy we use here in the forum chops up the formatting and doesnt have color
I will expand this to bacon2html and other formats


I was able to get an Idea working in bash
but I really wanted to take a swing at doing it in BaCon

some background info
so this is my second Bacon code attempt
I looked over some of the official examples and some here in the forum
and made very minor edits to get a feel for what is taking place
and then went for it and it works :D

what takes place is all the bacon keywords get coded to be seen as blue
and all the HUG keywords get coded to be seen as green

imagine all the keywords in a file are searched
and replaced automatically so any GUI could call this binary now
I will be able to make a bacon2html or other formats to follow later

Joe


' *****************************************************
' PROGRAM: bacon2bbc.bac
' PURPOSE: convert Bacon and HUG keywords to phpBB code
' AUTHOR: big_bass Joe Arose + a big thanks to rod the GatorDog
' DEPENDS: gcc, bacon, replace
' PLATFORM: linux
' DATE: Oct 17-2011
' NOTES: you must have the replace package installed http://replace.richardlloyd.org.uk/
' LICENSE: GPL version 3 or later
' *****************************************************

' a big thanks to rod the GatorDog for giving me help and code snippets
' to improve , simply and correctly format the code for BaCon

' USUAGE: ./bacon2bbc /path-and-filename"

' note the file will get a -BBcode added to the filename

Code: Select all

# ./bacon2bbc /root/bacon-highlighting/hug.bac 
now look at the file all the phpBB code is there

when you post the code in the forum place it between the quote brackets instead that
allows for color to be used [/quote]
Attachments
bacon2bbc.bac.tar.gz
Oct -17-2011 this is greatly improved thanks to GatorDog use this
(3.84 KiB) Downloaded 394 times
Last edited by big_bass on Fri 21 Oct 2011, 15:15, edited 4 times in total.

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#377 Post by big_bass »

this is an output of code generated by using bacon2bbc in the above post
sometimes just seeing what it does is better than explaining what it does
so any code snippets you want to post can have color now :D
BaCon keywords in blue
HUG keywords in green

Joe
' Imports when HUG is used as shared object
CONST HUG_lib$ = "./hug.so"

' Setup error handling
TRAP LOCAL
CATCH GOTO hug_handle_error

' Import HUG functions
IMPORT "ATTACH(long,long,int,int)" FROM HUG_lib$ TYPE void
IMPORT "BUTTON(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "CALLBACK(long,void*)" FROM HUG_lib$ TYPE void
IMPORT "CALLBACKX(long,void*,long)" FROM HUG_lib$ TYPE void
IMPORT "CANVAS(int,int)" FROM HUG_lib$ TYPE long
IMPORT "CHECK(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "CIRCLE(char*,int,int,int,int,long)" FROM HUG_lib$ TYPE void
IMPORT "CLIPBOARD" FROM HUG_lib$ TYPE long
IMPORT "COMBO(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "DISABLE(long)" FROM HUG_lib$ TYPE void
IMPORT "DISPLAY" FROM HUG_lib$ TYPE void
IMPORT "EDIT(int,int)" FROM HUG_lib$ TYPE long
IMPORT "ENABLE(long)" FROM HUG_lib$ TYPE void
IMPORT "ENTRY(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "FILEDIALOG(char*,char*,int,int,int)" FROM HUG_lib$ TYPE long
IMPORT "FOCUS(long)" FROM HUG_lib$ TYPE void
IMPORT "FONT(long,char*)" FROM HUG_lib$ TYPE void
IMPORT "FRAME(int,int)" FROM HUG_lib$ TYPE long
IMPORT "GET(long)" FROM HUG_lib$ TYPE long
IMPORT "GRAB$(long)" FROM HUG_lib$ TYPE char*
IMPORT "HIDE(long)" FROM HUG_lib$ TYPE void
IMPORT "HSEPARATOR(int)" FROM HUG_lib$ TYPE long
IMPORT "HUGOPTIONS(char*)" FROM HUG_lib$ TYPE void
IMPORT "HUGLIB$(char*)" FROM HUG_lib$ TYPE char*
IMPORT "IMAGE(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "INIT" FROM HUG_lib$ TYPE void
IMPORT "KEY" FROM HUG_lib$ TYPE long
IMPORT "LINE(char*,int,int,int,int)" FROM HUG_lib$ TYPE void
IMPORT "LIST(int,int)" FROM HUG_lib$ TYPE long
IMPORT "MARK(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "METHOD(long,int,void*)" FROM HUG_lib$ TYPE void
IMPORT "MOUSE(long)" FROM HUG_lib$ TYPE long
IMPORT "MSGDIALOG(char*,int,int,int,int)" FROM HUG_lib$ TYPE long
IMPORT "NOTEBOOK(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "OUT(char*,char*,char*,int,int)" FROM HUG_lib$ TYPE void
IMPORT "PASSWORD(int,int)" FROM HUG_lib$ TYPE long
IMPORT "PICTURE(char*,int,int,int,int)" FROM HUG_lib$ TYPE void
IMPORT "PIXEL(char*,int,int)" FROM HUG_lib$ TYPE void
IMPORT "PROGRESSBAR(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "QUIT" FROM HUG_lib$ TYPE void
IMPORT "RADIO(char*,int,int,long)" FROM HUG_lib$ TYPE long
IMPORT "REGISTER(long,int,int,int,long,long,long,long)" FROM HUG_lib$ TYPE void
IMPORT "SCREENSIZE(int)" FROM HUG_lib$ TYPE int
IMPORT "SET(long,int)" FROM HUG_lib$ TYPE void
IMPORT "SHOW(long)" FROM HUG_lib$ TYPE void
IMPORT "SPIN(int,int,double,double,double)" FROM HUG_lib$ TYPE long
IMPORT "SQUARE(char*,int,int,int,int,int)" FROM HUG_lib$ TYPE void
IMPORT "STOCK(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "SYNC" FROM HUG_lib$ TYPE void
IMPORT "TEXT(long,char*)" FROM HUG_lib$ TYPE void
IMPORT "TIMEOUT(int,void*)" FROM HUG_lib$ TYPE void
IMPORT "TOGGLE(char*,int,int)" FROM HUG_lib$ TYPE long
IMPORT "UNFOCUS(long)" FROM HUG_lib$ TYPE void
IMPORT "VSEPARATOR(int)" FROM HUG_lib$ TYPE long
IMPORT "WINDOW(char*,int,int)" FROM HUG_lib$ TYPE long

' Define the PROPERTY directive
hug_Gobject$ = HUGLIB$("gobject")
IMPORT "g_object_set(long,char*,...)" FROM hug_Gobject$ TYPE void
PROTO PROPERTY
DEF FN PROPERTY(widget, name, ...) = g_object_set(widget, name, __VA_ARGS__, NULL)

' The dialog response codes
CONST GTK_RESPONSE_ACCEPT = -3
CONST GTK_RESPONSE_DELETE_EVENT = -4
CONST GTK_RESPONSE_OK = -5
CONST GTK_RESPONSE_CANCEL = -6
CONST GTK_RESPONSE_CLOSE = -7
CONST GTK_RESPONSE_YES = -8
CONST GTK_RESPONSE_NO = -9
CONST GTK_RESPONSE_APPLY = -10
CONST GTK_RESPONSE_HELP = -11

' All is well, finish
GOTO hug_import_finish

' Print error
LABEL hug_handle_error
PRINT ERR$(ERROR)
END

' Retsore default error handling
LABEL hug_import_finish
CATCH RESET
TRAP SYSTEM

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#378 Post by vovchik »

Dear Joe,

That looks great. And the text copies normally - i.e. none of the BB codes get copied when doing copy/paste and grabbing code snippets. I will really have to get used to using your little prog for posting examples...:)

With thanks and kind regards,
vovchik

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#379 Post by big_bass »

I have this test script and up to here it works I want to expand it but need help
I have a bash command that needs to see arg$[1]
' call this arg-find.bac

TRAP LOCAL
SPLIT ARGUMENT$ BY " " TO arg$ SIZE dim

'make a string name from the argument

'--- copy_this$ is the first argument passed from the command line ---
'--- arg$[1] this is a valid bacon argument now ---
'--- give it a string name for clarity ---
copy_this$ = arg$[1]


PRINT "string name is -->" ,"copy_this$" , " it contains this info ",copy_this$
PRINT "this is the name of the program ", arg$[0]
PRINT "this is the first argument " , arg$[1]
PRINT "this is the second argument " , arg$[2]





'--- now I want this bacon argument copy_this$ to be valid in a bash shell---
'--- so an extra step is needed to convert it using Cmd$ = CONCAT$---
'--- notice that we place in double quotes on bash commands and separate with commas---
'--- remember to allow pad spaces for command splitting---
'--- the conversion from bacon mindset to bash in bacon takes some time---
'--- so below is a simple example using copy---
'--- backup original file to tmp---
Cmd$ = CONCAT$("cp ", copy_this$, " /tmp")
Opt$ = EXEC$(Cmd$)

'--- BaCon has its own COPY command I used the above for an easy example only

'***************stuck here *****************************
now how do I get bash to read the value in the arguments
in this example


I know this is the wrong syntax but this is the idea I want to be able to get the arguments
to be seen in bash because I have a command that needs to see arg$[1]
SYSTEM ("echo copy_this$")

I also know this is the wrong syntax but
the actual command shortend is
SYSTEM (replace "this" "forthis" arg$[1])
or SYSTEM (replace "this" "forthis" copy_this$)

any help will be welcomed

Joe
Last edited by big_bass on Wed 19 Oct 2011, 13:28, edited 2 times in total.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#380 Post by sunburnt »

Hey Joe ( big_bass ); I`ve wondered how to pass a complete array to bash.

But passing just arg$[1] seems like it would work ( pass by value ).

# A... Probably the same way linux does many things, with files in /tmp

BaCon`s connection to other execs. is very thin and needs improving.
With it`s small command set, BaCon will rely heavily on external execs.
Basic and it`s command set`s very old, I hope Peter makes it more Pascalish.
Mainly it has glaring holes in it`s capability... Plug them up with new commands.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#381 Post by vovchik »

Dear Joe,

Does this help:

Code: Select all

SETENVIRON "BACONARGS", ARGUMENT$
myvar$ = EXEC$("set")
PRINT myvar$
With kind regards,
vovchik

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#382 Post by big_bass »

Thank you vovchick
I will try that
it will be useful

while I was writing for help to the forum GatorDog sent me many improvements /corrections
and the answer I was looking for . That I applied quickly and updated bacon2bbc in the above post
now the code is cleaner and saves the modified file to filename-BBcode
the original file is unedited so its safer to use

this is the thing I was looking for and works

Code: Select all

SYSTEM CONCAT$(" what to do in bash here , copy_this$ ")
*remember that copy_this$ = arg$[1]

a working simple example to get the first argument into bash as a file :D

Code: Select all

SYSTEM CONCAT$("echo ", copy_this$ ,">" ," /tmp/first-argument.txt")
that shows the argument that was in copy_this$
but is now a file that could be read :idea:
we can read strings from BaCon and send them out to be read in bash

notice: that if a file name wasnt given /tmp/first-argument.txt
and only /tmp was used the original file gets copied to /tmp
instead of just the path and filename "the argument"



note that Gator dog showed me already how to do this with 100% Bacon
but this is for those that would like to call some bash commands
from inside a BaCon program sometimes binaries do one job well
already and the syntax is well documented so it will be easier to understand
and use less lines of code


using a Bacon argument process it with bash and send the info to a file

'--- these two are the same you could used the copy_this$ or arg$[1]

Code: Select all

SYSTEM CONCAT$("basename ", copy_this$ ,">" ," /tmp/basename-first-argument.txt")
SYSTEM CONCAT$("basename ", arg$[1] ,">" ," /tmp/basename-first-argument-using-arg1.txt")

Code: Select all

'--- using bash commands to get basename to be read in BaCon
Cmd$ = CONCAT$(" basename "  , arg$[1])
Opt$ = EXEC$(Cmd$)

PRINT "********"
PRINT "basename of arg1 ", Opt$
PRINT "********"


Joe

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#383 Post by big_bass »

this is just a small snippet so as to focus on the code example vovchick posted above
which sends out the arguments how the BaCon app was run with and
make the all of the env available to BaCon !
I will just pull out the env string bash version for this example
a big thanks to vovchick

Joe
' call this arg-find1.bac
TRAP LOCAL
SPLIT ARGUMENT$ BY " " TO arg$ SIZE dim

'--- thanks to vovchick for this gem
'--- send out to env the arguments used to run the program
'--- make the env availabe to BaCon
PRINT "==============env====================================="
SETENVIRON "BACONARGS", ARGUMENT$
myvar$ = EXEC$("set")
PRINT myvar$
PRINT "==============end====================================="


'--- use one of the env strings from bash in BaCon
Cmd$ = CONCAT$("echo ", "$BASH_VERSION")
Opt$ = EXEC$(Cmd$)
PRINT "this is the bash version " , Opt$


and I have a new "EXPORT" BACONARGS in the env 8)
BACONARGS='./arg-find1 /root/bacon-examples/experaments/colorbbc3bac'

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#384 Post by vovchik »

Dear puppians,

Here is a little demo that shows how to do graphic overlays in BaCon, making direct use of gtk/gdk libs. With just a few additions - i.e. passed parameters, horizontal and vertical offests and a routine for canvas size - this can replace IM for overlay creation. Have a look. The source and two images are in the archive, as well as a lucid binary. The binary weighs in at 34k, which is better, I think, than 8+ MB for an unpacked IM (although IM is great for many, many things!).

With kind regards,
vovchik
Attachments
overlay.tar.gz
(32.5 KiB) Downloaded 450 times
image1.png
(12.17 KiB) Downloaded 963 times
image2.png
(6.81 KiB) Downloaded 966 times
new_img.png
(23.39 KiB) Downloaded 992 times

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#385 Post by jpeps »

thanks! Any advantage over using mtPaint? (guess if you needed to script it...)

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#386 Post by vovchik »

Dear jpeps,

I am certain that mtpaint can do that type of thing well - I just don't know how. It was really easier, for me at least, to program my own little routine for that particular job :) And I learned something at the same time :)

With kind regards,
vovchik

wjaguar
Posts: 359
Joined: Wed 21 Jun 2006, 14:16

#387 Post by wjaguar »

vovchik wrote:I am certain that mtpaint can do that type of thing well - I just don't know how.
In point of fact, it cannot - at the moment. ;-) So, thank you for demonstrating to me that yet another unholy perversion of PNG format does indeed exist in the wild :-) and providing a test example in the form of your "image2.png". I'll add support for such files in the next version.

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#388 Post by big_bass »

Hey vovchik

I know how long you have been trying to remove the imagemagick dependency in the backend
while using your overlay app pikonahttp://www.murga-linux.com/puppy/viewto ... 06&t=49129
congratulations on getting a test run example going with just BaCon and HUG
and no other dependencies
and at such a small size

Joe

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#389 Post by jpeps »

wjaguar wrote:
vovchik wrote:I am certain that mtpaint can do that type of thing well - I just don't know how.
In point of fact, it cannot - at the moment. ;-) So, thank you for demonstrating to me that yet another unholy perversion of PNG format does indeed exist in the wild :-) and providing a test example in the form of your "image2.png". I'll add support for such files in the next version.
I don't know much about mtPaint, but I just dragged the two images onto the canvas and saved. (vovchik's looks better, though :) )
Attachments
image3.png
Adding a little transparency
(16.57 KiB) Downloaded 962 times
image4.png
(16.38 KiB) Downloaded 878 times

wjaguar
Posts: 359
Joined: Wed 21 Jun 2006, 14:16

#390 Post by wjaguar »

jpeps wrote:I just dragged the two images onto the canvas and saved. (vovchik's looks better, though :) )
Precisely. And it is because mtPaint cannot properly read in "image2.png", which uses a palette with partial transparency (the first such image I've ever seen).

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#391 Post by vovchik »

Dear puppians,

@ Joe
getting a test run example going with just BaCon and HUG
Thanks. There is no HUG - just straight calls to gtk/gdk, which makes the code more efficient and smaller. The down side of ths approach is that it looks almost like C, but that's OK if it gets the job done.:) I think I am finally ready to modify Picona, since I already have routines worked out for scaling and overlay. It's now a matter of reviewing my old Picona code and making the changes. It will be a small, single binary in the end, which is what I am after, and will run on any Linux/Unix with GTK installed. I just have to sit down and do it.

@ jpeps
I just dragged the two images onto the canvas
In my demo, in creating the final image, the 3D image is not on top but on the bottom, and the clear orb is on top - the overlay. The reason that the 3D is visible is because of the alpha transparency in the orb. That's why it looks better - apart from the scaling issue. :) Moreover, the merged image canvas (background) in the new image is transparent. I am fairly certain that wjaguar will include this capability in a new version of mtpaint, so we just have to wait a bit.

With kind regards,
vovchik

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#392 Post by jpeps »

wjaguar wrote:
jpeps wrote:I just dragged the two images onto the canvas and saved. (vovchik's looks better, though :) )
Precisely. And it is because mtPaint cannot properly read in "image2.png", which uses a palette with partial transparency (the first such image I've ever seen).
Yeah, I cheated and filled in the hole with paint for image3 :)

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#393 Post by jpeps »

vovchik wrote: In my demo, in creating the final image, the 3D image is not on top but on the bottom, and the clear orb is on top - the overlay. The reason that the 3D is visible is because of the alpha transparency in the orb. That's why it looks better
Converted the image2.png to a jpg first so it was more workable.
Attachments
image5.png
(10.42 KiB) Downloaded 1210 times

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#394 Post by vovchik »

Dear jpeps,

The reason jpg images are never used for icons is because they, by design, have no transparency. The "object" in the centre will always be accompanied by a background of some sort and there will be some dithering with respect to colours. There is, moreover, no alpha channel. Using jpgs for icons is, on the whole, a non-starter unless you add a transparent background and then remove the existing colour around an object and save back in a format that recognizes transparency such as png. Xpm images do have transparency, but they are limited in the number of colours they can display. Mac OSX icns and M$ ico support transparency and millions of colours, too, but for *nix, the standard is png or svg (for vector graphics).

With kind regards,
vovchik

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#395 Post by jpeps »

Very interesting, vovchik. mtPaint isn't recognizing the transparency format, so maybe that's why the jpg format looked better...although it comes with a backround, as you noted. A gif transformation (which also supports an alpha channel) looked the same as png.

You can create the transparency with the "opacity" slider in the layers window (as I did in my post) , although the background is part of the object.

It looks like your experiment will lead to some mtPaint development by wjaguar. (wow...he doesn't miss anything! :) )

Post Reply