Exemple #1
0
XPanoramiXInfo *XPanoramiXAllocInfo(void)
{
	return (XPanoramiXInfo *) Xmalloc (sizeof (XPanoramiXInfo));
}
Exemple #2
0
void glGetSeparableFilter(GLenum target, GLenum format, GLenum type,
			  GLvoid *row, GLvoid *column, GLvoid *span)
{
    __GLX_SINGLE_DECLARE_VARIABLES();
    const __GLXattribute * state;
    xGLXGetSeparableFilterReply reply;
    GLubyte *rowBuf, *colBuf;

    if (!dpy) return;
    __GLX_SINGLE_LOAD_VARIABLES();
    state = gc->client_state_private;

    /* Send request */
    __GLX_SINGLE_BEGIN(X_GLsop_GetSeparableFilter, __GLX_PAD(13));
    __GLX_SINGLE_PUT_LONG(0,target);
    __GLX_SINGLE_PUT_LONG(4,format);
    __GLX_SINGLE_PUT_LONG(8,type);
    __GLX_SINGLE_PUT_CHAR(12,state->storePack.swapEndian);
    __GLX_SINGLE_READ_XREPLY();
    compsize = reply.length << 2;

    if (compsize != 0) {
	GLint width, height;
	GLint widthsize, heightsize;

	width = reply.width;
	height = reply.height;

	widthsize = __glImageSize(width,1,1,format, type);
	heightsize = __glImageSize(height,1,1,format, type);

	/* Allocate a holding buffer to transform the data from */
	rowBuf = (GLubyte*) Xmalloc(widthsize);
	if (!rowBuf) {
	    /* Throw data away */
	    _XEatData(dpy, compsize);
	    __glXSetError(gc, GL_OUT_OF_MEMORY);
	    UnlockDisplay(dpy);
	    SyncHandle();
	    return;
	} else {
	    __GLX_SINGLE_GET_CHAR_ARRAY(((char*)rowBuf),widthsize);
	    __glEmptyImage(gc, 1, width, 1, 1, format, type, rowBuf, row);
	    Xfree((char*) rowBuf);
	}
	colBuf = (GLubyte*) Xmalloc(heightsize);
	if (!colBuf) {
	    /* Throw data away */
	    _XEatData(dpy, compsize - __GLX_PAD(widthsize));
	    __glXSetError(gc, GL_OUT_OF_MEMORY);
	    UnlockDisplay(dpy);
	    SyncHandle();
	    return;
	} else {
	    __GLX_SINGLE_GET_CHAR_ARRAY(((char*)colBuf),heightsize);
	    __glEmptyImage(gc, 1, height, 1, 1, format, type, colBuf, column);
	    Xfree((char*) colBuf);
	}
    } else {
	/*
	** don't modify user's buffer.
	*/
    }
    __GLX_SINGLE_END();
    
}
Exemple #3
0
int
XReadBitmapFileData (
    _Xconst char *filename,
    unsigned int *width,                /* RETURNED */
    unsigned int *height,               /* RETURNED */
    unsigned char **data,               /* RETURNED */
    int *x_hot,                         /* RETURNED */
    int *y_hot)                         /* RETURNED */
{
    FILE *fstream;			/* handle on file  */
    unsigned char *bits = NULL;		/* working variable */
    char line[MAX_SIZE];		/* input line from file */
    int size;				/* number of bytes of data */
    char name_and_type[MAX_SIZE];	/* an input line */
    char *type;				/* for parsing */
    int value;				/* from an input line */
    int version10p;			/* boolean, old format */
    int padding;			/* to handle alignment */
    int bytes_per_line;			/* per scanline of data */
    unsigned int ww = 0;		/* width */
    unsigned int hh = 0;		/* height */
    int hx = -1;			/* x hotspot */
    int hy = -1;			/* y hotspot */

#ifdef __UNIXOS2__
    filename = __XOS2RedirRoot(filename);
#endif
    if (!(fstream = fopen(filename, "r")))
	return BitmapOpenFailed;

    /* error cleanup and return macro	*/
#define	RETURN(code) \
{ if (bits) Xfree ((char *)bits); fclose (fstream); return code; }

    while (fgets(line, MAX_SIZE, fstream)) {
	if (strlen(line) == MAX_SIZE-1)
	    RETURN (BitmapFileInvalid);
	if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) {
	    if (!(type = strrchr(name_and_type, '_')))
	      type = name_and_type;
	    else
	      type++;

	    if (!strcmp("width", type))
	      ww = (unsigned int) value;
	    if (!strcmp("height", type))
	      hh = (unsigned int) value;
	    if (!strcmp("hot", type)) {
		if (type-- == name_and_type || type-- == name_and_type)
		  continue;
		if (!strcmp("x_hot", type))
		  hx = value;
		if (!strcmp("y_hot", type))
		  hy = value;
	    }
	    continue;
	}

	if (sscanf(line, "static short %s = {", name_and_type) == 1)
	  version10p = 1;
	else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1)
	  version10p = 0;
	else if (sscanf(line, "static char %s = {", name_and_type) == 1)
	  version10p = 0;
	else
	  continue;

	if (!(type = strrchr(name_and_type, '_')))
	  type = name_and_type;
	else
	  type++;

	if (strcmp("bits[]", type))
	  continue;

	if (!ww || !hh)
	  RETURN (BitmapFileInvalid);

	if ((ww % 16) && ((ww % 16) < 9) && version10p)
	  padding = 1;
	else
	  padding = 0;

	bytes_per_line = (ww+7)/8 + padding;

	size = bytes_per_line * hh;
	bits = (unsigned char *) Xmalloc ((unsigned int) size);
	if (!bits)
	  RETURN (BitmapNoMemory);

	if (version10p) {
	    unsigned char *ptr;
	    int bytes;

	    for (bytes=0, ptr=bits; bytes<size; (bytes += 2)) {
		if ((value = NextInt(fstream)) < 0)
		  RETURN (BitmapFileInvalid);
		*(ptr++) = value;
		if (!padding || ((bytes+2) % bytes_per_line))
		  *(ptr++) = value >> 8;
	    }
	} else {
	    unsigned char *ptr;
	    int bytes;

	    for (bytes=0, ptr=bits; bytes<size; bytes++, ptr++) {
		if ((value = NextInt(fstream)) < 0)
		  RETURN (BitmapFileInvalid);
		*ptr=value;
	    }
	}
    }					/* end while */
Exemple #4
0
/*
 *	NAME
 *		_XcmsLookupColorName - Lookup DB entry for a color name
 *
 *	SYNOPSIS
 */
static Status
_XcmsLookupColorName(
    XcmsCCC ccc,
    const char **name,
    XcmsColor *pColor)
