Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Step one on our way to C89
* Use int instead of bool
* Don't use "c++ style comments"

Change-Id: I1480e68971453a6aa8b920c936e1f1b7dd00c2db
Reviewed-on: http://review.couchbase.org/11624
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information
trondn authored and ingenthr committed Dec 21, 2011
1 parent 65ae533 commit 358d3c1
Show file tree
Hide file tree
Showing 38 changed files with 395 additions and 346 deletions.
34 changes: 19 additions & 15 deletions example/couchview.c
Expand Up @@ -29,7 +29,6 @@
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <inttypes.h>
Expand All @@ -44,9 +43,9 @@ static void set_flag(char cmd, const void *arg, void *cookie) {
}

static void set_char_ptr(char cmd, const void *arg, void *cookie) {
(void)cmd;
const char **myptr = cookie;
*myptr = arg;
(void)cmd;
}

const char *host = "localhost:8091";
Expand Down Expand Up @@ -74,10 +73,11 @@ static void set_auth_data(char cmd, const void *arg, void *cookie) {
}
} else {
char buffer[80];
size_t len;
if (fgets(buffer, sizeof(buffer), stdin) == NULL) {
exit(EXIT_FAILURE);
}
size_t len = strlen(buffer) - 1;
len = strlen(buffer) - 1;
while (len > 0 && isspace(buffer[len])) {
buffer[len] = '\0';
--len;
Expand All @@ -93,61 +93,61 @@ typedef void (*OPTION_HANDLER)(char cmd, const void *arg, void *cookie);
static struct {
const char *name;
const char *description;
bool argument;
int argument;
char letter;
OPTION_HANDLER handler;
void *cookie;
} my_options[256] = {
['?'] = {
.name = "help",
.description = "\t-?\t\tPrint program usage information",
.argument = false,
.argument = 0,
.letter = '?',
.handler = usage
},
['u'] = {
.name = "username",
.description = "\t-u name\t\tSpecify username",
.argument = true,
.argument = 1,
.letter = 'u',
.handler = set_auth_data
},
['h'] = {
.name = "host",
.description = "\t-h host\t\tHost to read configuration from",
.argument = true,
.argument = 1,
.letter = 'h',
.handler = set_char_ptr,
.cookie = &host
},
['b'] = {
.name = "bucket",
.description = "\t-b bucket\tThe bucket to connect to",
.argument = true,
.argument = 1,
.letter = 'b',
.handler = set_char_ptr,
.cookie = &bucket
},
['o'] = {
.name = "file",
.description = "\t-o filename\tSend the output to this file",
.argument = true,
.argument = 1,
.letter = 'o',
.handler = set_char_ptr,
.cookie = &filename
},
['c'] = {
.name = "chunked",
.description = "\t-c\t\tUse chunked callback to stream the data",
.argument = false,
.argument = 0,
.letter = 'c',
.handler = set_flag,
.cookie = &chunked
},
['d'] = {
.name = "data",
.description = "\t-d\t\tPOST data, e.g. {\"keys\": [\"key1\", \"key2\", ...]}",
.argument = true,
.argument = 1,
.letter = 'd',
.handler = set_char_ptr,
.cookie = &post_data
Expand All @@ -167,6 +167,7 @@ static void handle_options(int argc, char **argv) {
char shortopts[128] = { 0 };
int jj = 0;
int kk = 0;
int c;
for (ii = 0; ii < 256; ++ii) {
if (my_options[ii].name != NULL) {
opts[jj].name = (char*)my_options[ii].name;
Expand All @@ -180,7 +181,6 @@ static void handle_options(int argc, char **argv) {
}
}

int c;
while ((c = getopt_long(argc, argv, shortopts, opts, NULL)) != EOF) {
if (my_options[c].handler != NULL) {
my_options[c].handler((char)c, optarg, my_options[c].cookie);
Expand Down Expand Up @@ -250,6 +250,8 @@ int main(int argc, char **argv)
size_t nbytes = 0;
struct cookie_st cookie;
libcouchbase_error_t rc;
libcouchbase_t instance;

handle_options(argc, argv);

if (strcmp(filename, "-") == 0) {
Expand All @@ -273,7 +275,7 @@ int main(int argc, char **argv)
fprintf(stderr, "Failed to create IO instance\n");
return 1;
}
libcouchbase_t instance = libcouchbase_create(host, username,
instance = libcouchbase_create(host, username,
passwd, bucket, cookie.io);
if (instance == NULL) {
fprintf(stderr, "Failed to create libcouchbase instance\n");
Expand All @@ -289,7 +291,7 @@ int main(int argc, char **argv)
return 1;
}

// Wait for the connect to compelete
/* Wait for the connect to compelete */
libcouchbase_wait(instance);

bytes = post_data;
Expand All @@ -314,12 +316,14 @@ int main(int argc, char **argv)

static void usage(char cmd, const void *arg, void *cookie)
{
int ii;

(void)cmd;
(void)arg;
(void)cookie;

fprintf(stderr, "Usage: ./couchview [options] viewid\n");
for (int ii = 0; ii < 256; ++ii) {
for (ii = 0; ii < 256; ++ii) {
if (my_options[ii].name != NULL) {
fprintf(stderr, "%s\n", my_options[ii].description);
}
Expand Down
1 change: 0 additions & 1 deletion example/couchview_yajl.c
Expand Up @@ -33,7 +33,6 @@
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <inttypes.h>
Expand Down
21 changes: 10 additions & 11 deletions example/memcat.c
Expand Up @@ -22,14 +22,13 @@
* @todo add documentation
*/

// @todo figure out what I need to include for win32 in the headers!
/* @todo figure out what I need to include for win32 in the headers! */
#include "config.h"

#include <getopt.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <inttypes.h>
Expand All @@ -39,9 +38,9 @@
#ifdef WIN32
#define PRIu64 "llu"

static bool isatty(int a) {
static int isatty(int a) {
(void)a;
return true;
return 1;
}

static char *getpass(const char *prompt)
Expand Down Expand Up @@ -111,7 +110,7 @@ typedef void (*OPTION_HANDLER)(char cmd, const void *arg, void *cookie);
static struct {
const char *name;
const char *description;
bool argument;
int argument;
char letter;
OPTION_HANDLER handler;
void *cookie;
Expand All @@ -121,29 +120,29 @@ static void setup_options(void)
{
my_options['?'].name = "help";
my_options['?'].description = "\t-?\tPrint program usage information";
my_options['?'].argument = false;
my_options['?'].argument = 0;
my_options['?'].letter = '?';
my_options['?'].handler = usage;
my_options['u'].name = "username";
my_options['u'].description = "\t-u nm\tSpecify username";
my_options['u'].argument = true;
my_options['u'].argument = 1;
my_options['u'].letter = 'u';
my_options['u'].handler = set_auth_data;
my_options['h'].name = "host";
my_options['h'].description = "\t-h host\tHost to read configuration from";
my_options['h'].argument = true;
my_options['h'].argument = 1;
my_options['h'].letter = 'h';
my_options['h'].handler = set_char_ptr;
my_options['h'].cookie = &host;
my_options['b'].name = "bucket";
my_options['b'].description = "\t-b bucket\tThe bucket to connect to";
my_options['b'].argument = true;
my_options['b'].argument = 1;
my_options['b'].letter = 'b';
my_options['b'].handler = set_char_ptr;
my_options['b'].cookie = &bucket;
my_options['o'].name = "file";
my_options['o'].description = "\t-o filename\tSend the output to this file";
my_options['o'].argument = true;
my_options['o'].argument = 1;
my_options['o'].letter = 'o';
my_options['o'].handler = set_char_ptr;
my_options['o'].cookie = &filename;
Expand Down Expand Up @@ -281,7 +280,7 @@ int main(int argc, char **argv)
libcouchbase_strerror(instance, ret));
return 1;
}
// Wait for the connect to compelete
/* Wait for the connect to compelete */
libcouchbase_wait(instance);

(void)libcouchbase_set_get_callback(instance, get_callback);
Expand Down

0 comments on commit 358d3c1

Please sign in to comment.