main.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 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(_("scripts"));
  31. module->label =
  32. _("Prints a message, warning, progress info, or fatal error in the GRASS way.");
  33. module->description =
  34. _("This module should be used in scripts for messages served to user.");
  35. warning = G_define_flag();
  36. warning->key = 'w';
  37. warning->guisection = _("Type");
  38. warning->description = _("Print message as warning");
  39. fatal = G_define_flag();
  40. fatal->key = 'e';
  41. fatal->guisection = _("Type");
  42. fatal->description = _("Print message as fatal error");
  43. debug_flag = G_define_flag();
  44. debug_flag->key = 'd';
  45. debug_flag->guisection = _("Type");
  46. debug_flag->description = _("Print message as debug message");
  47. percent = G_define_flag();
  48. percent->key = 'p';
  49. percent->guisection = _("Type");
  50. percent->description = _("Print message as progress info");
  51. important = G_define_flag();
  52. important->key = 'i';
  53. important->guisection = _("Level");
  54. important->description = _("Print message in all but full quiet mode");
  55. verbose = G_define_flag();
  56. verbose->key = 'v';
  57. verbose->guisection = _("Level");
  58. verbose->description = _("Print message only in verbose mode");
  59. message = G_define_option();
  60. message->key = "message";
  61. message->type = TYPE_STRING;
  62. message->key_desc = "string";
  63. message->required = YES;
  64. message->description = _("Text of the message to be printed");
  65. debug_opt = G_define_option();
  66. debug_opt->key = "debug";
  67. debug_opt->type = TYPE_INTEGER;
  68. debug_opt->required = NO;
  69. debug_opt->guisection = _("Level");
  70. debug_opt->answer = "1";
  71. debug_opt->options = "0-5";
  72. debug_opt->description = _("Level to use for debug messages");
  73. if (G_parser(argc, argv))
  74. exit(EXIT_FAILURE);
  75. if (fatal->answer + warning->answer + debug_flag->answer +
  76. verbose->answer > 1)
  77. G_fatal_error(_("Select only one message level"));
  78. debug_level = atoi(debug_opt->answer);
  79. if (fatal->answer)
  80. G_fatal_error("%s", message->answer);
  81. else if (warning->answer)
  82. G_warning("%s", message->answer);
  83. else if (percent->answer) {
  84. int i, n, s;
  85. i = n = s = -1;
  86. sscanf(message->answer, "%d %d %d", &i, &n, &s);
  87. if (s == -1)
  88. G_fatal_error(_("Unable to parse input message"));
  89. G_percent(i, n, s);
  90. }
  91. else if (debug_flag->answer)
  92. G_debug(debug_level, "%s", message->answer);
  93. else if (important->answer)
  94. G_important_message("%s", message->answer);
  95. else if (verbose->answer)
  96. G_verbose_message("%s", message->answer);
  97. else
  98. G_message("%s", message->answer);
  99. exit(EXIT_SUCCESS);
  100. }