libDXF 0.0.1
A library with DXF related functions written in C.

appid.c

Go to the documentation of this file.
00001 
00059 #include "appid.h"
00060 
00061 
00067 DxfAppid *
00068 dxf_appid_new ()
00069 {
00070 #if DEBUG
00071         DXF_DEBUG_BEGIN
00072 #endif
00073         DxfAppid *appid = NULL;
00074         size_t size;
00075 
00076         size = sizeof (DxfAppid);
00077         /* avoid malloc of 0 bytes */
00078         if (size == 0) size = 1;
00079         if ((appid = malloc (size)) == NULL)
00080         {
00081                 fprintf (stderr,
00082                   (_("Error in %s () could not allocate memory.\n")),
00083                   __FUNCTION__);
00084                 appid = NULL;
00085         }
00086         else
00087         {
00088                 memset (appid, 0, size);
00089         }
00090 #if DEBUG
00091         DXF_DEBUG_END
00092 #endif
00093         return (appid);
00094 }
00095 
00096 
00104 DxfAppid *
00105 dxf_appid_init
00106 (
00107         DxfAppid *appid
00109 )
00110 {
00111 #if DEBUG
00112         DXF_DEBUG_BEGIN
00113 #endif
00114         /* Do some basic checks. */
00115         if (appid == NULL)
00116         {
00117                 fprintf (stderr,
00118                   (_("Warning in %s () a NULL pointer was passed.\n")),
00119                   __FUNCTION__);
00120                 appid = dxf_appid_new ();
00121         }
00122         if (appid == NULL)
00123         {
00124                 fprintf (stderr,
00125                   (_("Error in %s () could not allocate memory.\n")),
00126                   __FUNCTION__);
00127                 return (NULL);
00128         }
00129         dxf_appid_set_id_code (appid, 0);
00130         dxf_appid_set_application_name (appid, strdup (""));
00131         dxf_appid_set_flag (appid, 0);
00132         dxf_appid_set_dictionary_owner_soft (appid, strdup (""));
00133         dxf_appid_set_dictionary_owner_hard (appid, strdup (""));
00134         dxf_appid_set_next (appid, NULL);
00135 #if DEBUG
00136         DXF_DEBUG_END
00137 #endif
00138         return (appid);
00139 }
00140 
00141 
00154 DxfAppid *
00155 dxf_appid_read
00156 (
00157         DxfFile *fp,
00159         DxfAppid *appid
00161 )
00162 {
00163 #if DEBUG
00164         DXF_DEBUG_BEGIN
00165 #endif
00166         char *temp_string = NULL;
00167 
00168         /* Do some basic checks. */
00169         if (fp == NULL)
00170         {
00171                 fprintf (stderr,
00172                   (_("Error in %s () a NULL file pointer was passed.\n")),
00173                   __FUNCTION__);
00174                 /* Clean up. */
00175                 free (temp_string);
00176                 return (NULL);
00177         }
00178         if (appid == NULL)
00179         {
00180                 fprintf (stderr,
00181                   (_("Warning in %s () a NULL pointer was passed.\n")),
00182                   __FUNCTION__);
00183                 appid = dxf_appid_new ();
00184                 appid = dxf_appid_init (appid);
00185         }
00186         (fp->line_number)++;
00187         fscanf (fp->fp, "%[^\n]", temp_string);
00188         while (strcmp (temp_string, "0") != 0)
00189         {
00190                 if (ferror (fp->fp))
00191                 {
00192                         fprintf (stderr,
00193                           (_("Error in %s () while reading from: %s in line: %d.\n")),
00194                           __FUNCTION__, fp->filename, fp->line_number);
00195                         fclose (fp->fp);
00196                         /* Clean up. */
00197                         free (temp_string);
00198                         return (NULL);
00199                 }
00200                 if (strcmp (temp_string, "5") == 0)
00201                 {
00202                         /* Now follows a string containing a sequential
00203                          * id number. */
00204                         (fp->line_number)++;
00205                         fscanf (fp->fp, "%x\n", &appid->id_code);
00206                 }
00207                 else if (strcmp (temp_string, "2") == 0)
00208                 {
00209                         /* Now follows a string containing an application
00210                          * name. */
00211                         (fp->line_number)++;
00212                         fscanf (fp->fp, "%s\n", appid->application_name);
00213                 }
00214                 else if (strcmp (temp_string, "70") == 0)
00215                 {
00216                         /* Now follows a string containing the
00217                          * standard flag value. */
00218                         (fp->line_number)++;
00219                         fscanf (fp->fp, "%d\n", &appid->flag);
00220                 }
00221                 else if (strcmp (temp_string, "330") == 0)
00222                 {
00223                         /* Now follows a string containing Soft-pointer
00224                          * ID/handle to owner dictionary. */
00225                         (fp->line_number)++;
00226                         fscanf (fp->fp, "%s\n", appid->dictionary_owner_soft);
00227                 }
00228                 else if (strcmp (temp_string, "360") == 0)
00229                 {
00230                         /* Now follows a string containing Hard owner
00231                          * ID/handle to owner dictionary. */
00232                         (fp->line_number)++;
00233                         fscanf (fp->fp, "%s\n", appid->dictionary_owner_hard);
00234                 }
00235                 else if (strcmp (temp_string, "999") == 0)
00236                 {
00237                         /* Now follows a string containing a comment. */
00238                         (fp->line_number)++;
00239                         fscanf (fp->fp, "%s\n", temp_string);
00240                         fprintf (stdout, "DXF comment: %s\n", temp_string);
00241                 }
00242                 else
00243                 {
00244                         fprintf (stderr,
00245                           (_("Warning in %s () unknown string tag found while reading from: %s in line: %d.\n")),
00246                           __FUNCTION__, fp->filename, fp->line_number);
00247                 }
00248         }
00249         /* Clean up. */
00250         free (temp_string);
00251 #if DEBUG
00252         DXF_DEBUG_END
00253 #endif
00254         return (appid);
00255 }
00256 
00257 
00262 int
00263 dxf_appid_write
00264 (
00265         DxfFile *fp,
00267         DxfAppid *appid
00269 )
00270 {
00271 #if DEBUG
00272         DXF_DEBUG_BEGIN
00273 #endif
00274         char *dxf_entity_name = strdup ("APPID");
00275 
00276         /* Do some basic checks. */
00277         if (fp == NULL)
00278         {
00279                 fprintf (stderr,
00280                   (_("Error in %s () a NULL file pointer was passed.\n")),
00281                   __FUNCTION__);
00282                 /* Clean up. */
00283                 free (dxf_entity_name);
00284                 return (EXIT_FAILURE);
00285         }
00286         if (appid == NULL)
00287         {
00288                 fprintf (stderr,
00289                   (_("Error in %s () a NULL pointer was passed.\n")),
00290                   __FUNCTION__);
00291                 /* Clean up. */
00292                 free (dxf_entity_name);
00293                 return (EXIT_FAILURE);
00294         }
00295         if ((dxf_appid_get_application_name (appid) == NULL)
00296           || (strcmp (dxf_appid_get_application_name (appid), "") == 0))
00297         {
00298                 fprintf (stderr,
00299                   (_("Error in %s empty string for the %s entity with id-code: %x\n")),
00300                   __FUNCTION__, dxf_entity_name, dxf_appid_get_id_code (appid));
00301                 fprintf (stderr,
00302                   (_("\t%s entity is discarded from output.\n")),
00303                   dxf_entity_name);
00304                 /* Clean up. */
00305                 free (dxf_entity_name);
00306                 return (EXIT_FAILURE);
00307         }
00308         if (fp->acad_version_number < AutoCAD_12)
00309         {
00310                 fprintf (stderr,
00311                   (_("Warning in %s () illegal DXF version for this entity.\n")),
00312                   __FUNCTION__);
00313         }
00314         /* Start writing output. */
00315         fprintf (fp->fp, "  0\n%s\n", dxf_entity_name);
00316         if (dxf_appid_get_id_code (appid) != -1)
00317         {
00318                 fprintf (fp->fp, "  5\n%x\n", dxf_appid_get_id_code (appid));
00319         }
00330         if ((strcmp (dxf_appid_get_dictionary_owner_soft (appid), "") != 0)
00331           && (fp->acad_version_number >= AutoCAD_14))
00332         {
00333                 fprintf (fp->fp, "102\n{ACAD_REACTORS\n");
00334                 fprintf (fp->fp, "330\n%s\n", dxf_appid_get_dictionary_owner_soft (appid));
00335                 fprintf (fp->fp, "102\n}\n");
00336         }
00337         if ((strcmp (dxf_appid_get_dictionary_owner_hard (appid), "") != 0)
00338           && (fp->acad_version_number >= AutoCAD_14))
00339         {
00340                 fprintf (fp->fp, "102\n{ACAD_XDICTIONARY\n");
00341                 fprintf (fp->fp, "360\n%s\n", dxf_appid_get_dictionary_owner_hard (appid));
00342                 fprintf (fp->fp, "102\n}\n");
00343         }
00344         if (fp->acad_version_number >= AutoCAD_13)
00345         {
00346                 fprintf (fp->fp, "100\nAcDbSymbolTableRecord\n");
00347                 fprintf (fp->fp, "100\nAcDbRegAppTableRecord\n");
00348         }
00349         fprintf (fp->fp, "  2\n%s\n", dxf_appid_get_application_name (appid));
00350         fprintf (fp->fp, " 70\n%d\n", dxf_appid_get_flag (appid));
00351         /* Clean up. */
00352         free (dxf_entity_name);
00353 #if DEBUG
00354         DXF_DEBUG_END
00355 #endif
00356         return (EXIT_SUCCESS);
00357 }
00358 
00359 
00367 int
00368 dxf_appid_free
00369 (
00370         DxfAppid *appid
00372 )
00373 {
00374 #if DEBUG
00375         DXF_DEBUG_BEGIN
00376 #endif
00377         if (appid == NULL)
00378         {
00379                 fprintf (stderr,
00380                   (_("Error in %s () a NULL pointer was passed.\n")),
00381                   __FUNCTION__);
00382                 return (EXIT_FAILURE);
00383         }
00384         if (appid->next != NULL)
00385         {
00386               fprintf (stderr,
00387                 (_("Error in %s () pointer to next was not NULL.\n")),
00388                 __FUNCTION__);
00389               return (EXIT_FAILURE);
00390         }
00391         free (appid->application_name);
00392         free (appid->dictionary_owner_soft);
00393         free (appid->dictionary_owner_hard);
00394         free (appid);
00395         appid = NULL;
00396 #if DEBUG
00397         DXF_DEBUG_END
00398 #endif
00399         return (EXIT_SUCCESS);
00400 }
00401 
00402 
00407 void
00408 dxf_appid_free_chain
00409 (
00410         DxfAppid *appids
00413 )
00414 {
00415 #ifdef DEBUG
00416         DXF_DEBUG_BEGIN
00417 #endif
00418         if (appids == NULL)
00419         {
00420                 fprintf (stderr,
00421                   (_("Warning in %s () a NULL pointer was passed.\n")),
00422                   __FUNCTION__);
00423         }
00424         while (appids != NULL)
00425         {
00426                 struct DxfAppid *iter = appids->next;
00427                 dxf_appid_free (appids);
00428                 appids = (DxfAppid *) iter;
00429         }
00430 #if DEBUG
00431         DXF_DEBUG_END
00432 #endif
00433 }
00434 
00435 
00441 int
00442 dxf_appid_get_id_code
00443 (
00444         DxfAppid *appid
00446 )
00447 {
00448 #if DEBUG
00449         DXF_DEBUG_BEGIN
00450 #endif
00451         /* Do some basic checks. */
00452         if (appid == NULL)
00453         {
00454                 fprintf (stderr,
00455                   (_("Error in %s () a NULL pointer was passed.\n")),
00456                   __FUNCTION__);
00457                 return (EXIT_FAILURE);
00458         }
00459 #if DEBUG
00460         DXF_DEBUG_END
00461 #endif
00462         return (appid->id_code);
00463 }
00464 
00465 
00469 DxfAppid *
00470 dxf_appid_set_id_code
00471 (
00472         DxfAppid *appid,
00474         int id_code
00478 )
00479 {
00480 #if DEBUG
00481         DXF_DEBUG_BEGIN
00482 #endif
00483         /* Do some basic checks. */
00484         if (appid == NULL)
00485         {
00486                 fprintf (stderr,
00487                   (_("Error in %s () a NULL pointer was passed.\n")),
00488                   __FUNCTION__);
00489                 return (NULL);
00490         }
00491         appid->id_code = id_code;
00492 #if DEBUG
00493         DXF_DEBUG_END
00494 #endif
00495         return (appid);
00496 }
00497 
00498 
00505 char *
00506 dxf_appid_get_application_name
00507 (
00508         DxfAppid *appid
00510 )
00511 {
00512 #if DEBUG
00513         DXF_DEBUG_BEGIN
00514 #endif
00515         /* Do some basic checks. */
00516         if (appid == NULL)
00517         {
00518                 fprintf (stderr,
00519                   (_("Error in %s () a NULL pointer was passed.\n")),
00520                   __FUNCTION__);
00521                 return (NULL);
00522         }
00523 #if DEBUG
00524         DXF_DEBUG_END
00525 #endif
00526         return (strdup (appid->application_name));
00527 }
00528 
00529 
00543 DxfAppid *
00544 dxf_appid_set_application_name
00545 (
00546         DxfAppid *appid,
00548         char *name
00550 )
00551 {
00552 #if DEBUG
00553         DXF_DEBUG_BEGIN
00554 #endif
00555         /* Do some basic checks. */
00556         if (appid == NULL)
00557         {
00558                 fprintf (stderr,
00559                   (_("Error in %s () a NULL pointer was passed.\n")),
00560                   __FUNCTION__);
00561                 return (NULL);
00562         }
00563         if (name == NULL)
00564         {
00565                 fprintf (stderr,
00566                   (_("Warning in %s () the string name contained a NULL pointer.\n")),
00567                   __FUNCTION__);
00568                 return (NULL);
00569         }
00570         appid->application_name = strdup (name);
00571 #if DEBUG
00572         DXF_DEBUG_END
00573 #endif
00574         return (appid);
00575 }
00576 
00577 
00583 int
00584 dxf_appid_get_flag
00585 (
00586         DxfAppid *appid
00588 )
00589 {
00590 #if DEBUG
00591         DXF_DEBUG_BEGIN
00592 #endif
00593         /* Do some basic checks. */
00594         if (appid == NULL)
00595         {
00596                 fprintf (stderr,
00597                   (_("Error in %s () a NULL pointer was passed.\n")),
00598                   __FUNCTION__);
00599                 return (EXIT_FAILURE);
00600         }
00601 #if DEBUG
00602         DXF_DEBUG_END
00603 #endif
00604         return (appid->flag);
00605 }
00606 
00607 
00611 DxfAppid *
00612 dxf_appid_set_flag
00613 (
00614         DxfAppid *appid,
00616         int flag
00618 )
00619 {
00620 #if DEBUG
00621         DXF_DEBUG_BEGIN
00622 #endif
00623         /* Do some basic checks. */
00624         if (appid == NULL)
00625         {
00626                 fprintf (stderr,
00627                   (_("Error in %s () a NULL pointer was passed.\n")),
00628                   __FUNCTION__);
00629                 return (NULL);
00630         }
00631         appid->flag = flag;
00632 #if DEBUG
00633         DXF_DEBUG_END
00634 #endif
00635         return (appid);
00636 }
00637 
00638 
00646 int
00647 dxf_appid_is_no_save_xdata
00648 (
00649         DxfAppid *appid
00651 )
00652 {
00653 #if DEBUG
00654         DXF_DEBUG_BEGIN
00655 #endif
00656         /* Do some basic checks. */
00657         if (appid == NULL)
00658         {
00659                 fprintf (stderr,
00660                   (_("Error in %s () a NULL pointer was passed.\n")),
00661                   __FUNCTION__);
00662                 return (EXIT_FAILURE);
00663         }
00664 #if DEBUG
00665         DXF_DEBUG_END
00666 #endif
00667         return (DXF_CHECK_BIT (appid->flag, 0));
00668 }
00669 
00670 
00677 int
00678 dxf_appid_is_xreferenced
00679 (
00680         DxfAppid *appid
00682 )
00683 {
00684 #if DEBUG
00685         DXF_DEBUG_BEGIN
00686 #endif
00687         /* Do some basic checks. */
00688         if (appid == NULL)
00689         {
00690                 fprintf (stderr,
00691                   (_("Error in %s () a NULL pointer was passed.\n")),
00692                   __FUNCTION__);
00693                 return (EXIT_FAILURE);
00694         }
00695 #if DEBUG
00696         DXF_DEBUG_END
00697 #endif
00698         return (DXF_CHECK_BIT (appid->flag, 4));
00699 }
00700 
00701 
00710 int
00711 dxf_appid_is_xresolved
00712 (
00713         DxfAppid *appid
00715 )
00716 {
00717 #if DEBUG
00718         DXF_DEBUG_BEGIN
00719 #endif
00720         /* Do some basic checks. */
00721         if (appid == NULL)
00722         {
00723                 fprintf (stderr,
00724                   (_("Error in %s () a NULL pointer was passed.\n")),
00725                   __FUNCTION__);
00726                 return (EXIT_FAILURE);
00727         }
00728 #if DEBUG
00729         DXF_DEBUG_END
00730 #endif
00731         return ((DXF_CHECK_BIT (appid->flag, 4))
00732           && (DXF_CHECK_BIT (appid->flag, 5)));
00733 }
00734 
00735 
00743 int
00744 dxf_appid_is_referenced
00745 (
00746         DxfAppid *appid
00748 )
00749 {
00750 #if DEBUG
00751         DXF_DEBUG_BEGIN
00752 #endif
00753         /* Do some basic checks. */
00754         if (appid == NULL)
00755         {
00756                 fprintf (stderr,
00757                   (_("Error in %s () a NULL pointer was passed.\n")),
00758                   __FUNCTION__);
00759                 return (EXIT_FAILURE);
00760         }
00761 #if DEBUG
00762         DXF_DEBUG_END
00763 #endif
00764         return (DXF_CHECK_BIT (appid->flag, 6));
00765 }
00766 
00767 
00776 char *
00777 dxf_appid_get_dictionary_owner_soft
00778 (
00779         DxfAppid *appid
00781 )
00782 {
00783 #if DEBUG
00784         DXF_DEBUG_BEGIN
00785 #endif
00786         /* Do some basic checks. */
00787         if (appid == NULL)
00788         {
00789                 fprintf (stderr,
00790                   (_("Error in %s () a NULL pointer was passed.\n")),
00791                   __FUNCTION__);
00792                 return (NULL);
00793         }
00794         if (appid->dictionary_owner_soft ==  NULL)
00795         {
00796                 fprintf (stderr,
00797                   (_("Error in %s () a NULL pointer was found.\n")),
00798                   __FUNCTION__);
00799                 return (NULL);
00800         }
00801 #if DEBUG
00802         DXF_DEBUG_END
00803 #endif
00804         return (strdup (appid->dictionary_owner_soft));
00805 }
00806 
00807 
00812 DxfAppid *
00813 dxf_appid_set_dictionary_owner_soft
00814 (
00815         DxfAppid *appid,
00817         char *dictionary_owner_soft
00820 )
00821 {
00822 #if DEBUG
00823         DXF_DEBUG_BEGIN
00824 #endif
00825         /* Do some basic checks. */
00826         if (appid == NULL)
00827         {
00828                 fprintf (stderr,
00829                   (_("Error in %s () a NULL pointer was passed.\n")),
00830                   __FUNCTION__);
00831                 return (NULL);
00832         }
00833         if (dictionary_owner_soft == NULL)
00834         {
00835                 fprintf (stderr,
00836                   (_("Error in %s () a NULL pointer was passed.\n")),
00837                   __FUNCTION__);
00838                 return (NULL);
00839         }
00840         appid->dictionary_owner_soft = strdup (dictionary_owner_soft);
00841 #if DEBUG
00842         DXF_DEBUG_END
00843 #endif
00844         return (appid);
00845 }
00846 
00847 
00856 char *
00857 dxf_appid_get_dictionary_owner_hard
00858 (
00859         DxfAppid *appid
00861 )
00862 {
00863 #if DEBUG
00864         DXF_DEBUG_BEGIN
00865 #endif
00866         /* Do some basic checks. */
00867         if (appid == NULL)
00868         {
00869                 fprintf (stderr,
00870                   (_("Error in %s () a NULL pointer was passed.\n")),
00871                   __FUNCTION__);
00872                 return (NULL);
00873         }
00874         if (appid->dictionary_owner_hard ==  NULL)
00875         {
00876                 fprintf (stderr,
00877                   (_("Error in %s () a NULL pointer was found.\n")),
00878                   __FUNCTION__);
00879                 return (NULL);
00880         }
00881 #if DEBUG
00882         DXF_DEBUG_END
00883 #endif
00884         return (strdup (appid->dictionary_owner_hard));
00885 }
00886 
00887 
00892 DxfAppid *
00893 dxf_appid_set_dictionary_owner_hard
00894 (
00895         DxfAppid *appid,
00897         char *dictionary_owner_hard
00900 )
00901 {
00902 #if DEBUG
00903         DXF_DEBUG_BEGIN
00904 #endif
00905         /* Do some basic checks. */
00906         if (appid == NULL)
00907         {
00908                 fprintf (stderr,
00909                   (_("Error in %s () a NULL pointer was passed.\n")),
00910                   __FUNCTION__);
00911                 return (NULL);
00912         }
00913         if (dictionary_owner_hard == NULL)
00914         {
00915                 fprintf (stderr,
00916                   (_("Error in %s () a NULL pointer was passed.\n")),
00917                   __FUNCTION__);
00918                 return (NULL);
00919         }
00920         appid->dictionary_owner_hard = strdup (dictionary_owner_hard);
00921 #if DEBUG
00922         DXF_DEBUG_END
00923 #endif
00924         return (appid);
00925 }
00926 
00927 
00936 DxfAppid *
00937 dxf_appid_get_next
00938 (
00939         DxfAppid *appid
00941 )
00942 {
00943 #if DEBUG
00944         DXF_DEBUG_BEGIN
00945 #endif
00946         /* Do some basic checks. */
00947         if (appid == NULL)
00948         {
00949                 fprintf (stderr,
00950                   (_("Error in %s () a NULL pointer was passed.\n")),
00951                   __FUNCTION__);
00952                 return (NULL);
00953         }
00954         if (appid->next == NULL)
00955         {
00956                 fprintf (stderr,
00957                   (_("Error in %s () a NULL pointer was found.\n")),
00958                   __FUNCTION__);
00959                 return (NULL);
00960         }
00961 #if DEBUG
00962         DXF_DEBUG_END
00963 #endif
00964         return ((DxfAppid *) appid->next);
00965 }
00966 
00967 
00972 DxfAppid *
00973 dxf_appid_set_next
00974 (
00975         DxfAppid *appid,
00977         DxfAppid *next
00979 )
00980 {
00981 #if DEBUG
00982         DXF_DEBUG_BEGIN
00983 #endif
00984         /* Do some basic checks. */
00985         if (appid == NULL)
00986         {
00987                 fprintf (stderr,
00988                   (_("Error in %s () a NULL pointer was passed.\n")),
00989                   __FUNCTION__);
00990                 return (NULL);
00991         }
00992         if (next == NULL)
00993         {
00994                 fprintf (stderr,
00995                   (_("Error in %s () a NULL pointer was passed.\n")),
00996                   __FUNCTION__);
00997                 return (NULL);
00998         }
00999         appid->next = (struct DxfAppid *) next;
01000 #if DEBUG
01001         DXF_DEBUG_END
01002 #endif
01003         return (appid);
01004 }
01005 
01006 
01015 DxfAppid *
01016 dxf_appid_get_last
01017 (
01018         DxfAppid *appid
01020 )
01021 {
01022 #if DEBUG
01023         DXF_DEBUG_BEGIN
01024 #endif
01025         /* Do some basic checks. */
01026         if (appid == NULL)
01027         {
01028                 fprintf (stderr,
01029                   (_("Error in %s () a NULL pointer was passed.\n")),
01030                   __FUNCTION__);
01031                 return (NULL);
01032         }
01033         if (appid->next == NULL)
01034         {
01035                 fprintf (stderr,
01036                   (_("Warning in %s () a NULL pointer was found.\n")),
01037                   __FUNCTION__);
01038                 return ((DxfAppid *) appid);
01039         }
01040         DxfAppid *iter = (DxfAppid *) appid->next;
01041         while (iter->next != NULL)
01042         {
01043                 iter = (DxfAppid *) iter->next;
01044         }
01045 #if DEBUG
01046         DXF_DEBUG_END
01047 #endif
01048         return ((DxfAppid *) iter);
01049 }
01050 
01051 
01052 /* EOF*/