/*
 *	DESCRIPTION
 *		Searches for an entry in the Device-Independent Color Name
 *		Database for the specified string.
 *
 *	RETURNS
 *		XcmsFailure if failed to find a matching entry in
 *			the database.
 *		XcmsSuccess if succeeded in converting color name to
 *			XcmsColor.
 *		_XCMS_NEWNAME if succeeded in converting color string (which
 *			is a color name to yet another color name.  Note
 *			that the new name is passed back via 'name'.
 */
 {
    Status		retval = 0;
    char		name_lowered_64[64];
    char		*name_lowered;
    register int	i, j, left, right;
    int			len;
    const char		*tmpName;
    XcmsPair		*pair = NULL;

    /*
     * Check state of Database:
     *		XcmsDbInitNone
     *		XcmsDbInitSuccess
     *		XcmsDbInitFailure
     */
    if (XcmsColorDbState == XcmsDbInitFailure) {
	return(XcmsFailure);
    }
    if (XcmsColorDbState == XcmsDbInitNone) {
	if (!LoadColornameDB()) {
	    return(XcmsFailure);
	}
    }

    SetNoVisit();

    /*
     * While copying name to name_lowered, convert to lowercase
     */

    tmpName = *name;

Retry:
    if ((len = strlen(tmpName)) > 63) {
	name_lowered = (char *) Xmalloc(len+1);
    } else {
	name_lowered = name_lowered_64;
    }

    _XcmsCopyISOLatin1Lowered(name_lowered, tmpName);

    /*
     * Now, remove spaces.
     */
    for (i = 0, j = 0; j < len; j++) {
	if (!isspace(name_lowered[j])) {
	    name_lowered[i++] = name_lowered[j];
	}
    }
    name_lowered[i] = '\0';

    left = 0;
    right = nEntries - 1;
    while (left <= right) {
	i = (left + right) >> 1;
	pair = &pairs[i];
	j = strcmp(name_lowered, pair->first);
	if (j < 0)
	    right = i - 1;
	else if (j > 0)
	    left = i + 1;
	else {
	    break;
	}
    }
    if (len > 63) Xfree(name_lowered);

    if (left > right) {
	if (retval == 2) {
	    if (*name != tmpName) {
		*name = tmpName;
	    }
	    return(_XCMS_NEWNAME);
	}
	return(XcmsFailure);
    }

    if (pair->flag == CYCLE) {
	return(XcmsFailure);
    }
    if (pair->flag == VISITED) {
	pair->flag = CYCLE;
	return(XcmsFailure);
    }

    if (_XcmsParseColorString(ccc, pair->second, pColor) == XcmsSuccess) {
	/* f2 contains a numerical string specification */
	return(XcmsSuccess);
    } else {
	/* f2 does not contain a numerical string specification */
	tmpName = pair->second;
	pair->flag = VISITED;
	retval = 2;
	goto Retry;
    }
}
Exemple #5
0
/*
 *	NAME
 *		LoadColornameDB - Load the Color Name Database
 *
 *	SYNOPSIS
 */
static Status
LoadColornameDB(void)
/*
 *	DESCRIPTION
 *		Loads the Color Name Database from a text file.
 *
 *	RETURNS
 *		XcmsSuccess if succeeded, otherwise XcmsFailure.
 *
 */
{
    int size;
    FILE *stream;
    const char *pathname;
    struct stat txt;
    int length;

    /* use and name of this env var is not part of the standard */
    /* implementation-dependent feature */
    if ((pathname = getenv("XCMSDB")) == NULL) {
	pathname = XCMSDB;
    }

    length = strlen(pathname);
    if ((length == 0) || (length >= (BUFSIZ - 5))){
	XcmsColorDbState = XcmsDbInitFailure;
	return(XcmsFailure);
    }

    if (stat(pathname, &txt)) {
	/* can't stat file */
	XcmsColorDbState = XcmsDbInitFailure;
	return(XcmsFailure);
    }

//  if ((stream = _XFopenFile (pathname, "r")) == NULL) {
    if ((stream = fopen (pathname, "r")) == NULL) {
	/* can't open file */
	XcmsColorDbState = XcmsDbInitFailure;
	return(XcmsFailure);
    }

    if (stringSectionSize(stream, &nEntries, &size) != XcmsSuccess ||
	nEntries == 0) {
	(void) fclose(stream);
	XcmsColorDbState = XcmsDbInitFailure;
	return(XcmsFailure);
    }
    rewind(stream);

    strings = (char *) Xmalloc(size);
    pairs = (XcmsPair *)Xcalloc(nEntries, sizeof(XcmsPair));

    ReadColornameDB(stream, pairs, strings);
    (void) fclose(stream);

    /*
     * sort the pair recs
     */
    qsort((char *)pairs, nEntries, sizeof(XcmsPair), FirstCmp);

    XcmsColorDbState = XcmsDbInitSuccess;
    return(XcmsSuccess);
}
/**
 * Get a drawable's attribute.
 *
 * This function is used to implement \c glXGetSelectedEvent and
 * \c glXGetSelectedEventSGIX.
 *
 * \note
 * This function dynamically determines whether to use the SGIX_pbuffer
 * version of the protocol or the GLX 1.3 version of the protocol.
 *
 * \todo
 * The number of attributes returned is likely to be small, probably less than
 * 10.  Given that, this routine should try to use an array on the stack to
 * capture the reply rather than always calling Xmalloc.
 *
 * \todo
 * This function needs to be modified to work with direct-rendering drivers.
 */
