From 55ef0ba343a4865cd927aee38a316f5e2a07aaf7 Mon Sep 17 00:00:00 2001 From: schodet Date: Mon, 31 Mar 2003 18:37:07 +0000 Subject: Initial revision --- 2003/i/buspctl/src/main.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 2003/i/buspctl/src/main.c (limited to '2003/i/buspctl/src/main.c') diff --git a/2003/i/buspctl/src/main.c b/2003/i/buspctl/src/main.c new file mode 100644 index 0000000..fa53a36 --- /dev/null +++ b/2003/i/buspctl/src/main.c @@ -0,0 +1,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: + * }}} */ +#include + +/* Libreadline adaptation. {{{ */ +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifdef HAVE_LIBREADLINE +# if defined(HAVE_READLINE_READLINE_H) +# include +# elif defined(HAVE_READLINE_H) +# include +# 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 +# elif defined(HAVE_HISTORY_H) +# include +# 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 + +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 */ +} -- cgit v1.2.3