Пример #1
0
/*
=================
UI_LoadGame_GetGameList
=================
*/
static void UI_LoadGame_GetGameList( void )
{
	char	comment[256];
	char	**filenames;
	int	i, numFiles;

	filenames = FS_SEARCH( "save/*.sav", &numFiles, TRUE );

	// sort the saves in reverse order (oldest past at the end)
	qsort( filenames, numFiles, sizeof( char* ), (cmpfunc)COM_CompareSaves );

	for ( i = 0; i < numFiles; i++ )
	{
		if( i >= UI_MAXGAMES ) break;
		
		if( !GET_SAVE_COMMENT( filenames[i], comment ))
		{
			if( comment[0] )
			{
				// get name string even if not found - SV_GetComment can be mark saves
				// as <CORRUPTED> <OLD VERSION> etc
				AddSpaces( uiLoadGame.saveDescription[i], TIME_LENGTH );
				StringConcat( uiLoadGame.saveDescription[i], comment, NAME_LENGTH );
				AddSpaces( uiLoadGame.saveDescription[i], NAME_LENGTH );
				uiLoadGame.saveDescriptionPtr[i] = uiLoadGame.saveDescription[i];
				COM_FileBase( filenames[i], uiLoadGame.delName[i] );
			}
			else uiLoadGame.saveDescriptionPtr[i] = NULL;
			continue;
		}

		// strip path, leave only filename (empty slots doesn't have savename)
		COM_FileBase( filenames[i], uiLoadGame.saveName[i] );
		COM_FileBase( filenames[i], uiLoadGame.delName[i] );

		// fill save desc
		StringConcat( uiLoadGame.saveDescription[i], comment + CS_SIZE, TIME_LENGTH );
		StringConcat( uiLoadGame.saveDescription[i], " ", TIME_LENGTH );
		StringConcat( uiLoadGame.saveDescription[i], comment + CS_SIZE + CS_TIME, TIME_LENGTH );
		AddSpaces( uiLoadGame.saveDescription[i], TIME_LENGTH );// fill remaining entries
		StringConcat( uiLoadGame.saveDescription[i], comment, NAME_LENGTH );
		AddSpaces( uiLoadGame.saveDescription[i], NAME_LENGTH );
		StringConcat( uiLoadGame.saveDescription[i], comment + CS_SIZE + (CS_TIME * 2), GAMETIME_LENGTH );
		AddSpaces( uiLoadGame.saveDescription[i], GAMETIME_LENGTH );
		uiLoadGame.saveDescriptionPtr[i] = uiLoadGame.saveDescription[i];
	}

	for ( ; i < UI_MAXGAMES; i++ )
		uiLoadGame.saveDescriptionPtr[i] = NULL;

	uiLoadGame.savesList.itemNames = (const char **)uiLoadGame.saveDescriptionPtr;

	if ( uiLoadGame.saveName[0][0] == '\0' )
		uiLoadGame.load.generic.flags |= QMF_GRAYED;
	else uiLoadGame.load.generic.flags &= ~QMF_GRAYED;

	if ( uiLoadGame.delName[0][0] == '\0' )
		uiLoadGame.remove.generic.flags |= QMF_GRAYED;
	else uiLoadGame.remove.generic.flags &= ~QMF_GRAYED;
}
Пример #2
0
/*
=================
UI_InternetGames_GetGamesList
=================
*/
static void UI_InternetGames_GetGamesList( void )
{
	int		i;
	const char	*info;

	for( i = 0; i < uiStatic.numServers; i++ )
	{
		if( i >= UI_MAX_SERVERS )
			break;
		info = uiStatic.serverNames[i];

		uiInternetGames.gameDescription[i][0] = 0; // mark this string as empty

		StringConcat( uiInternetGames.gameDescription[i], Info_ValueForKey( info, "host" ), QMSB_GAME_LENGTH );
		AddSpaces( uiInternetGames.gameDescription[i], QMSB_GAME_LENGTH );

		StringConcat( uiInternetGames.gameDescription[i], Info_ValueForKey( info, "map" ), QMSB_MAPNAME_LENGTH );
		AddSpaces( uiInternetGames.gameDescription[i], QMSB_MAPNAME_LENGTH );

		StringConcat( uiInternetGames.gameDescription[i], Info_ValueForKey( info, "numcl" ), QMSB_MAXCL_LENGTH );
		StringConcat( uiInternetGames.gameDescription[i], "\\", QMSB_MAXCL_LENGTH );
		StringConcat( uiInternetGames.gameDescription[i], Info_ValueForKey( info, "maxcl" ), QMSB_MAXCL_LENGTH );
		AddSpaces( uiInternetGames.gameDescription[i], QMSB_MAXCL_LENGTH );

		char ping[10];
		snprintf( ping, 10, "%.f ms", uiStatic.serverPings[i] * 1000 );
		StringConcat( uiInternetGames.gameDescription[i], ping, QMSB_PING_LENGTH );
		AddSpaces( uiInternetGames.gameDescription[i], QMSB_PING_LENGTH );

		uiInternetGames.gameDescriptionPtr[i] = uiInternetGames.gameDescription[i];
	}

	for( ; i < UI_MAX_SERVERS; i++ )
		uiInternetGames.gameDescriptionPtr[i] = NULL;

	uiInternetGames.gameList.itemNames = (const char **)uiInternetGames.gameDescriptionPtr;
	uiInternetGames.gameList.numItems = 0; // reset it
	uiInternetGames.gameList.curItem = 0; // reset it

	if( !uiInternetGames.gameList.generic.charHeight )
		return; // to avoid divide integer by zero

	// count number of items
	while( uiInternetGames.gameList.itemNames[uiInternetGames.gameList.numItems] )
		uiInternetGames.gameList.numItems++;

	// calculate number of visible rows
	uiInternetGames.gameList.numRows = (uiInternetGames.gameList.generic.height2 / uiInternetGames.gameList.generic.charHeight) - 2;
	if( uiInternetGames.gameList.numRows > uiInternetGames.gameList.numItems ) uiInternetGames.gameList.numRows = uiInternetGames.gameList.numItems;

	if( uiStatic.numServers )
		uiInternetGames.joinGame.generic.flags &= ~QMF_GRAYED;
}
/*
=================
UI_CustomGame_GetModList
=================
*/
static void UI_CustomGame_GetModList( void )
{
	int	numGames, i;
	GAMEINFO	**games;

	games = GET_GAMES_LIST( &numGames );

	for( i = 0; i < numGames; i++ )
	{
		strncpy( uiCustomGame.modsDir[i], games[i]->gamefolder, sizeof( uiCustomGame.modsDir[i] ));
		strncpy( uiCustomGame.modsWebSites[i], games[i]->game_url, sizeof( uiCustomGame.modsWebSites[i] ));

		if( strlen( games[i]->type ))
			StringConcat( uiCustomGame.modsDescription[i], games[i]->type, TYPE_LENGTH );
		AddSpaces( uiCustomGame.modsDescription[i], TYPE_LENGTH );

		if( ColorStrlen( games[i]->title ) > 31 ) // NAME_LENGTH
		{
			StringConcat( uiCustomGame.modsDescription[i], games[i]->title, ( NAME_LENGTH - NAME_SPACE ));
			StringConcat( uiCustomGame.modsDescription[i], "...", NAME_LENGTH );
		}
		else StringConcat( uiCustomGame.modsDescription[i], games[i]->title, NAME_LENGTH );

		AddSpaces( uiCustomGame.modsDescription[i], NAME_LENGTH );
		StringConcat( uiCustomGame.modsDescription[i], games[i]->version, VER_LENGTH );
		AddSpaces( uiCustomGame.modsDescription[i], VER_LENGTH );
		if( strlen( games[i]->size ))
			StringConcat( uiCustomGame.modsDescription[i], games[i]->size, SIZE_LENGTH );
		else StringConcat( uiCustomGame.modsDescription[i], "0.0 Mb", SIZE_LENGTH );     
		AddSpaces( uiCustomGame.modsDescription[i], SIZE_LENGTH );
		uiCustomGame.modsDescriptionPtr[i] = uiCustomGame.modsDescription[i];

		if( !strcmp( gMenu.m_gameinfo.gamefolder, games[i]->gamefolder ))
			uiCustomGame.modList.curItem = i;
	}

	for( ; i < MAX_MODS; i++ )
		uiCustomGame.modsDescriptionPtr[i] = NULL;

	uiCustomGame.modList.itemNames = (const char **)uiCustomGame.modsDescriptionPtr;

	// see if the load button should be grayed
	if( !stricmp( gMenu.m_gameinfo.gamefolder, uiCustomGame.modsDir[uiCustomGame.modList.curItem] ))
		uiCustomGame.load.generic.flags |= QMF_GRAYED;
	if( strlen( uiCustomGame.modsWebSites[uiCustomGame.modList.curItem] ) == 0 )
		uiCustomGame.go2url.generic.flags |= QMF_GRAYED;
}
Пример #4
0
bool ConfigParser::GenerateConfigString(const ConfigToken * startToken, string &retString, uint spaceOffset)
{
  //Check for a valid token
  if(startToken == NULL)
  {
    return false;
  }
  
  //Reset the return string
  retString = "";

  //Append the name
  AddSpaces(retString,spaceOffset);
  string tokenName = startToken->GetName();
  if(!AddValueQuotes(tokenName))
  {
    return false;
  }
  retString += tokenName;

  //Add and values
  if(startToken->GetNumValues() > 0)
  {
    retString += " = ";

    //Add starting brackets for arrays of values
    if(startToken->GetNumValues() > 1)
    {
      retString += "("; 
    }
  
    //Loop for all the values
    for(uint i2=0;i2<startToken->GetNumValues();i2++)
    {
      //Get the value
      string tokenValue;
      startToken->Get(tokenValue, i2);

      //Validate and add the value
      if(!AddValueQuotes(tokenValue))
      {
        retString = "";
        return false;
      }
      retString += tokenValue; 

      //Add a seperating comma if not the last value
      if(i2 != startToken->GetNumValues()-1)
      {
        retString += ",";
      }
    }

    if(startToken->GetNumValues() > 1)
    {
      retString += ")"; 
    }
  }

  //Add a seperating colon
  retString += ";\n";

  //Append any children
  if(startToken->GetNumChildren() > 0)
  {
    AddSpaces(retString,spaceOffset); 
    retString += "{\n";

    //Loop for the number of children of this token
    for(uint i=0;i<startToken->GetNumChildren(); i++)
    {
      //Get the child
      const ConfigToken * child = startToken->GetChildToken(i);

      string childString;
      if(!GenerateConfigString(child,childString,spaceOffset+2))
      {
        retString = "";
        return false;
      }

      //Add the child string data
      retString += childString;
    }

    AddSpaces(retString,spaceOffset); 
    retString += "}\n";
  }

  return true;
}
Пример #5
0
char *change_justify( char *pszText, int iAlignment )
{
    static char s_szResult[4096];
    char *      pszResult = &s_szResult[0];
    char        szStore[4096];
    int         iMax;
    int         iLength = iAlignment-1;
    int         iLoop = 0;

    if ( strlen( pszText ) < 10 )
    {
        strcpy( s_szResult, "BUG: Justified string cannot be less than 10 characters long." );
        return( &s_szResult[0] );
    }

    while ( *pszText == ' ' ) pszText++;

    szStore[iLoop++] = *pszText++;

    if ( szStore[iLoop-1] >= 'a' && szStore[iLoop-1] <= 'z' )
        szStore[iLoop-1] = UPPER( szStore[iLoop] );

    /* The first loop goes through the string, copying it into szStore. The
     * string is formatted to remove all newlines, capitalise new sentences,
     * remove excess white spaces and ensure that full stops, commas and
     * exclaimation marks are all followed by two white spaces.
     */
    while ( *pszText )
    {
        switch ( *pszText )
        {
            default:
                szStore[iLoop++] = *pszText++;
                break;
            case ' ':
                if ( *(pszText+1) != ' ' )
                {
                    /* Store the character */
                    szStore[iLoop++] = *pszText;
                }
                pszText++;
                break;
            case '.': case '?': case '!':
                szStore[iLoop++] = *pszText++;
                switch ( *pszText )
                {
                    default:
                        szStore[iLoop++] = ' ';
                        szStore[iLoop++] = ' ';
                        /* Discard all leading spaces */
                        while ( *pszText == ' ' ) pszText++;
                        /* Store the character */
                        szStore[iLoop++] = *pszText++;
                        if ( szStore[iLoop-1] >= 'a' && szStore[iLoop-1] <= 'z' )
                            szStore[iLoop-1] &= ~32;
                        break;
                    case '.': case '?': case '!':
                        break;
                }
                break;
            case ',':
                /* Store the character */
                szStore[iLoop++] = *pszText++;
                /* Discard all leading spaces */
                while ( *pszText == ' ' ) pszText++;
                /* Commas shall be followed by one space */
                szStore[iLoop++] = ' ';
                break;
            case '$':
                szStore[iLoop++] = *pszText++;
                while ( *pszText == ' ' ) pszText++;
                break;
            case '\n': case '\r':
                pszText++;
                break;
        }
    }

    szStore[iLoop] = '\0';

    /* Initialise iMax to the size of szStore */
    iMax = strlen( szStore );

    /* The second loop goes through the string, inserting newlines at every
     * appropriate point.
     */
    while ( iLength < iMax )
    {
        /* Go backwards through the current line searching for a space */
        while ( szStore[iLength] != ' ' && iLength > 1 )
            iLength--;

        if ( szStore[iLength] == ' ' )
        {
            szStore[iLength] = '\n';

            iLength += iAlignment;
        }
        else
            break;
    }

    /* Reset the counter */
    iLoop = 0;

    /* The third and final loop goes through the string, making sure that there
     * is a \r (return to beginning of line) following every newline, with no
     * white spaces at the beginning of a particular line of text.
     */
    while ( iLoop < iMax )
    {
        /* Store the character */
        *pszResult++ = szStore[iLoop];
        switch ( szStore[iLoop] )
        {
            default:
                break;
            case '\n':
                *pszResult++ = '\r';
                while ( szStore[iLoop+1] == ' ' ) iLoop++;
                /* Add spaces to the front of the line as appropriate */
                AddSpaces( &pszResult, 25 );
                break;
        }
        iLoop++;
    }

    *pszResult++ = '\0';

    return( &s_szResult[0] );
}
Пример #6
0
/*
=================
UI_LoadGame_Init
=================
*/
static void UI_LoadGame_Init( void )
{
	memset( &uiLoadGame, 0, sizeof( uiLoadGame_t ));

	uiLoadGame.menu.vidInitFunc = UI_LoadGame_Init;
	uiLoadGame.menu.keyFunc = UI_LoadGame_KeyFunc;

	StringConcat( uiLoadGame.hintText, "Time", TIME_LENGTH );
	AddSpaces( uiLoadGame.hintText, TIME_LENGTH );
	StringConcat( uiLoadGame.hintText, "Game", NAME_LENGTH );
	AddSpaces( uiLoadGame.hintText, NAME_LENGTH );
	StringConcat( uiLoadGame.hintText, "Elapsed time", GAMETIME_LENGTH );
	AddSpaces( uiLoadGame.hintText, GAMETIME_LENGTH );

	uiLoadGame.background.generic.id = ID_BACKGROUND;
	uiLoadGame.background.generic.type = QMTYPE_BITMAP;
	uiLoadGame.background.generic.flags = QMF_INACTIVE;
	uiLoadGame.background.generic.x = 0;
	uiLoadGame.background.generic.y = 0;
	uiLoadGame.background.generic.width = uiStatic.width;
	uiLoadGame.background.generic.height = 768;
	uiLoadGame.background.pic = ART_BACKGROUND;

	uiLoadGame.banner.generic.id = ID_BANNER;
	uiLoadGame.banner.generic.type = QMTYPE_BITMAP;
	uiLoadGame.banner.generic.flags = QMF_INACTIVE|QMF_DRAW_ADDITIVE;
	uiLoadGame.banner.generic.x = UI_BANNER_POSX;
	uiLoadGame.banner.generic.y = UI_BANNER_POSY;
	uiLoadGame.banner.generic.width = UI_BANNER_WIDTH;
	uiLoadGame.banner.generic.height = UI_BANNER_HEIGHT;
	uiLoadGame.banner.pic = ART_BANNER;

	uiLoadGame.load.generic.id = ID_LOAD;
	uiLoadGame.load.generic.type = QMTYPE_BM_BUTTON;
	uiLoadGame.load.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW;
	uiLoadGame.load.generic.x = 72;
	uiLoadGame.load.generic.y = 230;
	uiLoadGame.load.generic.name = "Load";
	uiLoadGame.load.generic.statusText = "Load saved game";
	uiLoadGame.load.generic.callback = UI_LoadGame_Callback;

	UI_UtilSetupPicButton( &uiLoadGame.load, PC_LOAD_GAME );

	uiLoadGame.remove.generic.id = ID_DELETE;
	uiLoadGame.remove.generic.type = QMTYPE_BM_BUTTON;
	uiLoadGame.remove.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW;
	uiLoadGame.remove.generic.x = 72;
	uiLoadGame.remove.generic.y = 280;
	uiLoadGame.remove.generic.name = "Delete";
	uiLoadGame.remove.generic.statusText = "Delete saved game";
	uiLoadGame.remove.generic.callback = UI_LoadGame_Callback;

	UI_UtilSetupPicButton( &uiLoadGame.remove, PC_DELETE );

	uiLoadGame.cancel.generic.id = ID_CANCEL;
	uiLoadGame.cancel.generic.type = QMTYPE_BM_BUTTON;
	uiLoadGame.cancel.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW;
	uiLoadGame.cancel.generic.x = 72;
	uiLoadGame.cancel.generic.y = 330;
	uiLoadGame.cancel.generic.name = "Cancel";
	uiLoadGame.cancel.generic.statusText = "Return back to main menu";
	uiLoadGame.cancel.generic.callback = UI_LoadGame_Callback;

	UI_UtilSetupPicButton( &uiLoadGame.cancel, PC_CANCEL );

	uiLoadGame.hintMessage.generic.id = ID_TABLEHINT;
	uiLoadGame.hintMessage.generic.type = QMTYPE_ACTION;
	uiLoadGame.hintMessage.generic.flags = QMF_INACTIVE|QMF_SMALLFONT;
	uiLoadGame.hintMessage.generic.color = uiColorHelp;
	uiLoadGame.hintMessage.generic.name = uiLoadGame.hintText;
	uiLoadGame.hintMessage.generic.x = 360;
	uiLoadGame.hintMessage.generic.y = 225;

	uiLoadGame.levelShot.generic.id = ID_LEVELSHOT;
	uiLoadGame.levelShot.generic.type = QMTYPE_BITMAP;
	uiLoadGame.levelShot.generic.flags = QMF_INACTIVE;
	uiLoadGame.levelShot.generic.x = LEVELSHOT_X;
	uiLoadGame.levelShot.generic.y = LEVELSHOT_Y;
	uiLoadGame.levelShot.generic.width = LEVELSHOT_W;
	uiLoadGame.levelShot.generic.height = LEVELSHOT_H;
	uiLoadGame.levelShot.generic.ownerdraw = UI_LoadGame_Ownerdraw;

	uiLoadGame.savesList.generic.id = ID_SAVELIST;
	uiLoadGame.savesList.generic.type = QMTYPE_SCROLLLIST;
	uiLoadGame.savesList.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW|QMF_SMALLFONT;
	uiLoadGame.savesList.generic.x = 360;
	uiLoadGame.savesList.generic.y = 255;
	uiLoadGame.savesList.generic.width = 640;
	uiLoadGame.savesList.generic.height = 440;
	uiLoadGame.savesList.generic.callback = UI_LoadGame_Callback;

	uiLoadGame.msgBox.generic.id = ID_MSGBOX;
	uiLoadGame.msgBox.generic.type = QMTYPE_ACTION;
	uiLoadGame.msgBox.generic.flags = QMF_INACTIVE|QMF_HIDDEN;
	uiLoadGame.msgBox.generic.ownerdraw = UI_MsgBox_Ownerdraw; // just a fill rectangle
	uiLoadGame.msgBox.generic.x = DLG_X + 192;
	uiLoadGame.msgBox.generic.y = 256;
	uiLoadGame.msgBox.generic.width = 640;
	uiLoadGame.msgBox.generic.height = 256;

	uiLoadGame.promptMessage.generic.id = ID_MSGBOX;
	uiLoadGame.promptMessage.generic.type = QMTYPE_ACTION;
	uiLoadGame.promptMessage.generic.flags = QMF_INACTIVE|QMF_DROPSHADOW|QMF_HIDDEN;
	uiLoadGame.promptMessage.generic.name = "Delete selected game?";
	uiLoadGame.promptMessage.generic.x = DLG_X + 315;
	uiLoadGame.promptMessage.generic.y = 280;

	uiLoadGame.yes.generic.id = ID_YES;
	uiLoadGame.yes.generic.type = QMTYPE_BM_BUTTON;
	uiLoadGame.yes.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW|QMF_HIDDEN;
	uiLoadGame.yes.generic.name = "Ok";
	uiLoadGame.yes.generic.x = DLG_X + 380;
	uiLoadGame.yes.generic.y = 460;
	uiLoadGame.yes.generic.callback = UI_LoadGame_Callback;

	UI_UtilSetupPicButton( &uiLoadGame.yes, PC_OK );

	uiLoadGame.no.generic.id = ID_NO;
	uiLoadGame.no.generic.type = QMTYPE_BM_BUTTON;
	uiLoadGame.no.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW|QMF_HIDDEN;
	uiLoadGame.no.generic.name = "Cancel";
	uiLoadGame.no.generic.x = DLG_X + 530;
	uiLoadGame.no.generic.y = 460;
	uiLoadGame.no.generic.callback = UI_LoadGame_Callback;

	UI_UtilSetupPicButton( &uiLoadGame.no, PC_CANCEL );

	UI_LoadGame_GetGameList();

	UI_AddItem( &uiLoadGame.menu, (void *)&uiLoadGame.background );
	UI_AddItem( &uiLoadGame.menu, (void *)&uiLoadGame.banner );
	UI_AddItem( &uiLoadGame.menu, (void *)&uiLoadGame.load );
	UI_AddItem( &uiLoadGame.menu, (void *)&uiLoadGame.remove );
	UI_AddItem( &uiLoadGame.menu, (void *)&uiLoadGame.cancel );
	UI_AddItem( &uiLoadGame.menu, (void *)&uiLoadGame.hintMessage );
	UI_AddItem( &uiLoadGame.menu, (void *)&uiLoadGame.levelShot );
	UI_AddItem( &uiLoadGame.menu, (void *)&uiLoadGame.savesList );
	UI_AddItem( &uiLoadGame.menu, (void *)&uiLoadGame.msgBox );
	UI_AddItem( &uiLoadGame.menu, (void *)&uiLoadGame.promptMessage );
	UI_AddItem( &uiLoadGame.menu, (void *)&uiLoadGame.no );
	UI_AddItem( &uiLoadGame.menu, (void *)&uiLoadGame.yes );
}
Пример #7
0
int main(int argc, char *argv[]){
    int fd[4][2]; /* pipes array */
    char *child[] = { "./P1", "./P2", "./P3" }; /* child binaries */
    pid_t pid[3]; /* children pids*/

    char input[EXPR_MAX_LEN * 2], expr[EXPR_MAX_LEN], output[EXPR_MAX_LEN];

    int i, j, code;

    /* Initialize pipes */
    for(i = 0; i < 4; i++) {
        code = pipe(fd[i]);

        if( code < 0 ) {
            perror("pipe");
            exit(EXIT_FAILURE);
        }
    }

/****************************Spawn child processes****************************/

    for(i = 0; i < 3; i++) {
        /* Fork the proccess */
        pid[i] = fork();

        if( pid[i] == 0 ) {
            /* Child code */
            /*rPipe: Read Pipe, wPipe: Write pipe*/
            int rPipe = i, wPipe = i+1;

            /* Close the unsused pipes */
            for(j = 0; j < 4; j++) {
                if( j != rPipe )
                    Close( fd[j][0] );
                if( j != wPipe )
                    Close( fd[j][1] );
            }

            /* Redirect stdin & stdout */
            Redirect( fd[rPipe][0], 0);
            Redirect( fd[wPipe][1], 1);

            /* Execute the child code */
            execlp( child[i] , child[i], NULL);

            /* If we get here we got an eror */
            perror("execlp");
            exit(EXIT_FAILURE);
        }
        else if ( pid[i] < 0 ) {
            /* Kill the previous children */
            for(j = 0; j < i; j++) {
                kill(pid[j], SIGKILL);
            }

            perror("Fork failed");
            exit(EXIT_FAILURE);
        }

    }

    /* Close the unused pipes in main */
    for(j = 0; j < 4; j++) {
        if( j != 3 )
            Close(fd[j][0]);
        if( j != 0 )
            Close(fd[j][1]);
    }

    /* Initializing pollfd for poll-ing */
    struct pollfd fdinfo[2];

    fdinfo[0].fd = fd[3][0];
    fdinfo[0].events = POLLIN;
    fdinfo[1].fd = fd[0][1];
    fdinfo[1].events = POLLOUT;

/********************************************************************
 * ***** ****** MAIN LOOP *******************************************
 *******************************************************************/
    while ( 1 ) {
        printf( "Enter an expression up to %d characters long: ",
                EXPR_MAX_LEN - 2);

        while ( GetExpresssion(expr, EXPR_MAX_LEN) == 1 ){
            printf( "Warning: Maximum expression length is %d!\n",
                    EXPR_MAX_LEN );

            printf("Please re-try: ");
        }
        
        /* Add spaces when needed */
        if( expr[0] != ESCAPE_CHR )
            AddSpaces(expr, input);
        else
            strcpy(input, expr);
       
        /* Write to pipe */
        WaitForPipe( &fdinfo[1] );
        Write(fdinfo[1].fd, input, strlen(input));
        
        /* Read from pipe */
        WaitForPipe( &fdinfo[0] );
        Read(fdinfo[0].fd, output);

        if (expr[0] != ESCAPE_CHR ) {
            printf("Result: %s\n", output);
        }
        else break;
    }

    /* Clean up */
    int childStatus;
    for(i = 0 ; i < 3; i++){
        waitpid(pid[i], &childStatus, 0);
    }

    /* Close the pipes */
    Close(fdinfo[0].fd);
    Close(fdinfo[1].fd);

    return 0;
}
Пример #8
0
/*
=================
UI_InternetGames_Init
=================
*/
static void UI_InternetGames_Init( void )
{
	memset( &uiInternetGames, 0, sizeof( uiInternetGames_t ));

	uiInternetGames.menu.vidInitFunc = UI_InternetGames_Init;
	uiInternetGames.menu.keyFunc = UI_InternetGames_KeyFunc;

	StringConcat( uiInternetGames.hintText, "Name", QMSB_GAME_LENGTH );
	AddSpaces( uiInternetGames.hintText, QMSB_GAME_LENGTH );
	StringConcat( uiInternetGames.hintText, "Map", QMSB_MAPNAME_LENGTH );
	AddSpaces( uiInternetGames.hintText, QMSB_MAPNAME_LENGTH );
	StringConcat( uiInternetGames.hintText, "Players", QMSB_MAXCL_LENGTH );
	AddSpaces( uiInternetGames.hintText, QMSB_MAXCL_LENGTH );
	StringConcat( uiInternetGames.hintText, "Ping", QMSB_PING_LENGTH );
	AddSpaces( uiInternetGames.hintText, QMSB_PING_LENGTH );

	uiInternetGames.background.generic.id = ID_BACKGROUND;
	uiInternetGames.background.generic.type = QMTYPE_BITMAP;
	uiInternetGames.background.generic.flags = QMF_INACTIVE;
	uiInternetGames.background.generic.x = 0;
	uiInternetGames.background.generic.y = 0;
	uiInternetGames.background.generic.width = uiStatic.width;
	uiInternetGames.background.generic.height = 768;
	uiInternetGames.background.pic = ART_BACKGROUND;
	uiInternetGames.background.generic.ownerdraw = UI_Background_Ownerdraw;

	uiInternetGames.banner.generic.id = ID_BANNER;
	uiInternetGames.banner.generic.type = QMTYPE_BITMAP;
	uiInternetGames.banner.generic.flags = QMF_INACTIVE|QMF_DRAW_ADDITIVE;
	uiInternetGames.banner.generic.x = UI_BANNER_POSX;
	uiInternetGames.banner.generic.y = UI_BANNER_POSY;
	uiInternetGames.banner.generic.width = UI_BANNER_WIDTH;
	uiInternetGames.banner.generic.height = UI_BANNER_HEIGHT;
	uiInternetGames.banner.pic = ART_BANNER;

	uiInternetGames.joinGame.generic.id = ID_JOINGAME;
	uiInternetGames.joinGame.generic.type = QMTYPE_BM_BUTTON;
	uiInternetGames.joinGame.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW|QMF_GRAYED;
	uiInternetGames.joinGame.generic.x = 72;
	uiInternetGames.joinGame.generic.y = 230;
	uiInternetGames.joinGame.generic.name = "Join game";
	uiInternetGames.joinGame.generic.statusText = "Join to selected game";
	uiInternetGames.joinGame.generic.callback = UI_InternetGames_Callback;

	UI_UtilSetupPicButton( &uiInternetGames.joinGame, PC_JOIN_GAME );

	uiInternetGames.createGame.generic.id = ID_CREATEGAME;
	uiInternetGames.createGame.generic.type = QMTYPE_BM_BUTTON;
	uiInternetGames.createGame.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW;
	uiInternetGames.createGame.generic.x = 72;
	uiInternetGames.createGame.generic.y = 280;
	uiInternetGames.createGame.generic.name = "Create game";
	uiInternetGames.createGame.generic.statusText = "Create new Internet game";
	uiInternetGames.createGame.generic.callback = UI_InternetGames_Callback;

	UI_UtilSetupPicButton( &uiInternetGames.createGame, PC_CREATE_GAME );

	uiInternetGames.gameInfo.generic.id = ID_GAMEINFO;
	uiInternetGames.gameInfo.generic.type = QMTYPE_BM_BUTTON;
	uiInternetGames.gameInfo.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW|QMF_GRAYED;
	uiInternetGames.gameInfo.generic.x = 72;
	uiInternetGames.gameInfo.generic.y = 330;
	uiInternetGames.gameInfo.generic.name = "View game info";
	uiInternetGames.gameInfo.generic.statusText = "Get detail game info";
	uiInternetGames.gameInfo.generic.callback = UI_InternetGames_Callback;

	UI_UtilSetupPicButton( &uiInternetGames.gameInfo, PC_VIEW_GAME_INFO );

	uiInternetGames.refresh.generic.id = ID_REFRESH;
	uiInternetGames.refresh.generic.type = QMTYPE_BM_BUTTON;
	uiInternetGames.refresh.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW;
	uiInternetGames.refresh.generic.x = 72;
	uiInternetGames.refresh.generic.y = 380;
	uiInternetGames.refresh.generic.name = "Refresh";
	uiInternetGames.refresh.generic.statusText = "Refresh servers list";
	uiInternetGames.refresh.generic.callback = UI_InternetGames_Callback;

	UI_UtilSetupPicButton( &uiInternetGames.refresh, PC_REFRESH );

	uiInternetGames.done.generic.id = ID_DONE;
	uiInternetGames.done.generic.type = QMTYPE_BM_BUTTON;
	uiInternetGames.done.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW;
	uiInternetGames.done.generic.x = 72;
	uiInternetGames.done.generic.y = 430;
	uiInternetGames.done.generic.name = "Done";
	uiInternetGames.done.generic.statusText = "Return to main menu";
	uiInternetGames.done.generic.callback = UI_InternetGames_Callback;

	UI_UtilSetupPicButton( &uiInternetGames.done, PC_DONE );

	uiInternetGames.msgBox.generic.id = ID_MSGBOX;
	uiInternetGames.msgBox.generic.type = QMTYPE_ACTION;
	uiInternetGames.msgBox.generic.flags = QMF_INACTIVE|QMF_HIDDEN;
	uiInternetGames.msgBox.generic.ownerdraw = UI_MsgBox_Ownerdraw; // just a fill rectangle
	uiInternetGames.msgBox.generic.x = DLG_X + 192;
	uiInternetGames.msgBox.generic.y = 256;
	uiInternetGames.msgBox.generic.width = 640;
	uiInternetGames.msgBox.generic.height = 256;

	uiInternetGames.dlgMessage1.generic.id = ID_MSGTEXT;
	uiInternetGames.dlgMessage1.generic.type = QMTYPE_ACTION;
	uiInternetGames.dlgMessage1.generic.flags = QMF_INACTIVE|QMF_HIDDEN|QMF_DROPSHADOW;
	uiInternetGames.dlgMessage1.generic.name = "Join a network game will exit";
	uiInternetGames.dlgMessage1.generic.x = DLG_X + 248;
	uiInternetGames.dlgMessage1.generic.y = 280;

	uiInternetGames.dlgMessage2.generic.id = ID_MSGTEXT;
	uiInternetGames.dlgMessage2.generic.type = QMTYPE_ACTION;
	uiInternetGames.dlgMessage2.generic.flags = QMF_INACTIVE|QMF_HIDDEN|QMF_DROPSHADOW;
	uiInternetGames.dlgMessage2.generic.name = "any current game, OK to exit?";
	uiInternetGames.dlgMessage2.generic.x = DLG_X + 248;
	uiInternetGames.dlgMessage2.generic.y = 310;

	uiInternetGames.yes.generic.id = ID_YES;
	uiInternetGames.yes.generic.type = QMTYPE_BM_BUTTON;
	uiInternetGames.yes.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_HIDDEN|QMF_DROPSHADOW;
	uiInternetGames.yes.generic.name = "Ok";
	uiInternetGames.yes.generic.x = DLG_X + 380;
	uiInternetGames.yes.generic.y = 460;
	uiInternetGames.yes.generic.callback = UI_InternetGames_Callback;

	UI_UtilSetupPicButton( &uiInternetGames.yes, PC_OK );

	uiInternetGames.no.generic.id = ID_NO;
	uiInternetGames.no.generic.type = QMTYPE_BM_BUTTON;
	uiInternetGames.no.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_HIDDEN|QMF_DROPSHADOW;
	uiInternetGames.no.generic.name = "Cancel";
	uiInternetGames.no.generic.x = DLG_X + 530;
	uiInternetGames.no.generic.y = 460;
	uiInternetGames.no.generic.callback = UI_InternetGames_Callback;

	UI_UtilSetupPicButton( &uiInternetGames.no, PC_CANCEL );

	uiInternetGames.hintMessage.generic.id = ID_TABLEHINT;
	uiInternetGames.hintMessage.generic.type = QMTYPE_ACTION;
	uiInternetGames.hintMessage.generic.flags = QMF_INACTIVE|QMF_SMALLFONT;
	uiInternetGames.hintMessage.generic.color = uiColorHelp;
	uiInternetGames.hintMessage.generic.name = uiInternetGames.hintText;
	uiInternetGames.hintMessage.generic.x = 340;
	uiInternetGames.hintMessage.generic.y = 225;

	uiInternetGames.gameList.generic.id = ID_SERVERSLIST;
	uiInternetGames.gameList.generic.type = QMTYPE_SCROLLLIST;
	uiInternetGames.gameList.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_SMALLFONT;
	uiInternetGames.gameList.generic.x = 340;
	uiInternetGames.gameList.generic.y = 255;
	uiInternetGames.gameList.generic.width = 660;
	uiInternetGames.gameList.generic.height = 440;
	uiInternetGames.gameList.generic.callback = UI_InternetGames_Callback;
	uiInternetGames.gameList.itemNames = (const char **)uiInternetGames.gameDescriptionPtr;

	// server.dll needs for reading savefiles or startup newgame
	if( !CheckGameDll( ))
		uiInternetGames.createGame.generic.flags |= QMF_GRAYED;	// server.dll is missed - remote servers only

	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.background );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.banner );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.joinGame );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.createGame );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.gameInfo );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.refresh );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.done );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.hintMessage );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.gameList );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.msgBox );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.dlgMessage1 );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.dlgMessage2 );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.no );
 	UI_AddItem( &uiInternetGames.menu, (void *)&uiInternetGames.yes );

	uiInternetGames.refreshTime = uiStatic.realTime + 500; // delay before update 0.5 sec
}
Пример #9
0
int main(int argc, char *argv[]){

    int commFiles[4]; /* fds for our communication files */
    char filenames[4][10]; /* commincation files filenames */
    char *child[] = {"./P1", "./P2", "./P3" };/* children's filenames vector */

    pid_t pid[3]; /* forked pids */

    char input[EXPR_MAX_LEN * 2], expr[EXPR_MAX_LEN], output[EXPR_MAX_LEN];

    int i,j;

/*******************************Create files**********************************/
    for (i = 0; i < 4; i++){
        sprintf( filenames[i], ".com%d", i);
        commFiles[i] = open( filenames[i], O_CREAT | O_RDWR, S_IRWXU);

        /* error checking */
        if (commFiles[i] < 0) {
            fprintf( stderr, "Cannot create file %s!\n", filenames[i]);
            perror(NULL);

            /*close previous files!*/
            for (j = 0; j < i; j++){
                close( commFiles[j] );
            }

            exit(EXIT_FAILURE);
        }
    }

/**********************Create the 'children' proccesses***********************/
    for(i = 0; i < 3; i++){
        pid[i] = fork();

        if( pid[i] == 0 ) {
            execlp(child[i],
                    child[i],
                    filenames[i],
                    filenames[ (i+1) % 4 ],
                    (char *)NULL );

            /* This code is excecuted only if execlp fails! */
            perror("Exec failed");
            exit(EXIT_FAILURE);
        }
        else if( pid[i] < 0 ) {
            /* We kill the previous children */
            for(j = 0; j < i; j++) {
                kill(pid[j], SIGKILL);
            }

            perror("Fork failed");
            exit(EXIT_FAILURE);
        }
    }

/*******************************Main loop*************************************/
    while ( 1 ) {
        printf( "Enter an expression up to %d characters long: ",
                EXPR_MAX_LEN  / 2 - 2);

        while ( GetExpresssion(expr, EXPR_MAX_LEN / 2 ) == 1 ){
            printf( "Warning: Maximum expression length is %d!\n",
                    EXPR_MAX_LEN );

            printf("Please re-try: ");
        }
        
        /* Add spaces when needed */
        if( expr[0] != ESCAPE_CHR )
            AddSpaces(expr, input);
        else
            strcpy(input, expr);

        SendMessage(commFiles[0], input);
        ReceiveMessage(commFiles[3], output);

        if (expr[0] != ESCAPE_CHR ) {
            printf("Result: %s\n", output);
        }
        else break;

    }

/*******************************Clean Up**************************************/

    /* Wait for children to quit */
    int childStatus;
    for(i = 0; i < 3; i++){
        waitpid(pid[i], &childStatus, 0);
    }

    /* Close files */
    for(i = 0; i < 4; i++) {
        Close( commFiles[i] );
        if ( remove( filenames[i] ) < 0 ){
            perror("Delete file");
        }
    }

    printf("Quitting...Bye!\n");

    return 0;
}
/*
=================
UI_CustomGame_Init
=================
*/
static void UI_CustomGame_Init( void )
{
	memset( &uiCustomGame, 0, sizeof( uiCustomGame_t ));

	uiCustomGame.menu.vidInitFunc = UI_CustomGame_Init;
	uiCustomGame.menu.keyFunc = UI_CustomGame_KeyFunc;

	StringConcat( uiCustomGame.hintText, "Type", TYPE_LENGTH );
	AddSpaces( uiCustomGame.hintText, TYPE_LENGTH );
	StringConcat( uiCustomGame.hintText, "Name", NAME_LENGTH );
	AddSpaces( uiCustomGame.hintText, NAME_LENGTH );
	StringConcat( uiCustomGame.hintText, "Ver", VER_LENGTH );
	AddSpaces( uiCustomGame.hintText, VER_LENGTH );
	StringConcat( uiCustomGame.hintText, "Size", SIZE_LENGTH );
	AddSpaces( uiCustomGame.hintText, SIZE_LENGTH );

	uiCustomGame.background.generic.id = ID_BACKGROUND;
	uiCustomGame.background.generic.type = QMTYPE_BITMAP;
	uiCustomGame.background.generic.flags = QMF_INACTIVE;
	uiCustomGame.background.generic.x = 0;
	uiCustomGame.background.generic.y = 0;
	uiCustomGame.background.generic.width = uiStatic.width;
	uiCustomGame.background.generic.height = 768;
	uiCustomGame.background.pic = ART_BACKGROUND;

	uiCustomGame.banner.generic.id = ID_BANNER;
	uiCustomGame.banner.generic.type = QMTYPE_BITMAP;
	uiCustomGame.banner.generic.flags = QMF_INACTIVE|QMF_DRAW_ADDITIVE;
	uiCustomGame.banner.generic.x = UI_BANNER_POSX;
	uiCustomGame.banner.generic.y = UI_BANNER_POSY;
	uiCustomGame.banner.generic.width = UI_BANNER_WIDTH;
	uiCustomGame.banner.generic.height = UI_BANNER_HEIGHT;
	uiCustomGame.banner.pic = ART_BANNER;

	uiCustomGame.load.generic.id = ID_ACTIVATE;
	uiCustomGame.load.generic.type = QMTYPE_BM_BUTTON;
	uiCustomGame.load.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW;
	uiCustomGame.load.generic.x = 72;
	uiCustomGame.load.generic.y = 230;
	uiCustomGame.load.generic.name = "Activate";
	uiCustomGame.load.generic.statusText = "Activate selected custom game";
	uiCustomGame.load.generic.callback = UI_CustomGame_Callback;

	UI_UtilSetupPicButton( &uiCustomGame.load, PC_ACTIVATE );

	uiCustomGame.go2url.generic.id = ID_GOTOSITE;
	uiCustomGame.go2url.generic.type = QMTYPE_BM_BUTTON;
	uiCustomGame.go2url.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW;
	uiCustomGame.go2url.generic.x = 72;
	uiCustomGame.go2url.generic.y = 280;
	uiCustomGame.go2url.generic.name = "Visit web site";
	uiCustomGame.go2url.generic.statusText = "Visit the web site of game developrs";
	uiCustomGame.go2url.generic.callback = UI_CustomGame_Callback;

	UI_UtilSetupPicButton( &uiCustomGame.go2url, PC_VISIT_WEB_SITE );

	uiCustomGame.done.generic.id = ID_DONE;
	uiCustomGame.done.generic.type = QMTYPE_BM_BUTTON;
	uiCustomGame.done.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW;
	uiCustomGame.done.generic.x = 72;
	uiCustomGame.done.generic.y = 330;
	uiCustomGame.done.generic.name = "Done";
	uiCustomGame.done.generic.statusText = "Return to main menu";
	uiCustomGame.done.generic.callback = UI_CustomGame_Callback;

	UI_UtilSetupPicButton( &uiCustomGame.done, PC_DONE );

	uiCustomGame.hintMessage.generic.id = ID_TABLEHINT;
	uiCustomGame.hintMessage.generic.type = QMTYPE_ACTION;
	uiCustomGame.hintMessage.generic.flags = QMF_INACTIVE|QMF_SMALLFONT;
	uiCustomGame.hintMessage.generic.color = uiColorHelp;
	uiCustomGame.hintMessage.generic.name = uiCustomGame.hintText;
	uiCustomGame.hintMessage.generic.x = 360;
	uiCustomGame.hintMessage.generic.y = 225;

	uiCustomGame.modList.generic.id = ID_MODLIST;
	uiCustomGame.modList.generic.type = QMTYPE_SCROLLLIST;
	uiCustomGame.modList.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_SMALLFONT;
	uiCustomGame.modList.generic.x = 360;
	uiCustomGame.modList.generic.y = 255;
	uiCustomGame.modList.generic.width = 640;
	uiCustomGame.modList.generic.height = 440;
	uiCustomGame.modList.generic.callback = UI_CustomGame_Callback;

	uiCustomGame.msgBox.generic.id = ID_MSGBOX;
	uiCustomGame.msgBox.generic.type = QMTYPE_ACTION;
	uiCustomGame.msgBox.generic.flags = QMF_INACTIVE|QMF_HIDDEN;
	uiCustomGame.msgBox.generic.ownerdraw = UI_MsgBox_Ownerdraw; // just a fill rectangle
	uiCustomGame.msgBox.generic.x = DLG_X + 192;
	uiCustomGame.msgBox.generic.y = 256;
	uiCustomGame.msgBox.generic.width = 640;
	uiCustomGame.msgBox.generic.height = 256;

	uiCustomGame.promptMessage.generic.id = ID_MSGBOX;
	uiCustomGame.promptMessage.generic.type = QMTYPE_ACTION;
	uiCustomGame.promptMessage.generic.flags = QMF_INACTIVE|QMF_DROPSHADOW|QMF_HIDDEN;
	uiCustomGame.promptMessage.generic.name = "Leave current game?";
	uiCustomGame.promptMessage.generic.x = DLG_X + 315;
	uiCustomGame.promptMessage.generic.y = 280;

	uiCustomGame.yes.generic.id = ID_YES;
	uiCustomGame.yes.generic.type = QMTYPE_BM_BUTTON;
	uiCustomGame.yes.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW|QMF_HIDDEN;
	uiCustomGame.yes.generic.name = "Ok";
	uiCustomGame.yes.generic.x = DLG_X + 380;
	uiCustomGame.yes.generic.y = 460;
	uiCustomGame.yes.generic.callback = UI_CustomGame_Callback;

	UI_UtilSetupPicButton( &uiCustomGame.yes, PC_OK );

	uiCustomGame.no.generic.id = ID_NO;
	uiCustomGame.no.generic.type = QMTYPE_BM_BUTTON;
	uiCustomGame.no.generic.flags = QMF_HIGHLIGHTIFFOCUS|QMF_DROPSHADOW|QMF_HIDDEN;
	uiCustomGame.no.generic.name = "Cancel";
	uiCustomGame.no.generic.x = DLG_X + 530;
	uiCustomGame.no.generic.y = 460;
	uiCustomGame.no.generic.callback = UI_CustomGame_Callback;

	UI_UtilSetupPicButton( &uiCustomGame.no, PC_CANCEL );

	UI_CustomGame_GetModList();

	UI_AddItem( &uiCustomGame.menu, (void *)&uiCustomGame.background );
	UI_AddItem( &uiCustomGame.menu, (void *)&uiCustomGame.banner );
	UI_AddItem( &uiCustomGame.menu, (void *)&uiCustomGame.load );
	UI_AddItem( &uiCustomGame.menu, (void *)&uiCustomGame.go2url );
	UI_AddItem( &uiCustomGame.menu, (void *)&uiCustomGame.done );
	UI_AddItem( &uiCustomGame.menu, (void *)&uiCustomGame.hintMessage );
	UI_AddItem( &uiCustomGame.menu, (void *)&uiCustomGame.modList );
	UI_AddItem( &uiCustomGame.menu, (void *)&uiCustomGame.msgBox );
	UI_AddItem( &uiCustomGame.menu, (void *)&uiCustomGame.promptMessage );
	UI_AddItem( &uiCustomGame.menu, (void *)&uiCustomGame.no );
	UI_AddItem( &uiCustomGame.menu, (void *)&uiCustomGame.yes );
}
Пример #11
0
void LoadComboWithDirectories(
/************************************************************************/
HWND hWnd,
WORD idComboBox,
BOOL bHide)
{
#ifdef WIN32

#else
HWND hControl;
int i, count;
STRING szString, szDirName;
LPSTR lpDir, lp;
int retc, iMaxSubDirs;
struct find_t dir;

hControl = GetDlgItem( hWnd, idComboBox );

if ( bHide )
//	ShowControl( hWnd, idComboBox, idComboBox, NO, YES /*Delay*/ );
	SetWindowPos( hControl, 0, /* Same z order */
		0, 0, /* Same location */
		0, 0, /* Same size */
		SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
		SWP_NOREDRAW );

CURRENTDIR( szString, MAX_STR_LEN );
lpDir = &szString[3]; // Skip over the drive, colon, and slash
lp = lpDir;
iMaxSubDirs = 32;

SendDlgItemMessage( hWnd, idComboBox, LB_RESETCONTENT, 0, 0L );
AddSpaces( szDirName, iMaxSubDirs-- ); // Add spaces to defeat the sort
lstrcat( szDirName, "\\" );
CombineStringID( szDirName, IDC_PATHICON_ROOT );
SendDlgItemMessage( hWnd, idComboBox, LB_ADDSTRING, 0, (long)(LPSTR)szDirName );
count = 0;

while ( *lp )
	{
	if ( *lp != '\\' )
		{
		lp++;
		continue;
		}
	*lp++ = '\0'; // Overwrite the slash and skip past it
	AddSpaces( szDirName, iMaxSubDirs-- ); // Add spaces to defeat the sort
	lstrcat( szDirName, lpDir );
	CombineStringID( szDirName, IDC_PATHICON_OPEN );
	SendDlgItemMessage( hWnd, idComboBox, LB_ADDSTRING, 0,
		(long)Lowercase(szDirName) );
	count++;
	lpDir = lp;
	}

if ( lp > lpDir )
	{
	AddSpaces( szDirName, iMaxSubDirs-- ); // Add spaces to defeat the sort
	lstrcat( szDirName, lpDir );
	CombineStringID( szDirName, IDC_PATHICON_ACTIVE );
	SendDlgItemMessage( hWnd, idComboBox, LB_ADDSTRING, 0,
		(long)Lowercase(szDirName) );
	count++;
	}

retc = _dos_findfirst( "*.*", _A_SUBDIR, &dir );
for ( i=0; ; i++ )
	{
	if ( retc )
		break;
	if ( dir.attrib & _A_SUBDIR && dir.name[0] != '.' )
		{ // If this is a subdirectory
		lstrcpy( szDirName, dir.name );
		CombineStringID( szDirName, IDC_PATHICON_CLOSED );
		SendDlgItemMessage( hWnd, idComboBox, LB_ADDSTRING, 0,
			(long)Lowercase(szDirName) );
		}
	retc = _dos_findnext( &dir );
	}

//SendDlgItemMessage( hWnd, idComboBox, LB_SETCURSEL, count, 0L);
SendDlgItemMessage( hWnd, idComboBox, LB_SETCURSEL, -1, 0L);

if ( bHide )
	{
//	ShowControl( hWnd, idComboBox, idComboBox, YES, NO /*Delay*/ );
	SetWindowPos( hControl, 0, /* Same z order */
		0, 0, /* Same location */
		0, 0, /* Same size */
		SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER );
//		SWP_NOREDRAW );
	}
#endif  // WIN32
}