libDXF 0.0.1
A library with DXF related functions written in C.
|
00001 00035 #include "binary_graphics_data.h" 00036 00037 00043 DxfBinaryGraphicsData * 00044 dxf_binary_graphics_data_new () 00045 { 00046 #if DEBUG 00047 DXF_DEBUG_BEGIN 00048 #endif 00049 DxfBinaryGraphicsData *data = NULL; 00050 size_t size; 00051 00052 size = sizeof (DxfBinaryGraphicsData); 00053 /* avoid malloc of 0 bytes */ 00054 if (size == 0) size = 1; 00055 if ((data = malloc (size)) == NULL) 00056 { 00057 fprintf (stderr, 00058 (_("Error in %s () could not allocate memory for a DxfBinaryGraphicsData struct.\n")), 00059 __FUNCTION__); 00060 data = NULL; 00061 } 00062 else 00063 { 00064 memset (data, 0, size); 00065 } 00066 #if DEBUG 00067 DXF_DEBUG_END 00068 #endif 00069 return (data); 00070 } 00071 00072 00080 DxfBinaryGraphicsData * 00081 dxf_binary_graphics_data_init 00082 ( 00083 DxfBinaryGraphicsData *data 00085 ) 00086 { 00087 #if DEBUG 00088 DXF_DEBUG_BEGIN 00089 #endif 00090 /* Do some basic checks. */ 00091 if (data == NULL) 00092 { 00093 fprintf (stderr, 00094 (_("Warning in %s () a NULL pointer was passed.\n")), 00095 __FUNCTION__); 00096 data = dxf_binary_graphics_data_new (); 00097 } 00098 if (data == NULL) 00099 { 00100 fprintf (stderr, 00101 (_("Error in %s () could not allocate memory for a DxfBinaryGraphicsData struct.\n")), 00102 __FUNCTION__); 00103 return (NULL); 00104 } 00105 dxf_binary_graphics_data_set_data_line (data, strdup ("")); 00106 dxf_binary_graphics_data_set_length (data, 0); 00107 dxf_binary_graphics_data_set_next (data, NULL); 00108 #if DEBUG 00109 DXF_DEBUG_END 00110 #endif 00111 return (data); 00112 } 00113 00114 00121 int 00122 dxf_binary_graphics_data_write 00123 ( 00124 DxfFile *fp, 00126 DxfBinaryGraphicsData *data 00128 ) 00129 { 00130 #if DEBUG 00131 DXF_DEBUG_BEGIN 00132 #endif 00133 /* Do some basic checks. */ 00134 if (fp == NULL) 00135 { 00136 fprintf (stderr, 00137 (_("Error in %s () a NULL file pointer was passed.\n")), 00138 __FUNCTION__); 00139 return (EXIT_FAILURE); 00140 } 00141 /* Start writing output. */ 00142 fprintf (fp->fp, "310\n%s\n", data->data_line); 00143 #if DEBUG 00144 DXF_DEBUG_END 00145 #endif 00146 return (EXIT_SUCCESS); 00147 } 00148 00149 00157 int 00158 dxf_binary_graphics_data_free 00159 ( 00160 DxfBinaryGraphicsData *data 00163 ) 00164 { 00165 #if DEBUG 00166 DXF_DEBUG_BEGIN 00167 #endif 00168 /* Do some basic checks. */ 00169 if (data == NULL) 00170 { 00171 fprintf (stderr, 00172 (_("Error in %s () a NULL pointer was passed.\n")), 00173 __FUNCTION__); 00174 return (EXIT_FAILURE); 00175 } 00176 if (data->next != NULL) 00177 { 00178 fprintf (stderr, 00179 (_("Error in %s () pointer to next was not NULL.\n")), 00180 __FUNCTION__); 00181 return (EXIT_FAILURE); 00182 } 00183 free (data->data_line); 00184 free (data); 00185 data = NULL; 00186 #if DEBUG 00187 DXF_DEBUG_END 00188 #endif 00189 return (EXIT_SUCCESS); 00190 } 00191 00192 00197 void 00198 dxf_binary_graphics_data_free_chain 00199 ( 00200 DxfBinaryGraphicsData *data 00203 ) 00204 { 00205 #ifdef DEBUG 00206 DXF_DEBUG_BEGIN 00207 #endif 00208 /* Do some basic checks. */ 00209 if (data == NULL) 00210 { 00211 fprintf (stderr, 00212 (_("Warning in %s () a NULL pointer was passed.\n")), 00213 __FUNCTION__); 00214 } 00215 while (data != NULL) 00216 { 00217 struct DxfBinaryGraphicsData *iter = data->next; 00218 dxf_binary_graphics_data_free (data); 00219 data = (DxfBinaryGraphicsData *) iter; 00220 } 00221 #if DEBUG 00222 DXF_DEBUG_END 00223 #endif 00224 } 00225 00226 00232 char * 00233 dxf_binary_graphics_data_get_data_line 00234 ( 00235 DxfBinaryGraphicsData *data 00237 ) 00238 { 00239 #if DEBUG 00240 DXF_DEBUG_BEGIN 00241 #endif 00242 /* Do some basic checks. */ 00243 if (data == NULL) 00244 { 00245 fprintf (stderr, 00246 (_("Error in %s () a NULL pointer was passed.\n")), 00247 __FUNCTION__); 00248 return (NULL); 00249 } 00250 if (data->data_line == NULL) 00251 { 00252 fprintf (stderr, 00253 (_("Error in %s () a NULL pointer was found in the data_line member.\n")), 00254 __FUNCTION__); 00255 return (NULL); 00256 } 00257 #if DEBUG 00258 DXF_DEBUG_END 00259 #endif 00260 return (strdup (data->data_line)); 00261 } 00262 00263 00267 DxfBinaryGraphicsData * 00268 dxf_binary_graphics_data_set_data_line 00269 ( 00270 DxfBinaryGraphicsData *data, 00272 char *data_line 00274 ) 00275 { 00276 #if DEBUG 00277 DXF_DEBUG_BEGIN 00278 #endif 00279 /* Do some basic checks. */ 00280 if (data == NULL) 00281 { 00282 fprintf (stderr, 00283 (_("Error in %s () a NULL pointer was passed.\n")), 00284 __FUNCTION__); 00285 return (NULL); 00286 } 00287 if (data_line == NULL) 00288 { 00289 fprintf (stderr, 00290 (_("Error in %s () a NULL pointer was passed.\n")), 00291 __FUNCTION__); 00292 return (NULL); 00293 } 00294 data->data_line = strdup (data_line); 00295 #if DEBUG 00296 DXF_DEBUG_END 00297 #endif 00298 return (data); 00299 } 00300 00301 00307 int 00308 dxf_binary_graphics_data_get_length 00309 ( 00310 DxfBinaryGraphicsData *data 00312 ) 00313 { 00314 #if DEBUG 00315 DXF_DEBUG_BEGIN 00316 #endif 00317 /* Do some basic checks. */ 00318 if (data == NULL) 00319 { 00320 fprintf (stderr, 00321 (_("Error in %s () a NULL pointer was passed.\n")), 00322 __FUNCTION__); 00323 return (EXIT_FAILURE); 00324 } 00325 if (data->length < 0) 00326 { 00327 fprintf (stderr, 00328 (_("Error in %s () a negative value was found in the length member.\n")), 00329 __FUNCTION__); 00330 return (EXIT_FAILURE); 00331 } 00332 #if DEBUG 00333 DXF_DEBUG_END 00334 #endif 00335 return (data->length); 00336 } 00337 00338 00345 DxfBinaryGraphicsData * 00346 dxf_binary_graphics_data_set_length 00347 ( 00348 DxfBinaryGraphicsData *data, 00350 int length 00352 ) 00353 { 00354 #if DEBUG 00355 DXF_DEBUG_BEGIN 00356 #endif 00357 /* Do some basic checks. */ 00358 if (data == NULL) 00359 { 00360 fprintf (stderr, 00361 (_("Error in %s () a NULL pointer was passed.\n")), 00362 __FUNCTION__); 00363 return (NULL); 00364 } 00365 if (length < 0) 00366 { 00367 fprintf (stderr, 00368 (_("Error in %s () a negative length value was passed.\n")), 00369 __FUNCTION__); 00370 return (NULL); 00371 } 00372 data->length = length; 00373 #if DEBUG 00374 DXF_DEBUG_END 00375 #endif 00376 return (data); 00377 } 00378 00379 00388 DxfBinaryGraphicsData * 00389 dxf_binary_graphics_data_get_next 00390 ( 00391 DxfBinaryGraphicsData *data 00393 ) 00394 { 00395 #if DEBUG 00396 DXF_DEBUG_BEGIN 00397 #endif 00398 /* Do some basic checks. */ 00399 if (data == NULL) 00400 { 00401 fprintf (stderr, 00402 (_("Error in %s () a NULL pointer was passed.\n")), 00403 __FUNCTION__); 00404 return (NULL); 00405 } 00406 if (data->next == NULL) 00407 { 00408 fprintf (stderr, 00409 (_("Error in %s () a NULL pointer was found in the next member.\n")), 00410 __FUNCTION__); 00411 return (NULL); 00412 } 00413 #if DEBUG 00414 DXF_DEBUG_END 00415 #endif 00416 return ((DxfBinaryGraphicsData *) data->next); 00417 } 00418 00419 00424 DxfBinaryGraphicsData * 00425 dxf_binary_graphics_data_set_next 00426 ( 00427 DxfBinaryGraphicsData *data, 00429 DxfBinaryGraphicsData *next 00432 ) 00433 { 00434 #if DEBUG 00435 DXF_DEBUG_BEGIN 00436 #endif 00437 /* Do some basic checks. */ 00438 if (data == NULL) 00439 { 00440 fprintf (stderr, 00441 (_("Error in %s () a NULL pointer was passed.\n")), 00442 __FUNCTION__); 00443 return (NULL); 00444 } 00445 if (next == NULL) 00446 { 00447 fprintf (stderr, 00448 (_("Error in %s () a NULL pointer was passed.\n")), 00449 __FUNCTION__); 00450 return (NULL); 00451 } 00452 data->next = (struct DxfBinaryGraphicsData *) next; 00453 #if DEBUG 00454 DXF_DEBUG_END 00455 #endif 00456 return (data); 00457 } 00458 00459 00468 DxfBinaryGraphicsData * 00469 dxf_binary_graphics_data_get_last 00470 ( 00471 DxfBinaryGraphicsData *data 00473 ) 00474 { 00475 #if DEBUG 00476 DXF_DEBUG_BEGIN 00477 #endif 00478 /* Do some basic checks. */ 00479 if (data == NULL) 00480 { 00481 fprintf (stderr, 00482 (_("Error in %s () a NULL pointer was passed.\n")), 00483 __FUNCTION__); 00484 return (NULL); 00485 } 00486 if (data->next == NULL) 00487 { 00488 fprintf (stderr, 00489 (_("Warning in %s () a NULL pointer was found in the next member.\n")), 00490 __FUNCTION__); 00491 return ((DxfBinaryGraphicsData *) data); 00492 } 00493 DxfBinaryGraphicsData *iter = (DxfBinaryGraphicsData *) data->next; 00494 while (iter->next != NULL) 00495 { 00496 iter = (DxfBinaryGraphicsData *) iter->next; 00497 } 00498 #if DEBUG 00499 DXF_DEBUG_END 00500 #endif 00501 return ((DxfBinaryGraphicsData *) data->next); 00502 } 00503 00504 00505 /* EOF */