dslinux/user/pixil/libs/wm Makefile inidelsect.c iniread.c iniwrite.c nxgeom.c nxlist.c nxutil.c scrtoplib.c strzcpy.c

amadeus dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:25:32 CEST 2006


Update of /cvsroot/dslinux/dslinux/user/pixil/libs/wm
In directory antilope:/tmp/cvs-serv11916/libs/wm

Added Files:
	Makefile inidelsect.c iniread.c iniwrite.c nxgeom.c nxlist.c 
	nxutil.c scrtoplib.c strzcpy.c 
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it

--- NEW FILE: iniwrite.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pwd.h>
#include <wm/nxlib.h>
#include <errno.h>

int
IniWriteString(char *section, char *key, char *inbuf, char *inifile)
{
    char *p;
    FILE *fp;
    char buf[256];
    char newstring[256];
    struct stat filestat;
    off_t filesize;
    off_t file_pos = 0;
    off_t section_pos = 0;
    off_t key_pos = 0;
    char **newfile = NULL;
    int num_lines = 0;
    int idx;
    int jdx;
    int err;
    int newlineno;
    int _lineno = 0;

    if ((fp = fopen(inifile, "a+")) == NULL) {
	return 1;
    }
    fclose(fp);
    fp = fopen(inifile, "r+");
    err = stat(inifile, &filestat);
    if (err < 0) {
	fprintf(stderr, "Error [%s]\n", strerror(errno));
	fclose(fp);
	return 1;
    }
    filesize = filestat.st_size;
    while (NULL != fgets(buf, sizeof(buf) - 1, fp)) {
	num_lines++;
    }
    rewind(fp);
    newlineno = 0;
    while (NULL != fgets(buf, sizeof(buf) - 1, fp)) {
	file_pos += strlen(buf);
	_lineno++;
	if (buf[0] == '[') {
	    if ((p = strchr(buf, ']')) != NULL)
		*p = 0;
	    if (strcasecmp(buf + 1, section) == 0) {
		section_pos = file_pos;
		while (fgets(buf, sizeof(buf) - 1, fp) != NULL) {
		    _lineno++;
		    file_pos += strlen(buf);
		    if (strncasecmp(key, buf, strlen(key)) == 0) {	// found matching key change it
			key_pos = file_pos - strlen(buf);
			goto insert;
		    }
		    if (buf[0] == '[') {	// out of the section so insert new key
			rewind(fp);
			jdx = 1;
			file_pos = 0;
			while (NULL != fgets(buf, sizeof(buf) - 1, fp)) {
			    file_pos += strlen(buf);
			    jdx++;
			    if (0 == strcmp(buf, "\n")
				&& (jdx == _lineno - 1)) {
				key_pos = file_pos - strlen(buf);
				goto insert;
			    }
			    if (jdx == _lineno) {
				key_pos = file_pos;
				goto insert;
			    }
			}
		    }
		    if (file_pos == filesize) {	// insert new key at end of file
			sprintf(newstring, "%s=%s\n", key, inbuf);
			fputs(newstring, fp);
			fclose(fp);
			return 0;
		    }
		}
	    }
	}
    }
    // insert new section and key at end of file
    sprintf(newstring, "\n[%s]\n", section);
    fputs(newstring, fp);
    sprintf(newstring, "%s=%s\n", key, inbuf);
    fputs(newstring, fp);
    fclose(fp);
    return 0;

  insert:
    if ((newfile = (char **) calloc(num_lines + 1, sizeof(char *))) == NULL) {
	fclose(fp);
	return 1;
    }
    sprintf(newstring, "%s=%s\n", key, inbuf);
    newfile[newlineno] = (char *) calloc(strlen(newstring) + 1, sizeof(char));
    if (newfile[newlineno] == NULL) {
	fclose(fp);
	free(newfile);
	return 1;
    }
    file_pos -= strlen(buf);
    file_pos += strlen(newstring);
    strncpy(newfile[newlineno], newstring, strlen(newstring));
    while (NULL != fgets(buf, sizeof(buf) - 1, fp)) {
	newlineno++;
	newfile[newlineno] = (char *) calloc(strlen(buf) + 1, sizeof(char));
	if (newfile[newlineno] == NULL) {
	    fclose(fp);
	    free(newfile);
	    return 1;
	}
	file_pos += strlen(buf);
	strncpy(newfile[newlineno], buf, strlen(buf));
    }
    fsetpos(fp, (fpos_t *) & key_pos);
    for (idx = 0; idx <= newlineno; idx++) {
	fputs(newfile[idx], fp);
	free(newfile[idx]);
    }
    if (file_pos < filesize) {
	truncate(inifile, file_pos);
    }
    free(newfile[idx]);
    fclose(fp);
    return 0;

}

