Exemplo n.º 1
1
//--------------------------------------------------------------
void testApp::sendRequest() {
	ofxHttpForm form;
	form.action = action_url;
	form.method = OFX_HTTP_POST;
	
	time_t t;
	time(&t);
	char gmttime[256];
	strftime(gmttime, 255, "%Y´/%m´/%d´/%H´/%I´/%S", gmtime(&t));
	string timestr = gmttime;
	timestr = str_replace(timestr, "´", "");			
	
	form.addFormField("time", timestr);
	httpUtils.addForm(form);	
}
Exemplo n.º 2
0
/**
 * Detect charset from locale. If it's not possible due to missing
 * nl_langinfo(), use @c iso-8859-1.
 * @return Charset
 */
static const char* get_charset() {
#ifdef LIBMUTTNG_HAVE_LANGINFO_CODESET
  buffer_t tmp;
  buffer_init(&tmp);
  buffer_add_str(&tmp,nl_langinfo(CODESET),-1);
  conv_charset_normal(&tmp);
  if (tmp.len)
    str_replace(&Charset,tmp.str);
  buffer_free(&tmp);
#else
  Charset = str_dup("iso-8859-1");
#endif
  intl_encoding(Charset);
  return (const char*)Charset;
}
Exemplo n.º 3
0
int main()
{

	int a[] = {1,3,4,5,7,7,3,5,7,4,4,2,3,7};
	char b[] = "hello world";


	printf("%d\n",*arr_first_max(a, 14));
	printf("%d\n", *arr_last_max(a, 14));
	printf("%ld\n", str_replace(b, 'l', 'x'));
	printf("%c\n", *str_find_last(b, 'e'));
	
	getchar();
    return 0;
}
Exemplo n.º 4
0
static char *
_get_groupchat_log_filename(const char * const room, const char * const login,
    GDateTime *dt, gboolean create)
{
    gchar *chatlogs_dir = _get_chatlog_dir();
    GString *log_file = g_string_new(chatlogs_dir);
    g_free(chatlogs_dir);

    gchar *login_dir = str_replace(login, "@", "_at_");
    g_string_append_printf(log_file, "/%s", login_dir);
    if (create) {
        create_dir(log_file->str);
    }
    free(login_dir);

    g_string_append(log_file, "/rooms");
    if (create) {
        create_dir(log_file->str);
    }

    gchar *room_file = str_replace(room, "@", "_at_");
    g_string_append_printf(log_file, "/%s", room_file);
    if (create) {
        create_dir(log_file->str);
    }
    free(room_file);

    gchar *date = g_date_time_format(dt, "/%Y_%m_%d.log");
    g_string_append(log_file, date);
    g_free(date);

    char *result = strdup(log_file->str);
    g_string_free(log_file, TRUE);

    return result;
}
Exemplo n.º 5
0
//----------------------------------------------------
static char *selectSQL(t_object *o)
{
  t_table *tt = o->ds;
  int size=0,i=0;
  char *sql, str_where[MAX_WHERE_SQL],fields[MAX_SQL];

  sql = (char*)malloc(MAX_SQL*sizeof(char));
  //blanquear cadenas
  memset(sql, '\0',MAX_SQL);
  memset(fields, '\0',MAX_SQL);
  
  //ver si hay criterio para agregar 
  strcpy(sql,SQL_STR);
  //recorrer cada nombre de columna(armar listado de campos)
  for(i=0;i<tt->cant_columns;++i)
  {
     strcat(fields , ((t_column *)tt->columns)[i].nombre);
     strcat(fields,(i<tt->cant_columns-1)?",":"");
  }
  //reemplazar listado de campos y nombre de tabla.
  strcpy(sql ,(char*) str_replace(sql,TOK1,fields));  
  strcpy(sql ,(char*)str_replace(sql,TOK2,tt->nombre));
  return sql;
}
Exemplo n.º 6
0
void replace_double_space_with_single(char *str)
{
    const char *match;
    char *ret;
    do 
    {
        ret = str_replace(str, "  ", " ");
        if (ret)
        {
            strcpy(str, ret);
            free(ret);
        }
        match = strstr(str, "  ");
    } 
    while (match != 0);
}
Exemplo n.º 7
0
char	*cut_empty_lin(char *s)
{
	int		i;
	char	*s2;

	s2 = "....\n\0";
	i = 0;
	while (s[i])
	{
		if (ft_strnequ(s + i, s2, 4) == 1)
			str_replace(s + i, "\n\n\n\n");
		i++;
	}
	s = src_emptycol(s);
	return (s);
}
Exemplo n.º 8
0
int find_host_port(session *sess)
{
	int ret, start, end, temp_len;
	st_str *str_search;
	st_str *new_str = NULL, *org = NULL;
	if (sess == NULL || sess->p_read == NULL)
	{
		return -1;
	}
	str_search = sess->p_read;
	ret = strncasecmp(str_search->p, STR_HOST, strlen(STR_HOST));
	printf("start find\n");
	if (ret != 0)
	{
		start = kmp(str_search->p, str_search->cur_use_size, kmp_table[KMP_HOST]);
		LOGD("kmp start find:%d\n", start);
		if (start == -1)
		{
			return -1;
		}
		start += kmp_table[KMP_HOST]->length;
		end = kmp(str_search->p + start, str_search->cur_use_size - start, kmp_table[KMP_ENTER]);
		LOGW("kmp end find:%d\n", end);
		str_nassign(&(sess->host), str_search->p + start, end);
		sess_get_port(sess);
		str_delete_space(sess->host);
		LOGD("%s\n", sess->host->p);
		LOGD("%s:%d\n", sess->host_port->p, atoi(sess->host_port->p));
		
		str_assign(&org, "http://");
		str_nadd(&org, sess->host->p, sess->host->cur_use_size);
		end = kmp(str_search->p, str_search->cur_use_size, kmp_table[KMP_ENTER]);
		
		temp_len = str_search->cur_use_size;
		str_search->cur_use_size = end;
		new_str = str_replace(str_search, org->p, org->cur_use_size, "", 0);
		
		str_nadd(&new_str, str_search->p + end, temp_len - end);
		LOGD("%s\n", new_str->p);
		
		sess->p_read = new_str;
		str_free(str_search);
		str_free(org);
	}
	printf("end find\n");
	return 0;
}
Exemplo n.º 9
0
int main(void)
{
	int i = 0;
	char s[MAX] = { 0 };        //存放源字串
	char s1[MAX] = { 0 };        //存放子字串
	char s2[MAX] = { 0 };        //存放替换字串
	char result_a[2000] = { 0 };//存放替换结果;
	puts("Please input the string for s:");
	gets_s(s,MAX);
	puts("Please input the string for s1:");
	gets_s(s1, MAX);
	puts("Please input the string for s2:");
	gets_s(s2, MAX);
	i = str_replace(result_a, s, s1, s2);
	printf("替换%d个子字符串;\r\n", i);
	printf("替换后结果:%s\r\n", result_a);
}
Exemplo n.º 10
0
int ImageIDer::Query(const std::string& path) const
{
	std::string path_fixed = path.substr(0, path.find_last_of('.'));
	str_replace(path_fixed, "/", "\\");

	std::map<std::string, int>::const_iterator itr = m_ids.find(path_fixed);
	if (itr == m_ids.end()) {
		std::map<std::string, int>::const_iterator itr = m_ids.begin();
		for ( ; itr != m_ids.end(); ++itr) {
			if (itr->first.find(path_fixed) != std::string::npos) {
				return itr->second;
			}
		}
		throw Exception("Cannot find image %s\n", path);
	}
	return itr->second;
}
Exemplo n.º 11
0
//增加记录
void lottery_event::addLotteryNotice(const std::string& name, Item& item)
{
    std::string what = m_strLotteryGet;
    str_replace(what, "$W", item.toString(true));

    json_spirit::Array& notice_array = m_notices_value.get_array();
    json_spirit::Object obj;
    obj.push_back( Pair("name", name) );
    obj.push_back( Pair("get", what) );
    notice_array.push_back(obj);
    while ((int)notice_array.size() > 20)
    {
        notice_array.erase(notice_array.begin());
    }
    need_save = true;
    Save();
}
Exemplo n.º 12
0
int
api_cons_show_themed(const char *const group, const char *const key, const char *const def, const char *const message)
{
    if (message == NULL) {
        log_warning("%s", "prof_cons_show_themed failed, message is NULL");
        return 0;
    }

    char *parsed = str_replace(message, "\r\n", "\n");
    theme_item_t themeitem = plugin_themes_get(group, key, def);
    ProfWin *console = wins_get_console();
    win_println(console, themeitem, '-', "%s", parsed);

    free(parsed);

    return 1;
}
Exemplo n.º 13
0
char* mylib_find_and_replace(const char *string1, FILE* file1, char* change){
	char* string3 = (char*)malloc(10*sizeof(char));
	char* string = (char*)malloc(10*sizeof(char));
	long int  start, length;
	int i=0;
	fseek(file1, 0, SEEK_SET);
	while(fgets(string, 10, file1)!=NULL){
		string[strlen(string)-1] = '\0';
		start = str_istr(string1, string);
		if(start>=0){
			length = strlen(string);
			string = str_replace(string1, start, length, change);
			return string;
		}
		else i++;
	}
	return "";
}
Exemplo n.º 14
0
static int get_field_text (char *field, char **entry,
                           char *type, char *filename, int line)
{
  field = str_skip_initws (field);
  if (*field == '=') {
    if (entry) {
      field++;
      field = str_skip_initws (field);
      str_replace (entry, field);
    }
    return 1;
  }
  else {
    mutt_error (_("Improperly formated entry for type %s in \"%s\" line %d"),
                type, filename, line);
    return 0;
  }
}
Exemplo n.º 15
0
int b_route(int fd, int pv, int argc, char *argv[]) {
    if (argc > 1) {
        argv[1] = str_replace(argv[1], "'", "");
    }

    FILE *fp;
    char out[2048];
    char *command = malloc(100);

    if (pv == 4) {
        if (argc > 1) {
            snprintf(command, 100, "/usr/sbin/birdc -r show route for '%s' all 2>&1", argv[1]);
        } else {
            strcpy(command, "/usr/sbin/birdc -r show route stats");
        }
    } else {
        if (argc > 1) {
            snprintf(command, 100, "/usr/sbin/birdc6 -r show route for '%s' all 2>&1", argv[1]);
        } else {
            strcpy(command, "/usr/sbin/birdc6 -r show route stats");
        }
    }

    fp = popen(command, "r");
    if (fp == NULL) {
        free(command);
        return 3;
    }
    free(command);

    while (fgets(out, sizeof(out), fp) != NULL) {
        if (
            (strstr(out, "BIRD") == NULL) &&
            (strstr(out, "Access restricted") == NULL)
        ) {
            write(fd, out, strlen(out));
        }
    }

    pclose(fp);

    return 0;
}
template<typename T> bool SkRTConfRegistry::parse(const char *name, T* value) {
    SkString *str = NULL;

    for (int i = fConfigFileKeys.count() - 1 ; i >= 0; i--) {
        if (fConfigFileKeys[i]->equals(name)) {
            str = fConfigFileValues[i];
            break;
        }
    }

    SkString environment_variable("skia.");
    environment_variable.append(name);

    const char *environment_value = getenv(environment_variable.c_str());
    if (environment_value) {
        str->set(environment_value);
    } else {
        // apparently my shell doesn't let me have environment variables that
        // have periods in them, so also let the user substitute underscores.
        SkString underscore_environment_variable("skia_");
        char *underscore_name = SkStrDup(name);
        str_replace(underscore_name,'.','_');
        underscore_environment_variable.append(underscore_name);
        sk_free(underscore_name);
        environment_value = getenv(underscore_environment_variable.c_str());
        if (environment_value) {
            str->set(environment_value);
        }
    }

    if (!str) {
        return false;
    }

    bool success;
    T new_value = doParse<T>(str->c_str(),&success);
    if (success) {
        *value = new_value;
    } else {
        SkDebugf("WARNING: Couldn't parse value \'%s\' for variable \'%s\'\n", str->c_str(), name);
    }
    return success;
}
Exemplo n.º 17
0
// *Close the file-data* //
void FileClose( FILE * fp )
{
    FILE_DATA              *filedata,
                           *filedata_next;
    char                    new_fname[MIL];
    char                    old_fname[MIL];

    new_fname[0] = '\0';

    if ( !fp )
        return;

    for ( filedata = first_filedata; filedata; filedata = filedata_next ) {
        filedata_next = filedata->next;

        if ( filedata->fp == fp ) {
            if ( !str_suffix( ".temporary", filedata->filename ) ) {
                snprintf( old_fname, MIL, "%s", filedata->filename );
                snprintf( new_fname, MIL, "%s", filedata->filename );
                str_replace( ".temporary", "", new_fname );
            }
            free_filedata( filedata );
            break;
        }
    }

    fclose( fp );
    fp = NULL;
    FilesOpen--;

    if ( FilesOpen < 0 ) {
        FilesOpen = 0;
        log_string( "FileClose passed a null fp somewhere and schewed the list." );
    }

    if ( new_fname[0] != '\0' ) {
        if ( rename( old_fname, new_fname ) ) {
            log_printf( "FileClose: Problem with renaming %s to %s", old_fname, new_fname );
            return;
        }
    }
}
Exemplo n.º 18
0
void ImageIDer::Load(const std::string& filepath)
{
	std::string dir = get_file_dir(filepath);

	std::locale::global(std::locale(""));
	std::ifstream fin(filepath.c_str());
	std::locale::global(std::locale("C"));
	std::string line;
	int id = 1;
	while (std::getline(fin, line)) {
		std::string path = dir + "\\" + line;
		std::string key = path.substr(0, path.find_last_of('.'));

//		str_replace(key, "\\", "/");
		str_replace(key, "/", "\\");

		m_ids.insert(std::make_pair(key, id++));
	}
	fin.close();
}
Exemplo n.º 19
0
inline void PrintPrompt() {

    // eg, lustig
    char *user = getenv("USER");

    // eg, linprog4
    char *host = getenv("HOST");

    // eg, /home/majors/lustig
    char *home = getenv("HOME");

    char cwd[1024];
    getcwd(cwd, sizeof(cwd));

    // replace any occurrences of user's home directory with ~
    strncpy(cwd, str_replace(cwd, home, "~"), sizeof(cwd));

    // ie, lustig@linprog ~/stuff BASH_CHAR
    printf("%s@%s %s %c ", user, host, cwd, BASH_CHAR);
}
Exemplo n.º 20
0
void GMemory::exportAllRecords(string&tableName,string path) {
    path+="/";
    path=str_replace("//", "/", path);
    tableRecord &rec=table[tableName];
    if(!rec.status)loadTable(tableName);  //if table not exsist, create it
    GVector*dict=rec.data;
    for(int n=0; n<dict->size(); n++) {
        TString st;
        dict->getTStr(n,&st);
        string res;
        string fileName=path+st[0]+".txt";
        if(!st.size())continue;
        for(int n=0; n<st.size(); n++) {
            string s=st[n];
            res+=s+"\n";
        }
        writeText(res, fileName.c_str());
    }

};
Exemplo n.º 21
0
struct data *str_replace_op(struct data *src,struct data *what,struct data *by){
 
