Skip to content

Commit 676c205

Browse files
committedSep 4, 2024
Makefile and condition
fixed the makefile and corrected the condition that had strcmp and strncmp, and correcte the notes folder to note
1 parent 9c6f405 commit 676c205

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed
 

‎makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ SHELL := /bin/bash
33
FILE_NAME = notes.c
44

55
compile:
6-
@gcc -o $(basename $(FILE_NAME)) $(FILE_NAME)
6+
@gcc -Wall -o $(basename $(FILE_NAME)) $(FILE_NAME)
77

8-
run:
8+
new:
99
@./notes --new ciao.md
1010

1111
open:

‎notes.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Metadata get_metadata(char file_name[]) {
4444
// declare array
4545
static Metadata metadata;
4646

47-
// open stram
47+
// open stream
4848
FILE* ptr_file = fopen(file_name, "r");
4949
if (ptr_file == NULL) {
5050
fprintf(stderr, "%s[ERROR]%s: Failed while opening the file\n", color_red, color_reset);
@@ -58,11 +58,11 @@ Metadata get_metadata(char file_name[]) {
5858
while (fgets(field, MAX_FIELD_SIZE, ptr_file) != NULL && fgets(value, MAX_VALUE_SIZE, ptr_file) != NULL) {
5959

6060
// if "Tag"/"Argument" line then save value and set boolean
61-
if (strncmp(field, "Tag", 3)) {
61+
if (strncmp(field, "Tag", 3) == 0) {
6262
strcpy(metadata.tags, value);
63-
} else if (strncmp(field, "Argument", 8)) {
63+
} else if (strncmp(field, "Argument", 8) == 0) {
6464
strcpy(metadata.arguments, value);
65-
} else if (strcmp(field, "---\n")) {
65+
} else if (strcmp(field, "---\n") == 0) {
6666
if (!twice) {
6767
twice = true;
6868
} else {
@@ -117,7 +117,7 @@ void new(char file_name[]) {
117117
while (fgets(field, MAX_FIELD_SIZE, ptr_template) != NULL) {
118118

119119
// if the string is the start/end of the metadata section ot the new line at the bottom
120-
if (strcmp(field, "---\n") && strcmp(field, "\n")) {
120+
if (strcmp(field, "---\n") != 0 && strcmp(field, "\n") != 0) {
121121

122122
// null terminate string
123123
field[strcspn(field, "\n")] = '\0';
@@ -128,9 +128,9 @@ void new(char file_name[]) {
128128
// get input from stdin
129129
fgets(value, sizeof(value), stdin);
130130

131-
if (strncmp(field, "Tag", 3)) {
131+
if (strncmp(field, "Tag", 3) == 0) {
132132
strcpy(tags, value);
133-
} else if (strncmp(field, "Argument", 8)) {
133+
} else if (strncmp(field, "Argument", 8) == 0) {
134134
strcpy(arguments, value);
135135
}
136136

@@ -152,13 +152,13 @@ void save(char file_name[]) {
152152
metadata = get_metadata(file_name);
153153

154154
// create basic folders if they don't already exist
155-
mkdir("./notes", 0777);
156-
mkdir("./notes/arguments", 0777);
157-
mkdir("./notes/tags", 0777);
155+
mkdir("./note", 0777);
156+
mkdir("./note/arguments", 0777);
157+
mkdir("./note/tags", 0777);
158158

159159
// create the local path to the right tag folder
160160
char arguments_file[MAX_VALUE_SIZE];
161-
strcpy(arguments_file, "./notes/arguments/");
161+
strcpy(arguments_file, "./note/arguments/");
162162
strcat(arguments_file, metadata.arguments);
163163
strcat(arguments_file, ".md");
164164

@@ -186,7 +186,7 @@ void save(char file_name[]) {
186186

187187
// create the local path to the right tag folder
188188
char tags_folder[MAX_VALUE_SIZE];
189-
strcpy(tags_folder, "./notes/tags/");
189+
strcpy(tags_folder, "./note/tags/");
190190
strcat(tags_folder, metadata.tags);
191191

192192
// create the folder if not already exists
@@ -220,13 +220,13 @@ int main(int argc, char* argv[]) {
220220
strcpy(flag, argv[1]);
221221

222222
// check if creating file
223-
if (strcmp(flag, "-n") || strcmp(flag, "--new")) {
223+
if (strcmp(flag, "-n") == 0 || strcmp(flag, "--new") == 0) {
224224
// get file name
225225
char file_name[MAX_FILENAME_SIZE];
226226
strcpy(file_name, argv[2]);
227227

228228
new(file_name);
229-
} else if (strcmp(flag, "-s") || strcmp(flag, "--save")) {
229+
} else if (strcmp(flag, "-s") == 0 || strcmp(flag, "--save") == 0) {
230230
// get file name
231231
char file_name[MAX_FILENAME_SIZE];
232232
strcpy(file_name, argv[2]);

0 commit comments

Comments
 (0)
Please sign in to comment.