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

layer_name.c

Go to the documentation of this file.
00001 
00043 #include "layer_name.h"
00044 
00045 
00051 DxfLayerName *
00052 dxf_layer_name_new ()
00053 {
00054 #if DEBUG
00055         DXF_DEBUG_BEGIN
00056 #endif
00057         DxfLayerName *layer_name = NULL;
00058         size_t size;
00059 
00060         size = sizeof (DxfLayerName);
00061         /* avoid malloc of 0 bytes */
00062         if (size == 0) size = 1;
00063         if ((layer_name = malloc (size)) == NULL)
00064         {
00065                 fprintf (stderr,
00066                   (_("Error in %s () could not allocate memory.\n")),
00067                   __FUNCTION__);
00068                 layer_name = NULL;
00069         }
00070         else
00071         {
00072                 memset (layer_name, 0, size);
00073         }
00074 #if DEBUG
00075         DXF_DEBUG_END
00076 #endif
00077         return (layer_name);
00078 }
00079 
00080 
00088 DxfLayerName *
00089 dxf_layer_name_init
00090 (
00091         DxfLayerName *layer_name
00093 )
00094 {
00095 #if DEBUG
00096         DXF_DEBUG_BEGIN
00097 #endif
00098         /* Do some basic checks. */
00099         if (layer_name == NULL)
00100         {
00101                 fprintf (stderr,
00102                   (_("Warning in %s () a NULL pointer was passed.\n")),
00103                   __FUNCTION__);
00104                 layer_name = dxf_layer_name_new ();
00105         }
00106         if (layer_name == NULL)
00107         {
00108                 fprintf (stderr,
00109                   (_("Error in %s () could not allocate memory.\n")),
00110                   __FUNCTION__);
00111                 return (NULL);
00112         }
00113         layer_name->name = strdup ("");
00114         layer_name->length = 0;
00115         layer_name->next = NULL;
00116 #if DEBUG
00117         DXF_DEBUG_END
00118 #endif
00119         return (layer_name);
00120 }
00121 
00122 
00130 int
00131 dxf_layer_name_free
00132 (
00133         DxfLayerName *layer_name
00136 )
00137 {
00138 #if DEBUG
00139         DXF_DEBUG_BEGIN
00140 #endif
00141         /* Do some basic checks. */
00142         if (layer_name == NULL)
00143         {
00144                 fprintf (stderr,
00145                   (_("Error in %s () a NULL pointer was passed.\n")),
00146                   __FUNCTION__);
00147                 return (EXIT_FAILURE);
00148         }
00149         if (layer_name->next != NULL)
00150         {
00151                 fprintf (stderr,
00152                   (_("Error in %s () pointer to next was not NULL.\n")),
00153                   __FUNCTION__);
00154                 return (EXIT_FAILURE);
00155         }
00156         free (layer_name->name);
00157         free (layer_name);
00158         layer_name = NULL;
00159 #if DEBUG
00160         DXF_DEBUG_END
00161 #endif
00162         return (EXIT_SUCCESS);
00163 }
00164 
00165 
00170 void
00171 dxf_layer_name_free_chain
00172 (
00173         DxfLayerName *layer_names
00175 )
00176 {
00177 #ifdef DEBUG
00178         DXF_DEBUG_BEGIN
00179 #endif
00180         if (layer_names == NULL)
00181         {
00182                 fprintf (stderr,
00183                   (_("Warning in %s () a NULL pointer was passed.\n")),
00184                   __FUNCTION__);
00185         }
00186         while (layer_names != NULL)
00187         {
00188                 struct DxfLayerName *iter = layer_names->next;
00189                 dxf_layer_name_free (layer_names);
00190                 layer_names = (DxfLayerName *) iter;
00191         }
00192 #if DEBUG
00193         DXF_DEBUG_END
00194 #endif
00195 }
00196 
00197 
00205 char *
00206 dxf_layer_name_get_name
00207 (
00208         DxfLayerName *layer_name
00210 )
00211 {
00212 #if DEBUG
00213         DXF_DEBUG_BEGIN
00214 #endif
00215         /* Do some basic checks. */
00216         if (layer_name == NULL)
00217         {
00218                 fprintf (stderr,
00219                   (_("Error in %s () a NULL pointer was passed.\n")),
00220                   __FUNCTION__);
00221                 return (NULL);
00222         }
00223         if (layer_name->name ==  NULL)
00224         {
00225                 fprintf (stderr,
00226                   (_("Error in %s () a NULL pointer was found.\n")),
00227                   __FUNCTION__);
00228                 return (NULL);
00229         }
00230 #if DEBUG
00231         DXF_DEBUG_END
00232 #endif
00233         return (strdup (layer_name->name));
00234 }
00235 
00236 
00240 DxfLayerName *
00241 dxf_layer_name_set_name
00242 (
00243         DxfLayerName *layer_name,
00245         char *name
00247 )
00248 {
00249 #if DEBUG
00250         DXF_DEBUG_BEGIN
00251 #endif
00252         /* Do some basic checks. */
00253         if (layer_name == NULL)
00254         {
00255                 fprintf (stderr,
00256                   (_("Error in %s () a NULL pointer was passed.\n")),
00257                   __FUNCTION__);
00258                 return (NULL);
00259         }
00260         if (name == NULL)
00261         {
00262                 fprintf (stderr,
00263                   (_("Error in %s () a NULL pointer was passed.\n")),
00264                   __FUNCTION__);
00265                 return (NULL);
00266         }
00267         layer_name->name = strdup (name);
00268 #if DEBUG
00269         DXF_DEBUG_END
00270 #endif
00271         return (layer_name);
00272 }
00273 
00274 
00281 int
00282 dxf_layer_name_get_length
00283 (
00284         DxfLayerName *layer_name
00286 )
00287 {
00288 #if DEBUG
00289         DXF_DEBUG_BEGIN
00290 #endif
00291         /* Do some basic checks. */
00292         if (layer_name == NULL)
00293         {
00294                 fprintf (stderr,
00295                   (_("Error in %s () a NULL pointer was passed.\n")),
00296                   __FUNCTION__);
00297                 return (EXIT_FAILURE);
00298         }
00299         if (layer_name->length < 0)
00300         {
00301                 fprintf (stderr,
00302                   (_("Error in %s () a negative value was found.\n")),
00303                   __FUNCTION__);
00304                 return (EXIT_FAILURE);
00305         }
00306 #if DEBUG
00307         DXF_DEBUG_END
00308 #endif
00309         return (layer_name->length);
00310 }
00311 
00312 
00317 DxfLayerName *
00318 dxf_layer_name_set_length
00319 (
00320         DxfLayerName *layer_name,
00322         int length
00324 )
00325 {
00326 #if DEBUG
00327         DXF_DEBUG_BEGIN
00328 #endif
00329         /* Do some basic checks. */
00330         if (layer_name == NULL)
00331         {
00332                 fprintf (stderr,
00333                   (_("Error in %s () a NULL pointer was passed.\n")),
00334                   __FUNCTION__);
00335                 return (NULL);
00336         }
00337         if (length < 0)
00338         {
00339                 fprintf (stderr,
00340                   (_("Error in %s () a negative value was passed.\n")),
00341                   __FUNCTION__);
00342                 return (NULL);
00343         }
00344         layer_name->length = length;
00345 #if DEBUG
00346         DXF_DEBUG_END
00347 #endif
00348         return (layer_name);
00349 }
00350 
00351 
00360 DxfLayerName *
00361 dxf_layer_name_get_next
00362 (
00363         DxfLayerName *layer_name
00365 )
00366 {
00367 #if DEBUG
00368         DXF_DEBUG_BEGIN
00369 #endif
00370         /* Do some basic checks. */
00371         if (layer_name == NULL)
00372         {
00373                 fprintf (stderr,
00374                   (_("Error in %s () a NULL pointer was passed.\n")),
00375                   __FUNCTION__);
00376                 return (NULL);
00377         }
00378         if (layer_name->next == NULL)
00379         {
00380                 fprintf (stderr,
00381                   (_("Error in %s () a NULL pointer was found.\n")),
00382                   __FUNCTION__);
00383                 return (NULL);
00384         }
00385 #if DEBUG
00386         DXF_DEBUG_END
00387 #endif
00388         return ((DxfLayerName *) layer_name->next);
00389 }
00390 
00391 
00396 DxfLayerName *
00397 dxf_layer_name_set_next
00398 (
00399         DxfLayerName *layer_name,
00401         DxfLayerName *next
00404 )
00405 {
00406 #if DEBUG
00407         DXF_DEBUG_BEGIN
00408 #endif
00409         /* Do some basic checks. */
00410         if (layer_name == NULL)
00411         {
00412                 fprintf (stderr,
00413                   (_("Error in %s () a NULL pointer was passed.\n")),
00414                   __FUNCTION__);
00415                 return (NULL);
00416         }
00417         if (next == NULL)
00418         {
00419                 fprintf (stderr,
00420                   (_("Error in %s () a NULL pointer was passed.\n")),
00421                   __FUNCTION__);
00422                 return (NULL);
00423         }
00424         layer_name->next = (struct DxfLayerName *) next;
00425 #if DEBUG
00426         DXF_DEBUG_END
00427 #endif
00428         return (layer_name);
00429 }
00430 
00431 
00440 DxfLayerName *
00441 dxf_layer_name_get_last
00442 (
00443         DxfLayerName *layer_name
00445 )
00446 {
00447 #if DEBUG
00448         DXF_DEBUG_BEGIN
00449 #endif
00450         /* Do some basic checks. */
00451         if (layer_name == NULL)
00452         {
00453                 fprintf (stderr,
00454                   (_("Error in %s () a NULL pointer was passed.\n")),
00455                   __FUNCTION__);
00456                 return (NULL);
00457         }
00458         if (layer_name->next == NULL)
00459         {
00460                 fprintf (stderr,
00461                   (_("Warning in %s () a NULL pointer was found.\n")),
00462                   __FUNCTION__);
00463                 return ((DxfLayerName *) layer_name);
00464         }
00465         DxfLayerName *iter = (DxfLayerName *) layer_name->next;
00466         while (iter->next != NULL)
00467         {
00468                 iter = (DxfLayerName *) iter->next;
00469         }
00470 #if DEBUG
00471         DXF_DEBUG_END
00472 #endif
00473         return ((DxfLayerName *) iter);
00474 }
00475 
00476 
00477 /* EOF */