home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / html / rtf2html / wrtf2htm / html-win.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-21  |  2.4 KB  |  123 lines

  1. /*
  2.  * html-win32.c -- Win32 Console program rtftohtml wrapper
  3.  *
  4.  * Driver provides OpenOutputFile() and Basename() functions for the writer.
  5.  */
  6. #include    <windows.h>
  7. #include    <stdio.h>
  8.  
  9.  
  10. # include    "rtf.h"
  11. //# include    "rtf-unix.h"
  12. # include    "rtftohtml.h"
  13.  
  14. extern HWND ghWndMain;
  15. static char *usage="rtftohtml [-V] [-i] [-G] [-T] [-o filename] [-P extension] file";
  16. static char    *progPath = (char *) NULL;
  17.  
  18. void Win32SetProgPath (path)
  19. char    *path;
  20. {
  21. int    i, j, n;
  22.  
  23.     n = strlen (path);
  24.     for (j = -1, i = 0; i < n; i++)
  25.     {
  26.         if (path[i] == '/')
  27.             j = i;
  28.     }
  29.     if (j < 0)        /* no slash found */
  30.     {
  31.         path = ".";
  32.         j = 1;
  33.     }
  34.     if ((progPath = RTFAlloc (j + 1)) != (char *) NULL)
  35.     {
  36.         (void) strncpy (progPath, path, j);
  37.         progPath[j] = '\0';
  38.     }
  39. }
  40.  
  41. #define LIBDIR "."
  42.  
  43. FILE *
  44. Win32OpenLibFile (file, mode)
  45. char    *file;
  46. char    *mode;
  47. {
  48. FILE    *f;
  49. char    buf[rtfBufSiz];
  50. char    *p;
  51.  
  52.     if ((f = fopen (file, mode)) != (FILE *) NULL)
  53.     {
  54.         return (f);
  55.     }
  56.     /* if abolute pathname, give up, else look in library */
  57.     if (file[0] == '/')
  58.     {
  59.         return ((FILE *) NULL);
  60.     }
  61.     if ((p = getenv ("RTFLIBDIR")) != (char *) NULL)
  62.     {
  63.         sprintf (buf, "%s/%s", p, file);
  64.         if ((f = fopen (buf, mode)) != (FILE *) NULL)
  65.             return (f);
  66.     }
  67.     if (progPath != (char *) NULL)
  68.     {
  69.         sprintf (buf, "%s/%s", progPath, file);
  70.         if ((f = fopen (buf, mode)) != (FILE *) NULL)
  71.             return (f);
  72.     }
  73.     sprintf (buf, "%s/%s", LIBDIR, file);
  74.     f = fopen (buf, mode);    /* NULL if it fails */
  75.     return (f);
  76. }
  77.  
  78.  
  79. int mainconv(int argc,char *argv[])
  80. {
  81.     /* install OS-specific callbacks into RTF library */
  82.     Win32SetProgPath (argv[0]);
  83.     RTFSetOpenLibFileProc (Win32OpenLibFile);
  84.  
  85.     WriterInit ();
  86.     RTFInit ();
  87.     switch (do_main(argc,argv))    /* set up for output file */
  88.     {
  89.     case 1:            /* successful */
  90.         RTFRead ();
  91.         HTMLCleanup();
  92.         break;
  93.     case 0:            /* unsuccessful; die */
  94.         RTFPanic ("Error in input file. Check that input file is RTF format");
  95.     case -1:        /* unsuccessful; print usage message and die*/
  96.         RTFPanic ("Usage: %s", usage);
  97.     }
  98.     return 0;
  99. }
  100.  
  101.  
  102. FILE *
  103. OpenOutputFile (name, mode, fileType)
  104. char    *name;
  105. char    *mode;
  106. int    fileType;    /* ignored */
  107. {
  108.     return (fopen (name, mode));
  109. }
  110.  
  111.  
  112.  # define    pathSep    '/'
  113.  
  114. char * Basename (char *name)
  115. {
  116.     int    i, lsep;
  117.     for(i=0,lsep=0;name[i]!='\0';i++) {
  118.         if(name[i]==pathSep)
  119.             lsep=i+1;
  120.     }
  121.     return (&name[lsep]);
  122. }
  123.