Remove USE_CR and tag_fgets. #808

These features are only used by legacy Mac OS.
This commit is contained in:
Justin M. Keyes 2014-06-04 05:05:32 +00:00
parent 1e54b04bc0
commit 01ca4600ba
7 changed files with 9 additions and 165 deletions

View File

@ -50,9 +50,6 @@ static int diff_a_works = MAYBE;
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "diff.c.generated.h" # include "diff.c.generated.h"
#endif #endif
#ifndef USE_CR
# define tag_fgets vim_fgets
#endif // ifndef USE_CR
/// Called when deleting or unloading a buffer: No longer make a diff with it. /// Called when deleting or unloading a buffer: No longer make a diff with it.
/// ///
@ -702,7 +699,7 @@ void ex_diffupdate(exarg_T *eap)
for (;;) { for (;;) {
// There must be a line that contains "1c1". // There must be a line that contains "1c1".
if (tag_fgets(linebuf, LBUFLEN, fd)) { if (vim_fgets(linebuf, LBUFLEN, fd)) {
break; break;
} }
@ -1209,7 +1206,7 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname)
} }
for (;;) { for (;;) {
if (tag_fgets(linebuf, LBUFLEN, fd)) { if (vim_fgets(linebuf, LBUFLEN, fd)) {
// end of file // end of file
break; break;
} }

View File

@ -14086,18 +14086,7 @@ static void f_system(typval_T *argvars, typval_T *rettv)
res = get_cmd_output(get_tv_string(&argvars[0]), infile, res = get_cmd_output(get_tv_string(&argvars[0]), infile,
kShellOptSilent | kShellOptCooked); kShellOptSilent | kShellOptCooked);
#ifdef USE_CR #ifdef USE_CRNL
/* translate <CR> into <NL> */
if (res != NULL) {
char_u *s;
for (s = res; *s; ++s) {
if (*s == CAR)
*s = NL;
}
}
#else
# ifdef USE_CRNL
/* translate <CR><NL> into <NL> */ /* translate <CR><NL> into <NL> */
if (res != NULL) { if (res != NULL) {
char_u *s, *d; char_u *s, *d;
@ -14110,7 +14099,6 @@ static void f_system(typval_T *argvars, typval_T *rettv)
} }
*d = NUL; *d = NUL;
} }
# endif
#endif #endif
done: done:

View File

@ -94,7 +94,7 @@ struct source_cookie {
FILE *fp; /* opened file for sourcing */ FILE *fp; /* opened file for sourcing */
char_u *nextline; /* if not NULL: line that was read ahead */ char_u *nextline; /* if not NULL: line that was read ahead */
int finished; /* ":finish" used */ int finished; /* ":finish" used */
#if defined(USE_CRNL) || defined(USE_CR) #if defined(USE_CRNL)
int fileformat; /* EOL_UNKNOWN, EOL_UNIX or EOL_DOS */ int fileformat; /* EOL_UNKNOWN, EOL_UNIX or EOL_DOS */
int error; /* TRUE if LF found after CR-LF */ int error; /* TRUE if LF found after CR-LF */
#endif #endif
@ -2520,15 +2520,6 @@ do_source (
cookie.error = FALSE; cookie.error = FALSE;
#endif #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.nextline = NULL;
cookie.finished = FALSE; cookie.finished = FALSE;
@ -2755,41 +2746,6 @@ void free_scriptnames(void)
# endif # endif
#if defined(USE_CR) || defined(PROTO)
/*
* 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
/* /*
* Get one full line from a sourced file. * Get one full line from a sourced file.
* Called by do_cmdline() when it's called from do_source(). * Called by do_cmdline() when it's called from do_source().
@ -2896,9 +2852,6 @@ static char_u *get_one_sourceline(struct source_cookie *sp)
char_u *buf; char_u *buf;
#ifdef USE_CRNL #ifdef USE_CRNL
int has_cr; /* CR-LF found */ int has_cr; /* CR-LF found */
#endif
#ifdef USE_CR
char_u *scan;
#endif #endif
int have_read = FALSE; int have_read = FALSE;
@ -2914,13 +2867,6 @@ static char_u *get_one_sourceline(struct source_cookie *sp)
ga_grow(&ga, 120); ga_grow(&ga, 120);
buf = (char_u *)ga.ga_data; 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,
sp->fp) == NULL)
break;
} else
#endif
if (fgets((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) sp->fp) == NULL)
break; break;
@ -2936,30 +2882,6 @@ static char_u *get_one_sourceline(struct source_cookie *sp)
} }
#endif #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; have_read = TRUE;
ga.ga_len = len; ga.ga_len = len;

View File

