File: setup.c

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (49 lines) | stat: -rw-r--r-- 1,063 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include "segment.h"

/* SEG must have the following parms set
 *  fd (open for read and write)
 *  nrows, ncols, srows, scols, len
 *  nseg
 */
int segment_setup (SEGMENT *SEG)
{
    int i;
    char *malloc();

    SEG->open = 0;

    if (SEG->nrows <= 0 || SEG->ncols <= 0
    ||  SEG->srows <= 0 || SEG->scols <= 0
    ||  SEG->len   <= 0 || SEG->nseg  <= 0)
    {
	G_warning ("segment_setup: illegal segment file parameters\n");
	return -1;
    }

    SEG->offset = lseek (SEG->fd, 0L, 1);

    SEG->spr = SEG->ncols / SEG->scols ;
    SEG->spill = SEG->ncols % SEG->scols ;
    if(SEG->spill)
	SEG->spr++ ;

    if((SEG->scb =
        (struct SEGMENT_SCB *) G_malloc (SEG->nseg * sizeof(struct SEGMENT_SCB))) == NULL)
	return -2;

    SEG->size = SEG->srows * SEG->scols * SEG->len;

    for (i = 0; i < SEG->nseg; i++)
    {
	if((SEG->scb[i].buf = G_malloc (SEG->size)) == NULL)
	    return -2;
	SEG->scb[i].n = -1;	/* mark free */
	SEG->scb[i].dirty = 0;
	SEG->scb[i].age = 0;
    }
    SEG->cur = 0;
    SEG->open = 1;

    return 1;
}