Exemplo n.º 1
0
Arquivo: e26.cpp Projeto: cqiyi/kaoshi
void MK(char in[],char is,char ie,char pre[],char pres,char pree,Tnode **r)
{
	int i;
	if(is>ie||pres>pree)
		*r=NULL;
	else
	{
		*r=malloc(sizeof(Tnode));
		(*r)->d=pre[pres];
		for(i=is; i<=ie; i++)
		{
			if(in[i]==pre[pres])
			{
				MK(in,is,i-1,pre,pres+1,pres+i-is,&(*r)->lchild);
				MK(in,i+1,ie,pre,pres+i-is+1,pree,&(*r)->rchild);
				break;
			}
			if(i>ie)
			{
				printf("输入错误!\n");
				exit(1);
			}
		}
	}
}
Exemplo n.º 2
0
Opt_serv_policy_opts *httpd_policy_make(Opt_serv_opts *beg)
{
  Opt_serv_policy_opts *opts = MK(sizeof(Httpd_policy_opts));
  Vstr_ref *ref = NULL;
  
  if (!opts)
    goto mk_opts_fail;

  if (!(ref = vstr_ref_make_ptr(opts, httpd_policy_free)))
    goto mk_ref_fail;
  opts->ref = ref;

  if (!httpd_policy_init((Httpd_opts *)beg, (Httpd_policy_opts *)opts))
    goto policy_init_fail;
  
  return (opts);

 policy_init_fail:
  ref->ptr = NULL;
  vstr_ref_del(ref);
 mk_ref_fail:
  F(opts);
 mk_opts_fail:
  return (NULL);
}
Exemplo n.º 3
0
void VP8InitBitReader(VP8BitReader* const br,
                      const uint8_t* const start, const uint8_t* const end) {
  assert(br != NULL);
  assert(start != NULL);
  assert(start <= end);
  br->range_   = MK(255 - 1);
  br->buf_     = start;
  br->buf_end_ = end;
  br->value_   = 0;
  br->bits_    = -8;   // to load the very first 8bits
  br->eof_     = 0;
}
Exemplo n.º 4
0
// Name: InsertItem
//
// Description: Inserts a new Node into the Binary Tree
//
// Arguments: root - Pointer to the root Node pointer
//            item - Data value to insert into the tree
//
void InsertItem(Node **root, int item){

    Node **tmp = root;

    while(*tmp){
        if( (*tmp)->data > item)
            tmp = (&(*tmp)->left);
        else 
            tmp = (&(*tmp)->right);
    }
    *tmp = MK(item);
}
Exemplo n.º 5
0
Arquivo: e26.cpp Projeto: cqiyi/kaoshi
void main()
{
	Tnode *r=NULL;
	char in[MAX],pre[MAX];
	printf("请输入前序序列:\n");
	gets(pre);
	printf("请输入中序序列:\n");
	gets(in);
	MK(in,0,strlen(in)-1,pre,0,strlen(pre)-1,&r);
	printf("\n后序遍历序列为:\n");
	postorder(r);
	printf("\n叶结点的个数为:%d\n",leaf(r));
	printf("\n高度为:%d\n",height(r));
}
Exemplo n.º 6
0
int mime_types_init(Mime_types *pmime,
                    const Vstr_base *def_vs1, size_t def_pos, size_t def_len)
{
  Mime_types_data *mime = NULL;
  
  ASSERT(pmime);
  ASSERT(def_vs1);

  if (!(pmime->ref = vstr_ref_make_malloc(sizeof(Mime_types_data))))
    goto ref_malloc_fail;
  mime = pmime->ref->ptr;

  if (!(mime->ent_data = vstr_make_base(NULL)))
    goto ent_data_malloc_fail;
  
  if (!(mime->ents = vstr_sects_make(MIME_TYPES__INIT_SECT_SZ)))
    goto ents_malloc_fail;

  if (!(mime->types = MK(MIME_TYPES__INIT_TYPE_SZ)))
    goto types_malloc_fail;

  mime->type_sz  = MIME_TYPES__INIT_TYPE_SZ;
  mime->type_num = 0;
  
  /* make reference do the right thing... */
  mime->pref_func  = pmime->ref->func;
  pmime->ref->func = mime_types__filedata_free;
  
  pmime->def_type_vs1 = def_vs1;
  pmime->def_type_pos = def_pos;
  pmime->def_type_len = def_len;
  
  return (TRUE);

 types_malloc_fail:
  vstr_sects_free(mime->ents);
 ents_malloc_fail:
  vstr_free_base(mime->ent_data);
 ent_data_malloc_fail:
  vstr_ref_del(pmime->ref);
 ref_malloc_fail:
  return (FALSE);
}
Exemplo n.º 7
0
static struct con *cl_make(const char *server_fname)
{
  struct con *ret = MK(sizeof(struct con));

