PostgreSQL Source Code: src/bin/psql/variables.c Source File (original) (raw)

1

2

3

4

5

6

7

9

10#include <math.h>

11

15

16

17

18

19

20

21

22

23static bool

25{

26 const unsigned char *ptr = (const unsigned char *) name;

27

28

29 if (*ptr == '\0')

30 return false;

31

32 while (*ptr)

33 {

35 strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"

36 "_0123456789", *ptr) != NULL)

37 ptr++;

38 else

39 return false;

40 }

41

42 return true;

43}

44

45

46

47

48

49

50

51

54{

56

58 ptr->name = NULL;

59 ptr->value = NULL;

62 ptr->next = NULL;

63

64 return ptr;

65}

66

67

68

69

70

71

72const char *

74{

76

77 if (!space)

78 return NULL;

79

80 for (current = space->next; current; current = current->next)

81 {

83

84 if (cmp == 0)

85 {

86

87 return current->value;

88 }

89 if (cmp > 0)

90 break;

91 }

92

93 return NULL;

94}

95

96

97

98

99

100

101

102

103

104

105

106

107

108bool

110{

111 size_t len;

112 bool valid = true;

113

114

115 if (value == NULL)

117

119

121 *result = true;

123 *result = false;

125 *result = true;

127 *result = false;

128

130 *result = true;

132 *result = false;

134 *result = true;

136 *result = false;

137 else

138 {

139

141 pg_log_error("unrecognized value \"%s\" for \"%s\": Boolean expected",

143 valid = false;

144 }

145 return valid;

146}

147

148

149

150

151

152

153

154

155

156

157bool

159{

160 char *end;

161 long numval;

162

163

164 if (value == NULL)

166

167 errno = 0;

168 numval = strtol(value, &end, 0);

169 if (errno == 0 && *end == '\0' && end != value && numval == (int) numval)

170 {

171 *result = (int) numval;

172 return true;

173 }

174 else

175 {

176

178 pg_log_error("invalid value \"%s\" for \"%s\": integer expected",

180 return false;

181 }

182}

183

184

185

186

187

188

189

190

191

192

193

194bool

196{

197 char *end;

198 double dblval;

199

200

201

202

203

204 if ((value == NULL) || (*value == '\0'))

205 {

208 return false;

209 }

210

211 errno = 0;

212 dblval = strtod(value, &end);

213 if (errno == 0 && *end == '\0' && end != value)

214 {

215 if (dblval < min)

216 {

218 pg_log_error("invalid value \"%s\" for \"%s\": must be greater than %.2f",

220 return false;

221 }

222 else if (dblval > max)

223 {

225 pg_log_error("invalid value \"%s\" for \"%s\": must be less than %.2f",

227 }

228 *result = dblval;

229 return true;

230 }

231

232

233

234

235

236

237 else if ((errno == ERANGE) &&

238 (dblval == 0.0 || dblval >= HUGE_VAL || dblval <= -HUGE_VAL))

239 {

242 return false;

243 }

244 else

245 {

248 return false;

249 }

250}

251

252

253

254

255void

257{

259

260 if (!space)

261 return;

262

263 for (ptr = space->next; ptr; ptr = ptr->next)

264 {

268 break;

269 }

270}

271

272

273

274

275

276

277

278

279

280bool

282{

284 *previous;

285

286 if (!space || name)

287 return false;

288

290 {

291

293 return true;

295 return false;

296 }

297

298 for (previous = space, current = space->next;

299 current;

300 previous = current, current = current->next)

301 {

303

304 if (cmp == 0)

305 {

306

307

308

309

310

311

312

313

314

316 bool confirmed;

317

320

322 confirmed = current->assign_hook(new_value);

323 else

324 confirmed = true;

325

326 if (confirmed)

327 {

329 current->value = new_value;

330

331

332

333

334

335 if (new_value == NULL &&

338 {

339 previous->next = current->next;

341 free(current);

342 }

343 }

344 else

345 pg_free(new_value);

346

347 return confirmed;

348 }

349 if (cmp > 0)

350 break;

351 }

352

353

355 {

356 current = pg_malloc(sizeof *current);

361 current->next = previous->next;

362 previous->next = current;

363 }

364 return true;

365}

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383void

387{

389 *previous;

390

391 if (!space || name)

392 return;

393

395 return;

396

397 for (previous = space, current = space->next;

398 current;

399 previous = current, current = current->next)

400 {

402

403 if (cmp == 0)

404 {

405

408 if (shook)

409 current->value = (*shook) (current->value);

410 if (ahook)

411 (void) (*ahook) (current->value);

412 return;

413 }

414 if (cmp > 0)

415 break;

416 }

417

418

419 current = pg_malloc(sizeof *current);

421 current->value = NULL;

424 current->next = previous->next;

425 previous->next = current;

426 if (shook)

427 current->value = (*shook) (current->value);

428 if (ahook)

429 (void) (*ahook) (current->value);

430}

431

432

433

434

435

436bool

438{

440

443

444 for (current = space->next; current; current = current->next)

445 {

447

448 if (cmp == 0)

451 if (cmp > 0)

452 break;

453 }

454

455 return false;

456}

457

458

459

460

461bool

463{

465}

466

467

468

469

470

471

472

473bool

475{

477}

478

479

480

481

482

483

484

485void

487{

488 pg_log_error("unrecognized value \"%s\" for \"%s\"\n"

489 "Available values are: %s.",

491}

#define IS_HIGHBIT_SET(ch)

void * pg_malloc(size_t size)

char * pg_strdup(const char *in)

volatile sig_atomic_t cancel_pressed

Assert(PointerIsAligned(start, uint64))

#define pg_log_error(...)

int pg_strcasecmp(const char *s1, const char *s2)

int pg_strncasecmp(const char *s1, const char *s2, size_t n)

static int cmp(const chr *x, const chr *y, size_t len)

VariableSubstituteHook substitute_hook

VariableAssignHook assign_hook

void PrintVariables(VariableSpace space)

bool DeleteVariable(VariableSpace space, const char *name)

void SetVariableHooks(VariableSpace space, const char *name, VariableSubstituteHook shook, VariableAssignHook ahook)

void PsqlVarEnumError(const char *name, const char *value, const char *suggestions)

bool ParseVariableBool(const char *value, const char *name, bool *result)

bool ParseVariableDouble(const char *value, const char *name, double *result, double min, double max)

bool SetVariableBool(VariableSpace space, const char *name)

bool ParseVariableNum(const char *value, const char *name, int *result)

bool VariableHasHook(VariableSpace space, const char *name)

bool SetVariable(VariableSpace space, const char *name, const char *value)

static bool valid_variable_name(const char *name)

const char * GetVariable(VariableSpace space, const char *name)

VariableSpace CreateVariableSpace(void)

char *(* VariableSubstituteHook)(char *newval)

bool(* VariableAssignHook)(const char *newval)