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

binary_entity_data.c

Go to the documentation of this file.
00001 
00035 #include "binary_entity_data.h"
00036 
00037 
00043 DxfBinaryEntityData *
00044 dxf_binary_entity_data_new ()
00045 {
00046 #if DEBUG
00047         DXF_DEBUG_BEGIN
00048 #endif
00049         DxfBinaryEntityData *data = NULL;
00050         size_t size;
00051 
00052         size = sizeof (DxfBinaryEntityData);
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 DxfBinaryEntityData 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 DxfBinaryEntityData *
00081 dxf_binary_entity_data_init
00082 (
00083         DxfBinaryEntityData *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_entity_data_new ();
00097         }
00098         if (data == NULL)
00099         {
00100                 fprintf (stderr,
00101                   (_("Error in %s () could not allocate memory for a DxfBinaryEntityData struct.\n")),
00102                   __FUNCTION__);
00103                 return (NULL);
00104         }
00105         dxf_binary_entity_data_set_data_line (data, strdup (""));
00106         dxf_binary_entity_data_set_next (data, NULL);
00107 #if DEBUG
00108         DXF_DEBUG_END
00109 #endif
00110         return (data);
00111 }
00112 
00113 
00120 int
00121 dxf_binary_entity_data_write
00122 (
00123         DxfFile *fp,
00125         DxfBinaryEntityData *data
00127 )
00128 {
00129 #if DEBUG
00130         DXF_DEBUG_BEGIN
00131 #endif
00132         /* Do some basic checks. */
00133         if (fp == NULL)
00134         {
00135                 fprintf (stderr,
00136                   (_("Error in %s () a NULL file pointer was passed.\n")),
00137                   __FUNCTION__);
00138                 return (EXIT_FAILURE);
00139         }
00140         /* Start writing output. */
00141         fprintf (fp->fp, "310\n%s\n", data->data_line);
00142 #if DEBUG
00143         DXF_DEBUG_END
00144 #endif
00145         return (EXIT_SUCCESS);
00146 }
00147 
00148 
00156 int
00157 dxf_binary_entity_data_free
00158 (
00159         DxfBinaryEntityData *data
00162 )
00163 {
00164 #if DEBUG
00165         DXF_DEBUG_BEGIN
00166 #endif
00167         /* Do some basic checks. */
00168         if (data == NULL)
00169         {
00170                 fprintf (stderr,
00171                   (_("Error in %s () a NULL pointer was passed.\n")),
00172                   __FUNCTION__);
00173                 return (EXIT_FAILURE);
00174         }
00175         if (data->next != NULL)
00176         {
00177                 fprintf (stderr,
00178                   (_("Error in %s () pointer to next was not NULL.\n")),
00179                   __FUNCTION__);
00180                 return (EXIT_FAILURE);
00181         }
00182         free (data->data_line);
00183         free (data);
00184         data = NULL;
00185 #if DEBUG
00186         DXF_DEBUG_END
00187 #endif
00188         return (EXIT_SUCCESS);
00189 }
00190 
00191 
00196 void
00197 dxf_binary_entity_data_free_chain
00198 (
00199         DxfBinaryEntityData *data
00202 )
00203 {
00204 #ifdef DEBUG
00205         DXF_DEBUG_BEGIN
00206 #endif
00207         /* Do some basic checks. */
00208         if (data == NULL)
00209         {
00210                 fprintf (stderr,
00211                   (_("Warning in %s () a NULL pointer was passed.\n")),
00212                   __FUNCTION__);
00213         }
00214         while (data != NULL)
00215         {
00216                 struct DxfBinaryEntityData *iter = data->next;
00217                 dxf_binary_entity_data_free (data);
00218                 data = (DxfBinaryEntityData *) iter;
00219         }
00220 #if DEBUG
00221         DXF_DEBUG_END
00222 #endif
00223 }
00224 
00225 
00231 char *
00232 dxf_binary_entity_data_get_data_line
00233 (
00234         DxfBinaryEntityData *data
00236 )
00237 {
00238 #if DEBUG
00239         DXF_DEBUG_BEGIN
00240 #endif
00241         /* Do some basic checks. */
00242         if (data == NULL)
00243         {
00244                 fprintf (stderr,
00245                   (_("Error in %s () a NULL pointer was passed.\n")),
00246                   __FUNCTION__);
00247                 return (NULL);
00248         }
00249         if (data->data_line ==  NULL)
00250         {
00251                 fprintf (stderr,
00252                   (_("Error in %s () a NULL pointer was found in the data_line member.\n")),
00253                   __FUNCTION__);
00254                 return (NULL);
00255         }
00256 #if DEBUG
00257         DXF_DEBUG_END
00258 #endif
00259         return (strdup (data->data_line));
00260 }
00261 
00262 
00266 DxfBinaryEntityData *
00267 dxf_binary_entity_data_set_data_line
00268 (
00269         DxfBinaryEntityData *data,
00271         char *data_line
00273 )
00274 {
00275 #if DEBUG
00276         DXF_DEBUG_BEGIN
00277 #endif
00278         /* Do some basic checks. */
00279         if (data == NULL)
00280         {
00281                 fprintf (stderr,
00282                   (_("Error in %s () a NULL pointer was passed.\n")),
00283                   __FUNCTION__);
00284                 return (NULL);
00285         }
00286         if (data_line == NULL)
00287         {
00288                 fprintf (stderr,
00289                   (_("Error in %s () a NULL pointer was passed.\n")),
00290                   __FUNCTION__);
00291                 return (NULL);
00292         }
00293         data->data_line = strdup (data_line);
00294 #if DEBUG
00295         DXF_DEBUG_END
00296 #endif
00297         return (data);
00298 }
00299 
00300 
00306 int
00307 dxf_binary_entity_data_get_length
00308 (
00309         DxfBinaryEntityData *data
00311 )
00312 {
00313 #if DEBUG
00314         DXF_DEBUG_BEGIN
00315 #endif
00316         /* Do some basic checks. */
00317         if (data == NULL)
00318         {
00319                 fprintf (stderr,
00320                   (_("Error in %s () a NULL pointer was passed.\n")),
00321                   __FUNCTION__);
00322                 return (EXIT_FAILURE);
00323         }
00324         if (data->length < 0)
00325         {
00326                 fprintf (stderr,
00327                   (_("Error in %s () a negative value was found in the length member.\n")),
00328                   __FUNCTION__);
00329                 return (EXIT_FAILURE);
00330         }
00331 #if DEBUG
00332         DXF_DEBUG_END
00333 #endif
00334         return (data->length);
00335 }
00336 
00337 
00344 DxfBinaryEntityData *
00345 dxf_binary_entity_data_set_length
00346 (
00347         DxfBinaryEntityData *data,
00349         int length
00351 )
00352 {
00353 #if DEBUG
00354         DXF_DEBUG_BEGIN
00355 #endif
00356         /* Do some basic checks. */
00357         if (data == NULL)
00358         {
00359                 fprintf (stderr,
00360                   (_("Error in %s () a NULL pointer was passed.\n")),
00361                   __FUNCTION__);
00362                 return (NULL);
00363         }
00364         if (length < 0)
00365         {
00366                 fprintf (stderr,
00367                   (_("Error in %s () a negative length value was passed.\n")),
00368                   __FUNCTION__);
00369                 return (NULL);
00370         }
00371         data->length = length;
00372 #if DEBUG
00373         DXF_DEBUG_END
00374 #endif
00375         return (data);
00376 }
00377 
00378 
00387 DxfBinaryEntityData *
00388 dxf_binary_entity_data_get_next
00389 (
00390         DxfBinaryEntityData *data
00392 )
00393 {
00394 #if DEBUG
00395         DXF_DEBUG_BEGIN
00396 #endif
00397         /* Do some basic checks. */
00398         if (data == NULL)
00399         {
00400                 fprintf (stderr,
00401                   (_("Error in %s () a NULL pointer was passed.\n")),
00402                   __FUNCTION__);
00403                 return (NULL);
00404         }
00405         if (data->next == NULL)
00406         {
00407                 fprintf (stderr,
00408                   (_("Error in %s () a NULL pointer was found in the next member.\n")),
00409                   __FUNCTION__);
00410                 return (NULL);
00411         }
00412 #if DEBUG
00413         DXF_DEBUG_END
00414 #endif
00415         return ((DxfBinaryEntityData *) data->next);
00416 }
00417 
00418 
00423 DxfBinaryEntityData *
00424 dxf_binary_entity_data_set_next
00425 (
00426         DxfBinaryEntityData *data,
00428         DxfBinaryEntityData *next
00431 )
00432 {
00433 #if DEBUG
00434         DXF_DEBUG_BEGIN
00435 #endif
00436         /* Do some basic checks. */
00437         if (data == NULL)
00438         {
00439                 fprintf (stderr,
00440                   (_("Error in %s () a NULL pointer was passed.\n")),
00441                   __FUNCTION__);
00442                 return (NULL);
00443         }
00444         if (next == NULL)
00445         {
00446                 fprintf (stderr,
00447                   (_("Error in %s () a NULL pointer was passed.\n")),
00448                   __FUNCTION__);
00449                 return (NULL);
00450         }
00451         data->next = (struct DxfBinaryEntityData *) next;
00452 #if DEBUG
00453         DXF_DEBUG_END
00454 #endif
00455         return (data);
00456 }
00457 
00458 
00467 DxfBinaryEntityData *
00468 dxf_binary_entity_data_get_last
00469 (
00470         DxfBinaryEntityData *data
00472 )
00473 {
00474 #if DEBUG
00475         DXF_DEBUG_BEGIN
00476 #endif
00477         /* Do some basic checks. */
00478         if (data == NULL)
00479         {
00480                 fprintf (stderr,
00481                   (_("Error in %s () a NULL pointer was passed.\n")),
00482                   __FUNCTION__);
00483                 return (NULL);
00484         }
00485         if (data->next == NULL)
00486         {
00487                 fprintf (stderr,
00488                   (_("Warning in %s () a NULL pointer was found in the next member.\n")),
00489                   __FUNCTION__);
00490                 return ((DxfBinaryEntityData *) data);
00491         }
00492         DxfBinaryEntityData *iter = (DxfBinaryEntityData *) data->next;
00493         while (iter->next != NULL)
00494         {
00495                 iter = (DxfBinaryEntityData *) iter->next;
00496         }
00497 #if DEBUG
00498         DXF_DEBUG_END
00499 #endif
00500         return ((DxfBinaryEntityData *) data->next);
00501 }
00502 
00503 
00504 /* EOF */