@@ -269,39 +269,44 @@ static void pyformat(FILE *file, FILE *out, struct vlbuf *origfile,
269
269
char string_starter = '\0' ;
270
270
int line_state = LINE_IS_NORMAL ;
271
271
int leading_spaces = 0 ;
272
- int neof = 0 ;
273
272
int nestings = 0 ;
274
273
int netlen = 0 ;
275
274
int origfilelen = 0 ;
276
275
int formfilelen = 0 ;
276
+ int no_more_lines = 0 ;
277
277
while (1 ) {
278
- char * readct ;
279
278
int llen = 0 ;
280
- while (1 ) {
281
- readct = fgets (& linebuf .d .ch [llen ], linebuf .len - 3 - llen , file );
282
- if (!readct )
283
- break ;
284
- int rlen = strlen (readct );
285
- if (origfile ) {
286
- if (origfile -> len < rlen + origfilelen )
287
- vlbuf_expand (origfile , rlen + origfilelen );
288
- memcpy (& origfile -> d .ch [origfilelen ], & linebuf .d .ch [llen ], rlen + 1 );
289
- origfilelen += rlen ;
290
- }
291
- llen += rlen ;
292
- if (linebuf .d .ch [llen - 1 ] != '\n' ) {
293
- vlbuf_expand (& linebuf , llen + 3 );
294
- } else {
295
- break ;
279
+ {
280
+ char * readct ;
281
+ while (1 ) {
282
+ readct = fgets (& linebuf .d .ch [llen ], linebuf .len - 3 - llen , file );
283
+ if (!readct )
284
+ break ;
285
+ int rlen = strlen (readct );
286
+ if (feof (file ) && readct [rlen - 1 ] != '\n' ) {
287
+ /* if file ends, preserve line invariants by adding newline */
288
+ readct [rlen ] = '\n' ;
289
+ readct [rlen + 1 ] = '\0' ;
290
+ rlen ++ ;
291
+ no_more_lines = 1 ;
292
+ }
293
+ if (origfile ) {
294
+ if (origfile -> len < rlen + origfilelen )
295
+ vlbuf_expand (origfile , rlen + origfilelen );
296
+ memcpy (& origfile -> d .ch [origfilelen ], & linebuf .d .ch [llen ], rlen + 1 );
297
+ origfilelen += rlen ;
298
+ }
299
+ llen += rlen ;
300
+
301
+ if (linebuf .d .ch [llen - 1 ] != '\n' ) {
302
+ vlbuf_expand (& linebuf , llen + 3 );
303
+ } else {
304
+ break ;
305
+ }
296
306
}
297
- }
298
307
299
- if (!readct ) {
300
- if ((line_state == LINE_IS_NORMAL || line_state == LINE_IS_BLANK ) ||
301
- neof ) {
308
+ if (!readct ) {
302
309
break ;
303
- } else {
304
- neof = 1 ;
305
310
}
306
311
}
307
312
@@ -505,6 +510,8 @@ static void pyformat(FILE *file, FILE *out, struct vlbuf *origfile,
505
510
} else if (lopchar == '*' && nxt == '*' ) {
506
511
proctok = TOK_EXP ;
507
512
} else if (lopchar == '/' && nxt == '/' ) {
513
+ } else if (lopchar == '>' && nxt == '>' ) {
514
+ } else if (lopchar == '<' && nxt == '<' ) {
508
515
} else if (nxt == '=' ) {
509
516
if (proctok == TOK_EXP ) {
510
517
proctok = TOK_OPERATOR ;
@@ -624,7 +631,7 @@ static void pyformat(FILE *file, FILE *out, struct vlbuf *origfile,
624
631
625
632
if (line_state == LINE_IS_BLANK && !dumprest ) {
626
633
formfilelen = vlbuf_append (formfile , "\n" , formfilelen , out );
627
- } else if (line_state == LINE_IS_NORMAL || neof || dumprest ) {
634
+ } else if (line_state == LINE_IS_NORMAL || no_more_lines || dumprest ) {
628
635
/* Introduce spaces to list */
629
636
630
637
/* split ratings 0 is regular; -1 is force/cmt; 1 is weak */
0 commit comments