/* -------------- general macros ------------- */

#ifndef VERSION
#define VERSION		"1.1.0"		/* default version */
#endif
#ifndef BOOL
#define BOOL int
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define VDATE		"October 27, 2000"	/* version date */
#define VERBOSE0	2		/* default verbosity */
#define DEBUG_LV	0		/* debug output level */
#define OUTPUTFILE	"Out.ps"	/* standard output file */
#define PS_LEVEL	2		/* PS laguage level: must be 1 or 2 */

#ifndef _MSVC
int stricmp(const char *p1, const char *p2);
#endif

/* default directory to search for format files */
#define DEFAULT_FDIR	""


#define PAGEHEIGHT	(float)11.0		/* basic page dimensions in in ..  */
#define LEFTMARGIN	(float)0.75		/* (in).. used in all default formats  */
#define MIRRORINDENT (float)0.25	/* (in) */
#define STAFFWIDTH	(float)7.0		/* (in) */

/* This table is used to adjust the "absolute" pitch for the key in use. */
/* Second index is note C, D, E, F, G, A, B.                             */
extern	int		sharps_flats;
extern	short	key_convert[15][7];

/* ----- macros controlling music typesetting ----- */
#define STAFFHEIGHT	(float)24.0	/* Height of staff lines. */
#define BASEWIDTH	(float)0.8	/* width for lines drawn within music */
#define SLURWIDTH	(float)0.8	/* width for lines for slurs */
#define STEM_YOFF	(float)1.0	/* offset stem from note center */
#define STEM_XOFF	(float)3.5
#define STEM		(float)20	/* standard stem length */
#define STEM_MIN	(float)16	/* min stem length under beams */
#define STEM_MIN2	(float)12	/* ... for notes with two beams */
#define STEM_MIN3	(float)10	/* ... for notes with three beams */
#define STEM_MIN4	(float)10	/* ... for notes with four beams */
#define STEM_CH 	(float)20	/* standard stem length for chord */
#define STEM_CH_MIN	(float)12	/* min stem length for chords under beams */
#define STEM_CH_MIN2	 (float)8	/* ... for notes with two beams */
#define STEM_CH_MIN3	 (float)7	/* ... for notes with three beams */
#define STEM_CH_MIN4	 (float)7	/* ... for notes with four beams */
#define BEAM_DEPTH	(float)2.6	/* width of a beam stroke */
#define BEAM_OFFSET	(float)0.25	/* pos of flat beam relative to staff line */
#define BEAM_SHIFT	(float)5.3	/* shift of second and third beams */
/*  To align the 4th beam as the 1st: shift=6-(depth-2*offset)/3  */
#define BEAM_FLATFAC	(float)0.6	/* factor to decrease slope of long beams */
#define BEAM_THRESH	(float)0.06	/* flat beam if slope below this threshold */
#define BEAM_SLOPE	(float)0.5	/* max slope of a beam */
#define BEAM_STUB	(float)6.0	/* length of stub for flag under beam */ 
#define SLUR_SLOPE	(float)1.0	/* max slope of a slur */
#define DOTSHIFT	(float)5	/* shift dot when up flag on note */
#define GSTEM		(float)10.0	/* grace note stem length */
#define GSTEM_XOFF	(float)2.0	/* x offset for grace note stem */
#define GSPACE0		(float)10.0	/* space from grace note to big note */
#define GSPACE		(float)7.0	/* space between grace notes */
#define DECO_IS_ROLL	0	/* ~ makes roll if 1, otherwise twiddle */
#define CUT_NPLETS	0	/* 1 to always cut nplets off beams */
#define RANFAC		(float)0.05	/* max random shift = RANFAC * spacing */

#define BETA_C		(float)0.1	/* max expansion for flag -c */
#define ALFA_X		(float)1.0	/* max compression before complaining */
#define BETA_X		(float)1.2	/* max expansion before complaining */

#define VOCPRE		(float)0.4	/* portion of vocals word before note */
#define GCHPRE		(float)0.4	/* portion of guitar chord before note */

/* ----- macros for program internals ----- */

#define CM		(float)28.35	/* factor to transform cm to pt */
#define PT		(float)1.00	/* factor to transform pt to pt */
#define IN		(float)72.00	/* factor to transform inch to pt */

