📄 psapi.c
字号:
/*----------------------------------------------------------------------+
| PSAPI.C - FoxPro postscript printer driver (C version). |
| |
| Copyright (c) 1991, Fox Holdings, Inc. |
| Fox Software System's Group |
| 134 W. South Boundary |
| Perrysburg, Ohio 43551 |
+----------------------------------------------------------------------*/
#include <pro_ext.h>
#define BADHANDLE 0 // Not a handle.
typedef unsigned short USHORT;
#define P_BOLD 1 // Bold attrib.
#define P_ITALIC (1<<1) // Italic attrib.
#define P_UNDERLINE (1<<2) // Underline attrib.
#define P_RAISED (1<<3) // Superscript attrib.
#define P_LOWERED (1<<4) // Subscript attrib.
#define P_RIGHT (1<<5) // Right justified
#define P_CENTER (1<<6) // Centered
#define PDELEMENTS 40 // Number of elements in _PDPARMS
#define PDLOCALELES 14 // Number of local elements
#define PDALLOCSIZE 1024 // Allocation size
#define NUMWIDTH 20
static Locator g_pdparms; // The locator for _PDPARMS
static MHANDLE g_pdElement[PDLOCALELES]; // The local copy of _PDPARMS
static int g_pdELen[PDLOCALELES], g_length;
static double g_lmargin;
static TEXT g_pdxref[] = {3, 12, 13, 14, 15, 16, 18, 19, 20,
24, 25, 28, 30, 32}; // A list of char. elements
/*----------------------------------------------------------------------+
| _fltused() is a null function so that WATCOM does not link in |
| unneeded code into our library. If there is ever a need to add |
| floating point functions like sprintf() and vsprintf() this routine |
| should be removed. |
+----------------------------------------------------------------------*/
void _fltused()
{
}
/*----------------------------------------------------------------------+
| This function will return True if fchr is found within the string |
| pointed to by src. |
+----------------------------------------------------------------------*/
static mystrchr(TEXT fchr, TEXT FAR *src, int srclen)
{
for (;srclen; src++, srclen--)
if (toupper(*src) == fchr)
return TRUE;
return FALSE;
}
/*----------------------------------------------------------------------+
| Return whether or not the element specified was stored in our local |
| copy. |
+----------------------------------------------------------------------*/
static int FindLocalele(int element)
{
int i;
for (i = 0; i < PDLOCALELES; i++)
if (element == g_pdxref[i])
return i;
return -1;
}
/*----------------------------------------------------------------------+
| Add one char (ch) to the string pointed to by dest. |
+----------------------------------------------------------------------*/
static PDAdd1Char(TEXT FAR *dest, TEXT ch, USHORT FAR *len)
{
dest[*len] = ch;
*len += 1;
}
/*----------------------------------------------------------------------+
| Add the string pointed to by source to the end of the string |
| pointed to by dest. |
+----------------------------------------------------------------------*/
static PDAddChars(TEXT FAR *dest, TEXT FAR *source, USHORT FAR *len)
{
_StrCpy(dest + *len, source);
*len += _StrLen(source);
}
/*----------------------------------------------------------------------+
| Add the string pointed to by source to the end of the string |
| pointed to by dest, plus a final carriage return |
+----------------------------------------------------------------------*/
static PDAddCharsandCR(TEXT FAR *dest, TEXT FAR *source, USHORT FAR *len)
{
PDAddChars(dest, source, len);
PDAdd1Char(dest, 13, len);
}
/*----------------------------------------------------------------------+
| Convert the long integer, num, to it's ASCII equivalent. |
| NOTE: This function will not round the number. |
+----------------------------------------------------------------------*/
static void NumToStr(long num, TEXT FAR *result)
{
TEXT buff[NUMWIDTH+1], FAR *firstch;
long temp;
buff[NUMWIDTH] = 0;
firstch = buff+NUMWIDTH;
do
{
temp = num / 10;
*--firstch = (num - temp * 10) + '0'; // Store the ASCII value for this digit
num = temp;
}
while (num && (firstch > buff));
_StrCpy(result, firstch); // Return the result
}
/*----------------------------------------------------------------------+
| power() will return the base parameter raised to the nth. |
+----------------------------------------------------------------------*/
static long power(int base, int n)
{
long res=base;
if (n < 1)
return 1;
while (--n)
res *= base;
return res;
}
/*----------------------------------------------------------------------+
| RealNumToStr() will convert the double real number to a character |
| string and return it in result. |
+----------------------------------------------------------------------*/
static int RealNumToStr(double d, TEXT FAR *result, int decpl)
{
TEXT buff[NUMWIDTH * 2];
long lval;
int reslen, i;
lval = d * power(10, decpl) + 0.5001;
NumToStr(lval, buff);
reslen = _StrLen(buff);
if (reslen <= decpl)
{
_StrCpy(result, "0.");
i = decpl - reslen;
_MemFill(result + 2, '0', i);
_StrCpy(result + 2 + i, buff);
}
else
{
i = reslen - decpl;
_MemMove(result, buff, i);
if (decpl)
{
result[i] = '.';
_MemMove(result + i + 1, buff + i, decpl);
i += (decpl + 1);
}
result[i] = 0;
}
return _StrLen(result);
}
/*----------------------------------------------------------------------+
| StrToNum will convert the string passed in cp into a number. |
+----------------------------------------------------------------------*/
static double StrToNum(TEXT FAR *cp, int numlen)
{
double resnum = 0.0;
int j;
for(; *cp == ' '; cp++, numlen--);
for (; isdigit(*cp) && numlen; cp++, numlen--)
resnum = (resnum * 10) + (*cp - '0');
if ((*cp == '.') && numlen--)
{
cp++;
for (j=10 ; isdigit(*cp) && numlen; cp++, numlen--, j *= 10)
resnum += ((*cp - '0') / j);
}
return resnum;
}
/*----------------------------------------------------------------------+
| Retrieve value from Local copy of _pdparms element. |
+----------------------------------------------------------------------*/
static LocalpdCval(int element, TEXT FAR *dest, USHORT FAR *destlen)
{
int len;
if ((element = FindLocalele(element)) == -1) // Check if this is a local element
return NO;
len = g_pdELen[element];
if (len == 0)
return NO;
_MemMove(dest + *destlen,
_HandToPtr(g_pdElement[element]),
len);
*destlen += len;
return YES; // We retrieved the element alright.
}
/*----------------------------------------------------------------------+
| Retrieve Character value from _pdparms directly. |
+----------------------------------------------------------------------*/
static pdCval(int element, TEXT FAR *dest, int FAR *destlen)
{
Locator loc;
Value val;
loc = g_pdparms; // Our Locator for _PDPARMS.
loc.l_sub1 = element;
if ((_Load(&loc, &val) != 0) || (val.ev_type != 'C'))
{
*destlen = 0;
return NO; // This element was not a character type.
}
if (val.ev_handle != BADHANDLE)
_MemMove(dest,
_HandToPtr(val.ev_handle),
val.ev_length);
*destlen = val.ev_length;
_FreeHand(val.ev_handle); // Free the handle we got from _Load.
return YES;
}
/*----------------------------------------------------------------------+
| Retrieve values from _pdparms directly (except for 'C' type). |
+----------------------------------------------------------------------*/
static pdVal(int element, TEXT type, Value FAR *val)
{
Locator loc;
loc = g_pdparms; // Our Locator for _PDPARMS
loc.l_sub1 = element;
if (_Load(&loc, val) != 0)
return NO;
if (val->ev_type != type)
{
if ((val->ev_type == 'C') && (val->ev_handle != BADHANDLE))
{
_FreeHand(val->ev_handle); // Free the handle from the _Load()
val->ev_handle = BADHANDLE;
}
return NO;
}
return YES;
}
/*----------------------------------------------------------------------+
| Get a Logical value from _PDPARMS |
+----------------------------------------------------------------------*/
static pdLVal(int element)
{
Value val;
if (!pdVal(element, 'L', &val))
return TRUE;
return val.ev_length;
}
/*----------------------------------------------------------------------+
| Get a Numeric or Integer value from _PDPARMS |
+----------------------------------------------------------------------*/
static double pdNval(int element)
{
Value val;
double retval;
if (pdVal(element, 'N', &val) || pdVal(element, 'I', &val))
{
retval = (val.ev_type == 'N') ? val.ev_real : val.ev_long;
return (retval);
}
return (double)0.0;
}
/*----------------------------------------------------------------------+
| Store a numeric value into an _PDPARMS element. |
+----------------------------------------------------------------------*/
static void pdStoreNVal(int element, double nval)
{
Locator loc;
Value val;
val.ev_type = 'N'; // Setup our Value Structure.
val.ev_width = 10;
val.ev_length = 4;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -