-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
80 lines (62 loc) · 1.45 KB
/
main.cc
File metadata and controls
80 lines (62 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "includes.h"
#include "command_line.h"
#include "constants.h"
// Check that dependencies are installed:
// - hg
// - iconv
// - xml2
int check_dependencies ()
{
if (system ("iconv /dev/null"))
return -1;
if (system ("xml2 --help 2> /dev/null") < 0)
return -1;
if (system ("hg --help > /dev/null"))
return -1;
return 0;
}
// Check that we are in a mercurial repository
int check_hg_repo ()
{
char original_directory[MAX_FILE_SIZE];
char current_directory[MAX_FILE_SIZE];
if (!getcwd (original_directory, MAX_FILE_SIZE))
return -ENOENT;
while (true) {
DIR *dir = opendir (".hg");
if (dir) {
// We found it! Go back to the original directory and proceed
closedir (dir);
if (chdir (original_directory) == -1)
break;
return 0;
}
// If we reached root directory and didn't find it, give up
if (!strcmp (getcwd (current_directory, MAX_FILE_SIZE), "/"))
break;
// Try again with the next level up
if (chdir ("..") == -1)
break;
}
// Go back to the original directory and error out
if (chdir (original_directory) == -1)
return -ENOENT;
return -ENOENT;
}
int main (int argc, char *argv[])
{
int ret = 0;
ret = check_dependencies ();
if (ret) {
printf ("Dependencies not found. Please install iconv xml2 and hg.\n");
goto fail;
}
ret = check_hg_repo ();
if (ret) {
printf ("Not in a mercurial repo.\n");
goto fail;
}
ret = parse_command_line (argc - 1, argv + 1);
fail:
return ret;
}