]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/tex2rtf/src/rtfutils.cpp
Make _dist_dir a shadow directory of symlinks rather then copied files, and add
[wxWidgets.git] / utils / tex2rtf / src / rtfutils.cpp
index 9e0f5b9ce71124b4281cd17d8c1b901df5e95500..5b0b6386519395befa3cf9e971990744cdba02c5 100644 (file)
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -240,6 +236,7 @@ void WriteWinHelpContentsFileLine(wxChar *topicName, wxChar *xitle, int level)
   wxChar title[255];
   int s=0;
   int d=0;
+  // assuming iso-8859-1 here even in Unicode build (FIXME?)
   while ( (xitle[s]!=0)&&(d<255) )
   {
     wxChar ch=wxChar(xitle[s]&0xff);
@@ -248,12 +245,12 @@ void WriteWinHelpContentsFileLine(wxChar *topicName, wxChar *xitle, int level)
       wxChar ch2=wxChar(xitle[s+2]&0xff);
       wxChar ch3=wxChar(xitle[s+3]&0xff);
       s+=4; // next character
-      if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x36)) { title[d++]=_T('ö');  }
-      if ((ch1==0x27)&&(ch2==0x65)&&(ch3==0x34)) { title[d++]=_T('ä');  }
-      if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x63)) { title[d++]=_T('ü');  }
-      if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x36)) { title[d++]=_T('Ö');  }
-      if ((ch1==0x27)&&(ch2==0x63)&&(ch3==0x34)) { title[d++]=_T('Ä');  }
-      if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x63)) { title[d++]=_T('Ü');  }
+      if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x36)) { title[d++]=wxChar('ö');  }
+      if ((ch1==0x27)&&(ch2==0x65)&&(ch3==0x34)) { title[d++]=wxChar('ä');  }
+      if ((ch1==0x27)&&(ch2==0x66)&&(ch3==0x63)) { title[d++]=wxChar('ü');  }
+      if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x36)) { title[d++]=wxChar('Ö');  }
+      if ((ch1==0x27)&&(ch2==0x63)&&(ch3==0x34)) { title[d++]=wxChar('Ä');  }
+      if ((ch1==0x27)&&(ch2==0x64)&&(ch3==0x63)) { title[d++]=wxChar('Ü');  }
     } else {
       title[d++]=ch;
       s++;
@@ -454,7 +451,7 @@ void WriteRTFHeader(FILE *fd)
 {
   wxFprintf(fd, _T("{\\rtf1\\%s \\deff0\n"), RTFCharset);
   wxFprintf(fd, _T("{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\ftech Symbol;}{\\f2\\fswiss Arial;}\n"));
-  wxFprintf(fd, _T("{\\f3\\fmodern Courier;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}"));
+  wxFprintf(fd, _T("{\\f3\\fmodern Courier New;}{\\f4\\ftech Wingdings;}{\\f5\\ftech Monotype Sorts;}\n}"));
   /*
    * Style sheet
    */
@@ -520,65 +517,65 @@ void OutputNumberStyle(wxChar *numberStyle)
  * Write a Windows help project file
  */
 
-bool WriteHPJ(wxChar *filename)
+bool WriteHPJ(const wxString& filename)
 {
-  wxChar hpjFilename[256];
-  wxChar helpFile[50];
-  wxChar rtfFile[50];
-  wxStrcpy(hpjFilename, filename);
-  StripExtension(hpjFilename);
-  wxStrcat(hpjFilename, _T(".hpj"));
-
-  wxStrcpy(helpFile, wxFileNameFromPath(filename));
-  StripExtension(helpFile);
-  wxStrcpy(rtfFile, helpFile);
-  wxStrcat(helpFile, _T(".hlp"));
-  wxStrcat(rtfFile, _T(".rtf"));
-
-  FILE *fd = wxFopen(hpjFilename, _T("w"));
-  if (!fd)
-    return false;
-
-  wxChar *helpTitle = winHelpTitle;
-  if (!helpTitle)
-    helpTitle = _T("Untitled");
+    wxChar hpjFilename[256];
+    wxChar helpFile[50];
+    wxChar rtfFile[50];
+    wxStrcpy(hpjFilename, filename);
+    StripExtension(hpjFilename);
+    wxStrcat(hpjFilename, _T(".hpj"));
+
+    wxStrcpy(helpFile, wxFileNameFromPath(filename));
+    StripExtension(helpFile);
+    wxStrcpy(rtfFile, helpFile);
+    wxStrcat(helpFile, _T(".hlp"));
+    wxStrcat(rtfFile, _T(".rtf"));
+
+    FILE *fd = wxFopen(hpjFilename, _T("w"));
+    if (!fd)
+        return false;
 
-  wxString thePath = wxPathOnly(InputFile);
-  if (thePath.IsEmpty())
-    thePath = _T(".");
-  wxFprintf(fd, _T("[OPTIONS]\n"));
-  wxFprintf(fd, _T("BMROOT=%s ; Assume that bitmaps are where the source is\n"), thePath.c_str());
-  wxFprintf(fd, _T("TITLE=%s\n"), helpTitle);
-  wxFprintf(fd, _T("CONTENTS=Contents\n"));
+    wxChar *helpTitle = winHelpTitle;
+    if (!helpTitle)
+        helpTitle = _T("Untitled");
 
-  if (winHelpVersion > 3)
-  {
-    wxFprintf(fd, _T("; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n"));
-    wxFprintf(fd, _T("COMPRESS=8 Zeck\n"));
-    wxFprintf(fd, _T("LCID=0x809 0x0 0x0 ;English (British)\n"));
-    wxFprintf(fd, _T("HLP=.\\%s.hlp\n"), wxFileNameFromPath(FileRoot));
-  }
-  else
-  {
-    wxFprintf(fd, _T("COMPRESS=HIGH\n"));
-  }
-  wxFprintf(fd, _T("\n"));
+    wxString thePath = wxPathOnly(InputFile);
+    if (thePath.empty())
+        thePath = _T(".");
+    wxFprintf(fd, _T("[OPTIONS]\n"));
+    wxFprintf(fd, _T("BMROOT=%s ; Assume that bitmaps are where the source is\n"), thePath.c_str());
+    wxFprintf(fd, _T("TITLE=%s\n"), helpTitle);
+    wxFprintf(fd, _T("CONTENTS=Contents\n"));
 
-  if (winHelpVersion > 3)
-  {
-    wxFprintf(fd, _T("[WINDOWS]\n"));
-    wxFprintf(fd, _T("Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n"));
+    if (winHelpVersion > 3)
+    {
+        wxFprintf(fd, _T("; COMPRESS=12 Hall Zeck ; Max compression, but needs lots of memory\n"));
+        wxFprintf(fd, _T("COMPRESS=8 Zeck\n"));
+        wxFprintf(fd, _T("LCID=0x809 0x0 0x0 ;English (British)\n"));
+        wxFprintf(fd, _T("HLP=.\\%s.hlp\n"), wxFileNameFromPath(FileRoot));
+    }
+    else
+    {
+        wxFprintf(fd, _T("COMPRESS=HIGH\n"));
+    }
     wxFprintf(fd, _T("\n"));
-  }
 
-  wxFprintf(fd, _T("[FILES]\n%s\n\n"), rtfFile);
-  wxFprintf(fd, _T("[CONFIG]\n"));
-  if (useUpButton)
-    wxFprintf(fd, _T("CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n"), helpFile);
-  wxFprintf(fd, _T("BrowseButtons()\n\n"));
-  wxFprintf(fd, _T("[MAP]\n\n[BITMAPS]\n\n"));
-  fclose(fd);
-  return true;
+    if (winHelpVersion > 3)
+    {
+        wxFprintf(fd, _T("[WINDOWS]\n"));
+        wxFprintf(fd, _T("Main=\"\",(553,102,400,600),20736,(r14876671),(r12632256),f3\n"));
+        wxFprintf(fd, _T("\n"));
+    }
+
+    wxFprintf(fd, _T("[FILES]\n%s\n\n"), rtfFile);
+    wxFprintf(fd, _T("[CONFIG]\n"));
+    if (useUpButton)
+        wxFprintf(fd, _T("CreateButton(\"Up\", \"&Up\", \"JumpId(`%s', `Contents')\")\n"), helpFile);
+    wxFprintf(fd, _T("BrowseButtons()\n\n"));
+    wxFprintf(fd, _T("[MAP]\n\n[BITMAPS]\n\n"));
+    fclose(fd);
+    return true;
 }
 
 
@@ -670,7 +667,7 @@ void ProcessText2RTF(TexChunk *chunk)
       i += 1;
       changed = true;
     }
-    else if (inVerbatim && (ch == '{' || ch == '}')) // Escape the curley bracket
+    else if (inVerbatim && (ch == '{' || ch == '}')) // Escape the curly bracket
     {
       BigBuffer[ptr] = '\\'; ptr ++;
       BigBuffer[ptr] = ch; ptr ++;
@@ -5169,7 +5166,7 @@ bool RTFGo(void)
   inVerbatim = false;
   browseId = 0;
 
-  if (InputFile && OutputFile)
+  if (!InputFile.empty() && !OutputFile.empty())
   {
     // Do some RTF-specific transformations on all the strings,
     // recursively
@@ -5311,11 +5308,11 @@ bool RTFGo(void)
       if ((wxStrcmp(outputDirStr.c_str(),_T("")) == 0) ||  // no path specified on output file
           (wxStrcmp(cwdStr,outputDirStr.c_str()) == 0)) // paths do not match
       {
-        wxRenameFile(_T("tmp1.rtf"), OutputFile);
+          wxRenameFile(_T("tmp1.rtf"), OutputFile);
       }
       else
       {
-        wxCopyFile(_T("tmp1.rtf"), OutputFile);
+          wxCopyFile(_T("tmp1.rtf"), OutputFile);
       }
       delete [] cwdStr;
       Tex2RTFYield(true);
@@ -5341,7 +5338,7 @@ bool RTFGo(void)
       wxRemoveFile(_T("popups.rtf"));
     }
     if (winHelp && generateHPJ)
-      WriteHPJ(OutputFile);
+        WriteHPJ(OutputFile);
     return true;
   }
   return false;