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
User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#511 Post by vovchik »

Dear Terry,

Since build 1.29 beta and also build 2.0, you can use "&" to concatenate strings. :) That was somebody's request and Peter obliged...

With kind regards,
vovchik

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

#512 Post by sunburnt »

New things all the time...!

It is a bit better and easier to use.

Thanks vovchik.

PaulR
Posts: 249
Joined: Wed 04 May 2005, 18:45
Location: UK

#513 Post by PaulR »

sunburnt wrote: # PaulR; If you reduce the "find" to /usr or whatever you`re looking for, it be quicker.

Also, I think you`ll find that shell scripts are much better at doing strings.
And you end up needed the shell to interface with the O.S. and file systems anyway.
.
Hehe, I realize both of those but the files I'm seeking could be anywhere. As it's probably a program that would only be run once speed isn't a major issue - if it was I'd probably be doing it straight in C (although that would take much longer to code as I'm well out of practice).

At some point I'm going to learn shell scripting but for now I'm still learning Linux and BaCon!

Thinking about it, I suspect there's another way to solve this problem anyway...

Cheers

Paul

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

#514 Post by sunburnt »

PaulR; Shell scripting is Linux for the most part.

I coded Visual Basic for years ( very much like Bacon ).
When I tried scripting it was daunting at first ( pipe chaining commands ).

But then I realized an entire paragraph of code is needed in Basic to do what 1 line does in Bash.!
And again, you are using shell code in Bacon`s EXEC$ and SYSTEM commands.

I`m writing a pre-processor for Bacon, and it`s a pain in Bacon.
All it does is rewrite the Bacon code so it`s ready to run "bacon" on.
So a shell script will do this very well. I`d prefer it be Bacon code, but...

PaulR
Posts: 249
Joined: Wed 04 May 2005, 18:45
Location: UK

#515 Post by PaulR »

I know, I'm happy enough with the command line I just can't deal with all the arcane stuff and new syntax for scripting atm (having recently learned a good chunk of php and Java/Processing for no particular reason!).

The idea I had earlier is a non-starter so I've checked all the default icon locations in .jwmrc and they are all under /usr so I'll limit the search as you suggested - it's faster and eliminates the searching or /proc at a stroke.

The problem I have with icons not displaying seems to be Fluxbox related - all the problem ones are .png - obviously Fluxbox only likes .xpm. Maybe I can convert these on the fly somehow....

Thanks again

Paul

EDIT: Seems that the png problem is because this version of fluxbox is compiled without suitable support for png's.

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#516 Post by seaside »

PaulR wrote:I Maybe I can convert these on the fly somehow....

.
Paul,

Here you go-

Code: Select all

 pngtopnm FILENAME.png >FILENAME.pnm
ppmtoxpm FILENAME.pnm >FILENAME.xpm 
Two steps - first convert .png file to .pnm file then .pnm to .xpm.
I think those commands are standard in Puppies.

Cheers,
s

EDIT: actually I think you could just pipe it straight through-

Code: Select all

 pngtopnm FILENAME.png | ppmtoxpm  >FILENAME.xpm

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

#517 Post by sunburnt »

Or... Use vovchik`s picscale.

It converts most pic. types to any of the other types.

PaulR
Posts: 249
Joined: Wed 04 May 2005, 18:45
Location: UK

#518 Post by PaulR »

I'm going to try compiling Fluxbox with png support - first problem, it requires imlib2 which doesn't appear to be on my system so far as I can see. So, a few questions... :D

- where should I obtain this library? It doesn't appear in package manager...
EDIT: I found the library and the source but neither archive contains the imlib2-config file that ./configure is calling for as far as I can see. Actually I'm not sure if I need the pre-compiled library or the source package :?


Everything else when running ./configure looks ok so once the imglib2 issue is fixed, if I go ahead and make/install will itoverwrite my existing Fluxbox or is it possible to install another version side by side?

Please excuse my Linux noobiness!

Cheers

Paul

User avatar
miriam
Posts: 373
Joined: Wed 06 Dec 2006, 23:46
Location: Queensland, Australia
Contact:

#519 Post by miriam »

Hi PaulR, I just stumbled on this page. You've probably solved your imlib2 problem by now, but just in case you haven't, the Linux From Scratch project has a page that links to the downloadable and gives more info on dependencies and so on.
http://www.linuxfromscratch.org/blfs/vi ... mlib2.html

Just one thing. The page's instructions on compiling don't really need to be so complex for Puppy. Just open a terminal in the folder of decompressed imlib2 contents.
./configure
make
make install


And it should be all done.

Cheers.
[color=blue]A life! Cool! Where can I download one of those from?[/color]

PaulR
Posts: 249
Joined: Wed 04 May 2005, 18:45
Location: UK

#520 Post by PaulR »

Cheers Miriam, I'm sorted but no doubt others will find that info very useful :)

Paul

User avatar
miriam
Posts: 373
Joined: Wed 06 Dec 2006, 23:46
Location: Queensland, Australia
Contact:

Linux From Scratch

#521 Post by miriam »

Actually, I need to remind myself to visit the Linux From Scratch project's pages more often, as it has so much useful info there. Basically it, and its sister projects, build versions of Linux totally from start (hence the name) and document the process in its entirety.

http://www.linuxfromscratch.org

Of course those Linux forms don't have the cool features of Puppy -- their Linux From Scratch LiveCD project is much more bloated (fills the CD) with less content and less features. However it does have the wonderful advantage of being almost completely documented. There is so much yummy information there...
[color=blue]A life! Cool! Where can I download one of those from?[/color]

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

Help needed

#522 Post by e_mattis »

Hey guys!

I'm having problems. I'm trying to take a file with some text strings and reading it in as an array. I need to be able to compare the array elements and create anew array of totally unique elements. the list i am using to learn how is as follows:

array[1] = "SP"
array[2] = "HP"
array[3] = "SP"
array[4] = "B-tip"
array[5] = "B-tip"

I need to create an array containing only the following:

array[1] = "SP"
array[2] = "HP"
array[3] = "B-tip"

I've been through the documentation and have some limited (last time I did things like this was over 30 years ago - before qbasic even :shock: ) programming experience. I think it used to be done in a double-loop (ie. For x = 1 to 5, for y = 1 to 5, etc) Of course that could just be for bubble loops...can't remember ...grrrr :x

I just can't seem to find a handle on it, so I turn to those more knowledgeable for assistance. Any help is appreciated!

Thanks!

E

.

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

#523 Post by sunburnt »

I just coded a solution for this.

It looks like you`re wanting to remove duplicate lines.
You don`t say what the delimiter is, I assume it`s NL$.

