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

#181 Post by big_bass »

Hey Peter (PjotAwake)

Yes, you were correct
I did have an old bin installed in another folder :?

Code: Select all

which bacon  

/usr/bin/bacon
rm /usr/bin/bacon

Code: Select all

 which bacon

/usr/sbin/bacon
rm /usr/sbin/bacon

Code: Select all

which bacon      

#

(here I re ran the auto installer again)

even the version test fooled me it detected the new version
but during compile time it used the other in /usr/sbin

all is fine it compiled correctly with only the new bin 8)

thanks for the quick response

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

#182 Post by big_bass »

Hey Peter (PjotAwake)
excellent !

I did a very simple hack to your app to down files on the server I am using
very quickly it was easy to edit your code
now I can make a bacon powered TXZ package updater 8) 8) 8)

after seeing what you did to get the files to download

1.)first I made a file called files.txt

#that contained this

hexedit-1.2.12-i486-3_SLXR.txz
TXZpackageMgmt-1-i486-4_SLXR.txz
xrefresh-1.0.2-i486-3_SLXR.txz




2.) I uploaded files.txt to the server I am using

# just for a quick test I selected some very small files
# to use to download


3.) edit fetch.bac the server location and the path to where you
have your packages or other stuff you want to download

website$ = "www.puppy2.org"

OPEN CONCAT$(website$, ":80") FOR NETWORK AS mynet

SEND CONCAT$("GET /slaxer/files.txt HTTP/1.1\r\nHost: ", website$, "\r\n\r\n") TO mynet


4.) change the name fetch-TXZ or any other name that you will remember what it does
5.) recompile the "new fetch bac "


thanks a million :D
Joe


was renamed fetch-TXZ.bac for a demo

Code: Select all

'
' original code  Small utility to get all BaCon programs over HTTP from the BaCon website
'
' Dec 2010 - PvE.

' Small utility to get TXZ packages for a test   over HTTP from a different  website and different content 
'-----------------------------------------------------------------------------------

OPTION COLLAPSE TRUE

website$ = "www.puppy2.org"

OPEN CONCAT$(website$, ":80") FOR NETWORK AS mynet

SEND CONCAT$("GET /slaxer/files.txt HTTP/1.1\r\nHost: ", website$, "\r\n\r\n") TO mynet

REPEAT
    RECEIVE dat$ FROM mynet
    IF LEN(dat$) > 0 THEN total$ = CONCAT$(total$, dat$)
UNTIL ISFALSE(WAIT(mynet, 500))

SPLIT MID$(total$, INSTR(total$, "\r\n\r\n")+4) BY NL$ TO file$ SIZE amount

FOR x = 0 TO amount-1
    PRINT "Fetching ", file$[x], "... ";
    SEND CONCAT$("GET /", file$[x], " HTTP/1.1\r\nHost: ", website$, "\r\n\r\n") TO mynet
    total$ = ""
    REPEAT
	RECEIVE dat$ FROM mynet
	IF LEN(dat$) > 0 THEN total$ = CONCAT$(total$, dat$)
    UNTIL ISFALSE(WAIT(mynet, 500))

    OPEN file$[x] FOR WRITING AS baconfile
	WRITELN MID$(total$, INSTR(total$, "\r\n\r\n")+4) TO baconfile
    CLOSE FILE baconfile
    PRINT "done."
NEXT

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

#183 Post by vovchik »

Dear Joe and Peter and fellow Puppians,

I think we have a nice community.:)

With kind regards,
vovchik
User avatar
PjotAwake
Posts: 34
Joined: Wed 03 Nov 2010, 20:58
Location: The Hague, The Netherlands
Contact:

#184 Post by PjotAwake »

Hi Joe,
I did a very simple hack to your app to down files on the server I am using very quickly it was easy to edit your code
Well done! That's exactly what BaCon is for - creating cunning utilities in a quick and easy manner :)

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

#185 Post by big_bass »

Hey Peter (PjotAwake)

this is a special request
is there an easy way to modify your code to read a config file
such as files.txt so that sending the file to the server is not needed as a pre step


in bash I use something like this
here is the list of files I want to download /root/slaxer_updater/files.txt
could that idea be converted to basic using your code to replace wget
the wget options arent needed

Code: Select all


MYURL="http://puppy2.org/slaxer/"


#where the packages are downloaded to 
cd  /root/slaxer_updater
for package in `cat /root/slaxer_updater/files.txt`
do   wget -c -N $MYURL$package
echo $package  
done

