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

added more warnings

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