/* Create the child and the pipe to receive data from the child 
 */
int startChild(struct clientstate *cs) {
    int pid;
    fprintf(stderr, "Starting child\n");
	//if (checkResource(cs->resource + 2) != 0) {
	if (checkResource(cs->resource + 2) != 0) {
		if(pipe(cs->fd) == -1) {
			perror("pipe"); 
			printServerError(cs->sock);
			return -1;
		}
		
		if( (pid=fork()) > 0) {			
			/* read from fd[0] */
			close(cs->fd[1]);
			cs->pid  = pid;
			/* register pipe reader for select*/
			fprintf(stderr, "PARENT\n");
			return cs->fd[0];
		} 
		else if(pid == -1) {
			fprintf(stderr, "Fork failed\n");
			printServerError(cs->sock);
			return -1;
		}
		else {  /* child  */
			start_CGI(cs);
			//return 1 ;
		}
	}else{
		printNotFound(cs->sock);	
	}
    return -1; /* should never get here */
}
bool ApexResourceProvider::checkResource(ResID nameSpace, const char* name)
{
	/* Return true is named resource has known non-null pointer */
	uint32_t nsIndex = getNSIndex(nameSpace);
	if (nsIndex < mNameSpaces.size())
	{
		NameSpace* ns = mNameSpaces[nsIndex];
		ResID id = ns->getOrCreateID(name, mResources[ns->getID()].name);
		PX_ASSERT(id < mResources.size());
		return checkResource(id);
	}
	return false;
}
void ApexResourceProvider::generateUniqueName(ResID nameSpace, ApexSimpleString& name)
{
	uint32_t nsIndex = getNSIndex(nameSpace);
	if (nsIndex < mNameSpaces.size())
	{
		ApexSimpleString test;
		uint32_t   count = 1;
		char	buf[64];
		*buf = '.';

		do
		{
			shdfnd::snprintf(buf + 1,60, "%d", count);
			test = name + ApexSimpleString(buf);
			if (!checkResource(nameSpace, test.c_str()))
			{
				break;
			}
		}
		while (++count < 0xFFFFFFF0);

		name = test;
	}
}
Exemple #4
0
BOOL FAR PASCAL _EXPORT openTab(HWND hwnd, LPTabData lpTabData)
{
#if defined(_WIN32)
    HMODULE hInstance=InstanceFromWindow(hwnd);
    LPWORD p, lpCreateParams;
#else
    HINSTANCE hInstance=InstanceFromWindow(hwnd);
    LPBYTE p, lpCreateParams;
#endif
    LPBYTE lpszClass, lpszText=NULL;
    HWND hwndPrevChild=GetDlgItem(hwnd, lpTabData->nFrame);
    HFONT hFont;
    int nIndex=TabCtrl_GetCurSel(lpTabData->hwndTab);
    LPDLGTEMPLATE lpDlgTemplate;
    LPDLGITEMTEMPLATE lpDlgItemTemplate;
    LPFONTINFO lpFontInfo;
    HWND hwndChild;
    int nNumControls;
    RECT rc;

    if (nIndex<0)
	return(FALSE);

    lpTabData->nIndex=nIndex;
    lpDlgTemplate=lpTabData->lpTabList[nIndex].lpDlgTemplate;
    hFont=GetWindowFont(hwnd);

    //  Ignore everything in Dialog Template except for the number
    //  of controls.
    nNumControls=lpDlgTemplate->cdit;

#if defined(_WIN32)
    p=(LPWORD)(&lpDlgTemplate->cy+1); 	//  Start of Menu name
#if defined(_TABDEBUG)
    checkResource(hwnd, p, "Start of menu name");
#endif

    if (*p==0xffff)			//  Skip the menu name string
	p+=2;
    else
	while(*p++);

#if defined(_TABDEBUG)
    checkResource(hwnd, p, "Start of class name");
#endif

    if (*p==0xffff)			//  Skip the Class name string
	p+=2;
    else
	while(*p++);

#if defined(_TABDEBUG)
    checkResource(hwnd, p, "Start of caption");
#endif
#else
    p=(LPBYTE)(&lpDlgTemplate->cy+1); 	//  Start of Menu name
    while (*p++);           		//  Skip the menu name string
    while (*p++);           		//  Skip the Class name string
#endif
    while (*p++);           		//  Skip the Caption string
    lpFontInfo=(LPFONTINFO)p; 		//  Start of FONTINFO (if exists)

    //  Find address of first DLGITEMTEMPLATE structure
    if (lpDlgTemplate->style&DS_SETFONT) {
#if defined(_WIN32)
	p=(LPWORD)(&lpFontInfo->PointSize+1);
#if defined(_TABDEBUG)
	checkResource(hwnd, p, "Start of font name");
#endif
#else
	p=(LPBYTE)(&lpFontInfo->PointSize+1);
#endif
	while (*p++);  			//  Skip the Type face name string
	lpDlgItemTemplate=(LPDLGITEMTEMPLATE)p;
    } else
	lpDlgItemTemplate=(LPDLGITEMTEMPLATE)lpFontInfo;

    //  Create all of the child controls
    while (nNumControls--) {
#if defined(_WIN32)
	LPWORD lpwzClass=(LPWORD)(&lpDlgItemTemplate->id+1);
	BYTE szClassBuffer[64];
	LPWORD lpwzText;
	BYTE szTextBuffer[128];
	int nCount;

	lpDlgItemTemplate=(LPDLGITEMTEMPLATE)normalise(lpDlgItemTemplate, lpDlgTemplate, 1);
	lpwzClass=(LPWORD)(&lpDlgItemTemplate->id+1);

	if (*lpwzClass==0xffff) {
	    nCount=2;
	    lpwzText=lpwzClass+2;
	    lpszClass=(LPBYTE)szPredefinedClassNames[*(lpwzClass+1)-PREDEFINEDCNTRLBIT];
	} else {
	    lpszClass=szClassBuffer;
	    nCount=strcpy16to8(szClassBuffer, lpwzClass)+1;
	    lpwzText=lpwzClass+nCount;
	}

#if defined(_TABDEBUG)
	checkResource(hwnd, (LPINT)lpDlgItemTemplate, "Start of child control %d of %d, class \"%s\"",
		      lpDlgTemplate->cdit-nNumControls, lpDlgTemplate->cdit, lpszClass);
#endif

	if (*lpwzText==0xffff) {
	    nCount+=2;
	    lpszText=(LPBYTE)MAKELONG(*(lpszText+1), 0);
	} else {
	    lpszText=szTextBuffer;
	    nCount+=strcpy16to8(szTextBuffer, lpwzText)+1;
	}

	lpCreateParams=normalise(lpwzClass+nCount-1, lpDlgTemplate, 2);
#else
	lpszClass=(LPBYTE)(&lpDlgItemTemplate->style+1);

	if (*lpszClass&PREDEFINEDCNTRLBIT) {
	    lpszText=lpszClass+1;
	    lpszClass=(LPBYTE)szPredefinedClassNames[(WORD)(*lpszClass)-PREDEFINEDCNTRLBIT];
	} else
	    for (lpszText=lpszClass; *lpszText++;);

	//  Find address of number-of-bytes-in-additional-data
	for (lpCreateParams=lpszText; *lpCreateParams++;);
#endif

	//  Do not create any windows with an ID of uIDChangeableArea
	//  This control was used for reference when the template was
	//  created and should not be created.
	if (lpDlgItemTemplate->id!=lpTabData->nFrame) {
	    SetRect(&rc, lpDlgItemTemplate->x,
			 lpDlgItemTemplate->y,
			 lpDlgItemTemplate->x+lpDlgItemTemplate->cx,
			 lpDlgItemTemplate->y+lpDlgItemTemplate->cy);

	    MapDialogRect(hwnd, &rc);

	    hwndChild=CreateWindowEx(WS_EX_NOPARENTNOTIFY,
				     (LPCSTR)lpszClass, (LPCSTR)lpszText,
				     lpDlgItemTemplate->style,
				     rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
				     hwnd, (HMENU)lpDlgItemTemplate->id, hInstance,
				     lpCreateParams);

	    if (!hwndChild) {
		//  The child couldn't be created
		alert(hwnd, "Failed to create control %d (class %s)",
		      lpDlgTemplate->cdit-nNumControls+1, lpszClass);

		return(FALSE);
	    }

	    //  Tell the new control to use the same font as dialog box
	    SetWindowFont(hwndChild, hFont, FALSE);

	    // Fix the Z-Order of the controls
	    SetWindowPos(hwndChild, hwndPrevChild, 0, 0, 0, 0,
			 SWP_NOMOVE|SWP_NOSIZE);

	    hwndPrevChild=hwndChild;
	}

	// Point to the next DlgItemTemplate
	lpDlgItemTemplate=(LPDLGITEMTEMPLATE)(lpCreateParams+1+ *lpCreateParams);
    }

    FORWARD_WM_INITDIALOG(hwnd, 0, 0, lpTabData->lpTabList[nIndex].fpDlgProc);
    return(TRUE);
}