Skip to content

Commit

Permalink
[CWEB] Use 'kpse_find_file' for '*.bux' files.
Browse files Browse the repository at this point in the history
In addition to '*.aux' files that CTWILL creates dynamically on the
first run ("Prime the pump"), it uses several '*.bux' files to resolve
external definitions, e.g., in other CWEB modules or in system headers.

The '*.aux' file(s) are always created in the "current" directory, but
the auxiliary '*.bux' file(s) can reside elsewhere in the file system.

Just like other '@i'nclude files, these '*.bux' files can be addressed
through the CWEBINPUTS environment variable.

git-svn-id: svn://tug.org/texlive/trunk/Build/source@67416 c570f23f-e606-0410-a88d-b1316a301751
  • Loading branch information
Andreas Scherer committed Jun 20, 2023
1 parent f98d308 commit d772006
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 20 deletions.
5 changes: 5 additions & 0 deletions texk/web2c/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2023-06-20 Andreas Scherer <https://ascherer.github.io>

* ctangleboot.cin,
* cwebboot.cin: Changes in cwebdir/comm-w2c.h.

2023-06-18 Karl Berry <karl@freefriends.org>

* am/cweb.am (dist_bin_SCRIPTS): new script cwebdir/ctwill-proofsort.
Expand Down
19 changes: 10 additions & 9 deletions texk/web2c/ctangleboot.cin
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ extern char file_name[][max_file_name_length];

extern char change_file_name[];
extern char check_file_name[];
extern char*found_filename;
extern int line[];
extern int change_line;
extern int change_depth;
Expand All @@ -216,15 +217,15 @@ extern boolean changing;
extern boolean web_file_open;

/*:7*//*9:*/
#line 150 "cwebdir/comm-w2c.h"
#line 151 "cwebdir/comm-w2c.h"

extern sixteen_bits section_count;
extern boolean changed_section[];
extern boolean change_pending;
extern boolean print_where;

/*:9*//*10:*/
#line 164 "cwebdir/comm-w2c.h"
#line 165 "cwebdir/comm-w2c.h"

