Exemplo n.º 1
0
static void
xml_output_indent (const XMLNode *node, int level, GString *output)
{
    gchar **attrs;

    output_indent (level, output);
    g_string_append_printf (output, "<%s", node->name);

    attrs = node->attributes;

    while (attrs != NULL && *attrs != NULL) {
        g_string_append_printf (output, " %s", *(attrs++));
        g_string_append_printf (output, "=\"%s\"", *(attrs++));
    }

    if (node->sub_nodes != NULL){
        g_string_append (output, ">\n");
        GList *sub_node;

        for (sub_node = node->sub_nodes; sub_node != NULL; sub_node = sub_node->next) {
            xml_output_indent (sub_node->data, level + 1, output);
        }
        output_indent (level, output);
        g_string_append_printf (output, "</%s>\n",node->name);
    }
    else if (node->text != NULL) {
        gchar *text = g_markup_escape_text (node->text, -1);
        g_string_append_printf (output, ">%s</%s>\n", text, node->name);
        g_free (text);
    }
    else {
        g_string_append (output, "/>\n");
    }
}
Exemplo n.º 2
0
void trace_restrict_pos (pos_node p, value mval)
	{ tree_node node = p -> node;
	  int nodenr = node -> nodenr;
	  int pos_nr = find_position_nr (p, node);
	  output_indent ();
	  eprint_log ("restricting position %d of %s in module %s\n",
		      pos_nr + 1, node -> name,
		      module_name_from_nodenr (nodenr));
	  output_indent ();
	  eprint_log ("with value: ");
	  dump_value (mval);
	  eprint_log ("\n");
	  trace_pos_side (p, lower_side);
	  trace_pos_side (p, upper_side);
	};
Exemplo n.º 3
0
/* Begin a new paragraph with an indent of |indent| spaces.
 */
static void
new_paragraph(size_t old_indent, size_t indent) {
  if (output_buffer_length) {
    if (old_indent>0) output_indent(old_indent);
    wprintf(L"%.*ls\n", (int)output_buffer_length, output_buffer);
  }
  x=indent; x0=0; output_buffer_length=0; pending_spaces=0;
  output_in_paragraph = 0;
}
Exemplo n.º 4
0
void trace_pos (pos_node p)
	{ tree_node node = p -> node;
	  int nodenr = node -> nodenr;
	  int pos_nr = find_position_nr (p, node);
	  output_indent ();
	  eprint_log ("tracing position %d of %s in module %s\n",
		      pos_nr + 1, node -> name,
		      module_name_from_nodenr (nodenr));
	  trace_pos_side (p, lower_side);
	  trace_pos_side (p, upper_side);
	};
Exemplo n.º 5
0
/* Begin a new paragraph with an indent of |indent| spaces.
 */
static void
new_paragraph(size_t old_indent, size_t indent)
{

	if (x0) {
		if (old_indent > 0)
			output_indent(old_indent);
		fwrite(output_buffer, 1, x0, stdout);
		putchar('\n');
	}
	x = indent;
	x0 = 0;
	pending_spaces = 0;
	output_in_paragraph = 0;
}
Exemplo n.º 6
0
void trace_pos_side (pos_node p, int i)
	{ int tag = p -> sides[i].tag;
	  output_indent ();
	  eprint_log ("%s = (", (i == lower_side)?"lo":"hi");
	  eprint_log ("sill = %d, ", p -> sides[i].sill);
	  switch (tag)
	     { case tag_undefined: eprint_log ("_"); break;
	       case tag_single: trace_affix (p -> sides[i].a.affx); break;
	       case tag_compos:
	       case tag_concat:
	       case tag_union:
		  { int iy;
		    int nr = p -> sides[i].a.co.nr;
		    string seps = "*+|";
		    char sep = seps[tag - tag_compos];
		    for (iy = 0; iy < nr; iy++)
		       { trace_affix (p -> sides[i].a.co.affs[iy]);
			 if (iy != nr - 1) eprint_log (" %c ", sep);
		       };
		  };
	     };
	  eprint_log (")\n");
	};
