aboutsummaryrefslogtreecommitdiffstats
path: root/com32/modules/fancyhello.c
blob: 5cfc064f843e373f437ae0d09626f5159226c3c6 (plain)
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
#ident "$Id$"
/* ----------------------------------------------------------------------- *
 *   
 *   Copyright 2004 H. Peter Anvin - All Rights Reserved
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
 *   Bostom MA 02111-1307, USA; either version 2 of the License, or
 *   (at your option) any later version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

/*
 * fancyhello.c
 *
 * Hello, World! using libcom32 and ANSI console; also possible to compile
 * as a Linux application for testing.
 */

#include <string.h>
#include <stdio.h>

#ifdef __COM32__

#include <console.h>

static void console_init(void)
{
  /* Write both to the ANSI console and the serial port, if configured */
  openconsole(&dev_stdcon_r, &dev_ansiserial_w);
}  

#else

#include <termios.h>
#include <unistd.h>

static void console_init(void)
{
  struct termios tio;

  /* Set the termios flag so we behave the same as libcom32 */
  tcgetattr(0, &tio);
  tio.c_iflag &= ~ICRNL;
  tio.c_iflag |= IGNCR;
  tcsetattr(0, TCSANOW, &tio);
}  

#endif

int main(void)
{
  char buffer[1024];

  console_init();
  printf("\033[20h");		/* Automatically convert \r\n -> \n */

  printf("\033[1;33;44m *** \033[37mHello, World!\033[33m *** \033[0m\n");

  for (;;) {
    printf("\033[1;36m>\033[0m ");
    fgets(buffer, sizeof buffer, stdin);
    if ( !strncmp(buffer, "exit", 4) )
      break;
    printf("\033[1m:\033[0m %s", buffer);
  }
  return 0;
}