Example #1
0
static void pp_header(struct pretty_print_context *pp,
		      const char *encoding,
		      const struct commit *commit,
		      const char **msg_p,
		      struct strbuf *sb)
{
	int parents_shown = 0;

	for (;;) {
		const char *line = *msg_p;
		int linelen = get_one_line(*msg_p);

		if (!linelen)
			return;
		*msg_p += linelen;

		if (linelen == 1)
			/* End of header */
			return;

		if (pp->fmt == CMIT_FMT_RAW) {
			strbuf_add(sb, line, linelen);
			continue;
		}

		if (starts_with(line, "parent ")) {
			if (linelen != 48)
				die("bad parent line in commit");
			continue;
		}

		if (!parents_shown) {
			struct commit_list *parent;
			int num;
			for (parent = commit->parents, num = 0;
			     parent;
			     parent = parent->next, num++)
				;
			/* with enough slop */
			strbuf_grow(sb, num * 50 + 20);
			add_merge_info(pp, sb, commit);
			parents_shown = 1;
		}

		/*
		 * MEDIUM == DEFAULT shows only author with dates.
		 * FULL shows both authors but not dates.
		 * FULLER shows both authors and dates.
		 */
		if (starts_with(line, "author ")) {
			strbuf_grow(sb, linelen + 80);
			pp_user_info(pp, "Author", sb, line + 7, encoding);
		}
		if (starts_with(line, "committer ") &&
		    (pp->fmt == CMIT_FMT_FULL || pp->fmt == CMIT_FMT_FULLER)) {
			strbuf_grow(sb, linelen + 80);
			pp_user_info(pp, "Commit", sb, line + 10, encoding);
		}
	}
}
Example #2
0
void pp_remainder(struct pretty_print_context *pp,
		  const char **msg_p,
		  struct strbuf *sb,
		  int indent)
{
	int first = 1;
	for (;;) {
		const char *line = *msg_p;
		int linelen = get_one_line(line);
		*msg_p += linelen;

		if (!linelen)
			break;

		if (is_empty_line(line, &linelen)) {
			if (first)
				continue;
			if (pp->fmt == CMIT_FMT_SHORT)
				break;
		}
		first = 0;

		strbuf_grow(sb, linelen + indent + 20);
		if (indent) {
			memset(sb->buf + sb->len, ' ', indent);
			strbuf_setlen(sb, sb->len + indent);
		}
		strbuf_add(sb, line, linelen);
		strbuf_addch(sb, '\n');
	}
}
Example #3
0
File: pretty.c Project: Pistos/git
void pp_title_line(enum cmit_fmt fmt,
		   const char **msg_p,
		   struct strbuf *sb,
		   const char *subject,
		   const char *after_subject,
		   const char *encoding,
		   int need_8bit_cte)
{
	struct strbuf title;

	strbuf_init(&title, 80);

	for (;;) {
		const char *line = *msg_p;
		int linelen = get_one_line(line);

		*msg_p += linelen;
		if (!linelen || is_empty_line(line, &linelen))
			break;

		strbuf_grow(&title, linelen + 2);
		if (title.len) {
			if (fmt == CMIT_FMT_EMAIL) {
				strbuf_addch(&title, '\n');
			}
			strbuf_addch(&title, ' ');
		}
		strbuf_add(&title, line, linelen);
	}

	strbuf_grow(sb, title.len + 1024);
	if (subject) {
		strbuf_addstr(sb, subject);
		add_rfc2047(sb, title.buf, title.len, encoding);
	} else {
		strbuf_addbuf(sb, &title);
	}
	strbuf_addch(sb, '\n');

	if (need_8bit_cte > 0) {
		const char *header_fmt =
			"MIME-Version: 1.0\n"
			"Content-Type: text/plain; charset=%s\n"
			"Content-Transfer-Encoding: 8bit\n";
		strbuf_addf(sb, header_fmt, encoding);
	}
	if (after_subject) {
		strbuf_addstr(sb, after_subject);
	}
	if (fmt == CMIT_FMT_EMAIL) {
		strbuf_addch(sb, '\n');
	}
	strbuf_release(&title);
}
Example #4
0
static const char *skip_empty_lines(const char *msg)
{
	for (;;) {
		int linelen = get_one_line(msg);
		int ll = linelen;
		if (!linelen)
			break;
		if (!is_empty_line(msg, &ll))
			break;
		msg += linelen;
	}
	return msg;
}
Example #5
0
/* parse one line */
static Bool /* True == Error, False == Success */
parse_one_line(SDynPropRecValList *pThisList, FILE *is)
{
    Bool result = False;
    char *buf = NULL;
    char *recordHead, *valueHead = NULL;

    if (NULL == (buf = malloc(LEN_LINEBUF))) {
        fprintf(stderr,
                "truetype font property file : cannot allocate memory.\n");
        result = True;
        goto abort;
    }
    {
        recordHead = buf;
/*        refRecordValue->refRecordType = NULL;*/
        do {
            if (get_one_line(is, buf)) {
                result = True;
                goto quit;
            }
            if (feof(is)) {
                if ('\0' == *buf)
                    goto quit;
                break;
            }
        } while ('\0' == *buf);

        if (NULL != (valueHead = strchr(buf, 0xff))) {
            *valueHead = '\0';
            valueHead++;
        } else
            valueHead = buf+strlen(buf);
#if 0
        fprintf(stderr,
                "truetype font property file : \n"
                "recName:\"%s\"\nvalue:\"%s\"\n",
                recordHead, valueHead);
#endif
        result = SPropRecValList_add_record(pThisList, recordHead, valueHead);
    }
  quit:
    free(buf);
  abort:
    return result;
}
Example #6
0
/* Reads some text from the subprocess, and creates and returns a `line'
   object.  Adds that object to the lines list.   Returns 0 if no text
   available yet.

   If skip_blanks_p, then keep trying for new lines of text until we
   get one that is not empty.
 */
static line *
make_line (fliptext_configuration *sc, Bool skip_blanks_p)
{
  XCharStruct e;
  line *ln;
  char *s;

 AGAIN:
  s = get_one_line (sc);
  if (s && skip_blanks_p && blank_p (s))
    {
      free (s);
      goto AGAIN;
    }

  if (!s) return 0;

  ln = (line *) calloc (1, sizeof(*ln));
  ln->text = s;
  ln->state = NEW;
  texture_string_metrics (sc->texfont, s, &e, 0, 0);
  ln->width = sc->font_scale * e.width;
  ln->height = sc->font_scale * sc->line_height;

  memcpy (ln->color, sc->color, sizeof(ln->color));

  sc->nlines++;
  if (sc->lines_size <= sc->nlines)
    {
      sc->lines_size = (sc->lines_size * 1.2) + sc->nlines;
      sc->lines = (line **)
        realloc (sc->lines, sc->lines_size * sizeof(*sc->lines));
      if (! sc->lines)
        {
          fprintf (stderr, "%s: out of memory (%d lines)\n",
                   progname, sc->lines_size);
          exit (1);
        }
    }

  sc->lines[sc->nlines-1] = ln;
  return ln;
}
Example #7
0
void pp_remainder(struct pretty_print_context *pp,
		  const char **msg_p,
		  struct strbuf *sb,
		  int indent)
{
	int first = 1;
	for (;;) {
		const char *line = *msg_p;
		int linelen = get_one_line(line);
		*msg_p += linelen;

		if (!linelen)
			break;

		if (is_blank_line(line, &linelen)) {
			if (first)
				continue;
			if (pp->fmt == CMIT_FMT_SHORT)
				break;
		}
		first = 0;

		strbuf_grow(sb, linelen + indent + 20);
		if (indent)
			pp_handle_indent(pp, sb, indent, line, linelen);
		else if (pp->expand_tabs_in_log)
			strbuf_add_tabexpand(sb, pp->expand_tabs_in_log,
					     line, linelen);
		else {
			if (pp->fmt == CMIT_FMT_MBOXRD &&
					is_mboxrd_from(line, linelen))
				strbuf_addch(sb, '>');

			strbuf_add(sb, line, linelen);
		}
		strbuf_addch(sb, '\n');
	}
}
Example #8
0
const char *format_subject(struct strbuf *sb, const char *msg,
			   const char *line_separator)
{
	int first = 1;

	for (;;) {
		const char *line = msg;
		int linelen = get_one_line(line);

		msg += linelen;
		if (!linelen || is_empty_line(line, &linelen))
			break;

		if (!sb)
			continue;
		strbuf_grow(sb, linelen + 2);
		if (!first)
			strbuf_addstr(sb, line_separator);
		strbuf_add(sb, line, linelen);
		first = 0;
	}
	return msg;
}
Example #9
0
/*
 * name:    get_sections
 * func:    API: get all mainkey from buffer to *sections[]
 * input��  struct file *buffer 
 * output�� char *sections[]
 * return�� number of sections or error number (negative)  
 */
int cfg_get_sections(char *buffer, char *sections[])
{ 
  char buf[LINE_MAX_CHAR_NUM + 1]; 
  int n, n_sections = 0, ret; 
  unsigned int i, buf_len;
	
	if((buf_len = strlen((char *)buffer)) < 1) 
    return CFG_ERR; 
    
  for(i = 0; i < buf_len; )  /* search for section */
  { 
    ret = CFG_ERR_RD; 
    n = get_one_line(buffer, buf, LINE_MAX_CHAR_NUM); 
		buffer += n; 
    i += n;
    
    if(n < 0) 
      break; /* end of file */ 

    n = strlen(strim(buf)); 
    if(n == 0 || buf[0] == comment_pre) 
      continue; /* null line or comment line */
    ret = CFG_ERR_FMT; 
    if(n > 2 && ((buf[0] == sct_pre && buf[n-1] != sct_post))) 
      goto get_scts_end; 
    if(buf[0] == sct_pre) 
    { 
      buf[n-1] = 0x00; 
      strcpy(sections[n_sections], buf+1); 
      n_sections++; 
    } 
  } 
  ret = n_sections; 
get_scts_end:
  return ret;
}
Example #10
0
void
check_gnu(char *addr, size_t fsize)
{
	int	i;
	char	c, mc;
	char	*linebuf;
	char	*mbuf, *p, *buf;
	unsigned int	n;
	size_t	ln_size;
	size_t	bufsize, index;
	size_t	size = fsize;
	int	quotefound = 0;
	const char	*field;

	buf = NULL;
	linebuf = NULL;
	mbuf = addr;

loop:
	ln_size = get_one_line(&linebuf, &mbuf, &size);
	if ((ln_size == (size_t)-1) ||
		(ln_size == 0)) {
		goto no_gnu;
	}
	p = linebuf;

	while ((*p == '#') || (*p == '\n')) {
		ln_size = get_one_line(&linebuf, &mbuf, &size);
		if ((ln_size == (size_t)-1) ||
			(ln_size == 0)) {
			goto no_gnu;
		}
		p = linebuf;
	}

	if (strncmp(p, "domain", 6) == 0)
		goto loop;

	if (strncmp(p, "msgid", 5) != 0) {
		/* error */
		goto no_gnu;
	}

	p += 5;
	if ((*p != ' ') && (*p != '\t') &&
		(*p != '\n') && (*p != '\0')) {
		/* no space after msgid */
		goto no_gnu;
	}
	/* skip spaces */
	while ((*p == ' ') || (*p == '\t'))
		p++;

	/* check if this entry is an empty string */
	if ((*p != '\"') || (*(p + 1) != '\"')) {
		/* this is not an empty string */
		goto no_gnu;
	}
	p += 2;
	while (*p && ((*p == ' ') || (*p == '\t'))) {
		p++;
	}
	if ((*p != '\n') && (*p != '\0')) {
		/* other characters than '\n' and '\0' found */
		goto no_gnu;
	}

	for (; ; ) {
		ln_size = get_one_line(&linebuf, &mbuf, &size);
		if ((ln_size == (size_t)-1) ||
			(ln_size == 0)) {
			goto no_gnu;
		}
		p = linebuf;
		/* skip leading spaces */
		while ((*p == ' ') || (*p == '\t'))
			p++;

		if (*p != '\"') {
			if (strncmp(p, "msgstr", 6) == 0) {
				break;
			}
			/* not a valid entry */
			goto no_gnu;
		}
		if (*(p + 1) != '\"') {
			/* not an empty string */
			goto no_gnu;
		}
		p += 2;
		while ((*p == ' ') || (*p == '\t'))
			p++;

		if ((*p != '\n') && (*p != '\0')) {
			/* other characters than '\n' and '\0' found */
			goto no_gnu;
		}
	}

	/*
	 * msgid for the header entry found
	 * Now p points to "msgstr"
	 */
	p += 6;
	if ((*p != ' ') && (*p != '\t') &&
		(*p != '\n') && (*p != '\0')) {
		/* no space after msgid */
		goto no_gnu;
	}

	/* skip spaces */
	while ((*p == ' ') || (*p == '\t'))
		p++;

	if (*p != '\"') {
		/* no quote */
		goto no_gnu;
	}

	bufsize = ln_size + 1;
	index = 0;
	buf = (char *)Xmalloc(bufsize);

	for (; ; ) {
		if (*p != '\"') {
			/* msgstr entry ends */
			buf[index] = '\0';
			break;
		}

		if (*p++ != '\"') {
			/* no beginning quote */
			goto no_gnu;
		}
		while (*p) {
			switch (mc = *p++) {
			case '\n':
				if (!quotefound) {
					/* error */
					goto no_gnu;
				}
				break;
			case '\"':
				quotefound = 1;
				break;
			case '\\':
				if (!*p)
					break;
				switch (c = *p++) {
				case 'b':
					buf[index++] = '\b';
					break;
				case 'f':
					buf[index++] = '\f';
					break;
				case 'n':
					buf[index++] = '\n';
					break;
				case 'r':
					buf[index++] = '\r';
					break;
				case 't':
					buf[index++] = '\t';
					break;
				case 'v':
					buf[index++] = '\v';
					break;
				case 'a':
					buf[index++] = '\a';
					break;
				case '\"':
				case '\\':
				case '\'':
				case '?':
					buf[index++] = c;
					break;
				default:
					if (isdigit((unsigned char)c)) {
						unsigned int	x;
						unsigned char	*up =
							(unsigned char *)p;
						n = c - '0';
						if (isdigit(*up)) {
							x = *up++ - '0';
							n = 8 * n + x;
							if (isdigit(*up)) {
								x = *up++ - '0';
								n = 8 * n + x;
							}
						}
						p = (char *)up;
						buf[index++] = n;
					}
					break;
				}
				break;
			default:
				buf[index++] = mc;
				break;
			}
			if (quotefound) {
				while (*p && ((*p == ' ') || (*p == '\t'))) {
					p++;
				}
				if ((*p != '\n') && (*p != '\0')) {
					goto no_gnu;
				}
				quotefound = 0;
				break;
			}
		}
		ln_size = get_one_line(&linebuf, &mbuf, &size);
		if ((ln_size == (size_t)-1) ||
			(ln_size == 0)) {
			goto no_gnu;
		}
		p = linebuf;
		/* skip spaces */
		while ((*p == ' ') || (*p == '\t'))
			p++;
		bufsize += ln_size;
		buf = (char *)Xrealloc(buf, bufsize);
	}

	for (i = 0; (field = mandatory_fields[i]) != NULL; i++) {
		if (strstr(buf, field) == NULL)
			continue;
		/* one of mandatory fields found */
		free(linebuf);
		free(buf);
		(void) munmap(addr, fsize);
		if (verbose)
			diag(gettext(DIAG_GNU_FOUND));
		invoke_gnu_msgfmt();
		/* NOTREACHED */
	}
	for (i = 0; (field = mandatory_fields_new[i]) != NULL; i++) {
		if (strstr(buf, field) == NULL)
			continue;
		/* one of mandatory fields found */
		free(linebuf);
		free(buf);
		(void) munmap(addr, fsize);
		if (verbose)
			diag(gettext(DIAG_GNU_FOUND));
		invoke_gnu_msgfmt();
		/* NOTREACHED */
	}

no_gnu:
	free(linebuf);
	if (buf)
		free(buf);
}
Example #11
0
File: imc.c Project: bkero/Smaug
/* low-level idle function: read/write buffers as needed, etc */
void imc_idle_select(fd_set *read, fd_set *write, fd_set *exc, time_t now)
{
  const char *command;
  imc_packet *p;
  imc_connect *c, *c_next ;

  if (imc_active<IA_CONFIG1)
    return;

  if (imc_lock)
  {
    imc_logerror("imc_idle_select: recursive call");
    return;
  }

  imc_lock=1;

  if (imc_sequencenumber < (unsigned long)imc_now)
    imc_sequencenumber=(unsigned long)imc_now;

  imc_run_events(now);

  if (imc_active<IA_UP)
  {
    imc_lock=0;
    return;
  }

  /* handle results of the select */

  if (imc_active >= IA_LISTENING &&
      FD_ISSET(control, read))
    do_accept();

  for (c=imc_connect_list; c; c=c_next)
  {
    c_next=c->next;

    if (c->state!=IMC_CLOSED && FD_ISSET(c->desc, exc))
      do_close(c);

    if (c->state!=IMC_CLOSED && FD_ISSET(c->desc, read))
      do_read(c);

    while (c->state!=IMC_CLOSED &&
//	   (c->spamtime1>=0 || c->spamcounter1<=IMC_SPAM1MAX) &&
//	   (c->spamtime2>=0 || c->spamcounter2<=IMC_SPAM2MAX) &&
	   (command = get_one_line(c->inbuf)) != NULL)
    {
      if (strlen(command) > imc_stats.max_pkt)
	imc_stats.max_pkt=strlen(command);

//      imc_debug(c, 0, command);	/* log incoming packets */

      switch (c->state)
      {
      case IMC_CLOSED:
	break;
      case IMC_WAIT1:
	clientpassword(c, command);
	break;
      case IMC_WAIT2:
	serverpassword(c, command);
	break;
      case IMC_CONNECTED:
	p = do_interpret_packet(c, command);
	if (p)
	{
#ifdef IMC_PARANOIA
	  /* paranoia: check the last entry in the path is the same as the
	   * sending mud. Also check the first entry to see that it matches
	   * the sender.
	   */

	  imc_stats.rx_pkts++;

	  if (strcasecmp(c->info->name,
			 imc_lastinpath(p->i.path)))
	    imc_logerror("PARANOIA: packet from %s allegedly from %s",
			 c->info->name,
			 imc_lastinpath(p->i.path));
	  else if (strcasecmp(imc_mudof(p->i.from), imc_firstinpath(p->i.path)))
	    imc_logerror("PARANOIA: packet from %s has firstinpath %s",
			 p->i.from,
			 imc_firstinpath(p->i.path));
	  else
	    forward(p);		/* only forward if its a valid packet! */
#else
	  imc_stats.rx_pkts++;
	  forward(p);
#endif
#ifdef SPAMPROT
  if (!strcasecmp(p->type, "chat") ||
      !strcasecmp(p->type, "tell") ||
      !strcasecmp(p->type, "emote") || 1)
  {
      if (!c->spamcounter1 && !c->spamtime1)
	imc_add_event(IMC_SPAM1INTERVAL, ev_spam1, c, 0);
      c->spamcounter1++;

      if (!c->spamcounter2 && !c->spamtime2)
	imc_add_event(IMC_SPAM2INTERVAL, ev_spam2, c, 0);
      c->spamcounter2++;
  }
#endif
	  imc_freedata(&p->data);
	}
	break;
      }
    }
  }

  for (c=imc_connect_list; c; c=c_next)
  {
    c_next=c->next;
    
    if (c->state!=IMC_CLOSED &&
	(FD_ISSET(c->desc, write) || c->newoutput))
    {
//      c->newoutput=0;
      do_write(c);
      c->newoutput=c->outbuf[0];
    }
  }

  for (c=imc_connect_list; c; c=c_next)
  {
    c_next=c->next;

    if (c->state==IMC_CLOSED)
      imc_extract_connect(c);
  }

  imc_lock=0;
}
Example #12
0
/*
 * name:    get_all_keys_value
 * func:    get all key values in the specific section from buffer
 * input��  char *buffer, void *section
 * output�� char *keys[],void *value[]
 * return�� if correct, return keys number
 *					else return error number          
 */
