hier sind die structs:
Funktion in der die Elemente eingefügt werden
Funktion für die Ausgabe der Liste.
Code:
typedef struct line
{
char *id;
int x1;
int y1;
int x2;
int y2;
} lineTyp;
typedef struct
{
char *pfad;
char *svg;
} names;
typedef struct
{
int offsetX;
int offsetY;
char prompt[4];
int defWidth;
int defHeight;
int defRad;
} defValue;
typedef struct rect
{
char *id;
int x;
int y;
int width;
int height;
char *fill;
} rectTyp;
typedef struct circle
{
char *id;
int cx;
int cy;
int r;
char *fill;
} circleTyp;
typedef struct polygon
{
char *id;
int *x;
int *y;
char *fill;
} polyTyp;
typedef struct text
{
char *id;
char *text;
int x;
int y;
int font_size;
char *fill;
} textTyp;
typedef struct liste
{
struct liste *next;
struct liste *last;
int head;
int shape;
void *inhalt;
} listenTyp;
struct liste *start=NULL; //Anfang Liste
struct liste *end=NULL; //Ende Liste
struct liste *temp=NULL; //Hilfszeiger
Funktion in der die Elemente eingefügt werden
Code:
void insert_list(void *daten, int shape) //wird so aufgerufen insert(&lin,1)
{
struct liste *pointerEnd;
if(start == NULL)
{
if((start = (struct liste *) malloc(sizeof(listenTyp))) == NULL)
{
printf("Kein Speicherplatz vorhanden für anfang\n");
return;
}
start->next = NULL;
start->last = NULL;
// Daten in das erste Element schreiben
if(shape==1) //Linie
{
//temp->inhalt = malloc(sizeof(temp->inhalt));
//temp->inhalt = (struct line*) malloc(sizeof(lineTyp));
start->inhalt = daten;
start->shape = 1;
start->next = NULL;
if(shape==2) //Rechteck
{
start->inhalt = daten;
start->shape = 2;
start->next = NULL;
}
if(shape==3) //Text
{
start->inhalt = daten;
start->shape = 3;
start->next = NULL;
}
if(shape==4) //Kreis
{
start->inhalt = daten;
start->shape = 4;
start->next = NULL;
}
}
else
{
temp = start;
while (temp->next != NULL)
{
temp = temp->next;
}
if((temp->next = (struct liste *)malloc(sizeof(listenTyp))) == NULL)
{
printf("Kein Speicherplatz für das letzte Element\n");
return;
}
temp=temp->next;
if(shape==1) //Linie
{
temp->inhalt = (struct line*) malloc(sizeof(lineTyp));
temp->inhalt = daten;
temp->shape = 1;
temp->next = NULL;
}
if(shape==2) //Rechteck
{
temp->inhalt = daten;
temp->shape = 2;
temp->next = NULL;
}
if(shape==3) //Text
{
temp->inhalt = daten;
temp->shape = 3;
temp->next = NULL;
}
if(shape==4) //Kreis
{
temp->inhalt = daten;
temp->shape = 4;
temp->next = NULL;
}
}
}
}
Funktion für die Ausgabe der Liste.
Code:
void ausgeben()
{
// Hilfszeiger auf den Anfang der Liste setzen
temp = start;
// Erstes Element ausgeben
if((temp->shape)==1)
{
//struct line test;// = (struct line *) malloc(sizeof(lineTyp));
//test = temp->inhalt;
struct line *test = &(struct line*)(temp->inhalt);
printf("\nid: %s \n",test->id);
printf("x1: %d \n",test->x1);
printf("x2: %d \n",test->x2);
printf("y1: %d \n",test->y1);
printf("y2: %d \n",test->y2);
printf("---------------------------------------\n");
}
if((temp->shape)==2)
{
struct rect *test = (struct rect *) malloc(sizeof(rectTyp));
test = (struct rect *)(temp->inhalt);
printf("\nid: %s \n",test->id);
printf("x: %d \n",test->x);
printf("y: %d \n",test->y);
printf("height: %d \n",test->height);
printf("width: %d \n",test->width);
printf("fill: %d \n",test->fill);
printf("---------------------------------------\n");
}
if((temp->shape)==3)
{
struct text *test = (struct text *) malloc(sizeof(textTyp));
test = (struct text *)(temp->inhalt);
printf("\nid: %s \n",test->id);
printf("x: %d \n",test->x);
printf("y: %d \n",test->y);
printf("height: %d \n",test->font_size);
printf("fill: %d \n",test->fill);
printf("---------------------------------------\n");
}
if((temp->shape)==4)
{
struct circle *test = (struct circle *) malloc(sizeof(circleTyp));
test = (struct circle *)(temp->inhalt);
printf("\nid: %s \n",test->id);
printf("cx: %d \n",test->cx);
printf("cy: %d \n",test->cy);
printf("r: %d \n",test->r);
printf("fill: %d \n",test->fill);
printf("---------------------------------------\n");
}
while (temp->next != NULL)
{
//Hilfszeiger auf nächstes Element setzen
temp = temp->next;
// Daten ausgeben
//temp->data.id = NULL;
if((temp->shape)==1)
{
/*struct line *test = (struct line *) malloc(sizeof(lineTyp));
test = (struct line *)(temp->inhalt);*/
struct line *test = &(struct line*)(temp->inhalt);
printf("\nid: %s \n",test->id);
printf("x1: %d \n",test->x1);
printf("x2: %d \n",test->x2);
printf("y1: %d \n",test->y1);
printf("y2: %d \n",test->y2);
printf("---------------------------------------\n");
}
if((temp->shape)==2)
{
struct rect *test = (struct rect *) malloc(sizeof(rectTyp));
test = (struct rect *)(temp->inhalt);
printf("\nid: %s \n",test->id);
printf("x: %d \n",test->x);
printf("y: %d \n",test->y);
printf("height: %d \n",test->height);
printf("width: %d \n",test->width);
printf("fill: %d \n",test->fill);
printf("---------------------------------------\n");
}
if((temp->shape)==3)
{
struct text *test = (struct text *) malloc(sizeof(textTyp));
test = (struct text *)(temp->inhalt);
printf("\nid: %s \n",test->id);
printf("x: %d \n",test->x);
printf("y: %d \n",test->y);
printf("height: %d \n",test->font_size);
printf("fill: %d \n",test->fill);
printf("---------------------------------------\n");
}
if((temp->shape)==4)
{
struct circle *test = (struct circle *) malloc(sizeof(circleTyp));
test = (struct circle *)(temp->inhalt);
printf("\nid: %s \n",test->id);
printf("cx: %d \n",test->cx);
printf("cy: %d \n",test->cy);
printf("r: %d \n",test->r);
printf("fill: %d \n",test->fill);
printf("---------------------------------------\n");
}
}
}