#define STRL		301	/* string length in info fields */
#define STRL1		101	/* string length for file names */
#define MAXSYMS		2001	/* max symbols in tune */
#define MAXPITCHVAL 100	/* maximum value for a pitch */
#define MAXHD		10	/* max heads on one stem */
#define MAXDECO		4	/* max string tablature decorations on one head */
#define MAXVOICE	32	/* max voices */
#define MAXSTAFF	16	/* max staves */
#define MAXWHISTLETAB	4	/* max whistle tablature parts */
#define MAXSTRINGTAB 4	/* max string tablature parts */
#define NTEXT		100	/* max history lines for output */
#define MAXINF		100	/* max number of input files */
#define BSIZE		4001	/* buffer size for one input string */
#define BUFFSZ		80000	/* size of output buffer */
#define BUFFSZ1		6000	/* buffer reserved for one staff */
#define NWLINE		8	/* max number of vocal lines per staff */

#define BASE		192	/* base for durations */
#define WHOLE		192	/* whole note */
#define HALF		96	/* half note */
#define QUARTER 	48	/* quarter note */
#define EIGHTH		24	/* 1/8 note */
#define SIXTEENTH	12	/* 1/16 note */
#define THIRTYSECOND	6	/* 1/32 note */
#define SIXTYFOURTH	3	/* 1/64 note */

#define COMMENT 	1	/* types of lines scanned */
#define MUSIC		2
#define TO_BE_CONTINUED 3
#define E_O_F		4
#define INFO		5
#define TITLE		6
#define METER		7
#define PARTS		8
#define KEY			9
#define XREF		10
#define DLEN		11
#define HISTORY 	12
#define BLANK		13
#define WORDS		14
#define MWORDS		15
#define PSCOMMENT	16
#define TEMPO		17
#define VOICE_D		18

#define INVISIBLE	1	/* valid symbol types */
#define NOTE		2
#define REST		3
#define BAR			4
#define CLEF		5
#define TIMESIG 	6
#define KEYSIG		7
#define COMBINEDNOTE 98	/* [JSA] for adaptive voice joining */
#define COMBINEDREST 99 /* [JSA] for adaptive voice joining */
/*#define GCHORD		8*/

#define SPACE		101	/* additional parsable things */
#define E_O_L		102
#define ESCSEQ		103
#define CONTINUE	104
#define NEWLINE 	105
#define DUMMY		106

#define B_SNGL		1	/* codes for different types of bars */
#define B_DBL		2	/* ||   thin double bar */
#define B_LREP		3	/* |:   left repeat bar */
#define B_RREP		4	/* :|   right repeat bar */
#define B_DREP		5	/* ::   double repeat bar */
#define B_FAT1		6	/* [|   thick at section start */
#define B_FAT2		7	/* |]   thick at section end  */
#define B_INVIS 	8	/* invisible; for endings without bars */

/* Tab decos */
#define TD_STRMASK	0x000F
#define TD_FRETMASK	0x01F0
#define TD_HAMMER	0x0200
#define TD_PULL		0x0400
#define TD_TRILL	0x0800
#define TD_UP		0x1000
#define TD_FULL		0x2000
#define TD_TYPEMASK	0xC000
#define TD_NONE		0x0000
#define TD_BEND		0x4000
#define TD_SLIDEFROM	0x8000
#define TD_SLIDETO	0xC000

#define A_SH		1	/* codes for accidentals */
#define A_NT		2
#define A_FT		3
#define A_DS		4
#define A_DF		5

#define D_GRACE 	1	/* codes for decoration */
#define D_STACC 	2
#define D_SLIDE 	3
#define D_EMBAR 	4
#define D_HOLD		5
#define D_UPBOW 	6
#define D_DOWNBOW	7
#define D_ROLL		8
#define D_TRILL 	9
/* [JSA] 4/21/00 */
#define D_ACCENT	10
#define D_LOWM		11
#define D_UPM		12
#define D_CODA		13
#define D_SEGNO		14
/* [JSA] 05/00 */
#define D_DC		15
#define D_DS		16
#define D_FINE		17
#define D_BREATH	18
#define D_PLUS		19
#define D_WEDGE		20
#define D_FINGER0	21
#define D_FINGER1	22
#define D_FINGER2	23
#define D_FINGER3	24
#define D_FINGER4	25
#define D_FINGER5	26
#define D_sfz		27
#define D_ffff		28
#define D_fff		29
#define D_ff		30
#define D_f			31
#define D_mf		32
#define D_p			33
#define D_pp		34
#define D_ppp		35
#define D_pppp		36
#define D_NTEXT		37	/* Text next to notehead */
#define D_STEXT		38  /* For text decorations above staff. */
#define D_STDIM		39
#define D_ENDDIM	40
#define D_STCRESC	41
#define D_ENDCRESC	42
#define D_GCHORD	43	/* A guitar chord. */
#define D_GCHORDB	44	/* A guitar chord with the optional bass note.	*/

