/* 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 */ }