Пишем программу для создания книг FB2
Шрифт:
GroupBox1: TGroupBox;
GenresBox: TListBox;
Button4: TButton;
GroupBox3: TGroupBox;
ListBox2: TListBox;
Button7: TButton;
sequence: TEdit;
tome: TEdit;
Lang: TComboBox;
SLang: TComboBox;
Button9: TButton;
GroupBox2: TGroupBox;
Button1: TButton;
Button2: TButton;
Button5: TButton;
procedure Open1Click(Sender: TObject);
procedure SaveasFB21Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Path: ANSIstring;
implementation
uses EditStr;
{$R *.dfm}
procedure LoadTXT(FName: string);
var
L: TStringList;
i, j: integer;
s, ss: string;
begin
L:= TStringList.Create;
L.LoadFromFile(fname);
for i:= 0 to L.Count - 1 do
begin
s:= ''; ss:= L[i];
for j:= 1 to length(Ss) do
begin //
case ss[j] of
'<': S:= S + '<'; // знак < вызывает сбой в читалке
'>': S:= S + '>'; // заменяем, на всякий случай
'^': S:= S + '^'; //
'~': S:= S + '~';
'&': S:= S + '&';
else S:= S + ss[j];
end; // case
end;
L[i]:= ' N| ' + S;
end;
Form1.ListBox1.Items.Assign(L);
L.Free;
end;
procedure NameFB2_File(S: string);
begin //
S:= ExtractFileName(S);
Form1.Caption:= S;
Form1.FB2_file.Text:= ChangeFileExt(S,'.fb2');
end;
procedure TForm1.Open1Click(Sender: TObject);
begin
with OpenDialog1 do
if Execute then
begin
NameFB2_File(FileName);
ListBox1.Clear;
LoadTXT(FileName); // txt
end;
end;
function GetGaner(S: string):string;
var
i: integer;
begin
for i:= 0 to maxg do
if gg[i][2] = S then
begin
result:= gg[i][1];
exit;
end;
result:= s;
end;
procedure SaveAnnotation;
var
i: integer;
begin
OutList.Add('<annotation>');
with form1.Annotation do
for i:= 0 to Lines.Count - 1 do
OutList.Add(''+Lines[i]+'');
OutList.Add('</annotation>');
end;
procedure SavePersons(title: string; LB: TListBox);
var
i: integer;
Person: TPerson;
begin
with LB do
if Count > 0 then
for i:= 0 to Count - 1 do
begin
Person:= TPerson(Items.Objects[i]);
OutList.Add(' <'+title+'>');
with Person do
begin
PrintString('first-name',fname);
PrintString('last-name',lname);
PrintString('middle-name',mname);
PrintString('nick',nick);
PrintString('email',email);
end;
OutList.Add(' </'+title+'>');
end;
end;
procedure SaveSequence;
var
s: string;
begin
with Form1 do
begin
if sequence.Text = '' then exit;
S:= '<sequence name="' +sequence.Text+'"';
if tome.Text = ''
then S:= S + '/>'
else S:= S + ' number="'+tome.Text+'"/>';
end;
OutList.Add(S);
end;
procedure SaveDescription;
const
max = 5;
mas: array[1..max] of string =
(
'<?xml version="1.0" encoding="windows-1251"?>',
'<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0"',
' xmlns: l="http://www.w3.org/1999/xlink">',
' <description>',
' <title-info>'
);
var
i: byte;
S: string;
begin
// head
for i:= 1 to max do
OutList.Add(Mas[i]);
with form1.GenresBox do
if Items.Count > 0 then
for i:= 0 to Items.Count - 1 do
OutList.Add('<genre>'+GetGaner(Items[i])+'</genre>');
SavePersons('author',Form1.ListBox3);
SavePersons('translator',Form1.ListBox2);
with Form1 do
begin
PrintString('book-title',book_title.text);
if Annotation.Lines.Count > 0
then SaveAnnotation;
//if _date.text <> '' then
//OutList.Add('<date value="'+_date.text+'-01-01">'+_date.text+'</date>');
SaveSequence;