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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/* Prism Versioning
* Copyright 2014 Jeffrey Armstrong <jeff@rainbow-100.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "prism.h"
#include "db.h"
#include "rfile.h"
static void banner()
{
printf("Prism Versioning\nRelease %s\nBy Jeff Armstrong <jeff@rainbow-100.com>\n",VERSION);
}
static void usage(const char *name)
{
banner();
printf("\nUsage: %s <command> ...\n\n", name);
printf("Commands:\n\n");
printf("\tabout\tprints a banner and exits\n");
printf("\thash\tdisplays a file's hash\n");
printf("\tinfo\tshow information about repository\n");
printf("\tinit\tinitializes this directory for versioning\n");
}
static void init_task()
{
printf("Initializing Prism...\n");
switch(initdb()) {
case PRET_EXISTS:
printf(" ERR: already initialized\n");
break;
case PRET_PERMISSION:
printf(" ERR: permissions error\n");
break;
case PRET_ERROR:
printf(" ERR: general error\n");
break;
default:
printf(" OK: initialized\n");
}
}
static void add_task(const char *filename)
{
}
static void info_task()
{
int res;
printf("Retrieving Prism information...\n");
res = get_revision();
if(res < 0) {
printf(" ERR: no revision could be retrieved\n");
return;
} else
printf(" current revision: %d\n", res);
res = get_file_count();
if(res < 0) {
printf(" ERR: file count error\n");
return;
} else
printf(" tracking %d files\n", res);
}
static void info_hash(const char *filename)
{
int res;
char hash[33];
memset(hash, 0, 33);
printf("Computing hash for %s...\n", filename);
res = get_file_hash(filename, hash);
if(res == PRET_OK)
printf(" hash: %s\n", hash);
else
printf(" ERR: hash failed\n");
}
int main(int argc, char *argv[])
{
if(argc == 1) {
usage(argv[0]);
return 0;
}
if(strcmp(argv[1], "about") == 0)
banner();
else if(strcmp(argv[1], "init") == 0)
init_task();
else if(strcmp(argv[1], "info") == 0)
info_task();
else if(strcmp(argv[1], "hash") == 0 && argc == 3)
info_hash(argv[2]);
return 0;
}
|