示例#1
0
static int avi_write_trailer(AVFormatContext *s)
{
    AVIContext *avi = s->priv_data;
    ByteIOContext *pb = &s->pb;
    int res = 0;
    int i, j, n, nb_frames;
    offset_t file_size;

    if (!url_is_streamed(pb)){
        if (avi->riff_id == 1) {
            end_tag(pb, avi->movi_list);
            res = avi_write_idx1(s);
            end_tag(pb, avi->riff_start);
        } else {
            avi_write_ix(s);
            end_tag(pb, avi->movi_list);
            end_tag(pb, avi->riff_start);

            file_size = url_ftell(pb);
            url_fseek(pb, avi->odml_list - 8, SEEK_SET);
            put_tag(pb, "LIST"); /* Making this AVI OpenDML one */
            url_fskip(pb, 16);

            for (n=nb_frames=0;n<s->nb_streams;n++) {
                AVCodecContext *stream = s->streams[n]->codec;
                if (stream->codec_type == CODEC_TYPE_VIDEO) {
                    if (nb_frames < avi->packet_count[n])
                        nb_frames = avi->packet_count[n];
                } else {
                    if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3) {
                        nb_frames += avi->packet_count[n];
                    }
                }
            }
            put_le32(pb, nb_frames);
            url_fseek(pb, file_size, SEEK_SET);

            avi_write_counters(s, avi->riff_id);
        }
    }
    put_flush_packet(pb);

    for (i=0; i<MAX_STREAMS; i++) {
         for (j=0; j<avi->indexes[i].ents_allocated/AVI_INDEX_CLUSTER_SIZE; j++)
              av_free(avi->indexes[i].cluster[j]);
         av_free(avi->indexes[i].cluster);
         avi->indexes[i].cluster = NULL;
         avi->indexes[i].ents_allocated = avi->indexes[i].entry = 0;
    }

    return res;
}
示例#2
0
static void
writeText( ByteStream & str_out,
            const GUTF8String &textUTF8,
            const DjVuTXT::Zone &zone,
            const int WindowHeight )
{
//  DEBUG_MSG( "--zonetype=" << zone.ztype << "\n" );

  const GUTF8String xindent(indent( 2 * zone.ztype + 2 ));
  GPosition pos=zone.children;
  // Build attribute string
  if( ! pos )
  {
    GUTF8String coords;
    coords.format("coords=\"%d,%d,%d,%d\"",
      zone.rect.xmin, WindowHeight - 1 - zone.rect.ymin,
      zone.rect.xmax, WindowHeight - 1 - zone.rect.ymax);
    const int start=zone.text_start;
    const int end=textUTF8.firstEndSpace(start,zone.text_length);
    str_out.writestring(start_tag(zone.ztype,coords));
    str_out.writestring(textUTF8.substr(start,end-start).toEscaped());
    str_out.writestring(end_tag(zone.ztype));
  } else
  {
    writeText(str_out,textUTF8,zone.ztype,zone.children,WindowHeight);
  }
}
示例#3
0
 result_type operator()(StoppableGenerator& gen) const
 {
     return result_type(
         iter_t(gen, begin_tag()),
         iter_t(gen, end_tag())
     );
 }
示例#4
0
文件: wav.c 项目: Haaaaaank/avbin
static int wav_write_trailer(AVFormatContext *s)
{
    ByteIOContext *pb = s->pb;
    WAVContext *wav = s->priv_data;
    int64_t file_size;

    if (!url_is_streamed(s->pb)) {
        end_tag(pb, wav->data);

        /* update file size */
        file_size = url_ftell(pb);
        url_fseek(pb, 4, SEEK_SET);
        put_le32(pb, (uint32_t)(file_size - 8));
        url_fseek(pb, file_size, SEEK_SET);

        put_flush_packet(pb);

        if(s->streams[0]->codec->codec_tag != 0x01) {
            /* Update num_samps in fact chunk */
            int number_of_samples;
            number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration,
                                           s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num,
                                           s->streams[0]->time_base.den);
            url_fseek(pb, wav->data-12, SEEK_SET);
            put_le32(pb, number_of_samples);
            url_fseek(pb, file_size, SEEK_SET);
            put_flush_packet(pb);
        }
    }
    return 0;
}
示例#5
0
void config_write_end_tag(struct writeconfig *wc, const char *entity)
{
     GString *outstr = g_string_sized_new(128);

     end_tag(outstr, entity);

     config_write(wc, outstr->str);
     g_string_free(outstr, TRUE);
}
示例#6
0
void inline parse_collection(FILE *collection) {
	char *buffer = new char[BUF_SIZE];
	int size = 0;
    
    begin_indexing();

	char c = getc(collection);
	while (c != EOF) {
	    size = 0;
		// Token 
		if (c == '<') {
			c = getc(collection);
			// End Tag
			if (c == '/') {
			    c = getc(collection);
				while (c != '>' && isalnum(c)) {
					buffer[size++] = c;
					c = getc(collection);
				}
                if (c == '>') {
                    buffer[size] = '\0';
                    end_tag(buffer);
                } else {
                    printf("End tag error\n");
                }
               
			// Start Tag
			} else {
				while (c != '>' && isalnum(c)) {
					buffer[size++] = c;
					c = getc(collection);
				}
                if (c == '>') {
                    buffer[size] = '\0';
                    start_tag(buffer);
                } else {
                    printf("End tag error\n");
                }
			}
		}

		// Words
		// This is lazy, I know; but ambiguous cases are a nearly bottomless rabbit hole.
        // Furthermore, the WSJ doesn't escape & properly, so nither do I.
		if (isalpha(c)) {
			do {
			    buffer[size++] = tolower(c);
			    c = getc(collection);
			} while(isalpha(c));
			buffer[size] = '\0';
            word(buffer);
            continue;
		}
        c = getc(collection);
    }
    end_indexing();
}
示例#7
0
void config_write_int(struct writeconfig *wc, int value, const char *entity,
		      GHashTable *attr)
{
     GString *outstr = g_string_sized_new(128);

     start_tag(outstr, entity, attr);
     g_string_sprintfa(outstr, "%d", value);
     end_tag(outstr, entity);

     config_write(wc, outstr->str);
     g_string_free(outstr, TRUE);
}
示例#8
0
void
DjVuTXT::writeText(ByteStream &str_out,const int height) const
{
  if(has_valid_zones())
  {
    ::writeText(str_out,textUTF8,DjVuTXT::PAGE,page_zone.children,height);
  }else
  {
    str_out.writestring(start_tag(DjVuTXT::PAGE));
    str_out.writestring(end_tag(DjVuTXT::PAGE));
  }
}
示例#9
0
文件: wav.c 项目: Haaaaaank/avbin
static int wav_write_header(AVFormatContext *s)
{
    WAVContext *wav = s->priv_data;
    ByteIOContext *pb = s->pb;
    int64_t fmt, fact;

    put_tag(pb, "RIFF");
    put_le32(pb, 0); /* file length */
    put_tag(pb, "WAVE");

    /* format header */
    fmt = start_tag(pb, "fmt ");
    if (put_wav_header(pb, s->streams[0]->codec) < 0) {
        av_log(s, AV_LOG_ERROR, "%s codec not supported in WAVE format\n",
               s->streams[0]->codec->codec ? s->streams[0]->codec->codec->name : "NONE");
        av_free(wav);
        return -1;
    }
    end_tag(pb, fmt);

    if(s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */
       && !url_is_streamed(s->pb)) {
        fact = start_tag(pb, "fact");
        put_le32(pb, 0);
        end_tag(pb, fact);
    }

    av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
    wav->maxpts = wav->last_duration = 0;
    wav->minpts = INT64_MAX;

    /* data header */
    wav->data = start_tag(pb, "data");

    put_flush_packet(pb);

    return 0;
}
示例#10
0
static GUTF8String
tolayer(int &layer, const DjVuTXT::ZoneType next_layer)
{
  GUTF8String retval;
  for( ;layer < (int)next_layer;layer++ )
  {
    retval+=start_tag(layer);
  }
  while (layer > (int)next_layer )
  {
    retval+=end_tag(--layer);
  }
  return retval;
}
示例#11
0
	// xml_output_stream interface
	void write(xml_event const& ev)
	{
		switch( ev.type ) {
		case xml_event::START_ELEMENT:
			start_tag(ev.content, ev.attributes);
			break;
		case xml_event::END_ELEMENT:
			end_tag(ev.content);
			break;
		case xml_event::CDATA:
			char_data(ev.content);
			break;
		default:
			assert(false);
		}
	}
