Exemple #1
0
/***********************************************************************
 *
 * Name :       process_jnl_field_trim()
 *
 * Description: Processes the JNL_FEED_LAYOUT.jnl_field_trim values.
 *              It calls the trim library function in jnl_aux.c
 * Inputs :     None 
 * Outputs :    None
 * Returns :    None
 *
 **********************************************************************/
int 
process_jnl_field_trim(tiny command, char *string, tiny size)
{
  switch(command)
  {
     case FIELD_TRIM_TRIM_RIGHT:
       return(trim_string(TRIM_RIGHT, string, size));
     case FIELD_TRIM_TRIM_LEFT:
       return(trim_string(TRIM_LEFT, string, size));
     case FIELD_TRIM_FILL_RIGHT:
       return(fill_string(FILL_RIGHT, string, size, ' '));
     case FIELD_TRIM_FILL_LEFT:
       return(fill_string(FILL_LEFT, string, size, ' '));
     case FIELD_TRIM_FILL_ZERO_RIGHT:
       return(fill_string(FILL_RIGHT, string, size, '0'));
     case FIELD_TRIM_FILL_ZERO_LEFT:
       return(fill_string(FILL_LEFT, string, size, '0'));
     case FIELD_TRIM_CENTER:
       return(center_string(string, size));
     case FIELD_TRIM_NO_TRIM:
       break;
     default: break;
  }
  return(FAILURE);
}
Exemple #2
0
        void split_args(const char* args, /*out*/ std::list<std::string>& sargs, char splitter)
        {
            sargs.clear();

            std::string v(args);

            int lastPos = 0;
            while (true)
            {
                auto pos = v.find(splitter, lastPos);
                if (pos != std::string::npos)
                {
                    std::string s = v.substr(lastPos, pos - lastPos);
                    if (s.length() > 0)
                    {
                        std::string s2 = trim_string((char*)s.c_str());
                        if (s2.length() > 0)
                            sargs.push_back(s2);
                    }
                    lastPos = static_cast<int>(pos + 1);
                }
                else
                {
                    std::string s = v.substr(lastPos);
                    if (s.length() > 0)
                    {
                        std::string s2 = trim_string((char*)s.c_str());
                        if (s2.length() > 0)
                            sargs.push_back(s2);
                    }
                    break;
                }
            }
        }
Exemple #3
0
/* For one auto-props config entry (NAME, VALUE), if the filename pattern
   NAME matches BATON->filename case insensitively then add the properties
   listed in VALUE into BATON->properties.
   BATON must point to an auto_props_baton_t.
*/
static svn_boolean_t
auto_props_enumerator(const char *name,
                      const char *value,
                      void *baton,
                      apr_pool_t *pool)
{
  int i;
  auto_props_baton_t *autoprops = baton;
  apr_array_header_t *props;

  /* nothing to do here without a value */
  if (*value == 0)
    return TRUE;

  /* check if filename matches and return if it doesn't */
  if (apr_fnmatch(name, autoprops->filename, APR_FNM_CASE_BLIND) == APR_FNM_NOMATCH)
    return TRUE;

  split_props(&props, value, autoprops->pool);

  for (i = 0; i < props->nelts; i++)
    {
      size_t len;
      const char *this_value;
      char *property = APR_ARRAY_IDX(props, i, char *);
      char *equal_sign = strchr(property, '=');

      if (equal_sign)
        {
          *equal_sign = '\0';
          equal_sign++;
          trim_string(&equal_sign);
          unquote_string(&equal_sign);
          this_value = equal_sign;
        }
      else
        {
          this_value = "";
        }
      trim_string(&property);
      len = strlen(property);

      if (len > 0)
        {
          svn_string_t *propval = apr_palloc(autoprops->pool,
                                             sizeof(*propval));
          propval->data = this_value;
          propval->len = strlen(this_value);

          apr_hash_set(autoprops->properties, property, len, propval);
          if (strcmp(property, SVN_PROP_MIME_TYPE) == 0)
            autoprops->mimetype = this_value;
          else if (strcmp(property, SVN_PROP_EXECUTABLE) == 0)
            autoprops->have_executable = TRUE;
        }
    }
  return TRUE;
}
Exemple #4
0
void test_trim_string() {
	String str = copy_string(" abc ");
	String lstr = copy_string("abc ");
	String rstr = copy_string(" abc");
	String trimed = "abc";
	assert(strcmp(trim_string(str), trimed) == 0);
	assert(strcmp(trim_string(lstr), trimed) == 0);
	assert(strcmp(trim_string(rstr), trimed) == 0);
}
Exemple #5
0
String eval_sys(Mapping *m, Statement *source, Queue *repQueue) {
	String prepare = copy_string(m->sys->prepare);
	String eval = copy_string(m->sys->eval);
	Mapping *mapping = NULL;

	String* array = NULL;
	String* arraySource = NULL;
	String* arrayTarget = NULL;

	String prepareSource;
	String prepareTarget;
	String sourceFuncMacro;
	String sourceMacro;
	String targetFuncMacro;
	String targetMacro;

	if (!equals_string(prepare, "NIL")) {
		mapping = alloc_mapping();
		mapping->sys = NULL;
		if (strcmp(m->sys->name, DEF_MACRO) == 0) {
			mapping->isMacro = TRUE;
		} else {
			mapping->isMacro = FALSE;
		}

		array = split_string_once(prepare, '>');
		prepareSource = array[0];
		prepareTarget = array[1];

		arraySource = split_string_once(prepareSource, ',');
		sourceFuncMacro = trim_string(arraySource[0]);
		sourceMacro = trim_string(arraySource[1]);

		mapping->source = parse_macro(repQueue, sourceMacro);
		mapping->sourceFunc = parse_macro(repQueue, sourceFuncMacro);
		mapping->sourceStatement = parse(mapping->source);
		mapping->starter = to_dfa(mapping->sourceStatement);

		arrayTarget = split_string_once(prepareTarget, ',');
		targetFuncMacro = trim_string(arrayTarget[0]);
		targetMacro = trim_string(arrayTarget[1]);

		mapping->target = parse_macro(repQueue, targetMacro);
		mapping->targetFunc = parse_macro(repQueue, targetFuncMacro);
		mapping->targetStatement = parse(mapping->target);

		//enqueue(get_mappings(), mapping);
		add_mapping_to_trie(mapping);
	}

	if (!equals_string(eval, "NIL")) {
		return parse_macro(repQueue, eval);
	} else {
		return "";
	}
}
Exemple #6
0
/* For one auto-props config entry (NAME, VALUE), if the filename pattern
   NAME matches BATON->filename case insensitively then add the properties
   listed in VALUE into BATON->properties.
   BATON must point to an auto_props_baton_t.
*/
static svn_boolean_t
auto_props_enumerator(const char *name,
                      const char *value,
                      void *baton,
                      apr_pool_t *pool)
{
  auto_props_baton_t *autoprops = baton;
  char *property;
  char *last_token;

  /* nothing to do here without a value */
  if (strlen(value) == 0)
    return TRUE;

  /* check if filename matches and return if it doesn't */
  if (apr_fnmatch(name, autoprops->filename, APR_FNM_CASE_BLIND) == APR_FNM_NOMATCH)
    return TRUE;

  /* parse the value (we dup it first to effectively lose the
     'const', and to avoid messing up the original value) */
  property = apr_pstrdup(autoprops->pool, value);
  property = apr_strtok(property, ";", &last_token);
  while (property)
    {
      int len;
      const char *this_value;
      char *equal_sign = strchr(property, '=');

      if (equal_sign)
        {
          *equal_sign = '\0';
          equal_sign++;
          trim_string(&equal_sign);
          this_value = equal_sign;
        }
      else
        {
          this_value = "";
        }
      trim_string(&property);
      len = strlen(property);
      if (len > 0)
        {
          svn_string_t *propval = svn_string_create(this_value,
                                                    autoprops->pool);

          apr_hash_set(autoprops->properties, property, len, propval);
          if (strcmp(property, SVN_PROP_MIME_TYPE) == 0)
            autoprops->mimetype = this_value;
          else if (strcmp(property, SVN_PROP_EXECUTABLE) == 0)
            autoprops->have_executable = TRUE;
        }
      property = apr_strtok(NULL, ";", &last_token);
    }
  return TRUE;
}
Exemple #7
0
void result::dump_channel(std::ostream &out, const Json::Value &val) const
{
    auto name       = val["name"].asString();
    auto game       = val["game"].asString();
    const auto url  = val["url"].asString();
    
    trim_string(name, _name_len);
    trim_string(game, _game_len);
    
    out << "  " << std::setw(_name_len) << std::left << name
        << "  " << std::setw(_game_len) << std::left << game
        << "  " << url << "\n";
}
Exemple #8
0
bool IniParser::load(const char* filename)
{
	std::ifstream file(filename);
	if (file)
	{
		std::string line;
		Section* section = NULL;
		while (std::getline(file, line))
		{
			// Ignore comments and empty lines
			trim_string(line);
			if (line.size() > 0 && line[0] != TOKEN_COMMENT)
			{
				// Look for sections
				if (line[0] == TOKEN_START_SECTION)
				{
					// Extract section name
					size_t index = line.find(TOKEN_END_SECTION);
					line = line.substr(1, index - 1);
					section = &sections_[line];
				}
				else if (section != NULL)
				{
					size_t index = line.find(TOKEN_SEPARATOR);
					if (index != std::string::npos)
					{
						// Store key:value in the current section
						std::string key = line.substr(0, index);
						trim_string(key);
						std::string value = line.substr(index + 1);
						trim_string(value);
						(*section)[key] = value;
					}
					else
					{
						std::cerr << "[IniParser] line '" << line << "' ignored: missing '" << TOKEN_SEPARATOR << "' token" << std::endl;
					}
				}
				else
				{
					std::cerr << "[IniParser] line '" << line << "' ignored: outside of a section" << std::endl;
				}
			}
		}
		file.close();
		return true;
	}
	std::cerr << "[IniParser] cannot open file: " << filename << std::endl;
	return false;
}
Exemple #9
0
void result::dump_channel_header(std::ostream &out) const
{
    auto name = std::string("Name");
    auto game = std::string("Game");
    
    trim_string(name, _name_len);
    trim_string(game, _game_len);
    
    out << "  " << std::setw(_name_len) << std::left << name
        << "  " << std::setw(_game_len) << std::left << game
        << "  " << "URL\n" 
        << std::setfill('-') << std::setw(_name_len + _game_len + 40)
        << "" << std::setfill(' ') << "\n";
}
Exemple #10
0
void result::dump_top_header(std::ostream &out) const
{
    auto viewers = std::string("Viewers");
    auto channels = std::string("Channels");
    
    trim_string(viewers, _int_len);
    trim_string(channels, _int_len);
    
    out << "  " << std::setw(_int_len) << std::left << viewers
        << "  " << std::setw(_int_len) << std::left << channels
        << "  " << "Game\n"
        << std::setfill('-') << std::setw(2 * _int_len + _game_len)
        << "" << std::setfill(' ') << "\n";
}
Exemple #11
0
static summary_file *parse_driver_tag(char *linestart, int index)
{
	summary_file *curfile;
	char *colon;

	/* find the colon separating name from status */
	colon = strchr(linestart, ':');
	if (colon == NULL)
	{
		fprintf(stderr, "Unexpected text after @@@@@driver=\n");
		return NULL;
	}

	/* NULL terminate at the colon and look up the file */
	*colon = 0;
	curfile = get_file(trim_string(linestart));
	if (curfile == NULL)
	{
		fprintf(stderr, "Unable to allocate memory for driver\n");
		return NULL;
	}

	/* clear out any old status for this file */
	curfile->status[index] = STATUS_NOT_PRESENT;
	if (curfile->text[index] != NULL)
		free(curfile->text[index]);
	curfile->text[index] = NULL;
	curfile->textsize[index] = 0;
	curfile->textalloc[index] = 0;

	/* strip leading/trailing spaces from the status */
	colon = trim_string(colon + 1);

	/* convert status into statistics */
	if (strcmp(colon, "Success") == 0)
		curfile->status[index] = STATUS_SUCCESS;
	else if (strcmp(colon, "Missing files") == 0)
		curfile->status[index] = STATUS_MISSING_FILES;
	else if (strcmp(colon, "Exception") == 0)
		curfile->status[index] = STATUS_EXCEPTION;
	else if (strcmp(colon, "Fatal error") == 0)
		curfile->status[index] = STATUS_FATAL_ERROR;
	else if (strcmp(colon, "Failed validity check") == 0)
		curfile->status[index] = STATUS_FAILED_VALIDITY;
	else
		curfile->status[index] = STATUS_OTHER;

	return curfile;
}
Exemple #12
0
/****************************************************************************
interpret a node status response
****************************************************************************/
static void _interpret_node_status(char *p, char *master,char *rname)
{
  int numnames = CVAL(p,0);
  DEBUG(1,("received %d names\n",numnames));

  if (rname) *rname = 0;
  if (master) *master = 0;

  p += 1;
  while (numnames--)
    {
      char qname[17];
      int type;
      fstring flags;
      int i;
      *flags = 0;
      StrnCpy(qname,p,15);
      type = CVAL(p,15);
      p += 16;

      fstrcat(flags, (p[0] & 0x80) ? "<GROUP> " : "        ");
      if ((p[0] & 0x60) == 0x00) fstrcat(flags,"B ");
      if ((p[0] & 0x60) == 0x20) fstrcat(flags,"P ");
      if ((p[0] & 0x60) == 0x40) fstrcat(flags,"M ");
      if ((p[0] & 0x60) == 0x60) fstrcat(flags,"H ");
      if (p[0] & 0x10) fstrcat(flags,"<DEREGISTERING> ");
      if (p[0] & 0x08) fstrcat(flags,"<CONFLICT> ");
      if (p[0] & 0x04) fstrcat(flags,"<ACTIVE> ");
      if (p[0] & 0x02) fstrcat(flags,"<PERMANENT> ");

      if (master && !*master && type == 0x1d) {
	StrnCpy(master,qname,15);
	trim_string(master,NULL," ");
      }

      if (rname && !*rname && type == 0x20 && !(p[0]&0x80)) {
	StrnCpy(rname,qname,15);
	trim_string(rname,NULL," ");
      }
      
      for (i = strlen( qname) ; --i >= 0 ; ) {
	if (!isprint((int)qname[i])) qname[i] = '.';
      }
      DEBUG(1,("\t%-15s <%02x> - %s\n",qname,type,flags));
      p+=2;
    }
  DEBUG(1,("num_good_sends=%d num_good_receives=%d\n",
	       IVAL(p,20),IVAL(p,24)));
}
Exemple #13
0
/**
 A useful function for returning a path in the Samba lock directory.
**/
char *lpcfg_lock_path(TALLOC_CTX* mem_ctx, struct loadparm_context *lp_ctx,
			 const char *name)
{
	char *fname, *dname;
	if (name == NULL) {
		return NULL;
	}
	if (name[0] == 0 || name[0] == '/' || strstr(name, ":/")) {
		return talloc_strdup(mem_ctx, name);
	}

	dname = talloc_strdup(mem_ctx, lpcfg_lockdir(lp_ctx));
	trim_string(dname,"","/");
	
	if (!directory_exist(dname)) {
		if (!mkdir(dname,0755))
			DEBUG(1, ("Unable to create directory %s for file %s. "
			      "Error was %s\n", dname, name, strerror(errno)));
	}
	
	fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name);

	talloc_free(dname);

	return fname;
}
// ---------------------------------------------------------------------------
void play_playlist(char* player, char* file) {
	char buffer[512];
	char* line;
	
	FILE* f = fopen(file, "r");
	if(f == NULL) return;
	
	while(fgets(buffer, 512, f) != NULL && !stop) {
		line = buffer;
		line = trim_string(line);
		if(line[0] == '#') continue; // skip comments and meta information
		// otherwise, check if it is an mp3 and if yes, play it
		if(is_mp3(line)) {
		    char abs_path[256];  
		    // if relative path, add root path
		    if(line[0] == '/') strcpy(abs_path, line);
		    else {
		     strcpy(abs_path, root_path);
		     strcat(abs_path, "/");
		     strcat(abs_path, line);
		    }
		    start_player(player, abs_path);
		} else {
		    //printf("no mp3: %s\n", line);
		}
	}
	
	fclose(f);
}
Exemple #15
0
void Lexer::setToken()
{
  std::string tmp;
  std::size_t pos = 0, begin = 0;
  std::string::iterator end;
  std::string::size_type comment_start;
  std::string::size_type newline;

  std::replace(_string.begin(), _string.end(), '\t', ' ');
  _string += "exit";
  _string = trim_comments(_string);
  _string = trim_string(_string);

  for (std::string::iterator it = _string.begin() ; it + pos != _string.end() ; ++it)
    {
      if ((int)(pos = myMin(_string.find('\n', pos), _string.find(' ', pos))) == -1)
	{
	  _token.push_back("exit");
	  return;
	}
      tmp = _string.substr(begin, pos-begin);
      pos++;
      begin = pos;
      _token.push_back(tmp);
    }
}
Exemple #16
0
int Http_Response_Package::prase_package(std::string package)
{
	m_line.clear();
	m_fields.clear();
	StrVec fields;
	split_string(package,fields,"\r\n");
	if (fields.size()>1)
	{
		m_line=fields[0];
	}

	for (unsigned int i=1;i<fields.size(); i++ )
	{
		int colon_pos=fields[i].find(':');
		std::string key=fields[i].substr(0,colon_pos);
		std::string value=fields[i].substr(colon_pos+1);
		value=trim_string(value," ");
		if ( m_fields.find(key)==m_fields.end() )
		{
			m_fields[key]=value;
		}
		else
		{
			m_fields[key]+=";"+value;
		}
	}
	return 0;
}
Exemple #17
0
static char *lpcfg_common_path(TALLOC_CTX* mem_ctx,
			       const char *parent,
			       const char *name)
{
	char *fname, *dname;
	bool ok;

	if (name == NULL) {
		return NULL;
	}
	if (name[0] == 0 || name[0] == '/' || strstr(name, ":/")) {
		return talloc_strdup(mem_ctx, name);
	}

	dname = talloc_strdup(mem_ctx, parent);
	if (dname == NULL) {
		return NULL;
	}
	trim_string(dname,"","/");

	ok = directory_create_or_exist(dname, geteuid(), 0755);
	if (!ok) {
		DEBUG(1, ("Unable to create directory %s for file %s. "
			  "Error was %s\n", dname, name, strerror(errno)));
		return NULL;
	}

	fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name);
	if (fname == NULL) {
		return dname;
	}
	talloc_free(dname);

	return fname;
}
Exemple #18
0
/*  Calls trim_string to remove blank space;
    Removes paired punctuation delimiters from
    beginning and end of string. If the same punctuation 
    appears first and last (quotes, slashes) they are trimmed;
    Also checks for the following pairs: () <> {} [] */
