Skip to content

Commit

Permalink
apply .clang-format (#2715)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilason committed Dec 22, 2022
1 parent 5546e01 commit 1ca8e86
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 45 deletions.
59 changes: 29 additions & 30 deletions doc/raster/r.example/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/****************************************************************************
*
* MODULE: r.example
Expand All @@ -10,8 +9,8 @@
* COPYRIGHT: (C) 2002, 2005-2009 by the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
* for details.
* License (>=v2). Read the file COPYING that comes with GRASS
* for details.
*
*****************************************************************************/

Expand All @@ -22,15 +21,15 @@
#include <grass/raster.h>
#include <grass/glocale.h>

/*
* global function declaration
/*
* global function declaration
*/
extern CELL f_c(CELL);
extern FCELL f_f(FCELL);
extern DCELL f_d(DCELL);

/*
* function definitions
* function definitions
*/

CELL c_calc(CELL x)
Expand Down Expand Up @@ -58,25 +57,26 @@ DCELL d_calc(DCELL x)
*/
int main(int argc, char *argv[])
{
struct Cell_head cellhd; /* it stores region information,
and header information of rasters */
char *name; /* input raster name */
char *result; /* output raster name */
char *mapset; /* mapset name */
void *inrast; /* input buffer */
unsigned char *outrast; /* output buffer */
struct Cell_head cellhd; /* it stores region information,
and header information of rasters */
char *name; /* input raster name */
char *result; /* output raster name */
char *mapset; /* mapset name */
void *inrast; /* input buffer */
unsigned char *outrast; /* output buffer */
int nrows, ncols;
int row, col;
int infd, outfd; /* file descriptor */
RASTER_MAP_TYPE data_type; /* type of the map (CELL/DCELL/...) */
struct History history; /* holds meta-data (title, comments,..) */
int infd, outfd; /* file descriptor */
RASTER_MAP_TYPE data_type; /* type of the map (CELL/DCELL/...) */
struct History history; /* holds meta-data (title, comments,..) */

struct GModule *module; /* GRASS module for parsing arguments */
struct GModule *module; /* GRASS module for parsing arguments */

struct Option *input, *output; /* options */
struct Option *input, *output; /* options */

/* initialize GIS environment */
G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */
G_gisinit(
argv[0]); /* reads grass env, stores program name to G_program_name() */

/* initialize module */
module = G_define_module();
Expand All @@ -98,7 +98,7 @@ int main(int argc, char *argv[])
name = input->answer;
result = output->answer;

/* returns NULL if the map was not found in any mapset,
/* returns NULL if the map was not found in any mapset,
* mapset name otherwise */
mapset = (char *)G_find_raster2(name, "");
if (mapset == NULL)
Expand Down Expand Up @@ -142,19 +142,19 @@ int main(int argc, char *argv[])
/* use different function for each data type */
switch (data_type) {
case CELL_TYPE:
c = ((CELL *) inrast)[col];
c = c_calc(c); /* calculate */
((CELL *) outrast)[col] = c;
c = ((CELL *)inrast)[col];
c = c_calc(c); /* calculate */
((CELL *)outrast)[col] = c;
break;
case FCELL_TYPE:
f = ((FCELL *) inrast)[col];
f = f_calc(f); /* calculate */
((FCELL *) outrast)[col] = f;
f = ((FCELL *)inrast)[col];
f = f_calc(f); /* calculate */
((FCELL *)outrast)[col] = f;
break;
case DCELL_TYPE:
d = ((DCELL *) inrast)[col];
d = d_calc(d); /* calculate */
((DCELL *) outrast)[col] = d;
d = ((DCELL *)inrast)[col];
d = d_calc(d); /* calculate */
((DCELL *)outrast)[col] = d;
break;
}
}
Expand All @@ -176,6 +176,5 @@ int main(int argc, char *argv[])
Rast_command_history(&history);
Rast_write_history(result, &history);


exit(EXIT_SUCCESS);
}
33 changes: 18 additions & 15 deletions doc/vector/v.example/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/****************************************************************
*
* MODULE: v.example
Expand Down Expand Up @@ -31,7 +30,7 @@ int main(int argc, char *argv[])
struct line_cats *Cats;
int i, type, cat, ncols, nrows, col, more, open3d;
char *mapset, sql[200];
struct GModule *module; /* GRASS module for parsing arguments */
struct GModule *module; /* GRASS module for parsing arguments */
struct Option *old, *new;
dbDriver *driver;
dbHandle handle;
Expand Down Expand Up @@ -61,11 +60,13 @@ int main(int argc, char *argv[])
if (G_parser(argc, argv))
exit(EXIT_FAILURE);

/* Create and initialize struct's where to store points/lines and categories */
/* Create and initialize struct's where to store
points/lines and categories
*/
Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();

/* Check 1) output is legal vector name; 2) if can find input map;
/* Check 1) output is legal vector name; 2) if can find input map;
3) if input was found in current mapset, check if input != output.
lib/vector/Vlib/legal_vname.c
*/
Expand All @@ -74,7 +75,7 @@ int main(int argc, char *argv[])
if ((mapset = (char *)G_find_vector2(old->answer, "")) == NULL)
G_fatal_error(_("Vector map <%s> not found"), old->answer);

/* Predetermine level at which a map will be opened for reading
/* Predetermine level at which a map will be opened for reading
lib/vector/Vlib/open.c
*/
if (Vect_set_open_level(2))
Expand Down Expand Up @@ -109,13 +110,13 @@ int main(int argc, char *argv[])
G_fatal_error(_("Database connection not defined for layer %d"), 1);
}

/* Output information useful for debuging
/* Output information useful for debuging
include/vect/dig_structs.h
*/
G_debug(1,
"Field number:%d; Name:<%s>; Driver:<%s>; Database:<%s>; Table:<%s>; Key:<%s>;\n",
Fi->number, Fi->name, Fi->driver, Fi->database, Fi->table,
Fi->key);
"Field number:%d; Name:<%s>; Driver:<%s>; Database:<%s>; "
"Table:<%s>; Key:<%s>;\n",
Fi->number, Fi->name, Fi->driver, Fi->database, Fi->table, Fi->key);

/* Prepeare strings for use in db_* calls */
db_init_string(&dbsql);
Expand Down Expand Up @@ -170,8 +171,8 @@ int main(int argc, char *argv[])
G_debug(1, "SQL: \"%s\"", sql);
db_set_string(&dbsql, sql);
/* Now execute query */
if (db_open_select_cursor(driver, &dbsql, &cursor, DB_SEQUENTIAL)
!= DB_OK)
if (db_open_select_cursor(driver, &dbsql, &cursor, DB_SEQUENTIAL) !=
DB_OK)
G_warning(_("Unable to get attribute data for cat %d"), cat);
else {
/* Result count */
Expand All @@ -181,7 +182,8 @@ int main(int argc, char *argv[])
/* Let's output every columns name and value */
while (1) {
if (db_fetch(&cursor, DB_NEXT, &more) != DB_OK) {
G_warning(_("Error while retrieving database record for cat %d"),
G_warning(_("Error while retrieving database record "
"for cat %d"),
cat);
break;
}
Expand All @@ -206,13 +208,14 @@ int main(int argc, char *argv[])
Fin = Vect_default_field_info(&Out, 1, NULL, GV_1TABLE);
driver = db_start_driver_open_database(Fin->driver, Fin->database);
G_debug(1,
"Field number:%d; Name:<%s>; Driver:<%s>; Database:<%s>; Table:<%s>; Key:<%s>;\n",
"Field number:%d; Name:<%s>; Driver:<%s>; Database:<%s>; "
"Table:<%s>; Key:<%s>;\n",
Fin->number, Fin->name, Fin->driver, Fin->database, Fin->table,
Fin->key);

/* Let's copy attribute table data */
if (db_copy_table(Fi->driver, Fi->database, Fi->table,
Fin->driver, Vect_subst_var(Fin->database, &Out),
if (db_copy_table(Fi->driver, Fi->database, Fi->table, Fin->driver,
Vect_subst_var(Fin->database, &Out),
Fin->table) == DB_FAILED)
G_warning(_("Unable to copy attribute table to vector map <%s>"),
new->answer);
Expand Down

0 comments on commit 1ca8e86

Please sign in to comment.