  if (!ret)
    errno = ENOMEM, err(EXIT_FAILURE, "%s", __func__);
  if (!evnt_make_con_local(ret->ev, server_fname))
    err(EXIT_FAILURE, "%s", __func__);

  ret->ev->cbs->cb_func_connect = cl_cb_func_connect;
  ret->ev->cbs->cb_func_recv    = cl_cb_func_recv;
  ret->ev->cbs->cb_func_free    = cl_cb_func_free;
  
  ++server_clients_count;

  if (ret->ev->flag_q_none)
    cl_cb_func_connect(ret->ev);
  
  return (ret);
}
Exemplo n.º 8
0
void
backsumarena(Arena *arena)
{
	ASum *as;

	if(sumwait.l == nil)
		return;

	as = MK(ASum);
	if(as == nil)
		return;
	qlock(&sumlock);
	as->arena = arena;
	as->next = nil;
	if(sumq)
		sumqtail->next = as;
	else
		sumq = as;
	sumqtail = as;
	rwakeup(&sumwait);
	qunlock(&sumlock);
}
Exemplo n.º 9
0
const uint8_t kVP8Log2Range[128] = {
     7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  0
};

// range = (range << kVP8Log2Range[range]) + trailing 1's
const range_t kVP8NewRange[128] = {
  MK(127), MK(127), MK(191), MK(127), MK(159), MK(191), MK(223), MK(127),
  MK(143), MK(159), MK(175), MK(191), MK(207), MK(223), MK(239), MK(127),
  MK(135), MK(143), MK(151), MK(159), MK(167), MK(175), MK(183), MK(191),
  MK(199), MK(207), MK(215), MK(223), MK(231), MK(239), MK(247), MK(127),
  MK(131), MK(135), MK(139), MK(143), MK(147), MK(151), MK(155), MK(159),
  MK(163), MK(167), MK(171), MK(175), MK(179), MK(183), MK(187), MK(191),
  MK(195), MK(199), MK(203), MK(207), MK(211), MK(215), MK(219), MK(223),
  MK(227), MK(231), MK(235), MK(239), MK(243), MK(247), MK(251), MK(127),
  MK(129), MK(131), MK(133), MK(135), MK(137), MK(139), MK(141), MK(143),
  MK(145), MK(147), MK(149), MK(151), MK(153), MK(155), MK(157), MK(159),
  MK(161), MK(163), MK(165), MK(167), MK(169), MK(171), MK(173), MK(175),
  MK(177), MK(179), MK(181), MK(183), MK(185), MK(187), MK(189), MK(191),
  MK(193), MK(195), MK(197), MK(199), MK(201), MK(203), MK(205), MK(207),
  MK(209), MK(211), MK(213), MK(215), MK(217), MK(219), MK(221), MK(223),
  MK(225), MK(227), MK(229), MK(231), MK(233), MK(235), MK(237), MK(239),
  MK(241), MK(243), MK(245), MK(247), MK(249), MK(251), MK(253), MK(127)
Exemplo n.º 10
0
int cidisabled=0;
int allowUDLR=0;

#define MK(x)   {{BUTTC_KEYBOARD},{0},{MKK(x)},1}
#define MC(x)   {{BUTTC_KEYBOARD},{0},{x},1}
#define MK2(x1,x2)        {{BUTTC_KEYBOARD},{0},{MKK(x1),MKK(x2)},2}

#define MKZ()   {{0},{0},{0},0}

#define GPZ()   {MKZ(), MKZ(), MKZ(), MKZ()}

ButtConfig GamePadConfig[4][12]={
	//Gamepad 1
	{
		MK(F), MK(D), MK(S), MK(ENTER), MK(BL_CURSORUP),
			MK(BL_CURSORDOWN),MK(BL_CURSORLEFT),MK(BL_CURSORRIGHT)
	},

	//Gamepad 2
	GPZ(),

	//Gamepad 3
	GPZ(),

	//Gamepad 4
	GPZ()
};

ButtConfig GamePadPreset1[4][12]={GPZ(),GPZ(),GPZ(),GPZ()};
ButtConfig GamePadPreset2[4][12]={GPZ(),GPZ(),GPZ(),GPZ()};
Exemplo n.º 11
0
#endif
}

