Esempio n. 1
0
/**
 * jar包共享内存操作失败时自动终结当前JVM
 */
static void fail(const char *msg, va_list ap) {
  // This occurs very early during initialization: tty is not initialized.
  jio_fprintf(defaultStream::error_stream(),
              "An error has occurred while processing the"
              " shared archive file.\n");
  jio_vfprintf(defaultStream::error_stream(), msg, ap);
  jio_fprintf(defaultStream::error_stream(), "\n");
  vm_exit_during_initialization("Unable to use shared archive.", NULL);
}
Esempio n. 2
0
static void fail(const char *msg, va_list ap) {
  // This occurs very early during initialization: tty is not initialized.
  jio_fprintf(defaultStream::error_stream(),
              "An error has occurred while processing the"
              " shared archive file.\n");
  jio_vfprintf(defaultStream::error_stream(), msg, ap);
  jio_fprintf(defaultStream::error_stream(), "\n");
  // Do not change the text of the below message because some tests check for it.
  vm_exit_during_initialization("Unable to use shared archive.", NULL);
}
Esempio n. 3
0
int LogFileStreamOutput::write(const LogDecorations& decorations, const char* msg) {
  const bool use_decorations = !_decorators.is_empty();

  int written = 0;
  os::flockfile(_stream);
  if (use_decorations) {
    written += write_decorations(decorations);
    written += jio_fprintf(_stream, " ");
  }
  written += jio_fprintf(_stream, "%s\n", msg);
  fflush(_stream);
  os::funlockfile(_stream);

  return written;
}
Esempio n. 4
0
int LogFileStreamOutput::write(LogMessageBuffer::Iterator msg_iterator) {
  const bool use_decorations = !_decorators.is_empty();

  int written = 0;
  os::flockfile(_stream);
  for (; !msg_iterator.is_at_end(); msg_iterator++) {
    if (use_decorations) {
      written += write_decorations(msg_iterator.decorations());
      written += jio_fprintf(_stream, " ");
    }
    written += jio_fprintf(_stream, "%s\n", msg_iterator.message());
  }
  fflush(_stream);
  os::funlockfile(_stream);

  return written;
}
Esempio n. 5
0
/*
 * Performs Solaris dependent mapping. Returns a zone ID if
 * found. Otherwise, NULL is returned.  Solaris libc looks up
 * "/etc/default/init" to get the default TZ value if TZ is not defined
 * as an environment variable.
 */
static char *
getPlatformTimeZoneID()
{
    char *tz = NULL;
    FILE *fp;

    /*
     * Try the TZ entry in /etc/default/init.
     */
    if ((fp = fileopen(SYS_INIT_FILE, "r")) != NULL) {
        char line[256];
        char quote = '\0';

        while (filegets(line, sizeof(line), fp) != NULL) {
            char *p = line;
            char *s;
            char c;

            /* quick check for comment lines */
            if (*p == '#') {
                continue;
            }
            if (strncmp(p, "TZ=", 3) == 0) {
                p += 3;
                SKIP_SPACE(p);
                c = *p;
                if (c == '"' || c == '\'') {
                    quote = c;
                    p++;
                }

                /*
                 * PSARC/2001/383: quoted string support
                 */
                for (s = p; (c = *s) != '\0' && c != '\n'; s++) {
                    /* No '\\' is supported here. */
                    if (c == quote) {
                        quote = '\0';
                        break;
                    }
                    if (c == ' ' && quote == '\0') {
                        break;
                    }
                }
                if (quote != '\0') {
                    jio_fprintf(stderr, "ZoneInfo: unterminated time zone name in /etc/TIMEZONE\n");
                }
                *s = '\0';
                tz = strdup(p);
                break;
            }
        }
        (void) fileclose(fp);
    }
    return tz;
}
Esempio n. 6
0
LogFileOutput::~LogFileOutput() {
  if (_stream != NULL) {
    if (fclose(_stream) != 0) {
      jio_fprintf(defaultStream::error_stream(), "Could not close log file '%s' (%s).\n",
                  _file_name, os::strerror(errno));
    }
  }
  os::free(_archive_name);
  os::free(_file_name);
  os::free(const_cast<char*>(_name));
}
Esempio n. 7
0
/* Load a .class file normally from the local disk */
static ClassClass *
LoadClassFromFile(char *fn, char *dir, char *class_name)
{
    extern int OpenCode(char *, char *, char *, struct stat*);
    struct stat st;
    ClassClass *cb = 0;
    int codefd = -1;
    int	retryCount = 0;
    unsigned char *external_class;
    char *detail;

    codefd = OpenCode(fn, NULL, dir, &st);

    if (codefd < 0)		/* open failed */
	return 0;

    /* Snarf the file into memory. */
    external_class = (unsigned char *)sysMalloc(st.st_size);
    if (external_class == 0)
        goto failed;
    if (sysRead(codefd, external_class, st.st_size) != st.st_size)
        goto failed;
    sysClose(codefd);
    codefd = -1;

    /* Create the internal class */
    cb = allocClassClass();
    if (cb == NULL || 
	!createInternalClass(external_class, external_class + st.st_size, 
			     cb, NULL, class_name, &detail)) {
	sysFree(external_class);
	goto failed;
    }
    sysFree(external_class);

    if (verbose)
	jio_fprintf(stderr, "[Loaded %s]\n", fn);
    return cb;
failed:
    if (codefd >= 0)
	sysClose(codefd);
    if (cb != 0)
        FreeClass(cb);
    return 0;
}
Esempio n. 8
0
static void 
printToFile(JNIEnv *env, jstring s, FILE *file)
{ 
    char *sConverted;
    int length;
    int i;
    const jchar *sAsArray;

    sAsArray = (*env)->GetStringChars(env, s, NULL); 
    length = (*env)->GetStringLength(env, s);
    sConverted = (char *) malloc(length + 1);
    for(i = 0; i < length; i++) {
	sConverted[i] = (0x7f & sAsArray[i]);
    }
    sConverted[length] = '\0';
    jio_fprintf(file, "%s", sConverted);
    (*env)->ReleaseStringChars(env, s, sAsArray);
    free(sConverted); 
}
Esempio n. 9
0
static void 
dump_scroll_attrs(Widget scrollbar)
{
    unsigned char orient;
    int32_t value, size, incr, pIncr, max, min;

    XtVaGetValues(scrollbar,
                  XmNvalue, &value,
                  XmNincrement, &incr,
                  XmNpageIncrement, &pIncr,
                  XmNsliderSize, &size,
                  XmNmaximum, &max,
                  XmNminimum, &min,
                  XmNorientation, &orient,
                  NULL);

    jio_fprintf(stdout, "%s: min=%d max=%d slider-size=%d incr=%d pageIncr=%d value = %d\n",
                orient == XmVERTICAL ? "VSB" : "HSB", min, max, size,
                incr, pIncr, value);
}
Esempio n. 10
0
int LogFileStreamOutput::write_decorations(const LogDecorations& decorations) {
  int total_written = 0;

  for (uint i = 0; i < LogDecorators::Count; i++) {
    LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(i);
    if (!_decorators.is_decorator(decorator)) {
      continue;
    }

    int written = jio_fprintf(_stream, "[%-*s]",
                              _decorator_padding[decorator],
                              decorations.decoration(decorator));
    if (written <= 0) {
      return -1;
    } else if (static_cast<size_t>(written - 2) > _decorator_padding[decorator]) {
      _decorator_padding[decorator] = written - 2;
    }
    total_written += written;
  }
  return total_written;
}
Esempio n. 11
0
void getExtAwtData(Display      *display,
		   int32_t      screen,
		   int32_t      *awt_depth,
		   Colormap     *awt_cmap,
		   Visual       **awt_visual,
		   int32_t      *awt_num_colors,
		   void         *pReserved)
{
  AwtGraphicsConfigDataPtr defaultConfig = NULL;

#ifdef DEBUG
  if (pReserved != NULL) {
    jio_fprintf(stderr,
                "getExtAwtData: warning: reserved pointer is not null\n");
  }
#endif

  if (screen >= 0) {
    defaultConfig = getDefaultConfig(screen);
  }

  if (defaultConfig) {
    if (awt_depth != NULL) {
      *awt_depth = defaultConfig->awt_depth;
    }
    
    if (awt_cmap != NULL) {
      *awt_cmap = defaultConfig->awt_cmap;
    }
    
    if (awt_visual != NULL) {
      *awt_visual = defaultConfig->awt_visInfo.visual;
    }
    
    if (awt_num_colors != NULL) {
      *awt_num_colors = defaultConfig->awt_num_colors;
    }
  }
}
Esempio n. 12
0
void getAwtLockFunctions(void (**AwtLock)(JNIEnv *),
			 void (**AwtUnlock)(JNIEnv *),
			 void (**AwtNoFlushUnlock)(JNIEnv *),
			 void *pReserved)
{
#ifdef DEBUG
  if (pReserved != NULL) {
    jio_fprintf(stderr,
		"getAwtLockFunctions: warning: reserved pointer is not null\n");
  }
#endif

  if (AwtLock != NULL) {
    *AwtLock = awt_lock_wrapper;
  }

  if (AwtUnlock != NULL) {
    *AwtUnlock = awt_unlock_wrapper;
  }

  if (AwtNoFlushUnlock != NULL) {
    *AwtNoFlushUnlock = awt_noflush_unlock_wrapper;
  }
}
Esempio n. 13
0
/* get_im_height: returns height of the input method status area in pixels.
 *
 * This function assumes that if any XIM related information cannot be
 * queried then the app must not have an input method status area in the
 * current locale and returns zero as the status area height
 */
