gap.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /* gap.c, Ait, BSD 3-Clause, Kevin Bloom, 2023-2024,
  2. Derived from: Atto January 2017
  3. Derived from: Anthony's Editor January 93
  4. */
  5. #include <sys/stat.h>
  6. #include "header.h"
  7. #include "util.h"
  8. /* Enlarge gap by n chars, position of gap cannot change */
  9. int growgap(buffer_t *bp, point_t n)
  10. {
  11. char_t *new;
  12. point_t buflen, newlen, xgap, xegap;
  13. assert(bp->b_buf <= bp->b_gap);
  14. assert(bp->b_gap <= bp->b_egap);
  15. assert(bp->b_egap <= bp->b_ebuf);
  16. xgap = bp->b_gap - bp->b_buf;
  17. xegap = bp->b_egap - bp->b_buf;
  18. buflen = bp->b_ebuf - bp->b_buf;
  19. /* reduce number of reallocs by growing by a minimum amount */
  20. n = (n < MIN_GAP_EXPAND ? MIN_GAP_EXPAND : n);
  21. newlen = buflen + n * sizeof (char_t);
  22. if (buflen == 0) {
  23. if (newlen < 0 || MAX_SIZE_T < newlen)
  24. fatal("%s: Failed to allocate required memory.\n");
  25. new = (char_t*) malloc((size_t) newlen);
  26. if (new == NULL)
  27. fatal("%s: Failed to allocate required memory.\n"); /* Cannot edit a file without a buffer. */
  28. } else {
  29. if (newlen < 0 || MAX_SIZE_T < newlen) {
  30. msg("Failed to allocate required memory");
  31. return (FALSE);
  32. }
  33. new = (char_t*) realloc(bp->b_buf, (size_t) newlen);
  34. if (new == NULL) {
  35. msg("Failed to allocate required memory"); /* Report non-fatal error. */
  36. return (FALSE);
  37. }
  38. }
  39. /* Relocate pointers in new buffer and append the new
  40. * extension to the end of the gap.
  41. */
  42. bp->b_buf = new;
  43. bp->b_gap = bp->b_buf + xgap;
  44. bp->b_ebuf = bp->b_buf + buflen;
  45. bp->b_egap = bp->b_buf + newlen;
  46. while (xegap < buflen--)
  47. *--bp->b_egap = *--bp->b_ebuf;
  48. bp->b_ebuf = bp->b_buf + newlen;
  49. assert(bp->b_buf < bp->b_ebuf); /* Buffer must exist. */
  50. assert(bp->b_buf <= bp->b_gap);
  51. assert(bp->b_gap < bp->b_egap); /* Gap must grow only. */
  52. assert(bp->b_egap <= bp->b_ebuf);
  53. return (TRUE);
  54. }
  55. point_t movegap(buffer_t *bp, point_t offset)
  56. {
  57. char_t *p = ptr(bp, offset);
  58. while (p < bp->b_gap)
  59. *--bp->b_egap = *--bp->b_gap;
  60. while (bp->b_egap < p)
  61. *bp->b_gap++ = *bp->b_egap++;
  62. assert(bp->b_gap <= bp->b_egap);
  63. assert(bp->b_buf <= bp->b_gap);
  64. assert(bp->b_egap <= bp->b_ebuf);
  65. return (pos(bp, bp->b_egap));
  66. }
  67. /* Given a buffer offset, convert it to a pointer into the buffer */
  68. char_t * ptr(buffer_t *bp, register point_t offset)
  69. {
  70. if (offset < 0)
  71. return (bp->b_buf);
  72. return (bp->b_buf+offset + (bp->b_buf + offset < bp->b_gap ? 0 : bp->b_egap-bp->b_gap));
  73. }
  74. /* Given a pointer into the buffer, convert it to a buffer offset */
  75. point_t pos(buffer_t *bp, register char_t *cp)
  76. {
  77. assert(bp->b_buf <= cp && cp <= bp->b_ebuf);
  78. return (cp - bp->b_buf - (cp < bp->b_egap ? 0 : bp->b_egap - bp->b_gap));
  79. }
  80. int posix_file(char *fn)
  81. {
  82. if (fn[0] == '_')
  83. return (FALSE);
  84. for (; *fn != '\0'; ++fn) {
  85. if (!isalnum(*fn) && *fn != '.' && *fn != '_' && *fn != '-' && *fn != '/')
  86. return (FALSE);
  87. }
  88. return (TRUE);
  89. }
  90. void relocate_backup(char *fp)
  91. {
  92. char ltemp[PATH_MAX+2];
  93. strcpy(ltemp, fp);
  94. replace_all(ltemp, '/', '!');
  95. strcpy(fp, BACKUP_DIR);
  96. strcat(fp, ltemp);
  97. }
  98. /*
  99. This code is heavily based on OpenBSD's mg(1)
  100. See mg's `fileio.c` file.
  101. */
  102. int backup_file(char *fn)
  103. {
  104. int orig, backup;
  105. char bfn[PATH_MAX+2];
  106. char *tname;
  107. char buf[STRBUF_L];
  108. struct stat sb;
  109. ssize_t nread;
  110. struct timespec new_times[2];
  111. sprintf(bfn, "%s~", fn);
  112. if(BACKUP_DIR != NULL)
  113. relocate_backup(bfn);
  114. /* If we can't open the original, just don't make a back up */
  115. if (stat(fn, &sb) == -1) {
  116. msg("Can't stat %s : %s", fn, strerror(errno));
  117. return TRUE;
  118. }
  119. if((orig = open(fn, O_RDONLY)) == -1) {
  120. return TRUE;
  121. }
  122. if (asprintf(&tname, "%s.XXXXXXXXXX", bfn) == -1) {
  123. msg("Can't allocate temp file name : %s", strerror(errno));
  124. return FALSE;
  125. }
  126. backup = mkstemp(tname);
  127. if(backup == -1) {
  128. msg("Failed to open backup file: \"%s\"", bfn);
  129. return FALSE;
  130. }
  131. while ((nread = read(orig, buf, sizeof(buf))) > 0) {
  132. if (write(backup, buf, (size_t)nread) != nread) {
  133. nread = -1;
  134. break;
  135. }
  136. }
  137. (void) fchmod(backup, (sb.st_mode & 0777));
  138. new_times[0] = sb.st_atim;
  139. new_times[1] = sb.st_mtim;
  140. futimens(backup, new_times);
  141. close(orig);
  142. close(backup);
  143. if (nread == -1) {
  144. if (unlink(tname) == -1)
  145. msg("Can't unlink temp : %s", strerror(errno));
  146. } else {
  147. if (rename(tname, bfn) == -1) {
  148. msg("Can't rename temp : %s", strerror(errno));
  149. (void) unlink(tname);
  150. nread = -1;
  151. }
  152. }
  153. return (nread == -1 ? FALSE : TRUE);
  154. }
  155. int save(char *fn)
  156. {
  157. FILE *fp;
  158. point_t length;
  159. struct stat sb;
  160. // if (!posix_file(fn)) {
  161. // msg("Not a portable POSIX file name.");
  162. // return (FALSE);
  163. // }
  164. stat(fn, &sb);
  165. if (!backup_file(fn)) {
  166. // msg("Failed to backup file \"%s\".", fn);
  167. return (FALSE);
  168. }
  169. fp = fopen(fn, "w");
  170. if (fp == NULL) {
  171. msg("Failed to open file \"%s\".", fn);
  172. return (FALSE);
  173. }
  174. (void) movegap(curbp, (point_t) 0);
  175. length = (point_t) (curbp->b_ebuf - curbp->b_egap);
  176. if (fwrite(curbp->b_egap, sizeof (char), (size_t) length, fp) != length) {
  177. msg("Failed to write file \"%s\".", fn);
  178. return (FALSE);
  179. }
  180. if (fclose(fp) != 0) {
  181. msg("Failed to close file \"%s\".", fn);
  182. return (FALSE);
  183. }
  184. curbp->b_flags &= ~B_MODIFIED;
  185. if (stat(fn, &sb) < 0) {
  186. msg("Failed to find file \"%s\".", fn);
  187. return (FALSE);
  188. }
  189. if (MAX_SIZE_T < sb.st_size) {
  190. msg("File \"%s\" is too big to load.", fn);
  191. return (FALSE);
  192. }
  193. curbp->b_fmtime = sb.st_mtime;
  194. msg("File \"%s\" %ld bytes saved.", fn, pos(curbp, curbp->b_ebuf));
  195. return (TRUE);
  196. }
  197. int load_file(char *fn)
  198. {
  199. /* reset the gap, make it the whole buffer */
  200. curbp->b_gap = curbp->b_buf;
  201. curbp->b_egap = curbp->b_ebuf;
  202. top();
  203. return insert_file(fn, FALSE);
  204. }
  205. /* reads file into buffer at point */
  206. int insert_file(char *fn, int modflag)
  207. {
  208. FILE *fp;
  209. size_t len;
  210. struct stat sb;
  211. if (stat(fn, &sb) < 0) {
  212. msg("Failed to find file \"%s\".", fn);
  213. return (FALSE);
  214. }
  215. if (MAX_SIZE_T < sb.st_size) {
  216. msg("File \"%s\" is too big to load.", fn);
  217. return (FALSE);
  218. }
  219. if (curbp->b_egap - curbp->b_gap < sb.st_size * sizeof (char_t) && !growgap(curbp, sb.st_size))
  220. return (FALSE);
  221. if ((fp = fopen(fn, "r")) == NULL) {
  222. msg("Failed to open file \"%s\".", fn);
  223. return (FALSE);
  224. }
  225. curbp->b_point = movegap(curbp, curbp->b_point);
  226. // undoset();
  227. curbp->b_gap += len = fread(curbp->b_gap, sizeof (char), (size_t) sb.st_size, fp);
  228. if (fclose(fp) != 0) {
  229. msg("Failed to close file \"%s\".", fn);
  230. return (FALSE);
  231. }
  232. curbp->b_flags &= (modflag ? B_MODIFIED : ~B_MODIFIED);
  233. curbp->b_fmtime = sb.st_mtime;
  234. msg("%ld bytes read.", len);
  235. return (TRUE);
  236. }
  237. /* Record a new undo */
  238. void undoset(int type, int shouldconcat)
  239. {
  240. int length = strlen((const char *)input);
  241. int ulen = 0;
  242. int npc = 0;
  243. char_t *p;
  244. undo_t *u = (undo_t *)malloc(sizeof(undo_t));
  245. assert(u != NULL);
  246. u->u_type = type;
  247. u->u_point = curbp->b_point;
  248. u->u_line = curbp->b_line;
  249. u->u_adjust = FALSE;
  250. u->u_data = NULL;
  251. switch(type) {
  252. case INSERT:
  253. if(curbp->b_undo != NULL && curbp->b_undo->u_type == INSERT && shouldconcat) {
  254. ulen = strlen((const char *)curbp->b_undo->u_data);
  255. curbp->b_undo->u_data = (char_t *)(realloc(curbp->b_undo->u_data, sizeof(char_t)*(length + ulen)+1));
  256. strncpy((char *)curbp->b_undo->u_data, (char *)curbp->b_undo->u_data, ulen);
  257. strncat((char *)curbp->b_undo->u_data, (char *)input, length);
  258. curbp->b_undo->u_data[(length + ulen)] = '\0';
  259. return;
  260. } else {
  261. u->u_data = (char_t *)(malloc(sizeof(char_t)*length+1));
  262. strncpy((char *)u->u_data, (char *)input, length);
  263. u->u_data[length] = '\0';
  264. }
  265. break;
  266. case DELETE:
  267. npc = utf8_size(*ptr(curbp,curbp->b_point));
  268. if(curbp->b_undo != NULL && curbp->b_undo->u_type == DELETE && shouldconcat) {
  269. ulen = strlen((const char *)curbp->b_undo->u_data);
  270. curbp->b_undo->u_data = (char_t *)(realloc(curbp->b_undo->u_data, sizeof(char_t)*(npc + ulen)+1));
  271. strncpy((char *)curbp->b_undo->u_data, (char *)curbp->b_undo->u_data, ulen);
  272. strncat((char *)curbp->b_undo->u_data, (const char *)ptr(curbp, curbp->b_point), npc);
  273. curbp->b_undo->u_data[npc+ulen] = '\0';
  274. return;
  275. } else {
  276. u->u_data = (char_t *)(malloc(sizeof(char_t)+npc));
  277. strncpy((char *)u->u_data, (const char *)ptr(curbp, curbp->b_point), npc);
  278. u->u_data[npc] = '\0';
  279. }
  280. break;
  281. case BACKSP:
  282. npc = prev_utf8_char_size();
  283. if(curbp->b_undo != NULL && curbp->b_undo->u_type == BACKSP && shouldconcat) {
  284. char_t *temp;
  285. curbp->b_undo->u_point -= npc;
  286. ulen = strlen((const char *)curbp->b_undo->u_data);
  287. temp = (char_t *)(malloc(sizeof(char_t)*ulen));
  288. strncpy((char *)temp, (char *)curbp->b_undo->u_data, ulen);
  289. /* if(curbp->b_undo->u_data != NULL) {
  290. free(curbp->b_undo->u_data);
  291. curbp->b_undo->u_data = NULL;
  292. } */
  293. curbp->b_undo->u_data = (char_t *)(malloc(sizeof(char_t)*(npc + ulen)+1));
  294. // memset(curbp->b_undo->u_data, 0, 1+ulen);
  295. strncpy((char *)curbp->b_undo->u_data, (const char *)ptr(curbp, curbp->b_undo->u_point), npc);
  296. strncat((char *)curbp->b_undo->u_data, (char *)temp, ulen);
  297. curbp->b_undo->u_data[(npc + ulen)] = '\0';
  298. free(temp);
  299. return;
  300. } else {
  301. u->u_point = curbp->b_point - npc;
  302. u->u_data = (char_t *)(malloc(sizeof(char_t)+npc));
  303. strncpy((char *)u->u_data, (const char *)ptr(curbp, u->u_point), npc);
  304. u->u_data[npc] = '\0';
  305. u->u_adjust = TRUE;
  306. }
  307. break;
  308. case CUT: {
  309. int bigger_mark = FALSE;
  310. if (curbp->b_point < curbp->b_mark) {
  311. (void) movegap(curbp, curbp->b_point);
  312. p = ptr(curbp, curbp->b_point);
  313. length = curbp->b_mark - curbp->b_point;
  314. bigger_mark = TRUE;
  315. u->u_adjust = TRUE;
  316. } else {
  317. (void) movegap(curbp, curbp->b_mark);
  318. p = ptr(curbp, curbp->b_mark);
  319. length = curbp->b_point - curbp->b_mark;
  320. u->u_point = curbp->b_mark;
  321. }
  322. u->u_data = (char_t*) malloc(sizeof(char_t)*length+1);
  323. (void) memcpy(u->u_data, p, length * sizeof (char_t));
  324. u->u_data[length] = '\0';
  325. /* Only adjust u_adjust if it's not a delete command, otherwise
  326. the line count will be off.
  327. */
  328. if(currentcommand != KBD_DELETE_CHAR)
  329. for(int i = 0; u->u_data[i] != '\0'; i++) {
  330. if(u->u_data[i] == '\n') {
  331. u->u_adjust = !bigger_mark;
  332. break;
  333. }
  334. }
  335. break;
  336. }
  337. case YANK:
  338. u->u_data = (char_t*) malloc(sizeof(char_t)*nscrap+1);
  339. (void) memcpy(u->u_data, scrap, nscrap * sizeof (char_t));
  340. u->u_data[nscrap] = '\0';
  341. break;
  342. case REPLACE:
  343. (void) movegap(curbp, curbp->b_point);
  344. p = ptr(curbp, curbp->b_point);
  345. length = curbp->b_mark - curbp->b_point;
  346. u->u_data = (char_t*) malloc(sizeof(char_t)*length+1);
  347. (void) memcpy(u->u_data, p, length * sizeof (char_t));
  348. u->u_data[length] = '\0';
  349. u->u_size = shouldconcat;
  350. break;
  351. case CLIPBOARD: {
  352. int ntemp = strlen(gtemp);
  353. u->u_data = (char_t*) malloc(sizeof(char_t)*ntemp+1);
  354. (void) memcpy(u->u_data, gtemp, ntemp * sizeof (char_t));
  355. u->u_data[ntemp] = '\0';
  356. break;
  357. }
  358. }
  359. u->u_next = curbp->b_undo;
  360. curbp->b_undo = u;
  361. curbp->b_redo = NULL;
  362. }
  363. /* Record a new redo if you've just undid or a undo if you've just redid. */
  364. void redo_or_undo_set(undo_t *up, int datalen, int isundo)
  365. {
  366. undo_t *rp = (undo_t *)malloc(sizeof(undo_t));
  367. char_t *p;
  368. int newlines = 0;
  369. assert(rp != NULL);
  370. rp->u_point = up->u_point;
  371. rp->u_line = up->u_line;
  372. if(up->u_adjust)
  373. for(int i = 0 ; up->u_data[i] != '\0'; i++) {
  374. if(up->u_data[i] == '\n')
  375. newlines++;
  376. }
  377. switch(up->u_type) {
  378. case INSERT:
  379. rp->u_type = DELETE;
  380. break;
  381. case BACKSP:
  382. rp->u_adjust = TRUE;
  383. rp->u_line -= newlines;
  384. case DELETE:
  385. rp->u_type = INSERT;
  386. break;
  387. case CUT:
  388. rp->u_type = YANK;
  389. rp->u_line -= newlines;
  390. break;
  391. case CLIPBOARD:
  392. case YANK:
  393. rp->u_type = CUT;
  394. rp->u_line += newlines;
  395. break;
  396. case REPLACE:
  397. rp->u_type = REPLACE;
  398. (void) movegap(curbp, up->u_point);
  399. p = ptr(curbp, up->u_point);
  400. rp->u_data = (char_t*) malloc(sizeof(char_t)*up->u_size+1);
  401. (void) memcpy(rp->u_data, p, up->u_size * sizeof (char_t));
  402. rp->u_data[up->u_size] = '\0';
  403. rp->u_size = datalen;
  404. break;
  405. }
  406. /* if(rp != NULL && rp->u_data != NULL && rp->u_type != REPLACE) {
  407. free(rp->u_data);
  408. rp->u_data = NULL;
  409. } */
  410. if(rp->u_type != REPLACE) {
  411. rp->u_data = (char_t *) calloc(datalen+1, sizeof(char_t));
  412. (void) memcpy(rp->u_data, up->u_data, datalen * sizeof (char_t));
  413. rp->u_data[datalen] = '\0';
  414. }
  415. /* if an undo was done, save to redo */
  416. if(isundo) {
  417. rp->u_next = curbp->b_redo;
  418. curbp->b_redo = rp;
  419. } else {
  420. rp->u_next = curbp->b_undo;
  421. curbp->b_undo = rp;
  422. }
  423. }
  424. /* Undo */
  425. void undo_or_redo(buffer_t *bp, undo_t *up, int isundo)
  426. {
  427. int n = 0;
  428. currentcommand = KBD_UNDO;
  429. if(up == NULL) {
  430. if(isundo)
  431. msg("Nothing to undo!");
  432. else
  433. msg("Nothing to redo!");
  434. return;
  435. }
  436. bp->b_point = up->u_point;
  437. bp->b_line = up->u_line;
  438. n = strlen((const char *)up->u_data);
  439. redo_or_undo_set(up, n, isundo);
  440. switch(up->u_type) {
  441. case INSERT:
  442. case YANK:
  443. case CLIPBOARD:
  444. (void) movegap(bp, bp->b_point);
  445. bp->b_egap += n;
  446. bp->b_point = pos(bp, bp->b_egap);
  447. break;
  448. case BACKSP:
  449. case DELETE:
  450. case CUT:
  451. bp->b_point = movegap(bp, bp->b_point);
  452. memcpy(bp->b_gap, up->u_data, n*sizeof(char_t));
  453. bp->b_gap += n;
  454. bp->b_point = pos(bp, bp->b_egap);
  455. break;
  456. case REPLACE:
  457. (void) movegap(bp, bp->b_point);
  458. bp->b_egap += up->u_size;
  459. bp->b_point = pos(bp, bp->b_egap);
  460. bp->b_point = movegap(bp, bp->b_point);
  461. memcpy(bp->b_gap, up->u_data, n*sizeof(char_t));
  462. bp->b_gap += n;
  463. bp->b_point = pos(bp, bp->b_egap);
  464. break;
  465. }
  466. if(up->u_adjust)
  467. bp->b_point = movegap(bp, up->u_point + n);
  468. else
  469. bp->b_point = movegap(bp, up->u_point);
  470. bp->b_flags |= B_MODIFIED;
  471. if(isundo)
  472. bp->b_undo = up->u_next;
  473. else
  474. bp->b_redo = up->u_next;
  475. if(curbp->b_point < curbp->b_page || curbp->b_point > curbp->b_epage)
  476. bp->b_reframe = 1;
  477. }
  478. void undo()
  479. {
  480. undo_or_redo(curbp, curbp->b_undo, TRUE);
  481. }
  482. /* Redo */
  483. void redo()
  484. {
  485. undo_or_redo(curbp, curbp->b_redo, FALSE);
  486. }
  487. /* find the point for start of line ln */
  488. point_t line_to_point(int ln)
  489. {
  490. point_t end_p = pos(curbp, curbp->b_ebuf);
  491. point_t p, start;
  492. for (p=0, start=0; p <= end_p; p++) {
  493. char_t *c = ptr(curbp, p);
  494. if(c == 0)
  495. break;
  496. if ( *c == '\n') {
  497. if (--ln == 0)
  498. return start;
  499. if (p + 1 <= end_p)
  500. start = p + 1;
  501. }
  502. if(!*c && ln == 1)
  503. return start;
  504. }
  505. return -1;
  506. }
  507. /* scan buffer and fill in curline and lastline */
  508. void get_line_stats(int *curline, int *lastline, buffer_t *bp)
  509. {
  510. point_t end_p = pos(bp, bp->b_ebuf);
  511. point_t p;
  512. int line;
  513. *curline = -1;
  514. for (p=0, line=0; p < end_p; p++) {
  515. line += (*(ptr(bp,p)) == '\n') ? 1 : 0;
  516. *lastline = line;
  517. if (*curline == -1 && p == bp->b_point) {
  518. *curline = (*(ptr(bp,p)) == '\n') ? line : line + 1;
  519. }
  520. }
  521. *lastline = *lastline + 1;
  522. if (bp->b_point == end_p)
  523. *curline = *lastline;
  524. }
  525. /* Return TRUE if file was modified after the current buffer's recored mtime. */
  526. int is_file_modified(char *fn)
  527. {
  528. struct stat sb;
  529. if(stat(fn, &sb) < 0) {
  530. return (FALSE);
  531. }
  532. if(sb.st_mtime != 0 && curbp->b_fmtime != sb.st_mtime) {
  533. return (TRUE);
  534. }
  535. return (FALSE);
  536. }
  537. /* Return TRUE to continue, FALSE to stop. Revert happens here. */
  538. int file_was_modified_prompt()
  539. {
  540. int current = 0, lastln = 0;
  541. const char *prompt = "This file has changed on disk; really edit (y/N/r) ?";
  542. char c = '\0';
  543. point_t p = curbp->b_point;
  544. struct stat sb;
  545. print_to_msgline(prompt);
  546. clrtoeol(prompt, MSGLINE);
  547. c = yesnomaybeso('n');
  548. if (c == 'n') {
  549. clrtoeol("", MSGLINE);
  550. return FALSE;
  551. } else if(c == 'r') {
  552. curbp->b_point = 0;
  553. load_file(curbp->b_fname);
  554. clrtoeol("", MSGLINE);
  555. curbp->b_point = p;
  556. get_line_stats(&current, &lastln, curbp);
  557. curbp->b_line = current;
  558. msg("Buffer reverted.");
  559. return FALSE;
  560. } else if(c == 'y') {
  561. clrtoeol("", MSGLINE);
  562. if (stat(curbp->b_fname, &sb) < 0) {
  563. msg("Failed to find file \"%s\".", curbp->b_fname);
  564. return (FALSE);
  565. }
  566. if (MAX_SIZE_T < sb.st_size) {
  567. msg("File \"%s\" is too big to load.", curbp->b_fname);
  568. return (FALSE);
  569. }
  570. curbp->b_fmtime = sb.st_mtime;
  571. return TRUE;
  572. }
  573. clrtoeol("", MSGLINE);
  574. return (FALSE);
  575. }