--- NEW FILE: nxutil.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MWINCLUDECOLORS
#include <nano-X.h>
#include "nxdraw.h"
#include <wm/nxlib.h>

/*
nxterm -title nxterm -geom WxH+X+Y
nxclock -0+0
nxkbd -geom +0-0 -background 1 -style 44
nxscribble -geom -0-0
nxkbd -nomove -nofocus -noraise -appwindow -appframe -border -caption

nxARGS args[] = {
	nxTITLE(DEF_TITLE),
	nxGEOMETRY(DEF_GEOMETRY),
	nxBACKGROUND(GR_COLOR_WINDOW),
	nxSTYLE(GR_WM_PROPS_NOAUTOMOVE|GR_WM_PROPS_BORDER|GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX),
	nxEND
};
	wid = nxCreateAppWindow(&ac, &av, args);
*/

/*
 * Initialize application from nxARGS array and
 * passed user argument list.
 * Create new window with calculated style, geometry,
 * color and background.
 */
GR_WINDOW_ID
nxCreateAppWindow(int *aac, char ***aav, nxARGS * alist)
{
    int ac = *aac - 1;
    char **av = *aav + 1;
    nxARGS *pargs;
    int i;
    GR_COORD x, y;
    GR_SIZE w, h;
    char *title = NULL;
    char *defgeom = "100x100+100+150";
    char *usergeom = NULL;
    GR_COLOR background = GR_COLOR_APPWINDOW;
    GR_WM_PROPS style = GR_WM_PROPS_APPWINDOW;

    /* first traverse initialization list */
    for (pargs = alist; pargs->type; ++pargs) {
	switch (pargs->type & 0xff) {
	case nxtypeTITLE:
	    title = pargs->defvalue;
	    break;
	case nxtypeGEOMETRY:
	    defgeom = pargs->defvalue;
	    break;
	case nxtypeBACKGROUND:
	    background = (GR_COLOR) pargs->defvalue;
	    break;
	case nxtypeSTYLE:
	    style = (GR_WM_PROPS) pargs->defvalue;
	    break;
	}
    }

    /* then traverse passed user argument list */
    for (i = 0; i < ac; ++i) {
	for (pargs = alist; pargs->type; ++pargs) {
	    if (strcmp(av[i], pargs->optname) == 0) {
		if (i == ac - 1) {
		    printf("nxArgs: %s missing option\n", pargs->optname);
		    break;
		}
		++i;
		switch (pargs->type & 0xff) {
		case nxtypeTITLE:
		    title = av[i];
		    break;
		case nxtypeGEOMETRY:
		    usergeom = av[i];
		    break;
		case nxtypeBACKGROUND:
		    background = atoi(av[i]);
		    break;
		case nxtypeSTYLE:
		    style = atoi(av[i]);
		    break;
		}
		break;
	    }
	}
    }

    /* return ptr to first unused arg */
    av += ac;
    *aac = ac;
    *aav = av;

    /* parse geometry */
    nxGetGeometry(usergeom, defgeom, style, &x, &y, &w, &h);

    /* convert color */
    background = GrGetSysColor(background);

    /* create window and specify properties and title */
    return GrNewWindowEx(style, title, GR_ROOT_WINDOW_ID, x, y, w, h,
			 background);
}

/* return default window decoration style (for GR_WM_PROPS_APPWINDOW)*/
GR_WM_PROPS
nxGetDefaultWindowStyle(void)
{
    static GR_SCREEN_INFO si;

    if (!si.rows)
	GrGetScreenInfo(&si);
    if (si.ws_width < 400)
	return STYLE_PDA;
    return STYLE_WEBPAD;
}

/*
 * Calculate container size and client window offsets from
 * passed client window size and style.
 */

