comparison nnchat.c @ 132:10daf4660cae

Use th_get_hex_triplet().
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 30 Oct 2010 17:03:29 +0300
parents 352ec3c300e4
children ffe8bbd429fa
comparison
equal deleted inserted replaced
131:3896861974ac 132:10daf4660cae
70 }; 70 };
71 71
72 const int optListN = (sizeof(optList) / sizeof(optList[0])); 72 const int optListN = (sizeof(optList) / sizeof(optList[0]));
73 73
74 74
75 int getHexColorDef(char *str)
76 {
77 char *p = str;
78 int len, val = 0;
79
80 for (len = 0; *p && len < 6; p++, len++) {
81 if (*p >= '0' && *p <= '9') {
82 val *= 16; val += (*p - '0');
83 } else if (*p >= 'A' && *p <= 'F') {
84 val *= 16; val += (*p - 'A') + 10;
85 } else if (*p >= 'a' && *p <= 'f') {
86 val *= 16; val += (*p - 'a') + 10;
87 } else
88 return -1;
89 }
90
91 return (len == 6) ? val : -1;
92 }
93
94
95 void argShowHelp() 75 void argShowHelp()
96 { 76 {
97 th_args_help(stdout, optList, optListN, th_prog_name, 77 th_args_help(stdout, optList, optListN, th_prog_name,
98 "[options] <username> <password>"); 78 "[options] <username> <password>");
99 } 79 }
118 case 3: 98 case 3:
119 optServer = optArg; 99 optServer = optArg;
120 break; 100 break;
121 101
122 case 4: 102 case 4:
123 if ((optUserColor = getHexColorDef(optArg)) < 0) { 103 if ((optUserColor = th_get_hex_triplet(optArg)) < 0) {
124 THERR("Invalid color argument '%s', should be a RGB hex triplet '000000'.\n", 104 THERR("Invalid color argument '%s', should be a RGB hex triplet '000000'.\n",
125 optArg); 105 optArg);
126 return FALSE; 106 return FALSE;
127 } 107 }
128 THMSG(1, "Using color #%06x\n", optUserColor); 108 THMSG(1, "Using color #%06x\n", optUserColor);
573 if (*buf == 0) { 553 if (*buf == 0) {
574 return 1; 554 return 1;
575 } else if (!strncasecmp(buf, "/color ", 7)) { 555 } else if (!strncasecmp(buf, "/color ", 7)) {
576 /* Change color */ 556 /* Change color */
577 int tmpInt; 557 int tmpInt;
578 if ((tmpInt = getHexColorDef(trimLeft(buf + 7))) < 0) { 558 if ((tmpInt = th_get_hex_triplet(trimLeft(buf + 7))) < 0) {
579 printMsg("Invalid color value '%s'\n", buf+7); 559 printMsg("Invalid color value '%s'\n", buf+7);
580 return 1; 560 return 1;
581 } 561 }
582 optUserColor = tmpInt; 562 optUserColor = tmpInt;
583 printMsg("Setting color to #%06x\n", optUserColor); 563 printMsg("Setting color to #%06x\n", optUserColor);