comparison src/undo.c @ 2342:f6540762173d vim73

Fixes and improvements for MS-Windows build.
author Bram Moolenaar <bram@vim.org>
date Sun, 18 Jul 2010 21:42:34 +0200
parents ccda151dde4e
children 8878a9f8db87
comparison
equal deleted inserted replaced
2341:9272cc83214f 2342:f6540762173d
104 static void u_free_uhp __ARGS((u_header_T *uhp)); 104 static void u_free_uhp __ARGS((u_header_T *uhp));
105 static size_t fwrite_crypt __ARGS((buf_T *buf UNUSED, char_u *ptr, size_t len, FILE *fp)); 105 static size_t fwrite_crypt __ARGS((buf_T *buf UNUSED, char_u *ptr, size_t len, FILE *fp));
106 static char_u *read_string_decrypt __ARGS((buf_T *buf UNUSED, FILE *fd, int len)); 106 static char_u *read_string_decrypt __ARGS((buf_T *buf UNUSED, FILE *fd, int len));
107 static int serialize_header __ARGS((FILE *fp, buf_T *buf, char_u *hash)); 107 static int serialize_header __ARGS((FILE *fp, buf_T *buf, char_u *hash));
108 static int serialize_uhp __ARGS((FILE *fp, buf_T *buf, u_header_T *uhp)); 108 static int serialize_uhp __ARGS((FILE *fp, buf_T *buf, u_header_T *uhp));
109 static u_header_T *unserialize_uhp __ARGS((FILE *fp, char_u *file_name, int new_version)); 109 static u_header_T *unserialize_uhp __ARGS((FILE *fp, char_u *file_name));
110 static int serialize_uep __ARGS((FILE *fp, buf_T *buf, u_entry_T *uep)); 110 static int serialize_uep __ARGS((FILE *fp, buf_T *buf, u_entry_T *uep));
111 static u_entry_T *unserialize_uep __ARGS((FILE *fp, int *error, char_u *file_name)); 111 static u_entry_T *unserialize_uep __ARGS((FILE *fp, int *error, char_u *file_name));
112 static void serialize_pos __ARGS((pos_T pos, FILE *fp)); 112 static void serialize_pos __ARGS((pos_T pos, FILE *fp));
113 static void unserialize_pos __ARGS((pos_T *pos, FILE *fp)); 113 static void unserialize_pos __ARGS((pos_T *pos, FILE *fp));
114 static void serialize_visualinfo __ARGS((visualinfo_T *info, FILE *fp)); 114 static void serialize_visualinfo __ARGS((visualinfo_T *info, FILE *fp));
692 # define UF_START_MAGIC_LEN 9 692 # define UF_START_MAGIC_LEN 9
693 # define UF_HEADER_MAGIC 0x5fd0 /* magic at start of header */ 693 # define UF_HEADER_MAGIC 0x5fd0 /* magic at start of header */
694 # define UF_HEADER_END_MAGIC 0xe7aa /* magic after last header */ 694 # define UF_HEADER_END_MAGIC 0xe7aa /* magic after last header */
695 # define UF_ENTRY_MAGIC 0xf518 /* magic at start of entry */ 695 # define UF_ENTRY_MAGIC 0xf518 /* magic at start of entry */
696 # define UF_ENTRY_END_MAGIC 0x3581 /* magic after last entry */ 696 # define UF_ENTRY_END_MAGIC 0x3581 /* magic after last entry */
697 # define UF_VERSION_PREV 1 /* 2-byte undofile version number */
698 # define UF_VERSION 2 /* 2-byte undofile version number */ 697 # define UF_VERSION 2 /* 2-byte undofile version number */
699 # define UF_VERSION_CRYPT_PREV 0x8001 /* idem, encrypted */
700 # define UF_VERSION_CRYPT 0x8002 /* idem, encrypted */ 698 # define UF_VERSION_CRYPT 0x8002 /* idem, encrypted */
701 699
702 /* extra fields for header */ 700 /* extra fields for header */
703 # define UF_LAST_SAVE_NR 1 701 # define UF_LAST_SAVE_NR 1
704 702
1017 put_bytes(fp, (long_u)UF_ENTRY_END_MAGIC, 2); 1015 put_bytes(fp, (long_u)UF_ENTRY_END_MAGIC, 2);
1018 return OK; 1016 return OK;
1019 } 1017 }
1020 1018
1021 static u_header_T * 1019 static u_header_T *
1022 unserialize_uhp(fp, file_name, new_version) 1020 unserialize_uhp(fp, file_name)
1023 FILE *fp; 1021 FILE *fp;
1024 char_u *file_name; 1022 char_u *file_name;
1025 int new_version;
1026 { 1023 {
1027 u_header_T *uhp; 1024 u_header_T *uhp;
1028 int i; 1025 int i;
1029 u_entry_T *uep, *last_uep; 1026 u_entry_T *uep, *last_uep;
1030 int c; 1027 int c;
1066 } 1063 }
1067 #endif 1064 #endif
1068 uhp->uh_time = get8ctime(fp); 1065 uhp->uh_time = get8ctime(fp);
1069 1066
1070 /* Optional fields. */ 1067 /* Optional fields. */
1071 if (new_version) 1068 for (;;)
1072 for (;;) 1069 {
1073 { 1070 int len = getc(fp);
1074 int len = getc(fp); 1071 int what;
1075 int what; 1072
1076 1073 if (len == 0)
1077 if (len == 0) 1074 break;
1075 what = getc(fp);
1076 switch (what)
1077 {
1078 case UHP_SAVE_NR:
1079 uhp->uh_save_nr = get4c(fp);
1078 break; 1080 break;
1079 what = getc(fp); 1081 default:
1080 switch (what) 1082 /* field not supported, skip */
1081 { 1083 while (--len >= 0)
1082 case UHP_SAVE_NR: 1084 (void)getc(fp);
1083 uhp->uh_save_nr = get4c(fp); 1085 }
1084 break; 1086 }
1085 default:
1086 /* field not supported, skip */
1087 while (--len >= 0)
1088 (void)getc(fp);
1089 }
1090 }
1091 1087
1092 /* Unserialize the uep list. */ 1088 /* Unserialize the uep list. */
1093 last_uep = NULL; 1089 last_uep = NULL;
1094 while ((c = get2c(fp)) == UF_ENTRY_MAGIC) 1090 while ((c = get2c(fp)) == UF_ENTRY_MAGIC)
1095 { 1091 {
1562 char_u *orig_name; 1558 char_u *orig_name;
1563 { 1559 {
1564 char_u *file_name; 1560 char_u *file_name;
1565 FILE *fp; 1561 FILE *fp;
1566 long version, str_len; 1562 long version, str_len;
1567 int new_version;
1568 char_u *line_ptr = NULL; 1563 char_u *line_ptr = NULL;
1569 linenr_T line_lnum; 1564 linenr_T line_lnum;
1570 colnr_T line_colnr; 1565 colnr_T line_colnr;
1571 linenr_T line_count; 1566 linenr_T line_count;
1572 int num_head = 0; 1567 int num_head = 0;
1643 { 1638 {
1644 EMSG2(_("E823: Not an undo file: %s"), file_name); 1639 EMSG2(_("E823: Not an undo file: %s"), file_name);
1645 goto error; 1640 goto error;
1646 } 1641 }
1647 version = get2c(fp); 1642 version = get2c(fp);
1648 if (version == UF_VERSION_CRYPT || version == UF_VERSION_CRYPT_PREV) 1643 if (version == UF_VERSION_CRYPT)
1649 { 1644 {
1650 #ifdef FEAT_CRYPT 1645 #ifdef FEAT_CRYPT
1651 if (*curbuf->b_p_key == NUL) 1646 if (*curbuf->b_p_key == NUL)
1652 { 1647 {
1653 EMSG2(_("E832: Non-encrypted file has encrypted undo file: %s"), 1648 EMSG2(_("E832: Non-encrypted file has encrypted undo file: %s"),
1663 #else 1658 #else
1664 EMSG2(_("E827: Undo file is encrypted: %s"), file_name); 1659 EMSG2(_("E827: Undo file is encrypted: %s"), file_name);
1665 goto error; 1660 goto error;
1666 #endif 1661 #endif
1667 } 1662 }
1668 else if (version != UF_VERSION && version != UF_VERSION_PREV) 1663 else if (version != UF_VERSION)
1669 { 1664 {
1670 EMSG2(_("E824: Incompatible undo file: %s"), file_name); 1665 EMSG2(_("E824: Incompatible undo file: %s"), file_name);
1671 goto error; 1666 goto error;
1672 } 1667 }
1673 new_version = (version == UF_VERSION || version == UF_VERSION_CRYPT);
1674 1668
1675 if (fread(read_hash, UNDO_HASH_SIZE, 1, fp) != 1) 1669 if (fread(read_hash, UNDO_HASH_SIZE, 1, fp) != 1)
1676 { 1670 {
1677 corruption_error("hash", file_name); 1671 corruption_error("hash", file_name);
1678 goto error; 1672 goto error;
1714 num_head = get4c(fp); 1708 num_head = get4c(fp);
1715 seq_last = get4c(fp); 1709 seq_last = get4c(fp);
1716 seq_cur = get4c(fp); 1710 seq_cur = get4c(fp);
1717 seq_time = get8ctime(fp); 1711 seq_time = get8ctime(fp);
1718 1712
1719 /* Optional header fields, not in previous version. */ 1713 /* Optional header fields. */
1720 if (new_version) 1714 for (;;)
1721 for (;;) 1715 {
1722 { 1716 int len = getc(fp);
1723 int len = getc(fp); 1717 int what;
1724 int what; 1718
1725 1719 if (len == 0 || len == EOF)
1726 if (len == 0 || len == EOF) 1720 break;
1721 what = getc(fp);
1722 switch (what)
1723 {
1724 case UF_LAST_SAVE_NR:
1725 last_save_nr = get4c(fp);
1727 break; 1726 break;
1728 what = getc(fp); 1727 default:
1729 switch (what) 1728 /* field not supported, skip */
1730 { 1729 while (--len >= 0)
1731 case UF_LAST_SAVE_NR: 1730 (void)getc(fp);
1732 last_save_nr = get4c(fp); 1731 }
1733 break; 1732 }
1734 default:
1735 /* field not supported, skip */
1736 while (--len >= 0)
1737 (void)getc(fp);
1738 }
1739 }
1740 1733
1741 /* uhp_table will store the freshly created undo headers we allocate 1734 /* uhp_table will store the freshly created undo headers we allocate
1742 * until we insert them into curbuf. The table remains sorted by the 1735 * until we insert them into curbuf. The table remains sorted by the
1743 * sequence numbers of the headers. 1736 * sequence numbers of the headers.
1744 * When there are no headers uhp_table is NULL. */ 1737 * When there are no headers uhp_table is NULL. */
1756 { 1749 {
1757 corruption_error("num_head too small", file_name); 1750 corruption_error("num_head too small", file_name);
1758 goto error; 1751 goto error;
1759 } 1752 }
1760 1753
1761 uhp = unserialize_uhp(fp, file_name, new_version); 1754 uhp = unserialize_uhp(fp, file_name);
1762 if (uhp == NULL) 1755 if (uhp == NULL)
1763 goto error; 1756 goto error;
1764 uhp_table[num_read_uhps++] = uhp; 1757 uhp_table[num_read_uhps++] = uhp;
1765 } 1758 }
1766 1759