The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
modwrite.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * modwrite.cpp -
4  *
5  * $Id: modwrite.cpp 3063 2014-03-04 13:04:11Z chrislit $
6  *
7  * Copyright 2000-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 #ifdef _MSC_VER
24  #pragma warning( disable: 4251 )
25 #endif
26 
27 #include <fcntl.h>
28 #include <iostream>
29 #include <fstream>
30 //#include <string>
31 
32 #ifndef __GNUC__
33 #include <io.h>
34 #else
35 #include <unistd.h>
36 #endif
37 
38 #include <swmgr.h>
39 #include <swmodule.h>
40 #include <stdio.h>
41 
42 #ifndef NO_SWORD_NAMESPACE
43 using sword::SWMgr;
44 using sword::SWModule;
45 using sword::ModMap;
46 using sword::SWKey;
47 #endif
48 
49 using std::cerr;
50 
51 int main(int argc, char **argv)
52 {
53  int action = 0;
54 
55  if ((argc < 4) || (argc > 6)) {
56  cerr << "usage: " << argv[0] << " <mod_name> <key> <key|buf|""-delete> [0(deflt) - normal; 1 - link]\n";
57  exit(-1);
58  }
59 
60  if (argc > 4)
61  action = atoi(argv[4]);
62 
63  SWMgr mgr;
64 
65  ModMap::iterator it = mgr.Modules.find(argv[1]);
66  if (it == mgr.Modules.end()) {
67  fprintf(stderr, "error: %s: couldn't find module: %s \n", argv[0], argv[1]);
68  exit(-2);
69  }
70 
71  SWModule *module = it->second;
72  module->setKey(argv[2]);
73 
74  switch (action) {
75  case 0:
76  if (strlen(argv[3]))
77  (*module) << argv[3];
78  else module->deleteEntry();
79  break;
80  case 1:
81  (*module) << (SWKey)argv[3];
82  break;
83  default:
84  cerr << "Unknown action " << action << "\n";
85  exit(-3);
86  }
87 }
Definition: swmgr.h:93
virtual void deleteEntry()
Definition: swmodule.h:525
ModMap Modules
Definition: swmgr.h:322
SWText * module
Definition: osis2mod.cpp:105
virtual char setKey(const SWKey *ikey)
Definition: swmodule.cpp:298
int main(int argc, char **argv)
Definition: addcomment.cpp:32
std::map< SWBuf, SWModule *, std::less< SWBuf > > ModMap
Definition: swmgr.h:74
Definition: swkey.h:77
SWMgr * mgr
Definition: installmgr.cpp:46