Add xy_run(), xy_append_to_file() and xy_overwrite_file()

This commit is contained in:
Aoran Zeng 2023-09-26 19:20:12 +08:00
parent 31a3004aed
commit 57bf9f86a4

37
xy.h
View File

@ -3,13 +3,13 @@
* License : MIT
* Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-28>
* Last modified : <2023-09-22>
* Last modified : <2023-09-26>
*
* xy:
*
* y = f(x)
*
* Corss-Platform C utilities in Ruby flavor
* Corss-Platform C utilities for CLI applications in Ruby flavor
*
* MIT LICENSE.txt
* ------------------------------------------------------------*/
@ -525,4 +525,37 @@ xy_file_exist(char* path)
}
static void
xy_run (const char* cmd)
{
char* log = App_Log_Prefix;
xy_info (xy_2strjoin (log, cmd));
system(cmd);
}
static void
xy_append_to_file (char* str, char* file)
{
char* cmd = NULL;
if (xy_on_windows) {
cmd = xy_strjoin (4, "echo ", str, " >> ", file);
} else {
cmd = xy_strjoin (4, "echo '", str, "' >> ", file);
}
xy_run(cmd);
}
static void
xy_overwrite_file (char* str, char* file)
{
char* cmd = NULL;
if (xy_on_windows) {
cmd = xy_strjoin (4, "echo ", str, " > ", file);
} else {
cmd = xy_strjoin (4, "echo '", str, "' > ", file);
}
xy_run(cmd);
}
#endif