int32_t
awt_motif_getIMStatusHeight(Widget w, jobject tc)
{
    XIC xic = NULL;
    XRectangle *im_rect=NULL;
    int32_t im_height = 0;
    char *ret;

    xic = XmImGetXIC(getTextWidget(tc), XmPER_SHELL, NULL, 0);

    if(xic != NULL) {
        /* finally query the server for the status area geometry */
        xic_vlist[0].name = XNArea;
        xic_vlist[0].value = (XtArgVal)&im_rect;
        xic_vlist[1].name = NULL;
        ret=XGetICValues(xic, XNStatusAttributes, &xic_vlist[0], NULL);
        if (ret == NULL && im_rect != NULL) {
            im_height = im_rect->height;
            if (im_height > 0) {
                im_height += SEPARATOR_HEIGHT;
            }
            XFree(im_rect);
        } else {
            im_height = 0;
        }
    }

    if (im_height == 0) {
        im_height = _XmImGetGeo(w);
    }

#if defined(DEBUG)
    jio_fprintf(stderr,"awt_motif_getIMStatusHeight: Height = %d",im_height);
#endif
    return im_height;
}
Esempio n. 14
0
static char *
mapPlatformToJavaTimezone(const char *java_home_dir, const char *tz) {
    FILE *tzmapf;
    char mapfilename[PATH_MAX + 1];
    char line[256];
    int linecount = 0;
    char *tz_buf = NULL;
    char *temp_tz = NULL;
    char *javatz = NULL;
    size_t tz_len = 0;

    /* On AIX, the TZ environment variable may end with a comma
     * followed by modifier fields. These are ignored here. */
    temp_tz = strchr(tz, ',');
    tz_len = (temp_tz == NULL) ? strlen(tz) : temp_tz - tz;
    tz_buf = (char *)malloc(tz_len + 1);
    memcpy(tz_buf, tz, tz_len);
    tz_buf[tz_len] = 0;

    /* Open tzmappings file, with buffer overrun check */
    if ((strlen(java_home_dir) + 15) > PATH_MAX) {
        jio_fprintf(stderr, "Path %s/lib/tzmappings exceeds maximum path length\n", java_home_dir);
        goto tzerr;
    }
    strcpy(mapfilename, java_home_dir);
    strcat(mapfilename, "/lib/tzmappings");
    if ((tzmapf = fopen(mapfilename, "r")) == NULL) {
        jio_fprintf(stderr, "can't open %s\n", mapfilename);
        goto tzerr;
    }

    while (fgets(line, sizeof(line), tzmapf) != NULL) {
        char *p = line;
        char *sol = line;
        char *java;
        int result;

        linecount++;
        /*
         * Skip comments and blank lines
         */
        if (*p == '#' || *p == '\n') {
            continue;
        }

        /*
         * Get the first field, platform zone ID
         */
        while (*p != '\0' && *p != '\t') {
            p++;
        }
        if (*p == '\0') {
            /* mapping table is broken! */
            jio_fprintf(stderr, "tzmappings: Illegal format at near line %d.\n", linecount);
            break;
        }

        *p++ = '\0';
        if ((result = strncmp(tz_buf, sol, tz_len)) == 0) {
            /*
             * If this is the current platform zone ID,
             * take the Java time zone ID (2nd field).
             */
            java = p;
            while (*p != '\0' && *p != '\n') {
                p++;
            }

            if (*p == '\0') {
                /* mapping table is broken! */
                jio_fprintf(stderr, "tzmappings: Illegal format at line %d.\n", linecount);
                break;
            }

            *p = '\0';
            javatz = strdup(java);
            break;
        } else if (result < 0) {
            break;
        }
    }
    (void) fclose(tzmapf);

tzerr:
    if (tz_buf != NULL ) {
        free((void *) tz_buf);
    }

    if (javatz == NULL) {
        return getGMTOffsetID();
    }

    return javatz;
}
Esempio n. 15
0
/*
 * Performs Linux specific mapping and returns a zone ID
 * if found. Otherwise, NULL is returned.
 */
