Skip to content

Commit

Permalink
Indent most of C code (#2544)
Browse files Browse the repository at this point in the history
Indents most of the C and C++ code except for what is reported by indent as issues.
  • Loading branch information
wenzeslaus committed Aug 27, 2022
1 parent e817643 commit 40b5982
Show file tree
Hide file tree
Showing 2,584 changed files with 226,491 additions and 221,800 deletions.
20 changes: 10 additions & 10 deletions db/db.columns/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ int main(int argc, char **argv)
parse_command_line(argc, argv);

if (!db_table_exists(parms.driver, parms.database, parms.table)) {
G_warning(_("Table <%s> not found in database <%s> using driver <%s>"),
parms.table, parms.database, parms.driver);
exit(EXIT_FAILURE);
G_warning(_("Table <%s> not found in database <%s> using driver <%s>"),
parms.table, parms.database, parms.driver);
exit(EXIT_FAILURE);
}

driver = db_start_driver(parms.driver);
if (driver == NULL)
G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
G_fatal_error(_("Unable to start driver <%s>"), parms.driver);

db_init_handle(&handle);
db_set_handle(&handle, parms.database, NULL);
Expand All @@ -59,15 +59,15 @@ int main(int argc, char **argv)
db_init_string(&table_name);
db_set_string(&table_name, parms.table);
if (db_describe_table(driver, &table_name, &table) != DB_OK)
G_fatal_error(_("Unable to describe table <%s>"), parms.table);
G_fatal_error(_("Unable to describe table <%s>"), parms.table);

db_close_database(driver);
db_shutdown_driver(driver);

ncols = db_get_table_number_of_columns(table);
for (col = 0; col < ncols; col++)
fprintf(stdout, "%s\n",
db_get_column_name(db_get_table_column(table, col)));
fprintf(stdout, "%s\n",
db_get_column_name(db_get_table_column(table, col)));

exit(EXIT_SUCCESS);
}
Expand All @@ -88,11 +88,11 @@ static void parse_command_line(int argc, char **argv)
driver = G_define_standard_option(G_OPT_DB_DRIVER);
driver->options = db_list_drivers();
if ((drv = db_get_default_driver_name()))
driver->answer = (char *) drv;
driver->answer = (char *)drv;

database = G_define_standard_option(G_OPT_DB_DATABASE);
if ((db = db_get_default_database_name()))
database->answer = (char *) db;
database->answer = (char *)db;

/* Set description */
module = G_define_module();
Expand All @@ -101,7 +101,7 @@ static void parse_command_line(int argc, char **argv)
module->description = _("List all columns for a given table.");

if (G_parser(argc, argv))
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);

parms.driver = driver->answer;
parms.database = database->answer;
Expand Down
133 changes: 68 additions & 65 deletions db/db.connect/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(int argc, char *argv[])
G_add_keyword(_("attribute table"));
G_add_keyword(_("connection settings"));
module->description =
_("Prints/sets general DB connection for current mapset.");
_("Prints/sets general DB connection for current mapset.");

print = G_define_flag();
print->key = 'p';
Expand All @@ -54,15 +54,16 @@ int main(int argc, char *argv[])

shell = G_define_flag();
shell->key = 'g';
shell->description = _("Print current connection parameters using shell style and exit");
shell->description =
_("Print current connection parameters using shell style and exit");
shell->guisection = _("Print");

check_set_default = G_define_flag();
check_set_default->key = 'c';
check_set_default->description =
_("Check connection parameters, set if uninitialized, and exit");
_("Check connection parameters, set if uninitialized, and exit");
check_set_default->guisection = _("Set");

def = G_define_flag();
def->key = 'd';
def->label = _("Set from default settings and exit");
Expand All @@ -74,19 +75,20 @@ int main(int argc, char *argv[])
driver = G_define_standard_option(G_OPT_DB_DRIVER);
driver->options = db_list_drivers();
if (strcmp(DB_DEFAULT_DRIVER, "sqlite") == 0) {
driver->answer = "sqlite";
driver->answer = "sqlite";
}
else {
driver->answer = "dbf";
driver->answer = "dbf";
}
driver->guisection = _("Set");

database = G_define_standard_option(G_OPT_DB_DATABASE);
if (strcmp(DB_DEFAULT_DRIVER, "sqlite") == 0) {
database->answer = "$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db";
database->answer =
"$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db";
}
else {
database->answer = "$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/";
database->answer = "$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/";
}
database->guisection = _("Set");

Expand All @@ -99,7 +101,7 @@ int main(int argc, char *argv[])
group->required = NO;
group->multiple = NO;
group->description = _("Default group of database users to which "
"select privilege is granted");
"select privilege is granted");
group->guisection = _("Set");

/* commented due to new mechanism - see db.login
Expand All @@ -119,11 +121,11 @@ int main(int argc, char *argv[])
*/

if (G_parser(argc, argv))
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);

