├── BugList.html ├── Change.html ├── LICENCE ├── Link2EiC.README ├── Makefile ├── README ├── README.FIRST ├── config ├── Makefile ├── NormalNodeTargets ├── _LINUX │ └── make.params ├── _SOLARIS │ └── make.params ├── alignment.c ├── genstdio.c ├── make.rules └── makeconfig ├── doc ├── EiC.tex ├── EiCgram.tex ├── FigPageSetup.tex ├── Intro2EiC.tex ├── Library.tex ├── Makefile ├── advanced.tex ├── computer.bib ├── eicpreamble.tex ├── embed.tex ├── grammar.tex ├── headers ├── miniblurb.tex ├── preface.tex ├── preproc.tex ├── tech_doc │ ├── CommandSeq1 │ ├── LL1 │ ├── builtin.doc │ ├── comments │ ├── instructionSet.doc │ ├── modification.notes │ ├── runtime.txt │ ├── src_cutter.c │ └── typesets.doc └── test.tex ├── eic.man ├── eim.man ├── main ├── Makefile ├── README ├── examples │ ├── embedEiC.c │ └── myfile.c └── main.c ├── module ├── Makefile ├── MathStats │ ├── Makefile │ ├── combinatorial.c │ ├── harray.c │ ├── interpolate.c │ ├── mathstats.h │ ├── randg.c │ └── stats.c ├── gnuplot │ ├── Makefile │ ├── README.html │ ├── demo.c │ ├── gplot.h │ └── gplot3.c ├── link2eic │ ├── Makefile │ ├── link2eic.c │ └── link2eic.h └── stdClib │ ├── Makefile │ └── src │ ├── Makefile │ ├── _LINUX │ ├── dirent.h │ ├── fcntl.h │ ├── ioctl.h │ ├── stat.h │ ├── termios.h │ └── time.h │ ├── _SOLARIS │ ├── dirent.h │ ├── fcntl.h │ ├── ioctl.h │ ├── stat.h │ ├── termios.h │ └── time.h │ ├── assert.c │ ├── assert.h │ ├── ctype.c │ ├── ctype.h │ ├── dirent.c │ ├── dirent.h │ ├── eicfftoa.c │ ├── errno.c │ ├── errno.h │ ├── fcntl.c │ ├── float.h │ ├── iso646.h │ ├── itoa.c │ ├── math.c │ ├── math.h │ ├── printf.c │ ├── setjmp.h │ ├── signal.c │ ├── stat.c │ ├── stdClib.c │ ├── stdClib2eic.h │ ├── stdarg.c │ ├── stdarg.h │ ├── stddef.h │ ├── stdio.c │ ├── stdio.h │ ├── stdlib.c │ ├── stdlib.h │ ├── stdliblocal.h │ ├── string.c │ ├── string.h │ ├── strrev.c │ ├── strround.c │ ├── termios.c │ ├── termios.h │ ├── time.c │ ├── time.h │ ├── unistd.c │ └── unistd.h ├── new_main ├── Makefile ├── examples │ └── test-datatypes.c ├── link2eic.c ├── link2eic.h ├── main.c └── volatile.dat ├── override.params ├── project.params ├── src ├── MachSet.h ├── Makefile ├── assertp.h ├── callback.c ├── cdecl.c ├── cdecl.h ├── datastruct.h ├── eic.h ├── eicmod.c ├── eicval.h ├── emitter.c ├── emitter.h ├── error.c ├── error.h ├── func.c ├── func.h ├── global.h ├── interpre.c ├── lexer.c ├── lexer.h ├── main.c ├── metric.h ├── modules.h ├── optomizer.c ├── parser.c ├── parser.h ├── preexpr.c ├── preproc.c ├── preproc.h ├── readline.c ├── reset.c ├── reset.h ├── stab.c ├── stab.h ├── starteic.c ├── starteic.src ├── symbol.c ├── symbol.h ├── symentry.h ├── typemod.c ├── typemod.h ├── typesets.c ├── typesets.h ├── xalloc.h └── ymem.c └── test ├── EiCtests ├── gethashwords.c ├── testAassert.c ├── testAbinary.c ├── testMemErr1.aux ├── testMemErr1.c ├── testMemErr2.aux ├── testMemErr2.c ├── testMemErr2b.aux ├── testMemErr2c.aux ├── testaddressop.c ├── testarray.c ├── testarray2.c ├── testarray3.c ├── testarray4.c ├── testaryptr.c ├── testassign.c ├── testcast.c ├── testcomma.c ├── testcommandline.aux ├── testcommandline.c ├── testcompliant.c ├── testcond.c ├── testconst.c ├── testctype.c ├── testdeclerr.c ├── testeic.c ├── testenum.c ├── testerr.c ├── testerr1.c ├── testerr3.c ├── testerrno.c ├── testescape.c ├── testexit.c ├── testexit1.aux ├── testexit2.aux ├── testexit3.aux ├── testextern.c ├── testfloat.c ├── testfloat2.c ├── testflow.c ├── testflow2.c ├── testflow3.c ├── testfunc.c ├── testfuncptr.c ├── testgotos.c ├── testieee.c ├── testinclude.c ├── testinclude2.aux ├── testinclude2.c ├── testinclude2a.aux ├── testinit1.c ├── testinit2.c ├── testlexer.c ├── testlexerr.c ├── testlimits.c ├── testlimits2.c ├── testllong.c ├── testlogi.c ├── testparserr.c ├── testplot.c ├── testpopen.c ├── testpp2.c ├── testpp3.c ├── testpreperr.c ├── testpreproc.c ├── testprintf.c ├── testptr.c ├── testqsort.c ├── testreturn.c ├── testsafeptr.c ├── testscanf.c ├── testscanf2.c ├── testscanf3.aux ├── testscanf3.c ├── testsclass.c ├── testsclass1.aux ├── testscop.c ├── testsetjmp.c ├── testshow.c ├── testsign.c ├── testsignal.c ├── testsizeof.c ├── teststatic.c ├── teststatic1.aux ├── teststatic2.aux ├── teststatic3.aux ├── teststatic4.aux ├── teststdio.c ├── teststmt.c ├── teststring.c ├── teststru.c ├── teststru2.c ├── teststru3.c ├── testtime.c ├── testtrace.c ├── testtypedef.c ├── testtypeerr.c ├── testtypes.c ├── testtypes2.c ├── testunsafeptr1.c ├── testunsafeptr2.aux ├── testunsafeptr2.c ├── testunsafeptr3.aux ├── testunsafeptr3.c ├── testunsafeptr4.aux ├── testunsafeptr4.c └── testva.c ├── Makefile ├── eicScripts ├── Driver.c ├── script1.eic ├── script2.eic └── www_eic.eic ├── gnutests ├── forgnuport.h ├── gnu1.c ├── gnu11.c ├── gnu12.c ├── gnu14.c ├── gnu15.c ├── gnu16.c ├── gnu17.c ├── gnu18.c ├── gnu21.c ├── gnu23.c ├── gnu24.c ├── gnu26.c ├── gnu28.c ├── gnu29.c ├── gnu3.c ├── gnu30.c ├── gnu4.c ├── gnu6.c ├── gnu7.c ├── gnu8.c ├── t1.c ├── t2.c ├── t3.c ├── t4.c ├── t5.c ├── testcbrt.c ├── testconvert.c ├── testdiv1.c ├── testgofast.c ├── tststruct-big.c ├── tststruct-layout.c ├── tststruct-ret-1.c └── tststructret.c ├── lcctests ├── stdarg.c ├── struct.c ├── tst8q.c ├── tstarray.c ├── tstcq.c ├── tstcvt.c ├── tstinit.c ├── tstsort.c ├── tststruct.c ├── tstswitch.c ├── tstw.aux └── tstw.c ├── posix.1 ├── access.c ├── changemod.c ├── fileflags.c ├── filelock.c ├── filetype.c ├── hole.c ├── lockreg.c ├── locktest.c ├── mycat.c ├── ourhdr.h ├── seek.c ├── tst1.c ├── tstdirent.c ├── tstfile.c ├── tstfilelock.c ├── tstlock.c └── unlink.c ├── runtest ├── sniptests ├── README ├── amalloc.c ├── ansiflen.c ├── arccrc16.c ├── bcdd.c ├── bcdl.c ├── bincomp.c ├── bitcnt_1.c ├── bitcnt_2.c ├── bitcnt_3.c ├── bitcnt_4.c ├── bitfiles.c ├── bitfiles.cc ├── bitops.h ├── bitstrng.c ├── bodymass.c ├── bstr_i.c ├── c_cmnt.c ├── ccard.c ├── ccard.h ├── ccardplv.h ├── checksum.c ├── combin.c ├── crc.h ├── crc_16f.c ├── crc_32.c ├── cubic.c ├── datetime.h ├── daynum.c ├── dbl2long.c ├── dblround.c ├── dow.c ├── easter.c ├── eng.c ├── err_exit.c ├── errors.h ├── etphi.c ├── extkword.h ├── factoryl.c ├── fcompare.c ├── fibo.c ├── filnames.h ├── fmtmoney.c ├── fraction.c ├── hash.c ├── hash.h ├── head.c ├── ipow.c ├── ispow2.c ├── isqrt.c ├── jdn_l.c ├── l2roman.c ├── logscale.c ├── match.c ├── match.h ├── mathstat.c ├── mathstat.h ├── maxline.c ├── memmem.c ├── minmax.h ├── moon_age.c ├── parity.c ├── parity.h ├── parstime.c ├── pbmsrch.c ├── phonetic.h ├── pi.h ├── rad2deg.c ├── rand1.c ├── rdxcnvrt.c ├── regit.c ├── regkey.h ├── remtab.c ├── rg_rand.c ├── rnd_div.c ├── roman2l.c ├── round.h ├── ruleline.c ├── scaldate.c ├── scaldate.h ├── skiplist.c ├── snip1.c ├── snip2.c ├── snip3.c ├── snip4.c ├── snip5.c ├── snip6.c ├── snip7.c ├── snip8.c ├── snip9.c ├── snip_str.h ├── snipfile.h ├── snipmath.h ├── sniptype.h ├── snparray.h ├── soundex.c ├── spigot.c ├── sstrdel.c ├── stptok.c ├── strdel.c ├── strdelch.c ├── strdup.c ├── stristr.c ├── strrev.c ├── strrpbrk.c ├── strupr.c ├── tiresize.c ├── trim.c ├── vfname.c ├── vfname.h ├── w_wrap.c └── w_wrap.h ├── test.sh └── testcode ├── tarray.c ├── tarray2.c ├── tbool.c ├── tcast.c ├── tdouble.c ├── tdouble2.c ├── terror1.c ├── tfloat.c ├── tfunc.c ├── tfunc2.c ├── tfunc3.c ├── tfunc4.c ├── tinc.c ├── tinit.c ├── tlv.c ├── top.c ├── top2.c ├── tptr.c ├── tsizeof.c └── tstruct.c /config/Makefile: -------------------------------------------------------------------------------- 1 | ############################ 2 | # Part 1: LOCAL DEFINITIONS 3 | 4 | TOP = .. 5 | INCLUDES = 6 | DEFINES = 7 | LIBS = 8 | 9 | ############################# 10 | # Part 2: COMMON MAKE PARAMETERS 11 | 12 | include $(TOP)/make.proj 13 | 14 | ############################# 15 | # Part 3: LOCAL SOURCES 16 | 17 | 18 | HEADER_DIR=$(TOP)/include 19 | 20 | SYS_HEADERS = stdio.h stdlib.h errno.h\ 21 | stdtypes.h float.h termdefs.h\ 22 | types.h 23 | 24 | 25 | HEADERS = signal.h limits.h fcntl.h 26 | 27 | 28 | ############################## 29 | # Part 4: LOCAL TARGETS 30 | 31 | lib: 32 | 33 | #### CHANGE 34 | 35 | genstdio: genstdio.c 36 | $(CC) $(CFLAGS) -o $@ $@.c $(LIBDIRS) $(LIBS) 37 | 38 | all:: 39 | headers:: genstdio 40 | ./genstdio 41 | @for i in $(HEADERS) ;\ 42 | do \ 43 | $(MV) ./$$i $(HEADER_DIR) ;\ 44 | done 45 | @for i in $(SYS_HEADERS) ;\ 46 | do \ 47 | $(MV) ./$$i $(HEADER_DIR)/sys ;\ 48 | done 49 | $(DUMMY_TARGET) 50 | 51 | 52 | clobber:: 53 | $(RM) headers 54 | 55 | install:: 56 | clobber:: 57 | $(RM) ./genstdio 58 | @for i in $(HEADERS) ;\ 59 | do \ 60 | $(RM) $(HEADER_DIR)/$$i ;\ 61 | done 62 | @for i in $(SYS_HEADERS) ;\ 63 | do \ 64 | $(RM) $(HEADER_DIR)/sys/$$i ;\ 65 | done 66 | $(RM) $< 67 | 68 | clean:: 69 | 70 | 71 | 72 | ############################# 73 | # Part 5: COMMON RULES and 74 | # and default Targets 75 | 76 | include $(CONFIG_DIR)/make.rules 77 | 78 | ############################# 79 | # Part 6: DEPENDENCIES 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /config/NormalNodeTargets: -------------------------------------------------------------------------------- 1 | showSRCS:: 2 | echo "NormalNodeTargets showSRCS" 3 | @for i in $(DIRS); do \ 4 | (cd $$i ; \ 5 | $(MAKE) showSRCS) ;\ 6 | done 7 | 8 | all:: 9 | echo "NormalNodeTargets all" 10 | @for i in $(DIRS); do \ 11 | (cd $$i ; \ 12 | $(MAKE) all) ;\ 13 | done 14 | 15 | clean:: 16 | echo "NormalNodeTargets clean" 17 | @for i in $(DIRS); do \ 18 | (cd $$i ; \ 19 | $(MAKE) clean) ;\ 20 | done 21 | 22 | install:: 23 | echo "NormalNodeTargets install" 24 | @for i in $(DIRS); do \ 25 | (cd $$i ; \ 26 | $(MAKE) install) ;\ 27 | done 28 | 29 | clobber:: 30 | echo "NormalNodeTargets clobber" 31 | @for i in $(DIRS); do \ 32 | (cd $$i ; \ 33 | $(MAKE) clobber) ;\ 34 | done 35 | 36 | headers:: 37 | echo "NormalNodeTargets headers" 38 | @for i in $(DIRS); do \ 39 | (cd $$i ; \ 40 | $(MAKE) headers) ;\ 41 | done 42 | -------------------------------------------------------------------------------- /config/_LINUX/make.params: -------------------------------------------------------------------------------- 1 | PLATFORM = _LINUX 2 | CC = gcc 3 | STD_CFLAGS = -ansi -pedantic -O2 -fsigned-char -Wall 4 | INCLUDE_FLAGS = -I- 5 | 6 | AR = ar 7 | ARFLAGS = -rv 8 | RM = rm -f 9 | INSTALL = mv 10 | MV = mv 11 | COPY = cp 12 | MAKE = make 13 | MKDIR = mkdir 14 | MKDIRFLAGS = -p 15 | RANLIB = ranlib 16 | RUNLIBCMD = $(RANLIB) $@ 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /config/_SOLARIS/make.params: -------------------------------------------------------------------------------- 1 | PLATFORM = _SOLARIS 2 | CC = gcc 3 | STD_CFLAGS = -ansi -pedantic -O2 -fsigned-char -Wall 4 | INCLUDE_FLAGS = -I- 5 | 6 | AR = ar 7 | ARFLAGS = -rv 8 | RM = rm -f 9 | INSTALL = mv 10 | MV = mv 11 | COPY = cp 12 | MAKE = gmake 13 | MKDIR = mkdir 14 | MKDIRFLAGS = -p 15 | RANLIB = 16 | RUNLIBCMD = 17 | -------------------------------------------------------------------------------- /config/make.rules: -------------------------------------------------------------------------------- 1 | all:: 2 | headers:: 3 | clean:: 4 | $(RM) core *~ 5 | 6 | clobber::clean 7 | 8 | .c.o: 9 | $(CC) $(CFLAGS) -c $< 10 | 11 | 12 | .c.a: 13 | $(CC) $(CFLAGS) -c $< 14 | $(AR) $(ARFLAGS) $@ $*.o 15 | $(RM) $*.o 16 | 17 | showdep: 18 | @for i in $(SRCS) ; \ 19 | do \ 20 | $(CC) -c -MM $(CFLAGS) $$i ; \ 21 | done 22 | showAlldep: 23 | @for i in $(SRCS) ; \ 24 | do \ 25 | $(CC) -c -M $(CFLAGS) $$i ; \ 26 | done 27 | 28 | 29 | showSRCS:: 30 | @for i in $(SRCS) ; \ 31 | do \ 32 | echo $$i ; \ 33 | done 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /doc/EiC.tex: -------------------------------------------------------------------------------- 1 | \documentclass[12pt]{book} 2 | \usepackage{float,moreverb,xspace,makeidx,apalike,epsfig} 3 | 4 | \makeindex 5 | 6 | 7 | \include{eicpreamble} 8 | 9 | \title{Extensible Interactive C } 10 | \author{Edmond J. Breen} 11 | 12 | \includeonly{% 13 | ,FigPageSetup% 14 | ,preface% 15 | ,Intro2EiC% 16 | ,preproc% 17 | ,grammar% 18 | ,Library% 19 | ,advanced% 20 | ,EiCgram% 21 | } 22 | 23 | \begin{document} 24 | 25 | \maketitle 26 | 27 | \frontmatter 28 | 29 | \tableofcontents 30 | \include{FigPageSetup} 31 | \include{preface} 32 | 33 | \mainmatter 34 | 35 | \include{Intro2EiC} 36 | \include{preproc} 37 | \include{grammar} 38 | \include{Library} 39 | \include{advanced} 40 | 41 | \appendix 42 | 43 | \include{EiCgram} 44 | 45 | \bibliographystyle{apalike} 46 | \bibliography{computer} 47 | 48 | 49 | \section*{On line documentation and C sources} 50 | \begin{itemize} 51 | \item Steve Summit's Introductory C course: \\ 52 | \verb+http://www.eskimo.com/~scs/cclass/cclass.html+ 53 | \item Martin Leslie's Online C Language Reference:\\ 54 | \verb+http://users.southeast.net/~garyg/C_ref/C/c.html+ 55 | \item Ross Richardson's The C Standard Library:\\ 56 | \verb+http://www.infosys.utas.edu.au/info/documentation/C/CStdLib.html+ 57 | \item comp.lang.c Frequently Asked Questions:\\ 58 | \verb+http://www.eskimo.com/~scs/C-faq/top.html+ 59 | \item Other Sources, C, Related Languages, Programming Languages:\\ 60 | \verb+http://www.lysator.liu.se/c/c-www.html+ 61 | \end{itemize} 62 | 63 | \printindex 64 | \end{document} 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /doc/FigPageSetup.tex: -------------------------------------------------------------------------------- 1 | \setlength{\floatsep}{5pt plus 2pt minus 2pt} 2 | \setlength{\dblfloatsep}{5pt plus 2pt minus 2pt} 3 | \setlength{\textfloatsep}{5pt plus 2pt minus 2pt} 4 | \setlength{\dbltextfloatsep}{5pt plus 2pt minus 2pt} 5 | \renewcommand{\textfraction}{0} 6 | \renewcommand{\floatpagefraction}{1} 7 | \renewcommand{\dblfloatpagefraction}{1} 8 | \renewcommand{\topfraction}{1} 9 | \renewcommand{\bottomfraction}{1} 10 | \renewcommand{\dbltopfraction}{1} 11 | \setcounter{totalnumber}{5} 12 | \setcounter{topnumber}{5} 13 | \setcounter{dbltopnumber}{5} 14 | 15 | 16 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | ######################### 2 | # Part 1: LOCAL DEFINITIONS 3 | 4 | TOP = .. 5 | EXTRA = 6 | WARNINGS = 7 | INCLUDES = 8 | LIB = 9 | 10 | DEP_LIBS = 11 | LIBS = 12 | 13 | ######################### 14 | # Part 2: COMMON MAKE PARAMETERS 15 | 16 | include $(TOP)/make.proj 17 | 18 | ######################### 19 | # Part 3: LOCAL SOURCES 20 | 21 | ######################### 22 | # Part 4: LOCAL TARGETS 23 | 24 | 25 | #### make EiC.tex 26 | 27 | TexFiles = EiC.tex FigPageSetup.tex Library.tex preface.tex\ 28 | EiCgram.tex Intro2EiC.tex grammar.tex preproc.tex 29 | 30 | all:: 31 | 32 | EiC.dvi: $(TexFiles) 33 | latex EiC 34 | makeindex EiC.idx 35 | bibtex EiC 36 | latex EiC 37 | latex EiC 38 | dvips -o EiC.ps EiC 39 | 40 | 41 | install::EiC.dvi 42 | $(DUMMY_TARGET) 43 | 44 | clean:: 45 | find . -name "*~" | xargs $(RM) 46 | $(RM) *.aux *.dvi *.ind *.ilg *.blg *.bbl *.log *.idx *.toc 47 | $(RM) *.ps 48 | 49 | clobber::clean 50 | rm -f install 51 | 52 | ####### HEADERS 53 | headers:: 54 | 55 | ######################### 56 | # Part 5: COMMON RULES and 57 | # and default Targets 58 | 59 | include $(CONFIG_DIR)/make.rules 60 | 61 | ######################### 62 | # Part 6: DEPENDENCIES 63 | 64 | -------------------------------------------------------------------------------- /doc/tech_doc/CommandSeq1: -------------------------------------------------------------------------------- 1 | float (*fval)[5]; 2 | :show fval 3 | struct stag {int x; double da[5];} st; 4 | :show st 5 | struct { float v; struct stag st;} sr; 6 | :show sr 7 | int sqr(int x); 8 | :show sqr 9 | int sqr(int x) { return x * x;} 10 | :show sqr 11 | :show printf 12 | printf("hello\n"); 13 | #include 14 | :show printf 15 | printf("hello\n"); 16 | #include ../doc/regline.c 17 | :show regline 18 | :rm fval 19 | :show fval 20 | int *p1, *p2, a, b,c; 21 | :variables int * 22 | int f(char * s) { return 1;} 23 | int foo(const char * str); 24 | :variables int (char * x) 25 | struct stag {int x,y;}; 26 | enum etag {RED,GREE, BLUE}; 27 | :variables tags 28 | :help 29 | :-I./tests 30 | :-R ./tests 31 | :-L 32 | :history 33 | -------------------------------------------------------------------------------- /doc/tech_doc/modification.notes: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------- 2 | When modifying stack instructions check: 3 | MachSet.h 4 | emitter.c 5 | interpre.c 6 | parser.c 7 | cdecl.c: 8 | typesets.c: 9 | 10 | ----------------------------------------------------- 11 | Fri Jan 26 11:17:49 EST 1996 12 | ADDED SHORT CIRCUIT EVALUATION TO EIC /* EJB */ 13 | 14 | Instructions removed: 15 | jmpf replaced by jmpFint 16 | jmpt replaced by jmpTint 17 | 18 | Instructions Tagged for removal: 19 | landuint replaced by landint 20 | landulong replaced by landlong 21 | 22 | Instructions added: 23 | jmpFint jmpTint 24 | jmpFlng jmpTlng 25 | jmpFdbl jmpTdbl 26 | jmpTptr jmpTptr 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /doc/test.tex: -------------------------------------------------------------------------------- 1 | \documentclass[12pt]{book} 2 | \usepackage{float,moreverb,xspace,makeidx,apalike,epsfig} 3 | 4 | \makeindex 5 | 6 | 7 | \include{eicpreamble} 8 | 9 | \title{Extensible Interactive C } 10 | \author{Edmond J. Breen} 11 | 12 | \includeonly{% 13 | % ,FigPageSetup% 14 | % ,preface% 15 | % ,Intro2EiC% 16 | % ,preproc% 17 | ,grammar% 18 | % ,Library% 19 | % ,EiCgram% 20 | } 21 | 22 | 23 | 24 | \begin{document} 25 | 26 | \maketitle 27 | 28 | \frontmatter 29 | 30 | \tableofcontents 31 | %\include{FigPageSetup} 32 | %\include{preface} 33 | 34 | \mainmatter 35 | 36 | %\include{Intro2EiC} 37 | %\include{preproc} 38 | \include{grammar} 39 | %\include{Library} 40 | 41 | \appendix 42 | 43 | \include{EiCgram} 44 | 45 | \bibliographystyle{apalike} 46 | \bibliography{computer} 47 | 48 | 49 | \section*{On line documentation and C sources} 50 | \begin{itemize} 51 | \item Steve Summit's Introductory C course: \\ 52 | \verb+http://www.eskimo.com/~scs/cclass/cclass.html+ 53 | \item Martin Leslie's Online C Language Reference:\\ 54 | \verb+http://users.southeast.net/~garyg/C_ref/C/c.html+ 55 | \item Ross Richardson's The C Standard Library:\\ 56 | \verb+http://www.infosys.utas.edu.au/info/documentation/C/CStdLib.html+ 57 | \item comp.lang.c Frequently Asked Questions:\\ 58 | \verb+http://www.eskimo.com/~scs/C-faq/top.html+ 59 | \item Other Sources, C, Related Languages, Programming Languages:\\ 60 | \verb+http://www.lysator.liu.se/c/c-www.html+ 61 | \end{itemize} 62 | 63 | \printindex 64 | \end{document} 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /main/examples/myfile.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char **argv) 3 | { 4 | while(argc--) 5 | printf("%s\n",*argv++); 6 | fflush(stdout); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /module/Makefile: -------------------------------------------------------------------------------- 1 | ######################### 2 | # Part 1: LOCAL DEFINITIONS 3 | 4 | TOP = .. 5 | EXTRA = 6 | WARNINGS = 7 | INCLUDES = 8 | LIB = 9 | 10 | DEP_LIBS = 11 | LIBS = 12 | 13 | # DIRS = `find . -name "CVS" -prune -o -type d -maxdepth 1 -print` 14 | DIRS = `ls -1 -F | grep / | grep -v CVS` 15 | MODS_FILE = modules.calls 16 | LINKS_FILE = link.libs 17 | 18 | ######################### 19 | # Part 2: COMMON MAKE PARAMETERS 20 | 21 | include $(TOP)/make.proj 22 | 23 | ######################### 24 | # Part 3: LOCAL SOURCES 25 | 26 | 27 | ######################### 28 | # Part 4: LOCAL TARGETS 29 | 30 | #### scripts 31 | 32 | all:: 33 | 34 | install:: 35 | $(RM) $(MODS_FILE) 36 | touch $(MODS_FILE) 37 | $(RM) $(LINKS_FILE) 38 | touch $(LINKS_FILE) 39 | 40 | 41 | 42 | clean:: 43 | clobber::clean 44 | $(RM) $(LINKS_FILE) $(MODS_FILE) 45 | 46 | ####### HEADERS 47 | headers:: 48 | 49 | ######################### 50 | # Part 5: COMMON RULES and 51 | # and default Targets 52 | 53 | include $(CONFIG_DIR)/NormalNodeTargets 54 | include $(CONFIG_DIR)/make.rules 55 | 56 | ######################### 57 | # Part 6: DEPENDENCIES 58 | 59 | -------------------------------------------------------------------------------- /module/MathStats/Makefile: -------------------------------------------------------------------------------- 1 | ######################### 2 | # Part 1: LOCAL DEFINITIONS 3 | 4 | TOP = 5 | EXTRA = 6 | WARNINGS = 7 | INCLUDES = 8 | LIB = 9 | 10 | DEP_LIBS = 11 | LIBS = 12 | 13 | DIRS = 14 | MODS_FILE= 15 | 16 | ######################### 17 | # Part 2: COMMON MAKE PARAMETERS 18 | 19 | ######################### 20 | # Part 3: LOCAL SOURCES 21 | 22 | 23 | ######################### 24 | # Part 4: LOCAL TARGETS 25 | 26 | #### scripts 27 | 28 | all:: 29 | install:: 30 | clean:: 31 | clobber:: 32 | headers:: 33 | 34 | ######################### 35 | # Part 5: COMMON RULES and 36 | # and default Targets 37 | 38 | ######################### 39 | # Part 6: DEPENDENCIES 40 | 41 | -------------------------------------------------------------------------------- /module/MathStats/combinatorial.c: -------------------------------------------------------------------------------- 1 | void nexcom(int N, int K, 2 | int * R, 3 | int *MTC) 4 | { 5 | /* get next composition of n into k parts. 6 | (Nijenhuis, J. (1978) Combinatorial algorithms. pp 46-51. N.Y. Academic Press) 7 | 8 | ** N: Number of elements in the universe. 9 | ** K: Number of elements in the desired subset. 10 | ** R: Output array 11 | ** MTC: Logical: *MTC = 0 for first call for a new sequence. 1 otherwise. 12 | */ 13 | 14 | static int T=0,H=0; 15 | int i; 16 | 17 | /* you are allowed to point 1 position before and 1 after 18 | a legal area. 19 | */ 20 | R--; 21 | 22 | if(!*MTC) { 23 | R[1] = N; 24 | T = N; 25 | H = 0; 26 | if(K != 1) 27 | for(i=2; i <= K; i++) 28 | R[i] = 0; 29 | *MTC = R[K] != N; 30 | return; 31 | } 32 | if(T > 1) 33 | H = 0; 34 | H = H + 1; 35 | T = R[H]; 36 | R[H] = 0; 37 | R[1] = T - 1; 38 | R[H+1] = R[H+1] + 1; 39 | *MTC = R[K] != N; 40 | 41 | } 42 | 43 | 44 | #if 0 45 | 46 | void test_nexcom() 47 | { 48 | 49 | int W[3], mtc=0,j; 50 | 51 | do { 52 | nexcom(5,sizeof(W)/sizeof(int),W,&mtc); 53 | for(j=0;j 2 | 3 | 4 | float randg(float mean, float sigma) 5 | { 6 | unsigned i; 7 | float sum; 8 | for (sum = 0, i = 0; i < 12; ++i) 9 | sum += (float) rand() / (float) RAND_MAX; 10 | return (sum - 6) * sigma + mean; 11 | } 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /module/gnuplot/Makefile: -------------------------------------------------------------------------------- 1 | ######################### 2 | # Part 1: LOCAL DEFINITIONS 3 | 4 | TOP = 5 | EXTRA = 6 | WARNINGS = 7 | INCLUDES = 8 | LIB = 9 | 10 | DEP_LIBS = 11 | LIBS = 12 | 13 | DIRS = 14 | MODS_FILE= 15 | 16 | ######################### 17 | # Part 2: COMMON MAKE PARAMETERS 18 | 19 | ######################### 20 | # Part 3: LOCAL SOURCES 21 | 22 | 23 | ######################### 24 | # Part 4: LOCAL TARGETS 25 | 26 | #### scripts 27 | 28 | all:: 29 | install:: 30 | clean:: 31 | clobber:: 32 | headers:: 33 | 34 | ######################### 35 | # Part 5: COMMON RULES and 36 | # and default Targets 37 | 38 | ######################### 39 | # Part 6: DEPENDENCIES 40 | 41 | -------------------------------------------------------------------------------- /module/gnuplot/README.html: -------------------------------------------------------------------------------- 1 | 2 | EiC's gnuplot API 3 | 4 |
EiC's gnuplot API

