~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to vector/v.out.ogr/list.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "local_proto.h"
 
2
 
 
3
static int cmp(const void *, const void *);
 
4
 
 
5
/* to print available drivers in help text */
 
6
char *OGR_list_write_drivers(void)
 
7
{
 
8
    int i, count;
 
9
    size_t len;
 
10
    OGRSFDriverH Ogr_driver;
 
11
    char buf[2000];
 
12
    
 
13
    char **list, *ret;
 
14
 
 
15
    list = NULL;
 
16
    count = len = 0;
 
17
    
 
18
    /* Open OGR DSN */
 
19
    OGRRegisterAll();
 
20
    G_debug(2, "driver count = %d", OGRGetDriverCount());
 
21
    for (i = 0; i < OGRGetDriverCount(); i++) {
 
22
        /* only fetch read/write drivers */
 
23
        if (!OGR_Dr_TestCapability(OGRGetDriver(i), ODrCCreateDataSource))
 
24
            continue;
 
25
        
 
26
        Ogr_driver = OGRGetDriver(i);
 
27
        G_debug(2, "driver %d/%d : %s", i, OGRGetDriverCount(),
 
28
                OGR_Dr_GetName(Ogr_driver));
 
29
        
 
30
        list = G_realloc(list, (count + 1) * sizeof(char *));
 
31
 
 
32
        /* chg white space to underscore in OGR driver names */
 
33
        sprintf(buf, "%s", OGR_Dr_GetName(Ogr_driver));
 
34
        G_strchg(buf, ' ', '_');
 
35
        list[count++] = G_store(buf);
 
36
        len += strlen(buf) + 1; /* + ',' */
 
37
    }
 
38
 
 
39
    qsort(list, count, sizeof(char *), cmp);
 
40
 
 
41
    if (len > 0) {
 
42
        ret = G_malloc((len + 1) * sizeof(char)); /* \0 */
 
43
        *ret = '\0';
 
44
        for (i = 0; i < count; i++) {
 
45
            if (i > 0)
 
46
                strcat(ret, ",");
 
47
            strcat(ret, list[i]);
 
48
            G_free(list[i]);
 
49
        }
 
50
        G_free(list);
 
51
    }
 
52
    else {
 
53
        ret = G_store("");
 
54
    }
 
55
    
 
56
    G_debug(2, "all drivers: %s", ret);
 
57
 
 
58
    return ret;
 
59
}
 
60
 
 
61
int cmp(const void *a, const void *b) 
 
62
{
 
63
    return (strcmp(*(char **)a, *(char **)b));
 
64
}