Sam Trenholme's webpage
This article was posted to the Usenet group alt.hackers in 1995; any technical information is probably outdated.

Re: I am so bored


Article: 7385 of alt.hackers
Newsgroups: alt.hackers
From: dawagner@flagstaff.princeton.edu (David A. Wagner)
Subject: Re: I am so bored
Message-ID: 1995Feb14.030931.840@Princeton.EDU
Originator: news@hedgehog.Princeton.EDU
Sender: news@Princeton.EDU (USENET News System)
Nntp-Posting-Host: flagstaff.princeton.edu
Organization: Princeton University
Date: Tue, 14 Feb 1995 03:09:31 GMT
Approved: by induction.
Lines: 99
Status: RO

In article <1995Feb13.092210.15981@liberty.uc.wlu.edu>,
 <dogan@ceng.metu.edu.tr> wrote:
>       sitting by myself, I decided to turn on and off the loghts f my pc.
> The Capslock,numlock,.. : yeah the three lights on the keyboard.

Two guys (Unix gods!) who used to go to school here wrote
a program to do this on a Sun; I'll include it below for
amusement value.  [Hope they don't mind.]

ObHack: hrmm... well, this one is lame, but...
	Simulating tar xf without using tar.
	[Someone sent me a .tar which included a file with
	an absolute path (/home/user/foo); unless I'm missing
	something, there's no way to tell tar to extract this
	to a different path.]

-------------------------------------------------------------------------------
David Wagner						 dawagner@princeton.edu



/*
 * stupid LEDS program for a SPARCstation, by Spencer Sun
 *
 * idea somewhat ripped off from Kartik Subbarao
 * initial coding from scratch some time in 11/93 at the request of Jason Todd
 *   (I must have been really bored)
 * last touched 12/8/93
 */

#include <stdio.h>
#include <stdlib.h>

#include <sys/fcntlcom.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/signal.h>

#include <sundev/kbd.h>
#include <sundev/kbio.h>

int done = 0;

void
die(void)
{
  done = 1;
}

int
main(int argc, char **argv)
{
  int delay = 200000, devkbd, ch, i;
  char save, chararg, *argv0 = argv[0];
  extern int optind;
  extern char *optarg;

  if ((devkbd = open("/dev/kbd", O_RDWR)) < 0)
  {
    perror("Can't open /dev/kbd");
    return 1;
  }

  /* yeah, I think getopt is kind of overkill for this... */
  while ((ch = getopt(argc, argv, "i:")) != EOF)
    delay = atoi(optarg);
  argc -= optind; argv += optind;

  if (0 == argc)
  {
    fprintf(stderr, "Usage: %s [ -i usecs ] <pattern> [
    <pattern> ...  ]\n",
	    argv0);
    return 1;
  }

  /* save current LED settings and set up appropriate signal handlers */
  ioctl(devkbd, KIOCGLED, &save);
  signal(SIGINT, die);
  signal(SIGHUP, die);
  signal(SIGTERM, die);

  /* the main loop -- oh, boy, this is complex. */
  while(!done)
    for (i = 0; (i < argc) && !done; i++)
    {
      ch = atoi(argv[i]);
      chararg = 0;
      if (ch & 0x1) chararg |= LED_NUM_LOCK;
      if (ch & 0x2) chararg |= LED_SCROLL_LOCK;
      if (ch & 0x4) chararg |= LED_COMPOSE;
      if (ch & 0x8) chararg |= LED_CAPS_LOCK;
      ioctl(devkbd, KIOCSLED, &chararg);
      usleep(delay);
    }

  /* let's be polite and clean up after ourselves */
  ioctl(devkbd, KIOCSLED, &save);
  return 0;
}



Parent

Child

Back to index