Mercurial > hg
comparison mcabber/src/commands.c @ 954:27a7b2f986f5
Fix a freeze with UTF-8 locales
Some commands cause an infinite loop when using an utf-8 locale.
It occurs when a screen refresh is done and there are trailing spaces in the
command line. This patch should fix it.
(Problem reported by "AL" in the mcabber conference room)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 02 Sep 2006 10:01:25 +0200 |
parents | 2016f52a167f |
children | 82aaa7afbd03 |
comparison
equal
deleted
inserted
replaced
953:1757f8b03b8f | 954:27a7b2f986f5 |
---|---|
319 { | 319 { |
320 char *p; | 320 char *p; |
321 char *xpline; | 321 char *xpline; |
322 cmd *curcmd; | 322 cmd *curcmd; |
323 | 323 |
324 // Remove trailing spaces: | |
325 for (p=line ; *p ; p++) | |
326 ; | |
327 for (p-- ; p>line && (*p == ' ') ; p--) | |
328 *p = 0; | |
329 | |
330 // We do alias expansion here | 324 // We do alias expansion here |
331 if (scr_get_multimode() != 2) | 325 if (scr_get_multimode() != 2) |
332 xpline = expandalias(line); | 326 xpline = expandalias(line); |
333 else | 327 else |
334 xpline = line; // No expansion in verbatim multi-line mode | 328 xpline = line; // No expansion in verbatim multi-line mode |
335 | 329 |
330 // We want to have a copy | |
331 if (xpline == line) | |
332 xpline = g_strdup(line); | |
333 | |
334 // Remove trailing spaces: | |
335 for (p=xpline ; *p ; p++) | |
336 ; | |
337 for (p-- ; p>xpline && (*p == ' ') ; p--) | |
338 *p = 0; | |
339 | |
336 // Command "quit"? | 340 // Command "quit"? |
337 if ((!strncasecmp(xpline, "/quit", 5)) && (scr_get_multimode() != 2) ) | 341 if ((!strncasecmp(xpline, "/quit", 5)) && (scr_get_multimode() != 2) ) |
338 if (!xpline[5] || xpline[5] == ' ') | 342 if (!xpline[5] || xpline[5] == ' ') |
339 return 255; | 343 return 255; |
340 | 344 |
341 // If verbatim multi-line mode, we check if another /msay command is typed | 345 // If verbatim multi-line mode, we check if another /msay command is typed |
342 if ((scr_get_multimode() == 2) && (strncasecmp(xpline, "/msay ", 6))) { | 346 if ((scr_get_multimode() == 2) && (strncasecmp(xpline, "/msay ", 6))) { |
343 // It isn't an /msay command | 347 // It isn't an /msay command |
344 scr_append_multiline(xpline); | 348 scr_append_multiline(xpline); |
349 g_free(xpline); | |
345 return 0; | 350 return 0; |
346 } | 351 } |
347 | 352 |
348 // Commands handling | 353 // Commands handling |
349 curcmd = cmd_get(xpline); | 354 curcmd = cmd_get(xpline); |
350 | 355 |
351 if (!curcmd) { | 356 if (!curcmd) { |
352 scr_LogPrint(LPRINT_NORMAL, "Unrecognized command. " | 357 scr_LogPrint(LPRINT_NORMAL, "Unrecognized command. " |
353 "Please see the manual for a list of known commands."); | 358 "Please see the manual for a list of known commands."); |
354 if (xpline != line) g_free(xpline); | 359 g_free(xpline); |
355 return 0; | 360 return 0; |
356 } | 361 } |
357 if (!curcmd->func) { | 362 if (!curcmd->func) { |
358 scr_LogPrint(LPRINT_NORMAL, | 363 scr_LogPrint(LPRINT_NORMAL, |
359 "This functionality is not yet implemented, sorry."); | 364 "This functionality is not yet implemented, sorry."); |
360 if (xpline != line) g_free(xpline); | 365 g_free(xpline); |
361 return 0; | 366 return 0; |
362 } | 367 } |
363 // Lets go to the command parameters | 368 // Lets go to the command parameters |
364 for (p = xpline+1; *p && (*p != ' ') ; p++) | 369 for (p = xpline+1; *p && (*p != ' ') ; p++) |
365 ; | 370 ; |
366 // Skip spaces | 371 // Skip spaces |
367 while (*p && (*p == ' ')) | 372 while (*p && (*p == ' ')) |
368 p++; | 373 p++; |
369 // Call command-specific function | 374 // Call command-specific function |
370 (*curcmd->func)(p); | 375 (*curcmd->func)(p); |
371 if (xpline != line) g_free(xpline); | 376 g_free(xpline); |
372 return 0; | 377 return 0; |
373 } | 378 } |
374 | 379 |
375 // process_line(line) | 380 // process_line(line) |
376 // Process a command/message line. | 381 // Process a command/message line. |