File: arb_message.cxx

package info (click to toggle)
arb 6.0.2-1
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie-kfreebsd
  • size: 65,852 kB
  • sloc: ansic: 394,903; cpp: 250,252; makefile: 19,635; sh: 15,878; perl: 10,461; fortran: 6,019; ruby: 683; xml: 503; python: 53; awk: 32
file content (45 lines) | stat: -rw-r--r-- 1,729 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// =============================================================== //
//                                                                 //
//   File      : arb_message.cxx                                   //
//   Purpose   : raise aw_message from external scripts            //
//                                                                 //
//   Coded by Ralf Westram (coder@reallysoft.de) in November 2003  //
//   Institute of Microbiology (Technical University Munich)       //
//   http://www.arb-home.de/                                       //
//                                                                 //
// =============================================================== //

#include <arbdbt.h>

int ARB_main(int argc, char *argv[]) {
    if (argc == 1) {
        fprintf(stderr, "Usage: arb_message \"the message\"\n");
        return EXIT_FAILURE;
    }

    const char *progname = argv[0];
    if (!progname || progname[0] == 0) progname = "arb_message";

    char   *the_message  = strdup(argv[1]);
    size_t  len          = strlen(the_message);
    char   *unencoded_lf = 0;
    while ((unencoded_lf = strstr(the_message, "\\n")) != 0) {
        unencoded_lf[0] = '\n';
        size_t restlen  = len-(unencoded_lf-the_message)-1; // len - "chars before \n" - "\n"
        memmove(unencoded_lf+1, unencoded_lf+2, restlen+1); // copy restlen plus 0-terminator
    }

    {
        GB_shell shell;
        GBDATA *gb_main = GB_open(":", "r");
        if (!gb_main) {
            fprintf(stderr, "%s: %s\n", progname, the_message);
        }
        else {
            GBT_message(gb_main, the_message);
            GB_close(gb_main);
        }
    }
    free(the_message);
    return EXIT_SUCCESS;
}