Use chsrc_check_file()

This commit is contained in:
Aoran Zeng 2023-09-26 22:24:48 +08:00
parent eb0bd01d4c
commit f1ec6f8399
2 changed files with 23 additions and 23 deletions

33
chsrc.c
View File

@ -368,13 +368,11 @@ pl_go_setsrc (char* option)
void void
pl_rust_getsrc (char* option) pl_rust_getsrc (char* option)
{ {
char* cmd = NULL;
if(xy_on_windows) { if(xy_on_windows) {
cmd = "type %USERPROFILE%\\.cargo"; chsrc_check_file ("%USERPROFILE%\\.cargo");
} else { } else {
cmd = "cat ~/.cargo"; chsrc_check_file ("~/.cargo");
} }
chsrc_run(cmd);
} }
/** /**
@ -728,13 +726,11 @@ pl_r_getsrc (char* option)
// options()$repos // options()$repos
// options()$BioC_mirror // options()$BioC_mirror
// //
char* cmd = NULL;
if(xy_on_windows) { if(xy_on_windows) {
cmd = "type %USERPROFILE%\\Documents\\.Rprofile"; chsrc_check_file ("%USERPROFILE%\\Documents\\.Rprofile");
} else { } else {
cmd = "cat ~/.Rprofile"; chsrc_check_file ("~/.Rprofile");
} }
chsrc_run(cmd);
} }
/** /**
@ -787,13 +783,11 @@ pl_r_setsrc (char* option)
void void
pl_julia_getsrc (char* option) pl_julia_getsrc (char* option)
{ {
char* cmd = NULL;
if(xy_on_windows) { if(xy_on_windows) {
cmd = "type %USERPROFILE%\\.julia\\config\\startup.jl"; chsrc_check_file ("%USERPROFILE%\\.julia\\config\\startup.jl");
} else { } else {
cmd = "cat ~/.julia/config/startup.jl"; chsrc_check_file ("~/.julia/config/startup.jl");
} }
chsrc_run(cmd);
} }
/** /**
@ -838,8 +832,7 @@ pl_julia_setsrc (char* option)
void void
os_ubuntu_getsrc(char* option) os_ubuntu_getsrc(char* option)
{ {
char* cmd = "cat /etc/apt/sources.list"; chsrc_check_file ("/etc/apt/sources.list");
chsrc_run(cmd);
} }
/** /**
@ -894,8 +887,7 @@ os_ubuntu_setsrc (char* option)
void void
os_debian_getsrc(char* option) os_debian_getsrc(char* option)
{ {
char* cmd = "cat /etc/apt/sources.list"; chsrc_check_file ("/etc/apt/sources.list");
chsrc_run(cmd);
} }
/** /**
@ -942,8 +934,7 @@ os_debian_setsrc (char* option)
void void
os_deepin_getsrc(char* option) os_deepin_getsrc(char* option)
{ {
char* cmd = "cat /etc/apt/sources.list"; chsrc_check_file ("/etc/apt/sources.list");
chsrc_run(cmd);
} }
/** /**
@ -1613,8 +1604,7 @@ os_freebsd_setsrc (char* option)
void void
os_netbsd_getsrc (char* option) os_netbsd_getsrc (char* option)
{ {
char* cmd = "cat /usr/pkg/etc/pkgin/repositories.conf"; chsrc_check_file ("/usr/pkg/etc/pkgin/repositories.conf");
chsrc_run(cmd);
} }
/** /**
@ -1663,8 +1653,7 @@ os_netbsd_setsrc(char* option)
void void
os_openbsd_getsrc (char* option) os_openbsd_getsrc (char* option)
{ {
char* cmd = "cat /etc/installurl"; chsrc_check_file ("/etc/installurl");
chsrc_run(cmd);
} }
/** /**

13
chsrc.h
View File

@ -272,7 +272,6 @@ not_root:
#define chsrc_warn(str) xy_warn(xy_2strjoin(App_Prefix, (str))) #define chsrc_warn(str) xy_warn(xy_2strjoin(App_Prefix, (str)))
#define chsrc_error(str) xy_error(xy_2strjoin(App_Prefix, (str))) #define chsrc_error(str) xy_error(xy_2strjoin(App_Prefix, (str)))
static void static void
chsrc_run (const char* cmd) chsrc_run (const char* cmd)
{ {
@ -280,6 +279,18 @@ chsrc_run (const char* cmd)
system(cmd); system(cmd);
} }
static void
chsrc_check_file (const char* path)
{
char* cmd = NULL;
if(xy_on_windows) {
cmd = xy_2strjoin ("type ", path);
} else {
cmd = xy_2strjoin ("cat ", path);
}
chsrc_run (cmd);
}
static void static void
chsrc_append_to_file (const char* str, const char* file) chsrc_append_to_file (const char* str, const char* file)
{ {