void
nxCalcNCSize(GR_WM_PROPS style, GR_SIZE wClient, GR_SIZE hClient,
	     GR_COORD * xCliOffset, GR_COORD * yCliOffset,
	     GR_SIZE * wContainer, GR_SIZE * hContainer)
{
    GR_SIZE width, height;
    GR_SIZE xoffset, yoffset;

    /* determine container size and client child window offsets */
    if (style & GR_WM_PROPS_APPFRAME) {
	width = wClient + CXFRAME;
	height = hClient + CYFRAME;
	xoffset = CXBORDER;
	yoffset = CYBORDER;
    } else if (style & GR_WM_PROPS_BORDER) {
	width = wClient + 2;
	height = hClient + 2;
	xoffset = 1;
	yoffset = 1;
    } else {
	width = wClient;
	height = hClient;
	xoffset = 0;
	yoffset = 0;
    }
    if (style & GR_WM_PROPS_CAPTION) {
	height += CYCAPTION;
	yoffset += CYCAPTION;
	if (style & GR_WM_PROPS_APPFRAME) {
	    /* extra line under caption with appframe */
	    ++height;
	    ++yoffset;
	}
    }

    if (xCliOffset)
	*xCliOffset = xoffset;
    if (yCliOffset)
	*yCliOffset = yoffset;
    if (wContainer)
	*wContainer = width;
    if (hContainer)
	*hContainer = height;
}



/*
 * Calculate client size window offsets from
 * passed container window size and style.
 */
void
nxCalcClientSize(GR_WM_PROPS style, GR_SIZE wContainer, GR_SIZE hContainer,
		 GR_COORD * xCliOffset, GR_COORD * yCliOffset,
		 GR_SIZE * wClient, GR_SIZE * hClient)
{
    GR_SIZE width, height;
    GR_SIZE xoffset, yoffset;

    /* determine client size and window offsets */
    if (style & GR_WM_PROPS_APPFRAME) {
	width = wContainer - CXFRAME;
	height = hContainer - CYFRAME;
	xoffset = CXBORDER;
	yoffset = CYBORDER;
    } else if (style & GR_WM_PROPS_BORDER) {
	width = wContainer - 2;
	height = hContainer - 2;
	xoffset = 1;
	yoffset = 1;
    } else {
	width = wContainer;
	height = hContainer;
	xoffset = 0;
	yoffset = 0;
    }
    if (style & GR_WM_PROPS_CAPTION) {
	height -= CYCAPTION;
	yoffset += CYCAPTION;
	if (style & GR_WM_PROPS_APPFRAME) {
	    /* extra line under caption with appframe */
	    --height;
	    ++yoffset;
	}
    }

    if (xCliOffset)
	*xCliOffset = xoffset;
    if (yCliOffset)
	*yCliOffset = yoffset;
    if (wClient)
	*wClient = width;
    if (hClient)
	*hClient = height;
}

--- NEW FILE: iniread.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pwd.h>
#include <wm/nxlib.h>
#include <errno.h>

//#define USERAMFILE 1
//#include "ramfile.h"

/*
 * This file contains all the INI read/write functions, as well as
 * anything having to do with finding, reading or writing config files 
 */

#if MAC
#define EOLCHAR	'\r'
#else
#define EOLCHAR	'\n'
#endif

#define MODE_RT		"rt"	/* read text */
#define ISblank(c)	((c) == ' ' || (c) == '\t')

/* private data*/
int _sawsection;
int _lineno;
char _lineblank;

