remove the DOS_FILE and MAC_FILE flags, as they're only used in files.c,
and replace them with a static file_format enum; change the openfilestruct structure accordingly in order to handle this; also add a few miscellaneous cleanups git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2054 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
84d0d59cbb
commit
3e0c8a614d
|
@ -108,7 +108,15 @@ CVS code -
|
||||||
- Remove most redundant includes of sys/stat.h. It's included
|
- Remove most redundant includes of sys/stat.h. It's included
|
||||||
in nano.h, so it doesn't need to be included in files that
|
in nano.h, so it doesn't need to be included in files that
|
||||||
include nano.h. (DLR)
|
include nano.h. (DLR)
|
||||||
|
- Remove the DOS_FILE and MAC_FILE flags, as they're only used
|
||||||
|
in files.c, and replace them with a static file_format enum.
|
||||||
|
Change the openfilestruct structure accordingly in order to
|
||||||
|
handle this. Also move the PATH_MAX definition to nano.h.
|
||||||
|
(DLR)
|
||||||
- files.c:
|
- files.c:
|
||||||
|
read_file()
|
||||||
|
- Rename variable fileformat to format, to avoid confusion with
|
||||||
|
the file_format enum type. (DLR)
|
||||||
do_insertfile()
|
do_insertfile()
|
||||||
- Simplify by reusing variables whereever possible, and add a
|
- Simplify by reusing variables whereever possible, and add a
|
||||||
parameter execute to indicate whether or not to be in "Execute
|
parameter execute to indicate whether or not to be in "Execute
|
||||||
|
@ -209,6 +217,7 @@ CVS code -
|
||||||
- nano.h:
|
- nano.h:
|
||||||
- Add WIDTH_OF_TAB #define, containing the default width of a
|
- Add WIDTH_OF_TAB #define, containing the default width of a
|
||||||
tab. (DLR)
|
tab. (DLR)
|
||||||
|
- Remove unused COPYFILEBLOCKSIZE #define. (DLR)
|
||||||
- rcfile.c:
|
- rcfile.c:
|
||||||
parse_rcfile()
|
parse_rcfile()
|
||||||
- Add missing brackets around an if statement block so that
|
- Add missing brackets around an if statement block so that
|
||||||
|
|
78
src/files.c
78
src/files.c
|
@ -36,11 +36,8 @@
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "nano.h"
|
#include "nano.h"
|
||||||
|
|
||||||
/* Set a default value for PATH_MAX, so we can use it below in lines
|
static file_format fmt = NIX_FILE;
|
||||||
* like "path = getcwd(NULL, PATH_MAX + 1);". */
|
/* The format of the current file. */
|
||||||
#ifndef PATH_MAX
|
|
||||||
#define PATH_MAX -1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* What happens when there is no file to open? aiee! */
|
/* What happens when there is no file to open? aiee! */
|
||||||
void new_file(void)
|
void new_file(void)
|
||||||
|
@ -151,7 +148,7 @@ void read_file(FILE *f, const char *filename)
|
||||||
/* The current value we read from the file, whether an input
|
/* The current value we read from the file, whether an input
|
||||||
* character or EOF. */
|
* character or EOF. */
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
int fileformat = 0;
|
int format = 0;
|
||||||
/* 0 = *nix, 1 = DOS, 2 = Mac, 3 = both DOS and Mac. */
|
/* 0 = *nix, 1 = DOS, 2 = Mac, 3 = both DOS and Mac. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -170,10 +167,9 @@ void read_file(FILE *f, const char *filename)
|
||||||
assert(current != NULL || fileage == NULL);
|
assert(current != NULL || fileage == NULL);
|
||||||
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
/* Clear the DOS and Mac file format flags, since we don't know
|
/* We don't know which file format we have yet, so assume it's a
|
||||||
* which file format we have yet. */
|
* *nix file for now. */
|
||||||
UNSET(DOS_FILE);
|
fmt = NIX_FILE;
|
||||||
UNSET(MAC_FILE);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Read the entire file into the file struct. */
|
/* Read the entire file into the file struct. */
|
||||||
|
@ -185,12 +181,12 @@ void read_file(FILE *f, const char *filename)
|
||||||
if (input == '\n') {
|
if (input == '\n') {
|
||||||
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
/* If there's a CR before the LF, set fileformat to DOS if
|
/* If there's a CR before the LF, set format to DOS if we
|
||||||
* we currently think this is a *nix file, or to both if we
|
* currently think this is a *nix file, or to both if we
|
||||||
* currently think it's a Mac file. */
|
* currently think it's a Mac file. */
|
||||||
if (!ISSET(NO_CONVERT) && i > 0 && buf[i - 1] == '\r' &&
|
if (!ISSET(NO_CONVERT) && i > 0 && buf[i - 1] == '\r' &&
|
||||||
(fileformat == 0 || fileformat == 2))
|
(format == 0 || format == 2))
|
||||||
fileformat++;
|
format++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Read in the line properly. */
|
/* Read in the line properly. */
|
||||||
|
@ -208,11 +204,11 @@ void read_file(FILE *f, const char *filename)
|
||||||
* isn't disabled, handle it! */
|
* isn't disabled, handle it! */
|
||||||
} else if (!ISSET(NO_CONVERT) && i > 0 && buf[i - 1] == '\r') {
|
} else if (!ISSET(NO_CONVERT) && i > 0 && buf[i - 1] == '\r') {
|
||||||
|
|
||||||
/* If we currently think the file is a *nix file, set
|
/* If we currently think the file is a *nix file, set format
|
||||||
* fileformat to Mac. If we currently think the file is a
|
* to Mac. If we currently think the file is a DOS file,
|
||||||
* DOS file, set fileformat to both DOS and Mac. */
|
* set format to both DOS and Mac. */
|
||||||
if (fileformat == 0 || fileformat == 1)
|
if (format == 0 || format == 1)
|
||||||
fileformat += 2;
|
format += 2;
|
||||||
|
|
||||||
/* Read in the line properly. */
|
/* Read in the line properly. */
|
||||||
fileptr = read_line(buf, fileptr, &first_line_ins, len);
|
fileptr = read_line(buf, fileptr, &first_line_ins, len);
|
||||||
|
@ -268,12 +264,12 @@ void read_file(FILE *f, const char *filename)
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
/* If file conversion isn't disabled and the last character in
|
/* If file conversion isn't disabled and the last character in
|
||||||
* this file is a CR, set fileformat to Mac if we currently
|
* this file is a CR, set format to Mac if we currently think
|
||||||
* think the file is a *nix file, or to both DOS and Mac if we
|
* the file is a *nix file, or to both DOS and Mac if we
|
||||||
* currently think the file is a DOS file. */
|
* currently think the file is a DOS file. */
|
||||||
if (!ISSET(NO_CONVERT) && buf[len - 1] == '\r' &&
|
if (!ISSET(NO_CONVERT) && buf[len - 1] == '\r' &&
|
||||||
(fileformat == 0 || fileformat == 1))
|
(format == 0 || format == 1))
|
||||||
fileformat += 2;
|
format += 2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Read in the last line properly. */
|
/* Read in the last line properly. */
|
||||||
|
@ -304,18 +300,18 @@ void read_file(FILE *f, const char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
if (fileformat == 3)
|
if (format == 3)
|
||||||
statusbar(
|
statusbar(
|
||||||
P_("Read %lu line (Converted from DOS and Mac format)",
|
P_("Read %lu line (Converted from DOS and Mac format)",
|
||||||
"Read %lu lines (Converted from DOS and Mac format)",
|
"Read %lu lines (Converted from DOS and Mac format)",
|
||||||
(unsigned long)num_lines), (unsigned long)num_lines);
|
(unsigned long)num_lines), (unsigned long)num_lines);
|
||||||
else if (fileformat == 2) {
|
else if (format == 2) {
|
||||||
SET(MAC_FILE);
|
fmt = MAC_FILE;
|
||||||
statusbar(P_("Read %lu line (Converted from Mac format)",
|
statusbar(P_("Read %lu line (Converted from Mac format)",
|
||||||
"Read %lu lines (Converted from Mac format)",
|
"Read %lu lines (Converted from Mac format)",
|
||||||
(unsigned long)num_lines), (unsigned long)num_lines);
|
(unsigned long)num_lines), (unsigned long)num_lines);
|
||||||
} else if (fileformat == 1) {
|
} else if (format == 1) {
|
||||||
SET(DOS_FILE);
|
fmt = DOS_FILE;
|
||||||
statusbar(P_("Read %lu line (Converted from DOS format)",
|
statusbar(P_("Read %lu line (Converted from DOS format)",
|
||||||
"Read %lu lines (Converted from DOS format)",
|
"Read %lu lines (Converted from DOS format)",
|
||||||
(unsigned long)num_lines), (unsigned long)num_lines);
|
(unsigned long)num_lines), (unsigned long)num_lines);
|
||||||
|
@ -772,10 +768,7 @@ void add_open_file(bool update)
|
||||||
open_files->file_mark_beginx = mark_beginx;
|
open_files->file_mark_beginx = mark_beginx;
|
||||||
open_files->file_flags |= MARK_ISSET;
|
open_files->file_flags |= MARK_ISSET;
|
||||||
}
|
}
|
||||||
if (ISSET(DOS_FILE))
|
open_files->file_fmt = fmt;
|
||||||
open_files->file_flags |= DOS_FILE;
|
|
||||||
else if (ISSET(MAC_FILE))
|
|
||||||
open_files->file_flags |= MAC_FILE;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -829,12 +822,7 @@ void load_open_file(void)
|
||||||
UNSET(MARK_ISSET);
|
UNSET(MARK_ISSET);
|
||||||
|
|
||||||
/* restore file format status */
|
/* restore file format status */
|
||||||
UNSET(DOS_FILE);
|
fmt = open_files->file_fmt;
|
||||||
UNSET(MAC_FILE);
|
|
||||||
if (open_files->file_flags & DOS_FILE)
|
|
||||||
SET(DOS_FILE);
|
|
||||||
else if (open_files->file_flags & MAC_FILE)
|
|
||||||
SET(MAC_FILE);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
|
@ -1635,14 +1623,14 @@ int write_file(const char *name, int tmp, int append, int nonamechange)
|
||||||
goto cleanup_and_exit;
|
goto cleanup_and_exit;
|
||||||
}
|
}
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
if (ISSET(DOS_FILE) || ISSET(MAC_FILE))
|
if (fmt == DOS_FILE || fmt == MAC_FILE)
|
||||||
if (putc('\r', f) == EOF) {
|
if (putc('\r', f) == EOF) {
|
||||||
statusbar(_("Error writing %s: %s"), realname, strerror(errno));
|
statusbar(_("Error writing %s: %s"), realname, strerror(errno));
|
||||||
fclose(f);
|
fclose(f);
|
||||||
goto cleanup_and_exit;
|
goto cleanup_and_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ISSET(MAC_FILE))
|
if (fmt != MAC_FILE)
|
||||||
#endif
|
#endif
|
||||||
if (putc('\n', f) == EOF) {
|
if (putc('\n', f) == EOF) {
|
||||||
statusbar(_("Error writing %s: %s"), realname, strerror(errno));
|
statusbar(_("Error writing %s: %s"), realname, strerror(errno));
|
||||||
|
@ -1790,9 +1778,9 @@ int do_writeout(bool exiting)
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
const char *formatstr, *backupstr;
|
const char *formatstr, *backupstr;
|
||||||
|
|
||||||
if (ISSET(DOS_FILE))
|
if (fmt == DOS_FILE)
|
||||||
formatstr = N_(" [DOS Format]");
|
formatstr = N_(" [DOS Format]");
|
||||||
else if (ISSET(MAC_FILE))
|
else if (fmt == MAC_FILE)
|
||||||
formatstr = N_(" [Mac Format]");
|
formatstr = N_(" [Mac Format]");
|
||||||
else
|
else
|
||||||
formatstr = "";
|
formatstr = "";
|
||||||
|
@ -1856,12 +1844,10 @@ int do_writeout(bool exiting)
|
||||||
#endif /* !DISABLE_BROWSER */
|
#endif /* !DISABLE_BROWSER */
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
if (i == TOGGLE_DOS_KEY) {
|
if (i == TOGGLE_DOS_KEY) {
|
||||||
UNSET(MAC_FILE);
|
fmt = (fmt == DOS_FILE) ? NIX_FILE : DOS_FILE;
|
||||||
TOGGLE(DOS_FILE);
|
|
||||||
continue;
|
continue;
|
||||||
} else if (i == TOGGLE_MAC_KEY) {
|
} else if (i == TOGGLE_MAC_KEY) {
|
||||||
UNSET(DOS_FILE);
|
fmt = (fmt == MAC_FILE) ? NIX_FILE : MAC_FILE;
|
||||||
TOGGLE(MAC_FILE);
|
|
||||||
continue;
|
continue;
|
||||||
} else if (i == TOGGLE_BACKUP_KEY) {
|
} else if (i == TOGGLE_BACKUP_KEY) {
|
||||||
TOGGLE(BACKUP_FILE);
|
TOGGLE(BACKUP_FILE);
|
||||||
|
|
71
src/nano.h
71
src/nano.h
|
@ -49,9 +49,10 @@
|
||||||
#define regexec(preg, string, nmatch, pmatch, eflags) regexec_safe(preg, string, nmatch, pmatch, eflags)
|
#define regexec(preg, string, nmatch, pmatch, eflags) regexec_safe(preg, string, nmatch, pmatch, eflags)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NANO_SMALL
|
/* Set a default value for PATH_MAX, so we can use it in lines like
|
||||||
/* For the backup file copy. */
|
* "path = getcwd(NULL, PATH_MAX + 1);". */
|
||||||
#define COPYFILEBLOCKSIZE 1024
|
#ifndef PATH_MAX
|
||||||
|
#define PATH_MAX -1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SLANG
|
#ifdef USE_SLANG
|
||||||
|
@ -143,6 +144,23 @@
|
||||||
#define DISABLE_WRAPJUSTIFY 1
|
#define DISABLE_WRAPJUSTIFY 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Enumeration types. */
|
||||||
|
typedef enum {
|
||||||
|
NIX_FILE, DOS_FILE, MAC_FILE
|
||||||
|
} file_format;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
UP, DOWN
|
||||||
|
} updown;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TOP, CENTER, NONE
|
||||||
|
} topmidnone;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NO_SEQ, ESCAPE_SEQ, UTF8_SEQ
|
||||||
|
} seq_type;
|
||||||
|
|
||||||
/* Structure types. */
|
/* Structure types. */
|
||||||
typedef struct filestruct {
|
typedef struct filestruct {
|
||||||
char *data;
|
char *data;
|
||||||
|
@ -172,14 +190,15 @@ typedef struct openfilestruct {
|
||||||
* position. */
|
* position. */
|
||||||
int file_current_y; /* Current file's y-coordinate
|
int file_current_y; /* Current file's y-coordinate
|
||||||
* position. */
|
* position. */
|
||||||
long file_flags; /* Current file's flags: modification
|
|
||||||
* status (and marking status, if
|
|
||||||
* available). */
|
|
||||||
size_t file_placewewant; /* Current file's place we want. */
|
size_t file_placewewant; /* Current file's place we want. */
|
||||||
int file_totlines; /* Current file's total number of
|
int file_totlines; /* Current file's total number of
|
||||||
* lines. */
|
* lines. */
|
||||||
long file_totsize; /* Current file's total size. */
|
long file_totsize; /* Current file's total size. */
|
||||||
int file_lineno; /* Current file's line number. */
|
int file_lineno; /* Current file's line number. */
|
||||||
|
long file_flags; /* Current file's flags: modification
|
||||||
|
* status (and marking status, if
|
||||||
|
* available). */
|
||||||
|
file_format file_fmt; /* Current file's format. */
|
||||||
} openfilestruct;
|
} openfilestruct;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -290,21 +309,19 @@ typedef struct historyheadtype {
|
||||||
#define CUT_TO_END (1<<13)
|
#define CUT_TO_END (1<<13)
|
||||||
#define REVERSE_SEARCH (1<<14)
|
#define REVERSE_SEARCH (1<<14)
|
||||||
#define MULTIBUFFER (1<<15)
|
#define MULTIBUFFER (1<<15)
|
||||||
#define DOS_FILE (1<<16)
|
#define SMOOTHSCROLL (1<<16)
|
||||||
#define MAC_FILE (1<<17)
|
#define DISABLE_CURPOS (1<<17) /* Damn, we still need it. */
|
||||||
#define SMOOTHSCROLL (1<<18)
|
#define REBIND_DELETE (1<<18)
|
||||||
#define DISABLE_CURPOS (1<<19) /* Damn, we still need it. */
|
#define NO_CONVERT (1<<19)
|
||||||
#define REBIND_DELETE (1<<20)
|
#define BACKUP_FILE (1<<20)
|
||||||
#define NO_CONVERT (1<<21)
|
#define NO_RCFILE (1<<21)
|
||||||
#define BACKUP_FILE (1<<22)
|
#define COLOR_SYNTAX (1<<22)
|
||||||
#define NO_RCFILE (1<<23)
|
#define PRESERVE (1<<23)
|
||||||
#define COLOR_SYNTAX (1<<24)
|
#define HISTORY_CHANGED (1<<24)
|
||||||
#define PRESERVE (1<<25)
|
#define HISTORYLOG (1<<25)
|
||||||
#define HISTORY_CHANGED (1<<26)
|
#define RESTRICTED (1<<26)
|
||||||
#define HISTORYLOG (1<<27)
|
#define SMART_HOME (1<<27)
|
||||||
#define RESTRICTED (1<<28)
|
#define WHITESPACE_DISPLAY (1<<28)
|
||||||
#define SMART_HOME (1<<29)
|
|
||||||
#define WHITESPACE_DISPLAY (1<<30)
|
|
||||||
|
|
||||||
/* Control key sequences, changing these would be very very bad. */
|
/* Control key sequences, changing these would be very very bad. */
|
||||||
#define NANO_CONTROL_SPACE 0
|
#define NANO_CONTROL_SPACE 0
|
||||||
|
@ -496,18 +513,6 @@ typedef struct historyheadtype {
|
||||||
#define VIEW TRUE
|
#define VIEW TRUE
|
||||||
#define NOVIEW FALSE
|
#define NOVIEW FALSE
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
UP, DOWN
|
|
||||||
} updown;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
TOP, CENTER, NONE
|
|
||||||
} topmidnone;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
NO_SEQ, ESCAPE_SEQ, UTF8_SEQ
|
|
||||||
} seq_type;
|
|
||||||
|
|
||||||
/* Minimum editor window rows required for nano to work correctly. */
|
/* Minimum editor window rows required for nano to work correctly. */
|
||||||
#define MIN_EDITOR_ROWS 3
|
#define MIN_EDITOR_ROWS 3
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue