main.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /****************************************************************************
  2. *
  3. * MODULE: db.createdb
  4. * AUTHOR(S): Radim Blazek <radim.blazek gmail.com> (original contributor)
  5. * Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
  6. * PURPOSE: create a new empty database
  7. * COPYRIGHT: (C) 2002-2006 by the GRASS Development Team
  8. *
  9. * This program is free software under the GNU General Public
  10. * License (>=v2). Read the file COPYING that comes with GRASS
  11. * for details.
  12. *
  13. *****************************************************************************/
  14. #include <stdlib.h>
  15. #include <grass/dbmi.h>
  16. #include <grass/gis.h>
  17. #include <grass/codes.h>
  18. #include <grass/glocale.h>
  19. struct
  20. {
  21. char *driver, *database;
  22. } parms;
  23. /* function prototypes */
  24. static void parse_command_line(int, char **);
  25. int main(int argc, char **argv)
  26. {
  27. dbDriver *driver;
  28. dbHandle handle;
  29. int stat;
  30. parse_command_line(argc, argv);
  31. driver = db_start_driver(parms.driver);
  32. if (driver == NULL)
  33. G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
  34. db_init_handle(&handle);
  35. db_set_handle(&handle, parms.database, NULL);
  36. stat = db_create_database(driver, &handle);
  37. db_shutdown_driver(driver);
  38. exit(stat == DB_OK ? EXIT_SUCCESS : EXIT_FAILURE);
  39. }
  40. static void parse_command_line(int argc, char **argv)
  41. {
  42. struct Option *driver, *database;
  43. struct GModule *module;
  44. /* Initialize the GIS calls */
  45. G_gisinit(argv[0]);
  46. driver = G_define_standard_option(G_OPT_DB_DRIVER);
  47. driver->options = db_list_drivers();
  48. driver->required = YES;
  49. database = G_define_standard_option(G_OPT_DB_DATABASE);
  50. database->required = YES;
  51. /* Set description */
  52. module = G_define_module();
  53. G_add_keyword(_("database"));
  54. G_add_keyword(_("SQL"));
  55. module->description = _("Creates an empty database.");
  56. if (G_parser(argc, argv))
  57. exit(EXIT_FAILURE);
  58. parms.driver = driver->answer;
  59. parms.database = database->answer;
  60. }