--- zapit.cpp.orig 2003-12-20 12:41:09.000000000 +0100 +++ zapit.cpp 2004-01-01 18:11:17.000000000 +0100 @@ -22,6 +22,32 @@ * */ +/* + Options: + -d Debugmode: Don't fork, additionally generate debugging messages + + -q Be quiet. + + -r (readonly) Normally, zapit writes the values of some internal + parameters to the configuration file + /var/tuxbox/config/zapit/zapit.conf. These include the last selected + (TV or Radio) channel, and some satellite related parameters. If + this is not desired, e.g. due to concern about "wearing out" + flashmemory, or simply because remembrance of the last channel + selected is not desirable, the -r option will inhibit the saving, + however not the reading of the configuration file. + + -a (alternative_configuration_file) Using this option, zapit when + starting will look for an alternative configuration file, + /var/tuxbox/config/zapit/start_channel.conf. If found, and with + sensible content it will be used to select the inital channel. The + first line should contain the channel number (one minus the number + the user sees). Optionally, if the second line is present and starts with the + letter 'r', the channel will be considered a radio channel. + In all other cases, it is interpreted as a TV channel. +*/ + + /* system headers */ #include #include @@ -91,6 +117,10 @@ bool playbackStopForced = false; int debug = 0; +bool readonly = false; +bool alternative_config_file = false; +#define ALTERNATIVE_CONFIG_FILENAME "/var/tuxbox/config/zapit/start_channel.conf" + int waitForMotor = 0; int motorRotationSpeed = 0; //in 0.1 degrees per second diseqc_t diseqcType; @@ -131,6 +161,8 @@ void saveSettings(bool write) { + if (readonly) + return; if (channel) { config.setInt32("lastChannelMode", (currentMode & RADIO_MODE) ? 1 : 0); @@ -152,13 +184,32 @@ CZapitClient::responseGetLastChannel load_settings(void) { CZapitClient::responseGetLastChannel lastchannel; - + bool success = false; + if (alternative_config_file) { + lastchannel.mode = 't'; + FILE *f = fopen(ALTERNATIVE_CONFIG_FILENAME, "r"); + if (f) { + char s[1000]; + success = fgets(s, 1000, f) != NULL; + if (success) { + sscanf(s, "%d", &lastchannel.channelNumber); + if (fgets(s, 1000, f)) { + lastchannel.mode = s[0] == 'r' ? 'r' : 't'; + } + printf("**** Found channel %d, type %c\n", lastchannel.channelNumber, lastchannel.mode); + } + fclose(f); + } + } + if (!success) { + if (config.getInt32("lastChannelMode", 0)) lastchannel.mode = 'r'; else lastchannel.mode = 't'; lastchannel.channelNumber = config.getInt32((currentMode & RADIO_MODE) ? "lastChannelRadio" : "lastChannelTV", 0); + } return lastchannel; } @@ -1591,6 +1642,11 @@ fprintf(stdout, "$Id: zapit.cpp,v 1.339 2003/12/19 23:35:47 derget Exp $\n"); for (int i = 1; i < argc ; i++) { + if (!strcmp(argv[i], "-r")) { + readonly = true; + } else if (!strcmp(argv[i], "-a")) { + alternative_config_file = true; + } else if (!strcmp(argv[i], "-d")) { debug = true; } @@ -1607,7 +1663,7 @@ close(fd); } else { - fprintf(stderr, "Usage: %s [-d] [-q]\n", argv[0]); + fprintf(stderr, "Usage: %s [-d] [-q] [-r] [-a]\n", argv[0]); return EXIT_FAILURE; } }