this will allow for a great
downloader for any website

just by editing the config file "files.txt" to what you need to download

much better faster than wget running in a shell

Joe
User avatar
PjotAwake
Posts: 34
Joined: Wed 03 Nov 2010, 20:58
Location: The Hague, The Netherlands
Contact:

#186 Post by PjotAwake »

There are more ways to do that, this is one of them:

Code: Select all

OPTION COLLAPSE TRUE

website$ = "www.yourwebsite.org"

OPEN "files.txt" FOR READING AS myconfig
	WHILE NOT(ENDFILE(myconfig))
		READLN dat$ FROM myconfig
		IF LEN(dat$) > 0 THEN total$ = CONCAT$(total$, " ", dat$)
	WEND
CLOSE FILE myconfig

SPLIT total$ BY " " TO file$ SIZE amount

OPEN CONCAT$(website$, ":80") FOR NETWORK AS mynet

FOR x = 0 TO amount-1
	PRINT "Fetching ", file$[x], "... ";
	SEND CONCAT$("GET /", file$[x], " HTTP/1.1\r\nHost: ", website$, "\r\n\r\n") TO mynet
	total$ = ""
	REPEAT
		RECEIVE dat$ FROM mynet
		IF LEN(dat$) > 0 THEN total$ = CONCAT$(total$, dat$)
	UNTIL ISFALSE(WAIT(mynet, 500))

	OPEN file$[x] FOR WRITING AS baconfile
		WRITELN MID$(total$, INSTR(total$, "\r\n\r\n")+4) TO baconfile
	CLOSE FILE baconfile
	PRINT "done."
NEXT

CLOSE NETWORK mynet
BR,
Peter
User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

bacon networking etc

#187 Post by vovchik »

Dear guys and gals,

Look at Peter's little program above. Tiny and useful. And BaCon has networking, so you can write your own wgets and little http or chat servers. And, when you look at the code, you understand everything. There is nothing abstruse or cryptic. I am happy that more and more of us are becoming interested. Incidentally, the latest HUG - 0.26 - has a nice/simple progress bar, which will help for long operations requiring progress info.

With kind regards,
vovchik
big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#188 Post by big_bass »

Hey Peter (PjotAwake)


EXCELLENT! :D
Exactly what I needed it to do 8) 8)

what I wanted to see the most is how the code translates
from bash to bacon for opening files and reading them line for line

for someone else that wants to try this
only edit two lines in bold text
the files.txt in my case I placed in /tmp

so I just edited the directory /tmp/files.txt
remember that files.txt is a list of things you want to download
it could be anything files,pictures,packages....

compiled the bin and also placed the bin in /tmp





website$ = "www.yourwebsite.org"

OPEN "files.txt" FOR READING AS myconfig

this is great when I started with computers Qbasic was the way
I used to think in basic and was able to do some good things
when I started with linux everything looked cryptic :lol:
but I had to learn it I stopped writing in Qbasic around 2000
there were some commands such as OUT that allowed direct access to the ports such as the parallel port
under MSDOS then everything moved to using dll and got more complex

I wrote code to control some stepper motors reading the keyboard as input a control interface circuit is needed to isolate the signals for high current devices but this type of control was possible in basic


I believe this is a great thing that a lot of good small fast code is written in basic that will be able to be compiled in linux
having a basic compiler for linux is very ,very needed

and the coding for many micro controllers is still in a form of basic


Thank you with your code example I will be busy for awhile :D
Joe
seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#189 Post by seaside »

big_bass wrote:Hey Peter (PjotAwake)
excellent !

I did a very simple hack to your app to down files on the server I am using
very quickly it was easy to edit your code
now I can make a bacon powered TXZ package updater 8) 8) 8)

after seeing what you did to get the files to download

1.)first I made a file called files.txt

#that contained this

hexedit-1.2.12-i486-3_SLXR.txz
TXZpackageMgmt-1-i486-4_SLXR.txz
xrefresh-1.0.2-i486-3_SLXR.txz




2.) I uploaded files.txt to the server I am using

# just for a quick test I selected some very small files
# to use to download


3.) edit fetch.bac the server location and the path to where you
have your packages or other stuff you want to download

website$ = "www.puppy2.org"

OPEN CONCAT$(website$, ":80") FOR NETWORK AS mynet

SEND CONCAT$("GET /slaxer/files.txt HTTP/1.1\r\nHost: ", website$, "\r\n\r\n") TO mynet


