diff -ruN klic-3.003-2001-11-22/compiler/klic.c klic-3.003-2001-11-23/compiler/klic.c
--- klic-3.003-2001-11-22/compiler/klic.c	Wed Nov 21 11:26:12 2001
+++ klic-3.003-2001-11-23/compiler/klic.c	Fri Nov 23 21:43:16 2001
@@ -18,81 +18,82 @@
 #ifdef USELOCKF
 #include <fcntl.h>
 #endif
+#include <assert.h>
 
 #define KL1_TO_C_COMPILER   KLIC_COMPILER
 
-extern void *malloc();
+extern void* malloc();
 
 enum filetype { kl1_file, prog_file, asm_file, obj_file, other_file };
 
 struct lang_info {
-  char *ext;
-  char *comp_env;
-  char *comp_default;
-  char *comp;
-  char *comp_opt_env;
-  char *comp_opt_default;
-  char *comp_opt;
-  char *ld_env;
-  char *ld_default;
-  char *ld;
-  char *ld_opt_env;
-  char *ld_opt_default;
-  char *ld_opt;
+  char* ext;
+  char* comp_env;
+  char* comp_default;
+  char* comp;
+  char* comp_opt_env;
+  char* comp_opt_default;
+  char* comp_opt;
+  char* ld_env;
+  char* ld_default;
+  char* ld;
+  char* ld_opt_env;
+  char* ld_opt_default;
+  char* ld_opt;
   int prio;
-} lang_infos[] = {
-  /* CAUTION ! The 1st definition must be for C.*/
-  ".c",
-  "KLIC_CC",
-  CC,
-  0,
-  "KLIC_CC_OPTIONS",
-  KLIC_CC_OPTIONS,
-  0,
-  "KLIC_LD",
-  LD,
-  0,
-  "KLIC_LD_OPTIONS",
-  KLIC_LD_OPTIONS,
-  0,
-  0,
+};
+
+static struct lang_info lang_infos[] = {
+  /* CAUTION ! The 1st definition must be for C. */
+  { ".c",
+    "KLIC_CC",
+    CC,
+    NULL,
+    "KLIC_CC_OPTIONS",
+    KLIC_CC_OPTIONS,
+    NULL,
+    "KLIC_LD",
+    LD,
+    NULL,
+    "KLIC_LD_OPTIONS",
+    KLIC_LD_OPTIONS,
+    NULL,
+    0 },
 #ifdef KLIC_FORT
   /* Fortran */
-  ".f",
-  "KLIC_FORT",
-  KLIC_FORT,
-  0,
-  "KLIC_FORT_OPTIONS",
-  KLIC_FORT_OPTIONS,
-  0,
-  "KLIC_FORT_LD",
-  KLIC_FORT_LD,
-  0,
-  "KLIC_FORT_LD_OPTIONS",
-  KLIC_FORT_LD_OPTIONS,
-  0,
-  1,
+  { ".f",
+    "KLIC_FORT",
+    KLIC_FORT,
+    NULL,
+    "KLIC_FORT_OPTIONS",
+    KLIC_FORT_OPTIONS,
+    NULL,
+    "KLIC_FORT_LD",
+    KLIC_FORT_LD,
+    NULL,
+    "KLIC_FORT_LD_OPTIONS",
+    KLIC_FORT_LD_OPTIONS,
+    NULL,
+    1 },
 #endif
-  /* Do not remove the following one line. It's a `end mark'' */
-  0,
-};
+  /* Do not remove the following one line. It's a `end mark' */
+  { NULL } };
 
-struct lang_info * const c_info = lang_infos;
-struct lang_info * pref_info = lang_infos;
+static struct lang_info* const c_info = lang_infos;
+static struct lang_info* pref_info = lang_infos;
 
 struct namerec {
-  struct namerec *next;
+  struct namerec* next;
   enum filetype type;
-  char *name;
-  struct lang_info *info;
+  char* name;
+  struct lang_info* info;
 };
 