5 | 6 | This is a brief discription of EiC's gnuplot API.
7 | There is a demo program in this directory which can be easily compiled: 8 |
 9 |        gcc -o demo demo.c     
10 | 
11 | or run via EiC: 12 |
13 |        eic demo.c   
14 | 
15 | 16 | 17 | The basic method for EiC's gnuplot API works like this: 18 |
    19 | 20 |
  1. create a plot object: 21 |
    22 |      #include "gnuplot/gplot.h"
    23 |      ... 
    24 |      plot_t *p = openPlot("name of plot");
    25 |   
    26 | 27 |
  2. Send the plot some information: 28 |
    29 |      int a = 1;
    30 |      send2plot(p,"plot [x=%d:%d] cos(x)",-a,a);
    31 |   
    32 | 33 |
  3. There are also many predefined interface functions; 34 | for example: 35 |
    36 |      int i; float A[100];
    37 |      for(i=0;i<100;++i) A[i] = i/3.0;
    38 |      plotData(A,100,p,plotFloats);  
    39 |   
    40 | 41 | 42 |
  4. when finished close the plot: 43 |
    44 |      closePlot(p);
    45 |   
    46 | 47 |
48 | 49 | Other links: 50 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /module/link2eic/Makefile: -------------------------------------------------------------------------------- 1 | ######################### 2 | # Part 1: LOCAL DEFINITIONS 3 | 4 | TOP = ../../ 5 | EXTRA = 6 | WARNINGS = 7 | INCLUDES = -I$(TOP)/src -I. $(INCLUDE_FLAGS) 8 | LIB = 9 | 10 | DEP_LIBS = 11 | LIBS = 12 | 13 | DIRS = 14 | MODS_FILE= 15 | 16 | ######################### 17 | # Part 2: COMMON MAKE PARAMETERS 18 | 19 | include $(TOP)/make.proj 20 | 21 | ######################### 22 | # Part 3: LOCAL SOURCES 23 | 24 | LIB = ../../lib/libeic.a 25 | 26 | HEADERS = link2eic.h 27 | 28 | SRCS = link2eic.c 29 | 30 | OBJS = link2eic.o 31 | 32 | ######################### 33 | # Part 4: LOCAL TARGETS 34 | 35 | #### scripts 36 | 37 | all:: $(OBJS) 38 | 39 | install:: $(OBJS) 40 | $(AR) $(ARFLAGS) $(LIB) $(OBJS) 41 | 42 | clean:: 43 | $(RM) $(OBJS) 44 | clobber:: 45 | headers:: 46 | 47 | ######################### 48 | # Part 5: COMMON RULES and 49 | # and default Targets 50 | 51 | ######################### 52 | # Part 6: DEPENDENCIES 53 | 54 | -------------------------------------------------------------------------------- /module/link2eic/link2eic.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../../new_main/link2eic.h" 4 | #include "eic.h" 5 | 6 | /* 7 | int link2eic_iwait(secs) 8 | 9 | blocking until a message is arrived to stderr pipe stream 10 | if secs is a negative, it will wait indefinitely (no timeout) 11 | */ 12 | 13 | val_t eic_link2eic_iwait(void) 14 | { 15 | val_t v; 16 | 17 | v.ival = link2eic_iwait(arg(0,getargs(),int)); 18 | return v; 19 | } 20 | 21 | /* 22 | void link2eic_tracelog(msg) 23 | 24 | send out the message to stdin pipe stream using the 'trace' 25 | command. The message is logged to the agent's logging file. 26 | 27 | */ 28 | 29 | val_t eic_link2eic_tracelog(void) 30 | { 31 | val_t v; 32 | 33 | v.ival = link2eic_tracelog(arg(0,getargs(),char *)); 34 | return v; 35 | } 36 | 37 | /* 38 | int link2eic_init_cosim(nretries) 39 | 40 | try to initialize the Co-sim link to simulation 41 | up to nretries times (every 0.5 secs) 42 | this is for deferred initialization 43 | returns -1 (fatal error), 0 (success), >0 (failed for reason) 44 | */ 45 | 46 | val_t eic_link2eic_init_cosim(void) 47 | { 48 | val_t v; 49 | 50 | v.ival = link2eic_init_cosim(arg(0,getargs(),int)); 51 | return v; 52 | } 53 | 54 | /****************************************************************/ 55 | 56 | void module_link2eic(void) 57 | { 58 | 59 | EiC_add_builtinfunc("link2eic_iwait",eic_link2eic_iwait); 60 | EiC_add_builtinfunc("link2eic_tracelog",eic_link2eic_tracelog); 61 | EiC_add_builtinfunc("link2eic_init_cosim",eic_link2eic_init_cosim); 62 | } 63 | -------------------------------------------------------------------------------- /module/link2eic/link2eic.h: -------------------------------------------------------------------------------- 1 | #ifndef LINK2EICH_ 2 | #define LINK2EICH_ 3 | 4 | int link2eic_iwait(int secs); 5 | void link2eic_tracelog(char *msg); 6 | int link2eic_init_cosim(int nretries); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /module/stdClib/Makefile: -------------------------------------------------------------------------------- 1 | ############################ 2 | # Part 1: LOCAL DEFINITIONS 3 | 4 | TOP = ../.. 5 | 6 | ############################# 7 | # Part 2: COMMON MAKE PARAMETERS 8 | 9 | include $(TOP)/make.proj 10 | 11 | ############################# 12 | # Part 3: LOCAL SOURCES 13 | 14 | ## DIRS = src test 15 | DIRS = src 16 | 17 | ############################## 18 | # Part 4: LOCAL TARGETS 19 | 20 | include $(CONFIG_DIR)/NormalNodeTargets 21 | 22 | ############################# 23 | # Part 5: COMMON RULES and 24 | # and default Targets 25 | 26 | include $(CONFIG_DIR)/make.rules 27 | 28 | ############################# 29 | # Part 6: DEPENDENCIES 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /module/stdClib/src/_LINUX/dirent.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_DIRENTH 2 | #define _SYS_DIRENTH 3 | 4 | #if 0 /* libc5 definition */ 5 | struct dirent /* data from getdents()/readdir() */ 6 | { 7 | long d_ino; /* inode number of entry */ 8 | off_t d_off; /* offset of disk directory entry */ 9 | unsigned short d_reclen; /* length of this record */ 10 | char d_name[255+1]; /* name of file */ /* non-POSIX */ 11 | }; 12 | 13 | #else /* libc6 definition */ 14 | struct dirent /* data from getdents()/readdir() */ 15 | { 16 | long d_ino; /* inode number of entry */ 17 | off_t d_off; /* offset of disk directory entry */ 18 | unsigned short d_reclen; /* length of this record */ 19 | unsigned char d_type; /* libc6 extension */ 20 | char d_name[255+1]; /* name of file */ /* non-POSIX */ 21 | }; 22 | #endif 23 | 24 | 25 | #endif /* _SYS_DIRENTH */ 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /module/stdClib/src/_LINUX/fcntl.h: -------------------------------------------------------------------------------- 1 | struct flock { 2 | short l_type; 3 | short l_whence; 4 | off_t l_start; 5 | off_t l_len; 6 | pid_t l_pid; 7 | }; 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /module/stdClib/src/_LINUX/termios.h: -------------------------------------------------------------------------------- 1 | struct termios 2 | { 3 | tcflag_t c_iflag; /* input mode flags */ 4 | tcflag_t c_oflag; /* output mode flags */ 5 | tcflag_t c_cflag; /* control mode flags */ 6 | tcflag_t c_lflag; /* local mode flags */ 7 | cc_t c_line; /* line discipline */ 8 | cc_t c_cc[NCCS]; /* control characters */ 9 | speed_t c_ispeed; /* input speed */ 10 | speed_t c_ospeed; /* output speed */ 11 | }; 12 | -------------------------------------------------------------------------------- /module/stdClib/src/_LINUX/time.h: -------------------------------------------------------------------------------- 1 | #define CLOCKS_PER_SEC 1000000 2 | 3 | #ifndef _EiC 4 | #define unsafe 5 | #endif 6 | 7 | struct tm { 8 | int tm_sec; 9 | int tm_min; 10 | int tm_hour; 11 | int tm_mday; 12 | int tm_mon; 13 | int tm_year; 14 | int tm_wday; 15 | int tm_yday; 16 | int tm_isdst; 17 | 18 | long tm_gmtoff; 19 | char * unsafe tm_zone; 20 | 21 | }; 22 | 23 | char *asctime(struct tm * tm); 24 | clock_t clock(void); 25 | char *ctime(time_t * clock); 26 | double difftime(time_t t1, time_t t2); 27 | struct tm *gmtime(time_t *clock); 28 | struct tm *localtime(time_t *clock); 29 | time_t mktime(struct tm * tm); 30 | size_t strftime(char * buf, size_t bufsize,char * fmt,struct tm *tm); 31 | time_t time(time_t * tloc); 32 | 33 | #ifndef _EiC 34 | #undef unsafe 35 | #endif 36 | 37 | 38 | -------------------------------------------------------------------------------- /module/stdClib/src/_SOLARIS/dirent.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_DIRENTH 2 | #define _SYS_DIRENTH 3 | 4 | 5 | 6 | struct dirent /* data from getdents()/readdir() */ 7 | { 8 | ino_t d_ino; /* inode number of entry */ 9 | off_t d_off; /* offset of disk directory entry */ 10 | unsigned short d_reclen; /* length of this record */ 11 | char d_name[1]; /* name of file */ /* non-POSIX */ 12 | }; 13 | 14 | #endif /* _SYS_DIRENTH */ 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /module/stdClib/src/_SOLARIS/fcntl.h: -------------------------------------------------------------------------------- 1 | typedef struct flock { 2 | short l_type; 3 | short l_whence; 4 | off_t l_start; 5 | off_t l_len; /* len == 0 means until end of file */ 6 | long l_sysid; 7 | pid_t l_pid; 8 | long l_pad[4]; /* reserve area */ 9 | } flock_t; 10 | -------------------------------------------------------------------------------- /module/stdClib/src/_SOLARIS/termios.h: -------------------------------------------------------------------------------- 1 | struct termios { 2 | tcflag_t c_iflag; /* input modes */ 3 | tcflag_t c_oflag; /* output modes */ 4 | tcflag_t c_cflag; /* control modes */ 5 | tcflag_t c_lflag; /* line discipline modes */ 6 | cc_t c_cc[NCCS]; /* control chars */ 7 | }; 8 | -------------------------------------------------------------------------------- /module/stdClib/src/_SOLARIS/time.h: -------------------------------------------------------------------------------- 1 | #define CLOCKS_PER_SEC 1000000 2 | 3 | 4 | struct tm { 5 | int tm_sec; 6 | int tm_min; 7 | int tm_hour; 8 | int tm_mday; 9 | int tm_mon; 10 | int tm_year; 11 | int tm_wday; 12 | int tm_yday; 13 | int tm_isdst; 14 | }; 15 | 16 | char *asctime(struct tm * tm); 17 | clock_t clock(void); 18 | char *ctime(time_t * clock); 19 | double difftime(time_t t1, time_t t2); 20 | struct tm *gmtime(time_t *clock); 21 | struct tm *localtime(time_t *clock); 22 | time_t mktime(struct tm * tm); 23 | size_t strftime(char * buf, size_t bufsize, char * fmt,struct tm *tm); 24 | time_t time(time_t * tloc); 25 | 26 | -------------------------------------------------------------------------------- /module/stdClib/src/assert.c: -------------------------------------------------------------------------------- 1 | /* assert.c 2 | * 3 | * (C) Copyright Dec 20 1998, Edmond J. Breen. 4 | * ALL RIGHTS RESERVED. 5 | * This code may be copied for personal, non-profit use only. 6 | * 7 | */ 8 | 9 | #ifndef NO_ASSERT 10 | #include 11 | #include 12 | 13 | #include "eic.h" 14 | #include "stdliblocal.h" 15 | /*#include "assert.h"*/ 16 | 17 | 18 | /* ASSERT.H STUFF */ 19 | val_t eic_assert() 20 | { 21 | val_t v; 22 | fputs(arg(0,getargs(),ptr_t).p, stderr); 23 | fputs(" -- assert failed\n",stderr); 24 | return v; 25 | } 26 | #endif 27 | /******************************************************************/ 28 | void module_assert(void) 29 | { 30 | #ifndef NO_ASSERT 31 | /* ASSERT.H STUFF */ 32 | EiC_add_builtinfunc("_Assert",eic_assert); 33 | #endif 34 | } 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /module/stdClib/src/assert.h: -------------------------------------------------------------------------------- 1 | #ifndef _ASSERTH 2 | #define _ASSERTH 3 | 4 | #pragma push_safeptr 5 | 6 | 7 | void _Assert(char *msg); 8 | 9 | #undef assert 10 | #ifdef NDEBUG 11 | #define assert(test) 12 | #else 13 | #define __Str(x) __Val(x) 14 | #define __Val(x) #x 15 | #define assert(test) ((test) ? (void) 0 : _Assert("In "__FILE__ ", line " __Str(__LINE__) ": " #test )) 16 | #endif 17 | 18 | 19 | #pragma pop_ptr 20 | 21 | #endif /* end _ASSERTH */ 22 | 23 | -------------------------------------------------------------------------------- /module/stdClib/src/dirent.h: -------------------------------------------------------------------------------- 1 | #ifndef _DIRENTH 2 | #define _DIRENTH 3 | 4 | #pragma push_safeptr 5 | 6 | #include "sys/types.h" 7 | #include "sys/dirent.h" 8 | 9 | typedef struct 10 | { 11 | int dd_fd; /* file descriptor */ 12 | int dd_loc; /* offset in block */ 13 | int dd_size; /* amount of valid data */ 14 | struct dirent *dd_buf; /* -> directory block */ 15 | } DIR; /* stream data from opendir() */ 16 | 17 | /* POSIX.1 */ 18 | int closedir(DIR *dirp); 19 | DIR *opendir(const char *filename); 20 | struct dirent *readdir(DIR *dirp); 21 | void rewinddir(DIR *dirp); 22 | 23 | /* MISC */ 24 | void seekdir(DIR *dirp, long loc); 25 | long telldir(DIR *dirp); 26 | 27 | #pragma pop_ptr 28 | 29 | #endif /* end _DIRENTH */ 30 | -------------------------------------------------------------------------------- /module/stdClib/src/errno.c: -------------------------------------------------------------------------------- 1 | /* errno.c 2 | * 3 | * (C) Copyright Dec 20 1998, Edmond J. Breen. 4 | * ALL RIGHTS RESERVED. 5 | * This code may be copied for personal, non-profit use only. 6 | * 7 | */ 8 | 9 | #ifndef NO_ERRNO 10 | 11 | #include 12 | #include 13 | #include "eic.h" 14 | #include "stdliblocal.h" 15 | 16 | 17 | val_t _get_errno(void) 18 | { 19 | val_t v; 20 | /* 21 | * This function exists so that EiC can get the address 22 | * of the errno; 23 | */ 24 | 25 | errno = 0; 26 | v.p.sp = v.p.p = &errno; 27 | v.p.ep = (void *) ( ((char *) v.p.p) + sizeof( errno ) ); 28 | return v; 29 | } 30 | 31 | 32 | #endif 33 | 34 | /*************************************/ 35 | 36 | void module_errno() 37 | { 38 | #ifndef NO_ERRNO 39 | 40 | /* ERRNO.H STUFF */ 41 | EiC_add_builtinfunc("_get_errno",_get_errno); 42 | 43 | #endif 44 | } 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /module/stdClib/src/errno.h: -------------------------------------------------------------------------------- 1 | #ifndef ERRNOH_ 2 | #define ERRNOH_ 3 | 4 | #pragma push_safeptr 5 | 6 | 7 | #include 8 | 9 | #ifdef _EiC 10 | 11 | extern int *_ErRnNo_; 12 | #define errno (*_ErRnNo_) 13 | int * _get_errno(void); 14 | _ErRnNo_ = _get_errno(); 15 | 16 | #else 17 | 18 | extern int errno; 19 | 20 | #endif 21 | 22 | 23 | 24 | #pragma pop_ptr 25 | 26 | #endif /* ERRNOH_ */ 27 | -------------------------------------------------------------------------------- /module/stdClib/src/float.h: -------------------------------------------------------------------------------- 1 | #ifndef _FLOATH 2 | #define _FLOATH 3 | 4 | #pragma push_safeptr 5 | 6 | typedef union { 7 | unsigned short _Usv[4]; 8 | float _Fv; 9 | double _Dv; 10 | } _Dv_t; 11 | 12 | #include 13 | 14 | #pragma pop_ptr 15 | 16 | #endif /* _FLOATH */ 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /module/stdClib/src/iso646.h: -------------------------------------------------------------------------------- 1 | #ifndef EiC_iso646_H 2 | #define EiC_iso646_H 3 | 4 | #define and && 5 | #define and_eq &= 6 | #define bitand & 7 | #define bitor | 8 | #define compl ~ 9 | #define not ! 10 | #define not_eq != 11 | #define or || 12 | #define or_eq |= 13 | #define xor ^ 14 | #define xor_eq ^= 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /module/stdClib/src/math.h: -------------------------------------------------------------------------------- 1 | #ifndef _MATH 2 | #define _MATH 3 | 4 | #pragma push_safeptr 5 | 6 | #define HUGE_VAL 1.0e38 7 | 8 | double acos(double a); 9 | double asin(double a); 10 | double atan(double a); 11 | double atan2(double a, double b); 12 | double cos(double a); 13 | double sin(double a); 14 | double tan(double a); 15 | double cosh(double a); 16 | double sinh(double a); 17 | double tanh(double a); 18 | double exp(double a); 19 | double frexp(double a, int * b); 20 | double ldexp(double a, int b); 21 | double log(double a); 22 | double log10(double a); 23 | double modf(double a, double *b); 24 | double pow(double a, double b); 25 | double sqrt(double a); 26 | double ceil(double a); 27 | double fabs(double a); 28 | double floor(double a); 29 | double fmod(double a, double b); 30 | 31 | #pragma pop_ptr 32 | 33 | #endif /* _MATH */ 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /module/stdClib/src/setjmp.h: -------------------------------------------------------------------------------- 1 | #ifndef _SETJMP 2 | #define _SETJMP 3 | 4 | 5 | typedef char jmp_buf[64]; 6 | 7 | #define setjmp(x) (x),__eicsetjmp 8 | #define longjmp(x,y) {int f = y; (x)+(f),__eiclongjmp;} 9 | 10 | 11 | #endif 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /module/stdClib/src/stdClib.c: -------------------------------------------------------------------------------- 1 | extern void module_stdio(void); 2 | extern void module_math(void); 3 | extern void module_fcntl(void); 4 | extern void module_string(void); 5 | extern void module_ctype(void); 6 | extern void module_dirent(void); 7 | extern void module_assert(void); 8 | extern void module_time(void); 9 | extern void module_unistd(void); 10 | extern void module_stat(void); 11 | extern void module_stdarg(void); 12 | extern void module_errno(void); 13 | extern void module_stdlib(void); 14 | extern void module_termios(void); 15 | extern void module_signal(void); 16 | 17 | void stdClib(void) 18 | { 19 | 20 | module_stdio(); 21 | module_math(); 22 | module_fcntl(); 23 | module_string(); 24 | module_ctype(); 25 | module_dirent(); 26 | module_assert(); 27 | module_time(); 28 | module_unistd(); 29 | module_stat(); 30 | module_stdarg(); 31 | module_errno(); 32 | module_stdlib(); 33 | #if 1 34 | module_signal(); 35 | #endif 36 | 37 | #ifndef NO_TERMIOS 38 | module_termios(); 39 | #endif 40 | } 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /module/stdClib/src/stdarg.c: -------------------------------------------------------------------------------- 1 | /* stdarg.c 2 | * 3 | * (C) Copyright Dec 20 1998, Edmond J. Breen. 4 | * ALL RIGHTS RESERVED. 5 | * This code may be copied for personal, non-profit use only. 6 | * 7 | */ 8 | 9 | 10 | #ifndef NO_STDARG 11 | 12 | #include 13 | #include "eic.h" 14 | #include "stdliblocal.h" 15 | 16 | 17 | /* STDARG.H STUFF */ 18 | 19 | val_t _StArT_Va(void) 20 | { 21 | val_t v; 22 | getptrarg(0,v.p); 23 | v.p.ep = v.p.p; 24 | v.p.sp = (char*)v.p.p - 256 * sizeof(val_t); 25 | return v; 26 | } 27 | 28 | val_t _get_AR_t_size(void) 29 | { 30 | val_t v; 31 | v.ival = sizeof(AR_t); 32 | return v; 33 | } 34 | 35 | #endif 36 | 37 | 38 | /************************************************/ 39 | 40 | void module_stdarg() 41 | { 42 | #ifndef NO_STDARG 43 | 44 | /* STDARG.H STUFF */ 45 | EiC_add_builtinfunc("_get_AR_t_size",_get_AR_t_size); 46 | EiC_add_builtinfunc("_StArT_Va",_StArT_Va); 47 | 48 | #endif 49 | } 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /module/stdClib/src/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDARGH 2 | #define _STDARGH 3 | 4 | #pragma push_safeptr 5 | 6 | 7 | typedef char *va_list; 8 | 9 | int _get_AR_t_size(void); 10 | va_list _StArT_Va(void *); 11 | int _AR_t_SiZe; 12 | 13 | 14 | #define va_arg(x,y) (*(y*)(x -= _AR_t_SiZe)) 15 | #define va_start(x,y) (x)=_StArT_Va(&(y)) 16 | #define va_end(x) 17 | 18 | _AR_t_SiZe = _get_AR_t_size(); 19 | 20 | #pragma pop_ptr 21 | 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /module/stdClib/src/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef STDDEFH_ 2 | #define STDDEFH_ 3 | 4 | #pragma push_safeptr 5 | 6 | #define _need_NULL 7 | #define _need_ptrdiff_t 8 | #define _need_size_t 9 | #define _need_wchar_t 10 | 11 | #include "sys/stdtypes.h" 12 | 13 | #define offsetof(type, mem) ((size_t)(&((type*)0)->mem)) 14 | 15 | #undef _need_ptrdiff_t 16 | #undef _need_size_t 17 | #undef _need_wchar_t 18 | #undef _need_NULL 19 | 20 | #pragma pop_ptr 21 | 22 | #endif /* _STDDEFH */ 23 | -------------------------------------------------------------------------------- /module/stdClib/src/stdliblocal.h: -------------------------------------------------------------------------------- 1 | #ifndef STDLIBLOCALH_ 2 | #define STDLIBLOCALH_ 3 | 4 | char * strrev(char *s); 5 | char *utoa(unsigned int n, char *s, int radix); 6 | char *itoa(int n, char *s, int radix); 7 | char *ultoa(unsigned long n, char *s, int radix); 8 | char *ltoa(long n, char *s, int radix); 9 | char *ulltoa(unsigned long long n, char *s, int radix); 10 | char *lltoa(long long n, char *s, int radix); 11 | 12 | char *fftoa(double d, char *str, int p, char type, int trunc); 13 | 14 | int charout_(int c, char **buf); 15 | int charin_(char **buf); 16 | int charback_(int ch, char **buf); 17 | 18 | int strround(char *s,int len); 19 | 20 | 21 | #define setEp(P,sz) (P).ep = (char*)(P).p + (sz) 22 | 23 | #define getptrarg(x,y) y = arg(x,getargs(),ptr_t) 24 | #define checkEp(P,s) if((char*)P.p + (s) > (char *)P.ep)\ 25 | EiC_Mod_Error("Access beyond array\n"); 26 | 27 | extern void EiC_Mod_Error(char *fmt, ...); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /module/stdClib/src/strrev.c: -------------------------------------------------------------------------------- 1 | char * strrev(char *s) 2 | { 3 | int j,k,c; 4 | for(k=0;s[k] != 0;k++); 5 | for(j=0,k--;j0) 12 | if(s[--len] >= '5') { 13 | do { 14 | s[len--] = '0'; 15 | } while(len > 0 && s[len] == '9'); 16 | if(s[len] == '9') 17 | return 0; 18 | s[len]++; 19 | } 20 | return 1; 21 | } 22 | -------------------------------------------------------------------------------- /module/stdClib/src/termios.h: -------------------------------------------------------------------------------- 1 | #ifndef _TERMIOSH 2 | #define _TERMIOSH 3 | 4 | #pragma push_safeptr 5 | 6 | #if 0 7 | #include "sys/stdtypes.h" 8 | #endif 9 | #include "sys/termdefs.h" 10 | #include "sys/termios.h" 11 | 12 | int tcgetattr(int, struct termios *); 13 | int tcsetattr(int, int, const struct termios *); 14 | 15 | speed_t cfgetispeed(const struct termios *); 16 | int cfsetispeed(struct termios *, speed_t); 17 | 18 | speed_t cfgetospeed(const struct termios *); 19 | int cfsetospeed(struct termios *, speed_t); 20 | 21 | int tcdrain(int); 22 | int tcflow(int, int); 23 | int tcsendbreak(int, int); 24 | int tcflush(int, int); 25 | 26 | 27 | #pragma pop_ptr 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /module/stdClib/src/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIMEH 2 | #define _TIMEH 3 | 4 | #pragma push_safeptr 5 | 6 | #define _need_clock_t 7 | #define _need_time_t 8 | #define _need_size_t 9 | #define _need_NULL 10 | 11 | #include "sys/stdtypes.h" 12 | 13 | #undef _need_clock_t 14 | #undef _need_time_t 15 | #undef _need_size_t 16 | #undef _need_NULL 17 | 18 | #include "sys/time.h" 19 | 20 | 21 | #pragma pop_ptr 22 | 23 | #endif /* _TIMEH */ 24 | -------------------------------------------------------------------------------- /new_main/examples/test-datatypes.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | ***************************************************************************** 3 | $Id: //depot/easycosim/cint/EiC/new_main/examples/test-datatypes.c#1 $ 4 | (@project_name@) @explanational_name@ 5 | 6 | by neko 7 | 8 | Description: 9 | This simple program is provided to verify if the EiC was compiled 10 | for _ILP32 Unix system. Many changes made assumed the target system 11 | was _ILP32 Unix system (to match the target 64-bit AXI system) 12 | 13 | History: 14 | 4/05/2009: Created 15 | ***************************************************************************** 16 | *****************************************************************************/ 17 | #include 18 | #include 19 | 20 | int 21 | main() 22 | { 23 | printf("It pukes if the EiC was not compiled for _ILP32 Unix system\n"); 24 | printf("Testing char, short, int, long, long long, ptr data types ...\n\n"); 25 | // no assertion error if it is running on a _ILP32 Unix system 26 | assert(sizeof(char) == 1); 27 | assert(sizeof(unsigned char) == 1); 28 | assert(sizeof(short) == 2); 29 | assert(sizeof(unsigned short) == 2); 30 | assert(sizeof(int) == 4); 31 | assert(sizeof(unsigned int) == 4); 32 | assert(sizeof(long) == 4); 33 | assert(sizeof(unsigned long) == 4); 34 | assert(sizeof(long long) == 8); 35 | assert(sizeof(unsigned long long) == 8); 36 | // unsafe ptr is "naked" ptr 37 | assert(sizeof(void * unsafe) == 4); 38 | 39 | // endianness 40 | printf("Endianness: %s-endian\n", __LITTLE_ENDIAN__ ? "Little" : "Big"); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /new_main/link2eic.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | ***************************************************************************** 3 | $Id: //depot/easycosim/cint/EiC/new_main/link2eic.h#9 $ 4 | (@project_name@) @explanational_name@ 5 | 6 | by @designer_name@ 7 | 8 | Description: 9 | @Module_functional_summary@ 10 | 11 | History: 12 | @mm/dd/yy@: @description@ 13 | ***************************************************************************** 14 | *****************************************************************************/ 15 | 16 | #ifndef LINK2EICH_ 17 | #define LINK2EICH_ 18 | 19 | #define LINK2EIC_DEFAULT_PORT 17767 20 | #define LINK2EIC_IMASK ~(1 << 15) 21 | 22 | int link2eic_init_link(int port, int deferred); 23 | 24 | void *link2eic_read(void *p, int sz); 25 | int link2eic_write(void *p, int sz, void *pd); 26 | 27 | int link2eic_bgjob(int ival); 28 | int link2eic_ivec(); 29 | 30 | int link2eic_iwait(int secs); 31 | int link2eic_fini(void); 32 | int link2eic_tracelog(char *msg); 33 | int link2eic_init_cosim(int nretries); 34 | 35 | int link2eic_loadVolatile(void); 36 | int link2eic_parse(char *rdbuf); 37 | 38 | typedef struct predef_t { 39 | unsigned int address; 40 | unsigned long long rdata; 41 | struct predef_t *next; 42 | } predefined_t; 43 | 44 | predefined_t *append_entry(); 45 | unsigned long long link2eic_lookup(void *p, int sz, unsigned long long fallback); 46 | 47 | 48 | #endif /* LINK2EICH_ */ 49 | -------------------------------------------------------------------------------- /override.params: -------------------------------------------------------------------------------- 1 | ############################################# 2 | # This file is for over riding previous 3 | # parameter settings. Any parameters 4 | # assigned in this file will over ride 5 | # the corresponding parameters in: 6 | # 7 | # $(CONFIG_DIR)/$(PLATFORM)/make.params 8 | # 9 | # This is useful for adding memory debuggers 10 | # etc; for example: 11 | # 12 | # CC = checkergcc 13 | # 14 | # will over ride the previous assignment: 15 | # 16 | # CC = gcc 17 | # 18 | ############################################# 19 | MAKE = make 20 | 21 | #CC = cc 22 | #STD_CFLAGS = -Xc -g 23 | # from the original EiC (strict ANSI) 24 | #STD_CFLAGS = -ansi -pedantic -fsigned-char -Wall 25 | STD_CFLAGS = -fsigned-char -Wall 26 | #STD_CFLAGS = -g -fsigned-char -Wall 27 | #INCLUDE_FLAGS = 28 | 29 | #CC = gcc -DDMALLOCH 30 | 31 | #CC = /usr/local/gnu/bin/gcc 32 | 33 | #CC = checkergcc 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /project.params: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # EiC project parameters 3 | # 4 | # After changing the contents of this file you must 5 | # also setup the project top 6 | # configuration via: 7 | # % makeconfig config_dir proj_dir platform 8 | 9 | # INSTALL_DIR = $(HOME)/bin 10 | INSTALL_DIR = $(HOME)/local/bin 11 | INCLUDE_DIR = $(TOP_DIR)/include 12 | LIB_DIR = $(TOP_DIR)/lib 13 | PRJ_DEFINES = 14 | STD_DEFINES = -D$(PLATFORM) $(PRJ_DEFINES) 15 | ALLDEFINES = $(DEFINES) $(STD_DEFINES) 16 | CFLAGS = $(STD_CFLAGS) $(WARNINGS) $(INCLUDES) $(ALLDEFINES) 17 | DUMMY_STR = This file is a dummy target. Please don't remove. 18 | DUMMY_TARGET = echo "$(DUMMY_STR)" > $@ 19 | ALL_LIBS = $(LIBS) 20 | 21 | ########################################### 22 | # Platform and configuration stuff is added 23 | # automatically below this point by 24 | # the makeconfig program. 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/assertp.h: -------------------------------------------------------------------------------- 1 | 2 | void abort(void); 3 | 4 | #ifndef NDEBUG 5 | 6 | #define assertandpause(p, args) if(p){fprintf(stderr,\ 7 | "ASSERT : %s, At line %d in file %s.\n",\ 8 | #p, __LINE__,__FILE__);\ 9 | printf args;\ 10 | fprintf(stderr,"");\ 11 | getchar();} 12 | 13 | 14 | 15 | #define assertp(p, args) if(p){\ 16 | fprintf(stderr,\ 17 | "ASSERT : %s, At line %d in file %s.\nCalled From: ",\ 18 | #p, __LINE__,__FILE__);\ 19 | printf args; abort();} 20 | 21 | #else 22 | #define assertandpause(p, args) 23 | #define assertp(p, args) 24 | #endif 25 | -------------------------------------------------------------------------------- /src/cdecl.h: -------------------------------------------------------------------------------- 1 | #define TYPEQUAL case constsym: case volatilesym 2 | 3 | #define STORECLASS case autosym:\ 4 | case externsym:\ 5 | case registersym:\ 6 | case staticsym:\ 7 | case typedefsym 8 | 9 | #define TYPESPEC case charsym:\ 10 | case doublesym:\ 11 | case enumsym:\ 12 | case floatsym:\ 13 | case intsym:\ 14 | case longsym:\ 15 | case shortsym:\ 16 | case signedsym:\ 17 | case structsym:\ 18 | case voidsym:\ 19 | case unionsym:\ 20 | case unsignedsym:\ 21 | case TYPENAME 22 | 23 | 24 | #define DECL case '*':case ID: case '(' 25 | 26 | 27 | 28 | /* cdecl.c 29 | -----------*/ 30 | int EiC_ext_decl(token_t *e1); 31 | int EiC_type_name(token_t * e1); 32 | void EiC_clearTempories(void); 33 | token_t *EiC_genTemporay(type_expr *type, int level); 34 | void EiC_free_un_mem(type_expr * e); 35 | 36 | extern int EiC_INFUNC; 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/eic.h: -------------------------------------------------------------------------------- 1 | /* eic.h 2 | * 3 | * (C) Copyright May 7 1995, Edmond J. Breen. 4 | * ALL RIGHTS RESERVED. 5 | * This code may be copied for personal, non-profit use only. 6 | * 7 | */ 8 | #ifndef EICH_ 9 | #define EICH_ 10 | 11 | 12 | #if !defined(_eic_ptr) && !defined(_EiC) 13 | #define _eic_ptr 14 | typedef struct {void *p, *sp, *ep;} ptr_t; 15 | #endif 16 | 17 | #include 18 | #include "eicval.h" 19 | 20 | 21 | void *EiC_add_builtinfunc(char *name, val_t(*vfunc)(void)); 22 | void EiC_startEiC(int argc, char ** argv); 23 | void EiC_init_EiC(); 24 | int EiC_run(int argc, char **argv); 25 | void EiC_parseString(char *, ...); 26 | void EiC_callBack(void *code); 27 | 28 | void EiC_setMessageDisplay(void (*)(char *)); 29 | 30 | extern void (*EiC_messageDisplay)(char *); 31 | 32 | 33 | #define setArg(x,C,type,v) do { code_t *c = C; \ 34 | *(type*)(&c->inst[c->nextinst - 5 - 2 * x].val) = v;} while(0) 35 | 36 | extern val_t EiC_STaCK_VaLuE; 37 | 38 | #define EiC_ReturnValue(type) (*(type*)&EiC_STaCK_VaLuE) 39 | 40 | 41 | extern AR_t * AR[3]; 42 | extern size_t ARGC; 43 | 44 | #define arg_list AR_t * 45 | #define getargc() ARGC 46 | #define getargs() AR[2] 47 | #define nextarg(x,type) (*((type*)&(--x)->v)) 48 | #define arg(i,x,type) (*((type*)&x[-(i+1)].v)) 49 | 50 | #define malloc(x) xmalloc(x) 51 | #define calloc(x,y) xcalloc(x,y) 52 | #define free(x) xfree(x) 53 | #define realloc(x,y) xrealloc(x,y) 54 | 55 | 56 | #endif /* EICH_ */ 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/emitter.h: -------------------------------------------------------------------------------- 1 | #ifndef EMITTERH_ 2 | #define EMITTERH_ 3 | 4 | void EiC_listcode(code_t * CODE); 5 | 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src/error.h: -------------------------------------------------------------------------------- 1 | #ifndef ERRORH_ 2 | #define ERRORH_ 3 | 4 | /* error handling error.c 5 | ---------------------------*/ 6 | void EiC_error(char *, ...); 7 | int EiC_match(int t, char * m); 8 | void EiC_warningerror(char *, ...); 9 | void EiC_clear_err_msgs(void); 10 | void EiC_formatMessage(char *,...); 11 | 12 | 13 | /* error handling globals 14 | ---------------------------*/ 15 | extern int EiC_ParseError; /* if 1 an error has occured */ 16 | extern int EiC_ErrorRecover; /* if 1 attempting to recover from error*/ 17 | extern int EiC_errs; /* Number of errors and warnings */ 18 | 19 | extern void (*EiC_messageDisplay)(char *); /* pointer function to 20 | * message Display 21 | * function 22 | */ 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/modules.h: -------------------------------------------------------------------------------- 1 | void stdClib(void); 2 | void liar(void); 3 | void preliar(void); 4 | -------------------------------------------------------------------------------- /src/parser.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSERH_ 2 | #define PARSERH_ 3 | 4 | /* parser.c 5 | ------------*/ 6 | void EiC_initparser(void); 7 | void EiC_updateLocals(void); 8 | void EiC_parse(environ_t * env); 9 | void EiC_stmt(token_t * e1); 10 | void EiC_assign_expr(token_t * e1); 11 | void cond_expr(token_t * e1); 12 | int EiC_GI(token_t * e1); 13 | 14 | void EiCp_freeLabels(Label_t *lab); 15 | Label_t * EiCp_addLabel(Label_t *lab, char *name, int loc, int chck); 16 | 17 | extern int EiC_S_LEVEL; 18 | extern unsigned int EiC_ASPOT; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/reset.h: -------------------------------------------------------------------------------- 1 | #ifndef RESET_H 2 | #define RESET_H 3 | 4 | void EiCp_initiateReset(void); 5 | void EiCp_Reset(int flag); 6 | void EiCp_setResetStart(void); 7 | void EiCp_ResetStart(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/stab.h: -------------------------------------------------------------------------------- 1 | #ifndef STABH_ 2 | #define STABH_ 3 | 4 | typedef struct { 5 | char ** strs; 6 | int n; 7 | }stab_t; 8 | 9 | 10 | /** PROTOTYPES from stab.c **/ 11 | char * EiC_stab_SaveString(stab_t *stab, char *s); 12 | size_t EiC_stab_NextEntryNum(stab_t *stab); 13 | void EiC_stab_CleanUp(stab_t *stab, size_t bot); 14 | void EiC_stab_Mark(stab_t *stab, char mark); 15 | void EiC_stab_ShowStrings(stab_t *stab); 16 | int EiC_stab_FindString(stab_t *stab, char *s); 17 | int EiC_stab_RemoveString(stab_t *stab, char *s); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/starteic.src: -------------------------------------------------------------------------------- 1 | #ifndef _STARTEiCH 2 | #define _STARTEiCH 3 | 4 | /* ISO STUFF */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /* POSIX.1 STUFF */ 17 | #include 18 | #include 19 | 20 | #endif /* _STARTEiCH */ 21 | -------------------------------------------------------------------------------- /src/symbol.h: -------------------------------------------------------------------------------- 1 | /* symbol.h 2 | * 3 | * (C) Copyright May 7 1995, Edmond J. Breen. 4 | * ALL RIGHTS RESERVED. 5 | * This code may be copied for personal, non-profit use only. 6 | * 7 | */ 8 | 9 | #ifndef HSIZE 10 | #define HSIZE 101 11 | #endif 12 | extern symentry_t *EiC_HTAB[]; 13 | 14 | int EiC_iskeyword(keyword_t *keywords,char*id,int n); 15 | void EiC_eicpush(eicstack_t *s, val_t v); 16 | int EiC_eicpop(eicstack_t *s, val_t *pop); 17 | int init_hashtab(int size); 18 | int hashsmc(char * s,int mod); 19 | symentry_t * EiC_lookup(char nspace,char *id); 20 | void EiC_remlevel(int level); 21 | void EiC_lut_CleanUp(size_t bot); 22 | void EiC_addoffsettolevel(char nspace,int level,int off); 23 | void EiC_marktype(type_expr *type, char mark); 24 | void EiC_marksyms(char mark); 25 | void EiC_remsym(symentry_t *sym); 26 | symentry_t * EiC_insertLUT(char nspace,char *id,int type); 27 | char * EiC_strsave(char *s); 28 | void EiC_newsymtype(symentry_t *sym, type_expr *t); 29 | void newsymARval(token_t *e1, val_t *v); 30 | int nextstackitem(int level); 31 | int EiC_stackit(symentry_t * sym,int level); 32 | void EiC_inittoken(token_t * e1); 33 | void EiC_freetoken(token_t * e1); 34 | 35 | void initcode(code_t * code); 36 | void EiC_killcode(symentry_t *sym); 37 | void EiC_freecode(code_t * code); 38 | void EiC_generate(code_t * code, int opcode,val_t *val,int ext); 39 | void copycode(code_t * c1, code_t * c2); 40 | void EiC_concode(code_t * c1, code_t * c2); 41 | void EiC_contoken(token_t * e1, token_t * e2); 42 | void EiC_swaptokens(token_t *e1, token_t * e2); 43 | 44 | #define setCodeLineNo(C,idx,No); ((C)->inst[idx].line = No) 45 | 46 | size_t EiC_lut_NextEntryNum(void); 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/symentry.h: -------------------------------------------------------------------------------- 1 | typedef struct symentry_t { 2 | unsigned int entry; /* entry number */ 3 | struct symentry_t *next; /* link to next symentry */ 4 | char *id; /* pointer to name */ 5 | char sclass; /* storage class code */ 6 | char typequal; /* type qualifier */ 7 | char level; /* scope level */ 8 | char nspace; /* name space identifier */ 9 | char ass; /* used to flag assignment */ 10 | type_expr * type; /* object type */ 11 | val_t val; /* symbol value information */ 12 | }symentry_t; 13 | -------------------------------------------------------------------------------- /src/typesets.h: -------------------------------------------------------------------------------- 1 | #define INCLUDE_INT 0 /*(sizeof(long) != sizeof(int))*/ 2 | 3 | #define CASE_INT case t_char: case t_short:\ 4 | case t_int: case t_enum 5 | #define CASE_UINT case t_uchar: case t_ushort: case t_uint 6 | #define CASE_LONG case t_long 7 | #define CASE_ULONG case t_ulong 8 | #define CASE_FLOAT case t_float: case t_double 9 | #define CASE_NUM CASE_INT:\ 10 | CASE_UINT:\ 11 | CASE_LONG:\ 12 | CASE_ULONG:\ 13 | CASE_FLOAT 14 | 15 | /* typesets.c 16 | --------------*/ 17 | void EiC_do_stooutput(token_t * e1); 18 | void EiC_do_inc_dec(token_t *e1, int op); 19 | void EiC_output(token_t *e1); 20 | int do_binaryop(token_t *e1, token_t *e2,int op); 21 | int EiC_unaryop(token_t *e1,int op); 22 | void EiC_cast2comm(token_t *e1, token_t *e2); 23 | int EiC_bin_validate(unsigned oper, token_t *e1, token_t *e2); 24 | void EiC_castconst(token_t *e1, token_t *e2,int explicit); 25 | void EiC_castvar(token_t *e1, token_t *e2, int explicit); 26 | 27 | -------------------------------------------------------------------------------- /test/EiCtests/gethashwords.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int hashsmc(char * s,int mod) 7 | { 8 | register unsigned int h, c; 9 | h = 0; 10 | while( (c = (int) *s++) > 0) 11 | h = (h << 1) + c; 12 | return ( h % mod); 13 | } 14 | 15 | 16 | char * getnextword(FILE *fp) 17 | { 18 | static char buff[512]; 19 | int c; 20 | int i; 21 | if(!feof(fp)) { 22 | while(!isalpha(c = fgetc(fp)) && c != EOF) 23 | ; 24 | for(i=0;(isalpha(c) || c == '_') && c != EOF;++i) { 25 | buff[i] = c; 26 | c = fgetc(fp); 27 | } 28 | ungetc(c,fp); 29 | buff[i] = 0; 30 | return buff; 31 | } else 32 | return NULL; 33 | } 34 | 35 | void process(char *fname) 36 | { 37 | char *w; 38 | FILE *fp; 39 | 40 | fp = fopen(fname,"r+"); 41 | 42 | while((w = getnextword(fp)) != NULL) 43 | printf("%d:%s\n",hashsmc(w,101),w); 44 | 45 | fclose(fp); 46 | } 47 | 48 | int main(int argc, char **argv) 49 | { 50 | while(--argc > 0) { 51 | printf("processing %s\n",*++argv); 52 | process(*argv); 53 | } 54 | return 0; 55 | } 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /test/EiCtests/testAassert.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main(void) 6 | { 7 | int v = 1; 8 | assert(v == 1); 9 | fprintf(stderr,"Assert should fail on line %d\n",__LINE__ + 1); 10 | assert(v == 0); 11 | 12 | /* check with string literals */ 13 | assert(v != '\''); 14 | 15 | return 0; 16 | } 17 | 18 | #ifdef EiCTeStS 19 | main(); 20 | #endif 21 | -------------------------------------------------------------------------------- /test/EiCtests/testMemErr1.aux: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | return 1; 4 | } 5 | -------------------------------------------------------------------------------- /test/EiCtests/testMemErr1.c: -------------------------------------------------------------------------------- 1 | #include "testMemErr1.aux" 2 | 3 | void g() 4 | { 5 | int a[5]; 6 | f(); /* call foo in file testMemErr1.aux*/ 7 | a[5]; /* access error */ 8 | } 9 | 10 | int main() 11 | { 12 | g(); 13 | return 0; 14 | } 15 | 16 | 17 | #ifdef EiCTeStS 18 | main(); 19 | #endif 20 | -------------------------------------------------------------------------------- /test/EiCtests/testMemErr2.aux: -------------------------------------------------------------------------------- 1 | #include 2 | char str1[] = "0123456789", str2[] = "01234567890123456789"; 3 | 4 | memcpy(str1,str2,20),1; /* must fail */ 5 | memcpy(str2,str1,20),1; /* must fail */ 6 | memcpy(str1,str1,10),1; /* must pass */ 7 | memcpy(str2,str2,20),1; /* must pass */ 8 | 9 | memmove(str1,str2,20),1; /* must fail */ 10 | memmove(str2,str1,20),1; /* must fail */ 11 | memmove(str1,str1,11),1; /* must pass */ 12 | memmove(str2,str2,21),1; /* must pass */ 13 | 14 | strncpy(str1,str2,12); /* must fail */ 15 | 16 | strncpy(str1,str1,11); /* must pass */ 17 | strncpy(str2,str2,21); /* must pass */ 18 | 19 | strcpy(str1,str2); /* must fail */ 20 | strcpy(str2,str1); /* must pass */ 21 | strcpy(str1,str1); /* must pass */ 22 | strcpy(str2,str2); /* must pass */ 23 | 24 | //str1[5] ='\0'; strcat(str1,str1); /* this line is brokeb */ 25 | str1[6] = '\0'; strcat(str1,str1); /* must fail */ 26 | str1[6] = '6'; // reset string 27 | 28 | str2[10] = '\0'; strncat(str2,str2,10); /* must pass*/ 29 | str2[11] = '\0'; strncat(str2,str2,10); /* must fail*/ 30 | str2[11] = '1'; // reset string 31 | 32 | char c; short s; int i; long l; float f; double b; 33 | memcpy(&c,&c,sizeof(c)); 1; // must pass 34 | memcpy(&s,&s,sizeof(s)); 2; // must pass 35 | memcpy(&i,&i,sizeof(i)); 3; // must pass 36 | memcpy(&f,&f,sizeof(f)); 4; // must pass 37 | memcpy(&b,&b,sizeof(b)); 5;// must pass 38 | memcpy(&c,&c,sizeof(c)+1); 6; // must fail 39 | memcpy(&s,&s,sizeof(s)+1); 7; // must fail 40 | memcpy(&i,&i,sizeof(i)+1); 8; // must fail 41 | memcpy(&f,&f,sizeof(f)+1); 9; // must fail 42 | memcpy(&b,&b,sizeof(b)+1); 10; // must fail 43 | 44 | :exit 45 | 46 | -------------------------------------------------------------------------------- /test/EiCtests/testMemErr2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | system("eic -g -sA < testMemErr2.aux"); 5 | system("eic -g -sA < testMemErr2b.aux"); 6 | system("eic -g -sA < testMemErr2c.aux"); 7 | return 0; 8 | } 9 | 10 | #ifdef EiCTeStS 11 | main(); 12 | #endif 13 | -------------------------------------------------------------------------------- /test/EiCtests/testassign.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void T1() 5 | { 6 | typedef struct {int x,y;} xy_t; 7 | xy_t a,b, xya[5]; 8 | int x,y,z,i; 9 | char *p, ca[20]; 10 | 11 | x = y = z = 5; 12 | assert(x == y && y == z && z == 5); 13 | 14 | x += y += z; 15 | 16 | assert(y == 10 && x == 15); 17 | 18 | for(i=0;ia == aba[2].a); 51 | } 52 | 53 | int main() 54 | { 55 | T1(); 56 | T2(); 57 | return 0; 58 | } 59 | 60 | #ifdef EiCTeStS 61 | main(); 62 | #endif 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /test/EiCtests/testcast.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void T1(void) 4 | { 5 | int i = 10; 6 | unsigned ui = 20; 7 | long l = 50; 8 | unsigned long ul = 60; 9 | long long ll = 70; 10 | int *p; 11 | 12 | p = (int *)i; 13 | assert((int)p == i); 14 | 15 | p = (int *)ui; 16 | assert((int)p == ui); 17 | 18 | p = (int *)l; 19 | assert((int)p == l); 20 | 21 | p = (int *)ul; 22 | assert((int)p == ul); 23 | 24 | p = (int *)ll; 25 | assert((int)p == ll); 26 | 27 | 28 | } 29 | 30 | int main() 31 | { 32 | 33 | T1(); 34 | return 0; 35 | } 36 | 37 | 38 | #ifdef EiCTeStS 39 | main(); 40 | #endif 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /test/EiCtests/testcomma.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int sum(int x, int y) 4 | { 5 | return x + y; 6 | } 7 | 8 | 9 | int accum() 10 | { 11 | int a,b,c,d,e; 12 | 13 | return a=1,b=a+1,c=b+1,d=c+1,e=d+1,e; 14 | } 15 | int accum2() 16 | { 17 | int a,b,c,d,e; 18 | 19 | return (a=1,b=a+1,c=b+1,d=c+1,e=d+1,e); 20 | } 21 | 22 | int array[5] = {0,1,2,3,4,}; 23 | void T1() 24 | { 25 | int i,j; 26 | i = (5,6,7,8,9,j=10,j); 27 | assert(i == j && j == 10); 28 | assert(sum(5,(j=2,2*j)) == 9); 29 | j = array[i=2,j=2,i+j]; 30 | assert(j == 4); 31 | assert(accum() == 5); 32 | assert(accum() == accum2()); 33 | } 34 | 35 | void T2() 36 | { 37 | assert(2 == ((accum()),2)); 38 | assert(2 == (accum(),2)); 39 | } 40 | 41 | 42 | 43 | int main() 44 | { 45 | T1(); 46 | T2(); 47 | return 0; 48 | } 49 | 50 | #ifdef EiCTeStS 51 | main(); 52 | #endif 53 | 54 | 55 | -------------------------------------------------------------------------------- /test/EiCtests/testcommandline.aux: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char ** argv) 4 | { 5 | int i; 6 | 7 | for(i=0; i< argc; ++i) 8 | printf("%d %s\n",i,argv[i]); 9 | return 0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /test/EiCtests/testcommandline.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int main(void) 5 | { 6 | system("eic -g 'testcommandline.aux' abc 123 \" hello world\" this.and.that"); 7 | return 0; 8 | } 9 | 10 | 11 | #ifdef EiCTeStS 12 | main(); 13 | #endif 14 | -------------------------------------------------------------------------------- /test/EiCtests/testcompliant.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define K 0xFFFFFFFF /* -1 in 32-bit, 2's compl. */ 4 | 5 | #define pass() printf("ISO C compliant, line %d\n",__LINE__) 6 | #define fail() printf("Not ISO C compliant, line %d\n",__LINE__) 7 | 8 | void T1() 9 | { 10 | if(0 2 | 3 | 4 | enum { CHAR, INT, DOUBLE }; 5 | 6 | enum rgb { RED, GREEN = 13, BLUE }; 7 | 8 | enum {Ed = 1, CLAIRE, SARAH = 1, ALEX, GEORGIA}; 9 | 10 | enum Rem; 11 | enum b { abc }; 12 | /* EiC should allow for the re-declaration of 13 | enumeration types */ 14 | enum b { abc }; 15 | 16 | extern enum rgb colour; 17 | 18 | 19 | enum Test_e { One = 1, Two, Three }; 20 | 21 | void SubA( enum Test_e *T1 ) 22 | { 23 | 24 | enum Test_e T2 = *T1; 25 | 26 | switch( T2 ) { 27 | case One : printf( "One\n" ); T2 = Two; break; 28 | case Two : printf( "Two\n" ); T2 = Three; break; 29 | case Three : printf( "Three\n" ); T2 = One; break; 30 | default : printf( "Unknown\n" ); T2 = One; break; 31 | } 32 | *T1 = T2; 33 | } 34 | 35 | 36 | int main() 37 | { 38 | enum Test_e T1 = Two; 39 | 40 | enum rgb colour = RED; 41 | enum rgb RGB = 5; 42 | { int shep = 13; 43 | { 44 | enum {farm, axe=3, shep}; 45 | printf("shep = %d :-> shep = 4\n",shep); 46 | } 47 | printf("shep = %d :-> shep = 13\n",shep); 48 | } 49 | printf("colour = %d\n",colour); 50 | printf("RGB = %d\n",RGB); 51 | printf("Ed = %d, CLAIRE = %d, SARAH = %d, ALEX %d, GEORGIA = %d\n", 52 | Ed,CLAIRE, SARAH,ALEX, GEORGIA); 53 | printf ("RED = %d,GREEN = %d,BLUE = %d " 54 | ":-> RED = 0,GREEN = 13,BLUE = 14 \n", RED, GREEN, BLUE); 55 | printf ("CHAR = %d,INT = %d,DOUBLE = %d " 56 | ":-> CHAR = 0,INT = 1,DOUBLE = 2 \n", CHAR, INT, DOUBLE); 57 | 58 | 59 | SubA( &T1 ); 60 | 61 | return 0; 62 | } 63 | 64 | #ifdef EiCTeStS 65 | main(); 66 | #endif 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /test/EiCtests/testerr3.c: -------------------------------------------------------------------------------- 1 | 2 | /* more errors that EiC should pick up and recover from */ 3 | 4 | char *pstr[] = "hello"; /* Error: initialisation error */ 5 | 6 | ; // force error alignment 7 | 8 | void constErrors() 9 | { 10 | const int i = 5; 11 | 12 | ++i; 13 | i++; 14 | --i; 15 | i--; 16 | } 17 | 18 | ; // force error alignment 19 | 20 | 21 | /* error from unsafe and safe pointers */ 22 | 23 | void f1(char * * p) {1;} 24 | void f2(char * *unsafe q) {1;} 25 | 26 | char * * p; 27 | char * *unsafe q; 28 | f1(p); // okay 29 | f1(q); // error 30 | f2(p); // error 31 | f2(q); // okay 32 | 33 | ; // force error alignment 34 | 35 | /* error from goto's and labels */ 36 | lab1 :; // error 37 | ; 38 | goto lab1; // error 39 | ; 40 | 41 | void f3() 42 | { 43 | 44 | 5; 45 | 46 | goto 5; // error 47 | 48 | goto fooey; // error 49 | } 50 | 51 | 52 | /* Illegal array domains specifications */ 53 | 54 | char xx[5][]; 55 | char aa, yy[5][0]; 56 | char vv[5][0] = {"aa"}; 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /test/EiCtests/testerrno.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | assert(errno == 0); 7 | errno = ERANGE; 8 | assert(errno == ERANGE); 9 | errno = 0; 10 | assert(errno == 0); 11 | return 0; 12 | } 13 | 14 | 15 | #ifdef EiCTeStS 16 | main(); 17 | #endif 18 | -------------------------------------------------------------------------------- /test/EiCtests/testescape.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main () { 4 | 5 | printf ("audible alert (bell) BEL \\a %d\n" , '\a'); 6 | printf ("backspace BS \\b %d\n" , '\b'); 7 | printf ("horizontal tab HT \\t %d\n" , '\t'); 8 | printf ("newline LF \\n %d\n" , '\n'); 9 | printf ("vertical tab VT \\v %d\n" , '\v'); 10 | printf ("formfeed FF \\f %d\n" , '\f'); 11 | printf ("carriage return CR \\r %d\n" , '\r'); 12 | printf ("double quote \" \\\" %d\n", '\"'); 13 | printf ("single quote \' \\\' %d\n", '\''); 14 | printf ("question mark ? \\? %d\n" , '\?'); 15 | printf ("backslash \\ \\\\ %d\n", '\\'); 16 | 17 | return 0; 18 | } 19 | 20 | #ifdef EiCTeStS 21 | main(); 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /test/EiCtests/testexit.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | system("eic -g testexit1.aux"); 6 | system("eic -g testexit2.aux"); 7 | system("eic -g testexit3.aux"); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /test/EiCtests/testexit1.aux: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void f1() 5 | { 6 | printf("f1\n"); 7 | } 8 | void f2() 9 | { 10 | printf("f2\n"); 11 | } 12 | void f3() 13 | { 14 | printf("f3\n"); 15 | } 16 | 17 | void T1() 18 | { 19 | atexit(f1); 20 | atexit(f2); 21 | atexit(f3); 22 | 23 | exit(0); 24 | 25 | } 26 | 27 | 28 | int main() 29 | { 30 | T1(); 31 | return 0; 32 | } 33 | #ifdef EiCtEsTs 34 | 35 | main(); 36 | 37 | #endif 38 | 39 | 40 | -------------------------------------------------------------------------------- /test/EiCtests/testexit2.aux: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void f1() 5 | { 6 | printf("f1\n"); 7 | } 8 | void f2() 9 | { 10 | printf("f2\n"); 11 | } 12 | void f3() 13 | { 14 | printf("f3\n"); 15 | } 16 | 17 | void T1() 18 | { 19 | atexit(f3); 20 | atexit(f2); 21 | atexit(f1); 22 | } 23 | 24 | 25 | int main() 26 | { 27 | T1(); 28 | return 0; 29 | } 30 | #ifdef EiCtEsTs 31 | 32 | main(); 33 | 34 | #endif 35 | 36 | 37 | -------------------------------------------------------------------------------- /test/EiCtests/testexit3.aux: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void f1() 5 | { 6 | printf("f1\n"); 7 | } 8 | void f2() 9 | { 10 | printf("f2\n"); 11 | } 12 | void f3() 13 | { 14 | printf("f3\n"); 15 | } 16 | 17 | void T1() 18 | { 19 | atexit(f2); 20 | atexit(f1); 21 | atexit(f3); 22 | } 23 | 24 | 25 | int main(int argc, char ** argv) 26 | { 27 | T1(); 28 | return 0; 29 | } 30 | #ifdef EiCtEsTs 31 | 32 | main(); 33 | 34 | #endif 35 | 36 | 37 | -------------------------------------------------------------------------------- /test/EiCtests/testextern.c: -------------------------------------------------------------------------------- 1 | #include 2 | int i = 5; 3 | 4 | void T1_() 5 | { 6 | extern int i,j; 7 | i = 7; 8 | j = 10; 9 | } 10 | 11 | int j = 3; 12 | 13 | void T1(void) 14 | { 15 | assert(i == 5); 16 | assert(j == 3); 17 | T1_(); 18 | assert(i == 7); 19 | assert(j == 10); 20 | } 21 | 22 | #define N 4 23 | double x[N]; 24 | 25 | 26 | void T2(void) 27 | { 28 | void T2_(void); 29 | T2_(); 30 | assert(x[0] == 10); 31 | assert(x[1] == 20); 32 | assert(x[2] == 30); 33 | assert(x[3] == 40); 34 | } 35 | 36 | void T2_(void) 37 | { 38 | extern double x[N]; 39 | x[0] = 10; 40 | x[1] = 20; 41 | x[2] = 30; 42 | x[3] = 40; 43 | 44 | assert(x[0] == 10); 45 | assert(x[1] == 20); 46 | assert(x[2] == 30); 47 | assert(x[3] == 40); 48 | } 49 | 50 | int main(void) 51 | { 52 | T1(); 53 | T2(); 54 | return 0; 55 | } 56 | 57 | #ifdef EiCTeStS 58 | main(); 59 | #endif 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /test/EiCtests/testfloat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | double radlog; 9 | int digs; 10 | static int radix = FLT_RADIX; 11 | 12 | assert(10 <= DBL_DIG && FLT_DIG <= DBL_DIG); 13 | assert(DBL_EPSILON <= 1e-9); 14 | assert(1e37 <= DBL_MAX); 15 | radlog = log10(radix); 16 | digs = (DBL_MANT_DIG -1)* radlog; 17 | assert(digs <= DBL_DIG && DBL_DIG <= digs+1); 18 | assert(37 <= DBL_MAX_10_EXP); 19 | return 0; 20 | } 21 | 22 | 23 | #ifdef EiCTeStS 24 | main(); 25 | #endif 26 | -------------------------------------------------------------------------------- /test/EiCtests/testfloat2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | 5 | [#6] The translation-time conversion of floating constants 6 | should match the execution-time conversion of character 7 | strings by library functions, such as strtod, given matching 8 | inputs suitable for both conversions, the same result 9 | format, and default execution-time rounding.52) 10 | */ 11 | 12 | #include 13 | 14 | void T1() 15 | { 16 | 17 | double d1, d2, d3,d4; 18 | float f; 19 | d1 = f = 0.7; 20 | d2 = (float) 0.7; 21 | d3 = 0.7F; 22 | d4 = 0.7f; 23 | 24 | 25 | /* 26 | the values assigned to d1, d2, d3 and d4 are required to have been 27 | converted to float. 28 | */ 29 | 30 | 31 | assert(d1 == f); /* EiC fails here */ 32 | assert(d2 == f); 33 | assert(d3 == f); 34 | assert(d4 == f); 35 | assert(f == 0.7F); 36 | 37 | } 38 | 39 | void T2() 40 | { 41 | float f; 42 | double d; 43 | 44 | assert(sizeof(f) == sizeof(0.7F)); 45 | assert(sizeof(d) == sizeof(0.7)); 46 | assert(sizeof(0.7F) <= sizeof(0.7)); 47 | } 48 | 49 | int main() 50 | { 51 | T1(); 52 | T2(); 53 | 54 | return 0; 55 | } 56 | 57 | 58 | #ifdef EiCTeStS 59 | main(); 60 | #endif 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /test/EiCtests/testflow3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define F 5 4 | 5 | 6 | void T1() 7 | { 8 | char c =F; 9 | unsigned char uc = F; 10 | short s =F; 11 | unsigned short us = F; 12 | int i =F; 13 | unsigned int ui = F; 14 | long l = F; 15 | unsigned long ul = F; 16 | float f =F; 17 | double d = F; 18 | 19 | 20 | if(c) c --; 21 | if(uc) uc --; 22 | if(s) s --; 23 | if(us) us--; 24 | if(i) i--; 25 | if(ui) ui--; 26 | if(l) l--; 27 | if(ul) ul--; 28 | 29 | if(f) f -= 1; 30 | if(d) d -= 1; 31 | 32 | assert(c == F -1); 33 | assert(uc == F -1); 34 | assert(s == F -1); 35 | assert(us == F -1); 36 | assert(i == F -1); 37 | assert(ui == F -1); 38 | assert(l == F -1); 39 | assert(ul == F -1); 40 | assert(f == F -1); 41 | assert(d == F -1); 42 | 43 | } 44 | 45 | int main() 46 | { 47 | T1(); 48 | return 0; 49 | } 50 | 51 | 52 | #ifdef EiCTeStS 53 | main(); 54 | #endif 55 | 56 | 57 | -------------------------------------------------------------------------------- /test/EiCtests/testfuncptr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | struct s { 6 | int s; 7 | int (*f1)(char *,...); 8 | int (*f2)(char *,...); 9 | } stype; 10 | 11 | int myprint(char *fmt, ...) 12 | { /* very simple */ 13 | return printf(fmt); 14 | } 15 | 16 | void T1(void) 17 | { 18 | stype.f1 = printf; 19 | stype.f2 = myprint; 20 | 21 | assert(stype.f1("hey\n") == 4); 22 | assert(stype.f2("hey\n") == 4); 23 | } 24 | 25 | void T2(void) 26 | { 27 | int (*f1)(char *,...); 28 | int (*f2)(char *,...); 29 | 30 | f1 = printf; 31 | f2 = myprint; 32 | 33 | assert(f1("hey\n") == 4); 34 | assert(f2("hey\n") == 4); 35 | } 36 | 37 | 38 | void T3(void) 39 | { 40 | int (*f[2])(char *,...); 41 | 42 | f[0] = printf; 43 | f[1] = myprint; 44 | 45 | assert(f[0]("hey\n") == 4); 46 | assert(f[1]("hey\n") == 4); 47 | } 48 | 49 | void T4(void) 50 | { 51 | int (*f)(const char *,...); 52 | 53 | assert(myprint == myprint); 54 | assert(myprint == &myprint); 55 | assert(&myprint == myprint); 56 | assert(printf == printf); 57 | assert(printf == &printf); 58 | assert(&printf == printf); 59 | 60 | f = printf; 61 | 62 | assert(f == printf); 63 | assert(printf == f); 64 | 65 | assert(f == &printf); 66 | assert(&printf == f); 67 | 68 | 69 | } 70 | 71 | int main() 72 | { 73 | T1(); 74 | T2(); 75 | T3(); 76 | 77 | T4(); 78 | return 0; 79 | } 80 | 81 | 82 | #ifdef EiCTeStS 83 | main(); 84 | #endif 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /test/EiCtests/testgotos.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void T1() 4 | { 5 | int x; 6 | 7 | x : 8 | x = 20; 9 | 10 | goto x; // infinite loop 11 | 12 | x = 5; // unreachable code 13 | } 14 | 15 | void T2() 16 | { 17 | int x = 0; 18 | 19 | x: 20 | x += 2; 21 | 22 | if(x < 10) 23 | goto x; 24 | 25 | assert(x >= 10); 26 | } 27 | 28 | 29 | void T3() 30 | { 31 | int f = 30; 32 | 33 | goto end; 34 | 35 | f *= 20; // unreachable code 36 | 37 | end:; 38 | 39 | assert(f == 30); 40 | } 41 | 42 | 43 | void T4() 44 | { 45 | /* what a mess you can make with gotos!!! */ 46 | int i = 1; 47 | int l1 = 0, l2 = 0, l3 = 0; 48 | 49 | goto start; 50 | 51 | l1: l1 = 1; i = 2; goto start; 52 | l2: l2 = 2; i = 3; goto start; 53 | l3: l3 = 3; i = 4; goto end; 54 | 55 | start: 56 | 57 | switch(i) { 58 | case 1: goto l1; 59 | case 2: goto l2; 60 | case 3: goto l3; 61 | } 62 | 63 | end: 64 | assert(i == 4 && l1 == 1 && l2 == 2 && l3 == 3); 65 | } 66 | 67 | int main() 68 | { 69 | 70 | T2(); 71 | T3(); 72 | T4(); 73 | 74 | return 0; 75 | } 76 | 77 | #ifdef EiCTeStS 78 | main(); 79 | #endif 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /test/EiCtests/testinclude.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct Dvector { double x, y; }; 3 | struct Dvector { double x, y; }; 4 | 5 | #undef EiCTeStS 6 | #include testplot.c 7 | :rm main 8 | #include testarray.c 9 | :rm main 10 | #include teststru.c 11 | :rm main 12 | 13 | /* EiC should allow this */ 14 | 15 | #include teststru.c 16 | :rm main 17 | #include testplot.c 18 | :rm main 19 | #include testarray.c 20 | :rm main 21 | 22 | struct Dvector { double x, y; }; 23 | struct Dvector { double x, y; }; 24 | 25 | 26 | /* a bit of torture for EiC */ 27 | 28 | #include 29 | 30 | #undef _STDLIBH 31 | 32 | #include 33 | #include 34 | 35 | int main() 36 | { 37 | assert(atoi("22") == 22); 38 | assert(atof("1.5") == 1.5); 39 | srand(100); 40 | assert(rand() == 12662); 41 | return 0; 42 | } 43 | 44 | 45 | main(); 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /test/EiCtests/testinclude2.aux: -------------------------------------------------------------------------------- 1 | int i = 5; 2 | float x[] = {3,2,1}; 3 | struct {int a, b ;} ab = {20,30}; 4 | int foo() { return 22;} 5 | #include testinclude2a.aux 6 | i == 5; 7 | x[0] == 3; 8 | x[1] == 2; 9 | x[2] == 1; 10 | ab.a == 20; 11 | ab.b == 30; 12 | foo() == 22; 13 | :exit 14 | 15 | -------------------------------------------------------------------------------- /test/EiCtests/testinclude2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | system("eic -g -As < testinclude2.aux"); 6 | return 0; 7 | } 8 | 9 | #ifdef EiCTeStS 10 | main(); 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /test/EiCtests/testinclude2a.aux: -------------------------------------------------------------------------------- 1 | int i = 5*2; 2 | float x[] = {3*2,2*2,1*2}; 3 | struct {int a, b ;} ab = {2*20,2*30}; 4 | 5 | int foo() { return 22*2;} 6 | -------------------------------------------------------------------------------- /test/EiCtests/testinit1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct S0 {int a; char b[5]; double c; }; 5 | struct S0 xs0 = {1, "abcd", 45.0}; 6 | 7 | struct S1 { int a; 8 | struct S2 {double b; 9 | char c;} b; 10 | char c[4]; 11 | }; 12 | 13 | struct S1 xs1 = {22, {5.5}, "ab" }; 14 | 15 | 16 | 17 | int f() {return 1;} 18 | int i1 = 1,i2 = 2,i3 = 3; 19 | 20 | 21 | typedef struct { 22 | int *v; 23 | int (*p)(); 24 | }arg_t; 25 | 26 | arg_t arg[] = {&i1,f,&i2,f,&i3,f}; 27 | 28 | int foo(int * x) 29 | { 30 | const int * p = (int *)x; 31 | return *p; 32 | } 33 | 34 | 35 | 36 | int main() 37 | { 38 | int k = 5; 39 | assert(3 == sizeof(arg)/sizeof(arg_t)); 40 | assert(*arg[0].v == i1 && *arg[1].v == i2 && *arg[2].v == i3); 41 | assert(arg[0].p == f && arg[1].p == f && arg[2].p == f); 42 | assert(xs0.a == 1 && xs0.b[2] == 'c' && xs0.c == 45.0); 43 | assert(xs1.a == 22 && xs1.b.b == 5.5 && xs1.c[2] == 0); 44 | assert(xs1.b.c == 0 && xs1.c[1] == 'b'); 45 | assert(foo(&k) == k); 46 | return 0; 47 | } 48 | 49 | 50 | #ifdef EiCTeStS 51 | main(); 52 | #endif 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /test/EiCtests/testlexerr.c: -------------------------------------------------------------------------------- 1 | /* */ 2 | /* testlexerr.c - written by Martin Gonda, 30-11-95 */ 3 | /* */ 4 | /* code to test the lexer - ie. get as many errors as possible */ 5 | /* generated by the lexan.c, lexer.c modules */ 6 | /* */ 7 | 8 | char a = 'a; /* error: missing single quote */ 9 | 10 | char b = '\0777'; /* error: illegal char oct value */ 11 | /* this gets chewed up due to err */ 12 | /* above */ 13 | 14 | char c = '\x1ff'; /* error: illegal char hex value */ 15 | 16 | char d = '\078'; 17 | 18 | char e[10]="abcdef ; /* error: unbalanced double quote */ 19 | /* error: string literal error */ 20 | 21 | -------------------------------------------------------------------------------- /test/EiCtests/testplot.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | float randg(float mean, float sigma) 6 | { 7 | unsigned i; 8 | float sum; 9 | for (sum = 0, i = 0; i < 12; ++i) { 10 | sum += (double) rand() / (double) RAND_MAX; 11 | } 12 | return (sum - 6 ) * sigma + mean; 13 | } 14 | 15 | int *shell(int *y, int n) 16 | { 17 | int i,j, gap, hy; 18 | for(gap = n >> 1; gap > 0; gap >>= 1) 19 | for(i=gap;i=0 && y[j]>y[j+gap]; j-= gap) { 21 | hy = y[j]; 22 | y[j] = y[j+gap]; 23 | y[j+gap] = hy; 24 | } 25 | return y; 26 | } 27 | 28 | void plothist(int *x, int m) 29 | { 30 | unsigned i, j; 31 | for (i = 0; i < m; ++i, ++x) { 32 | printf("%3d: ", i); 33 | for (j = 0; j < *x; ++j) 34 | printf("*"); 35 | printf("\n"); 36 | } 37 | } 38 | 39 | 40 | void testplot(float std, int x) 41 | { 42 | int i, idx, m, ary[24]; 43 | m = sizeof(ary)/sizeof(int); 44 | 45 | for(i=0;i>1,std)+0.5); 51 | if(idx >= m) 52 | idx = m - 1; 53 | else if(idx < 0) 54 | idx = 0; 55 | ary[idx]++; 56 | } 57 | plothist(ary,m); 58 | } 59 | 60 | 61 | int main() 62 | { 63 | testplot(3,300); 64 | return 0; 65 | } 66 | 67 | #ifdef EiCTeStS 68 | main(); 69 | #endif 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /test/EiCtests/testpopen.c: -------------------------------------------------------------------------------- 1 | /*#include */ 2 | #include 3 | #include 4 | 5 | #define perror(x) fprintf(stderr,x) 6 | void 7 | write_data(FILE *stream) 8 | { 9 | int i; 10 | for (i=0; i<100; i++) 11 | fprintf (stream, "%d\n", i); 12 | if (ferror (stream)) { 13 | fprintf (stderr, "Output to stream failed.\n"); 14 | return; 15 | } 16 | } 17 | 18 | void 19 | read_data(FILE *stream) 20 | { 21 | int i, j; 22 | 23 | for (i=0; i<100; i++) { 24 | if (fscanf (stream, "%d\n", &j) != 1 || j != i) { 25 | if (ferror (stream)) 26 | perror ("fscanf"); 27 | puts ("Test FAILED!"); 28 | return; 29 | } 30 | } 31 | } 32 | 33 | int 34 | main() 35 | { 36 | FILE *output, *input; 37 | int wstatus, rstatus; 38 | 39 | output = popen ("/bin/cat >tstpopen.tmp", "w"); 40 | if (output == NULL) 41 | { 42 | perror ("popen"); 43 | puts ("Test FAILED!"); 44 | return 1; 45 | } 46 | write_data (output); 47 | wstatus = pclose (output); 48 | printf ("writing pclose returned %d\n", wstatus); 49 | input = popen ("/bin/cat tstpopen.tmp", "r"); 50 | if (input == NULL) 51 | { 52 | perror ("tstpopen.tmp"); 53 | puts ("Test FAILED!"); 54 | return 1; 55 | } 56 | read_data (input); 57 | rstatus = pclose (input); 58 | printf ("reading pclose returned %d\n", rstatus); 59 | 60 | puts (wstatus | rstatus ? "Test FAILED!" : "Test succeeded."); 61 | remove("tstpopen.tmp"); 62 | return 1; 63 | } 64 | 65 | 66 | #ifdef EiCTeStS 67 | main(); 68 | #endif 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /test/EiCtests/testpp3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Some simple expressions for testing 4 | * out the preprocessor with 5 | */ 6 | 7 | 8 | #if 5 + 6 > 5 + 7 9 | #error 5 + 6 > 5 + 7 10 | #endif 11 | 12 | #if !(5 + 6 < 5 + 7) 13 | #error !(5 + 6 < 5 + 7) 14 | #endif 15 | 16 | #if 5*3+22-5 != 32 17 | #error 5*3+22-5 != 32 18 | #endif 19 | 20 | #if 0xFFFFFFF < 33 21 | #error 0xFFFFFFF < 33 22 | #endif 23 | 24 | #if SHRT_MAX < CHAR_MAX 25 | #error SHRT_MAX < CHAR_MAX 26 | #endif 27 | 28 | #if INT_MAX < SHRT_MAX 29 | #error INT_MAX < SHRT_MAX 30 | #endif 31 | 32 | #if LONG_MAX < INT_MAX 33 | #error LONG_MAX < INT_MAX 34 | #endif 35 | 36 | #if USHRT_MAX < UCHAR_MAX 37 | #error USHRT_MAX < UCHAR_MAX 38 | #endif 39 | 40 | #if UINT_MAX < USHRT_MAX 41 | #error UINT_MAX < USHRT_MAX 42 | #endif 43 | 44 | #if 0 < CHAR_MIN 45 | #error 0 < CHAR_MIN 46 | #endif 47 | 48 | #if 0 49 | #error 0 50 | #endif 51 | 52 | #if 1<<2 != 4 53 | #error 1<<2 != 4 54 | #endif 55 | 56 | #if 4 != 1<<2 57 | #error 4 != 1<<2 58 | #endif 59 | 60 | #if -1 + 2 != 1 61 | #error -1 + 2 != 1 62 | #endif 63 | 64 | #if 5 < 5 65 | #error 5 < 5 66 | #endif 67 | 68 | #if +5 != 5 69 | #error +5 != 5 70 | #endif 71 | 72 | 73 | /* Character constants */ 74 | 75 | #if 'a' > 'b' 76 | #error 'a' > 'b 77 | #endif 78 | 79 | #if '\23' != 19 80 | #error '\23' != 19 81 | #endif 82 | 83 | #if '\x42' != 'B' 84 | #error '\x42' != 'B' 85 | #endif 86 | 87 | /* Miscellaneous tests */ 88 | 89 | #if !(helloworldnot) - 1 90 | #error !(helloworldnot) - 1 91 | #endif 92 | 93 | 94 | int main(void) 95 | { 96 | return 0; 97 | } 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /test/EiCtests/testpreperr.c: -------------------------------------------------------------------------------- 1 | /* 2 | testpreperr.c 3 | tries to generate as many as possible errors by the preprocessor 4 | section of EiC - to see how robust it is !! 5 | */ 6 | 7 | #if defined LNX 8 | #undef LNX 9 | #endif 10 | 11 | #include #include 12 | #if 13 | 14 | #define `'macro(a,b) (a) - b) 15 | 16 | #ifdef ~#if #else 17 | #~##ifdefine 18 | #define #undef #define 19 | #define #define #undef 20 | #define 21 | 22 | #define PI PI 3.14159 23 | 24 | #ifdef 33 /* error: Illegal macro identifier */ 25 | #endif 26 | #include "stdio.h 27 | #include 2 | 3 | 4 | char a[] = "adsf"; 5 | char *b = a; 6 | char* c = &a[0]; 7 | char *d; 8 | 9 | 10 | assert(a == b && b == c); 11 | d = a; 12 | 13 | assert(d == a); 14 | -------------------------------------------------------------------------------- /test/EiCtests/testqsort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | 7 | int compints(const void *d1, const void *d2) 8 | { 9 | if(*(int *)d1 > *(int*)d2) 10 | return 1; 11 | else if(*(int *)d1 < *(int*)d2) 12 | return -1; 13 | return 0; 14 | } 15 | 16 | 17 | #define print for(i=0;i>1], 37 | *(int*)bsearch(&data[N>>1],data,N,sizeof(int),compints)); 38 | 39 | assert(bsearch(&k,data,N,sizeof(int),compints) == NULL); 40 | 41 | return 0; 42 | } 43 | 44 | #ifdef EiCTeStS 45 | main(); 46 | #endif 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /test/EiCtests/testreturn.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int y; 4 | 5 | int *T(void) 6 | { 7 | return &y; 8 | } 9 | 10 | 11 | int *T1(int y) 12 | { 13 | return &y; /* dangling pointer */ 14 | } 15 | 16 | 17 | int *T2(void) 18 | { 19 | int f; 20 | return &f; /* dangling pointer */ 21 | } 22 | 23 | int *T3(void) 24 | { 25 | static int x; 26 | return &x; 27 | } 28 | 29 | int *T4(int *t) 30 | { 31 | return t; 32 | } 33 | 34 | int *T5(int a[]) 35 | { 36 | return a; 37 | } 38 | 39 | int main(void) 40 | { 41 | printf("This file should generate 2 dangling pointer warnings\n"); 42 | return 0; 43 | } 44 | 45 | #ifdef EiCTeStS 46 | main(); 47 | #endif 48 | -------------------------------------------------------------------------------- /test/EiCtests/testsafeptr.c: -------------------------------------------------------------------------------- 1 | 2 | /* boundary test for safe ptrs */ 3 | /* run -D_EiC -I../include */ 4 | #include 5 | 6 | char *p = "hello"; 7 | p[0];p[4]; p[5]; 8 | 9 | 10 | 11 | char *q = p; 12 | 13 | q[0]; q[5]; 14 | 15 | {char *q, *p = "hello"; p[0];p[5];q=p; q[0];q[5];} 16 | 17 | 18 | 19 | 20 | int a[5]; a[0]; a[4]; 21 | 22 | int aa[2][2]; aa[0][0]; aa[1][1]; 23 | char *pp[] = {"hello", "world"}; 24 | 25 | pp[0][0]; pp[1][5]; 26 | 27 | char *mp = malloc(10); mp[0]; mp[9]; 28 | void foo(char *p) {p[0]; p[9];} foo(mp); 29 | free(mp); 30 | 31 | 32 | int c[2][3] = { {1,2,}, {4,5,}, }; 33 | int *v[2]; 34 | v[0] = c[0]; v[1] = c[1]; 35 | v[0][0]; v[1][2]; c[1][2]; 36 | 37 | 38 | int *ip, i; ip = &i; *ip = 5; i== *ip; 39 | 40 | int ia1d[5]; *ia1d; 41 | 42 | 43 | typedef struct {int x, y;} point_t; 44 | 45 | void ref(){ static point_t p; p.x;} ref(); 46 | 47 | int i1 = 1, i2 = 2; 48 | int *i1_2[] = {&i1,&i2}; 49 | 50 | *i1_2[0]; *i1_2[1]; 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /test/EiCtests/testscanf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | void T1() 7 | { 8 | int in = 555; 9 | char buf[10]; 10 | 11 | sprintf(buf, "|%%%n |",&in); 12 | assert(in == 2); 13 | in = 555; 14 | sscanf(buf, "|%%%n", &in); 15 | assert(in == 2); 16 | } 17 | 18 | void testsscanf(void) 19 | { 20 | char * str = "10.5 hello"; 21 | char buf[50]; 22 | float fval; 23 | sscanf(str,"%f %s",&fval,buf); 24 | assert(fval == 10.5); 25 | assert(strcmp("hello",buf) == 0); 26 | 27 | } 28 | 29 | void testfscanf(void) 30 | { 31 | FILE *fp; 32 | int count; float quant; char units[21], item[21]; 33 | char * tfile = "xx"; 34 | 35 | fp = fopen(tfile,"w+"); 36 | 37 | if(!fp){ 38 | printf("file open fail\n"); 39 | return; 40 | } else 41 | printf("Okay 1\n"); 42 | 43 | fputs("2 quarts of oil\n" 44 | "-12.8 degrees Celsius\n" 45 | "lots of luck\n" 46 | "10.0LBS of\n" 47 | "dirt\n" 48 | "100ergs of energy", 49 | fp); 50 | fseek(fp,0L,SEEK_SET); 51 | 52 | printf("Okay 1\n"); 53 | while(!feof(fp)) { 54 | units[0] = item[0] ='\0'; 55 | count = fscanf(fp,"%f%20s of %20s",&quant, units, item); 56 | fscanf(fp,"%*[^\n]"); 57 | printf("count = [%d] quant = [%g] units = [%s] item = [%s]\n", 58 | count,quant,units,item); 59 | } 60 | fclose(fp); 61 | remove(tfile); 62 | } 63 | 64 | int main(void) 65 | { 66 | testsscanf(); 67 | testfscanf(); 68 | T1(); 69 | return 0; 70 | } 71 | 72 | #ifdef EiCTeStS 73 | main(); 74 | /*"\nTo clean :rm testscanf,testsscanf,testfscanf\n";*/ 75 | #endif 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /test/EiCtests/testscanf2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void T1() 5 | { 6 | int i = 0,cnt = 0; 7 | float f=0; 8 | double d=0; 9 | 10 | char *bad = "x"; 11 | char *good ="567"; 12 | 13 | while(sscanf(bad,"%d", &i)==1) 14 | cnt++; 15 | assert(cnt == 0); 16 | while(sscanf(bad,"%f", &f)==1) 17 | cnt++; 18 | assert(cnt == 0); 19 | while(sscanf(bad,"%lf", &d)==1) 20 | cnt++; 21 | assert(cnt == 0); 22 | 23 | assert(sscanf(bad,"%d",&i) != 1); 24 | assert(sscanf(good,"%d",&i) == 1); 25 | assert(i == 567); 26 | 27 | assert(sscanf(bad,"%f",&f) != 1); 28 | assert(sscanf(good,"%f",&f) == 1); 29 | assert(f == 567); 30 | 31 | assert(sscanf(bad,"%lf",&d) != 1); 32 | assert(sscanf(good,"%lf",&d) == 1); 33 | assert(d == 567); 34 | } 35 | 36 | int main() 37 | { 38 | T1(); 39 | return 0; 40 | } 41 | 42 | #ifdef EiCTeStS 43 | main(); 44 | #endif 45 | -------------------------------------------------------------------------------- /test/EiCtests/testscanf3.aux: -------------------------------------------------------------------------------- 1 | Hi Ed, 2 | 3 | Today I downloaded EiC, and I must say, I really don't regret it! 4 | Great stuff! 5 | 6 | I ran into a little problem however, when I tried to use fscanf, 7 | in (for example): 8 | 9 | 10 | FILE * f = fopen("somefile", "r"); 11 | /* Just a file with some lines of text, separated by newlines */ 12 | /* Perhaps this e-mail will do ;-) */ 13 | char buf[256]; 14 | 15 | while (fscanf(f,"%[^\n]\n",buf) != EOF) printf("%s\n", buf); 16 | 17 | /* If you try this at home, I suggest you use : */ 18 | 19 | int j = 1, maxj = 100; 20 | /* or some convenient number for maxj */ 21 | 22 | while ((fscanf(f,"%[^\n]\n",buf) != EOF) && (j < maxj))\ 23 | printf("Line %i: %s\n", j++, buf); 24 | 25 | There were two problems: 26 | 1: fscanf never gets past the first newline. 27 | 2: later on, (after I fixed 1), I found EOF is never detected. 28 | 29 | I took the liberty of hacking around in _eicUscanf (in stdio.c) 30 | until it worked, and hereby send you the result. 31 | This version is also allows one to use ranges in scansets. 32 | I hope you can use it, and that it doesnot break anything. 33 | (I attached the improved (?) version of _eicUscanf and also 34 | a diff of the new(<) and the old (>) stdio.c) 35 | 36 | Oh, by the way, the makefile for seic (Makefile.seic) misses two 37 | objects, reset.o and callback.o, IIRC. 38 | -------------------------------------------------------------------------------- /test/EiCtests/testscanf3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void T1() 5 | { 6 | char buf[256]; 7 | FILE * f = fopen("testscanf3.aux", "r"); 8 | int j = 1, maxj = 100; 9 | while ((fscanf(f,"%[^\n]\n",buf) != EOF) && (j < maxj)) 10 | printf("Line %i: %s\n", j++, buf); 11 | 12 | fclose(f); 13 | } 14 | 15 | int main(void) 16 | { 17 | T1(); 18 | return 0; 19 | } 20 | 21 | #ifdef EiCTeStS 22 | main(); 23 | #endif 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /test/EiCtests/testsclass.c: -------------------------------------------------------------------------------- 1 | //#!/home/edb/bin/eic -f 2 | 3 | /* the purpose of this test is to test 4 | * the following declarations conflicts, 5 | * when f1 includes f2 and which declares 6 | * the same variable with different storage 7 | * classes: 8 | * f2 9 | * int static extern 10 | * int N Y Y 11 | * f1 static N Y N 12 | * extern Y Y Y 13 | * 14 | * 15 | * N = error 16 | * Y = allowed. 17 | * 18 | */ 19 | 20 | #include 21 | 22 | int a1; 23 | int a2; 24 | int a3; 25 | static int a4; 26 | static int a5; 27 | static int a6; 28 | extern int a7; 29 | extern int a8; 30 | extern int a9; 31 | 32 | 33 | #include testsclass1.aux 34 | 35 | 36 | int a10; 37 | static int a11; 38 | 39 | 40 | :files testsclass.c 41 | :files testsclass1.aux 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /test/EiCtests/testsclass1.aux: -------------------------------------------------------------------------------- 1 | int a1; 2 | static int a2; 3 | extern int a3; 4 | int a4; 5 | static int a5; 6 | extern int a6; 7 | int a7; 8 | static int a8; 9 | extern int a9; 10 | 11 | 12 | static int a10; 13 | static int a11; 14 | 15 | -------------------------------------------------------------------------------- /test/EiCtests/testscop.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void T1(void) 4 | { 5 | int x = 33; 6 | { 7 | float x = 1.5; 8 | { 9 | int x = 2; 10 | { 11 | float x = 3.5; 12 | assert(x == 3.5); 13 | } 14 | assert(x == 2); 15 | } 16 | assert(x == 1.5); 17 | } 18 | assert(x == 33); 19 | } 20 | 21 | void T2(void) 22 | { 23 | int i; 24 | int j =1; 25 | int x[5] = {10,11,12,13,14}; 26 | { 27 | float x[5] = {20,21,22,23,24}; 28 | int j = 2; 29 | { 30 | int x[5] = {30,31,32,33,34}; 31 | int j = 3; 32 | assert(j==3); 33 | for(i=0;i<5;++i) 34 | assert(x[i] == j*10+i); 35 | } 36 | assert(j == 2); 37 | for(i=0;i<5;++i) 38 | assert(x[i] == j*10+i); 39 | } 40 | assert(j == 1); 41 | for(i=0;i<5;++i) 42 | assert(x[i] == j*10+i); 43 | } 44 | 45 | 46 | int main(void) 47 | { 48 | T1(); 49 | T2(); 50 | return 0; 51 | } 52 | 53 | #ifdef EiCTeStS 54 | main(); 55 | #endif 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /test/EiCtests/testshow.c: -------------------------------------------------------------------------------- 1 | /* 2 | * this file is designed to test EiC's show facility 3 | */ 4 | 5 | #define test hasty tasty 6 | #define sum(x,y) ((x) + (y)) 7 | #define empty() 8 | #define empty1() nothing 9 | #define cat(x,y) x ## y 10 | #define mcat(x,y) F ## x ## y ## E 11 | #define item(x) # x 12 | #define order(x,y,z) z + x + y 13 | #define xy(x,y) y + y + x + y + x 14 | 15 | typedef int *IP; /* IP is a pointer to int */ 16 | typedef int (*FP)(); /* FP is a pointer to function returning int */ 17 | typedef int F(int a); /* F is function with one int parameter, */ 18 | /* and it returns an int */ 19 | 20 | typedef double A5[5]; /* A5 is 5-element array of double */ 21 | typedef int A[]; /* A is array of int of undefined size*/ 22 | 23 | void regline(float *x, /* x values */ 24 | float *y, /* y values; i.e., y = f(x) */ 25 | int n, 26 | float *m, /* slope */ 27 | float *b /* offset */ 28 | ) 29 | { 30 | 31 | /* In a least square sense, find the equation: 32 | * y = mx + b; Returns the slope in m and 33 | * the offset in b. 34 | */ 35 | int c; 36 | /* some more comments */ 37 | } 38 | 39 | 40 | void f( void x(int y, int z), int i1, int i2); 41 | void (*f2(int f, int x)) (char * s); 42 | 43 | #ifdef _EiC 44 | :show test 45 | :show sum 46 | :show empty 47 | :show empty1 48 | :show cat 49 | :show mcat 50 | :show item 51 | :show order 52 | :show xy 53 | 54 | :show IP 55 | :show FP 56 | :show F 57 | :show A5 58 | :show A 59 | 60 | /* functions */ 61 | :show f 62 | :show regline 63 | :show f2 64 | 65 | #endif 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /test/EiCtests/testsizeof.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main(void) 6 | { 7 | int a; 8 | long lv; 9 | char c; 10 | char ar[sizeof (long)]; 11 | 12 | assert( strlen("hell of a day") == sizeof("hell of a day") - 1 ); 13 | assert( sizeof(8.8) == sizeof(double) ); 14 | assert( sizeof(15) == sizeof(int) ); 15 | assert( sizeof(struct {int x,y;}) == 2 * sizeof(int) ); 16 | assert( sizeof c == sizeof(char) ); 17 | assert( sizeof a == sizeof(int) ); 18 | assert( 3 * sizeof(int *) == sizeof(int *[3]) ); 19 | assert( sizeof(int *) == sizeof(int (*)[]) ); 20 | assert( sizeof(long) == sizeof((long)1) ); 21 | assert( sizeof (4+5*3) == sizeof (int) ); 22 | assert( sizeof(ar) == sizeof(long) ); 23 | assert( sizeof((long)(1==2)) == sizeof lv ); 24 | 25 | return 0; 26 | } 27 | 28 | 29 | #ifdef EiCTeStS 30 | main(); 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /test/EiCtests/teststatic.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int p = 7; 5 | int q = 5; 6 | 7 | 8 | #include teststatic1.aux 9 | #include teststatic2.aux 10 | #include teststatic3.aux 11 | 12 | #include teststatic4.aux 13 | 14 | static int a10 = 101; 15 | static int a11 = 111; 16 | 17 | void T1() 18 | { 19 | assert(getp1() == 33); 20 | assert(getq1() == 15.5); 21 | assert(p == 7); 22 | assert(q == 5); 23 | } 24 | 25 | void T2(void) 26 | { 27 | assert(getbar() == 3); 28 | } 29 | 30 | void T3() 31 | { 32 | assert(getp3() == 7); 33 | assert(getq3() == 44); 34 | 35 | setp1(50); 36 | assert(p == 7); 37 | assert(getp1() == 50); 38 | assert(getp3() == 7); 39 | 40 | setp3(60); 41 | assert(p == 7); 42 | assert(getp1() == 50); 43 | assert(getp3() == 60); 44 | 45 | p = 22; 46 | assert(p == 22); 47 | assert(getp1() == 50); 48 | assert(getp3() == 60); 49 | } 50 | 51 | 52 | void T4() 53 | { 54 | assert(a10 == 101); 55 | assert(a11 == 111); 56 | assert(geta10() == 10); 57 | assert(geta11() == 11); 58 | } 59 | 60 | int main() 61 | { 62 | T1(); 63 | T2(); 64 | T1(); 65 | T3(); 66 | T4(); 67 | return 0; 68 | } 69 | 70 | #ifdef EiCTeSts 71 | main(); 72 | #endif 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /test/EiCtests/teststatic1.aux: -------------------------------------------------------------------------------- 1 | /* private methods and data */ 2 | static int p = 33; 3 | static float q = 15.5; 4 | 5 | /* public methods and data */ 6 | 7 | void setp1(int x) { p = x;} 8 | int getp1() { return p;} 9 | float getq1() { return q;} 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/EiCtests/teststatic2.aux: -------------------------------------------------------------------------------- 1 | /* private methods and data */ 2 | 3 | static int bar(int p) 4 | { 5 | return p; 6 | } 7 | 8 | int getbar() 9 | { 10 | return bar(3); 11 | } 12 | -------------------------------------------------------------------------------- /test/EiCtests/teststatic3.aux: -------------------------------------------------------------------------------- 1 | static int p = 7; 2 | static float q = 44; 3 | 4 | 5 | int getp3() { return p;} 6 | void setp3(int x) { p = x;} 7 | float getq3() {return q;} 8 | 9 | -------------------------------------------------------------------------------- /test/EiCtests/teststatic4.aux: -------------------------------------------------------------------------------- 1 | 2 | int a10 = 10; 3 | static int a11 = 11; 4 | 5 | int geta10() { return a10;} 6 | int geta11() { return a11;} 7 | 8 | 9 | -------------------------------------------------------------------------------- /test/EiCtests/teststmt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains statements 3 | * that could be entered directly from EiC's command line 4 | * It purpose is to test this facility. 5 | */ 6 | 7 | #include 8 | 9 | int i,x; 10 | 11 | { int i; for(i=0;i<10;i++) x = i;} 12 | 13 | assert(x == 9); 14 | 15 | {\ 16 | int a[5], i; \ 17 | a[0] = 1; a[1] = 2; a[2] = 3; a[3] = 4;\ 18 | a[4] = 5;\ 19 | for(x=i =0;i 5 | #include 6 | 7 | char *a[] = { 8 | "hello", 9 | "world",}; 10 | 11 | char *b[] = { 12 | "hello", 13 | "world",}; 14 | 15 | char *c[] = { 16 | "hello", 17 | "world",}; 18 | 19 | char *d[] = { 20 | "hello", 21 | "world",}; 22 | 23 | char *e[] = { 24 | "hello", 25 | "world",}; 26 | 27 | 28 | 29 | void T1() 30 | { 31 | assert(a != b); 32 | assert(a != c); 33 | assert(a != d); 34 | assert(a != e); 35 | 36 | assert(a[0] == b[0]); 37 | assert(a[0] == c[0]); 38 | assert(a[0] == d[0]); 39 | assert(a[0] == e[0]); 40 | 41 | assert(a[1] == b[1]); 42 | assert(a[1] == c[1]); 43 | assert(a[1] == d[1]); 44 | assert(a[1] == e[1]); 45 | } 46 | 47 | 48 | void T2() 49 | { 50 | assert(strcmp("hello",a[0]) == 0); 51 | assert(strcmp("hello",b[0]) == 0); 52 | assert(strcmp("hello",c[0]) == 0); 53 | assert(strcmp("hello",d[0]) == 0); 54 | assert(strcmp("hello",e[0]) == 0); 55 | 56 | 57 | assert(strcmp("world",a[1]) == 0); 58 | assert(strcmp("world",b[1]) == 0); 59 | assert(strcmp("world",c[1]) == 0); 60 | assert(strcmp("world",d[1]) == 0); 61 | assert(strcmp("world",e[1]) == 0); 62 | } 63 | 64 | int main() 65 | { 66 | T1(); 67 | T2(); 68 | return 0; 69 | } 70 | 71 | #ifdef EiCTeStS 72 | main(); 73 | #endif 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /test/EiCtests/teststru3.c: -------------------------------------------------------------------------------- 1 | /******* 2 | The following code, pulled into EiC using a #include will 3 | report an error with regard to incomplete declarations. We 4 | have a workaround, by using typedef {...} Geometry_e;, but the 5 | bug bears fixing at some point. 6 | ********/ 7 | 8 | #include 9 | 10 | enum Geometry_e { e_SlabGeometry = 1, e_CylindricalGeometry, 11 | e_SphericalGeometry }; 12 | 13 | struct OneD_Hydro_s { 14 | int Version; 15 | enum Geometry_e alpha; 16 | }; 17 | 18 | int main( ) { 19 | 20 | struct OneD_Hydro_s a, b, c; 21 | 22 | a.alpha = e_SlabGeometry; 23 | b.alpha = e_CylindricalGeometry; 24 | c.alpha = e_SphericalGeometry; 25 | 26 | printf( "a = %d\n", a.alpha ); 27 | printf( "b = %d\n", b.alpha ); 28 | printf( "c = %d\n", c.alpha ); 29 | 30 | printf("sizeof = %d\n",(int)sizeof(enum Geometry_e)); 31 | return( 0 ); 32 | } 33 | 34 | #ifdef EiCTeStS 35 | main(); 36 | #endif 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /test/EiCtests/testtime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | int main() 8 | { 9 | char buf[32]; 10 | clock_t tc = clock(); 11 | struct tm ts1; 12 | time_t tt1, tt2; 13 | 14 | static char * dstr = "Sun Dec 2 06:55:15 1979\n"; 15 | 16 | tt1 = time(&tt2); 17 | assert(tt1 == tt2); 18 | 19 | ts1.tm_sec = 15; 20 | ts1.tm_min = 55; 21 | ts1.tm_hour = 6; 22 | ts1.tm_mday = 2; 23 | ts1.tm_mon = 11; 24 | ts1.tm_year = 79; 25 | ts1.tm_isdst = -1; 26 | 27 | #if !defined(_SUNOS) /* hack for bloody non standard SUNOS system */ 28 | tt1 = mktime(&ts1); 29 | assert(ts1.tm_wday == 0); 30 | assert(ts1.tm_yday == 335); 31 | ++ts1.tm_sec; 32 | tt2 = mktime(&ts1); 33 | #else 34 | tt1 = 312926115; 35 | tt2 = 312926116; 36 | #endif 37 | 38 | assert(difftime(tt1,tt2) < 0.0); 39 | assert(strcmp(asctime(localtime(&tt1)),dstr) == 0); 40 | assert(strftime(buf, sizeof(buf),"%S",gmtime(&tt2)) == 2); 41 | assert(strcmp(buf,"16") == 0); 42 | assert(tc <= clock()); 43 | 44 | /* 45 | fputs("Current date -- ", stdout); 46 | time(&tt1); 47 | fputs(ctime(&tt1),stdout); 48 | */ 49 | return 0; 50 | } 51 | 52 | #ifdef EiCTeStS 53 | main(); 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /test/EiCtests/testtrace.c: -------------------------------------------------------------------------------- 1 | int f(void) 2 | { int i; 3 | for(i=0;i<3;++i) 4 | if(i>2) 5 | break; 6 | return i; 7 | } 8 | int g(void) 9 | { int k = 0,i = 2; 10 | while(i--) 11 | k += f(); 12 | return k; 13 | } 14 | int main() 15 | { int i = 2; 16 | do { 17 | int k = g(); 18 | } while(--i); 19 | return 0; 20 | } 21 | 22 | #ifdef EiCTeStS 23 | :trace 24 | main(); 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /test/EiCtests/testtypeerr.c: -------------------------------------------------------------------------------- 1 | char c = 'f'; 2 | unsigned char uc = 'g'; 3 | short s = -2; 4 | unsigned short us = 3; 5 | int i = -4; 6 | unsigned int ui = 7; 7 | long l = 7998; 8 | unsigned long ul = 987535; 9 | float f = -5.2; 10 | double d = 7234.33e-10; 11 | void *vp = 0; 12 | char *cp = &c; 13 | int *ip = &i; 14 | float *fp = &f; 15 | 16 | 17 | typedef struct {int i; char c; float f;} icftype; 18 | icftype icf = {3,'g',4.3,}; /* error: expected { */ 19 | 20 | if (c==i) "c == i"; else "c <> i"; 21 | 22 | c = i; 23 | s = ui; 24 | i = s; 25 | uc = ul; 26 | us = d; 27 | c = f; 28 | 29 | fp--; 30 | fp++; 31 | 32 | vp = cp - ip; /* error: mixed pointer operation */ 33 | fp = fp + fp; /* error: incompatible types */ 34 | fp -= fp; /* warning: Suspicious pointer conversion*/ 35 | fp = fp - fp; /* warning: Suspicious pointer conversion*/ 36 | ip = vp - 1; /* error: illegal pointer operation */ 37 | ip = fp - 1; 38 | f = 3.1 % f; /* error: illegal binary operation to `%' */ 39 | ip = (int*) d; 40 | d = !f+!f; 41 | d = ~f; 42 | i = -ip; 43 | c = (char) +cp; 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /test/EiCtests/testunsafeptr1.c: -------------------------------------------------------------------------------- 1 | 2 | /* default pointer type should be safe */ 3 | #include 4 | 5 | 6 | int *pABC; 7 | int * safe qABC; 8 | int * unsafe rABC; 9 | assert(sizeof(pABC) == sizeof(qABC)); 10 | assert(sizeof(pABC) > sizeof(rABC)); 11 | 12 | 13 | #pragma push_unsafeptr 14 | 15 | int *pBCD; 16 | int * safe qBCD; 17 | int * unsafe rBCD; 18 | assert(sizeof(pBCD) < sizeof(qBCD)); 19 | assert(sizeof(pBCD) == sizeof(rBCD)); 20 | 21 | 22 | 23 | #include testaryptr.c 24 | 25 | 26 | 27 | #pragma pop_ptr 28 | 29 | int *pCDE; 30 | int * safe qCDE; 31 | int * unsafe rCDE; 32 | assert(sizeof(pCDE) == sizeof(qCDE)); 33 | assert(sizeof(pCDE) > sizeof(rCDE)); 34 | 35 | 36 | -------------------------------------------------------------------------------- /test/EiCtests/testunsafeptr2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | system("eic -g -sA < testunsafeptr2.aux"); 5 | return 0; 6 | } 7 | 8 | #ifdef EiCTeStS 9 | main(); 10 | #endif 11 | -------------------------------------------------------------------------------- /test/EiCtests/testunsafeptr3.aux: -------------------------------------------------------------------------------- 1 | 2 | #pragma push_unsafeptr 3 | 4 | ""; 5 | #include testfloat.c 6 | main(); 7 | :clear testfloat.c 8 | 9 | ""; 10 | #include testflow.c 11 | main(); 12 | :clear testflow.c 13 | 14 | ""; 15 | #include testflow2.c 16 | main(); 17 | :clear testflow2.c 18 | 19 | ""; 20 | #include testfunc.c 21 | main(); 22 | :clear testfunc.c 23 | 24 | ""; 25 | #include testinit1.c 26 | main(); 27 | :clear testinit1.c 28 | 29 | ""; 30 | #include testinit2.c 31 | main(); 32 | :clear testinit2.c 33 | 34 | ""; 35 | #include testlexer.c 36 | main(); 37 | :clear testlexer.c 38 | 39 | ""; 40 | #include testlimits.c 41 | main(); 42 | :clear testlimits.c 43 | 44 | ""; 45 | #include testlimits2.c 46 | main(); 47 | :clear testlimits2.c 48 | 49 | ""; 50 | #include testlogi.c 51 | main(); 52 | :clear testlogi.c 53 | 54 | 55 | ""; 56 | #include testpopen.c 57 | main(); 58 | :clear testpopen.c 59 | 60 | ""; 61 | #include testpp2.c 62 | :clear testpp2.c 63 | 64 | ""; 65 | #include testpp3.c 66 | main(); 67 | :clear testpp3.c 68 | 69 | ""; 70 | #include testprintf.c 71 | main(); 72 | :clear testprintf.c 73 | 74 | #include 75 | assert(sizeof(int *) < sizeof(int * safe)); 76 | 77 | :exit 78 | 79 | -------------------------------------------------------------------------------- /test/EiCtests/testunsafeptr3.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | system("eic -g -sA < testunsafeptr3.aux"); 5 | return 0; 6 | } 7 | 8 | #ifdef EiCTeStS 9 | main(); 10 | #endif 11 | -------------------------------------------------------------------------------- /test/EiCtests/testunsafeptr4.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | system("eic -g -sA < testunsafeptr4.aux"); 5 | return 0; 6 | } 7 | 8 | #ifdef EiCTeStS 9 | main(); 10 | #endif 11 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | ######################### 2 | # Part 1: LOCAL DEFINITIONS 3 | 4 | TOP = .. 5 | EXTRA = 6 | WARNINGS = 7 | INCLUDES = 8 | LIB = 9 | 10 | DEP_LIBS = 11 | LIBS = 12 | 13 | ################################################# 14 | # INSTALL_DIR can be any directory 15 | # that is in your normal search path; 16 | # such as, /usr/local/bin, etc 17 | ################################################# 18 | 19 | ## 'INSTALL_DIR' is globally set in $(TOP)/project.params 20 | ##INSTALL_DIR = $(HOME)/bin 21 | 22 | 23 | 24 | ######################### 25 | # Part 2: COMMON MAKE PARAMETERS 26 | 27 | include $(TOP)/make.proj 28 | 29 | ######################### 30 | # Part 3: LOCAL SOURCES 31 | 32 | TSTDIRS = gnutests testcode lcctest posix.1 33 | 34 | 35 | ######################### 36 | # Part 4: LOCAL TARGETS 37 | 38 | #### runtest and shell scripts 39 | 40 | $(INSTALL_DIR)/eictester:runtest 41 | cp runtest $(INSTALL_DIR)/eictester 42 | all:: 43 | install::$(INSTALL_DIR)/eictester 44 | clean:: 45 | find . -name "*.diff" | xargs $(RM) 46 | find . -name "*.out" | xargs $(RM) 47 | 48 | clobber::clean 49 | $(RM) $(INSTALL_DIR)/eictester 50 | 51 | ####### HEADERS 52 | headers:: 53 | 54 | ######################### 55 | # Part 5: COMMON RULES and 56 | # and default Targets 57 | 58 | include $(CONFIG_DIR)/make.rules 59 | 60 | ######################### 61 | # Part 6: DEPENDENCIES 62 | 63 | -------------------------------------------------------------------------------- /test/eicScripts/Driver.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | #include "tools/nxtString.c" 6 | 7 | int main() 8 | { 9 | FILE *fp; 10 | char *p; 11 | 12 | system("ls *.eic > /tmp/123eicList"); 13 | 14 | fp = fopen("/tmp/123eicList","r"); 15 | if(!fp) { 16 | fprintf(stderr,"failed to open /tmp/123eicList\n"); 17 | exit(0); 18 | } 19 | 20 | while((p=nxtString(fp))) { 21 | printf("\n running %s\n",p); 22 | system(p); 23 | } 24 | 25 | fclose(fp); 26 | 27 | return 0; 28 | } 29 | 30 | 31 | #ifdef EiCTeStS 32 | main(); 33 | #endif 34 | -------------------------------------------------------------------------------- /test/eicScripts/script1.eic: -------------------------------------------------------------------------------- 1 | #!/home/edb/bin/eic -f 2 | 3 | #include 4 | 5 | printf("\n\t **** Hello from EiC's script mode **** \n\n"); 6 | 7 | 8 | // example of control of flow 9 | 10 | int i; 11 | int isqr(int x) { return x*x; } 12 | 13 | for(i=0;i<4;i++) 14 | printf("%d^2 = %d\n",i,isqr(i)); 15 | 16 | switch(i) { 17 | case 4: printf(" good\n\n"); break; 18 | default: printf(" bad\n\n"); 19 | } 20 | 21 | // example of some file stuff; 22 | // read in some tools 23 | #include "tools/nxtString.c" 24 | 25 | FILE *fp = fopen(_Argv[0],"r"); 26 | char *p; 27 | while((p=nxtString(fp))) 28 | printf("%s ",p); 29 | printf("\n\n"); 30 | fclose(fp); 31 | 32 | 33 | 34 | // Further example of using command line args 35 | 36 | if(_Argc) { 37 | int k=0; 38 | printf("Processing command line arguments\n"); 39 | for(k=0;k<_Argc;k++) { 40 | printf("%s\n",_Argv[k]); 41 | } 42 | } else 43 | printf("NO command line arguments passed\n"); 44 | 45 | 46 | -------------------------------------------------------------------------------- /test/eicScripts/script2.eic: -------------------------------------------------------------------------------- 1 | #!/home/edb/bin/eic -f 2 | 3 | #include 4 | 5 | 6 | printf("hello 1\n"); 7 | 8 | int main() 9 | { 10 | printf("hello 2\n"); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /test/eicScripts/www_eic.eic: -------------------------------------------------------------------------------- 1 | #!/home/edb/bin/eic -f 2 | int printf(char *fmt,...); // prototype for printf 3 | printf("hello, world wide web!\n"); 4 | 5 | -------------------------------------------------------------------------------- /test/gnutests/forgnuport.h: -------------------------------------------------------------------------------- 1 | #ifndef _FORGNUPORTH 2 | #define _FORGNUPORTH 3 | 4 | #include 5 | #include 6 | 7 | #define abort() printf("Failure on line %d\n",__LINE__) 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /test/gnutests/gnu1.c: -------------------------------------------------------------------------------- 1 | unsigned char msgi[10] = {0x10, 0x09, 0x88, 0xaa, 0x22, 0x09}; 2 | #define MAGIC 0125252 /* checksum is subtracted from this */ 3 | 4 | int main() 5 | { 6 | unsigned short pktsum, oursum; 7 | 8 | pktsum = msgi[2] + (msgi[3] << 8); 9 | 10 | /* Check checksums for control packets */ 11 | oursum = MAGIC - msgi[4]; 12 | if (pktsum != oursum) 13 | printf("control checksum bad %x %x\n", pktsum, oursum); 14 | else 15 | printf("Test passed\n"); 16 | } 17 | 18 | #ifdef EiCTeStS 19 | main(); 20 | #endif 21 | -------------------------------------------------------------------------------- /test/gnutests/gnu11.c: -------------------------------------------------------------------------------- 1 | /* DEJAGNU_OUTPUT:"Failed (if it compiled at all)..." */ 2 | 3 | int main(void) 4 | { 5 | int s; 6 | 7 | s = sizeof main; 8 | printf("Failed (if it compiled at all)...\n"); 9 | return 0; 10 | } 11 | 12 | #ifdef EiCTeStS 13 | main(); 14 | #endif 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/gnutests/gnu12.c: -------------------------------------------------------------------------------- 1 | /* 2 | Deceived: by hoptoad.uucp (1.1/SMI-3.0DEV3) 3 | id AA08037; Wed, 1 Apr 87 03:40:07 PST 4 | Message-Id: <8704010914.AA23555@prep.ai.mit.edu> 5 | Date: 31 Mar 1987 2359-PST (Tuesday) 6 | From: Malcolm Wing 7 | To: bug-gcc@prep.ai.mit.edu 8 | Subject: Clobber nil bug and Tail recursion bug 9 | 10 | BUG 2 11 | When compiling Ackerman for the vax it tries to remove the 12 | tail recursion. However the tail recursive call contains another 13 | call so the update (used to be parameter passing) can't be done 14 | until the imbedded call returns. 15 | 16 | SOURCE 17 | 18 | /* Ackerman's function */ 19 | 20 | int A(int x,int y); 21 | 22 | int main(void) 23 | { 24 | int i; 25 | 26 | i = A(3,6); 27 | if (i == 509) 28 | printf("Test passed\n"); 29 | else 30 | printf("FAILED ackerman's(3, 6): %d\n", i); 31 | return 0; 32 | } 33 | 34 | int A(int x,int y) 35 | { 36 | 37 | if(x==0) return(++y); 38 | if(y==0) return(A(--x,1)); 39 | return(A(x-1,A(x,--y))); 40 | } 41 | 42 | #ifdef EiCTeStS 43 | main(); 44 | #endif 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /test/gnutests/gnu14.c: -------------------------------------------------------------------------------- 1 | /* 2 | Return-Path: 3 | Date: Tue, 23 Jun 87 17:17:38 +0200 4 | From: H}vard Eidnes 5 | To: 6 | Message-Id: <2178:H_Eidnes@vax.runit.unit.uninett> 7 | Subject: Spurious error-message (?) from GCC 8 | 9 | The following is an exerpt from a header file from the X Window 10 | System, version 10r3. 11 | 12 | GCC (version 1.5) says: 13 | /usr/include/X/Xlib.h:108: declaration of table invalidly omits array size 14 | */ 15 | 16 | typedef struct _x_assoc_table { 17 | struct _x_assoc (*table)[]; /* Array of association queues. */ 18 | int size; /* Table size. */ 19 | } XAssocTable; 20 | 21 | int main(void) { 22 | printf("Test passed\n"); 23 | return 0; 24 | } 25 | 26 | #ifdef EiCTeStS 27 | main(); 28 | #endif 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /test/gnutests/gnu15.c: -------------------------------------------------------------------------------- 1 | /* 2 | Date: Sun, 5 Jul 87 18:24:54 PDT 3 | From: andy@csvax.caltech.edu (Andy Fyfe) 4 | To: bug-gcc@prep.ai.mit.edu 5 | Subject: unsigned -> float conversion 6 | */ 7 | 8 | int main(void) 9 | { 10 | unsigned u = 0x80000000; 11 | 12 | printf("(f)u = %g\n", (float)u); 13 | printf("(f)(u)0x80000000 = %g\n", (float)(unsigned)0x80000000); 14 | return 0; 15 | } 16 | 17 | /* 18 | Using 68020/68881 the above gives: 19 | 20 | (f)u = 2.14748e+09 21 | (f)(u)0x80000000 = -2.14748e+09 22 | 23 | Using 68020/soft-float the above gives: 24 | 25 | (f)u = -2.14748e+09 26 | (f)(u)0x80000000 = -2.14748e+09 27 | 28 | gcc, version 1.6, compiled on a sun3 by gcc itself. 29 | */ 30 | 31 | 32 | #ifdef EiCTeStS 33 | main(); 34 | #endif 35 | -------------------------------------------------------------------------------- /test/gnutests/gnu16.c: -------------------------------------------------------------------------------- 1 | int install = !0; /* Gcc 1.16 said "initializer is not constant" */ 2 | /* Gcc 1.17 gets wrong answer! */ 3 | char foo = !1; 4 | int bar = !3.14156; /* SunOS 3.3 cc said "Illegal initialization" */ 5 | int pno = ! &bar; /* Gcc 1.17 said "initializer for static variable 6 | uses complex arithmetic" */ 7 | int pyes = !(char *)0; 8 | 9 | int main() { 10 | if (install && !foo && !bar && pyes && !pno) 11 | printf("Test passed\n"); 12 | else 13 | printf("FAILED, install=%d, foo=%d, bar=%d, pno=%d, pyes=%d\n", 14 | install, foo, bar, pno, pyes); 15 | return 0; 16 | } 17 | 18 | 19 | #ifdef EiCTeStS 20 | main(); 21 | #endif 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/gnutests/gnu18.c: -------------------------------------------------------------------------------- 1 | /* 2 | Date: Sat, 5 Sep 87 00:34:13 PDT 3 | From: gnu (John Gilmore) 4 | To: rms 5 | Subject: Stack adjustment bug in 'continue' -- gcc 1.10+ 6 | 7 | Compiling the following simplified program with or without -O produces 8 | bad code. The 'continue' compiles to a jump to a label which PRECEDES 9 | the stack adjust for the printf at the end of the loop. This makes the 10 | stack pointer walk up each time around the loop. If you compile without 11 | -O, "foo" gets allocated on the stack and the debug printf fires. 12 | Compiled with -O, it coredumps before printing. Compiled on a working 13 | compiler, it loops forever. 14 | 15 | I have installed the bugfix for while loops posted to bug-gcc; it fails 16 | with or without the bugfix. 17 | */ 18 | 19 | int tty; 20 | 21 | int iscmd() 22 | { 23 | static int counter; 24 | if (counter++ < 10000) return 0; 25 | printf("Test passed\n"); 26 | return -1; 27 | } 28 | 29 | int main(void) 30 | { 31 | int k; 32 | int foo = 0; 33 | 34 | for ( ;; ) { 35 | if (foo != 0) printf("***BUG*** foo=%x\n", foo); 36 | if (!tty) { 37 | if (!(k = iscmd ())) 38 | continue; 39 | if(k== -1) 40 | return 1; 41 | foo = 1; 42 | } 43 | 44 | printf("**BUG** Past iscmd\n"); 45 | } 46 | 47 | return 0; 48 | } 49 | 50 | #ifdef EiCTeStS 51 | main(); 52 | #endif 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /test/gnutests/gnu21.c: -------------------------------------------------------------------------------- 1 | /* 2 | Message-Id: <8712292244.AA24155@prep.ai.mit.edu> 3 | Date: Mon, 28 Dec 87 21:05:20 PST 4 | From: Greg Satz 5 | To: bug-gcc@prep.ai.mit.edu 6 | Subject: Error handling bug? 7 | 8 | The following program causes cc1 to make a core file. Since it was 9 | caused by a syntax error, I didn't spend that much time tracking it 10 | down. I was able to reduce the example to this small result. Could 11 | someone check to see if this bug exists in the Vax and Sun versions as 12 | well and let me know? Thanks! 13 | */ 14 | 15 | int global; 16 | 17 | int main(void) 18 | { 19 | int ch; 20 | 21 | if (global) { 22 | printf("here"); 23 | } else { 24 | if (((ch & 0x7f) == 0)) && (ch & 1) { /* syntax error here */ 25 | if (!ch) 26 | return(0); 27 | ch = 0; 28 | } 29 | } 30 | return 0; 31 | } 32 | 33 | #ifdef EiCTeStS 34 | main(); 35 | #endif 36 | -------------------------------------------------------------------------------- /test/gnutests/gnu24.c: -------------------------------------------------------------------------------- 1 | /* From Sun-Spots v6n12 2 | Date: 26 Jan 88 15:58:58 CST (Tue) 3 | From: uunet!mcrware!jejones@ut-sally.UUCP 4 | Subject: ?: vs. pointer to function "returning" void 5 | 6 | I find that on a Sun 3, the C compiler complains about code of the following 7 | form with a message "operands of : have incompatible types." I don't think 8 | this is correct, because woof1 and woof2 are both pointers to functions 9 | "returning" void, so that (pointer to function returning void) should be 10 | the type of the actual parameter. Right? 11 | 12 | Have other people seen this problem? Is it, if it is indeed a problem 13 | with the Sun C compiler, fixed in some release? 14 | 15 | James Jones 16 | */ 17 | 18 | void woof1() {}; 19 | void woof2() {}; 20 | 21 | void bletch( void (*x)()) 22 | { 23 | } 24 | 25 | 26 | int main(int i, char **argv) 27 | { 28 | bletch(i ? woof1 : woof2); 29 | printf("Test passed (if it compiled at all)\n"); 30 | return 0; 31 | } 32 | 33 | #ifdef EiCTeStS 34 | main(1,NULL); 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /test/gnutests/gnu26.c: -------------------------------------------------------------------------------- 1 | /* 2 | Deceived: by hoptoad.uucp (1.1/SMI-3.0DEV3) 3 | id AA08037; Wed, 1 Apr 87 03:40:07 PST 4 | Message-Id: <8704010914.AA23555@prep.ai.mit.edu> 5 | Date: 31 Mar 1987 2359-PST (Tuesday) 6 | From: Malcolm Wing 7 | To: bug-gcc@prep.ai.mit.edu 8 | Subject: Clobber nil bug and Tail recursion bug 9 | 10 | BUG 2 11 | When compiling Ackerman for the vax it tries to remove the 12 | tail recursion. However the tail recursive call contains another 13 | call so the update (used to be parameter passing) can't be done 14 | until the imbedded call returns. 15 | 16 | SOURCE 17 | 18 | /* Ackerman's function */ 19 | 20 | 21 | 22 | int A(int x,int y) 23 | { 24 | if(x==0) return(++y); 25 | if(y==0) return(A(--x,1)); 26 | return(A(x-1,A(x,--y))); 27 | } 28 | 29 | /* This one is more in the true spirit of the original Algol code. */ 30 | int B(int m,int n) 31 | { 32 | return m==0 ? n+1 : n==0 ? B(m-1,1) : B(m-1,B(m,n-1)); 33 | } 34 | 35 | /* Try it with subtract/add rather than ++ and -- */ 36 | int C(int x,int y) 37 | { 38 | if(x==0) return(y+1); 39 | if(y==0) return(C(x-1,1)); 40 | return(C(x-1,C(x,y-1))); 41 | } 42 | 43 | 44 | int main(void) 45 | { 46 | int i, j; 47 | 48 | i = A(3,6); 49 | j = B(3,6); 50 | if (i == 509 && j == 509 && i == j) 51 | printf("Test passed\n"); 52 | else 53 | printf("FAILED ackerman's(3, 6): %d, %d\n", i, j); 54 | return 0; 55 | } 56 | 57 | #ifdef EiCTeStS 58 | main(); 59 | #endif 60 | -------------------------------------------------------------------------------- /test/gnutests/gnu28.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | From: uunet!mcvax!sor.inria.fr!tiemann (Mike Tiemann) 4 | Date: Sun, 4 Sep 88 11:15:27 +0100 5 | 6 | I got all your tests working (except str1597a.c), and the compiler 7 | bootstrapping itself, and I thought I was done. Then I remembered 8 | *my* favorite test program...which used to work, but now fails again. 9 | Here it is, for your collecting joy: 10 | 11 | [Altered in obvious ways to avoid using function prototypes -- gnu] 12 | */ 13 | 14 | #include 15 | 16 | /* a reasonably sized structure. */ 17 | typedef struct foo 18 | { 19 | int x[57]; 20 | } foo; 21 | 22 | int bad = 0; 23 | 24 | foo sum ( foo x, foo y) 25 | { 26 | foo s; 27 | int i; 28 | 29 | for (i = 0; i < 57; i++) 30 | { 31 | if (x.x[i] != 1) {printf("sum x[%d] = %d\n", i, x.x[i]); bad++;} 32 | if (y.x[i] != 2) {printf("sum y[%d] = %d\n", i, y.x[i]); bad++;} 33 | s.x[i] = x.x[i] + y.x[i]; 34 | } 35 | return s; 36 | } 37 | 38 | foo init (int val) 39 | { 40 | foo s; 41 | int i; 42 | 43 | for (i = 0; i < 57; i++) 44 | s.x[i] = val; 45 | return s; 46 | } 47 | 48 | int main (void) 49 | { 50 | foo s; 51 | foo t; 52 | int i; 53 | 54 | s = sum (init (1), init (2)); 55 | t = sum (init (1), init (2)); 56 | 57 | for (i = 0; i < 57; i++) 58 | if (s.x[i] != 3 || t.x[i] != 3) { 59 | printf ("failure at %i\n", i); 60 | bad++; 61 | } 62 | if (bad) printf ("Failed %d ways.\n", bad); 63 | else printf ("Test passed.\n"); 64 | return 0; 65 | } 66 | 67 | 68 | #ifdef EiCTeStS 69 | main(); 70 | #endif 71 | -------------------------------------------------------------------------------- /test/gnutests/gnu3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * From ptsfa!ames!hc!siegel Tue Nov 24 15:38:28 1987 3 | * From: siegel@hc.DSPO.GOV (Josh Siegel) 4 | * Newsgroups: comp.bugs.4bsd 5 | * Subject: Bug in Sun compiler... 6 | * Message-ID: <11636@hc.DSPO.GOV> 7 | * Date: 24 Nov 87 23:38:28 GMT 8 | * Organization: Los Alamos National Laboratory 9 | * 10 | * The program causes Suns compiler to generate code that 11 | * has a Segmentation fault upon exiting. 12 | * 13 | * The reason being that Sun don't check to see if you specificly 14 | * returned a structure. The register d0 is null and it offsets 15 | * through it. 16 | * 17 | * Vax and GNU do this correctly... 18 | */ 19 | 20 | struct { 21 | int a,b,c; 22 | } 23 | bar(void) 24 | {} 25 | 26 | int main(void) 27 | { 28 | bar(); 29 | printf("Test passed\n"); 30 | } 31 | 32 | #ifdef EiCTeStS 33 | main(); 34 | #endif 35 | 36 | 37 | -------------------------------------------------------------------------------- /test/gnutests/gnu4.c: -------------------------------------------------------------------------------- 1 | int bar(int i) 2 | {} 3 | 4 | struct s {int x[5];}; 5 | 6 | int main() 7 | { 8 | struct s {struct s *next; int i;}; 9 | static struct s sa[2]; 10 | 11 | /* bar(sa[0].next->x[4]); */ 12 | printf("Test passed (if it compiled)\n"); 13 | return 0; 14 | bar(sa[0].next->i); 15 | } 16 | 17 | #ifdef EiCTeStS 18 | main(); 19 | #endif 20 | -------------------------------------------------------------------------------- /test/gnutests/gnu6.c: -------------------------------------------------------------------------------- 1 | static int it1, it3; 2 | int i1 = 4, i2 = 7; 3 | int main(void) 4 | { 5 | if ( (it3 = (it1 = i1) + (it1 = i2)) == i1+i2 ) 6 | printf("Test passed\n"); 7 | else 8 | printf("Failed...\n"); 9 | } 10 | 11 | #ifdef EiCTeStS 12 | main(); 13 | #endif 14 | -------------------------------------------------------------------------------- /test/gnutests/gnu7.c: -------------------------------------------------------------------------------- 1 | #define Neg -113 2 | static unsigned int ui2 = Neg; 3 | int main(void) { 4 | if ( ui2/2 == ((unsigned)Neg)/2 ) 5 | printf("Test passed\n"); 6 | else 7 | printf("Failed...\n"); 8 | return 0; 9 | } 10 | 11 | #ifdef EiCTeStS 12 | main(); 13 | #endif 14 | -------------------------------------------------------------------------------- /test/gnutests/gnu8.c: -------------------------------------------------------------------------------- 1 | #define Neg -113 2 | static unsigned int ui2 = Neg; 3 | int main(void) { 4 | if ( ui2%2 == ((unsigned)Neg)%2 ) 5 | printf("Test passed\n"); 6 | else 7 | printf("Failed...\n"); 8 | return 0; 9 | } 10 | 11 | #ifdef EiCTeStS 12 | main(); 13 | #endif 14 | -------------------------------------------------------------------------------- /test/gnutests/t2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int a[] = 4 | { 5 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 6 | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 7 | 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 8 | 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 9 | }; 10 | 11 | int 12 | f (int n) 13 | { 14 | return a[n - 100000]; 15 | } 16 | 17 | int main (void) 18 | { 19 | assert(f(100030) == 30); 20 | return 0; 21 | } 22 | 23 | #ifdef EiCTeStS 24 | main(); 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /test/gnutests/t3.c: -------------------------------------------------------------------------------- 1 | #include 2 | int a[2]; 3 | 4 | void f (int b) 5 | { 6 | unsigned int i; 7 | for (i = 0; i < b; i++) 8 | a[i] = i - 2; 9 | } 10 | 11 | int main (void) 12 | { 13 | a[0] = a[1] = 0; 14 | f (2); 15 | assert(a[0] == -2 && a[1] == -1); 16 | return 0; 17 | } 18 | 19 | #ifdef EiCTeStS 20 | main(); 21 | #endif 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /test/gnutests/t4.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main (void) 3 | { 4 | int i, j, k[3]; 5 | j = 0; 6 | for (i=0; i < 3; i++) 7 | { 8 | k[i] = j++; 9 | } 10 | 11 | for (i=2; i >= 0; i--) 12 | assert(k[i] == i); 13 | return 0; 14 | } 15 | 16 | #ifdef EiCTeStS 17 | main(); 18 | #endif 19 | -------------------------------------------------------------------------------- /test/gnutests/t5.c: -------------------------------------------------------------------------------- 1 | #include "forgnuport.h" 2 | 3 | void f(int *x) 4 | { 5 | *x = 0; 6 | } 7 | 8 | char a[] = "c"; 9 | void main() 10 | { 11 | int s, c, x; 12 | 13 | f(&s); 14 | a[c = 0] = s == 0 ? (x=1, 'a') : (x=2, 'b'); 15 | if (a[c] != 'a') 16 | abort(); 17 | else 18 | printf("Passed\n"); 19 | } 20 | 21 | #ifdef EiCTeStS 22 | main(); 23 | #endif 24 | -------------------------------------------------------------------------------- /test/gnutests/testdiv1.c: -------------------------------------------------------------------------------- 1 | #include "forgnuport.h" 2 | 3 | int div1 ( 4 | signed char x) 5 | { 6 | return x / -1; 7 | } 8 | 9 | int div2 ( 10 | signed short x) 11 | { 12 | return x / -1; 13 | } 14 | 15 | int div3 ( 16 | signed char x, 17 | signed char y) 18 | { 19 | return x / y; 20 | } 21 | 22 | int div4 ( 23 | signed short x, 24 | signed short y) 25 | { 26 | return x / y; 27 | } 28 | 29 | int mod1 ( 30 | signed char x) 31 | { 32 | return x % -1; 33 | } 34 | 35 | int mod2 ( 36 | signed short x) 37 | { 38 | return x % -1; 39 | } 40 | 41 | int mod3 ( 42 | signed char x, 43 | signed char y) 44 | { 45 | return x % y; 46 | } 47 | 48 | int mod4 ( 49 | signed short x, 50 | signed short y) 51 | { 52 | return x % y; 53 | } 54 | 55 | int main (void) 56 | { 57 | if (div1 (-(1 << 7)) != 1 << 7) 58 | abort (); 59 | if (div2 (-(1 << 15)) != 1 << 15) 60 | abort (); 61 | if (div3 (-(1 << 7), -1) != 1 << 7) 62 | abort (); 63 | if (div4 (-(1 << 15), -1) != 1 << 15) 64 | abort (); 65 | if (mod1 (-(1 << 7)) != 0) 66 | abort (); 67 | if (mod2 (-(1 << 15)) != 0) 68 | abort (); 69 | if (mod3 (-(1 << 7), -1) != 0) 70 | abort (); 71 | if (mod4 (-(1 << 15), -1) != 0) 72 | abort (); 73 | return 0; 74 | } 75 | 76 | 77 | #ifdef EiCTeStS 78 | main(); 79 | #endif 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /test/gnutests/tststruct-big.c: -------------------------------------------------------------------------------- 1 | #include "forgnuport.h" 2 | 3 | typedef struct {int a, b, c, d, e;} T; 4 | 5 | void h (T *x); 6 | T g (T x); 7 | 8 | void h (T *x) 9 | { 10 | if (x->a != 0 || x->b != 1 || x->c != 2 || x->d != 3 || x->e != 4) 11 | abort (); 12 | } 13 | 14 | 15 | T g (T x) 16 | { 17 | if (x.a != 13 || x.b != 47 || x.c != 123456 || x.d != -4711 || x.e != -2) 18 | abort (); 19 | x.a = 0; 20 | x.b = 1; 21 | x.c = 2; 22 | x.d = 3; 23 | x.e = 4; 24 | h (&x); 25 | return x; 26 | } 27 | 28 | 29 | void f () 30 | { 31 | T x; 32 | x.a = 13; 33 | x.b = 47; 34 | x.c = 123456; 35 | x.d = -4711; 36 | x.e = -2; 37 | g (x); 38 | if (x.a != 13 || x.b != 47 || x.c != 123456 || x.d != -4711 || x.e != -2) 39 | abort (); 40 | x = g (x); 41 | if (x.a != 0 || x.b != 1 || x.c != 2 || x.d != 3 || x.e != 4) 42 | abort (); 43 | } 44 | 45 | 46 | int main (void) 47 | { 48 | f (); 49 | return 0; 50 | } 51 | 52 | #ifdef EiCTeStS 53 | main(); 54 | #endif 55 | -------------------------------------------------------------------------------- /test/gnutests/tststruct-layout.c: -------------------------------------------------------------------------------- 1 | #include "forgnuport.h" 2 | 3 | 4 | typedef struct 5 | { 6 | char a; 7 | int b; 8 | char c; 9 | short d; 10 | double e; 11 | char f; 12 | } T; 13 | 14 | 15 | void f (T *x) 16 | { 17 | x[0].a = 'a'; 18 | x[0].b = 47114711; 19 | x[0].c = 'c'; 20 | x[0].d = 1234; 21 | x[0].e = 3.141592897932; 22 | x[0].f = '*'; 23 | 24 | x[1].a = 'A'; 25 | x[1].b = 71417141; 26 | x[1].c = 'C'; 27 | x[1].d = 4321; 28 | x[1].e = 2.718281828459; 29 | x[1].f = '?'; 30 | } 31 | 32 | void g (T *x) 33 | { 34 | if (x[0].a != 'a') 35 | abort (); 36 | if (x[0].b != 47114711) 37 | abort (); 38 | if (x[0].c != 'c') 39 | abort (); 40 | if (x[0].d != 1234) 41 | abort (); 42 | if (x[0].e != 3.141592897932) 43 | abort (); 44 | if (x[0].f != '*') 45 | abort (); 46 | 47 | if (x[1].a != 'A') 48 | abort (); 49 | if (x[1].b != 71417141) 50 | abort (); 51 | if (x[1].c != 'C') 52 | abort (); 53 | if (x[1].d != 4321) 54 | abort (); 55 | if (x[1].e != 2.718281828459) 56 | abort (); 57 | if (x[1].f != '?') 58 | abort (); 59 | } 60 | 61 | int main () 62 | { 63 | T x[2]; 64 | f (x); 65 | g (x); 66 | return 0; 67 | } 68 | 69 | 70 | #ifdef EiCTeStS 71 | main(); 72 | #endif 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /test/gnutests/tststruct-ret-1.c: -------------------------------------------------------------------------------- 1 | #include "forgnuport.h" 2 | 3 | typedef struct { int re; int im; } T; 4 | 5 | T f (int x, int y); 6 | 7 | T f (int arg1, int arg2) 8 | { 9 | T x; 10 | x.re = arg1; 11 | x.im = arg2; 12 | return x; 13 | } 14 | 15 | 16 | int main (void) 17 | { 18 | T result; 19 | result = f (3, 4); 20 | if (result.re != 3 || result.im != 4) 21 | abort (); 22 | return 0; 23 | } 24 | 25 | 26 | #ifdef EiCTeStS 27 | main(); 28 | #endif 29 | -------------------------------------------------------------------------------- /test/gnutests/tststructret.c: -------------------------------------------------------------------------------- 1 | #include "forgnuport.h" 2 | 3 | struct foo 4 | { 5 | int a, b, c, d; 6 | double doubl; 7 | } s1, s2; 8 | 9 | struct foo structret (struct foo s1, 10 | int i1, int i2, 11 | struct foo s2) 12 | { 13 | if (i1 != i2) 14 | { 15 | if (i1 < i2) 16 | return s1; 17 | else 18 | return s2; 19 | } 20 | s2.a = 11; 21 | s2.b = 22; 22 | s2.c = s1.c; 23 | s2.d = s1.d; 24 | return s2; 25 | } 26 | 27 | struct foo mani (int a, int b) 28 | { 29 | return structret (s1, a, b, s2); 30 | } 31 | 32 | void init () 33 | { 34 | s1.a = 1; 35 | s1.b = 2; 36 | s1.c = 3; 37 | s1.d = 4; 38 | s1.doubl = 3.1415; 39 | s2.a = -1; 40 | s2.b = -2; 41 | s2.c = -3; 42 | s2.d = -4; 43 | s2.doubl = 2.71818; 44 | } 45 | 46 | int main (void) 47 | { 48 | struct foo s; 49 | 50 | init (); 51 | s = mani (1, 1); 52 | printf ("%d, %d, %d, %d : %f\n", s.a, s.b, s.c, s.d, s.doubl); 53 | 54 | init (); 55 | s = mani (2, 1); 56 | printf ("%d, %d, %d, %d : %f\n", s.a, s.b, s.c, s.d, s.doubl); 57 | 58 | init (); 59 | s = mani (1, 2); 60 | printf ("%d, %d, %d, %d : %f\n", s.a, s.b, s.c, s.d, s.doubl); 61 | 62 | return 0; 63 | } 64 | 65 | #ifdef EiCTeStS 66 | main(); 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /test/lcctests/stdarg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { int a[4]; } x = {{1,2,3,4}}; 5 | 6 | void print(char *fmt, ...); 7 | 8 | int main(void) 9 | { 10 | print("test 1\n"); 11 | print("test %s\n", "2"); 12 | print("test %d%c", 3, '\n'); 13 | print("%s%s %w%c", "te", "st", 4, '\n'); 14 | print("%s%s %f%c", "te", "st", 5.0, '\n'); 15 | print("%b %b %b %b %b %b\n", x, x, x, x, x, x); 16 | return 0; 17 | } 18 | 19 | void print(char *fmt, ...) { 20 | va_list ap; 21 | 22 | va_start(ap, fmt); 23 | for (; *fmt; fmt++) 24 | if (*fmt == '%') 25 | switch (*++fmt) { 26 | case 'b': { 27 | struct node x = va_arg(ap, struct node); 28 | printf("{%d %d %d %d}", x.a[0], x.a[1], x.a[2], x.a[3]); 29 | break; 30 | } 31 | case 'c': 32 | printf("%c", va_arg(ap, char)); 33 | break; 34 | case 'd': 35 | printf("%d", va_arg(ap, int)); 36 | break; 37 | case 'w': 38 | printf("%x", va_arg(ap, short)); 39 | break; 40 | case 's': 41 | printf("%s", va_arg(ap, char *)); 42 | break; 43 | case 'f': 44 | printf("%f", va_arg(ap, double)); 45 | break; 46 | default: 47 | printf("%c", *fmt); 48 | break; 49 | } 50 | else 51 | printf("%c", *fmt); 52 | va_end(ap); 53 | } 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /test/lcctests/tst8q.c: -------------------------------------------------------------------------------- 1 | #include 2 | int up[15], down[15], rows[8], x[8]; 3 | 4 | void print() 5 | { 6 | int k; 7 | 8 | for (k = 0; k < 8; k++) 9 | printf("%c ", x[k]+'1'); 10 | printf("\n"); 11 | } 12 | 13 | void queens(int c) 14 | { 15 | int r; 16 | 17 | for (r = 0; r < 8; r++) 18 | if (rows[r] && up[r-c+7] && down[r+c]) { 19 | rows[r] = up[r-c+7] = down[r+c] = 0; 20 | x[c] = r; 21 | if (c == 7) 22 | print(); 23 | else 24 | queens(c + 1); 25 | rows[r] = up[r-c+7] = down[r+c] = 1; 26 | } 27 | } 28 | 29 | int main() 30 | { 31 | int i; 32 | 33 | for (i = 0; i < 15; i++) 34 | up[i] = down[i] = 1; 35 | for (i = 0; i < 8; i++) 36 | rows[i] = 1; 37 | queens(0); 38 | return 0; 39 | } 40 | 41 | #ifdef EiCTeStS 42 | main(); 43 | #endif 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /test/lcctests/tstarray.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int x[3][4], *y[3]; 4 | 5 | void f() 6 | { 7 | int i, j; 8 | 9 | for (i = 0; i < 3; i++) 10 | for (j = 0; j < 4; j++) 11 | printf(" %d", x[i][j]); 12 | printf("\n"); 13 | for (i = 0; i < 3; i++) 14 | for (j = 0; j < 4; j++) 15 | printf(" %d", y[i][j]); 16 | printf("\n"); 17 | } 18 | 19 | void g(int x[][4], int *y[]) 20 | { 21 | int i, j; 22 | 23 | for (i = 0; i < 3; i++) 24 | for (j = 0; j < 4; j++) 25 | printf(" %d", x[i][j]); 26 | printf("\n"); 27 | for (i = 0; i < 3; i++) 28 | for (j = 0; j < 4; j++) 29 | printf(" %d", y[i][j]); 30 | printf("\n"); 31 | } 32 | 33 | 34 | int main() 35 | { 36 | int z[3][4]; 37 | int i, j, *p; 38 | 39 | for (i = 0; i < 3; i++) { 40 | for (j = 0; j < 4; j++) 41 | x[i][j] = 1000*i + j; 42 | y[i] = x[i]; 43 | } 44 | f(); 45 | for (i = 0; i < 3; i++) { 46 | y[i] = p = &z[i][0]; 47 | for (j = 0; j < 4; j++) 48 | p[j] = x[i][j]; 49 | } 50 | g(z, y); 51 | return 0; 52 | } 53 | 54 | 55 | #ifdef EiCTeStS 56 | main(); 57 | #endif 58 | -------------------------------------------------------------------------------- /test/lcctests/tstcvt.c: -------------------------------------------------------------------------------- 1 | #include 2 | signed char c, c1, c2; 3 | signed short s; 4 | signed int i, i1, i2; 5 | unsigned char C; 6 | unsigned short S; 7 | unsigned int I; 8 | float f, f1, f2; 9 | double d, d1, d2; 10 | 11 | int main() 12 | { 13 | c=1; s=c;i=c;C=c;S=c;I=c;f=c;d=c; printf("%d %d %d %d %d %d %f %f\n", c, s, i, C, S, I, f, d); 14 | s=2; c=s; i=s;C=s;S=s;I=s;f=s;d=s; printf("%d %d %d %d %d %d %f %f\n", c, s, i, C, S, I, f, d); 15 | i=3; c=i;s=i; C=i;S=i;I=i;f=i;d=i; printf("%d %d %d %d %d %d %f %f\n", c, s, i, C, S, I, f, d); 16 | C=4; c=C;s=C;i=C; S=C;I=C;f=C;d=C; printf("%d %d %d %d %d %d %f %f\n", c, s, i, C, S, I, f, d); 17 | S=5; c=S;s=S;i=S;C=S; I=S;f=S;d=S; printf("%d %d %d %d %d %d %f %f\n", c, s, i, C, S, I, f, d); 18 | I=6; c=I;s=I;i=I;C=I;S=I; f=I;d=I; printf("%d %d %d %d %d %d %f %f\n", c, s, i, C, S, I, f, d); 19 | f=7; c=f;s=f;i=f;C=f;S=f;I=f; d=f; printf("%d %d %d %d %d %d %f %f\n", c, s, i, C, S, I, f, d); 20 | d=8; c=d;s=d;i=d;C=d;S=d;I=d;f=d; printf("%d %d %d %d %d %d %f%f\n", c, s, i, C, S, I, f, d); 21 | return 0; 22 | } 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /test/lcctests/tstinit.c: -------------------------------------------------------------------------------- 1 | #include 2 | typedef struct { int codes[3]; char name[6]; } Word; 3 | 4 | Word words[] = { 5 | {{1, 2, 3,}, "if"}, 6 | { { 4, 5 }, { 'f', 'o', 'r' } }, 7 | {{6, 7, 8}, "else"}, 8 | { { 9, 10, 11,}, {'w', 'h', 'i', 'l', 'e',} }, 9 | { {0} }, 10 | }, *wordlist = words; 11 | 12 | int x[][5] = { {1, 2, 3, 4, 0}, { 5, 6 }, { 7 } }; 13 | int *y[] = { x[0], x[1], x[2], 0 }; 14 | 15 | 16 | void f() { 17 | static char *keywords[] = {"if", "for", "else", "while", 0, }; 18 | char **p; 19 | 20 | for (p = keywords; *p != 0; p++) 21 | printf("%s\n", *p); 22 | } 23 | 24 | void h() 25 | { 26 | int i; 27 | 28 | for (i = 0; i < sizeof(words)/sizeof(Word); i++) 29 | printf("%d %d %d %s\n", words[i].codes[0], 30 | words[i].codes[1], words[i].codes[2], 31 | &words[i].name[0]); 32 | } 33 | 34 | void g(Word *p) 35 | { 36 | int i; 37 | 38 | for ( ; p->codes[0]; p++) { 39 | for (i = 0; i < sizeof p->codes/sizeof(p->codes[0]); i++) 40 | printf("%d ", p->codes[i]); 41 | printf("%s\n", p->name); 42 | } 43 | h(); 44 | } 45 | 46 | 47 | int main() 48 | { 49 | int i, j; 50 | 51 | for (i = 0; y[i] != 0; i++) { 52 | for (j = 0; y[i][j]; j++) 53 | printf(" %d", y[i][j]); 54 | printf("\n"); 55 | } 56 | f(); 57 | g(wordlist); 58 | return 0; 59 | } 60 | 61 | #ifdef EiCTeStS 62 | main(); 63 | #endif 64 | -------------------------------------------------------------------------------- /test/lcctests/tstsort.c: -------------------------------------------------------------------------------- 1 | #include 2 | int in[] = {10, 32, -1, 567, 3, 18, 1, -51, 789, 0}; 3 | 4 | 5 | /* putd - output decimal number */ 6 | void putd(int n) 7 | { 8 | if (n < 0) { 9 | putchar('-'); 10 | n = -n; 11 | } 12 | if (n/10) 13 | putd(n/10); 14 | putchar(n%10 + '0'); 15 | } 16 | 17 | int *xx; 18 | 19 | /* exchange - exchange *x and *y */ 20 | void exchange(int *x, int *y) 21 | { 22 | int t; 23 | 24 | printf("exchange(%d,%d)\n", x - xx, y - xx); 25 | t = *x; *x = *y; *y = t; 26 | } 27 | 28 | /* partition - partition a[i..j] */ 29 | int partition(int *a, int i, int j) 30 | { 31 | int v, k; 32 | 33 | j++; 34 | k = i; 35 | v = a[k]; 36 | while (i < j) { 37 | i++; while (a[i] < v) i++; 38 | j--; while (a[j] > v) j--; 39 | if (i < j) exchange(&a[i], &a[j]); 40 | } 41 | exchange(&a[k], &a[j]); 42 | return j; 43 | } 44 | 45 | /* quick - quicksort a[lb..ub] */ 46 | void quick(int a[], int lb, int ub) 47 | { 48 | int k, partition(int *a,int i, int j); 49 | 50 | if (lb >= ub) 51 | return; 52 | k = partition(a, lb, ub); 53 | quick(a, lb, k - 1); 54 | quick(a, k + 1, ub); 55 | } 56 | 57 | 58 | /* sort - sort a[0..n-1] into increasing order */ 59 | void sort(int a[], int n) 60 | { 61 | quick(xx = a, 0, --n); 62 | } 63 | 64 | 65 | int main() 66 | { 67 | int i; 68 | 69 | sort(in, (sizeof in)/(sizeof in[0])); 70 | for (i = 0; i < (sizeof in)/(sizeof in[0]); i++) { 71 | putd(in[i]); 72 | putchar('\n'); 73 | } 74 | return 0; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /test/lcctests/tstw.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int main(void) 5 | { 6 | system("eic -g 'tstw.aux' < tstw.aux"); 7 | return 0; 8 | } 9 | 10 | 11 | #ifdef EiCTeStS 12 | main(); 13 | #endif 14 | -------------------------------------------------------------------------------- /test/posix.1/access.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "ourhdr.h" 4 | 5 | int 6 | main(int argc, char *argv[]) 7 | { 8 | if (argc != 2) 9 | err_quit("usage: a.out "); 10 | 11 | if (access(argv[1], R_OK) < 0) 12 | err_ret("access error for %s", argv[1]); 13 | else 14 | printf("read access OK\n"); 15 | 16 | if (open(argv[1], O_RDONLY) < 0) 17 | err_ret("open error for %s", argv[1]); 18 | else 19 | printf("open for reading OK\n"); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/posix.1/changemod.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include "ourhdr.h" 6 | 7 | int 8 | main(void) 9 | { 10 | struct stat statbuf; 11 | 12 | /* turn on set-group-ID and turn off group-execute */ 13 | 14 | if (stat("foo", &statbuf) < 0) 15 | err_sys("stat error for foo"); 16 | if (chmod("foo", (statbuf.st_mode & ~S_IXGRP) | S_ISGID) < 0) 17 | err_sys("chmod error for foo"); 18 | 19 | /* set absolute mode to "rw-r--r--" */ 20 | 21 | if (chmod("bar", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) 22 | err_sys("chmod error for bar"); 23 | 24 | printf("okay from changemod\n"); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /test/posix.1/fileflags.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "ourhdr.h" 4 | 5 | int 6 | main(int argc, char *argv[]) 7 | { 8 | int accmode, val; 9 | 10 | if (argc != 2) 11 | err_quit("usage: a.out "); 12 | 13 | if ( (val = fcntl(atoi(argv[1]), F_GETFL, 0)) < 0) 14 | err_sys("fcntl error for fd %d", atoi(argv[1])); 15 | 16 | accmode = val & O_ACCMODE; 17 | if (accmode == O_RDONLY) printf("read only"); 18 | else if (accmode == O_WRONLY) printf("write only"); 19 | else if (accmode == O_RDWR) printf("read write"); 20 | else err_dump("unknown access mode"); 21 | 22 | if (val & O_APPEND) printf(", append"); 23 | if (val & O_NONBLOCK) printf(", nonblocking"); 24 | #if !defined(_POSIX_SOURCE) && defined(O_SYNC) 25 | if (val & O_SYNC) printf(", synchronous writes"); 26 | #endif 27 | putchar('\n'); 28 | return 0; 29 | } 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/posix.1/filelock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "lockreg.c" 10 | #include "locktest.c" 11 | 12 | void err(char *s) 13 | { 14 | fprintf(stderr,"%s\n",s); 15 | exit(0); 16 | } 17 | 18 | 19 | void test4lock(char *fname) 20 | { 21 | int fd = open(fname,O_RDWR); 22 | if(fd < 0) 23 | err("failed to open file"); 24 | 25 | assert(is_writelock(fd,0,SEEK_SET,0) != 0); 26 | close(fd); 27 | 28 | } 29 | 30 | int main(int argc, char ** argv) 31 | { 32 | 33 | if(argc != 2) 34 | err("wrong number of arguments"); 35 | test4lock(argv[1]); 36 | return 0; 37 | } 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /test/posix.1/filetype.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "ourhdr.h" 4 | 5 | int 6 | main(int argc, char *argv[]) 7 | { 8 | int i; 9 | struct stat buf; 10 | char *ptr; 11 | 12 | 13 | for (i = 1; i < argc; i++) { 14 | printf("%s: ", argv[i]); 15 | if (/*l*/stat(argv[i], &buf) < 0) { 16 | err_ret("lstat error"); 17 | continue; 18 | } 19 | 20 | if (S_ISREG(buf.st_mode)) ptr = "regular"; 21 | else if (S_ISDIR(buf.st_mode)) ptr = "directory"; 22 | else if (S_ISCHR(buf.st_mode)) ptr = "character special"; 23 | else if (S_ISBLK(buf.st_mode)) ptr = "block special"; 24 | else if (S_ISFIFO(buf.st_mode)) ptr = "fifo"; 25 | #ifdef S_ISLNK 26 | else if (S_ISLNK(buf.st_mode)) ptr = "symbolic link"; 27 | #endif 28 | #ifdef S_ISSOCK 29 | else if (S_ISSOCK(buf.st_mode)) ptr = "socket"; 30 | #endif 31 | else ptr = "** unknown mode **"; 32 | printf("%s\n", ptr); 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/posix.1/hole.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "ourhdr.h" 5 | 6 | char buf1[] = "abcdefghij"; 7 | char buf2[] = "ABCDEFGHIJ"; 8 | 9 | int 10 | main(void) 11 | { 12 | int fd; 13 | 14 | if ( (fd = creat("file.hole", FILE_MODE)) < 0) 15 | err_sys("creat error"); 16 | 17 | if (write(fd, buf1, 10) != 10) 18 | err_sys("buf1 write error"); 19 | /* offset now = 10 */ 20 | 21 | if (lseek(fd, 40, SEEK_SET) == -1) 22 | err_sys("lseek error"); 23 | /* offset now = 40 */ 24 | 25 | if (write(fd, buf2, 10) != 10) 26 | err_sys("buf2 write error"); 27 | /* offset now = 50 */ 28 | 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /test/posix.1/lockreg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "ourhdr.h" 4 | 5 | int 6 | lock_reg(int fd, int cmd, int type, off_t offset, int whence, off_t len) 7 | { 8 | struct flock lock; 9 | 10 | lock.l_type = type; /* F_RDLCK, F_WRLCK, F_UNLCK */ 11 | lock.l_start = offset; /* byte offset, relative to l_whence */ 12 | lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ 13 | lock.l_len = len; /* #bytes (0 means to EOF) */ 14 | 15 | return( fcntl(fd, cmd, &lock) ); 16 | } 17 | -------------------------------------------------------------------------------- /test/posix.1/locktest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "ourhdr.h" 4 | 5 | pid_t 6 | lock_test(int fd, int type, off_t offset, int whence, off_t len) 7 | { 8 | struct flock lock; 9 | 10 | lock.l_type = type; /* F_RDLCK or F_WRLCK */ 11 | lock.l_start = offset; /* byte offset, relative to l_whence */ 12 | lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ 13 | lock.l_len = len; /* #bytes (0 means to EOF) */ 14 | 15 | if (fcntl(fd, F_GETLK, &lock) < 0) 16 | err_sys("fcntl error"); 17 | 18 | if (lock.l_type == F_UNLCK) 19 | return(0); /* false, region is not locked by another proc */ 20 | return(lock.l_pid); /* true, return pid of lock owner */ 21 | } 22 | -------------------------------------------------------------------------------- /test/posix.1/mycat.c: -------------------------------------------------------------------------------- 1 | #include "ourhdr.h" 2 | 3 | #define BUFFSIZE 8192 4 | 5 | int 6 | main(void) 7 | { 8 | int n; 9 | char buf[BUFFSIZE]; 10 | 11 | while ( (n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0) 12 | if (write(STDOUT_FILENO, buf, n) != n) 13 | err_sys("write error"); 14 | 15 | if (n < 0) 16 | err_sys("read error"); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/posix.1/seek.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ourhdr.h" 3 | 4 | int 5 | main(void) 6 | { 7 | if (lseek(STDIN_FILENO, 0, SEEK_CUR) == -1) 8 | printf("cannot seek\n"); 9 | else 10 | printf("seek OK\n"); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /test/posix.1/tst1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define tmp "tabc11" 5 | 6 | int main() 7 | { 8 | 9 | system("ln -s tst1.c " tmp); 10 | system("eic -g filetype.c .. filetype.c " tmp); 11 | system("eic -g unlink.c "); 12 | 13 | 14 | system("touch foo bar"); 15 | system("eic -g changemod.c"); 16 | system("rm foo bar"); 17 | 18 | 19 | remove(tmp); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /test/posix.1/tstdirent.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void dirCrawl(char *dir, int depth) 10 | { 11 | DIR *dp; 12 | 13 | struct dirent *entry; 14 | struct stat statbuf; 15 | 16 | int cf, cd=0; 17 | 18 | if((dp = opendir(dir)) == NULL) { 19 | fprintf(stderr,"cannont open directory; %s\n", dir); 20 | return; 21 | } 22 | chdir(dir); 23 | while((entry = readdir(dp)) != NULL) { 24 | 25 | stat(entry->d_name,&statbuf); 26 | 27 | /* ignore directories for test code */ 28 | if (S_ISDIR(statbuf.st_mode)) { 29 | continue; 30 | } 31 | 32 | /* count files */ 33 | cf++; 34 | /* 35 | if(strcmp(".",entry->d_name) == 0 || 36 | strcmp("..",entry->d_name) == 0) 37 | continue; 38 | */ 39 | if(strcmp(entry->d_name,"tstdirent.c") == 0) 40 | printf("%*s%s %ld\n",depth,"",entry->d_name,(long)statbuf.st_mtime); 41 | else 42 | 43 | 44 | if(S_ISDIR(statbuf.st_mode)) 45 | dirCrawl(entry->d_name,depth+4); 46 | } 47 | 48 | printf("Okay = %d\n", cf > 10); 49 | chdir(".."); 50 | closedir(dp); 51 | } 52 | 53 | 54 | int main() 55 | { 56 | dirCrawl(".",0); 57 | return 0; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /test/posix.1/tstfile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void do_fileflags() 8 | { 9 | system("eic -g fileflags.c fileflags.c"); 10 | system("eic -g fileflags.c 0 < /dev/tty"); 11 | system("eic -g fileflags.c 1 > temp.foo"); 12 | system("cat temp.foo"); 13 | system("eic -g fileflags.c 2 2>>temp.foo"); 14 | remove("temp.foo"); 15 | } 16 | 17 | void do_filetype() 18 | { 19 | system("eic -g filetype.c filetype.c /usr /etc"); 20 | } 21 | 22 | 23 | void do_access() 24 | { 25 | system("eic -g access.c"); 26 | system("eic -g access.c access.c"); 27 | } 28 | 29 | void do_unistd() 30 | { 31 | system("eic -g seek.c < seek.c"); 32 | system("eic -g hole.c"); 33 | system("od -c file.hole"); 34 | sleep(1); 35 | remove("file.hole"); 36 | system("eic -g mycat.c < mycat.c"); 37 | } 38 | int main(void) 39 | { 40 | do_fileflags(); 41 | do_filetype(); 42 | do_access(); 43 | do_unistd(); 44 | return 0; 45 | } 46 | 47 | #ifdef EiCTeStS 48 | main(); 49 | #endif 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /test/posix.1/tstfilelock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) 12 | 13 | void err(char *s) 14 | { 15 | fprintf(stderr,"%s\n",s); 16 | exit(0); 17 | } 18 | 19 | void lockByteZero(int fd) 20 | { 21 | struct flock lock; 22 | memset(&lock, 0, sizeof (lock)); 23 | lock.l_type = F_WRLCK; 24 | lock.l_whence = SEEK_SET; 25 | lock.l_start = 0; 26 | lock.l_len = 1; 27 | if(fcntl(fd,F_SETLKW,&lock) < 0) 28 | err("failed to lock file"); 29 | } 30 | 31 | int main() 32 | { 33 | char * myfile = "myfile"; 34 | char * str = "hello world\n"; 35 | struct flock lock; 36 | int fd; 37 | 38 | errno = 0; 39 | 40 | fd = open(myfile,O_RDWR | O_CREAT, MODE); 41 | if(fd < 0) 42 | err("failed to creat myfile"); 43 | 44 | write(fd,str,strlen(str)); 45 | 46 | memset(&lock, 0, sizeof (lock)); 47 | lock.l_whence = SEEK_SET; 48 | lock.l_start = 0; 49 | lock.l_len = 1; 50 | 51 | lock.l_type = F_WRLCK; 52 | fcntl(fd,F_GETLK, &lock); 53 | assert(lock.l_type == F_UNLCK); 54 | 55 | lockByteZero(fd); 56 | 57 | lock.l_type = F_WRLCK; 58 | fcntl(fd,F_GETLK, &lock); 59 | assert(lock.l_type != F_UNLCK); 60 | 61 | if(remove(myfile) < 0) 62 | err("failed to remove myfile"); 63 | return 0; 64 | } 65 | 66 | #ifdef EiCTeStS 67 | main(); 68 | #endif 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /test/posix.1/tstlock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "lockreg.c" 10 | #include "locktest.c" 11 | 12 | void err(char *s) 13 | { 14 | fprintf(stderr,"%s\n",s); 15 | exit(0); 16 | } 17 | 18 | int main() 19 | { 20 | char *tmpfile = "tmpfile"; 21 | char *str = "hello world\n"; 22 | int fd; 23 | 24 | if((fd =creat(tmpfile,FILE_MODE)) < 0) 25 | err("failed to creat"); 26 | 27 | if(write(fd,str,strlen(str)) != strlen(str)) 28 | err("failed to write"); 29 | 30 | 31 | assert(writew_lock(fd,0,SEEK_SET,0) == 0); 32 | 33 | printf("system 1\n"); 34 | system("eic -g filelock.c tmpfile"); 35 | 36 | assert(un_lock(fd,0,SEEK_SET,0) == 0); 37 | 38 | printf("system 2\n"); 39 | system("eic -g filelock.c tmpfile"); 40 | 41 | close(fd); 42 | remove(tmpfile); 43 | 44 | return 0; 45 | } 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /test/posix.1/unlink.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "ourhdr.h" 6 | 7 | int 8 | main(void) 9 | { 10 | 11 | system("touch tempfile"); 12 | if (open("tempfile", O_RDWR) < 0) 13 | err_sys("open error"); 14 | 15 | if (unlink("tempfile") < 0) 16 | err_sys("unlink error"); 17 | 18 | printf("file unlinked\n"); 19 | printf("done\n"); 20 | 21 | return 0; 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /test/sniptests/ansiflen.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** FLENGTH.C - a simple function using all ANSI-standard functions 5 | ** to determine the size of a file. 6 | ** 7 | ** Public domain by Bob Jarvis. 8 | */ 9 | 10 | #include "snipfile.h" 11 | 12 | #if defined(__cplusplus) && __cplusplus /* C++ version follows */ 13 | 14 | #include 15 | 16 | long flength(char *fname) 17 | { 18 | long length = -1L; 19 | ifstream ifs; 20 | 21 | ifs.open(fname, ios::binary); 22 | if (ifs) 23 | { 24 | ifs.seekg(0L, ios::end) ; 25 | length = ifs.tellg() ; 26 | } 27 | return length; 28 | } 29 | 30 | #else /* Straight C version follows */ 31 | 32 | long flength(char *fname) 33 | { 34 | long length = -1L; 35 | FILE *fptr; 36 | 37 | fptr = fopen(fname, "rb"); 38 | if(fptr != NULL) 39 | { 40 | fseek(fptr, 0L, SEEK_END); 41 | length = ftell(fptr); 42 | fclose(fptr); 43 | } 44 | 45 | return length; 46 | } 47 | 48 | #endif /* C++ */ 49 | 50 | #ifdef TEST 51 | 52 | #ifdef __WATCOMC__ 53 | #pragma off (unreferenced); 54 | #endif 55 | #ifdef __TURBOC__ 56 | #pragma argsused 57 | #endif 58 | 59 | int main(int argc, char *argv[]) 60 | { 61 | char *ptr; 62 | long len; 63 | 64 | while (--argc) 65 | { 66 | len = flength(ptr = *(++argv)); 67 | if (-1L == len) 68 | printf("\nUnable to get length of %s\n", ptr); 69 | else printf("\nLength of %s = %ld\n", ptr, len); 70 | } 71 | return 0; 72 | } 73 | 74 | #endif /* TEST */ 75 | -------------------------------------------------------------------------------- /test/sniptests/bitcnt_1.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Bit counter by Ratko Tomic 5 | */ 6 | 7 | #include "bitops.h" 8 | 9 | int CDECL bit_count(long x) 10 | { 11 | int n = 0; 12 | /* 13 | ** The loop will execute once for each bit of x set, this is in average 14 | ** twice as fast as the shift/test method. 15 | */ 16 | if (x) do 17 | n++; 18 | while (0 != (x = x&(x-1))) ; 19 | return(n); 20 | } 21 | 22 | #ifdef TEST 23 | 24 | #include 25 | #include "snip_str.h" /* For plural_text() macro */ 26 | 27 | int main(int argc, char *argv[]) 28 | { 29 | long n; 30 | 31 | while(--argc) 32 | { 33 | int i; 34 | 35 | n = atol(*++argv); 36 | i = bit_count(n); 37 | printf("%ld contains %d bit%s set\n", 38 | n, i, plural_text(i)); 39 | } 40 | return 0; 41 | } 42 | 43 | #endif /* TEST */ 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /test/sniptests/bitcnt_2.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Bit counter by Ratko Tomic 5 | */ 6 | 7 | #include "bitops.h" 8 | 9 | int CDECL bitcount(long i) 10 | { 11 | i = ((i & 0xAAAAAAAAL) >> 1) + (i & 0x55555555L); 12 | i = ((i & 0xCCCCCCCCL) >> 2) + (i & 0x33333333L); 13 | i = ((i & 0xF0F0F0F0L) >> 4) + (i & 0x0F0F0F0FL); 14 | i = ((i & 0xFF00FF00L) >> 8) + (i & 0x00FF00FFL); 15 | i = ((i & 0xFFFF0000L) >> 16) + (i & 0x0000FFFFL); 16 | return (int)i; 17 | } 18 | 19 | #ifdef TEST 20 | 21 | #include 22 | #include "snip_str.h" /* For plural_text() macro */ 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | long n; 27 | 28 | while(--argc) 29 | { 30 | int i; 31 | 32 | n = atol(*++argv); 33 | i = bitcount(n); 34 | printf("%ld contains %d bit%s set\n", 35 | n, i, plural_text(i)); 36 | } 37 | return 0; 38 | } 39 | 40 | #endif /* TEST */ 41 | -------------------------------------------------------------------------------- /test/sniptests/bstr_i.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Make an ascii binary string into an integer. 5 | ** 6 | ** Public domain by Bob Stout 7 | */ 8 | 9 | #include 10 | #include "bitops.h" 11 | 12 | unsigned int bstr_i(char *cptr) 13 | { 14 | unsigned int i, j = 0; 15 | 16 | while (cptr && *cptr && strchr("01", *cptr)) 17 | { 18 | i = *cptr++ - '0'; 19 | j <<= 1; 20 | j |= (i & 0x01); 21 | } 22 | return(j); 23 | } 24 | 25 | #ifdef TEST 26 | 27 | #include 28 | 29 | int main(int argc, char *argv[]) 30 | { 31 | char *arg; 32 | unsigned int x; 33 | 34 | while (--argc) 35 | { 36 | x = bstr_i(arg = *++argv); 37 | printf("Binary %s = %d = %04Xh\n", arg, x, x); 38 | } 39 | return EXIT_SUCCESS; 40 | } 41 | 42 | #endif /* TEST */ 43 | -------------------------------------------------------------------------------- /test/sniptests/ccard.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | #ifndef CCARD_H 4 | #define CCARD_H 5 | 6 | enum ccard_type_ty 7 | { 8 | ccard_type_unknown, 9 | ccard_type_mastercard, 10 | ccard_type_visa, 11 | ccard_type_amex, 12 | ccard_type_diners, 13 | ccard_type_discover, 14 | ccard_type_enroute, 15 | ccard_type_jcb, 16 | ccard_type_bankcard 17 | }; 18 | typedef enum ccard_type_ty ccard_type_ty; 19 | 20 | enum ccard_error_ty 21 | { 22 | ccard_error_none = 0, 23 | ccard_error_type_unknown, 24 | ccard_error_non_numeric, 25 | ccard_error_too_long, 26 | ccard_error_length_incorrect, 27 | ccard_error_checksum 28 | }; 29 | typedef enum ccard_error_ty ccard_error_ty; 30 | 31 | 32 | char *ccard_type_name (ccard_type_ty); 33 | char *ccard_error_name (ccard_error_ty); 34 | ccard_error_ty ccard_valid (char *, ccard_type_ty *); 35 | 36 | #endif /* CCARD_H */ 37 | -------------------------------------------------------------------------------- /test/sniptests/ccardplv.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | #define PATCHLEVEL "1.1.D009" 4 | -------------------------------------------------------------------------------- /test/sniptests/checksum.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** CHECKSUM.C - Compute the checksum of a file 5 | ** 6 | ** public domain demo by Bob Stout 7 | */ 8 | 9 | #include "crc.h" 10 | 11 | unsigned checksum(void *buffer, size_t len, unsigned int seed) 12 | { 13 | unsigned char *buf = (unsigned char *)buffer; 14 | size_t i; 15 | 16 | for (i = 0; i < len; ++i) 17 | seed += (unsigned int)(*buf++); 18 | return seed; 19 | } 20 | 21 | #ifdef TEST 22 | 23 | #include 24 | 25 | int main() 26 | { 27 | FILE *fp; 28 | size_t len; 29 | char buf[4096], *file = "checksum.c"; 30 | 31 | if (NULL == (fp = fopen(file, "rb"))) 32 | { 33 | printf("Unable to open %s for reading\n", file); 34 | return -1; 35 | } 36 | len = fread(buf, sizeof(char), sizeof(buf), fp); 37 | printf("%d bytes read\n", len); 38 | printf("The checksum of %s is %#x\n", file, checksum(buf, len, 0)); 39 | return 0; 40 | } 41 | 42 | #endif /* TEST */ 43 | -------------------------------------------------------------------------------- /test/sniptests/crc.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** CRC.H - header file for SNIPPETS CRC and checksum functions 5 | */ 6 | 7 | #ifndef CRC__H 8 | #define CRC__H 9 | 10 | #include /* For size_t */ 11 | #include "sniptype.h" /* For BYTE, WORD, DWORD */ 12 | 13 | /* 14 | ** File: ARCCRC16.C 15 | */ 16 | 17 | void init_crc_table(void); 18 | WORD crc_calc(WORD crc, char *buf, unsigned nbytes); 19 | void do_file(char *fn); 20 | 21 | /* 22 | ** File: CRC-16.C 23 | */ 24 | 25 | WORD crc16(char *data_p, WORD length); 26 | 27 | /* 28 | ** File: CRC-16F.C 29 | */ 30 | 31 | WORD updcrc(WORD icrc, BYTE *icp, size_t icnt); 32 | 33 | /* 34 | ** File: CRC_32.C 35 | */ 36 | 37 | #define UPDC32(octet,crc) (crc_32_tab[((crc)\ 38 | ^ ((BYTE)octet)) & 0xff] ^ ((crc) >> 8)) 39 | 40 | DWORD updateCRC32(unsigned char ch, DWORD crc); 41 | Boolean_T crc32file(char *name, DWORD *crc, long *charcnt); 42 | DWORD crc32buf(char *buf, size_t len); 43 | 44 | /* 45 | ** File: CHECKSUM.C 46 | */ 47 | 48 | unsigned checksum(void *buffer, size_t len, unsigned int seed); 49 | 50 | /* 51 | ** File: CHECKEXE.C 52 | */ 53 | 54 | void checkexe(char *fname); 55 | 56 | 57 | 58 | #endif /* CRC__H */ 59 | -------------------------------------------------------------------------------- /test/sniptests/datetime.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Header for SNIPPETS date & time function, excluding scalar dates 5 | */ 6 | 7 | #ifndef DATETIME__H 8 | #define DATETIME__H 9 | 10 | #include "sniptype.h" 11 | 12 | /* 13 | ** Julian day number functions from JDN_L.C 14 | */ 15 | 16 | long ymd_to_jdnl(int y, int m, int d, int julian); 17 | void jdnl_to_ymd(long jdn, int *yy, int *mm, int *dd, int julian); 18 | 19 | /* 20 | ** Add times from ADDTIME.C 21 | */ 22 | 23 | int add_time(unsigned basehrs, unsigned basemins, unsigned basesecs, 24 | int spanhrs, int spanmins, int spansecs, 25 | unsigned *hrs, unsigned *mins, unsigned *secs, int *days); 26 | 27 | /* 28 | ** Determine the date of Easter for any given year 29 | */ 30 | 31 | void easter(int year, int *easter_month, int *easter_day); 32 | 33 | 34 | /* 35 | ** Moon phase from MOON_AGE.C 36 | */ 37 | 38 | int moon_age(int month, int day, int year); 39 | 40 | /* 41 | ** Date parser from PARSDATE.C 42 | */ 43 | 44 | typedef enum {USA, ISO, EUROPE} Syntax_T; 45 | 46 | Boolean_T parse_date(const char *str, unsigned *year, unsigned *month, 47 | unsigned *day, Syntax_T syntax); 48 | 49 | /* 50 | ** Time parser from PARSTIME.C 51 | */ 52 | 53 | Boolean_T parse_time(const char *str, unsigned *hours, unsigned *mins, 54 | unsigned *secs); 55 | 56 | 57 | #endif /* DATETIME__H */ 58 | -------------------------------------------------------------------------------- /test/sniptests/dblround.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** DBLROUND.C - Rounds a double to the nearest whole number 5 | ** public domain by Ross Cottrell 6 | */ 7 | 8 | #include 9 | #include 10 | #include "snipmath.h" 11 | 12 | #if defined(__ZTC__) 13 | #include 14 | #define SAVEROUND() \ 15 | int fersave = fegetround(); \ 16 | fesetround(FE_TONEAREST) 17 | #define RESTOREROUND() \ 18 | fesetround(fersave) 19 | #else 20 | #if !defined(FLT_ROUNDS) || (FLT_ROUNDS != 1) 21 | #error FLT_ROUNDS needs to be defined to be 1 22 | #endif 23 | #define SAVEROUND() 24 | #define RESTOREROUND() 25 | #endif 26 | 27 | double dround(double x) 28 | { 29 | Boolean_T flag; 30 | static volatile double X; 31 | 32 | SAVEROUND(); 33 | if (True_ == (flag = (x < 0.0))) 34 | X = -x; 35 | else X = x; 36 | X += 1.0 / DBL_EPSILON; 37 | X -= 1.0 / DBL_EPSILON; 38 | RESTOREROUND(); 39 | return ((flag) ? -X : X); 40 | } 41 | 42 | #ifdef TEST 43 | 44 | #include 45 | #include 46 | 47 | int main(int argc, char *argv[]) 48 | { 49 | double val; 50 | char *dummy; 51 | 52 | while (--argc) 53 | { 54 | val = strtod((const char *)(*(++argv)), &dummy); 55 | printf("dround(%g) = ", val); 56 | printf("%.12g\n", dround(val)); 57 | } 58 | return EXIT_SUCCESS; 59 | } 60 | 61 | #endif /* TEST */ 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /test/sniptests/easter.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** EASTER.C - Determine the date of Easter for any given year 5 | ** 6 | ** public domain by Ed Bernal 7 | */ 8 | 9 | #include 10 | #include "datetime.h" 11 | 12 | 13 | void easter(int year,int *easter_month, int *easter_day) 14 | { 15 | int a,b,c,e,g,h,i,k,u,x,z; 16 | div_t f; 17 | 18 | /* 19 | ** Gauss' famous algorithm (I don't know how or why it works, 20 | ** so there's no commenting) 21 | */ 22 | 23 | a = year % 19; 24 | f = div(year,100); 25 | b = f.quot; 26 | c = f.rem; 27 | f = div(b,4); 28 | z = f.quot; 29 | e = f.rem; 30 | f = div((8*b + 13),25); 31 | g = f.quot; 32 | f = div((19*a + b - z - g + 15),30); 33 | h = f.rem; 34 | f = div((a + 11*h),319); 35 | u = f.quot; 36 | f = div(c,4); 37 | i = f.quot; 38 | k = f.rem; 39 | f = div((2*e + 2*i - k - h + u + 32),7); 40 | x = f.rem; 41 | f = div((h-u+x+90),25); 42 | *easter_month = f.quot; 43 | f = div((h-u+x + *easter_month +19),32); 44 | *easter_day = f.rem; 45 | } 46 | 47 | #ifdef TEST 48 | 49 | #include 50 | 51 | int main(int argc, char *argv[]) 52 | { 53 | int yr, mo, dy; 54 | 55 | while (--argc) 56 | { 57 | yr = atoi(*++argv); 58 | if (100 > yr) 59 | yr += 1900; 60 | easter(yr, &mo, &dy); 61 | printf("Easter in %d on %d/%d\n", yr, mo, dy); 62 | } 63 | return 0; 64 | } 65 | 66 | #endif /* TEST */ 67 | -------------------------------------------------------------------------------- /test/sniptests/eng.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kungfooman/EiC-C-Interpreter/0c4150760b613f7de666c492ce14683f216cfc84/test/sniptests/eng.c -------------------------------------------------------------------------------- /test/sniptests/err_exit.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** ERR_EXIT.C - A generic fatal error-handler by Dave Schaumann 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include "errors.h" 11 | 12 | void ErrExit(char *fmt, ...) 13 | { 14 | va_list ap; 15 | 16 | va_start(ap, fmt) ; 17 | vfprintf(stderr, fmt, ap); 18 | fputc('\n', stderr); 19 | exit(EXIT_FAILURE); 20 | } 21 | 22 | #ifdef TEST 23 | 24 | int main() 25 | { 26 | int x = 1, y = -1; 27 | 28 | if (x != y) 29 | ErrExit("Found x = %d, y = %d; Expected them to be equal!", x, y); 30 | return EXIT_SUCCESS; 31 | } 32 | 33 | #endif /* TEST */ 34 | 35 | -------------------------------------------------------------------------------- /test/sniptests/errors.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Header file for SNIPPETS error handlers 5 | */ 6 | 7 | #ifndef ERRORS__H 8 | #define ERRORS__H 9 | 10 | #include 11 | 12 | int ferrorf(FILE *filehandle, const char *format, ...); /* Ferrorf.C */ 13 | FILE * cant(char *fname, char *fmode); /* Ferrorf.C */ 14 | void ErrExit(char *fmt, ...); /* Err_Exit.C */ 15 | 16 | #endif /* ERRORS__H */ 17 | -------------------------------------------------------------------------------- /test/sniptests/fibo.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | This program demonstrates how to calculate any arbitrary term 5 | of the Fibonacci sequence using phi (the golden number) and 6 | eighteenth century mathematician A. de Moivre's formula. 7 | 8 | written on Fri 04-05-1996 by Ed Beroset 9 | and released to the public domain by the author 10 | 11 | modified for SNIPPETS 01-Sep-1996 by Bob Stout 12 | */ 13 | 14 | #include "snipmath.h" /* includes math.h */ 15 | 16 | #ifdef TEST 17 | #undef TEST 18 | #include "dblround.c" 19 | #define TEST 20 | #endif 21 | 22 | double fibo(unsigned short term) 23 | { 24 | const double k = 1/sqrt(5.0); /* a handy constant */ 25 | double x; /* the Fibonacci term */ 26 | 27 | /* 28 | ** this is de Moivre's formula using phi, the golden number (defined 29 | ** in snipmath.h), and as simplified by Donald Knuth 30 | */ 31 | 32 | x = k * pow(PHI, term); 33 | 34 | /* 35 | ** this is to compensate for computer error 36 | */ 37 | 38 | return dround(x); 39 | } 40 | 41 | #ifdef TEST 42 | 43 | #include 44 | 45 | int main() 46 | { 47 | unsigned i; /* which term? */ 48 | 49 | for (i = 1; i < 84; i++) /* limit of precision */ 50 | printf("%2d: %20.0f\n", i, fibo(i)); 51 | return 0; 52 | } 53 | 54 | #endif /* TEST */ 55 | -------------------------------------------------------------------------------- /test/sniptests/filnames.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** FILNAMES.H - Header file for SNIPPETS DOS file name processing functions. 5 | */ 6 | 7 | #ifndef FILNAMES__H 8 | #define FILNAMES__H 9 | 10 | #include "sniptype.h" 11 | 12 | char *fln_fix(char *path); 13 | int flnorm(char *in_name, char *out_name); 14 | char *unix2dos(char *path); 15 | char *dos2unix(char *path); 16 | char *chgext(char *path, char *oldext, char *newext); 17 | 18 | Boolean_T valid_fname (const char *fname, Boolean_T wild_check); 19 | 20 | /* 21 | ** FNSPLIT.C prototypes and definitions 22 | */ 23 | 24 | #define Extension_ 1 25 | #define Filename_ 2 26 | #define Directory_ 4 27 | #define Drive_ 8 28 | #define Wildname_ 16 29 | #define Wildpath_ 32 30 | 31 | Boolean_T has_wild(char *pname); 32 | int fnSplit(char *spec, char *drive, char *pname, char *path, 33 | char *fname, char *name, char *ext); 34 | char *fnMerge(char *spec, char *drive, char *pname, char *path, 35 | char *fname, char *name, char *ext) ; 36 | 37 | /* 38 | ** Macros for backwards compatibility with previous SNIPPETS, also more 39 | ** compatible with Borland psplit(), Microsoft _splitpath(), et al. 40 | */ 41 | 42 | #define psplit(str,drv,dir,nam,ext) fnSplit(str,drv,NULL,dir,NULL,nam,ext) 43 | #define pmerge(str,drv,dir,nam,ext) fnMerge(str,drv,NULL,dir,NULL,nam,ext) 44 | 45 | #endif /* FILNAMES__H */ 46 | -------------------------------------------------------------------------------- /test/sniptests/head.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define NUL '\000' 8 | #define BEL '\007' 9 | #define LINE_LEN 132 10 | 11 | void give_up(char *msg) 12 | { 13 | putchar(BEL); 14 | puts(msg); 15 | exit(-1); 16 | } 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | FILE *infile; 21 | char line[LINE_LEN + 2]; /* Allow for '\n' & NUL */ 22 | int i, N = 0; 23 | 24 | if (2 > argc) 25 | give_up("Usage: HEAD file [number_of_lines]"); 26 | if (NULL == (infile = fopen(argv[1], "r"))) 27 | give_up("Unable to open input file"); 28 | if (2 < argc) 29 | N = atoi(argv[2]); 30 | if (!N) N = 4; 31 | for (i = 0; i < N; ++i) 32 | { 33 | if (NULL == fgets(line, LINE_LEN + 1, infile)) 34 | break; 35 | line[LINE_LEN + 1] = NUL; /* Allow too-long lines */ 36 | fputs(line, stdout); 37 | if (!strrchr(line, '\n')) 38 | i -= 1; /* More to read */ 39 | } 40 | fclose(infile); 41 | return EXIT_SUCCESS; 42 | } 43 | -------------------------------------------------------------------------------- /test/sniptests/ipow.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** IPOW.C - Raise a number to an integer power 5 | ** 6 | ** public domain by Mark Stephen with suggestions by Keiichi Nakasato 7 | */ 8 | 9 | #include "snipmath.h" 10 | 11 | double ipow(double x, int n) /* return x^n */ 12 | { 13 | double t = 1.0; 14 | 15 | if (!n) 16 | return 1.0; /* At the top. 0**0 = 1 */ 17 | if (n < 0) 18 | { 19 | n = -n; 20 | x = 1.0/x; /* error if x == 0. Good */ 21 | } /* ZTC/SC returns inf, which is even better */ 22 | if (x == 0.0) 23 | return 0.0; 24 | do 25 | { 26 | if (n & 1) 27 | t *= x; 28 | n /= 2; /* KN prefers if (n/=2) x*=x; This avoids an */ 29 | x *= x; /* unnecessary but benign multiplication on */ 30 | } while (n); /* the last pass, but the comparison is always */ 31 | return t; /* true _except_ on the last pass. */ 32 | } 33 | 34 | #ifdef TEST 35 | 36 | #include 37 | #include 38 | 39 | #ifdef __WATCOMC__ 40 | #pragma off (unreferenced); 41 | #endif 42 | #ifdef __TURBOC__ 43 | #pragma argsused 44 | #endif 45 | 46 | int main(int argc, char *argv[]) 47 | { 48 | double d; 49 | int n; 50 | 51 | d = atof(argv[1]); 52 | n = atoi(argv[2]); 53 | printf("%f^%d = %f\n", d, n, ipow(d, n) ); 54 | return 0; 55 | } 56 | 57 | #endif /* TEST */ 58 | -------------------------------------------------------------------------------- /test/sniptests/ispow2.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | #include 4 | #include "snipmath.h" 5 | 6 | int ispow2(int x) 7 | { 8 | return! ((~(~0U>>1)|x)&x -1) ; 9 | } 10 | 11 | #ifdef TEST 12 | 13 | int main(void) 14 | { 15 | int i; 16 | 17 | for (i = 0; i < 256; ++i) 18 | printf("%3d: %d\n", i, ispow2(i)); 19 | return 0; 20 | } 21 | 22 | #endif /* TEST */ 23 | -------------------------------------------------------------------------------- /test/sniptests/maxline.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** maxline.c - returns the length of the longest line in text file 5 | ** 6 | ** Released to Public Domain by Phi Nguyen 7 | ** 8 | ** 03.22.96 - First release 9 | ** 03.26.96 - Chad Wallace, for use with FILECAT.C 10 | ** Uses an array of pointers to strings (ala argv) 11 | ** instead of a file. 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | unsigned int max_line(char ** str_array) 18 | { 19 | unsigned cur_len, max = 0; 20 | 21 | while (*str_array != NULL) 22 | { 23 | cur_len = strlen(*str_array); 24 | if (cur_len > max) 25 | max = cur_len; 26 | 27 | str_array++; 28 | } 29 | 30 | return max; 31 | } 32 | 33 | #ifdef TEST 34 | 35 | /* 36 | ** Will return the length of the largest parameter given on the 37 | ** command line, including argv[0], the program's .EXE file. 38 | */ 39 | 40 | int main(int argc, char **argv) 41 | { 42 | printf("%i\n", max_line(argv)); 43 | 44 | return 0; 45 | } 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /test/sniptests/parity.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** PARITY.C - Computes even or odd parity for various integral types 5 | ** 6 | ** public domain demo by Bob Stout 7 | */ 8 | 9 | #include "parity.h" 10 | 11 | unsigned parity32(unsigned long x, Parity_T even) 12 | { 13 | x = x ^ (x >> 16); 14 | x = x ^ (x >> 8); 15 | x = x ^ (x >> 4); 16 | x = x ^ (x >> 2); 17 | x = x ^ (x >> 1); 18 | 19 | return ((unsigned)(x & 1)) ^ even; 20 | } 21 | 22 | unsigned parity16(unsigned short x, Parity_T even) 23 | { 24 | x = x ^ (x >> 8); 25 | x = x ^ (x >> 4); 26 | x = x ^ (x >> 2); 27 | x = x ^ (x >> 1); 28 | 29 | return ((unsigned)(x & 1)) ^ even; 30 | } 31 | 32 | unsigned parity8(unsigned char x, Parity_T even) 33 | { 34 | x = x ^ (x >> 4); 35 | x = x ^ (x >> 2); 36 | x = x ^ (x >> 1); 37 | 38 | return ((unsigned)(x & 1)) ^ even; 39 | } 40 | 41 | unsigned parity64(void *x, Parity_T even) 42 | { 43 | union longlong *val64 = (union longlong *)x; 44 | 45 | return (parity32(val64->lo, even) ^ parity32(val64->hi, even)); 46 | } 47 | 48 | #ifdef TEST 49 | 50 | #include 51 | #include 52 | 53 | int main(int argc, char **argv) 54 | { 55 | while (--argc) 56 | { 57 | unsigned long n = strtoul(*(++argv), NULL, 10); 58 | 59 | printf("Even parity of %ld = %d\n", n, parity32(n, Even_)); 60 | printf("Odd parity of %ld = %d\n\n", n, parity32(n, Odd_)); 61 | } 62 | return 0; 63 | } 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /test/sniptests/parity.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** PARITY.H 5 | */ 6 | 7 | typedef enum {Even_, Odd_} Parity_T; 8 | 9 | unsigned parity32(unsigned long x, Parity_T even); 10 | unsigned parity16(unsigned short x, Parity_T even); 11 | unsigned parity8(unsigned char x, Parity_T even); 12 | 13 | union longlong { 14 | unsigned long lo; 15 | unsigned long hi; 16 | }; 17 | 18 | unsigned parity64(void *x, Parity_T even); 19 | -------------------------------------------------------------------------------- /test/sniptests/phonetic.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** PHONETIC.H - Snippets header file for functions to perform 5 | ** phonetic string matching. 6 | */ 7 | 8 | #ifndef PHONETIC__H 9 | #define PHONETIC__H 10 | 11 | #include "sniptype.h" 12 | 13 | 14 | /* 15 | ** File SOUNDEX.C 16 | */ 17 | 18 | char *soundex(char *instr, char *outstr); 19 | 20 | 21 | /* 22 | ** File SOUNDEX4.C 23 | */ 24 | 25 | void soundex4(const char *instr, char *outstr, int N); 26 | 27 | 28 | /* 29 | ** File SOUNDEX5.C 30 | */ 31 | 32 | #define SNDMAX (1 + 6 + 6*6 + 6*6*6) 33 | #define SNDLEN (26 * SNDMAX) 34 | 35 | int soundex5(char *instr); 36 | 37 | 38 | /* 39 | ** File METAPHON.C 40 | */ 41 | 42 | /* 43 | ** MAXMETAPH is the length of the Metaphone code. 44 | ** 45 | ** Four is a good compromise value for English names. For comparing words 46 | ** which are not names or for some non-English names, use a longer code 47 | ** length for more precise matches. 48 | ** 49 | ** The default here is 5. 50 | */ 51 | 52 | #define MAXMETAPH 5 53 | 54 | typedef enum {COMPARE, GENERATE} metaphlag; 55 | 56 | Boolean_T metaphone(const char *Word, char *Metaph, metaphlag Flag); 57 | 58 | 59 | /* 60 | ** File APPROX.C 61 | */ 62 | 63 | void App_init(char *pattern, char *text, int degree); 64 | void App_next(char **start, char **end, int *howclose); 65 | 66 | #endif /* PHONETIC__H */ 67 | -------------------------------------------------------------------------------- /test/sniptests/pi.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | #ifndef PI__H 4 | #define PI__H 5 | 6 | #ifndef PI 7 | #define PI (4*atan(1)) 8 | #endif 9 | 10 | #define deg2rad(d) ((d)*PI/180) 11 | #define rad2deg(r) ((r)*180/PI) 12 | 13 | #endif /* PI__H */ 14 | -------------------------------------------------------------------------------- /test/sniptests/rad2deg.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** RAD2DEG.C - Functions to convert between radians and degrees 5 | */ 6 | 7 | #include 8 | #include "snipmath.h" 9 | 10 | #undef rad2deg /* These are macros defined in PI.H */ 11 | #undef deg2rad 12 | 13 | double rad2deg(double rad) 14 | { 15 | return (180.0 * rad / (PI)); 16 | } 17 | 18 | double deg2rad(double deg) 19 | { 20 | return (PI * deg / 180.0); 21 | } 22 | 23 | #ifdef TEST 24 | 25 | #include 26 | 27 | int main() 28 | { 29 | double X; 30 | 31 | for (X = 0.0; X <= 360.0; X += 45.0) 32 | printf("%3.0f degrees = %.12f radians\n", X, deg2rad(X)); 33 | puts(""); 34 | for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 6)) 35 | printf("%.12f radians = %3.0f degrees\n", X, rad2deg(X)); 36 | return 0; 37 | } 38 | 39 | #endif /* TEST */ 40 | -------------------------------------------------------------------------------- /test/sniptests/rdxcnvrt.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** RDXCNVRT.C - Convert between number bases 5 | ** 6 | ** public domain demo by Bob Stout 7 | ** uses LTOA.C, also in SNIPPETS 8 | */ 9 | 10 | #include 11 | #ifdef TEST 12 | #include 13 | #endif 14 | 15 | #ifndef _EiC 16 | #ifdef TEST 17 | #undef TEST 18 | char *ltoa(long num, char *buf, int base); 19 | #include "ltoa.c" 20 | #define TEST 21 | #endif 22 | #endif 23 | /* 24 | ** Calling parameters: 1 - Number string to be converted 25 | ** 2 - Buffer for the converted output 26 | ** 3 - Radix (base) of the input 27 | ** 4 - Radix of the output 28 | ** 29 | ** Returns: Pointer to converted output 30 | */ 31 | 32 | char *radix_convert(const char *in, char *out, int rin, int rout) 33 | { 34 | long n; 35 | char *dummy; 36 | 37 | n = strtol(in, &dummy, rin); 38 | return ltoa(n, out, rout); 39 | } 40 | 41 | #ifdef TEST 42 | 43 | int main(int argc, char *argv[]) 44 | { 45 | int rin, rout; 46 | char buf[40]; 47 | 48 | if (4 > argc) 49 | { 50 | puts("Usage: RDXCNVRT "); 51 | return(-1); 52 | } 53 | rin = atoi(argv[2]); 54 | rout = atoi(argv[3]); 55 | printf("%s (base %d) = %s (base %d)\n", argv[1], rin, 56 | radix_convert((const char *)argv[1], buf, rin, rout), rout); 57 | return 0; 58 | } 59 | 60 | #endif /* TEST */ 61 | -------------------------------------------------------------------------------- /test/sniptests/regkey.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** REGKEY.H - SNIPPETS header file for REGIT.C and CHKREG.C 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /* Choose your own values for these */ 13 | 14 | #define XOR_PRIME 0xFFFFFFFFL 15 | #define XOR_CRYPT 0x13579ACEL 16 | #define XOR_POST_CRYPT 0x2468BDF0L 17 | -------------------------------------------------------------------------------- /test/sniptests/rnd_div.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** RND_DIV.C - Rounded integer division 5 | ** 6 | ** Public domain - suggested by Dave Hansen in comp.lang.c 7 | */ 8 | 9 | #include 10 | 11 | int round_div(int n, int d) 12 | { 13 | div_t res = div(n,d); 14 | div_t rnd = div(res.rem, (abs(d)+1)/2 ); 15 | 16 | return res.quot + rnd.quot; 17 | } 18 | 19 | long round_ldiv(long n, long d) 20 | { 21 | ldiv_t res = ldiv(n,d); 22 | ldiv_t rnd = ldiv(res.rem, (abs(d)+1)/2 ); 23 | 24 | return res.quot + rnd.quot; 25 | } 26 | 27 | #ifdef TEST 28 | 29 | #include 30 | #include 31 | 32 | int main(int argc, char *argv[]) 33 | { 34 | long n, d, q; 35 | 36 | if (argc != 3) 37 | { 38 | puts("Usage: RND_DIV n d\n"); 39 | puts("Returns n/d rounded to nearest integer"); 40 | return -1; 41 | } 42 | 43 | n = atol(argv[1]); 44 | d = atol(argv[2]); 45 | 46 | if (n > INT_MAX || d > INT_MAX) 47 | { 48 | q = round_ldiv(n, d); 49 | printf("round_ldiv(%ld, %ld) = %ld\n", n, d, q); 50 | } 51 | else 52 | { 53 | q = (long)round_div((int)n, (int)d); 54 | printf("round_div(%ld, %ld) = %ld\n", n, d, q); 55 | } 56 | 57 | return 0; 58 | } 59 | 60 | #endif /* TEST */ 61 | -------------------------------------------------------------------------------- /test/sniptests/round.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** rounding macros by Dave Knapp, Thad Smith, Jon Strayer, & Bob Stout 5 | */ 6 | 7 | #ifndef ROUND__H 8 | #define ROUND__H 9 | 10 | #include 11 | 12 | #if defined(__cplusplus) && __cplusplus 13 | 14 | /* 15 | ** Safe C++ inline versions 16 | */ 17 | 18 | /* round to integer */ 19 | 20 | inline int iround(double x) 21 | { 22 | return (int)floor(x + 0.5); 23 | } 24 | 25 | /* round number n to d decimal points */ 26 | 27 | inline double fround(double n, unsigned d) 28 | { 29 | return floor(n * pow(10., d) + .5) / pow(10., d); 30 | } 31 | 32 | #else 33 | 34 | /* 35 | ** NOTE: These C macro versions are unsafe since arguments are referenced 36 | ** more than once. 37 | ** 38 | ** Avoid using these with expression arguments to be safe. 39 | */ 40 | 41 | /* 42 | ** round to integer 43 | */ 44 | 45 | #define iround(x) floor((x) + 0.5) 46 | 47 | /* 48 | ** round number n to d decimal points 49 | */ 50 | 51 | #define fround(n,d) (floor((n)*pow(10.,(d))+.5)/pow(10.,(d))) 52 | 53 | #endif 54 | 55 | #endif /* ROUND__H */ 56 | -------------------------------------------------------------------------------- /test/sniptests/snip1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | system("eic -g -DTEST arccrc16.c arccrc16.c"); 6 | system("eic -g -DTEST bcdl.c"); 7 | system("eic -g -DTEST bcdd.c"); 8 | system("eic -g -DTEST bitstrng.c"); 9 | system("eic -g -DTEST bodymass.c 67 175"); 10 | system("eic -g -DTEST ccard.c 38437534974933"); 11 | 12 | return 0; 13 | } 14 | 15 | #ifdef EiCTeStS 16 | main(); 17 | #endif 18 | -------------------------------------------------------------------------------- /test/sniptests/snip2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | system("eic -g -DTEST checksum.c"); 6 | system("eic -g -DTEST combin.c 6 2"); 7 | system("eic -g -DTEST crc_16f.c crc_16f.c"); 8 | system("eic -g -DTEST cubic.c"); 9 | system("eic -g -DTEST daynum.c 11 13 57"); 10 | system("eic -g -DTEST dow.c 57 11 13"); 11 | system("eic -g -DTEST dbl2long.c 13.13"); 12 | 13 | return 0; 14 | } 15 | 16 | #ifdef EiCTeStS 17 | main(); 18 | #endif 19 | -------------------------------------------------------------------------------- /test/sniptests/snip3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | system("eic -g -DTEST eng.c"); 6 | system("eic -g -DTEST err_exit.c"); 7 | system("eic -g -DTEST fcompare.c fcompare.c fcompare.c"); 8 | system("eic -g -DTEST fibo.c"); 9 | system("eic -g -DTEST fmtmoney.c 3303.50"); 10 | system("eic -g -DTEST fraction.c 0.37931034"); 11 | system("eic -g -DTEST hash.c"); 12 | system("eic -g -DTEST ipow.c 8 4"); 13 | system("eic -g -DTEST ispow2.c"); 14 | 15 | return 0; 16 | } 17 | 18 | #ifdef EiCTeStS 19 | main(); 20 | #endif 21 | -------------------------------------------------------------------------------- /test/sniptests/snip4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | system("eic -g -DTEST jdn_l.c 13 11 57"); 6 | system("eic -g -DTEST l2roman.c 1345"); 7 | system("eic -g -DTEST logscale.c"); 8 | system("eic -g -DTEST match.c ell hello"); 9 | system("eic -g -DTEST mathstat.c 12 13 14 15"); 10 | system("eic -g -DTEST maxline.c helloworldhow"); 11 | system("eic -g -DTEST memmem.c"); 12 | system("eic -g -DTEST moon_age.c 11 13 57"); 13 | system("eic -g -DTEST parity.c 13456"); 14 | system("eic -g -DTEST parstime.c 12:30:30"); 15 | 16 | return 0; 17 | } 18 | 19 | #ifdef EiCTeStS 20 | main(); 21 | #endif 22 | -------------------------------------------------------------------------------- /test/sniptests/snip5.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | system("eic -g -DTEST pbmsrch.c"); 6 | system("eic -g -DTEST rad2deg.c"); 7 | system("eic -g -DTEST rg_rand.c"); 8 | system("eic -g -DTEST rnd_div.c 333 22"); 9 | system("eic -g -DTEST roman2l.c MCIV"); 10 | system("eic -g -DTEST ruleline.c"); 11 | system("eic -g -DTEST soundex.c helloworld"); 12 | system("eic -g -DTEST stptok.c ItsaniceDay iD"); 13 | system("eic -g -DTEST stristr.c"); 14 | system("eic -g -DTEST strrpbrk.c"); 15 | system("eic -g -DTEST vfname.c"); 16 | system("eic -g -DTEST w_wrap.c"); 17 | 18 | return 0; 19 | } 20 | 21 | #ifdef EiCTeStS 22 | main(); 23 | #endif 24 | -------------------------------------------------------------------------------- /test/sniptests/snip6.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | system("eic -g -DTEST crc_32.c"); 6 | system("eic -g -DTEST ansiflen.c ansiflen.c"); 7 | system("eic -g -DTEST bitcnt_1.c 1313131212"); 8 | system("eic -g -DTEST bitcnt_2.c 1313131212"); 9 | system("eic -g -DTEST bitcnt_3.c 1313131212"); 10 | system("eic -g -DTEST bitcnt_4.c 1313131212"); 11 | system("eic -g -DTEST bstr_i.c 100110101111"); 12 | 13 | return 0; 14 | } 15 | 16 | #ifdef EiCTeStS 17 | main(); 18 | #endif 19 | -------------------------------------------------------------------------------- /test/sniptests/snip7.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | system("eic -g -DTEST easter.c 1997"); 6 | system("eic -g -DTEST dblround.c 167.5678"); 7 | system("eic -g -DTEST factoryl.c"); 8 | system("eic -g -DTEST sstrdel.c"); 9 | system("eic -g -DTEST trim.c \" trim test\""); 10 | system("eic -g -DTEST amalloc.c"); 11 | return 0; 12 | } 13 | 14 | #ifdef EiCTeStS 15 | main(); 16 | #endif 17 | -------------------------------------------------------------------------------- /test/sniptests/snip8.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | system("eic -g -DTEST bincomp.c bincomp.c bincomp.c"); 6 | system("eic -g -DTEST head.c head.c 7"); 7 | system("eic -g -DTEST tiresize.c 265 75 16"); 8 | system("eic -g -DTEST strupr.c hello world"); 9 | system("eic -g -DTEST skiplist.c "); 10 | system("eic -g -DTEST remtab.c < remtab.c"); 11 | system("eic -g -DTEST spigot.c 13"); 12 | system("eic -g -DTEST rand1.c"); 13 | system("eic -g -DTEST regit.c DougFunny"); 14 | 15 | return 0; 16 | } 17 | 18 | #ifdef EiCTeStS 19 | main(); 20 | #endif 21 | -------------------------------------------------------------------------------- /test/sniptests/snip9.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | system("eic -g -DTEST rdxcnvrt.c 2013 10 3"); 6 | system("eic -g -DTEST strdel.c helloworld pos 2 3"); 7 | system("eic -g -DTEST strdelch.c eo helloworld"); 8 | system("eic -g -DTEST c_cmnt.c < c_cmnt.c"); 9 | system("eic -g -DTEST strrev.c DougFunny"); 10 | system("eic -g -DTEST etphi.c 11"); 11 | 12 | return 0; 13 | } 14 | 15 | #ifdef EiCTeStS 16 | main(); 17 | #endif 18 | -------------------------------------------------------------------------------- /test/sniptests/sniptype.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** SNIPTYPE.H - Include file for SNIPPETS data types and commonly used macros 5 | */ 6 | 7 | #ifndef SNIPTYPE__H 8 | #define SNIPTYPE__H 9 | 10 | #include /* For free() */ 11 | #include /* For NULL & strlen() */ 12 | 13 | typedef enum {Error_ = -1, Success_, False_ = 0, True_} Boolean_T; 14 | 15 | #if !defined(WIN32) && !defined(_WIN32) && !defined(__NT__) \ 16 | && !defined(_WINDOWS) 17 | #if !defined(OS2) 18 | typedef unsigned char BYTE; 19 | typedef unsigned long DWORD; 20 | #endif 21 | typedef unsigned short WORD; 22 | #else 23 | #define WIN32_LEAN_AND_MEAN 24 | #define NOGDI 25 | #define NOSERVICE 26 | #undef INC_OLE1 27 | #undef INC_OLE2 28 | #include 29 | #define HUGE 30 | #endif 31 | 32 | #define NUL '\0' 33 | #define LAST_CHAR(s) (((char *)s)[strlen(s) - 1]) 34 | #define TOBOOL(x) (!(!(x))) 35 | #define FREE(p) (free(p),(p)=NULL) 36 | 37 | #endif /* SNIPTYPE__H */ 38 | -------------------------------------------------------------------------------- /test/sniptests/snparray.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Header file for SNIPPETS array allocation functions 5 | */ 6 | 7 | #ifndef SNPARRAY__H 8 | #define SNPARRAY__H 9 | 10 | /* 11 | ** AMALLOC.C 12 | */ 13 | 14 | void *amalloc( int esiz, void *initval, int dims, ... ); 15 | 16 | /* 17 | ** MDALLOC.C 18 | */ 19 | 20 | void *mdalloc(int ndim, int width, ...); 21 | void mdfree(void *tip, int ndim); 22 | 23 | #endif /* SNPARRAY__H */ 24 | -------------------------------------------------------------------------------- /test/sniptests/strdup.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Portable, public domain strdup() by Bob Stout 5 | */ 6 | 7 | #include 8 | #include 9 | #include "snip_str.h" 10 | 11 | #if defined(__cplusplus) && __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | char *strdup(const char *string) 16 | { 17 | char *newstring; 18 | 19 | if (string) 20 | { 21 | if (NULL != (newstring = malloc(strlen(string) + 1))) 22 | strcpy(newstring, string); 23 | return newstring; 24 | } 25 | else return NULL; 26 | } 27 | 28 | #if defined(__cplusplus) && __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /test/sniptests/strrev.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** STRREV.C - reverse a string in place 5 | ** 6 | ** public domain by Bob Stout 7 | */ 8 | 9 | #include 10 | #include "snip_str.h" 11 | 12 | #if defined(__cplusplus) && __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | char *strrev(char *str) 17 | { 18 | char *p1, *p2; 19 | 20 | if (! str || ! *str) 21 | return str; 22 | for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) 23 | { 24 | *p1 ^= *p2; 25 | *p2 ^= *p1; 26 | *p1 ^= *p2; 27 | } 28 | return str; 29 | } 30 | 31 | #if defined(__cplusplus) && __cplusplus 32 | } 33 | #endif 34 | 35 | #ifdef TEST 36 | 37 | #include 38 | 39 | int main(int argc, char *argv[]) 40 | { 41 | while (--argc) 42 | { 43 | printf("\"%s\" backwards is ", *++argv); 44 | printf("\"%s\"\n", strrev(*argv)); 45 | } 46 | return 0; 47 | } 48 | 49 | #endif /* TEST */ 50 | -------------------------------------------------------------------------------- /test/sniptests/strrpbrk.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** strrpbrk() - reverse of strpbrk() - Finds the last occurrence of 5 | ** any characters from szChars found in szString. 6 | ** 7 | ** Donated to SNIPPETS by Phi Nguyen 1995, modified by Bob Stout 8 | */ 9 | 10 | #include 11 | #include 12 | #include "snip_str.h" 13 | 14 | #if defined(__cplusplus) && __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | char *strrpbrk(const char *szString, const char *szChars) 19 | { 20 | const char *p; 21 | char *p0, *p1; 22 | 23 | for (p = szChars, p0 = p1 = NULL; p && *p; ++p) 24 | { 25 | p1 = strrchr(szString, *p); 26 | if (p1 && p1 > p0) 27 | p0 = p1; 28 | } 29 | return p0; 30 | } 31 | 32 | #if defined(__cplusplus) && __cplusplus 33 | } 34 | #endif 35 | 36 | #ifdef TEST 37 | 38 | int main() 39 | { 40 | char string[] = "This is a testing string", 41 | chars[] = "xyzet", 42 | *ptr; 43 | 44 | ptr = strrpbrk(string, chars); 45 | 46 | if (ptr) 47 | printf("One or more of \"%s\" found at \"%s\"\n", chars, ptr); 48 | else printf("Can't find any of \"%s\" in \"%s\".\n", chars, string); 49 | return 0; 50 | } 51 | 52 | #endif /* TEST */ 53 | -------------------------------------------------------------------------------- /test/sniptests/strupr.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Portable, public domain replacements for strupr() & strlwr() by Bob Stout 5 | */ 6 | 7 | #include 8 | #include "snip_str.h" 9 | 10 | #if defined(__cplusplus) && __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | char *strupr(char *string) 15 | { 16 | char *s; 17 | 18 | if (string) 19 | { 20 | for (s = string; *s; ++s) 21 | *s = toupper(*s); 22 | } 23 | return string; 24 | } 25 | 26 | char *strlwr(char *string) 27 | { 28 | char *s; 29 | 30 | if (string) 31 | { 32 | for (s = string; *s; ++s) 33 | *s = tolower(*s); 34 | } 35 | return string; 36 | } 37 | 38 | #if defined(__cplusplus) && __cplusplus 39 | } 40 | #endif 41 | 42 | #ifdef TEST 43 | 44 | #include 45 | #include 46 | 47 | int main(int argc, char *argv[]) 48 | { 49 | if (argc < 2) 50 | { 51 | puts("Usage: STRUPR string1 [...string2 [...stringN]]"); 52 | return EXIT_FAILURE; 53 | } 54 | while (--argc) 55 | { 56 | printf("Original = \"%s\"\n", *++argv); 57 | printf("strupr() = \"%s\"\n", strupr(*argv)); 58 | printf("strlwr() = \"%s\"\n", strlwr(*argv)); 59 | } 60 | return EXIT_SUCCESS; 61 | } 62 | 63 | #endif /* TEST */ 64 | -------------------------------------------------------------------------------- /test/sniptests/vfname.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Configuration header file for VFNAME.C 5 | */ 6 | 7 | /* 8 | ** Rules for MS/PC-DOS 9 | */ 10 | 11 | #define FNAME_MAX 12 12 | #define FNAME_SIZE_MAX 8 13 | #define FNAME_SIZE_MIN 1 14 | #define FEXT_SIZE_MAX 3 15 | #define FEXT_SIZE_MIN 0 16 | #define MULTIPLE_EXTS False_ 17 | #define PATH_SEP_CHARS "\\/" 18 | #define INVALID_CHARS " ,;:|<>\"+=[]" 19 | #define WILDCARD_CHARS "*?" 20 | #define DEVICE_LIST_3 {"AUX","CON","PRN","NUL",\ 21 | "aux","con","prn","nul",NULL} 22 | #define DEVICE_LIST_4 {"LPT1","LPT2","LPT3","COM1","COM2","COM3","COM4",\ 23 | "lpt1","lpt2","lpt3","com1","com2","com3","com4",NULL} 24 | #define DEVICE_LIST_6 {"CLOCK$","clock$",NULL} 25 | 26 | #if 0 27 | /* 28 | ** Rules for Posix 29 | */ 30 | 31 | #define FNAME_MAX _PC_NAME_MAX 32 | #define FNAME_SIZE_MAX _PC_NAME_MAX 33 | #define FNAME_SIZE_MIN 0 34 | #define FEXT_SIZE_MAX _PC_NAME_MAX 35 | #define FEXT_SIZE_MIN 0 36 | #define MULTIPLE_EXTS True_ 37 | #define PATH_SEP_CHARS "/" 38 | #define INVALID_CHARS " ,;:|<>\"\'+=(){}!@#%&!~`" 39 | #define WILDCARD_CHARS "*?[]^$" 40 | #define DEVICE_LIST_3 {"nul",NULL} 41 | #define DEVICE_LIST_4 {"",NULL} 42 | #define DEVICE_LIST_6 {"",NULL} 43 | #endif 44 | -------------------------------------------------------------------------------- /test/sniptests/w_wrap.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* w_wrap.h */ 4 | /* prototypes for the functions in w_wrap.c */ 5 | 6 | #ifndef W_WRAP__H 7 | #define W_WRAP__H 8 | 9 | #include /* For size_t */ 10 | #include /* For FILE */ 11 | 12 | char *word_wrap(char *string, size_t line_len); 13 | void set_tab_size(size_t size); 14 | void center(FILE *file, char *string, size_t width); 15 | 16 | #endif /* W_WRAP__H */ 17 | -------------------------------------------------------------------------------- /test/test.sh: -------------------------------------------------------------------------------- 1 | echo "in EiCtests" 2 | cd EiCtests 3 | ../runtest test*.c 4 | cd .. 5 | 6 | echo "in eicScripts" 7 | cd eicScripts 8 | ../runtest Drive*.c 9 | cd .. 10 | 11 | echo "in sniptests" 12 | cd sniptests 13 | ../runtest snip?.c 14 | cd .. 15 | 16 | echo "in gnutests" 17 | cd gnutests 18 | ../runtest *.c 19 | cd .. 20 | 21 | echo "in lcctests" 22 | cd lcctests 23 | ../runtest tst*.c 24 | cd .. 25 | 26 | echo "in testcode" 27 | cd testcode 28 | ../runtest *.c 29 | cd .. 30 | 31 | echo "in posix.1" 32 | cd posix.1 33 | ../runtest tst*.c 34 | cd .. 35 | -------------------------------------------------------------------------------- /test/testcode/tarray.c: -------------------------------------------------------------------------------- 1 | int size=5; 2 | int a[4+1]; 3 | int t; 4 | 5 | for (t=0; t 3 | 4 | int main(void) 5 | { 6 | int a; 7 | 8 | printf ("%d (5)\n", (4,5)); 9 | 10 | a = 1; 11 | 12 | printf ("%d (3)\n", a+=1+1); 13 | printf ("%d (0)\n", a == 3 ? 1 : 0); 14 | printf ("%d (1)\n", -- a < 3 ? 0 : 1); 15 | printf ("%d (6)\n", 2*2+2); 16 | printf ("%d (0)\n", 0 && 1 || 0); 17 | printf ("%d (1)\n", 1 && 0 || 1 ); 18 | printf ("%d (15)\n", 8 | 7 ^ 7 & 8); 19 | /* printf ("%d ()\n", ); */ 20 | 21 | return 0; 22 | } 23 | 24 | #ifdef EiCTeStS 25 | main(); 26 | :show main 27 | #endif 28 | -------------------------------------------------------------------------------- /test/testcode/tptr.c: -------------------------------------------------------------------------------- 1 | 2 | struct Dvector 3 | { 4 | double x, y; 5 | }; 6 | 7 | void PrintDVector (struct Dvector * v) 8 | { 9 | printf ("--- v = (%g/%g)\n", v->x, v->y); 10 | } 11 | 12 | struct Dvector v, v2; 13 | 14 | v.x = 1.0; 15 | v.y = 1.5; 16 | v2.x = 1.1; 17 | v2.y = 1.6; 18 | 19 | printf ("--- v = (%g/%g)\n", v.x, v.y); 20 | 21 | PrintDVector (&v); 22 | PrintDVector (&v2); 23 | 24 | :show PrintDVector 25 | 26 | -------------------------------------------------------------------------------- /test/testcode/tsizeof.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int main(void) 5 | { 6 | int t; 7 | 8 | printf ("sizeof (char) = %d\n", sizeof (char)); 9 | printf ("sizeof (int) = %d\n", sizeof (int)); 10 | printf ("sizeof (double) = %d\n", sizeof (double)); 11 | printf ("sizeof !7 = %d\n", sizeof !7); 12 | printf ("sizeof (4+5*3) = %d\n", sizeof (4+5*3)); 13 | printf ("sizeof t = %d\n", sizeof t); 14 | printf ("sizeof \"hello\" = %d\n", sizeof "hallo"); 15 | printf ("sizeof (0 == 1) = %d\n", sizeof (0 == 1)); 16 | 17 | return 0; 18 | } 19 | 20 | 21 | #ifdef EiCTeStS 22 | 23 | main(); 24 | :show main 25 | #endif 26 | -------------------------------------------------------------------------------- /test/testcode/tstruct.c: -------------------------------------------------------------------------------- 1 | 2 | struct st 3 | { 4 | int i; 5 | int i2; 6 | float f; 7 | double d; 8 | struct s1 9 | { 10 | struct s2 11 | { 12 | struct s3 13 | { 14 | int i3; 15 | } s3; 16 | int i2; 17 | } s2; 18 | union 19 | { 20 | int a; 21 | float b; 22 | } u; 23 | int i1; 24 | } s1; 25 | }; 26 | 27 | struct st st; 28 | 29 | st.i = 1; 30 | st.f = 2.0; 31 | st.d = 3.0; 32 | st.s1.i1 = 4; 33 | st.s1.s2.i2 = 5; 34 | st.s1.s2.s3.i3 = 6; 35 | 36 | printf ("struct st st =\n" 37 | "{\n" 38 | " int i; /* %d */\n" 39 | " float f; /* %f */\n" 40 | " double d; /* %g */\n" 41 | " ...int i1; /* %d */\n" 42 | " ...int i2; /* %d */\n" 43 | " ...int i3; /* %d */\n" 44 | "};\n", st.i, st.f, st.d, 45 | st.s1.i1, 46 | st.s1.s2.i2, 47 | st.s1.s2.s3.i3); 48 | 49 | --------------------------------------------------------------------------------