site logo  RexxutilSysobjectsc

HomePage | Categories |* BLOG *| RecentChanges | RecentlyCommented | Login/Register

sysobjects.c


This source file contains SysSetIcon and "SysQueryClassList.

SysQueryClassList calls SetRexxVariable helper function.

/**************************************************************************
*
*             eCS RexxUtil Library Replacement Project
*
*  Contains the following functions:
*      SysSetIcon
*
*  Michael K Greene December 2007
*
------------------------------------------------------------------------------*/
/*                                                                            */
/* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved.             */
/* Copyright (c) 2005-2006 Rexx Language Association. All rights reserved.    */
/*                                                                            */
/* This program and the accompanying materials are made available under       */
/* the terms of the Common Public License v1.0 which accompanies this         */
/* distribution. A copy is also available at the following address:           */
/* http://www.oorexx.org/license.html                                         */
/*                                                                            */
/* Redistribution and use in source and binary forms, with or                 */
/* without modification, are permitted provided that the following            */
/* conditions are met:                                                        */
/*                                                                            */
/* Redistributions of source code must retain the above copyright             */
/* notice, this list of conditions and the following disclaimer.              */
/* Redistributions in binary form must reproduce the above copyright          */
/* notice, this list of conditions and the following disclaimer in            */
/* the documentation and/or other materials provided with the distribution.   */
/*                                                                            */
/* Neither the name of Rexx Language Association nor the names                */
/* of its contributors may be used to endorse or promote products             */
/* derived from this software without specific prior written permission.      */
/*                                                                            */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS        */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT          */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS          */
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,      */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED   */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,        */
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY     */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING    */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS         */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.               */
/*                                                                            */
/******************************************************************************/

#define INCL_WINWORKPLACE
#define INCL_WINPOINTERS

#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <alloca.h>
#include <io.h>

#include <rexxdefs.h>  // rexxsaa.h include in this header

RexxFunctionHandler SysSetIcon;
RexxFunctionHandler SysQueryClassList;


/*************************************************************************
* Function:  SysSetIcon                                                  *
*                                                                        *
* Syntax:    call SysSetIcon filename, iconfilename                      *
*                                                                        *
* Params:    filename     - name of the target file whose icon is        *
*                           to be set                                    *
*            iconfilename - name of the OS/2 icon file (.ICO) which      *
*                           contains the icon data to be used            *
*                                                                        *
* Return:    WinSetFileIcon API return code. Possible values are 1       *
*            if the icon was set successfully, or 0 otherwise            *
*************************************************************************/

unsigned long SysSetIcon(unsigned char *name,
						   unsigned long numargs,
						   RXSTRING args[],
						   char *queuename,
						   RXSTRING *retstr)
{
	bool rc;

	ICONINFO icon;

	if (numargs != 2) return INVALID_ROUTINE; /* raise error condition */

	if(access(args[0].strptr, F_OK) !=0) RETVAL(0)
	if(access(args[1].strptr, F_OK) !=0) RETVAL(0)

	icon.fFormat     = ICON_FILE;
	icon.pszFileName = args[1].strptr;
	icon.cb          = sizeof(ICONINFO);

	rc = WinSetFileIcon(args[0].strptr, &icon);

	if(!rc) RETVAL(0)

	RETVAL(1)
}


/*************************************************************************
* Function:  SysQueryClassList                                           *
*                                                                        *
* Syntax:    call SysQueryClassList stem                                 *
*                                                                        *
* Params:    stem  -  name of a stem variable in which the list of       *
*                     classes will be saved                              *
*                                                                        *
* Return:    WinSetFileIcon API return code. Possible values are 1       *
*            if the icon was set successfully, or 0 otherwise            *
*************************************************************************/

unsigned long SysQueryClassList(unsigned char *name,
						   unsigned long numargs,
						   RXSTRING args[],
						   char *queuename,
						   RXSTRING *retstr)
{
	int  countClass = 0;

	bool  firstStruct = TRUE;

	char szStemName[255];   // what's max stem name length?
	char *pszStemIdx;
	char szValue[255];

	unsigned long rc;
	unsigned long objSize = 0;

	POBJCLASS ClassBuffer;
	POBJCLASS ptrBuffer;

	/* Only one argument accepted */
	if (numargs != 1) return INVALID_ROUTINE;

	/* remember stem name */
	memset(szStemName, 0, sizeof(szStemName));
	strcpy(szStemName, args[0].strptr);

	// check for '.' and if not there make it so
	if (szStemName[args[0].strlength-1] != '.')
		szStemName[args[0].strlength] = '.';

	// pointer to the index part of stem
	pszStemIdx = &(szStemName[strlen(szStemName)]);

	// get size of buffer required
	if(!WinEnumObjectClasses(NULL, &objSize)) RETVAL(0)

	// make buffer
	ClassBuffer = alloca( objSize );

	// get classes
	if(!WinEnumObjectClasses(ClassBuffer, &objSize)) RETVAL(0)

	ptrBuffer = ClassBuffer;

	while(1) {

		if(!firstStruct) ptrBuffer = ptrBuffer->pNext;
		else firstStruct = FALSE;

		itoa(++countClass, pszStemIdx, 10);

		sprintf(szValue, "%s %s",
			ptrBuffer->pszClassName, ptrBuffer->pszModName);

		rc = SetRexxVariable(szStemName, szValue);

		if ((rc != RXSHV_OK) && (rc != RXSHV_NEWV)) RETVAL(0)

		if(ptrBuffer->pNext == NULL) break;
	}

	// setup the 0 index with number of classes
	strcpy(pszStemIdx, "0");                    // index
	sprintf(szValue, "%ld", countClass);        // value

	rc = SetRexxVariable(szStemName, szValue);

	if ((rc != RXSHV_OK) && (rc != RXSHV_NEWV)) RETVAL(0)
	else RETVAL(1)
}

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.7
Page was generated in 0.6047 seconds