Exemplo n.º 1
0
/**
 * 算法2.21
 */
Status MergeList(LinkList &La, LinkList &Lb, LinkList &Lc, 
				int (*compare)(ElemType, ElemType))
{
	Link ha, hb, pa, pb, q;
	ElemType a, b;
	if (!InitList(Lc))
		return ERROR;
	ha = GetHead(La);
	hb = GetHead(Lb);
	pa = NextPos(La, ha);
	pb = NextPos(Lb, hb);
	while (pa && pb) {
		a = GetCurElem(pa);
		b = GetCurElem(pb);
		if (compare(a, b) <= 0) {   // a<=b
			DelFirst(ha, q);
			Append(Lc, q);
			pa = NextPos(La, ha);
		} else {    // a>b
			DelFirst(hb, q);
			Append(Lc, q);
			pb = NextPos(Lb, hb);
		}   
	} // while
	if (pa)
		Append(Lc, pa);
	else
		Append(Lc, pb);
	FreeNode(ha);
	FreeNode(hb);
	return OK;
}
Exemplo n.º 2
0
Status MazePath(MazeType maze[][N],Postype start,Postype end) {
    SqStack S;
    SElemType_Sq nodeInf;      // 当前通道的信息
    Postype curPos;            // 当前位置
    int curStep;               // 当前通道的序号

    InitList_Sq(&S);

    curPos = start;
    curStep = 1;

    do {
        if (Pass(curPos,maze)) {    // 当前位置可通过?
            FootPrint(curPos,maze); //留下足迹
            ShowMaze(maze);

            SetSElemType(&nodeInf,curStep,curPos,East); // 设置当前位置的属性

            Push_sq(&S,nodeInf); // 加入栈

            if (EqualPosType(curPos,end)) { // 如果到终点
                printf("\n 寻路成功!!\n\n");
                return TRUE;
            }

            curPos = NextPos(curPos,East); // 设置下一个为东
            curStep++; // 探索下一块
        } else {
            if (!StackEmpty_Sq(S)) {// 如果没有倒退到原点
                Pop_Sq(&S,&nodeInf);
                while (nodeInf.di == North && !StackEmpty_Sq(S)) {
                    MarkPrint(nodeInf.seat,maze);    // 四个方向都遍历过,就回退一步
                    ShowMaze(maze);
                    Pop_Sq(&S,&nodeInf);
                }

                if (nodeInf.di < North) {
                    maze[nodeInf.seat.x][nodeInf.seat.y] = ++nodeInf.di;
                    ShowMaze(maze);
                    Push_sq(&S,nodeInf);
                    curPos = NextPos(nodeInf.seat,nodeInf.di);
                }
            }
        }
    } while (!StackEmpty_Sq(S));

    printf("\n 寻路失败!!\n\n");
    return FALSE;

}
Exemplo n.º 3
0
void CNewTexWnd::EnsureTextureIsVisible(const char *name) {
	// scroll origin so the texture is completely on screen
	// init stuff
	current.x = 8;
	current.y = -8;
	currentRow = 0;
	currentIndex = 0;

	while (1) {
		const idMaterial *mat = NextPos();
		if (mat == NULL) {
			break;
		}

		int width = mat->GetEditorImage()->uploadWidth * ((float)g_PrefsDlg.m_nTextureScale / 100);
		int height = mat->GetEditorImage()->uploadHeight * ((float)g_PrefsDlg.m_nTextureScale / 100);

		if ( !idStr::Icmp(name, mat->GetName()) ) {
			if (current.y > origin.y) {
				origin.y = current.y;
				Sys_UpdateWindows(W_TEXTURE);
				return;
			}

			if (current.y - height - 2 * FONT_HEIGHT < origin.y - rectClient.Height()) {
				origin.y = current.y - height - 2 * FONT_HEIGHT + rectClient.Height();
				Sys_UpdateWindows(W_TEXTURE);
				return;
			}

			return;
		}
	}

}
Exemplo n.º 4
0
const idMaterial *CNewTexWnd::getMaterialAtPoint(CPoint point) {

	// init stuff
	int my = rectClient.Height() - 1 - point.y;
	my += origin.y - rectClient.Height();

	current.x = 8;
	current.y = -8;
	currentRow = 0;
	currentIndex = 0;

	while (1) {
		const idMaterial *mat = NextPos();
		if (mat == NULL) {
			return NULL;
		}

		int width = mat->GetEditorImage()->uploadWidth * ((float)g_PrefsDlg.m_nTextureScale / 100);
		int height = mat->GetEditorImage()->uploadHeight * ((float)g_PrefsDlg.m_nTextureScale / 100);
		//if (point.x > draw.x && point.x - draw.x < width && my < draw.y && my + draw.y < height + FONT_HEIGHT) {
		if (point.x > draw.x && point.x - draw.x < width && my < draw.y &&  draw.y - my < height + FONT_HEIGHT) {
			return mat;
		}
	
	}

}
Exemplo n.º 5
0
void setmap()
{
    int a[8];
    int i,j,k,m,min,s,h;
    struct around n1,n2;

    for(i=0; i<N; i++){
        for (j=0; j<N; j++) {
            for (h=0; h<8; h++) {
                n2.x = i;
                n2.y = j;
                n1 = NextPos(n2,h+1);
                if((n1.x>=0) && (n1.x<N) && (n1.y>=0) && (n1.y<N)) {
                    a[h] = weight[n1.x][n1.y];
                }
                else a[h]=0;
            }
            for (m=0; m<8; m++) {
                min = 9;
                for (k=0; k<8; k++) {
                    if(min > a[k]) {
                        min = a[k];
                        borad[i][j][m] = k;
                        s = k; 
                    }
                }
                a[s] = 9;
            }
        }
    }
}
Exemplo n.º 6
0
 Status MazePath(PosType start,PosType end) /* 算法3.3 */
 { /* 若迷宫maze中存在从入口start到出口end的通道,则求得一条 */
   /* 存放在栈中(从栈底到栈顶),并返回TRUE;否则返回FALSE */
   SqStack S;
   PosType curpos;
   SElemType e;
   InitStack(&S);
   curpos=start;
   do
   {
     if(Pass(curpos))
     { /* 当前位置可以通过,即是未曾走到过的通道块 */
       FootPrint(curpos); /* 留下足迹 */
       e.ord=curstep;
       e.seat.x=curpos.x;
       e.seat.y=curpos.y;
       e.di=0;
       Push(&S,e); /* 入栈当前位置及状态 */
       curstep++; /* 足迹加1 */
       if(curpos.x==end.x&&curpos.y==end.y) /* 到达终点(出口) */
         return TRUE;
       curpos=NextPos(curpos,e.di);
     }
     else
     { /* 当前位置不能通过 */
       if(!StackEmpty(S))
       {
         Pop(&S,&e); /* 退栈到前一位置 */
         curstep--;
         while(e.di==3&&!StackEmpty(S)) /* 前一位置处于最后一个方向(北) */
         {
           MarkPrint(e.seat); /* 留下不能通过的标记(-1) */
           Pop(&S,&e); /* 退回一步 */
           curstep--;
         }
         if(e.di<3) /* 没到最后一个方向(北) */
         {
           e.di++; /* 换下一个方向探索 */
           Push(&S,e);
           curstep++;
           curpos=NextPos(e.seat,e.di); /* 设定当前位置是该新方向上的相邻块 */
         }
       }
     }
   }while(!StackEmpty(S));
   return FALSE;
 }
