libDXF 0.0.1
A library with DXF related functions written in C.
|
00001 00043 #include "idbuffer.h" 00044 00045 00051 DxfIdbuffer * 00052 dxf_idbuffer_new () 00053 { 00054 #if DEBUG 00055 DXF_DEBUG_BEGIN 00056 #endif 00057 DxfIdbuffer *idbuffer = NULL; 00058 size_t size; 00059 00060 size = sizeof (DxfIdbuffer); 00061 /* avoid malloc of 0 bytes */ 00062 if (size == 0) size = 1; 00063 if ((idbuffer = malloc (size)) == NULL) 00064 { 00065 fprintf (stderr, 00066 (_("Error in %s () could not allocate memory for a DxfIdbuffer struct.\n")), 00067 __FUNCTION__); 00068 idbuffer = NULL; 00069 } 00070 else 00071 { 00072 memset (idbuffer, 0, size); 00073 } 00074 #if DEBUG 00075 DXF_DEBUG_END 00076 #endif 00077 return (idbuffer); 00078 } 00079 00080 00088 DxfIdbuffer * 00089 dxf_idbuffer_init 00090 ( 00091 DxfIdbuffer *idbuffer 00093 ) 00094 { 00095 #if DEBUG 00096 DXF_DEBUG_BEGIN 00097 #endif 00098 /* Do some basic checks. */ 00099 if (idbuffer == NULL) 00100 { 00101 fprintf (stderr, 00102 (_("Warning in %s () a NULL pointer was passed.\n")), 00103 __FUNCTION__); 00104 idbuffer = dxf_idbuffer_new (); 00105 } 00106 if (idbuffer == NULL) 00107 { 00108 fprintf (stderr, 00109 (_("Error in %s () could not allocate memory for a DxfIdbuffer struct.\n")), 00110 __FUNCTION__); 00111 return (NULL); 00112 } 00113 idbuffer->id_code = 0; 00114 idbuffer->dictionary_owner_soft = strdup (""); 00115 idbuffer->dictionary_owner_hard = strdup (""); 00116 idbuffer->entity_pointer = (DxfIdbufferEntityPointer *) dxf_idbuffer_entity_pointer_init (idbuffer->entity_pointer); 00117 idbuffer->next = NULL; 00118 #if DEBUG 00119 DXF_DEBUG_END 00120 #endif 00121 return (idbuffer); 00122 } 00123 00124 00136 DxfIdbuffer * 00137 dxf_idbuffer_read 00138 ( 00139 DxfFile *fp, 00141 DxfIdbuffer *idbuffer 00143 ) 00144 { 00145 #if DEBUG 00146 DXF_DEBUG_BEGIN 00147 #endif 00148 char *temp_string = NULL; 00149 int i; 00150 DxfIdbufferEntityPointer *entity_pointer = NULL; 00151 00152 /* Do some basic checks. */ 00153 if (fp == NULL) 00154 { 00155 fprintf (stderr, 00156 (_("Error in %s () a NULL file pointer was passed.\n")), 00157 __FUNCTION__); 00158 /* Clean up. */ 00159 free (temp_string); 00160 return (NULL); 00161 } 00162 if (fp->acad_version_number < AutoCAD_14) 00163 { 00164 fprintf (stderr, 00165 (_("Warning in %s () illegal DXF version for this entity.\n")), 00166 __FUNCTION__); 00167 } 00168 if (idbuffer == NULL) 00169 { 00170 fprintf (stderr, 00171 (_("Warning in %s () a NULL pointer was passed.\n")), 00172 __FUNCTION__); 00173 idbuffer = dxf_idbuffer_new (); 00174 idbuffer = dxf_idbuffer_init (idbuffer); 00175 } 00176 i = 0; 00177 entity_pointer = (DxfIdbufferEntityPointer *) dxf_idbuffer_entity_pointer_init (entity_pointer); 00178 (fp->line_number)++; 00179 fscanf (fp->fp, "%[^\n]", temp_string); 00180 while (strcmp (temp_string, "0") != 0) 00181 { 00182 if (ferror (fp->fp)) 00183 { 00184 fprintf (stderr, 00185 (_("Error in %s () while reading from: %s in line: %d.\n")), 00186 __FUNCTION__, fp->filename, fp->line_number); 00187 /* Clean up. */ 00188 free (temp_string); 00189 fclose (fp->fp); 00190 return (NULL); 00191 } 00192 if (strcmp (temp_string, "5") == 0) 00193 { 00194 /* Now follows a string containing a sequential 00195 * id number. */ 00196 (fp->line_number)++; 00197 fscanf (fp->fp, "%x\n", &idbuffer->id_code); 00198 } 00199 else if (strcmp (temp_string, "100") == 0) 00200 { 00201 /* Now follows a string containing the 00202 * subclass marker value. */ 00203 (fp->line_number)++; 00204 fscanf (fp->fp, "%s\n", temp_string); 00205 if (strcmp (temp_string, "AcDbIdBuffer") != 0) 00206 { 00207 fprintf (stderr, 00208 (_("Warning in %s () found a bad subclass marker in: %s in line: %d.\n")), 00209 __FUNCTION__, fp->filename, fp->line_number); 00210 } 00211 } 00212 else if ((strcmp (temp_string, "330") == 0) 00213 && (i == 0)) 00214 { 00215 /* Now follows a string containing Soft-pointer 00216 * ID/handle to owner dictionary. */ 00217 (fp->line_number)++; 00218 fscanf (fp->fp, "%s\n", idbuffer->dictionary_owner_soft); 00219 i++; 00220 } 00221 else if ((strcmp (temp_string, "330") == 0) 00222 && (i > 0)) 00223 { 00224 /* Now follows a string containing a Soft 00225 * pointer reference to entity. */ 00226 (fp->line_number)++; 00227 fscanf (fp->fp, "%s\n", entity_pointer->soft_pointer); 00228 dxf_idbuffer_entity_pointer_init ((DxfIdbufferEntityPointer *) entity_pointer->next); 00229 entity_pointer = (DxfIdbufferEntityPointer *) entity_pointer->next; 00230 } 00231 else if (strcmp (temp_string, "360") == 0) 00232 { 00233 /* Now follows a string containing Hard owner 00234 * ID/handle to owner dictionary. */ 00235 (fp->line_number)++; 00236 fscanf (fp->fp, "%s\n", idbuffer->dictionary_owner_hard); 00237 } 00238 else if (strcmp (temp_string, "999") == 0) 00239 { 00240 /* Now follows a string containing a comment. */ 00241 (fp->line_number)++; 00242 fscanf (fp->fp, "%s\n", temp_string); 00243 fprintf (stdout, (_("DXF comment: %s\n")), temp_string); 00244 } 00245 else 00246 { 00247 fprintf (stderr, 00248 (_("Warning in %s () unknown string tag found while reading from: %s in line: %d.\n")), 00249 __FUNCTION__, fp->filename, fp->line_number); 00250 } 00251 } 00252 /* Clean up. */ 00253 free (temp_string); 00254 #if DEBUG 00255 DXF_DEBUG_END 00256 #endif 00257 return (idbuffer); 00258 } 00259 00260 00267 int 00268 dxf_idbuffer_write 00269 ( 00270 DxfFile *fp, 00272 DxfIdbuffer *idbuffer 00274 ) 00275 { 00276 #if DEBUG 00277 DXF_DEBUG_BEGIN 00278 #endif 00279 char *dxf_entity_name = strdup ("IDBUFFER"); 00280 DxfIdbufferEntityPointer * entity_pointer = NULL; 00281 00282 /* Do some basic checks. */ 00283 if (fp == NULL) 00284 { 00285 fprintf (stderr, 00286 (_("Error in %s () a NULL file pointer was passed.\n")), 00287 __FUNCTION__); 00288 /* Clean up. */ 00289 free (dxf_entity_name); 00290 return (EXIT_FAILURE); 00291 } 00292 if (idbuffer == NULL) 00293 { 00294 fprintf (stderr, 00295 (_("Error in %s () a NULL pointer was passed.\n")), 00296 __FUNCTION__); 00297 /* Clean up. */ 00298 free (dxf_entity_name); 00299 return (EXIT_FAILURE); 00300 } 00301 if (fp->acad_version_number < AutoCAD_14) 00302 { 00303 fprintf (stderr, 00304 (_("Warning in %s () illegal DXF version for this %s entity with id-code: %x.\n")), 00305 __FUNCTION__, dxf_entity_name, dxf_idbuffer_get_id_code (idbuffer)); 00306 } 00307 /* Start writing output. */ 00308 fprintf (fp->fp, " 0\n%s\n", dxf_entity_name); 00309 if (dxf_idbuffer_get_id_code (idbuffer) != -1) 00310 { 00311 fprintf (fp->fp, " 5\n%x\n", dxf_idbuffer_get_id_code (idbuffer)); 00312 } 00323 if ((strcmp (idbuffer->dictionary_owner_soft, "") != 0) 00324 && (fp->acad_version_number >= AutoCAD_14)) 00325 { 00326 fprintf (fp->fp, "102\n{ACAD_REACTORS\n"); 00327 fprintf (fp->fp, "330\n%s\n", dxf_idbuffer_get_dictionary_owner_soft (idbuffer)); 00328 fprintf (fp->fp, "102\n}\n"); 00329 } 00330 if ((strcmp (idbuffer->dictionary_owner_hard, "") != 0) 00331 && (fp->acad_version_number >= AutoCAD_14)) 00332 { 00333 fprintf (fp->fp, "102\n{ACAD_XDICTIONARY\n"); 00334 fprintf (fp->fp, "360\n%s\n", dxf_idbuffer_get_dictionary_owner_hard (idbuffer)); 00335 fprintf (fp->fp, "102\n}\n"); 00336 } 00337 if (fp->acad_version_number >= AutoCAD_13) 00338 { 00339 fprintf (fp->fp, "100\nAcDbIdBuffer\n"); 00340 } 00341 entity_pointer = (DxfIdbufferEntityPointer *) dxf_idbuffer_get_entity_pointer (idbuffer); 00342 while (idbuffer->entity_pointer != NULL) 00343 { 00344 fprintf (fp->fp, "330\n%s\n", dxf_idbuffer_entity_pointer_get_soft_pointer (dxf_idbuffer_get_entity_pointer (idbuffer))); 00345 entity_pointer = dxf_idbuffer_entity_pointer_get_next (dxf_idbuffer_get_entity_pointer (idbuffer)); 00346 } 00347 /* Clean up. */ 00348 free (dxf_entity_name); 00349 #if DEBUG 00350 DXF_DEBUG_END 00351 #endif 00352 return (EXIT_SUCCESS); 00353 } 00354 00355 00363 int 00364 dxf_idbuffer_free 00365 ( 00366 DxfIdbuffer *idbuffer 00369 ) 00370 { 00371 #if DEBUG 00372 DXF_DEBUG_BEGIN 00373 #endif 00374 /* Do some basic checks. */ 00375 if (idbuffer == NULL) 00376 { 00377 fprintf (stderr, 00378 (_("Error in %s () a NULL pointer was passed.\n")), 00379 __FUNCTION__); 00380 return (EXIT_FAILURE); 00381 } 00382 if (idbuffer->next != NULL) 00383 { 00384 fprintf (stderr, 00385 (_("Error in %s () pointer to next was not NULL.\n")), 00386 __FUNCTION__); 00387 return (EXIT_FAILURE); 00388 } 00389 free (dxf_idbuffer_get_dictionary_owner_soft (idbuffer)); 00390 free (dxf_idbuffer_get_dictionary_owner_hard (idbuffer)); 00391 dxf_idbuffer_entity_pointer_free_chain ((DxfIdbufferEntityPointer *) dxf_idbuffer_get_entity_pointer (idbuffer)); 00392 free (idbuffer); 00393 idbuffer = NULL; 00394 #if DEBUG 00395 DXF_DEBUG_END 00396 #endif 00397 return (EXIT_SUCCESS); 00398 } 00399 00400 00405 void 00406 dxf_idbuffer_free_chain 00407 ( 00408 DxfIdbuffer *id_buffers 00410 ) 00411 { 00412 #ifdef DEBUG 00413 DXF_DEBUG_BEGIN 00414 #endif 00415 if (id_buffers == NULL) 00416 { 00417 fprintf (stderr, 00418 (_("Warning in %s () a NULL pointer was passed.\n")), 00419 __FUNCTION__); 00420 } 00421 while (id_buffers != NULL) 00422 { 00423 DxfIdbuffer *iter = (DxfIdbuffer *) dxf_idbuffer_get_next (id_buffers); 00424 dxf_idbuffer_free (id_buffers); 00425 id_buffers = (DxfIdbuffer *) iter; 00426 } 00427 #if DEBUG 00428 DXF_DEBUG_END 00429 #endif 00430 } 00431 00432 00439 int 00440 dxf_idbuffer_get_id_code 00441 ( 00442 DxfIdbuffer *idbuffer 00444 ) 00445 { 00446 #if DEBUG 00447 DXF_DEBUG_BEGIN 00448 #endif 00449 /* Do some basic checks. */ 00450 if (idbuffer == NULL) 00451 { 00452 fprintf (stderr, 00453 (_("Error in %s () a NULL pointer was passed.\n")), 00454 __FUNCTION__); 00455 return (EXIT_FAILURE); 00456 } 00457 if (idbuffer->id_code < 0) 00458 { 00459 fprintf (stderr, 00460 (_("Error in %s () a negative value was found in the id_code member.\n")), 00461 __FUNCTION__); 00462 return (EXIT_FAILURE); 00463 } 00464 #if DEBUG 00465 DXF_DEBUG_END 00466 #endif 00467 return (idbuffer->id_code); 00468 } 00469 00470 00477 DxfIdbuffer * 00478 dxf_idbuffer_set_id_code 00479 ( 00480 DxfIdbuffer *idbuffer, 00482 int id_code 00486 ) 00487 { 00488 #if DEBUG 00489 DXF_DEBUG_BEGIN 00490 #endif 00491 /* Do some basic checks. */ 00492 if (idbuffer == NULL) 00493 { 00494 fprintf (stderr, 00495 (_("Error in %s () a NULL pointer was passed.\n")), 00496 __FUNCTION__); 00497 return (NULL); 00498 } 00499 if (id_code < 0) 00500 { 00501 fprintf (stderr, 00502 (_("Error in %s () a negative id-code value was passed.\n")), 00503 __FUNCTION__); 00504 return (NULL); 00505 } 00506 idbuffer->id_code = id_code; 00507 #if DEBUG 00508 DXF_DEBUG_END 00509 #endif 00510 return (idbuffer); 00511 } 00512 00513 00523 char * 00524 dxf_idbuffer_get_dictionary_owner_soft 00525 ( 00526 DxfIdbuffer *idbuffer 00528 ) 00529 { 00530 #if DEBUG 00531 DXF_DEBUG_BEGIN 00532 #endif 00533 /* Do some basic checks. */ 00534 if (idbuffer == NULL) 00535 { 00536 fprintf (stderr, 00537 (_("Error in %s () a NULL pointer was passed.\n")), 00538 __FUNCTION__); 00539 return (NULL); 00540 } 00541 if (idbuffer->dictionary_owner_soft == NULL) 00542 { 00543 fprintf (stderr, 00544 (_("Error in %s () a NULL pointer was found in the dictionary_owner_soft member.\n")), 00545 __FUNCTION__); 00546 return (NULL); 00547 } 00548 #if DEBUG 00549 DXF_DEBUG_END 00550 #endif 00551 return (strdup (idbuffer->dictionary_owner_soft)); 00552 } 00553 00554 00562 DxfIdbuffer * 00563 dxf_idbuffer_set_dictionary_owner_soft 00564 ( 00565 DxfIdbuffer *idbuffer, 00567 char *dictionary_owner_soft 00570 ) 00571 { 00572 #if DEBUG 00573 DXF_DEBUG_BEGIN 00574 #endif 00575 /* Do some basic checks. */ 00576 if (idbuffer == NULL) 00577 { 00578 fprintf (stderr, 00579 (_("Error in %s () a NULL pointer was passed.\n")), 00580 __FUNCTION__); 00581 return (NULL); 00582 } 00583 if (dictionary_owner_soft == NULL) 00584 { 00585 fprintf (stderr, 00586 (_("Error in %s () a NULL pointer was passed.\n")), 00587 __FUNCTION__); 00588 return (NULL); 00589 } 00590 idbuffer->dictionary_owner_soft = strdup (dictionary_owner_soft); 00591 #if DEBUG 00592 DXF_DEBUG_END 00593 #endif 00594 return (idbuffer); 00595 } 00596 00597 00607 char * 00608 dxf_idbuffer_get_dictionary_owner_hard 00609 ( 00610 DxfIdbuffer *idbuffer 00612 ) 00613 { 00614 #if DEBUG 00615 DXF_DEBUG_BEGIN 00616 #endif 00617 /* Do some basic checks. */ 00618 if (idbuffer == NULL) 00619 { 00620 fprintf (stderr, 00621 (_("Error in %s () a NULL pointer was passed.\n")), 00622 __FUNCTION__); 00623 return (NULL); 00624 } 00625 if (idbuffer->dictionary_owner_soft == NULL) 00626 { 00627 fprintf (stderr, 00628 (_("Error in %s () a NULL pointer was found in the dictionary_owner_hard member.\n")), 00629 __FUNCTION__); 00630 return (NULL); 00631 } 00632 #if DEBUG 00633 DXF_DEBUG_END 00634 #endif 00635 return (strdup (idbuffer->dictionary_owner_hard)); 00636 } 00637 00638 00646 DxfIdbuffer * 00647 dxf_idbuffer_set_dictionary_owner_hard 00648 ( 00649 DxfIdbuffer *idbuffer, 00651 char *dictionary_owner_hard 00654 ) 00655 { 00656 #if DEBUG 00657 DXF_DEBUG_BEGIN 00658 #endif 00659 /* Do some basic checks. */ 00660 if (idbuffer == NULL) 00661 { 00662 fprintf (stderr, 00663 (_("Error in %s () a NULL pointer was passed.\n")), 00664 __FUNCTION__); 00665 return (NULL); 00666 } 00667 if (dictionary_owner_hard == NULL) 00668 { 00669 fprintf (stderr, 00670 (_("Error in %s () a NULL pointer was passed.\n")), 00671 __FUNCTION__); 00672 return (NULL); 00673 } 00674 idbuffer->dictionary_owner_hard = strdup (dictionary_owner_hard); 00675 #if DEBUG 00676 DXF_DEBUG_END 00677 #endif 00678 return (idbuffer); 00679 } 00680 00681 00690 DxfIdbufferEntityPointer * 00691 dxf_idbuffer_get_entity_pointer 00692 ( 00693 DxfIdbuffer *idbuffer 00695 ) 00696 { 00697 #if DEBUG 00698 DXF_DEBUG_BEGIN 00699 #endif 00700 /* Do some basic checks. */ 00701 if (idbuffer == NULL) 00702 { 00703 fprintf (stderr, 00704 (_("Error in %s () a NULL pointer was passed.\n")), 00705 __FUNCTION__); 00706 return (NULL); 00707 } 00708 if (idbuffer->entity_pointer == NULL) 00709 { 00710 fprintf (stderr, 00711 (_("Error in %s () a NULL pointer was found in the entity_pointer member.\n")), 00712 __FUNCTION__); 00713 return (NULL); 00714 } 00715 #if DEBUG 00716 DXF_DEBUG_END 00717 #endif 00718 return ((DxfIdbufferEntityPointer *) idbuffer->entity_pointer); 00719 } 00720 00721 00729 DxfIdbuffer * 00730 dxf_idbuffer_set_entity_pointer 00731 ( 00732 DxfIdbuffer *idbuffer, 00734 DxfIdbufferEntityPointer *entity_pointer 00737 ) 00738 { 00739 #if DEBUG 00740 DXF_DEBUG_BEGIN 00741 #endif 00742 /* Do some basic checks. */ 00743 if (idbuffer == NULL) 00744 { 00745 fprintf (stderr, 00746 (_("Error in %s () a NULL pointer was passed.\n")), 00747 __FUNCTION__); 00748 return (NULL); 00749 } 00750 if (entity_pointer == NULL) 00751 { 00752 fprintf (stderr, 00753 (_("Error in %s () a NULL pointer was passed.\n")), 00754 __FUNCTION__); 00755 return (NULL); 00756 } 00757 idbuffer->entity_pointer = (DxfIdbufferEntityPointer *) entity_pointer; 00758 #if DEBUG 00759 DXF_DEBUG_END 00760 #endif 00761 return (idbuffer); 00762 } 00763 00764 00773 DxfIdbuffer * 00774 dxf_idbuffer_get_next 00775 ( 00776 DxfIdbuffer *idbuffer 00778 ) 00779 { 00780 #if DEBUG 00781 DXF_DEBUG_BEGIN 00782 #endif 00783 /* Do some basic checks. */ 00784 if (idbuffer == NULL) 00785 { 00786 fprintf (stderr, 00787 (_("Error in %s () a NULL pointer was passed.\n")), 00788 __FUNCTION__); 00789 return (NULL); 00790 } 00791 if (idbuffer->next == NULL) 00792 { 00793 fprintf (stderr, 00794 (_("Error in %s () a NULL pointer was found in the next member.\n")), 00795 __FUNCTION__); 00796 return (NULL); 00797 } 00798 #if DEBUG 00799 DXF_DEBUG_END 00800 #endif 00801 return ((DxfIdbuffer *) idbuffer->next); 00802 } 00803 00804 00812 DxfIdbuffer * 00813 dxf_idbuffer_set_next 00814 ( 00815 DxfIdbuffer *idbuffer, 00817 DxfIdbuffer *next 00819 ) 00820 { 00821 #if DEBUG 00822 DXF_DEBUG_BEGIN 00823 #endif 00824 /* Do some basic checks. */ 00825 if (idbuffer == NULL) 00826 { 00827 fprintf (stderr, 00828 (_("Error in %s () a NULL pointer was passed.\n")), 00829 __FUNCTION__); 00830 return (NULL); 00831 } 00832 if (next == NULL) 00833 { 00834 fprintf (stderr, 00835 (_("Error in %s () a NULL pointer was passed.\n")), 00836 __FUNCTION__); 00837 return (NULL); 00838 } 00839 idbuffer->next = (struct DxfIdbuffer *) next; 00840 #if DEBUG 00841 DXF_DEBUG_END 00842 #endif 00843 return (idbuffer); 00844 } 00845 00846 00855 DxfIdbuffer * 00856 dxf_idbuffer_get_last 00857 ( 00858 DxfIdbuffer *idbuffer 00860 ) 00861 { 00862 #if DEBUG 00863 DXF_DEBUG_BEGIN 00864 #endif 00865 /* Do some basic checks. */ 00866 if (idbuffer == NULL) 00867 { 00868 fprintf (stderr, 00869 (_("Error in %s () a NULL pointer was passed.\n")), 00870 __FUNCTION__); 00871 return (NULL); 00872 } 00873 if (idbuffer->next == NULL) 00874 { 00875 fprintf (stderr, 00876 (_("Warning in %s () a NULL pointer was found in the next member.\n")), 00877 __FUNCTION__); 00878 return ((DxfIdbuffer *) idbuffer); 00879 } 00880 DxfIdbuffer *iter = (DxfIdbuffer *) idbuffer->next; 00881 while (iter->next != NULL) 00882 { 00883 iter = (DxfIdbuffer *) iter->next; 00884 } 00885 #if DEBUG 00886 DXF_DEBUG_END 00887 #endif 00888 return ((DxfIdbuffer *) iter); 00889 } 00890 00891 00897 DxfIdbufferEntityPointer * 00898 dxf_idbuffer_entity_pointer_new () 00899 { 00900 #if DEBUG 00901 DXF_DEBUG_BEGIN 00902 #endif 00903 DxfIdbufferEntityPointer *entity_pointer = NULL; 00904 size_t size; 00905 00906 size = sizeof (DxfIdbufferEntityPointer); 00907 /* avoid malloc of 0 bytes */ 00908 if (size == 0) size = 1; 00909 if ((entity_pointer = malloc (size)) == NULL) 00910 { 00911 fprintf (stderr, 00912 (_("Error in %s () could not allocate memory for a DxfIdbufferEntityPointer struct.\n")), 00913 __FUNCTION__); 00914 entity_pointer = NULL; 00915 } 00916 else 00917 { 00918 memset (entity_pointer, 0, size); 00919 } 00920 #if DEBUG 00921 DXF_DEBUG_END 00922 #endif 00923 return (entity_pointer); 00924 } 00925 00926 00934 DxfIdbufferEntityPointer * 00935 dxf_idbuffer_entity_pointer_init 00936 ( 00937 DxfIdbufferEntityPointer *entity_pointer 00939 ) 00940 { 00941 #if DEBUG 00942 DXF_DEBUG_BEGIN 00943 #endif 00944 /* Do some basic checks. */ 00945 if (entity_pointer == NULL) 00946 { 00947 fprintf (stderr, 00948 (_("Warning in %s () a NULL pointer was passed.\n")), 00949 __FUNCTION__); 00950 entity_pointer = dxf_idbuffer_entity_pointer_new (); 00951 } 00952 if (entity_pointer == NULL) 00953 { 00954 fprintf (stderr, 00955 (_("Error in %s () could not allocate memory for a DxfIdbufferEntityPointer struct.\n")), 00956 __FUNCTION__); 00957 return (NULL); 00958 } 00959 entity_pointer->soft_pointer = strdup (""); 00960 entity_pointer->next = NULL; 00961 #if DEBUG 00962 DXF_DEBUG_END 00963 #endif 00964 return (entity_pointer); 00965 } 00966 00967 00975 int 00976 dxf_idbuffer_entity_pointer_free 00977 ( 00978 DxfIdbufferEntityPointer *entity_pointer 00981 ) 00982 { 00983 #if DEBUG 00984 DXF_DEBUG_BEGIN 00985 #endif 00986 /* Do some basic checks. */ 00987 if (entity_pointer == NULL) 00988 { 00989 fprintf (stderr, 00990 (_("Error in %s () a NULL pointer was passed.\n")), 00991 __FUNCTION__); 00992 return (EXIT_FAILURE); 00993 } 00994 if (entity_pointer->next != NULL) 00995 { 00996 fprintf (stderr, 00997 (_("Error in %s () pointer to next was not NULL.\n")), 00998 __FUNCTION__); 00999 return (EXIT_FAILURE); 01000 } 01001 free (entity_pointer->soft_pointer); 01002 free (entity_pointer); 01003 entity_pointer = NULL; 01004 #if DEBUG 01005 DXF_DEBUG_END 01006 #endif 01007 return (EXIT_SUCCESS); 01008 } 01009 01010 01015 void 01016 dxf_idbuffer_entity_pointer_free_chain 01017 ( 01018 DxfIdbufferEntityPointer *entity_pointers 01021 ) 01022 { 01023 #ifdef DEBUG 01024 DXF_DEBUG_BEGIN 01025 #endif 01026 if (entity_pointers == NULL) 01027 { 01028 fprintf (stderr, 01029 (_("Warning in %s () a NULL pointer was passed.\n")), 01030 __FUNCTION__); 01031 } 01032 while (entity_pointers != NULL) 01033 { 01034 struct DxfIdbufferEntityPointer *iter = entity_pointers->next; 01035 dxf_idbuffer_entity_pointer_free (entity_pointers); 01036 entity_pointers = (DxfIdbufferEntityPointer *) iter; 01037 } 01038 #if DEBUG 01039 DXF_DEBUG_END 01040 #endif 01041 } 01042 01043 01053 char * 01054 dxf_idbuffer_entity_pointer_get_soft_pointer 01055 ( 01056 DxfIdbufferEntityPointer *entity_pointer 01058 ) 01059 { 01060 #if DEBUG 01061 DXF_DEBUG_BEGIN 01062 #endif 01063 /* Do some basic checks. */ 01064 if (entity_pointer == NULL) 01065 { 01066 fprintf (stderr, 01067 (_("Error in %s () a NULL pointer was passed.\n")), 01068 __FUNCTION__); 01069 return (NULL); 01070 } 01071 if (entity_pointer->soft_pointer == NULL) 01072 { 01073 fprintf (stderr, 01074 (_("Error in %s () a NULL pointer was found in the soft_pointer member.\n")), 01075 __FUNCTION__); 01076 return (NULL); 01077 } 01078 #if DEBUG 01079 DXF_DEBUG_END 01080 #endif 01081 return (strdup (entity_pointer->soft_pointer)); 01082 } 01083 01084 01092 DxfIdbufferEntityPointer * 01093 dxf_idbuffer_entity_pointer_set_soft_pointer 01094 ( 01095 DxfIdbufferEntityPointer *entity_pointer, 01097 char *soft_pointer 01100 ) 01101 { 01102 #if DEBUG 01103 DXF_DEBUG_BEGIN 01104 #endif 01105 /* Do some basic checks. */ 01106 if (entity_pointer == NULL) 01107 { 01108 fprintf (stderr, 01109 (_("Error in %s () a NULL pointer was passed.\n")), 01110 __FUNCTION__); 01111 return (NULL); 01112 } 01113 if (soft_pointer == NULL) 01114 { 01115 fprintf (stderr, 01116 (_("Error in %s () a NULL pointer was passed.\n")), 01117 __FUNCTION__); 01118 return (NULL); 01119 } 01120 entity_pointer->soft_pointer = strdup (soft_pointer); 01121 #if DEBUG 01122 DXF_DEBUG_END 01123 #endif 01124 return (entity_pointer); 01125 } 01126 01127 01136 DxfIdbufferEntityPointer * 01137 dxf_idbuffer_entity_pointer_get_next 01138 ( 01139 DxfIdbufferEntityPointer *entity_pointer 01141 ) 01142 { 01143 #if DEBUG 01144 DXF_DEBUG_BEGIN 01145 #endif 01146 /* Do some basic checks. */ 01147 if (entity_pointer == NULL) 01148 { 01149 fprintf (stderr, 01150 (_("Error in %s () a NULL pointer was passed.\n")), 01151 __FUNCTION__); 01152 return (NULL); 01153 } 01154 if (entity_pointer->next == NULL) 01155 { 01156 fprintf (stderr, 01157 (_("Error in %s () a NULL pointer was found in the next member.\n")), 01158 __FUNCTION__); 01159 return (NULL); 01160 } 01161 #if DEBUG 01162 DXF_DEBUG_END 01163 #endif 01164 return ((DxfIdbufferEntityPointer *) entity_pointer->next); 01165 } 01166 01167 01175 DxfIdbufferEntityPointer* 01176 dxf_idbuffer_entity_pointer_set_next 01177 ( 01178 DxfIdbufferEntityPointer *entity_pointer, 01181 DxfIdbufferEntityPointer *next 01184 ) 01185 { 01186 #if DEBUG 01187 DXF_DEBUG_BEGIN 01188 #endif 01189 /* Do some basic checks. */ 01190 if (entity_pointer == NULL) 01191 { 01192 fprintf (stderr, 01193 (_("Error in %s () a NULL pointer was passed.\n")), 01194 __FUNCTION__); 01195 return (NULL); 01196 } 01197 if (next == NULL) 01198 { 01199 fprintf (stderr, 01200 (_("Error in %s () a NULL pointer was passed.\n")), 01201 __FUNCTION__); 01202 return (NULL); 01203 } 01204 entity_pointer->next = (struct DxfIdbufferEntityPointer *) next; 01205 #if DEBUG 01206 DXF_DEBUG_END 01207 #endif 01208 return (entity_pointer); 01209 } 01210 01211 01220 DxfIdbufferEntityPointer * 01221 dxf_idbuffer_entity_pointer_get_last 01222 ( 01223 DxfIdbufferEntityPointer *entity_pointer 01226 ) 01227 { 01228 #if DEBUG 01229 DXF_DEBUG_BEGIN 01230 #endif 01231 /* Do some basic checks. */ 01232 if (entity_pointer == NULL) 01233 { 01234 fprintf (stderr, 01235 (_("Error in %s () a NULL pointer was passed.\n")), 01236 __FUNCTION__); 01237 return (NULL); 01238 } 01239 if (entity_pointer->next == NULL) 01240 { 01241 fprintf (stderr, 01242 (_("Warning in %s () a NULL pointer was found in the next member.\n")), 01243 __FUNCTION__); 01244 return ((DxfIdbufferEntityPointer *) entity_pointer); 01245 } 01246 DxfIdbufferEntityPointer *iter = (DxfIdbufferEntityPointer *) entity_pointer->next; 01247 while (iter->next != NULL) 01248 { 01249 iter = (DxfIdbufferEntityPointer *) iter->next; 01250 } 01251 #if DEBUG 01252 DXF_DEBUG_END 01253 #endif 01254 return ((DxfIdbufferEntityPointer *) iter); 01255 } 01256 01257 01258 /* EOF*/