tweaks: add a helper function without the ubiquitous NULL argument
For conciseness and clarity.master
parent
ab6635c3a6
commit
d256d0cbc0
|
@ -285,7 +285,7 @@ char *do_browser(char *path)
|
|||
|
||||
/* If it isn't a directory, a file was selected -- we're done. */
|
||||
if (!S_ISDIR(st.st_mode)) {
|
||||
retval = mallocstrcpy(NULL, filelist[selected]);
|
||||
retval = copy_of(filelist[selected]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -314,7 +314,7 @@ char *do_browser(char *path)
|
|||
/* If the window resized, refresh the file list. */
|
||||
if (kbinput == KEY_WINCH) {
|
||||
/* Remember the selected file, to be able to reselect it. */
|
||||
present_name = mallocstrcpy(NULL, filelist[selected]);
|
||||
present_name = copy_of(filelist[selected]);
|
||||
/* Reread the contents of the current directory. */
|
||||
goto read_directory_contents;
|
||||
}
|
||||
|
@ -546,17 +546,17 @@ void browser_refresh(void)
|
|||
* "(dir)" for directories, and the file size for normal files. */
|
||||
if (lstat(filelist[i], &st) == -1 || S_ISLNK(st.st_mode)) {
|
||||
if (stat(filelist[i], &st) == -1 || !S_ISDIR(st.st_mode))
|
||||
info = mallocstrcpy(NULL, "--");
|
||||
info = copy_of("--");
|
||||
else
|
||||
/* TRANSLATORS: Try to keep this at most 7 characters. */
|
||||
info = mallocstrcpy(NULL, _("(dir)"));
|
||||
info = copy_of(_("(dir)"));
|
||||
} else if (S_ISDIR(st.st_mode)) {
|
||||
if (strcmp(thename, "..") == 0) {
|
||||
/* TRANSLATORS: Try to keep this at most 12 characters. */
|
||||
info = mallocstrcpy(NULL, _("(parent dir)"));
|
||||
info = copy_of(_("(parent dir)"));
|
||||
infomaxlen = 12;
|
||||
} else
|
||||
info = mallocstrcpy(NULL, _("(dir)"));
|
||||
info = copy_of(_("(dir)"));
|
||||
} else {
|
||||
off_t result = st.st_size;
|
||||
char modifier;
|
||||
|
@ -664,7 +664,7 @@ int filesearch_init(bool forwards)
|
|||
(breadth(last_search) > COLS / 3) ? "..." : "");
|
||||
free(disp);
|
||||
} else
|
||||
thedefault = mallocstrcpy(NULL, "");
|
||||
thedefault = copy_of("");
|
||||
|
||||
/* Now ask what to search for. */
|
||||
response = do_prompt(FALSE, FALSE, MWHEREISFILE, NULL, &search_history,
|
||||
|
@ -792,7 +792,7 @@ void to_last_file(void)
|
|||
* The returned string is dynamically allocated, and should be freed. */
|
||||
char *strip_last_component(const char *path)
|
||||
{
|
||||
char *copy = mallocstrcpy(NULL, path);
|
||||
char *copy = copy_of(path);
|
||||
char *last_slash = strrchr(copy, '/');
|
||||
|
||||
if (last_slash != NULL)
|
||||
|
|
42
src/files.c
42
src/files.c
|
@ -35,7 +35,7 @@
|
|||
/* Verify that the containing directory of the given filename exists. */
|
||||
bool has_valid_path(const char *filename)
|
||||
{
|
||||
char *namecopy = mallocstrcpy(NULL, filename);
|
||||
char *namecopy = copy_of(filename);
|
||||
char *parentdir = dirname(namecopy);
|
||||
struct stat parentinfo;
|
||||
bool validity = FALSE;
|
||||
|
@ -86,10 +86,10 @@ void make_new_buffer(void)
|
|||
/* Make the new buffer the current one, and start initializing it. */
|
||||
openfile = newnode;
|
||||
|
||||
openfile->filename = mallocstrcpy(NULL, "");
|
||||
openfile->filename = copy_of("");
|
||||
|
||||
openfile->filetop = make_new_node(NULL);
|
||||
openfile->filetop->data = mallocstrcpy(NULL, "");
|
||||
openfile->filetop->data = copy_of("");
|
||||
openfile->filebot = openfile->filetop;
|
||||
|
||||
openfile->current = openfile->filetop;
|
||||
|
@ -293,8 +293,8 @@ int delete_lockfile(const char *lockfilename)
|
|||
* creating the lockfile but we should continue to load the file. */
|
||||
int do_lockfile(const char *filename)
|
||||
{
|
||||
char *namecopy = mallocstrcpy(NULL, filename);
|
||||
char *secondcopy = mallocstrcpy(NULL, filename);
|
||||
char *namecopy = copy_of(filename);
|
||||
char *secondcopy = copy_of(filename);
|
||||
size_t locknamesize = strlen(filename) + strlen(locking_prefix)
|
||||
+ strlen(locking_suffix) + 3;
|
||||
char *lockfilename = charalloc(locknamesize);
|
||||
|
@ -349,7 +349,7 @@ int do_lockfile(const char *filename)
|
|||
room = COLS - breadth(question) + 7 - breadth(lockuser) -
|
||||
breadth(lockprog) - breadth(pidstring);
|
||||
if (room < 4)
|
||||
postedname = mallocstrcpy(NULL, "_");
|
||||
postedname = copy_of("_");
|
||||
else if (room < breadth(filename)) {
|
||||
char *fragment = display_string(filename,
|
||||
breadth(filename) - room + 3, room, FALSE, FALSE);
|
||||
|
@ -675,7 +675,7 @@ char *encode_data(char *buf, size_t buf_len)
|
|||
unsunder(buf, buf_len);
|
||||
buf[buf_len] = '\0';
|
||||
|
||||
return mallocstrcpy(NULL, buf);
|
||||
return copy_of(buf);
|
||||
}
|
||||
|
||||
/* Read the given open file f into the current buffer. filename should be
|
||||
|
@ -841,7 +841,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
|
|||
/* If the file ended with newline, or it was entirely empty, make the
|
||||
* last line blank. Otherwise, put the last read data in. */
|
||||
if (len == 0)
|
||||
bottomline->data = mallocstrcpy(NULL, "");
|
||||
bottomline->data = copy_of("");
|
||||
else {
|
||||
bool mac_line_needs_newline = FALSE;
|
||||
|
||||
|
@ -867,7 +867,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
|
|||
if (mac_line_needs_newline) {
|
||||
bottomline->next = make_new_node(bottomline);
|
||||
bottomline = bottomline->next;
|
||||
bottomline->data = mallocstrcpy(NULL, "");
|
||||
bottomline->data = copy_of("");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1024,7 +1024,7 @@ void do_insertfile(void)
|
|||
{
|
||||
int response;
|
||||
const char *msg;
|
||||
char *given = mallocstrcpy(NULL, "");
|
||||
char *given = copy_of("");
|
||||
/* The last answer the user typed at the statusbar prompt. */
|
||||
#ifndef NANO_TINY
|
||||
format_type was_fmt = openfile->fmt;
|
||||
|
@ -1245,7 +1245,7 @@ char *get_full_path(const char *origpath)
|
|||
strcat(here, "/");
|
||||
}
|
||||
} else {
|
||||
here = mallocstrcpy(NULL, "");
|
||||
here = copy_of("");
|
||||
free(allocation);
|
||||
}
|
||||
|
||||
|
@ -1275,7 +1275,7 @@ char *get_full_path(const char *origpath)
|
|||
} else {
|
||||
/* If target contains a filename, separate the two. */
|
||||
if (!path_only) {
|
||||
just_filename = mallocstrcpy(NULL, last_slash + 1);
|
||||
just_filename = copy_of(last_slash + 1);
|
||||
*(last_slash + 1) = '\0';
|
||||
}
|
||||
|
||||
|
@ -1358,7 +1358,7 @@ char *safe_tempfile(FILE **stream)
|
|||
tempdir = check_writable_directory(P_tmpdir);
|
||||
|
||||
if (tempdir == NULL)
|
||||
tempdir = mallocstrcpy(NULL, "/tmp/");
|
||||
tempdir = copy_of("/tmp/");
|
||||
|
||||
tempfile_name = charealloc(tempdir, strlen(tempdir) + 12);
|
||||
strcat(tempfile_name, "nano.XXXXXX");
|
||||
|
@ -1607,7 +1607,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
|
|||
* filename portion of the given path. Otherwise, replace
|
||||
* slashes with exclamation marks in the full path. */
|
||||
if (backuptemp == NULL)
|
||||
backuptemp = mallocstrcpy(NULL, tail(realname));
|
||||
backuptemp = copy_of(tail(realname));
|
||||
else {
|
||||
size_t i = 0;
|
||||
|
||||
|
@ -2025,7 +2025,7 @@ int do_writeout(bool exiting, bool withprompt)
|
|||
/* Display newlines in filenames as ^J. */
|
||||
as_an_at = FALSE;
|
||||
|
||||
given = mallocstrcpy(NULL,
|
||||
given = copy_of(
|
||||
#ifndef NANO_TINY
|
||||
(openfile->mark && !exiting) ? "" :
|
||||
#endif
|
||||
|
@ -2279,7 +2279,7 @@ char *real_dir_from_tilde(const char *path)
|
|||
size_t i = 1;
|
||||
|
||||
if (*path != '~')
|
||||
return mallocstrcpy(NULL, path);
|
||||
return copy_of(path);
|
||||
|
||||
/* Figure out how much of the string we need to compare. */
|
||||
while (path[i] != '/' && path[i] != '\0')
|
||||
|
@ -2287,7 +2287,7 @@ char *real_dir_from_tilde(const char *path)
|
|||
|
||||
if (i == 1) {
|
||||
get_homedir();
|
||||
tilded = mallocstrcpy(NULL, homedir);
|
||||
tilded = copy_of(homedir);
|
||||
} else {
|
||||
#ifdef HAVE_PWD_H
|
||||
const struct passwd *userdata;
|
||||
|
@ -2415,7 +2415,7 @@ char **username_tab_completion(const char *buf, size_t *num_matches,
|
|||
char **cwd_tab_completion(const char *buf, bool allow_files,
|
||||
size_t *num_matches, size_t buf_len)
|
||||
{
|
||||
char *dirname = mallocstrcpy(NULL, buf);
|
||||
char *dirname = copy_of(buf);
|
||||
char *slash, *filename;
|
||||
size_t filenamelen;
|
||||
char **matches = NULL;
|
||||
|
@ -2430,7 +2430,7 @@ char **cwd_tab_completion(const char *buf, bool allow_files,
|
|||
if (slash != NULL) {
|
||||
char *wasdirname = dirname;
|
||||
|
||||
filename = mallocstrcpy(NULL, ++slash);
|
||||
filename = copy_of(++slash);
|
||||
/* Cut off the filename part after the slash. */
|
||||
*slash = '\0';
|
||||
dirname = real_dir_from_tilde(dirname);
|
||||
|
@ -2443,7 +2443,7 @@ char **cwd_tab_completion(const char *buf, bool allow_files,
|
|||
free(wasdirname);
|
||||
} else {
|
||||
filename = dirname;
|
||||
dirname = mallocstrcpy(NULL, present_path);
|
||||
dirname = copy_of(present_path);
|
||||
}
|
||||
|
||||
dir = opendir(dirname);
|
||||
|
@ -2488,7 +2488,7 @@ char **cwd_tab_completion(const char *buf, bool allow_files,
|
|||
|
||||
matches = (char **)nrealloc(matches, (*num_matches + 1) *
|
||||
sizeof(char *));
|
||||
matches[*num_matches] = mallocstrcpy(NULL, nextdir->d_name);
|
||||
matches[*num_matches] = copy_of(nextdir->d_name);
|
||||
++(*num_matches);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ void wrap_help_text_into_buffer(void)
|
|||
do {
|
||||
openfile->current->next = make_new_node(openfile->current);
|
||||
openfile->current = openfile->current->next;
|
||||
openfile->current->data = mallocstrcpy(NULL, "");
|
||||
openfile->current->data = copy_of("");
|
||||
} while (*(++ptr) == '\n');
|
||||
}
|
||||
|
||||
|
|
|
@ -48,17 +48,17 @@ static poshiststruct *position_history = NULL;
|
|||
void history_init(void)
|
||||
{
|
||||
search_history = make_new_node(NULL);
|
||||
search_history->data = mallocstrcpy(NULL, "");
|
||||
search_history->data = copy_of("");
|
||||
searchtop = search_history;
|
||||
searchbot = search_history;
|
||||
|
||||
replace_history = make_new_node(NULL);
|
||||
replace_history->data = mallocstrcpy(NULL, "");
|
||||
replace_history->data = copy_of("");
|
||||
replacetop = replace_history;
|
||||
replacebot = replace_history;
|
||||
|
||||
execute_history = make_new_node(NULL);
|
||||
execute_history->data = mallocstrcpy(NULL, "");
|
||||
execute_history->data = copy_of("");
|
||||
executetop = execute_history;
|
||||
executebot = execute_history;
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ void update_history(linestruct **item, const char *text)
|
|||
(*hbot)->data = mallocstrcpy((*hbot)->data, text);
|
||||
splice_node(*hbot, make_new_node(*hbot));
|
||||
*hbot = (*hbot)->next;
|
||||
(*hbot)->data = mallocstrcpy(NULL, "");
|
||||
(*hbot)->data = copy_of("");
|
||||
|
||||
/* Indicate that the history needs to be saved on exit. */
|
||||
history_changed = TRUE;
|
||||
|
@ -431,7 +431,7 @@ void load_poshistory(void)
|
|||
|
||||
/* Create a new position record. */
|
||||
newrecord = (poshiststruct *)nmalloc(sizeof(poshiststruct));
|
||||
newrecord->filename = mallocstrcpy(NULL, line);
|
||||
newrecord->filename = copy_of(line);
|
||||
newrecord->lineno = atoi(lineptr);
|
||||
newrecord->xno = atoi(xptr);
|
||||
newrecord->next = NULL;
|
||||
|
@ -563,7 +563,7 @@ void update_poshistory(char *filename, ssize_t lineno, ssize_t xpos)
|
|||
* not at the end, move the matching one to the end. */
|
||||
if (theone == NULL) {
|
||||
theone = (poshiststruct *)nmalloc(sizeof(poshiststruct));
|
||||
theone->filename = mallocstrcpy(NULL, fullpath);
|
||||
theone->filename = copy_of(fullpath);
|
||||
if (position_history == NULL)
|
||||
position_history = theone;
|
||||
else
|
||||
|
|
24
src/nano.c
24
src/nano.c
|
@ -100,7 +100,7 @@ linestruct *copy_node(const linestruct *src)
|
|||
{
|
||||
linestruct *dst = nmalloc(sizeof(linestruct));
|
||||
|
||||
dst->data = mallocstrcpy(NULL, src->data);
|
||||
dst->data = copy_of(src->data);
|
||||
dst->next = src->next;
|
||||
dst->prev = src->prev;
|
||||
dst->lineno = src->lineno;
|
||||
|
@ -233,7 +233,7 @@ void partition_buffer(linestruct *top, size_t top_x,
|
|||
* bottom of the partition from it, and save the text after bot_x. */
|
||||
hindline = bot->next;
|
||||
bot->next = NULL;
|
||||
postdata = mallocstrcpy(NULL, bot->data + bot_x);
|
||||
postdata = copy_of(bot->data + bot_x);
|
||||
|
||||
/* At the end of the partition, remove all text after bot_x. */
|
||||
bot->data[bot_x] = '\0';
|
||||
|
@ -342,7 +342,7 @@ void extract(linestruct *top, size_t top_x, linestruct *bot, size_t bot_x)
|
|||
|
||||
/* Since the text has now been saved, remove it from the file buffer. */
|
||||
openfile->filetop = make_new_node(NULL);
|
||||
openfile->filetop->data = mallocstrcpy(NULL, "");
|
||||
openfile->filetop->data = copy_of("");
|
||||
openfile->filebot = openfile->filetop;
|
||||
|
||||
/* Restore the current line and cursor position. If the mark begins
|
||||
|
@ -2444,11 +2444,11 @@ int main(int argc, char **argv)
|
|||
#ifdef ENABLE_JUSTIFY
|
||||
/* Set the default value for things that weren't specified. */
|
||||
if (punct == NULL)
|
||||
punct = mallocstrcpy(NULL, "!.?");
|
||||
punct = copy_of("!.?");
|
||||
if (brackets == NULL)
|
||||
brackets = mallocstrcpy(NULL, "\"')>]}");
|
||||
brackets = copy_of("\"')>]}");
|
||||
if (quotestr == NULL)
|
||||
quotestr = mallocstrcpy(NULL, "^([ \t]*([!#%:;>|}]|/{2}))+");
|
||||
quotestr = copy_of("^([ \t]*([!#%:;>|}]|/{2}))+");
|
||||
|
||||
/* Compile the quoting regex, and exit when it's invalid. */
|
||||
quoterc = regcomp("ereg, quotestr, NANO_REG_EXTENDED);
|
||||
|
@ -2472,14 +2472,14 @@ int main(int argc, char **argv)
|
|||
const char *spellenv = getenv("SPELL");
|
||||
|
||||
if (spellenv != NULL)
|
||||
alt_speller = mallocstrcpy(NULL, spellenv);
|
||||
alt_speller = copy_of(spellenv);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* If matchbrackets wasn't specified, set its default value. */
|
||||
if (matchbrackets == NULL)
|
||||
matchbrackets = mallocstrcpy(NULL, "(<[{)>]}");
|
||||
matchbrackets = copy_of("(<[{)>]}");
|
||||
|
||||
/* If the whitespace option wasn't specified, set its default value. */
|
||||
if (whitespace == NULL) {
|
||||
|
@ -2487,13 +2487,13 @@ int main(int argc, char **argv)
|
|||
if (using_utf8()) {
|
||||
/* A tab is shown as a Right-Pointing Double Angle Quotation Mark
|
||||
* (U+00BB), and a space as a Middle Dot (U+00B7). */
|
||||
whitespace = mallocstrcpy(NULL, "\xC2\xBB\xC2\xB7");
|
||||
whitespace = copy_of("\xC2\xBB\xC2\xB7");
|
||||
whitelen[0] = 2;
|
||||
whitelen[1] = 2;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
whitespace = mallocstrcpy(NULL, ">.");
|
||||
whitespace = copy_of(">.");
|
||||
whitelen[0] = 1;
|
||||
whitelen[1] = 1;
|
||||
}
|
||||
|
@ -2501,7 +2501,7 @@ int main(int argc, char **argv)
|
|||
#endif /* !NANO_TINY */
|
||||
|
||||
/* Initialize the search string. */
|
||||
last_search = mallocstrcpy(NULL, "");
|
||||
last_search = copy_of("");
|
||||
UNSET(BACKWARDS_SEARCH);
|
||||
|
||||
/* If tabsize wasn't specified, set its default value. */
|
||||
|
@ -2609,7 +2609,7 @@ int main(int argc, char **argv)
|
|||
|
||||
if (argv[optind][n] == '/' || argv[optind][n] == '?') {
|
||||
if (argv[optind][n + 1]) {
|
||||
searchstring = mallocstrcpy(NULL, &argv[optind][n + 1]);
|
||||
searchstring = copy_of(&argv[optind][n + 1]);
|
||||
if (argv[optind][n] == '?')
|
||||
SET(BACKWARDS_SEARCH);
|
||||
} else if (n == 1)
|
||||
|
|
|
@ -581,6 +581,7 @@ void *nmalloc(size_t howmuch);
|
|||
void *nrealloc(void *ptr, size_t howmuch);
|
||||
char *mallocstrncpy(char *dest, const char *src, size_t n);
|
||||
char *mallocstrcpy(char *dest, const char *src);
|
||||
char *copy_of(const char *string);
|
||||
char *free_and_assign(char *dest, char *src);
|
||||
size_t get_page_start(size_t column);
|
||||
size_t xplustabs(void);
|
||||
|
|
12
src/rcfile.c
12
src/rcfile.c
|
@ -325,7 +325,7 @@ void begin_new_syntax(char *ptr)
|
|||
|
||||
/* Initialize a new syntax struct. */
|
||||
live_syntax = (syntaxtype *)nmalloc(sizeof(syntaxtype));
|
||||
live_syntax->name = mallocstrcpy(NULL, nameptr);
|
||||
live_syntax->name = copy_of(nameptr);
|
||||
live_syntax->filename = strdup(nanorc);
|
||||
live_syntax->lineno = lineno;
|
||||
live_syntax->augmentations = NULL;
|
||||
|
@ -335,7 +335,7 @@ void begin_new_syntax(char *ptr)
|
|||
live_syntax->linter = NULL;
|
||||
live_syntax->tab = NULL;
|
||||
#ifdef ENABLE_COMMENT
|
||||
live_syntax->comment = mallocstrcpy(NULL, GENERAL_COMMENT_CHARACTER);
|
||||
live_syntax->comment = copy_of(GENERAL_COMMENT_CHARACTER);
|
||||
#endif
|
||||
live_syntax->color = NULL;
|
||||
live_syntax->nmultis = 0;
|
||||
|
@ -405,7 +405,7 @@ void parse_binding(char *ptr, bool dobind)
|
|||
|
||||
keyptr = ptr;
|
||||
ptr = parse_next_word(ptr);
|
||||
keycopy = mallocstrcpy(NULL, keyptr);
|
||||
keycopy = copy_of(keyptr);
|
||||
|
||||
if (strlen(keycopy) < 2) {
|
||||
jot_error(N_("Key name is too short"));
|
||||
|
@ -463,7 +463,7 @@ void parse_binding(char *ptr, bool dobind)
|
|||
if (*funcptr == '"') {
|
||||
newsc = nmalloc(sizeof(keystruct));
|
||||
newsc->func = (functionptrtype)implant;
|
||||
newsc->expansion = mallocstrcpy(NULL, funcptr + 1);
|
||||
newsc->expansion = copy_of(funcptr + 1);
|
||||
#ifndef NANO_TINY
|
||||
newsc->toggle = 0;
|
||||
#endif
|
||||
|
@ -900,7 +900,7 @@ void grab_and_store(const char *kind, char *ptr, regexlisttype **storage)
|
|||
|
||||
/* Copy the regex into a struct, and hook this in at the end. */
|
||||
newthing = (regexlisttype *)nmalloc(sizeof(regexlisttype));
|
||||
newthing->full_regex = mallocstrcpy(NULL, regexstring);
|
||||
newthing->full_regex = copy_of(regexstring);
|
||||
newthing->next = NULL;
|
||||
|
||||
if (lastthing == NULL)
|
||||
|
@ -1195,7 +1195,7 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only)
|
|||
continue;
|
||||
}
|
||||
#endif
|
||||
argument = mallocstrcpy(NULL, argument);
|
||||
argument = copy_of(argument);
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
if (strcasecmp(option, "titlecolor") == 0)
|
||||
|
|
|
@ -88,7 +88,7 @@ void search_init(bool replacing, bool keep_the_answer)
|
|||
(breadth(last_search) > COLS / 3) ? "..." : "");
|
||||
free(disp);
|
||||
} else
|
||||
thedefault = mallocstrcpy(NULL, "");
|
||||
thedefault = copy_of("");
|
||||
|
||||
while (TRUE) {
|
||||
functionptrtype func;
|
||||
|
|
35
src/text.c
35
src/text.c
|
@ -428,7 +428,7 @@ void do_comment(void)
|
|||
|
||||
/* Store the comment sequence used for the operation, because it could
|
||||
* change when the file name changes; we need to know what it was. */
|
||||
openfile->current_undo->strdata = mallocstrcpy(NULL, comment_seq);
|
||||
openfile->current_undo->strdata = copy_of(comment_seq);
|
||||
|
||||
/* Comment/uncomment each of the selected lines when possible, and
|
||||
* store undo data when a line changed. */
|
||||
|
@ -586,7 +586,7 @@ void do_undo(void)
|
|||
break;
|
||||
}
|
||||
t = make_new_node(f);
|
||||
t->data = mallocstrcpy(NULL, u->strdata);
|
||||
t->data = copy_of(u->strdata);
|
||||
data = mallocstrncpy(NULL, f->data, u->mark_begin_x + 1);
|
||||
data[u->mark_begin_x] = '\0';
|
||||
free(f->data);
|
||||
|
@ -726,7 +726,7 @@ void do_redo(void)
|
|||
case ENTER:
|
||||
redidmsg = _("line break");
|
||||
shoveline = make_new_node(f);
|
||||
shoveline->data = mallocstrcpy(NULL, u->strdata);
|
||||
shoveline->data = copy_of(u->strdata);
|
||||
data = mallocstrncpy(NULL, f->data, u->begin + 1);
|
||||
data[u->begin] = '\0';
|
||||
free(f->data);
|
||||
|
@ -1189,12 +1189,12 @@ void add_undo(undo_type action, const char *message)
|
|||
u->lineno = openfile->current->next->lineno;
|
||||
u->begin = 0;
|
||||
}
|
||||
u->strdata = mallocstrcpy(NULL, openfile->current->next->data);
|
||||
u->strdata = copy_of(openfile->current->next->data);
|
||||
}
|
||||
action = u->type = JOIN;
|
||||
break;
|
||||
case REPLACE:
|
||||
u->strdata = mallocstrcpy(NULL, openfile->current->data);
|
||||
u->strdata = copy_of(openfile->current->data);
|
||||
break;
|
||||
#ifdef ENABLE_WRAPPING
|
||||
case SPLIT_BEGIN:
|
||||
|
@ -1229,7 +1229,7 @@ void add_undo(undo_type action, const char *message)
|
|||
case COUPLE_BEGIN:
|
||||
u->mark_begin_lineno = openfile->current_y;
|
||||
case COUPLE_END:
|
||||
u->strdata = mallocstrcpy(NULL, _(message));
|
||||
u->strdata = copy_of(_(message));
|
||||
break;
|
||||
case INDENT:
|
||||
case UNINDENT:
|
||||
|
@ -1263,8 +1263,7 @@ void update_multiline_undo(ssize_t lineno, char *indentation)
|
|||
number_of_lines = u->grouping->bottom_line - u->grouping->top_line + 1;
|
||||
u->grouping->indentations = (char **)nrealloc(u->grouping->indentations,
|
||||
number_of_lines * sizeof(char *));
|
||||
u->grouping->indentations[number_of_lines - 1] = mallocstrcpy(NULL,
|
||||
indentation);
|
||||
u->grouping->indentations[number_of_lines - 1] = copy_of(indentation);
|
||||
} else {
|
||||
groupstruct *born = nmalloc(sizeof(groupstruct));
|
||||
|
||||
|
@ -1274,7 +1273,7 @@ void update_multiline_undo(ssize_t lineno, char *indentation)
|
|||
born->bottom_line = lineno;
|
||||
|
||||
u->grouping->indentations = (char **)nmalloc(sizeof(char *));
|
||||
u->grouping->indentations[0] = mallocstrcpy(NULL, indentation);
|
||||
u->grouping->indentations[0] = copy_of(indentation);
|
||||
}
|
||||
|
||||
/* Store the file size after the change, to be used when redoing. */
|
||||
|
@ -1305,7 +1304,7 @@ void update_undo(undo_type action)
|
|||
u->mark_begin_x = openfile->current_x;
|
||||
break;
|
||||
case ENTER:
|
||||
u->strdata = mallocstrcpy(NULL, openfile->current->data);
|
||||
u->strdata = copy_of(openfile->current->data);
|
||||
u->mark_begin_x = openfile->current_x;
|
||||
break;
|
||||
case BACK:
|
||||
|
@ -2114,7 +2113,7 @@ void do_justify(bool full_justify)
|
|||
strlen(cutbuffer->data) - needed_top_extra + 1);
|
||||
else {
|
||||
cutbuffer->prev = make_new_node(NULL);
|
||||
cutbuffer->prev->data = mallocstrcpy(NULL, "");
|
||||
cutbuffer->prev->data = copy_of("");
|
||||
cutbuffer->prev->next = cutbuffer;
|
||||
cutbuffer = cutbuffer->prev;
|
||||
}
|
||||
|
@ -2127,7 +2126,7 @@ void do_justify(bool full_justify)
|
|||
* region is "pasted" back. */
|
||||
if (bot_x > 0 && !ends_at_eol) {
|
||||
line->next = make_new_node(line);
|
||||
line->next->data = mallocstrcpy(NULL, the_lead + needed_bot_extra);
|
||||
line->next->data = copy_of(the_lead + needed_bot_extra);
|
||||
}
|
||||
|
||||
free(the_lead);
|
||||
|
@ -2213,7 +2212,7 @@ void do_full_justify(void)
|
|||
/* Set up an argument list for executing the given command. */
|
||||
void construct_argument_list(char ***arguments, char *command, char *filename)
|
||||
{
|
||||
char *copy_of_command = mallocstrcpy(NULL, command);
|
||||
char *copy_of_command = copy_of(command);
|
||||
char *element = strtok(copy_of_command, " ");
|
||||
int count = 2;
|
||||
|
||||
|
@ -2252,7 +2251,7 @@ bool fix_spello(const char *word)
|
|||
|
||||
/* Save the current search string, then set it to the misspelled word. */
|
||||
save_search = last_search;
|
||||
last_search = mallocstrcpy(NULL, word);
|
||||
last_search = copy_of(word);
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* If the mark is on, start at the beginning of the marked region. */
|
||||
|
@ -2810,7 +2809,7 @@ void do_linter(void)
|
|||
*pointer = '\0';
|
||||
if (onelint != pointer) {
|
||||
char *filename = NULL, *linestr = NULL, *maybecol = NULL;
|
||||
char *message = mallocstrcpy(NULL, onelint);
|
||||
char *message = copy_of(onelint);
|
||||
|
||||
/* At the moment we handle the following formats:
|
||||
*
|
||||
|
@ -2849,10 +2848,10 @@ void do_linter(void)
|
|||
curlint->prev = tmplint;
|
||||
if (curlint->prev != NULL)
|
||||
curlint->prev->next = curlint;
|
||||
curlint->msg = mallocstrcpy(NULL, message);
|
||||
curlint->msg = copy_of(message);
|
||||
curlint->lineno = tmplineno;
|
||||
curlint->colno = tmpcolno;
|
||||
curlint->filename = mallocstrcpy(NULL, filename);
|
||||
curlint->filename = copy_of(filename);
|
||||
|
||||
if (lints == NULL)
|
||||
lints = curlint;
|
||||
|
@ -2928,7 +2927,7 @@ void do_linter(void)
|
|||
open_buffer(curlint->filename, TRUE);
|
||||
} else {
|
||||
#endif
|
||||
char *dontwantfile = mallocstrcpy(NULL, curlint->filename);
|
||||
char *dontwantfile = copy_of(curlint->filename);
|
||||
lintstruct *restlint = NULL;
|
||||
|
||||
while (curlint != NULL) {
|
||||
|
|
12
src/utils.c
12
src/utils.c
|
@ -49,7 +49,7 @@ void get_homedir(void)
|
|||
/* Only set homedir if some home directory could be determined,
|
||||
* otherwise keep homedir NULL. */
|
||||
if (homenv != NULL && *homenv != '\0')
|
||||
homedir = mallocstrcpy(NULL, homenv);
|
||||
homedir = copy_of(homenv);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ bool parse_line_column(const char *str, ssize_t *line, ssize_t *column)
|
|||
if (comma == str)
|
||||
return retval;
|
||||
|
||||
firstpart = mallocstrcpy(NULL, str);
|
||||
firstpart = copy_of(str);
|
||||
firstpart[comma - str] = '\0';
|
||||
|
||||
retval = parse_num(firstpart, line) && retval;
|
||||
|
@ -331,6 +331,12 @@ char *mallocstrcpy(char *dest, const char *src)
|
|||
return mallocstrncpy(dest, src, (src == NULL) ? 1 : strlen(src) + 1);
|
||||
}
|
||||
|
||||
/* Return an allocated copy of the given string. */
|
||||
char *copy_of(const char *string)
|
||||
{
|
||||
return mallocstrncpy(NULL, string, strlen(string) + 1);
|
||||
}
|
||||
|
||||
/* Free the string at dest and return the string at src. */
|
||||
char *free_and_assign(char *dest, char *src)
|
||||
{
|
||||
|
@ -418,7 +424,7 @@ size_t breadth(const char *text)
|
|||
void new_magicline(void)
|
||||
{
|
||||
openfile->filebot->next = make_new_node(openfile->filebot);
|
||||
openfile->filebot->next->data = mallocstrcpy(NULL, "");
|
||||
openfile->filebot->next->data = copy_of("");
|
||||
openfile->filebot = openfile->filebot->next;
|
||||
openfile->totsize++;
|
||||
}
|
||||
|
|
|
@ -3431,7 +3431,7 @@ void spotlight(size_t from_col, size_t to_col)
|
|||
|
||||
/* This is so we can show zero-length matches. */
|
||||
if (to_col == from_col) {
|
||||
word = mallocstrcpy(NULL, " ");
|
||||
word = copy_of(" ");
|
||||
to_col++;
|
||||
} else
|
||||
word = display_string(openfile->current->data, from_col,
|
||||
|
@ -3474,7 +3474,7 @@ void spotlight_softwrapped(size_t from_col, size_t to_col)
|
|||
|
||||
/* This is so we can show zero-length matches. */
|
||||
if (break_col == from_col) {
|
||||
word = mallocstrcpy(NULL, " ");
|
||||
word = copy_of(" ");
|
||||
break_col++;
|
||||
} else
|
||||
word = display_string(openfile->current->data, from_col,
|
||||
|
|
Loading…
Reference in New Issue