7dd85833448cd338cb2933c6904d4cebd9aedbf6
[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         // Setup
14
15         // Parse arguments
16         for( int i = 1; i < argc; i ++ )
17         {
18                 if( strcmp("--image", argv[i]) == 0 || strcmp("-i", argv[i]) == 0 ) {
19                         // Mount an image
20                         if( argc - i < 3 ) {
21                                 fprintf(stderr, "--image/-i takes 2 arguments (ident and path)\n");
22                                 exit(-1);
23                         }
24
25                         if( DiskTool_MountImage(argv[i+1], argv[i+2]) ) {
26                                 fprintf(stderr, "Unable to mount '%s' as '%s'\n", argv[i+2], argv[i+1]);
27                                 exit(-1);
28                         }
29
30                         i += 2;
31                 }
32         }
33         return 0;
34 }
35
36 // NOTE: This is in a native compiled file because it needs access to the real errno macro
37 int *Threads_GetErrno(void)
38 {
39         return &errno;
40 }
41
42 // TODO: Move into a helper lib?
43 void itoa(char *buf, uint64_t num, int base, int minLength, char pad)
44 {
45         char fmt[] = "%0ll*x";
46         switch(base)
47         {
48         case  8:        fmt[5] = 'o';   break;
49         case 10:        fmt[5] = 'd';   break;
50         case 16:        fmt[5] = 'x';   break;
51         }
52         if(pad != '0') {
53                 fmt[1] = '%';
54                 sprintf(buf, fmt+1, minLength, num);
55         }
56         else {
57                 sprintf(buf, fmt, minLength, num);
58         }
59 }
60
61 int strpos(const char *Str, char Ch)
62 {
63         const char *r = strchr(Str, Ch);
64         if(!r)  return -1;
65         return r - Str;
66 }

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