- snprintf(ppdev, sizeof(ppdev), "/dev/parport%d", parportnum);
+ int max = -1;
+ struct pports **port = &pplist;
+
+ while (*port) {
+ DPRINTF("Looking up parallel port in linked list, entry: %d\n", (*port)->num);
+ if (max < (*port)->num)
+ max = (*port)->num;
+
+ if ((*port)->base == (unsigned long)cr->Card.Item[0].I.IO.dwAddr) {
+ break;
+ }
+
+ port = &((*port)->next);
+ }
+
+ if (!(*port)) { /* not found */
+ (*port) = malloc(sizeof(struct pports));
+ if (!(*port)) {
+ perror("malloc");
+ exit(EXIT_FAILURE);
+ }
+
+ (*port)->base = (unsigned long)cr->Card.Item[0].I.IO.dwAddr;
+ (*port)->num = max+1;
+ (*port)->next = NULL;
+
+ DPRINTF("parallel port not in linked list, new entry: %d\n", (*port)->num);
+ }
+
+ snprintf(ppdev, sizeof(ppdev), "/dev/parport%d", (*port)->num);