  struct data *ptr = (struct data *) NULL;

  char src_buf[BUFFER];
  char what_buf[BUFFER];
  char by_buf[BUFFER];
  char *src_ptr = src_buf;
  char *by_ptr = by_buf;
  char *what_ptr = what_buf;
  int src_flag = 0;

  if (str_convert(src,src_ptr) ) {

    src_ptr = strdup(src->STR_VALUE);

    src_flag = 1;

  }

  if (str_convert(what,what_ptr) )
   
    what_ptr = what->STR_VALUE;

  if (str_convert(by,by_ptr) )

    by_ptr = by->STR_VALUE ;

  str_replace(src_ptr,what_ptr,by_ptr); 

  ptr = MALLOC_DATA;
  ptr->ele_type = _STR;
  ptr->STR_PTR = INSTALL_STRING(src_ptr);
 
  if (src_flag) 

    free((void*) src_ptr);

  return ptr;

}
Exemplo n.º 22
0
void vsx_widget_base_edit::set_string(const vsx_string& str) {
  lines.clear();
  vsx_string deli = "\n";
  vsx_string f = str_replace("\r","",str);
  explode(f, deli, lines);
  lines_visible.clear();
  for (unsigned long i = 0; i < lines.size(); i++) lines_visible.push_back(0);
  longest_line = 0;
  scrollbar_pos_x = 0;
  scrollbar_pos_y = 0;
  for (std::vector<vsx_string>::iterator it = lines.begin(); it != lines.end(); ++it) {
    if ((*it).size() > longest_line) longest_line = (*it).size();
  }
  // hide eventual action buttons
  for (size_t i = 0; i < action_buttons.size(); i++)
  {
    action_buttons[i]->visible = 0.0f;
  }
  process_lines();
  calculate_scroll_size();
}
Exemplo n.º 23
0
// custom callback function to exec on each match
void pcre_match_callback(PCRE_CONTAINER *pcre_info)
{
  // get_named_substring if it exists
  if(pcre_info->namecount > 0)
  {
    const char *matched_substring = NULL;

    if((fetch_named_substring(pcre_info->named_substring, pcre_info, &matched_substring)) >= 0)
    {
      char *ret = NULL;
      if((ret=str_replace("\\u0026#39;","\'",(char*)matched_substring)))
      {
        printf("substring match for %s: %s\n",pcre_info->named_substring,ret);
        free(ret);
      } else {
        printf("substring match for %s: %s\n",pcre_info->named_substring,matched_substring);
      }
      pcre_free_substring(matched_substring);
    }
  }
}
Exemplo n.º 24
0
p_val punt_srepl(p_val *args, p_var **vars) {
  p_val rval;
    rval.type = "str";
    rval.val = (void *)"";

  if(val_llen(args) != 3) {
    fprintf(stderr, "sfind: 3 args required\n");
    exit(1);
  }
  int i;
  for(i = 0; i < val_llen(args); i++) {
    if(strcmp(args[i].type, "str")) {
      fprintf(stderr, "sfind: all args must be strings\n");
      exit(1);
    }
  }

  rval.val = (void *)str_replace((char *)args[0].val, (char *)args[1].val, (char *)args[2].val, 0);

  return rval;
}
Exemplo n.º 25
0
int CmdZshCompletionUuids::execute (std::string& output)
{
    // Apply filter.
    handleRecurrence ();
    std::vector <Task> filtered;
    filter (filtered);
    context.tdb2.commit ();

    std::stringstream out;
    std::vector <Task>::iterator task;
    for (task = filtered.begin (); task != filtered.end (); ++task)
        out << task->get ("uuid")
            << ":"
            << str_replace (task->get ("description"), ":", zshColonReplacement)
            << "\n";

    output = out.str ();

    context.headers.clear ();
    return 0;
}
Exemplo n.º 26
0
gchar *
get_xdg_var (gboolean user, XdgDir dir)
{
    XdgVar const *vars = user ? xdg_user : xdg_system;
    XdgVar xdg = vars[dir];

    const gchar *actual_value = getenv (xdg.environment);

    if (!actual_value || !actual_value[0]) {
        actual_value = xdg.default_value;
    }

    if (!actual_value) {
        return NULL;
    }

    /* TODO: Handle home == NULL. */
    const gchar *home = getenv ("HOME");

    return str_replace("~", home, actual_value);
}
Exemplo n.º 27
0
int mshell_parser_oneline(const struct mshell *mshell, struct cmd *cmd)
{
	int offset = 0;
	unsigned char *out, *tmp;
	int i = 0;

	for(i=0; i<ARRAY_SIZE(cmd->cmd); i++) {
		if(cmd->cmd[i] != NULL) {
			free(cmd->cmd[i]);
			cmd->cmd[i] = NULL;
		} else {
			i = 0;
			break;
		}
	}

	cmd->offset = 0; /*init offset*/

	/*parser command*/
	do {
		parser_one_block(mshell->oneline, &offset, &out);
		//printf("out: offset = %d, %s\n", offset, out);
		//fflush(stdout);
		
		//if(out != NULL) {
		//	free(out);
		//}
		if(out != NULL) {
			tmp = out;
			str_replace(&out, tmp, "~", mshell->user->pw_dir);
			free(tmp);
			//printf("%s\n", out);
		}
		cmd->cmd[i++] = out;
		cmd->max = i;
	} while(out != NULL);

	/*TODO: parser arg*/
	return 0;
}
Exemplo n.º 28
0
Arquivo: rule.cpp Projeto: Sebi55/GPC
std::string Rule::toString(EntryPathBilder const& pathBuilder){
	std::string result = isVisible ? "+" : "-";
	if (dataSource)
		result += pathBuilder.buildPathString(*dataSource, this->type == OTHER_ENTRIES_PLACEHOLDER);
	else if (type == OTHER_ENTRIES_PLACEHOLDER)
		result += "*"; 
	else
		result += "???";
	if (type == NORMAL && (dataSource && dataSource->name != outputName))
		result += " as '"+str_replace("'", "''", outputName)+"'";

	if (this->subRules.size() > 0) {
		result += "{";
		for (std::list<Rule>::iterator iter = this->subRules.begin(); iter != this->subRules.end(); iter++) {
			if (iter != this->subRules.begin())
				result += ", ";
			result += iter->toString(pathBuilder);
		}
		result += "}";
	}
	return result;
}
Exemplo n.º 29
0
int q_route(int fd, int pv, int argc, char *argv[]) {
    if (argc > 1) {
        argv[1] = str_replace(argv[1], "'", "");
    }

    FILE *fp;
    char out[2048];
    char *command = malloc(100);

    if (pv == 4) {
        if (argc > 1) {
            snprintf(command, 100, "/usr/bin/vtysh -c 'show ip bgp %s' 2>&1", argv[1]);
        } else {
            strcpy(command, "/usr/bin/vtysh -c show ip bgp");
        }
    } else {
        if (argc > 1) {
            snprintf(command, 100, "/usr/bin/vtysh -c 'show bgp %s' 2>&1", argv[1]);
        } else {
            strcpy(command, "/usr/bin/vtysh -c show bgp");
        }
    }

    fp = popen(command, "r");
    if (fp == NULL) {
        free(command);
        return 3;
    }
    free(command);

    while (fgets(out, sizeof(out), fp) != NULL) {
        write(fd, out, strlen(out));
    }

    pclose(fp);

    return 0;
}
Exemplo n.º 30
0
Arquivo: str.c Projeto: xdave/xsps
/* Returns new string with all ${FOO} vars replaced from getbenv() */
char *
breplace(const char *input)
{
	size_t i, input_len, tmp_len;
	const char *env;
	char *item, *tmp = NULL, *replacement = NULL;

	/* Copy input to output if this is a useless call */
	if ((strstr(input, "${") == NULL))
	    return xstrcpy(input);

	str_t to_replace;
	to_replace.size = 0;
	to_replace.items = xmalloc(sizeof(char *) * to_replace.size);

	bvars(&to_replace, input);
	input_len = strlen(input);
	replacement = xmalloc(input_len + 1);
	replacement = strncpy(replacement, input, input_len);
	replacement[input_len] = '\0';

	if (to_replace.size > 0) {
		for (i = 0; i < to_replace.size; i++) {
			item = to_replace.items[i];
			env = getbenv(item);
			tmp = str_replace(replacement, item, env);
			tmp_len = strlen(tmp);
			free(replacement);
			replacement = xmalloc(tmp_len + 1);
			replacement = strncpy(replacement, tmp, tmp_len);
			replacement[tmp_len] = '\0';
			/* NOTE: 'tmp' is free()'d by the strmgr. */
			free(item);
		}
	}
	free(to_replace.items);
	return str_add_nocopy(replacement);
}