-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Installer] Adding Config File Support
- Loading branch information
1 parent
5087b91
commit fa3ff4c
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#define MAX_LINE_LENGTH 100 | ||
#define MAX_CONFIGS 10 | ||
|
||
struct Config { | ||
char key[MAX_LINE_LENGTH]; | ||
char value[MAX_LINE_LENGTH]; | ||
}; | ||
|
||
int main(int argc, char *argv[]) { | ||
|
||
FILE *file = fopen(argv[1], "r"); | ||
if (file == NULL) { | ||
perror("The file doesn't exist"); | ||
return 1; | ||
} | ||
|
||
struct Config config[MAX_CONFIGS]; | ||
int configCount = 0; | ||
|
||
char line[MAX_LINE_LENGTH]; | ||
while (fgets(line, sizeof(line), file)) { | ||
if (line[0] == '#') { | ||
continue; | ||
} | ||
|
||
char *key = strtok(line, "="); | ||
char *value = strtok(NULL, "\n"); | ||
|
||
if (key) { | ||
strcpy(config[configCount].key, key); | ||
if (value) { | ||
strcpy(config[configCount].value, value); | ||
} else { | ||
config[configCount].value[0] = '\0'; | ||
} | ||
configCount++; | ||
} | ||
} | ||
|
||
fclose(file); | ||
|
||
|
||
for (int i = 0; i < configCount; i++) { | ||
printf("%s\n", config[i].value); | ||
} | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Installer Specifics | ||
TODO: Write Doc |