ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/VTBFileUtil2.cxx
Revision: 255
Committed: 2003-08-15T17:12:57-07:00 (21 years, 10 months ago) by douglas
File size: 1924 byte(s)
Log Message:
Added files.

File Contents

# User Rev Content
1 douglas 255 // Vance Thrift and Biller File Utility 2
2     //
3     // Douglas Thrift
4     //
5     // $Id: VTBFileUtil2.cxx,v 1.1 2003/08/16 00:12:57 douglas Exp $
6    
7     #include "VTBFileUtil2.h"
8    
9     #include <io.h>
10     #include <fcntl.h>
11    
12     bool debug = false;
13     string program;
14     string programName = "Vance Thrift and Biller File Utility 2";
15     unsigned programVersion = 0x00101000;
16    
17     inline void arguments(vector<string>& args, const string& command)
18     {
19     istringstream line(command);
20     string arg;
21    
22     do
23     {
24     if (line.peek() == '\"')
25     {
26     line.get();
27     getline(line, arg, '\"');
28     }
29     else
30     {
31     line >> arg;
32     line.get();
33     }
34    
35     args.push_back(arg);
36     }
37     while (line.good());
38     }
39    
40     inline void munge(void)
41     {
42     AllocConsole();
43     SetConsoleTitle("Renegade Map Selector");
44    
45     int hin = _open_osfhandle(long(GetStdHandle(STD_INPUT_HANDLE)), _O_TEXT);
46     int hout = _open_osfhandle(long(GetStdHandle(STD_OUTPUT_HANDLE)), _O_TEXT);
47     int herr = _open_osfhandle(long(GetStdHandle(STD_ERROR_HANDLE)), _O_TEXT);
48    
49     FILE* fin = _fdopen(hin, "r");
50     FILE* fout = _fdopen(hout, "w");
51     FILE* ferr = _fdopen(herr, "w");
52    
53     *stdin = *fin;
54     *stdout = *fout;
55     *stderr = *ferr;
56    
57     setvbuf(stdin, NULL, _IONBF, 0);
58     setvbuf(stdout, NULL, _IONBF, 0);
59     setvbuf(stderr, NULL, _IONBF, 0);
60    
61     cin.sync_with_stdio();
62     cout.sync_with_stdio();
63     cerr.sync_with_stdio();
64     }
65    
66     int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
67     lpCmdLine, int nShowCmd)
68     {
69     vector<string> args;
70    
71     arguments(args, GetCommandLine());
72    
73     program = args[0];
74    
75     for (unsigned index = 1; index < args.size(); index++)
76     {
77     if (args[index] == "-help")
78     {
79     usage();
80     return 0;
81     }
82     else if (args[index] == "-version")
83     {
84     version();
85     return 0;
86     }
87     else if (args[index] == "-disc")
88     {
89     //
90     }
91     else if (args[index] == "-scan")
92     {
93     //
94     }
95     else if (args[index] == "-D")
96     {
97     if (!debug)
98     {
99     debug = true;
100    
101     munge();
102     }
103     }
104     }
105    
106     return 0;
107     }
108    
109     void usage(void)
110     {
111     //
112     }
113    
114     void version(void)
115     {
116     //
117     }