diff options
author | Jakub Jelinek <jakub@redhat.com> | 2005-07-07 17:58:16 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2005-07-07 17:58:16 +0200 |
commit | d1e3d6ae11f6d436d0bbbc295e4d5a93a055829d (patch) | |
tree | 99bb771816d3b38f2aaf8d4ae3fbb546935bc476 /gcc | |
parent | 4c3a6ca189d0bf3a62b4f529275e0a666543650c (diff) | |
download | gcc-d1e3d6ae11f6d436d0bbbc295e4d5a93a055829d.zip gcc-d1e3d6ae11f6d436d0bbbc295e4d5a93a055829d.tar.gz gcc-d1e3d6ae11f6d436d0bbbc295e4d5a93a055829d.tar.bz2 |
scanner.c (load_line): Add pbuflen argument, don't make buflen static.
* scanner.c (load_line): Add pbuflen argument, don't make
buflen static. If maxlen == 0 or preprocessor_flag,
don't truncate at buflen, but at maxlen. In xrealloc add
1 byte at the end for the terminating '\0'. Don't fill
with spaces up to buflen, but gfc_option.fixed_line_length.
(load_file): Adjust load_line caller. Add line_len variable.
* gfortran.dg/longline.f: New test.
From-SVN: r101718
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/fortran/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/fortran/scanner.c | 30 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 2 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/longline.f | 10 |
4 files changed, 36 insertions, 13 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 45ae28c..5de8b3c 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,5 +1,12 @@ 2005-07-07 Jakub Jelinek <jakub@redhat.com> + * scanner.c (load_line): Add pbuflen argument, don't make + buflen static. If maxlen == 0 or preprocessor_flag, + don't truncate at buflen, but at maxlen. In xrealloc add + 1 byte at the end for the terminating '\0'. Don't fill + with spaces up to buflen, but gfc_option.fixed_line_length. + (load_file): Adjust load_line caller. Add line_len variable. + * scanner.c (preprocessor_line): Only set current_file->line when errors have not been encountered. Warn and don't crash if a file leave preprocessor line has no corresponding entering line. Formatting. diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c index b2efd81..fe28820 100644 --- a/gcc/fortran/scanner.c +++ b/gcc/fortran/scanner.c @@ -683,11 +683,10 @@ gfc_gobble_whitespace (void) load_line returns wether the line was truncated. */ static int -load_line (FILE * input, char **pbuf) +load_line (FILE * input, char **pbuf, int *pbuflen) { - int c, maxlen, i, preprocessor_flag; + int c, maxlen, i, preprocessor_flag, buflen = *pbuflen; int trunc_flag = 0; - static int buflen = 0; char *buffer; /* Determine the maximum allowed line length. */ @@ -753,15 +752,18 @@ load_line (FILE * input, char **pbuf) *buffer++ = c; i++; - if (i >= buflen && (maxlen == 0 || preprocessor_flag)) + if (maxlen == 0 || preprocessor_flag) { - /* Reallocate line buffer to double size to hold the - overlong line. */ - buflen = buflen * 2; - *pbuf = xrealloc (*pbuf, buflen); - buffer = (*pbuf)+i; + if (i >= buflen) + { + /* Reallocate line buffer to double size to hold the + overlong line. */ + buflen = buflen * 2; + *pbuf = xrealloc (*pbuf, buflen + 1); + buffer = (*pbuf)+i; + } } - else if (i >= buflen) + else if (i >= maxlen) { /* Truncate the rest of the line. */ for (;;) @@ -782,10 +784,11 @@ load_line (FILE * input, char **pbuf) && gfc_option.fixed_line_length > 0 && !preprocessor_flag && c != EOF) - while (i++ < buflen) + while (i++ < gfc_option.fixed_line_length) *buffer++ = ' '; *buffer = '\0'; + *pbuflen = buflen; return trunc_flag; } @@ -1001,7 +1004,7 @@ load_file (char *filename, bool initial) gfc_linebuf *b; gfc_file *f; FILE *input; - int len; + int len, line_len; for (f = current_file; f; f = f->up) if (strcmp (filename, f->filename) == 0) @@ -1036,10 +1039,11 @@ load_file (char *filename, bool initial) current_file = f; current_file->line = 1; line = NULL; + line_len = 0; for (;;) { - int trunc = load_line (input, &line); + int trunc = load_line (input, &line, &line_len); len = strlen (line); if (feof (input) && len == 0) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 36a93cd..6ce5a0f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,7 @@ 2005-07-07 Jakub Jelinek <jakub@redhat.com> + * gfortran.dg/longline.f: New test. + * gfortran.dg/badline.f: New test. 2005-07-07 Feng Wang <fengwang@nudt.edu.cn> diff --git a/gcc/testsuite/gfortran.dg/longline.f b/gcc/testsuite/gfortran.dg/longline.f new file mode 100644 index 0000000..ffd5a4b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/longline.f @@ -0,0 +1,10 @@ +# 1 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.f" +! { dg-do compile } + + subroutine foo + character*10 cpnam + character*4 csig + write (34,808) csig,ilax,cpnam + 808 format (/9X,4HTHE ,A4, 29HTIVE MINOS ERROR OF PARAMETER,I3, 2H + +, ,A10) + end |