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

Contents of /mimetic/branches/upstream/current/examples/mm.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: 2935 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: mm.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 #include <fstream>
17 #include <streambuf>
18 #include <cassert>
19 #include <getopt.h>
20 #include <mimetic/mimetic.h>
21 #include "mm.h"
22 #include "cmdline.h"
23 #include "engine.h"
24
25 using namespace std;
26 using namespace mimetic;
27
28
29 void print_cmd_info()
30 {
31 static const char *cmd_info =
32 "mm " MM_VERSION ", a multipurpose mail tool\n"
33 "Copyright (c) 2003 by Stefano Barbato - All rights reserved.\n";
34 cerr << cmd_info << endl;
35 }
36
37 void do_usage_if(int b, const string& file, int line)
38 {
39 const static char *usage =
40 "WARNING: mm is still under development. It's NOT ready for production!\n"
41 "Usage: mm [MATCH] [ACTION] [INFILE] [OUTFILE]\n" ;
42 if(!b)
43 return;
44 cerr << usage << endl << "[" << file << ":" << line << "]" << endl;
45 exit(1);
46 }
47
48 void do_die_if(int b, const std::string& msg, const string& file, int line)
49 {
50 if(!b)
51 return;
52 cerr << "Error [" << file << ":" << line << "]: " << msg << endl;
53 exit(1);
54 }
55
56
57 int main(int argc, char** argv)
58 {
59 std::ios_base::sync_with_stdio(false);
60 command_line cl;
61
62 die_if(!cl.parse_cmd_line(argc, argv), "command line error");
63
64 string fqn;
65 filebuf fin;
66 filebuf fout;
67 if(cl.is_set("out"))
68 {
69 fqn = cl["out"];
70 fout.open(fqn.c_str(), ios::out);
71 die_if(!fout.is_open(),
72 string("unable to open output file ")+fqn);
73 }
74 if(cl.is_set("in"))
75 {
76 fqn = cl["in"];
77 fin.open(fqn.c_str(), ios::in);
78 die_if(!fin.is_open(),
79 string("unable to open input file ")+fqn);
80 }
81 print_cmd_info();
82 engine e(cl);
83 istream is( fin.is_open() ? &fin : cin.rdbuf());
84 ostream os( fout.is_open() ? &fout : cout.rdbuf());
85 istreambuf_iterator<char> ibeg(is), iend;
86 ostreambuf_iterator<char> out(os);
87 int iMask = (cl.is_set("ignore-child-parts") ? imChildParts: imNone);
88 MimeEntity me(ibeg, iend, iMask);
89 if(!e.match(me))
90 cerr << "not ";
91 cerr << "matched" << endl;
92 return 0;
93 }
94

  ViewVC Help
Powered by ViewVC 1.1.26