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 May 2013, 16:50
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 18 of 36 [526 Posts]   Goto page: Previous 1, 2, 3, ..., 16, 17, 18, 19, 20, ..., 34, 35, 36 Next
Author Message
vovchik


Joined: 23 Oct 2006
Posts: 1231
Location: Ukraine

PostPosted: Mon 13 Dec 2010, 07:58    Post subject: giftalk  

Dear Puppians,

If you are trying to learn how to use BaCon and HUG, please have a look. This is my redaction of the BB dancing letters program which produces HTML and saves it to disk. What I am trying to demonstrate is how totally structured BaCon programming can be. It is easy, if you do it this way, to return to your source after a year's time and still understand it, and anybody looking at it will also understand. The archive contains a binary and the source. Please use the latest HUG.

With kind regards,
vovchik

Code:
' *****************************************************
' PROGRAM:   giftalk.bac
' PURPOSE:   to show dancing letters
' AUTHOR:      Piratesmack (Puppy Linux forum)
' MODDED:      vovchik (Puppy Linux forum) for html
' DEPENDS:   gcc, bacon, bash
' PLATFORM:   Puppy Linux (actually, any *nix)
' DATE:      11-12-2010
' *****************************************************

' *********************
' CONSTANTS
' *********************

SETENVIRON "LANG", "C"
CONST url$ = "http://somuchdamage.com/stuff/dancingletters/"
CONST c1$ = "small"
CONST c2$ = "large"
CONST c3$ = "rainbow"

' *********************
' END CONSTANTS
' *********************


' *********************
' DECLARATIONS
' *********************

GLOBAL dancing_html$, text_type$ TYPE STRING

' *********************
' END DECLARATIONS
' *********************


' *********************
' INCLUDES
' *********************

INCLUDE "hug.bac"

' *********************
' END INCLUDES
' *********************


' *********************
' SUBS & FUNCTIONS
' *********************

' ----------------
SUB COMBO_RESULT()
' ----------------
   ' set letter size/style from combo choice
   text_type$ = COMBO_GRAB$(mycombo)
END SUB

' ----------------
SUB GENERATE()
' ----------------
   ' generate html code for dancing letters - still a bit messy
   LOCAL q$, text$, text_new$, char$, dletter$, h1$, h2$, h3$, h4$
   LOCAL len, i
   q$ = CHR$(34)
   h1$ = "<html>"
   h2$ = "</html>"
   h3$ =  CONCAT$(".gif", q$, "/>", NL$)
   h4$ = "<img src="
   dancing_html$ = ""
   ' grab text from edit box 1
   text$ = GRAB$(edit1)
   ' chop, make uppercase, and replace "?" with "q"
   text_new$ = REPLACE$(CHOP$(UCASE$(text$)), "?", "q")
   text_new$ = REPLACE$(text_new$, " ", "|")
   len = LEN(text_new$)
   ' translate each character to dancing letter
   FOR i = 1 TO len
      char$ = MID$(text_new$, i, 1)
      IF REGEX(char$, "[A-Z]") THEN
         dletter$ = CONCAT$(h4$, q$, url$, text_type$, "/", char$, h3$)
      ELIF REGEX(char$, "[0-9!$&@q]") THEN
         IF EQUAL(text_type$, "rainbow") THEN
            dletter$ = CONCAT$(h4$, q$, url$, text_type$, "/", char$, h3$)
         ELSE
            dletter$ = CONCAT$(h4$, q$, url$, "punctuation/", char$, h3$)
         END IF
      ELSE
         dletter$ = char$
      END IF
      IF EQUAL(char$, "|") THEN
         dletter$ = CONCAT$("<br>", NL$)
      END IF
      dancing_text$ = CONCAT$(dancing_text$, dletter$)
   NEXT i
   ' clear edit box 2
   TEXT(edit2, "")
   ' put dancing letter html in edit box 2
   dancing_text$ = CONCAT$(h1$, NL$, dancing_text$, h2$)
   dancing_html$ = dancing_text$
   TEXT(edit2, dancing_text$)
   dancing_text$ = ""
