Chris Allegretta | 11b0011 | 2000-08-06 21:13:45 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 2 | /************************************************************************** |
| 3 | * files.c * |
| 4 | * * |
| 5 | * Copyright (C) 1999 Chris Allegretta * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 1, or (at your option) * |
| 9 | * any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the Free Software * |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * |
| 19 | * * |
| 20 | **************************************************************************/ |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | #include <stdio.h> |
| 25 | #include <unistd.h> |
| 26 | #include <sys/types.h> |
| 27 | #include <sys/stat.h> |
| 28 | #include <fcntl.h> |
| 29 | #include <errno.h> |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 30 | #include <ctype.h> |
| 31 | #include <dirent.h> |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 32 | |
| 33 | #include "config.h" |
| 34 | #include "proto.h" |
| 35 | #include "nano.h" |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 36 | |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 37 | #ifndef NANO_SMALL |
| 38 | #include <libintl.h> |
| 39 | #define _(string) gettext(string) |
| 40 | #else |
| 41 | #define _(string) (string) |
| 42 | #endif |
| 43 | |
| 44 | /* Load file into edit buffer - takes data from file struct */ |
| 45 | void load_file(void) |
| 46 | { |
| 47 | current = fileage; |
| 48 | wmove(edit, current_y, current_x); |
| 49 | } |
| 50 | |
| 51 | /* What happens when there is no file to open? aiee! */ |
| 52 | void new_file(void) |
| 53 | { |
| 54 | fileage = nmalloc(sizeof(filestruct)); |
| 55 | fileage->data = nmalloc(1); |
| 56 | strcpy(fileage->data, ""); |
| 57 | fileage->prev = NULL; |
| 58 | fileage->next = NULL; |
| 59 | fileage->lineno = 1; |
| 60 | filebot = fileage; |
| 61 | edittop = fileage; |
| 62 | editbot = fileage; |
| 63 | current = fileage; |
| 64 | totlines = 1; |
| 65 | UNSET(VIEW_MODE); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | int read_byte(int fd, char *filename, char *input) |
| 70 | { |
| 71 | static char buf[BUFSIZ]; |
| 72 | static int index = 0; |
| 73 | static int size = 0; |
| 74 | |
| 75 | if (index == size) { |
| 76 | index = 0; |
| 77 | size = read(fd, buf, BUFSIZ); |
| 78 | if (size == -1) { |
| 79 | clear(); |
| 80 | refresh(); |
| 81 | resetty(); |
| 82 | endwin(); |
| 83 | perror(filename); |
| 84 | } |
| 85 | if (!size) |
| 86 | return 0; |
| 87 | } |
| 88 | *input = buf[index++]; |
| 89 | return 1; |
| 90 | } |
| 91 | |
| 92 | filestruct *read_line(char *buf, filestruct * prev, int *line1ins) |
| 93 | { |
| 94 | filestruct *fileptr; |
| 95 | |
| 96 | fileptr = nmalloc(sizeof(filestruct)); |
| 97 | fileptr->data = nmalloc(strlen(buf) + 2); |
| 98 | strcpy(fileptr->data, buf); |
| 99 | |
| 100 | if (*line1ins) { |
| 101 | /* Special case, insert with cursor on 1st line. */ |
| 102 | fileptr->prev = NULL; |
| 103 | fileptr->next = fileage; |
| 104 | fileptr->lineno = 1; |
| 105 | *line1ins = 0; |
| 106 | /* If we're inserting into the first line of the file, then |
| 107 | we want to make sure that our edit buffer stays on the |
| 108 | first line (and that fileage stays up to date!) */ |
| 109 | fileage = fileptr; |
| 110 | edittop = fileptr; |
| 111 | } else if (fileage == NULL) { |
| 112 | fileage = fileptr; |
| 113 | fileage->lineno = 1; |
| 114 | fileage->next = fileage->prev = NULL; |
| 115 | fileptr = filebot = fileage; |
| 116 | } else if (prev) { |
| 117 | fileptr->prev = prev; |
| 118 | fileptr->next = NULL; |
| 119 | fileptr->lineno = prev->lineno + 1; |
| 120 | prev->next = fileptr; |
| 121 | } else { |
| 122 | die(_("read_line: not on first line and prev is NULL")); |
| 123 | } |
| 124 | |
| 125 | return fileptr; |
| 126 | } |
| 127 | |
| 128 | |
| 129 | int read_file(int fd, char *filename) |
| 130 | { |
Adam Rogoyski | 1e328fb | 2000-07-08 03:57:16 +0000 | [diff] [blame] | 131 | long size, num_lines = 0, linetemp = 0; |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 132 | char input[2]; /* buffer */ |
| 133 | char *buf; |
| 134 | long i = 0, bufx = 128; |
| 135 | filestruct *fileptr = current, *tmp = NULL; |
| 136 | int line1ins = 0; |
| 137 | |
| 138 | buf = nmalloc(bufx); |
Chris Allegretta | 8f6c069 | 2000-07-19 01:16:18 +0000 | [diff] [blame] | 139 | buf[0] = '\0'; |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 140 | |
| 141 | if (fileptr != NULL && fileptr->prev != NULL) { |
| 142 | fileptr = fileptr->prev; |
| 143 | tmp = fileptr; |
| 144 | } else if (fileptr != NULL && fileptr->prev == NULL) { |
| 145 | tmp = fileage; |
| 146 | current = fileage; |
| 147 | line1ins = 1; |
| 148 | } |
| 149 | input[1] = 0; |
| 150 | /* Read the entire file into file struct */ |
| 151 | while ((size = read_byte(fd, filename, input)) > 0) { |
| 152 | linetemp = 0; |
| 153 | if (input[0] == '\n') { |
| 154 | fileptr = read_line(buf, fileptr, &line1ins); |
Adam Rogoyski | 1e328fb | 2000-07-08 03:57:16 +0000 | [diff] [blame] | 155 | num_lines++; |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 156 | buf[0] = 0; |
| 157 | i = 0; |
| 158 | } else { |
| 159 | /* Now we allocate a bigger buffer 128 characters at a time. |
| 160 | If we allocate a lot of space for one line, we may indeed |
| 161 | have to use a buffer this big later on, so we don't |
| 162 | decrease it at all. We do free it at the end though. */ |
| 163 | |
| 164 | if (i >= bufx - 1) { |
| 165 | buf = nrealloc(buf, bufx + 128); |
| 166 | bufx += 128; |
| 167 | } |
| 168 | buf[i] = input[0]; |
| 169 | buf[i + 1] = 0; |
| 170 | i++; |
| 171 | } |
| 172 | totsize += size; |
| 173 | } |
| 174 | |
| 175 | /* Did we not get a newline but still have stuff to do? */ |
| 176 | if (buf[0]) { |
| 177 | fileptr = read_line(buf, fileptr, &line1ins); |
Adam Rogoyski | 1e328fb | 2000-07-08 03:57:16 +0000 | [diff] [blame] | 178 | num_lines++; |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 179 | buf[0] = 0; |
| 180 | } |
| 181 | /* Did we even GET a file? */ |
Chris Allegretta | 9956e53 | 2000-11-26 02:09:53 +0000 | [diff] [blame] | 182 | if (totsize == 0 || fileptr == NULL) { |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 183 | new_file(); |
Adam Rogoyski | 1e328fb | 2000-07-08 03:57:16 +0000 | [diff] [blame] | 184 | statusbar(_("Read %d lines"), num_lines); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 185 | return 1; |
| 186 | } |
Robert Siemborski | 63b3d7e | 2000-07-04 22:15:39 +0000 | [diff] [blame] | 187 | |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 188 | if (current != NULL) { |
| 189 | fileptr->next = current; |
| 190 | current->prev = fileptr; |
| 191 | renumber(current); |
| 192 | current_x = 0; |
| 193 | placewewant = 0; |
| 194 | } else if (fileptr->next == NULL) { |
| 195 | filebot = fileptr; |
Robert Siemborski | 63b3d7e | 2000-07-04 22:15:39 +0000 | [diff] [blame] | 196 | new_magicline(); |
Chris Allegretta | 321590a | 2000-12-10 06:03:40 +0000 | [diff] [blame] | 197 | totsize--; |
Robert Siemborski | 63b3d7e | 2000-07-04 22:15:39 +0000 | [diff] [blame] | 198 | |
| 199 | /* Update the edit buffer */ |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 200 | load_file(); |
| 201 | } |
Adam Rogoyski | 1e328fb | 2000-07-08 03:57:16 +0000 | [diff] [blame] | 202 | statusbar(_("Read %d lines"), num_lines); |
| 203 | totlines += num_lines; |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 204 | |
| 205 | free(buf); |
| 206 | close(fd); |
| 207 | |
| 208 | return 1; |
| 209 | } |
| 210 | |
| 211 | /* Open the file (and decide if it exists) */ |
| 212 | int open_file(char *filename, int insert, int quiet) |
| 213 | { |
| 214 | int fd; |
| 215 | struct stat fileinfo; |
| 216 | |
| 217 | if (!strcmp(filename, "") || stat(filename, &fileinfo) == -1) { |
| 218 | if (insert) { |
| 219 | if (!quiet) |
| 220 | statusbar(_("\"%s\" not found"), filename); |
| 221 | return -1; |
| 222 | } else { |
| 223 | /* We have a new file */ |
| 224 | statusbar(_("New File")); |
| 225 | new_file(); |
| 226 | } |
| 227 | } else if ((fd = open(filename, O_RDONLY)) == -1) { |
| 228 | if (!quiet) |
| 229 | statusbar("%s: %s", strerror(errno), filename); |
Chris Allegretta | 3a7c0be | 2000-12-18 01:09:07 +0000 | [diff] [blame] | 230 | if (!insert) |
| 231 | new_file(); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 232 | return -1; |
| 233 | } else { /* File is A-OK */ |
Chris Allegretta | 7960dcf | 2000-12-13 15:01:29 +0000 | [diff] [blame] | 234 | if (S_ISDIR(fileinfo.st_mode) || S_ISCHR(fileinfo.st_mode) || |
| 235 | S_ISBLK(fileinfo.st_mode)) { |
| 236 | if (S_ISDIR(fileinfo.st_mode)) |
| 237 | statusbar(_("File \"%s\" is a directory"), filename); |
| 238 | else |
| 239 | /* Don't open character or block files. Sorry, /dev/sndstat! */ |
| 240 | statusbar(_("File \"%s\" is a device file"), filename); |
| 241 | |
Chris Allegretta | f45c18d | 2000-09-16 05:25:06 +0000 | [diff] [blame] | 242 | if (!insert) |
| 243 | new_file(); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 244 | return -1; |
| 245 | } |
| 246 | if (!quiet) |
| 247 | statusbar(_("Reading File")); |
| 248 | read_file(fd, filename); |
| 249 | } |
| 250 | |
| 251 | return 1; |
| 252 | } |
| 253 | |
| 254 | int do_insertfile(void) |
| 255 | { |
| 256 | int i; |
Chris Allegretta | 25f4e58 | 2000-11-25 05:03:20 +0000 | [diff] [blame] | 257 | char *realname = NULL; |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 258 | |
| 259 | wrap_reset(); |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 260 | i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, "", |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 261 | _("File to insert [from ./] ")); |
| 262 | if (i != -1) { |
| 263 | |
| 264 | #ifdef DEBUG |
| 265 | fprintf(stderr, "filename is %s", answer); |
| 266 | #endif |
| 267 | |
Chris Allegretta | 09a8084 | 2000-11-30 02:31:13 +0000 | [diff] [blame] | 268 | #ifndef DISABLE_TABCOMP |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 269 | realname = real_dir_from_tilde(answer); |
Chris Allegretta | 09a8084 | 2000-11-30 02:31:13 +0000 | [diff] [blame] | 270 | #else |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 271 | realname = mallocstrcpy(realname, answer); |
Chris Allegretta | 09a8084 | 2000-11-30 02:31:13 +0000 | [diff] [blame] | 272 | #endif |
Chris Allegretta | 25f4e58 | 2000-11-25 05:03:20 +0000 | [diff] [blame] | 273 | |
| 274 | i = open_file(realname, 1, 0); |
| 275 | free(realname); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 276 | |
| 277 | dump_buffer(fileage); |
| 278 | set_modified(); |
| 279 | |
| 280 | /* Here we want to rebuild the edit window */ |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 281 | fix_editbot(); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 282 | |
| 283 | /* If we've gone off the bottom, recenter, otherwise just redraw */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 284 | if (current->lineno > editbot->lineno) |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 285 | edit_update(current, CENTER); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 286 | else |
| 287 | edit_refresh(); |
| 288 | |
| 289 | UNSET(KEEP_CUTBUFFER); |
| 290 | display_main_list(); |
| 291 | return i; |
| 292 | } else { |
| 293 | statusbar(_("Cancelled")); |
| 294 | UNSET(KEEP_CUTBUFFER); |
| 295 | display_main_list(); |
| 296 | return 0; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | * Write a file out. If tmp is nonzero, we set the umask to 0600, |
| 302 | * we don't set the global variable filename to it's name, and don't |
| 303 | * print out how many lines we wrote on the statusbar. |
| 304 | * |
Chris Allegretta | 3dbb278 | 2000-12-02 04:36:50 +0000 | [diff] [blame] | 305 | * tmp means we are writing a tmp file in a secute fashion. We use |
| 306 | * it when spell checking or dumping the file on an error. |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 307 | */ |
| 308 | int write_file(char *name, int tmp) |
| 309 | { |
| 310 | long size, lineswritten = 0; |
Chris Allegretta | 1a6e904 | 2000-12-14 13:56:28 +0000 | [diff] [blame] | 311 | static char *buf = NULL; |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 312 | filestruct *fileptr; |
Chris Allegretta | 07f9ee0 | 2000-12-04 05:15:39 +0000 | [diff] [blame] | 313 | int fd, mask = 0, realexists, anyexists; |
Chris Allegretta | 7960dcf | 2000-12-13 15:01:29 +0000 | [diff] [blame] | 314 | struct stat st, lst; |
Chris Allegretta | 0f5dfef | 2000-11-24 14:02:57 +0000 | [diff] [blame] | 315 | static char *realname = NULL; |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 316 | |
| 317 | if (!strcmp(name, "")) { |
| 318 | statusbar(_("Cancelled")); |
| 319 | return -1; |
| 320 | } |
| 321 | titlebar(); |
| 322 | fileptr = fileage; |
Chris Allegretta | 0f5dfef | 2000-11-24 14:02:57 +0000 | [diff] [blame] | 323 | |
| 324 | if (realname != NULL) |
| 325 | free(realname); |
| 326 | |
Chris Allegretta | 1a6e904 | 2000-12-14 13:56:28 +0000 | [diff] [blame] | 327 | if (buf != NULL) |
| 328 | free(buf); |
| 329 | |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 330 | #ifndef DISABLE_TABCOMP |
| 331 | realname = real_dir_from_tilde(name); |
| 332 | #else |
| 333 | realname = mallocstrcpy(realname, name); |
| 334 | #endif |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 335 | |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 336 | /* Save the state of file at the end of the symlink (if there is one) */ |
Chris Allegretta | f7ee9e6 | 2000-12-02 21:13:50 +0000 | [diff] [blame] | 337 | realexists = stat(realname, &st); |
| 338 | |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 339 | /* Stat the link itself for the check... */ |
| 340 | anyexists = lstat(realname, &lst); |
Chris Allegretta | acb6234 | 2000-07-21 22:42:46 +0000 | [diff] [blame] | 341 | |
Chris Allegretta | 07f9ee0 | 2000-12-04 05:15:39 +0000 | [diff] [blame] | 342 | /* New case: if the file exists, just give up */ |
| 343 | if (tmp && anyexists != -1) |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 344 | return -1; |
Chris Allegretta | b5bb24c | 2000-12-06 00:57:54 +0000 | [diff] [blame] | 345 | /* NOTE: If you change this statement, you MUST CHANGE the if |
Chris Allegretta | 544d9b0 | 2000-12-11 02:47:13 +0000 | [diff] [blame] | 346 | statement below (that says: |
| 347 | if (realexists == -1 || tmp || (!ISSET(FOLLOW_SYMLINKS) && |
| 348 | S_ISLNK(lst.st_mode))) { |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 349 | to reflect whether or not to link/unlink/rename the file */ |
| 350 | else if (ISSET(FOLLOW_SYMLINKS) || !S_ISLNK(lst.st_mode) || tmp) { |
Chris Allegretta | 3308439 | 2000-12-09 22:50:38 +0000 | [diff] [blame] | 351 | /* Use O_EXCL if tmp == 1. This is now copied from joe, because |
Chris Allegretta | f597777 | 2000-12-09 23:58:41 +0000 | [diff] [blame] | 352 | wiggy says so *shrug*. */ |
| 353 | if (tmp) |
| 354 | fd = open(realname, O_WRONLY | O_CREAT | O_EXCL, (S_IRUSR|S_IWUSR)); |
| 355 | else |
| 356 | fd = open(realname, O_WRONLY | O_CREAT | O_TRUNC, (S_IRUSR|S_IWUSR)); |
Chris Allegretta | 07f9ee0 | 2000-12-04 05:15:39 +0000 | [diff] [blame] | 357 | |
| 358 | /* First, just give up if we couldn't even open the file */ |
Chris Allegretta | 5982849 | 2000-12-04 03:31:39 +0000 | [diff] [blame] | 359 | if (fd == -1) { |
Chris Allegretta | 20c131c | 2000-12-04 04:20:09 +0000 | [diff] [blame] | 360 | if (!tmp && ISSET(TEMP_OPT)) { |
Chris Allegretta | a299b03 | 2000-07-14 02:44:02 +0000 | [diff] [blame] | 361 | UNSET(TEMP_OPT); |
| 362 | return do_writeout(1); |
| 363 | } |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 364 | statusbar(_("Could not open file for writing: %s"), |
| 365 | strerror(errno)); |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 366 | free(realname); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 367 | return -1; |
| 368 | } |
Chris Allegretta | 07f9ee0 | 2000-12-04 05:15:39 +0000 | [diff] [blame] | 369 | |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 370 | } |
| 371 | /* Don't follow symlink. Create new file. */ |
| 372 | else { |
Chris Allegretta | 1a6e904 | 2000-12-14 13:56:28 +0000 | [diff] [blame] | 373 | buf = nmalloc(strlen(realname) + 8); |
| 374 | strncpy(buf, realname, strlen(realname)+1); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 375 | strcat(buf, ".XXXXXX"); |
| 376 | if ((fd = mkstemp(buf)) == -1) { |
Chris Allegretta | a299b03 | 2000-07-14 02:44:02 +0000 | [diff] [blame] | 377 | if (ISSET(TEMP_OPT)) { |
| 378 | UNSET(TEMP_OPT); |
| 379 | return do_writeout(1); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 380 | } |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 381 | statusbar(_("Could not open file for writing: %s"), |
| 382 | strerror(errno)); |
| 383 | return -1; |
| 384 | } |
| 385 | } |
| 386 | |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 387 | dump_buffer(fileage); |
| 388 | while (fileptr != NULL && fileptr->next != NULL) { |
Robert Siemborski | 63b3d7e | 2000-07-04 22:15:39 +0000 | [diff] [blame] | 389 | /* Next line is so we discount the "magic line" */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 390 | if (filebot == fileptr && fileptr->data[0] == '\0') |
| 391 | break; |
Robert Siemborski | 63b3d7e | 2000-07-04 22:15:39 +0000 | [diff] [blame] | 392 | |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 393 | size = write(fd, fileptr->data, strlen(fileptr->data)); |
| 394 | if (size == -1) { |
| 395 | statusbar(_("Could not open file for writing: %s"), |
| 396 | strerror(errno)); |
| 397 | return -1; |
| 398 | } else { |
| 399 | #ifdef DEBUG |
| 400 | fprintf(stderr, _("Wrote >%s\n"), fileptr->data); |
| 401 | #endif |
| 402 | } |
| 403 | write(fd, "\n", 1); |
| 404 | |
| 405 | fileptr = fileptr->next; |
| 406 | lineswritten++; |
| 407 | } |
| 408 | |
| 409 | if (fileptr != NULL) { |
| 410 | size = write(fd, fileptr->data, strlen(fileptr->data)); |
| 411 | if (size == -1) { |
| 412 | statusbar(_("Could not open file for writing: %s"), |
| 413 | strerror(errno)); |
| 414 | return -1; |
| 415 | } else if (size > 0) { |
| 416 | size = write(fd, "\n", 1); |
| 417 | if (size == -1) { |
| 418 | statusbar(_("Could not open file for writing: %s"), |
| 419 | strerror(errno)); |
| 420 | return -1; |
| 421 | } |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | |
| 426 | if (close(fd) == -1) { |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 427 | statusbar(_("Could not close %s: %s"), realname, strerror(errno)); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 428 | unlink(buf); |
| 429 | return -1; |
| 430 | } |
| 431 | |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 432 | if (realexists == -1 || tmp || |
| 433 | (!ISSET(FOLLOW_SYMLINKS) && S_ISLNK(lst.st_mode))) { |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 434 | |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 435 | /* Use default umask as file permisions if file is a new file. */ |
| 436 | mask = umask(0); |
| 437 | umask(mask); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 438 | |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 439 | if (tmp) /* We don't want anyone reading our temporary file! */ |
| 440 | mask = 0600; |
| 441 | else |
| 442 | mask = 0666 & ~mask; |
| 443 | } else |
Chris Allegretta | da13f0b | 2000-12-06 05:59:31 +0000 | [diff] [blame] | 444 | /* Use permissions from file we are overwriting. */ |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 445 | mask = st.st_mode; |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 446 | |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 447 | if (!tmp && (!ISSET(FOLLOW_SYMLINKS) && S_ISLNK(lst.st_mode))) { |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 448 | if (unlink(realname) == -1) { |
| 449 | if (errno != ENOENT) { |
Chris Allegretta | f7ee9e6 | 2000-12-02 21:13:50 +0000 | [diff] [blame] | 450 | statusbar(_("Could not open %s for writing: %s"), |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 451 | realname, strerror(errno)); |
Chris Allegretta | f7ee9e6 | 2000-12-02 21:13:50 +0000 | [diff] [blame] | 452 | unlink(buf); |
| 453 | return -1; |
| 454 | } |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 455 | } |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 456 | if (link(buf, realname) != -1) |
| 457 | unlink(buf); |
| 458 | else if (errno != EPERM) { |
| 459 | statusbar(_("Could not open %s for writing: %s"), |
| 460 | name, strerror(errno)); |
| 461 | unlink(buf); |
| 462 | return -1; |
| 463 | } else if (rename(buf, realname) == -1) { /* Try a rename?? */ |
| 464 | statusbar(_("Could not open %s for writing: %s"), |
| 465 | realname, strerror(errno)); |
| 466 | unlink(buf); |
| 467 | return -1; |
| 468 | } |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 469 | } |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 470 | if (chmod(realname, mask) == -1) |
| 471 | statusbar(_("Could not set permissions %o on %s: %s"), |
| 472 | mask, realname, strerror(errno)); |
| 473 | |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 474 | if (!tmp) { |
Chris Allegretta | 1a6e904 | 2000-12-14 13:56:28 +0000 | [diff] [blame] | 475 | filename = mallocstrcpy(filename, realname); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 476 | statusbar(_("Wrote %d lines"), lineswritten); |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 477 | UNSET(MODIFIED); |
| 478 | titlebar(); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 479 | } |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 480 | return 1; |
| 481 | } |
| 482 | |
| 483 | int do_writeout(int exiting) |
| 484 | { |
| 485 | int i = 0; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 486 | #ifdef NANO_EXTRA |
| 487 | static int did_cred = 0; |
| 488 | #endif |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 489 | |
Chris Allegretta | 92d2bab | 2000-11-02 14:53:46 +0000 | [diff] [blame] | 490 | answer = mallocstrcpy(answer, filename); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 491 | |
Chris Allegretta | 962c3c9 | 2000-07-24 21:52:17 +0000 | [diff] [blame] | 492 | if ((exiting) && (ISSET(TEMP_OPT))) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 493 | if (filename[0]) { |
Chris Allegretta | 962c3c9 | 2000-07-24 21:52:17 +0000 | [diff] [blame] | 494 | i = write_file(answer, 0); |
| 495 | display_main_list(); |
| 496 | return i; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 497 | } else { |
Chris Allegretta | 461b2a9 | 2000-07-24 22:05:18 +0000 | [diff] [blame] | 498 | UNSET(TEMP_OPT); |
| 499 | do_exit(); |
| 500 | |
| 501 | /* They cancelled, abort quit */ |
| 502 | return -1; |
Chris Allegretta | 962c3c9 | 2000-07-24 21:52:17 +0000 | [diff] [blame] | 503 | } |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | while (1) { |
Chris Allegretta | 7da4e9f | 2000-11-06 02:57:22 +0000 | [diff] [blame] | 507 | i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer, |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 508 | _("File Name to write")); |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 509 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 510 | if (i != -1) { |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 511 | |
| 512 | #ifdef DEBUG |
| 513 | fprintf(stderr, _("filename is %s"), answer); |
| 514 | #endif |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 515 | |
| 516 | #ifdef NANO_EXTRA |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 517 | if (exiting && !ISSET(TEMP_OPT) && !strcasecmp(answer, "zzy") |
| 518 | && !did_cred) { |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 519 | do_credits(); |
| 520 | did_cred = 1; |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 521 | return -1; |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 522 | } |
| 523 | #endif |
Chris Allegretta | 92d2bab | 2000-11-02 14:53:46 +0000 | [diff] [blame] | 524 | if (strcmp(answer, filename)) { |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 525 | struct stat st; |
| 526 | if (!stat(answer, &st)) { |
| 527 | i = do_yesno(0, 0, _("File exists, OVERWRITE ?")); |
| 528 | |
| 529 | if (!i || (i == -1)) |
| 530 | continue; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 531 | } |
| 532 | } |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 533 | i = write_file(answer, 0); |
| 534 | |
| 535 | display_main_list(); |
| 536 | return i; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 537 | } else { |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 538 | statusbar(_("Cancelled")); |
| 539 | display_main_list(); |
| 540 | return 0; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 541 | } |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
| 545 | int do_writeout_void(void) |
| 546 | { |
| 547 | return do_writeout(0); |
| 548 | } |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 549 | |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 550 | #ifndef DISABLE_TABCOMP |
| 551 | static char **homedirs; |
| 552 | |
| 553 | /* Return a malloc()ed string containing the actual directory, used |
| 554 | * to convert ~user and ~/ notation... |
| 555 | */ |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 556 | char *real_dir_from_tilde(char *buf) |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 557 | { |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 558 | char *dirtmp = NULL, *line = NULL, byte[1], *lineptr; |
| 559 | int fd, i, status, searchctr = 1; |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 560 | |
| 561 | if (buf[0] == '~') { |
Chris Allegretta | 2773184 | 2000-11-28 05:53:41 +0000 | [diff] [blame] | 562 | if (buf[1] == '~') |
| 563 | goto abort; /* Handle ~~ without segfaulting =) */ |
| 564 | else if (buf[1] == '/') { |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 565 | if (getenv("HOME") != NULL) { |
| 566 | dirtmp = nmalloc(strlen(buf) + 2 + strlen(getenv("HOME"))); |
| 567 | |
| 568 | sprintf(dirtmp, "%s/%s", getenv("HOME"), &buf[2]); |
| 569 | } |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 570 | } else if (buf[1] != 0) { |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 571 | |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 572 | if ((fd = open("/etc/passwd", O_RDONLY)) == -1) |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 573 | goto abort; |
| 574 | |
| 575 | /* Figure how how much of of the str we need to compare */ |
| 576 | for (searchctr = 1; buf[searchctr] != '/' && |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 577 | buf[searchctr] != 0; searchctr++); |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 578 | |
| 579 | do { |
| 580 | i = 0; |
| 581 | line = nmalloc(1); |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 582 | while ((status = read(fd, byte, 1)) != 0 |
| 583 | && byte[0] != '\n') { |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 584 | |
| 585 | line[i] = byte[0]; |
| 586 | i++; |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 587 | line = nrealloc(line, i + 1); |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 588 | } |
| 589 | line[i] = 0; |
| 590 | |
| 591 | if (i == 0) |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 592 | goto abort; |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 593 | |
| 594 | line[i] = 0; |
| 595 | lineptr = strtok(line, ":"); |
| 596 | |
| 597 | if (!strncmp(lineptr, &buf[1], searchctr - 1)) { |
| 598 | |
| 599 | /* Okay, skip to the password portion now */ |
| 600 | for (i = 0; i <= 4 && lineptr != NULL; i++) |
| 601 | lineptr = strtok(NULL, ":"); |
| 602 | |
| 603 | if (lineptr == NULL) |
| 604 | goto abort; |
| 605 | |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 606 | /* Else copy the new string into the new buf */ |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 607 | dirtmp = nmalloc(strlen(buf) + 2 + strlen(lineptr)); |
| 608 | |
| 609 | sprintf(dirtmp, "%s%s", lineptr, &buf[searchctr]); |
| 610 | free(line); |
| 611 | break; |
| 612 | } |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 613 | |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 614 | free(line); |
| 615 | |
| 616 | } while (status != 0); |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 617 | } |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 618 | } else |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 619 | dirtmp = mallocstrcpy(dirtmp, buf); |
| 620 | |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 621 | return dirtmp; |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 622 | |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 623 | abort: |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 624 | dirtmp = mallocstrcpy(dirtmp, buf); |
| 625 | return dirtmp; |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | /* Tack a slash onto the string we're completing if it's a directory */ |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 629 | int append_slash_if_dir(char *buf, int *lastWasTab, int *place) |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 630 | { |
| 631 | char *dirptr; |
| 632 | struct stat fileinfo; |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 633 | int ret = 0; |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 634 | |
| 635 | dirptr = real_dir_from_tilde(buf); |
| 636 | |
| 637 | if (stat(dirptr, &fileinfo) == -1) |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 638 | ret = 0; |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 639 | else if (S_ISDIR(fileinfo.st_mode)) { |
| 640 | strncat(buf, "/", 1); |
| 641 | *place += 1; |
| 642 | /* now we start over again with # of tabs so far */ |
| 643 | *lastWasTab = 0; |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 644 | ret = 1; |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | if (dirptr != buf) |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 648 | free(dirptr); |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 649 | |
| 650 | return ret; |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 651 | } |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 652 | |
| 653 | /* |
| 654 | * These functions (username_tab_completion, cwd_tab_completion, and |
| 655 | * input_tab were taken from busybox 0.46 (cmdedit.c). Here is the notice |
| 656 | * from that file: |
| 657 | * |
| 658 | * Termios command line History and Editting, originally |
| 659 | * intended for NetBSD sh (ash) |
| 660 | * Copyright (c) 1999 |
| 661 | * Main code: Adam Rogoyski <rogoyski@cs.utexas.edu> |
| 662 | * Etc: Dave Cinege <dcinege@psychosis.com> |
| 663 | * Majorly adjusted/re-written for busybox: |
| 664 | * Erik Andersen <andersee@debian.org> |
| 665 | * |
| 666 | * You may use this code as you wish, so long as the original author(s) |
| 667 | * are attributed in any redistributions of the source code. |
| 668 | * This code is 'as is' with no warranty. |
| 669 | * This code may safely be consumed by a BSD or GPL license. |
| 670 | */ |
| 671 | |
| 672 | char **username_tab_completion(char *buf, int *num_matches) |
| 673 | { |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 674 | char **matches = (char **) NULL, *line = NULL, *lineptr; |
| 675 | char *matchline = NULL, *matchdir = NULL; |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 676 | |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 677 | int fd, i = 0, status = 1; |
| 678 | char byte[1]; |
| 679 | |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 680 | if ((fd = open("/etc/passwd", O_RDONLY)) == -1) { |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 681 | return NULL; |
| 682 | } |
| 683 | |
| 684 | if (homedirs != NULL) { |
| 685 | for (i = 0; i < *num_matches; i++) |
| 686 | free(homedirs[i]); |
| 687 | free(homedirs); |
| 688 | homedirs = (char **) NULL; |
| 689 | *num_matches = 0; |
| 690 | } |
| 691 | matches = nmalloc(BUFSIZ); |
| 692 | homedirs = nmalloc(BUFSIZ); |
| 693 | strcat(buf, "*"); |
| 694 | do { |
| 695 | i = 0; |
| 696 | line = nmalloc(1); |
| 697 | while ((status = read(fd, byte, 1)) != 0 && byte[0] != '\n') { |
| 698 | |
| 699 | line[i] = byte[0]; |
| 700 | i++; |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 701 | line = nrealloc(line, i + 1); |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | if (i == 0) |
| 705 | break; |
| 706 | |
| 707 | line[i] = 0; |
| 708 | lineptr = strtok(line, ":"); |
| 709 | |
| 710 | if (check_wildcard_match(line, &buf[1]) == TRUE) { |
| 711 | |
| 712 | if (*num_matches == BUFSIZ) |
| 713 | break; |
| 714 | |
| 715 | /* Cool, found a match. Add it to the list |
| 716 | * This makes a lot more sense to me (Chris) this way... |
| 717 | */ |
| 718 | matchline = nmalloc(strlen(line) + 2); |
| 719 | sprintf(matchline, "~%s", line); |
| 720 | |
| 721 | for (i = 0; i <= 4 && lineptr != NULL; i++) |
| 722 | lineptr = strtok(NULL, ":"); |
| 723 | |
| 724 | if (lineptr == NULL) |
| 725 | break; |
| 726 | |
| 727 | matchdir = mallocstrcpy(matchdir, lineptr); |
| 728 | homedirs[*num_matches] = matchdir; |
| 729 | matches[*num_matches] = matchline; |
| 730 | |
| 731 | ++*num_matches; |
| 732 | |
| 733 | /* If there's no more room, bail out */ |
| 734 | if (*num_matches == BUFSIZ) |
| 735 | break; |
| 736 | } |
| 737 | |
| 738 | free(line); |
| 739 | |
| 740 | } while (status != 0); |
| 741 | |
| 742 | close(fd); |
| 743 | return matches; |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 744 | #ifdef DEBUG |
| 745 | fprintf(stderr, "\nin username_tab_completion\n"); |
| 746 | #endif |
| 747 | return (matches); |
| 748 | } |
| 749 | |
| 750 | /* This was originally called exe_n_cwd_tab_completion, but we're not |
| 751 | worried about executables, only filenames :> */ |
| 752 | |
| 753 | char **cwd_tab_completion(char *buf, int *num_matches) |
| 754 | { |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 755 | char *dirName, *dirtmp = NULL, *tmp = NULL, *tmp2 = NULL; |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 756 | char **matches = (char **) NULL; |
| 757 | DIR *dir; |
| 758 | struct dirent *next; |
| 759 | |
Chris Allegretta | 2c97522 | 2000-11-15 01:25:42 +0000 | [diff] [blame] | 760 | matches = nmalloc(BUFSIZ); |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 761 | |
| 762 | /* Stick a wildcard onto the buf, for later use */ |
| 763 | strcat(buf, "*"); |
| 764 | |
Chris Allegretta | 2c97522 | 2000-11-15 01:25:42 +0000 | [diff] [blame] | 765 | /* Okie, if there's a / in the buffer, strip out the directory part */ |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 766 | if (strcmp(buf, "") && strstr(buf, "/")) { |
| 767 | dirName = malloc(strlen(buf) + 1); |
| 768 | tmp = buf + strlen(buf); |
| 769 | while (*tmp != '/' && tmp != buf) |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 770 | tmp--; |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 771 | |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 772 | tmp++; |
| 773 | |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 774 | strncpy(dirName, buf, tmp - buf + 1); |
| 775 | dirName[tmp - buf] = 0; |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 776 | |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 777 | } else { |
| 778 | if ((dirName = getcwd(NULL, 0)) == NULL) |
| 779 | return matches; |
| 780 | else |
| 781 | tmp = buf; |
| 782 | } |
| 783 | |
| 784 | #ifdef DEBUG |
| 785 | fprintf(stderr, "\nDir = %s\n", dirName); |
| 786 | fprintf(stderr, "\nbuf = %s\n", buf); |
| 787 | fprintf(stderr, "\ntmp = %s\n", tmp); |
| 788 | #endif |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 789 | |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 790 | dirtmp = real_dir_from_tilde(dirName); |
| 791 | free(dirName); |
| 792 | dirName = dirtmp; |
| 793 | |
| 794 | #ifdef DEBUG |
| 795 | fprintf(stderr, "\nDir = %s\n", dirName); |
| 796 | fprintf(stderr, "\nbuf = %s\n", buf); |
| 797 | fprintf(stderr, "\ntmp = %s\n", tmp); |
| 798 | #endif |
| 799 | |
| 800 | |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 801 | dir = opendir(dirName); |
| 802 | if (!dir) { |
| 803 | /* Don't print an error, just shut up and return */ |
| 804 | *num_matches = 0; |
| 805 | beep(); |
| 806 | return (matches); |
| 807 | } |
| 808 | while ((next = readdir(dir)) != NULL) { |
| 809 | |
| 810 | /* Some quick sanity checks */ |
| 811 | if ((strcmp(next->d_name, "..") == 0) |
| 812 | || (strcmp(next->d_name, ".") == 0)) { |
| 813 | continue; |
| 814 | } |
| 815 | #ifdef DEBUG |
Chris Allegretta | 2c97522 | 2000-11-15 01:25:42 +0000 | [diff] [blame] | 816 | fprintf(stderr, "Comparing \'%s\'\n", next->d_name); |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 817 | #endif |
| 818 | /* See if this matches */ |
| 819 | if (check_wildcard_match(next->d_name, tmp) == TRUE) { |
Chris Allegretta | 7d97ce7 | 2000-11-06 04:04:15 +0000 | [diff] [blame] | 820 | |
| 821 | /* Cool, found a match. Add it to the list |
| 822 | * This makes a lot more sense to me (Chris) this way... |
| 823 | */ |
| 824 | tmp2 = NULL; |
| 825 | tmp2 = nmalloc(strlen(next->d_name) + 1); |
| 826 | strcpy(tmp2, next->d_name); |
| 827 | matches[*num_matches] = tmp2; |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 828 | ++*num_matches; |
Chris Allegretta | 2c97522 | 2000-11-15 01:25:42 +0000 | [diff] [blame] | 829 | |
| 830 | /* If there's no more room, bail out */ |
| 831 | if (*num_matches == BUFSIZ) |
| 832 | break; |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | |
| 836 | return (matches); |
| 837 | } |
| 838 | |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 839 | /* This function now has an arg which refers to how much the |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 840 | * statusbar (place) should be advanced, i.e. the new cursor pos. |
| 841 | */ |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 842 | char *input_tab(char *buf, int place, int *lastWasTab, int *newplace) |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 843 | { |
| 844 | /* Do TAB completion */ |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 845 | static int num_matches = 0, match_matches = 0; |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 846 | static char **matches = (char **) NULL; |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 847 | int pos = place, i = 0, col = 0, editline = 0; |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 848 | int longestname = 0, is_dir = 0; |
Chris Allegretta | 3b0d144 | 2000-11-05 21:56:54 +0000 | [diff] [blame] | 849 | char *foo; |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 850 | |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 851 | if (*lastWasTab == FALSE) { |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 852 | char *tmp, *copyto, *matchBuf; |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 853 | |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 854 | *lastWasTab = 1; |
| 855 | |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 856 | /* Make a local copy of the string -- up to the position of the |
| 857 | cursor */ |
Chris Allegretta | e118acc | 2000-11-06 05:40:03 +0000 | [diff] [blame] | 858 | matchBuf = (char *) calloc(strlen(buf) + 2, sizeof(char)); |
| 859 | |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 860 | strncpy(matchBuf, buf, place); |
| 861 | tmp = matchBuf; |
| 862 | |
| 863 | /* skip any leading white space */ |
Chris Allegretta | 63a89d3 | 2000-11-18 03:05:50 +0000 | [diff] [blame] | 864 | while (*tmp && isspace((int) *tmp)) |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 865 | ++tmp; |
| 866 | |
| 867 | /* Free up any memory already allocated */ |
| 868 | if (matches != NULL) { |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 869 | for (i = i; i < num_matches; i++) |
| 870 | free(matches[i]); |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 871 | free(matches); |
| 872 | matches = (char **) NULL; |
Chris Allegretta | 7d97ce7 | 2000-11-06 04:04:15 +0000 | [diff] [blame] | 873 | num_matches = 0; |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | /* If the word starts with `~' and there is no slash in the word, |
| 877 | * then try completing this word as a username. */ |
| 878 | |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 879 | /* FIXME -- this check is broken! */ |
Chris Allegretta | 1bd0ce2 | 2000-12-06 05:56:08 +0000 | [diff] [blame] | 880 | if (*tmp == '~' && !strchr(tmp, '/')) |
| 881 | matches = username_tab_completion(tmp, &num_matches); |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 882 | |
| 883 | /* Try to match everything in the current working directory that |
| 884 | * matches. */ |
| 885 | if (!matches) |
| 886 | matches = cwd_tab_completion(tmp, &num_matches); |
| 887 | |
| 888 | /* Don't leak memory */ |
| 889 | free(matchBuf); |
| 890 | |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 891 | #ifdef DEBUG |
| 892 | fprintf(stderr, "%d matches found...\n", num_matches); |
| 893 | #endif |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 894 | /* Did we find exactly one match? */ |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 895 | switch (num_matches) { |
Chris Allegretta | e118acc | 2000-11-06 05:40:03 +0000 | [diff] [blame] | 896 | case 0: |
Chris Allegretta | 2434243 | 2000-11-06 05:41:20 +0000 | [diff] [blame] | 897 | blank_edit(); |
Chris Allegretta | 2c97522 | 2000-11-15 01:25:42 +0000 | [diff] [blame] | 898 | wrefresh(edit); |
Chris Allegretta | e118acc | 2000-11-06 05:40:03 +0000 | [diff] [blame] | 899 | break; |
| 900 | case 1: |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 901 | |
| 902 | buf = nrealloc(buf, strlen(buf) + strlen(matches[0]) + 1); |
| 903 | |
| 904 | if (strcmp(buf, "") && strstr(buf, "/")) { |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 905 | for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf; |
| 906 | tmp--); |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 907 | tmp++; |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 908 | } else |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 909 | tmp = buf; |
| 910 | |
Chris Allegretta | 04fec91 | 2000-11-25 04:43:43 +0000 | [diff] [blame] | 911 | if (!strcmp(tmp, matches[0])) |
| 912 | is_dir = append_slash_if_dir(buf, lastWasTab, newplace); |
| 913 | |
| 914 | if (is_dir) |
| 915 | break; |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 916 | |
| 917 | copyto = tmp; |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 918 | for (pos = 0; *tmp == matches[0][pos] && |
| 919 | pos <= strlen(matches[0]); pos++) |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 920 | tmp++; |
| 921 | |
Chris Allegretta | 2c97522 | 2000-11-15 01:25:42 +0000 | [diff] [blame] | 922 | /* write out the matched name */ |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 923 | strncpy(copyto, matches[0], strlen(matches[0]) + 1); |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 924 | *newplace += strlen(matches[0]) - pos; |
| 925 | |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 926 | /* Is it a directory? */ |
| 927 | append_slash_if_dir(buf, lastWasTab, newplace); |
| 928 | |
Chris Allegretta | e118acc | 2000-11-06 05:40:03 +0000 | [diff] [blame] | 929 | break; |
| 930 | default: |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 931 | /* Check to see if all matches share a beginning, and if so |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 932 | tack it onto buf and then beep */ |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 933 | |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 934 | if (strcmp(buf, "") && strstr(buf, "/")) { |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 935 | for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf; |
| 936 | tmp--); |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 937 | tmp++; |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 938 | } else |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 939 | tmp = buf; |
| 940 | |
| 941 | for (pos = 0; *tmp == matches[0][pos] && *tmp != 0 && |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 942 | pos <= strlen(matches[0]); pos++) |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 943 | tmp++; |
| 944 | |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 945 | while (1) { |
| 946 | match_matches = 0; |
| 947 | |
| 948 | for (i = 0; i < num_matches; i++) { |
| 949 | if (matches[i][pos] == 0) |
| 950 | break; |
| 951 | else if (matches[i][pos] == matches[0][pos]) |
| 952 | match_matches++; |
| 953 | } |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 954 | if (match_matches == num_matches && |
| 955 | (i == num_matches || matches[i] != 0)) { |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 956 | /* All the matches have the same character at pos+1, |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 957 | so paste it into buf... */ |
Chris Allegretta | 7586495 | 2000-11-05 22:48:35 +0000 | [diff] [blame] | 958 | buf = nrealloc(buf, strlen(buf) + 2); |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 959 | strncat(buf, matches[0] + pos, 1); |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 960 | *newplace += 1; |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 961 | pos++; |
Chris Allegretta | 7586495 | 2000-11-05 22:48:35 +0000 | [diff] [blame] | 962 | } else { |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 963 | beep(); |
| 964 | break; |
| 965 | } |
| 966 | } |
Chris Allegretta | e118acc | 2000-11-06 05:40:03 +0000 | [diff] [blame] | 967 | break; |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 968 | } |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 969 | } else { |
| 970 | /* Ok -- the last char was a TAB. Since they |
| 971 | * just hit TAB again, print a list of all the |
| 972 | * available choices... */ |
| 973 | if (matches && num_matches > 0) { |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 974 | |
| 975 | /* Blank the edit window, and print the matches out there */ |
| 976 | blank_edit(); |
| 977 | wmove(edit, 0, 0); |
| 978 | |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 979 | editline = 0; |
Chris Allegretta | 2c97522 | 2000-11-15 01:25:42 +0000 | [diff] [blame] | 980 | |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 981 | /* Figure out the length of the longest filename */ |
| 982 | for (i = 0; i < num_matches; i++) |
| 983 | if (strlen(matches[i]) > longestname) |
| 984 | longestname = strlen(matches[i]); |
| 985 | |
| 986 | if (longestname > COLS - 1) |
| 987 | longestname = COLS - 1; |
| 988 | |
Chris Allegretta | 3b0d144 | 2000-11-05 21:56:54 +0000 | [diff] [blame] | 989 | foo = nmalloc(longestname + 5); |
| 990 | |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 991 | /* Print the list of matches */ |
| 992 | for (i = 0, col = 0; i < num_matches; i++) { |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 993 | |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 994 | /* make each filename shown be the same length as the longest |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 995 | filename, with two spaces at the end */ |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 996 | snprintf(foo, longestname + 1, matches[i]); |
| 997 | while (strlen(foo) < longestname) |
| 998 | strcat(foo, " "); |
| 999 | |
| 1000 | strcat(foo, " "); |
| 1001 | |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 1002 | /* Disable el cursor */ |
| 1003 | curs_set(0); |
Chris Allegretta | 7586495 | 2000-11-05 22:48:35 +0000 | [diff] [blame] | 1004 | /* now, put the match on the screen */ |
| 1005 | waddnstr(edit, foo, strlen(foo)); |
| 1006 | col += strlen(foo); |
| 1007 | |
| 1008 | /* And if the next match isn't going to fit on the |
| 1009 | line, move to the next one */ |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 1010 | if (col > (COLS - longestname) && matches[i + 1] != NULL) { |
Chris Allegretta | ec58a99 | 2000-11-05 21:54:23 +0000 | [diff] [blame] | 1011 | editline++; |
| 1012 | wmove(edit, editline, 0); |
Chris Allegretta | b5b89ae | 2000-11-14 18:25:26 +0000 | [diff] [blame] | 1013 | if (editline == editwinrows - 1) { |
| 1014 | waddstr(edit, _("(more)")); |
| 1015 | break; |
| 1016 | } |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 1017 | col = 0; |
| 1018 | } |
| 1019 | } |
Chris Allegretta | 3b0d144 | 2000-11-05 21:56:54 +0000 | [diff] [blame] | 1020 | free(foo); |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 1021 | wrefresh(edit); |
Chris Allegretta | 24dd8d6 | 2000-11-06 05:45:48 +0000 | [diff] [blame] | 1022 | } else |
| 1023 | beep(); |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 1024 | |
| 1025 | } |
| 1026 | |
| 1027 | edit_refresh(); |
Chris Allegretta | 442f2c5 | 2000-11-14 17:46:06 +0000 | [diff] [blame] | 1028 | curs_set(1); |
| 1029 | return buf; |
Chris Allegretta | 04d848e | 2000-11-05 17:54:41 +0000 | [diff] [blame] | 1030 | } |
Chris Allegretta | be77c61 | 2000-11-24 14:00:16 +0000 | [diff] [blame] | 1031 | #endif |