playfair

Playfair Script Formatter
git clone https://git.mulligrubs.me/playfair
Log | Files | Refs | README

commit 1838f8eb395e4b9944209693d1248008390ed658
parent 5e23f97731f908dfc924a09bc3db75c8374155e9
Author: Saint Cassian <git@stjohnkarp.net>
Date:   Sat,  3 Sep 2011 20:52:21 -0700

Playfair

I edited the play formatter to work in a web interface and officially
titled it Playfair.  This commit adds in the PHP script that calls it
and the CSS, which will be tracked here from now on.

Diffstat:
Dplay.pl | 139-------------------------------------------------------------------------------
Aplayfair.pl | 149+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascript.php | 14++++++++++++++
Ascriptfrenzy.css | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 224 insertions(+), 139 deletions(-)

diff --git a/play.pl b/play.pl @@ -1,139 +0,0 @@ -play_to_html(File):- - consult('/home/stjohn/XML/xmlprint-1.0.pl'), - open(File, read, In), - process_file(In, Play), - close(In), - play(HTML, Play, []), - xml_print(HTML), - atom_concat(File, '.html', OutFile), - open(OutFile, write, Out), - xml_write(Out, HTML, []), - close(Out). - - -play([element(html, [], - [element(head, [], Head), - element(body, [], [element(h1, [], Title)|Text])])]) - --> head(Head), double_break, body(Body), double_break, end(End), single_break, - {member(element(title, [], Title), Head), append(Body, [End], Text)}. - - -body(Scene) --> scene(Scene). - -body(Scene) --> scene(Scene1), double_break, body(Body), - {append(Scene1, Body, Scene)}. - - -scene(Scene) --> act(Act), double_break, scene_directions(SceneDirections), double_break, block_repeater(Block), - {append([Act|SceneDirections], Block, Scene)}. - - -block_repeater(Repeater) --> block(Block1), double_break, block_repeater(Block2), - {append(Block1, Block2, Repeater)}. - -block_repeater(Block) --> block(Block). - - -block([Character, CharacterStageDirections, Dialogue]) --> character(Character), single_break, character_stage_directions(CharacterStageDirections), single_break, dialogue(Dialogue). - -block([StageDirections]) --> stage_directions(StageDirections). - -block([Character, Dialogue]) --> character(Character), single_break, dialogue(Dialogue). - - -scene_directions([element(p, [class = sceneDirections], [Text])]) --> text(['\n', <], Text). - -scene_directions([element(p, [class = sceneDirections], [Text])|SceneDirections]) --> text(['\n', <], Text), line_break(_), scene_directions(SceneDirections). - - -stage_directions(element(p, [class = stageDirections], [Text])) --> text(['\n'], Text). - - -character(element(p, [class = character], [Text])) --> text(['\n'], Text). - - -dialogue(element(p, [class = dialogue], Line)) --> dialogue_line(Line). - -dialogue(element(p, [class = dialogue], Dialogue)) --> dialogue_line(Line), single_break, dialogue(element(p, [class = dialogue], Dialogue1)), - {append(Line, [element(br, [], [])|Dialogue1], Dialogue)}. - - -dialogue_line([Unit]) --> dialogue_unit(Unit). - -dialogue_line([Unit|Dialogue]) --> dialogue_unit(Unit), dialogue(element(p, [class = dialogue], Dialogue)). - - -dialogue_unit(Text) --> text(['\n', <, >, '(', ')'], Text). - -dialogue_unit(Italic) --> italic(Italic). - -dialogue_unit(CDD) --> character_directions(CDD). - - -character_stage_directions(element(p, [class = characterStageDirections], ['(', Text, ')'])) --> ['('], text(['\n', <, >, ')'], Text), [')']. - - -italic(element(em, [], [Text])) --> [<, e, m, >], text(['\n', <, >, '(', ')'], Text), [<, '/', e, m, >]. - -italic(element(em, [], [Text])) --> [<, i, >], text(['\n', <, >, '(', ')'], Text), [<, '/', i, >]. - - -character_directions(element(span, [class = characterDirections], ['(', Text, ')'])) --> ['('], text(['\n', <, >, '(', ')'], Text), [')']. - - -head([Styles|Tags]) --> styles(Styles), sisu_repeater(Tags). - - -sisu_repeater([Tag]) --> sisu_tag(Tag). - -sisu_repeater([Tag|Tags]) --> sisu_tag(Tag), double_break, sisu_repeater(Tags). - - -sisu_tag(element(title, [], [Text])) --> ['@', t, i, t, l, e, ':', ' '], text(['\n'], Text). - - -styles(element(link, [rel = 'stylesheet', type = 'text/css', href = '/Data/styles/scriptfrenzy.css'], [])) --> []. - - -single_break --> ['\n']. - - -double_break --> ['\n', '\n']. - - -line_break([element(br, [], [])]) --> [<, b, r, '/', >]. - -line_break([element(br, [], [])|Break]) --> [<, b, r, '/', >], line_break(Break). - - -act(element(h3, [class = actScene], ['A', 'C', 'T', Text])) --> ['A', 'C', 'T'], text(['\n'], Text). - - -end(element(p, [class = end], ['The End.'])) --> ['T', 'h', 'e', ' ', 'E', 'n', 'd', '.']. - - -text(Forbidden, Text) --> no_funny_business(Forbidden, Text). - - -no_funny_business(Forbidden, Text, List, Rest):- - not(List = ['A', 'C', 'T'|_]), - forbidden_fruit(Forbidden, List, CharList), - not(CharList = []), - atom_chars(Text, CharList), - append(CharList, Rest, List). - - -forbidden_fruit(Forbidden, [First|_], []):- - member(First, Forbidden). - -forbidden_fruit(Forbidden, [First|Rest], [First|List]):- - not(member(First, Forbidden)), - forbidden_fruit(Forbidden, Rest, List). - - -process_file(File, []):- - peek_char(File, end_of_file). - -process_file(File, [Letter|List]):- - get_char(File, Letter), - process_file(File, List). diff --git a/playfair.pl b/playfair.pl @@ -0,0 +1,149 @@ +%-------------------------------------------------------- +% +% Filename: playfair.pl +% Author: St John Karp +% Date: 3 September 2011 +% Version: 1.0 +% +% Purpose: +% A program to format stage play scripts. +% +% Copyright: +% Playfair Script Formatter by St John Karp is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. +% +%------------------------------------------------------- + +play_to_html(File):- + open(File, read, In, [encoding(utf8)]), + process_file(In, Play), + close(In), + play(HTML, Play, []), + xml_write(HTML, [header(false)]). + + +play([element(html, [], + [element(head, [], Head), + element(body, [], [element(h1, [], Title)|Text])])]) + --> head(Head), double_break, body(Body), double_break, end(End), single_break, + {member(element(title, [], Title), Head), append(Body, [End], Text)}. + + +body(Scene) --> scene(Scene). + +body(Scene) --> scene(Scene1), double_break, body(Body), + {append(Scene1, Body, Scene)}. + + +scene(Scene) --> act(Act), double_break, scene_directions(SceneDirections), double_break, island_repeater(Island), + {append([Act|SceneDirections], Island, Scene)}. + + +island_repeater(Repeater) --> island(Island1), double_break, island_repeater(Island2), + {append(Island1, Island2, Repeater)}. + +island_repeater(Island) --> island(Island). + + +island([Character, CharacterStageDirections, Dialogue]) --> character(Character), single_break, character_stage_directions(CharacterStageDirections), single_break, dialogue(Dialogue). + +island([StageDirections]) --> stage_directions(StageDirections). + +island([Character, Dialogue]) --> character(Character), single_break, dialogue(Dialogue). + + +scene_directions([element(p, [class = sceneDirections], [Text])]) --> text(['\n', <], Text). + +scene_directions([element(p, [class = sceneDirections], [Text])|SceneDirections]) --> text(['\n', <], Text), line_break(_), scene_directions(SceneDirections). + + +stage_directions(element(p, [class = stageDirections], [Text])) --> text(['\n'], Text). + + +character(element(p, [class = character], [Text])) --> text(['\n'], Text). + + +dialogue(element(p, [class = dialogue], Line)) --> dialogue_line(Line). + +dialogue(element(p, [class = dialogue], Dialogue)) --> dialogue_line(Line), single_break, dialogue(element(p, [class = dialogue], Dialogue1)), + {append(Line, [element(br, [], [])|Dialogue1], Dialogue)}. + + +dialogue_line([Unit]) --> dialogue_unit(Unit). + +dialogue_line([Unit|Dialogue]) --> dialogue_unit(Unit), dialogue(element(p, [class = dialogue], Dialogue)). + + +dialogue_unit(Text) --> text(['\n', <, >, '(', ')'], Text). + +dialogue_unit(Italic) --> italic(Italic). + +dialogue_unit(CDD) --> character_directions(CDD). + + +character_stage_directions(element(p, [class = characterStageDirections], ['(', Text, ')'])) --> ['('], text(['\n', <, >, ')'], Text), [')']. + + +italic(element(em, [], [Text])) --> [<, e, m, >], text(['\n', <, >, '(', ')'], Text), [<, '/', e, m, >]. + +italic(element(em, [], [Text])) --> [<, i, >], text(['\n', <, >, '(', ')'], Text), [<, '/', i, >]. + + +character_directions(element(span, [class = characterDirections], ['(', Text, ')'])) --> ['('], text(['\n', <, >, '(', ')'], Text), [')']. + + +head([Charset, Styles, Title]) --> meta_charset(Charset), styles(Styles), title(Title). + + +title(element(title, [], [Text])) --> text(['\n'], Text). + + +styles(element(link, [rel = 'stylesheet', type = 'text/css', href = '/scriptfrenzy.css'], [])) --> []. + + +meta_charset(element(meta, [charset = 'utf-8'], [])) --> []. + + +single_break --> ['\n']. + + +double_break --> ['\n', '\n']. + + +line_break([element(br, [], [])]) --> [<, b, r, '/', >]. + +line_break([element(br, [], [])|Break]) --> [<, b, r, '/', >], line_break(Break). + + +act(element(h3, [class = actScene], ['A', 'C', 'T', Text])) --> ['A', 'C', 'T'], text(['\n'], Text). + +act(element(h3, [class = actScene], ['A', 'C', 'T', Text])) --> ['A', 'c', 't'], text(['\n'], Text). + + +end(element(p, [class = end], ['The End.'])) --> ['T', 'h', 'e', ' ', 'E', 'n', 'd', '.']. + + +text(Forbidden, Text) --> no_funny_business(Forbidden, Text). + + +no_funny_business(Forbidden, Text, List, Rest):- + not(List = ['A', 'C', 'T'|_]), + forbidden_fruit(Forbidden, List, CharList), + not(CharList = []), + atom_chars(Text, CharList), + append(CharList, Rest, List). + + +forbidden_fruit(Forbidden, [First|_], []):- + member(First, Forbidden). + +forbidden_fruit(Forbidden, [First|Rest], [First|List]):- + not(member(First, Forbidden)), + forbidden_fruit(Forbidden, Rest, List). + + +process_file(File, []):- + peek_char(File, end_of_file). + +process_file(File, [Letter|List]):- + get_char(File, Letter), + process_file(File, List). diff --git a/script.php b/script.php @@ -0,0 +1,14 @@ +<?php +if (($_FILES["file"]["type"] == "text/plain") +&& ($_FILES["file"]["size"] < 1000000)) { + if ($_FILES["file"]["error"] > 0) { + echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; + } + else { + system("swipl -s playfair.pl -g \"play_to_html('".$_FILES["file"]["tmp_name"]."')\""); + } +} +else { + echo "Invalid file"; +} +?> diff --git a/scriptfrenzy.css b/scriptfrenzy.css @@ -0,0 +1,61 @@ +body { + font-size: 12pt; +} + +h1,h2#author { + text-align: center; +} + +h3.actScene { + font-size: 1em; + font-weight: bold; + page-break-before: always; + text-align: center; +} + +hr.page { + page-break-after: always; + width: 0; +} + +p { + margin-top: 0; +} + +p.character { + text-align: center; + margin-bottom: 0.04in; +} + +p.dialogue { + margin-bottom: 0.22in; +} + +p.end { + font-weight: bold; + text-align: center; +} + +p.sceneDirections { + font-style: italic; + margin-left: 2in; + margin-right: 1in; + margin-bottom: 0.08in; +} + +p.stageDirections { + font-style: italic; + margin-bottom: 0.22in; + margin-left: 1in; + margin-right: 1in; +} + +span.characterDirections { + font-style: italic; +} + +p.characterStageDirections { + font-style: italic; + text-align: center; + margin-bottom: 0.04in; +}