GRASS Programmer's Manual
6.4.2(2012)
|
00001 00022 #include <stdio.h> 00023 #include <string.h> 00024 #include <grass/segment.h> 00025 00026 00027 static int check(const SEGMENT *, int, int, char *); 00028 00029 00048 int segment_get(SEGMENT * SEG, void *buf, int row, int col) 00049 { 00050 int index, n; 00051 00052 if (!check(SEG, row, col, "segment_get")) 00053 return -1; 00054 00055 segment_address(SEG, row, col, &n, &index); 00056 if ((i = segment_pagein(SEG, n)) < 0) 00057 return -1; 00058 00059 memcpy(buf, &SEG->scb[i].buf[index], SEG->len); 00060 00061 return 1; 00062 } 00063 00064 00086 int segment_put(SEGMENT * SEG, const void *buf, int row, int col) 00087 { 00088 int index, n; 00089 00090 if (!check(SEG, row, col, "segment_put")) 00091 return -1; 00092 00093 segment_address(SEG, row, col, &n, &index); 00094 if ((i = segment_pagein(SEG, n)) < 0) 00095 return -1; 00096 00097 SEG->scb[i].dirty = 1; 00098 00099 memcpy(&SEG->scb[i].buf[index], buf, SEG->len); 00100 00101 return 1; 00102 } 00103 00104 00105 static int check(const SEGMENT * SEG, int row, int col, char *me) 00106 { 00107 int r = row >= 0 && row < SEG->nrows; 00108 int c = col >= 0 && col < SEG->ncols; 00109 00110 if (r && c) 00111 return 1; 00112 00113 fprintf(stderr, "%s(SEG=%lx,fd=%d,row=%d,col=%d) ", 00114 me, (unsigned long int)SEG, SEG->fd, row, col); 00115 if (!r) { 00116 fprintf(stderr, "bad row "); 00117 if (row >= SEG->nrows) 00118 fprintf(stderr, "(max %d) ", SEG->nrows - 1); 00119 } 00120 if (!c) { 00121 fprintf(stderr, "bad col "); 00122 if (col >= SEG->ncols) 00123 fprintf(stderr, "(max %d) ", SEG->ncols - 1); 00124 } 00125 fprintf(stderr, "\n"); 00126 00127 return 0; 00128 }