diff --git a/src/ldeboot.c b/src/ldeboot.c index 2f870cc..1fd356d 100644 --- a/src/ldeboot.c +++ b/src/ldeboot.c @@ -18,6 +18,8 @@ #include #include +#include "unixfork.h" + #if defined(sun) && !defined(OS5) #define USESUNSCREEN #else @@ -26,16 +28,16 @@ #ifdef USESUNSCREEN #include +#ifndef FBTYPE_SUNFAST_COLOR +#define FBTYPE_SUNFAST_COLOR 12 +#endif #define LDEMONO "ldesingle" #define LDECOLOR "ldemulti" #define LDETRUECOLOR "ldetruecolor" -#define FBTYPE_SUNFAST_COLOR 12 #endif /* USESUNSCREEN */ -#include "unixfork.h" - #ifdef XWINDOW #include #include @@ -45,12 +47,6 @@ #ifdef SDL #define LDESDL "ldesdl" #endif -#define LDEMONO "ldesingle" -#define LDECOLOR "ldemulti" -#define LDETRUECOLOR "ldetruecolor" - -#define FBTYPE_SUNFAST_COLOR 12 - /************************************************************************/ /* */ @@ -60,10 +56,11 @@ /* */ /************************************************************************/ -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int i; - char filetorun[30] = {0}; + char *filetorun = NULL; + char *displayName = (char *)NULL; + int doFork = 1; #ifdef USESUNSCREEN int FrameBufferFd; struct fbtype my_screen; @@ -71,143 +68,128 @@ int main(int argc, char *argv[]) struct fbgattr FBattr; #endif /* USESUNSCREEN */ -/* Kickstart program for the Lisp Development Environment (LDE). - Display Device emulator - CG3, CG6 lde.multi - BW2, CG2, CG4, CG9 lde.single + /* Kickstart program for the Lisp Development Environment (LDE). + Display Device emulator + CG3, CG6 lde.multi + BW2, CG2, CG4, CG9 lde.single - FB-TYPE REAL-TYPE - BW2 2 x - CG2 3 3 - CG3 8 6 - CG4 2 8 - CG6 8 12 - CG8 6 7 - CG9(GP1) 4 4 ;gpconfig -f -b - CG9(GP1) 2 13 ;gpconfig gpone0 -f -b cgtwo0 - ;We assume This config for GXP model + FB-TYPE REAL-TYPE + BW2 2 x + CG2 3 3 + CG3 8 6 + CG4 2 8 + CG6 8 12 + CG8 6 7 + CG9(GP1) 4 4 ;gpconfig -f -b + CG9(GP1) 2 13 ;gpconfig gpone0 -f -b cgtwo0 + ;We assume This config for GXP model + */ + + /* look for a -display argument that could tell us X11 vs SDL for display + */ + for (i = 1; i < argc; i++) { + if ((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "-display") == 0)) { + if (i == argc - 1) { + fprintf(stderr, "Missing argument to -display option.\n"); + exit(1); + } + displayName = argv[++i]; + } + } + + /* Unless prevented by -NF option, fork the process, while small, to handle + * process communications and subsequent forks */ -#ifdef XWINDOW - /* If X-Server exists on the host specified in -display option - or environment variable DISPLAY, ldex is started. Otherwise - ldesingle or ldemulti. - */ - { - char *Display_Name = (char *)NULL; - Display *Xdisplay = (Display *)NULL; - char *pos; - - for (i = 1; i < argc; i++) { - if ((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "-display") == 0)) { - if (i == argc) break; - pos = (char *)strchr(argv[++i], ':'); - if (pos != NULL) { Display_Name = argv[i]; } - continue; - } + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-NF") == 0) { + doFork = 0; + break; } + } + if (doFork) fork_Unix(); - if ((Xdisplay = XOpenDisplay(Display_Name)) != (Display *)NULL) { - /* success to connect X-server */ +#ifdef SDL +#ifdef XWINDOW + /* if we have SDL *and* XWINDOW we only do SDL if requested */ + if (displayName && (0 == strcmp(displayName, "SDL"))) { +#else + /* otherwise SDL is it */ + { +#endif + filetorun = LDESDL; + goto run; + } +#endif /* SDL */ + +#ifdef XWINDOW + /* If an X server exists as specified in the -display option + * or environment variable DISPLAY, ldex is started. + */ + { + Display *Xdisplay = XOpenDisplay(displayName); + + if (Xdisplay) { + /* success connecting to X server. Close it now, it will be reopened by ldex */ XCloseDisplay(Xdisplay); - strcpy(filetorun, LDEX); - - /* JRB - call fork_Unix here, while we're REALLY small, unless -NF is - specified, of course... */ - for (i = 1; i < argc; i++) - if (!strcmp(argv[i], "-NF")) break; - if (i == argc) /* -NF not in arguments */ - fork_Unix(); - - argv[0] = filetorun; - execvp(filetorun, argv); - perror(filetorun); + filetorun = LDEX; + goto run; + } else { + fprintf(stderr, "Unable to open X11 display %s\n", + displayName ? displayName : "from DISPLAY"); exit(1); - } else { /* failed to connect X-server */ -#define NAME_LEN 100 - char host_name[NAME_LEN]; - gethostname(host_name, NAME_LEN); - if (Display_Name == NULL) { - if ((Display_Name = getenv("DISPLAY")) != NULL) { - if (strncmp(Display_Name, host_name, strlen(host_name)) == 0) { - fprintf(stderr, "ldeboot: can't find X-Server\n"); - exit(-1); - } /* end if */ - } - /* end if */ - } else { - fprintf(stderr, "ldeboot: can't find X-Server\n"); - exit(-1); - } /* end if */ - } /* end if */ + } } #endif /* XWINDOW */ -#ifdef SDL - strcpy(filetorun,LDESDL); -#endif /* SDL */ + #ifdef USESUNSCREEN if ((FrameBufferFd = open("/dev/fb", O_RDWR)) < 0) { - fprintf(stderr, "ldeboot: can't open FrameBuffer\n"); - exit(-1); + fprintf(stderr, "lde: can't open FrameBuffer\n"); + exit(1); } if (ioctl(FrameBufferFd, FBIOGTYPE, &my_screen) < 0) { - perror("initdisplay0:"); - exit(-1); - } - - if (my_screen.fb_type == FBTYPE_SUN4COLOR) { /* cg3 or cg6 */ - if (ioctl(FrameBufferFd, FBIOGATTR, &FBattr) >= 0) { - if (FBattr.real_type == FBTYPE_SUN3COLOR || /* cg3 */ - FBattr.real_type == FBTYPE_SUNFAST_COLOR) /* cg6 */ - { - strcpy(filetorun, LDECOLOR); - } - } else { /* if( ioctl... */ - perror("lde: This Display Model does not supported\n"); - exit(-1); - } - } else if (my_screen.fb_type == FBTYPE_SUN2BW) { /* bw2, cg4 or cg9 */ - strcpy(filetorun, LDEMONO); - } else if (my_screen.fb_type == FBTYPE_SUN3COLOR) { - if (ioctl(FrameBufferFd, FBIOGATTR, &FBattr) >= 0) { - if (FBattr.real_type == FBTYPE_MEMCOLOR) /* cg8 */ - { - strcpy(filetorun, LDETRUECOLOR); - } - } else { /* if( ioctl... */ - perror("lde: This Display Model does not supported\n"); - exit(-1); - } - - } else if (my_screen.fb_type == FBTYPE_SUN2COLOR) { /* cg2 */ - strcpy(filetorun, LDEMONO); - } else { - perror("lde: This Display Model does not supported\n"); - exit(-1); - } /* endif( my_screen... */ - - close(FrameBufferFd); - -#endif /* USESUNSCREEN */ - - /* JRB - call fork_Unix here, while we're REALLY small, unless -NF is - specified, of course... */ - for (i = 1; i < argc; i++) - if (!strcmp(argv[i], "-NF")) break; - if (i == argc) /* -NF not in arguments */ - fork_Unix(); - - /* start ldemono or ldecolor */ - if (filetorun[0] == '\0') { - fprintf(stderr, "Unable to determine what display program to run.\n"); + perror(argv[0]); exit(1); } - argv[0] = filetorun; /* or whatever... */ - - /* then execve the LDE executable */ - execvp(filetorun, argv); - perror(filetorun); + switch (my_screen.fb_type) { + case FBTYPE_SUN4COLOR: /* cg3 or cg6 */ + if (ioctl(FrameBufferFd, FBIOGATTR, &FBattr) >= 0) { + if (FBattr.real_type == FBTYPE_SUN3COLOR || /* cg3 */ + FBattr.real_type == FBTYPE_SUNFAST_COLOR) /* cg6 */ + { + filetorun = LDECOLOR; + } + } + break; + case FBTYPE_SUN2BW: /* bw2, cg4 or cg9 */ + filetorun = LDEMONO; + break; + case FBTYPE_SUN3COLOR: /* cg8 */ + if (ioctl(FrameBufferFd, FBIOGATTR, &FBattr) >= 0) { + if (FBattr.real_type == FBTYPE_MEMCOLOR) { filetorun = LDETRUECOLOR; } + } + break; + case FBTYPE_SUN2COLOR: /* cg2 */ + filetorun = LDEMONO; + break; + default: break; + } + if (filetorun == (char *)NULL) { + perror("lde: This Display Model is not supported\n"); + exit(1); + } + close(FrameBufferFd); +#endif /* USESUNSCREEN */ + run: + if (filetorun == NULL) { + fprintf(stderr, "Unable to determine what display program to run.\n"); + exit(1); + } + argv[0] = filetorun; + execvp(argv[0], argv); + perror(argv[0]); exit(1); + }