GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
segment/debug.c
Go to the documentation of this file.
1 
22 #include <stdio.h>
23 #include <string.h>
24 #include <grass/segment.h>
25 
26 
27 static int check(const SEGMENT *, int, int, char *);
28 
29 
48 int segment_get(SEGMENT * SEG, void *buf, int row, int col)
49 {
50  int index, n;
51 
52  if (!check(SEG, row, col, "segment_get"))
53  return -1;
54 
55  segment_address(SEG, row, col, &n, &index);
56  if ((i = segment_pagein(SEG, n)) < 0)
57  return -1;
58 
59  memcpy(buf, &SEG->scb[i].buf[index], SEG->len);
60 
61  return 1;
62 }
63 
64 
86 int segment_put(SEGMENT * SEG, const void *buf, int row, int col)
87 {
88  int index, n;
89 
90  if (!check(SEG, row, col, "segment_put"))
91  return -1;
92 
93  segment_address(SEG, row, col, &n, &index);
94  if ((i = segment_pagein(SEG, n)) < 0)
95  return -1;
96 
97  SEG->scb[i].dirty = 1;
98 
99  memcpy(&SEG->scb[i].buf[index], buf, SEG->len);
100 
101  return 1;
102 }
103 
104 
105 static int check(const SEGMENT * SEG, int row, int col, char *me)
106 {
107  int r = row >= 0 && row < SEG->nrows;
108  int c = col >= 0 && col < SEG->ncols;
109 
110  if (r && c)
111  return 1;
112 
113  fprintf(stderr, "%s(SEG=%lx,fd=%d,row=%d,col=%d) ",
114  me, (unsigned long int)SEG, SEG->fd, row, col);
115  if (!r) {
116  fprintf(stderr, "bad row ");
117  if (row >= SEG->nrows)
118  fprintf(stderr, "(max %d) ", SEG->nrows - 1);
119  }
120  if (!c) {
121  fprintf(stderr, "bad col ");
122  if (col >= SEG->ncols)
123  fprintf(stderr, "(max %d) ", SEG->ncols - 1);
124  }
125  fprintf(stderr, "\n");
126 
127  return 0;
128 }
int segment_put(SEGMENT *SEG, const void *buf, int row, int col)
Definition: segment/debug.c:86
int segment_pagein(SEGMENT *SEG, int n)
Segment pagein.
Definition: pagein.c:39
float r
Definition: named_colr.c:8
int segment_address(const SEGMENT *SEG, int row, int col, int *n, int *index)
Definition: address.c:31
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
int n
Definition: dataquad.c:291
int segment_get(SEGMENT *SEG, void *buf, int row, int col)
Get value from segment file.
Definition: segment/debug.c:48