From: handa Date: Thu, 24 Mar 2011 06:51:29 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=m17n%2Fm17n-test.git *** empty log message *** --- diff --git a/conv-by-im.c b/conv-by-im.c new file mode 100644 index 0000000..988f970 --- /dev/null +++ b/conv-by-im.c @@ -0,0 +1,63 @@ +#include +#include + +int +main (int argc, char **argv) +{ + MSymbol imname; + char filename[256]; + MText *mt; + MSymbol utf_8, key; + MInputMethod *im; + MInputContext *ic; + int c; + char byte[2]; + + M17N_INIT (); + + if (argc < 2) + { + fprintf (stderr, "Usage: %s CONVERTER-NAME\n", argv[0]); + exit (1); + } + imname = msymbol (argv[1]); + sprintf (filename, "%s.cnv", argv[1]); + mdatabase_define (msymbol ("input-method"), Mt, imname, Mnil, + NULL, filename); + im = minput_open_im (Mt, imname, NULL); + if (! im) + { + fprintf (stderr, "IM-Open failed: %s\n", argv[1]); + exit (1); + } + ic = minput_create_ic (im, NULL); + if (! ic) + { + fprintf (stderr, "IC-Create failed: %s\n", argv[1]); + exit (1); + } + byte[1] = '\0'; + mt = mtext (); + utf_8 = msymbol ("utf-8"); + while ((c = getchar ()) != EOF) + { + byte[0] = c; + key = msymbol (byte); + if (minput_filter (ic, key, NULL) == 0) + { + if (minput_lookup (ic, key, NULL, mt) < 0) + { + fflush (stdout); + fprintf (stderr, "Filtering `0x%02X' failed\n", c); + exit (1); + } + mconv_encode_stream (msymbol ("utf-8"), mt, stdout); + mtext_del (mt, 0, mtext_len (mt)); + } + } + minput_destroy_ic (ic); + minput_close_im (im); + m17n_object_unref (mt); + M17N_FINI (); + exit (0); +} diff --git a/finddb.c b/finddb.c new file mode 100644 index 0000000..53ec655 --- /dev/null +++ b/finddb.c @@ -0,0 +1,55 @@ +#include +#include +#include + +int +main (int argc, char **argv) +{ + MSymbol tags[4]; + int i; + MDatabase *mdb; + MPlist *plist; + + M17N_INIT (); + for (i = 0; i < argc - 1; i++) + tags[i] = msymbol (argv[i + 1]); + for (; i < 4; i++) + tags[i] = Mnil; + mdb = mdatabase_find (tags[0], tags[1], tags[2], tags[3]); + if (! mdb) + { + MPlist *p; + + plist = mdatabase_list (tags[0], tags[1], tags[2], tags[3]); + + if (! plist) + { + printf ("No such database!\n"); + exit (1); + } + printf ("These databases matched.\n"); + for (p = plist; mplist_key (p) != Mnil; p = mplist_next (p)) + { + MSymbol *s = mdatabase_tag (mplist_value (p)); + + printf ("("); + for (i = 0; i < 4; i++) + { + if (i > 0) putchar (' '); + printf ("%s", msymbol_name (s[i])); + } + printf (")\n"); + } + exit (1); + } + plist = mdatabase_load (mdb); + if (! plist) + { + printf ("Load fail!\n"); + exit (1); + } + mdebug_dump_plist (plist, 0); + m17n_object_unref (plist); + M17N_FINI (); + exit (0); +} diff --git a/flt-old.c b/flt-old.c new file mode 100644 index 0000000..dab4f3a --- /dev/null +++ b/flt-old.c @@ -0,0 +1,110 @@ +#include +#include +#include +#include +#include FT_FREETYPE_H +#include +#include + +static FT_Library ft_library; + +MFont * +open_font (MFrame *frame, char *fontname, char **err) +{ + FcPattern *pat; + FcChar8 *fam, *file; + double pixelsize; + FcFontSet *fs; + FcObjectSet *os; + FT_Face face; + + pat = FcNameParse ((FcChar8 *) fontname); + if (! pat) + { + *err = "invalid name format"; + return NULL; + } + if (FcPatternGetString (pat, FC_FAMILY, 0, &fam) != FcResultMatch) + { + *err = "no family name"; + return NULL; + } + if (FcPatternGetDouble (pat, FC_PIXEL_SIZE, 0, &pixelsize) != FcResultMatch) + pixelsize = 20; + FcPatternAddBool (pat, FC_SCALABLE, FcTrue); + FcPatternDel (pat, FC_PIXEL_SIZE); + os = FcObjectSetBuild (FC_FILE, NULL); + fs = FcFontList (NULL, pat, os); + if (fs->nfont == 0) + { + *err = "no matching font"; + return NULL; + } + FcPatternGetString (fs->fonts[0], FC_FILE, 0, &file); + + if (FT_New_Face (ft_library, (char *) file, 0, &face)) + { + FcFontSetDestroy (fs); + FcObjectSetDestroy (os); + FcPatternDestroy (pat); + *err = "font open fail"; + return NULL; + } + FcFontSetDestroy (fs); + FcObjectSetDestroy (os); + FcPatternDestroy (pat); + if (FT_Set_Pixel_Sizes (face, pixelsize, pixelsize)) + { + *err = "set pixelsize fail"; + FT_Done_Face (face); + return NULL; + } + return mfont_encapsulate (frame, Mfreetype, face); +} + +int +main (int argc, char **argv) +{ + char *err; + MText *mt; + MFrame *frame; + MFont *font; + int len; + + if (argc < 2) + { + fprintf (stderr, "Usage: flt-old FONT-NAME < TEXT-FILE\n"); + exit (1); + } + + FT_Init_FreeType (&ft_library); + M17N_INIT (); + mt = mconv_decode_stream (msymbol ("utf-8"), stdin); + len = mtext_len (mt); + { + MFace *face = mface (); + MPlist *plist = mplist (); + MFontset *fontset = mfontset ("generic"); + + mface_put_prop (face, Mfontset, fontset); + mplist_add (plist, Mface, face); + mplist_add (plist, Mdevice, Mnil); + frame = mframe (plist); + m17n_object_unref (plist); + m17n_object_unref (face); + m17n_object_unref (fontset); + } + font = open_font (frame, argv[1], &err); + mtext_put_prop (mt, 0, len, Mfont, font); + if (! font) + { + fprintf (stderr, "Font error: %s: %s\n", argv[1], err); + exit (1); + } + + mdraw_text_extents (frame, mt, 0, len, NULL, NULL, NULL, NULL); + m17n_object_unref (frame); + m17n_object_unref (mt); + M17N_FINI (); + return 0; +} diff --git a/imsim.c b/imsim.c new file mode 100644 index 0000000..43d967a --- /dev/null +++ b/imsim.c @@ -0,0 +1,84 @@ +#include +#include +#include +#include + +int +main (int argc, char **argv) +{ + MSymbol utf_8; + MInputMethod *im; + MInputContext *ic; + char buf[256]; + + if (argc < 3) + { + fprintf (stderr, "Usage: imsim LANG NAME\n"); + exit (1); + } + + M17N_INIT (); + utf_8 = msymbol ("utf-8"); + im = minput_open_im (msymbol (argv[1]), msymbol (argv[2]), NULL); + if (! im) + { + fprintf (stderr, "Can't open input metdhod: (%s %s)\n", + argv[1], argv[2]); + exit (1); + } + ic = minput_create_ic (im, NULL); + if (! ic) + { + fprintf (stderr, "Can't create input context: (%s %s)\n", + argv[1], argv[2]); + exit (1); + } + + + while (fgets (buf, 256, stdin)) + { + int len = strlen (buf); + char convbuf[1024]; + int keylen, i; + char keyname[2]; + MText *mt = mtext (); + + if (buf[len - 1] == '\n') + buf[--len] = '\0'; + for (keylen = 0; keylen < len; keylen++) + if (buf[keylen] == '\t') + break; + if (keylen == len) + { + fprintf (stderr, "Invalid input line: %s\n", buf); + exit (1); + } + keyname[1] = '\0'; + for (i = 0; i < keylen; i++) + { + MSymbol key; + + keyname[0] = buf[i]; + key = msymbol (keyname); + if (minput_filter (ic, key, NULL)) + continue; + if (minput_lookup (ic, key, NULL, mt) < 0) + mtext_cat_char (mt, buf[i]); + } + minput_filter (ic, Mnil, NULL); + minput_lookup (ic, Mnil, NULL, mt); + len = mconv_encode_buffer (utf_8, mt, (unsigned char *) convbuf, 1024); + convbuf[len] = '\0'; + if (strcmp (buf + keylen + 1, convbuf)) + { + buf[keylen] = '\0'; + printf ("%s => %s (!= %s)\n", buf, convbuf, buf + keylen + 1); + } + m17n_object_unref (mt); + } + + minput_destroy_ic (ic); + minput_close_im (im); + M17N_FINI (); + exit (0); +} diff --git a/key-aliases.c b/key-aliases.c new file mode 100644 index 0000000..bf76f29 --- /dev/null +++ b/key-aliases.c @@ -0,0 +1,71 @@ +#include +#include +#include + +int +main (int argc, char **argv) +{ + MInputMethod *im; + MInputContext *ic; + unsigned char buf[6]; + int i; + MSymbol prop, alias, sym; + + M17N_INIT (); + im = minput_open_im (Mt, msymbol ("test"), NULL); + if (im) + { + ic = minput_create_ic (im, NULL); + if (ic) + { + buf[0] = 0xd1; + buf[1] = 0; + minput_filter (ic, msymbol (buf), NULL); + minput_destroy_ic (ic); + } + minput_close_im (im); + } + prop = msymbol (" key-alias"); + buf[1] = 0; + for (i = 0; i < 256; i++) + { + buf[0] = i; + sym = msymbol ((char *) buf); + alias = msymbol_get (sym, prop); + if (alias) + { + printf ("%02X:", i); + while (alias && alias != sym) + { + printf (" %s", msymbol_name (alias)); + alias = msymbol_get (alias, prop); + } + printf ("\n"); + } + } + buf[0] = 'C', buf[1] = '-', buf[2] = 'M', buf[3] = '-', buf[5] = '\0'; + for (i = ' '; i <= '~'; i++) + { + if (i == '@') + { + i = '_'; + continue; + } + if (i == 'a') + { + i = 'z'; + continue; + } + buf[4] = i; + sym = msymbol (buf); + alias = msymbol_get (sym, prop); + printf ("%s:", buf); + while (alias && alias != sym) + { + printf (" %s", msymbol_name (alias)); + alias = msymbol_get (alias, prop); + } + printf ("\n"); + } + exit (0); +} diff --git a/langname.c b/langname.c new file mode 100644 index 0000000..840a455 --- /dev/null +++ b/langname.c @@ -0,0 +1,46 @@ +#include +#include + +int +main (int argc, char **argv) +{ + MPlist *plist, *pl; + MSymbol utf8, lang, script, territory; + + if (argc < 2) + { + fprintf (stderr, "Usage: langname LANG [SCRIPT [TERRITORY]]\n"); + exit (1); + } + + M17N_INIT (); + utf8 = msymbol ("utf-8"); + lang = msymbol (argv[1]); + if (argc > 2) + { + script = msymbol (argv[2]); + if (argc > 3) + territory = msymbol (argv[3]); + else + territory = Mnil; + } + else + script = territory = Mnil; + + plist = mlanguage_list (); + for (pl = plist; mplist_key (pl) != Mnil; pl = mplist_next (pl)) + { + MSymbol target = (MSymbol) mplist_value (pl); + MPlist *p = mlanguage_name_list (lang, target, script, territory); + + if (p) + { + printf ("%s:", msymbol_name (target)); + mconv_encode_stream (utf8, (MText *) mplist_value (p), stdout); + putchar ('\n'); + } + } + m17n_object_unref (plist); + M17N_FINI (); + exit (0); +} diff --git a/pangotest.c b/pangotest.c new file mode 100644 index 0000000..8ccb0ba --- /dev/null +++ b/pangotest.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int +main (int argc, char **argv) +{ + FILE *fp; + struct stat statbuf; + char *buf; + size_t nbytes; + PangoFontMap *fontmap; + PangoContext *context; + PangoLayout *layout; + int width, height; + int count = 1; + + if (argc < 2) + { + fprintf (stderr, "Usage: viewfile FILENAME [COUNT]\n"); + exit (1); + } + if (argc > 2) + count = atoi (argv[2]); + + if (stat (argv[1], &statbuf) != 0 + || ! (fp = fopen (argv[1], "r"))) + { + fprintf (stderr, "Can't open \"%s\"\n", argv[1]); + exit (1); + } + buf = alloca (statbuf.st_size + 1); + fread (buf, 1, statbuf.st_size, fp); + fclose (fp); + buf[statbuf.st_size] = '\0'; + + fontmap = pango_cairo_font_map_get_default (); + context = pango_cairo_font_map_create_context ((PangoCairoFontMap *) fontmap); + layout = pango_layout_new (context); + while (count-- > 0) + { + int w, h; + + pango_layout_set_text (layout, buf, statbuf.st_size); + pango_layout_get_pixel_size (layout, &width, &height); + pango_layout_set_text (layout, "abc", 3); + pango_layout_get_pixel_size (layout, &w, &h); + } + printf ("%dx%d\n", width, height); + exit (0); +} diff --git a/reader2.c b/reader2.c new file mode 100644 index 0000000..5daf174 --- /dev/null +++ b/reader2.c @@ -0,0 +1,126 @@ +/** + * section: xmlReader + * synopsis: Parse and validate an XML file with an xmlReader + * purpose: Demonstrate the use of xmlReaderForFile() to parse an XML file + * validating the content in the process and activating options + * like entities substitution, and DTD attributes defaulting. + * (Note that the XMLReader functions require libxml2 version later + * than 2.6.) + * usage: reader2 + * test: reader2 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp + * author: Daniel Veillard + * copy: see Copyright for the status of this software. + */ + +#include +#include + +#ifdef LIBXML_READER_ENABLED + +/** + * processNode: + * @reader: the xmlReader + * + * Dump information about the current node + */ +static void +processNode(xmlTextReaderPtr reader) { + const xmlChar *name, *value; + + name = xmlTextReaderConstName(reader); + if (name == NULL) + name = BAD_CAST "--"; + + value = xmlTextReaderConstValue(reader); + + printf("%d %d %s %d %d", + xmlTextReaderDepth(reader), + xmlTextReaderNodeType(reader), + name, + xmlTextReaderIsEmptyElement(reader), + xmlTextReaderHasValue(reader)); + if (value == NULL) + printf("\n"); + else { + if (xmlStrlen(value) > 40) + printf(" %.40s...\n", value); + else + printf(" %s\n", value); + } +} + +/** + * streamFile: + * @filename: the file name to parse + * + * Parse, validate and print information about an XML file. + */ +static void +streamFile(const char *filename) { + xmlTextReaderPtr reader; + int ret; + + + /* + * Pass some special parsing options to activate DTD attribute defaulting, + * entities substitution and DTD validation + */ + reader = xmlReaderForFile(filename, NULL, + XML_PARSE_DTDATTR /* default DTD attributes */ + | XML_PARSE_NOENT /* substitute entities */ + | XML_PARSE_NOBLANKS +#if 0 + | XML_PARSE_DTDVALID /* validate with the DTD */ +#endif + ); + if (reader != NULL) { + ret = xmlTextReaderRead(reader); + while (ret == 1) { + processNode(reader); + ret = xmlTextReaderRead(reader); + } + /* + * Once the document has been fully parsed check the validation results + */ + if (xmlTextReaderIsValid(reader) != 1) { + fprintf(stderr, "Document %s does not validate\n", filename); + } + xmlFreeTextReader(reader); + if (ret != 0) { + fprintf(stderr, "%s : failed to parse\n", filename); + } + } else { + fprintf(stderr, "Unable to open %s\n", filename); + } +} + +int main(int argc, char **argv) { + if (argc != 2) + return(1); + + /* + * this initialize the library and check potential ABI mismatches + * between the version it was compiled for and the actual shared + * library used. + */ + LIBXML_TEST_VERSION + + streamFile(argv[1]); + + /* + * Cleanup function for the XML library. + */ + xmlCleanupParser(); + /* + * this is to debug memory for regression tests + */ + xmlMemoryDump(); + return(0); +} + +#else +int main(void) { + fprintf(stderr, "XInclude support not compiled in\n"); + exit(1); +} +#endif diff --git a/test.c b/test.c new file mode 100644 index 0000000..97a8d0b --- /dev/null +++ b/test.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +int +main () +{ + MFLTOtfSpec spec; + int result; + void *handle; + int (*parse_otf_command) (MSymbol, MFLTOtfSpec *); + + M17N_INIT (); + handle = dlopen (NULL, RTLD_NOW); + if (! handle) + exit (1); + *(void **) (&parse_otf_command) = dlsym (handle, "mflt_find"); + if (dlerror () != NULL) + exit (2); + *(void **) (&parse_otf_command) = dlsym (handle, "parse_otf_command"); + if (dlerror () != NULL) + exit (3); + result = (*parse_otf_command) (msymbol (":otf=arab"), &spec); + printf ("result = %d\n", result); + exit (0); +} diff --git a/viewfile.c b/viewfile.c new file mode 100644 index 0000000..bb9e54a --- /dev/null +++ b/viewfile.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include +#include + +static void +destroy (GtkWidget *widget, gpointer data) +{ + gtk_main_quit (); +} + +int +main (int argc, char **argv) +{ + FILE *fp; + struct stat statbuf; + unsigned char *buf; + size_t nbytes; + GtkWidget *window, *view; + GtkTextBuffer *buffer; + + if (argc < 2) + { + fprintf (stderr, "Usage: viewfile FILENAME\n"); + exit (1); + } + if (stat (argv[1], &statbuf) != 0 + || ! (fp = fopen (argv[1], "r"))) + { + fprintf (stderr, "Can't open \"%s\"\n", argv[1]); + exit (1); + } + buf = alloca (statbuf.st_size); + fread (buf, 1, statbuf.st_size, fp); + fclose (fp); + + gtk_init (&argc, &argv); + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL); + view = gtk_text_view_new (); + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); + gtk_text_buffer_set_text (buffer, (gchar *) buf, statbuf.st_size); + gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE); + gtk_container_add (GTK_CONTAINER (window), view); + gtk_widget_show_all (window); + gtk_main (); + + return 0; +}