static int
GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
                     int attribute, unsigned int *value)
{
   __GLXdisplayPrivate *priv;
   xGLXGetDrawableAttributesReply reply;
   CARD32 *data;
   CARD8 opcode;
   unsigned int length;
   unsigned int i;
   unsigned int num_attributes;
   GLboolean use_glx_1_3;

   if ((dpy == NULL) || (drawable == 0)) {
      return 0;
   }

   priv = __glXInitialize(dpy);
   use_glx_1_3 = ((priv->majorVersion > 1) || (priv->minorVersion >= 3));

   *value = 0;


   opcode = __glXSetupForCommand(dpy);
   if (!opcode)
      return 0;

   LockDisplay(dpy);

   if (use_glx_1_3) {
      xGLXGetDrawableAttributesReq *req;

      GetReqExtra(GLXGetDrawableAttributes, 4, req);
      req->reqType = opcode;
      req->glxCode = X_GLXGetDrawableAttributes;
      req->drawable = drawable;
   }
   else {
      xGLXVendorPrivateWithReplyReq *vpreq;

      GetReqExtra(GLXVendorPrivateWithReply, 4, vpreq);
      data = (CARD32 *) (vpreq + 1);
      data[0] = (CARD32) drawable;

      vpreq->reqType = opcode;
      vpreq->glxCode = X_GLXVendorPrivateWithReply;
      vpreq->vendorCode = X_GLXvop_GetDrawableAttributesSGIX;
   }

   _XReply(dpy, (xReply *) & reply, 0, False);

   if (reply.type == X_Error) {
      UnlockDisplay(dpy);
      SyncHandle();
      return 0;
   }

   length = reply.length;
   if (length) {
      num_attributes = (use_glx_1_3) ? reply.numAttribs : length / 2;
      data = (CARD32 *) Xmalloc(length * sizeof(CARD32));
      if (data == NULL) {
         /* Throw data on the floor */
         _XEatData(dpy, length);
      }
      else {
         _XRead(dpy, (char *) data, length * sizeof(CARD32));

         /* Search the set of returned attributes for the attribute requested by
          * the caller.
          */
         for (i = 0; i < num_attributes; i++) {
            if (data[i * 2] == attribute) {
               *value = data[(i * 2) + 1];
               break;
            }
         }

#ifdef GLX_DIRECT_RENDERING
         {
            __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);

            if (pdraw != NULL && !pdraw->textureTarget)
               pdraw->textureTarget =
                  determineTextureTarget((const int *) data, num_attributes);
            if (pdraw != NULL && !pdraw->textureFormat)
               pdraw->textureFormat =
                  determineTextureFormat((const int *) data, num_attributes);
         }
#endif

         Xfree(data);
      }
   }

   UnlockDisplay(dpy);
   SyncHandle();

   return 0;
}
Exemple #7
0
static int
_XTextPropertyToTextList(
    XLCd lcd,
    Display *dpy,
    const XTextProperty *text_prop,
    const char *to_type,
    XPointer **list_ret,
    int *count_ret)
{
    XlcConv conv = NULL;
    const char *from_type;
    XPointer from, to, buf;
    char *str_ptr, *last_ptr;
    Atom encoding;
    int from_left, to_left, buf_len, ret, len;
    int unconv_num, nitems = text_prop->nitems;
    Bool is_wide_char = False, do_strcpy = False;

    if (strcmp(XlcNWideChar, to_type) == 0)
	is_wide_char = True;

    if (nitems <= 0) {
	*list_ret = NULL;
	*count_ret = 0;
	return Success;
    }

    if (text_prop->format != 8)
	return XConverterNotFound;

    encoding = text_prop->encoding;
    if (encoding == XA_STRING)
	from_type = XlcNString;
    else if (encoding == XInternAtom(dpy, "UTF8_STRING", False))
	from_type = XlcNUtf8String;
    else if (encoding == XInternAtom(dpy, "COMPOUND_TEXT", False))
	from_type = XlcNCompoundText;
    else if (encoding == XInternAtom(dpy, XLC_PUBLIC(lcd, encoding_name), False))
	from_type = XlcNMultiByte;
    else
	return XConverterNotFound;

    if (is_wide_char) {
	buf_len = (text_prop->nitems + 1) * sizeof(wchar_t);
    } else {
	if (strcmp(to_type, XlcNUtf8String) == 0)
	    buf_len = text_prop->nitems * 6 + 1;
	else
	    buf_len = text_prop->nitems * XLC_PUBLIC(lcd, mb_cur_max) + 1;
    }
    buf = Xmalloc(buf_len);
    if (buf == NULL)
	return XNoMemory;
    to = buf;
    to_left = buf_len;

    /* can be XlcNMultiByte to XlcNMultiByte,
       or XlcNUtf8String to XlcNUtf8String */
    if (!strcmp(from_type, to_type)) {
        do_strcpy = True;
    } else {
        conv = _XlcOpenConverter(lcd, from_type, lcd, to_type);
        if (conv == NULL) {
	    Xfree(buf);
	    return XConverterNotFound;
        }
    }

    last_ptr = str_ptr = (char *) text_prop->value;
    unconv_num = *count_ret = 0;

    while (1) {
	if (nitems == 0 || *str_ptr == 0) {
	    from = (XPointer) last_ptr;
	    from_left = str_ptr - last_ptr;
	    last_ptr = str_ptr;

            if (do_strcpy) {
            	len = min(from_left, to_left);
                strncpy(to, from, len);
                from += len;
                to += len;
                from_left -= len;
                to_left -= len;
                ret = 0;
            } else {
	        ret = _XlcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0);
            }

	    if (ret < 0)
		continue;

	    unconv_num += ret;
	    (*count_ret)++;

	    if (nitems == 0)
		break;
 	    last_ptr = ++str_ptr;
	    if (is_wide_char) {
		*((wchar_t *)to) = (wchar_t) 0;
		to += sizeof(wchar_t);
		to_left -= sizeof(wchar_t);
	    } else {
		*((char *)to) = '\0';
		to++;
		to_left--;
	    }
	    if (! do_strcpy)
	        _XlcResetConverter(conv);
	} else
	    str_ptr++;

	nitems--;
    }

    if (! do_strcpy)
        _XlcCloseConverter(conv);

    if (is_wide_char) {
	*((wchar_t *) to) = (wchar_t) 0;
	to_left -= sizeof(wchar_t);
    } else {
	*((char *) to) = '\0';
	to_left--;
    }

    *list_ret = alloc_list(is_wide_char, *count_ret, buf_len - to_left);
    if (*list_ret)
	copy_list(is_wide_char, buf, *list_ret, *count_ret);

    Xfree(buf);

    return unconv_num;
}
Exemple #8
0
XFixesCursorImage *
XFixesGetCursorImage (Display *dpy)
{
    XFixesExtDisplayInfo		*info = XFixesFindDisplay (dpy);
    xXFixesGetCursorImageAndNameReq	*req;
    xXFixesGetCursorImageAndNameReply	rep;
    int					npixels;
    int					nbytes_name;
    int					nbytes, nread, rlength;
    XFixesCursorImage			*image;
    char				*name;

    XFixesCheckExtension (dpy, info, 0);
    LockDisplay (dpy);
    GetReq (XFixesGetCursorImageAndName, req);
    req->reqType = info->codes->major_opcode;
    if (info->major_version >= 2)
	req->xfixesReqType = X_XFixesGetCursorImageAndName;
    else
	req->xfixesReqType = X_XFixesGetCursorImage;
    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
    {
	UnlockDisplay (dpy);
	SyncHandle ();
	return 0;
    }
    if (info->major_version < 2)
    {
	rep.cursorName = None;
	rep.nbytes = 0;
    }
    npixels = rep.width * rep.height;
    nbytes_name = rep.nbytes;
    /* reply data length */
    nbytes = (long) rep.length << 2;
    /* bytes of actual data in the reply */
    nread = (npixels << 2) + nbytes_name;
    /* size of data returned to application */
    rlength = (sizeof (XFixesCursorImage) + 
	       npixels * sizeof (unsigned long) +
	       nbytes_name + 1);

    image = (XFixesCursorImage *) Xmalloc (rlength);
    if (!image)
    {
	_XEatData (dpy, nbytes);
	UnlockDisplay (dpy);
	SyncHandle ();
	return 0;
    }
    image->x = rep.x;
    image->y = rep.y;
    image->width = rep.width;
    image->height = rep.height;
    image->xhot = rep.xhot;
    image->yhot = rep.yhot;
    image->cursor_serial = rep.cursorSerial;
    image->pixels = (unsigned long *) (image + 1);
    image->atom = rep.cursorName;
    name = (char *) (image->pixels + npixels);
    image->name = name;
    _XRead32 (dpy, image->pixels, npixels << 2);
    _XRead (dpy, name, nbytes_name);
    name[nbytes_name] = '\0';	/* null-terminate */
    /* skip any padding */
    if(nbytes > nread)
    {
	_XEatData (dpy, (unsigned long) (nbytes - nread));
    }
    UnlockDisplay (dpy);
    SyncHandle ();
    return image;
}
Exemple #9
0
/*
 * XdbeGetVisualInfo -
 *	This function returns information about which visuals support
 *	double buffering.  The argument num_screens specifies how many
 *	elements there are in the screen_specifiers list.  Each drawable
 *	in screen_specifiers designates a screen for which the supported
 *	visuals are being requested.  If num_screens is zero, information
 *	for all screens is requested.  In this case, upon return from this
 *	function, num_screens will be set to the number of screens that were
 *	found.  If an error occurs, this function returns NULL, else it returns
 *	a pointer to a list of XdbeScreenVisualInfo structures of length
 *	num_screens.  The nth element in the returned list corresponds to the
 *	nth drawable in the screen_specifiers list, unless num_screens was
 *	passed in with the value zero, in which case the nth element in the
 *	returned list corresponds to the nth screen of the server, starting
 *	with screen zero.
 */
