From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
---|---|
To: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
Cc: | Postgresql Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: new initdb.c available |
Date: | 2003-10-06 23:18:16 |
Message-ID: | Pine.LNX.4.44.0310070054490.17902-100000@peter.localdomain |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-hackers-win32 |
Andrew Dunstan writes:
> New version has passed basic Windows tests, and is available (with new
> Makefile too) at http://www.dunslane.net/~andrew/Initdb_In_C.html
>
> constructive comments (very) welcome.
That looks very nice. Just some nitpicking comments. (Most of these
comments should be extrapolated to similar source code fragments.)
> #include <getopt_long.h>
Must be "getopt_long.h" because it might be our own replacement file.
> #include <sys/types.h>
Already done in c.h.
> /* who we are */
> #define PG_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
Should be "initdb (PostgreSQL) ...".
> #define WRITEMODE "wb"
Use #define PG_BINARY_W "wb", if you are writing "binary" files, which
isn't quite clear.
> /*
> * macros for running pipes to postgres
> * note lack of trailing ';' must be placed there when macros are used.
> * this keeps emacs indentation happy
> */
>
> #define PG_CMD_DECL char cmd[MAXPGPATH]; char ** line ; FILE * pg
Use
#define MACRO do { code; here; } while(0)
That's the standard mechanism.
> #endif
Write "#endif /* WIN32 */", or whatever the case may be.
> #define malloc(x) xmalloc( (x) )
You are not allowed to redefine or otherwise fiddle with standard library
functions. Just write xmalloc when you mean xmalloc.
> if (strcmp(file->d_name,".") && strcmp(file->d_name,".."))
Please compare the result of strcmp() with 0. Code like this makes my
brain hurt. Do
#define streq(a, b) (strcmp((a), (b))==0)
if you must.
> snprintf(filepath,MAXPGPATH,"%s/%s",path,*filename);
Spaces after the commas. Spaces after semicolons. Spaces before and
after binary operators. More spaces everywhere.
> static char *
> pg_getlocale(char * arg)
This is redundant. In C you can just use, for example,
locale = setlocale(LC_CTYPE, NULL);
This is actually one of the nice things we'll get out of having this in C.
> sizeof(char)
... is always 1.
> newtext = replace_token(usage_text,"$CMDNAME",progname);
>
> for (i=0; newtext[i]; i++)
> fputs(newtext[i],stdout);
Uh, why not use printf directly?
> if (show_version)
> {
> printf("%s (PostgreSQL) %s\n",argv[0],PG_VERSION);
> exit(0);
> }
For the --version output, the program name is always hardcoded, to allow
identification in case the program was renamed.
> if (!mkdatadir(NULL))
> {
> exit_nicely();
> }
> else
> check_ok();
Bizarre use of braces.
--
Peter Eisentraut peter_e(at)gmx(dot)net
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2003-10-07 00:04:01 | Re: new initdb.c available |
Previous Message | Bruce Momjian | 2003-10-06 23:17:22 | Re: Disabling function validation |
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2003-10-07 00:04:01 | Re: new initdb.c available |
Previous Message | Andrew Dunstan | 2003-10-06 22:32:02 | new initdb.c available |