Ejemplo n.º 1
0
/* ---- api functions ---- */
struct pgn_game_node* pgn_list_games(const char* filename){
    int fhandler;
    char line_buffer[128];
    struct pgn_game_node size_node, *first_game = NULL;
    struct pgn_game_node *curr_node = NULL, *temp_node;
    unsigned short game_count = 1;
    int line_count = 0;
    bool header_start = true, game_start = false;

    if ( (fhandler = rb->open(filename, O_RDONLY)) < 0 ) return NULL;

    if (bufptr == NULL){
        pl_malloc_init();
    }
    while (rb->read_line(fhandler, line_buffer, sizeof line_buffer) > 0){
        line_count++;
        /* looking for a game header */
        if (header_start) {
            /* a new game header is found */
            if (line_buffer[0] == '['){
                temp_node = (struct pgn_game_node *)pl_malloc(sizeof size_node);
                temp_node->next_node = NULL;
                if (curr_node == NULL) {
                    first_game = curr_node = temp_node;
                } else {
                    curr_node->next_node = temp_node;
                    curr_node = temp_node;
                }
                process_tag(curr_node, line_buffer);
                curr_node->game_number = game_count;
                curr_node->pgn_line = 0;
                game_count++;
                header_start = false;
                game_start = true;
            }
        } else {
            if (line_buffer[0] == '['){
                process_tag(curr_node, line_buffer);
            } else if (line_buffer[0] == '\r'
                       || line_buffer[0] == '\n'
                       || line_buffer[0] == '\0'){
                if (game_start) {
                    game_start = false;
                } else {
                    header_start = true;
                }
            } else {
                if (curr_node->pgn_line == 0) {
                    curr_node->pgn_line = line_count;
                }
            }
        }
    }
    rb->close(fhandler);
    return first_game;
}
Ejemplo n.º 2
0
/**
 * Process a tag
 */
static int tag_hook(void *user_data, char *name, char **atts, int type)
{
	int result = IKS_OK;
	struct nlsml_parser *parser = (struct nlsml_parser *)user_data;

	if (type == IKS_OPEN || type == IKS_SINGLE) {
		struct nlsml_node *child_node = malloc(sizeof(*child_node));
		child_node->name = name;
		child_node->tag_def = switch_core_hash_find(globals.tag_defs, name);
		if (!child_node->tag_def) {
			child_node->tag_def = switch_core_hash_find(globals.tag_defs, "ANY");
		}
		child_node->parent = parser->cur;
		parser->cur = child_node;
		switch_log_printf(SWITCH_CHANNEL_UUID_LOG(parser->uuid), SWITCH_LOG_DEBUG1, "<%s>\n", name);
		result = process_tag(parser, name, atts);
	}

	if (type == IKS_CLOSE || type == IKS_SINGLE) {
		struct nlsml_node *node = parser->cur;
		parser->cur = node->parent;
		free(node);
		switch_log_printf(SWITCH_CHANNEL_UUID_LOG(parser->uuid), SWITCH_LOG_DEBUG1, "</%s>\n", name);
	}

	return result;
}
Ejemplo n.º 3
0
static void
process_dense(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__DenseNodes *dense, struct maptool_osm *osm)
{
	int i,j=0,has_tags;
	long long id=0,lat=0,lon=0,changeset=0,timestamp=0;
	int user_sid=0,uid=0;

	if (!dense)
		return;

	for (i = 0 ; i < dense->n_id ; i++) {
		id+=dense->id[i];
		lat+=dense->lat[i];
		lon+=dense->lon[i];
		changeset+=dense->denseinfo->changeset[i];
		user_sid+=dense->denseinfo->user_sid[i];
		uid+=dense->denseinfo->uid[i];
		timestamp+=dense->denseinfo->timestamp[i];
		has_tags=dense->keys_vals && dense->keys_vals[j];
		osm_add_node(id, lat/latlon_scale,lon/latlon_scale);
#if 0
		printf("\t<node id=\"%Ld\" lat=\"%.7f\" lon=\"%.7f\" version=\"%d\" changeset=\"%Ld\"",id,lat/latlon_scale,lon/latlon_scale,dense->denseinfo->version[i],changeset);
		process_user(primitive_block, user_sid, uid, 0);
		process_timestamp(timestamp);
#endif
		if (has_tags) {
#if 0
			printf(">\n");
#endif
			while (dense->keys_vals[j]) {
				process_tag(primitive_block, dense->keys_vals[j], dense->keys_vals[j+1]);
				j+=2;
			}
#if 0
			printf("\t</node>\n");
		} else
			printf("/>\n");
#else
		}
#endif
		osm_end_node(osm);
		j++;
	}
