--- cygnus/src/wconfig.c	Tue Jul  1 14:04:37 1997
+++ kerbnet-1.2/wconfig.c	Tue May 27 21:54:51 1997
@@ -1,7 +1,7 @@
 /*
  * wconfig.c
  *
- * Copyright 1995 by the Massachusetts Institute of Technology.
+ * Copyright 1995,1996 by the Massachusetts Institute of Technology.
  * All Rights Reserved.
  *
  * Export of this software from the United States of America may
@@ -39,29 +39,105 @@
 #include <stdio.h>
 #include <string.h>
 
-static char buf [1024];							/* Holds line from a file */
 static int copy_file (char *path, char *fname);
 
-int main(int argc, char *argv[]) {
-    char *ptr;									/* For parsing the input */
-
-    if (argc == 2)                              /* Config directory given */
-        copy_file (argv[1], "\\windows.in");        /* Send out prefix */
-
-    while ((ptr = gets(buf)) != NULL) {         /* Filter stdin */
-        if (memcmp ("##DOS", buf, 5) == 0)
-            ptr += 5;
-		else if (*ptr == '@')					/* Lines starting w/ '@'... */
-			*ptr = '\0';						/* ...turn into blank lines */
-
-        puts (ptr);
-    }
+struct ignore {
+  char *match;
+  int   len;
+  int   flags;
+};
+
+#ifdef _WIN32
+#define SYSTYPE "win32"
+#else
+#ifdef _MSDOS
+#define SYSTYPE "msdos"
+#else
+#ifdef _unix
+#define SYSTYPE "unix"
+#else
+#define SYSTYPE "unknown"
+#endif
+#endif
+#endif
+
+#define FLAGS_DLL    0x0001U  /* only when compiling a DLL-making file */
+#define FLAGS_NODLL  0x0002U  /* only when compiling a non-DLL making file */
+#define FLAGS_ALWAYS 0xffffU
+
+int strip_flags = FLAGS_NODLL;  /* default to standard build */
+		
+struct ignore ignore_list[] = {
+  { "DOS##",        5, FLAGS_ALWAYS },
+  { "DOS",          3, FLAGS_ALWAYS },
+#ifdef _MSDOS
+  { "WIN16##",      7, FLAGS_ALWAYS },
+  { "WIN16DLL##",  10, FLAGS_DLL },
+  { "WIN16STD##",  10, FLAGS_NODLL },
+#endif
+#ifdef _WIN32
+  { "WIN32##",      7, FLAGS_ALWAYS },
+  { "WIN32DLL##",  10, FLAGS_DLL },
+  { "WIN32STD##",  10, FLAGS_NODLL },
+#endif
+  { NULL,           0, 0 }
+};
+
+int
+main(int argc, char *argv[])
+{
+  char *filepath = NULL;
+  
+#if 0
+  fprintf(stderr, "Configured for %s\n", SYSTYPE);
+#endif
+  
+  switch (argc) {
+  case 3:
+    if (strcmp(argv[1], "-dll") == 0)
+      strip_flags = FLAGS_DLL;
+    filepath = argv[2];
+    break;
+
+  case 2:
+    filepath = argv[1];
+    break;
+
+  case 1:
+    break;
+
+  default:
+    fprintf(stderr, "Usage:  wconfig [-dll] [config-dir] < in > out\n");
+    exit(1);
+  }
+
+  if (filepath != NULL)                         /* Config directory given */
+    copy_file (filepath, "\\windows.in");       /* Send out prefix */
+
+  copy_file("", "-");
+  
+  if (filepath != NULL)                         /* Config directory given */
+    copy_file (filepath, "\\win-post.in");      /* Send out postfix */
+  
+  return 0;
+}
 
-    if (argc == 2)                              /* Config directory given */
-        copy_file (argv[1], "\\win-post.in");       /* Send out postfix */
+int
+is_ignored_prefix(char *p, int len)
+{
+  struct ignore *i;
+
+  i = ignore_list;
+
+  while (i->match != NULL) {
+    if ((strip_flags & i->flags) && strncmp(i->match, p, i->len) == 0)
+      return i->len;
+    i++;
+  }
 
-    return 0;
+  return 0;
 }
+
 /*
  * 
  * Copy_file
@@ -70,18 +146,39 @@
  * 
  */
 static int
-copy_file (char *path, char *fname) {
+copy_file (char *path, char *fname)
+{
     FILE *fin;
-
-    strcpy (buf, path);                         /* Build up name to open */
-    strcat (buf, fname);
-
-    fin = fopen (buf, "r");                     /* File to read */
-    if (fin == NULL)
-        return 1;
+    char buf[1024];
+    char *ptr;
+    char **cpp;
+    
+    int len;
+
+    if (strcmp(fname, "-") == 0) {
+	    fin = stdin;
+    } else {
+	    strcpy (buf, path);              /* Build up name to open */
+	    strcat (buf, fname);
+	    fin = fopen (buf, "r");                     /* File to read */
+	    if (fin == NULL)
+		    return 1;
+    }
+    
 
     while (fgets (buf, sizeof(buf), fin) != NULL) { /* Copy file over */
-        fputs (buf, stdout);
+	    if (buf[0] == '@') {
+		    fputs("\n", stdout);
+		    continue;
+	    }
+	    if (buf[0] != '#' || buf[1] != '#') {
+		    fputs(buf, stdout);
+		    continue;
+	    }
+	    ptr = buf;
+	    if (len = is_ignored_prefix(ptr + 2, strlen(ptr + 2)))
+		    ptr += 2+len;
+	    fputs(ptr, stdout);
     }
 
     fclose (fin);
