main.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /****************************************************************************
  2. *
  3. * MODULE: db.drivers
  4. * AUTHOR(S): Radim Blazek <radim.blazek gmail.com> (original contributor)
  5. * Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>, Stephan Holl
  6. * PURPOSE: lists all database drivers
  7. * COPYRIGHT: (C) 2002-2006, 2012 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/glocale.h>
  18. struct
  19. {
  20. int f;
  21. } parms;
  22. /* function prototypes */
  23. static void parse_command_line(int, char **);
  24. int main(int argc, char **argv)
  25. {
  26. dbDbmscap *list, *p;
  27. parse_command_line(argc, argv);
  28. list = db_read_dbmscap();
  29. if (list == NULL) {
  30. G_fatal_error(_("Unable to read dbmscap file"));
  31. }
  32. for (p = list; p; p = p->next) {
  33. fprintf(stdout, "%s", p->driverName);
  34. if (parms.f)
  35. fprintf(stdout, ":%s", p->comment);
  36. fprintf(stdout, "\n");
  37. }
  38. exit(EXIT_SUCCESS);
  39. }
  40. static void parse_command_line(int argc, char **argv)
  41. {
  42. struct Flag *full, *print;
  43. struct GModule *module;
  44. /* Initialize the GIS calls */
  45. G_gisinit(argv[0]);
  46. full = G_define_flag();
  47. full->key = 'f';
  48. full->description = _("Full output");
  49. print = G_define_flag();
  50. print->key = 'p';
  51. print->description = _("Print drivers and exit");
  52. /* Set description */
  53. module = G_define_module();
  54. G_add_keyword(_("database"));
  55. G_add_keyword(_("connection settings"));
  56. module->description = _("Lists all database drivers.");
  57. if (G_parser(argc, argv))
  58. exit(EXIT_FAILURE);
  59. parms.f = full->answer;
  60. }