From 069f5fb827189efe39e7c10e05dd9a847841248f Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Wed, 3 Jul 2024 13:59:06 +0800 Subject: [PATCH] Add prepend --- include/chsrc.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/include/chsrc.h b/include/chsrc.h index 9a0c6c5..56b385c 100644 --- a/include/chsrc.h +++ b/include/chsrc.h @@ -7,7 +7,7 @@ * Contributors : Null Nil * | * Created on : <2023-08-29> - * Last modified : <2024-06-24> + * Last modified : <2024-07-03> * * chsrc 头文件 * ------------------------------------------------------------*/ @@ -666,6 +666,25 @@ chsrc_append_to_file (const char *str, const char *file) chsrc_run (cmd, RunOpt_Default); } +static void +chsrc_prepend_to_file (const char *str, const char *file) +{ + file = xy_uniform_path (file); + char *dir = xy_parent_dir (file); + chsrc_ensure_dir (dir); + + char *cmd = NULL; + if (xy_on_windows) + { + xy_unimplement; + } + else + { + cmd = xy_strjoin (4, "sed -i '1i ", str, "'", file); + } + chsrc_run (cmd, RunOpt_Default); +} + static void chsrc_overwrite_file (const char *str, const char *file) {