#define H_FULL		1	/* types of heads */
#define H_EMPTY 	2
#define H_OVAL		3

#define TREBLE		0	/* types of clefs */
#define BASS		1
#define ALTO		2

#define G_FILL		1	/* modes for glue */
#define G_SHRINK	2
#define G_SPACE 	3
#define G_STRETCH	4

#define S_TITLE		1	/* where to do pattern matching */
#define S_RHYTHM	2
#define S_COMPOSER	3
#define S_SOURCE	4

#define TEXT_H		1	/* type of a text line */
#define TEXT_W		2
#define TEXT_Z		3
#define TEXT_N		4
#define TEXT_D		5

#define DO_INDEX	1	/* what program does */
#define DO_OUTPUT	2

#define SWFAC		(float)0.50	/* factor to estimate width of string */

#define DB_SW		0	/* debug switch */

#define MAXFORMATS	10	/* max number of defined page formats */
#define STRLFMT		81	/* string length in FORMAT struct */

#define ALIGN		1
#define RAGGED		2
#define OBEYLINES	3
#define OBEYCENTER	4
#define SKIP		5

extern int db;			/* debug control */

#define NCOMP	5		/* max number of composer lines */

struct ISTRUCT {		/* information fields */
	char *area;
	char *book;
	char *comp[NCOMP];
	int  ncomp;
	char *disc;
	char *eskip;
	char *group;
	char *hist;
	char *info;
	char *key;
	char *len;
	char *meter;
	char *notes;
	char *orig;
	char *rhyth;
	char *src;
	char *title;
	char *title2;
	char *title3;
	char *parts;
	char *xref;
	char *trans;
	char *tempo;
	char DecoTbl[36];	/* For U: substitution [JSA] 05/00 */
};

extern struct ISTRUCT info,default_info;

struct GRACE {		/* describes grace notes */
	int n;			/* number of grace notes */
	char p[30];		/* pitches */
	char a[30];		/* accidentals */
};

struct DECO {		/* describes decorations */
	int n;			/* number of decorations */
	float top;		/* Top of note, stem, & decorations close to note heads. */
	float bot;		/* Bottom of note, stem, & decorations close to note heads. */
	char t[10];		/* type of deco */
};

