~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

Viewing changes to plug-ins/imagemap/imap_ncsa.y

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%{
 
2
/*
 
3
 * This is a plug-in for the GIMP.
 
4
 *
 
5
 * Generates clickable image maps.
 
6
 *
 
7
 * Copyright (C) 1998-1999 Maurits Rijk  lpeek.mrijk@consunet.nl
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU General Public License as published by
 
11
 * the Free Software Foundation; either version 2 of the License, or
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
22
 *
 
23
 */
 
24
 
 
25
#include <math.h>
 
26
 
 
27
#include <gtk/gtk.h>
 
28
 
 
29
#include "imap_circle.h"
 
30
#include "imap_file.h"
 
31
#include "imap_main.h"
 
32
#include "imap_polygon.h"
 
33
#include "imap_rectangle.h"
 
34
#include "imap_string.h"
 
35
 
 
36
extern int ncsa_lex();
 
37
extern int ncsa_restart();
 
38
static void ncsa_error(char* s);
 
39
 
 
40
static Object_t *current_object;
 
41
 
 
42
%}
 
43
 
 
44
%union {
 
45
   int val;
 
46
   double value;
 
47
   char id[256];
 
48
}
 
49
 
 
50
%token<val> RECTANGLE POLYGON CIRCLE DEFAULT
 
51
%token<val> AUTHOR TITLE DESCRIPTION BEGIN_COMMENT
 
52
%token<value> FLOAT
 
53
%token<id> LINK COMMENT
 
54
 
 
55
%%
 
56
 
 
57
ncsa_file       : comment_lines area_list
 
58
                ;
 
59
 
 
60
comment_lines   : /* empty */
 
61
                | comment_lines comment_line
 
62
                ;
 
63
 
 
64
comment_line    : author_line
 
65
                | title_line
 
66
                | description_line
 
67
                | real_comment
 
68
                ;
 
69
 
 
70
real_comment    : BEGIN_COMMENT COMMENT
 
71
                {
 
72
                }
 
73
                ;
 
74
 
 
75
author_line     : AUTHOR COMMENT
 
76
                {
 
77
                   MapInfo_t *info = get_map_info();
 
78
                   g_strreplace(&info->author, $2);
 
79
                }
 
80
                ;
 
81
 
 
82
title_line      : TITLE COMMENT
 
83
                {
 
84
                   MapInfo_t *info = get_map_info();
 
85
                   g_strreplace(&info->title, $2);
 
86
                }
 
87
                ;
 
88
 
 
89
description_line: DESCRIPTION COMMENT
 
90
                {
 
91
                   MapInfo_t *info = get_map_info();
 
92
                   gchar *description;
 
93
 
 
94
                   description = g_strconcat(info->description, $2, "\n", 
 
95
                                             NULL);
 
96
                   g_strreplace(&info->description, description);
 
97
                }
 
98
                ;
 
99
 
 
100
area_list       : /* Empty */
 
101
                | area_list area
 
102
                ;
 
103
 
 
104
area            : default
 
105
                | rectangle
 
106
                | circle
 
107
                | polygon
 
108
                | real_comment
 
109
                ;
 
110
 
 
111
default         : DEFAULT LINK
 
112
                {
 
113
                   MapInfo_t *info = get_map_info();                  
 
114
                   g_strreplace(&info->default_url, $2);
 
115
                }
 
116
                ;
 
117
 
 
118
 
 
119
rectangle       : RECTANGLE LINK FLOAT ',' FLOAT FLOAT ',' FLOAT
 
120
                {
 
121
                   gint x = (gint) $3;
 
122
                   gint y = (gint) $5;
 
123
                   gint width = (gint) fabs($6 - x);
 
124
                   gint height = (gint) fabs($8 - y);
 
125
                   current_object = create_rectangle(x, y, width, height);
 
126
                   object_set_url(current_object, $2);
 
127
                   add_shape(current_object);
 
128
                }
 
129
                ;
 
130
 
 
131
circle          : CIRCLE LINK FLOAT ',' FLOAT FLOAT ',' FLOAT
 
132
                {
 
133
                   gint x = (gint) $3;
 
134
                   gint y = (gint) $5;
 
135
                   gint r = (gint) fabs($8 - $5);
 
136
                   current_object = create_circle(x, y, r);
 
137
                   object_set_url(current_object, $2);
 
138
                   add_shape(current_object);
 
139
                }
 
140
                ;
 
141
 
 
142
polygon         : POLYGON LINK {current_object = create_polygon(NULL);} coord_list
 
143
                {
 
144
                   object_set_url(current_object, $2);
 
145
                   add_shape(current_object);
 
146
                }
 
147
                ;
 
148
 
 
149
coord_list      : /* Empty */
 
150
                | coord_list coord
 
151
                {
 
152
                }
 
153
                ;
 
154
 
 
155
coord           : FLOAT ',' FLOAT
 
156
                {
 
157
                   Polygon_t *polygon = ObjectToPolygon(current_object);
 
158
                   GdkPoint *point = new_point((gint) $1, (gint) $3);
 
159
                   polygon->points = g_list_append(polygon->points, 
 
160
                                                   (gpointer) point);
 
161
                }
 
162
                ;
 
163
 
 
164
%%
 
165
 
 
166
static void 
 
167
ncsa_error(char* s)
 
168
{
 
169
   extern FILE *ncsa_in;
 
170
   ncsa_restart(ncsa_in);
 
171
}
 
172
 
 
173
gboolean
 
174
load_ncsa(const char* filename)
 
175
{
 
176
   gboolean status;
 
177
   extern FILE *ncsa_in;
 
178
   ncsa_in = fopen(filename, "r");
 
179
   if (ncsa_in) {
 
180
      status = !ncsa_parse();
 
181
      fclose(ncsa_in);
 
182
   } else {
 
183
      status = FALSE;
 
184
   }
 
185
   return status;
 
186
}