⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 driver2.c

📁 用汇编语言或高级语言编写的源程序翻译成机器可执行的机器语言程序的工具称为“语言处理程序.
💻 C
📖 第 1 页 / 共 3 页
字号:
	else
	    create = TRUE;
    }
    else                                // we couldn't find the NTI of _PDPARMS
        create = TRUE;                  // so, it needs to be created.

    if (create)                 // Create FoxPro's _PDPARMS
    {
	loc.l_subs = 0;

        if (errcode = _NewVar("_PDPARMS", &loc, NV_PUBLIC) < 0)
	    _Error(errcode);
	else
	    varflag = TRUE;
    }

    if (varflag)                        // If we need to signal an error in loading
    {                                   // the printer drivers, we do so by filling
        val.ev_type = 'I';              // the first element of _PDPARMS with -1.
	val.ev_width = 10;
	val.ev_long = -1;
	_Store(&loc, &val);
    }
}

/*----------------------------------------------------------------------+
 |  Release the array of handles which we have accumulated for our copy |
 |  of _PDPARMS.  This only done if the value in _PDPARMS(43) is 1.     |
 +----------------------------------------------------------------------*/
FAR pdonunload()
{
    int		element;
    MHANDLE	hand;


    if (pdNval(43) == 1)
        _Release(g_pdparms.l_NTI);
    else
        pdStoreNVal(43, pdNval(43) - 1);

    for (element=0; element < PDELEMENTS; element++)
    {
        if (hand = g_pdElement[element])
	    _FreeHand(hand);
    }
}

/*----------------------------------------------------------------------+
 |  Call the FoxPro User Procedure which accompanies this element.      |
 +----------------------------------------------------------------------*/
static ParseExtern(int element, Value FAR *val)
{
    int 	created;
    Locator	loc;
    TEXT	buff[512], numtext[10];

    /* Execute the User Procedure if there is one.	*/
    if (g_pdELen[element-1] != 0)
    {
	loc.l_subs = 0;
        created = _NewVar("_ctlchars", &loc, NV_PUBLIC);        // create our parameter variable

        if (created >= 0)
	{
	    created = _Store(&loc, val);

	    if (created == 0)
	    {
		_StrCpy(buff, "DO (LOCFILE(_pdparms[");
		NumToStr(element, numtext);
		_StrCpy(buff + _StrLen(buff), numtext);
		_StrCpy(buff + _StrLen(buff), "], 'PRG;APP;SPR;FXP;SPX', 'Where is ' + _pdparms[");
		_StrCpy(buff + _StrLen(buff), numtext);
                _StrCpy(buff + _StrLen(buff), "] + '?')) WITH _ctlchars");

                created = _Execute(buff);       // Execute the User Procedure passing it
                                                // everything we have built and will be
                                                // sending to the printer.

	        if (!created)
		{
                    _FreeHand(val->ev_handle);
                    _Load(&loc, val);           // Load the parameter back in
                    _Release(loc.l_NTI);        // and release the parameter variable.
		}
	    }

	    if (val->ev_type != 'C')
	    {
                _FreeHand(val->ev_handle);
		val->ev_handle = BADHANDLE;
		val->ev_length = 0;
	    }

	}
    }
}

/*----------------------------------------------------------------------+
 |  Return a value back to FoxPro and call the User Procedure.          |
 +----------------------------------------------------------------------*/
static RetBinary(TEXT FAR *sourcechars, int sourcelen, int element)
{
    Value	retval;
    MHANDLE	mhand;

    retval.ev_type   = 'C';
    retval.ev_length = sourcelen;

    mhand = _AllocHand(sourcelen);
    if (mhand == BADHANDLE)
        _Error(182);                    /* Insufficient Memory */

    if ((mhand != BADHANDLE) && sourcelen)
        _MemMove(_HandToPtr(mhand), sourcechars, sourcelen);


    retval.ev_handle = mhand;

    if (element > 0)
        ParseExtern(element, &retval);          // Call the User Proc.

    _RetVal(&retval);                           // Pass this along to the printer
}

/*----------------------------------------------------------------------+
 |  Add a form feed to the escape codes we have put together so far.    |
 +----------------------------------------------------------------------*/
