Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <unistd.h>
  4 #include <string.h>
  5 #include <pthread.h>
  6 #include <errno.h>
  7 #include <sys/time.h>
  8 
  9 #include "grab-ng.h"
 10 #include "commands.h"
 11 #include "frequencies.h"
 12 
 13 /* --------------------------------------------------------------------- */
 14 
 15 int               chantab = -1;
 16 struct CHANLISTS  *chanlists;
 17 struct STRTAB     *chanlist_names;
 18 
 19 
 20 /* --------------------------------------------------------------------- */
 21 
 22 void freq_init(void)
 23 {
 24     char line[256],value[256];
 25     FILE *fp;
 26     int nr,i,j;
 27 
 28     if (NULL == (fp = fopen(DATADIR "/Index.map","r"))) {
 29         perror("open " DATADIR "/Index.map");
 30         exit(1);
 31     }
 32     if (debug)
 33         fprintf(stderr,"freq: reading " DATADIR "/Index.map\n");
 34 
 35     nr = 0;
 36     i  = 0;
 37     while (NULL != fgets(line,255,fp)) {
 38         nr++;
 39         if (line[0] == '\n' || line[0] == '#' || line[0] == '%')
 40             continue;
 41         if (1 == sscanf(line,"[%255[^]]]",value)) {
 42             /* [section] */
 43             chanlists = realloc(chanlists, (i+2) * sizeof(struct CHANLISTS));
 44             memset(chanlists+i, 0, 2*sizeof(struct CHANLISTS));
 45             chanlists[i].name = strdup(value);
 46             i++;
 47             continue;
 48         }
 49         if (NULL == chanlists) {
 50             fprintf(stderr,"%s:%d: error: no section\n",
 51                     DATADIR "/Index.map",nr);
 52             continue;
 53         }
 54 
 55         if (1 == sscanf(line," file = %255[^\n]",value)) {
 56             /* file = <filename> */
 57             chanlists[i-1].filename = strdup(value);
 58             continue;
 59         }
 60 
 61         /* Huh ? */
 62         fprintf(stderr,"%s:%d: syntax error\n",
 63                 DATADIR "/Index.map",nr);
 64     }
 65     fclose(fp);
 66 
 67     chanlist_names = malloc((i+1) * sizeof(struct STRTAB));
 68     for (j = 0; j < i; j++) {
 69         chanlist_names[j].nr  = j;
 70         chanlist_names[j].str = chanlists[j].name;
 71     }
 72     chanlist_names[j].nr  = -1;
 73     chanlist_names[j].str = NULL;
 74 }
 75 
 76 /* --------------------------------------------------------------------- */
 77 
 78 static int freq_readlist(struct CHANLIST **list, int n, char *name)
 79 {
 80     char line[256],value[256];
 81     char filename[256];
 82     FILE *fp;
 83     int nr;
 84 
 85     sprintf(filename,"%s/%s",DATADIR,name);
 86     if (NULL == (fp = fopen(filename,"r"))) {
 87         fprintf(stderr,"open %s: %s\n",filename,strerror(errno));
 88         exit(1);
 89     }
 90     if (debug)
 91         fprintf(stderr,"freq: reading %s\n",filename);
 92 
 93     nr = 0;
 94     while (NULL != fgets(line,255,fp)) {
 95         nr++;
 96         if (1 == sscanf(line,"# include \"%[^\"]\"",value)) {
 97             /* includes */
 98             n = freq_readlist(list,n,value);
 99             continue;
100         }
101         if (line[0] == '\n' || line[0] == '#' || line[0] == '%') {
102             /* ignore */
103             continue;
104         }
105         if (1 == sscanf(line,"[%255[^]]]",value)) {
106             /* [section] */
107             if (0 == (n % 16)) {
108                 *list = realloc(*list, (n+16) * sizeof(struct CHANLIST));
109                 memset((*list)+n, 0, 16*sizeof(struct CHANLIST));
110             }
111             (*list)[n].name = strdup(value);
112             n++;
113             continue;
114         }
115         if (0 == n) {
116             fprintf(stderr,"%s:%d: error: no section\n",filename,nr);
117             continue;
118         }
119 
120         if (1 == sscanf(line," freq = %255[^\n]", value)) {
121             /* freq =  */
122             (*list)[n-1].freq = atoi(value);
123             continue;
124         }
125         
126         /* Huh ? */
127         fprintf(stderr,"%s:%d: syntax error\n", filename, nr);
128     }
129     fclose(fp);
130     return n;
131 }
132 
133 void freq_newtab(int n)
134 {
135     if (debug)
136         fprintf(stderr,"freq: newtab %d\n",n);
137 
138     if (NULL == chanlists[n].list)
139         chanlists[n].count =
140             freq_readlist(&chanlists[n].list,0,chanlists[n].filename);
141     chantab = n;
142 }
143 
  This page was automatically generated by the LXR engine.