コード例 #1
0
ファイル: mgrlogin.c プロジェクト: wvdschel/bellcore-mgr
/*{{{  cutebox*/
void cutebox(int bx, int by, int bw, int bh)
{
  bit_blit(screen, bx, by, bw, bh, BIT_CLR, (BITMAP *)0, 0, 0);

  bit_line(screen, bx, by, bx + bw, by, BIT_SRC);
  bit_line(screen, bx + bw, by, bx + bw, by + bh, BIT_SRC);
  bit_line(screen, bx + bw, by + bh, bx, by + bh, BIT_SRC);
  bit_line(screen, bx, by + bh, bx, by, BIT_SRC);

  bit_line(screen, bx + 1, by + 1, bx + bw - 1, by + 1, BIT_SRC);
  bit_line(screen, bx + bw - 1, by + 1, bx + bw - 1, by + bh - 1, BIT_SRC);
  bit_line(screen, bx + bw - 1, by + bh - 1, bx + 1, by + bh - 1, BIT_SRC);
  bit_line(screen, bx + 1, by + bh - 1, bx + 1, by + 1, BIT_SRC);

  bit_line(screen, bx + 3, by + 3, bx + bw - 3, by + 3, BIT_SRC);
  bit_line(screen, bx + bw - 3, by + 3, bx + bw - 3, by + bh - 3, BIT_SRC);
  bit_line(screen, bx + bw - 3, by + bh - 3, bx + 3, by + bh - 3, BIT_SRC);
  bit_line(screen, bx + 3, by + bh - 3, bx + 3, by + 3, BIT_SRC);
}
コード例 #2
0
ファイル: lines.c プロジェクト: LambdaCalculus379/SLS-1.02
int main(int argc, char *argv[])
{
  BITMAP *bp;
  int i;

#ifdef MOVIE
  log_start(fopen("lines.log","w"));
#endif
  bp=bit_open(SCREEN_DEV);
  bit_blit(bp,0,0,BIT_WIDE(bp),BIT_HIGH(bp),BIT_CLR,(BITMAP*)0,0,0);
  srand(getpid()*time((time_t*)0));
  for (i=0; i<1000; i++)
  bit_line(bp,rand()%BIT_WIDE(bp),rand()%BIT_HIGH(bp),rand()%BIT_WIDE(bp),rand()%BIT_HIGH(bp),BIT_SET);
  bit_destroy(bp);
#ifdef MOVIE
  log_end();
#endif
  exit(0);
}
コード例 #3
0
ファイル: update.c プロジェクト: wvdschel/bellcore-mgr
/*{{{  do_update -- update obscured window*/
static void do_update(WINDOW *win, rect *clipp)
{
  struct rect_list *list; /* list of rectangle to clip to */
  rectangle *got;         /* intersecting region */

  dbgprintf('U', (stderr, "Updating background window to %d,%d => %d,%d\r\n",
                     clipp->x1, clipp->y1, clipp->x2, clipp->y2));

  for (list = (struct rect_list *)W(clip_list); list; list = list->next) {
    if ((got = got_int(&(list->rect), clipp, W(borderwid)))) {
      int x = got->x,
          y = got->y,
          wide = got->wide,
          high = got->high;
      in_mouseoff(x + W(x0), y + W(y0), wide, high);
      bit_blit(W(border), x, y, wide, high, BIT_SRC, W(save), x, y);
      MOUSE_ON(screen, mousex, mousey);
    }
  }
}
コード例 #4
0
ファイル: mgrlogin.c プロジェクト: wvdschel/bellcore-mgr
/*{{{  printchar*/
void printchar(int x, int y, unsigned char c)
{
  bit_blit(screen, x, y - font->head.high, font->head.wide, font->head.high, BIT_SRC, font->glyph[c], 0, 0);
}
コード例 #5
0
ファイル: mgrlogin.c プロジェクト: wvdschel/bellcore-mgr
/*{{{  printcursor*/
void printcursor(int x, int y, int on)
{
  bit_blit(screen, x, y - font->head.high, font->head.wide, font->head.high, on ? BIT_SET : BIT_CLR, (BITMAP *)0, 0, 0);
}
コード例 #6
0
ファイル: mgrlogin.c プロジェクト: wvdschel/bellcore-mgr
/*{{{  main*/
int main(int argc, char *argv[])
{
  /*{{{  variables*/
  int x, login_y, password_y;
  char loginstr[9], passwordstr[9], ret;
  char ttystr[_POSIX_PATH_MAX];
  char *background = (char *)0;
  char *fontname = (char *)0;
  /*}}}  */

  /*{{{  parse arguments*/
  {
    int c;

    while ((c = getopt(argc, argv, "b:f:")) != EOF)
      switch (c) {
      case 'b':
        background = optarg;
        break;
      case 'f':
        fontname = optarg;
        break;
      }
    /*{{{  parse tty*/
    {
      int tty;

      if (optind + 1 > argc) {
        fprintf(stderr, "Usage: %s tty\n", argv[0]);
        exit(1);
      } else {
        strcpy(ttystr, "/dev/");
        strcat(ttystr, argv[optind++]);
      }
      close(0);
      close(1);
      close(2);
      setsid();
      if ((tty = open(ttystr, O_RDWR)) != 0) {
        fprintf(stderr, "%s: Can't open controlling terminal on fd 0.\n", argv[0]);
        exit(1);
      }
      fchmod(tty, 0600);
      fchown(tty, getuid(), getgid());
      open(argv[optind], O_RDWR);
      open(argv[optind], O_RDWR);
    }
    /*}}}  */
  }
  /*}}}  */
  /*{{{  get into grafics mode*/
  signal(SIGTERM, quit);
  signal(SIGHUP, quit);
  set_tty(0);
  if ((screen = bit_open(SCREEN_DEV)) == (BITMAP *)0) {
    reset_tty(0);
    exit(EX_NOPERM);
  }
  bit_grafscreen();
  /*}}}  */
  /*{{{  load font*/
  if (fontname) {
    char fontpath[_POSIX_PATH_MAX];

    if (*fontname == '/' || *fontname == '.')
      strcpy(fontpath, fontname);
    else {
      strcpy(fontpath, ICONDIR);
      strcat(fontpath, "/");
      strcat(fontpath, fontname);
    }

    if ((font = open_font(fontname)) == (struct font *)0)
      font = open_font((char *)0);
  } else
    font = open_font((char *)0);
  /*}}}  */
  /*{{{  draw background*/
  bit_blit(screen, 0, 0, screen->wide, screen->high, BIT_CLR, (BITMAP *)0, 0, 0);
  if (background) {
    BITMAP *bp;
    FILE *fp;
    char backgroundpath[_POSIX_PATH_MAX];

    if (*background == '/' || *background == '.')
      strcpy(backgroundpath, background);
    else {
      strcpy(backgroundpath, ICONDIR);
      strcat(backgroundpath, "/");
      strcat(backgroundpath, background);
    }

    if ((fp = fopen(backgroundpath, "r")) != (FILE *)0 && (bp = bitmapread(fp)) != (BITMAP *)0) {
      int x, y;

      for (x = 0; x < screen->wide; x += bp->wide)
        bit_blit(
            screen,
            x, 0,
            screen->wide - x < bp->wide ? screen->wide - x : bp->wide,
            bp->high,
            BIT_SRC, bp, 0, 0);

      for (y = 0; y < screen->high; y += bp->high)
        bit_blit(
            screen,
            0, y,
            screen->wide,
            screen->high - y < bp->high ? screen->high - y : bp->high,
            BIT_SRC, screen, 0, 0);
    }
  }
  /*}}}  */
  /*{{{  draw hostname*/
  {
    int bx, bw, by, bh;
    char hostname[_POSIX_PATH_MAX];
    struct hostent *h;

    gethostname(hostname, sizeof(hostname));
    if ((h = gethostbyname(hostname)) != (struct hostent *)0)
      strcpy(hostname, h->h_name);
    bw = font->head.wide * (strlen(hostname) + 2);
    bh = 2 * font->head.high;
    bx = (screen->wide - bw) / 2;
    by = screen->high / 6 - bh / 2;
    cutebox(bx, by, bw, bh);
    printstr(bx + font->head.wide, by + bh - font->head.high / 2, hostname);
  }
  /*}}}  */
  /*{{{  draw login box*/
  {
    int bx, bw, by, bh;

    bx = (screen->wide - font->head.wide * 40) / 2;
    by = (screen->high - font->head.high * 8) / 2;
    bw = font->head.wide * 40;
    bh = font->head.high * 8;
    cutebox(bx, by, bw, bh);
  }
  /*}}}  */
  /*{{{  draw login box contents*/
  x = (screen->wide - font->head.wide * 18) / 2;
  login_y = screen->high / 2 - font->head.wide / 6;
  password_y = screen->high / 2 + font->head.high / 6 + font->head.high;
  printstr(x, password_y, "Password:         "******"Press ESC for terminal login");
  /*}}}  */
  while (1) {
    /*{{{  get login and password or escape*/
    printstr(x, login_y, "Login:            "******"mgr", (char *)0 };
        int i;

        sprintf(env_user, "USER=%s", pw->pw_name);
        sprintf(env_logname, "LOGNAME=%s", pw->pw_name);
        sprintf(env_home, "HOME=%s", pw->pw_dir);
        sprintf(env_shell, "SHELL=%s", pw->pw_shell == (char *)0 || pw->pw_shell[0] == '\0' ? "/bin/sh" : pw->pw_shell);
        sprintf(env_path, "PATH=%s", PATH);
        sprintf(env_mail, "MAIL=%s/%s", MAILDIR, pw->pw_name);
        if (chdir(pw->pw_dir) != 0)
          chdir("/");
        if (ttyname(0)) {
          chown(ttyname(0), pw->pw_uid, pw->pw_gid);
          chmod(ttyname(0), 0600);
        }
        for (i = 1; i <= _NSIG; i++)
          signal(i, SIG_DFL);
        bit_destroy(screen);
        reset_tty(0);
        initgroups(pw->pw_name, pw->pw_gid);
        setgid(pw->pw_gid);
        setuid(pw->pw_uid);
        sprintf(mgrlogin, "%s/.mgrlogin", pw->pw_dir);
        execve(mgrlogin, login_argv, login_env);
        execve(MGR_BINARY, login_argv, login_env);
        exit(EX_OSFILE);
      }
      /*}}}  */
      else
      /*{{{  incorrect login*/
      {
        printstr((screen->wide - font->head.wide * 16) / 2, login_y + 3 * font->head.high,
            "Login incorrect");
      }
      /*}}}  */
    }
    /*}}}  */
  }
}
コード例 #7
0
ファイル: shape.c プロジェクト: wvdschel/bellcore-mgr
/*{{{  shape -- reshape a window to specified dimensions*/
int shape(int x, int y, int dx, int dy)
{
  int sx, sy, w, h;
  WINDOW *win;

  if (dx > 0) {
    sx = x;
    w = dx;
  } else {
    sx = x + dx;
    w = -dx;
  }
  if (dy > 0) {
    sy = y;
    h = dy;
  } else {
    sy = y + dy;
    h = -dy;
  }

  if (sx < 0)
    sx = 0;

  if (sx + w >= BIT_WIDE(screen))
    w = BIT_WIDE(screen) - sx;

  if (sy + h >= BIT_HIGH(screen))
    h = BIT_HIGH(screen) - sy;

  if (w < 2 * ACTIVE(borderwid) + ACTIVE(font)->head.wide * MIN_X || h < 2 * ACTIVE(borderwid) + ACTIVE(font)->head.high * MIN_Y)
    return (-1);

#ifdef MGR_ALIGN
  alignwin(screen, &sx, &w, ACTIVE(borderwid));
#endif

  /* remove current window position */
  save_win(active);
  erase_win(ACTIVE(border));
  clip_bad(active); /* invalidate clip lists */

  /* redraw remaining windows */
  repair(active);

  /* adjust window state */
  ACTIVE(x0) = sx;
  ACTIVE(y0) = sy;
  bit_destroy(ACTIVE(window));
  bit_destroy(ACTIVE(border));
  ACTIVE(border) = bit_create(screen, sx, sy, w, h);
  ACTIVE(window) = bit_create(ACTIVE(border),
      ACTIVE(borderwid),
      ACTIVE(borderwid),
      w - ACTIVE(borderwid) * 2,
      h - ACTIVE(borderwid) * 2);

  for (win = ACTIVE(next); win != (WINDOW *)0; win = W(next)) {
    if (W(flags) & W_ACTIVE && intersect(active, win))
      save_win(win);
  }

  CLEAR(ACTIVE(window), PUTOP(BIT_CLR, ACTIVE(style)));

  border(active, BORDER_THIN);
  bit_blit(ACTIVE(border), 0, 0,
      BIT_WIDE(ACTIVE(save)) - ACTIVE(borderwid),
      BIT_HIGH(ACTIVE(save)) - ACTIVE(borderwid),
      BIT_SRC, ACTIVE(save), 0, 0);

  /* make sure character cursor is in a good spot */
  if (ACTIVE(x) > BIT_WIDE(ACTIVE(window))) {
    ACTIVE(x) = 0;
    ACTIVE(y) += ((int)(ACTIVE(font)->head.high));
  }
  if (ACTIVE(y) > BIT_HIGH(ACTIVE(window))) {
#ifdef WIERD
    ACTIVE(y) = BIT_HIGH(ACTIVE(window));
    scroll(ACTIVE(window), 0, BIT_HIGH(ACTIVE(window)),
        ((int)(ACTIVE(font)->head.high)), SWAPCOLOR(ACTIVE(style)));
    bit_blit(ACTIVE(window), 0, BIT_HIGH(ACTIVE(window)) - ((int)(ACTIVE(font)->head.high)),
        BIT_WIDE(ACTIVE(save)), ((int)(ACTIVE(font)->head.high)),
        BIT_SRC, ACTIVE(save),
        ACTIVE(borderwid), BIT_HIGH(ACTIVE(save)) - ((int)(ACTIVE(font)->head.high)) - ACTIVE(borderwid));
#else
    ACTIVE(y) = BIT_HIGH(ACTIVE(window)) - ((int)(ACTIVE(font)->head.high));
#endif
  }

  bit_destroy(ACTIVE(save));
  ACTIVE(save) = (BITMAP *)0;

  /* invalidate clip lists */
  clip_bad(active);
  un_covered();
  set_size(active);
  return (0);
}