1 #include "csf.h"
2 #include "csfimpl.h"
3 #include <string.h>
4 
UINT1tLdd(size_t nrCells,void * Buf)5 static void UINT1tLdd(size_t nrCells, void *Buf)
6 {
7 	size_t i;
8 	UINT1 *buf = (UINT1 *)Buf;
9 
10 	for(i=0; i < (size_t)nrCells; i++)
11 		if (buf[i] != MV_UINT1)
12 		{
13 			buf[i] %= (UINT1)10;
14 			if (buf[i] == 0)
15 				buf[i] = MV_UINT1;
16 		}
17 }
18 
INT2tLdd(size_t nrCells,void * Buf)19 static void INT2tLdd(size_t nrCells, void *Buf)
20 {
21 	size_t i;
22 	INT2  *inBuf  = (INT2  *)Buf;
23 	UINT1 *outBuf = (UINT1 *)Buf;
24 	for(i=0; i < (size_t)nrCells; i++)
25 		if (inBuf[i] != MV_INT2)
26 		{
27 			outBuf[i] = (UINT1)(ABS(inBuf[i]) % 10);
28 			if (outBuf[i] == 0)
29 				outBuf[i] = MV_UINT1;
30 		}
31 		else
32 			outBuf[i] = MV_UINT1;
33 }
34 
35 #define TOBOOL(nr, buf, srcType)\
36 {\
37 	size_t i;\
38 /* loop must be upward to prevent overwriting of values \
39  * not yet converted \
40  */ \
41  	PRECOND(sizeof(srcType) >= sizeof(UINT1));\
42 	for(i=0; i < (size_t)nr; i++)\
43 		if (IS_MV_##srcType( ((srcType *)buf)+i) )\
44 			((UINT1 *)buf)[i] = MV_UINT1;\
45 		else\
46 			((UINT1 *)buf)[i] = ((srcType *)buf)[i] != ZERO_##srcType;\
47 }
48 
INT1tBoolean(size_t nrCells,void * buf)49 static void INT1tBoolean(size_t nrCells, void *buf)
50 { TOBOOL(nrCells, buf, INT1); }
51 
INT2tBoolean(size_t nrCells,void * buf)52 static void INT2tBoolean(size_t nrCells, void *buf)
53 { TOBOOL(nrCells, buf, INT2); }
54 
INT4tBoolean(size_t nrCells,void * buf)55 static void INT4tBoolean(size_t nrCells, void *buf)
56 { TOBOOL(nrCells, buf, INT4); }
57 
UINT1tBoolean(size_t nrCells,void * buf)58 static void UINT1tBoolean(size_t nrCells, void *buf)
59 { TOBOOL(nrCells, buf, UINT1); }
60 
UINT2tBoolean(size_t nrCells,void * buf)61 static void UINT2tBoolean(size_t nrCells, void *buf)
62 { TOBOOL(nrCells, buf, UINT2); }
63 
UINT4tBoolean(size_t nrCells,void * buf)64 static void UINT4tBoolean(size_t nrCells, void *buf)
65 { TOBOOL(nrCells, buf, UINT4); }
66 
REAL4tBoolean(size_t nrCells,void * buf)67 static void REAL4tBoolean(size_t nrCells, void *buf)
68 { TOBOOL(nrCells, buf, REAL4); }
69 
REAL8tBoolean(size_t nrCells,void * buf)70 static void REAL8tBoolean(size_t nrCells, void *buf)
71 { TOBOOL(nrCells, buf, REAL8); }
72 
73 #define CONV_BIG_TO_SMALL(nr, buf, destType, srcType)\
74 {\
75 	size_t i;\
76 /* loop must be upward to prevent overwriting of values \
77  * not yet converted: \
78  */ \
79  	PRECOND(sizeof(srcType) >= sizeof(destType)); /* upward loop OK */ \
80 	for(i=0; i < (size_t)nr; i++) {\
81 		if (IS_MV_##srcType( ((srcType *)buf)+i) )\
82 		    SET_MV_##destType( ((destType *)buf)+i);\
83 		else {\
84 			destType CBTS_temp = (destType)(((srcType *)buf)[i]); \
85 			((destType *)buf)[i] = CBTS_temp; \
86 		} \
87 	} \
88 }
89 
90 #define CONV_SMALL_TO_BIG(nr, buf, destType, srcType)\
91 {\
92 	size_t i = (size_t)nr;\
93 /* loop must be downward to prevent overwriting of values \
94  * not yet converted: \
95  */ \
96  	PRECOND(sizeof(srcType) <= sizeof(destType)); /* downward loop OK */ \
97 	do { i--;\
98 		if (IS_MV_##srcType( ((srcType *)buf)+i) )\
99 		    SET_MV_##destType( ((destType *)buf)+i);\
100 		else {\
101 			destType CSTB_temp = (destType)(((srcType *)buf)[i]); \
102 			((destType *)buf)[i] = CSTB_temp; \
103 		} \
104 	}while ( i != 0);\
105 }
106 
UINT1tINT4(size_t nrCells,void * buf)107 static void UINT1tINT4(size_t nrCells, void *buf)
108 { CONV_SMALL_TO_BIG(nrCells, buf, INT4, UINT1);}
109 
UINT1tREAL4(size_t nrCells,void * buf)110 static void UINT1tREAL4(size_t nrCells, void *buf)
111 { CONV_SMALL_TO_BIG(nrCells, buf, REAL4, UINT1);}
112 
UINT1tREAL8(size_t nrCells,void * buf)113 static void UINT1tREAL8(size_t nrCells, void *buf)
114 { CONV_SMALL_TO_BIG(nrCells, buf, REAL8, UINT1);}
115 
INT4tUINT1(size_t nrCells,void * buf)116 static void INT4tUINT1(size_t nrCells, void *buf)
117 { CONV_BIG_TO_SMALL(nrCells, buf, UINT1, INT4);}
118 
INT2tUINT1(size_t nrCells,void * buf)119 static void INT2tUINT1(size_t nrCells, void *buf)
120 { CONV_BIG_TO_SMALL(nrCells, buf, UINT1, INT2);}
121 
UINT2tUINT1(size_t nrCells,void * buf)122 static void UINT2tUINT1(size_t nrCells, void *buf)
123 { CONV_BIG_TO_SMALL(nrCells, buf, UINT1, UINT2);}
124 
INT4tREAL4(size_t nrCells,void * buf)125 static void INT4tREAL4(size_t nrCells, void *buf)
126 { CONV_BIG_TO_SMALL(nrCells, buf, REAL4, INT4);}
127 
INT4tREAL8(size_t nrCells,void * buf)128 static void INT4tREAL8(size_t nrCells, void *buf)
129 { CONV_SMALL_TO_BIG(nrCells, buf, REAL8, INT4);}
130 
REAL4tUINT1(size_t nrCells,void * buf)131 static void REAL4tUINT1(size_t nrCells, void *buf)
132 { CONV_BIG_TO_SMALL(nrCells, buf, UINT1, REAL4);}
133 
REAL4tINT4(size_t nrCells,void * buf)134 static void REAL4tINT4(size_t nrCells, void *buf)
135 { CONV_BIG_TO_SMALL(nrCells, buf, INT4, REAL4);}
136 
REAL4tREAL8(size_t nrCells,void * buf)137 static void REAL4tREAL8(size_t nrCells, void *buf)
138 { CONV_SMALL_TO_BIG(nrCells, buf, REAL8, REAL4);}
139 
REAL8tUINT1(size_t nrCells,void * buf)140 static void REAL8tUINT1(size_t nrCells, void *buf)
141 { CONV_BIG_TO_SMALL(nrCells, buf, UINT1, REAL8);}
142 
REAL8tINT4(size_t nrCells,void * buf)143 static void REAL8tINT4(size_t nrCells, void *buf)
144 { CONV_BIG_TO_SMALL(nrCells, buf, INT4, REAL8);}
145 
REAL8tREAL4(size_t nrCells,void * buf)146 static void REAL8tREAL4(size_t nrCells, void *buf)
147 { CONV_BIG_TO_SMALL(nrCells, buf, REAL4, REAL8);}
148 
149 static void Transform2( size_t nrCells, void *buf, CSF_CR destCellRepr, CSF_CR currCellRepr);
150 
INT1tINT4(size_t nrCells,void * buf)151 static void INT1tINT4(size_t nrCells, void *buf)
152 { Transform2(nrCells, buf, CR_INT4, CR_INT1);}
153 
INT1tREAL4(size_t nrCells,void * buf)154 static void INT1tREAL4(size_t nrCells, void *buf)
155 { Transform2(nrCells, buf, CR_REAL4, CR_INT1);}
156 
INT1tREAL8(size_t nrCells,void * buf)157 static void INT1tREAL8(size_t nrCells, void *buf)
158 { Transform2(nrCells, buf, CR_REAL8, CR_INT1);}
159 
INT2tINT4(size_t nrCells,void * buf)160 static void INT2tINT4(size_t nrCells, void *buf)
161 { Transform2(nrCells, buf, CR_INT4, CR_INT2);}
162 
INT2tREAL4(size_t nrCells,void * buf)163 static void INT2tREAL4(size_t nrCells, void *buf)
164 { Transform2(nrCells, buf, CR_REAL4, CR_INT2);}
165 
INT2tREAL8(size_t nrCells,void * buf)166 static void INT2tREAL8(size_t nrCells, void *buf)
167 { Transform2(nrCells, buf, CR_REAL8, CR_INT2);}
168 
UINT2tINT4(size_t nrCells,void * buf)169 static void UINT2tINT4(size_t nrCells, void *buf)
170 { Transform2(nrCells, buf, CR_INT4, CR_UINT2);}
171 
UINT2tREAL4(size_t nrCells,void * buf)172 static void UINT2tREAL4(size_t nrCells, void *buf)
173 { Transform2(nrCells, buf, CR_REAL4, CR_UINT2);}
174 
UINT2tREAL8(size_t nrCells,void * buf)175 static void UINT2tREAL8(size_t nrCells, void *buf)
176 { Transform2(nrCells, buf, CR_REAL8, CR_UINT2);}
177 
UINT4tREAL4(size_t nrCells,void * buf)178 static void UINT4tREAL4(size_t nrCells, void *buf)
179 { Transform2(nrCells, buf, CR_REAL4, CR_UINT4);}
180 
UINT4tREAL8(size_t nrCells,void * buf)181 static void UINT4tREAL8(size_t nrCells, void *buf)
182 { Transform2(nrCells, buf, CR_REAL8, CR_UINT4);}
183 
184 
ConvertToINT2(size_t nrCells,void * buf,CSF_CR src)185 static void ConvertToINT2( size_t nrCells, void *buf, CSF_CR src)
186 {
187 	if (IS_SIGNED(src))
188 	{
189 		POSTCOND(src == CR_INT1);
190 		CONV_SMALL_TO_BIG(nrCells,buf, INT2, INT1);
191 	}
192 	else
193 	{
194 		POSTCOND(src == CR_UINT1);
195 		CONV_SMALL_TO_BIG(nrCells,buf, INT2, UINT1);
196 	}
197 }
198 
ConvertToINT4(size_t nrCells,void * buf,CSF_CR src)199 static void ConvertToINT4( size_t nrCells, void *buf, CSF_CR src)
200 {
201 	if (IS_SIGNED(src))
202 	{
203 		POSTCOND(src == CR_INT2);
204 		CONV_SMALL_TO_BIG(nrCells,buf, INT4, INT2);
205 	}
206 	else
207 	{
208 		POSTCOND(src == CR_UINT2);
209 		CONV_SMALL_TO_BIG(nrCells,buf, INT4, UINT2);
210 	}
211 }
212 
213 
UINT1tUINT2(size_t nrCells,void * buf)214 static void UINT1tUINT2(
215 size_t nrCells,
216 void *buf)
217 {
218 	CONV_SMALL_TO_BIG(nrCells, buf, UINT2, UINT1);
219 }
220 
UINT2tUINT4(size_t nrCells,void * buf)221 static void UINT2tUINT4(
222 size_t nrCells,
223 void *buf)
224 {
225 	CONV_SMALL_TO_BIG(nrCells, buf, UINT4, UINT2);
226 }
227 
ConvertToREAL4(size_t nrCells,void * buf,CSF_CR src)228 static void ConvertToREAL4( size_t nrCells, void *buf, CSF_CR src)
229 {
230 	size_t i;
231 
232 	i = (size_t)nrCells;
233 
234 	if (IS_SIGNED(src))
235 	{
236 		POSTCOND(src == CR_INT4);
237 		INT4tREAL4(nrCells, buf);
238 	}
239 	else
240 	{
241 		POSTCOND(src == CR_UINT4);
242 		{
243 			do {
244 				i--;
245 				if ( ((UINT4 *)buf)[i] == MV_UINT4 )
246 					((UINT4 *)buf)[i] = MV_UINT4;
247 				else
248 					((REAL4 *)buf)[i] = (REAL4)((UINT4 *)buf)[i];
249 			    }
250 			while(i != 0);
251 		}
252 	}
253 }
254 
Transform2(size_t nrCells,void * buf,CSF_CR destCellRepr,CSF_CR currCellRepr)255 static void Transform2(
256 	size_t nrCells,
257 	void  *buf,
258 	CSF_CR destCellRepr, /* the output representation */
259 	CSF_CR currCellRepr)  /* at start of while this is the representation
260 				read in the MAP-file */
261 {
262   /* subsequent looping changes the to the new
263    * converted type
264    */
265 	while(currCellRepr != destCellRepr)
266 	{
267 		switch(currCellRepr)
268 		{
269 			case CR_INT1:    ConvertToINT2(nrCells, buf,
270 						currCellRepr);
271 					currCellRepr = CR_INT2;
272 					break;
273 			case CR_INT2:    ConvertToINT4(nrCells, buf,
274 						currCellRepr);
275 					currCellRepr = CR_INT4;
276 					break;
277 			case CR_INT4:    ConvertToREAL4(nrCells, buf,
278 						currCellRepr);
279 					currCellRepr = CR_REAL4;
280 					break;
281 			case CR_UINT1: 	if (IS_SIGNED(destCellRepr))
282 					{
283 						ConvertToINT2(nrCells, buf,
284 							currCellRepr);
285 						currCellRepr = CR_INT2;
286 					}
287 					else
288 					{
289 						UINT1tUINT2(nrCells, buf);
290 						currCellRepr = CR_UINT2;
291 					}
292 					break;
293 			case CR_UINT2:   if (destCellRepr == CR_INT4)
294 					{
295 						ConvertToINT4(nrCells, buf,
296 							currCellRepr);
297 					 	currCellRepr = CR_INT4;
298 					 }
299 					 else
300 					 {
301 						UINT2tUINT4(nrCells, buf);
302 						currCellRepr = CR_UINT4;
303 					 }
304 					 break;
305 			case CR_UINT4:   ConvertToREAL4(nrCells, buf,
306 						currCellRepr);
307 					currCellRepr = CR_REAL4;
308 					break;
309 			default       :	POSTCOND(currCellRepr == CR_REAL4);
310 					REAL4tREAL8(nrCells, buf);
311 					currCellRepr = CR_REAL8;
312 		}
313 	}
314 }
315 
316 /* OLD STUFF
317 void TransForm(
318 	const MAP *map,
319 	size_t nrCells,
320 	void *buf)
321 {
322 	Transform2(nrCells, buf, map->types[READ_AS], map->types[STORED_AS]);
323 }
324 */
325 
326 #define illegal NULL
327 #define same    CsfDummyConversion
328 
329 static const CSF_CONV_FUNC ConvTable[8][8] = {
330 /* ConvTable[source][destination] */
331 /* INT1     , INT2      , INT4      , UINT1     , UINT2     , UINT4     , REAL4     , REAL8        */
332 /* 0        , 1         , 2         , 3         , 4         , 5         , 6         , 7      ind   */
333 /* 0x04     , 0x05      , 0x06      , 0x00      , 0x01      , 0x02      , 0x0A      , 0x0B low-nib */
334 {  same     , illegal   , INT1tINT4 , illegal   , illegal   , illegal   , INT1tREAL4, INT1tREAL8}, /* INT1 */
335 { illegal   ,  same     , INT2tINT4 ,INT2tUINT1 , illegal   , illegal   , INT2tREAL4, INT2tREAL8}, /* INT2 */
336 { illegal   , illegal   ,  same     ,INT4tUINT1 , illegal   , illegal   , INT4tREAL4, INT4tREAL8}, /* INT4 */
337 { illegal   , illegal   ,UINT1tINT4 ,  same     ,UINT1tUINT2, illegal   ,UINT1tREAL4,UINT1tREAL8}, /* UINT1 */
338 { illegal   , illegal   ,UINT2tINT4 , UINT2tUINT1 ,  same     ,UINT2tUINT4,UINT2tREAL4,UINT2tREAL8}, /* UINT2 */
339 { illegal   , illegal   , illegal   , illegal   , illegal   ,  same     ,UINT4tREAL4,UINT4tREAL8}, /* UINT4 */
340 { illegal   , illegal   ,REAL4tINT4 ,REAL4tUINT1, illegal   , illegal   ,  same     ,REAL4tREAL8}, /* REAL4 */
341 { illegal   , illegal   ,REAL8tINT4 ,REAL8tUINT1, illegal   , illegal   ,REAL8tREAL4,  same     }  /* REAL8 */
342 };
343 
344 static const CSF_CONV_FUNC boolConvTable[8] = {
345 INT1tBoolean, INT2tBoolean, INT4tBoolean,
346 UINT1tBoolean, UINT2tBoolean, UINT4tBoolean,
347 REAL4tBoolean, REAL8tBoolean };
348 
349 
350 static const char  convTableIndex[12] = {
351 	   3 /* UINT1 */,  4 /* UINT2 */,  5 /* UINT4 */, -1 /* 0x03  */,
352 	   0 /*  INT1 */,  1 /*  INT2 */,  2 /*  INT4 */, -1 /* 0x07  */,
353 	  -1 /*  0x08 */, -1 /*  0x09 */,  6 /* REAL4 */,  7 /* REAL8 */
354 };
355 
ConvFuncBool(CSF_CR cr)356 static CSF_CONV_FUNC ConvFuncBool(CSF_CR cr)
357 {
358 	PRECOND(CSF_UNIQ_CR_MASK(cr) < 12);
359 	PRECOND(convTableIndex[CSF_UNIQ_CR_MASK(cr)] != -1);
360 
361 	return boolConvTable[(int)convTableIndex[CSF_UNIQ_CR_MASK(cr)]];
362 }
363 
ConvFunc(CSF_CR destType,CSF_CR srcType)364 static CSF_CONV_FUNC ConvFunc(CSF_CR destType, CSF_CR srcType)
365 {
366 
367 	PRECOND(CSF_UNIQ_CR_MASK(destType) < 12);
368 	PRECOND(CSF_UNIQ_CR_MASK(srcType) < 12);
369 	PRECOND(convTableIndex[CSF_UNIQ_CR_MASK(srcType)] != -1);
370 	PRECOND(convTableIndex[CSF_UNIQ_CR_MASK(destType)] != -1);
371 	/* don't complain on illegal, it can be attached
372 	 * to a app2file while there's no WRITE_MODE
373 	 * if it is an error then it is cached in RputSomeCells
374 	 */
375 	return
376          ConvTable[(int)convTableIndex[CSF_UNIQ_CR_MASK(srcType)]]
377  	          [(int)convTableIndex[CSF_UNIQ_CR_MASK(destType)]];
378 }
379 
HasInFileCellReprType2(CSF_CR cr)380 static int HasInFileCellReprType2(CSF_CR cr)
381 {
382 	char  type2[12] = {
383 	   1 /* UINT1 */,  0 /* UINT2 */,  0 /* UINT4 */,  0 /* 0x03  */,
384 	   0 /*  INT1 */,  0 /*  INT2 */,  1 /*  INT4 */,  0 /* 0x07  */,
385 	   0 /*  0x08 */,  0 /*  0x09 */,  1 /* REAL4 */,  1 /* REAL8 */};
386 
387 	PRECOND(CSF_UNIQ_CR_MASK(cr) < 12);
388 
389 	return (int)type2[CSF_UNIQ_CR_MASK(cr)];
390 }
391 
392 /* set the cell representation the application will use
393  * RuseAs enables an application to use cell values
394  * in a different format than they are stored in the map.
395  * Cell values are converted when getting (Rget*-functions) and
396  * putting (Rput*-functions) cells if necessary.
397  * Thus no conversions are applied if cell representation and/or
398  * value scale already match.
399  * Any conversions between the version 2 cell representations,
400  * (CR_UINT1, CR_INT4, CR_REAL4 and CR_REAL8) is possible.
401  * Conversion from a non version 2 cell representation to a version
402  * 2 cell representation is only possible when you don't
403  * have write access to the cells.
404  * Conversion rules are exactly as described in K&R 2nd edition section A6.
405  *
406  * Two special conversions are possible if you don't
407  * have write access to the cells or if the in-file cell representation is
408  * UINT1:
409  * (1) VS_BOOLEAN: successive calls to the Rget*-functions returns the result of
410  * value != 0
411  * , that is 0 or 1 in UINT1 format. The in-file cell representation can be
412  * anything, except if the value scale is VS_DIRECTION or VS_LDD.
413  * (2) VS_LDD: successive calls to the Rget*-functions returns the result of
414  * value % 10
415  * , that is 1 to 9 in UINT1 format (0's are set to MV_UINT1).
416  * The in-file cell representation must be CR_UINT1 or CR_INT2 and
417  * the value scale must be VS_LDD, VS_CLASSIFIED or VS_NOTDETERMINED.
418  *
419  * NOTE
420  * that you must use Rmalloc() to get enough space for both the in-file and
421  * app cell representation.
422  *
423  * returns
424  * 0 if conversion obeys rules given here. 1 if not (conversions
425  * will not take place).
426  *
427  * Merrno
428  * CANT_USE_AS_BOOLEAN CANT_USE_WRITE_BOOLEAN
429  * CANT_USE_WRITE_LDD
430  * CANT_USE_AS_LDD
431  * CANT_USE_WRITE_OLDCR
432  * ILLEGAL_USE_TYPE
433  *
434  * EXAMPLE
435  * .so examples/maskdump.tr
436  */
437 
RuseAs(MAP * m,CSF_CR useType)438 int RuseAs(
439 	MAP *m,          /* map handle */
440 	CSF_CR useType)   /* CR_UINT1,CR_INT4, CR_REAL4, CR_REAL8, VS_BOOLEAN or VS_LDD */
441 {
442 
443   CSF_CR inFileCR = RgetCellRepr(m);
444   CSF_VS inFileVS = RgetValueScale(m);
445   int hasInFileCellReprType2 =  HasInFileCellReprType2(inFileCR);
446   int useTypeNoEnumIn;
447   int useTypeNoEnum;
448 
449   /* It is very inconvenient that both, VS and CR are taken as arguments
450    * for this function, and previously were used in the switch statement
451    * now, at least 'special conversions' handled first.
452    */
453 
454   /* Hopefully Coverity will no longer detect that useTypeNoEnum */
455   /* comes from useType */
456   useTypeNoEnumIn = useType;
457   memcpy(&useTypeNoEnum, &useTypeNoEnumIn, sizeof(int));
458 
459   if(useTypeNoEnum == VS_BOOLEAN){
460     switch(inFileVS) {
461       case VS_LDD:
462       case VS_DIRECTION: {
463         M_ERROR(CANT_USE_AS_BOOLEAN);
464         return 1;
465       }
466       case VS_BOOLEAN: {
467         POSTCOND(inFileCR == CR_UINT1);
468         m->appCR = CR_UINT1;
469         m->file2app = same;
470         m->app2file = same;
471         return 0;
472       }
473       default: {
474         if((!hasInFileCellReprType2) && WRITE_ENABLE(m)) {
475           /* cellrepr is old one, we can't write that */
476           M_ERROR(CANT_USE_WRITE_BOOLEAN);
477           return 1;
478         }
479         m->appCR = CR_UINT1;
480         m->file2app  = ConvFuncBool(inFileCR);
481         m->app2file = ConvFunc(inFileCR, CR_UINT1);
482         return 0;
483       }
484     }
485   }
486   else if (useTypeNoEnum == VS_LDD){
487     switch(inFileVS) {
488       case VS_LDD: {
489         POSTCOND(inFileCR == CR_UINT1);
490         m->appCR = CR_UINT1;
491         m->file2app = same;
492         m->app2file = same;
493         return 0;
494       }
495       case VS_CLASSIFIED:
496       case VS_NOTDETERMINED: {
497         switch(inFileCR) {
498           case CR_UINT1: {
499             m->appCR = CR_UINT1;
500             m->file2app  = UINT1tLdd;
501             m->app2file = same;
502             return 0;
503           }
504           case CR_INT2: {
505             if(WRITE_ENABLE(m)) {
506               M_ERROR(CANT_USE_WRITE_LDD);
507               return 1;
508             }
509             m->appCR = CR_UINT1;
510             m->file2app  = INT2tLdd;
511             m->app2file = illegal;
512             return 0;
513           }
514           default: {
515             /* This should never happen.
516              * Shut up compiler.
517              */
518             assert(0);
519           }
520         }
521       }
522       default: {
523         M_ERROR(CANT_USE_AS_LDD);
524         return 1;
525       }
526     }
527   }
528 
529   switch(useType) {
530     case CR_UINT1:
531     case CR_INT4 :
532     case CR_REAL4:
533     case CR_REAL8: {
534       if((!hasInFileCellReprType2) && WRITE_ENABLE(m)) {
535         /* cellrepr is old one, we can't write that */
536         M_ERROR(CANT_USE_WRITE_OLDCR);
537         return 1;
538       }
539       m->appCR = useType;
540       m->file2app  = ConvFunc(useType, inFileCR);
541       m->app2file = ConvFunc(inFileCR, useType);
542       POSTCOND(m->file2app != NULL);
543       return 0;
544     }
545     default: {
546       M_ERROR(ILLEGAL_USE_TYPE);
547       return 1;
548     }
549   }
550   /* NOTREACHED */
551 }
552