Skip to content

Commit

Permalink
Add print macro
Browse files Browse the repository at this point in the history
  • Loading branch information
ccmywish committed Dec 14, 2024
1 parent 2746fe0 commit 6ded338
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 42 deletions.
9 changes: 5 additions & 4 deletions include/xy.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ bool xy_enable_color = true;
void putf (double n) { printf ("%f\n", n); }
void puti (long long n) { printf ("%lld\n", n); }
void putb (bool n) { if (n) puts ("true"); else puts ("false"); }
void print (const char *s) { printf ("%s", s); }
void println (const char *s) { printf ("%s\n", s);}
void say (const char *s) { printf ("%s\n", s);}
void br () { puts ("");}
void print (const char *s) { printf ("%s", s); }
void println (const char *s) { printf ("%s\n", s); }
void say (const char *s) { printf ("%s\n", s); }
void br () { puts (""); }
void p (const char *s) { printf ("%s\n", s); }

#define assert_str(a, b) assert (xy_streql ((a), (b)))

Expand Down
10 changes: 3 additions & 7 deletions src/framework/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,11 +819,7 @@ source_has_empty_url (Source_t *source)



static inline void
divide_source_changing_process ()
{
say ("--------------------------------");
}
#define hr() say ("--------------------------------");


/**
Expand Down Expand Up @@ -861,7 +857,7 @@ confirm_source (Source_t *source)
say (xy_strjoin (5, msg, green (source->mirror->abbr), " (", green (source->mirror->code), ")"));
}

divide_source_changing_process();
hr();
}

#define chsrc_yield_source_and_confirm(for_what) chsrc_yield_source(for_what);chsrc_confirm_source
Expand Down Expand Up @@ -899,7 +895,7 @@ confirm_source (Source_t *source)
void
chsrc_conclude (Source_t *source)
{
divide_source_changing_process();
hr();

// fprintf (stderr, "chsrc: now change type: %d\n", ProgMode_ChgType);

Expand Down
2 changes: 1 addition & 1 deletion src/recipe/lang/Clojure.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pl_clojure_setsrc (char *option)
chsrc_yield_source_and_confirm (pl_clojure);

chsrc_note2 ("抱歉,Clojure换源较复杂,您可手动查阅并换源:");
say (source.url);
p(source.url);
ProgMode_ChgType = ChgType_Manual;
chsrc_conclude (&source);
}
Expand Down
2 changes: 1 addition & 1 deletion src/recipe/lang/Haskell.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pl_haskell_setsrc (char *option)
" ignore-expiry: no");

chsrc_note2 (xy_strjoin (3, "请向 ", config, " 中手动添加:"));
say (file);
p(file);
ProgMode_ChgType = ChgType_Manual;
chsrc_conclude (&source);
}
Expand Down
2 changes: 1 addition & 1 deletion src/recipe/lang/Java.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pl_java_setsrc (char *option)
"}");

chsrc_note2 ("请在您的 build.gradle 中添加:");
say (file);
p(file);
}
ProgMode_ChgType = ChgType_Manual;
chsrc_conclude (&source);
Expand Down
2 changes: 1 addition & 1 deletion src/recipe/lang/Lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pl_lua_setsrc (char *option)
"server = \"", source.url, "\"");

chsrc_note2 ("请手动修改 ~/.luarocks/upload_config.lua 文件 (用于上传):");
say (upload_config);
p(upload_config);

ProgMode_ChgType = ChgType_Manual;
chsrc_conclude (&source);
Expand Down
2 changes: 1 addition & 1 deletion src/recipe/lang/Node.js/Bun.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pl_nodejs_bun_setsrc (char *option)
chsrc_note2 (xy_strjoin (3, "请您手动写入以下内容到 ", xy_normalize_path ("~/.bunfig.toml"), " 文件中"));
}

say (file);
p(file);
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_conclude (&source);
}
Expand Down
12 changes: 6 additions & 6 deletions src/recipe/lang/Node.js/Node.js.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ pl_nodejs_getsrc (char *option)
bool npm_exist, yarn_exist, pnpm_exist;
pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist);

divide_source_changing_process();
hr();

if (npm_exist)
{
pl_nodejs_npm_getsrc (option);
say ("");
br();
}

if (yarn_exist)
{
pl_nodejs_yarn_getsrc (option);
say ("");
br();
}

if (pnpm_exist)
{
pl_nodejs_pnpm_getsrc (option);
say ("");
br();
}
}

Expand Down Expand Up @@ -80,13 +80,13 @@ pl_nodejs_setsrc (char *option)
if (npm_exist)
{
pl_nodejs_npm_setsrc (option);
say ("");
br();
}

if (yarn_exist)
{
pl_nodejs_yarn_setsrc (option);
say ("");
br();
}

if (pnpm_exist)
Expand Down
2 changes: 1 addition & 1 deletion src/recipe/lang/OCaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pl_ocaml_setsrc(char *option)
chsrc_run (cmd, RunOpt_Default);

chsrc_note2 ("如果是首次使用 opam ,请使用以下命令进行初始化");
say (xy_2strjoin ("opam init default ", source.url));
p(xy_2strjoin ("opam init default ", source.url));

ProgMode_ChgType = ChgType_SemiAuto;
chsrc_conclude (&source);
Expand Down
2 changes: 1 addition & 1 deletion src/recipe/lang/Perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pl_perl_setsrc (char *option)
chsrc_run (cmd, RunOpt_Default);

chsrc_note2 ("请您使用 perl -v 以及 cpan -v,若 Perl >= v5.36 或 CPAN >= 2.29,请额外手动调用下面的命令");
say ("perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->edit('pushy_https', 0);; CPAN::HandleConfig->commit()\"");
p("perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->edit('pushy_https', 0);; CPAN::HandleConfig->commit()\"");

ProgMode_ChgType = ChgType_SemiAuto;
chsrc_conclude (&source);
Expand Down
12 changes: 6 additions & 6 deletions src/recipe/lang/Python/Python.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ pl_python_getsrc (char *option)

// 交给后面检查命令的存在性
pl_python_pip_getsrc (option);
say ("");
br();

if (poetry_exist)
{
pl_python_poetry_getsrc (option);
say ("");
br();
}

if (pdm_exist)
{
pl_python_pdm_getsrc (option);
}

if (uv_exist)
{
pl_python_uv_getsrc (option);
Expand Down Expand Up @@ -63,19 +63,19 @@ pl_python_setsrc (char *option)

// 交给后面检查命令的存在性
pl_python_pip_setsrc (option);
say ("");
br();

if (poetry_exist)
{
pl_python_poetry_setsrc (option);
say ("");
br();
}

if (pdm_exist)
{
pl_python_pdm_setsrc (option);
}

if (uv_exist)
{
pl_python_uv_setsrc (option);
Expand Down
2 changes: 1 addition & 1 deletion src/recipe/lang/Rust/Cargo.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pl_rust_cargo_setsrc (char *option)
"registry = \"sparse+", source.url, "\"");

chsrc_note2 (xy_strjoin (3, "请您手动写入以下内容到 ", xy_normalize_path ("~/.cargo/config.toml"), " 文件中:"));
say (file);
p(file);
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_conclude (&source);
}
Expand Down
2 changes: 1 addition & 1 deletion src/recipe/os/Void-Linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ os_voidlinux_setsrc (char *option)
);

chsrc_note2 ("若报错可尝试使用以下命令:");
say (cmd);
p(cmd);
ProgMode_ChgType = ChgType_Untested;
chsrc_conclude (&source);
}
Expand Down
11 changes: 5 additions & 6 deletions src/recipe/ware/CocoaPods.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ wr_cocoapods_setsrc (char *option)
chsrc_yield_source_and_confirm (wr_cocoapods);

chsrc_note2 ("请手动执行以下命令:");

say ("cd ~/.cocoapods/repos");
say ("pod repo remove master");
p("cd ~/.cocoapods/repos");
p("pod repo remove master");
char *git_cmd = xy_strjoin (3, "git clone ", source.url, " master");
say (git_cmd);
say ("");
p(git_cmd);
br();

chsrc_note2 ("最后进入项目工程目录,在Podfile中第一行加入:");
char *source_str = xy_strjoin (3, "source '", source.url, "'");
say (source_str);
p(source_str);

ProgMode_ChgType = ChgType_Manual;
chsrc_conclude (&source);
Expand Down
2 changes: 1 addition & 1 deletion src/recipe/ware/Emacs.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ wr_emacs_setsrc (char *option)
chsrc_yield_source_and_confirm (wr_emacs);

chsrc_note2 ("Emacs换源涉及Elisp,需要手动查阅并换源:");
say (source.url);
p(source.url);

ProgMode_ChgType = ChgType_Manual;
chsrc_conclude (&source);
Expand Down
2 changes: 1 addition & 1 deletion src/recipe/ware/Guix.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ wr_guix_setsrc (char *option)
" (url \"", source.url, "\")))");

chsrc_note2 ("为防止扰乱配置文件,请您手动写入以下内容到 ~/.config/guix/channels.scm 文件中");
say (file);
p(file);

ProgMode_ChgType = ChgType_Manual;
chsrc_conclude (&source);
Expand Down
4 changes: 2 additions & 2 deletions src/recipe/ware/Nix.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ wr_nix_setsrc (char *option)

chsrc_note2 ("若您使用的是NixOS,请确认您的系统版本<version>(如22.11),并手动运行:");
cmd = xy_strjoin (3, "nix-channel --add ", source.url, "nixpkgs-<version> nixpkgs");
say (cmd);
p(cmd);

cmd = xy_strjoin (3, "nix.settings.substituters = [ \"", source.url, "store\" ];");
chsrc_note2 ("若您使用的是NixOS,请额外添加下述内容至 configuration.nix 中");
say (cmd);
p(cmd);

ProgMode_ChgType = ChgType_SemiAuto;
chsrc_conclude (&source);
Expand Down

0 comments on commit 6ded338

Please sign in to comment.