1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336
|
/*
xtools.c
27.3.99 tn
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/types.h>
#include <errno.h>
#include <ctype.h>
#include <grp.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk_imlib.h>
#include "xcdrdata.h"
#include "xcdroast.h"
#include "main.h"
extern gint debug;
extern scsi_devices_t **scsidevices;
extern gchar **alt_scsidevices;
extern setup_data_t setupdata;
extern cd_info_t cdinfo;
extern track_info_t **trackinfo;
extern GList *imagelist;
extern current_set_t curset;
extern track_read_set_t trackreadset;
extern GList *tocfiles;
extern GList *writelist;
extern gint bigfonts;
extern gint oldfontcode;
extern gchar sharedir[MAXLINE];
extern gchar prefixdir[MAXLINE];
extern writer_driver_t **drv_options;
extern gint runningbash2;
void define_tooltip(GtkWidget *widget, gchar *ttext) {
GtkTooltips *tip;
#ifdef YELLOW_TIPS
GdkColor bg;
GtkStyle *style;
#endif
/* tooltips wanted? */
if (setupdata.option_tooltips == 0) {
return;
}
tip = gtk_tooltips_new();
gtk_tooltips_set_tip(tip,widget,ttext,NULL);
/* set tip color (yellow) */
/*
*** Commented by C.W.Huang :
*** Why set tip color by hand? It should be set by the theme.
*** Due to an unknown feature or bug of gtk_widget_set_style(),
*** GdkFont of the tip will be changed so multibyte characters
*** cannot be displayed correctly!
*/
#ifdef YELLOW_TIPS
gtk_tooltips_force_window(tip);
if (!gdk_color_parse(TOOLTIPCOL,&bg)) {
g_warning("Can't parse color %s\n",TOOLTIPCOL);
return;
}
if (!gdk_color_alloc(gtk_widget_get_colormap(tip->tip_window),&bg)) {
g_warning("Cant allocate color %s\n",TOOLTIPCOL);
return;
}
style = gtk_style_copy(gtk_widget_get_style(tip->tip_window));
style->bg[GTK_STATE_NORMAL] = bg;
gtk_widget_set_style(tip->tip_window, style);
#endif
}
/* sets the font and color for a label widget.
if color/font is NULL then don't set color/font */
void set_font_and_color(GtkWidget *widget, gchar *font, gchar *color) {
GtkStyle *style;
GdkColor c;
gchar tmp[MAXLINE];
gchar *p;
style=gtk_style_copy(gtk_widget_get_style(widget));
if (font != NULL) {
gdk_font_unref(style->font);
/* make copy of string, because we use strtok later */
strcpy(tmp,font);
/* for unknown reasons in some locales the fonts do
not work correcly bold or italic when using fontset */
if (oldfontcode) {
/* now use only the definition up to the first comma */
p = strtok(tmp,",");
if (p) {
style->font = gdk_font_load(p);
} else {
style->font = gdk_font_load(tmp);
}
} else {
style->font = gdk_fontset_load(tmp);
}
/* check if valid font */
if (style->font == NULL) {
g_warning("Font %s not found\n",tmp);
return;
}
}
if (color != NULL) {
if (!gdk_color_parse(color,&c)) {
g_warning("Can't parse color %s\n",color);
return;
}
if (!gdk_color_alloc(gtk_widget_get_colormap(widget),&c)) {
g_warning("Cant allocate color %s\n",color);
return;
}
style->fg[GTK_STATE_NORMAL] = c;
}
gtk_widget_set_style(GTK_WIDGET(widget),style);
}
/* sets the color for a label widget.
if color is NULL then don't set color/font */
void set_labelcolor(GtkWidget *widget, gchar *color) {
GtkStyle *style;
GdkColor c;
style=gtk_style_copy(gtk_widget_get_style(widget));
if (color != NULL) {
if (!gdk_color_parse(color,&c)) {
g_warning("Can't parse color %s\n",color);
return;
}
if (!gdk_color_alloc(gtk_widget_get_colormap(widget),&c)) {
g_warning("Cant allocate color %s\n",color);
return;
}
style->fg[GTK_STATE_NORMAL] = c;
}
gtk_widget_set_style(GTK_WIDGET(widget),style);
}
/* sets a certain row in a clist to a font */
void set_clist_row_font(GtkCList *clist, gint row, gchar *ffont) {
GtkStyle *style;
gchar tmp[MAXLINE];
gchar *p;
style=gtk_style_copy(gtk_widget_get_style(GTK_WIDGET(clist)));
/* make copy of string, because we use strtok later */
strcpy(tmp,ffont);
gdk_font_unref(style->font);
/* for unknown reasons in some locales the fonts do
not work correcly bold or italic when using fontset */
if (oldfontcode) {
/* now use only the definition up to the first comma */
p = strtok(tmp,",");
if (p) {
style->font = gdk_font_load(p);
} else {
style->font = gdk_font_load(tmp);
}
} else {
style->font = gdk_fontset_load(tmp);
}
/* check if valid font */
if (style->font == NULL) {
g_warning("Font %s not found\n",tmp);
return;
}
gtk_clist_set_row_style(clist,row,style);
}
/* colors a certain row in a clist */
void set_clist_row_color(GtkCList *clist, gint row, gchar *color) {
GtkStyle *style;
GdkColor c;
style=gtk_style_copy(gtk_widget_get_style(GTK_WIDGET(clist)));
if (!gdk_color_parse(color,&c)) {
g_warning("Can't parse color %s\n",color);
return;
}
if (!gdk_color_alloc(gtk_widget_get_colormap(GTK_WIDGET(clist)),&c)) {
g_warning("Cant allocate color %s\n",color);
return;
}
style->fg[GTK_STATE_NORMAL] = c;
gtk_clist_set_row_style(clist,row,style);
}
/* free a simple glist structure */
void free_glist(GList **list) {
GList *loop;
gchar *dir;
loop = g_list_first(*list);
while(loop) {
dir = loop->data;
g_free(dir);
loop = loop->next;
}
g_list_free(*list);
*list = NULL;
}
/* copy a simple glist (which has only strings as elements) */
void copy_glist(GList **dst, GList *src) {
GList *loop;
gchar *dir;
/* clear target list */
free_glist(dst);
loop = g_list_first(src);
while(loop) {
dir = loop->data;
*dst = g_list_append(*dst,g_strdup(dir));
loop = loop->next;
}
}
/* remove a string-element from a glist */
void del_glist_link(GList **list, gchar *str) {
GList *loop;
gchar *dir;
if (str == NULL)
return;
loop = g_list_first(*list);
while(loop) {
dir = loop->data;
if (dir && strcmp(str,dir) == 0) {
g_free(dir);
*list = g_list_remove_link(*list, loop);
return;
}
loop = loop->next;
}
}
/* check if a string-element is in a glist */
/* return 1 if found, 0 if not */
gint check_in_glist(GList **list, gchar *str) {
GList *loop;
gchar *dir;
if (str == NULL)
return 0;
loop = g_list_first(*list);
while(loop) {
dir = loop->data;
if (dir && strcmp(str,dir) == 0) {
return 1;
}
loop = loop->next;
}
return 0;
}
/* check if a path is in a master-path-glist */
/* return 1 if found, 0 if not */
gint check_in_mstr_glist(GList **list, gchar *str) {
GList *loop;
mstr_redirect_t *mstr;
gchar *dir;
if (str == NULL)
return 0;
loop = g_list_first(*list);
while(loop) {
mstr = (mstr_redirect_t *) loop->data;
if (mstr) {
dir = mstr->mstr_path;
} else {
dir = NULL;
}
if (dir && strcmp(str,dir) == 0) {
return 1;
}
loop = loop->next;
}
return 0;
}
/* remove a string-element from a master-glist */
/* if there is a redir-path, remove only this and return */
void del_mstr_glist_link(GList **list, gchar *str) {
GList *loop;
mstr_redirect_t *mstr;
gchar *dir;
if (str == NULL)
return;
loop = g_list_first(*list);
while(loop) {
mstr = (mstr_redirect_t *) loop->data;
if (mstr) {
dir = mstr->mstr_path;
} else {
dir = NULL;
}
if (dir && strcmp(str,dir) == 0) {
/* found link */
if (mstr->redir_path) {
/* remove redir-path only */
g_free(mstr->redir_path);
mstr->redir_path = NULL;
return;
}
g_free(dir);
g_free(mstr);
*list = g_list_remove_link(*list, loop);
return;
}
loop = loop->next;
}
}
/* add a redir path to the master-glist */
void add_redir_mstr_glist(GList **list, gchar *str, gchar *new) {
GList *loop;
mstr_redirect_t *mstr;
gchar *dir;
if (str == NULL)
return;
loop = g_list_first(*list);
while(loop) {
mstr = (mstr_redirect_t *) loop->data;
if (mstr) {
dir = mstr->mstr_path;
} else {
dir = NULL;
}
if (dir && strcmp(str,dir) == 0) {
/* found link */
if (mstr->redir_path) {
/* remove redir-path first */
g_free(mstr->redir_path);
}
/* now set new value */
mstr->redir_path = g_strdup(new);
return;
}
loop = loop->next;
}
}
/* get a string in the form bla => foo and return only bla */
void extract_mstr_path_from_clist(gchar *in, gchar *out) {
gint i, found;
if (in == NULL || out == NULL)
return;
found = -1;
for (i = 0; i < strlen(in)-1; i++) {
if ((in[i] == '=') && (in[i+1] == '>')) {
found = i;
break;
}
}
if (found == -1) {
/* nothing found - return original string */
strcpy(out,in);
} else {
strncpy(out,in,found);
out[found] = '\0';
}
strip_string(out);
}
/* get the redir path from the master-glist */
void get_redir_path_from_mstr_glist(GList **list, gchar *str, gchar *ret) {
GList *loop;
mstr_redirect_t *mstr;
gchar *dir;
if (str == NULL)
return;
loop = g_list_first(*list);
while(loop) {
mstr = (mstr_redirect_t *) loop->data;
if (mstr) {
dir = mstr->mstr_path;
} else {
dir = NULL;
}
if (dir && strcmp(str,dir) == 0) {
/* found link */
if (mstr->redir_path) {
strcpy(ret, mstr->redir_path);
} else {
strcpy(ret, "");
}
return;
}
loop = loop->next;
}
strcpy(ret, "");
}
/* convert the devnr to a device-string. return 1 if devnr not found */
gint convert_devnr2devstring(gint devnr, gchar *str) {
gint i;
gchar tmp[MAXLINE];
i = 0;
while(scsidevices[i] != NULL) {
if (devnr == scsidevices[i]->devnr) {
g_snprintf(tmp,MAXLINE,"%s %s [%d,%d]",
scsidevices[i]->vendor, scsidevices[i]->model,
scsidevices[i]->bus, scsidevices[i]->id);
strcpy(str,tmp);
return 0;
}
i++;
}
strcpy(str,"");
return 1;
}
/* convert the devnr to a vendor-string. return 1 if devnr not found */
gint convert_devnr2vendor(gint devnr, gchar *str) {
gint i;
i = 0;
while(scsidevices[i] != NULL) {
if (devnr == scsidevices[i]->devnr) {
strcpy(str,scsidevices[i]->vendor);
return 0;
}
i++;
}
strcpy(str,"");
return 1;
}
/* convert the devnr to a model-string. return 1 if devnr not found */
gint convert_devnr2model(gint devnr, gchar *str) {
gint i;
i = 0;
while(scsidevices[i] != NULL) {
if (devnr == scsidevices[i]->devnr) {
strcpy(str,scsidevices[i]->model);
return 0;
}
i++;
}
strcpy(str,"");
return 1;
}
/* convert the devnr to a bus/id/lun-string. return 1 if devnr not found */
gint convert_devnr2busid(gint devnr, gchar *str) {
gint i;
i = 0;
while(scsidevices[i] != NULL) {
if (devnr == scsidevices[i]->devnr) {
if (scsidevices[i]->alt_dev == -1) {
g_snprintf(str,MAXLINE,"%d,%d,%d",
scsidevices[i]->bus,
scsidevices[i]->id,
0); /* lun always zero? */
} else {
/* return manual configured device-str */
strncpy(str,
alt_scsidevices[scsidevices[i]->alt_dev],
MAXLINE);
convert_escape(str);
}
return 0;
}
i++;
}
strcpy(str,"");
return 1;
}
/* convert kilobytes to MB/min string */
/* displays MB when using 2048b sectors. min like stored audiotracks on the
hard drive - this is not correct when displaying the minutesize of DATA
tracks. */
void convert_kbytes2mbminstring(gint kbytes, gchar *str) {
gint mb;
gint min;
gint sec;
gint frames;
gint frms;
mb = kbytes/1024;
/* we have a problem here, that we hit gint overflow on
large values - in this case round a little inexact */
if (mb < 2000) {
/* correct value */
frames = (kbytes*1024)/CDDAFRAME;
} else {
/* rounded value */
frames = (kbytes/CDDAFRAME)*1024;
}
min = frames/(60*75);
sec = (frames%(60*75))/75;
frms = (frames%75);
/* csec = (4*(frames%75)+1)/3; */
g_snprintf(str,MAXLINE,"%dMB / %d:%02d.%02d",mb,min,sec,frms);
}
/* convert kilobytes to MB/min string */
/* displays MB when using 2048b sectors. min like the size of track after
burned. The only correct min size display when burning data tracks */
void convert_kbytes2mbcorrectminstring(gint kbytes, gchar *str) {
gint mb;
gint min;
gint sec;
gint frames;
gint frms;
mb = kbytes/1024;
frames = kbytes/2;
min = frames/(60*75);
sec = (frames%(60*75))/75;
frms = (frames%75);
/* csec = (4*(frames%75)+1)/3; */
g_snprintf(str,MAXLINE,"%dMB / %d:%02d.%02d",mb,min,sec,frms);
}
/* convert frames to MB/min string */
/* should only be used for audio or full disk info */
void convert_frames2mbminstring(gint frames, gchar *str) {
gint mb;
gint min;
gint sec;
gint frms;
mb = ((frames/1024)*CDDAFRAME)/1024;
/* mb = ((frames/1024)*DATASECTORSIZE)/1024; */
min = frames/(60*75);
sec = (frames%(60*75))/75;
frms = (frames%75);
/* csec = (4*(frames%75)+1)/3; */
g_snprintf(str,MAXLINE,"%dMB / %d:%02d.%02d",mb,min,sec,frms);
}
/* convert frames/sectors to MB string */
/* note - this is only true for DATA-tracks */
void convert_frames2mbstring(gint frames, gchar *str) {
gint mb;
mb = frames*(DATASECTORSIZE/1024)/1024;
g_snprintf(str,MAXLINE,"%dMB",mb);
}
/* convert kbytes to MB string */
void convert_kbytes2mbstring(gint kbytes, gchar *str) {
gint mb;
mb = kbytes/1024;
g_snprintf(str,MAXLINE,"%dMB",mb);
}
/* convert frames to min string */
void convert_frames2minstring(gint frames, gchar *str) {
gint min;
gint sec;
gint frms;
min = frames/(60*75);
sec = (frames%(60*75))/75;
frms = (frames%75);
/* csec = (4*(frames%75)+1)/3; */
g_snprintf(str,MAXLINE,"%d:%02d.%02d",min,sec,frms);
}
/* creates a label that is right justified. Useful when
packing into a table */
GtkWidget *rightjust_gtk_label_new(gchar *txt) {
GtkWidget *align;
GtkWidget *label;
/* create right justify alignment */
align = gtk_alignment_new(1.0,0.5,0,0);
label = gtk_label_new(txt);
gtk_container_add(GTK_CONTAINER(align),label);
gtk_widget_show(label);
return align;
}
/* creates a label that is left justified. Useful when
packing into a table */
GtkWidget *leftjust_gtk_label_new(gchar *txt) {
GtkWidget *align;
GtkWidget *label;
/* create left justify alignment */
align = gtk_alignment_new(0.0,0.5,0,0);
label = gtk_label_new(txt);
gtk_container_add(GTK_CONTAINER(align),label);
gtk_widget_show(label);
return align;
}
/* get some info about our image-file */
void analyze_imgfile(gchar *path, gchar *file, GList **retlist) {
struct stat buf;
image_files_t *entry;
gchar tmp[MAXLINE];
gchar volid[MAXLINE];
glong size;
gint type,readable,isosize;
gint fd;
strncpy(tmp,path,MAXLINE-strlen(file)-2);
strcat(tmp,"/");
strcat(tmp,file);
stat(tmp,&buf);
/* check if regular file or link */
if (S_ISLNK(buf.st_mode) != 1 && S_ISREG(buf.st_mode) != 1) {
/* its not..so ignore */
return;
}
/* readable for us? */
fd = open(tmp, O_RDONLY,0);
if (fd == -1) {
readable = 0;
} else {
readable = 1;
close(fd);
}
size = (glong) buf.st_size;
isosize = 0;
/* now do some tests about file-contents */
if (strncmp(file+strlen(file)-4,".toc",4) == 0) {
type = 4;
} else if (strncmp(file+strlen(file)-4,".wav",4) == 0) {
/* wav-file */
if (check_wav_file(tmp) == 0) {
/* invalid wav */
type = 2;
} else {
/* valid wav */
type = 1;
}
} else {
/* data-file */
isosize = check_iso_file(-1,tmp,volid,0);
if (isosize == 0) {
/* unknown data */
type = 3;
} else {
/* iso9660 */
type = 0;
}
}
/* allocate memory and fill structure */
entry = g_new(image_files_t,1);
entry->path = g_strdup(tmp);
entry->mtime = buf.st_mtime;
entry->size = size;
entry->type = type;
entry->readable = readable;
entry->from_track = 0;
if (type == 0) {
entry->volname = g_strdup(volid);
} else {
entry->volname = NULL;
}
entry->title = NULL;
entry->artist = NULL;
entry->cddb_ttitle = NULL;
entry->cd_discid = NULL;
entry->isosize = isosize;
/* find if there is some information in the inf-file */
get_inf_tracktitle(tmp, entry);
/* add to list */
*retlist = g_list_append(*retlist, entry);
}
/* scans a directory for files matching the known extensions */
/* return 0 if ok, 1 on problem */
gint get_img_files(gchar *path, GList **retlist) {
gchar *img_ext[] = IMG_EXTENSIONS;
struct dirent *ent;
DIR *dir;
gint i,len,len2;
dir = opendir(path);
/* invalid directory */
if (dir == NULL)
return 1;
/* scan a directory */
while ( (ent = readdir(dir)) ) {
/* does the extension match? */
for(i = 0; img_ext[i] != NULL; i++) {
len = strlen(img_ext[i]);
len2 = strlen(ent->d_name);
/* skip to short filenames */
if (len2 < len) continue;
if (strncmp((ent->d_name)+len2-len,img_ext[i],len) == 0) {
/* we found a match */
analyze_imgfile(path,ent->d_name,retlist);
}
}
}
closedir(dir);
return 0;
}
/* print imagelist-memory-structure (debug purpose) */
void print_imagelist() {
GList *loop;
image_files_t *entry;
dodebug(2,"--------- imagelist glist ---------\n");
loop = g_list_first(imagelist);
while (loop) {
entry = loop->data;
dodebug(2,"path: %s, %ld, %d, %d, %d\n",entry->path,
entry->size, entry->type, entry->readable,
entry->isosize);
if (entry->volname != NULL) {
dodebug(2, "\tvolname: %s\n", entry->volname);
}
loop = loop->next;
}
}
/* sort the imagelist according to file names */
void sort_imagelist() {
GList *first, *last, *list1, *list2;
image_files_t *ent1, *ent2, *ent3;
first = g_list_first(imagelist);
last = g_list_last(imagelist);
for (list1 = first; list1 != last; list1 = list1->next) {
for (list2 = last; list2 != list1; list2 = list2->prev) {
ent1 = (image_files_t *) list1->data;
ent2 = (image_files_t *) list2->data;
if(strcmp(ent1->path,ent2->path) > 0) {
ent3 = ent1;
list1->data = list2->data;
list2->data = ent3;
}
}
}
}
/* search all image-directories and create a list of matching files */
/* return number of matching files */
gint scan_imagedirs() {
GList *loop;
gchar tmp[MAXLINE];
image_files_t *entry;
/* free the old image-list first */
loop = g_list_first(imagelist);
while (loop) {
entry = loop->data;
g_free(entry->path);
g_free(entry->volname);
g_free(entry->title);
g_free(entry->artist);
g_free(entry->cddb_ttitle);
g_free(entry);
loop = loop->next;
}
g_list_free(imagelist);
imagelist = NULL;
loop = g_list_first(setupdata.image_dirs);
while (loop) {
/* image-dir extracted */
strncpy(tmp,(gchar *)loop->data, MAXLINE);
get_img_files(tmp,&imagelist);
loop = loop->next;
}
/* sort the image-list */
sort_imagelist();
/* now we have a complete image-list */
if (debug) print_imagelist();
return (g_list_length(imagelist));
}
/* return a string saying which type of CD we are currently handling */
/* mode = 0: used check cd in drive, mode = 1: check trackreadset for
writing */
gint determine_cd_type(gchar *ret, gint mode) {
gint i;
gint audio,data;
gint type;
gchar tmp[MAXLINE];
GList *loop;
track_read_param_t *trackparam;
/* unknown type */
type = -1;
/* count tracks */
audio = 0;
data = 0;
trackparam = NULL;
if (mode == 0) {
/* check cdinfo-structure */
for (i = 0; i < cdinfo.nr_tracks; i++) {
if (trackinfo[i]->type == 0) {
data++;
} else {
audio++;
}
}
} else {
/* check trackreadset-structure */
loop = g_list_first(trackreadset.trackparams);
while(loop) {
trackparam = loop->data;
if (trackparam->tracktype == 0) {
data++;
} else {
audio++;
}
loop = loop->next;
}
/* now point trackparam back to first track for later use */
loop = g_list_first(trackreadset.trackparams);
if (loop) trackparam = loop->data;
else trackparam = NULL;
}
/* pure data-cd */
if (data == 1 && audio == 0) {
type = 0;
} else
/* pure audio-cd */
if (data == 0 && audio > 0) {
type = 1;
} else
/* mixed-mode */
if (mode == 0 && data == 1 && audio > 0 && trackinfo[0]->type == 0) {
type = 2;
} else
if (mode == 1 && data == 1 && audio > 0 && trackparam->tracktype == 0) {
type = 2;
} else
/* cd-extra */
if (mode == 0 && data == 1 && audio > 0 && cdinfo.have_cdextra) {
type = 3;
} else
if (mode == 1 && data == 1 && audio > 0 && trackparam->tracktype == 1) {
/* one data, at least one audio and first track audio */
type = 3;
} else
/* multisession */
if (data > 1 && audio == 0) {
type = 4;
}
/* enough for now */
switch (type) {
case 0:
strncpy(tmp,text(128),MAXLINE);
break;
case 1:
strncpy(tmp,text(129),MAXLINE);
break;
case 2:
strncpy(tmp,text(130),MAXLINE);
break;
case 3:
strncpy(tmp,text(131),MAXLINE);
break;
case 4:
strncpy(tmp,text(132),MAXLINE);
break;
default:
strncpy(tmp,text(127),MAXLINE);
break;
}
/* return value */
strncpy(ret,tmp,MAXLINE);
return (type);
}
/* calculate free space dependent of current image-dir setting */
/* return free kbytes and kbytes free in biggest imagedir */
gint determine_free_space(gint *biggestfree) {
gchar tmp[MAXLINE];
gchar path[MAXLINE];
GList *loop;
gint free, getfree;
gint maxfree;
/* get image-path */
if (curset.image_index == -1) {
strncpy(path,"",MAXLINE);
} else {
strncpy(path,(gchar *)g_list_nth_data(setupdata.image_dirs,
curset.image_index), MAXLINE);
/* this dir writeable? */
if (is_dir_writeable(path) == 1) {
/* its not */
*biggestfree = 0;
return 0;
}
}
free = 0;
maxfree = 0;
if (strcmp(path,"") != 0) {
free = get_free_space(path,NULL);
maxfree = free;
} else {
/* automatic setting - add all available space */
loop = g_list_first(setupdata.image_dirs);
while(loop) {
strcpy(tmp,(gchar *)loop->data);
/* this dir writeable? */
if (is_dir_writeable(tmp) == 1) {
/* no? skip */
loop = loop->next;
continue;
}
getfree = get_free_space(tmp,NULL);
free += getfree;
/* get biggest block */
if (getfree > maxfree)
maxfree = getfree;
loop = loop->next;
}
}
if (free < 0) {
g_warning("Invalid image-path setting?\n");
free = 0;
maxfree = 0;
}
*biggestfree = maxfree;
return free;
}
/* does look where to save the tracks before reading them.
Checks available diskspace and the image-directory-settings.
return 0 if ok, 1 on error/disk full, 2 if no writeable dir found */
/* return via call by reference the size (in kbytes) that will be
free due overwriting old files. Also return the freed size on
the directory with the most space available */
gint allocate_track_filenames(gint *overwrite, gint *overwritebiggest) {
gchar tmp[MAXLINE];
gchar biggestpath[MAXLINE];
gchar path[MAXLINE];
gchar ext[MAXLINE];
track_read_param_t *trackparam;
GList *loop, *loop2;
gint free;
gint size, tmpkbyte;
gint ret;
image_dir_free_t *freedir;
GList *freedirs;
struct stat buf;
gint overwritefree, overwritefreebiggest;
gint maxfree;
dodebug(10,"calling allocate_track_filenames\n");
overwritefree = 0;
overwritefreebiggest = 0;
ret = 0;
freedirs = NULL;
maxfree = 0;
strcpy(biggestpath,"");
/* build image-path/free structure */
if (curset.image_index == -1) {
/* automatic setting */
loop = g_list_first(setupdata.image_dirs);
while(loop) {
strcpy(path,(gchar *)loop->data);
/* this dir writeable? */
if (is_dir_writeable(path) == 1) {
/* no? skip */
loop = loop->next;
continue;
}
free = get_free_space(path,NULL);
freedir = g_new(image_dir_free_t,1);
freedir->path = g_strdup(path);
freedir->free = free;
freedirs = g_list_append(freedirs,freedir);
/* path with biggest available block? */
if (free > maxfree) {
maxfree = free;
strcpy(biggestpath,path);
}
loop = loop->next;
}
/* no dirs writeable */
if (freedirs == NULL) {
*overwrite = 0;
*overwritebiggest = 0;
return 2;
}
} else {
/* single path */
strncpy(path,(gchar *)g_list_nth_data(setupdata.image_dirs,
curset.image_index), MAXLINE);
/* this dir writeable? */
if (is_dir_writeable(path) == 1) {
*overwrite = 0;
*overwritebiggest = 0;
return 2;
}
free = get_free_space(path,NULL);
freedir = g_new(image_dir_free_t,1);
freedir->path = g_strdup(path);
freedir->free = free;
freedirs = g_list_append(freedirs,freedir);
maxfree = free;
strcpy(biggestpath,path);
}
/* now we have a structure with all path we are allowed to
save data in and how much space is available there */
/* loop through all available tracks */
loop = g_list_first(trackreadset.trackparams);
while (loop) {
trackparam = loop->data;
if (trackparam->tracktype == 0)
strcpy(ext,"img");
else
strcpy(ext,"wav");
/* how much space needs this track? */
size = trackparam->kbyte;
strcpy(path,"");
/* where is enough space for it? */
loop2 = g_list_first(freedirs);
while (loop2) {
freedir = loop2->data;
/* build temporary filename */
g_snprintf(tmp,MAXLINE, "%s/%s-%02d.%s", freedir->path,
curset.file_prefix,
trackparam->starttrack, ext);
/* already a file with this name on hd? */
if (stat(tmp,&buf) == 0) {
/* file exists */
tmpkbyte = buf.st_size/1024;
overwritefree += tmpkbyte;
/* file in directory with most space? */
if (strcmp(freedir->path,biggestpath) == 0) {
overwritefreebiggest += tmpkbyte;
}
} else {
tmpkbyte = 0;
}
/* enough free? consider space that is freed
when we overwrite a file (tmpkbyte) */
if (size < (freedir->free + tmpkbyte)) {
/* found freespace */
strcpy(path,freedir->path);
freedir->free-=size - tmpkbyte;
break;
}
loop2 = loop2->next;
}
/* no free space found? */
if (strcmp(path,"") == 0) {
ret = 1;
break;
}
/* tmp does contain now our valid filename */
g_free(trackparam->trackfile);
trackparam->trackfile = g_strdup(tmp);
loop = loop->next;
}
/* free image-path/free structure */
loop2 = g_list_first(freedirs);
while (loop2) {
freedir = loop2->data;
g_free(freedir->path);
g_free(freedir);
loop2 = loop2->next;
}
g_list_free(freedirs);
*overwrite = overwritefree;
*overwritebiggest = overwritefreebiggest;
if (debug > 1) {
print_trackreadset();
}
return ret;
}
/* does scan the image-structure for toc-files.
Takes current image-dir-setting into account. Return number
of found toc files or 0. Newest file is on top */
gint scan_for_toc_files() {
GList *loop;
image_files_t *entry;
gchar basename[MAXLINE];
gchar ipath[MAXLINE];
gchar *p;
time_t fdate;
/* clear old list */
g_list_free(tocfiles);
tocfiles = NULL;
fdate = 0;
loop = g_list_first(imagelist);
while (loop) {
entry = loop->data;
/* toc-file */
if (entry->type == 4) {
/* get the basedir */
strncpy(basename,entry->path,MAXLINE);
p = rindex(basename,'/');
*p = '\0';
if (strcmp(basename,"") == 0) {
strcpy(basename,"/");
}
/* now check if the basedir fits in the currently
set image-path */
if (curset.image_index != -1) {
strncpy(ipath, (gchar *)g_list_nth_data(
setupdata.image_dirs,
curset.image_index), MAXLINE);
/* does not fit - skip */
if (strcmp(ipath, basename) != 0) {
loop = loop->next;
continue;
}
}
/* if new file newer than the old one */
if (entry->mtime < fdate) {
/* append at back */
tocfiles = g_list_append(tocfiles,entry->path);
} else {
/* prepend at front */
tocfiles = g_list_prepend(tocfiles,entry->path);
fdate = entry->mtime;
}
}
loop = loop->next;
}
return g_list_length(tocfiles);
}
/* this function is called whenever a dialog window idles on the screen
and we want that events are processed and if there are no events
no CPU-time is wasted */
void wait_and_process_events() {
while (gtk_events_pending())
gtk_main_iteration();
usleep(100);
}
/* check if all files scheduled for writing does exist and have
the right size. Return 0 if all ok, 1 if all files there but with
wrong size, 2 if files missing and 3 if no permission to read/invalid */
gint check_write_files(gint nosizecheck) {
GList *loop;
track_read_param_t *trackparam;
struct stat buf;
glong size;
gint sumframes;
gint fd;
gint errsize, diff;
sumframes = 0;
errsize = 0;
loop = g_list_first(trackreadset.trackparams);
while(loop) {
trackparam = loop->data;
if (stat(trackparam->trackfile, &buf) != 0) {
/* no such file */
return 2;
}
/* check if regular file or link */
if (S_ISLNK(buf.st_mode) != 1 && S_ISREG(buf.st_mode) != 1) {
/* its not */
return 3;
}
/* readable for us? */
fd = open(trackparam->trackfile, O_RDONLY,0);
if (fd == -1) {
return 3;
} else {
close(fd);
}
if (trackparam->tracktype == 0) {
/* datatrack */
size = trackparam->frames * DATASECTORSIZE;
sumframes += trackparam->frames;
} else {
/* audiotrack */
size = trackparam->frames * CDDAFRAME;
sumframes += trackparam->frames;
}
/* check size of file - allow a offset of 4096 bytes */
/* and offset of 152*2048 (leadout+runout sectors) */
/* (and allow offset of 44 bytes (wavheader)) */
diff = abs(size - (glong) buf.st_size);
if (diff != 0 && diff != 4096 && diff != 152*2048 && diff != 44) {
/* a file with wrong size found? */
errsize++;
}
loop = loop->next;
}
/* g_print("sumframes: %d\n", sumframes); */
if (errsize == 0 || nosizecheck) {
/* all ok */
return 0;
} else {
/* files with wrong sizes */
return 1;
}
}
/* get the size of a track given by filename from imagelist (in bytes) */
/* or -1 when not found */
glong get_size_from_imagelist(gchar *tname) {
GList *loop;
image_files_t *entry;
loop = g_list_first(imagelist);
while (loop) {
entry = loop->data;
if (strcmp(tname,entry->path) == 0) {
return (entry->size);
}
loop = loop->next;
}
return -1;
}
/* get the type of a track given by filename from imagelist */
/* or -1 when not found */
gint get_type_from_imagelist(gchar *tname) {
GList *loop;
image_files_t *entry;
loop = g_list_first(imagelist);
while (loop) {
entry = loop->data;
if (strcmp(tname,entry->path) == 0) {
return (entry->type);
}
loop = loop->next;
}
return -1;
}
/* get the number of a track given by filename from imagelist */
/* or -1 when not found */
gint get_tracknr_from_imagelist(gchar *tname) {
GList *loop;
image_files_t *entry;
loop = g_list_first(imagelist);
while (loop) {
entry = loop->data;
if (strcmp(tname,entry->path) == 0) {
return (entry->from_track);
}
loop = loop->next;
}
return -1;
}
image_files_t *get_entry_from_imagelist(gchar *tname) {
GList *loop;
image_files_t *entry;
loop = g_list_first(imagelist);
while (loop) {
entry = loop->data;
if (tname && strcmp(tname,entry->path) == 0) {
return entry;
}
loop = loop->next;
}
return NULL;
}
/* get the discid of a track given by filename from imagelist */
/* or 1 when not found */
gint get_discid_from_imagelist(gchar *tname, gchar *ret) {
GList *loop;
image_files_t *entry;
loop = g_list_first(imagelist);
while (loop) {
entry = loop->data;
if (strcmp(tname,entry->path) == 0) {
if (entry->cd_discid == NULL)
return 1;
strcpy(ret, entry->cd_discid);
return 0;
}
loop = loop->next;
}
return 1;
}
/* get the volname of a track given by filename from imagelist */
/* or 1 when not found */
gint get_volname_from_imagelist(gchar *tname, gchar *ret) {
GList *loop;
image_files_t *entry;
loop = g_list_first(imagelist);
while (loop) {
entry = loop->data;
if (strcmp(tname,entry->path) == 0) {
if (entry->volname == NULL)
return 1;
strcpy(ret, entry->volname);
return 0;
}
loop = loop->next;
}
return 1;
}
/* is valid wav-file and in cd-quality? */
/* return 1 if, 0 if not */
gint check_wav_file(gchar *wavname) {
guchar waveHdr[44];
gint fd;
fd = open (wavname, O_RDONLY, 0);
if (fd == -1) {
return 0;
}
read(fd, &waveHdr, sizeof(waveHdr));
if (!is_std_wav_file(waveHdr)) {
/* no wav at all */
close(fd);
return 0;
}
/* is it in cd-quality? */
if (!is_in_cd_quality(waveHdr)) {
close(fd);
return 0;
}
/* passed all tests */
close(fd);
return 1;
}
/* small thing for iso-check */
gint empty(gchar c) {
return (c == 0 || c == ' ');
}
/* check if valid iso9660-image */
/* return number of sectors if, 0 if not */
/* if isoname set to NULL then query drive directly */
gint check_iso_file(gint devnr, gchar *isoname, gchar *volid, gint startsec) {
gchar buf[DATASECTORSIZE];
gchar tmp[MAXLINE];
gchar c;
gint i,j,k,count;
gint volsize;
if (isoname != NULL) {
/* read from file */
if (read_info_sector_from_file(isoname,buf,sizeof(buf)) == 0) {
return 0;
}
} else {
/* read from device */
if (read_info_sector_from_dev(devnr,buf,sizeof(buf), startsec) == 0) {
return 0;
}
}
/* search iso9660-signature */
if (strncmp(buf, "\001CD001\001", 8) != 0) {
return 0;
}
/* ok, we got an iso9660-image.
As a bonus extract volumne-name if requested */
if (volid != NULL) {
count = 0;
for(i = 40; i < 72; i++) {
if (empty(buf[i]))
continue;
for (j = i+1; j < 72; j++) {
if (!buf[j] || (j < 72-1
&& empty(buf[j]) && empty(buf[j+1])))
break;
}
for (k = i; k < j; k++) {
c = buf[k];
if (isprint((gint)c) || isspace((gint)c)) {
tmp[count++] = c;
}
}
i = j;
}
tmp[count] = '\0';
strcpy(volid,tmp);
}
/* now also extract the size of the image */
volsize = ((buf[80] & 0xff) |
((buf[81] & 0xff) << 8) |
((buf[82] & 0xff) << 16) |
((buf[83] & 0xff) << 24));
return volsize;
}
/* get cd toc and do read the iso9660-volid if possible */
void get_cd_toc_and_volid(gint devnr) {
gint i, volsize;
gchar tmp[MAXLINE];
get_cd_toc(devnr);
/* no cd loaded? */
if (cdinfo.nr_tracks <= 0) {
return;
}
strcpy(tmp,"");
/* scan every data track */
#ifdef SCANEVERYTRACK
for (i = 0; i < cdinfo.nr_tracks; i++) {
#else
for (i = 0; i < 1; i++) {
#endif
if (trackinfo[i]->type == 0) {
/* get iso-header for current track */
strcpy(tmp,"");
volsize = check_iso_file(devnr, NULL, tmp,
trackinfo[i]->start_sec);
if (strcmp(tmp,"") != 0) {
g_free(trackinfo[i]->volname);
trackinfo[i]->volname = g_strdup(tmp);
}
trackinfo[i]->isosize = volsize;
}
}
/* now set disk-title to iso9660-volname because thats all we
got at the moment */
/* last label still in buffer? */
if (strcmp(tmp,"") != 0) {
/* now check we have currently another title */
if (cdinfo.cddb_dtitle == NULL) {
/* no? then use iso-header as title */
cdinfo.cddb_dtitle = g_strdup(tmp);
}
}
}
/* do output debug messages */
void dodebug(gint debuglevel, gchar *fmt, ...) {
va_list ap;
gchar tmp[MAXLINE*10];
gchar *p;
/* output message when debuglevel is high enough */
if (debuglevel <= debug) {
/* put together the variable argument list */
va_start(ap,fmt);
vsprintf(tmp, fmt, ap);
va_end(ap);
/* remove first linefeed if any */
p = index(tmp,'\r');
if (p != NULL)
*p = ' ';
fprintf(stderr,"DGB%d: %s",debuglevel,tmp);
}
}
/* do write to logfile */
void dolog(gint loglevel, gchar *fmt, ...) {
va_list ap;
gchar tmp[MAXLINE*10];
gchar tmp2[MAXLINE];
char timestr[MAXLINE];
time_t acttime;
FILE *lfile;
/* output message when loglevel is high enough */
if (loglevel <= setupdata.loglevel && strcmp(setupdata.logfile,"")) {
/* put together the variable argument list */
va_start(ap,fmt);
vsprintf(tmp, fmt, ap);
va_end(ap);
acttime = time((time_t *) 0);
strcpy(timestr,ctime(&acttime));
/* remove last \n from timestr */
timestr[strlen(timestr)-1] = 0;
strncpy(tmp2, setupdata.logfile,MAXLINE);
check_tilde(tmp2);
lfile = fopen(tmp2,"a");
if (lfile == NULL) {
g_warning("Can't open logfile %s for writing\n",
tmp2);
return;
}
if (!fprintf(lfile,"%s XCDR %s: %s", timestr,
XCDROAST_VERSION, tmp)) {
g_warning("Error appending to logfile\n");
}
fclose(lfile);
}
}
/* notify-beep function */
/* type: 1 = completed task, 2 = warnings */
void dobeep(gint type) {
gint doit;
doit = 0;
switch (setupdata.notify_at) {
case 0:
/* we want no beep */
return;
case 1:
/* always */
doit = 1;
break;
case 2:
/* on completion */
if (type == 1)
doit = 1;
break;
case 3:
/* warnings only */
if (type == 2)
doit = 1;
break;
default:
return;
}
/* ok..we have to play a sound */
if (doit == 1) {
if (setupdata.notify_via == 0) {
/* dspdevice */
if (strcmp(setupdata.dsp_device,"") != 0) {
test_dspdevice_play();
}
} else {
/* internal speaker */
gdk_beep();
}
}
}
/* does check if the loaded devices are matching the current hardware */
/* returns 0 if ok, 1 if writer/read not match */
gint verify_loaded_config() {
gint i;
gint found1, found2, found3;
/* found any scsidevices at all? */
if (scsidevices[0] == NULL) {
/* now look if this is the condition we got in the config */
if (setupdata.writer_devnr == -1 &&
setupdata.readdev1_devnr == -1 &&
setupdata.readdev2_devnr == -1) {
/* ok..now devices, its ok */
return 0;
}
}
i = 0;
found1 = 0;
found2 = 0;
found3 = 0;
while(scsidevices[i] != NULL) {
/* check cdwriter */
if (setupdata.writer_devnr == scsidevices[i]->devnr) {
if ((strcmp(setupdata.writer_vendor,
scsidevices[i]->vendor) != 0) ||
(strcmp(setupdata.writer_model,
scsidevices[i]->model) != 0)) {
/* devices do not match */
return 1;
}
found1 = 1;
}
/* check readdev1 */
if (setupdata.readdev1_devnr == scsidevices[i]->devnr) {
if ((strcmp(setupdata.readdev1_vendor,
scsidevices[i]->vendor) != 0) ||
(strcmp(setupdata.readdev1_model,
scsidevices[i]->model) != 0)) {
/* devices do not match */
return 1;
}
found2 = 1;
}
/* check readdev2 */
if (setupdata.readdev2_devnr == scsidevices[i]->devnr) {
if ((strcmp(setupdata.readdev2_vendor,
scsidevices[i]->vendor) != 0) ||
(strcmp(setupdata.readdev2_model,
scsidevices[i]->model) != 0)) {
/* devices do not match */
return 1;
}
found3 = 1;
}
i++;
}
if (found1 == 0 || found2 == 0 || found3 == 0) {
/* devnr did not even match -> missing devices */
return 1;
}
return 0;
}
/* check if the image-dirs fit to our partitions */
/* return 0 if ok, 1 when there were errors (and we edited the list) */
gint verify_loaded_config2 () {
GList *loop, *loop2;
GList *fslist;
gchar dir[MAXLINE];
gchar fs[MAXLINE];
gint free;
gint fsuse;
gint dirsok;
/* now check if all the loaded image-dir exists and are each on
a own partition */
fslist = NULL;
dirsok = 0;
loop = g_list_first(setupdata.image_dirs);
while (loop) {
strcpy(dir,(gchar *)loop->data);
/* get filesystem for this dir */
free = get_free_space(dir,fs);
if (free == -1) {
/* no such directory */
/* mark to remove this entry from the list...*/
g_free(loop->data);
loop->data = NULL;
dirsok = 1;
} else {
/* check if this dir is already in use */
/* if not, add to fs-list */
fsuse = 0;
loop2 = g_list_first(fslist);
while (loop2) {
if (strcmp(fs, (gchar *)loop2->data) == 0) {
fsuse = 1;
}
loop2 = loop2->next;
}
if (fsuse == 0) {
/* not already used */
fslist = g_list_append(fslist, g_strdup(fs));
} else {
/* remove this entry from list */
g_free(loop->data);
loop->data = NULL;
dirsok = 1;
}
}
loop = loop->next;
}
/* free our temporary list */
free_glist(&fslist);
/* now really remove the marked dirs from list */
loop = g_list_first(setupdata.image_dirs);
while (loop) {
loop2 = loop->next;
if (loop->data == NULL) {
setupdata.image_dirs =
g_list_remove_link(setupdata.image_dirs, loop);
}
loop = loop2;
}
return dirsok;
}
/* check if this track match the inserted cd (verify tracks) */
/* return 0 if all ok, 1 on some error, 2 if file does not match to cd
and 3 if we dont want verify audio (checking for readable not necessary
because unreadable tracks are not displayed in verify menu */
gint check_vrfy_track(gchar *fname) {
gchar tmp[MAXLINE];
/* get the discid */
if (get_discid_from_imagelist(fname,tmp) != 0) {
/* no discid found in info-file? */
return 1;
}
/* compare with current cd */
if (strcmp(tmp, cdinfo.cddb_discid) != 0) {
return 2;
}
/* check if its an audio track and we want to verify them */
if (curset.noaudioverify == 1 &&
get_type_from_imagelist(fname) == 1) {
return 3;
}
/* all ok */
return 0;
}
/* build a trackname for image-lists */
void assign_trackname(gchar *titlestr, image_files_t *entry) {
/* see if there is cd text for this track */
if (entry->title && entry->artist &&
strcmp(entry->title,"") && strcmp(entry->artist,"")) {
g_snprintf(titlestr,MAXLINE,"%s / %s",
entry->title, entry->artist);
} else
if (entry->title && strcmp(entry->title,"")) {
strcpy(titlestr, entry->title);
} else
if (entry->cddb_ttitle && strcmp(entry->cddb_ttitle,"")) {
strcpy(titlestr, entry->cddb_ttitle);
} else
if (entry->volname && strcmp(entry->volname,"")) {
g_snprintf(titlestr,MAXLINE,"%s / ISO9660",
entry->volname);
}
}
/* check if a filename is on the writelist */
gint is_on_writelist(gchar *file) {
GList *loop;
gchar *track;
loop = g_list_first(writelist);
while (loop) {
track = loop->data;
if (track && strcmp(track, file) == 0) {
return 1;
}
loop = loop->next;
}
return 0;
}
/* free trackreadset */
void clear_trackreadset() {
GList *loop;
track_read_param_t *trackparam;
loop = g_list_first(trackreadset.trackparams);
while (loop) {
trackparam = loop->data;
g_free(trackparam->trackfile);
g_free(trackparam);
loop = loop->next;
}
if (trackreadset.trackparams)
g_list_free(trackreadset.trackparams);
trackreadset.trackparams = NULL;
g_free(trackreadset.tocfile);
trackreadset.tocfile = g_strdup("");
g_free(trackreadset.cdtitle);
trackreadset.cdtitle = g_strdup("");
trackreadset.nrtracks = 0;
trackreadset.cdsize = 0;
}
/* transform coordinates when bigfonts are used */
gint tbf(gint koord) {
if (bigfonts == 1) {
return (koord * XCDR_TOPLEVEL_X1)/XCDR_TOPLEVEL_X0;
} else {
return koord;
}
}
/* sort a glist */
void sort_glist(GList *filelist) {
GList *first, *last, *list1, *list2;
gchar *str1, *str2, *str3;
first = g_list_first(filelist);
last = g_list_last(filelist);
for (list1 = first; list1 != last; list1 = list1->next) {
for (list2 = last; list2 != list1; list2 = list2->prev) {
str1 = (gchar *) list1->data;
str2 = (gchar *) list2->data;
if (strcmp (str1, str2) > 0) {
str3 = str1;
list1->data = list2->data;
list2->data = str3;
}
}
}
}
/* determine path for helper apps */
void get_spawn_path(gchar *app, gchar *ret) {
struct stat buf;
/* when path is with a leading slash (absolute), do nothing */
if (app[0] == '/') {
strcpy(ret,app);
return;
}
/* otherwise its relative - add sharedir first */
g_snprintf(ret,MAXLINE,"%s/%s", sharedir, app);
/* now check if this file does exist */
if (stat(ret,&buf) != 0) {
/* it does not, so try the fallback */
g_snprintf(ret,MAXLINE,"%s/%s", prefixdir, app);
}
return;
}
/* reroute a command through the wrapper */
/* cmd is one of "CDRECORD", "MKISOFS", "CDDA2WAV", "READCD" */
gchar *get_wrap_path(gchar *cmd, gchar *ret) {
gchar tmp[MAXLINE];
g_snprintf(tmp,MAXLINE,"%s/%s %s", sharedir, WRAPPER, cmd);
strncpy(ret, tmp, MAXLINE);
return ret;
}
/* find a path with enough space to save a mkisofs-image */
/* return 0 if found, 1 on error/disk-full, return 2 if no writeable dir */
/* size is given in kbyte */
/* return via call by reference the size (in kbytes) that will be
free due overwriting old files. Also return the freed size on
the directory with the most space available */
gint allocate_master_filename(gint size, gint nr, gchar **return_fname,
gint *overwrite, gint *overwritebiggest) {
gchar tmp[MAXLINE];
gchar biggestpath[MAXLINE];
gchar path[MAXLINE];
GList *freedirs;
struct stat buf;
GList *loop, *loop2;
image_dir_free_t *freedir;
gint free,maxfree,tmpkbyte;
gint overwritefree, overwritefreebiggest;
gint ret;
overwritefree = 0;
overwritefreebiggest = 0;
ret = 0;
freedirs = NULL;
maxfree = 0;
strcpy(biggestpath,"");
/* build image-path/free structure */
if (curset.image_index == -1) {
/* automatic setting */
loop = g_list_first(setupdata.image_dirs);
while(loop) {
strcpy(path,(gchar *)loop->data);
/* this dir writeable? */
if (is_dir_writeable(path) == 1) {
/* no? skip */
loop = loop->next;
continue;
}
free = get_free_space(path,NULL);
freedir = g_new(image_dir_free_t,1);
freedir->path = g_strdup(path);
freedir->free = free;
freedirs = g_list_append(freedirs,freedir);
/* path with biggest available block? */
if (free > maxfree) {
maxfree = free;
strcpy(biggestpath,path);
}
loop = loop->next;
}
/* no dirs writeable */
if (freedirs == NULL) {
*overwrite = 0;
*overwritebiggest = 0;
return 2;
}
} else {
/* single path */
strncpy(path,(gchar *)g_list_nth_data(setupdata.image_dirs,
curset.image_index), MAXLINE);
/* this dir writeable? */
if (is_dir_writeable(path) == 1) {
*overwrite = 0;
*overwritebiggest = 0;
return 2;
}
free = get_free_space(path,NULL);
freedir = g_new(image_dir_free_t,1);
freedir->path = g_strdup(path);
freedir->free = free;
freedirs = g_list_append(freedirs,freedir);
maxfree = free;
strcpy(biggestpath,path);
}
/* now we have a structure with all path we are allowed to
save data in and how much space is available there */
strcpy(path,"");
/* look in which path we have space */
loop2 = g_list_first(freedirs);
while (loop2) {
freedir = loop2->data;
/* build temporary filename */
g_snprintf(tmp,MAXLINE, "%s/%s-%02d.%s", freedir->path,
curset.file_prefix, nr, "img");
/* already a file with this name on hd? */
if (stat(tmp,&buf) == 0) {
/* file exists */
tmpkbyte = buf.st_size/1024;
overwritefree += tmpkbyte;
/* file in directory with most space? */
if (strcmp(freedir->path,biggestpath) == 0) {
overwritefreebiggest += tmpkbyte;
}
} else {
tmpkbyte = 0;
}
/* enough free? consider space that is freed
when we overwrite a file (tmpkbyte) */
if (size < (freedir->free + tmpkbyte)) {
/* found freespace */
strcpy(path,freedir->path);
freedir->free-=size - tmpkbyte;
break;
}
loop2 = loop2->next;
}
/* no free space found? */
if (strcmp(path,"") == 0) {
ret = 1;
dodebug(1,"allocate_master_filename: no free space\n");
} else {
/* found a file */
if (return_fname != NULL) {
g_free(*return_fname);
*return_fname = g_strdup(tmp);
}
dodebug(1,"allocate_master_filename: got %s\n", tmp);
}
/* free image-path/free structure */
loop2 = g_list_first(freedirs);
while (loop2) {
freedir = loop2->data;
g_free(freedir->path);
g_free(freedir);
loop2 = loop2->next;
}
g_list_free(freedirs);
*overwrite = overwritefree;
*overwritebiggest = overwritefreebiggest;
return ret;
}
/* checks if the current writer does support SANYO burnproof */
gint does_support_burnproof() {
gint count;
if (drv_options == NULL) return 0;
count = 0;
while(drv_options[count] != NULL) {
if (strcmp(drv_options[count]->driver,"burnproof") == 0) {
return 1;
}
count++;
}
return 0;
}
/* do change the group rights for nonroot mode */
/* this seems only be required with /bin/sh being bash2 */
void fix_guid() {
dodebug(3,"Current gid/egid = %d/%d\n", getgid(), getegid());
/* if we are not bash2, no special handling */
if (!runningbash2)
return;
setregid(getegid(), getgid());
dodebug(3,"Current gid/egid after setregid = %d/%d\n", getgid(), getegid());
}
/* check if a given group-id matches a groupname */
gint match_group_name(gid_t gid, gchar *group) {
struct group *grp;
/* get structure containing name of group */
grp = getgrgid(gid);
if (grp && grp->gr_name) {
dodebug(3,"Matching gid = %d (%s)\n", gid, grp->gr_name);
if (strncmp(grp->gr_name,group,strlen(group)) == 0) {
/* does match */
return 1;
}
}
return 0;
}
/* parse the alternate device string (if any) */
void parse_alt_devs(gchar *str) {
gint i;
gchar *p;
gchar tmp[MAXLINE];
/* allocate memory */
alt_scsidevices = g_new0(gchar *,MAXDEVICES);
i = 0;
if (str == NULL) {
/* no devices, return */
return;
}
dodebug(2,"----- list of manually choosen device names -----\n");
/* get list of devices */
p = strtok(str,";");
while (p) {
strncpy(tmp,p,MAXLINE);
strip_string(tmp);
alt_scsidevices[i] = g_strdup(tmp);
dodebug(2,"alt_device: %d - \"%s\"\n",i, tmp);
p = strtok(NULL,";");
i++;
if (i >= MAXDEVICES) {
g_error("Error: More than %d devices given\n",MAXDEVICES);
}
}
return;
}
|