Skip to content
Snippets Groups Projects
Commit 213cfafe authored by Manuel Bucher's avatar Manuel Bucher
Browse files

added more warnings

parent 558632c7
No related merge requests found
all: loesung all: loesung
WARNINGS = -Wall -Werror WARNINGS = -Wall -Werror
OPTIONAL = -Werror -Wpedantic OPTIONAL = -Wextra -Wpedantic -Wshadow
DEBUG = -ggdb -fno-omit-frame-pointer DEBUG = -ggdb -fno-omit-frame-pointer
OPTIMIZE = -O3 -std=c11 OPTIMIZE = -O3 -std=c11
......
...@@ -21,7 +21,7 @@ typedef struct List { ...@@ -21,7 +21,7 @@ typedef struct List {
/** Initialisieren einer leeren Liste */ /** Initialisieren einer leeren Liste */
void list_init(List *s) { void list_init(List *s) {
s->p_top = 0; s->p_top = NULL;
s->size = 0; s->size = 0;
} }
...@@ -35,10 +35,10 @@ Tile* list_push(List *s) { ...@@ -35,10 +35,10 @@ Tile* list_push(List *s) {
p_tile->x = 0; p_tile->x = 0;
p_tile->y = 0; p_tile->y = 0;
p_tile->p_next = s->p_top; p_tile->p_next = s->p_top;
p_tile->p_prev = 0; p_tile->p_prev = NULL;
s->p_top = p_tile; s->p_top = p_tile;
s->size++; s->size++;
if(p_tile->p_next != 0) { if(p_tile->p_next != NULL) {
p_tile->p_next->p_prev = p_tile; p_tile->p_next->p_prev = p_tile;
} }
return p_tile; return p_tile;
...@@ -51,7 +51,7 @@ Tile* list_push(List *s) { ...@@ -51,7 +51,7 @@ Tile* list_push(List *s) {
Tile* list_pop(List *s) { Tile* list_pop(List *s) {
Tile *p_tile = s->p_top; Tile *p_tile = s->p_top;
s->p_top->p_next = p_tile->p_next; s->p_top->p_next = p_tile->p_next;
s->p_top->p_prev = 0; s->p_top->p_prev = NULL;
return p_tile; return p_tile;
} }
...@@ -61,8 +61,8 @@ Tile* list_pop(List *s) { ...@@ -61,8 +61,8 @@ Tile* list_pop(List *s) {
*/ */
void list_free(List *s) { void list_free(List *s) {
Tile *p_cur = s->p_top; Tile *p_cur = s->p_top;
s->p_top = 0; s->p_top = NULL;
while (p_cur != 0) { while (p_cur != NULL) {
Tile *p_next = p_cur->p_next; Tile *p_next = p_cur->p_next;
free(p_cur); free(p_cur);
p_cur = p_next; p_cur = p_next;
...@@ -81,7 +81,8 @@ typedef enum ReadResult { ...@@ -81,7 +81,8 @@ typedef enum ReadResult {
typedef struct Field { typedef struct Field {
Tile t_min; Tile t_min;
Tile t_max; Tile t_max;
List tiles; List tile_list;
Tile tile_array[];
} Field; } Field;
/** Parsen einer Kachel(Tile) aus einer Zeile von StdIn /** Parsen einer Kachel(Tile) aus einer Zeile von StdIn
...@@ -155,13 +156,13 @@ inline uint32_t max(uint32_t a, uint32_t b) { ...@@ -155,13 +156,13 @@ inline uint32_t max(uint32_t a, uint32_t b) {
* Parameter: * Parameter:
* - Field* f pointer auf ein uninitialisiertes Feld, nach dem ausfuehren der * - Field* f pointer auf ein uninitialisiertes Feld, nach dem ausfuehren der
* Funktion ist das Feld initialisiert, wenn es sich um eine gueltige Eingabe * Funktion ist das Feld initialisiert, wenn es sich um eine gueltige Eingabe
* handelt. `f->num_tiles` Ist im Fehlerfall die Zeile, in dem die Eingabe * handelt. `f->tile_list->size` Ist im Fehlerfall die Zeile, in dem die Eingabe
* ungueltig ist. * ungueltig ist.
* *
* Return: * Return:
* - ReadResult: * - ReadResult:
* ReadOk, falls das lesen erfolgreich war * ReadOk, falls das lesen Erfolgreich war
* ReadErr..., falls die eingabe ungueltig ist. f ist dann nicht vollstaendig * ReadErr..., falls die Eingabe ungueltig ist. `f` ist dann nicht vollstaendig
* initialisiert * initialisiert
*/ */
ReadResult parse_input(Field *f) { ReadResult parse_input(Field *f) {
...@@ -170,10 +171,10 @@ ReadResult parse_input(Field *f) { ...@@ -170,10 +171,10 @@ ReadResult parse_input(Field *f) {
f->t_max.x = 0; f->t_max.x = 0;
f->t_max.y = 0; f->t_max.y = 0;
// initialisieren der Liste // initialisieren der Liste
list_init(&f->tiles); list_init(&f->tile_list);
while (1) { while (1) {
Tile *t = list_push(&f->tiles); // neues Element in die Liste einfuegen Tile *t = list_push(&f->tile_list); // neues Element in die Liste einfuegen
ReadResult result = read_line(t); ReadResult result = read_line(t);
switch (result) { switch (result) {
case ReadOk: case ReadOk:
...@@ -184,8 +185,8 @@ ReadResult parse_input(Field *f) { ...@@ -184,8 +185,8 @@ ReadResult parse_input(Field *f) {
f->t_max.y = max(f->t_max.x, t->y); f->t_max.y = max(f->t_max.x, t->y);
break; break;
case ReadEof: case ReadEof:
list_pop(&f->tiles); list_pop(&f->tile_list);
if (f->tiles.size == 1) { if (f->tile_list.size == 1) {
return ReadEof; return ReadEof;
} else { } else {
return ReadOk; return ReadOk;
...@@ -196,15 +197,14 @@ ReadResult parse_input(Field *f) { ...@@ -196,15 +197,14 @@ ReadResult parse_input(Field *f) {
} }
} }
int main (int argc, int main (void)
char *argv[])
{ {
Field f; Field f;
ReadResult result = parse_input(&f); ReadResult result = parse_input(&f);
switch (result) { switch (result) {
case ReadOk: case ReadOk:
printf("Valider Input\n"); printf("Valider Input\n");
printf("Anzahl: %d\n", f.tiles.size); printf("Anzahl: %d\n", f.tile_list.size);
printf("Range(%d, %d), (%d, %d)\n", printf("Range(%d, %d), (%d, %d)\n",
f.t_min.x, f.t_min.y, f.t_min.x, f.t_min.y,
f.t_max.x, f.t_max.y); f.t_max.x, f.t_max.y);
...@@ -216,22 +216,22 @@ int main (int argc, ...@@ -216,22 +216,22 @@ int main (int argc,
// bei leerer Eingabe nichts ausgeben // bei leerer Eingabe nichts ausgeben
return EXIT_SUCCESS; return EXIT_SUCCESS;
case ReadErrIntegerOverflow: case ReadErrIntegerOverflow:
fprintf(stderr, "Error in line %d: too big integer\n", f.tiles.size); fprintf(stderr, "Error in line %d: too big integer\n", f.tile_list.size);
list_free(&f.tiles); list_free(&f.tile_list);
return EXIT_FAILURE; return EXIT_FAILURE;
case ReadErrNonDigitCharacter: case ReadErrNonDigitCharacter:
fprintf(stderr, "Error in line %d: invalid character\n", f.tiles.size); fprintf(stderr, "Error in line %d: invalid character\n", f.tile_list.size);
list_free(&f.tiles); list_free(&f.tile_list);
return EXIT_FAILURE; return EXIT_FAILURE;
case ReadErrTooFewNumbers: case ReadErrTooFewNumbers:
fprintf(stderr, "Error in line %d: Too few numbers, expected exactly 2\n", fprintf(stderr, "Error in line %d: Too few numbers, expected exactly 2\n",
f.tiles.size); f.tile_list.size);
list_free(&f.tiles); list_free(&f.tile_list);
return EXIT_FAILURE; return EXIT_FAILURE;
case ReadErrTooManyNumbers: case ReadErrTooManyNumbers:
fprintf(stderr, "Error in line %d: Too much numbers, expected exactly 2\n", fprintf(stderr, "Error in line %d: Too much numbers, expected exactly 2\n",
f.tiles.size); f.tile_list.size);
list_free(&f.tiles); list_free(&f.tile_list);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment