From 3d9889baee9c5c11cd960a43c0f51c449ce35b45 Mon Sep 17 00:00:00 2001 From: Nat Friedman Date: Thu, 6 Apr 2000 05:21:29 +0000 Subject: Committing this thing I wrote last year to parse names. It's cute. svn path=/trunk/; revision=2301 --- addressbook/ename/Makefile.am | 43 +++++++++ addressbook/ename/TODO | 2 + addressbook/ename/e-name-western-tables.h | 53 +++++++++++ addressbook/ename/e-name-western.h | 23 +++++ addressbook/ename/test-ename-western-gtk.c | 148 +++++++++++++++++++++++++++++ addressbook/ename/test-ename-western.c | 70 ++++++++++++++ e-util/ename/Makefile.am | 43 +++++++++ e-util/ename/TODO | 2 + e-util/ename/e-name-western-tables.h | 53 +++++++++++ e-util/ename/e-name-western.h | 23 +++++ e-util/ename/test-ename-western-gtk.c | 148 +++++++++++++++++++++++++++++ e-util/ename/test-ename-western.c | 70 ++++++++++++++ 12 files changed, 678 insertions(+) create mode 100644 addressbook/ename/Makefile.am create mode 100644 addressbook/ename/TODO create mode 100644 addressbook/ename/e-name-western-tables.h create mode 100644 addressbook/ename/e-name-western.h create mode 100644 addressbook/ename/test-ename-western-gtk.c create mode 100644 addressbook/ename/test-ename-western.c create mode 100644 e-util/ename/Makefile.am create mode 100644 e-util/ename/TODO create mode 100644 e-util/ename/e-name-western-tables.h create mode 100644 e-util/ename/e-name-western.h create mode 100644 e-util/ename/test-ename-western-gtk.c create mode 100644 e-util/ename/test-ename-western.c diff --git a/addressbook/ename/Makefile.am b/addressbook/ename/Makefile.am new file mode 100644 index 0000000000..17a542d9c5 --- /dev/null +++ b/addressbook/ename/Makefile.am @@ -0,0 +1,43 @@ +INCLUDES = \ + -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ + -DG_LOG_DOMAIN=\"EName\" \ + -I$(srcdir) -I$(top_srcdir) \ + -I. \ + -I.. \ + -I$(top_builddir) \ + -I$(includedir) \ + $(GNOME_INCLUDEDIR) + +gnome_libs = \ + $(GNOME_LIBDIR) \ + $(GNOMEUI_LIBS) \ + $(GNOMEGNORBA_LIBS) \ + $(INTLLIBS) + +ename_libs = \ + libename.la \ + $(gnome_libs) + +lib_LTLIBRARIES = libename.la + +libename_la_SOURCES = \ + e-name-western.c + +libenameincludedir = $(includedir)/ename + +libenameinclude_HEADERS = \ + e-name-western.h + +noinst_PROGRAMS = \ + test-ename-western \ + test-ename-western-gtk + +test_ename_western_SOURCES = \ + test-ename-western.c + +test_ename_western_LDADD = $(ename_libs) + +test_ename_western_gtk_SOURCES = \ + test-ename-western-gtk.c + +test_ename_western_gtk_LDADD = $(ename_libs) $(gnome_libs) diff --git a/addressbook/ename/TODO b/addressbook/ename/TODO new file mode 100644 index 0000000000..669661eea7 --- /dev/null +++ b/addressbook/ename/TODO @@ -0,0 +1,2 @@ +* Support other naming systems. +* Handle misspelled suffixes better. diff --git a/addressbook/ename/e-name-western-tables.h b/addressbook/ename/e-name-western-tables.h new file mode 100644 index 0000000000..369d530edc --- /dev/null +++ b/addressbook/ename/e-name-western-tables.h @@ -0,0 +1,53 @@ +#ifndef __E_NAME_WESTERN_TABLES_H__ +#define __E_NAME_WESTERN_TABLES_H__ + +char *e_name_western_pfx_table[] = { + + /* + * English. + */ + "mister", "miss.", "mr.", "mrs.", "ms.", + "miss", "mr", "mrs", "ms", "sir", + "professor", "prof.", "dr", "dr.", "doctor", + "reverend", "president", "judge", "senator", + "congressman", "congresswoman", + + "the honorable", "the reverend", "his holiness", + "his eminence", + + + /* + * French. + */ + "monsieur", "mr.", "mademoiselle", "melle.", + "madame", "mme.", "professeur", + + /* + * Spanish. + */ + "senor", "senora", "senorita", + + NULL}; + +char *e_name_western_sfx_table[] = { + + /* + * English. + */ + "junior", "senior", "jr", "sr", "I", "II", "III", "IV", "V", + "phd", "ms", "md", "esq", "esq.", "esquire", + + NULL}; + +char *e_name_western_twopart_sfx_table[] = { + + /* + * English. + */ + "the first", "the second", "the third", + + NULL}; + +char *e_name_western_complex_last_table[] = {"van", "von", "de", NULL}; + +#endif /* ! __E_NAME_WESTERN_TABLES_H__ */ diff --git a/addressbook/ename/e-name-western.h b/addressbook/ename/e-name-western.h new file mode 100644 index 0000000000..695719b1c0 --- /dev/null +++ b/addressbook/ename/e-name-western.h @@ -0,0 +1,23 @@ +#ifndef __E_NAME_WESTERN_H__ +#define __E_NAME_WESTERN_H__ + +#include + +typedef struct { + + /* Public */ + char *prefix; + char *first; + char *middle; + char *nick; + char *last; + char *suffix; + + /* Private */ + char *full; +} ENameWestern; + +ENameWestern *e_name_western_parse (const char *full_name); +void e_name_western_free (ENameWestern *w); + +#endif /* ! __E_NAME_WESTERN_H__ */ diff --git a/addressbook/ename/test-ename-western-gtk.c b/addressbook/ename/test-ename-western-gtk.c new file mode 100644 index 0000000000..15db38ce10 --- /dev/null +++ b/addressbook/ename/test-ename-western-gtk.c @@ -0,0 +1,148 @@ +#include +#include + +ENameWestern *name; +GtkWidget *full; +GtkWidget *prefix; +GtkWidget *first; +GtkWidget *middle; +GtkWidget *nick; +GtkWidget *last; +GtkWidget *suffix; + +static void +fill_entries (void) +{ + +#define SET(a,b) (gtk_entry_set_text (GTK_ENTRY (a), (b) == NULL ? "" : (b))) + SET(prefix, name->prefix); + SET(first, name->first); + SET(middle, name->middle); + SET(nick, name->nick); + SET(last, name->last); + SET(suffix, name->suffix); +} + +static void +full_changed_cb (GtkEntry *fulle) +{ + e_name_western_free (name); + name = e_name_western_parse (gtk_entry_get_text (fulle)); + fill_entries (); +} + +static void +create_window (void) +{ + GtkWidget *app; + GtkTable *table; + + GtkWidget *prefix_label; + GtkWidget *first_label; + GtkWidget *middle_label; + GtkWidget *nick_label; + GtkWidget *last_label; + GtkWidget *suffix_label; + + app = gnome_app_new ("test", "Evolution Western Name Parser"); + + table = GTK_TABLE (gtk_table_new (3, 6, FALSE)); + + full = gtk_entry_new (); + prefix = gtk_entry_new (); + first = gtk_entry_new (); + middle = gtk_entry_new (); + nick = gtk_entry_new (); + last = gtk_entry_new (); + suffix = gtk_entry_new (); + + gtk_widget_set_usize (prefix, 100, 0); + gtk_widget_set_usize (first, 100, 0); + gtk_widget_set_usize (middle, 100, 0); + gtk_widget_set_usize (nick, 100, 0); + gtk_widget_set_usize (last, 100, 0); + gtk_widget_set_usize (suffix, 100, 0); + + gtk_table_attach (table, full, 0, 6, 0, 1, + GTK_EXPAND | GTK_FILL, 0, + 0, 0); + + gtk_table_attach (table, prefix, 0, 1, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, first, 1, 2, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, middle, 2, 3, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, nick, 3, 4, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, last, 4, 5, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, suffix, 5, 6, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, + 0, 0); + + prefix_label = gtk_label_new ("Prefix"); + first_label = gtk_label_new ("First"); + middle_label = gtk_label_new ("Middle"); + nick_label = gtk_label_new ("Nick"); + last_label = gtk_label_new ("Last"); + suffix_label = gtk_label_new ("Suffix"); + + gtk_table_attach (table, prefix_label, 0, 1, 2, 3, + GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, first_label, 1, 2, 2, 3, + GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, middle_label, 2, 3, 2, 3, + GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, nick_label, 3, 4, 2, 3, + GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, last_label, 4, 5, 2, 3, + GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, suffix_label, 5, 6, 2, 3, + GTK_SHRINK, 0, + 0, 0); + + gnome_app_set_contents (GNOME_APP (app), GTK_WIDGET (table)); + + gtk_widget_show_all (app); + + gtk_entry_set_text (GTK_ENTRY (full), + "The Honorable Doctor van Jacobsen, Albert Roderick \"The Clenched Fist\" Jr, MD, PhD, Esquire"); + + name = e_name_western_parse ("The Honorable Doctor van Jacobsen, Albert Roderick \"The Clenched Fist\" Jr, MD, PhD, Esquire"); + fill_entries (); + + gtk_signal_connect (GTK_OBJECT (full), "changed", full_changed_cb, NULL); +} + +int +main (int argc, char **argv) +{ + gnome_init ("Test EName", "Test EName", argc, argv); + + create_window (); + + gtk_main (); + + return 0; +} diff --git a/addressbook/ename/test-ename-western.c b/addressbook/ename/test-ename-western.c new file mode 100644 index 0000000000..17ff91dbf2 --- /dev/null +++ b/addressbook/ename/test-ename-western.c @@ -0,0 +1,70 @@ +#include +#include + +#include + +static void +do_name (char *n) +{ + ENameWestern *wname; + + wname = e_name_western_parse (n); + + printf ("Full Name: [%s]\n", n); + + printf ("Prefix: [%s]\n", wname->prefix); + printf ("First: [%s]\n", wname->first); + printf ("Middle: [%s]\n", wname->middle); + printf ("Nick: [%s]\n", wname->nick); + printf ("Last: [%s]\n", wname->last); + printf ("Suffix: [%s]\n", wname->suffix); + + printf ("\n"); + + e_name_western_free (wname); +} + +int +main (int argc, char **argv) +{ + if (argc == 2) { + while (! feof (stdin)) { + char s[256]; + + if (fgets (s, sizeof (s), stdin) == NULL) + return 0; + + g_strstrip (s); + + do_name (s); + } + + return 0; + } + + do_name ("Nat"); + do_name ("Karl Anders Carlsson"); + do_name ("Miguel de Icaza Amozorrutia"); + do_name ("The Honorable Doctor de Icaza, Miguel \"Sparky\" Junior, PhD, MD"); + do_name ("Nat Friedman MD, Phd"); + do_name ("Nat Friedman PhD"); + do_name ("Friedman, Nat"); + do_name ("Miguel de Icaza Esquire"); + do_name ("Dr Miguel \"Sparky\" de Icaza"); + do_name ("Robert H.B. Netzer"); + do_name ("W. Richard Stevens"); + do_name ("Nat Friedman"); + do_name ("N. Friedman"); + do_name ("Miguel de Icaza"); + do_name ("Drew Johnson"); + do_name ("President Bill \"Slick Willy\" Clinton"); + do_name ("The Honorable Mark J. Einstein Jr"); + do_name ("Friedman, Nat"); + do_name ("de Icaza, Miguel"); + do_name ("Mr de Icaza, Miguel"); + do_name ("Smith, John Jr"); + do_name ("Nick Glennie-Smith"); + do_name ("Dr von Johnson, Albert Roderick Jr"); + + return 0; +} diff --git a/e-util/ename/Makefile.am b/e-util/ename/Makefile.am new file mode 100644 index 0000000000..17a542d9c5 --- /dev/null +++ b/e-util/ename/Makefile.am @@ -0,0 +1,43 @@ +INCLUDES = \ + -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ + -DG_LOG_DOMAIN=\"EName\" \ + -I$(srcdir) -I$(top_srcdir) \ + -I. \ + -I.. \ + -I$(top_builddir) \ + -I$(includedir) \ + $(GNOME_INCLUDEDIR) + +gnome_libs = \ + $(GNOME_LIBDIR) \ + $(GNOMEUI_LIBS) \ + $(GNOMEGNORBA_LIBS) \ + $(INTLLIBS) + +ename_libs = \ + libename.la \ + $(gnome_libs) + +lib_LTLIBRARIES = libename.la + +libename_la_SOURCES = \ + e-name-western.c + +libenameincludedir = $(includedir)/ename + +libenameinclude_HEADERS = \ + e-name-western.h + +noinst_PROGRAMS = \ + test-ename-western \ + test-ename-western-gtk + +test_ename_western_SOURCES = \ + test-ename-western.c + +test_ename_western_LDADD = $(ename_libs) + +test_ename_western_gtk_SOURCES = \ + test-ename-western-gtk.c + +test_ename_western_gtk_LDADD = $(ename_libs) $(gnome_libs) diff --git a/e-util/ename/TODO b/e-util/ename/TODO new file mode 100644 index 0000000000..669661eea7 --- /dev/null +++ b/e-util/ename/TODO @@ -0,0 +1,2 @@ +* Support other naming systems. +* Handle misspelled suffixes better. diff --git a/e-util/ename/e-name-western-tables.h b/e-util/ename/e-name-western-tables.h new file mode 100644 index 0000000000..369d530edc --- /dev/null +++ b/e-util/ename/e-name-western-tables.h @@ -0,0 +1,53 @@ +#ifndef __E_NAME_WESTERN_TABLES_H__ +#define __E_NAME_WESTERN_TABLES_H__ + +char *e_name_western_pfx_table[] = { + + /* + * English. + */ + "mister", "miss.", "mr.", "mrs.", "ms.", + "miss", "mr", "mrs", "ms", "sir", + "professor", "prof.", "dr", "dr.", "doctor", + "reverend", "president", "judge", "senator", + "congressman", "congresswoman", + + "the honorable", "the reverend", "his holiness", + "his eminence", + + + /* + * French. + */ + "monsieur", "mr.", "mademoiselle", "melle.", + "madame", "mme.", "professeur", + + /* + * Spanish. + */ + "senor", "senora", "senorita", + + NULL}; + +char *e_name_western_sfx_table[] = { + + /* + * English. + */ + "junior", "senior", "jr", "sr", "I", "II", "III", "IV", "V", + "phd", "ms", "md", "esq", "esq.", "esquire", + + NULL}; + +char *e_name_western_twopart_sfx_table[] = { + + /* + * English. + */ + "the first", "the second", "the third", + + NULL}; + +char *e_name_western_complex_last_table[] = {"van", "von", "de", NULL}; + +#endif /* ! __E_NAME_WESTERN_TABLES_H__ */ diff --git a/e-util/ename/e-name-western.h b/e-util/ename/e-name-western.h new file mode 100644 index 0000000000..695719b1c0 --- /dev/null +++ b/e-util/ename/e-name-western.h @@ -0,0 +1,23 @@ +#ifndef __E_NAME_WESTERN_H__ +#define __E_NAME_WESTERN_H__ + +#include + +typedef struct { + + /* Public */ + char *prefix; + char *first; + char *middle; + char *nick; + char *last; + char *suffix; + + /* Private */ + char *full; +} ENameWestern; + +ENameWestern *e_name_western_parse (const char *full_name); +void e_name_western_free (ENameWestern *w); + +#endif /* ! __E_NAME_WESTERN_H__ */ diff --git a/e-util/ename/test-ename-western-gtk.c b/e-util/ename/test-ename-western-gtk.c new file mode 100644 index 0000000000..15db38ce10 --- /dev/null +++ b/e-util/ename/test-ename-western-gtk.c @@ -0,0 +1,148 @@ +#include +#include + +ENameWestern *name; +GtkWidget *full; +GtkWidget *prefix; +GtkWidget *first; +GtkWidget *middle; +GtkWidget *nick; +GtkWidget *last; +GtkWidget *suffix; + +static void +fill_entries (void) +{ + +#define SET(a,b) (gtk_entry_set_text (GTK_ENTRY (a), (b) == NULL ? "" : (b))) + SET(prefix, name->prefix); + SET(first, name->first); + SET(middle, name->middle); + SET(nick, name->nick); + SET(last, name->last); + SET(suffix, name->suffix); +} + +static void +full_changed_cb (GtkEntry *fulle) +{ + e_name_western_free (name); + name = e_name_western_parse (gtk_entry_get_text (fulle)); + fill_entries (); +} + +static void +create_window (void) +{ + GtkWidget *app; + GtkTable *table; + + GtkWidget *prefix_label; + GtkWidget *first_label; + GtkWidget *middle_label; + GtkWidget *nick_label; + GtkWidget *last_label; + GtkWidget *suffix_label; + + app = gnome_app_new ("test", "Evolution Western Name Parser"); + + table = GTK_TABLE (gtk_table_new (3, 6, FALSE)); + + full = gtk_entry_new (); + prefix = gtk_entry_new (); + first = gtk_entry_new (); + middle = gtk_entry_new (); + nick = gtk_entry_new (); + last = gtk_entry_new (); + suffix = gtk_entry_new (); + + gtk_widget_set_usize (prefix, 100, 0); + gtk_widget_set_usize (first, 100, 0); + gtk_widget_set_usize (middle, 100, 0); + gtk_widget_set_usize (nick, 100, 0); + gtk_widget_set_usize (last, 100, 0); + gtk_widget_set_usize (suffix, 100, 0); + + gtk_table_attach (table, full, 0, 6, 0, 1, + GTK_EXPAND | GTK_FILL, 0, + 0, 0); + + gtk_table_attach (table, prefix, 0, 1, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, first, 1, 2, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, middle, 2, 3, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, nick, 3, 4, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, last, 4, 5, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, suffix, 5, 6, 1, 2, + GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, + 0, 0); + + prefix_label = gtk_label_new ("Prefix"); + first_label = gtk_label_new ("First"); + middle_label = gtk_label_new ("Middle"); + nick_label = gtk_label_new ("Nick"); + last_label = gtk_label_new ("Last"); + suffix_label = gtk_label_new ("Suffix"); + + gtk_table_attach (table, prefix_label, 0, 1, 2, 3, + GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, first_label, 1, 2, 2, 3, + GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, middle_label, 2, 3, 2, 3, + GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, nick_label, 3, 4, 2, 3, + GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, last_label, 4, 5, 2, 3, + GTK_SHRINK, 0, + 0, 0); + + gtk_table_attach (table, suffix_label, 5, 6, 2, 3, + GTK_SHRINK, 0, + 0, 0); + + gnome_app_set_contents (GNOME_APP (app), GTK_WIDGET (table)); + + gtk_widget_show_all (app); + + gtk_entry_set_text (GTK_ENTRY (full), + "The Honorable Doctor van Jacobsen, Albert Roderick \"The Clenched Fist\" Jr, MD, PhD, Esquire"); + + name = e_name_western_parse ("The Honorable Doctor van Jacobsen, Albert Roderick \"The Clenched Fist\" Jr, MD, PhD, Esquire"); + fill_entries (); + + gtk_signal_connect (GTK_OBJECT (full), "changed", full_changed_cb, NULL); +} + +int +main (int argc, char **argv) +{ + gnome_init ("Test EName", "Test EName", argc, argv); + + create_window (); + + gtk_main (); + + return 0; +} diff --git a/e-util/ename/test-ename-western.c b/e-util/ename/test-ename-western.c new file mode 100644 index 0000000000..17ff91dbf2 --- /dev/null +++ b/e-util/ename/test-ename-western.c @@ -0,0 +1,70 @@ +#include +#include + +#include + +static void +do_name (char *n) +{ + ENameWestern *wname; + + wname = e_name_western_parse (n); + + printf ("Full Name: [%s]\n", n); + + printf ("Prefix: [%s]\n", wname->prefix); + printf ("First: [%s]\n", wname->first); + printf ("Middle: [%s]\n", wname->middle); + printf ("Nick: [%s]\n", wname->nick); + printf ("Last: [%s]\n", wname->last); + printf ("Suffix: [%s]\n", wname->suffix); + + printf ("\n"); + + e_name_western_free (wname); +} + +int +main (int argc, char **argv) +{ + if (argc == 2) { + while (! feof (stdin)) { + char s[256]; + + if (fgets (s, sizeof (s), stdin) == NULL) + return 0; + + g_strstrip (s); + + do_name (s); + } + + return 0; + } + + do_name ("Nat"); + do_name ("Karl Anders Carlsson"); + do_name ("Miguel de Icaza Amozorrutia"); + do_name ("The Honorable Doctor de Icaza, Miguel \"Sparky\" Junior, PhD, MD"); + do_name ("Nat Friedman MD, Phd"); + do_name ("Nat Friedman PhD"); + do_name ("Friedman, Nat"); + do_name ("Miguel de Icaza Esquire"); + do_name ("Dr Miguel \"Sparky\" de Icaza"); + do_name ("Robert H.B. Netzer"); + do_name ("W. Richard Stevens"); + do_name ("Nat Friedman"); + do_name ("N. Friedman"); + do_name ("Miguel de Icaza"); + do_name ("Drew Johnson"); + do_name ("President Bill \"Slick Willy\" Clinton"); + do_name ("The Honorable Mark J. Einstein Jr"); + do_name ("Friedman, Nat"); + do_name ("de Icaza, Miguel"); + do_name ("Mr de Icaza, Miguel"); + do_name ("Smith, John Jr"); + do_name ("Nick Glennie-Smith"); + do_name ("Dr von Johnson, Albert Roderick Jr"); + + return 0; +} -- cgit