Exemplo n.º 7
0
Hint VAM_MAZE_PATH(int mg[][MCOL], PosType start, PosType end, SqStack *s) {
  PosType curpos;
  int Status;

  SElemType Static_Stack[20]; // 20 is the MAX depth of stack. Change later if need.
  Status = InitStack(s, Static_Stack);
  if (Status != SUCCESS) {putnum(0xdead000C); return FAILURE;}
  SElemType e;
  int curstep;

  curpos  = start;  // Set the start as the current step
  curstep = 0;    // Step Counter

  do {
    // If the current pos can be passed
    if (Pass(mg, curpos)) {
      //Leave Foot Print
      FootPrint(mg, curpos, MAZE_PASSED);
      e.di   = 1; // Direction
      e.ord  = curstep;
      e.seat = curpos;
      Push(s,e); // Push to stack
      if (curpos.x == end.x && curpos.y == end.y) {
        // Touch Down! Reach the Des
        return SUCCESS;
      }
      curpos = NextPos(&curpos, 1);
      curstep++;
    }
    else {
      if (!StackEmpty(s)) {
        Pop(s, &e);
        while (e.di == 4 && !StackEmpty(s)) {
          FootPrint(mg, e.seat, MAZE_BLOACKED);
          Pop(s, &e);
        }
        if (e.di < 4) {
          e.di++;
          Push(s, e);
          curpos = NextPos(&e.seat, e.di);
        }
      }
    }
  }while (!StackEmpty(s));
  return FAILURE;
}
Exemplo n.º 8
0
int HorsePath(struct around start)
{
    struct around curpos;
    int horsestep=0, off;
    struct zhan elem;
    int i;

    curpos = start;
    do{
        i++;
        if(Pass(curpos)) {
            horsestep++;
            elem.di = 0;
            elem.ord = horsestep;
            elem.seat = curpos;
            Push(elem);
            if(N*N == horsestep) {
                printf("%d\n",i);
                return 1;
            }
            off = borad[elem.seat.x][elem.seat.y][elem.di]+1;
            curpos = NextPos(elem.seat, off);
        }
        else {
            if(s.top) {
                while(s.top && elem.di == 8){
                    Pop(&elem);
                    if(s.top) {
                        elem = GetTop();
                        horsestep = elem.ord;
                    }
                }
                if(s.top && elem.di < 8) {
                    Pop(&elem);
                    off = borad[elem.seat.x][elem.seat.y][++elem.di];
                    curpos = NextPos(elem.seat, off+1);
                    Push(elem);
                }
            }
        }
    }while(s.top != 0);
    printf("no way\n");
    exit(0);
}
Status	MergeLinkList(LinkList	*La,
					  LinkList	*Lb,
					  LinkList	*Lc,
					  int		(*compare)(ElemType, ElemType))