#define MK(x)   {{BUTTC_KEYBOARD},{0},{MKK(x)},1}					// Make key obj, 1 player?
#define MK2(x1,x2)	{{BUTTC_KEYBOARD},{0},{MKK(x1),MKK(x2)},2}		// Make key obj, 2 players?

#define MKZ()   {{0},{0},{0},0}

#define GPZ()   {MKZ(), MKZ(), MKZ(), MKZ()}

ButtConfig GamePadConfig[4][10]={
        /* Gamepad 1 */
        { 
//	MK(KP3), MK(KP2), MK(TAB), MK(ENTER), MK(W), MK(Z),
//				MK(A), MK(S), MKZ(), MKZ()
	MK(O), MK(P), MK(TAB), MK(ENTER), MK(W), MK(S),		// b, a, select, start, up, down, left, right, n/a, n/a
            MK(A), MK(D), MKZ(), MKZ()
//	MK(C), MK(D), MK(TAB), MK(ENTER), MK(CURSORUP), MK(CURSORDOWN),		// b, a, select, start, up, down, left, right, n/a, n/a
//			MK(CURSORLEFT), MK(CURSORRIGHT), MKZ(), MKZ()
	},

        /* Gamepad 2 */
        GPZ(),

        /* Gamepad 3 */
        GPZ(),
  
        /* Gamepad 4 */
        GPZ()
};
Exemplo n.º 12
0
	v->spritenum = 0;
	v->progress = 0;
}

struct BubbleMovement {
	int8 x:4;
	int8 y:4;
	int8 z:4;
	byte image:4;
};

#define MK(x, y, z, i) { x, y, z, i }
#define ME(i) { i, 4, 0, 0 }

static const BubbleMovement _bubble_float_sw[] = {
	MK(0, 0, 1, 0),
	MK(1, 0, 1, 1),
	MK(0, 0, 1, 0),
	MK(1, 0, 1, 2),
	ME(1)
};


