File: logo.c

package info (click to toggle)
cgdb 0.6.7-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 3,276 kB
  • sloc: ansic: 17,828; sh: 5,176; exp: 1,019; lex: 611; makefile: 287; yacc: 255; cpp: 10
file content (169 lines) | stat: -rw-r--r-- 4,658 bytes parent folder | download | duplicates (5)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* logo.c
 * ------
 * Data for ASCII logos.
 *
 * These logos were generated thanks to J�rg Seyfferth and his web-based
 * ASCII-text generator:  http://www.network-science.de/ascii/
 */

#if HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */

/* System Includes */
#if HAVE_STDLIB_H 
#include <stdlib.h>
#endif  /* HAVE_STDLIB_H */

#if HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */

#if HAVE_TIME_H
#include <time.h>
#endif /* HAVE_TIME_H */

#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif /* HAVE_SYS_TIME_H */

/* Local Includes */
#include "cgdb.h"
#include "logo.h"
#include "highlight_groups.h"

/* ----------- */
/* Definitions */
/* ----------- */

#define CGDB_NUM_LOGOS 4

/* --------------- */
/* Data Structures */
/* --------------- */

struct Logo{
   int h;                  /* Height of logo */
   char *data[11];         /* Increase the array size as necessary */
};

static struct Logo CGDB_LOGO[CGDB_NUM_LOGOS] =
{
   { 6,
      { "                  .______.    ",
        "  ____   ____   __| _/\\_ |__  ",
        "_/ ___\\ / ___\\ / __ |  | __ \\ ",
        "\\  \\___/ /_/  > /_/ |  | \\_\\ \\",
        " \\___  >___  /\\____ |  |___  /",
        "     \\/_____/      \\/      \\/ "
      }
   },

   { 7,
      { "                          _|  _|      ",
        "  _|_|_|    _|_|_|    _|_|_|  _|_|_|  ",
        "_|        _|    _|  _|    _|  _|    _|",
        "_|        _|    _|  _|    _|  _|    _|",
        "  _|_|_|    _|_|_|    _|_|_|  _|_|_|  ",
        "                _|                    ",
        "            _|_|                      "
      }
   },

   { 11,
      { "============================",
        "==================  ==  ====",
        "==================  ==  ====",
        "==================  ==  ====",
        "==   ====   ======  ==  ====",
        "=  =  ==  =  ===    ==    ==",
        "=  ======    ==  =  ==  =  =",
        "=  ========  ==  =  ==  =  =",
        "=  =  ==  =  ==  =  ==  =  =",
        "==   ====   ====    ==    ==",
        "============================"
      }
   },

   { 6,
      { "_______________________________/\\/\\__/\\/\\_______",
        "___/\\/\\/\\/\\____/\\/\\/\\/\\________/\\/\\__/\\/\\_______",
        "_/\\/\\________/\\/\\__/\\/\\____/\\/\\/\\/\\__/\\/\\/\\/\\___",
        "_/\\/\\__________/\\/\\/\\/\\__/\\/\\__/\\/\\__/\\/\\__/\\/\\_",
        "___/\\/\\/\\/\\________/\\/\\____/\\/\\/\\/\\__/\\/\\/\\/\\___",
        "_____________/\\/\\/\\/\\___________________________"
      }
   }
};

static char *usage[] = {
    "type  q<Enter>            to exit      ",
    "type  help<Enter>         for GDB help ",
    "type  <ESC>:help<Enter>   for CGDB help"
};

/* --------- */
/* Functions */
/* --------- */

static void center_line(WINDOW *win, int row, int width, char *data)
{
    mvwprintw(win, row, (width - strlen(data))/2, data);
}

void logo_display(WINDOW *win)
{
    static int logo = -1;                /* Logo index */
    int height, width;                   /* Dimensions of the window */
    int line;                            /* Starting line */
    int usage_height;                    /* Height of the usage message */
    int i, j;                            /* Iterators */
    int attr;

    if (hl_groups_get_attr (hl_groups_instance, HLG_LOGO, &attr) == -1)
      return;
    
    /* Get dimensions */
    getmaxyx(win, height, width);
    usage_height = sizeof(usage)/sizeof(char *);
        
    /* Clear the window */
    wmove(win, 0, 0);
    for (i = 0; i < height; i++){
       for (j = 0; j < width; j++)
          wprintw(win, " ");
       wprintw(win, "\n");
    }  
        
    /* Display cgdb logo */
    wattron(win, attr);

    /* Pick a random logo */
    if (logo == -1){
        srand(time(NULL));
        logo = rand() % CGDB_NUM_LOGOS;
    }

    /* If the logo fits on the screen, draw it */
    if (CGDB_LOGO[logo].h <= height - usage_height - 4){
        line = (height - CGDB_LOGO[logo].h - usage_height - 4)/2;
        wmove(win, line, 0);
        for(i = 0; i < CGDB_LOGO[logo].h; i++)
            center_line(win, i+line, width, CGDB_LOGO[logo].data[i]);
        center_line(win, ++i + line, width, "a curses debugger");
    }
    else{
        line = (height - usage_height - 4)/2;
        center_line(win, line, width, "CGDB: a curses debugger");
        i = 0;
    }
    center_line(win, ++i + line, width, "version " VERSION);
    i++;
    
    /* Show simple usage info */
    for (j = 0; j < sizeof(usage)/sizeof(char *); j++)
        center_line(win, ++i + line, width, usage[j]);

    wattroff(win, attr);
    curs_set(0);         /* Hide the cursor */
}