Exemplo n.º 1
0
static void open_tag(int level, const char *tag)
{
	if(current_tag>level)
	{
		close_tag(level);
		printf(",\n");
	}
	if(current_tag==level)
	{
		printf("\n");
		print_spaces(current_tag);
		printf("},\n");
		print_spaces(current_tag);
		printf("{\n");
	}
	for(; current_tag<level; current_tag++)
	{
		if(tag)
		{
			print_spaces(current_tag+1);
			printf("\"%s\":\n", tag);
		}
		print_spaces(current_tag+1);
		printf("%c\n", current_tag%2?'{':'[');
	}
}
Exemplo n.º 2
0
 void style(boost::filesystem::path filepath)
 {
     open_tag("style");
     insert_text(filesystem::read_file(filepath));
     next_line();
     close_tag("style");
 }
Exemplo n.º 3
0
 string tag(const string &tag, const string &cls, const string &body, int id = -1) {
     std::stringstream s;
     s << open_tag(tag, cls, id);
     s << body;
     s << close_tag(tag);
     return s.str();
 }
Exemplo n.º 4
0
 void js_inline(boost::filesystem::path filepath)
 {
     ensure(html_locations::in_head,"Cannot link to script out of head!");
     open_tag("script");
     insert_text(filesystem::read_file(filepath));
     next_line();
     close_tag("script");
 }
Exemplo n.º 5
0
/*
 * ----------------------------------------------------------------------
 * print_audit_common() - common routine for print_audit* functions.
 *
 *		   Parses the binary audit data, and formats as requested.
 *		   The context parameter defines whether the source of the
 *		   audit data is a buffer, or a file mapped to stdin, and
 *		   whether the output is to a buffer or a file mapped to
 *		   stdout.
 *
 *	inputs:
 *		   context -	defines the context of the request, including
 *				info about the source and output.
 *		   flags -	formatting flags as defined in praudit.h
 *		   separator -	field delimiter (or NULL if the default
 *				delimiter of comma is to be used).
 *
 * return codes:   -1 - error
 *		    0 - successful
 * ----------------------------------------------------------------------
 */
static int
print_audit_common(pr_context_t *context, const int flags,
    const char *separator)
{
	int	retstat = 0;

	if (!initdone) {
		init_tokens();
		initdone++;
	}

	context->format = flags;

	/* start with default delimiter of comma */
	(void) strlcpy(context->SEPARATOR, ",", SEP_SIZE);
	if (separator != NULL) {
		if (strlen(separator) < SEP_SIZE) {
			(void) strlcpy(context->SEPARATOR, separator, SEP_SIZE);
		}
	}

	while ((retstat == 0) && pr_input_remaining(context, 1)) {
		if (pr_adr_char(context, (char *)&(context->tokenid), 1) == 0) {
			retstat = token_processing(context);
		} else
			break;
	}

	/*
	 * For buffer processing, if the entire input buffer was processed
	 * successfully, but the last record in the buffer was incomplete
	 * (according to the length from its header), then reflect an
	 * "incomplete input" error (which will cause partial results to be
	 * returned).
	 */
	if ((context->data_mode == BUFMODE) && (retstat == 0) &&
	    (context->audit_adr->adr_now < (context->audit_rec_start +
	    context->audit_rec_len))) {
		retstat = -1;
		errno = EIO;
	}

	/*
	 * If there was a last record that didn't get officially closed
	 * off, do it now.
	 */
	if ((retstat == 0) && (context->format & PRF_XMLM) &&
	    (context->current_rec)) {
		retstat = do_newline(context, 1);
		if (retstat == 0)
			retstat = close_tag(context, context->current_rec);
	}

	return (retstat);
}
Exemplo n.º 6
0
/*
 * -----------------------------------------------------------------------
 * token_processing:
 *		  Calls the routine corresponding to the token id
 *		  passed in the parameter from the token table, tokentable
 * return codes : -1 - error
 *		:  0 - successful
 * -----------------------------------------------------------------------
 */