static char *
getPlatformTimeZoneID()
{
    struct stat statbuf;
    char *tz = NULL;
    FILE *fp;
    int fd;
    char *buf;
    size_t size;

#if defined(__linux__)
    /*
     * Try reading the /etc/timezone file for Debian distros. There's
     * no spec of the file format available. This parsing assumes that
     * there's one line of an Olson tzid followed by a '\n', no
     * leading or trailing spaces, no comments.
     */
    if ((fp = fopen(ETC_TIMEZONE_FILE, "r")) != NULL) {
        char line[256];

        if (fgets(line, sizeof(line), fp) != NULL) {
            char *p = strchr(line, '\n');
            if (p != NULL) {
                *p = '\0';
            }
            if (strlen(line) > 0) {
                tz = strdup(line);
            }
        }
        (void) fclose(fp);
        if (tz != NULL) {
            return tz;
        }
    }
#endif /* defined(__linux__) */

    /*
     * Next, try /etc/localtime to find the zone ID.
     */
    if (lstat(DEFAULT_ZONEINFO_FILE, &statbuf) == -1) {
        return NULL;
    }

    /*
     * If it's a symlink, get the link name and its zone ID part. (The
     * older versions of timeconfig created a symlink as described in
     * the Red Hat man page. It was changed in 1999 to create a copy
     * of a zoneinfo file. It's no longer possible to get the zone ID
     * from /etc/localtime.)
     */
    if (S_ISLNK(statbuf.st_mode)) {
        char linkbuf[PATH_MAX+1];
        int len;

        if ((len = readlink(DEFAULT_ZONEINFO_FILE, linkbuf, sizeof(linkbuf)-1)) == -1) {
            jio_fprintf(stderr, (const char *) "can't get a symlink of %s\n",
                        DEFAULT_ZONEINFO_FILE);
            return NULL;
        }
        linkbuf[len] = '\0';
        tz = getZoneName(linkbuf);
        if (tz != NULL) {
            tz = strdup(tz);
            return tz;
        }
    }

    /*
     * If it's a regular file, we need to find out the same zoneinfo file
     * that has been copied as /etc/localtime.
     * If initial symbolic link resolution failed, we should treat target
     * file as a regular file.
     */
    if ((fd = open(DEFAULT_ZONEINFO_FILE, O_RDONLY)) == -1) {
        return NULL;
    }
    if (fstat(fd, &statbuf) == -1) {
        (void) close(fd);
        return NULL;
    }
    size = (size_t) statbuf.st_size;
    buf = (char *) malloc(size);
    if (buf == NULL) {
        (void) close(fd);
        return NULL;
    }

    if (read(fd, buf, size) != (ssize_t) size) {
        (void) close(fd);
        free((void *) buf);
        return NULL;
    }
    (void) close(fd);

    tz = findZoneinfoFile(buf, size, ZONEINFO_DIR);
    free((void *) buf);
    return tz;
}
Esempio n. 16
0
/*
 * Scans the specified directory and its subdirectories to find a
 * zoneinfo file which has the same content as /etc/localtime on Linux
 * or /usr/share/lib/zoneinfo/localtime on Solaris given in 'buf'.
 * If file is symbolic link, then the contents it points to are in buf.
 * Returns a zone ID if found, otherwise, NULL is returned.
 */
static char *
findZoneinfoFile(char *buf, size_t size, const char *dir)
{
    DIR *dirp = NULL;
    struct stat statbuf;
    struct dirent *dp = NULL;
    struct dirent *entry = NULL;
    char *pathname = NULL;
    int fd = -1;
    char *dbuf = NULL;
    char *tz = NULL;

    dirp = opendir(dir);
    if (dirp == NULL) {
        return NULL;
    }

    entry = (struct dirent *) malloc((size_t) pathconf(dir, _PC_NAME_MAX));
    if (entry == NULL) {
        (void) closedir(dirp);
        return NULL;
    }

#if defined(__linux__) || defined(MACOSX) || (defined(__solaris__) \
    && (defined(_POSIX_PTHREAD_SEMANTICS) || defined(_LP64)))
    while (readdir_r(dirp, entry, &dp) == 0 && dp != NULL) {
#else
    while ((dp = readdir_r(dirp, entry)) != NULL) {
#endif

        /*
         * Skip '.' and '..' (and possibly other .* files)
         */
        if (dp->d_name[0] == '.') {
            continue;
        }

        /*
         * Skip "ROC", "posixrules", and "localtime".
         */
        if ((strcmp(dp->d_name, "ROC") == 0)
            || (strcmp(dp->d_name, "posixrules") == 0)
#ifdef __solaris__
            /*
             * Skip the "src" and "tab" directories on Solaris.
             */
            || (strcmp(dp->d_name, "src") == 0)
            || (strcmp(dp->d_name, "tab") == 0)
#endif
            || (strcmp(dp->d_name, "localtime") == 0)) {
            continue;
        }

        pathname = getPathName(dir, dp->d_name);
        if (pathname == NULL) {
            break;
        }
        if (stat(pathname, &statbuf) == -1) {
            break;
        }

        if (S_ISDIR(statbuf.st_mode)) {
            tz = findZoneinfoFile(buf, size, pathname);
            if (tz != NULL) {
                break;
            }
        } else if (S_ISREG(statbuf.st_mode) && (size_t)statbuf.st_size == size) {
            dbuf = (char *) malloc(size);
            if (dbuf == NULL) {
                break;
            }
            if ((fd = open(pathname, O_RDONLY)) == -1) {
                fd = 0;
                break;
            }
            if (read(fd, dbuf, size) != (ssize_t) size) {
                break;
            }
            if (memcmp(buf, dbuf, size) == 0) {
                tz = getZoneName(pathname);
                if (tz != NULL) {
                    tz = strdup(tz);
                }
                break;
            }
            free((void *) dbuf);
            dbuf = NULL;
            (void) close(fd);
            fd = 0;
        }
        free((void *) pathname);
        pathname = NULL;
    }

    if (entry != NULL) {
        free((void *) entry);
    }
    if (dirp != NULL) {
        (void) closedir(dirp);
    }
    if (pathname != NULL) {
        free((void *) pathname);
    }
    if (fd != 0) {
        (void) close(fd);
    }
    if (dbuf != NULL) {
        free((void *) dbuf);
    }
    return tz;
}

#if defined(__linux__) || defined(MACOSX)

/*
 * Performs Linux specific mapping and returns a zone ID
 * if found. Otherwise, NULL is returned.
 */
static char *
getPlatformTimeZoneID()
{
    struct stat statbuf;
    char *tz = NULL;
    FILE *fp;
    int fd;
    char *buf;
    size_t size;

#ifdef __linux__
    /*
     * Try reading the /etc/timezone file for Debian distros. There's
     * no spec of the file format available. This parsing assumes that
     * there's one line of an Olson tzid followed by a '\n', no
     * leading or trailing spaces, no comments.
     */
    if ((fp = fopen(ETC_TIMEZONE_FILE, "r")) != NULL) {
        char line[256];

        if (fgets(line, sizeof(line), fp) != NULL) {
            char *p = strchr(line, '\n');
            if (p != NULL) {
                *p = '\0';
            }
            if (strlen(line) > 0) {
                tz = strdup(line);
            }
        }
        (void) fclose(fp);
        if (tz != NULL) {
            return tz;
        }
    }
#endif /* __linux__ */

    /*
     * Next, try /etc/localtime to find the zone ID.
     */
    if (lstat(DEFAULT_ZONEINFO_FILE, &statbuf) == -1) {
        return NULL;
    }

    /*
     * If it's a symlink, get the link name and its zone ID part. (The
     * older versions of timeconfig created a symlink as described in
     * the Red Hat man page. It was changed in 1999 to create a copy
     * of a zoneinfo file. It's no longer possible to get the zone ID
     * from /etc/localtime.)
     */
    if (S_ISLNK(statbuf.st_mode)) {
        char linkbuf[PATH_MAX+1];
        int len;

        if ((len = readlink(DEFAULT_ZONEINFO_FILE, linkbuf, sizeof(linkbuf)-1)) == -1) {
            jio_fprintf(stderr, (const char *) "can't get a symlink of %s\n",
                        DEFAULT_ZONEINFO_FILE);
            return NULL;
        }
        linkbuf[len] = '\0';
        tz = getZoneName(linkbuf);
        if (tz != NULL) {
            tz = strdup(tz);
            return tz;
        }
    }

    /*
     * If it's a regular file, we need to find out the same zoneinfo file
     * that has been copied as /etc/localtime.
     * If initial symbolic link resolution failed, we should treat target
     * file as a regular file.
     */
    if ((fd = open(DEFAULT_ZONEINFO_FILE, O_RDONLY)) == -1) {
        return NULL;
    }
    if (fstat(fd, &statbuf) == -1) {
        (void) close(fd);
        return NULL;
    }
    size = (size_t) statbuf.st_size;
    buf = (char *) malloc(size);
    if (buf == NULL) {
        (void) close(fd);
        return NULL;
    }

    if (read(fd, buf, size) != (ssize_t) size) {
        (void) close(fd);
        free((void *) buf);
        return NULL;
    }
    (void) close(fd);

    tz = findZoneinfoFile(buf, size, ZONEINFO_DIR);
    free((void *) buf);
    return tz;
}
#else
#ifdef __solaris__
#if !defined(__sparcv9) && !defined(amd64)

