Commit 38e8ed14 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

Normalizing the whitespace and some comments in src/files.c.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5270 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 74 additions and 78 deletions
+74 -78
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
a temporary file as parameter, so forget the case of an empty filename. a temporary file as parameter, so forget the case of an empty filename.
Also, don't bother putting the pointer at the top of the buffer, as the Also, don't bother putting the pointer at the top of the buffer, as the
first action after this function is to restore the cursor position. first action after this function is to restore the cursor position.
* src/files.c: Normalize the whitespace and some comments.
2015-06-23 Benno Schulenberg <bensberg@justemail.net> 2015-06-23 Benno Schulenberg <bensberg@justemail.net>
* src/winio.c (edit_draw): Verify that there exists multidata for the * src/winio.c (edit_draw): Verify that there exists multidata for the
......
...@@ -136,14 +136,14 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi ...@@ -136,14 +136,14 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
* old state. */ * old state. */
myuid = geteuid(); myuid = geteuid();
if ((mypwuid = getpwuid(myuid)) == NULL) { if ((mypwuid = getpwuid(myuid)) == NULL) {
statusbar(_("Couldn't determine my identity for lock file (getpwuid() failed)")); statusbar(_("Couldn't determine my identity for lock file (getpwuid() failed)"));
return -1; return -1;
} }
mypid = getpid(); mypid = getpid();
if (gethostname(myhostname, 31) < 0) { if (gethostname(myhostname, 31) < 0) {
statusbar(_("Couldn't determine hostname for lock file: %s"), strerror(errno)); statusbar(_("Couldn't determine hostname for lock file: %s"), strerror(errno));
return -1; return -1;
} }
/* Check if the lock exists before we try to delete it...*/ /* Check if the lock exists before we try to delete it...*/
...@@ -152,19 +152,19 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi ...@@ -152,19 +152,19 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
return -1; return -1;
if (ISSET(INSECURE_BACKUP)) if (ISSET(INSECURE_BACKUP))
cflags = O_WRONLY | O_CREAT | O_APPEND; cflags = O_WRONLY | O_CREAT | O_APPEND;
else else
cflags = O_WRONLY | O_CREAT | O_EXCL | O_APPEND; cflags = O_WRONLY | O_CREAT | O_EXCL | O_APPEND;
fd = open(lockfilename, cflags, fd = open(lockfilename, cflags,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
/* Maybe we just don't have write access. Print an error message /* Maybe we just don't have write access. Print an error message
and continue. */ * and continue. */
if (fd < 0) { if (fd < 0) {
statusbar(_("Error writing lock file %s: %s"), lockfilename, statusbar(_("Error writing lock file %s: %s"), lockfilename,
strerror(errno)); strerror(errno));
return 0; return 0;
} }
/* Now we've got a safe file stream. If the previous open() call /* Now we've got a safe file stream. If the previous open() call
...@@ -172,9 +172,9 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi ...@@ -172,9 +172,9 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
filestream = fdopen(fd, "wb"); filestream = fdopen(fd, "wb");
if (fd < 0 || filestream == NULL) { if (fd < 0 || filestream == NULL) {
statusbar(_("Error writing lock file %s: %s"), lockfilename, statusbar(_("Error writing lock file %s: %s"), lockfilename,
strerror(errno)); strerror(errno));
return -1; return -1;
} }
/* Okay, so at the moment we're following this state for how to /* Okay, so at the moment we're following this state for how to
...@@ -205,13 +205,13 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi ...@@ -205,13 +205,13 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
strncpy(&lockdata[68], myhostname, 31); strncpy(&lockdata[68], myhostname, 31);
strncpy(&lockdata[108], origfilename, 768); strncpy(&lockdata[108], origfilename, 768);
if (modified == TRUE) if (modified == TRUE)
lockdata[1007] = 0x55; lockdata[1007] = 0x55;
wroteamt = fwrite(lockdata, sizeof(char), lockdatalen, filestream); wroteamt = fwrite(lockdata, sizeof(char), lockdatalen, filestream);
if (wroteamt < lockdatalen) { if (wroteamt < lockdatalen) {
statusbar(_("Error writing lock file %s: %s"), statusbar(_("Error writing lock file %s: %s"),
lockfilename, ferror(filestream)); lockfilename, ferror(filestream));
return -1; return -1;
} }
#ifdef DEBUG #ifdef DEBUG
...@@ -219,9 +219,9 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi ...@@ -219,9 +219,9 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
#endif #endif
if (fclose(filestream) == EOF) { if (fclose(filestream) == EOF) {
statusbar(_("Error writing lock file %s: %s"), statusbar(_("Error writing lock file %s: %s"),
lockfilename, strerror(errno)); lockfilename, strerror(errno));
return -1; return -1;
} }
openfile->lock_filename = lockfilename; openfile->lock_filename = lockfilename;
...@@ -236,7 +236,7 @@ int delete_lockfile(const char *lockfilename) ...@@ -236,7 +236,7 @@ int delete_lockfile(const char *lockfilename)
if (unlink(lockfilename) < 0 && errno != ENOENT) { if (unlink(lockfilename) < 0 && errno != ENOENT) {
statusbar(_("Error deleting lock file %s: %s"), lockfilename, statusbar(_("Error deleting lock file %s: %s"), lockfilename,
strerror(errno)); strerror(errno));
return -1; return -1;
} }
return 1; return 1;
} }
...@@ -258,49 +258,47 @@ int do_lockfile(const char *filename) ...@@ -258,49 +258,47 @@ int do_lockfile(const char *filename)
int lockfd, lockpid; int lockfd, lockpid;
snprintf(lockfilename, lockfilesize, "%s/%s%s%s", lockdir, snprintf(lockfilename, lockfilesize, "%s/%s%s%s", lockdir,
locking_prefix, lockbase, locking_suffix); locking_prefix, lockbase, locking_suffix);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "lock file name is %s\n", lockfilename); fprintf(stderr, "lock file name is %s\n", lockfilename);
#endif #endif
if (stat(lockfilename, &fileinfo) != -1) { if (stat(lockfilename, &fileinfo) != -1) {
ssize_t readtot = 0; ssize_t readtot = 0;
ssize_t readamt = 0; ssize_t readamt = 0;
char *lockbuf = charalloc(8192); char *lockbuf = charalloc(8192);
char *promptstr = charalloc(128); char *promptstr = charalloc(128);
int ans; int ans;
if ((lockfd = open(lockfilename, O_RDONLY)) < 0) { if ((lockfd = open(lockfilename, O_RDONLY)) < 0) {
statusbar(_("Error opening lock file %s: %s"), statusbar(_("Error opening lock file %s: %s"),
lockfilename, strerror(errno)); lockfilename, strerror(errno));
return -1; return -1;
} }
do { do {
readamt = read(lockfd, &lockbuf[readtot], BUFSIZ); readamt = read(lockfd, &lockbuf[readtot], BUFSIZ);
readtot += readamt; readtot += readamt;
} while (readtot < 8192 && readamt > 0); } while (readtot < 8192 && readamt > 0);
if (readtot < 48) { if (readtot < 48) {
statusbar(_("Error reading lock file %s: Not enough data read"), statusbar(_("Error reading lock file %s: Not enough data read"),
lockfilename); lockfilename);
return -1; return -1;
} }
strncpy(lockprog, &lockbuf[2], 10); strncpy(lockprog, &lockbuf[2], 10);
lockpid = (unsigned char)lockbuf[25] * 256 + (unsigned char)lockbuf[24]; lockpid = (unsigned char)lockbuf[25] * 256 + (unsigned char)lockbuf[24];
strncpy(lockuser, &lockbuf[28], 16); strncpy(lockuser, &lockbuf[28], 16);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "lockpid = %d\n", lockpid); fprintf(stderr, "lockpid = %d\n", lockpid);
fprintf(stderr, "program name which created this lock file should be %s\n", fprintf(stderr, "program name which created this lock file should be %s\n", lockprog);
lockprog); fprintf(stderr, "user which created this lock file should be %s\n", lockuser);
fprintf(stderr, "user which created this lock file should be %s\n",
lockuser);
#endif #endif
/* TRANSLATORS: The second %s is the name of the user, the third that of the editor. */ /* TRANSLATORS: The second %s is the name of the user, the third that of the editor. */
sprintf(promptstr, _("File %s is being edited (by %s with %s, PID %d); continue?"), sprintf(promptstr, _("File %s is being edited (by %s with %s, PID %d); continue?"),
filename, lockuser, lockprog, lockpid); filename, lockuser, lockprog, lockpid);
ans = do_yesno_prompt(FALSE, promptstr); ans = do_yesno_prompt(FALSE, promptstr);
if (ans < 1) { if (ans < 1) {
blank_statusbar(); blank_statusbar();
return -1; return -1;
} }
} else { } else {
lockfiledir = mallocstrcpy(NULL, lockfilename); lockfiledir = mallocstrcpy(NULL, lockfilename);
lockfiledir = dirname(lockfiledir); lockfiledir = dirname(lockfiledir);
...@@ -311,7 +309,6 @@ int do_lockfile(const char *filename) ...@@ -311,7 +309,6 @@ int do_lockfile(const char *filename)
} }
} }
return write_lockfile(lockfilename, filename, FALSE); return write_lockfile(lockfilename, filename, FALSE);
} }
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
...@@ -360,11 +357,10 @@ void open_buffer(const char *filename, bool undoable) ...@@ -360,11 +357,10 @@ void open_buffer(const char *filename, bool undoable)
} else if (lockstatus == 0) { } else if (lockstatus == 0) {
quiet = TRUE; quiet = TRUE;
} }
} }
#endif #endif
} }
/* If the filename isn't blank, and we are not in NOREAD_MODE, /* If the filename isn't blank, and we are not in NOREAD_MODE,
* open the file. Otherwise, treat it as a new file. */ * open the file. Otherwise, treat it as a new file. */
rc = (filename[0] != '\0' && !ISSET(NOREAD_MODE)) ? rc = (filename[0] != '\0' && !ISSET(NOREAD_MODE)) ?
...@@ -424,7 +420,6 @@ void replace_buffer(const char *filename) ...@@ -424,7 +420,6 @@ void replace_buffer(const char *filename)
/* If opening the file succeeded, read it in. */ /* If opening the file succeeded, read it in. */
if (descriptor > 0) if (descriptor > 0)
read_file(f, descriptor, filename, FALSE, TRUE); read_file(f, descriptor, filename, FALSE, TRUE);
} }
#endif /* !DISABLE_SPELLER */ #endif /* !DISABLE_SPELLER */
...@@ -473,8 +468,8 @@ void switch_to_prevnext_buffer(bool next_buf, bool quiet) ...@@ -473,8 +468,8 @@ void switch_to_prevnext_buffer(bool next_buf, bool quiet)
/* Indicate the switch on the statusbar. */ /* Indicate the switch on the statusbar. */
if (quiet == FALSE) if (quiet == FALSE)
statusbar(_("Switched to %s"), statusbar(_("Switched to %s"),
((openfile->filename[0] == '\0') ? _("New Buffer") : ((openfile->filename[0] == '\0') ?
openfile->filename)); _("New Buffer") : openfile->filename));
#ifdef DEBUG #ifdef DEBUG
dump_filestruct(openfile->current); dump_filestruct(openfile->current);
...@@ -512,7 +507,7 @@ bool close_buffer(bool quiet) ...@@ -512,7 +507,7 @@ bool close_buffer(bool quiet)
#endif #endif
/* Switch to the next file buffer. */ /* Switch to the next file buffer. */
switch_to_prevnext_buffer(TRUE, quiet); switch_to_prevnext_buffer(TRUE, quiet);
/* Close the file buffer we had open before. */ /* Close the file buffer we had open before. */
unlink_opennode(openfile->prev); unlink_opennode(openfile->prev);
...@@ -547,17 +542,17 @@ int is_file_writable(const char *filename) ...@@ -547,17 +542,17 @@ int is_file_writable(const char *filename)
full_filename = get_full_path(filename); full_filename = get_full_path(filename);
/* Okay, if we can't stat the path due to a component's /* Okay, if we can't stat the path due to a component's
permissions, just try the relative one. */ *permissions, just try the relative one. */
if (full_filename == NULL if (full_filename == NULL ||
|| (stat(full_filename, &fileinfo) == -1 && stat(filename, &fileinfo2) != -1)) (stat(full_filename, &fileinfo) == -1 && stat(filename, &fileinfo2) != -1))
full_filename = mallocstrcpy(NULL, filename); full_filename = mallocstrcpy(NULL, filename);
if ((fd = open(full_filename, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | if ((fd = open(full_filename, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR |
S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) == -1 S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) == -1 ||
|| (f = fdopen(fd, "a")) == NULL) (f = fdopen(fd, "a")) == NULL)
ans = FALSE; ans = FALSE;
else else
fclose(f); fclose(f);
close(fd); close(fd);
free(full_filename); free(full_filename);
...@@ -918,7 +913,7 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f) ...@@ -918,7 +913,7 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f)
full_filename = get_full_path(filename); full_filename = get_full_path(filename);
/* Okay, if we can't stat the path due to a component's /* Okay, if we can't stat the path due to a component's
permissions, just try the relative one. */ * permissions, just try the relative one. */
if (full_filename == NULL if (full_filename == NULL
|| (stat(full_filename, &fileinfo) == -1 && stat(filename, &fileinfo2) != -1)) || (stat(full_filename, &fileinfo) == -1 && stat(filename, &fileinfo2) != -1))
full_filename = mallocstrcpy(NULL, filename); full_filename = mallocstrcpy(NULL, filename);
...@@ -927,7 +922,7 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f) ...@@ -927,7 +922,7 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f)
if (stat(full_filename, &fileinfo) == -1) { if (stat(full_filename, &fileinfo) == -1) {
/* Well, maybe we can open the file even if the OS says it's /* Well, maybe we can open the file even if the OS says it's
* not there. */ * not there. */
if ((fd = open(filename, O_RDONLY)) != -1) { if ((fd = open(filename, O_RDONLY)) != -1) {
if (!quiet) if (!quiet)
statusbar(_("Reading File")); statusbar(_("Reading File"));
free(full_filename); free(full_filename);
...@@ -956,7 +951,7 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f) ...@@ -956,7 +951,7 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f)
strerror(errno)); strerror(errno));
beep(); beep();
return -1; return -1;
} else { } else {
/* The file is A-OK. Open it. */ /* The file is A-OK. Open it. */
*f = fdopen(fd, "rb"); *f = fdopen(fd, "rb");
...@@ -1599,11 +1594,11 @@ int prompt_failed_backupwrite(const char *filename) ...@@ -1599,11 +1594,11 @@ int prompt_failed_backupwrite(const char *filename)
{ {
static int i; static int i;
static char *prevfile = NULL; /* What was the last file we were static char *prevfile = NULL; /* What was the last file we were
* passed so we don't keep asking * passed so we don't keep asking
* this? Though maybe we should... */ * this? Though maybe we should... */
if (prevfile == NULL || strcmp(filename, prevfile)) { if (prevfile == NULL || strcmp(filename, prevfile)) {
i = do_yesno_prompt(FALSE, i = do_yesno_prompt(FALSE,
_("Failed to write backup file, continue saving? (Say N if unsure) ")); _("Failed to write backup file, continue saving? (Say N if unsure) "));
prevfile = mallocstrcpy(prevfile, filename); prevfile = mallocstrcpy(prevfile, filename);
} }
return i; return i;
...@@ -1896,9 +1891,9 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type ...@@ -1896,9 +1891,9 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
free(backupname); free(backupname);
fclose(backup_file); fclose(backup_file);
/* If we can't write to the backup, DONT go on, since /* If we can't write to the backup, DONT go on, since
whatever caused the backup file to fail (e.g. disk * whatever caused the backup file to fail (e.g. disk
full may well cause the real file write to fail, which * full may well cause the real file write to fail, which
means we could lose both the backup and the original! */ * means we could lose both the backup and the original! */
goto cleanup_and_exit; goto cleanup_and_exit;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment