/*---------------------------------------------------------------------------
pilrc.c -- a resource compiler for the pilot

by Wes Cherry wesc@ricochet.net

usage:

pilrc [-L LANGUAGE] infile [outdir]

infile is a file describing the resources to be emitted.  Each resource is 
written as a seperate file in the [outdir] directory.  The output filename 
is constructed by appending the hexcode resource id to the four character 
resource type.  For example, a FORM (tFRM) with formid of 15 would be 
written as tfrm000f.bin.  


SYNTAX
------
Pilrc's syntax is described below.  Items in all CAPS appear as literals 
in the file.  Items enclosed in < and > are required fields.  The type is 
indicated by a suffix after the field name (see below for types).  Items 
inclosed in [ and ] are optional fields.  

types
-----
.s  = string 
      example:  "Click Me"

.ss = multi line string.  pilrc will concatenate strings on seperate lines 
      enclosed with quotes and terminated by the \ character
      example:  "Now is the time for all good "\ 
                "men to come to the aid of their country"

.n = number or simple arithmetic expression.  Valid operators are + - * /.  
      precedence is left to right. math is integer.
      examples: 23 12+3+1 12*4 14*3+5/2

.p = position coordinate.  Which may be either a number, expression or one 
     of the following keywords
        AUTO       : Automatic width or height.  The width/height of the 
                     item is computed based on the text in the item.  
	             valid only for widths or heights of items.
        CENTER     : Centers the item either horizontally or vertically.  
                     Only valid for left or top coordinate of an item.
	PREVLEFT   : Previous items left coordinate
	PREVRIGHT  : Previous items right coordinate
	PREVWIDTH  : Previous items width
	PREVTOP    : Previous items top coordinate
	PREVBOTTOM : Previous items bottom coordinate
	PREVHEIGHT : Previous items height
	
	example: PREVRIGHT+2 
	
	NOTE:  AUTO and CENTER must stand alone and are not valid in 
        arithmetic expressions


FORM (tFRM) syntax
------------------
FORM <FormResourceId.n> <Left.p> <Top.p> <Width.p> <Height.p>
[FRAME]
[NOFRAME]
[MODAL]
[SAVEBEHIND]
[USABLE]
[HELPID <HelpId.n>]
[DEFAULTBTNID <BtnId.n>]
[MENUID <MenuId.n>]
BEGIN
	<OBJECTS>
END

<OBJECTS>: one or more of:

TITLE           <Title.s>
BUTTON          <Label.s> <Id.n> <Left.p> <Top.p> <Width.p> <Height.p> 
                [USABLE] [NONUSABLE] [DISABLED] [LEFTANCHOR] [RIGHTANCHOR] [FRAME] [NOFRAME] [BOLDFRAME] [FONT <FontId.n>]
PUSHBUTTON      <Label.s> <Id.n> <Left.p> <Top.p> <Width.p> <Height.p> [USABLE] [NONUSABLE] [DISABLED] [LEFTANCHOR] [RIGHTANCHOR] [FONT <FontId>] [GROUP <GroupId.n>]
CHECKBOX        <Label.s> <Id.n> <Left.p> <Top.p> <Width.p> <Height.p> [USABLE] [NONUSABLE] [DISABLED] [LEFTANCHOR] [RIGHTANCHOR] [FONT <FontId>] [GROUP <GroupId.n>] [CHECKED]
POPUPTRIGGER    <Label.s> <Id.n> <Left.p> <Top.p> <Width.p> <Height.p> [USABLE] [NONUSABLE] [DISABLED] [LEFTANCHOR] [RIGHTANCHOR] [FONT <FontId>]
SELECTORTRIGGER <Label.s> <Id.n> <Left.p> <Top.p> <Width.p> <Height.p> [USABLE] [NONUSABLE] [DISABLED] [LEFTANCHOR] [RIGHTANCHOR] [FONT <FontId>]
REPEATBUTTON    <Label.s> <Id.n> <Left.p> <Top.p> <Width.p> <Height.p> [USABLE] [NONUSABLE] [DISABLED] [LEFTANCHOR] [RIGHTANCHOR] [FRAME] [NOFRAME] [BOLDFRAME] [FONT <FontId.n>]
LABEL           <Label.s> <Id.n> <Left.p> <Top.p> [USABLE] [NONUSABLE] [FONT <FontId>]
FIELD           <Id.n> <Left> <Top.p> <Width.p> <Height.p> [USABLE] [NONUSABLE] [DISABLED] [LEFTALIGN] [RIGHTALIGN] [FONT <FontId>] [EDITABLE] [NONEDITABLE] [UNDERLINED] [SINGLELINE] [MULTIPLELINES] [Height.pNAMICSIZE] [MAXCHARS <maxchars>]
POPUPLIST       <Id.n> <idList>
LIST            <Item.s> <Item2.s>... <Id.n> <Left.p> <Top.p> <Width.p> <Height.p> [USABLE] [NONUSABLE] [DISABLED] [VISIBLEITEMS <numvisitems>] [FONT <FontId.n>]
FORMBITMAP      <x> <y> [BITMAP <BitmapId> [NONUSABLE]  
GRAFFITISTATEINDICATOR  <Left.p> <Top.p>
GADGET          <Id.n> <Left> <Top.p> <Width.p> <Height.p> [USABLE] [NONUSABE]
TABLE NYI!


Example: (this is a cliff notes version of AlarmHack's resource)
FORM 1 2 2 156 156
USABLE
MODAL
HELPID 1
MENUID 1
BEGIN
	TITLE "AlarmHack"
	LABEL "Repeat Datebook alarm sound" 2000 CENTER 16 
	PUSHBUTTON "1" 2001 20 PrevBottom+2 12 AUTO GROUP 1
	PUSHBUTTON "2" 2002 PrevRight+1  PrevTop PrevWidth PrevHeight GROUP 1
	PUSHBUTTON "3" 2003 PrevRight+1  PrevTop PrevWidth PrevHeight GROUP 1

	LABEL "times.  Ring again every" 601 CENTER PrevBottom+2 FONT 0

	PUSHBUTTON "never" 3000 13 PrevBottom+2 32 12 GROUP 2
	PUSHBUTTON "10 sec" 3001 PrevRight+1 PrevTop PrevWidth PrevHeight GROUP 2
	PUSHBUTTON "30 sec" 3002 PrevRight+1 PrevTop PrevWidth PrevHeight GROUP 2
	PUSHBUTTON "1 min" 3003 PrevRight+1 PrevTop PrevWidth PrevHeight GROUP 2

	LABEL "Alarm sound:" 601 24 PrevBottom+4
	POPUPTRIGGER "          " 5000 PrevRight+4 PrevTop 62 AUTO LEFTANCHOR
	LIST "Standard" "Two Tone" "Sine" "Computer" "Skip Along" "Beethoven" "EuroCop" "Cricket" "Bleep" "Computer2" 6000 PrevLeft PrevTop 52 1 VISIBLEITEMS 10 NONUSABLE
	POPUPLIST 5000 6000

	BUTTON "Test" 1202 CENTER 138 AUTO AUTO
	GRAFFITISTATEINDICATOR  100 100
END



MENU (MBAR) syntax:
-------------------
MENU <MenuResourceId>
BEGIN
	<PULLDOWNS>
END


<PULLDOWNS>: one or more of:

PULLDOWN <PulldownTitle.s>
BEGIN
	<MENUITEMS>
END

<MENUITEMS>: : one or more of:
	MENUITEM <MenuItem.s> <MenuItemId.n> [AccelChar.c]

Example:
MENU 100
BEGIN
	PULLDOWN "File"
	BEGIN
		MENUITEM "Open..." 100 "O"	
		MENUITEM "Close" 101 "C"
	END
	PULLDOWN "Options"
	BEGIN
		MENUITEM "Get Info..." 500 "I"
	END
END


ALERT (tALT) syntax:
--------------------
ALERT <AlertResrouceId.n>
[HELPID <HelpId.n>]
[INFORMATION] [CONFIRMATION] [WARNING] [ERROR]
BEGIN
	TITLE <Title.s>
	MESSAGE <Message.ss>
	BUTTONS <Button.s> <BUTTON.s>...
END

Example:
ALERT 1000
HELPID 100
CONFIRMATION
BEGIN
	TITLE "AlarmHack"
	MESSAGE "Continuing will cause you 7 years of bad luck\n"\
		"Are you sure?"
	BUTTONS "Ok" "Cancel"
END


VERSION (tVER) syntax:
----------------------
VERSION <VersionResourceId.n> <Version.s>

Example:
VERSION 1 "0.09"


STRING (tSTR) syntax:
---------------------
STRING <StringResourceId.n> <String.ss>

Example:
STRING 100 "This is a very long string that demonstrates carriage retuns\n" \
	"as well as continued .ss syntax strings"

APPLICATIONICONNAME (tAIN) syntax:
----------------------------------
APPLICATIONICONNAME <AINResourceId.n> <ApplicationName.s>

Example:
APPLICATIONICONNAME 100 "AlarmHack"

APPLICATION (APPL) syntax:
--------------------------
APPLICATION <ApplResourceId.n> <APPL.s> 

(APPL must be 4 chars)

Example:
APPLICATION 1 "ALHK"

-----------------------------------------------------------------------------

INTERNATIONAL SUPPORT:
Pilrc supports a limited form of international tokenization.  It works by 
substituting strings in the resource definitions with replacements 
specified in a TRANSLATION section.  Multiple translation blocks may be 
specified in a resource script.  The active language is specified with the 
-L flag to pilrc.  (Yeah, I know this is a pretty cheezy way to do this, 
but it has worked so far.  The biggest problem is with positioning of 
controls.  If you use AUTO, CENTER and PREVRIGHT et al it might not 
involve any position changing in your script.  If you do need to change 
the position, Right now the only workaround is to put some #ifdefs in your 
file and hook up a custom rule to preprocess your source file) 

Example:
pilrc -L FRENCH myscript.rcp res\

TRANSLATION syntex
------------------
TRANSLATION <Language.s>
BEGIN
	<STRINGTRANSLATIONS>
END

where <STRINGTRANSLATINOS> is one or more of:
<Original.s> = <Translated.ss>

Example:
TRANSLATION "FRENCH"
BEGIN
	"Repeat Datebook alarm sound" = "Rptitions Alarme Agenda" 
	"Ring again every" = "Rappel tous les" 
END

TIP: For long strings define a short keyword and then define both native 
and foriegn translations for it.  

-------------------------------------------------------------WESC----------*/


