PageRenderTime 34ms CodeModel.GetById 9ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/libreg/src/vr_stubs.c

http://github.com/zpao/v8monkey
C | 507 lines | 368 code | 77 blank | 62 comment | 89 complexity | dbfd596c7b1d37614d12d87d03e8d73f MD5 | raw file
  1/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2/* ***** BEGIN LICENSE BLOCK *****
  3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4 *
  5 * The contents of this file are subject to the Mozilla Public License Version
  6 * 1.1 (the "License"); you may not use this file except in compliance with
  7 * the License. You may obtain a copy of the License at
  8 * http://www.mozilla.org/MPL/
  9 *
 10 * Software distributed under the License is distributed on an "AS IS" basis,
 11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 12 * for the specific language governing rights and limitations under the
 13 * License.
 14 *
 15 * The Original Code is mozilla.org code.
 16 *
 17 * The Initial Developer of the Original Code is
 18 * Netscape Communications Corporation.
 19 * Portions created by the Initial Developer are Copyright (C) 1998
 20 * the Initial Developer. All Rights Reserved.
 21 *
 22 * Contributor(s):
 23 *
 24 * Alternatively, the contents of this file may be used under the terms of
 25 * either the GNU General Public License Version 2 or later (the "GPL"), or
 26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 27 * in which case the provisions of the GPL or the LGPL are applicable instead
 28 * of those above. If you wish to allow use of your version of this file only
 29 * under the terms of either the GPL or the LGPL, and not to allow others to
 30 * use your version of this file under the terms of the MPL, indicate your
 31 * decision by deleting the provisions above and replace them with the notice
 32 * and other provisions required by the GPL or the LGPL. If you do not delete
 33 * the provisions above, a recipient may use your version of this file under
 34 * the terms of any one of the MPL, the GPL or the LGPL.
 35 *
 36 * ***** END LICENSE BLOCK ***** */
 37
 38/* this file contains stubs needed to build the registry routines
 39 * into a stand-alone library for use with our installers
 40 */
 41
 42#ifdef STANDALONE_REGISTRY
 43
 44#include <stdlib.h>
 45#include <stdio.h>
 46#include <string.h>
 47
 48#else
 49
 50#include "prtypes.h"
 51#include "plstr.h"
 52
 53#endif /*STANDALONE_REGISTRY*/
 54
 55#include "vr_stubs.h"
 56
 57#ifdef XP_MACOSX
 58#include <Carbon/Carbon.h>
 59#include <stdlib.h>
 60#endif
 61
 62#ifdef XP_BEOS
 63#include <FindDirectory.h>
 64#endif 
 65
 66#ifdef XP_MACOSX
 67/* So that we're not dependent on the size of chars in a wide string literal */
 68static const UniChar kOSXRegParentName[] =
 69  { 'M', 'o', 'z', 'i', 'l', 'l', 'a' };
 70static const UniChar kOSXRegName[] =
 71  { 'G', 'l', 'o', 'b', 'a', 'l', '.', 'r', 'e', 'g', 's' };
 72static const UniChar kOSXVersRegName[] =
 73  { 'V', 'e', 'r', 's', 'i', 'o', 'n', 's', '.', 'r', 'e', 'g', 's' };
 74
 75#define UNICHAR_ARRAY_LEN(s) (sizeof(s) / sizeof(UniChar))
 76#endif
 77
 78#define DEF_REG "/.mozilla/registry"
 79#define WIN_REG "\\mozregistry.dat"
 80#define MAC_REG "\pMozilla Registry"
 81#define BEOS_REG "/mozilla/registry"
 82
 83#define DEF_VERREG "/.mozilla/mozver.dat"
 84#define WIN_VERREG "\\mozver.dat"
 85#define MAC_VERREG "\pMozilla Versions"
 86#define BEOS_VERREG "/mozilla/mozver.dat"
 87
 88
 89/* ------------------------------------------------------------------
 90 *  OS/2 STUBS
 91 * ------------------------------------------------------------------
 92 */
 93#ifdef XP_OS2
 94#define INCL_DOS
 95#include <os2.h>
 96
 97#ifdef STANDALONE_REGISTRY
 98extern XP_File vr_fileOpen (const char *name, const char * mode)
 99{
100    XP_File fh = NULL;
101    struct stat st;
102
103    if ( name != NULL ) {
104        if ( stat( name, &st ) == 0 )
105            fh = fopen( name, XP_FILE_UPDATE_BIN );
106        else
107            fh = fopen( name, XP_FILE_TRUNCATE_BIN );
108    }
109
110    return fh;
111}
112#endif /*STANDALONE_REGISTRY*/
113
114extern void vr_findGlobalRegName ()
115{
116    char    path[ CCHMAXPATH ];
117    int     pathlen;
118    XP_File fh = NULL;
119    struct stat st;
120
121    XP_STRCPY(path, ".");
122    pathlen = strlen(path);
123
124    if ( pathlen > 0 ) {
125        XP_STRCPY( path+pathlen, WIN_REG );
126        globalRegName = XP_STRDUP(path);
127    }
128}
129
130char* vr_findVerRegName()
131{
132    /* need to find a global place for the version registry */
133    if ( verRegName == NULL )
134    {
135        if ( globalRegName == NULL)
136            vr_findGlobalRegName();
137        verRegName = XP_STRDUP(globalRegName);
138    }
139
140    return verRegName;
141}
142
143#endif /* XP_OS2 */
144
145
146/* ------------------------------------------------------------------
147 *  WINDOWS STUBS
148 * ------------------------------------------------------------------
149 */
150#if defined(XP_WIN)
151#include "windows.h"
152#define PATHLEN 260
153
154#ifdef STANDALONE_REGISTRY
155extern XP_File vr_fileOpen (const char *name, const char * mode)
156{
157    XP_File fh = NULL;
158    struct stat st;
159
160    if ( name != NULL ) {
161        if ( stat( name, &st ) == 0 )
162            fh = fopen( name, XP_FILE_UPDATE_BIN );
163        else
164            fh = fopen( name, XP_FILE_TRUNCATE_BIN );
165    }
166
167    return fh;
168}
169#endif /*STANDALONE_REGISTRY*/
170
171extern void vr_findGlobalRegName ()
172{
173    char    path[ PATHLEN ];
174    int     pathlen;
175   
176    pathlen = GetWindowsDirectory(path, PATHLEN);
177    if ( pathlen > 0 ) {
178        XP_FREEIF(globalRegName);
179        XP_STRCPY( path+pathlen, WIN_REG );
180        globalRegName = XP_STRDUP(path);
181    }
182}
183
184char* vr_findVerRegName()
185{
186    char    path[ PATHLEN ];
187    int     pathlen;
188   
189    if ( verRegName == NULL )
190    {
191        pathlen = GetWindowsDirectory(path, PATHLEN);
192        if ( pathlen > 0 ) {
193            XP_STRCPY( path+pathlen, WIN_VERREG );
194            verRegName = XP_STRDUP(path);
195        }
196    }
197
198    return verRegName;
199}
200
201#if !defined(WIN32) && !defined(__BORLANDC__)
202int FAR PASCAL _export WEP(int);
203
204int FAR PASCAL LibMain(HANDLE hInst, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
205{
206    if ( wHeapSize > 0 )
207        UnlockData(0);
208    return 1;
209}
210
211int FAR PASCAL _export WEP(int nParam)
212{ 
213    return 1; 
214}
215#endif /* not WIN32 */
216
217#endif /* XP_WIN */
218
219
220/* ------------------------------------------------------------------
221 *  MACINTOSH STUBS
222 * ------------------------------------------------------------------
223 */
224
225#if defined(XP_MACOSX)
226
227#ifdef STANDALONE_REGISTRY
228extern XP_File vr_fileOpen(const char *name, const char * mode)
229{
230    XP_File fh = NULL;
231    struct stat st;
232
233    errno = 0; /* reset errno (only if we're using stdio) */
234
235    if ( name != NULL ) {
236        if ( stat( name, &st ) == 0 )
237            fh = fopen( name, XP_FILE_UPDATE_BIN );
238        else 
239        {
240            /* should never get here! */
241            fh = fopen( name, XP_FILE_TRUNCATE_BIN );
242        }
243    }
244    return fh;
245}
246#endif /*STANDALONE_REGISTRY*/
247
248extern void vr_findGlobalRegName()
249{
250    OSErr   err;
251    FSRef   foundRef;
252    
253    err = FSFindFolder(kLocalDomain, kDomainLibraryFolderType, kDontCreateFolder, &foundRef);
254    if (err == noErr)
255    {
256        FSRef parentRef;
257        err = FSMakeFSRefUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
258                                 kTextEncodingUnknown, &parentRef);
259        if (err == fnfErr)
260        {
261            err = FSCreateDirectoryUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
262                                           kFSCatInfoNone, NULL, &parentRef, NULL, NULL);
263        }
264        if (err == noErr)
265        {
266            FSRef regRef;
267            err = FSMakeFSRefUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXRegName), kOSXRegName,
268                                     kTextEncodingUnknown, &regRef);
269            if (err == fnfErr)
270            {
271                FSCatalogInfo catalogInfo;
272                FileInfo fileInfo = { 'REGS', 'MOSS', 0, { 0, 0 }, 0 };
273                memmove(&(catalogInfo.finderInfo), &fileInfo, sizeof(FileInfo));
274                err = FSCreateFileUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXRegName), kOSXRegName,
275                                               kFSCatInfoFinderInfo, &catalogInfo, &regRef, NULL);
276            }
277            if (err == noErr)
278            {
279                UInt8 pathBuf[PATH_MAX];
280                err = FSRefMakePath(&regRef, pathBuf, sizeof(pathBuf));
281                if (err == noErr)
282                    globalRegName = XP_STRDUP((const char*)pathBuf);
283            }
284        }
285    }
286}
287
288extern char* vr_findVerRegName()
289{
290    OSErr   err;
291    FSRef   foundRef;
292    
293    err = FSFindFolder(kLocalDomain, kDomainLibraryFolderType, kDontCreateFolder, &foundRef);
294    if (err == noErr)
295    {
296        FSRef parentRef;
297        err = FSMakeFSRefUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
298                                 kTextEncodingUnknown, &parentRef);
299        if (err == fnfErr)
300        {
301            err = FSCreateDirectoryUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
302                                           kFSCatInfoNone, NULL, &parentRef, NULL, NULL);
303        }
304        if (err == noErr)
305        {
306            FSRef regRef;
307            err = FSMakeFSRefUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXVersRegName), kOSXVersRegName,
308                                     kTextEncodingUnknown, &regRef);
309            if (err == fnfErr)
310            {
311                FSCatalogInfo catalogInfo;
312                FileInfo fileInfo = { 'REGS', 'MOSS', 0, { 0, 0 }, 0 };
313                memmove(&(catalogInfo.finderInfo), &fileInfo, sizeof(FileInfo));
314                err = FSCreateFileUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXVersRegName), kOSXVersRegName,
315                                               kFSCatInfoFinderInfo, &catalogInfo, &regRef, NULL);
316            }
317            if (err == noErr)
318            {
319                UInt8 pathBuf[PATH_MAX];
320                err = FSRefMakePath(&regRef, pathBuf, sizeof(pathBuf));
321                if (err == noErr)
322                    verRegName = XP_STRDUP((const char*)pathBuf);
323            }
324        }
325    }
326    return verRegName;
327}
328
329#endif /* XP_MACOSX */
330
331
332/* ------------------------------------------------------------------
333 *  UNIX STUBS
334 * ------------------------------------------------------------------
335 */
336
337#if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS)
338
339#include <stdlib.h>
340
341#ifdef XP_OS2
342#include <io.h>
343#define W_OK 0x02 /*evil hack from the docs...*/
344#else
345#include <unistd.h>
346#endif
347
348#include "NSReg.h"
349#include "VerReg.h"
350
351char *TheRegistry = "registry"; 
352char *Flist;
353
354REGERR vr_ParseVersion(char *verstr, VERSION *result);
355
356#if defined(XP_UNIX) && !defined(XP_MACOSX)
357
358#ifdef STANDALONE_REGISTRY
359extern XP_File vr_fileOpen (const char *name, const char * mode)
360{
361    XP_File fh = NULL;
362    struct stat st;
363
364    if ( name != NULL ) {
365        if ( stat( name, &st ) == 0 )
366            fh = fopen( name, XP_FILE_UPDATE_BIN );
367        else
368            fh = fopen( name, XP_FILE_TRUNCATE_BIN );
369    }
370
371    return fh;
372}
373#endif /*STANDALONE_REGISTRY*/
374
375extern void vr_findGlobalRegName ()
376{
377#ifndef STANDALONE_REGISTRY
378    char *def = NULL;
379    char *home = getenv("HOME");
380    if (home != NULL) {
381        def = (char *) XP_ALLOC(XP_STRLEN(home) + XP_STRLEN(DEF_REG)+1);
382        if (def != NULL) {
383          XP_STRCPY(def, home);
384          XP_STRCAT(def, DEF_REG);
385        }
386    }
387    if (def != NULL) {
388        globalRegName = XP_STRDUP(def);
389    } else {
390        globalRegName = XP_STRDUP(TheRegistry);
391    }
392    XP_FREEIF(def);
393#else
394    globalRegName = XP_STRDUP(TheRegistry);
395#endif /*STANDALONE_REGISTRY*/
396}
397
398char* vr_findVerRegName ()
399{
400    if ( verRegName != NULL )
401        return verRegName;
402
403#ifndef STANDALONE_REGISTRY
404    {
405        char *def = NULL;
406        char *home = getenv("HOME");
407        if (home != NULL) {
408            def = (char *) XP_ALLOC(XP_STRLEN(home) + XP_STRLEN(DEF_VERREG)+1);
409            if (def != NULL) {
410                XP_STRCPY(def, home);
411                XP_STRCAT(def, DEF_VERREG);
412            }
413        }
414        if (def != NULL) {
415            verRegName = XP_STRDUP(def);
416        }
417        XP_FREEIF(def);
418    }
419#else
420    verRegName = XP_STRDUP(TheRegistry);
421#endif /*STANDALONE_REGISTRY*/
422
423    return verRegName;
424}
425
426#endif /*XP_UNIX*/
427
428 /* ------------------------------------------------------------------
429 *  BeOS STUBS
430 * ------------------------------------------------------------------
431 */
432
433#ifdef XP_BEOS
434
435#ifdef STANDALONE_REGISTRY
436extern XP_File vr_fileOpen (const char *name, const char * mode)
437{
438    XP_File fh = NULL;
439    struct stat st;
440
441    if ( name != NULL ) {
442        if ( stat( name, &st ) == 0 )
443            fh = fopen( name, XP_FILE_UPDATE_BIN );
444        else
445            fh = fopen( name, XP_FILE_TRUNCATE_BIN );
446    }
447
448    return fh;
449}
450#endif /*STANDALONE_REGISTRY*/
451
452extern void vr_findGlobalRegName ()
453{
454#ifndef STANDALONE_REGISTRY
455    char *def = NULL;
456      char settings[1024];
457      find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, settings, sizeof(settings));
458    if (settings != NULL) {
459        def = (char *) XP_ALLOC(XP_STRLEN(settings) + XP_STRLEN(BEOS_REG)+1);
460        if (def != NULL) {
461          XP_STRCPY(def, settings);
462          XP_STRCAT(def, BEOS_REG);
463        }
464    }
465    if (def != NULL) {
466        globalRegName = XP_STRDUP(def);
467    } else {
468        globalRegName = XP_STRDUP(TheRegistry);
469    }
470    XP_FREEIF(def);
471#else
472    globalRegName = XP_STRDUP(TheRegistry);
473#endif /*STANDALONE_REGISTRY*/
474}
475
476char* vr_findVerRegName ()
477{
478    if ( verRegName != NULL )
479        return verRegName;
480
481#ifndef STANDALONE_REGISTRY
482    {
483        char *def = NULL;
484        char settings[1024];
485        find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, settings, sizeof(settings));
486        if (settings != NULL) {
487            def = (char *) XP_ALLOC(XP_STRLEN(settings) + XP_STRLEN(BEOS_VERREG)+1);
488            if (def != NULL) {
489                XP_STRCPY(def, settings);
490                XP_STRCAT(def, BEOS_VERREG);
491            }
492        }
493        if (def != NULL) {
494            verRegName = XP_STRDUP(def);
495        }
496        XP_FREEIF(def);
497    }
498#else
499    verRegName = XP_STRDUP(TheRegistry);
500#endif /*STANDALONE_REGISTRY*/
501
502    return verRegName;
503}
504
505#endif /*XP_BEOS*/
506
507#endif /* XP_UNIX || XP_OS2 */