示例#12
0
static int avi_write_idx1(AVFormatContext *s)
{
    ByteIOContext *pb = &s->pb;
    AVIContext *avi = s->priv_data;
    offset_t idx_chunk;
    int i;
    char tag[5];

    if (!url_is_streamed(pb)) {
        AVIIentry* ie = 0, *tie;
        int entry[MAX_STREAMS];
        int empty, stream_id = -1;

        idx_chunk = start_tag(pb, "idx1");
        memset(&entry[0], 0, sizeof(entry));
        do {
            empty = 1;
            for (i=0; i<s->nb_streams; i++) {
                 if (avi->indexes[i].entry <= entry[i])
                     continue;

                 tie = avi_get_ientry(&avi->indexes[i], entry[i]);
                 if (empty || tie->pos < ie->pos) {
                     ie = tie;
                     stream_id = i;
                 }
                 empty = 0;
            }
            if (!empty) {
                avi_stream2fourcc(&tag[0], stream_id,
                                  s->streams[stream_id]->codec->codec_type);
                put_tag(pb, &tag[0]);
                put_le32(pb, ie->flags);
                put_le32(pb, ie->pos);
                put_le32(pb, ie->len);
                entry[stream_id]++;
            }
        } while (!empty);
        end_tag(pb, idx_chunk);

        avi_write_counters(s, avi->riff_id);
    }
    return 0;
}
示例#13
0
void check_team_frozen( CHAR_DATA *ch )
{
    DESCRIPTOR_DATA        *d,
                           *d_next;
    char                    buf[MAX_STRING_LENGTH];
    bool                    cblue = FALSE,
        cred = FALSE;

    if ( IS_NPC( ch ) || !ch->pcdata )
        return;

    if ( xIS_SET( ch->act, PLR_BLUE ) )
        cblue = TRUE;
    else if ( xIS_SET( ch->act, PLR_RED ) )
        cred = TRUE;
    else
        return;

    for ( d = first_descriptor; d; d = d_next ) {
        d_next = d->next;

        if ( d->connected != CON_PLAYING || !d->character || IS_NPC( d->character ) )
            continue;
        if ( !xIS_SET( d->character->act, PLR_PLAYING ) )
            continue;
        if ( cblue && !xIS_SET( d->character->act, PLR_BLUE ) )
            continue;
        if ( cred && !xIS_SET( d->character->act, PLR_RED ) )
            continue;
        if ( !xIS_SET( d->character->act, PLR_FROZEN ) )    /* At least one person on the 
                                                             * team isn't * frozen */
            return;
    }

    /*
     * If we made it this far then everyone on the team has been frozen 
     */
    snprintf( buf, sizeof( buf ), "&R[&WEvento de congelación&R] &WEl equipo %s &Wha ganado!!!",
              cblue ? "&RROJO" : "&CAZUL" );
    tag_channel( NULL, buf );
    end_tag(  );
}
示例#14
0
void config_write_string(struct writeconfig *wc,
			 const char *value,
			 const char *entity, GHashTable *attr)
{
     GString *outstr = g_string_sized_new(1024);
     gunichar c;

     start_tag(outstr, entity, attr);

     for(c = g_utf8_get_char(value); c ;
	 value = g_utf8_next_char(value), c = g_utf8_get_char(value)) {
	  switch(c) {
	  case '<':
	       g_string_append(outstr, "&lt;");
	       break;
	  case '>':
	       g_string_append(outstr, "&gt;");
	       break;
	  case '&':
	       g_string_append(outstr, "&amp;");
	       break;
	  case '\'':
	       g_string_append(outstr, "&apos;");
	       break;
	  case '"':
	       g_string_append(outstr, "&quot;");
	       break;
	  default:
	       g_string_append_unichar(outstr, c);
	  }
     }

     end_tag(outstr, entity);
     config_write(wc, outstr->str);

     g_string_free(outstr, TRUE);
}
示例#15
0
    void xml_writer_impl::write_element(const variant& element)
    {
        try
        {
            if (element.is<variant::Collection>() && element.empty() && element.type() != variant::DataTable)
            {
                write_empty_element();
                return;
            }

            switch(element.type())
            {
            case variant::None:
            {
                write_empty_element();
                break;
            }
            case variant::Any:
            case variant::String:
            {
                if (element.as<std::string>().empty())
                {
                    write_empty_element();
                    break;
                }
            }
            case variant::Float:
            case variant::Double:
            case variant::Int32:
            case variant::UInt32:
            case variant::Int64:
            case variant::UInt64:
            case variant::Boolean:
            case variant::Date:
            case variant::Time:
            case variant::DateTime:
            {
                m_os << start_tag();
                write_text(element);
                m_os << end_tag();
                break;
            }
            case variant::Dictionary:
            case variant::Bag:
            {
                if ((m_mode & xml_mode::Preserve)!=0)
                {
                    if (element.has_key(xml_attributes))
                    {
                        m_stack.top().m_attributes = element[xml_attributes];

                        if (element.size()==1)
                        {
                            write_empty_element();
                            break;
                        }
                    }

                    m_os << start_tag();

                    bool prev_is_text = false;
                    variant::const_iterator it, end(element.end());
                    for (it=element.begin(); it!=end; ++it)
                    {
                        if (it.key()==xml_attributes)
                        {
                            continue;
                        }
                        else if (it.key()==xml_text)
                        {
                            write_text(it.value());
                            prev_is_text = true;
                        }
                        else if (it.key()==xml_instruction)
                        {
                            push(it.key());

                            if (!prev_is_text)
                            {
                                m_os << indent();
                            }

                            write_instruction(it.value());

                            prev_is_text = false;

                            pop();
                        }
                        else if (it.key()==xml_comment)
                        {
                            push(it.key());

                            if (!prev_is_text)
                            {
                                m_os << indent();
                            }

                            write_comment(it.value());

                            prev_is_text = false;

                            pop();
                        }
                        else
                        {
                            push(it.key());

                            if (!prev_is_text)
                            {
                                m_os << indent();
                            }

                            write_element(it.value());

                            prev_is_text = false;

                            pop();
                        }
                    }

                    if (!prev_is_text)
                    {
                        m_os << indent();
                    }

                    m_os << end_tag();
                }
                else
                {
                    m_os << start_tag();

                    variant::const_iterator it, end(element.end());
                    for (it=element.begin(); it!=end; ++it)
                    {
                        push(it.key());

                        m_os << indent();
                        write_variant(it.value());

                        pop();
                    }

                    m_os << indent() << end_tag();
                }

                break;
            }
            case variant::List:
            {
                m_os << start_tag();

                BOOST_FOREACH(const variant& item, element)
                {
                    push();
                    m_os << indent();
                    write_variant(item);
                    pop();
                }

                m_os << indent();
                m_os << end_tag();

                break;
            }
            case variant::Tuple:
            {
                m_stack.top().m_attributes.insert("size", variant(element.size()));
                m_os << start_tag();

                BOOST_FOREACH(const variant& item, element)
                {
                    push();
                    m_os << indent();
                    write_variant(item);
                    pop();
                }

                m_os << indent();
                m_os << end_tag();
                break;
            }
            case variant::TimeSeries:
            {
                m_os << start_tag();

                variant::const_iterator it, end = element.end();
                for (it=element.begin(); it!=end; ++it)
                {
                    push().insert("time", variant(it.time()));
                    m_os << indent();
                    write_variant(it.value());
                    pop();
                }

                m_os << indent();
                m_os << end_tag();
                break;
            }
            case variant::DataTable:
            {
                const data_table& dt = element.m_value.get<variant::DataTable>();

                m_stack.top().m_attributes
                    .insert("rows",    variant(dt.size()))
                    .insert("columns", variant(dt.columns().size()));
                m_os << start_tag();

                if (!dt.columns().empty())
                {
                    push("Columns");
                    m_os << indent() << start_tag();

                    for (data_table::column_container_type::const_iterator column_iter = dt.columns().begin()
                           ; column_iter != dt.columns().end()
                           ; ++column_iter)
                    {
                        push("Column")
                            .insert("name", variant(column_iter->name()))
                            .insert("type", variant(variant::enum_to_string(column_iter->type())));
                        m_os << indent();
                        write_empty_element();
                        pop();
                    }

                    m_os << indent() << end_tag();
                    pop();
                }

                for (data_table::column_container_type::const_iterator column_iter = dt.columns().begin()
                       ; column_iter != dt.columns().end()
                       ; ++column_iter)
                {
                    push("Column").insert("name", variant(column_iter->name()));
                    m_os << indent() << start_tag();

                    if (column_iter->type() & variant_base::Primitive)
                    {
                        boost::scoped_ptr<data_table_column_writer> column_writer(
                            make_data_table_column_stream_writer(*column_iter, m_os)
                        );

                        while (column_writer->has_next())
                        {
                            push("V");
                            m_os << indent() << start_tag();
                            column_writer->write();
                            m_os << end_tag();
                            pop();

                            column_writer->advance();
                        }
                    }
                    else
                    {
                        variant::const_iterator iter(column_iter->begin());
                        variant::const_iterator end(column_iter->end());
                        while (iter != end)
                        {
                            push("V");
                            m_os << indent();
                            write_variant(*(iter++));
                            pop();
                        }
                    }

                    m_os << indent() << end_tag();
                    pop();
                }

                m_os << indent();
                m_os << end_tag();

                break;
            }
            case variant::Buffer:
            {
                m_os << start_tag();
                const void *data = element.as<void*>();
                size_t size = element.size();
                if (data!=nullptr && size>0)
                {
                    unsigned int n = 0;
                    boost::scoped_ptr<char> b64(detail::b64_encode((const char*)data, (unsigned int)size, &n));
                    if (!b64.get())
                    {
                        boost::throw_exception(variant_error("Unable to base64 encode data"));
                    }
                    m_os << b64.get();
                }
                m_os << end_tag();
                break;
            }
            case variant::Object:
            {
                const object& obj(element.as<object>());

                // write class name
                m_stack.top().m_attributes
                    .insert("class", variant(obj.name()))
                    .insert("version", variant(obj.version()));

                m_os << start_tag();

                // write parameter dictionary
                variant params;
                obj.deflate(params);
                push("params");
                m_os << indent();
                write_variant(params);
                pop();

                m_os << indent();
                m_os << end_tag();

                break;
            }
            case variant::Exception:
            {
                m_os << start_tag();

                exception_data e(element.as<exception_data>());

                push("type");
                m_os << indent();
                write_element(variant(e.type()));
                pop();
                
                push("message");
                m_os << indent();
                write_element(variant(e.message()));
                pop();

                if (!e.source().empty())
                {
                    push("source");
                    m_os << indent();
                    write_element(variant(e.source()));
                    pop();
                }

                if (!e.stack().empty())
                {
                    push("stack");
                    m_os << indent();
                    write_element(variant(e.stack()));
                    pop();
                }

                m_os << indent();
                m_os << end_tag();
                break;
            }
            case variant::Array:
            {
                const typed_array& a(element.as<typed_array>());
                m_stack.top().m_attributes
                    .insert("size", variant(a.size()))
                    .insert("type", variant(variant::enum_to_string(a.type())));
                
                m_os << start_tag();

                for (size_t i=0; i<a.size(); ++i)
                {
                    push();
                    m_os << indent();
                    write_element(variant(a[i]));
                    pop();
                }

                m_os << indent();
                m_os << end_tag();
                break;
            }
            default:
                 boost::throw_exception(variant_error("Case exhaustion: " + variant::enum_to_string(element.type()))); 
            }
示例#16
0
static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
{
    AVIContext *avi = s->priv_data;
    ByteIOContext *pb = &s->pb;
    unsigned char tag[5];
    unsigned int flags=0;
    const int stream_index= pkt->stream_index;
    AVCodecContext *enc= s->streams[stream_index]->codec;
    int size= pkt->size;

//    av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %d\n", pkt->dts, avi->packet_count[stream_index], stream_index);
    while(enc->block_align==0 && pkt->dts != AV_NOPTS_VALUE && pkt->dts > avi->packet_count[stream_index]){
        AVPacket empty_packet;

        av_init_packet(&empty_packet);
        empty_packet.size= 0;
        empty_packet.data= NULL;
        empty_packet.stream_index= stream_index;
        avi_write_packet(s, &empty_packet);
//        av_log(s, AV_LOG_DEBUG, "dup %"PRId64" %d\n", pkt->dts, avi->packet_count[stream_index]);
    }
    avi->packet_count[stream_index]++;

    // Make sure to put an OpenDML chunk when the file size exceeds the limits
    if (!url_is_streamed(pb) &&
        (url_ftell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) {

        avi_write_ix(s);
        end_tag(pb, avi->movi_list);

        if (avi->riff_id == 1)
            avi_write_idx1(s);

        end_tag(pb, avi->riff_start);
        avi->movi_list = avi_start_new_riff(avi, pb, "AVIX", "movi");
    }

    avi_stream2fourcc(&tag[0], stream_index, enc->codec_type);
    if(pkt->flags&PKT_FLAG_KEY)
        flags = 0x10;
    if (enc->codec_type == CODEC_TYPE_AUDIO) {
       avi->audio_strm_length[stream_index] += size;
    }

    if (!url_is_streamed(&s->pb)) {
        AVIIndex* idx = &avi->indexes[stream_index];
        int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
        int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
        if (idx->ents_allocated <= idx->entry) {
            idx->cluster = av_realloc(idx->cluster, (cl+1)*sizeof(void*));
            if (!idx->cluster)
                return -1;
            idx->cluster[cl] = av_malloc(AVI_INDEX_CLUSTER_SIZE*sizeof(AVIIentry));
            if (!idx->cluster[cl])
                return -1;
            idx->ents_allocated += AVI_INDEX_CLUSTER_SIZE;
        }

        idx->cluster[cl][id].flags = flags;
        idx->cluster[cl][id].pos = url_ftell(pb) - avi->movi_list;
        idx->cluster[cl][id].len = size;
        idx->entry++;
    }

    put_buffer(pb, tag, 4);
    put_le32(pb, size);
    put_buffer(pb, pkt->data, size);
    if (size & 1)
        put_byte(pb, 0);

    put_flush_packet(pb);
    return 0;
}
示例#17
0
static int avi_write_header(AVFormatContext *s)
{
    AVIContext *avi = s->priv_data;
    ByteIOContext *pb = &s->pb;
    int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
    AVCodecContext *stream, *video_enc;
    offset_t list1, list2, strh, strf;

    /* header list */
    avi->riff_id = 0;
    list1 = avi_start_new_riff(avi, pb, "AVI ", "hdrl");

    /* avi header */
    put_tag(pb, "avih");
    put_le32(pb, 14 * 4);
    bitrate = 0;

    video_enc = NULL;
    for(n=0;n<s->nb_streams;n++) {
        stream = s->streams[n]->codec;
        bitrate += stream->bit_rate;
        if (stream->codec_type == CODEC_TYPE_VIDEO)
            video_enc = stream;
    }

    nb_frames = 0;

    if(video_enc){
        put_le32(pb, (uint32_t)(INT64_C(1000000) * video_enc->time_base.num / video_enc->time_base.den));
    } else {
        put_le32(pb, 0);
    }
    put_le32(pb, bitrate / 8); /* XXX: not quite exact */
    put_le32(pb, 0); /* padding */
    if (url_is_streamed(pb))
        put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */
    else
        put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */
    avi->frames_hdr_all = url_ftell(pb); /* remember this offset to fill later */
    put_le32(pb, nb_frames); /* nb frames, filled later */
    put_le32(pb, 0); /* initial frame */
    put_le32(pb, s->nb_streams); /* nb streams */
    put_le32(pb, 1024 * 1024); /* suggested buffer size */
    if(video_enc){
        put_le32(pb, video_enc->width);
        put_le32(pb, video_enc->height);
    } else {
        put_le32(pb, 0);
        put_le32(pb, 0);
    }
    put_le32(pb, 0); /* reserved */
    put_le32(pb, 0); /* reserved */
    put_le32(pb, 0); /* reserved */
    put_le32(pb, 0); /* reserved */

    /* stream list */
    for(i=0;i<n;i++) {
        list2 = start_tag(pb, "LIST");
        put_tag(pb, "strl");

        stream = s->streams[i]->codec;

        /* FourCC should really be set by the codec itself */
        if (! stream->codec_tag) {
            stream->codec_tag = codec_get_bmp_tag(stream->codec_id);
        }

        /* stream generic header */
        strh = start_tag(pb, "strh");
        switch(stream->codec_type) {
        case CODEC_TYPE_VIDEO: put_tag(pb, "vids"); break;
        case CODEC_TYPE_AUDIO: put_tag(pb, "auds"); break;
//        case CODEC_TYPE_TEXT : put_tag(pb, "txts"); break;
        case CODEC_TYPE_DATA : put_tag(pb, "dats"); break;
        }
        if(stream->codec_type == CODEC_TYPE_VIDEO)
            put_le32(pb, stream->codec_tag);
        else
            put_le32(pb, 1);
        put_le32(pb, 0); /* flags */
        put_le16(pb, 0); /* priority */
        put_le16(pb, 0); /* language */
        put_le32(pb, 0); /* initial frame */

        ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);

        put_le32(pb, au_scale); /* scale */
        put_le32(pb, au_byterate); /* rate */
        av_set_pts_info(s->streams[i], 64, au_scale, au_byterate);

        put_le32(pb, 0); /* start */
        avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */
        if (url_is_streamed(pb))
            put_le32(pb, AVI_MAX_RIFF_SIZE); /* FIXME: this may be broken, but who cares */
        else
            put_le32(pb, 0); /* length, XXX: filled later */

        /* suggested buffer size */ //FIXME set at the end to largest chunk
        if(stream->codec_type == CODEC_TYPE_VIDEO)
            put_le32(pb, 1024 * 1024);
        else if(stream->codec_type == CODEC_TYPE_AUDIO)
            put_le32(pb, 12 * 1024);
        else
            put_le32(pb, 0);
        put_le32(pb, -1); /* quality */
        put_le32(pb, au_ssize); /* sample size */
        put_le32(pb, 0);
        put_le16(pb, stream->width);
        put_le16(pb, stream->height);
        end_tag(pb, strh);

      if(stream->codec_type != CODEC_TYPE_DATA){
        strf = start_tag(pb, "strf");
        switch(stream->codec_type) {
        case CODEC_TYPE_VIDEO:
            put_bmp_header(pb, stream, codec_bmp_tags, 0);
            break;
        case CODEC_TYPE_AUDIO:
            if (put_wav_header(pb, stream) < 0) {
                av_free(avi);
                return -1;
            }
            break;
        default:
            return -1;
        }
        end_tag(pb, strf);
      }

        if (!url_is_streamed(pb)) {
            unsigned char tag[5];
            int j;

            /* Starting to lay out AVI OpenDML master index.
             * We want to make it JUNK entry for now, since we'd
             * like to get away without making AVI an OpenDML one
             * for compatibility reasons.
             */
            avi->indexes[i].entry = avi->indexes[i].ents_allocated = 0;
            avi->indexes[i].indx_start = start_tag(pb, "JUNK");
            put_le16(pb, 4);        /* wLongsPerEntry */
            put_byte(pb, 0);        /* bIndexSubType (0 == frame index) */
            put_byte(pb, 0);        /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */
            put_le32(pb, 0);        /* nEntriesInUse (will fill out later on) */
            put_tag(pb, avi_stream2fourcc(&tag[0], i, stream->codec_type));
                                    /* dwChunkId */
            put_le64(pb, 0);        /* dwReserved[3]
            put_le32(pb, 0);           Must be 0.    */
            for (j=0; j < AVI_MASTER_INDEX_SIZE * 2; j++)
                 put_le64(pb, 0);
            end_tag(pb, avi->indexes[i].indx_start);
        }

        end_tag(pb, list2);
    }

    if (!url_is_streamed(pb)) {
        /* AVI could become an OpenDML one, if it grows beyond 2Gb range */
        avi->odml_list = start_tag(pb, "JUNK");
        put_tag(pb, "odml");
        put_tag(pb, "dmlh");
        put_le32(pb, 248);
        for (i = 0; i < 248; i+= 4)
             put_le32(pb, 0);
        end_tag(pb, avi->odml_list);
    }

    end_tag(pb, list1);

    list2 = start_tag(pb, "LIST");
    put_tag(pb, "INFO");
    avi_write_info_tag(pb, "INAM", s->title);
    avi_write_info_tag(pb, "IART", s->author);
    avi_write_info_tag(pb, "ICOP", s->copyright);
    avi_write_info_tag(pb, "ICMT", s->comment);
    avi_write_info_tag(pb, "IPRD", s->album);
    avi_write_info_tag(pb, "IGNR", s->genre);
    if (s->track) {
        char str_track[4];
        snprintf(str_track, 4, "%d", s->track);
        avi_write_info_tag(pb, "IPRT", str_track);
    }
    if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
        avi_write_info_tag(pb, "ISFT", LIBAVFORMAT_IDENT);
    end_tag(pb, list2);

    /* some padding for easier tag editing */
    list2 = start_tag(pb, "JUNK");
    for (i = 0; i < 1016; i += 4)
        put_le32(pb, 0);
    end_tag(pb, list2);

    avi->movi_list = start_tag(pb, "LIST");
    put_tag(pb, "movi");

    put_flush_packet(pb);

    return 0;
}
示例#18
0
static int avi_write_idx1(AVFormatContext *s)
{
    ByteIOContext *pb = &s->pb;
    AVIContext *avi = s->priv_data;
    offset_t file_size, idx_chunk;
    int i, n, nb_frames, au_byterate, au_ssize, au_scale;
    AVCodecContext *stream;
    unsigned char tag[5];

    if (!url_is_streamed(pb)) {
	AVIIentry* ie = 0, *tie;
	int entry[MAX_STREAMS];
	int empty, stream_id = -1;

	idx_chunk = start_tag(pb, "idx1");
	memset(&entry[0], 0, sizeof(entry));
	do {
	    empty = 1;
	    for (i=0; i<s->nb_streams; i++) {
	         if (avi->indexes[i].entry <= entry[i])
		     continue;
		 
		 tie = avi_get_ientry(&avi->indexes[i], entry[i]);
		 if (empty || tie->pos < ie->pos) {
		     ie = tie; 
		     stream_id = i;
		 }
		 empty = 0;
	    }
	    if (!empty) {
	        avi_stream2fourcc(&tag[0], stream_id, 
		                  s->streams[stream_id]->codec.codec_type); 
	        put_tag(pb, &tag[0]);
		put_le32(pb, ie->flags);
                put_le32(pb, ie->pos);
                put_le32(pb, ie->len);
		entry[stream_id]++;
	    }
	} while (!empty);
	end_tag(pb, idx_chunk);

        /* Fill in frame/sample counters */
	file_size = url_ftell(pb);
        nb_frames = 0;
        for(n=0;n<s->nb_streams;n++) {
            if (avi->frames_hdr_strm[n] != 0) {
                stream = &s->streams[n]->codec;
                url_fseek(pb, avi->frames_hdr_strm[n], SEEK_SET);
                if (stream->codec_type == CODEC_TYPE_VIDEO) {
                    put_le32(pb, stream->frame_number); 
                    if (nb_frames < stream->frame_number)
                        nb_frames = stream->frame_number;
                } else {
                    if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3) {
                        put_le32(pb, stream->frame_number);
                        nb_frames += stream->frame_number;
                    } else {
                        parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);
                        put_le32(pb, avi->audio_strm_length[n] / au_ssize);
                    }
                }
            }
       }
       if (avi->frames_hdr_all != 0) {
           url_fseek(pb, avi->frames_hdr_all, SEEK_SET);
           put_le32(pb, nb_frames); 
       }
       url_fseek(pb, file_size, SEEK_SET);
    }
    return 0;
}
示例#19
0
文件: parse.c 项目: okey/431
void parse(FILE *stream) {
   char buffer[MAX_WORD_LEN];
   int c = 0, index = 0;

   while (EOF != (c = tolower(getc(stream)))) {
      switch (c) {
      case '<': /* Tags */
         /* End the current word */
         if (index) {
            buffer[index] = '\0';
            clean_word(buffer);
            word(buffer);
            index = 0;
         }
         /* Get the next character and decide what to do next */
         c = getc(stream); /* Case doesn't matter here */
         switch (c) {
         case '/': /* End tags */
            tag_section(buffer, stream);
            end_tag(buffer);
            break;
         default: /* Start tags */
            c = ungetc(c, stream);
            if (EOF != c) {
               tag_section(buffer, stream);
               start_tag(buffer);
            }
            break;
         }
         break;
      case '&': /* Entity references */
         entity_ref(stream);
         /*if (39 == entity_ref(stream)) ungetc(39, stream);*/
         break;
      default: /* Plain text */
         if (index == MAX_WORD_LEN) {
            fprintf(stderr, "Maximum word length exceeded!\n");
            exit(EXIT_FAILURE);
         }

         if (isalnum(c) || c == 39) {
            if (c != 39 || index) { /* no ' allowed at the start */
               buffer[index++] = c;
            }
         } else if (index) {
            buffer[index] = '\0';
            clean_word(buffer);
            word(buffer);
            index = 0;
         }
         break;
      }
   }

   if (!feof(stream)) {
      /* Stop due to an error! */
      perror("Parsing failure");
      exit(EXIT_FAILURE);
   }

}
示例#20
0
void do_ftag( CHAR_DATA *ch, char *argument )
{
    CHAR_DATA              *victim;
    ROOM_INDEX_DATA        *loc;
    char                    arg1[MAX_INPUT_LENGTH];
    char                    arg2[MAX_INPUT_LENGTH];
    char                    buf[MAX_STRING_LENGTH];

    if ( IS_NPC( ch ) )
        return;

    argument = one_argument( argument, arg1 );
    if ( !arg1 || arg1[0] == '\0' ) {
        send_to_char( "sintaxis: congelacion entrar\r\n", ch );
        send_to_char( "para comunicarte usa los canales rojo o azul.\r\n", ch );
        send_to_char( "para congelar o descongelar a alguien una vez haya empezado el evento usa el comando tocar.\r\n", ch );
        if ( IS_IMMORTAL( ch ) ) {
            send_to_char( "\r\nSintaxis: congelacion reset\r\n", ch );
            send_to_char( " congelacion next\r\n", ch );
            send_to_char( " congelacion start\r\n", ch );
            send_to_char( " congelacion rojo <player>\r\n", ch );
            send_to_char( " congelacion azul <player>\r\n", ch );
        }
        return;
    }

    if ( arena_prep || challenge || arena_underway ) {
        send_to_char( "Espera a que termine el evento actual de arena.\r\n", ch );
        return;
    }

    if ( !str_cmp( arg1, "entrar" ) ) {
        if ( tag_game.status != TAG_ISWAIT ) {
            send_to_char( "no hay ningún evento de congelación activo.\r\n", ch );
            return;
        }
        if ( xIS_SET( ch->act, PLR_PLAYING ) || xIS_SET( ch->act, PLR_WAITING ) ) {
            send_to_char( "ya estás jugando.\r\n", ch );
            return;
        }
        if ( !( loc = get_room_index( FTAG_WAIT_ROOM ) ) ) {
            send_to_char( "Espera a que termine el que ya hay empezado.\r\n", ch );
            return;
        }
        send_to_char( "Entras al evento de congelación.\r\n", ch );
        char_from_room( ch );
        char_to_room( ch, loc );
        tag_game.playing += 1;
        do_look( ch, ( char * ) "auto" );
        xSET_BIT( ch->act, PLR_WAITING );
        xREMOVE_BIT( ch->act, PLR_FROZEN );
        xSET_BIT( ch->act, PLR_PKSAFE );
        ch->quest_curr += 5;
        ch->quest_accum += 5;
        ch_printf( ch, "¡Ganas 5 puntos de gloria por participar en el evento!\r\n" );
        if ( ( fRed = !fRed ) ) {
            xSET_BIT( ch->act, PLR_RED );
            xREMOVE_BIT( ch->act, PLR_BLUE );
            send_to_char( "&W¡formas parte del equipo &RROJO&W!\r\n", ch );
            tag_channel( ch, "&R[&WEvento de congelación&R] &W¡$n forma parte del equipo &RROJO&W!" );
        }
        else {
            xSET_BIT( ch->act, PLR_BLUE );
            xREMOVE_BIT( ch->act, PLR_RED );
            send_to_char( "&W¡formas parte del equipo &CAZUL&W!\r\n", ch );
            tag_channel( ch, "&R[&WEvento de congelación&R] &W¡$n forma parte del equipo &CAZUL&W!" );
        }
        return;
    }

    if ( !str_cmp( arg1, "start" ) ) {
        if ( GET_MONEY( ch, CURR_SILVER ) < 10 ) {
            send_to_char
                ( "necesitas 10 monedas de plata para comenzar el evento.\r\n", ch );
            return;
        }
        if ( tag_game.status != TAG_OFF ) {
            send_to_char( "ya hay un juego en progreso.\r\n", ch );
            return;
        }
        GET_MONEY( ch, CURR_SILVER ) -= 10;

        tag_channel( NULL,
                     "&R[&WEvento&R] &C¡Ha comenzado un evento de congelación! ¡Teclea '&Wcongelacion entrar&C' para unirte!" );
        tag_game.status = TAG_ISWAIT;
        tag_game.timer = 3;
        tag_game.playing = 0;
        tag_game.next = -1;

        if ( !IS_IMMORTAL( ch ) ) {
            GET_MONEY( ch, CURR_SILVER ) -= 10;
            return;
        }
        return;
    }

    if ( !IS_IMMORTAL( ch ) ) {
        do_ftag( ch, ( char * ) "" );
        return;
    }

    if ( !str_cmp( arg1, "next" ) ) {
        tag_game.next = atoi( argument );
        ch_printf( ch, "El próximo juego comenzará en %d ticks.\r\n", tag_game.next );
        return;
    }

    if ( !str_cmp( arg1, "reset" ) ) {
        end_tag(  );
        send_to_char( "Jugadores reseteados.\r\n", ch );
        return;
    }

    argument = one_argument( argument, arg2 );
    if ( arg2[0] == '\0' || ( str_cmp( arg1, "rojo" ) && str_cmp( arg1, "azul" ) ) ) {
        send_to_char( "sintaxis: congelacion rojo  <player>\r\n", ch );
        send_to_char( "        Congelacion azul <player>\r\n", ch );
        return;
    }

    if ( tag_game.status == TAG_ISPLAY ) {
        send_to_char( "El juego ya ha comenzado.\r\n", ch );
        return;
    }

    if ( !( victim = get_char_world( ch, arg2 ) ) ) {
        send_to_char( "No está aquí.\r\n", ch );
        return;
    }

    if ( IS_NPC( victim ) ) {
        send_to_char( "No puede jugar.\r\n", ch );
        return;
    }

    if ( !( loc = get_room_index( FTAG_WAIT_ROOM ) ) ) {
        send_to_char( "El evento de congelación todavía no ha finalizado.\r\n", ch );
        return;
    }

    send_to_char( "Alguien te une al evento de congelación.\r\n", victim );
    char_from_room( victim );
    char_to_room( victim, loc );
    tag_game.playing += 1;
    do_look( victim, ( char * ) "auto" );

    xSET_BIT( victim->act, PLR_WAITING );
    xREMOVE_BIT( victim->act, PLR_FROZEN );
    xSET_BIT( victim->act, PLR_PKSAFE );

    if ( !str_cmp( arg1, "rojo" ) ) {
        xSET_BIT( victim->act, PLR_RED );
        xREMOVE_BIT( victim->act, PLR_BLUE );
        act( AT_WHITE, "¡Formas parte del equipo &RROJO&W!", ch, NULL, victim, TO_VICT );
        act( AT_WHITE, "¡$N forma parte del equipo &RROJO&W!", ch, NULL, victim, TO_NOTVICT );
        act( AT_WHITE, "¡$N forma parte del equipo &RROJO&W!", ch, NULL, victim, TO_CHAR );
    }
    else if ( !str_cmp( arg1, "blue" ) ) {
        xSET_BIT( victim->act, PLR_BLUE );
        xREMOVE_BIT( victim->act, PLR_RED );
        act( AT_WHITE, "¡Formas parte del equipo &Cazul&W!", ch, NULL, victim, TO_VICT );
        act( AT_WHITE, "¡$N forma parte del equipo &CAZUL&W!", ch, NULL, victim, TO_NOTVICT );
        act( AT_WHITE, "¡$N forma parte del equipo &CAZUL&W!", ch, NULL, victim, TO_CHAR );
    }
}
示例#21
0
static inline GUTF8String
end_tag(const int layer)
{
  return end_tag((const DjVuTXT::ZoneType)layer);
}
示例#22
0
/**
HTML 문서를 parsing 하면서 text로 변환.
*/
int htmlParse::parse(stToken *tok, char *text, int maxlen)
{
	int	tok_val=0, prev_tok_val=0, prev_ch=0;
	int	is_in_tag=0;
	uint4	tmp=0;
	int	not_moved=0;
	char *start=text;

	stTagProc *curr_tag=0;
	//stTagProc **prev_tag=0;
	stEntityProc *ent_proc;
	int	tag_depth=0;
	int	is_in_BODY_tag=0;
	int	is_in_A_tag=0;
	int	is_in_PRE_tag=0; // 2003.11.8
	int	hlink_chars = 0;
	//int	newline_delayed=0; // Optional Pair && Newline tag가 시작한 경우 TRUE
	//int	dont_newline=0; // TRUE means "dont write newline"
	int	pair_mark=0;
	int	words_in_line=0;
	int	b_tag_first_in_line=0; // 라인 첫머리에 B tag가 나온 경우 
	int	glossary_marked=0;
	int	is_glossary=0;

	tok->offset = 0;
	tok->line_num=1;
	*text = 0;

	maxlen -= 20;
	
	while(tok->offset <  tok->src_len && (int)((uint4)text-(uint4)start) < maxlen) {
	
		tmp = tok->offset;

		htmlLex::get_token_mem(tok);

		#ifdef BUG
		if (tok->tok_len>=20) {
			printf("long tok: line=%d, tok_val=%d, CH=%c\n",
			tok->line_num, tok->tok_val, tok->src_mem[tok->offset-1]);
			fflush(stdout);
			printf("tok=%s\n", tok->tok_str);
			fflush(stdout);
		}
		#endif
		
		#ifdef DEB
		/*
		if (tok->tok_val==0 || tok->line_num==1) {
			printf("line=%d, tok_val=%d, CH=%c\n",
			tok->line_num, tok->tok_val, tok->src_mem[tok->offset-1]);
			printf("offset=%d, text-start=%d\n", tok->offset, text-start);
		}
		*/
		#endif
		
		if (text > start) {
			prev_ch = *(text-1);
			if (prev_ch=='\n') {
				words_in_line = 0;
				b_tag_first_in_line = 0;
				glossary_marked = 0;
			}
		}
		
		if (tok->tok_val == TOK_EOF) break;

		if (tok->tok_val == URL_CMNT) {
			//printf("%s", tok->tok_str);
			continue;
		}
		
		if (tok->offset==tmp) {
			#ifdef BUG
			//printf("parse(): offset not moved: line=%d, CH=%d(%c)\n",
			//	tok->line_num, tok->src_mem[tok->offset-1], tok->src_mem[tok->offset-1]);
			#endif
			tok->offset++;
			if (++not_moved >= 2) break;
			else continue;
		}
		tok_val = tok->tok_val;

	
		if (tok_val == BTAG_BEGIN) {	
			skip_to_two_token(tok, STRING, TAG_END);
			if (tok->tok_val != STRING) { // must be a HTML tag
				skip_to_token(tok, TAG_END);
				continue;			
			}
			
			//prn_tabs();
			//fprintf(log,"%s-->:%d :%d\n", tok->tok_str, tok->line_num, tok->offset);
			
			curr_tag = htmlTagEntity::tag_idx(tok->tok_str);
			
			if (curr_tag == NULL) {
				skip_to_token(tok, TAG_END);
				continue;
			}

			tag_depth++;

			#ifdef MAIN_TEXT_ONLY
			if (curr_tag->pair != Not_PAIR && is_in_BODY_tag && curr_tag!=htmlTagEntity::A_tag)
			push_tag(curr_tag, tag_depth, (int)((uint4)text-(uint4)start));
			

			if (curr_tag==htmlTagEntity::BODY_tag) {
				is_in_BODY_tag = 1;
			}
			#endif
			
			if (curr_tag==htmlTagEntity::A_tag) {
				is_in_A_tag = 1;
			}
			else if (curr_tag==htmlTagEntity::PRE_tag) {
				is_in_PRE_tag = 1;
			}
			else if(curr_tag==htmlTagEntity::B_tag||curr_tag==htmlTagEntity::DT_tag) {
				if (words_in_line==0)
					b_tag_first_in_line = 1;
			}
			else if (curr_tag==htmlTagEntity::TITLE_tag) {							
				get_hyperlink_title(tok->src_mem + tok->offset  , htmlTitle, HTMLTITLE_LEN);
					
				#ifdef DEB
				PRN("tok->scr_mem=%X, offset=%d, title=%X\n", 
					tok->src_mem, tok->offset, htmlTitle);
				PRN("title: %s (%d)\n", htmlTitle, strlen(htmlTitle) );
				#endif
				
				is_glossary =  is_glossay_mode(htmlTitle);
		
			}						
			else if (curr_tag==htmlTagEntity::BR_tag) {
				*text++ = '\n';
			}
	
			if (curr_tag->proc == 0) { // 0
				if (curr_tag->pair != Not_PAIR)
					skip_ignore_part(tok, curr_tag);
				else
					skip_to_token(tok, TAG_END);
				if (curr_tag->newline) {
					if (prev_ch != '\n') *text++ = '\n';
				}				
				continue;
			}

			if (curr_tag==htmlTagEntity::TITLE_tag) {
				if (prev_ch != '\n') *text++ = '\n';
				*text++ = '[';
				*text++ = '[';
			}
			else if (curr_tag->proc == 1) {
			}
			else if (!pair_mark && curr_tag->proc == 2) {
				pair_mark = 2;
				*text++ = '<';
			}
			else if (!pair_mark && curr_tag->proc == 3) {
				pair_mark = 3;
				*text++ = '\'';
			}
			else if (!pair_mark && curr_tag->proc == 4) {
				pair_mark = 4;
				*text++ = '[';
			}
			else if (curr_tag->proc == 5) {
				if (prev_ch != '\n') *text++ = '\n';
				*text++ = '*';
				*text++ = ' ';
				words_in_line = 0;
			}
			else if (curr_tag->proc == 6) {
				if (prev_ch != '\n') *text++ = '\n';
				*text++ = '\n';
			}
			
				
			skip_to_token(tok, TAG_END);

			if (!pair_mark && prev_ch != ' ') *text++ = ' ';
			//if (!ISSPACE(*text)) *text++ = ' ';

		}// BTAG_BEGIN '<'
				
		else if (tok_val == ETAG_BEGIN) {
					
			skip_to_two_token(tok, STRING, TAG_END);
			if (tok->tok_val != STRING) { // must be a HTML tag
				skip_to_token(tok, TAG_END);
				continue;
			}
			
		
			curr_tag = htmlTagEntity::tag_idx(tok->tok_str);

			if (curr_tag == NULL) {
				skip_to_token(tok, TAG_END);
				continue;
			}

			#ifdef MAIN_TEXT_ONLY
			tag_depth--;

			if (curr_tag==htmlTagEntity::BODY_tag) {
				is_in_BODY_tag = 0;
			}
			
			if (curr_tag->pair != Not_PAIR && is_in_BODY_tag && curr_tag!=htmlTagEntity::A_tag)
			end_tag(curr_tag, (int)((uint4)text-(uint4)start));
			#endif
			
			if (curr_tag==htmlTagEntity::A_tag) {
				is_in_A_tag = 0;
				#ifdef MARK_A_LINK
				*text++ = '}';
				#endif
			}
			else if (curr_tag==htmlTagEntity::PRE_tag) {
				is_in_PRE_tag = 0;
			}
			else if(curr_tag==htmlTagEntity::DT_tag || 
				(curr_tag==htmlTagEntity::B_tag && (b_tag_first_in_line && is_glossary)))
			{
				if (glossary_marked==0) {
					*text++ = ' ';
					*text++ = ':';
					//*text++ = ' ';
					b_tag_first_in_line = 0;
					glossary_marked = 1;
				}
					
			}
			else if (curr_tag==htmlTagEntity::TITLE_tag) {
				*text++ = ']';
				*text++ = ']';
				*text++ = '\n';
			}
			else if (curr_tag->proc == 1) {
			}
			else if (pair_mark==2 && curr_tag->proc == 2) {
				pair_mark = 0;
				*text++ = '>';
			}
			else if (pair_mark==3 && curr_tag->proc == 3) {
				pair_mark = 0;
				*text++ = '\'';
			}
			else if (pair_mark==4 && curr_tag->proc == 4) {
				pair_mark = 0;
				*text++ = ']';
			}
			else if (curr_tag->proc == 5) {				
			}
			else if (curr_tag->proc == 6) {
				if (prev_ch != '\n') *text++ = '\n';
				*text++ = '\n';
			}

			if (curr_tag->newline) {
				*text++ = '\n';
			}			
		
	
			skip_to_token(tok, TAG_END);

		}// ETAG_BEGIN '</'
		
		else if (tok_val == STAG_END) {
			skip_to_token(tok, TAG_END);
			is_in_tag = 0;
			tag_depth--;
		}
		
		else if (tok_val == TAG_EXC) {			
			tmp = skip_to_token(tok, TAG_END);
			//fprintf(log,"<- > skipped %d\n", tmp);
		}
		
		else if (tok_val == CMNT_BEGIN) {
			//fprintf(log,"Cmnt -->: %d :%d\n", tok->line_num, tok->offset);
			htmlLex::skip_to_cmnt_end(tok);
			//fprintf(log,"Cmnt <--: %d :%d\n", tok->line_num, tok->offset);
		}		
		else if (tok_val == ENTITY_STR) {
			if (prev_ch !=' ') *text++ = ' '; //2002.12.2
			
			ent_proc = htmlTagEntity::entity_idx(tok->tok_str);

			if (ent_proc && ent_proc->conv[0]) {
				#ifdef BUG
				//prn_ent_proc(ent_proc);
				#endif
				strcpy(text, ent_proc->conv);
				text += strlen(ent_proc->conv);
			}
			else {
				//fprintf(log,"ignored entity = %s\n", tok->tok_str);
			}
		
		}
		else if (tok_val == ENTITY_NUM) {
			if (prev_ch !=' ') *text++ = ' '; //2002.12.2
			
			ent_proc = htmlTagEntity::entity_id_idx(tok->tok_realval);

			if (ent_proc && ent_proc->conv[0]) {
				#ifdef BUG
				//prn_ent_proc(ent_proc);
				#endif
				strcpy(text, ent_proc->conv);
				text += strlen(ent_proc->conv);
			}
			else {			
				if (tok->tok_realval < 0x80) {
				// 2005.7.19
					*text = (char)tok->tok_realval ;
					text++;
				}

			}

		}
		else {
			char *t = text;
			if (is_in_PRE_tag || tok->tok_len>1 || tok_val == STRING || tok_val == NUMBER) {
				//if (prev_tok_val == TAG_END && *text != ' ') *text++ = ' ';
				// 2003. 3.20
				//if (prev_tok_val == TAG_END && isalnum(prev_ch) ) 
				//	*text++ = ' ';
				words_in_line++;
				strcpy(text, tok->tok_str);
				text += tok->tok_len;
			}
			// 2002.10.16 한글은 space로 전환 
			else if (tok->tok_val == FR_STR) {
				if (do_prn_hangul) {
					if (prev_ch != ' ') *text++ = ' ';
					strcpy(text, tok->tok_str);
					text += tok->tok_len;
					words_in_line++;
				}
				else {
					if (prev_ch != ' ') *text++ = ' ';
				}
			}
			else if (tok->tok_len==1) {		
				
				if (curr_tag==htmlTagEntity::PRE_tag) {					
					#ifdef ODD_CHAR
					if ( (tok_val & 0xF0) != 0x90)
						*text++ = tok_val;
					else if (tok_val==0x92) {
						if (prev_tok_val != 0x92)
							*text++ = '\'';
					}
					#else
					*text++ = tok_val;
					#endif
				}
				//else if (tok_val == '\n' || tok_val == '\r') {
				else if (ISSPACE(tok_val)) {
					if (prev_ch != ' ') *text++ = ' ';
				}
								
				else {
					if (prev_ch==':' && tok_val==':') { }
					else *text++ = tok_val;
				}
				
			}
			if (is_in_A_tag)
				hlink_chars += (int)(text - t);
		}

		prev_tok_val = tok->tok_val;
		
	}// while(1)

	*text = 0;

	if ((int)(text-start) >= maxlen-5) {
		PRN("parse(): too far !! maxlen=%d, %d\n", maxlen, text-start);
	}
	if ((int)(text-start) < maxlen-5)
		memset(text, 0, 4);
	#ifdef DEB
		PRN("text=%X, start=%X, text=%d, start=%d\n", 
			text, start, (int)text % 10000, (int)start % 10000);
		PRN("start[0]=%d text[0]=%d\n", start[0], text[0]);
	#endif

	return ((int)text-(int)start);
}