int
IniGetString(char *section, char *key, char *defval, char *retbuf, int bufsiz,
	     char *inifile)
{
    char *p;
    char *q = 0;
    FILE *fp;
    char buf[256];
    char buf2[256];

    _sawsection = 0;
    _lineno = 0;
    _lineblank = 1;
    if ((fp = fopen(inifile, MODE_RT)) == NULL) {
      def:
	strzcpy(retbuf, defval, bufsiz);
	return (0);		/* not found */
    }
    if (key != NULL) {
	if (bufsiz > sizeof(buf))
	    bufsiz = sizeof(buf);
    } else
	q = retbuf;
    while (fgets(buf, sizeof(buf) - 1, fp) != NULL) {
	_lineno++;
	_lineblank = (buf[0] == EOLCHAR);
	if (buf[0] == '[') {
	    if ((p = strchr(buf, ']')) != NULL)
		*p = 0;
	    if (strcasecmp(buf + 1, section) == 0) {
		_sawsection = _lineno;
		while (fgets(buf, sizeof(buf) - 1, fp) != NULL) {
		    if (buf[0] == '[')
			goto notfound;
		    _lineno++;
		    _lineblank = (buf[0] == EOLCHAR);
		    /* enumeration case */
		    if (key == NULL) {
			if (_lineblank || buf[0] == ';')
			    continue;
			p = buf;
			while (bufsiz > 1) {
			    if (*p == EOLCHAR || *p == 0) {
				*q++ = 0;
				bufsiz--;
				break;
			    } else {
				*q++ = *p;
				bufsiz--;
			    }
			    p++;
			}
			continue;
		    }
		    p = buf;
		    q = buf2;
		    while (ISblank(*p))
			p++;
		    while (*p && *p != '=' /***&& !ISblank( *p)***/ )
			*q++ = *p++;
		    while (q > buf2 && ISblank(q[-1]))
			--q;
		    *q = 0;
		    if (strcasecmp(key, buf2) == 0) {
						/***while( ISblank( *p))
							p++;***/
			if (*p == '=')
			    p++;
			while (ISblank(*p))
			    p++;
			for (q = retbuf; bufsiz-- > 1;) {
			    if (*p == EOLCHAR || *p == 0)
				break;
			    *q++ = *p++;
			}
			*q = 0;
			fclose(fp);
			/* we return 1 instead of q-retbuf here
			 * so that IniWriteString() works with key=(null) strs
			 */
			return (q - retbuf ? q - retbuf : 1);
		    }
		}
	    }
	}
    }
  notfound:
    fclose(fp);
    if (key == NULL) {
	if (q == retbuf)	/* handle no enumeration case */
	    *q++ = 0;
	*q = 0;			/* double nul char terminate */
	return (q - retbuf);	/* return byte count copied minus NUL */
    }
    goto def;
}

/* 
 * Call a function for each enumerated key/value pair
 */
void
IniEnumKeyValues(char *buf, void (*pfn) (char *, char *, int), int data)
{
    char *list;
    char *q;
    char key[256];

    for (list = buf; *list;) {
	/* parse key */
	q = key;
	while (ISblank(*list))
	    list++;
	while (*list && *list != '=' && !ISblank(*list))
	    *q++ = *list++;
	*q = 0;

	/* skip separator */
	if (*list == '=')
	    list++;
	while (ISblank(*list))
	    list++;

	pfn(key, list, data);
	list += strlen(list) + 1;
    }
}

/* Replace the given keyword in the given string with the given value */

void
str_replace_variable(char *keyword, char *value,
		     char *input, char *output, int outsize)
{
    char *in = input;
    char *out = output;
    int size = 0;

    char *pos;

    if (!in || !out)
	return;

    if (!strlen(in))
	return;

    /* Zero out the output just in case */
    bzero(out, outsize);

    while (1 && *in) {
	/* If the string doesn't exist, then copy the rest out and bail */
	pos = strstr(in, keyword);

	if (!pos) {
	    if ((size + strlen(in)) > outsize)
		strncpy(out, in, outsize - size - 1);
	    else
		strcpy(out, in);

	    return;
	} else {
	    int subsize = 0;

	    if ((subsize = (int) (pos - in))) {
		if ((size + subsize) > outsize) {
		    strncpy(out, in, outsize - size - 1);
		    return;
		} else
		    strncpy(out, in, subsize);

		in += subsize;
		out += subsize;
		size += subsize;
	    }

	    if ((size + strlen(value)) > outsize) {
		strncpy(out, value, outsize - size);
		return;
	    } else
		strcpy(out, value);

	    in += strlen(keyword);
	    out += strlen(value);
	    size += strlen(value);
	}
    }
}

#ifdef NOTUSED

/* We can now have mulitiple configuration files.  To make it */
/* easy, we have an array of pointers that store the locations */
/* of the various config files */

static char nxConfigFiles[256][NX_CONFIG_COUNT];

/* This routine will find a config file in the standard locations */
/* and store it's value in the array at the indicated index */

