8273104: Refactoring option parser for UL · openjdk/jdk@4eacdb3 (original) (raw)

`@@ -165,71 +165,33 @@ static uint next_file_number(const char* filename,

`

165

165

`return next_num;

`

166

166

`}

`

167

167

``

168

``

`-

bool LogFileOutput::parse_options(const char* options, outputStream* errstream) {

`

169

``

`-

if (options == NULL || strlen(options) == 0) {

`

170

``

`-

return true;

`

171

``

`-

}

`

172

``

`-

bool success = true;

`

173

``

`-

char* opts = os::strdup_check_oom(options, mtLogging);

`

174

``

-

175

``

`-

char* comma_pos;

`

176

``

`-

char* pos = opts;

`

177

``

`-

do {

`

178

``

`-

comma_pos = strchr(pos, ',');

`

179

``

`-

if (comma_pos != NULL) {

`

180

``

`-

*comma_pos = '\0';

`

181

``

`-

}

`

182

``

-

183

``

`-

char* equals_pos = strchr(pos, '=');

`

184

``

`-

if (equals_pos == NULL) {

`

185

``

`-

errstream->print_cr("Invalid option '%s' for log file output.", pos);

`

186

``

`-

success = false;

`

187

``

`-

break;

`

188

``

`-

}

`

189

``

`-

char* key = pos;

`

190

``

`-

char* value_str = equals_pos + 1;

`

191

``

`-

*equals_pos = '\0';

`

192

``

-

193

``

`-

if (strcmp(FoldMultilinesOptionKey, key) == 0) {

`

194

``

`-

if (strcmp(value_str, "true") == 0) {

`

195

``

`-

_fold_multilines = true;

`

196

``

`-

} else if (strcmp(value_str, "false") == 0) {

`

197

``

`-

_fold_multilines = false;

`

198

``

`-

} else {

`

199

``

`-

errstream->print_cr("Invalid option '%s' for %s.", value_str, FoldMultilinesOptionKey);

`

200

``

`-

success = false;

`

201

``

`-

break;

`

202

``

`-

}

`

203

``

`-

} else if (strcmp(FileCountOptionKey, key) == 0) {

`

204

``

`-

size_t value = parse_value(value_str);

`

205

``

`-

if (value > MaxRotationFileCount) {

`

``

168

`+

bool LogFileOutput::set_option(const char* key, const char* value, outputStream* errstream) {

`

``

169

`+

bool success = LogFileStreamOutput::set_option(key, value, errstream);

`

``

170

`+

if (!success) {

`

``

171

`+

if (strcmp(FileCountOptionKey, key) == 0) {

`

``

172

`+

size_t sizeval = parse_value(value);

`

``

173

`+

if (sizeval > MaxRotationFileCount) {

`

206

174

` errstream->print_cr("Invalid option: %s must be in range [0, %u]",

`

207

175

` FileCountOptionKey,

`

208

176

` MaxRotationFileCount);

`

209

``

`-

success = false;

`

210

``

`-

break;

`

``

177

`+

} else {

`

``

178

`+

_file_count = static_cast(sizeval);

`

``

179

`+

_is_default_file_count = false;

`

``

180

`+

success = true;

`

211

181

` }

`

212

``

`-

_file_count = static_cast(value);

`

213

``

`-

_is_default_file_count = false;

`

214

182

` } else if (strcmp(FileSizeOptionKey, key) == 0) {

`

215

``

`-

julong value;

`

216

``

`-

success = Arguments::atojulong(value_str, &value);

`

217

``

`-

if (!success || (value > SIZE_MAX)) {

`

``

183

`+

julong longval;

`

``

184

`+

success = Arguments::atojulong(value, &longval);

`

``

185

`+

if (!success || (longval > SIZE_MAX)) {

`

218

186

` errstream->print_cr("Invalid option: %s must be in range [0, "

`

219

187

` SIZE_FORMAT "]", FileSizeOptionKey, (size_t)SIZE_MAX);

`

220

188

` success = false;

`

221

``

`-

break;

`

``

189

`+

} else {

`

``

190

`+

_rotate_size = static_cast(longval);

`

``

191

`+

success = true;

`

222

192

` }

`

223

``

`-

_rotate_size = static_cast(value);

`

224

``

`-

} else {

`

225

``

`-

errstream->print_cr("Invalid option '%s' for log file output.", key);

`

226

``

`-

success = false;

`

227

``

`-

break;

`

228

193

` }

`

229

``

`-

pos = comma_pos + 1;

`

230

``

`-

} while (comma_pos != NULL);

`

231

``

-

232

``

`-

os::free(opts);

`

``

194

`+

}

`

233

195

`return success;

`

234

196

`}

`

235

197

``