Annotation of 43BSDTahoe/new/X/libsun/initial.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char *rcsid = "$Header: initial.c,v 10.6 86/12/17 20:34:22 swick Exp $";
                      3: #endif lint
                      4: #ifdef sun
                      5: /*
                      6:  * The Sun X drivers are a product of Sun Microsystems, Inc. and are provided
                      7:  * for unrestricted use provided that this legend is included on all tape
                      8:  * media and as a part of the software program in whole or part.  Users
                      9:  * may copy or modify these drivers without charge, but are not authorized
                     10:  * to license or distribute them to anyone else except as part of a product or
                     11:  * program developed by the user.
                     12:  * 
                     13:  * THE SUN X DRIVERS ARE PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND
                     14:  * INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A
                     15:  * PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE
                     16:  * PRACTICE.
                     17:  *
                     18:  * The Sun X Drivers are provided with no support and without any obligation
                     19:  * on the part of Sun Microsystems, Inc. to assist in their use, correction,
                     20:  * modification or enhancement.
                     21:  * 
                     22:  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
                     23:  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THE SUN X
                     24:  * DRIVERS OR ANY PART THEREOF.
                     25:  * 
                     26:  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
                     27:  * or profits or other special, indirect and consequential damages, even if
                     28:  * Sun has been advised of the possibility of such damages.
                     29:  * 
                     30:  * Sun Microsystems, Inc.
                     31:  * 2550 Garcia Avenue
                     32:  * Mountain View, California  94043
                     33:  */
                     34: 
                     35: #ifndef        lint
                     36: static char sccsid[] = "@(#)initial.c 1.2 86/08/26 Copyright 1986 Sun Micro";
                     37: #endif
                     38: 
                     39: /*-
                     40:  * Copyright 1985, Massachusetts Institute of Technology
                     41:  * Copyright (c) 1986 by Sun Microsystems,  Inc.
                     42:  */
                     43: 
                     44: /* initial.c   Routines to open & close display
                     45:  *
                     46:  *     OpenDisplay             Open it
                     47:  *     InitDisplay             Download it
                     48:  *     DisplayDead             Check if dead
                     49:  *     Allocate_space          Allocate some temporary storage
                     50:  *
                     51:  */
                     52: 
                     53: /*
                     54:  *     ToDo:
                     55:  *             Look in environment/defaults for programs to start
                     56:  */
                     57: 
                     58: 
                     59: #include <stdio.h>
                     60: #include <fcntl.h>
                     61: #include <errno.h>
                     62: #include <sys/time.h>
                     63: #include <sys/ioctl.h>
                     64: #include <sys/signal.h>
                     65: #include <sun/fbio.h>
                     66: #include "Xsun.h"
                     67: #include <pixrect/pixrect_hs.h>
                     68: #include <sunwindow/rect.h>
                     69: #include <sunwindow/rectlist.h>
                     70: #include <sunwindow/pixwin.h>
                     71: #include <sunwindow/win_screen.h>
                     72: #include <sunwindow/win_struct.h>
                     73: #include <sunwindow/win_input.h>
                     74: #include <sundev/kbd.h>
                     75: #include <sundev/kbio.h>
                     76: 
                     77: extern int InputReader();
                     78: 
                     79: struct pixwin *Display;
                     80: struct pixrect *PixRect;
                     81: u_char InvPix[256];
                     82: 
                     83: short Sun_From_X_Op[] = {
                     84:        PIX_CLR,                        /* GXclear */
                     85:        PIX_SRC&PIX_DST,                /* GXand */
                     86:        PIX_SRC&PIX_NOT(PIX_DST),       /* GXandReverse */
                     87:        PIX_SRC,                        /* GXcopy */
                     88:        PIX_NOT(PIX_SRC)&PIX_DST,       /* GXandInverted */
                     89:        PIX_DST,                        /* GXnoop */
                     90:        PIX_SRC^PIX_DST,                /* GXxor */
                     91:        PIX_SRC|PIX_DST,                /* GXor */
                     92:        PIX_NOT(PIX_SRC)&PIX_NOT(PIX_DST), /* GXnor */
                     93:        PIX_NOT(PIX_SRC)^PIX_DST,       /* GXequiv */
                     94:        PIX_NOT(PIX_DST),               /* GXinvert */
                     95:        PIX_SRC|PIX_NOT(PIX_DST),       /* GXorReverse */
                     96:        PIX_NOT(PIX_SRC),               /* GXcopyInverted */
                     97:        PIX_NOT(PIX_SRC)|PIX_DST,               /* GXorInverted */
                     98:        PIX_NOT(PIX_SRC)|PIX_NOT(PIX_DST), /* GXnand */
                     99:        PIX_SET,                        /* GXset */
                    100: };
                    101: 
                    102: int vsdev = -1;
                    103: extern int errno;
                    104: DEVICE *CurrentDevice;
                    105: 
                    106: #define PARENT "WINDOW_GFX"
                    107: /* Open the display */
                    108: static char *parent;
                    109: 
                    110: #ifdef RAW_KBD
                    111: struct kiockey sunkeymap[128*5];
                    112: #endif
                    113: 
                    114: /*ARGSUSED*/
                    115: OpenDisplay (devname)
                    116:        char *devname;
                    117: {
                    118:     struct screen sc;
                    119:     extern char *getenv();
                    120: 
                    121:     signal (SIGWINCH, SIG_IGN);
                    122:     parent = getenv(PARENT);
                    123:     bzero((caddr_t) & sc, sizeof sc);
                    124:     if (*devname != '/')
                    125:        devname = "/dev/fb";
                    126:     strncpy(sc.scr_fbname, devname, SCR_NAMESIZE);
                    127:     if (parent) {
                    128:        /* Running under "overview" */
                    129:        int         pfd;
                    130: 
                    131:        if ((pfd = open(parent, 2, 0)) < 0) {
                    132:            fprintf(stderr, "Can't open parent %s\n", parent);
                    133:            return (-1);
                    134:        }
                    135:        vsdev = win_getnewwindow();
                    136:        win_setlink(vsdev, WL_PARENT, win_fdtonumber(pfd));
                    137:        win_insert(vsdev);
                    138:        close(pfd);
                    139:     }
                    140:     else {
                    141:        /* Running alone */
                    142:        vsdev = win_screennew(&sc);
                    143:     }
                    144:     return (vsdev);
                    145: }
                    146: 
                    147: /* Do sun specific initialization */
                    148: #ifdef notdef
                    149: static int pid;
                    150: #define        XTERM   "xterm"
                    151: static char *args[] = {
                    152:     XTERM,
                    153:     "=80x24+30+30",
                    154:     "-C",
                    155:     "-n",
                    156:     "console",
                    157:     0,
                    158: };
                    159: 
                    160: #include <sys/wait.h>
                    161: 
                    162: static SigChildHandler()
                    163: {
                    164:     register int dead;
                    165:     union wait status;
                    166: 
                    167:     while ((dead = wait3(&status, WNOHANG, NULL)) > 0) {
                    168:        if (dead == pid) {
                    169:            exit(0);
                    170:        }
                    171:     }
                    172: }
                    173: 
                    174: static StartShell()
                    175: {
                    176:     signal(SIGCHLD, SigChildHandler);
                    177:     if ((pid = fork()) == 0) {
                    178:        {
                    179:            register int i = getdtablesize();
                    180: 
                    181:            while (--i >= 0) {
                    182:                close(i);
                    183:            }
                    184:        }
                    185:        open("/dev/null", 2, 0);
                    186:        dup(0);
                    187:        dup(0);
                    188:        {
                    189:            /* Copy the environment for Setenv */
                    190:            extern char **environ;
                    191:            register int i = 0;
                    192:            char      **envnew;
                    193: 
                    194:            while (environ[i] != NULL)
                    195:                i++;
                    196: 
                    197:            envnew = (char **) malloc(sizeof(char *) * (i + 1));
                    198:            for (; i >= 0; i--)
                    199:                envnew[i] = environ[i];
                    200:            environ = envnew;
                    201:        }
                    202:        {
                    203: #define        HOSTNAMESIZE    128
                    204:            char        DisplayName[HOSTNAMESIZE];
                    205: 
                    206:            gethostname(DisplayName, HOSTNAMESIZE);
                    207:            strcat(DisplayName, ":0");
                    208:            Setenv("DISPLAY=", DisplayName);
                    209: #undef HOSTNAMESIZE
                    210:        }
                    211:        execvp(XTERM, args);
                    212:        _exit(1);
                    213:     }
                    214: }
                    215: #endif
                    216: 
                    217: InitDisplay (info)
                    218:        register DEVICE *info;
                    219: {
                    220:     register int i;
                    221:     static vsCursor vsc;
                    222:     static vsBox vsm;
                    223:     static vsEventQueue vsq = {
                    224:                               NULL,
                    225:                               0,
                    226:                               0,
                    227:                               0,
                    228:     };
                    229:     struct screen sc;
                    230: 
                    231:     win_screenget(vsdev, &sc);
                    232:     info->height = sc.scr_rect.r_height;
                    233:     info->width = sc.scr_rect.r_width;
                    234:     if (parent) {
                    235:        /* running under "overview" */
                    236:        win_setrect(vsdev, &sc.scr_rect);
                    237:     }
                    238:     {
                    239:        struct fbtype fbt;
                    240:        int         fd = open(sc.scr_fbname, O_RDWR, 0);
                    241: 
                    242:        if (fd < 0 || ioctl(fd, FBIOGTYPE, &fbt) < 0) {
                    243:            if (fd < 0)
                    244:                fprintf(stderr, "Can't open fb %s\n", sc.scr_fbname);
                    245:            else
                    246:                fprintf(stderr, "Can't FBIOGTYPE on %s\n", sc.scr_fbname);
                    247:            return (-1);
                    248:        }
                    249:        close(fd);
                    250:        info->id = fbt.fb_type + SUN_BASE;
                    251:        info->planes = fbt.fb_depth;
                    252:        info->entries = fbt.fb_cmsize;
                    253:     }
                    254:     Display = pw_open(vsdev);
                    255:     PixRect = Display->pw_pixrect;
                    256:     pw_reversevideo(Display,0,1);
                    257:     {
                    258:        struct inputmask im;
                    259:        struct kiockey kk;
                    260:        int     kbfd, i = 0;
                    261: 
                    262:        if ((kbfd = open("/dev/kbd", O_RDWR, 0)) >= 0) {
                    263: #ifdef RAW_KBD
                    264:                struct kiockey ok;
                    265: 
                    266:                for (i = 0; i < 0200; ++i) {
                    267:                        ok.kio_station =
                    268:                        kk.kio_station = kk.kio_entry = i;
                    269: 
                    270:                        ok.kio_tablemask = kk.kio_tablemask = 0;
                    271:                        ioctl(kbfd, KIOCGETKEY, &ok);
                    272:                        sunkeymap[i] = ok;
                    273:                        /*
                    274:                         * If I am a shift key then remap past what
                    275:                         * kbd.c knows about so no mapping is done
                    276:                         * Only shift keys can be used the with UPMASK
                    277:                         * due to assumptions in sun's kernel
                    278:                         */
                    279:                        if ((ok.kio_entry & 0xf0) == SHIFTKEYS) {
                    280:                                switch (ok.kio_entry) {
                    281:                                default:
                    282:                                case SHIFTKEYS+CAPSLOCK:
                    283:                                        kk.kio_entry = SHIFTKEYS+10;
                    284:                                        break;
                    285:                                case SHIFTKEYS+SHIFTLOCK:
                    286:                                        kk.kio_entry = SHIFTKEYS+13;
                    287:                                        break;
                    288:                                case SHIFTKEYS+LEFTSHIFT:
                    289:                                        kk.kio_entry = SHIFTKEYS+11;
                    290:                                        break;
                    291:                                case SHIFTKEYS+RIGHTSHIFT:
                    292:                                        kk.kio_entry = SHIFTKEYS+14;
                    293:                                        break;
                    294:                                case SHIFTKEYS+LEFTCTRL:
                    295:                                        kk.kio_entry = SHIFTKEYS+12;
                    296:                                        break;
                    297:                                case SHIFTKEYS+RIGHTCTRL:
                    298:                                        kk.kio_entry = SHIFTKEYS+15;
                    299:                                        break;
                    300:                                }
                    301:                        } else if (ok.kio_entry == BUCKYBITS+METABIT)
                    302:                                kk.kio_entry = SHIFTKEYS+09;
                    303:                        else if (ok.kio_entry == BUCKYBITS+SYSTEMBIT)
                    304:                                kk.kio_entry = ok.kio_entry;
                    305:                        ioctl(kbfd, KIOCSETKEY, &kk);
                    306: 
                    307:                        ok.kio_tablemask = kk.kio_tablemask = CTRLMASK;
                    308:                        ioctl(kbfd, KIOCGETKEY, &ok);
                    309:                        sunkeymap[i+00200] = ok;
                    310: 
                    311:                        ok.kio_tablemask = kk.kio_tablemask = CAPSMASK;
                    312:                        ioctl(kbfd, KIOCGETKEY, &ok);
                    313:                        sunkeymap[i+00400] = ok;
                    314: 
                    315:                        ok.kio_tablemask = kk.kio_tablemask = SHIFTMASK;
                    316:                        ioctl(kbfd, KIOCGETKEY, &ok);
                    317:                        sunkeymap[i+00600] = ok;
                    318: 
                    319:                        ok.kio_tablemask = kk.kio_tablemask = UPMASK;
                    320:                        ioctl(kbfd, KIOCGETKEY, &ok);
                    321:                        sunkeymap[i+01000] = ok;
                    322:                        if ((kk.kio_entry & 0xf0) == SHIFTKEYS)
                    323:                                ioctl(kbfd, KIOCSETKEY, &kk);
                    324:                }
                    325: #else
                    326:                kk.kio_tablemask = 0;
                    327:                kk.kio_entry = ~(SHIFTKEYS+CAPSLOCK);
                    328:                do {
                    329:                        kk.kio_station = i++;
                    330:                        ioctl(kbfd, KIOCGETKEY, &kk);
                    331:                } while ( i < 128 && kk.kio_entry != SHIFTKEYS+CAPSLOCK);
                    332:                if (kk.kio_entry == SHIFTKEYS+CAPSLOCK) {
                    333:                        kk.kio_tablemask = UPMASK;
                    334:                        ioctl(kbfd, KIOCSETKEY, &kk);
                    335:                        kk.kio_tablemask = CTRLMASK;
                    336:                        ioctl(kbfd, KIOCSETKEY, &kk);
                    337:                        kk.kio_tablemask = CAPSMASK;
                    338:                        ioctl(kbfd, KIOCSETKEY, &kk);
                    339:                        kk.kio_tablemask = SHIFTMASK;
                    340:                        ioctl(kbfd, KIOCSETKEY, &kk);
                    341:                }
                    342: #endif
                    343:                close(kbfd);
                    344:        }
                    345:        input_imnull(&im);
                    346:        im.im_flags = IM_ASCII | IM_META | IM_NEGEVENT;
                    347:        win_setinputcodebit(&im, LOC_MOVE);
                    348:        win_setinputcodebit(&im, MS_LEFT);
                    349:        win_setinputcodebit(&im, MS_MIDDLE);
                    350:        win_setinputcodebit(&im, MS_RIGHT);
                    351: #ifdef RAW_KBD
                    352:        win_setinputcodebit(&im, VKEY_FIRSTSHIFT+9);
                    353:        win_setinputcodebit(&im, VKEY_FIRSTSHIFT+10);
                    354:        win_setinputcodebit(&im, VKEY_FIRSTSHIFT+11);
                    355:        win_setinputcodebit(&im, VKEY_FIRSTSHIFT+12);
                    356:        win_setinputcodebit(&im, VKEY_FIRSTSHIFT+13);
                    357:        win_setinputcodebit(&im, VKEY_FIRSTSHIFT+14);
                    358:        win_setinputcodebit(&im, VKEY_FIRSTSHIFT+15);
                    359: #else
                    360:        win_setinputcodebit(&im, SHIFT_CAPSLOCK);
                    361: #endif
                    362:        win_setinputmask(vsdev, &im, NULL, WIN_NULLLINK);
                    363:     }
                    364:     if (fcntl(vsdev, F_SETFL, O_NDELAY) < 0)
                    365:        return (-1);
                    366:     {
                    367:        /* Following struct cannot be included from win_cursor.h */
                    368:        struct cursor {
                    369:                short   cur_xhot, cur_yhot;     /* offset of mouse position from shape*/
                    370:                int     cur_function;           /* relationship of shape to screen */
                    371:                struct  pixrect *cur_shape;     /* memory image to use */
                    372:                int     flags;                  /* various options */
                    373:        
                    374:                short   horiz_hair_thickness;   /* horizontal crosshair height */
                    375:                int     horiz_hair_op;          /*            drawing op       */
                    376:                int     horiz_hair_color;       /*            color            */ 
                    377:                short   horiz_hair_length;      /*            width           */ 
                    378:                short   horiz_hair_gap;         /*            gap             */ 
                    379:        
                    380:                short   vert_hair_thickness;    /* vertical crosshair width  */
                    381:                int     vert_hair_op;           /*          drawing op       */
                    382:                int     vert_hair_color;        /*          color            */ 
                    383:                short   vert_hair_length;       /*          height           */ 
                    384:                short   vert_hair_gap;          /*          gap              */ 
                    385:        } cs;
                    386:        static struct pixrect pr;
                    387: 
                    388:        cs.cur_xhot = cs.cur_yhot = cs.cur_function = 0;
                    389:        cs.flags = 0;
                    390:        cs.cur_shape = &pr;
                    391:        pr.pr_size.x = pr.pr_size.y = 0;
                    392:        win_setcursor(vsdev, &cs);
                    393:        win_setmouseposition(vsdev, info->width >> 1, info->height >> 1);
                    394:     }
                    395:     info->mouse = &vsc;
                    396:     info->mbox = &vsm;
                    397:     info->queue = &vsq;
                    398:     Define_input_handler(InputReader);
                    399:     SetUpInvPix();
                    400:     CurrentDevice = info;
                    401: #ifdef notdef
                    402:     StartShell();
                    403: #endif
                    404:     return (0);
                    405: }
                    406: 
                    407: /* Check if display is dead */
                    408: 
                    409: DisplayDead ()
                    410: {
                    411: #ifdef RAW_KBD
                    412:        int i;
                    413:        int kbfd = open("/dev/kbd", O_RDWR, 0);
                    414:        for (i = 0; i < 0200; ++i) {
                    415:                ioctl(kbfd, KIOCSETKEY, &sunkeymap[i]);
                    416:                if ((sunkeymap[i].kio_entry & 0xf0) == SHIFTKEYS)
                    417:                        ioctl(kbfd, KIOCSETKEY, &sunkeymap[i+01000]);
                    418:                else if (sunkeymap[i].kio_entry == BUCKYBITS+METABIT)
                    419:                        ioctl(kbfd, KIOCSETKEY, &sunkeymap[i+01000]);
                    420:        }
                    421:        close(kbfd);
                    422: #endif
                    423:        return(0);
                    424: }
                    425: 
                    426: /* the presumption here is that only one Allocate_space call is made/request */
                    427: 
                    428: #define ABUFSIZE 3072
                    429: static char ABuffer[3072];     /* random size buffer for allocate space */
                    430: caddr_t AllocateSpace (size)
                    431:        register int size;
                    432: {
                    433:        if (size < ABUFSIZE) return(ABuffer);
                    434:        errno = ENOMEM;
                    435:        return (NULL);
                    436: }
                    437: 
                    438: /* XXX - should be static data */
                    439: SetUpInvPix()
                    440: {
                    441:     register int i;
                    442: 
                    443:     for (i = 255; i >= 0; i--) {
                    444:        register int j = 1, k = 128, l = 8;
                    445: 
                    446:        while (l--) {
                    447:            if ((i & j) != 0)
                    448:                InvPix[i] |= k;
                    449:            j <<= 1;
                    450:            k >>= 1;
                    451:        }
                    452:     }
                    453: }
                    454: 
                    455: #ifdef notdef
                    456: Setenv (var, value)
                    457: /*
                    458:    sets the value of var to be arg in the Unix 4.2 BSD environment env.
                    459:    Var should end with '='.
                    460:    (bindings are of the form "var=value")
                    461:    This procedure assumes the memory for the first level of environ
                    462:    was allocated using malloc.
                    463:  */
                    464: register char *var, *value;
                    465: {
                    466:     extern char **environ;
                    467:     register int index = 0;
                    468: 
                    469:     while (environ[index] != NULL) {
                    470:        if (strncmp(environ[index], var, strlen(var)) == 0) {
                    471:            /* found it */
                    472:            environ[index] = (char *) malloc(strlen(var) + strlen(value));
                    473:            strcpy(environ[index], var);
                    474:            strcat(environ[index], value);
                    475:            return;
                    476:        }
                    477:        index++;
                    478:     }
                    479: 
                    480:     if ((environ = (char **) realloc(environ, sizeof(char *) *
                    481:                                     (index + 2))) == NULL) {
                    482:        fprintf(stderr, "Setenv: malloc out of memory\n");
                    483:        exit(1);
                    484:     }
                    485: 
                    486:     environ[index] = (char *) malloc(strlen(var) + strlen(value));
                    487:     strcpy(environ[index], var);
                    488:     strcat(environ[index], value);
                    489:     environ[++index] = NULL;
                    490: }
                    491: #endif
                    492: #endif sun

unix.superglobalmegacorp.com

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