bool i_char( char * p, lay_att curr, char * tm ) { curr = curr; if( is_quote_char( *p ) && (*p == *(p + 2)) ) { *tm = *(p + 1); // 2. char if quoted } else { *tm = *p; // else 1. } return( false ); }
static bool needs_quoting(std::string const& name) { if (name.size() > 0) { const char first = name[0]; if (is_quote_char(first)) { return false; } if ((first >= '0' && first <= '9') || (name.find("-") != std::string::npos) ) { return true; } } return false; }
bool i_default_frame( char * p, lay_att curr, def_frame * tm ) { bool cvterr; int len; curr = curr; cvterr = false; if( !strnicmp( "none", p, 4 ) ) { tm->type = none; } else if( !strnicmp( "rule", p, 4 ) ) { tm->type = rule_frame; } else if( !strnicmp( "box", p, 3 ) ) { tm->type = box_frame; } else if( !is_quote_char( *p ) ) { cvterr = true; } else { len = strlen( p ); if( *p != *(p + len - 1) ) { cvterr = true; // string not terminated } else { if( sizeof( tm->string ) > len - 2 ) { *(p + len - 1 ) = '\0'; strcpy_s( tm->string, sizeof( tm->string ), p + 1 ); tm->type = char_frame; } else { cvterr = true; // string too long; } } } if( cvterr ) { err_count++; g_err( err_att_val_inv ); file_mac_info(); } return( cvterr ); }
bool process_tag( gtentry * ge, mac_entry * me ) { bool processed; gaentry * ga; gavalentry * gaval; char * p; char * p2; int rc; char quote; char longwork[20]; bool tag_end_found = false; processed = true; init_dict( &loc_dict ); add_defaults_to_dict( ge, &loc_dict ); /***********************************************************************/ /* scan input for attributes and / or tagtext */ /***********************************************************************/ p = tok_start + ge->namelen + 1; // over tagname if( ge->attribs != NULL ) { // only process attributes if they exist while( *p == ' ' ) { // not yet end of tag, process attributes while( *p == ' ' ) { // over WS to attribute p++; } if( *p == '.' ) { tag_end_found = true; break; } p2 = token_buf; while( is_id_char( *p ) ) { *p2++ = *p++; } *p2 = '\0'; if( p2 != token_buf ) { // ignore nullstring for( ga = ge->attribs; ga != NULL; ga = ga->next ) {// all attrs if( !stricmp( ga->name, token_buf ) ) { ga->attflags |= att_proc_seen; // attribute specified if( ga->attflags & att_auto ) { auto_att_err(); break; } if( *p == '=' ) { // value follows ga->attflags |= att_proc_val; p++; // over = p2 = token_buf; if( is_quote_char( *p ) ) { quote = *p++; while( *p && *p != quote ) {// quoted value *p2++ = *p++; } if( *p == quote ) { p++;// over ending quote } } else { quote = '\0'; while( *p && (*p != ' ') && (*p != '.') ) { *p2++ = *p++; } } *p2 = '\0'; if( ga->attflags & att_off ) {// attribute inactive continue; } if( ga->attflags & att_upper ) {// uppercase option strupr( token_buf ); } scan_err = check_att_value( ga ); } else {// special for range set default2 if no value if( ga->attflags & att_range ) { for( gaval = ga->vals; gaval != NULL; gaval = gaval->next ) { if( gaval->valflags & val_range ) { break; } } if( gaval != NULL ) { sprintf( token_buf, "%d", gaval->a.range[3] ); rc = add_symvar( &loc_dict, ga->name, token_buf, no_subscript, local_var ); } } } break; } } if( ga == NULL ) { // attribute Not found char linestr[MAX_L_AS_STR]; processed = false; wng_count++; //***WARNING*** SC--040: 'abd' is not a valid attribute name g_warn( wng_att_name, token_buf ); if( input_cbs->fmflags & II_macro ) { ultoa( input_cbs->s.m->lineno, linestr, 10 ); g_info( inf_mac_line, linestr, input_cbs->s.m->mac->name ); } else { ultoa( input_cbs->s.f->lineno, linestr, 10 ); g_info( inf_file_line, linestr, input_cbs->s.f->filename ); } show_include_stack(); } } /***************************************************************/ /* check for tag end . */ /***************************************************************/ if( *p == ' ' ) { continue; // not yet at buffer / tag end } #if 0 /***************************************************************/ /* continue scanning for attriutes on next line if not tag end*/ /* This does not work for constructs such as */ /* */ /* :hdref refid=diffs */ /* .bd to determine if you need to recompile your application.*/ /* from docs\doc\gs\intro.gml line 37 f */ /***************************************************************/ if( *p != '.' ) { // if( get_line( true ) ) { p = buff2; } else { *p = '\0'; } } else { tag_end_found = true; } #else if( (*p == '.') || (*p == '\0') ) { tag_end_found = true; } #endif } /*******************************************************************/ /* check for missing reqrd attributes */ /*******************************************************************/ *token_buf = '\0'; for( ga = ge->attribs; ga != NULL; ga = ga->next ) {// for all attrs if( ga->attflags & att_req ) { if( !(ga->attflags & att_proc_seen) ) { if( *token_buf != '\0' ) { strcat( token_buf, " '" ); } else { strcpy( token_buf, "'" ); } strcat( token_buf, ga->name ); strcat( token_buf, "' " ); } } } if( *token_buf != '\0' ) { // some req attr missing char linestr[MAX_L_AS_STR]; // the errmsg in wgml 4.0 is wrong, it shows the macroname, not tag. // ****ERROR**** SC--047: For the tag '@willi', the required attribute(s) // 'muss2' // 'muss' // have not been specified processed = false; err_count++; g_err( err_att_req, ge->name, token_buf ); if( input_cbs->fmflags & II_macro ) { ultoa( input_cbs->s.m->lineno, linestr, 10 ); g_info( inf_mac_line, linestr, input_cbs->s.m->mac->name ); } else { ultoa( input_cbs->s.f->lineno, linestr, 10 ); g_info( inf_file_line, linestr, input_cbs->s.f->filename ); } show_include_stack(); } if( *p == '.' ) { // does text follow tag end if( strlen( p + 1 ) > 0 ) { if( ge->tagflags & tag_texterr ) { // no text allowed tag_text_err( ge->name ); processed = false; } } else { if( ge->tagflags & tag_textreq ) { // reqrd text missing tag_text_req_err( ge->name ); processed = false; } } strcpy( token_buf, p + 1 ); rc = add_symvar( &loc_dict, "_", token_buf, no_subscript, local_var ); p += strlen( token_buf ); } scan_start = p + 1; // all processed /*******************************************************************/ /* add standard symbols to dict */ /*******************************************************************/ rc = add_symvar( &loc_dict, "_tag", ge->name, no_subscript, local_var ); ge->usecount++; sprintf( longwork, "%d", ge->usecount ); rc = add_symvar( &loc_dict, "_n", longwork, no_subscript, local_var ); add_macro_cb_entry( me, ge ); // prepare GML macro as input input_cbs->local_dict = loc_dict; inc_inc_level(); // start new include level if( ge->tagflags & tag_cont ) { // +++++++++++++++++++ TBD trial post_space = 0; ProcFlags.ct = true; } if( input_cbs->fmflags & II_research && GlobalFlags.firstpass ) { print_sym_dict( input_cbs->local_dict ); } } else { // user-defined tag has no attributes if( ge->tagflags & tag_texterr ) { // no text allowed // '.' or CW_sep_char immediately after the tag does not count as text if( (*p == '.') || (*p == CW_sep_char ) ) { p++; } while( *p == ' ' ) { // spaces don't count as text p++; } if( *p ) { // text found tag_text_err( ge->name ); processed = false; return( processed ); } } if( ge->tagflags & tag_textreq ) { // text is required // per wgml 4.0 behavior if( *p == CW_sep_char ) { processed = false; return( processed ); } // '.' immediately after the tag does not count as text if( *p == '.' ) { p++; } while( *p == ' ' ) { // spaces don't count as text p++; } if( !*p ) { // no text found tag_text_req_err( ge->name ); processed = false; return( processed ); } } // per wgml 4.0 behavior if( *p == CW_sep_char ) { processed = false; return( processed ); } // '.' immediately after the tag is not passed to the macro if( *p == '.' ) { p++; } strcpy( token_buf, p ); rc = add_symvar( &loc_dict, "_", token_buf, no_subscript, local_var ); p += strlen( token_buf ); scan_start = p + 1; // all processed /*******************************************************************/ /* add standard symbols to dict */ /*******************************************************************/ rc = add_symvar( &loc_dict, "_tag", ge->name, no_subscript, local_var ); ge->usecount++; sprintf( longwork, "%d", ge->usecount ); rc = add_symvar( &loc_dict, "_n", longwork, no_subscript, local_var ); add_macro_cb_entry( me, ge ); // prepare GML macro as input input_cbs->local_dict = loc_dict; inc_inc_level(); // start new include level if( ge->tagflags & tag_cont ) { // +++++++++++++++++++ TBD trial post_space = 0; ProcFlags.ct = true; } if( input_cbs->fmflags & II_research && GlobalFlags.firstpass ) { print_sym_dict( input_cbs->local_dict ); } } return( processed ); }
void AsxTokenizer::move_next () { char c; while ((c = read_char ()) != -1) { if (in_data) { bool entirely_whitespace; current_token->set_type (TOKEN_DATA); current_token->set_value (read_data (c, entirely_whitespace)); current_token->set_entirely_whitespace (entirely_whitespace); return; } if (c == OP_OPEN_ELEMENT) { if (is_comment_open (c)) { read_comment (); continue; } current_token->set_type (TOKEN_OPEN_ELEMENT); current_token->set_value (NULL); in_data = false; return; } if (c == OP_CLOSE_ELEMENT) { current_token->set_type (TOKEN_CLOSE_ELEMENT); current_token->set_value (NULL); in_data = true; return; } if (c == OP_ASSIGNMENT) { current_token->set_type (TOKEN_ASSIGNMENT); current_token->set_value (NULL); return; } if (c == OP_SLASH) { current_token->set_type (TOKEN_SLASH); current_token->set_value (NULL); return; } if (g_ascii_isspace (c)) { current_token->set_type (TOKEN_WHITESPACE); current_token->set_value (NULL); return; } if (is_quote_char (c)) { current_token->set_type (TOKEN_QUOTED_STRING); current_token->set_value (read_quoted_string (c)); return; } if (is_name_char (c)) { current_token->set_type (TOKEN_NAME); current_token->set_value (read_name (c)); return; } } current_token->set_type (TOKEN_EOF); current_token->set_value (NULL); }
condcode get_lay_sub_and_value( att_args * args ) { char * p; char quote; condcode rc; p = scan_start; rc = no; while( is_space_tab_char( *p ) ) { // over WS to start of name p++; } args->start[0] = p; args->len[0] = -1; // switch for scanning error args->len[1] = -1; // switch for scanning error while( *p && is_lay_att_char( *p ) ) { p++; } if( *p == '\0' ) { if( p == args->start[0] ) { rc = omit; // nothing found } return( rc ); // or parsing error } args->len[0] = p - args->start[0]; if( args->len[0] < 4 ) { // attribute name length err_count++; g_err( err_att_name_inv ); file_mac_info(); return( rc ); } while( is_space_tab_char( *p ) ) { // over WS to = p++; } if(*p && *p == '=' ) { p++; while( is_space_tab_char( *p ) ) { // over WS to attribute value p++; } } else { err_count++; g_err( err_att_val_inv ); file_mac_info(); return( no ); // parsing err '=' missing } args->start[1] = p; // delimiters must be included for error checking if( is_quote_char( *p ) ) { quote = *p; ++p; args->quoted = true; } else { quote = ' '; args->quoted = false; } while( *p && *p != quote ) { ++p; } if( args->quoted && is_quote_char( *p ) ) { p++; // over terminating quote } args->len[1] = p - args->start[1]; if( args->len[1] < 1 ) { // attribute value length err_count++; g_err( err_att_val_inv ); file_mac_info(); } else { rc = pos; } if( *p == '.' ) { ProcFlags.tag_end_found = true; p++; } val_start = args->start[1]; val_len = args->len[1]; if( args->quoted) { // delimiters must be omitted for these externs val_start++; val_len -= 2; } scan_start = p; return( rc ); }
void gml_hdref( const gmltag * entry ) { char * p; char * pa; char * pe; char * idp; char quote; char c; bool idseen; bool pageseen; bool withpage; size_t len; char buf64[64]; ref_entry * re; static char undefid[] = "\"Undefined Heading\" on page XXX"; idseen = false; pageseen = false; withpage = false; p = scan_start; re = NULL; /***********************************************************************/ /* Scan attributes for :HDREF */ /* id= */ /* page= */ /***********************************************************************/ for( ;; ) { while( *p == ' ' ) { p++; } if( *p == '\0' || *p == '.' ) { break; // tag end found } if( !strnicmp( "page=", p, 5 ) ) { p += 5; while( *p == ' ' ) { p++; } pa = p; if( !strnicmp( "yes", p, 3 ) ) { pageseen = true; withpage = true; p += 3; } else { if( !strnicmp( "no", p, 2 ) ) { pageseen = true; withpage = false; p += 2; } else { g_err( err_inv_att_val ); file_mac_info(); err_count++; while( *p && (*p != '.') && (*p != ' ') ) p++; } } scan_start = p; continue; } if( !strnicmp( "refid=", p, 6 ) ) { p += 6; while( *p == ' ' ) { p++; } if( is_quote_char( *p ) ) { quote = *p; p++; } else { quote = '\0'; } pa = p; while( *p && is_id_char( *p ) ) { p++; } len = __min( ID_LEN, p - pa );// restrict length as in ghx.c if( len > 0 ) { idseen = true; // valid id attribute found pe = pa + len; c = *pe; *pe = '\0'; re = find_refid( ref_dict, strlwr( pa ) ); if( re != NULL ) { // id found in ref dict idp = mem_alloc( 4 + strlen( re->text_cap ) ); *idp = '"'; // decorate with quotes strcpy( idp + 1, re->text_cap ); strcat( idp, "\"" ); } else { if( GlobalFlags.lastpass ) { g_warn( wng_id_xxx, pa ); g_info( inf_id_unknown ); file_mac_info(); wng_count++; } } *pe = c; } if( *p && (quote == *p) ) { p++; } scan_start = p; continue; } /*******************************************************************/ /* no more valid attributes */ /*******************************************************************/ break; } if( *p == '.' ) { // tag end ? p++; } if( idseen ) { // id attribute was specified bool concatsave = ProcFlags.concat; ProcFlags.concat = true; // make process_text add to line if( re == NULL ) { // undefined refid process_text( undefid, g_curr_font_num ); } else { process_text( idp, g_curr_font_num ); if( withpage || (!pageseen && (page != re->pageno)) ) { sprintf_s( buf64, sizeof( buf64 ), "on page %d", re->pageno ); process_text( buf64, g_curr_font_num ); } mem_free( idp ); } ProcFlags.concat = concatsave; } else { g_err( err_att_missing ); // id attribute missing file_mac_info(); err_count++; } scan_start = p; return; }