/*
 * Those file* functions mimic the UNIX stream io functions. This is
 * because of the limitation of the number of open files on Solaris
 * (32-bit mode only) due to the System V ABI.
 */

#define BUFFER_SIZE     4096

static struct iobuffer {
    int     magic;      /* -1 to distinguish from the real FILE */
    int     fd;         /* file descriptor */
    char    *buffer;    /* pointer to buffer */
    char    *ptr;       /* current read pointer */
    char    *endptr;    /* end pointer */
};

static int
fileclose(FILE *stream)
{
    struct iobuffer *iop = (struct iobuffer *) stream;

    if (iop->magic != -1) {
        return fclose(stream);
    }

    if (iop == NULL) {
        return 0;
    }
    close(iop->fd);
    free((void *)iop->buffer);
    free((void *)iop);
    return 0;
}

static FILE *
fileopen(const char *fname, const char *fmode)
{
    FILE *fp;
    int fd;
    struct iobuffer *iop;

    if ((fp = fopen(fname, fmode)) != NULL) {
        return fp;
    }

    /*
     * It assumes read open.
     */
    if ((fd = open(fname, O_RDONLY)) == -1) {
        return NULL;
    }

    /*
     * Allocate struct iobuffer and its buffer
     */
    iop = malloc(sizeof(struct iobuffer));
    if (iop == NULL) {
        (void) close(fd);
        errno = ENOMEM;
        return NULL;
    }
    iop->magic = -1;
    iop->fd = fd;
    iop->buffer = malloc(BUFFER_SIZE);
    if (iop->buffer == NULL) {
        (void) close(fd);
        free((void *) iop);
        errno = ENOMEM;
        return NULL;
    }
    iop->ptr = iop->buffer;
    iop->endptr = iop->buffer;
    return (FILE *)iop;
}
Esempio n. 17
0
XVaNestedList awt_motif_getXICStatusAreaList(Widget w, jobject tc)
{
    XIC xic;

    XRectangle *im_rect;
    XFontSet   *im_font;

    Pixel bg ;
    Pixel fg ;
    Dimension height, width ;
    Position x,y ;

    XVaNestedList list = NULL;

    char *ret;
    Widget p=w;

    while (!XtIsShell(p)) {
        p = XtParent(p);
    }

    XtVaGetValues(p,
        XmNx, &x,
        XmNy, &y,
        XmNwidth, &width,
        XmNheight, &height,
        XmNbackgroundPixmap, &bpm,
        NULL);



    xic = XmImGetXIC(getTextWidget(tc), XmPER_SHELL, NULL, 0);
    if(xic == NULL)
    {
#if defined DEBUG
        jio_fprintf(stderr,"Could not get XIC");
#endif
        return list ;
    }

   /* finally query the server for the required attributes area geometry */
    xic_vlist[0].name = XNFontSet ;
    xic_vlist[0].value =  (XtArgVal) &im_font ;
    xic_vlist[1].name = XNArea;
    xic_vlist[1].value = (XtArgVal) &im_rect;
    xic_vlist[2].name = XNBackground ;
    xic_vlist[2].value = (XtArgVal) &bg ;
    xic_vlist[3].name = XNForeground ;
    xic_vlist[3].value = (XtArgVal) &fg ;
    xic_vlist[4].name = NULL;


    if(ret=XGetICValues(xic, XNStatusAttributes, &xic_vlist[0], NULL))
    {
        return list ;
    } else {
        geomRect.x = 0 ;
        geomRect.y = height - im_rect->height ;
        geomRect.width = im_rect->width ;
        geomRect.height = im_rect->height ;
        XFree(im_rect) ;

        list = XVaCreateNestedList(0 ,
                        XNFontSet, im_font ,
                        XNArea, &geomRect ,
                        XNBackground, bg ,
                        XNForeground, fg ,
                        XNBackgroundPixmap, &bpm ,
                        NULL );
    }
#if defined(DEBUG)
    jio_fprintf(stderr,"awt_motif_getXICStatusAreaList:\n");
    jio_fprintf(stderr,"XNArea:x=%d,y=%d,width=%d,height=%d\n", \
         geomRect.x,geomRect.y,geomRect.width,geomRect.height);
    jio_fprintf(stderr,"XNBackground=0x%x\n",bg);
    jio_fprintf(stderr,"XNForeground=0x%x\n",fg);
    jio_fprintf(stderr,"XNBackgroundPixmap=0x%x\n",bpm);
#endif
    return list ;

}
Esempio n. 18
0
// **** Audio card support
// Aquire and enabled audio card
// return 0 if ok, -1 if failed
// $$kk: 08.12.98 merge: modified this function
int HAE_AquireAudioCard(void *context, UINT32 sampleRate, UINT32 channels, UINT32 bits)
{
    int	flag;
    long error;

#ifdef DEBUG_AUDIO
    jio_fprintf(stderr, "Acquire audio card(sampleRate=%d, channels=%d, bits=%d\n", sampleRate, channels, bits);
#endif


    flag = 0;
    g_activeDoubleBuffer = FALSE;
    g_shutDownDoubleBuffer = TRUE;


    g_audioFramesToGenerate = HAE_GetMaxSamplePerSlice();

#ifdef TODO // ask Kara
    switch (sampleRate) {
    case 44100:
        g_audioFramesToGenerate = HAE_GetMaxSamplePerSlice();
        break;
    case 11025:
        /* [sbb fix] why is this case thrown away? */
        sampleRate = 22050;
    case 22050:
        g_audioFramesToGenerate = HAE_GetMaxSamplePerSlice()/2;
        break;
    }
#endif

    /* we're going to build this many buffers at a time */
    g_synthFramesPerBlock = HAE_LINUX_FRAMES_PER_BLOCK;
    g_audioPeriodSleepTime = HAE_LINUX_SOUND_PERIOD;
    g_bitSize = bits;
    g_channels = channels;
    if (bits == 8) {
        g_audioByteBufferSize = (sizeof(char) * g_audioFramesToGenerate);
    } else {
        g_audioByteBufferSize = (sizeof(short int) * g_audioFramesToGenerate);
    }
    g_audioByteBufferSize *= channels;

    flag = 1;
    /* allocate buffer blocks */
    g_audioBufferBlock = HAE_Allocate(g_audioByteBufferSize * HAE_LINUX_FRAMES_PER_BLOCK);

    if (g_audioBufferBlock) {

        g_waveDevice = HAE_OpenSoundCard(0); // for playback

        if (g_waveDevice > 0) {
            /* for linux it's
             *    set sample format,
             *    set channels (mono or stereo)
             *    set sample rate
             */

            int format = AFMT_MU_LAW;
            int stereo = (channels == 2);
            int speed = sampleRate;

            switch (bits) {
            case 8:
                format = AFMT_MU_LAW;	/* [sbb fix] don't know if this is right or not -- maybe should be s8? */
                break;

            case 16:
                format = LINUX_FORMAT16;
                break;

                //default:
                //fprintf(stderr, "Warning: unhandled number of data bits %d\n", (int) bits);
            }

            error = ioctl(g_waveDevice, SNDCTL_DSP_SETFMT, &format);

            if (error < 0) {
                //perror("SNDCTL_DSP_SETFMT");
                //exit(1);
            }

            error = ioctl(g_waveDevice, SNDCTL_DSP_STEREO, &stereo);

            if (error < 0) {
                /* [sbb fix] issue some kind of error message */

                //perror("SNDCTL_DSP_STEREO");
                //exit(1);
            }



            if (ioctl(g_waveDevice, SNDCTL_DSP_SPEED, &speed) < 0) { /* Fatal error */
                /* [sbb fix] handle this better */
                //perror("SNDCTL_DSP_SPEED");
                // $$ay: dont exit !
                // exit(1);
            }

            if (speed != (INT32) sampleRate) {
                /* [sbb fix] need to issue a message */
            }


            if (error == 0) {
                g_shutDownDoubleBuffer = FALSE;
                g_activeDoubleBuffer = TRUE;	/* must enable process, before thread begins */


                /* $$kk: 05.06.98: added this whole block.
                 * we need to reset the lastPos each time the device gets acquired.
                 * otherwise we may get stuck in the wait loop because we never count
                 * up to the right sample position. */
                {
#ifdef NOT_HERE_BUT_PRESERVED
                    audio_info_t	sunAudioHeader;
                    long sampleFrameSize;

                    ioctl(g_waveDevice, AUDIO_GETINFO, &sunAudioHeader);

                    /* [sbb] I don't think this should be any value other than zero,
                     * since we just opened the device... */
                    /* lastPos = sunAudioHeader.play.samples - ((g_audioByteBufferSize * HAE_LINUX_FRAMES_PER_BLOCK * 2) / sampleFrameSize); */
                    lastPos = 0;
#endif
                }


                /* Spin threads for device service and possibly
                 * stream service.
                 */
                /* create thread to manage and render audio frames */
                error = HAE_CreateFrameThread(context, PV_AudioWaveOutFrameThread);

                if (error == 0) {	/* ok */
                    flag = 0;
                } else {
                    flag = 1;
                    g_activeDoubleBuffer = FALSE;
                }
            }
        }
    }

    if (flag) {	/* something failed */
        HAE_CloseSoundCard(0); // Close for playback
    }
    return flag;
}
Esempio n. 19
0
void
img_makePalette(int cmapsize, int tablesize, int lookupsize,
		float lscale, float weight,
		int prevclrs, int doMac,
		unsigned char *reds,
		unsigned char *greens,
		unsigned char *blues,
		unsigned char *lookup)
{
    CmapEntry *pCmap;
    int i, ix;
#ifdef STATS
    double ave_dL, ave_dE;
    double max_dL, max_dE;
#endif /* STATS */
#ifdef TIMES
    clock_t start, mid, tbl, end;

    start = clock();
#endif /* TIMES */

    init_matrices();
    Lscale = lscale;
    Weight = weight;

    cmapmax = cmapsize;
    total = 0;
    for (i = 0; i < prevclrs; i++) {
	add_color(reds[i], greens[i], blues[i], TRUE);
    }

    add_color(0, 0, 0, TRUE);
    add_color(255,255,255, TRUE);

    /* do grays next; otherwise find_nearest may break! */
    init_grays();
    if (doMac) {
	init_mac_palette();
    }
    init_pastels();

    init_primaries();

    /* special case some blues */
    add_color(0,0,192,TRUE);
    add_color(0x30,0x20,0x80,TRUE);
    add_color(0x20,0x60,0xc0,TRUE);

    init_virt_cmap(lookupsize, tablesize);

    while (total < cmapsize) {
	handle_biggest_offenders(tablesize, cmapsize);
    }

    memcpy(reds, cmap_r, cmapsize);
    memcpy(greens, cmap_g, cmapsize);
    memcpy(blues, cmap_b, cmapsize);

#ifdef TIMES
    mid = clock();
#endif /* TIMES */

    pCmap = virt_cmap;
    for (i = 0; i < num_virt_cmap_entries; i++, pCmap++) {
	if (pCmap->nextidx < 0) {
	    continue;
	}
	if (pCmap->nextidx < total) {
	    ix = find_nearest(pCmap);
	}
    }

#ifdef TIMES
    tbl = clock();
#endif /* TIMES */

    pCmap = virt_cmap;
    if (tablesize != lookupsize) {
	int r, g, b;
	for (r = 0; r < lookupsize; ++r)
	{
	    for (g = 0; g < lookupsize; ++g)
	    {
		for (b = 0; b < lookupsize; ++b, pCmap++)
		{
		    float L, U, V;
		    float bestd = 0;
		    CmapEntry *pTest;

		    if (pCmap->nextidx >= 0) {
			continue;
		    }
#ifdef DEBUG
		    if (r == g && g == b) {
			jio_fprintf(stderr, "GRAY VALUE!?\n");
		    }
#endif /* DEBUG */
		    L = pCmap->L;
		    U = pCmap->U;
		    V = pCmap->V;
		    for (i = 0; i < 8; i++) {
			int ri, gi, bi;
			float d, t;
			ri = (i & 1) ? prevtest[r] : nexttest[r];
			gi = (i & 2) ? prevtest[g] : nexttest[g];
			bi = (i & 4) ? prevtest[b] : nexttest[b];
			pTest = &virt_cmap[((ri * lookupsize)
					    + gi) * lookupsize
					   + bi];
#ifdef DEBUG
			if (pTest->nextidx < 0) {
			    jio_fprintf(stderr, "OOPS!\n");
			}
#endif /* DEBUG */
			ix = pTest->bestidx;
			t = Ltab[ix] - L; d  = t * t * Lscale;
			if (i != 0 && d > bestd) continue;
			t = Utab[ix] - U; d += t * t;
			if (i != 0 && d > bestd) continue;
			t = Vtab[ix] - V; d += t * t;
			if (i != 0 && d > bestd) continue;
			bestd = d;
			pCmap->bestidx = ix;
		    }
		}
	    }
	}
    }
    pCmap = virt_cmap;
    for (i = 0; i < num_virt_cmap_entries; i++) {
	*lookup++ = (pCmap++)->bestidx;
    }

#ifdef TIMES
    end = clock();
#endif /* TIMES */

#ifdef STATS
    max_dL = 0.0;
    max_dE = 0.0;
    ave_dL = 0.0;
    ave_dE = 0.0;

    pCmap = virt_cmap;
    for (i = 0; i < num_virt_cmap_entries; i++, pCmap++) {
	double t, dL, dU, dV, dE;
	if (pCmap->nextidx < 0) {
	    int ix = pCmap->bestidx;
	    dL = pCmap->L - Ltab[ix]; dL *= dL;
	    dU = pCmap->U - Utab[ix]; dU *= dU;
	    dV = pCmap->V - Vtab[ix]; dV *= dV;
	    dE = dL * Lscale + dU + dV;
	    dE = WEIGHT_DIST(dE, pCmap->L);
	} else {
	    dL = pCmap->dL;
	    dE = pCmap->dE;
	}

	if (dL > max_dL) max_dL = dL;
	t = UNWEIGHT_DIST(dE,dL) - dL*(Lscale-1);
	if (t > max_dE) max_dE = t;

	ave_dL += (dL > 0) ? sqrt(dL) : 0.0;
	ave_dE += (t > 0) ? sqrt(t) : 0.0;
    }

    jio_fprintf(stderr, "colors=%d, tablesize=%d, cubesize=%d, ",
	    cmapsize, tablesize, lookupsize);
    jio_fprintf(stderr, "Lscale=%5.3f, Weight=%5.3f mac=%s\n",
	    (double)lscale, (double)weight, doMac ? "true" : "false");
    jio_fprintf(stderr, "Worst case error dL = %5.3f, dE = %5.3f\n", 
	    sqrt(max_dL), sqrt(max_dE));
    jio_fprintf(stderr, "Average error dL = %5.3f, dE = %5.3f\n", 
	    ave_dL / num_virt_cmap_entries,  ave_dE / num_virt_cmap_entries);
#endif /* STATS */
#ifdef TIMES
    jio_fprintf(stderr, "%f seconds to find colors\n",
	    (double)(mid - start) / CLOCKS_PER_SEC);
    jio_fprintf(stderr, "%f seconds to finish nearest colors\n",
	    (double)(tbl - mid) / CLOCKS_PER_SEC);
    jio_fprintf(stderr, "%f seconds to make lookup table\n",
	    (double)(end - tbl) / CLOCKS_PER_SEC);
    jio_fprintf(stderr, "%f seconds total\n",
	    (double)(end - start) / CLOCKS_PER_SEC);
#endif /* TIMES */

    free(virt_cmap);
    virt_cmap = 0;
}
Esempio n. 20
0
/*
 * Looks up the mapping table (tzmappings) and returns a Java time
 * zone ID (e.g., "America/Los_Angeles") if found. Otherwise, NULL is
 * returned.
 *
 * value_type is one of the following values:
 *      VALUE_KEY for exact key matching
 *      VALUE_MAPID for MapID and country-based mapping (this is
 *      required for the old Windows, such as NT 4.0 SP3).
 */
