The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mod2vpl.cpp File Reference
#include <swmgr.h>
#include <swmodule.h>
#include <swkey.h>
#include <versekey.h>
#include <stdio.h>
#include <iostream>
+ Include dependency graph for mod2vpl.cpp:

Go to the source code of this file.

Functions

void cleanbuf (char *buf)
 
int main (int argc, char **argv)
 

Function Documentation

void cleanbuf ( char *  buf)

Definition at line 43 of file mod2vpl.cpp.

43  {
44  char *from = buf;
45  char *to = buf;
46 
47  while (*from) {
48  if ((*from != 10) && (*from != 13)) {
49  *to++ = *from++;
50  }
51  else {
52  from++;
53  }
54  }
55  *to = 0;
56 }
int main ( int  argc,
char **  argv 
)

Definition at line 58 of file mod2vpl.cpp.

58  {
59  char *buffer = 0;
60 
61  if (argc < 2) {
62  fprintf(stderr, "usage: %s <Mod Name> [0|1 - prepend verse reference to each line]\n", argv[0]);
63  exit(-1);
64  }
65 
66  SWMgr mgr;
67 
68  ModMap::iterator it = mgr.Modules.find(argv[1]);
69  if (it == mgr.Modules.end()) {
70  fprintf(stderr, "error: %s: couldn't find module: %s \n", argv[0], argv[1]);
71  exit(-2);
72  }
73 
74  bool vref = false;
75  if (argc > 2)
76  vref = (argv[2][0] == '0') ? false : true;
77 
78 
79  SWModule *mod = it->second;
80 
81  SWKey *key = (*mod);
82  VerseKey *vkey = 0;
83  SWTRY {
84  vkey = dynamic_cast<VerseKey *>(key);
85  }
86  SWCATCH (...) {}
87 
88  if (!vkey) {
89  fprintf(stderr, "error: %s: %s module is not keyed to verses \n", argv[0], argv[1]);
90  exit(-3);
91  }
92 
93  vkey->setIntros(true); // turn on mod/testmnt/book/chap headings
94 
95  (*mod) = TOP;
96 
97  while (!mod->popError()) {
98  buffer = new char [ mod->renderText().length() + 1 ];
99  strcpy(buffer, mod->renderText());
100  cleanbuf(buffer);
101  if (vref) {
102  if ((strlen(buffer) > 0) && (vref)) {
103  std::cout << (const char *)(*vkey) << " ";
104  std::cout << buffer << std::endl;
105  }
106  }
107  else std::cout << buffer << std::endl;
108 
109  delete [] buffer;
110  (*mod)++;
111  }
112 }
#define TOP
Definition: swkey.h:68
Definition: swmgr.h:93
unsigned long length() const
Definition: swbuf.h:197
ModMap Modules
Definition: swmgr.h:322
preg buffer
Definition: regex.c:8089
#define SWTRY
Definition: defs.h:57
SWBuf renderText(const char *buf, int len=-1, bool render=true) const
Definition: swmodule.cpp:1038
virtual void setIntros(bool val)
Definition: versekey.cpp:1663
#define SWCATCH(x)
Definition: defs.h:58
virtual char popError()
Definition: swmodule.cpp:185
void cleanbuf(char *buf)
Definition: mod2vpl.cpp:43
Definition: swkey.h:77
SWMgr * mgr
Definition: installmgr.cpp:46