From d60640af0f2e4323e001e0eaf7fae6d993c54324 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Sat, 30 Nov 2024 16:32:16 +0800 Subject: [PATCH] Quick Mac Hack: add Mac mode for CR only EOL. --- buffer.c | 20 ++++++++++---------- buffer.h | 3 ++- file.c | 3 ++- fileio.c | 7 ++++--- fileio.h | 2 +- line.c | 2 +- random.c | 11 +++++++++-- 7 files changed, 29 insertions(+), 19 deletions(-) diff --git a/buffer.c b/buffer.c index 8810ce8..01b1503 100644 --- a/buffer.c +++ b/buffer.c @@ -28,7 +28,7 @@ buffer_p blistp ; /* Buffer for C-X C-B */ const char *modename[ NUMMODES] = { /* name of modes */ "Wrap", "Cmode", "Exact", "View", "Over", "Magic", - "Asave", "Utf-8", "Dos" + "Asave", "Utf-8", "Dos", "Mac" } ; int gmode = 0 ; /* global editor mode */ @@ -293,9 +293,9 @@ BINDABLE( listbuffers) { int iflag; list hidden buffer flag */ -/* Layout: "ACT MODES Size Buffer File" - AAA MMMMMMMMMSSSSSSSSSS BBBBBBBBBBBBBBB FFF... - FNAMSTART ---------------------------------------^ +/* Layout: "ACT MODES Size Buffer File" + AAA MMMMMMMMMMSSSSSSSSSS BBBBBBBBBBBBBBB FFF... + FNAMSTART ----------------------------------------^ */ #define FNAMSTART (3 + 1 + NUMMODES + 10 + 1 + (sizeof( bname_t) - 1) + 1) @@ -303,7 +303,7 @@ static void do_layout( char *line, int mode) { int i ; /* build line to report global mode settings */ - strcpy( line, " WCEVOMAUD Global Modes") ; + strcpy( line, " WCEVOmAUDM Global Modes") ; /* output the mode codes */ for( i = 0 ; i < NUMMODES ; i++) @@ -336,8 +336,8 @@ static int makelist( int iflag) { blistp->b_fname[ 0] = 0 ; /* in case of user override */ - if( addline("ACT MODES Size Buffer File") == FALSE - || addline("‾‾‾ ‾‾‾‾‾ ‾‾‾‾ ‾‾‾‾‾‾ ‾‾‾‾") == FALSE) + if( addline("ACT MODES Size Buffer File") == FALSE + || addline("‾‾‾ ‾‾‾‾‾ ‾‾‾‾ ‾‾‾‾‾‾ ‾‾‾‾") == FALSE) return FALSE ; /* report global mode settings */ @@ -369,7 +369,7 @@ static int makelist( int iflag) { long nbytes = 0L; /* Count bytes in buf. */ long nlines = 0 ; for( line_p lp = lforw( bp->b_linep) ; lp != bp->b_linep ; - lp = lforw( lp)) { + lp = lforw( lp)) { nbytes += (long) llength(lp) + 1L; nlines += 1 ; } @@ -377,8 +377,8 @@ static int makelist( int iflag) { if( bp->b_mode & MDDOS) nbytes += nlines ; - l_to_a( &line[ 13], 10 + 1, nbytes) ; /* "%10d" formatted numbers */ - cp1 = &line[ 23] ; + l_to_a( &line[ 14], 10 + 1, nbytes) ; /* "%10d" formatted numbers */ + cp1 = &line[ 24] ; *cp1++ = ' ' ; /* Display buffer name */ diff --git a/buffer.h b/buffer.h index 50b4329..4a7721e 100644 --- a/buffer.h +++ b/buffer.h @@ -44,7 +44,7 @@ extern buffer_p blistp ; /* Buffer for C-X C-B */ #define BFTRUNC 0x04 /* buffer was truncated when read */ /* mode flags */ -#define NUMMODES 9 /* # of defined modes */ +#define NUMMODES 10 /* # of defined modes */ #define MDWRAP 0x0001 /* word wrap */ #define MDCMOD 0x0002 /* C indentation and fence match */ @@ -55,6 +55,7 @@ extern buffer_p blistp ; /* Buffer for C-X C-B */ #define MDASAVE 0x0040 /* auto-save mode */ #define MDUTF8 0x0080 /* utf8 mode */ #define MDDOS 0x0100 /* CRLF eol mode */ +#define MDMAC 0x0200 /* CR eol mode */ extern const char *modename[ NUMMODES] ; /* text names of modes */ extern int gmode ; /* global editor mode */ diff --git a/file.c b/file.c index 4190591..dbf7374 100644 --- a/file.c +++ b/file.c @@ -310,6 +310,7 @@ int readin( const char *fname, boolean lockfl) { break ; case FTYPE_MAC: found_eol = EOL_MAC ; + curbp->b_mode |= MDMAC ; break ; case FTYPE_NONE: found_eol = EOL_NONE ; @@ -474,7 +475,7 @@ int writeout( const char *fn) { mloutstr( "(Writing...)") ; /* tell us we are writing */ for( lp = lforw( curbp->b_linep) ; lp != curbp->b_linep ; lp = lforw( lp)) { - s = ffputline( lp->l_text, llength( lp), curbp->b_mode & MDDOS) ; + s = ffputline( lp->l_text, llength( lp), curbp->b_mode >> 8) ; // Mack Hack if( s != FIOSUC) break ; diff --git a/fileio.c b/fileio.c index c255d7f..3e5fe32 100644 --- a/fileio.c +++ b/fileio.c @@ -66,13 +66,14 @@ fio_code ffclose( void) { buffer, and the "nbuf" is its length, less the free newline. Return the status. Check only at the newline. */ -fio_code ffputline( char *buf, int nbuf, int dosflag) { +fio_code ffputline( char *buf, int nbuf, int eolflag) { fwrite( buf, 1, nbuf, ffp) ; - if( dosflag) + if( eolflag) // DOS and Mac fputc( '\r', ffp) ; - fputc( '\n', ffp) ; + if( eolflag != 2) // Not Mac + fputc( '\n', ffp) ; if( ferror( ffp)) return FIOERR ; diff --git a/fileio.h b/fileio.h index c8caf57..5166282 100644 --- a/fileio.h +++ b/fileio.h @@ -28,7 +28,7 @@ extern int fpayload ; /* actual length of fline content */ fio_code ffclose( void) ; fio_code ffgetline( void) ; -fio_code ffputline( char *buf, int nbuf, int dosflag) ; +fio_code ffputline( char *buf, int nbuf, int eolflag) ; fio_code ffropen( const char *fn) ; fio_code ffwopen( const char *fn) ; diff --git a/line.c b/line.c index 797f596..8a58b92 100644 --- a/line.c +++ b/line.c @@ -517,7 +517,7 @@ boolean lnewline( void) { */ int lgetchar( unicode_t *cp) { if( curwp->w_dotp->l_used == curwp->w_doto) { /* at EOL? */ - *cp = (curbp->b_mode & MDDOS) ? '\r' : '\n' ; + *cp = (curbp->b_mode & (MDDOS | MDMAC)) ? '\r' : '\n' ; return 1 ; } else return utf8_to_unicode( curwp->w_dotp->l_text, curwp->w_doto, diff --git a/random.c b/random.c index 28ddfc3..7be35e5 100644 --- a/random.c +++ b/random.c @@ -814,10 +814,17 @@ static int adjustmode( int kind, int global) { if( strcasecmp( cbuf, modename[ i]) == 0) { /* finding a match, we process it */ if (kind == TRUE) - if (global) + if (global) { + if( i > 7) // Mac Hack + gmode &= 0xFF ; + gmode |= (1 << i); - else + } else { + if( i > 7) //Mac Hack + curbp->b_mode &= 0xFF ; + curbp->b_mode |= (1 << i); + } else if (global) gmode &= ~(1 << i); else