typedef struct name_info{
char*byte_start;
Expand All @@ -249,12 +250,12 @@ extern hash_pointer hash_end;
extern hash_pointer h;

/*:10*//*12:*/
#line 208 "cwebdir/comm-w2c.h"
#line 209 "cwebdir/comm-w2c.h"

extern int history;

/*:12*//*14:*/
#line 225 "cwebdir/comm-w2c.h"
#line 226 "cwebdir/comm-w2c.h"

extern int argc;
extern char**argv;
Expand All @@ -266,7 +267,7 @@ extern boolean flags[];
extern const char*use_language;

/*:14*//*15:*/
#line 240 "cwebdir/comm-w2c.h"
#line 241 "cwebdir/comm-w2c.h"

extern FILE*C_file;
extern FILE*tex_file;
Expand Down Expand Up @@ -387,14 +388,14 @@ static eight_bits next_control;
#line 71 "cwebdir/ctangle.w"

/*8:*/
#line 144 "cwebdir/comm-w2c.h"
#line 145 "cwebdir/comm-w2c.h"

extern boolean get_line(void);
extern void check_complete(void);
extern void reset_input(void);

/*:8*//*11:*/
#line 187 "cwebdir/comm-w2c.h"
#line 188 "cwebdir/comm-w2c.h"

extern boolean names_match(name_pointer,const char*,size_t,eight_bits);
extern name_pointer id_lookup(const char*,const char*,eight_bits);
Expand All @@ -407,15 +408,15 @@ extern void print_section_name(name_pointer);
extern void sprint_section_name(char*,name_pointer);

/*:11*//*13:*/
#line 211 "cwebdir/comm-w2c.h"
#line 212 "cwebdir/comm-w2c.h"

extern int wrap_up(void);
extern void err_print(const char*);
extern void fatal(const char*,const char*);
extern void overflow(const char*);

/*:13*//*16:*/
#line 249 "cwebdir/comm-w2c.h"
#line 250 "cwebdir/comm-w2c.h"

extern void common_init(void);
extern void print_stats(void);
Expand Down
19 changes: 10 additions & 9 deletions texk/web2c/cwebboot.cin
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ extern char file_name[][max_file_name_length];

extern char change_file_name[];
extern char check_file_name[];
extern char*found_filename;
extern int line[];
extern int change_line;
extern int change_depth;
Expand All @@ -222,15 +223,15 @@ extern boolean changing;
extern boolean web_file_open;

/*:6*//*8:*/
#line 150 "cwebdir/comm-w2c.h"
#line 151 "cwebdir/comm-w2c.h"

extern sixteen_bits section_count;
extern boolean changed_section[];
extern boolean change_pending;
extern boolean print_where;

/*:8*//*9:*/
#line 164 "cwebdir/comm-w2c.h"
#line 165 "cwebdir/comm-w2c.h"

typedef struct name_info{
char*byte_start;
Expand All @@ -255,12 +256,12 @@ extern hash_pointer hash_end;
extern hash_pointer h;

/*:9*//*11:*/
#line 208 "cwebdir/comm-w2c.h"
#line 209 "cwebdir/comm-w2c.h"

extern int history;

/*:11*//*13:*/
#line 225 "cwebdir/comm-w2c.h"
#line 226 "cwebdir/comm-w2c.h"

extern int argc;
extern char**argv;
Expand All @@ -272,7 +273,7 @@ extern boolean flags[];
extern const char*use_language;

/*:13*//*14:*/
#line 240 "cwebdir/comm-w2c.h"
#line 241 "cwebdir/comm-w2c.h"

extern FILE*C_file;
extern FILE*tex_file;
Expand Down Expand Up @@ -420,14 +421,14 @@ string texmf_locale;
#line 66 "cwebdir/common.w"

/*7:*/
#line 144 "cwebdir/comm-w2c.h"
#line 145 "cwebdir/comm-w2c.h"

extern boolean get_line(void);
extern void check_complete(void);
extern void reset_input(void);

/*:7*//*10:*/
#line 187 "cwebdir/comm-w2c.h"
#line 188 "cwebdir/comm-w2c.h"

extern boolean names_match(name_pointer,const char*,size_t,eight_bits);
extern name_pointer id_lookup(const char*,const char*,eight_bits);
Expand All @@ -440,15 +441,15 @@ extern void print_section_name(name_pointer);
extern void sprint_section_name(char*,name_pointer);

/*:10*//*12:*/
#line 211 "cwebdir/comm-w2c.h"
#line 212 "cwebdir/comm-w2c.h"

extern int wrap_up(void);
extern void err_print(const char*);
extern void fatal(const char*,const char*);
extern void overflow(const char*);

/*:12*//*15:*/
#line 249 "cwebdir/comm-w2c.h"
#line 250 "cwebdir/comm-w2c.h"

extern void common_init(void);
extern void print_stats(void);
Expand Down
7 changes: 7 additions & 0 deletions texk/web2c/cwebdir/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2023-06-20 Andreas Scherer <https://ascherer.github.io>

* comm-w2c.h,
* ctwill-mini.ch,
* ctwill-w2c.ch,
* ctwill.bux: Use 'kpse_find_file' for '*.bux' files.

2023-06-18 Karl Berry <karl@freefriends.org>

* ctwill-proofsort: die if getopt fails;
Expand Down
1 change: 1 addition & 0 deletions texk/web2c/cwebdir/comm-w2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ extern char file_name[][max_file_name_length];
/* stack of non-change file names */
extern char change_file_name[]; /* name of change file */
extern char check_file_name[]; /* name of |check_file| */
extern char *found_filename; /* filename found by |kpse_find_file| */
extern int line[]; /* number of current line in the stacked files */
extern int change_line; /* number of current line in change file */
extern int change_depth; /* where \.{@@y} originated during a change */
Expand Down
9 changes: 9 additions & 0 deletions texk/web2c/cwebdir/ctwill-mini.ch
Original file line number Diff line number Diff line change
Expand Up @@ -2161,6 +2161,15 @@ Section 322.
Section 328.
@x l.116 of CTWILL-TEXLIVE.CH
@d kpse_find_cweb(name) kpse_find_file(name,kpse_cweb_format,true)
@y
@d kpse_find_cweb(name) kpse_find_file(name,kpse_cweb_format,true)
@-name@>
@z
Section 330.
@x
@** Index.
If you have read and understood the code for Phase III above, you know what
Expand Down
50 changes: 48 additions & 2 deletions texk/web2c/cwebdir/ctwill-w2c.ch
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
@x
\def\title{CWEAVE (Version 4.9)}
@y
\def\Kpathsea/{{\mc KPATHSEA\spacefactor1000}} \ifacro\sanitizecommand\Kpathsea{KPATHSEA}\fi
\def\title{CTWILL (Version 4.9 [\TeX~Live])}
@z

Expand Down Expand Up @@ -1787,12 +1788,20 @@ memcpy(aux_file_name,tex_file_name,strlen(tex_file_name)-4);
strcat(aux_file_name,".bux");
include_depth=1; /* we simulate \.{@@i} */
strcpy(cur_file_name,aux_file_name); /* first in, third out */
if ((cur_file=fopen(cur_file_name,"r"))) { cur_line=0; include_depth++; }
if ( (found_filename = kpse_find_cweb(cur_file_name)) @|
&& ((cur_file=fopen(found_filename,"r"))) ) {
@<Set up |cur_file_name| for opened |cur_file|@>@;
cur_line=0; include_depth++;
}
strcpy(aux_file_name+strlen(aux_file_name)-4,".aux");@/
strcpy(cur_file_name,aux_file_name); /* second in, second out */
if ((cur_file=fopen(cur_file_name,"r"))) { cur_line=0; include_depth++; }
strcpy(cur_file_name,"system.bux"); /* third in, first out */
if ((cur_file=fopen(cur_file_name,"r"))) cur_line=0;
if ( (found_filename = kpse_find_cweb(cur_file_name)) @|
&& ((cur_file=fopen(found_filename,"r"))) ) {
@<Set up |cur_file_name| for opened |cur_file|@>@;
cur_line=0;
}
else include_depth--;
if (include_depth) { /* at least one new file was opened */
while (get_next()==meaning) ; /* new meaning is digested */
Expand Down Expand Up @@ -2036,6 +2045,43 @@ extern char cb_banner[];
@ @<Set init...@>=
strncpy(cb_banner,banner,max_banner-1);

@* File lookup with \Kpathsea/. The \.{CTANGLE} and \.{CWEAVE} programs from
the original \.{CWEB} package use the compile-time default directory or the
value of the environment variable \.{CWEBINPUTS} as an alternative place to be
searched for files, if they could not be found in the current directory.

This version uses the \Kpathsea/ mechanism for searching files.
The directories to be searched for come from three sources:
\smallskip
{\parindent1em
\item{(a)} a user-set environment variable \.{CWEBINPUTS}
(overridden by \.{CWEBINPUTS\_cweb});
\item{(b)} a line in \Kpathsea/ configuration file \.{texmf.cnf},\hfil\break
e.g., \.{CWEBINPUTS=\$TEXMFDOTDIR:\$TEXMF/texmf/cweb//}\hfil\break
or \.{CWEBINPUTS.cweb=\$TEXMFDOTDIR:\$TEXMF/texmf/cweb//};
\item{(c)} compile-time default directories (specified in
\.{texmf.in}),\hfil\break
i.e., \.{\$TEXMFDOTDIR:\$TEXMF/texmf/cweb//}.\par}
@.CWEBINPUTS@>

@s const_string int
@s string int

@d kpse_find_cweb(name) kpse_find_file(name,kpse_cweb_format,true)

@<Include files@>=
#include <kpathsea/kpathsea.h> /* include every \Kpathsea/ header;
for |@!kpse_find_file| */

@ @<Set up |cur_file_name|...@>=
if (strlen(found_filename) < max_file_name_length) {
if (strcmp(cur_file_name,found_filename)) {
strcpy(cur_file_name,found_filename + @|
((strncmp(found_filename,"./",2)==0) ? 2 : 0)); /* Strip path prefix */
free(found_filename);
}
}@+else fatal(_("! Filename too long\n"), found_filename);

@** Index.
@z

3 changes: 3 additions & 0 deletions texk/web2c/cwebdir/ctwill.bux
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@
@$scn_file {COMMON.W}83 \&{FILE} ${*}$@>
@$check_file {COMMON.W}83 \&{FILE} ${*}$@>
@$active_file {COMMON.W}83 \&{FILE} ${*}$@>
@$found_filename {COMMON.W}83 \&{char} ${*}$@>

@$use_language {COMMON.W}86 \&{const char} ${*}$@>

@$cb_banner {COMMON.W}87 \&{char} [\,]@>

@$cb_show_banner {COMMON.W}99 \&{void} (\,)@>

@$kpse_cweb_format "<kpathsea/types.h>" \zip@>
@$kpse_find_file "<kpathsea/tex-file.h>" \zip@>
@$versionstring "<lib/lib.h>" \zip@>

0 comments on commit d772006

Please sign in to comment.