1 |
torben |
132 |
#include <iostream> |
2 |
|
|
#include <fstream> |
3 |
|
|
#include <string> |
4 |
|
|
#include <stdexcept> |
5 |
|
|
|
6 |
|
|
#include <stdlib.h> |
7 |
|
|
|
8 |
|
|
#include "version.h" |
9 |
|
|
#include "Spooler.h" |
10 |
|
|
#include "util.h" |
11 |
|
|
|
12 |
|
|
using namespace std; |
13 |
|
|
|
14 |
|
|
void printUsage() |
15 |
|
|
{ |
16 |
|
|
cout << "smsqueue / " << SVNVERSION << endl; |
17 |
|
|
cout << "Usage: smsqueue <-m message|messagefile> <recipient>" << endl<<endl; |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
|
21 |
|
|
int main(int argc, char* argv[]) |
22 |
|
|
{ |
23 |
|
|
string recipient; |
24 |
|
|
string message; |
25 |
|
|
|
26 |
|
|
if (!(argc == 3 || argc == 4)) { |
27 |
|
|
printUsage(); |
28 |
|
|
return 0; |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
if ( string(argv[1]) == "-m") |
32 |
|
|
{ |
33 |
|
|
if (argc != 4) { |
34 |
|
|
printUsage(); |
35 |
|
|
return 0; |
36 |
|
|
} |
37 |
|
|
message = string(argv[2]); |
38 |
|
|
recipient = string(argv[3]); |
39 |
|
|
} |
40 |
|
|
else |
41 |
|
|
{ |
42 |
|
|
if (argc != 3) { |
43 |
|
|
printUsage(); |
44 |
|
|
return 0; |
45 |
|
|
} |
46 |
|
|
try { |
47 |
|
|
message = Util::readfile(string(argv[1])); |
48 |
|
|
} catch(exception& e) { |
49 |
|
|
cout << e.what() << endl; |
50 |
|
|
return -1; |
51 |
|
|
} |
52 |
|
|
recipient = string(argv[2]); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
srand(time(0)); |
56 |
|
|
|
57 |
|
|
Spooler spool; |
58 |
|
|
|
59 |
|
|
try { |
60 |
|
|
spool.enqueue(recipient,message); |
61 |
torben |
134 |
cout << "enqueued as: " << spool.getFilename() << endl; |
62 |
torben |
132 |
} catch (std::exception& e) { |
63 |
|
|
cout << e.what() << endl; |
64 |
|
|
return -1; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
return 0; |
68 |
|
|
} |