Exemplo n.º 7
0
void trace_leave (char *s)
	{ indent--;
	  output_indent ();
	  eprint_log ("<%s\n", s);
	};
Exemplo n.º 8
0
void trace_placeholder_alternative (char *s, int untyped)
	{ output_indent ();
	  eprint_log ("-%s, %styped placeholder alt\n", s, (untyped)?"un":"");
	};
Exemplo n.º 9
0
void trace_alternative (char *s, int i)
	{ output_indent ();
	  eprint_log ("-%s, alt %d\n", s, i);
	};
Exemplo n.º 10
0
void trace_enter (char *s)
	{ output_indent ();
	  eprint_log (">%s\n", s);
	  indent++;
	};
Exemplo n.º 11
0
/**
 * Outputs the CPP comment at pc.
 * CPP comment combining is done here
 *
 * @return the last chunk output'd
 */
chunk_t *output_comment_cpp(chunk_t *first)
{
   int col    = first->column;
   int col_br = 1 + (first->brace_level * cpd.settings[UO_indent_columns].n);

   /* Make sure we have at least one space past the last token */
   if (first->parent_type == CT_COMMENT_END)
   {
      chunk_t *prev = chunk_get_prev(first);
      if (prev != NULL)
      {
         int col_min = prev->column + prev->len + 1;
         if (col < col_min)
         {
            col = col_min;
         }
      }
   }

   /* Bump out to the column */
   output_indent(col, col_br);

   if (!cpd.settings[UO_cmt_cpp_to_c].b)
   {
      add_text_len(first->str, first->len);
      return(first);
   }

   /* If we are grouping, see if there is something to group */
   bool combined = false;
   if (cpd.settings[UO_cmt_cpp_group].b)
   {
      /* next is a newline by definition */
      chunk_t *next = chunk_get_next(first);
      if ((next != NULL) && (next->nl_count == 1))
      {
         next = chunk_get_next(next);

         /**
          * Only combine the next comment if they are both at indent level or
          * the second one is NOT at indent or less
          *
          * A trailing comment cannot be combined with a comment at indent
          * level or less
          */
         if ((next != NULL) &&
             (next->type == CT_COMMENT_CPP) &&
             (((next->column == 1) && (first->column == 1)) ||
              ((next->column == col_br) && (first->column == col_br)) ||
              ((next->column > col_br) && (first->parent_type == CT_COMMENT_END))))
         {
            combined = true;
         }
      }
   }

   if (!combined)
   {
      /* nothing to group: just output a single line */
      add_text_len("/*", 2);
      if ((first->str[2] != ' ') && (first->str[2] != '\t'))
      {
         add_char(' ');
      }
      add_text_len(&first->str[2], first->len - 2);
      add_text_len(" */", 3);
      return(first);
   }

   chunk_t *pc   = first;
   chunk_t *last = first;

   /* Output the first line */
   add_text_len("/*", 2);
   if (combined && cpd.settings[UO_cmt_cpp_nl_start].b)
   {
      /* I suppose someone more clever could do this without a goto or
       * repeating too much code...
       */
      goto cpp_newline;
   }
   goto cpp_addline;

   /* Output combined lines */
   while ((pc = chunk_get_next(pc)) != NULL)
   {
      if ((pc->type == CT_NEWLINE) && (pc->nl_count == 1))
      {
         continue;
      }
      if (pc->type != CT_COMMENT_CPP)
      {
         break;
      }
      if (((pc->column == 1) && (first->column == 1)) ||
          ((pc->column == col_br) && (first->column == col_br)) ||
          ((pc->column > col_br) && (first->parent_type == CT_COMMENT_END)))
      {
         last = pc;
cpp_newline:
         add_char('\n');
         output_indent(col, col_br);
         add_char(' ');
         add_char(cpd.settings[UO_cmt_star_cont].b ? '*' : ' ');
cpp_addline:
         if ((pc->str[2] != ' ') && (pc->str[2] != '\t'))
         {
            add_char(' ');
         }
         add_text_len(&pc->str[2], pc->len - 2);
      }
   }

   if (cpd.settings[UO_cmt_cpp_nl_end].b)
   {
      add_char('\n');
      output_indent(col, col_br);
   }
   add_text_len(" */", 3);
   return(last);
}
Exemplo n.º 12
0
/* Output a single word, or add it to the buffer.
 * indent0 and indent1 are the indents to use on the first and subsequent
 * lines of a paragraph. They'll often be the same, of course.
 */
