main.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. ****************************************************************************
  3. *
  4. * MODULE: g.message
  5. * AUTHOR(S): Jachym Cepicky - jachym AT les-ejk cz
  6. * Hamish Bowman - hamish_b AT yahoo com
  7. * PURPOSE: Provides a means of reporting the contents of GRASS
  8. * projection information files and creating
  9. * new projection information files.
  10. * COPYRIGHT: (C) 2007 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. *****************************************************************************/
  17. #include <stdlib.h>
  18. #include <grass/gis.h>
  19. #include <grass/glocale.h>
  20. int main(int argc, char *argv[])
  21. {
  22. struct Flag *warning, *fatal, *debug_flag, *verbose, *important;
  23. struct Option *message, *debug_opt;
  24. struct GModule *module;
  25. int debug_level;
  26. G_gisinit(argv[0]);
  27. module = G_define_module();
  28. G_add_keyword(_("general"));
  29. module->label =
  30. _("Prints a message, warning, or fatal error the GRASS way.");
  31. module->description =
  32. _("This module should be used in scripts for messages served to user.");
  33. warning = G_define_flag();
  34. warning->key = 'w';
  35. warning->guisection = "Input";
  36. warning->description = _("Print message as GRASS warning");
  37. fatal = G_define_flag();
  38. fatal->key = 'e';
  39. fatal->guisection = "Input";
  40. fatal->description = _("Print message as GRASS fatal error");
  41. debug_flag = G_define_flag();
  42. debug_flag->key = 'd';
  43. debug_flag->guisection = "Input";
  44. debug_flag->description = _("Print message as GRASS debug message");
  45. important = G_define_flag();
  46. important->key = 'i';
  47. important->guisection = "Input";
  48. important->description = _("Print message in all but full quiet mode");
  49. verbose = G_define_flag();
  50. verbose->key = 'v';
  51. verbose->guisection = "Input";
  52. verbose->description = _("Print message only if in verbose mode");
  53. message = G_define_option();
  54. message->key = "message";
  55. message->type = TYPE_STRING;
  56. message->key_desc = "string";
  57. message->required = YES;
  58. message->guisection = "Input";
  59. message->description = _("Text of the message to be printed");
  60. debug_opt = G_define_option();
  61. debug_opt->key = "debug";
  62. debug_opt->type = TYPE_INTEGER;
  63. debug_opt->required = NO;
  64. debug_opt->guisection = "Input";
  65. debug_opt->answer = "1";
  66. debug_opt->options = "0-5";
  67. debug_opt->description = _("Level to use for debug messages");
  68. if (G_parser(argc, argv))
  69. exit(EXIT_FAILURE);
  70. if (fatal->answer + warning->answer + debug_flag->answer +
  71. verbose->answer > 1)
  72. G_fatal_error(_("Select only one message level."));
  73. debug_level = atoi(debug_opt->answer);
  74. if (fatal->answer)
  75. G_fatal_error(message->answer);
  76. else if (warning->answer)
  77. G_warning(message->answer);
  78. else if (debug_flag->answer)
  79. G_debug(debug_level, message->answer);
  80. else if (verbose->answer)
  81. G_verbose_message(message->answer);
  82. else if (important->answer)
  83. G_important_message(message->answer);
  84. else
  85. G_message(message->answer);
  86. exit(EXIT_SUCCESS);
  87. }