| 1388 | */ |
| 1389 | |
| 1390 | static int level_cmp(var_rec *var1, var_rec *var2) |
| 1391 | { |
| 1392 | /* Levels are only comparable between matching media types */ |
| 1393 | |
| 1394 | if (var1->is_pseudo_html && !var2->is_pseudo_html) { |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
| 1398 | if (!var1->is_pseudo_html && strcmp(var1->mime_type, var2->mime_type)) { |
| 1399 | return 0; |
| 1400 | } |
| 1401 | /* The result of the above if statements is that, if we get to |
| 1402 | * here, both variants have the same mime_type or both are |
| 1403 | * pseudo-html. |
| 1404 | */ |
| 1405 | |
| 1406 | /* Take highest level that matched, if either did match. */ |
| 1407 | |
| 1408 | if (var1->level_matched > var2->level_matched) { |
| 1409 | return 1; |
| 1410 | } |
| 1411 | if (var1->level_matched < var2->level_matched) { |
| 1412 | return -1; |
| 1413 | } |
| 1414 | |
| 1415 | /* Neither matched. Take lowest level, if there's a difference. */ |
| 1416 | |
| 1417 | if (var1->level < var2->level) { |
| 1418 | return 1; |
| 1419 | } |
| 1420 | if (var1->level > var2->level) { |
| 1421 | return -1; |
| 1422 | } |
| 1423 | |
| 1424 | /* Tied */ |
| 1425 | |
| 1426 | return 0; |
| 1427 | } |
| 1428 | |
| 1429 | /* Finding languages. The main entry point is set_language_quality() |
| 1430 | * which is called for each variant. It sets two elements in the |