END SUB

' ----------------
SUB CLEAR()
' ----------------
   ' clear edit boxes
   TEXT(edit1, "")
   TEXT(edit2, "")
   dancing_html$ = ""
END SUB

' ----------------
SUB SAVEFILE()
' ----------------
   ' write html file to disk and clean up display boxes
   OPEN "dancing_letters.html" FOR WRITING AS myfile
   WRITELN dancing_html$ TO myfile
   CLOSE FILE myfile
   TEXT(edit1, "")
   TEXT(edit2, "")
END SUB

' ----------------
SUB CREATE_WIDGETS()
' ----------------
   ' define all the widgets we need and widget sizes (x-y stuff)
   window = WINDOW("HTML Dancing letter generator", 500, 400)
   frame1 = FRAME(500-15, 155)
   frame2 = FRAME(500-15, 155)
   edit1 = EDIT(500-25, 130)
   edit2 = EDIT(500-25, 130)
   ' define frame annotations
   TEXT(frame1, " Enter some text: ")
   TEXT(frame2, " HTML code: ")
   ' define buttons, using gtk stock icons
   button1 = STOCK("gtk-execute", 90, 30)
   button2 = STOCK("gtk-clear", 70, 30)
   button3 = STOCK("gtk-save", 70, 30)
   ' define a text label
   mylabel = MARK("Letter style:", 90, 30)
   ' define combo box, using CONST strings defined earlier
   mycombo = COMBO(c1$, 100, 30)
   COMBO_TEXT(mycombo, c2$)
   COMBO_TEXT(mycombo, c3$)
END SUB

' ----------------
SUB ATTACH_WIDGETS()
' ----------------
   ' attach all the widgets to the main window (x-y stuff)
   ATTACH(window, frame1, 10, 10)
   ATTACH(window, frame2, 10, 180)
   ATTACH(window, edit1, 15, 30)
   ATTACH(window, edit2, 15, 200)
   ATTACH(window, button1, 245, 353)
   ATTACH(window, button2, 345, 353)
   ATTACH(window, button3, 425, 353)
   ATTACH(window, mylabel, 10, 353)
   ATTACH(window, mycombo, 105, 353)
END SUB

' ----------------
SUB CREATE_CALLBACKS()
' ----------------
   ' create widget actions
   CALLBACK(button1, GENERATE)
   CALLBACK(button2, CLEAR)
   CALLBACK(button3, SAVEFILE)
   CALLBACK(mycombo, COMBO_RESULT)
END SUB

' *********************
' END SUBS & FUNCTIONS
' *********************


' *********************
' MAIN
' *********************

' set default letter size
text_type$ = "small"
' call sub to define all the widgets
CREATE_WIDGETS
' call sub to attach them to the main window
ATTACH_WIDGETS
' call sub to define actions for widgets
CREATE_CALLBACKS
' show gui - and away we go!
DISPLAY

' *********************
' END MAIN
' *********************
giftalk-0.1a.tar.gz
Description 
gz

 Download 
Filename  giftalk-0.1a.tar.gz 
Filesize  28.43 KB 
Downloaded  246 Time(s) 
giftalk.jpg
 Description   
 Filesize   52.65 KB
 Viewed   1623 Time(s)

giftalk.jpg

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


Joined: 13 Aug 2007
Posts: 1736

PostPosted: Mon 13 Dec 2010, 11:08    Post subject:  

Hey vovchik

excellent !

and thanks for adding a save file option

and yes I agree with you about readability 100%

while its still fresh in my mind I just added some more comment
suggestions to your already very nicely commented code with the only goal
of the code being educational for those tying to follow
the code (myself being one of them that will probably forget
so I want to document the steps )

thanks
Joe

Quote:
' generate html code for dancing letters - still a bit messy
' local values are used here so that they only apply
' to this program without exporting these values


LOCAL q$, text$, text_new$, char$, dletter$, h1$, h2$, h3$, h4$
LOCAL len, i

' is a quote symbol made into a string
q$ = CHR$(34)