int
nxLoadConfigFile(char *filename, int index)
{
    char foundfile[512];

    char etcdir[] = "/etc";
    char *searchdirs[3];
    char cwd[512];

    int res;
    int scount;
    uid_t uid;
    struct passwd *pwd;

    if (index > NX_CONFIG_COUNT)
	return (-1);

    if ((strlen(nxConfigFiles[index]))) {
	printf("Found config file [%s]\n", nxConfigFiles[index]);
	return (1);
    }

    printf("Searching for config file [%s]\n", filename);

    getcwd(cwd, 512);
    searchdirs[0] = cwd;	/* Always look in the local dir first */

    uid = getuid();		/* Get the uid of the current process */
    pwd = getpwuid(uid);	/* Get the user information from passwd */

    if (pwd) {			/* If the user was found in the password file */
	searchdirs[1] = pwd->pw_dir;	/* Search homedir second */
	searchdirs[2] = etcdir;	/* Search /etc third */
	scount = 3;
    } else {
	searchdirs[1] = etcdir;	/* Search /etc second */
	scount = 2;
    }

    res = nxSearchForFile(filename, foundfile, sizeof(foundfile),
			  searchdirs, scount);

    if (res == 0) {
	printf("Unable to find config file [%s] in path\n", filename);
    } else {
	printf("Found config file [%s]\n", foundfile);

	bzero(&nxConfigFiles[index], 256);

	strncpy(nxConfigFiles[index], foundfile, 255);
    }

    return (res);
}

char *
nxGetConfigFile(int index)
{
    if (strlen(nxConfigFiles[index]))
	return (nxConfigFiles[index]);

    return (0);
}

void
nxFreeConfigFiles()
{
}

#endif

--- NEW FILE: scrtoplib.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


/* This sends a generic message to the screentop */

#include <stdio.h>
#include <string.h>

#include <ipc/colosseum.h>
#include <wm/scrtoplib.h>

static int scrtopId = 0;

static int
sendScrtopMessage(scrtop_message * msg, int size)
{

    int id;

    /* See if we need to resolve the screentop id */
    if (!scrtopId) {
	id = ClFindApp("nxscrtop");
	if (id <= 0) {
	    fprintf(stderr,
		    "Error - Got error %d while talking to the screentop\n",
		    id);
	    return (-1);
	}

	scrtopId = id;
    }

    return (ClSendMessage(scrtopId, (void *) msg, size));
}

int
scrtopDoAction(int type, char *app)
{

    scrtop_action action;
    action.type = type;

    strncpy(action.app, app, sizeof(action.app) - 1);
    return (sendScrtopMessage((scrtop_message *) & action, sizeof(action)));
}

--- NEW FILE: strzcpy.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <wm/nxlib.h>

void
strzcpy(char *dst, char *src, int count)
{
    if (NULL == src)
	return;
    while (--count > 0)
	if ((*dst++ = *src++) == '\0')
	    return;
    *dst = 0;
}

--- NEW FILE: nxgeom.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include "nano-X.h"
#include "nxdraw.h"
#include <wm/nxlib.h>

/*
Copyright 1989, 1998  The Open Group
Copyright 1985, 1986, 1987,1998  The Open Group

All Rights Reserved.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/

/* 
 * Bitmask returned by ParseGeometry().  Each bit tells if the corresponding
 * value (x, y, width, height) was found in the parsed string.
 */
#define NoValue		0x0000
#define XValue  	0x0001
#define YValue		0x0002
#define WidthValue  	0x0004
#define HeightValue  	0x0008
#define AllValues 	0x000F
#define XNegative 	0x0010
#define YNegative 	0x0020

/*
 *   ParseGeometry parses strings of the form
 *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
 *   width, height, xoffset, and yoffset are unsigned integers.
 *   Example:  "=80x24+300-49"
 *   The equal sign is optional.
 *   It returns a bitmask that indicates which of the four values
 *   were actually found in the string.  For each value found,
 *   the corresponding argument is updated;  for each value
 *   not found, the corresponding argument is left unchanged. 
 */
static int
ReadInteger(char *string, char **NextString)
{
    int Result = 0;
    int Sign = 1;

    if (*string == '+')
	string++;
    else if (*string == '-') {
	string++;
	Sign = -1;
    }
    for (; (*string >= '0') && (*string <= '9'); string++)
	Result = (Result * 10) + (*string - '0');
    *NextString = string;
    if (Sign >= 0)
	return (Result);
    return (-Result);
}

