@@ -269,39 +269,44 @@ static void pyformat(FILE *file, FILE *out, struct vlbuf *origfile,
269269 char string_starter = '\0' ;
270270 int line_state = LINE_IS_NORMAL ;
271271 int leading_spaces = 0 ;
272- int neof = 0 ;
273272 int nestings = 0 ;
274273 int netlen = 0 ;
275274 int origfilelen = 0 ;
276275 int formfilelen = 0 ;
276+ int no_more_lines = 0 ;
277277 while (1 ) {
278- char * readct ;
279278 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+ }
296306 }
297- }
298307
299- if (!readct ) {
300- if ((line_state == LINE_IS_NORMAL || line_state == LINE_IS_BLANK ) ||
301- neof ) {
308+ if (!readct ) {
302309 break ;
303- } else {
304- neof = 1 ;
305310 }
306311 }
307312
@@ -505,6 +510,8 @@ static void pyformat(FILE *file, FILE *out, struct vlbuf *origfile,
505510 } else if (lopchar == '*' && nxt == '*' ) {
506511 proctok = TOK_EXP ;
507512 } else if (lopchar == '/' && nxt == '/' ) {
513+ } else if (lopchar == '>' && nxt == '>' ) {
514+ } else if (lopchar == '<' && nxt == '<' ) {
508515 } else if (nxt == '=' ) {
509516 if (proctok == TOK_EXP ) {
510517 proctok = TOK_OPERATOR ;
@@ -624,7 +631,7 @@ static void pyformat(FILE *file, FILE *out, struct vlbuf *origfile,
624631
625632 if (line_state == LINE_IS_BLANK && !dumprest ) {
626633 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 ) {
628635 /* Introduce spaces to list */
629636
630637 /* split ratings 0 is regular; -1 is force/cmt; 1 is weak */
0 commit comments