[GRASS-SVN] r73511 - grass/trunk/raster/r.watershed/seg
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Oct 9 06:31:07 PDT 2018
Author: mmetz
Date: 2018-10-09 06:31:07 -0700 (Tue, 09 Oct 2018)
New Revision: 73511
Modified:
grass/trunk/raster/r.watershed/seg/bseg_close.c
grass/trunk/raster/r.watershed/seg/bseg_open.c
grass/trunk/raster/r.watershed/seg/cseg_close.c
grass/trunk/raster/r.watershed/seg/cseg_open.c
grass/trunk/raster/r.watershed/seg/dseg_close.c
grass/trunk/raster/r.watershed/seg/dseg_open.c
grass/trunk/raster/r.watershed/seg/sseg_close.c
grass/trunk/raster/r.watershed/seg/sseg_open.c
Log:
r.watershed/seg: use Segment_[open|close]()
Modified: grass/trunk/raster/r.watershed/seg/bseg_close.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/bseg_close.c 2018-10-09 13:21:00 UTC (rev 73510)
+++ grass/trunk/raster/r.watershed/seg/bseg_close.c 2018-10-09 13:31:07 UTC (rev 73511)
@@ -4,9 +4,7 @@
int bseg_close(BSEG * bseg)
{
- Segment_release(&(bseg->seg));
- close(bseg->fd);
- unlink(bseg->filename);
+ Segment_close(&(bseg->seg));
if (bseg->name) {
G_free(bseg->name);
bseg->name = NULL;
Modified: grass/trunk/raster/r.watershed/seg/bseg_open.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/bseg_open.c 2018-10-09 13:21:00 UTC (rev 73510)
+++ grass/trunk/raster/r.watershed/seg/bseg_open.c 2018-10-09 13:31:07 UTC (rev 73511)
@@ -2,6 +2,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <grass/segment.h>
+#include <grass/glocale.h>
#include "Gwater.h"
@@ -9,7 +10,6 @@
{
char *filename;
int errflag;
- int fd;
bseg->filename = NULL;
bseg->fd = -1;
@@ -17,43 +17,36 @@
bseg->mapset = NULL;
filename = G_tempfile();
- if (-1 == (fd = creat(filename, 0666))) {
- G_warning("bseg_open(): unable to create segment file");
- return -2;
- }
- if (0 > (errflag = Segment_format(fd, Rast_window_rows(),
- Rast_window_cols(), srows, scols,
- sizeof(char)))) {
- close(fd);
- unlink(filename);
+ if (0 > (errflag = Segment_open(&(bseg->seg), filename, Rast_window_rows(),
+ Rast_window_cols(), srows, scols,
+ sizeof(char), nsegs_in_memory))) {
if (errflag == -1) {
- G_warning("bseg_open(): could not write segment file");
+ G_warning(_("File name is invalid"));
return -1;
}
- else {
- G_warning("bseg_open(): illegal configuration parameter(s)");
+ else if (errflag == -2) {
+ G_warning(_("File write error"));
+ return -2;
+ }
+ else if (errflag == -3) {
+ G_warning(_("Illegal parameters are passed"));
return -3;
}
- }
- close(fd);
- if (-1 == (fd = open(filename, 2))) {
- unlink(filename);
- G_warning("bseg_open(): unable to re-open segment file");
- return -4;
- }
- if (0 > (errflag = Segment_init(&(bseg->seg), fd, nsegs_in_memory))) {
- close(fd);
- unlink(filename);
- if (errflag == -1) {
- G_warning("bseg_open(): could not read segment file");
+ else if (errflag == -4) {
+ G_warning(_("File could not be re-opened"));
+ return -4;
+ }
+ else if (errflag == -5) {
+ G_warning(_("Prepared file could not be read"));
return -5;
}
- else {
- G_warning("bseg_open(): out of memory");
+ else if (errflag == -6) {
+ G_warning(_("Out of memory"));
return -6;
}
}
+
bseg->filename = filename;
- bseg->fd = fd;
+
return 0;
}
Modified: grass/trunk/raster/r.watershed/seg/cseg_close.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/cseg_close.c 2018-10-09 13:21:00 UTC (rev 73510)
+++ grass/trunk/raster/r.watershed/seg/cseg_close.c 2018-10-09 13:31:07 UTC (rev 73511)
@@ -5,9 +5,7 @@
int cseg_close(CSEG * cseg)
{
- Segment_release(&(cseg->seg));
- close(cseg->fd);
- unlink(cseg->filename);
+ Segment_close(&(cseg->seg));
if (cseg->name) {
G_free(cseg->name);
cseg->name = NULL;
Modified: grass/trunk/raster/r.watershed/seg/cseg_open.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/cseg_open.c 2018-10-09 13:21:00 UTC (rev 73510)
+++ grass/trunk/raster/r.watershed/seg/cseg_open.c 2018-10-09 13:31:07 UTC (rev 73511)
@@ -1,6 +1,7 @@
#include <grass/gis.h>
#include <unistd.h>
#include <fcntl.h>
+#include <grass/glocale.h>
#include "Gwater.h"
@@ -8,7 +9,6 @@
{
char *filename;
int errflag;
- int fd;
cseg->filename = NULL;
cseg->fd = -1;
@@ -16,44 +16,36 @@
cseg->mapset = NULL;
filename = G_tempfile();
- if (-1 == (fd = creat(filename, 0666))) {
- G_warning("cseg_open(): unable to create segment file");
- return -2;
- }
- if (0 >
- (errflag =
- Segment_format(fd, Rast_window_rows(), Rast_window_cols(), srows,
- scols, sizeof(CELL)))) {
- close(fd);
- unlink(filename);
+ if (0 > (errflag = Segment_open(&(cseg->seg), filename, Rast_window_rows(),
+ Rast_window_cols(), srows, scols,
+ sizeof(CELL), nsegs_in_memory))) {
if (errflag == -1) {
- G_warning("cseg_open(): could not write segment file");
+ G_warning(_("File name is invalid"));
return -1;
}
- else {
- G_warning("cseg_open(): illegal configuration parameter(s)");
+ else if (errflag == -2) {
+ G_warning(_("File write error"));
+ return -2;
+ }
+ else if (errflag == -3) {
+ G_warning(_("Illegal parameters are passed"));
return -3;
}
- }
- close(fd);
- if (-1 == (fd = open(filename, 2))) {
- unlink(filename);
- G_warning("cseg_open(): unable to re-open segment file");
- return -4;
- }
- if (0 > (errflag = Segment_init(&(cseg->seg), fd, nsegs_in_memory))) {
- close(fd);
- unlink(filename);
- if (errflag == -1) {
- G_warning("cseg_open(): could not read segment file");
+ else if (errflag == -4) {
+ G_warning(_("File could not be re-opened"));
+ return -4;
+ }
+ else if (errflag == -5) {
+ G_warning(_("Prepared file could not be read"));
return -5;
}
- else {
- G_warning("cseg_open(): out of memory");
+ else if (errflag == -6) {
+ G_warning(_("Out of memory"));
return -6;
}
}
+
cseg->filename = filename;
- cseg->fd = fd;
+
return 0;
}
Modified: grass/trunk/raster/r.watershed/seg/dseg_close.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/dseg_close.c 2018-10-09 13:21:00 UTC (rev 73510)
+++ grass/trunk/raster/r.watershed/seg/dseg_close.c 2018-10-09 13:31:07 UTC (rev 73511)
@@ -4,9 +4,7 @@
int dseg_close(DSEG * dseg)
{
- Segment_release(&(dseg->seg));
- close(dseg->fd);
- unlink(dseg->filename);
+ Segment_close(&(dseg->seg));
if (dseg->name) {
G_free(dseg->name);
dseg->name = NULL;
Modified: grass/trunk/raster/r.watershed/seg/dseg_open.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/dseg_open.c 2018-10-09 13:21:00 UTC (rev 73510)
+++ grass/trunk/raster/r.watershed/seg/dseg_open.c 2018-10-09 13:31:07 UTC (rev 73511)
@@ -2,6 +2,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <grass/segment.h>
+#include <grass/glocale.h>
#include "Gwater.h"
@@ -9,7 +10,6 @@
{
char *filename;
int errflag;
- int fd;
dseg->filename = NULL;
dseg->fd = -1;
@@ -17,44 +17,36 @@
dseg->mapset = NULL;
filename = G_tempfile();
- if (-1 == (fd = creat(filename, 0666))) {
- G_warning("dseg_open(): unable to create segment file");
- return -2;
- }
- if (0 >
- (errflag =
- Segment_format(fd, Rast_window_rows(), Rast_window_cols(), srows,
- scols, sizeof(double)))) {
- close(fd);
- unlink(filename);
+ if (0 > (errflag = Segment_open(&(dseg->seg), filename, Rast_window_rows(),
+ Rast_window_cols(), srows, scols,
+ sizeof(DCELL), nsegs_in_memory))) {
if (errflag == -1) {
- G_warning("dseg_open(): could not write segment file");
+ G_warning(_("File name is invalid"));
return -1;
}
- else {
- G_warning("dseg_open(): illegal configuration parameter(s)");
+ else if (errflag == -2) {
+ G_warning(_("File write error"));
+ return -2;
+ }
+ else if (errflag == -3) {
+ G_warning(_("Illegal parameters are passed"));
return -3;
}
- }
- close(fd);
- if (-1 == (fd = open(filename, 2))) {
- unlink(filename);
- G_warning("dseg_open(): unable to re-open segment file");
- return -4;
- }
- if (0 > (errflag = Segment_init(&(dseg->seg), fd, nsegs_in_memory))) {
- close(fd);
- unlink(filename);
- if (errflag == -1) {
- G_warning("dseg_open(): could not read segment file");
+ else if (errflag == -4) {
+ G_warning(_("File could not be re-opened"));
+ return -4;
+ }
+ else if (errflag == -5) {
+ G_warning(_("Prepared file could not be read"));
return -5;
}
- else {
- G_warning("dseg_open(): out of memory");
+ else if (errflag == -6) {
+ G_warning(_("Out of memory"));
return -6;
}
}
+
dseg->filename = filename;
- dseg->fd = fd;
+
return 0;
}
Modified: grass/trunk/raster/r.watershed/seg/sseg_close.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/sseg_close.c 2018-10-09 13:21:00 UTC (rev 73510)
+++ grass/trunk/raster/r.watershed/seg/sseg_close.c 2018-10-09 13:31:07 UTC (rev 73511)
@@ -5,8 +5,7 @@
int seg_close(SSEG * sseg)
{
- Segment_release(&(sseg->seg));
- close(sseg->fd);
- unlink(sseg->filename);
+ Segment_close(&(sseg->seg));
+
return 0;
}
Modified: grass/trunk/raster/r.watershed/seg/sseg_open.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/sseg_open.c 2018-10-09 13:21:00 UTC (rev 73510)
+++ grass/trunk/raster/r.watershed/seg/sseg_open.c 2018-10-09 13:31:07 UTC (rev 73511)
@@ -2,6 +2,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <grass/segment.h>
+#include <grass/glocale.h>
#include "Gwater.h"
int
@@ -10,48 +11,41 @@
{
char *filename;
int errflag;
- int fd;
sseg->filename = NULL;
sseg->fd = -1;
filename = G_tempfile();
- if (-1 == (fd = creat(filename, 0666))) {
- G_warning("seg_open(): unable to create segment file");
- return -2;
- }
- if (0 > (errflag = Segment_format(fd, rows, cols,
- row_in_seg, col_in_seg, size_struct))) {
- close(fd);
- unlink(filename);
+ if (0 > (errflag = Segment_open(&(sseg->seg), filename, rows, cols,
+ row_in_seg, col_in_seg,
+ size_struct, nsegs_in_memory))) {
if (errflag == -1) {
- G_warning("seg_open(): could not write segment file");
+ G_warning(_("File name is invalid"));
return -1;
}
- else {
- G_warning("seg_open(): illegal configuration parameter(s)");
+ else if (errflag == -2) {
+ G_warning(_("File write error"));
+ return -2;
+ }
+ else if (errflag == -3) {
+ G_warning(_("Illegal parameters are passed"));
return -3;
}
- }
- close(fd);
- if (-1 == (fd = open(filename, 2))) {
- unlink(filename);
- G_warning("seg_open(): unable to re-open segment file");
- return -4;
- }
- if (0 > (errflag = Segment_init(&(sseg->seg), fd, nsegs_in_memory))) {
- close(fd);
- unlink(filename);
- if (errflag == -1) {
- G_warning("seg_open(): could not read segment file");
+ else if (errflag == -4) {
+ G_warning(_("File could not be re-opened"));
+ return -4;
+ }
+ else if (errflag == -5) {
+ G_warning(_("Prepared file could not be read"));
return -5;
}
- else {
- G_warning("seg_open(): out of memory");
+ else if (errflag == -6) {
+ G_warning(_("Out of memory"));
return -6;
}
}
+
sseg->filename = filename;
- sseg->fd = fd;
+
return 0;
}
More information about the grass-commit
mailing list