static int
token_processing(pr_context_t *context)
{
	uval_t	uval;
	int	retstat;
	int	tokenid = context->tokenid;

	if ((tokenid > 0) && (tokenid <= MAXTOKEN) &&
	    (tokentable[tokenid].func != NOFUNC)) {
		/*
		 * First check if there's a previous record that needs to be
		 * closed off now; then checkpoint our progress as needed.
		 */
		if ((retstat = check_close_rec(context, tokenid)) != 0)
			return (retstat);
		checkpoint_progress(context);

		/* print token name */
		if (context->format & PRF_XMLM) {
			retstat = open_tag(context, tokenid);
		} else {
			if (!(context->format & PRF_RAWM) &&
			    (tokentable[tokenid].t_name != (char *)0)) {
				uval.uvaltype = PRA_STRING;
				uval.string_val =
				    gettext(tokentable[tokenid].t_name);
			} else {
				uval.uvaltype = PRA_BYTE;
				uval.char_val = tokenid;
			}
			retstat = pa_print(context, &uval, 0);
		}
		if (retstat == 0)
			retstat = (*tokentable[tokenid].func)(context);

		/*
		 * For XML, close the token tag. Header tokens wrap the
		 * entire record, so they only get closed later implicitly;
		 * here, just make sure the header open tag gets finished.
		 */
		if ((retstat == 0) && (context->format & PRF_XMLM)) {
			if (!is_header_token(tokenid))
				retstat = close_tag(context, tokenid);
			else
				retstat = finish_open_tag(context);
		}
		return (retstat);
	}
	/* here if token id is not in table */
	(void) fprintf(stderr, gettext("praudit: No code associated with "
	    "token id %d\n"), tokenid);
	return (0);
}
Exemplo n.º 7
0
bool TextParser::Tag::operator == (const Tag &t) const
{
    return close_tag() == t.close_tag();
}
Exemplo n.º 8
0
int do_list_client(struct asfd *asfd,
	struct conf *conf, enum action act, int json)
{
	int ret=-1;
	char msg[512]="";
	char *dpth=NULL;
	struct sbuf *sb=NULL;
	int json_started=0;
	struct iobuf *rbuf=asfd->rbuf;
//logp("in do_list\n");

	if(conf->browsedir)
	  snprintf(msg, sizeof(msg), "listb %s:%s",
		conf->backup?conf->backup:"", conf->browsedir);
	else
	  snprintf(msg, sizeof(msg), "list %s:%s",
		conf->backup?conf->backup:"", conf->regex?conf->regex:"");
	if(asfd->write_str(asfd, CMD_GEN, msg)
	  || asfd->read_expect(asfd, CMD_GEN, "ok"))
		goto end;

	if(!(sb=sbuf_alloc(conf))) goto end;
	iobuf_init(&sb->path);
	iobuf_init(&sb->link);
	iobuf_init(&sb->attr);

	if(json)
	{
		open_tag(0, NULL);
		open_tag(1, "backups");
		json_started++;
	}

	// This should probably should use the sbuf stuff.
	while(1)
	{
		sbuf_free_content(sb);

		iobuf_free_content(rbuf);
		if(asfd->read(asfd)) break;
		if(rbuf->cmd==CMD_TIMESTAMP)
		{
			// A backup timestamp, just print it.
			if(json) json_backup(rbuf->buf, conf);
			else
			{
				printf("Backup: %s\n", rbuf->buf);
				if(conf->browsedir)
					printf("Listing directory: %s\n",
					       conf->browsedir);
				if(conf->regex)
					printf("With regex: %s\n",
					       conf->regex);
			}
			continue;
		}
		else if(rbuf->cmd!=CMD_ATTRIBS)
		{
			iobuf_log_unexpected(rbuf, __func__);
			goto end;
		}
		iobuf_copy(&sb->attr, rbuf);
		iobuf_init(rbuf);

		attribs_decode(sb);

		if(asfd->read(asfd))
		{
			logp("got stat without an object\n");
			goto end;
		}
		iobuf_copy(&sb->path, rbuf);
		iobuf_init(rbuf);

		if(sb->path.cmd==CMD_DIRECTORY
			|| sb->path.cmd==CMD_FILE
			|| sb->path.cmd==CMD_ENC_FILE
			|| sb->path.cmd==CMD_EFS_FILE
			|| sb->path.cmd==CMD_SPECIAL)
		{
			list_item(json, act, sb);
		}
		else if(cmd_is_link(sb->path.cmd)) // symlink or hardlink
		{
			if(asfd->read(asfd)
			  || rbuf->cmd!=sb->path.cmd)
			{
				logp("could not get link %c:%s\n",
					sb->path.cmd, sb->path.buf);
				goto end;
			}
			iobuf_copy(&sb->link, rbuf);
			iobuf_init(rbuf);
			list_item(json, act, sb);
		}
		else
		{
			fprintf(stderr, "unlistable %c:%s\n",
				sb->path.cmd, sb->path.buf?sb->path.buf:"");
		}
	}

