test
Revision | 1bf2d0f6e091694ff8da0346f06bdd5c7b3953a3 (tree) |
---|---|
Zeit | 2009-08-24 19:38:43 |
Autor | TATEISHI Katsuyuki <kt@whee...> |
Commiter | TATEISHI Katsuyuki |
Add new library subr.
Makefile.am configure.ac: Add lib entry.
lib/: Add new library.
hello.c: Modify to use library function.
@@ -1 +1 @@ | ||
1 | -SUBDIRS = src | |
1 | +SUBDIRS = lib src |
@@ -9,12 +9,17 @@ AM_INIT_AUTOMAKE(foreign) | ||
9 | 9 | |
10 | 10 | # Checks for programs. |
11 | 11 | AC_PROG_CC |
12 | +AC_PROG_LIBTOOL | |
13 | +AC_PROG_INSTALL | |
14 | +AC_PROG_LN_S | |
15 | +AC_PROG_MAKE_SET | |
16 | +AC_PROG_RANLIB | |
12 | 17 | |
13 | 18 | # Checks for libraries. |
14 | 19 | |
15 | 20 | # Checks for header files. |
16 | 21 | AC_HEADER_STDC |
17 | -AC_CHECK_HEADERS([stdlib.h]) | |
22 | +AC_CHECK_HEADERS([stdlib.h string.h unistd.h]) | |
18 | 23 | |
19 | 24 | # Checks for typedefs, structures, and compiler characteristics. |
20 | 25 | AC_STRUCT_TM |
@@ -22,6 +27,10 @@ AC_STRUCT_TM | ||
22 | 27 | # Checks for library functions. |
23 | 28 | AC_FUNC_STRFTIME |
24 | 29 | |
30 | +AC_CHECK_FUNCS([strrchr], | |
31 | + [setprogname]) | |
32 | + | |
25 | 33 | AC_CONFIG_FILES([Makefile |
34 | + lib/Makefile | |
26 | 35 | src/Makefile]) |
27 | 36 | AC_OUTPUT |
@@ -0,0 +1,3 @@ | ||
1 | +noinst_LIBRARIES = libsubr.a | |
2 | + | |
3 | +libsubr_a_SOURCES = setprogname.c |
@@ -0,0 +1,27 @@ | ||
1 | +#include <string.h> | |
2 | + | |
3 | +#include <subr.h> | |
4 | + | |
5 | +#ifndef HAVE_SETPROGNAME | |
6 | +static const char *prog = NULL; | |
7 | + | |
8 | +void | |
9 | +setprogname(const char *progname) | |
10 | +{ | |
11 | + char *p; | |
12 | + | |
13 | + p = strrchr(progname, '/'); | |
14 | + | |
15 | + if (p) { | |
16 | + prog = p + 1; | |
17 | + } else { | |
18 | + prog = progname; | |
19 | + } | |
20 | +} | |
21 | + | |
22 | +const char * | |
23 | +getprogname(void) | |
24 | +{ | |
25 | + return prog; | |
26 | +} | |
27 | +#endif |
@@ -0,0 +1,15 @@ | ||
1 | +#ifndef SUBR_H | |
2 | +#define SUBR_H | |
3 | + | |
4 | +#include <stdlib.h> | |
5 | +#include <config.h> | |
6 | + | |
7 | +#ifndef HAVE_SETPROGNAME | |
8 | +void | |
9 | +setprogname(const char *progname); | |
10 | + | |
11 | +const char * | |
12 | +getprogname(void); | |
13 | +#endif /* HAVE_SETPROGNAME */ | |
14 | + | |
15 | +#endif /* SUBR_H */ |
@@ -1,3 +1,6 @@ | ||
1 | +INCLUDES = -I$(top_srcdir)/lib | |
2 | +LDADD = $(top_builddir)/lib/libsubr.a | |
3 | + | |
1 | 4 | bin_PROGRAMS = hello localtime |
2 | 5 | |
3 | 6 | hello_SOURCES = hello.c |
@@ -1,16 +1,19 @@ | ||
1 | 1 | #include <stdio.h> |
2 | 2 | #include <unistd.h> |
3 | 3 | |
4 | +#include <subr.h> | |
4 | 5 | #include <config.h> |
5 | 6 | |
6 | 7 | int main(int argc, char **argv) |
7 | 8 | { |
8 | 9 | char ch; |
9 | 10 | |
11 | + setprogname(argv[0]); | |
12 | + | |
10 | 13 | while ((ch = getopt(argc, argv, "v")) != -1) { |
11 | 14 | switch (ch) { |
12 | 15 | case 'v': |
13 | - printf("%s (%s) %s\n", argv[0], PACKAGE_NAME, PACKAGE_VERSION); | |
16 | + printf("%s (%s) %s\n", getprogname(), PACKAGE_NAME, PACKAGE_VERSION); | |
14 | 17 | return 0; |
15 | 18 | break; |
16 | 19 | default: |