1 : /* -*- Mode: C++; tab-width: 2; 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 : #ifndef nsPluginManifestLineReader_h_
39 : #define nsPluginManifestLineReader_h_
40 :
41 : #include "nspr.h"
42 : #include "nsDebug.h"
43 :
44 : #ifdef XP_WIN
45 : #define PLUGIN_REGISTRY_FIELD_DELIMITER '|'
46 : #else
47 : #define PLUGIN_REGISTRY_FIELD_DELIMITER ':'
48 : #endif
49 :
50 : #define PLUGIN_REGISTRY_END_OF_LINE_MARKER '$'
51 :
52 : class nsPluginManifestLineReader
53 : {
54 : public:
55 5 : nsPluginManifestLineReader() {mBase = mCur = mNext = mLimit = 0;}
56 10 : ~nsPluginManifestLineReader() { if (mBase) delete[] mBase; mBase=0;}
57 :
58 5 : char* Init(PRUint32 flen)
59 : {
60 10 : mBase = mCur = mNext = new char[flen + 1];
61 5 : if (mBase) {
62 5 : mLimit = mBase + flen;
63 5 : *mLimit = 0;
64 : }
65 5 : mLength = 0;
66 5 : return mBase;
67 : }
68 :
69 72 : bool NextLine()
70 : {
71 72 : if (mNext >= mLimit)
72 5 : return false;
73 :
74 67 : mCur = mNext;
75 67 : mLength = 0;
76 :
77 67 : char *lastDelimiter = 0;
78 1783 : while(mNext < mLimit) {
79 1716 : if (IsEOL(*mNext)) {
80 67 : if (lastDelimiter) {
81 43 : if (lastDelimiter && *(mNext - 1) != PLUGIN_REGISTRY_END_OF_LINE_MARKER)
82 0 : return false;
83 43 : *lastDelimiter = '\0';
84 : } else {
85 24 : *mNext = '\0';
86 : }
87 :
88 81 : for (++mNext; mNext < mLimit; ++mNext) {
89 76 : if (!IsEOL(*mNext))
90 62 : break;
91 : }
92 67 : return true;
93 : }
94 1649 : if (*mNext == PLUGIN_REGISTRY_FIELD_DELIMITER)
95 77 : lastDelimiter = mNext;
96 1649 : ++mNext;
97 1649 : ++mLength;
98 : }
99 0 : return false;
100 : }
101 :
102 33 : int ParseLine(char** chunks, int maxChunks)
103 : {
104 33 : NS_ASSERTION(mCur && maxChunks && chunks, "bad call to ParseLine");
105 33 : int found = 0;
106 33 : chunks[found++] = mCur;
107 :
108 33 : if (found < maxChunks) {
109 315 : for (char* cur = mCur; *cur; cur++) {
110 315 : if (*cur == PLUGIN_REGISTRY_FIELD_DELIMITER) {
111 34 : *cur = 0;
112 34 : chunks[found++] = cur + 1;
113 34 : if (found == maxChunks)
114 19 : break;
115 : }
116 : }
117 : }
118 33 : return found;
119 : }
120 :
121 79 : char* LinePtr() { return mCur; }
122 14 : PRUint32 LineLength() { return mLength; }
123 :
124 1792 : bool IsEOL(char c) {return c == '\n' || c == '\r';}
125 :
126 : char* mBase;
127 : private:
128 : char* mCur;
129 : PRUint32 mLength;
130 : char* mNext;
131 : char* mLimit;
132 : };
133 :
134 : #endif
|