• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

test


Commit MetaInfo

Revision1bf2d0f6e091694ff8da0346f06bdd5c7b3953a3 (tree)
Zeit2009-08-24 19:38:43
AutorTATEISHI Katsuyuki <kt@whee...>
CommiterTATEISHI Katsuyuki

Log Message

Add new library subr.

Makefile.am configure.ac: Add lib entry.
lib/: Add new library.
hello.c: Modify to use library function.

Ändern Zusammenfassung

Diff

--- a/Makefile.am
+++ b/Makefile.am
@@ -1 +1 @@
1-SUBDIRS = src
1+SUBDIRS = lib src
--- a/configure.ac
+++ b/configure.ac
@@ -9,12 +9,17 @@ AM_INIT_AUTOMAKE(foreign)
99
1010 # Checks for programs.
1111 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
1217
1318 # Checks for libraries.
1419
1520 # Checks for header files.
1621 AC_HEADER_STDC
17-AC_CHECK_HEADERS([stdlib.h])
22+AC_CHECK_HEADERS([stdlib.h string.h unistd.h])
1823
1924 # Checks for typedefs, structures, and compiler characteristics.
2025 AC_STRUCT_TM
@@ -22,6 +27,10 @@ AC_STRUCT_TM
2227 # Checks for library functions.
2328 AC_FUNC_STRFTIME
2429
30+AC_CHECK_FUNCS([strrchr],
31+ [setprogname])
32+
2533 AC_CONFIG_FILES([Makefile
34+ lib/Makefile
2635 src/Makefile])
2736 AC_OUTPUT
--- /dev/null
+++ b/lib/Makefile.am
@@ -0,0 +1,3 @@
1+noinst_LIBRARIES = libsubr.a
2+
3+libsubr_a_SOURCES = setprogname.c
--- /dev/null
+++ b/lib/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
--- /dev/null
+++ b/lib/subr.h
@@ -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 */
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,3 +1,6 @@
1+INCLUDES = -I$(top_srcdir)/lib
2+LDADD = $(top_builddir)/lib/libsubr.a
3+
14 bin_PROGRAMS = hello localtime
25
36 hello_SOURCES = hello.c
--- a/src/hello.c
+++ b/src/hello.c
@@ -1,16 +1,19 @@
11 #include <stdio.h>
22 #include <unistd.h>
33
4+#include <subr.h>
45 #include <config.h>
56
67 int main(int argc, char **argv)
78 {
89 char ch;
910
11+ setprogname(argv[0]);
12+
1013 while ((ch = getopt(argc, argv, "v")) != -1) {
1114 switch (ch) {
1215 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);
1417 return 0;
1518 break;
1619 default: