• R/O
  • SSH

wp2latex: Commit

WP2LaTeX sources.


Commit MetaInfo

Revisiond2cb0513333373ba4e8de178314c30b24bf7db0a (tree)
Time2021-10-12 06:46:58
AuthorFojtik
CommiterFojtik

Log Message

Fix for multithread building. File is created with different name and it is renamed after finishing.

Change Summary

Incremental Difference

diff -r 3e8cadb4c1c5 -r d2cb05133333 trunk/sources.cc/cp_lib/cpbldr.cc
--- a/trunk/sources.cc/cp_lib/cpbldr.cc Sun Oct 10 13:12:11 2021 +0200
+++ b/trunk/sources.cc/cp_lib/cpbldr.cc Mon Oct 11 23:46:58 2021 +0200
@@ -388,6 +388,27 @@
388388 }
389389
390390
391+/// Multithreading build fails when a file growing in progress is accessed by
392+/// another job. It is safe to create a different file and reneme it when it is finished.
393+int FcloseEpilog(FILE *F, const char *TmpFilename, const char *PersistentFilename)
394+{
395+string FileName2;
396+ if(F) fclose(F);
397+ ForgeFname(FileName2, PersistentFilename);
398+ if((F=fopen(TmpFilename,"r"))!=NULL) // Destroy older file if exists.
399+ {
400+ fclose(F);
401+ remove(FileName2());
402+ }
403+ if(rename(TmpFilename, FileName2()))
404+ {
405+ printf("Cannot rename file from \"%s\" to \"%s\"!", TmpFilename, FileName2());
406+ return -1;
407+ }
408+return 0;
409+}
410+
411+
391412 int main(int argc, char *argv[])
392413 {
393414 FILE *F;
@@ -473,7 +494,7 @@
473494 printf("%ld\n",coreleft());
474495
475496
476- ForgeFname(FileName, "trn.trn");
497+ ForgeFname(FileName, "trn.new");
477498 if((F=fopen(FileName(),"w"))==NULL)
478499 {
479500 printf("Cannot write to the file \"%s\"", FileName());
@@ -494,14 +515,10 @@
494515 CreateTranslator(trn,cpwp6, internal);
495516 WriteTranslator(cpwp6,internal,trn,F);
496517
497-
498-
499-
500518 //if(heapcheck()<=0)
501519 // asm int 3;
502520 //goto end;
503521
504-
505522 /*
506523 CreateTranslator(trn,cpkam,internal);
507524 WriteTranslator(cpkam,internal,trn,F);
@@ -510,21 +527,20 @@
510527 WriteTranslator(cp1250,internal,trn,F);
511528 */
512529
513-
514530 /*
515531 trn=CreateTranslator(cp1250,cpkam);
516532 WriteTranslator(cp1250,cpkam,trn,F);
517533 */
518534
519535 //end:
520- fclose(F);
536+ if(FcloseEpilog(F,FileName(),"trn.trn")) return -1;
521537
522538
523539 LoadTextCodePage("html",llHTML);
524540 llHTML.sort(strcmp);
525541 CreateCodePage("html",cphtml,llHTML);
526542
527- ForgeFname(FileName, "html.trn");
543+ ForgeFname(FileName, "html.new");
528544 if((F=fopen(FileName(),"w"))==NULL)
529545 {
530546 printf("Cannot write to the file \"%s\"", FileName());
@@ -534,12 +550,10 @@
534550 CreateTranslator(trn,cphtml, internal);
535551 WriteTranslator(cphtml,internal,trn,F);
536552 WriteStringTable(F,cphtml,llHTML);
537- fclose(F);
553+ if(FcloseEpilog(F,FileName(),"html.trn")) return -1;
538554
539555
540- FileName=Directory;
541- if(FileName.length()>0) FileName+=DIR_DEPARATOR;
542- FileName += "cpg.trn";
556+ ForgeFname(FileName, "cpg.new");
543557 if((F=fopen(FileName(),"w"))==NULL)
544558 {
545559 printf("Cannot write to the file \"%s\"", FileName());
@@ -611,11 +625,10 @@
611625 CreateTranslator(trn, internal, iso_8859_2);
612626 WriteTranslator(internal, iso_8859_2, trn, F);
613627 */
614-
615- fclose(F);
628+ if(FcloseEpilog(F,FileName(),"cpg.trn")) return -1;
616629
617630
618- ForgeFname(FileName, "mtef.trn");
631+ ForgeFname(FileName, "mtef.new");
619632 if((F=fopen(FileName(),"w"))==NULL)
620633 {
621634 printf("Cannot write to the file \"%s\"", FileName());
@@ -628,11 +641,11 @@
628641
629642 CreateTranslator(trn,mtef2,internal);
630643 WriteTranslator(mtef2,internal,trn,F);
631- fclose(F);
644+ if(FcloseEpilog(F,FileName(),"mtef.trn")) return -1;
632645
633646
634647 SkipMtef:
635- ForgeFname(FileName, "macroman.trn");
648+ ForgeFname(FileName, "macroman.new");
636649 if((F=fopen(FileName(),"w"))==NULL)
637650 {
638651 printf("Cannot write to the file \"%s\"", FileName());
@@ -641,7 +654,7 @@
641654 fprintf(F,"/*Do not edit this file. It is automatically generated.*/\n");
642655 CreateTranslator(trn,MAC_ROMAN,internal);
643656 WriteTranslator(MAC_ROMAN,internal,trn,F);
644- fclose(F);
657+ if(FcloseEpilog(F,FileName(),"macroman.trn")) return -1;
645658
646659
647660 trn.erase();
diff -r 3e8cadb4c1c5 -r d2cb05133333 trunk/sources.cc/wp2latex.h
--- a/trunk/sources.cc/wp2latex.h Sun Oct 10 13:12:11 2021 +0200
+++ b/trunk/sources.cc/wp2latex.h Mon Oct 11 23:46:58 2021 +0200
@@ -18,7 +18,7 @@
1818 #define LineLength 80 /* Split lines after more than LineLength charcters */
1919
2020 #define VersionWP2L "3.pre101"
21-#define VersionDate "10 Oct 2021" /* day (space) month (space) full year */
21+#define VersionDate "11 Oct 2021" /* day (space) month (space) full year */
2222
2323 #ifndef false
2424 #define false 0
Show on old repository browser