/* Copyright (C) 2019-2020, Dirk Krause SPDX-License-Identifier: BSD-3-Clause */ /* WARNING: This file was generated by the dkct program (see http://dktools.sourceforge.net/ for details). Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: WxdkdrawRead.cpt */ /** @file WxdkdrawRead.cpp The WxdkdrawRead module. */ #line 52 "WxdkdrawRead.cpt" #include "wxdkdraw.h" #line 58 "WxdkdrawRead.cpt" /** Flags in the context. */ enum { FLAG_VERSION_OK = 0x0001 , /**< Version number found and ok. */ FLAG_BB = 0x0002 , /**< Bounding box found. */ }; /** Current reader state, what is expected in next line. */ enum { S_OBJ_START = 0, /**< Start of new object. */ S_TEXT_DETAILS , /**< Text label: Coordinates. */ S_TEXT_EXPORT , /**< Text label: Export text. */ S_TEXT_SCREEN , /**< Text label: Screen text. */ S_POLY_POINT , /**< Polyline/polygon: Point. */ S_SPLINE_POINT , /**< Spline: Point. */ S_ARC , /**< Arc: 3 points. */ S_CIRCLE , /**< Circle: Coordinates. */ S_DOT_FILLED , /**< Filled dot: Details. */ S_DOT_WHITE , /**< White filled dot: Details. */ S_ELLIPSE , /**< Ellipse: Details. */ S_BOX , /**< Box: Details. */ S_IMAGE_DETAILS , /**< Image: Coordinates and details. */ S_IMAGE_FILENAME /**< Image: File name. */ }; /** Context. */ typedef struct { Wxd_object_t styletemp; /**< Style template. */ Wxd_drawing_t *pdrw; /**< Drawing to add to. */ Wxd_object_t *pgrp; /**< Group object to add to. */ Wxd_object_t *pouc; /**< Object under construction. */ FILE *fin; /**< Input file to read. */ wxdrd_status_t *pstat; /**< Status to report errors. */ char **parts; /**< Words in the current line. */ int *back; /**< Address of result variable. */ size_t nparts; /**< Elements available in parts array. */ size_t uparts; /**< Number of words in current line. */ unsigned long lineno; /**< Current line number. */ int issym; /**< Flag: Reading library symbol. */ int flags; /**< Flags about found information. */ int cc; /**< Flag: Can continue. */ int st; /**< Current reader state. */ uint16_t cpi; /**< Current point index. */ } wxdrd_ctx_t; /** Constant text fragments. */ static const char * const wxdrd_c8_kw[] = { /* 0 */ "WXD", NULL #line 123 "WxdkdrawRead.cpt" }; /** Initialize a reader context before using it. @param pctx Context to initialize. */ static void ctx_init(wxdrd_ctx_t *pctx) { #line 135 "WxdkdrawRead.cpt" wxdobj_obj_init(&(pctx->styletemp), WXD_OT_POLYLINE); pctx->pdrw = NULL; pctx->pgrp = NULL; pctx->pouc = NULL; pctx->fin = NULL; pctx->pstat = NULL; pctx->back = NULL; pctx->lineno = 0UL; pctx->issym = 0; pctx->flags = 0; pctx->cc = 0; pctx->st = S_OBJ_START; pctx->cpi = 0U; #line 149 "WxdkdrawRead.cpt" } /** Write error to status and abort processing. @param pctx Reader context. @param ec Error code. @param te Number of text element in the line causing the problem. */ static void wxd_read_error(wxdrd_ctx_t *pctx, int ec, size_t te) { #line 163 "WxdkdrawRead.cpt" pctx->cc = -1; *(pctx->back) = 0; if ((0UL == pctx->pstat->ln) || (WXDRD_E_NONE == pctx->pstat->ec)) { pctx->pstat->ln = pctx->lineno; pctx->pstat->te = te; pctx->pstat->ec = ec; } #line 171 "WxdkdrawRead.cpt" } /** Read double number. @param pctx Context to use. @param te Text element index on line. @param pd Address of result variable. */ static void rd_dbl(wxdrd_ctx_t *pctx, size_t te, double *pd) { const char *ep = NULL; int res; res = dk4ma_input_c8_double(pd, (pctx->parts)[te], &ep, 1, NULL); if (0 == res) { #line 188 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_NUM_CONV, te); } } /** Read 8 bit unsigned integer number. @param pctx Context to use. @param te Text element index on line. @param pu Address of result variable. */ static void rd_u08(wxdrd_ctx_t *pctx, size_t te, uint8_t *pu) { const char *ep = NULL; int res; res = dk4ma_input_c8_dec_u8(pu, (pctx->parts)[te], &ep, 1, NULL); if (0 == res) { #line 207 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_NUM_CONV, te); } } /** Read 8 bit signed integer number. @param pctx Context to use. @param te Text element index on line. @param pi Address of result variable. */ static void rd_i08(wxdrd_ctx_t *pctx, size_t te, int8_t *pi) { const char *ep = NULL; int res; res = dk4ma_input_c8_dec_i8(pi, (pctx->parts)[te], &ep, 1, NULL); if (0 == res) { #line 226 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_NUM_CONV, te); } } /** Read 16 bit unsigned integer number. @param pctx Context to use. @param te Text element index on line. @param pu Address of result variable. */ static void rd_u16(wxdrd_ctx_t *pctx, size_t te, uint16_t *pu) { const char *ep = NULL; int res; res = dk4ma_input_c8_dec_u16(pu, (pctx->parts)[te], &ep, 1, NULL); if (0 == res) { #line 245 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_NUM_CONV, te); } } /** Read 16 bit signed integer number. @param pctx Context to use. @param te Text element index on line. @param pi Address of result variable. */ static void rd_i16(wxdrd_ctx_t *pctx, size_t te, int16_t *pi) { const char *ep = NULL; int res; res = dk4ma_input_c8_dec_i16(pi, (pctx->parts)[te], &ep, 1, NULL); if (0 == res) { #line 264 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_NUM_CONV, te); } } /** Read 32 bit unsigned integer number. @param pctx Context to use. @param te Text element index on line. @param pu Address of result variable. */ static void rd_u32(wxdrd_ctx_t *pctx, size_t te, uint32_t *pu) { const char *ep = NULL; int res; res = dk4ma_input_c8_dec_u32(pu, (pctx->parts)[te], &ep, 1, NULL); if (0 == res) { #line 283 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_NUM_CONV, te); } } /** Read 32 bit signed integer number. @param pctx Context to use. @param te Text element index on line. @param pi Address of result variable. */ static void rd_i32(wxdrd_ctx_t *pctx, size_t te, int32_t *pi) { const char *ep = NULL; int res; res = dk4ma_input_c8_dec_i32(pi, (pctx->parts)[te], &ep, 1, NULL); if (0 == res) { #line 302 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_NUM_CONV, te); } } /** Check whether the line starts with space or tabulator. @param il Line to check. @return 0 for object start line, 1 for details line (indented). */ static int line_starts_with_space(char const *il) { int back = 0; if (' ' == *il) { back = 1; } if ('\t' == *il) { back = 1; } return back; } /** Check whether the file version found is acceptable. @param maj Major format version number found in file. @param min Minor format version number found in file. @param maxmaj Major format version allowed by module. @param maxmin Minor format version allowed by module. @return 1 for acceptable file format version. */ static int acceptable_version(uint16_t maj, uint16_t min, uint16_t maxmaj, uint16_t maxmin) { int back = 0; #line 341 "WxdkdrawRead.cpt" if (maxmaj > maj) { back = 1; } else { if (maxmaj == maj) { if (maxmin >= min) { back = 1; } } } #line 351 "WxdkdrawRead.cpt" return back; } /** Apply the first line of a WXD file, check for file format keyword and format version numbers. @param pctx Reader context. @param il Input line to process. */ static void apply_first_line(wxdrd_ctx_t *pctx, char *il) { int res; #line 367 "WxdkdrawRead.cpt" if (0 == line_starts_with_space(il)) { pctx->uparts = dk4str8_tokenize( pctx->parts, pctx->nparts, il, NULL, NULL ); if (3 == pctx->uparts) { if (0 == strcmp(wxdrd_c8_kw[0], (pctx->parts)[0])) { rd_u16(pctx, 1, &((pctx->pdrw)->fv_maj)); rd_u16(pctx, 2, &((pctx->pdrw)->fv_min)); res = acceptable_version( (pctx->pdrw)->fv_maj, (pctx->pdrw)->fv_min, 1, 0 ); if (0 == res) { #line 379 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_WRONG_VERSION, 0); } } else { #line 383 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_NO_WXD, 0); } } else { #line 387 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_NO_WXD, 0); } } else { #line 391 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_NO_WXD, 0); } #line 394 "WxdkdrawRead.cpt" } /** Check whether or not to split the current line for processing. @param pctx Reader context containing the state. @return 1 to split the line, 0 to leave unchanged. */ static int must_split_line(wxdrd_ctx_t *pctx) { int back = 1; #line 408 "WxdkdrawRead.cpt" switch (pctx->st) { case S_TEXT_EXPORT : case S_TEXT_SCREEN : case S_IMAGE_FILENAME : { back = 0; } break; } #line 413 "WxdkdrawRead.cpt" return back; } /** Process configuration line. The line is processed only when reading an entire drawing. Configuration lines are not processed when reading a symbol. @param pctx Reader context. */ static void process_osl_config(wxdrd_ctx_t *pctx) { int16_t st = 0; /* Sub type */ #line 429 "WxdkdrawRead.cpt" if (0 == pctx->issym) { if (1 < pctx->uparts) { rd_i16(pctx, 1, &st); if (1 == pctx->cc) { switch ( (int)st ) { case 0 : { #line 435 "WxdkdrawRead.cpt" if (6 == pctx->uparts) { rd_i32(pctx, 2, &(((pctx->pdrw)->bb).xl)); rd_i32(pctx, 3, &(((pctx->pdrw)->bb).xr)); rd_i32(pctx, 4, &(((pctx->pdrw)->bb).yb)); rd_i32(pctx, 5, &(((pctx->pdrw)->bb).yt)); if (wxdobj_bb_is_null_area(&((pctx->pdrw)->bb))) { #line 442 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_BOX_NO_AREA, 2); } } else { #line 446 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } break; case 1 : { #line 450 "WxdkdrawRead.cpt" if (3 == pctx->uparts) { rd_u32(pctx, 2, &((pctx->pdrw)->baselw)); if ((uint32_t)0UL == (pctx->pdrw)->baselw) { (pctx->pdrw)->baselw = 1UL; } } else { #line 457 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } break; case 2 : { #line 461 "WxdkdrawRead.cpt" if (3 == pctx->uparts) { rd_i08(pctx, 2, &((pctx->pdrw)->zl)); if ((int8_t)(-14) > (pctx->pdrw)->zl) { (pctx->pdrw)->zl = (int8_t)(-14); } if ((int8_t)14 < (pctx->pdrw)->zl) { (pctx->pdrw)->zl = (int8_t)14; } } else { #line 471 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } break; case 3 : { #line 475 "WxdkdrawRead.cpt" /* The "0 3 xc yc" configuration option was removed from the file format. As we have some old test files we ignore 0 3 lines. */ } break; case 4 : { #line 482 "WxdkdrawRead.cpt" if (6 == pctx->uparts) { rd_u32(pctx, 2, &((pctx->pdrw)->bleft)); rd_u32(pctx, 2, &((pctx->pdrw)->bright)); rd_u32(pctx, 2, &((pctx->pdrw)->bbottom)); rd_u32(pctx, 2, &((pctx->pdrw)->btop)); } else { #line 489 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } break; case 5 : { #line 493 "WxdkdrawRead.cpt" if (3 == pctx->uparts) { rd_u08(pctx, 2, &((pctx->pdrw)->gridunit)); if (0x00 != (pctx->pdrw)->gridunit) { (pctx->pdrw)->gridunit = 0x01; } } else { #line 500 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } break; case 6 : { #line 504 "WxdkdrawRead.cpt" if (3 == pctx->uparts) { rd_u08(pctx, 2, &((pctx->pdrw)->gridbase)); if (0x00 != (pctx->pdrw)->gridbase) { (pctx->pdrw)->gridbase = 0x01; } } else { #line 511 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } break; default : { #line 515 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_OBJTYPE, 0); } break; } } #if TRACE_DEBUG else { #line 521 "WxdkdrawRead.cpt" } #endif } else { #line 525 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } else { #line 529 "WxdkdrawRead.cpt" if (1 < pctx->uparts) { rd_i16(pctx, 1, &st); if (1 == pctx->cc) { switch ( (int)st ) { case 0 : { if (6 == pctx->uparts) { rd_i32(pctx, 2, &(((pctx->pstat)->bb).xl)); rd_i32(pctx, 3, &(((pctx->pstat)->bb).xr)); rd_i32(pctx, 4, &(((pctx->pstat)->bb).yb)); rd_i32(pctx, 5, &(((pctx->pstat)->bb).yt)); if (wxdobj_bb_is_null_area(&((pctx->pstat)->bb))) { #line 541 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_BOX_NO_AREA, 2); } } } break; } } } } #line 550 "WxdkdrawRead.cpt" } /** Process group begin line. @param pctx Reader context. */ static void process_osl_group_begin(wxdrd_ctx_t *pctx) { Wxd_object_t *ng; #line 563 "WxdkdrawRead.cpt" ng = wxdobj_drw_add_group(pctx->pdrw, pctx->pgrp); if (NULL != ng) { pctx->pgrp = ng; } else { #line 568 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } #line 571 "WxdkdrawRead.cpt" } /** Process group end line. @param pctx Reader context. */ static void process_osl_group_end(wxdrd_ctx_t *pctx) { Wxd_object_t *ng = NULL; if (NULL != pctx->pgrp) { ng = (pctx->pgrp)->pa; pctx->pgrp = ng; if ((NULL == pctx->pgrp) && (0 != pctx->issym)) { #line 587 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_NO_GROUP_TO_END, 0); } } else { #line 591 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_NO_GROUP_TO_END, 0); } } /** Read layer number and stroke/fill colour for text labels, dots and images. @param pctx Reader context. */ static void read_elements_05(wxdrd_ctx_t *pctx) { #line 606 "WxdkdrawRead.cpt" rd_i16(pctx, 1, &((pctx->styletemp).lay)); rd_u08(pctx, 2, &((pctx->styletemp).fc[0])); rd_u08(pctx, 3, &((pctx->styletemp).fc[1])); rd_u08(pctx, 4, &((pctx->styletemp).fc[2])); (pctx->styletemp).sc[0] = (pctx->styletemp).fc[0]; (pctx->styletemp).sc[1] = (pctx->styletemp).fc[1]; (pctx->styletemp).sc[2] = (pctx->styletemp).fc[2]; #line 614 "WxdkdrawRead.cpt" } /** Process text label begin line. @param pctx Reader context. */ static void process_osl_textlabel(wxdrd_ctx_t *pctx) { #line 626 "WxdkdrawRead.cpt" if (5 == pctx->uparts) { wxdobj_obj_init(&(pctx->styletemp), WXD_OT_TEXT); read_elements_05(pctx); pctx->st = S_TEXT_DETAILS; } else { #line 632 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 635 "WxdkdrawRead.cpt" } /** Correct line style. @param pls Address of line style variable to correct. */ static void correct_linestyle(uint8_t *pls) { if ((uint8_t)(WXD_LS_DASH_DOT_DOT_DOT) < *pls) { *pls = (uint8_t)(WXD_LS_DASH_DOT_DOT_DOT); } } /** Correct style length. @param psl Address of style length variable to correct. */ static void correct_stylelength(uint8_t *psl) { if ((uint8_t)1U > *psl) { *psl = (uint8_t)1U; } } /** Correct line cap style. @param pcs Address of line cap style variable to correct. */ static void correct_capstyle(uint8_t *pcs) { if ((uint8_t)(WXD_LC_PROJECTING) < *pcs) { *pcs = (uint8_t)(WXD_LC_PROJECTING); } } /** Correct line join style. @param pjs Address of line join style variable to correct. */ static void correct_joinstyle(uint8_t *pjs) { if ((uint8_t)(WXD_LJ_BEVELED) < *pjs) { *pjs = (uint8_t)(WXD_LJ_BEVELED); } } /** Correct miter limit. @param pml Address of miter limit variable to correct. */ static void correct_miterlimit(uint8_t *pml) { if ((uint8_t)1U > *pml) { *pml = (uint8_t)1U; } } /** Correct arrow type. @param pat Address of arrow type variable to correct. */ static void correct_arrowtype(uint8_t *pat) { if ((uint8_t)29U < *pat) { *pat = (uint8_t)29U; } } /** Correct arrow length. @param pal Address of arrow length variable to correct. */ static void correct_arrowlength(uint8_t *pal) { if ((uint8_t)1U > *pal) { *pal = (uint8_t)1U; } } /** Correct arrow width. @param paw Address of arrow width variable to correct. */ static void correct_arrowwidth(uint8_t *paw) { if ((uint8_t)1U > *paw) { *paw = (uint8_t)1U; } } /** Correct fill style. @param pfs Address of fill style variable to correct. */ static void correct_fillstyle(uint8_t *pfs) { if ((uint8_t)(WXD_FS_VERTICAL_TIRES) < *pfs) { *pfs = (uint8_t)(WXD_FS_VERTICAL_TIRES); } } /** Read 18 style values for polylines and open splines. @param pctx Reader context. */ static void read_elements_18(wxdrd_ctx_t *pctx) { #line 772 "WxdkdrawRead.cpt" rd_u16(pctx, 1, &(((pctx->styletemp).det).p.n)); rd_i16(pctx, 2, &((pctx->styletemp).lay)); rd_u08(pctx, 3, &((pctx->styletemp).sc[0])); rd_u08(pctx, 4, &((pctx->styletemp).sc[1])); rd_u08(pctx, 5, &((pctx->styletemp).sc[2])); rd_u16(pctx, 6, &((pctx->styletemp).lw)); rd_u08(pctx, 7, &((pctx->styletemp).ls)); correct_linestyle(&((pctx->styletemp).ls)); rd_u08(pctx, 8, &((pctx->styletemp).sl)); correct_stylelength(&((pctx->styletemp).sl)); rd_u08(pctx, 9, &((pctx->styletemp).cs)); correct_capstyle(&((pctx->styletemp).cs)); rd_u08(pctx, 10, &((pctx->styletemp).js)); correct_joinstyle(&((pctx->styletemp).js)); rd_u08(pctx, 11, &((pctx->styletemp).ml)); correct_miterlimit(&((pctx->styletemp).ml)); rd_u08(pctx, 12, &((pctx->styletemp).aft)); correct_arrowtype(&((pctx->styletemp).aft)); rd_u08(pctx, 13, &((pctx->styletemp).afl)); correct_arrowlength(&((pctx->styletemp).afl)); rd_u08(pctx, 14, &((pctx->styletemp).afw)); correct_arrowwidth(&((pctx->styletemp).afw)); rd_u08(pctx, 15, &((pctx->styletemp).abt)); correct_arrowtype(&((pctx->styletemp).abt)); rd_u08(pctx, 16, &((pctx->styletemp).abl)); correct_arrowlength(&((pctx->styletemp).abl)); rd_u08(pctx, 17, &((pctx->styletemp).abw)); correct_arrowwidth(&((pctx->styletemp).abw)); #line 801 "WxdkdrawRead.cpt" } /** Process polyline object begin line. @param pctx Reader context. */ static void process_osl_polyline(wxdrd_ctx_t *pctx) { #line 813 "WxdkdrawRead.cpt" if (18 == pctx->uparts) { wxdobj_obj_init(&(pctx->styletemp), WXD_OT_POLYLINE); read_elements_18(pctx); if (1 < (pctx->styletemp).det.p.n) { pctx->pouc = wxdobj_add_polyline( pctx->pdrw, pctx->pgrp, (pctx->styletemp).det.p.n, 0, &(pctx->styletemp) ); if (NULL != pctx->pouc) { pctx->st = S_POLY_POINT; pctx->cpi = 0U; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc)) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 826 "WxdkdrawRead.cpt" } } else { #line 829 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 833 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TOO_FEW_POINTS, 0); } } else { #line 837 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 840 "WxdkdrawRead.cpt" } /** Process open spline begin line. @param pctx Reader context. */ static void process_osl_ospline(wxdrd_ctx_t *pctx) { #line 852 "WxdkdrawRead.cpt" if (18 == pctx->uparts) { wxdobj_obj_init(&(pctx->styletemp), WXD_OT_O_SPLINE); read_elements_18(pctx); if (1 < (pctx->styletemp).det.p.n) { pctx->pouc = wxdobj_add_spline( pctx->pdrw, pctx->pgrp, (pctx->styletemp).det.p.n, 0, &(pctx->styletemp) ); if (NULL != pctx->pouc) { pctx->st = S_SPLINE_POINT; pctx->cpi = 0U; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc)) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 865 "WxdkdrawRead.cpt" } } else { #line 868 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 872 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TOO_FEW_POINTS, 0); } } else { #line 876 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 879 "WxdkdrawRead.cpt" } /** Process open arc begin line. @param pctx Reader context. */ static void process_osl_oarc(wxdrd_ctx_t *pctx) { #line 891 "WxdkdrawRead.cpt" if (15 == pctx->uparts) { wxdobj_obj_init(&(pctx->styletemp), WXD_OT_O_ARC); rd_i16(pctx, 1, &((pctx->styletemp).lay)); rd_u08(pctx, 2, &((pctx->styletemp).sc[0])); rd_u08(pctx, 3, &((pctx->styletemp).sc[1])); rd_u08(pctx, 4, &((pctx->styletemp).sc[2])); rd_u16(pctx, 5, &((pctx->styletemp).lw)); rd_u08(pctx, 6, &((pctx->styletemp).ls)); correct_linestyle(&((pctx->styletemp).ls)); rd_u08(pctx, 7, &((pctx->styletemp).sl)); correct_stylelength(&((pctx->styletemp).sl)); rd_u08(pctx, 8, &((pctx->styletemp).cs)); correct_capstyle(&((pctx->styletemp).cs)); rd_u08(pctx, 9, &((pctx->styletemp).aft)); correct_arrowtype(&((pctx->styletemp).aft)); rd_u08(pctx, 10, &((pctx->styletemp).afl)); correct_arrowlength(&((pctx->styletemp).afl)); rd_u08(pctx, 11, &((pctx->styletemp).afw)); correct_arrowwidth(&((pctx->styletemp).afw)); rd_u08(pctx, 12, &((pctx->styletemp).abt)); correct_arrowtype(&((pctx->styletemp).abt)); rd_u08(pctx, 13, &((pctx->styletemp).abl)); correct_arrowlength(&((pctx->styletemp).abl)); rd_u08(pctx, 14, &((pctx->styletemp).abw)); correct_arrowwidth(&((pctx->styletemp).abw)); pctx->pouc = wxdobj_add_arc(pctx->pdrw,pctx->pgrp,0,&(pctx->styletemp)); if (NULL != pctx->pouc) { pctx->st = S_ARC; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc)) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 921 "WxdkdrawRead.cpt" } } else { #line 924 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 928 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 931 "WxdkdrawRead.cpt" } /** Read 14 or 15 style values for polygons, closed splines and closed arcs. @param pctx Reader context. @param p 1 for polylines and splines, 0 for arc. */ static void read_elements_14_15(wxdrd_ctx_t *pctx, size_t p) { #line 945 "WxdkdrawRead.cpt" if (0 != p) { rd_u16(pctx, 1, &(((pctx->styletemp).det).p.n)); } rd_i16(pctx, (p + 1), &((pctx->styletemp).lay)); rd_u08(pctx, (p + 2), &((pctx->styletemp).sc[0])); rd_u08(pctx, (p + 3), &((pctx->styletemp).sc[1])); rd_u08(pctx, (p + 4), &((pctx->styletemp).sc[2])); rd_u08(pctx, (p + 5), &((pctx->styletemp).fc[0])); rd_u08(pctx, (p + 6), &((pctx->styletemp).fc[1])); rd_u08(pctx, (p + 7), &((pctx->styletemp).fc[2])); rd_u16(pctx, (p + 8), &((pctx->styletemp).lw)); rd_u08(pctx, (p + 9), &((pctx->styletemp).ls)); correct_linestyle(&((pctx->styletemp).ls)); rd_u08(pctx, (p + 10), &((pctx->styletemp).sl)); correct_stylelength(&((pctx->styletemp).sl)); rd_u08(pctx, (p + 11), &((pctx->styletemp).js)); correct_joinstyle(&((pctx->styletemp).js)); rd_u08(pctx, (p + 12), &((pctx->styletemp).ml)); correct_miterlimit(&((pctx->styletemp).ml)); rd_u08(pctx, (p + 13), &((pctx->styletemp).fs)); correct_fillstyle(&((pctx->styletemp).fs)); #line 967 "WxdkdrawRead.cpt" } /** Process polygon begin line. @param pctx Reader context. */ static void process_osl_polygon(wxdrd_ctx_t *pctx) { #line 979 "WxdkdrawRead.cpt" if (15 == pctx->uparts) { wxdobj_obj_init(&(pctx->styletemp), WXD_OT_POLYGON); read_elements_14_15(pctx, 1); if (1 < (pctx->styletemp).det.p.n) { pctx->pouc = wxdobj_add_polyline( pctx->pdrw, pctx->pgrp, (pctx->styletemp).det.p.n, 1, &(pctx->styletemp) ); if (NULL != pctx->pouc) { pctx->st = S_POLY_POINT; pctx->cpi = 0U; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc)) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 992 "WxdkdrawRead.cpt" } } else { #line 995 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 999 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TOO_FEW_POINTS, 0); } } else { #line 1003 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 1006 "WxdkdrawRead.cpt" } /** Process closed spline begin line. @param pctx Reader context. */ static void process_osl_cspline(wxdrd_ctx_t *pctx) { #line 1018 "WxdkdrawRead.cpt" if (15 == pctx->uparts) { /* We initialize as polygon here as read_elements_14_15() writes the number of points to det.p.n. As the details of polygon and closed spline only contain point number and buffer address, this is no problem. All style values are initialized and transferred same way. */ wxdobj_obj_init(&(pctx->styletemp), WXD_OT_POLYGON); read_elements_14_15(pctx, 1); if (1 < (pctx->styletemp).det.p.n) { pctx->pouc = wxdobj_add_spline( pctx->pdrw, pctx->pgrp, (pctx->styletemp).det.p.n, 1, &(pctx->styletemp) ); if (NULL != pctx->pouc) { pctx->st = S_SPLINE_POINT; pctx->cpi = 0U; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc)) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 1038 "WxdkdrawRead.cpt" } } else { #line 1041 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 1045 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TOO_FEW_POINTS, 0); } } else { #line 1049 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 1052 "WxdkdrawRead.cpt" } /** Process closed arc begin line. @param pctx Reader context. */ static void process_osl_carc(wxdrd_ctx_t *pctx) { #line 1064 "WxdkdrawRead.cpt" if (14 == pctx->uparts) { wxdobj_obj_init(&(pctx->styletemp), WXD_OT_C_ARC); read_elements_14_15(pctx, 0); pctx->pouc = wxdobj_add_arc( pctx->pdrw, pctx->pgrp, 1, &(pctx->styletemp) ); if (NULL != pctx->pouc) { pctx->st = S_ARC; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc)) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 1074 "WxdkdrawRead.cpt" } } else { #line 1077 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 1081 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 1084 "WxdkdrawRead.cpt" } /** Read 12 style values for circles, ellipses and boxes. @param pctx Reader context. */ static void read_elements_12(wxdrd_ctx_t *pctx) { #line 1096 "WxdkdrawRead.cpt" rd_i16(pctx, 1, &((pctx->styletemp).lay)); rd_u08(pctx, 2, &((pctx->styletemp).sc[0])); rd_u08(pctx, 3, &((pctx->styletemp).sc[1])); rd_u08(pctx, 4, &((pctx->styletemp).sc[2])); rd_u08(pctx, 5, &((pctx->styletemp).fc[0])); rd_u08(pctx, 6, &((pctx->styletemp).fc[1])); rd_u08(pctx, 7, &((pctx->styletemp).fc[2])); rd_u16(pctx, 8, &((pctx->styletemp).lw)); rd_u08(pctx, 9, &((pctx->styletemp).ls)); correct_linestyle(&((pctx->styletemp).ls)); rd_u08(pctx, 10, &((pctx->styletemp).sl)); correct_stylelength(&((pctx->styletemp).sl)); rd_u08(pctx, 11, &((pctx->styletemp).fs)); correct_fillstyle(&((pctx->styletemp).fs)); #line 1111 "WxdkdrawRead.cpt" } /** Process circle begin line. @param pctx Reader context. */ static void process_osl_circle(wxdrd_ctx_t *pctx) { #line 1123 "WxdkdrawRead.cpt" if (12 == pctx->uparts) { wxdobj_obj_init(&(pctx->styletemp), WXD_OT_CIRCLE); read_elements_12(pctx); pctx->pouc = wxdobj_add_circle( pctx->pdrw, pctx->pgrp, &(pctx->styletemp) ); if (NULL != pctx->pouc) { pctx->st = S_CIRCLE; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc)) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 1133 "WxdkdrawRead.cpt" } } else { #line 1136 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 1140 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 1143 "WxdkdrawRead.cpt" } /** Process ellipse begin line. @param pctx Reader context. */ static void process_osl_ellipse(wxdrd_ctx_t *pctx) { #line 1155 "WxdkdrawRead.cpt" if (12 == pctx->uparts) { wxdobj_obj_init(&(pctx->styletemp), WXD_OT_ELLIPSE); read_elements_12(pctx); pctx->pouc = wxdobj_add_ellipse( pctx->pdrw, pctx->pgrp, &(pctx->styletemp) ); if (NULL != pctx->pouc) { pctx->st = S_ELLIPSE; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc)) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 1165 "WxdkdrawRead.cpt" } } else { #line 1168 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 1172 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 1175 "WxdkdrawRead.cpt" } /** Process box begin line. @param pctx Reader context. */ static void process_osl_box(wxdrd_ctx_t *pctx) { #line 1187 "WxdkdrawRead.cpt" if (12 == pctx->uparts) { wxdobj_obj_init(&(pctx->styletemp), WXD_OT_BOX); read_elements_12(pctx); pctx->pouc = wxdobj_add_box( pctx->pdrw, pctx->pgrp, &(pctx->styletemp) ); if (NULL != pctx->pouc) { pctx->st = S_BOX; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc)) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 1197 "WxdkdrawRead.cpt" } } else { #line 1200 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 1204 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 1207 "WxdkdrawRead.cpt" } /** Process image begin line. @param pctx Reader context. */ static void process_osl_image(wxdrd_ctx_t *pctx) { #line 1219 "WxdkdrawRead.cpt" if (5 == pctx->uparts) { wxdobj_obj_init(&(pctx->styletemp), WXD_OT_IMAGE); read_elements_05(pctx); pctx->st = S_IMAGE_DETAILS; } else { #line 1225 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 1228 "WxdkdrawRead.cpt" } /** Process filled dot begin line. @param pctx Reader context. */ static void process_osl_dot_filled(wxdrd_ctx_t *pctx) { #line 1240 "WxdkdrawRead.cpt" if (5 == pctx->uparts) { wxdobj_obj_init(&(pctx->styletemp), WXD_OT_DOT_FILLED); read_elements_05(pctx); pctx->pouc = wxdobj_add_dot(pctx->pdrw,pctx->pgrp,0,&(pctx->styletemp)); if (NULL != pctx->pouc) { pctx->st = S_DOT_FILLED; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc)) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 1248 "WxdkdrawRead.cpt" } } else { #line 1251 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 1255 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 1258 "WxdkdrawRead.cpt" } /** Process white dot begin line. @param pctx Reader context. */ static void process_osl_dot_white(wxdrd_ctx_t *pctx) { #line 1270 "WxdkdrawRead.cpt" if (5 == pctx->uparts) { wxdobj_obj_init(&(pctx->styletemp), WXD_OT_DOT_WHITE); read_elements_05(pctx); pctx->pouc = wxdobj_add_dot(pctx->pdrw,pctx->pgrp,1,&(pctx->styletemp)); if (NULL != pctx->pouc) { pctx->st = S_DOT_WHITE; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc)) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 1278 "WxdkdrawRead.cpt" } } else { #line 1281 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 1285 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 1288 "WxdkdrawRead.cpt" } /** Process object start line. @param pctx Reader context. @param il Input line to process. */ static void process_line_objstart(wxdrd_ctx_t *pctx, char *il) { int8_t ot; #line 1305 "WxdkdrawRead.cpt" for (size_t i = 0; i < pctx->nparts; i++) { (pctx->parts)[i] = NULL; } pctx->uparts = dk4str8_tokenize(pctx->parts, pctx->nparts, il, NULL, NULL); if (0 < pctx->uparts) { ot = 0; rd_i08(pctx, 0, &ot); if (1 == pctx->cc) { switch ( (int)ot ) { case WXD_OT_CONFIG : { #line 1313 "WxdkdrawRead.cpt" process_osl_config(pctx); } break; case WXD_OT_GROUP_BEGIN : { #line 1316 "WxdkdrawRead.cpt" process_osl_group_begin(pctx); } break; case WXD_OT_GROUP_END : { #line 1319 "WxdkdrawRead.cpt" process_osl_group_end(pctx); } break; case WXD_OT_TEXT : { #line 1322 "WxdkdrawRead.cpt" process_osl_textlabel(pctx); } break; case WXD_OT_POLYLINE : { #line 1325 "WxdkdrawRead.cpt" process_osl_polyline(pctx); } break; case WXD_OT_O_SPLINE : { #line 1328 "WxdkdrawRead.cpt" process_osl_ospline(pctx); } break; case WXD_OT_O_ARC : { #line 1331 "WxdkdrawRead.cpt" process_osl_oarc(pctx); } break; case WXD_OT_POLYGON : { #line 1334 "WxdkdrawRead.cpt" process_osl_polygon(pctx); } break; case WXD_OT_C_SPLINE : { #line 1337 "WxdkdrawRead.cpt" process_osl_cspline(pctx); } break; case WXD_OT_C_ARC : { #line 1340 "WxdkdrawRead.cpt" process_osl_carc(pctx); } break; case WXD_OT_CIRCLE : { #line 1343 "WxdkdrawRead.cpt" process_osl_circle(pctx); } break; case WXD_OT_ELLIPSE : { #line 1346 "WxdkdrawRead.cpt" process_osl_ellipse(pctx); } break; case WXD_OT_BOX : { #line 1349 "WxdkdrawRead.cpt" process_osl_box(pctx); } break; case WXD_OT_IMAGE : { #line 1352 "WxdkdrawRead.cpt" process_osl_image(pctx); } break; case WXD_OT_DOT_FILLED : { #line 1355 "WxdkdrawRead.cpt" process_osl_dot_filled(pctx); } break; case WXD_OT_DOT_WHITE : { #line 1358 "WxdkdrawRead.cpt" process_osl_dot_white(pctx); } break; default : { #line 1361 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_OBJTYPE, 0); } break; } } } else { #line 1367 "WxdkdrawRead.cpt" /* Skip empty line */ } #line 1370 "WxdkdrawRead.cpt" } /** Correct font index. @param pfi Address of font index variable to correct. */ static void correct_fontindex(uint8_t *pfi) { if ((uint8_t)34U < *pfi) { *pfi = (uint8_t)34U; } } /** Correct font size. @param pfs Address of font size variable to correct. */ static void correct_fontsize(uint16_t *pfs) { if ((uint16_t)1U > *pfs) { *pfs = (uint16_t)1U; } } /** Correct text align. @param pta Address of text align variable to correct. */ static void correct_textalign(uint8_t *pta) { if ((uint8_t)(WXD_TA_RIGHT) < *pta) { *pta = (uint8_t)(WXD_TA_RIGHT); } } /** Process details line 1 for text (coordinates). @param pctx Reader context. */ static void process_det_text1(wxdrd_ctx_t *pctx) { #line 1423 "WxdkdrawRead.cpt" if (7 == pctx->uparts) { rd_u08(pctx, 0, &((pctx->styletemp).det.t.find)); correct_fontindex(&((pctx->styletemp).det.t.find)); rd_u16(pctx, 1, &((pctx->styletemp).det.t.fsz)); correct_fontsize(&((pctx->styletemp).det.t.fsz)); rd_u08(pctx, 2, &((pctx->styletemp).det.t.al)); correct_textalign(&((pctx->styletemp).det.t.al)); rd_u08(pctx, 3, &((pctx->styletemp).det.t.fl)); rd_i32(pctx, 4, &((pctx->styletemp).det.t.x)); rd_i32(pctx, 5, &((pctx->styletemp).det.t.y)); rd_i16(pctx, 6, &((pctx->styletemp).det.t.a)); pctx->st = S_TEXT_EXPORT; } else { #line 1437 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 1440 "WxdkdrawRead.cpt" } /** Process details line 2 for text (export text). @param pctx Reader context. */ static void process_det_text2(wxdrd_ctx_t *pctx, const char *il) { wxChar wxb[1024]; size_t const szwxb = DK4_SIZEOF(wxb,wxChar); #line 1454 "WxdkdrawRead.cpt" if (0 != dk4recwx_utf8_to_wxchar(wxb, szwxb, &(il[1]), NULL)) { pctx->pouc = wxdobj_add_textlabel( pctx->pdrw, pctx->pgrp, wxb, &(pctx->styletemp) ); if (NULL != pctx->pouc) { ((pctx->pouc)->det).t.find = (pctx->styletemp).det.t.find; ((pctx->pouc)->det).t.fsz = (pctx->styletemp).det.t.fsz; ((pctx->pouc)->det).t.al = (pctx->styletemp).det.t.al; ((pctx->pouc)->det).t.fl = (pctx->styletemp).det.t.fl; ((pctx->pouc)->det).t.x = (pctx->styletemp).det.t.x; ((pctx->pouc)->det).t.y = (pctx->styletemp).det.t.y; ((pctx->pouc)->det).t.a = (pctx->styletemp).det.t.a; ((pctx->pouc)->det).t.font = NULL; pctx->st = S_TEXT_SCREEN; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc)) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 1470 "WxdkdrawRead.cpt" } } else { #line 1473 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 1477 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_RECODE_TEXT, 0); } #line 1480 "WxdkdrawRead.cpt" } /** Process details line 3 for text (screen text). @param pctx Reader context. @param il Input line. */ static void process_det_text3(wxdrd_ctx_t *pctx, const char *il) { wxChar wxb[1024]; size_t const szwxb = DK4_SIZEOF(wxb,wxChar); #line 1495 "WxdkdrawRead.cpt" if ('\0' != il[1]) { if (0 != dk4recwx_utf8_to_wxchar(wxb, szwxb, &(il[1]), NULL)) { if (NULL != pctx->pouc) { ((pctx->pouc)->det).t.tsc = dk4strx_dup(wxb, NULL); if (NULL == ((pctx->pouc)->det).t.tsc) { #line 1500 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 1504 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } else { #line 1508 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_RECODE_TEXT, 0); } } else { if (NULL != pctx->pouc) { ((pctx->pouc)->det).t.tsc = NULL; } else { #line 1516 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } pctx->st = S_OBJ_START; #line 1521 "WxdkdrawRead.cpt" } /** Process details line for polyline (point coordinates). @param pctx Reader context. */ static void process_det_poly(wxdrd_ctx_t *pctx) { #line 1533 "WxdkdrawRead.cpt" if (NULL != pctx->pouc) { if (2 == pctx->uparts) { rd_i32(pctx, 0, &((((pctx->pouc)->det).p.p)[pctx->cpi].x)); rd_i32(pctx, 1, &((((pctx->pouc)->det).p.p)[pctx->cpi].y)); } else { #line 1539 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } pctx->cpi += 1U; if (pctx->cpi >= ((pctx->pouc)->det).p.n) { pctx->st = S_OBJ_START; #line 1544 "WxdkdrawRead.cpt" } } else { #line 1547 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } #line 1550 "WxdkdrawRead.cpt" } /** Correct X-spline s coefficient of control point. @param ps Address of s value variable to correct. */ static void correct_svalue(double *ps) { if (-1.0 > *ps) { *ps = -1.0; } else { if (1.0 < *ps) { *ps = 1.0; } } } /** Process details line for spline (control point coordinates and s value). @param pctx Reader context. */ static void process_det_spline(wxdrd_ctx_t *pctx) { #line 1580 "WxdkdrawRead.cpt" if (NULL != pctx->pouc) { if (3 == pctx->uparts) { rd_i32(pctx, 0, &((((pctx->pouc)->det).s.p)[pctx->cpi].x)); rd_i32(pctx, 1, &((((pctx->pouc)->det).s.p)[pctx->cpi].y)); rd_dbl(pctx, 2, &((((pctx->pouc)->det).s.p)[pctx->cpi].s)); correct_svalue(&((((pctx->pouc)->det).s.p)[pctx->cpi].s)); } else { #line 1588 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } pctx->cpi += 1U; if (pctx->cpi >= ((pctx->pouc)->det).s.n) { pctx->st = S_OBJ_START; #line 1593 "WxdkdrawRead.cpt" } } else { #line 1596 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } #line 1599 "WxdkdrawRead.cpt" } /** Process details line for arc. @param pctx Reader context. */ static void process_det_arc(wxdrd_ctx_t *pctx) { #line 1611 "WxdkdrawRead.cpt" if (NULL != pctx->pouc) { if (6 == pctx->uparts) { rd_i32(pctx, 0, &(((pctx->pouc)->det).a.x1)); rd_i32(pctx, 1, &(((pctx->pouc)->det).a.y1)); rd_i32(pctx, 2, &(((pctx->pouc)->det).a.x2)); rd_i32(pctx, 3, &(((pctx->pouc)->det).a.y2)); rd_i32(pctx, 4, &(((pctx->pouc)->det).a.x3)); rd_i32(pctx, 5, &(((pctx->pouc)->det).a.y3)); wxdarc_calculation( &(((pctx->pouc)->det).a.x), &(((pctx->pouc)->det).a.y), &(((pctx->pouc)->det).a.r), &(((pctx->pouc)->det).a.a), &(((pctx->pouc)->det).a.b), &(((pctx->pouc)->det).a.d), ((pctx->pouc)->det).a.x1, ((pctx->pouc)->det).a.y1, ((pctx->pouc)->det).a.x2, ((pctx->pouc)->det).a.y2, ((pctx->pouc)->det).a.x3, ((pctx->pouc)->det).a.y3 ); } else { #line 1629 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } else { #line 1633 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } pctx->st = S_OBJ_START; #line 1637 "WxdkdrawRead.cpt" } /** Correct a radius. @param pr Address of radius variable to correct. @param pctx Reader context. */ static void correct_radius(uint32_t *pr, wxdrd_ctx_t *pctx) { if ((uint32_t)1UL > *pr) { *pr = (uint32_t)15875UL; (pctx->pstat)->mod = 1; #line 1652 "WxdkdrawRead.cpt" } } /** Correct dot diameter. @param pd Address of dot diameter variable to correct. @param pctx Reader context. */ static void correct_dotdiameter(uint16_t *pd, wxdrd_ctx_t *pctx) { if ((uint16_t)1U > *pd) { *pd = (uint16_t)1U; (pctx->pstat)->mod = 1; #line 1668 "WxdkdrawRead.cpt" } } static void correct_bounding_box(Wxd_bb_t *pbb, wxdrd_ctx_t *pctx) { if (pbb->xl >= pbb->xr) { (pctx->pstat)->mod = 1; #line 1679 "WxdkdrawRead.cpt" if ((DK4_I32_MAX - (int32_t)15875L) >= pbb->xl) { pbb->xr = pbb->xl + (int32_t)15875L; } else { pbb->xl = pbb->xr - (int32_t)15875L; } } if (pbb->yb >= pbb->yt) { (pctx->pstat)->mod = 1; #line 1688 "WxdkdrawRead.cpt" if ((DK4_I32_MAX - (int32_t)15875L) >= pbb->yb) { pbb->yt = pbb->yb + (int32_t)15875L; } else { pbb->yb = pbb->yt - (int32_t)15875L; } } } /** Process details line for circle. @param pctx Reader context. */ static void process_det_circle(wxdrd_ctx_t *pctx) { #line 1707 "WxdkdrawRead.cpt" if (NULL != pctx->pouc) { if (3 == pctx->uparts) { rd_i32(pctx, 0, &(((pctx->pouc)->det).e.x)); rd_i32(pctx, 1, &(((pctx->pouc)->det).e.y)); rd_u32(pctx, 2, &(((pctx->pouc)->det).e.rx)); correct_radius(&(((pctx->pouc)->det).e.rx), pctx); ((pctx->pouc)->det).e.ry = ((pctx->pouc)->det).e.rx; } else { #line 1716 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } else { #line 1720 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } pctx->st = S_OBJ_START; #line 1724 "WxdkdrawRead.cpt" } /** Process details line for colour filled dot. @param pctx Reader context. */ static void process_det_dot_filled(wxdrd_ctx_t *pctx) { #line 1736 "WxdkdrawRead.cpt" if (NULL != pctx->pouc) { if (3 == pctx->uparts) { rd_i32(pctx, 0, &(((pctx->pouc)->det).d.x)); rd_i32(pctx, 1, &(((pctx->pouc)->det).d.y)); rd_u16(pctx, 2, &(((pctx->pouc)->det).d.d)); correct_dotdiameter(&(((pctx->pouc)->det).d.d), pctx); } else { #line 1744 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } else { #line 1748 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } pctx->st = S_OBJ_START; #line 1752 "WxdkdrawRead.cpt" } /** Process details line for white filled dot. @param pctx Reader context. */ static void process_det_dot_white(wxdrd_ctx_t *pctx) { #line 1764 "WxdkdrawRead.cpt" if (NULL != pctx->pouc) { if (4 == pctx->uparts) { rd_i32(pctx, 0, &(((pctx->pouc)->det).d.x)); rd_i32(pctx, 1, &(((pctx->pouc)->det).d.y)); rd_u16(pctx, 2, &(((pctx->pouc)->det).d.d)); correct_dotdiameter(&(((pctx->pouc)->det).d.d), pctx); rd_u16(pctx, 3, &((pctx->pouc)->lw)); correct_dotdiameter(&((pctx->pouc)->lw), pctx); } else { #line 1774 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } else { #line 1778 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } pctx->st = S_OBJ_START; #line 1782 "WxdkdrawRead.cpt" } /** Process details line for ellipse. @param pctx Reader context. */ static void process_det_ellipse(wxdrd_ctx_t *pctx) { #line 1794 "WxdkdrawRead.cpt" if (NULL != pctx->pouc) { if (5 == pctx->uparts) { rd_i32(pctx, 0, &(((pctx->pouc)->det).e.x)); rd_i32(pctx, 1, &(((pctx->pouc)->det).e.y)); rd_u32(pctx, 2, &(((pctx->pouc)->det).e.rx)); correct_radius(&(((pctx->pouc)->det).e.rx), pctx); rd_u32(pctx, 3, &(((pctx->pouc)->det).e.ry)); correct_radius(&(((pctx->pouc)->det).e.ry), pctx); rd_i16(pctx, 4, &(((pctx->pouc)->det).e.a)); } else { #line 1805 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } else { #line 1809 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } pctx->st = S_OBJ_START; #line 1813 "WxdkdrawRead.cpt" } /** Process details line for box. @param pctx Reader context. */ static void process_det_box(wxdrd_ctx_t *pctx) { uint32_t w; uint32_t h; #line 1827 "WxdkdrawRead.cpt" if (NULL != pctx->pouc) { if (5 == pctx->uparts) { rd_i32(pctx, 0, &(((pctx->pouc)->det).b.b.xl)); rd_i32(pctx, 1, &(((pctx->pouc)->det).b.b.xr)); rd_i32(pctx, 2, &(((pctx->pouc)->det).b.b.yb)); rd_i32(pctx, 3, &(((pctx->pouc)->det).b.b.yt)); rd_u32(pctx, 4, &(((pctx->pouc)->det).b.r)); wxdobj_bb_correct(&(((pctx->pouc)->det).b.b)); if (wxdobj_bb_is_null_area(&(((pctx->pouc)->det).b.b))) { #line 1837 "WxdkdrawRead.cpt" #if 0 wxd_read_error(pctx, WXDRD_E_BOX_NO_AREA, 0); #endif correct_bounding_box(&(((pctx->pouc)->det).b.b), pctx); } w = (uint32_t)(((pctx->pouc)->det).b.b.xr - ((pctx->pouc)->det).b.b.xl); h = (uint32_t)(((pctx->pouc)->det).b.b.yt - ((pctx->pouc)->det).b.b.yb); if (h < w) { w = h; } w = w / (uint32_t)2UL; if (((pctx->pouc)->det).b.r > w) { ((pctx->pouc)->det).b.r = w; } } else { #line 1853 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } } else { #line 1857 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } pctx->st = S_OBJ_START; #line 1861 "WxdkdrawRead.cpt" } static int32_t add_signed_unsigned_32(wxdrd_ctx_t *pctx, int32_t s, uint32_t u, size_t te) { dk4_er_t er; uint32_t sum; uint32_t x; int32_t back = (int32_t)0L; #line 1874 "WxdkdrawRead.cpt" dk4error_init(&er); if (0 <= s) { #line 1876 "WxdkdrawRead.cpt" sum = dk4ma_uint32_t_add((uint32_t)s, u, &er); if (DK4_E_NONE == er.ec) { if ((uint32_t)(DK4_I32_MAX) >= sum) { back = (int32_t)sum; } else { #line 1882 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_COORD_OVERFLOW, te); } } else { #line 1886 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_COORD_OVERFLOW, te); } } else { #line 1890 "WxdkdrawRead.cpt" x = (uint32_t)dk4ma_int32_t_abs(s, &er); if (DK4_E_NONE != er.ec) { #line 1892 "WxdkdrawRead.cpt" x = (uint32_t)(DK4_I32_MAX); x += (uint32_t)1U; } dk4error_init(&er); sum = dk4ma_uint32_t_sub(u, x, &er); if (DK4_E_NONE == er.ec) { if ((uint32_t)(DK4_I32_MAX) >= sum) { back = (int32_t)sum; } else { #line 1902 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_COORD_OVERFLOW, te); } } else { #line 1906 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_COORD_OVERFLOW, te); } } #line 1909 "WxdkdrawRead.cpt" return back; } /** Process details line 1 for image (coordinates and flags). @param pctx Reader context. */ static void process_det_image1(wxdrd_ctx_t *pctx) { uint32_t w; uint32_t h; #line 1924 "WxdkdrawRead.cpt" if (7 == pctx->uparts) { rd_u16(pctx, 0, &((pctx->styletemp).det.i.fl)); rd_i08(pctx, 1, &((pctx->styletemp).det.i.r2g)); rd_i08(pctx, 2, &((pctx->styletemp).det.i.r2c)); rd_i32(pctx, 3, &((pctx->styletemp).det.i.br.xl)); rd_i32(pctx, 4, &((pctx->styletemp).det.i.br.yb)); rd_u32(pctx, 5, &w); rd_u32(pctx, 6, &h); (pctx->styletemp).det.i.br.xr = add_signed_unsigned_32( pctx, (pctx->styletemp).det.i.br.xl, w, 5 ); (pctx->styletemp).det.i.br.yt = add_signed_unsigned_32( pctx, (pctx->styletemp).det.i.br.yb, h, 6 ); pctx->st = S_IMAGE_FILENAME; if ( ((pctx->styletemp).det.i.br.xr == (pctx->styletemp).det.i.br.xl) || ((pctx->styletemp).det.i.br.yt == (pctx->styletemp).det.i.br.yb) ) { wxd_read_error(pctx, WXDRD_E_COORD_OVERFLOW, 0); } } else { #line 1947 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_TEXT_PARTS, 0); } #line 1950 "WxdkdrawRead.cpt" } /** Process details line 2 for image (file name). @param pctx Reader context. */ static void process_det_image2(wxdrd_ctx_t *pctx, const char *il) { wxChar fnb[DK4_MAX_PATH]; wxChar wxb[1024]; size_t const szwxb = DK4_SIZEOF(wxb,wxChar); size_t const szfnb = DK4_SIZEOF(fnb,wxChar); int ok = 0; #line 1967 "WxdkdrawRead.cpt" if ('\0' != il[1]) { if (0 != dk4recwx_utf8_to_wxchar(wxb, szwxb, &(il[1]), NULL)) { if ( (0 == dk4strx_path_is_absolute(wxb)) && (NULL != pctx->pstat->dirn) ) { if (0 != dk4strx_cpy_s(fnb, szfnb, (pctx->pstat->dirn), NULL)) { if (0 != dk4strx_path_append(fnb, szfnb, wxb, NULL)) { ok = 1; #if TRACE_DEBUG #if DK4_SIZEOF_WXCHAR > 1 #line 1980 "WxdkdrawRead.cpt" #else #line 1982 "WxdkdrawRead.cpt" #endif #endif } else { #line 1986 "WxdkdrawRead.cpt" /* ERROR: File name too long */ wxd_read_error(pctx, WXDRD_E_FILENAME_TOO_LONG, 0); } } else { #line 1991 "WxdkdrawRead.cpt" /* ERROR: Directory name too long */ wxd_read_error(pctx, WXDRD_E_FILENAME_TOO_LONG, 0); } } else { if (0 != dk4strx_cpy_s(fnb, szfnb, wxb, NULL)) { ok = 1; #if TRACE_DEBUG #if DK4_SIZEOF_WXCHAR > 1 #line 2001 "WxdkdrawRead.cpt" #else #line 2003 "WxdkdrawRead.cpt" #endif #endif } else { #line 2007 "WxdkdrawRead.cpt" /* ERROR: Name too long */ wxd_read_error(pctx, WXDRD_E_FILENAME_TOO_LONG, 0); } } if (0 != ok) { pctx->pouc = wxdobj_add_image( pctx->pdrw, pctx->pgrp, fnb, &(pctx->styletemp) ); if (NULL != pctx->pouc) { ((pctx->pouc)->det).i.fl = (pctx->styletemp).det.i.fl; ((pctx->pouc)->det).i.r2g = (pctx->styletemp).det.i.r2g; ((pctx->pouc)->det).i.r2c = (pctx->styletemp).det.i.r2c; ((pctx->pouc)->det).i.br.xl = (pctx->styletemp).det.i.br.xl; ((pctx->pouc)->det).i.br.yb = (pctx->styletemp).det.i.br.yb; ((pctx->pouc)->det).i.br.xr = (pctx->styletemp).det.i.br.xr; ((pctx->pouc)->det).i.br.yt = (pctx->styletemp).det.i.br.yt; if (0 == wxdobj_find_layer_structure(pctx->pdrw, pctx->pouc) ) { wxd_read_error(pctx, WXDRD_E_MEMORY, 0); #line 2026 "WxdkdrawRead.cpt" } } else { #line 2029 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_MEMORY, 0); } } } else { #line 2034 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_RECODE_FILENAME, 0); } } else { #line 2038 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_EMPTY_FILENAME, 0); } pctx->st = S_OBJ_START; #line 2042 "WxdkdrawRead.cpt" } /** Process details line. @param pctx Reader context. @param il Input line to process. */ static void process_line_details(wxdrd_ctx_t *pctx, char *il) { #line 2056 "WxdkdrawRead.cpt" for (size_t i = 0; i < pctx->nparts; i++) { (pctx->parts)[i] = NULL; } if (0 != must_split_line(pctx)) { #line 2058 "WxdkdrawRead.cpt" pctx->uparts = dk4str8_tokenize(pctx->parts,pctx->nparts,il,NULL,NULL); #line 2060 "WxdkdrawRead.cpt" } else { #line 2062 "WxdkdrawRead.cpt" pctx->uparts = 0; } switch (pctx->st) { case S_TEXT_DETAILS : { process_det_text1(pctx); } break; case S_TEXT_EXPORT : { process_det_text2(pctx, il); } break; case S_TEXT_SCREEN : { process_det_text3(pctx, il); } break; case S_POLY_POINT : { process_det_poly(pctx); } break; case S_SPLINE_POINT : { process_det_spline(pctx); } break; case S_ARC : { process_det_arc(pctx); } break; case S_CIRCLE : { process_det_circle(pctx); } break; case S_DOT_FILLED : { process_det_dot_filled(pctx); } break; case S_DOT_WHITE : { process_det_dot_white(pctx); } break; case S_ELLIPSE : { process_det_ellipse(pctx); } break; case S_BOX : { process_det_box(pctx); } break; case S_IMAGE_DETAILS : { process_det_image1(pctx); } break; case S_IMAGE_FILENAME : { process_det_image2(pctx, il); } break; default : { #line 2105 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_READER_STATE, 0); } break; } #line 2108 "WxdkdrawRead.cpt" } static void apply_input_line(wxdrd_ctx_t *pctx, char *il) { #line 2117 "WxdkdrawRead.cpt" if (1UL == pctx->lineno) { apply_first_line(pctx, il); } else { if (0 == line_starts_with_space(il)) { if (S_OBJ_START == pctx->st) { pctx->pouc = NULL; pctx->uparts = 0; process_line_objstart(pctx, il); } else { #line 2128 "WxdkdrawRead.cpt" /* Details line expected */ wxd_read_error(pctx, WXDRD_E_EXPECTED_DETAILS, 0); } } else { if (S_OBJ_START != pctx->st) { process_line_details(pctx, il); } else { #line 2137 "WxdkdrawRead.cpt" /* Object start line expected */ wxd_read_error(pctx, WXDRD_E_EXPECTED_OBJSTART, 0); } } } #line 2142 "WxdkdrawRead.cpt" } /** Apply input file contents to current drawing. @param pctx Context, prepared to read drawing or symbol. @return 1 on success, 0 on error. */ static int apply_input_file(wxdrd_ctx_t *pctx) { char ib[1024]; /* Input buffer */ char *parts[32]; int back; #line 2159 "WxdkdrawRead.cpt" back = 1; pctx->back = &back; pctx->parts = parts; pctx->nparts = 32; pctx->uparts = 0; pctx->cc = 1; while (1 == pctx->cc) { if (NULL != fgets(ib, sizeof(ib), pctx->fin)) { if (ULONG_MAX > pctx->lineno) { pctx->lineno += 1UL; } if ('\0' != ib[0]) { dk4str8_delnl(&(ib[1])); } #line 2170 "WxdkdrawRead.cpt" #line 2171 "WxdkdrawRead.cpt" apply_input_line(pctx, ib); } else { /* No more lines available */ pctx->cc = 0; #line 2177 "WxdkdrawRead.cpt" } } if ((1 == back) && (S_OBJ_START != pctx->st)) { #line 2180 "WxdkdrawRead.cpt" wxd_read_error(pctx, WXDRD_E_READER_STATE, 0); } #line 2183 "WxdkdrawRead.cpt" return back; } Wxd_drawing_t * wxdrd_read_file(FILE *fin, wxdrd_status_t *pstat) { wxdrd_ctx_t ctx; Wxd_drawing_t *back = NULL; #line 2194 "WxdkdrawRead.cpt" if ((NULL != fin) && (NULL != pstat)) { back = wxdobj_drw_new(); if (NULL != back) { ctx_init(&ctx); ctx.pdrw = back; ctx.fin = fin; ctx.pstat = pstat; ctx.lineno = 0UL; ctx.issym = 0; if (0 != apply_input_file(&ctx)) { back->cx = (back->bb).xl / (int32_t)2L + (back->bb).xr / (int32_t)2L; back->cy = (back->bb).yb / (int32_t)2L + (back->bb).yt / (int32_t)2L; } else { wxdobj_drw_delete(back); back = NULL; } } else { #line 2215 "WxdkdrawRead.cpt" pstat->ec = WXDRD_E_MEMORY; } } else { #line 2219 "WxdkdrawRead.cpt" if (NULL != pstat) { pstat->ec = WXDRD_E_INVALID_ARGS; } } #line 2224 "WxdkdrawRead.cpt" return back; } Wxd_object_t * wxdrd_read_symbol(Wxd_drawing_t *pdrw, FILE *fin, wxdrd_status_t *pstat) { wxdrd_ctx_t ctx; Wxd_object_t *back = NULL; #line 2235 "WxdkdrawRead.cpt" if ((NULL != pdrw) && (NULL != fin) && (NULL != pstat)) { (pstat->bb).xl = 0L; (pstat->bb).xr = 0L; (pstat->bb).yb = 0L; (pstat->bb).yt = 0L; ctx_init(&ctx); ctx.pdrw = pdrw; ctx.fin = fin; ctx.pstat = pstat; ctx.lineno = 0UL; ctx.issym = 1; ctx.pgrp = wxdobj_drw_add_group(pdrw, NULL); if (NULL != ctx.pgrp) { if (0 != apply_input_file(&ctx)) { #line 2249 "WxdkdrawRead.cpt" back = ctx.pgrp; } else { #line 2252 "WxdkdrawRead.cpt" wxdobj_obj_delete_from_drawing(pdrw, ctx.pgrp); } } else { #line 2256 "WxdkdrawRead.cpt" pstat->ec = WXDRD_E_MEMORY; } } else { #line 2260 "WxdkdrawRead.cpt" if (NULL != pstat) { pstat->ec = WXDRD_E_INVALID_ARGS; } } #line 2265 "WxdkdrawRead.cpt" return back; } void wxdrd_status_init(wxdrd_status_t *pstat) { #if DK4_SIZEOF_WXCHAR <= 1 dkChar blang[32]; dkChar bregi[32]; size_t const szblang = DK4_SIZEOF(blang,dkChar); size_t const szbregi = DK4_SIZEOF(bregi,dkChar); int enc; #endif #line 2281 "WxdkdrawRead.cpt" if (NULL != pstat) { pstat->dirn = NULL; pstat->ln = 0UL; pstat->ec = WXDRD_E_NONE; pstat->te = (size_t)0U; #if DK4_SIZEOF_WXCHAR > 1 #if DK4_SIZEOF_WXCHAR > 2 pstat->wxe = DK4_ENCODING_32; #else pstat->wxe = DK4_ENCODING_UTF16; #endif #else pstat->wxe = DK4_FILE_ENCODING_UTF8; if (0 != dk4loc_get_settings(blang,szblang,bregi,szbregi,&enc,NULL)) { pstat->wxe = enc; } #endif pstat->mod = 0; #line 2299 "WxdkdrawRead.cpt" } #if TRACE_DEBUG else { #line 2302 "WxdkdrawRead.cpt" } #endif #line 2305 "WxdkdrawRead.cpt" } /* vim: set ai sw=4 ts=4 : */