utilities/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 38 of file mod2vpl.cpp.

00038                          {
00039     char *from = buf;
00040     char *to = buf;
00041 
00042     while (*from) {
00043         if ((*from != 10) && (*from != 13)) {
00044             *to++ = *from++;
00045         }
00046         else {
00047             from++;
00048         }
00049     }
00050     *to = 0;
00051 }

int main ( int  argc,
char **  argv 
)

Definition at line 53 of file mod2vpl.cpp.

00053                                 {
00054     char *buffer = 0;
00055 
00056     if (argc < 2) {
00057         fprintf(stderr, "usage: %s <Mod Name> [0|1 - prepend verse reference to each line]\n", argv[0]);
00058         exit(-1);
00059     }
00060 
00061     SWMgr mgr;
00062 
00063     ModMap::iterator it = mgr.Modules.find(argv[1]);
00064     if (it == mgr.Modules.end()) {
00065         fprintf(stderr, "error: %s: couldn't find module: %s \n", argv[0], argv[1]);
00066         exit(-2);
00067     }
00068 
00069     bool vref = false;
00070     if (argc > 2)
00071         vref = (argv[2][0] == '0') ? false : true;
00072 
00073 
00074     SWModule *mod = it->second;
00075 
00076     SWKey *key = (*mod);
00077     VerseKey *vkey = 0;
00078     SWTRY {
00079         vkey = dynamic_cast<VerseKey *>(key);
00080     }
00081     SWCATCH (...) {}
00082 
00083     if (!vkey) {
00084         fprintf(stderr, "error: %s: %s module is not keyed to verses \n", argv[0], argv[1]);
00085         exit(-3);
00086     }
00087 
00088     vkey->setIntros(true);  // turn on mod/testmnt/book/chap headings
00089 
00090     (*mod) = TOP;
00091 
00092     while (!mod->popError()) {
00093         buffer = new char [ strlen ((const char *)(*mod)) + 1 ];
00094         strcpy(buffer, (const char *)(*mod));
00095         cleanbuf(buffer);
00096         if (vref) {
00097             if ((strlen(buffer) > 0) && (vref)) {
00098                 std::cout << (const char *)(*vkey) << " ";
00099                 std::cout << buffer << std::endl;
00100             }
00101         }
00102         else std::cout << buffer << std::endl;
00103 
00104         delete [] buffer;
00105         (*mod)++;
00106     }
00107 }


Generated on 18 Mar 2013 for The SWORD Project by  doxygen 1.6.1