/* * (c) 2004-2006 * * This small tool tunes through list of frequencys * while every round a given command will be executed. * The frequencys may be given as arguments or they can * be parsed from a channels.conf. * * Useful for example to find programs (another tool would * have to check if there's a multiplex) or to get a * full EPG (with tv_grab_dvb) - last one was my intention. * * Example: * * $ ./freqtool -e "~/tv_grab_dvb-0.9/update.sh" -f 650000000 -f 834000000 -f 514000000 -f 698000000 -f 826000000 * * My 'update.sh' looks like this: * - * #!/bin/sh * /home/myth/tv_grab_dvb-0.9/tv_grab_dvb -o 1 -t 3 > /tmp/tv.xml 2>/dev/null && /usr/local/bin/mythfilldatabase --file 1 0 /tmp/tv.xml > /dev/null 2>&1 * - * * This would update the EPG of mythtv for every channel (one frequency is a multiplex of multiple channels). */ #define MAX_FREQS 30 #define VERSION "0.2" #include #include #include #include #include "linux/dvb/frontend.h" int open_frontend(int adapter, int frontend); int set_frontend(int frequency); int help(char *exe); int parse_channelsconf(char *channelsconf); int fd_frontend, freq[MAX_FREQS], frequencys_done=0; int main(int argc, char *argv[]) { int i, adapter=0, frontend=0, execute_done=0, channelsconf_done=0, parsed; char option, *execute, *channelsconf; while((option=getopt(argc, argv, "a:c:e:f:l:hv")) != -1) { switch(option) { case 'a': adapter = atoi(optarg); break; case 'c': channelsconf = (char *)malloc(strlen(optarg)+1); channelsconf = optarg; channelsconf_done = 1; break; case 'e': execute = (char *)malloc(strlen(optarg)+1); execute = optarg; execute_done = 1; break; case 'l': frontend = atoi(optarg); case 'f': if(frequencys_done\n"); exit(0); } } if (execute_done<1) { fprintf(stderr, "Error: You must set a path to the program that should be executed.\n\n"); help(argv[0]); exit(1); } if (frequencys_done<1) { if(channelsconf_done<1) { fprintf(stderr, "Error: You must set at least one frequency.\n\n"); help(argv[0]); exit(1); } else { parsed = parse_channelsconf(channelsconf); if(parsed<1) { exit(5); } printf("%d frequencys parsed (with %d channels).\n", frequencys_done, parsed); } } if (open_frontend(adapter, frontend) < 0) { exit(2); } for (i=0; i\n\n" " Usage: %s [ -a ] [ -c ] -e \n" " [ -f (-f ...) ] [ -l ]\n\n" "Options:\n" " -a DVB-Adapter (default: 0)\n" " -c Path to channels.conf\n" " -e Program to execute\n" " -f Frequency in Hz\n" " -l DVB-Frontend (default: 0)\n" " -h Help (this one)\n" " -v Version\n\n" "It's either -c or at least one -f. -e is needed.\n", exe); } int parse_channelsconf(char *channelsconf) { FILE *fd_channels; int i, fr, j, k, frequencys_done_save; fd_channels = fopen(channelsconf, "r"); if(fd_channels == NULL) { perror(channelsconf); return -1; } while(fscanf(fd_channels, "%*[^:]:%d:%*s\n", &fr) != EOF) { if(frequencys_done