#include #include #include #define NA 0xffff struct uwdata xuw = { NA, NA, NA, NA, NA}; struct utdata xut[WTXTNUM]; int bflag = 0; int Kflag = 0; char blot[81]; char *ttyname(); main(ac,av) int ac; char **av; { int nflag = 0; char avname[81]; extern char *optarg; extern int optind; int i, c; while((c = getopt(ac, av, "brp:c:l:u:1:2:n:f:h:w:x:y:K:")) != EOF) { switch(c) { case 'r': report(ttyname(0)); exit(0); break; case 'b': bflag++; break; case 'h': xuw.uw_height = atoi(optarg); break; case 'w': xuw.uw_width = atoi(optarg); break; case 'x': xuw.uw_x = atoi(optarg); break; case 'y': xuw.uw_y = atoi(optarg); break; case 'f': xuw.uw_uflags = htoi(optarg); xuw.uw_uflags &= ~NOSETUFLAGS; break; case 'p': utset(WTXTPROMPT, optarg); break; case 'c': utset(WTXTCMD, optarg); break; case 'l': utset(WTXTLABEL, optarg); break; case 'n': case 'u': nflag = 1; utset(WTXTUSER, optarg); break; case '1': utset(WTXTSLK1, optarg); break; case '2': utset(WTXTSLK2, optarg); break; case '?': fprintf(stderr, "usage: windy [window-args] [command-args]\n"); fprintf(stderr, "or windy -r\n"); exit(2); case 'K': strncpy(blot, optarg, 80); Kflag ++; } } /* * if gave command args, put it in a new window * if gave window args, or no args at all, change window params */ if(optind == 1) { xuw.uw_x = 0; xuw.uw_y = 12; xuw.uw_width = 720; xuw.uw_height = 288; xuw.uw_uflags = 0x1; } if(optind < ac) { newwind(); avname[0] = 0; for(i=optind; i 0) exit(1); else if(pid == 0) { setpgrp(); ioctl(0, WIOCPGRP); } } av += optind; execvp(av[0], av); perror(av[0]); exit(1); } exit(0); } utset(n, s) char *s; { xut[n].ut_num = 1; strncpy(xut[n].ut_text, s, WTXTLEN); } newwind() { char name[10]; extern char **environ; struct termio t; int bad = 0, i, fd; if (!isatty(0)) return; if(strncmp("/dev/w", ttyname(0), 6)!=0 ) return; if (ioctl(0, TCGETA, &t) < 0) { perror("getting tty chars"); bad = 1; } fd = open("/dev/window",2); if (fd < 0) { perror("opening window"); return; } if(bflag) { ioctl(fd, WIOCSELECT); sprintf(name, "[w%d]\n", ioctl(fd, WIOCGCURR)); write(0, name, strlen(name)); } close(0); dup(fd); close(1); dup(fd); close(2); dup(fd); close(fd); /* Set in the previous edit characters to the new window */ if (!bad && ioctl(0, TCSETAF, &t) < 0) perror("setting tty chars"); for (i=0; environ[i]; ++i) { if (!strncmp(environ[i],"TERMCAP=",8)) { environ[i] = "TERMCAP=/etc/termcap"; } if (!strncmp(environ[i],"TERM=",5)) { environ[i] = "TERM=s4"; } } } fixwind() { struct uwdata uw; int i; if(Kflag) { xut[WTXTSLK1].ut_num = WTXTSLK1; xut[WTXTSLK2].ut_num = WTXTSLK2; keyfix(xut[WTXTSLK1].ut_text); keyfix(xut[WTXTSLK2].ut_text); } for(i=0; i\n", utname[i], ut.ut_text); } } } uwshow(p, s) struct uwdata *p; char *s; { printf("(x,y)=(%d,%d) ", p->uw_x, p->uw_y); printf("(width,height)=(%d,%d) ", p->uw_width, p->uw_height); printf("flags=%x\n ", p->uw_uflags); printf("(hs,vs)=(%d, %d)[RO] ", p->uw_hs, p->uw_vs); printf("baseline=%d[RO] ", p->uw_baseline); printf("(cx,cy)=(%d, %d)[RO]\n", p->uw_cx, p->uw_cy); } htoi(s) char *s; { int x = NA; sscanf(s, "%x", &x); return x; }