static void
output_word(size_t indent0, size_t indent1, const wchar_t *word, size_t length, size_t spaces) {
  size_t new_x;
  size_t indent = output_in_paragraph ? indent1 : indent0;
  size_t width;
  const wchar_t *p;
  int cwidth;

  for (p = word, width = 0; p < &word[length]; p++)
    width += (cwidth = wcwidth(*p)) > 0 ? cwidth : 1;

  new_x = x + pending_spaces + width;

  /* If either |spaces==0| (at end of line) or |coalesce_spaces_P|
   * (squashing internal whitespace), then add just one space;
   * except that if the last character was a sentence-ender we
   * actually add two spaces.
   */
  if (coalesce_spaces_P || spaces==0)
    spaces = wcschr(sentence_enders, word[length-1]) ? 2 : 1;

  if (new_x<=goal_length) {
    /* After adding the word we still aren't at the goal length,
     * so clearly we add it to the buffer rather than outputing it.
     */
    wmemset(output_buffer+output_buffer_length, L' ', pending_spaces);
    x0 += pending_spaces; x += pending_spaces;
    output_buffer_length += pending_spaces;
    wmemcpy(output_buffer+output_buffer_length, word, length);
    x0 += width; x += width; output_buffer_length += length;
    pending_spaces = spaces;
  }
  else {
    /* Adding the word takes us past the goal. Print the line-so-far,
     * and the word too iff either (1) the lsf is empty or (2) that
     * makes us nearer the goal but doesn't take us over the limit,
     * or (3) the word on its own takes us over the limit.
     * In case (3) we put a newline in between.
     */
    if (indent>0) output_indent(indent);
    wprintf(L"%.*ls", (int)output_buffer_length, output_buffer);
    if (x0==0 || (new_x <= max_length && new_x-goal_length <= goal_length-x)) {
      wprintf(L"%*ls", (int)pending_spaces, L"");
      goto write_out_word;
    }
    else {
      /* If the word takes us over the limit on its own, just
       * spit it out and don't bother buffering it.
       */
      if (indent+width > max_length) {
        putwchar('\n');
        if (indent>0) output_indent(indent);
write_out_word:
        wprintf(L"%.*ls", (int)length, word);
        x0 = 0; x = indent1; pending_spaces = 0;
        output_buffer_length = 0;
      }
      else {
        wmemcpy(output_buffer, word, length);
        x0 = width; x = width+indent1; pending_spaces = spaces;
        output_buffer_length = length;
      }
    }
    putwchar('\n');
    output_in_paragraph = 1;
  }
}
Exemplo n.º 13
0
/* Output a single word, or add it to the buffer.
 * indent0 and indent1 are the indents to use on the first and subsequent
 * lines of a paragraph. They'll often be the same, of course.
 */
