Changeset 4d24650


Ignore:
Timestamp:
Feb 4, 2011, 3:49:44 PM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
e062f97
Parents:
e3c8332
git-author:
David Benjamin <davidben@mit.edu> (01/25/11 00:18:14)
git-committer:
David Benjamin <davidben@mit.edu> (02/04/11 15:49:44)
Message:
Make owl_text_indent return a new string

You can't really use it correctly as it is.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cmd.c

    re3c8332 r4d24650  
    276276  if (cmd->usage && *cmd->usage) {
    277277    s = cmd->usage;
    278     indent = owl_malloc(strlen(s)+(owl_text_num_lines(s)+3)*OWL_TAB+1);
    279     owl_text_indent(indent, s, OWL_TAB);
     278    indent = owl_text_indent(s, OWL_TAB);
    280279    owl_fmtext_append_bold(fm, "\nSYNOPSIS\n");
    281280    owl_fmtext_append_normal(fm, indent);
     
    291290  if (cmd->description && *cmd->description) {
    292291    s = cmd->description;
    293     indent = owl_malloc(strlen(s)+(owl_text_num_lines(s)+3)*OWL_TAB+1);
    294     owl_text_indent(indent, s, OWL_TAB);
     292    indent = owl_text_indent(s, OWL_TAB);
    295293    owl_fmtext_append_bold(fm, "\nDESCRIPTION\n");
    296294    owl_fmtext_append_normal(fm, indent);
  • style.c

    r30da473 r4d24650  
    6565
    6666  /* indent and ensure ends with a newline */
    67   indent=owl_malloc(strlen(body)+(owl_text_num_lines(body))*OWL_TAB+10);
    68   owl_text_indent(indent, body, OWL_TAB);
     67  indent = owl_text_indent(body, OWL_TAB);
    6968  curlen = strlen(indent);
    7069  if (curlen==0 || indent[curlen-1] != '\n') {
  • text.c

    rd222c44 r4d24650  
    55#include "owl.h"
    66
    7 void owl_text_indent(char *out, const char *in, int n)
     7/* Returns a copy of 'in' with each line indented 'n'
     8 * characters. Result must be freed with owl_free. */
     9char *owl_text_indent(const char *in, int n)
    810{
    911  const char *ptr1, *ptr2, *last;
     12  GString *out = g_string_new("");
    1013  int i;
    11 
    12   strcpy(out, "");
    1314
    1415  last=in+strlen(in)-1;
     
    1617  while (ptr1<=last) {
    1718    for (i=0; i<n; i++) {
    18       strcat(out, " ");
     19      g_string_append_c(out, ' ');
    1920    }
    2021    ptr2=strchr(ptr1, '\n');
    2122    if (!ptr2) {
    22       strcat(out, ptr1);
     23      g_string_append(out, ptr1);
    2324      break;
    2425    } else {
    25       strncat(out, ptr1, ptr2-ptr1+1);
     26      g_string_append_len(out, ptr1, ptr2-ptr1+1);
    2627    }
    2728    ptr1=ptr2+1;
    2829  }
     30  return g_string_free(out, false);
    2931}
    3032
Note: See TracChangeset for help on using the changeset viewer.