--- /usr/src/release/sysinstall/pccard.c	Mon Sep  3 22:31:03 2001
+++ /usr/src/release/sysinstall/pccard.c	Tue Sep 11 12:04:54 2001
@@ -17,6 +17,7 @@
 #include "sysinstall.h"
 #include <sys/fcntl.h>
 #include <sys/time.h>
+#include <sys/stat.h>
 #include <pccard/cardinfo.h>
 
 int	pccard_mode = 0;
@@ -54,18 +55,18 @@
 
 /* Fill in with potential free IRQs for pccardd */
 static Irq IrqTable[] = {
-    { "irq_03", "-i 3",  ~IRQ_03, IRQ_03 },
-    { "irq_04", "-i 4",  ~IRQ_04, IRQ_04 },
-    { "irq_05", "-i 5",  ~IRQ_05, IRQ_05 },
-    { "irq_06", "-i 6",  ~IRQ_06, IRQ_06 },
-    { "irq_07", "-i 7",  ~IRQ_07, IRQ_07 },
-    { "irq_09", "-i 9",  ~IRQ_09, IRQ_09 },
-    { "irq_10", "-i 10", ~IRQ_10, IRQ_10 },
-    { "irq_11", "-i 11", ~IRQ_11, IRQ_11 },
-    { "irq_15", "-i 15", ~IRQ_15, IRQ_15 },
+    { "irq_03", "3",  ~IRQ_03, IRQ_03 },
+    { "irq_04", "4",  ~IRQ_04, IRQ_04 },
+    { "irq_05", "5",  ~IRQ_05, IRQ_05 },
+    { "irq_06", "6",  ~IRQ_06, IRQ_06 },
+    { "irq_07", "7",  ~IRQ_07, IRQ_07 },
+    { "irq_09", "9",  ~IRQ_09, IRQ_09 },
+    { "irq_10", "10", ~IRQ_10, IRQ_10 },
+    { "irq_11", "11", ~IRQ_11, IRQ_11 },
+    { "irq_15", "15", ~IRQ_15, IRQ_15 },
 #ifdef PC98
-    { "irq_12", "-i 12", ~IRQ_12, IRQ_12 },
-    { "irq_13", "-i 13", ~IRQ_13, IRQ_13 },
+    { "irq_12", "12", ~IRQ_12, IRQ_12 },
+    { "irq_13", "13", ~IRQ_13, IRQ_13 },
 #endif /* PC98 */
     {NULL},
 };
@@ -180,7 +181,9 @@
     char *spcic_mem;
     char pccardd_cmd[256];
     WINDOW *w;
