Skip to content

Commit

Permalink
Quick Mac Hack: add Mac mode for CR only EOL.
Browse files Browse the repository at this point in the history
  • Loading branch information
rfivet committed Nov 30, 2024
1 parent 22e26fc commit d60640a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
20 changes: 10 additions & 10 deletions buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -293,17 +293,17 @@ 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)

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++)
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -369,16 +369,16 @@ 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 ;
}

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 */
Expand Down
3 changes: 2 additions & 1 deletion buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down Expand Up @@ -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 ;

Expand Down
7 changes: 4 additions & 3 deletions fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down
2 changes: 1 addition & 1 deletion fileio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) ;

Expand Down
2 changes: 1 addition & 1 deletion line.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions random.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d60640a

Please sign in to comment.