(root)/
libredwg-0.13/
examples/
odaversion.c
       1  /*****************************************************************************/
       2  /*  LibreDWG - free implementation of the DWG file format                    */
       3  /*                                                                           */
       4  /*  Copyright (C) 2023 Free Software Foundation, Inc.                        */
       5  /*                                                                           */
       6  /*  This library is free software, licensed under the terms of the GNU       */
       7  /*  General Public License as published by the Free Software Foundation,     */
       8  /*  either version 3 of the License, or (at your option) any later version.  */
       9  /*  You should have received a copy of the GNU General Public License        */
      10  /*  along with this program.  If not, see <http://www.gnu.org/licenses/>.    */
      11  /*****************************************************************************/
      12  
      13  /*
      14   * odaversion.c: prints the ODA compatible DWG version
      15   * modified by Reini Urban
      16     oda understands those versions:
      17      "ACAD9","ACAD10","ACAD12",
      18      "ACAD13","ACAD14",
      19      "ACAD2000","ACAD2004",
      20      "ACAD2007","ACAD2010",
      21      "ACAD2013","ACAD2018"
      22  */
      23  
      24  #include <stdio.h>
      25  
      26  int
      27  main (int argc, char *argv[])
      28  {
      29    FILE *f;
      30    char buf[7];
      31    size_t size;
      32  
      33    if (argc != 2)
      34      return 1;
      35    f = fopen (argv[1], "rb");
      36    if (!f)
      37      return 1;
      38    size = fread (buf, 1, 6, f);
      39    if (size != 6)
      40      return 1;
      41    buf[6] = '\0';
      42    if (buf[0] == 'A' && buf[1] == 'C')
      43      {
      44        int v;
      45        if (1 != sscanf (buf, "AC%4d", &v))
      46          return 1;
      47        if (v < 1004) // <r9
      48          printf ("\n");
      49        else if (v <= 1005)
      50          printf ("9\n");
      51        else if (v <= 1006)
      52          printf ("10\n");
      53        else if (v <= 1009)
      54          printf ("11\n");
      55        else if (v <= 1012)
      56          printf ("13\n");
      57        else if (v <= 1014)
      58          printf ("14\n");
      59        else if (v <= 1016)
      60          printf ("2000\n");
      61        else if (v <= 1018)
      62          printf ("2004\n");
      63        else if (v <= 1021)
      64          printf ("2007\n");
      65        else if (v <= 1024)
      66          printf ("2010\n");
      67        else if (v < 1028)
      68          printf ("2013\n");
      69        else if (v < 1033)
      70          printf ("2018\n");
      71        else
      72          printf ("\n");
      73      }
      74    fclose (f);
      75    return 0;
      76  }