if (print->answer || shell->answer) {
/* get and print connection in shell style */
if (db_get_connection(&conn) == DB_OK) {
/* get and print connection in shell style */
if (db_get_connection(&conn) == DB_OK) {
if (shell->answer) {
fprintf(stdout, "driver=%s\n",
conn.driverName ? conn.driverName : "");
Expand All @@ -135,121 +137,121 @@ int main(int argc, char *argv[])
}
else {
databaseName = substitute_variables(&conn);

fprintf(stdout, "driver: %s\n",
conn.driverName ? conn.driverName : "");
/* substitute variables */
fprintf(stdout, "database: %s\n", databaseName);
G_free(database);

fprintf(stdout, "schema: %s\n",
conn.schemaName ? conn.schemaName : "");
fprintf(stdout, "group: %s\n", conn.group ? conn.group : "");
}
}
else
G_fatal_error(_("Database connection not defined. "
"Run db.connect."));
exit(EXIT_SUCCESS);
else
G_fatal_error(_("Database connection not defined. "
"Run db.connect."));

exit(EXIT_SUCCESS);
}

if (check_set_default->answer) {
/* check connection and set to system-wide default in required */
/*
* TODO: improve db_{get,set}_connection() to not return DB_OK on error
* (thus currently there is no point in checking for that here)
*/
db_get_connection(&conn);
/* check connection and set to system-wide default in required */
/*
* TODO: improve db_{get,set}_connection() to not return DB_OK on error
* (thus currently there is no point in checking for that here)
*/
db_get_connection(&conn);

if (!conn.driverName && !conn.databaseName) {
if (!conn.driverName && !conn.databaseName) {

db_set_default_connection();
db_get_connection(&conn);
db_set_default_connection();
db_get_connection(&conn);

databaseName = substitute_variables(&conn);
G_important_message(_("Default driver / database set to:\n"
"driver: %s\ndatabase: %s"), conn.driverName,
databaseName);
}
G_important_message(_("Default driver / database set to:\n"
"driver: %s\ndatabase: %s"),
conn.driverName, databaseName);
}
else {
G_important_message(_("DB settings already defined, nothing to do"));
}
/* they must be a matched pair, so if one is set but not the other
then give up and let the user figure it out */
if (!conn.driverName) {
G_fatal_error(_("Default driver is not set"));
}
if (!conn.databaseName) {
G_fatal_error(_("Default database is not set"));
}

/* connection either already existed or now exists */
exit(EXIT_SUCCESS);

/* they must be a matched pair, so if one is set but not the other
then give up and let the user figure it out */
if (!conn.driverName) {
G_fatal_error(_("Default driver is not set"));
}
if (!conn.databaseName) {
G_fatal_error(_("Default database is not set"));
}

/* connection either already existed or now exists */
exit(EXIT_SUCCESS);
}

if (def->answer) {
db_set_default_connection();
db_get_connection(&conn);
db_set_default_connection();
db_get_connection(&conn);

databaseName = substitute_variables(&conn);
G_important_message(_("Default driver / database set to:\n"
"driver: %s\ndatabase: %s"), conn.driverName,
databaseName);
exit(EXIT_SUCCESS);
G_important_message(_("Default driver / database set to:\n"
"driver: %s\ndatabase: %s"), conn.driverName,
databaseName);
exit(EXIT_SUCCESS);
}

/* do not read current, set new connection from options */
G_zero(&conn, sizeof(dbConnection));

if (driver->answer)
conn.driverName = driver->answer;
conn.driverName = driver->answer;

if (database->answer)
conn.databaseName = database->answer;
conn.databaseName = database->answer;

if (schema->answer)
conn.schemaName = schema->answer;
conn.schemaName = schema->answer;

if (group->answer)
conn.group = group->answer;
conn.group = group->answer;

db_set_connection(&conn);
/* check */
if (db_get_connection(&conn) != DB_OK) {
G_fatal_error(_("Unable to set default database connection"));
G_fatal_error(_("Unable to set default database connection"));

exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}

exit(EXIT_SUCCESS);
}

char *substitute_variables(dbConnection *conn)
char *substitute_variables(dbConnection * conn)
{
char *database, *c, buf[GPATH_MAX];

if (!conn->databaseName)
return NULL;

database = (char *) G_malloc(GPATH_MAX);
database = (char *)G_malloc(GPATH_MAX);
strcpy(database, conn->databaseName);

strcpy(buf, database);
c = (char *)strstr(buf, "$GISDBASE");
if (c != NULL) {
*c = '\0';
sprintf(database, "%s%s%s", buf, G_gisdbase(), c + 9);
}

strcpy(buf, database);
c = (char *)strstr(buf, "$LOCATION_NAME");
if (c != NULL) {
*c = '\0';
sprintf(database, "%s%s%s", buf, G_location(), c + 14);
}

strcpy(buf, database);
c = (char *)strstr(buf, "$MAPSET");
if (c != NULL) {
Expand All @@ -260,8 +262,9 @@ char *substitute_variables(dbConnection *conn)
if (strcmp(conn->driverName, "sqlite") == 0 ||
strcmp(conn->driverName, "dbf") == 0) {
char *p;

p = database;
while(*p) {
while (*p) {
if (*p == '/')
*p = HOST_DIRSEP;
p++;
Expand Down

0 comments on commit 40b5982

Please sign in to comment.