| 1 |
This is the change file to CWEB's COMMON for porting to Macintoshes. |
| 2 |
No changes to CTANGLE or CWEAVE are needed. |
| 3 |
|
| 4 |
(Contributed 13 Oct 2000 by [email protected]; slightly edited by Don Knuth) |
| 5 |
|
| 6 |
@x in limbo, change the title page document to specify Mac version |
| 7 |
\centerline{(Version 4.12.2)} |
| 8 |
@y |
| 9 |
\centerline{(Version 4.12.2 for MacOS)} |
| 10 |
@z |
| 11 |
|
| 12 |
@x section 23: Make input_ln accept \n, \r, \n\r, or \r\n as line endings |
| 13 |
@ In the unlikely event that your standard I/O library does not |
| 14 |
support |feof| and |getc| you may have to change things here. |
| 15 |
@^system dependencies@> |
| 16 |
|
| 17 |
@c |
| 18 |
static bool input_ln( /* copies a line into |buffer| or returns |false| */ |
| 19 |
FILE *fp) /* what file to read from */ |
| 20 |
{ |
| 21 |
int c=EOF; /* character read; initialized so some compilers won't complain */ |
| 22 |
char *k; /* where next character goes */ |
| 23 |
if (feof(fp)) return false; /* we have hit end-of-file */ |
| 24 |
limit = k = buffer; /* beginning of buffer */ |
| 25 |
while (k<=buffer_end && (c=getc(fp)) != EOF && c!='\n') |
| 26 |
if ((*(k++) = c) != ' ') limit = k; |
| 27 |
if (k>buffer_end) { |
| 28 |
while ((c=getc(fp))!=EOF && c!='\n'); /* discard rest of line */ |
| 29 |
loc=buffer; err_print("! Input line too long"); |
| 30 |
@.Input line too long@> |
| 31 |
} |
| 32 |
if (c==EOF && limit==buffer) return false; /* there was nothing after |
| 33 |
the last newline */ |
| 34 |
return true; |
| 35 |
} |
| 36 |
@y |
| 37 |
@ In the unlikely event that your standard I/O library does not |
| 38 |
support |feof|, |getc|, and |ungetc| you may have to change things here. |
| 39 |
|
| 40 |
This |input_ln| function accepts |"\n"|, |"\r"|, |"\n\r"| and |"\r\n"| as |
| 41 |
line endings, so that \.{CWEB} will works with ASCII files stored in |
| 42 |
\UNIX/, {\mc DOS} or {\mc MAC} format. |
| 43 |
@^system dependencies@> |
| 44 |
|
| 45 |
@c |
| 46 |
static bool input_ln( /* copies a line into |buffer| or returns |false| */ |
| 47 |
FILE *fp) /* what file to read from */ |
| 48 |
{ |
| 49 |
int c=EOF; /* character read; initialized so some compilers won't complain */ |
| 50 |
char *k; /* where next character goes */ |
| 51 |
if (feof(fp)) return false; /* we have hit end-of-file */ |
| 52 |
limit = k = buffer; /* beginning of buffer */ |
| 53 |
while (true) { |
| 54 |
c = getc(fp); |
| 55 |
if (c==EOF) return limit!=buffer; /* |false|, if there was nothing after |
| 56 |
the last newline */ |
| 57 |
else if (c=='\n' || c=='\r') { /* we have hit end-of-line */ |
| 58 |
int d = getc(fp); |
| 59 |
if (c+d!='\n'+'\r') /* no combination |"\n\r"| or |"\r\n"| */ |
| 60 |
ungetc(d,fp); |
| 61 |
return true; |
| 62 |
} |
| 63 |
else if (k>buffer_end) { |
| 64 |
while ((c=getc(fp))!=EOF && c!='\n' && c!='\r'); /* discard rest of line */ |
| 65 |
return true; |
| 66 |
@.Input line too long@> |
| 67 |
} |
| 68 |
else |
| 69 |
if ((*(k++)=c) != ' ') limit = k; |
| 70 |
} |
| 71 |
} |
| 72 |
@z |
| 73 |
|
| 74 |
@x section 27, simply return if no change file was specified |
| 75 |
change_limit=change_buffer; /* this value is used if the change file ends */ |
| 76 |
@<Skip over comment lines in the change file; |return| if end of file@>@; |
| 77 |
@y |
| 78 |
change_limit=change_buffer; /* this value is used if the change file ends */ |
| 79 |
if (change_file_name[0] == '\0') /* no change file specified */ |
| 80 |
return; /* so we have reached the end of that file */ |
| 81 |
@<Skip over comment lines in the change file; |return| if end of file@>@; |
| 82 |
@z |
| 83 |
|
| 84 |
@x section 36, declare colon as Mac's path separator |
| 85 |
(Colon-separated paths are not supported.) |
| 86 |
The remainder of the \.{@@i} line after the file name is ignored. |
| 87 |
|
| 88 |
@y |
| 89 |
(Colon-separated path alternatives in the style of \UNIX/ or Kpathsea |
| 90 |
are not supported. On a Macintosh, colons are used to separate the names on |
| 91 |
different levels of a path.) |
| 92 |
The remainder of the \.{@@i} line after the file name is ignored. |
| 93 |
|
| 94 |
@d PATH_SEP ':' /* MacOS pathname separator */ |
| 95 |
@^system dependencies@> |
| 96 |
@z |
| 97 |
@x section 36, use the path separator constant |
| 98 |
cur_file_name[l]='/'; /* \UNIX/ pathname separator */ |
| 99 |
@y |
| 100 |
cur_file_name[l]=PATH_SEP; /* pathname separator */ |
| 101 |
@z |
| 102 |
|
| 103 |
@x section 41, don't try to open a change file if none was specified |
| 104 |
if ((change_file=fopen(change_file_name,"r"))==NULL) |
| 105 |
fatal("! Cannot open change file ", change_file_name); |
| 106 |
@y |
| 107 |
if (change_file_name[0] == '\0') /* no change file specified */ |
| 108 |
change_file = NULL; /* reset at least the |change_file| */ |
| 109 |
else if ((change_file=fopen(change_file_name,"r"))==NULL) |
| 110 |
fatal("! Cannot open change file ", change_file_name); |
| 111 |
@z |
| 112 |
|
| 113 |
@x section 75, explain the convention for omitted change files |
| 114 |
An omitted change file argument means that |"/dev/null"| should be used, |
| 115 |
@y |
| 116 |
An omitted change file argument means that no change file should be used, |
| 117 |
@z |
| 118 |
@x section 75, make change file name empty when it is unspecified |
| 119 |
strcpy(change_file_name,"/dev/null"); |
| 120 |
@y |
| 121 |
change_file_name[0]='\0'; /* empty string */ |
| 122 |
@z |
| 123 |
@x section 75, use the Metrowerks |ccommand| to access command lines |
| 124 |
while (--argc > 0) { |
| 125 |
@y |
| 126 |
argc = ccommand (&argv); /* use Mac interface to command line */ |
| 127 |
@^system dependencies@> |
| 128 |
while (--argc > 0) { |
| 129 |
@z |
| 130 |
@x section 75, use the path separator constant |
| 131 |
else if (*s=='/') dot_pos=NULL,name_pos=++s; |
| 132 |
@y |
| 133 |
else if (*s==PATH_SEP) dot_pos=NULL,name_pos=++s; |
| 134 |
@z |
| 135 |
|
| 136 |
@x section 85, insert an extra module before the index |
| 137 |
@* Index. |
| 138 |
@y by putting the new module here, we preserve all the previous section numbers |
| 139 |
@ We assume an interface to \CEE/ command-line emulation as supplied by |
| 140 |
the |ccommand| function of Metrowerks CodeWarrior, as defined in |
| 141 |
the header file \.{console.h}. |
| 142 |
|
| 143 |
@<Include files@>= |
| 144 |
#include <console.h> |
| 145 |
@^system dependencies@> |
| 146 |
|
| 147 |
@* Index. |
| 148 |
@z |