- Added config.guess and config.sub to distribution because,
apparently, newer autoconf/automakes can't live without them.
- Various spelling updates by David Lawrence Ramsey.
+ - Changed all string allocations to charalloc(), new function
+ designed to take nmalloc argument but call calloc based on
+ (char *) size.
- configure.in:
- New option, --enable-nanorc, which allows people to have a .nanorc
initialization file and set options normally used on the command
/* Set up the beginning of the cutbuffer */
tmp = copy_node(top);
- tmpstr = nmalloc(strlen(&top->data[top_x]) + 1);
+ tmpstr = charalloc(strlen(&top->data[top_x]) + 1);
strcpy(tmpstr, &top->data[top_x]);
free(tmp->data);
tmp->data = tmpstr;
/* Chop off the end of the first line */
- tmpstr = nmalloc(top_x + 1);
+ tmpstr = charalloc(top_x + 1);
strncpy(tmpstr, top->data, top_x);
free(top->data);
top->data = tmpstr;
if (next == NULL)
return;
/* Now, paste bot[bot_x] into top[top_x] */
- tmpstr = nmalloc(strlen(top->data) + strlen(&bot->data[bot_x]));
+ tmpstr = charalloc(strlen(top->data) + strlen(&bot->data[bot_x]));
strncpy(tmpstr, top->data, top_x);
strcpy(&tmpstr[top_x], &bot->data[bot_x]);
free(top->data);
tmp = copy_node(current);
newsize = abs(mark_beginx - current_x) + 1;
- tmpstr = nmalloc(newsize + 1);
+ tmpstr = charalloc(newsize + 1);
if (current_x < mark_beginx) {
strncpy(tmpstr, ¤t->data[current_x], newsize);
memmove(¤t->data[current_x],
} else {
add_to_cutbuffer(fileptr);
fileage = make_new_node(NULL);
- fileage->data = nmalloc(1);
+ fileage->data = charalloc(1);
fileage->data[0] = '\0';
current = fileage;
}
/* If there's only one line in the cutbuffer */
if (cutbuffer->next == NULL) {
tmpstr =
- nmalloc(strlen(current->data) + strlen(cutbuffer->data) +
+ charalloc(strlen(current->data) + strlen(cutbuffer->data) +
1);
strncpy(tmpstr, current->data, current_x);
strcpy(&tmpstr[current_x], cutbuffer->data);
} else { /* yuck -- no kidding! */
tmp = current->next;
/* New beginning */
- tmpstr = nmalloc(current_x + strlen(newbuf->data) + 1);
+ tmpstr = charalloc(current_x + strlen(newbuf->data) + 1);
strncpy(tmpstr, current->data, current_x);
strcpy(&tmpstr[current_x], newbuf->data);
totsize += strlen(newbuf->data) + strlen(newend->data) + 1;
/* New end */
- tmpstr2 = nmalloc(strlen(newend->data) +
+ tmpstr2 = charalloc(strlen(newend->data) +
strlen(¤t->data[current_x]) + 1);
strcpy(tmpstr2, newend->data);
strcat(tmpstr2, ¤t->data[current_x]);
if (marked_cut == 2 && current_x != strlen(current->data)) {
tmp = make_new_node(current);
- tmp->data = nmalloc(strlen(¤t->data[current_x]) + 1);
+ tmp->data = charalloc(strlen(¤t->data[current_x]) + 1);
strcpy(tmp->data, ¤t->data[current_x]);
splice_node(current, tmp, current->next);
null_at(current->data, current_x);
void new_file(void)
{
fileage = nmalloc(sizeof(filestruct));
- fileage->data = nmalloc(1);
+ fileage->data = charalloc(1);
strcpy(fileage->data, "");
fileage->prev = NULL;
fileage->next = NULL;
filestruct *fileptr;
fileptr = nmalloc(sizeof(filestruct));
- fileptr->data = nmalloc(strlen(buf) + 2);
+ fileptr->data = charalloc(strlen(buf) + 2);
strcpy(fileptr->data, buf);
if (*line1ins) {
filestruct *fileptr = current, *tmp = NULL;
int line1ins = 0;
- buf = nmalloc(bufx);
+ buf = charalloc(bufx);
buf[0] = '\0';
if (fileptr != NULL && fileptr->prev != NULL) {
}
/* Don't follow symlink. Create new file. */
else {
- buf = nmalloc(strlen(realname) + 8);
+ buf = charalloc(strlen(realname) + 8);
strncpy(buf, realname, strlen(realname)+1);
strcat(buf, ".XXXXXX");
if ((fd = mkstemp(buf)) == -1) {
if (getenv("HOME") != NULL) {
free(dirtmp);
- dirtmp = nmalloc(strlen(buf) + 2 + strlen(getenv("HOME")));
+ dirtmp = charalloc(strlen(buf) + 2 + strlen(getenv("HOME")));
sprintf(dirtmp, "%s%s", getenv("HOME"), &buf[1]);
if (userdata != NULL) { /* User found */
free(dirtmp);
- dirtmp = nmalloc(strlen(buf) + 2 + strlen(userdata->pw_dir));
+ dirtmp = charalloc(strlen(buf) + 2 + strlen(userdata->pw_dir));
sprintf(dirtmp, "%s%s", userdata->pw_dir, &buf[i]);
}
* This makes a lot more sense to me (Chris) this way...
*/
- matchline = nmalloc(strlen(userdata->pw_name) + 2);
+ matchline = charalloc(strlen(userdata->pw_name) + 2);
sprintf(matchline, "~%s", userdata->pw_name);
matches[*num_matches] = matchline;
++*num_matches;
/* Okie, if there's a / in the buffer, strip out the directory part */
if (strcmp(buf, "") && strstr(buf, "/")) {
- dirName = nmalloc(strlen(buf) + 1);
+ dirName = charalloc(strlen(buf) + 1);
tmp = buf + strlen(buf);
while (*tmp != '/' && tmp != buf)
tmp--;
* This makes a lot more sense to me (Chris) this way...
*/
tmp2 = NULL;
- tmp2 = nmalloc(strlen(next->d_name) + 1);
+ tmp2 = charalloc(strlen(next->d_name) + 1);
strcpy(tmp2, next->d_name);
matches[*num_matches] = tmp2;
++*num_matches;
if (longestname > COLS - 1)
longestname = COLS - 1;
- foo = nmalloc(longestname + 5);
+ foo = charalloc(longestname + 5);
/* Print the list of matches */
for (i = 0, col = 0; i < num_matches; i++) {
while ((next = readdir(dir)) != NULL) {
if (!strcmp(next->d_name, "."))
continue;
- filelist[i] = nmalloc(strlen(next->d_name) + strlen(path) + 2);
+ filelist[i] = charalloc(strlen(next->d_name) + strlen(path) + 2);
if (!strcmp(path, "/"))
snprintf(filelist[i], strlen(next->d_name) + strlen(path) + 1,
path = mallocstrcpy(path, inpath);
filelist = browser_init(path, &longest, &numents);
- foo = nmalloc(longest + 8);
+ foo = charalloc(longest + 8);
/* Sort the list by directory first, then alphabetically */
qsort(filelist, numents, sizeof(char *), diralphasort);
i = write_file(name, 1);
} else {
- char *buf = nmalloc(strlen(filename) + 6);
+ char *buf = charalloc(strlen(filename) + 6);
strcpy(buf, filename);
strcat(buf, ".save");
i = write_file(buf, 1);
{
if (filename != NULL)
free(filename);
- filename = nmalloc(1);
+ filename = charalloc(1);
filename[0] = 0;
}
if (fill < MIN_FILL_LENGTH)
die_too_small();
- hblank = nmalloc(COLS + 1);
+ hblank = charalloc(COLS + 1);
memset(hblank, ' ', COLS);
hblank[COLS] = 0;
}
filestruct *dst;
dst = nmalloc(sizeof(filestruct));
- dst->data = nmalloc(strlen(src->data) + 1);
+ dst->data = charalloc(strlen(src->data) + 1);
dst->next = src->next;
dst->prev = src->prev;
current_x++;
totsize++;
}
- newnode->data = nmalloc(strlen(tmp) + extra + 1);
+ newnode->data = charalloc(strlen(tmp) + extra + 1);
strncpy(newnode->data, current->data, extra);
strcpy(&newnode->data[extra], tmp);
}
} else {
- newnode->data = nmalloc(strlen(tmp) + 1);
+ newnode->data = charalloc(strlen(tmp) + 1);
strcpy(newnode->data, tmp);
}
*tmp = 0;
down = 1;
}
- temp->data = nmalloc(strlen(&inptr->data[current_word_start]) + 1);
+ temp->data = charalloc(strlen(&inptr->data[current_word_start]) + 1);
strcpy(temp->data, &inptr->data[current_word_start]);
inptr->data = nrealloc(inptr->data, last_word_end + 2);
inptr->data[last_word_end + 1] = 0;
/* Category 1b: one word on the line and word not taking up whole line
(i.e. there are spaces at the beginning of the line) */
if (last_word_end == -1) {
- temp->data = nmalloc(strlen(&inptr->data[current_word_start]) + 1);
+ temp->data = charalloc(strlen(&inptr->data[current_word_start]) + 1);
strcpy(temp->data, &inptr->data[current_word_start]);
/* Inside word, remove it from original, and move cursor to right spot. */
/* Case 2a: cursor before word at wrap point. */
if (current_x < current_word_start) {
temp->data =
- nmalloc(strlen(&inptr->data[current_word_start]) + 1);
+ charalloc(strlen(&inptr->data[current_word_start]) + 1);
strcpy(temp->data, &inptr->data[current_word_start]);
if (!isspace((int) input_char)) {
else if ((current_x >= current_word_start)
&& (current_x <= (current_word_end + 1))) {
temp->data =
- nmalloc(strlen(&inptr->data[current_word_start]) + 1);
+ charalloc(strlen(&inptr->data[current_word_start]) + 1);
strcpy(temp->data, &inptr->data[current_word_start]);
down = 1;
/* Case 2c: cursor past word at wrap point. */
else {
temp->data =
- nmalloc(strlen(&inptr->data[current_word_start]) + 1);
+ charalloc(strlen(&inptr->data[current_word_start]) + 1);
strcpy(temp->data, &inptr->data[current_word_start]);
down = 1;
/* Plus one for the space which concatenates the two lines together plus 1 for \0. */
char *p =
- nmalloc((strlen(temp->data) + strlen(inptr->next->data) + 2)
- * sizeof(char));
+ charalloc((strlen(temp->data) + strlen(inptr->next->data) + 2));
if (ISSET(AUTOINDENT)) {
int non = 0;
spc++;
totsize++;
}
- t = nmalloc(strlen(temp->data) + extra + 1);
+ t = charalloc(strlen(temp->data) + extra + 1);
strncpy(t, inptr->data, extra);
strcpy(t + extra, temp->data);
free(temp->data);
return FALSE;
}
- read_buff = nmalloc(pipe_buff_size + 1);
+ read_buff = charalloc(pipe_buff_size + 1);
/* Process the returned spelling errors */
current->data[i] = '\0';
len2 = strlen(current->data + i + 1);
- tmpline->data = nmalloc(len2 + 1);
+ tmpline->data = charalloc(len2 + 1);
/* Skip the white space in current. */
memcpy(tmpline->data, current->data + i + 1, len2);
free(help_text);
/* Allocate space for the help text */
- help_text = nmalloc(allocsize);
+ help_text = charalloc(allocsize);
/* Now add the text we want */
strcpy(help_text, help_text_init);
break;
#ifndef DISABLE_SPELLER
case 's':
- alt_speller = nmalloc(strlen(optarg) + 1);
+ alt_speller = charalloc(strlen(optarg) + 1);
strcpy(alt_speller, optarg);
break;
#endif
void bottombars(shortcut s[], int slen);
void blank_statusbar_refresh(void);
void *nmalloc (size_t howmuch);
-void *ncalloc (size_t howmuch, size_t size);
void *mallocstrcpy(char *dest, char *src);
void wrap_reset(void);
void display_main_list(void);
int do_replace(void), do_help(void), do_enter_void(void);
int keypad_on(WINDOW * win, int newval);
+char *charalloc (size_t howmuch);
+
#ifndef DISABLE_BROWSER
char *do_browser(char *path);
struct stat filestat(const char *path);
if (getenv("HOME") == NULL)
return;
- nanorc = nmalloc(strlen(getenv("HOME")) + 10);
+ nanorc = charalloc(strlen(getenv("HOME")) + 10);
sprintf(nanorc, "%s/.nanorc", getenv("HOME"));
if (stat(nanorc, &fileinfo) == -1) {
void search_init_globals(void)
{
if (last_search == NULL) {
- last_search = nmalloc(1);
+ last_search = charalloc(1);
last_search[0] = 0;
}
if (last_replace == NULL) {
- last_replace = nmalloc(1);
+ last_replace = charalloc(1);
last_replace[0] = 0;
}
}
search_init_globals();
- buf = nmalloc(strlen(last_search) + 5);
+ buf = charalloc(strlen(last_search) + 5);
buf[0] = 0;
/* Okay, fun time. backupstring is our holder for what is being
}
/* Create buffer */
- copy = nmalloc(new_line_size);
+ copy = charalloc(new_line_size);
/* Head of Original Line */
strncpy(copy, current->data, current_x);
}
if (ISSET(PICO_MODE)) {
- buf = nmalloc(strlen(last_replace) + 5);
+ buf = charalloc(strlen(last_replace) + 5);
if (strcmp(last_replace, "")) {
if (strlen(last_replace) > (COLS / 3)) {
strncpy(buf, last_replace, COLS / 3);
return r;
}
-/* We're going to need this too */
-void *ncalloc(size_t howmuch, size_t size)
+/* We're going to need this too - Hopefully this will minimize
+ the transition cost of moving to the apropriate function. */
+char *charalloc(size_t howmuch)
{
void *r;
/* Panic save? */
- if (!(r = calloc(howmuch, size)))
+ if (!(r = calloc(howmuch, sizeof (char *))))
die(_("nano: calloc: out of memory!"));
- return r;
+ return (char *) r;
}
void *nrealloc(void *ptr, size_t howmuch)
return(dest);
}
- dest = nmalloc(strlen(src) + 1);
+ dest = charalloc(strlen(src) + 1);
strcpy(dest, src);
return dest;
void new_magicline(void)
{
filebot->next = nmalloc(sizeof(filestruct));
- filebot->next->data = nmalloc(1);
+ filebot->next->data = charalloc(1);
filebot->next->data[0] = '\0';
filebot->next->prev = filebot;
filebot->next->next = NULL;
int shift = 0;
#endif
- inputbuf = nmalloc(strlen(def) + 1);
+ inputbuf = charalloc(strlen(def) + 1);
inputbuf[0] = 0;
x_left = strlen(buf);
realdata = fileptr->data;
len = strlen(realdata);
- fileptr->data = nmalloc(xpt(fileptr, len) + 1);
+ fileptr->data = charalloc(xpt(fileptr, len) + 1);
pos = 0;
for (i = 0; i < len; i++) {