static int get_all_keys_value(char *buffer, void *section, char *keys[], void *value[])
{ 
  char buf[LINE_MAX_CHAR_NUM + 1];
  char *key_ptr, *val_ptr; 
  int n, n_keys = 0, ret; 
  unsigned int i, buf_len;
	
	if((buf_len = strlen((char *)buffer)) < 1) 
    return CFG_ERR; 
	
	key_ptr = (char*)kzalloc(MAX_NAME_LEN,GFP_KERNEL);
	val_ptr = (char*)kzalloc(MAX_VALUE_LEN,GFP_KERNEL);
	
  for(i = 0; i < buf_len;)  /* search for section */
  { 
    ret = CFG_ERR_RD; 
    n = get_one_line(buffer, buf, LINE_MAX_CHAR_NUM); 
		buffer += n;
		i += n;
		
    ret = CFG_NOT_FOUND; 
    if(n < 0) 
      goto g_all_keys_end; /* end of file */ 
    n = strlen(strim(buf)); 
    if(n == 0 || buf[0] == comment_pre) 
      continue; /* null line or comment line */ 
    ret = CFG_ERR_FMT; 
    if(n > 2 && ((buf[0] == sct_pre && buf[n-1] != sct_post))) 
      goto g_all_keys_end; 
    if(buf[0] == sct_pre) 
    { 
      buf[n-1] = 0x00; 
      if(strcmp(buf+1, section) == 0) 
        break; /* section found */ 
    } 
  } 
  for( ; i < buf_len; ) /* search for keys */  
  { 
    ret = CFG_ERR_RD; 
    n = get_one_line(buffer, buf, LINE_MAX_CHAR_NUM); 
    buffer += n;
    i += n;
    
    if(n < 0) 
      break; /* end of file */ 
    n = strlen(strim(buf)); 
    if(n == 0 || buf[0] == comment_pre) 
      continue; /* null line or comment line */ 
    ret = CFG_NOT_FOUND; 
    if(buf[0] == sct_pre) 
      break; /* another section */ 
    ret = CFG_ERR_FMT; 
    if(split_key_value(buf, key_ptr, val_ptr) != 1) 
      goto g_all_keys_end; 
		
    strim(key_ptr);
    strcpy(keys[n_keys], key_ptr); 
    strim(val_ptr);
    strcpy(value[n_keys], val_ptr);

    n_keys++; 
  } 
  ret = n_keys; 
g_all_keys_end: 
	if(key_ptr)
		kfree(key_ptr);
	if(val_ptr)
		kfree(val_ptr);
  return ret; 
}
Example #13
0
unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned long len, char *buf, unsigned long space)
{
	int hdr = 1, body = 0;
	unsigned long offset = 0;
	int parents = 0;
	int indent = (fmt == CMIT_FMT_ONELINE) ? 0 : 4;

	for (;;) {
		const char *line = msg;
		int linelen = get_one_line(msg, len);

		if (!linelen)
			break;

		/*
		 * We want some slop for indentation and a possible
		 * final "...". Thus the "+ 20".
		 */
		if (offset + linelen + 20 > space) {
			memcpy(buf + offset, "    ...\n", 8);
			offset += 8;
			break;
		}

		msg += linelen;
		len -= linelen;
		if (hdr) {
			if (linelen == 1) {
				hdr = 0;
				if (fmt != CMIT_FMT_ONELINE)
					buf[offset++] = '\n';
				continue;
			}
			if (fmt == CMIT_FMT_RAW) {
				memcpy(buf + offset, line, linelen);
				offset += linelen;
				continue;
			}
			if (!memcmp(line, "parent ", 7)) {
				if (linelen != 48)
					die("bad parent line in commit");
				offset += add_parent_info(fmt, buf + offset, line, ++parents);
			}

			/*
			 * MEDIUM == DEFAULT shows only author with dates.
			 * FULL shows both authors but not dates.
			 * FULLER shows both authors and dates.
			 */
			if (!memcmp(line, "author ", 7))
				offset += add_user_info("Author", fmt,
							buf + offset,
							line + 7);
			if (!memcmp(line, "committer ", 10) &&
			    (fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER))
				offset += add_user_info("Commit", fmt,
							buf + offset,
							line + 10);
			continue;
		}

		if (is_empty_line(line, linelen)) {
			if (!body)
				continue;
			if (fmt == CMIT_FMT_SHORT)
				break;
		} else {
			body = 1;
		}

		memset(buf + offset, ' ', indent);
		memcpy(buf + offset + indent, line, linelen);
		offset += linelen + indent;
		if (fmt == CMIT_FMT_ONELINE)
			break;
	}
	if (fmt == CMIT_FMT_ONELINE) {
		/* We do not want the terminating newline */
		if (buf[offset - 1] == '\n')
			offset--;
	}
	else {
		/* Make sure there is an EOLN */
		if (buf[offset - 1] != '\n')
			buf[offset++] = '\n';
	}
	buf[offset] = '\0';
	return offset;
}
Example #14
0
static void pp_header(enum cmit_fmt fmt,
		      int abbrev,
		      enum date_mode dmode,
		      const char *encoding,
		      const struct commit *commit,
		      const char **msg_p,
		      struct strbuf *sb)
{
	int parents_shown = 0;

