1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-04 03:49:14 +02:00

Remove too-verbose braces in switch statements.

The original intention was to enclose complex code in braces but somehow braces got propagated almost everywhere.

Document the standard for braces in switch statements and update the code to reflect the standard.
This commit is contained in:
David Steele 2021-01-26 12:10:24 -05:00
parent f669da7dcc
commit 456a300bb7
27 changed files with 50 additions and 347 deletions

View File

@ -162,6 +162,26 @@ if (condition)
valueThatUsesEntireLine2;
}
```
Braces should be added to `switch` statement cases that have a significant amount of code. As a general rule of thumb, if the code block in the `case` is large enough to have blank lines and/or multiple comments then it should be enclosed in braces.
```c
switch (int)
{
case 1:
a = 2;
break;
case 2:
{
# Comment this more complex code
a = 1;
b = 2;
c = func(a, b);
break;
}
}
```
#### Hints, Warnings, and Errors

View File

@ -209,6 +209,28 @@ if (condition)
return
valueThatUsesEntireLine1 &&
valueThatUsesEntireLine2;
}
</code-block>
<p>Braces should be added to <code>switch</code> statement cases that have a significant amount of code. As a general rule of thumb, if the code block in the <code>case</code> is large enough to have blank lines and/or multiple comments then it should be enclosed in braces.</p>
<code-block type="c">
switch (int)
{
case 1:
a = 2;
break;
case 2:
{
# Comment this more complex code
a = 1;
b = 2;
c = func(a, b);
break;
}
}
</code-block>
</section>

View File

@ -647,19 +647,15 @@ void backupResumeCallback(void *data, const StorageInfo *info)
// The link will be recreated during the backup if needed.
// -------------------------------------------------------------------------------------------------------------------------
case storageTypeLink:
{
storageRemoveP(storageRepoWrite(), backupPath);
break;
}
// Remove special files
// -------------------------------------------------------------------------------------------------------------------------
case storageTypeSpecial:
{
LOG_WARN_FMT("remove special file '%s' from resumed backup", strZ(storagePathP(storageRepo(), backupPath)));
storageRemoveP(storageRepoWrite(), backupPath);
break;
}
}
FUNCTION_TEST_RETURN_VOID();

View File

@ -122,22 +122,16 @@ const String *backupTypeStr(BackupType type)
switch (type)
{
case backupTypeFull:
{
result = BACKUP_TYPE_FULL_STR;
break;
}
case backupTypeDiff:
{
result = BACKUP_TYPE_DIFF_STR;
break;
}
case backupTypeIncr:
{
result = BACKUP_TYPE_INCR_STR;
break;
}
}
FUNCTION_TEST_RETURN(result);

View File

@ -165,40 +165,28 @@ stanzaStatus(const int code, bool backupLockHeld, Variant *stanzaInfo)
switch (code)
{
case INFO_STANZA_STATUS_CODE_OK:
{
kvAdd(statusKv, STATUS_KEY_MESSAGE_VAR, VARSTR(INFO_STANZA_STATUS_MESSAGE_OK_STR));
break;
}
case INFO_STANZA_STATUS_CODE_MISSING_STANZA_PATH:
{
kvAdd(statusKv, STATUS_KEY_MESSAGE_VAR, VARSTR(INFO_STANZA_STATUS_MESSAGE_MISSING_STANZA_PATH_STR));
break;
}
case INFO_STANZA_STATUS_CODE_MISSING_STANZA_DATA:
{
kvAdd(statusKv, STATUS_KEY_MESSAGE_VAR, VARSTR(INFO_STANZA_STATUS_MESSAGE_MISSING_STANZA_DATA_STR));
break;
}
case INFO_STANZA_STATUS_CODE_NO_BACKUP:
{
kvAdd(statusKv, STATUS_KEY_MESSAGE_VAR, VARSTR(INFO_STANZA_STATUS_MESSAGE_NO_BACKUP_STR));
break;
}
case INFO_STANZA_STATUS_CODE_MIXED:
{
kvAdd(statusKv, STATUS_KEY_MESSAGE_VAR, VARSTR(INFO_STANZA_MESSAGE_MIXED_STR));
break;
}
case INFO_STANZA_STATUS_CODE_PG_MISMATCH:
{
kvAdd(statusKv, STATUS_KEY_MESSAGE_VAR, VARSTR(INFO_STANZA_STATUS_MESSAGE_PG_MISMATCH_STR));
break;
}
}
// Construct a specific lock part
@ -230,28 +218,20 @@ repoStanzaStatus(const int code, Variant *repoStanzaInfo)
switch (code)
{
case INFO_STANZA_STATUS_CODE_OK:
{
kvAdd(statusKv, STATUS_KEY_MESSAGE_VAR, VARSTR(INFO_STANZA_STATUS_MESSAGE_OK_STR));
break;
}
case INFO_STANZA_STATUS_CODE_MISSING_STANZA_PATH:
{
kvAdd(statusKv, STATUS_KEY_MESSAGE_VAR, VARSTR(INFO_STANZA_STATUS_MESSAGE_MISSING_STANZA_PATH_STR));
break;
}
case INFO_STANZA_STATUS_CODE_MISSING_STANZA_DATA:
{
kvAdd(statusKv, STATUS_KEY_MESSAGE_VAR, VARSTR(INFO_STANZA_STATUS_MESSAGE_MISSING_STANZA_DATA_STR));
break;
}
case INFO_STANZA_STATUS_CODE_NO_BACKUP:
{
kvAdd(statusKv, STATUS_KEY_MESSAGE_VAR, VARSTR(INFO_STANZA_STATUS_MESSAGE_NO_BACKUP_STR));
break;
}
}
FUNCTION_TEST_RETURN_VOID();

View File

@ -60,28 +60,20 @@ storageListRenderCallback(void *data, const StorageInfo *info)
switch (info->type)
{
case storageTypeFile:
{
ioWrite(listData->write, BUFSTRDEF("file\""));
break;
}
case storageTypeLink:
{
ioWrite(listData->write, BUFSTRDEF("link\""));
break;
}
case storageTypePath:
{
ioWrite(listData->write, BUFSTRDEF("path\""));
break;
}
case storageTypeSpecial:
{
ioWrite(listData->write, BUFSTRDEF("special\""));
break;
}
}
if (info->type == storageTypeFile)

View File

@ -867,11 +867,9 @@ restoreCleanInfoListCallback(void *data, const StorageInfo *info)
// Special file types cannot exist in the manifest so just delete them
case storageTypeSpecial:
{
LOG_DETAIL_FMT("remove special file '%s'", strZ(pgPath));
storageRemoveP(storageLocalWrite(), pgPath, .errorOnMissing = true);
break;
}
}
FUNCTION_TEST_RETURN_VOID();

View File

@ -25,67 +25,47 @@ bz2Error(int error)
switch (error)
{
case BZ_SEQUENCE_ERROR:
{
errorMsg = "sequence error";
break;
}
case BZ_PARAM_ERROR:
{
errorMsg = "parameter error";
break;
}
case BZ_MEM_ERROR:
{
errorMsg = "memory error";
errorType = &MemoryError;
break;
}
case BZ_DATA_ERROR:
{
errorMsg = "data error";
errorType = &FormatError;
break;
}
case BZ_DATA_ERROR_MAGIC:
{
errorMsg = "data error magic";
errorType = &FormatError;
break;
}
case BZ_IO_ERROR:
{
errorMsg = "io error";
break;
}
case BZ_UNEXPECTED_EOF:
{
errorMsg = "unexpected eof";
break;
}
case BZ_OUTBUFF_FULL:
{
errorMsg = "outbuff full";
break;
}
case BZ_CONFIG_ERROR:
{
errorMsg = "config error";
break;
}
default:
{
errorMsg = "unknown error";
break;
}
}
THROWP_FMT(errorType, "bz2 error: [%d] %s", error, errorMsg);

View File

@ -22,58 +22,42 @@ gzError(int error)
{
// Not exactly an error, but since we are not using custom dictionaries it shouldn't be possible to get this result
case Z_NEED_DICT:
{
errorMsg = "need dictionary";
break;
}
// We should not get this error -- included for completeness
case Z_ERRNO:
{
errorMsg = "file error";
break;
}
case Z_STREAM_ERROR:
{
errorMsg = "stream error";
errorType = &FormatError;
break;
}
case Z_DATA_ERROR:
{
errorMsg = "data error";
errorType = &FormatError;
break;
}
case Z_MEM_ERROR:
{
errorMsg = "insufficient memory";
errorType = &MemoryError;
break;
}
// This error indicates an error in the code -- there should always be space in the buffer
case Z_BUF_ERROR:
{
errorMsg = "no space in buffer";
break;
}
case Z_VERSION_ERROR:
{
errorMsg = "incompatible version";
errorType = &FormatError;
break;
}
default:
{
errorMsg = "unknown error";
break;
}
}
THROWP_FMT(errorType, "zlib threw error: [%d] %s", error, errorMsg);

View File

@ -31,22 +31,16 @@ exitSignalName(SignalType signalType)
switch (signalType)
{
case signalTypeHup:
{
name = "HUP";
break;
}
case signalTypeInt:
{
name = "INT";
break;
}
case signalTypeTerm:
{
name = "TERM";
break;
}
case signalTypeNone:
THROW(AssertError, "no name for signal none");

View File

@ -134,19 +134,15 @@ tlsSessionResultProcess(TlsSession *this, int errorTls, long unsigned int errorT
// Try again after waiting for read ready
case SSL_ERROR_WANT_READ:
{
ioReadReadyP(ioSessionIoRead(this->ioSession), .error = true);
result = 0;
break;
}
// Try again after waiting for write ready
case SSL_ERROR_WANT_WRITE:
{
ioWriteReadyP(ioSessionIoWrite(this->ioSession), .error = true);
result = 0;
break;
}
// A syscall failed (this usually indicates unexpected eof)
case SSL_ERROR_SYSCALL:

View File

@ -259,35 +259,35 @@ jsonToStrInternal(const char *json, unsigned int *jsonPos)
switch (json[*jsonPos])
{
case '"':
strCatChr(result, '"');
strCatChr(result, '"');
break;
case '\\':
strCatChr(result, '\\');
strCatChr(result, '\\');
break;
case '/':
strCatChr(result, '/');
strCatChr(result, '/');
break;
case 'n':
strCatChr(result, '\n');
strCatChr(result, '\n');
break;
case 'r':
strCatChr(result, '\r');
strCatChr(result, '\r');
break;
case 't':
strCatChr(result, '\t');
strCatChr(result, '\t');
break;
case 'b':
strCatChr(result, '\b');
strCatChr(result, '\b');
break;
case 'f':
strCatChr(result, '\f');
strCatChr(result, '\f');
break;
default:
@ -515,26 +515,20 @@ jsonToVarInternal(const char *json, unsigned int *jsonPos)
{
// String
case '"':
{
result = varNewStr(jsonToStrInternal(json, jsonPos));
break;
}
// Integer
case '-':
case '0' ... '9':
{
result = jsonToNumberInternal(json, jsonPos);
break;
}
// Boolean
case 't':
case 'f':
{
result = varNewBool(jsonToBoolInternal(json, jsonPos));
break;
}
// Null
case 'n':
@ -549,24 +543,18 @@ jsonToVarInternal(const char *json, unsigned int *jsonPos)
// Array
case '[':
{
result = varNewVarLst(jsonToVarLstInternal(json, jsonPos));
break;
}
// Object
case '{':
{
result = varNewKv(jsonToKvInternal(json, jsonPos));
break;
}
// Object
default:
{
THROW_FMT(JsonFormatError, "invalid type at '%s'", json + *jsonPos);
break;
}
}
jsonConsumeWhiteSpace(json, jsonPos);
@ -705,46 +693,32 @@ jsonFromStrInternal(String *json, const String *string)
switch (stringChr)
{
case '"':
{
strCatZ(json, "\\\"");
break;
}
case '\\':
{
strCatZ(json, "\\\\");
break;
}
case '\n':
{
strCatZ(json, "\\n");
break;
}
case '\r':
{
strCatZ(json, "\\r");
break;
}
case '\t':
{
strCatZ(json, "\\t");
break;
}
case '\b':
{
strCatZ(json, "\\b");
break;
}
case '\f':
{
strCatZ(json, "\\f");
break;
}
}
break;
@ -823,10 +797,8 @@ jsonFromKvInternal(const KeyValue *kv)
switch (varType(value))
{
case varTypeKeyValue:
{
strCat(result, jsonFromKvInternal(kvDup(varKv(value))));
break;
}
case varTypeVariantList:
{
@ -878,16 +850,12 @@ jsonFromKvInternal(const KeyValue *kv)
// String
case varTypeString:
{
jsonFromStrInternal(result, varStr(value));
break;
}
default:
{
strCat(result, varStrForce(value));
break;
}
}
}
}

View File

@ -433,10 +433,8 @@ lstSort(List *this, SortOrder sortOrder)
switch (sortOrder)
{
case sortOrderAsc:
{
qsort(this->list, this->listSize, this->itemSize, this->comparator);
break;
}
case sortOrderDesc:
{

View File

@ -120,22 +120,16 @@ varDup(const Variant *this)
switch (this->type)
{
case varTypeBool:
{
result = varNewBool(varBool(this));
break;
}
case varTypeInt:
{
result = varNewInt(varInt(this));
break;
}
case varTypeInt64:
{
result = varNewInt64(varInt64(this));
break;
}
case varTypeKeyValue:
{
@ -153,28 +147,20 @@ varDup(const Variant *this)
}
case varTypeString:
{
result = varNewStr(varStr(this));
break;
}
case varTypeUInt:
{
result = varNewUInt(varUInt(this));
break;
}
case varTypeUInt64:
{
result = varNewUInt64(varUInt64(this));
break;
}
case varTypeVariantList:
{
result = varNewVarLst(varVarLst(this));
break;
}
}
}
@ -201,40 +187,28 @@ varEq(const Variant *this1, const Variant *this2)
switch (varType(this1))
{
case varTypeBool:
{
result = varBool(this1) == varBool(this2);
break;
}
case varTypeInt:
{
result = varInt(this1) == varInt(this2);
break;
}
case varTypeInt64:
{
result = varInt64(this1) == varInt64(this2);
break;
}
case varTypeString:
{
result = strEq(varStr(this1), varStr(this2));
break;
}
case varTypeUInt:
{
result = varUInt(this1) == varUInt(this2);
break;
}
case varTypeUInt64:
{
result = varUInt64(this1) == varUInt64(this2);
break;
}
default:
THROW_FMT(AssertError, "unable to test equality for %s", variantTypeName[this1->type]);
@ -412,16 +386,12 @@ varIntForce(const Variant *this)
switch (this->type)
{
case varTypeBool:
{
result = varBool(this);
break;
}
case varTypeInt:
{
result = varInt(this);
break;
}
case varTypeInt64:
{
@ -438,10 +408,8 @@ varIntForce(const Variant *this)
}
case varTypeString:
{
result = cvtZToInt(strZ(varStr(this)));
break;
}
case varTypeUInt:
{
@ -527,35 +495,25 @@ varInt64Force(const Variant *this)
switch (this->type)
{
case varTypeBool:
{
result = varBool(this);
break;
}
case varTypeInt:
{
result = (int64_t)varInt(this);
break;
}
case varTypeInt64:
{
result = varInt64(this);
break;
}
case varTypeString:
{
result = cvtZToInt64(strZ(varStr(this)));
break;
}
case varTypeUInt:
{
result = varUInt(this);
break;
}
case varTypeUInt64:
{
@ -630,10 +588,8 @@ varUIntForce(const Variant *this)
switch (this->type)
{
case varTypeBool:
{
result = varBool(this);
break;
}
case varTypeInt:
{
@ -670,10 +626,8 @@ varUIntForce(const Variant *this)
}
case varTypeUInt:
{
result = varUInt(this);
break;
}
case varTypeUInt64:
{
@ -693,10 +647,8 @@ varUIntForce(const Variant *this)
}
case varTypeString:
{
result = cvtZToUInt(strZ(varStr(this)));
break;
}
default:
THROW_FMT(AssertError, "unable to force %s to %s", variantTypeName[this->type], variantTypeName[varTypeUInt]);
@ -754,10 +706,8 @@ varUInt64Force(const Variant *this)
switch (this->type)
{
case varTypeBool:
{
result = varBool(this);
break;
}
case varTypeInt:
{
@ -794,22 +744,16 @@ varUInt64Force(const Variant *this)
}
case varTypeString:
{
result = cvtZToUInt64(strZ(varStr(this)));
break;
}
case varTypeUInt:
{
result = varUInt(this);
break;
}
case varTypeUInt64:
{
result = varUInt64(this);
break;
}
default:
THROW_FMT(AssertError, "unable to force %s to %s", variantTypeName[this->type], variantTypeName[varTypeUInt64]);
@ -924,10 +868,8 @@ varStrForce(const Variant *this)
switch (varType(this))
{
case varTypeBool:
{
result = strNew(cvtBoolToConstZ(varBool(this)));
break;
}
case varTypeInt:
{
@ -948,10 +890,8 @@ varStrForce(const Variant *this)
}
case varTypeString:
{
result = strDup(varStr(this));
break;
}
case varTypeUInt:
{
@ -1033,22 +973,16 @@ varToLog(const Variant *this)
switch (varType(this))
{
case varTypeString:
{
result = strToLog(varStr(this));
break;
}
case varTypeKeyValue:
{
result = strNew("{KeyValue}");
break;
}
case varTypeVariantList:
{
result = strNew("{VariantList}");
break;
}
case varTypeBool:
case varTypeInt:
@ -1080,55 +1014,39 @@ varFree(Variant *this)
switch (this->type)
{
case varTypeBool:
{
memContext = ((VariantBool *)this)->memContext;
break;
}
case varTypeInt:
{
memContext = ((VariantInt *)this)->memContext;
break;
}
case varTypeInt64:
{
memContext = ((VariantInt64 *)this)->memContext;
break;
}
case varTypeKeyValue:
{
memContext = ((VariantKeyValue *)this)->memContext;
kvFree(((VariantKeyValue *)this)->data);
break;
}
case varTypeString:
{
memContext = ((VariantString *)this)->memContext;
strFree(((VariantString *)this)->data);
break;
}
case varTypeUInt:
{
memContext = ((VariantUInt *)this)->memContext;
break;
}
case varTypeUInt64:
{
memContext = ((VariantUInt64 *)this)->memContext;
break;
}
case varTypeVariantList:
{
memContext = ((VariantVariantList *)this)->memContext;
varLstFree(((VariantVariantList *)this)->data);
break;
}
}
MEM_CONTEXT_BEGIN(memContext)

View File

@ -257,22 +257,16 @@ cfgCommandRoleStr(ConfigCommandRole commandRole)
break;
case cfgCmdRoleAsync:
{
result = CONFIG_COMMAND_ROLE_ASYNC_STR;
break;
}
case cfgCmdRoleLocal:
{
result = CONFIG_COMMAND_ROLE_LOCAL_STR;
break;
}
case cfgCmdRoleRemote:
{
result = CONFIG_COMMAND_ROLE_REMOTE_STR;
break;
}
}
FUNCTION_TEST_RETURN(result);
@ -523,18 +517,14 @@ cfgOptionDefaultValue(ConfigOption optionId)
switch (cfgParseOptionType(optionId))
{
case cfgOptTypeBoolean:
{
result = varNewBool(varBoolForce(defaultValue));
break;
}
case cfgOptTypeInteger:
case cfgOptTypeSize:
case cfgOptTypeTime:
{
result = varNewInt64(varInt64Force(defaultValue));
break;
}
case cfgOptTypePath:
case cfgOptTypeString:

View File

@ -597,40 +597,28 @@ sizeQualifierToMultiplier(char qualifier)
switch (qualifier)
{
case 'b':
{
result = 1;
break;
}
case 'k':
{
result = 1024;
break;
}
case 'm':
{
result = 1024 * 1024;
break;
}
case 'g':
{
result = 1024 * 1024 * 1024;
break;
}
case 't':
{
result = 1024LL * 1024LL * 1024LL * 1024LL;
break;
}
case 'p':
{
result = 1024LL * 1024LL * 1024LL * 1024LL * 1024LL;
break;
}
default:
THROW_FMT(AssertError, "'%c' is not a valid size qualifier", qualifier);

View File

@ -839,10 +839,8 @@ manifestBuildCallback(void *data, const StorageInfo *info)
// Skip special files
// -------------------------------------------------------------------------------------------------------------------------
case storageTypeSpecial:
{
LOG_WARN_FMT("exclude special file '%s/%s' from backup", strZ(buildData.pgPath), strZ(info->name));
break;
}
}
FUNCTION_TEST_RETURN_VOID();

View File

@ -141,139 +141,105 @@ main(int argListSize, const char *argList[])
// Check command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdCheck:
{
cmdCheck();
break;
}
// Expire command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdExpire:
{
cmdExpire();
break;
}
// Help command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdHelp:
case cfgCmdNone:
{
THROW(AssertError, "'help' and 'none' commands should have been handled already");
}
// Info command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdInfo:
{
cmdInfo();
break;
}
// Repository create command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdRepoCreate:
{
cmdRepoCreate();
break;
}
// Repository get file command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdRepoGet:
{
result = cmdStorageGet();
break;
}
// Repository list paths/files command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdRepoLs:
{
cmdStorageList();
break;
}
// Repository put file command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdRepoPut:
{
cmdStoragePut();
break;
}
// Repository remove paths/files command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdRepoRm:
{
cmdStorageRemove();
break;
}
// Restore command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdRestore:
{
cmdRestore();
break;
}
// Stanza create command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdStanzaCreate:
{
cmdStanzaCreate();
break;
}
// Stanza delete command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdStanzaDelete:
{
cmdStanzaDelete();
break;
}
// Stanza upgrade command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdStanzaUpgrade:
{
cmdStanzaUpgrade();
break;
}
// Start command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdStart:
{
cmdStart();
break;
}
// Stop command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdStop:
{
cmdStop();
break;
}
// Verify command
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdVerify:
{
cmdVerify();
break;
}
// Display version
// -----------------------------------------------------------------------------------------------------------------
case cfgCmdVersion:
{
printf(PROJECT_NAME " " PROJECT_VERSION "\n");
fflush(stdout);
break;
}
}
}
}

View File

@ -280,36 +280,28 @@ pgClientQuery(PgClient *this, const String *query)
{
// Boolean type
case 16: // bool
{
varLstAdd(resultRow, varNewBool(varBoolForce(varNewStrZ(value))));
break;
}
// Text/char types
case 18: // char
case 19: // name
case 25: // text
{
varLstAdd(resultRow, varNewStrZ(value));
break;
}
// Integer types
case 20: // int8
case 21: // int2
case 23: // int4
case 26: // oid
{
varLstAdd(resultRow, varNewInt64(cvtZToInt64(value)));
break;
}
default:
{
THROW_FMT(
FormatError, "unable to parse type %u in column %d for query '%s'",
columnType[columnIdx], columnIdx, strZ(query));
}
}
}
}

View File

@ -241,22 +241,16 @@ protocolParallelJobToConstZ(ProtocolParallelJobState state)
switch (state)
{
case protocolParallelJobStatePending:
{
result = "pending";
break;
}
case protocolParallelJobStateRunning:
{
result = "running";
break;
}
case protocolParallelJobStateDone:
{
result = "done";
break;
}
}
return result;

View File

@ -45,74 +45,52 @@ String *hrnPackToStr(PackRead *read)
THROW_FMT(AssertError, "invalid type %s", strZ(pckTypeToStr(type)));
case pckTypeArray:
{
pckReadArrayBeginP(read, .id = id);
strCatFmt(result, "[%s]", strZ(hrnPackToStr(read)));
pckReadArrayEndP(read);
break;
}
case pckTypeBool:
{
strCatZ(result, cvtBoolToConstZ(pckReadBoolP(read, .id = id)));
break;
}
case pckTypeBin:
{
strCatFmt(result, "%s", strZ(bufHex(pckReadBinP(read, .id = id))));
break;
}
case pckTypeI32:
{
strCatFmt(result, "%d", pckReadI32P(read, .id = id));
break;
}
case pckTypeI64:
{
strCatFmt(result, "%" PRId64, pckReadI64P(read, .id = id));
break;
}
case pckTypeObj:
{
pckReadObjBeginP(read, .id = id);
strCatFmt(result, "{%s}", strZ(hrnPackToStr(read)));
pckReadObjEndP(read);
break;
}
case pckTypePtr:
{
strCatFmt(result, "%p", pckReadPtrP(read, .id = id));
break;
}
case pckTypeStr:
{
strCatFmt(result, "%s", strZ(pckReadStrP(read, .id = id)));
break;
}
case pckTypeTime:
{
strCatFmt(result, "%" PRId64, (int64_t)pckReadTimeP(read, .id = id));
break;
}
case pckTypeU32:
{
strCatFmt(result, "%u", pckReadU32P(read, .id = id));
break;
}
case pckTypeU64:
{
strCatFmt(result, "%" PRIu64, pckReadU64P(read, .id = id));
break;
}
}
first = false;

View File

@ -368,10 +368,8 @@ void hrnServerRun(IoRead *read, HrnServerProtocol protocol, HrnServerRunParam pa
}
case hrnServerCmdDone:
{
done = true;
break;
}
case hrnServerCmdExpect:
{
@ -409,19 +407,13 @@ void hrnServerRun(IoRead *read, HrnServerProtocol protocol, HrnServerRunParam pa
}
case hrnServerCmdReply:
{
ioWrite(ioSessionIoWrite(serverSession), BUFSTR(varStr(data)));
ioWriteFlush(ioSessionIoWrite(serverSession));
break;
}
case hrnServerCmdSleep:
{
sleepMSec(varUInt64Force(data));
break;
}
}
}
while (!done);

View File

@ -110,22 +110,16 @@ hrnStorageInfoListCallback(void *callbackData, const StorageInfo *info)
}
case storageTypeLink:
{
strCatFmt(data->content, "link, d=%s", strZ(info->linkDestination));
break;
}
case storageTypePath:
{
strCatZ(data->content, "path");
break;
}
case storageTypeSpecial:
{
strCatZ(data->content, "special");
break;
}
}
if (info->type != storageTypeSpecial)

View File

@ -593,16 +593,12 @@ void hrnTestResultInt64(int64_t actual, int64_t expected, HarnessTestResultOpera
switch (operation)
{
case harnessTestResultOperationEq:
{
result = actual == expected;
break;
}
case harnessTestResultOperationNe:
{
result = actual != expected;
break;
}
}
if (!result)
@ -628,16 +624,12 @@ void hrnTestResultPtr(const void *actual, const void *expected, HarnessTestResul
switch (operation)
{
case harnessTestResultOperationEq:
{
result = actual == expected;
break;
}
case harnessTestResultOperationNe:
{
result = actual != expected;
break;
}
}
if (!result)
@ -676,16 +668,12 @@ void hrnTestResultUInt64(uint64_t actual, uint64_t expected, HarnessTestResultOp
switch (operation)
{
case harnessTestResultOperationEq:
{
result = actual == expected;
break;
}
case harnessTestResultOperationNe:
{
result = actual != expected;
break;
}
}
if (!result)
@ -729,18 +717,14 @@ void hrnTestResultZ(const char *actual, const char *expected, HarnessTestResultO
switch (operation)
{
case harnessTestResultOperationEq:
{
result = (actual == NULL && expected == NULL) || (actual != NULL && expected != NULL && strcmp(actual, expected) == 0);
break;
}
case harnessTestResultOperationNe:
{
result =
(actual == NULL && expected != NULL) || (actual != NULL && expected == NULL) ||
(actual != NULL && expected != NULL && strcmp(actual, expected) == 0);
break;
}
}
if (!result)

View File

@ -117,10 +117,8 @@ testBackupValidateCallback(void *callbackData, const StorageInfo *info)
}
case storageTypeLink:
{
strCatFmt(data->content, "link, d=%s", strZ(info->linkDestination));
break;
}
case storageTypePath:
{
@ -145,10 +143,7 @@ testBackupValidateCallback(void *callbackData, const StorageInfo *info)
}
case storageTypeSpecial:
{
THROW_FMT(AssertError, "unexpected special file '%s'", strZ(info->name));
break;
}
}
strCatZ(data->content, "}\n");

View File

@ -130,16 +130,12 @@ testResponse(IoWrite *write, TestResponseParam param)
switch (param.code)
{
case 200:
{
strCatZ(response, "OK");
break;
}
case 403:
{
strCatZ(response, "Forbidden");
break;
}
}
// End header

View File

@ -148,16 +148,12 @@ testResponse(IoWrite *write, TestResponseParam param)
switch (param.code)
{
case 200:
{
strCatZ(response, "OK");
break;
}
case 403:
{
strCatZ(response, "Forbidden");
break;
}
}
// End header