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

« back to all changes in this revision

Viewing changes to raster/r.support/modhead/ask_format.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 <stdlib.h>
2
 
#include <string.h>
3
 
#include <limits.h>
4
 
#include <grass/gis.h>
5
 
#include <grass/glocale.h>
6
 
#include <grass/vask.h>
7
 
#include "local_proto.h"
8
 
 
9
 
/*
10
 
 * ask_format()
11
 
 *
12
 
 * RETURN: 0 success : -1 failure
13
 
 */
14
 
int ask_format(char *name, struct Cell_head *cellhd, off_t filesize)
15
 
{
16
 
    RASTER_MAP_TYPE maptype;
17
 
    char title[80];
18
 
    char buf[80];
19
 
    char no_zeros[80];
20
 
 
21
 
    G_zero(no_zeros, (int)sizeof(no_zeros));
22
 
    maptype = G_raster_map_type(name, G_mapset());
23
 
 
24
 
    G_snprintf(title, sizeof(title), _("Please enter the following "
25
 
                                       "information for [%s]:"), name);
26
 
 
27
 
    V_clear();
28
 
    V_line(0, title);
29
 
    V_line(2, _("        Number of rows"));
30
 
    V_line(3, _("        Number of cols"));
31
 
    V_line(4, (maptype == CELL_TYPE ?
32
 
               _("        Number of bytes per cell") :
33
 
               _("        Floating point map")));
34
 
 
35
 
    if (cellhd->compressed)
36
 
        V_const(&cellhd->rows, 'i', 2, 1, 5);
37
 
    else
38
 
        V_ques(&cellhd->rows, 'i', 2, 1, 5);
39
 
 
40
 
    V_ques(&cellhd->cols, 'i', 3, 1, 5);
41
 
 
42
 
    if (maptype == CELL_TYPE)
43
 
        V_ques(&cellhd->format, 'i', 4, 1, 5);
44
 
 
45
 
    /* If not compressed and filesize mismatch */
46
 
    if (maptype == CELL_TYPE && cellhd->compressed == 0 &&
47
 
        (off_t) cellhd->rows * cellhd->cols * cellhd->format != filesize) {
48
 
 
49
 
        if (sizeof(off_t) > sizeof(long) && filesize > ULONG_MAX)
50
 
            filesize = 0;
51
 
        G_snprintf(buf, sizeof(buf), _("rows * cols * bytes per cell "
52
 
                                       "must be same as file size (%lu)"),
53
 
                   (unsigned long)filesize);
54
 
        V_line(6, buf);
55
 
        V_line(7, _("If you need help figuring them out, just hit ESC"));
56
 
    }
57
 
    V_line(10, no_zeros);
58
 
 
59
 
    while (1) {
60
 
        V_intrpt_ok();
61
 
        if (!V_call())
62
 
            return -1;
63
 
 
64
 
        G_zero(no_zeros, (int)sizeof(no_zeros));
65
 
        if (maptype == CELL_TYPE && cellhd->rows > 0 &&
66
 
            cellhd->cols > 0 && cellhd->format > 0)
67
 
            break;
68
 
 
69
 
        if (maptype != CELL_TYPE && cellhd->rows > 0 && cellhd->cols > 0)
70
 
            break;
71
 
 
72
 
        if (!cellhd->compressed) {
73
 
            if (cellhd->rows >= 0 && cellhd->cols >= 0 && cellhd->format >= 0)
74
 
                break;
75
 
 
76
 
            strcpy(no_zeros, _("** Negative values not allowed!"));
77
 
        }
78
 
        else
79
 
            strcpy(no_zeros, _("** Positive values only please!"));
80
 
    }
81
 
 
82
 
    return EXIT_SUCCESS;
83
 
}