Accept standard input as an inputstream (Hanzac Chen)
This commit is contained in:
16
tcc-doc.texi
16
tcc-doc.texi
@ -94,9 +94,11 @@ the @code{main()} of a.c.
|
|||||||
|
|
||||||
@item @samp{tcc a.c -run b.c arg1}
|
@item @samp{tcc a.c -run b.c arg1}
|
||||||
Compile @file{a.c} and @file{b.c}, link them together and execute them. arg1 is given
|
Compile @file{a.c} and @file{b.c}, link them together and execute them. arg1 is given
|
||||||
as first argument to the @code{main()} of the resulting program. Because
|
as first argument to the @code{main()} of the resulting program.
|
||||||
multiple C files are specified, @option{--} are necessary to clearly separate the
|
@ignore
|
||||||
program arguments from the TCC options.
|
Because multiple C files are specified, @option{--} are necessary to clearly
|
||||||
|
separate the program arguments from the TCC options.
|
||||||
|
@end ignore
|
||||||
|
|
||||||
@item @samp{tcc -o myprog a.c b.c}
|
@item @samp{tcc -o myprog a.c b.c}
|
||||||
Compile @file{a.c} and @file{b.c}, link them and generate the executable @file{myprog}.
|
Compile @file{a.c} and @file{b.c}, link them and generate the executable @file{myprog}.
|
||||||
@ -135,6 +137,13 @@ int main()
|
|||||||
return 0;
|
return 0;
|
||||||
@}
|
@}
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
|
TCC can read C source code from @emph{standard input} when @option{-} is used in
|
||||||
|
place of @option{infile}. Example:
|
||||||
|
|
||||||
|
@example
|
||||||
|
echo 'main(){puts("hello");}' | tcc -run -
|
||||||
|
@end example
|
||||||
@c man end
|
@c man end
|
||||||
|
|
||||||
@section Option summary
|
@section Option summary
|
||||||
@ -160,7 +169,6 @@ Set the path where the tcc internal libraries can be found (default is
|
|||||||
Output compilation statistics.
|
Output compilation statistics.
|
||||||
|
|
||||||
@item -run source [args...]
|
@item -run source [args...]
|
||||||
|
|
||||||
Compile file @var{source} and run it with the command line arguments
|
Compile file @var{source} and run it with the command line arguments
|
||||||
@var{args}. In order to be able to give more than one argument to a
|
@var{args}. In order to be able to give more than one argument to a
|
||||||
script, several TCC options can be given @emph{after} the
|
script, several TCC options can be given @emph{after} the
|
||||||
|
|||||||
17
tcc.c
17
tcc.c
@ -1956,14 +1956,13 @@ BufferedFile *tcc_open(TCCState *s1, const char *filename)
|
|||||||
int fd;
|
int fd;
|
||||||
BufferedFile *bf;
|
BufferedFile *bf;
|
||||||
|
|
||||||
fd = open(filename, O_RDONLY | O_BINARY);
|
if (strcmp(filename, "-") == 0)
|
||||||
|
fd = 0, filename = "stdin";
|
||||||
|
else
|
||||||
|
fd = open(filename, O_RDONLY | O_BINARY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
bf = tcc_malloc(sizeof(BufferedFile));
|
bf = tcc_malloc(sizeof(BufferedFile));
|
||||||
if (!bf) {
|
|
||||||
close(fd);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
bf->fd = fd;
|
bf->fd = fd;
|
||||||
bf->buf_ptr = bf->buffer;
|
bf->buf_ptr = bf->buffer;
|
||||||
bf->buf_end = bf->buffer;
|
bf->buf_end = bf->buffer;
|
||||||
@ -10730,7 +10729,7 @@ int parse_args(TCCState *s, int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
r = argv[optind++];
|
r = argv[optind++];
|
||||||
if (r[0] != '-') {
|
if (r[0] != '-' || r[1] == '\0') {
|
||||||
/* add a new file */
|
/* add a new file */
|
||||||
dynarray_add((void ***)&files, &nb_files, r);
|
dynarray_add((void ***)&files, &nb_files, r);
|
||||||
if (!multiple_files) {
|
if (!multiple_files) {
|
||||||
@ -10982,7 +10981,9 @@ int main(int argc, char **argv)
|
|||||||
if (!outfile) {
|
if (!outfile) {
|
||||||
/* compute default outfile name */
|
/* compute default outfile name */
|
||||||
char *ext;
|
char *ext;
|
||||||
pstrcpy(objfilename, sizeof(objfilename), tcc_basename(files[0]));
|
const char *name =
|
||||||
|
strcmp(files[0], "-") == 0 ? "a" : tcc_basename(files[0]);
|
||||||
|
pstrcpy(objfilename, sizeof(objfilename), name);
|
||||||
ext = tcc_fileextension(objfilename);
|
ext = tcc_fileextension(objfilename);
|
||||||
#ifdef TCC_TARGET_PE
|
#ifdef TCC_TARGET_PE
|
||||||
if (output_type == TCC_OUTPUT_DLL)
|
if (output_type == TCC_OUTPUT_DLL)
|
||||||
@ -11015,7 +11016,7 @@ int main(int argc, char **argv)
|
|||||||
if (tcc_add_file_internal(s, filename,
|
if (tcc_add_file_internal(s, filename,
|
||||||
AFF_PRINT_ERROR | AFF_PREPROCESS) < 0)
|
AFF_PRINT_ERROR | AFF_PREPROCESS) < 0)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
} else if (filename[0] == '-') {
|
} else if (filename[0] == '-' && filename[1]) {
|
||||||
if (tcc_add_library(s, filename + 2) < 0)
|
if (tcc_add_library(s, filename + 2) < 0)
|
||||||
error("cannot find %s", filename);
|
error("cannot find %s", filename);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user