@@ -578,8 +578,12 @@ void MasterTrainer::WriteInttempAndPFFMTable(const UNICHARSET& unicharset,
578
578
INT_TEMPLATES int_templates = classify->CreateIntTemplates (float_classes,
579
579
shape_set);
580
580
FILE* fp = fopen (inttemp_file, " wb" );
581
- classify->WriteIntTemplates (fp, int_templates, shape_set);
582
- fclose (fp);
581
+ if (fp == nullptr ) {
582
+ tprintf (" Error, failed to open file \" %s\"\n " , inttemp_file);
583
+ } else {
584
+ classify->WriteIntTemplates (fp, int_templates, shape_set);
585
+ fclose (fp);
586
+ }
583
587
// Now write pffmtable. This is complicated by the fact that the adaptive
584
588
// classifier still wants one indexed by unichar-id, but the static
585
589
// classifier needs one indexed by its shape class id.
@@ -612,15 +616,19 @@ void MasterTrainer::WriteInttempAndPFFMTable(const UNICHARSET& unicharset,
612
616
shapetable_cutoffs.push_back (max_length);
613
617
}
614
618
fp = fopen (pffmtable_file, " wb" );
615
- shapetable_cutoffs.Serialize (fp);
616
- for (int c = 0 ; c < unicharset.size (); ++c) {
617
- const char *unichar = unicharset.id_to_unichar (c);
618
- if (strcmp (unichar, " " ) == 0 ) {
619
- unichar = " NULL" ;
619
+ if (fp == nullptr ) {
620
+ tprintf (" Error, failed to open file \" %s\"\n " , pffmtable_file);
621
+ } else {
622
+ shapetable_cutoffs.Serialize (fp);
623
+ for (int c = 0 ; c < unicharset.size (); ++c) {
624
+ const char *unichar = unicharset.id_to_unichar (c);
625
+ if (strcmp (unichar, " " ) == 0 ) {
626
+ unichar = " NULL" ;
627
+ }
628
+ fprintf (fp, " %s %d\n " , unichar, unichar_cutoffs[c]);
620
629
}
621
- fprintf (fp, " %s %d \n " , unichar, unichar_cutoffs[c] );
630
+ fclose (fp);
622
631
}
623
- fclose (fp);
624
632
free_int_templates (int_templates);
625
633
delete classify;
626
634
}
0 commit comments