Applying the patch of Wilson Costrino. Thank you! - acarsdec - an ACARS decoder
       
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 296701ba461bf58d529af38e0205b2ce57add536
 (DIR) parent 1d02ca9bad4722ee06db81573977907b6e564a0e
 (HTM) Author: Christoph Lohmann <20h@r-36.net>
       Date:   Wed, 29 Aug 2012 11:49:08 +0200
       
       Applying the patch of Wilson Costrino. Thank you!
       
       Diffstat:
         main.c                              |      74 +++++++++++++++++++++++--------
       
       1 file changed, 55 insertions(+), 19 deletions(-)
       ---
 (DIR) diff --git a/main.c b/main.c
       @@ -31,6 +31,20 @@
        extern int optind, opterr;
        extern char *optarg;
        
       +#define RED      "\033[0;31m"        /* 0 -> normal ;  31 -> red */
       +#define CYAN     "\033[1;36m"        /* 1 -> bold ;  36 -> cyan */
       +#define GREEN    "\033[1;32m"        /* 1 -> bold ;  32 -> green */
       +#define YELLOW   "\033[0;33m"        /* 0 -> normal ;  33 -> yellow */
       +#define BLUE     "\033[1;34m"        /* 1 -> bold ;  34 -> blue */
       +
       +#define BLACK    "\033[0;30m"
       +#define BROWN    "\033[0;33m"
       +#define MAGENTA  "\033[7;35m"        /* 7 -> inverted; 35 -> magenta */
       +#define GRAY     "\033[0;37m"
       +
       +#define NONE     "\033[0m"           /* to flush the previous property */
       +
       +
        static void usage(void)
        {
                fprintf(stderr, "%s\n", version);
       @@ -42,6 +56,7 @@ static void usage(void)
                                "input alsapcmdevice (ie: hw:0,0)\n");
                fprintf(stderr, " -t :\t\t\tread from stdin.\n");
                fprintf(stderr, " [-v] :\t\t\tbe verbose.\n");
       +        fprintf(stderr, " [-c] :\t\t\tcolorfull output.\n");
                fprintf(stderr, " [-p] :\t\t\toutput should be parseable protocol.\n");
                fprintf(stderr, " [-e] :\t\t\tdo debug?\n");
                fprintf(stderr, " [-LR] :\t\tdisable left or right channel "
       @@ -55,31 +70,47 @@ static void usage(void)
                exit(1);
        }
        
       -void print_mesg(msg_t * msg)
       +void print_mesg(msg_t * msg, int colored, int messgnumb)
        {
                time_t t;
                struct tm *tmp;
                char pos[128];
        
       -        printf("ACARS mode: %c", msg->mode);
       -        printf(" Aircraft reg: %s\n", msg->addr);
       -        printf("Message label: %s", msg->label);
       -        printf(" Block id: %d", (int) msg->bid);
       -        printf(" Msg. no: %s\n", msg->no);
       -        printf("Flight id: %s\n", msg->fid);
       -        printf("Message content:-\n%s", msg->txt);
       -
       -        if (posconv(msg->txt, msg->label, pos)==0) {
       -                printf("\nAPRS : Addr:%s Fid:%s Lbl:%s pos:%s\n",
       +        if (colored) {
       +                printf("ACARS mode: %s%c%s", RED,msg->mode,NONE);
       +                printf(" Aircraft reg: %s%s%s\n", GREEN,msg->addr,NONE);
       +                printf("Message label: %s%s%s", CYAN,msg->label,NONE);
       +                printf(" Block id: %s%d%s", RED,(int) msg->bid,NONE);
       +                printf(" Msg. no: %s%s%s\n", BLUE,msg->no,NONE);
       +                printf("Flight id: %s%s%s\n", MAGENTA,msg->fid,NONE);
       +                printf("Message content:-\n%s%s%s", YELLOW,msg->txt,NONE);
       +                if (posconv(msg->txt, msg->label, pos)==0) {
       +                        printf("\n%sAPRS : Addr:%s Fid:%s Lbl:%s pos:%s%s\n",
       +                                RED,msg->addr, msg->fid, msg->label, pos,NONE);
       +                }
       +        } else {
       +                printf("ACARS mode: %c", msg->mode);
       +                printf(" Aircraft reg: %s\n", msg->addr);
       +                printf("Message label: %s", msg->label);
       +                printf(" Block id: %d", (int) msg->bid);
       +                printf(" Msg. no: %s\n", msg->no);
       +                printf("Flight id: %s\n", msg->fid);
       +                printf("Message content:-\n%s", msg->txt);
       +                if (posconv(msg->txt, msg->label, pos)==0) {
       +                        printf("\nAPRS : Addr:%s Fid:%s Lbl:%s pos:%s\n",
                                        msg->addr, msg->fid, msg->label, pos);
       +                }
                }
        
       +
       +
                t = time(NULL);
                tmp = gmtime(&t);
       -        printf("\n--------------------------------------------"
       -                        "--------------[%02d/%02d/%04d %02d:%02d]\n\n",
       -             tmp->tm_mday, tmp->tm_mon + 1, tmp->tm_year + 1900,
       -             tmp->tm_hour, tmp->tm_min);
       +        printf("\n[%5d]-------------------------------------"
       +                "--------------[%02d/%02d/%04d %02d:%02d:%02d]\n\n",
       +                messgnumb,
       +                tmp->tm_mday, tmp->tm_mon + 1, tmp->tm_year + 1900,
       +                tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
                fflush(stdout);
        }
        
       @@ -113,13 +144,13 @@ void print_proto(msg_t * msg)
                fflush(stdout);
        }
        
       -void do_output(int type, msg_t *msg)
       +void do_output(int type, msg_t *msg, int colored, int messgnumb)
        {
        
                if(type & OUT_NET)
                        send_mesg(msg);
                if(type & OUT_PRINT)
       -                print_mesg(msg);
       +                print_mesg(msg,colored,messgnumb);
                if(type & OUT_PROTO)
                        print_proto(msg);
        }
       @@ -137,8 +168,10 @@ int main(int argc, char **argv)
                int debug=0;
                int output = 0;
                int i;
       +        int colored = 0;
       +        int messgnumb = 0;
        
       -        while ((c = getopt(argc, argv, "ptevd:f:RLs:")) != EOF) {
       +        while ((c = getopt(argc, argv, "cptevd:f:RLs:")) != EOF) {
                        switch (c) {
                        case 'd':
                                nbch = initsample(optarg, IN_ALSA);
       @@ -168,6 +201,9 @@ int main(int argc, char **argv)
                        case 'e':
                                debug++;
                                break;
       +                case 'c':
       +                        colored = 1;
       +                        break;
                        default:
                                usage();
                                exit(1);
       @@ -219,7 +255,7 @@ int main(int argc, char **argv)
                                                        nbit[i] = 0;
                                                        if (nrbit[i] == 0) {
                                                                do_output(output,
       -                                                                &msg[i]);
       +                                                                &msg[i], colored, ++messgnumb);
                                                                nrbit[i] = 8;
                                                        }
                                                }