📄 psapi.c
字号:
val.ev_real = nval;
val.ev_handle = BADHANDLE;
loc = g_pdparms;
loc.l_sub1 = element;
_Store(&loc, &val); // Store the new value.
}
/*----------------------------------------------------------------------+
| Store a character value in our local copy of _PDPARMS |
+----------------------------------------------------------------------*/
static void LocalpdStoreCVal(int element, TEXT FAR *string, USHORT slen)
{
MHANDLE handle;
if ((element = FindLocalele(element)) == -1) // Is it a local element?
return;
handle = _AllocHand(slen);
if (handle == BADHANDLE)
_Error(182); // Insufficient Memory
if (g_pdElement[element])
_FreeHand(g_pdElement[element]); // Free the old handle
if (handle != BADHANDLE)
{
_MemMove((TEXT FAR *)_HandToPtr(handle), string, slen);
g_pdElement[element] = handle; // Save the new value's handle
g_pdELen[element] = slen;
}
else
{
g_pdElement[element] = BADHANDLE;
g_pdELen[element] = 0;
}
}
/*----------------------------------------------------------------------+
| Store a character type to an element in the actual _PDPARMS array |
+----------------------------------------------------------------------*/
static void pdStoreCVal(int element, TEXT FAR *string, USHORT slen, TEXT stlocal)
{
Locator loc;
Value val;
if (stlocal)
LocalpdStoreCVal(element, string, slen); // Store a local copy.
val.ev_type = 'C'; // Setup the Value structure.
val.ev_handle = _AllocHand(slen);
if (val.ev_handle != BADHANDLE)
{
val.ev_length = slen;
_MemMove(_HandToPtr(val.ev_handle), string, slen);
}
else
val.ev_length = 0;
loc = g_pdparms; // Our Locator of _PDPARMS
loc.l_sub1 = element;
_Store(&loc, &val); // Store the element
}
/*----------------------------------------------------------------------+
| Call the FoxPro User Procedure which accompanies this element. |
+----------------------------------------------------------------------*/
static void ParseExtern(int element, Value FAR *val)
{
int created, lelement;
Locator loc;
TEXT buff[512], numtext[10];
/* Execute the User Procedure if there is one. */
if (((lelement = FindLocalele(element)) != -1)
&& (g_pdELen[lelement] != 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 void RetBinary(TEXT FAR *sourcechars, USHORT sourcelen, int element)
{
Value retval;
MHANDLE mhand;
retval.ev_type = 'C';
retval.ev_length = sourcelen;
mhand = _AllocHand(retval.ev_length);
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 Procedure
_RetVal(&retval); // Pass this along to the printer
}
/*----------------------------------------------------------------------+
| mydiv() checks for division by zero and returns a zero if an attempt|
| was made to do so. otherwise, it returns d1 divided by d2. |
+----------------------------------------------------------------------*/
static double mydiv(double d1, double d2)
{
if (d2 == 0)
return 0;
else
return d1/d2;
}
/*----------------------------------------------------------------------+
| Check for the special line characters within an object. If the |
| line characters are found, then output the correct Postscript |
| procedure code which will draw the correct character. This is done |
| for the soul purpose that Postscript does not handle the graphic |
| symbols correctly. |
+----------------------------------------------------------------------*/
static MHANDLE chk_special(MHANDLE srchand, int FAR *srclen, USHORT styles)
{
MHANDLE reshand; // The resultant handle
TEXT FAR *restext;
TEXT FAR *srctext;
TEXT FAR *srcend;
TEXT numstr[4];
TEXT buff[PDALLOCSIZE], buff2[PDALLOCSIZE];
USHORT i, reslen=0, x;
TEXT lastaline=FALSE, rjorctr[5];
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;
if (styles & P_CENTER) // Centered?
_StrCpy(rjorctr, "ctr ");
else if (styles & P_RIGHT) // Right justified?
_StrCpy(rjorctr, "rj ");
else
rjorctr[0] = 0;
PDAddChars(restext, "xy ", &reslen);
if ((*srctext > 178) && (*srctext < 219))
lastaline = TRUE; // Flag the last char. as a line.
else
{
if (styles & P_UNDERLINE) // Underline the object
PDAddChars(restext, "u1 (", &reslen);
else
PDAddChars(restext, "(", &reslen);
lastaline = FALSE;
}
/*----------------------------------------------------------------------+
| Parse the object's characters one at a time checking for a graphic |
| character. If one is found, then output the correct Postscript |
| code for showing the text and for drawing the graphic character. |
| |
| Note: All graphic characters (ASCII 179 - 219) are drawn through |
| procedures written in Postscript. These procedures are output to |
| the Postscript printer at document start time. The procedure's name|
| that is to be called is the actual graphic character. |
+----------------------------------------------------------------------*/
for (i=0; srctext < srcend; srctext++, i++)
{
if ((*srctext > 178) && (*srctext < 219)) // It's a Line!
{
if (lastaline) // Was the last one a line?
PDAdd1Char(restext, *srctext, &reslen);
else
{
PDAddChars(restext, ") ", &reslen);
PDAddChars(restext, rjorctr, &reslen);
if (styles & P_UNDERLINE)
PDAddChars(restext, "u2 ", &reslen);
else
PDAddChars(restext, "say ", &reslen);
PDAddChars(restext, "mtxy ", &reslen);
NumToStr(i, buff2);
PDAddChars(restext, buff2, &reslen);
PDAddChars(restext, " 0 rmt ", &reslen);
PDAdd1Char(restext, *srctext, &reslen);
lastaline = TRUE;
}
PDAdd1Char(restext, ' ', &reslen);
}
else // It's a text char.
{
if (lastaline) // But did we have a line last?
{
PDAddChars(restext, "draw mtxy ", &reslen);
NumToStr(i, buff);
PDAddChars(restext, buff, &reslen);
PDAddChars(restext, " 0 rmt (", &reslen);
}
/*----------------------------------------------------------------------+
| Certain characters other than graphic characters need to be checked |
| for. These characters are ones in which they have special meaning |
| to the Postscript language. These characters are Ctrl-Z Ctrl-D |
| \ ( ). When these are encountered, they are dealt with accordingly.|
+----------------------------------------------------------------------*/
switch (*srctext)
{
case 0x04: // Ctrl-D and Ctrl-Z would normally tell
case 0x1A: // Postscript to end the job. We replace with a space
PDAdd1Char(restext, 32, &reslen);
break;
case '(': // Parenthesis and the backslash have special
case ')': // meaning in Postscript. So, we need to add
case '\\': // another backslach too make Postscript not eval. it
PDAdd1Char(restext, 92, &reslen);
default: // Add the current character
PDAdd1Char(restext, *srctext, &reslen);
}
lastaline = FALSE;
}
}
if (lastaline)
{
PDAdd1Char(restext, ' ', &reslen);
PDAddChars(restext, "draw ", &reslen);
}
else // Add the styles
{
PDAddChars(restext, ") ", &reslen);
PDAddChars(restext, rjorctr, &reslen);
if (styles & P_UNDERLINE)
PDAddChars(restext, "u2 ", &reslen);
else
PDAddChars(restext, "say ", &reslen);
}
PDAdd1Char(restext, ' ', &reslen);
_HUnLock(reshand);
_HUnLock(srchand);
*srclen = reslen;
_SetHandSize(reshand, reslen); // Resize the handle to the correct size
return reshand; // Return the string we put together
}
static loadPDParms(int start, int end)
{
int element, lelement; // the element we are addressing
int errcode=0, i; // internal error code
Locator loc; // a locator to _PDPARMS
Value val; // the value structure for _PDPARMS
// Load in certain element of _PDPARMS in our local copy.
for (element=start; element < end; element++)
{
if (((lelement = FindLocalele(element + 1)) != -1)
&& (lelement < PDLOCALELES))
{
loc = g_pdparms;
loc.l_sub1 = element + 1;
if (errcode = _Load(&loc, &val))
break;
// Only save character types
if ((val.ev_type != 'C') || (val.ev_handle == BADHANDLE))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -