diff --git a/src/tup/init.c b/src/tup/init.c index 99cda1740..ba7322729 100644 --- a/src/tup/init.c +++ b/src/tup/init.c @@ -30,7 +30,15 @@ #include "variant.h" #include "version.h" #include +#include +#include +#include #include +#include + +#ifdef _WIN32 +#define mkdir(a,b) mkdir(a) +#endif int tup_init(void) { @@ -112,3 +120,135 @@ void tup_valgrind_cleanup(void) close(STDIN_FILENO); } } + +static int mkdirtree(const char *dirname) +{ + char *dirpart = strdup(dirname); + char *p; + + if(!dirpart) { + perror("strdup"); + return -1; + } + + p = dirpart; + while(1) { + char *slash = p; + char slash_found = 0; + + while(*slash && !is_path_sep(slash)) { + slash++; + } + if(*slash) { + slash_found = *slash; + *slash = 0; + } + if(mkdir(dirpart, 0777) < 0) { + if(errno != EEXIST) { + perror(dirpart); + fprintf(stderr, "tup error: Unable to create directory '%s' for a tup repository.\n", dirname); + return -1; + } + } + if(slash_found) { + *slash = slash_found; + p = slash + 1; + } else { + break; + } + } + free(dirpart); + return 0; +} + +int init_command(int argc, char **argv) +{ + int x; + int db_sync = 1; + int force_init = 0; + int fd; + const char *dirname = NULL; + + for(x=1; x + * Copyright (C) 2009-2013 Mike Shal * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -21,3 +21,4 @@ int tup_init(void); int tup_cleanup(void); void tup_valgrind_cleanup(void); +int init_command(int argc, char **argv); diff --git a/src/tup/option.c b/src/tup/option.c index 5d4b1c1b2..920c6f5a4 100644 --- a/src/tup/option.c +++ b/src/tup/option.c @@ -31,6 +31,7 @@ #include "option.h" #include "vardb.h" #include "inih/ini.h" +#include "init.h" #include #include #include @@ -107,9 +108,6 @@ static struct sigaction sigact = { }; #endif -/* From tup/main.c, used to invoke `tup init' */ -int init_command(int argc, char **argv); - int tup_option_process_ini(void) { int cur_dir; int best_root = -1; // file descriptor -> best root candidate diff --git a/src/tup/tup/main.c b/src/tup/tup/main.c index 331b9fcfb..8e63d90ad 100644 --- a/src/tup/tup/main.c +++ b/src/tup/tup/main.c @@ -47,7 +47,6 @@ #define mkdir(a,b) mkdir(a) #endif - int init_command(int argc, char **argv); static int graph_cb(void *arg, struct tup_entry *tent); static int graph(int argc, char **argv); /* Testing commands */ @@ -275,139 +274,6 @@ int main(int argc, char **argv) return rc; } -static int mkdirtree(const char *dirname) -{ - char *dirpart = strdup(dirname); - char *p; - - if(!dirpart) { - perror("strdup"); - return -1; - } - - p = dirpart; - while(1) { - char *slash = p; - char slash_found = 0; - - while(*slash && !is_path_sep(slash)) { - slash++; - } - if(*slash) { - slash_found = *slash; - *slash = 0; - } - if(mkdir(dirpart, 0777) < 0) { - if(errno != EEXIST) { - perror(dirpart); - fprintf(stderr, "tup error: Unable to create directory '%s' for a tup repository.\n", dirname); - return -1; - } - } - if(slash_found) { - *slash = slash_found; - p = slash + 1; - } else { - break; - } - } - free(dirpart); - return 0; -} - -/* Symbol is exported so that option can call it to automatically run tup init */ -int init_command(int argc, char **argv) -{ - int x; - int db_sync = 1; - int force_init = 0; - int fd; - const char *dirname = NULL; - - for(x=1; x