ARB
arb_message.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : arb_message.cxx //
4 // Purpose : raise aw_message from external scripts //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in November 2003 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // =============================================================== //
11 
12 #include <arbdbt.h>
13 
14 int ARB_main(int argc, char *argv[]) {
15  if (argc == 1) {
16  fprintf(stderr, "Usage: arb_message \"the message\"\n");
17  return EXIT_FAILURE;
18  }
19 
20  const char *progname = argv[0];
21  if (!progname || progname[0] == 0) progname = "arb_message";
22 
23  char *the_message = ARB_strdup(argv[1]);
24  size_t len = strlen(the_message);
25  char *unencoded_lf = NULp;
26  while ((unencoded_lf = strstr(the_message, "\\n"))) {
27  unencoded_lf[0] = '\n';
28  size_t restlen = len-(unencoded_lf-the_message)-1; // len - "chars before \n" - "\n"
29  memmove(unencoded_lf+1, unencoded_lf+2, restlen+1); // copy restlen plus 0-terminator
30  }
31 
32  {
33  GB_shell shell;
34  GBDATA *gb_main = GB_open(":", "r");
35  if (!gb_main) {
36  fprintf(stderr, "%s: %s\n", progname, the_message);
37  }
38  else {
39  GBT_message(gb_main, the_message);
40  GB_close(gb_main);
41  }
42  }
43  free(the_message);
44  return EXIT_SUCCESS;
45 }
GBDATA * GB_open(const char *path, const char *opent)
Definition: ad_load.cxx:1363
int ARB_main(int argc, char *argv[])
Definition: arb_message.cxx:14
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
#define EXIT_SUCCESS
Definition: arb_a2ps.c:154
#define EXIT_FAILURE
Definition: arb_a2ps.c:157
void GBT_message(GBDATA *gb_main, const char *msg)
Definition: adtools.cxx:238
#define NULp
Definition: cxxforward.h:97
GBDATA * gb_main
Definition: adname.cxx:33
void GB_close(GBDATA *gbd)
Definition: arbdb.cxx:625