@ -3844,13 +3844,11 @@ static int msg_add_fileformat(int eol_type)
return TRUE; return TRUE;
} }
#endif #endif
#ifndef USE_CR
if (eol_type == EOL_MAC) { if (eol_type == EOL_MAC) {
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[mac]") : _("[mac format]")); STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[mac]") : _("[mac format]"));
return TRUE; return TRUE;
} }
#endif #ifdef USE_CRNL
#if defined(USE_CRNL) || defined(USE_CR)
if (eol_type == EOL_UNIX) { if (eol_type == EOL_UNIX) {
STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[unix]") : _("[unix format]")); STRCAT(IObuff, shortmess(SHM_TEXT) ? _("[unix]") : _("[unix format]"));
return TRUE; return TRUE;
@ -4506,64 +4504,19 @@ int vim_fgets(char_u *buf, int size, FILE *fp)
char tbuf[FGETS_SIZE]; char tbuf[FGETS_SIZE];
buf[size - 2] = NUL; buf[size - 2] = NUL;
#ifdef USE_CR
eof = fgets_cr((char *)buf, size, fp);
#else
eof = fgets((char *)buf, size, fp); eof = fgets((char *)buf, size, fp);
#endif
if (buf[size - 2] != NUL && buf[size - 2] != '\n') { if (buf[size - 2] != NUL && buf[size - 2] != '\n') {
buf[size - 1] = NUL; /* Truncate the line */ buf[size - 1] = NUL; /* Truncate the line */
/* Now throw away the rest of the line: */ /* Now throw away the rest of the line: */
do { do {
tbuf[FGETS_SIZE - 2] = NUL; tbuf[FGETS_SIZE - 2] = NUL;
#ifdef USE_CR
ignoredp = fgets_cr((char *)tbuf, FGETS_SIZE, fp);
#else
ignoredp = fgets((char *)tbuf, FGETS_SIZE, fp); ignoredp = fgets((char *)tbuf, FGETS_SIZE, fp);
#endif
} while (tbuf[FGETS_SIZE - 2] != NUL && tbuf[FGETS_SIZE - 2] != '\n'); } while (tbuf[FGETS_SIZE - 2] != NUL && tbuf[FGETS_SIZE - 2] != '\n');
} }
return eof == NULL; 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
/* /*
* os_rename() only works if both files are on the same file system, this * os_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 * function will (attempts to?) copy the file across if rename fails -- webb

View File

@ -1992,9 +1992,6 @@ static void msg_puts_printf(char_u *str, int maxlen)
p = &buf[0]; p = &buf[0];
if (*s == '\n' && !info_message) if (*s == '\n' && !info_message)
*p++ = '\r'; *p++ = '\r';
#if defined(USE_CR) && !defined(MACOS_X_UNIX)
else
#endif
*p++ = *s; *p++ = *s;
*p = '\0'; *p = '\0';
if (info_message) /* informative message, not an error */ if (info_message) /* informative message, not an error */

View File

@ -39,15 +39,9 @@
# define DFLT_FFS_VIM "dos,unix" # define DFLT_FFS_VIM "dos,unix"
# define DFLT_FFS_VI "dos,unix" /* also autodetect in compatible mode */ # define DFLT_FFS_VI "dos,unix" /* also autodetect in compatible mode */
#else #else
# ifdef USE_CR
# define DFLT_FF "mac"
# define DFLT_FFS_VIM "mac,unix,dos"
# define DFLT_FFS_VI "mac,unix,dos"
# else
# define DFLT_FF "unix" # define DFLT_FF "unix"
# define DFLT_FFS_VIM "unix,dos" # define DFLT_FFS_VIM "unix,dos"
# define DFLT_FFS_VI "" # define DFLT_FFS_VI ""
# endif
#endif #endif

View File

@ -987,13 +987,6 @@ void do_tags(exarg_T *eap)
MSG_PUTS("\n>"); MSG_PUTS("\n>");
} }
/* When not using a CR for line separator, use vim_fgets() to read tag lines.
* For the Mac use tag_fgets(). It can handle any line separator, but is much
* slower than vim_fgets().
*/
#ifndef USE_CR
# define tag_fgets vim_fgets
#endif
/* /*
@ -1355,7 +1348,7 @@ find_tags (
#else #else
fseek(fp, (long)search_info.curr_offset, SEEK_SET); fseek(fp, (long)search_info.curr_offset, SEEK_SET);
#endif #endif
eof = tag_fgets(lbuf, LSIZE, fp); eof = vim_fgets(lbuf, LSIZE, fp);
if (!eof && search_info.curr_offset != 0) { if (!eof && search_info.curr_offset != 0) {
/* The explicit cast is to work around a bug in gcc 3.4.2 /* The explicit cast is to work around a bug in gcc 3.4.2
* (repeated below). */ * (repeated below). */
@ -1369,12 +1362,12 @@ find_tags (
#endif #endif
search_info.curr_offset = search_info.low_offset; search_info.curr_offset = search_info.low_offset;
} }
eof = tag_fgets(lbuf, LSIZE, fp); eof = vim_fgets(lbuf, LSIZE, fp);
} }
/* skip empty and blank lines */ /* skip empty and blank lines */
while (!eof && vim_isblankline(lbuf)) { while (!eof && vim_isblankline(lbuf)) {
search_info.curr_offset = ftell(fp); search_info.curr_offset = ftell(fp);
eof = tag_fgets(lbuf, LSIZE, fp); eof = vim_fgets(lbuf, LSIZE, fp);
} }
if (eof) { if (eof) {
/* Hit end of file. Skip backwards. */ /* Hit end of file. Skip backwards. */
@ -1393,7 +1386,7 @@ find_tags (
if (use_cscope) if (use_cscope)
eof = cs_fgets(lbuf, LSIZE); eof = cs_fgets(lbuf, LSIZE);
else else
eof = tag_fgets(lbuf, LSIZE, fp); eof = vim_fgets(lbuf, LSIZE, fp);
} while (!eof && vim_isblankline(lbuf)); } while (!eof && vim_isblankline(lbuf));
if (eof) { if (eof) {