Read the file into a list and test it for dups. like this:

Code: Select all

OPEN File$ FOR READING AS file_
list$ = ""
WHILE NOT(ENDFILE(file_))
	READ line$ FROM file_
	IF ENDFILE(file_) THEN BREAK
	IF INSTR(list$, line$) > 0 THEN CONTINUE
	list$ = list$ & line$ & NL$
WHEN
CLOSE FILE file_

SPLIT list$ BY NL$ TO array$ SIZE Sz
This code ignores any duplicate lines and makes an array.

I know Bash`s "uniq" will do the same, but I assume BaCon code is wanted.
Enjoy dude..!
.
Last edited by sunburnt on Fri 17 May 2013, 21:01, edited 3 times in total.

User avatar
miriam
Posts: 373
Joined: Wed 06 Dec 2006, 23:46
Location: Queensland, Australia
Contact:

#524 Post by miriam »

If you have the text strings as lines in a file called list.txt, like

Code: Select all

dog
cat
tree
world
dog
tree
Then you can list the unique strings like this:

Code: Select all

sort list.txt | uniq >no_duplicates.txt
Then you can read the no_duplicates.txt file in using BaCon to do whatever else you want with it.

I don't know enough about BaCon to be able to give a fully BaCon solution, but it seems that if using the shell makes your task simpler it's worth using it.
[color=blue]A life! Cool! Where can I download one of those from?[/color]

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

#525 Post by vovchik »

Dear all,

If we take miriam's list as a basis:

Code: Select all

dog
cat
tree
world
dog
tree
we can do this little bit of processing:

Code: Select all

' ------------------
FUNCTION CAT(STRING FILENAME$)
' ------------------
	LOCAL fileline$, txt$ TYPE STRING
	IF FILEEXISTS(FILENAME$) THEN
		OPEN FILENAME$ FOR READING AS catfile
		WHILE NOT(ENDFILE(catfile)) DO
			READLN fileline$ FROM catfile
			txt$ = CONCAT$(txt$, fileline$, NL$)
		WEND
		CLOSE FILE catfile
	END IF
	RETURN CHOP$(txt$)
END FUNCTION

' ------------------
FUNCTION UNIQ$(STRING org$)
' ------------------
	' assumes OPTION BASE 0
	LOCAL i TYPE NUMBER
	LOCAL new$ TYPE STRING
	SPLIT org$ BY NL$ TO tmp$ SIZE elements
	SORT tmp$
	FOR i = 1 TO elements - 1
		IF tmp$[i] = tmp$[i - 1] THEN
			tmp$[i - 1] = " "
		END IF
	NEXT i
	SORT tmp$
	JOIN tmp$ BY NL$ TO new$ SIZE elements
	RETURN CHOP$(new$)
END FUNCTION
		
myoldlist$ = CAT("list.txt")
PRINT "Old list: ", NL$, myoldlist$
mynewlist$ = UNIQ$(myoldlist$)
PRINT "New list: ", NL$, mynewlist$
OPEN "newlist.txt" FOR WRITING AS newfile
WRITELN mynewlist$ TO newfile
CLOSE FILE newfile
The function CAT is there just there for convenience - to read the 'list.txt' file into a string variable. There are many ways of doing this, but this is one of them. Note that it doesn't take care of numerics well. You would have to check for a numeric type (probably using REGEX) and then prepend the requisite number of space pads before sorting - not hard.

With kind regards,
vovchik

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#526 Post by e_mattis »

Thanks guys!

Very kewl how it can be accomplished in a variety of ways! I appreciate the help very much! You guys ROCK! :D

E

.

Post Reply