static int
ParseGeometry(char *string, int *x, int *y, unsigned int *width,
	      unsigned int *height)
{
    int mask = NoValue;
    register char *strind;
    unsigned int tempWidth = 0, tempHeight = 0;
    int tempX = 0, tempY = 0;
    char *nextCharacter;

    if ((string == NULL) || (*string == '\0'))
	return (mask);
    if (*string == '=')
	string++;		/* ignore possible '=' at beg of geometry spec */

    strind = (char *) string;
    if (*strind != '+' && *strind != '-' && *strind != 'x') {
	tempWidth = ReadInteger(strind, &nextCharacter);
	if (strind == nextCharacter)
	    return (0);
	strind = nextCharacter;
	mask |= WidthValue;
    }

    if (*strind == 'x' || *strind == 'X') {
	strind++;
	tempHeight = ReadInteger(strind, &nextCharacter);
	if (strind == nextCharacter)
	    return (0);
	strind = nextCharacter;
	mask |= HeightValue;
    }

    if ((*strind == '+') || (*strind == '-')) {
	if (*strind == '-') {
	    strind++;
	    tempX = -ReadInteger(strind, &nextCharacter);
	    if (strind == nextCharacter)
		return (0);
	    strind = nextCharacter;
	    mask |= XNegative;

	} else {
	    strind++;
	    tempX = ReadInteger(strind, &nextCharacter);
	    if (strind == nextCharacter)
		return (0);
	    strind = nextCharacter;
	}
	mask |= XValue;
	if ((*strind == '+') || (*strind == '-')) {
	    if (*strind == '-') {
		strind++;
		tempY = -ReadInteger(strind, &nextCharacter);
		if (strind == nextCharacter)
		    return (0);
		strind = nextCharacter;
		mask |= YNegative;

	    } else {
		strind++;
		tempY = ReadInteger(strind, &nextCharacter);
		if (strind == nextCharacter)
		    return (0);
		strind = nextCharacter;
	    }
	    mask |= YValue;
	}
    }

    /* If strind isn't at the end of the string the it's an invalid
       geometry specification. */

    if (*strind != '\0')
	return (0);

    if (mask & XValue)
	*x = tempX;
    if (mask & YValue)
	*y = tempY;
    if (mask & WidthValue)
	*width = tempWidth;
    if (mask & HeightValue)
	*height = tempHeight;
    return (mask);
}

/*
 * This routine given a user supplied positional argument and a default
 * argument (fully qualified) will return the position the window should take.
 * Always sets all return values and returns a mask describing which fields
 * were set by the user or'ed with whether or not the x and y values should
 * be considered "negative".
 */