-static void
-initialize_lang_info(void)
+static void initialize_lang_info(void)
 {
-  extern char *option_value();
-  struct lang_info *info = lang_infos;
-  for(; info->ext; ++info) {
+  extern char* option_value();
+  struct lang_info* info;
+  for(info = lang_infos; info->ext != NULL; ++info) {
     info->comp = option_value(info->comp_env, info->comp_default);
     info->comp_opt = option_value(info->comp_opt_env, info->comp_opt_default);
     info->ld = option_value(info->ld_env, info->ld_default);
@@ -100,27 +101,25 @@
   }
 }
 
-static struct lang_info*
-search_lang_info(suffix)
-     char *suffix;
+static struct lang_info* search_lang_info(
+  char* suffix )
 {
   int i;
-  struct lang_info *info = lang_infos;
-  for(; info->ext; ++info) {
+  struct lang_info* info;
+  for(info = lang_infos; info->ext != NULL; ++info) {
     if(strcmp(info->ext, suffix) == 0) {
       return info;
     }
   }
-  return 0;
+  return NULL;
 }
 
-static void reverse_names(names)
-     struct namerec **names;
+static void reverse_names(
+  struct namerec** names )
 {
-  struct namerec *one, *next;
-  next = *names;
-  one = 0;
-  while (next != 0) {
+  struct namerec* one = NULL;
+  struct namerec* next = *names;
+  while (next != NULL) {
     struct namerec *last = one;
     one = next;
     next = one->next;
@@ -129,32 +128,38 @@
   *names = one;
 }
 
-static void error_exit(format, arg)
-     char *format, *arg;
+static void error_exit(
+  char* format,
+  char* arg )
 {
-  (void)fprintf(stderr, format, arg);
+  (void) fprintf(stderr, format, arg);
   putc('\n', stderr);
   exit(-1);
 }
 
-static void sync_and_exit()
+static void sync_and_exit(void)
 {
   int status;
-  while (wait(&status) >= 0 || errno != ECHILD)
-    ;
-  exit(1);
+  for(;;)
+    if(wait(&status) < 0 && errno==ECHILD)
+      exit(1);
 }
 
-static void usage_error(cmd)
-     char *cmd;
+
+#define USAGE  "Usage: %s -options files ...\n"
+
+static void usage_error(
+  char* cmd )
 {
-  error_exit("Usage: %s -options files ...\nSpecify -h option for help", cmd);
+  error_exit(
+    USAGE "Specify -h option for help",
+    cmd );
 }
 
-static void usage_help(cmd)
-     char *cmd;
+static void usage_help(
+  char* cmd )
 {
-  fprintf(stderr, "Usage: %s -options files ...\n", cmd);
+  fprintf(stderr, USAGE, cmd);
   fprintf(stderr, "Options available are:\n");
   fprintf(stderr, "  -c: no link; only compile to .o\n");
   fprintf(stderr, "  -C: no C compilation; only compile to .c\n");
@@ -181,15 +186,15 @@
   fprintf(stderr, "  -X initdbdir: specifies database initiation directory\n");
 }
 
-static void access_error(file)
-     char *file;
+static void access_error(
+  char* file )
 {
   error_exit("Can't access file %s", file);
 }
 
-static void get_stat(file, st)
-     char *file;
-     struct stat *st;
+static void get_stat(
+  char* file,
+  struct stat* st )
 {
   if (stat(file, st) != 0) {
     access_error(file);
@@ -198,65 +203,68 @@
 
 /* Options */
 
-char distklic = 0;  /***** added for klicdist *****/
-char shmklic = 0;  /***** added for klicshm *****/
+static char distklic = 0;  /***** added for klicdist *****/
+static char shmklic = 0;  /***** added for klicshm *****/
 
-char *ofile = 0;
-int optlevel = 0;
-char *optflags;
-char debug = 1;
-char cdebug = 0;
-char *cc_profile_flag = "";
-char *link_profile_flag = "";
-char verbose = 0;
-char no_link = 0;
-char no_cc = 0;
-char make_asm = 0;
-char dryrun = 0;
-char do_recompile = 0;
-char *dbdir = 0;
-int parallelism = 0;
-int forked = 0;
-char *forced_linker = 0;
-char *forced_linker_opt = 0;
-
-char *initdbdir;
-char *klic_compiler;
-char *klic_dbmaker;
-char *klic_libdir;
-char *klic_incdir;
-char *klic_cc;
-char *klic_cc_options;
-
-struct namerec *files = 0;
-struct namerec *incdirs = 0;
-struct namerec *libraries = 0;
-struct namerec *libdirs = 0;
-
-char buf[BUFSIZE];
-time_t inittime;
-
-static void exec_command(msg, info, garbage)
-     char *msg;
-     char *info;
-     void (*garbage)();
+static char* ofile = NULL;
+static int optlevel = 0;
+static char* optflags;
+static char debug = 1;
+static char cdebug = 0;
+static char* cc_profile_flag = "";
+static char* link_profile_flag = "";
+static char verbose = 0;
+static char no_link = 0;
+static char no_cc = 0;
+static char make_asm = 0;
+static char dryrun = 0;
+static char do_recompile = 0;  /* -R option forces to recompile */
+static char* dbdir = NULL;
+static int parallelism = 0;
+static int forked = 0;
+static char* forced_linker = NULL;
+static char* forced_linker_opt = NULL;
+
+static char* initdbdir;
+static char* klic_compiler;
+static char* klic_dbmaker;
+static char* klic_libdir;
+static char* klic_incdir;
+static char* klic_cc;
+static char* klic_cc_options;
+
+static struct namerec* files = NULL;
+static struct namerec* incdirs = NULL;
+static struct namerec* libraries = NULL;
+static struct namerec* libdirs = NULL;
+
+static char buf[BUFSIZE];
+static time_t inittime;
+
+static void exec_command(
+  char* msg,
+  char* info,
+  void (* garbage)() )
 {
   if (verbose) {
-    (void)fputs(buf, stderr);
-    (void)putc('\n', stderr);
+    (void) fputs(buf, stderr);
+    (void) putc('\n', stderr);
   }
-  if (!dryrun) {
-    if (parallelism == 0) {
-      if (system(buf) != 0) {
-	(void)fprintf(stderr, msg, info);
-	(void)putc('\n', stderr);
+
+  if(dryrun) return;
+
+  assert(!dryrun);
+  if (parallelism == 0) {
+    if (system(buf) != 0) {
+	(void) fprintf(stderr, msg, info);
+	(void) putc('\n', stderr);
 	garbage(info);
 	exit(1);
-      }
-    } else {
-      pid_t child;
+    }
+  } else {
+    pid_t child;
 
-      if (forked >= parallelism) {
+    if (forked >= parallelism) {
 	int status;
 	while (1) {
 	  pid_t wait_result = wait(&status);
@@ -271,24 +279,24 @@
 	  }
 	}
 	forked--;
-      }
+    }
 
-      if ((child = fork()) != 0) {
+    child = fork();
+    if (child != 0) {
 	forked++;
 	return;
-      } else if (system(buf) != 0) {
-	(void)fprintf(stderr, msg, info);
-	(void)putc('\n', stderr);
+    } else if (system(buf) != 0) {
+	(void) fprintf(stderr, msg, info);
+	(void) putc('\n', stderr);
 	garbage(info);
 	exit(1);
-      } else {
+    } else {
 	exit(0);
-      }
     }
   }
 }
 
-static void sync_with_subtasks()
+static void sync_with_subtasks(void)
 {
   int status;
   while (wait(&status) >= 0) {
@@ -299,13 +307,13 @@
   }
 }
 
-static char *make_path(name)
-     char *name;
+static char* make_path(
+  char* name )
 {
-  char *path;
-  if (dbdir != 0) {
-    path = (char *)malloc(strlen(dbdir)+strlen(name)+2);
-    (void)sprintf(path, "%s/%s", dbdir, name);
+  char* path;
+  if (dbdir != NULL) {
+    path = (char*) malloc(strlen(dbdir) + 1 + strlen(name) + 1);
+    (void) sprintf(path, "%s/%s", dbdir, name);
   } else {
     path = name;
   }
@@ -313,44 +321,48 @@
 }
 
 /* Cleaning after commmand failure */
-static void delete_file(file, prefix, suffix)
-     char *file, *prefix, *suffix;
+static void delete_file(
+  char* file,
+  char* prefix,
+  char* suffix )
 {
-  buf[0] = 0;
-  (void)sprintf(buf, "%s%s%s%s%s",
-		(prefix ? prefix : ""), (prefix ? "/" : ""),
-		file,
-		(suffix ? "." : ""), (suffix ? suffix : ""));
-  if (unlink(buf) == 0) (void)fprintf(stderr, "%s removed\n", buf);
+  buf[0] = '\0';
+  (void) sprintf(buf, "%s%s%s%s",
+    (prefix != NULL ? prefix : ""),
+    (prefix != NULL ? "/" : ""),
+    file,
+    (suffix != NULL ? suffix : ""));
+  if (unlink(buf) == 0)
+    (void) fprintf(stderr, "%s removed\n", buf);
 }
 
-static void failed_kl1c(file)
-     char *file;
+static void failed_kl1c(
+  char* file )
 {
-  delete_file(file, 0, "c");
-  delete_file(file, 0, "ext");
+  delete_file(file, NULL, ".c");
+  delete_file(file, NULL, ".ext");
 }
 
-static void failed_makedb(dbdir)
-     char *dbdir;
+static void failed_makedb(
+  char *dbdir )
 {
-  delete_file("atom", 0, "h");
-  delete_file("funct", 0, "h");
-  delete_file("atom", dbdir, "c");
-  delete_file("funct", dbdir, "c");
+  delete_file("atom", NULL, ".h");
+  delete_file("funct", NULL, ".h");
+  delete_file("atom", dbdir, ".c");
+  delete_file("funct", dbdir, ".c");
 }
 
-static void noop(dummy)
-     char *dummy;
-{}
+static void noop(
+  char* dummy )
+{
+}
 
-static void guess_linker()
+/* Decide what linker to use */
+static void guess_linker(void)
 {
-  /* Decide what linker to use */
-  struct namerec *f = files;
   int prio = -1;
-
-  for(; f != 0; f = f->next) {
+  struct namerec* f;
+  for(f = files; f != NULL; f = f->next) {
     if(f->type == prog_file) {
       if(prio < f->info->prio) {
 	pref_info = f->info;
@@ -360,155 +372,174 @@
   }
 }
 
-static void kl1_to_c()
+static void kl1_to_c(void)
 {
-  struct namerec *f = files;
-
-  while (f != 0) {
+  struct namerec* f;
+  for(f = files; f != NULL; f = f->next) {
     if (f->type == kl1_file) {
       int recompile = 0;
       struct stat kl1_stat, c_stat, ext_stat;
-      (void)sprintf(buf, "%s.kl1", f->name);
+
+      if(do_recompile) {
+        recompile = 1;
+        goto COMPILE;
+      }
+
+      (void) sprintf(buf, "%s.kl1", f->name);
       get_stat(buf, &kl1_stat);
-      (void)sprintf(buf, "%s.c", f->name);
-      if (do_recompile ||
-	  stat(buf, &c_stat) != 0 ||
+
+      (void) sprintf(buf, "%s.c", f->name);
+      if (stat(buf, &c_stat) != 0 ||
 	  kl1_stat.st_mtime > c_stat.st_mtime) {
 	recompile = 1;
-      } else {
-	(void)sprintf(buf, "%s.kl1", f->name);
-	if (do_recompile ||
-	    stat(buf, &ext_stat) != 0 ||
-	    kl1_stat.st_mtime > ext_stat.st_mtime) {
-	  recompile = 1;
-	}
+	goto COMPILE;
+      }
+
+      (void) sprintf(buf, "%s.ext", f->name);
+      if (stat(buf, &ext_stat) != 0 ||
+          kl1_stat.st_mtime > ext_stat.st_mtime) {
+        recompile = 1;
+	goto COMPILE;
       }
+
+    COMPILE:
       if (recompile) {
-	(void)sprintf(buf, "%s %s.kl1 </dev/null", klic_compiler, f->name);
+	(void) sprintf(buf, "%s %s.kl1 </dev/null", klic_compiler, f->name);
 	exec_command("KL1 to C translation failed for %s",
 		     f->name, failed_kl1c);
       }
       f->type = prog_file;
       f->info = c_info;
     }
-    f = f->next;
   }
+  assert(f == NULL);
 }
 
-make_database()
+static void make_database(void)
 {
-  struct namerec *f;
+  struct namerec* f;
   struct stat initstat;
   int makedb = 0;
-  (void)sprintf(buf, "%s%sklicdb.init",
-		(initdbdir ? initdbdir : ""),
-		(initdbdir ? "/" : ""));
+
+  (void) sprintf(buf, "%s%s" "klicdb.init",
+    (initdbdir != NULL ? initdbdir : ""),
+    (initdbdir != NULL ? "/" : ""));
   get_stat(buf, &initstat);
   inittime = initstat.st_mtime;
-  (void)sprintf(buf, "%s %s%s%s%s%s%s",
-		klic_dbmaker,
-		(no_cc ? " -n" : ""), (no_link ? " -c" : ""),
-		(initdbdir ? " -X " : ""), (initdbdir ? initdbdir : ""),
-		(dbdir ? " -x " : ""), (dbdir ? dbdir : ""));
-  for (f = files; f != 0; f = f->next) {
+
+  (void) sprintf(buf, "%s" "%s" "%s" "%s%s" "%s%s",
+    klic_dbmaker,
+    (no_cc ? " -C" : ""),
+    (no_link ? " -c" : ""),
+    (initdbdir != NULL ? " -X " : ""), (initdbdir != NULL ? initdbdir : ""),
+    (dbdir != NULL ? " -x " : ""), (dbdir != NULL ? dbdir : "") );
+
+  for (f = files; f != NULL; f = f->next) {
     char xbuf[BUFSIZE];
-    (void)sprintf(xbuf, "%s.ext", f->name);
+    (void) sprintf(xbuf, "%s.ext", f->name);
     if (access(xbuf, F_OK) == 0) {
       makedb = 1;
-      (void)strcat(buf, " ");
-      (void)strcat(buf, xbuf);
+      (void) strcat(buf, " ");
+      (void) strcat(buf, xbuf);
     }
   }
+  assert(f == NULL);
+
   if (makedb || !no_cc) {
     exec_command("Atom/functor database merging failed",
 		 dbdir, failed_makedb);
   }
 }
 
-static void
-compile_c_file(name, inf, masm)
-     char *name;
-     struct lang_info *inf;
-     int masm;
+static void compile_c_file(
+  char* name,
+  struct lang_info* inf,
+  int masm )
 {
   int recompile;
   char suffix = (masm ? 's' : 'o');
-  char *bufp;
+  char* bufp;
   struct stat c_stat, o_stat;
 
-  (void)sprintf(buf, "%s%s", name, inf->ext);
+  (void) sprintf(buf, "%s%s", name, inf->ext);
   get_stat(buf, &c_stat);
-  (void)sprintf(buf, "%s.%c", name, suffix);
+
+  (void) sprintf(buf, "%s.%c", name, suffix);
   recompile =
     (do_recompile ||
      stat(buf, &o_stat) != 0 ||
      c_stat.st_mtime >= o_stat.st_mtime ||
      inittime >= o_stat.st_mtime);
+
   if (recompile) {
-    struct namerec *inc;
+    struct namerec* inc;
     (void)
       sprintf(buf, "%s -%c %s%s%s %s -o %s.%c",
 	      inf->comp, (masm ? 'S' : 'c'), optflags,
 	      (cdebug ? " -g" : ""), cc_profile_flag,
 	      (inf->comp_opt ? inf->comp_opt : ""),
 	      name, suffix);
-    bufp = buf+strlen(buf);
-    for (inc = incdirs; inc != 0; inc = inc->next) {
-      (void)sprintf(bufp, " -I%s", inc->name);
+    bufp = buf + strlen(buf);
+    for (inc = incdirs; inc != NULL; inc = inc->next) {
+      (void) sprintf(bufp, " -I%s", inc->name);
       bufp += strlen(bufp);
     }
     /*** for Distributed KLIC system ***/
     if (distklic) {
       DIST_COMPILER_FLAG(name, inf->ext);
     } else if ( shmklic ) {
-      (void)sprintf(bufp, " -DSHM -I%s -I. %s%s", klic_incdir, name, inf->ext);
+      (void) sprintf(bufp, " -DSHM -I%s -I. %s%s",
+        klic_incdir, name, inf->ext);
     } else {
-      (void)sprintf(bufp, " -I%s -I. %s%s", klic_incdir, name, inf->ext);
+      (void) sprintf(bufp, " -I%s -I. %s%s",
+        klic_incdir, name, inf->ext);
     }
+
     {
       char tmpbuf[256];
-      (void)sprintf(tmpbuf, "%s%s", name, inf->ext);
+      (void) sprintf(tmpbuf, "%s%s", name, inf->ext);
       exec_command("Compilation failed for file %s",
 		   tmpbuf, noop);
     }
   }
 }
 
-static void
-compile_s_file(name, masm)
- char *name;
- int masm; 
-{
- if (!masm) {
-   struct stat s_stat, o_stat;
-   (void)sprintf(buf, "%s.s", name);
-   get_stat(buf, &s_stat);
-   (void)sprintf(buf, "%s.o", name);
-   if (do_recompile ||
-       stat(buf, &o_stat) != 0 ||
-       s_stat.st_mtime >= o_stat.st_mtime) {
-     (void)sprintf(buf, "%s -c %s%s -I%s %s -o %s.o %s.s",
+static void compile_s_file(
+  char* name,
+  int masm )
+{
+  struct stat s_stat, o_stat;
+
+  if(masm) return;
+  assert(!masm);
+
+  (void) sprintf(buf, "%s.s", name);
+  get_stat(buf, &s_stat);
+
+  (void) sprintf(buf, "%s.o", name);
+  if (do_recompile ||
+      stat(buf, &o_stat) != 0 ||
+      s_stat.st_mtime >= o_stat.st_mtime) {
+    (void) sprintf(buf, "%s -c %s%s -I%s %s -o %s.o %s.s",
 		   klic_cc, optflags,
 		   (cdebug ? " -g" : ""),
 		   klic_incdir,
 		   (klic_cc_options ? klic_cc_options : ""),
 		   name, name);
-     exec_command("Assembly failed for file %s.s",
+    exec_command("Assembly failed for file %s.s",
 		  name, noop);
-   }
- }
+  }
 }
 
-static void
-c_to_o(void)
+static void c_to_o(void)
 {
-  struct namerec *f;
+  struct namerec* f;
   int status;
 
-  for (f = files; f != 0; f = f->next) {
+  for (f = files; f != NULL; f = f->next) {
     if(f->type == prog_file) {
-      char *tmpname = f->name;
-      struct lang_info *tmpinfo = f->info;
+      char* tmpname = f->name;
+      struct lang_info* tmpinfo = f->info;
       compile_c_file(tmpname, tmpinfo, make_asm);
     } else if (f->type == asm_file && !make_asm) {
       compile_s_file(f->name, make_asm);
@@ -517,35 +548,35 @@
   }
 }
 
-make_atom_o()
+static void make_atom_o(void)
 {
   compile_c_file(make_path("atom"), c_info, 0);
 }
 
-make_funct_o()
+static void make_funct_o(void)
 {
   compile_c_file(make_path("funct"), c_info, 0);
 }
 
-make_pred_o()
+static void make_pred_o(void)
 {
   compile_c_file(make_path("predicates"), c_info, 0);
 }
 
-linkage()
+static void linkage(void)
 {
-  struct namerec *f;
-  char *bufp;
-  char *ld;
-  char *ldopt;
+  struct namerec* f;
+  char* bufp;
+  char* ld;
+  char* ldopt;
 
-  if(forced_linker) {
+  if(forced_linker != NULL) {
     ld = forced_linker;
   } else {
     ld = pref_info->ld;
   }
 
-  if(forced_linker_opt) {
+  if(forced_linker_opt != NULL) {
     ldopt = forced_linker_opt;
   } else {
     ldopt = pref_info->ld_opt;
@@ -554,27 +585,27 @@
   /* We will link the program anyway, as we can't tell whether the */
   /* existing executable was linked with the tracing library or not */
 
-  (void)sprintf(buf, "%s%s%s%s %s %s %s %s",
-		ld,
-		(ofile ? " -o " : ""), (ofile ? ofile : ""),
-		link_profile_flag,
-		(ldopt ? ldopt : ""),
-		make_path("atom.o"),
-		make_path("funct.o"),
-		( debug ? make_path("predicates.o") : ""));
-  bufp = buf+strlen(buf);
-  for (f = files; f != 0; f = f->next) {
-    (void)sprintf(bufp, " %s.o", f->name);
+  (void) sprintf(buf, "%s" "%s%s" "%s %s %s %s %s",
+    ld,
+    (ofile != NULL ? " -o " : ""), (ofile != NULL ? ofile : ""),
+    link_profile_flag,
+    (ldopt != NULL ? ldopt : ""),
+    make_path("atom.o"),
+    make_path("funct.o"),
+    (debug ? make_path("predicates.o") : "") );
+  bufp = buf + strlen(buf);
+  for (f = files; f != NULL; f = f->next) {
+    (void) sprintf(bufp, " %s.o", f->name);
     bufp += strlen(bufp);
   }
-  for (f = libdirs; f != 0; f = f->next) {
-    (void)sprintf(bufp, " -L%s", f->name);
+  for (f = libdirs; f != NULL; f = f->next) {
+    (void) sprintf(bufp, " -L%s", f->name);
     bufp += strlen(bufp);
   }
-  (void)sprintf(bufp, " -L%s", klic_libdir);
+  (void) sprintf(bufp, " -L%s", klic_libdir);
   bufp += strlen(bufp);
   {
-    char *tptr;
+    char* tptr;
     if ( distklic ) {
       tptr = LIBRARIES_D;
     } else if ( shmklic ) {
@@ -584,32 +615,33 @@
     } else {
       tptr = LIBRARIES;
     }
-    (void)sprintf(bufp, " %s", tptr);
+    (void) sprintf(bufp, " %s", tptr);
   }
   bufp += strlen(bufp);
-  for (f = libraries; f != 0; f = f->next) {
-    (void)sprintf(bufp, " -l%s", f->name);
+  for (f = libraries; f != NULL; f = f->next) {
+    (void) sprintf(bufp, " -l%s", f->name);
     bufp += strlen(bufp);
   }
   if (distklic) {
     DIST_LINKAGE_FLAG();
   }
-  exec_command("Linkage failed", 0, noop);
+  exec_command("Linkage failed", NULL, noop);
 }
 
+
 #define Optarg() \
-( argv[optind][charind+1] != 0 ? \
+( argv[optind][charind+1] != '\0' ? \
   argv[optind]+charind+1 : \
-  (optind++, argv[optind] ))
+  (optind++, argv[optind]) )
 
 #define Nextarg() \
-( argv[++optind] )
+( optind++, argv[optind] )
 
-main(argc,argv)
-     int argc;
-     char **argv;
+extern int main(
+  int argc,
+  char** argv )
 {
-  extern char *option_value();
+  extern char* option_value();
   int optind;
   int optc;
   int c;
@@ -643,9 +675,10 @@
        optind++) {
     int charind;
     for (charind = 1;
-	 argv[optind][charind] != 0;
+	 argv[optind][charind] != '\0';
 	 charind++) {
-      switch (c=argv[optind][charind]) {
+      c = argv[optind][charind];
+      switch (c) {
       case 'c': no_link = 1; break;
       case 'C': no_cc = 1; break;
       case 'd': 
@@ -667,8 +700,8 @@
       case 'I':
       case 'L':
       case 'l': {
-	struct namerec *newname =
-	  (struct namerec *)malloc(sizeof(struct namerec));
+	struct namerec* newname =
+	  (struct namerec*) malloc(sizeof(struct namerec));
 	newname->name = Optarg();
 	newname->type = other_file;
 	switch (c) {
@@ -734,8 +767,9 @@
       default: usage_error(argv[0]);
       }
     }
-  nextarg:;
+  nextarg: ;
   }
+  assert(optind >= argc || argv[optind][0] != '-');
 
   if (verbose) {
     fprintf(stderr, "KLIC compiler driver version %s (%s)\n",
@@ -745,47 +779,52 @@
     optflags = "";
   } else {
     if (optlevel<1) {
-      (void)sprintf(buf, " -O %s", UOPTFLAGS);
+      (void) sprintf(buf, " -O %s", UOPTFLAGS);
     } else {
-      (void)sprintf(buf, " -O%d %s", optlevel, UOPTFLAGS);
+      (void) sprintf(buf, " -O%d %s", optlevel, UOPTFLAGS);
     }
-    optflags = strcpy((char *)malloc(strlen(buf)+1), buf);
+    optflags = (char*) malloc(strlen(buf)+1);
+    optflags = strcpy(optflags, buf);
   }
   for (optc = optind; optc < argc; optc++) {
-    char *suffix;
-    struct namerec *newname =
-      (struct namerec *)malloc(sizeof(struct namerec));
+    char* suffix;
+    struct namerec* newname;
+
+    newname = (struct namerec*) malloc(sizeof(struct namerec));
     suffix = strrchr(argv[optc], '.');
-    if (suffix == 0) {
+    if (suffix == NULL) {
       error_exit("Can't process file: %s", argv[optc]);
     } else {
-      int len = suffix-argv[optc];
-      struct lang_info *info;
-      newname->name =
-	strncpy((char *)malloc(len+1), argv[optc], len);
-      newname->name[len] = 0;
+      struct lang_info* info;
+      int len = suffix - argv[optc];
+
+      newname->name = (char*) malloc(len+1);
+      newname->name = strncpy(newname->name, argv[optc], len);
+      newname->name[len] = '\0';
       if (strcmp(suffix, ".kl1") == 0) {
 	newname->type = kl1_file;
       } else if (strcmp(suffix, ".a") == 0) {
 	newname->type = asm_file;
       } else if (strcmp(suffix, ".o") == 0) {
 	newname->type = obj_file;
-      } else if ((info = search_lang_info(suffix)) != 0) {
+      } else {
+	info = search_lang_info(suffix);
+        if (info == NULL)
+	  error_exit("Can't process file: %s", argv[optc]);
+	assert(info != NULL);
 	newname->type = prog_file;
 	newname->info = info;
-      } else {
-	error_exit("Can't process file: %s", argv[optc]);
       }
     }
     newname->next = files;
     files = newname;
   }
+  assert(optc >= argc);
 
   reverse_names(&files);
   reverse_names(&libraries);
   reverse_names(&libdirs);
 
-
   guess_linker();
   kl1_to_c();
   if (!no_cc) {
@@ -797,9 +836,10 @@
 #ifdef USELOCKF
       int fd;
       char fdbuf[BUFSIZE];
-      strcpy(fdbuf,make_path(DBFILENAME));
-      strcat(fdbuf,".lock");
-      lockf(fd=open(fdbuf,O_RDONLY),F_LOCK,1);
+      strcpy(fdbuf, make_path(DBFILENAME));
+      strcat(fdbuf, ".lock");
+      fd = open(fdbuf, O_RDONLY);
+      lockf(fd, F_LOCK, 1);
 #endif
       if (!no_link) {
 	make_atom_o();
@@ -811,7 +851,7 @@
       sync_with_subtasks();
 #ifdef USELOCKF
       close(fd);
-      lockf(fd,F_ULOCK,1);
+      lockf(fd, F_ULOCK, 1);
 #endif
     }
   }
diff -ruN klic-3.003-2001-11-22/config.h.sh klic-3.003-2001-11-23/config.h.sh
--- klic-3.003-2001-11-22/config.h.sh	Wed Nov 21 11:26:13 2001
+++ klic-3.003-2001-11-23/config.h.sh	Fri Nov 23 18:08:07 2001
@@ -8,8 +8,11 @@
 cat <<GAZONK >>config.h
 
 #define DIST_COMPILER_FLAG(name, ext) \
-    {(void)sprintf(bufp, " -DDIST -I%s -I. %s%s", \
-    klic_incdir, (name), (ext)); }
+do{ \
+  (void) sprintf(bufp, " -DDIST -I%s -I. %s%s", \
+    klic_incdir, (name), (ext) ); \
+}while(0)
+
 #define DIST_LINKAGE_FLAG() 
 
 GAZONK