static char *matchJavaTZ(const char *java_home_dir, int value_type, char *tzName,
                         char *mapID, const char *country)
{
    int line;
    int IDmatched = 0;
    FILE *fp;
    char *javaTZName = NULL;
    char *items[TZ_NITEMS];
    char mapFileName[_MAX_PATH + 1];
    char lineBuffer[MAX_ZONE_CHAR * 4];
    char bestMatch[MAX_ZONE_CHAR];
    int noMapID = *mapID == '\0';       /* no mapID on Vista */

    bestMatch[0] = '\0';

    strcpy(mapFileName, java_home_dir);
    strcat(mapFileName, MAPPINGS_FILE);

    if ((fp = fopen(mapFileName, "r")) == NULL) {
        jio_fprintf(stderr, "can't open %s.\n", mapFileName);
        return NULL;
    }

    line = 0;
    while (fgets(lineBuffer, sizeof(lineBuffer), fp) != NULL) {
        char *start, *idx, *endp;
        int itemIndex = 0;

        line++;
        start = idx = lineBuffer;
        endp = &lineBuffer[sizeof(lineBuffer)];

        /*
         * Ignore comment and blank lines.
         */
        if (*idx == '#' || *idx == '\n') {
            continue;
        }

        for (itemIndex = 0; itemIndex < TZ_NITEMS; itemIndex++) {
            items[itemIndex] = start;
            while (*idx && *idx != ':') {
                if (++idx >= endp) {
                    goto illegal_format;
                }
            }
            if (*idx == '\0') {
                goto illegal_format;
            }
            *idx++ = '\0';
            start = idx;
        }

        if (*idx != '\n') {
            goto illegal_format;
        }

        if (noMapID || strcmp(mapID, items[TZ_MAPID]) == 0) {
            /*
             * When there's no mapID, we need to scan items until the
             * exact match is found or the end of data is detected.
             */
            if (!noMapID) {
                IDmatched = 1;
            }
            if (strcmp(items[TZ_WIN_NAME], tzName) == 0) {
                /*
                 * Found the time zone in the mapping table.
                 */
                javaTZName = _strdup(items[TZ_JAVA_NAME]);
                break;
            }
            /*
             * Try to find the most likely time zone.
             */
            if (*items[TZ_REGION] == '\0') {
                strncpy(bestMatch, items[TZ_JAVA_NAME], MAX_ZONE_CHAR);
            } else if (country != NULL && strcmp(items[TZ_REGION], country) == 0) {
                if (value_type == VALUE_MAPID) {
                    javaTZName = _strdup(items[TZ_JAVA_NAME]);
                    break;
                }
                strncpy(bestMatch, items[TZ_JAVA_NAME], MAX_ZONE_CHAR);
            }
        } else {
            if (IDmatched == 1) {
                /*
                 * No need to look up the mapping table further.
                 */
                break;
            }
        }
    }
    fclose(fp);

    if (javaTZName == NULL && bestMatch[0] != '\0') {
        javaTZName = _strdup(bestMatch);
    }
    return javaTZName;

 illegal_format:
    (void) fclose(fp);
    jio_fprintf(stderr, "tzmappings: Illegal format at line %d.\n", line);
    return NULL;
}
Esempio n. 21
0
/*
 * Reads zip file central directory. Returns the file position of first
 * CEN header, otherwise returns -1 if an error occured. If zip->msg != NULL
 * then the error was a zip format error and zip->msg has the error text.
 * Always pass in -1 for knownTotal; it's used for a recursive call.
 */
