-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.cpp
75 lines (63 loc) · 1.82 KB
/
main.cpp
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
#include "CStackFile.h"
#include <iostream>
#include <climits>
#include <unistd.h>
void RunTests();
// Arguments as string for syntax info
#define SYNTAXSTR "[--dumprawblocks] [--nostatus] [--noprogress] [--rawgraphics] <originalStackPath>"
int main( int argc, char * const argv[] )
{
#if DEBUG
RunTests();
#endif
CStackFile theStack;
if( argc < 2 )
{
fprintf( stderr, "Error: Syntax is %s " SYNTAXSTR "\n", argv[0] );
return 2;
}
int x = 1; // Skip command name in argv[0].
if( argc > 2 )
{
for( ; x < argc; x++ )
{
if( strcmp(argv[x],"--dumprawblocks") == 0 )
theStack.SetDumpRawBlockData( true );
else if( strcmp(argv[x],"--nostatus") == 0 )
theStack.SetStatusMessages( false );
else if( strcmp(argv[x],"--noprogress") == 0 )
theStack.SetProgressMessages( false );
else if( strcmp(argv[x],"--rawgraphics") == 0 )
theStack.SetDecodeGraphics( false );
else if( argv[x][0] == '-' )
{
fprintf( stderr, "Error: Unknown option %s, syntax is %s " SYNTAXSTR "\n", argv[x], argv[0] );
return 3;
}
else // Doesn't start with a dash? Must be pathname!
break; // End of options, exit loop.
}
}
if( x >= argc ) // Only options, no file path?
{
fprintf( stderr, "Error: Syntax is %s " SYNTAXSTR "\n", argv[0] );
return 4;
}
const char* fpath = argv[x];
char fullpath[PATH_MAX +1] = {0}; // Outside so we can assign it to fpath and it stays alive.
if( fpath[0] != '/' )
{
getcwd( fullpath, PATH_MAX );
size_t len = strlen(fullpath);
if( fullpath[len-1] != '/' )
fullpath[len++] = '/';
strncat( fullpath, fpath, PATH_MAX );
fpath = fullpath;
}
if( !theStack.LoadFile( fpath ) )
{
fprintf( stderr, "Error: Conversion of '%s' incomplete/failed.\n", fpath );
return 5;
}
return 0;
}