summaryrefslogtreecommitdiff
path: root/2003
diff options
context:
space:
mode:
Diffstat (limited to '2003')
-rw-r--r--2003/i/buspctl/AUTHORS0
-rw-r--r--2003/i/buspctl/ChangeLog0
-rw-r--r--2003/i/buspctl/Makefile.am1
-rw-r--r--2003/i/buspctl/NEWS0
-rw-r--r--2003/i/buspctl/README1
-rw-r--r--2003/i/buspctl/acinclude.m446
-rwxr-xr-x2003/i/buspctl/autogen.sh3
-rw-r--r--2003/i/buspctl/configure.ac25
-rw-r--r--2003/i/buspctl/src/Makefile.am5
-rw-r--r--2003/i/buspctl/src/grammar.y33
-rw-r--r--2003/i/buspctl/src/lexer.l47
-rw-r--r--2003/i/buspctl/src/main.c108
-rw-r--r--2003/i/buspctl/src/serial.c74
-rw-r--r--2003/i/buspctl/src/serial.h47
14 files changed, 390 insertions, 0 deletions
diff --git a/2003/i/buspctl/AUTHORS b/2003/i/buspctl/AUTHORS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/2003/i/buspctl/AUTHORS
diff --git a/2003/i/buspctl/ChangeLog b/2003/i/buspctl/ChangeLog
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/2003/i/buspctl/ChangeLog
diff --git a/2003/i/buspctl/Makefile.am b/2003/i/buspctl/Makefile.am
new file mode 100644
index 0000000..af437a6
--- /dev/null
+++ b/2003/i/buspctl/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = src
diff --git a/2003/i/buspctl/NEWS b/2003/i/buspctl/NEWS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/2003/i/buspctl/NEWS
diff --git a/2003/i/buspctl/README b/2003/i/buspctl/README
new file mode 100644
index 0000000..3b65e2e
--- /dev/null
+++ b/2003/i/buspctl/README
@@ -0,0 +1 @@
+buspctl - controleur de bus parallèle de test sur le port série.
diff --git a/2003/i/buspctl/acinclude.m4 b/2003/i/buspctl/acinclude.m4
new file mode 100644
index 0000000..2327b3f
--- /dev/null
+++ b/2003/i/buspctl/acinclude.m4
@@ -0,0 +1,46 @@
+dnl Available from the GNU Autoconf Macro Archive at:
+dnl http://www.gnu.org/software/ac-archive/htmldoc/vl_lib_readline.html
+dnl
+AC_DEFUN([VL_LIB_READLINE], [
+ AC_CACHE_CHECK([for a readline compatible library],
+ vl_cv_lib_readline, [
+ ORIG_LIBS="$LIBS"
+ for readline_lib in readline edit editline; do
+ for termcap_lib in "" termcap curses ncurses; do
+ if test -z "$termcap_lib"; then
+ TRY_LIB="-l$readline_lib"
+ else
+ TRY_LIB="-l$readline_lib -l$termcap_lib"
+ fi
+ LIBS="$ORIG_LIBS $TRY_LIB"
+ AC_TRY_LINK_FUNC(readline, vl_cv_lib_readline="$TRY_LIB")
+ if test -n "$vl_cv_lib_readline"; then
+ break
+ fi
+ done
+ if test -n "$vl_cv_lib_readline"; then
+ break
+ fi
+ done
+ if test -z "$vl_cv_lib_readline"; then
+ vl_cv_lib_readline="no"
+ LIBS="$ORIG_LIBS"
+ fi
+ ])
+
+ if test "$vl_cv_lib_readline" != "no"; then
+ AC_DEFINE(HAVE_LIBREADLINE, 1,
+ [Define if you have a readline compatible library])
+ AC_CHECK_HEADERS(readline.h readline/readline.h)
+ AC_CACHE_CHECK([whether readline supports history],
+ vl_cv_lib_readline_history, [
+ vl_cv_lib_readline_history="no"
+ AC_TRY_LINK_FUNC(add_history, vl_cv_lib_readline_history="yes")
+ ])
+ if test "$vl_cv_lib_readline_history" = "yes"; then
+ AC_DEFINE(HAVE_READLINE_HISTORY, 1,
+ [Define if your readline library has \`add_history'])
+ AC_CHECK_HEADERS(history.h readline/history.h)
+ fi
+ fi
+])
diff --git a/2003/i/buspctl/autogen.sh b/2003/i/buspctl/autogen.sh
new file mode 100755
index 0000000..2ca291f
--- /dev/null
+++ b/2003/i/buspctl/autogen.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+aclocal && autoheader && autoconf && automake -a && ./configure
diff --git a/2003/i/buspctl/configure.ac b/2003/i/buspctl/configure.ac
new file mode 100644
index 0000000..d4c76eb
--- /dev/null
+++ b/2003/i/buspctl/configure.ac
@@ -0,0 +1,25 @@
+AC_INIT(buspctl, 0.1.0)
+AC_CONFIG_AUX_DIR(auxdir)
+
+AC_CONFIG_SRCDIR(src/lexer.l)
+AM_INIT_AUTOMAKE
+
+AC_PROG_CC
+AM_PROG_LEX
+if test "$LEX" != flex; then
+ LEX="$SHELL $missing_dir/missing flex"
+ AC_SUBST(LEX_OUTPUT_ROOT, lex.yy)
+ AC_SUBST(LEXLIB, '')
+fi
+AC_PROG_MAKE_SET
+AC_PROG_YACC
+
+AC_HEADER_STDC
+
+AC_C_CONST
+
+VL_LIB_READLINE
+
+AC_CONFIG_FILES(Makefile src/Makefile)
+AM_CONFIG_HEADER(config.h)
+AC_OUTPUT
diff --git a/2003/i/buspctl/src/Makefile.am b/2003/i/buspctl/src/Makefile.am
new file mode 100644
index 0000000..87380bc
--- /dev/null
+++ b/2003/i/buspctl/src/Makefile.am
@@ -0,0 +1,5 @@
+bin_PROGRAMS = buspctl
+
+CFLAGS = -Wall -O2 -g
+
+buspctl_SOURCES = lexer.l grammar.y main.c serial.c
diff --git a/2003/i/buspctl/src/grammar.y b/2003/i/buspctl/src/grammar.y
new file mode 100644
index 0000000..0128947
--- /dev/null
+++ b/2003/i/buspctl/src/grammar.y
@@ -0,0 +1,33 @@
+%{
+#include <serial.h>
+
+#include <stdio.h>
+
+void
+yyerror (const char *s);
+
+int
+yylex (void);
+
+%}
+
+%defines
+
+%token NUM WRITE READ ERR
+
+%%
+
+input: READ NUM { printf ("read %d = %d\n", $2, serial_busp_read ($2)); }
+ | WRITE NUM NUM {
+ printf ("write %d %d\n", $2, $3);
+ serial_busp_write ($2, $3);
+ }
+;
+
+%%
+
+void
+yyerror (const char *s)
+{
+ fprintf (stderr, "buspctl: %s\n", s);
+}
diff --git a/2003/i/buspctl/src/lexer.l b/2003/i/buspctl/src/lexer.l
new file mode 100644
index 0000000..b4498ad
--- /dev/null
+++ b/2003/i/buspctl/src/lexer.l
@@ -0,0 +1,47 @@
+%{
+#include <grammar.h>
+
+int yyparse (void);
+
+%}
+
+WRITE w|write
+READ r|read
+
+DEC [0-9]+
+HEX 0x[0-9a-fA-F]+
+BIN 0b[01]+
+
+%option noyywrap nounput
+
+%%
+
+{WRITE} {
+ return WRITE;
+}
+
+{READ} {
+ return READ;
+}
+
+{DEC}|{HEX} {
+ yylval = strtol (yytext, 0, 0);
+ return NUM;
+}
+
+{BIN} {
+ yylval = strtol (yytext + 2, 0, 2);
+ return NUM;
+}
+
+[ \t\n]+ /* Rien à battre. */
+
+. return ERR;
+
+%%
+
+int parse_string (const char *s)
+{
+ yy_scan_string (s);
+ return yyparse ();
+}
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 */
+}
diff --git a/2003/i/buspctl/src/serial.c b/2003/i/buspctl/src/serial.c
new file mode 100644
index 0000000..13eb844
--- /dev/null
+++ b/2003/i/buspctl/src/serial.c
@@ -0,0 +1,74 @@
+/* serial.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>
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+/* +AutoDec */
+/* -AutoDec */
+
+/* Les variables globales, c'est mal. */
+static int serial_busp_fd = -1;
+
+/* Ouvre le port série. */
+int
+serial_busp_init (const char *file)
+{
+ serial_busp_fd = open (file, O_RDONLY);
+ return serial_busp_fd;
+}
+
+/* Ferme le port série. */
+void
+serial_busp_uninit (void)
+{
+ close (serial_busp_fd);
+}
+
+/* Ecrit un octet. */
+void
+serial_busp_write (int addr, int data)
+{
+ unsigned char c;
+ c = addr & 0x0f;
+ write (serial_busp_fd, &c, 1);
+ c = data;
+ write (serial_busp_fd, &c, 1);
+}
+
+/* Lit un octet. */
+int
+serial_busp_read (int addr)
+{
+ unsigned char c, c2;
+ c = (addr & 0x0f) | 0x10;
+ write (serial_busp_fd, &c, 1);
+ read (serial_busp_fd, &c2, 1);
+ // if (c != c2) ...
+ read (serial_busp_fd, &c, 1);
+ return c;
+}
diff --git a/2003/i/buspctl/src/serial.h b/2003/i/buspctl/src/serial.h
new file mode 100644
index 0000000..6727625
--- /dev/null
+++ b/2003/i/buspctl/src/serial.h
@@ -0,0 +1,47 @@
+#ifndef serial_h
+#define serial_h
+/* serial.h */
+/* {{{
+ *
+ * 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>
+ * }}} */
+
+/* +AutoDec */
+
+/* Ouvre le port série. */
+int
+serial_busp_init (const char *file);
+
+/* Ferme le port série. */
+void
+serial_busp_uninit (void);
+
+/* Ecrit un octet. */
+void
+serial_busp_write (int addr, int data);
+
+/* Lit un octet. */
+int
+serial_busp_read (int addr);
+
+/* -AutoDec */
+
+#endif /* serial_h */