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

proprietary_data.c

Go to the documentation of this file.
00001 
00035 #include "proprietary_data.h"
00036 
00037 
00043 DxfProprietaryData *
00044 dxf_proprietary_data_new ()
00045 {
00046 #if DEBUG
00047         DXF_DEBUG_BEGIN
00048 #endif
00049         DxfProprietaryData *data = NULL;
00050         size_t size;
00051 
00052         size = sizeof (DxfProprietaryData);
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 DxfProprietaryData struct.\n")),
00059                   __FUNCTION__);
00060                 return (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 DxfProprietaryData *
00081 dxf_proprietary_data_init
00082 (
00083         DxfProprietaryData *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_proprietary_data_new ();
00097         }
00098         if (data == NULL)
00099         {
00100               fprintf (stderr,
00101                 (_("Error in %s () could not allocate memory for a DxfProprietaryData struct.\n")),
00102                 __FUNCTION__);
00103               return (NULL);
00104         }
00105         data->line = strdup ("");
00106         data->next = NULL;
00107 #if DEBUG
00108         DXF_DEBUG_END
00109 #endif
00110         return (data);
00111 }
00112 
00113 
00121 int
00122 dxf_proprietary_data_free
00123 (
00124         DxfProprietaryData *data
00127 )
00128 {
00129 #if DEBUG
00130         DXF_DEBUG_BEGIN
00131 #endif
00132         /* Do some basic checks. */
00133         if (data == NULL)
00134         {
00135                 fprintf (stderr,
00136                   (_("Error in %s () a NULL pointer was passed.\n")),
00137                   __FUNCTION__);
00138                 return (EXIT_FAILURE);
00139         }
00140         if (data->next != NULL)
00141         {
00142                 fprintf (stderr,
00143                   (_("Error in %s () pointer to next was not NULL.\n")),
00144                   __FUNCTION__);
00145                 return (EXIT_FAILURE);
00146         }
00147         free (data->line);
00148         free (data);
00149         data = NULL;
00150 #if DEBUG
00151         DXF_DEBUG_END
00152 #endif
00153         return (EXIT_SUCCESS);
00154 }
00155 
00156 
00161 void
00162 dxf_proprietary_data_free_chain
00163 (
00164         DxfProprietaryData *datas
00167 )
00168 {
00169 #ifdef DEBUG
00170         DXF_DEBUG_BEGIN
00171 #endif
00172         if (datas == NULL)
00173         {
00174                 fprintf (stderr,
00175                   (_("Warning in %s () a NULL pointer was passed.\n")),
00176                   __FUNCTION__);
00177         }
00178         while (datas != NULL)
00179         {
00180                 struct DxfProprietaryData *iter = datas->next;
00181                 dxf_proprietary_data_free (datas);
00182                 datas = (DxfProprietaryData *) iter;
00183         }
00184 #if DEBUG
00185         DXF_DEBUG_END
00186 #endif
00187 }
00188 
00189 
00196 int
00197 dxf_proprietary_data_get_order
00198 (
00199         DxfProprietaryData *data
00201 )
00202 {
00203 #if DEBUG
00204         DXF_DEBUG_BEGIN
00205 #endif
00206         /* Do some basic checks. */
00207         if (data == NULL)
00208         {
00209                 fprintf (stderr,
00210                   (_("Error in %s () a NULL pointer was passed.\n")),
00211                   __FUNCTION__);
00212                 return (EXIT_FAILURE);
00213         }
00214         if (data->order < 0)
00215         {
00216                 fprintf (stderr,
00217                   (_("Error in %s () a negative value was found in the order member.\n")),
00218                   __FUNCTION__);
00219                 return (EXIT_FAILURE);
00220         }
00221 #if DEBUG
00222         DXF_DEBUG_END
00223 #endif
00224         return (data->order);
00225 }
00226 
00227 
00232 DxfProprietaryData *
00233 dxf_proprietary_data_set_order
00234 (
00235         DxfProprietaryData *data,
00237         int order
00239 )
00240 {
00241 #if DEBUG
00242         DXF_DEBUG_BEGIN
00243 #endif
00244         /* Do some basic checks. */
00245         if (data == NULL)
00246         {
00247                 fprintf (stderr,
00248                   (_("Error in %s () a NULL pointer was passed.\n")),
00249                   __FUNCTION__);
00250                 return (NULL);
00251         }
00252         if (order < 0)
00253         {
00254                 fprintf (stderr,
00255                   (_("Error in %s () a negative order value was passed.\n")),
00256                   __FUNCTION__);
00257                 return (NULL);
00258         }
00259         data->order = order;
00260 #if DEBUG
00261         DXF_DEBUG_END
00262 #endif
00263         return (data);
00264 }
00265 
00266 
00272 char *
00273 dxf_proprietary_data_get_line
00274 (
00275         DxfProprietaryData *data
00277 )
00278 {
00279 #if DEBUG
00280         DXF_DEBUG_BEGIN
00281 #endif
00282         /* Do some basic checks. */
00283         if (data == NULL)
00284         {
00285                 fprintf (stderr,
00286                   (_("Error in %s () a NULL pointer was passed.\n")),
00287                   __FUNCTION__);
00288                 return (NULL);
00289         }
00290         if (data->line ==  NULL)
00291         {
00292                 fprintf (stderr,
00293                   (_("Error in %s () a NULL pointer was found in the line member.\n")),
00294                   __FUNCTION__);
00295                 return (NULL);
00296         }
00297 #if DEBUG
00298         DXF_DEBUG_END
00299 #endif
00300         return (strdup (data->line));
00301 }
00302 
00303 
00310 DxfProprietaryData *
00311 dxf_proprietary_data_set_line
00312 (
00313         DxfProprietaryData *data,
00315         char *line
00317 )
00318 {
00319 #if DEBUG
00320         DXF_DEBUG_BEGIN
00321 #endif
00322         /* Do some basic checks. */
00323         if (data == NULL)
00324         {
00325                 fprintf (stderr,
00326                   (_("Error in %s () a NULL pointer was passed.\n")),
00327                   __FUNCTION__);
00328                 return (NULL);
00329         }
00330         if (line == NULL)
00331         {
00332                 fprintf (stderr,
00333                   (_("Error in %s () a NULL pointer was passed.\n")),
00334                   __FUNCTION__);
00335                 return (NULL);
00336         }
00337         data->line = strdup (line);
00338 #if DEBUG
00339         DXF_DEBUG_END
00340 #endif
00341         return (data);
00342 }
00343 
00344 
00351 int
00352 dxf_proprietary_data_get_length
00353 (
00354         DxfProprietaryData *data
00356 )
00357 {
00358 #if DEBUG
00359         DXF_DEBUG_BEGIN
00360 #endif
00361         /* Do some basic checks. */
00362         if (data == NULL)
00363         {
00364                 fprintf (stderr,
00365                   (_("Error in %s () a NULL pointer was passed.\n")),
00366                   __FUNCTION__);
00367                 return (EXIT_FAILURE);
00368         }
00369         if (data->length < 0)
00370         {
00371                 fprintf (stderr,
00372                   (_("Error in %s () a negative value was found in the length member.\n")),
00373                   __FUNCTION__);
00374                 return (EXIT_FAILURE);
00375         }
00376         if (data->length == 0)
00377         {
00378                 fprintf (stderr,
00379                   (_("Error in %s () a zero value was found in the length member.\n")),
00380                   __FUNCTION__);
00381         }
00382 #if DEBUG
00383         DXF_DEBUG_END
00384 #endif
00385         return (data->length);
00386 }
00387 
00388 
00400 int
00401 dxf_proprietary_data_test_length
00402 (
00403         DxfProprietaryData *data
00405 )
00406 {
00407 #if DEBUG
00408         DXF_DEBUG_BEGIN
00409 #endif
00410         int i;
00411 
00412         /* Do some basic checks. */
00413         if (data == NULL)
00414         {
00415                 fprintf (stderr,
00416                   (_("Error in %s () a NULL pointer was passed.\n")),
00417                   __FUNCTION__);
00418                 return (EXIT_FAILURE);
00419         }
00420         if (data->line == NULL)
00421         {
00422                 fprintf (stderr,
00423                   (_("Error in %s () a NULL pointer was found in the line member.\n")),
00424                   __FUNCTION__);
00425                 return (EXIT_FAILURE);
00426         }
00427         if (data->length == 0)
00428         {
00429                 fprintf (stderr,
00430                   (_("Error in %s () a value of 0 was found in the length member.\n")),
00431                   __FUNCTION__);
00432                 return (EXIT_FAILURE);
00433         }
00434         if (data->length < 0)
00435         {
00436                 fprintf (stderr,
00437                   (_("Error in %s () a negative value was found in the length member.\n")),
00438                   __FUNCTION__);
00439                 return (EXIT_FAILURE);
00440         }
00441         for (i = 0; i <= DXF_MAX_STRING_LENGTH; i++)
00442         {
00443                 if ((data->line[i] == '\0') && (data->length == i))
00444                 {
00445                         break; /* Break out from the for-loop. */
00446                 }
00447                 else
00448                 {
00449                         fprintf (stderr,
00450                           (_("Error in %s () the value found in the length member did not match the actual string length.\n")),
00451                           __FUNCTION__);
00452                         return (EXIT_FAILURE);
00453                 }
00454         }
00455 #if DEBUG
00456         DXF_DEBUG_END
00457 #endif
00458         return (EXIT_SUCCESS);
00459 }
00460 
00461 
00466 DxfProprietaryData *
00467 dxf_proprietary_data_set_length
00468 (
00469         DxfProprietaryData *data,
00471         int length
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 (length < 0)
00487         {
00488                 fprintf (stderr,
00489                   (_("Error in %s () a negative length value was passed.\n")),
00490                   __FUNCTION__);
00491                 return (NULL);
00492         }
00493         data->length = length;
00494 #if DEBUG
00495         DXF_DEBUG_END
00496 #endif
00497         return (data);
00498 }
00499 
00500 
00509 DxfProprietaryData *
00510 dxf_proprietary_data_get_next
00511 (
00512         DxfProprietaryData *data
00514 )
00515 {
00516 #if DEBUG
00517         DXF_DEBUG_BEGIN
00518 #endif
00519         /* Do some basic checks. */
00520         if (data == NULL)
00521         {
00522                 fprintf (stderr,
00523                   (_("Error in %s () a NULL pointer was passed.\n")),
00524                   __FUNCTION__);
00525                 return (NULL);
00526         }
00527         if (data->next == NULL)
00528         {
00529                 fprintf (stderr,
00530                   (_("Error in %s () a NULL pointer was found in the next member.\n")),
00531                   __FUNCTION__);
00532                 return (NULL);
00533         }
00534 #if DEBUG
00535         DXF_DEBUG_END
00536 #endif
00537         return ((DxfProprietaryData *) data->next);
00538 }
00539 
00540 
00548 DxfProprietaryData *
00549 dxf_proprietary_data_set_next
00550 (
00551         DxfProprietaryData *data,
00553         DxfProprietaryData *next
00556 )
00557 {
00558 #if DEBUG
00559         DXF_DEBUG_BEGIN
00560 #endif
00561         /* Do some basic checks. */
00562         if (data == NULL)
00563         {
00564                 fprintf (stderr,
00565                   (_("Error in %s () a NULL pointer was passed.\n")),
00566                   __FUNCTION__);
00567                 return (NULL);
00568         }
00569         if (next == NULL)
00570         {
00571                 fprintf (stderr,
00572                   (_("Error in %s () a NULL pointer was passed.\n")),
00573                   __FUNCTION__);
00574                 return (NULL);
00575         }
00576         data->next = (struct DxfProprietaryData *) next;
00577 #if DEBUG
00578         DXF_DEBUG_END
00579 #endif
00580         return (data);
00581 }
00582 
00583 
00592 DxfProprietaryData *
00593 dxf_proprietary_data_get_last
00594 (
00595         DxfProprietaryData *data
00597 )
00598 {
00599 #if DEBUG
00600         DXF_DEBUG_BEGIN
00601 #endif
00602         /* Do some basic checks. */
00603         if (data == NULL)
00604         {
00605                 fprintf (stderr,
00606                   (_("Error in %s () a NULL pointer was passed.\n")),
00607                   __FUNCTION__);
00608                 return (NULL);
00609         }
00610         if (data->next == NULL)
00611         {
00612                 fprintf (stderr,
00613                   (_("Warning in %s () a NULL pointer was found.\n")),
00614                   __FUNCTION__);
00615                 return ((DxfProprietaryData *) data);
00616         }
00617         DxfProprietaryData *iter = (DxfProprietaryData *) data->next;
00618         while (iter->next != NULL)
00619         {
00620                 iter = (DxfProprietaryData *) iter->next;
00621         }
00622 #if DEBUG
00623         DXF_DEBUG_END
00624 #endif
00625         return ((DxfProprietaryData *) iter);
00626 }
00627 
00628 
00629 /* EOF */