struct SYMBOL { 		/* struct for a drawable symbol */
	short type;			/* type of symbol */
	short pits[MAXHD];	/* pitches for notes */
	short lens[MAXHD];	/* note lengths as multiple of BASE */
	short abspitch[MAXHD];	/* "absolute" pitch for tablature mods [JSA] */
	unsigned short TabDeco[MAXHD];	/* tab decorations [JSA] */
	char accs[MAXHD];	/* code for accidentals */
	char sl1 [MAXHD];	/* which slur start on this head */
	char sl2 [MAXHD];	/* which slur ends on this head */
	char ti1 [MAXHD];	/* flag to start tie here */
	char ti2 [MAXHD];	/* flag to end tie here */
	float shhd[MAXHD];	/* horizontal shift for heads */
	float shac[MAXHD];	/* horizontal shift for accidentals */
	short len;			/* basic note length */
	char npitch;		/* number of note heads */
	unsigned word_st:1;	/* 1 if word starts here */
	unsigned word_end:1;/* 1 if word ends here */
	unsigned in_beam:1;	/* 1 if note is beamed */
	unsigned eoln:1;	/* flag for last symbol in line */
	unsigned invis:1;	/* mark note as invisible */
	unsigned first:1;	/* first symbol */
	unsigned last:1;	/* last symbol */
	char slur_st; 		/* how many slurs starts here */
	char slur_end;		/* how many slurs ends here */
	float x,y;			/* position */
	int ymn,ymx,yav;	/* min,mav,avg note head height */
	/* ylo and yhi were described as "bounds for this object" but	*/
	/* in reality they were only being set quite crudely and only	*/
	/* for notes.  Furthermore, I couldn't find a single instance	*/
	/* where they were actually USED as input to functionality.		*/
	/* They are now set more accurately for noteheads, stems, and	*/
	/* decorations, and are actually used to push decorations up	*/
	/* (or down, if below staff). [JSA]								*/
	float ylo,yhi;		/* bounds for this object */
	float xmn,xmx;		/* min,max h-pos of a head rel to top */
	short stem;			/* 0,1,-1 for no stem, up, down */
	char flags;			/* number of flags or bars */
	char dots;			/* number of dots */
	char head;			/* type of head */
	char staff;			/* staff (0..nstaff) */
	char multi;			/* multi voice in the staff (+1, 0, -1) */
	struct GRACE gr;	/* grace notes */
	struct DECO dc;		/* decorations */
	float xs,ys;		/* position of stem end */
	int u,v,w,t,z;		/* auxillary information */
	float wl,wr;		/* left,right min width */
	float pl,pr;		/* left,right preferred width */
	float xl,xr;		/* left,right expanded width */
	float space,shrink,stretch; /* glue before this symbol */
	int p_plet,q_plet,r_plet;   /* data for n-plets */
	/* gchy was being set in two places but was never used! */
	/* (it makes sense that it wouldn't be used because we  */
	/* want to position guitar chords level for an entire   */
	/* line, not have them bounce up and down depending on	*/
	/* the symbol height).  [JSA]							*/
	/*float gchy;*/			/* height of guitar chord */
	char *text;			/* for guitar chords etc. */
	char *wordp[NWLINE];/* pointers to wpool for vocals */
	struct SYMBOL *lnk; /* [JSA] Pointer to symbol this one was combined with. */
	char StemDir;		/* [JSA] -1, 0, 1 Stem direction from %%jsastem=dn|def|up */
	char EndTie;		/* [JSA] End a tie outside a chord. */
	char Voice;			/* [JSA] voice this symbol was parsed on. */
	BOOL Unison;		/* [JSA] true when two or more notes in unison. */
};
extern struct SYMBOL *sym;

struct FONTSPEC {
	char name[STRLFMT];
	float size;
};

struct FORMAT { 		/* struct for page layout */
	char	name[STRLFMT];
	float	pageheight,staffwidth;
	float	topmargin,botmargin,leftmargin;
	float	topspace,wordsspace,titlespace,subtitlespace,partsspace;
	float	composerspace,musicspace,staffsep,vocalspace,textspace;
	float	scale,maxshrink,lineskipfac,parskipfac;
	int		landscape,titleleft,continueall,breakall,writehistory;
	int		stretchstaff,stretchlast,withxrefs,barsperstaff;
	int		oneperpage,musiconly,titlecaps;
	struct	FONTSPEC titlefont,subtitlefont,vocalfont,textfont,tempofont;
	struct	FONTSPEC composerfont,partsfont,gchordfont,wordsfont;
	/* [JSA] new in jaabc2ps ... */
	char	BookTitle[256], BookCR[256], tWatermarkText[256]; /* [JSA] */
	char	InlineSyntax[64], Syntax[64];
	float	DecoSpacing;			/* [JSA] Vertical spacing for decorations.	*/
	float	StaffTextHFac, StaffTextVFac, NoteTextFac;	/* [JSA] spacing		*/ 
	BOOL	PageNumTop, PageMirror, ShowTempo;
	BOOL	CombineVoices, CarryAccs, HelperAccs;
	BOOL	Watermark, WatermarkFile, WatermarkDate;
	BOOL	ShowHistory, ShowRhythm, ShowTrans, ShowSource;	
	BOOL	NoInlineFmt;
	BOOL	RollsClose, BreathsClose;
	BOOL	ManualPages;
	float	MirrorIndent, LineSep, StrTabSpace, WatermarkGray;
	struct	FONTSPEC StrTabFont;
	struct	FONTSPEC CopyrightFont, BookTitleFont, SourceFont;
	struct	FONTSPEC DcDsFont, DynFont;		/* not user configurable */
	struct  FONTSPEC InfoFont, HistoryFont;
	BOOL	DecosBelow[MAXVOICE];	/* Print decorations below the staff.			*/
	BOOL	NoDecos[MAXVOICE];		/* Do not print "far" decos for this voice.		*/
	int		FreeMetStyle;			/* 0 = none, 1 = free, 2 = free/meter, 3 = fm	*/
};

