home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / libreg / src / vr_stubs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.5 KB  |  367 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /* this file contains stubs needed to build the registry routines
  20.  * into a stand-alone library for use with our installers
  21.  */
  22. #ifdef STANDALONE_REGISTRY
  23.  
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "vr_stubs.h"
  27.  
  28. #ifdef XP_MAC
  29. #include <Folders.h>
  30. #include <Script.h>
  31. #include <size_t.h>
  32. #include <stdlib.h>
  33. #endif
  34.  
  35. /* ------------------------------------------------------------------
  36.  *  OS/2 STUBS
  37.  * ------------------------------------------------------------------
  38.  */
  39. #ifdef XP_OS2
  40. #define INCL_DOS
  41. #include <os2.h>
  42. extern XP_File VR_StubOpen (const char * mode)
  43. {
  44.     char    path[ CCHMAXPATH ];
  45.     int     pathlen;
  46.     XP_File fh = NULL;
  47.     struct stat st;
  48.  
  49. #ifdef XP_OS2_HACK
  50.     /*DSR050197 - at this point, I need some front-end call to get the install directory of*/
  51.     /*communicator... for now I will let it default to the current directory...*/
  52. #endif
  53.     XP_STRCPY(path, ".");
  54.     pathlen = strlen(path);
  55.  
  56.     if ( pathlen > 0 ) {
  57.         XP_STRCPY( path+pathlen, "\\nsreg.dat" );
  58.  
  59.         if ( stat( path, &st ) == 0 )
  60.             fh = fopen( path, XP_FILE_UPDATE_BIN );
  61.         else
  62.             fh = fopen( path, XP_FILE_WRITE_BIN );
  63.     }
  64.  
  65.     return fh;
  66. }
  67.  
  68. /* ------------------------------------------------------------------
  69.  *  WINDOWS STUBS
  70.  * ------------------------------------------------------------------
  71.  */
  72. #elif XP_PC
  73. #include "windows.h"
  74. #define PATHLEN 260
  75.  
  76. extern XP_File VR_StubOpen (const char * mode)
  77. {
  78.     char    path[ PATHLEN ];
  79.     int     pathlen;
  80.     XP_File fh = NULL;
  81.     struct stat st;
  82.  
  83.     pathlen = GetWindowsDirectory(path, PATHLEN);
  84.     if ( pathlen > 0 ) {
  85.         XP_STRCPY( path+pathlen, "\\nsreg.dat" );
  86.  
  87.         if ( stat( path, &st ) == 0 )
  88.             fh = fopen( path, XP_FILE_UPDATE_BIN );
  89.         else
  90.             fh = fopen( path, XP_FILE_WRITE_BIN );
  91.     }
  92.  
  93.     return fh;
  94. }
  95.  
  96. #if !defined(WIN32) && !defined(__BORLANDC__)
  97. int FAR PASCAL _export WEP(int);
  98.  
  99. int FAR PASCAL LibMain(HANDLE hInst, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
  100. {
  101.     if ( wHeapSize > 0 )
  102.         UnlockData(0);
  103.     return 1;
  104. }
  105.  
  106. int FAR PASCAL _export WEP(int nParam)
  107.     return 1; 
  108. }
  109. #endif /* not WIN32 */
  110.  
  111. #endif /* XP_PC */
  112.  
  113.  
  114. /* ------------------------------------------------------------------
  115.  *  MACINTOSH STUBS
  116.  * ------------------------------------------------------------------
  117.  */
  118.  
  119. #ifdef XP_MAC
  120. #include <Files.h>
  121. #include "FullPath.h"
  122. extern XP_File VR_StubOpen (const char *mode)
  123. {
  124.  
  125.     XP_File fh = NULL;
  126.     FSSpec    regSpec;
  127.     OSErr    err;
  128.     short    foundVRefNum;
  129.     long    foundDirID;
  130.     short    pathLen;
  131.     Handle    thePath;
  132.     int     bCreate = 0;
  133.     Ptr        finalPath;
  134.     
  135.     err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID);
  136.  
  137.     if (!err) {
  138.  
  139.         err = FSMakeFSSpec(foundVRefNum, foundDirID, "\pNetscape Registry", ®Spec);
  140.  
  141.         if (err == -43) { /* if file doesn't exist */
  142.             err = FSpCreate(®Spec, '    ', '    ', smSystemScript);
  143.             bCreate = 1;
  144.         }
  145.  
  146.         if (err == noErr) {
  147.             err = FSpGetFullPath(®Spec, &pathLen, &thePath);
  148.             
  149.             finalPath = NewPtrClear(pathLen+1);
  150.             BlockMoveData(*thePath, finalPath, pathLen);
  151.                         
  152.             if (bCreate)
  153.                 fh = fopen( finalPath, XP_FILE_WRITE_BIN );
  154.             else 
  155.                 fh = fopen( finalPath, "w+b" ); /* this hack to support CW11 MSL C Lib fopen update mode */
  156.              
  157.             DisposePtr(finalPath);
  158.         }
  159.     }
  160.                                 
  161.     return fh;
  162. }
  163.  
  164. char *strdup(const char *source)
  165. {
  166.         char    *newAllocation;
  167.         size_t  stringLength;
  168.  
  169.         stringLength = strlen(source) + 1;
  170.  
  171.         newAllocation = (char *)XP_ALLOC(stringLength);
  172.         if (newAllocation == NULL)
  173.                 return NULL;
  174.         BlockMoveData(source, newAllocation, stringLength);
  175.         return newAllocation;
  176. }
  177.  
  178. int strcasecmp(const char *str1, const char *str2)
  179. {
  180.     char     currentChar1, currentChar2;
  181.  
  182.     while (1) {
  183.     
  184.         currentChar1 = *str1;
  185.         currentChar2 = *str2;
  186.         
  187.         if ((currentChar1 >= 'a') && (currentChar1 <= 'z'))
  188.             currentChar1 += ('A' - 'a');
  189.         
  190.         if ((currentChar2 >= 'a') && (currentChar2 <= 'z'))
  191.             currentChar2 += ('A' - 'a');
  192.                 
  193.         if (currentChar1 == '\0')
  194.             break;
  195.     
  196.         if (currentChar1 != currentChar2)
  197.             return currentChar1 - currentChar2;
  198.             
  199.         str1++;
  200.         str2++;
  201.     
  202.     }
  203.     
  204.     return currentChar1 - currentChar2;
  205. }
  206.  
  207. int strncasecmp(const char *str1, const char *str2, int length)
  208. {
  209.     char     currentChar1, currentChar2;
  210.  
  211.     while (length > 0) {
  212.  
  213.         currentChar1 = *str1;
  214.         currentChar2 = *str2;
  215.  
  216.         if ((currentChar1 >= 'a') && (currentChar1 <= 'z'))
  217.             currentChar1 += ('A' - 'a');
  218.  
  219.         if ((currentChar2 >= 'a') && (currentChar2 <= 'z'))
  220.             currentChar2 += ('A' - 'a');
  221.  
  222.         if (currentChar1 == '\0')
  223.             break;
  224.  
  225.         if (currentChar1 != currentChar2)
  226.             return currentChar1 - currentChar2;
  227.  
  228.         str1++;
  229.         str2++;
  230.  
  231.         length--;
  232.     }
  233.  
  234.     return currentChar1 - currentChar2;
  235. }
  236. #endif /* XP_MAC */
  237.  
  238.  
  239. /* ------------------------------------------------------------------
  240.  *  UNIX STUBS
  241.  * ------------------------------------------------------------------
  242.  */
  243.  
  244. /*allow OS/2 to use this main to test...*/
  245. #if defined(XP_UNIX) || defined(XP_OS2)
  246.  
  247. #include <stdlib.h>
  248. #ifdef XP_OS2
  249. #include <io.h>
  250. #define W_OK 0x02 /*evil hack from the docs...*/
  251. #else
  252. #include <unistd.h>
  253. #endif
  254. #include "NSReg.h"
  255. #include "VerReg.h"
  256.  
  257. char *TheRegistry; 
  258. char *Flist;
  259. /* WARNING: build hackery */
  260. long BUILDNUM =
  261. #include "../../../build/build_number"
  262. ;
  263.  
  264.  
  265. REGERR vr_ParseVersion(char *verstr, VERSION *result);
  266. int main(int argc, char *argv[]);
  267.  
  268. #ifdef XP_UNIX
  269. XP_File VR_StubOpen (const char * mode)
  270. {
  271.     XP_File fh;
  272.     struct stat st;
  273.  
  274.     if ( stat( TheRegistry, &st ) == 0 )
  275.         fh = fopen( TheRegistry, XP_FILE_UPDATE_BIN );
  276.     else
  277.         fh = fopen( TheRegistry, XP_FILE_WRITE_BIN );
  278.  
  279.     return fh;
  280. }
  281. #endif
  282.  
  283. int main(int argc, char *argv[])
  284. {
  285.     XP_File fh;
  286.     char    *entry;
  287.     char    *p;
  288.     char    *v;
  289.     char    buff[1024];
  290.     char    name[MAXREGPATHLEN+1];
  291.     char    path[MAXREGPATHLEN+1];
  292.     char    ver[MAXREGPATHLEN+1];
  293.  
  294.     if ( argc >= 3 )
  295.     {
  296.         TheRegistry = argv[1];
  297.         Flist = argv[2];
  298.     }
  299.     else
  300.     {
  301.         fprintf(stderr, "Usage: %s RegistryName FileList\n", argv[0]);
  302.         fprintf(stderr, "    The FileList file contains lines with comma-separated fields:\n");
  303.         fprintf(stderr, "    <regItemName>,<version>,<full filepath>\n");
  304.         exit (1);
  305.     }
  306.  
  307.     /* tmp use of buff to get the registry directory, which must be
  308.      * the navigator home directory.  Preserve the slash to match
  309.      * FE_GetDirectoryPath() called during navigator set-up
  310.      */
  311.  
  312.  
  313.     strcpy(buff, TheRegistry);
  314.     if ( p = strrchr( buff, '/' ))
  315.     {
  316.        char pwd[1024];
  317.  
  318.        *(p+1) = '\0';
  319.        getcwd(pwd, sizeof(pwd));
  320.        chdir(buff); getcwd(buff, sizeof(buff));
  321.        chdir(pwd); 
  322.     }
  323.     else
  324.     {
  325.        getcwd(buff, sizeof(buff));
  326.     }
  327.     strcat(buff, "/");
  328.  
  329.     if ( -1 == (access( TheRegistry, W_OK )) ) {
  330.         sprintf(ver,"4.1.0.%ld",BUILDNUM);
  331.         VR_CreateRegistry("Communicator", buff, ver);
  332.     }
  333.  
  334.     if ( !(fh = fopen( Flist, "r" )) )
  335.     {
  336.         fprintf(stderr, "%s: Cannot open \"%s\"\n", argv[0], Flist);
  337.         exit (1);
  338.     }
  339.  
  340.     while ( fgets ( buff, 1024, fh ) )
  341.     {
  342.         if (  *(entry = &buff[strlen(buff)-1]) == '\n' )
  343.             *entry = '\0';
  344.  
  345.         entry = strchr(buff, ',');
  346.         strcpy(name, strtok(buff, ","));
  347.         strcpy(ver,  strtok( NULL, ","));
  348.         strcpy(path, strtok( NULL, ","));
  349.  
  350.         v = ver;
  351.         while (*v && *v == ' ')
  352.             v++;
  353.  
  354.         p = path;
  355.         while (*p && *p == ' ')
  356.             p++;
  357.  
  358.         VR_Install ( name, p, v, FALSE );
  359.     }
  360.     fclose( fh );
  361.     return 0;
  362. }
  363. #endif /* XP_UNIX || XP_OS2 */
  364.  
  365. #endif /* STANDALONE_REGISTRY */
  366.