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>
45 #include "dmxconfig.h"
47 #include "dmxcompat.h"
54 static int dmxVDLReadLine(FILE *str
, char *buf
, int len
)
56 if (fgets(buf
, len
, str
)) return strlen(buf
);
60 static int dmxVDLCount(const char *buf
)
62 return strtol(buf
, NULL
, 10);
65 static void dmxVDLVirtualEntry(const char *buf
,
74 *x
= strtol(buf
, &end
, 10);
75 *y
= strtol(end
, &end
, 10);
77 for (s
= end
, d
= name
, start
= 1; *s
&& *s
!= '['; ++s
) {
78 if (start
&& isspace(*s
)) continue;
83 while (d
> name
&& isspace(d
[-1])) *--d
= '\0'; /* remove trailing space */
87 static void dmxVDLDisplayEntry(const char *buf
,
91 int *xorig
, int *yorig
)
96 pt
= strchr(buf
, ' ');
97 strncpy(name
, buf
, pt
-buf
);
101 *x
= strtol(pt
, &end
, 10);
102 *y
= strtol(end
, &end
, 10);
103 *xorig
= strtol(end
, &end
, 10);
104 *yorig
= strtol(end
, &end
, 10);
105 *xoff
= strtol(end
, &end
, 10);
106 *yoff
= strtol(end
, NULL
, 10);
109 /** Read from the VDL format \a filename and return a newly allocated \a
110 * DMXConfigEntryPtr */
111 DMXConfigEntryPtr
dmxVDLRead(const char *filename
)
114 char buf
[2048]; /* RATS: Use ok */
117 DMXConfigEntryPtr entry
= NULL
;
118 DMXConfigVirtualPtr
virtual = NULL
;
119 DMXConfigSubPtr sub
= NULL
;
120 DMXConfigDisplayPtr display
= NULL
;
121 DMXConfigFullDimPtr fdim
= NULL
;
125 int x
, y
, xoff
, yoff
, xorig
, yorig
;
126 char name
[2048]; /* RATS: Use ok */
137 } state
= simulateFlag
;
139 if (!filename
) str
= stdin
;
140 else str
= fopen(filename
, "r");
141 if (!str
) return NULL
;
143 while (dmxVDLReadLine(str
, buf
, sizeof(buf
))) {
144 DMXConfigCommentPtr comment
= NULL
;
147 for (pt
= buf
; *pt
; pt
++)
148 if (*pt
== '\r' || *pt
== '\n') {
153 tmp
= dmxConfigCopyString(buf
+ 1, strlen(buf
+ 1));
154 comment
= dmxConfigCreateComment(T_COMMENT
, lineno
, tmp
);
155 entry
= dmxConfigAddEntry(entry
, dmxConfigComment
, comment
, NULL
);
160 state
= virtualCount
;
163 vcount
= dmxVDLCount(buf
);
164 state
= virtualEntry
;
168 dmxVDLVirtualEntry(buf
, name
, &len
, &x
, &y
);
169 tmp
= dmxConfigCopyString(name
, len
);
170 virtual = dmxConfigCreateVirtual(NULL
,
171 dmxConfigCreateString(T_STRING
,
175 dmxConfigCreatePair(T_DIMENSION
,
180 state
= displayCount
;
183 dcount
= dmxVDLCount(buf
);
184 state
= displayEntry
;
187 dmxVDLDisplayEntry(buf
, name
, &len
, &x
, &y
, &xoff
, &yoff
,
189 tmp
= dmxConfigCopyString(name
, len
);
190 fdim
= dmxConfigCreateFullDim(
191 dmxConfigCreatePartDim(
192 dmxConfigCreatePair(T_DIMENSION
,
196 dmxConfigCreatePair(T_OFFSET
,
202 display
= dmxConfigCreateDisplay(NULL
,
203 dmxConfigCreateString(T_STRING
,
208 dmxConfigCreatePair(T_ORIGIN
,
214 sub
= dmxConfigAddSub(sub
, dmxConfigSubDisplay(display
));
217 virtual->subentry
= sub
;
218 entry
= dmxConfigAddEntry(entry
,
227 icount
= dmxVDLCount(buf
);
231 if (!--icount
) state
= virtualEntry
;