| 1883 | | //TODO: Remove me before 1.0. |
|---|
| 1884 | | private void old_collectStructs(char[][] lines, ConvParms* convParms) |
|---|
| 1885 | | { |
|---|
| 1886 | | char[] structName = lines[0].dup; |
|---|
| 1887 | | if ( startsWith(structName, "struct ") ) |
|---|
| 1888 | | { |
|---|
| 1889 | | structName = structName[7..structName.length]; |
|---|
| 1890 | | } |
|---|
| 1891 | | debug(structs)writefln("found typdef struct = %s", structName); |
|---|
| 1892 | | bool includeStruct = true; |
|---|
| 1893 | | int nStructs = 0; |
|---|
| 1894 | | while ( includeStruct && nStructs < convParms.noStructs.length ) |
|---|
| 1895 | | { |
|---|
| 1896 | | includeStruct = ! (structName == convParms.noStructs[nStructs++]); |
|---|
| 1897 | | } |
|---|
| 1898 | | if ( includeStruct ) |
|---|
| 1899 | | { |
|---|
| 1900 | | |
|---|
| 1901 | | char[][] structDef; /// all elements of the struct |
|---|
| 1902 | | bool invalidDStruct = false; |
|---|
| 1903 | | int pos = 1; |
|---|
| 1904 | | if ( lines[1][lines[1].length-1] == '{' ) |
|---|
| 1905 | | { |
|---|
| 1906 | | ++pos; |
|---|
| 1907 | | debug(structs)writefln("collectStructs %s",std.string.strip(lines[pos])); |
|---|
| 1908 | | while ( pos < lines.length && lines[pos][0] != '}' ) |
|---|
| 1909 | | { |
|---|
| 1910 | | structDef ~= lines[pos].dup; |
|---|
| 1911 | | //invalidDStruct = true; |
|---|
| 1912 | | //if ( std.string.find(lines[pos], ":") >= 0 ) |
|---|
| 1913 | | //{ |
|---|
| 1914 | | // invalidDStruct = true; |
|---|
| 1915 | | // debug(structs)writefln("- INVALID >>>%s<<<", lines[pos]); |
|---|
| 1916 | | //} |
|---|
| 1917 | | //else |
|---|
| 1918 | | if ( std.string.find(lines[pos], "[") >= 0 ) |
|---|
| 1919 | | { |
|---|
| 1920 | | // invalidDStruct = true; |
|---|
| 1921 | | // debug(structs)writefln("- INVALID ([)>>>%s<<<", lines[pos]); |
|---|
| 1922 | | } |
|---|
| 1923 | | else if ( std.string.find(lines[pos], "{") >= 0 ) |
|---|
| 1924 | | { |
|---|
| 1925 | | invalidDStruct = true; |
|---|
| 1926 | | debug(structs)writefln("- INVALID ({)>>>%s<<<", lines[pos]); |
|---|
| 1927 | | } |
|---|
| 1928 | | else if ( startsWith(std.string.strip(lines[pos]), '#') ) |
|---|
| 1929 | | { |
|---|
| 1930 | | // ignore |
|---|
| 1931 | | // writefln("collectStructs %s", std.string.strip(lines[pos])); |
|---|
| 1932 | | // debug(structs)writefln("= IGNORED >>>%s<<<", lines[pos]); |
|---|
| 1933 | | } |
|---|
| 1934 | | else if ( std.string.find(lines[pos], "(") >= 0 && std.string.find(lines[pos], "*") > 3) |
|---|
| 1935 | | { |
|---|
| 1936 | | // invalidDStruct = true; |
|---|
| 1937 | | // debug(structs)writefln("- INVALID (()>>>%s<<<", lines[pos]); |
|---|
| 1938 | | } |
|---|
| 1939 | | /* else if ( !primitiveType(lines[pos]) ) |
|---|
| 1940 | | { |
|---|
| 1941 | | switch ( structName ) |
|---|
| 1942 | | { |
|---|
| 1943 | | |
|---|
| 1944 | | // case "GtkWidget" |
|---|
| 1945 | | // ,"GdkRectangle" |
|---|
| 1946 | | // ,"GdkWindow" |
|---|
| 1947 | | // ,"GObject" |
|---|
| 1948 | | // ,"GtkAllocation" |
|---|
| 1949 | | // : |
|---|
| 1950 | | // // not invalid |
|---|
| 1951 | | // break; |
|---|
| 1952 | | |
|---|
| 1953 | | default: |
|---|
| 1954 | | if ( std.string.find(structName, "Event")>=0 ) |
|---|
| 1955 | | { |
|---|
| 1956 | | // try build a D struct |
|---|
| 1957 | | } |
|---|
| 1958 | | else |
|---|
| 1959 | | { |
|---|
| 1960 | | invalidDStruct = true; |
|---|
| 1961 | | debug(structs)writefln("- INVALID (not primitive) >>>%s<<<", lines[pos]); |
|---|
| 1962 | | } |
|---|
| 1963 | | break; |
|---|
| 1964 | | } |
|---|
| 1965 | | } |
|---|
| 1966 | | */ else |
|---|
| 1967 | | { |
|---|
| 1968 | | debug(structs)writefln("+ ADDED >>>%s<<<", lines[pos]); |
|---|
| 1969 | | } |
|---|
| 1970 | | ++pos; |
|---|
| 1971 | | } |
|---|
| 1972 | | } |
|---|
| 1973 | | |
|---|
| 1974 | | if ( pos < lines.length ) |
|---|
| 1975 | | { |
|---|
| 1976 | | collectedStructs ~= ""; |
|---|
| 1977 | | char[] line = lines[pos]; |
|---|
| 1978 | | ++pos; |
|---|
| 1979 | | char[] gtkStruct = convParms.realStrct.length > 0 |
|---|
| 1980 | | ? convParms.realStrct |
|---|
| 1981 | | : convParms.strct; |
|---|
| 1982 | | |
|---|
| 1983 | | if ( pos < lines.length && lines[pos][0] > ' ' ) |
|---|
| 1984 | | { |
|---|
| 1985 | | collectedStructs ~= "/**"; |
|---|
| 1986 | | if ( structName == gtkStruct ) |
|---|
| 1987 | | { |
|---|
| 1988 | | collectedStructs ~= " * Main Gtk struct."; |
|---|
| 1989 | | } |
|---|
| 1990 | | while ( pos < lines.length && lines[pos][0] > ' ' ) |
|---|
| 1991 | | { |
|---|
| 1992 | | collectedStructs ~= " * "~lines[pos++].dup; |
|---|
| 1993 | | } |
|---|
| 1994 | | collectedStructs ~= " */"; |
|---|
| 1995 | | } |
|---|
| 1996 | | else if ( structName == gtkStruct ) |
|---|
| 1997 | | { |
|---|
| 1998 | | collectedStructs ~= "/**"; |
|---|
| 1999 | | collectedStructs ~= " * Main Gtk struct."; |
|---|
| 2000 | | collectedStructs ~= " */"; |
|---|
| 2001 | | } |
|---|
| 2002 | | } |
|---|
| 2003 | | if ( (!invalidDStruct |
|---|
| 2004 | | || "GValue"==structName |
|---|
| 2005 | | || "GError"==structName |
|---|
| 2006 | | ) |
|---|
| 2007 | | && structDef.length>0 |
|---|
| 2008 | | && structName != "GPollFD" // todo contain "long fd" and "int fd" conditionally |
|---|
| 2009 | | ) |
|---|
| 2010 | | { |
|---|
| 2011 | | collectedStructs ~= "public struct "~structName~"\n{"; |
|---|
| 2012 | | |
|---|
| 2013 | | bool bitField = false; // if we are in a bit field |
|---|
| 2014 | | int bitFieldNr; // Number apended to bit field |
|---|
| 2015 | | int bits; // Bits used in the curent bit field |
|---|
| 2016 | | |
|---|
| 2017 | | for ( uint i; i < structDef.length; i++ ) |
|---|
| 2018 | | { |
|---|
| 2019 | | char[] elem = stringToGtkD(structDef[i], convParms, wrapper.getAliases()); |
|---|
| 2020 | | |
|---|
| 2021 | | if ( startsWith(elem, "*") && std.string.find(elem, "+/") < elem.length - 2) |
|---|
| 2022 | | { |
|---|
| 2023 | | elem = std.string.replace(elem, "/", "\\"); |
|---|
| 2024 | | } |
|---|
| 2025 | | if ( std.string.find(elem, "unsigned long") == 0) |
|---|
| 2026 | | { |
|---|
| 2027 | | elem = "ulong"~ elem[13..$]; |
|---|
| 2028 | | } |
|---|
| 2029 | | if ( std.string.find(structDef[i], ":") >= 0 && (std.string.find(structDef[i], ":") < std.string.find(structDef[i], "/+*") || std.string.find(structDef[i], "/+*") == -1) ) |
|---|
| 2030 | | { |
|---|
| 2031 | | if ( !bitField ) |
|---|
| 2032 | | { |
|---|
| 2033 | | bitField = true; |
|---|
| 2034 | | // just assume uint for now |
|---|
| 2035 | | // TODO get the type |
|---|
| 2036 | | collectedStructs ~= "\tuint bitfield"~ std.string.toString(bitFieldNr) ~";"; |
|---|
| 2037 | | } |
|---|
| 2038 | | if (std.string.find(elem, "/+*") > 0 && std.string.find(elem, "+/") < 0) |
|---|
| 2039 | | { |
|---|
| 2040 | | char[][] parts = std.string.split(elem, "/+*"); |
|---|
| 2041 | | collectedStructs ~= "//" ~ parts[0]; |
|---|
| 2042 | | collectedStructs ~= "/+*" ~ parts[1]; |
|---|
| 2043 | | } |
|---|
| 2044 | | else |
|---|
| 2045 | | { |
|---|
| 2046 | | collectedStructs ~= "//" ~ elem; |
|---|
| 2047 | | } |
|---|
| 2048 | | |
|---|
| 2049 | | bits += std.string.atoi(std.string.split(elem, ":")[1]); |
|---|
| 2050 | | if ( bits >= 32) |
|---|
| 2051 | | { |
|---|
| 2052 | | bitField = false; |
|---|
| 2053 | | bitFieldNr++; |
|---|
| 2054 | | bits = 0; |
|---|
| 2055 | | } |
|---|
| 2056 | | } |
|---|
| 2057 | | else if ( std.string.find(elem, "(") > 0 && !startsWith(elem, "* ") && !startsWith(elem, "/+*") ) |
|---|
| 2058 | | { |
|---|
| 2059 | | char[] funct; |
|---|
| 2060 | | for ( ; i < structDef.length; i++ ) |
|---|
| 2061 | | { |
|---|
| 2062 | | funct ~= stringToGtkD(structDef[i], convParms, wrapper.getAliases()); |
|---|
| 2063 | | |
|---|
| 2064 | | if ( std.string.find(structDef[i], ");") > 0 ) |
|---|
| 2065 | | break; |
|---|
| 2066 | | } |
|---|
| 2067 | | |
|---|
| 2068 | | funct = std.string.split(funct, ";")[0]; |
|---|
| 2069 | | char[][] splitFunct = std.string.split(funct, "("); |
|---|
| 2070 | | |
|---|
| 2071 | | collectedStructs ~= splitFunct[0] ~ " function(" ~ ((splitFunct[2][0..$-1] == "void") ? ")" : splitFunct[2]) ~ " " ~ splitFunct[1][1..$-2] ~ ";"; |
|---|
| 2072 | | } |
|---|
| 2073 | | else if ( std.string.find(elem, "#") == 0 ) |
|---|
| 2074 | | { |
|---|
| 2075 | | if ( std.string.find(elem, "#ifndef") == 0 ) |
|---|
| 2076 | | { |
|---|
| 2077 | | collectedStructs ~= "version("~ elem[8..$] ~")"; |
|---|
| 2078 | | collectedStructs ~= "{"; |
|---|
| 2079 | | } |
|---|
| 2080 | | else if ( std.string.find(elem, "#else") == 0 ) |
|---|
| 2081 | | { |
|---|
| 2082 | | collectedStructs ~= "}"; |
|---|
| 2083 | | collectedStructs ~= "else"; |
|---|
| 2084 | | collectedStructs ~= "{"; |
|---|
| 2085 | | } |
|---|
| 2086 | | else if ( std.string.find(elem, "#endif") == 0 ) |
|---|
| 2087 | | { |
|---|
| 2088 | | collectedStructs ~= "}"; |
|---|
| 2089 | | } |
|---|
| 2090 | | } |
|---|
| 2091 | | else |
|---|
| 2092 | | { |
|---|
| 2093 | | collectedStructs ~= elem; |
|---|
| 2094 | | } |
|---|
| 2095 | | } |
|---|
| 2096 | | collectedStructs ~= "\n}"; |
|---|
| 2097 | | // char[] gtkDStructName; |
|---|
| 2098 | | // if ( startsWith(structName, "Gtk") |
|---|
| 2099 | | // || startsWith(structName, "Gdk") |
|---|
| 2100 | | // ) |
|---|
| 2101 | | // { |
|---|
| 2102 | | // gtkDStructName = structName[3..structName.length]; |
|---|
| 2103 | | // } |
|---|
| 2104 | | // else if ( startsWith(structName, "Gst") ) |
|---|
| 2105 | | // { |
|---|
| 2106 | | // gtkDStructName = structName[3..structName.length]; |
|---|
| 2107 | | // } |
|---|
| 2108 | | // else if ( startsWith(structName, "G") ) |
|---|
| 2109 | | // { |
|---|
| 2110 | | // gtkDStructName = structName[1..structName.length]; |
|---|
| 2111 | | // } |
|---|
| 2112 | | // if ( gtkDStructName.length > 0 |
|---|
| 2113 | | // && "Color"!=gtkDStructName |
|---|
| 2114 | | // && "Rectangle"!=gtkDStructName |
|---|
| 2115 | | // && "Bitmap"!=gtkDStructName |
|---|
| 2116 | | // ) |
|---|
| 2117 | | // { |
|---|
| 2118 | | // collectedStructs ~= "\nalias "~structName~" "~gtkDStructName~";\n"; |
|---|
| 2119 | | // } |
|---|
| 2120 | | } |
|---|
| 2121 | | else //if ( structDef.length > 0 ) |
|---|
| 2122 | | { |
|---|
| 2123 | | switch ( structName ) |
|---|
| 2124 | | { |
|---|
| 2125 | | // TODO "public struct GdkEventClient;" confuses DMD!!!??? |
|---|
| 2126 | | case "GdkEventClient": |
|---|
| 2127 | | collectedStructs ~= "public struct "~structName~"{}"; |
|---|
| 2128 | | break; |
|---|
| 2129 | | |
|---|
| 2130 | | default: |
|---|
| 2131 | | collectedStructs ~= "public struct "~structName~"{}"; |
|---|
| 2132 | | break; |
|---|
| 2133 | | } |
|---|
| 2134 | | foreach ( char[] def; structDef ) |
|---|
| 2135 | | { |
|---|
| 2136 | | collectedStructs ~= "// "~stringToGtkD(def, convParms, wrapper.getAliases()); |
|---|
| 2137 | | collectedStructs ~= "// "~convParms.inFile; |
|---|
| 2138 | | } |
|---|
| 2139 | | } |
|---|
| 2140 | | collectedStructs ~= ""; |
|---|
| 2141 | | } |
|---|
| 2142 | | } |
|---|
| 2143 | | |
|---|