/[debian]/mimetic/branches/upstream/current/examples/qp.cxx
ViewVC logotype

Contents of /mimetic/branches/upstream/current/examples/qp.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (show annotations)
Sat Feb 25 16:49:20 2006 UTC (15 years, 5 months ago) by gregoa
File size: 2428 byte(s)
[svn-inject] Installing original source of mimetic
1 /***************************************************************************
2 copyright : (C) 2002-2005 by Stefano Barbato
3 email : stefano@codesink.org
4
5 $Id: qp.cxx,v 1.2 2005/02/23 10:26:14 tat Exp $
6 ***************************************************************************/
7
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16 /** \example qp.cc
17 * Usage: qp [-ed] [in_file [out_file]]
18 *
19 * Quoted-Printable encodes or decodes in_file (or standard input) and writes
20 * output to out_file (or standard output)
21 */
22 #include <iostream>
23 #include <iterator>
24 #include <fstream>
25 #include <mimetic/mimetic.h>
26
27 using namespace std;
28 using namespace mimetic;
29
30 void usage()
31 {
32 cout << "qp [-ed] [in_file [out_file]]" << endl;
33 exit(1);
34 }
35
36 void die_if(bool b, const string& s)
37 {
38 if(b)
39 {
40 cerr << s << endl;
41 exit(-1);
42 }
43 }
44
45
46 int main(int argc, char** argv)
47 {
48 std::ios_base::sync_with_stdio(false);
49 bool encoding = 0;
50 if(argc < 2)
51 usage();
52
53 string opt = argv[1];
54 if(opt == "-e")
55 encoding = true;
56 else if(opt == "-d")
57 encoding = false;
58 else
59 usage();
60
61 filebuf fin;
62 filebuf fout;
63 if(argc > 2)
64 {
65 fin.open(argv[2], ios::in);
66 die_if(!fin.is_open(), string("unable to open file ")+argv[2]);
67 }
68 if(argc > 3)
69 {
70 fout.open(argv[3], ios::out);
71 die_if(!fout.is_open(), string("unable to open file ")+argv[3]);
72 }
73 istream is( fin.is_open() ? &fin : cin.rdbuf());
74 ostream os( fout.is_open() ? &fout : cout.rdbuf());
75 istreambuf_iterator<char> ibeg(is), iend;
76 ostreambuf_iterator<char> out(os);
77 if(encoding)
78 {
79 QP::Encoder qp;
80 encode(ibeg, iend, qp, out);
81 } else {
82 QP::Decoder qp;
83 decode(ibeg, iend, qp, out);
84 }
85 }
86

  ViewVC Help
Powered by ViewVC 1.1.26