int
nxGetGeometry(GR_CHAR * user_geom,	/* user provided geometry spec */
	      GR_CHAR * def_geom,	/* default geometry spec for window */
	      GR_WM_PROPS style,	/* window style */
	      GR_COORD * x_return,	/* location of window */
	      GR_COORD * y_return,	/* location of window */
	      GR_SIZE * width_return,	/* size of window */
	      GR_SIZE * height_return)
{				/* size of window */
    int ux, uy;			/* returned values from parse */
    unsigned int uwidth, uheight;	/* returned values from parse */
    int umask;			/* parse mask of returned values */
    int dx, dy;			/* default values from parse */
    unsigned int dwidth, dheight;	/* default values from parse */
    int dmask;			/* parse mask of returned values */
    int min_width, min_height;	/* valid amounts */
    int rx, ry, rwidth, rheight;	/* return values */
    int rmask;			/* return mask */
    int cxborder = 0, cyborder = 0;
    GR_SCREEN_INFO si;
#define SCREENWIDTH	si.ws_width	/* useable workspace width */
#define SCREENHEIGHT	si.ws_height	/* useable workspace height */

    GrGetScreenInfo(&si);

    /*
     * Calc correct border sizes
     */
    // FIXME put in nxCalcBorderSizes
    if ((style & GR_WM_PROPS_APPMASK) == GR_WM_PROPS_APPWINDOW)
	style = (style & ~GR_WM_PROPS_APPMASK) | nxGetDefaultWindowStyle();
    if (style & GR_WM_PROPS_BORDER) {
	cxborder = 1 * 2;
	cyborder = 1 * 2;
    }
    /* appframe overrides border */
    if (style & GR_WM_PROPS_APPFRAME) {
	cxborder = 0 * 2;
	cyborder = 0 * 2;
    }
    if (style & GR_WM_PROPS_CAPTION) {
	cyborder += 16;
    }

    /*
     * parse the two geometry masks
     */
    rmask = umask = ParseGeometry(user_geom, &ux, &uy, &uwidth, &uheight);
    dmask = ParseGeometry(def_geom, &dx, &dy, &dwidth, &dheight);

    /*
     * get the width and height:
     *     1.  if user-specified, then take that value
     *     2.  else, if program-specified, then take that value
     *     3.  else, take 1
     */
    rwidth = ((umask & WidthValue) ? uwidth :
	      ((dmask & WidthValue) ? dwidth : 1));
    rheight = ((umask & HeightValue) ? uheight :
	       ((dmask & HeightValue) ? dheight : 1));

    /*
     * Make sure computed size is within limits.  Note that we always do the
     * lower bounds check since the base size (which defaults to 0) should
     * be used if a minimum size isn't specified.
     */
    min_width = 0;
    min_height = 0;
    if (rwidth < min_width)
	rwidth = min_width;
    if (rheight < min_height)
	rheight = min_height;

    /*
     * Compute the location.  Set the negative flags in the return mask
     * (and watch out for borders), if necessary.
     */
    if (umask & XValue) {
	rx = ((umask & XNegative) ?
	      (SCREENWIDTH + ux - rwidth - cxborder) : ux);
    } else if (dmask & XValue) {
	if (dmask & XNegative) {
	    rx = (SCREENWIDTH + dx - rwidth - cxborder);
	    rmask |= XNegative;
	} else
	    rx = dx;
    } else {
	rx = 0;			/* gotta choose something... */
    }

    if (umask & YValue) {
	ry = ((umask & YNegative) ?
	      (SCREENHEIGHT + uy - rheight - cyborder) : uy);
    } else if (dmask & YValue) {
	if (dmask & YNegative) {
	    ry = (SCREENHEIGHT + dy - rheight - cyborder);
	    rmask |= YNegative;
	} else
	    ry = dy;
    } else {
	ry = 0;			/* gotta choose something... */
    }

    /*
     * All finished, so set the return variables.
     */
    *x_return = rx;
    *y_return = ry;
    *width_return = rwidth;
    *height_return = rheight;
    return rmask;
}

#if TEST
int
main(int ac, char **av)
{
    char *geom = NULL;
    int x, y, w, h;

    if (ac > 1)
	geom = av[1];
    nxGetGeometry(geom, "320x240+10+10", 0, &x, &y, &w, &h);
    printf("%d,%d,%d,%d\n", x, y, w, h);
}
#endif

--- NEW FILE: Makefile ---
#libs/wm/Makefile

LIB_STATIC=libwm.a
LIB_SHARED=libwm.so

SRC=${shell ls *.c}
OBJS=${SRC:.c=.o}

INCLUDES=-I./include

include $(BASE_DIR)/Rules.make




--- NEW FILE: inidelsect.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pwd.h>
#include <wm/nxlib.h>
#include <errno.h>

int
IniDelSection(char *section, char *inifile)
{
    char *p;
    FILE *fp;
    char buf[256];
    int numlines = 0;
    int sectnumlines = 0;
    int sectionline = 0;
    int lineno = 0;
    char **newfile = NULL;
    struct stat filestat;
    off_t filesize;
    off_t filepos = 0;
    int err;
    int newlineno = 0;
    int idx = 0;

    if ((fp = fopen(inifile, "r+")) == NULL) {
	return (1);
    }

    err = stat(inifile, &filestat);
    if (err < 0) {
	fprintf(stderr, "Error [%s]\n", strerror(errno));
	fclose(fp);
	return 1;
    }
    filesize = filestat.st_size;
    while (NULL != fgets(buf, sizeof(buf) - 1, fp)) {
	numlines++;
    }
    rewind(fp);
    while (fgets(buf, sizeof(buf) - 1, fp) != NULL) {
	lineno++;
	if (buf[0] == '[') {
	    if ((p = strchr(buf, ']')) != NULL) {
		*p = 0;
	    }
	}
	if (strcasecmp(buf + 1, section) == 0) {
	    sectionline = lineno;
	    //sectnumlines++;
	    while (fgets(buf, sizeof(buf) - 1, fp) != NULL) {
		sectnumlines++;
		if (buf[0] == '[') {
		    sectnumlines--;
		    break;
		}
	    }
	    if ((newfile =
		 (char **) calloc(numlines + 1, sizeof(char *))) == NULL) {
		fclose(fp);
		return 1;
	    }
	    rewind(fp);
	    filepos = 0;
	    lineno = 0;
	    while (NULL != fgets(buf, sizeof(buf) - 1, fp)) {
		lineno++;
		if ((lineno < sectionline)
		    || (lineno > sectionline + sectnumlines)) {
		    newfile[newlineno] =
			(char *) calloc(strlen(buf) + 1, sizeof(char));
		    if (newfile[newlineno] == NULL) {
			fclose(fp);
			free(newfile);
			return 1;
		    }
		    filepos += strlen(buf);
		    strncpy(newfile[newlineno], buf, strlen(buf));
		    newlineno++;
		}
	    }
	    rewind(fp);
	    for (idx = 0; idx < newlineno; idx++) {
		fputs(newfile[idx], fp);
		free(newfile[idx]);
	    }
	    if (filepos < filesize) {
		truncate(inifile, filepos);
	    }
	    free(newfile[idx]);
	    fclose(fp);
	    return 0;
	}
    }
    fclose(fp);
    return 0;
}

