DiskTool - Compiling again, now with modules
[tpg/acess2.git] / Tools / DiskTool / src / main.c
1 /*
2  */
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <errno.h>
6 #include <stdint.h>
7 #include <string.h>
8 #include <disktool_common.h>
9
10 // === CODE ===
11 int main(int argc, char *argv[])
12 {
13         // Parse arguments
14         for( int i = 1; i < argc; i ++ )
15         {
16                 if( strcmp("--image", argv[i]) == 0 || strcmp("-i", argv[i]) == 0 ) {
17                         // Mount an image
18                         if( argc - i < 3 ) {
19                                 fprintf(stderr, "--image/-i takes 2 arguments (ident and path)\n");
20                                 exit(-1);
21                         }
22
23                         if( DiskTool_MountImage(argv[i+1], argv[i+2]) ) {
24                                 fprintf(stderr, "Unable to mount '%s' as '%s'\n", argv[i+2], argv[i+1]);
25                                 exit(-1);
26                         }
27
28                         i += 2;
29                 }
30         }
31         return 0;
32 }
33
34 // NOTE: This is in a native compiled file because it needs access to the real errno macro
35 int *Threads_GetErrno(void)
36 {
37         return &errno;
38 }
39
40 // TODO: Move into a helper lib?
41 void itoa(char *buf, uint64_t num, int base, int minLength, char pad)
42 {
43         char fmt[] = "%0ll*x";
44         switch(base)
45         {
46         case  8:        fmt[5] = 'o';   break;
47         case 10:        fmt[5] = 'd';   break;
48         case 16:        fmt[5] = 'x';   break;
49         }
50         if(pad != '0') {
51                 fmt[1] = '%';
52                 sprintf(buf, fmt+1, minLength, num);
53         }
54         else {
55                 sprintf(buf, fmt, minLength, num);
56         }
57 }
58
59 int strpos(const char *Str, char Ch)
60 {
61         const char *r = strchr(Str, Ch);
62         if(!r)  return -1;
63         return r - Str;
64 }
65
66 int strucmp(const char *s1, const char *s2)
67 {
68         return strcasecmp(s1, s2);
69 }
70
71 int64_t DivUp(int64_t value, int64_t divisor)
72 {
73         return (value + divisor - 1) / divisor;
74 }
75
76 int64_t timestamp(int sec, int min, int hr, int day, int month, int year)
77 {
78         return 0;
79 }
80

UCC git Repository :: git.ucc.asn.au