29
29
#include <errno.h>
30
30
31
31
#include "config.h"
32
- #include "parser .h"
32
+ #include "math .h"
33
33
#include "main.h"
34
34
#include "math.h"
35
35
#include "build-config.h"
@@ -50,6 +50,10 @@ static gpointer UNDOKEY_SYMBOL_VALUE = (gpointer) 4;
50
50
/*
51
51
* initialize GScanner for the parsing of tool definitions
52
52
*/
53
+ <<<<<<< HEAD
54
+ == = == ==
55
+
56
+ >>>>>>> 5385d 7b (config , callbacks : add option to change tool definitions and individual tool attributes )
53
57
void scanner_init (GScanner * scanner )
54
58
{
55
59
scanner -> config -> case_sensitive = 0 ;
@@ -59,6 +63,7 @@ void scanner_init(GScanner *scanner)
59
63
scanner -> config -> numbers_2_int = 1 ;
60
64
scanner -> config -> int_2_float = 1 ;
61
65
66
+ <<<<<<< HEAD
62
67
g_scanner_scope_add_symbol (scanner , 0 , "PEN" , (gpointer ) GROMIT_PEN );
63
68
g_scanner_scope_add_symbol (scanner , 0 , "LINE" , (gpointer ) GROMIT_LINE );
64
69
g_scanner_scope_add_symbol (scanner , 0 , "RECT" , (gpointer ) GROMIT_RECT );
@@ -68,6 +73,15 @@ void scanner_init(GScanner *scanner)
68
73
g_scanner_scope_add_symbol (scanner , 0 , "RECOLOR" , (gpointer ) GROMIT_RECOLOR );
69
74
g_scanner_scope_add_symbol (scanner , 0 , "HOTKEY" , HOTKEY_SYMBOL_VALUE );
70
75
g_scanner_scope_add_symbol (scanner , 0 , "UNDOKEY" , UNDOKEY_SYMBOL_VALUE );
76
+ = == == ==
77
+ g_scanner_scope_add_symbol (scanner , 0 , "PEN" , (gpointer ) GROMIT_PEN );
78
+ g_scanner_scope_add_symbol (scanner , 0 , "LINE" , (gpointer ) GROMIT_LINE );
79
+ g_scanner_scope_add_symbol (scanner , 0 , "RECT" , (gpointer ) GROMIT_RECT );
80
+ g_scanner_scope_add_symbol (scanner , 0 , "ERASER" , (gpointer ) GROMIT_ERASER );
81
+ g_scanner_scope_add_symbol (scanner , 0 , "RECOLOR" ,(gpointer ) GROMIT_RECOLOR );
82
+ g_scanner_scope_add_symbol (scanner , 0 , "HOTKEY" , HOTKEY_SYMBOL_VALUE );
83
+ g_scanner_scope_add_symbol (scanner , 0 , "UNDOKEY" , UNDOKEY_SYMBOL_VALUE );
84
+ >>>>>>> 5385d 7b (config , callbacks : add option to change tool definitions and individual tool attributes )
71
85
72
86
g_scanner_scope_add_symbol (scanner , 1 , "BUTTON1" , (gpointer ) 1 );
73
87
g_scanner_scope_add_symbol (scanner , 1 , "BUTTON2" , (gpointer ) 2 );
@@ -85,11 +99,14 @@ void scanner_init(GScanner *scanner)
85
99
g_scanner_scope_add_symbol (scanner , 2 , "arrowtype" , (gpointer ) SYM_ARROWTYPE );
86
100
g_scanner_scope_add_symbol (scanner , 2 , "minsize" , (gpointer ) SYM_MINSIZE );
87
101
g_scanner_scope_add_symbol (scanner , 2 , "maxsize" , (gpointer ) SYM_MAXSIZE );
102
+ <<<<<<< HEAD
88
103
g_scanner_scope_add_symbol (scanner , 2 , "radius" , (gpointer ) SYM_RADIUS );
89
104
g_scanner_scope_add_symbol (scanner , 2 , "maxangle" , (gpointer ) SYM_MAXANGLE );
90
105
g_scanner_scope_add_symbol (scanner , 2 , "minlen" , (gpointer ) SYM_MINLEN );
91
106
g_scanner_scope_add_symbol (scanner , 2 , "simplify" , (gpointer ) SYM_SIMPLIFY );
92
107
g_scanner_scope_add_symbol (scanner , 2 , "snap" , (gpointer ) SYM_SNAP );
108
+ = == == ==
109
+ >>>>>>> 5385d 7b (config , callbacks : add option to change tool definitions and individual tool attributes )
93
110
94
111
g_scanner_set_scope (scanner , 0 );
95
112
scanner -> config -> scope_0_fallback = 0 ;
@@ -121,10 +138,13 @@ gchar* parse_name (GScanner *scanner)
121
138
name = g_strndup (scanner -> value .v_string , len + 3 );
122
139
token = g_scanner_get_next_token (scanner );
123
140
141
+ <<<<<<< HEAD
124
142
/*
125
143
* Are there any options to limit the scope of the definition?
126
144
*/
127
145
146
+ == = == ==
147
+ >>>>>>> 5385d 7b (config , callbacks : add option to change tool definitions and individual tool attributes )
128
148
if (token == G_TOKEN_LEFT_BRACE )
129
149
{
130
150
g_scanner_set_scope (scanner , 1 );
@@ -193,11 +213,14 @@ gboolean parse_tool(GromitData *data, GScanner *scanner, GromitPaintContext *sty
193
213
style -> width = 7 ;
194
214
style -> arrowsize = 0 ;
195
215
style -> arrow_type = GROMIT_ARROW_END ;
216
+ <<<<<<< HEAD
196
217
style -> radius = 10 ;
197
218
style -> minlen = style -> radius * 5 / 2 ;
198
219
style -> maxangle = 15 ;
199
220
style -> simplify = 10 ;
200
221
style -> snapdist = 0 ;
222
+ = == == ==
223
+ >>>>>>> 5385d 7b (config , callbacks : add option to change tool definitions and individual tool attributes )
201
224
style -> minwidth = 1 ;
202
225
style -> maxwidth = G_MAXUINT ;
203
226
@@ -226,11 +249,14 @@ gboolean parse_tool(GromitData *data, GScanner *scanner, GromitPaintContext *sty
226
249
style -> width = context -> width ;
227
250
style -> arrowsize = context -> arrowsize ;
228
251
style -> arrow_type = context -> arrow_type ;
252
+ <<<<<<< HEAD
229
253
style -> radius = context -> radius ;
230
254
style -> minlen = context -> minlen ;
231
255
style -> maxangle = context -> maxangle ;
232
256
style -> simplify = context -> simplify ;
233
257
style -> snapdist = context -> snapdist ;
258
+ = == == ==
259
+ >>>>>>> 5385d 7b (config , callbacks : add option to change tool definitions and individual tool attributes )
234
260
style -> minwidth = context -> minwidth ;
235
261
style -> maxwidth = context -> maxwidth ;
236
262
* style -> paint_color = * context -> paint_color ;
@@ -247,7 +273,11 @@ gboolean parse_tool(GromitData *data, GScanner *scanner, GromitPaintContext *sty
247
273
}
248
274
else
249
275
{
276
+ <<<<<<< HEAD
250
277
g_printerr ("Expected tool definition or name of template tool\n" );
278
+ = == == ==
279
+ g_printerr ("Expected Tool-definition or name of template tool\n" );
280
+ >>>>>>> 5385d 7b (config , callbacks : add option to change tool definitions and individual tool attributes )
251
281
goto cleanup ;
252
282
}
253
283
return TRUE;
@@ -256,6 +286,10 @@ gboolean parse_tool(GromitData *data, GScanner *scanner, GromitPaintContext *sty
256
286
if (color_allocated )
257
287
{
258
288
g_free (style -> paint_color );
289
+ <<<<<<< HEAD
290
+ == = == ==
291
+ g_printerr ("parse_tool: free color @ %p\n" , style -> paint_color );
292
+ >>>>>>> 5385d 7b (config , callbacks : add option to change tool definitions and individual tool attributes )
259
293
style -> paint_color = NULL ;
260
294
}
261
295
return FALSE;
@@ -299,7 +333,11 @@ ToolAttribute parse_attribute(GScanner *scanner, GromitPaintContext *style)
299
333
{
300
334
gfloat v = parse_float (scanner , "Missing arrowsize" );
301
335
if (isnan (v )) return SYM_ERROR ;
336
+ <<<<<<< HEAD
302
337
style -> arrowsize = v ;
338
+ = == == ==
339
+ style -> arrowsize = v + 0.5 ;
340
+ >>>>>>> 5385d 7b (config , callbacks : add option to change tool definitions and individual tool attributes )
303
341
}
304
342
else if (id == SYM_ARROWTYPE )
305
343
{
@@ -334,6 +372,7 @@ ToolAttribute parse_attribute(GScanner *scanner, GromitPaintContext *style)
334
372
return SYM_ERROR ;
335
373
}
336
374
}
375
+ <<<<<<< HEAD
337
376
else if ((intptr_t ) scanner -> value .v_symbol == SYM_RADIUS )
338
377
{
339
378
gfloat v = parse_get_float (scanner , "Missing radius (float)" );
@@ -375,6 +414,19 @@ ToolAttribute parse_attribute(GScanner *scanner, GromitPaintContext *style)
375
414
gfloat v = parse_float (scanner , "Missing maxsize" );
376
415
if (isnan (v )) return SYM_ERROR ;
377
416
style -> maxwidth = v + 0.5 ;
417
+ = == == ==
418
+ else if (id == SYM_MINSIZE )
419
+ {
420
+ gfloat v = parse_float (scanner , "Missing minsize" );
421
+ if (isnan (v )) return SYM_ERROR ;
422
+ style -> minwidth = v + 0.5 ;
423
+ }
424
+ else if (id == SYM_MAXSIZE )
425
+ {
426
+ gfloat v = parse_float (scanner , "Missing maxsize" );
427
+ if (isnan (v )) return SYM_ERROR ;
428
+ style -> maxwidth = v + 0.5 ;
429
+ >>>>>>> 5385d 7b (config , callbacks : add option to change tool definitions and individual tool attributes )
378
430
}
379
431
else
380
432
{
@@ -385,6 +437,7 @@ ToolAttribute parse_attribute(GScanner *scanner, GromitPaintContext *style)
385
437
}
386
438
387
439
/*
440
+ <<<<<<< HEAD
388
441
* get "=VALUE", where VALUE is a float
389
442
* returns NAN is an error occurs
390
443
*/
@@ -404,6 +457,24 @@ gfloat parse_get_float(GScanner *scanner, const gchar *msg)
404
457
return NAN ;
405
458
}
406
459
return scanner -> value .v_float ;
460
+ = == == ==
461
+ * parse "=<VALUE>" , with value being a float
462
+ * return < VALUE > as gfloat , or NAN on error
463
+ * /
464
+ gfloat parse_float (GScanner * scanner , const gchar * msg ) {
465
+ GTokenType token = g_scanner_get_next_token (scanner );
466
+ if (token != G_TOKEN_EQUAL_SIGN ) {
467
+ g_printerr ("Missing \"=\"... aborting\n" );
468
+ return NAN ;
469
+ }
470
+ token = g_scanner_get_next_token (scanner );
471
+ if (token != G_TOKEN_FLOAT ) {
472
+ g_printerr ("%s" , msg );
473
+ g_printerr ("... aborting\n" );
474
+ return NAN ;
475
+ }
476
+ return scanner -> value .v_float ;
477
+ >>>>>>> 5385d 7b (config , callbacks : add option to change tool definitions and individual tool attributes )
407
478
}
408
479
409
480
/*
@@ -438,14 +509,14 @@ gboolean parse_style(GScanner *scanner, GromitPaintContext *style)
438
509
gboolean parse_config (GromitData * data )
439
510
{
440
511
gboolean status = FALSE;
441
- GromitPaintContext * context = NULL ;
512
+ GromitPaintContext * context = NULL ;
442
513
GScanner * scanner ;
443
514
GTokenType token ;
444
515
gchar * filename ;
445
516
int file ;
446
517
gchar * name ;
447
518
448
- /* try user config location */
519
+ // try user config location
449
520
filename = g_strjoin (G_DIR_SEPARATOR_S ,
450
521
g_get_user_config_dir (), "gromit-mpx.cfg" , NULL );
451
522
if ((file = open (filename , O_RDONLY )) < 0 )
@@ -454,7 +525,7 @@ gboolean parse_config (GromitData *data)
454
525
g_print ("Using user config %s\n" , filename );
455
526
456
527
457
- /* try global config file */
528
+ // try global config file
458
529
if (file < 0 ) {
459
530
g_free (filename );
460
531
filename = g_strdup (SYSCONFDIR "/gromit-mpx/gromit-mpx.cfg" );
@@ -464,20 +535,21 @@ gboolean parse_config (GromitData *data)
464
535
g_print ("Using system config %s\n" , filename );
465
536
}
466
537
467
- /* was the last possibility, no use to go on */
538
+ // was the last possibility, no use to go on
468
539
if (file < 0 ) {
469
540
g_free (filename );
470
- GtkWidget * dialog = gtk_message_dialog_new (GTK_WINDOW (data -> win ),
471
- GTK_DIALOG_DESTROY_WITH_PARENT ,
472
- GTK_MESSAGE_WARNING ,
473
- GTK_BUTTONS_CLOSE ,
474
- _ ("No usable config file found, falling back to default tools." ));
541
+ GtkWidget * dialog = gtk_message_dialog_new (
542
+ GTK_WINDOW (data -> win ),
543
+ GTK_DIALOG_DESTROY_WITH_PARENT ,
544
+ GTK_MESSAGE_WARNING ,
545
+ GTK_BUTTONS_CLOSE ,
546
+ _ ("No usable config file found, falling back to default tools." ));
475
547
gtk_dialog_run (GTK_DIALOG (dialog ));
476
548
gtk_widget_destroy (dialog );
477
549
return FALSE;
478
550
}
479
551
480
- scanner = g_scanner_new (NULL );
552
+ scanner = g_scanner_new (NULL );
481
553
scanner_init (scanner );
482
554
scanner -> input_name = filename ;
483
555
g_scanner_input_file (scanner , file );
@@ -495,13 +567,14 @@ gboolean parse_config (GromitData *data)
495
567
goto cleanup ;
496
568
497
569
if (!parse_tool (data , scanner , & style ))
498
- goto cleanup ;
570
+ {
571
+ g_printerr ("parse tool failed\n" );
572
+ goto cleanup ;
573
+ }
499
574
500
- token = g_scanner_cur_token (scanner );
501
- //
502
- /* Are there any tool-options?
503
- */
504
575
576
+ // are there any tool-options?
577
+ token = g_scanner_cur_token (scanner );
505
578
if (token == G_TOKEN_LEFT_PAREN )
506
579
{
507
580
if (! parse_style (scanner , & style ))
@@ -516,20 +589,29 @@ gboolean parse_config (GromitData *data)
516
589
goto cleanup ;
517
590
}
518
591
592
+ <<<<<<< HEAD
519
593
context = paint_context_new (data , style .type , style .paint_color , style .width ,
520
594
style .arrowsize , style .arrow_type ,
521
595
style .simplify , style .radius , style .maxangle , style .minlen , style .snapdist ,
522
596
style .minwidth , style .maxwidth );
523
597
g_hash_table_insert (data -> tool_config , name , context );
598
+ = == == ==
599
+ context = paint_context_new (data ,
600
+ style .type ,
601
+ style .paint_color ,
602
+ style .width ,
603
+ style .arrowsize ,
604
+ style .arrow_type ,
605
+ style .minwidth ,
606
+ style .maxwidth );
607
+ g_hash_table_insert (data -> tool_config , name , context );
608
+ >>>>>>> 5385d 7b (config , callbacks : add option to change tool definitions and individual tool attributes )
524
609
}
525
610
else if (token == G_TOKEN_SYMBOL &&
526
611
(scanner -> value .v_symbol == HOTKEY_SYMBOL_VALUE ||
527
612
scanner -> value .v_symbol == UNDOKEY_SYMBOL_VALUE ))
528
613
{
529
- /*
530
- * Hot key definition
531
- */
532
-
614
+ // hot key definition
533
615
gpointer key_type = scanner -> value .v_symbol ;
534
616
token = g_scanner_get_next_token (scanner );
535
617
@@ -568,7 +650,7 @@ gboolean parse_config (GromitData *data)
568
650
}
569
651
else
570
652
{
571
- g_printerr ("Expected name of Tool to define or Hot key definition\n" );
653
+ g_printerr ("Expected name of tool to define or hot key definition\n" );
572
654
goto cleanup ;
573
655
}
574
656
@@ -589,12 +671,13 @@ gboolean parse_config (GromitData *data)
589
671
g_hash_table_remove_all (data -> tool_config );
590
672
591
673
/* alert user */
592
- GtkWidget * dialog = gtk_message_dialog_new (GTK_WINDOW (data -> win ),
593
- GTK_DIALOG_DESTROY_WITH_PARENT ,
594
- GTK_MESSAGE_WARNING ,
595
- GTK_BUTTONS_CLOSE ,
596
- _ ("Failed parsing config file %s, falling back to default tools." ),
597
- filename );
674
+ GtkWidget * dialog = gtk_message_dialog_new (
675
+ GTK_WINDOW (data -> win ),
676
+ GTK_DIALOG_DESTROY_WITH_PARENT ,
677
+ GTK_MESSAGE_WARNING ,
678
+ GTK_BUTTONS_CLOSE ,
679
+ _ ("Failed parsing config file %s, falling back to default tools." ),
680
+ filename );
598
681
gtk_dialog_run (GTK_DIALOG (dialog ));
599
682
gtk_widget_destroy (dialog );
600
683
}
@@ -730,6 +813,7 @@ void read_keyfile(GromitData *data)
730
813
{
731
814
gchar * filename = g_strjoin (G_DIR_SEPARATOR_S ,
732
815
g_get_user_config_dir (), "gromit-mpx.ini" , NULL );
816
+
733
817
/*
734
818
set defaults
735
819
*/
@@ -755,7 +839,7 @@ void read_keyfile(GromitData *data)
755
839
if (data -> opacity == 0 )
756
840
data -> opacity = DEFAULT_OPACITY ;
757
841
758
- cleanup :
842
+ cleanup :
759
843
g_free (filename );
760
844
g_key_file_free (key_file );
761
845
}
0 commit comments