extern struct FORMAT sfmt;	/* format after initialization */
extern struct FORMAT dfmt;	/* format at start of tune */
extern struct FORMAT cfmt;	/* current format for output */

extern char fontnames[50][STRLFMT];	/* list of needed fonts */
extern int  nfontnames;

extern int  ntxt; 

extern char mbf[501];		/* mini-buffer for one line */
extern int nbuf;		/* number of bytes buffered */
extern float bposy;		/* current position in buffered data */
extern int use_buffer;		/* 1 if lines are being accumulated */

extern char *text[NTEXT];	/* pool for history, words, etc. lines */
extern int text_type[NTEXT];	/* type of each text line */
extern int ntext;		/* number of text lines */
extern char page_init[201];	/* initialization string after page break */
extern int do_mode;		/* control whether to do index or output */
extern int linenum;		/* current line number in input file */
extern int tunenum;		/* number of current tune */
extern int tnum1,tnum2;
extern int numtitle;		/* how many titles were read */
extern int nsym;		/* number of symbols in line */
extern int pagenum;		/* current page in output file */
extern int xrefnum;		/* xref number of current tune */

extern int meter1,meter2;	/* for meter */
extern int transpose;
extern int bagpipe;		/* switch for HP mode */
extern int within_tune, within_block;	/* where we are in the file */
extern int do_this_tune;	/* are we typesetting the current one ? */
extern float posx,posy; 	/* overall scale, position on page */

extern int insert_btype,insert_num;	/* needed to split bars across lines */

extern int vb, verbose; 		/* verbosity, global and within tune */
extern int in_page;

				 /* switches modified by flags: */
extern int gmode;			/* switch for glue treatment */
extern int include_xrefs;		/* to include xref numbers in title */
extern int one_per_page;		/* new page for each tune ? */
extern int pagenumbers; 		/* write page numbers ? */
extern int write_history;		/* write history and notes ? */
extern int interactive; 		/* interactive mode ? */
extern int help_me;			/* need help ? */
extern int select_all;			/* select all tunes ? */
extern int epsf;			/* for EPSF postscript output */
extern int choose_outname;		/* 1 names outfile w. title/fnam */
extern int break_continues;		/* ignore continuations ? */
extern int search_field0;		/* default search field */

extern char in_file[MAXINF][STRL1];	/* list of input file names */
extern int  ninf;			/* number of input file names */

extern char outf[STRL1];		/* output file name */
extern char infostr[STRL1];		/* title string in PS file */

extern int  file_open;			/* for output file */
extern int  file_initialized;		/* for output file */
extern FILE *fout;			/* for output file */
extern int nepsf;			/* counter for epsf output files */

extern char sel_str[MAXINF][STRL1];	/* list of selector strings */
extern int  s_field[MAXINF];		/* type of selection for each file */
extern int  psel[MAXINF];		/* pointers from files to selectors */

struct STAFF {
	char	clef;			/* basic clef */
	unsigned brace:1;		/* 1st staff of a brace */
	unsigned brace_end:1;	/* 2nd staff of a brace */
	unsigned bracket:1;		/* 1st staff of a bracket */
	unsigned bracket_end:1;	/* last staff of a bracket */
	char	nvoice;			/* number of voices in the staff (0..n-1) */
	char	nvocal;			/* number of vocals (1..n) */
	float	toppos;			/* place needed at top */
	float	botpos;			/* place needed at bottom */
	float	y;				/* y position */
	float	CrescendoStX;	/* Start for crescendo or diminuendo [JSA] 05/00 */
	float	CrescendoStY;	/* Start for crescendo or diminuendo [JSA] 05/00 */
};
extern struct STAFF staff_tb[MAXSTAFF];
extern int nstaff;		/* (0..MAXSTAFF-1) */

/*****************************************************************/
/*                                                               */
/* BEGIN whistle tablature modification, J. S. Atchley, 10/99    */
/*                                                               */
/* Note, whistle tablature appears below all staves.             */
/*                                                               */
/*****************************************************************/
typedef struct WHISTLETAB {
	int		voice;		/* The voice for this tablature. */
	int		keypitch;	/* Key of the whistle. */
	float	y;			/* y position */
} tWhistleTab;
extern tWhistleTab WhistleTab_tb[MAXWHISTLETAB];
extern int nWhistleTab;		/* (0..MAXWHISTLETAB-1) */