/* 已知单链表La和Lb的元素按值非递减排列
 * 归并La和Lb得到新的单链表Lc, Lc的元素也按值非递减排列.
 */
{
	Link pNode_La = La->head, ha = GetHead(*La),
		 pNode_Lb = Lb->head, hb = GetHead(*Lb);
	int  iLen_La  = La->len,  iLen_Lb  = Lb->len;
	ElemType a = 0, b = 0;
	Link pTemp = NULL;

	if (!InitList(Lc))	// Initialize link list Lc.
		return ERROR;
	while (pNode_La && pNode_Lb)
	{
		a = GetCurElem(pNode_La);
		b = GetCurElem(pNode_Lb);
		if (0 >= (*compare)(a, b))
		{
			DelFirst(&ha, &pTemp);
			Append(Lc, pTemp);
			pNode_La = NextPos(*La, ha);
		}
		else
		{
			DelFirst(&hb, &pTemp);
			Append(Lc, pTemp);
			pNode_Lb = NextPos(*Lb, hb);
		}
	}
	if (pNode_La)
		Append(Lc, pNode_La);
	else
		Append(Lc, pNode_Lb);

	FreeNode(&ha);
	FreeNode(&hb);
	return OK;
}
Exemplo n.º 10
0
static void MakeOddSquare (IntMatrix &M, int offset, int n, int srow, int scol)
{
  int count = offset, 
      row   = 0, 
      col   = (n - 1) / 2;

  for (int i = 0; i < n*n; ++i) {
    M(row+srow, col+scol) = count;
    NextPos(row, col, count, n);
    count++;
  }
}
Exemplo n.º 11
0
/*
* @description:求解迷宫路径
*/
Status MazePath(MazeType maze,SqStack *S,PosType start,PosType end) {
	PosType curpos;
	int curstep;
	SElemType elem;

	InitStack(S);
	curpos = start;
	curstep = 1;
		
	do {
		if(Pass(&maze,curpos)) {
			FootPrint(&maze,curpos);
			elem = SetElem(curpos,curstep,1);
			Push(S,elem);
			if(curpos.x == end.x && curpos.y == end.y )
				return TRUE;
			curpos = NextPos(curpos,1);
			curstep++;
		}
		else {
			if(!StackEmpty(*S)) {
				Pop(S,&elem);
				//这种情况是:东南西已经
				while(elem.di == 4 && !StackEmpty(*S)) {
					MarkPrint(&maze,elem.seat);  //此路不通,做标记
					Pop(S,&elem);
				}

				if(elem.di < 4) {
					//按东南西北的方向调整探测
					elem.di++;
					Push(S,elem);
					curpos = NextPos(elem.seat,elem.di);
				}
			}
		}
	}while(!StackEmpty(*S));
	
	return FALSE;
}
Exemplo n.º 12
0
Status MazePath(MazeType &maze,PostType start,PostType end){
    //迷宫maze存在从入口start到end的通道则求得一条存放在栈中
    Stack S;
    PostType curpos;
    int curstep;//当前序号,1.2.3.4分别表示东,南,西,北方向
    SElemType e;
    InitStack(S);
    curpos=start; //设置"当前位置"为"入口位置"
    curstep=1;   //探索第一步
    do{   
        if(Pass(maze,curpos)){     //当前位置可以通过,
            FootPrint(maze,curpos);//留下足迹
            e.ord=curstep;
            e.seat=curpos;
            e.di=1;
            Push(S,e);              //加入路径
            if(curpos.r==end.r&& curpos.c==end.c)
                return TRUE; //到达出口             
            curpos=NextPos(curpos,1); //下一位置是当前位置的东邻
            curstep++;       //探索下一步                            
        }
        else{        //当前位置不通
            if(!StackEmpty(S)){        
                Pop(S,e);
                while(e.di==4 && !StackEmpty(S)){
                    MarkPrint(maze,e.seat);
                    Pop(S,e);         //留下不能通过的标记,并退一步
                }//while
                if(e.di < 4){
                    e.di++;//换下一个方向探索
                    Push(S,e);            
                    curpos=NextPos(e.seat,e.di);//设定当前位置是该新方向上的相邻
                }
            }
        }
    }while(!StackEmpty(S));
    return OK;
}//MazePath
Exemplo n.º 13
0
void setweight()
{
    int i,j,k;
    struct around m;
    struct zhan elem;
    for (i=0; i<N; i++) {
        for (j=0; j<N; j++) {
            elem.seat.x = i;
            elem.seat.y = j;
            weight[i][j] = 0;
            for(k=0; k<8; k++) {
                m=NextPos(elem.seat,k+1);
                if(m.x>=0 && m.x<N && m.y>=0 && m.y<N){
                    weight[i][j]++;
                }
            }
        }
    }
}
Exemplo n.º 14
0
/*
 =======================================================================================================================
 =======================================================================================================================
 */
