summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-03-12 23:16:45 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-03-12 23:16:45 +0800
commit299ef83df0c1b90094e00ef5ad7a9c0c49f71423 (patch)
tree13cefd6c4e43fa58b0e00a5004c32f9b480c30d4
parentb200dd2a15365007b5ea64dff4df3e29273b2212 (diff)
downloadcvn-299ef83df0c1b90094e00ef5ad7a9c0c49f71423.tar.gz
Format diff output.
-rw-r--r--main.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/main.c b/main.c
index cdf1340..65ec01d 100644
--- a/main.c
+++ b/main.c
@@ -9,8 +9,7 @@
#define PATCH_DIR ".cvn"
#define BASE PATCH_DIR "/base"
-
-#define EXCLUDE_PATHS ".cvnignore"
+#define EXCLUDE_PATHS PATCH_DIR "ignore"
static inline void init(int argc, char *argv[]);
static inline void status(int argc, char *argv[]);
@@ -73,11 +72,11 @@ static inline void init(int argc, char *argv[])
static inline void status(int argc, char *argv[])
{
+ FILE *fp;
pid_t pid;
int status;
int pipefd[2];
- char buf[1024];
- ssize_t bytes_read;
+ char line[1024];
if (pipe(pipefd) == -1)
err(1, "pipe()");
@@ -87,8 +86,10 @@ static inline void status(int argc, char *argv[])
if (pid == 0) {
close(pipefd[0]);
+
dup2(pipefd[1], STDOUT_FILENO);
close(pipefd[1]);
+
if (access(EXCLUDE_PATHS, F_OK) == 0) {
char *args[] = {"diff", "-x", PATCH_DIR, "-X",
EXCLUDE_PATHS, "-rq", BASE, ".", NULL};
@@ -101,11 +102,21 @@ static inline void status(int argc, char *argv[])
} else {
waitpid(pid, &status, 0);
close(pipefd[1]);
- while ((bytes_read = read(pipefd[0], buf, sizeof(buf) - 1)) > 0) {
- buf[bytes_read] = '\0';
- printf("%s", buf);
+
+ if (!(fp = fdopen(pipefd[0], "r")))
+ err(1, "fdopen()");
+
+ const char *src = "Only in .: ";
+ const char *rep = "(N) ";
+
+ while (fgets(line, sizeof(line), fp) != NULL) {
+ if (strncmp(line, src, strlen(src)) == 0)
+ printf("%s%s", rep, line + strlen(src));
+ else
+ printf("%s", line);
}
- close(pipefd[0]);
- wait(NULL);
+
+ fclose(fp);
+ waitpid(pid, &status, 0);
}
}