XdbeScreenVisualInfo *XdbeGetVisualInfo (
    Display        *dpy,
    Drawable       *screen_specifiers,
    int            *num_screens)  /* SEND and RETURN */
{
    XExtDisplayInfo *info = find_display(dpy);
    register xDbeGetVisualInfoReq *req;
    xDbeGetVisualInfoReply rep;
    XdbeScreenVisualInfo *scrVisInfo;
    int i;

    DbeCheckExtension (dpy, info, (XdbeScreenVisualInfo *)NULL);

    LockDisplay (dpy);

    DbeGetReq(DbeGetVisualInfo, req, info);
    req->length = 2 + *num_screens;
    req->n      = *num_screens;
    Data32 (dpy, screen_specifiers, (*num_screens * sizeof (CARD32)));

    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
        UnlockDisplay (dpy);
        SyncHandle ();
        return NULL;
    }

    /* return the number of screens actually found if we
     * requested information about all screens (*num_screens == 0)
     */
    if (*num_screens == 0)
       *num_screens = rep.m;

    /* allocate list of visual information to be returned */
    if (!(scrVisInfo =
        (XdbeScreenVisualInfo *)Xmalloc(
        (unsigned)(*num_screens * sizeof(XdbeScreenVisualInfo))))) {
        UnlockDisplay (dpy);
        SyncHandle ();
        return NULL;
    }

    for (i = 0; i < *num_screens; i++)
    {
        int nbytes;
        int j;
        long c;

        _XRead32 (dpy, &c, sizeof(CARD32));
        scrVisInfo[i].count = c;

        nbytes = scrVisInfo[i].count * sizeof(XdbeVisualInfo);

        /* if we can not allocate the list of visual/depth info
         * then free the lists that we already allocate as well
         * as the visual info list itself
         */
        if (!(scrVisInfo[i].visinfo = (XdbeVisualInfo *)Xmalloc(
            (unsigned)nbytes))) {
            for (j = 0; j < i; j++) {
                Xfree ((char *)scrVisInfo[j].visinfo);
            }
            Xfree ((char *)scrVisInfo);
            UnlockDisplay (dpy);
            SyncHandle ();
            return NULL;
        }
    
        /* Read the visual info item into the wire structure.  Then copy each
         * element into the library structure.  The element sizes and/or
         * padding may be different in the two structures.
         */
        for (j = 0; j < scrVisInfo[i].count; j++) {
            xDbeVisInfo xvi;

            _XRead (dpy, (char *)&xvi, sizeof(xDbeVisInfo));
            scrVisInfo[i].visinfo[j].visual    = xvi.visualID;
            scrVisInfo[i].visinfo[j].depth     = xvi.depth;
            scrVisInfo[i].visinfo[j].perflevel = xvi.perfLevel;
        }

    }

    UnlockDisplay (dpy);
    SyncHandle ();
    return scrVisInfo;

} /* XdbeGetVisualInfo() */
Exemple #10
0
int
/*ARGSUSED*/
XGetErrorDatabaseText(
    Display *dpy,
    register _Xconst char *name,
    register _Xconst char *type,
    _Xconst char *defaultp,
    char *buffer,
    int nbytes)
{

    static XrmDatabase db = NULL;
    XrmString type_str;
    XrmValue result;
    char temp[BUFSIZ];
    char* tptr;
    unsigned long tlen;

    if (nbytes == 0) return 0;

    if (!db) {
	/* the Xrm routines expect to be called with the global
	   mutex unlocked. */
	XrmDatabase temp_db;
	int do_destroy;
	const char *dbname;

	XrmInitialize();
#ifdef WIN32
	dbname = getenv("XERRORDB");
	if (!dbname)
	    dbname = ERRORDB;
#else
    dbname = ERRORDB;
#endif
	temp_db = XrmGetFileDatabase(dbname);

	_XLockMutex(_Xglobal_lock);
	if (!db) {
	    db = temp_db;
	    do_destroy = 0;
	} else
	    do_destroy = 1;	/* we didn't need to get it after all */
	_XUnlockMutex(_Xglobal_lock);

	if (do_destroy)
	    XrmDestroyDatabase(temp_db);
    }

    if (db)
    {
	tlen = strlen (name) + strlen (type) + 2;
	if (tlen <= sizeof(temp))
	    tptr = temp;
	else
	    tptr = Xmalloc (tlen);
	if (tptr) {
	    sprintf(tptr, "%s.%s", name, type);
	    XrmGetResource(db, tptr, "ErrorType.ErrorNumber",
	      &type_str, &result);
	    if (tptr != temp)
		Xfree (tptr);
	} else {
	    result.addr = (XPointer) NULL;
	}
    }
    else
	result.addr = (XPointer)NULL;
    if (!result.addr) {
	result.addr = (XPointer) defaultp;
	result.size = strlen(defaultp) + 1;
    }
    (void) strncpy (buffer, (char *) result.addr, nbytes);
    if (result.size > nbytes) buffer[nbytes-1] = '\0';
    return 0;
}
Exemple #11
0
void
output_all_gnu_mo_files(void)
{
	struct catalog	*p, *op;
	struct messages	*m;
	size_t	id_len, str_len, id_off, str_off, ids_top, strs_top;
	unsigned int	*hash_tbl;
	unsigned int	hash_size;
	unsigned int	num = 0, fnum = 0, unum = 0;
	unsigned int	i, idx;
	char	*ids, *strs;
	struct msgtbl	*id_tbl, *str_tbl;
	struct gnu_msg_info	header;
	FILE	*out;

	p = catalog_head;

	while (p) {
		num += p->nmsg;
		fnum += p->fnum;
		unum += p->unum;


		free(p->thash);
		if (p->nmsg == 0) {
			/*
			 * no message in this file
			 * skip generating a mo
			 */
			goto skip;
		}

		if (p->header)
			num--;

		p->msg = (struct messages *)Xrealloc(p->msg,
			sizeof (struct messages) * p->nmsg);

		/*
		 * Sort the message array
		 */
		qsort(p->msg, p->nmsg, sizeof (struct messages),
			(int (*)(const void *, const void *))msg_cmp);


		hash_size = find_prime(p->nmsg);
		hash_tbl = (unsigned int *)Xcalloc(hash_size,
			sizeof (unsigned int));


		/* Setting Header info */
		header.magic = GNU_MAGIC;
		header.revision = GNU_REVISION;
		header.num_of_str = p->nmsg;
		header.off_msgid_tbl = sizeof (struct gnu_msg_info);
		header.off_msgstr_tbl = sizeof (struct gnu_msg_info) +
			p->nmsg * sizeof (struct msgtbl);
		header.sz_hashtbl = hash_size;
		header.off_hashtbl = header.off_msgstr_tbl +
			p->nmsg * sizeof (struct msgtbl);

		m = p->msg;

		id_len = 0;
		str_len = 0;
		for (i = 0; i < p->nmsg; i++) {
			id_len += m[i].id_len;
			str_len += m[i].str_len;
		}
		ids = (char *)Xmalloc(id_len);
		strs = (char *)Xmalloc(str_len);
		id_tbl = (struct msgtbl *)Xmalloc(sizeof (struct msgtbl) *
			p->nmsg);
		str_tbl = (struct msgtbl *)Xmalloc(sizeof (struct msgtbl) *
			p->nmsg);
		id_off = 0;
		str_off = 0;
		ids_top = header.off_hashtbl +
			sizeof (unsigned int) * hash_size;
		strs_top = ids_top + id_len;
		for (i = 0; i < p->nmsg; i++) {
			/*
			 * Set the hash table
			 */
			idx = get_hash_index(hash_tbl, m[i].hash, hash_size);
			hash_tbl[idx] = i + 1;

			/*
			 * rearrange msgid and msgstr
			 */
			id_tbl[i].len = m[i].id_len - 1;
			str_tbl[i].len = m[i].str_len - 1;
			id_tbl[i].offset = id_off + ids_top;
			str_tbl[i].offset = str_off + strs_top;
			(void) memcpy(ids + id_off, m[i].id, m[i].id_len);
			(void) memcpy(strs + str_off, m[i].str, m[i].str_len);
			id_off += m[i].id_len;
			str_off += m[i].str_len;
			free(m[i].id);
			free(m[i].str);
		}

		if ((out = fopen(p->fname, "w")) == NULL) {
			error(gettext(ERR_OPEN_FAILED), p->fname);
			/* NOTREACHED */
		}

		/* writing header */
		(void) fwrite(&header, sizeof (struct gnu_msg_info),
			1, out);

		/* writing msgid offset table */
		(void) fwrite(id_tbl, sizeof (struct msgtbl),
			p->nmsg, out);
		/* writing msgstr offset table */
		(void) fwrite(str_tbl, sizeof (struct msgtbl),
			p->nmsg, out);
		/* writing hash table */
		(void) fwrite(hash_tbl, sizeof (unsigned int),
			hash_size, out);
		/* writing msgid table */
		(void) fwrite(ids, id_len, 1, out);
		/* writing msgstr table */
		(void) fwrite(strs, str_len, 1, out);

		(void) fclose(out);
		free(id_tbl);
		free(str_tbl);
		free(hash_tbl);
		free(ids);
		free(strs);
skip:
		free(p->fname);
		free(p->msg);
		op = p->next;
		free(p);
		p = op;
	}
	if (verbose_flag) {
		diag(gettext(DIAG_RESULTS), num, fnum, unum);
	}
}
/*
 * XFixesExtAddDisplay - add a display to this extension. (Replaces
 * XextAddDisplay)
 */