' h1 is the header for html
h1$ = "<html>"

' h2 is the close of the html header
h2$ = "</html>"

' add to the right side of .gif the "/> and a new line
h3$ = CONCAT$(".gif", q$, "/>", NL$)

' prefix the code to the far left
h4$ = "<img src="

' preset this value to nothing to clear it
dancing_html$ = ""

' grab text from edit box 1
text$ = GRAB$(edit1)

' chop, make uppercase, and replace "?" with "q"
text_new$ = REPLACE$(CHOP$(UCASE$(text$)), "?", "q")

' if your text input has a space it gets converted to a "|"
text_new$ = REPLACE$(text_new$, " ", "|")

' get the string length of the input text
len = LEN(text_new$)






Quote:

' check for spaces in the input text if found
' a <br> line break command is used instead of the "|" symbol

IF EQUAL(char$, "|") THEN
dletter$ = CONCAT$("<br>", NL$)
END IF
dancing_text$ = CONCAT$(dancing_text$, dletter$)

_________________
slackware 14
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1231
Location: Ukraine

PostPosted: Mon 13 Dec 2010, 13:12    Post subject: documented code  

Dear Joe,

Thanks. I, too, am a believer in well documented code - because, as we get older, our memories go to hell and/or others can pick up on something that we might have written. And code should not be obscure. I can truly understand why some stuff is not really annotated - and I am guilty of this myself (many other things to do at the very same time) - but I find annotated code much easier to work with, no matter what language. And it is also good programming practice. Good and simple structure also helps...Smile

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


Joined: 03 Nov 2010
Posts: 34
Location: The Hague, The Netherlands

PostPosted: Tue 14 Dec 2010, 14:19    Post subject:  

Hi seaside,

So I am back Smile

It took quite some time to analyze this issue. It appears that Puppy Linux 4.2.1 and probably other Puppy versions use the Xft.dpi = 78 as a default. That means that the whole desktop including all individual applications are optimized for for this DPI setting. Nowadays a lot of Linux distributions use a Xft.dpi of 96 which also is assumed by GTK.

So now for the problem: though it is possible to find out the current Xft.dpi setting, there is no way to see for which Xft.dpi setting the desktop was optimized. (This Xft.dpi for which the desktop was optimized I will refer to as base Xft.dpi.)

So the base Xft.dpi cannot be determined. Therefore, I have introduced a new option in HUGOPTIONS. For your HUG programs in Puppy, first use HUGOPTIONS("BASEXFTDPI 78") and then start designing your GUI. Example program:

Code:

HUGOPTIONS("BASEXFTDPI 78")

' Create the GUI
mainwin = WINDOW("My program", 500, 400)

frame = FRAME(490, 340)
ATTACH (mainwin, frame, 5, 5)
canvas = CANVAS(480, 330)
ATTACH (mainwin, canvas, 10, 10)
<...more code...>


So if you change your Puppy desktopfont to 96 or 108, with this new option the GUI always should show correctly.

Can you please try the latest HUG and add the line 'HUGOPTIONS("BASEXFTDPI 78")' at the beginning of the 'proxy' program?

Then if you switch the Xft.dpi from 78 to 108 or any other value the GUI should show correctly.

Thanks,
Peter
Back to top
View user's profile Send private message Visit poster's website 
ICQ Number 
vovchik


Joined: 23 Oct 2006
Posts: 1231
Location: Ukraine

PostPosted: Tue 14 Dec 2010, 15:07    Post subject: dpi option  

Dear Peter,

As usual, very clever. I will try this out and report back...

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

Joined: 31 May 2008
Posts: 2421

PostPosted: Tue 14 Dec 2010, 16:33    Post subject:  

PjotAwake wrote:


Can you please try the latest HUG and add the line 'HUGOPTIONS("BASEXFTDPI 78")' at the beginning of the 'proxy' program?

Then if you switch the Xft.dpi from 78 to 108 or any other value the GUI should show correctly.

Thanks,
Peter


works...
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1231
Location: Ukraine

