Parsing and help
This commit is contained in:
parent
c1051e9866
commit
e1aaacda20
8
Makefile
8
Makefile
|
@ -3,13 +3,13 @@ FLAGS=-g -Wall -Wextra -Wpedantic
|
||||||
LFLAGS=
|
LFLAGS=
|
||||||
|
|
||||||
|
|
||||||
all: bin/main
|
all: bin/colloscope
|
||||||
|
|
||||||
test: bin/main
|
test: bin/colloscope
|
||||||
bin/main MP2I-creneaux.txt 33 MP2I-colleurs.txt 16 6 15 output.csv
|
bin/colloscope -v MP2I-creneaux.txt 33 MP2I-colleurs.txt 16 6 15 output.csv
|
||||||
|
|
||||||
OBJECTS = obj/structure.o obj/algorithm.o obj/display.o obj/logger.o obj/main.o
|
OBJECTS = obj/structure.o obj/algorithm.o obj/display.o obj/logger.o obj/main.o
|
||||||
bin/main: $(OBJECTS)
|
bin/colloscope: $(OBJECTS)
|
||||||
@mkdir -p bin
|
@mkdir -p bin
|
||||||
$(CC) -o $@ $(LFLAGS) $(FLAGS) $(OBJECTS)
|
$(CC) -o $@ $(LFLAGS) $(FLAGS) $(OBJECTS)
|
||||||
|
|
||||||
|
|
75
src/main.c
75
src/main.c
|
@ -21,6 +21,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "structure.h"
|
#include "structure.h"
|
||||||
|
@ -29,21 +30,75 @@
|
||||||
// gcc -g -Wall -Wextra -Wpedantic main.c -lSDL2 -lSDL2_image -lm -o main
|
// gcc -g -Wall -Wextra -Wpedantic main.c -lSDL2 -lSDL2_image -lm -o main
|
||||||
// ./main MP2I-creneaux.txt 33 MP2I-colleurs.txt 16 6 15 output.csv
|
// ./main MP2I-creneaux.txt 33 MP2I-colleurs.txt 16 6 15 output.csv
|
||||||
|
|
||||||
|
void print_help()
|
||||||
|
{
|
||||||
|
printf("Colloscope - A program that generates a colloscope for French 'classe prépas'. By Alexandre Aboujaib\n");
|
||||||
|
printf("Licensed under the terms of the GNU GPL version 3 or later.\n\n");
|
||||||
|
printf("Usage: colloscope [-qvh] <creneaux> <n_creneaux> <colleurs> <n_colleurs> <n_weeks> <n_groups> <output>\n\n");
|
||||||
|
printf("Available options :\n");
|
||||||
|
printf(" -q Quiet mode\n");
|
||||||
|
printf(" -v Verbose mode\n");
|
||||||
|
printf(" -h Print this help\n");
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if (argc!=8) {
|
int offset;
|
||||||
fprintf(stderr, "Usage: %s <creneaux> <n_creneaux> <colleurs> <n_colleurs> <n_weeks> <n_groups> <output>\n", argv[0]);
|
bool quiet=false;
|
||||||
|
bool verbose=false;
|
||||||
|
|
||||||
|
if (argc==2 && strcmp(argv[1], "-h")==0)
|
||||||
|
{
|
||||||
|
print_help();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
else if (argc==8)
|
||||||
|
{
|
||||||
|
offset=0;
|
||||||
|
}
|
||||||
|
else if (argc==9 && argv[1][0]=='-')
|
||||||
|
{
|
||||||
|
offset=1;
|
||||||
|
|
||||||
|
for (char *ch=&argv[1][1]; *ch != '\0'; ch++)
|
||||||
|
{
|
||||||
|
switch (*ch)
|
||||||
|
{
|
||||||
|
case 'q':
|
||||||
|
quiet=true; break;
|
||||||
|
case 'v':
|
||||||
|
verbose=true; break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Unknown option '%c'. Available: [-qvh].\n", *ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quiet && verbose)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "You can't be both quiet and verbose!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "Usage: %s [-qvh] <creneaux> <n_creneaux> <colleurs> <n_colleurs> <n_weeks> <n_groups> <output>\n", argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
create_logger("colloscope.log", LOG_TRACE);
|
|
||||||
|
|
||||||
char* path_creneaux = argv[1];
|
char* path_creneaux = argv[1+offset];
|
||||||
int n_creneaux = str_to_int(argv[2]);
|
int n_creneaux = str_to_int(argv[2+offset]);
|
||||||
char* path_colleurs = argv[3];
|
char* path_colleurs = argv[3+offset];
|
||||||
int n_colleurs = str_to_int(argv[6]);
|
int n_colleurs = str_to_int(argv[6+offset]);
|
||||||
int n_weeks = str_to_int(argv[5]);
|
int n_weeks = str_to_int(argv[5+offset]);
|
||||||
int n_groups = str_to_int(argv[6]);
|
int n_groups = str_to_int(argv[6+offset]);
|
||||||
char* path_output = argv[7];
|
char* path_output = argv[7+offset];
|
||||||
|
|
||||||
|
|
||||||
|
if (quiet) {
|
||||||
|
create_logger("colloscope.log", LOG_WARN);
|
||||||
|
} else if (verbose) {
|
||||||
|
create_logger("colloscope.log", LOG_DEBUG);
|
||||||
|
} else {
|
||||||
|
create_logger("colloscope.log", LOG_INFO);
|
||||||
|
}
|
||||||
|
|
||||||
trace("%d %d %d %d", n_creneaux, n_colleurs, n_weeks, n_groups);
|
trace("%d %d %d %d", n_creneaux, n_colleurs, n_weeks, n_groups);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue