main.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. * Martin Landa - landa.martin AT gmail.com
  8. * PURPOSE: Provides a means of reporting the contents of GRASS
  9. * projection information files and creating
  10. * new projection information files.
  11. * COPYRIGHT: (C) 2007,2010,2012 by the GRASS Development Team
  12. *
  13. * This program is free software under the GNU General Public
  14. * License (>=v2). Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. *****************************************************************************/
  18. #include <stdlib.h>
  19. #include <grass/gis.h>
  20. #include <grass/glocale.h>
  21. int main(int argc, char *argv[])
  22. {
  23. struct Flag *warning, *fatal, *percent, *debug_flag, *verbose, *important;
  24. struct Option *message, *debug_opt;
  25. struct GModule *module;
  26. int debug_level;
  27. G_gisinit(argv[0]);
  28. module = G_define_module();
  29. G_add_keyword(_("general"));
  30. G_add_keyword(_("support"));
  31. G_add_keyword(_("scripts"));
  32. module->label =
  33. _("Prints a message, warning, progress info, or fatal error in the GRASS way.");
  34. module->description =
  35. _("This module should be used in scripts for messages served to user.");
  36. warning = G_define_flag();
  37. warning->key = 'w';
  38. warning->guisection = _("Type");
  39. warning->description = _("Print message as warning");
  40. fatal = G_define_flag();
  41. fatal->key = 'e';
  42. fatal->guisection = _("Type");
  43. fatal->description = _("Print message as fatal error");
  44. debug_flag = G_define_flag();
  45. debug_flag->key = 'd';
  46. debug_flag->guisection = _("Type");
  47. debug_flag->description = _("Print message as debug message");
  48. percent = G_define_flag();
  49. percent->key = 'p';
  50. percent->guisection = _("Type");
  51. percent->description = _("Print message as progress info");
  52. important = G_define_flag();
  53. important->key = 'i';
  54. important->guisection = _("Level");
  55. important->label = _("Print message in all modes except of quiet mode");
  56. important->description = _("Message is printed on GRASS_VERBOSE>=1");
  57. verbose = G_define_flag();
  58. verbose->key = 'v';
  59. verbose->guisection = _("Level");
  60. verbose->label = _("Print message only in verbose mode");
  61. verbose->description = _("Message is printed only on GRASS_VERBOSE>=3");
  62. message = G_define_option();
  63. message->key = "message";
  64. message->type = TYPE_STRING;
  65. message->key_desc = "string";
  66. message->required = YES;
  67. message->label = _("Text of the message to be printed");
  68. message->description = _("Message is printed on GRASS_VERBOSE>=2");
  69. debug_opt = G_define_option();
  70. debug_opt->key = "debug";
  71. debug_opt->type = TYPE_INTEGER;
  72. debug_opt->required = NO;
  73. debug_opt->guisection = _("Level");
  74. debug_opt->answer = "1";
  75. debug_opt->options = "0-5";
  76. debug_opt->description = _("Level to use for debug messages");
  77. if (G_parser(argc, argv))
  78. exit(EXIT_FAILURE);
  79. if (fatal->answer + warning->answer + debug_flag->answer +
  80. verbose->answer > 1)
  81. G_fatal_error(_("Select only one message level"));
  82. debug_level = atoi(debug_opt->answer);
  83. if (fatal->answer)
  84. G_fatal_error("%s", message->answer);
  85. else if (warning->answer)
  86. G_warning("%s", message->answer);
  87. else if (percent->answer) {
  88. int i, n, s;
  89. i = n = s = -1;
  90. sscanf(message->answer, "%d %d %d", &i, &n, &s);
  91. if (s == -1)
  92. G_fatal_error(_("Unable to parse input message"));
  93. G_percent(i, n, s);
  94. }
  95. else if (debug_flag->answer)
  96. G_debug(debug_level, "%s", message->answer);
  97. else if (important->answer)
  98. G_important_message("%s", message->answer);
  99. else if (verbose->answer)
  100. G_verbose_message("%s", message->answer);
  101. else
  102. G_message("%s", message->answer);
  103. exit(EXIT_SUCCESS);
  104. }