comparison src/libvterm/src/vterm.c @ 30876:2d2758ffd959 v9.0.0772

patch 9.0.0772: the libvterm code is outdated Commit: https://github.com/vim/vim/commit/501e77766cd30d8f4bfeb04a67aff1865b5f5a41 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Oct 16 14:35:46 2022 +0100 patch 9.0.0772: the libvterm code is outdated Problem: The libvterm code is outdated. Solution: Include libvterm changes from revision 790 to 801.
author Bram Moolenaar <Bram@vim.org>
date Sun, 16 Oct 2022 15:45:04 +0200
parents f93337ae0612
children 82336c3b679d
comparison
equal deleted inserted replaced
30875:3295247d97a5 30876:2d2758ffd959
32 &default_free // free 32 &default_free // free
33 }; 33 };
34 34
35 VTerm *vterm_new(int rows, int cols) 35 VTerm *vterm_new(int rows, int cols)
36 { 36 {
37 return vterm_new_with_allocator(rows, cols, &default_allocator, NULL); 37 struct VTermBuilder builder;
38 memset(&builder, 0, sizeof(builder));
39 builder.rows = rows;
40 builder.cols = cols;
41 return vterm_build(&builder);
38 } 42 }
39 43
40 VTerm *vterm_new_with_allocator(int rows, int cols, VTermAllocatorFunctions *funcs, void *allocdata) 44 VTerm *vterm_new_with_allocator(int rows, int cols, VTermAllocatorFunctions *funcs, void *allocdata)
41 { 45 {
46 struct VTermBuilder builder;
47 memset(&builder, 0, sizeof(builder));
48 builder.rows = rows;
49 builder.cols = cols;
50 builder.allocator = funcs;
51 builder.allocdata = allocdata;
52 return vterm_build(&builder);
53 }
54
55 /* A handy macro for defaulting values out of builder fields */
56 #define DEFAULT(v, def) ((v) ? (v) : (def))
57
58 VTerm *vterm_build(const struct VTermBuilder *builder)
59 {
60 const VTermAllocatorFunctions *allocator = DEFAULT(builder->allocator, &default_allocator);
61
42 /* Need to bootstrap using the allocator function directly */ 62 /* Need to bootstrap using the allocator function directly */
43 VTerm *vt = (*funcs->malloc)(sizeof(VTerm), allocdata); 63 VTerm *vt = (*allocator->malloc)(sizeof(VTerm), builder->allocdata);
44 64
45 if (vt == NULL) 65 vt->allocator = allocator;
46 return NULL; 66 vt->allocdata = builder->allocdata;
47 vt->allocator = funcs; 67
48 vt->allocdata = allocdata; 68 vt->rows = builder->rows;
49 69 vt->cols = builder->cols;
50 vt->rows = rows;
51 vt->cols = cols;
52 70
53 vt->parser.state = NORMAL; 71 vt->parser.state = NORMAL;
54 72
55 vt->parser.callbacks = NULL; 73 vt->parser.callbacks = NULL;
56 vt->parser.cbdata = NULL; 74 vt->parser.cbdata = NULL;
57 75
58 vt->outfunc = NULL; 76 vt->outfunc = NULL;
59 vt->outdata = NULL; 77 vt->outdata = NULL;
60 78
61 vt->outbuffer_len = 200; 79 vt->outbuffer_len = DEFAULT(builder->outbuffer_len, 4096);
62 vt->outbuffer_cur = 0; 80 vt->outbuffer_cur = 0;
63 vt->outbuffer = vterm_allocator_malloc(vt, vt->outbuffer_len); 81 vt->outbuffer = vterm_allocator_malloc(vt, vt->outbuffer_len);
64 82
65 vt->tmpbuffer_len = 64; 83 vt->tmpbuffer_len = DEFAULT(builder->tmpbuffer_len, 4096);
66 vt->tmpbuffer = vterm_allocator_malloc(vt, vt->tmpbuffer_len); 84 vt->tmpbuffer = vterm_allocator_malloc(vt, vt->tmpbuffer_len);
67 85
68 if (vt->tmpbuffer == NULL 86 if (vt->tmpbuffer == NULL
69 || vt->outbuffer == NULL 87 || vt->outbuffer == NULL
70 || vt->tmpbuffer == NULL) 88 || vt->tmpbuffer == NULL)