static doff(TEXT FAR *ctlchars, int FAR *ctllen)
{
    int         bufflen=0, buff2len=0;
    int         j;
    double      tmargin=0;
    TEXT        buff[1024];
    TEXT        buff2[64];

    pdCval(6, ctlchars, ctllen);                // Form feed value

    if (*ctllen == 0)                           // If the database didn't have a
    {                                           // form feed value, then use FF+CR
        ctlchars[0] = 12;   /* FF   */
        ctlchars[1] = 13;   /* CR   */
        *ctllen = 2;
    }

    pdCval(40, buff, &bufflen);                 // Take care of the top margin

    if (!bufflen)
    {
        pdCval(22, buff2, &buff2len);
        if (!buff2len)
        {
           buff2[0] = 13;
           buff2[1] = 10;
           buff2[2] = 0;
           buff2len = 2;
        }

        tmargin = pdNval(41);                   // Replicate the number of lines
        for (j=0; j < tmargin; j++)             // for the top margin.
        {
            _StrCpy(ctlchars + *ctllen, buff2);
            *ctllen += buff2len;
        }
    }
}

/*----------------------------------------------------------------------+
 |  Check for the special line characters within an object.  If the     |
 |  line characters are found, then output the correct positioning      |
 |  command which will move to the correct column.                      |
 +----------------------------------------------------------------------*/
static void chk_special(MHANDLE srchand, int FAR *srclen)
{
    MHANDLE		reshand;					// The resultant handle
    TEXT FAR	*restext;
    TEXT FAR	*srctext;
    TEXT FAR	*srcend;
    int			i, reslen=0;

    reshand = _AllocHand(PDALLOCSIZE);		// Allocate memory for the result
    if (reshand == BADHANDLE)
        _Error(182);						// Insufficient memory

    _HLock(reshand);						// We must lock the handle in order
    restext = _HandToPtr(reshand);			// To use it as a pointer.

    _HLock(srchand);			   			// The handle to the object
    srctext = _HandToPtr(srchand);
    srcend = srctext + *srclen;

    for (i=0; srctext < srcend; srctext++, i++)
	{
		if ((*srctext > 178) && (*srctext < 219))	// It's a graphic character!
		{
			pdCval(23, restext, &reslen);
			reslen += NumToStr(g_graph_width * g_curcolumn, restext + reslen);
			pdCval(24, restext, &reslen);
		}

		*(restext + reslen) = *srctext;
		reslen++;
		if (reslen >= PDALLOCSIZE)
		{
			_HUnLock(reshand);
			if (!_SetHandSize(reshand, reslen + PDALLOCSIZE))
				_Error(182);				// Insufficient memory.

			_HLock(reshand);
			restext = _HandToPtr(reshand);
		}
		g_curcolumn++;

	}

	_HUnLock(reshand);
    _HUnLock(srchand);

	_SetHandSize(srchand, reslen);
	_MemMove(_HandToPtr(srchand), _HandToPtr(reshand), reslen);
    *srclen = reslen;

	_FreeHand(reshand);

	return;
}


/*----------------------------------------------------------------------+
 |  PDObject is the procedure which gets called everytime FoxPro is     |
 |  about to print any kind of object.  This includes fields, text,     |
 |  boxes, numbers, etc.  Each object can have an attribute associated  |
 |  with it.  This printer driver does not take into account if a user  |
 |  has enclosed his own attribute characters in the style code box.    |
 |  Thus, if it encounters any that are meaningful to himself, he will  |
 |  use them.                                                           |
 |                                                                      |
 |  This routine also builds the starting and ending codes that would   |
 |  normally be sent on object start and object end.  This is done for  |
 |  efficiency reasons.                                                 |
 +----------------------------------------------------------------------*/

