Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'format' target #2

Merged
merged 1 commit into from
Apr 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BasedOnStyle: Google
AllowShortFunctionsOnASingleLine: false
SpaceAfterCStyleCast: true
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ SOURCES = src/main.c \
src/dependencies/krypton.c
BINARY = sj

CLANG_FORMAT:=clang-format

# installable with: `brew install llvm36 --with-clang`
ifneq ("$(wildcard /usr/local/bin/clang-format-3.6)","")
CLANG_FORMAT:=/usr/local/bin/clang-format-3.6
endif

# TODO(lsm): reuse established test infrastructure as we move to a dev repo
all: $(BINARY) unit_test
./unit_test
Expand All @@ -32,3 +39,6 @@ w:

clean:
rm -rf $(BINARY) *.exe *.obj *.o *.dSYM unit_test

format:
/usr/bin/find src test -name "*.[ch]" | grep -v 'src/dependencies' | xargs $(CLANG_FORMAT) -i
5 changes: 2 additions & 3 deletions src/api_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ static unsigned char from_b64(unsigned char ch) {
return tab[ch & 127];
}


static void base64_decode(const unsigned char *s, int len, char *dst) {
unsigned char a, b, c, d;
while (len >= 4 && (a = from_b64(s[0])) != 255 &&
Expand Down Expand Up @@ -97,12 +96,12 @@ static v7_val_t b64_transform(struct v7 *v7, v7_val_t this_obj, v7_val_t args,
}

static v7_val_t Crypto_base64_decode(struct v7 *v7, v7_val_t this_obj,
v7_val_t args) {
v7_val_t args) {
return b64_transform(v7, this_obj, args, base64_decode, 0.75);
}

static v7_val_t Crypto_base64_encode(struct v7 *v7, v7_val_t this_obj,
v7_val_t args) {
v7_val_t args) {
return b64_transform(v7, this_obj, args, base64_encode, 1.5);
}

Expand Down
11 changes: 7 additions & 4 deletions src/api_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ static v7_val_t Socket_send(struct v7 *v7, v7_val_t this_obj, v7_val_t args) {
* JS: Socket.connect(addr, port)
* Ex: var x = new Socket(); x.connect("www.hello.com",80);
*/
static v7_val_t Socket_connect(struct v7 *v7, v7_val_t this_obj, v7_val_t args) {
static v7_val_t Socket_connect(struct v7 *v7, v7_val_t this_obj,
v7_val_t args) {
struct socket_internal *si = Socket_get_si(v7, this_obj);
char addr[ADDRESS_BUF_SIZE] = {0};
union socket_address sa;
Expand Down Expand Up @@ -495,7 +496,7 @@ static int Socket_get_recvtype(struct socket_internal *si, struct v7 *v7,
}

static v7_val_t Socket_get_retdata(struct v7 *v7, int recvtype, char *buf,
size_t buf_size) {
size_t buf_size) {
if (recvtype == RECVTYPE_STRING) {
return v7_create_string(v7, buf, buf_size, 1);
} else if (recvtype == RECVTYPE_RAW) {
Expand Down Expand Up @@ -581,7 +582,8 @@ static int Socket_sa_split(union socket_address *sa, int *family, char *addr,
* Object.src.port: originator’s port
* Object.src.family : address family
*/
static v7_val_t Socket_recvfrom(struct v7 *v7, v7_val_t this_obj, v7_val_t args) {
static v7_val_t Socket_recvfrom(struct v7 *v7, v7_val_t this_obj,
v7_val_t args) {
struct socket_internal *si = Socket_get_si(v7, this_obj);
char recv_buf[RECV_BUF_SIZE] = {0};
long bytes_received;
Expand Down Expand Up @@ -668,7 +670,8 @@ static v7_val_t Socket_accept(struct v7 *v7, v7_val_t this_obj, v7_val_t args) {
}

#define SOCKET_DEF_PROP(name, func, retval, error) \
static v7_val_t Socket_##name(struct v7 *v7, v7_val_t this_obj, v7_val_t args) { \
static v7_val_t Socket_##name(struct v7 *v7, v7_val_t this_obj, \
v7_val_t args) { \
struct socket_internal *si = Socket_get_si(v7, this_obj); \
union socket_address sa; \
unsigned int sa_len = sizeof(sa); \
Expand Down