diff -r ad92d11d59b8 -r cd3068704d3a bookloupe/bookloupe.c --- a/bookloupe/bookloupe.c Tue Oct 15 09:16:04 2013 +0100 +++ b/bookloupe/bookloupe.c Sun Oct 20 21:06:25 2013 +0100 @@ -183,7 +183,7 @@ gboolean mixdigit(const char *); gchar *getaword(const char **); -char *flgets(char **,long); +char *flgets(char **,long,gboolean); void postprocess_for_HTML(char *); char *linehasmarkup(char *); char *losemarkup(char *); @@ -487,11 +487,20 @@ gchar *inword; QuoteClass qc; lines=g_strsplit(etext,"\n",0); + if (lines[0]) + /* If there's at least one line, we might have UNIX-style terminators */ + results.unix_lineends=TRUE; for (j=0;lines[j];j++) { lbytes=strlen(lines[j]); - while (lbytes>0 && lines[j][lbytes-1]=='\r') - lines[j][--lbytes]='\0'; + if (lbytes>0 && lines[j][lbytes-1]=='\r') + { + results.unix_lineends=FALSE; + do + { + lines[j][--lbytes]='\0'; + } while (lbytes>0 && lines[j][lbytes-1]=='\r'); + } llen=g_utf8_strlen(lines[j],lbytes); linecnt++; if (strstr(lines[j],"*END") && strstr(lines[j],"SMALL PRINT") && @@ -633,6 +642,13 @@ struct warnings *report_first_pass(struct first_pass_results *results) { static struct warnings warnings={0}; + warnings.nocr=1; + if (results->unix_lineends) + { + warnings.nocr=0; + g_print(" --> No lines in this file have a CR. Not reporting them. " + "Project Gutenberg requires that all lineends be CR-LF.\n"); + } if (cnt_spacend>0) g_print(" --> %ld lines in this file have white space at end\n", cnt_spacend); @@ -2621,7 +2637,7 @@ */ linecnt=0; etext_ptr=etext; - while ((aline=flgets(&etext_ptr,linecnt+1))) + while ((aline=flgets(&etext_ptr,linecnt+1,warnings->nocr))) { linecnt++; if (linecnt==1) @@ -2767,7 +2783,7 @@ * * Returns: a pointer to the line. */ -char *flgets(char **etext,long lcnt) +char *flgets(char **etext,long lcnt,gboolean warn_nocr) { gunichar c; gboolean isCR=FALSE; @@ -2806,7 +2822,7 @@ else { /* Error - a LF without a preceding CR */ - if (pswit[LINE_END_SWITCH]) + if (pswit[LINE_END_SWITCH] && warn_nocr) { if (pswit[ECHO_SWITCH]) {