GRASS 8 Programmer's Manual 8.6.0dev(2026)-55de52a352
Loading...
Searching...
No Matches
legal_dbname.c
Go to the documentation of this file.
1/*!
2 \file lib/db/dbmi_base/legal_dbname.c
3
4 \brief DBMI Library (base) - validate DB names
5
6 \todo Are we as restrictive here as for vector names?
7
8 SPDX-FileCopyrightText: 1999-2009, 2011 GRASS Development Team
9 SPDX-License-Identifier: GPL-2.0-or-later
10
11 \author Joel Jones (CERL/UIUC), Radim Blazek
12 \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
13 */
14
15#include <grass/gis.h>
16#include <grass/dbmi.h>
17#include <grass/glocale.h>
18
19/*!
20 \brief Check if output is legal table name
21
22 Rule: [A-Za-z][A-Za-z0-9_@]*
23 \param s table name to be checked
24
25 \return 1 OK
26 \return -1 if name does not start with letter A..Za..z or if name does
27 not continue with A..Za..z0..9_@
28 */
29int db_legal_tablename(const char *s)
30{
31 char buf[GNAME_MAX];
32
33 snprintf(buf, sizeof(buf), "%s", s);
34
35 if (*s == '.' || *s == 0) {
37 _("Illegal table map name <%s>. May not contain '.' or 'NULL'."),
38 buf);
39 return DB_FAILED;
40 }
41
42 /* file name must start with letter */
43 if (!((*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z'))) {
44 G_warning(_("Illegal table map name <%s>. Must start with a letter."),
45 buf);
46 return DB_FAILED;
47 }
48
49 for (s++; *s; s++)
50 if (!((*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z') ||
51 (*s >= '0' && *s <= '9') || *s == '_' || *s == '@')) {
53 _("Illegal table map name <%s>. Character <%c> not allowed."),
54 buf, *s);
55 return DB_FAILED;
56 }
57
58 return DB_OK;
59}
Main header of GRASS DataBase Management Interface.
#define DB_FAILED
Definition dbmi.h:70
#define DB_OK
Definition dbmi.h:69
void G_warning(const char *,...) __attribute__((format(printf
#define GNAME_MAX
Definition gis.h:193
#define _(str)
Definition glocale.h:10
int db_legal_tablename(const char *s)
Check if output is legal table name.