From 77c28f2a982d2b235dff6c05a1631ee4c333e5bd Mon Sep 17 00:00:00 2001 From: Tony Bai Date: Tue, 2 Apr 2013 13:19:15 +0800 Subject: [PATCH] migrate to github 2013-04-02 --- astyle_scripts/astylerc | 17 ++ cdefer/examples/Makefile | 3 + cdefer/examples/main.c | 27 +++ cdefer/lib/Makefile | 5 + cdefer/lib/defer.c | 68 +++++++ cdefer/lib/defer.h | 34 ++++ cdefer/lib/funcexit.c | 38 ++++ cdefer/lib/libcdefer.so | Bin 0 -> 10165 bytes func_trace/Makefile | 24 +++ func_trace/example.c | 20 ++ func_trace/func_trace.c | 72 ++++++++ py-simulators/AUTHORS | 4 + py-simulators/ChangeLog | 5 + py-simulators/LICENSE | 13 ++ py-simulators/README | 0 py-simulators/core/__init__.py | 0 py-simulators/core/reactor/__init__.py | 0 py-simulators/core/reactor/event.py | 27 +++ py-simulators/core/reactor/reactor.py | 23 +++ py-simulators/core/reactor/source.py | 32 ++++ py-simulators/py-config-admin | 10 + py-simulators/py-sp | 7 + py-simulators/setup.py | 3 + py-simulators/test/__init__.py | 0 py-simulators/utils/__init__.py | 0 shell_scripts/source-counter | 68 +++++++ style_check_scripts/c_style_check.py | 165 +++++++++++++++++ style_check_scripts/clint.py | 53 ++++++ style_check_scripts/clint_unittest.py | 12 ++ sys-running-data-extract/Makefile | 7 + sys-running-data-extract/perf/xxstat | Bin 0 -> 4096 bytes sys-running-data-extract/producer.c | 68 +++++++ sys-running-data-extract/reader.c | 55 ++++++ tex_template/Makefile | 6 + tex_template/book_utf8.tex | 133 ++++++++++++++ tex_template/introduction_utf8.tex | 44 +++++ tex_template/ppt_utf8.tex | 127 +++++++++++++ tex_template/preface_utf8.tex | 22 +++ tmux_scripts/tmux.conf | 55 ++++++ vim_scripts/vimrc | 242 +++++++++++++++++++++++++ 40 files changed, 1489 insertions(+) create mode 100644 astyle_scripts/astylerc create mode 100644 cdefer/examples/Makefile create mode 100644 cdefer/examples/main.c create mode 100644 cdefer/lib/Makefile create mode 100644 cdefer/lib/defer.c create mode 100644 cdefer/lib/defer.h create mode 100644 cdefer/lib/funcexit.c create mode 100755 cdefer/lib/libcdefer.so create mode 100644 func_trace/Makefile create mode 100644 func_trace/example.c create mode 100644 func_trace/func_trace.c create mode 100644 py-simulators/AUTHORS create mode 100644 py-simulators/ChangeLog create mode 100644 py-simulators/LICENSE create mode 100644 py-simulators/README create mode 100644 py-simulators/core/__init__.py create mode 100644 py-simulators/core/reactor/__init__.py create mode 100644 py-simulators/core/reactor/event.py create mode 100644 py-simulators/core/reactor/reactor.py create mode 100644 py-simulators/core/reactor/source.py create mode 100755 py-simulators/py-config-admin create mode 100755 py-simulators/py-sp create mode 100644 py-simulators/setup.py create mode 100644 py-simulators/test/__init__.py create mode 100644 py-simulators/utils/__init__.py create mode 100755 shell_scripts/source-counter create mode 100755 style_check_scripts/c_style_check.py create mode 100755 style_check_scripts/clint.py create mode 100755 style_check_scripts/clint_unittest.py create mode 100644 sys-running-data-extract/Makefile create mode 100644 sys-running-data-extract/perf/xxstat create mode 100644 sys-running-data-extract/producer.c create mode 100644 sys-running-data-extract/reader.c create mode 100644 tex_template/Makefile create mode 100644 tex_template/book_utf8.tex create mode 100644 tex_template/introduction_utf8.tex create mode 100644 tex_template/ppt_utf8.tex create mode 100644 tex_template/preface_utf8.tex create mode 100644 tmux_scripts/tmux.conf create mode 100644 vim_scripts/vimrc diff --git a/astyle_scripts/astylerc b/astyle_scripts/astylerc new file mode 100644 index 0000000..2805ec9 --- /dev/null +++ b/astyle_scripts/astylerc @@ -0,0 +1,17 @@ +# bigwhite's astyle options file + +--indent=spaces=4 +--brackets=attach +# --brackets=linux +--indent-switches +--indent-cases +--indent-preprocessor +--indent-col1-comments +--pad-oper +--pad-header +--unpad-paren +--add-brackets +--keep-one-line-statements +--align-pointer=name +--mode=c +--min-conditional-indent=0 diff --git a/cdefer/examples/Makefile b/cdefer/examples/Makefile new file mode 100644 index 0000000..130355e --- /dev/null +++ b/cdefer/examples/Makefile @@ -0,0 +1,3 @@ +all: + gcc -g main.c -o main -finstrument-functions -I ../lib -L ../lib -lcdefer + diff --git a/cdefer/examples/main.c b/cdefer/examples/main.c new file mode 100644 index 0000000..e55fc8a --- /dev/null +++ b/cdefer/examples/main.c @@ -0,0 +1,27 @@ +#include +#include +#include "defer.h" + +int +bar(int a, char *s) +{ + printf("a = [%d], s = [%s]\n", a, s); + +} + +int +main() +{ + FILE *fp = NULL; + fp = fopen("main.c", "r"); + if (!fp) return; + defer(fclose, 1, fp); + + int *p = malloc(sizeof(*p)); + if (!p) return; + defer(free, 1, p); + + defer(bar, 2, 13, "hello"); + return 0; +} + diff --git a/cdefer/lib/Makefile b/cdefer/lib/Makefile new file mode 100644 index 0000000..e0e6c7b --- /dev/null +++ b/cdefer/lib/Makefile @@ -0,0 +1,5 @@ +# Makefile for cdefer + +all: + gcc -g -fPIC -shared -o libcdefer.so funcexit.c defer.c + cp libcdefer.so ../examples diff --git a/cdefer/lib/defer.c b/cdefer/lib/defer.c new file mode 100644 index 0000000..890e924 --- /dev/null +++ b/cdefer/lib/defer.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include "defer.h" + +struct defer_func_ctx ctx_stack[10]; +int top_of_stack = 0; /* stack top from 1 to 10 */ + +void +stack_push(struct defer_func_ctx *ctx) +{ + if (top_of_stack >= 10) { + return; + } + + ctx_stack[top_of_stack] = *ctx; + top_of_stack++; +} + +struct defer_func_ctx* +stack_pop() +{ + if (top_of_stack == 0) { + return NULL; + } + + top_of_stack--; + return &ctx_stack[top_of_stack]; +} + +int +stack_top() +{ + return top_of_stack; +} + +void +defer(defer_func fp, int arg_count, ...) +{ + va_list ap; + va_start(ap, arg_count); + + struct defer_func_ctx ctx; + memset(&ctx, 0, sizeof(ctx)); + ctx.params_count = arg_count; + printf("in defer: params count is [%d]\n", ctx.params_count); + + if (arg_count == 0) { + ctx.ctx.zp.df = fp; + + } else if (arg_count == 1) { + ctx.ctx.op.df = fp; + ctx.ctx.op.p1 = va_arg(ap, void*); + + } else if (arg_count == 2) { + ctx.ctx.tp.df = fp; + ctx.ctx.tp.p1 = va_arg(ap, void*); + ctx.ctx.tp.p2 = va_arg(ap, void*); + ctx.ctx.tp.df(ctx.ctx.tp.p1, ctx.ctx.tp.p2); + } + + va_end(ap); + stack_push(&ctx); + printf("defer push function: [%p]\n", fp); + printf("in defer: stack top is: [%d]\n", stack_top()); +} + diff --git a/cdefer/lib/defer.h b/cdefer/lib/defer.h new file mode 100644 index 0000000..243b1f4 --- /dev/null +++ b/cdefer/lib/defer.h @@ -0,0 +1,34 @@ +#ifndef _DEFER_H_ +#define _DEFER_H_ + +typedef void (*defer_func)(); + +struct zero_params_func_ctx { + defer_func df; +}; + +struct one_params_func_ctx { + defer_func df; + void *p1; +}; + +struct two_params_func_ctx { + defer_func df; + void *p1; + void *p2; +}; + +struct defer_func_ctx { + int params_count; + union { + struct zero_params_func_ctx zp; + struct one_params_func_ctx op; + struct two_params_func_ctx tp; + } ctx; +}; + +void stack_push(struct defer_func_ctx *ctx); +struct defer_func_ctx* stack_pop(); +int stack_top(); + +#endif diff --git a/cdefer/lib/funcexit.c b/cdefer/lib/funcexit.c new file mode 100644 index 0000000..c46960a --- /dev/null +++ b/cdefer/lib/funcexit.c @@ -0,0 +1,38 @@ +#include +#include "defer.h" + +extern struct defer_func_ctx ctx_stack[10]; + +__attribute__((no_instrument_function)) +void +__cyg_profile_func_enter(void *this_fn, void *call_site) +{ + printf("enter func => %p\n", this_fn); +} + +__attribute__((no_instrument_function)) +void +__cyg_profile_func_exit(void *this_fn, void *call_site) +{ + printf("exit func <= %p\n", this_fn); + + struct defer_func_ctx *ctx = NULL; + printf("in funcexit: stack top is [%d]\n", stack_top()); + + while ((ctx = stack_pop()) != NULL) { + printf("params count is [%d]\n", ctx->params_count); + if (ctx->params_count == 0) { + printf("defer pop function: [%p]\n", ctx->ctx.zp.df); + ctx->ctx.zp.df(); + } else if (ctx->params_count == 1) { + printf("defer pop function: [%p]\n", ctx->ctx.op.df); + ctx->ctx.op.df(ctx->ctx.op.p1); + } else if (ctx->params_count == 2) { + printf("in exit: df = %p\n", (ctx->ctx).tp.df); + printf("in exit: p1 = %p\n", (ctx->ctx).tp.p1); + printf("in exit: p2 = %p\n", (ctx->ctx).tp.p2); + printf("defer pop function: [%p]\n", ctx->ctx.tp.df); + ctx->ctx.tp.df(ctx->ctx.tp.p1, ctx->ctx.tp.p2); + } + } +} diff --git a/cdefer/lib/libcdefer.so b/cdefer/lib/libcdefer.so new file mode 100755 index 0000000000000000000000000000000000000000..0f6ff205076fe6118b528ae14cea4e000617ae2f GIT binary patch literal 10165 zcmeHNdyrezc|Z5+?(W@{yeoUx#$dMyvknWfwYFnC#z0s<)^G5FZHntS7phE{X zJ-c`9O(xUHpM08gzvubR<2&cvdydY%{hQYsh9NZggilDWNrhScopP2dppA?TS#!81{Bxv2~GI(0+Fq;&&t z6=Uf(A#~ad9h27I3_aKjK>NQ1dT;&C!IFvjQLMyWz&@mPH*FXGUq1EN(;xnD*-sX2 zJ^b43TYkFk-Zz8PvAxXGg48xIXx-N;T5U^2?q7SrqAq}hW{L-2*){whfBdI|tNOox z=Jua-@BHR}|H<7yJ3aH_%IL1)dSyq;n|Itc_Zzhzw_o+_hK_gs_1*S4e|BIovQ2{9 zJlqV>Zdjyr9-geXh7gF4YX+G79;9EOqO*Z#2*0=i_*c0X!0Dlo+`WpfMD)>zp;{sdU^KDrKThJOjPRQl!h&zYK}@YJZ}Il_~CoO)XFoGHl=`Nt$rGTB4^Ao%T-w{G29=ja<5 zd*>2V=S=Xv=NEt#rCrtXSy-UX?bUKOBo(W>{vagP@*;4xXSzYx9tz=kOJ%w@%147cKfP-V1nSaojq*g@tkpXsW<3#*Z_1;}12=T4!l?RI5b zx5esy`@=><V4`C01RVs3?wVzGa;G@rzPRV)9a$KYz$pwDU?KgG31T9-dCO5v%@n_cq(i`qUL zO=-M(YX3w&v-Af#-$_p~-}|Mi$ADcczwePhr{#fK*?woD-j8bedDVTum9LlO4+Pv= zsMa=KsncJj|6KW=bE0Ga8C14>v>Q=5cu>Zq{%J@?#vZ{Std`HAzpJABLF>IMT_#v9 zpMmg&|FVo1tNnJ>uC!IxTa}Ggb-i8LXjl6Jl~njMU@v(Xmy088^@I^&cl%x&R#U(N{z|#nWgp5qm?6L zuR&Ma9<24BtKf0+7)uey`Z!I2W8IkxwgqSONcL-(Dk1T&Cj)oINl{n zaNYG%AW|90Q?Vi>UmYR5O+u+cXy^Rct~Qa2vc#1L=95lWgnn&_c&klSq?^@Se^!VM02p(8*RBWVnCbpm zqY(ohKsOx#z6bb8;FIY2*MR#m_C5eU2s|5O^ai; zI$0L=$B}Z-V@^-#w@I~Z(^-g<(96}?Q(yD6DkBIzzn7PzpXAh}pO4_99{8vSe&Zg% z>fWHS#-us*`CZKy9QP~uh?e`3_daZ7xgOzDSRBE3F!z>U0MCW)G!j06<##tejm0^9 zL&HQYLgKnL9SJX0(F1>^KY$VUbkuhuaec%xm;DFGQI{<1fG^SPUx3GQBzcJb-@rY$ zhR0Ed=a61PdL8L)r1z1yKUlYV^@>o>_CdUIO1+!0oyuoJOT){;pIErKB!yRBsd%~K zvW05DsCJfzSZx=$!kOY#NZ=a4o#PRY{(GR^{Kj3-8;?pe<>*Ej6HKe+?}!Y06_MF8 zpoHI$!sazn*fbNad{z^7al*8l{+B|#EcjbgRn-vLQXK7x{N(73aE@7df^&}oabLP!3oi+^GoVA6| z%S9V@p~9TQGR?~^(QbSfa>F*b$LGG8@JCQ~T#AQb%W@Bijwr;MW3C6tcNomUZeI@e zyW_b!CgpNDE69?KPMVpA(&$UJL)?sTn&MwTSt_D6N&yVLjjd@8^lv+&kFX9sDxw3R z*+WfV0pS~92xP=9>&qZptiQz5eiDyX(Iz8qHNOPTkBD0>4})UF+hoM8w*S!@zpL>h z;?{V?+hoM8j>}M#bP)8K>4^Igacex{fq-?SSBOhVf-~H!*8&Ic@o18{vt#wK7NwsA-0^QPB*?r>sgf2 zm`6iTAj5Q{O!;LTRh02a<^<>t<8zc>VNk&E%?2AnjDtfth-GsRi5dH(ksOkTtk%v5 zbXQi89Rs6N4wD5e+&uIt(M4hr9L$^#eXE$oRn2IjOQXrx7ZPIDASE`PLDB<>Fs2*x z+dKWf_Brj-jTuI;8NRxO-~UO75M-A`4XqAH5%5{U*S^Akt$zcS)n>{_w9GUNAe*0B zt(}Ii-S4LjWo^@h&sG_hV8_(`+{%Pi zaOt>rvcHAq_}XQIbjxhjvR1aNZF0-}6SZfB1KyUgF>b5Tl*ujYn7U;_w9L)Irc4hD z-Tn=os{MGSO>TYXVz$vB#E$_T=g!oFS9r8#$$8IPVTT1hwReJU$#s34nE`$>yP0p z*pK>xcF1gocb?psqJ-xK<@J^d`Cgph^(Lax-qf%@5J6zCYmnA z;zHVK#;umDVWAj{A`_2=qRB{J6q4C|F*GjY+cX+U zr=0?_x_ePa?nQY(9$M{w226FT%2QKMtYm@mz*VHPnM6oFCY3Xl6L~Z{k=5Z^GLfCN z%Vy$^+OewBTw16`P+Lr<3eHeQ+!fDfFEA_axlo3q*-|Q9Ol6!qBTgDe$CJ-?;oUvu zMNHj}Q0Kio8dfolDvVQJjFITLAJ4I{OCkq>Bij^39>~bkUeLA=G>1P1rA@q0(na+V zB_lYf56AXpkW=AeUTN-(=LP7ED( zc!Z^I5aR@0He!F>Eq&0)ogYZ|?w$#hmO zQ0UU%0C1Eq|L?-mHR=C3omGd9qw#(0RcN;y(P6qBv=50uJ0^Z%V(mxt)c)xUunQqk z2PAP2xDSbWX~+E*(`nEeXiHd+#61)3xL;!G2Cd7boM}4}_gJL4&tl@N@s9rtxi+K%sfZFeVV))k*FazDvECHqPP?Fe@uX}g0EGUcR3 zJ%T{Ay&Fl}$;~LEojVK5Fl%K_Jp{St!>Qxh|~pzRKVr zyH`DS+-uK9peWa%={F%@`Lcc?v;%gd;5CF?;)lR2cah7}?kbliqK@fp7XwLH3%fp- zCZY}DJtR$&e*kt@=t_BX{2=q%J%vs=>k(+O<2<`B;f(w$t@QYt9^HuST3dZs{&(kj<=O3|8o`R|WrWLPd8t0SZXG+X@L-5Jl0>~edEO?%-O@L3{ zdhqfXEFSPpS_$coZ@CHZO}cGC{qIaDLHWe*j*lZMEZmO>0PFS}Xg}9l-F^e7em&rI z`wg7_T@7CMzlr|e1eWdLkTB4m-v{mn&ybQ&0^jGxi}vo&fmD@W1P;3W#qvkM|GNq+ zY&*nf!F$Vpg!UZV0Q&o?BIT3q`PO;-QSe{)l>cwwXOEXRUDUzzoPa=o4PYHF1Mv!= z!ulN2fPWs_>G+cWxTirJ9oK{R-d|Y<-g|%LcJSW&BSYZ(LP9)-yu5#s1Mj_mvIjih zfdt+!xd*(4c_4T&(i2ks&HRsh^biXkpPV28;C+~Hg7^A=={)-%fam5e0(;(Xc?-Pv zzRbJez4u|>13&4$OEh0B6iY)x*zY>d>TO$YaW-$*x{WtqoHdiUjjKJXSk_6TvxAYe zBR?^nNNKOY=VLA%FUDixWs9%AMo{6TVtc_YTP)O9YOFLoyib?Yf72RS%-UO4-q`PG zj>Twtq7?Z(D@!?l&nN56jdM5=FFLuXQ%sgJyTgNfbpy1s3vHsbi50R=GLngcZ`ug;3nnj*lJHLK&>AA|Iujov1 np=iQ0@99js^K<^CBwp&7bjxRot4LFB2;J*UQ`}PGe)|6aD+Wv< literal 0 HcmV?d00001 diff --git a/func_trace/Makefile b/func_trace/Makefile new file mode 100644 index 0000000..bc5a3aa --- /dev/null +++ b/func_trace/Makefile @@ -0,0 +1,24 @@ +# +# Makefile for func_trace share lib +# + +OS := $(shell uname -s) + +LIBS = + +ifeq ($(OS), SunOS) + DEFS = -D_SOLARIS_TRACE + LIBS += -lfunc_trace +else ifeq ($(OS), Linux) + DEFS = -D_LINUX_TRACE +else + $(error $(OS) is not supported!) +endif + + +all: + gcc $(DEFS) -fPIC -shared -o libfunc_trace.so func_trace.c + gcc -g example.c -o example -finstrument-functions $(LIBS) + +clean: + rm -fr example libfunc_trace.so diff --git a/func_trace/example.c b/func_trace/example.c new file mode 100644 index 0000000..6f459d7 --- /dev/null +++ b/func_trace/example.c @@ -0,0 +1,20 @@ +#include + +static void foo2() { + +} + +void foo1() { + foo2(); +} + +void foo(){ + chdir("/home/tonybai"); + foo1(); +} + +int main(int argc, const char *argv[]) +{ + foo(); + return 0; +} diff --git a/func_trace/func_trace.c b/func_trace/func_trace.c new file mode 100644 index 0000000..4c554c9 --- /dev/null +++ b/func_trace/func_trace.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include /* for PATH_MAX */ + +static char path[PATH_MAX]; + +__attribute__((constructor)) +static void executable_path_init() { + char buf[PATH_MAX]; + + memset(buf, 0, sizeof(buf)); + memset(path, 0, sizeof(path)); + +#ifdef _SOLARIS_TRACE + getcwd(buf, PATH_MAX); + sprintf(path, "%s/%s", buf, getexecname()); +#elif _LINUX_TRACE + readlink("/proc/self/exe", path, PATH_MAX); +#else + #error "The OS has not been supported!" +#endif +} + +__attribute__((no_instrument_function)) +void __cyg_profile_func_enter(void *this_fn, void *call_site) { + char buf[PATH_MAX]; + char cmd[PATH_MAX]; + + memset(buf, 0, sizeof(buf)); + memset(cmd, 0, sizeof(cmd)); + + sprintf(cmd, "addr2line %p -e %s -f", this_fn, path); + + FILE *ptr = NULL; + memset(buf, 0, sizeof(buf)); + + if ((ptr = popen(cmd, "r")) != NULL) { + fgets(buf, PATH_MAX, ptr); + buf[strlen(buf) - 1] = '\0'; + printf("enter func => %p:%s:", this_fn, buf); + fgets(buf, PATH_MAX, ptr); /* filename and lineno */ + printf("%s\n", buf); + } + + (void) pclose(ptr); +} + +__attribute__((no_instrument_function)) +void __cyg_profile_func_exit(void *this_fn, void *call_site) { + char buf[PATH_MAX]; + char cmd[PATH_MAX]; + + memset(buf, 0, sizeof(buf)); + memset(cmd, 0, sizeof(cmd)); + + sprintf(cmd, "addr2line %p -e %s -f", this_fn, path); + + FILE *ptr = NULL; + memset(buf, 0, sizeof(buf)); + + if ((ptr = popen(cmd, "r")) != NULL) { + fgets(buf, PATH_MAX, ptr); + buf[strlen(buf) - 1] = '\0'; + printf("exit func <= %p:%s:", this_fn, buf); + fgets(buf, PATH_MAX, ptr); /* filename and lineno */ + printf("%s\n", buf); + } + + (void) pclose(ptr); +} diff --git a/py-simulators/AUTHORS b/py-simulators/AUTHORS new file mode 100644 index 0000000..0e8c6ae --- /dev/null +++ b/py-simulators/AUTHORS @@ -0,0 +1,4 @@ +Tony Bai + +Other Contributors: + diff --git a/py-simulators/ChangeLog b/py-simulators/ChangeLog new file mode 100644 index 0000000..bca429b --- /dev/null +++ b/py-simulators/ChangeLog @@ -0,0 +1,5 @@ +# +# ChangeLog for py-simulators +# +2013-01-22 Tony Bai + * initial import diff --git a/py-simulators/LICENSE b/py-simulators/LICENSE new file mode 100644 index 0000000..fb5e5b9 --- /dev/null +++ b/py-simulators/LICENSE @@ -0,0 +1,13 @@ +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + diff --git a/py-simulators/README b/py-simulators/README new file mode 100644 index 0000000..e69de29 diff --git a/py-simulators/core/__init__.py b/py-simulators/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/py-simulators/core/reactor/__init__.py b/py-simulators/core/reactor/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/py-simulators/core/reactor/event.py b/py-simulators/core/reactor/event.py new file mode 100644 index 0000000..2255cc1 --- /dev/null +++ b/py-simulators/core/reactor/event.py @@ -0,0 +1,27 @@ + +"""event.py + + A wrapper of epoll or poll events + +""" + +import select + +try: + from select import epoll + EVENT_IN = select.EPOLLIN + EVENT_PRI = select.EPOLLPRI + EVENT_OUT = select.EPOLLOUT + EVENT_ERR = select.EPOLLERR + EVENT_HUP = select.EPOLLHUP + EVENT_NVAL = 0 + +except ImportError: + + from select import poll + EVENT_IN = select.POLLIN + EVENT_PRI = select.POLLPRI + EVENT_OUT = select.POLLOUT + EVENT_ERR = select.POLLERR + EVENT_HUP = select.POLLHUP + EVENT_NVAL = select.POLLNVAL diff --git a/py-simulators/core/reactor/reactor.py b/py-simulators/core/reactor/reactor.py new file mode 100644 index 0000000..9fa8668 --- /dev/null +++ b/py-simulators/core/reactor/reactor.py @@ -0,0 +1,23 @@ +# +# +# + +"""reactor.py + +""" + +try: + from select import epoll + EVENT_NOTIFY_FACILITY = 'epoll' +except ImportError: + from select import poll + EVENT_NOTIFY_FACILITY = 'poll' + +class Reactor(object): + """ + + """ + + def __init__(self, + + diff --git a/py-simulators/core/reactor/source.py b/py-simulators/core/reactor/source.py new file mode 100644 index 0000000..416c179 --- /dev/null +++ b/py-simulators/core/reactor/source.py @@ -0,0 +1,32 @@ + +"""source.py + + Definitions of the source which trigger the events. + There are several sorts of source, such as File Descriptor + source, Timer source etc. +""" + +class Source(object): + """class Source + + three source object could be created: + * file source -- fs = Source(sock) + * file source with timeout -- fs = Source(sock, 500) + * pure timer source -- ts = Source(None, 1000) + + """ + + __slots__ = ('fileobj', 'timeval') + + def __init__(self, fileobj, timeval = None): + """ timeval in microseconds """ + self.fileobj = fileobj + self.timeval = timeval + + @property + def fileno(self): + if not self.fileobj: + return -1 + else: + return self.fileobj.fileno() + diff --git a/py-simulators/py-config-admin b/py-simulators/py-config-admin new file mode 100755 index 0000000..8e005cf --- /dev/null +++ b/py-simulators/py-config-admin @@ -0,0 +1,10 @@ +#! /usr/bin/env python + +""" + config-admin + + config-admin is an assistant tool of simulator configure + files administration. + + usage: +""" diff --git a/py-simulators/py-sp b/py-simulators/py-sp new file mode 100755 index 0000000..50ae0fd --- /dev/null +++ b/py-simulators/py-sp @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +""" py-sp + + A short-message service provider simulator, + support CMPP2.0/2.1 and CMPP3.0 protocol. +""" diff --git a/py-simulators/setup.py b/py-simulators/setup.py new file mode 100644 index 0000000..8f308e8 --- /dev/null +++ b/py-simulators/setup.py @@ -0,0 +1,3 @@ +#! /usr/bin/env python + + diff --git a/py-simulators/test/__init__.py b/py-simulators/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/py-simulators/utils/__init__.py b/py-simulators/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/shell_scripts/source-counter b/shell_scripts/source-counter new file mode 100755 index 0000000..e3acd68 --- /dev/null +++ b/shell_scripts/source-counter @@ -0,0 +1,68 @@ +#! /bin/bash + +# +# 计算有效变更代码量的脚本 +# 包括注释,但不包括新增的空行 +# + +version() { + OS=`uname -o` + echo "Source_counter ($OS) 0.0.1" + echo " tony bai (http://tonybai.com)" +} + +usage() { + echo "usage: source-counter [-t SVN_REPOSITORY_URL] [-s START_REVISION]" + echo " [-e END_REVISION] [-u USER_NAME]" + echo " [-p PASSWD]" + echo " source-counter [-v|-h]" + echo + echo " -t, 目标SVN库地址" + echo " -s, 起始修订号" + echo " -e, 结束修订号" + echo " -u, svn帐号" + echo " -p, svn密码" + echo " -h, 帮助" + echo " -v, 版本信息" +} + +if [ $# -lt 2 ]; then + usage + exit 1 +fi + +while getopts "t:s:e:u:p:vh" opt; do + case $opt in + t) target=$OPTARG;; + s) start_revision=$OPTARG;; + e) end_revision=$OPTARG;; + u) user=$OPTARG;; + p) passwd=$OPTARG;; + v) version; exit 1;; + h) usage; exit 1;; + esac +done + +if [ -z $target ]; then + echo "请输入目标SVN库地址!" + exit 1 +fi + +if [ -z $start_revision ]; then + echo "请输入起始修订号!" + exit 1 +fi + +if [ -z $end_revision ]; then + echo "请输入终止修订号!" + exit 1 +fi + +TEMPFILE=temp.log +USERNAME=${user:-} +PASSWD=${passwd:-} + +svn diff -r$start_revision:$end_revision $target $USERNAME $PASSWD > $TEMPFILE +add_lines_count=`grep "^+" $TEMPFILE|grep -v "^+++"|sed 's/^.//'|sed '/^\s*$/d'|wc -l` +rm -fr $TEMPFILE +echo "the actually incremental source code lines = $add_lines_count" diff --git a/style_check_scripts/c_style_check.py b/style_check_scripts/c_style_check.py new file mode 100755 index 0000000..45e1eb8 --- /dev/null +++ b/style_check_scripts/c_style_check.py @@ -0,0 +1,165 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# +# A simple-minded style checker for C code. +# This only catches the most obvious style mistakes, and occasionally +# flags stuff that isn't wrong. +# + +import sys, string, re, os + +# +# Constants. +# + +MAX_LINE_LENGTH = 190 # default: 78 +OK = 0 +ERROR = -1 + +# +# Regular expressions corresponding to style violations. +# + +tabs = re.compile(r"\t+") +comma_space = re.compile(",[^\n\r ]") + +# This one is really tough to get right, so we settle for catching the +# most common mistakes. Add other operators as necessary and/or feasible. +operator_space = re.compile("(\w(\+|\-|\*|\<|\>|\=)\w)" + \ + "|(\w(\=\=|\<\=|\>\=)\w)") +comment_line = re.compile("^\s*\/\*.*\*\/\s*$") +open_comment_space = re.compile("\/\*[^ *\n\r]") +close_comment_space = re.compile("[^ *]\*\/") +paren_curly_space = re.compile("\)\{") +space_before_paren = re.compile("if\(|while\(|for\(") +c_plus_plus_comment = re.compile("\/\/") +semi_space = re.compile(";[^ \s]") + +def check_line(filename, line, n): + """ + Check a line of code for style mistakes. + """ + # Strip the terminal newline. + line = line[:-1] + err_cnt = 0 + + # 禁止使用TAB,应全部转换为空格 + if tabs.search(line): + print "File: %s, line %d: [TABS]:\n%s" % \ + (filename, n, line) + err_cnt = err_cnt + 1 + + # 限制每行代码长度不得超过MAX_LINE_LENGTH + if len(line) > MAX_LINE_LENGTH: + print "File: %s, line %d: [TOO LONG (%d CHARS)]:\n%s" % \ + (filename, n, len(line), line) + err_cnt = err_cnt + 1 + + # 要求所有逗号后面必须有空格,包括注释里的内容 + if comma_space.search(line): + if not comment_line.search(line): + print "File: %s, line %d: [PUT SPACE AFTER COMMA]:\n%s" % \ + (filename, n, line) + err_cnt = err_cnt + 1 + + # 要求在常见操作符(比如+,-,*,/,>,<等)两侧要添加空格 + if operator_space.search(line): + if not comment_line.search(line): + # 排除字符串内有类似"mpiag-smsc.fifo"这样的字符串被误匹配 + sections_in_quotes = re.findall(r'"(.*?)"', line) + operator_in_string = False + for section in sections_in_quotes: + if operator_space.search(section): + operator_in_string = True + break + if not operator_in_string: + print "File: %s, line %d: [PUT SPACE AROUND OPERATORS]:\n%s" % \ + (filename, n, line) + err_cnt = err_cnt + 1 + + # 我们希望/* Comments */而不是/*Comments*/ + if open_comment_space.search(line): + print "File: %s, line %d: [PUT SPACE AFTER OPEN COMMENT]:\n%s" % \ + (filename, n, line) + err_cnt = err_cnt + 1 + + # 我们希望/* Comments */而不是/*Comments*/ + if close_comment_space.search(line): + print "File: %s, line %d: [PUT SPACE BEFORE CLOSE COMMENT]:\n%s" % \ + (filename, n, line) + err_cnt = err_cnt + 1 + + # 在){之间要求添加一个空格 + if paren_curly_space.search(line): + print "File: %s, line %d: [PUT SPACE BETWEEN ) AND {]:\n%s" % \ + (filename, n, line) + err_cnt = err_cnt + 1 + + # 在if/while/for与(之间要求添加一个空格 + if space_before_paren.search(line): + print "File: %s, line %d: [PUT SPACE BETWEEN if/while/for AND (]:\n%s" % \ + (filename, n, line) + err_cnt = err_cnt + 1 + + # 要求使用传统的C注释方式:/* ... */ + if c_plus_plus_comment.search(line): + print "File: %s, line %d: [DON'T USE C++ COMMENTS]:\n%s" % \ + (filename, n, line) + err_cnt = err_cnt + 1 + + # 要求分号后面放置一个空格或换行符 + if semi_space.search(line): + print "File: %s, line %d: [PUT SPACE/NEWLINE AFTER SEMICOLON]:\n%s" % \ + (filename, n, line) + err_cnt = err_cnt + 1 + + if err_cnt == 0: + return OK + else: + return ERROR + + +def check_file(filename): + file = open(filename, "r") + lines = file.readlines() + file.close() + + err_lines_cnt = 0; + for i in range(len(lines)): + result = check_line(filename, lines[i], i + 1) # Start on line 1. + if result == ERROR: + err_lines_cnt = err_lines_cnt + 1 + + if err_lines_cnt == 0: + return OK + else: + return ERROR + +# +# Main body of program. +# + +usage = "usage: c_style_check filename1 [filename2 ...]" + +def main(): + if len(sys.argv) < 2: + print usage + #raise SystemExit + os._exit(os.EX_USAGE) + + for filename in sys.argv[1:]: + print "=====> checking file: %s" % filename + check_result = check_file(filename) + if check_result == ERROR: + print "=====> checking file: %s Error!" % filename + os._exit(os.EX_DATAERR) + else: + print "=====> checking file: %s OK" % filename + + os._exit(os.EX_OK) + + +if __name__ == '__main__': + main() + diff --git a/style_check_scripts/clint.py b/style_check_scripts/clint.py new file mode 100755 index 0000000..f809896 --- /dev/null +++ b/style_check_scripts/clint.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +import getopt +import os +import re +import sys + +USAGE = """ + Usage: clint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...] + [--counting=total|toplevel|detailed] + [file] ... + + +""" + +def print_usage(message): + """Prints a brief usage string, optionally with an error message. + + Args: + message: The optional error message. + """ + + sys.stderr.write(USAGE) + if message: + sys.stderr.write('\nFATAL ERROR: %s\n' % message) + + +def parse_arguments(args): + """ Parse the command line arguments + + Args: + args: The command line arguments: + + Returns: + The list of filenames to lint. + """ + + try: + (opts, filenames) = getopt.getopt(args, '', ['help', 'output=', + 'verbose=','filter=']) + except getopt.GetoptError: + print_usage('Invalid arguments.') + sys.exit(1) + + if not filenames: + print_usage('No files were specified') + + +def main(): + filenames = parse_arguments(sys.argv[1:]) + +if __name__ == '__main__': + main() diff --git a/style_check_scripts/clint_unittest.py b/style_check_scripts/clint_unittest.py new file mode 100755 index 0000000..9a3677a --- /dev/null +++ b/style_check_scripts/clint_unittest.py @@ -0,0 +1,12 @@ +#! /usr/bin/python + +import clint +import unittest + +class ClintTest(unittest.TestCase): + def testParseArguments(self): + self.assertEqual(1, 1) + +if __name__ == "__main__": + unittest.main() + diff --git a/sys-running-data-extract/Makefile b/sys-running-data-extract/Makefile new file mode 100644 index 0000000..e6400eb --- /dev/null +++ b/sys-running-data-extract/Makefile @@ -0,0 +1,7 @@ + +all: + gcc -g -o producer producer.c + gcc -g -o reader reader.c + +clean: + rm reader producer diff --git a/sys-running-data-extract/perf/xxstat b/sys-running-data-extract/perf/xxstat new file mode 100644 index 0000000000000000000000000000000000000000..d20fba7543c59a752c346bc0b37cb93a1551340a GIT binary patch literal 4096 zcmdlQ&j1D=4lsl1gicj3eIT}+5h626j)uT!2#kinXb6mkz-S1JhQMeDjE2By2#kin PXb6mkz-R~z^$-96ZBzwo literal 0 HcmV?d00001 diff --git a/sys-running-data-extract/producer.c b/sys-running-data-extract/producer.c new file mode 100644 index 0000000..80c153d --- /dev/null +++ b/sys-running-data-extract/producer.c @@ -0,0 +1,68 @@ + + +#include +#include + +#include +#include +#include + +#define STAT_FILE "./perf/xxstat" + +int +main() +{ + FILE *fp = NULL; + + errno = 0; + fp = fopen(STAT_FILE, "w+"); + if (fp == NULL) { + printf("can not create stat file , err = %d\n", errno); + return -1; + } + + errno = 0; + long size = sysconf(_SC_PAGESIZE); + if (ftruncate(fileno(fp), size) != 0) { + printf("can not set stat file size, err = %d\n", errno); + fclose(fp); + return -1; + } + + errno = 0; + char *p = NULL; + p = mmap(NULL, size, PROT_WRITE|PROT_READ, + MAP_SHARED, fileno(fp), 0); + if (p == MAP_FAILED) { + printf("can not mmap file, error = %d\n", errno); + fclose(fp); + return -1; + } + + errno = 0; + if (fclose(fp) != 0) { + printf("can not close file, error = %d\n", errno); + return -1; + } + + /* round up to a multiple of 8 */ + while((int)p % 8 != 0) { + p++; + } + + long long *q = (long long*)p; + q[0] = 1; + q[1] = 1000; + q[2] = 10000; + q[3] = 100000; + + while(1) { + q[0] += 1; + q[1] += 10; + q[2] += 100; + q[3] += 1000; + usleep(200); + } + + return 0; +} diff --git a/sys-running-data-extract/reader.c b/sys-running-data-extract/reader.c new file mode 100644 index 0000000..516ff80 --- /dev/null +++ b/sys-running-data-extract/reader.c @@ -0,0 +1,55 @@ + + +#include +#include + +#include +#include +#include +#include + +#define STAT_FILE "./perf/xxstat" + +int +main() +{ + FILE *fp = NULL; + + errno = 0; + fp = fopen(STAT_FILE, "r"); + if (fp == NULL) { + printf("can not open stat file , err = %d\n", errno); + return -1; + } + + long size = sysconf(_SC_PAGESIZE); + errno = 0; + char *p = NULL; + p = mmap(NULL, size, PROT_READ, + MAP_SHARED, fileno(fp), 0); + if (p == MAP_FAILED) { + printf("can not mmap file, error = %d\n", errno); + fclose(fp); + return -1; + } + + errno = 0; + if (fclose(fp) != 0) { + printf("can not close file, error = %d\n", errno); + return -1; + } + + /* round up to a multiple of 8 */ + while((int)p % 8 != 0) { + p++; + } + + long long *q = (long long*)p; + + while(1) { + printf("%lld\t\t%lld\t\t%lld\t\t%lld\n", q[0], q[1], q[2], q[3]); + sleep(1); + } + + return 0; +} diff --git a/tex_template/Makefile b/tex_template/Makefile new file mode 100644 index 0000000..3e3bac3 --- /dev/null +++ b/tex_template/Makefile @@ -0,0 +1,6 @@ +all: + xelatex book_utf8.tex + xelatex ppt_utf8.tex +clean: + rm -f *.aux *.log *.out *.pdf *.toc *.vrb *.snm *nav + diff --git a/tex_template/book_utf8.tex b/tex_template/book_utf8.tex new file mode 100644 index 0000000..c4bf8d8 --- /dev/null +++ b/tex_template/book_utf8.tex @@ -0,0 +1,133 @@ +% +% TeX模板 +% +% 中文支持方案: XeTeX + xeCJK +% author: Tony Bai +% +% compile: +% xelatex book_utf8.tex +% + +\documentclass[a4paper,11pt,titlepage]{book} % 五号字 + +% +% preamble begin { +% + +\usepackage{fontspec} +\usepackage{xunicode} +\usepackage{xltxtra} % xltxtra include the cmd \XeTeX + +\XeTeXlinebreaklocale "zh" +\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt + +\usepackage{titletoc} % 控制目录 +\usepackage{appendix} % 控制附录 + +\usepackage[colorlinks, + linkcolor=black, + citecolor=black]{hyperref} % \url + +% 页边距设置 +\usepackage[top=1.2in,bottom=1.2in,left=1.2in,right=1in]{geometry} + +% 封面设置 +\title{\XeTeX\ 日常使用模板} +\author{著:Tony Bai\\ + 译:Tony Bai\footnote{\url{http://bigwhite.blogbus.com}}} +\date{October, 2010} + +% 页眉页脚设置 +\usepackage{fancyhdr} +\pagestyle{fancy} +\fancyhf{} % 清空页眉页脚 +\fancyhead[LE,RO]{\thepage} % 偶数页左,奇数页右 +\fancyhead[RE]{\leftmark} % 偶数页右 +\fancyhead[LO]{\rightmark} % 奇数页左 +\fancypagestyle{plain}{ +\fancyhf{} % 重定义plain页面样式 +\renewcommand{\headrulewidth}{0pt} +} +\renewcommand\chaptermark[1]{\markboth{\chaptername~ #1}{}} +\renewcommand\sectionmark[1]{\markright{\thesection~ #1}} + +% 行距 +\renewcommand{\baselinestretch}{1.25} + +% 章节设置 +\usepackage{titlesec} +\titleformat{\chapter}{\centering\huge}{第\thechapter{}章}{1em}{\textbf} + +% xeCJK设置 +\usepackage[slantfont, boldfont, CJKaddspaces]{xeCJK} + +% view the font list through the cmd "fc-list :lang=en" +\setmainfont{Times New Roman} % for normal and italic en +\setsansfont{Arial} +\setmonofont{Courier New} + +% view the font list through the cmd "fc-list :lang=zh" +\setCJKmainfont{WenQuanYi Micro Hei} +\setCJKsansfont{WenQuanYi Micro Hei} +\setCJKmonofont{WenQuanYi Micro Hei} +%\setCJKfamilyfont{song}{WenQuanYi Micro Hei} + +% 重定义设置 +\renewcommand{\chaptername}{第{\thechapter}章} +\renewcommand{\contentsname}{目~录} +\renewcommand{\indexname}{索引} +\renewcommand{\listfigurename}{插图目录} +\renewcommand{\listtablename}{表格目录} +\renewcommand{\figurename}{图} +\renewcommand{\tablename}{表} +\renewcommand{\appendixname}{附录} +\renewcommand{\appendixpagename}{附录} +\renewcommand{\appendixtocname}{附录} +%\renewcommand\refname{参考文献} + +\usepackage[fleqn]{amsmath} % 公式居左 +\usepackage{listings} % 用于在文档中插入源代码 + +\lstset{ language={[ANSI]C}, + showspaces=false, + showtabs=false, + tabsize=4, + frame=single, + framerule=1pt, + framexleftmargin=5mm, + framexrightmargin=5mm, + framextopmargin=5mm, + framexbottommargin=5mm, + %numbers=left, + %numberstyle=\small, + basicstyle=\tt, + directivestyle=\tt, + identifierstyle=\tt, + commentstyle=\tt, + stringstyle=\tt, + keywordstyle=\color{blue}\tt } +% +% } preamble end +% + + +% +% body begin { +% + +\begin{document} + +\maketitle % 生成title + +\include{preface_utf8} % 序言 + +\tableofcontents % 生成目录 +\setcounter{tocdepth}{3} % 设置目录深度 + +\include{introduction_utf8} % 第一章 导 言 + +\end{document} + +% +% } body end +% diff --git a/tex_template/introduction_utf8.tex b/tex_template/introduction_utf8.tex new file mode 100644 index 0000000..eba7d19 --- /dev/null +++ b/tex_template/introduction_utf8.tex @@ -0,0 +1,44 @@ +\chapter{导~言} +在这一章节中,... + +\section{XX} +在xx + +\begin{center} +\begin{lstlisting}[caption={An Example}] + +/* + * HelloWorld.h + * + * A trivial example + */ + +#ifndef _HELLOWORLD_H_ +#define _HELLOWORLD_H_ + +/* headers included */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* your_own_functions_prototype */ + +#ifdef __cplusplus +} +#endif + +#endif /* _HELLOWORLD_H_ */ +\end{lstlisting} + +\end{center} + +\subsection{XX-1} +在xx-1 +\subsection{XX-2} +在xx-2 + +\section{YY} +在yy +\subsection{YY-1} +在yy-1 diff --git a/tex_template/ppt_utf8.tex b/tex_template/ppt_utf8.tex new file mode 100644 index 0000000..f029377 --- /dev/null +++ b/tex_template/ppt_utf8.tex @@ -0,0 +1,127 @@ +% +% PPT TeX模板 +% +% 中文支持方案: XeTeX + xeCJK +% author: Tony Bai +% +% compile: +% xelatex ppt_gbk.tex +% + +\documentclass{beamer} + +%\XeTeXinputencoding "GBK" + +\usepackage{fontspec} % for XeTeX +\usepackage{xunicode} +\usepackage{xltxtra} + +%\usepackage{beamerthemesplit} +\usepackage{hyperref} +\usepackage{listings} + +\lstset{ language={[ANSI]C}, + showspaces=false, + showtabs=false, + tabsize=4, + frame=single, + %framerule=1pt, + framexleftmargin=5mm, + framexrightmargin=5mm, + framextopmargin=5mm, + framexbottommargin=5mm, + %numbers=left, + %numberstyle=\small, + basicstyle=\tt\tiny, + directivestyle=\tt\tiny, + identifierstyle=\tt\tiny, + commentstyle=\tt\tiny, + stringstyle=\tt\tiny, + keywordstyle=\color{blue}\tt\tiny } + +% xeCJK设置 +\usepackage[slantfont, boldfont, CJKaddspaces]{xeCJK} + +% view the font list through the cmd "fc-list :lang=en" +\setmainfont{Times New Roman} % for normal and italic en +\setsansfont{Arial} +\setmonofont{Courier New} + +% view the font list through the cmd "fc-list :lang=zh" +\setCJKmainfont{WenQuanYi Micro Hei} +\setCJKsansfont{WenQuanYi Micro Hei} +\setCJKmonofont{WenQuanYi Micro Hei} +%\setCJKfamilyfont{song}{WenQuanYi Micro Hei} + +\XeTeXlinebreaklocale "zh" +\XeTeXlinebreakskip = 0pt plus 1pt + +\usetheme{boxes} + +\title{\XeTeX~PPT模板} +\author{Tony Bai \footnote{\url{http://bigwhite.blogbus.com}}} +\date{\today} + +\begin{document} + +\begin{frame} +\titlepage +\end{frame} + +\begin{frame} +\frametitle{Outline} +\tableofcontents +\end{frame} + +\begin{frame} +\frametitle{first frame} +\framesubtitle{usage of itemize} + This is the first frame using \XeTeX~and beamer. + \begin{itemize} + \item<1-> xx + \item<2-> yy + \item<3-> zz + \end{itemize} +\end{frame} + +\begin{frame} +\frametitle{second frame} +\framesubtitle{usage of enumerate} + This is the second frame. + \begin{enumerate} + \item<1-> xx + \item<2-> yy + \item<3-> zz + \end{enumerate} +\end{frame} + +\begin{frame} +\frametitle{third frame} +\framesubtitle{usage of block} + This is the third frame. + \begin{block}{Advantage} + The obvious disadvantage of this approach is that you have to know LaTeX in order to use Beamer. + \end{block} + \begin{block}{disadvantage} + The advantage is that if you know LaTeX, you can use your knowledge of LaTeX also when creating a presentation, not only when writing papers. + \end{block} +\end{frame} + +\begin{frame}[fragile] +\frametitle{fourth frame} +\framesubtitle{在ppt中插入源代码} +\begin{center} +\begin{lstlisting}[caption={An Example}] + int a[10] = {[0] = 1, [4] = 14, [7] = 17}; + struct foo_struct s = {.a = 13, .b = "hello"}; + struct foo_struct fa[3] = {[0] = {.a = 12, + .b= "hello", + .c = 1.4}, + [2] = {.a = 13, + .b = "world"} + }; +\end{lstlisting} +\end{center} +\end{frame} + +\end{document} diff --git a/tex_template/preface_utf8.tex b/tex_template/preface_utf8.tex new file mode 100644 index 0000000..80164f6 --- /dev/null +++ b/tex_template/preface_utf8.tex @@ -0,0 +1,22 @@ +%\XeTeXinputencoding "GBK" % 本文件采用GBK编码 + +\chapter*{序} +\addcontentsline{toc}{chapter}{序} +\begin{quotation} +...这个世界上有两种设计软件的方法:一种是使设计尽量的简化,以至于明显没有任何缺陷;而另一种是使设计尽量的复杂,以至于找不到明显的缺陷。第一种方法更加困难。 +\begin{flushright} +\textit{ -- Tony Hoare,1980 ACM图灵奖演讲} % or use \itshape cmd +\end{flushright} +\end{quotation} +这本书讲述了... + +\begin{flushleft} +致谢\\ +\end{flushleft} + +我要感谢XX + +\begin{flushright} +Tony Bai\\ +Shenyang, 2010 +\end{flushright} diff --git a/tmux_scripts/tmux.conf b/tmux_scripts/tmux.conf new file mode 100644 index 0000000..d19104e --- /dev/null +++ b/tmux_scripts/tmux.conf @@ -0,0 +1,55 @@ +set -g prefix C-a + +set -g default-command /bin/bash +set -g default-shell /bin/bash + +set -sg escape-time 1 + +set -g base-index 1 +setw -g pane-base-index 1 + + +bind r source-file ~/.tmux.conf \; display "Reloaded!" + +bind | split-window -h +bind - split-window -v + +bind h select-pane -L +bind j select-pane -D +bind k select-pane -U +bind l select-pane -R + +bind -r H resize-pane -L 5 +bind -r J resize-pane -D 5 +bind -r K resize-pane -U 5 +bind -r L resize-pane -R 5 + +set -g mouse-select-pane on +set -g mouse-resize-pane on +set -g mouse-select-window on + +set -g status-justify centre + +set -g status-fg white +set -g status-bg black + + +set -g pane-border-fg green +set -g pane-border-bg black +set -g pane-active-border-fg white +set -g pane-active-border-bg yellow + +setw -g window-status-fg cyan +setw -g window-status-bg default +setw -g window-status-attr dim + +setw -g window-status-current-fg white +setw -g window-status-current-bg red +setw -g window-status-current-attr bright + +setw -g monitor-activity on +set -g visual-activity on + +setw -g mode-keys vi + + diff --git a/vim_scripts/vimrc b/vim_scripts/vimrc new file mode 100644 index 0000000..c3ad637 --- /dev/null +++ b/vim_scripts/vimrc @@ -0,0 +1,242 @@ +" +" .vimrc +" +" version: 0.1 2010-08-21 +" maintainer: tony_bai (http://bigwhite.blogbus.com) +" +" ref: http://amix.dk/vim/vimrc.txt +" + +""""""""""""""""" +"" => General +""""""""""""""""" +function! MySys() + return "linux" +endfunction + +function! CurDir() + let curdir = substitute(getcwd(), '/Users/tonybai/', "~/", "g") + return curdir +endfunction + +set nocompatible +"set path=PATH1,PATH2,... + +" Sets how many lines of history VIM has to remember +set history=300 + +" Enable filetype plugin +filetype plugin on +filetype indent on "help indent-expression + +" Set to auto read when a file is changed from the outside +"set autoread + +" it seems to be a trick when we use map leader! +" With a map leader it's possible to do extra key combinations +" like w saves the current file +" +" :help mapleader +let mapleader = "," +let g:mapleader = "," + +" Fast saving +nmap w :w! + +" Fast editing of the .vimrc +map e :e! ~/.vim_runtime/vimrc + +" When *vimrc* is edited, reload it +autocmd! bufwritepost *vimrc* source ~/.vimrc + +" Set backspace config +set backspace=eol,start,indent +set whichwrap+=<,>,h,l + +set hlsearch "Highlight search things +set incsearch "Make search act like search in modern browsers + +set showmatch "Show matching bracets when text indicator is over them +set mat=2 "How many tenths of a second to blink + +" No sound on errors +set noerrorbells +set novisualbell +set t_vb= + +source $VIMRUNTIME/ftplugin/man.vim + +" Զʶļıʽ +set fileencodings=UTF-8,GBK,gb18030,ucs-bom,cp936 +" ʶԴļеݵʽ +set fileencoding=GBK +" ʶvim bufferеݱʽ +set encoding=UTF-8 + +set splitright + +""""""""""""""""" +"" => Colors and fonts +""""""""""""""""" +syntax enable "Enable syntax hl + +" Set font according to system +if MySys() == "mac" + set gfn=Bitstream\ Vera\ Sans\ Mono:h13 + set shell=/bin/bash +elseif MySys() == "windows" + set gfn=Bitstream\ Vera\ Sans\ Mono:h10 +elseif MySys() == "linux" + set gfn=WenQuanYi\ Micro\ Hei\ Mono\10 "Monospace\ 10 + set shell=/bin/bash +endif + +set gfn=WenQuanYi\ Micro\ Hei\ Mono\ 11 +set shell=/bin/bash + + +if has("gui_running") + set guioptions-=T + set background=dark + set t_Co=256 + set background=dark + "colorscheme peaksea + colorscheme evening + + "set nu +else + colorscheme zellner + set background=dark + + set nonu +endif + +set ffs=unix,dos,mac "Default file types + +""""""""""""" +" => Files and backups +""""""""""""" +" Turn backup off, since most stuff is in SVN, git anyway... +set nobackup +set nowb +set noswapfile + + +""""""""""""" +" => Text, tab and indent related +""""""""""""" +set expandtab +set shiftwidth=4 +set tabstop=4 +"set smarttab + +set lbr +set textwidth=788 + +"set ai "Auto indent +"set si "Smart indet +set wrap "Wrap lines + +map t2 :setlocal shiftwidth=2 +map t4 :setlocal shiftwidth=4 +map t8 :setlocal shiftwidth=4 + +"""""""""""""""" +" => Command mode related +"""""""""""""""" +" Smart mappings on the command line +cno $h e ~/ +cno $d e ~/Desktop/ +cno $j e ./ + +" Bash like keys for the command line +cnoremap +cnoremap +cnoremap +cnoremap +cnoremap + +"""""""""""" +" => Moving around, tabs and buffers +"""""""""""" +" Map space to / (search) and c-space to ? (backgwards search) +map / +map ? + +"""""""""""""""""""""""""""""" +" => Statusline +"""""""""""""""""""""""""""""" +" Always hide the statusline +set laststatus=2 + +" Format the statusline +"set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c + +"""""""""""""""""""""""""""" +" => Parenthesis/bracket expanding +"""""""""""""""""""""""""""" +vnoremap $1 `>a)` +vnoremap $2 `>a]` +vnoremap $3 `>a}` +vnoremap $$ `>a"` +vnoremap $q `>a'` +vnoremap $e `>a"` + +" Map auto complete of (, ", ', [ +inoremap $1 ()i +inoremap $2 []i +inoremap $3 {}i +inoremap $4 {o}O +inoremap $q ''i +inoremap $e ""i + +"""""""""" +" => text format (c source) +""""""""" +autocmd BufNewFile,BufRead *[.h|.c] set formatprg=astyle +map :%! astyle + +"""""""""" +" => TagList plugin +" http://www.vim.org/scripts/script.php?script_id=273 +""""""""" +nmap tl :TlistToggle + +"""""""""" +" => NERDTree plugin +" http://www.vim.org/scripts/script.php?script_id=1658 +""""""""" +nmap tn :NERDTreeToggle + +"""""""""" +" => Cscope plugin +" http://cscope.sourceforge.net/cscope_maps.vim +""""""""" +set cscopequickfix=s-,c-,d-,i-,t-,e-" +if has("cscope") + if filereadable("cscope.out") + cscope add cscope.out + endif +endif + +"""""""""" +" => Minibuffer plugin +" http://www.vim.org/scripts/script.php?script_id=159 +""""""""" +let g:miniBufExplModSelTarget = 1 +let g:miniBufExplorerMoreThanOne = 2 +let g:miniBufExplModSelTarget = 0 +let g:miniBufExplUseSingleClick = 1 +let g:miniBufExplMapWindowNavVim = 1 +"let g:miniBufExplVSplit = 25 +"let g:miniBufExplSplitBelow=1 +let g:bufExplorerSortBy = "name" +autocmd BufRead,BufNew :call UMiniBufExplorer +map u :TMiniBufExplorer:TMiniBufExplorer + +"""""""""" +" => BufExplorer plugin +" http://www.vim.org/scripts/script.php?script_id=42 +""""""""" +"let g:bufExplorerDefaultHelp=0 +"let g:bufExplorerShowRelativePath=1