Patches for OpenVMS and conversions to nsQuickSort(). Thanks to Colin Blake and James Lewis Nance (resp)

This commit is contained in:
mcmullen%netscape.com 1999-06-03 18:15:53 +00:00
Родитель 12f1f2604a
Коммит 8e15accfb2
14 изменённых файлов: 135 добавлений и 991 удалений

Просмотреть файл

@ -39,10 +39,6 @@
#include <stat.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h> /* for SEEK_SET and SEEK_END on some platforms */
#endif
#include "prlog.h"
#include "prio.h"
#include "prdtoa.h"
@ -55,7 +51,7 @@
#include "nsZip.h"
#include "zlib.h"
#include "xp.h" /* for XP_STRDUP */
#include "xp_qsort.h"
#include "nsQuickSort.h"
#include "prmem.h"
#include "prerror.h"
@ -183,7 +179,7 @@ static void
ns_zip_errmsg(const char *msg)
{
#ifdef DEBUG
PRFileDesc* prfd = PR_GetSpecialFD(2);
PRFileDesc* prfd = PR_GetSpecialFD(PR_StandardError);
PR_Write(prfd, msg, strlen(msg));
#endif
}
@ -317,7 +313,7 @@ nsZipFindEnd(ns_zip_t *zip, char *endbuf)
PRUint32 len, off, mark;
/* Need to search backwards from end of file */
if ((len = PR_Seek(zip->fd, 0, SEEK_END)) == -1) {
if ((len = PR_Seek(zip->fd, 0, PR_SEEK_END)) == -1) {
#if !defined(XP_PC) || defined(_WIN32)
/*
* perror is not defined for win16
@ -342,7 +338,7 @@ nsZipFindEnd(ns_zip_t *zip, char *endbuf)
for (off = len; off > mark; ) {
long n = min(off - mark, INBUFSIZ);
memcpy(buf + n, buf, SIGSIZ);
if (PR_Seek(zip->fd, off -= n, SEEK_SET) == -1) {
if (PR_Seek(zip->fd, off -= n, PR_SEEK_SET) == -1) {
#if !defined(XP_PC) || defined(_WIN32)
/*
* perror is not defined for win16
@ -364,7 +360,7 @@ nsZipFindEnd(ns_zip_t *zip, char *endbuf)
if ((buf+n-bp) >= ENDHDRSIZ) {
memcpy(endbuf, bp, ENDHDRSIZ);
} else {
if (PR_Seek(zip->fd, endoff, SEEK_SET) == -1) {
if (PR_Seek(zip->fd, endoff, PR_SEEK_SET) == -1) {
#if !defined(XP_PC) || defined(_WIN32)
/*
* perror is not defined for win16
@ -380,7 +376,7 @@ nsZipFindEnd(ns_zip_t *zip, char *endbuf)
if (endoff + ENDHDRSIZ + ENDCOM(endbuf) != len) {
continue;
}
if (PR_Seek(zip->fd, endoff, SEEK_SET) == -1) {
if (PR_Seek(zip->fd, endoff, PR_SEEK_SET) == -1) {
#if !defined(XP_PC) || defined(_WIN32)
/*
* perror is not defined for win16
@ -420,6 +416,12 @@ ns_zip_direlcmp(const void *d1, const void *d2)
return strcmp(((direl_t *)d1)->fn, ((direl_t *)d2)->fn);
}
static int
ns_zip_direlcmp2(const void *d1, const void *d2, void *unused)
{
return strcmp(((direl_t *)d1)->fn, ((direl_t *)d2)->fn);
}
/*
* Initialize zip file reader, read in central directory and construct the
* lookup table for locating zip file members.
@ -476,7 +478,7 @@ ns_zip_initReader(ns_zip_t *zip)
return PR_FALSE;
}
/* Seek to first CEN header */
if (PR_Seek(zip->fd, zip->cenoff, SEEK_SET) == -1) {
if (PR_Seek(zip->fd, zip->cenoff, PR_SEEK_SET) == -1) {
#if !defined(XP_PC) || defined(_WIN32)
/*
* perror is not defined for win16
@ -550,7 +552,7 @@ ns_zip_initReader(ns_zip_t *zip)
/* Free temporary buffer */
PR_Free(cenbuf);
/* Sort directory elements by name */
XP_QSORT(zip->dir, (size_t) zip->nel, sizeof(direl_t), ns_zip_direlcmp);
NS_QuickSort(zip->dir, (size_t) zip->nel, sizeof(direl_t), ns_zip_direlcmp2, NULL);
return PR_TRUE;
}
@ -828,7 +830,7 @@ ns_zip_get(ns_zip_t *zip, const char *fn, void HUGEP *buf, PRInt32 len)
return PR_FALSE;
}
/* Seek to beginning of LOC header */
if (PR_Seek(zip->fd, dp->off, SEEK_SET) == -1) {
if (PR_Seek(zip->fd, dp->off, PR_SEEK_SET) == -1) {
#if !defined(XP_PC) || defined(_WIN32)
/*
* perror is not defined for win16
@ -864,7 +866,7 @@ ns_zip_get(ns_zip_t *zip, const char *fn, void HUGEP *buf, PRInt32 len)
return PR_FALSE;
}
/* Seek to file data */
if (PR_Seek(zip->fd, off, SEEK_SET) == -1) {
if (PR_Seek(zip->fd, off, PR_SEEK_SET) == -1) {
#if !defined(XP_PC) || defined(_WIN32)
/*
* perror is not defined for win16

Просмотреть файл

@ -39,6 +39,7 @@
#include <fstream.h>
#include <time.h>
#include "prmem.h"
#include "nsQuickSort.h"
#define CONTEXT_VECTOR_MAP "/vector.map"
#define CONTEXT_VECTOR_STAT "/vector.stat"
@ -47,7 +48,7 @@
// structure to store the vector statistic information
typedef struct vector_info {
PRInt32 references; // number of occurances counted
PRInt32 references; // number of occurrences counted
PRInt32 count; // number of tags in the vector
PRBool good_vector; // is this a valid vector?
eHTMLTags* vector; // and the vector
@ -221,7 +222,7 @@ PRBool CDTDDebug::DebugRecord(char * path, nsString& aURLRef, char * filename)
// get the file size, read in the file and parse it line at
// a time to check to see if we have already recorded this
// occurance
// occurrence
PRInt32 iSize = PR_Seek(recordFile,0,PR_SEEK_END);
if (iSize) {
@ -289,10 +290,10 @@ PRBool CDTDDebug::DebugRecord(char * path, nsString& aURLRef, char * filename)
/**
* compare function for quick sort. Compares references and
* sorts in decending order
* sorts in descending order
*/
static int compare( const void *arg1, const void *arg2 )
static int compare( const void *arg1, const void *arg2 , void *unused)
{
VectorInfo ** p1 = (VectorInfo**)arg1;
VectorInfo ** p2 = (VectorInfo**)arg2;
@ -359,7 +360,7 @@ void CDTDDebug::NoteVector(eHTMLTags aTags[],PRInt32 count, PRBool good_vector)
mVectorInfoArray,
(sizeof(VectorInfo*)*((mVectorCount/TABLE_SIZE)+1)*TABLE_SIZE));
if (mVectorCount) {
qsort((void*)mVectorInfoArray,(size_t)mVectorCount,sizeof(VectorInfo*),compare);
NS_QuickSort((void*)mVectorInfoArray,(size_t)mVectorCount,sizeof(VectorInfo*),compare, NULL);
}
}
}
@ -379,7 +380,7 @@ void CDTDDebug::MakeVectorString(char * vector_string, VectorInfo * pInfo)
* This debug routine dumps out the vector statistics to a text
* file in the verification directory and defaults to the name
* "vector.stat". It contains all parsed context vectors and there
* occurance count sorted in decending order.
* occurrence count sorted in descending order.
*
* @update jevering 6/11/98
* @param
@ -413,11 +414,11 @@ void CDTDDebug::DumpVectorRecord(void)
// oh what the heck, sort it again
if (mVectorCount) {
qsort((void*)mVectorInfoArray,(size_t)mVectorCount,sizeof(VectorInfo*),compare);
NS_QuickSort((void*)mVectorInfoArray,(size_t)mVectorCount,sizeof(VectorInfo*),compare, NULL);
}
// cute little header
sprintf(vector_string,"Context vector occurance results. Processed %d unique vectors.\r\n\r\n", mVectorCount);
sprintf(vector_string,"Context vector occurrence results. Processed %d unique vectors.\r\n\r\n", mVectorCount);
ps << vector_string;
ps << "Invalid context vector summary (see " CONTEXT_VECTOR_STAT ") for mapping.\r\n";

Просмотреть файл

@ -21,17 +21,12 @@
Includes dithering for B&W displays, but not dithering
for PseudoColor displays which can be found in dither.c.
$Id: color.cpp,v 3.9 1999-05-27 22:30:53 pnunn%netscape.com Exp $
$Id: color.cpp,v 3.10 1999-06-03 18:11:47 mcmullen%netscape.com Exp $
*/
#include "if.h"
#ifdef XP_MAC
#include "xpcompat.h"
#else
#include "xp_qsort.h"
#endif
#include "nsQuickSort.h"
#ifdef PROFILE
#pragma profile on
@ -584,9 +579,8 @@ ConvertRGBToRGB32(il_container *ic,
}
}
/* Sorting predicate for qsort() */
static int
compare_uint32(const void *a, const void *b)
/* Sorting predicate for NS_QuickSort() */
int compare_uint32(const void *a, const void *b, void *unused)
{
uint32 a1 = *(uint32*)a;
uint32 b1 = *(uint32*)b;
@ -621,7 +615,7 @@ unique_map_colors(NI_ColorMap *cmap)
}
/* Sort by color, so identical colors will be grouped together. */
XP_QSORT(ind, max_colors, sizeof(*ind), compare_uint32);
NS_QuickSort(ind, max_colors, sizeof(*ind), compare_uint32, NULL);
/* Look for adjacent colors with different values */
for (i = 0; i < max_colors-1; i++)

Просмотреть файл

@ -31,18 +31,18 @@
#ifndef STANDALONE
#include "nscore.h"
#include "prmem.h"
#include "prio.h"
#include "plstr.h"
#include "xp_regexp.h"
#define ZFILE_CREATE PR_WRONLY | PR_CREATE_FILE
#define READTYPE PRInt32
#include "nscore.h"
#include "prmem.h"
#include "prio.h"
#include "plstr.h"
#include "xp_regexp.h"
#define ZFILE_CREATE PR_WRONLY | PR_CREATE_FILE
#define READTYPE PRInt32
#else
#include "zipstub.h"
#undef NETSCAPE // undoes prtypes damage in zlib.h
#define ZFILE_CREATE "wb"
#define READTYPE PRUint32
#include "zipstub.h"
#undef NETSCAPE // undoes prtypes damage in zlib.h
#define ZFILE_CREATE "wb"
#define READTYPE PRUint32
#endif /* STANDALONE */
#include "zlib.h"

Просмотреть файл

@ -33,6 +33,15 @@
#define NEW_PREF_ARCH
#if defined(VMS)
/* Deal with case naming conflicts */
#define pref_CopyCharPref prefl_CopyCharPref
#define pref_GetBoolPref prefl_GetBoolPref
#define pref_GetCharPref prefl_GetCharPref
#define pref_GetIntPref prefl_GetIntPref
#define pref_LockPref prefl_LockPref
#endif /* VMS */
NSPR_BEGIN_EXTERN_C
/*

Просмотреть файл

@ -33,6 +33,7 @@
#include "nsFileLocations.h"
#include "nsFileStream.h"
#include "nsIProfile.h"
#include "nsQuickSort.h"
#include "plhash.h"
#include "prmem.h"
@ -45,8 +46,6 @@
#include "windows.h"
#endif /* _WIN32 */
#define XP_QSORT qsort
#define PREFS_HEADER_LINE_1 "// Mozilla User Preferences"
#define PREFS_HEADER_LINE_2 "// This is a generated file!"
@ -1180,7 +1179,7 @@ PR_IMPLEMENT(PrefResult) PREF_SavePrefFileSpecWith(
PR_HashTableEnumerateEntries(gHashTable, heSaveProc, valueArray);
/* Sort the preferences to make a readable file on disk */
XP_QSORT(valueArray, gHashTable->nentries, sizeof(char*), pref_CompareStrings);
NS_QuickSort(valueArray, gHashTable->nentries, sizeof(char*), pref_CompareStrings, NULL);
char** walker = valueArray;
for (PRUint32 valueIdx = 0; valueIdx < gHashTable->nentries; valueIdx++,walker++)
{

Просмотреть файл

@ -60,13 +60,7 @@
#include "prprf.h"
#include "xpassert.h"
#include "xp_str.h"
#define XP_QSORT qsort
#if defined(XP_MAC) && defined (__MWERKS__)
/* Can't get the xp people to fix warnings... */
#pragma require_prototypes off
#endif
#include "nsQuickSort.h"
typedef union
{
@ -79,34 +73,29 @@ typedef struct
{
PrefValue defaultPref;
PrefValue userPref;
uint8 flags;
PRUint8 flags;
} PrefNode;
/*-----------------------
** Hash table allocation
**----------------------*/
PR_IMPLEMENT(void *) pref_AllocTable(void *pool, size_t size)
PR_STATIC_CALLBACK(void*) pref_AllocTable(void *pool, size_t size)
{
return malloc(size);
}
PR_IMPLEMENT(void) pref_FreeTable(void *pool, void *item)
PR_STATIC_CALLBACK(void) pref_FreeTable(void *pool, void *item)
{
free(item); /* free items? */
}
PR_IMPLEMENT(PLHashEntry *) pref_AllocEntry(void *pool, const void *key)
PR_STATIC_CALLBACK(PLHashEntry*) pref_AllocEntry(void *pool, const void *key)
{
return malloc(sizeof(PLHashEntry));
}
/* if we're using gcc's -pedantic-errors, uint isn't defined */
#if defined(__STRICT_ANSI__) || !defined(HAVE_UINT)
typedef unsigned int uint;
#endif
PR_IMPLEMENT(void) pref_FreeEntry(void *pool, PLHashEntry *he, uint flag)
PR_STATIC_CALLBACK(void) pref_FreeEntry(void *pool, PLHashEntry *he, PRUint32 flag)
{
PrefNode *pref = (PrefNode *) he->value;
if (pref)
@ -126,18 +115,18 @@ PR_IMPLEMENT(void) pref_FreeEntry(void *pool, PLHashEntry *he, uint flag)
}
}
JSBool PR_CALLBACK pref_NativeDefaultPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeUserPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeLockPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeUnlockPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeSetConfig(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeGetPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeGetLDAPAttr(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeDefaultPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeUserPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeLockPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeUnlockPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeSetConfig(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeGetPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeGetLDAPAttr(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
/* LI_STUFF add nativelilocalpref */
JSBool PR_CALLBACK pref_NativeLILocalPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeLILocalPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
/* LI_STUFF add NativeLIUserPref - does both lilocal and user at once */
JSBool PR_CALLBACK pref_NativeLIUserPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeLIDefPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeLIUserPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeLIDefPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
/*----------------------------------------------------------------------------------------*/
#include "prefapi_private_data.h"
@ -749,7 +738,7 @@ PREF_SetBinaryPref(const char *pref_name, void * value, long size)
}
PR_IMPLEMENT(PrefResult)
PREF_SetColorPref(const char *pref_name, uint8 red, uint8 green, uint8 blue)
PREF_SetColorPref(const char *pref_name, PRUint8 red, PRUint8 green, PRUint8 blue)
{
char colstr[63];
PrefValue pref;
@ -759,9 +748,9 @@ PREF_SetColorPref(const char *pref_name, uint8 red, uint8 green, uint8 blue)
return pref_HashPref(pref_name, pref, PREF_STRING, PREF_SETUSER);
}
#define MYGetboolVal(rgb) ((uint8) ((rgb) >> 16))
#define MYGetGValue(rgb) ((uint8) (((uint16) (rgb)) >> 8))
#define MYGetRValue(rgb) ((uint8) (rgb))
#define MYGetboolVal(rgb) ((PRUint8) ((rgb) >> 16))
#define MYGetGValue(rgb) ((PRUint8) (((PRUint16) (rgb)) >> 8))
#define MYGetRValue(rgb) ((PRUint8) (rgb))
PR_IMPLEMENT(PrefResult)
PREF_SetColorPrefDWord(const char *pref_name, PRUint32 colorref)
@ -780,7 +769,7 @@ PREF_SetColorPrefDWord(const char *pref_name, PRUint32 colorref)
}
PR_IMPLEMENT(PrefResult)
PREF_SetRectPref(const char *pref_name, int16 left, int16 top, int16 right, int16 bottom)
PREF_SetRectPref(const char *pref_name, PRInt16 left, PRInt16 top, PRInt16 right, PRInt16 bottom)
{
char rectstr[63];
PrefValue pref;
@ -835,7 +824,7 @@ PREF_SetDefaultBinaryPref(const char *pref_name,void * value,long size)
}
PR_IMPLEMENT(PrefResult)
PREF_SetDefaultColorPref(const char *pref_name, uint8 red, uint8 green, uint8 blue)
PREF_SetDefaultColorPref(const char *pref_name, PRUint8 red, PRUint8 green, PRUint8 blue)
{
char colstr[63];
PR_snprintf( colstr, 63, "#%02X%02X%02X", red, green, blue);
@ -844,7 +833,7 @@ PREF_SetDefaultColorPref(const char *pref_name, uint8 red, uint8 green, uint8 bl
}
PR_IMPLEMENT(PrefResult)
PREF_SetDefaultRectPref(const char *pref_name, int16 left, int16 top, int16 right, int16 bottom)
PREF_SetDefaultRectPref(const char *pref_name, PRInt16 left, PRInt16 top, PRInt16 right, PRInt16 bottom)
{
char rectstr[63];
PR_snprintf( rectstr, 63, "%d,%d,%d,%d", left, top, right, bottom);
@ -991,7 +980,7 @@ pref_savePref(PLHashEntry *he, int i, void *arg)
}
PR_IMPLEMENT(int)
pref_CompareStrings(const void *v1, const void *v2)
pref_CompareStrings(const void *v1, const void *v2, void *unused)
{
char *s1 = *(char**) v1;
char *s2 = *(char**) v2;
@ -1074,7 +1063,7 @@ PREF_SavePrefFileWith(const char *filename, PLHashEnumerator heSaveProc)
PR_HashTableEnumerateEntries(gHashTable, heSaveProc, valueArray);
/* Sort the preferences to make a readable file on disk */
XP_QSORT(valueArray, gHashTable->nentries, sizeof(char*), pref_CompareStrings);
NS_QuickSort(valueArray, gHashTable->nentries, sizeof(char*), pref_CompareStrings, NULL);
for (valueIdx = 0; valueIdx < gHashTable->nentries; valueIdx++)
{
if (valueArray[valueIdx])
@ -1337,7 +1326,7 @@ PREF_GetBoolPref(const char *pref_name, PRBool * return_value)
}
PR_IMPLEMENT(PrefResult)
PREF_GetColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8 *blue)
PREF_GetColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue)
{
char colstr[8];
int iSize = 8;
@ -1347,7 +1336,7 @@ PREF_GetColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8 *blue)
if (result == PREF_NOERROR)
{
int r, g, b;
sscanf(colstr, "#%02X%02X%02X", &r, &g, &b);
sscanf(colstr, "#%02x%02x%02x", &r, &g, &b);
*red = r;
*green = g;
*blue = b;
@ -1355,12 +1344,12 @@ PREF_GetColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8 *blue)
return result;
}
#define MYRGB(r, g ,b) ((PRUint32) (((uint8) (r) | ((uint16) (g) << 8)) | (((PRUint32) (uint8) (b)) << 16)))
#define MYRGB(r, g ,b) ((PRUint32) (((PRUint8) (r) | ((PRUint16) (g) << 8)) | (((PRUint32) (PRUint8) (b)) << 16)))
PR_IMPLEMENT(PrefResult)
PREF_GetColorPrefDWord(const char *pref_name, PRUint32 *colorref)
{
uint8 red, green, blue;
PRUint8 red, green, blue;
PrefResult result;
PR_ASSERT(colorref);
result = PREF_GetColorPref(pref_name, &red, &green, &blue);
@ -1370,7 +1359,7 @@ PREF_GetColorPrefDWord(const char *pref_name, PRUint32 *colorref)
}
PR_IMPLEMENT(PrefResult)
PREF_GetRectPref(const char *pref_name, int16 *left, int16 *top, int16 *right, int16 *bottom)
PREF_GetRectPref(const char *pref_name, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom)
{
char rectstr[64];
int iSize=64;
@ -1504,7 +1493,7 @@ PREF_GetDefaultBinaryPref(const char *pref_name, void * return_value, int * leng
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8 *blue)
PREF_GetDefaultColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue)
{
char colstr[8];
int iSize = 8;
@ -1514,7 +1503,7 @@ PREF_GetDefaultColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8
if (result == PREF_NOERROR)
{
int r, g, b;
sscanf(colstr, "#%02X%02X%02X", &r, &g, &b);
sscanf(colstr, "#%02x%02x%02x", &r, &g, &b);
*red = r;
*green = g;
*blue = b;
@ -1526,7 +1515,7 @@ PREF_GetDefaultColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultColorPrefDWord(const char *pref_name, PRUint32 * colorref)
{
uint8 red, green, blue;
PRUint8 red, green, blue;
PrefResult result;
PR_ASSERT(colorref);
result = PREF_GetDefaultColorPref(pref_name, &red, &green, &blue);
@ -1536,7 +1525,7 @@ PREF_GetDefaultColorPrefDWord(const char *pref_name, PRUint32 * colorref)
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultRectPref(const char *pref_name, int16 *left, int16 *top, int16 *right, int16 *bottom)
PREF_GetDefaultRectPref(const char *pref_name, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom)
{
char rectstr[256];
int iLen = 256;

Просмотреть файл

@ -60,13 +60,7 @@
#include "prprf.h"
#include "xpassert.h"
#include "xp_str.h"
#define XP_QSORT qsort
#if defined(XP_MAC) && defined (__MWERKS__)
/* Can't get the xp people to fix warnings... */
#pragma require_prototypes off
#endif
#include "nsQuickSort.h"
typedef union
{
@ -79,34 +73,29 @@ typedef struct
{
PrefValue defaultPref;
PrefValue userPref;
uint8 flags;
PRUint8 flags;
} PrefNode;
/*-----------------------
** Hash table allocation
**----------------------*/
PR_IMPLEMENT(void *) pref_AllocTable(void *pool, size_t size)
PR_STATIC_CALLBACK(void*) pref_AllocTable(void *pool, size_t size)
{
return malloc(size);
}
PR_IMPLEMENT(void) pref_FreeTable(void *pool, void *item)
PR_STATIC_CALLBACK(void) pref_FreeTable(void *pool, void *item)
{
free(item); /* free items? */
}
PR_IMPLEMENT(PLHashEntry *) pref_AllocEntry(void *pool, const void *key)
PR_STATIC_CALLBACK(PLHashEntry*) pref_AllocEntry(void *pool, const void *key)
{
return malloc(sizeof(PLHashEntry));
}
/* if we're using gcc's -pedantic-errors, uint isn't defined */
#if defined(__STRICT_ANSI__) || !defined(HAVE_UINT)
typedef unsigned int uint;
#endif
PR_IMPLEMENT(void) pref_FreeEntry(void *pool, PLHashEntry *he, uint flag)
PR_STATIC_CALLBACK(void) pref_FreeEntry(void *pool, PLHashEntry *he, PRUint32 flag)
{
PrefNode *pref = (PrefNode *) he->value;
if (pref)
@ -126,18 +115,18 @@ PR_IMPLEMENT(void) pref_FreeEntry(void *pool, PLHashEntry *he, uint flag)
}
}
JSBool PR_CALLBACK pref_NativeDefaultPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeUserPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeLockPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeUnlockPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeSetConfig(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeGetPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeGetLDAPAttr(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeDefaultPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeUserPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeLockPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeUnlockPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeSetConfig(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeGetPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeGetLDAPAttr(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
/* LI_STUFF add nativelilocalpref */
JSBool PR_CALLBACK pref_NativeLILocalPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeLILocalPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
/* LI_STUFF add NativeLIUserPref - does both lilocal and user at once */
JSBool PR_CALLBACK pref_NativeLIUserPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
JSBool PR_CALLBACK pref_NativeLIDefPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeLIUserPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
PR_STATIC_CALLBACK(JSBool) pref_NativeLIDefPref(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval);
/*----------------------------------------------------------------------------------------*/
#include "prefapi_private_data.h"
@ -749,7 +738,7 @@ PREF_SetBinaryPref(const char *pref_name, void * value, long size)
}
PR_IMPLEMENT(PrefResult)
PREF_SetColorPref(const char *pref_name, uint8 red, uint8 green, uint8 blue)
PREF_SetColorPref(const char *pref_name, PRUint8 red, PRUint8 green, PRUint8 blue)
{
char colstr[63];
PrefValue pref;
@ -759,9 +748,9 @@ PREF_SetColorPref(const char *pref_name, uint8 red, uint8 green, uint8 blue)
return pref_HashPref(pref_name, pref, PREF_STRING, PREF_SETUSER);
}
#define MYGetboolVal(rgb) ((uint8) ((rgb) >> 16))
#define MYGetGValue(rgb) ((uint8) (((uint16) (rgb)) >> 8))
#define MYGetRValue(rgb) ((uint8) (rgb))
#define MYGetboolVal(rgb) ((PRUint8) ((rgb) >> 16))
#define MYGetGValue(rgb) ((PRUint8) (((PRUint16) (rgb)) >> 8))
#define MYGetRValue(rgb) ((PRUint8) (rgb))
PR_IMPLEMENT(PrefResult)
PREF_SetColorPrefDWord(const char *pref_name, PRUint32 colorref)
@ -780,7 +769,7 @@ PREF_SetColorPrefDWord(const char *pref_name, PRUint32 colorref)
}
PR_IMPLEMENT(PrefResult)
PREF_SetRectPref(const char *pref_name, int16 left, int16 top, int16 right, int16 bottom)
PREF_SetRectPref(const char *pref_name, PRInt16 left, PRInt16 top, PRInt16 right, PRInt16 bottom)
{
char rectstr[63];
PrefValue pref;
@ -835,7 +824,7 @@ PREF_SetDefaultBinaryPref(const char *pref_name,void * value,long size)
}
PR_IMPLEMENT(PrefResult)
PREF_SetDefaultColorPref(const char *pref_name, uint8 red, uint8 green, uint8 blue)
PREF_SetDefaultColorPref(const char *pref_name, PRUint8 red, PRUint8 green, PRUint8 blue)
{
char colstr[63];
PR_snprintf( colstr, 63, "#%02X%02X%02X", red, green, blue);
@ -844,7 +833,7 @@ PREF_SetDefaultColorPref(const char *pref_name, uint8 red, uint8 green, uint8 bl
}
PR_IMPLEMENT(PrefResult)
PREF_SetDefaultRectPref(const char *pref_name, int16 left, int16 top, int16 right, int16 bottom)
PREF_SetDefaultRectPref(const char *pref_name, PRInt16 left, PRInt16 top, PRInt16 right, PRInt16 bottom)
{
char rectstr[63];
PR_snprintf( rectstr, 63, "%d,%d,%d,%d", left, top, right, bottom);
@ -991,7 +980,7 @@ pref_savePref(PLHashEntry *he, int i, void *arg)
}
PR_IMPLEMENT(int)
pref_CompareStrings(const void *v1, const void *v2)
pref_CompareStrings(const void *v1, const void *v2, void *unused)
{
char *s1 = *(char**) v1;
char *s2 = *(char**) v2;
@ -1074,7 +1063,7 @@ PREF_SavePrefFileWith(const char *filename, PLHashEnumerator heSaveProc)
PR_HashTableEnumerateEntries(gHashTable, heSaveProc, valueArray);
/* Sort the preferences to make a readable file on disk */
XP_QSORT(valueArray, gHashTable->nentries, sizeof(char*), pref_CompareStrings);
NS_QuickSort(valueArray, gHashTable->nentries, sizeof(char*), pref_CompareStrings, NULL);
for (valueIdx = 0; valueIdx < gHashTable->nentries; valueIdx++)
{
if (valueArray[valueIdx])
@ -1337,7 +1326,7 @@ PREF_GetBoolPref(const char *pref_name, PRBool * return_value)
}
PR_IMPLEMENT(PrefResult)
PREF_GetColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8 *blue)
PREF_GetColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue)
{
char colstr[8];
int iSize = 8;
@ -1347,7 +1336,7 @@ PREF_GetColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8 *blue)
if (result == PREF_NOERROR)
{
int r, g, b;
sscanf(colstr, "#%02X%02X%02X", &r, &g, &b);
sscanf(colstr, "#%02x%02x%02x", &r, &g, &b);
*red = r;
*green = g;
*blue = b;
@ -1355,12 +1344,12 @@ PREF_GetColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8 *blue)
return result;
}
#define MYRGB(r, g ,b) ((PRUint32) (((uint8) (r) | ((uint16) (g) << 8)) | (((PRUint32) (uint8) (b)) << 16)))
#define MYRGB(r, g ,b) ((PRUint32) (((PRUint8) (r) | ((PRUint16) (g) << 8)) | (((PRUint32) (PRUint8) (b)) << 16)))
PR_IMPLEMENT(PrefResult)
PREF_GetColorPrefDWord(const char *pref_name, PRUint32 *colorref)
{
uint8 red, green, blue;
PRUint8 red, green, blue;
PrefResult result;
PR_ASSERT(colorref);
result = PREF_GetColorPref(pref_name, &red, &green, &blue);
@ -1370,7 +1359,7 @@ PREF_GetColorPrefDWord(const char *pref_name, PRUint32 *colorref)
}
PR_IMPLEMENT(PrefResult)
PREF_GetRectPref(const char *pref_name, int16 *left, int16 *top, int16 *right, int16 *bottom)
PREF_GetRectPref(const char *pref_name, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom)
{
char rectstr[64];
int iSize=64;
@ -1504,7 +1493,7 @@ PREF_GetDefaultBinaryPref(const char *pref_name, void * return_value, int * leng
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8 *blue)
PREF_GetDefaultColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue)
{
char colstr[8];
int iSize = 8;
@ -1514,7 +1503,7 @@ PREF_GetDefaultColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8
if (result == PREF_NOERROR)
{
int r, g, b;
sscanf(colstr, "#%02X%02X%02X", &r, &g, &b);
sscanf(colstr, "#%02x%02x%02x", &r, &g, &b);
*red = r;
*green = g;
*blue = b;
@ -1526,7 +1515,7 @@ PREF_GetDefaultColorPref(const char *pref_name, uint8 *red, uint8 *green, uint8
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultColorPrefDWord(const char *pref_name, PRUint32 * colorref)
{
uint8 red, green, blue;
PRUint8 red, green, blue;
PrefResult result;
PR_ASSERT(colorref);
result = PREF_GetDefaultColorPref(pref_name, &red, &green, &blue);
@ -1536,7 +1525,7 @@ PREF_GetDefaultColorPrefDWord(const char *pref_name, PRUint32 * colorref)
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultRectPref(const char *pref_name, int16 *left, int16 *top, int16 *right, int16 *bottom)
PREF_GetDefaultRectPref(const char *pref_name, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom)
{
char rectstr[256];
int iLen = 256;

Просмотреть файл

@ -46,7 +46,7 @@ PR_EXTERN(PrefResult) pref_savePref(PLHashEntry *he, int i, void *arg);
PR_EXTERN(PrefResult) pref_saveLIPref(PLHashEntry *he, int i, void *arg);
PR_EXTERN(PRBool) pref_VerifyLockFile(char* buf, long buflen);
PR_EXTERN(PrefResult) PREF_SetSpecialPrefsLocal(void);
PR_EXTERN(int) pref_CompareStrings(const void *v1, const void *v2);
PR_EXTERN(int) pref_CompareStrings(const void *v1, const void *v2, void* unused);
extern JSBool pref_InitInitialObjects(void);
NSPR_END_EXTERN_C

Просмотреть файл

@ -92,7 +92,7 @@ MODULE_PRIVATE NET_FileEntryInfo * NET_CreateFileEntryInfoStruct (void)
*
*/
PRIVATE int
NET_CompareFileEntryInfoStructs (const void *ent2, const void *ent1)
NET_CompareFileEntryInfoStructs (const void *ent2, const void *ent1, void *unused)
{
int status;
const NET_FileEntryInfo *entry1 = *(NET_FileEntryInfo **) ent1;

Просмотреть файл

@ -17,7 +17,7 @@
*/
#include "mkutils.h"
#include "mksort.h"
#include "xp_qsort.h"
#include "nsQuickSort.h"
#define CHUNK_SIZE 400
@ -122,9 +122,9 @@ NET_SortInsert(SortStruct * sort_struct, void * insert_before, void * new_object
}
MODULE_PRIVATE void
NET_DoSort(SortStruct * sort_struct, int (*compar) (const void *, const void *))
NET_DoSort(SortStruct * sort_struct, int (*compar) (const void *, const void *, void *))
{
XP_QSORT(sort_struct->list, sort_struct->num_entries, sizeof(void *), compar);
NS_QuickSort(sort_struct->list, sort_struct->num_entries, sizeof(void *), compar, NULL);
}
/* unloads backwards :(

Просмотреть файл

@ -27,7 +27,7 @@ typedef struct _SortStruct {
extern SortStruct * NET_SortInit (void);
extern Bool NET_SortAdd (SortStruct * sort_struct, void * add_object);
extern void NET_DoSort(SortStruct * sort_struct, int (*compar) (const void *, const void *));
extern void NET_DoSort(SortStruct * sort_struct, int (*compar) (const void *, const void *, void *));
extern void * NET_SortUnloadNext(SortStruct * sort_struct);
extern void * NET_SortRetrieveNumber(SortStruct * sort_struct, int number);
extern int NET_SortCount(SortStruct * sort_struct);

Просмотреть файл

@ -39,6 +39,7 @@
#include <fstream.h>
#include <time.h>
#include "prmem.h"
#include "nsQuickSort.h"
#define CONTEXT_VECTOR_MAP "/vector.map"
#define CONTEXT_VECTOR_STAT "/vector.stat"
@ -47,7 +48,7 @@
// structure to store the vector statistic information
typedef struct vector_info {
PRInt32 references; // number of occurances counted
PRInt32 references; // number of occurrences counted
PRInt32 count; // number of tags in the vector
PRBool good_vector; // is this a valid vector?
eHTMLTags* vector; // and the vector
@ -221,7 +222,7 @@ PRBool CDTDDebug::DebugRecord(char * path, nsString& aURLRef, char * filename)
// get the file size, read in the file and parse it line at
// a time to check to see if we have already recorded this
// occurance
// occurrence
PRInt32 iSize = PR_Seek(recordFile,0,PR_SEEK_END);
if (iSize) {
@ -289,10 +290,10 @@ PRBool CDTDDebug::DebugRecord(char * path, nsString& aURLRef, char * filename)
/**
* compare function for quick sort. Compares references and
* sorts in decending order
* sorts in descending order
*/
static int compare( const void *arg1, const void *arg2 )
static int compare( const void *arg1, const void *arg2 , void *unused)
{
VectorInfo ** p1 = (VectorInfo**)arg1;
VectorInfo ** p2 = (VectorInfo**)arg2;
@ -359,7 +360,7 @@ void CDTDDebug::NoteVector(eHTMLTags aTags[],PRInt32 count, PRBool good_vector)
mVectorInfoArray,
(sizeof(VectorInfo*)*((mVectorCount/TABLE_SIZE)+1)*TABLE_SIZE));
if (mVectorCount) {
qsort((void*)mVectorInfoArray,(size_t)mVectorCount,sizeof(VectorInfo*),compare);
NS_QuickSort((void*)mVectorInfoArray,(size_t)mVectorCount,sizeof(VectorInfo*),compare, NULL);
}
}
}
@ -379,7 +380,7 @@ void CDTDDebug::MakeVectorString(char * vector_string, VectorInfo * pInfo)
* This debug routine dumps out the vector statistics to a text
* file in the verification directory and defaults to the name
* "vector.stat". It contains all parsed context vectors and there
* occurance count sorted in decending order.
* occurrence count sorted in descending order.
*
* @update jevering 6/11/98
* @param
@ -413,11 +414,11 @@ void CDTDDebug::DumpVectorRecord(void)
// oh what the heck, sort it again
if (mVectorCount) {
qsort((void*)mVectorInfoArray,(size_t)mVectorCount,sizeof(VectorInfo*),compare);
NS_QuickSort((void*)mVectorInfoArray,(size_t)mVectorCount,sizeof(VectorInfo*),compare, NULL);
}
// cute little header
sprintf(vector_string,"Context vector occurance results. Processed %d unique vectors.\r\n\r\n", mVectorCount);
sprintf(vector_string,"Context vector occurrence results. Processed %d unique vectors.\r\n\r\n", mVectorCount);
ps << vector_string;
ps << "Invalid context vector summary (see " CONTEXT_VECTOR_STAT ") for mapping.\r\n";

Просмотреть файл

@ -1,840 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsPrefsCore.h"
#include "nsIPref.h"
#include "nsIURL.h"
#include "nsIFileLocator.h"
#include "nsFileLocations.h"
#include "nsFileSpec.h"
#include "nsFileStream.h"
#include "nsIBrowserWindow.h"
#include "nsIWebShell.h"
#include "pratom.h"
#include "nsIComponentManager.h"
#include "nsAppCores.h"
#include "nsAppCoresCIDs.h"
#include "nsAppShellCIDs.h"
#include "nsAppCoresManager.h"
#include "nsIAppShellService.h"
#include "nsIServiceManager.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
#include "nsIDOMWindow.h"
#include "nsIWebShellWindow.h"
#include "nsIDOMHTMLInputElement.h"
#include "plstr.h"
#include "prprf.h"
#include "prmem.h"
#include <ctype.h>
// Globals - how many K are we wasting by putting these in every file?
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIPrefsCoreIID, NS_IDOMPREFSCORE_IID);
static NS_DEFINE_IID(kIDOMDocumentIID, nsIDOMDocument::GetIID());
static NS_DEFINE_IID(kIDocumentIID, nsIDocument::GetIID());
static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID);
static NS_DEFINE_IID(kPrefsCoreCID, NS_PREFSCORE_CID);
static NS_DEFINE_IID(kBrowserWindowCID, NS_BROWSER_WINDOW_CID);
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID);
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
#ifdef NS_DEBUG
static PRBool firstTime = PR_TRUE;
#endif
static void DOMWindowToWebShellWindow(nsIDOMWindow *DOMWindow, nsCOMPtr<nsIWebShellWindow> *webWindow);
//----------------------------------------------------------------------------------------
nsPrefsCore::nsPrefsCore()
//----------------------------------------------------------------------------------------
: mTreeScriptContext(nsnull)
, mPanelScriptContext(nsnull)
, mTreeWindow(nsnull)
, mPanelWindow(nsnull)
, mPrefs(nsnull)
, mSubStrings(nsnull)
{
printf("Created nsPrefsCore\n");
#ifdef NS_DEBUG
NS_ASSERTION(firstTime, "There can be only one");
firstTime = PR_FALSE;
#endif
// initialize substrings to null
mSubStrings = new char*[MAX_STRINGS+1];
int i;
for (i=0; i<MAX_STRINGS; i++) mSubStrings[i]=nsnull;
mSubStrings[MAX_STRINGS] = nsnull;
}
//----------------------------------------------------------------------------------------
nsPrefsCore::~nsPrefsCore()
//----------------------------------------------------------------------------------------
{
NS_IF_RELEASE(mTreeScriptContext);
NS_IF_RELEASE(mPanelScriptContext);
NS_IF_RELEASE(mTreeWindow);
NS_IF_RELEASE(mPanelWindow);
nsServiceManager::ReleaseService(kPrefCID, mPrefs);
if (mSubStrings) {
int i;
for (i=0; i< MAX_STRINGS; i++)
if (mSubStrings[i])
delete[] mSubStrings[i];
delete[] mSubStrings;
}
#ifdef NS_DEBUG
NS_ASSERTION(!firstTime, "There can be only one");
firstTime = PR_TRUE;
#endif
}
NS_IMPL_ISUPPORTS_INHERITED(nsPrefsCore, nsBaseAppCore, nsIDOMPrefsCore)
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsPrefsCore::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
//----------------------------------------------------------------------------------------
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject)
{
res = NS_NewScriptPrefsCore(aContext,
(nsISupports *)(nsIDOMPrefsCore*)this,
nsnull,
&mScriptObject);
}
*aScriptObject = mScriptObject;
return res;
}
//----------------------------------------------------------------------------------------
nsresult nsPrefsCore::InitializePrefsManager()
//----------------------------------------------------------------------------------------
{
nsIPref* prefs;
nsresult rv = nsServiceManager::GetService(kPrefCID, kIPrefIID, (nsISupports**)&prefs);
if (NS_FAILED(rv))
return rv;
if (!prefs)
return NS_ERROR_FAILURE;
#if 0
nsIFileLocator* locator;
rv = nsServiceManager::GetService(kFileLocatorCID, kIFileLocatorIID, (nsISupports**)&locator);
if (NS_FAILED(rv))
return rv;
if (!locator)
return NS_ERROR_FAILURE;
nsFileSpec newPrefs;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_PreferencesFile50, &newPrefs);
#if 0
// Migration?
if (NS_FAILED(rv) || !newPrefs.Exists())
{
nsFileSpec oldPrefs;
rv = locator->GetFileLocation(App_PreferencesFile40, &oldPrefs);
if (NS_FAILED(rv) || !oldPrefs.Exists())
{
rv = locator->GetFileLocation(App_PreferencesFile30, &oldPrefs);
}
if (NS_SUCCEEDED(rv) && oldPrefs.Exists())
{
nsFileSpec newParent;
rv = locator->GetFileLocation(App_PrefsDirectory50, &newParent);
if (NS_SUCCEEDED(rv))
{
oldPrefs.Copy(newParent);
const char* oldName = oldPrefs.GetLeafName();
newPrefs = newParent + oldName;
PL_strfree(oldName);
newPrefs.Rename("prefs.js");
}
}
}
#endif
nsServiceManager::ReleaseService(kFileLocatorCID, locator);
if (NS_SUCCEEDED(rv))
{
if (!newPrefs.Exists())
{
nsOutputFileStream stream(newPrefs);
if (stream.is_open())
{
stream << "// This is an empty prefs file" << nsEndl;
}
}
if (newPrefs.Exists())
rv = prefs->Startup(newPrefs.GetCString());
else
rv = NS_ERROR_FAILURE;
}
if (prefs && NS_FAILED(rv))
nsServiceManager::ReleaseService(kPrefCID, prefs);
if (NS_FAILED(rv))
return rv;
#endif // 0
mPrefs = prefs;
return NS_OK;
} // nsPrefsCore::InitializePrefsManager
//----------------------------------------------------------------------------------------
static PRBool CheckAndStrip(
nsString& ioString,
const char* inPrefix)
//----------------------------------------------------------------------------------------
{
if (ioString.Find(inPrefix) != 0)
return PR_FALSE;
ioString.Cut(0, PL_strlen(inPrefix));
return PR_TRUE;
}
//----------------------------------------------------------------------------------------
static PRInt16 CheckOrdinalAndStrip(nsString& ioString, PRInt16& outOrdinal)
//----------------------------------------------------------------------------------------
{
PRInt32 colonPos = ioString.Find(':');
if (colonPos <= 0)
return PR_FALSE;
char* intString = ioString.ToNewCString();
intString[colonPos] = 0;
if (!isdigit(*intString))
{
outOrdinal = 0;
return PR_TRUE;
}
ioString.Cut(0, colonPos + 1);
short result = 0;
sscanf(intString, "%hd", &result);
delete [] intString;
outOrdinal = result;
return PR_TRUE;
}
//----------------------------------------------------------------------------------------
static PRBool ParseElementIDString(
nsString& ioWidgetIDString,
nsPrefsCore::TypeOfPref& outType,
PRInt16& outOrdinal)
// If the id in the HTML is "pref:bool:general.startup.browser".
// outType will be set to eBool
// ioWidgetIDString will be modified to "general.startup.browser".
//----------------------------------------------------------------------------------------
{
if (!CheckAndStrip(ioWidgetIDString, "pref:"))
return PR_FALSE;
if (!CheckOrdinalAndStrip(ioWidgetIDString, outOrdinal))
return PR_FALSE;
if (CheckAndStrip(ioWidgetIDString, "bool:"))
{
outType = nsPrefsCore::eBool;
return PR_TRUE;
}
if (CheckAndStrip(ioWidgetIDString, "int:"))
{
outType = nsPrefsCore::eInt;
return PR_TRUE;
}
if (CheckAndStrip(ioWidgetIDString, "string:"))
{
outType = nsPrefsCore::eString;
return PR_TRUE;
}
if (CheckAndStrip(ioWidgetIDString, "path:"))
{
outType = nsPrefsCore::ePath;
return PR_TRUE;
}
return PR_FALSE;
} // ParseElementIDString
//----------------------------------------------------------------------------------------
nsresult nsPrefsCore::InitializeOneWidget(
nsIDOMHTMLInputElement* inElement,
const nsString& inWidgetType,
const char* inPrefName,
TypeOfPref inPrefType,
PRInt16 inPrefOrdinal)
//----------------------------------------------------------------------------------------
{
// See comments in FinalizeOneWidget for an explanation of the subtree technique. When
// initializing a widget, we have to check the subtree first, to see if the user has
// visited that panel previously and changed the value.
char tempPrefName[256];
PL_strcpy(tempPrefName, "temp_tree.");
PL_strcat(tempPrefName, inPrefName);
switch (inPrefType)
{
case eBool:
{
PRBool boolVal;
// Check the subtree first, then the real tree.
// If the preference value is not set at all, let the HTML
// determine the setting.
if (NS_SUCCEEDED(mPrefs->GetBoolPref(tempPrefName, &boolVal))
|| NS_SUCCEEDED(mPrefs->GetBoolPref(inPrefName, &boolVal)))
{
if (inWidgetType == "checkbox")
{
boolVal = (PRBool)(boolVal ^ inPrefOrdinal);
inElement->SetDefaultChecked(boolVal);
inElement->SetChecked(boolVal);
}
else if (inWidgetType == "radio" && inPrefOrdinal == boolVal)
{
// Radio pairs representing a boolean pref must have their
// ordinals "0" and "1". They work just like radio buttons
// representing int prefs.
// Turn on the radio whose ordinal matches the value.
// The others will turn off automatically.
inElement->SetDefaultChecked(PR_TRUE);
inElement->SetChecked(PR_TRUE);
}
}
break;
}
case eInt:
{
PRInt32 intVal;
// Check the subtree first, then the real tree.
// If the preference value is not set at all, let the HTML
// determine the setting.
if (NS_SUCCEEDED(mPrefs->GetIntPref(tempPrefName, &intVal))
|| NS_SUCCEEDED(mPrefs->GetIntPref(inPrefName, &intVal)))
{
if (inWidgetType == "radio")
{
// Turn on the radio whose ordinal matches the value.
// The others will turn off automatically.
if (inPrefOrdinal == intVal)
{
inElement->SetDefaultChecked(PR_TRUE);
inElement->SetChecked(PR_TRUE);
}
}
else if (inWidgetType == "text")
{
char charVal[32];
sprintf(charVal, "%d", (int)intVal);
nsString newValue(charVal);
inElement->SetValue(newValue);
}
}
break;
}
case eString:
{
// Check the subtree first, then the real tree.
// If the preference value is not set at all, let the HTML
// determine the setting.
char* charVal;
if (NS_SUCCEEDED(mPrefs->CopyCharPref(tempPrefName, &charVal))
|| NS_SUCCEEDED(mPrefs->CopyCharPref(inPrefName, &charVal)))
{
nsString newValue = charVal;
PR_Free(charVal);
inElement->SetValue(newValue);
}
break;
}
case ePath:
{
// Check the subtree first, then the real tree.
// If the preference value is not set at all, let the HTML
// determine the setting.
nsFileSpec *specVal;
nsresult rv = mPrefs->GetFilePref(tempPrefName, &specVal);
if (NS_FAILED(rv))
rv = mPrefs->GetFilePref(inPrefName, &specVal);
if NS_SUCCEEDED(rv) {
nsString newValue = specVal->GetCString();
inElement->SetValue(newValue);
delete specVal;
}
break;
}
}
return NS_OK;
} // nsPrefsCore::InitializeOneWidget
//----------------------------------------------------------------------------------------
nsresult nsPrefsCore::InitializeWidgetsRecursive(nsIDOMNode* inParentNode)
//----------------------------------------------------------------------------------------
{
if (!inParentNode)
return NS_OK;
PRBool hasChildren;
inParentNode->HasChildNodes(&hasChildren);
if (hasChildren)
{
//nsCOMPtr<nsIDOMNodeList> childList;
//inParentNode->GetChildNodes(getter_AddRefs(childList));
nsCOMPtr<nsIDOMNode> nextChild;
nsresult aResult = inParentNode->GetFirstChild(getter_AddRefs(nextChild));
while (NS_SUCCEEDED(aResult) && nextChild)
{
nsCOMPtr<nsIDOMNode> child = nextChild;
InitializeWidgetsRecursive(child);
aResult = child->GetNextSibling(getter_AddRefs(nextChild));
}
}
// OK, the buck stops here. Do the real work.
PRUint16 aNodeType;
nsresult rv = inParentNode->GetNodeType(&aNodeType);
if (NS_SUCCEEDED(rv) && aNodeType == nsIDOMNode::ELEMENT_NODE)
{
nsCOMPtr<nsIDOMHTMLInputElement> element = do_QueryInterface(inParentNode);
if (element)
{
nsString prefName;
TypeOfPref prefType;
PRInt16 ordinal;
element->GetId( prefName);
if (ParseElementIDString(prefName, prefType, ordinal))
{
nsString widgetType;
element->GetType(widgetType);
char* prefNameString = GetSubstitution(prefName);
InitializeOneWidget(element, widgetType, prefNameString,
prefType, ordinal);
PR_Free(prefNameString);
}
}
}
return NS_OK;
} // InitializeWidgetsRecursive
//----------------------------------------------------------------------------------------
nsresult nsPrefsCore::InitializePrefWidgets()
//----------------------------------------------------------------------------------------
{
NS_ASSERTION(mPanelWindow, "panel window is null");
NS_ASSERTION(mPrefs, "prefs pointer is null");
if (!mPanelWindow || !mPrefs)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMDocument> aDOMDoc;
mPanelWindow->GetDocument(getter_AddRefs(aDOMDoc));
return InitializeWidgetsRecursive(aDOMDoc);
} // nsPrefsCore::InitializePrefWidgets
//----------------------------------------------------------------------------------------
nsresult nsPrefsCore::FinalizeOneWidget(
nsIDOMHTMLInputElement* inElement,
const nsString& inWidgetType,
const char* inPrefName,
TypeOfPref inPrefType,
PRInt16 inPrefOrdinal)
//----------------------------------------------------------------------------------------
{
// As each panel is replaced, the values of its widgets are written out to a subtree
// of the prefs tree with root at "temp_tree". This subtree is rather sparse, since it
// only contains prefs (if any) that are represented by widgets in panels that the user
// visits. If the user clicks "OK" at the end, then prefs in this subtree will be
// copied back over to the real tree. This subtree will be deleted at the end
// in either case (OK or Cancel).
char tempPrefName[256];
PL_strcpy(tempPrefName, "temp_tree.");
PL_strcat(tempPrefName, inPrefName);
switch (inPrefType)
{
case eBool:
{
PRBool boolVal;
nsresult rv = inElement->GetChecked(&boolVal);
if (NS_FAILED(rv))
return rv;
if (inWidgetType == "checkbox")
{
boolVal = (PRBool)(boolVal ^ inPrefOrdinal);
mPrefs->SetBoolPref(tempPrefName, boolVal);
}
else if (inWidgetType == "radio" && boolVal)
{
// The radio that is ON writes out its ordinal. Others do nothing.
mPrefs->SetBoolPref(tempPrefName, inPrefOrdinal);
}
break;
}
case eInt:
{
if (inWidgetType == "radio")
{
// The radio that is ON writes out its ordinal. Others do nothing.
PRBool boolVal;
nsresult rv = inElement->GetChecked(&boolVal);
if (NS_FAILED(rv) || !boolVal)
return rv;
mPrefs->SetIntPref(tempPrefName, inPrefOrdinal);
}
else if (inWidgetType == "text")
{
nsString fieldValue;
nsresult rv = inElement->GetValue(fieldValue);
if (NS_FAILED(rv))
return rv;
char* s = fieldValue.ToNewCString();
mPrefs->SetIntPref(tempPrefName, atoi(s));
delete [] s;
}
break;
}
case eString:
{
nsString fieldValue;
nsresult rv = inElement->GetValue(fieldValue);
if (NS_FAILED(rv))
return rv;
char* s = fieldValue.ToNewCString();
mPrefs->SetCharPref(tempPrefName, s);
delete [] s;
break;
}
case ePath:
{
nsString fieldValue;
nsresult rv = inElement->GetValue(fieldValue);
if (NS_FAILED(rv))
return rv;
nsFileSpec specValue(fieldValue);
mPrefs->SetFilePref(tempPrefName, &specValue, PR_TRUE);
break;
}
}
// if (inWidgetType == "checkbox" || inWidgetType = "radio")
// {
// inElement->SetAttribute(attributeToSet, newValue);
// }
return NS_OK;
} // nsPrefsCore::FinalizeOneWidget
//----------------------------------------------------------------------------------------
nsresult nsPrefsCore::FinalizeWidgetsRecursive(nsIDOMNode* inParentNode)
//----------------------------------------------------------------------------------------
{
if (!inParentNode)
return NS_OK;
PRBool hasChildren;
inParentNode->HasChildNodes(&hasChildren);
if (hasChildren)
{
//nsCOMPtr<nsIDOMNodeList> childList;
//inParentNode->GetChildNodes(getter_AddRefs(childList));
nsCOMPtr<nsIDOMNode> nextChild;
nsresult aResult = inParentNode->GetFirstChild(getter_AddRefs(nextChild));
while (NS_SUCCEEDED(aResult) && nextChild)
{
nsCOMPtr<nsIDOMNode> child = nextChild;
FinalizeWidgetsRecursive(child);
aResult = child->GetNextSibling(getter_AddRefs(nextChild));
}
}
// OK, the buck stops here. Do the real work.
PRUint16 aNodeType;
nsresult rv = inParentNode->GetNodeType(&aNodeType);
if (NS_SUCCEEDED(rv) && aNodeType == nsIDOMNode::ELEMENT_NODE)
{
nsCOMPtr<nsIDOMHTMLInputElement> element = do_QueryInterface(inParentNode);
if (element)
{
nsString prefName;
TypeOfPref prefType;
PRInt16 ordinal;
element->GetId( prefName);
if (ParseElementIDString(prefName, prefType, ordinal))
{
nsString widgetType;
element->GetType(widgetType);
char* prefNameString = GetSubstitution(prefName);
FinalizeOneWidget(element, widgetType, prefNameString, prefType, ordinal);
delete [] prefNameString;
}
}
}
return NS_OK;
} // FinalizeWidgetsRecursive
//----------------------------------------------------------------------------------------
nsresult nsPrefsCore::FinalizePrefWidgets()
//----------------------------------------------------------------------------------------
{
NS_ASSERTION(mPanelWindow, "panel window is null");
NS_ASSERTION(mPrefs, "prefs pointer is null");
if (!mPanelWindow || !mPrefs)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMDocument> aDOMDoc;
mPanelWindow->GetDocument(getter_AddRefs(aDOMDoc));
return FinalizeWidgetsRecursive(aDOMDoc);
} // nsPrefsCore::FinalizePrefWidgets
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsPrefsCore::Init(const nsString& aId)
//----------------------------------------------------------------------------------------
{
nsresult rv = nsBaseAppCore::Init(aId);
if (NS_FAILED(rv))
return rv;
rv = InitializePrefsManager();
if (NS_FAILED(rv))
return rv;
return NS_OK;
} // nsPrefsCore::Init
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsPrefsCore::ShowWindow(nsIDOMWindow* aCurrentFrontWin)
//----------------------------------------------------------------------------------------
{
// (code adapted from nsToolkitCore::ShowModal. yeesh.)
nsresult rv;
nsIAppShellService *appShell;
nsIWebShellWindow *window;
window = nsnull;
nsCOMPtr<nsIURL> urlObj;
rv = NS_NewURL(getter_AddRefs(urlObj), "resource://res/samples/PrefsWindow.html");
if (NS_FAILED(rv))
return rv;
rv = nsServiceManager::GetService(kAppShellServiceCID, kIAppShellServiceIID,
(nsISupports**) &appShell);
if (NS_FAILED(rv))
return rv;
// Create "save to disk" nsIXULCallbacks...
//nsIXULWindowCallbacks *cb = new nsFindDialogCallbacks( aURL, aContentType );
nsIXULWindowCallbacks *cb = nsnull;
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(aCurrentFrontWin, &parent);
appShell->CreateDialogWindow(parent, urlObj, PR_TRUE, window,
nsnull, cb, 504, 436);
nsServiceManager::ReleaseService(kAppShellServiceCID, appShell);
if (window != nsnull) {
nsCOMPtr<nsIWidget> parentWindowWidgetThing;
nsresult gotParent;
gotParent = parent ? parent->GetWidget(*getter_AddRefs(parentWindowWidgetThing)) :
NS_ERROR_FAILURE;
// Windows OS is the only one that needs the parent disabled, or cares
// arguably this should be done by the new window, within ShowModal...
if (NS_SUCCEEDED(gotParent))
parentWindowWidgetThing->Enable(PR_FALSE);
window->ShowModal();
if (NS_SUCCEEDED(gotParent))
parentWindowWidgetThing->Enable(PR_TRUE);
}
return rv;
} // nsPrefsCore::ShowWindow
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsPrefsCore::ChangePanel(const nsString& aURL)
// Start loading of a new prefs panel.
//----------------------------------------------------------------------------------------
{
NS_ASSERTION(mPanelWindow, "panel window is null");
if (!mPanelWindow)
return NS_OK;
nsresult rv = FinalizePrefWidgets();
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIScriptGlobalObject> globalScript(do_QueryInterface(mPanelWindow));
if (!globalScript)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIWebShell> webshell;
globalScript->GetWebShell(getter_AddRefs(webshell));
if (!webshell)
return NS_ERROR_FAILURE;
webshell->LoadURL(aURL.GetUnicode());
return NS_OK;
}
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsPrefsCore::PanelLoaded(nsIDOMWindow* aWin)
// Callback after loading of a new prefs panel.
//----------------------------------------------------------------------------------------
{
// Out with the old!
if (mPanelWindow != aWin)
{
NS_IF_RELEASE(mPanelWindow);
mPanelWindow = aWin;
NS_IF_ADDREF(mPanelWindow);
}
// In with the new!
if (mPanelWindow)
{
mPanelScriptContext = GetScriptContext(mPanelWindow);
nsresult rv = InitializePrefWidgets();
if (NS_FAILED(rv))
return rv;
}
return NS_OK;
}
//----------------------------------------------------------------------------------------
static void DOMWindowToWebShellWindow(
nsIDOMWindow *DOMWindow,
nsCOMPtr<nsIWebShellWindow> *webWindow)
//----------------------------------------------------------------------------------------
{
if (!DOMWindow)
return; // with webWindow unchanged -- its constructor gives it a null ptr
nsCOMPtr<nsIScriptGlobalObject> globalScript(do_QueryInterface(DOMWindow));
nsCOMPtr<nsIWebShell> webshell, rootWebshell;
if (globalScript)
globalScript->GetWebShell(getter_AddRefs(webshell));
if (webshell)
webshell->GetRootWebShellEvenIfChrome(*getter_AddRefs(rootWebshell));
if (rootWebshell) {
nsCOMPtr<nsIWebShellContainer> webshellContainer;
rootWebshell->GetContainer(*getter_AddRefs(webshellContainer));
*webWindow = do_QueryInterface(webshellContainer);
}
}
//----------------------------------------------------------------------------------------
static nsresult Close(nsIDOMWindow*& dw)
//----------------------------------------------------------------------------------------
{
if (!dw)
return NS_ERROR_FAILURE;
nsIDOMWindow* top;
dw->GetTop(&top);
if (!top)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIWebShellWindow> parent;
DOMWindowToWebShellWindow(top, &parent);
if (parent)
parent->Close();
NS_IF_RELEASE(dw);
return NS_OK;
}
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsPrefsCore::SavePrefs()
//----------------------------------------------------------------------------------------
{
FinalizePrefWidgets();
if (mPrefs)
{
// Do the prefs stuff...
mPrefs->CopyPrefsTree("temp_tree", "");
mPrefs->DeleteBranch("temp_tree");
mPrefs->SavePrefFile();
}
// Then close
return Close(mPanelWindow);
}
char *
nsPrefsCore::GetSubstitution(nsString& formatstr)
{
char *cformatstr = formatstr.ToNewCString();
char *result;
// for now use PR_smprintf and hardcode the strings as parameters
#define substring(_i) mSubStrings[_i] ? mSubStrings[_i] : ""
result = PR_smprintf(cformatstr,
substring(0),
substring(1),
substring(2),
substring(3),
substring(4),
substring(5),
substring(6),
substring(7),
substring(8),
substring(9));
delete[] cformatstr;
return result;
}
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsPrefsCore::CancelPrefs()
//----------------------------------------------------------------------------------------
{
// Do the prefs stuff...
if (mPrefs)
mPrefs->DeleteBranch("temp_tree");
// Then close
return Close(mPanelWindow);
}
NS_IMETHODIMP
nsPrefsCore::SetSubstitutionVar(PRInt32 aStringnum,
const nsString& aVal)
{
if (aStringnum < MAX_STRINGS) {
NS_WARNING("substitution string number to large");
return NS_ERROR_UNEXPECTED;
}
if (mSubStrings[aStringnum]) delete[] mSubStrings[aStringnum];
mSubStrings[aStringnum] = aVal.ToNewCString();
return NS_OK;
}