diff options
-rw-r--r-- | libstorycode/scparse_priv.h | 4 | ||||
-rw-r--r-- | libstorycode/slide.c | 12 | ||||
-rw-r--r-- | libstorycode/slide.h | 2 | ||||
-rw-r--r-- | libstorycode/storycode.y | 51 | ||||
-rw-r--r-- | meson.build | 55 | ||||
-rw-r--r-- | src-old/colloquium.c (renamed from src/colloquium.c) | 0 | ||||
-rw-r--r-- | src-old/colloquium.h (renamed from src/colloquium.h) | 0 | ||||
-rw-r--r-- | src-old/debugger.c (renamed from src/debugger.c) | 0 | ||||
-rw-r--r-- | src-old/debugger.h (renamed from src/debugger.h) | 0 | ||||
-rw-r--r-- | src-old/frame.c (renamed from src/frame.c) | 0 | ||||
-rw-r--r-- | src-old/frame.h (renamed from src/frame.h) | 0 | ||||
-rw-r--r-- | src-old/imagestore.c (renamed from src/imagestore.c) | 0 | ||||
-rw-r--r-- | src-old/imagestore.h (renamed from src/imagestore.h) | 0 | ||||
-rw-r--r-- | src-old/narrative_window.c (renamed from src/narrative_window.c) | 0 | ||||
-rw-r--r-- | src-old/narrative_window.h (renamed from src/narrative_window.h) | 0 | ||||
-rw-r--r-- | src-old/pr_clock.c (renamed from src/pr_clock.c) | 0 | ||||
-rw-r--r-- | src-old/pr_clock.h (renamed from src/pr_clock.h) | 0 | ||||
-rw-r--r-- | src-old/presentation.c (renamed from src/presentation.c) | 0 | ||||
-rw-r--r-- | src-old/presentation.h (renamed from src/presentation.h) | 0 | ||||
-rw-r--r-- | src-old/print.c (renamed from src/print.c) | 0 | ||||
-rw-r--r-- | src-old/print.h (renamed from src/print.h) | 0 | ||||
-rw-r--r-- | src-old/render.c (renamed from src/render.c) | 0 | ||||
-rw-r--r-- | src-old/render.h (renamed from src/render.h) | 0 | ||||
-rw-r--r-- | src-old/sc_editor.c (renamed from src/sc_editor.c) | 0 | ||||
-rw-r--r-- | src-old/sc_editor.h (renamed from src/sc_editor.h) | 0 | ||||
-rw-r--r-- | src-old/sc_interp.c (renamed from src/sc_interp.c) | 0 | ||||
-rw-r--r-- | src-old/sc_interp.h (renamed from src/sc_interp.h) | 0 | ||||
-rw-r--r-- | src-old/sc_parse.c (renamed from src/sc_parse.c) | 0 | ||||
-rw-r--r-- | src-old/sc_parse.h (renamed from src/sc_parse.h) | 0 | ||||
-rw-r--r-- | src-old/slide_window.c (renamed from src/slide_window.c) | 0 | ||||
-rw-r--r-- | src-old/slide_window.h (renamed from src/slide_window.h) | 0 | ||||
-rw-r--r-- | src-old/slideshow.c (renamed from src/slideshow.c) | 0 | ||||
-rw-r--r-- | src-old/slideshow.h (renamed from src/slideshow.h) | 0 | ||||
-rw-r--r-- | src-old/stylesheet.c (renamed from src/stylesheet.c) | 0 | ||||
-rw-r--r-- | src-old/stylesheet.h (renamed from src/stylesheet.h) | 0 | ||||
-rw-r--r-- | src-old/stylesheet_editor.c (renamed from src/stylesheet_editor.c) | 0 | ||||
-rw-r--r-- | src-old/stylesheet_editor.h (renamed from src/stylesheet_editor.h) | 0 | ||||
-rw-r--r-- | src-old/testcard.c (renamed from src/testcard.c) | 0 | ||||
-rw-r--r-- | src-old/testcard.h (renamed from src/testcard.h) | 0 | ||||
-rw-r--r-- | src-old/utils.c (renamed from src/utils.c) | 0 | ||||
-rw-r--r-- | src-old/utils.h (renamed from src/utils.h) | 0 | ||||
-rw-r--r-- | src/pdfstorycode.c (renamed from src/sc2_test.c) | 13 | ||||
-rw-r--r-- | tests/meson.build | 42 |
43 files changed, 112 insertions, 67 deletions
diff --git a/libstorycode/scparse_priv.h b/libstorycode/scparse_priv.h index 51d0d8a..54dca40 100644 --- a/libstorycode/scparse_priv.h +++ b/libstorycode/scparse_priv.h @@ -34,6 +34,10 @@ struct scpctx Stylesheet *ss; Slide *s; + int n_str; + int max_str; + char **str; + /* Frame options */ struct frame_geom geom; }; diff --git a/libstorycode/slide.c b/libstorycode/slide.c index 28ca159..6ff5691 100644 --- a/libstorycode/slide.c +++ b/libstorycode/slide.c @@ -27,12 +27,17 @@ #include <stdlib.h> #include <string.h> +#include <stdio.h> #include "slide.h" enum slide_item_type { SLIDE_ITEM_TEXT, + SLIDE_ITEM_IMAGE, + SLIDE_ITEM_FOOTER, + SLIDE_ITEM_SLIDETITLE, + SLIDE_ITEM_PRESTITLE, }; @@ -82,8 +87,13 @@ int slide_add_image(Slide *s, char *filename, struct frame_geom geom) } -int slide_add_text(Slide *s, char *text, struct frame_geom geom) +int slide_add_text(Slide *s, char **text, int n_text, struct frame_geom geom) { + int i; + printf("got text:\n"); + for ( i=0; i<n_text; i++ ) { + printf("%3i: '%s'\n", i, text[i]); + } return 0; } diff --git a/libstorycode/slide.h b/libstorycode/slide.h index 2c0607f..c9be25a 100644 --- a/libstorycode/slide.h +++ b/libstorycode/slide.h @@ -45,7 +45,7 @@ extern void slide_free(Slide *s); extern int slide_add_prestitle(Slide *s, char *prestitle); extern int slide_add_image(Slide *s, char *filename, struct frame_geom geom); -extern int slide_add_text(Slide *s, char *text, struct frame_geom geom); +extern int slide_add_text(Slide *s, char **text, int n_text, struct frame_geom geom); extern int slide_add_footer(Slide *s); extern int slide_add_slidetitle(Slide *s, char *slidetitle); diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y index 654dec3..433b158 100644 --- a/libstorycode/storycode.y +++ b/libstorycode/storycode.y @@ -44,6 +44,7 @@ %{ #include <stdio.h> + #include <stdlib.h> extern int sclex(); extern int scparse(); @@ -75,10 +76,8 @@ %type <ss> stylesheet %type <str> prestitle %type <str> STRING -%type <str> textframe %type <str> imageframe %type <str> bulletpoint -%type <str> multi_line_string %type <str> frameopt %type <str> geometry /* FIXME: Should have its own type */ %type <str> slidetitle @@ -93,12 +92,33 @@ ctx->n = narrative_new(); ctx->ss = stylesheet_new(); ctx->s = slide_new(); + + ctx->n_str = 0; + ctx->max_str = 32; + ctx->str = malloc(ctx->max_str*sizeof(char *)); + if ( ctx->str == NULL ) ctx->max_str = 0; } %{ void frameopts_reset(struct scpctx *ctx) { } + + void str_reset(struct scpctx *ctx) + { + ctx->n_str = 0; + } + + void add_str(struct scpctx *ctx, char *str) + { + if ( ctx->n_str == ctx->max_str ) { + char **nstr = realloc(ctx->str, (ctx->max_str+32)*sizeof(char *)); + if ( nstr == NULL ) return; + ctx->max_str += 32; + } + + ctx->str[ctx->n_str++] = str; + } %} %% @@ -148,11 +168,15 @@ slide_parts: ; slide_part: - prestitle { slide_add_prestitle(ctx->s, $1); } -| imageframe { slide_add_image(ctx->s, $1, ctx->geom); frameopts_reset(ctx); } -| textframe { slide_add_text(ctx->s, $1, ctx->geom); frameopts_reset(ctx); } + prestitle { slide_add_prestitle(ctx->s, $1); str_reset(ctx); } +| imageframe { slide_add_image(ctx->s, $1, ctx->geom); + frameopts_reset(ctx); + str_reset(ctx); } +| textframe { slide_add_text(ctx->s, ctx->str, ctx->n_str, ctx->geom); + frameopts_reset(ctx); + str_reset(ctx); } | FOOTER { slide_add_footer(ctx->s); } -| slidetitle { slide_add_slidetitle(ctx->s, $1); } +| slidetitle { slide_add_slidetitle(ctx->s, $1); str_reset(ctx); } ; imageframe: @@ -160,14 +184,15 @@ imageframe: ; textframe: - TEXTFRAME frame_options multi_line_string { printf("text frame '%s'\n", $3); } -| TEXTFRAME frame_options OPENBRACE multi_line_string CLOSEBRACE { printf("text frame m\n"); } + TEXTFRAME frame_options multi_line_string { } +| TEXTFRAME frame_options OPENBRACE multi_line_string CLOSEBRACE { } +; multi_line_string: - STRING { printf("string '%s'\n", $1); } -| multi_line_string STRING { printf("more string '%s'\n", $2); } -| bulletpoint { printf("string *%s\n", $1); } -| multi_line_string bulletpoint { printf("more string *%s\n", $1); } + STRING { add_str(ctx, $1); } +| multi_line_string STRING { add_str(ctx, $2); } +| bulletpoint { add_str(ctx, $1); } +| multi_line_string bulletpoint { add_str(ctx, $2); } ; /* There can be any number of options */ @@ -178,7 +203,7 @@ frame_options: /* Each option is enclosed in square brackets */ frame_option: - SQOPEN frameopt SQCLOSE { printf("got an option: '%s'\n", $2); } + SQOPEN frameopt SQCLOSE { } ; frameopt: diff --git a/meson.build b/meson.build index c99fb01..ee790d0 100644 --- a/meson.build +++ b/meson.build @@ -19,7 +19,8 @@ subdir('po') # Dependencies gtkdep = dependency('gtk+-3.0') -jsondep = dependency('json-glib-1.0') +glib_dep = dependency('glib-2.0') +gio_dep = dependency('gio-2.0') cc = meson.get_compiler('c') mdep = cc.find_library('m', required : false) @@ -66,36 +67,36 @@ libstorycode_dep = declare_dependency(include_directories : libstorycode_include link_with : libstorycode) -executable('sc2_test', - ['src/sc2_test.c', +executable('pdfstorycode', + ['src/pdfstorycode.c', ], gresources, - dependencies : [gtkdep, libstorycode_dep]) + dependencies : [glib_dep, gio_dep, libstorycode_dep]) # Main program -executable('colloquium', - ['src/colloquium.c', - 'src/narrative_window.c', - 'src/render.c', - 'src/slideshow.c', - 'src/debugger.c', - 'src/pr_clock.c', - 'src/sc_editor.c', - 'src/slide_window.c', - 'src/frame.c', - 'src/presentation.c', - 'src/sc_interp.c', - 'src/testcard.c', - 'src/imagestore.c', - 'src/print.c', - 'src/sc_parse.c', - 'src/utils.c', - 'src/stylesheet.c', - 'src/stylesheet_editor.c', - ], - gresources, - dependencies : [gtkdep, mdep, jsondep], - install : true) +#executable('colloquium', +# ['src/colloquium.c', +# 'src/narrative_window.c', +# 'src/render.c', +# 'src/slideshow.c', +# 'src/debugger.c', +# 'src/pr_clock.c', +# 'src/sc_editor.c', +# 'src/slide_window.c', +# 'src/frame.c', +# 'src/presentation.c', +# 'src/sc_interp.c', +# 'src/testcard.c', +# 'src/imagestore.c', +# 'src/print.c', +# 'src/sc_parse.c', +# 'src/utils.c', +# 'src/stylesheet.c', +# 'src/stylesheet_editor.c', +# ], +# gresources, +# dependencies : [gtkdep, mdep, jsondep], +# install : true) # Desktop file install_data(['data/colloquium.desktop'], diff --git a/src/colloquium.c b/src-old/colloquium.c index 02ffa0a..02ffa0a 100644 --- a/src/colloquium.c +++ b/src-old/colloquium.c diff --git a/src/colloquium.h b/src-old/colloquium.h index 89f600f..89f600f 100644 --- a/src/colloquium.h +++ b/src-old/colloquium.h diff --git a/src/debugger.c b/src-old/debugger.c index f15478a..f15478a 100644 --- a/src/debugger.c +++ b/src-old/debugger.c diff --git a/src/debugger.h b/src-old/debugger.h index d6191bf..d6191bf 100644 --- a/src/debugger.h +++ b/src-old/debugger.h diff --git a/src/frame.c b/src-old/frame.c index 08b8fd9..08b8fd9 100644 --- a/src/frame.c +++ b/src-old/frame.c diff --git a/src/frame.h b/src-old/frame.h index d0525f8..d0525f8 100644 --- a/src/frame.h +++ b/src-old/frame.h diff --git a/src/imagestore.c b/src-old/imagestore.c index 61ebcfb..61ebcfb 100644 --- a/src/imagestore.c +++ b/src-old/imagestore.c diff --git a/src/imagestore.h b/src-old/imagestore.h index 0d4df24..0d4df24 100644 --- a/src/imagestore.h +++ b/src-old/imagestore.h diff --git a/src/narrative_window.c b/src-old/narrative_window.c index e0c59ef..e0c59ef 100644 --- a/src/narrative_window.c +++ b/src-old/narrative_window.c diff --git a/src/narrative_window.h b/src-old/narrative_window.h index 24b4a4b..24b4a4b 100644 --- a/src/narrative_window.h +++ b/src-old/narrative_window.h diff --git a/src/pr_clock.c b/src-old/pr_clock.c index 8085c89..8085c89 100644 --- a/src/pr_clock.c +++ b/src-old/pr_clock.c diff --git a/src/pr_clock.h b/src-old/pr_clock.h index 97d2d0d..97d2d0d 100644 --- a/src/pr_clock.h +++ b/src-old/pr_clock.h diff --git a/src/presentation.c b/src-old/presentation.c index d7d9c08..d7d9c08 100644 --- a/src/presentation.c +++ b/src-old/presentation.c diff --git a/src/presentation.h b/src-old/presentation.h index b288d8e..b288d8e 100644 --- a/src/presentation.h +++ b/src-old/presentation.h diff --git a/src/print.c b/src-old/print.c index 43c967e..43c967e 100644 --- a/src/print.c +++ b/src-old/print.c diff --git a/src/print.h b/src-old/print.h index 265b7c1..265b7c1 100644 --- a/src/print.h +++ b/src-old/print.h diff --git a/src/render.c b/src-old/render.c index 6ac09fc..6ac09fc 100644 --- a/src/render.c +++ b/src-old/render.c diff --git a/src/render.h b/src-old/render.h index 0cfae26..0cfae26 100644 --- a/src/render.h +++ b/src-old/render.h diff --git a/src/sc_editor.c b/src-old/sc_editor.c index 8e79fd8..8e79fd8 100644 --- a/src/sc_editor.c +++ b/src-old/sc_editor.c diff --git a/src/sc_editor.h b/src-old/sc_editor.h index d3c111b..d3c111b 100644 --- a/src/sc_editor.h +++ b/src-old/sc_editor.h diff --git a/src/sc_interp.c b/src-old/sc_interp.c index 07f09a5..07f09a5 100644 --- a/src/sc_interp.c +++ b/src-old/sc_interp.c diff --git a/src/sc_interp.h b/src-old/sc_interp.h index 764b532..764b532 100644 --- a/src/sc_interp.h +++ b/src-old/sc_interp.h diff --git a/src/sc_parse.c b/src-old/sc_parse.c index 78f5799..78f5799 100644 --- a/src/sc_parse.c +++ b/src-old/sc_parse.c diff --git a/src/sc_parse.h b/src-old/sc_parse.h index 17ce2dd..17ce2dd 100644 --- a/src/sc_parse.h +++ b/src-old/sc_parse.h diff --git a/src/slide_window.c b/src-old/slide_window.c index ed37a50..ed37a50 100644 --- a/src/slide_window.c +++ b/src-old/slide_window.c diff --git a/src/slide_window.h b/src-old/slide_window.h index 681ec39..681ec39 100644 --- a/src/slide_window.h +++ b/src-old/slide_window.h diff --git a/src/slideshow.c b/src-old/slideshow.c index 6e1c49d..6e1c49d 100644 --- a/src/slideshow.c +++ b/src-old/slideshow.c diff --git a/src/slideshow.h b/src-old/slideshow.h index ff16d73..ff16d73 100644 --- a/src/slideshow.h +++ b/src-old/slideshow.h diff --git a/src/stylesheet.c b/src-old/stylesheet.c index a6e2531..a6e2531 100644 --- a/src/stylesheet.c +++ b/src-old/stylesheet.c diff --git a/src/stylesheet.h b/src-old/stylesheet.h index 16d0a0a..16d0a0a 100644 --- a/src/stylesheet.h +++ b/src-old/stylesheet.h diff --git a/src/stylesheet_editor.c b/src-old/stylesheet_editor.c index 292bbf1..292bbf1 100644 --- a/src/stylesheet_editor.c +++ b/src-old/stylesheet_editor.c diff --git a/src/stylesheet_editor.h b/src-old/stylesheet_editor.h index a7c77b6..a7c77b6 100644 --- a/src/stylesheet_editor.h +++ b/src-old/stylesheet_editor.h diff --git a/src/testcard.c b/src-old/testcard.c index 2b6598f..2b6598f 100644 --- a/src/testcard.c +++ b/src-old/testcard.c diff --git a/src/testcard.h b/src-old/testcard.h index bb1ce2b..bb1ce2b 100644 --- a/src/testcard.h +++ b/src-old/testcard.h diff --git a/src/utils.c b/src-old/utils.c index b41f344..b41f344 100644 --- a/src/utils.c +++ b/src-old/utils.c diff --git a/src/utils.h b/src-old/utils.h index af3c7b8..af3c7b8 100644 --- a/src/utils.h +++ b/src-old/utils.h diff --git a/src/sc2_test.c b/src/pdfstorycode.c index 1dc4099..276a381 100644 --- a/src/sc2_test.c +++ b/src/pdfstorycode.c @@ -1,5 +1,5 @@ /* - * sc2_test.c + * pdfstorycode.c * * Copyright © 2019 Thomas White <taw@bitwiz.org.uk> * @@ -30,8 +30,6 @@ #include "storycode.h" #include "presentation.h" -//int scdebug = 1; - int main(int argc, char *argv[]) { GFile *file; @@ -39,12 +37,19 @@ int main(int argc, char *argv[]) const char *text; size_t len; Presentation *p; + int i; - file = g_file_new_for_uri("resource:///uk/me/bitwiz/Colloquium/demo.sc"); + file = g_file_new_for_commandline_arg(argv[1]); bytes = g_file_load_bytes(file, NULL, NULL, NULL); text = g_bytes_get_data(bytes, &len); p = storycode_parse_presentation(text); g_bytes_unref(bytes); + /* Render each slide to PDF */ +// for ( i=0; i<presentation_num_slides(p); i++ ) { +// Slide *slide = presentation_slide(p, i); +// +// } + return 0; } diff --git a/tests/meson.build b/tests/meson.build index d1f66b9..940f3b0 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,21 +1,21 @@ -basic_rendering = ['../src/render.c', '../src/frame.c', - '../src/sc_parse.c', '../src/imagestore.c', - '../src/sc_interp.c', '../src/utils.c', - '../src/stylesheet.c'] - -e = executable('storycode_test', 'storycode_test.c', '../src/sc_parse.c', - dependencies : [gtkdep]) -test('Simple StoryCode parsing', e) - -e = executable('render_basic', 'render_basic.c', basic_rendering, - dependencies : [gtkdep, mdep, jsondep]) -test('Simple rendering', e) - -e = executable('render_subframe', 'render_subframe.c', basic_rendering, - dependencies : [gtkdep, mdep, jsondep]) -test('Rendering with subframes', e) - -e = executable('json_test', 'json_test.c', '../src/sc_parse.c', - '../src/stylesheet.c', - gresources, dependencies : [mdep, jsondep, gtkdep]) -test('JSON parsing', e) +#basic_rendering = ['../src/render.c', '../src/frame.c', +# '../src/sc_parse.c', '../src/imagestore.c', +# '../src/sc_interp.c', '../src/utils.c', +# '../src/stylesheet.c'] +# +#e = executable('storycode_test', 'storycode_test.c', '../src/sc_parse.c', +# dependencies : [gtkdep]) +#test('Simple StoryCode parsing', e) +# +#e = executable('render_basic', 'render_basic.c', basic_rendering, +# dependencies : [gtkdep, mdep, jsondep]) +#test('Simple rendering', e) +# +#e = executable('render_subframe', 'render_subframe.c', basic_rendering, +# dependencies : [gtkdep, mdep, jsondep]) +#test('Rendering with subframes', e) +# +#e = executable('json_test', 'json_test.c', '../src/sc_parse.c', +# '../src/stylesheet.c', +# gresources, dependencies : [mdep, jsondep, gtkdep]) +#test('JSON parsing', e) |