comparison src/undo.c @ 2266:ae2e615a7320 vim73

Fix tiny build, move functions to undo.c.
author Bram Moolenaar <bram@vim.org>
date Mon, 14 Jun 2010 01:39:13 +0200
parents 771f21e35ec5
children c08f91142c41
comparison
equal deleted inserted replaced
2265:b7cb69ab616d 2266:ae2e615a7320
100 static void u_freeentries __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp)); 100 static void u_freeentries __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp));
101 static void u_freeentry __ARGS((u_entry_T *, long)); 101 static void u_freeentry __ARGS((u_entry_T *, long));
102 #ifdef FEAT_PERSISTENT_UNDO 102 #ifdef FEAT_PERSISTENT_UNDO
103 static void corruption_error __ARGS((char *msg, char_u *file_name)); 103 static void corruption_error __ARGS((char *msg, char_u *file_name));
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));
106 static char_u *read_string_decrypt __ARGS((buf_T *buf UNUSED, FILE *fd, int len));
105 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));
106 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));
107 static u_header_T *unserialize_uhp __ARGS((FILE *fp, char_u *file_name)); 109 static u_header_T *unserialize_uhp __ARGS((FILE *fp, char_u *file_name));
108 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));
109 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));
659 } 661 }
660 do_outofmem_msg((long_u)0); 662 do_outofmem_msg((long_u)0);
661 return FAIL; 663 return FAIL;
662 } 664 }
663 665
664 #ifdef FEAT_PERSISTENT_UNDO 666 #if defined(FEAT_PERSISTENT_UNDO) || defined(PROTO)
665 667
666 # define UF_START_MAGIC "Vim\237UnDo\345" /* magic at start of undofile */ 668 # define UF_START_MAGIC "Vim\237UnDo\345" /* magic at start of undofile */
667 # define UF_START_MAGIC_LEN 9 669 # define UF_START_MAGIC_LEN 9
668 # define UF_HEADER_MAGIC 0x5fd0 /* magic at start of header */ 670 # define UF_HEADER_MAGIC 0x5fd0 /* magic at start of header */
669 # define UF_HEADER_END_MAGIC 0xe7aa /* magic after last header */ 671 # define UF_HEADER_END_MAGIC 0xe7aa /* magic after last header */
797 nuep = uep->ue_next; 799 nuep = uep->ue_next;
798 u_freeentry(uep, uep->ue_size); 800 u_freeentry(uep, uep->ue_size);
799 uep = nuep; 801 uep = nuep;
800 } 802 }
801 vim_free(uhp); 803 vim_free(uhp);
804 }
805
806 /*
807 * Like fwrite() but crypt the bytes when 'key' is set.
808 * Returns 1 if successful.
809 */
810 static size_t
811 fwrite_crypt(buf, ptr, len, fp)
812 buf_T *buf UNUSED;
813 char_u *ptr;
814 size_t len;
815 FILE *fp;
816 {
817 #ifdef FEAT_CRYPT
818 char_u *copy;
819 char_u small_buf[100];
820 size_t i;
821
822 if (*buf->b_p_key == NUL)
823 return fwrite(ptr, len, (size_t)1, fp);
824 if (len < 100)
825 copy = small_buf; /* no malloc()/free() for short strings */
826 else
827 {
828 copy = lalloc(len, FALSE);
829 if (copy == NULL)
830 return 0;
831 }
832 crypt_encode(ptr, len, copy);
833 i = fwrite(copy, len, (size_t)1, fp);
834 if (copy != small_buf)
835 vim_free(copy);
836 return i;
837 #else
838 return fwrite(ptr, len, (size_t)1, fp);
839 #endif
840 }
841
842 /*
843 * Read a string of length "len" from "fd".
844 * When 'key' is set decrypt the bytes.
845 */
846 static char_u *
847 read_string_decrypt(buf, fd, len)
848 buf_T *buf UNUSED;
849 FILE *fd;
850 int len;
851 {
852 char_u *ptr;
853
854 ptr = read_string(fd, len);
855 #ifdef FEAT_CRYPT
856 if (ptr != NULL || *buf->b_p_key != NUL)
857 crypt_decode(ptr, len);
858 #endif
859 return ptr;
802 } 860 }
803 861
804 static int 862 static int
805 serialize_header(fp, buf, hash) 863 serialize_header(fp, buf, hash)
806 FILE *fp; 864 FILE *fp;