static XFixesExtDisplayInfo *
XFixesExtAddDisplay (XFixesExtInfo *extinfo,
                      Display        *dpy,
                      char           *ext_name)
{
    XFixesExtDisplayInfo    *info;
    int			    ev;

    info = (XFixesExtDisplayInfo *) Xmalloc (sizeof (XFixesExtDisplayInfo));
    if (!info) return NULL;
    info->display = dpy;

    info->codes = XInitExtension (dpy, ext_name);

    /*
     * if the server has the extension, then we can initialize the
     * appropriate function vectors
     */
    if (info->codes) {
	xXFixesQueryVersionReply	rep;
	xXFixesQueryVersionReq	*req;
        XESetCloseDisplay (dpy, info->codes->extension,
                           XFixesCloseDisplay);
	for (ev = info->codes->first_event;
	     ev < info->codes->first_event + XFixesNumberEvents;
	     ev++)
	{
	    XESetWireToEvent (dpy, ev, XFixesWireToEvent);
	    XESetEventToWire (dpy, ev, XFixesEventToWire);
	}
	/*
	 * Get the version info
	 */
	LockDisplay (dpy);
	GetReq (XFixesQueryVersion, req);
	req->reqType = info->codes->major_opcode;
	req->xfixesReqType = X_XFixesQueryVersion;
	req->majorVersion = XFIXES_MAJOR;
	req->minorVersion = XFIXES_MINOR;
	if (!_XReply (dpy, (xReply *) &rep, 0, xTrue))
	{
	    UnlockDisplay (dpy);
	    SyncHandle ();
	    Xfree(info);
	    return NULL;
	}
	info->major_version = rep.majorVersion;
	info->minor_version = rep.minorVersion;
	UnlockDisplay (dpy);
	SyncHandle ();
    } else {
	/* The server doesn't have this extension.
	 * Use a private Xlib-internal extension to hang the close_display
	 * hook on so that the "cache" (extinfo->cur) is properly cleaned.
	 * (XBUG 7955)
	 */
	XExtCodes *codes = XAddExtension(dpy);
	if (!codes) {
	    XFree(info);
	    return NULL;
	}
        XESetCloseDisplay (dpy, codes->extension, XFixesCloseDisplay);
    }

    /*
     * now, chain it onto the list
     */
    _XLockMutex(_Xglobal_lock);
    info->next = extinfo->head;
    extinfo->head = info;
    extinfo->cur = info;
    extinfo->ndisplays++;
    _XUnlockMutex(_Xglobal_lock);
    return info;
}
Exemple #13
0
void 
GenerateWeights (void)
{
  FILE *dict, *invf, *f, *idx;
  struct invf_dict_header idh;
  struct invf_file_header ifh;
  int i;
  double logN;
  float *DocWeights;

  get_NumPara ();
  get_StaticNumOfDocs ();

  if ((f = open_file (file_name, WEIGHTS_SUFFIX, "r", MAGIC_WGHT,
		      MG_CONTINUE)) != NULL)
    {
      fclose (f);
      return;
    }

  logN = log ((double) NumPara);

  Message ("The file \"%s.weight\" does not exist.", file_name);
  Message ("Building the weight data from the file \"%s.invf\".", file_name);

  if (!(DocWeights = Xmalloc (sizeof (float) * (NumPara + 1))))
      FatalError (1, "No memory for doc weights");
  bzero ((char *) DocWeights, sizeof (float) * (NumPara + 1));

  dict = open_file (file_name, INVF_DICT_SUFFIX, "r", MAGIC_STEM_BUILD,
		    MG_ABORT);
  fread ((char *) &idh, sizeof (idh), 1, dict);

  idx = open_file (file_name, INVF_IDX_SUFFIX, "r", MAGIC_INVI,
		   MG_ABORT);

  invf = open_file (file_name, INVF_SUFFIX, "r", MAGIC_INVF,
		    MG_ABORT);
  fread ((char *) &ifh, sizeof (ifh), 1, invf);
  if (ifh.skip_mode != 0)
    FatalError (0, "Can\'t make weights file from a skipped inverted file.");
  if (ifh.InvfLevel == 1)
    FatalError (0, "Can\'t make weights file from level 1 inverted file.");

  DECODE_START (invf)

    for (i = 0; i < ifh.no_of_words; i++)
    {
      u_char dummy1, dummy2[MAXSTEMLEN + 1];
      unsigned long fcnt, wcnt, blk, CurrDoc, p, j;
      float idf;

      if ((i & 0xfff) == 0)
	fprintf (stderr, ".");
      /* read an entry for a word, just to get p value */
      dummy1 = fgetc (dict);
      dummy1 = fgetc (dict);
      fread (dummy2, sizeof (u_char), dummy1, dict);
      fread ((char *) &fcnt, sizeof (fcnt), 1, dict);
      fread ((char *) &wcnt, sizeof (wcnt), 1, dict);

      p = fcnt;

      idf = logN - log ((double) fcnt);
      blk = BIO_Bblock_Init (StaticNumOfDocs, p);
      CurrDoc = 0;

      {
	unsigned long loc;
	fread ((char *) &loc, sizeof (loc), 1, idx);
	if (ftell (invf) != loc)
	  {
	    FatalError (1, "Word %d  %d != %d", i, ftell (invf), loc);
	  }
      }
      for (j = 0; j < p; j++)
	{
	  unsigned long x, tf;
	  BBLOCK_DECODE (x, blk);
	  CurrDoc += x;
	  if (ifh.InvfLevel >= 2)
	    {
	      double weight;
	      GAMMA_DECODE (tf);
	      weight = tf * idf;
	      DocWeights[CurrDoc - 1] += weight * weight;
	    }
	}
      while (__btg)
	DECODE_BIT;
    }
  DECODE_DONE
    fclose (dict);
  fclose (invf);
  fprintf (stderr, "\n");

  f = create_file (file_name, WEIGHTS_SUFFIX, "w", MAGIC_WGHT,
		   MG_ABORT);

  fwrite ((char *) DocWeights, sizeof (float), NumPara, f);
  fclose (f);
  Xfree (DocWeights);
}
Exemple #14
0
int
CSDPSInit(
    Display *dpy,
    int *numberType,		/* RETURN */
    char **floatingName)	/* RETURN */
{
    register Display *agent;
    register xCAPConnReplyPrefix *p;
    register char *c;
    DPSCAPData my;
    xCAPConnSetupReq setup;
    union {
        xCAPConnSuccess good;
        xCAPConnFailed bad;
    } reply;
    XExtData *extData;
    XExtCodes *codes;
    int indian;
    int rest;
    Window clientWindow;
    char fullDisplayName[MAXHOSTNAMELEN+10];

    if (gCSDPS == NULL)
        DPSCAPStartUp();

    /* To fix dps-nx #68, Motif too slow on HP */
    if ((c = getenv("DPSNXGCMODE")) != 0)
        {
	gNXSyncGCMode = atoi(c);
	if (gNXSyncGCMode < DPSNXSYNCGCMODE_FLUSH
	  || gNXSyncGCMode > DPSNXSYNCGCMODE_DELAYED)
	    gNXSyncGCMode = DPSNXSYNCGCMODE_DEFAULT;
	}

    /* We may have already called this routine via XDPSExtensionPresent,
       so don't do it again! */

    if ((codes = XDPSLGetCodes(dpy))
        && (agent = XDPSLGetShunt(dpy))
        && agent != dpy
	&& codes->major_opcode == DPSXOPCODEBASE)
        return(DPSCAPSUCCESS);

    /* Try to create a window for ClientMessage communication */

    clientWindow = XCreateSimpleWindow(
      dpy,
      DefaultRootWindow(dpy),
      0, 0,
      1, 1,
      0,
      BlackPixel(dpy, DefaultScreen(dpy)),
      WhitePixel(dpy, DefaultScreen(dpy)));
    if (clientWindow == None)
        return(DPSCAPFAILED);

    /* Try to open a connection to an agent */

    if ((extData = DPSCAPOpenAgent(dpy, fullDisplayName)) == NULL)
        {
        XDestroyWindow(dpy, clientWindow);
        return(DPSCAPFAILED);
        }

    /* DPSCAPOpenAgent only partially fills in extData, so finish it */

    codes = XAddExtension(dpy);
    codes->major_opcode = DPSXOPCODEBASE;
    codes->first_event = 0;  /* REQUIRED */
    codes->first_error = FirstExtensionError;
    extData->number = codes->extension;
    extData->free_private = DPSCAPDestroy;
    my = (DPSCAPData) extData->private_data;
    my->codes = codes;
    agent = my->agent;
    /* +++ Is this all we have to do here? */

    /* Send opening handshake */

    indian = 1;
    if (*(char *) &indian)
        setup.byteorder = 'l';
    else
    	setup.byteorder = 'B';
    setup.dpscapVersion = DPSCAPPROTOVERSION;
    setup.flags = DPSCAPNONEFLAG;
    setup.libraryversion = DPSPROTOCOLVERSION;
    setup.authProtoNameLength = 0;
    setup.authProtoDataLength = 0;
    setup.displayStringLength = strlen(fullDisplayName);
    setup.nodeStringLength = 0;
    setup.transportStringLength = 0;
    setup.display = 0;
    setup.screen = 0;
    setup.reserved = 0;
    setup.clientWindow = clientWindow;

#ifndef DPSLNKL
    DPSCAPWrite(agent, (char *)&setup, sizeof(xCAPConnSetupReq), dpscap_nopad,dpscap_insert);
    DPSCAPWrite(agent, fullDisplayName, setup.displayStringLength, dpscap_pad, dpscap_append);
    N_XFlush(agent);
#else /* DPSLNKL */
    if (CSDPSConfirmDisplay(agent, dpy, &setup, &reply, fullDisplayName) == 1)
        {
	p = (xCAPConnReplyPrefix *)&reply.good;
        goto skip_read;
	}
    /* Read normal reply */
#endif /* DPSLNKL */

    /* Read common reply prefix */

    p = (xCAPConnReplyPrefix *)&reply.good;
    N_XRead(agent, (char *)p, (long)sizeof(xCAPConnReplyPrefix));
#ifdef DPSLNKL
skip_read:
#endif
    if (!p->success)
        {
	char mbuf[512];
        /* read the rest */
        c = (char *)&reply.bad.serverVersion;
        N_XRead(agent, c, sz_xCAPConnFailed - sz_xCAPConnReplyPrefix);
	sprintf(mbuf, "DPS NX: connection to \"%s\" refused by agent.", DisplayString(agent));
	DPSWarnProc(NULL, mbuf);
        c = (char *)Xmalloc(reply.bad.reasonLength);
        if (!c) return(DPSCAPFAILED);
        N_XReadPad(agent, c, (long)reply.bad.reasonLength);
	if (!reply.bad.reasonLength)
	    sprintf(mbuf, "DPS NX: (no reason given)\n");
	else
            {
	    strcpy(mbuf, "DPS NX: ");
	    strncat(mbuf, c, reply.bad.reasonLength);
	    mbuf[reply.bad.reasonLength+7] = '\0';
	    }
	DPSWarnProc(NULL, mbuf);
        Xfree(c);
        DPSCAPDestroy(extData);
        Xfree(extData);
        XDestroyWindow(dpy, clientWindow);
        return(DPSCAPFAILED);
        }

    /* read the rest of the fixed length reply */
    c = (char *)&reply.good.serverVersion;
    rest = sizeof(xCAPConnSuccess) - sizeof(xCAPConnReplyPrefix);
    N_XRead(agent, c, rest);

    /* verify */

    if (reply.good.serverVersion < DPSPROTOCOLVERSION)
        {
	/* Fine, we downgrade the client */
	char qbuf[256];
	sprintf(qbuf, "NX: server version %ld older than expected %d, client will downgrade", (long)reply.good.serverVersion, DPSPROTOCOLVERSION);
	DPSWarnProc(NULL, qbuf);
	}
    my->dpscapVersion = reply.good.dpscapVersion;
    if (my->dpscapVersion < DPSCAPPROTOVERSION)
        {
	/* Fine, we downgrade the client */
	char kbuf[256];
	sprintf(kbuf, "NX: agent version %d older than expected %d, client will downgrade", my->dpscapVersion, DPSCAPPROTOVERSION);
	DPSWarnProc(NULL, kbuf);
#ifdef XXX
        /* Saving this code as a reminder about what needs to be
	   cleaned up if we exit here */
        DPSCAPDestroy(extData);
        Xfree(extData);
        XDestroyWindow(clientWindow);
        return(DPSCAPFAILED);
#endif
	}

    if (numberType)
        *numberType = reply.good.preferredNumberFormat;

    /* read additional data */

    c = (char *)Xmalloc(reply.good.floatingNameLength + 1);
    N_XReadPad(agent, c, reply.good.floatingNameLength);
    c[reply.good.floatingNameLength] = 0;
    if (floatingName)
	*floatingName = c;
    else
	Xfree(c);

    /* set library extension data */

    XDPSLSetVersion(agent, reply.good.serverVersion);
    XDPSLSetVersion(dpy, reply.good.serverVersion);
    XDPSLSetShunt(dpy, agent);
    XDPSLSetCodes(dpy, codes);
    if (XDPSLGetSyncMask(dpy) == DPSCAP_SYNCMASK_NONE)
        XDPSLSetSyncMask(dpy, DPSCAP_SYNCMASK_DFLT);
    my->agentWindow = reply.good.agentWindow;
    XDPSLSetGCFlushMode(dpy, XDPSNX_GC_UPDATES_SLOW); /* default */

    /* Hook my extension data on the dpy */

    my->extData = extData;
    XAddToExtensionList(CSDPSHeadOfDpyExt(dpy), extData);
    (void) XESetCloseDisplay(dpy, codes->extension, DPSCAPCloseDisplayProc);
    (void) XESetCopyGC(dpy, codes->extension, DPSCAPCopyGCProc);
    (void) XESetFreeGC(dpy, codes->extension, DPSCAPFreeGCProc);
    (void) XESetFlushGC(dpy, codes->extension, DPSCAPFlushGCProc);
    XDPSLSetClientMessageHandler(dpy);

    /* Chain my data on global list */

    my->next = gCSDPS->head;
    gCSDPS->head = my;

#ifdef MAHALO
    /* Set function that is called after every Xlib protocol proc */
    XDPSLSetAfterProc(dpy);

    /* All CSDPS protocol is auto-flushed */
    (void) XSetAfterFunction(agent, DPSCAPFlushAfterProc);
#endif /* MAHALO */

    /* set agent arguments, if needed */
    /* must follow setting of ShuntMap at least, so safest to
       do here when everything has been setup */
    XDPSLUpdateAgentArgs(dpy);

    return(DPSCAPSUCCESS);
}
Exemple #15
0
static XineramaScreenInfo * XineramaGetFake(int * number)
{
  	const char * home;
	char buf[4096];
	char line[64];
	FILE * fparse;

	if (number == NULL) return NULL;

	// max: 256 screens
	int i, screens = 0;
	struct { int x, y, w, h; } scbuf[256];
	XineramaScreenInfo *scrnInfo = NULL;

	/* store in tentative, max-length 256 structure so we can allocate just the right amount for XineramaScreenInfo later on */

	home = getenv("HOME");
	if (home == NULL) return NULL;

	sprintf(buf, "%s/.fakescreens", home);

	if (NULL == (fparse = fopen(buf, "r"))) return NULL;

	while (!feof(fparse))
	{
		if (NULL != fgets(line, 64, fparse))
		{
			// read file and call sscanf in a way to consume whitespace
			if (4 == sscanf(line, " .screen %d , %d , %d , %d ", &scbuf[screens].x, &scbuf[screens].y, &scbuf[screens].w, &scbuf[screens].h ))
			{
				/*printf("screen: %d\n", screens);
				printf("\tx: %d\n", scbuf[screens].x);
				printf("\ty: %d\n", scbuf[screens].y);
				printf("\tw: %d\n", scbuf[screens].w);
				printf("\th: %d\n", scbuf[screens].h);*/

				if (++screens >= 256) { /*fprintf(stderr, "Too many screens (> 256)\n");*/ goto close; }
			}
		}
	}

	/* convert tentative structure into Xinerama structure */

	scrnInfo = Xmalloc(sizeof(XineramaScreenInfo) * screens);
	for (i = 0; i < screens; i++)
	{
		scrnInfo[i].screen_number = i;
		scrnInfo[i].x_org = scbuf[i].x;
		scrnInfo[i].y_org = scbuf[i].y;
		scrnInfo[i].width = scbuf[i].w;
		scrnInfo[i].height = scbuf[i].h;
	}

	*number = screens;
	fclose(fparse);
	return scrnInfo;

close:
	fclose(fparse);
	return NULL;
}
Exemple #16
0
static void 
MoreDocs (query_data * qd, char *Query, char OutputType)
{
  static char terms_str[MAXTERMSTRLEN + 1];
  int DocCount = 0;		/* number of actual matches */
  FILE *Output = NULL;
  int using_pipe = 0;
  char *pager = NULL;

  Ctrl_C = 0;

  qd->num_of_ans = qd->DL->num;

  signal (SIGPIPE, SIGPIPE_handler);
  signal (SIGINT, SIGINT_handler);

  PagerRunning = 1;
  if (isatty (fileno (OutFile)) && GetEnv ("pager") &&
      OutputType != OUTPUT_HILITE &&
      OutputType != OUTPUT_SILENT && OutputType != OUTPUT_COUNT)
    {
      pager = GetEnv ("pager");
    }
  else if (isatty (fileno (OutFile)) && OutputType == OUTPUT_HILITE)
    {
      /* concat the pager and its word argument strings */
      ConvertTermsToString (qd->TL, terms_str);
      pager = Xmalloc (MAX_HILITE_PAGER_STR + strlen (terms_str) + 1);
      if (!pager)
	{
	  fprintf (stderr, "Unable to allocate memory for highlighting\n");
	  return;
	}
      sprintf (pager, "%s --style=%s --pager=%s --stem_method=%ld %s",
	       HILITE_PAGER,
	       GetEnv ("hilite_style"),
	       GetEnv ("pager"),
	       qd->sd->sdh.stem_method,
	       terms_str);

    }
  else
    {
      Output = OutFile;
    }

  if (pager)
    {
      Output = popen (pager, "w");
      using_pipe = (Output != NULL);
      if (!using_pipe)
	{
	  fprintf (stderr, "Unable to run \"%s\"\n", pager);
	  return;
	}
    }


  if (qd->DL->num > 0)
    {
      if (OutputType == OUTPUT_COUNT && !post_proc)
	DocCount = qd->DL->num;
      else
	DocCount = ProcessDocs (qd, qd->DL->num,
				BooleanEnv (GetEnv ("verbatim"), 1),
				OutputType, Output);
    }

  if (PagerRunning)
    {
      output_terminator (Output);
      fflush (Output);
    }

  if (OutputType == OUTPUT_HILITE && pager)
    free (pager);		/* as needed to malloc to create the pager string */

  if (using_pipe)
    pclose (Output);

  if (qd->DL->num == 0)
    fprintf (stderr, "No entries correspond to that query.\n");
  else
    {
      if (OutputType == OUTPUT_COUNT)
	fprintf (stderr, "%d documents match.\n", DocCount);
      else
	fprintf (stderr, "%d documents retrieved.\n", DocCount);
    }

  signal (SIGINT, SIG_DFL);
}
Exemple #17
0
Bool XNVCTRLStringOperation (
    Display *dpy,
    int target_type,
    int target_id,
    unsigned int display_mask,
    unsigned int attribute,
    char *pIn,
    char **ppOut
) {
    XExtDisplayInfo *info = find_display(dpy);
    xnvCtrlStringOperationReq *req;
    xnvCtrlStringOperationReply rep;
    Bool ret;
    int inSize, outSize, length, slop;

    if (!XextHasExtension(info))
        return False;

    if (!ppOut)
        return False;

    *ppOut = NULL;

    XNVCTRLCheckExtension(dpy, info, False);
    XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);

    if (pIn) {
        inSize = strlen(pIn) + 1;
    } else {
        inSize = 0;
    }

    LockDisplay(dpy);
    GetReq(nvCtrlStringOperation, req);

    req->reqType = info->codes->major_opcode;
    req->nvReqType = X_nvCtrlStringOperation;
    req->target_type = target_type;
    req->target_id = target_id;
    req->display_mask = display_mask;
    req->attribute = attribute;

    req->length += ((inSize + 3) & ~3) >> 2;
    req->num_bytes = inSize;

    if (pIn) {
        Data(dpy, pIn, inSize);
    }

    if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
        UnlockDisplay(dpy);
        SyncHandle();
        return False;
    }

    length = rep.length;
    outSize = rep.num_bytes;
    slop = outSize & 3;

    if (outSize) *ppOut = (char *) Xmalloc(outSize);

    if (!*ppOut) {
        _XEatData(dpy, length);
    } else {
        _XRead(dpy, (char *) *ppOut, outSize);
        if (slop) _XEatData(dpy, 4-slop);
    }

    ret = rep.ret;

    UnlockDisplay(dpy);
    SyncHandle();

    return ret;
}
Exemple #18
0
/*
 * The data returned by the following routine is always in left-most byte
 * first and left-most bit first.  If it doesn't return BitmapSuccess then
 * its arguments won't have been touched.  This routine should look as much
 * like the Xlib routine XReadBitmapfile as possible.
 */
