Ejemplo n.º 1
0
/* dump out a Paragraph in the desired manner
 */
static Paragraph*
display(Paragraph *p, MMIOT *f)
{
    if ( !p ) return 0;
    
    switch ( p->typ ) {
    case STYLE:
    case WHITESPACE:
	break;

    case HTML:
	printhtml(p->text, f);
	break;
	
    case CODE:
	printcode(p->text, f);
	break;
	
    case QUOTE:
	htmlify(p->down, p->ident ? "div" : "blockquote", p->ident, f);
	break;
	
    case UL:
    case OL:
    case AL:
	listdisplay(p->typ, p->down, f);
	break;

#if DL_TAG_EXTENSION
    case DL:
	definitionlist(p->down, f);
	break;
#endif

    case HR:
	Qstring("<hr />", f);
	break;

    case HDR:
	printheader(p, f);
	break;

    case TABLE:
	printtable(p, f);
	break;

    case SOURCE:
	htmlify(p->down, 0, 0, f);
	break;
	
    default:
	printblock(p, f);
	break;
    }
    return p->next;
}
Ejemplo n.º 2
0
void
#elif  __linux__
int 
#endif
main(int argc, char **argv)
{
   // Directory
   std::string sDir = argv[1];
#ifdef _WIN32
   HANDLE          hList;
   WIN32_FIND_DATA FileData;
   std::string sDirPattern;
#elif  __linux__
   // Directory pointer
   DIR *pDir;
   // pointer to the directory entry
   struct dirent *pEntry;
#endif

   // Language
   std::string sLanguage = argv[2];
   int iLanguage = initLanguage(sLanguage);

   // Verifying if the directory exist
   if (!isDir(sDir)) {
      exit(1);
   }

#ifdef __linux__
   // Open the directory
   if ((pDir = opendir(sDir.c_str())) == NULL) {
      std::cerr << __FILE__ << ":" << __LINE__ << " "
           << "Error in opendir() [" << sDir << "] " << std::endl
           << "errno (" << errno << ")" << std::endl;
      exit(1);
   }
#endif

#ifdef _WIN32
   sDirPattern = sDir;
   sDirPattern += "\\*";
   // Get the first file
   if ((hList = FindFirstFile(sDirPattern.c_str(), &FileData)) == INVALID_HANDLE_VALUE)
#elif  __linux__
   if ((pEntry = readdir(pDir)) == NULL)
#endif
   {
     std::cerr << __FILE__ << ":" << __LINE__ << " "
          << "No files found" << std::endl
          << "errno (" << errno << ")" << std::endl;
     exit(1);
   }
   // Directory: read entries
   do 
   {
#ifdef _WIN32
      char *pFileName = FileData.cFileName;
#elif  __linux__
      char *pFileName = pEntry->d_name;
#endif

      std::string sFileType;
      off_t st_size = 0;     // total size, in bytes
      if ((st_size = processEntryDirectoryName(sDir, pFileName, sFileType)) == -1) {
         continue;
      }

      // Obtaining the short name of the book
      std::string sBook;
      getBookShortName(pFileName, sFileType.length(), sBook);
      std::cerr << "Book [" << sBook << "]" << std::endl;

      // Obtain the authors
      std::string sAuthors = "-";
      {
         const int N = strlen(pFileName);
         const int M = 1;
         char *token = "-";
         char *pszAuthors0= std::find_end(pFileName,
                                          pFileName + N,
                                          token, token + M);
         if (pszAuthors0 != (pFileName + N)) {
            while (*pszAuthors0== ' ' ||
                   *pszAuthors0== '-') {
               ++pszAuthors0;
            }
            const int L0 = strlen(pszAuthors0);
            const int L = L0 - sFileType.length() - 1;
            if (L > 3) {
               char *pszAuthors1 = new char[L0];
               memcpy(pszAuthors1, pszAuthors0, L);
               pszAuthors1[L] = 0;
               sAuthors = pszAuthors1;
            }
         }
      }
      std::cerr << "Authors [" << sAuthors << "]" << std::endl;

      // create an instance of the book structure, and save it in the vector
      {
      stBooks b;
      std::string sFile(pFileName);
      b.sFile = sFile;
      b.sFileType = sFileType;
      b.sBook = sBook;
      b.sAuthors = sAuthors;
      b.st_size = st_size;

      vBooks.push_back(b);
      }
   }
#ifdef _WIN32
   while (FindNextFile(hList, &FileData));
#elif  __linux__
   while ((pEntry = readdir(pDir)) != NULL);
#endif

   if (vBooks.size()) {
      // Sort the vector
      std::stable_sort(vBooks.begin(), vBooks.end(), std::ptr_fun(byBook));
      // Print all the books
      printhtml(sDir, iLanguage);
   }
   exit(0);
}
Ejemplo n.º 3
0
/* dump out a Paragraph in the desired manner
 */
