' *****************************************************
' PROGRAM:      beer99.bac
' PURPOSE:      http://99-bottles-of-beer.net   
' AUTHOR:               vovchik (Puppy Linux forum)     
' DEPENDS:      gcc, bacon, bash
' PLATFORM:     Puppy Linux (actually, any *nix)
' DATE:         15-11-2009
' COMMENTS:     Not very elegant - but it works
' *****************************************************

GLOBAL beer_bottles TYPE NUMBER
GLOBAL stock$, what$, where$, action TYPE STRING

' *********************
' SUBS
' *********************

' -------------
SUB init_vars()
' -------------
        beer_bottles = 100
        stock$ = "bottles"
        what$ = "of beer"
        where$ = "on the wall"
        action$ = "Take one down and pass it around, "
END SUB

' -------------
SUB check_beers()
' -------------
        SELECT beer_bottles
                CASE 0
                        stock$ = "No more bottles"
                        action$ = "Go to the store and buy some more, "
                        stock_depleted$ = CONCAT$(STR$(beer_bottles + 99)," ","bottles")
                CASE 1
                        stock$ = CONCAT$(STR$(beer_bottles)," ","bottle")
                        stock_depleted$ = "no more bottles"
                CASE 2
                        stock$ = CONCAT$(STR$(beer_bottles)," ","bottles")
                        stock_depleted$ = CONCAT$(STR$(beer_bottles - 1)," ","bottle")
                DEFAULT
                        stock$ = CONCAT$(STR$(beer_bottles)," ","bottles")
                        stock_depleted$ = CONCAT$(STR$(beer_bottles - 1)," ","bottles")
        END SELECT
END SUB

' -------------
SUB report_beers()
' -------------
        PRINT
        PRINT stock$," ", what$," ", where$, ", ", LCASE$(stock$), " ", what$, "."
        PRINT action$, stock_depleted$, " ", what$," ", where$,"."
        PRINT
END SUB

' *********************
' END SUBS
' *********************


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

init_vars
REPEAT
        beer_bottles = beer_bottles - 1
        check_beers
        report_beers
UNTIL beer_bottles EQ 0
END

' *********************
' END MAIN
' *********************