├── Configur ├── FAQ ├── FAQ.eng ├── HISTORY ├── HISTORY.eng ├── Install ├── Install.eng ├── LICENSES ├── LICENSES.eng ├── Makefile ├── Makefile.in ├── README ├── README.eng ├── TECHKNOW ├── TECHKNOW.eng ├── ToAdmin ├── ToAdmin.eng ├── _fdrc ├── _fdrc.dif ├── apply.c ├── archive.c ├── auth.c ├── auth.h ├── backend.c ├── browse.c ├── builtin.c ├── catalog.c ├── catalog.h ├── command.c ├── config.hin ├── custom.c ├── depend.h ├── device.h ├── dict.c ├── dirent.h ├── doscom.c ├── dosdisk.c ├── dosdisk.h ├── encode.c ├── encode.h ├── evalopt.c ├── evalopt.h ├── expfunc.c ├── fd.cat ├── fd.h ├── fd.man ├── fd.spec ├── fd_e.cat ├── fd_e.man ├── file.c ├── frontend.c ├── fsinfo.h ├── ftp.c ├── func.h ├── functabl.h ├── gentbl.c ├── gentbl.h ├── headers.h ├── hinsi.h ├── html.c ├── html.h ├── http.c ├── ime.c ├── info.c ├── input.c ├── kanji.hin ├── kanjicnv.c ├── kconv.c ├── kconv.h ├── kctype.h ├── libc.c ├── log.c ├── log.h ├── lsparse.c ├── lsparse.h ├── machine.h ├── main.c ├── makefile.b98 ├── makefile.bpc ├── makefile.d98 ├── makefile.dpc ├── makefile.g98 ├── makefile.gpc ├── makefile.l98 ├── makefile.lpc ├── malloc.c ├── malloc.h ├── mkcat.c ├── mkdict.c ├── mkdir_p.c ├── mkfuncno.c ├── mkkanji.c ├── mkmfdosb.sed ├── mkmfdosd.sed ├── mkmfdosg.sed ├── mkmfdosl.sed ├── mkmfsed.c ├── mktankan.c ├── mkunitbl.c ├── mntinfo.c ├── mntinfo.h ├── namelist.h ├── parse.c ├── parse.h ├── pathname.c ├── pathname.h ├── posixsh.c ├── posixsh.h ├── printf.c ├── printf.h ├── pty.c ├── realpath.c ├── realpath.h ├── rockridg.c ├── roman.c ├── roman.h ├── shell.c ├── socket.c ├── socket.h ├── statfs.c ├── stream.c ├── stream.h ├── string.c ├── string.h ├── sysemu.c ├── sysemu.h ├── system.c ├── system.h ├── term.c ├── term.h ├── termemu.c ├── termemu.h ├── termio.c ├── termio.h ├── time.c ├── time.h ├── tree.c ├── types.h ├── typesize.h ├── unixdisk.c ├── unixdisk.h ├── unixemu.h ├── url.c ├── url.h ├── urldisk.c ├── urldisk.h ├── version.h └── wait.h /LICENSES: -------------------------------------------------------------------------------- 1 | [FDclone3 $B$K4X$9$k%i%$%;%s%95,Dj(B] 2 | 3 | 4 | <0.$B=x(B> 5 | 6 | $B!!K\J8=q$O(B FDclone $B$N;HMQ5vBz$K$D$$$F5-$5$l$?$b$N$G$9!#(B 7 | 8 | $B!!(BFDclone $B$O%U%j!<%=%U%H%&%'%"$G$"$j!"$=$N;HMQ$K$"$?$C$F$OMx(B 9 | $BMQE*MWK>$r4^$a!"$3(B 10 | $B$3$G$O8D!9$N;vNc$KB($7$?>\:Y$K$D$$$F=R$Y$F$$$-$^$9!#(B 11 | 12 | 13 | <1.$BMQ8l$NDj5A(B> 14 | 15 | $B!!K\J8=q$G;HMQ$9$kMQ8l$K$D$$$F$^$:5,Dj$7$F$*$-$^$9!#K\J8=q$G(B 16 | $B$O!"FC$KCG$j$N$J$$8B$j!"0J2<$K5s$2$kC18l$K$D$$$F$O$3$3$K=q$+(B 17 | $B$l$?FCDj$N0UL#$GMQ$$$F$$$^$9!#(B 18 | 19 | $B%=!<%9(B 20 | $B%=!<%9%W%m%0%i%`0l<0!#0?$O!"$=$l$K%I%-%e%a%s%H$=$NB>(B 21 | $B$r4^$s$@%Q%C%1!<%80l<0!#(B 22 | 23 | $B%P%$%J%j(B 24 | $B%=!<%9%W%m%0%i%`0l<0$r%3%s%Q%$%k$7$FF@$i$l$k$r4^$s$@%Q%C%1!<(B 26 | $B%80l<0!#(B 27 | 28 | $BG[IU(B 29 | $B9-5A$G$O!"%=!<%9Kt$O%P%$%J%j$NJ#@=(B ($B2~JQ$NM-L5$rLd$o(B 30 | $B$J$$(B) $B$r:n@.$7!"Bh;0/?t$rBP>]$KG[$jM?$($k$3$H!#(B 32 | 33 | $BHRI[(B 34 | $B9-5A$NG[IU$N0l7ABV!#%=!<%9Kt$O%P%$%J%j$NJ#@=$r!"8x6&(B 35 | $B$N>l$G9-$/$"$^$M$/G[$jM?$($k$3$H!#(B 36 | 37 | $B0lN!#(B 47 | 48 | $B2~JQ(B 49 | $B85$N%=!<%9Kt$O%P%$%J%j$K0lIt 57 | 58 | $B!!695A$NG[IU$K$D$$$F$O!"2~JQ$NM-L5$rLd$o$:%=!<%9$b%P%$%J%j$b(B 59 | $B<+M3$K:FG[IU2DG=$G$9!#1DMx!&Hs1DMxEy!"MQES$rLd$o$:<+M3$K9T$J(B 60 | $B$C$F9=$$$^$;$s!#;0o$KF0:n$9$k$3$H$NJ]>Z$,I,MW$G$"$l$P!":F(B 64 | $BG[IUZ$7$F2<$5$$!#(B 65 | 66 | 67 | <3.$B:FHRI[$K$D$$$F(B> 68 | 69 | $B!!HRI[$K$D$$$F$O!"2~JQ$NM-L5$rLd$o$:%=!<%9!&%P%$%J%j6&$K:FHR(B 70 | $BI[2DG=$G$9!#695A$NG[IU$HF1MM!"MQES$rLd$o$:<+M3$K9T$J$C$F9=$$(B 71 | $B$^$;$s!#(B 72 | 73 | $B!!C"$7!":FHRI[$5$l$?$b$N$KBP$7$F:nZ$r:nl9g!"HRI[EPO?$O9T$J$o$J(B 79 | $B$/$F9=$$$^$;$s!#(B 80 | 81 | $B!!$^$?!"0lEYHRI[EPO?$5$l$?:FHRI[J*$KBP$9$k;0u5Z$SFbMF$,HRI[EPO?$5$l$?:FHRI[J*$+$i(B 83 | $BA4$/2~JQ$5$l$F$$$J$$>l9g$K8B$j!"$=$N:FHRI[$HF1Ey$N@UG$$r:nl9g!"$=$N;~E@$GHRI[EPO?$O(B 86 | $BL58z$H$J$j$^$9$N$G!":FEYHRI[EPO?$r9T$J$o$J$$8B$j$O:nr7o$rIUM?$7$?>l9g$O!";0r7o$O$=$l$K(B 91 | $B=>$$$^$9!#(B 92 | $B!!HRI[EPO?$r9T$J$($P!"0lr7o$r?/$5$J$$HO0O(B 93 | $B$K1w$$$F!"Fsr7o$r<+M3$K@_Dj$G$-$^(B 94 | $B$9$N$G!"Fsl9g$O!"FsD$7$^$;$s!#(B 98 | 99 | 100 | <4.$B:n 101 | 102 | $B!!0l$K1~$8!"I,MW$J>l9g(B 105 | $B$K$O%W%m%0%i%`$N2~Dj$r9T$J$$$^$9!#$^$?!"0-0U$"$k;EMM305!G=$r(B 106 | $B?%9~$^$:@5>o$KF0:n$9$k$3$H$rJ]>Z$7$^$9!#(B 107 | $B!!3Fl9g$O!"$=(B 108 | $B$N2~Dj$K1~$8$^$9!#(B 109 | 110 | $B!!HRI[EPO?$5$l$F$$$J$$:FHRI[J*$KBP$7$F$O!":n$K$b0l@Z1~$8$^(B 112 | $B$;$s!#(B 113 | $B!!$3$l$iMxMQ$7$^$9!#(B 115 | 116 | $B!!C"$7!";HMQ$K$"$?$C$F@8$8$?G!2?$J$kB;32$KBP$7$F$b!":nZ$77s$M$^$9$N$G!"3FMxMQ 121 | 122 | $B!!%=!<%9$NHRI[$K$D$$$F$O!"0ll9g$K8B$j!"HRI[EPO?$J$->l9g$b:nl9g$b!"%W%m%0%i%`%=!<%9ItJ,$K2~(B 126 | $BJQ$,$J$/!"%I%-%e%a%s%HKt$O%W%m%0%i%`$rDI2C$9$k$N$_$NJQ99$G$"(B 127 | $B$l$P!"0l@ZJQ99$N$J$$>l9g$HF1MM$K07$$$^$9!#(B 128 | $B!!$3$l$i$N>l9g!"%Q%C%1!<%87A>u$NJQ99!"B($A05=LJ}<0$d%Q%C%1!<(B 129 | $B%8L>Ey$NJQ99$K$D$$$F$OLd$$$^$;$s!#(B 130 | 131 | $B!!%W%m%0%i%`%=!<%9ItJ,!"$b$7$/$O(B Makefile $BEy$N@\4XM?$9$k%U%!%$%k72$K2~JQ$N$"$k>l9g!"%=!<%9HRI[EPO?$r9T$J(B 133 | $B$&$3$H$K$h$j:n$C$F!"HRI[EPO?$r9T$J$C$F2<$5$$!#(B 135 | 136 | 137 | <6.$B%P%$%J%jHRI[EPO?$K$D$$$F(B> 138 | 139 | $B!!%P%$%J%j$NHRI[$K$D$$$F$O!"HRI[EPO?$N$J$$:FHRI[$K4X$7$F$O0l(B 140 | $B@Z:nl9g$G$bF1MM$G$9!#(B 142 | $B!!:nZ$NI,MW$J>l9g!"JQ99$NM-L5$K94$i$:!"8e=R$NHRI[EP(B 143 | $BO?$C$F!"HRI[EPO?$r9T$J$C$F2<$5$$!#(B 144 | 145 | $B!!:n$H$7$F$O!"FC$K4m81@-$N9b$$%P%$%J%jHRI[$K$D$$(B 146 | $B$F$O!"@'HsHRI[EPO?$r9T$J$C$FD:$1$k$3$H$r?d>)$7$^$9!#(B 147 | 148 | 149 | <7.$B%W%m%0%i%`$N2~JQ$K$D$$$F(B> 150 | 151 | $B!!MxMQl9g!"JQ99A0$N%W%m(B 152 | $B%0%i%`$H$OJL$N:nIJ$H$7$F07$&$h$&$J>l9g$O!"2~JQ2U=j$NNL$rLd$o(B 153 | $B$:!"Fse5-$N:FG[IU5,B'$K=>(B 155 | $B$$$^$9$,!"Fs 160 | 161 | $B!!;THN$5$l$k=q@R$K(B CD-ROM $BEy$NG^BN$rDL$8$FE:IU$9$k>l9g$O!":F(B 162 | $BHRI[$H8+$J$7$^$9!#(B 163 | $B!!:nZ$,I,MW$J>l9g$O!"$=$NE:IUJ*$,%=!<%9$G$"$k$+%P%$%J(B 164 | $B%j$G$"$k$+$K1~$8$F!"$=$l$>$l$NHRI[EPO?$r9T$J$C$F2<$5$$!#B>$N(B 165 | $B:FHRI[$HA4$/F1Ey$K07$o$l$^$9!#(B 166 | $B!!C"$7!"4{$KHRI[EPO?$5$l$F$$$k:FHRI[J*$NE:IU$K$D$$$F$O!"2~$a(B 167 | $B$FHRI[EPO?$9$kI,MW$O$"$j$^$;$s$N$G!"HRI[EPO?$r9T$C$?HRI[r7o$K=>$C$F2<$5$$!#(B 169 | 170 | $B!!E:IU$G$O$J$/!"C1$K5-;v$H$7$F>R2p$9$k$N$_$N>l9g$O!"J]>Z$b@U(B 171 | $BG$$bH/@8$7F@$^$;$s$N$G!"FC$KEPO?$NI,MW$O$"$j$^$;$s!#:n$H$7$F$O!"E:IU!&>R2p$K$9$k>l9g$KO"Mm$d8%K\$7(B 175 | $B$FD:$1$k$H4r$7$$$H;W$$$^$9!#(B 176 | $B!!FC$K!">R2p5-;v$K$D$$$F$O!";vA0$K869F$rGR8+$5$;$FD:$1$l$P!"(B 177 | $B:n 183 | 184 | $B!!HRI[EPO?$r9T$J$$$?$$>l9g$O!"0J2<$Nl9g$O$=$l$b:9J,$K4^$a$k!#(B 194 | 4. $BHRI[%Q%C%1!<%8$r:n@.$9$k!#(B 195 | 5. $BHRI[%Q%C%1!<%8$N(B MD5 $B%A%'%C%/%5%`$rD4$Y$F95$($F$*$/!#%P%$(B 196 | $B%J%jHRI[$N>l9g$K$O(B FDclone $B<+?H$Nl9g$O!"(BFDclone $B$K!V(Bcheckid$B!W$H$$$&AH9~$_(B 199 | $B%3%^%s%I$,$"$k$N$G$=$l$rMQ$$$k$HNI$$!#(BFDclone $B$r%3%s%Q%$(B 200 | $B%k8e!"5/F0$7$F!V(Bh$B!W%-!<$r2!$7$F(B EXECUTE_SH $B%3%^%s%I$N%W%m(B 201 | $B%s%W%HFb$G!V(Bcheckid <$B%U%!%$%kL>(B>$B!W$rl9g$O!"HR(B 205 | $BI[$9$kr7o$rJQ99$7$?$$>l9g$O!"HRI[EPO?J8LL(B 208 | $BFb$G$=$N;]@bL@$9$k!#(B 209 | 210 | $B!!EPO?$NJ8LL$G$O!"%=!<%9HRI[EPO?$+%P%$%J%jHRI[$+$,L@3N$KH=$k(B 211 | $B$h$&$K$7$F2<$5$$!#F1$8EPO?J8LL$GF1;~$K%=!<%9HRI[EPO?$H%P%$%J(B 212 | $B%jHRI[EPO?$r9T$J$&$3$H$,2DG=$G$9!#(B 213 | $B!!%P%$%J%jHRI[EPO?$GJ#?t$NF0:n4D6-$KBP$7!"A4$/F1$8JQ99:9J,$K(B 214 | $B$h$k:FHRI[$r9T$J$&>l9g$O!"J#?t$NF0:n4D6-$rNs5s$9$k$3$H$G!"0l(B 215 | $B$D$NHRI[EPO?$GF1;~$KA4$F$NF0:n4D6-$KBP$7HRI[EPO?$G$-$^$9!#(B 216 | 217 | $B!!>0!"6qBNE*$J:n6HFbMF$K$D$$$FIT0FFb$JE@$,$"$k>l9g$O!"EPO?A0(B 218 | $B$K:n $@ || \ 79 | ($(RM) $@; exit 1) 80 | 81 | makefile.gpc: Makefile.in mkmfdosg.sed mkmf.sed 82 | $(SED) -f mkmfdosg.sed Makefile.in | \ 83 | $(SED) "s:__OSTYPE__:DOSV:g" | \ 84 | $(SED) -f mkmf.sed > $@ || \ 85 | ($(RM) $@; exit 1) 86 | 87 | makefile.g98: Makefile.in mkmfdosg.sed mkmf.sed 88 | $(SED) -f mkmfdosg.sed Makefile.in | \ 89 | $(SED) "s:__OSTYPE__:PC98:g" | \ 90 | $(SED) -f mkmf.sed > $@ || \ 91 | ($(RM) $@; exit 1) 92 | 93 | makefile.dpc: Makefile.in mkmfdosd.sed mkmf.sed 94 | $(SED) -f mkmfdosd.sed Makefile.in | \ 95 | $(SED) "s:__OSTYPE__:DOSV:g" | \ 96 | $(SED) -f mkmf.sed > $@ || \ 97 | ($(RM) $@; exit 1) 98 | 99 | makefile.d98: Makefile.in mkmfdosd.sed mkmf.sed 100 | $(SED) -f mkmfdosd.sed Makefile.in | \ 101 | $(SED) "s:__OSTYPE__:PC98:g" | \ 102 | $(SED) -f mkmf.sed > $@ || \ 103 | ($(RM) $@; exit 1) 104 | 105 | makefile.lpc: Makefile.in mkmfdosl.sed mkmf.sed 106 | $(SED) -f mkmfdosl.sed Makefile.in | \ 107 | $(SED) "s:__OSTYPE__:DOSV:g" | \ 108 | $(SED) -f mkmf.sed > $@ || \ 109 | ($(RM) $@; exit 1) 110 | 111 | makefile.l98: Makefile.in mkmfdosl.sed mkmf.sed 112 | $(SED) -f mkmfdosl.sed Makefile.in | \ 113 | $(SED) "s:__OSTYPE__:PC98:g" | \ 114 | $(SED) -f mkmf.sed > $@ || \ 115 | ($(RM) $@; exit 1) 116 | 117 | makefile.bpc: Makefile.in mkmfdosb.sed mkmf.sed 118 | $(SED) -f mkmfdosb.sed Makefile.in | \ 119 | $(SED) "s:__OSTYPE__:DOSV:g" | \ 120 | $(SED) -f mkmf.sed > $@ || \ 121 | ($(RM) $@; exit 1) 122 | 123 | makefile.b98: Makefile.in mkmfdosb.sed mkmf.sed 124 | $(SED) -f mkmfdosb.sed Makefile.in | \ 125 | $(SED) "s:__OSTYPE__:PC98:g" | \ 126 | $(SED) -f mkmf.sed > $@ || \ 127 | ($(RM) $@; exit 1) 128 | 129 | mkmf.sed: mkmfsed 130 | ./mkmfsed > mkmf.sed 131 | 132 | mkmfsed: mkmfsed.c 133 | $(HOSTCC) $(HOSTCFLAGS) $(HOSTCPPFLAGS) $(DEFCFLAGS) -o $@ mkmfsed.c 134 | 135 | mkmfsed: hmachine.h config.h fd.h headers.h machine.h 136 | mkmfsed: depend.h version.h 137 | 138 | fd.h: 139 | -[ -f $@ ] || $(CP) headers.h $@ 140 | 141 | config.h: config.hin 142 | $(CP) config.hin config.h 143 | 144 | hmachine.h: Makefile machine.h hmachine.sed 145 | $(SED) -n -e 's:machine.h:$@:g' -e '1,/^$$/p' machine.h > $@ 146 | @if [ "$(CC)" != "$(HOSTCC)" ]; then \ 147 | for i in $(PREDEF); do \ 148 | $(ECHO) "#ifdef $${i}"; \ 149 | $(ECHO) "__DEFINE__ $(HPREFIX)$${i} $${i}"; \ 150 | $(ECHO) "#endif"; \ 151 | done | $(CPP) - | \ 152 | $(SED) -n -e 's:__DEFINE__:#define:p' >> $@; \ 153 | $(ECHO) >> $@; \ 154 | fi 155 | $(SED) -f hmachine.sed machine.h >> $@ 156 | 157 | hmachine.sed: Makefile 158 | $(ECHO) '1,/^$$/d' > $@ 159 | @if [ "$(CC)" != "$(HOSTCC)" ]; then \ 160 | for i in $(PREDEF); do \ 161 | $(ECHO) "s:($${i}):($(HPREFIX)$${i}):g"; \ 162 | done >> $@; \ 163 | fi 164 | 165 | install install-table install-man install-jman \ 166 | catman catman-b compman compman-b \ 167 | jcatman jcatman-b jcompman jcompman-b: Makefile.tmp 168 | $(MAKE) BUILD=$(BUILD) -f Makefile.tmp $@ 169 | 170 | sh bsh nsh \ 171 | fd.doc README.doc HISTORY.doc FAQ.doc LICENSES.doc \ 172 | depend lint: Makefile.tmp 173 | $(MAKE) -f Makefile.tmp $@ 174 | 175 | config: rmconfig Makefile.tmp 176 | $(MAKE) SHELL=$(SHELL) -f Makefile.tmp $@ 177 | 178 | rmconfig: 179 | $(CP) config.hin config.h 180 | 181 | ipk: Makefile.tmp 182 | $(MAKE) STRIP=$(STRIP) -f Makefile.tmp $@ 183 | 184 | everything: Makefile.tmp 185 | $(MAKE) -f Makefile.tmp sh bsh nsh all 186 | 187 | makes: $(MAKES) 188 | 189 | tar gtar shtar lzh shar: Makefile.tmp $(MAKES) 190 | $(MAKE) $(DEFAR) -f Makefile.tmp $@ 191 | 192 | rmdict: Makefile.tmp 193 | $(MAKE) -f Makefile.tmp $@ 194 | -$(RM) Makefile.tmp mkmf.sed 195 | -$(RM) mkmfsed mkmfsed.exe 196 | 197 | clean: Makefile.tmp 198 | $(MAKE) -f Makefile.tmp $@ 199 | -$(RM) Makefile.tmp mkmf.sed 200 | -$(RM) mkmfsed mkmfsed.exe 201 | -$(RM) hmachine.h hmachine.sed 202 | 203 | distclean: clean 204 | -$(RM) config.h 205 | 206 | realclean: distclean 207 | -$(RM) makefile.gpc makefile.g98 208 | -$(RM) makefile.dpc makefile.d98 209 | -$(RM) makefile.lpc makefile.l98 210 | -$(RM) makefile.bpc makefile.b98 211 | -------------------------------------------------------------------------------- /ToAdmin: -------------------------------------------------------------------------------- 1 | [FDclone3 $B1?MQ$K4X$9$k4IM}$r(B 10 | $B0lIt$GGc$C$F$7$^$&$h$&$J%$%s%?%U%'!<%9$7$+MQ0U$5$l$F$$$J$$$H(B 11 | $B$$$&8=>u$r4U$_!"=i?4l$G$=$NH?1~$r<*$K$9$k(B 16 | $B$3$H$,$"$k$N$G$9$,!"e5-$N$h$&$J%]%j%7!<$OI,$:(B 17 | $B$7$be:G$b%?%A$N0-$$ItN`$KB0$9$k$H;W$o$l$k$N(B 19 | $B$,!"!V?7JF(B root $B$K$h$k(B FDclone $B$rMQ$$$?%7%9%F%`4IM}!W$G$9!#(B 20 | 21 | $B!!(BFDclone $B$OK0$/$^$G$b%(%s%I%f!<%6$N$?$a$N%D!<%k$G$9!#(B 22 | 23 | $B!!(Broot $B$?$k0(B root $B$G$N:n6H$r9T$J$&$H$$$&$N$G$"$l$P!"(B 33 | $B>/$J$/$H$b%m%0$r;D$9$h$&$K$7$FM_$7$$$H;W$$$^$9!#(B 34 | $B!!(BFDclone $B$K$O%m%0$r;D$95!G=$,03n$D$=$l$i$N@_DjJQ(B 38 | $B?t$r(B readonly $BB0@-$K$7$F$*$1$P!"(BFDclone $B5/F08e$K@_DjJQ99$K$h(B 39 | $B$j%m%0$r2sHr$9$k$3$H$,$G$-$J$/$J$j$^$9!#(B 40 | 41 | $B!!$3$&$$$C$?!"(Broot $B$J$i$G$O$NLdBjE@$KBP$7!"$-$A$s$HLdBj0U<1(B 42 | $B$r;}$C$FD:$-!"0B0W$K(B root $B8"8B$G(B FDclone $B$r5/F0$9$k$3$H$,$J(B 43 | $B$$$h$&!"(BUNIX $B4IM}HJ}K!$J$I$K4X$7$F$b!"(B 61 | $B!V=i?4e(B 68 | $B$N$b$N$r4|BT$7$F!"=i?4/$J$/$H$b!"%(%s%I%f!<%6$N6l>p$d@\:n@\:n)$5$;$FD:$-$^$9!#(B 84 | 85 | 86 | 3.FDclone $B$NJ]>ZHO0O(B 87 | 88 | $B!!(BFDclone $B$OL5J]>Z$G$9!#>&MQ$GHNGd$5$l$F$$$k$b$N$H0[$J$j!"K|(B 89 | $BA4$N%A%'%C%/$r9T$J$C$F$$$k$H$O?=$7>e$2$K$/$$$N$,u$G$9!#(B 90 | $B!!FC$K(B Ver. 1.03 $B0J9_$N3+H/$K$"$?$C$F$O!":np$K(B 91 | $B$h$j!"3+H/4D6-$,Cx$7$/K3$7$$$b$N$H$J$C$F$7$^$C$F$$$^$9!#8=:_(B 92 | $B$N:nl9g$K$h$C$F$O%;%-%e%j%F%#%[!<%k$b;D$C$F$$$k$+$bCN$l$^$;$s!#(B 100 | $B$b$7$=$&$$$C$?E@$KIT0B$rJz$+$l$k$N$G$"$l$P!"(BFDclone $B$O$=$NIT(B 101 | $B0B$rJ'?!$G$-$k$@$1$N?.Mj@-$rJ];}$7$F$*$j$^$;$s!#(B 102 | $B!!5U$K?=$7>e$2$k$J$i$P!"$=$3$^$G$N?.Mj@-$r4|BT$5$l$kJ}$K$O!"(B 103 | $B$4<+?H$G$h$j0BA4$G?.MQ$G$-$k%D!<%k$r:n$i$l$k$3$H$r$4Ds0F:9$7(B 104 | $B>e$2$^$9!#(B 105 | 106 | $B!!(BFDclone $B$O(B UNIX $B$K@:DL$7$?%(%s%8%K%"$Ne!"(BFDclone $B$K2aBg$J4|BT$rJz$+$J$$$h$&!"$*4j(B 110 | $B$$?=$7>e$2$^$9!#(B 111 | -------------------------------------------------------------------------------- /ToAdmin.eng: -------------------------------------------------------------------------------- 1 | [CAUTION TO THE ADMINISTRATORS FOR FDCLONE3 EMPLOYMENT] 2 | 3 | 4 | 1.Employment Policy for FDclone 5 | 6 | Although FDclone is built aiming at the general purpose 7 | tool for beginners, its intention is "compromise from UNIX 8 | to beginners". 9 | In view of the present condition where someone complains 10 | that it has only interface difficult for beginners, the target 11 | is that any beginner can handle UNIX easily and any administrator 12 | can be out of supporting beginners. 13 | 14 | I can hear some reactions in various places after the first 15 | release of FDclone, and often feel that the above policy can 16 | not be always kept in the actual employment. 17 | One of the worst case as employment seems "the system 18 | administration with FDclone by a novice root". 19 | 20 | FDclone is only a tool for end users. 21 | 22 | The author has the policy that any root, even if he is a 23 | novice, should be used to the UNIX world well. 24 | If he is used to FDclone in daily administrations, he will 25 | not be able to raise the skill of the special operation in 26 | some accidents and the shell programming. 27 | And the most important problem is a security. There is not 28 | only the risk that a miss operation can cause damages widely, 29 | but also the problem that FDclone operations is hard to be 30 | traced later. 31 | 32 | If you nevertheless dare to operate as a root, I suggest 33 | that you should record the log at least. 34 | FDclone has the function to record the log, which can 35 | output to not only a file but also syslogd(8). The log level 36 | of the root especially can be specified individually. 37 | If you specify this log setting in /etc/fd2rc and then 38 | attribute readonly to the variables for the setting, no one 39 | can avoid logging with changing settings after FDclone has 40 | been invoked. 41 | 42 | You should keep a awareness of the problem for just root, 43 | and walk on the road of UNIX administrator not invoking 44 | FDclone with root permission easily. 45 | 46 | 47 | 2.Administration of End Users 48 | 49 | Although FDclone is a tool for beginners, the responsibility 50 | for the beginner education in each environment cannot be 51 | taken. 52 | The administrator who install FDclone take the minimum 53 | responsibility in its employed environment, and need to 54 | educate and enlighten end users including UNIX itself in 55 | order to use FDclone correctly. 56 | FDclone is just only a tool. 57 | 58 | When you install FDclone, you must build the environment 59 | where any end user can make use of FDclone with no special 60 | knowledge. 61 | This means not only to consider the configuration of /etc/fd2rc 62 | specialized in your environment, but also to build the 63 | environment "kind to beginner" about the reference method 64 | for a man page and FAQ. 65 | 66 | Therefore, the administrator who install FDclone will need 67 | to have the minimum knowledge as the UNIX administrator. 68 | It seems the work of each administrator to support end users 69 | in order to use FDclone comfortably. I wish you endeavor not 70 | to neglect the beginner education and support with expecting 71 | FDclone to be more than a tool. 72 | 73 | You should avoid that any complaint and question from end 74 | users reach the author directly. 75 | Some mails are send to the author about not only the affair 76 | specialized in FDclone but also the general question for UNIX. 77 | A FDclone package includes FAQ about FDclone, and can hardly 78 | include FAQ over whole UNIX. 79 | Moreover, even if it is a question about FDclone, the 80 | direct mail from an end user requires a lot of explanation 81 | filling his UNIX knowledge, and make difficult to support. 82 | It is recommended that the administrator in the employed 83 | environment will administer the employment of FDclone, and 84 | he send only the problem which will be resolved only by the 85 | author. 86 | 87 | 88 | 3.Guarantees of FDclone 89 | 90 | FDclone has no warranty. The fact is that it is not checked 91 | perfectly differing from some commercial products. 92 | Especially in the development after Ver. 1.03, the developing 93 | environment becomes very poor for my personal reasons. I am 94 | currently not a UNIX administrator but just end user who can 95 | not have any root permission. 96 | Although it is very difficult to continue the development 97 | of FDclone in such environment, I have continued the development 98 | with a long time and earnest approval from some users. 99 | 100 | It still has poor implementation in the view of some UNIX 101 | wizards, and may keep some security holes possibly. If you 102 | have some anxiety for them, FDclone don't hold the reliability 103 | enough to sweep off the anxiety. 104 | In opposite view, I propose that whose who expect such that 105 | reliability should build the safer and more reliable tool 106 | yourself. 107 | 108 | FDclone is not made by the engineer familiar with UNIX, and 109 | just a tool made for hobby by a mere game designer in spare 110 | time. 111 | Please don't expect FDclone too much on account of this 112 | point. 113 | -------------------------------------------------------------------------------- /auth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * auth.h 3 | * 4 | * definitions & function prototype declarations for "auth.c" 5 | */ 6 | 7 | #include "url.h" 8 | 9 | #ifndef __AUTH_H_ 10 | #define __AUTH_H_ 11 | 12 | #define AUTHNOFILE 16 13 | #define AUTHBASIC "Basic" 14 | #define AUTHDIGEST "Digest" 15 | 16 | typedef struct _auth_t { 17 | urlhost_t host; 18 | int type; 19 | int nlink; 20 | } auth_t; 21 | 22 | char *authgetuser __P_((VOID_A)); 23 | char *authgetpass __P_((VOID_A)); 24 | int authfind __P_((urlhost_t *, int, int)); 25 | VOID authentry __P_((urlhost_t *, int)); 26 | VOID authfree __P_((VOID_A)); 27 | char *authencode __P_((urlhost_t *, 28 | CONST char *, CONST char *, CONST char *)); 29 | 30 | #endif /* !__AUTH_H_ */ 31 | -------------------------------------------------------------------------------- /catalog.c: -------------------------------------------------------------------------------- 1 | /* 2 | * catalog.c 3 | * 4 | * message catalog 5 | */ 6 | 7 | #include "fd.h" 8 | #include "termio.h" 9 | #include "func.h" 10 | #include "kanji.h" 11 | 12 | #ifdef USEMMAP 13 | #include 14 | #endif 15 | 16 | #define MAXVERBUF 8 17 | #define CF_KANJI 0001 18 | #define getword(s, n) (((u_short)((s)[(n) + 1]) << 8) | (s)[n]) 19 | #define CATTBL "fd-cat." 20 | 21 | #ifndef _NOCATALOG 22 | static int NEAR fgetword __P_((u_short *, int)); 23 | static int NEAR opencatalog __P_((CONST char *)); 24 | 25 | char *cattblpath = NULL; 26 | CONST char *catname = NULL; 27 | 28 | static u_char *catbuf = NULL; 29 | static ALLOC_T catsize = (ALLOC_T)0; 30 | static off_t catofs = (off_t)0; 31 | static u_short *catindex = NULL; 32 | static u_short catmax = (u_short)0; 33 | static CONST char *cat_ja = "ja"; 34 | static CONST char *cat_C = "C"; 35 | #endif /* !_NOCATALOG */ 36 | 37 | 38 | #ifdef _NOCATALOG 39 | # if !defined (_NOENGMES) && !defined (_NOJPNMES) 40 | CONST char *mesconv(jpn, eng) 41 | CONST char *jpn, *eng; 42 | { 43 | int n; 44 | 45 | if (outputkcode == ENG) return(eng); 46 | n = (messagelang != NOCNV) ? messagelang : outputkcode; 47 | return((n == ENG) ? eng : jpn); 48 | } 49 | # endif /* !_NOENGMES && !_NOJPNMES */ 50 | 51 | #else /* !_NOCATALOG */ 52 | 53 | static int NEAR fgetword(wp, fd) 54 | u_short *wp; 55 | int fd; 56 | { 57 | u_char buf[2]; 58 | 59 | if (sureread(fd, buf, 2) != 2) return(-1); 60 | *wp = getword(buf, 0); 61 | 62 | return(0); 63 | } 64 | 65 | static int NEAR opencatalog(lang) 66 | CONST char *lang; 67 | { 68 | char *cp, path[MAXPATHLEN], file[MAXPATHLEN], ver[MAXVERBUF]; 69 | off_t ofs; 70 | ALLOC_T size; 71 | u_short w, flags; 72 | int n, fd; 73 | 74 | VOID_C Xsnprintf(file, sizeof(file), "%s%s", CATTBL, lang); 75 | if (!cattblpath || !*cattblpath) Xstrcpy(path, file); 76 | else strcatdelim2(path, cattblpath, file); 77 | 78 | if ((fd = open(path, O_BINARY | O_RDONLY, 0666)) < 0) return(-1); 79 | cp = getversion(&n); 80 | if (read(fd, ver, sizeof(ver)) != sizeof(ver) 81 | || strncmp(cp, ver, n) || ver[n] 82 | || fgetword(&flags, fd) < 0 83 | || ((flags & CF_KANJI) && outputkcode == ENG) 84 | || fgetword(&w, fd) < 0 || w != CAT_SUM 85 | || fgetword(&w, fd) < 0) { 86 | VOID_C close(fd); 87 | return(-1); 88 | } 89 | 90 | if (!catbuf) /*EMPTY*/; 91 | #ifdef USEMMAP 92 | else if (catbuf == (u_char *)MAP_FAILED) /*EMPTY*/; 93 | else if (catsize) { 94 | if (munmap(catbuf, catsize) < 0) error("munmap()"); 95 | } 96 | #endif 97 | else Xfree(catbuf); 98 | catbuf = NULL; 99 | catsize = (ALLOC_T)0; 100 | catofs = (off_t)0; 101 | catindex = (u_short *)Xrealloc(catindex, w * sizeof(u_short)); 102 | catmax = w; 103 | 104 | catindex[0] = (u_short)0; 105 | for (w = 1; w < catmax; w++) if (fgetword(&(catindex[w]), fd) < 0) { 106 | VOID_C close(fd); 107 | return(-1); 108 | } 109 | if (fgetword(&w, fd) < 0) { 110 | VOID_C close(fd); 111 | return(-1); 112 | } 113 | size = w; 114 | 115 | ofs = sizeof(ver) + 2 + 2 + 2 + 2 * catmax; 116 | #ifdef USEMMAP 117 | catbuf = (u_char *)mmap(NULL, (ALLOC_T)ofs + size, 118 | PROT_READ, MAP_PRIVATE, fd, (off_t)0); 119 | if (catbuf != (u_char *)MAP_FAILED) { 120 | catsize = (ALLOC_T)ofs + size; 121 | catofs = ofs; 122 | } 123 | else 124 | #endif 125 | { 126 | catbuf = (u_char *)Xmalloc(size); 127 | if (lseek(fd, ofs, L_SET) < (off_t)0 128 | || sureread(fd, catbuf, size) != size) { 129 | VOID_C close(fd); 130 | Xfree(catbuf); 131 | Xfree(catindex); 132 | catbuf = NULL; 133 | catindex = NULL; 134 | catmax = 0; 135 | return(-1); 136 | } 137 | } 138 | VOID_C close(fd); 139 | 140 | return(0); 141 | } 142 | 143 | VOID freecatalog(VOID_A) 144 | { 145 | if (!catbuf) /*EMPTY*/; 146 | #ifdef USEMMAP 147 | else if (catbuf == (u_char *)MAP_FAILED) /*EMPTY*/; 148 | else if (catsize) VOID_C munmap(catbuf, catsize); 149 | #endif 150 | else Xfree(catbuf); 151 | Xfree(catindex); 152 | 153 | catbuf = NULL; 154 | catsize = (ALLOC_T)0; 155 | catofs = (off_t)0; 156 | catindex = NULL; 157 | catmax = 0; 158 | } 159 | 160 | char **listcatalog(VOID_A) 161 | { 162 | DIR *dirp; 163 | struct dirent *dp; 164 | CONST char *cp; 165 | char **argv; 166 | int argc; 167 | 168 | if (!cattblpath || !*cattblpath) cp = curpath; 169 | else cp = cattblpath; 170 | 171 | if (!(dirp = Xopendir(cp))) return(NULL); 172 | argv = NULL; 173 | argc = 0; 174 | while ((dp = Xreaddir(dirp))) { 175 | cp = dp -> d_name; 176 | if (strnpathcmp(cp, CATTBL, strsize(CATTBL))) continue; 177 | cp += strsize(CATTBL); 178 | if (!strpathcmp(cp, cat_ja)) continue; 179 | if (!strpathcmp(cp, cat_C)) continue; 180 | argv = (char **)Xrealloc(argv, (argc + 2) * sizeof(char *)); 181 | argv[argc++] = Xstrdup(cp); 182 | argv[argc] = NULL; 183 | } 184 | VOID_C Xclosedir(dirp); 185 | 186 | return(argv); 187 | } 188 | 189 | int chkcatalog(VOID_A) 190 | { 191 | CONST char *lang; 192 | 193 | if (messagelang != NOCNV) lang = (messagelang == ENG) ? cat_C : cat_ja; 194 | else if (catname && *catname) lang = catname; 195 | else lang = (outputkcode == ENG) ? cat_C : cat_ja; 196 | 197 | if (opencatalog(lang) >= 0) return(0); 198 | if (opencatalog(cat_ja) >= 0) return(0); 199 | if (opencatalog(cat_C) >= 0) return(0); 200 | 201 | return(-1); 202 | } 203 | 204 | CONST char *mesconv(id) 205 | int id; 206 | { 207 | off_t ofs; 208 | 209 | if (!catbuf && chkcatalog() < 0) return(nullstr); 210 | if (id < 0 || id >= catmax) return(nullstr); 211 | ofs = catindex[id] + catofs; 212 | 213 | return((CONST char *)&(catbuf[ofs])); 214 | } 215 | #endif /* !_NOCATALOG */ 216 | -------------------------------------------------------------------------------- /catalog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * catalog.h 3 | * 4 | * function prototype declarations for "catalog.c" 5 | */ 6 | 7 | #include "depend.h" 8 | 9 | #ifdef _NOCATALOG 10 | # ifdef _NOENGMES 11 | # define mesconv2(n, jpn, eng) (jpn) 12 | # define meslist(n, jpn, eng) jpn 13 | # else /* !_NOENGMES */ 14 | # ifdef _NOJPNMES 15 | # define mesconv2(n, jpn, eng) (eng) 16 | # define meslist(n, jpn, eng) eng 17 | # else 18 | # define mesconv2(n, jpn, eng) mesconv(jpn, eng) 19 | # define meslist(n, jpn, eng) jpn, eng 20 | # endif 21 | # endif /* !_NOENGMES */ 22 | #else /* !_NOCATALOG */ 23 | #define mesconv2(n, jpn, eng) mesconv(n) 24 | #define meslist(n, jpn, eng) (n) 25 | #endif /* !_NOCATALOG */ 26 | 27 | #ifdef _NOCATALOG 28 | # if !defined (_NOENGMES) && !defined (_NOJPNMES) 29 | extern CONST char *mesconv __P_((CONST char *, CONST char *)); 30 | # endif 31 | #else /* !_NOCATALOG */ 32 | extern VOID freecatalog __P_((VOID_A)); 33 | extern char **listcatalog __P_((VOID_A)); 34 | extern int chkcatalog __P_((VOID_A)); 35 | extern CONST char *mesconv __P_((int)); 36 | 37 | extern char *cattblpath; 38 | extern CONST char *catname; 39 | #endif /* !_NOCATALOG */ 40 | -------------------------------------------------------------------------------- /config.hin: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | * definitions for each OS 5 | */ 6 | 7 | -------------------------------------------------------------------------------- /depend.h: -------------------------------------------------------------------------------- 1 | /* 2 | * depend.h 3 | * 4 | * definitions for dependency 5 | */ 6 | 7 | #if MSDOS && defined (_NOUSELFN) && !defined (_NODOSDRIVE) 8 | #define _NODOSDRIVE 9 | #endif 10 | 11 | #if defined (NOMULTIKANJI) && !defined (_NOKANJICONV) 12 | #define _NOKANJICONV 13 | #endif 14 | #if (defined (_NOKANJICONV) || (defined (FD) && FD < 2)) \ 15 | && !defined (_NOKANJIFCONV) 16 | #define _NOKANJIFCONV 17 | #endif 18 | #if (defined (_NOKANJICONV) || (defined (FD) && FD < 2)) \ 19 | && !defined (_NOIME) 20 | #define _NOIME 21 | #endif 22 | #if defined (_NOENGMES) && defined (_NOJPNMES) 23 | #undef _NOENGMES 24 | #endif 25 | #if (defined (_NOENGMES) || defined (_NOJPNMES) \ 26 | || (defined (FD) && FD < 3)) \ 27 | && !defined (_NOCATALOG) 28 | #define _NOCATALOG 29 | #endif 30 | 31 | #if (MSDOS || (defined (FD) && FD < 3)) && !defined (_NOSOCKET) 32 | #define _NOSOCKET 33 | #endif 34 | #if defined (_NOSOCKET) && !defined (_NOSOCKREDIR) 35 | #define _NOSOCKREDIR 36 | #endif 37 | #if defined (_NOSOCKET) && !defined (_NOFTP) 38 | #define _NOFTP 39 | #endif 40 | #if defined (_NOSOCKET) && !defined (_NOHTTP) 41 | #define _NOHTTP 42 | #endif 43 | 44 | #ifdef WITHNETWORK 45 | #undef OLDPARSE 46 | #endif 47 | #if defined (OLDPARSE) && !defined (_NOCUSTOMIZE) 48 | #define _NOCUSTOMIZE 49 | #endif 50 | #if defined (OLDPARSE) && !defined (_NOBROWSE) 51 | #define _NOBROWSE 52 | #endif 53 | #if defined (OLDPARSE) && !defined (_NOFTP) 54 | #define _NOFTP 55 | #endif 56 | #if defined (OLDPARSE) && !defined (_NOHTTP) 57 | #define _NOHTTP 58 | #endif 59 | 60 | #if MSDOS && !defined (_NOKEYMAP) 61 | #define _NOKEYMAP 62 | #endif 63 | #if MSDOS && !defined (_USEDOSCOPY) 64 | #define _USEDOSCOPY 65 | #endif 66 | #if (defined (_NOORIGSHELL) || (defined (FD) && FD < 2)) \ 67 | && !defined (_NOEXTRAMACRO) 68 | #define _NOEXTRAMACRO 69 | #endif 70 | #ifdef _NOSPLITWIN 71 | #undef MAXWINDOWS 72 | #define MAXWINDOWS 1 73 | #else /* !_NOSPLITWIN */ 74 | # if (MAXWINDOWS <= 1) 75 | # define _NOSPLITWIN 76 | # endif 77 | #endif /* !_NOSPLITWIN */ 78 | #if (defined (_NOSPLITWIN) || (defined (FD) && FD < 2)) \ 79 | && !defined (_NOEXTRAWIN) 80 | #define _NOEXTRAWIN 81 | #endif 82 | #if (MSDOS || defined (NOSELECT) || (defined(FD) && FD < 2)) \ 83 | && !defined (_NOPTY) 84 | #define _NOPTY 85 | #endif 86 | #if (!defined (FD) || FD < 3) && !defined (_NOVERSCMP) 87 | #define _NOVERSCMP 88 | #else 89 | #undef _NOVERSCMP 90 | #define _NOVERSCMP "unsupported" 91 | #endif 92 | 93 | #undef DEP_DOSDRIVE 94 | #undef DEP_DOSEMU 95 | #undef DEP_DOSPATH 96 | #undef DEP_DOSLFN 97 | #undef DEP_ROCKRIDGE 98 | #undef DEP_KCONV 99 | #undef DEP_FILECONV 100 | #undef DEP_KANJIPATH 101 | #undef DEP_UNICODE 102 | #undef DEP_EMBEDUNITBL 103 | #undef DEP_ORIGSTREAM 104 | #undef DEP_ORIGSHELL 105 | #undef DEP_PTY 106 | #undef DEP_IME 107 | #undef DEP_EMBEDDICTTBL 108 | #undef DEP_LOGGING 109 | #undef DEP_DYNAMICLIST 110 | #undef DEP_SOCKET 111 | #undef DEP_SOCKREDIR 112 | #undef DEP_FTPPATH 113 | #undef DEP_HTTPPATH 114 | #undef DEP_URLPATH 115 | #undef DEP_STREAMTIMEOUT 116 | #undef DEP_STREAMLOCK 117 | #undef DEP_STREAMSOCKET 118 | #undef DEP_STREAMLOG 119 | #undef DEP_LSPARSE 120 | #undef DEP_PSEUDOPATH 121 | #undef DEP_BIASPATH 122 | #undef DEP_DIRENT 123 | #undef DEP_PATHTOP 124 | 125 | #if defined (FD) && !defined (_NODOSDRIVE) 126 | #define DEP_DOSDRIVE 127 | #endif 128 | #if !MSDOS && defined (DEP_DOSDRIVE) 129 | #define DEP_DOSEMU 130 | #endif 131 | #if MSDOS || defined (DEP_DOSDRIVE) 132 | #define DEP_DOSPATH 133 | #endif 134 | #if MSDOS && defined (FD) && !defined (_NOUSELFN) 135 | #define DEP_DOSLFN 136 | #endif 137 | #if defined (FD) && !defined (_NOROCKRIDGE) 138 | #define DEP_ROCKRIDGE 139 | #endif 140 | 141 | #if defined (FD) && !defined (_NOKANJICONV) 142 | #define DEP_KCONV 143 | #endif 144 | #if defined (FD) && !defined (_NOKANJIFCONV) 145 | #define DEP_FILECONV 146 | #endif 147 | #if !defined (NOMULTIKANJI) && defined (DEP_FILECONV) 148 | #define DEP_KANJIPATH 149 | #endif 150 | #if (defined (DEP_KCONV) && !defined (_NOUNICODE)) \ 151 | || defined (DEP_DOSDRIVE) 152 | #define DEP_UNICODE 153 | #endif 154 | #if defined (DEP_UNICODE) && defined (_NOUNICDTBL) 155 | #define DEP_EMBEDUNITBL 156 | #endif 157 | #ifndef MINIMUMSHELL 158 | #define DEP_ORIGSTREAM 159 | #endif 160 | #if defined (FDSH) || (defined (FD) && FD >= 2 && !defined (_NOORIGSHELL)) 161 | #define DEP_ORIGSHELL 162 | #endif 163 | #if defined (FD) && FD >= 2 && !defined (_NOPTY) 164 | #define DEP_PTY 165 | #endif 166 | #if defined (FD) && FD >= 2 && !defined (_NOIME) 167 | #define DEP_IME 168 | #endif 169 | #if defined (DEP_IME) && defined (_NODICTTBL) 170 | #define DEP_EMBEDDICTTBL 171 | #endif 172 | #if defined (FD) && FD >= 2 && !defined (_NOLOGGING) 173 | #define DEP_LOGGING 174 | #endif 175 | #if defined (FD) && FD >= 3 && !defined (_NODYNAMICLIST) 176 | #define DEP_DYNAMICLIST 177 | #endif 178 | 179 | #if !MSDOS \ 180 | && (defined (WITHNETWORK) || (defined (FD) && !defined (_NOSOCKET))) 181 | #define DEP_SOCKET 182 | #endif 183 | #if !MSDOS \ 184 | && (defined (WITHNETWORK) || (defined (FD) && !defined (_NOSOCKREDIR))) 185 | #define DEP_SOCKREDIR 186 | #endif 187 | #if !MSDOS \ 188 | && (defined (WITHNETWORK) || (defined (FD) && !defined (_NOFTP))) 189 | #define DEP_FTPPATH 190 | #endif 191 | #if !MSDOS \ 192 | && (defined (WITHNETWORK) || (defined (FD) && !defined (_NOHTTP))) 193 | #define DEP_HTTPPATH 194 | #endif 195 | #if defined (DEP_FTPPATH) || defined (DEP_HTTPPATH) 196 | #define DEP_URLPATH 197 | #endif 198 | #if defined (MH) || (defined (DEP_URLPATH) && !defined (NOSELECT)) 199 | #define DEP_STREAMTIMEOUT 200 | #endif 201 | #if defined (MH) && !defined (NOFLOCK) 202 | #define DEP_STREAMLOCK 203 | #endif 204 | #if defined (MH) || defined (DEP_SOCKET) 205 | #define DEP_STREAMSOCKET 206 | #endif 207 | #ifdef MH 208 | #define DEP_STREAMLOG 209 | #endif 210 | 211 | #if !defined (FD) || !defined (_NOARCHIVE) || defined (DEP_FTPPATH) 212 | #define DEP_LSPARSE 213 | #endif 214 | #if defined (DEP_DOSDRIVE) || defined (DEP_URLPATH) 215 | #define DEP_PSEUDOPATH 216 | #endif 217 | #if defined (DEP_PSEUDOPATH) || defined (DEP_DOSLFN) \ 218 | || defined (DEP_KANJIPATH) || defined (DEP_ROCKRIDGE) 219 | #define DEP_BIASPATH 220 | #endif 221 | #if MSDOS || defined (DEP_BIASPATH) 222 | #define DEP_DIRENT 223 | #endif 224 | #if defined (DEP_DOSEMU) || defined (DOUBLESLASH) || defined (DEP_URLPATH) 225 | #define DEP_PATHTOP 226 | #endif 227 | -------------------------------------------------------------------------------- /device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * device.h 3 | * 4 | * definitions for device ID 5 | */ 6 | 7 | #ifdef USEMKDEVH 8 | #include 9 | #else /* !USEMKDEVH */ 10 | # ifdef USEMKNODH 11 | # include 12 | # else /* !USEMKNODH */ 13 | # ifdef SVR4 14 | # include 15 | # endif 16 | # endif /* !USEMKNODH */ 17 | #endif /* !USEMKDEVH */ 18 | 19 | #ifdef SVR4 20 | #define BIT_MAJOR 15 21 | #define BIT_MINOR 18 22 | #else 23 | #define BIT_MAJOR 8 24 | #define BIT_MINOR 8 25 | #endif 26 | #define MASK_MAJOR (((u_long)1 << BIT_MAJOR) - 1) 27 | #define MASK_MINOR (((u_long)1 << BIT_MINOR) - 1) 28 | 29 | #ifndef major 30 | #define major(n) ((((u_long)(n)) >> BIT_MINOR) & MASK_MAJOR) 31 | #endif 32 | #ifndef minor 33 | #define minor(n) (((u_long)(n)) & MASK_MINOR) 34 | #endif 35 | #ifndef makedev 36 | #define makedev(ma, mi) (((((u_long)(ma)) & MASK_MAJOR) << BIT_MAJOR) \ 37 | | (((u_long)(mi)) & MASK_MINOR)) 38 | #endif 39 | 40 | #if MSDOS 41 | typedef short r_dev_t; 42 | #else 43 | typedef dev_t r_dev_t; 44 | #endif 45 | -------------------------------------------------------------------------------- /dirent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * dirent.h 3 | * 4 | * definitions for directory entry 5 | */ 6 | 7 | #ifndef __DIRENT_H_ 8 | #define __DIRENT_H_ 9 | 10 | #include "unixemu.h" 11 | 12 | #if defined (USESYSDIRH) || defined (USEDIRECT) 13 | #include 14 | #endif 15 | #if MSDOS 16 | # if defined (__TURBOC__) || (defined (DJGPP) && DJGPP < 2) 17 | # include 18 | # endif 19 | #else /* !MSDOS */ 20 | # ifndef USEDIRECT 21 | # include 22 | # endif 23 | #endif /* !MSDOS */ 24 | 25 | #ifdef USEDIRECT 26 | #define dirent direct 27 | #undef DIRSIZ 28 | #endif 29 | 30 | #ifndef DEV_BSIZE 31 | #define DEV_BSIZE 512 32 | #endif 33 | #if !defined (MAXNAMLEN) && defined (FILENAME_MAX) 34 | #define MAXNAMLEN FILENAME_MAX 35 | #endif 36 | 37 | #if defined (DNAMESIZE) && DNAMESIZE < (MAXNAMLEN + 1) 38 | typedef struct _st_dirent { 39 | char buf[(int)sizeof(struct dirent) - DNAMESIZE + MAXNAMLEN + 1]; 40 | } st_dirent; 41 | #else 42 | typedef struct dirent st_dirent; 43 | #endif 44 | 45 | #endif /* !__DIRENT_H_ */ 46 | -------------------------------------------------------------------------------- /encode.c: -------------------------------------------------------------------------------- 1 | /* 2 | * encode.c 3 | * 4 | * MD5 message digest in RFC1321 & BASE64 encoding in RFC3548 5 | */ 6 | 7 | #include "headers.h" 8 | #include "kctype.h" 9 | #include "sysemu.h" 10 | #include "pathname.h" 11 | #include "encode.h" 12 | 13 | static VOID NEAR voidmd5 __P_((u_long, u_long, u_long, u_long)); 14 | static VOID NEAR calcmd5 __P_((md5_t *)); 15 | static VOID NEAR initmd5 __P_((md5_t *)); 16 | static VOID NEAR addmd5 __P_((md5_t *, CONST u_char *, ALLOC_T)); 17 | static VOID NEAR endmd5 __P_((md5_t *, u_char *, ALLOC_T *)); 18 | static VOID NEAR base64encodechar __P_((char *, int, int)); 19 | 20 | static CONST char encode64table[64] = { 21 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 22 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 23 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 24 | 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 25 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 26 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 27 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', 28 | '4', '5', '6', '7', '8', '9', '+', '/', 29 | }; 30 | 31 | 32 | /*ARGSUSED*/ 33 | static VOID NEAR voidmd5(a, b, c, d) 34 | u_long a, b, c, d; 35 | { 36 | /* For bugs on NEWS-OS optimizer */ 37 | } 38 | 39 | static VOID NEAR calcmd5(md5p) 40 | md5_t *md5p; 41 | { 42 | u_long a, b, c, d, tmp, t[MD5_BLOCKS]; 43 | int i, s[MD5_BUFSIZ]; 44 | 45 | a = md5p -> sum[0]; 46 | b = md5p -> sum[1]; 47 | c = md5p -> sum[2]; 48 | d = md5p -> sum[3]; 49 | 50 | s[0] = 7; 51 | s[1] = 12; 52 | s[2] = 17; 53 | s[3] = 22; 54 | t[0] = 0xd76aa478; /* floor(4294967296.0 * fabs(sin(1.0))) */ 55 | t[1] = 0xe8c7b756; 56 | t[2] = 0x242070db; 57 | t[3] = 0xc1bdceee; 58 | t[4] = 0xf57c0faf; 59 | t[5] = 0x4787c62a; 60 | t[6] = 0xa8304613; 61 | t[7] = 0xfd469501; 62 | t[8] = 0x698098d8; 63 | t[9] = 0x8b44f7af; 64 | t[10] = 0xffff5bb1; 65 | t[11] = 0x895cd7be; 66 | t[12] = 0x6b901122; 67 | t[13] = 0xfd987193; 68 | t[14] = 0xa679438e; 69 | t[15] = 0x49b40821; 70 | for (i = 0; i < MD5_BLOCKS; i++) { 71 | a += ((b & c) | (~b & d)) + (md5p -> x[i]) + t[i]; 72 | tmp = b + ((a << s[i % MD5_BUFSIZ]) 73 | | a >> (32 - s[i % MD5_BUFSIZ])); 74 | tmp &= (u_long)0xffffffff; 75 | a = d; 76 | d = c; 77 | c = b; 78 | b = tmp; 79 | voidmd5(a, b, c, d); 80 | } 81 | 82 | s[0] = 5; 83 | s[1] = 9; 84 | s[2] = 14; 85 | s[3] = 20; 86 | t[0] = 0xf61e2562; /* floor(4294967296.0 * fabs(sin(16.0))) */ 87 | t[1] = 0xc040b340; 88 | t[2] = 0x265e5a51; 89 | t[3] = 0xe9b6c7aa; 90 | t[4] = 0xd62f105d; 91 | t[5] = 0x02441453; 92 | t[6] = 0xd8a1e681; 93 | t[7] = 0xe7d3fbc8; 94 | t[8] = 0x21e1cde6; 95 | t[9] = 0xc33707d6; 96 | t[10] = 0xf4d50d87; 97 | t[11] = 0x455a14ed; 98 | t[12] = 0xa9e3e905; 99 | t[13] = 0xfcefa3f8; 100 | t[14] = 0x676f02d9; 101 | t[15] = 0x8d2a4c8a; 102 | for (i = 0; i < MD5_BLOCKS; i++) { 103 | a += ((b & d) | (c & ~d)) 104 | + (md5p -> x[(i * 5 + 1) % MD5_BLOCKS]) + t[i]; 105 | tmp = b + ((a << s[i % MD5_BUFSIZ]) 106 | | a >> (32 - s[i % MD5_BUFSIZ])); 107 | tmp &= (u_long)0xffffffff; 108 | a = d; 109 | d = c; 110 | c = b; 111 | b = tmp; 112 | voidmd5(a, b, c, d); 113 | } 114 | 115 | s[0] = 4; 116 | s[1] = 11; 117 | s[2] = 16; 118 | s[3] = 23; 119 | t[0] = 0xfffa3942; /* floor(4294967296.0 * fabs(sin(32.0))) */ 120 | t[1] = 0x8771f681; 121 | t[2] = 0x6d9d6122; 122 | t[3] = 0xfde5380c; 123 | t[4] = 0xa4beea44; 124 | t[5] = 0x4bdecfa9; 125 | t[6] = 0xf6bb4b60; 126 | t[7] = 0xbebfbc70; 127 | t[8] = 0x289b7ec6; 128 | t[9] = 0xeaa127fa; 129 | t[10] = 0xd4ef3085; 130 | t[11] = 0x04881d05; 131 | t[12] = 0xd9d4d039; 132 | t[13] = 0xe6db99e5; 133 | t[14] = 0x1fa27cf8; 134 | t[15] = 0xc4ac5665; 135 | for (i = 0; i < MD5_BLOCKS; i++) { 136 | a += (b ^ c ^ d) 137 | + (md5p -> x[(i * 3 + 5) % MD5_BLOCKS]) + t[i]; 138 | tmp = b + ((a << s[i % MD5_BUFSIZ]) 139 | | a >> (32 - s[i % MD5_BUFSIZ])); 140 | tmp &= (u_long)0xffffffff; 141 | a = d; 142 | d = c; 143 | c = b; 144 | b = tmp; 145 | voidmd5(a, b, c, d); 146 | } 147 | 148 | s[0] = 6; 149 | s[1] = 10; 150 | s[2] = 15; 151 | s[3] = 21; 152 | t[0] = 0xf4292244; /* floor(4294967296.0 * fabs(sin(48.0))) */ 153 | t[1] = 0x432aff97; 154 | t[2] = 0xab9423a7; 155 | t[3] = 0xfc93a039; 156 | t[4] = 0x655b59c3; 157 | t[5] = 0x8f0ccc92; 158 | t[6] = 0xffeff47d; 159 | t[7] = 0x85845dd1; 160 | t[8] = 0x6fa87e4f; 161 | t[9] = 0xfe2ce6e0; 162 | t[10] = 0xa3014314; 163 | t[11] = 0x4e0811a1; 164 | t[12] = 0xf7537e82; 165 | t[13] = 0xbd3af235; 166 | t[14] = 0x2ad7d2bb; 167 | t[15] = 0xeb86d391; 168 | for (i = 0; i < MD5_BLOCKS; i++) { 169 | a += (c ^ (b | ~d)) 170 | + (md5p -> x[(i * 7) % MD5_BLOCKS]) + t[i]; 171 | tmp = b + ((a << s[i % MD5_BUFSIZ]) 172 | | a >> (32 - s[i % MD5_BUFSIZ])); 173 | tmp &= (u_long)0xffffffff; 174 | a = d; 175 | d = c; 176 | c = b; 177 | b = tmp; 178 | voidmd5(a, b, c, d); 179 | } 180 | 181 | md5p -> sum[0] = (md5p -> sum[0] + a) & (u_long)0xffffffff; 182 | md5p -> sum[1] = (md5p -> sum[1] + b) & (u_long)0xffffffff; 183 | md5p -> sum[2] = (md5p -> sum[2] + c) & (u_long)0xffffffff; 184 | md5p -> sum[3] = (md5p -> sum[3] + d) & (u_long)0xffffffff; 185 | } 186 | 187 | static VOID NEAR initmd5(md5p) 188 | md5_t *md5p; 189 | { 190 | md5p -> cl = md5p -> ch = (u_long)0; 191 | md5p -> sum[0] = (u_long)0x67452301; 192 | md5p -> sum[1] = (u_long)0xefcdab89; 193 | md5p -> sum[2] = (u_long)0x98badcfe; 194 | md5p -> sum[3] = (u_long)0x10325476; 195 | memset((char *)(md5p -> x), 0, sizeof(md5p -> x)); 196 | md5p -> n = md5p -> b = 0; 197 | } 198 | 199 | static VOID NEAR addmd5(md5p, s, len) 200 | md5_t *md5p; 201 | CONST u_char *s; 202 | ALLOC_T len; 203 | { 204 | while (len--) { 205 | if (md5p -> cl <= (u_long)0xffffffff - (u_long)BITSPERBYTE) 206 | md5p -> cl += (u_long)BITSPERBYTE; 207 | else { 208 | md5p -> cl -= 209 | (u_long)0xffffffff - (u_long)BITSPERBYTE + 1; 210 | (md5p -> ch)++; 211 | md5p -> ch &= (u_long)0xffffffff; 212 | } 213 | 214 | md5p -> x[md5p -> n] |= ((u_long)(*(s++)) << (md5p -> b)); 215 | if ((md5p -> b += BITSPERBYTE) >= BITSPERBYTE * 4) { 216 | md5p -> b = 0; 217 | if (++(md5p -> n) >= MD5_BLOCKS) { 218 | md5p -> n = 0; 219 | calcmd5(md5p); 220 | memset((char *)(md5p -> x), 221 | 0, sizeof(md5p -> x)); 222 | } 223 | } 224 | } 225 | } 226 | 227 | static VOID NEAR endmd5(md5p, buf, sizep) 228 | md5_t *md5p; 229 | u_char *buf; 230 | ALLOC_T *sizep; 231 | { 232 | ALLOC_T ptr; 233 | int i, n; 234 | 235 | md5p -> x[md5p -> n] |= (1 << ((md5p -> b) + BITSPERBYTE - 1)); 236 | if (md5p -> n >= 14) { 237 | calcmd5(md5p); 238 | memset((char *)(md5p -> x), 0, sizeof(md5p -> x)); 239 | } 240 | md5p -> x[14] = md5p -> cl; 241 | md5p -> x[15] = md5p -> ch; 242 | calcmd5(md5p); 243 | 244 | ptr = (ALLOC_T)0; 245 | for (i = 0; i < MD5_BUFSIZ; i++) for (n = 0; n < 4; n++) { 246 | if (ptr >= *sizep) break; 247 | buf[ptr++] = (md5p -> sum[i] & 0xff); 248 | md5p -> sum[i] >>= BITSPERBYTE; 249 | } 250 | 251 | *sizep = ptr; 252 | } 253 | 254 | VOID md5encode(buf, sizep, s, len) 255 | u_char *buf; 256 | ALLOC_T *sizep; 257 | CONST u_char *s; 258 | ALLOC_T len; 259 | { 260 | md5_t md5; 261 | 262 | if (!s) s = (u_char *)nullstr; 263 | if (len == (ALLOC_T)-1) len = strlen((char *)s); 264 | 265 | initmd5(&md5); 266 | addmd5(&md5, s, len); 267 | endmd5(&md5, buf, sizep); 268 | } 269 | 270 | int md5fencode(buf, sizep, fp) 271 | u_char *buf; 272 | ALLOC_T *sizep; 273 | XFILE *fp; 274 | { 275 | md5_t md5; 276 | u_char tmp[MD5_FILBUFSIZ]; 277 | int n; 278 | 279 | initmd5(&md5); 280 | if (fp) for (;;) { 281 | n = Xfread((char *)tmp, sizeof(tmp), fp); 282 | if (n < 0) return(-1); 283 | else if (!n) break; 284 | addmd5(&md5, tmp, n); 285 | } 286 | endmd5(&md5, buf, sizep); 287 | 288 | return(0); 289 | } 290 | 291 | static VOID NEAR base64encodechar(s, n, val) 292 | char *s; 293 | int n, val; 294 | { 295 | val &= 0x3f; 296 | s[n] = encode64table[val]; 297 | } 298 | 299 | int base64encode(buf, size, s, len) 300 | char *buf; 301 | ALLOC_T size; 302 | CONST u_char *s; 303 | ALLOC_T len; 304 | { 305 | int i, j, n; 306 | 307 | if (len == (ALLOC_T)-1) len = strlen((char *)s); 308 | for (i = j = 0; i < len; i++) { 309 | if (j + BASE64_ENCSIZ >= size) { 310 | errno = ERANGE; 311 | return(-1); 312 | } 313 | base64encodechar(buf, j++, s[i] >> 2); 314 | n = ((s[i] << 4) & 0x30); 315 | if (i + 1 >= len) { 316 | base64encodechar(buf, j++, n); 317 | buf[j++] = '='; 318 | buf[j++] = '='; 319 | } 320 | else { 321 | base64encodechar(buf, j++, 322 | n | ((s[++i] >> 4) & 0x0f)); 323 | n = ((s[i] << 2) & 0x3c); 324 | if (i + 1 >= len) { 325 | base64encodechar(buf, j++, n); 326 | buf[j++] = '='; 327 | } 328 | else { 329 | base64encodechar(buf, j++, 330 | n | ((s[++i] >> 6) & 0x03)); 331 | base64encodechar(buf, j++, s[i]); 332 | } 333 | } 334 | } 335 | buf[j] = '\0'; 336 | errno = 0; 337 | 338 | return(0); 339 | } 340 | -------------------------------------------------------------------------------- /encode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * encode.h 3 | * 4 | * definitions & function prototype declarations for "md5.c" & "base64.c" 5 | */ 6 | 7 | #include "stream.h" 8 | 9 | #define MD5_BUFSIZ (128 / 32) 10 | #define MD5_BLOCKS 16 11 | #define MD5_FILBUFSIZ 512 12 | #define BASE64_ORGSIZ 3 13 | #define BASE64_ENCSIZ 4 14 | 15 | typedef struct _md5_t { 16 | u_long cl, ch; 17 | u_long sum[MD5_BUFSIZ]; 18 | u_long x[MD5_BLOCKS]; 19 | int n, b; 20 | } md5_t; 21 | 22 | extern VOID md5encode __P_((u_char *, ALLOC_T *, CONST u_char *, ALLOC_T)); 23 | extern int md5fencode __P_((u_char *, ALLOC_T *, XFILE *)); 24 | extern int base64encode __P_((char *, ALLOC_T, CONST u_char *, ALLOC_T)); 25 | extern int base64decode __P_((u_char *, ALLOC_T *, CONST char *, ALLOC_T)); 26 | -------------------------------------------------------------------------------- /evalopt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * evalopt.c 3 | * 4 | * option arguments parser 5 | */ 6 | 7 | #include "headers.h" 8 | #include "evalopt.h" 9 | 10 | static CONST opt_t *NEAR getoption __P_((int, CONST opt_t *)); 11 | 12 | 13 | static CONST opt_t *NEAR getoption(c, optlist) 14 | int c; 15 | CONST opt_t *optlist; 16 | { 17 | int n; 18 | 19 | if (!optlist) return(NULL); 20 | for (n = 0; optlist[n].opt; n++) 21 | if (c == optlist[n].opt) return(&(optlist[n])); 22 | 23 | return(NULL); 24 | } 25 | 26 | VOID initopt(optlist) 27 | CONST opt_t *optlist; 28 | { 29 | int n; 30 | 31 | if (!optlist) return; 32 | for (n = 0; optlist[n].opt; n++) 33 | if (optlist[n].var) *(optlist[n].var) = 0; 34 | } 35 | 36 | VOID optusage(arg0, args, optlist) 37 | CONST char *arg0, *args; 38 | CONST opt_t *optlist; 39 | { 40 | int n; 41 | 42 | fprintf(stderr, "Usage: %s", arg0); 43 | n = 0; 44 | if (optlist) while (optlist[n].opt) n++; 45 | if (n > 0) { 46 | fputs(" [-", stderr); 47 | for (n = 0; optlist[n].opt; n++) { 48 | fputc(optlist[n].opt, stderr); 49 | 50 | if (!(optlist[n].argval)) continue; 51 | fprintf(stderr, " <%s>", optlist[n].argval); 52 | if (optlist[n + 1].opt) fputs(" [-", stderr); 53 | } 54 | fputc(']', stderr); 55 | } 56 | fprintf(stderr, " %s\n", args); 57 | } 58 | 59 | int evalopt(argc, argv, optlist) 60 | int argc; 61 | char *CONST *argv; 62 | CONST opt_t *optlist; 63 | { 64 | CONST char *cp; 65 | CONST opt_t *optp; 66 | int i, n, val; 67 | 68 | for (n = 1; n < argc; n++) { 69 | if (argv[n][0] != '-' || !argv[n][1]) break; 70 | if (argv[n][1] == '=' && !argv[n][2]) { 71 | n++; 72 | break; 73 | } 74 | 75 | for (i = 1; argv[n][i]; i++) { 76 | if (!(optp = getoption(argv[n][i], optlist))) 77 | return(-1); 78 | 79 | if (!(optp -> argval)) { 80 | if (optp -> var) *(optp -> var) = optp -> val; 81 | } 82 | else { 83 | cp = &(argv[n][++i]); 84 | if (!*cp) cp = argv[++n]; 85 | if (!cp || (val = atoi(cp)) <= 0) return(-1); 86 | if (optp -> var) *(optp -> var) = val; 87 | break; 88 | } 89 | } 90 | } 91 | 92 | return(n); 93 | } 94 | -------------------------------------------------------------------------------- /evalopt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * evalopt.h 3 | * 4 | * definitions & function prototype declarations for "evalopt.c" 5 | */ 6 | 7 | #ifndef __EVALOPT_H_ 8 | #define __EVALOPT_H_ 9 | 10 | typedef struct _opt_t { 11 | int opt; 12 | int *var; 13 | int val; 14 | CONST char *argval; 15 | } opt_t; 16 | 17 | extern VOID initopt __P_((CONST opt_t *)); 18 | extern VOID optusage __P_((CONST char *, CONST char*, CONST opt_t *)); 19 | extern int evalopt __P_((int, char *CONST *, CONST opt_t *)); 20 | 21 | #endif /* __EVALOPT_H_ */ 22 | -------------------------------------------------------------------------------- /fd.spec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/knu/FDclone/460e59145805a9e34dd3a88c4278db8c142b5db0/fd.spec -------------------------------------------------------------------------------- /fsinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * fsinfo.h 3 | * 4 | * definitions for file system information 5 | */ 6 | 7 | #ifndef __FSINFO_H_ 8 | #define __FSINFO_H_ 9 | 10 | #if (!defined (USEMOUNTH) && !defined (USEFSDATA) \ 11 | && (defined (USEGETFSSTAT) || defined (USEGETVFSTAT) \ 12 | || defined (USEMNTINFOR) || defined (USEMNTINFO))) \ 13 | || defined (USEMOUNTH) || defined (USEFSDATA) 14 | #include 15 | #endif 16 | #if defined (USEGETFSSTAT) || defined (USEGETMNT) 17 | #include 18 | #endif 19 | #ifdef USEGETFSENT 20 | #include 21 | #endif 22 | #if defined (USESTATVFSH) || defined (USEGETVFSTAT) 23 | #include 24 | #endif 25 | #ifdef USESTATFSH 26 | #include 27 | #endif 28 | #ifdef USEVFSH 29 | #include 30 | #endif 31 | 32 | #ifdef USESTATVFSH 33 | # ifdef USESTATVFS_T 34 | typedef statvfs_t statfs_t; 35 | # else 36 | typedef struct statvfs statfs_t; 37 | # endif 38 | #define Xstatfs statvfs 39 | #define blocksize(fs) ((fs).f_frsize ? (fs).f_frsize : (fs).f_bsize) 40 | #endif /* USESTATVFSH */ 41 | 42 | #ifdef USESTATFSH 43 | #define Xf_bavail f_bfree 44 | typedef struct statfs statfs_t; 45 | #define blocksize(fs) (fs).f_bsize 46 | #endif 47 | 48 | #ifdef USEVFSH 49 | typedef struct statfs statfs_t; 50 | #define blocksize(fs) (fs).f_bsize 51 | #endif 52 | 53 | #ifdef USEMOUNTH 54 | typedef struct statfs statfs_t; 55 | #define blocksize(fs) (fs).f_bsize 56 | #endif 57 | 58 | #ifdef USEFSDATA 59 | typedef struct fs_data statfs_t; 60 | #define Xf_bsize fd_req.bsize 61 | #define Xf_files fd_req.gtot 62 | #define Xf_blocks fd_req.btot 63 | #define Xf_bfree fd_req.bfree 64 | #define Xf_bavail fd_req.bfreen 65 | #define Xstatfs(p, b) (statfs(p, b) - 1) 66 | #define blocksize(fs) 1024 67 | #endif 68 | 69 | #ifdef USEFFSIZE 70 | #define Xf_bsize f_fsize 71 | #endif 72 | 73 | #ifndef Xf_bsize 74 | #define Xf_bsize f_bsize 75 | #endif 76 | #ifndef Xf_files 77 | #define Xf_files f_files 78 | #endif 79 | #ifndef Xf_blocks 80 | #define Xf_blocks f_blocks 81 | #endif 82 | #ifndef Xf_bfree 83 | #define Xf_bfree f_bfree 84 | #endif 85 | #ifndef Xf_bavail 86 | #define Xf_bavail f_bavail 87 | #endif 88 | 89 | #if defined (USESTATFSH) || defined (USEVFSH) || defined (USEMOUNTH) 90 | # if (STATFSARGS >= 4) 91 | # define Xstatfs(p, b) statfs(p, b, sizeof(statfs_t), 0) 92 | # else /* STATFSARGS < 4 */ 93 | # if (STATFSARGS == 3) 94 | # define Xstatfs(p, b) statfs(p, b, sizeof(statfs_t)) 95 | # else /* STATFSARGS != 3 */ 96 | # ifdef USEFSTATFS 97 | extern int Xstatfs __P_((CONST char *, statfs_t *)); 98 | # else 99 | # define Xstatfs statfs 100 | # endif 101 | # endif /* STATFSARGS != 3 */ 102 | # endif /* STATFSARGS < 4 */ 103 | #endif /* USESTATFSH || USEVFSH || USEMOUNTH */ 104 | 105 | #if MSDOS 106 | typedef struct _statfs_t { 107 | long Xf_bsize; 108 | long Xf_blocks; 109 | long Xf_bfree; 110 | long Xf_bavail; 111 | long Xf_files; 112 | } statfs_t; 113 | #define Xstatfs unixstatfs 114 | #define blocksize(fs) (fs).Xf_bsize 115 | #endif 116 | 117 | #endif /* !__FSINFO_H_ */ 118 | -------------------------------------------------------------------------------- /functabl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * functabl.h 3 | * 4 | * function status table 5 | */ 6 | 7 | #ifndef _TBL_ 8 | #define _TBL_(fn, id, hl, fl) {fn, id, hl, BIN(fl)} 9 | #endif 10 | 11 | #define BIN(oct) ( (((oct) ) & 0001) \ 12 | | (((oct) >> 2) & 0002) \ 13 | | (((oct) >> 4) & 0004) \ 14 | | (((oct) >> 6) & 0010) \ 15 | | (((oct) >> 8) & 0020) \ 16 | | (((oct) >> 10) & 0040) \ 17 | | (((oct) >> 12) & 0100) \ 18 | | (((oct) >> 14) & 0200)) 19 | 20 | CONST functable funclist[] = { 21 | /* +---------- NEEDSTATUS 22 | * |+--------- RESTRICT 23 | * ||+-------- NOFILE 24 | * |||+------- ARCHIVE 25 | * ||||+------ KILLSTACK 26 | * |||||+----- RESCREEN 27 | * ||||||++-- 01: REWRITE 28 | * |||||||| 10: RELIST 29 | * |||||||| 11: REWIN 30 | * |||||||| */ 31 | _TBL_(cur_up, "CUR_UP", CUP_H, 000010000), 32 | _TBL_(cur_down, "CUR_DOWN", CDWN_H, 000010000), 33 | _TBL_(cur_right, "CUR_RIGHT", CRIG_H, 000010000), 34 | _TBL_(cur_left, "CUR_LEFT", CLEF_H, 000010000), 35 | _TBL_(roll_up, "ROLL_UP", RUP_H, 000010010), 36 | _TBL_(roll_down, "ROLL_DOWN", RDWN_H, 000010010), 37 | _TBL_(cur_top, "CUR_TOP", CTOP_H, 000010000), 38 | _TBL_(cur_bottom, "CUR_BOTTOM", CBTM_H, 000010000), 39 | _TBL_(fname_right, "FNAME_RIGHT", FNRI_H, 000010001), 40 | _TBL_(fname_left, "FNAME_LEFT", FNLE_H, 000010001), 41 | _TBL_(one_column, "ONE_COLUMN", COL1_H, 000110111), 42 | _TBL_(two_columns, "TWO_COLUMNS", COL2_H, 000110111), 43 | _TBL_(three_columns, "THREE_COLUMNS",COL3_H, 000110111), 44 | _TBL_(five_columns, "FIVE_COLUMNS", COL5_H, 000110111), 45 | _TBL_(mark_file, "MARK_FILE", MRK_H, 010010001), 46 | _TBL_(mark_file2, "MARK_FILE2", MRK2_H, 010010001), 47 | _TBL_(mark_file3, "MARK_FILE3", MRK2_H, 010010001), 48 | _TBL_(mark_all, "MARK_ALL", MRKA_H, 010010010), 49 | _TBL_(mark_reverse, "MARK_REVERSE", MRKR_H, 010010010), 50 | _TBL_(mark_find, "MARK_FIND", MRKF_H, 010010010), 51 | _TBL_(in_dir, "IN_DIR", IND_H, 011011000), 52 | _TBL_(out_dir, "OUT_DIR", OUTD_H, 001111000), 53 | _TBL_(log_top, "LOG_TOP", LOGT_H, 001101000), 54 | _TBL_(reread_dir, "REREAD_DIR", READ_H, 000110000), 55 | _TBL_(push_file, "PUSH_FILE", PUSH_H, 000010110), 56 | _TBL_(pop_file, "POP_FILE", POP_H, 000010110), 57 | _TBL_(log_dir, "LOG_DIR", LOGD_H, 001111000), 58 | _TBL_(attr_file, "ATTR_FILE", ATTR_H, 011001110), 59 | _TBL_(execute_file, "EXECUTE_FILE", EXEF_H, 010011111), 60 | _TBL_(info_filesys, "INFO_FILESYS", INFO_H, 000110010), 61 | _TBL_(copy_file, "COPY_FILE", COPY_H, 011001000), 62 | _TBL_(move_file, "MOVE_FILE", MOVE_H, 011001000), 63 | _TBL_(delete_file, "DELETE_FILE", DELF_H, 011001000), 64 | _TBL_(delete_dir, "DELETE_DIR", DELD_H, 011001000), 65 | _TBL_(rename_file, "RENAME_FILE", RENM_H, 001001000), 66 | _TBL_(make_dir, "MAKE_DIR", MKDR_H, 001101000), 67 | _TBL_(sort_dir, "SORT_DIR", SORT_H, 000010110), 68 | _TBL_(execute_sh, "EXECUTE_SH", EXSH_H, 000111111), 69 | _TBL_(find_file, "FIND_FILE", FNDF_H, 000111000), 70 | #ifndef _NOWRITEFS 71 | _TBL_(write_dir, "WRITE_DIR", WRIT_H, 001001000), 72 | #endif 73 | #ifndef _NOTREE 74 | _TBL_(tree_dir, "TREE_DIR", TREE_H, 001101110), 75 | #endif 76 | #ifndef _NOARCHIVE 77 | _TBL_(backup_tape, "BACKUP_TAPE", BACK_H, 001011000), 78 | #endif 79 | _TBL_(edit_file, "EDIT_FILE", EDIT_H, 011001000), 80 | _TBL_(view_file, "VIEW_FILE", VIEW_H, 010010111), 81 | #ifndef _NOARCHIVE 82 | _TBL_(unpack_file, "UNPACK_FILE", UNPK_H, 011011000), 83 | _TBL_(pack_file, "PACK_FILE", PACK_H, 001011000), 84 | #endif 85 | #ifndef _NOTREE 86 | _TBL_(tree_dir, "LOG_TREE", LGTR_H, 001101110), 87 | _TBL_(copy_tree, "COPY_TREE", CPTR_H, 011001110), 88 | _TBL_(move_tree, "MOVE_TREE", MVTR_H, 011001110), 89 | # ifndef _NOARCHIVE 90 | _TBL_(unpack_tree, "UNPACK_TREE", UPTR_H, 011011110), 91 | # endif 92 | #endif /* !_NOTREE */ 93 | _TBL_(find_dir, "FIND_DIR", FNDD_H, 011001110), 94 | #ifndef _NOEXTRAATTR 95 | _TBL_(attr_dir, "ATTR_DIR", ATRD_H, 011001110), 96 | #endif 97 | _TBL_(symlink_mode, "SYMLINK_MODE", SYLN_H, 000100000), 98 | _TBL_(filetype_mode, "FILETYPE_MODE",FLTY_H, 000110110), 99 | _TBL_(dotfile_mode, "DOTFILE_MODE", DTFL_H, 000101000), 100 | _TBL_(fileflg_mode, "FILEFLG_MODE", FLFL_H, 000100110), 101 | #ifndef _NOARCHIVE 102 | _TBL_(launch_file, "LAUNCH_FILE", LAUN_H, 010011111), 103 | #endif 104 | _TBL_(search_forw, "SEARCH_FORW", SEAF_H, 000010000), 105 | _TBL_(search_back, "SEARCH_BACK", SEAB_H, 000010000), 106 | #ifndef _NOSPLITWIN 107 | _TBL_(split_window, "SPLIT_WINDOW", SPWN_H, 000101000), 108 | _TBL_(next_window, "NEXT_WINDOW", NXWN_H, 000111000), 109 | #endif 110 | #ifndef _NOEXTRAWIN 111 | _TBL_(widen_window, "WIDEN_WINDOW", WDWN_H, 000111000), 112 | _TBL_(narrow_window, "NARROW_WINDOW",NRWN_H, 000111000), 113 | _TBL_(kill_window, "KILL_WINDOW", KLWN_H, 000101000), 114 | #endif 115 | #ifndef _NOCUSTOMIZE 116 | _TBL_(edit_config, "EDIT_CONFIG", EDCF_H, 000111110), 117 | #endif 118 | _TBL_(help_message, "HELP_MESSAGE", HELP_H, 000110110), 119 | _TBL_(quit_system, "QUIT_SYSTEM", QUIT_H, 000111000), 120 | _TBL_(warning_bell, "WARNING_BELL", WARN_H, 000110000), 121 | _TBL_(no_operation, "NO_OPERATION", NOOP_H, 000110000) 122 | }; 123 | -------------------------------------------------------------------------------- /gentbl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * gentbl.c 3 | * 4 | * table generator module 5 | */ 6 | 7 | #include "headers.h" 8 | #include "gentbl.h" 9 | 10 | #define MAXBYTES 8 11 | 12 | int textmode = 0; 13 | 14 | static int textlen = 0; 15 | static int textnext = 0; 16 | 17 | 18 | FILE *opentbl(path) 19 | CONST char *path; 20 | { 21 | FILE *fp; 22 | 23 | if (!(fp = fopen(path, (textmode) ? "w" : "wb"))) { 24 | fprintf(stderr, "%s: Cannot open.\n", path); 25 | return(NULL); 26 | } 27 | 28 | return(fp); 29 | } 30 | 31 | int fputheader(name, fp) 32 | CONST char *name; 33 | FILE *fp; 34 | { 35 | if (!textmode) return(0); 36 | if (fprintf(fp, "#include \"%s.h\"\n", name) < 0 && ferror(fp)) 37 | return(-1); 38 | 39 | return(0); 40 | } 41 | 42 | int fputbegin(name, fp) 43 | CONST char *name; 44 | FILE *fp; 45 | { 46 | if (!textmode) return(0); 47 | textnext = textlen = 0; 48 | if (fprintf(fp, "CONST u_char %s[] = {", name) < 0 && ferror(fp)) 49 | return(-1); 50 | 51 | return(0); 52 | } 53 | 54 | int fputend(fp) 55 | FILE *fp; 56 | { 57 | if (!textmode) return(0); 58 | 59 | if (!textnext) { 60 | fputbyte('\0', fp); 61 | fputs("\t/* dummy entry */", fp); 62 | } 63 | 64 | return((fputs("\n};\n", fp) == EOF && ferror(fp)) ? -1 : 0); 65 | } 66 | 67 | int fputbyte(c, fp) 68 | int c; 69 | FILE *fp; 70 | { 71 | CONST char *sep1, *sep2; 72 | 73 | if (!textmode) return((fputc(c, fp) == EOF && ferror(fp)) ? -1 : 0); 74 | 75 | sep1 = (textnext) ? "," : ""; 76 | sep2 = (textlen) ? " " : "\n\t"; 77 | 78 | textnext = 1; 79 | if (++textlen >= MAXBYTES) textlen = 0; 80 | 81 | if (fprintf(fp, "%s%s0x%02x", sep1, sep2, c & 0xff) < 0 && ferror(fp)) 82 | return(-1); 83 | 84 | return(0); 85 | } 86 | 87 | int fputword(w, fp) 88 | u_int w; 89 | FILE *fp; 90 | { 91 | if (fputbyte((int)(w & 0xff), fp) < 0 92 | || fputbyte((int)((w >> 8) & 0xff), fp) < 0) 93 | return(-1); 94 | 95 | return(0); 96 | } 97 | 98 | int fputdword(dw, fp) 99 | long dw; 100 | FILE *fp; 101 | { 102 | if (fputword((u_int)(dw & 0xffff), fp) < 0 103 | || fputword((u_int)((dw >> 16) & 0xffff), fp) < 0) 104 | return(-1); 105 | 106 | return(0); 107 | } 108 | 109 | int fputbuf(buf, size, fp) 110 | CONST u_char *buf; 111 | ALLOC_T size; 112 | FILE *fp; 113 | { 114 | ALLOC_T n; 115 | 116 | if (!textmode) { 117 | if (fwrite(buf, size, (ALLOC_T)1, fp) != (ALLOC_T)1) 118 | return(-1); 119 | } 120 | else for (n = (ALLOC_T)0; n < size; n++) 121 | if (fputbyte((int)(buf[n]), fp) < 0) return(-1); 122 | 123 | return(0); 124 | } 125 | 126 | int fputlength(name, len, fp, width) 127 | CONST char *name; 128 | long len; 129 | FILE *fp; 130 | int width; 131 | { 132 | CONST char *cp; 133 | 134 | if (!textmode) { 135 | switch (width) { 136 | case 2: 137 | if (fputword(len, fp) < 0) return(-1); 138 | break; 139 | case 4: 140 | if (fputdword(len, fp) < 0) return(-1); 141 | break; 142 | default: 143 | if (fputbyte(len, fp) < 0) return(-1); 144 | break; 145 | } 146 | return(0); 147 | } 148 | 149 | switch (width) { 150 | case 2: 151 | cp = "u_int"; 152 | break; 153 | case 4: 154 | cp = "long"; 155 | break; 156 | default: 157 | cp = "int"; 158 | break; 159 | } 160 | 161 | if (fprintf(fp, "%s %s = %ld;\n", cp, name, len) < 0 && ferror(fp)) 162 | return(-1); 163 | 164 | return(0); 165 | } 166 | -------------------------------------------------------------------------------- /gentbl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gentbl.h 3 | * 4 | * definitions & function prototype declarations for "gentbl.c" 5 | */ 6 | 7 | #ifndef __GENTBL_H_ 8 | #define __GENTBL_H_ 9 | 10 | extern FILE *opentbl __P_((CONST char *)); 11 | extern int fputheader __P_((CONST char *, FILE *)); 12 | extern int fputbegin __P_((CONST char *, FILE *)); 13 | extern int fputend __P_((FILE *)); 14 | extern int fputbyte __P_((int, FILE *)); 15 | extern int fputword __P_((u_int, FILE *)); 16 | extern int fputdword __P_((long, FILE *)); 17 | extern int fputbuf __P_((CONST u_char *, ALLOC_T, FILE *)); 18 | extern int fputlength __P_((CONST char *, long, FILE *, int)); 19 | 20 | extern int textmode; 21 | 22 | #endif /* __GENTBL_H_ */ 23 | -------------------------------------------------------------------------------- /headers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * headers.h 3 | * 4 | * include headers 5 | */ 6 | 7 | #ifdef __HOST_CC__ 8 | #include "hmachine.h" 9 | #else 10 | #include "machine.h" 11 | #endif 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #ifdef BUGGYSIGNALH 18 | #define _SYSTEM /* TIPS for MINIX 3.2 bug */ 19 | #endif 20 | #include 21 | #ifdef BUGGYSIGNALH 22 | #undef _SYSTEM 23 | #endif 24 | 25 | #include 26 | #include 27 | 28 | #ifndef NOUNISTDH 29 | #include 30 | #endif 31 | 32 | #ifndef NOSTDLIBH 33 | #include 34 | #endif 35 | 36 | #ifdef USETIMEH 37 | #include 38 | #endif 39 | 40 | #ifdef USESTDARGH 41 | #include 42 | #else 43 | #include 44 | #endif 45 | 46 | #if MSDOS 47 | #undef MAXPATHLEN 48 | #define MAXPATHLEN 260 49 | #undef MAXNAMLEN 50 | #define MAXNAMLEN 255 51 | #else /* !MSDOS */ 52 | #include 53 | #include 54 | #include 55 | # ifdef USEUTIME 56 | # include 57 | # endif 58 | # ifdef MINIX 59 | # include 60 | # endif 61 | # if !defined (MAXPATHLEN) && defined (PATH_MAX) 62 | # define MAXPATHLEN PATH_MAX 63 | # endif 64 | #endif /* !MSDOS */ 65 | 66 | #ifndef O_BINARY 67 | #define O_BINARY 0 68 | #endif 69 | #ifndef O_TEXT 70 | #define O_TEXT 0 71 | #endif 72 | #ifndef O_NOCTTY 73 | #define O_NOCTTY 0 74 | #endif 75 | #ifndef O_ACCMODE 76 | #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) 77 | #endif 78 | 79 | #ifndef L_SET 80 | # ifdef SEEK_SET 81 | # define L_SET SEEK_SET 82 | # else 83 | # define L_SET 0 84 | # endif 85 | #endif /* !L_SET */ 86 | #ifndef L_INCR 87 | # ifdef SEEK_CUR 88 | # define L_INCR SEEK_CUR 89 | # else 90 | # define L_INCR 1 91 | # endif 92 | #endif /* !L_INCR */ 93 | #ifndef L_XTND 94 | # ifdef SEEK_END 95 | # define L_XTND SEEK_END 96 | # else 97 | # define L_XTND 2 98 | # endif 99 | #endif /* !L_XTND */ 100 | 101 | #ifdef __TURBOC__ 102 | #undef EFAULT 103 | #undef ENFILE 104 | #undef ENOSPC 105 | #undef EROFS 106 | #undef EPERM 107 | #undef EINTR 108 | #undef EIO 109 | #undef ENXIO 110 | #undef ENOTDIR 111 | #undef EISDIR 112 | #endif /* __TURBOC__ */ 113 | 114 | #ifndef ENOSPC 115 | #define ENOSPC EACCES 116 | #endif 117 | #ifndef ENODEV 118 | #define ENODEV EACCES 119 | #endif 120 | #ifndef EIO 121 | #define EIO ENODEV 122 | #endif 123 | #ifndef EISDIR 124 | #define EISDIR EACCES 125 | #endif 126 | #ifndef ENOTEMPTY 127 | # ifdef ENFSNOTEMPTY 128 | # define ENOTEMPTY ENFSNOTEMPTY 129 | # else 130 | # define ENOTEMPTY EACCES 131 | # endif 132 | #endif /* !ENOTEMPTY */ 133 | #ifndef EPERM 134 | #define EPERM EACCES 135 | #endif 136 | #ifndef EFAULT 137 | #define EFAULT ENODEV 138 | #endif 139 | #ifndef EROFS 140 | #define EROFS EACCES 141 | #endif 142 | #ifndef ENAMETOOLONG 143 | #define ENAMETOOLONG ERANGE 144 | #endif 145 | #ifndef ENOTDIR 146 | #define ENOTDIR ENOENT 147 | #endif 148 | #ifndef EINTR 149 | #define EINTR 0 150 | #endif 151 | #ifndef ETIMEDOUT 152 | #define ETIMEDOUT EIO 153 | #endif 154 | 155 | #ifdef NOERRNO 156 | extern int errno; 157 | #endif 158 | #ifdef USESTRERROR 159 | #define Xstrerror strerror 160 | #else /* !USESTRERROR */ 161 | # ifndef DECLERRLIST 162 | extern CONST char *CONST sys_errlist[]; 163 | # endif 164 | #define Xstrerror(n) (char *)sys_errlist[n] 165 | #endif /* !USESTRERROR */ 166 | 167 | #ifdef USESTDARGH 168 | #define VA_START(a, f) va_start(a, f) 169 | #else 170 | #define VA_START(a, f) va_start(a) 171 | #endif 172 | 173 | #ifndef R_OK 174 | #define R_OK 4 175 | #endif 176 | #ifndef W_OK 177 | #define W_OK 2 178 | #endif 179 | #ifndef X_OK 180 | #define X_OK 1 181 | #endif 182 | #ifndef F_OK 183 | #define F_OK 0 184 | #endif 185 | 186 | #ifndef LOCK_SH 187 | #define LOCK_SH 1 188 | #endif 189 | #ifndef LOCK_EX 190 | #define LOCK_EX 2 191 | #endif 192 | #ifndef LOCK_NB 193 | #define LOCK_NB 4 194 | #endif 195 | #ifndef LOCK_UN 196 | #define LOCK_UN 8 197 | #endif 198 | 199 | #if !MSDOS && defined (UF_SETTABLE) && defined (SF_SETTABLE) 200 | #define HAVEFLAGS 201 | #endif 202 | 203 | #undef S_IRUSR 204 | #undef S_IWUSR 205 | #undef S_IXUSR 206 | #undef S_IRGRP 207 | #undef S_IWGRP 208 | #undef S_IXGRP 209 | #undef S_IROTH 210 | #undef S_IWOTH 211 | #undef S_IXOTH 212 | #define S_IRUSR 00400 213 | #define S_IWUSR 00200 214 | #define S_IXUSR 00100 215 | #define S_IRGRP 00040 216 | #define S_IWGRP 00020 217 | #define S_IXGRP 00010 218 | #define S_IROTH 00004 219 | #define S_IWOTH 00002 220 | #define S_IXOTH 00001 221 | #define S_IREAD_ALL (S_IRUSR | S_IRGRP | S_IROTH) 222 | #define S_IWRITE_ALL (S_IWUSR | S_IWGRP | S_IWOTH) 223 | #define S_IEXEC_ALL (S_IXUSR | S_IXGRP | S_IXOTH) 224 | 225 | #undef S_IFLNK 226 | #undef S_IFSOCK 227 | #undef S_IFIFO 228 | #undef S_ISUID 229 | #undef S_ISGID 230 | #undef S_ISVTX 231 | #define S_IFLNK 0120000 232 | #define S_IFSOCK 0140000 233 | #define S_IFIFO 0010000 234 | #define S_ISUID 0004000 235 | #define S_ISGID 0002000 236 | #define S_ISVTX 0001000 237 | 238 | #ifdef HAVEFLAGS 239 | # ifndef UF_NODUMP 240 | # define UF_NODUMP 0x00000001 241 | # endif 242 | # ifndef UF_IMMUTABLE 243 | # define UF_IMMUTABLE 0x00000002 244 | # endif 245 | # ifndef UF_APPEND 246 | # define UF_APPEND 0x00000004 247 | # endif 248 | # ifndef UF_NOUNLINK 249 | # define UF_NOUNLINK 0x00000010 250 | # endif 251 | # ifndef SF_ARCHIVED 252 | # define SF_ARCHIVED 0x00010000 253 | # endif 254 | # ifndef SF_IMMUTABLE 255 | # define SF_IMMUTABLE 0x00020000 256 | # endif 257 | # ifndef SF_APPEND 258 | # define SF_APPEND 0x00040000 259 | # endif 260 | # ifndef SF_NOUNLINK 261 | # define SF_NOUNLINK 0x00080000 262 | # endif 263 | #endif /* HAVEFLAGS */ 264 | 265 | #ifdef NOUID_T 266 | typedef u_short uid_t; 267 | typedef u_short gid_t; 268 | #endif 269 | #ifdef OLDARGINT 270 | typedef int u_id_t; 271 | typedef int g_id_t; 272 | #define convuid(u) (((u) == (uid_t)-1) ? (u_id_t)-1 : (u_id_t)(u)) 273 | #define convgid(g) (((g) == (gid_t)-1) ? (g_id_t)-1 : (g_id_t)(g)) 274 | #else 275 | typedef uid_t u_id_t; 276 | typedef gid_t g_id_t; 277 | #define convuid(u) (u) 278 | #define convgid(g) (g) 279 | #endif 280 | -------------------------------------------------------------------------------- /html.h: -------------------------------------------------------------------------------- 1 | /* 2 | * html.h 3 | * 4 | * definitions & function prototype declarations for "html.c" 5 | */ 6 | 7 | #include "stream.h" 8 | 9 | typedef struct _htmlstat_t { 10 | XFILE *fp; 11 | char *buf; 12 | char *path; 13 | ALLOC_T ptr; 14 | ALLOC_T len; 15 | ALLOC_T max; 16 | int charset; 17 | int flags; 18 | } htmlstat_t; 19 | 20 | #define HTML_LVL 00007 21 | #define HTML_NONE 00000 22 | #define HTML_HTML 00001 23 | #define HTML_HEAD 00002 24 | #define HTML_BODY 00003 25 | #define HTML_PRE 00004 26 | #define HTML_TAG 00010 27 | #define HTML_CLOSE 00020 28 | #define HTML_COMMENT 00040 29 | #define HTML_BREAK 00100 30 | #define HTML_NEWLINE 00200 31 | #define HTML_ANCHOR 00400 32 | #define htmllvl(h) (((hp) -> flags) & HTML_LVL) 33 | 34 | extern VOID htmllog __P_((CONST char *, ...)); 35 | extern int getcharset __P_((char *CONST *)); 36 | extern VOID htmlinit __P_((htmlstat_t *, XFILE *, CONST char *)); 37 | extern VOID htmlfree __P_((htmlstat_t *)); 38 | extern char *htmlfgets __P_((htmlstat_t *)); 39 | -------------------------------------------------------------------------------- /kanjicnv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * kanjicnv.c 3 | * 4 | * tiny Kanji code converter 5 | */ 6 | 7 | #include "headers.h" 8 | #include "evalopt.h" 9 | 10 | #ifdef WITHUTF8 11 | #define K_EXTERN 12 | #include "kctype.h" 13 | #endif 14 | 15 | #define ASCII 000 16 | #define KANA 001 17 | #define KANJI 002 18 | #define JKANA 004 19 | 20 | #define K_SJIS 010 21 | #define K_EUC 020 22 | #define K_UTF8 040 23 | 24 | #define U2_UDEF 0x3013 /* GETA */ 25 | #define MINUNICODE 0x00a7 26 | #define MAXUNICODE 0xffe5 27 | #define MINKANJI 0x8140 28 | #define MAXKANJI 0xfc4b 29 | #define getword(s, n) (((u_short)((s)[(n) + 1]) << 8) | (s)[n]) 30 | 31 | #ifdef WITHUTF8 32 | extern CONST u_char unitblbuf[]; 33 | extern u_int unitblent; 34 | extern int nftblnum; 35 | extern int nflen; 36 | extern CONST u_char *nftblbuf[]; 37 | extern u_int nftblent[]; 38 | #endif 39 | 40 | static VOID NEAR Xfputc __P_((int, FILE *)); 41 | #ifdef WITHUTF8 42 | static u_int NEAR cnvunicode __P_((u_int)); 43 | static VOID NEAR fputucs2 __P_((u_int, FILE *)); 44 | static VOID NEAR ucs2normalization __P_((u_int, int, FILE *)); 45 | static VOID NEAR convertutf8 __P_((u_int, FILE *)); 46 | #endif 47 | static VOID NEAR convert __P_((int, int, FILE *)); 48 | static VOID NEAR output __P_((FILE *, int, int)); 49 | int main __P_((int, char *CONST [])); 50 | 51 | static int msboff = 0; 52 | static int prefix = 0; 53 | static int removebs = 0; 54 | static int kanjicode = K_SJIS; 55 | static CONST opt_t optlist[] = { 56 | {'7', &msboff, 1, NULL}, 57 | {'b', &removebs, 1, NULL}, 58 | {'c', &prefix, 1, NULL}, 59 | {'e', &kanjicode, K_EUC, NULL}, 60 | {'s', &kanjicode, K_SJIS, NULL}, 61 | #ifdef WITHUTF8 62 | {'u', &kanjicode, K_UTF8, NULL}, 63 | #endif 64 | {'\0', NULL, 0, NULL}, 65 | }; 66 | 67 | 68 | static VOID NEAR Xfputc(c, fp) 69 | int c; 70 | FILE *fp; 71 | { 72 | if (msboff && (c & 0x80)) fprintf(fp, "\\%03o", c); 73 | else fputc(c, fp); 74 | } 75 | 76 | #ifdef WITHUTF8 77 | static u_int NEAR cnvunicode(wc) 78 | u_int wc; 79 | { 80 | CONST u_char *cp; 81 | u_int w, ofs, min, max; 82 | 83 | if (wc < 0x0080) return(wc); 84 | if (wc >= 0x00a1 && wc <= 0x00df) 85 | return(0xff00 | (wc - 0x00a1 + 0x61)); 86 | if (wc >= 0x8260 && wc <= 0x8279) 87 | return(0xff00 | (wc - 0x8260 + 0x21)); 88 | if (wc >= 0x8281 && wc <= 0x829a) 89 | return(0xff00 | (wc - 0x8281 + 0x41)); 90 | if (wc < MINKANJI || wc > MAXKANJI) return(U2_UDEF); 91 | 92 | # if 0 93 | wc = unifysjis(wc, 0); 94 | # endif 95 | 96 | ofs = min = max = 0; 97 | cp = unitblbuf; 98 | for (ofs = 0; ofs < unitblent; ofs++) { 99 | w = getword(cp, 2); 100 | if (wc == w) return(getword(cp, 0)); 101 | cp += 4; 102 | } 103 | 104 | return(U2_UDEF); 105 | } 106 | 107 | static VOID NEAR fputucs2(wc, fp) 108 | u_int wc; 109 | FILE *fp; 110 | { 111 | if (wc < 0x80) Xfputc(wc, fp); 112 | else if (wc < 0x800) { 113 | Xfputc(0xc0 | (wc >> 6), fp); 114 | Xfputc(0x80 | (wc & 0x3f), fp); 115 | } 116 | else { 117 | Xfputc(0xe0 | (wc >> 12), fp); 118 | Xfputc(0x80 | ((wc >> 6) & 0x3f), fp); 119 | Xfputc(0x80 | (wc & 0x3f), fp); 120 | } 121 | } 122 | 123 | static VOID NEAR ucs2normalization(wc, nf, fp) 124 | u_int wc; 125 | int nf; 126 | FILE *fp; 127 | { 128 | CONST u_char *cp; 129 | u_int w, ofs, ent; 130 | int n; 131 | 132 | if (nf <= 0 || nf > nftblnum || wc < MINUNICODE || wc > MAXUNICODE) { 133 | cp = NULL; 134 | ofs = ent = (u_int)0; 135 | } 136 | else { 137 | n = 2 + nflen * 2; 138 | cp = nftblbuf[nf - 1]; 139 | ent = nftblent[nf - 1]; 140 | for (ofs = 0; ofs < ent; ofs++) { 141 | w = getword(cp, 0); 142 | if (wc == w) break; 143 | cp += n; 144 | } 145 | } 146 | 147 | if (ofs >= ent) fputucs2(wc, fp); 148 | else for (n = 0; n < nflen; n++) { 149 | cp += 2; 150 | w = getword(cp, 0); 151 | if (!w) break; 152 | fputucs2(w, fp);; 153 | } 154 | } 155 | 156 | static VOID NEAR convertutf8(wc, fp) 157 | u_int wc; 158 | FILE *fp; 159 | { 160 | ucs2normalization(cnvunicode(wc), WITHUTF8, fp); 161 | } 162 | #endif /* WITHUTF8 */ 163 | 164 | static VOID NEAR convert(j1, j2, fp) 165 | int j1, j2; 166 | FILE *fp; 167 | { 168 | int c1, c2; 169 | 170 | c1 = c2 = '\0'; 171 | if (kanjicode == K_EUC) { 172 | if (j1) { 173 | c1 = (j1 | 0x80); 174 | c2 = (j2 | 0x80); 175 | } 176 | else if (j2 <= 0x20 || j2 >= 0x60) c2 = j2; 177 | else { 178 | c1 = 0x8e; 179 | c2 = (j2 | 0x80); 180 | } 181 | } 182 | else { 183 | if (j1) { 184 | c1 = ((j1 - 1) >> 1) + ((j1 < 0x5f) ? 0x71 : 0xb1); 185 | c2 = j2 + ((j1 & 1) 186 | ? ((j2 < 0x60) ? 0x1f : 0x20) : 0x7e); 187 | } 188 | else if (j2 <= 0x20 || j2 >= 0x60) c2 = j2; 189 | else c2 = (j2 | 0x80); 190 | #ifdef WITHUTF8 191 | if (kanjicode == K_UTF8) { 192 | convertutf8(((u_int)c1 << 8) | c2, fp); 193 | c1 = c2 = '\0'; 194 | } 195 | #endif 196 | } 197 | 198 | if (c1) Xfputc(c1, fp); 199 | if (c2) Xfputc(c2, fp); 200 | if (c2 == '\\' && (prefix || msboff)) Xfputc('\\', fp); 201 | } 202 | 203 | static VOID NEAR output(fp, c, mode) 204 | FILE *fp; 205 | int c, mode; 206 | { 207 | static u_char buf[2]; 208 | static int kanji1 = 0; 209 | static int bufp = 0; 210 | 211 | if (!fp) { 212 | bufp = kanji1 = 0; 213 | return; 214 | } 215 | 216 | if (!bufp) /*EMPTY*/; 217 | else if (bufp > 1) { 218 | convert(buf[0], buf[1], fp); 219 | bufp = 0; 220 | } 221 | else if (kanji1 & (KANA | JKANA)) { 222 | convert(0, buf[0], fp); 223 | bufp = 0; 224 | } 225 | else if (!(kanji1 & KANJI)) { 226 | Xfputc(buf[0], fp); 227 | bufp = 0; 228 | } 229 | kanji1 = mode; 230 | 231 | if (c != EOF) buf[bufp++] = c; 232 | } 233 | 234 | int main(argc, argv) 235 | int argc; 236 | char *CONST argv[]; 237 | { 238 | FILE *fpin, *fpout; 239 | int n, c, mode, esc, kanji; 240 | 241 | initopt(optlist); 242 | n = evalopt(argc, argv, optlist); 243 | if (n >= argc || n + 2 < argc) { 244 | optusage(argv[0], " []", optlist); 245 | return(1); 246 | } 247 | 248 | if (!strcmp(argv[n], "-")) fpin = stdin; 249 | else if (!(fpin = fopen(argv[n], "r"))) { 250 | fprintf(stderr, "%s: cannot open.\n", argv[n]); 251 | return(1); 252 | } 253 | if (n + 1 >= argc) fpout = stdout; 254 | else if (!(fpout = fopen(argv[n + 1], "w"))) { 255 | fprintf(stderr, "%s: cannot open.\n", argv[n + 1]); 256 | VOID_C fclose(fpin); 257 | return(1); 258 | } 259 | 260 | mode = ASCII; 261 | esc = kanji = 0; 262 | 263 | while ((c = fgetc(fpin)) != EOF) { 264 | switch (c) { 265 | case '\033': /* ESC */ 266 | if (esc) output(fpout, '\033', mode); 267 | else if (kanji > 0) { 268 | output(fpout, '\033', mode); 269 | output(fpout, '$', mode); 270 | } 271 | else if (kanji < 0) { 272 | output(fpout, '\033', mode); 273 | output(fpout, '(', mode); 274 | } 275 | esc = 1; 276 | kanji = 0; 277 | break; 278 | case '$': 279 | if (!esc) { 280 | if (!kanji) output(fpout, c, mode); 281 | } 282 | else { 283 | mode &= ~JKANA; 284 | esc = 0; 285 | kanji = 1; 286 | } 287 | break; 288 | case '(': 289 | if (!esc) { 290 | if (!kanji) output(fpout, c, mode); 291 | } 292 | else { 293 | mode &= ~JKANA; 294 | esc = 0; 295 | kanji = -1; 296 | } 297 | break; 298 | case '\016': /* SO */ 299 | if (esc) output(fpout, '\033', mode); 300 | else if (kanji > 0) { 301 | output(fpout, '\033', mode); 302 | output(fpout, '$', mode); 303 | } 304 | else if (kanji < 0) { 305 | output(fpout, '\033', mode); 306 | output(fpout, '(', mode); 307 | } 308 | mode |= KANA; 309 | esc = kanji = 0; 310 | break; 311 | case '\017': /* SI */ 312 | if (esc) output(fpout, '\033', mode); 313 | else if (kanji > 0) { 314 | output(fpout, '\033', mode); 315 | output(fpout, '$', mode); 316 | } 317 | else if (kanji < 0) { 318 | output(fpout, '\033', mode); 319 | output(fpout, '(', mode); 320 | } 321 | mode &= ~KANA; 322 | esc = kanji = 0; 323 | break; 324 | case '\b': 325 | if (removebs) { 326 | if (esc) output(fpout, '\033', mode); 327 | else if (kanji > 0) { 328 | output(fpout, '\033', mode); 329 | output(fpout, '$', mode); 330 | } 331 | else if (kanji < 0) { 332 | output(fpout, '\033', mode); 333 | output(fpout, '(', mode); 334 | } 335 | output(NULL, EOF, mode); 336 | esc = kanji = 0; 337 | break; 338 | } 339 | /*FALLTHRU*/ 340 | default: 341 | if (esc) output(fpout, '\033', mode); 342 | else if (kanji > 0) mode |= KANJI; 343 | else if (kanji < 0) { 344 | if (c == 'I') mode |= JKANA; 345 | else mode &= ~KANJI; 346 | } 347 | else output(fpout, c, mode); 348 | esc = kanji = 0; 349 | break; 350 | } 351 | } 352 | output(fpout, EOF, mode); 353 | 354 | VOID_C fclose(fpout); 355 | VOID_C fclose(fpin); 356 | 357 | return(0); 358 | } 359 | -------------------------------------------------------------------------------- /kconv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * kconv.h 3 | * 4 | * definitions & function prototype declarations for "kconv.c" 5 | */ 6 | 7 | #include "depend.h" 8 | 9 | extern int onkanji1 __P_((CONST char *, int)); 10 | #if !defined (_NOKANJICONV) \ 11 | || (!defined (_NOENGMES) && !defined (_NOJPNMES)) 12 | extern int getlang __P_((CONST char *, int)); 13 | #endif 14 | #if !defined (_NOKANJICONV) || (defined (DEP_DOSEMU) && defined (CODEEUC)) 15 | extern int sjis2ujis __P_((char *, CONST u_char *, int)); 16 | extern int ujis2sjis __P_((char *, CONST u_char *, int)); 17 | #endif 18 | #ifdef DEP_UNICODE 19 | # ifndef DEP_EMBEDUNITBL 20 | extern VOID readunitable __P_((int)); 21 | extern VOID discardunitable __P_((VOID_A)); 22 | # endif 23 | extern u_int unifysjis __P_((u_int, int)); 24 | extern u_int cnvunicode __P_((u_int, int)); 25 | #endif /* DEP_UNICODE */ 26 | #ifndef _NOKANJICONV 27 | # ifdef DEP_UNICODE 28 | extern VOID ucs2normalization __P_((u_short *, int *, int, u_int, int)); 29 | extern u_int ucs2denormalization __P_((CONST u_short *, int *, int)); 30 | extern int ucs2toutf8 __P_((char *, int, u_int)); 31 | extern u_int ucs2fromutf8 __P_((CONST u_char *, int *)); 32 | # endif 33 | extern int kanjiconv __P_((char *, CONST char *, int, int, int, int)); 34 | extern CONST char *kanjiconv2 __P_((char *, CONST char *, int, int, int, int)); 35 | extern char *newkanjiconv __P_((CONST char *, int, int, int)); 36 | extern VOID renewkanjiconv __P_((char **, int, int, int)); 37 | #endif /* !_NOKANJICONV */ 38 | #if defined (FD) && !defined (_NOKANJIFCONV) 39 | extern int getkcode __P_((CONST char *)); 40 | #endif 41 | #ifndef _NOKANJICONV 42 | extern int getoutputkcode __P_((VOID_A)); 43 | #endif 44 | #ifdef FD 45 | extern char *convget __P_((char *, char *, int)); 46 | extern char *convput __P_((char *, CONST char *, int, int, char *, int *)); 47 | #endif 48 | 49 | #ifdef FD 50 | extern int noconv; 51 | #endif 52 | #ifndef _NOKANJIFCONV 53 | extern int nokanjifconv; 54 | extern char *sjispath; 55 | extern char *eucpath; 56 | extern char *jis7path; 57 | extern char *jis8path; 58 | extern char *junetpath; 59 | extern char *ojis7path; 60 | extern char *ojis8path; 61 | extern char *ojunetpath; 62 | extern char *hexpath; 63 | extern char *cappath; 64 | extern char *utf8path; 65 | extern char *utf8macpath; 66 | extern char *utf8iconvpath; 67 | extern char *noconvpath; 68 | #endif /* !_NOKANJIFCONV */ 69 | #ifdef DEP_UNICODE 70 | extern char *unitblpath; 71 | extern int unicodebuffer; 72 | #endif 73 | -------------------------------------------------------------------------------- /log.c: -------------------------------------------------------------------------------- 1 | /* 2 | * log.c 3 | * 4 | * system logging 5 | */ 6 | 7 | #include "fd.h" 8 | #include "func.h" 9 | 10 | #if MSDOS 11 | #include 12 | #endif 13 | #ifndef NOSYSLOG 14 | #include 15 | #endif 16 | 17 | #ifndef LOG_PID 18 | #define LOG_PID 0 19 | #endif 20 | #ifndef LOG_ERR 21 | #define LOG_ERR 3 22 | #endif 23 | #ifndef LOG_INFO 24 | #define LOG_INFO 6 25 | #endif 26 | 27 | #ifdef DEP_LOGGING 28 | 29 | extern char *progname; 30 | 31 | static lockbuf_t *NEAR openlogfile __P_((VOID_A)); 32 | static VOID NEAR writelog __P_((int, int, CONST char *)); 33 | 34 | char *logfile = NULL; 35 | int logsize = 0; 36 | #ifndef NOSYSLOG 37 | int usesyslog = 0; 38 | #endif 39 | int loglevel = 0; 40 | #ifndef NOUID 41 | int rootloglevel = 0; 42 | #endif 43 | 44 | static char *logfname = NULL; 45 | #ifndef NOSYSLOG 46 | static int syslogged = 0; 47 | #endif 48 | 49 | 50 | static lockbuf_t *NEAR openlogfile(VOID_A) 51 | { 52 | lockbuf_t *lck; 53 | struct stat st; 54 | CONST char *home; 55 | char *cp, *top, path[MAXPATHLEN]; 56 | ALLOC_T size; 57 | 58 | cp = logfname; 59 | if (logfname) { 60 | if (!*logfname) return(NULL); 61 | } 62 | else { 63 | if (!logfile || !*logfile) return(NULL); 64 | 65 | logfname = vnullstr; 66 | top = logfile; 67 | #ifdef DEP_DOSPATH 68 | if (_dospath(top)) top += 2; 69 | #endif 70 | if (*top == _SC_) cp = logfile; 71 | else { 72 | if (!(home = gethomedir())) return(NULL); 73 | strcatdelim2(path, home, top); 74 | if (!*path) return(NULL); 75 | cp = Xstrdup(path); 76 | } 77 | } 78 | 79 | size = (ALLOC_T)logsize * (ALLOC_T)1024; 80 | if (size > 0 && Xstat(cp, &st) >= 0 && st.st_size > size) { 81 | VOID_C Xsnprintf(path, sizeof(path), "%s.old", cp); 82 | if (Xrename(cp, path) < 0) VOID_C Xunlink(cp); 83 | } 84 | 85 | lck = lockopen(cp, O_TEXT | O_WRONLY | O_CREAT | O_APPEND, 0666); 86 | if (!lck) { 87 | Xfree(cp); 88 | return(NULL); 89 | } 90 | 91 | logfname = cp; 92 | return(lck); 93 | } 94 | 95 | VOID logclose(VOID_A) 96 | { 97 | if (logfname != vnullstr) Xfree(logfname); 98 | logfname = vnullstr; 99 | #ifndef NOSYSLOG 100 | if (syslogged > 0) closelog(); 101 | syslogged = -1; 102 | #endif 103 | } 104 | 105 | /*ARGSUSED*/ 106 | static VOID NEAR writelog(lvl, p, buf) 107 | int lvl, p; 108 | CONST char *buf; 109 | { 110 | static int logging = 0; 111 | lockbuf_t *lck; 112 | struct tm *tm; 113 | char hbuf[MAXLOGLEN + 1]; 114 | time_t t; 115 | u_char uc; 116 | int n; 117 | 118 | if (logging) return; 119 | #ifndef NOUID 120 | if (!getuid()) { 121 | n = rootloglevel; 122 | lvl--; 123 | } 124 | else 125 | #endif 126 | n = loglevel; 127 | if (!n || n < lvl) return; 128 | 129 | logging = 1; 130 | if ((lck = openlogfile())) { 131 | t = time(NULL); 132 | tm = localtime(&t); 133 | #ifdef NOUID 134 | VOID_C Xsnprintf(hbuf, sizeof(hbuf), 135 | "%04u/%02u/%02u %02u:%02u:%02u %s[%d]:\n ", 136 | tm -> tm_year + 1900, tm -> tm_mon + 1, tm -> tm_mday, 137 | tm -> tm_hour, tm -> tm_min, tm -> tm_sec, 138 | progname, getpid()); 139 | #else 140 | VOID_C Xsnprintf(hbuf, sizeof(hbuf), 141 | "%04u/%02u/%02u %02u:%02u:%02u uid=%d %s[%d]:\n ", 142 | tm -> tm_year + 1900, tm -> tm_mon + 1, tm -> tm_mday, 143 | tm -> tm_hour, tm -> tm_min, tm -> tm_sec, 144 | getuid(), progname, getpid()); 145 | #endif 146 | VOID_C Xwrite(lck -> fd, hbuf, strlen(hbuf)); 147 | VOID_C Xwrite(lck -> fd, buf, strlen(buf)); 148 | uc = '\n'; 149 | VOID_C Xwrite(lck -> fd, (char *)&uc, sizeof(uc)); 150 | lockclose(lck); 151 | } 152 | logging = 0; 153 | #ifndef NOSYSLOG 154 | if (usesyslog && syslogged >= 0) { 155 | if (!syslogged) { 156 | syslogged++; 157 | # ifdef LOG_USER 158 | openlog(progname, LOG_PID, LOG_USER); 159 | # else 160 | openlog(progname, LOG_PID); 161 | # endif 162 | } 163 | syslog(p, "%s", buf); 164 | } 165 | #endif /* !NOSYSLOG */ 166 | } 167 | 168 | #ifdef USESTDARGH 169 | /*VARARGS3*/ 170 | VOID logsyscall(int lvl, int val, CONST char *fmt, ...) 171 | #else 172 | /*VARARGS3*/ 173 | VOID logsyscall(lvl, val, fmt, va_alist) 174 | int lvl, val; 175 | CONST char *fmt; 176 | va_dcl 177 | #endif 178 | { 179 | va_list args; 180 | char buf[MAXLOGLEN + 1]; 181 | int n, len, duperrno; 182 | 183 | duperrno = errno; 184 | if (val >= 0) lvl++; 185 | VA_START(args, fmt); 186 | len = Xvsnprintf(buf, sizeof(buf), fmt, args); 187 | va_end(args); 188 | 189 | if (len >= 0) { 190 | #ifdef CODEEUC 191 | len = strlen(buf); 192 | #endif 193 | if (val >= 0) n = Xsnprintf(&(buf[len]), 194 | (int)sizeof(buf) - len, " succeeded"); 195 | else n = Xsnprintf(&(buf[len]), (int)sizeof(buf) - len, 196 | " -- FAILED -- (%k)", Xstrerror(duperrno)); 197 | if (n < 0) buf[len] = '\0'; 198 | writelog(lvl, (val < 0) ? LOG_ERR : LOG_INFO, buf); 199 | } 200 | errno = duperrno; 201 | } 202 | 203 | #ifdef USESTDARGH 204 | /*VARARGS2*/ 205 | VOID logmessage(int lvl, CONST char *fmt, ...) 206 | #else 207 | /*VARARGS2*/ 208 | VOID logmessage(lvl, fmt, va_alist) 209 | int lvl; 210 | CONST char *fmt; 211 | va_dcl 212 | #endif 213 | { 214 | va_list args; 215 | char buf[MAXLOGLEN + 1]; 216 | int len, duperrno; 217 | 218 | duperrno = errno; 219 | VA_START(args, fmt); 220 | len = Xvsnprintf(buf, sizeof(buf), fmt, args); 221 | va_end(args); 222 | 223 | if (len >= 0) writelog(lvl, LOG_INFO, buf); 224 | errno = duperrno; 225 | } 226 | #endif /* DEP_LOGGING */ 227 | -------------------------------------------------------------------------------- /log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * log.h 3 | * 4 | * definitions & function prototype declarations for "log.c" 5 | */ 6 | 7 | #include "depend.h" 8 | 9 | #define _LOG_WARNING_ 0 10 | #define _LOG_NOTICE_ 1 11 | #define _LOG_INFO_ 2 12 | #define _LOG_DEBUG_ 3 13 | 14 | #ifdef DEP_LOGGING 15 | #define LOG0(l, n, f) logsyscall(l, n, f) 16 | #define LOG1(l, n, f, a1) logsyscall(l, n, f, a1) 17 | #define LOG2(l, n, f, a1, a2) logsyscall(l, n, f, a1, a2) 18 | #define LOG3(l, n, f, a1, a2, a3) \ 19 | logsyscall(l, n, f, a1, a2, a3) 20 | extern VOID logclose __P_((VOID_A)); 21 | extern VOID logsyscall __P_((int, int, CONST char *, ...)); 22 | extern VOID logmessage __P_((int, CONST char *, ...)); 23 | #else /* !DEP_LOGGING */ 24 | #define LOG0(l, n, f) 25 | #define LOG1(l, n, f, a1) 26 | #define LOG2(l, n, f, a1, a2) 27 | #define LOG3(l, n, f, a1, a2, a3) 28 | #endif /* !DEP_LOGGING */ 29 | -------------------------------------------------------------------------------- /lsparse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lsparse.h 3 | * 4 | * definitions & function prototype declarations for "lsparse.c" 5 | */ 6 | 7 | #ifndef __LSPARSE_H_ 8 | #define __LSPARSE_H_ 9 | 10 | #include "typesize.h" 11 | #include "namelist.h" 12 | 13 | #if defined (FD) && (FD < 2) && !defined (OLDPARSE) 14 | #define OLDPARSE 15 | #endif 16 | 17 | #define MAXLSPARSEFIELD 9 18 | #define MAXLSPARSESEP 3 19 | typedef struct _lsparse_t { 20 | char *ext; 21 | char *comm; 22 | #ifndef OLDPARSE 23 | char **format; 24 | char **lignore; 25 | char **lerror; 26 | #endif 27 | u_char topskip; 28 | u_char bottomskip; 29 | #ifdef OLDPARSE 30 | u_char field[MAXLSPARSEFIELD]; 31 | u_char delim[MAXLSPARSEFIELD]; 32 | u_char width[MAXLSPARSEFIELD]; 33 | u_char sep[MAXLSPARSESEP]; 34 | u_char lines; 35 | #endif 36 | u_char flags; 37 | } lsparse_t; 38 | 39 | #define F_MODE 0 40 | #define F_UID 1 41 | #define F_GID 2 42 | #define F_SIZE 3 43 | #define F_YEAR 4 44 | #define F_MON 5 45 | #define F_DAY 6 46 | #define F_TIME 7 47 | #define F_NAME 8 48 | #define LF_IGNORECASE 0001 49 | #define LF_DIRLOOP 0002 50 | #define LF_DIRNOPREP 0004 51 | #define LF_FILELOOP 0010 52 | #define LF_FILENOPREP 0020 53 | #define LF_NOTRAVERSE 0040 54 | #define LF_BASENAME 0100 55 | #define SKP_NONE MAXUTYPE(u_char) 56 | #define FLD_NONE MAXUTYPE(u_char) 57 | #define SEP_NONE MAXUTYPE(u_char) 58 | 59 | extern u_int getfmode __P_((int)); 60 | extern int getfsymbol __P_((u_int)); 61 | #ifdef NOUID 62 | extern int logical_access __P_((u_int)); 63 | #define logical_access2(s) logical_access((u_int)((s) -> st_mode)) 64 | #else 65 | extern int logical_access __P_((u_int, u_id_t, g_id_t)); 66 | #define logical_access2(s) logical_access((u_int)((s) -> st_mode), \ 67 | (s) -> st_uid, (s) -> st_gid) 68 | #endif 69 | #ifdef DEP_LSPARSE 70 | extern VOID initlist __P_((namelist *, CONST char *)); 71 | extern VOID todirlist __P_((namelist *, u_int)); 72 | extern int dirmatchlen __P_((CONST char *, CONST char *)); 73 | extern int parsefilelist __P_((VOID_P, CONST lsparse_t *, 74 | namelist *, int *, char *(*)__P_((VOID_P)))); 75 | extern namelist *addlist __P_((namelist *, int, int *)); 76 | extern VOID freelist __P_((namelist *, int)); 77 | extern int lsparse __P_((VOID_P, CONST lsparse_t *, 78 | namelist **, char *(*)__P_((VOID_P)))); 79 | extern int Xstrptime __P_((CONST char *, CONST char *, struct tm *, int *)); 80 | #endif 81 | 82 | extern int (*lsintrfunc)__P_((VOID_A)); 83 | 84 | #endif /* !__LSPARSE_H_ */ 85 | -------------------------------------------------------------------------------- /malloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * malloc.c 3 | * 4 | * alternative memoly allocation functions 5 | */ 6 | 7 | #include "headers.h" 8 | #include "printf.h" 9 | #include "malloc.h" 10 | #include "sysemu.h" 11 | 12 | #ifdef FD 13 | extern VOID error __P_((CONST char *)); 14 | #else 15 | static VOID NEAR error __P_((CONST char *)); 16 | #endif 17 | 18 | 19 | #ifndef FD 20 | static VOID NEAR error(s) 21 | CONST char *s; 22 | { 23 | VOID_C Xfprintf(Xstderr, "%s: memory allocation error", s); 24 | VOID_C fputnl(Xstderr); 25 | 26 | exit(2); 27 | } 28 | #endif /* !FD */ 29 | 30 | char *Xmalloc(size) 31 | ALLOC_T size; 32 | { 33 | char *tmp; 34 | 35 | if (!size || !(tmp = (char *)malloc(size))) { 36 | error("malloc()"); 37 | #ifdef FAKEUNINIT 38 | tmp = NULL; /* fake for -Wuninitialized */ 39 | #endif 40 | } 41 | 42 | return(tmp); 43 | } 44 | 45 | char *Xrealloc(ptr, size) 46 | VOID_P ptr; 47 | ALLOC_T size; 48 | { 49 | char *tmp; 50 | 51 | if (!size 52 | || !(tmp = (ptr) ? (char *)realloc(ptr, size) : (char *)malloc(size))) 53 | { 54 | error("realloc()"); 55 | #ifdef FAKEUNINIT 56 | tmp = NULL; /* fake for -Wuninitialized */ 57 | #endif 58 | } 59 | 60 | return(tmp); 61 | } 62 | 63 | VOID Xfree(ptr) 64 | VOID_P ptr; 65 | { 66 | int duperrno; 67 | 68 | if (!ptr) return; 69 | duperrno = errno; 70 | free(ptr); 71 | errno = duperrno; 72 | } 73 | 74 | char *c_realloc(ptr, n, sizep) 75 | char *ptr; 76 | ALLOC_T n, *sizep; 77 | { 78 | if (!ptr) { 79 | *sizep = BUFUNIT; 80 | return(Xmalloc(*sizep)); 81 | } 82 | while (n + 1 >= *sizep) *sizep *= 2; 83 | 84 | return(Xrealloc(ptr, *sizep)); 85 | } 86 | 87 | char *Xstrdup(s) 88 | CONST char *s; 89 | { 90 | char *tmp; 91 | int n; 92 | 93 | if (!s) return(NULL); 94 | n = strlen(s); 95 | if (!(tmp = (char *)malloc((ALLOC_T)n + 1))) error("malloc()"); 96 | memcpy(tmp, s, n + 1); 97 | 98 | return(tmp); 99 | } 100 | 101 | char *Xstrndup(s, n) 102 | CONST char *s; 103 | int n; 104 | { 105 | char *tmp; 106 | int i; 107 | 108 | if (!s) return(NULL); 109 | for (i = 0; i < n; i++) if (!s[i]) break; 110 | if (!(tmp = (char *)malloc((ALLOC_T)i + 1))) error("malloc()"); 111 | memcpy(tmp, s, i); 112 | tmp[i] = '\0'; 113 | 114 | return(tmp); 115 | } 116 | 117 | #ifndef MINIMUMSHELL 118 | int vasprintf2(sp, fmt, args) 119 | char **sp; 120 | CONST char *fmt; 121 | va_list args; 122 | { 123 | int n; 124 | 125 | n = Xvasprintf(sp, fmt, args); 126 | if (n < 0) error("malloc()"); 127 | 128 | return(n); 129 | } 130 | 131 | # ifdef USESTDARGH 132 | /*VARARGS1*/ 133 | char *asprintf2(CONST char *fmt, ...) 134 | # else 135 | /*VARARGS1*/ 136 | char *asprintf2(fmt, va_alist) 137 | CONST char *fmt; 138 | va_dcl 139 | # endif 140 | { 141 | va_list args; 142 | char *cp; 143 | 144 | VA_START(args, fmt); 145 | VOID_C vasprintf2(&cp, fmt, args); 146 | va_end(args); 147 | 148 | return(cp); 149 | } 150 | #endif /* !MINIMUMSHELL */ 151 | -------------------------------------------------------------------------------- /malloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * malloc.h 3 | * 4 | * definitions & function prototype declarations for "malloc.c" 5 | */ 6 | 7 | #define BUFUNIT 32 8 | #define b_size(n, type) ((((n) / BUFUNIT) + 1) \ 9 | * BUFUNIT * sizeof(type)) 10 | #define b_realloc(ptr, n, type) (((n) % BUFUNIT) ? ((type *)(ptr)) \ 11 | : (type *)Xrealloc(ptr, b_size(n, type))) 12 | 13 | extern char *Xmalloc __P_((ALLOC_T)); 14 | extern char *Xrealloc __P_((VOID_P, ALLOC_T)); 15 | extern VOID Xfree __P_((VOID_P)); 16 | extern char *Xstrdup __P_((CONST char *)); 17 | extern char *Xstrndup __P_((CONST char *, int)); 18 | extern char *c_realloc __P_((char *, ALLOC_T, ALLOC_T *)); 19 | #ifndef MINIMUMSHELL 20 | extern int vasprintf2 __P_((char **, CONST char *, va_list)); 21 | extern char *asprintf2 __P_((CONST char *, ...)); 22 | #endif 23 | -------------------------------------------------------------------------------- /mkdir_p.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mkdir_p.c 3 | * 4 | * make directory with parent directories 5 | */ 6 | 7 | #define K_EXTERN 8 | #include "headers.h" 9 | #include "kctype.h" 10 | #include "typesize.h" 11 | 12 | #if MSDOS && !defined (DJGPP) 13 | #undef MAXPATHLEN 14 | #define MAXPATHLEN 260 15 | #define unixmkdir(p, m) ((mkdir(p)) ? -1 : 0) 16 | #else 17 | #define unixmkdir(p, m) ((mkdir(p, m)) ? -1 : 0) 18 | #endif 19 | 20 | static int a2octal __P_((CONST char *)); 21 | static char *strrdelim __P_((CONST char *)); 22 | static int mkdir_p __P_((CONST char *, int)); 23 | int main __P_((int, char *CONST [])); 24 | 25 | 26 | static int a2octal(s) 27 | CONST char *s; 28 | { 29 | CONST char *cp; 30 | int n; 31 | 32 | if (!s) return(-1); 33 | 34 | n = 0; 35 | for (cp = s; *cp; cp++) { 36 | if (*cp < '0' || *cp > '7') break; 37 | n *= 8; 38 | n += *cp - '0'; 39 | } 40 | if (cp <= s) return(-1); 41 | 42 | return(n); 43 | } 44 | 45 | static char *strrdelim(s) 46 | CONST char *s; 47 | { 48 | CONST char *cp; 49 | 50 | cp = NULL; 51 | for (; *s; s++) { 52 | if (*s == _SC_) cp = s; 53 | #ifdef BSPATHDELIM 54 | if (iskanji1(s, 0)) s++; 55 | #endif 56 | } 57 | 58 | return((char *)cp); 59 | } 60 | 61 | static int mkdir_p(path, mode) 62 | CONST char *path; 63 | int mode; 64 | { 65 | char *cp, buf[MAXPATHLEN]; 66 | ALLOC_T len; 67 | 68 | if (unixmkdir(path, mode) >= 0) return(0); 69 | if (errno != ENOENT) return(-1); 70 | 71 | cp = strrdelim(path); 72 | if (!cp || cp < path) { 73 | errno = ENOENT; 74 | return(-1); 75 | } 76 | if ((len = cp - path) >= strsize(buf)) { 77 | errno = ENAMETOOLONG; 78 | return(-1); 79 | } 80 | 81 | memcpy(buf, path, len); 82 | buf[len] = '\0'; 83 | if (mkdir_p(buf, mode) < 0) return(-1); 84 | 85 | return(unixmkdir(path, mode)); 86 | } 87 | 88 | int main(argc, argv) 89 | int argc; 90 | char *CONST argv[]; 91 | { 92 | CONST char *cp; 93 | int n, mode; 94 | 95 | mode = 0777; 96 | for (n = 1; n < argc; n++) { 97 | if (argv[n][0] != '-' || !argv[n][1]) break; 98 | if (argv[n][1] == '-' && !argv[n][2]) { 99 | n++; 100 | break; 101 | } 102 | if (argv[n][1] == 'm') { 103 | cp = &(argv[n][2]); 104 | if (!*cp) cp = argv[++n]; 105 | if ((mode = a2octal(cp)) < 0) { 106 | n = argc; 107 | break; 108 | } 109 | } 110 | } 111 | 112 | if (n >= argc || n + 1 < argc) { 113 | fprintf(stderr, "Usage: mkdir_p [-m ] \n"); 114 | return(1); 115 | } 116 | if (mkdir_p(argv[n], mode) < 0) { 117 | fprintf(stderr, "%s: cannot make directory.\n", argv[n]); 118 | return(1); 119 | } 120 | 121 | return(0); 122 | } 123 | -------------------------------------------------------------------------------- /mkfuncno.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mkfuncno.c 3 | * 4 | * preprocesser for "funcno.h" 5 | */ 6 | 7 | #define __FD_PRIMAL__ 8 | #include "fd.h" 9 | #include "types.h" 10 | #ifdef _NOCATALOG 11 | #define _TBL_(fn, id, hl, fl) {NULL, id, NULL, 0} 12 | #else 13 | #define _TBL_(fn, id, hl, fl) {NULL, id, 0, 0} 14 | #endif 15 | #include "functabl.h" 16 | 17 | int main __P_((int, char *CONST [])); 18 | 19 | 20 | /*ARGSUSED*/ 21 | int main(argc, argv) 22 | int argc; 23 | char *CONST argv[]; 24 | { 25 | FILE *fp; 26 | int i, len; 27 | 28 | if (!strcmp(argv[1], "-")) fp = stdout; 29 | else if (!(fp = fopen(argv[1], "w"))) { 30 | fprintf(stderr, "%s: Cannot open.\n", argv[1]); 31 | return(1); 32 | } 33 | 34 | fprintf(fp, "/*\n"); 35 | fprintf(fp, " *\t%s\n", (fp != stdout) ? argv[1] : "STDOUT"); 36 | fprintf(fp, " *\n"); 37 | fprintf(fp, " *\tfunction No. table\n"); 38 | fprintf(fp, " */\n"); 39 | fprintf(fp, "\n"); 40 | 41 | for (i = 0; i < (int)sizeof(funclist) / sizeof(functable); i++) { 42 | fprintf(fp, "#define\t%s\t", funclist[i].ident); 43 | len = strlen(funclist[i].ident); 44 | while ((len += 8) < 16) fputc('\t', fp); 45 | fprintf(fp, "\t%d\n", i); 46 | } 47 | fprintf(fp, "\n#define\tFUNCLISTSIZ\t\t%d\n", i); 48 | 49 | if (fp != stdout) VOID_C fclose(fp); 50 | 51 | return(0); 52 | } 53 | -------------------------------------------------------------------------------- /mkkanji.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mkkanji.c 3 | * 4 | * preprocesser for "kanji.h" 5 | */ 6 | 7 | #include "headers.h" 8 | #include "typesize.h" 9 | 10 | #define MAXLINEBUF 255 11 | #define MESCONVSTR "mesconv" 12 | #define MESLISTSTR "meslist" 13 | #define MESCONVSTR2 "mesconv2" 14 | #define MESLISTSTR2 "meslist" 15 | 16 | int main __P_((int, char *CONST [])); 17 | 18 | 19 | int main(argc, argv) 20 | int argc; 21 | char *CONST argv[]; 22 | { 23 | FILE *fpin, *fpout; 24 | char *cp, *s, buf[MAXLINEBUF + 1]; 25 | long n; 26 | u_short sum; 27 | int i, len, quote; 28 | 29 | if (argc <= 1 || argc > 3) { 30 | fprintf(stderr, "Usage: mkkanji []\n"); 31 | return(1); 32 | } 33 | if (!strcmp(argv[1], "-")) fpin = stdin; 34 | else if (!(fpin = fopen(argv[1], "r"))) { 35 | fprintf(stderr, "%s: cannot open.\n", argv[1]); 36 | return(1); 37 | } 38 | if (argc <= 2) fpout = stdout; 39 | else if (!(fpout = fopen(argv[2], "w"))) { 40 | fprintf(stderr, "%s: cannot open.\n", argv[2]); 41 | VOID_C fclose(fpin); 42 | return(1); 43 | } 44 | 45 | n = 0L; 46 | sum = (u_short)0; 47 | while (fgets(buf, sizeof(buf), fpin)) { 48 | s = NULL; 49 | len = 0; 50 | for (cp = buf; cp; cp = strpbrk(cp, " \t")) { 51 | while (*cp == ' ' || *cp == '\t') cp++; 52 | if (!*cp) break; 53 | if (!strncmp(cp, MESCONVSTR, strsize(MESCONVSTR))) { 54 | s = MESCONVSTR2; 55 | len = strsize(MESCONVSTR); 56 | break; 57 | } 58 | if (!strncmp(cp, MESLISTSTR, strsize(MESLISTSTR))) { 59 | s = MESLISTSTR2; 60 | len = strsize(MESLISTSTR); 61 | break; 62 | } 63 | } 64 | if (s) { 65 | for (i = len; cp[i]; i++) 66 | if (cp[i] != ' ' && cp[i] != '\t') break; 67 | if (cp[i] != '(') s = NULL; 68 | else { 69 | len = cp - buf; 70 | cp += ++i; 71 | while (*cp == ' ' || *cp == '\t') cp++; 72 | } 73 | } 74 | 75 | if (!s) fputs(buf, fpout); 76 | else if (++n >= MAXUTYPE(u_short)) { 77 | fprintf(stderr, "too many entries.\n"); 78 | VOID_C fclose(fpin); 79 | VOID_C fclose(fpout); 80 | return(1); 81 | } 82 | else { 83 | quote = '\0'; 84 | for (i = 0; cp[i]; i++) { 85 | if (cp[i] == quote) quote = '\0'; 86 | else if (quote) sum += cp[i]; 87 | else if (cp[i] == '"') quote = cp[i]; 88 | } 89 | fprintf(fpout, "%-.*s%s(%3ld, %s", len, buf, s, n, cp); 90 | } 91 | } 92 | fprintf(fpout, "\n#define\tCAT_SUM\t%u\n", (u_int)sum & 0xffff); 93 | 94 | return(0); 95 | } 96 | -------------------------------------------------------------------------------- /mkmfdosb.sed: -------------------------------------------------------------------------------- 1 | s:/:\\:g 2 | s:__PREFIX__:: 3 | s:__CONFDIR__:: 4 | s:__EXE__:.exe:g 5 | s:__OBJ__:.obj:g 6 | s:__DOSOBJS__:$(DOSOBJS): 7 | s:__IMEOBJS__:: 8 | s:__DICTSRC__:: 9 | s:__MKDICTOPTION__:: 10 | s:__SOCKETOBJS__:: 11 | s:__SOCKETLIBS__:: 12 | s:__OBJLIST__:@$(ARGS): 13 | s:__SOBJLIST__:@$(SARGS): 14 | s:__NOBJLIST__:@$(NARGS): 15 | s:__DEFRC__:\\"$(DOSRC)\\": 16 | s:__TBLPATH__:: 17 | s:__DATADIR__:$(BINDIR):g 18 | s:__DATADIR2__:$(BINDIR):g 19 | s:__SLEEP__:#: 20 | s:__DJGPP1__:#: 21 | s:__ECHO__:command /c echo: 22 | s:__COPY__:copy /y: 23 | s:__RM__:del: 24 | s:__LANGDIR__:: 25 | s:__WITHUTF8__:: 26 | s:__PRESETKCODE__:: 27 | s:__INSTALL__:copy /y: 28 | s:__INSTSTRIP__:: 29 | s:__LN__:copy /y: 30 | s:__CC__:bcc: 31 | s:__CFLAGS__:-O -N -d -w-par -w-rch -w-ccc -w-pia: 32 | s:__CPPFLAGS__:: 33 | s:__LDFLAGS__:: 34 | s:__HOSTCC__:$(CC): 35 | s:__HOSTCFLAGS__:$(CFLAGS): 36 | s:__HOSTCPPFLAGS__:$(CPPFLAGS): 37 | s:__HOSTLDFLAGS__:$(LDFLAGS): 38 | s:__COPTS__:$(OSOPTS) $(DEBUG) $(CFLAGS): 39 | s:__HOSTCOPTS__:$(COPTS): 40 | s:__FDSETSIZE__:: 41 | s:__MEM__:-ml: 42 | s:__SHMEM__:-mm: 43 | s:__BSHMEM__:-mm: 44 | s:__NSHMEM__:-ml: 45 | s:__OUT__:-o$@: 46 | s:__LNK__:-e$@: 47 | s:__FLDFLAGS__:$(ALLOC) $(LDFLAGS): 48 | s:__SLDFLAGS__:$(ALLOC) $(LDFLAGS): 49 | s:__NLDFLAGS__:$(ALLOC) $(LDFLAGS): 50 | s:__KCODEOPTION__:-s: 51 | s:__MSBOPTION__:: 52 | s:__TABLES__:$(UNITBL) $(CATTBL) $(ECATTBL): 53 | s:__UNITBLOBJ__:: 54 | s:__PREFIXOPTION__:: 55 | s:[ ]*$:: 56 | /^[ ][ ]*-*\$(RM)$/d 57 | -------------------------------------------------------------------------------- /mkmfdosd.sed: -------------------------------------------------------------------------------- 1 | s:/:\\:g 2 | s:__PREFIX__:: 3 | s:__CONFDIR__:: 4 | s:__EXE__:.exe:g 5 | s:__OBJ__:.o:g 6 | s:__DOSOBJS__:$(DOSOBJS): 7 | s:__IMEOBJS__:: 8 | s:__DICTSRC__:: 9 | s:__MKDICTOPTION__:: 10 | s:__SOCKETOBJS__:: 11 | s:__SOCKETLIBS__:: 12 | s:__OBJLIST__:@$(ARGS): 13 | s:__SOBJLIST__:@$(SARGS): 14 | s:__NOBJLIST__:@$(NARGS): 15 | s:__DEFRC__:'"'$(DOSRC)'"': 16 | s:__TBLPATH__:: 17 | s:__DATADIR__:$(BINDIR):g 18 | s:__DATADIR2__:$(BINDIR):g 19 | s:__SLEEP__:#: 20 | s:__DJGPP1__:#: 21 | s:__ECHO__:command /c echo: 22 | s:__COPY__:copy /y: 23 | s:__RM__:del: 24 | s:__LANGDIR__:: 25 | s:__WITHUTF8__:: 26 | s:__PRESETKCODE__:: 27 | s:__INSTALL__:copy /y: 28 | s:__INSTSTRIP__:: 29 | s:__LN__:copy /y: 30 | s:__CC__:gcc: 31 | s:__CFLAGS__:-O: 32 | s:__CPPFLAGS__:: 33 | s:__LDFLAGS__:: 34 | s:__HOSTCC__:$(CC): 35 | s:__HOSTCFLAGS__:$(CFLAGS): 36 | s:__HOSTCPPFLAGS__:$(CPPFLAGS): 37 | s:__HOSTLDFLAGS__:$(LDFLAGS): 38 | s:__COPTS__:$(OSOPTS) $(DEBUG) $(CFLAGS): 39 | s:__HOSTCOPTS__:$(COPTS): 40 | s:__FDSETSIZE__:: 41 | s:__MEM__:: 42 | s:__SHMEM__:: 43 | s:__BSHMEM__:: 44 | s:__NSHMEM__:: 45 | s:__OUT__:-o $@: 46 | s:__LNK__:-o $@: 47 | s:__FLDFLAGS__:$(ALLOC) $(LDFLAGS): 48 | s:__SLDFLAGS__:$(ALLOC) $(LDFLAGS): 49 | s:__NLDFLAGS__:$(ALLOC) $(LDFLAGS): 50 | s:__KCODEOPTION__:-s: 51 | s:__MSBOPTION__:: 52 | s:__TABLES__:$(UNITBL) $(CATTBL) $(ECATTBL): 53 | s:__UNITBLOBJ__:: 54 | s:__PREFIXOPTION__:-c: 55 | s:[ ]*$:: 56 | /^[ ][ ]*-*\$(RM)$/d 57 | -------------------------------------------------------------------------------- /mkmfdosg.sed: -------------------------------------------------------------------------------- 1 | s:/:\\:g 2 | s:__PREFIX__:: 3 | s:__CONFDIR__:: 4 | s:__EXE__:.exe:g 5 | s:__OBJ__:.o:g 6 | s:__DOSOBJS__:$(DOSOBJS): 7 | s:__IMEOBJS__:: 8 | s:__DICTSRC__:: 9 | s:__MKDICTOPTION__:: 10 | s:__SOCKETOBJS__:: 11 | s:__SOCKETLIBS__:: 12 | s:__OBJLIST__:@$(ARGS): 13 | s:__SOBJLIST__:@$(SARGS): 14 | s:__NOBJLIST__:@$(NARGS): 15 | s:__DEFRC__:'"'$(DOSRC)'"': 16 | s:__TBLPATH__:: 17 | s:__DATADIR__:$(BINDIR):g 18 | s:__DATADIR2__:$(BINDIR):g 19 | s:__SLEEP__:#: 20 | s:__DJGPP1__:: 21 | s:__ECHO__:command /c echo: 22 | s:__COPY__:copy /y: 23 | s:__RM__:del: 24 | s:__LANGDIR__:: 25 | s:__WITHUTF8__:: 26 | s:__PRESETKCODE__:: 27 | s:__INSTALL__:copy /y: 28 | s:__INSTSTRIP__:: 29 | s:__LN__:copy /y: 30 | s:__CC__:gcc: 31 | s:__CFLAGS__:-O: 32 | s:__CPPFLAGS__:: 33 | s:__LDFLAGS__:: 34 | s:__HOSTCC__:$(CC): 35 | s:__HOSTCFLAGS__:$(CFLAGS): 36 | s:__HOSTCPPFLAGS__:$(CPPFLAGS): 37 | s:__HOSTLDFLAGS__:$(LDFLAGS): 38 | s:__COPTS__:$(OSOPTS) $(DEBUG) $(CFLAGS): 39 | s:__HOSTCOPTS__:$(COPTS): 40 | s:__FDSETSIZE__:: 41 | s:__MEM__:: 42 | s:__SHMEM__:: 43 | s:__BSHMEM__:: 44 | s:__NSHMEM__:: 45 | s:__OUT__:-o $@: 46 | s:__LNK__:-o $@: 47 | s:__FLDFLAGS__:$(ALLOC) $(LDFLAGS): 48 | s:__SLDFLAGS__:$(ALLOC) $(LDFLAGS): 49 | s:__NLDFLAGS__:$(ALLOC) $(LDFLAGS): 50 | s:__KCODEOPTION__:-s: 51 | s:__MSBOPTION__:: 52 | s:__TABLES__:$(UNITBL) $(CATTBL) $(ECATTBL): 53 | s:__UNITBLOBJ__:: 54 | s:__PREFIXOPTION__:: 55 | s:[ ]*$:: 56 | /^[ ][ ]*-*\$(RM)$/d 57 | -------------------------------------------------------------------------------- /mkmfdosl.sed: -------------------------------------------------------------------------------- 1 | s:/:\\:g 2 | s:__PREFIX__:: 3 | s:__CONFDIR__:: 4 | s:__EXE__:.exe:g 5 | s:__OBJ__:.obj:g 6 | s:__DOSOBJS__:$(DOSOBJS): 7 | s:__IMEOBJS__:: 8 | s:__DICTSRC__:: 9 | s:__MKDICTOPTION__:: 10 | s:__SOCKETOBJS__:: 11 | s:__SOCKETLIBS__:: 12 | s:__OBJLIST__:@$(ARGS): 13 | s:__SOBJLIST__:@$(SARGS): 14 | s:__NOBJLIST__:@$(NARGS): 15 | s:__DEFRC__:\\\\\\"$(DOSRC)\\\\\\": 16 | s:__TBLPATH__:: 17 | s:__DATADIR__:$(BINDIR):g 18 | s:__DATADIR2__:$(BINDIR):g 19 | s:__SLEEP__:#: 20 | s:__DJGPP1__:#: 21 | s:__ECHO__:command /c echo: 22 | s:__COPY__:copy /y: 23 | s:__RM__:del: 24 | s:__LANGDIR__:: 25 | s:__WITHUTF8__:: 26 | s:__PRESETKCODE__:: 27 | s:__INSTALL__:copy /y: 28 | s:__INSTSTRIP__:: 29 | s:__LN__:copy /y: 30 | s:__CC__:lcc86: 31 | s:__CFLAGS__:-O: 32 | s:__CPPFLAGS__:: 33 | s:__LDFLAGS__:: 34 | s:__HOSTCC__:$(CC): 35 | s:__HOSTCFLAGS__:$(CFLAGS): 36 | s:__HOSTCPPFLAGS__:$(CPPFLAGS): 37 | s:__HOSTLDFLAGS__:$(LDFLAGS): 38 | s:__COPTS__:$(OSOPTS) $(DEBUG) $(CFLAGS): 39 | s:__HOSTCOPTS__:$(COPTS): 40 | s:__FDSETSIZE__:: 41 | s:__MEM__:-ml -h -k"-s 3000": 42 | s:__SHMEM__:-mp -h -k"-s 8000": 43 | s:__BSHMEM__:-ms -k"-s 8000": 44 | s:__NSHMEM__:-mp -h -k"-s 8000": 45 | s:__OUT__:-o $@: 46 | s:__LNK__:-o $@: 47 | s:__FLDFLAGS__:-lintlib -ltinymain.obj $(ALLOC) $(LDFLAGS): 48 | s:__SLDFLAGS__:-lintlib -ltinymain.obj $(ALLOC) $(LDFLAGS): 49 | s:__NLDFLAGS__:-lintlib -ltinymain.obj $(ALLOC) $(LDFLAGS): 50 | s:__KCODEOPTION__:-s: 51 | s:__MSBOPTION__:: 52 | s:__TABLES__:$(UNITBL) $(CATTBL) $(ECATTBL): 53 | s:__UNITBLOBJ__:: 54 | s:__PREFIXOPTION__:: 55 | s:[ ]*$:: 56 | /^[ ][ ]*-*\$(RM)$/d 57 | -------------------------------------------------------------------------------- /mntinfo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mntinfo.c 3 | * 4 | * mount information module 5 | */ 6 | 7 | #include "headers.h" 8 | #include "kctype.h" 9 | #include "string.h" 10 | #include "malloc.h" 11 | #include "pathname.h" 12 | #include "mntinfo.h" 13 | #include "fsinfo.h" 14 | 15 | #ifdef USEREADMTAB 16 | static char *NEAR getmntfield __P_((char **)); 17 | #endif 18 | 19 | #if defined (USEGETFSSTAT) || defined (USEGETVFSTAT) \ 20 | || defined (USEMNTCTL) || defined (USEMNTINFOR) || defined (USEMNTINFO) \ 21 | || defined (USEGETMNT) 22 | static int mnt_ptr = 0; 23 | static int mnt_size = 0; 24 | #endif 25 | 26 | 27 | #ifdef USEMNTCTL 28 | /*ARGSUSED*/ 29 | FILE *Xsetmntent(file, mode) 30 | CONST char *file, *mode; 31 | { 32 | char *buf; 33 | 34 | mntctl(MCTL_QUERY, sizeof(int), (struct vmount *)&mnt_size); 35 | buf = Xmalloc(mnt_size); 36 | mntctl(MCTL_QUERY, mnt_size, (struct vmount *)buf); 37 | mnt_ptr = 0; 38 | 39 | return((FILE *)buf); 40 | } 41 | 42 | mnt_t *Xgetmntent(fp, mntp) 43 | FILE *fp; 44 | mnt_t *mntp; 45 | { 46 | static char *fsname = NULL; 47 | static char *dir = NULL; 48 | static char *type = NULL; 49 | struct vfs_ent *entp; 50 | struct vmount *vmntp; 51 | char *cp, *buf, *host; 52 | ALLOC_T len; 53 | 54 | if (mnt_ptr >= mnt_size) return(NULL); 55 | buf = (char *)fp; 56 | vmntp = (struct vmount *)&(buf[mnt_ptr]); 57 | 58 | cp = &(buf[mnt_ptr + vmntp -> vmt_data[VMT_OBJECT].vmt_off]); 59 | len = strlen(cp) + 1; 60 | if (!(vmntp -> vmt_flags & MNT_REMOTE)) { 61 | fsname = Xrealloc(fsname, len); 62 | memcpy(fsname, cp, len); 63 | } 64 | else { 65 | host = &(buf[mnt_ptr 66 | + vmntp -> vmt_data[VMT_HOSTNAME].vmt_off]); 67 | len += strlen(host) + 1; 68 | fsname = Xrealloc(fsname, len); 69 | Xstrcpy(Xstrcpy(Xstrcpy(fsname, host), ":"), cp); 70 | } 71 | 72 | cp = &(buf[mnt_ptr + vmntp -> vmt_data[VMT_STUB].vmt_off]); 73 | len = strlen(cp) + 1; 74 | dir = Xrealloc(dir, len); 75 | memcpy(dir, cp, len); 76 | 77 | entp = getvfsbytype(vmntp -> vmt_gfstype); 78 | if (entp) { 79 | cp = entp -> vfsent_name; 80 | len = strlen(cp) + 1; 81 | type = Xrealloc(type, len); 82 | memcpy(type, cp, len); 83 | } 84 | else if (type) { 85 | Xfree(type); 86 | type = NULL; 87 | } 88 | 89 | mntp -> Xmnt_fsname = fsname; 90 | mntp -> Xmnt_dir = dir; 91 | mntp -> Xmnt_type = (type) ? type : "???"; 92 | mntp -> Xmnt_opts = 93 | (vmntp -> vmt_flags & MNT_READONLY) ? "ro" : nullstr; 94 | mnt_ptr += vmntp -> vmt_length; 95 | 96 | return(mntp); 97 | } 98 | #endif /* USEMNTCTL */ 99 | 100 | #if defined (USEMNTINFOR) || defined (USEMNTINFO) \ 101 | || defined (USEGETFSSTAT) || defined (USEGETVFSTAT) 102 | 103 | # ifdef USEGETVFSTAT 104 | # define f_flags f_flag 105 | # define getfsstat2 getvfsstat 106 | typedef struct statvfs mntinfo_t; 107 | # else 108 | # define getfsstat2 getfsstat 109 | typedef struct statfs mntinfo_t; 110 | # endif 111 | 112 | # if !defined (MNT_RDONLY) && defined (M_RDONLY) 113 | # define MNT_RDONLY M_RDONLY 114 | # endif 115 | 116 | /*ARGSUSED*/ 117 | FILE *Xsetmntent(file, mode) 118 | CONST char *file, *mode; 119 | { 120 | # ifndef USEMNTINFO 121 | int size; 122 | # endif 123 | mntinfo_t *buf; 124 | 125 | buf = NULL; 126 | mnt_ptr = mnt_size = 0; 127 | 128 | # ifdef DEBUG 129 | _mtrace_file = "getmntinfo(start)"; 130 | # endif 131 | # ifdef USEMNTINFO 132 | mnt_size = getmntinfo(&buf, MNT_NOWAIT); 133 | # else /* !USEMNTINFO */ 134 | # ifdef USEMNTINFOR 135 | size = 0; 136 | getmntinfo_r(&buf, MNT_WAIT, &mnt_size, &size); 137 | # else 138 | size = (getfsstat2(NULL, 0, MNT_WAIT) + 1) * sizeof(mntinfo_t); 139 | if (size > 0) { 140 | buf = (mntinfo_t *)Xmalloc(size); 141 | mnt_size = getfsstat2(buf, size, MNT_WAIT); 142 | } 143 | # endif 144 | # endif /* !USEMNTINFO */ 145 | # ifdef DEBUG 146 | if (_mtrace_file) _mtrace_file = NULL; 147 | else { 148 | _mtrace_file = "getmntinfo(end)"; 149 | malloc(0); /* dummy malloc */ 150 | } 151 | # endif 152 | 153 | return((FILE *)buf); 154 | } 155 | 156 | mnt_t *Xgetmntent(fp, mntp) 157 | FILE *fp; 158 | mnt_t *mntp; 159 | { 160 | # if defined (USEMNTINFO) || defined (USEGETVFSTAT) 161 | # ifdef USEVFCNAME 162 | struct vfsconf *conf; 163 | # define getvfsbynumber(n) \ 164 | ((conf = getvfsbytype(n)) \ 165 | ? conf -> vfc_name : NULL) 166 | # else /* !USEVFCNAME */ 167 | # ifdef USEFFSTYPE 168 | # define getvfsbynumber(n) \ 169 | (buf[mnt_ptr].f_fstypename) 170 | # else /* !USEFFSTYPE */ 171 | # ifdef INITMOUNTNAMES 172 | static char *mnt_names[] = INITMOUNTNAMES; 173 | # define getvfsbynumber(n) \ 174 | (((n) <= MOUNT_MAXTYPE) \ 175 | ? mnt_names[n] : NULL) 176 | # else 177 | # define getvfsbynumber(n) \ 178 | (NULL) 179 | # endif 180 | # endif /* !USEFFSTYPE */ 181 | # endif /* !USEVFCNAME */ 182 | # else /* !USEMNTINFO && !USEGETVFSTAT */ 183 | # ifdef USEGETFSSTAT 184 | # define getvfsbynumber(n) \ 185 | (((n) <= MOUNT_MAXTYPE) \ 186 | ? mnt_names[n] : NULL) 187 | # endif 188 | # endif /* !USEMNTINFO && !USEGETVFSTAT */ 189 | static char *fsname = NULL; 190 | static char *dir = NULL; 191 | static char *type = NULL; 192 | mntinfo_t *buf; 193 | char *cp; 194 | ALLOC_T len; 195 | 196 | if (mnt_ptr >= mnt_size) return(NULL); 197 | buf = (mntinfo_t *)fp; 198 | 199 | # ifdef DEBUG 200 | _mtrace_file = "getmntent(start)"; 201 | # endif 202 | len = strlen(buf[mnt_ptr].f_mntfromname) + 1; 203 | fsname = Xrealloc(fsname, len); 204 | memcpy(fsname, buf[mnt_ptr].f_mntfromname, len); 205 | 206 | len = strlen(buf[mnt_ptr].f_mntonname) + 1; 207 | dir = Xrealloc(dir, len); 208 | memcpy(dir, buf[mnt_ptr].f_mntonname, len); 209 | 210 | cp = (char *)getvfsbynumber(buf[mnt_ptr].f_type); 211 | if (cp) { 212 | len = strlen(cp) + 1; 213 | type = Xrealloc(type, len); 214 | memcpy(type, cp, len); 215 | } 216 | else if (type) { 217 | Xfree(type); 218 | type = NULL; 219 | } 220 | # ifdef DEBUG 221 | if (_mtrace_file) _mtrace_file = NULL; 222 | else { 223 | _mtrace_file = "getmntent(end)"; 224 | malloc(0); /* dummy malloc */ 225 | } 226 | # endif 227 | 228 | mntp -> Xmnt_fsname = fsname; 229 | mntp -> Xmnt_dir = dir; 230 | mntp -> Xmnt_type = (type) ? type : "???"; 231 | mntp -> Xmnt_opts = 232 | (buf[mnt_ptr].f_flags & MNT_RDONLY) ? "ro" : nullstr; 233 | mnt_ptr++; 234 | 235 | return(mntp); 236 | } 237 | #endif /* USEMNTINFOR || USEMNTINFO || USEGETFSSTAT || USEGETVFSTAT */ 238 | 239 | #ifdef USEGETMNT 240 | /*ARGSUSED*/ 241 | FILE *Xsetmntent(file, mode) 242 | CONST char *file, *mode; 243 | { 244 | mnt_ptr = 0; 245 | 246 | return((FILE *)1); 247 | } 248 | 249 | /*ARGSUSED*/ 250 | mnt_t *Xgetmntent(fp, mntp) 251 | FILE *fp; 252 | mnt_t *mntp; 253 | { 254 | static char *fsname = NULL; 255 | static char *dir = NULL; 256 | static char *type = NULL; 257 | struct fs_data buf; 258 | ALLOC_T len; 259 | 260 | if (getmnt(&mnt_ptr, &buf, sizeof(buf), NOSTAT_MANY, NULL) <= 0) 261 | return(NULL); 262 | 263 | len = strlen(buf.fd_req.devname) + 1; 264 | fsname = Xrealloc(fsname, len); 265 | memcpy(fsname, buf.fd_req.devname, len); 266 | 267 | len = strlen(buf.fd_req.path) + 1; 268 | dir = Xrealloc(dir, len); 269 | memcpy(dir, buf.fd_req.path, len); 270 | 271 | len = strlen(gt_names[buf.fd_req.fstype]) + 1; 272 | type = Xrealloc(type, len); 273 | memcpy(type, gt_names[buf.fd_req.fstype], len); 274 | 275 | mntp -> Xmnt_fsname = fsname; 276 | mntp -> Xmnt_dir = dir; 277 | mntp -> Xmnt_type = type; 278 | mntp -> Xmnt_opts = (buf.fd_req.flags & M_RONLY) ? "ro" : nullstr; 279 | 280 | return(mntp); 281 | } 282 | #endif /* USEGETMNT */ 283 | 284 | #ifdef USEREADMTAB 285 | static char *NEAR getmntfield(cpp) 286 | char **cpp; 287 | { 288 | char *s; 289 | 290 | if (!cpp || !*cpp || !**cpp) return(vnullstr); 291 | 292 | while (Xisspace(**cpp)) (*cpp)++; 293 | if (!**cpp) return(vnullstr); 294 | s = *cpp; 295 | 296 | while (**cpp && !Xisspace(**cpp)) (*cpp)++; 297 | if (**cpp) *((*cpp)++) = '\0'; 298 | 299 | return(s); 300 | } 301 | 302 | FILE *Xsetmntent(file, mode) 303 | CONST char *file, *mode; 304 | { 305 | return(fopen(file, mode)); 306 | } 307 | 308 | mnt_t *Xgetmntent(fp, mntp) 309 | FILE *fp; 310 | mnt_t *mntp; 311 | { 312 | static char buf[BUFSIZ]; 313 | char *cp; 314 | 315 | if (!(cp = fgets(buf, sizeof(buf), fp))) return(NULL); 316 | 317 | mntp -> Xmnt_fsname = mntp -> Xmnt_dir = 318 | mntp -> Xmnt_type = mntp -> Xmnt_opts = NULL; 319 | 320 | mntp -> Xmnt_fsname = getmntfield(&cp); 321 | mntp -> Xmnt_dir = getmntfield(&cp); 322 | mntp -> Xmnt_type = getmntfield(&cp); 323 | mntp -> Xmnt_opts = getmntfield(&cp); 324 | 325 | return(mntp); 326 | } 327 | #endif /* USEREADMTAB */ 328 | 329 | char *Xhasmntopt(mntp, opt) 330 | mnt_t *mntp; 331 | CONST char *opt; 332 | { 333 | CONST char *cp; 334 | ALLOC_T len; 335 | 336 | len = strlen(opt); 337 | for (cp = mntp -> Xmnt_opts; cp && *cp;) { 338 | if (!strncmp(cp, opt, len) && (!cp[len] || cp[len] == ',')) 339 | return((char *)cp); 340 | if ((cp = Xstrchr(cp, ','))) cp++; 341 | } 342 | 343 | return(NULL); 344 | } 345 | -------------------------------------------------------------------------------- /mntinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mntinfo.h 3 | * 4 | * definitions & function prototype declarations for "mntinfo.c" 5 | */ 6 | 7 | #ifndef __MNTINFO_H_ 8 | #define __MNTINFO_H_ 9 | 10 | #ifdef USEMNTENTH 11 | #include 12 | #endif 13 | #ifdef USEMNTTABH 14 | #include 15 | #endif 16 | #ifdef USEMNTCTL 17 | #include 18 | #include 19 | #include 20 | #include 21 | #endif 22 | 23 | #define ETCMTAB "/etc/mtab" 24 | #define PROCMOUNTS "/proc/mounts" 25 | #define DEVROOT "/dev/root" 26 | #define ROOTFS "rootfs" 27 | 28 | #ifdef USEMNTENTH 29 | typedef struct mntent mnt_t; 30 | #define Xmnt_fsname mnt_fsname 31 | #define Xmnt_dir mnt_dir 32 | #define Xmnt_type mnt_type 33 | #define Xmnt_opts mnt_opts 34 | #define Xsetmntent setmntent 35 | #define Xgetmntent(f, m) getmntent(f) 36 | #define Xendmntent endmntent 37 | #endif 38 | 39 | #ifdef USEMNTTABH 40 | #define MOUNTED MNTTAB 41 | typedef struct mnttab mnt_t; 42 | #define Xmnt_fsname mnt_special 43 | #define Xmnt_dir mnt_mountp 44 | #define Xmnt_type mnt_fstype 45 | #define Xmnt_opts mnt_mntopts 46 | #define Xsetmntent fopen 47 | #define Xgetmntent(f, m) (getmntent(f, m) ? NULL : m) 48 | #define Xendmntent fclose 49 | #endif 50 | 51 | #if defined (USEGETFSSTAT) || defined (USEGETVFSTAT) \ 52 | || defined (USEMNTCTL) || defined (USEMNTINFOR) || defined (USEMNTINFO) \ 53 | || defined (USEGETMNT) || defined (USEREADMTAB) 54 | typedef struct _mnt_t { 55 | CONST char *Xmnt_fsname; 56 | CONST char *Xmnt_dir; 57 | CONST char *Xmnt_type; 58 | CONST char *Xmnt_opts; 59 | } mnt_t; 60 | # ifdef USEREADMTAB 61 | # define Xendmntent fclose 62 | # else /* !USEREADMTAB */ 63 | # if defined (USEMNTINFO) || defined (USEGETMNT) 64 | # define Xendmntent(f) 65 | # else 66 | # define Xendmntent Xfree 67 | # endif 68 | # endif /* !USEREADMTAB */ 69 | #endif /* USEGETFSSTAT || USEGETVFSTAT || USEMNTCTL \ 70 | || USEMNTINFOR || USEMNTINFO || USEGETMNT || USEREADMTAB */ 71 | 72 | #ifdef USEGETFSENT 73 | typedef struct fstab mnt_t; 74 | #define Xmnt_fsname fs_spec 75 | #define Xmnt_dir fs_file 76 | #define Xmnt_type fs_vfstype 77 | #define Xmnt_opts fs_mntops 78 | #define Xsetmntent(f, m) (FILE *)setfsent() 79 | #define Xgetmntent(f, m) getfsent() 80 | #define Xendmntent(fp) endfsent() 81 | #endif 82 | 83 | #if MSDOS 84 | # ifdef DOUBLESLASH 85 | # define MNTDIRSIZ MAXPATHLEN 86 | # else 87 | # define MNTDIRSIZ (3 + 1) 88 | # endif 89 | typedef struct _mnt_t { 90 | CONST char *Xmnt_fsname; 91 | char Xmnt_dir[MNTDIRSIZ]; 92 | CONST char *Xmnt_type; 93 | CONST char *Xmnt_opts; 94 | } mnt_t; 95 | #endif /* MSDOS */ 96 | 97 | #ifdef USEPROCMNT 98 | #undef MOUNTED 99 | #define MOUNTED PROCMOUNTS 100 | #endif 101 | #ifndef MOUNTED 102 | #define MOUNTED ETCMTAB 103 | #endif 104 | 105 | #if defined (USEGETFSSTAT) || defined (USEGETVFSTAT) \ 106 | || defined (USEMNTCTL) || defined (USEMNTINFOR) || defined (USEMNTINFO) \ 107 | || defined (USEGETMNT) || defined (USEREADMTAB) 108 | extern FILE *Xsetmntent __P_((CONST char *, CONST char *)); 109 | extern mnt_t *Xgetmntent __P_((FILE *, mnt_t *)); 110 | #endif 111 | extern char *Xhasmntopt __P_((mnt_t *, CONST char *)); 112 | 113 | #endif /* !__MNTINFO_H_ */ 114 | -------------------------------------------------------------------------------- /namelist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * namelist.h 3 | * 4 | * definitions for listing files 5 | */ 6 | 7 | #ifndef __NAMELIST_H_ 8 | #define __NAMELIST_H_ 9 | 10 | #include "depend.h" 11 | 12 | typedef struct _namelist { 13 | char *name; 14 | u_short ent; 15 | u_short st_mode; 16 | short st_nlink; 17 | #ifndef NOUID 18 | u_id_t st_uid; 19 | g_id_t st_gid; 20 | #endif 21 | #if !defined (NOSYMLINK) && defined (DEP_LSPARSE) 22 | char *linkname; 23 | #endif 24 | #ifdef HAVEFLAGS 25 | u_long st_flags; 26 | #endif 27 | off_t st_size; 28 | time_t st_mtim; 29 | u_char flags; 30 | u_char tmpflags; 31 | } namelist; 32 | 33 | #define F_ISEXE 0001 34 | #define F_ISWRI 0002 35 | #define F_ISRED 0004 36 | #define F_ISDIR 0010 37 | #define F_ISLNK 0020 38 | #define F_ISDEV 0040 39 | #define F_ISMRK 0001 40 | #define F_WSMRK 0002 41 | #define F_ISARG 0004 42 | #define F_STAT 0010 43 | #define isdir(file) ((file) -> flags & F_ISDIR) 44 | #define islink(file) ((file) -> flags & F_ISLNK) 45 | #define isdev(file) ((file) -> flags & F_ISDEV) 46 | #define isfile(file) (!((file) -> flags & (F_ISDIR | F_ISDEV))) 47 | #define isread(file) ((file) -> flags & F_ISRED) 48 | #define iswrite(file) ((file) -> flags & F_ISWRI) 49 | #define isexec(file) ((file) -> flags & F_ISEXE) 50 | #define ismark(file) ((file) -> tmpflags & F_ISMRK) 51 | #define wasmark(file) ((file) -> tmpflags & F_WSMRK) 52 | #define isarg(file) ((file) -> tmpflags & F_ISARG) 53 | #define havestat(file) ((file) -> tmpflags & F_STAT) 54 | #define s_isdir(s) ((((s) -> st_mode) & S_IFMT) == S_IFDIR) 55 | #define s_isreg(s) ((((s) -> st_mode) & S_IFMT) == S_IFREG) 56 | #define s_islnk(s) ((((s) -> st_mode) & S_IFMT) == S_IFLNK) 57 | #define s_isfifo(s) ((((s) -> st_mode) & S_IFMT) == S_IFIFO) 58 | #define s_ischr(s) ((((s) -> st_mode) & S_IFMT) == S_IFCHR) 59 | #define s_isblk(s) ((((s) -> st_mode) & S_IFMT) == S_IFBLK) 60 | 61 | #endif /* !__NAMELIST_H_ */ 62 | -------------------------------------------------------------------------------- /parse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * parse.h 3 | * 4 | * definitions & function prototype declarations for "parse.c" 5 | */ 6 | 7 | #include "depend.h" 8 | 9 | #if defined (FD) && (FD < 2) && !defined (OLDPARSE) 10 | #define OLDPARSE 11 | #endif 12 | 13 | extern char *skipspace __P_((CONST char *)); 14 | extern char *Xsscanf __P_((CONST char *, CONST char *, ...)); 15 | extern int Xatoi __P_((CONST char *)); 16 | #if defined (FD) && !defined (DEP_ORIGSHELL) 17 | extern char *strtkchr __P_((CONST char *, int, int)); 18 | extern int getargs __P_((CONST char *, char ***)); 19 | extern char *gettoken __P_((CONST char *)); 20 | extern char *getenvval __P_((int *, char *CONST [])); 21 | extern char *evalcomstr __P_((CONST char *, CONST char *)); 22 | #endif 23 | extern char *evalpaths __P_((CONST char *, int)); 24 | #if MSDOS && defined (FD) && !defined (DEP_ORIGSHELL) 25 | #define killmeta(s) Xstrdup(s) 26 | #else 27 | extern char *killmeta __P_((CONST char *)); 28 | #endif 29 | #if defined (FD) && !defined (DEP_ORIGSHELL) 30 | extern VOID adjustpath __P_((VOID_A)); 31 | #endif 32 | #ifdef FD 33 | extern char *includepath __P_((CONST char *, CONST char *)); 34 | #endif 35 | #if defined (OLDPARSE) && !defined (_NOARCHIVE) 36 | extern char *getrange __P_((CONST char *, int, u_char *, u_char *, u_char *)); 37 | #endif 38 | extern int getprintable __P_((char *, ALLOC_T, CONST char *, ALLOC_T, int *)); 39 | extern int evalprompt __P_((char **, CONST char *)); 40 | #if defined (FD) && !defined (_NOARCHIVE) 41 | extern char *getext __P_((CONST char *, u_char *)); 42 | extern int extcmp __P_((CONST char *, int, CONST char *, int, int)); 43 | #endif 44 | #ifdef FD 45 | extern int getkeycode __P_((CONST char *, int)); 46 | #endif 47 | extern CONST char *getkeysym __P_((int, int)); 48 | extern char *decodestr __P_((CONST char *, u_char *, int)); 49 | #if defined (FD) && !defined (_NOKEYMAP) 50 | extern char *encodestr __P_((CONST char *, int)); 51 | #endif 52 | -------------------------------------------------------------------------------- /posixsh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * posixsh.h 3 | * 4 | * function prototype declarations for "posixsh.c" 5 | */ 6 | 7 | #include "stream.h" 8 | 9 | #ifndef NOJOB 10 | extern int gettermio __P_((p_id_t, int)); 11 | extern VOID dispjob __P_((int, XFILE *)); 12 | extern int statjob __P_((int)); 13 | extern VOID freejob __P_((int)); 14 | extern int searchjob __P_((p_id_t, int *)); 15 | extern int getjob __P_((CONST char *)); 16 | extern int stackjob __P_((p_id_t, int, int, syntaxtree *)); 17 | extern int stoppedjob __P_((p_id_t)); 18 | extern VOID killjob __P_((VOID_A)); 19 | extern VOID checkjob __P_((XFILE *)); 20 | #endif /* !NOJOB */ 21 | extern char *evalposixsubst __P_((CONST char *, int *)); 22 | #if !MSDOS 23 | extern VOID replacemailpath __P_((CONST char *, int)); 24 | extern VOID checkmail __P_((int)); 25 | #endif 26 | #ifndef NOALIAS 27 | extern int addalias __P_((char *, char *)); 28 | extern int deletealias __P_((CONST char *)); 29 | extern VOID freealias __P_((shaliastable *)); 30 | extern int checkalias __P_((syntaxtree *, char *, int, int)); 31 | #endif 32 | #ifndef NOJOB 33 | extern int posixjobs __P_((syntaxtree *)); 34 | extern int posixfg __P_((syntaxtree *)); 35 | extern int posixbg __P_((syntaxtree *)); 36 | #endif 37 | #ifndef NOALIAS 38 | extern int posixalias __P_((syntaxtree *)); 39 | extern int posixunalias __P_((syntaxtree *)); 40 | #endif 41 | extern int posixkill __P_((syntaxtree *)); 42 | extern int posixtest __P_((syntaxtree *)); 43 | #ifndef NOPOSIXUTIL 44 | extern int posixcommand __P_((syntaxtree *)); 45 | extern int posixgetopts __P_((syntaxtree *)); 46 | #endif 47 | 48 | #ifndef NOJOB 49 | extern jobtable *joblist; 50 | extern int maxjobs; 51 | #endif 52 | #if !MSDOS 53 | extern int mailcheck; 54 | #endif 55 | #ifndef NOALIAS 56 | extern shaliastable *shellalias; 57 | #endif 58 | #ifndef NOPOSIXUTIL 59 | extern int posixoptind; 60 | #endif 61 | -------------------------------------------------------------------------------- /printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * printf.h 3 | * 4 | * definitions & function prototype declarations for "printf.c" 5 | */ 6 | 7 | #ifndef __PRINTF_H_ 8 | #define __PRINTF_H_ 9 | 10 | #include "stream.h" 11 | 12 | #define MAXCHARWID 4 13 | 14 | typedef struct _printbuf_t { 15 | char *buf; 16 | int ptr; 17 | int size; 18 | u_short flags; 19 | } printbuf_t; 20 | 21 | #define VF_NEW 000001 22 | #define VF_FILE 000002 23 | #define VF_KANJI 000010 24 | #define VF_UNSIGNED 000020 25 | #define VF_ARGUMENT 000040 26 | #define VF_PLUS 000100 27 | #define VF_MINUS 000200 28 | #define VF_SPACE 000400 29 | #define VF_ZERO 001000 30 | #define VF_THOUSAND 002000 31 | #define VF_STRICTWIDTH 004000 32 | #define VF_PRINTABLE 010000 33 | #define VF_SIZEUNIT 020000 34 | #define VF_ASPOSSIBLE 040000 35 | 36 | #ifdef MINIMUMSHELL 37 | #define strlen3 strlen2 38 | #else 39 | extern VOID getcharwidth __P_((CONST char *, ALLOC_T, int *, int *)); 40 | extern int strlen3 __P_((CONST char *)); 41 | #endif 42 | extern int getnum __P_((CONST char *, int *)); 43 | extern int setchar __P_((int, printbuf_t *)); 44 | #ifndef MINIMUMSHELL 45 | extern int Xvasprintf __P_((char **, CONST char *, va_list)); 46 | extern int Xasprintf __P_((char **, CONST char *, ...)); 47 | #endif 48 | extern int Xvsnprintf __P_((char *, int, CONST char *, va_list)); 49 | extern int Xsnprintf __P_((char *, int, CONST char *, ...)); 50 | extern int Xvfprintf __P_((XFILE *, CONST char *, va_list)); 51 | extern int Xfprintf __P_((XFILE *, CONST char *, ...)); 52 | extern int Xprintf __P_((CONST char *, ...)); 53 | extern int fputnl __P_((XFILE *)); 54 | #ifdef FD 55 | extern VOID kanjifputs __P_((CONST char *, XFILE *)); 56 | #else 57 | #define kanjifputs Xfputs 58 | #endif 59 | 60 | extern CONST char printfflagchar[]; 61 | extern CONST int printfflag[]; 62 | extern CONST char printfsizechar[]; 63 | extern CONST int printfsize[]; 64 | extern int printf_urgent; 65 | #ifdef DEP_FILECONV 66 | extern int printf_defkanji; 67 | #endif 68 | 69 | #endif /* !__PRINTF_H_ */ 70 | -------------------------------------------------------------------------------- /pty.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pty.c 3 | * 4 | * pseudo terminal access 5 | */ 6 | 7 | #include "fd.h" 8 | #include "sysemu.h" 9 | #include "pathname.h" 10 | #include "termio.h" 11 | 12 | #if !MSDOS 13 | #include 14 | #endif 15 | #ifdef SYSV 16 | #include 17 | #endif 18 | 19 | #ifdef GETPGRPVOID 20 | #define getpgroup getpgrp 21 | #else 22 | #define getpgroup() getpgrp(0) 23 | #endif 24 | #ifdef USESETPGID 25 | #define setpgroup setpgid 26 | #else 27 | #define setpgroup setpgrp 28 | #endif 29 | 30 | #define TTY_GROUP "tty" 31 | #ifndef _PATH_DEVNULL 32 | #define _PATH_DEVNULL "/dev/null" 33 | #endif 34 | #ifndef _PATH_PTY 35 | #define _PATH_PTY "/dev/pty" 36 | #endif 37 | #ifndef _PATH_DEVPTMX 38 | #define _PATH_DEVPTMX "/dev/ptmx" 39 | #endif 40 | #ifndef _PATH_DEVPTS 41 | #define _PATH_DEVPTS "/dev/pts" 42 | #endif 43 | #if defined (CYGWIN) && (CYGWIN > 1007009) 44 | /* for Cygwin buggy ioctl */ 45 | #undef TIOCSCTTY 46 | #endif 47 | 48 | #ifdef DEP_PTY 49 | 50 | static p_id_t NEAR Xsetsid __P_((VOID_A)); 51 | static VOID NEAR Xgrantpt __P_((int, CONST char *)); 52 | static VOID NEAR Xunlockpt __P_((int, CONST char *)); 53 | static int NEAR Xptsname __P_((int, CONST char *, char *, ALLOC_T)); 54 | int Xopenpty __P_((int *, int *, char *, ALLOC_T)); 55 | int Xlogin_tty __P_((CONST char *, CONST char *, CONST char *)); 56 | p_id_t Xforkpty __P_((int *, CONST char *, CONST char *)); 57 | 58 | #ifndef USEDEVPTMX 59 | static CONST char pty_char1[] = "pqrstuvwxyzPQRST"; 60 | static CONST char pty_char2[] = "0123456789abcdefghijklmnopqrstuv"; 61 | #endif 62 | 63 | 64 | static p_id_t NEAR Xsetsid(VOID_A) 65 | { 66 | #ifdef USESETSID 67 | return(setsid()); 68 | #else /* USESETSID */ 69 | p_id_t pid; 70 | int fd; 71 | 72 | pid = getpid(); 73 | if (pid == getpgroup()) { 74 | errno = EPERM; 75 | return((p_id_t)-1); 76 | } 77 | if (setpgroup(0, pid) < 0) return((p_id_t)-1); 78 | 79 | # ifdef TIOCNOTTY 80 | if ((fd = Xopen(_PATH_TTY, O_RDWR, 0)) >= 0) { 81 | VOID_C Xioctl(fd, TIOCNOTTY, NULL); 82 | safeclose(fd); 83 | } 84 | # else 85 | if ((fd = Xopen(_PATH_DEVNULL, O_RDWR, 0)) >= 0) { 86 | VOID_C Xdup2(fd, STDIN_FILENO); 87 | VOID_C Xdup2(fd, STDOUT_FILENO); 88 | VOID_C Xdup2(fd, STDERR_FILENO); 89 | safeclose(fd); 90 | } 91 | # endif 92 | 93 | return(pid); 94 | #endif /* USESETSID */ 95 | } 96 | 97 | /*ARGSUSED*/ 98 | static VOID NEAR Xgrantpt(fd, path) 99 | int fd; 100 | CONST char *path; 101 | { 102 | #ifdef USEDEVPTMX 103 | extern int grantpt __P_((int)); /* for Linux */ 104 | #else 105 | struct group *grp; 106 | gid_t gid; 107 | #endif 108 | 109 | #ifdef USEDEVPTMX 110 | VOID_C grantpt(fd); 111 | #else 112 | gid = ((grp = getgrnam(TTY_GROUP))) ? grp -> gr_gid : (gid_t)-1; 113 | 114 | VOID_C chown(path, getuid(), gid); 115 | VOID_C chmod(path, 0620); 116 | #endif 117 | } 118 | 119 | /*ARGSUSED*/ 120 | static VOID NEAR Xunlockpt(fd, path) 121 | int fd; 122 | CONST char *path; 123 | { 124 | #if defined (USEDEVPTMX) && defined (TIOCSPTLCK) 125 | int n; 126 | #endif 127 | 128 | #ifdef USEDEVPTMX 129 | # ifdef TIOCSPTLCK 130 | n = 0; 131 | VOID_C Xioctl(fd, TIOCSPTLCK, &n); 132 | # else 133 | VOID_C unlockpt(fd); 134 | # endif 135 | #else /* !USEDEVPTMX */ 136 | # ifdef BSD44 137 | VOID_C revoke(path); 138 | # endif 139 | #endif /* !USEDEVPTMX */ 140 | } 141 | 142 | /*ARGSUSED*/ 143 | static int NEAR Xptsname(fd, path, spath, size) 144 | int fd; 145 | CONST char *path; 146 | char *spath; 147 | ALLOC_T size; 148 | { 149 | #if !defined (USEDEVPTMX) || !defined (TIOCGPTN) 150 | char *cp; 151 | #endif 152 | #if defined (USEDEVPTMX) && defined (TIOCGPTN) 153 | int n; 154 | #endif 155 | 156 | #ifdef USEDEVPTMX 157 | # ifdef TIOCGPTN 158 | if (Xioctl(fd, TIOCGPTN, &n) < 0) return(-1); 159 | VOID_C Xsnprintf(spath, size, "%s/%d", _PATH_DEVPTS, n); 160 | # else 161 | if (!(cp = ptsname(fd))) return(-1); 162 | VOID_C Xsnprintf(spath, size, "%s", cp); 163 | # endif 164 | #else /* !USEDEVPTMX */ 165 | VOID_C Xsnprintf(spath, size, "%s", path); 166 | if ((cp = Xstrrchr(spath, '/'))) *(++cp) = 't'; 167 | #endif /* !USEDEVPTMX */ 168 | 169 | return(0); 170 | } 171 | 172 | int Xopenpty(amaster, aslave, spath, size) 173 | int *amaster, *aslave; 174 | char *spath; 175 | ALLOC_T size; 176 | { 177 | #ifndef USEDEVPTMX 178 | CONST char *cp1, *cp2; 179 | int n; 180 | #endif 181 | char path[MAXPATHLEN]; 182 | int master, slave; 183 | 184 | #ifdef USEDEVPTMX 185 | VOID_C Xsnprintf(path, sizeof(path), "%s", _PATH_DEVPTMX); 186 | if ((master = Xopen(path, O_RDWR, 0)) < 0) return(-1); 187 | 188 | Xgrantpt(master, path); 189 | Xunlockpt(master, path); 190 | if (Xptsname(master, path, spath, size) < 0 191 | || (slave = Xopen(spath, O_RDWR | O_NOCTTY, 0)) < 0) { 192 | safeclose(master); 193 | return(-1); 194 | } 195 | #else /* !USEDEVPTMX */ 196 | n = Xsnprintf(path, sizeof(path), "%sXX", _PATH_PTY); 197 | n -= 2; 198 | master = slave = -1; 199 | for (cp1 = pty_char1; *cp1; cp1++) { 200 | path[n] = *cp1; 201 | for (cp2 = pty_char2; *cp2; cp2++) { 202 | path[n + 1] = *cp2; 203 | master = Xopen(path, O_RDWR, 0); 204 | if (master < 0) { 205 | if (errno == ENOENT) break; 206 | continue; 207 | } 208 | 209 | VOID_C Xptsname(master, path, spath, size); 210 | Xgrantpt(master, spath); 211 | Xunlockpt(master, spath); 212 | slave = Xopen(spath, O_RDWR, 0); 213 | if (slave >= 0) break; 214 | 215 | safeclose(master); 216 | } 217 | 218 | if (master >= 0 && slave >= 0) break; 219 | } 220 | 221 | if (!*cp1) return(seterrno(ENOENT)); 222 | #endif /* !USEDEVPTMX */ 223 | 224 | *amaster = master; 225 | *aslave = slave; 226 | 227 | return(0); 228 | } 229 | 230 | #if defined (IRIX) || defined (DECOSF1V2) || defined (DECOSF1V3) 231 | #undef I_PUSH 232 | #endif 233 | 234 | int Xlogin_tty(path, tty, ws) 235 | CONST char *path, *tty, *ws; 236 | { 237 | int fd; 238 | 239 | VOID_C Xsetsid(); 240 | 241 | VOID_C Xclose(STDIN_FILENO); 242 | VOID_C Xclose(STDOUT_FILENO); 243 | VOID_C Xclose(STDERR_FILENO); 244 | if ((fd = Xopen(path, O_RDWR, 0)) < 0) return(-1); 245 | 246 | #ifdef I_PUSH 247 | if (Xioctl(fd, I_PUSH, "ptem") < 0 248 | || Xioctl(fd, I_PUSH, "ldterm") < 0) { 249 | VOID_C Xclose(fd); 250 | return(-1); 251 | } 252 | # if defined (SOLARIS) || defined (NEWS_OS6) 253 | VOID_C Xioctl(fd, I_PUSH, "ttcompat"); 254 | # endif 255 | #endif /* I_PUSH */ 256 | #ifdef TIOCSCTTY 257 | if (Xioctl(fd, TIOCSCTTY, NULL) < 0) { 258 | VOID_C Xclose(fd); 259 | return(-1); 260 | } 261 | #endif 262 | 263 | VOID_C Xdup2(fd, STDIN_FILENO); 264 | VOID_C Xdup2(fd, STDOUT_FILENO); 265 | VOID_C Xdup2(fd, STDERR_FILENO); 266 | loadtermio(fd, tty, ws); 267 | safeclose(fd); 268 | 269 | return(0); 270 | } 271 | 272 | p_id_t Xforkpty(amaster, tty, ws) 273 | int *amaster; 274 | CONST char *tty, *ws; 275 | { 276 | char path[MAXPATHLEN]; 277 | p_id_t pid; 278 | u_char uc; 279 | int n, master, slave, fds[2]; 280 | 281 | if (pipe(fds) < 0) return((p_id_t)-1); 282 | 283 | if (Xopenpty(&master, &slave, path, sizeof(path)) < 0) { 284 | pid = (p_id_t)-1; 285 | } 286 | else if ((pid = Xfork()) < (p_id_t)0) { 287 | safeclose(master); 288 | safeclose(slave); 289 | master = -1; 290 | } 291 | else if (pid) { 292 | VOID_C sureread(fds[0], &uc, sizeof(uc)); 293 | safeclose(slave); 294 | } 295 | else { 296 | safeclose(master); 297 | safeclose(slave); 298 | master = -1; 299 | n = Xlogin_tty(path, tty, ws); 300 | uc = '\n'; 301 | VOID_C surewrite(fds[1], &uc, sizeof(uc)); 302 | if (n < 0) _exit(1); 303 | } 304 | 305 | safeclose(fds[0]); 306 | safeclose(fds[1]); 307 | *amaster = master; 308 | 309 | return(pid); 310 | } 311 | #endif /* DEP_PTY */ 312 | -------------------------------------------------------------------------------- /realpath.c: -------------------------------------------------------------------------------- 1 | /* 2 | * realpath.c 3 | * 4 | * alternative pathname parser 5 | */ 6 | 7 | #ifdef FD 8 | #include "fd.h" 9 | #else 10 | #include "headers.h" 11 | #include "depend.h" 12 | #include "printf.h" 13 | #include "kctype.h" 14 | #include "string.h" 15 | #endif 16 | 17 | #include "sysemu.h" 18 | #include "pathname.h" 19 | #include "unixemu.h" 20 | #include "realpath.h" 21 | 22 | #if MSDOS && !defined (FD) 23 | #include "termio.h" 24 | #endif 25 | #ifdef DEP_URLPATH 26 | #include "url.h" 27 | #endif 28 | 29 | #if defined (FD) && (defined (DEP_DOSDRIVE) || defined (DEP_FTPPATH)) 30 | extern int reallstat __P_((CONST char *, struct stat *)); 31 | #else 32 | #define reallstat Xlstat 33 | #endif 34 | 35 | #if MSDOS 36 | # ifdef FD 37 | extern int setcurdrv __P_((int, int)); 38 | extern VOID error __P_((CONST char *)); 39 | extern VOID lostcwd __P_((char *)); 40 | # else 41 | static VOID NEAR error __P_((CONST char *)); 42 | # endif 43 | #endif /* MSDOS */ 44 | #ifdef DEP_DOSEMU 45 | extern char *dosgetcwd __P_((char *, int)); 46 | #endif 47 | 48 | #ifdef FD 49 | extern char fullpath[]; 50 | #endif 51 | #ifdef DEP_DOSEMU 52 | extern int lastdrive; 53 | #endif 54 | 55 | #ifndef NOSYMLINK 56 | static int NEAR evallink __P_((char *, int, int)); 57 | #endif 58 | static int NEAR _Xrealpath __P_((CONST char *, int, char *, int, int, int)); 59 | 60 | int norealpath = 0; 61 | 62 | 63 | #if MSDOS && !defined (FD) 64 | static VOID NEAR error(s) 65 | CONST char *s; 66 | { 67 | VOID_C Xfprintf(Xstderr, "%s: Error(%d).\n", errno); 68 | exit(2); 69 | } 70 | #endif /* MSDOS && !FD */ 71 | 72 | #ifndef NOSYMLINK 73 | static int NEAR evallink(path, tlen, rlen) 74 | char *path; 75 | int tlen, rlen; 76 | { 77 | struct stat st; 78 | char buf[MAXPATHLEN]; 79 | int n, duperrno; 80 | 81 | duperrno = errno; 82 | if (reallstat(path, &st) < 0) { 83 | errno = duperrno; 84 | return(-1); 85 | } 86 | if ((st.st_mode & S_IFMT) != S_IFLNK) { 87 | errno = duperrno; 88 | return(0); 89 | } 90 | if ((n = Xreadlink(path, buf, sizeof(buf) - 1)) < 0) { 91 | errno = duperrno; 92 | return(-1); 93 | } 94 | 95 | buf[n] = '\0'; 96 | if (*buf != _SC_ && rlen) path[rlen] = '\0'; 97 | else { 98 | copyrootpath(&(path[tlen])); 99 | rlen = tlen + 1; 100 | } 101 | rlen = _Xrealpath(buf, n, path, tlen, rlen, RLP_READLINK); 102 | errno = duperrno; 103 | 104 | return(rlen); 105 | } 106 | #endif /* !NOSYMLINK */ 107 | 108 | /*ARGSUSED*/ 109 | static int NEAR _Xrealpath(path, plen, resolved, tlen, rlen, flags) 110 | CONST char *path; 111 | int plen; 112 | char *resolved; 113 | int tlen, rlen, flags; 114 | { 115 | #ifndef NOSYMLINK 116 | int n; 117 | #endif 118 | char *cp, *top; 119 | int len; 120 | 121 | if (plen <= 0) return(rlen); 122 | else if (path[0] != '.') /*EMPTY*/; 123 | else if (plen == 1) return(rlen); 124 | else if (path[1] != '.') /*EMPTY*/; 125 | else if (plen == 2) { 126 | top = &(resolved[tlen]); 127 | cp = strrdelim(top, 0); 128 | if (!cp || cp <= top) { 129 | copyrootpath(top); 130 | return(++tlen); 131 | } 132 | *cp = '\0'; 133 | return(cp - top); 134 | } 135 | 136 | if ((cp = Xmemchr(path, _SC_, plen))) { 137 | len = cp++ - path; 138 | rlen = _Xrealpath(path, len, resolved, tlen, rlen, flags); 139 | plen -= ++len; 140 | return(_Xrealpath(cp, plen, resolved, tlen, rlen, flags)); 141 | } 142 | 143 | len = Xsnprintf(&(resolved[rlen]), MAXPATHLEN - rlen, 144 | "%s%-.*s", (rlen > tlen + 1) ? _SS_ : nullstr, plen, path); 145 | #ifdef CODEEUC 146 | len = strlen(&(resolved[rlen])); 147 | #endif 148 | #ifndef NOSYMLINK 149 | if ((flags & RLP_READLINK) 150 | && (n = evallink(resolved, tlen, rlen)) > 0) { 151 | rlen = n; 152 | len = 0; 153 | } 154 | #endif 155 | rlen += len; 156 | 157 | return(rlen); 158 | } 159 | 160 | char *Xrealpath(path, resolved, flags) 161 | CONST char *path; 162 | char *resolved; 163 | int flags; 164 | { 165 | #ifdef DEP_DOSEMU 166 | int duplastdrive; 167 | #endif 168 | #ifdef DEP_PATHTOP 169 | int drv; 170 | #endif 171 | #if MSDOS 172 | int drive; 173 | #endif 174 | char *cp, tmp[MAXPATHLEN]; 175 | int tlen, rlen; 176 | 177 | Xstrcpy(tmp, path); 178 | path = tmp; 179 | 180 | cp = NULL; 181 | tlen = rlen = 0; 182 | #ifdef DEP_DOSPATH 183 | drv = 0; 184 | #endif 185 | #ifdef DEP_PATHTOP 186 | if (!(flags & RLP_PSEUDOPATH) 187 | && (tlen = getpathtop(path, &drv, NULL))) { 188 | # ifdef DEP_DOSEMU 189 | if (drv) { 190 | if (path[tlen] != _SC_) { 191 | duplastdrive = lastdrive; 192 | lastdrive = drv; 193 | cp = dosgetcwd(resolved, MAXPATHLEN - 1); 194 | lastdrive = duplastdrive; 195 | } 196 | } 197 | else 198 | # endif 199 | rlen = Xsnprintf(resolved, MAXPATHLEN, 200 | "%-.*s%c", tlen, path, _SC_); 201 | path += tlen; 202 | flags &= ~RLP_READLINK; 203 | } 204 | else 205 | #endif /* DEP_PATHTOP */ 206 | { 207 | #if MSDOS 208 | tlen = 2; 209 | drive = dospath(nullstr, NULL); 210 | if ((drv = _dospath(path))) path += 2; 211 | else drv = drive; 212 | #endif 213 | 214 | if (*path == _SC_) /*EMPTY*/; 215 | #if MSDOS 216 | else if (Xtoupper(drv) != Xtoupper(drive)) { 217 | if (setcurdrv(drv, 0) >= 0) { 218 | cp = Xgetwd(resolved); 219 | if (setcurdrv(drive, 0) < 0) 220 | error("setcurdrv()"); 221 | # ifdef FD 222 | if (!cp) lostcwd(resolved); 223 | # else 224 | if (!cp) /*EMPTY*/; 225 | else 226 | # endif 227 | cp = resolved; 228 | } 229 | } 230 | #endif /* MSDOS */ 231 | #ifdef FD 232 | else if (!(flags & RLP_READLINK) 233 | && resolved != fullpath && *fullpath) { 234 | cp = Xstrcpy(resolved, fullpath); 235 | # ifdef DEP_PATHTOP 236 | tlen = getpathtop(resolved, NULL, NULL); 237 | # endif 238 | } 239 | #endif /* FD */ 240 | else cp = Xgetwd(resolved); 241 | } 242 | 243 | if (rlen > 0) { 244 | #ifdef CODEEUC 245 | rlen = strlen(resolved); 246 | #else 247 | /*EMPTY*/; 248 | #endif 249 | } 250 | else if (cp) rlen = strlen(cp); 251 | #ifdef DEP_DOSPATH 252 | else if (drv) { 253 | cp = gendospath(resolved, drv, _SC_); 254 | rlen = cp - resolved; 255 | } 256 | #endif 257 | else { 258 | copyrootpath(resolved); 259 | rlen = 1; 260 | } 261 | 262 | norealpath++; 263 | VOID_C _Xrealpath(path, strlen(path), 264 | resolved, tlen, strlen(resolved), flags); 265 | norealpath--; 266 | 267 | return(resolved); 268 | } 269 | -------------------------------------------------------------------------------- /realpath.h: -------------------------------------------------------------------------------- 1 | /* 2 | * realpath.h 3 | * 4 | * definitions & function prototype declarations for "realpath.c" 5 | */ 6 | 7 | #define RLP_READLINK 0001 8 | #define RLP_PSEUDOPATH 0002 9 | 10 | extern char *Xrealpath __P_((CONST char *, char *, int)); 11 | 12 | extern int norealpath; 13 | -------------------------------------------------------------------------------- /roman.h: -------------------------------------------------------------------------------- 1 | /* 2 | * roman.h 3 | * 4 | * definitions & function prototype declarations for "roman.c" 5 | */ 6 | 7 | #define R_MAXROMAN 4 8 | #define R_MAXKANA 2 9 | #define J_MIN 0x2121 10 | #define J_MAX 0x7e7e 11 | #define J_CHO 0x213c 12 | #define J_TSU 0x2443 13 | #define J_NN 0x2473 14 | #define VALIDJIS(c) (iseuc((((c) >> 8) & 0xff) ^ 0x80) \ 15 | && iseuc(((c) & 0xff) ^ 0x80)) 16 | 17 | typedef struct _romantable { 18 | char str[R_MAXROMAN + 1]; 19 | ALLOC_T len; 20 | u_short code[R_MAXKANA]; 21 | } romantable; 22 | 23 | extern int code2kanji __P_((char *, u_int)); 24 | extern int searchroman __P_((CONST char *, int)); 25 | extern VOID initroman __P_((VOID_A)); 26 | extern int jis2str __P_((char *, u_int)); 27 | extern int str2jis __P_((u_short *, int, CONST char *)); 28 | extern int addroman __P_((CONST char *, CONST char *)); 29 | extern VOID freeroman __P_((int)); 30 | 31 | extern romantable *romanlist; 32 | extern int maxromanlist; 33 | -------------------------------------------------------------------------------- /socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * socket.h 3 | * 4 | * definitions & function prototype declarations for "socket.c" 5 | */ 6 | 7 | #ifndef __SOCKET_H_ 8 | #define __SOCKET_H_ 9 | 10 | #include "depend.h" 11 | 12 | #if !MSDOS 13 | #include 14 | #endif 15 | 16 | #ifdef USESOCKLEN 17 | #define sock_len_t socklen_t 18 | #else 19 | typedef int sock_len_t; 20 | #endif 21 | 22 | #ifndef SHUT_RD 23 | #define SHUT_RD 0 24 | #endif 25 | #ifndef SHUT_WR 26 | #define SHUT_WR 1 27 | #endif 28 | #ifndef SHUT_RDWR 29 | #define SHUT_RDWR 2 30 | #endif 31 | 32 | #define SCK_BACKLOG 5 33 | #define SCK_ADDRSIZE (3 * 4 + 3) 34 | 35 | #define TELNET_IAC 255 36 | #define TELNET_DONT 254 37 | #define TELNET_DO 253 38 | #define TELNET_WONT 252 39 | #define TELNET_WILL 251 40 | #define TELNET_IP 244 41 | #define TELNET_DM 242 42 | 43 | typedef struct _sockdirdesc { 44 | int dd_id; 45 | int dd_fd; 46 | long dd_loc; 47 | long dd_size; 48 | } sockDIR; 49 | 50 | #define SID_IFURLDRIVE (-2) 51 | 52 | #define SCK_TOSTYPE 0007 53 | #define SCK_LOWDELAY 0001 54 | #define SCK_THROUGHPUT 0002 55 | #define SCK_RELIABILITY 0003 56 | #define SCK_MINCOST 0004 57 | #define SCK_NORMAL 0005 58 | #define SCK_KEEPALIVE 0010 59 | #define SCK_REUSEADDR 0020 60 | 61 | extern int cmpsockport __P_((CONST char *, CONST char *)); 62 | extern int cmpsockaddr __P_((CONST char *, CONST char *)); 63 | extern int issocket __P_((int)); 64 | extern int getsockinfo __P_((int, char *, ALLOC_T, int *, int)); 65 | extern int chgsockopt __P_((int, int)); 66 | extern int sockconnect __P_((CONST char *, int, int, int)); 67 | extern int sockbind __P_((CONST char *, int, int)); 68 | extern int sockreply __P_((int, int, u_char *, ALLOC_T, int)); 69 | extern int sockaccept __P_((int, int)); 70 | extern int socksendoob __P_((int, CONST VOID_P, ALLOC_T)); 71 | 72 | #endif /* !__SOCKET_H_ */ 73 | -------------------------------------------------------------------------------- /statfs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * statfs.c 3 | * 4 | * file system information module 5 | */ 6 | 7 | #include "headers.h" 8 | #include "fsinfo.h" 9 | 10 | 11 | #ifdef USEFSTATFS 12 | int Xstatfs(path, buf) 13 | CONST char *path; 14 | statfs_t *buf; 15 | { 16 | int n, fd; 17 | 18 | if ((fd = open(path, O_RDONLY, 0666)) < 0) return(-1); 19 | n = fstatfs(fd, buf); 20 | close(fd); 21 | 22 | return(n); 23 | } 24 | #endif /* USEFSTATFS */ 25 | -------------------------------------------------------------------------------- /stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * stream.h 3 | * 4 | * definitions & function prototype declarations for "stream.c" 5 | */ 6 | 7 | #ifndef __STREAM_H_ 8 | #define __STREAM_H_ 9 | 10 | #include "depend.h" 11 | 12 | #ifndef XF_BUFSIZ 13 | #define XF_BUFSIZ ((ALLOC_T)BUFSIZ) 14 | #endif 15 | 16 | #if MSDOS 17 | #define CH_EOF '\032' 18 | #else 19 | #define CH_EOF '\004' 20 | #endif 21 | 22 | #ifdef DEP_ORIGSTREAM 23 | typedef struct _XFILE { 24 | int fd; 25 | int status; 26 | int flags; 27 | ALLOC_T ptr; 28 | ALLOC_T count; 29 | char buf[XF_BUFSIZ]; 30 | # ifdef DEP_STREAMTIMEOUT 31 | int timeout; 32 | # endif 33 | # ifdef DEP_STREAMLOG 34 | VOID_T (*dumpfunc)__P_((CONST u_char *, ALLOC_T, CONST char *)); 35 | int debuglvl; 36 | CONST char *debugmes; 37 | char path[1]; 38 | # endif 39 | } XFILE; 40 | #else /* !DEP_ORIGSTREAM */ 41 | #define XFILE FILE 42 | #endif /* !DEP_ORIGSTREAM */ 43 | 44 | #define XS_EOF 000001 45 | #define XS_ERROR 000002 46 | #define XS_CLOSED 000004 47 | #define XS_READ 000010 48 | #define XS_WRITTEN 000020 49 | #define XS_BINARY 000040 50 | #define XS_RDONLY 000100 51 | #define XS_WRONLY 000200 52 | #define XS_LOCKED 000400 53 | #define XS_NOAHEAD 001000 54 | #define XS_CLEARBUF 002000 55 | #define XF_NOBUF 000001 56 | #define XF_LINEBUF 000002 57 | #define XF_CRNL 000004 58 | #define XF_NOCLOSE 000010 59 | #define XF_NONBLOCK 000020 60 | #define XF_CONNECTED 000040 61 | #define XF_TELNET 000100 62 | #define XF_NULLCONV 000200 63 | 64 | #ifdef DEP_ORIGSTREAM 65 | extern XFILE *Xfopen __P_((CONST char *, CONST char *)); 66 | extern XFILE *Xfdopen __P_((int, CONST char *)); 67 | extern int Xfclose __P_((XFILE *)); 68 | extern VOID Xclearerr __P_((XFILE *)); 69 | extern int Xfeof __P_((XFILE *)); 70 | extern int Xferror __P_((XFILE *)); 71 | extern int Xfileno __P_((XFILE *)); 72 | extern VOID Xsetflags __P_((XFILE *, int)); 73 | # ifdef DEP_STREAMTIMEOUT 74 | extern VOID Xsettimeout __P_((XFILE *, int)); 75 | # endif 76 | extern int Xfflush __P_((XFILE *)); 77 | extern int Xfpurge __P_((XFILE *)); 78 | extern int Xfread __P_((char *, ALLOC_T, XFILE *)); 79 | extern int Xfwrite __P_((CONST char *, ALLOC_T, XFILE *)); 80 | extern int Xfgetc __P_((XFILE *)); 81 | extern int Xfputc __P_((int, XFILE *)); 82 | extern char *Xfgets __P_((XFILE *)); 83 | extern int Xfputs __P_((CONST char *, XFILE *)); 84 | extern VOID Xsetbuf __P_((XFILE *)); 85 | extern VOID Xsetlinebuf __P_((XFILE *)); 86 | #else /* !DEP_ORIGSTREAM */ 87 | #define Xfopen fopen 88 | #define Xfdopen fdopen 89 | #define Xfclose fclose 90 | #define Xclearerr clearerr 91 | #define Xfeof feof 92 | #define Xferror ferror 93 | #define Xfileno fileno 94 | #define Xfflush fflush 95 | #define Xfpurge(f) 96 | #define Xfread(p, s, f) fread(p, 1, s, f) 97 | #define Xfwrite(p, s, f) fwrite(p, 1, s, f) 98 | #define Xfgetc fgetc 99 | #define Xfputc fputc 100 | #define Xfputs fputs 101 | # if MSDOS 102 | # define Xsetbuf(f) setbuf(f, NULL) 103 | # define Xsetlinebuf(f) 104 | # else /* !MSDOS */ 105 | # ifdef USESETVBUF 106 | # define Xsetbuf(f) setvbuf(f, NULL, _IONBF, 0) 107 | # define Xsetlinebuf(f) setvbuf(f, NULL, _IOLBF, 0) 108 | # else 109 | # define Xsetbuf(f) setbuf(f, NULL) 110 | # define Xsetlinebuf(f) setlinebuf(f) 111 | # endif 112 | # endif /* !MSDOS */ 113 | #endif /* !DEP_ORIGSTREAM */ 114 | #if defined (FD) && !defined (DEP_ORIGSHELL) 115 | extern XFILE *Xpopen __P_((CONST char *, CONST char *)); 116 | extern int Xpclose __P_((XFILE *)); 117 | #endif 118 | #ifndef FD 119 | extern char *gets2 __P_((CONST char *)); 120 | #endif 121 | 122 | #ifdef DEP_ORIGSTREAM 123 | extern int (*stream_isnfsfunc)__P_((CONST char *)); 124 | extern XFILE *Xstdin; 125 | extern XFILE *Xstdout; 126 | extern XFILE *Xstderr; 127 | #else 128 | #define Xstdin stdin 129 | #define Xstdout stdout 130 | #define Xstderr stderr 131 | #endif 132 | 133 | #endif /* !__STREAM_H_ */ 134 | -------------------------------------------------------------------------------- /string.c: -------------------------------------------------------------------------------- 1 | /* 2 | * string.c 3 | * 4 | * alternative string functions 5 | */ 6 | 7 | #include "headers.h" 8 | #include "kctype.h" 9 | #include "string.h" 10 | 11 | #define VT_OTHER 1 12 | #define VT_DIGIT 2 13 | #define VT_ALPHA 3 14 | 15 | 16 | char *Xstrchr(s, c) 17 | CONST char *s; 18 | int c; 19 | { 20 | for (; *s != c; s++) { 21 | if (!*s) return(NULL); 22 | else if (iswchar(s, 0)) s++; 23 | } 24 | 25 | return((char *)s); 26 | } 27 | 28 | char *Xstrrchr(s, c) 29 | CONST char *s; 30 | int c; 31 | { 32 | char *cp; 33 | 34 | cp = NULL; 35 | for (;; s++) { 36 | if (*s == c) cp = (char *)s; 37 | else if (iswchar(s, 0)) s++; 38 | if (!*s) break; 39 | } 40 | 41 | return(cp); 42 | } 43 | 44 | char *Xmemchr(s, c, n) 45 | CONST char *s; 46 | int c, n; 47 | { 48 | for (; n-- > 0; s++) { 49 | if (*s == c) return((char *)s); 50 | else if (iswchar(s, 0)) { 51 | if (n-- <= 0) break; 52 | s++; 53 | } 54 | } 55 | 56 | return(NULL); 57 | } 58 | 59 | char *Xstrcpy(s1, s2) 60 | char *s1; 61 | CONST char *s2; 62 | { 63 | int i; 64 | 65 | for (i = 0; s2[i]; i++) s1[i] = s2[i]; 66 | s1[i] = '\0'; 67 | 68 | return(&(s1[i])); 69 | } 70 | 71 | char *Xstrncpy(s1, s2, n) 72 | char *s1; 73 | CONST char *s2; 74 | int n; 75 | { 76 | int i; 77 | 78 | for (i = 0; i < n && s2[i]; i++) s1[i] = s2[i]; 79 | s1[i] = '\0'; 80 | 81 | return(&(s1[i])); 82 | } 83 | 84 | int Xstrcasecmp(s1, s2) 85 | CONST char *s1, *s2; 86 | { 87 | int c1, c2; 88 | 89 | for (;;) { 90 | c1 = Xtoupper(*s1); 91 | c2 = Xtoupper(*s2); 92 | if (c1 != c2) return(c1 - c2); 93 | if (iswchar(s1, 0)) { 94 | s1++; 95 | s2++; 96 | if (*s1 != *s2) return((u_char)*s1 - (u_char)*s2); 97 | } 98 | if (!*s1) break; 99 | s1++; 100 | s2++; 101 | } 102 | 103 | return(0); 104 | } 105 | 106 | int Xstrncasecmp(s1, s2, n) 107 | CONST char *s1, *s2; 108 | int n; 109 | { 110 | int c1, c2; 111 | 112 | while (n-- > 0) { 113 | c1 = Xtoupper(*s1); 114 | c2 = Xtoupper(*s2); 115 | if (c1 != c2) return(c1 - c2); 116 | if (iswchar(s1, 0)) { 117 | if (n-- <= 0) break; 118 | s1++; 119 | s2++; 120 | if (*s1 != *s2) return((u_char)*s1 - (u_char)*s2); 121 | } 122 | if (!*s1) break; 123 | s1++; 124 | s2++; 125 | } 126 | 127 | return(0); 128 | } 129 | 130 | #ifndef _NOVERSCMP 131 | static int NEAR verstype(c) 132 | int c; 133 | { 134 | if (Xisdigit(c)) return(VT_DIGIT); 135 | if (Xisalpha(c)) return(VT_ALPHA); 136 | 137 | return(VT_OTHER); 138 | } 139 | 140 | int Xstrverscmp(s1, s2, nocase) 141 | CONST char *s1, *s2; 142 | int nocase; 143 | { 144 | int n, c1, c2, t1, t2, blk, last; 145 | 146 | blk = last = 0; 147 | for (;;) { 148 | c1 = *s1; 149 | c2 = *s2; 150 | if (nocase) { 151 | c1 = Xtoupper(c1); 152 | c2 = Xtoupper(c2); 153 | } 154 | n = c1 - c2; 155 | if (!c1 || !c2) return(n); 156 | 157 | t1 = verstype(c1); 158 | switch (t1) { 159 | case VT_OTHER: 160 | blk++; 161 | break; 162 | case VT_ALPHA: 163 | blk = 0; 164 | break; 165 | default: 166 | break; 167 | } 168 | if (n) break; 169 | 170 | if (iswchar(s1, 0)) { 171 | s1++; 172 | s2++; 173 | if (*s1 != *s2) return((u_char)*s1 - (u_char)*s2); 174 | } 175 | 176 | last = t1; 177 | s1++; 178 | s2++; 179 | } 180 | 181 | t2 = verstype(c2); 182 | if (blk > 0) /*EMPTY*/; 183 | else if (last == VT_DIGIT || (t1 == VT_DIGIT && t2 == VT_DIGIT)) { 184 | for (;;) { 185 | if (t1 != t2) return((t1 == VT_DIGIT) ? 1 : -1); 186 | if (t1 != VT_DIGIT) return(n); 187 | 188 | t1 = verstype(*(++s1)); 189 | t2 = verstype(*(++s2)); 190 | } 191 | } 192 | 193 | return((t1 == t2) ? n : t1 - t2); 194 | } 195 | #endif /* !_NOVERSCMP */ 196 | 197 | #ifdef CODEEUC 198 | int strlen2(s) 199 | CONST char *s; 200 | { 201 | int i, len; 202 | 203 | for (i = len = 0; s[i]; i++, len++) if (isekana(s, i)) i++; 204 | 205 | return(len); 206 | } 207 | #endif /* CODEEUC */ 208 | 209 | VOID Xstrtolower(s) 210 | char *s; 211 | { 212 | if (s) for (; *s; s++) { 213 | if (iswchar(s, 0)) s++; 214 | else *s = Xtolower(*s); 215 | } 216 | } 217 | 218 | VOID Xstrtoupper(s) 219 | char *s; 220 | { 221 | if (s) for (; *s; s++) { 222 | if (iswchar(s, 0)) s++; 223 | else *s = Xtoupper(*s); 224 | } 225 | } 226 | 227 | VOID Xstrntolower(s, n) 228 | char *s; 229 | int n; 230 | { 231 | if (s) for (; n-- > 0 && *s; s++) { 232 | if (iswchar(s, 0)) s++; 233 | else *s = Xtolower(*s); 234 | } 235 | } 236 | 237 | VOID Xstrntoupper(s, n) 238 | char *s; 239 | int n; 240 | { 241 | if (s) for (; n-- > 0 && *s; s++) { 242 | if (iswchar(s, 0)) s++; 243 | else *s = Xtoupper(*s); 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * string.h 3 | * 4 | * function prototype declarations for "string.c" 5 | */ 6 | 7 | extern char *Xstrchr __P_((CONST char *, int)); 8 | extern char *Xstrrchr __P_((CONST char *, int)); 9 | extern char *Xmemchr __P_((CONST char *, int, int)); 10 | extern char *Xstrcpy __P_((char *, CONST char *)); 11 | extern char *Xstrncpy __P_((char *, CONST char *, int)); 12 | extern int Xstrcasecmp __P_((CONST char *, CONST char *)); 13 | extern int Xstrncasecmp __P_((CONST char *, CONST char *, int)); 14 | #ifndef _NOVERSCMP 15 | extern int Xstrverscmp __P_((CONST char *, CONST char *, int)); 16 | #endif 17 | #ifdef CODEEUC 18 | extern int strlen2 __P_((CONST char *)); 19 | #else 20 | #define strlen2 strlen 21 | #endif 22 | extern VOID Xstrtolower __P_((char *)); 23 | extern VOID Xstrtoupper __P_((char *)); 24 | extern VOID Xstrntolower __P_((char *, int)); 25 | extern VOID Xstrntoupper __P_((char *, int)); 26 | -------------------------------------------------------------------------------- /sysemu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sysemu.h 3 | * 4 | * definitions & function prototype declarations for "sysemu.c" 5 | */ 6 | 7 | #include "depend.h" 8 | #include "dirent.h" 9 | #include "stream.h" 10 | 11 | #define DEV_NORMAL 0 12 | #define DEV_DOS 1 13 | #define DEV_URL 2 14 | #define DEV_HTTP 3 15 | 16 | struct utimes_t { 17 | time_t actime; 18 | time_t modtime; 19 | }; 20 | 21 | extern int seterrno __P_((int)); 22 | #if MSDOS && defined (DJGPP) 23 | extern int dos_putpath __P_((CONST char *, int)); 24 | #endif 25 | #if MSDOS && !defined (FD) 26 | extern int getcurdrv __P_((VOID_A)); 27 | extern int setcurdrv __P_((int, int)); 28 | extern char *unixrealpath __P_((CONST char *, char *)); 29 | #endif 30 | #ifdef DEP_DOSPATH 31 | extern int _dospath __P_((CONST char *)); 32 | extern int dospath __P_((CONST char *, char *)); 33 | #endif 34 | #ifdef DEP_URLPATH 35 | extern int _urlpath __P_((CONST char *, char **, int *)); 36 | extern int urlpath __P_((CONST char *, char **, char *, int *)); 37 | #endif 38 | #ifdef DEP_DOSDRIVE 39 | # if MSDOS 40 | extern int dospath2 __P_((CONST char *)); 41 | extern int dospath3 __P_((CONST char *)); 42 | # else 43 | #define dospath2(path) dospath(path, NULL) 44 | #define dospath3(path) dospath(path, NULL) 45 | # endif 46 | #endif /* DEP_DOSDRIVE */ 47 | #ifdef CYGWIN 48 | char *getcygdrive_user __P_((VOID_A)); 49 | char *getcygdrive_system __P_((VOID_A)); 50 | # ifdef DEBUG 51 | VOID freecygdrive __P_((VOID_A)); 52 | # endif 53 | #endif /* CYGWIN */ 54 | #if (defined (DEP_KANJIPATH) || defined (DEP_ROCKRIDGE) \ 55 | || defined (DEP_PSEUDOPATH)) \ 56 | && defined (DEBUG) 57 | extern VOID freeopenlist(VOID_A); 58 | #endif 59 | #ifdef DEP_PSEUDOPATH 60 | extern int checkdrv __P_((int, int *)); 61 | extern int preparedrv __P_((CONST char *, int *, char *)); 62 | extern VOID shutdrv __P_((int)); 63 | #endif 64 | #ifdef DEP_DOSPATH 65 | extern u_int getunixmode __P_((u_int)); 66 | extern time_t getunixtime __P_((u_int, u_int)); 67 | extern u_short getdosmode __P_((u_int)); 68 | extern int getdostime __P_((u_short *, u_short *, time_t)); 69 | #endif 70 | #ifdef DEP_DIRENT 71 | extern DIR *Xopendir __P_((CONST char *)); 72 | extern int Xclosedir __P_((DIR *)); 73 | extern struct dirent *Xreaddir __P_((DIR *)); 74 | extern VOID Xrewinddir __P_((DIR *)); 75 | #else 76 | #define Xopendir opendir 77 | #define Xclosedir closedir 78 | #define Xreaddir readdir 79 | #define Xrewinddir rewinddir 80 | #endif 81 | #if MSDOS 82 | extern int rawchdir __P_((CONST char *)); 83 | #else 84 | #define rawchdir(p) ((chdir(p)) ? -1 : 0) 85 | #endif 86 | extern int Xchdir __P_((CONST char *)); 87 | extern char *Xgetwd __P_((char *)); 88 | #ifdef DEP_DIRENT 89 | extern int Xstat __P_((CONST char *, struct stat *)); 90 | extern int Xlstat __P_((CONST char *, struct stat *)); 91 | #else 92 | #define Xstat(p, s) ((stat(p, s)) ? -1 : 0) 93 | #define Xlstat(p, s) ((lstat(p, s)) ? -1 : 0) 94 | #endif 95 | #ifdef DEP_BIASPATH 96 | extern int Xaccess __P_((CONST char *, int)); 97 | extern int Xsymlink __P_((CONST char *, CONST char *)); 98 | extern int Xreadlink __P_((CONST char *, char *, int)); 99 | extern int Xchmod __P_((CONST char *, int)); 100 | #else 101 | #define Xaccess(p, m) ((access(p, m)) ? -1 : 0) 102 | #define Xsymlink(o, n) ((symlink(o, n)) ? -1 : 0) 103 | #define Xreadlink readlink 104 | #define Xchmod(p, m) ((chmod(p, m)) ? -1 : 0) 105 | #endif 106 | extern int rawutimes __P_((CONST char *, CONST struct utimes_t *)); 107 | extern int Xutimes __P_((CONST char *, CONST struct utimes_t *)); 108 | #ifdef DEP_BIASPATH 109 | # ifdef HAVEFLAGS 110 | extern int Xchflags __P_((CONST char *, u_long)); 111 | # endif 112 | # ifndef NOUID 113 | extern int Xchown __P_((CONST char *, u_id_t, g_id_t)); 114 | # endif 115 | extern int Xunlink __P_((CONST char *)); 116 | extern int Xrename __P_((CONST char *, CONST char *)); 117 | extern int Xopen __P_((CONST char *, int, int)); 118 | #else /* !DEP_BIASPATH */ 119 | #define Xchflags(p, f) ((chflags(p, f)) ? -1 : 0) 120 | #define Xchown(p, u, g) ((chown(p, u, g)) ? -1 : 0) 121 | #define Xunlink(p) ((unlink(p)) ? -1 : 0) 122 | #define Xrename(f, t) ((rename(f, t)) ? -1 : 0) 123 | #define Xopen open 124 | #endif /* !DEP_BIASPATH */ 125 | #ifdef DEP_PSEUDOPATH 126 | extern VOID putopenfd __P_((int, int)); 127 | extern int chkopenfd __P_((int)); 128 | extern int delopenfd __P_((int)); 129 | extern int Xclose __P_((int)); 130 | extern int Xread __P_((int, char *, int)); 131 | extern int Xwrite __P_((int, CONST char *, int)); 132 | extern off_t Xlseek __P_((int, off_t, int)); 133 | #ifndef NOFTRUNCATE 134 | extern int Xftruncate __P_((int, off_t)); 135 | #endif 136 | extern int Xdup __P_((int)); 137 | extern int Xdup2 __P_((int, int)); 138 | #else 139 | #define Xclose(f) ((close(f)) ? -1 : 0) 140 | #define Xread read 141 | #define Xwrite write 142 | #define Xlseek lseek 143 | #define Xftruncate ftruncate 144 | #define Xdup safe_dup 145 | #define Xdup2 safe_dup2 146 | #endif 147 | extern int Xmkdir __P_((CONST char *, int)); 148 | #ifdef DEP_BIASPATH 149 | extern int Xrmdir __P_((CONST char *)); 150 | #else 151 | #define Xrmdir(p) ((rmdir(p)) ? -1 : 0) 152 | #endif 153 | #ifdef NOFLOCK 154 | #define Xflock(f, o) (0) 155 | #else 156 | extern int Xflock __P_((int, int)); 157 | #endif 158 | #ifdef NOSELECT 159 | #define checkread(f, b, n, t) sureread(f, b, n) 160 | #else 161 | extern int checkread __P_((int, VOID_P, int, int)); 162 | #endif 163 | 164 | #ifdef DEP_PSEUDOPATH 165 | extern int lastdrv; 166 | #endif 167 | #ifdef DEP_DOSDRIVE 168 | extern int dosdrive; 169 | #endif 170 | #ifdef DEP_URLPATH 171 | extern int urldrive; 172 | extern int urlkcode; 173 | #endif 174 | #if defined (FD) && !defined (NOSELECT) 175 | extern int (*readintrfunc)__P_((VOID_A)); 176 | #endif 177 | -------------------------------------------------------------------------------- /term.h: -------------------------------------------------------------------------------- 1 | /* 2 | * term.h 3 | * 4 | * definitions & function prototype declarations for "term.c" 5 | */ 6 | 7 | #ifndef __TERM_H_ 8 | #define __TERM_H_ 9 | 10 | #include "stream.h" 11 | 12 | typedef struct _keyseq_t { 13 | char *str; 14 | short code; 15 | u_char len; 16 | u_char flags; 17 | } keyseq_t; 18 | 19 | #define KF_DEFINED 0001 20 | #define KF_HASALTER 0002 21 | 22 | #define GETSIZE "\033[6n" 23 | #define SIZEFMT "\033[%d;%dR" 24 | 25 | #define K_CR '\r' 26 | #define K_ESC '\033' 27 | 28 | #define K_MIN K_NOKEY 29 | #define K_NOKEY 0401 30 | #define K_DOWN 0402 31 | #define K_UP 0403 32 | #define K_LEFT 0404 33 | #define K_RIGHT 0405 34 | #define K_HOME 0406 35 | #define K_BS 0407 36 | #define K_F0 0410 37 | #define K_F(n) (K_F0 + (n)) 38 | #define K_DL 0510 39 | #define K_IL 0511 40 | #define K_DC 0512 41 | #define K_IC 0513 42 | #define K_EIC 0514 43 | #define K_CLR 0515 44 | #define K_EOS 0516 45 | #define K_EOL 0517 46 | #define K_ESF 0520 47 | #define K_ESR 0521 48 | #define K_NPAGE 0522 49 | #define K_PPAGE 0523 50 | #define K_STAB 0524 51 | #define K_CTAB 0525 52 | #define K_CATAB 0526 53 | #define K_ENTER 0527 54 | #define K_SRST 0530 55 | #define K_RST 0531 56 | #define K_PRINT 0532 57 | #define K_LL 0533 58 | #define K_A1 0534 59 | #define K_A3 0535 60 | #define K_B2 0536 61 | #define K_C1 0537 62 | #define K_C3 0540 63 | #define K_BTAB 0541 64 | #define K_BEG 0542 65 | #define K_CANC 0543 66 | #define K_CLOSE 0544 67 | #define K_COMM 0545 68 | #define K_COPY 0546 69 | #define K_CREAT 0547 70 | #define K_END 0550 71 | #define K_EXIT 0551 72 | #define K_FIND 0552 73 | #define K_HELP 0553 74 | #define K_MAX K_HELP 75 | #define K_TIMEOUT (K_MAX + 1) 76 | 77 | #define K_METAKEY 01000 78 | #define K_ALTERNATE 02000 79 | #if MSDOS 80 | #define mkmetakey(c) (K_METAKEY | (Xtolower(c) & 0x7f)) 81 | #define ismetakey(c) (((c) & K_METAKEY) && Xislower((c) & 0xff)) 82 | #else 83 | #define mkmetakey(c) (K_METAKEY | ((c) & 0x7f)) 84 | #define ismetakey(c) (((c) & K_METAKEY) && Xisalpha((c) & 0xff)) 85 | #endif 86 | #define mkekana(c) (K_METAKEY | ((c) & 0xff)) 87 | #define isekana2(c) (((c) & K_METAKEY) && Xiskana((c) & 0xff)) 88 | #define alternate(c) ((c) & ~K_ALTERNATE) 89 | 90 | #ifndef K_CTRL 91 | #define K_CTRL(c) ((c) & 037) 92 | #endif 93 | 94 | extern int n_column; 95 | extern int n_lastcolumn; 96 | extern int n_line; 97 | extern int stable_standout; 98 | 99 | #if MSDOS 100 | extern CONST char *termstr[]; 101 | #else 102 | extern char *termstr[]; 103 | #endif 104 | #define T_INIT 0 105 | #define T_END 1 106 | #define T_METAMODE 2 107 | #define T_NOMETAMODE 3 108 | #define T_SCROLL 4 109 | #define T_KEYPAD 5 110 | #define T_NOKEYPAD 6 111 | #define T_NORMALCURSOR 7 112 | #define T_HIGHCURSOR 8 113 | #define T_NOCURSOR 9 114 | #define T_SETCURSOR 10 115 | #define T_RESETCURSOR 11 116 | #define T_BELL 12 117 | #define T_VBELL 13 118 | #define T_CLEAR 14 119 | #define T_NORMAL 15 120 | #define T_BOLD 16 121 | #define T_REVERSE 17 122 | #define T_DIM 18 123 | #define T_BLINK 19 124 | #define T_STANDOUT 20 125 | #define T_UNDERLINE 21 126 | #define END_STANDOUT 22 127 | #define END_UNDERLINE 23 128 | #define L_CLEAR 24 129 | #define L_CLEARBOL 25 130 | #define L_INSERT 26 131 | #define L_DELETE 27 132 | #define C_INSERT 28 133 | #define C_DELETE 29 134 | #define C_LOCATE 30 135 | #define C_HOME 31 136 | #define C_RETURN 32 137 | #define C_NEWLINE 33 138 | #define C_SCROLLFORW 34 139 | #define C_SCROLLREV 35 140 | #define C_UP 36 141 | #define C_DOWN 37 142 | #define C_RIGHT 38 143 | #define C_LEFT 39 144 | #define C_NUP 40 145 | #define C_NDOWN 41 146 | #define C_NRIGHT 42 147 | #define C_NLEFT 43 148 | #define T_FGCOLOR 44 149 | #define T_BGCOLOR 45 150 | #define MAXTERMSTR 46 151 | 152 | extern u_char cc_intr; 153 | extern u_char cc_quit; 154 | extern u_char cc_eof; 155 | extern u_char cc_eol; 156 | extern u_char cc_erase; 157 | extern int (*keywaitfunc)__P_((VOID_A)); 158 | #if !MSDOS 159 | extern int usegetcursor; 160 | extern int suspended; 161 | extern char *duptty[2]; 162 | #endif 163 | extern int ttyio; 164 | extern int isttyiomode; 165 | extern XFILE *ttyout; 166 | extern int dumbterm; 167 | 168 | extern VOID inittty __P_((int)); 169 | extern VOID Xcooked __P_((VOID_A)); 170 | extern VOID Xcbreak __P_((VOID_A)); 171 | extern VOID Xraw __P_((VOID_A)); 172 | extern VOID Xecho __P_((VOID_A)); 173 | extern VOID Xnoecho __P_((VOID_A)); 174 | extern VOID Xnl __P_((VOID_A)); 175 | extern VOID Xnonl __P_((VOID_A)); 176 | extern VOID tabs __P_((VOID_A)); 177 | extern VOID notabs __P_((VOID_A)); 178 | extern VOID keyflush __P_((VOID_A)); 179 | #if !MSDOS 180 | extern int savettyio __P_((int)); 181 | #endif 182 | extern VOID ttyiomode __P_((int)); 183 | extern VOID stdiomode __P_((VOID_A)); 184 | extern int termmode __P_((int)); 185 | extern VOID exit2 __P_((int)); 186 | extern int getxy __P_((int *, int *)); 187 | extern VOID getterment __P_((CONST char *)); 188 | #if !MSDOS 189 | extern VOID freeterment __P_((VOID_A)); 190 | extern VOID regetterment __P_((CONST char *, int)); 191 | extern VOID setdefterment __P_((VOID_A)); 192 | extern VOID setdefkeyseq __P_((VOID_A)); 193 | extern int getdefkeyseq __P_((keyseq_t *)); 194 | extern VOID setkeyseq __P_((int, char *, int)); 195 | extern int getkeyseq __P_((keyseq_t *)); 196 | extern keyseq_t *copykeyseq __P_((keyseq_t *)); 197 | extern VOID freekeyseq __P_((keyseq_t *)); 198 | #endif 199 | extern int tputparam __P_((int, int, int, int)); 200 | extern VOID initterm __P_((VOID_A)); 201 | extern VOID endterm __P_((VOID_A)); 202 | extern VOID putterm __P_((int)); 203 | extern int Xputch __P_((int)); 204 | extern VOID Xcputs __P_((CONST char *)); 205 | extern VOID tputs2 __P_((CONST char *, int)); 206 | #if MSDOS 207 | #define putterms putterm 208 | #else 209 | extern VOID putterms __P_((int)); 210 | extern VOID checksuspend __P_((VOID_A)); 211 | #endif 212 | extern int kbhit2 __P_((long)); 213 | extern int Xgetch __P_((VOID_A)); 214 | extern int getkey2 __P_((int, int, int)); 215 | #if MSDOS 216 | #define getkey3 getkey2 217 | #else 218 | extern int getkey3 __P_((int, int, int)); 219 | #endif 220 | extern int ungetkey2 __P_((int, int)); 221 | extern int setscroll __P_((int, int)); 222 | extern VOID locate __P_((int, int)); 223 | extern VOID tflush __P_((VOID_A)); 224 | extern char *getwsize __P_((int, int)); 225 | extern VOID setwsize __P_((int, int, int)); 226 | extern int cvasprintf __P_((char **sp, CONST char *fmt, va_list)); 227 | extern int Xcprintf __P_((CONST char *, ...)); 228 | extern VOID tprintf __P_((CONST char *, int, ...)); 229 | extern VOID cputnl __P_((VOID_A)); 230 | extern int kanjiputs __P_((CONST char *)); 231 | extern VOID attrputs __P_((CONST char *, int)); 232 | extern int attrprintf __P_((CONST char *, int, ...)); 233 | extern int attrkanjiputs __P_((CONST char *, int)); 234 | extern VOID chgcolor __P_((int, int)); 235 | extern VOID movecursor __P_((int, int, int)); 236 | 237 | #ifndef SENSEPERSEC 238 | #define SENSEPERSEC 50 239 | #endif 240 | #ifndef WAITKEYPAD 241 | #define WAITKEYPAD 360 /* msec */ 242 | #endif 243 | #ifndef WAITTERMINAL 244 | #define WAITTERMINAL WAITKEYPAD /* msec */ 245 | #endif 246 | #ifndef WAITKANJI 247 | #define WAITKANJI 120 /* msec */ 248 | #endif 249 | 250 | #define ANSI_BLACK 0 251 | #define ANSI_RED 1 252 | #define ANSI_GREEN 2 253 | #define ANSI_YELLOW 3 254 | #define ANSI_BLUE 4 255 | #define ANSI_MAGENTA 5 256 | #define ANSI_CYAN 6 257 | #define ANSI_WHITE 7 258 | #define ANSI_NORMAL 30 259 | #define ANSI_REVERSE 40 260 | 261 | #endif /* !__TERM_H_ */ 262 | -------------------------------------------------------------------------------- /termemu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * termemu.h 3 | * 4 | * definitions for "termemu.c" 5 | */ 6 | 7 | #include "depend.h" 8 | #include "pathname.h" 9 | 10 | typedef struct _ptyinfo_t { 11 | p_id_t pid; 12 | char *path; 13 | int fd; 14 | int pipe; 15 | int status; 16 | #ifdef DEP_KCONV 17 | u_char incode, outcode; 18 | #endif 19 | } ptyinfo_t; 20 | 21 | #define TE_XPUTCH (K_MAX + 1) 22 | #define TE_XCPUTS (K_MAX + 2) 23 | #define TE_PUTTERM (K_MAX + 3) 24 | #define TE_PUTTERMS (K_MAX + 4) 25 | #define TE_SETSCROLL (K_MAX + 5) 26 | #define TE_LOCATE (K_MAX + 6) 27 | #define TE_CPUTNL (K_MAX + 7) 28 | #define TE_CHGCOLOR (K_MAX + 8) 29 | #define TE_MOVECURSOR (K_MAX + 9) 30 | #define TE_CHANGEWIN (K_MAX + 10) 31 | #define TE_CHANGEWSIZE (K_MAX + 11) 32 | #define TE_INSERTWIN (K_MAX + 12) 33 | #define TE_DELETEWIN (K_MAX + 13) 34 | #define TE_LOCKBACK (K_MAX + 14) 35 | #define TE_UNLOCKBACK (K_MAX + 15) 36 | #define TE_CHANGEKCODE (K_MAX + 16) 37 | #define TE_CHANGEINKCODE (K_MAX + 17) 38 | #define TE_CHANGEOUTKCODE (K_MAX + 18) 39 | #define TE_AWAKECHILD (K_MAX + 99) 40 | 41 | #define TE_SETVAR 1 42 | #define TE_PUSHVAR 2 43 | #define TE_POPVAR 3 44 | #define TE_CHDIR 4 45 | #define TE_PUTEXPORTVAR 5 46 | #define TE_PUTSHELLVAR 6 47 | #define TE_UNSET 7 48 | #define TE_SETEXPORT 8 49 | #define TE_SETRONLY 9 50 | #define TE_SETSHFLAG 10 51 | #define TE_ADDFUNCTION 11 52 | #define TE_DELETEFUNCTION 12 53 | #define TE_ADDALIAS 13 54 | #define TE_DELETEALIAS 14 55 | #define TE_SETHISTORY 15 56 | #define TE_ADDKEYBIND 16 57 | #define TE_DELETEKEYBIND 17 58 | #define TE_SETKEYSEQ 18 59 | #define TE_ADDLAUNCH 19 60 | #define TE_DELETELAUNCH 20 61 | #define TE_ADDARCH 21 62 | #define TE_DELETEARCH 22 63 | #define TE_INSERTDRV 23 64 | #define TE_DELETEDRV 24 65 | #define TE_LOCKFRONT 25 66 | #define TE_UNLOCKFRONT 26 67 | #define TE_SAVETTYIO 27 68 | #define TE_ADDROMAN 28 69 | #define TE_FREEROMAN 29 70 | #define TE_INTERNAL 30 71 | #define TE_CHANGESTATUS 99 72 | 73 | extern VOID regionscroll __P_((int, int, int, int, int, int)); 74 | extern int selectpty __P_((int, int [], char [], long)); 75 | extern VOID syncptyout __P_((int, int)); 76 | extern int recvbuf __P_((int, VOID_P, int)); 77 | extern VOID sendbuf __P_((int, CONST VOID_P, int)); 78 | extern int recvword __P_((int, int *)); 79 | extern VOID sendword __P_((int, int)); 80 | extern int recvstring __P_((int, char **)); 81 | extern VOID sendstring __P_((int, CONST char *)); 82 | extern VOID sendparent __P_((int, ...)); 83 | extern int ptymacro __P_((CONST char *, CONST char *, int)); 84 | extern VOID killpty __P_((int, int *)); 85 | extern VOID killallpty __P_((VOID_A)); 86 | extern int checkpty __P_((int)); 87 | extern int checkallpty __P_((VOID_A)); 88 | 89 | extern int ptymode; 90 | extern int ptyinternal; 91 | extern char *ptyterm; 92 | extern int ptymenukey; 93 | extern ptyinfo_t ptylist[]; 94 | extern int parentfd; 95 | -------------------------------------------------------------------------------- /termio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * termio.h 3 | * 4 | * definitions & function prototype declarations for "termio.c" 5 | */ 6 | 7 | #ifndef __TERMIO_H_ 8 | #define __TERMIO_H_ 9 | 10 | #include "stream.h" 11 | 12 | #ifdef CYGWIN 13 | #include "typesize.h" 14 | #endif 15 | #if !MSDOS 16 | #include 17 | #endif 18 | 19 | #if MSDOS 20 | #include 21 | #include 22 | # ifdef DJGPP 23 | # include 24 | # include 25 | # include 26 | # if (DJGPP >= 2) 27 | # include 28 | # endif 29 | # endif /* !DJGPP */ 30 | #else /* MSDOS */ 31 | # ifdef USETERMIOS 32 | #include 33 | # endif 34 | # ifdef USETERMIO 35 | #include 36 | # endif 37 | # ifdef USESGTTY 38 | #include 39 | # endif 40 | #endif /* MSDOS */ 41 | 42 | #if MSDOS 43 | #undef USETERMIOS 44 | #undef USETERMIO 45 | #undef USESGTTY 46 | #endif 47 | 48 | #ifndef STDIN_FILENO 49 | #define STDIN_FILENO 0 50 | #endif 51 | #ifndef STDOUT_FILENO 52 | #define STDOUT_FILENO 1 53 | #endif 54 | #ifndef STDERR_FILENO 55 | #define STDERR_FILENO 2 56 | #endif 57 | 58 | #ifdef ULONGIOCTL 59 | typedef unsigned long ioctlreq_t; 60 | #else 61 | typedef int ioctlreq_t; 62 | #endif 63 | 64 | #ifdef USETERMIOS 65 | typedef struct termios termioctl_t; 66 | typedef struct termios ldiscioctl_t; 67 | #define tioctl(d, r, a) ((r) \ 68 | ? Xtcsetattr(d, (r) - 1, a) : Xtcgetattr(d, a)) 69 | #define ttyflush(f, a) Xtcflush(f, a) 70 | #define getspeed(t) cfgetospeed(&t) 71 | # ifdef HAVECLINE 72 | # define ldisc(a) ((a).c_line) 73 | # endif 74 | #define REQGETP 0 75 | #define REQGETD 0 76 | #define REQSETP (TCSAFLUSH + 1) 77 | #define REQSETD (TCSADRAIN + 1) 78 | #define REQSETN (TCSANOW + 1) 79 | #define FLSHIN TCIFLUSH 80 | #define FLSHOUT TCOFLUSH 81 | #define FLSHIO TCIOFLUSH 82 | #endif /* USETERMIOS */ 83 | 84 | #ifdef USETERMIO 85 | typedef struct termio termioctl_t; 86 | typedef struct termio ldiscioctl_t; 87 | #define tioctl Xioctl 88 | #define ttyflush(f, a) Xioctl(f, TCFLSH, (VOID_P)a) 89 | #define getspeed(t) ((t).c_cflag & CBAUD) 90 | #define ldisc(a) ((a).c_line) 91 | #define REQGETP TCGETA 92 | #define REQGETD TCGETA 93 | #define REQSETP TCSETAF 94 | #define REQSETD TCSETAW 95 | #define REQSETN TCSETA 96 | #define FLSHIN 0 97 | #define FLSHOUT 1 98 | #define FLSHIO 2 99 | #endif /* USETERMIO */ 100 | 101 | #ifdef USESGTTY 102 | typedef struct sgttyb termioctl_t; 103 | typedef int ldiscioctl_t; 104 | #define tioctl Xioctl 105 | #define ttyflush(f, a) Xioctl(f, TIOCFLUSH, &(a)) 106 | #define getspeed(t) ((t).sg_ospeed) 107 | #define ldisc(a) (a) 108 | #define REQGETP TIOCGETP 109 | #define REQGETD TIOCGETD 110 | #define REQSETP TIOCSETP 111 | #define REQSETD TIOCSETD 112 | #define REQSETN TIOCSETN 113 | #define FLSHIN FREAD 114 | #define FLSHOUT FWRITE 115 | #define FLSHIO (FREAD | FWRITE) 116 | #endif /* USESGTTY */ 117 | 118 | #if defined (CYGWIN) && (CYGWIN > 1007009) 119 | /* for Cygwin buggy ioctl */ 120 | #undef ttyflush 121 | #define ttyflush(f, a) Xioctl(f, TCFLSH, (VOID_P)a) 122 | #endif 123 | 124 | #ifdef TIOCGWINSZ 125 | typedef struct winsize termwsize_t; 126 | #define REQGETWS TIOCGWINSZ 127 | #define REQSETWS TIOCSWINSZ 128 | #else /* !TIOCGWINSZ */ 129 | # ifdef WIOCGETD 130 | typedef struct uwdata termwsize_t; 131 | #define REQGETWS WIOCGETD 132 | #define REQSETWS WIOCSETD 133 | # else /* !WIOCGETD */ 134 | # ifdef TIOCGSIZE 135 | typedef struct ttysize termwsize_t; 136 | #define REQGETWS TIOCGSIZE 137 | #define REQSETWS TIOCSSIZE 138 | # else /* !TIOCGSIZE */ 139 | #define NOTERMWSIZE 140 | # endif /* !TIOCGSIZE */ 141 | # endif /* !WIOCGETD */ 142 | #endif /* !TIOCGWINSZ */ 143 | 144 | #ifndef PENDIN 145 | #define PENDIN 0 146 | #endif 147 | #ifndef IEXTEN 148 | #define IEXTEN 0 149 | #endif 150 | #ifndef ECHOCTL 151 | #define ECHOCTL 0 152 | #endif 153 | #ifndef ECHOKE 154 | #define ECHOKE 0 155 | #endif 156 | #ifndef OCRNL 157 | #define OCRNL 0 158 | #endif 159 | #ifndef ONOCR 160 | #define ONOCR 0 161 | #endif 162 | #ifndef ONLRET 163 | #define ONLRET 0 164 | #endif 165 | #ifndef OXTABS 166 | #define OXTABS XTABS 167 | #endif 168 | #ifndef TAB3 169 | #define TAB3 OXTABS 170 | #endif 171 | 172 | #define TIO_LCBREAK (ISIG | IEXTEN) 173 | #define TIO_LCOOKED (TIO_LCBREAK | ICANON) 174 | #define TIO_LECHO (ECHO | ECHOE | ECHOCTL | ECHOKE) 175 | #define TIO_LNOECHO ~(ECHO | ECHOE | ECHOK | ECHONL) 176 | #define TIO_ICOOKED (BRKINT | IXON) 177 | #define TIO_INOCOOKED ~(IGNBRK | ISTRIP) 178 | #define TIO_ONL (OPOST | ONLCR) 179 | #define TIO_ONONL ~(OCRNL | ONOCR | ONLRET) 180 | 181 | #if MSDOS 182 | # ifdef DJGPP 183 | # define TIO_BUFSIZ (ALLOC_T)0 184 | # else 185 | # define TIO_BUFSIZ sizeof(u_char) 186 | # endif 187 | # define TIO_WINSIZ (ALLOC_T)0 188 | #else /* !MSDOS */ 189 | # ifdef USESGTTY 190 | # define TIO_BUFSIZ (sizeof(termioctl_t) \ 191 | + sizeof(int) + sizeof(struct tchars)) 192 | # else 193 | # define TIO_BUFSIZ sizeof(termioctl_t) 194 | # endif 195 | # ifdef NOTERMWSIZE 196 | # define TIO_WINSIZ (ALLOC_T)0 197 | # else 198 | # define TIO_WINSIZ sizeof(termwsize_t) 199 | # endif 200 | #endif /* !MSDOS */ 201 | 202 | #if defined (USETERMIOS) || defined (USETERMIO) 203 | #if (VEOF == VMIN) || (VEOL == VTIME) 204 | #define VAL_VMIN '\004' 205 | #define VAL_VTIME 255 206 | #else 207 | #define VAL_VMIN 0 208 | #define VAL_VTIME 0 209 | #endif 210 | #endif /* USETERMIOS || USETERMIO */ 211 | 212 | #if MSDOS 213 | #define FR_CARRY 00001 214 | #define FR_PARITY 00004 215 | #define FR_ACARRY 00020 216 | #define FR_ZERO 00100 217 | #define FR_SIGN 00200 218 | #define FR_TRAP 00400 219 | #define FR_INTERRUPT 01000 220 | #define FR_DIRECTION 02000 221 | #define FR_OVERFLOW 04000 222 | # ifdef DJGPP 223 | # if (DJGPP < 2) 224 | # define __dpmi_regs _go32_dpmi_registers 225 | # define __dpmi_int(v, r) \ 226 | ((r) -> x.ss = (r) -> x.sp = 0, \ 227 | _go32_dpmi_simulate_int(v, r)) 228 | # define _dos_ds _go32_info_block.selector_for_linear_memory 229 | # define __tb \ 230 | _go32_info_block.linear_address_of_transfer_buffer 231 | # define __tb_offset (__tb & 15) 232 | # define __tb_segment (__tb / 16) 233 | # endif 234 | # define tbsize _go32_info_block.size_of_transfer_buffer 235 | # define PTR_FAR(p) ((u_long)(__tb)) 236 | # define PTR_SEG(p) (__tb_segment) 237 | # define PTR_OFF(p, o) (__tb_offset + (o)) 238 | # else /* !DJGPP */ 239 | # ifdef __TURBOC__ /* Oops!! Borland C++ has not x.bp !! */ 240 | typedef union DPMI_REGS { 241 | struct XREGS { 242 | u_short ax, bx, cx, dx, si, di, bp, flags; 243 | } x; 244 | struct HREGS { 245 | u_char al, ah, bl, bh, cl, ch, dl, dh; 246 | } h; 247 | } __dpmi_regs; 248 | # else 249 | typedef union REGS __dpmi_regs; 250 | # endif 251 | # define PTR_FAR(p) (((u_long)FP_SEG(p) << 4) \ 252 | + FP_OFF(p)) 253 | # define PTR_SEG(p) FP_SEG(p) 254 | # define PTR_OFF(p, o) FP_OFF(p) 255 | # endif /* !DJGPP */ 256 | #endif /* MSDOS */ 257 | 258 | #define ENVTERM "TERM" 259 | #define ENVLINES "LINES" 260 | #define ENVCOLUMNS "COLUMNS" 261 | #define ENVEMACS "EMACS" 262 | 263 | #define SEL_WRITE 0001 264 | #define SEL_NOINTR 0002 265 | #define SEL_TTYIO 0004 266 | 267 | #ifndef _PATH_TTY 268 | # if MSDOS 269 | # define _PATH_TTY "CON" 270 | # else 271 | # define _PATH_TTY "/dev/tty" 272 | # endif 273 | #endif /* !_PATH_TTY */ 274 | 275 | #ifdef LSI_C 276 | extern int safe_dup __P_((int)); 277 | extern int safe_dup2 __P_((int, int)); 278 | #else 279 | #define safe_dup dup 280 | #define safe_dup2 dup2 281 | #endif 282 | #if MSDOS 283 | extern VOID dosseterrno __P_((u_int)); 284 | extern int intcall __P_((int, __dpmi_regs *, struct SREGS *)); 285 | #endif 286 | extern int Xgetdtablesize __P_((VOID_A)); 287 | extern int isvalidfd __P_((int)); 288 | extern int newdup __P_((int)); 289 | extern int sureread __P_((int, VOID_P, int)); 290 | extern int surewrite __P_((int, CONST VOID_P, int)); 291 | extern VOID safeclose __P_((int)); 292 | extern VOID safefclose __P_((XFILE *)); 293 | extern int opentty __P_((int *, XFILE **)); 294 | extern VOID closetty __P_((int *, XFILE **)); 295 | #if !MSDOS 296 | extern VOID closeonexec __P_((int)); 297 | extern int Xioctl __P_((int, ioctlreq_t, VOID_P)); 298 | # ifdef USETERMIOS 299 | extern int Xtcgetattr __P_((int, termioctl_t *)); 300 | extern int Xtcsetattr __P_((int, int, CONST termioctl_t *)); 301 | extern int Xtcflush __P_((int, int)); 302 | # endif 303 | #endif /* !MSDOS */ 304 | #if defined (FD) || defined (CYGWIN) || !defined (NOJOB) 305 | extern VOID loadtermio __P_((int, CONST char *, CONST char *)); 306 | extern VOID savetermio __P_((int, char **, char **)); 307 | #endif 308 | #ifdef CYGWIN 309 | extern p_id_t Xfork __P_((VOID_A)); 310 | #else 311 | #define Xfork fork 312 | #endif 313 | #ifndef NOSELECT 314 | extern int sureselect __P_((int, int [], char [], VOID_P, int)); 315 | #define readselect(n, f, r, v) sureselect(n, f, r, v, 0) 316 | #endif 317 | 318 | #endif /* !__TERMIO_H_ */ 319 | -------------------------------------------------------------------------------- /time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * time.c 3 | * 4 | * alternative time functions 5 | */ 6 | 7 | #include "headers.h" 8 | #include "typesize.h" 9 | #include "string.h" 10 | #include "time.h" 11 | 12 | #if !MSDOS && !defined (USEMKTIME) && !defined (USETIMELOCAL) 13 | #include "sysemu.h" 14 | #include "pathname.h" 15 | #include "stream.h" 16 | #endif 17 | 18 | #ifndef NOTZFILEH 19 | #include 20 | #endif 21 | #if MSDOS 22 | #include 23 | #endif 24 | 25 | #ifdef GETTODNULL 26 | #define timezonep(t) NULL 27 | #else 28 | #define timezonep(t) &(t) 29 | #endif 30 | 31 | #if !MSDOS && !defined (NOTZFILEH) \ 32 | && !defined (USEMKTIME) && !defined (USETIMELOCAL) 33 | static long NEAR char2long __P_((CONST u_char *)); 34 | static int NEAR tmcmp __P_((CONST struct tm *, CONST struct tm *)); 35 | # ifdef DEP_ORIGSTREAM 36 | static int NEAR Xfseek __P_((XFILE *, off_t, int)); 37 | # else 38 | # define Xfseek fseek 39 | # endif 40 | #endif /* !MSDOS && !NOTZFILEH && !USEMKTIME && !USETIMELOCAL */ 41 | static int NEAR getmaxday __P_((int, int)); 42 | #if !defined (USEMKTIME) && !defined (USETIMELOCAL) 43 | static long NEAR gettimezone __P_((CONST struct tm *, time_t)); 44 | #endif 45 | 46 | 47 | time_t Xtime(tp) 48 | time_t *tp; 49 | { 50 | #if MSDOS 51 | struct timeb buffer; 52 | #else /* !MSDOS */ 53 | # ifndef GETTODNULL 54 | struct timezone tz; 55 | # endif 56 | struct timeval tv; 57 | #endif /* !MSDOS */ 58 | time_t t; 59 | 60 | #if MSDOS 61 | VOID_C ftime(&buffer); 62 | t = (time_t)(buffer.time); 63 | if (tp) *tp = (time_t)(buffer.millitm); 64 | #else 65 | VOID_C Xgettimeofday(&tv, timezonep(tz)); 66 | t = (time_t)(tv.tv_sec); 67 | if (tp) *tp = (time_t)(tv.tv_usec / 1000L); 68 | #endif 69 | 70 | return(t); 71 | } 72 | 73 | #if !MSDOS && !defined (NOTZFILEH) \ 74 | && !defined (USEMKTIME) && !defined (USETIMELOCAL) 75 | static long NEAR char2long(s) 76 | CONST u_char *s; 77 | { 78 | return((long)((u_long)(s[3]) 79 | | ((u_long)(s[2]) << (BITSPERBYTE * 1)) 80 | | ((u_long)(s[1]) << (BITSPERBYTE * 2)) 81 | | ((u_long)(s[0]) << (BITSPERBYTE * 3)))); 82 | } 83 | 84 | static int NEAR tmcmp(tm1, tm2) 85 | CONST struct tm *tm1, *tm2; 86 | { 87 | if (tm1 -> tm_year != tm2 -> tm_year) 88 | return (tm1 -> tm_year - tm2 -> tm_year); 89 | if (tm1 -> tm_mon != tm2 -> tm_mon) 90 | return (tm1 -> tm_mon - tm2 -> tm_mon); 91 | if (tm1 -> tm_mday != tm2 -> tm_mday) 92 | return (tm1 -> tm_mday - tm2 -> tm_mday); 93 | if (tm1 -> tm_hour != tm2 -> tm_hour) 94 | return (tm1 -> tm_hour - tm2 -> tm_hour); 95 | if (tm1 -> tm_min != tm2 -> tm_min) 96 | return (tm1 -> tm_min - tm2 -> tm_min); 97 | 98 | return (tm1 -> tm_sec - tm2 -> tm_sec); 99 | } 100 | 101 | # ifdef DEP_ORIGSTREAM 102 | static int NEAR Xfseek(fp, offset, whence) 103 | XFILE *fp; 104 | off_t offset; 105 | int whence; 106 | { 107 | if (!fp || (fp -> flags & XF_ERROR)) return(-1); 108 | if ((fp -> flags & XF_WRITTEN) && Xfflush(fp) == EOF) return(-1); 109 | offset = Xlseek(fp -> fd, offset, whence); 110 | fp -> ptr = fp -> count = (ALLOC_T)0; 111 | fp -> flags &= ~XF_EOF; 112 | 113 | return((offset < (off_t)0) ? -1 : 0); 114 | } 115 | # endif /* DEP_ORIGSTREAM */ 116 | #endif /* !MSDOS && !NOTZFILEH && !USEMKTIME && !USETIMELOCAL */ 117 | 118 | static int NEAR getmaxday(mon, year) 119 | int mon, year; 120 | { 121 | int mday; 122 | 123 | switch (mon) { 124 | case 2: 125 | mday = 28; 126 | if (!(year % 4) && ((year % 100) || !(year % 400))) 127 | mday++; 128 | break; 129 | case 4: 130 | case 6: 131 | case 9: 132 | case 11: 133 | mday = 30; 134 | break; 135 | default: 136 | mday = 31; 137 | break; 138 | } 139 | 140 | return(mday); 141 | } 142 | 143 | time_t Xtimegm(tm) 144 | CONST struct tm *tm; 145 | { 146 | time_t t; 147 | int i, y; 148 | 149 | if (tm -> tm_year < 0) return((time_t)-1); 150 | y = (tm -> tm_year < 1900) ? tm -> tm_year + 1900 : tm -> tm_year; 151 | if (tm -> tm_mon < 0 || tm -> tm_mon > 11) return((time_t)-1); 152 | if (tm -> tm_mday < 1 153 | || tm -> tm_mday > getmaxday(tm -> tm_mon + 1, y)) 154 | return((time_t)-1); 155 | if (tm -> tm_hour < 0 || tm -> tm_hour > 23) return((time_t)-1); 156 | if (tm -> tm_min < 0 || tm -> tm_min > 59) return((time_t)-1); 157 | if (tm -> tm_sec < 0 || tm -> tm_sec > 60) return((time_t)-1); 158 | 159 | t = ((long)y - 1970) * 365; 160 | t += ((y - 1 - 1968) / 4) 161 | - ((y - 1 - 1900) / 100) 162 | + ((y - 1 - 1600) / 400); 163 | for (i = 1; i < tm -> tm_mon + 1; i++) t += getmaxday(i, y); 164 | t += tm -> tm_mday - 1; 165 | t *= 60L * 60L * 24L; 166 | t += ((long)(tm -> tm_hour) * 60L + tm -> tm_min) * 60L + tm -> tm_sec; 167 | 168 | return(t); 169 | } 170 | 171 | #if !defined (USEMKTIME) && !defined (USETIMELOCAL) 172 | static long NEAR gettimezone(tm, t) 173 | CONST struct tm *tm; 174 | time_t t; 175 | { 176 | # if MSDOS 177 | struct timeb buffer; 178 | 179 | ftime(&buffer); 180 | return((long)(buffer.timezone) * 60L); 181 | # else /* !MSDOS */ 182 | # ifndef NOTZFILEH 183 | struct tzhead head; 184 | XFILE *fp; 185 | time_t tmp; 186 | long i, leap, nleap, ntime, ntype, nchar; 187 | char *cp, buf[MAXPATHLEN]; 188 | u_char c; 189 | # endif 190 | struct tm tmbuf; 191 | long tz; 192 | 193 | memcpy((char *)&tmbuf, (char *)tm, sizeof(struct tm)); 194 | 195 | # ifdef NOTMGMTOFF 196 | tz = (long)t - (long)Xtimegm(localtime(&t)); 197 | # else 198 | tz = -(localtime(&t) -> tm_gmtoff); 199 | # endif 200 | 201 | # ifndef NOTZFILEH 202 | cp = getenv("TZ"); 203 | if (!cp || !*cp) cp = TZDEFAULT; 204 | if (cp[0] == _SC_) Xstrcpy(buf, cp); 205 | else strcatdelim2(buf, TZDIR, cp); 206 | if (!(fp = Xfopen(buf, "rb"))) return(tz); 207 | if (Xfread((char *)&head, sizeof(head), fp) != sizeof(head)) { 208 | VOID_C Xfclose(fp); 209 | return(tz); 210 | } 211 | # ifdef USELEAPCNT 212 | nleap = char2long(head.tzh_leapcnt); 213 | # else 214 | nleap = char2long(head.tzh_timecnt - 4); 215 | # endif 216 | ntime = char2long(head.tzh_timecnt); 217 | ntype = char2long(head.tzh_typecnt); 218 | nchar = char2long(head.tzh_charcnt); 219 | 220 | for (i = 0; i < ntime; i++) { 221 | if (Xfread(buf, 4, fp) != 4) { 222 | VOID_C Xfclose(fp); 223 | return(tz); 224 | } 225 | tmp = char2long(buf); 226 | if (tmcmp(&tmbuf, localtime(&tmp)) < 0) break; 227 | } 228 | if (i > 0) { 229 | i--; 230 | i *= (int)sizeof(char); 231 | i += (int)sizeof(struct tzhead) + ntime * 4 * sizeof(char); 232 | if (Xfseek(fp, i, 0) < 0 || Xfread((char *)&c, 1, fp) != 1) { 233 | VOID_C Xfclose(fp); 234 | return(tz); 235 | } 236 | i = c; 237 | } 238 | i *= (4 + 1 + 1) * sizeof(char); 239 | i += (int)sizeof(struct tzhead) + ntime * (4 + 1) * sizeof(char); 240 | if (Xfseek(fp, i, 0) < 0 || Xfread(buf, 4, fp) != 4) { 241 | VOID_C Xfclose(fp); 242 | return(tz); 243 | } 244 | tmp = char2long(buf); 245 | tz = -tmp; 246 | 247 | i = (int)sizeof(struct tzhead) + ntime * (4 + 1) * sizeof(char) 248 | + ntype * (4 + 1 + 1) * sizeof(char) 249 | + nchar * sizeof(char); 250 | if (Xfseek(fp, i, 0) < 0) { 251 | VOID_C Xfclose(fp); 252 | return(tz); 253 | } 254 | leap = 0; 255 | for (i = 0; i < nleap; i++) { 256 | if (Xfread(buf, 4, fp) != 4) { 257 | VOID_C Xfclose(fp); 258 | return(tz); 259 | } 260 | tmp = char2long(buf); 261 | if (tmcmp(&tmbuf, localtime(&tmp)) <= 0) break; 262 | if (Xfread(buf, 4, fp) != 4) { 263 | VOID_C Xfclose(fp); 264 | return(tz); 265 | } 266 | leap = char2long(buf); 267 | } 268 | 269 | tz += leap; 270 | VOID_C Xfclose(fp); 271 | # endif /* !NOTZFILEH */ 272 | 273 | return(tz); 274 | # endif /* !MSDOS */ 275 | } 276 | #endif /* !USEMKTIME && !USETIMELOCAL */ 277 | 278 | time_t Xtimelocal(tm) 279 | struct tm *tm; 280 | { 281 | #ifdef USEMKTIME 282 | tm -> tm_isdst = -1; 283 | return(mktime(tm)); 284 | #else /* !USEMKTIME */ 285 | # ifdef USETIMELOCAL 286 | return(timelocal(tm)); 287 | # else /* !USETIMELOCAL */ 288 | time_t t; 289 | 290 | t = Xtimegm(tm); 291 | if (t == (time_t)-1) return(t); 292 | t += gettimezone(tm, t); 293 | 294 | return(t); 295 | # endif /* !USETIMELOCAL */ 296 | #endif /* !USEMKTIME */ 297 | } 298 | -------------------------------------------------------------------------------- /time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * time.h 3 | * 4 | * definitions & function prototype declarations for "time.c" 5 | */ 6 | 7 | #if (GETTODARGS == 1) 8 | #define Xgettimeofday(tv, tz) gettimeofday(tv) 9 | #else 10 | #define Xgettimeofday(tv, tz) gettimeofday(tv, tz) 11 | #endif 12 | 13 | extern time_t Xtime __P_((time_t *)); 14 | extern time_t Xtimegm __P_((CONST struct tm *)); 15 | extern time_t Xtimelocal __P_((struct tm *)); 16 | -------------------------------------------------------------------------------- /types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * types.h 3 | * 4 | * type definitions 5 | */ 6 | 7 | #include "depend.h" 8 | #include "typesize.h" 9 | #include "stream.h" 10 | #include "lsparse.h" 11 | 12 | typedef struct _strtable { 13 | u_short no; 14 | CONST char *str; 15 | } strtable; 16 | 17 | typedef struct _lockbuf_t { 18 | int fd; 19 | XFILE *fp; 20 | char *name; 21 | u_char flags; 22 | } lockbuf_t; 23 | 24 | #define LCK_FLOCK 0001 25 | #define LCK_INVALID 0002 26 | #define LCK_STREAM 0004 27 | #define LCK_MAXRETRY 32 28 | 29 | #ifdef DEP_DYNAMICLIST 30 | typedef u_short funcno_t; 31 | #else 32 | typedef u_char funcno_t; 33 | #endif 34 | 35 | typedef struct _bindtable { 36 | short key; 37 | funcno_t f_func; 38 | funcno_t d_func; 39 | } bindtable; 40 | 41 | #define FNO_NONE MAXUTYPE(funcno_t) 42 | #define FNO_SETMACRO (MAXUTYPE(funcno_t) - 1) 43 | #define ffunc(n) (bindlist[n].f_func) 44 | #define dfunc(n) (bindlist[n].d_func) 45 | #define hasdfunc(n) (dfunc(n) != FNO_NONE) 46 | 47 | typedef struct _functable { 48 | int (*func)__P_((CONST char *)); 49 | CONST char *ident; 50 | #ifdef _NOCATALOG 51 | # ifndef _NOJPNMES 52 | CONST char *hmes; 53 | # endif 54 | # ifndef _NOENGMES 55 | CONST char *hmes_eng; 56 | # endif 57 | #else /* !_NOCATALOG */ 58 | int hmes_no; 59 | #endif /* !_NOCATALOG */ 60 | u_char status; 61 | } functable; 62 | 63 | #define FN_REWRITE 0001 64 | #define FN_RELIST 0002 65 | #define FN_REWIN 0003 66 | #define FN_REWRITEMODE 0003 67 | #define FN_RESCREEN 0004 68 | #define FN_KILLSTACK 0010 69 | #define FN_ARCHIVE 0020 70 | #define FN_NOFILE 0040 71 | #define FN_RESTRICT 0100 72 | #define FN_NEEDSTATUS 0200 73 | #define rewritemode(n) ((n) & FN_REWRITEMODE) 74 | 75 | #ifndef _NOARCHIVE 76 | typedef struct _archive_t { 77 | char *ext; 78 | char *p_comm; 79 | char *u_comm; 80 | u_char flags; 81 | } archive_t; 82 | 83 | #define AF_IGNORECASE 0001 /* must be the same as LF_IGNORECASE */ 84 | #endif 85 | 86 | #ifndef _NOTREE 87 | typedef struct _treelist { 88 | char *name; 89 | int max; 90 | # ifndef NODIRLOOP 91 | dev_t dev; 92 | ino_t ino; 93 | struct _treelist *parent; 94 | # endif 95 | struct _treelist *sub; 96 | } treelist; 97 | #endif /* !_NOTREE */ 98 | 99 | typedef struct _winvartable { 100 | #ifndef _NOARCHIVE 101 | struct _winvartable *v_archduplp; 102 | char *v_archivedir; 103 | char *v_archivefile; 104 | char *v_archtmpdir; 105 | lsparse_t *v_launchp; 106 | namelist *v_arcflist; 107 | int v_maxarcf; 108 | # ifdef DEP_PSEUDOPATH 109 | int v_archdrive; 110 | # endif 111 | # ifndef _NOBROWSE 112 | lsparse_t *v_browselist; 113 | int v_browselevel; 114 | # endif 115 | #endif /* !_NOARCHIVE */ 116 | #ifndef _NOTREE 117 | char *v_treepath; 118 | #endif 119 | char *v_fullpath; 120 | char *v_lastfile; 121 | char *v_findpattern; 122 | namelist *v_filelist; 123 | int v_maxfile; 124 | int v_maxent; 125 | int v_filepos; 126 | int v_sorton; 127 | int v_dispmode; 128 | int v_fileperrow; 129 | } winvartable; 130 | 131 | extern winvartable winvar[]; 132 | #ifdef _NOSPLITWIN 133 | #define windows 1 134 | #else 135 | extern int windows; 136 | #endif 137 | #if defined (_NOSPLITWIN) && !defined (DEP_PTY) 138 | #define win 0 139 | #else 140 | extern int win; 141 | #endif 142 | #ifndef _NOARCHIVE 143 | #define archduplp (winvar[win].v_archduplp) 144 | #define archivefile (winvar[win].v_archivefile) 145 | #define archtmpdir (winvar[win].v_archtmpdir) 146 | #define launchp (winvar[win].v_launchp) 147 | #define arcflist (winvar[win].v_arcflist) 148 | #define maxarcf (winvar[win].v_maxarcf) 149 | # ifdef DEP_PSEUDOPATH 150 | # define archdrive (winvar[win].v_archdrive) 151 | # endif 152 | # ifndef _NOBROWSE 153 | # define browselist (winvar[win].v_browselist) 154 | # define browselevel (winvar[win].v_browselevel) 155 | # endif 156 | #endif /* !_NOARCHIVE */ 157 | #ifndef _NOTREE 158 | #define treepath (winvar[win].v_treepath) 159 | #endif 160 | #define lastfile (winvar[win].v_lastfile) 161 | #define findpattern (winvar[win].v_findpattern) 162 | #define filelist (winvar[win].v_filelist) 163 | #define maxfile (winvar[win].v_maxfile) 164 | #define maxent (winvar[win].v_maxent) 165 | #define filepos (winvar[win].v_filepos) 166 | #define sorton (winvar[win].v_sorton) 167 | #define dispmode (winvar[win].v_dispmode) 168 | #define FILEPERROW (winvar[win].v_fileperrow) 169 | 170 | typedef struct _macrostat { 171 | short addopt; 172 | short needburst; 173 | short needmark; 174 | u_short flags; 175 | } macrostat; 176 | 177 | #define F_NOCONFIRM 0000001 178 | #define F_ARGSET 0000002 179 | #define F_REMAIN 0000004 180 | #define F_NOEXT 0000010 181 | #define F_TOSFN 0000020 182 | #define F_ISARCH 0000040 183 | #define F_BURST 0000100 184 | #define F_MARK 0000200 185 | #define F_NOADDOPT 0000400 186 | #define F_IGNORELIST 0001000 187 | #define F_NOCOMLINE 0002000 188 | #define F_NOKANJICONV 0004000 189 | #define F_TTYIOMODE 0010000 190 | #define F_TTYNL 0020000 191 | #define F_EVALMACRO 0040000 192 | #define F_DOSYSTEM 0100000 193 | 194 | #ifndef DEP_ORIGSHELL 195 | typedef struct _aliastable { 196 | char *alias; 197 | char *comm; 198 | } aliastable; 199 | 200 | typedef struct _userfunctable { 201 | char *func; 202 | char **comm; 203 | } userfunctable; 204 | #endif /* !DEP_ORIGSHELL */ 205 | 206 | typedef struct _builtintable { 207 | int (NEAR *func)__P_((int, char *CONST [])); 208 | char *ident; 209 | } builtintable; 210 | 211 | #ifdef DEP_DYNAMICLIST 212 | typedef bindtable * bindlist_t; 213 | typedef CONST bindtable origbindlist_t[]; 214 | typedef lsparse_t * launchlist_t; 215 | typedef CONST lsparse_t origlaunchlist_t[]; 216 | typedef archive_t * archivelist_t; 217 | typedef CONST archive_t origarchivelist_t[]; 218 | typedef char ** macrolist_t; 219 | typedef char ** helpindex_t; 220 | typedef char * orighelpindex_t[]; 221 | #else 222 | typedef bindtable bindlist_t[MAXBINDTABLE]; 223 | typedef bindtable * origbindlist_t; 224 | typedef lsparse_t launchlist_t[MAXLAUNCHTABLE]; 225 | typedef lsparse_t * origlaunchlist_t; 226 | typedef archive_t archivelist_t[MAXARCHIVETABLE]; 227 | typedef archive_t * origarchivelist_t; 228 | typedef char * macrolist_t[MAXMACROTABLE]; 229 | typedef char * helpindex_t[MAXHELPINDEX]; 230 | typedef char ** orighelpindex_t; 231 | #endif 232 | 233 | #define F_SYMLINK 001 234 | #define F_FILETYPE 002 235 | #define F_DOTFILE 004 236 | #define F_FILEFLAG 010 237 | 238 | #define isdisptyp(n) ((n) & F_FILETYPE) 239 | #define ishidedot(n) ((n) & F_DOTFILE) 240 | #ifdef _NOARCHIVE 241 | #define isdisplnk(n) ((n) & F_SYMLINK) 242 | #define isfileflg(n) ((n) & F_FILEFLAG) 243 | #else 244 | #define isdisplnk(n) (!archivefile && ((n) & F_SYMLINK)) 245 | #define isfileflg(n) (!archivefile && ((n) & F_FILEFLAG)) 246 | #endif 247 | 248 | #define FNC_NONE 0 249 | #define FNC_CANCEL 1 250 | #define FNC_UPDATE 2 251 | #define FNC_HELPSPOT 3 252 | #define FNC_EFFECT 4 253 | #define FNC_QUIT (-1) 254 | #define FNC_FAIL (-2) 255 | 256 | #define ICM_BINDKEY 0 257 | #define ICM_CMDLINE 1 258 | 259 | #define FSID_UFS 1 260 | #define FSID_EFS 2 261 | #define FSID_SYSV 3 262 | #define FSID_LINUX 4 263 | #define FSID_FAT 5 264 | #define FSID_LFN 6 265 | #define FSID_DOSDRIVE 7 266 | 267 | #define CHK_OK 0 268 | #define CHK_EXIST 1 269 | #define CHK_OVERWRITE 2 270 | #define CHK_ERROR (-1) 271 | #define CHK_CANCEL (-2) 272 | 273 | #define APL_OK 0 274 | #define APL_IGNORE 1 275 | #define APL_ERROR (-1) 276 | #define APL_CANCEL (-2) 277 | 278 | #define CPP_UPDATE 1 279 | #define CPP_RENAME 2 280 | #define CPP_OVERWRITE 3 281 | #define CPP_NOCOPY 4 282 | #define CPP_FORWUPDATE 5 283 | #define CPP_FORWOVERWRITE 6 284 | 285 | #define RMP_BIAS 2 286 | #define RMP_REMOVEALL (RMP_BIAS + CHK_OK) 287 | #define RMP_KEEPALL (RMP_BIAS + CHK_ERROR) 288 | 289 | #define TCH_MODE 00001 290 | #define TCH_UID 00002 291 | #define TCH_GID 00004 292 | #define TCH_ATIME 00010 293 | #define TCH_MTIME 00020 294 | #define TCH_FLAGS 00040 295 | #define TCH_CHANGE 00100 296 | #define TCH_MASK 00200 297 | #define TCH_MODEEXE 00400 298 | #define TCH_IGNOREERR 01000 299 | 300 | #define ATR_EXCLUSIVE 3 301 | #define ATR_MODEONLY 1 302 | #define ATR_TIMEONLY 2 303 | #define ATR_OWNERONLY 3 304 | #define ATR_MULTIPLE 4 305 | #define ATR_RECURSIVE 8 306 | 307 | #define ORD_NODIR 0 308 | #define ORD_NORMAL 1 309 | #define ORD_LOWER 2 310 | #define ORD_NOPREDIR 3 311 | 312 | #define SRT_TYPE 0007 313 | #define SRT_FILENAME 0001 314 | #define SRT_EXTENSION 0002 315 | #define SRT_SIZE 0003 316 | #define SRT_DATE 0004 317 | #define SRT_LENGTH 0005 318 | #define SRT_DESC 0010 319 | 320 | #define HST_TYPE 0007 321 | #define HST_COMM 0000 322 | #define HST_PATH 0001 323 | #define HST_USER 0002 324 | #define HST_GROUP 0003 325 | #define HST_UNIQ 0010 326 | #define HST_INIT 0400 327 | #define nohist(n) ((n) != HST_COMM && (n) != HST_PATH) 328 | #define completable(n) ((n) >= 0) 329 | -------------------------------------------------------------------------------- /typesize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * typesize.h 3 | * 4 | * definitions for size of types 5 | */ 6 | 7 | #ifndef __TYPESIZE_H_ 8 | #define __TYPESIZE_H_ 9 | 10 | #define strsize(s) ((int)sizeof(s) - 1) 11 | #define arraysize(a) ((int)((u_int)sizeof(a) / (u_int)sizeof(*(a)))) 12 | 13 | #define MAXLONGWIDTH 20 /* log10(2^64) = 19.266 */ 14 | #define MAXCOLSCOMMA(d) (MAXLONGWIDTH + (MAXLONGWIDTH / (d))) 15 | #ifndef BITSPERBYTE 16 | # ifdef CHAR_BIT 17 | # define BITSPERBYTE CHAR_BIT 18 | # else /* !CHAR_BIT */ 19 | # ifdef NBBY 20 | # define BITSPERBYTE NBBY 21 | # else 22 | # define BITSPERBYTE 8 23 | # endif 24 | # endif /* !CHAR_BIT */ 25 | #endif /* !BITSPERBYTE */ 26 | 27 | #ifdef HAVELONGLONG 28 | typedef long long long_t; 29 | typedef unsigned long long u_long_t; 30 | #else 31 | typedef long long_t; 32 | typedef unsigned long u_long_t; 33 | #endif 34 | 35 | #define _MAXUTYPE(t) ((t)(~(t)0)) 36 | #define MINTYPE(t) ((t)(_MAXUTYPE(t) << \ 37 | (BITSPERBYTE * sizeof(t) - 1))) 38 | #define MAXTYPE(t) ((t)~MINTYPE(t)) 39 | #ifdef LSI_C 40 | #define MAXUTYPE(t) ((u_long_t)~0 >> \ 41 | (BITSPERBYTE * (sizeof(u_long_t) - sizeof(t)))) 42 | #else 43 | #define MAXUTYPE(t) _MAXUTYPE(t) 44 | #endif 45 | 46 | #ifdef USELLSEEK 47 | typedef long_t l_off_t; 48 | #else 49 | typedef off_t l_off_t; 50 | #endif 51 | 52 | #ifdef USEPID_T 53 | typedef pid_t p_id_t; 54 | #else /* !USEPID_T */ 55 | # if MSDOS 56 | typedef int p_id_t; 57 | # else 58 | typedef long p_id_t; 59 | # endif 60 | #endif /* !USEPID_T */ 61 | 62 | #endif /* !__TYPESIZE_H_ */ 63 | -------------------------------------------------------------------------------- /unixemu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * unixemu.h 3 | * 4 | * UNIX function emulation 5 | */ 6 | 7 | #if MSDOS && !defined (__UNIXEMU_H_) 8 | #define __UNIXEMU_H_ 9 | 10 | #ifndef DJGPP 11 | # ifndef random 12 | # define random() rand() 13 | # endif 14 | #define kill(pid, sig) ((raise(sig)) ? -1 : 0) 15 | #define SIGALRM 11 /* SIGSEGV */ 16 | #undef SIGSEGV 17 | #undef SIGTERM 18 | #undef SIGILL 19 | #endif /* !DJGPP */ 20 | 21 | typedef struct _dirdesc { 22 | int dd_id; 23 | u_short dd_fd; 24 | #if 0 25 | long dd_loc; 26 | long dd_size; 27 | long dd_bsize; 28 | #endif 29 | long dd_off; 30 | char *dd_buf; 31 | 32 | char *dd_path; 33 | } DIR; 34 | 35 | #define DID_IFNORMAL 000 36 | #define DID_IFLABEL 001 37 | #define DID_IFLFN 002 38 | 39 | struct dirent { 40 | long d_off; 41 | #ifndef _NODOSDRIVE 42 | u_long d_fileno; 43 | u_short d_reclen; 44 | #endif 45 | char d_name[MAXNAMLEN + 1]; 46 | 47 | char d_alias[14]; 48 | }; 49 | 50 | #endif /* MSDOS && !__UNIXEMU_H_ */ 51 | -------------------------------------------------------------------------------- /url.c: -------------------------------------------------------------------------------- 1 | /* 2 | * url.c 3 | * 4 | * URL parser 5 | */ 6 | 7 | #include "headers.h" 8 | #include "depend.h" 9 | #include "printf.h" 10 | #include "kctype.h" 11 | #include "typesize.h" 12 | #include "string.h" 13 | #include "malloc.h" 14 | #include "sysemu.h" 15 | #include "pathname.h" 16 | #include "url.h" 17 | 18 | #if defined (DEP_URLPATH) || defined (DEP_SOCKREDIR) 19 | 20 | static scheme_t schemelist[] = { 21 | #define DEFSCHEME(i, p, t) {i, strsize(i), p, t} 22 | DEFSCHEME(SCHEME_FTP, 21, TYPE_FTP), 23 | DEFSCHEME(SCHEME_HTTP, 80, TYPE_HTTP), 24 | {NULL, 0, 0, TYPE_UNKNOWN}, 25 | }; 26 | 27 | static CONST u_char uctypetable[256] = { 28 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* 0x00 */ 29 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, 30 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* 0x10 */ 31 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, 32 | 0001, 0000, 0001, 0040, 0000, 0001, 0000, 0000, /* 0x20 */ 33 | 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0030, 34 | 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, /* 0x30 */ 35 | 0000, 0000, 0030, 0040, 0001, 0000, 0001, 0040, 36 | 0010, 0000, 0000, 0000, 0000, 0000, 0000, 0000, /* 0x40 */ 37 | 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 38 | 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, /* 0x50 */ 39 | 0000, 0000, 0000, 0001, 0001, 0001, 0001, 0000, 40 | 0001, 0000, 0000, 0000, 0000, 0000, 0000, 0000, /* 0x60 */ 41 | 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 42 | 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, /* 0x70 */ 43 | 0000, 0000, 0000, 0001, 0001, 0001, 0000, 0001, 44 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* 0x80 */ 45 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, 46 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* 0x90 */ 47 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, 48 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* 0xa0 */ 49 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, 50 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* 0xb0 */ 51 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, 52 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* 0xc0 */ 53 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, 54 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* 0xd0 */ 55 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, 56 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* 0xe0 */ 57 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, 58 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, /* 0xf0 */ 59 | 0001, 0001, 0001, 0001, 0001, 0001, 0001, 0001, 60 | }; 61 | 62 | 63 | char *urldecode(s, len) 64 | CONST char *s; 65 | int len; 66 | { 67 | char *cp; 68 | int i, j, n, c; 69 | 70 | if (!s) return(NULL); 71 | if (len < 0) len = strlen(s); 72 | cp = Xmalloc(len + 1); 73 | 74 | for (i = j = 0; i < len; i++, j++) { 75 | if (s[i] == '%') { 76 | cp[j] = '\0'; 77 | for (n = 1; n <= 2; n++) { 78 | c = Xtolower(s[i + n]); 79 | if (Xisdigit(c)) c -= '0'; 80 | else if (Xisxdigit(c)) c -= 'a' - 10; 81 | else break; 82 | cp[j] = ((cp[j]) << 4) + c; 83 | } 84 | if (n >= 2) { 85 | i += 2; 86 | continue; 87 | } 88 | } 89 | cp[j] = s[i]; 90 | } 91 | cp[j++] = '\0'; 92 | cp = Xrealloc(cp, j); 93 | 94 | return(cp); 95 | } 96 | 97 | char *urlencode(s, len, mask) 98 | CONST char *s; 99 | int len, mask; 100 | { 101 | char *cp; 102 | int i, j; 103 | 104 | if (!s) return(NULL); 105 | if (len < 0) len = strlen(s); 106 | cp = Xmalloc(len * 3 + 1); 107 | 108 | for (i = j = 0; i < len; i++, j++) { 109 | if (uctypetable[(u_char)(s[i])] & mask) { 110 | cp[j++] = '%'; 111 | cp[j++] = Xtoupper(tohexa((s[i] >> 4) & 0xf)); 112 | cp[j] = Xtoupper(tohexa(s[i] & 0xf)); 113 | continue; 114 | } 115 | cp[j] = s[i]; 116 | } 117 | cp[j++] = '\0'; 118 | cp = Xrealloc(cp, j); 119 | 120 | return(cp); 121 | } 122 | 123 | int urlparse(s, scheme, hostp, typep, flags) 124 | CONST char *s; 125 | scheme_t *scheme; 126 | char **hostp; 127 | int *typep, flags; 128 | { 129 | CONST char *cp, *path; 130 | int i, n; 131 | 132 | /* 133 | * scheme://user:passwd@host:port/path;params?query#fragment 134 | * scheme:/path;params?query#fragment 135 | */ 136 | 137 | if (!scheme) scheme = schemelist; 138 | if (hostp) *hostp = NULL; 139 | if (typep) *typep = TYPE_NONURL; 140 | if (!s) return(-1); 141 | 142 | for (cp = s; *cp; cp++) { 143 | if (Xisalnum(*cp)) continue; 144 | if (!Xstrchr(SCHEME_SYMBOLCHAR, *cp)) break; 145 | } 146 | n = cp - s; 147 | if (cp <= s || *(cp++) != ':' || *(cp++) != '/') 148 | return((flags & UPF_ALLOWNONURL) ? 0 : -1); 149 | 150 | for (i = 0; scheme[i].ident; i++) { 151 | if (n != scheme[i].len) continue; 152 | if (!Xstrncasecmp(s, scheme[i].ident, n)) break; 153 | } 154 | if (scheme[i].ident) { 155 | if (typep) *typep = scheme[i].type; 156 | } 157 | else { 158 | if (typep) *typep = TYPE_UNKNOWN; 159 | if (!(flags & UPF_ALLOWANYSCHEME)) return(-1); 160 | } 161 | 162 | if (*cp != '/') { 163 | if (!(flags & UPF_ALLOWABSPATH)) return(-1); 164 | n = --cp - s; 165 | } 166 | else if ((path = Xstrchr(++cp, _SC_))) { 167 | if (path == cp) return(-1); 168 | if (hostp) *hostp = Xstrndup(cp, path - cp); 169 | n = path - s; 170 | } 171 | else { 172 | if (hostp) *hostp = Xstrdup(cp); 173 | n = strlen(s); 174 | } 175 | 176 | return(n); 177 | } 178 | 179 | int urlgetport(type) 180 | int type; 181 | { 182 | int i; 183 | 184 | for (i = 0; schemelist[i].ident; i++) 185 | if (type == schemelist[i].type) break; 186 | if (!(schemelist[i].ident)) return(-1); 187 | 188 | return(schemelist[i].port); 189 | } 190 | 191 | CONST char *urlgetscheme(type) 192 | int type; 193 | { 194 | int i; 195 | 196 | for (i = 0; schemelist[i].ident; i++) 197 | if (type == schemelist[i].type) break; 198 | if (!(schemelist[i].ident)) return(NULL); 199 | 200 | return(schemelist[i].ident); 201 | } 202 | 203 | int isurl(s, flags) 204 | CONST char *s; 205 | int flags; 206 | { 207 | int n; 208 | 209 | n = urlparse(s, NULL, NULL, NULL, flags); 210 | 211 | return((n > 0) ? n : 0); 212 | } 213 | 214 | VOID urlfreehost(hp) 215 | urlhost_t *hp; 216 | { 217 | if (!hp) return; 218 | 219 | Xfree(hp -> user); 220 | Xfree(hp -> pass); 221 | Xfree(hp -> host); 222 | hp -> user = hp -> pass = hp -> host = NULL; 223 | hp -> port = -1; 224 | } 225 | 226 | int urlgethost(s, hp) 227 | CONST char *s; 228 | urlhost_t *hp; 229 | { 230 | CONST char *cp, *host, *user; 231 | int i, n, len, hlen, ulen; 232 | 233 | if (!s) return(0); 234 | 235 | if ((host = Xstrchr(s, '@'))) { 236 | user = s; 237 | ulen = host++ - s; 238 | } 239 | else { 240 | ulen = 0; 241 | user = NULL; 242 | host = s; 243 | } 244 | 245 | n = 0; 246 | cp = (user) ? Xmemchr(user, ':', ulen) : NULL; 247 | if (!cp) hp -> pass = NULL; 248 | else { 249 | len = ulen - (cp - user) - 1; 250 | ulen = cp - user; 251 | if (len <= 0) hp -> pass = NULL; 252 | else if (!(hp -> pass = urldecode(++cp, len))) n = -1; 253 | } 254 | 255 | if (!(cp = Xstrchr(host, ':'))) { 256 | hlen = strlen(host); 257 | hp -> port = -1; 258 | } 259 | else { 260 | hlen = cp++ - host; 261 | if (!*cp) hp -> port = -1; 262 | else { 263 | i = 0; 264 | hp -> port = getnum(cp, &i); 265 | if (hp -> port < 0 || cp[i]) n = seterrno(EINVAL); 266 | } 267 | } 268 | 269 | if (!host || hlen <= 0) hp -> host = NULL; 270 | else if (!(hp -> host = urldecode(host, hlen))) n = -1; 271 | if (!user || ulen <= 0) hp -> user = NULL; 272 | else if (!(hp -> user = urldecode(user, ulen))) n = -1; 273 | 274 | if (n < 0) { 275 | urlfreehost(hp); 276 | return(-1); 277 | } 278 | 279 | return(0); 280 | } 281 | 282 | int urlgetpath(s, pp) 283 | CONST char *s; 284 | urlpath_t *pp; 285 | { 286 | CONST char *cp; 287 | 288 | if (!s || *s != _SC_) return(seterrno(EINVAL)); 289 | pp -> params = pp -> query = pp -> fragment = NULL; 290 | 291 | if (!(cp = strpbrk(s, ";?#"))) { 292 | pp -> path = Xstrdup(s); 293 | pp -> params = pp -> query = pp -> fragment = NULL; 294 | return(0); 295 | } 296 | pp -> path = Xstrndup(s, cp - s); 297 | s = &(cp[1]); 298 | 299 | if (*cp != ';') pp -> params = NULL; 300 | else { 301 | if (!(cp = strpbrk(s, "?#"))) { 302 | pp -> params = Xstrdup(s); 303 | pp -> query = pp -> fragment = NULL; 304 | return(0); 305 | } 306 | pp -> params = Xstrndup(s, cp - s); 307 | s = &(cp[1]); 308 | } 309 | 310 | if (*cp != '?') pp -> query = NULL; 311 | else { 312 | if (!(cp = Xstrchr(s, '#'))) { 313 | pp -> query = Xstrdup(s); 314 | pp -> fragment = NULL; 315 | return(0); 316 | } 317 | pp -> query = Xstrndup(s, cp - s); 318 | s = &(cp[1]); 319 | } 320 | 321 | if (*cp != '#') pp -> fragment = NULL; 322 | else pp -> fragment = Xstrdup(s); 323 | 324 | return(0); 325 | } 326 | #endif /* DEP_URLPATH || DEP_SOCKREDIR */ 327 | -------------------------------------------------------------------------------- /url.h: -------------------------------------------------------------------------------- 1 | /* 2 | * url.h 3 | * 4 | * definitions & function prototype declarations for "url.c" 5 | */ 6 | 7 | #ifndef __URL_H_ 8 | #define __URL_H_ 9 | 10 | #define URL_UNSAFE 0001 11 | #define URL_UNSAFEUSER 0011 12 | #define URL_UNSAFEHOST 0021 13 | #define URL_UNSAFEPATH 0041 14 | 15 | #define UPF_ALLOWNONURL 0001 16 | #define UPF_ALLOWABSPATH 0002 17 | #define UPF_ALLOWANYSCHEME 0004 18 | 19 | typedef struct _scheme_t { 20 | CONST char *ident; 21 | int len; 22 | int port; 23 | int type; 24 | } scheme_t; 25 | 26 | #define SCHEME_FTP "ftp" 27 | #define SCHEME_HTTP "http" 28 | #define SCHEME_SYMBOLCHAR "+-." /* RFC1738 */ 29 | #define TYPE_UNKNOWN 0 30 | #define TYPE_FTP 1 31 | #define TYPE_HTTP 2 32 | #define TYPE_NONURL (-1) 33 | 34 | typedef struct _urlhost_t { 35 | char *user; 36 | char *pass; 37 | char *host; 38 | int port; 39 | } urlhost_t; 40 | 41 | typedef struct _urlpath_t { 42 | char *path; 43 | char *params; 44 | char *query; 45 | char *fragment; 46 | } urlpath_t; 47 | 48 | typedef struct _url_t { 49 | char *host; 50 | char *path; 51 | int type; 52 | } url_t; 53 | 54 | #if defined (DEP_URLPATH) || defined (DEP_SOCKREDIR) 55 | extern char *urldecode __P_((CONST char *, int)); 56 | extern char *urlencode __P_((CONST char *, int, int)); 57 | extern int urlparse __P_((CONST char *, scheme_t *, char **, int *, int)); 58 | extern int urlgetport __P_((int)); 59 | extern CONST char *urlgetscheme __P_((int)); 60 | extern int isurl __P_((CONST char *, int)); 61 | extern VOID urlfreehost __P_((urlhost_t *)); 62 | extern int urlgethost __P_((CONST char *, urlhost_t *)); 63 | extern int urlgetpath __P_((CONST char *, urlpath_t *)); 64 | #endif 65 | 66 | #endif /* !__URL_H_ */ 67 | -------------------------------------------------------------------------------- /urldisk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * urldisk.h 3 | * 4 | * definitions & function prototype declarations for "urldisk.c" 5 | */ 6 | 7 | #include "dirent.h" 8 | #include "stream.h" 9 | #include "namelist.h" 10 | #include "url.h" 11 | #include "auth.h" 12 | 13 | #define URLNOFILE 16 14 | #define URLMAXCMDLINE 255 15 | #define URLENDTIMEOUT 2 16 | #define FTPANONUSER "anonymous" 17 | #define FTPANONPASS "@" 18 | #define lazyproxy(uh) (urlhostlist[uh].prototype == TYPE_HTTP \ 19 | && urlhostlist[uh].type == TYPE_FTP \ 20 | && urlhostlist[uh].http \ 21 | && !((urlhostlist[uh].http) -> server) \ 22 | && (urlhostlist[uh].http) -> version < 101) 23 | 24 | typedef struct _httpstat_t { 25 | char cwd[MAXPATHLEN]; 26 | int version; 27 | off_t clength; 28 | time_t mtim; 29 | char *server; 30 | url_t location; 31 | char *digest; 32 | int charset; 33 | int chunk; 34 | int flags; 35 | } httpstat_t; 36 | 37 | #define HFL_CLENGTH 000001 38 | #define HFL_MTIME 000002 39 | #define HFL_LOCATION 000004 40 | #define HFL_DISCONNECT 000010 41 | #define HFL_AUTHED 000020 42 | #define HFL_PROXYAUTHED 000040 43 | #define HFL_CHUNKED 000100 44 | #define HFL_OTHERHOST 000200 45 | #define HFL_BODYLESS 000400 46 | 47 | typedef struct _urldev_t { 48 | XFILE *fp; 49 | urlhost_t host; 50 | urlhost_t proxy; 51 | int type; 52 | int prototype; 53 | #ifdef DEP_HTTPPATH 54 | httpstat_t *http; 55 | char *redirect; 56 | #endif 57 | int nlink; 58 | int options; 59 | int flags; 60 | } urldev_t; 61 | 62 | #define UOP_NOPASV 000001 63 | #define UOP_NOPORT 000002 64 | #define UOP_NOMDTM 000004 65 | #define UOP_NOFEAT 000010 66 | #define UOP_FULLSTAT 000020 67 | #define UOP_NOLISTOPT 000040 68 | #define UOP_USENLST 000100 69 | #define UOP_NOSIZE 000200 70 | #define UFL_LOCKED 000001 71 | #define UFL_INTRED 000002 72 | #define UFL_CLOSED 000004 73 | #define UFL_PROXIED 000010 74 | #define UFL_RETRYPASV 000100 75 | #define UFL_RETRYPORT 000200 76 | #define UFL_FIXLISTOPT 000400 77 | 78 | typedef struct _urlstat_t { 79 | namelist *list; 80 | int max; 81 | int uh; 82 | int nlink; 83 | char *path; 84 | int flags; 85 | } urlstat_t; 86 | 87 | #define UFL_FULLLIST 000001 88 | 89 | #define UGP_SCHEME 000001 90 | #define UGP_USER 000002 91 | #define UGP_PASS 000004 92 | #define UGP_HOST 000010 93 | #define UGP_CWD 000020 94 | #define UGP_ANON 000100 95 | #define UGP_ENCODE 000200 96 | 97 | extern VOID urlfreestatlist __P_((int)); 98 | extern int urlferror __P_((XFILE *)); 99 | extern int urlgetreply __P_((int, char **)); 100 | extern int urlcommand __P_((int, char **, int, ...)); 101 | extern int urlnewstatlist __P_((int, namelist *, int, CONST char *)); 102 | extern int urlrecvlist __P_((int *, CONST char *, int)); 103 | extern CONST char *urlsplitpath __P_((char *, ALLOC_T, CONST char *)); 104 | extern int urlrecvstatus __P_((int *, CONST char *, namelist *, int *, int)); 105 | extern int urltracelink __P_((int *, CONST char *, namelist *, int *)); 106 | extern int urlreconnect __P_((int)); 107 | extern int urlopendev __P_((CONST char *, int)); 108 | extern VOID urlclosedev __P_((int)); 109 | extern int urlgenpath __P_((int, char *, ALLOC_T, int)); 110 | extern int urlchdir __P_((int, CONST char *)); 111 | extern char *urlgetcwd __P_((int, char *, ALLOC_T)); 112 | extern DIR *urlopendir __P_((CONST char *, int, CONST char *)); 113 | extern int urlclosedir __P_((DIR *)); 114 | extern struct dirent *urlreaddir __P_((DIR *)); 115 | extern VOID urlrewinddir __P_((DIR *)); 116 | extern int urlstat __P_((CONST char *, int, CONST char *, struct stat *)); 117 | extern int urllstat __P_((CONST char *, int, CONST char *, struct stat *)); 118 | extern int urlaccess __P_((CONST char *, int, CONST char *, int)); 119 | extern int urlreadlink __P_((CONST char *, int, CONST char *, char *, int)); 120 | extern int urlchmod __P_((CONST char *, int, CONST char *, int)); 121 | extern int urlunlink __P_((CONST char *, int, CONST char *)); 122 | extern int urlrename __P_((CONST char *, int, CONST char *, CONST char *)); 123 | extern VOID urlputopenlist __P_((int, int, CONST char *, int)); 124 | extern int urldelopenlist __P_((int)); 125 | extern int urlopen __P_((CONST char *, int, CONST char *, int)); 126 | extern int urlclose __P_((int)); 127 | extern int urlfstat __P_((int, struct stat *)); 128 | extern int urlselect __P_((int)); 129 | extern int urlread __P_((int, char *, int)); 130 | extern int urlwrite __P_((int, CONST char *, int)); 131 | extern int urldup2 __P_((int, int)); 132 | extern int urlmkdir __P_((CONST char *, int, CONST char *)); 133 | extern int urlrmdir __P_((CONST char *, int, CONST char *)); 134 | extern int urlallclose __P_((VOID_A)); 135 | #ifdef DEP_FTPPATH 136 | extern int ftpgetreply __P_((XFILE *, char **)); 137 | extern int ftpseterrno __P_((int)); 138 | extern int vftpcommand __P_((int, char **, int, va_list)); 139 | extern int ftpquit __P_((int)); 140 | extern int ftpabort __P_((int)); 141 | extern int ftplogin __P_((int)); 142 | extern int ftprecvlist __P_((int, CONST char *, namelist **)); 143 | extern int ftprecvstatus __P_((int, CONST char *, namelist *, int, int)); 144 | extern int ftpchdir __P_((int, CONST char *)); 145 | extern char *ftpgetcwd __P_((int, char *, ALLOC_T)); 146 | extern int ftpchmod __P_((int, CONST char *, int)); 147 | extern int ftpunlink __P_((int, CONST char *)); 148 | extern int ftprename __P_((int, CONST char *, CONST char *)); 149 | extern int ftpopen __P_((int, CONST char *, int)); 150 | extern int ftpclose __P_((int, int)); 151 | extern int ftpfstat __P_((int, struct stat *)); 152 | extern int ftpread __P_((int, int, char *, int)); 153 | extern int ftpwrite __P_((int, int, CONST char *, int)); 154 | extern int ftpmkdir __P_((int, CONST char *)); 155 | extern int ftprmdir __P_((int, CONST char *)); 156 | #endif /* DEP_FTPPATH */ 157 | #ifdef DEP_HTTPPATH 158 | extern VOID httpreset __P_((int, int)); 159 | extern int httpgetreply __P_((int, char **)); 160 | extern int httpseterrno __P_((int)); 161 | extern int vhttpcommand __P_((int, char **, int, va_list)); 162 | extern int httprecvlist __P_((int, CONST char *, namelist **)); 163 | extern int httprecvstatus __P_((int, CONST char *, namelist *, int, int *)); 164 | extern int httpchdir __P_((int, CONST char *)); 165 | extern char *httpgetcwd __P_((int, char *, ALLOC_T)); 166 | extern int httpchmod __P_((int, CONST char *, int)); 167 | extern int httpunlink __P_((int, CONST char *)); 168 | extern int httprename __P_((int, CONST char *, CONST char *)); 169 | extern int httpopen __P_((int, CONST char *, int)); 170 | extern int httpclose __P_((int, int)); 171 | extern int httpfstat __P_((int, struct stat *)); 172 | extern int httpread __P_((int, int, char *, int)); 173 | extern int httpwrite __P_((int, int, CONST char *, int)); 174 | extern int httpmkdir __P_((int, CONST char *)); 175 | extern int httprmdir __P_((int, CONST char *)); 176 | extern int httpreopen __P_((int, int)); 177 | extern int httprerecvlist __P_((int *, namelist **)); 178 | extern int httprerecvstatus __P_((int *, namelist *, int *)); 179 | #endif /* DEP_HTTPPATH */ 180 | 181 | extern int urloptions; 182 | extern int urltimeout; 183 | extern int urlkcode; 184 | extern urldev_t urlhostlist[]; 185 | extern int maxurlhost; 186 | extern urlstat_t *urlstatlist; 187 | extern int maxurlstat; 188 | extern char *logheader; 189 | #ifdef DEP_FTPPATH 190 | extern char *ftpaddress; 191 | extern char *ftpproxy; 192 | extern char *ftplogfile; 193 | #endif 194 | #ifdef DEP_HTTPPATH 195 | extern char *httpproxy; 196 | extern char *httplogfile; 197 | extern char *htmllogfile; 198 | #endif 199 | -------------------------------------------------------------------------------- /version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * version.h 3 | * 4 | * version number 5 | */ 6 | 7 | char *distributor = NULL; 8 | static char version[] = "@(#)fd.c 3.01a 06/08/13"; 9 | -------------------------------------------------------------------------------- /wait.h: -------------------------------------------------------------------------------- 1 | /* 2 | * wait.h 3 | * 4 | * definitions for waiting child 5 | */ 6 | 7 | #ifndef __WAIT_H_ 8 | #define __WAIT_H_ 9 | 10 | #include "unixemu.h" 11 | 12 | #if !MSDOS 13 | #include 14 | #endif 15 | 16 | #ifdef USESIGPMASK 17 | #define sigmask_t sigset_t 18 | #define Xsigemptyset(m) sigemptyset(&m) 19 | #define Xsigfillset(m) sigfillset(&m) 20 | #define Xsigaddset(m, s) sigaddset(&m, s) 21 | #define Xsigdelset(m, s) sigdelset(&m, s) 22 | #define Xsigsetmask(m) sigprocmask(SIG_SETMASK, &m, NULL) 23 | #define Xsigblock(o, m) sigprocmask(SIG_BLOCK, &m, &o) 24 | #else /* !USESIGPMASK */ 25 | typedef int sigmask_t; 26 | #define Xsigemptyset(m) ((m) = 0) 27 | #define Xsigfillset(m) ((m) = ~0) 28 | #define Xsigaddset(m, s) ((m) |= sigmask(s)) 29 | #define Xsigdelset(m, s) ((m) &= ~sigmask(s)) 30 | #define Xsigsetmask(m) sigsetmask(m) 31 | #define Xsigblock(o, m) ((o) = sigblock(m)) 32 | #endif /* !USESIGPMASK */ 33 | 34 | #ifdef NOKILLPG 35 | #define Xkillpg(p, s) kill(-(p), s) 36 | #else 37 | #define Xkillpg(p, s) killpg(p, s) 38 | #endif 39 | 40 | #ifdef USEWAITPID 41 | typedef int wait_pid_t; 42 | #else 43 | #define wait_pid_t union wait 44 | #endif 45 | 46 | #ifndef WSTOPPED 47 | #define WSTOPPED 0177 48 | #endif 49 | #ifndef WNOHANG 50 | #define WNOHANG 1 51 | #endif 52 | #ifndef WUNTRACED 53 | #define WUNTRACED 2 54 | #endif 55 | 56 | #ifdef USEWAITPID 57 | #define Xwait3(wp, opts, ru) waitpid(-1, wp, opts) 58 | #define Xwait4(p, wp, opts, ru) waitpid(p, wp, opts) 59 | # ifndef WIFSTOPPED 60 | # define WIFSTOPPED(x) (((x) & 0177) == WSTOPPED) 61 | # endif 62 | # ifndef WIFSIGNALED 63 | # define WIFSIGNALED(x) (((x) & 0177) != WSTOPPED \ 64 | && ((x) & 0177) != 0) 65 | # endif 66 | # ifndef WIFEXITED 67 | # define WIFEXITED(x) (((x) & 0177) == 0) 68 | # endif 69 | # ifndef WCOREDUMP 70 | # define WCOREDUMP(x) ((x) & 0200) 71 | # endif 72 | # ifndef WSTOPSIG 73 | # define WSTOPSIG(x) (((x) >> 8) & 0177) 74 | # endif 75 | # ifndef WTERMSIG 76 | # define WTERMSIG(x) ((x) & 0177) 77 | # endif 78 | # ifndef WEXITSTATUS 79 | # define WEXITSTATUS(x) (((x) >> 8) & 0377) 80 | # endif 81 | #else /* !USEWAITPID */ 82 | #define Xwait3 wait3 83 | #define Xwait4 wait4 84 | # ifndef WIFSTOPPED 85 | # define WIFSTOPPED(x) ((x).w_stopval == WSTOPPED) 86 | # endif 87 | # ifndef WIFSIGNALED 88 | # define WIFSIGNALED(x) ((x).w_stopval != WSTOPPED \ 89 | && (x).w_termsig != 0) 90 | # endif 91 | # ifndef WIFEXITED 92 | # define WIFEXITED(x) ((x).w_stopval != WSTOPPED \ 93 | && (x).w_termsig == 0) 94 | # endif 95 | # ifndef WCOREDUMP 96 | # define WCOREDUMP(x) ((x).w_coredump) 97 | # endif 98 | # ifndef WSTOPSIG 99 | # define WSTOPSIG(x) ((x).w_stopsig) 100 | # endif 101 | # ifndef WTERMSIG 102 | # define WTERMSIG(x) ((x).w_termsig) 103 | # endif 104 | # ifndef WEXITSTATUS 105 | # define WEXITSTATUS(x) ((x).w_retcode) 106 | # endif 107 | #endif /* !USEWAITPID */ 108 | 109 | #ifndef NSIG 110 | # ifdef _NSIG 111 | # define NSIG _NSIG 112 | # else 113 | # ifdef DJGPP 114 | # define NSIG 301 115 | # else 116 | # define NSIG 64 117 | # endif 118 | # endif 119 | #endif 120 | 121 | #ifndef SIG_ERR 122 | #define SIG_ERR ((sigcst_t)-1) 123 | #endif 124 | #ifndef SIG_DFL 125 | #define SIG_DFL ((sigcst_t)0) 126 | #endif 127 | #ifndef SIG_IGN 128 | #define SIG_IGN ((sigcst_t)1) 129 | #endif 130 | #if !defined (SIGIOT) && defined (SIGABRT) 131 | #define SIGIOT SIGABRT 132 | #endif 133 | #if !defined (SIGCHLD) && defined (SIGCLD) 134 | #define SIGCHLD SIGCLD 135 | #endif 136 | #if !defined (SIGWINCH) && defined (SIGWINDOW) 137 | #define SIGWINCH SIGWINDOW 138 | #endif 139 | 140 | #ifdef FD 141 | # ifdef SIGALRM 142 | extern int noalrm; 143 | # define sigalrm(sig) ((!noalrm && (sig)) ? SIGALRM : 0) 144 | # else 145 | # define sigalrm(sig) 0 146 | # endif 147 | #endif /* FD */ 148 | 149 | #endif /* !__WAIT_H_ */ 150 | --------------------------------------------------------------------------------