	for (;;) {
		const char *line = *msg_p;
		int linelen = get_one_line(*msg_p);

		if (!linelen)
			return;
		*msg_p += linelen;

		if (linelen == 1)
			/* End of header */
			return;

		if (fmt == CMIT_FMT_RAW) {
			strbuf_add(sb, line, linelen);
			continue;
		}

		if (!memcmp(line, "parent ", 7)) {
			if (linelen != 48)
				die("bad parent line in commit");
			continue;
		}

		if (!parents_shown) {
			struct commit_list *parent;
			int num;
			for (parent = commit->parents, num = 0;
			     parent;
			     parent = parent->next, num++)
				;
			/* with enough slop */
			strbuf_grow(sb, num * 50 + 20);
			add_merge_info(fmt, sb, commit, abbrev);
			parents_shown = 1;
		}

		/*
		 * MEDIUM == DEFAULT shows only author with dates.
		 * FULL shows both authors but not dates.
		 * FULLER shows both authors and dates.
		 */
		if (!memcmp(line, "author ", 7)) {
			strbuf_grow(sb, linelen + 80);
			pp_user_info("Author", fmt, sb, line + 7, dmode, encoding);
		}
		if (!memcmp(line, "committer ", 10) &&
		    (fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER)) {
			strbuf_grow(sb, linelen + 80);
			pp_user_info("Commit", fmt, sb, line + 10, dmode, encoding);
		}
	}
}
Example #15
0
File: pretty.c Project: Pistos/git
void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
			 struct strbuf *sb, int abbrev,
			 const char *subject, const char *after_subject,
			 enum date_mode dmode, int need_8bit_cte)
{
	unsigned long beginning_of_body;
	int indent = 4;
	const char *msg = commit->buffer;
	char *reencoded;
	const char *encoding;

