- luaclient: formatting code using astyle

This commit is contained in:
vanhofen
2023-01-31 23:34:11 +01:00
committed by Thilo Graf
parent b56159bbf8
commit 884a69c3f9
2 changed files with 23 additions and 16 deletions

View File

@@ -30,15 +30,15 @@
class CLuaClient : private CBasicClient class CLuaClient : private CBasicClient
{ {
private: private:
unsigned char getVersion () const { return LUACLIENT_VERSION; }; unsigned char getVersion() const { return LUACLIENT_VERSION; };
const char * getSocketName() const { return LUACLIENT_UDS_NAME; }; const char *getSocketName() const { return LUACLIENT_UDS_NAME; };
public: public:
bool Send(const char *data, const size_t size) { return send(0, data, size);} bool Send(const char *data, const size_t size) { return send(0, data, size);}
bool Recv(char *data, const size_t size) { return receive_data(data, size, true); } bool Recv(char *data, const size_t size) { return receive_data(data, size, true); }
~CLuaClient() { close_connection(); } ~CLuaClient() { close_connection(); }
}; };
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
char *cmd = strrchr(argv[0], '/'); char *cmd = strrchr(argv[0], '/');
if (cmd) if (cmd)
@@ -48,7 +48,8 @@ int main(int argc, char** argv)
if (!strcmp(cmd, "luaclient")) if (!strcmp(cmd, "luaclient"))
argv++, argc--; argv++, argc--;
if (!*argv) { if (!*argv)
{
fprintf(stderr, fprintf(stderr,
"Usage: luaclient [command [arguments ...]]\n" "Usage: luaclient [command [arguments ...]]\n"
" or: command [arguments ...] (with command being a link to luaclient)\n"); " or: command [arguments ...] (with command being a link to luaclient)\n");
@@ -57,7 +58,8 @@ int main(int argc, char** argv)
size_t len[argc]; size_t len[argc];
size_t size = 0; size_t size = 0;
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++)
{
len[i] = strlen(argv[i]) + 1; len[i] = strlen(argv[i]) + 1;
size += len[i]; size += len[i];
} }
@@ -67,7 +69,8 @@ int main(int argc, char** argv)
memcpy(b, &size, sizeof(size)); memcpy(b, &size, sizeof(size));
size += sizeof(size); size += sizeof(size);
b += sizeof(size); b += sizeof(size);
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++)
{
memcpy(b, argv[i], len[i]); memcpy(b, argv[i], len[i]);
b += len[i]; b += len[i];
} }
@@ -78,23 +81,27 @@ int main(int argc, char** argv)
char *resp = NULL; char *resp = NULL;
char *result = NULL; char *result = NULL;
if (!client.Send(data, size)) { if (!client.Send(data, size))
{
fun = "Send failed"; fun = "Send failed";
goto fail; goto fail;
} }
if (!client.Recv((char *)&size, sizeof(size))) { if (!client.Recv((char *)&size, sizeof(size)))
{
fun = "Recv (1) failed"; fun = "Recv (1) failed";
goto fail; goto fail;
} }
if(size) if (size)
result = (char*) malloc(size); result = (char *) malloc(size);
if (result && !client.Recv(result, size)) { if (result && !client.Recv(result, size))
{
fun = "Recv (2) failed"; fun = "Recv (2) failed";
goto fail; goto fail;
} }
if (result[size - 1]) { if (result[size - 1])
{
fun = "unterminated result"; fun = "unterminated result";
goto fail; goto fail;
} }
@@ -105,11 +112,11 @@ int main(int argc, char** argv)
resp += strlen(resp) + 1; resp += strlen(resp) + 1;
if (resp < result + size) if (resp < result + size)
fprintf(stderr, "%s", resp); fprintf(stderr, "%s", resp);
if(result) if (result)
free(result); free(result);
exit(res); exit(res);
fail: fail:
if(result) if (result)
free(result); free(result);
if (fun) if (fun)
fprintf(stderr, "luaclient: %s.\n", fun); fprintf(stderr, "luaclient: %s.\n", fun);

View File

@@ -20,6 +20,6 @@
#ifndef __LUACLIENT__H__ #ifndef __LUACLIENT__H__
#define __LUACLIENT__H__ #define __LUACLIENT__H__
#define LUACLIENT_UDS_NAME "/tmp/luaclient.sock" #define LUACLIENT_UDS_NAME "/tmp/luaclient.sock"
#define LUACLIENT_VERSION 1 #define LUACLIENT_VERSION 1
#endif #endif