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

« back to all changes in this revision

Viewing changes to lib/gis/put_title.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
 
 
2
 
/**************************************************************
3
 
 * G_put_cell_title (name, title)
4
 
 *   char *name        name of map file
5
 
 *   char *title       new title
6
 
 *
7
 
 *   changes the title for the cell file 'name' in  current mapset
8
 
 *
9
 
 *   returns  1 if ok, -1 if error
10
 
 *************************************************************/
11
 
 
12
 
#include <string.h>
13
 
#include <grass/gis.h>
14
 
#include <grass/glocale.h>
15
 
 
16
 
int G_put_cell_title(const char *name, const char *title)
17
 
{
18
 
    char *mapset;
19
 
    FILE *in, *out;
20
 
    char *tempfile;
21
 
    int line;
22
 
    char buf[1024];
23
 
 
24
 
    mapset = G_mapset();
25
 
    in = out = 0;
26
 
    in = G_fopen_old("cats", name, mapset);
27
 
    if (!in) {
28
 
        sprintf(buf,
29
 
                _("category information for [%s] in [%s] missing or invalid"),
30
 
                name, mapset);
31
 
        G_warning(buf);
32
 
        return -1;
33
 
    }
34
 
 
35
 
    tempfile = G_tempfile();
36
 
    out = fopen(tempfile, "w");
37
 
    if (!out) {
38
 
        fclose(in);
39
 
        sprintf(buf, _("G_put_title - can't create a temp file"));
40
 
        G_warning(buf);
41
 
        return -1;
42
 
    }
43
 
 
44
 
    for (line = 0; G_getl(buf, sizeof buf, in); line++) {
45
 
        if (line == 1) {
46
 
            strcpy(buf, title);
47
 
            G_strip(buf);
48
 
        }
49
 
        fprintf(out, "%s\n", buf);
50
 
    }
51
 
    fclose(in);
52
 
    fclose(out);
53
 
 
54
 
    /* must be #cats line, title line, and label for cat 0 */
55
 
    if (line < 3) {
56
 
        sprintf(buf, _("category information for [%s] in [%s] invalid"), name,
57
 
                mapset);
58
 
        G_warning(buf);
59
 
        return -1;
60
 
    }
61
 
 
62
 
    in = fopen(tempfile, "r");
63
 
    if (!in) {
64
 
        sprintf(buf, _("G_put_title - can't reopen temp file"));
65
 
        G_warning(buf);
66
 
        return -1;
67
 
    }
68
 
 
69
 
    out = G_fopen_new("cats", name);
70
 
    if (!out) {
71
 
        fclose(in);
72
 
        sprintf(buf, _("can't write category information for [%s] in [%s]"),
73
 
                name, mapset);
74
 
        G_warning(buf);
75
 
        return -1;
76
 
    }
77
 
 
78
 
    while (fgets(buf, sizeof buf, in))
79
 
        fprintf(out, "%s", buf);
80
 
 
81
 
    fclose(in);
82
 
    fclose(out);
83
 
    remove(tempfile);
84
 
 
85
 
    return 1;
86
 
}