%% options copyright owner = Dirk Krause copyright year = 2018-xxxx SPDX-License-Identifier: BSD-3-Clause %% header #ifndef DK4APP_H_INCLUDED #include "dk4app.h" #endif #ifndef WXDTYPES_H_INCLUDED #include "wxdtypes.h" #endif #ifdef __cplusplus extern "C" { #endif /** Open a drawing from file. @param fn File name. @param job Job structure. @return Valid pointer to drawing on success, NULL on error. */ wxd_drawing_t * wxdrd_open_from_file(const dkChar *fn, wxd2lat_job_t *job); /** Open a new empty drawing. @return Valid pointer to drawing on success, NULL on error. */ wxd_drawing_t * wxdrd_open_empty(void); /** Apply file contents to empty drawing. @param drw Drawing to modify. @param fipo File pointer, opened for text reading. @param fn File name, may be NULL. @param job Job structure. @return 1 on success, 0 on error. */ int wxdrd_apply_file( wxd_drawing_t *drw, FILE *fipo, const dkChar *fn, wxd2lat_job_t *job ); /** Close drawing and release resources. @param drw Drawing to close. */ void wxdrd_close(wxd_drawing_t *drw); #ifdef __cplusplus } #endif /* vim: set ai sw=4 ts=4 : */ %% module #include "wxd2lat.h" $!trace-include /** Context used while applying file contents. For initialization search for text INITCONTEXT . */ typedef struct { wxd_object_t tobj; /**< Temporary object filled from line. */ wxd_object_t *pobj; /**< Object currently created. */ char **parts; /**< Tokens from input line. */ dk4_app_t *app; /**< Application structure for diagnostics. */ const dkChar * const *msg; /**< Localized message texts. */ const dkChar *fn; /**< File name currently processed. */ wxd_drawing_t *drw; /**< Drawing to modify. */ dk4_um_t grdepth; /**< Grouping depth. */ dk4_um_t lineno; /**< Current line number to process. */ size_t szparts; /**< Number of elements in parts array. */ size_t nparts; /**< Number of elements used in parts array. */ size_t sz_msg; /**< Number of texts in msg array. */ uint16_t curp; /**< Index of current point to add. */ int st; /**< Reader state. */ int cc; /**< Continue: 1=yes, 0=finished, 2=abort. */ int back; /**< Reader process result */ } wxd_reader_context_t; /** Reader states */ enum { /** Error occured, can not continue. */ ST_ERROR = -1 , /** Expecting first line containing file format info. */ ST_FIRSTLINE = 0 , /** Expecting line to start an object. */ ST_OBJECT_LINE , /** Expecting details line. */ ST_DETAIL_LINE , /** Expecting text to export. */ ST_TEXT_EXPORT , /** Expecting text to show on screen. */ ST_TEXT_SCREEN , /** Expecting image file name. */ ST_IMAGE_NAME , /** Attempt to resume processing. */ ST_RESUME }; /** Constant text fragments used by module. */ static const char * const wxdrd_kwnl8[] = { $!string-table # # 0 Keyword wxd # WXD $!end }; static void wxd_object_initialize(wxd_object_t *pobj) { DK4_MEMRES(pobj,sizeof(wxd_object_t)); pobj->lino = (dk4_um_t)0UL; } void wxdrd_close(wxd_drawing_t *drw) { wxd_object_t *obj; if (NULL != drw) { if (NULL != drw->s_flat) { if (NULL != drw->i_flat) { dk4sto_it_reset(drw->i_flat); do { obj = (wxd_object_t *)dk4sto_it_next(drw->i_flat); if (NULL != obj) { wxd2lat_object_delete(obj); } } while(NULL != obj); dk4sto_it_close(drw->i_flat); } dk4sto_close(drw->s_flat); } dk4mem_free(drw); } } /** Initialize a drawing after allocating the memory. @param drw Drawing to initialize. */ static void wxdrd_initialize_empty_drawing(wxd_drawing_t *drw) { drw->s_flat = NULL; drw->i_flat = NULL; drw->bbxl = drw->bbxr = drw->bbyb = drw->bbyt = 0.0; drw->fv_maj = 1; drw->fv_min = 0; drw->baselw = 0.45; } wxd_drawing_t * wxdrd_open_empty(void) { wxd_drawing_t *back = NULL; int ok = 0; back = dk4mem_new(wxd_drawing_t,1,NULL); if (NULL != back) { wxdrd_initialize_empty_drawing(back); back->s_flat = dk4sto_open(NULL); if (NULL != back->s_flat) { dk4sto_set_comp(back->s_flat, wxd2lat_compare_object, 0); back->i_flat = dk4sto_it_open(back->s_flat, NULL); if (NULL != back->i_flat) { ok = 1; } } if (0 == ok) { wxdrd_close(back); back = NULL; } } return back; } /** Check drawing file format version against version given by numbers. @param drw Drawing to check. @param maj Major number of version to compare against. @param min Minor number of version to compare against. @return 1 if drawing version is higher, 0 for equal versions, -1 if drawing version is less than specified version. */ static int wxdrd_check_version(wxd_drawing_t *drw, uint16_t maj, uint16_t min) { int back = 0; if (drw->fv_maj > maj) { back = 1; } else { if (drw->fv_maj < maj) { back = -1; } else { if (drw->fv_min > min) { back = 1; } else { if (drw->fv_min < min) { back = -1; } } } } return back; } /** Check whether a character is a white space. @param c Character to test. @return 1 for space or tabulator, 0 otherwise. */ static int is_whsp(char c) { if (' ' == c) return 1; if ('\t' == c) return 1; return 0; } /** Read double value from one of the parts, if we can still continue. @param rp Address of destination variable. @param pctx Context to use. @param pind Index of source text in parts array. */ static void wxdrd_input_double( double *rp, wxd_reader_context_t *pctx, size_t pind ) { const char *ep = NULL; double v = 0.0; int res = 0; if (1 == pctx->cc) { res = dk4ma_input_c8_double(&v, pctx->parts[pind], &ep, 1, NULL); if (0 != res) { *rp = v; } else { pctx->cc = -1; /* ERROR: Syntax */ #if DK4_CHAR_SIZE == 1 dk4app_log_3( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 22, 23, pctx->parts[pind] ); #else /* ##### TODO: ERROR Message */ #endif } } } static void wxdrd_input_u8( uint8_t *rp, wxd_reader_context_t *pctx, size_t pind ) { const char *ep = NULL; int res = 0; uint8_t v = 0U; res = dk4ma_input_c8_dec_u8(&v, pctx->parts[pind], &ep, 1, NULL); if (0 != res) { *rp = v; } else { pctx->cc = -1; /* ERROR: Syntax */ #if DK4_CHAR_SIZE == 1 dk4app_log_3( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 82, 83, pctx->parts[pind] ); #else /* ##### TODO: ERROR message */ #endif } } static void wxdrd_input_i8( int8_t *rp, wxd_reader_context_t *pctx, size_t pind ) { const char *ep = NULL; int res = 0; int8_t v = 0U; res = dk4ma_input_c8_dec_i8(&v, pctx->parts[pind], &ep, 1, NULL); if (0 != res) { *rp = v; } else { pctx->cc = -1; /* ERROR: Syntax */ #if DK4_CHAR_SIZE == 1 dk4app_log_3( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 84, 85, pctx->parts[pind] ); #else /* ##### ERROR: Syntax */ #endif } } static void wxdrd_input_u16( uint16_t *rp, wxd_reader_context_t *pctx, size_t pind ) { const char *ep = NULL; int res = 0; uint16_t v = 0U; res = dk4ma_input_c8_dec_u16(&v, pctx->parts[pind], &ep, 1, NULL); if (0 != res) { *rp = v; } else { pctx->cc = -1; /* ERROR: Syntax */ #if DK4_CHAR_SIZE == 1 dk4app_log_3( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 86, 87, pctx->parts[pind] ); #else /* ##### TODO: Error message */ #endif } } static void wxdrd_input_i16( int16_t *rp, wxd_reader_context_t *pctx, size_t pind ) { const char *ep = NULL; int res = 0; int16_t v = 0U; res = dk4ma_input_c8_dec_i16(&v, pctx->parts[pind], &ep, 1, NULL); if (0 != res) { *rp = v; } else { pctx->cc = -1; /* ERROR: Syntax */ #if DK4_CHAR_SIZE == 1 dk4app_log_3( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 88, 89, pctx->parts[pind] ); #else /* ##### TODO: Error message */ #endif } } static void wxdrd_input_u32( uint32_t *rp, wxd_reader_context_t *pctx, size_t pind ) { const char *ep = NULL; int res = 0; uint32_t v = 0U; res = dk4ma_input_c8_dec_u32(&v, pctx->parts[pind], &ep, 1, NULL); if (0 != res) { *rp = v; } else { pctx->cc = -1; /* ERROR: Syntax */ #if DK4_CHAR_SIZE == 1 dk4app_log_3( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 90, 91, pctx->parts[pind] ); #else /* ##### TODO: Error message */ #endif } } static void wxdrd_input_i32( int32_t *rp, wxd_reader_context_t *pctx, size_t pind ) { const char *ep = NULL; int res = 0; int32_t v = 0U; res = dk4ma_input_c8_dec_i32(&v, pctx->parts[pind], &ep, 1, NULL); if (0 != res) { *rp = v; } else { pctx->cc = -1; /* ERROR: Syntax */ #if DK4_CHAR_SIZE == 1 dk4app_log_3( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 92, 93, pctx->parts[pind] ); #else /* ##### TODO: Error message */ #endif } } /** Process first line of file containing the file type. @param pctx Context to modify. @param il Input line to process. */ static void wxdrd_process_filetype_line(wxd_reader_context_t *pctx, char *il) { const char *ep; int res; $? "+ wxdrd_process_filetype_line" pctx->nparts = dk4str8_tokenize( &(pctx->parts[0]), pctx->szparts, il, NULL, NULL ); if (3 == pctx->nparts) { if (0 == strcmp(wxdrd_kwnl8[0], pctx->parts[0])) { ep = NULL; res = dk4ma_input_c8_dec_u16( &(pctx->drw->fv_maj), pctx->parts[1], &ep, 1, NULL ); if (0 != res) { ep = NULL; res = dk4ma_input_c8_dec_u16( &(pctx->drw->fv_min), pctx->parts[2], &ep, 1, NULL ); if (0 != res) { pctx->st = ST_OBJECT_LINE; if (0 < wxdrd_check_version(pctx->drw, 1, 0)) { /* WARNING: File format version too high! */ /* While reading the input file object of types not supported by format 1.0 are ignored. */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 94 ); } } else { $? "! missing minor version" pctx->cc = -1; /* ERROR: Not a wxd file */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 4 ); } } else { $? "! missing major version" pctx->cc = -1; /* ERROR: Not a wxd file */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 4 ); } } else { $? "! no WXD" pctx->cc = -1; /* ERROR: Not a wxd file */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 4 ); } } else { $? "! nparts != 3" pctx->cc = -1; /* ERROR: Not a wxd file */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 4 ); } $? "- wxdrd_process_filetype_line cc=%d", pctx->cc } /** Process configuration line for bounding box. @param pctx Context to modify. */ static void wxdrd_process_bounding_box_line(wxd_reader_context_t *pctx) { int32_t i32[4]; const char *ep = NULL; size_t i; int ok = 1; int res; $? "+ wxdrd_process_bounding_box_line" if (6 == pctx->nparts) { for (i = 0; i < 4; i++) { ep = NULL; res = dk4ma_input_c8_dec_i32( &(i32[i]), pctx->parts[i + 2], &ep, 1, NULL ); if (0 == res) { $? "! not a number" ok = 0 ; #if DK4_CHAR_SIZE == 1 dk4app_log_3( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 92, 93, pctx->parts[i + 2] ); #else /* ##### TODO: Error message */ #endif } } if (1 == ok) { pctx->drw->bbxl = (double)(i32[0]); pctx->drw->bbxr = (double)(i32[1]); pctx->drw->bbyb = (double)(i32[2]); pctx->drw->bbyt = (double)(i32[3]); if ( (pctx->drw->bbxl >= pctx->drw->bbxr) || (pctx->drw->bbyb >= pctx->drw->bbyt) ) { /* ERROR: Illegal bounding box */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 95 ); pctx->cc = -1; } } else { pctx->cc = -1; /* ERROR: Syntax */ } } else { $? "! nparts" /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_bounding_box_line cc=%d", pctx->cc } /** Process configuration line for base line width. @param pctx Context to modify. */ static void wxdrd_process_base_line_width_line(wxd_reader_context_t *pctx) { const char *ep = NULL; int res; uint32_t u32; $? "+ wxdrd_process_base_line_width_line" if (3 == pctx->nparts) { res = dk4ma_input_c8_dec_u32(&u32, pctx->parts[2], &ep, 1, NULL); if (0 != res) { pctx->drw->baselw = ((9.0 * (double)u32) / 2032000.0); if ((uint32_t)0U == u32) { pctx->cc = -1; /* ERROR: Base line width 0 not allowed */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 97 ); } } else { $? "! not a number" pctx->cc = -1; /* ERROR: Syntax */ #if DK4_CHAR_SIZE == 1 dk4app_log_3( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 90, 91, pctx->parts[2] ); #else /* ##### TODO: Error message */ #endif } } else { $? "! nparts" pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_base_line_width_line cc=%d", pctx->cc } /** Process configuration line. @param pctx Context to modify. */ static void wxdrd_process_config_option_line(wxd_reader_context_t *pctx) { const char *ep = NULL; int res; int16_t st; $? "+ wxdrd_process_config_option_line" if (1 < pctx->nparts) { res = dk4ma_input_c8_dec_i16(&st, pctx->parts[1], &ep, 1, NULL); if (0 != res) { switch (st) { case 0 : { /* Bounding box */ wxdrd_process_bounding_box_line(pctx); } break; case 1 : { /* Base line width */ wxdrd_process_base_line_width_line(pctx); } break; case 2 : { /* Zoom level */ /* Zoom level is used in the drawing application only */ } break; case 3 : { /* Zoom center */ /* Zoom center is used in the drawing application only */ } break; case 4 : { /* Grid unit */ /* Grid unit is used in the drawing application only */ } break; case 5 : { /* Grid divisor base */ /* Grid divisor is used in the drawing application only */ } break; } } else { pctx->cc = -1; /* ERROR: Syntax - Too few numbers */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 98 ); } } else { pctx->cc = -1; /* ERROR: Syntax - Too few numbers */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 98 ); } $? "- wxdrd_process_config_option_line cc=%d", pctx->cc } /** Read layer and colour. No memory is allocated for the identifier, we just check existance. @param pctx Context to modify. @param isst Colour purpose (is stroke): 1=stroke, 0=fill. */ static void wxd_layer_colour(wxd_reader_context_t *pctx, int isst) { size_t i; $? "+ wxd_layer_colour" wxdrd_input_i16(&(pctx->tobj.lay), pctx, 1); if (0 != isst) { for (i = 0; ((i < 3) && (1 == pctx->cc)); i++) { wxdrd_input_u8(&(pctx->tobj.sc[i]), pctx, (2 + i)); } } else { for (i = 0; ((i < 3) && (1 == pctx->cc)); i++) { wxdrd_input_u8(&(pctx->tobj.fc[i]), pctx, (2 + i)); } } $? "- wxd_layer_colour cc=%d", pctx->cc } /** Retrieve attributes for stroked object. @param pctx Context to use and modify. @param addi Offset to add to indices (0 for objects without a number of points, 1 for objects with variable point number). @param jm Offset to add to indices (0 for objects without join style and miter limit, 2 for objects with these information). */ static void wxd_stroke_attributes(wxd_reader_context_t *pctx, size_t addi, size_t jm) { size_t i; uint16_t u16 = (uint16_t)0U; $? "+ wxd_stroke_attributes" wxdrd_input_i16(&(pctx->tobj.lay), pctx, (1 + addi)); for (i = 0; ((i < 3) && (1 == pctx->cc)); i++) { wxdrd_input_u8(&(pctx->tobj.sc[i]), pctx, (2 + addi + i)); } wxdrd_input_u16(&u16, pctx, (5 + addi)); pctx->tobj.lw = (double)u16; wxdrd_input_u8(&(pctx->tobj.ls), pctx, (6 + addi)); if (WXD_LS_DASH_DOT_DOT_DOT < pctx->tobj.ls) { pctx->tobj.ls = WXD_LS_DASH_DOT_DOT_DOT; /* WARNING: Line style corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 99 ); } wxdrd_input_u8(&(pctx->tobj.sl), pctx, (7 + addi)); if (1 > pctx->tobj.sl) { pctx->tobj.sl = 1; /* WARNING: Style length corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 100 ); } wxdrd_input_u8(&(pctx->tobj.csfs), pctx, (8 + addi)); if (WXD_LC_PROJECTING < pctx->tobj.csfs) { pctx->tobj.csfs = WXD_LC_PROJECTING; /* WARNING: Cap style corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 101 ); } if (2 == jm) { wxdrd_input_u8(&(pctx->tobj.js), pctx, (9 + addi)); if (WXD_LJ_BEVELED < pctx->tobj.js) { pctx->tobj.js = WXD_LJ_BEVELED; /* WARNING: Join style corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 102 ); } wxdrd_input_u8(&(pctx->tobj.ml), pctx, (10 + addi)); $? ". ml = %u", (unsigned)(pctx->tobj.ml) if (1U > pctx->tobj.ml) { pctx->tobj.ml = 1U; /* WARNING: Miter limit corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 103 ); } } wxdrd_input_u8(&(pctx->tobj.af.type), pctx, ( 9 + jm + addi)); if (29U < pctx->tobj.af.type) { pctx->tobj.af.type = 29U; /* WARNING: Forward arrow type corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 104 ); } wxdrd_input_u8(&(pctx->tobj.af.length), pctx, (10 + jm + addi)); if (1U > pctx->tobj.af.length) { pctx->tobj.af.length = 1U; /* WARNING: Forward arrow length corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 106 ); } wxdrd_input_u8(&(pctx->tobj.af.width), pctx, (11 + jm + addi)); if (1U > pctx->tobj.af.width) { pctx->tobj.af.width = 1U; /* WARNING: Forward arrow width corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 108 ); } wxdrd_input_u8(&(pctx->tobj.ab.type), pctx, (12 + jm + addi)); if (29U < pctx->tobj.ab.type) { pctx->tobj.ab.type = 29U; /* WARNING: Backward arrow type corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 105 ); } wxdrd_input_u8(&(pctx->tobj.ab.length), pctx, (13 + jm + addi)); if (1U > pctx->tobj.ab.length) { pctx->tobj.ab.length = 1U; /* WARNING: Backward arrow length corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 107 ); } wxdrd_input_u8(&(pctx->tobj.ab.width), pctx, (14 + jm + addi)); if (1U > pctx->tobj.ab.width) { pctx->tobj.ab.width = 1U; /* WARNING: Backward arrow width corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 109 ); } $? "- wxd_stroke_attributes cc=%d", pctx->cc } static void wxd_fill_stroke_attributes(wxd_reader_context_t *pctx, size_t addi, int js) { size_t i; uint16_t u16 = (uint16_t)0U; $? "+ wxd_fill_stroke_attributes" wxdrd_input_i16(&(pctx->tobj.lay), pctx, (1 + addi)); for (i = 0; ((i < 3) && (1 == pctx->cc)); i++) { wxdrd_input_u8(&(pctx->tobj.sc[i]), pctx, (2 + addi + i)); } for (i = 0; ((i < 3) && (1 == pctx->cc)); i++) { wxdrd_input_u8(&(pctx->tobj.fc[i]), pctx, (5 + addi + i)); } wxdrd_input_u16(&u16, pctx, (8 + addi)); pctx->tobj.lw = (double)u16; wxdrd_input_u8(&(pctx->tobj.ls), pctx, (9 + addi)); if (WXD_LS_DASH_DOT_DOT_DOT < pctx->tobj.ls) { pctx->tobj.ls = WXD_LS_DASH_DOT_DOT_DOT; /* WARNING: Line style corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 99 ); } wxdrd_input_u8(&(pctx->tobj.sl), pctx, (10 + addi)); if (1 > pctx->tobj.sl) { pctx->tobj.sl = 1; /* WARNING: Style length corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 100 ); } if (1 == js) { wxdrd_input_u8(&(pctx->tobj.js), pctx, (11 + addi)); if (WXD_LJ_BEVELED < pctx->tobj.js) { pctx->tobj.js = WXD_LJ_BEVELED; /* WARNING: Join style corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 102 ); } wxdrd_input_u8(&(pctx->tobj.ml), pctx, (12 + addi)); $? ". ml = %u", (unsigned)(pctx->tobj.ml) if (1U > pctx->tobj.ml) { pctx->tobj.ml = 1U; /* WARNING: Miter limit corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 103 ); } wxdrd_input_u8(&(pctx->tobj.csfs), pctx, (13 + addi)); if (WXD_FS_VERTICAL_TIRES < pctx->tobj.csfs) { pctx->tobj.csfs = WXD_FS_VERTICAL_TIRES; /* WARNING: Fill style corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 110 ); } } else { wxdrd_input_u8(&(pctx->tobj.csfs), pctx, (11 + addi)); if (WXD_FS_VERTICAL_TIRES < pctx->tobj.csfs) { pctx->tobj.csfs = WXD_FS_VERTICAL_TIRES; /* WARNING: Fill style corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 110 ); } } $? "- wxd_fill_stroke_attributes cc=%d", pctx->cc } /** Add object pobj to drawing. @param pctx Context to modify, contains both drw and pobj. @param idin Index of identifier in parts array. */ static void wxdrd_add_object(wxd_reader_context_t *pctx) { if ((NULL != pctx->pobj) && (1 == pctx->cc)) { if (0 == dk4sto_add(pctx->drw->s_flat, pctx->pobj, NULL)) { wxd2lat_object_delete(pctx->pobj); pctx->pobj = NULL; pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } /** Process object start line for text object. @param pctx Context to modify. */ static void wxdrd_process_text_start_line(wxd_reader_context_t *pctx) { $? "+ wxdrd_process_text_start_line" if (5 == pctx->nparts) { wxd_layer_colour(pctx, 0); if (1 == pctx->cc) { /* Set details to reasonable defaults before creating a dynamic copy of the object */ pctx->tobj.det.t.t = NULL; pctx->tobj.det.t.tsc = NULL; pctx->tobj.det.t.a = 0.0; pctx->tobj.det.t.x = 0.0; pctx->tobj.det.t.y = 0.0; pctx->tobj.det.t.fsz = 12U; pctx->tobj.det.t.find = 0; pctx->tobj.det.t.al = WXD_TA_LEFT; pctx->tobj.det.t.fl = 0; pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); /* Create dynamic copy and register interest in the details */ if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_text_start_line cc=%d", pctx->cc } /** Process object start line for polyline object. @param pctx Context to modify. */ static void wxdrd_process_polyline_start_line(wxd_reader_context_t *pctx) { $? "+ wxdrd_process_polyline_start_line" if (18 == pctx->nparts) { pctx->tobj.det.p.p = NULL; pctx->tobj.det.p.n = 0; wxdrd_input_u16(&(pctx->tobj.det.p.n), pctx, 1); if (1 == pctx->cc) { wxd_stroke_attributes(pctx, 1, 2); if (2 > pctx->tobj.det.p.n) { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 59 ); } if (1 == pctx->cc) { pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); pctx->pobj->det.p.p = dk4mem_new(wxd_point_t,pctx->tobj.det.p.n,NULL); if (NULL != pctx->pobj->det.p.p) { wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { dk4mem_free(pctx->pobj); pctx->pobj = NULL; pctx->cc = -1; } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_polyline_start_line cc=%d", pctx->cc } /** Process object start line for open spline. @param pctx Context to modify. */ static void wxdrd_process_ospline_start_line(wxd_reader_context_t *pctx) { $? "+ wxdrd_process_ospline_start_line" if (18 == pctx->nparts) { pctx->tobj.det.s.p = NULL; pctx->tobj.det.s.sl = NULL; pctx->tobj.det.s.n = 0; pctx->tobj.det.s.ts = 0.0; wxdrd_input_u16(&(pctx->tobj.det.s.n), pctx, 1); pctx->tobj.det.s.te = (double)((pctx->tobj).det.s.n - (uint16_t)1U); if (1 == pctx->cc) { wxd_stroke_attributes(pctx, 1, 2); if (2 > pctx->tobj.det.s.n) { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 59 ); } if (1 == pctx->cc) { pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); pctx->pobj->det.s.p = dk4mem_new(wxd_spline_point_t,pctx->tobj.det.s.n,NULL); if (NULL != pctx->pobj->det.s.p) { wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { dk4mem_free(pctx->pobj); pctx->pobj = NULL; pctx->cc = -1; } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_ospline_start_line cc=%d", pctx->cc } /** Process object start line for open arc. @param pctx Context to modify. */ static void wxdrd_process_oarc_start_line(wxd_reader_context_t *pctx) { $? "+ wxdrd_process_oarc_start_line" if (15 == pctx->nparts) { pctx->tobj.det.a.a = 0.0; pctx->tobj.det.a.b = 0.0; pctx->tobj.det.a.x = 0L; pctx->tobj.det.a.y = 0L; pctx->tobj.det.a.r = 0UL; wxd_stroke_attributes(pctx, 0, 0); if (1 == pctx->cc) { pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_oarc_start_line cc=%d", pctx->cc } /** Process object start line for polygon. @param pctx Context to modify. */ static void wxdrd_process_polygon_start_line(wxd_reader_context_t *pctx) { $? "+ wxdrd_process_polygon_start_line" if (15 == pctx->nparts) { pctx->tobj.det.p.p = NULL; pctx->tobj.det.p.n = 0; wxdrd_input_u16(&(pctx->tobj.det.p.n), pctx, 1); if (1 == pctx->cc) { wxd_fill_stroke_attributes(pctx, 1, 1); if (2 > pctx->tobj.det.p.n) { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 59 ); } if (1 == pctx->cc) { pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); pctx->pobj->det.p.p = dk4mem_new(wxd_point_t,pctx->tobj.det.p.n,NULL); if (NULL != pctx->pobj->det.p.p) { wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { dk4mem_free(pctx->pobj); pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_polygon_start_line cc=%d", pctx->cc } /** Process object start line for closed spline. @param pctx Context to modify. */ static void wxdrd_process_cspline_start_line(wxd_reader_context_t *pctx) { $? "+ wxdrd_process_cspline_start_line" if (15 == pctx->nparts) { pctx->tobj.det.s.p = NULL; pctx->tobj.det.s.sl = NULL; pctx->tobj.det.s.n = 0; wxdrd_input_u16(&(pctx->tobj.det.s.n), pctx, 1); if (1 == pctx->cc) { wxd_fill_stroke_attributes(pctx, 1, 1); if (2 > pctx->tobj.det.s.n) { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 59 ); } if (1 == pctx->cc) { pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); pctx->pobj->det.s.p = dk4mem_new(wxd_spline_point_t,pctx->tobj.det.s.n,NULL); if (NULL != pctx->pobj->det.s.p) { wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { dk4mem_free(pctx->pobj); pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_cspline_start_line cc=%d", pctx->cc } /** Process object start line for closed arc. @param pctx Context to modify. */ static void wxdrd_process_carc_start_line(wxd_reader_context_t *pctx) { $? "+ wxdrd_process_carc_start_line" if (14 == pctx->nparts) { pctx->tobj.det.a.a = 0.0; pctx->tobj.det.a.b = 0.0; pctx->tobj.det.a.x = 0L; pctx->tobj.det.a.y = 0L; pctx->tobj.det.a.r = 0UL; wxd_fill_stroke_attributes(pctx, 0, 1); if (1 == pctx->cc) { pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_carc_start_line cc=%d", pctx->cc } /** Process object start line for ellipse. @param pctx Context to modify. */ static void wxdrd_process_ellipse_start_line(wxd_reader_context_t *pctx) { $? "+ wxdrd_process_ellipse_start_line" if (12 == pctx->nparts) { pctx->tobj.det.e.a = 0.0; pctx->tobj.det.e.x = 0.0; pctx->tobj.det.e.y = 0.0; pctx->tobj.det.e.rx = 0.0; pctx->tobj.det.e.ry = 0.0; wxd_fill_stroke_attributes(pctx, 0, 0); if (1 == pctx->cc) { pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } else { pctx->cc = -1; } $? "- wxdrd_process_ellipse_start_line cc=%d", pctx->cc } /** Process object start line for box. @param pctx Context to modify. */ static void wxdrd_process_box_start_line(wxd_reader_context_t *pctx) { $? "+ wxdrd_process_box_start_line" if (12 == pctx->nparts) { pctx->tobj.det.b.xl = 0.0; pctx->tobj.det.b.xr = 0.0; pctx->tobj.det.b.yb = 0.0; pctx->tobj.det.b.yt = 0.0; pctx->tobj.det.b.r = -1.0; wxd_fill_stroke_attributes(pctx, 0, 0); pctx->tobj.js = WXD_LJ_MITERED; pctx->tobj.ml = 8U; $? ". ml = 8" if (1 == pctx->cc) { pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_box_start_line cc=%d", pctx->cc } /** Process object start line for embedded image. @param pctx Context to modify. */ static void wxdrd_process_image_start_line(wxd_reader_context_t *pctx) { $? "+ wxdrd_process_image_start_line" if (5 == pctx->nparts) { pctx->tobj.det.i.fn = NULL; pctx->tobj.det.i.x = 0.0; pctx->tobj.det.i.y = 0.0; pctx->tobj.det.i.w = 0.0; pctx->tobj.det.i.h = 0.0; pctx->tobj.det.i.fl = 0U; pctx->tobj.det.i.r2g = 0; pctx->tobj.det.i.r2c = 0; wxd_layer_colour(pctx, 0); if (1 == pctx->cc) { pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_image_start_line cc=%d", pctx->cc } /** Process object start line for filled dot. @param pctx Context to modify. */ static void wxdrd_process_filled_dot_start_line(wxd_reader_context_t *pctx) { size_t i; $? "+ wxdrd_process_filled_dot_start_line" if (5 == pctx->nparts) { pctx->tobj.det.d.x = 0.0; pctx->tobj.det.d.y = 0.0; pctx->tobj.det.d.d = 0.0; pctx->tobj.lw = 0.0; wxd_layer_colour(pctx, 0); for (i = 0; i < 3; i++) { pctx->tobj.sc[i] = pctx->tobj.fc[i]; } pctx->tobj.csfs = WXD_FS_PURE; if (1 == pctx->cc ) { pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_filled_dot_start_line cc=%d", pctx->cc } /** Process object start line for white filled dot. @param pctx Context to modify. */ static void wxdrd_process_white_dot_start_line(wxd_reader_context_t *pctx) { size_t i; $? "+ wxdrd_process_white_dot_start_line" if (5 == pctx->nparts) { pctx->tobj.det.d.x = 0.0; pctx->tobj.det.d.y = 0.0; pctx->tobj.det.d.d = 0.0; pctx->tobj.lw = 0.0; wxd_layer_colour(pctx, 1); for (i = 0; i < 3; i++) { pctx->tobj.fc[i] = 255; } pctx->tobj.csfs = WXD_FS_PURE; if (1 == pctx->cc) { pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_white_dot_start_line cc=%d", pctx->cc } /** Process object start line for circle. @param pctx Context to modify. */ static void wxdrd_process_circle_start_line(wxd_reader_context_t *pctx) { $? "+ wxdrd_process_circle_start_line" if (12 == pctx->nparts) { pctx->tobj.det.e.a = 0.0; pctx->tobj.det.e.x = 0.0; pctx->tobj.det.e.y = 0.0; pctx->tobj.det.e.rx = 0.0; pctx->tobj.det.e.ry = 0.0; wxd_fill_stroke_attributes(pctx, 0, 0); if (1 == pctx->cc) { pctx->pobj = dk4mem_new(wxd_object_t,1,NULL); if (NULL != pctx->pobj) { DK4_MEMCPY(pctx->pobj, &(pctx->tobj), sizeof(wxd_object_t)); wxdrd_add_object(pctx); if (1 == pctx->cc) { pctx->st = ST_DETAIL_LINE; } } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_circle_start_line cc=%d", pctx->cc } /** Process first line of new object. @param pctx Context to modify. @param il Input line to process. */ static void wxdrd_process_object_line(wxd_reader_context_t *pctx, char *il) { const char *ep = NULL; int res; $? "+ wxdrd_process_object_line" pctx->nparts = dk4str8_tokenize( &(pctx->parts[0]), pctx->szparts, il, NULL, NULL ); wxd_object_initialize(&(pctx->tobj)); (pctx->tobj).lino = pctx->lineno; pctx->pobj = NULL; pctx->curp = 0U; if (0 < pctx->nparts) { res = dk4ma_input_c8_dec_i16( &(pctx->tobj.ot), pctx->parts[0], &ep, 1, NULL ); if (0 != res) { switch (pctx->tobj.ot) { case WXD_OT_GROUP_END : { $? ". grdepth = %lu", (unsigned long)(pctx->grdepth) if ((dk4_um_t)0UL < pctx->grdepth) { pctx->grdepth -= (dk4_um_t)1UL; $? ". grdepth = %lu", (unsigned long)(pctx->grdepth) } else { pctx->cc = -1; /* ERROR: Syntax - Closing too many groups */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 111 ); } } break; case WXD_OT_GROUP_BEGIN : { $? ". grdepth = %lu", (unsigned long)(pctx->grdepth) if (DK4_UM_MAX > pctx->grdepth) { pctx->grdepth += (dk4_um_t)1UL; $? ". grdepth = %lu", (unsigned long)(pctx->grdepth) } else { $? "! too many groups" pctx->cc = -1; /* ERROR: Syntax - Opening too many groups */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 112 ); } } break; case WXD_OT_CONFIG : { wxdrd_process_config_option_line(pctx); } break; case WXD_OT_TEXT : { wxdrd_process_text_start_line(pctx); } break; case WXD_OT_POLYLINE : { wxdrd_process_polyline_start_line(pctx); } break; case WXD_OT_O_SPLINE : { wxdrd_process_ospline_start_line(pctx); } break; case WXD_OT_O_ARC : { wxdrd_process_oarc_start_line(pctx); } break; case WXD_OT_POLYGON : { wxdrd_process_polygon_start_line(pctx); } break; case WXD_OT_C_SPLINE : { wxdrd_process_cspline_start_line(pctx); } break; case WXD_OT_C_ARC : { wxdrd_process_carc_start_line(pctx); } break; case WXD_OT_CIRCLE : { wxdrd_process_circle_start_line(pctx); } break; case WXD_OT_ELLIPSE : { wxdrd_process_ellipse_start_line(pctx); } break; case WXD_OT_BOX : { wxdrd_process_box_start_line(pctx); } break; case WXD_OT_IMAGE : { wxdrd_process_image_start_line(pctx); } break; case WXD_OT_DOT_FILLED : { wxdrd_process_filled_dot_start_line(pctx); } break; case WXD_OT_DOT_WHITE : { wxdrd_process_white_dot_start_line(pctx); } break; default : { if (0 < wxdrd_check_version(pctx->drw, 1, 0)) { pctx->st = ST_RESUME; /* WARNING: Skipping object */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 113 ); } else { $? "! version number" pctx->cc = -1; /* ERROR: Syntax - Illegal object type */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 114 ); } } break; } } else { $? "! input type is not a number" pctx->cc = -1; /* ERROR: Syntax - Missing object type */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 115 ); } } else { $? "! missing object type" pctx->cc = -1; /* ERROR: Syntax - No object type */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 115 ); } $? "- wxdrd_process_object_line cc=%d", pctx->cc } /** Process details for a text. @param pctx Context to modify. */ static void wxdrd_process_details_text(wxd_reader_context_t *pctx) { int32_t i32; int16_t i16; uint8_t u8; $? "+ wxdrd_process_details_text" wxdrd_input_u8(&(pctx->pobj->det.t.find), pctx, 0); if (1 == pctx->cc) { if (34 < pctx->pobj->det.t.find) { pctx->pobj->det.t.find = 34; /* WARNING: Font index corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 116 ); } } wxdrd_input_u16(&(pctx->pobj->det.t.fsz), pctx, 1); if (1 > pctx->pobj->det.t.fsz) { pctx->pobj->det.t.fsz = 1; /* WARNING: Font size corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 116 ); } wxdrd_input_u8(&u8, pctx, 2); if (1 == pctx->cc) { if (2 < u8) { u8 = 2; /* WARNING: Text align corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 117 ); } pctx->pobj->det.t.al = u8; } wxdrd_input_u8(&(pctx->pobj->det.t.fl), pctx, 3); wxdrd_input_i32(&i32, pctx, 4); pctx->pobj->det.t.x = (double)i32; wxdrd_input_i32(&i32, pctx, 5); pctx->pobj->det.t.y = (double)i32; wxdrd_input_i16(&i16, pctx, 6); pctx->pobj->det.t.a = (double)i16; if (1 == pctx->cc) { pctx->st = ST_TEXT_EXPORT; } $? "- wxdrd_process_details_text cc=%d", pctx->cc } /** Process details for a polyline. @param pctx Context to modify. */ static void wxdrd_process_details_polyline(wxd_reader_context_t *pctx) { int32_t i32; $? "+ wxdrd_process_details_polyline" if (pctx->curp < pctx->pobj->det.p.n) { wxdrd_input_i32(&i32, pctx, 0); (pctx->pobj->det.p.p)[pctx->curp].x = (double)i32; wxdrd_input_i32(&i32, pctx, 1); (pctx->pobj->det.p.p)[pctx->curp].y = (double)i32; pctx->curp += 1U; if (pctx->curp >= pctx->pobj->det.p.n) { pctx->st = ST_OBJECT_LINE; } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } $? "- wxdrd_process_details_polyline cc=%d", pctx->cc } /** Process details for a spline. @param pctx Context to modify. */ static void wxdrd_process_details_spline(wxd_reader_context_t *pctx) { int32_t i32; $? "+ wxdrd_process_details_spline" if (pctx->curp < pctx->pobj->det.s.n) { wxdrd_input_i32(&i32, pctx, 0); (pctx->pobj->det.s.p)[pctx->curp].x = (double)i32; wxdrd_input_i32(&i32, pctx, 1); (pctx->pobj->det.s.p)[pctx->curp].y = (double)i32; wxdrd_input_double(&((pctx->pobj->det.s.p)[pctx->curp].s), pctx, 2); if (-1.0 > (pctx->pobj->det.s.p)[pctx->curp].s) { (pctx->pobj->det.s.p)[pctx->curp].s = -1.0; /* WARNING: s parameter corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 118 ); } if ( 1.0 < (pctx->pobj->det.s.p)[pctx->curp].s) { (pctx->pobj->det.s.p)[pctx->curp].s = 1.0; /* WARNING: s parameter corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 118 ); } pctx->curp += 1U; if (pctx->curp >= pctx->pobj->det.s.n) { pctx->st = ST_OBJECT_LINE; } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 59 ); } $? "- wxdrd_process_details_spline cc=%d", pctx->cc } /** Process details for an arc. @param pctx Context to modify. */ static void wxdrd_process_details_arc(wxd_reader_context_t *pctx) { $? "+ wxdrd_process_details_arc" wxdrd_input_i32(&(pctx->pobj->det.a.x1), pctx, 0); wxdrd_input_i32(&(pctx->pobj->det.a.y1), pctx, 1); wxdrd_input_i32(&(pctx->pobj->det.a.x2), pctx, 2); wxdrd_input_i32(&(pctx->pobj->det.a.y2), pctx, 3); wxdrd_input_i32(&(pctx->pobj->det.a.x3), pctx, 4); wxdrd_input_i32(&(pctx->pobj->det.a.y3), pctx, 5); pctx->st = ST_OBJECT_LINE; wxdarc_calculation( &((((pctx->pobj)->det).a).x), &((((pctx->pobj)->det).a).y), &((((pctx->pobj)->det).a).r), &((((pctx->pobj)->det).a).a), &((((pctx->pobj)->det).a).b), &((((pctx->pobj)->det).a).d), (((pctx->pobj)->det).a).x1, (((pctx->pobj)->det).a).y1, (((pctx->pobj)->det).a).x2, (((pctx->pobj)->det).a).y2, (((pctx->pobj)->det).a).x3, (((pctx->pobj)->det).a).y3 ); $? "- wxdrd_process_details_arc cc=%d", pctx->cc } /** Process details for a circle @param pctx Context to modify. */ static void wxdrd_process_details_circle(wxd_reader_context_t *pctx) { int32_t i32; uint32_t u32; $? "+ wxdrd_process_details_circle" wxdrd_input_i32(&i32, pctx, 0); pctx->pobj->det.e.x = (double)i32; wxdrd_input_i32(&i32, pctx, 1); pctx->pobj->det.e.y = (double)i32; wxdrd_input_u32(&u32, pctx, 2); pctx->pobj->det.e.rx = (double)u32; if ((uint32_t)1UL > u32) { pctx->pobj->det.e.rx = 1.0; /* WARNING: Radius corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 119 ); } if ((uint32_t)80UL > u32) { /* WARNING: Very small radius */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 120 ); } pctx->pobj->det.e.ry = pctx->pobj->det.e.rx; pctx->st = ST_OBJECT_LINE; $? "- wxdrd_process_details_circle cc=%d", pctx->cc } /** Process details for an ellipse. @param pctx Context to modify. */ static void wxdrd_process_details_ellipse(wxd_reader_context_t *pctx) { int32_t i32; uint32_t u32; int16_t i16; $? "+ wxdrd_process_details_ellipse" wxdrd_input_i32(&i32, pctx, 0); pctx->pobj->det.e.x = (double)i32; wxdrd_input_i32(&i32, pctx, 1); pctx->pobj->det.e.y = (double)i32; wxdrd_input_u32(&u32, pctx, 2); pctx->pobj->det.e.rx = (double)u32; if ((uint32_t)1UL > u32) { pctx->pobj->det.e.rx = 1.0; /* WARNING: X radius corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 119 ); } if ((uint32_t)80UL > u32) { /* WARNING: Unusual small x radius */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 120 ); } wxdrd_input_u32(&u32, pctx, 3); pctx->pobj->det.e.ry = (double)u32; if ((uint32_t)1UL > u32) { pctx->pobj->det.e.ry = 1.0; /* WARNING: Y radius corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 119 ); } if ((uint32_t)80UL > u32) { /* WARNING: Unusual small y radius */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 120 ); } wxdrd_input_i16(&i16, pctx, 4); pctx->pobj->det.e.a = (double)i16; pctx->st = ST_OBJECT_LINE; $? "- wxdrd_process_details_ellipse cc=%d", pctx->cc } /** Process details for a box. @param pctx Context to modify. */ static void wxdrd_process_details_box(wxd_reader_context_t *pctx) { double dv; double dw; double dh; int32_t i32; uint32_t u32; $? "+ wxdrd_process_details_box" wxdrd_input_i32(&i32, pctx, 0); pctx->pobj->det.b.xl = (double)i32; wxdrd_input_i32(&i32, pctx, 1); pctx->pobj->det.b.xr = (double)i32; if (pctx->pobj->det.b.xl > pctx->pobj->det.b.xr) { dv = pctx->pobj->det.b.xl; pctx->pobj->det.b.xl = pctx->pobj->det.b.xr; pctx->pobj->det.b.xr = dv; } wxdrd_input_i32(&i32, pctx, 2); pctx->pobj->det.b.yb = (double)i32; wxdrd_input_i32(&i32, pctx, 3); pctx->pobj->det.b.yt = (double)i32; if (pctx->pobj->det.b.yb > pctx->pobj->det.b.yt) { dv = pctx->pobj->det.b.yb; pctx->pobj->det.b.yb = pctx->pobj->det.b.yt; pctx->pobj->det.b.yt = dv; } wxdrd_input_u32(&u32, pctx, 4); pctx->pobj->det.b.r = (double)u32; if ((uint32_t)0UL == u32) { pctx->pobj->det.b.r = -1.0; } dw = pctx->pobj->det.b.xr - pctx->pobj->det.b.xl; dh = pctx->pobj->det.b.yt - pctx->pobj->det.b.yb; if (dh < dw) { dw = dh; } if ((dw / 2.0) < pctx->pobj->det.b.r) { pctx->pobj->det.b.r = dw / 2.0; /* WARNING: Corner radius corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 119 ); } pctx->st = ST_OBJECT_LINE; $? "- wxdrd_process_details_box cc=%d", pctx->cc } /** Process details for an embedded image. @param pctx Context to modify. */ static void wxdrd_process_details_image(wxd_reader_context_t *pctx) { int32_t i32; uint32_t u32; $? "+ wxdrd_process_details_image" wxdrd_input_u8(&(pctx->pobj->det.i.fl), pctx, 0); wxdrd_input_i8(&(pctx->pobj->det.i.r2g), pctx, 1); if ((int8_t)(-1) > pctx->pobj->det.i.r2g) { pctx->pobj->det.i.r2g = (int8_t)(-1); /* WARNING: RGB to gray method corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 121 ); } if ( (int8_t)(DK4_CS_CONV_RGB_TO_GRAY_CHANNEL_BLUE) < pctx->pobj->det.i.r2g ) { pctx->pobj->det.i.r2g = (int8_t)(DK4_CS_CONV_RGB_TO_GRAY_CHANNEL_BLUE); /* WARNING: RGB to gray method corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 121 ); } wxdrd_input_i8(&(pctx->pobj->det.i.r2c), pctx, 2); wxdrd_input_i32(&i32, pctx, 3); pctx->pobj->det.i.x = (double)i32; wxdrd_input_i32(&i32, pctx, 4); pctx->pobj->det.i.y = (double)i32; wxdrd_input_u32(&u32, pctx, 5); pctx->pobj->det.i.w = (double)u32; wxdrd_input_u32(&u32, pctx, 6); pctx->pobj->det.i.h = (double)u32; if (1.0 > pctx->pobj->det.i.w) { pctx->cc = -1; /* ERROR: Invalid image width */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 122 ); } if (1.0 > pctx->pobj->det.i.h) { pctx->cc = -1; /* ERROR: Invalid image height */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 122 ); } pctx->st = ST_IMAGE_NAME; $? "- wxdrd_process_details_image cc=%d", pctx->cc } /** Process details for a dot. @param pctx Context to modify. */ static void wxdrd_process_details_dot(wxd_reader_context_t *pctx) { int32_t i32; uint16_t u16; $? "+ wxdrd_process_details_dot" wxdrd_input_i32(&i32, pctx, 0); pctx->pobj->det.d.x = (double)i32; wxdrd_input_i32(&i32, pctx, 1); pctx->pobj->det.d.y = (double)i32; wxdrd_input_u16(&u16, pctx, 2); pctx->pobj->det.d.d = (double)u16; if (1.0 > pctx->pobj->det.d.d) { pctx->pobj->det.d.d = 1.0; /* WARNING: Dot diameter corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 123 ); } pctx->st = ST_OBJECT_LINE; $? "- wxdrd_process_details_dot cc=%d", pctx->cc } /** Process details for a white filled dot. @param pctx Context to modify. */ static void wxdrd_process_details_white_dot(wxd_reader_context_t *pctx) { int32_t i32; uint16_t u16; $? "+ wxdrd_process_details_white_dot" wxdrd_input_i32(&i32, pctx, 0); pctx->pobj->det.d.x = (double)i32; wxdrd_input_i32(&i32, pctx, 1); pctx->pobj->det.d.y = (double)i32; wxdrd_input_u16(&u16, pctx, 2); if ((uint16_t)0U == u16) { u16 = (uint16_t)1U; /* WARNING: Dot diameter corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 123 ); } pctx->pobj->det.d.d = (double)u16; wxdrd_input_u16(&u16, pctx, 3); pctx->pobj->lw = (double)u16; if (1.0 > pctx->pobj->lw) { pctx->pobj->lw = 1.0; /* WARNING: Dot line width corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 124 ); } #if 0 if (pctx->pobj->det.d.d < pctx->pobj->lw) { pctx->pobj->det.d.d = pctx->pobj->lw; /* WARNING: Dot diameter corrected */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 123 ); } #endif pctx->st = ST_OBJECT_LINE; $? "- wxdrd_process_details_white_dot cc=%d", pctx->cc } /** Process details line from input file. @param pctx Context to modify. @param il Input line to process. */ static void wxdrd_process_details_line(wxd_reader_context_t *pctx, char *il) { $? "+ wxdrd_process_details_line" if (NULL != pctx->pobj) { pctx->nparts = dk4str8_tokenize( &(pctx->parts[0]), pctx->szparts, il, NULL, NULL ); switch (pctx->pobj->ot) { case WXD_OT_TEXT : { if (7 == pctx->nparts) { wxdrd_process_details_text(pctx); } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } } break; case WXD_OT_POLYLINE : case WXD_OT_POLYGON : { if (2 == pctx->nparts) { wxdrd_process_details_polyline(pctx); } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } } break; case WXD_OT_O_SPLINE : case WXD_OT_C_SPLINE : { if (3 == pctx->nparts) { wxdrd_process_details_spline(pctx); } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } } break; case WXD_OT_O_ARC : case WXD_OT_C_ARC : { if (6 == pctx->nparts) { wxdrd_process_details_arc(pctx); } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } } break; case WXD_OT_CIRCLE : { if (3 == pctx->nparts) { wxdrd_process_details_circle(pctx); } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } } break; case WXD_OT_ELLIPSE : { if (5 == pctx->nparts) { wxdrd_process_details_ellipse(pctx); } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } } break; case WXD_OT_BOX : { if (5 == pctx->nparts) { wxdrd_process_details_box(pctx); } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } } break; case WXD_OT_IMAGE : { if (7 == pctx->nparts) { wxdrd_process_details_image(pctx); } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } } break; case WXD_OT_DOT_FILLED : { if (3 == pctx->nparts) { wxdrd_process_details_dot(pctx); } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } } break; case WXD_OT_DOT_WHITE : { if (4 == pctx->nparts) { wxdrd_process_details_white_dot(pctx); } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 96 ); } } break; } } else { $? "! BUG, no current object" pctx->cc = -1; /* BUG */ } $? "- wxdrd_process_details_line cc=%d", pctx->cc } /** Process export text line. @param pctx Context to modify. @param il Input line to process. */ static void wxdrd_process_text_export(wxd_reader_context_t *pctx, char *il) { $? "+ wxdrd_process_text_export" if (0 < strlen(&(il[1]))) { pctx->pobj->det.t.t = dk4str8_dup(&(il[1]), NULL); if (NULL != pctx->pobj->det.t.t) { pctx->st = ST_TEXT_SCREEN; } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 125 ); } $? "- wxdrd_process_text_export cc=%d", pctx->cc } /** Process export text line. @param pctx Context to modify. @param il Input line to process. */ static void wxdrd_process_text_screen(wxd_reader_context_t *pctx, char *il) { $? "+ wxdrd_process_text_export" if (0 < strlen(&(il[1]))) { pctx->pobj->det.t.tsc = dk4str8_dup(&(il[1]), NULL); if (NULL != pctx->pobj->det.t.tsc) { pctx->st = ST_OBJECT_LINE; } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } else { pctx->pobj->det.t.tsc = NULL; pctx->st = ST_OBJECT_LINE; } $? "- wxdrd_process_text_export cc=%d", pctx->cc } /** Process the line containing the image file name. @param pctx Context to modify. @param il Input line to process. */ static void wxdrd_process_image_file_line(wxd_reader_context_t *pctx, char *il) { dk4str8_delnl(&(il[1])); if (0 < dk4str8_len(&(il[1]))) { pctx->pobj->det.i.fn = dk4str8_dup(&(il[1]), NULL); if (NULL != pctx->pobj->det.i.fn) { pctx->st = ST_OBJECT_LINE; } else { pctx->cc = -1; /* ERROR: Memory */ dk4app_log_base1(pctx->app, DK4_LL_ERROR, 90); } } else { pctx->cc = -1; /* ERROR: Syntax */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 126 ); } } /** Process one non-comment line from input file. @param pctx Context to modify. @param il Input line to process. */ static void wxdrd_process_line(wxd_reader_context_t *pctx, char *il) { int sl = 1; /* Object start line */ $? "+ wxdrd_process_line \"%!8s\"", il if (0 != is_whsp(il[0])) { sl = 0; } switch (pctx->st) { case ST_FIRSTLINE : { if (1 == sl) { wxdrd_process_filetype_line(pctx, il); } else { pctx->cc = -1; /* ERROR: Not a wxd file */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 4 ); } } break; case ST_OBJECT_LINE : { if (1 == sl) { wxdrd_process_object_line(pctx, il); } else { pctx->cc = -1; /* ERROR: Object start line expected! */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 127 ); } } break; case ST_DETAIL_LINE : { if (0 == sl) { wxdrd_process_details_line(pctx, il); } else { pctx->cc = -1; /* ERROR: Details line expected! */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 128 ); } } break; case ST_TEXT_EXPORT : { if (0 == sl) { wxdrd_process_text_export(pctx, il); } else { pctx->cc = -1; /* ERROR: Details line expected! */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 128 ); } } break; case ST_TEXT_SCREEN : { if (0 == sl) { wxdrd_process_text_screen(pctx, il); } else { /* WARNING: Details line expected! */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_WARNING, 128 ); pctx->st = ST_OBJECT_LINE; wxdrd_process_object_line(pctx, il); } } break; case ST_IMAGE_NAME : { if (0 == sl) { wxdrd_process_image_file_line(pctx, il); } else { pctx->cc = -1; /* ERROR: Details line expected! */ dk4app_log_1( pctx->app, pctx->msg, pctx->sz_msg, DK4_LL_ERROR, 128 ); } } break; case ST_RESUME : { if (1 == sl) { pctx->st = ST_OBJECT_LINE; wxdrd_process_object_line(pctx, il); } } break; } $? "- wxdrd_process_line cc=%d", pctx->cc } int wxdrd_apply_file( wxd_drawing_t *drw, FILE *fipo, const dkChar *fn, wxd2lat_job_t *job ) { char inbuf[WXD_LINE_LENGTH]; wxd_reader_context_t ctx; char *parts[32]; const dkChar *osf = NULL; /* Old source file */ dk4_um_t osl = 0UL; /* Old source line number */ int back = 0; /* Function result */ $? "+ wxdrd_apply_file \"%!ds\"", fn /* Arguments check */ if ((NULL == drw) || (NULL == fipo)) { goto finished; } /* Keep source file and line number */ osf = dk4app_get_log_source_file(job->app); osl = dk4app_get_log_source_line(job->app); dk4app_set_log_source_file(job->app, fn); dk4app_set_log_source_line(job->app, 0UL); /* Initialize reader context. INITCONTEXT */ DK4_MEMRES(&ctx,sizeof(wxd_reader_context_t)); ctx.st = ST_FIRSTLINE; ctx.cc = 1; ctx.back = 1; ctx.parts = parts; ctx.szparts = DK4_SIZEOF(parts,DK4_PCHAR); ctx.nparts = 0; ctx.lineno = (dk4_um_t)0UL; ctx.grdepth = (dk4_um_t)0UL; $? ". grdepth = %lu", (unsigned long)(ctx.grdepth) ctx.fn = fn; ctx.app = job->app; ctx.msg = job->msg; ctx.sz_msg = job->sz_msg; ctx.drw = drw; ctx.pobj = NULL; ctx.curp = 0; wxd_object_initialize(&(ctx.tobj)); /* Process input file */ while (1 == ctx.cc) { if (NULL != fgets(inbuf, sizeof(inbuf), fipo)) { if (DK4_UM_MAX > ctx.lineno) { ctx.lineno += (dk4_um_t)1UL; } dk4app_set_log_source_line(job->app, ctx.lineno); dk4str8_delnl(inbuf); if ('#' != inbuf[0]) { wxdrd_process_line(&ctx, inbuf); } } else { ctx.cc = 0; } } if (0 > ctx.cc) { ctx.back = 0; } else { if (ST_OBJECT_LINE != ctx.st) { if (ST_TEXT_SCREEN == ctx.st) { /* WARNING: Expecting screen text */ dk4app_log_1( ctx.app, ctx.msg, ctx.sz_msg, DK4_LL_WARNING, 129 ); } else { ctx.back = 0; /* ERROR: Syntax - Unexpected end of file */ dk4app_log_1( ctx.app, ctx.msg, ctx.sz_msg, DK4_LL_ERROR, 130 ); } } } back = ctx.back; /* Restore source file and line number */ dk4app_set_log_source_file(job->app, osf); dk4app_set_log_source_line(job->app, osl); finished: $? "- wxdrd_apply_file %d", back return back; } wxd_drawing_t * wxdrd_open_from_file(const dkChar *fn, wxd2lat_job_t *job) { wxd_drawing_t *back = NULL; FILE *fipo = NULL; const dkChar *osf = NULL; dk4_um_t osl = 0UL; int res = 0; osf = dk4app_get_log_source_file(job->app); osl = dk4app_get_log_source_line(job->app); dk4app_set_log_source_file(job->app, fn); dk4app_set_log_source_line(job->app, 0UL); back = wxdrd_open_empty(); if (NULL != back) { fipo = dk4fopen_app(fn, dkT("r"), 0, job->app); if (NULL != fipo) { res = wxdrd_apply_file(back, fipo, fn, job); fclose(fipo); } else { /* ERROR: Failed to open file. Already reported. */ } if (0 == res) { wxdrd_close(back); back = NULL; } } else { /* ERROR: Memory */ dk4app_log_base1(job->app, DK4_LL_ERROR, 90); } dk4app_set_log_source_file(job->app, osf); dk4app_set_log_source_line(job->app, osl); return back; } /* vim: set ai sw=4 ts=4 : */