static Paragraph*
display(Paragraph *p, MMIOT *f, int easyNewLine)
{
    if ( !p ) return 0;

    switch ( p->typ ) {
    case STYLE:
    case WHITESPACE:
	break;

    case HTML:
	printhtml(p->text, f);
	break;
	
    case CODE:
	printcode(p->text, f);
	break;
	
    case QUOTE:
    if (p->down) {
        p->down->easyNewline = p->easyNewline;
    }
	htmlify(p->down, p->ident ? "div" : "blockquote", p->ident, f);
	break;
	
    case UL:
    case OL:
    case AL:
	listdisplay(p->typ, p->down, f);
	break;

    case DL:
	definitionlist(p->down, f);
	break;

    case HR:
	Qstring("<hr />", f);
	break;

    case HDR:
	printheader(p, f);
	break;

    case TABLE:
	printtable(p, f);
	break;

    case SOURCE:
    if (p->down) {
        p->down->easyNewline = p->easyNewline;
    }
	htmlify(p->down, 0, 0, f);
	break;
	
    default:
	printblock(p, f, easyNewLine);
	break;
    }
    // MK HACK, copy easyNewLine
    Paragraph *pNext = p->next;
    if (pNext) {
        pNext->easyNewline = p->easyNewline;
    }
    return pNext;
}
Ejemplo n.º 4
0
void
#elif  __linux__
int 
#endif
main(int argc, char **argv)
{
   // Directory
   std::string sDir = argv[1];
#ifdef _WIN32
   HANDLE          hList;
   WIN32_FIND_DATA FileData;
   std::string sDirPattern;
#elif  __linux__
   // Directory pointer
   DIR *pDir;
   // pointer to the directory entry
   struct dirent *pEntry;
#endif

   // Language
   std::string sLanguage = argv[2];
   int iLanguage = initLanguage(sLanguage);

   // Verifying if the directory exist
   if (!isDir(sDir)) {
      exit(1);
   }

#ifdef __linux__
   // Open the directory
   if ((pDir = opendir(sDir.c_str())) == NULL) {
      std::cerr << __FILE__ << ":" << __LINE__ << " "
           << "Error in opendir() [" << sDir << "] " << std::endl
           << "errno (" << errno << ")" << std::endl;
      exit(1);
   }
#endif

#ifdef _WIN32
   sDirPattern = sDir;
   sDirPattern += "\\*";
   // Get the first file
   if ((hList = FindFirstFile(sDirPattern.c_str(), &FileData)) == INVALID_HANDLE_VALUE)
#elif  __linux__
   if ((pEntry = readdir(pDir)) == NULL)
#endif
   {
     std::cerr << __FILE__ << ":" << __LINE__ << " "
          << "No files found" << std::endl
          << "errno (" << errno << ")" << std::endl;
     exit(1);
   }
   // Directory: read entries
   do 
   {
#ifdef _WIN32
      char *pFileName = FileData.cFileName;
#elif  __linux__
      char *pFileName = pEntry->d_name;
#endif

      std::string sFileType;
      off_t st_size = 0;     // total size, in bytes
      // process the file entry
      if ((st_size = processEntryDirectoryName(sDir, pFileName, sFileType)) == -1) {
         continue;
      }

      // Obtaining the Long name of the book
      std::string sBook;
      getBookLongName(pFileName, sFileType.length(), sBook);
      std::cerr << "Book [" << sBook << "]" << std::endl;

      // create an instance of the book structure, and save it in the vector
      {
      stBooks b;
      std::string sFile(pFileName);
      b.sFile = sFile;
      b.sFileType = sFileType;
      b.sBook = sBook;
      b.st_size = st_size;

      vBooks.push_back(b);
      }
   }
#ifdef _WIN32
   while (FindNextFile(hList, &FileData));
#elif  __linux__
   while ((pEntry = readdir(pDir)) != NULL);
#endif

   if (vBooks.size()) {
      // Sort the vector
      std::stable_sort(vBooks.begin(), vBooks.end(), std::ptr_fun(byBook));
      // Print all the books
      printhtml(sDir, iLanguage);
   }
   exit(0);
}