home *** CD-ROM | disk | FTP | other *** search
-
-
- /*
- * File name: x %I%
- * By: Marc Ries
- * Latest change: Thursday, November 13, 1986
- * Purpose of this file:
- * Screen manipulations via a shell
- *
- */
- #include <curses.h>
- #ifndef BSD
- #include <term.h>
- #endif BSD
-
- void exit();
- char *tparm();
-
- outc (c)
- int c;
- {
- (void) putchar(c);
- }
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- char c1, c2, *s;
- char *i_xy;
- int x, y, errret;
-
- if (--argc <= 0) {
- (void) fprintf(stderr,"Usage: kurses -xx ...\n");
- exit(1);
- }
- #ifndef BSD
- if ((setupterm(0,1,&errret)) == -1) {
- (void) fprintf(stderr, "Unknown terminfo terminal type!\n");
- exit(1);
- }
- #else
- initscr();
- #endif BSD
- while (--argc >= 0) {
- ++argv;
- if ((*argv)[0] == '-') {
- c1 = (*argv)[1];
- if ((c1 >= 'A') && (c1 <= 'Z')) c1 = c1+'a'-'A';
- c2 = (*argv)[2];
- if ((c2 >= 'A') && (c2 <= 'Z')) c2 = c2+'a'-'A';
-
- if ((c1 == 'x') && (c2 == 'x')) {
- (void) printf("Legal options are:\n");
- (void) printf("al,bc,bt,cd,ce,cl,cm,dc,dl,dm,do,ed,ei,ho\n");
- (void) printf("ic,im,ip,ll,ma,nd,pc,se,sf,so,sr,ta,te,ti\n");
- (void) printf("uc,ue,ul,us,vb,ve,vs\n");
- (void) printf("Numeric valued capabilities:\n");
- (void) printf("li and co\n");
- }
- else if ((c1 == 'a') && (c2 == 'l')) {
- #ifndef BSD
- tputs(key_il, 1, outc);
- #else
- tputs(AL, 1, outc);
- #endif BSD
- }
- #ifndef BSD
- else if ((c1 == 'b') && (c2 == 'c')) {
- (void) printf("%s",cursor_left);
- }
- else if ((c1 == 'b') && (c2 == 't')) {
- tputs(back_tab, 1, outc);
- }
- #else
- else if ((c1 == 'b') && (c2 == 'c')) (void) printf("%s",BC);
- else if ((c1 == 'b') && (c2 == 't')) (void) printf("%s",BT);
- #endif BSD
- else if ((c1 == 'c') && (c2 == 'd')) {
- #ifndef BSD
- tputs(clr_eos, 1, outc);
- #else
- tputs(CD, 1, outc);
- #endif BSD
- }
- else if ((c1 == 'c') && (c2 == 'e')) {
- #ifndef BSD
- putp(clr_eol);
- #else
- tputs(CE, 1, outc);
- #endif BSD
- }
- else if ((c1 == 'c') && (c2 == 'l')) {
- #ifndef BSD
- putp(clear_screen);
- #else
- tputs(CL, 1, outc);
- #endif BSD
- }
- else if ((c1 == 'c') && (c2 == 'm')) {
- if ((argc -= 2) < 0) {
- (void) fprintf(stderr,"Usage: kurses -cm X Y\n");
- exit(1);
- }
- x = (char)atoi(*++argv);
- y = (char)atoi(*++argv);
- #ifndef BSD
- i_xy = (tparm(cursor_address,y,x));
- tputs(i_xy,0,outc);
- #else
- movecursor(x,y);
- #endif BSD
- }
- #ifndef BSD
- else if ((c1 == 'c') && (c2 == 'o')) (void) printf("%d", columns);
- #else
- else if ((c1 == 'c') && (c2 == 'o')) (void) printf("%d", COLS);
- #endif BSD
- else if ((c1 == 'd') && (c2 == 'c')) {
- #ifndef BSD
- tputs(parm_dch, 1, outc);
- #else
- tputs(DC, 1, outc);
- #endif BSD
- }
- else if ((c1 == 'd') && (c2 == 'l')) {
- #ifndef BSD
- tputs(key_dl, 1, outc);
- #else
- tputs(DL, 1, outc);
- #endif BSD
- }
- #ifndef BSD
- else if ((c1 == 'd') && (c2 == 'm')) {
- (void) printf("%s",enter_delete_mode);
- #else
- else if ((c1 == 'd') && (c2 == 'm')) (void) printf("%s",DM);
- else if ((c1 == 'd') && (c2 == 'o')) (void) printf("%s",DO);
- else if ((c1 == 'e') && (c2 == 'd')) (void) printf("%s",ED);
- else if ((c1 == 'e') && (c2 == 'i')) (void) printf("%s",EI);
- else if ((c1 == 'h') && (c2 == 'o')) {
- if (*HO != '\0') (void) printf("%s",HO);
- else movecursor(0,0);
- #endif BSD
- }
- #ifndef BSD
- else if ((c1 == 'd') && (c2 == 'o')) {
- (void) printf("%s",cursor_down);
- }
- else if ((c1 == 'e') && (c2 == 'd')) {
- (void) printf("%s",exit_delete_mode);
- }
- else if ((c1 == 'e') && (c2 == 'i')) {
- (void) printf("%s",exit_insert_mode);
- }
- else if ((c1 == 'h') && (c2 == 'o')) {
- putp(cursor_home);
- }
- #endif BSD
- else if ((c1 == 'i') && (c2 == 'c')) {
- #ifndef BSD
- tputs(insert_character, 1, outc);
- #else
- tputs(IC, 1, outc);
- #endif BSD
- }
- #ifndef BSD
- else if ((c1 == 'i') && (c2 == 'm')) {
- (void) printf("%s",enter_insert_mode);
- }
- #else
- else if ((c1 == 'i') && (c2 == 'm')) (void) printf("%s",IM);
- #endif BSD
- else if ((c1 == 'i') && (c2 == 'p')) {
- #ifndef BSD
- tputs(insert_padding, 1, outc);
- #else
- tputs(IP, 1, outc);
- #endif BSD
- }
- #ifndef BSD
- else if ((c1 == 'l') && (c2 == 'l')) {
- if (*cursor_to_ll != '\0') {
- putp(cursor_to_ll);
- }
- i_xy = (tparm(cursor_address,lines-1,0));
- tputs(i_xy,0,outc);
- #else
- else if ((c1 == 'l') && (c2 == 'l')) {
- if (*LL != '\0') (void) printf("%s",LL);
- else movecursor(0,LINES-1);
- #endif BSD
- }
- #ifndef BSD
- else if ((c1 == 'l') && (c2 == 'i')) {
- (void) printf("%d", lines);
- }
- else if ((c1 == 'n') && (c2 == 'd')) {
- (void) printf("%s",cursor_right);
- }
- else if ((c1 == 'p') && (c2 == 'c')) {
- (void) printf("%s",pad_char);
- }
- else if ((c1 == 's') && (c2 == 'e')) {
- tputs(exit_standout_mode, 1, outc);
- }
- #else
- else if ((c1 == 'l') && (c2 == 'i')) (void) printf("%d", LINES);
- else if ((c1 == 'm') && (c2 == 'a')) (void) printf("%s",MA);
- else if ((c1 == 'n') && (c2 == 'd')) (void) printf("%s",ND);
- else if ((c1 == 'p') && (c2 == 'c')) (void) printf("%s",PC);
- else if ((c1 == 's') && (c2 == 'e')) (void) printf("%s",SE);
- #endif BSD
- else if ((c1 == 's') && (c2 == 'f')) {
- #ifndef BSD
- tputs(scroll_forward, 1, outc);
- #else
- tputs(SF, 1, outc);
- #endif BSD
- }
- #ifndef BSD
- else if ((c1 == 's') && (c2 == 'o')) {
- tputs(enter_standout_mode, 1, outc);
- }
- else if ((c1 == 's') && (c2 == 'r')) {
- #else
- else if ((c1 == 's') && (c2 == 'o')) (void) printf("%s",SO);
- else if ((c1 == 's') && (c2 == 'r')) {
- #endif BSD
- #ifndef BSD
- *scroll_reverse = tputs(scroll_reverse, 1, outc);
- (void) printf("%s",scroll_reverse);
- #else
- *SR = tputs(SR, 1, outc);
- (void) printf("%s",SR);
- #endif BSD
- }
- else if ((c1 == 't') && (c2 == 'a')) {
- #ifndef BSD
- tputs(tab, 1, outc);
- #else
- tputs(TA, 1, outc);
- #endif BSD
- }
- #ifndef BSD
- else if ((c1 == 't') && (c2 == 'e')) {
- (void) printf("%s",exit_ca_mode);
- }
- else if ((c1 == 't') && (c2 == 'i')) {
- (void) printf("%s",enter_ca_mode);
- }
- else if ((c1 == 'u') && (c2 == 'c')) {
- tputs(underline_char, 1, outc);
- }
- else if ((c1 == 'u') && (c2 == 'e')) {
- tputs(exit_underline_mode, 1, outc);
- }
- else if ((c1 == 'u') && (c2 == 'l')) {
- (void) printf("%s",transparent_underline);
- }
- else if ((c1 == 'u') && (c2 == 's')) {
- tputs(enter_underline_mode, 1, outc);
- }
- else if ((c1 == 'v') && (c2 == 'b')) {
- tputs(flash_screen, 1, outc);
- }
- else if ((c1 == 'v') && (c2 == 'e')) {
- tputs(cursor_normal, 1, outc);
- }
- else if ((c1 == 'v') && (c2 == 's')) {
- tputs(cursor_visible, 1, outc);
- }
- #else
- else if ((c1 == 't') && (c2 == 'e')) (void) printf("%s",TE);
- else if ((c1 == 't') && (c2 == 'i')) (void) printf("%s",TI);
- else if ((c1 == 'u') && (c2 == 'c')) (void) printf("%s",UC);
- else if ((c1 == 'u') && (c2 == 'e')) (void) printf("%s",UE);
- else if ((c1 == 'u') && (c2 == 'l')) (void) printf("%s",UL);
- else if ((c1 == 'u') && (c2 == 's')) (void) printf("%s",US);
- else if ((c1 == 'v') && (c2 == 'b')) (void) printf("%s",VB);
- else if ((c1 == 'v') && (c2 == 'e')) (void) printf("%s",VE);
- else if ((c1 == 'v') && (c2 == 's')) (void) printf("%s",VS);
- #endif BSD
- else (void) fprintf(stderr,"kurses: unknown option %s\n",*argv);
- }
- else for (s = argv[0]; *s != '\0'; s++) (void) putchar(*s);
- }
- #ifndef BSD
- resetterm();
- exit(0);
- #else
- endwin();
- #endif BSD
- }
-
- #ifdef BSD
- movecursor(x,y)
- int x, y;
- {
- char n, *s;
- int i = 0, rev = 0;
-
- for (s = CM; *s != '\0'; s++) {
- while (*s >= '0' && *s <= '9') *s++; /* strip padding nums */
-
- if (*s != '%') (void) putchar(*s);
- else {
- switch (i) {
- case 0: n = (rev?x:y);
- break;
- case 1: n = (rev?y:x);
- break;
- default: n = '\0';
- }
- switch(*++s) {
- case 'd': (void) printf("%d",n);
- i++;
- break;
- case '2': (void) printf("%2d",n);
- i++;
- break;
- case '3': (void) printf("%3d",n);
- i++;
- break;
- case '+': n += (int)*++s;
- case '.': (void) printf("%c",(char)n);
- i++;
- break;
- case '>': if (n > (int)*++s) n+=(int)*++s;
- else *++s;
- break;
- case 'i': x++; y++;
- break;
- case 'n': x ^= 0140; y ^= 0140;
- break;
- case 'B': x = (16*(x/10))+(x%10);
- y = (16*(y/10))+(y%10);
- break;
- case 'D': x = (x-2*(x%16));
- y = (y-2*(y%16));
- case 'r': rev++;
- break;
- default: *--s;
- case '%': break;
- }
- }
- }
- }
- #endif BSD
-