Mercurial > pidgin.yaz
comparison src/util.c @ 2372:2927c2c26fe6
[gaim-migrate @ 2385]
reformatting. nothing else.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 27 Sep 2001 19:17:11 +0000 |
parents | db02399a9ad7 |
children | cacaf7ace3a5 |
comparison
equal
deleted
inserted
replaced
2371:db02399a9ad7 | 2372:2927c2c26fe6 |
---|---|
84 if (daze) { | 84 if (daze) { |
85 if (hrs || min) { | 85 if (hrs || min) { |
86 if (hrs) { | 86 if (hrs) { |
87 if (min) { | 87 if (min) { |
88 g_snprintf(ret, 256, | 88 g_snprintf(ret, 256, |
89 "%d day%s, %d hour%s, %d minute%s.", | 89 "%d day%s, %d hour%s, %d minute%s.", |
90 daze, daze == 1 ? "" : "s", | 90 daze, daze == 1 ? "" : "s", |
91 hrs, hrs == 1 ? "" : "s", | 91 hrs, hrs == 1 ? "" : "s", min, min == 1 ? "" : "s"); |
92 min, min == 1 ? "" : "s"); | |
93 } else { | 92 } else { |
94 g_snprintf(ret, 256, | 93 g_snprintf(ret, 256, |
95 "%d day%s, %d hour%s.", | 94 "%d day%s, %d hour%s.", |
96 daze, daze == 1 ? "" : "s", | 95 daze, daze == 1 ? "" : "s", hrs, hrs == 1 ? "" : "s"); |
97 hrs, hrs == 1 ? "" : "s"); | |
98 } | 96 } |
99 } else { | 97 } else { |
100 g_snprintf(ret, 256, | 98 g_snprintf(ret, 256, |
101 "%d day%s, %d minute%s.", | 99 "%d day%s, %d minute%s.", |
102 daze, daze == 1 ? "" : "s", | 100 daze, daze == 1 ? "" : "s", min, min == 1 ? "" : "s"); |
103 min, min == 1 ? "" : "s"); | |
104 } | 101 } |
105 } else | 102 } else |
106 g_snprintf(ret, 256, "%d day%s.", daze, daze == 1 ? "" : "s"); | 103 g_snprintf(ret, 256, "%d day%s.", daze, daze == 1 ? "" : "s"); |
107 } else { | 104 } else { |
108 if (hrs) { | 105 if (hrs) { |
109 if (min) { | 106 if (min) { |
110 g_snprintf(ret, 256, | 107 g_snprintf(ret, 256, |
111 "%d hour%s, %d minute%s.", | 108 "%d hour%s, %d minute%s.", |
112 hrs, hrs == 1 ? "" : "s", | 109 hrs, hrs == 1 ? "" : "s", min, min == 1 ? "" : "s"); |
113 min, min == 1 ? "" : "s"); | |
114 } else { | 110 } else { |
115 g_snprintf(ret, 256, "%d hour%s.", hrs, hrs == 1 ? "" : "s"); | 111 g_snprintf(ret, 256, "%d hour%s.", hrs, hrs == 1 ? "" : "s"); |
116 } | 112 } |
117 } else { | 113 } else { |
118 g_snprintf(ret, 256, "%d minute%s.", min, min == 1 ? "" : "s"); | 114 g_snprintf(ret, 256, "%d minute%s.", min, min == 1 ? "" : "s"); |
438 | 434 |
439 fd = fopen(l->filename, "a"); | 435 fd = fopen(l->filename, "a"); |
440 | 436 |
441 if (flag) { /* is a new file */ | 437 if (flag) { /* is a new file */ |
442 if (logging_options & OPT_LOG_STRIP_HTML) { | 438 if (logging_options & OPT_LOG_STRIP_HTML) { |
443 fprintf(fd, "IM Sessions with %s\n", name); | 439 fprintf(fd, "IM Sessions with %s\n", name); |
444 }else { | 440 } else { |
445 fprintf(fd, "<HTML><HEAD><TITLE>"); | 441 fprintf(fd, "<HTML><HEAD><TITLE>"); |
446 fprintf(fd, "IM Sessions with %s", name); | 442 fprintf(fd, "IM Sessions with %s", name); |
447 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n"); | 443 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n"); |
448 } | 444 } |
449 } | 445 } |
450 | 446 |
451 return fd; | 447 return fd; |
452 } | 448 } |
454 g_snprintf(realname, sizeof(realname), "%s.log", normalize(name)); | 450 g_snprintf(realname, sizeof(realname), "%s.log", normalize(name)); |
455 fd = open_gaim_log_file(realname, &flag); | 451 fd = open_gaim_log_file(realname, &flag); |
456 | 452 |
457 if (fd && flag) { /* is a new file */ | 453 if (fd && flag) { /* is a new file */ |
458 if (logging_options & OPT_LOG_STRIP_HTML) { | 454 if (logging_options & OPT_LOG_STRIP_HTML) { |
459 fprintf(fd, "IM Sessions with %s\n", name); | 455 fprintf(fd, "IM Sessions with %s\n", name); |
460 }else { | 456 } else { |
461 fprintf(fd, "<HTML><HEAD><TITLE>"); | 457 fprintf(fd, "<HTML><HEAD><TITLE>"); |
462 fprintf(fd, "IM Sessions with %s", name); | 458 fprintf(fd, "IM Sessions with %s", name); |
463 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n"); | 459 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n"); |
464 } | 460 } |
465 } | 461 } |
466 | 462 |
467 return fd; | 463 return fd; |
468 } | 464 } |
1164 struct stat st; | 1160 struct stat st; |
1165 char *name; | 1161 char *name; |
1166 | 1162 |
1167 if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) { | 1163 if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) { |
1168 /* append a / if needed */ | 1164 /* append a / if needed */ |
1169 if (path[strlen(path) - 1] != '/') | 1165 if (path[strlen(path) - 1] != '/') { |
1170 name = g_strconcat(path, "/", NULL); | 1166 name = g_strconcat(path, "/", NULL); |
1171 else | 1167 } else { |
1172 name = g_strdup(path); | 1168 name = g_strdup(path); |
1169 } | |
1173 gtk_file_selection_set_filename(GTK_FILE_SELECTION(w), name); | 1170 gtk_file_selection_set_filename(GTK_FILE_SELECTION(w), name); |
1174 g_free(name); | 1171 g_free(name); |
1175 return 1; | 1172 return 1; |
1176 } | 1173 } |
1177 | 1174 |
1261 strcpy(dest, "<BR>"); | 1258 strcpy(dest, "<BR>"); |
1262 src++; | 1259 src++; |
1263 dest += 4; | 1260 dest += 4; |
1264 } else { | 1261 } else { |
1265 *dest++ = *src; | 1262 *dest++ = *src; |
1266 if (*src == '\0') return; | 1263 if (*src == '\0') |
1267 else src++; | 1264 return; |
1268 } | 1265 else |
1269 } | 1266 src++; |
1270 } | 1267 } |
1271 | 1268 } |
1272 | 1269 } |
1273 void away_on_login (char *mesg) | 1270 |
1271 | |
1272 void away_on_login(char *mesg) | |
1274 { | 1273 { |
1275 GSList *awy = away_messages; | 1274 GSList *awy = away_messages; |
1276 struct away_message *a, *message = NULL; | 1275 struct away_message *a, *message = NULL; |
1277 | 1276 |
1278 if (!blist) { | 1277 if (!blist) { |
1279 return; | 1278 return; |
1280 } | 1279 } |
1281 | 1280 |
1282 if (mesg == NULL) { | 1281 if (mesg == NULL) { |
1283 /* Use default message */ | 1282 /* Use default message */ |
1284 do_away_message((GtkWidget*)NULL, default_away); | 1283 do_away_message((GtkWidget *)NULL, default_away); |
1285 } else { | 1284 } else { |
1286 /* Use argument */ | 1285 /* Use argument */ |
1287 while (awy) { | 1286 while (awy) { |
1288 a = (struct away_message *)awy->data; | 1287 a = (struct away_message *)awy->data; |
1289 if (strcmp (a->name, mesg) == 0) { | 1288 if (strcmp(a->name, mesg) == 0) { |
1290 message = a; | 1289 message = a; |
1291 break; | 1290 break; |
1292 } | 1291 } |
1293 awy = awy->next; | 1292 awy = awy->next; |
1294 } | 1293 } |
1295 if (message == NULL) | 1294 if (message == NULL) |
1296 message = default_away; | 1295 message = default_away; |
1297 do_away_message((GtkWidget*)NULL, message); | 1296 do_away_message((GtkWidget *)NULL, message); |
1298 } | 1297 } |
1299 return; | 1298 return; |
1300 } | 1299 } |
1301 | 1300 |
1302 void system_log(enum log_event what, struct gaim_connection *gc, struct buddy *who, int why) | 1301 void system_log(enum log_event what, struct gaim_connection *gc, struct buddy *who, int why) |
1320 | 1319 |
1321 if (why & OPT_LOG_MY_SIGNON) { | 1320 if (why & OPT_LOG_MY_SIGNON) { |
1322 switch (what) { | 1321 switch (what) { |
1323 case log_signon: | 1322 case log_signon: |
1324 g_snprintf(text, sizeof(text), "+++ %s (%s) signed on @ %s", | 1323 g_snprintf(text, sizeof(text), "+++ %s (%s) signed on @ %s", |
1325 gc->username, (*gc->prpl->name)(), full_date()); | 1324 gc->username, (*gc->prpl->name)(), full_date()); |
1326 g_snprintf(html, sizeof(html), "<B>%s</B>", text); | 1325 g_snprintf(html, sizeof(html), "<B>%s</B>", text); |
1327 break; | 1326 break; |
1328 case log_signoff: | 1327 case log_signoff: |
1329 g_snprintf(text, sizeof(text), "+++ %s (%s) signed off @ %s", | 1328 g_snprintf(text, sizeof(text), "+++ %s (%s) signed off @ %s", |
1330 gc->username, (*gc->prpl->name)(), full_date()); | 1329 gc->username, (*gc->prpl->name)(), full_date()); |
1331 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); | 1330 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); |
1332 break; | 1331 break; |
1333 case log_away: | 1332 case log_away: |
1334 g_snprintf(text, sizeof(text), "+++ %s (%s) changed away state @ %s", | 1333 g_snprintf(text, sizeof(text), "+++ %s (%s) changed away state @ %s", |
1335 gc->username, (*gc->prpl->name)(), full_date()); | 1334 gc->username, (*gc->prpl->name)(), full_date()); |
1336 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); | 1335 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); |
1337 break; | 1336 break; |
1338 case log_back: | 1337 case log_back: |
1339 g_snprintf(text, sizeof(text), "+++ %s (%s) came back @ %s", | 1338 g_snprintf(text, sizeof(text), "+++ %s (%s) came back @ %s", |
1340 gc->username, (*gc->prpl->name)(), full_date()); | 1339 gc->username, (*gc->prpl->name)(), full_date()); |
1341 g_snprintf(html, sizeof(html), "%s", text); | 1340 g_snprintf(html, sizeof(html), "%s", text); |
1342 break; | 1341 break; |
1343 case log_idle: | 1342 case log_idle: |
1344 g_snprintf(text, sizeof(text), "+++ %s (%s) became idle @ %s", | 1343 g_snprintf(text, sizeof(text), "+++ %s (%s) became idle @ %s", |
1345 gc->username, (*gc->prpl->name)(), full_date()); | 1344 gc->username, (*gc->prpl->name)(), full_date()); |
1346 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); | 1345 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); |
1347 break; | 1346 break; |
1348 case log_unidle: | 1347 case log_unidle: |
1349 g_snprintf(text, sizeof(text), "+++ %s (%s) returned from idle @ %s", | 1348 g_snprintf(text, sizeof(text), "+++ %s (%s) returned from idle @ %s", |
1350 gc->username, (*gc->prpl->name)(), full_date()); | 1349 gc->username, (*gc->prpl->name)(), full_date()); |
1351 g_snprintf(html, sizeof(html), "%s", text); | 1350 g_snprintf(html, sizeof(html), "%s", text); |
1352 break; | 1351 break; |
1353 case log_quit: | 1352 case log_quit: |
1354 g_snprintf(text, sizeof(text), "+++ Program exit @ %s", full_date()); | 1353 g_snprintf(text, sizeof(text), "+++ Program exit @ %s", full_date()); |
1355 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); | 1354 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); |
1357 } | 1356 } |
1358 } else if (strcmp(who->name, who->show)) { | 1357 } else if (strcmp(who->name, who->show)) { |
1359 switch (what) { | 1358 switch (what) { |
1360 case log_signon: | 1359 case log_signon: |
1361 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) signed on @ %s", | 1360 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) signed on @ %s", |
1362 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); | 1361 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); |
1363 g_snprintf(html, sizeof(html), "<B>%s</B>", text); | 1362 g_snprintf(html, sizeof(html), "<B>%s</B>", text); |
1364 break; | 1363 break; |
1365 case log_signoff: | 1364 case log_signoff: |
1366 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) signed off @ %s", | 1365 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) signed off @ %s", |
1367 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); | 1366 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); |
1368 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); | 1367 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); |
1369 break; | 1368 break; |
1370 case log_away: | 1369 case log_away: |
1371 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) went away @ %s", | 1370 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) went away @ %s", |
1372 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); | 1371 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); |
1373 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); | 1372 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); |
1374 break; | 1373 break; |
1375 case log_back: | 1374 case log_back: |
1376 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) came back @ %s", | 1375 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) came back @ %s", |
1377 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); | 1376 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); |
1378 g_snprintf(html, sizeof(html), "%s", text); | 1377 g_snprintf(html, sizeof(html), "%s", text); |
1379 break; | 1378 break; |
1380 case log_idle: | 1379 case log_idle: |
1381 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) became idle @ %s", | 1380 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) became idle @ %s", |
1382 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); | 1381 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); |
1383 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); | 1382 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); |
1384 break; | 1383 break; |
1385 case log_unidle: | 1384 case log_unidle: |
1386 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) returned from idle @ %s", | 1385 g_snprintf(text, sizeof(text), |
1387 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); | 1386 "%s (%s) reported that %s (%s) returned from idle @ %s", gc->username, |
1387 (*gc->prpl->name)(), who->show, who->name, full_date()); | |
1388 g_snprintf(html, sizeof(html), "%s", text); | 1388 g_snprintf(html, sizeof(html), "%s", text); |
1389 break; | 1389 break; |
1390 default: | 1390 default: |
1391 fclose(fd); | 1391 fclose(fd); |
1392 return; | 1392 return; |
1394 } | 1394 } |
1395 } else { | 1395 } else { |
1396 switch (what) { | 1396 switch (what) { |
1397 case log_signon: | 1397 case log_signon: |
1398 g_snprintf(text, sizeof(text), "%s (%s) reported that %s signed on @ %s", | 1398 g_snprintf(text, sizeof(text), "%s (%s) reported that %s signed on @ %s", |
1399 gc->username, (*gc->prpl->name)(), who->name, full_date()); | 1399 gc->username, (*gc->prpl->name)(), who->name, full_date()); |
1400 g_snprintf(html, sizeof(html), "<B>%s</B>", text); | 1400 g_snprintf(html, sizeof(html), "<B>%s</B>", text); |
1401 break; | 1401 break; |
1402 case log_signoff: | 1402 case log_signoff: |
1403 g_snprintf(text, sizeof(text), "%s (%s) reported that %s signed off @ %s", | 1403 g_snprintf(text, sizeof(text), "%s (%s) reported that %s signed off @ %s", |
1404 gc->username, (*gc->prpl->name)(), who->name, full_date()); | 1404 gc->username, (*gc->prpl->name)(), who->name, full_date()); |
1405 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); | 1405 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); |
1406 break; | 1406 break; |
1407 case log_away: | 1407 case log_away: |
1408 g_snprintf(text, sizeof(text), "%s (%s) reported that %s went away @ %s", | 1408 g_snprintf(text, sizeof(text), "%s (%s) reported that %s went away @ %s", |
1409 gc->username, (*gc->prpl->name)(), who->name, full_date()); | 1409 gc->username, (*gc->prpl->name)(), who->name, full_date()); |
1410 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); | 1410 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); |
1411 break; | 1411 break; |
1412 case log_back: | 1412 case log_back: |
1413 g_snprintf(text, sizeof(text), "%s (%s) reported that %s came back @ %s", | 1413 g_snprintf(text, sizeof(text), "%s (%s) reported that %s came back @ %s", |
1414 gc->username, (*gc->prpl->name)(), who->name, full_date()); | 1414 gc->username, (*gc->prpl->name)(), who->name, full_date()); |
1415 g_snprintf(html, sizeof(html), "%s", text); | 1415 g_snprintf(html, sizeof(html), "%s", text); |
1416 break; | 1416 break; |
1417 case log_idle: | 1417 case log_idle: |
1418 g_snprintf(text, sizeof(text), "%s (%s) reported that %s became idle @ %s", | 1418 g_snprintf(text, sizeof(text), "%s (%s) reported that %s became idle @ %s", |
1419 gc->username, (*gc->prpl->name)(), who->name, full_date()); | 1419 gc->username, (*gc->prpl->name)(), who->name, full_date()); |
1420 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); | 1420 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); |
1421 break; | 1421 break; |
1422 case log_unidle: | 1422 case log_unidle: |
1423 g_snprintf(text, sizeof(text), "%s (%s) reported that %s returned from idle @ %s", | 1423 g_snprintf(text, sizeof(text), |
1424 gc->username, (*gc->prpl->name)(), who->name, full_date()); | 1424 "%s (%s) reported that %s returned from idle @ %s", gc->username, |
1425 (*gc->prpl->name)(), who->name, full_date()); | |
1425 g_snprintf(html, sizeof(html), "%s", text); | 1426 g_snprintf(html, sizeof(html), "%s", text); |
1426 break; | 1427 break; |
1427 default: | 1428 default: |
1428 fclose(fd); | 1429 fclose(fd); |
1429 return; | 1430 return; |
1443 fclose(fd); | 1444 fclose(fd); |
1444 } | 1445 } |
1445 | 1446 |
1446 unsigned char *utf8_to_str(unsigned char *in) | 1447 unsigned char *utf8_to_str(unsigned char *in) |
1447 { | 1448 { |
1448 int n = 0,i = 0; | 1449 int n = 0, i = 0; |
1449 int inlen; | 1450 int inlen; |
1450 unsigned char *result; | 1451 unsigned char *result; |
1451 | 1452 |
1452 if (!in) | 1453 if (!in) |
1453 return NULL; | 1454 return NULL; |
1454 | 1455 |
1455 inlen = strlen(in); | 1456 inlen = strlen(in); |
1456 | 1457 |
1457 result = g_malloc(inlen+1); | 1458 result = g_malloc(inlen + 1); |
1458 | 1459 |
1459 while(n <= inlen-1) { | 1460 while (n <= inlen - 1) { |
1460 long c = (long)in[n]; | 1461 long c = (long)in[n]; |
1461 if(c<0x80) | 1462 if (c < 0x80) |
1462 result[i++] = (char)c; | 1463 result[i++] = (char)c; |
1463 else { | 1464 else { |
1464 if((c&0xC0) == 0xC0) | 1465 if ((c & 0xC0) == 0xC0) |
1465 result[i++] = (char)(((c&0x03)<<6)|(((unsigned char)in[++n])&0x3F)); | 1466 result[i++] = |
1466 else if((c&0xE0) == 0xE0) { | 1467 (char)(((c & 0x03) << 6) | (((unsigned char)in[++n]) & 0x3F)); |
1468 else if ((c & 0xE0) == 0xE0) { | |
1467 if (n + 2 <= inlen) { | 1469 if (n + 2 <= inlen) { |
1468 result[i] = (char)(((c&0xF)<<4)|(((unsigned char)in[++n])&0x3F)); | 1470 result[i] = |
1469 result[i] = (char)(((unsigned char)result[i]) |(((unsigned char)in[++n])&0x3F)); | 1471 (char)(((c & 0xF) << 4) | (((unsigned char)in[++n]) & 0x3F)); |
1472 result[i] = | |
1473 (char)(((unsigned char)result[i]) | | |
1474 (((unsigned char)in[++n]) & 0x3F)); | |
1470 i++; | 1475 i++; |
1471 } else n += 2; | 1476 } else |
1472 } | 1477 n += 2; |
1473 else if((c&0xF0) == 0xF0) | 1478 } else if ((c & 0xF0) == 0xF0) |
1474 n += 3; | 1479 n += 3; |
1475 else if((c&0xF8) == 0xF8) | 1480 else if ((c & 0xF8) == 0xF8) |
1476 n += 4; | 1481 n += 4; |
1477 else if((c&0xFC) == 0xFC) | 1482 else if ((c & 0xFC) == 0xFC) |
1478 n += 5; | 1483 n += 5; |
1479 } | 1484 } |
1480 n++; | 1485 n++; |
1481 } | 1486 } |
1482 result[i] = '\0'; | 1487 result[i] = '\0'; |
1484 return result; | 1489 return result; |
1485 } | 1490 } |
1486 | 1491 |
1487 char *str_to_utf8(unsigned char *in) | 1492 char *str_to_utf8(unsigned char *in) |
1488 { | 1493 { |
1489 int n = 0,i = 0; | 1494 int n = 0, i = 0; |
1490 int inlen; | 1495 int inlen; |
1491 char *result = NULL; | 1496 char *result = NULL; |
1492 | 1497 |
1493 if (!in) | 1498 if (!in) |
1494 return NULL; | 1499 return NULL; |
1507 n++; | 1512 n++; |
1508 n += 2; | 1513 n += 2; |
1509 continue; | 1514 continue; |
1510 } | 1515 } |
1511 if ((c == 0x0D) || (c == 0x0A)) { | 1516 if ((c == 0x0D) || (c == 0x0A)) { |
1512 n++; continue; | 1517 n++; |
1518 continue; | |
1513 } | 1519 } |
1514 if (c < 128) | 1520 if (c < 128) |
1515 result[i++] = (char)c; | 1521 result[i++] = (char)c; |
1516 else { | 1522 else { |
1517 result[i++] = (char)((c>>6)|192); | 1523 result[i++] = (char)((c >> 6) | 192); |
1518 result[i++] = (char)((c&63)|128); | 1524 result[i++] = (char)((c & 63) | 128); |
1519 } | 1525 } |
1520 n++; | 1526 n++; |
1521 } | 1527 } |
1522 result[i] = '\0'; | 1528 result[i] = '\0'; |
1523 | 1529 |