4.) change the name fetch-TXZ or any other name that you will remember what it does
5.) recompile the "new fetch bac "


thanks a million :D
Joe


was renamed fetch-TXZ.bac for a demo

Code: Select all

'
' original code  Small utility to get all BaCon programs over HTTP from the BaCon website
'
' Dec 2010 - PvE.

' Small utility to get TXZ packages for a test   over HTTP from a different  website and different content 
'-----------------------------------------------------------------------------------

OPTION COLLAPSE TRUE

website$ = "www.puppy2.org"

OPEN CONCAT$(website$, ":80") FOR NETWORK AS mynet

SEND CONCAT$("GET /slaxer/files.txt HTTP/1.1\r\nHost: ", website$, "\r\n\r\n") TO mynet

REPEAT
    RECEIVE dat$ FROM mynet
    IF LEN(dat$) > 0 THEN total$ = CONCAT$(total$, dat$)
UNTIL ISFALSE(WAIT(mynet, 500))

SPLIT MID$(total$, INSTR(total$, "\r\n\r\n")+4) BY NL$ TO file$ SIZE amount

FOR x = 0 TO amount-1
    PRINT "Fetching ", file$[x], "... ";
    SEND CONCAT$("GET /", file$[x], " HTTP/1.1\r\nHost: ", website$, "\r\n\r\n") TO mynet
    total$ = ""
    REPEAT
	RECEIVE dat$ FROM mynet
	IF LEN(dat$) > 0 THEN total$ = CONCAT$(total$, dat$)
    UNTIL ISFALSE(WAIT(mynet, 500))

    OPEN file$[x] FOR WRITING AS baconfile
	WRITELN MID$(total$, INSTR(total$, "\r\n\r\n")+4) TO baconfile
    CLOSE FILE baconfile
    PRINT "done."
NEXT

CLOSE NETWORK mynet
big_bass,

I was wondering how you did this.......

In trying to create a utility to download based on Peter's "fetch" program with mods for a local "files.txt" selection, I tried out the "http://www.puppy2.org/slaxer/" site and it didn't work.

The "http://www.puppy2.org/slaxer/" site (and many others) do not process an appended port. E.G "http://www.puppy2.org/slaxer/:80" produces a "Page not found" error.

If the port is left out of the BaCon OPEN website command, it errs.

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

#190 Post by vovchik »

Dear Joe and seaside,

It works for me. Please note that any TCP/IP communication needs a port, hence 80 for http. Joe's site is not http://www.puppy2.org/slaxer but just www.puppy2.org. That is what is needed by OPEN, and that works. The rest is the GET bit, with the file then fully specified.

With kind regards,
vovchik
seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#191 Post by seaside »

vovchik wrote:Dear Joe and seaside,

It works for me. Please note that any TCP/IP communication needs a port, hence 80 for http. Joe's site is not http://www.puppy2.org/slaxer but just www.puppy2.org. That is what is needed by OPEN, and that works. The rest is the GET bit, with the file then fully specified.

With kind regards,
vovchik
Thanks vovchik,

After all my compiled attempts had failed using the wrong URL, I moved to trying different URL combinations.

I then tested "www.puppy2.org:80" as well by browser and when it resolved to http://www.puppy2.org/eminima/", I thought since it wasn't the /slaxer directory it wouldn't work...

"The one test I didn't try" Yikes...

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

#192 Post by big_bass »

Hey seaside

*I had to play with the very first example a bit to understand what to change

I didnt want to duplicate Peter's second example he improved it again because it worked but
it would be better to show exactly what was changed for clarity only
to have a working example for a different website

thanks for trying it and posting the feedback
Joe


this is a pre step to generate the files.txt

Code: Select all

#!/bin/bash
# this is the config file it makes a plain txt file 
# what the program does is look for a list
# of files outside of the compiled bin
# this way you can edit a list of files 
# to download only what you want to download 
# and there is no need to upload anything to the server first 

# called files.txt 
# edit this file for other files to download 
# edit fetch-TXZ.bac to change the website and path to files 
# note  after you compile the bin place it in /tmp alongside the files.txt
# /slaxer is just a folder I use you can edit that name 

# this is just a test example 
cat << 'EOF' >/tmp/files.txt 
hexedit-1.2.12-i486-3_SLXR.txz
TXZpackageMgmt-1-i486-4_SLXR.txz
xrefresh-1.0.2-i486-3_SLXR.txz 

EOF



fetch-TXZ.bac

Code: Select all