static inline char *
trim_note( char *in )
{
	int len;
	char *note, start, end;

	note = trim_string( in );
	if ( note != NULL ) {
                len = ( int ) strlen( note );
		if ( len > 0 ) {
			if ( ispunct( *note ) ) {
				start = *note;
				end = note[len - 1];
				if ( ( start == end )
					 || ( ( start == '(' ) && ( end == ')' ) )
					 || ( ( start == '<' ) && ( end == '>' ) )
					 || ( ( start == '{' ) && ( end == '}' ) )
					 || ( ( start == '[' ) && ( end == ']' ) ) ) {
					note[len - 1] = '\0';
					*note = '\0';
					note++;
				}
			}
		}
	}
	return note;
}
static int login_with_md5(char* user_name, char* md5, char* result, int len) {
	CURL* curl;
	int i, slen;

	char url[1024];
	char post_data[2048];
	char all_value[1024];

	sprintf(url,"http://net.tsinghua.edu.cn/cgi-bin/do_login");
	sprintf(post_data, "username=%s&password=%s&drop=0&type=1&n=100", user_name, md5);

	/*
	printf("POST DATA : %s\n", post_data);
	*/
	if(post_data_to(url,post_data,all_value) != 0)
		return -1;

	trim_string(all_value);

	strncpy(result,all_value,len);
	
	if(result[0] <= '9' && result[0] >= '0')
		return 0;
	else
		return 1;
}
Exemple #20
0
int
pfq_set_group_computation_from_string(pfq_t *q, int gid, const char *comp)
{
	int do_set_group_computation(char **fun, int n)
	{
		int i = 0, j, ret;

                struct pfq_computation_descr * prog = malloc(sizeof(size_t) * 2 +
							     sizeof(struct pfq_functional_descr) * n);
		if (!prog)
			return Q_ERROR(q, "PFQ: group computation error (no memory)");

		prog->entry_point = 0;
		prog->size = n;

		for(i = 0; i < n; i++)
		{
			prog->fun[i].symbol = trim_string(fun[i]);
			prog->fun[i].next = i+1;

			for (j = 0; j < 8; j++)
			{
				prog->fun[i].arg[j].addr  = NULL;
				prog->fun[i].arg[j].size  = 0;
				prog->fun[i].arg[j].nelem = 0;
			}

		}

		ret = pfq_set_group_computation(q, gid, prog);

		free(prog);

		return ret;
	}
Exemple #21
0
int segment_words(const char * content,enum wtype type,int len,bool stepword,vector<funit>& features)
{
	if(!content || len <= 0){
		UB_LOG_WARNING("segment words,parameter error");
		return -1;
	}

    /*get word segment result buffer*/
    thread_data * tsd = (thread_data *)pthread_getspecific(key);
    if(!tsd){
        UB_LOG_FATAL("thread special data is null");
        exit(0);
    }
    scw_out_t *pout = tsd->pout;

	/*word segment*/
	if(scw_segment_words(pwdict,pout,content,len,LANGTYPE_SIMP_CHINESE,NULL) == -1){
		UB_LOG_WARNING("scw segment words failed");
		return -1;
	}

	/*get result to vectore features*/
	int i,count;
	token_t tokens[1024];
	funit tmp;
    
    /*word type,we just need SCW_OUT_WPCOMP*/
	u_int tsco[5] = {SCW_OUT_WPCOMP,SCW_OUT_BASIC,SCW_OUT_SUBPH,
		SCW_OUT_HUMANNAME,SCW_OUT_BOOKNAME};
    
	/*just SCW_OUT_WPCOMP mode,so j < 1*/
	for(int j = 0;j < 1;j ++)
	{
		count = scw_get_token_1(pout,tsco[j],tokens,1024);
		for(i = 0;i < count;i ++)
		{
			/*filter space and special punc*/
			trim_string(tokens[i].buffer);
			if(strlen(tokens[i].buffer) <= 1)
				continue;
            
            tmp.feature = tokens[i].buffer;
			tmp.weight = 1;
			features.push_back(tmp);
		}
	}

    /*get weight*/
    feature_weight(features,type);

	/*output result for debug*/
	for(i = 0;i < (int)features.size();i++)
	{
		tmp = features.at(i);
		UB_LOG_DEBUG("word[%s] weight[%f]",tmp.feature.c_str(),tmp.weight);
	}

	return 0;
}
Exemple #22
0
int main() {

    char *temp = "   I struggle with strings in C.\n";
    trim_string(temp);
    printf("%s", temp);

    return 0;
}
Exemple #23
0
void result::dump_stream(std::ostream &out, const Json::Value &val) const
{
    const auto channel = val["channel"];
    
    auto name           = channel["name"].asString();
    const auto url      = channel["url"].asString();
    const auto viewers  = val["viewers"].asInt();
    auto game           = val["game"].asString();
    
    trim_string(name, _name_len);
    trim_string(game, _game_len);
    
    out << "  " << std::setw(_int_len)  << std::right << viewers
        << "  " << std::setw(_name_len) << std::left  << name
        << "  " << std::setw(_game_len) << std::left << game
        << "  " << url << "\n";
}
Exemple #24
0
int parse_one_parameter ( char *buffer)
{
     char name[MAXPARAMLINELENGTH+1];
     char data[MAXPARAMLINELENGTH+1];
     int i, j, k, l;
     int n, d;

     k = -1;
     j = 0;
     l = strlen ( buffer );
     /** scan for a equals sign. **/
     for ( i = 0; i < l; ++i )
     {
	  /* j records whether or not we have found a nonwhitespace
	    character. */
	  j += (buffer[i] != ' ' && buffer[i] != '\t' && buffer[i] != '\n');
	  if ( buffer[i] == '=' )
	  {
	       k = i;
	       /* copy the name part. */
	       strncpy ( name, buffer, k );
	       name[k] = 0;
	       /* copy the value part. */
	       strcpy ( data, buffer+k+1 );
	       break;
	  }
     }

     /* if we found no '=', return an error unless the line was
	completely blank. */
     if ( k == -1 )
	  return !!j;

     /* trim leading and trailing whitespace. */
     n = trim_string ( name );
     d = trim_string ( data );

     /** if either section is blank, return an error, otherwise add
       the pair as a parameter. **/
     if ( n == 0 || d == 0 )
	  return 1;
     else
	  add_parameter ( name, data, PARAM_COPY_NAME|PARAM_COPY_VALUE );
     return 0;
}
/****************************************************************************
Build the print command in the supplied buffer. This means getting the
print command for the service and inserting the printer name and the
print file name. Return NULL on error, else the passed buffer pointer.
****************************************************************************/
static char *build_print_command(int cnum, char *command, char *syscmd, char *filename1)
{
  int snum = SNUM(cnum);
  char *tstr;
  pstring filename;
  
  /* get the print command for the service. */
  tstr = command;
  if (!syscmd || !tstr) {
    DEBUG(0,("No print command for service `%s'\n", SERVICE(snum)));
    return (NULL);
  }

  /* copy the command into the buffer for extensive meddling. */
  StrnCpy(syscmd, tstr, sizeof(pstring) - 1);
  
  /* look for "%s" in the string. If there is no %s, we cannot print. */   
  if (!strstr(syscmd, "%s") && !strstr(syscmd, "%f")) {
    DEBUG(2,("WARNING! No placeholder for the filename in the print command for service %s!\n", SERVICE(snum)));
  }
  
  if (strstr(syscmd,"%s")) {
    int iOffset = PTR_DIFF(strstr(syscmd, "%s"),syscmd);
    
    /* construct the full path for the filename, shouldn't be necessary unless
       the subshell causes a "cd" to be executed.
       Only use the full path if there isn't a / preceding the %s */
    if (iOffset==0 || syscmd[iOffset-1] != '/') {
      StrnCpy(filename,Connections[cnum].connectpath,sizeof(filename)-1);
      trim_string(filename,"","/");
      pstrcat(filename,"/");
      pstrcat(filename,filename1);
    }
    else
      pstrcpy(filename,filename1);
    
    string_sub(syscmd, "%s", filename);
  }
  
  string_sub(syscmd, "%f", filename1);
  
  /* Does the service have a printername? If not, make a fake and empty    */
  /* printer name. That way a %p is treated sanely if no printer */
  /* name was specified to replace it. This eventuality is logged.         */
  tstr = PRINTERNAME(snum);
  if (tstr == NULL || tstr[0] == '\0') {
    DEBUG(3,( "No printer name - using %s.\n", SERVICE(snum)));
    tstr = SERVICE(snum);
  }
  
  string_sub(syscmd, "%p", tstr);
  
  standard_sub(cnum,syscmd);
  
  return (syscmd);
}
string RecordedSentence::get_sentence_content() {
    if (sentence_content.length() == 0) {
        sentence_content = "";
        for (int i = 0; i < (int) phrases.size(); ++i) {
            sentence_content = sentence_content + " " + phrases[i].get_phrase_content();
        }
        trim_string(sentence_content);
    }
    return sentence_content;
}
Exemple #27
0
void result::dump_stream_header(std::ostream &out) const
{
    auto line_len = _int_len + _name_len + _game_len;
    
    auto viewers = std::string("Viewers");
    auto name = std::string("Name");
    auto game = std::string("Game");
    
    trim_string(viewers, _int_len);
    trim_string(name, _name_len);
    trim_string(game, _game_len);
    
    out << "  " << std::setw(_int_len)  << std::left << viewers
        << "  " << std::setw(_name_len) << std::left << name
        << "  " << std::setw(_game_len) << std::left << game
        << "  " << "URL\n"
        << std::setfill('-') << std::setw(line_len)
        << "" << std::setfill(' ') << "\n";
}
Exemple #28
0
char* get_value(char* buff)
{
  char *buff2 = strdup(buff);
   char* prop = strtok(buff2, CONF_SYMBOL);
  strtok(buff2, "=");
  char* value = strtok(NULL,CONF_SYMBOL);
  char value2[200];
  strncpy(value2, value, 200);
  return trim_string(value);
}
Exemple #29
0
int get_count(char* buff, FILE* fp, int *line_size)
{
  char* str = trim_string(buff);
  char* line = NULL;
  size_t len;
  size_t read;
  int count=0;
  while((read=getline(&line, &len, fp))!=-1)
    {
      count += strlen(line);
      if (strcmp(trim_string(get_prop(line)), str)==0)
	{
	  *line_size = count;
	  count = count-strlen(line)+strlen(str);
	  break;
	}
    }
  return count;
}
Exemple #30
0
static int
istgt_uctl_cmd_execute(UCTL_Ptr uctl)
{
	int (*func) (UCTL_Ptr);
	const char *delim = ARGS_DELIM;
	char *arg;
	char *cmd;
	int rc;
	int i;

	arg = trim_string(uctl->recvbuf);
	cmd = strsepq(&arg, delim);
	uctl->arg = arg;
	uctl->cmd = strupr(cmd);

	func = NULL;
	for (i = 0; istgt_uctl_cmd_table[i].name != NULL; i++) {
		if (cmd[0] == istgt_uctl_cmd_table[i].name[0]
		    && strcmp(cmd, istgt_uctl_cmd_table[i].name) == 0) {
			func = istgt_uctl_cmd_table[i].func;
			break;
		}
	}
	if (func == NULL) {
		istgt_uctl_snprintf(uctl, "ERR unknown command\n");
		rc = istgt_uctl_writeline(uctl);
		if (rc != UCTL_CMD_OK) {
			return UCTL_CMD_DISCON;
		}
		return UCTL_CMD_ERR;
	}

	if (uctl->no_auth
	    && (strcasecmp(cmd, "AUTH") == 0)) {
		istgt_uctl_snprintf(uctl, "ERR auth not required\n");
		rc = istgt_uctl_writeline(uctl);
		if (rc != UCTL_CMD_OK) {
			return UCTL_CMD_DISCON;
		}
		return UCTL_CMD_ERR;
	}
	if (uctl->req_auth && uctl->authenticated == 0
	    && !(strcasecmp(cmd, "QUIT") == 0
		|| strcasecmp(cmd, "AUTH") == 0)) {
		istgt_uctl_snprintf(uctl, "ERR auth required\n");
		rc = istgt_uctl_writeline(uctl);
		if (rc != UCTL_CMD_OK) {
			return UCTL_CMD_DISCON;
		}
		return UCTL_CMD_ERR;
	}

	rc = func(uctl);
	return rc;
}