Category : Word Processors
Archive   : HP22D5.ZIP
Filename : BASE.C

 
Output of file : BASE.C contained in archive : HP22D5.ZIP
#include

#include /* include for variable number of arguments */
#include "extern.h" /* Extensions need these! */

char near buf[80];
PTR near p;
int near base;

pascal near digit(r)

int r;

{
*p++ = r > 9 ? 'A' + (r - 10) : '0' + r;
}

pascal near __tobase(d)

DWORD d;

{
unsigned long r;

if (d >= base) {
__tobase(d / base);
digit(d % base);
}
else {
digit(d);
}
}

/*
** TOBASE
**
** This function converts a decimal number to a different base.
**
** Examples:
**
** toBase(10,16) -- returns A
** toBase(10,2) -- returns 1010
**
** Syntax:
**
** toBase(,)
*/
ToBase(int NumArgs,HANDLE hNumber,HANDLE hBase)

{
DWORD d;

if (NumArgs != 2) return(STOP);

d = htol(hNumber);
base = htoi(hBase);

p = buf;
__tobase(d);
*p = '\0';

ReturnValue(stoh(buf));

return(STOP);
}

int pascal near getdigit(c)

char c;

{
return(c >= 'A' ? 10 + (c - 'A') : c - '0');
}

DWORD pascal near __frombase(s)

PTR s;

{
DWORD d = 0,b = 1;
int len;

len = strlen(s);

while (len--) {
d += getdigit(s[len]) * b;
b *= base;
}

return(d);
}

FromBase(int NumArgs,HANDLE hNumberText,HANDLE hBase)

{
DWORD d;
HANDLE hdl;

if (NumArgs != 2) return(STOP);

base = htoi(hBase);

d = __frombase(deref(hNumberText));

ReturnValue(ltoh(d));
return(STOP);
}

POOL pascal Pool[] = {
{"toBase", ToBase, 0, FUNCTION},
{"fromBase", FromBase, 0, FUNCTION},
{NULL, NULL, 0, 0} };


  3 Responses to “Category : Word Processors
Archive   : HP22D5.ZIP
Filename : BASE.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/