texlive[55464] Build/source/texk/web2c: [CWEB] Handle special 'files'

commits+ascherer at tug.org commits+ascherer at tug.org
Sun Jun 7 17:37:44 CEST 2020


Revision: 55464
          http://tug.org/svn/texlive?view=revision&revision=55464
Author:   ascherer
Date:     2020-06-07 17:37:44 +0200 (Sun, 07 Jun 2020)
Log Message:
-----------
[CWEB] Handle special 'files' as secondary output.

Modified Paths:
--------------
    trunk/Build/source/texk/web2c/ChangeLog
    trunk/Build/source/texk/web2c/ctangleboot.cin
    trunk/Build/source/texk/web2c/cwebdir/ChangeLog
    trunk/Build/source/texk/web2c/cwebdir/ctang-w2c.ch

Modified: trunk/Build/source/texk/web2c/ChangeLog
===================================================================
--- trunk/Build/source/texk/web2c/ChangeLog	2020-06-07 10:41:27 UTC (rev 55463)
+++ trunk/Build/source/texk/web2c/ChangeLog	2020-06-07 15:37:44 UTC (rev 55464)
@@ -1,5 +1,9 @@
 2020-06-07  Andreas Scherer  <https://ascherer.github.io>
 
+	* ctangleboot.cin: Handle special 'files' as secondary output.
+
+2020-06-07  Andreas Scherer  <https://ascherer.github.io>
+
 	* ctangleboot.cin,
 	* cwebboot.cin: Check accessibility to output files.
 

Modified: trunk/Build/source/texk/web2c/ctangleboot.cin
===================================================================
--- trunk/Build/source/texk/web2c/ctangleboot.cin	2020-06-07 10:41:27 UTC (rev 55463)
+++ trunk/Build/source/texk/web2c/ctangleboot.cin	2020-06-07 15:37:44 UTC (rev 55464)
@@ -289,12 +289,12 @@
 extern void cb_show_banner(void);
 #line 128 "cwebdir/ctangle.w"
 
-/*:15*//*104:*/
-#line 839 "cwebdir/ctang-w2c.ch"
+/*:15*//*108:*/
+#line 886 "cwebdir/ctang-w2c.ch"
 
 extern char cb_banner[];
 
-/*:104*/
+/*:108*/
 #line 67 "cwebdir/ctangle.w"
 
 /*16:*/
@@ -524,12 +524,12 @@
 #line 1116 "cwebdir/ctangle.w"
 section_text[0]= ' ';
 
-/*:71*//*105:*/
-#line 842 "cwebdir/ctang-w2c.ch"
+/*:71*//*109:*/
+#line 889 "cwebdir/ctang-w2c.ch"
 
 strncpy(cb_banner,banner,max_banner-1);
 
-/*:105*/
+/*:109*/
 #line 98 "cwebdir/ctangle.w"
 ;
 common_init();
@@ -828,8 +828,112 @@
 while(stack_ptr> stack)get_output();
 flush_buffer();fclose(C_file);C_file= NULL;
 /*102:*/
-#line 816 "cwebdir/ctang-w2c.ch"
+#line 821 "cwebdir/ctang-w2c.ch"
 
+if(0==strcmp("/dev/stdout",output_file_name))
+/*104:*/
+#line 846 "cwebdir/ctang-w2c.ch"
+{
+/*107:*/
+#line 873 "cwebdir/ctang-w2c.ch"
+
+char in_buf[BUFSIZ+1];
+int in_size,comparison= true;
+if((check_file= fopen(check_file_name,"r"))==NULL)
+fatal("! Cannot open output file ",check_file_name);
+
+
+/*:107*/
+#line 847 "cwebdir/ctang-w2c.ch"
+
+do{
+in_size= fread(in_buf,1,BUFSIZ,check_file);
+in_buf[in_size]= '\0';
+fprintf(stdout,"%s",in_buf);
+}while(!feof(check_file));
+fclose(check_file);check_file= NULL;
+/*103:*/
+#line 838 "cwebdir/ctang-w2c.ch"
+
+if(comparison)
+remove(check_file_name);
+else{
+remove(output_file_name);
+rename(check_file_name,output_file_name);
+}
+
+/*:103*/
+#line 854 "cwebdir/ctang-w2c.ch"
+
+}
+
+/*:104*/
+#line 823 "cwebdir/ctang-w2c.ch"
+
+else if(0==strcmp("/dev/stderr",output_file_name))
+/*105:*/
+#line 857 "cwebdir/ctang-w2c.ch"
+{
+/*107:*/
+#line 873 "cwebdir/ctang-w2c.ch"
+
+char in_buf[BUFSIZ+1];
+int in_size,comparison= true;
+if((check_file= fopen(check_file_name,"r"))==NULL)
+fatal("! Cannot open output file ",check_file_name);
+
+
+/*:107*/
+#line 858 "cwebdir/ctang-w2c.ch"
+
+do{
+in_size= fread(in_buf,1,BUFSIZ,check_file);
+in_buf[in_size]= '\0';
+fprintf(stderr,"%s",in_buf);
+}while(!feof(check_file));
+fclose(check_file);check_file= NULL;
+/*103:*/
+#line 838 "cwebdir/ctang-w2c.ch"
+
+if(comparison)
+remove(check_file_name);
+else{
+remove(output_file_name);
+rename(check_file_name,output_file_name);
+}
+
+/*:103*/
+#line 865 "cwebdir/ctang-w2c.ch"
+
+}
+
+/*:105*/
+#line 825 "cwebdir/ctang-w2c.ch"
+
+else if(0==strcmp("/dev/null",output_file_name))
+/*106:*/
+#line 868 "cwebdir/ctang-w2c.ch"
+{
+int comparison= true;
+/*103:*/
+#line 838 "cwebdir/ctang-w2c.ch"
+
+if(comparison)
+remove(check_file_name);
+else{
+remove(output_file_name);
+rename(check_file_name,output_file_name);
+}
+
+/*:103*/
+#line 870 "cwebdir/ctang-w2c.ch"
+
+}
+
+/*:106*/
+#line 827 "cwebdir/ctang-w2c.ch"
+
+else{
 if((C_file= fopen(output_file_name,"r"))!=NULL){
 /*99:*/
 #line 782 "cwebdir/ctang-w2c.ch"
@@ -859,10 +963,10 @@
 fclose(check_file);check_file= NULL;
 
 /*:99*/
-#line 818 "cwebdir/ctang-w2c.ch"
+#line 830 "cwebdir/ctang-w2c.ch"
 
 /*103:*/
-#line 825 "cwebdir/ctang-w2c.ch"
+#line 838 "cwebdir/ctang-w2c.ch"
 
 if(comparison)
 remove(check_file_name);
@@ -872,10 +976,11 @@
 }
 
 /*:103*/
-#line 819 "cwebdir/ctang-w2c.ch"
+#line 831 "cwebdir/ctang-w2c.ch"
 
 }else
 rename(check_file_name,output_file_name);