-    
+    FILE *fp;
+    struct stat sbuf;
+
     pccard_mode = 1;
     
     if (!RunningAsInit && !Fake) {
@@ -202,87 +205,104 @@
 
     variable_set2("_pccard_install", "YES", 0);
 
-    dmenuOpenSimple(&MenuPCICMem, FALSE);
-    spcic_mem = variable_get("_pcicmem");
-    dmenuOpenSimple(&MenuCardIRQ, FALSE);
-
-    sscanf(spcic_mem, "%d", &t);
-    switch (t) {
-      case 0:
-	pcic_mem = 0xd0000;
-	variable_set2("pccard_mem", "DEFAULT", 1);
-	break;
-      case 1:
-	pcic_mem = 0xd4000;
-	variable_set2("pccard_mem", "0xd4000", 1);
-	break;
-      case 2:
-	pcic_mem = 0xd8000;
-	variable_set2("pccard_mem", "0xd8000", 1);
-	break;
-      case 3:
-	pcic_mem = 0xdc000;
-	variable_set2("pccard_mem", "0xdc000", 1);
-	break;
+    /* check to see if they've already created a pccard configuration file. */
+    if ( stat("/mnt/etc/pccard.conf", &sbuf) ) 
+    {
+      /* if they haven't go ahead and ask them about how to configure it. */
+      dmenuOpenSimple(&MenuPCICMem, FALSE);
+      spcic_mem = variable_get("_pcicmem");
+      dmenuOpenSimple(&MenuCardIRQ, FALSE);
+
+      sscanf(spcic_mem, "%d", &t);
+      switch (t) {
+        case 0:
+  	  pcic_mem = 0xd0000;
+	  variable_set2("pccard_mem", "DEFAULT", 1);
+	  break;
+        case 1:
+	  pcic_mem = 0xd4000;
+	  variable_set2("pccard_mem", "0xd4000", 1);
+	  break;
+        case 2:
+	  pcic_mem = 0xd8000;
+	  variable_set2("pccard_mem", "0xd8000", 1);
+	  break;
+        case 3:
+	  pcic_mem = 0xdc000;
+	  variable_set2("pccard_mem", "0xdc000", 1);
+	  break;
 #ifdef PC98
-      case 4:
-	pcic_mem = 0xda000;
-	variable_set2("pccard_mem", "0xda000", 1);
-	break;
+        case 4:
+	  pcic_mem = 0xda000;
+	  variable_set2("pccard_mem", "0xda000", 1);
+	  break;
 #endif /* PC98 */
-    }
+      }
 
-    /* get card_irq out of CardIrq somehow */
-    if (CardIrq) {
-        for (i = 0; i < IRQ_COUNT; i++) {
-            if ((CardIrq & IrqTable[i].my_bit) != 0) {
-                sprintf(temp, "%s %s", card_irq, IrqTable[i].my_flag);
-                strcpy(card_irq, temp);
-            }
-        } 
+      /* get card_irq out of CardIrq somehow */
+      if (CardIrq) {
+          for (i = 0; i < IRQ_COUNT; i++) {
+              if ((CardIrq & IrqTable[i].my_bit) != 0) {
+                  sprintf(temp, "%s -i %s", card_irq, IrqTable[i].my_flag);
+                  strcpy(card_irq, temp);
+              }
+          } 
+      }
+
+      w = savescr();
+      dialog_clear_norefresh();
+      msgConfirm("Now we start initializing PC-card controller and cards.\n"
+  	         "If you've executed this installer from a PC-card floppy\n"
+	         "drive, this is the last chance to replace it with\n"
+	         "installation media (PC-card Ethernet, CDROM, etc.).\n"
+	         "Please insert installation media and press [Enter].\n"
+	         "If you've not plugged the PC-card installation media\n"
+	         "in yet, please plug it in now and press [Enter].\n"
+	         "Otherwise, just press [Enter] to proceed."); 
+
+      dialog_clear();
+      msgNotify("Initializing PC-card controller....");
+
+      if (!Fake) {
+	  if ((fd = open(card_device, O_RDWR)) < 1) {
+	      msgNotify("Can't open PC-card controller %s.\n", card_device);
+	      restorescr(w);
+	      return;
+	  }
+
+	  if (ioctl(fd, PIOCRWMEM, &pcic_mem) < 0) {
+	      msgNotify("ioctl %s failed.\n", card_device);
+	      restorescr(w);
+	      return;
+	  }
+	  beep_newstat = 2;
+	  if (ioctl(fd, PIOCSBEEP, &beep_newstat) < 0) {
+	      msgNotify("Warning: unable to set pccard insertion beep type for %s",
+	  	  card_device);
+	      restorescr(w);
+	      return;
+	  }
+
+      }
+
+      strcpy(pccardd_cmd, "/stand/pccardd ");
+      strcat(pccardd_cmd, card_irq);
+
+      fp = fopen("/mnt/etc/pccard.conf", "a+");
+      fprintf(fp, "irq    ");
+      fprintf(fp, "%s", card_irq);
+      fputc('\n', fp);
+      fclose(fp);
     }
-
-    w = savescr();
-    dialog_clear_norefresh();
-    msgConfirm("Now we start initializing PC-card controller and cards.\n"
-	       "If you've executed this installer from a PC-card floppy\n"
-	       "drive, this is the last chance to replace it with\n"
-	       "installation media (PC-card Ethernet, CDROM, etc.).\n"
-	       "Please insert installation media and press [Enter].\n"
-	       "If you've not plugged the PC-card installation media\n"
-	       "in yet, please plug it in now and press [Enter].\n"
-	       "Otherwise, just press [Enter] to proceed."); 
-
-    dialog_clear();
-    msgNotify("Initializing PC-card controller....");
-
-    if (!Fake) {
-	if ((fd = open(card_device, O_RDWR)) < 1) {
-	    msgNotify("Can't open PC-card controller %s.\n", card_device);
-	    restorescr(w);
-	    return;
-	}
-
-	if (ioctl(fd, PIOCRWMEM, &pcic_mem) < 0) {
-	    msgNotify("ioctl %s failed.\n", card_device);
-	    restorescr(w);
-	    return;
-	}
-	beep_newstat = 2;
-	if (ioctl(fd, PIOCSBEEP, &beep_newstat) < 0) {
-	    msgNotify("Warning: unable to set pccard insertion beep type for %s",
-		card_device);
-	    restorescr(w);
-	    return;
-	}
-
+    else
+    {
+      /* If they've already configured pccard, lets just run the daemon */
+      /* since the pccard.conf is in a different position, we should tell */
+      /* the daemon where to find the old configuration file. */
+      sprintf(pccardd_cmd, "/stand/pccardd -f /mnt/etc/pccard.conf");
     }
 
-    strcpy(pccardd_cmd, "/stand/pccardd ");
-    strcat(pccardd_cmd, card_irq);
     strcat(pccardd_cmd, " -z");
-
-    variable_set2("pccardd_flags", card_irq, 1);
     variable_set2("pccard_enable", "YES", 1);
 
     vsystem("%s", pccardd_cmd);