Ejemplo n.º 4
0
static void go(Job *job, FILE *pjf)
{
    int c;
    while ((c = fgetc(pjf)) != EOF)
    {
        if (c != TAG_BEGIN)
            putchar(c);
        else
        {
            c = fgetc(pjf);
            if (c == TAG_CANCEL)
                putchar(c);
            else
            {
                ungetc(c, pjf);
                process_tag(job, pjf);
            }
        }
    }
}
Ejemplo n.º 5
0
static int process_object(struct walker *walker, struct object *obj)
{
	if (obj->type == OBJ_COMMIT) {
		if (process_commit(walker, (struct commit *)obj))
			return -1;
		return 0;
	}
	if (obj->type == OBJ_TREE) {
		if (process_tree(walker, (struct tree *)obj))
			return -1;
		return 0;
	}
	if (obj->type == OBJ_BLOB) {
		return 0;
	}
	if (obj->type == OBJ_TAG) {
		if (process_tag(walker, (struct tag *)obj))
			return -1;
		return 0;
	}
	return error("Unable to determine requirements "
		     "of type %s for %s",
		     typename(obj->type), sha1_to_hex(obj->sha1));
}
Ejemplo n.º 6
0
/**
 * Process a tag
 */
static int tag_hook(void *user_data, char *name, char **atts, int type)
{
	int result = IKS_OK;
	struct ssml_parser *parsed_data = (struct ssml_parser *)user_data;
	struct ssml_node *new_node = malloc(sizeof *new_node);
	struct ssml_node *parent_node = parsed_data->cur_node;

	if (type == IKS_OPEN || type == IKS_SINGLE) {
		if (parent_node) {
			/* inherit parent attribs */
			*new_node = *parent_node;
			new_node->parent_node = parent_node;
		} else {
			new_node->name[0] = '\0';
			new_node->language[0] = '\0';
			new_node->gender[0] = '\0';
			new_node->parent_node = NULL;
		}
		new_node->tts_voice = NULL;
		new_node->say_macro = NULL;
		strncpy(new_node->tag_name, name, TAG_LEN);
		new_node->tag_name[TAG_LEN - 1] = '\0';
		parsed_data->cur_node = new_node;
		result = process_tag(parsed_data, name, atts);
	}

	if (type == IKS_CLOSE || type == IKS_SINGLE) {
		if (parsed_data->cur_node) {
			struct ssml_node *parent_node = parsed_data->cur_node->parent_node;
			free(parsed_data->cur_node);
			parsed_data->cur_node = parent_node;
		}
	}

	return result;
}
Ejemplo n.º 7
0
void
RichTextBox::DrawRichText(Rect& text_rect)
{
    // clip the rect:
    Rect clip_rect = ClipRect(text_rect);
    clip_rect.h -= 8;

    if (clip_rect.w < 1 || clip_rect.h < 1)
    return;

    const char* t     = text.data();
    int count         = text.length();
    int nlines        = 0;

    int xpos          = 0;
    int block_start   = 0;
    int block_count   = 0;
    int curr_word_end = -1;
    int next_word_end = 0;
    int eol_index     = 0;

    int new_line      = 0;
    int x_offset      = 0;
    int y_offset      = 0;
    int length        = 0;

    Font* rich_font   = font;
    rich_font->SetColor(fore_color);

    if (smooth_scroll) {
        double fraction = smooth_offset - (int) smooth_offset;

        y_offset = (int) ((1-fraction) * (rich_font->Height() + leading));
    }

    // while there is still text:
    while (block_start < count) {
        bool found_tag = false;

        do {
            found_tag = false;

            if (t[block_start] == '<') {
                block_start = process_tag(t, block_start, rich_font);
                found_tag = true;
            }

            else if (t[block_start] == '\t') {
                block_start++;
                x_offset = GetNextTab(x_offset);

                if (x_offset > text_rect.w) {
                    nlines++;
                    if (nlines > top_index)
                    y_offset += rich_font->Height() + leading;
                    x_offset = 0;
                    new_line = false;
                }

                found_tag = true;
            }

            else if (t[block_start] == '\r') {
                block_start++;

                if (t[block_start] == '\n')
                block_start++;

                nlines++;
                if (nlines > top_index)
                y_offset += rich_font->Height() + leading;
                x_offset = 0;
                new_line = false;

                found_tag = true;
            }

            else if (t[block_start] == '\n') {
                block_start++;

                if (t[block_start] == '\r')
                block_start++;

                nlines++;
                if (nlines > top_index)
                y_offset += rich_font->Height() + leading;
                x_offset = 0;
                new_line = false;

                found_tag = true;
            }
        }
        while (found_tag);

        next_word_end = find_next_word_end(t, block_start);

        if (!next_word_end || next_word_end == curr_word_end) {
            new_line = true;
        }

        else if (t[next_word_end] == '\n') {
            eol_index = curr_word_end = next_word_end;
            new_line = true;
        }

        else {
            int word_len = next_word_end - block_start + 1;

            length = rich_font->StringWidth(t+block_start, word_len);

            // if this word was too long, wrap to next line:
            if (x_offset + length > text_rect.w) {
                nlines++;
                if (nlines > top_index)
                y_offset += rich_font->Height() + leading;
                x_offset = 0;
                new_line = false;
            }

            // is there a trailing newline?
            curr_word_end = next_word_end;

            // check for a newline in the next block of white space:
            eol_index = 0;
            const char* eol = &t[curr_word_end+1];
            while (*eol && isspace(*eol) && *eol != '\n')
            eol++;

            if (*eol == '\n') {
                eol_index = eol - t;
                new_line = true;
            }
        }

        block_count = curr_word_end - block_start + 1;

        if (block_count > 0) {
            length = rich_font->StringWidth(t+block_start, block_count);
        }

        // there was a single word longer than the entire line:
        else {
            block_count = next_word_end - block_start + 1;
            length = rich_font->StringWidth(t+block_start, block_count);
            curr_word_end = next_word_end;
        }

        if (length > 0 && nlines >= top_index && nlines < top_index+page_size) {
            int x1 = text_rect.x + x_offset + rect.x;
            int y1 = text_rect.y + y_offset + rect.y;

            rich_font->DrawString(t+block_start, block_count, x1, y1, clip_rect);
        }

        if (new_line) {
            nlines++;
            if (nlines > top_index)
            y_offset += rich_font->Height() + leading;
            x_offset = 0;
            new_line = false;
        }

        else if (length < 1 || text[next_word_end] == '-') {
            x_offset += length;
        }

        else {
            x_offset += length + rich_font->SpaceWidth();
        }

        if (eol_index > 0)
        curr_word_end = eol_index;

        block_start = find_next_word_start(t, curr_word_end+1);
    }

    line_count = nlines;
}
Ejemplo n.º 8
0
static void scan_gml( void )
{
    inputcb     *   cb;
    char        *   p;
    int             toklen;
    int             k;
    char            csave;
    bool            processed;
    gtentry     *   ge;                 // GML user tag entry
    mac_entry   *   me;                // script macro for processing GML tag
    char            linestr[MAX_L_AS_STR];
    char            tok_upper[TAG_NAME_LENGTH];

    cb = input_cbs;

    p = scan_start + 1;
    tok_start = scan_start;
    while( is_id_char( *p ) && p <= scan_stop ) { // search end of TAG
        p++;
    }
    scan_start = p;                      // store argument start address
    toklen = p - tok_start - 1;
    csave = *p;
    *p = '\0';
    if( toklen >= TAG_NAME_LENGTH ) {
        err_count++;
        // SC--009 The tagname is too long
        if( cb->fmflags & II_macro ) {
            ultoa( cb->s.m->lineno, linestr, 10 );
            g_err( err_tag_name, tok_start + 1, linestr, "macro",
                   cb->s.m->mac->name );
        } else {
            ultoa( cb->s.f->lineno, linestr, 10 );
            g_err( err_tag_name, tok_start + 1, linestr, "file",
                   cb->s.f->filename );
        }
        if( inc_level > 0 ) {
            show_include_stack();
        }
        *p = csave;
        scan_start = tok_start;         // process as text
        return;
    }

    if( GlobalFlags.firstpass && cb->fmflags & II_research ) {

        if(  stricmp( tok_start + 1, "cmt" ) ) {   // quiet for :cmt.

            if( cb->fmflags & II_macro ) {
                printf_research( "L%d    %c%s tag found in macro %s(%d)\n\n",
                                 inc_level, GML_char, tok_start + 1,
                                 cb->s.m->mac->name, cb->s.m->lineno );
            } else {
                printf_research( "L%d    %c%s tag found in file %s(%d)\n\n",
                                 inc_level, GML_char, tok_start + 1,
                                 cb->s.f->filename, cb->s.f->lineno );
            }
        }
        add_GML_tag_research( tok_start + 1 );
    }

    if( ProcFlags.layout ) {
        ge = NULL;                      // no user tags within :LAYOUT
    } else {
        ge = find_tag( &tag_dict, tok_start + 1 );
    }
    processed = false;
    me = NULL;
    if( ge != NULL ) {                  // GML user defined Tag found
        *p = csave;
        if( ge->tagflags & tag_off ) {  // inactive, treat as text
            scan_start = tok_start;
            return;
        }
        me = find_macro( macro_dict, ge->macname );
        if( me == NULL ) {
            err_count++;
            // SC--037: The macro 'xxxxxx' for the gml tag 'yyyyy'
            //          is not defined
            if( cb->fmflags & II_macro ) {
                ultoa( cb->s.m->lineno, linestr, 10 );
                g_err( err_tag_macro, ge->macname, ge->name,
                         linestr, "macro", cb->s.m->mac->name );
            } else {
                ultoa( cb->s.f->lineno, linestr, 10 );
                g_err( err_tag_macro, ge->macname, ge->name,
                         linestr, "file", cb->s.f->filename );
            }
            if( inc_level > 0 ) {
                show_include_stack();
            }
            *p = csave;
            scan_start = tok_start;         // process as text
            return;
        } else {

        /*******************************************************************/
        /*  The following is to prevent an endless loop                    */
        /*  Example from ow documentation:                                 */
        /*  .gt ZH1 add zh1                                                */
        /*  .gt H1 add zh1                                                 */
        /*  .dm zh1 begin                                                  */
        /*  ...                                                            */
        /*  :H1      <---- overridden gml tag                              */
        /*  ...                                                            */
        /*  .dm zh1 end                                                    */
        /*                                                                 */
        /*  we call the predefined :H1  instead                            */
        /*******************************************************************/

            if( (cb->fmflags & II_tag) && (cb->s.m->mac == me) ) {
                me = NULL;
            }
        }
    }
    if( me != NULL ) {                  // usertag and coresponding macro ok
        processed = process_tag( ge, me );
    } else {
        *p ='\0';
        for( k = 0; k <= toklen; k++ ) {
            tok_upper[k] = toupper( *(tok_start + 1 + k) );
        }
        tok_upper[k] = '\0';

        if( ProcFlags.layout ) {        // different tags within :LAYOUT
            for( k = 0; k < LAY_TAGMAX; ++k ) {
                if( toklen == lay_tags[k].taglen ) {
                    if( !strcmp( lay_tags[k].tagname, tok_upper ) ) {
                        *p = csave;
                        lay_ind = -1;   // process tag not attribute

                        lay_tags[k].gmlproc( &lay_tags[k] );

                        processed = true;
                        lay_ind = k;    // now process attributes if any
                        if( *scan_start == '.' ) {
                            scan_start++;
                        }
                        break;
                    }
                }
            }
            if( !processed ) {          // check for gml only tag in :LAYOUT
                for( k = 0; k < GML_TAGMAX; ++k ) {
                    if( toklen == gml_tags[k].taglen ) {
                        if( !strcmp( gml_tags[k].tagname, tok_upper ) ) {
                            g_err( err_gml_in_lay, gml_tags[k].tagname );
                            err_count++;
                            file_mac_info();
                            processed = true;
                            scan_start = scan_stop + 1;
                            break;
                        }
                    }
                }
            }
        } else {                        // not within :LAYOUT
            for( k = 0; k < GML_TAGMAX; ++k ) {
                if( toklen == gml_tags[k].taglen ) {
                    if( !strcmp( gml_tags[k].tagname, tok_upper ) ) {
                        if( GlobalFlags.firstpass &&
                            !strcmp(tok_upper, "LAYOUT" ) &&
                            ProcFlags.fb_document_done  ) {

                            g_err( err_lay_too_late );
                            err_count++;
                            file_mac_info();
                            processed = true;
                            scan_start = scan_stop + 1;
                            break;
                        }
                        *p = csave;

                        if( (rs_loc == 0) && !ProcFlags.need_li_lp ) {
                            // no restrictions: do them all
                            gml_tags[k].gmlproc( &gml_tags[k] );
                        } else if( ProcFlags.need_li_lp &&
                                ((gml_tags[k].taglocs & li_lp_tag) != 0) ) {
                            // tag is LP or LI
                            gml_tags[k].gmlproc( &gml_tags[k] );
                        } else if( (gml_tags[k].taglocs & rs_loc) != 0 ) {
                            // tag allowed in this restricted location
                            gml_tags[k].gmlproc( &gml_tags[k] );
                        } else if( (gml_tags[k].tagflags & tag_is_general) != 0 ) {
                            // tag allowed everywhere
                            gml_tags[k].gmlproc( &gml_tags[k] );
                        } else {
                            start_doc_sect();   // if not already done
                            if( ProcFlags.need_li_lp ) {
                                xx_nest_err( err_no_li_lp );
                            } else {            // rs_loc > 0
                                g_err_tag_rsloc( rs_loc, tok_start );
                            }
                        }
                        processed = true;
                        if( *scan_start == '.' ) {
                            scan_start++;
                        }
                        break;
                    }
                }
            }
            if( !processed ) {         // check for layout tag in normal text
                for( k = 0; k < LAY_TAGMAX; ++k ) {
                    if( toklen == lay_tags[k].taglen ) {
                        if( !strcmp( lay_tags[k].tagname, tok_upper ) ) {
                            g_err( err_lay_in_gml, lay_tags[k].tagname );
                            err_count++;
                            file_mac_info();
                            processed = true;
                            scan_start = scan_stop + 1;
                            break;
                        }
                    }
                }
            }
        }
    }
    if( *p == '\0' ) {
        *p = csave;
    }
    if( !processed ) {                  // treat as text
        scan_start = tok_start;
    }
}