PostPosted: Tue 14 Dec 2010, 16:50    Post subject: HUG etc  

Dear Puppians,

Peter is trying to accommodate every whimsy and, sometimes, silly request, but he does it. I think we should all say THANKS AND HATS OFF!. He is a wonderful logician.

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

Joined: 11 Apr 2007
Posts: 836

PostPosted: Wed 15 Dec 2010, 10:41    Post subject:
Subject description: font dpi
 

Peter,

I just had to grab a moment to go on-line to tell you how much we appreciate your help in sorting out these tricky issues.

Regards,
s
NOTE: (Still in the midst of moving but couldn't resist - much to my wife's annoyance - I tried out your new HUG with everything from 54-108 and it worked nicely with all Smile )
Back to top
View user's profile Send private message 
PjotAwake


Joined: 03 Nov 2010
Posts: 34
Location: The Hague, The Netherlands

PostPosted: Wed 15 Dec 2010, 16:50    Post subject:  

Quote:

I tried out your new HUG with everything from 54-108 and it worked nicely with all Smile


Great! Thanks for letting know. I will upload this version as the new default.

Regards
Peter
Back to top
View user's profile Send private message Visit poster's website 
ICQ Number 
piratesmack


Joined: 16 Sep 2009
Posts: 100

PostPosted: Thu 16 Dec 2010, 06:09    Post subject:  

Great stuff, Peter.

In such a short amount of time, I have already gotten further with BASIC and BaCon than I have ever gotten with the other languages I've tried.

Thanks a lot, keep up the good work! Smile
Back to top
View user's profile Send private message 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 6866
Location: Perth, Western Australia

PostPosted: Thu 16 Dec 2010, 20:25    Post subject:  

As BaCon is continually improving, I put some code into Woof to automatically build a Puppy with the latest BaCon files. Also the bacon.bac from beta is downloaded and compiled. It will all go into the devx sfs:

http://bkhome.org/blog/?viewDetailed=02032