	if (fmt == CMIT_FMT_USERFORMAT) {
		format_commit_message(commit, user_format, sb);
		return;
	}

	encoding = (git_log_output_encoding
		    ? git_log_output_encoding
		    : git_commit_encoding);
	if (!encoding)
		encoding = "utf-8";
	reencoded = logmsg_reencode(commit, encoding);
	if (reencoded) {
		msg = reencoded;
	}

	if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
		indent = 0;

	/*
	 * We need to check and emit Content-type: to mark it
	 * as 8-bit if we haven't done so.
	 */
	if (fmt == CMIT_FMT_EMAIL && need_8bit_cte == 0) {
		int i, ch, in_body;

		for (in_body = i = 0; (ch = msg[i]); i++) {
			if (!in_body) {
				/* author could be non 7-bit ASCII but
				 * the log may be so; skip over the
				 * header part first.
				 */
				if (ch == '\n' && msg[i+1] == '\n')
					in_body = 1;
			}
			else if (non_ascii(ch)) {
				need_8bit_cte = 1;
				break;
			}
		}
	}

	pp_header(fmt, abbrev, dmode, encoding, commit, &msg, sb);
	if (fmt != CMIT_FMT_ONELINE && !subject) {
		strbuf_addch(sb, '\n');
	}

	/* Skip excess blank lines at the beginning of body, if any... */
	for (;;) {
		int linelen = get_one_line(msg);
		int ll = linelen;
		if (!linelen)
			break;
		if (!is_empty_line(msg, &ll))
			break;
		msg += linelen;
	}

	/* These formats treat the title line specially. */
	if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
		pp_title_line(fmt, &msg, sb, subject,
			      after_subject, encoding, need_8bit_cte);

	beginning_of_body = sb->len;
	if (fmt != CMIT_FMT_ONELINE)
		pp_remainder(fmt, &msg, sb, indent);
	strbuf_rtrim(sb);

	/* Make sure there is an EOLN for the non-oneline case */
	if (fmt != CMIT_FMT_ONELINE)
		strbuf_addch(sb, '\n');

	/*
	 * The caller may append additional body text in e-mail
	 * format.  Make sure we did not strip the blank line
	 * between the header and the body.
	 */
	if (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
		strbuf_addch(sb, '\n');
	free(reencoded);
}