summaryrefslogtreecommitdiff
path: root/2003/i/buspctl/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to '2003/i/buspctl/src/main.c')
-rw-r--r--2003/i/buspctl/src/main.c108
1 files changed, 108 insertions, 0 deletions
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: <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 */
+}