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

thoni56 / c-xrefactory / 1670

22 Dec 2025 02:19PM UTC coverage: 82.747% (-0.07%) from 82.813%
1670

push

travis-ci

thoni56
[tidy] Remove some OO-prefixes

13194 of 15945 relevant lines covered (82.75%)

17986964.81 hits per line

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

76.15
src/server.c
1
#include "server.h"
2

3
#include "commons.h"
4
#include "complete.h"
5
#include "cxfile.h"
6
#include "cxref.h"
7
#include "editorbuffer.h"
8
#include "filedescriptor.h"
9
#include "filetable.h"
10
#include "globals.h"
11
#include "head.h"
12
#include "lexer.h"
13
#include "log.h"
14
#include "startup.h"
15
#include "misc.h"
16
#include "options.h"
17
#include "parsers.h"
18
#include "ppc.h"
19
#include "referenceableitemtable.h"
20
#include "session.h"
21
#include "yylex.h"
22

23

24
const char *operationNamesTable[] = {
25
    "OLO_NONE",
26
    ALL_OPERATION_ENUMS(GENERATE_ENUM_STRING)
27
};
28

29

30

31
static bool requiresProcessingInputFile(ServerOperation operation) {
265✔
32
    return operation==OLO_COMPLETION
33
           || operation==OLO_EXTRACT
243✔
34
           || operation==OLO_TAG_SEARCH
234✔
35
           || operation==OLO_SET_MOVE_FUNCTION_TARGET
232✔
36
           || operation==OLO_GET_METHOD_COORD
232✔
37
           || operation==OLO_GET_ENV_VALUE
232✔
38
           || requiresCreatingRefs(operation)
508✔
39
        ;
40
}
41

42

43
static int scheduleFileUsingTheMacro(void) {
×
44
    SessionStackEntry *tmpc;
45

46
    assert(completionStringInMacroBody);
×
47
    tmpc = NULL;
×
48
    ReferenceableItem references = makeReferenceableItem(completionStringInMacroBody, TypeMacro, StorageExtern,
×
49
                                                         GlobalScope, GlobalVisibility, NO_FILE_NUMBER);
50

51
    BrowserMenu menu = makeBrowserMenu(references, 1, true, 0, UsageUsed, UsageNone, noPosition);
×
52
    if (sessionData.browsingStack.top==NULL) {
×
53
        pushEmptySession(&sessionData.browsingStack);
×
54
        tmpc = sessionData.browsingStack.top;
×
55
    }
56

57
    assert(sessionData.browsingStack.top);
×
58
    BrowserMenu *oldMenu = sessionData.browsingStack.top->menu;
×
59
    sessionData.browsingStack.top->menu = &menu;
×
60
    olMacro2PassFile = NO_FILE_NUMBER;
×
61
    scanForMacroUsage(completionStringInMacroBody);
×
62
    sessionData.browsingStack.top->menu = oldMenu;
×
63
    if (tmpc!=NULL) {
×
64
        deleteEntryFromSessionStack(tmpc);
×
65
    }
66
    log_debug(":scheduling file '%s'", getFileItemWithFileNumber(olMacro2PassFile)->name);
×
67
    return olMacro2PassFile;
×
68
}
69

70
// WTF does "DependingStatics" mean?
71
static char *presetEditServerFileDependingStatics(void) {
265✔
72
    fileProcessingStartTime = time(NULL);
265✔
73

74
    primaryStartPosition = noPosition;
265✔
75
    staticPrefixStartPosition = noPosition;
265✔
76

77
    // This is pretty stupid, there is always only one input file
78
    // in edit server, otherwise it is an error
79
    int fileNumber = 0;
265✔
80
    inputFileName = getNextScheduledFile(&fileNumber);
265✔
81
    if (inputFileName == NULL) { /* No more input files... */
265✔
82
        // conservative message, probably macro invoked on nonsaved file, TODO: WTF?
83
        originalCommandLineFileNumber = NO_FILE_NUMBER;
21✔
84
        return NULL;
21✔
85
    }
86

87
    /* TODO: This seems strange, we only assert that the first file is scheduled to process.
88
       Then reset all other files, why? */
89
    assert(getFileItemWithFileNumber(fileNumber)->isScheduled);
1,395✔
90
    for (int i=getNextExistingFileNumber(fileNumber+1); i != -1; i = getNextExistingFileNumber(i+1)) {
1,151✔
91
        getFileItemWithFileNumber(i)->isScheduled = false;
92
    }
93

244✔
94
    originalCommandLineFileNumber = fileNumber;
95

244✔
96
    char *fileName = inputFileName;
244✔
97
    currentLanguage = getLanguageFor(fileName);
98

99
    // O.K. just to be sure, there is no other input file
244✔
100
    return fileName;
101
}
102

173✔
103
static void closeInputFile(void) {
173✔
104
    if (currentFile.characterBuffer.file != stdin) {
173✔
105
        closeCharacterBuffer(&currentFile.characterBuffer);
106
    }
173✔
107
}
108

173✔
109
static void parseInputFile(void) {
173✔
110
    if (options.fileTrace)
×
111
        fprintf(stderr, "parseInputFile: '%s\n", currentFile.fileName);
173✔
112
    if (options.serverOperation != OLO_TAG_SEARCH && options.serverOperation != OLO_PUSH_NAME) {
169✔
113
        log_debug("parse start");
169✔
114
        parseCurrentInputFile(currentLanguage);
169✔
115
        log_debug("parse end");
116
    } else
4✔
117
        log_debug("Not parsing input because of server operation TAG_SEARCH or PUSH_NAME");
173✔
118
    closeInputFile();
173✔
119
}
120

