/* * (C) COPYRIGHT International Business Machines Corp. 1995 * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation, and that the name of IBM not be * used in advertising or publicity pertaining to distribution of the * software without specific prior written permission. * * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. * * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE * OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include "dxf.h" #include "entity.h" static VariableTable variables[] = { {"$ACADVER", V_STRING, NULL, "the AutoCAD drawing database version number."}, {"$ANGBASE", V_FLOAT, NULL, "Angle 0 direction."}, {"$ANGDIR", V_INTEGER, NULL, "1=clockwise angles, 0=counterclockwise."}, {"$ATTDIA", V_INTEGER, NULL, "Attribute entry dialogues, 1 = on, 0 = off "}, {"$ATTMODE", V_INTEGER, NULL, "Attribute visibility: 0=none, 1=normal, 2=all."}, {"$ATTREQ", V_INTEGER, NULL, "Attribute prompting during INSERT, 1=on, 0=off."}, {"$AUNITS", V_INTEGER, NULL, "UNITS format for angles."}, {"$AUPREC", V_INTEGER, NULL, "UNITS precision for angles."}, {"$AXISMODE", V_INTEGER, NULL, "axis on if nonzero."}, {"$AXISUNIT", V_2VECTOR, NULL, "axis X and Y tick spacing."}, {"$BLIPMODE", V_INTEGER, NULL, "blip mode on if nonzero."}, {"$CECOLOR", V_INTEGER, NULL, "entity color number; 0 = BYBLOCK, 256 = BYLAYER."}, {"$CELTYPE", V_STRING, NULL, "entity linetype name, or BYBLOCK or BYLAYER."}, {"$CHAMFERA", V_FLOAT, NULL, "first chamfer distance."}, {"$CHAMFERB", V_FLOAT, NULL, "second chamfer distance."}, {"$CLAYER", V_STRING, NULL, "current layer name."}, {"$COORDS", V_INTEGER, NULL, "0=coord disp, 1=cont update, 2=d 9 || *group < 1) { /* Did not find a string */ rewind_file(); return NULL; } /* This is a malloc!!!!! */ item = strdup(value); if (!item) { fprintf(stderr,"malloc failed\n"); exit(0); } return (void *)item; } /* * Snag a single float type variable */ void *snag_float(FILE *fpin, char *s, char *value, int *group, int *type) { float *item; get_next_group(fpin, REQUIRED, s, value, group, type); if (*group > 59 || *group < 10) { rewind_file(); return NULL; } item = (float *)malloc(sizeof(float)); if (!item) { fprintf(stderr,"malloc failed\n"); exit(0); } *item = atof(value); return (void *)item; } /* * Snag a single int type variable */ void *snag_integer(FILE *fpin, char *s, char *value, int *group, int *type) { int *item; get_next_group(fpin, REQUIRED, s, value, group, type); if (*group > 79 || *group < 60) { rewind_file(); return NULL; } item = (int *)malloc(sizeof(int)); if (!item) { fprintf(stderr,"malloc failed\n"); exit(0); } *item = strtol(value,NULL,0); return (void *)item; } /* * Snag a two floats type variable */ void *snag_2vector(FILE *fpin, char *s, char *value, int *group, int *type) { float *f; float *item; item = (float *)malloc(sizeof(float)*2); if (!item) { fprintf(stderr,"malloc failed\n"); exit(0); } f = (float *)snag_float(fpin, s, value, group, type); if (f) item[0] = *f; else item[0] = 0.0; f = (float *)snag_float(fpin, s, value, group, type); if (f) item[1] = *f; else item[1] = 0.0; return (void *)item; } /* * Snag a three floats type variable */ void *snag_3vector(FILE *fpin, char *s, char *value, int *group, int *type) { float *f; float *item; item = (float *)malloc(sizeof(float)*3); if (!item) { fprintf(stderr,"malloc failed\n"); exit(0); } f = (float *)snag_float(fpin, s, value, group, type); if (f) item[0] = *f; else item[0] = 0.0; f = (float *)snag_float(fpin, s, value, group, type); if (f) item[1] = *f; else item[1] = 0.0; f = (float *)snag_float(fpin, s, value, group, type); if (f) item[2] = *f; else item[2] = 0.0; return (void *)item; } /* * For debugging: print the value and name of a variable. */ void print_var(Variable *var) { int i; float f[3]; printf(" %-10.10s (%-30.30s): ", var->name, var->comment); switch (var->var_type) { case V_FLOAT: f[0] = *(float *)var->data; printf("\t%5.5f\n", f[0]); break; case V_INTEGER: i = *(int *)var->data; printf("\t%d\n", i); break; case V_STRING: printf("\t%-20.20s\n", (char *)var->data); break; case V_2VECTOR: f[0] = ((float *)var->data)[0]; f[1] = ((float *)var->data)[1]; printf("\t[%5.5f %5.5f]\n", f[0], f[1]); break; case V_3VECTOR: f[0] = ((float *)var->data)[0]; f[1] = ((float *)var->data)[1]; f[2] = ((float *)var->data)[2]; printf("\t[%5.5f %5.5f %5.5f]\n", f[0], f[1], f[2]); break; } } /* * For debugging: print all variables found in the header section of the file. */ void print_header(void) { int i; printf("\n--Varaibles defined in header section----------------------------\n"); printf("\n Name Comment Value\n"); printf("--------------------------------------------------------------------\n"); for (i=0;i