Commit 92b8d6fb authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

files: miscellaneous tweaks of braces, comments, and variable names

No related merge requests found
Showing with 29 additions and 42 deletions
+29 -42
...@@ -47,14 +47,12 @@ bool has_valid_path(const char *filename) ...@@ -47,14 +47,12 @@ bool has_valid_path(const char *filename)
statusbar(_("Directory '%s' does not exist"), parentdir); statusbar(_("Directory '%s' does not exist"), parentdir);
else else
statusbar(_("Path '%s': %s"), parentdir, strerror(errno)); statusbar(_("Path '%s': %s"), parentdir, strerror(errno));
} else if (!S_ISDIR(parentinfo.st_mode)) { } else if (!S_ISDIR(parentinfo.st_mode))
statusbar(_("Path '%s' is not a directory"), parentdir); statusbar(_("Path '%s' is not a directory"), parentdir);
} else { else if (access(parentdir, X_OK) == -1)
if (access(parentdir, X_OK) == -1) statusbar(_("Path '%s' is not accessible"), parentdir);
statusbar(_("Path '%s' is not accessible"), parentdir); else
else validity = TRUE;
validity = TRUE;
}
free(namecopy); free(namecopy);
...@@ -64,14 +62,13 @@ bool has_valid_path(const char *filename) ...@@ -64,14 +62,13 @@ bool has_valid_path(const char *filename)
return validity; return validity;
} }
/* Add an entry to the openfile openfilestruct. This should only be /* Add an entry to the circular list of openfile structs. */
* called from open_buffer(). */
void make_new_buffer(void) void make_new_buffer(void)
{ {
if (openfile == NULL) { if (openfile == NULL) {
openfile = make_new_opennode(); openfile = make_new_opennode();
/* Make the first open file the only element in a circular list. */ /* Make the first open file the only element in the list. */
openfile->prev = openfile; openfile->prev = openfile;
openfile->next = openfile; openfile->next = openfile;
} else { } else {
...@@ -120,8 +117,7 @@ void make_new_buffer(void) ...@@ -120,8 +117,7 @@ void make_new_buffer(void)
#endif #endif
} }
/* Initialize the text of the current entry of the openfile /* Initialize the text of the current openfile struct. */
* openfilestruct. */
void initialize_buffer_text(void) void initialize_buffer_text(void)
{ {
assert(openfile != NULL); assert(openfile != NULL);
...@@ -1216,8 +1212,9 @@ void do_insertfile( ...@@ -1216,8 +1212,9 @@ void do_insertfile(
#endif #endif
#ifndef DISABLE_MULTIBUFFER #ifndef DISABLE_MULTIBUFFER
if (!ISSET(MULTIBUFFER)) { if (!ISSET(MULTIBUFFER))
#endif #endif
{
/* If we're not inserting into a new buffer, partition /* If we're not inserting into a new buffer, partition
* the filestruct so that it contains no text and hence * the filestruct so that it contains no text and hence
* looks like a new buffer, and keep track of whether * looks like a new buffer, and keep track of whether
...@@ -1226,9 +1223,7 @@ void do_insertfile( ...@@ -1226,9 +1223,7 @@ void do_insertfile(
openfile->current_x, openfile->current, openfile->current_x, openfile->current,
openfile->current_x); openfile->current_x);
edittop_inside = (openfile->edittop == openfile->fileage); edittop_inside = (openfile->edittop == openfile->fileage);
#ifndef DISABLE_MULTIBUFFER
} }
#endif
/* Convert newlines to nulls in the given filename. */ /* Convert newlines to nulls in the given filename. */
sunder(answer); sunder(answer);
...@@ -1387,7 +1382,7 @@ void do_insertfile_void(void) ...@@ -1387,7 +1382,7 @@ void do_insertfile_void(void)
char *get_full_path(const char *origpath) char *get_full_path(const char *origpath)
{ {
int attempts = 0; int attempts = 0;
/* How often we've tried climing back up the tree. */ /* How often we've tried climbing back up the tree. */
struct stat fileinfo; struct stat fileinfo;
char *currentdir, *d_here, *d_there, *d_there_file = NULL; char *currentdir, *d_here, *d_there, *d_there_file = NULL;
const char *last_slash; const char *last_slash;
...@@ -1762,7 +1757,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type ...@@ -1762,7 +1757,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
struct stat st; struct stat st;
/* The status fields filled in by stat(). */ /* The status fields filled in by stat(). */
char *realname; char *realname;
/* name after tilde expansion. */ /* The filename after tilde expansion. */
FILE *f = f_open; FILE *f = f_open;
/* The actual file, realname, we are writing to. */ /* The actual file, realname, we are writing to. */
char *tempname = NULL; char *tempname = NULL;
...@@ -2153,8 +2148,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type ...@@ -2153,8 +2148,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
realname); realname);
#ifndef DISABLE_COLOR #ifndef DISABLE_COLOR
/* We might have changed the filename, so update the colors /* We might have changed the filename, so update the colors
* to account for it, and then make sure we're using * to account for it, and then make sure we're using them. */
* them. */
color_update(); color_update();
color_init(); color_init();
...@@ -2475,12 +2469,12 @@ int do_writeout(bool exiting) ...@@ -2475,12 +2469,12 @@ int do_writeout(bool exiting)
* a separate file. If we're using restricted mode, this * a separate file. If we're using restricted mode, this
* function is disabled, since it allows reading from or * function is disabled, since it allows reading from or
* writing to files not specified on the command line. */ * writing to files not specified on the command line. */
result =
#ifndef NANO_TINY #ifndef NANO_TINY
(!ISSET(RESTRICTED) && !exiting && openfile->mark_set) ? if (!ISSET(RESTRICTED) && !exiting && openfile->mark_set)
write_marked_file(answer, NULL, FALSE, append) : result = write_marked_file(answer, NULL, FALSE, append);
else
#endif #endif
write_file(answer, NULL, FALSE, append, FALSE); result = write_file(answer, NULL, FALSE, append, FALSE);
break; break;
} }
...@@ -2773,9 +2767,9 @@ char *input_tab(char *buf, bool allow_files, size_t *place, ...@@ -2773,9 +2767,9 @@ char *input_tab(char *buf, bool allow_files, size_t *place,
/* If the word starts with `~' and there is no slash in the word, /* If the word starts with `~' and there is no slash in the word,
* then try completing this word as a username. */ * then try completing this word as a username. */
if (*place > 0 && *buf == '~') { if (*place > 0 && *buf == '~') {
const char *bob = strchr(buf, '/'); const char *slash = strchr(buf, '/');
if (bob == NULL || bob >= buf + *place) if (slash == NULL || slash >= buf + *place)
matches = username_tab_completion(buf, &num_matches, *place); matches = username_tab_completion(buf, &num_matches, *place);
} }
...@@ -2849,38 +2843,31 @@ char *input_tab(char *buf, bool allow_files, size_t *place, ...@@ -2849,38 +2843,31 @@ char *input_tab(char *buf, bool allow_files, size_t *place,
else if (num_matches > 1) { else if (num_matches > 1) {
int longest_name = 0, ncols, editline = 0; int longest_name = 0, ncols, editline = 0;
/* Now we show a list of the available choices. */ /* Sort the list of available choices. */
assert(num_matches > 1);
/* Sort the list. */
qsort(matches, num_matches, sizeof(char *), diralphasort); qsort(matches, num_matches, sizeof(char *), diralphasort);
/* Find the length of the longest among the choices. */
for (match = 0; match < num_matches; match++) { for (match = 0; match < num_matches; match++) {
common_len = strnlenpt(matches[match], COLS - 1); size_t namelen = strnlenpt(matches[match], COLS - 1);
if (common_len > COLS - 1) {
longest_name = COLS - 1;
break;
}
if (common_len > longest_name) if (namelen > longest_name)
longest_name = common_len; longest_name = namelen;
} }
assert(longest_name <= COLS - 1); if (longest_name > COLS - 1)
longest_name = COLS - 1;
/* Each column will be (longest_name + 2) columns wide, i.e. /* Each column will be (longest_name + 2) columns wide, i.e.
* two spaces between columns, except that there will be * two spaces between columns, except that there will be
* only one space after the last column. */ * only one space after the last column. */
ncols = (COLS + 1) / (longest_name + 2); ncols = (COLS + 1) / (longest_name + 2);
/* Blank the edit window, and print the matches out there. */ /* Blank the edit window and hide the cursor. */
blank_edit(); blank_edit();
wmove(edit, 0, 0);
/* Don't show a cursor in the list of completions. */
curs_set(0); curs_set(0);
wmove(edit, 0, 0);
/* Now print the list of matches out there. */
for (match = 0; match < num_matches; match++) { for (match = 0; match < num_matches; match++) {
char *disp; char *disp;
......
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