Skip to content
This repository was archived by the owner on Jan 11, 2026. It is now read-only.

Commit 1ba4b9b

Browse files
Merge pull request #17 from Adwaith-Rajesh/release-build
added release mode to nobuild, fic the warnings that show up while building in release mode, and updated the docs.
2 parents 989c29c + 00ba02e commit 1ba4b9b

5 files changed

Lines changed: 41 additions & 9 deletions

File tree

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,22 @@ A search engine to search for local files based on their contents and not just t
3939

4040
```console
4141
git clone --depth=1 https://github.com/Adwaith-Rajesh/calsen.git
42+
cd calsen
4243
```
4344

44-
- compiling
45-
[`Calsen`](https://github.com/Adwaith-Rajesh/calsen/) makes use of [nobuild](https://github.com/tsoding/nobuild) as it's build system. To compile run the following commands
45+
- dependencies (I've plans to make this optional [#2](https://github.com/Adwaith-Rajesh/calsen/issues/2))
46+
47+
```console
48+
apt install libmagic-dev
49+
```
50+
51+
#### Compiling
52+
53+
[`Calsen`](https://github.com/Adwaith-Rajesh/calsen/) makes use of [nobuild](https://github.com/tsoding/nobuild) as it's build system. To compile run the following commands
4654

4755
```console
4856
gcc -o nobuild ./nobuild.c
49-
./nobuild
57+
./nobuild --release
5058
ln -s ./build/bin/calsen ./calsen
5159
```
5260

nobuild.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#define NOBUILD_IMPLEMENTATION
22
#include "nobuild.h"
33

4+
#include <getopt.h>
45
#include <stdio.h>
56
#include <stdlib.h>
67
#include <string.h>
78

89
#define CC "cc" // use the default compiler to compile the code
9-
#define C_FLAGS "-g", "-Wall", "-Wextra", "-std=c11", "-I./src", "-I./src/utils"
10+
#define C_FLAGS (in_release) ? "-O3" : "-g", "-Wall", "-Wextra", "-std=c11", "-I./src", "-I./src/utils"
1011

1112
#define OUT_DIR "./build/out"
1213
#define BIN_DIR "./build/bin"
1314

15+
int in_release = 0;
16+
1417
typedef struct {
1518
char parser_file_name[20];
1619
Cmd cmd;
@@ -76,6 +79,9 @@ void build_calsen() {
7679
cmd_run_sync(cmd);
7780
}
7881

82+
#pragma GCC diagnostic push
83+
#pragma GCC diagnostic ignored "-Wstringop-overread"
84+
7985
int custom_parser_check_execute(Cstr file) {
8086
CParserCompileCommand cp_commands[] = {
8187
// sample code
@@ -94,6 +100,8 @@ int custom_parser_check_execute(Cstr file) {
94100

95101
if (!cp_commands_len) return 0;
96102

103+
// this loop will only run if there is an element in the array
104+
// so its safe to access it and also ignore the "-Wstringop-overread" warning
97105
for (size_t i = 0; i < cp_commands_len; i++) {
98106
if (strcmp(file, cp_commands[i].parser_file_name) == 0) {
99107
INFO("CMD: %s", cmd_show(cp_commands[i].cmd));
@@ -104,6 +112,8 @@ int custom_parser_check_execute(Cstr file) {
104112
return 0;
105113
}
106114

115+
#pragma GCC diagnostic pop
116+
107117
void build_parsers() {
108118
INFO("Building parsers");
109119
if (!IS_DIR("./src/parsers")) {
@@ -123,11 +133,19 @@ void build_parsers() {
123133
}
124134

125135
int main(int argc, char **argv) {
136+
GO_REBUILD_URSELF(argc, argv);
137+
138+
int option_index = 0;
139+
struct option long_options[] = {
140+
{"release", no_argument, &in_release, 1},
141+
{0, 0, 0, 0},
142+
};
143+
144+
int c = getopt_long(argc, argv, "", long_options, &option_index);
145+
126146
MKDIRS("build", "out");
127147
MKDIRS("build", "bin");
128148
MKDIRS("build", "parsers");
129-
130-
GO_REBUILD_URSELF(argc, argv);
131149
build_src();
132150
build_src_utils();
133151
build_calsen();

src/indexer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ static HashTable *_read_token(FILE *fp) {
159159

160160
// read the TF val (14 bytes, after the '=')
161161
char tf_val[15];
162-
fgets(tf_val, 15, fp);
162+
if (fgets(tf_val, 15, fp) == NULL) {
163+
fprintf(stderr, "Error reading token");
164+
exit(1);
165+
}
163166

164167
double *db_val = malloc(sizeof(double));
165168
*db_val = strtod(tf_val, &tw);

src/parsers/text_plain.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ void parse_file(const char *pathname, String *str) {
1313
fprintf(stderr, "Could not open file: %s : %s\n", pathname, strerror(errno));
1414
exit(1);
1515
}
16-
fread(str->str, str->size, 1, fp);
16+
size_t read_bytes = fread(str->str, str->size, 1, fp);
17+
if (read_bytes == 0) {
18+
fprintf(stderr, "Error, reading contents of: %s", pathname);
19+
}
1720
fclose(fp);
1821
}
1922
#pragma GCC diagnostic pop

src/utils/linked_list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Node *ll_pop(LinkedList *list) {
6565
list->size--;
6666
return temp;
6767
}
68-
Node *prev;
68+
Node *prev = NULL;
6969
Node *curr = list->head;
7070

7171
while (curr->next != NULL) {

0 commit comments

Comments
 (0)