Back to index

lightning-sunbird  0.9+nobinonly
interp.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 /* Registry interpreter */
00038 
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <string.h>
00042 #include <assert.h>
00043 
00044 #include "VerReg.h"
00045 #include "NSReg.h"
00046 
00047 extern char *errstr(REGERR err);
00048 extern int DumpTree(void);
00049 
00050 
00051 int error(char *func, int err)
00052 {
00053        if (err == REGERR_OK)
00054        {
00055        printf("\t%s -- OK\n", func);
00056        }
00057        else
00058        {
00059               printf("\t%s -- %s\n", func, errstr(err));
00060        }
00061 
00062        return err;
00063 
00064 }      /* error */
00065 
00066 static char  *GetNextWord(char *cmd, char *buf)
00067 {
00068        /* copies until ',' or eos, then skips spaces */
00069        if (!cmd || !buf)
00070               return 0;
00071        while (*cmd && *cmd != ',')
00072               *buf++ = *cmd++;
00073        *buf = '\0';
00074        if (*cmd == ',')
00075        {
00076               cmd++;
00077               while(*cmd && *cmd == ' ')
00078                      cmd++;
00079        }
00080        return cmd;
00081 
00082 }      /* GetNextWord */
00083 
00084 static int vr_ParseVersion(char *verstr, VERSION *result)
00085 {
00086 
00087        result->major = result->minor = result->release = result->build = 0;
00088        result->major = atoi(verstr);
00089        while (*verstr && *verstr != '.')
00090               verstr++;
00091        if (*verstr)
00092        {
00093               verstr++;
00094               result->minor = atoi(verstr);
00095               while (*verstr && *verstr != '.')
00096                      verstr++;
00097               if (*verstr)
00098               {
00099                      verstr++;
00100                      result->release = atoi(verstr);
00101                      while (*verstr && *verstr != '.')
00102                             verstr++;
00103                      if (*verstr)
00104                      {
00105                             verstr++;
00106                             result->build = atoi(verstr);
00107                             while (*verstr && *verstr != '.')
00108                                    verstr++;
00109                      }
00110               }
00111        }
00112 
00113        return REGERR_OK;
00114 
00115 }      /* ParseVersion */
00116 
00117 
00118 void vCreate(char *cmd)
00119 {
00120 
00121        /* Syntax: Create [new,] 5.0b1 */
00122        char buf[512];
00123     
00124        int flag = 0;
00125        cmd = GetNextWord(cmd, buf);
00126     
00127        error("VR_CreateRegistry", VR_CreateRegistry("Communicator", buf, cmd));
00128 
00129 }      /* vCreate */
00130 
00131 
00132 
00133 void vFind(char *cmd)
00134 {
00135 
00136        VERSION ver;
00137        char path[MAXREGPATHLEN];
00138 
00139        if (error("VR_GetVersion", VR_GetVersion(cmd, &ver)) == REGERR_OK)
00140        {
00141               if (error("VR_GetPath", VR_GetPath(cmd, sizeof(path), path)) == REGERR_OK)
00142               {
00143                      printf("%s found: ver=%d.%d.%d.%d, check=0x%04x, path=%s\n", 
00144                             cmd, ver.major, ver.minor, ver.release, ver.build, ver.check,
00145                             path);
00146                      return;
00147               }
00148        }
00149 
00150        printf("%s not found.\n", cmd);
00151        return;
00152 
00153 }      /* vFind */
00154 
00155 
00156 void vHelp(char *cmd)
00157 {
00158 
00159        puts("Enter a command:");
00160     puts("\tN)ew <dir> [, <ver>] - create a new registry");
00161     puts("\tA)pp <dir>       - set application directory");
00162     puts("\tC)lose           - close the registry");
00163     puts("");
00164        puts("\tI)nstall <name>, <version>, <path> - install a new component");
00165        puts("\tR)emove <name>   - deletes a component from the Registry");
00166     puts("\tX)ists <name>    - checks for existence in registry");
00167     puts("\tT)est <name>     - validates physical existence");
00168     puts("\tE)num <name>     - dumps named subtree");
00169     puts("");
00170     puts("\tV)ersion <name>  - gets component version");
00171     puts("\tP)ath <name>     - gets component path");
00172     puts("\treF)count <name> - gets component refcount");
00173     puts("\tD)ir <name>      - gets component directory");
00174     puts("\tSR)efcount <name>- sets component refcount");
00175     puts("\tSD)ir <name>     - sets component directory");
00176     puts("");
00177        puts("\tQ)uit            - end the program");
00178 
00179 }      /* vHelp */
00180 
00181 
00182 void vInstall(char *cmd)
00183 {
00184 
00185        char name[MAXREGPATHLEN+1];
00186        char path[MAXREGPATHLEN+1];
00187     char ver[MAXREGPATHLEN+1];
00188 
00189     char *pPath, *pVer;
00190 
00191        cmd = GetNextWord(cmd, name);
00192     cmd = GetNextWord(cmd, ver);
00193     cmd = GetNextWord(cmd, path);
00194 
00195     pVer  = ( ver[0]  != '*' ) ? ver  : NULL;
00196     pPath = ( path[0] != '*' ) ? path : NULL;
00197 
00198        error("VR_Install", VR_Install(name, pPath, pVer, FALSE));
00199 
00200 }      /* vInstall */
00201 
00202 
00203 
00204 
00205                      
00206 
00207 void interp(void)
00208 {
00209 
00210        char line[256];
00211        char *p;
00212 
00213        while(1)
00214        {
00215               putchar('>');
00216               putchar(' ');
00217               fflush(stdin); fflush(stdout); fflush(stderr);
00218               gets(line);
00219 
00220               /* p points to next word after verb on command line */
00221               p = line;
00222               while (*p && *p!=' ')
00223                      p++;
00224               if (!*p)
00225                      p = 0;
00226               else
00227               {
00228                      while(*p && *p==' ')
00229                             p++;
00230               }
00231 
00232               switch(toupper(line[0]))
00233               {
00234               case 'N':
00235                      vCreate(p);
00236                      break;
00237         case 'A':
00238             error("VR_SetRegDirectory", VR_SetRegDirectory(p));
00239             break;
00240         case 'C':
00241             error("VR_Close", VR_Close());
00242             break;
00243 
00244               case 'I':
00245                      vInstall(p);
00246                      break;
00247               case 'R':
00248               error("VR_Remove", VR_Remove(p));
00249                      break;
00250         case 'X':
00251               error("VR_InRegistry", VR_InRegistry(p));
00252             break;
00253         case 'T':
00254               error("VR_ValidateComponent", VR_ValidateComponent(p));
00255             break;
00256 
00257 #if  LATER
00258         case 'E':
00259             vEnum(p);
00260             break;
00261 
00262         case 'V':
00263             vVersion(p);
00264             break;
00265         case 'P':
00266             vPath(p);
00267             break;
00268         case 'F':
00269             vGetRefCount(p);
00270             break;
00271         case 'D':
00272             vGetDir(p);
00273             break;
00274         
00275         case 'S':
00276             puts("--Unsupported--");
00277 #endif
00278 
00279               case 'H':
00280               default:
00281                      vHelp(line);
00282                      break;
00283               case 'Q':
00284                      return;
00285               }      /* switch */
00286        }      /* while */
00287 
00288        assert(0);
00289        return;       /* shouldn't get here */
00290 
00291 }      /* interp */
00292 
00293 /* EOF: interp.c */