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

tables.c

Go to the documentation of this file.
00001 
00035 #include "tables.h"
00036 #include "section.h"
00037 
00038 
00047 DxfTables *
00048 dxf_tables_new ()
00049 {
00050 #if DEBUG
00051         DXF_DEBUG_BEGIN
00052 #endif
00053         DxfTables *tables = NULL;
00054         size_t size;
00055 
00056         size = sizeof (DxfTables);
00057         /* avoid malloc of 0 bytes */
00058         if (size == 0) size = 1;
00059         if ((tables = malloc (size)) == NULL)
00060         {
00061                 fprintf (stderr,
00062                   (_("Error in %s () could not allocate memory for a DxfTables struct.\n")),
00063                   __FUNCTION__);
00064                 tables = NULL;
00065         }
00066         else
00067         {
00068                 memset (tables, 0, size);
00069         }
00070 #if DEBUG
00071         DXF_DEBUG_END
00072 #endif
00073         return (tables);
00074 }
00075 
00076 
00084 DxfTables *
00085 dxf_tables_init
00086 (
00087         DxfTables *tables
00089 )
00090 {
00091 #if DEBUG
00092         DXF_DEBUG_BEGIN
00093 #endif
00094         /* Do some basic checks. */
00095         if (tables == NULL)
00096         {
00097                 fprintf (stderr,
00098                   (_("Warning in %s () a NULL pointer was passed.\n")),
00099                   __FUNCTION__);
00100                 tables = dxf_tables_new ();
00101         }
00102         if (tables == NULL)
00103         {
00104                 fprintf (stderr,
00105                   (_("Error in %s () could not allocate memory for a DxfTables struct.\n")),
00106                   __FUNCTION__);
00107                 return (NULL);
00108         }
00109         tables->max_table_entries = 0;
00110         tables->appids = NULL;
00111         tables->block_records = NULL;
00112         tables->dimstyles = NULL;
00113         tables->layers = NULL;
00114         tables->ltypes = NULL;
00115         tables->styles = NULL;
00116         tables->ucss = NULL;
00117         tables->views = NULL;
00118         tables->vports = NULL;
00119 #if DEBUG
00120         DXF_DEBUG_END
00121 #endif
00122         return (tables);
00123 }
00124 
00125 
00132 int
00133 dxf_tables_write
00134 (
00135         DxfFile *fp,
00137         DxfTables *tables
00139 )
00140 {
00141 #if DEBUG
00142         DXF_DEBUG_BEGIN
00143 #endif
00144         char *dxf_section_name = strdup ("TABLES");
00145 
00146         /* Do some basic checks. */
00147         if (fp == NULL)
00148         {
00149                 fprintf (stderr,
00150                   (_("Error in %s () a NULL file pointer was passed.\n")),
00151                   __FUNCTION__);
00152                 /* Clean up. */
00153                 free (dxf_section_name);
00154                 return (EXIT_FAILURE);
00155         }
00156         dxf_section_write (fp, dxf_section_name);
00158         dxf_endsec_write (fp);
00159 #if DEBUG
00160         DXF_DEBUG_END
00161 #endif
00162         return (EXIT_SUCCESS);
00163 }
00164 
00165 
00173 int
00174 dxf_tables_free
00175 (
00176         DxfTables *tables
00178 )
00179 {
00180 #if DEBUG
00181         DXF_DEBUG_BEGIN
00182 #endif
00183         if (tables == NULL)
00184         {
00185                 fprintf (stderr,
00186                   (_("Error in %s () a NULL pointer was passed.\n")),
00187                   __FUNCTION__);
00188                 return (EXIT_FAILURE);
00189         }
00190         free (tables->appids);
00191         free (tables->block_records);
00192         free (tables->dimstyles);
00193         free (tables->layers);
00194         free (tables->ltypes);
00195         free (tables->styles);
00196         free (tables->ucss);
00197         free (tables->views);
00198         free (tables->vports);
00199         tables = NULL;
00200 #if DEBUG
00201         DXF_DEBUG_END
00202 #endif
00203         return (EXIT_SUCCESS);
00204 }
00205 
00206 
00207 /* EOF */