static void
output_word(size_t indent0, size_t indent1, const char *word, size_t length, size_t spaces)
{
	size_t new_x = x + pending_spaces + length;
	size_t indent = output_in_paragraph ? indent1 : indent0;

	/* If either |spaces==0| (at end of line) or |coalesce_spaces_P|
	 * (squashing internal whitespace), then add just one space;
	 * except that if the last character was a sentence-ender we
	 * actually add two spaces.
	 */
	if (coalesce_spaces_P || spaces == 0)
		spaces = strchr(sentence_enders, word[length-1]) ? 2 : 1;

	if (new_x <= goal_length) {
		/* After adding the word we still aren't at the goal length,
		 * so clearly we add it to the buffer rather than outputing it.
		 */
		memset(output_buffer+x0, ' ', pending_spaces);
		x0 += pending_spaces;
		x += pending_spaces;
		memcpy(output_buffer+x0, word, length);
		x0 += length;
		x += length;
		pending_spaces = spaces;
	} else {
		/* Adding the word takes us past the goal. Print the line-so-far,
		 * and the word too iff either (1) the lsf is empty or (2) that
		 * makes us nearer the goal but doesn't take us over the limit,
		 * or (3) the word on its own takes us over the limit.
		 * In case (3) we put a newline in between.
		 */
		if (indent > 0)
			output_indent(indent);
		fwrite(output_buffer, 1, x0, stdout);
		if (x0 == 0 || (new_x <= max_length && new_x-goal_length <= goal_length-x)) {
			printf("%*s", (int)pending_spaces, "");
			goto write_out_word;
		} else {
			/* If the word takes us over the limit on its own, just
			 * spit it out and don't bother buffering it.
			 */
			if (indent+length > max_length) {
				putchar('\n');
				if (indent > 0)
					output_indent(indent);
write_out_word:
				fwrite(word, 1, length, stdout);
				x0 = 0;
				x = indent1;
				pending_spaces = 0;
			} else {
				memcpy(output_buffer, word, length);
				x0 = length;
				x = length+indent1;
				pending_spaces = spaces;
			}
		}

		putchar('\n');
		output_in_paragraph = 1;
	}
}
Exemplo n.º 14
0
static void
begin_of_line(struct process *proc, int is_func, int indent)
{
    current_column = 0;
    if (!proc) {
        return;
    }
    if ((options.output != stderr) && (opt_p || options.follow)) {
        current_column += fprintf(options.output, "%u ", proc->pid);
    } else if (options.follow) {
        current_column += fprintf(options.output, "[pid %u] ", proc->pid);
    }
    if (opt_r) {
        struct timeval tv;
        static struct timeval old_tv = { 0, 0 };
        struct timeval diff;

        gettimeofday(&tv, NULL);

        if (old_tv.tv_sec == 0 && old_tv.tv_usec == 0) {
            old_tv.tv_sec = tv.tv_sec;
            old_tv.tv_usec = tv.tv_usec;
        }
        diff.tv_sec = tv.tv_sec - old_tv.tv_sec;
        if (tv.tv_usec >= old_tv.tv_usec) {
            diff.tv_usec = tv.tv_usec - old_tv.tv_usec;
        } else {
            diff.tv_sec--;
            diff.tv_usec = 1000000 + tv.tv_usec - old_tv.tv_usec;
        }
        old_tv.tv_sec = tv.tv_sec;
        old_tv.tv_usec = tv.tv_usec;
        current_column += fprintf(options.output, "%3lu.%06d ",
                                  (unsigned long)diff.tv_sec,
                                  (int)diff.tv_usec);
    }
    if (opt_t) {
        struct timeval tv;
        gettimeofday(&tv, NULL);
        if (opt_t > 2) {
            current_column += fprintf(options.output, "%lu.%06d ",
                                      (unsigned long)tv.tv_sec,
                                      (int)tv.tv_usec);
        } else if (opt_t > 1) {
            struct tm *tmp = localtime(&tv.tv_sec);
            current_column +=
                fprintf(options.output, "%02d:%02d:%02d.%06d ",
                        tmp->tm_hour, tmp->tm_min, tmp->tm_sec,
                        (int)tv.tv_usec);
        } else {
            struct tm *tmp = localtime(&tv.tv_sec);
            current_column += fprintf(options.output, "%02d:%02d:%02d ",
                                      tmp->tm_hour, tmp->tm_min,
                                      tmp->tm_sec);
        }
    }
    if (opt_i) {
        if (is_func) {
            struct callstack_element *stel
                    = &proc->callstack[proc->callstack_depth - 1];
            current_column += fprintf(options.output, "[%p] ",
                                      stel->return_addr);
        } else {
            current_column += fprintf(options.output, "[%p] ",
                                      proc->instruction_pointer);
        }
    }
    if (options.indent > 0 && indent) {
        output_indent(proc);
    }
}