void CNewTexWnd::OnPaint() {

	CPaintDC	dc(this);	// device context for painting

	int nOld = g_qeglobals.d_texturewin.m_nTotalHeight;

	//hdcTexture = GetDC();
	if (!qwglMakeCurrent(dc.GetSafeHdc(), win32.hGLRC)) {
		common->Printf("ERROR: wglMakeCurrent failed..\n ");
	}
	else {
		const char	*name;
		qglClearColor
		(
			g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][0],
			g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][1],
			g_qeglobals.d_savedinfo.colors[COLOR_TEXTUREBACK][2],
			0
		);
		qglViewport(0, 0, rectClient.Width(), rectClient.Height());
		qglScissor(0, 0, rectClient.Width(), rectClient.Height());
		qglMatrixMode(GL_PROJECTION);
		qglLoadIdentity();
		qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		qglDisable(GL_DEPTH_TEST);
		qglDisable(GL_BLEND);
		qglOrtho(0, rectClient.Width(), origin.y - rectClient.Height(), origin.y, -100, 100);
		qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

		// init stuff
		current.x = 8;
		current.y = -8;
		currentRow = 0;
		currentIndex = 0;
		while (1) {
			const idMaterial *mat = NextPos();
			if (mat == NULL) {
				break;
			}

			int width = mat->GetEditorImage()->uploadWidth * ((float)g_PrefsDlg.m_nTextureScale / 100);
			int height = mat->GetEditorImage()->uploadHeight * ((float)g_PrefsDlg.m_nTextureScale / 100);

			// Is this texture visible?
			if ((draw.y - height - FONT_HEIGHT < origin.y) && (draw.y > origin.y - rectClient.Height())) {
				// if in use, draw a background
				qglLineWidth(1);
				qglColor3f(1, 1, 1);
				globalImages->BindNull();
				qglBegin(GL_LINE_LOOP);
				qglVertex2f(draw.x - 1, draw.y + 1 - FONT_HEIGHT);
				qglVertex2f(draw.x - 1, draw.y - height - 1 - FONT_HEIGHT);
				qglVertex2f(draw.x + 1 + width, draw.y - height - 1 - FONT_HEIGHT);
				qglVertex2f(draw.x + 1 + width, draw.y + 1 - FONT_HEIGHT);
				qglEnd();

				// Draw the texture
				float	fScale = (g_PrefsDlg.m_bHiColorTextures == TRUE) ? ((float)g_PrefsDlg.m_nTextureScale / 100) : 1.0;

				mat->GetEditorImage()->Bind();
				QE_CheckOpenGLForErrors();
				qglColor3f(1, 1, 1);
				qglBegin(GL_QUADS);
				qglTexCoord2f(0, 0);
				qglVertex2f(draw.x, draw.y - FONT_HEIGHT);
				qglTexCoord2f(1, 0);
				qglVertex2f(draw.x + width, draw.y - FONT_HEIGHT);
				qglTexCoord2f(1, 1);
				qglVertex2f(draw.x + width, draw.y - FONT_HEIGHT - height);
				qglTexCoord2f(0, 1);
				qglVertex2f(draw.x, draw.y - FONT_HEIGHT - height);
				qglEnd();

				// draw the selection border
				if ( !idStr::Icmp(g_qeglobals.d_texturewin.texdef.name, mat->GetName()) ) {
					qglLineWidth(3);
					qglColor3f(1, 0, 0);
					globalImages->BindNull();

					qglBegin(GL_LINE_LOOP);
					qglVertex2f(draw.x - 4, draw.y - FONT_HEIGHT + 4);
					qglVertex2f(draw.x - 4, draw.y - FONT_HEIGHT - height - 4);
					qglVertex2f(draw.x + 4 + width, draw.y - FONT_HEIGHT - height - 4);
					qglVertex2f(draw.x + 4 + width, draw.y - FONT_HEIGHT + 4);
					qglEnd();

					qglLineWidth(1);
				}

				// draw the texture name
				globalImages->BindNull();
				qglColor3f(1, 1, 1);
				qglRasterPos2f(draw.x, draw.y - FONT_HEIGHT + 2);

				// don't draw the directory name
				for (name = mat->GetName(); *name && *name != '/' && *name != '\\'; name++) {
					;
				}

				if (!*name) {
					name = mat->GetName();
				}
				else {
					name++;
				}
				qglCallLists(strlen(name), GL_UNSIGNED_BYTE, name);
				//qglCallLists(va("%s -- %d, %d" strlen(name), GL_UNSIGNED_BYTE, name);
			} 
		}

		g_qeglobals.d_texturewin.m_nTotalHeight = abs(draw.y) + 100;

		// reset the current texture
		globalImages->BindNull();
		qglFinish();
		qwglSwapBuffers(dc.GetSafeHdc());
		TRACE("Texture Paint\n");
	}

	if (g_PrefsDlg.m_bTextureScrollbar && (m_bNeedRange || g_qeglobals.d_texturewin.m_nTotalHeight != nOld)) {
		m_bNeedRange = false;
		SetScrollRange(SB_VERT, 0, g_qeglobals.d_texturewin.m_nTotalHeight, TRUE);
	}

	//ReleaseDC(hdcTexture);
}
Exemplo n.º 15
0
void CSceneKing::DoDraw(Context32* dst)
{

    //dst->fill(Color32(0,0,0));
    dst->darkle(1<<6);

    const int     sCountCr=300;   //圆上 初始点数目 
    const int     sCountLine=300; //直线上 初始点数目
    const int     sIteratCount=m_DrawCount/(sCountCr+sCountLine);// 每个初始点迭代的次数

    const double     scrLeft  =-2.2;   //屏幕映射参数
    const double     scrRight = 2.2;
    const double     scrTop   =-2.2;
    const double     scrButtom= 2.2;

    const CColorMover& ColorMover=m_ColorMoverList[0];

    const double vmapp_x=dst->width*(1.0/(scrRight-scrLeft));
    const double vmapp_y=dst->height*(1.0/(scrButtom-scrTop));
    for (int i=0;i<(sCountCr+sCountLine);i++)
    {
        double sx0,sy0;
        /*if (i<sCountCr)
        {
            const double  PI=3.1415926535897932384626433832795;
            double seta=i*(PI*2/sCountCr);
            sx0=sin(seta);
            sy0=cos(seta);
        }
        else
        {
            sx0=(i-sCountCr)*(2.0/sCountLine)+0.00-1;
            sy0=(i-sCountCr)*(2.0/sCountLine)+0.05-1;
        }*/
        sx0=rand()*(1.0/RAND_MAX )*(scrRight-scrLeft)+scrLeft;
        sy0=rand()*(1.0/RAND_MAX )*(scrButtom-scrTop)+scrTop;
        
        const long csSkipCount=15;
        for (int skip=0;skip<csSkipCount;skip++)
        {
            double sxn;
            double syn;
            NextPos(sx0,sy0,sxn,syn);
            sx0=sxn;
            sy0=syn;
        }
        for (int j=0;j<sIteratCount;j++)
        {
            double sxn;
            double syn;
            NextPos(sx0,sy0,sxn,syn);

            long px=(long)(vmapp_x*(sxn-scrLeft));
            long py=(long)(vmapp_y*(syn-scrTop));

            if ((px>=0)&&(py>=0)&&(px<dst->width)&&(py<dst->height))
            {
                double dx=(sxn-sx0);
                double dy=(syn-sy0);
                dst->Pixels(px,py)=Color32(ColorMover.getR8(dx),ColorMover.getG8(dy),ColorMover.getB8(dx+dy));
            }
            sx0=sxn;
            sy0=syn;
        }
    }


}
Exemplo n.º 16
0
JoinConvert& JoinConvert::Add() {
	Add(NextPos());
	return *this;
}
Exemplo n.º 17
0
JoinConvert& JoinConvert::Add(const Convert& cv) {
	Add(NextPos(), cv);
	return *this;
}
Exemplo n.º 18
0
void SetCode(int code)
{
	if(format[epos]==NUM)
	{
		hex=0;
		cpos=code;
		kpos=0;
		estr[epos]=kcod[cpos][kpos];
		NextPos();
	}
	else
	{
		if(format[epos]==HEX)
		{
			hex=1;
			if(strlen(hcod[code])>1)
			{
				if(!first)
				{
				 	if(cpos==code)
					{
						if(++kpos>=strlen(hcod[cpos]))
						{
							kpos=0;
						}
					}
					else
					{
						NextPos();
						cpos=code;
						kpos=0;
						first=0;
					}
					estr[epos]=hcod[cpos][kpos];
				}
				else
				{
					cpos=code;
					kpos=0;
					estr[epos]=hcod[cpos][kpos];
					first=0;
				}
			}
			else
			{
				cpos=code;
				kpos=0;
				estr[epos]=hcod[cpos][kpos];
				NextPos();
			}
		}
		else
		{
			hex=0;
			if(!first)
			{
			 	if(cpos==code)
				{
					if(++kpos>=strlen(kcod[cpos]))
					{
						kpos=0;
					}
				}
				else
				{
					NextPos();
					cpos=code;
					kpos=1;
					first=0;
				}
				estr[epos]=kcod[cpos][kpos];
			}
			else
			{
				cpos=code;
				kpos=1;
				estr[epos]=kcod[cpos][kpos];
				first=0;
			}
		}
	}
}
Exemplo n.º 19
0
int LookupStringInFixedSet(const unsigned char* graph,
	size_t length,
	const char* key,
	size_t key_length)
{
	const unsigned char* pos = graph;
	const unsigned char* end = graph + length;
	const unsigned char* offset = pos;
	const char* key_end = key + key_length;
	const char* multibyte_start = 0;

	while (GetNextOffset(&pos, end, &offset)) {
		/*char <char>+ end_char offsets
		 * char <char>+ return value
		 * char end_char offsets
		 * char return value
		 * end_char offsets
		 * return_value
		 */
		int did_consume = 0;

		if (key != key_end && !IsEOL(offset, end)) {
			/* Leading <char> is not a match. Don't dive into this child */
			if (!IsMatch(offset, end, key, multibyte_start))
				continue;
			did_consume = 1;
			NextPos(&offset, &key, &multibyte_start);
			/* Possible matches at this point:
			 * <char>+ end_char offsets
			 * <char>+ return value
			 * end_char offsets
			 * return value
			 */

			/* Remove all remaining <char> nodes possible */
			while (!IsEOL(offset, end) && key != key_end) {
				if (!IsMatch(offset, end, key, multibyte_start))
					return -1;
				NextPos(&offset, &key, &multibyte_start);
			}
		}
		/* Possible matches at this point:
		 * end_char offsets
		 * return_value
		 * If one or more <char> elements were consumed, a failure
		 * to match is terminal. Otherwise, try the next node.
		 */
		if (key == key_end) {
			int return_value;

			if (GetReturnValue(offset, end, multibyte_start, &return_value))
				return return_value;
			/* The DAFSA guarantees that if the first char is a match, all
			 * remaining char elements MUST match if the key is truly present.
			 */
			if (did_consume)
				return -1;
			continue;
		}
		if (!IsEndCharMatch(offset, end, key, multibyte_start)) {
			if (did_consume)
				return -1; /* Unexpected */
			continue;
		}
		NextPos(&offset, &key, &multibyte_start);
		pos = offset; /* Dive into child */
	}

	return -1; /* No match */
}
Exemplo n.º 20
0
char *inputd(char *form, char *title, char *defstr, int keys, int frame, int mask, int bhelp, int cols, int tmo, int debounce)
{
int exs,eys,wxs,wxw,wys,wyw,i,j,xp,yp;
char trnd[2]={0,0},tch;
int act_key=-1, last_key=-1, b_key=-1, run=1, ipos=0;
time_t t1,t2,tm1;
char knum[12][2]={"1","2","3","4","5","6","7","8","9"," ","0"};
char kalp[12][5]={"+-*/","abcä","def","ghi","jkl","mnoö","pqrs","tuvü","wxyz","","_,.;"};

	epos=-1;
	cpos=0;
	kpos=0;
	first=1;
	time(&tm1);
	if(cols>25)
	{
		cols=25;
	}
	if(cols<1)
	{
		cols=1;
	}
	format=form;
	estr=strdup(form);
	cnt=strlen(form);
	
	RenderString("X", 310, 250, 20, LEFT, BIG, CMC);
	i=GetStringLen(title)+10;
	j=((cnt>cols)?cols:cnt)*exsz;
	if(j>i)
	{
		i=j;
	}
	if(keys)
	{
		j=3*bxsz;
		if(j>i)
		{
			i=j;
		}
	}
	wxw=i+2*xbrd;

	i=(((cnt-1)/cols)+1)*eysz;
	if(keys)
	{
		i+=4*bysz;
	}
	wyw=((keys)?4:2)*ybrd+i;

	wxs=((ex-sx)-wxw)/2;
	wys=(((ey-sy)-wyw)+hsz)/2;
	exs=wxs+(wxw-((cnt>cols)?cols:cnt)*exsz)/2;
	eys=wys+ybrd;

	*estr=0;
	*rstr=0;
		
	j=0;
	for(i=0; i<strlen(format); i++)
	{
		tch=format[i];
		if(IsInput(tch))
		{
			if(epos==-1)
			{
				epos=i;
			}
			if(defstr && j<strlen(defstr))
			{
				estr[i]=defstr[j++];
			}
			else
			{
				estr[i]=' ';
			}
		}
		else
		{
			estr[i]=format[i];
		}
	}
	estr[i]=0;

	RenderBox(wxs-2, wys-hsz-2, wxs+wxw+2, wys+wyw+2, radius, CMH);
	RenderBox(wxs, wys-hsz, wxs+wxw, wys+wyw, radius, CMC);
	RenderBox(wxs, wys-hsz, wxs+wxw, wys, radius, CMH);
	RenderString(title, wxs, wys-15, wxw, CENTER, BIG, CMHT);
	if(keys)
	{
		int bxs=wxs+(wxw-(3*bxsz))/2;
		int bys=((wys+wyw)-2*ybrd)-4*bysz;
		
		for(i=0; i<11; i++)
		{
			if(i!=9)
			{
				RenderBox(bxs+(i%3)*bxsz, bys+(i/3)*bysz, bxs+((i%3)+1)*bxsz, bys+((i/3)+1)*bysz, radius, COL_MENUCONTENT_PLUS_4);
				RenderBox(bxs+(i%3)*bxsz+2, bys+(i/3)*bysz+2, bxs+((i%3)+1)*bxsz-2, bys+((i/3)+1)*bysz-2, radius, CMC);
				RenderString(knum[i], bxs+(i%3)*bxsz, bys+(i/3)*bysz+bysz/2, bxsz, CENTER, MED, CMCIT);
				RenderString(kalp[i], bxs+(i%3)*bxsz, bys+(i/3)*bysz+bysz-8, bxsz, CENTER, SMALL, CMCIT);
				
			}
		}	
		RenderCircle(bxs,wys+wyw-ybrd-8,'R');
		RenderString("Groß/Klein",bxs+15,wys+wyw-ybrd+5,3*bxsz,LEFT,SMALL,CMCIT);
		RenderCircle(bxs+3*bxsz-GetStringLen("löschen")-15,wys+wyw-ybrd-8,'Y');
		RenderString("löschen",bxs,wys+wyw-ybrd+5,3*bxsz,RIGHT,SMALL,CMCIT);
	}
	
	while(run)
	{
		for(i=0; i<cnt; i++)
		{
			xp=i%cols;
			yp=i/cols;
			if(frame && IsInput(format[i]))
			{
				RenderBox(exs+xp*exsz, eys+5+yp*eysz, exs+(xp+1)*exsz, eys+(yp+1)*eysz, radius, COL_MENUCONTENT_PLUS_4);
			}
			RenderBox(exs+xp*exsz+1, eys+5+yp*eysz+1, exs+(xp+1)*exsz-1, eys+(yp+1)*eysz-1, radius, (epos==i)?CMCS:CMC);
			*trnd=(mask && format[i]==NUM && IsNum(estr[i]))?'*':estr[i];
			RenderString(trnd, exs+xp*exsz+2, eys+yp*eysz+tys, exsz-2, CENTER, MED, (epos==i)?CMCST:(IsInput(format[i]))?CMCT:CMCIT);
		}
		memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres);

		time(&t1);
		i=-1;
		while(i==-1)
		{
			i=GetRCCode();
			if(i!=-1)
			{
				tmo=0;
				if(i==b_key)
				{
					usleep(debounce*1000);
					while((i=GetRCCode())!=-1);
				}
				b_key=i;
			}
			time(&t2);
			if(tmo)
			{
				if((t2-tm1)>=tmo)
				{
					i=RC_HOME;
				}
			}
			if((((format[epos]!=NUM) && (format[epos]!=HEX)) || ((format[epos]==HEX)&&(strlen(hcod[cpos])>1))) && ((t2-t1)>ndelay) && last_key>=0)
			{
				act_key=i=-2;
				b_key=-3;
				NextPos();
			}
		}
		act_key=i;
		
		switch(act_key)
		{
			case RC_0:
				SetCode(0);
			break;
			
			case RC_1:
				SetCode(1);
			break;
			
			case RC_2:
				SetCode(2);
			break;
			
			case RC_3:
				SetCode(3);
			break;
			
			case RC_4:
				SetCode(4);
			break;
			
			case RC_5:
				SetCode(5);
			break;
			
			case RC_6:
				SetCode(6);
			break;
			
			case RC_7:
				SetCode(7);
			break;
			
			case RC_8:
				SetCode(8);
			break;
			
			case RC_9:
				SetCode(9);
			break;
			
			case RC_RIGHT:
				NextPos();
				act_key=-2;
			break;
			
			case RC_LEFT:
				PrevPos();
				act_key=-2;
			break;
			
			case RC_PLUS:
				ipos=epos;
				while(IsInput(format[ipos+1]) && ((ipos+1)<cnt))
				{
					++ipos;
				}
				while(ipos>epos)
				{
					estr[ipos]=estr[ipos-1];
					--ipos;
				}
				estr[epos]=' ';
				act_key=-1;
			break;

			case RC_MINUS:
				ipos=epos+1;
				while(IsInput(format[ipos]) && (ipos<cnt))
				{
					estr[ipos-1]=estr[ipos];
					++ipos;
				}
				estr[ipos-1]=' ';
				act_key=-1;
			break;

			case RC_OK:
				run=0;
			break;
			
			case RC_MUTE:	
				memset(lfb, TRANSP, 720*576);
				usleep(500000L);
				while(GetRCCode()!=-1)
				{
					usleep(100000L);
				}
				while(GetRCCode()!=RC_MUTE)
				{
					usleep(500000L);
				}
				while((act_key=GetRCCode())!=-1)
				{
					usleep(100000L);
				}
			break;

			case RC_UP:
				if(epos>=cols)
				{
					epos-=cols;
					if(!IsInput(format[epos]))
					{
						NextPos();
					}
				}
				else
				{
					epos=cnt-1;
					if(!IsInput(format[epos]))
					{
						PrevPos();
					}
				}
				act_key=-2;
			break;
			
			case RC_DOWN:
				if(epos<=(cnt-cols))
				{
					epos+=cols;
					if(!IsInput(format[epos]))
					{
						NextPos();
					}
				}
				else
				{
					epos=0;
					if(!IsInput(format[epos]))
					{
						NextPos();
					}
				}
				act_key=-2;
			break;
			
			case RC_HOME:
				free(estr);
				estr=NULL;
				*rstr=0;
				run=0;
			break;
			
			case RC_RED:
				if(IsAlpha(estr[epos]))
				{
					estr[epos]^=0x20;
				}
				act_key=-2;
			break;
			
			case RC_YELLOW:
				epos=-1;
				for(i=0; i<strlen(format); i++)
				{
					if(IsInput(format[i]))
					{
						if(epos==-1)
						{
							epos=i;
						}
						estr[i]=' ';
					}
				}
				act_key=-2;
			break;
			
			case RC_HELP:
				if(bhelp)
				{
					sprintf(estr,"?");
					run=0;
				}
			break;
			
			default:
				act_key=-2;
			break;
		}
		last_key=act_key;
	}
	
	if(estr)
	{
		j=0;
		for(i=0; i<strlen(format); i++)
		{
			if(IsInput(format[i]))
			{
				rstr[j++]=estr[i];
			}
		}
		rstr[j]=0;
		free(estr);
	}	
	ReTransform_Msg(rstr);
	return tstr;
}