示例#1
0
文件: test.c 项目: S010/misc
char           *
remove_comments(char *buffer)
{
	char           *buf = NULL;
	size_t          bufsize = 0;
	size_t          len = 0;
	char           *p, *s, *e;

	if (!buffer)
		return NULL;

	for (s = buffer; s != NULL && *s != '\0'; s = next_code_chunk(e)) {
		if (e = find_comment(s))
			*e = '\0';
		if ((len = strlen(s)) == 0)
			continue;
		buf = realloc(buf, bufsize + len + (bufsize ? 1 : 2));
		memcpy(buf + (bufsize ? bufsize - 1 : 0), s, len);
		bufsize += len + (bufsize ? 1 : 2);
		buf[bufsize - 2] = ' ';
		buf[bufsize - 1] = '\0';
	}

	if (!bufsize) {
		buf = malloc(sizeof(char));
		*buf = '\0';
	} else {
		buf[bufsize - 2] = '\0';
	}

	return buf;
}
示例#2
0
文件: LeoIni.cpp 项目: pulsar-git/PJC
Leo::Ini::Line Leo::Ini::read_line()
{
  Line line;

  while( true )
    {
      std::getline( file, line.str );    
      
      line.number = line_number;
      line_number++;

      if( file.eof() )
	{
	  eof_reached = true;
	  line_number = 0;
	}
      
      if( !strip( line.str ).empty() )
	{
	  // comment
	  std::string::size_type pos = find_comment( line.str );
	  if( pos != std::string::npos )
	    {
	      line.comment.pos = pos;
	      line.comment.str = line.str.substr( pos+1 );
	    }
	  
	  // tag
	  std::string::size_type end_pos;
	  if( find_tag( pos, end_pos, line.str.substr(0,pos) ) )
	    {
	      line.tag.pos = pos;
	      line.tag.str = line.str.substr( pos, end_pos - pos + 1 );
	    }
	  break; // we have a valid line
	}
      
      if( eof_reached )
	break;
    }

  return line;
}
示例#3
0
/* find a host comment by id */
nagios_comment *find_host_comment(unsigned long comment_id) {

	return find_comment(comment_id, HOST_COMMENT);
	}
示例#4
0
/* find a service comment by id */
nagios_comment *find_service_comment(unsigned long comment_id) {

	return find_comment(comment_id, SERVICE_COMMENT);
	}