--- NEW FILE: nxlist.c ---
/*                                                                       
 * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.     
 *                                                                       
 * This file is part of the PIXIL Operating Environment                 
 *                                                                       
 * The use, copying and distribution of this file is governed by one    
 * of two licenses, the PIXIL Commercial License, or the GNU General    
 * Public License, version 2.                                           
 *                                                                       
 * Licensees holding a valid PIXIL Commercial License may use this file 
 * in accordance with the PIXIL Commercial License Agreement provided   
 * with the Software. Others are governed under the terms of the GNU   
 * General Public License version 2.                                    
 *                                                                       
 * This file may be distributed and/or modified under the terms of the  
 * GNU General Public License version 2 as published by the Free        
 * Software Foundation and appearing in the file LICENSE.GPL included   
 * in the packaging of this file.                                      
 *                                                                       
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING  
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A            
 * PARTICULAR PURPOSE.                                                  
 *                                                                       
 * RESTRICTED RIGHTS LEGEND                                             
 *                                                                     
 * Use, duplication, or disclosure by the government is subject to      
 * restriction as set forth in paragraph (b)(3)(b) of the Rights in     
 * Technical Data and Computer Software clause in DAR 7-104.9(a).       
 *                                                                      
 * See http://www.pixil.org/gpl/ for GPL licensing       
 * information.                                                         
 *                                                                      
 * See http://www.pixil.org/license.html or              
 * email cetsales at centurysoftware.com for information about the PIXIL   
 * Commercial License Agreement, or if any conditions of this licensing 
 * are not clear to you.                                                
 */


#include <stdio.h>
#include <stdlib.h>
#include <nano-X.h>
#include <wm/nxlib.h>

void *
nxItemAlloc(unsigned int size)
{
    return (void *) calloc(size, 1);
}

/* insert at tail of list*/
void
nxListAdd(PNXLISTHEAD pHead, PNXLIST pItem)
{
    if (pHead->tail) {
	pItem->prev = pHead->tail;
	pHead->tail->next = pItem;
    } else
	pItem->prev = NULL;
    pItem->next = NULL;
    pHead->tail = pItem;
    if (!pHead->head)
	pHead->head = pItem;
}

/* insert at head of list*/
void
nxListInsert(PNXLISTHEAD pHead, PNXLIST pItem)
{
    if (pHead->head) {
	pItem->next = pHead->head;
	pHead->head->prev = pItem;
    } else
	pItem->next = NULL;
    pItem->prev = NULL;
    pHead->head = pItem;
    if (!pHead->head)
	pHead->head = pItem;
}

void
nxListRemove(PNXLISTHEAD pHead, PNXLIST pItem)
{
    if (pItem->next)
	pItem->next->prev = pItem->prev;
    if (pItem->prev)
	pItem->prev->next = pItem->next;
    if (pHead->head == pItem)
	pHead->head = pItem->next;
    if (pHead->tail == pItem)
	pHead->tail = pItem->prev;
    pItem->next = pItem->prev = NULL;
}




More information about the dslinux-commit mailing list