/*****************************************************************/
/*                                                               */
/*  END tablature modification, J. S. Atchley, 10/99             */
/*                                                               */
/*****************************************************************/

/*****************************************************************/
/*                                                               */
/* BEGIN string tablature modification, J. S. Atchley, 11/99     */
/*                                                               */
/* Note, string tablature appears below all staves but above     */
/* whistle tablature.                                            */
/*                                                               */
/*****************************************************************/
#define TABCHROMATIC	0
#define TABDULCIMER		1
#define TABDULCIMERPLUS	2
#define TABSIMPLE		0
#define TABMARKED		1
typedef struct STRINGTAB {
	int		voice;		/* The voice for this tablature.         */
	int		fretting;	/* 0 = chromatic, 1 = dulcimer, 2 = 6+   */
	int		style;		/* TABSIMPLE | TABMARKED                 */
	int		capo;		/* capo fret                             */
	int		pitches[8];	/* Pitch of each string.                 */
	int		nstrings;	/* The number of strings used.           */
	float	y;			/* y position                            */
} tStringTab;
extern tStringTab StringTab_tb[MAXSTRINGTAB];
extern int nStringTab;		/* (0..MAXSTRINGTAB-1) */

/*****************************************************************/
/*                                                               */
/*  END tablature modification, J. S. Atchley, 11/99             */
/*                                                               */
/*****************************************************************/

/* This implements a FIFO queue for storing text "decorations."  */
#define MAXSTRDECO		256		/* Maximum number of chords or text decorations in a tune. */
#define STRDECOMAXLEN	256     /* Max length of text decorations. */
#define TXTJ_LT		0
#define TXTJ_RT		1
#define TXTJ_CN		2
#define TXTA_LT		0
#define TXTA_RT		1
#define TXTA_TOP	2
#define TXTA_BOT	3
#define TXTA_CLAMP	4
typedef struct tagFIFO {	
	char	*strings[MAXSTRDECO];
	int		inidx, outidx;
	float	dx[MAXSTRDECO], dy[MAXSTRDECO];
	char	anchor[MAXSTRDECO], just[MAXSTRDECO];			/* Defined above. */
} tFIFO;

struct VOICE_S {
	char		staff;			/* staff (0..n-1) (1st if brace) */
	char		clef;			/* current clef while parsing */
	unsigned	forced_clef:1;	/* explicit clef */
	unsigned	end_slur_next_note:1;	/* for patched in a-b slurs */
	unsigned	second:1;		/* secondary voice in a brace/parenthesis */
	unsigned	floating:1;		/* floating voice in a brace */
	int			nsym;			/* current number of symbols */
	int			nsym0;			/* beginning of the current line */
	struct SYMBOL *sym;			/* associated symbols (size MAXSYMS) */
	char		*name;			/* voice name */
	short		dlen;			/* default length */
	short		meter1, meter2;	/* for meter */
	char		mflag,lflag;	/* flags for C, l or s in meter */
	int			sharps_flats;
	char		StemDir;		/* -1, 0, or 1 from "%%jsastem=dn|def|up" [JSA] */
	tFIFO		TextDecs;		/* For storing text decorations. [JSA] */
	tFIFO		TextHdDecs;		/* Text decos near noteheads. [JSA] */
	tFIFO		Chords;			/* Guitar chords. [JSA]	*/
};
extern struct VOICE_S voice_tb[MAXVOICE];	/* voice table */
extern int VoiceMute_tb[MAXVOICE];			/* for muting voices [JSA] */

extern BOOL	VoiceSet;
extern int nvoice;			/* (0..MAXVOICE-1) */
extern int current_voice;	/* current voice while parsing */
extern int measure_nb;		/* measure numbering (-1: none, 0: on the left, or every n bars) */
extern int ParamUnits;		/* [JSA] 0 = inches, 1 = cm, 2 = pt */
extern int FixEols;			/* Fix the line breaks in source files */

/* PUTn: add to buffer with n arguments */
#define PUT0(f) do {sprintf(mbf,f); a2b(mbf); } while (0)
#define PUT1(f,a) do {sprintf(mbf,f,a); a2b(mbf); } while (0)
#define PUT2(f,a,b) do {sprintf(mbf,f,a,b); a2b(mbf); } while (0)
#define PUT3(f,a,b,c) do {sprintf(mbf,f,a,b,c); a2b(mbf); } while (0)
#define PUT4(f,a,b,c,d) do {sprintf(mbf,f,a,b,c,d); a2b(mbf); } while (0)
#define PUT5(f,a,b,c,d,e) do {sprintf(mbf,f,a,b,c,d,e); a2b(mbf); } while (0)

