author | zautrix <zautrix> | 2004-09-12 09:56:56 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-12 09:56:56 (UTC) |
commit | 31fab1d7e531b492d1075964ddcbebe7a563a41a (patch) (unidiff) | |
tree | 91fe6d49f28003106cba1adc9aed816a9019888d /gammu | |
parent | 8d822fd4d97fbb38ab2c4f3f3f64f175ef143cff (diff) | |
download | kdepimpi-31fab1d7e531b492d1075964ddcbebe7a563a41a.zip kdepimpi-31fab1d7e531b492d1075964ddcbebe7a563a41a.tar.gz kdepimpi-31fab1d7e531b492d1075964ddcbebe7a563a41a.tar.bz2 |
Kammu fixes
-rw-r--r-- | gammu/emb/gammu/gammu.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/gammu/emb/gammu/gammu.c b/gammu/emb/gammu/gammu.c index 1d53fb0..5163d81 100644 --- a/gammu/emb/gammu/gammu.c +++ b/gammu/emb/gammu/gammu.c | |||
@@ -8121,236 +8121,281 @@ static void Help(int argc, char *argv[]) | |||
8121 | 8121 | ||
8122 | /* Just --help */ | 8122 | /* Just --help */ |
8123 | if (argc == 2) { | 8123 | if (argc == 2) { |
8124 | HelpGeneral(); | 8124 | HelpGeneral(); |
8125 | return; | 8125 | return; |
8126 | } | 8126 | } |
8127 | 8127 | ||
8128 | if (!strcmp(argv[2],"all")) { | 8128 | if (!strcmp(argv[2],"all")) { |
8129 | HelpHeader(); | 8129 | HelpHeader(); |
8130 | } else { | 8130 | } else { |
8131 | while (HelpDescriptions[i].category != 0) { | 8131 | while (HelpDescriptions[i].category != 0) { |
8132 | if (strcmp(argv[2], HelpDescriptions[i].option) == 0) break; | 8132 | if (strcmp(argv[2], HelpDescriptions[i].option) == 0) break; |
8133 | i++; | 8133 | i++; |
8134 | } | 8134 | } |
8135 | if (HelpDescriptions[i].category == 0) { | 8135 | if (HelpDescriptions[i].category == 0) { |
8136 | HelpGeneral(); | 8136 | HelpGeneral(); |
8137 | printmsg("Unknown help topic specified!\n"); | 8137 | printmsg("Unknown help topic specified!\n"); |
8138 | return; | 8138 | return; |
8139 | } | 8139 | } |
8140 | HelpHeader(); | 8140 | HelpHeader(); |
8141 | printmsg("Gammu parameters, topic: %s\n\n", HelpDescriptions[i].description); | 8141 | printmsg("Gammu parameters, topic: %s\n\n", HelpDescriptions[i].description); |
8142 | } | 8142 | } |
8143 | 8143 | ||
8144 | #if defined(WIN32) || defined(DJGPP) | 8144 | #if defined(WIN32) || defined(DJGPP) |
8145 | cols = 80; | 8145 | cols = 80; |
8146 | #else | 8146 | #else |
8147 | cols = 0; | 8147 | cols = 0; |
8148 | /* If stdout is a tty, we will wrap to columns it has */ | 8148 | /* If stdout is a tty, we will wrap to columns it has */ |
8149 | if (isatty(1)) { | 8149 | if (isatty(1)) { |
8150 | #ifdef TIOCGWINSZ | 8150 | #ifdef TIOCGWINSZ |
8151 | if (ioctl(2, TIOCGWINSZ, &w) == 0) { | 8151 | if (ioctl(2, TIOCGWINSZ, &w) == 0) { |
8152 | if (w.ws_col > 0) cols = w.ws_col; | 8152 | if (w.ws_col > 0) cols = w.ws_col; |
8153 | } | 8153 | } |
8154 | #endif | 8154 | #endif |
8155 | if (cols == 0) { | 8155 | if (cols == 0) { |
8156 | columns = getenv("COLUMNS"); | 8156 | columns = getenv("COLUMNS"); |
8157 | if (columns != NULL) { | 8157 | if (columns != NULL) { |
8158 | cols = atoi(columns); | 8158 | cols = atoi(columns); |
8159 | if (cols <= 0) cols = 0; | 8159 | if (cols <= 0) cols = 0; |
8160 | } | 8160 | } |
8161 | } | 8161 | } |
8162 | 8162 | ||
8163 | if (cols == 0) { | 8163 | if (cols == 0) { |
8164 | /* Fallback */ | 8164 | /* Fallback */ |
8165 | cols = 80; | 8165 | cols = 80; |
8166 | } | 8166 | } |
8167 | } | 8167 | } |
8168 | #endif | 8168 | #endif |
8169 | 8169 | ||
8170 | while (Parameters[j].Function != NULL) { | 8170 | while (Parameters[j].Function != NULL) { |
8171 | k = 0; | 8171 | k = 0; |
8172 | disp = false; | 8172 | disp = false; |
8173 | if (!strcmp(argv[2],"all")) { | 8173 | if (!strcmp(argv[2],"all")) { |
8174 | if (j==0) disp = true; | 8174 | if (j==0) disp = true; |
8175 | if (j!=0) { | 8175 | if (j!=0) { |
8176 | if (strcmp(Parameters[j].help,Parameters[j-1].help)) { | 8176 | if (strcmp(Parameters[j].help,Parameters[j-1].help)) { |
8177 | disp = true; | 8177 | disp = true; |
8178 | } else { | 8178 | } else { |
8179 | if (strcmp(Parameters[j].parameter,Parameters[j-1].parameter)) { | 8179 | if (strcmp(Parameters[j].parameter,Parameters[j-1].parameter)) { |
8180 | disp = true; | 8180 | disp = true; |
8181 | } | 8181 | } |
8182 | } | 8182 | } |
8183 | } | 8183 | } |
8184 | } else { | 8184 | } else { |
8185 | while (Parameters[j].help_cat[k] != 0) { | 8185 | while (Parameters[j].help_cat[k] != 0) { |
8186 | if (Parameters[j].help_cat[k] == HelpDescriptions[i].category) { | 8186 | if (Parameters[j].help_cat[k] == HelpDescriptions[i].category) { |
8187 | disp = true; | 8187 | disp = true; |
8188 | break; | 8188 | break; |
8189 | } | 8189 | } |
8190 | k++; | 8190 | k++; |
8191 | } | 8191 | } |
8192 | } | 8192 | } |
8193 | if (disp) { | 8193 | if (disp) { |
8194 | printf("%s", Parameters[j].parameter); | 8194 | printf("%s", Parameters[j].parameter); |
8195 | if (Parameters[j].help[0] == 0) { | 8195 | if (Parameters[j].help[0] == 0) { |
8196 | printf("\n"); | 8196 | printf("\n"); |
8197 | } else { | 8197 | } else { |
8198 | HelpSplit(cols - 1, strlen(Parameters[j].parameter) + 1, Parameters[j].help); | 8198 | HelpSplit(cols - 1, strlen(Parameters[j].parameter) + 1, Parameters[j].help); |
8199 | } | 8199 | } |
8200 | } | 8200 | } |
8201 | j++; | 8201 | j++; |
8202 | } | 8202 | } |
8203 | } | 8203 | } |
8204 | #if 0 | 8204 | #if 0 |
8205 | #endif // 0 | 8205 | #endif // 0 |
8206 | int main(int argc, char *argv[]) | 8206 | int main(int argc, char *argv[]) |
8207 | { | 8207 | { |
8208 | 8208 | ||
8209 | //fprintf(stderr,"HIIIIIIIIIIIII \n"); | 8209 | //fprintf(stderr,"HIIIIIIIIIIIII \n"); |
8210 | //#if 0 | 8210 | //#if 0 |
8211 | static int z ,start,i; | 8211 | static int z ,start,i; |
8212 | static intonly_config ; | 8212 | static intonly_config ; |
8213 | #if !defined(WIN32) && defined(LOCALE_PATH) | 8213 | #if !defined(WIN32) && defined(LOCALE_PATH) |
8214 | static char*locale, locale_file[201]; | 8214 | static char*locale, locale_file[201]; |
8215 | #endif | 8215 | #endif |
8216 | static char*cp; | 8216 | static char*cp; |
8217 | static boolcount_failed; | 8217 | static boolcount_failed; |
8218 | z = 0; | 8218 | z = 0; |
8219 | start=0;only_config = -1;count_failed = false; | 8219 | start=0;only_config = -1;count_failed = false; |
8220 | s.opened = false; | 8220 | s.opened = false; |
8221 | s.msg = NULL; | 8221 | s.msg = NULL; |
8222 | s.ConfigNum = 0; | 8222 | s.ConfigNum = 0; |
8223 | 8223 | ||
8224 | setlocale(LC_ALL, ""); | 8224 | setlocale(LC_ALL, ""); |
8225 | #ifdef DEBUG | 8225 | #ifdef DEBUG |
8226 | di.dl = DL_TEXTALL; | 8226 | di.dl = DL_TEXTALL; |
8227 | di.df = stdout; | 8227 | di.df = stdout; |
8228 | #endif | 8228 | #endif |
8229 | //#if 0 | 8229 | //#if 0 |
8230 | /* Any parameters? */ | 8230 | /* Any parameters? */ |
8231 | if (argc == 1) { | 8231 | if (argc == 1) { |
8232 | HelpGeneral(); | 8232 | HelpGeneral(); |
8233 | printmsg("Too few parameters!\n"); | 8233 | printmsg("Too few parameters!\n"); |
8234 | exit(1); | 8234 | exit(1); |
8235 | } | 8235 | } |
8236 | 8236 | ||
8237 | /* Help? */ | 8237 | /* Help? */ |
8238 | if (strncmp(argv[1 + start], "--help", 6) == 0) { | 8238 | if (strncmp(argv[1 + start], "--help", 6) == 0) { |
8239 | Help(argc - start, argv + start); | 8239 | Help(argc - start, argv + start); |
8240 | exit(1); | 8240 | exit(1); |
8241 | } | 8241 | } |
8242 | 8242 | ||
8243 | /* Is first parameter numeric? If so treat it as config that should be loaded. */ | 8243 | /* Is first parameter numeric? If so treat it as config that should be loaded. */ |
8244 | if (isdigit(argv[1][0])) { | 8244 | if (isdigit(argv[1][0])) { |
8245 | only_config = atoi(argv[1]); | 8245 | only_config = atoi(argv[1]); |
8246 | if (only_config >= 0) start++; else only_config = -1; | 8246 | if (only_config >= 0) start++; else only_config = -1; |
8247 | } | 8247 | } |
8248 | 8248 | ||
8249 | GSM_ReadConfig(NULL, &s.Config[0], 0); | ||
8250 | s.ConfigNum = 1; | ||
8251 | GSM_Config *con = &s.Config[0]; | ||
8252 | |||
8253 | char* tempC; | ||
8254 | tempC = argv[argc-1]+2; | ||
8255 | if ( *tempC != 0 ) { | ||
8256 | fprintf(stderr,"Using model %s \n",tempC); | ||
8257 | strcpy(con->Model,tempC ); | ||
8258 | } | ||
8259 | tempC = argv[argc-2]+2; | ||
8260 | if ( *tempC != 0 ) { | ||
8261 | fprintf(stderr,"Using device %s \n",tempC); | ||
8262 | con->Device = strdup(tempC); | ||
8263 | con->DefaultDevice = false; | ||
8264 | } | ||
8265 | tempC = argv[argc-3]+2; | ||
8266 | if ( *tempC != 0 ) { | ||
8267 | fprintf(stderr,"Using connection %s \n",tempC); | ||
8268 | con->Connection = strdup(tempC); | ||
8269 | con->DefaultConnection = false; | ||
8270 | } | ||
8271 | argc = argc-3; | ||
8272 | #if 0 | ||
8273 | if ( ! mConnection.isEmpty() ) { | ||
8274 | cfg->Connection = strdup(mConnection.latin1()); | ||
8275 | cfg->DefaultConnection = false; | ||
8276 | qDebug("Connection set %s ", cfg->Connection ); | ||
8277 | |||
8278 | } | ||
8279 | if ( ! mDevice.isEmpty() ) { | ||
8280 | cfg->Device = strdup(mDevice.latin1()); | ||
8281 | cfg->DefaultDevice = false; | ||
8282 | qDebug("Device set %s ", cfg->Device); | ||
8283 | |||
8284 | } | ||
8285 | if ( ! mModel.isEmpty() ) { | ||
8286 | strcpy(cfg->Model,mModel.latin1() ); | ||
8287 | cfg->DefaultModel = false; | ||
8288 | qDebug("Model set %s ",cfg->Model ); | ||
8289 | } | ||
8290 | |||
8291 | #endif | ||
8292 | |||
8293 | #if 0 | ||
8249 | cfg=GSM_FindGammuRC(); | 8294 | cfg=GSM_FindGammuRC(); |
8250 | for (i = 0; i <= MAX_CONFIG_NUM; i++) { | 8295 | for (i = 0; i <= MAX_CONFIG_NUM; i++) { |
8251 | if (cfg!=NULL) { | 8296 | if (cfg!=NULL) { |
8252 | cp = INI_GetValue(cfg, "gammu", "gammucoding", false); | 8297 | cp = INI_GetValue(cfg, "gammu", "gammucoding", false); |
8253 | if (cp) di.coding = cp; | 8298 | if (cp) di.coding = cp; |
8254 | 8299 | ||
8255 | s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false); | 8300 | s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false); |
8256 | if (s.Config[i].Localize) { | 8301 | if (s.Config[i].Localize) { |
8257 | s.msg=INI_ReadFile(s.Config[i].Localize, true); | 8302 | s.msg=INI_ReadFile(s.Config[i].Localize, true); |
8258 | } else { | 8303 | } else { |
8259 | #if !defined(WIN32) && defined(LOCALE_PATH) | 8304 | #if !defined(WIN32) && defined(LOCALE_PATH) |
8260 | locale = setlocale(LC_MESSAGES, NULL); | 8305 | locale = setlocale(LC_MESSAGES, NULL); |
8261 | if (locale != NULL) { | 8306 | if (locale != NULL) { |
8262 | snprintf(locale_file, 200, "%s/gammu_%c%c.txt", | 8307 | snprintf(locale_file, 200, "%s/gammu_%c%c.txt", |
8263 | LOCALE_PATH, | 8308 | LOCALE_PATH, |
8264 | tolower(locale[0]), | 8309 | tolower(locale[0]), |
8265 | tolower(locale[1])); | 8310 | tolower(locale[1])); |
8266 | s.msg = INI_ReadFile(locale_file, true); | 8311 | s.msg = INI_ReadFile(locale_file, true); |
8267 | } | 8312 | } |
8268 | #endif | 8313 | #endif |
8269 | } | 8314 | } |
8270 | } | 8315 | } |
8271 | 8316 | ||
8272 | /* Wanted user specific configuration? */ | 8317 | /* Wanted user specific configuration? */ |
8273 | if (only_config != -1) { | 8318 | if (only_config != -1) { |
8274 | /* Here we get only in first for loop */ | 8319 | /* Here we get only in first for loop */ |
8275 | if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break; | 8320 | if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break; |
8276 | } else { | 8321 | } else { |
8277 | if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; | 8322 | if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; |
8278 | } | 8323 | } |
8279 | s.ConfigNum++; | 8324 | s.ConfigNum++; |
8280 | 8325 | ||
8281 | /* We want to use only one file descriptor for global and state machine debug output */ | 8326 | /* We want to use only one file descriptor for global and state machine debug output */ |
8282 | s.Config[i].UseGlobalDebugFile = true; | 8327 | s.Config[i].UseGlobalDebugFile = true; |
8283 | 8328 | ||
8284 | /* It makes no sense to open several debug logs... */ | 8329 | /* It makes no sense to open several debug logs... */ |
8285 | if (i != 0) { | 8330 | if (i != 0) { |
8286 | strcpy(s.Config[i].DebugLevel, s.Config[0].DebugLevel); | 8331 | strcpy(s.Config[i].DebugLevel, s.Config[0].DebugLevel); |
8287 | free(s.Config[i].DebugFile); | 8332 | free(s.Config[i].DebugFile); |
8288 | s.Config[i].DebugFile = strdup(s.Config[0].DebugFile); | 8333 | s.Config[i].DebugFile = strdup(s.Config[0].DebugFile); |
8289 | } else { | 8334 | } else { |
8290 | /* Just for first config */ | 8335 | /* Just for first config */ |
8291 | /* When user gave debug level on command line */ | 8336 | /* When user gave debug level on command line */ |
8292 | if (argc > 1 + start && GSM_SetDebugLevel(argv[1 + start], &di)) { | 8337 | if (argc > 1 + start && GSM_SetDebugLevel(argv[1 + start], &di)) { |
8293 | /* Debug level from command line will be used with phone too */ | 8338 | /* Debug level from command line will be used with phone too */ |
8294 | strcpy(s.Config[i].DebugLevel,argv[1 + start]); | 8339 | strcpy(s.Config[i].DebugLevel,argv[1 + start]); |
8295 | start++; | 8340 | start++; |
8296 | } else { | 8341 | } else { |
8297 | /* Try to set debug level from config file */ | 8342 | /* Try to set debug level from config file */ |
8298 | GSM_SetDebugLevel(s.Config[i].DebugLevel, &di); | 8343 | GSM_SetDebugLevel(s.Config[i].DebugLevel, &di); |
8299 | } | 8344 | } |
8300 | /* If user gave debug file in gammurc, we will use it */ | 8345 | /* If user gave debug file in gammurc, we will use it */ |
8301 | error=GSM_SetDebugFile(s.Config[i].DebugFile, &di); | 8346 | error=GSM_SetDebugFile(s.Config[i].DebugFile, &di); |
8302 | Print_Error(error); | 8347 | Print_Error(error); |
8303 | } | 8348 | } |
8304 | 8349 | ||
8305 | /* We wanted to read just user specified configuration. */ | 8350 | /* We wanted to read just user specified configuration. */ |
8306 | if (only_config != -1) {break;} | 8351 | if (only_config != -1) {break;} |
8307 | } | 8352 | } |
8308 | 8353 | #endif | |
8309 | /* Do we have enough parameters? */ | 8354 | /* Do we have enough parameters? */ |
8310 | if (argc == 1 + start) { | 8355 | if (argc == 1 + start) { |
8311 | HelpGeneral(); | 8356 | HelpGeneral(); |
8312 | printmsg("Too few parameters!\n"); | 8357 | printmsg("Too few parameters!\n"); |
8313 | exit(-2); | 8358 | exit(-2); |
8314 | } | 8359 | } |
8315 | 8360 | ||
8316 | /* Check used version vs. compiled */ | 8361 | /* Check used version vs. compiled */ |
8317 | if (!mystrncasecmp(GetGammuVersion(),VERSION,0)) { | 8362 | if (!mystrncasecmp(GetGammuVersion(),VERSION,0)) { |
8318 | printmsg("ERROR: version of installed libGammu.so (%s) is different to version of Gammu (%s)\n", | 8363 | printmsg("ERROR: version of installed libGammu.so (%s) is different to version of Gammu (%s)\n", |
8319 | GetGammuVersion(),VERSION); | 8364 | GetGammuVersion(),VERSION); |
8320 | exit(-1); | 8365 | exit(-1); |
8321 | } | 8366 | } |
8322 | 8367 | ||
8323 | /* Check parameters */ | 8368 | /* Check parameters */ |
8324 | while (Parameters[z].Function != NULL) { | 8369 | while (Parameters[z].Function != NULL) { |
8325 | if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) { | 8370 | if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) { |
8326 | if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) { | 8371 | if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) { |
8327 | Parameters[z].Function(argc - start, argv + start); | 8372 | Parameters[z].Function(argc - start, argv + start); |
8328 | break; | 8373 | break; |
8329 | } else { | 8374 | } else { |
8330 | count_failed = true; | 8375 | count_failed = true; |
8331 | } | 8376 | } |
8332 | } | 8377 | } |
8333 | z++; | 8378 | z++; |
8334 | } | 8379 | } |
8335 | 8380 | ||
8336 | /* Tell user when we did nothing */ | 8381 | /* Tell user when we did nothing */ |
8337 | if (Parameters[z].Function == NULL) { | 8382 | if (Parameters[z].Function == NULL) { |
8338 | HelpGeneral(); | 8383 | HelpGeneral(); |
8339 | if (count_failed) { | 8384 | if (count_failed) { |
8340 | printmsg("Bad parameter count!\n"); | 8385 | printmsg("Bad parameter count!\n"); |
8341 | } else { | 8386 | } else { |
8342 | printmsg("Bad option!\n"); | 8387 | printmsg("Bad option!\n"); |
8343 | } | 8388 | } |
8344 | } | 8389 | } |
8345 | 8390 | ||
8346 | /* Close debug output if opened */ | 8391 | /* Close debug output if opened */ |
8347 | if (di.df!=stdout) fclose(di.df); | 8392 | if (di.df!=stdout) fclose(di.df); |
8348 | //#endif // 0 | 8393 | //#endif // 0 |
8349 | fprintf(stderr,"kammu: Success. End. \n"); | 8394 | fprintf(stderr,"kammu: Success. End. \n"); |
8350 | exit(0); | 8395 | exit(0); |
8351 | } | 8396 | } |
8352 | 8397 | ||
8353 | /* How should editor hadle tabs in this file? Add editor commands here. | 8398 | /* How should editor hadle tabs in this file? Add editor commands here. |
8354 | * vim: noexpandtab sw=8 ts=8 sts=8: | 8399 | * vim: noexpandtab sw=8 ts=8 sts=8: |
8355 | */ | 8400 | */ |
8356 | 8401 | ||