static jlong
readCEN(jzfile *zip, jint knownTotal)
{
    /* Following are unsigned 32-bit */
    jlong endpos, end64pos, cenpos, cenlen, cenoff;
    /* Following are unsigned 16-bit */
    jint total, tablelen, i, j;
    unsigned char *cenbuf = NULL;
    unsigned char *cenend;
    unsigned char *cp;
#ifdef USE_MMAP
    static jlong pagesize;
    jlong offset;
#endif
    unsigned char endbuf[ENDHDR];
    jint endhdrlen = ENDHDR;
    jzcell *entries;
    jint *table;

    /* Clear previous zip error */
    zip->msg = NULL;
    /* Get position of END header */
    if ((endpos = findEND(zip, endbuf)) == -1)
        return -1; /* no END header or system error */

    if (endpos == 0) return 0;  /* only END header present */

    freeCEN(zip);
   /* Get position and length of central directory */
    cenlen = ENDSIZ(endbuf);
    cenoff = ENDOFF(endbuf);
    total  = ENDTOT(endbuf);
    if (cenlen == ZIP64_MAGICVAL || cenoff == ZIP64_MAGICVAL ||
        total == ZIP64_MAGICCOUNT) {
        unsigned char end64buf[ZIP64_ENDHDR];
        if ((end64pos = findEND64(zip, end64buf, endpos)) != -1) {
            cenlen = ZIP64_ENDSIZ(end64buf);
            cenoff = ZIP64_ENDOFF(end64buf);
            total = (jint)ZIP64_ENDTOT(end64buf);
            endpos = end64pos;
            endhdrlen = ZIP64_ENDHDR;
        }
    }

    if (cenlen > endpos)
        ZIP_FORMAT_ERROR("invalid END header (bad central directory size)");
    cenpos = endpos - cenlen;

    /* Get position of first local file (LOC) header, taking into
     * account that there may be a stub prefixed to the zip file. */
    zip->locpos = cenpos - cenoff;
    if (zip->locpos < 0)
        ZIP_FORMAT_ERROR("invalid END header (bad central directory offset)");

#ifdef USE_MMAP
    if (zip->usemmap) {
      /* On Solaris & Linux prior to JDK 6, we used to mmap the whole jar file to
       * read the jar file contents. However, this greatly increased the perceived
       * footprint numbers because the mmap'ed pages were adding into the totals shown
       * by 'ps' and 'top'. We switched to mmaping only the central directory of jar
       * file while calling 'read' to read the rest of jar file. Here are a list of
       * reasons apart from above of why we are doing so:
       * 1. Greatly reduces mmap overhead after startup complete;
       * 2. Avoids dual path code maintainance;
       * 3. Greatly reduces risk of address space (not virtual memory) exhaustion.
       */
        if (pagesize == 0) {
            pagesize = (jlong)sysconf(_SC_PAGESIZE);
            if (pagesize == 0) goto Catch;
        }
        if (cenpos > pagesize) {
            offset = cenpos & ~(pagesize - 1);
        } else {
            offset = 0;
        }
        /* When we are not calling recursively, knownTotal is -1. */
        if (knownTotal == -1) {
            void* mappedAddr;
            /* Mmap the CEN and END part only. We have to figure
               out the page size in order to make offset to be multiples of
               page size.
            */
            zip->mlen = cenpos - offset + cenlen + endhdrlen;
            zip->offset = offset;
            mappedAddr = mmap64(0, zip->mlen, PROT_READ, MAP_SHARED, zip->zfd, (off64_t) offset);
            zip->maddr = (mappedAddr == (void*) MAP_FAILED) ? NULL :
                (unsigned char*)mappedAddr;

            if (zip->maddr == NULL) {
                jio_fprintf(stderr, "mmap failed for CEN and END part of zip file\n");
                goto Catch;
            }
        }
        cenbuf = zip->maddr + cenpos - offset;
    } else
#endif
    {
        if ((cenbuf = malloc((size_t) cenlen)) == NULL ||
            (readFullyAt(zip->zfd, cenbuf, cenlen, cenpos) == -1))
        goto Catch;
    }

    cenend = cenbuf + cenlen;

    /* Initialize zip file data structures based on the total number
     * of central directory entries as stored in ENDTOT.  Since this
     * is a 2-byte field, but we (and other zip implementations)
     * support approx. 2**31 entries, we do not trust ENDTOT, but
     * treat it only as a strong hint.  When we call ourselves
     * recursively, knownTotal will have the "true" value.
     *
     * Keep this path alive even with the Zip64 END support added, just
     * for zip files that have more than 0xffff entries but don't have
     * the Zip64 enabled.
     */
    total = (knownTotal != -1) ? knownTotal : total;
    entries  = zip->entries  = calloc(total, sizeof(entries[0]));
    tablelen = zip->tablelen = ((total/2) | 1); // Odd -> fewer collisions
    table    = zip->table    = malloc(tablelen * sizeof(table[0]));
    if (entries == NULL || table == NULL) goto Catch;
    for (j = 0; j < tablelen; j++)
        table[j] = ZIP_ENDCHAIN;

    /* Iterate through the entries in the central directory */
    for (i = 0, cp = cenbuf; cp <= cenend - CENHDR; i++, cp += CENSIZE(cp)) {
        /* Following are unsigned 16-bit */
        jint method, nlen;
        unsigned int hsh;

        if (i >= total) {
            /* This will only happen if the zip file has an incorrect
             * ENDTOT field, which usually means it contains more than
             * 65535 entries. */
            cenpos = readCEN(zip, countCENHeaders(cenbuf, cenend));
            goto Finally;
        }

        method = CENHOW(cp);
        nlen   = CENNAM(cp);

        if (GETSIG(cp) != CENSIG)
            ZIP_FORMAT_ERROR("invalid CEN header (bad signature)");
        if (CENFLG(cp) & 1)
            ZIP_FORMAT_ERROR("invalid CEN header (encrypted entry)");
        if (method != STORED && method != DEFLATED)
            ZIP_FORMAT_ERROR("invalid CEN header (bad compression method)");
        if (cp + CENHDR + nlen > cenend)
            ZIP_FORMAT_ERROR("invalid CEN header (bad header size)");

        /* if the entry is metadata add it to our metadata names */
        if (isMetaName((char *)cp+CENHDR, nlen))
            if (addMetaName(zip, (char *)cp+CENHDR, nlen) != 0)
                goto Catch;

        /* Record the CEN offset and the name hash in our hash cell. */
        entries[i].cenpos = cenpos + (cp - cenbuf);
        entries[i].hash = hashN((char *)cp+CENHDR, nlen);

        /* Add the entry to the hash table */
        hsh = entries[i].hash % tablelen;
        entries[i].next = table[hsh];
        table[hsh] = i;
    }
    if (cp != cenend)
        ZIP_FORMAT_ERROR("invalid CEN header (bad header size)");

    zip->total = i;
    goto Finally;

 Catch:
    freeCEN(zip);
    cenpos = -1;

 Finally:
#ifdef USE_MMAP
    if (!zip->usemmap)
#endif
        free(cenbuf);

    return cenpos;
}
Esempio n. 22
0
static void
init_virt_cmap(int tablesize, int testsize)
{
    int r, g, b;
    int gray = -1;
    CmapEntry *pCmap;
    unsigned int dotest[256];

    if (virt_cmap) {
	free(virt_cmap);
	virt_cmap = 0;
    }

    num_virt_cmap_entries = tablesize * tablesize * tablesize;
    virt_cmap = malloc(sizeof(CmapEntry) * num_virt_cmap_entries);
    /*
     * Fix for bug 4070647 malloc return value not check in img_colors.c
     * We have to handle the malloc failure differently under
     * Win32 and Solaris since under Solaris this file is linked with
     * libawt.so and under Win32 it's a separate awt_makecube.exe
     * application.
     */
    if (virt_cmap == NULL) {
#ifndef MAKECUBE_EXE
        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
        JNU_ThrowOutOfMemoryError(env, "init_virt_cmap: OutOfMemoryError");
        return;
#else
        fprintf(stderr,"init_virt_cmap: OutOfMemoryError\n");
        exit(-1);
#endif
    }
    pCmap = virt_cmap;
    for (r = 0; r < total; r++) {
	if (cmap_r[r] == cmap_g[r] && cmap_g[r] == cmap_b[r]) {
	    if (gray < 0 || cmap_r[gray] < cmap_r[r]) {
		gray = r;
	    }
	}
    }
    if (gray < 0) {
#ifdef DEBUG
	jio_fprintf(stderr, "Didn't find any grays in color table!\n");
#endif /* DEBUG */
	gray = 0;
    }
    g = 0;
    b = 0;
    for (r = 0; r < tablesize - 1; ++r) {
	if (g >= 0) {
	    b = r;
	    dotest[r] = 1;
	    g -= tablesize;
	} else {
	    dotest[r] = 0;
	}
	prevtest[r] = b;
	g += testsize;
    }
    b = r;
    prevtest[r] = b;
    dotest[r] = 1;
    for (r = tablesize - 1; r >= 0; --r) {
	if (prevtest[r] == r) {
	    b = r;
	}
	nexttest[r] = b;
    }
#ifdef DEBUG
    for (r = 0; r < tablesize; ++r) {
	if (dotest[r]) {
	    if (prevtest[r] != r || nexttest[r] != r) {
		jio_fprintf(stderr, "prev/next != r!\n");
	    }
	}
    }
#endif /* DEBUG */
    for (r = 0; r < tablesize; ++r)
    {
	int red = (int)(floor(r*255.0/(tablesize - 1)));
	for (g = 0; g < tablesize; ++g)
	{
	    int green = (int)(floor(g*255.0/(tablesize - 1)));
	    for (b = 0; b < tablesize; ++b)
	    {
		int blue = (int)(floor(b*255.0/(tablesize - 1)));
		float t, d;
		if (pCmap >= virt_cmap + num_virt_cmap_entries) {
#ifdef DEBUG
		    jio_fprintf(stderr, "OUT OF pCmap CONVERSION SPACE!\n");
#endif /* DEBUG */
		    continue;		/* Shouldn't happen */
		}
		pCmap->red = red;
		pCmap->green = green;
		pCmap->blue = blue;
		LUV_convert(red, green, blue, &pCmap->L, &pCmap->U, &pCmap->V);
		if ((red != green || green != blue) &&
		    (!dotest[r] || !dotest[g] || !dotest[b]))
		{
		    pCmap->nextidx = -1;
		    pCmap++;
		    continue;
		}
		pCmap->bestidx = gray;
		pCmap->nextidx = 0;
		t = Ltab[gray] - pCmap->L;
		d = t * t;
		if (red == green && green == blue) {
		    pCmap->dist = d;
		    d *= Lscale;
		} else {
		    d *= Lscale;
		    t = Utab[gray] - pCmap->U;
		    d += t * t;
		    t = Vtab[gray] - pCmap->V;
		    d += t * t;
		    pCmap->dist = d;
		}
		pCmap->dE = WEIGHT_DIST(d, pCmap->L);
		pCmap++;
	    }
	}
    }
#ifdef DEBUG
    if (pCmap < virt_cmap + num_virt_cmap_entries) {
	jio_fprintf(stderr, "Didn't fill pCmap conversion table!\n");
    }
#endif /* DEBUG */
}
/*
 * Performs libc implementation specific mapping and returns a zone ID
 * if found. Otherwise, NULL is returned.
 */