int XmuReadBitmapData (
    FILE *fstream,			/* handle on file  */
    unsigned int *width,		/* RETURNED */
    unsigned int *height,		/* RETURNED */
    unsigned char **datap,		/* RETURNED */
    int *x_hot, int *y_hot)		/* RETURNED */
{
    unsigned char *data = NULL;		/* working variable */
    char line[MAX_SIZE];		/* input line from file */
    int size;				/* number of bytes of data */
    char name_and_type[MAX_SIZE];	/* an input line */
    char *type;				/* for parsing */
    int value;				/* from an input line */
    int version10p;			/* boolean, old format */
    int padding;			/* to handle alignment */
    int bytes_per_line;			/* per scanline of data */
    unsigned int ww = 0;		/* width */
    unsigned int hh = 0;		/* height */
    int hx = -1;			/* x hotspot */
    int hy = -1;			/* y hotspot */

#ifndef Xmalloc
#define Xmalloc(size) malloc(size)
#endif

    /* first time initialization */
    if (!hex_initialized) initHexTable();

    /* error cleanup and return macro	*/
#define	RETURN(code) { if (data) free (data); return code; }

    while (fgets(line, MAX_SIZE, fstream)) {
	if (strlen(line) == MAX_SIZE-1) {
	    RETURN (BitmapFileInvalid);
	}
	if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) {
	    if (!(type = strrchr(name_and_type, '_')))
	      type = name_and_type;
	    else
	      type++;

	    if (!strcmp("width", type))
	      ww = (unsigned int) value;
	    if (!strcmp("height", type))
	      hh = (unsigned int) value;
	    if (!strcmp("hot", type)) {
		if (type-- == name_and_type || type-- == name_and_type)
		  continue;
		if (!strcmp("x_hot", type))
		  hx = value;
		if (!strcmp("y_hot", type))
		  hy = value;
	    }
	    continue;
	}

	if (sscanf(line, "static short %s = {", name_and_type) == 1)
	  version10p = 1;
	else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1)
	  version10p = 0;
	else if (sscanf(line, "static char %s = {", name_and_type) == 1)
	  version10p = 0;
	else
	  continue;

	if (!(type = strrchr(name_and_type, '_')))
	  type = name_and_type;
	else
	  type++;

	if (strcmp("bits[]", type))
	  continue;

	if (!ww || !hh)
	  RETURN (BitmapFileInvalid);

	if ((ww % 16) && ((ww % 16) < 9) && version10p)
	  padding = 1;
	else
	  padding = 0;

	bytes_per_line = (ww+7)/8 + padding;

	size = bytes_per_line * hh;
	data = (unsigned char *) Xmalloc ((unsigned int) size);
	if (!data)
	  RETURN (BitmapNoMemory);

	if (version10p) {
	    unsigned char *ptr;
	    int bytes;

	    for (bytes=0, ptr=data; bytes<size; (bytes += 2)) {
		if ((value = NextInt(fstream)) < 0)
		  RETURN (BitmapFileInvalid);
		*(ptr++) = value;
		if (!padding || ((bytes+2) % bytes_per_line))
		  *(ptr++) = value >> 8;
	    }
	} else {
	    unsigned char *ptr;
	    int bytes;

	    for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) {
		if ((value = NextInt(fstream)) < 0)
		  RETURN (BitmapFileInvalid);
		*ptr=value;
	    }
	}
	break;
    }					/* end while */