mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-18 07:16:23 -05:00
Handle all types of eol when reading files.
This commit is contained in:
parent
319957e8e0
commit
30b1b06acb
21
file.c
21
file.c
@ -231,6 +231,7 @@ int readin(char *fname, int lockfl)
|
||||
struct window *wp;
|
||||
struct buffer *bp;
|
||||
int s;
|
||||
int eoltype ;
|
||||
int nbytes;
|
||||
int nline;
|
||||
char mesg[NSTRING];
|
||||
@ -294,6 +295,7 @@ int readin(char *fname, int lockfl)
|
||||
lputc(lp1, i, fline[i]);
|
||||
++nline;
|
||||
}
|
||||
eoltype = ftype ;
|
||||
ffclose(); /* Ignore errors. */
|
||||
strcpy(mesg, "(");
|
||||
if (s == FIOERR) {
|
||||
@ -307,6 +309,25 @@ int readin(char *fname, int lockfl)
|
||||
sprintf(&mesg[strlen(mesg)], "Read %d line", nline);
|
||||
if (nline != 1)
|
||||
strcat(mesg, "s");
|
||||
|
||||
strcat( mesg, ", eol = ") ;
|
||||
switch( eoltype) {
|
||||
case FTYPE_DOS:
|
||||
strcat( mesg, "DOS") ;
|
||||
break ;
|
||||
case FTYPE_UNIX:
|
||||
strcat( mesg, "UNIX") ;
|
||||
break ;
|
||||
case FTYPE_MAC:
|
||||
strcat( mesg, "MAC") ;
|
||||
break ;
|
||||
case FTYPE_NONE:
|
||||
strcat( mesg, "NONE") ;
|
||||
break ;
|
||||
default:
|
||||
strcat( mesg, "MIXED") ;
|
||||
}
|
||||
|
||||
strcat(mesg, ")");
|
||||
mlwrite(mesg);
|
||||
|
||||
|
25
fileio.c
25
fileio.c
@ -19,14 +19,17 @@
|
||||
static FILE *ffp; /* File pointer, all functions. */
|
||||
static int eofflag; /* end-of-file flag */
|
||||
|
||||
int ftype ;
|
||||
|
||||
/*
|
||||
* Open a file for reading.
|
||||
*/
|
||||
int ffropen( const char *fn)
|
||||
{
|
||||
if ((ffp = fopen(fn, "rt")) == NULL)
|
||||
if ((ffp = fopen(fn, "r")) == NULL)
|
||||
return FIOFNF;
|
||||
eofflag = FALSE;
|
||||
ftype = FTYPE_NONE ;
|
||||
return FIOSUC;
|
||||
}
|
||||
|
||||
@ -61,6 +64,7 @@ int ffclose(void)
|
||||
fline = NULL;
|
||||
}
|
||||
eofflag = FALSE;
|
||||
ftype = FTYPE_NONE ;
|
||||
|
||||
#if MSDOS & CTRLZ
|
||||
fputc(26, ffp); /* add a ^Z at the end of the file */
|
||||
@ -103,6 +107,7 @@ int ffputline(char *buf, int nbuf)
|
||||
fputc(buf[i] & 0xFF, ffp);
|
||||
#endif
|
||||
|
||||
fputc( '\r', ffp) ;
|
||||
fputc('\n', ffp);
|
||||
|
||||
if (ferror(ffp)) {
|
||||
@ -141,7 +146,7 @@ int ffgetline(void)
|
||||
return FIOMEM;
|
||||
|
||||
/* read the line in */
|
||||
#if PKCODE
|
||||
#if 0 /* PKCODE */
|
||||
if (!nullflag) {
|
||||
if (fgets(fline, NSTRING, ffp) == (char *) NULL) { /* EOF ? */
|
||||
i = 0;
|
||||
@ -161,9 +166,9 @@ int ffgetline(void)
|
||||
while (c != EOF && c != '\n') {
|
||||
#else
|
||||
i = 0;
|
||||
while ((c = fgetc(ffp)) != EOF && c != '\n') {
|
||||
while ((c = fgetc(ffp)) != EOF && c != '\r' && c != '\n') {
|
||||
#endif
|
||||
#if PKCODE
|
||||
#if 0 /* PKCODE */
|
||||
if (c) {
|
||||
#endif
|
||||
fline[i++] = c;
|
||||
@ -177,7 +182,7 @@ int ffgetline(void)
|
||||
free(fline);
|
||||
fline = tmpline;
|
||||
}
|
||||
#if PKCODE
|
||||
#if 0 /* PKCODE */
|
||||
}
|
||||
c = fgetc(ffp);
|
||||
#endif
|
||||
@ -194,7 +199,15 @@ int ffgetline(void)
|
||||
eofflag = TRUE;
|
||||
else
|
||||
return FIOEOF;
|
||||
}
|
||||
} else if( c == '\r') {
|
||||
c = fgetc( ffp) ;
|
||||
if( c != '\n') {
|
||||
ftype |= FTYPE_MAC ;
|
||||
ungetc( c, ffp) ;
|
||||
} else
|
||||
ftype |= FTYPE_DOS ;
|
||||
} else /* c == '\n' */
|
||||
ftype |= FTYPE_UNIX ;
|
||||
|
||||
/* terminate and decrypt the string */
|
||||
fline[i] = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user