static char *
getPlatformTimeZoneID()
{
    struct stat statbuf;
    char *tz = NULL;
    FILE *fp;
    int fd;
    char *buf;
    size_t size;

    /*
     * First, try the ZONE entry in /etc/sysconfig/clock. However, the
     * ZONE entry is not set up after initial Red Hat Linux
     * installation. In case that /etc/localtime is set up without
     * using timeconfig, there might be inconsistency between
     * /etc/localtime and the ZONE entry. The inconsistency between
     * timeconfig and linuxconf is reported as a bug in the Red Hat
     * web page as of May 1, 2000.
     */
    if ((fp = fopen(sysconfig_clock_file, "r")) != NULL) {
	char line[256];

	while (fgets(line, sizeof(line), fp) != NULL) {
	    char *p = line;
	    char *s;

	    SKIP_SPACE(p);
	    if (*p != 'Z') {
		continue;
	    }
	    if (strncmp(p, "ZONE=\"", 6) == 0) {
		p += 6;
	    } else {
		/*
		 * In case we need to parse it token by token.
		 */
		if (strncmp(p, "ZONE", 4) != 0) {
		    continue;
		}
		p += 4;
		SKIP_SPACE(p);
		if (*p++ != '=') {
		    break;
		}
		SKIP_SPACE(p);
		if (*p++ != '"') {
		    break;
		}
	    }
	    for (s = p; *s && *s != '"'; s++)
		;
	    if (*s != '"') {
		/* this ZONE entry is broken. */
		break;
	    }
	    *s = '\0';
	    tz = strdup(p);
	    break;
	}
	(void) fclose(fp);
	if (tz != NULL) {
	    return tz;
	}
    }

    /*
     * Next, try /etc/localtime to find the zone ID.
     */
    if (lstat(defailt_zoneinfo_file, &statbuf) == -1) {
	return NULL;
    }

    /*
     * If it's a symlink, get the link name and its zone ID part. (The
     * older versions of timeconfig created a symlink as described in
     * the Red Hat man page. It was changed in 1999 to create a copy
     * of a zoneinfo file. It's no longer possible to get the zone ID
     * from /etc/localtime.)
     */
    if (S_ISLNK(statbuf.st_mode)) {
	char linkbuf[PATH_MAX+1];
	int len;

	if ((len = readlink(defailt_zoneinfo_file, linkbuf, sizeof(linkbuf)-1)) == -1) {
	    jio_fprintf(stderr, (const char *) "can't get a symlink of %s\n",
			defailt_zoneinfo_file);
	    return NULL;
	}
	linkbuf[len] = '\0';
	tz = getZoneName(linkbuf);
	if (tz != NULL) {
	    tz = strdup(tz);
	}
	return tz;
    }

    /*
     * If it's a regular file, we need to find out the same zoneinfo file
     * that has been copied as /etc/localtime.
     */
    size = (size_t) statbuf.st_size;
    buf = (char *) malloc(size);
    if (buf == NULL) {
	return NULL;
    }
    if ((fd = open(defailt_zoneinfo_file, O_RDONLY)) == -1) {
	free((void *) buf);
	return NULL;
    }

    if (read(fd, buf, size) != (ssize_t) size) {
	(void) close(fd);
	free((void *) buf);
	return NULL;
    }
    (void) close(fd);

    tz = findZoneinfoFile(buf, size, zoneinfo_dir);
    free((void *) buf);
    return tz;
}
Esempio n. 24
0
static int32_t
awtJNI_FontName(JNIEnv * env, jstring name, char **foundry, char **facename, char **encoding)
{
    char *cname = NULL;

    if (JNU_IsNull(env, name)) {
        return 0;
    }
    cname = (char *) JNU_GetStringPlatformChars(env, name, NULL);

    /* additional default font names */
    if (strcmp(cname, "serif") == 0) {
        *foundry = "adobe";
        *facename = "times";
        *encoding = isolatin1;
    } else if (strcmp(cname, "sansserif") == 0) {
        *foundry = "adobe";
        *facename = "helvetica";
        *encoding = isolatin1;
    } else if (strcmp(cname, "monospaced") == 0) {
        *foundry = "adobe";
        *facename = "courier";
        *encoding = isolatin1;
    } else if (strcmp(cname, "helvetica") == 0) {
        *foundry = "adobe";
        *facename = "helvetica";
        *encoding = isolatin1;
    } else if (strcmp(cname, "timesroman") == 0) {
        *foundry = "adobe";
        *facename = "times";
        *encoding = isolatin1;
    } else if (strcmp(cname, "courier") == 0) {
        *foundry = "adobe";
        *facename = "courier";
        *encoding = isolatin1;
    } else if (strcmp(cname, "dialog") == 0) {
        *foundry = "b&h";
        *facename = "lucida";
        *encoding = isolatin1;
    } else if (strcmp(cname, "dialoginput") == 0) {
        *foundry = "b&h";
        *facename = "lucidatypewriter";
        *encoding = isolatin1;
    } else if (strcmp(cname, "zapfdingbats") == 0) {
        *foundry = "itc";
        *facename = "zapfdingbats";
        *encoding = "*-*";
    } else {
#ifdef DEBUG
        jio_fprintf(stderr, "Unknown font: %s\n", cname);
#endif
        *foundry = defaultfoundry;
        *facename = defaultfontname;
        *encoding = isolatin1;
    }

    if (cname != NULL)
        JNU_ReleaseStringPlatformChars(env, name, (const char *) cname);

    return 1;
}