	ret=0;
end:
	if(json && json_started) close_tag(0);
	printf("\n");
	iobuf_free_content(&sb->path);
	iobuf_free_content(&sb->link);
	iobuf_free_content(&sb->attr);
	if(dpth) free(dpth);
	sbuf_free(&sb);
	if(!ret) logp("List finished ok\n");
	return ret;
}
Exemplo n.º 9
0
 string close_div() {
     return close_tag("div") + "\n";
 }
Exemplo n.º 10
0
 string close_span() {
     return close_tag("span");
 }
Exemplo n.º 11
0
/*
 * Parse succesive blocks of XML data, generating events for the 
 * handlers/callbacks as we go. State is maintained in the 
 * simple_xml_parser object.
 * If the top level XML document ends before the last character, 
 * the "read" parameter indicates how much input was consumed.
 */
hcerr_t xml_parse(xml_parser *formal_parser, char s[], hc_long_t size, hc_long_t *read){
  simple_xml_parser *parser = (simple_xml_parser *)  formal_parser;

  int i = 0;

  if (DEBUG == TRUE){
    print_state(parser->state, parser->depth);
    printf ("in parser with " LL_FORMAT " %s\n", size, s);
    fflush(stdout);
  }

  while (i < size){

    switch(parser->state){

    case OUTSIDE_ELEMENT:
      if (is_white_space(s[i])){
	/*skip_white_space */
	break;
      }
      if (s[i] == '<'){
	parser->start_tag = TRUE;
	change_state(&parser->state, EXPECTING_OPEN_OR_CLOSE_TAG, parser->depth);
      }
      else {
	HC_ERR_LOG(("Expected '<', read %c at %d %s\n", s[i], i, s));
	return HCERR_XML_EXPECTED_LT;
      }
      break;
      
      
    case DOCUMENT_ELEMENT:
      /* discard document element */
      if (s[i] != '>'){
	if (DEBUG == TRUE)
	  printf("discarding %c", s[i]);
	break;
      }
      else{
	parser->state = OUTSIDE_ELEMENT;
	break;
      }

    case EXPECTING_OPEN_OR_CLOSE_TAG:
      if (is_white_space(s[i])){
	/*skip_white_space */
	break;
      }
      if (s[i] == '/'){
	if (DEBUG)
	  printf("parser->start_tag = FALSE\n");
	parser->start_tag = FALSE;
	break;
      }

    case EXPECTING_TAG:
      
      if (is_name_first_char(s[i]) == TRUE){
	change_state(&parser->state, SCANNING_TAG, parser->depth);
	require_ok(token_append(&parser->buffer_list, s[i]));
	break;
      }

      /* Discard document element */
      else if (s[i] == '?' && parser->depth == 0){
	parser->state = DOCUMENT_ELEMENT;
	break;
      }
      else{
	HC_ERR_LOG(("Invalid first character for element name : %c %d %s\n", s[i], i, s));
	return HCERR_XML_INVALID_ELEMENT_TAG;
      }
      
      // FALLTHRU INTENTIONAL???

      /* Start tag is terminated by whitespace, /, or >
	 End tag is terminated by whitespace or >
      */
    case SCANNING_TAG:
      /* Still reading token */
      if (is_name_char(s[i]) == TRUE){
	require_ok(token_append(&parser->buffer_list, s[i]));
	break;
      }
      else if (is_white_space(s[i]) == TRUE) {
	parser->current_tag = token_finish(&parser->buffer_list);
	if (parser->start_tag == TRUE){
	  /*printf("Start element: %s\n", parser->current_tag);*/
	  change_state(&parser->state, SCANNING_ATTRIBUTES, parser->depth);
	  break;
	}
	else{
	  change_state(&parser->state, SCANNING_CLOSE_TAG, parser->depth);
	  break;
	}
      }
      else if (s[i] == '>') {
	if (DEBUG == TRUE)
	  printf("parser->depth: %d\n", parser->depth);
	require_ok(close_tag(&i, parser));
	if (DEBUG == TRUE)
	  printf("parser->depth: %d\n", parser->depth);
	if (parser->depth == 0){
	  *read = i + 1;
	  return HCERR_OK;
	}
      }
      /* <element/> */
      else if (s[i] == '/' && parser->start_tag == TRUE) {
	if (DEBUG == TRUE){
	  printf("Start element: %s\n", parser->current_tag);	
	  printf("End element: %s\n", parser->current_tag);
	}
	change_state(&parser->state, EXPECTING_RIGHT_BRACKET, parser->depth);
	break;
      }
      else {
	HC_ERR_LOG(("Invalid character '%c' in tag. %i %s\n", s[i], i, s));
	return HCERR_XML_INVALID_ELEMENT_TAG;
      }
      break;

    case EXPECTING_RIGHT_BRACKET:
      if (s[i] != '>') {
	HC_ERR_LOG(("Unexpected character %c after close element. %d %s", s[i], i, s));
	return HCERR_XML_MALFORMED_START_ELEMENT;
      }
      if (parser->depth == 0){
	*read = i + 1;
	return HCERR_OK;
      }
      change_state(&parser->state, OUTSIDE_ELEMENT, parser->depth);
      break;


    case SCANNING_CLOSE_TAG:
	  if (is_white_space(s[i])) {
	    break;
	  }
	  if (DEBUG == TRUE)
	    fprintf(stdout, "End element: %s\n", parser->current_tag);
	  if (s[i] != '>') {
	    HC_ERR_LOG(("Unexpected character %c after close element. %d %s", s[i], i, s));
	    return HCERR_XML_MALFORMED_END_ELEMENT;
	  }
	  require_ok((*parser->end_element_callback)(parser->current_tag, parser->data));
	  parser->depth--;
	  if (parser->depth == 0){
	    *read = i + 1;
	    return HCERR_OK;
	  }

	  change_state(&parser->state, OUTSIDE_ELEMENT, parser->depth);
	  break;


      /* Expected tokens:
       *   attribute_name
       *   '/'
       *   >
       */
    case SCANNING_ATTRIBUTES:
      if (is_white_space(s[i])){
	/*skip_white_space */
	break;
      }
      if (is_name_first_char(s[i]) == TRUE) {
	change_state(&parser->state, SCANNING_ATTRIBUTE_NAME, parser->depth);
	require_ok(token_append(&parser->buffer_list, s[i]));
      }
      else if (s[i] == '/' && parser->start_tag == TRUE) {

	if (DEBUG == TRUE){
	  int j = 0;
	  printf("SA Start element: %s\n", parser->current_tag);		 
	  fprintf(stdout, "Start  element: %s %d\n", parser->current_tag, parser->current_attribute);
	  for (j = 0; j < parser->current_attribute; j++){
	    printf(" %s=\"%s\"", *(parser->attribute_names + j), *(parser->attribute_values + j));
	  }
	  fprintf(stdout, "End  element: %s\n", parser->current_tag);
	  fflush(stdout);
	} 
	require_ok((*parser->start_element_callback)(parser->current_tag, 
						     parser->data, 
						     parser->attribute_names,
						     parser->attribute_values,
						     parser->current_attribute));
	require_ok((*parser->end_element_callback)(parser->current_tag, parser->data));

	parser->current_attribute = 0;
	change_state(&parser->state, EXPECTING_RIGHT_BRACKET, parser->depth);
      }
      else  if (s[i] == '>') { 
	if (DEBUG == TRUE){
	  int j = 0;
	  fprintf(stdout, "Start  element event: %s %d\n", parser->current_tag, parser->current_attribute);
	  for (j = 0; j < parser->current_attribute; j++){
	    printf(" %s=\"%s\"", *(parser->attribute_names + j), *(parser->attribute_values + j));
	  }
	}
	require_ok((*parser->start_element_callback)(parser->current_tag, 
						     parser->data,
						     parser->attribute_names,
						     parser->attribute_values,
						     parser->current_attribute));

	parser->current_attribute = 0;
	parser->depth++;
	change_state(&parser->state, OUTSIDE_ELEMENT, parser->depth);
      }
      else{
	HC_ERR_LOG(("Unexpected character %c after close element. %d %s", s[i], i, s));
	return HCERR_XML_MALFORMED_START_ELEMENT;
      }
      break;

    case SCANNING_ATTRIBUTE_NAME:
      if (s[i] == '='){
	if (parser->current_attribute == parser->attribute_arrays_size){
	  require_ok(grow_attribute_arrays(parser));
	}
	parser->attribute_names[parser->current_attribute] = token_finish(&parser->buffer_list);

	change_state(&parser->state, SCANNING_START_ATTRIBUTE_VALUE, parser->depth);
      }
      else if (is_name_char(s[i]) == TRUE) {
	require_ok(token_append(&parser->buffer_list, s[i]));
      }
      else{
	HC_ERR_LOG(("Illegal char %c in attribute name. %i <<%s>>\n", s[i], i, s));
	return HCERR_XML_BAD_ATTRIBUTE_NAME;
      }
      break;

    case SCANNING_START_ATTRIBUTE_VALUE:
      if (is_white_space(s[i])){
	break;
      }
      else if (s[i] != '"'){
	HC_ERR_LOG(("Attribute value does not begin with quote: '%c'. %i %s\n", s[i], i, s));
	return HCERR_XML_BAD_ATTRIBUTE_NAME;
      }
      change_state(&parser->state, SCANNING_ATTRIBUTE_VALUE, parser->depth);
      break;


    case SCANNING_ATTRIBUTE_VALUE:
      if (s[i] == '\\') {
	if (parser->backslash == TRUE){
	  parser->backslash = FALSE;
	}
	else{
	  parser->backslash = TRUE;
	}
      }
      else if (s[i] == '"' && parser->backslash == FALSE) {
	parser->attribute_values[parser->current_attribute++] = token_finish(&parser->buffer_list);
	change_state(&parser->state, SCANNING_ATTRIBUTES, parser->depth);
      	break;
      }
      require_ok(token_append(&parser->buffer_list, s[i]));
      
      break;
    }
    i++;
  }
  return HCERR_OK;
}
Exemplo n.º 12
0
static void
do_new_spitfile(dbref player, char *arg1, help_file *help_dat)
{
  help_indx *entry = NULL;
  FILE *fp;
  char *p, line[LINE_SIZE + 1];
  char the_topic[LINE_SIZE + 2];
  int default_topic = 0;
  size_t n;

  if (*arg1 == '\0') {
    default_topic = 1;
    arg1 = (char *) help_dat->command;
  } else if (*arg1 == '&') {
    notify(player, T("Help topics don't start with '&'."));
    return;
  }
  if (strlen(arg1) > LINE_SIZE)
    *(arg1 + LINE_SIZE) = '\0';

  if (help_dat->admin) {
    sprintf(the_topic, "&%s", arg1);
  } else
    strcpy(the_topic, arg1);

  if (!help_dat->indx || help_dat->entries == 0) {
    notify(player, T("Sorry, that command is temporarily unvailable."));
    do_rawlog(LT_ERR, "No index for %s.", help_dat->command);
    return;
  }

  entry = help_find_entry(help_dat, the_topic);
  if (!entry && default_topic)
    entry = help_find_entry(help_dat, (help_dat->admin ? "&help" : "help"));

  if (!entry) {
    notify_format(player, T("No entry for '%s'."), arg1);
    return;
  }

  if ((fp = fopen(help_dat->file, FOPEN_READ)) == NULL) {
    notify(player, T("Sorry, that function is temporarily unavailable."));
    do_log(LT_ERR, 0, 0, "Can't open text file %s for reading", help_dat->file);
    return;
  }
  if (fseek(fp, entry->pos, 0) < 0L) {
    notify(player, T("Sorry, that function is temporarily unavailable."));
    do_rawlog(LT_ERR, "Seek error in file %s", help_dat->file);
    return;
  }
  strcpy(the_topic, strupper(entry->topic + (*entry->topic == '&')));
  /* ANSI topics */
  notify_format(player, "%s%s%s", ANSI_HILITE, the_topic, ANSI_END);

  if (SUPPORT_PUEBLO)
    notify_noenter(player, open_tag("SAMP"));
  for (n = 0; n < BUFFER_LEN; n++) {
    if (fgets(line, LINE_SIZE, fp) == NULL)
      break;
    if (line[0] == '&')
      break;
    if (line[0] == '\n') {
      notify(player, " ");
    } else {
      for (p = line; *p != '\0'; p++)
        if (*p == '\n')
          *p = '\0';
      notify(player, line);
    }
  }
  if (SUPPORT_PUEBLO)
    notify(player, close_tag("SAMP"));
  fclose(fp);
  if (n >= BUFFER_LEN)
    notify_format(player, T("%s output truncated."), help_dat->command);
}
Exemplo n.º 13
0
guint8 *
gimp_text_buffer_serialize (GtkTextBuffer     *register_buffer,
                            GtkTextBuffer     *content_buffer,
                            const GtkTextIter *start,
                            const GtkTextIter *end,
                            gsize             *length,
                            gpointer           user_data)
{
  GString     *string;
  GtkTextIter  iter, old_iter;
  GSList      *tag_list;
  GSList      *active_tags;

  string = g_string_new ("<markup>");

  iter        = *start;
  tag_list    = NULL;
  active_tags = NULL;

  do
    {
      GSList *tmp;
      gchar *tmp_text, *escaped_text;

      active_tags = NULL;
      tag_list = gtk_text_iter_get_tags (&iter);

      /* Handle added tags */
      for (tmp = tag_list; tmp; tmp = tmp->next)
        {
          GtkTextTag *tag = tmp->data;

          open_tag (GIMP_TEXT_BUFFER (register_buffer), string, tag);

          active_tags = g_slist_prepend (active_tags, tag);
        }

      g_slist_free (tag_list);
      old_iter = iter;

      /* Now try to go to either the next tag toggle, or if a pixbuf appears */
      while (TRUE)
        {
          gunichar ch = gtk_text_iter_get_char (&iter);

          if (ch == 0xFFFC)
            {
              /* pixbuf? can't happen! */
            }
          else if (ch == 0)
            {
              break;
            }
          else
            {
              gtk_text_iter_forward_char (&iter);
            }

          if (gtk_text_iter_toggles_tag (&iter, NULL))
            break;
        }

      /* We might have moved too far */
      if (gtk_text_iter_compare (&iter, end) > 0)
        iter = *end;

      /* Append the text */
      tmp_text = gtk_text_iter_get_slice (&old_iter, &iter);
      escaped_text = g_markup_escape_text (tmp_text, -1);
      g_free (tmp_text);

      g_string_append (string, escaped_text);
      g_free (escaped_text);

      /* Close any open tags */
      for (tmp = active_tags; tmp; tmp = tmp->next)
        close_tag (GIMP_TEXT_BUFFER (register_buffer), string, tmp->data);

      g_slist_free (active_tags);
    }
  while (! gtk_text_iter_equal (&iter, end));

  g_string_append (string, "</markup>");

  *length = string->len;

  return (guint8 *) g_string_free (string, FALSE);
}
Exemplo n.º 14
0
unsigned get_decoder_line_encoded(unsigned char *buffer, int line_num, struct eia608_screen *data)
{
	int col = COL_WHITE;
	int underlined = 0;
	int italics = 0;
	int changed_font = 0;
	char tagstack[128] = ""; // Keep track of opening/closing tags

	unsigned char *line = data->characters[line_num];
	unsigned char *orig = buffer; // Keep for debugging
	int first = 0, last = 31;
	if (ccx_encoders_helpers_settings.trim_subs)
		find_limit_characters(line, &first, &last);
	for (int i = first; i <= last; i++)
	{
		// Handle color
		int its_col = data->colors[line_num][i];
		if (its_col != col  && !ccx_encoders_helpers_settings.no_font_color &&
			!(col == COL_USERDEFINED && its_col == COL_WHITE)) // Don't replace user defined with white
		{
			if (changed_font)
				buffer = close_tag(buffer, tagstack, 'F', &underlined, &italics, &changed_font);
			// Add new font tag
			buffer += encode_line(buffer, (unsigned char*)color_text[its_col][1]);
			if (its_col == COL_USERDEFINED)
			{
				// The previous sentence doesn't copy the whole
				// <font> tag, just up to the quote before the color
				buffer += encode_line(buffer, (unsigned char*)usercolor_rgb);
				buffer += encode_line(buffer, (unsigned char*) "\">");
			}
			if (color_text[its_col][1][0]) // That means a <font> was added to the buffer
			{
				strcat(tagstack, "F");
				changed_font++;
			}
			col = its_col;
		}
		// Handle underlined
		int is_underlined = data->fonts[line_num][i] & FONT_UNDERLINED;
		if (is_underlined && underlined == 0 && !ccx_encoders_helpers_settings.no_type_setting) // Open underline
		{
			buffer += encode_line(buffer, (unsigned char *) "<u>");
			strcat(tagstack, "U");
			underlined++;
		}
		if (is_underlined == 0 && underlined && !ccx_encoders_helpers_settings.no_type_setting) // Close underline
		{
			buffer = close_tag(buffer, tagstack, 'U', &underlined, &italics, &changed_font);
		}
		// Handle italics
		int has_ita = data->fonts[line_num][i] & FONT_ITALICS;
		if (has_ita && italics == 0 && !ccx_encoders_helpers_settings.no_type_setting) // Open italics
		{
			buffer += encode_line(buffer, (unsigned char *) "<i>");
			strcat(tagstack, "I");
			italics++;
		}
		if (has_ita == 0 && italics && !ccx_encoders_helpers_settings.no_type_setting) // Close italics
		{
			buffer = close_tag(buffer, tagstack, 'I', &underlined, &italics, &changed_font);
		}
		int bytes = 0;
		switch (ccx_encoders_helpers_settings.encoding)
		{
		case CCX_ENC_UTF_8:
			bytes = get_char_in_utf_8(buffer, line[i]);
			break;
		case CCX_ENC_LATIN_1:
			get_char_in_latin_1(buffer, line[i]);
			bytes = 1;
			break;
		case CCX_ENC_UNICODE:
			get_char_in_unicode(buffer, line[i]);
			bytes = 2;
			break;
		}
		buffer += bytes;
	}
	buffer = close_tag(buffer, tagstack, 'A', &underlined, &italics, &changed_font);
	if (underlined || italics || changed_font)
		ccx_common_logging.fatal_ftn(CCX_COMMON_EXIT_BUG_BUG, "Not all tags closed in encoding, this is a bug, please report.\n");
	*buffer = 0;
	return (unsigned)(buffer - orig); // Return length
}
Exemplo n.º 15
0
Error ResourceInteractiveLoaderText::rename_dependencies(FileAccess *p_f, const String &p_path,const Map<String,String>& p_map) {




#if 0
	open(p_f);
	ERR_FAIL_COND_V(error!=OK,error);

	//FileAccess

	bool old_format=false;

	FileAccess *fw = NULL;

	String base_path=local_path.get_base_dir();

	while(true) {
		bool exit;
		List<String> order;

		Tag *tag = parse_tag(&exit,true,&order);

		bool done=false;

		if (!tag) {
			if (fw) {
				memdelete(fw);
			}
			error=ERR_FILE_CORRUPT;
			ERR_FAIL_COND_V(!exit,error);
			error=ERR_FILE_EOF;

			return error;
		}

		if (tag->name=="ext_resource") {

			if (!tag->args.has("index") || !tag->args.has("path") || !tag->args.has("type")) {
				old_format=true;
				break;
			}

			if (!fw) {

				fw=FileAccess::open(p_path+".depren",FileAccess::WRITE);
				fw->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); //no escape
				fw->store_line("<resource_file type=\""+resource_type+"\" subresource_count=\""+itos(resources_total)+"\" version=\""+itos(VERSION_MAJOR)+"."+itos(VERSION_MINOR)+"\" version_name=\""+VERSION_FULL_NAME+"\">");

			}

			String path = tag->args["path"];
			String index = tag->args["index"];
			String type = tag->args["type"];


			bool relative=false;
			if (!path.begins_with("res://")) {
				path=base_path.plus_file(path).simplify_path();
				relative=true;
			}


			if (p_map.has(path)) {
				String np=p_map[path];
				path=np;
			}

			if (relative) {
				//restore relative
				path=base_path.path_to_file(path);
			}

			tag->args["path"]=path;
			tag->args["index"]=index;
			tag->args["type"]=type;

		} else {

			done=true;
		}

		String tagt="\t<";
		if (exit)
			tagt+="/";
		tagt+=tag->name;

		for(List<String>::Element *E=order.front();E;E=E->next()) {
			tagt+=" "+E->get()+"=\""+tag->args[E->get()]+"\"";
		}
		tagt+=">";
		fw->store_line(tagt);
		if (done)
			break;
		close_tag("ext_resource");
		fw->store_line("\t</ext_resource>");

	}


	if (old_format) {
		if (fw)
			memdelete(fw);

		DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
		da->remove(p_path+".depren");
		memdelete(da);
		//f**k it, use the old approach;

		WARN_PRINT(("This file is old, so it can't refactor dependencies, opening and resaving: "+p_path).utf8().get_data());

		Error err;
		FileAccess *f2 = FileAccess::open(p_path,FileAccess::READ,&err);
		if (err!=OK) {
			ERR_FAIL_COND_V(err!=OK,ERR_FILE_CANT_OPEN);
		}

		Ref<ResourceInteractiveLoaderText> ria = memnew( ResourceInteractiveLoaderText );
		ria->local_path=Globals::get_singleton()->localize_path(p_path);
		ria->res_path=ria->local_path;
		ria->remaps=p_map;
	//	ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
		ria->open(f2);

		err = ria->poll();

		while(err==OK) {
			err=ria->poll();
		}

		ERR_FAIL_COND_V(err!=ERR_FILE_EOF,ERR_FILE_CORRUPT);
		RES res = ria->get_resource();
		ERR_FAIL_COND_V(!res.is_valid(),ERR_FILE_CORRUPT);

		return ResourceFormatSaverText::singleton->save(p_path,res);
	}

	if (!fw) {

		return OK; //nothing to rename, do nothing
	}

	uint8_t c=f->get_8();
	while(!f->eof_reached()) {
		fw->store_8(c);
		c=f->get_8();
	}

	bool all_ok = fw->get_error()==OK;

	memdelete(fw);

	if (!all_ok) {
		return ERR_CANT_CREATE;
	}

	DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
	da->remove(p_path);
	da->rename(p_path+".depren",p_path);
	memdelete(da);