'
' original code  Small utility to get all BaCon programs over HTTP from the BaCon website
'
' Dec 2010 - PvE.

' Small utility to get TXZ packages for a test   over HTTP from a different  website and different content
'-----------------------------------------------------------------------------------

OPTION COLLAPSE TRUE

website$ = "www.puppy2.org"

OPEN CONCAT$(website$, ":80") FOR NETWORK AS mynet

SEND CONCAT$("GET /slaxer/files.txt HTTP/1.1\r\nHost: ", website$, "\r\n\r\n") TO mynet

REPEAT
    RECEIVE dat$ FROM mynet
    IF LEN(dat$) > 0 THEN total$ = CONCAT$(total$, dat$)
UNTIL ISFALSE(WAIT(mynet, 500))

SPLIT MID$(total$, INSTR(total$, "\r\n\r\n")+4) BY NL$ TO file$ SIZE amount

FOR x = 0 TO amount-1
    PRINT "Fetching ", file$[x], "... ";
    SEND CONCAT$("GET /", file$[x], " HTTP/1.1\r\nHost: ", website$, "\r\n\r\n") TO mynet
    total$ = ""
    REPEAT
   RECEIVE dat$ FROM mynet
   IF LEN(dat$) > 0 THEN total$ = CONCAT$(total$, dat$)
    UNTIL ISFALSE(WAIT(mynet, 500))

    OPEN file$[x] FOR WRITING AS baconfile
   WRITELN MID$(total$, INSTR(total$, "\r\n\r\n")+4) TO baconfile
    CLOSE FILE baconfile
    PRINT "done."
NEXT

CLOSE NETWORK mynet 
Last edited by big_bass on Wed 28 Sep 2011, 15:03, edited 2 times in total.
seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#193 Post by seaside »

big_bass,

Thanks for the clarifications. I ran your code successfully with a change in the "path-to-the-website-file" here -

Code: Select all

SEND CONCAT$("GET /", file$[x], " HTTP/1.1\r\nHost: ", website$, "\r\n\r\n") TO mynet 
CHANGE TO

Code: Select all

SEND CONCAT$("GET /slaxer/", file$[x], " HTTP/1.1\r\nHost: ", website$, "\r\n\r\n") TO mynet
However, what was downloaded didn't equal the original files-
Below files as downloaded with BaCon

# ls -l *.txz
-rw-r--r-- 1 root root 11967 2010-12-05 15:35 hexedit-1.2.12-i486-3_SLXR.txz
-rw-r--r-- 1 root root 400 2010-12-05 15:35 TXZpackageMgmt-1-i486-4_SLXR.txz
-rw-r--r-- 1 root root 3448 2010-12-05 15:35 xrefresh-1.0.2-i486-3_SLXR.txz
#

Below files as they are downloaded with wget

ls -l *.txz
-rw-r--r-- 1 root root 24408 2010-12-05 15:38 hexedit-1.2.12-i486-3_SLXR.txz
-rw-r--r-- 1 root root 764 2010-12-05 15:41 TXZpackageMgmt-1-i486-4_SLXR.txz
-rw-r--r-- 1 root root 11492 2010-12-05 15:46 xrefresh-1.0.2-i486-3_SLXR.tx
I am totally perplexed ......

Any ideas.

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

#194 Post by big_bass »

