Annotation of 43BSD/contrib/X/xterm/resize.c, revision 1.1

1.1     ! root        1: #include <X/mit-copyright.h>
        !             2: 
        !             3: /* Copyright    Massachusetts Institute of Technology    1984  */
        !             4: 
        !             5: /* resize.c */
        !             6: 
        !             7: #include <stdio.h>
        !             8: #include <sgtty.h>
        !             9: #include <strings.h>
        !            10: #include <sys/ioctl.h>
        !            11: 
        !            12: #ifndef lint
        !            13: static char *rcsid_resize_c = "$Header: resize.c,v 10.5 86/02/01 16:06:55 tony Rel $";
        !            14: #endif
        !            15: 
        !            16: char *myname;
        !            17: 
        !            18: char *strindex (), *index (), *rindex();
        !            19: 
        !            20: main (argc, argv)
        !            21: char **argv;
        !            22: /*
        !            23:    resets termcap string to reflect current screen size
        !            24:  */
        !            25: {
        !            26:        int rows, cols;
        !            27:        char *size = "\0337\033[r\033[999;999H\033[6n";
        !            28:        struct sgttyb sg, sgorig;
        !            29:        char termcap [1024];
        !            30:        char newtc [1024];
        !            31:        char *setname = "";
        !            32:        register char *ptr, *env;
        !            33:        char *getenv();
        !            34: #ifdef TIOCSWINSZ
        !            35:        struct winsize ws;
        !            36: #endif
        !            37:        tgetent (termcap, "xterm");
        !            38: 
        !            39:        if(ptr = rindex(myname = argv[0], '/'))
        !            40:                myname = ptr + 1;
        !            41:        if((env = getenv("TERMCAP")) && *env)
        !            42:                strcpy(termcap, env);
        !            43:        else {
        !            44:                if(!(env = getenv("TERM")) || !*env) {
        !            45:                        env = "xterm";
        !            46:                        setname = "setenv TERM xterm;\n";
        !            47:                }
        !            48:                if(tgetent (termcap, env) <= 0) {
        !            49:                        fprintf(stderr, "%s: Can't get entry \"%s\"\n",
        !            50:                         myname, env);
        !            51:                        exit(1);
        !            52:                }
        !            53:        }
        !            54: 
        !            55:        ioctl ( 0, TIOCGETP, &sgorig);
        !            56:        sg = sgorig;
        !            57:        sg.sg_flags |= RAW;
        !            58:        ioctl ( 0, TIOCSETP, &sg);
        !            59: 
        !            60:        write ( 0, size, strlen (size));
        !            61:        scanf ("\033[%d;%dR", &rows, &cols);
        !            62:        write ( 0, "\0338", 2);
        !            63: 
        !            64:        ioctl ( 0, TIOCSETP, &sgorig);
        !            65: 
        !            66:        /* update termcap string */
        !            67:        /* first do columns */
        !            68:        if ((ptr = strindex (termcap, "co#")) == NULL) {
        !            69:                fprintf(stderr, "%s: No `co#'\n", myname);
        !            70:                exit (1);
        !            71:        }
        !            72:        strncpy (newtc, termcap, ptr - termcap + 3);
        !            73:        sprintf (newtc + strlen (newtc), "%d", cols);
        !            74:        ptr = index (ptr, ':');
        !            75:        strcat (newtc, ptr);
        !            76: 
        !            77:        /* now do lines */
        !            78:        if ((ptr = strindex (newtc, "li#")) == NULL) {
        !            79:                fprintf(stderr, "%s: No `li#'\n", myname);
        !            80:                exit (1);
        !            81:        }
        !            82:        strncpy (termcap, newtc, ptr - newtc + 3);
        !            83:        sprintf (termcap + ((int) ptr - (int) newtc + 3), "%d", rows);
        !            84:        ptr = index (ptr, ':');
        !            85:        strcat (termcap, ptr);
        !            86: 
        !            87:        printf ("set noglob;\n%ssetenv TERMCAP '%s';\nunset noglob;\n",
        !            88:         setname, termcap);
        !            89: #ifdef TIOCGWINSZ
        !            90:        /* finally, set the tty's window size */
        !            91:        if (ioctl (0, TIOCGWINSZ, &ws) != -1) {
        !            92:            /* we don't have any way of directly finding out
        !            93:               the current height & width of the window in pixels.  We try
        !            94:               our best by computing the font height and width from the "old"
        !            95:               struct winsize values, and multiplying by these ratios...*/
        !            96:            if (ws.ws_xpixel != 0)
        !            97:                ws.ws_xpixel = cols*(ws.ws_xpixel/ws.ws_col);
        !            98:            if (ws.ws_ypixel != 0)
        !            99:                ws.ws_ypixel = rows*(ws.ws_ypixel/ws.ws_row);
        !           100:            ws.ws_row = rows;
        !           101:            ws.ws_col = cols;
        !           102:            ioctl (0, TIOCSWINSZ, &ws);
        !           103:            }
        !           104: #endif
        !           105:        exit(0);
        !           106: }
        !           107: 
        !           108: char *strindex (s1, s2)
        !           109: /*
        !           110:    returns a pointer to the first occurrence of s2 in s1, or NULL if there are
        !           111:    none.
        !           112:  */
        !           113: char *s1, *s2;
        !           114: {
        !           115:        char *s3;
        !           116: 
        !           117:        while ((s3 = index (s1, *s2)) != NULL)
        !           118:        {
        !           119:                if (strncmp (s3, s2, strlen (s2)) == 0) return (s3);
        !           120:                s1 = ++s3;
        !           121:        }
        !           122:        return (NULL);
        !           123: }
        !           124: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.