From 45f9640554b28f78f48f792d926e3b16531e330f Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sun, 13 Jan 2008 00:12:59 +0000 Subject: [PATCH] Add a new configuration file command ifnxcp that allows file copying without overwriting already existing file. git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@410 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- config.l | 1 + dgamelaunch.h | 1 + dgl-common.c | 7 +++++++ examples/dgamelaunch.conf | 1 + 4 files changed, 10 insertions(+) diff --git a/config.l b/config.l index 09e10da..d826480 100644 --- a/config.l +++ b/config.l @@ -86,6 +86,7 @@ game_start { yylval.i = DGLTIME_GAMESTART; return TYPE_CMDQUEUENAME; } mkdir { yylval.i = DGLCMD_MKDIR; return TYPE_DGLCMD1; } chdir { yylval.i = DGLCMD_CHDIR; return TYPE_DGLCMD1; } cp { yylval.i = DGLCMD_CP; return TYPE_DGLCMD2; } +ifnxcp { yylval.i = DGLCMD_IF_NX_CP; return TYPE_DGLCMD2; } unlink { yylval.i = DGLCMD_UNLINK; return TYPE_DGLCMD1; } setenv { yylval.i = DGLCMD_SETENV; return TYPE_DGLCMD2; } exec { yylval.i = DGLCMD_EXEC; return TYPE_DGLCMD2; } diff --git a/dgamelaunch.h b/dgamelaunch.h index fedfd0a..39a05d5 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -99,6 +99,7 @@ typedef enum DGLCMD_NONE = 0, DGLCMD_MKDIR, /* mkdir foo */ DGLCMD_CHDIR, /* chdir foo */ + DGLCMD_IF_NX_CP, /* ifnxcp foo bar */ DGLCMD_CP, /* cp foo bar */ DGLCMD_UNLINK, /* unlink foo */ DGLCMD_EXEC, /* exec foo bar */ diff --git a/dgl-common.c b/dgl-common.c index 69ceedc..a9ec2d6 100644 --- a/dgl-common.c +++ b/dgl-common.c @@ -144,6 +144,13 @@ dgl_exec_cmdqueue(struct dg_cmdpart *queue, int game, struct dg_user *me) case DGLCMD_CHDIR: if (p1) chdir(p1); break; + case DGLCMD_IF_NX_CP: + if (p1 && p2) { + FILE *tmpfile; + tmpfile = fopen(p2, "r"); + if (tmpfile) break; + } + /* else fall through to cp */ case DGLCMD_CP: if (p1 && p2) { FILE *cannedf, *newfile; diff --git a/examples/dgamelaunch.conf b/examples/dgamelaunch.conf index 530d2b9..cea5787 100644 --- a/examples/dgamelaunch.conf +++ b/examples/dgamelaunch.conf @@ -71,6 +71,7 @@ lockfile = "/dgl-lock" # mkdir "foo" = creates a directory "foo" # chdir "foo" = changes current work dir to "foo" # cp "foo" "bar" = copies file "foo" to "bar", overwriting previous "bar" +# ifnxcp "foo" "bar" = copies file "foo" to "bar", if "bar" doesn't exist # unlink "foo" = deletes file "foo" # setenv "foo "bar" = sets environment variable "foo" to "bar" # exec "foo" "bar" = execute "foo" with "bar" as it's param