2 * Copyright 2002 Red Hat Inc., Durham, North Carolina.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation on the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * Rickard E. (Rik) Faith <faith@redhat.com>
34 * This file provides some compatibility support for reading VDL files
35 * that are used by xmovie
36 * (http://www.llnl.gov/icc/sdd/img/xmovie/xmovie.shtml).
38 * This file is not used by the DMX server.
41 #ifdef HAVE_DMX_CONFIG_H
42 #include <dmx-config.h>
46 #include "dmxconfig.h"
48 #include "dmxcompat.h"
56 dmxVDLReadLine(FILE * str
, char *buf
, int len
)
58 if (fgets(buf
, len
, str
))
64 dmxVDLCount(const char *buf
)
66 return strtol(buf
, NULL
, 10);
70 dmxVDLVirtualEntry(const char *buf
, char *name
, int *len
, int *x
, int *y
)
77 *x
= strtol(buf
, &end
, 10);
78 *y
= strtol(end
, &end
, 10);
80 for (s
= end
, d
= name
, start
= 1; *s
&& *s
!= '['; ++s
) {
81 if (start
&& isspace(*s
))
87 while (d
> name
&& isspace(d
[-1]))
88 *--d
= '\0'; /* remove trailing space */
93 dmxVDLDisplayEntry(const char *buf
,
95 int *x
, int *y
, int *xoff
, int *yoff
, int *xorig
, int *yorig
)
100 pt
= strchr(buf
, ' ');
101 strlcpy(name
, buf
, 1 + pt
- buf
);
104 *x
= strtol(pt
, &end
, 10);
105 *y
= strtol(end
, &end
, 10);
106 *xorig
= strtol(end
, &end
, 10);
107 *yorig
= strtol(end
, &end
, 10);
108 *xoff
= strtol(end
, &end
, 10);
109 *yoff
= strtol(end
, NULL
, 10);
112 /** Read from the VDL format \a filename and return a newly allocated \a
113 * DMXConfigEntryPtr */
115 dmxVDLRead(const char *filename
)
118 char buf
[2048]; /* RATS: Use ok */
121 DMXConfigEntryPtr entry
= NULL
;
122 DMXConfigVirtualPtr
virtual = NULL
;
123 DMXConfigSubPtr sub
= NULL
;
124 DMXConfigDisplayPtr display
= NULL
;
125 DMXConfigFullDimPtr fdim
= NULL
;
129 int x
, y
, xoff
, yoff
, xorig
, yorig
;
130 char name
[2048]; /* RATS: Use ok */
141 } state
= simulateFlag
;
146 str
= fopen(filename
, "r");
150 while (dmxVDLReadLine(str
, buf
, sizeof(buf
))) {
151 DMXConfigCommentPtr comment
= NULL
;
154 for (pt
= buf
; *pt
; pt
++)
155 if (*pt
== '\r' || *pt
== '\n') {
160 tmp
= dmxConfigCopyString(buf
+ 1, strlen(buf
+ 1));
161 comment
= dmxConfigCreateComment(T_COMMENT
, lineno
, tmp
);
162 entry
= dmxConfigAddEntry(entry
, dmxConfigComment
, comment
, NULL
);
167 state
= virtualCount
;
170 vcount
= dmxVDLCount(buf
);
171 state
= virtualEntry
;
175 dmxVDLVirtualEntry(buf
, name
, &len
, &x
, &y
);
176 tmp
= dmxConfigCopyString(name
, len
);
177 virtual = dmxConfigCreateVirtual(NULL
,
178 dmxConfigCreateString(T_STRING
,
182 dmxConfigCreatePair(T_DIMENSION
,
187 state
= displayCount
;
190 dcount
= dmxVDLCount(buf
);
191 state
= displayEntry
;
194 dmxVDLDisplayEntry(buf
, name
, &len
, &x
, &y
, &xoff
, &yoff
,
196 tmp
= dmxConfigCopyString(name
, len
);
198 dmxConfigCreateFullDim(dmxConfigCreatePartDim
200 (T_DIMENSION
, lineno
, NULL
, x
, y
, 0, 0),
201 dmxConfigCreatePair(T_OFFSET
, lineno
,
205 dmxConfigCreateDisplay(NULL
,
206 dmxConfigCreateString(T_STRING
, lineno
,
208 dmxConfigCreatePair(T_ORIGIN
, lineno
,
211 sub
= dmxConfigAddSub(sub
, dmxConfigSubDisplay(display
));
214 virtual->subentry
= sub
;
215 entry
= dmxConfigAddEntry(entry
,
216 dmxConfigVirtual
, NULL
, virtual);
222 icount
= dmxVDLCount(buf
);
227 state
= virtualEntry
;