static const BubbleMovement _bubble_float_ne[] = {
	MK( 0, 0, 1, 0),
	MK(-1, 0, 1, 1),
	MK( 0, 0, 1, 0),
	MK(-1, 0, 1, 2),
	ME(1)
};
Exemplo n.º 13
0
void input(FILE *fd, void (*cb)(struct message *), struct message *p)
{
	int c;

#define ST(X) do { p->status = (X); } while(0)
#define MK(X) do { p->X = p->p; } while(0)
#define RST() do { \
	ST(AT_BOM); \
	p->p = p->buffer; \
	p->sz = p->argc = 0; \
	p->org = p->cmd = NULL; \
} while (0)
#define ADDCH(X) do { \
	*p->p++ = X; p->sz++; \
	if (p->sz >= (sizeof p->buffer)-1) \
		RST(); \
} while (0)
#define ADDARG(s) do { \
	assert(p->argc < MAX_ARGS); \
	p->argv[p->argc] = s; \
	if (s) p->argc++; \
} while (0)

	RST();
	while ((c = fgetc(fd)) != EOF) {
		switch (p->status) {
		case AT_BOM:
			switch (c) {
			case ':': ST(IN_ORG); MK(org); break;
			case ' ': break; /* ignored */
			case '\r': ST(IN_EOL); break;
			case '\n': RST(); break;
			default: ST(IN_CMD); MK(cmd); ADDCH(c); break;
			} break;
		case IN_ORG:
			switch(c) {
			case ' ': ST(IN_SPC0); ADDCH(0); break;
			case '\r': ST(IN_EOL); ADDCH(0); break;
			case '\n': RST(); break;
			case ':': /* NO BREAK HERE, valid char */
			default: ADDCH(c); break;
			} break;
		case IN_SPC0:
			switch(c) {
			case ' ': break; /* ignore extra */
			case '\r': ST(IN_EOL); break;
			case '\n': RST(); break;
			default: ST(IN_CMD); MK(cmd); ADDCH(c); break;
			} break;
		case IN_CMD:
			switch(c) {
			case ' ': ST(IN_SPC1); ADDCH(0); break;
			case '\r': ST(IN_EOL); ADDCH(0); break;
			case '\n': ADDARG(NULL); cb(p); RST(); break;
			case ':': /* NO BREAK HERE, valid char */
			default: ADDCH(c); break;
			} break;
		case IN_SPC1:
			switch(c) {
			case ' ': break; /* ignore */
			case '\r': ST(IN_EOL); break;
			case '\n': ADDARG(NULL); cb(p); RST(); break;
			case ':': ST(IN_ARGN); ADDARG(p->p); break;
			default: ST(IN_ARG); ADDARG(p->p); ADDCH(c); break;
			} break;
		case IN_ARG:
			switch (c) {
			case ' ': ST(IN_SPC1); ADDCH(0); break;
			case '\r': ST(IN_EOL); ADDCH(0); break;
			case '\n': ADDARG(NULL); cb(p); RST(); break;
			case ':':
			default: ADDCH(c); break;
			} break;
		case IN_ARGN:
			switch (c) {
			case '\r': ST(IN_EOL); ADDCH(0); break;
			case '\n': ADDARG(NULL); cb(p); RST(); break;
			default: ADDCH(c); break;
			} break;
		case IN_EOL:
			switch (c) {
			case '\r': break;
			case '\n': ADDARG(NULL); cb(p); RST(); break;
			case ':': RST(); ST(IN_ORG); break;
			default: RST(); break;
			} break;
		} /* switch */
	} /* while */
} /* input */
#define AC_NO_AE KC_QUOT
#define AC_NO_OE KC_SCLN
#define AC_NO_LT KC_NONUS_BSLASH
#define AC_NO_PLUS KC_MINS
#define AC_NO_BSLS KC_EQUAL
#define AC_NO_QUOTE KC_BSLS
#define AC_NO_MINS KC_SLSH
#define AC_NO_PIPE KC_GRAVE


