1use Cwd; 2 3$VERSION = '0.81'; 4 5$name = $ARGV[0]; 6 7$cwd = getcwd(); 8 9# These are the standard constants. If you need to add any constants for 10# your local machine, it is better to put then in the .def file. 11 12@c=grep(!/^$/,split(/[,\s]+/,join(" ",grep(!/^\s*#/,split(/\n/,<<'End of constants'))))); 13 14# Constants go here 15 16# Ioctl 17 18:File 19 20FIOCLEX FIONCLEX FIONBIO FIOASYNC FIONREAD FIOSETOWN FIOGETOWN 21 22:Socket 23 24SIOCATMARK SIOCSPGRP SIOCGPGRP 25 26:CDROM 27 28CDROMEJECT 29CDROMREADTOCHDR 30CDROMSUBCHNL 31 32:Interface 33 34#SIOCGIFCONF SIOCSIFADDR SIOCGIFADDR SIOCSIFFLAGS SIOCGIFFLAGS SIOCSIFDSTADDR 35#SIOCGIFDSTADDR SIOCGIFBRDADDR SIOCSIFBRDADDR SIOCGIFNETMASK SIOCSIFNETMASK 36#SIOCGIFMETRIC SIOCSIFMETRIC 37 38:ARP 39 40#SIOCSARP SIOCGARP SIOCDARP 41 42:Routing 43 44# SIOCADDRT SIOCDELRT 45 46:Term 47 48VINTR VQUIT VERASE VKILL VEOF VEOL VEOL2 VSWTCH VSTART VSTOP VSUSP 49VDSUSP VREPRINT VDISCARD VWERASE VLNEXT 50 51BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC IXON 52IXANY IXOFF IMAXBEL 53 54OLCUC ONLCR OCRNL ONOCR ONLRET OFILL OFDEL NLDLY NL0 NL1 55CRDLY CR0 CR1 CR2 CR3 TABDLY TAB0 TAB1 TAB2 TAB3 XTABS 56BSDLY BS0 BS1 VTDLY VT0 VT1 FFDLY FF0 FF1 57B0 B50 B75 B110 B134 B150 B200 B300 B600 B1800 B2400 B4800 58B9600 B19200 B38400 B57600 B76800 B115200 B153600 B230400 59B307200 B460800 CSIZE CS5 CS6 CS7 CS8 CSTOPB CREAD PARENB 60PARODD HUPCL CLOCAL CIBAUD PAREXT CRTSXOFF CRTSCTS 61CBAUDEXT CIBAUDEXT ICANON XCASE ECHO ECHOE ECHOK ECHONL 62NOFLSH TOSTOP ECHOCTL ECHOPRT ECHOKE FLUSHO PENDIN IEXTEN 63 64TCGETS TCSETS TCSETSW TCSETSF TCGETA TCSETA TCSETAW TCSETAF TCSBRK 65TCXONC TCFLSH TIOCGPGRP TIOCSPGRP TIOCGSID TIOCGWINSZ TIOCSWINSZ 66TIOCMBIS TIOCMBIC TIOCMGET TIOCMSET TIOCSPPS TIOCGPPS TIOCGPPSEV 67 68End of constants 69 70 71$h = <<'End of header'; 72 73/* This will probably needs lots of system-dependent ifdef's. If you 74need to add anything for new constants, put them in the .def file. */ 75 76#ifdef I_SYS_IOCTL 77# include <sys/ioctl.h> 78#endif 79 80#ifdef I_TERMIOS 81# include <termios.h> 82#else 83# ifdef I_TERMIO 84# include <termio.h> 85# else 86# ifdef I_SGTTY 87# include <sgtty.h> 88# endif 89# endif 90#endif 91 92#ifdef sun 93# include <sys/filio.h> 94# include <sys/sockio.h> 95#endif 96 97#ifdef LINUX 98# include <linux/cdrom.h> 99#endif 100 101End of header 102 103 104foreach (@c) { 105 if(/^:/) { 106 $tag = $_; 107 $ctag{$tag} = []; 108 } elsif( $tag ) { 109 push(@{$ctag{$tag}},$_); 110 } 111} 112 113@c = grep(!/^:/,@c); 114 115open(C,"<$name.def"); 116 117while(<C>) { 118 last if /^--------/; 119 $h .= $_; 120} 121 122map( $c2{$_}=1, @c); 123@c = sort keys %c2; # Strip out duplicate entries 124 125while(<C>) { 126 next if /^#/; 127 push(@c,split(/[,\s]+/,$_)); 128} 129 130map(s/^\+//,@c); 131@notc = map((s/^-//,$notc{$_}=1),grep(/^-(.*)$/,@c)); 132@c = grep(!/^-/,@c); 133map($unique{$_}=1,@c); 134@c=keys %unique; 135 136foreach (sort @c) { 137 $f{substr($_,0,1)} .= " 138 if(strEQ(name,\"$_\")) 139# ifdef $_ ".($notc{$_}?" 140 goto disabled; ":" 141 return ((double)($_)); ")." 142# else 143 goto not_there; 144# endif 145"; 146} 147 148close(C); 149 150open(IN,"<xsproto"); 151open(OUT,">$name.xs"); 152 153print OUT <<'DONE'; 154/********************************************************** 155 156 Warning! Don't edit this file ($name.xs). Any changes made 157 will be lost. Edit xsproto, instead. 158 159**********************************************************/ 160DONE 161 162 163while(<IN>) { 164 s/<Directory>/$cwd/g; 165 s/<Constants>/join("",map(" case '$_':\n".$f{$_}. 166" break;\n" ,sort keys %f))/ge; 167 s/<Headers>/$h/g; 168 s/<Name>/$name/g; 169 s/<Version>/$VERSION/g; 170 print OUT; 171} 172close(IN); 173close(OUT); 174 175open(IN,"<pmproto"); 176open(OUT,">$name.pm"); 177 178print OUT <<DONE; 179################################################################## 180# 181# Warning! Don't edit this file ($name.pm). Any changes will 182# be lost. Edit pmproto instead. 183# 184################################################################## 185DONE 186 187while(<IN>) { 188 s/<Directory>/$cwd/g; 189 s/<Constants>/join("\n\t",map("$_",sort @c))/ge; 190 s/<Tags>/join("",map(" \"$_\" => [".join(",",map("\"$_\"",@{$ctag{$_}}))."],\n",keys %ctag))/ge; 191 s/<Name>/$name/g; 192 s/<Version>/$VERSION/g; 193 print OUT; 194} 195close(IN); 196close(OUT); 197 198 199