FAR pdobject(ParamBlk FAR *pblk)
{
    TEXT        startchars[256], endchars[256];         // start and end esc codes
    int		startlen=0, endlen=0, i, j;
    TEXT        FAR *attribs;                   // the objects attributes
    Value	retval;
    MHANDLE     mhand, mhand2;                  // handles for the object and attrib.
    unsigned    styles=0;                       // flag if any styles have been used
	double		num_len=0;


    g_sendff = TRUE;                    // Set flag to say we have output text
    mhand = pblk->p[1].val.ev_handle;           // The handle for the attribs.
    i = pblk->p[1].val.ev_length;               // length of the attribs.

	if (!g_curlin)
	{
        pdCval(22, startchars, &startlen);

        if (startlen == 0)
        {
            startchars[0] = 13;   /* CR   */
            startchars[1] = 10;   /* LF   */
            startlen = 2;
        }
		g_curlin = 1;
	}


    g_bop = FALSE;

    if (g_caplen)               // output capture buffer
    {
        _MemMove((TEXT FAR *)startchars + startlen,
            ((TEXT FAR *)_HandToPtr(g_capture)), g_caplen);
        startlen += g_caplen;
        g_caplen = 0;
    }

    if (i || startlen)          // If there are attributes or we have already built text
    {
        if (i)                  // attributes?
        {
            _HLock(mhand);
            attribs = ((TEXT FAR *)_HandToPtr(mhand));

            for (j = 0; j < i; j++)             // parse the attributes string
            {
                switch(attribs[j])
                {
                case 'B':
                                            /* The object is BOLD         */
                    if (!(styles & P_BOLD))
                    {
                        pdCval(11, startchars, &startlen);

                        pdCval(12, endchars, &endlen);

                        styles |= P_BOLD;
                    }

                    break;

                case 'I':
                                            /* The object is ITALIC        */
                    if (!(styles & P_ITALIC))
                    {
                        pdCval(15, startchars, &startlen);

                        pdCval(16, endchars, &endlen);

                        styles |= P_ITALIC;
                    }

                    break;

                case 'R':
                                            /* The object is SUPERSCRIPT   */
                    if (!(styles & P_RAISED) && !(styles & P_LOWERED))
                    {
                        pdCval(17, startchars, &startlen);

                        pdCval(8,  endchars, &endlen);
                        pdCval(18, endchars, &endlen);

                        styles |= P_RAISED;
                    }

                    break;

                case 'L':
                                            /* The object is SUBSCRIPT     */
                    if (!(styles & P_RAISED) && !(styles & P_LOWERED))
                    {
                        pdCval(19, startchars, &startlen);

                        pdCval(8,  endchars, &endlen);
                        pdCval(20, endchars, &endlen);

                        styles |= P_LOWERED;
                    }

                    break;

                case 'U':
                                            /* The object is UNDERLINED    */
                    if (!(styles & P_UNDERLINE))
                    {
                        pdCval(13, startchars, &startlen);

                        pdCval(14, endchars, &endlen);

                        styles |= P_UNDERLINE;
                    }

                    break;

				case 'J':
											/* The object is Right Justified. 	*/
					if (pdNval(49))
					{
						num_len = ((double) (pblk->p[0].val.ev_length - LeftTrim( & (pblk->p[0].val) )))
										 * pdNval(51);

						if (styles & (P_RAISED + P_LOWERED))
							num_len /= 2;

						if (num_len)
						{
							pdCval(23, startchars, &startlen);
							startchars[startlen] = '+';
							startlen++;

        					startlen += RealNumToStr(num_len, startchars + startlen, 2);
							pdCval(24, startchars, &startlen);
						}
					}
					break;

				case 'C':
											/* The object is Centered.	*/
					if (pdNval(49))
					{
						num_len = ((double) (pblk->p[0].val.ev_length - LeftTrim( & (pblk->p[0].val) )) / 2)
										 * pdNval(51);

						if (styles & (P_RAISED + P_LOWERED))
							num_len /= 2;

						if (num_len)
						{
							pdCval(23, startchars, &startlen);
							startchars[startlen] = '+';
							startlen++;

        					startlen += RealNumToStr(num_len, startchars + startlen, 2);
							pdCval(24, startchars, &startlen);
						}

					}
                    }
                }

            _HUnLock(mhand);
        }

    		  /* Prepare to return the resultant codes and string	*/
		i      = pblk->p[0].val.ev_length;
		mhand2 = pblk->p[0].val.ev_handle;


		mhand = _AllocHand(i + startlen + endlen);

		if (mhand == BADHANDLE)
			_Error(182);			// Insufficient memory.

        if (startlen)
		{							// Move the starting ctlchars for the object
		    _MemMove(_HandToPtr(mhand),
			startchars,
		    startlen);
		}

		if (g_graph_width)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -