Advertisement
kalemas

Untitled

Mar 17th, 2014
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.99 KB | None | 0 0
  1. diff --git a/include/swld.h b/include/swld.h
  2. index ced6707..d47536f 100644
  3. --- a/include/swld.h
  4. +++ b/include/swld.h
  5. @@ -36,9 +36,10 @@ SWORD_NAMESPACE_START
  6.  class SWDLLEXPORT SWLD : public SWModule {
  7.  protected:
  8.     mutable char *entkeytxt;
  9. -   static void strongsPad(char *buf);
  10.     bool strongsPadding;
  11. +
  12.  public:
  13. +
  14.     /** Initializes data for instance of SWLD
  15.     */
  16.     SWLD(const char *imodname = 0, const char *imoddesc = 0,
  17. @@ -65,6 +66,13 @@ public:
  18.    
  19.     virtual bool hasEntry(const SWKey *k) const;
  20.  
  21. +
  22. +   /** Pads a key if (it-1) is 100% digits to 5 places allows for final to be alpha, e.g. '123B'
  23. +   *
  24. +   * @param[in,out] buffer to check and pad
  25. +   */
  26. +   static void strongsPad(char *buffer);
  27. +
  28.     // OPERATORS -----------------------------------------------------------------
  29.    
  30.     SWMODULE_OPERATORS
  31. diff --git a/src/modules/common/rawstr.cpp b/src/modules/common/rawstr.cpp
  32. index 79c7cf2..a5ac41c 100644
  33. --- a/src/modules/common/rawstr.cpp
  34. +++ b/src/modules/common/rawstr.cpp
  35. @@ -165,7 +165,7 @@ void RawStr::getIDXBuf(long ioffset, char **buf) const
  36.   *     away        - number of entries before of after to jump
  37.   *                 (default = 0)
  38.   *
  39. - * RET: error status -1 general error; -2 new file
  40. + * RET: error status -1 general error; -2 new file; -3 inconsecutive index
  41.   */
  42.  
  43.  signed char RawStr::findOffset(const char *ikey, __u32 *start, __u16 *size, long away, __u32 *idxoff) const
  44. @@ -274,6 +274,11 @@ signed char RawStr::findOffset(const char *ikey, __u32 *start, __u16 *size, long
  45.             if (idxoff)
  46.                 *idxoff = tryoff;
  47.  
  48. +           if(away > 0 && tmpStart < *start) {
  49. +               SWLog::getSystemLog()->logError("inconsequtive index for module at path %s", path);
  50. +               retval = -3;
  51. +           }
  52. +
  53.             *start = swordtoarch32(tmpStart);
  54.             *size  = swordtoarch16(tmpSize);
  55.  
  56. diff --git a/src/modules/common/rawstr4.cpp b/src/modules/common/rawstr4.cpp
  57. index 9acbe4d..d14e11d 100644
  58. --- a/src/modules/common/rawstr4.cpp
  59. +++ b/src/modules/common/rawstr4.cpp
  60. @@ -174,7 +174,7 @@ void RawStr4::getIDXBuf(long ioffset, char **buf) const
  61.   *     away        - number of entries before of after to jump
  62.   *                 (default = 0)
  63.   *
  64. - * RET: error status -1 general error; -2 new file
  65. + * RET: error status -1 general error; -2 new file; -3 inconsecutive index
  66.   */
  67.  
  68.  signed char RawStr4::findOffset(const char *ikey, __u32 *start, __u32 *size, long away, __u32 *idxoff) const
  69. @@ -283,6 +283,11 @@ signed char RawStr4::findOffset(const char *ikey, __u32 *start, __u32 *size, lon
  70.             if (idxoff)
  71.                 *idxoff = tryoff;
  72.  
  73. +           if(away > 0 && tmpStart < *start) {
  74. +               SWLog::getSystemLog()->logError("inconsequtive index for module at path %s", path);
  75. +               retval = -3;
  76. +           }
  77. +
  78.             *start = swordtoarch32(tmpStart);
  79.             *size  = swordtoarch32(tmpSize);
  80.  
  81. diff --git a/utilities/imp2ld.cpp b/utilities/imp2ld.cpp
  82. index a9745cf..8174e74 100644
  83. --- a/utilities/imp2ld.cpp
  84. +++ b/utilities/imp2ld.cpp
  85. @@ -48,10 +48,12 @@ void usage(const char *progName, const char *error = 0) {
  86.     fprintf(stderr, "  -a\t\t\t augment module if exists (default is to create new)\n");
  87.     fprintf(stderr, "  -z\t\t\t use ZIP compression (default no compression)\n");
  88.     fprintf(stderr, "  -Z\t\t\t use LZSS compression (default no compression)\n");
  89. -   fprintf(stderr, "  -o <output_path>\t where to write data files.\n");
  90. +   fprintf(stderr, "  -o <output_path>\t\t where to write data files.\n");
  91.     fprintf(stderr, "  -4\t\t\t use 4 byte size entries (default is 2).\n");
  92.     fprintf(stderr, "  -b <entry_count>\t\t compression block size (default 30 entries)\n");
  93.     fprintf(stderr, "  -s\t\t\t case sensitive keys (default is not case sensitive)\n");
  94. +   fprintf(stderr, "  -P\t\t\t disable Strong's number padding check for digit entries. "
  95. +       "Incorrect padding without StrongsPadding=false in you conf file will cause eternal loop.\n");
  96.     fprintf(stderr, "\n");
  97.     fprintf(stderr, "'imp' format is a simple standard for importing data into SWORD modules.\n"
  98.         "Required is a plain text file containing $$$key lines followed by content.\n\n"
  99. @@ -79,6 +81,7 @@ int main(int argc, char **argv) {
  100.     SWCompress *compressor = 0;
  101.     SWBuf compType         = "";
  102.     bool fourByteSize      = false;
  103. +    bool paddingCheck      = true;
  104.  
  105.     if (argc < 2) usage(*argv);
  106.  
  107. @@ -102,6 +105,9 @@ int main(int argc, char **argv) {
  108.         else if (!strcmp(argv[i], "-4")) {
  109.             fourByteSize = true;
  110.         }
  111. +        else if (!strcmp(argv[i], "-P")) {
  112. +            paddingCheck = false;
  113. +        }
  114.         else if (!strcmp(argv[i], "-b")) {
  115.             if (i+1 < argc) {
  116.                 blockCount = atoi(argv[++i]);
  117. @@ -129,6 +135,10 @@ int main(int argc, char **argv) {
  118.  
  119.     std::ifstream infile(inFileName);
  120.  
  121. +   if(!infile.is_open()) {
  122. +       std::cout << "Unable to open file " << inFileName << std::endl;
  123. +       return -1;
  124. +   }
  125.  
  126.     SWModule *mod = 0;
  127.     SWKey *key, *linkKey;
  128. @@ -185,6 +195,15 @@ int main(int argc, char **argv) {
  129.                 std::cout << keybuffer << std::endl;
  130.                 *key = keybuffer.c_str();
  131.  
  132. +               if(paddingCheck) {
  133. +                   char *buf = new char [ strlen(*key) + 6 ];
  134. +                   strcpy(buf, *key);
  135. +                   SWLD::strongsPad(buf);
  136. +                   if(strcmp(buf, *key))
  137. +                       std::cout << "Warning: entry " << *key << " is a number but not padded correctly. ";
  138. +                   delete buf;
  139. +               }
  140. +
  141.                 mod->setEntry(entbuffer.c_str(), entbuffer.size());
  142.                 for (i = 0; i < links; i++) {
  143.                     std::cout << "Linking: " << linkbuffer[i] << std::endl;
  144. @@ -213,6 +232,15 @@ int main(int argc, char **argv) {
  145.         std::cout << keybuffer << std::endl;
  146.         *key = keybuffer.c_str();
  147.  
  148. +       if(paddingCheck) {
  149. +           char *buf = new char [ strlen(*key) + 6 ];
  150. +           strcpy(buf, *key);
  151. +           SWLD::strongsPad(buf);
  152. +           if(strcmp(buf, *key))
  153. +               std::cout << "Warning: entry " << *key << " is a number but not padded correctly. ";
  154. +           delete buf;
  155. +       }
  156. +      
  157.         mod->setEntry(entbuffer.c_str(), entbuffer.size());
  158.         for (i = 0; i < links; i++) {
  159.             std::cout << "Linking: " << linkbuffer[i] << std::endl;
  160. @@ -224,7 +252,6 @@ int main(int argc, char **argv) {
  161.     infile.close();
  162.  
  163.     delete linkKey;
  164. -   delete key;
  165.     delete mod;
  166.  
  167.     return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement