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

viewport.c

Go to the documentation of this file.
00001 
00035 #include "viewport.h"
00036 
00037 
00049 DxfViewport *
00050 dxf_viewport_new ()
00051 {
00052 #if DEBUG
00053         DXF_DEBUG_BEGIN
00054 #endif
00055         DxfViewport *viewport = NULL;
00056         size_t size;
00057 
00058         size = sizeof (DxfViewport);
00059         /* avoid malloc of 0 bytes */
00060         if (size == 0) size = 1;
00061         if ((viewport = malloc (size)) == NULL)
00062         {
00063                 fprintf (stderr,
00064                   (_("Error in %s () could not allocate memory for a DxfViewport struct.\n")),
00065                   __FUNCTION__);
00066                 viewport = NULL;
00067         }
00068         else
00069         {
00070                 memset (viewport, 0, size);
00071         }
00072 #if DEBUG
00073         DXF_DEBUG_END
00074 #endif
00075         return (viewport);
00076 }
00077 
00078 
00092 DxfViewport *
00093 dxf_viewport_init
00094 (
00095         DxfViewport *viewport
00097 )
00098 {
00099 #if DEBUG
00100         DXF_DEBUG_BEGIN
00101 #endif
00102         int i;
00103 
00104         /* Do some basic checks. */
00105         if (viewport == NULL)
00106         {
00107                 fprintf (stderr,
00108                   (_("Warning in %s () a NULL pointer was passed.\n")),
00109                   __FUNCTION__);
00110                 viewport = dxf_viewport_new ();
00111         }
00112         if (viewport == NULL)
00113         {
00114                 fprintf (stderr,
00115                   (_("Error in %s () could not allocate memory for a DxfViewport struct.\n")),
00116                   __FUNCTION__);
00117                 return (NULL);
00118         }
00119         viewport->id_code = 0;
00120         viewport->linetype = strdup (DXF_DEFAULT_LINETYPE);
00121         viewport->layer = strdup (DXF_DEFAULT_LAYER);
00122         viewport->x0 = 0.0;
00123         viewport->y0 = 0.0;
00124         viewport->z0 = 0.0;
00125         viewport->elevation = 0.0;
00126         viewport->thickness = 0.0;
00127         viewport->linetype_scale = DXF_DEFAULT_LINETYPE_SCALE;
00128         viewport->visibility = DXF_DEFAULT_VISIBILITY;
00129         viewport->width = 0.0;
00130         viewport->height = 0.0;
00131         viewport->status = 0;
00132         viewport->id = 1; /* Always 1. */
00133         viewport->color = DXF_COLOR_BYLAYER;
00134         viewport->paperspace = DXF_PAPERSPACE; /* Always on PAPERSPACE. */
00135         viewport->app_name = strdup ("ACAD"); /* Always "ACAD". */
00136         viewport->viewport_data = strdup ("MVIEW"); /* Always "MVIEW". */
00137         viewport->window_descriptor_begin = strdup ("{"); /* Always "{". */
00138         viewport->extended_entity_data_version = 16;
00139         viewport->x_target = 0.0;
00140         viewport->y_target = 0.0;
00141         viewport->z_target = 0.0;
00142         viewport->x_direction = 0.0;
00143         viewport->y_direction = 0.0;
00144         viewport->z_direction = 0.0;
00145         viewport->view_twist_angle = 0.0;
00146         viewport->view_height = 0.0;
00147         viewport->x_center = 0.0;
00148         viewport->y_center = 0.0;
00149         viewport->perspective_lens_length = 0.0;
00150         viewport->front_plane_offset = 0.0;
00151         viewport->back_plane_offset = 0.0;
00152         viewport->view_mode = 0;
00153         viewport->circle_zoom_percent = 0;
00154         viewport->fast_zoom_setting = 0;
00155         viewport->UCSICON_setting = 0;
00156         viewport->snap_on = 0;
00157         viewport->grid_on = 0;
00158         viewport->snap_style = 0;
00159         viewport->snap_isopair = 0;
00160         viewport->snap_rotation_angle = 0.0;
00161         viewport->x_snap_base = 0.0;
00162         viewport->y_snap_base = 0.0;
00163         viewport->x_snap_spacing = 0.0;
00164         viewport->y_snap_spacing = 0.0;
00165         viewport->x_grid_spacing = 0.0;
00166         viewport->y_grid_spacing = 0.0;
00167         viewport->plot_flag = 0;
00168         viewport->frozen_layer_list_begin = strdup ("{"); /* Always "{". */
00176         for (i = 0; i < DXF_MAX_LAYERS; i++)
00177         {
00178                 viewport->frozen_layers[i] = strdup ("");
00179         }
00180         viewport->frozen_layer_list_end = strdup ("}"); /* Always "}". */
00181         viewport->window_descriptor_end = strdup ("}"); /* Always "}". */
00182         viewport->dictionary_owner_soft = strdup ("");
00183         viewport->dictionary_owner_hard = strdup ("");
00184         viewport->next = NULL;
00185 #if DEBUG
00186         DXF_DEBUG_END
00187 #endif
00188         return (viewport);
00189 }
00190 
00191 
00210 DxfViewport *
00211 dxf_viewport_read
00212 (
00213         DxfFile *fp,
00215         DxfViewport *viewport
00217 )
00218 {
00219 #if DEBUG
00220         DXF_DEBUG_BEGIN
00221 #endif
00222         char *temp_string = NULL;
00223 
00224         /* Do some basic checks. */
00225         if (fp == NULL)
00226         {
00227                 fprintf (stderr,
00228                   (_("Error in %s () a NULL file pointer was passed.\n")),
00229                   __FUNCTION__);
00230                 /* Clean up. */
00231                 free (temp_string);
00232                 return (NULL);
00233         }
00234         if (viewport == NULL)
00235         {
00236                 fprintf (stderr,
00237                   (_("Warning in %s () a NULL pointer was passed.\n")),
00238                   __FUNCTION__);
00239                 viewport = dxf_viewport_new ();
00240                 viewport = dxf_viewport_init (viewport);
00241         }
00242         (fp->line_number)++;
00243         fscanf (fp->fp, "%[^\n]", temp_string);
00244         while (strcmp (temp_string, "0") != 0)
00245         {
00246                 if (ferror (fp->fp))
00247                 {
00248                         fprintf (stderr,
00249                           (_("Error in %s () while reading from: %s in line: %d.\n")),
00250                           __FUNCTION__, fp->filename, fp->line_number);
00251                         fclose (fp->fp);
00252                         /* Clean up. */
00253                         free (temp_string);
00254                         return (NULL);
00255                 }
00256                 if (strcmp (temp_string, "5") == 0)
00257                 {
00258                         /* Now follows a string containing a sequential
00259                          * id number. */
00260                         (fp->line_number)++;
00261                         fscanf (fp->fp, "%x\n", &viewport->id_code);
00262                 }
00263                 else if (strcmp (temp_string, "6") == 0)
00264                 {
00265                         /* Now follows a string containing a linetype
00266                          * name. */
00267                         (fp->line_number)++;
00268                         fscanf (fp->fp, "%s\n", viewport->linetype);
00269                 }
00270                 else if (strcmp (temp_string, "8") == 0)
00271                 {
00272                         /* Now follows a string containing a layer name. */
00273                         (fp->line_number)++;
00274                         fscanf (fp->fp, "%s\n", viewport->layer);
00275                 }
00276                 else if (strcmp (temp_string, "10") == 0)
00277                 {
00278                         /* Now follows a string containing the
00279                          * X-coordinate of the center point. */
00280                         (fp->line_number)++;
00281                         fscanf (fp->fp, "%lf\n", &viewport->x0);
00282                 }
00283                 else if (strcmp (temp_string, "20") == 0)
00284                 {
00285                         /* Now follows a string containing the
00286                          * Y-coordinate of the center point. */
00287                         (fp->line_number)++;
00288                         fscanf (fp->fp, "%lf\n", &viewport->y0);
00289                 }
00290                 else if (strcmp (temp_string, "30") == 0)
00291                 {
00292                         /* Now follows a string containing the
00293                          * Z-coordinate of the center point. */
00294                         (fp->line_number)++;
00295                         fscanf (fp->fp, "%lf\n", &viewport->z0);
00296                 }
00297                 else if ((fp->acad_version_number <= AutoCAD_11)
00298                         && (strcmp (temp_string, "38") == 0)
00299                         && (viewport->z0 = 0.0))
00300                 {
00301                         /* Elevation is a pre AutoCAD R11 variable
00302                          * so additional testing for the version should
00303                          * probably be added.
00304                          * Now follows a string containing the
00305                          * elevation. */
00306                         (fp->line_number)++;
00307                         fscanf (fp->fp, "%lf\n", &viewport->z0);
00308                 }
00309                 else if (strcmp (temp_string, "39") == 0)
00310                 {
00311                         /* Now follows a string containing the
00312                          * thickness. */
00313                         (fp->line_number)++;
00314                         fscanf (fp->fp, "%lf\n", &viewport->thickness);
00315                 }
00316                 else if (strcmp (temp_string, "40") == 0)
00317                 {
00318                         /* Now follows a string containing the
00319                          * width. */
00320                         (fp->line_number)++;
00321                         fscanf (fp->fp, "%lf\n", &viewport->width);
00322                 }
00323                 else if (strcmp (temp_string, "41") == 0)
00324                 {
00325                         /* Now follows a string containing the
00326                          * height. */
00327                         (fp->line_number)++;
00328                         fscanf (fp->fp, "%lf\n", &viewport->height);
00329                 }
00330                 else if (strcmp (temp_string, "48") == 0)
00331                 {
00332                         /* Now follows a string containing the linetype
00333                          * scale. */
00334                         (fp->line_number)++;
00335                         fscanf (fp->fp, "%lf\n", &viewport->linetype_scale);
00336                 }
00337                 else if (strcmp (temp_string, "60") == 0)
00338                 {
00339                         /* Now follows a string containing the
00340                          * visibility value. */
00341                         (fp->line_number)++;
00342                         fscanf (fp->fp, "%hd\n", &viewport->visibility);
00343                 }
00344                 else if (strcmp (temp_string, "62") == 0)
00345                 {
00346                         /* Now follows a string containing the
00347                          * color value. */
00348                         (fp->line_number)++;
00349                         fscanf (fp->fp, "%d\n", &viewport->color);
00350                 }
00351                 else if (strcmp (temp_string, "67") == 0)
00352                 {
00353                         /* Now follows a string containing the
00354                          * paperspace value. */
00355                         (fp->line_number)++;
00356                         fscanf (fp->fp, "%d\n", &viewport->paperspace);
00357                 }
00358                 else if (strcmp (temp_string, "68") == 0)
00359                 {
00360                         /* Now follows a string containing the
00361                          * status value. */
00362                         (fp->line_number)++;
00363                         fscanf (fp->fp, "%d\n", &viewport->status);
00364                 }
00365                 else if (strcmp (temp_string, "69") == 0)
00366                 {
00367                         /* Now follows a string containing the
00368                          * id. */
00369                         (fp->line_number)++;
00370                         fscanf (fp->fp, "%d\n", &viewport->id);
00371                 }
00372                 else if (strcmp (temp_string, "999") == 0)
00373                 {
00374                         /* Now follows a string containing a comment. */
00375                         (fp->line_number)++;
00376                         fscanf (fp->fp, "%s\n", temp_string);
00377                         fprintf (stdout, "DXF comment: %s\n", temp_string);
00378                 }
00379                 else if (strcmp (temp_string, "1001") == 0)
00380                 {
00381                         /* Now follows a sequence of ordered data fields. */
00382                         /* Now follows a string containing the appname,
00383                          * always "ACAD". */
00384                         (fp->line_number)++;
00385                         fscanf (fp->fp, "%s\n", viewport->app_name);
00386                         if (strcmp (viewport->app_name, "ACAD") == 1)
00387                         {
00388                                 fprintf (stderr,
00389                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00390                                   __FUNCTION__, fp->filename, fp->line_number);
00391                                 fprintf (stderr,
00392                                   (_("\tunexpected content in string followed after group code 1001.\n")));
00393                                 return (NULL);
00394                         }
00395                         /* Now follows a string containing a group code. */
00396                         (fp->line_number)++;
00397                         fscanf (fp->fp, "%s\n", temp_string);
00398                         if (strcmp (temp_string, "1000") == 1)
00399                         {
00400                                 fprintf (stderr,
00401                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00402                                   __FUNCTION__, fp->filename, fp->line_number);
00403                                 fprintf (stderr,
00404                                   (_("\tunexpected content in string sequence found.\n")));
00405                                 return (NULL);
00406                         }
00407                         /* Now follows a string containing the viewport
00408                          * data, always "MVIEW". */
00409                         (fp->line_number)++;
00410                         fscanf (fp->fp, "%s\n", viewport->viewport_data);
00411                         if (strcmp (viewport->viewport_data, "MVIEW") == 1)
00412                         {
00413                                 fprintf (stderr,
00414                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00415                                   __FUNCTION__, fp->filename, fp->line_number);
00416                                 fprintf (stderr,
00417                                   (_("\tunexpected content in string.\n")));
00418                                 return (NULL);
00419                         }
00420                         /* Now follows a string containing a group code. */
00421                         (fp->line_number)++;
00422                         fscanf (fp->fp, "%s\n", temp_string);
00423                         if (strcmp (temp_string, "1002") == 1)
00424                         {
00425                                 fprintf (stderr,
00426                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00427                                   __FUNCTION__, fp->filename, fp->line_number);
00428                                 fprintf (stderr,
00429                                   (_("\tunexpected content in string sequence found.\n")));
00430                                 return (NULL);
00431                         }
00432                         /* Now follows a string containing the window
00433                          * begin descriptor, always "{". */
00434                         (fp->line_number)++;
00435                         fscanf (fp->fp, "%s\n", viewport->window_descriptor_begin);
00436                         if (strcmp (viewport->window_descriptor_begin, "{") == 1)
00437                         {
00438                                 fprintf (stderr,
00439                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00440                                   __FUNCTION__, fp->filename, fp->line_number);
00441                                 fprintf (stderr, "    unexpected content in string.\n");
00442                                 return (NULL);
00443                         }
00444                         /* Now follows a string containing a group code. */
00445                         (fp->line_number)++;
00446                         fscanf (fp->fp, "%s\n", temp_string);
00447                         if (strcmp (temp_string, "1070") == 1)
00448                         {
00449                                 fprintf (stderr,
00450                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00451                                   __FUNCTION__, fp->filename, fp->line_number);
00452                                 fprintf (stderr,
00453                                   (_("\tunexpected content in string sequence found.\n")));
00454                                 return (NULL);
00455                         }
00456                         /* Now follows a string containing the extended
00457                          * entity data version number. */
00458                         (fp->line_number)++;
00459                         fscanf (fp->fp, "%d\n", &viewport->extended_entity_data_version);
00460                         /* Now follows a string containing a group code. */
00461                         (fp->line_number)++;
00462                         fscanf (fp->fp, "%s\n", temp_string);
00463                         if (strcmp (temp_string, "1010") == 1)
00464                         {
00465                                 fprintf (stderr,
00466                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00467                                   __FUNCTION__, fp->filename, fp->line_number);
00468                                 fprintf (stderr,
00469                                   (_("\tunexpected content in string sequence found.\n")));
00470                                 return (NULL);
00471                         }
00472                         /* Now follows a string containing the X-target. */
00473                         (fp->line_number)++;
00474                         fscanf (fp->fp, "%lf\n", &viewport->x_target);
00475                         /* Now follows a string containing a group code. */
00476                         (fp->line_number)++;
00477                         fscanf (fp->fp, "%s\n", temp_string);
00478                         if (strcmp (temp_string, "1020") == 1)
00479                         {
00480                                 fprintf (stderr,
00481                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00482                                   __FUNCTION__, fp->filename, fp->line_number);
00483                                 fprintf (stderr,
00484                                   (_("\tunexpected content in string sequence found.\n")));
00485                                 return (NULL);
00486                         }
00487                         /* Now follows a string containing the Y-target. */
00488                         (fp->line_number)++;
00489                         fscanf (fp->fp, "%lf\n", &viewport->y_target);
00490                         /* Now follows a string containing a group code. */
00491                         (fp->line_number)++;
00492                         fscanf (fp->fp, "%s\n", temp_string);
00493                         if (strcmp (temp_string, "1030") == 1)
00494                         {
00495                                 fprintf (stderr,
00496                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00497                                   __FUNCTION__, fp->filename, fp->line_number);
00498                                 fprintf (stderr,
00499                                   (_("\tunexpected content in string sequence found.\n")));
00500                                 return (NULL);
00501                         }
00502                         /* Now follows a string containing the Z-target. */
00503                         (fp->line_number)++;
00504                         fscanf (fp->fp, "%lf\n", &viewport->z_target);
00505                         /* Now follows a string containing a group code. */
00506                         (fp->line_number)++;
00507                         fscanf (fp->fp, "%s\n", temp_string);
00508                         if (strcmp (temp_string, "1010") == 1)
00509                         {
00510                                 fprintf (stderr,
00511                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00512                                   __FUNCTION__, fp->filename, fp->line_number);
00513                                 fprintf (stderr,
00514                                   (_("\tunexpected content in string sequence found.\n")));
00515                                 return (NULL);
00516                         }
00517                         /* Now follows a string containing the X-direction. */
00518                         (fp->line_number)++;
00519                         fscanf (fp->fp, "%lf\n", &viewport->x_direction);
00520                         /* Now follows a string containing a group code. */
00521                         (fp->line_number)++;
00522                         fscanf (fp->fp, "%s\n", temp_string);
00523                         if (strcmp (temp_string, "1020") == 1)
00524                         {
00525                                 fprintf (stderr,
00526                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00527                                   __FUNCTION__, fp->filename, fp->line_number);
00528                                 fprintf (stderr,
00529                                   (_("\tunexpected content in string sequence found.\n")));
00530                                 return (NULL);
00531                         }
00532                         /* Now follows a string containing the Y-direction. */
00533                         (fp->line_number)++;
00534                         fscanf (fp->fp, "%lf\n", &viewport->y_direction);
00535                         /* Now follows a string containing a group code. */
00536                         (fp->line_number)++;
00537                         fscanf (fp->fp, "%s\n", temp_string);
00538                         if (strcmp (temp_string, "1030") == 1)
00539                         {
00540                                 fprintf (stderr,
00541                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00542                                   __FUNCTION__, fp->filename, fp->line_number);
00543                                 fprintf (stderr,
00544                                   (_("\tunexpected content in string sequence found.\n")));
00545                                 return (NULL);
00546                         }
00547                         /* Now follows a string containing the Z-direction. */
00548                         (fp->line_number)++;
00549                         fscanf (fp->fp, "%lf\n", &viewport->z_direction);
00550                         /* Now follows a string containing a group code. */
00551                         (fp->line_number)++;
00552                         fscanf (fp->fp, "%s\n", temp_string);
00553                         if (strcmp (temp_string, "1040") == 1)
00554                         {
00555                                 fprintf (stderr,
00556                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00557                                   __FUNCTION__, fp->filename, fp->line_number);
00558                                 fprintf (stderr,
00559                                   (_("\tunexpected content in string sequence found.\n")));
00560                                 return (NULL);
00561                         }
00562                         /* Now follows a string containing the view
00563                          * twist angle. */
00564                         (fp->line_number)++;
00565                         fscanf (fp->fp, "%lf\n", &viewport->view_twist_angle);
00566                         /* Now follows a string containing a group code. */
00567                         (fp->line_number)++;
00568                         fscanf (fp->fp, "%s\n", temp_string);
00569                         if (strcmp (temp_string, "1040") == 1)
00570                         {
00571                                 fprintf (stderr,
00572                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00573                                   __FUNCTION__, fp->filename, fp->line_number);
00574                                 fprintf (stderr,
00575                                   (_("\tunexpected content in string sequence found.\n")));
00576                                 return (NULL);
00577                         }
00578                         /* Now follows a string containing the view
00579                          * height. */
00580                         (fp->line_number)++;
00581                         fscanf (fp->fp, "%lf\n", &viewport->view_height);
00582                         /* Now follows a string containing a group code. */
00583                         (fp->line_number)++;
00584                         fscanf (fp->fp, "%s\n", temp_string);
00585                         if (strcmp (temp_string, "1040") == 1)
00586                         {
00587                                 fprintf (stderr,
00588                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00589                                   __FUNCTION__, fp->filename, fp->line_number);
00590                                 fprintf (stderr,
00591                                   (_("\tunexpected content in string sequence found.\n")));
00592                                 return (NULL);
00593                         }
00594                         /* Now follows a string containing the
00595                          * X-coordinate of the view center point. */
00596                         (fp->line_number)++;
00597                         fscanf (fp->fp, "%lf\n", &viewport->x_center);
00598                         /* Now follows a string containing a group code. */
00599                         (fp->line_number)++;
00600                         fscanf (fp->fp, "%s\n", temp_string);
00601                         if (strcmp (temp_string, "1040") == 1)
00602                         {
00603                                 fprintf (stderr,
00604                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00605                                   __FUNCTION__, fp->filename, fp->line_number);
00606                                 fprintf (stderr,
00607                                   (_("\tunexpected content in string sequence found.\n")));
00608                                 return (NULL);
00609                         }
00610                         /* Now follows a string containing the
00611                          * Y-coordinate of the view center point. */
00612                         (fp->line_number)++;
00613                         fscanf (fp->fp, "%lf\n", &viewport->y_center);
00614                         /* Now follows a string containing a group code. */
00615                         (fp->line_number)++;
00616                         fscanf (fp->fp, "%s\n", temp_string);
00617                         if (strcmp (temp_string, "1040") == 1)
00618                         {
00619                                 fprintf (stderr,
00620                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00621                                   __FUNCTION__, fp->filename, fp->line_number);
00622                                 fprintf (stderr,
00623                                   (_("\tunexpected content in string sequence found.\n")));
00624                                 return (NULL);
00625                         }
00626                         /* Now follows a string containing the
00627                          * perspective lens length. */
00628                         (fp->line_number)++;
00629                         fscanf (fp->fp, "%lf\n", &viewport->perspective_lens_length);
00630                         /* Now follows a string containing a group code. */
00631                         (fp->line_number)++;
00632                         fscanf (fp->fp, "%s\n", temp_string);
00633                         if (strcmp (temp_string, "1040") == 1)
00634                         {
00635                                 fprintf (stderr,
00636                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00637                                   __FUNCTION__, fp->filename, fp->line_number);
00638                                 fprintf (stderr,
00639                                   (_("\tunexpected content in string sequence found.\n")));
00640                                 return (NULL);
00641                         }
00642                         /* Now follows a string containing the front
00643                          * clipping plane offset. */
00644                         (fp->line_number)++;
00645                         fscanf (fp->fp, "%lf\n", &viewport->front_plane_offset);
00646                         /* Now follows a string containing a group code. */
00647                         (fp->line_number)++;
00648                         fscanf (fp->fp, "%s\n", temp_string);
00649                         if (strcmp (temp_string, "1040") == 1)
00650                         {
00651                                 fprintf (stderr,
00652                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00653                                   __FUNCTION__, fp->filename, fp->line_number);
00654                                 fprintf (stderr,
00655                                   (_("\tunexpected content in string sequence found.\n")));
00656                                 return (NULL);
00657                         }
00658                         /* Now follows a string containing the back
00659                          * clipping plane offset. */
00660                         (fp->line_number)++;
00661                         fscanf (fp->fp, "%lf\n", &viewport->back_plane_offset);
00662                         /* Now follows a string containing a group code. */
00663                         (fp->line_number)++;
00664                         fscanf (fp->fp, "%s\n", temp_string);
00665                         if (strcmp (temp_string, "1070") == 1)
00666                         {
00667                                 fprintf (stderr,
00668                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00669                                   __FUNCTION__, fp->filename, fp->line_number);
00670                                 fprintf (stderr,
00671                                   (_("\tunexpected content in string sequence found.\n")));
00672                                 return (NULL);
00673                         }
00674                         /* Now follows a string containing the view mode. */
00675                         (fp->line_number)++;
00676                         fscanf (fp->fp, "%d\n", &viewport->view_mode);
00677                         /* Now follows a string containing a group code. */
00678                         (fp->line_number)++;
00679                         fscanf (fp->fp, "%s\n", temp_string);
00680                         if (strcmp (temp_string, "1070") == 1)
00681                         {
00682                                 fprintf (stderr,
00683                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00684                                   __FUNCTION__, fp->filename, fp->line_number);
00685                                 fprintf (stderr,
00686                                   (_("\tunexpected content in string sequence found.\n")));
00687                                 return (NULL);
00688                         }
00689                         /* Now follows a string containing the circle
00690                          * zoom percent. */
00691                         (fp->line_number)++;
00692                         fscanf (fp->fp, "%d\n", &viewport->circle_zoom_percent);
00693                         /* Now follows a string containing a group code. */
00694                         (fp->line_number)++;
00695                         fscanf (fp->fp, "%s\n", temp_string);
00696                         if (strcmp (temp_string, "1070") == 1)
00697                         {
00698                                 fprintf (stderr,
00699                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00700                                   __FUNCTION__, fp->filename, fp->line_number);
00701                                 fprintf (stderr,
00702                                   (_("\tunexpected content in string sequence found.\n")));
00703                                 return (NULL);
00704                         }
00705                         /* Now follows a string containing the fast zoom
00706                          * setting. */
00707                         (fp->line_number)++;
00708                         fscanf (fp->fp, "%d\n", &viewport->fast_zoom_setting);
00709                         /* Now follows a string containing a group code. */
00710                         (fp->line_number)++;
00711                         fscanf (fp->fp, "%s\n", temp_string);
00712                         if (strcmp (temp_string, "1070") == 1)
00713                         {
00714                                 fprintf (stderr,
00715                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00716                                   __FUNCTION__, fp->filename, fp->line_number);
00717                                 fprintf (stderr,
00718                                   (_("\tunexpected content in string sequence found.\n")));
00719                                 return (NULL);
00720                         }
00721                         /* Now follows a string containing the ICS ICON
00722                          * setting. */
00723                         (fp->line_number)++;
00724                         fscanf (fp->fp, "%d\n", &viewport->UCSICON_setting);
00725                         /* Now follows a string containing a group code. */
00726                         (fp->line_number)++;
00727                         fscanf (fp->fp, "%s\n", temp_string);
00728                         if (strcmp (temp_string, "1070") == 1)
00729                         {
00730                                 fprintf (stderr,
00731                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00732                                   __FUNCTION__, fp->filename, fp->line_number);
00733                                 fprintf (stderr,
00734                                   (_("\tunexpected content in string sequence found.\n")));
00735                                 return (NULL);
00736                         }
00737                         /* Now follows a string containing the snap on
00738                          * setting. */
00739                         (fp->line_number)++;
00740                         fscanf (fp->fp, "%d\n", &viewport->snap_on);
00741                         /* Now follows a string containing a group code. */
00742                         (fp->line_number)++;
00743                         fscanf (fp->fp, "%s\n", temp_string);
00744                         if (strcmp (temp_string, "1070") == 1)
00745                         {
00746                                 fprintf (stderr,
00747                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00748                                   __FUNCTION__, fp->filename, fp->line_number);
00749                                 fprintf (stderr,
00750                                   (_("\tunexpected content in string sequence found.\n")));
00751                                 return (NULL);
00752                         }
00753                         /* Now follows a string containing the grid on
00754                          * setting. */
00755                         (fp->line_number)++;
00756                         fscanf (fp->fp, "%d\n", &viewport->grid_on);
00757                         /* Now follows a string containing a group code. */
00758                         (fp->line_number)++;
00759                         fscanf (fp->fp, "%s\n", temp_string);
00760                         if (strcmp (temp_string, "1070") == 1)
00761                         {
00762                                 fprintf (stderr,
00763                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00764                                   __FUNCTION__, fp->filename, fp->line_number);
00765                                 fprintf (stderr,
00766                                   (_("\tunexpected content in string sequence found.\n")));
00767                                 return (NULL);
00768                         }
00769                         /* Now follows a string containing the snap
00770                          * style setting. */
00771                         (fp->line_number)++;
00772                         fscanf (fp->fp, "%d\n", &viewport->snap_style);
00773                         /* Now follows a string containing a group code. */
00774                         (fp->line_number)++;
00775                         fscanf (fp->fp, "%s\n", temp_string);
00776                         if (strcmp (temp_string, "1070") == 1)
00777                         {
00778                                 fprintf (stderr,
00779                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00780                                   __FUNCTION__, fp->filename, fp->line_number);
00781                                 fprintf (stderr,
00782                                   (_("\tunexpected content in string sequence found.\n")));
00783                                 return (NULL);
00784                         }
00785                         /* Now follows a string containing the snap
00786                          * isopair setting. */
00787                         (fp->line_number)++;
00788                         fscanf (fp->fp, "%d\n", &viewport->snap_isopair);
00789                         /* Now follows a string containing a group code. */
00790                         (fp->line_number)++;
00791                         fscanf (fp->fp, "%s\n", temp_string);
00792                         if (strcmp (temp_string, "1040") == 1)
00793                         {
00794                                 fprintf (stderr,
00795                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00796                                   __FUNCTION__, fp->filename, fp->line_number);
00797                                 fprintf (stderr,
00798                                   (_("\tunexpected content in string sequence found.\n")));
00799                                 return (NULL);
00800                         }
00801                         /* Now follows a string containing the snap
00802                          * rotation angle. */
00803                         (fp->line_number)++;
00804                         fscanf (fp->fp, "%lf\n", &viewport->snap_rotation_angle);
00805                         /* Now follows a string containing a group code. */
00806                         (fp->line_number)++;
00807                         fscanf (fp->fp, "%s\n", temp_string);
00808                         if (strcmp (temp_string, "1040") == 1)
00809                         {
00810                                 fprintf (stderr,
00811                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00812                                   __FUNCTION__, fp->filename, fp->line_number);
00813                                 fprintf (stderr,
00814                                   (_("\tunexpected content in string sequence found.\n")));
00815                                 return (NULL);
00816                         }
00817                         /* Now follows a string containing the X snap
00818                          * base. */
00819                         (fp->line_number)++;
00820                         fscanf (fp->fp, "%lf\n", &viewport->x_snap_base);
00821                         /* Now follows a string containing a group code. */
00822                         (fp->line_number)++;
00823                         fscanf (fp->fp, "%s\n", temp_string);
00824                         if (strcmp (temp_string, "1040") == 1)
00825                         {
00826                                 fprintf (stderr,
00827                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00828                                   __FUNCTION__, fp->filename, fp->line_number);
00829                                 fprintf (stderr,
00830                                   (_("\tunexpected content in string sequence found.\n")));
00831                                 return (NULL);
00832                         }
00833                         /* Now follows a string containing the Y snap
00834                          * base. */
00835                         (fp->line_number)++;
00836                         fscanf (fp->fp, "%lf\n", &viewport->y_snap_base);
00837                         /* Now follows a string containing a group code. */
00838                         (fp->line_number)++;
00839                         fscanf (fp->fp, "%s\n", temp_string);
00840                         if (strcmp (temp_string, "1040") == 1)
00841                         {
00842                                 fprintf (stderr,
00843                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00844                                   __FUNCTION__, fp->filename, fp->line_number);
00845                                 fprintf (stderr,
00846                                   (_("\tunexpected content in string sequence found.\n")));
00847                                 return (NULL);
00848                         }
00849                         /* Now follows a string containing the X snap
00850                          * spacing. */
00851                         (fp->line_number)++;
00852                         fscanf (fp->fp, "%lf\n", &viewport->x_snap_spacing);
00853                         /* Now follows a string containing a group code. */
00854                         (fp->line_number)++;
00855                         fscanf (fp->fp, "%s\n", temp_string);
00856                         if (strcmp (temp_string, "1040") == 1)
00857                         {
00858                                 fprintf (stderr,
00859                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00860                                   __FUNCTION__, fp->filename, fp->line_number);
00861                                 fprintf (stderr,
00862                                   (_("\tunexpected content in string sequence found.\n")));
00863                                 return (NULL);
00864                         }
00865                         /* Now follows a string containing the Y snap
00866                          * spacing. */
00867                         (fp->line_number)++;
00868                         fscanf (fp->fp, "%lf\n", &viewport->y_snap_spacing);
00869                         /* Now follows a string containing a group code. */
00870                         (fp->line_number)++;
00871                         fscanf (fp->fp, "%s\n", temp_string);
00872                         if (strcmp (temp_string, "1070") == 1)
00873                         {
00874                                 fprintf (stderr,
00875                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00876                                   __FUNCTION__, fp->filename, fp->line_number);
00877                                 fprintf (stderr,
00878                                   (_("\tunexpected content in string sequence found.\n")));
00879                                 return (NULL);
00880                         }
00881                         /* Now follows a string containing the plot flag. */
00882                         (fp->line_number)++;
00883                         fscanf (fp->fp, "%d\n", &viewport->plot_flag);
00884                         /* Now follows a string containing a group code. */
00885                         (fp->line_number)++;
00886                         fscanf (fp->fp, "%s\n", temp_string);
00887                         if (strcmp (temp_string, "1002") == 1)
00888                         {
00889                                 fprintf (stderr,
00890                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00891                                   __FUNCTION__, fp->filename, fp->line_number);
00892                                 fprintf (stderr,
00893                                   (_("\tunexpected content in string sequence found.\n")));
00894                                 return (NULL);
00895                         }
00896                         /* Now follows a string containing the frozen
00897                          * layer list begin descriptor, always "{". */
00898                         (fp->line_number)++;
00899                         fscanf (fp->fp, "%s\n", viewport->frozen_layer_list_begin);
00900                         if (strcmp (viewport->frozen_layer_list_begin, "{") == 1)
00901                         {
00902                                 fprintf (stderr,
00903                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00904                                   __FUNCTION__, fp->filename, fp->line_number);
00905                                 fprintf (stderr,
00906                                   (_("\tunexpected content in string.\n")));
00907                                 return (NULL);
00908                         }
00909                         /* Now follows a string containing a group code
00910                          * value of "1003". */
00911                         (fp->line_number)++;
00912                         fscanf (fp->fp, "%s\n", temp_string);
00913                         if (strcmp (temp_string, "1003") == 0)
00914                         {
00915                                 /* Start a loop reading all frozen layer
00916                                  * names and bail out when a group code
00917                                  * with a value of "1002" is encountered
00918                                  * or DXF_MAX_LAYERS is reached.*/
00919                                 int j = 0;
00920                                 do
00921                                 {
00922                                         (fp->line_number)++;
00923                                         fscanf (fp->fp, "%s\n", viewport->frozen_layers[j]);
00924                                         j++;
00925                                         /* Now follows a string containing a group code. */
00926                                         (fp->line_number)++;
00927                                         fscanf (fp->fp, "%s\n", temp_string);
00928                                 }
00929                                 while ((strcmp (temp_string, "1003") == 0)
00930                                         || (j < DXF_MAX_LAYERS));
00931                         }
00932                         else
00933                         {
00934                                 /* Either we found an empty list or we
00935                                  * have found an exception. */
00936                                 fprintf (stderr,
00937                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00938                                   __FUNCTION__, fp->filename, fp->line_number);
00939                                 fprintf (stderr,
00940                                   (_("\tunexpected end of frozen layer list found.\n")));
00941                                 return (NULL);
00942                         }
00943                         /* Now we are expecting temp_string to contain a
00944                          * group code value of "1002". */
00945                         if (strcmp (temp_string, "1002") == 1)
00946                         {
00947                                 fprintf (stderr,
00948                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00949                                   __FUNCTION__, fp->filename, fp->line_number);
00950                                 fprintf (stderr,
00951                                   (_("\tunexpected content in string sequence found.\n")));
00952                                 return (NULL);
00953                         }
00954                         /* Now follows a string containing the frozen
00955                          * layer list end descriptor, always "}". */
00956                         (fp->line_number)++;
00957                         fscanf (fp->fp, "%s\n", viewport->frozen_layer_list_end);
00958                         if (strcmp (viewport->frozen_layer_list_end, "}") == 1)
00959                         {
00960                                 fprintf (stderr,
00961                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00962                                   __FUNCTION__, fp->filename, fp->line_number);
00963                                 fprintf (stderr,
00964                                   (_("\tunexpected content in string.\n")));
00965                                 return (NULL);
00966                         }
00967                         /* Now follows a string containing a group code. */
00968                         (fp->line_number)++;
00969                         fscanf (fp->fp, "%s\n", temp_string);
00970                         if (strcmp (temp_string, "1002") == 1)
00971                         {
00972                                 fprintf (stderr,
00973                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00974                                   __FUNCTION__, fp->filename, fp->line_number);
00975                                 fprintf (stderr,
00976                                   (_("\tunexpected content in string sequence found.\n")));
00977                                 return (NULL);
00978                         }
00979                         /* Now follows a string containing the window
00980                          * end descriptor, always "}". */
00981                         (fp->line_number)++;
00982                         fscanf (fp->fp, "%s\n", viewport->window_descriptor_end);
00983                         if (strcmp (viewport->window_descriptor_end, "}") == 1)
00984                         {
00985                                 fprintf (stderr,
00986                                   (_("Error in %s () while reading from: %s in line: %d.\n")),
00987                                   __FUNCTION__, fp->filename, fp->line_number);
00988                                 fprintf (stderr,
00989                                   (_("\tunexpected content in string.\n")));
00990                                 return (NULL);
00991                         }
00992                 }
00993                 /* End of sequential ordered data fields. */
00994                 else 
00995                 {
00996                         fprintf (stderr,
00997                           (_("Warning in %s () unknown string tag found while reading from: %s in line: %d.\n")),
00998                           __FUNCTION__, fp->filename, fp->line_number);
00999                 }
01000         }
01001         /* Handle omitted members and/or illegal values. */
01002         if (strcmp (viewport->linetype, "") == 0)
01003         {
01004                 viewport->linetype = strdup (DXF_DEFAULT_LINETYPE);
01005         }
01006         if (strcmp (viewport->layer, "") == 0)
01007         {
01008                 viewport->layer = strdup (DXF_DEFAULT_LAYER);
01009         }
01010         /* Clean up. */
01011         free (temp_string);
01012 #if DEBUG
01013         DXF_DEBUG_END
01014 #endif
01015         return (viewport);
01016 }
01017 
01018 
01031 int
01032 dxf_viewport_write
01033 (
01034         DxfFile *fp,
01036         DxfViewport *viewport
01038 )
01039 {
01040 #if DEBUG
01041         DXF_DEBUG_BEGIN
01042 #endif
01043         char *dxf_entity_name = strdup ("VIEWPORT");
01044 
01045         /* Do some basic checks. */
01046         if (fp == NULL)
01047         {
01048                 fprintf (stderr,
01049                   (_("Error in %s () a NULL file pointer was passed.\n")),
01050                   __FUNCTION__);
01051                 /* Clean up. */
01052                 free (dxf_entity_name);
01053                 return (EXIT_FAILURE);
01054         }
01055         if (viewport == NULL)
01056         {
01057                 fprintf (stderr,
01058                   (_("Error in %s () a NULL pointer was passed.\n")),
01059                   __FUNCTION__);
01060                 /* Clean up. */
01061                 free (dxf_entity_name);
01062                 return (EXIT_FAILURE);
01063         }
01064         if (strcmp (viewport->linetype, "") == 0)
01065         {
01066                 fprintf (stderr,
01067                   (_("Warning in %s () empty linetype string for the %s entity with id-code: %x\n")),
01068                   __FUNCTION__, dxf_entity_name, viewport->id_code);
01069                 fprintf (stderr,
01070                   (_("\t%s entity is reset to default linetype")),
01071                   dxf_entity_name);
01072                 viewport->linetype = strdup (DXF_DEFAULT_LINETYPE);
01073         }
01074         if (strcmp (viewport->layer, "") == 0)
01075         {
01076                 fprintf (stderr,
01077                   (_("Warning in %s () empty layer string for the %s entity with id-code: %x.\n")),
01078                   __FUNCTION__, dxf_entity_name, viewport->id_code);
01079                 fprintf (stderr,
01080                   (_("\t%s entity is relocated to default layer.\n")),
01081                   dxf_entity_name);
01082                 viewport->layer = strdup (DXF_DEFAULT_LAYER);
01083         }
01084         /* Start writing output. */
01085         fprintf (fp->fp, "  0\n%s\n", dxf_entity_name);
01086         if (viewport->id_code != -1)
01087         {
01088                 fprintf (fp->fp, "  5\n%x\n", viewport->id_code);
01089         }
01100         if ((strcmp (viewport->dictionary_owner_soft, "") != 0)
01101           && (fp->acad_version_number >= AutoCAD_14))
01102         {
01103                 fprintf (fp->fp, "102\n{ACAD_REACTORS\n");
01104                 fprintf (fp->fp, "330\n%s\n", viewport->dictionary_owner_soft);
01105                 fprintf (fp->fp, "102\n}\n");
01106         }
01107         if ((strcmp (viewport->dictionary_owner_hard, "") != 0)
01108           && (fp->acad_version_number >= AutoCAD_14))
01109         {
01110                 fprintf (fp->fp, "102\n{ACAD_XDICTIONARY\n");
01111                 fprintf (fp->fp, "360\n%s\n", viewport->dictionary_owner_hard);
01112                 fprintf (fp->fp, "102\n}\n");
01113         }
01114         if (fp->acad_version_number >= AutoCAD_13)
01115         {
01116                 fprintf (fp->fp, "100\nAcDbEntity\n");
01117         }
01118         if (viewport->paperspace == DXF_PAPERSPACE)
01119         {
01120                 fprintf (fp->fp, " 67\n%d\n", DXF_PAPERSPACE);
01121         }
01122         fprintf (fp->fp, "  8\n%s\n", viewport->layer);
01123         if (strcmp (viewport->linetype, DXF_DEFAULT_LINETYPE) != 0)
01124         {
01125                 fprintf (fp->fp, "  6\n%s\n", viewport->linetype);
01126         }
01127         if ((fp->acad_version_number <= AutoCAD_11)
01128           && DXF_FLATLAND
01129           && (viewport->elevation != 0.0))
01130         {
01131                 fprintf (fp->fp, " 38\n%f\n", viewport->elevation);
01132         }
01133         if (viewport->color != DXF_COLOR_BYLAYER)
01134         {
01135                 fprintf (fp->fp, " 62\n%d\n", viewport->color);
01136         }
01137         if (viewport->linetype_scale != 1.0)
01138         {
01139                 fprintf (fp->fp, " 48\n%f\n", viewport->linetype_scale);
01140         }
01141         if (viewport->visibility != 0)
01142         {
01143                 fprintf (fp->fp, " 60\n%d\n", viewport->visibility);
01144         }
01145         if (fp->acad_version_number >= AutoCAD_13)
01146         {
01147                 fprintf (fp->fp, "100\nAcDbViewport\n");
01148         }
01149         if (viewport->thickness != 0.0)
01150         {
01151                 fprintf (fp->fp, " 39\n%f\n", viewport->thickness);
01152         }
01153         fprintf (fp->fp, " 10\n%f\n", viewport->x0);
01154         fprintf (fp->fp, " 20\n%f\n", viewport->y0);
01155         fprintf (fp->fp, " 30\n%f\n", viewport->z0);
01156         fprintf (fp->fp, " 40\n%f\n", viewport->width);
01157         fprintf (fp->fp, " 41\n%f\n", viewport->height);
01158         fprintf (fp->fp, " 68\n%d\n", viewport->status);
01159         fprintf (fp->fp, " 69\n%d\n", viewport->id);
01160         fprintf (fp->fp, "1001\n%s\n", DXF_VIEWPORT_APP_NAME);
01161         fprintf (fp->fp, "1000\n%s\n", DXF_VIEWPORT_DATA);
01162         fprintf (fp->fp, "1002\n%s\n", DXF_VIEWPORT_WINDOW_BEGIN);
01163         fprintf (fp->fp, "1070\n%d\n", viewport->extended_entity_data_version);
01164         fprintf (fp->fp, "1010\n%f\n", viewport->x_target);
01165         fprintf (fp->fp, "1020\n%f\n", viewport->y_target);
01166         fprintf (fp->fp, "1030\n%f\n", viewport->z_target);
01167         fprintf (fp->fp, "1010\n%f\n", viewport->x_direction);
01168         fprintf (fp->fp, "1020\n%f\n", viewport->y_direction);
01169         fprintf (fp->fp, "1030\n%f\n", viewport->z_direction);
01170         fprintf (fp->fp, "1040\n%f\n", viewport->view_twist_angle);
01171         fprintf (fp->fp, "1040\n%f\n", viewport->view_height);
01172         fprintf (fp->fp, "1040\n%f\n", viewport->x_center);
01173         fprintf (fp->fp, "1040\n%f\n", viewport->y_center);
01174         fprintf (fp->fp, "1040\n%f\n", viewport->perspective_lens_length);
01175         fprintf (fp->fp, "1040\n%f\n", viewport->front_plane_offset);
01176         fprintf (fp->fp, "1040\n%f\n", viewport->back_plane_offset);
01177         fprintf (fp->fp, "1070\n%d\n", viewport->view_mode);
01178         fprintf (fp->fp, "1070\n%d\n", viewport->circle_zoom_percent);
01179         fprintf (fp->fp, "1070\n%d\n", viewport->fast_zoom_setting);
01180         fprintf (fp->fp, "1070\n%d\n", viewport->UCSICON_setting);
01181         fprintf (fp->fp, "1070\n%d\n", viewport->snap_on);
01182         fprintf (fp->fp, "1070\n%d\n", viewport->grid_on);
01183         fprintf (fp->fp, "1070\n%d\n", viewport->snap_style);
01184         fprintf (fp->fp, "1070\n%d\n", viewport->snap_isopair);
01185         fprintf (fp->fp, "1040\n%f\n", viewport->snap_rotation_angle);
01186         fprintf (fp->fp, "1040\n%f\n", viewport->x_snap_base);
01187         fprintf (fp->fp, "1040\n%f\n", viewport->y_snap_base);
01188         fprintf (fp->fp, "1040\n%f\n", viewport->x_snap_spacing);
01189         fprintf (fp->fp, "1040\n%f\n", viewport->y_snap_spacing);
01190         fprintf (fp->fp, "1040\n%f\n", viewport->x_grid_spacing);
01191         fprintf (fp->fp, "1040\n%f\n", viewport->y_grid_spacing);
01192         fprintf (fp->fp, "1070\n%d\n", viewport->plot_flag);
01193         fprintf (fp->fp, "1002\n%s\n", DXF_VIEWPORT_FROZEN_LAYER_LIST_BEGIN);
01194         /* Start a loop writing all frozen layer names. */
01195         int j = 0;
01196         while ((!viewport->frozen_layers[j]) /* Do not allow NULL pointers. */
01197                 || (strcmp (viewport->frozen_layers[j], "") == 1) /* Do not allow empty strings. */
01198                 || (j < DXF_MAX_LAYERS)) /* Do not overrun the array size. */
01199         {
01200                 fprintf (fp->fp, "1003\n%s\n", viewport->frozen_layers[j]);
01201                 j++;
01202         }
01203         fprintf (fp->fp, "1002\n%s\n", DXF_VIEWPORT_FROZEN_LAYER_LIST_END);
01204         fprintf (fp->fp, "1002\n%s\n", DXF_VIEWPORT_WINDOW_END);
01205         /* Clean up. */
01206         free (dxf_entity_name);
01207 #if DEBUG
01208         DXF_DEBUG_END
01209 #endif
01210         return (EXIT_SUCCESS);
01211 }
01212 
01213 
01225 int
01226 dxf_viewport_free
01227 (
01228         DxfViewport *viewport
01231 )
01232 {
01233 #if DEBUG
01234         DXF_DEBUG_BEGIN
01235 #endif
01236         int i;
01237 
01238         /* Do some basic checks. */
01239         if (viewport == NULL)
01240         {
01241                 fprintf (stderr,
01242                   (_("Error in %s () a NULL pointer was passed.\n")),
01243                   __FUNCTION__);
01244                 return (EXIT_FAILURE);
01245         }
01246         if (viewport->next != NULL)
01247         {
01248                 fprintf (stderr,
01249                   (_("Error in %s () pointer to next was not NULL.\n")),
01250                   __FUNCTION__);
01251                 return (EXIT_FAILURE);
01252         }
01253         free (viewport->linetype);
01254         free (viewport->layer);
01255         free (viewport->app_name);
01256         free (viewport->viewport_data);
01257         free (viewport->window_descriptor_begin);
01258         free (viewport->frozen_layer_list_begin);
01259         for (i = 0; i < DXF_MAX_LAYERS; i++)
01260         {
01261                 if (strcmp (viewport->frozen_layers[i], "") != 0)
01262                 {
01263                         free (viewport->frozen_layers[i]);
01264                 }
01265         }
01266         free (viewport->frozen_layer_list_end);
01267         free (viewport->window_descriptor_end);
01268         free (viewport);
01269         viewport = NULL;
01270 #if DEBUG
01271         DXF_DEBUG_END
01272 #endif
01273         return (EXIT_SUCCESS);
01274 }
01275 
01276 
01287 void
01288 dxf_viewport_free_chain
01289 (
01290         DxfViewport *viewports
01293 )
01294 {
01295 #ifdef DEBUG
01296         DXF_DEBUG_BEGIN
01297 #endif
01298         if (viewports == NULL)
01299         {
01300                 fprintf (stderr,
01301                   (_("Warning in %s () a NULL pointer was passed.\n")),
01302                   __FUNCTION__);
01303         }
01304         while (viewports != NULL)
01305         {
01306                 struct DxfViewport *iter = viewports->next;
01307                 dxf_viewport_free (viewports);
01308                 viewports = (DxfViewport *) iter;
01309         }
01310 #if DEBUG
01311         DXF_DEBUG_END
01312 #endif
01313 }
01314 
01315 
01316 /* EOF */