290✔
121
void initServer(ArgumentsVector args) {
290✔
122
    clearAvailableRefactorings();
290✔
123
    processOptions(args, PROCESS_FILE_ARGUMENTS); /* no include or define options */
266✔
124
    processFileArguments();
266✔
125
    initCompletions(&collectedCompletions, 0, noPosition);
266✔
126
}
127

173✔
128
static void singlePass(ArgumentsVector args, ArgumentsVector nargs, bool *firstPassP) {
173✔
129
    bool inputOpened = false;
130

173✔
131
    inputOpened = initializeFileProcessing(args, nargs, &currentLanguage, firstPassP);
132

173✔
133
    smartReadFileNumbersFromStore();
173✔
134
    originalFileNumber = inputFileNumber;
135

173✔
136
    if (inputOpened) {
137
        /* If the file has preloaded content, remove old references before parsing */
173✔
138
        EditorBuffer *buffer = getOpenedAndLoadedEditorBuffer(inputFileName);
173✔
139
        if (buffer != NULL && buffer->preLoadedFromFile != NULL) {
6✔
140
            log_debug("file has preloaded content, removing old references for file %d", inputFileNumber);
6✔
141
            removeReferenceableItemsForFile(inputFileNumber);
142
        }
143

173✔
144
        parseInputFile();
173✔
145
        *firstPassP = false;
146
    }
173✔
147
    if (options.olCursorOffset==0) {
148
        // special case, push the file as include reference
1✔
149
        if (requiresCreatingRefs(options.serverOperation)) {
×
150
            Position position = makePosition(inputFileNumber, 1, 0);
×
151
            gotOnLineCxRefs(position);
152
        }
1✔
153
        addFileAsIncludeReference(inputFileNumber);
154
    }
173✔
155
    if (completionPositionFound && !completionStringServed) {
156
        // on-line action with cursor in an un-used macro body ???
×
157
        int ol2procfile = scheduleFileUsingTheMacro();
×
158
        if (ol2procfile!=NO_FILE_NUMBER) {
×
159
            inputFileName = getFileItemWithFileNumber(ol2procfile)->name;
×
160
            inputOpened = initializeFileProcessing(args, nargs, &currentLanguage, firstPassP);
×
161
            if (inputOpened) {
×
162
                parseInputFile();
×
163
                *firstPassP = false;
164
            }
165
        }
166
    }
173✔
167
}
168

173✔
169
static void processFile(ArgumentsVector baseArgs, ArgumentsVector requestArgs, bool *firstPassP) {
173✔
170
    FileItem *fileItem = getFileItemWithFileNumber(originalCommandLineFileNumber);
171

173✔
172
    assert(fileItem->isScheduled);
315✔
173
    maxPasses = 1;
173✔
174
    for (currentPass=1; currentPass<=maxPasses; currentPass++) {
173✔
175
        inputFileName = fileItem->name;
173✔
176
        assert(inputFileName!=NULL);
177
        singlePass(baseArgs, requestArgs, firstPassP);
178
        if (options.serverOperation==OLO_EXTRACT || (completionStringServed && !requiresCreatingRefs(options.serverOperation)))
173✔
179
            break;
173✔
180
    }
181
    fileItem->isScheduled = false;
265✔
182
}
265✔
183

184
void callServer(ArgumentsVector baseArgs, ArgumentsVector requestArgs, bool *firstPass) {
265✔
185
    ENTER();
186

265✔
187
    loadAllOpenedEditorBuffers();
139✔
188

189
    if (requiresCreatingRefs(options.serverOperation))
265✔
190
        pushEmptySession(&sessionData.browsingStack);
173✔
191

×
192
    if (requiresProcessingInputFile(options.serverOperation)) {
193
        if (presetEditServerFileDependingStatics() == NULL) {
173✔
194
            errorMessage(ERR_ST, "No input file");
195
        } else {
196
            processFile(baseArgs, requestArgs, firstPass);
92✔
197
        }
71✔
198
    } else {
71✔
199
        if (presetEditServerFileDependingStatics() != NULL) {
200
            getFileItemWithFileNumber(originalCommandLineFileNumber)->isScheduled = false;
201
            inputFileName = NULL;
265✔
202
        }
265✔
203
    }
204
    LEAVE();
24✔
205
}
206

207
void server(ArgumentsVector args) {
208
    ArgumentsVector pipedOptions;
24✔
209
    bool firstPass;
24✔
210

24✔
211
    ENTER();
24✔
212
    cxResizingBlocked = true;
213
    firstPass = true;
170✔
214
    deepCopyOptionsFromTo(&options, &savedOptions);
170✔
215
    for(;;) {
216
        currentPass = ANY_PASS;
170✔
217
        deepCopyOptionsFromTo(&savedOptions, &options);
218

170✔
219
        pipedOptions = getPipedOptions();
220
        // -o option on command line should catch also file not found
170✔
221
        openOutputFile(options.outputFileName);
170✔
222
        //&dumpArguments(nargc, nargv);
×
223
        log_trace("Server: Getting request");
224
        initServer(pipedOptions);
146✔
225
        if (outputFile==stdout && options.outputFileName!=NULL) {
146✔
226
            openOutputFile(options.outputFileName);
×
227
        }
228
        callServer(args, pipedOptions, &firstPass);
146✔
229
        if (options.serverOperation == OLO_ABOUT) {
230
            aboutMessage();
231
        } else {
232
            answerEditAction();
146✔
233
        }
146✔
234
        //& options.outputFileName = NULL;  // why this was here ???
146✔
235
        //editorCloseBufferIfNotUsedElsewhere(s_input_file_name);
146✔
236
        closeAllEditorBuffers();
146✔
237
        closeOutputFile();
238
        if (options.xref2)
239
            ppcSynchronize();
240
        log_trace("Server: Request answered");
241
    }
242
    LEAVE();
243
}
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