• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thoni56 / c-xrefactory / 1774

06 Apr 2026 08:55AM UTC coverage: 83.228% (+0.1%) from 83.117%
1774

push

travis-ci

thoni56
[tidy][unused] Remove more unused stuff after move to memory-is-truth

15676 of 18835 relevant lines covered (83.23%)

15599379.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.92
src/editorbuffertable.c
1
#include "editorbuffer.h"
2
#define IN_EDITORBUFFERTABLE_C
3
#include "editorbuffertable.h"
4

5
#include <stdlib.h>
6

7
#include "head.h"
8

9

10
static unsigned editorBufferHashFun(char *fileName);
11

12
#define HASH_FUN(element) editorBufferHashFun(element->buffer->fileName)
13
#define HASH_ELEM_EQUAL(e1,e2) (strcmp(e1->buffer->fileName,e2->buffer->fileName)==0)
14

15
#include "hashlist.tc"
16

17
#define EDITOR_BUFFER_TABLE_SIZE 100
18

19
/* Make it possible to inject a mocked hashFun() */
20
static unsigned (*mockedHashFun)(char *fileName) = NULL;
21
static unsigned editorBufferHashFun(char *fileName) {
11,602,358✔
22
    if (mockedHashFun == NULL)
11,602,358✔
23
        return hashFun(fileName);
11,602,337✔
24
    else
25
        return mockedHashFun(fileName);
21✔
26
}
27

28
void injectHashFun(unsigned (fun)(char *fileName)) {
4✔
29
    mockedHashFun = fun;
4✔
30
}
4✔
31

32
static EditorBufferList *editorBufferTablesInit[EDITOR_BUFFER_TABLE_SIZE];
33
protected EditorBufferTable editorBufferTable;
34

35

36
void initEditorBufferTable() {
230✔
37
    editorBufferTable.tab = editorBufferTablesInit;
230✔
38
    editorBufferTableNoAllocInit(&editorBufferTable, EDITOR_BUFFER_TABLE_SIZE);
230✔
39
}
230✔
40

41
int addEditorBuffer(EditorBufferList *bufferListElement) {
461,900✔
42
    assert(strcmp(bufferListElement->buffer->fileName, "") != 0); /* Check that it is accessible */
461,900✔
43
    return editorBufferTableAdd(&editorBufferTable, bufferListElement);
44
}
45

11,140,458✔
46
bool editorBufferIsMember(EditorBufferList *elementP, int *positionP, EditorBufferList **foundMemberP) {
11,140,458✔
47
    return editorBufferTableIsMember(&editorBufferTable, elementP, positionP, foundMemberP);
48
}
49

255,580✔
50
EditorBufferList *getEditorBufferListElementAt(int index) {
255,580✔
51
    return editorBufferTable.tab[index];
52
}
53

255,653✔
54
int getNextExistingEditorBufferIndex(int index) {
715,312✔
55
    for (int i=index; i < editorBufferTable.size; i++)
708,175✔
56
        if (editorBufferTable.tab[i] != NULL)
248,516✔
57
            return i;
7,137✔
58
    return -1;
59
}
60

61
/**
62
 * @brief Registers an EditorBuffer in the editor buffer table
63
 *
64
 * This function allocates the necessary EditorBufferList element so
65
 * that the caller does not have to bother with that.
66
 *
67
 * @param buffer - buffer owned by the caller to register.
68
 * @return the index in the editor buffer table. NB. There might be more at the same index.
69
 */
461,894✔
70
int registerEditorBuffer(EditorBuffer *buffer) {
461,894✔
71
    EditorBufferList *list = malloc(sizeof(EditorBufferList));
461,894✔
72
    *list = (EditorBufferList){.buffer = buffer, .next = NULL};
461,894✔
73
    return addEditorBuffer(list); /* TODO Handles existing, and hash collisions? */
74
}
75

76
/**
77
 * @brief Deregisters a buffer from the editor buffer table
78
 *
79
 * Frees the necessary list element but returns the item itself to the
80
 * caller to free.
81
 *
82
 * @param fileName - the name of the file it was loaded from.
83
 * @returns the EditorBuffer that was deregistered or NULL if not found.
84
 */
461,749✔
85
EditorBuffer *deregisterEditorBuffer(char *fileName) {
461,749✔
86
    EditorBuffer *buffer = malloc(sizeof(EditorBuffer));
461,749✔
87
    *buffer = (EditorBuffer){.fileName = fileName};
461,749✔
88
    EditorBufferList *list = malloc(sizeof(EditorBufferList));
461,749✔
89
    *list = (EditorBufferList){.buffer = buffer, .next = NULL};
90

91
    int foundIndex;
461,749✔
92
    if (!editorBufferIsMember(list, &foundIndex, NULL))
×
93
        return NULL;
94

461,749✔
95
    EditorBufferList **elementP = &editorBufferTable.tab[foundIndex];
801,268✔
96
    while(*elementP != NULL && strcmp((*elementP)->buffer->fileName, fileName) != 0) {
339,519✔
97
        elementP = &(*elementP)->next;
98
    }
99

461,749✔
100
    if (*elementP != NULL) {
461,749✔
101
        EditorBuffer *found_buffer = (*elementP)->buffer;
461,749✔
102
        EditorBufferList *element = *elementP;
461,749✔
103
        *elementP = element->next;
461,749✔
104
        free(element);
461,749✔
105
        return found_buffer;
106
    } else {
×
107
        return NULL;
108
    }
109
}
110

111
/**
112
 * @brief Retrievs an editor buffer in the table and returns it, or NULL
113
 *
114
 * The editor buffer will remain in the table and may not be deleted by
115
 * the caller.
116
 *
117
 * @params fileName - the filename in the buffer to find
118
 *
119
 */
10,678,709✔
120
EditorBuffer *getEditorBufferForFile(char *fileName) {
10,678,709✔
121
    EditorBuffer buffer = {.fileName = fileName};
10,678,709✔
122
    EditorBufferList element = {.buffer = &buffer, .next = NULL};
123
    EditorBufferList *foundElement;
124

10,678,709✔
125
    if (editorBufferIsMember(&element, NULL, &foundElement)) {
2,601,700✔
126
        return foundElement->buffer;
127
    }
8,077,009✔
128
    return NULL;
129
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc