DiskTool - Mounts successfully, debugging readdir
[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                         continue ;
30                 }
31                 
32                 if( strcmp("ls", argv[i]) == 0 ) {
33                         if( argc - i < 2 ) {
34                                 fprintf(stderr, "ls 1 argument (path)\n");
35                                 exit(-1);
36                         }
37
38                         DiskTool_ListDirectory(argv[i+1]);
39                 }
40         }
41         return 0;
42 }
43
44 // NOTE: This is in a native compiled file because it needs access to the real errno macro
45 int *Threads_GetErrno(void)
46 {
47         return &errno;
48 }
49
50 // TODO: Move into a helper lib?
51 void itoa(char *buf, uint64_t num, int base, int minLength, char pad)
52 {
53         char fmt[] = "%0ll*x";
54         switch(base)
55         {
56         case  8:        fmt[5] = 'o';   break;
57         case 10:        fmt[5] = 'd';   break;
58         case 16:        fmt[5] = 'x';   break;
59         }
60         if(pad != '0') {
61                 fmt[1] = '%';
62                 sprintf(buf, fmt+1, minLength, num);
63         }
64         else {
65                 sprintf(buf, fmt, minLength, num);
66         }
67 }
68
69 int strpos(const char *Str, char Ch)
70 {
71         const char *r = strchr(Str, Ch);
72         if(!r)  return -1;
73         return r - Str;
74 }
75
76 int strucmp(const char *s1, const char *s2)
77 {
78         return strcasecmp(s1, s2);
79 }
80
81 int64_t DivUp(int64_t value, int64_t divisor)
82 {
83         return (value + divisor - 1) / divisor;
84 }
85
86 int64_t timestamp(int sec, int min, int hr, int day, int month, int year)
87 {
88         return 0;
89 }
90

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