1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-17 23:06:25 -05:00

Quick Mac Hack: add Mac mode for CR only EOL.

This commit is contained in:
Renaud 2024-11-30 16:32:16 +08:00
parent 22e26fc885
commit d60640af0f
7 changed files with 29 additions and 19 deletions

View File

@ -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 */

View File

@ -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 */

3
file.c
View File

@ -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 ;

View File

@ -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 ;

View File

@ -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) ;

2
line.c
View File

@ -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,

View File

@ -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