Hi Kevin,

On 2026-03-18T10:50:35+0800, Kevin J. McCarthy wrote:
> +  while ((buf = mutt_read_line (buf, &blen, ifp, NULL, MUTT_EOL)) != NULL)
> +  {
> +    has_nl = 0;
> +    olen = mutt_strlen (buf);
> +    if ((olen > 0) && buf[olen - 1] == '\n')
> +    {
> +      has_nl = 1;
> +      buf[olen - 1] = '\0';
> +      if ((olen > 1) && buf[olen - 2] == '\r')
> +        buf[olen - 2] = '\0';
> +    }
> +    fputs (buf, ofp);
> +    if (has_nl)
> +    {
> +      if (tocrlf)
> +        fputc ('\r', ofp);
> +      fputc ('\n', ofp);
> +    }

Just a comment about readability:

If we had a strsuffix() function, this could be written as something
like:

        while (...) {
                nl = strsuffix(buf, "\r\n") ?: strsuffix(buf, "\n");
                if (nl != NULL)
                        strcpy(nl, "");

                fputs(buf, ofp);
                if (nl != NULL) {
                        if (tocrlf)
                                fputc('\r', ofp);
                        fputc('\n', ofp);
                }
        }

I've found strsuffix() quite useful for a few things.  It's rarely used,
but when it's used, it improves readability significantly.


Have a lovely day!
Alex

> +  }
> +
> +  if (infile)
> +    safe_fclose (&ifp);
> +  if (outfile)
> +    safe_fclose (&ofp);
> +  FREE (&buf);
> +
> +  return 0;
> +}
> +
> +int mutt_convert_to_crlf (const char *infile, FILE *ifp, const char 
> *outfile, FILE *ofp)
> +{
> +  return normalize_line_endings (infile, ifp, outfile, ofp, 1);
> +}
> +
> +int mutt_convert_to_lf (const char *infile, FILE *ifp, const char *outfile, 
> FILE *ofp)
> +{
> +  return normalize_line_endings (infile, ifp, outfile, ofp, 0);
> +}
> +
> +
>  
>  /************************************************************************
>   * These functions are transplanted from lib.c, in order to modify them *
> diff --git a/protos.h b/protos.h
> index a641034a..71497f95 100644
> --- a/protos.h
> +++ b/protos.h
> @@ -323,6 +323,8 @@ int mutt_command_complete (char *, size_t, int, int);
>  int mutt_var_value_complete (char *, size_t, int);
>  int mutt_complete (char *, size_t);
>  int mutt_compose_attachment (BODY *a);
> +int mutt_convert_to_crlf (const char *, FILE *, const char *, FILE *);
> +int mutt_convert_to_lf (const char *, FILE *, const char *, FILE *);
>  int mutt_copy_body (FILE *, BODY **, BODY *);
>  int mutt_decode_save_attachment (FILE *, BODY *, const char *, int, int);
>  int mutt_display_message (HEADER *h);
> -- 
> 2.53.0
> 

-- 
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature

Reply via email to