| 1 | typedef struct GC
 | 
| 2 | {
 | 
| 3 |     unsigned int G;               // G-Code
 | 
| 4 |     unsigned int X;               // X-Koordinate (Optional)
 | 
| 5 |     unsigned int Y;               // Y-Koordinate (Optional)
 | 
| 6 |     unsigned int D;               // D-Code (Optional)
 | 
| 7 |     struct DB *Block_Liste;       // Nur wenn dem G-Code ein Block folgt
 | 
| 8 | } G_CODE;
 | 
| 9 | 
 | 
| 10 | typedef struct DB
 | 
| 11 | { 
 | 
| 12 |     unsigned int X;               // X-Koordinate
 | 
| 13 |     unsigned int Y;               // Y-Koordinate
 | 
| 14 |     unsigned int PLOT_FUNCTION;   // D-Code
 | 
| 15 | } DATA_BLOCK;
 | 
| 16 | 
 | 
| 17 | 
 | 
| 18 | typedef struct Block
 | 
| 19 | {
 | 
| 20 |   char union_type;
 | 
| 21 |   union 
 | 
| 22 |   {
 | 
| 23 |     G_CODE  g;                          //Falls das Element ein G-Code ist
 | 
| 24 |     DATA_BLOCK data;                    //Falls das Element ein Data-Block ist        
 | 
| 25 |   } body;
 | 
| 26 |   struct Block *next;     
 | 
| 27 | } DATA_LIST;
 | 
| 28 | 
 | 
| 29 | 
 | 
| 30 | /*----------------------------------------------------------------------------*/
 | 
| 31 | /*----------------------------------------------------------------------------*/
 | 
| 32 | /*----------------------------------------------------------------------------*/
 | 
| 33 | /* Einfuegen von wert an passender Stelle (aufsteigend sortiert) */
 | 
| 34 | void Einfuegen_Block(DATA_LIST **pliste,G_CODE *g,DATA_BLOCK *data)
 | 
| 35 | {
 | 
| 36 |  if (*pliste==NULL)
 | 
| 37 |  {
 | 
| 38 |   *pliste = (DATA_LIST*)malloc(sizeof(DATA_LIST));
 | 
| 39 |   
 | 
| 40 |   if (*pliste == NULL)
 | 
| 41 |   {
 | 
| 42 |    fprintf(stderr,"\nmalloc()-Aufruf schlug fehl!\n");
 | 
| 43 | //   exit(0);
 | 
| 44 |   } /* end if malloc() schlug fehl */
 | 
| 45 |   
 | 
| 46 |   if( g != NULL)
 | 
| 47 |   {
 | 
| 48 |       (*pliste)->union_type = 1;
 | 
| 49 |       (*pliste)->body.g = *g; 
 | 
| 50 |       printf("\n\t%d\n",(*pliste)->union_type);
 | 
| 51 |   }          
 | 
| 52 |   else if ( data != NULL )
 | 
| 53 |   {
 | 
| 54 |       (*pliste)->union_type = 2;
 | 
| 55 |       (*pliste)->body.data = *data; 
 | 
| 56 |       printf("\n\t%d\n",(*pliste)->union_type);
 | 
| 57 |   }
 | 
| 58 |        
 | 
| 59 |   (*pliste)->next = NULL;
 | 
| 60 | 
 | 
| 61 |  } /* end if *pliste==NULL */
 | 
| 62 |  else 
 | 
| 63 |  {
 | 
| 64 | 
 | 
| 65 |   Einfuegen_Block(&((*pliste)->next),g,data);
 | 
| 66 |  } /* rekursiver Zweig - weiter hinten anhängen oder einfügen*/
 | 
| 67 | } /* end Einfuegen */
 | 
| 68 | 
 | 
| 69 | /*----------------------------------------------------------------------------*/
 | 
| 70 | /*----------------------------------------------------------------------------*/
 | 
| 71 | /*----------------------------------------------------------------------------*/
 | 
| 72 | /* Einfache Ausgabe der linearen Liste */
 | 
| 73 | void Ausgeben_Block(DATA_LIST *liste)
 | 
| 74 | {
 | 
| 75 | DATA_BLOCK data;
 | 
| 76 | int i,x;
 | 
| 77 |  if (liste==NULL)
 | 
| 78 |     printf("\n(Ende der Liste)\n");
 | 
| 79 |  else
 | 
| 80 |  {
 | 
| 81 |   printf("\n(Test %d)\n",(*liste).union_type);
 | 
| 82 |   if( ((*liste).union_type) == 1 )
 | 
| 83 |   {
 | 
| 84 |    printf("G%02d",liste->body.g.G);    
 | 
| 85 |   }
 | 
| 86 |   else if( ((*liste).union_type) == 2 )
 | 
| 87 |   {
 | 
| 88 |        
 | 
| 89 |   }
 | 
| 90 |   Ausgeben_Block(liste->next);   
 | 
| 91 |  }
 | 
| 92 | } /* end Ausgeben */
 | 
| 93 | 
 | 
| 94 | /*----------------------------------------------------------------------------*/
 | 
| 95 | /*----------------------------------------------------------------------------*/
 | 
| 96 | /*----------------------------------------------------------------------------*/
 | 
| 97 | 
 | 
| 98 | DATA_LIST *scan_line(char *s,DATA_LIST *pointer)
 | 
| 99 | {
 | 
| 100 | DATA_BLOCK data_block;
 | 
| 101 | G_CODE g_block;
 | 
| 102 | 
 | 
| 103 | 
 | 
| 104 | if( DATA_BLOCK_FILTER(s,&data_block) != NULL)
 | 
| 105 | {
 | 
| 106 | 
 | 
| 107 | Einfuegen_Block(pointer,NULL,&data_block);
 | 
| 108 | 
 | 
| 109 |  #if DEBUG == 1
 | 
| 110 |      printf("\n\tX = %d\n\tY = %d\n\tD = %d\n",data_block.X,data_block.Y,data_block.PLOT_FUNCTION);
 | 
| 111 |  #endif
 | 
| 112 | }
 | 
| 113 | else if ( G_CODE_FILTER(s,&g_block) != NULL)
 | 
| 114 | {
 | 
| 115 | Einfuegen_Block(pointer,&g_block,NULL);
 | 
| 116 |  #if DEBUG == 1
 | 
| 117 |      printf("\n\tG = %d\n\tX = %d\n\tY = %d\n\tD = %d\n",g_block.G,g_block.X,g_block.Y,g_block.D);
 | 
| 118 |  #endif     
 | 
| 119 | }
 | 
| 120 |        
 | 
| 121 | }
 | 
| 122 | 
 | 
| 123 | int main(void)
 | 
| 124 | {
 | 
| 125 | ....
 | 
| 126 | scan_line("G54D10*",&liste);
 | 
| 127 | 
 | 
| 128 | scan_line("X1000Y4356D01*",&liste);
 | 
| 129 | 
 | 
| 130 | Ausgeben_Block(&liste);
 | 
| 131 | ....
 | 
| 132 | }
 |