10 struct CommentList *next;
14 invalid_file (char *filename)
16 fprintf (stderr, "Invalid input method file: %s\n", filename);
21 main (int argc, char **argv)
25 MSymbol language, name;
29 struct CommentList *head_comment = NULL, *cur_comment = NULL;
30 MSymbol Minput_method, Mutf8;
32 setlocale (LC_ALL, "");
34 Minput_method = msymbol ("input-method");
35 Mutf8 = msymbol ("utf-8");
39 fprintf (stderr, "Usage: imdoc FILE\n");
42 fp = fopen (argv[1], "r");
45 fprintf (stderr, "Usage: imdoc FILE\n");
48 while (fgets (buf, 256, fp)
51 if (buf[0] == ';' && buf[1] == ';' && buf[2] == ';')
55 cur_comment = head_comment = alloca (sizeof (struct CommentList));
59 cur_comment->next = alloca (sizeof (struct CommentList));
60 cur_comment = cur_comment->next;
62 strcpy (cur_comment->line, buf + 4);
63 cur_comment->next = NULL;
67 invalid_file (argv[1]);
68 mt = mtext_from_data (buf, strlen (buf), MTEXT_FORMAT_US_ASCII);
69 plist = mplist_deserialize (mt);
70 m17n_object_unref (mt);
72 invalid_file (argv[1]);
73 plist = mplist_value (plist);
74 if (mplist_value (plist) != Minput_method)
75 invalid_file (argv[1]);
76 plist = mplist_next (plist);
77 language = mplist_value (plist);
78 plist = mplist_next (plist);
79 name = mplist_value (plist);
80 plist = mplist_next (plist);
81 if (mplist_key (plist) != Mnil)
82 language = mplist_value (plist), name = Mnil;
83 m17n_object_unref (plist);
85 file = basename (strdup (argv[1]));
91 printf ("*/\n/***ja\n<li> %s (language:", file);
93 printf ("generic name:%s", msymbol_name (name));
95 printf ("%s name:%s", msymbol_name (language), msymbol_name (name));
96 printf (")*/\n/***en\n<li> %s (language:", file);
98 printf ("generic name:%s", msymbol_name (name));
100 printf ("%s name:%s", msymbol_name (language), msymbol_name (name));
101 plist = minput_get_title_icon (language, name);
104 MText *title = mplist_value (plist);
106 printf ("@htmlonly\n title:\"");
107 plist = mplist_next (plist);
108 mconv_encode_stream (Mutf8, title, stdout);
110 if (mplist_key (plist) != Mnil)
112 MText *icon = mplist_value (plist);
113 char *iconfile = mtext_data (icon, MTEXT_FORMAT_US_ASCII,
118 base = basename (strdup (iconfile));
119 sprintf (cmd, "convert -resize 50%% %s images/icon-%s",
122 printf (" icon:<img src=\"icon-%s\" border=\"1\" style=\"vertical-align:middle;\">\n", base);
125 printf (" icon:none\n");
126 printf ("@endhtmlonly\n");
128 printf (")*/\n/***\n");
131 printf ("<li> %s (extra-name:%s, only for inclusion)\n", file,
132 msymbol_name (name));
134 mt = minput_get_description (language, name);
137 printf ("Not yet officially released.\n");
140 else if (head_comment)
142 for (; head_comment; head_comment = head_comment->next)
144 char *p = head_comment->line;
146 if (p[0] == '|' && p[1] == '|')
147 printf ("<tr><td align=\"center\">"), p += 2;
153 printf ("</td></tr>"), p += 2;
155 printf ("</td><td align=\"center\">"), p++;
164 int len = mtext_len (mt), i, c;
166 for (i = 0; i < len; i++)
168 c = mtext_ref_char (mt, i);
173 printf ("@htmlonly\n<div class=\"fragment\"><pre class=\"fragment\">\n");
175 printf ("@verbatim\n");
176 mconv_encode_stream (Mutf8, mt, stdout);
177 if (mtext_ref_char (mt, mtext_len (mt) - 1) != '\n')
181 MConverter *converter = mconv_stream_converter (Mutf8, stdout);
184 printf ("</pre></div><p>\n@endhtmlonly\n");
185 printf ("@latexonly\n\\begin{verbatim}\n");
187 mconv_encode_range (converter, mt, 0, i);
188 for (from = i; i < len; i++)
190 c = mtext_ref_char (mt, i);
194 mconv_encode_range (converter, mt, from, i);
195 printf ("U+%04X", c);
200 mconv_encode_range (converter, mt, from, i);
201 printf ("\\end{verbatim}\n@endlatexonly\n");
202 mconv_free_converter (converter);
205 printf ("@endverbatim\n");