Category : UNIX Files
Archive   : XDEBT.ZIP
Filename : XDEBT.ASC
For your viewing pleasure, and just in time so you, too, can watch the
national debt cross the 4e12 mark on July 28th 1992, the xdebt tool.
Sorry, there is no Makefile; but this is easy to compile and use. Just
read the header comments.
Just compile and run, and watch the country's future draining away.
Makes a great conversation piece.
Remember, xdebt only covers the on-books debt; off books debt may
total several more trillion dollars.
For your viewing pleasure, the 4e12 transition happens on the 28th!
Don't miss it! You can tell your children about how you remember back
when people were still stupid enough that they were willing to loan
the Feds FOUR TRILLION DOLLARS.
--Cut Here--------------------------------------------------------------------
/* Displays the current national debt in a window, updated once a second.
Public domain. By Jamie Zawinski
(you may need to add -DSYSV if timelocal is undefined -- tom)
cc -O -o xdebt xdebt-new.c -lXaw -lXmu -lXt -lX11 -lXext
More mods by [email protected] [a/k/a [email protected]] to include
per-capita, also small square vs big rect; changed number printing style.
Theoretically, you can run it as:
xdebt [-g +XCOORD+YCOORD] [-update SECS] [-font FONT]
I haven't tested that -font works, but I use
xdebt -g +1080+360
routinely and
xdebt -update 1
also works for me. Your mileage may vary....
--sonroc
More mods by Perry Metzger, ([email protected]); reverted to a
big rectangle, eliminated silly cents field, uped the updates to
once a second, picked a bigger font, changed the labels to suit my
tastes. Easy to change, though.
*/
#include
#include
#include
#include
#ifdef SYSV
#define timelocal mktime
#endif
typedef double debt_t;
typedef double pop_t;
/* The US Population, and its rate of increase, as of July 1, 1990 */
/* (in people/second) based on numbers from the CIA's World Factbook 1990 */
/* .... thanks to [email protected] */
#define POP 250410000.0/* people */
#define POP_DELTA0.0714151266/* increase in people per second */
static struct tm pop_tm = { 0, 0, 0, 1, 6, 90 };
/* The US National Debt, and its rate of increase as of June 30, 1992 */
/* (in $/second) based on numbers from the 5 July 1992 Albuquerque Journal */
/* .... thanks to Brooke King [email protected] */
#define DEBT3965170506502.395/* in dollars */
#define DEBT_DELTA14132.887/* Dollars per second */
static struct tm debt_tm = { 0, 0, 0, 30, 05, 92 };
debt_t
national_debt_at (now)
time_t now;
{
time_t debt_date = timelocal (&debt_tm);
time_t seconds_since_then = now - debt_date;
debt_t delta_since_then = DEBT_DELTA * seconds_since_then;
return DEBT + delta_since_then;
}
pop_t
national_pop_at (now)
time_t now;
{
time_t pop_date = timelocal (&pop_tm);
time_t seconds_since_then = now - pop_date;
pop_t delta_since_then = POP_DELTA * seconds_since_then;
return POP + delta_since_then;
}
void
pretty_number(n, buf)
double n;
char buf[256];
{
char tmpBuf[256], *cp, *bp;
int len, count, digits;
/*sprintf(tmpBuf, "%.2lf", n);*/
sprintf(tmpBuf, "%.0lf", n);
len = strlen(tmpBuf);
cp = tmpBuf + len - 1;
bp = buf;
/* copy over the cents and first 3 digits */
/* *bp++ = *cp--; *bp++ = *cp--; *bp++ = *cp--; */
*bp++ = *cp--; *bp++ = *cp--; *bp++ = *cp--;
digits = 7;
/* Now every three digits gets a comma; at 10 digits insert a line at the
comma */
while (cp >= tmpBuf)
{
/* MODIFY NEWLINE IN LARGE NUMBERS HERE */
/*if (digits > 10)
{
*bp++ = ' '; *bp++ = '\n'; digits=0;
}*/
*bp++ = ','; digits++;
for (count = 0; count < 3 && cp >= tmpBuf; count++)
{
*bp++ = *cp--; digits++;
}
}
*bp++ = '\0';
strcpy(tmpBuf, buf);
len = strlen(tmpBuf);
for (count = 0; count < len; count++)
{
buf[(len-1) - count] = tmpBuf[count];
}
buf[len] = '\0';
}
void
construct_string (now, outBuf)
time_t now;
char *outBuf;
{
debt_t debt = national_debt_at(now);
pop_t pop = national_pop_at(now);
char debtBuf[256], shareBuf[256];
pretty_number(debt, debtBuf);
pretty_number(debt/pop, shareBuf);
sprintf(outBuf, "U.S. National Debt:\n$%s\nYour Share:\n$%s", debtBuf,
shareBuf);
}
static int update;
/* MODIFY FONT HERE */
static char *defaults[] = {
"*Label.font:12x24",/* was times-...-240 */
/* "*Label.font:*-helvetica-bold-r-*-*-*-100-*-*-*-*-*-*",/* was times-...-240
*/
"*title:xdebt",
"*update:1",
NULL
};
static XrmOptionDescRec options [] = {
{ "-update","*update",XrmoptionSepArg, 0 }
};
static void
get_update (dpy)/* Easier than making a subclass... */
Display *dpy;
{
char *name, *class, *type, buf1[255], buf2[255];
XrmValue value;
XtGetApplicationNameAndClass (dpy, &name, &class);
sprintf (buf1, "%s.update", name);
sprintf (buf2, "%s.Update", class);
XrmGetResource (XtDatabase (dpy), buf1, buf2, &type, &value);
if (sscanf (value.addr, " %d ", &update) == 0 || update < 1)
{
fprintf (stderr, "%s: update must be a positive integer, not \"%s\"\n",
name, value.addr);
update = 1;
}
}
static void
timer (w, id)
Widget w;
XtIntervalId id;
{
char buf [255];
Arg av [10];
int ac = 0;
time_t now = time((time_t *)0);
construct_string (now, buf);
XtSetArg (av [ac], XtNlabel, buf); ac++;
XtSetValues (w, av, ac);
XtAppAddTimeOut (XtWidgetToApplicationContext (w), update * 1000, timer, w);
}
void
main (argc, argv)
int argc;
char **argv;
{
XtAppContext app;
Widget shell = XtAppInitialize (&app, "XDebt", options, XtNumber (options),
&argc, argv, defaults, NULL, 0);
Widget label;
XEvent event;
if (argc > 1)
{
fprintf (stderr, "%s: unknown option %s\n", argv[0], argv[1]);
fprintf (stderr, "options: -update
exit (-1);
}
label = XtCreateManagedWidget ("label", labelWidgetClass, shell, NULL, 0);
get_update (XtDisplay (label));
timer (label, 0);
XtRealizeWidget (shell);
XtAppMainLoop (app);
}
--Cut Here--------------------------------------------------------------------
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
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/