GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71933
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  (C) 1999-2009, 2011 by the GRASS Development Team
9 
10  This program is free software under the GNU General Public License
11  (>=v2). Read the file COPYING that comes with GRASS for details.
12 
13  \author Joel Jones (CERL/UIUC), Radim Blazek
14  \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
15 */
16 
17 #include <grass/gis.h>
18 #include <grass/dbmi.h>
19 #include <grass/glocale.h>
20 
21 /*!
22  \brief Check if output is legal table name
23 
24  Rule: [A-Za-z][A-Za-z0-9_@]*
25  \param s table name to be checked
26 
27  \return 1 OK
28  \return -1 if name does not start with letter A..Za..z or if name does
29  not continue with A..Za..z0..9_@
30 */
31 int db_legal_tablename(const char *s)
32 {
33  char buf[GNAME_MAX];
34 
35  sprintf(buf, "%s", s);
36 
37  if (*s == '.' || *s == 0) {
38  G_warning(_("Illegal table map name <%s>. May not contain '.' or 'NULL'."),
39  buf);
40  return DB_FAILED;
41  }
42 
43  /* file name must start with letter */
44  if (!((*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z'))) {
45  G_warning(_("Illegal table map name <%s>. Must start with a letter."),
46  buf);
47  return DB_FAILED;
48  }
49 
50  for (s++; *s; s++)
51  if (!
52  ((*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z') ||
53  (*s >= '0' && *s <= '9') || *s == '_' || *s == '@')) {
54  G_warning(_("Illegal table map name <%s>. Character <%c> not allowed."),
55  buf, *s);
56  return DB_FAILED;
57  }
58 
59  return DB_OK;
60 }
#define DB_FAILED
Definition: dbmi.h:72
#define GNAME_MAX
Definition: gis.h:148
#define _(str)
Definition: glocale.h:13
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition: gis/error.c:203
#define DB_OK
Definition: dbmi.h:71