Skip to content

Commit

Permalink
patch 8.1.0927: USE_CR is never defined
Browse files Browse the repository at this point in the history
Problem:    USE_CR is never defined.
Solution:   Remove usage of USE_CR. (Ken Takata, closes #3958)
  • Loading branch information
brammool committed Feb 15, 2019
1 parent e93e5a5 commit 0059074
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 224 deletions.
10 changes: 4 additions & 6 deletions runtime/doc/options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3134,9 +3134,8 @@ A jump table for the options with a short description can be found at |Q_op|.
is read.

*'fileformat'* *'ff'*
'fileformat' 'ff' string (MS-DOS, MS-Windows, OS/2 default: "dos",
Unix default: "unix",
Macintosh default: "mac")
'fileformat' 'ff' string (MS-Windows default: "dos",
Unix, macOS default: "unix")
local to buffer
{not in Vi}
This gives the <EOL> of the current buffer, which is used for
Expand All @@ -3159,9 +3158,8 @@ A jump table for the options with a short description can be found at |Q_op|.

*'fileformats'* *'ffs'*
'fileformats' 'ffs' string (default:
Vim+Vi MS-DOS, MS-Windows OS/2: "dos,unix",
Vim Unix: "unix,dos",
Vim Mac: "mac,unix,dos",
Vim+Vi MS-Windows: "dos,unix",
Vim Unix, macOS: "unix,dos",
Vi Cygwin: "unix,dos",
Vi others: "")
global
Expand Down
12 changes: 4 additions & 8 deletions src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ static int parse_diff_ed(char_u *line, linenr_T *lnum_orig, long *count_orig, li
static int parse_diff_unified(char_u *line, linenr_T *lnum_orig, long *count_orig, linenr_T *lnum_new, long *count_new);
static int xdiff_out(void *priv, mmbuffer_t *mb, int nbuf);

#ifndef USE_CR
# define tag_fgets vim_fgets
#endif

/*
* Called when deleting or unloading a buffer: No longer make a diff with it.
*/
Expand Down Expand Up @@ -996,7 +992,7 @@ check_external_diff(diffio_T *diffio)
for (;;)
{
/* There must be a line that contains "1c1". */
if (tag_fgets(linebuf, LBUFLEN, fd))
if (vim_fgets(linebuf, LBUFLEN, fd))
break;
if (STRNCMP(linebuf, "1c1", 3) == 0)
ok = TRUE;
Expand Down Expand Up @@ -1604,7 +1600,7 @@ diff_read(
}
else
{
if (tag_fgets(linebuf, LBUFLEN, fd))
if (vim_fgets(linebuf, LBUFLEN, fd))
break; // end of file
line = linebuf;
}
Expand All @@ -1626,9 +1622,9 @@ diff_read(
else if ((STRNCMP(line, "@@ ", 3) == 0))
diffstyle = DIFF_UNIFIED;
else if ((STRNCMP(line, "--- ", 4) == 0)
&& (tag_fgets(linebuf, LBUFLEN, fd) == 0)
&& (vim_fgets(linebuf, LBUFLEN, fd) == 0)
&& (STRNCMP(line, "+++ ", 4) == 0)
&& (tag_fgets(linebuf, LBUFLEN, fd) == 0)
&& (vim_fgets(linebuf, LBUFLEN, fd) == 0)
&& (STRNCMP(line, "@@ ", 3) == 0))
diffstyle = DIFF_UNIFIED;
else
Expand Down
16 changes: 1 addition & 15 deletions src/evalfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13431,20 +13431,7 @@ get_cmd_output_as_rettv(
else
{
res = get_cmd_output(tv_get_string(&argvars[0]), infile, flags, NULL);
#ifdef USE_CR
/* translate <CR> into <NL> */
if (res != NULL)
{
char_u *s;

for (s = res; *s; ++s)
{
if (*s == CAR)
*s = NL;
}
}
#else
# ifdef USE_CRNL
#ifdef USE_CRNL
/* translate <CR><NL> into <NL> */
if (res != NULL)
{
Expand All @@ -13459,7 +13446,6 @@ get_cmd_output_as_rettv(
}
*d = NUL;
}
# endif
#endif
rettv->vval.v_string = res;
res = NULL;
Expand Down
110 changes: 4 additions & 106 deletions src/ex_cmds2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ check_due_timer(void)
did_throw = FALSE;
current_exception = NULL;
save_vimvars(&vvsave);

ch_log(NULL, "calling timer callback");
timer->tr_firing = TRUE;
timer_callback(timer);
timer->tr_firing = FALSE;
Expand Down Expand Up @@ -4243,7 +4243,7 @@ struct source_cookie
FILE *fp; /* opened file for sourcing */
char_u *nextline; /* if not NULL: line that was read ahead */
int finished; /* ":finish" used */
#if defined(USE_CRNL) || defined(USE_CR)
#ifdef USE_CRNL
int fileformat; /* EOL_UNKNOWN, EOL_UNIX or EOL_DOS */
int error; /* TRUE if LF found after CR-LF */
#endif
Expand Down Expand Up @@ -4465,15 +4465,6 @@ do_source(
cookie.error = FALSE;
#endif

#ifdef USE_CR
/* If no automatic file format: Set default to CR. */
if (*p_ffs == NUL)
cookie.fileformat = EOL_MAC;
else
cookie.fileformat = EOL_UNKNOWN;
cookie.error = FALSE;
#endif

cookie.nextline = NULL;
cookie.finished = FALSE;

Expand Down Expand Up @@ -4768,59 +4759,6 @@ free_scriptnames(void)

#endif

#if defined(USE_CR) || defined(PROTO)

# if defined(__MSL__) && (__MSL__ >= 22)
/*
* Newer version of the Metrowerks library handle DOS and UNIX files
* without help.
* Test with earlier versions, MSL 2.2 is the library supplied with
* Codewarrior Pro 2.
*/
char *
fgets_cr(char *s, int n, FILE *stream)
{
return fgets(s, n, stream);
}
# else
/*
* Version of fgets() which also works for lines ending in a <CR> only
* (Macintosh format).
* For older versions of the Metrowerks library.
* At least CodeWarrior 9 needed this code.
*/
char *
fgets_cr(char *s, int n, FILE *stream)
{
int c = 0;
int char_read = 0;

while (!feof(stream) && c != '\r' && c != '\n' && char_read < n - 1)
{
c = fgetc(stream);
s[char_read++] = c;
/* If the file is in DOS format, we need to skip a NL after a CR. I
* thought it was the other way around, but this appears to work... */
if (c == '\n')
{
c = fgetc(stream);
if (c != '\r')
ungetc(c, stream);
}
}

s[char_read] = 0;
if (char_read == 0)
return NULL;

if (feof(stream) && char_read == 1)
return NULL;

return s;
}
# endif
#endif

/*
* Get one full line from a sourced file.
* Called by do_cmdline() when it's called from do_source().
Expand Down Expand Up @@ -4953,9 +4891,6 @@ get_one_sourceline(struct source_cookie *sp)
char_u *buf;
#ifdef USE_CRNL
int has_cr; /* CR-LF found */
#endif
#ifdef USE_CR
char_u *scan;
#endif
int have_read = FALSE;

Expand All @@ -4973,18 +4908,9 @@ get_one_sourceline(struct source_cookie *sp)
break;
buf = (char_u *)ga.ga_data;

#ifdef USE_CR
if (sp->fileformat == EOL_MAC)
{
if (fgets_cr((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len,
if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len,
sp->fp) == NULL)
break;
}
else
#endif
if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len,
sp->fp) == NULL)
break;
break;
len = ga.ga_len + (int)STRLEN(buf + ga.ga_len);
#ifdef USE_CRNL
/* Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the
Expand All @@ -4998,34 +4924,6 @@ get_one_sourceline(struct source_cookie *sp)
}
#endif

#ifdef USE_CR
/* If the read doesn't stop on a new line, and there's
* some CR then we assume a Mac format */
if (sp->fileformat == EOL_UNKNOWN)
{
if (buf[len - 1] != '\n' && vim_strchr(buf, '\r') != NULL)
sp->fileformat = EOL_MAC;
else
sp->fileformat = EOL_UNIX;
}

if (sp->fileformat == EOL_MAC)
{
scan = vim_strchr(buf, '\r');

if (scan != NULL)
{
*scan = '\n';
if (*(scan + 1) != 0)
{
*(scan + 1) = 0;
fseek(sp->fp, (long)(scan - buf - len + 1), SEEK_CUR);
}
}
len = STRLEN(buf);
}
#endif

have_read = TRUE;
ga.ga_len = len;

Expand Down
53 changes: 1 addition & 52 deletions src/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -5216,14 +5216,12 @@ msg_add_fileformat(int eol_type)
return TRUE;
}
#endif
#ifndef USE_CR
if (eol_type == EOL_MAC)
{
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[mac]") : _("[mac format]"));
return TRUE;
}
#endif
#if defined(USE_CRNL) || defined(USE_CR)
#ifdef USE_CRNL
if (eol_type == EOL_UNIX)
{
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[unix]") : _("[unix format]"));
Expand Down Expand Up @@ -6359,11 +6357,7 @@ vim_fgets(char_u *buf, int size, FILE *fp)
char tbuf[FGETS_SIZE];

buf[size - 2] = NUL;
#ifdef USE_CR
eof = fgets_cr((char *)buf, size, fp);
#else
eof = fgets((char *)buf, size, fp);
#endif
if (buf[size - 2] != NUL && buf[size - 2] != '\n')
{
buf[size - 1] = NUL; /* Truncate the line */
Expand All @@ -6372,57 +6366,12 @@ vim_fgets(char_u *buf, int size, FILE *fp)
do
{
tbuf[FGETS_SIZE - 2] = NUL;
#ifdef USE_CR
vim_ignoredp = fgets_cr((char *)tbuf, FGETS_SIZE, fp);
#else
vim_ignoredp = fgets((char *)tbuf, FGETS_SIZE, fp);
#endif
} while (tbuf[FGETS_SIZE - 2] != NUL && tbuf[FGETS_SIZE - 2] != '\n');
}
return (eof == NULL);
}

#if defined(USE_CR) || defined(PROTO)
/*
* Like vim_fgets(), but accept any line terminator: CR, CR-LF or LF.
* Returns TRUE for end-of-file.
* Only used for the Mac, because it's much slower than vim_fgets().
*/
int
tag_fgets(char_u *buf, int size, FILE *fp)
{
int i = 0;
int c;
int eof = FALSE;

for (;;)
{
c = fgetc(fp);
if (c == EOF)
{
eof = TRUE;
break;
}
if (c == '\r')
{
/* Always store a NL for end-of-line. */
if (i < size - 1)
buf[i++] = '\n';
c = fgetc(fp);
if (c != '\n') /* Macintosh format: single CR. */
ungetc(c, fp);
break;
}
if (i < size - 1)
buf[i++] = c;
if (c == '\n')
break;
}
buf[i] = NUL;
return eof;
}
#endif

/*
* rename() only works if both files are on the same file system, this
* function will (attempts to?) copy the file across if rename fails -- webb
Expand Down
5 changes: 1 addition & 4 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -2590,10 +2590,7 @@ msg_puts_printf(char_u *str, int maxlen)
memcpy(buf, p, n);
if (!info_message)
buf[n++] = CAR;
#ifdef USE_CR
else
#endif
buf[n++] = NL;
buf[n++] = NL;
buf[n++] = NUL;
if (info_message) // informative message, not an error
mch_msg((char *)buf);
Expand Down
4 changes: 0 additions & 4 deletions src/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -6577,11 +6577,7 @@ clip_convert_selection(char_u **str, long_u *len, VimClipboard *cbd)
#ifdef USE_CRNL
p[i++] = '\r';
#endif
#ifdef USE_CR
p[i] = '\r';
#else
p[i] = '\n';
#endif
lnum++;
j = -1;
}
Expand Down
21 changes: 7 additions & 14 deletions src/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,14 @@
# define DFLT_FFS_VI "dos,unix" /* also autodetect in compatible mode */
# define DFLT_TEXTAUTO TRUE
#else
# ifdef USE_CR
# define DFLT_FF "mac"
# define DFLT_FFS_VIM "mac,unix,dos"
# define DFLT_FFS_VI "mac,unix,dos"
# define DFLT_TEXTAUTO TRUE
# define DFLT_FF "unix"
# define DFLT_FFS_VIM "unix,dos"
# ifdef __CYGWIN__
# define DFLT_FFS_VI "unix,dos" /* Cygwin always needs file detection */
# define DFLT_TEXTAUTO TRUE
# else
# define DFLT_FF "unix"
# define DFLT_FFS_VIM "unix,dos"
# ifdef __CYGWIN__
# define DFLT_FFS_VI "unix,dos" /* Cygwin always needs file detection */
# define DFLT_TEXTAUTO TRUE
# else
# define DFLT_FFS_VI ""
# define DFLT_TEXTAUTO FALSE
# endif
# define DFLT_FFS_VI ""
# define DFLT_TEXTAUTO FALSE
# endif
#endif

Expand Down
Loading

0 comments on commit 0059074

Please sign in to comment.