diff --git a/classify/intproto.cpp b/classify/intproto.cpp index b922f7604964abe5198681e9d15f880cf0db8902..7ace02315d0119f348b62910c85656f241858766 100644 --- a/classify/intproto.cpp +++ b/classify/intproto.cpp @@ -26,12 +26,16 @@ #include "const.h" #include "ndminx.h" #include "adaptmatch.h" +#include "globals.h" //extern GetPicoFeatureLength(); #include #include #include +#ifdef __UNIX__ +#include +#endif /* match debug display constants*/ #define DISPLAY_OFFSET (0.5 * INT_CHAR_NORM_RANGE) @@ -631,7 +635,8 @@ void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class) { /*---------------------------------------------------------------------------*/ -INT_TEMPLATES CreateIntTemplates(CLASSES FloatProtos) { +INT_TEMPLATES CreateIntTemplates(CLASSES FloatProtos, + const UNICHARSET& target_unicharset) { /* ** Parameters: ** FloatProtos prototypes in old floating pt format @@ -651,11 +656,10 @@ INT_TEMPLATES CreateIntTemplates(CLASSES FloatProtos) { IntTemplates = NewIntTemplates (); - for (ClassId = 0; ClassId < NUMBER_OF_CLASSES; ClassId++) { + for (ClassId = 0; ClassId < target_unicharset.size(); ClassId++) { FClass = &(FloatProtos[ClassId]); if (NumProtosIn (FClass) > 0) { assert (UnusedClassIdIn (IntTemplates, ClassId)); - IClass = NewIntClass (NumProtosIn (FClass), NumConfigsIn (FClass)); AddIntClass(IntTemplates, ClassId, IClass); @@ -867,6 +871,7 @@ INT_TEMPLATES ReadIntTemplates(FILE *File, BOOL8 swap) { */ int i, j, x, y, z; int nread; + int unicharset_size; INT_TEMPLATES Templates; CLASS_PRUNER Pruner; INT_CLASS Class; @@ -876,30 +881,38 @@ INT_TEMPLATES ReadIntTemplates(FILE *File, BOOL8 swap) { /* first read the high level template struct */ Templates = NewIntTemplates (); // Read Templates in parts for 64 bit compatibility. + if (fread(&unicharset_size, sizeof(int), 1, File) != 1) + cprintf ("Bad read of inttemp!\n"); if (fread(&Templates->NumClasses, sizeof(int), 1, File) != 1 || fread(&Templates->NumClassPruners, sizeof(int), 1, File) != 1) cprintf ("Bad read of inttemp!\n"); - for (i = 0; i <= MAX_CLASS_ID; ++i) { + // Swap status is determined automatically. + swap = Templates->NumClassPruners < 0 || + Templates->NumClassPruners > MAX_NUM_CLASS_PRUNERS; + if (swap) { + reverse32 (&Templates->NumClassPruners); + reverse32 (&Templates->NumClasses); + reverse32 (&unicharset_size); + } + if (unicharset_size != unicharset.size()) { + cprintf("Error: %d classes in inttemp while " + "unicharset contains %d unichars.\n", + unicharset_size, unicharset.size()); + exit(1); + } + for (i = 0; i < unicharset_size; ++i) { if (fread(&Templates->IndexFor[i], sizeof(CLASS_INDEX), 1, File) != 1) cprintf("Bad read of inttemp!\n"); } - for (i = 0; i < MAX_NUM_CLASSES; ++i) { + for (i = 0; i < NumClassesIn (Templates); ++i) { if (fread(&Templates->ClassIdFor[i], sizeof(CLASS_ID), 1, File) != 1) cprintf("Bad read of inttemp!\n"); } - for (i = 0; i < MAX_NUM_CLASSES + MAX_NUM_CLASS_PRUNERS; ++i) { - int junk; - if (fread(&junk, sizeof(junk), 1, File) != 1) - cprintf("Bad read of inttemp!\n"); - } - // Swap status is determined automatically. - swap = Templates->NumClassPruners < 0 || - Templates->NumClassPruners > MAX_NUM_CLASS_PRUNERS; if (swap) { - reverse32 (&Templates->NumClassPruners); - reverse32 (&Templates->NumClasses); for (i = 0; i < MAX_CLASS_ID + 1; i++) reverse16 (&Templates->IndexFor[i]); + for (i = 0; i < MAX_NUM_CLASSES; i++) + reverse32 (&Templates->ClassIdFor[i]); } /* then read in the class pruners */ @@ -1042,7 +1055,8 @@ void ShowMatchDisplay() { #endif /*---------------------------------------------------------------------------*/ -void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates) { +void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates, + const UNICHARSET& target_unicharset) { /* ** Parameters: ** File open file to write templates to @@ -1057,9 +1071,16 @@ void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates) { */ int i, j; INT_CLASS Class; + int unicharset_size = target_unicharset.size(); /* first write the high level template struct */ - fwrite ((char *) Templates, sizeof (INT_TEMPLATES_STRUCT), 1, File); + fwrite((char *) &unicharset_size, sizeof (int), 1, File); + fwrite((char *) &Templates->NumClasses, sizeof (int), 1, File); + fwrite((char *) &Templates->NumClassPruners, sizeof (int), 1, File); + fwrite((char *) &Templates->IndexFor[0], sizeof (CLASS_INDEX), + unicharset_size, File); + fwrite((char *) &Templates->ClassIdFor[0], sizeof (CLASS_ID), + NumClassesIn (Templates), File); /* then write out the class pruners */ for (i = 0; i < NumClassPrunersIn (Templates); i++) @@ -1302,8 +1323,31 @@ CLASS_ID GetClassToDebug(const char *Prompt) { ** Exceptions: none ** History: Thu Mar 21 16:55:13 1991, DSJ, Created. */ - return window_wait (IntMatchWindow); + char c = 0; + do + c = window_wait(IntMatchWindow); + while (c != 0 && c != '\n'); +#ifdef __UNIX__ + // Temp sychronization. + if (c == '\n' && input_unicode[0] == 0) { + sleep(1); + } +#endif + char utf8[kInputSize * UNICHAR_LEN]; + int offset = 0; + int i; + for (i = 0; i < kInputSize && input_unicode[i] != 0; ++i) { + UNICHAR ch(input_unicode[i]); + int len = ch.utf8_len(); + for (int j = 0; j < len; ++j) { + utf8[offset++] = ch.utf8()[j]; + } + } + cprintf("unicode len = %d, 1st code=%d, utf8 len = %d, 1st code=%d\n", + i, input_unicode[0], offset, utf8[0]); + input_unicode[0] = 0; + return c == '\n' ? unicharset.unichar_to_id(utf8, offset) : 0; } /* GetClassToDebug */ #endif diff --git a/viewer/grphics.cpp b/viewer/grphics.cpp index d59c3eb405eae628157984bfecd0ce044f5085a2..8134938b0ded5ced65d0df1eae86579f766ff73e 100644 --- a/viewer/grphics.cpp +++ b/viewer/grphics.cpp @@ -36,6 +36,7 @@ void def_overlap_picture_ops(BOOL8 update); WINCREATEFUNC create_func = WINFD::create; void (*overlap_func) (BOOL8) = def_overlap_picture_ops; +int input_unicode[kInputSize]; /********************************************************************** * line_color_index @@ -741,7 +742,7 @@ void WINFD::Destroy_window() { /*destroy a window */ return; } else { - Clear_event_queue(); + Clear_event_queue(); sbfds[fd].used = FALSE; /*it is not in use */ sbfds[fd].click_handler = NULL; @@ -921,7 +922,7 @@ void WINFD::Make_picture_current() { /*update window */ ONEOP *newop; /*message structure */ if (this == NULL || fd <= 0) { - overlap_picture_ops(TRUE); + overlap_picture_ops(TRUE); } else { /*get some space */ diff --git a/viewer/grphics.h b/viewer/grphics.h index 5226668b5aa2c5891055b668980f7451728c12ef..b0b39a2bc33818d238ebd77335d2175a104b88de 100644 --- a/viewer/grphics.h +++ b/viewer/grphics.h @@ -76,6 +76,8 @@ BOOL8 moveon, BOOL8 upon, BOOL8 keyon); extern WINCREATEFUNC create_func; extern void (*overlap_func) (BOOL8); extern WINDOW (*await_event_func) (WINDOW, BOOL8, INT8, GRAPHICS_EVENT *); +const int kInputSize = 16; +extern int input_unicode[kInputSize]; class DLLSYM WINFD { @@ -182,11 +184,11 @@ class DLLSYM WINFD float rotation, /*rotation of arc */ INT16 close_type); /*type of closure */ /*destroy a window */ - virtual void Destroy_window(); + virtual void Destroy_window(); /*clear window */ - virtual void Clear_view_surface(); + virtual void Clear_view_surface(); /*Mark need to recalc */ - virtual void Re_compute_colourmap(); + virtual void Re_compute_colourmap(); virtual void Vdc_extent( /*set window focus */ float xmin, /*min values */ float ymin, /*min values */ @@ -197,7 +199,7 @@ class DLLSYM WINFD float xorig, /*min values */ float yorig); /*min values */ /*update window */ - virtual void Make_picture_current(); + virtual void Make_picture_current(); /*flush output */ friend void def_overlap_picture_ops(BOOL8 update); /*send make_ */ /*set line colour */ @@ -224,7 +226,7 @@ class DLLSYM WINFD void Set_click_handler( //set callback function EVENT_HANDLER handler); //handler function /*delete all events */ - virtual void Clear_event_queue(); + virtual void Clear_event_queue(); //internal maintenance functions friend void add_event( /*add an event */ @@ -244,15 +246,15 @@ class DLLSYM WINFD //callback function EVENT_HANDLER destroy_handler; private: - void get_lock() { + void get_lock() { } //wait for lock - void get_lock_for_draw() { + void get_lock_for_draw() { } //kill draw thread - void release_lock() { + void release_lock() { } //let it go - void get_core_lock() { + void get_core_lock() { } //wait for lock - void release_core_lock() { + void release_core_lock() { } //let it go INT16 fd; //"file descriptor"