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

file.c

Go to the documentation of this file.
00001 
00035 #include "file.h"
00036 
00037 
00038 char *dxf_entities_list;
00039 char *dxf_objects_list;
00040 char *dxf_blocks_list;
00041 DxfThumbnail *dxf_thumbnail;
00042 
00043 
00053 int
00054 dxf_file_read
00055 (
00056         char *filename
00058 )
00059 {
00060         char temp_string[DXF_MAX_STRING_LENGTH];
00061         DxfFile *fp;
00062 #if DEBUG
00063         DXF_DEBUG_BEGIN
00064 #endif
00065         /* open the file */
00066         fp = dxf_read_init (filename);
00067         if (fp == NULL)
00068         {
00069                 fprintf (stderr,
00070                   (_("Error in %s () a NULL file pointer was passed.\n")),
00071                   __FUNCTION__);
00072                 return (EXIT_FAILURE);
00073         }
00074         while (fp)
00075         {
00076                 dxf_read_line (temp_string, fp);
00077                 if (strcmp (temp_string, "999") == 0)
00078                 {
00079                         /* Flush dxf comments to stdout as some apps put meta
00080                          * data regarding the correct loading of libraries in
00081                          * front of dxf data (sections, tables, entities etc.
00082                          */
00083                         dxf_read_line (temp_string, fp);
00084                         fprintf (stdout, "DXF comment: %s\n", temp_string);
00085                 }
00086                 else if (strcmp (temp_string, "0") == 0)
00087                 {
00088                 /* Now follows some meaningfull dxf data. */
00089                         while (!feof (fp->fp))
00090                         {
00091                                 dxf_read_line (temp_string, fp);
00092                                 if (strcmp (temp_string, "SECTION") == 0)
00093                                 {
00094                                          /* We have found the beginning of a
00095                                           * SECTION. */
00096                                         dxf_section_read (fp);
00097                                 }
00098                                 else
00099                                 {
00100                                          /* We were expecting a dxf SECTION and
00101                                           * got something else. */
00102                                         fprintf (stderr,
00103                                           (_("Warning: in line %d \"SECTION\" was expected, \"%s\" was found.\n")),
00104                                           fp->line_number, temp_string);
00105                                 }
00106                         }
00107                 }
00108                 else
00109                 {
00110                         fprintf (stderr,
00111                           (_("Warning: unexpected string encountered while reading line %d from: %s.\n")),
00112                           fp->line_number , fp->filename);
00113                         return (EXIT_FAILURE);
00114                 }
00115         }
00116         dxf_read_close (fp);
00117 #if DEBUG
00118         DXF_DEBUG_END
00119 #endif
00120         return (EXIT_SUCCESS);
00121 }
00122 
00123 
00127 int
00128 dxf_file_write
00129 (
00130         DxfFile *fp,
00132         DxfHeader dxf_header,
00134         DxfClass dxf_classes_list,
00136         DxfTable dxf_tables_list
00138 )
00139 {
00140 #if DEBUG
00141         DXF_DEBUG_BEGIN
00142 #endif
00143         extern char *dxf_entities_list;
00144         extern char *dxf_objects_list;
00145 //        DxfBlock *dxf_blocks_list;
00146         extern DxfThumbnail *dxf_thumbnail;
00147 
00148         /* Do some basic checks. */
00149         if (fp == NULL)
00150         {
00151                 fprintf (stderr,
00152                   (_("Error in %s () a NULL file pointer was passed.\n")),
00153                   __FUNCTION__);
00154                 return (EXIT_FAILURE);
00155         }
00156 //        dxf_header_init (dxf_header);
00157 //        dxf_header_write (fp, dxf_header);
00158 //        dxf_write_classes (fp, dxf_classes_list);
00159 //        dxf_write_tables (fp, dxf_tables_list);
00160 //        dxf_block_write_table (fp, dxf_blocks_list);
00161 //        dxf_entities_write_table (fp, dxf_entities_list);
00162 //        dxf_object_write_objects (fp, dxf_objects_list);
00163 //        dxf_thumbnail_write (fp, dxf_thumbnail);
00164 //        dxf_file_write_eof (fp);
00165 #if DEBUG
00166         DXF_DEBUG_END
00167 #endif
00168         return (EXIT_SUCCESS);
00169 }
00170 
00171 
00175 int
00176 dxf_file_write_eof
00177 (
00178         DxfFile *fp
00180 )
00181 {
00182 #if DEBUG
00183         DXF_DEBUG_BEGIN
00184 #endif
00185         /* Do some basic checks. */
00186         if (fp == NULL)
00187         {
00188                 fprintf (stderr,
00189                   (_("Error in %s () a NULL file pointer was passed.\n")),
00190                   __FUNCTION__);
00191                 return (EXIT_FAILURE);
00192         }
00193         /* Start writing output. */
00194         fprintf (fp->fp, "  0\nEOF\n");
00195 #if DEBUG
00196         DXF_DEBUG_END
00197 #endif
00198         return (EXIT_SUCCESS);
00199 }
00200 
00201 
00202 /* EOF */