This is the code I put into the '3builddistro' script:
Code:
#101217 get latest BaCon...
if [ -f support/fetch ];then #see http://www.basic-converter.org/fetch.bac
 if [ "`which bacon`" != "" ];then
  echo
  echo "Press ENTER key only to download latest BaCon BASIC compiler and support files."
  echo "You will need Internet access to do this."
  echo -n "ENTER to download, any other char not to: "
  read dobacon
  if [ "`$dobacon`" = "" ];then
   mkdir -p sandbox3/devx/usr/share/BaCon
   rm -f sandbox3/devx/usr/share/BaCon/* 2>/dev/null
   cp support/fetch sandbox3/devx/usr/share/BaCon/
   cd sandbox3/devx/usr/share/BaCon
   ./fetch
   sync
   wget http://www.basic-converter.org/documentation.pdf
   wget http://www.basic-converter.org/documentation.html
   wget http://www.basic-converter.org/hug.txt
   wget http://www.basic-converter.org/sqlite3.txt
   wget http://www.basic-converter.org/gmp.txt
   wget http://www.basic-converter.org/curses.txt
   wget http://www.basic-converter.org/pthreads.txt
   wget http://www.basic-converter.org/gd.txt
   wget http://www.basic-converter.org/gtk.txt
   wget http://www.basic-converter.org/gl.txt
   #fetch has already downloaded bacon.bac, but want beta version...
   mv -f bacon.bac bacon-released.bac
   wget http://www.basic-converter.org/beta/bacon.bac
   [ $? -ne 0 ] && mv -f bacon-released.bac bacon.bac
   mv -f documentation.html documentation-released.html
   wget http://www.basic-converter.org/beta/documentation.html
   [ $? -ne 0 ] && mv -f documentation-released.html documentation.html
   sync
   if [ -f bacon.bac ];then
    bacon bacon.bac
    sync
    cp -f -a bacon ../../bin/
   fi
   echo "...done"
   cd ../../../../../ #back to woof-tree project dir.
  fi
 else
  echo
  echo "WARNING: 'devx' SFS not loaded, cannot install latest BaCon BASIC compiler."
 fi
fi


But, the thought has just occurred to me, why not have a script in Puppy, say /usr/bin/bacon-upgrade, that does all of the above, so you can upgrade whenever you want?

_________________
http://bkhome.org/blog2/
Back to top
View user's profile Send private message Visit poster's website 
big_bass


Joined: 13 Aug 2007
Posts: 1736

PostPosted: Sat 18 Dec 2010, 22:38    Post subject:  

Hey Peter (PjotAwake)

I want to add a big thanks for all your help

I got a "hack" going for geany syntax highlighting with BaCon!
of course you would have to complete it so it gets official status so it could be compiled in and maintained correctly (and having the correct name in the window)

well here´s what has to be done to get it going quickly

rename the original default file in the folder
/usr/share/geany/filetypes.freebasic to
/usr/share/geany/filetypes.freebasic-old
as a safety

then untar the attachment and install this in /usr/share/geany



then open geany with any *.bac and select
Document -->Set Filetype-->Programming Languages-->FreeBasic source file

and you get the BaCon commands highlighted !

*since FreeBasic was compiled in the GUI as an option I used that Confused
later when all the commands are added and tested Bacon would be used and compiled into geany the right way Very Happy


look at lines 27-28
what I did was take all the commands out of the bacon *language file and added them in manually removing the "free basic keywords"
----------------------------------------------------------------------------
EDIT to add click on file to open with the correct highlighting Cool

edit this file
/usr/share/geany/filetype_extensions.conf
and add FreeBasic=*.bas;*.bi;*.bac;


Joe
filetypes.freebasic.tar.gz
Description 
gz

 Download 
Filename  filetypes.freebasic.tar.gz 
Filesize  1.75 KB 
Downloaded  237 Time(s) 

_________________
slackware 14
Back to top
View user's profile Send private message 
Ted Dog


Joined: 13 Sep 2005
Posts: 987
Location: Heart of Texas

PostPosted: Wed 29 Dec 2010, 14:38    Post subject: Bacon BITS
Subject description: Bacon & TCC w/o dev.sfs
 

I've finally got a working system without dev.sys that runs bacon and tcc together. Only adds 1M to base .sfs by copied only needed includes from a working GCC to a TCC .
Its not cleaned up yet but I'm posting this if anyone else is interested in a super small Basic & C combo system. (need to relearn how to make a pet from files)

Tiny C Compiler does not have compatible includes but a subset of GCC does.

was able to recompile bacon.bas using this mini system
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 836

PostPosted: Thu 30 Dec 2010, 14:06    Post subject: Re: Bacon BITS
Subject description: Bacon & TCC w/o dev.sfs
 

Ted Dog wrote:
I've finally got a working system without dev.sys that runs bacon and tcc together. Only adds 1M to base .sfs by copied only needed includes from a working GCC to a TCC .
Its not cleaned up yet but I'm posting this if anyone else is interested in a super small Basic & C combo system. (need to relearn how to make a pet from files)

Tiny C Compiler does not have compatible includes but a subset of GCC does.

was able to recompile bacon.bas using this mini system


Ted Dog,

That would make a very nice and compact development package.

Cheers,
s
(You remember
Code:
# dir2pet abiword-0.5.6
where abiword-0.5.6 is a directory in the same directory
in which this terminal window is open. 'abiword-0.5.6' is
just an example, and contains subdirectories and files
that will become the PET package.
Very Happy
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1231
Location: Ukraine

PostPosted: Sat 01 Jan 2011, 05:20    Post subject: New bacon version  

Dear Puppians,

Happy New Year!. Peter has released bacon v.1.0 build 20 (www.basic-converter.org) and v. 0.30 of HUG. You can download the latest versions, plus documentation from his site. Have fun.

With kind regards,
vovchik
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 18 of 36 [526 Posts]   Goto page: Previous 1, 2, 3, ..., 16, 17, 18, 19, 20, ..., 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.1159s ][ Queries: 12 (0.0178s) ][ GZIP on ]