1 /* $Id: readers.c,v 1.2 2003/06/19 22:40:53 rees Exp $ */ 2 3 /* 4 copyright 2001 5 the regents of the university of michigan 6 all rights reserved 7 8 permission is granted to use, copy, create derivative works 9 and redistribute this software and such derivative works 10 for any purpose, so long as the name of the university of 11 michigan is not used in any advertising or publicity 12 pertaining to the use or distribution of this software 13 without specific, written prior authorization. if the 14 above copyright notice or any other identification of the 15 university of michigan is included in any copy of any 16 portion of this software, then the disclaimer below must 17 also be included. 18 19 this software is provided as is, without representation 20 from the university of michigan as to its fitness for any 21 purpose, and without warranty by the university of 22 michigan of any kind, either express or implied, including 23 without limitation the implied warranties of 24 merchantability and fitness for a particular purpose. the 25 regents of the university of michigan shall not be liable 26 for any damages, including special, indirect, incidental, or 27 consequential damages, with respect to any claim arising 28 out of or in connection with the use of the software, even 29 if it has been or is hereafter advised of the possibility of 30 such damages. 31 */ 32 33 /* 34 * parse the reader.conf file 35 * 36 * Jim Rees 37 * University of Michigan CITI, August 2000 38 */ 39 40 #include <stdlib.h> 41 #include <stdio.h> 42 #include <string.h> 43 44 int 45 DBUpdateReaders(char *readerconf, int (callback) (int rn, unsigned long channelId, unsigned long lun, char *driverFile)) 46 { 47 FILE *f; 48 char buf[512], lv[64], rv[512], libpath[512]; 49 long channelno, lun = 0; 50 int nr = 0; 51 52 f = fopen(readerconf, "r"); 53 if (!f) 54 return -1; 55 56 libpath[0] = '\0'; 57 channelno = -1; 58 59 while (fgets(buf, sizeof buf, f)) { 60 if (sscanf(buf, "%63s %511s", lv, rv) != 2) 61 continue; 62 if (rv[0] == '"') { 63 /* if rv starts with quote, read everything up to terminating quote */ 64 sscanf(buf, "%*s \"%511[^\"]", rv); 65 } 66 #ifdef DEBUG 67 printf("%s %s\n", lv, rv); 68 #endif 69 if (!strcasecmp(lv, "libpath")) 70 strncpy(libpath, rv, sizeof libpath); 71 if (!strcasecmp(lv, "channelid")) 72 channelno = strtol(rv, NULL, 0); 73 if (libpath[0] && channelno != -1) { 74 #ifdef DEBUG 75 printf("adding rn %d Id 0x%x lun %d path %s\n", nr, channelno, lun, libpath); 76 #endif 77 (*callback)(nr++, channelno, lun, libpath); 78 libpath[0] = '\0'; 79 channelno = -1; 80 } 81 } 82 83 fclose(f); 84 return 0; 85 } 86