I am totally perplexed ......
well, now I am partially perplexed too (since it did work with the bac download
it does work so its just a matter of pointing things correctly


there is an error that I didnt catch I will have some time tomorrow to
go though the steps again and see what is happening with the down load file

thanks for catching that
Joe
User avatar
piratesmack
Posts: 100
Joined: Wed 16 Sep 2009, 14:22

#195 Post by piratesmack »

Thank you Peter for BaCon and thank you Puppians for the examples you've posted.

I've created my first useful (to me at least :)) program in BaCon.
It generates a Slackware package description template for when I'm building Slackware packages.

Code: Select all

' slack-desc-template.bac

OPTION BASE 1

' Display usage:
SUB print_usage
  PRINT "Usage:", NL$, \
    "  ", arg$[1], " -p <program name> [-o <output file>]", NL$, NL$, \
    "If no output file is specified, then stdout is used."
  END
END SUB

prgnam$ = ""
outfile$ = ""

' Parse command line arguments:
SPLIT ARGUMENT$ BY " " TO arg$ SIZE dim

FOR i=1 TO dim
  SELECT arg$[i]
    CASE "-h";
    CASE "--help";
    CASE "-?"
      print_usage
    CASE "-p"
      IF dim > i THEN prgnam$ = arg$[i+1]
    CASE "-o"
      IF dim > i THEN outfile$ = arg$[i+1]
  END SELECT
NEXT

' If no program named specified:
IF EQUAL(prgnam$, "") THEN
  print_usage
END IF

header$ = CONCAT$("# HOW TO EDIT THIS FILE:", NL$, \
"# The \"handy ruler\" below makes it easier to edit a package description.  Line", NL$, \
"# up the first '|' above the ':' following the base package name, and the '|'", NL$, \
"# on the right side marks the last column you can put a character in.  You must", NL$, \
"# make exactly 11 lines for the formatting to be correct.  It's also", NL$, \
"# customary to leave one space after the ':' except on otherwise blank lines.", NL$, NL$)

' spaces to prepend to handy_ruler
FOR i=1 TO LEN(prgnam$)
  spaces$ = CONCAT$(spaces$, " ")
NEXT

handy_ruler$ = CONCAT$("|-----handy-ruler------------------------------------------------------|", NL$)

FOR i=1 TO 11
  IF i EQ 11 THEN
    ' avoid extra newline at the end of file:
    desc$ = CONCAT$(desc$, prgnam$, ":")
  ELSE
    desc$ = CONCAT$(desc$, prgnam$, ":", NL$)
  END IF
NEXT

' full slack-desc:
slack_desc$ = CONCAT$(header$, spaces$, handy_ruler$, desc$)

IF EQUAL(outfile$, "")  THEN
  ' write to stdout
  PRINT slack_desc$
ELSE
  ' write to outfile$
  OPEN outfile$ FOR WRITING AS outfile
    WRITELN slack_desc$ TO outfile
  CLOSE FILE outfile
  PRINT "slack-desc template written to '", outfile$, "'"
END IF
edit:
fixed a segfault caused by using the '-p' or '-o' switch without giving the program name or output file
Last edited by piratesmack on Mon 06 Dec 2010, 10:39, edited 2 times in total.
User avatar
PjotAwake
Posts: 34
Joined: Wed 03 Nov 2010, 20:58
Location: The Hague, The Netherlands
Contact:

#196 Post by PjotAwake »

@piratesmack: well done!

@big_bass & seaside: the reason why you have wrong filesizes now, is that you are downloading binary files. The original program was designed for ASCII text files.

So the question is: can we do binary downloads with BaCon as well? Fortunately, yes, we can. There is an example here which shows how it can be achieved.

As I don't want to spoil all the fun, I'll leave it up to you guys implementing it in the program above :)

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

#197 Post by big_bass »

Peter (PjotAwake)
As I don't want to spoil all the fun, I'll leave it up to you guys implementing it in the program above Smile
:D
thanks for another excellent working example !

by having a working example of what you need
it is a very valuable learning tool to see what is needed
to make it all happen
well this time you made it just to easy to do such a minor edit
of only the website and content that your example speaks for itself

but I cant contain my happiness to post that it works for txz packages too!!

note: it will download the files to your default download location that was set by your browser so look there for the package

*sfind is a patched slocate that I made a small Xdialog frontend for
when many searches are needed this is lightning fast the data base takes time to build but thereafter each new search is very fast

a very big thanks Peter
working examples and help are priceless
what a nice surprise to wake up to :D

Joe
'
' This program shows how to implement binary downloads over HTTP.
'
' Needs BaCon 1.0 build 18 or higher - September 2010, PvE - GPL.
'----------------------------------------------------------------------------------------

OPTION MEMSTREAM TRUE

TRAP LOCAL
' Define HTTP separator
CONST Separator$ = CONCAT$(CHR$(13), CHR$(10), CHR$(13), CHR$(10))

' This is the size of the memory buffer
CONST ChunkSize = 1024

' Website we're downloading from
website$ = "www.puppy2.org"
port$ = "80"

' The actual file to download
file$ = "sfind-3.1-i486-3_SLXR.txz"

' Reserve memory
area = MEMORY(ChunkSize)

' The area should be readable as memory stream because
' we need to strip off HTTP headers
OPEN area FOR MEMORY AS data$

' The file where the binary data will be written to
OPEN file$ FOR WRITING AS download

' Open network connection
OPEN CONCAT$(website$, ":", port$) FOR NETWORK AS mynet

' Send a HTTP GET
SEND CONCAT$("GET /slaxer/", file$, " HTTP/1.1\r\nHost: ", website$, Separator$) TO mynet

