/*****************************************************************************/ /* */ /* UNIT: NTL1_Assemble_Label (Level 1 library routine) */ /* */ /* Author: Nikola Stojanovic */ /* */ /* Revision: 19 JUL 94 Version 1.0 */ /* 07 APR 96 Version 2.0 */ /* */ /* Function: */ /* */ /* Procedure forms a list representing a complete label (with display */ /* fonts) based on a text string received in the input; returns the standard */ /* error structure, allocated if there were any errors in the layout of the */ /* defining string, NULL if the label has been assembled correctly */ /* */ /* */ /* Legal layout of a string defining a label: */ /* */ /*****************************************************************************/ #include #include #include "ntl1.h" /*****************************************************************************/ /* */ /* Definitions section */ /* */ /*****************************************************************************/ /*****************************************************************************/ /* Definitions of local constants of the unit */ /*****************************************************************************/ /* In case that font and its size are not supplied with the text in the */ /* string, the "default" values are to be placed in the record */ #define DEFAULT_LABEL_FONT_STRING NULL #define DEFAULT_LABEL_FONT_SIZE 0 /* Maximal permitted length of the number string defining label font size */ #define LABINT_MAX 4 /*****************************************************************************/ /* Prototypes of all locally used functions of this unit */ /*****************************************************************************/ errind NTL1_AL_Assemble_Error (int severity, int code, char *comment, int description); /*****************************************************************************/ /* */ /* Code section */ /* */ /*****************************************************************************/ /*****************************************************************************/ /* */ /* Procedure: NTL1_Assemble_Label */ errind NTL1_Assemble_Label (char *label_string, label_ptr *result) { char *scan, *start_str, save_scan; int len_count; label_ptr new_fraction; *result = NULL; scan = label_string; /* Initialize 'in' & 'out' structures */ while (*scan != '\0') { /* Loop for all label parts provided */ while ((*scan != '\"') && (*scan != '\0')) { /* Skip 'white space' */ if ((*scan != ' ') && (*scan != '\t') && (*scan != '\n')) return NTL1_AL_Assemble_Error (USER_ERROR, ERR_BAD_STRUCTURE, "Illegal label layout in string", 0); scan++; } if (*scan != '\0') { /* Some part of the label still to be read */ scan++; start_str = scan; while ((*scan != '\"') && (*scan != '\0')) scan++; if (*scan == '\0') return NTL1_AL_Assemble_Error (USER_ERROR, ERR_BAD_STRUCTURE, "Illegal label layout in string", 0); *scan = '\0'; /* Temporary replace the closing double-quote */ /* Some fraction of the label text has been collected, create new record */ new_fraction = (label_ptr) NTL0_ckalloc (sizeof (Label_Struct)); new_fraction -> text = NTL0_strsave (start_str); new_fraction -> font_name = NULL; new_fraction -> font_size = DEFAULT_LABEL_FONT_SIZE; new_fraction -> next = NULL; /* Now continue checking whether the font and its size are provided */ *scan = '\"'; scan++; while ((*scan == ' ') || (*scan == '\t') || (*scan == '\n')) scan++; if ((*scan == '\0') || (*scan == '\"')) { /* Font not supplied */ new_fraction -> font_name = NTL0_strsave (DEFAULT_LABEL_FONT_STRING); new_fraction -> font_size = DEFAULT_LABEL_FONT_SIZE; new_fraction -> next = *result; *result = new_fraction; } else { /* At least the name of the font is supplied with the text */ start_str = scan; while ((*scan != ' ') && (*scan != '\t') && (*scan != '\n') && (*scan != '\0')) scan++; save_scan = *scan; *scan = '\0'; new_fraction -> font_name = NTL0_strsave (start_str); /* Examine whether the font size is supplied, too, and set its value */ *scan = save_scan; while ((*scan == ' ') || (*scan == '\t') || (*scan == '\n')) scan++; if ((*scan != '\0') && (*scan != '\"')) { /* There is some "free" text */ if ((*scan < '1') || (*scan > '9')) /* Must be a number here */ return NTL1_AL_Assemble_Error (USER_ERROR, ERR_BAD_STRUCTURE, "Illegal label layout in string", 0); start_str = scan; len_count = 0; while ((*scan >= '0') && (*scan <= '9') && (len_count < LABINT_MAX)) scan++; if ((len_count >= LABINT_MAX) || ((*scan != ' ') && (*scan != '\t') && (*scan != '\n') && (*scan != '\0'))) return NTL1_AL_Assemble_Error (USER_ERROR, ERR_BAD_STRUCTURE, "Illegal label layout in string", 0); else { /* Legal number provided as size for the given font */ save_scan = *scan; *scan = '\0'; new_fraction -> font_size = atoi (start_str); *scan = save_scan; new_fraction -> next = *result; *result = new_fraction; } } else { /* Font string was provided, but font size was not */ new_fraction -> font_size = DEFAULT_LABEL_FONT_SIZE; new_fraction -> next = *result; *result = new_fraction; } } } } /* Now when the whole defining string has been processed, correct the order */ *result = NTL1_Flip_Label (*result); return NULL; /* Label assembled */ } /*****************************************************************************/ /* */ /* Procedure: NTL1_AL_Assemble_Error */ /* */ /* Service procedure for assembling and returnning an error report, based on */ /* the values of the input parameters; returns the record with the report */ errind NTL1_AL_Assemble_Error (int severity, int code, char *comment, int description) { char *report; errind assembled; report = (char *) NTL0_ckalloc ( (strlen (comment) + strlen ("_Assemble_Label: ") + 1) * sizeof (char)); sprintf (report, "_Assemble_Label: %s", comment); assembled = NTL1_Error_Record (severity, code, report, description); free (report); return assembled; }