summaryrefslogtreecommitdiff
path: root/2003/i/buspctl/src/main.c
blob: fa53a36cc636ba6d67229af6ffb1fc9be3cfe5ee (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
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
/* main.c */
/*  {{{
 *
 * Copyright (C) 2003 Nicolas Schodet
 *
 * 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; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Contact :
 *        Web: http://perso.efrei.fr/~schodet/
 *      Email: <contact@ni.fr.eu.org>
 * }}} */
#include <serial.h>

/* Libreadline adaptation. {{{ */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#ifdef HAVE_LIBREADLINE
#  if defined(HAVE_READLINE_READLINE_H)
#    include <readline/readline.h>
#  elif defined(HAVE_READLINE_H)
#    include <readline.h>
#  else /* !defined(HAVE_READLINE_H) */
extern char *readline ();
#  endif /* !defined(HAVE_READLINE_H) */
char *cmdline = NULL;
#else /* !defined(HAVE_READLINE_READLINE_H) */
  /* no readline */
#endif /* HAVE_LIBREADLINE */

#ifdef HAVE_READLINE_HISTORY
#  if defined(HAVE_READLINE_HISTORY_H)
#    include <readline/history.h>
#  elif defined(HAVE_HISTORY_H)
#    include <history.h>
#  else /* !defined(HAVE_HISTORY_H) */
extern void add_history ();
extern int write_history ();
extern int read_history ();
#  endif /* defined(HAVE_READLINE_HISTORY_H) */
  /* no history */
#endif /* HAVE_READLINE_HISTORY */
/* }}} */
#include <stdio.h>

int parse_string (const char *s);

/* +AutoDec */

/* Lit une cha�ne de l'utilsateur. */
static const char *
get_user_line (void);

/* -AutoDec */

int
 main (int argc, char **argv)
{
    const char *s;
    int i;
    serial_busp_init ("/dev/ttyS0");
    if (argc == 1)
      {
#ifdef HAVE_LIBREADLINE
	rl_bind_key ('\t', rl_insert);
#endif
	while ((s = get_user_line ()))
	    parse_string (s);
      }
    else
	for (i = 1; i < argc; ++i)
	  {
	    parse_string (argv[i]);
	  }
    serial_busp_uninit ();
    return 0;
}

/* Lit une cha�ne de l'utilsateur. */
static const char *
get_user_line (void)
{
#ifdef HAVE_LIBREADLINE
    static char *buf = 0;
    if (buf) free (buf);
    buf = readline ("> ");
# ifdef HAVE_READLINE_HISTORY
    if (buf && *buf) add_history (buf);
# endif /* HAVE_READLINE_HISTORY */
    return buf;
#else /* ! HAVE_LIBREADLINE */
    char buf[2048];
    return fgets (buf, 2048, stdin);
#endif /* ! HAVE_LIBREADLINE */
}