const uint16_t PROGMEM actionmaps[][MATRIX_ROWS][MATRIX_COLS] = {
  KEYMAP( /* 0: mostly letters */
    Q,   W,         E,         R,         T,   					   /*|,, |*/         Y,              U,         I,   	          O,    P,    \
    A,   S,         D,         F,         G,   					   /*|,, |*/         H,              J,         K,   	          L,    COMM, \
		Z,   X,         C,         V,         B,               /*|,, |*/         N,              M,         COMM,           DOT,  KP_SLASH, \
    ESC, TAPT(3),   OSM(LGUI), OSM(LSFT), MK(LCTL,BSPC), TAPT(1), TAPT(2),   MK(LALT,SPC),   TACK(TAB), TACSK(SLSH), SH(2), ENT
  ),
  KEYMAP( /* layer one is mostly for programming and shell. lots of idea shortcute on left, not sure how much i will use them.*/
    ACK(7),  CTRL(W),    NO_AE,      SH(F10),     ACSK(L),                     SH(NO_ACNT), RA(7), RA(0), NO_OE,   SH(1), \
    NO_AA,   ACK(LEFT),  CSK(ENT),   ACK(RIGHT),  ALT(INS),                    0,           SH(8), SH(9), NO_PIPE, RA(4), \
    CSK(A),  CSK(F),     ACSK(T),    ALT(V),      CTRL(F9),                    SH(NO_BSLS), RA(8), RA(9), SH(6),   RA(NO_ACNT), \
    ESC,     TRNS,       OSM(LGUI),  OSM(LSFT),   TRNS,    TRNS,    TRNS,      SPC,         OFF(1),RA(2), NO_QUOTE,KP_EQUAL
  ),
  KEYMAP( /* hold space brings up move pad and numpad */
    INS,      HOME,   UP  ,      END  ,     PGUP,                          SH(5),         7     , 8  , 9, SH(NO_QUOTE),     \
    DEL,      LEFT,   DOWN,      RIGHT,     PGDN,                          NO_MINS,       4     , 5  , 6, NO_PLUS, \
    GUI(1),   GUI(2), GUI(3),    GUI(4),    GUI(5),                        RA(4),         1     , 2  , 3, NO_BSLS,      \
    ACK(DEL), TRNS, OSM(LGUI), OSM(LSFT),   GUI(D) , TRNS, TRNS,           MK(LALT,SPC),  OFF(1), DOT, 0, KP_EQUAL
  ),
  KEYMAP( /* hold tab to have fpad and mouse */
    F1,     F2,    F3,        F4,         F5,                             WH_D ,           BTN1   ,  MS_U ,         BTN2 ,      SH(3) , \
Exemplo n.º 15
0
 * mips_cause2sig_map:
 *
 * Maps an MIPS Cause code to a signal number.
 * The first 32 define the actual EXCODE of the
 * cause registers. Values >= 32 are extended
 * cause code to cover exceptions other than
 * general exceptions.
 */

#define MK(signo,code,fault)		MAKE_SIGCODE(SIG##signo,signo##_##code,FLT##fault)

#define BAD(cause)	MAKE_SIGCODE(SIGKILL,0,64+cause)

MIPS_CAUSE2SIGMAP_CONST unsigned long __mips_cause2sig_map[] = {
    BAD(0),						/* 00 - CAUSE_INTERRUPT                 */
    MK(SEGV,ACCERR,ACCESS)|SIGCODE_STORE,/* 01 - CAUSE_TLB_MOD           */
    MK(SEGV,MAPERR,BOUNDS),		/* 02 - CAUSE_TLB_LOAD                  */
    MK(SEGV,MAPERR,BOUNDS)|SIGCODE_STORE,	/* 03 - CAUSE_TLB_SAVE      */
    MK(BUS,ADRALN,ACCESS),		/* 04 - CAUSE_ADDR_LOAD                 */
    MK(BUS,ADRALN,ACCESS)|SIGCODE_STORE,/* 05 - CAUSE_ADDR_SAVE         */
    MK(BUS,ADRERR,BOUNDS),		/* 06 - CAUSE_BUS_INSTR                 */
    MK(BUS,ADRERR,BOUNDS),		/* 07 - CAUSE_BUS_DATA                  */
    BAD(8),						/* 08 - CAUSE_SYSCALL                   */
    MK(TRAP,BRKPT,BPT),			/* 09 - CAUSE_BP                        */
    MK(ILL,ILLOPC,ILL),			/* 10 - CAUSE_ILLOP                     */
    MK(ILL,PRVOPC,PRIV),		/* 11 - CAUSE_CP_UNUSABLE               */
    MK(FPE,INTOVF,IOVF),		/* 12 - CAUSE_OVFLW                     */
    MK(FPE,INTOVF,IOVF), 		/* 13 - CAUSE_TRAP                      */
    BAD(14),    				/* 14 - CAUSE_VIRT_COHERENCY_INSTR      */
    MK(FPE,NOFPU,FPE), 			/* 15 - CAUSE_FPE                       */
    BAD(16),    				/* 16 - Reserved, should never happen   */