stripped = FALSE

' Get the binary content
REPEAT
' Print progress on sreen
PRINT ".";

' Receive binary data into memory buffer
RECEIVE area FROM mynet CHUNK ChunkSize SIZE amount

' Strip off HTTP header
IF NOT(stripped) THEN
x = INSTR(data$, Separator$)-1
IF x THEN
PUTBYTE area + x + LEN(Separator$) TO download SIZE amount-x-LEN(Separator$)
stripped = TRUE
END IF
' If stripped add binary data to file
ELSE
PUTBYTE area TO download SIZE amount
END IF

UNTIL ISFALSE(WAIT(mynet, 1000))

' Close all open handles
CLOSE NETWORK mynet
CLOSE FILE download
CLOSE MEMORY data$

' Finished!
PRINT "Downloading '", file$, "' done!"


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

#198 Post by big_bass »

Hey piratesmack

excellent Job writing that in bacon!
it is very useful to see what was needed
thanks for posting your code

*I wrote a bash DragNdrop script I use all the time to make the slackware
slack-desc and the install folder here below lets get that
all done in bacon too (the dragNdrop part I have no clue
how to do that since it uses the power of ROX as the input )
so thats an extra feature


Code: Select all

#!/bin/bash 
# Joe Arose aka..big_bass
# call it dnd-slack-desc-maker
# dragNdrop a *tar.gz ,*tgz , or whatever it gets cut off anyway 
# or even better a folder with a version number that way
# the install folder is auto made
# make a blank slack-desc
# it opens in leafpad to add info 
# make a new file with time stamp 

# strip off the path 
basename "$@" >/root/nameofpackage

mkdir -p  "$@"/install


# filter the name by removing the version numbers 
# since this is a drag  N drop you may need to edit the field cut

# this cuts off everything after the first  "-"   cut -f 1 -d '-'` 
# this cuts off everything after the second "-"   cut -f 1,2 -d '-'` 
#

PKGNAME=`grep '-' /root/nameofpackage| cut -f 1 -d '-'` 

# clean up old files 
rm /root/nameofpackage



CHAR=`echo "$PKGNAME" | wc -c | sed s/^\ *//`
echo $CHAR
COUNTER="1"

cat << COMMENT > /root/slack-desc
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.  Line
# up the first '|' above the ':' following the base package name, and the '|' on
# the right side marks the last column you can put a character in.  You must make
# exactly 11 lines for the formatting to be correct.  It's also customary to
# leave one space after the ':'.

COMMENT
while [ $COUNTER -lt $CHAR ]; do
  echo -n " " >> /root/slack-desc
  COUNTER=`expr $COUNTER + 1`
done

echo "|-----handy-ruler------------------------------------------------------|" >>/root/slack-desc
echo "$PKGNAME: $PKGNAME 
$PKGNAME:
$PKGNAME:
$PKGNAME:
$PKGNAME:
$PKGNAME:
$PKGNAME:
$PKGNAME:
$PKGNAME: Package created for TXZ_pup
$PKGNAME:
$PKGNAME:">>/root/slack-desc


leafpad /root/slack-desc

cp /root/slack-desc  "$@"/install
User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

slack

#199 Post by vovchik »

Dear Joe and piratesmack,

Always nice to see some slack guys - I like it...

With kind regards,
vovchik
User avatar
piratesmack
Posts: 100
Joined: Wed 16 Sep 2009, 14:22

#200 Post by piratesmack »

Thanks, guys.

I got a question for you BaCon experts.
Is there any way to make function arguments optional?

For example, I'm trying to write a function that works like the Bash 'basename' command:

Code: Select all

' basename clone
FUNCTION BASENAME$(STRING file$, STRING ext$)
  LOCAL dim
  LOCAL ret$

  SPLIT file$ BY "/" TO array$ SIZE dim
  ret$ = array$[dim-1]

  ' Chop ext$ off the end of ret$
  IF NOT(EQUAL(ext$, "")) THEN ret$ = CHOP$(ret$, ext$, 2)

  RETURN ret$
END FUNCTION

' basename /home/steven/somefile.bac
PRINT BASENAME$("/home/steven/somefile.bac", "")

' basename /home/steven/somefile.bac .bac
PRINT BASENAME$("/home/steven/somefile.bac", ".bac")
It seems to work, but is there any way I can make the second argument, 'STRING ext$', optional? So I can just do 'BASENAME$("/some/file")'

Thanks
Post Reply