/* external routines */
/* buffer.c */
extern void a2b(char *t);
extern void buffer_eob(FILE *fp);
extern void bskip(float h);
extern void check_buffer(FILE *fp,
			 int nb);
extern void clear_buffer(void);
extern void init_pdims(void);
extern void write_buffer(FILE *fp);
/* format.c */
extern void g_unum(char *l,
		   int nch,
		   float *num);
extern int interpret_format_line(char l[],
				 struct FORMAT *f);
extern void make_font_list(struct FORMAT *f);
extern void print_format(struct FORMAT f);
extern int read_fmt_file(char filename[],
			 char dirname[],
			 struct FORMAT *f);
extern void set_pretty_format(struct FORMAT *f);
extern void set_pretty2_format(struct FORMAT *f);
extern void set_standard_format(struct FORMAT *f);
/* music.c */
extern void output_music(FILE *fp);
extern void process_pscomment(FILE *fpin,
			      FILE *fp,
			      char line[]);
extern void reset_gen(void);
/* parse.c */
extern int add_sym(int type);
extern void do_index(FILE *fp,
		     char xref_str[],
		     int npat,
		     char pat[][STRL1],
		     int select_all,
		     int search_field);
extern void get_staves(char *p);
extern void identify_note(struct SYMBOL *s,
		   char *q);
extern void init_music_line(int voice);
extern int parse_length(void);
extern void process_file(FILE *fpin,
			 FILE *fpout,
			 char xref_str[],
			 int npat,
			 char pat[][STRL1],
			 int sel_all,
			 int search_field);
extern int rehash_selectors(char sel_str[],
			    char xref_str[],
			    char pat[][STRL1]);
extern void zero_sym(void);
/* pssubs.c */
extern void close_ps(FILE *fp);
extern void close_epsf(FILE *fp);
extern void close_page(FILE *fp);
extern void init_epsf(FILE *fp);
extern void init_page(FILE *fp);
extern void init_ps(FILE *fp,
		    char str[],
		    int  is_epsf,
		    float bx1,
		    float by1,
		    float bx2,
		    float by2);
extern void write_pagebreak(FILE *fp);
/* subs.c */
extern void add_to_text_block(char ln[],
		       int add_final_nl);
extern void check_margin(float new_posx);
extern void close_output_file(void);
extern void epsf_title(char title[],
		      char fnm[]);
extern int is_xrefstr(char str[]);
extern int make_arglist(char str[],
			char *av[]);
extern void open_output_file(char fnam[],
			     char tstr[]);
extern void ops_into_fmt(struct FORMAT *fmt);
extern int parse_args(int ac,
		      char *av[]);
extern void PutSource(FILE *fp);
extern void put_history(FILE *fp);
extern void put_words(FILE *fp);
extern void set_font(struct FONTSPEC font,
		     int add_bracket);
extern int set_page_format();
extern int tex_str(char *str,
		   char s[],
		   float *wid);
extern void write_inside_tempo(void);
extern void write_inside_title(void);
extern void write_heading(void);
extern void write_help(void);
extern void write_parts(void);
extern void write_text_block(FILE *fp,
			     int  job);
extern void write_tunetop(void);
/* syms.c */
extern void define_font(FILE *fp,
			char name[],
			int  num);
extern void define_symbols(FILE *fp, char *Watermark, float Gray);
/* util.c */
extern int abbrev(char str[],
		  char ab[],
		  int nchar);
extern void bug(char msg[],
		int fatal);
extern void clrarena(void);
extern char *getarena(int len);
extern void cap_str(char *c);
extern int get_file_size(char fname[]);
extern void getext(char fid[],
		   char ext[]);
extern int isblankstr(char str[]);
extern int nwords(char *str);
extern float ranf(float x1,
		  float x2);
extern void cutext(char fid[]);
extern float cwid(char c);
extern void init_ops(int job);
extern int match(char str[],
		 char pat[]);
extern float scan_u(char str[]);
extern void rx(char msg[],
	       char str[]);
extern void strext(char fid1[],
		   char ext[]);
extern char *strip(char *str);
extern void wng(char msg[],
		char str[]);