#endif
	return OK;

}
Exemplo n.º 16
0
guint8 *
gimp_text_buffer_serialize (GtkTextBuffer     *register_buffer,
                            GtkTextBuffer     *content_buffer,
                            const GtkTextIter *start,
                            const GtkTextIter *end,
                            gsize             *length,
                            gpointer           user_data)
{
  GString     *string;
  GtkTextIter  iter, old_iter;
  GSList      *tag_list, *new_tag_list;
  GSList      *active_tags;

  string = g_string_new ("<markup>");

  iter        = *start;
  tag_list    = NULL;
  active_tags = NULL;

  do
    {
      GList *added, *removed;
      GList *tmp;
      gchar *tmp_text, *escaped_text;

      new_tag_list = gtk_text_iter_get_tags (&iter);

      find_list_delta (tag_list, new_tag_list, &added, &removed);

      /* Handle removed tags */
      for (tmp = removed; tmp; tmp = tmp->next)
        {
          GtkTextTag *tag = tmp->data;

          /* Only close the tag if we didn't close it before (by using
           * the stack logic in the while() loop below)
           */
          if (g_slist_find (active_tags, tag))
            {
              /* Drop all tags that were opened after this one (which are
               * above this on in the stack), but move them to the added
               * list so they get re-opened again, *unless* they are also
               * closed at this iter
               */
              while (active_tags->data != tag)
                {
                  close_tag (GIMP_TEXT_BUFFER (register_buffer),
                             string, active_tags->data);

                  /* if it also in the list of removed tags, *don't* add
                   * it to the list of added tags again
                   */
                  if (! g_list_find (removed, active_tags->data))
                    added = g_list_prepend (added, active_tags->data);

                  active_tags = g_slist_remove (active_tags, active_tags->data);
                }

              /*  then, close the tag itself  */
              close_tag (GIMP_TEXT_BUFFER (register_buffer), string, tag);

              active_tags = g_slist_remove (active_tags, active_tags->data);
            }
        }

      /* Handle added tags */
      for (tmp = added; tmp; tmp = tmp->next)
        {
          GtkTextTag *tag = tmp->data;

          open_tag (GIMP_TEXT_BUFFER (register_buffer), string, tag);

          active_tags = g_slist_prepend (active_tags, tag);
        }

      g_slist_free (tag_list);
      tag_list = new_tag_list;

      g_list_free (added);
      g_list_free (removed);

      old_iter = iter;

      /* Now try to go to either the next tag toggle, or if a pixbuf appears */
      while (TRUE)
        {
          gunichar ch = gtk_text_iter_get_char (&iter);

          if (ch == 0xFFFC)
            {
              /* pixbuf? can't happen! */
            }
          else if (ch == 0)
            {
              break;
            }
          else
            {
              gtk_text_iter_forward_char (&iter);
            }

          if (gtk_text_iter_toggles_tag (&iter, NULL))
            break;
        }

      /* We might have moved too far */
      if (gtk_text_iter_compare (&iter, end) > 0)
        iter = *end;

      /* Append the text */
      tmp_text = gtk_text_iter_get_slice (&old_iter, &iter);
      escaped_text = g_markup_escape_text (tmp_text, -1);
      g_free (tmp_text);

      g_string_append (string, escaped_text);
      g_free (escaped_text);
    }
  while (! gtk_text_iter_equal (&iter, end));

  g_slist_free (tag_list);

  /* Close any open tags */
  for (tag_list = active_tags; tag_list; tag_list = tag_list->next)
    close_tag (GIMP_TEXT_BUFFER (register_buffer), string, tag_list->data);

  g_slist_free (active_tags);

  g_string_append (string, "</markup>");

  *length = string->len;

  return (guint8 *) g_string_free (string, FALSE);
}