- lib: added string_substitute() function

- lib: changed boinc_copy() to replace " " with "\ " in its args
    (to allow pathnames containing spaces).
    From Tolu Aina

svn path=/trunk/boinc/; revision=15891
This commit is contained in:
David Anderson 2008-08-19 19:46:18 +00:00
parent 9af4275e0e
commit 91f8666309
5 changed files with 54 additions and 10 deletions

View File

@ -6809,3 +6809,13 @@ Charlie 18 Aug 2008
clientgui/
AsyncRPC.cpp
David 19 Aug 2008
- lib: added string_substitute() function
- lib: changed boinc_copy() to replace " " with "\ " in its args
(to allow pathnames containing spaces).
From Tolu Aina
lib/
filesys.C
str_util.C,h

View File

@ -33,12 +33,6 @@ array("July 9, 2008",
a PHP script to display BOINC stats on a webpage,
and store or retrieve these stats to a mySQL database."
),
array("June 26, 2008",
"Congratulations and thanks to volunteer
<a href=\"http://boinc.netsoft-online.com/e107_plugins/boinc/get_user.php?cpid=4b03581a7c1802a7bd62649720327b04&amp;html=1\">Banshee</a> from
<a href=\"http://www.boinc-af.org/\">L'Alliance Francophone</a>,
who has recently contributed over 10 TeraFLOPS to several projects."
),
array("June 16, 2008",
"<a href=logo/logo_3d>3-D versions of the BOINC logo</a>
are now available; thanks to John from Ireland for creating these."

View File

@ -492,13 +492,15 @@ int boinc_copy(const char* orig, const char* newf) {
}
return 0;
#elif defined(__EMX__)
char cmd[256];
char cmd[1024], cmd_esc[1024];
sprintf(cmd, "copy %s %s", orig, newf);
return system(cmd);
string_substitute(cmd, cmd_esc, sizeof(cmd_esc), " ", "\\ ");
return system(cmd_esc);
#else
char cmd[256];
char cmd[1024], cmd_esc[1024];
sprintf(cmd, "cp %s %s", orig, newf);
return system(cmd);
string_substitute(cmd, cmd_esc, sizeof(cmd_esc), " ", "\\ ");
return system(cmd_esc);
#endif
}

View File

@ -843,4 +843,37 @@ char* windows_format_error_string(
}
#endif
// string substitution:
// haystack is the input string
// out is the output buffer
// out_len is the length of the output buffer
// needle is string to search for within the haystack
// target is string to replace with
//
int string_substitute(
const char* haystack, char* out, int out_len,
const char* needle, const char* target
) {
unsigned int i=0, j=0;
int needle_len = strlen(needle);
int target_len = strlen(target);
int retval = 0;
while (haystack[i]) {
if (j+target_len >= out_len-1) {
retval = ERR_BUFFER_OVERFLOW;
break;
}
if (!strncmp(&haystack[i], needle, needle_len)){
strcpy(out+j, target);
i += strlen(needle);
j += strlen(target);
} else {
out[j++] = haystack[i++];
}
}
out[j] = 0;
return retval;
}
const char *BOINC_RCSID_ab90e1e = "$Id$";

View File

@ -78,6 +78,11 @@ inline void downcase_string(std::string& w) {
}
}
extern int string_substitute(
const char* haystack, char* out, int out_len,
const char* needle, const char* target
);
// convert UNIX time to MySQL timestamp (yyyymmddhhmmss)
//
extern void mysql_timestamp(double, char*);