1 /*
2 **
3 ** media.c
4 **
5 ** Copyright (C) 1997 Johannes Plass
6 ** Copyright (C) 2004 Jose E. Marchesi
7 **
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 3 of the License, or
11 ** (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with GNU gv; see the file COPYING. If not, write to
20 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ** Boston, MA 02111-1307, USA.
22 **
23 ** Author: Johannes Plass (plass@thep.physik.uni-mainz.de)
24 ** Department of Physics
25 ** Johannes Gutenberg-University
26 ** Mainz, Germany
27 **
28 ** Jose E. Marchesi (jemarch@gnu.org)
29 ** GNU Project
30 **
31 */
32 #include "ac_config.h"
33
34 /*
35 #define MESSAGES
36 */
37 #include "message.h"
38
39 #include <stdio.h>
40 #include <math.h>
41
42 #include "paths.h"
43 #include INC_X11(Intrinsic.h)
44 #include INC_XMU(SysUtil.h)
45
46 #include "types.h"
47 #include "config.h"
48 #include "types.h"
49 #include "options.h"
50 #include "media.h"
51
52 /*##################################################
53 media_freeMedias
54 ##################################################*/
55
media_freeMedias(medias)56 void media_freeMedias(medias)
57 Media *medias;
58 {
59 int i=0;
60 BEGINMESSAGE(media_freeMedias)
61 while (medias[i]) {
62 XtFree(medias[i]->name);
63 XtFree((XtPointer)medias[i]);
64 i++;
65 }
66 XtFree((XtPointer)medias);
67 ENDMESSAGE(media_freeMedias)
68 }
69
70 /*##################################################
71 media_parseMedias
72 ##################################################*/
73
media_mallocMedia(void)74 static Media media_mallocMedia(void)
75 {
76 Media media;
77 media = (Media) XtMalloc(sizeof(MediaStruct));
78 memset((void*)media ,0,sizeof(MediaStruct));
79 return media;
80 }
81
media_parseMedias(s)82 Media *media_parseMedias(s)
83 char *s;
84 {
85 char *c,*nl;
86 Media *medias,*mmedias,media;
87 int i,n,have_media=0,have_used_media=0,used,w,h;
88 char name[100];
89
90 BEGINMESSAGE(media_parseMedias)
91 if (!s) s = "";
92 s =options_squeezeMultiline(s);
93 for (n=1,c=s; (c = strchr(c,'\n')); n++, c++);
94 INFIMESSAGE(number of medias,n)
95 mmedias = medias = (Media*) XtMalloc((n+3)*sizeof(Media));
96 media = media_mallocMedia();
97 media->name = XtNewString("BBox");
98 media->width= 0;
99 media->height= 0;
100 media->used= 1;
101 *medias++ = media;
102 c=s;
103 if (*s) while (n>0) {
104 nl = strchr(c,'\n');
105 if (nl) *nl='\0';
106 name[0]='\0';
107 used = 1;
108 while (*c && (*c == '#' || *c == '!')) { used=0; c++; }
109 i=sscanf(c," %[^,] , %d %d ",name,&w,&h);
110 if (i==3 && w>0 && h>0) {
111 media = media_mallocMedia();
112 media->name = XtNewString(name);
113 media->width= w;
114 media->height= h;
115 media->used= used;
116 if (used) have_used_media=1;
117 have_media = 1;
118 INFSMESSAGE(found media,media->name)
119 IIMESSAGE(media->width,media->height)
120 *medias++ = media;
121 }
122 n--;
123 if (!nl) break;
124 c=++nl;
125 }
126 if (!have_media) {
127 media = media_mallocMedia();
128 media->name = XtNewString("A4");
129 media->width= 595;
130 media->height= 842;
131 media->used= 1;
132 *medias++ = media;
133 }
134 if (!have_used_media) mmedias[1]->used=1;
135 *medias = (Media) NULL;
136
137 XtFree(s);
138 ENDMESSAGE(media_parseMedias)
139 return(mmedias);
140 }
141
142 /*##################################################
143 media_numMedias
144 ##################################################*/
145
media_numMedias(medias)146 int media_numMedias(medias)
147 Media *medias;
148 {
149 int i;
150 for (i=1; medias[i]; i++);
151 return i;
152 }
153
154
155