Skip to content

Commit

Permalink
move cmdl_test() to libsim/sim_test.c
Browse files Browse the repository at this point in the history
fix Makefile
  • Loading branch information
gitgjogh committed Feb 2, 2017
1 parent e1a5e42 commit 500d20d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CFLAGS = -c -O3
LIBS = -lm

TMPDIR = mk.tmp
BINSRCS = ztest.c
BINSRCS = ztest.c
BINOBJS = $(BINSRCS:%.c=$(TMPDIR)/%.o)
OUTBIN = ztest

Expand All @@ -32,7 +32,7 @@ $(OUTBIN): $(BINOBJS) $(LIBSIM) $(LIBZBASE) | libzbase
$(BINOBJS): $(LIBZBASE) Makefile
$(BINOBJS): $(TMPDIR)/%.o:%.c | $(TMPDIR)
@echo; echo "[CC] compiling: $< "
$(CC) $(CFLAGS) -I$(LIBSIMDIRS) -I$(LIBZBASEDIRS) -l$(LIBSIM) -l$(LIBZBASE) -o $@ $<
$(CC) $(CFLAGS) -I$(LIBSIMDIRS) -I$(LIBZBASEDIRS) -o $@ $<

.PHONY: libzbase
libzbase $(LIBZBASE):
Expand Down
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ For example, to allow users to specified the name/color/age for a pet, the devel
{ 0, "age", 1, cmdl_parse_int, PET_OPT_M(age), "0", "pet's age", },
};

Link the code to `libsim` and then you will got a program like this:

> $ ./a.exe -h
>
-h,help , show help
-name <%s>, pet's name
-color <%d>, [0], pet's color
-age <%d>, [0], pet's age
>
> $ ./a.exe -name tom -color 2 -age 3
>
-h,help =
-name = 'tom'
-color = '2'
-age = '3'

The full sample is in `libsim/sim_test.c`. Built it like this:

> cd libsim
> make #make libsim.a
Link the code to `libsim` and then you will got a program like this:

> $ ./a.exe -h
>
-h,help , show help
-name <%s>, pet's name
-color <%d>, [0], pet's color
-age <%d>, [0], pet's age
>
> $ ./a.exe -name tom -color 2 -age 3
>
-h,help =
-name = 'tom'
-color = '2'
-age = '3'

The full sample is in `libsim/sim_test.c`. Built it like this:

> cd libsim
> make #make libsim.a
> cc sim_test.c -o a.exe -L./ -lsim
6 changes: 6 additions & 0 deletions libsim/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ $(LIBSIMOBJS): $(TMPDIR)/%.o:%.c | $(TMPDIR)

$(TMPDIR):
mkdir -p $@

.PHONY: test
test: sim_test
sim_test: sim_test.c $(LIBSIM)
@echo; echo "[CC] sim_test.c"
$(CC) -D _SIM_TEST_ -o $@ $^
8 changes: 8 additions & 0 deletions libsim/sim_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ int cmdl_test(int argc, char **argv)

return 0;
}

#ifdef _SIM_TEST_
int main(int argc, char **argv)
{
xlog_init(SLOG_DEFULT);
return cmdl_test(argc, argv);
}
#endif
3 changes: 0 additions & 3 deletions ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ int main(int argc, char **argv)
{
int i=0, j = 0;
int exit_code = 0;
int cmdl_test(int argc, char **argv);

typedef struct yuv_module {
const char *name;
Expand All @@ -351,8 +350,6 @@ int main(int argc, char **argv)

const static yuv_module_t sub_main[] = {
{"list", zlist_test, ""},
//{"opt", zopt_test, ""},
{"cmdl", cmdl_test, ""},
{"array", zarray_test, ""},
{"strq", zstrq_test, ""},
{"hash", zhash_test, ""},
Expand Down

0 comments on commit 500d20d

Please sign in to comment.