This commit was manufactured by cvs2svn to create tag 'REL-1-6-3RC'.
[m17n/m17n-docs.git] / utils / imdoc.c
index 346da2f..ed5d820 100644 (file)
@@ -17,6 +17,8 @@ invalid_file (char *filename)
   exit (1);
 }
 
+#define INHIBIT_TITLE
+
 int
 main (int argc, char **argv)
 {
@@ -103,10 +105,16 @@ main (int argc, char **argv)
        {
          MText *title = mplist_value (plist);
          
+#ifndef INHIBIT_TITLE
          printf ("@htmlonly\n title:\"");
+#else
+         printf ("@htmlonly\n");
+#endif
          plist = mplist_next (plist);
+#ifndef INHIBIT_TITLE
          mconv_encode_stream (Mutf8, title, stdout);
          printf ("\"");
+#endif
          if (mplist_key (plist) != Mnil)
            {
              MText *icon = mplist_value (plist);
@@ -114,11 +122,17 @@ main (int argc, char **argv)
                                           NULL, NULL, NULL);
              char *base;
              char cmd[1024];
+             int result;
 
              base = basename (strdup (iconfile));
              sprintf (cmd, "convert -resize 50%% %s images/icon-%s",
                       iconfile, base);
-             system (cmd);
+             result = system (cmd);
+             if (result != 0)
+               {
+                 fprintf (stderr, "Command fail: %s", cmd);
+                 exit (1);
+               }
              printf (" icon:<img src=\"icon-%s\" border=\"1\" style=\"vertical-align:middle;\">\n", base);
            }
          else
@@ -161,11 +175,46 @@ main (int argc, char **argv)
     }
   else
     {
+      MConverter *converter = mconv_stream_converter (Mutf8, stdout);
+      int len = mtext_len (mt), i, c;
+      int has_non_ascii = 0;
+      
+      if (mtext_ref_char (mt, len - 1) != '\n')
+       {
+         mtext_ins_char (mt, len, '\n', 1);
+         len ++;
+       }
+
+      for (i = 0; i < len; i++)
+       {
+         c = mtext_ref_char (mt, i);
+         if (c >= 0x100)
+           {
+             has_non_ascii = 1;
+             break;
+           }
+       }
+      if (has_non_ascii)
+       printf ("@if FOR_HTML\n");
       printf ("@verbatim\n");
-      mconv_encode_stream (msymbol ("utf-8"), mt, stdout);
-      if (mtext_ref_char (mt, mtext_len (mt) - 1) != '\n')
-       printf ("\n");
+      mconv_encode_stream (Mutf8, mt, stdout);
       printf ("@endverbatim\n");
+      if (has_non_ascii)
+       {
+         printf ("@endif\n@if FOR_LATEX\n");
+         printf ("@verbatim\n");
+         for (i = 0; i < len; i++)
+           {
+             c = mtext_ref_char (mt, i);
+             if (c >= 0x100)
+               printf ("<U+%04X>", c);
+             else
+               putchar (c);
+           }
+         printf ("@endverbatim\n");
+         printf ("@endif\n");
+       }
+      mconv_free_converter (converter);
     }
 
   M17N_FINI ();