File: dbfinfo.c

package info (click to toggle)
shapelib 1.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,884 kB
  • sloc: ansic: 10,567; sh: 4,620; cpp: 752; makefile: 192; pascal: 159
file content (94 lines) | stat: -rw-r--r-- 2,838 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (c) 1999 Carl Anderson
 *
 * This code is in the public domain.
 *
 * This code is based in part on the earlier work of Frank Warmerdam
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "shapefil.h"

int main(int argc, char **argv)
{
    /* -------------------------------------------------------------------- */
    /*      Display a usage message.                                        */
    /* -------------------------------------------------------------------- */
    if (argc != 2)
    {
        printf("dbfinfo xbase_file\n");
        exit(1);
    }

    /* -------------------------------------------------------------------- */
    /*      Open the file.                                                  */
    /* -------------------------------------------------------------------- */
    DBFHandle hDBF = DBFOpen(argv[1], "rb");
    if (hDBF == NULL)
    {
        printf("DBFOpen(%s,\"r\") failed.\n", argv[1]);
        exit(2);
    }

    printf("Info for %s\n", argv[1]);

    /* -------------------------------------------------------------------- */
    /*  If there is no data in this file let the user know.                 */
    /* -------------------------------------------------------------------- */
    const int iCount = DBFGetFieldCount(hDBF);
    printf("%d Columns,  %d Records in file\n", iCount,
           DBFGetRecordCount(hDBF));

    /* -------------------------------------------------------------------- */
    /*  Compute offsets to use when printing each of the field              */
    /*  values. We make each field as wide as the field title+1, or         */
    /*  the field value + 1.                                                */
    /* -------------------------------------------------------------------- */
    char ftype[32];
    int nDecimals;
    int nWidth;

    for (int i = 0; i < DBFGetFieldCount(hDBF); i++)
    {
        char szTitle[XBASE_FLDNAME_LEN_READ + 1];

        switch (DBFGetFieldInfo(hDBF, i, szTitle, &nWidth, &nDecimals))
        {
            case FTString:
                strcpy(ftype, "string");
                break;

            case FTInteger:
                strcpy(ftype, "integer");
                break;

            case FTDouble:
                strcpy(ftype, "float");
                break;

            case FTLogical:
                strcpy(ftype, "logical");
                break;

            case FTDate:
                strcpy(ftype, "date");
                break;

            case FTInvalid:
                strcpy(ftype, "invalid/unsupported");
                break;

            default:
                strcpy(ftype, "unknown");
                break;
        }
        printf("%15.15s\t%15s  (%d,%d)\n", szTitle, ftype, nWidth, nDecimals);
    }

    DBFClose(hDBF);

    return (0);
}