Commit 098b1537 authored by Seblu's avatar Seblu
Browse files

Debut de dev de slc

Creation des fichiers de base
Parser d'option
parent 056973ed
Loading
Loading
Loading
Loading

slc/trunk/Makefile.am

0 → 100644
+14 −0
Original line number Diff line number Diff line
bin_PROGRAMS=	slc

slc_SOURCES=	src/slc.hh		\
		src/slc.cc		\
		src/options.cc		\
		src/options.hh

CLEANFILES= *~ '\#*' .*.swp .*~

.PHONY: tar re

tar: distcheck

re: clean all

slc/trunk/bootstrap

0 → 100755
+21 −0
Original line number Diff line number Diff line
#!/bin/sh
## bootstrap for 42sh in /home/seblu/devel/c/42sh
##
## Made by Seblu
## Login   <seblu@epita.fr>
##
## Started on  Sun Jul 16 19:43:53 2006 Seblu
## Last update Sun Jul 16 19:44:01 2006 Seblu
##

# Failures do matter.
set -e

# See what i'am doing
set -x

# install the GNU Build System.
autoreconf -i -f -v

# FIXME: autoheader does not obey --force.
find . -name 'config.h.in' | xargs touch
 No newline at end of file

slc/trunk/configure.ac

0 → 100644
+89 −0
Original line number Diff line number Diff line
# Require a recent version of autotools
AC_PREREQ(2.59)

# Auto conf init
AC_INIT([slc],[1.0],[seblu@seblu.net],[slc])

# Define configure generator directory
AC_CONFIG_AUX_DIR([build])

# Auto Make init
AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip])

# Check platform
AC_CANONICAL_HOST

CXXFLAGS='-Wall -W -ansi -pedantic -D_XOPEN_SOURCE=600'

# Check for C++ compiler
AC_LANG([C++])
AC_PROG_CXX

# Check for Make
AC_PROG_MAKE_SET

# check for ranlib
AC_PROG_RANLIB

# Check for lib efence
AC_CHECK_LIB([efence], [malloc], [EFENCELIB=-lefence])
AC_SUBST([EFENCELIB])

# Checks for library functions.

# Checks for typedefs, structures, and compiler characteristics.

# Check for headers

dnl Memo:
dnl AC ARG WITH(package, help-string, [action-if-given], [action-if-not-given])


AC_ARG_WITH([noerror],
  [AS_HELP_STRING([--with-noerror], [Warning dont create compilation error])],
  [dnl action-if-given
       true
  ],
  [dnl action-if-not-given
       CXXFLAGS="$CXXFLAGS -Werror"
  ]
)

AC_ARG_WITH([debug],
  [AS_HELP_STRING([--with-debug], [use -g and don't use -DNDEBUG -O3])],
  [dnl action-if-given
       CXXFLAGS="$CXXFLAGS -g"
  ],
  [dnl action-if-not-given
      CXXFLAGS="$CXXFLAGS -DNDEBUG -O3"
  ]
)

AC_ARG_WITH([efence],
  [AS_HELP_STRING([--with-efence], [link with lib efence])],
  [dnl action-if-given
       LDFLAGS="$LDFLAGS -lefence"
       #test -r "/usr/include/efencepp.h" &&
       #CXXFLAGS="$CXXFLAGS -include efencepp.h"
  ],
  [dnl action-if-not-given
       true
  ]
)

LDFLAGS="$LDFLAGS -lssl -lncurses"

AC_SUBST([CXXFLAGS])
AC_SUBST([LDFLAGS])

AC_HEADER_STDC

AC_CONFIG_HEADERS([config.h])
AC_CHECK_HEADERS([stdlib.h])

# define Autoconf config files
AC_CONFIG_FILES([
	Makefile
])

AC_OUTPUT
+65 −0
Original line number Diff line number Diff line
#include "slc.hh"
#include "options.hh"

#include <getopt.h>

Options::Options() {
  port = 18136;
}

void Options::usage(const char *name, ostream &out) const {
  out << "usage: " << name
      << " [-h|--help] [-l|--login name] [-v|--verbose] server [port]" << std::endl;
  out << "-h | --help        : Print this help." << std::endl;
  out << "-l | --login name  : Define login to name." << std::endl;
}

Options &Options::load(int argc, char *argv[]) {
  struct option lopt[] = {
    {"help", 0, 0, 'h'},
    {"login", 0, 0, 'l'},
    {0, 0, 0, 0},
  };
  int option;

  while ((option = getopt_long(argc, argv, "hl:", lopt, 0)) != -1) {
    switch (option) {
    case 'h':
      usage(*argv, std::cout);
      break;
    case 'l':
      printf("login %s\n", optarg);
      login = optarg;
      break;
    case '?':
      usage(*argv, std::cerr);
      exit(ERR_USAGE);
    }
  }

  if (argv[optind] == 0) {
    usage(*argv, std::cerr);
    exit(ERR_USAGE);
  }

  server = argv[optind++];

  if (argv[optind] != 0) {
    port = atoi(argv[optind++]);
  }

  if (argv[optind] != 0) {
    usage(*argv, std::cerr);
    exit(ERR_USAGE);
  }

  return *this;
}

ostream &operator<< (ostream &s, const Options &o) {
  return s << "server: " << o.server << std::endl
	   << "port: " << o.port << std::endl
	   << "host login: " << o.login << std::endl
	   << "host pass: " << o.pass << std::endl;
}
+19 −0
Original line number Diff line number Diff line
#ifndef OPTIONS_HH
# define OPTIONS_HH

struct Options {
  Options();

  Options &load(int argc, char *argv[]);
  void usage(const char *name, ostream &out) const;

  friend ostream &operator<<(ostream &, const Options &);


  string server;
  int port; //-1 undef
  string login;
  string pass;
};

#endif
Loading