comparison src/mark.c @ 7827:41789f16d6b2 v7.4.1210

commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 30 18:51:09 2016 +0100 patch 7.4.1210 Problem: Using old style function declarations. Solution: Change to new style function declarations. (script by Hirohito Higashi)
author Christian Brabandt <cb@256bit.org>
date Sat, 30 Jan 2016 19:00:05 +0100
parents 37c929c4a073
children 78712a2f687a
comparison
equal deleted inserted replaced
7826:df34d45f38d4 7827:41789f16d6b2
41 /* 41 /*
42 * Set named mark "c" at current cursor position. 42 * Set named mark "c" at current cursor position.
43 * Returns OK on success, FAIL if bad name given. 43 * Returns OK on success, FAIL if bad name given.
44 */ 44 */
45 int 45 int
46 setmark(c) 46 setmark(int c)
47 int c;
48 { 47 {
49 return setmark_pos(c, &curwin->w_cursor, curbuf->b_fnum); 48 return setmark_pos(c, &curwin->w_cursor, curbuf->b_fnum);
50 } 49 }
51 50
52 /* 51 /*
53 * Set named mark "c" to position "pos". 52 * Set named mark "c" to position "pos".
54 * When "c" is upper case use file "fnum". 53 * When "c" is upper case use file "fnum".
55 * Returns OK on success, FAIL if bad name given. 54 * Returns OK on success, FAIL if bad name given.
56 */ 55 */
57 int 56 int
58 setmark_pos(c, pos, fnum) 57 setmark_pos(int c, pos_T *pos, int fnum)
59 int c;
60 pos_T *pos;
61 int fnum;
62 { 58 {
63 int i; 59 int i;
64 60
65 /* Check for a special key (may cause islower() to crash). */ 61 /* Check for a special key (may cause islower() to crash). */
66 if (c < 0) 62 if (c < 0)
136 /* 132 /*
137 * Set the previous context mark to the current position and add it to the 133 * Set the previous context mark to the current position and add it to the
138 * jump list. 134 * jump list.
139 */ 135 */
140 void 136 void
141 setpcmark() 137 setpcmark(void)
142 { 138 {
143 #ifdef FEAT_JUMPLIST 139 #ifdef FEAT_JUMPLIST
144 int i; 140 int i;
145 xfmark_T *fm; 141 xfmark_T *fm;
146 #endif 142 #endif
196 * where ever, then call checkpcmark(). This ensures that the previous 192 * where ever, then call checkpcmark(). This ensures that the previous
197 * context will only be changed if the cursor moved to a different line. 193 * context will only be changed if the cursor moved to a different line.
198 * If pcmark was deleted (with "dG") the previous mark is restored. 194 * If pcmark was deleted (with "dG") the previous mark is restored.
199 */ 195 */
200 void 196 void
201 checkpcmark() 197 checkpcmark(void)
202 { 198 {
203 if (curwin->w_prev_pcmark.lnum != 0 199 if (curwin->w_prev_pcmark.lnum != 0
204 && (equalpos(curwin->w_pcmark, curwin->w_cursor) 200 && (equalpos(curwin->w_pcmark, curwin->w_cursor)
205 || curwin->w_pcmark.lnum == 0)) 201 || curwin->w_pcmark.lnum == 0))
206 { 202 {
212 #if defined(FEAT_JUMPLIST) || defined(PROTO) 208 #if defined(FEAT_JUMPLIST) || defined(PROTO)
213 /* 209 /*
214 * move "count" positions in the jump list (count may be negative) 210 * move "count" positions in the jump list (count may be negative)
215 */ 211 */
216 pos_T * 212 pos_T *
217 movemark(count) 213 movemark(int count)
218 int count;
219 { 214 {
220 pos_T *pos; 215 pos_T *pos;
221 xfmark_T *jmp; 216 xfmark_T *jmp;
222 217
223 cleanup_jumplist(); 218 cleanup_jumplist();
272 267
273 /* 268 /*
274 * Move "count" positions in the changelist (count may be negative). 269 * Move "count" positions in the changelist (count may be negative).
275 */ 270 */
276 pos_T * 271 pos_T *
277 movechangelist(count) 272 movechangelist(int count)
278 int count;
279 { 273 {
280 int n; 274 int n;
281 275
282 if (curbuf->b_changelistlen == 0) /* nothing to jump to */ 276 if (curbuf->b_changelistlen == 0) /* nothing to jump to */
283 return (pos_T *)NULL; 277 return (pos_T *)NULL;
312 * in another file which can't be gotten. (caller needs to check lnum!) 306 * in another file which can't be gotten. (caller needs to check lnum!)
313 * - NULL if there is no mark called 'c'. 307 * - NULL if there is no mark called 'c'.
314 * - -1 if mark is in other file and jumped there (only if changefile is TRUE) 308 * - -1 if mark is in other file and jumped there (only if changefile is TRUE)
315 */ 309 */
316 pos_T * 310 pos_T *
317 getmark_buf(buf, c, changefile) 311 getmark_buf(buf_T *buf, int c, int changefile)
318 buf_T *buf;
319 int c;
320 int changefile;
321 { 312 {
322 return getmark_buf_fnum(buf, c, changefile, NULL); 313 return getmark_buf_fnum(buf, c, changefile, NULL);
323 } 314 }
324 315
325 pos_T * 316 pos_T *
326 getmark(c, changefile) 317 getmark(int c, int changefile)
327 int c;
328 int changefile;
329 { 318 {
330 return getmark_buf_fnum(curbuf, c, changefile, NULL); 319 return getmark_buf_fnum(curbuf, c, changefile, NULL);
331 } 320 }
332 321
333 pos_T * 322 pos_T *
334 getmark_buf_fnum(buf, c, changefile, fnum) 323 getmark_buf_fnum(
335 buf_T *buf; 324 buf_T *buf,
336 int c; 325 int c,
337 int changefile; 326 int changefile,
338 int *fnum; 327 int *fnum)
339 { 328 {
340 pos_T *posp; 329 pos_T *posp;
341 pos_T *startp, *endp; 330 pos_T *startp, *endp;
342 static pos_T pos_copy; 331 static pos_T pos_copy;
343 332
470 * Search for the next named mark in the current file. 459 * Search for the next named mark in the current file.
471 * 460 *
472 * Returns pointer to pos_T of the next mark or NULL if no mark is found. 461 * Returns pointer to pos_T of the next mark or NULL if no mark is found.
473 */ 462 */
474 pos_T * 463 pos_T *
475 getnextmark(startpos, dir, begin_line) 464 getnextmark(
476 pos_T *startpos; /* where to start */ 465 pos_T *startpos, /* where to start */
477 int dir; /* direction for search */ 466 int dir, /* direction for search */
478 int begin_line; 467 int begin_line)
479 { 468 {
480 int i; 469 int i;
481 pos_T *result = NULL; 470 pos_T *result = NULL;
482 pos_T pos; 471 pos_T pos;
483 472
518 * For an xtended filemark: set the fnum from the fname. 507 * For an xtended filemark: set the fnum from the fname.
519 * This is used for marks obtained from the .viminfo file. It's postponed 508 * This is used for marks obtained from the .viminfo file. It's postponed
520 * until the mark is used to avoid a long startup delay. 509 * until the mark is used to avoid a long startup delay.
521 */ 510 */
522 static void 511 static void
523 fname2fnum(fm) 512 fname2fnum(xfmark_T *fm)
524 xfmark_T *fm;
525 { 513 {
526 char_u *p; 514 char_u *p;
527 515
528 if (fm->fname != NULL) 516 if (fm->fname != NULL)
529 { 517 {
559 * Check all file marks for a name that matches the file name in buf. 547 * Check all file marks for a name that matches the file name in buf.
560 * May replace the name with an fnum. 548 * May replace the name with an fnum.
561 * Used for marks that come from the .viminfo file. 549 * Used for marks that come from the .viminfo file.
562 */ 550 */
563 void 551 void
564 fmarks_check_names(buf) 552 fmarks_check_names(buf_T *buf)
565 buf_T *buf;
566 { 553 {
567 char_u *name; 554 char_u *name;
568 int i; 555 int i;
569 #ifdef FEAT_JUMPLIST 556 #ifdef FEAT_JUMPLIST
570 win_T *wp; 557 win_T *wp;
590 577
591 vim_free(name); 578 vim_free(name);
592 } 579 }
593 580
594 static void 581 static void
595 fmarks_check_one(fm, name, buf) 582 fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf)
596 xfmark_T *fm;
597 char_u *name;
598 buf_T *buf;
599 { 583 {
600 if (fm->fmark.fnum == 0 584 if (fm->fmark.fnum == 0
601 && fm->fname != NULL 585 && fm->fname != NULL
602 && fnamecmp(name, fm->fname) == 0) 586 && fnamecmp(name, fm->fname) == 0)
603 { 587 {
610 /* 594 /*
611 * Check a if a position from a mark is valid. 595 * Check a if a position from a mark is valid.
612 * Give and error message and return FAIL if not. 596 * Give and error message and return FAIL if not.
613 */ 597 */
614 int 598 int
615 check_mark(pos) 599 check_mark(pos_T *pos)
616 pos_T *pos;
617 { 600 {
618 if (pos == NULL) 601 if (pos == NULL)
619 { 602 {
620 EMSG(_(e_umark)); 603 EMSG(_(e_umark));
621 return FAIL; 604 return FAIL;
640 * clrallmarks() - clear all marks in the buffer 'buf' 623 * clrallmarks() - clear all marks in the buffer 'buf'
641 * 624 *
642 * Used mainly when trashing the entire buffer during ":e" type commands 625 * Used mainly when trashing the entire buffer during ":e" type commands
643 */ 626 */
644 void 627 void
645 clrallmarks(buf) 628 clrallmarks(buf_T *buf)
646 buf_T *buf;
647 { 629 {
648 static int i = -1; 630 static int i = -1;
649 631
650 if (i == -1) /* first call ever: initialize */ 632 if (i == -1) /* first call ever: initialize */
651 for (i = 0; i < NMARKS + 1; i++) 633 for (i = 0; i < NMARKS + 1; i++)
674 * Get name of file from a filemark. 656 * Get name of file from a filemark.
675 * When it's in the current buffer, return the text at the mark. 657 * When it's in the current buffer, return the text at the mark.
676 * Returns an allocated string. 658 * Returns an allocated string.
677 */ 659 */
678 char_u * 660 char_u *
679 fm_getname(fmark, lead_len) 661 fm_getname(fmark_T *fmark, int lead_len)
680 fmark_T *fmark;
681 int lead_len;
682 { 662 {
683 if (fmark->fnum == curbuf->b_fnum) /* current buffer */ 663 if (fmark->fnum == curbuf->b_fnum) /* current buffer */
684 return mark_line(&(fmark->mark), lead_len); 664 return mark_line(&(fmark->mark), lead_len);
685 return buflist_nr2name(fmark->fnum, FALSE, TRUE); 665 return buflist_nr2name(fmark->fnum, FALSE, TRUE);
686 } 666 }
688 /* 668 /*
689 * Return the line at mark "mp". Truncate to fit in window. 669 * Return the line at mark "mp". Truncate to fit in window.
690 * The returned string has been allocated. 670 * The returned string has been allocated.
691 */ 671 */
692 static char_u * 672 static char_u *
693 mark_line(mp, lead_len) 673 mark_line(pos_T *mp, int lead_len)
694 pos_T *mp;
695 int lead_len;
696 { 674 {
697 char_u *s, *p; 675 char_u *s, *p;
698 int len; 676 int len;
699 677
700 if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count) 678 if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count)
716 694
717 /* 695 /*
718 * print the marks 696 * print the marks
719 */ 697 */
720 void 698 void
721 do_marks(eap) 699 do_marks(exarg_T *eap)
722 exarg_T *eap;
723 { 700 {
724 char_u *arg = eap->arg; 701 char_u *arg = eap->arg;
725 int i; 702 int i;
726 char_u *name; 703 char_u *name;
727 704
755 show_one_mark('>', arg, &curbuf->b_visual.vi_end, NULL, TRUE); 732 show_one_mark('>', arg, &curbuf->b_visual.vi_end, NULL, TRUE);
756 show_one_mark(-1, arg, NULL, NULL, FALSE); 733 show_one_mark(-1, arg, NULL, NULL, FALSE);
757 } 734 }
758 735
759 static void 736 static void
760 show_one_mark(c, arg, p, name, current) 737 show_one_mark(
761 int c; 738 int c,
762 char_u *arg; 739 char_u *arg,
763 pos_T *p; 740 pos_T *p,
764 char_u *name; 741 char_u *name,
765 int current; /* in current file */ 742 int current) /* in current file */
766 { 743 {
767 static int did_title = FALSE; 744 static int did_title = FALSE;
768 int mustfree = FALSE; 745 int mustfree = FALSE;
769 746
770 if (c == -1) /* finish up */ 747 if (c == -1) /* finish up */
813 790
814 /* 791 /*
815 * ":delmarks[!] [marks]" 792 * ":delmarks[!] [marks]"
816 */ 793 */
817 void 794 void
818 ex_delmarks(eap) 795 ex_delmarks(exarg_T *eap)
819 exarg_T *eap;
820 { 796 {
821 char_u *p; 797 char_u *p;
822 int from, to; 798 int from, to;
823 int i; 799 int i;
824 int lower; 800 int lower;
897 #if defined(FEAT_JUMPLIST) || defined(PROTO) 873 #if defined(FEAT_JUMPLIST) || defined(PROTO)
898 /* 874 /*
899 * print the jumplist 875 * print the jumplist
900 */ 876 */
901 void 877 void
902 ex_jumps(eap) 878 ex_jumps(exarg_T *eap UNUSED)
903 exarg_T *eap UNUSED;
904 { 879 {
905 int i; 880 int i;
906 char_u *name; 881 char_u *name;
907 882
908 cleanup_jumplist(); 883 cleanup_jumplist();
945 920
946 /* 921 /*
947 * print the changelist 922 * print the changelist
948 */ 923 */
949 void 924 void
950 ex_changes(eap) 925 ex_changes(exarg_T *eap UNUSED)
951 exarg_T *eap UNUSED;
952 { 926 {
953 int i; 927 int i;
954 char_u *name; 928 char_u *name;
955 929
956 /* Highlight title */ 930 /* Highlight title */
1023 * Example: Delete lines 34 and 35: mark_adjust(34, 35, MAXLNUM, -2); 997 * Example: Delete lines 34 and 35: mark_adjust(34, 35, MAXLNUM, -2);
1024 * Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0); 998 * Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0);
1025 * or: mark_adjust(56, 55, MAXLNUM, 2); 999 * or: mark_adjust(56, 55, MAXLNUM, 2);
1026 */ 1000 */
1027 void 1001 void
1028 mark_adjust(line1, line2, amount, amount_after) 1002 mark_adjust(
1029 linenr_T line1; 1003 linenr_T line1,
1030 linenr_T line2; 1004 linenr_T line2,
1031 long amount; 1005 long amount,
1032 long amount_after; 1006 long amount_after)
1033 { 1007 {
1034 int i; 1008 int i;
1035 int fnum = curbuf->b_fnum; 1009 int fnum = curbuf->b_fnum;
1036 linenr_T *lp; 1010 linenr_T *lp;
1037 win_T *win; 1011 win_T *win;
1205 * Adjust marks in line "lnum" at column "mincol" and further: add 1179 * Adjust marks in line "lnum" at column "mincol" and further: add
1206 * "lnum_amount" to the line number and add "col_amount" to the column 1180 * "lnum_amount" to the line number and add "col_amount" to the column
1207 * position. 1181 * position.
1208 */ 1182 */
1209 void 1183 void
1210 mark_col_adjust(lnum, mincol, lnum_amount, col_amount) 1184 mark_col_adjust(
1211 linenr_T lnum; 1185 linenr_T lnum,
1212 colnr_T mincol; 1186 colnr_T mincol,
1213 long lnum_amount; 1187 long lnum_amount,
1214 long col_amount; 1188 long col_amount)
1215 { 1189 {
1216 int i; 1190 int i;
1217 int fnum = curbuf->b_fnum; 1191 int fnum = curbuf->b_fnum;
1218 win_T *win; 1192 win_T *win;
1219 pos_T *posp; 1193 pos_T *posp;
1289 /* 1263 /*
1290 * When deleting lines, this may create duplicate marks in the 1264 * When deleting lines, this may create duplicate marks in the
1291 * jumplist. They will be removed here for the current window. 1265 * jumplist. They will be removed here for the current window.
1292 */ 1266 */
1293 static void 1267 static void
1294 cleanup_jumplist() 1268 cleanup_jumplist(void)
1295 { 1269 {
1296 int i; 1270 int i;
1297 int from, to; 1271 int from, to;
1298 1272
1299 to = 0; 1273 to = 0;
1321 # if defined(FEAT_WINDOWS) || defined(PROTO) 1295 # if defined(FEAT_WINDOWS) || defined(PROTO)
1322 /* 1296 /*
1323 * Copy the jumplist from window "from" to window "to". 1297 * Copy the jumplist from window "from" to window "to".
1324 */ 1298 */
1325 void 1299 void
1326 copy_jumplist(from, to) 1300 copy_jumplist(win_T *from, win_T *to)
1327 win_T *from;
1328 win_T *to;
1329 { 1301 {
1330 int i; 1302 int i;
1331 1303
1332 for (i = 0; i < from->w_jumplistlen; ++i) 1304 for (i = 0; i < from->w_jumplistlen; ++i)
1333 { 1305 {
1341 1313
1342 /* 1314 /*
1343 * Free items in the jumplist of window "wp". 1315 * Free items in the jumplist of window "wp".
1344 */ 1316 */
1345 void 1317 void
1346 free_jumplist(wp) 1318 free_jumplist(win_T *wp)
1347 win_T *wp;
1348 { 1319 {
1349 int i; 1320 int i;
1350 1321
1351 for (i = 0; i < wp->w_jumplistlen; ++i) 1322 for (i = 0; i < wp->w_jumplistlen; ++i)
1352 vim_free(wp->w_jumplist[i].fname); 1323 vim_free(wp->w_jumplist[i].fname);
1353 } 1324 }
1354 # endif 1325 # endif
1355 #endif /* FEAT_JUMPLIST */ 1326 #endif /* FEAT_JUMPLIST */
1356 1327
1357 void 1328 void
1358 set_last_cursor(win) 1329 set_last_cursor(win_T *win)
1359 win_T *win;
1360 { 1330 {
1361 if (win->w_buffer != NULL) 1331 if (win->w_buffer != NULL)
1362 win->w_buffer->b_last_cursor = win->w_cursor; 1332 win->w_buffer->b_last_cursor = win->w_cursor;
1363 } 1333 }
1364 1334
1365 #if defined(EXITFREE) || defined(PROTO) 1335 #if defined(EXITFREE) || defined(PROTO)
1366 void 1336 void
1367 free_all_marks() 1337 free_all_marks(void)
1368 { 1338 {
1369 int i; 1339 int i;
1370 1340
1371 for (i = 0; i < NMARKS + EXTRA_MARKS; i++) 1341 for (i = 0; i < NMARKS + EXTRA_MARKS; i++)
1372 if (namedfm[i].fmark.mark.lnum != 0) 1342 if (namedfm[i].fmark.mark.lnum != 0)
1374 } 1344 }
1375 #endif 1345 #endif
1376 1346
1377 #if defined(FEAT_VIMINFO) || defined(PROTO) 1347 #if defined(FEAT_VIMINFO) || defined(PROTO)
1378 int 1348 int
1379 read_viminfo_filemark(virp, force) 1349 read_viminfo_filemark(vir_T *virp, int force)
1380 vir_T *virp;
1381 int force;
1382 { 1350 {
1383 char_u *str; 1351 char_u *str;
1384 xfmark_T *fm; 1352 xfmark_T *fm;
1385 int i; 1353 int i;
1386 1354
1436 } 1404 }
1437 return vim_fgets(virp->vir_line, LSIZE, virp->vir_fd); 1405 return vim_fgets(virp->vir_line, LSIZE, virp->vir_fd);
1438 } 1406 }
1439 1407
1440 void 1408 void
1441 write_viminfo_filemarks(fp) 1409 write_viminfo_filemarks(FILE *fp)
1442 FILE *fp;
1443 { 1410 {
1444 int i; 1411 int i;
1445 char_u *name; 1412 char_u *name;
1446 buf_T *buf; 1413 buf_T *buf;
1447 xfmark_T *fm; 1414 xfmark_T *fm;
1497 } 1464 }
1498 #endif 1465 #endif
1499 } 1466 }
1500 1467
1501 static void 1468 static void
1502 write_one_filemark(fp, fm, c1, c2) 1469 write_one_filemark(
1503 FILE *fp; 1470 FILE *fp,
1504 xfmark_T *fm; 1471 xfmark_T *fm,
1505 int c1; 1472 int c1,
1506 int c2; 1473 int c2)
1507 { 1474 {
1508 char_u *name; 1475 char_u *name;
1509 1476
1510 if (fm->fmark.mark.lnum == 0) /* not set */ 1477 if (fm->fmark.mark.lnum == 0) /* not set */
1511 return; 1478 return;
1527 1494
1528 /* 1495 /*
1529 * Return TRUE if "name" is on removable media (depending on 'viminfo'). 1496 * Return TRUE if "name" is on removable media (depending on 'viminfo').
1530 */ 1497 */
1531 int 1498 int
1532 removable(name) 1499 removable(char_u *name)
1533 char_u *name;
1534 { 1500 {
1535 char_u *p; 1501 char_u *p;
1536 char_u part[51]; 1502 char_u part[51];
1537 int retval = FALSE; 1503 int retval = FALSE;
1538 size_t n; 1504 size_t n;
1563 /* 1529 /*
1564 * Write all the named marks for all buffers. 1530 * Write all the named marks for all buffers.
1565 * Return the number of buffers for which marks have been written. 1531 * Return the number of buffers for which marks have been written.
1566 */ 1532 */
1567 int 1533 int
1568 write_viminfo_marks(fp_out) 1534 write_viminfo_marks(FILE *fp_out)
1569 FILE *fp_out;
1570 { 1535 {
1571 int count; 1536 int count;
1572 buf_T *buf; 1537 buf_T *buf;
1573 int is_mark_set; 1538 int is_mark_set;
1574 int i; 1539 int i;
1630 1595
1631 return count; 1596 return count;
1632 } 1597 }
1633 1598
1634 static void 1599 static void
1635 write_one_mark(fp_out, c, pos) 1600 write_one_mark(FILE *fp_out, int c, pos_T *pos)
1636 FILE *fp_out;
1637 int c;
1638 pos_T *pos;
1639 { 1601 {
1640 if (pos->lnum != 0) 1602 if (pos->lnum != 0)
1641 fprintf(fp_out, "\t%c\t%ld\t%d\n", c, (long)pos->lnum, (int)pos->col); 1603 fprintf(fp_out, "\t%c\t%ld\t%d\n", c, (long)pos->lnum, (int)pos->col);
1642 } 1604 }
1643 1605
1646 * fp_out != NULL: copy marks for buffers not in buffer list 1608 * fp_out != NULL: copy marks for buffers not in buffer list
1647 * fp_out == NULL && (flags & VIF_WANT_MARKS): read marks for curbuf only 1609 * fp_out == NULL && (flags & VIF_WANT_MARKS): read marks for curbuf only
1648 * fp_out == NULL && (flags & VIF_GET_OLDFILES | VIF_FORCEIT): fill v:oldfiles 1610 * fp_out == NULL && (flags & VIF_GET_OLDFILES | VIF_FORCEIT): fill v:oldfiles
1649 */ 1611 */
1650 void 1612 void
1651 copy_viminfo_marks(virp, fp_out, count, eof, flags) 1613 copy_viminfo_marks(
1652 vir_T *virp; 1614 vir_T *virp,
1653 FILE *fp_out; 1615 FILE *fp_out,
1654 int count; 1616 int count,
1655 int eof; 1617 int eof,
1656 int flags; 1618 int flags)
1657 { 1619 {
1658 char_u *line = virp->vir_line; 1620 char_u *line = virp->vir_line;
1659 buf_T *buf; 1621 buf_T *buf;
1660 int num_marked_files; 1622 int num_marked_files;
1661 int load_marks; 1623 int load_marks;