bookloupe/bookloupe.c
changeset 191 189183b37598
parent 186 4912234d80be
parent 184 cd3068704d3a
child 192 1aeda7fe17ca
     1.1 --- a/bookloupe/bookloupe.c	Sun Sep 29 22:51:27 2013 +0100
     1.2 +++ b/bookloupe/bookloupe.c	Mon Oct 21 23:36:40 2013 +0100
     1.3 @@ -245,7 +245,7 @@
     1.4  
     1.5  gboolean mixdigit(const char *);
     1.6  gchar *getaword(const char **);
     1.7 -char *flgets(char **,long);
     1.8 +char *flgets(char **,long,gboolean);
     1.9  void postprocess_for_HTML(char *);
    1.10  char *linehasmarkup(char *);
    1.11  char *losemarkup(char *);
    1.12 @@ -735,11 +735,20 @@
    1.13      gchar *inword;
    1.14      QuoteClass qc;
    1.15      lines=g_strsplit(etext,"\n",0);
    1.16 +    if (lines[0])
    1.17 +	/* If there's at least one line, we might have UNIX-style terminators */
    1.18 +	results.unix_lineends=TRUE;
    1.19      for (j=0;lines[j];j++)
    1.20      {
    1.21  	lbytes=strlen(lines[j]);
    1.22 -	while (lbytes>0 && lines[j][lbytes-1]=='\r')
    1.23 -	    lines[j][--lbytes]='\0';
    1.24 +	if (lbytes>0 && lines[j][lbytes-1]=='\r')
    1.25 +	{
    1.26 +	    results.unix_lineends=FALSE;
    1.27 +	    do
    1.28 +	    {
    1.29 +		lines[j][--lbytes]='\0';
    1.30 +	    } while (lbytes>0 && lines[j][lbytes-1]=='\r');
    1.31 +	}
    1.32  	llen=g_utf8_strlen(lines[j],lbytes);
    1.33  	linecnt++;
    1.34  	if (strstr(lines[j],"*END") && strstr(lines[j],"SMALL PRINT") &&
    1.35 @@ -881,6 +890,13 @@
    1.36  struct warnings *report_first_pass(struct first_pass_results *results)
    1.37  {
    1.38      static struct warnings warnings={0};
    1.39 +    warnings.nocr=1;
    1.40 +    if (results->unix_lineends)
    1.41 +    {
    1.42 +	warnings.nocr=0;
    1.43 +	g_print("   --> No lines in this file have a CR. Not reporting them. "
    1.44 +	  "Project Gutenberg requires that all lineends be CR-LF.\n");
    1.45 +    }
    1.46      if (cnt_spacend>0)
    1.47  	g_print("   --> %ld lines in this file have white space at end\n",
    1.48  	  cnt_spacend);
    1.49 @@ -2869,7 +2885,7 @@
    1.50       */
    1.51      linecnt=0;
    1.52      etext_ptr=etext;
    1.53 -    while ((aline=flgets(&etext_ptr,linecnt+1)))
    1.54 +    while ((aline=flgets(&etext_ptr,linecnt+1,warnings->nocr)))
    1.55      {
    1.56  	linecnt++;
    1.57  	if (linecnt==1)
    1.58 @@ -3015,7 +3031,7 @@
    1.59   *
    1.60   * Returns: a pointer to the line.
    1.61   */
    1.62 -char *flgets(char **etext,long lcnt)
    1.63 +char *flgets(char **etext,long lcnt,gboolean warn_nocr)
    1.64  {
    1.65      gunichar c;
    1.66      gboolean isCR=FALSE;
    1.67 @@ -3054,7 +3070,7 @@
    1.68  	    else
    1.69  	    {
    1.70  		/* Error - a LF without a preceding CR */
    1.71 -		if (pswit[LINE_END_SWITCH])
    1.72 +		if (pswit[LINE_END_SWITCH] && warn_nocr)
    1.73  		{
    1.74  		    if (pswit[ECHO_SWITCH])
    1.75  		    {