12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136 |
- Program fd2pascal;
- { ---------------------------------------------------------------------------
- Program to convert forms fdesign file to pascal code
- Copyright (C) 1997 Michael Van Canneyt
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
- any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- --------------------------------------------------------------------------- }
- { $Id$ }
- uses
- {$ifdef ver1_0}
- Linux
- {$else}
- Unix
- {$endif}
- ;
- Const RevString = '$Revision$';
- NrOptions = 4;
- Options : Array[0..NrOptions] Of String[20] =
- ('v','callback','main','altformat','compensate');
- Type
- { Properties of an object }
- ContProps=(CPclass,CPtype,CPbox,CPBoxtype,CPColors,CPalignment,CPstyle,CPsize,
- CPlcol,CPlabel,CPShortcut,CPresize,CPgravity,CPname,CPCallback,
- CPargument,
- CPinvalid);
- { Properties of an object for which defaults must be set }
- AdjProps=(APClass,APBoxtype,ApColors,APAlignment,APSize,APLcol,APstyle,APgravity);
- { List of all object classes }
- ObjClasses=(FL_INVALID,FL_BUTTON, FL_LIGHTBUTTON,FL_ROUNDBUTTON, FL_ROUND3DBUTTON,
- FL_CHECKBUTTON, FL_BITMAPBUTTON, FL_PIXMAPBUTTON,FL_BITMAP, FL_PIXMAP,
- FL_BOX, FL_TEXT, FL_MENU, FL_CHART, FL_CHOICE, FL_COUNTER, FL_SLIDER, FL_VALSLIDER, FL_INPUT,
- FL_BROWSER,FL_DIAL,FL_TIMER,FL_CLOCK, FL_POSITIONER, FL_FREE,
- FL_XYPLOT,FL_FRAME, FL_LABELFRAME, FL_CANVAS, FL_GLCANVAS,
- FL_IMAGECANVAS, FL_FOLDER);
- { Properties in preamble }
- PreProps=(PPmagic,PPNrforms,PPUnitofMeasure,PPinvalid);
- { Properties of a form }
- FormProps=(FPName,FPWidth,FPHeight,FPnumObjs,FPinvalid);
- Const
- { Names of all object properties }
- ContPropNames : Array[ContProps] of string[20] =
- ('class','type','box','boxtype','colors','alignment','style','size',
- 'lcol','label','shortcut','resize','gravity','name','callback',
- 'argument',
- 'invalid');
- { Names of all object properties which must be checked.}
- AdjPropsNames : Array[AdjProps] of string[20] =
- ('class','boxtype','colors','alignment','size','lcol','style','gravity');
- { Names of all preamble properties }
- PrePropNames : Array[PreProps] of string[20] =
- ('Magic','Number of forms','Unit of measure','Invalid');
- { Names of all form properties }
- FormPropNames : Array[FormProps] of string[20] =
- ('Name','Width','Height','Number of Objects','Invalid');
- { Names of all object classes }
- FObjClassNames : Array[ObjClasses] of string[20]=
- ('FL_INVALID','BUTTON', 'LIGHTBUTTON','ROUNDBUTTON', 'ROUND3DBUTTON',
- 'CHECKBUTTON', 'BITMAPBUTTON', 'PIXMAPBUTTON','BITMAP', 'PIXMAP',
- 'BOX', 'TEXT', 'MENU', 'CHART', 'CHOICE', 'COUNTER', 'SLIDER', 'VALSLIDER', 'INPUT',
- 'BROWSER','DIAL','TIMER','CLOCK', 'POSITIONER', 'FREE',
- 'XYPLOT','FRAME', 'LABELFRAME', 'CANVAS', 'GLCANVAS',
- 'IMAGECANVAS', 'FOLDER');
- { Default properties. If empty a property is ignored.
- To force setting of a property, put 'FL_FORCE' as a string.
- Mind : Case sensitive }
- DefProps : array[ObjClasses,AdjProps] of string[30] =
- (('FL_INVALID','','','','','','FL_NORMAL_STYLE','FL_FORCE'),
- ('BUTTON','FL_UP_BOX','FL_COL1 FL_COL1','FL_ALIGN_CENTER','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('LIGHTBUTTON','FL_UP_BOX','FL_COL1 FL_YELLOW','FL_ALIGN_CENTER','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('ROUNDBUTTON','FL_NO_BOX','FL_MCOL FL_YELLOW','FL_ALIGN_CENTER','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('ROUND3DBUTTON','FL_NO_BOX','FL_COL1 FL_BLACK','FL_ALIGN_CENTER','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('CHECKBUTTON','FL_NO_BOX','FL_COL1 FL_YELLOW','FL_ALIGN_CENTER','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('BITMAPBUTTON','FL_UP_BOX','FL_COL1 FL_BLUE','FL_ALIGN_BOTTOM','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('PIXMAPBUTTON','FL_UP_BOX','FL_COL1 FL_YELLOW','FL_ALIGN_BOTTOM','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('BITMAP','FL_NO_BOX','FL_COL1 FL_COL1','FL_ALIGN_BOTTOM','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('PIXMAP','FL_NO_BOX','FL_COL1 FL_COL1','FL_ALIGN_BOTTOM','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('BOX','','','','','','FL_NORMAL_STYLE','FL_FORCE'),
- ('TEXT','FL_FLAT_BOX','FL_COL1 FL_MCOL','FL_ALIGN_LEFT','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('MENU','FL_BORDER_BOX','FL_COL1 FL_MCOL','FL_ALIGN_CENTER','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('CHART','FL_BORDER_BOX','FL_COL1','FL_ALIGN_BOTTOM','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('CHOICE','FL_ROUNDED_BOX','FL_COL1 FL_LCOL','FL_ALIGN_LEFT','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('COUNTER','FL_UP_BOX','FL_COL1 FL_BLUE','FL_ALIGN_BOTTOM','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('SLIDER','FL_DOWN_BOX','FL_COL1 FL_COL1','FL_ALIGN_BOTTOM','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('VALSLIDER','FL_DOWN_BOX','FL_COL1 FL_COL1','FL_ALIGN_BOTTOM','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('INPUT','FL_DOWN_BOX','FL_COL1 FL_MCOL','FL_ALIGN_LEFT','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('BROWSER','FL_DOWN_BOX','FL_COL1 FL_YELLOW','FL_ALIGN_BOTTOM','FL_SMALL_FONT','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('DIAL','FL_FLAT_BOX','FL_COL1 FL_RIGHT_BCOL','FL_ALIGN_BOTTOM','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('TIMER','FL_DOWN_BOX','FL_COL1 FL_RED','FL_ALIGN_CENTER','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('CLOCK','FL_UP_BOX','FL_INACTIVE_COL FL_BOTTOM_BCOL','FL_ALIGN_BOTTOM','','FL_BLACK','FL_NORMAL_STYLE','FL_FORCE'),
- ('POSITIONER','FL_DOWN_BOX','FL_COL1 FL_RED','FL_ALIGN_BOTTOM','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('FREE','','','','','','FL_NORMAL_STYLE','FL_FORCE'),
- ('XYPLOT','FL_FLAT_BOX','FL_COL1','FL_ALIGN_BOTTOM','','FL_LCOL','FL_NORMAL_STYLE','FL_FORCE'),
- ('FRAME','','FL_BLACK FL_COL1','','','FL_BLACK','FL_NORMAL_STYLE','FL_FORCE'),
- ('LABELFRAME','','','','','','FL_NORMAL_STYLE','FL_FORCE'),
- ('CANVAS','FL_NO_BOX','','FL_ALIGN_TOP','','','FL_NORMAL_STYLE','FL_FORCE'),
- ('GLCANVAS','','','','','','FL_NORMAL_STYLE','FL_FORCE'),
- ('IMAGECANVAS','','','','','','FL_NORMAL_STYLE','FL_FORCE'),
- ('FOLDER','','','','','','FL_NORMAL_STYLE','FL_FORCE'));
- Type
- { object data type }
- PControl = ^TControl;
- TControl = Record
- Props : array[ContProps] of string;
- NextControl : PControl;
- end;
- { Form data type}
- PFormRec = ^TFormRec;
- TFormRec = Record
- Name : String;
- Width,Height : String[5];
- Controls : PControl;
- NextForm : PFormRec;
- end;
- { Callback data type }
- PCBrec = ^TCBrec;
- TCBrec = record
- name : string;
- next : PCBrec;
- end;
- { Property emitting procedures }
- EmitProp = Procedure (Data : PControl;ObjClass : ObjClasses);
- Var
- OptionsSet : Array[1..NrOptions] Of Boolean;
- FileName : String;
- Infile,outfile : Text;
- LineNr : Longint;
- NrForms,NrControls : Longint;
- FormRoot : PFormRec;
- cbroot : pcbrec;
- { Default properties emitters }
- EmitProcs : array [AdjProps] of EmitProp;
- { Class specific property emitters. Nil pointers are ignored.}
- ClassEmitters : Array[ObjClasses] of EmitProp;
- { ------------------------------------------------------------------------
- Utilities Code
- ------------------------------------------------------------------------ }
- Function IntTostr (s : Longint) : String;
- var temp : String;
- begin
- str(s,temp);
- IntToStr:=Temp;
- end;
- Procedure EmitError (Const s : String);
- begin
- writeln (stderr,'Error: ',s);
- flush(stderr)
- end;
- Procedure EmitLineError (Const s : string);
- begin
- EmitError('Line '+IntToStr(LineNr)+': '+s)
- end;
- { ------------------------------------------------------------------------
- Option handling Code
- ------------------------------------------------------------------------ }
- Procedure DoOptions;
- Var i,j,k : byte;
- os : string;
- Procedure ShowVersion;
- begin
- Writeln ('fd2pascal : ',RevString);
- Halt(0);
- end;
- Procedure ShowUsage;
- begin
- Writeln ('fd2pascal : usage :');
- writeln (' fd2pascal [options] filename');
- writeln (' Where [options] may be zero or more of :');
- writeln (' -compensate Emit size-compensation code.');
- writeln (' -altformat Emit code in alternate format.');
- writeln (' -main Emit program instead of unit.');
- writeln (' -callback Emit callback stubs.');
- writeln;
- halt(0);
- end;
- begin
- if paramcount=0 then
- ShowUsage;
- FileName:='';
- for i:=1 to paramcount do
- begin
- if paramstr(i)[1]<>'-' then
- If FileName<>'' then
- EmitError('Only one filename supported. Ignoring :'+paramstr(i))
- else
- Filename:=Paramstr(i)
- else
- begin
- os:=copy(paramstr(i),2,length(paramstr(i))-1);
- k:=NrOptions+1;
- for j:=0 to NrOptions do
- if os=options[j] then k:=j;
- if k=NrOptions+1 then
- EmitError('Option not recognised : '+paramstr(i))
- else
- if k=0 then ShowVersion else OptionsSet[k]:=True;
- end
- end; {for}
- if FileName='' then
- begin
- EmitError('No filename supplied. Exiting.');
- halt(1);
- end;
- end;
- { ------------------------------------------------------------------------
- Code for reading the input file.
- ------------------------------------------------------------------------ }
- Procedure OpenFile;
- begin
- if pos('.fd',FileName)=0 then
- FileName:=FileName+'.fd';
- assign(infile,Filename);
- {$i-}
- reset (infile);
- {$i+}
- if ioresult<>0 then
- begin
- EmitError('Can''t open : '+filename);
- halt(1);
- end;
- LineNr:=0;
- end;
- Procedure CloseFile;
- begin
- Close(infile);
- end;
- Procedure GetLine(Var S : String);
- begin
- inc(LineNr);
- Readln(infile,s);
- {$ifdef debug}
- writeln ('Reading line : ',linenr)
- {$endif}
- end;
- Procedure ProcessPreAmbleLine (Const s: String);
- var key,value : string;
- ppos : Longint;
- i,k : PreProps;
- code : Word;
- begin
- if s='' then exit;
- ppos:=pos(':',s);
- if ppos=0 then
- exit;
- Key:=Copy(s,1,ppos-1);
- Value:=Copy(s,ppos+2,length(s)-ppos-1);
- k:=PPinvalid;
- for i:=PPmagic to PPinvalid do
- if key=PrePropNames[i] then k:=i;
- if k=PPinvalid then
- EmitLineError('Unknown keyword : '+Key)
- else
- Case K of
- PPMagic,
- PPunitofmeasure: ;
- PPnrforms: begin
- val(value,NrForms,code);
- if code<>0 then EmitLineError('Invalid number of forms');
- end;
- end;
- end;
- { ------------------------------------------------------------------------
- Code for reading preamble.
- ------------------------------------------------------------------------ }
- Procedure DoPreamble;
- var line : String;
- begin
- {$ifdef debug}
- writeln ('Starting preamble');
- {$endif}
- Getline (line);
- while pos('= FORM =',line)=0 do
- begin
- ProcessPreAmbleLine(line);
- GetLine(Line)
- end;
- end;
- { ------------------------------------------------------------------------
- Code for reading 1 object.
- ------------------------------------------------------------------------ }
- Procedure ProcessControlLine (PC : PControl; const S : String);
- Var Key,Value : String;
- i,k : ContProps;
- ppos : word;
- begin
- if s='' then exit;
- ppos:=pos(':',s);
- if ppos=0 then
- exit;
- Key:=Copy(s,1,ppos-1);
- Value:=Copy(s,ppos+2,length(s)-ppos-1);
- K:=CPInvalid;
- For i:=CPclass to CPInvalid do
- if ContPropNames[i]=Key then k:=i;
- if K=CPinvalid then
- begin
- EmitLineError('Unknown keyword'+key);
- exit
- end;
- PC^.props[k]:=value;
- end;
- Procedure ProcessControl (PC : PControl);
- var line : String;
- begin
- {$ifdef debug}
- Writeln ('Starting Control');
- {$endif}
- Getline(Line);
- while Line<>'' do
- begin
- ProcessControlLine (PC,line);
- Getline(Line);
- end;
- Getline(Line)
- end;
- { ------------------------------------------------------------------------
- Code for reading 1 form.
- ------------------------------------------------------------------------ }
- Procedure ProcessFormLine (PF : PFormRec; const S : String);
- Var Key,Value : String;
- i,k : FormProps;
- ppos,code : word;
- begin
- if s='' then exit;
- ppos:=pos(':',s);
- if ppos=0 then
- exit;
- Key:=Copy(s,1,ppos-1);
- Value:=Copy(s,ppos+2,length(s)-ppos-1);
- K:=FPInvalid;
- For i:=FPName to FPInvalid do
- if FormPropNames[i]=Key then k:=i;
- if K=FPinvalid then
- begin
- EmitLineError('Unknown keyword'+key);
- exit
- end;
- case k of
- FPname : PF^.name:=value;
- FPWidth : PF^.width:=value;
- FPHeight : PF^.height:=value;
- FPNumObjs : begin
- val(value,Nrcontrols,code);
- If Code<>0 then EmitLineError('Invalid number of objects : '+value)
- end;
- end;
- end;
- Procedure ProcessForm (PF : PFormRec);
- Var line : String;
- CurrentControl : PControl;
- I : Integer;
- begin
- {$ifdef debug}
- writeln('Starting form');
- {$endif}
- NrControls:=0;
- with PF^ do
- begin
- name:='';
- Width:='';
- Height:='';
- Controls:=nil;
- GetLine(Line);
- while line<>'' do
- begin
- ProcessFormLine(PF,Line);
- GetLine(Line);
- end;
- Getline(Line);
- If NrControls=0 then
- Controls:=nil
- else
- begin
- New (Controls);
- CurrentControl:=Controls;
- for i:=1 to nrcontrols do
- begin
- ProcessControl(CurrentControl);
- if i<NrControls then
- New(CurrentControl^.NextControl)
- else
- CurrentControl^.NextControl:=nil;
- CurrentControl:=CurrentControl^.NextControl
- end; { for }
- end; { Else }
- end; { With }
- end;
- { ------------------------------------------------------------------------
- Code for reading the forms.
- ------------------------------------------------------------------------ }
- Procedure DoForms;
- Var
- i : Longint;
- CurrentForm: PformRec;
- begin
- FormRoot:=Nil;
- if NrForms=0 then exit;
- new(FormRoot);
- Currentform:=FormRoot;
- for i:=1 to nrforms do
- begin
- ProcessForm (CurrentForm);
- If i=nrforms then
- Currentform^.NextForm:=nil
- else
- New(CurrentForm^.NextForm);
- CurrentForm:=CurrentForm^.NextForm;
- end;
- end;
- { ------------------------------------------------------------------------
- Code for reading the postamble.
- ------------------------------------------------------------------------ }
- Procedure DoPostamble;
- begin
- end;
- { ------------------------------------------------------------------------
- Code for writing the output file.
- ------------------------------------------------------------------------ }
- Procedure OpenOutFile;
- var info : stat;
- begin
- FileName:=Copy(Filename,1,Length(Filename)-3)+'.pp';
- fstat(FileName,info);
- if linuxerror=0 then
- begin
- { File exists, move to .bak}
- link (FileName,FileName+'.bak');
- unlink (FileName);
- end;
- assign(outfile,filename);
- {$i-}
- rewrite(outfile);
- {$i+}
- if ioresult<>0 then
- begin
- EmitError('Couldn''t open output file : '+filename);
- halt(1)
- end;
- end;
- Procedure CloseOutFile;
- begin
- Close(OutFile);
- end;
- { ------------------------------------------------------------------------
- Code to emit Header/variable/type declarations
- ------------------------------------------------------------------------ }
- Procedure EmitType (fp : Pformrec);
- var cp : PControl;
- begin
- writeln (OutFile,' TFD_',fp^.name,' = record');
- writeln (OutFile,' ',fp^.name,' : PFL_FORM;');
- writeln (OutFile,' vdata : Pointer;');
- writeln (OutFile,' ldata : Longint;');
- cp:=fp^.controls;
- {Skip first control, is formbackground }
- if cp<>nil then cp:=cp^.nextcontrol;
- while cp<>nil do
- begin
- if cp^.props[CPclass]<>'FL_END_GROUP' then
- begin
- write (Outfile,' ',cp^.props[CPname]);
- if cp^.nextcontrol<>nil then
- writeln (OutFile,',')
- else
- writeln (OutFile,' : PFL_OBJECT;');
- end;
- cp:=cp^.nextcontrol;
- end;
- writeln (OutFile,' end;');
- writeln (OutFile,' PFD_',fp^.name,' = ^TFD_',fp^.name,';');
- writeln (OutFile);
- end;
- Procedure EmitVar (fp : Pformrec);
- var cp : PControl;
- begin
- writeln (OutFile,' ',fp^.name,' : PFL_FORM;');
- cp:=fp^.controls;
- {Skip first control, is formbackground }
- if cp<>nil then cp:=cp^.nextcontrol;
- while cp<>nil do
- begin
- if cp^.props[CPclass]<>'FL_END_GROUP' then
- begin
- write (Outfile,' ',cp^.props[CPname]);
- if cp^.nextcontrol<>nil then
- writeln (OutFile,',')
- else
- writeln (OutFile,' : PFL_OBJECT;');
- end;
- cp:=cp^.nextcontrol;
- end;
- writeln (OutFile);
- end;
- Procedure EmitHeader;
- var fp : PFormRec;
- begin
- if OptionsSet[2] then
- write (OutFile,'Program ')
- else
- write (OutFile,'Unit ');
- writeln (OutFile,basename(filename,'.pp'),';');
- writeln (OutFile);
- writeln (OutFile,'{ Form definition file generated by fd2pascal }');
- writeln (Outfile);
- if not OptionsSet[2] then
- begin
- writeln (OutFile,'Interface');
- writeln (OutFile);
- end;
- writeln (OutFile,'Uses forms;');
- writeln (OutFile);
- writeln (OutFile,' { Variable / Type definitions. }');
- if Optionsset[3] then
- writeln (OutFile,'Var')
- else
- writeln (OutFile,'Type');
- fp:=FormRoot;
- While fp<>nil do
- begin
- if not optionsset[3] then
- EmitType(fp) { Emit Type definitions }
- else
- EmitVar(fp); { Emit Variable declaration}
- fp:=fp^.nextform;
- end;
- if not optionsset[2] then
- begin
- { No program, we must emit interface stuff }
- if not (optionsset[3]) then
- begin
- { Emit normal interface declarations
- -> functions }
- fp:=formroot;
- while fp<>nil do
- begin
- with fp^ do
- writeln (OutFile,'Function create_form_',name,' : PFD_',name,';');
- fp:=fp^.nextform;
- end;
- end
- else
- begin
- { Emit alternate interface declaration
- -> 1 function to create all forms.}
- writeln (OutFile,'Procedure Create_The_Forms;');
- end;
- writeln (OutFile);
- writeln (OutFile,'Implementation');
- end
- else
- begin
- { We must make a program. }
- if not(optionsset[3]) then
- begin
- { Normal format, so we need to emit variables for the forms.}
- writeln (OutFile,'Var');
- fp:=formroot;
- while fp<>nil do
- begin
- writeln (OutFile,' ',fp^.name,' : PFD_',fp^.name,';');
- fp:=fp^.nextform;
- end;
- writeln (OutFile);
- end;
- end;
- writeln (OutFile);
- end;
- { ------------------------------------------------------------------------
- Code to emit footer/main program
- ------------------------------------------------------------------------ }
- Procedure EmitCreateforms;
- var fp : PFormRec;
- begin
- writeln (OutFile,'Procedure Create_The_Forms;');
- writeln (OutFile);
- writeln (OutFile,'begin');
- fp:=FormRoot;
- while fp<>nil do
- begin
- writeln(OutFile,'create_form_',fp^.name,';');
- fp:=fp^.nextform;
- end;
- writeln (outFile,'End;');
- writeln (OutFile);
- end;
- Procedure EmitAlternateMain;
- begin
- { Alternate format, we just call creatallforms to create all forms}
- writeln (OutFile,'Create_The_Forms;');
- writeln (OutFile,' fl_show_form(',formroot^.name,
- ',FL_PLACE_CENTER,FL_FULLBORDER,''',
- FormRoot^.name,''');');
- end;
- Procedure EmitMain;
- var fp : PFormRec;
- begin
- { variables are emitted in the header }
- fp:=formroot;
- { Create all forms }
- while fp<>nil do
- begin
- writeln (OutFile,' ',fp^.name,' :=Create_Form_',fp^.name,';');
- fp:=fp^.nextform;
- end;
- { Show the first form }
- writeln (OutFile,' fl_show_form(',formroot^.name,'^.',Formroot^.name,
- ',FL_PLACE_CENTER,FL_FULLBORDER,''',
- FormRoot^.name,''');');
- end;
- Procedure EmitFooter;
- begin
- if OptionsSet[3] then {Alternate format.}
- EmitCreateForms;
- if Optionsset[2] then
- begin
- {Emit Main Program}
- writeln (OutFile);
- writeln (OutFile,'Begin');
- writeln (OutFile,' fl_initialize (@argc,argv,''',
- BaseName(Filename,'.pp'),''',nil,0);');
- if Not(OptionsSet[3]) then
- EmitMain
- else
- EmitAlternateMain;
- writeln (OutFile,' fl_do_forms;');
- end
- else
- writeln (OutFile,'begin');
- writeln (OutFile,'end.')
- end;
- { ------------------------------------------------------------------------
- Code to emit properties
- ------------------------------------------------------------------------ }
- Function EmitString(S : string) : String;
- var temp : String;
- i : longint;
- begin
- temp:='''';
- for i:=1 to length(s) do
- if s[i]<>'''' then temp:=temp+s[i] else temp:=temp+'''''';
- Temp:=temp+'''';
- EmitString:=temp;
- end;
- Procedure EmitBoxtype (cp : PControl;ObjClass : ObjClasses);
- begin
- {$ifdef debug}
- writeln ('EmitBoxType called with args:');
- writeln (cp^.props[cpboxtype]);
- writeln (defprops[objclass,APboxtype]);
- writeln ('for object : ',defprops[objclass,apclass]);
- writeln ('With object : ',cp^.props[cpclass]);
- {$endif}
- if cp^.props[cpboxtype]<>defprops[objclass,APboxtype] then
- writeln (OutFile,' fl_set_object_boxtype(obj,',
- cp^.props[cpboxtype],');')
- end;
- Procedure EmitColors (cp : PControl;ObjClass : ObjClasses);
- var temp : string;
- begin
- if cp^.props[cpcolors]<>defprops[objclass,APcolors] then
- begin
- temp:=cp^.props[cpcolors];
- if pos(' ',temp)=0 then exit;
- temp[pos(' ',temp)]:=',';
- writeln (OutFile,' fl_set_object_color(obj,',temp,');');
- end;
- end;
- Procedure EmitAlignment (cp : PControl;ObjClass : ObjClasses);
- begin
- if cp^.props[cpalignment]<>defprops[objclass,APalignment] then
- writeln (OutFile,' fl_set_object_alignment(obj,',
- cp^.props[cpalignment],');');
- end;
- Procedure EmitLcol (cp : PControl;ObjClass : ObjClasses);
- begin
- if cp^.props[cplcol]<>defprops[objclass,APlcol] then
- writeln (OutFile,' fl_set_object_lcol(obj,',
- cp^.props[cplcol],');');
- end;
- Procedure EmitSize (cp : PControl;ObjClass : ObjClasses);
- begin
- if cp^.props[cpsize]<>defprops[objclass,APsize] then
- writeln (OutFile,' fl_set_object_lsize(obj,',
- cp^.props[cpsize],');');
- end;
- Procedure EmitStyle (cp : PControl;ObjClass : ObjClasses);
- begin
- if cp^.props[cpstyle]<>defprops[objclass,APstyle] then
- writeln (OutFile,' fl_set_object_lstyle(obj,',
- cp^.props[cpstyle],');');
- end;
- Procedure EmitGravity (cp : PControl;ObjClass : ObjClasses);
- var temp: string;
- begin
- if cp^.props[cpstyle]<>'FL_NoGravity FL_NoGravity' then
- begin
- temp:=cp^.props[cpstyle];
- if pos(' ',temp)=0 then exit;
- temp[pos(' ',temp)]:=',';
- writeln (OutFile,' fl_set_object_gravity(obj,',
- temp,');');
- end;
- end;
- Procedure EmitProperties (Cp : PControl; Objclass : ObjClasses);
- Var i : AdjProps;
- begin
- for i:=APboxtype to APgravity do
- if DefProps[ObjClass,i]<>'' then
- EmitProcs[i](cp,objclass);
- end;
- { ------------------------------------------------------------------------
- Code to emit objects
- ------------------------------------------------------------------------ }
- Procedure EmitObject(cp : PControl);
- var temp : string;
- I : Longint;
- j,k : ObjClasses;
- begin
- with cp^ do
- begin
- temp:=lowercase(props[CPclass]);
- delete(temp,1,3);
- if temp='begin_group' then
- begin
- writeln (OutFile);
- write (OutFile,' ');
- if not (Optionsset[3]) then Write (OutFile,'fdui^.');
- writeln (OutFile,props[cpname],':=fl_bgn_group;');
- exit;
- end
- else if temp='end_group' then
- begin
- writeln (OutFile,' fl_end_group;');
- writeln (OutFile);
- exit;
- end;
- { Normal object. Emit creation code. }
- write (OutFile,' obj:=fl_add_',temp,' (FL_',props[Cptype],',');
- temp:=props[cpbox];
- for i:=1 to 3 do
- begin
- write (OutFile,copy(temp,1,pos(' ',temp)-1),',');
- delete (temp,1,pos(' ',temp));
- end;
- writeln (OutFile,temp,',',EmitString(props[cplabel]),');');
- { Emit Callback code if needed }
- if props[cpcallback]<>'' then
- begin
- write (OutFile,' fl_set_object_callback(obj,PFL_CALLBACKPTR(@');
- write (OutFile,props[CPcallback],'),');
- if props[CPargument]<>'' then
- writeln (OutFile,props[CPargument],');')
- else
- writeln (OutFile,'0);');
- end;
- { If known object, start emitting properties }
- temp:=props[CPclass];
- delete(temp,1,3);
- k:=FL_INVALID;
- for j:=FL_BUTTON to FL_FOLDER do
- if temp=DefProps[j,apclass] then k:=j;
- if k<>FL_INVALID then
- begin
- { Emit defaults }
- EmitProperties (cp,k);
- { If A class-specific emitter exists, call it.}
- if Assigned(ClassEmitters[k]) then
- ClassEmitters[k] (cp,k);
- end;
- { Assign to needed object. }
- if Optionsset[3] then
- Writeln (OutFile,' ',props[cpname],':=obj;')
- else
- Writeln (OutFile,' fdui^.',props[cpname],':=obj;');
- end;
- end;
- { ------------------------------------------------------------------------
- Code to emit forms
- ------------------------------------------------------------------------ }
- Procedure EmitForm(fp : PFormRec);
- Var
- cp : PControl;
- begin
- with fp^ do
- begin
- if Optionsset[3] then
- begin
- writeln (OutFile,'Procedure create_form_',name,';');
- writeln (OutFile);
- writeln (OutFile,'Var obj : PFL_OBJECT;');
- writeln (OutFile);
- writeln (OutFile,'Begin');
- writeln (OutFile,' If ',name,'<>nil then exit;');
- write (OutFile,' ',name);
- end
- else
- begin
- writeln (OutFile,'Function create_form_',name,' : PFD_',name,';');
- writeln (OutFile);
- writeln (OutFile,'Var obj : PFL_OBJECT;');
- writeln (OutFile,' fdui : PFD_',name,';');
- writeln (OutFile);
- writeln (OutFile,'Begin');
- writeln (OutFile,' New(fdui);');
- write (OutFile,' fdui^.',name);
- end;
- writeln (OutFile,':=fl_bgn_form(FL_NO_BOX,'
- ,width,','
- ,height,');');
- cp:=controls;
- writeln (OutFile,' obj:=fl_add_box(',cp^.props[CPboxtype],',0,0,',
- width,',',
- height,',',
- EmitString (cp^.props[CPname]),');');
- cp:=cp^.nextcontrol;
- { Emit all objects }
- while cp<>nil do
- begin
- EmitObject(cp);
- cp:=cp^.nextcontrol;
- end;
- writeln (OutFile,' fl_end_form;');
- if Optionsset[4] then
- begin
- { Emit Compensation code }
- write (OutFile,' fl_adjust_form_size(');
- if not(OptionsSet[3]) then write (OutFile,'fdui^.');
- writeln(OutFile,fp^.name,');');
- end;
- if not(OptionsSet[3]) then
- begin
- writeln (OutFile,' fdui^.',fp^.name,'^.fdui:=fdui;');
- writeln (OutFile,' create_form_',fp^.name,':=fdui;');
- end;
- writeln (OutFile,'end;');
- writeln (OutFile);
- end;
- end;
- Procedure EmitForms;
- var
- fp : PformRec;
- begin
- { Start emitting forms }
- fp:=Formroot;
- while fp<>nil do
- begin
- EmitForm(fp);
- fp:=fp^.nextform;
- end;
- end;
- { ------------------------------------------------------------------------
- Code to emit callbacks
- ------------------------------------------------------------------------ }
- Procedure CollectCallbacks;
- Var CurrentCb,CBwalk : PCBrec;
- fp : PformRec;
- cp : PControl;
- begin
- CbRoot:=nil;
- CurrentCB:=cbroot;
- fp:=formroot;
- while fp<>nil do
- begin
- cp:=fp^.controls;
- while cp<>nil do
- begin
- if cp^.props[CPcallback]<>'' then
- if cbroot<>nil then
- begin
- cbwalk:=cbroot;
- while cbwalk<>nil do
- if upcase(cbwalk^.name)=upcase(cp^.props[CPcallback]) then
- break
- else
- cbwalk:=cbwalk^.next;
- if cbwalk=nil then
- begin
- new(currentcb^.next);
- currentcb:=currentcb^.next;
- currentcb^.name:=cp^.props[CPcallback];
- currentcb^.next:=nil;
- end;
- end
- else
- begin
- new(cbroot);
- currentcb:=cbroot;
- cbroot^.name:=cp^.props[CPcallback];
- cbroot^.next:=nil;
- end;
- cp:=cp^.nextcontrol;
- end;
- fp:=fp^.nextform;
- end;
- end;
- Procedure EmitCallback (Const s : string);
- begin
- writeln (OutFile,'Procedure ',s,' (Sender: PFL_OBJECT; Data : Longint); export;');
- writeln (OutFile);
- writeln (OutFile,'begin');
- writeln (OutFile,' { Place your code here }');
- writeln (OutFile,'end;');
- writeln (OutFile);
- end;
- Procedure EmitCallBacks;
- var cb : pcbrec;
- begin
- { See if we must emit callback stubs }
- If Optionsset[1] then
- begin
- cb:=cbroot;
- while cb<>nil do
- begin
- EmitCallBack(cb^.Name);
- cb:=cb^.next;
- end;
- end;
- end;
- { ------------------------------------------------------------------------
- EmitterTable initialization Code
- ------------------------------------------------------------------------ }
- Procedure EmitDummy (cp : PControl;ObjClass : ObjClasses);
- begin
- end;
- Procedure InitEmitters;
- var i : objclasses;
- begin
- EmitProcs[APClass]:=@EmitDummy;
- EmitProcs[APBoxtype]:=@EmitBoxType;
- EmitProcs[APColors]:=@EmitColors;
- EmitProcs[APAlignment]:=@EmitAlignment;
- EmitProcs[APlcol]:=@EmitLcol;
- EmitProcs[APsize]:=@EmitSize;
- EmitProcs[APStyle]:=@EmitStyle;
- EmitProcs[APgravity]:=@EmitGravity;
- for i:=FL_INVALID to FL_FOLDER do
- ClassEmitters[i]:=EmitProp(Nil);
- end;
- { ------------------------------------------------------------------------
- Main program Code
- ------------------------------------------------------------------------ }
- begin
- { Process options }
- DoOptions;
- { Read input file }
- OpenFile;
- DoPreamble;
- DoForms;
- DoPostamble;
- CloseFile;
- { Write output file }
- OpenOutfile;
- InitEmitters;
- CollectCallbacks;
- EmitHeader;
- EmitCallbacks;
- EmitForms;
- EmitFooter;
- CloseOutFile;
- end. $Log$
- end. Revision 1.4 2001-04-08 12:27:55 peter
- end. * made it compilable with both 1.0.x and 1.1
- end.
- end. Revision 1.3 2001/01/21 21:38:52 marco
- end. * renamefest in packages
- end.
- end. Revision 1.2 2000/07/13 11:33:11 michael
- end. + removed logs
- end.
- }
|