Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 24 Oct 2014, 04:59
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
BaCon - Bash-based Basic-to-C converter/compiler
Post new topic   Reply to topic View previous topic :: View next topic
Page 26 of 36 [526 Posts]   Goto page: Previous 1, 2, 3, ..., 24, 25, 26, 27, 28, ..., 34, 35, 36 Next
Author Message
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Sat 15 Oct 2011, 21:14    Post subject:  

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 Very Happy

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


Quote:


' *****************************************************
' 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:
# ./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]
bacon2bbc.bac.tar.gz
Description  Oct -17-2011 this is greatly improved thanks to GatorDog use this
gz

 Download 
Filename  bacon2bbc.bac.tar.gz 
Filesize  3.84 KB 
Downloaded  230 Time(s) 

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though

Last edited by big_bass on Fri 21 Oct 2011, 11:15; edited 4 times in total
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Sun 16 Oct 2011, 17:20    Post subject:  

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 Very Happy
BaCon keywords in blue
HUG keywords in green

Joe

Quote:
' 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

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Sun 16 Oct 2011, 17:35    Post subject:  

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...Smile

With thanks and kind regards,
vovchik
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Mon 17 Oct 2011, 10:37    Post subject:  

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]

Quote:
' 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

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though

Last edited by big_bass on Wed 19 Oct 2011, 09:28; edited 2 times in total
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5037
Location: Arizona, U.S.A.

PostPosted: Mon 17 Oct 2011, 11:56    Post subject:  

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.
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Mon 17 Oct 2011, 12:32    Post subject:  

Dear Joe,

Does this help:

Code:
SETENVIRON "BACONARGS", ARGUMENT$
myvar$ = EXEC$("set")
PRINT myvar$


With kind regards,
vovchik
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Mon 17 Oct 2011, 13:39    Post subject:  

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:
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 Very Happy
Code:
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:
SYSTEM CONCAT$("basename ", copy_this$ ,">" ," /tmp/basename-first-argument.txt")
SYSTEM CONCAT$("basename ", arg$[1] ,">" ," /tmp/basename-first-argument-using-arg1.txt")



Code:

'--- 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

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Wed 19 Oct 2011, 09:35    Post subject:  

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

Quote:

' 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 Cool
BACONARGS='./arg-find1 /root/bacon-examples/experaments/colorbbc3bac'

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Wed 19 Oct 2011, 10:30    Post subject:
Subject description: making graphic overlays with gtk/gdk libs
 

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
overlay.tar.gz
Description 
gz

 Download 
Filename  overlay.tar.gz 
Filesize  32.5 KB 
Downloaded  241 Time(s) 
image1.png
 Description   
 Filesize   12.17 KB
 Viewed   870 Time(s)

image1.png

image2.png
 Description   
 Filesize   6.81 KB
 Viewed   866 Time(s)

image2.png

new_img.png
 Description   
 Filesize   23.39 KB
 Viewed   892 Time(s)

new_img.png

Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Wed 19 Oct 2011, 11:42    Post subject:  

thanks! Any advantage over using mtPaint? (guess if you needed to script it...)
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Wed 19 Oct 2011, 12:53    Post subject:  

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 Smile And I learned something at the same time Smile

With kind regards,
vovchik
Back to top
View user's profile Send private message 
wjaguar

Joined: 21 Jun 2006
Posts: 282

PostPosted: Wed 19 Oct 2011, 14:52    Post subject:  

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. Wink So, thank you for demonstrating to me that yet another unholy perversion of PNG format does indeed exist in the wild Smile and providing a test example in the form of your "image2.png". I'll add support for such files in the next version.
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Wed 19 Oct 2011, 23:11    Post subject:  

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/viewtopic.php?search_id=1673665206&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

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Thu 20 Oct 2011, 01:57    Post subject:  

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. Wink So, thank you for demonstrating to me that yet another unholy perversion of PNG format does indeed exist in the wild Smile 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 Smile )
image3.png
 Description   Adding a little transparency
 Filesize   16.57 KB
 Viewed   868 Time(s)

image3.png

image4.png
 Description   
 Filesize   16.38 KB
 Viewed   790 Time(s)

image4.png

Back to top
View user's profile Send private message 
wjaguar

Joined: 21 Jun 2006
Posts: 282

PostPosted: Thu 20 Oct 2011, 02:50    Post subject:  

jpeps wrote:
I just dragged the two images onto the canvas and saved. (vovchik's looks better, though Smile )

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).
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 26 of 36 [526 Posts]   Goto page: Previous 1, 2, 3, ..., 24, 25, 26, 27, 28, ..., 34, 35, 36 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1449s ][ Queries: 12 (0.0093s) ][ GZIP on ]