+}
 
 /*:102*/
 #line 330 "cwebdir/ctang-w2c.ch"

Modified: trunk/Build/source/texk/web2c/cwebdir/ChangeLog
===================================================================
--- trunk/Build/source/texk/web2c/cwebdir/ChangeLog	2020-06-07 10:41:27 UTC (rev 55463)
+++ trunk/Build/source/texk/web2c/cwebdir/ChangeLog	2020-06-07 15:37:44 UTC (rev 55464)
@@ -1,5 +1,9 @@
 2020-06-07  Andreas Scherer  <https://ascherer.github.io>
 
+	* ctang-w2c.ch: Handle special 'files' as secondary output.
+
+2020-06-07  Andreas Scherer  <https://ascherer.github.io>
+
 	* comm-w2c.ch,
 	* ctang-w2c.ch,
 	* cweav-w2c.ch,

Modified: trunk/Build/source/texk/web2c/cwebdir/ctang-w2c.ch
===================================================================
--- trunk/Build/source/texk/web2c/cwebdir/ctang-w2c.ch	2020-06-07 10:41:27 UTC (rev 55463)
+++ trunk/Build/source/texk/web2c/cwebdir/ctang-w2c.ch	2020-06-07 15:37:44 UTC (rev 55464)
@@ -813,13 +813,26 @@
   rename(check_file_name,C_file_name);
 }
 
-@ @<Update the secondary results...@>=
-if((C_file=fopen(output_file_name,"r"))!=NULL) {
-  @<Set up the comparison of temporary output@>@;
-  @<Create the secondary output depending on the comparison@>@;
-} else
-  rename(check_file_name,output_file_name); /* This was the first run */
+@ The author of a \.{CWEB} program may want to write the \\{secondary} output
+instead of to a file (in \.{@@(...@@>}) to \.{/dev/null} or \.{/dev/stdout} or
+\.{/dev/stderr}.  We must take care of the \\{temporary} output already written
+to a file and finally get rid of that file.
 
+@<Update the secondary results...@>=
+if(0==strcmp("/dev/stdout",output_file_name))
+  @<Redirect temporary output to \.{/dev/stdout}@>@;
+else if(0==strcmp("/dev/stderr",output_file_name))
+  @<Redirect temporary output to \.{/dev/stderr}@>@;
+else if(0==strcmp("/dev/null",output_file_name))
+  @<Redirect temporary output to \.{/dev/null}@>@;
+else { /* Hopefully a \\{regular} output file */
+  if((C_file=fopen(output_file_name,"r"))!=NULL) {
+    @<Set up the comparison of temporary output@>@;
+    @<Create the secondary output depending on the comparison@>@;
+  } else
+    rename(check_file_name,output_file_name); /* This was the first run */
+}
+
 @ Again, we use a call to |remove| before |rename|.
 
 @<Create the secondary output...@>=
@@ -830,6 +843,40 @@
   rename(check_file_name,output_file_name);
 }
 
+@ @<Redirect temporary output to \.{/dev/stdout}@>={
+  @<Setup system redirection@>@;
+  do {
+    in_size = fread(in_buf,1,BUFSIZ,check_file);
+    in_buf[in_size]='\0';
+    fprintf(stdout,"%s",in_buf);
+  } while(!feof(check_file));@/
+  fclose(check_file); check_file=NULL;
+  @<Create the secondary output...@>@;
+}
+
+@ @<Redirect temporary output to \.{/dev/stderr}@>={
+  @<Setup system redirection@>@;
+  do {
+    in_size = fread(in_buf,1,BUFSIZ,check_file);
+    in_buf[in_size]='\0';
+    fprintf(stderr,"%s",in_buf);
+  } while(!feof(check_file));@/
+  fclose(check_file); check_file=NULL;
+  @<Create the secondary output...@>@;
+}
+
+@ @<Redirect temporary output to \.{/dev/null}@>={
+  int comparison=true;
+  @<Create the secondary output...@>@;
+}
+
+@ @<Setup system redirection@>=
+char in_buf[BUFSIZ+1];
+int in_size,comparison=true;
+if((check_file=fopen(check_file_name,"r"))==NULL)
+  fatal("! Cannot open output file ",check_file_name);
+ at .Cannot open output file@>
+
 @* Put ``version'' information in a single spot.
 Don't do this at home, kids! Push our local macro to the variable in \.{COMMON}
 for printing the |banner| and the |versionstring| from there.



More information about the tex-live-commits mailing list.