Skip to content

Commit

Permalink
Attack of whitespace pedantry
Browse files Browse the repository at this point in the history
pgsql conventions (tabs, four-spaces-wide, etc) applied all around.

Also tried to fix some very tiny capitalization errors, auto-fill
problems, and some inter-block vertical whitespacing issues.

Long strings in repmgr.c were left intact, though. They are rather
numerous and are less of a problem than tiny bits of function calls
and comments wrapping over a line; the latter kind of problem has been
mostly fixed.

Signed-off-by: Dan Farina <drfarina@acm.org>
Signed-off-by: Peter van Hardenberg <pvh@heroku.com>
  • Loading branch information
Dan Farina authored and Peter van Hardenberg committed Dec 21, 2010
1 parent 56c65ac commit af2edf1
Show file tree
Hide file tree
Showing 8 changed files with 947 additions and 857 deletions.
88 changes: 44 additions & 44 deletions check_dir.c
Expand Up @@ -31,63 +31,63 @@ static int mkdir_p(char *path, mode_t omode);
int
check_dir(char *dir)
{
DIR *chkdir;
struct dirent *file;
int result = 1;

errno = 0;

chkdir = opendir(dir);

if (!chkdir)
return (errno == ENOENT) ? 0 : -1;

while ((file = readdir(chkdir)) != NULL)
{
if (strcmp(".", file->d_name) == 0 ||
strcmp("..", file->d_name) == 0)
{
/* skip this and parent directory */
continue;
}
else
{
result = 2; /* not empty */
break;
}
}
DIR *chkdir;
struct dirent *file;
int result = 1;

errno = 0;

chkdir = opendir(dir);

if (!chkdir)
return (errno == ENOENT) ? 0 : -1;

while ((file = readdir(chkdir)) != NULL)
{
if (strcmp(".", file->d_name) == 0 ||
strcmp("..", file->d_name) == 0)
{
/* skip this and parent directory */
continue;
}
else
{
result = 2; /* not empty */
break;
}
}

#ifdef WIN32
/*
* This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in
* released version
*/
if (GetLastError() == ERROR_NO_MORE_FILES)
errno = 0;
/*
* This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in
* released version
*/
if (GetLastError() == ERROR_NO_MORE_FILES)
errno = 0;
#endif

closedir(chkdir);
closedir(chkdir);

if (errno != 0)
return -1; /* some kind of I/O error? */
if (errno != 0)
return -1; /* some kind of I/O error? */

return result;
}


/*
* Create directory
* Create directory
*/
bool
create_directory(char *dir)
{
if (mkdir_p(dir, 0700) == 0)
return true;
if (mkdir_p(dir, 0700) == 0)
return true;

fprintf(stderr, _("Could not create directory \"%s\": %s\n"),
dir, strerror(errno));
fprintf(stderr, _("Could not create directory \"%s\": %s\n"),
dir, strerror(errno));

return false;
return false;
}

bool
Expand All @@ -114,10 +114,10 @@ mkdir_p(char *path, mode_t omode)
{
struct stat sb;
mode_t numask,
oumask;
oumask;
int first,
last,
retval;
last,
retval;
char *p;

p = path;
Expand Down Expand Up @@ -212,5 +212,5 @@ is_pg_dir(char *dir)

sprintf(path, "%s/PG_VERSION", dir);

return (stat(path, &sb) == 0) ? true : false;
return (stat(path, &sb) == 0) ? true : false;
}
66 changes: 34 additions & 32 deletions config.c
Expand Up @@ -8,60 +8,62 @@
#include "repmgr.h"

void
parse_config(const char *config_file, char *cluster_name, int *node, char *conninfo)
parse_config(const char *config_file, char *cluster_name, int *node,
char *conninfo)
{
char *s, buff[256];
FILE *fp = fopen (config_file, "r");

if (fp == NULL)
return;
return;

/* Read next line */
while ((s = fgets (buff, sizeof buff, fp)) != NULL)
{
char name[MAXLEN];
char value[MAXLEN];

/* Skip blank lines and comments */
if (buff[0] == '\n' || buff[0] == '#')
continue;
/* Skip blank lines and comments */
if (buff[0] == '\n' || buff[0] == '#')
continue;

/* Parse name/value pair from line */
/* Parse name/value pair from line */
parse_line(buff, name, value);

/* Copy into correct entry in parameters struct */
if (strcmp(name, "cluster") == 0)
strncpy (cluster_name, value, MAXLEN);
else if (strcmp(name, "node") == 0)
*node = atoi(value);
else if (strcmp(name, "conninfo") == 0)
strncpy (conninfo, value, MAXLEN);
else
printf ("WARNING: %s/%s: Unknown name/value pair!\n", name, value);
}
/* Copy into correct entry in parameters struct */
if (strcmp(name, "cluster") == 0)
strncpy (cluster_name, value, MAXLEN);
else if (strcmp(name, "node") == 0)
*node = atoi(value);
else if (strcmp(name, "conninfo") == 0)
strncpy (conninfo, value, MAXLEN);
else
printf("WARNING: %s/%s: Unknown name/value pair!\n",
name, value);
}

/* Close file */
fclose (fp);
/* Close file */
fclose (fp);
}

char *
trim (char *s)
{
/* Initialize start, end pointers */
char *s1 = s, *s2 = &s[strlen (s) - 1];
/* Initialize start, end pointers */
char *s1 = s, *s2 = &s[strlen (s) - 1];

/* Trim and delimit right side */
while ( (isspace (*s2)) && (s2 >= s1) )
s2--;
*(s2+1) = '\0';
/* Trim and delimit right side */
while ( (isspace (*s2)) && (s2 >= s1) )
s2--;
*(s2+1) = '\0';

/* Trim left side */
while ( (isspace (*s1)) && (s1 < s2) )
s1++;
/* Trim left side */
while ( (isspace (*s1)) && (s1 < s2) )
s1++;

/* Copy finished string */
strcpy (s, s1);
return s;
/* Copy finished string */
strcpy (s, s1);
return s;
}

void
Expand All @@ -86,7 +88,7 @@ parse_line(char *buff, char *name, char *value)
i++;
/*
* Now the value
*/
*/
j = 0;
for ( ; i < MAXLEN; i++)
if (buff[i] == '\'')
Expand All @@ -96,5 +98,5 @@ parse_line(char *buff, char *name, char *value)
else
break;
value[j] = '\0';
trim(value);
trim(value);
}
3 changes: 2 additions & 1 deletion config.h
Expand Up @@ -4,6 +4,7 @@
*
*/

void parse_config(const char *config_file, char *cluster_name, int *node, char *service);
void parse_config(const char *config_file, char *cluster_name, int *node,
char *service);
void parse_line(char *buff, char *name, char *value);
char *trim(char *s);

0 comments on commit af2edf1

Please sign in to comment.