From 864f44aaa9aa1446853423a2ce976b1ad4b897b9 Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Tue, 6 Oct 2020 14:04:17 +0200 Subject: [PATCH 01/17] modern cpp --- .gitignore | 23 +- CMakeLists.txt | 6 +- bin/nrniv_makefile.in | 2 +- bin/nrnivmodl.in | 21 +- bin/nrnivmodl_makefile_cmake.in | 4 +- bin/nrnmech_makefile.in | 4 +- bin/nrnoc_makefile.in | 2 +- bin/nrnocmodl.in | 18 +- cmake/CompilerFlagsHelpers.cmake | 4 + cmake/MacroHelper.cmake | 19 +- cmake/NeuronFileLists.cmake | 215 +- cmake/ReleaseDebugAutoFlags.cmake | 16 +- setup.py | 4 +- .../python/neuron/rxd/geometry3d/setup.py.in | 2 +- share/lib/python/neuron/rxd/region.py | 2 +- src/gnu/Complex.cpp | 2 +- src/gnu/d_vec.cpp | 4 +- src/ivoc/Makefile.am | 2 +- src/ivoc/apwindow.cpp | 11 +- src/ivoc/checkpnt.cpp | 4 - src/ivoc/classreg.cpp | 2 - src/ivoc/datapath.cpp | 8 +- src/ivoc/epsprint.cpp | 2 +- src/ivoc/fourier.cpp | 6 +- src/ivoc/gifimage.cpp | 8 +- src/ivoc/graph.cpp | 15 +- src/ivoc/graphvec.cpp | 6 +- src/ivoc/grglyph.cpp | 6 +- src/ivoc/grmanip.cpp | 2 +- src/ivoc/idraw.cpp | 2 +- src/ivoc/ivoc.cpp | 20 +- src/ivoc/ivoc.h | 2 - src/ivoc/ivocmac.cpp | 6 +- src/ivoc/ivocmain.cpp | 44 +- src/ivoc/ivocrand.cpp | 27 +- src/ivoc/ivocvect.cpp | 67 +- src/ivoc/ivocvect.h | 24 +- src/ivoc/ivocwin.cpp | 10 +- src/ivoc/macmain.cpp | 5 +- src/ivoc/matrix.cpp | 12 +- src/ivoc/mlinedit.cpp | 12 +- src/ivoc/mymath.cpp | 4 +- src/ivoc/mymath.h | 4 +- ...rngsl_hc_radix2.c => nrngsl_hc_radix2.cpp} | 2 +- ...l_real_radix2.c => nrngsl_real_radix2.cpp} | 6 +- src/ivoc/nrnmain.cpp | 16 +- src/ivoc/nrnmutdec.h | 2 +- src/ivoc/objcmd.cpp | 2 - src/ivoc/oc2iv.cpp | 4 +- src/ivoc/ocbox.cpp | 14 +- src/ivoc/ocdeck.cpp | 8 +- src/ivoc/ocfile.cpp | 18 +- src/ivoc/ochelp.cpp | 6 +- src/ivoc/ocjump.cpp | 27 +- src/ivoc/oclist.cpp | 21 +- src/ivoc/ocmatrix.cpp | 4 +- src/ivoc/ocmatrix.h | 4 +- src/ivoc/ocnoiv1.cpp | 2 - src/ivoc/ocobserv.cpp | 2 +- src/ivoc/ocobserv.h | 2 +- src/ivoc/ocpicker.cpp | 2 +- src/ivoc/ocpointer.cpp | 2 +- src/ivoc/ocptrvector.cpp | 9 +- src/ivoc/octimer.cpp | 2 +- src/ivoc/pwman.cpp | 53 +- src/ivoc/strfun.cpp | 8 +- src/ivoc/symchoos.cpp | 10 +- src/ivoc/symdir.cpp | 2 - src/ivoc/utility.cpp | 11 +- src/ivoc/xdep.cpp | 1 - src/ivoc/xmenu.cpp | 20 +- src/ivoc/xmenu.h | 2 +- src/ivos/file.cpp | 16 +- src/ivos/math.cpp | 2 +- src/ivos/regexp.cpp | 4 +- src/memacs/estruct.h | 2 +- src/mesch/matrix.h | 29 +- src/mesch/matrix2.h | 11 +- src/modlunit/{consist.c => consist.cpp} | 2 +- src/modlunit/{declare.c => declare.cpp} | 57 +- src/modlunit/{init.c => init.cpp} | 113 +- src/modlunit/{io.c => io.cpp} | 38 +- src/modlunit/{kinunit.c => kinunit.cpp} | 48 +- src/modlunit/lex.l | 20 +- src/modlunit/{list.c => list.cpp} | 83 +- src/modlunit/{model.c => model.cpp} | 31 +- src/modlunit/model.h | 71 +- src/modlunit/modlunit.h | 126 +- src/modlunit/{nrnunit.c => nrnunit.cpp} | 26 +- src/modlunit/parse1.y | 27 +- src/modlunit/{passn.c => passn.cpp} | 16 +- src/modlunit/{symbol.c => symbol.cpp} | 16 +- src/modlunit/{units.c => units.cpp} | 170 +- src/modlunit/units.h | 2 +- src/modlunit/{units1.c => units1.cpp} | 46 +- src/modlunit/{version.c => version.cpp} | 0 src/mswin/extra/{d2uenv.c => d2uenv.cpp} | 0 src/mswin/extra/{d2upath.c => d2upath.cpp} | 2 +- src/mswin/extra/{splitnrn.c => splitnrn.cpp} | 2 +- src/mswin/extra/{winmain.c => winmain.cpp} | 0 src/mswin/rdln/{emacs_ke.c => emacs_ke.cpp} | 2 +- src/mswin/rdln/{funmap.c => funmap.cpp} | 2 +- src/mswin/rdln/{history.c => history.cpp} | 4 +- src/mswin/rdln/{keymaps.c => keymaps.cpp} | 6 +- src/mswin/rdln/{readline.c => readline.cpp} | 6 +- src/mswin/wnrnbbs/{ddeclnt.c => ddeclnt.cpp} | 0 src/mswin/wnrnbbs/{ddesrvr.c => ddesrvr.cpp} | 2 +- src/mswin/wnrnbbs/nrnbbs.h | 6 - src/nmodl/{consist.c => consist.cpp} | 0 src/nmodl/{cout.c => cout.cpp} | 11 +- src/nmodl/{deriv.c => deriv.cpp} | 93 +- src/nmodl/diffeq.y | 34 +- src/nmodl/{discrete.c => discrete.cpp} | 15 +- src/nmodl/extdef5.h | 2 +- src/nmodl/init.c | 254 -- src/nmodl/init.cpp | 252 ++ src/nmodl/{io.c => io.cpp} | 45 +- src/nmodl/{kinetic.c => kinetic.cpp} | 136 +- src/nmodl/lex.l | 118 +- src/nmodl/{list.c => list.cpp} | 87 +- src/nmodl/{modl.c => modl.cpp} | 32 +- src/nmodl/modl.h | 38 +- .../{netrec_discon.c => netrec_discon.cpp} | 0 src/nmodl/nmodlfunc.h | 216 +- src/nmodl/{noccout.c => noccout.cpp} | 23 +- src/nmodl/{nocpout.c => nocpout.cpp} | 176 +- src/nmodl/{parsact.c => parsact.cpp} | 116 +- src/nmodl/parse1.y | 95 +- src/nmodl/{partial.c => partial.cpp} | 30 +- src/nmodl/{sens.c => sens.cpp} | 16 +- src/nmodl/{simultan.c => simultan.cpp} | 52 +- src/nmodl/{solve.c => solve.cpp} | 39 +- src/nmodl/{symbol.c => symbol.cpp} | 17 +- src/nmodl/{units.c => units.cpp} | 2 +- src/nmodl/{version.c => version.cpp} | 0 src/nrncvode/Makefile.am | 2 +- src/nrncvode/cvodeobj.cpp | 30 +- src/nrncvode/cvodestb.cpp | 19 +- src/nrncvode/cvtrset.cpp | 4 +- src/nrncvode/hocevent.cpp | 2 - src/nrncvode/netcon.h | 2 - src/nrncvode/netcvode.cpp | 58 +- src/nrncvode/nrndaspk.cpp | 16 +- src/nrncvode/occvode.cpp | 12 +- src/nrncvode/{spaux.c => spaux.cpp} | 4 +- src/nrncvode/{spdaveb.c => spdaveb.cpp} | 2 +- src/nrncvode/spt2queue.cpp | 6 +- src/nrncvode/sptbinq.cpp | 8 +- src/nrncvode/sptfifoq.cpp | 6 +- src/nrncvode/sptqueue.cpp | 6 +- src/nrncvode/{sptree.c => sptree.cpp} | 2 +- src/nrncvode/sptree.h | 6 +- src/nrniv/CMakeLists.txt | 38 +- src/nrniv/Makefile.am | 12 +- src/nrniv/bbsavestate.cpp | 50 +- src/nrniv/bgpdma.cpp | 7 +- src/nrniv/bgpdmasetup.cpp | 4 +- src/nrniv/{bgpmeminfo.c => bgpmeminfo.cpp} | 2 +- src/nrniv/cachevec.cpp | 4 +- src/nrniv/cxprop.cpp | 36 +- src/nrniv/finithnd.cpp | 4 +- src/nrniv/geometry3d.cpp | 27 +- src/nrniv/glinerec.cpp | 6 +- src/nrniv/hocmech.cpp | 10 +- src/nrniv/impedanc.cpp | 4 +- src/nrniv/kschan.cpp | 5 +- src/nrniv/kschan.h | 8 +- src/nrniv/kssingle.cpp | 2 - src/nrniv/kssingle.h | 2 - src/nrniv/linmod.cpp | 4 +- src/nrniv/linmod1.cpp | 4 +- src/nrniv/matrixmap.cpp | 5 +- src/nrniv/multisplit.cpp | 16 +- src/nrniv/ndatclas.cpp | 5 - src/nrniv/netpar.cpp | 14 +- src/nrniv/nonlinz.cpp | 7 +- src/nrniv/nrncore_write.cpp | 3 - src/nrniv/nrncore_write.h | 6 - .../callbacks/nrncore_callbacks.cpp | 2 - src/nrniv/nrncore_write/data/cell_group.cpp | 2 - src/nrniv/nrncore_write/data/cell_group.h | 6 +- src/nrniv/nrncore_write/io/nrncore_io.cpp | 2 - src/nrniv/nrncore_write/io/nrncore_io.h | 2 - .../nrncore_write/utils/nrncore_utils.cpp | 6 +- src/nrniv/nrncore_write/utils/nrncore_utils.h | 4 +- src/nrniv/nrndae.cpp | 30 +- src/nrniv/nrnmenu.cpp | 18 +- src/nrniv/nrnmusic.cpp | 2 - src/nrniv/nrnoc2iv.h | 2 - src/nrniv/nrnpy.cpp | 14 +- src/nrniv/nrnrtime.cpp | 8 +- src/nrniv/nrnsection_mapping.h | 4 +- src/nrniv/nrnste.cpp | 2 +- ...rallel_ld.c => nvector_nrnparallel_ld.cpp} | 10 +- src/nrniv/nvector_nrnparallel_ld.h | 12 +- ...rnserial_ld.c => nvector_nrnserial_ld.cpp} | 0 src/nrniv/nvector_nrnserial_ld.h | 10 +- ...ctor_nrnthread.c => nvector_nrnthread.cpp} | 40 +- src/nrniv/nvector_nrnthread.h | 8 +- ...rnthread_ld.c => nvector_nrnthread_ld.cpp} | 40 +- src/nrniv/nvector_nrnthread_ld.h | 12 +- src/nrniv/nvkludge.cpp | 9 +- src/nrniv/partrans.cpp | 20 +- src/nrniv/ppshape.cpp | 6 +- src/nrniv/prcellstate.cpp | 8 +- src/nrniv/pysecname2sec.cpp | 2 - src/nrniv/savstate.cpp | 40 +- src/nrniv/secbrows.cpp | 8 +- src/nrniv/shape.cpp | 26 +- src/nrniv/shapeplt.cpp | 16 +- src/nrniv/singlech.cpp | 10 +- src/nrniv/spaceplt.cpp | 5 +- src/nrniv/splitcell.cpp | 4 +- src/nrniv/vrecord.cpp | 4 +- src/nrnjava/Makefile.am | 2 +- src/nrnjava/neuron/Neuron.java | 2 +- src/nrnjava/njvm.cpp | 10 +- src/nrnjava/njvm.h | 6 - src/nrnjava/nrnccmb/NrnKSChan.java | 4 +- src/nrnjava/nrnjava.cpp | 7 +- src/nrnjava/nrnjni.cpp | 4 +- src/nrnmpi/Makefile.am | 4 +- src/nrnmpi/{bbsmpipack.c => bbsmpipack.cpp} | 10 +- src/nrnmpi/{mpispike.c => mpispike.cpp} | 8 +- src/nrnmpi/mpispike.h | 6 - src/nrnmpi/{nrnmpi.c => nrnmpi.cpp} | 2 +- .../{nrnmpi_dynam.c => nrnmpi_dynam.cpp} | 12 +- ...i_dynam_stubs.c => nrnmpi_dynam_stubs.cpp} | 0 src/nrnmpi/nrnmpi_impl.h | 10 +- src/nrnmpi/nrnmpidec.h | 11 +- src/nrnmpi/{nrnrt.c => nrnrt.cpp} | 2 +- src/nrnoc/Makefile.am | 2 +- src/nrnoc/{cabcode.c => cabcode.cpp} | 115 +- src/nrnoc/cabvars.h | 104 +- src/nrnoc/capac.c | 146 - src/nrnoc/capac.cpp | 149 + src/nrnoc/clamp.c | 216 -- src/nrnoc/clamp.cpp | 219 ++ src/nrnoc/{hocusr.c => code.cpp} | 2 +- src/nrnoc/cprop.c | 41 - src/nrnoc/cprop.cpp | 52 + src/nrnoc/eion.cpp | 638 ++++ src/nrnoc/{extcelln.c => extcelln.cpp} | 43 +- src/nrnoc/{fadvance.c => fadvance.cpp} | 588 ++-- src/nrnoc/fstim.c | 169 -- src/nrnoc/fstim.cpp | 169 ++ src/nrnoc/gui-redirect.h | 6 - src/nrnoc/hh.mod | 4 +- src/nrnoc/hoc_init.cpp | 6 + src/nrnoc/hoc_oop.cpp | 6 + src/nrnoc/{hocprax.c => hocprax.cpp} | 57 +- src/nrnoc/{code.c => hocusr.cpp} | 2 +- src/nrnoc/hocusr.h | 186 ++ src/nrnoc/{init.c => init.cpp} | 202 +- src/nrnoc/{ldifus.c => ldifus.cpp} | 14 +- src/nrnoc/membdef.h | 2 +- src/nrnoc/membfunc.h | 13 +- src/nrnoc/{method3.c => method3.cpp} | 14 +- src/nrnoc/{multicore.c => multicore.cpp} | 221 +- src/nrnoc/multicore.h | 6 - src/nrnoc/multisplit.h | 6 - src/nrnoc/neuron.h | 42 +- src/nrnoc/nonvintblock.h | 18 +- src/nrnoc/nrn_ansi.h | 53 +- src/nrnoc/nrncvode.h | 12 +- src/nrnoc/nrndae_c.h | 6 - src/nrnoc/nrniv_mf.h | 101 +- src/nrnoc/nrnnemo.c | 238 -- src/nrnoc/nrnnemo.cpp | 239 ++ src/nrnoc/nrnnoiv.c | 120 - src/nrnoc/nrnnoiv.cpp | 237 ++ src/nrnoc/nrntimeout.c | 83 - src/nrnoc/nrntimeout.cpp | 86 + src/nrnoc/nrnversion.c | 82 - src/nrnoc/nrnversion.cpp | 79 + src/nrnoc/ocmain.c | 6 - src/nrnoc/{hoc_init.c => ocmain.cpp} | 2 +- src/nrnoc/ocnoiv.c | 6 - src/nrnoc/{hoc_oop.c => ocnoiv.cpp} | 2 +- src/nrnoc/osxdlfcn.c | 239 -- src/nrnoc/osxdlfcn.cpp | 214 ++ src/nrnoc/osxdlfcn.h | 2 +- src/nrnoc/{passive0.c => passive0.cpp} | 15 +- src/nrnoc/{point.c => point.cpp} | 69 +- src/nrnoc/{psection.c => psection.cpp} | 13 +- src/nrnoc/{seclist.c => seclist.cpp} | 20 +- src/nrnoc/{secref.c => secref.cpp} | 44 +- src/nrnoc/section.h | 27 +- src/nrnoc/{solve.c => solve.cpp} | 62 +- src/nrnoc/synapse.c | 227 -- src/nrnoc/synapse.cpp | 225 ++ src/nrnoc/{treeset.c => treeset.cpp} | 214 +- src/nrnpython/CMakeLists.txt | 2 +- src/nrnpython/Makefile.am | 4 +- src/nrnpython/grids.cpp | 6 +- src/nrnpython/grids.h | 2 +- src/nrnpython/hoccontext.h | 2 - src/nrnpython/inithoc.cpp | 23 +- src/nrnpython/nrnpy_hoc.cpp | 41 +- src/nrnpython/nrnpy_nrn.cpp | 4 +- src/nrnpython/nrnpy_p2h.cpp | 8 +- src/nrnpython/nrnpy_reg.h | 2 - src/nrnpython/nrnpython.cpp | 27 +- src/nrnpython/nrnpython.h | 6 - src/nrnpython/nrnpython_config.h.in | 2 +- src/nrnpython/rxd.h | 4 +- src/nrnpython/rxd_extracellular.cpp | 2 +- src/nrnpython/rxd_intracellular.cpp | 4 +- .../{rxd_llgramarea.c => rxd_llgramarea.cpp} | 4 +- ...arching_cubes.c => rxd_marching_cubes.cpp} | 2 +- src/nrnpython/{rxdmath.c => rxdmath.cpp} | 0 src/nrnpython/setup.py.in | 2 +- src/oc/Makefile.am | 32 +- src/oc/{audit.c => audit.cpp} | 5 +- src/oc/{axis.c => axis.cpp} | 12 +- src/oc/bksub.c | 6 - src/oc/bksub.cpp | 6 + src/oc/classreg.h | 6 - src/oc/code.cpp | 2668 +++++++++++++++++ src/oc/code.h | 21 +- src/oc/{code2.c => code2.cpp} | 81 +- src/oc/{cygwinprt.c => cygwinprt.cpp} | 4 +- src/oc/{debug.c => debug.cpp} | 2 +- src/oc/equation.h | 4 + src/oc/{fileio.c => fileio.cpp} | 42 +- src/oc/{fmenu.c => fmenu.cpp} | 151 +- src/oc/{ftime.c => ftime.cpp} | 42 +- src/oc/{functabl.c => functabl.cpp} | 0 src/oc/getelm.c | 6 - src/oc/getelm.cpp | 6 + src/oc/{getsym.c => getsym.cpp} | 4 +- src/oc/{hoc.c => hoc.cpp} | 77 +- src/oc/hoc_init.cpp | 397 +++ src/oc/{hoc_oop.c => hoc_oop.cpp} | 284 +- src/oc/hocassrt.h | 5 + src/oc/hocdec.h | 53 +- src/oc/{hocedit.c => hocedit.cpp} | 208 +- src/oc/hoclist.h | 79 +- src/oc/hocparse.h | 8 - src/oc/hocstr.h | 4 +- src/oc/hocusr.c | 166 - src/oc/hocusr.cpp | 160 + src/oc/{isaac64.c => isaac64.cpp} | 2 +- src/oc/isoc99.c | 22 - src/oc/isoc99.cpp | 26 + src/oc/isoc99.h | 6 + src/oc/lineq.c | 6 - src/oc/lineq.cpp | 6 + src/oc/{list.c => list.cpp} | 16 +- src/oc/{macprt.c => macprt.cpp} | 7 +- src/oc/math.c | 183 -- src/oc/math.cpp | 176 ++ src/oc/{mcran4.c => mcran4.cpp} | 25 +- src/oc/mcran4.h | 8 + src/oc/modlreg.c | 3 - src/oc/modlreg.cpp | 12 + src/oc/{mswinprt.c => mswinprt.cpp} | 17 +- src/oc/{nocable.c => nocable.cpp} | 6 +- src/oc/{nonlin.c => nonlin.cpp} | 8 +- src/oc/{nrn_vsscanf.c => nrn_vsscanf.cpp} | 2 +- src/oc/nrnassrt.h | 2 + src/oc/{nrnfilewrap.c => nrnfilewrap.cpp} | 4 +- src/oc/nrnfilewrap.h | 6 - src/oc/{nrnisaac.c => nrnisaac.cpp} | 0 src/oc/nrnisaac.h | 8 +- src/oc/nrnjava.h | 6 - src/oc/nrnmpi.h | 6 - src/oc/nrnmpi_dynam.c | 1 - src/oc/nrnmpi_dynam.cpp | 1 + src/oc/nrnmpi_dynam_stubs.c | 1 - src/oc/nrnmpi_dynam_stubs.cpp | 1 + src/oc/{nrnran123.c => nrnran123.cpp} | 20 +- src/oc/nrnran123.h | 21 +- src/oc/nrnrt.h | 6 - src/oc/oc_ansi.h | 97 +- src/oc/{ocerf.c => ocerf.cpp} | 4 +- src/oc/ocfunc.h | 9 +- src/oc/{ockludge.c => ockludge.cpp} | 0 src/oc/{ocmain.c => ocmain.cpp} | 4 +- src/oc/ocmisc.h | 3 + src/oc/{ocnoiv.c => ocnoiv.cpp} | 17 +- src/oc/{parallel.c => parallel.cpp} | 207 +- src/oc/plot.c | 1205 -------- src/oc/plot.cpp | 1195 ++++++++ src/oc/{plt.c => plt.cpp} | 3 + src/oc/prmat.c | 6 - src/oc/prmat.cpp | 6 + src/oc/profile.h | 6 - src/oc/redef.h | 4 + src/oc/{regexp.c => regexp.cpp} | 10 +- src/oc/scoplib_ansi.h | 2 + src/oc/{scoprand.c => scoprand.cpp} | 8 +- src/oc/{settext.c => settext.cpp} | 0 src/oc/{spinit.c => spinit.cpp} | 6 +- src/oc/{spinit1.c => spinit1.cpp} | 2 +- src/oc/{spinit2.c => spinit2.cpp} | 4 +- src/oc/subrows.c | 6 - src/oc/subrows.cpp | 6 + src/oc/{symbol.c => symbol.cpp} | 49 +- src/oc/{system.c => system.cpp} | 0 src/oc/{termio.c => termio.cpp} | 0 src/oc/{version.c => version.cpp} | 44 +- src/oc/{x.c => x.cpp} | 0 src/oc/{xred.c => xred.cpp} | 14 +- src/parallel/Makefile.am | 2 +- src/parallel/bbs.cpp | 8 +- src/parallel/bbsclimpi.cpp | 2 - src/parallel/bbsdirectmpi.cpp | 2 - src/parallel/bbsimpl.h | 2 +- src/parallel/bbslsrv.cpp | 4 +- src/parallel/bbslsrv2.h | 4 +- src/parallel/bbssrv2mpi.cpp | 4 +- src/parallel/bbssrv2mpi.h | 4 +- src/parallel/bbssrvmpi.cpp | 10 +- src/parallel/ocbbs.cpp | 6 +- src/parallel/subworld.cpp | 2 +- src/scopmath/newton_struct.h | 4 +- src/scopmath/newton_thread.c | 2 +- src/scopmath/praxis.c | 4 +- src/scopmath/simeq.c | 2 +- src/sparse/{bksub.c => bksub.cpp} | 0 src/sparse/{getelm.c => getelm.cpp} | 40 +- src/sparse/{lineq.c => lineq.cpp} | 0 src/sparse/{prmat.c => prmat.cpp} | 0 src/sparse/{subrows.c => subrows.cpp} | 0 src/sparse13/cspalloc.c | 0 src/sparse13/cspbuild.c | 0 src/sparse13/cspfactor.c | 0 src/sparse13/cspoutput.c | 0 src/sparse13/cspsolve.c | 0 src/sparse13/csputils.c | 0 src/sparse13/spalloc.c | 0 src/sparse13/spbuild.c | 0 src/sparse13/spfactor.c | 0 src/sparse13/spmatrix.h | 12 +- src/sparse13/spoutput.c | 0 src/sparse13/spsolve.c | 0 src/sparse13/sputils.c | 0 src/sundials/shared/nvector_parallel.c | 4 +- src/sundials/shared/nvector_parallel.h | 13 +- src/uxnrnbbs/nrnbbs.cpp | 2 +- src/uxnrnbbs/nrnbbs.h | 6 - test/unit_tests/oc/hoc_interpreter.cpp | 4 +- test/unit_tests/unit_test.cpp | 8 +- 444 files changed, 11433 insertions(+), 7888 deletions(-) rename src/ivoc/{nrngsl_hc_radix2.c => nrngsl_hc_radix2.cpp} (99%) rename src/ivoc/{nrngsl_real_radix2.c => nrngsl_real_radix2.cpp} (98%) rename src/modlunit/{consist.c => consist.cpp} (97%) rename src/modlunit/{declare.c => declare.cpp} (83%) rename src/modlunit/{init.c => init.cpp} (78%) rename src/modlunit/{io.c => io.cpp} (91%) rename src/modlunit/{kinunit.c => kinunit.cpp} (78%) rename src/modlunit/{list.c => list.cpp} (82%) rename src/modlunit/{model.c => model.cpp} (93%) rename src/modlunit/{nrnunit.c => nrnunit.cpp} (84%) rename src/modlunit/{passn.c => passn.cpp} (90%) rename src/modlunit/{symbol.c => symbol.cpp} (91%) rename src/modlunit/{units.c => units.cpp} (91%) rename src/modlunit/{units1.c => units1.cpp} (82%) rename src/modlunit/{version.c => version.cpp} (100%) rename src/mswin/extra/{d2uenv.c => d2uenv.cpp} (100%) rename src/mswin/extra/{d2upath.c => d2upath.cpp} (96%) rename src/mswin/extra/{splitnrn.c => splitnrn.cpp} (96%) rename src/mswin/extra/{winmain.c => winmain.cpp} (100%) rename src/mswin/rdln/{emacs_ke.c => emacs_ke.cpp} (99%) rename src/mswin/rdln/{funmap.c => funmap.cpp} (99%) rename src/mswin/rdln/{history.c => history.cpp} (99%) rename src/mswin/rdln/{keymaps.c => keymaps.cpp} (97%) rename src/mswin/rdln/{readline.c => readline.cpp} (99%) rename src/mswin/wnrnbbs/{ddeclnt.c => ddeclnt.cpp} (100%) rename src/mswin/wnrnbbs/{ddesrvr.c => ddesrvr.cpp} (99%) rename src/nmodl/{consist.c => consist.cpp} (100%) rename src/nmodl/{cout.c => cout.cpp} (99%) rename src/nmodl/{deriv.c => deriv.cpp} (94%) rename src/nmodl/{discrete.c => discrete.cpp} (90%) delete mode 100755 src/nmodl/init.c create mode 100755 src/nmodl/init.cpp rename src/nmodl/{io.c => io.cpp} (92%) rename src/nmodl/{kinetic.c => kinetic.cpp} (93%) rename src/nmodl/{list.c => list.cpp} (78%) rename src/nmodl/{modl.c => modl.cpp} (92%) rename src/nmodl/{netrec_discon.c => netrec_discon.cpp} (100%) rename src/nmodl/{noccout.c => noccout.cpp} (98%) rename src/nmodl/{nocpout.c => nocpout.cpp} (94%) rename src/nmodl/{parsact.c => parsact.cpp} (91%) rename src/nmodl/{partial.c => partial.cpp} (90%) rename src/nmodl/{sens.c => sens.cpp} (97%) rename src/nmodl/{simultan.c => simultan.cpp} (89%) rename src/nmodl/{solve.c => solve.cpp} (96%) rename src/nmodl/{symbol.c => symbol.cpp} (88%) rename src/nmodl/{units.c => units.cpp} (82%) rename src/nmodl/{version.c => version.cpp} (100%) rename src/nrncvode/{spaux.c => spaux.cpp} (98%) rename src/nrncvode/{spdaveb.c => spdaveb.cpp} (99%) rename src/nrncvode/{sptree.c => sptree.cpp} (99%) rename src/nrniv/{bgpmeminfo.c => bgpmeminfo.cpp} (99%) rename src/nrniv/{nvector_nrnparallel_ld.c => nvector_nrnparallel_ld.cpp} (98%) rename src/nrniv/{nvector_nrnserial_ld.c => nvector_nrnserial_ld.cpp} (100%) rename src/nrniv/{nvector_nrnthread.c => nvector_nrnthread.cpp} (98%) rename src/nrniv/{nvector_nrnthread_ld.c => nvector_nrnthread_ld.cpp} (98%) rename src/nrnmpi/{bbsmpipack.c => bbsmpipack.cpp} (97%) rename src/nrnmpi/{mpispike.c => mpispike.cpp} (98%) rename src/nrnmpi/{nrnmpi.c => nrnmpi.cpp} (99%) rename src/nrnmpi/{nrnmpi_dynam.c => nrnmpi_dynam.cpp} (96%) rename src/nrnmpi/{nrnmpi_dynam_stubs.c => nrnmpi_dynam_stubs.cpp} (100%) rename src/nrnmpi/{nrnrt.c => nrnrt.cpp} (99%) rename src/nrnoc/{cabcode.c => cabcode.cpp} (96%) delete mode 100755 src/nrnoc/capac.c create mode 100755 src/nrnoc/capac.cpp delete mode 100644 src/nrnoc/clamp.c create mode 100644 src/nrnoc/clamp.cpp rename src/nrnoc/{hocusr.c => code.cpp} (85%) delete mode 100644 src/nrnoc/cprop.c create mode 100644 src/nrnoc/cprop.cpp create mode 100644 src/nrnoc/eion.cpp rename src/nrnoc/{extcelln.c => extcelln.cpp} (95%) rename src/nrnoc/{fadvance.c => fadvance.cpp} (68%) delete mode 100644 src/nrnoc/fstim.c create mode 100644 src/nrnoc/fstim.cpp create mode 100755 src/nrnoc/hoc_init.cpp create mode 100755 src/nrnoc/hoc_oop.cpp rename src/nrnoc/{hocprax.c => hocprax.cpp} (84%) rename src/nrnoc/{code.c => hocusr.cpp} (84%) create mode 100644 src/nrnoc/hocusr.h rename src/nrnoc/{init.c => init.cpp} (85%) rename src/nrnoc/{ldifus.c => ldifus.cpp} (98%) rename src/nrnoc/{method3.c => method3.cpp} (98%) rename src/nrnoc/{multicore.c => multicore.cpp} (89%) delete mode 100644 src/nrnoc/nrnnemo.c create mode 100644 src/nrnoc/nrnnemo.cpp delete mode 100644 src/nrnoc/nrnnoiv.c create mode 100644 src/nrnoc/nrnnoiv.cpp delete mode 100644 src/nrnoc/nrntimeout.c create mode 100644 src/nrnoc/nrntimeout.cpp delete mode 100755 src/nrnoc/nrnversion.c create mode 100755 src/nrnoc/nrnversion.cpp delete mode 100755 src/nrnoc/ocmain.c rename src/nrnoc/{hoc_init.c => ocmain.cpp} (84%) delete mode 100755 src/nrnoc/ocnoiv.c rename src/nrnoc/{hoc_oop.c => ocnoiv.cpp} (84%) delete mode 100755 src/nrnoc/osxdlfcn.c create mode 100755 src/nrnoc/osxdlfcn.cpp rename src/nrnoc/{passive0.c => passive0.cpp} (79%) rename src/nrnoc/{point.c => point.cpp} (86%) rename src/nrnoc/{psection.c => psection.cpp} (93%) rename src/nrnoc/{seclist.c => seclist.cpp} (91%) rename src/nrnoc/{secref.c => secref.cpp} (89%) rename src/nrnoc/{solve.c => solve.cpp} (96%) delete mode 100644 src/nrnoc/synapse.c create mode 100644 src/nrnoc/synapse.cpp rename src/nrnoc/{treeset.c => treeset.cpp} (95%) rename src/nrnpython/{rxd_llgramarea.c => rxd_llgramarea.cpp} (82%) rename src/nrnpython/{rxd_marching_cubes.c => rxd_marching_cubes.cpp} (98%) rename src/nrnpython/{rxdmath.c => rxdmath.cpp} (100%) rename src/oc/{audit.c => audit.cpp} (98%) rename src/oc/{axis.c => axis.cpp} (98%) delete mode 100755 src/oc/bksub.c create mode 100755 src/oc/bksub.cpp create mode 100755 src/oc/code.cpp rename src/oc/{code2.c => code2.cpp} (90%) rename src/oc/{cygwinprt.c => cygwinprt.cpp} (95%) rename src/oc/{debug.c => debug.cpp} (98%) rename src/oc/{fileio.c => fileio.cpp} (95%) rename src/oc/{fmenu.c => fmenu.cpp} (86%) rename src/oc/{ftime.c => ftime.cpp} (63%) rename src/oc/{functabl.c => functabl.cpp} (100%) delete mode 100755 src/oc/getelm.c create mode 100755 src/oc/getelm.cpp rename src/oc/{getsym.c => getsym.cpp} (97%) rename src/oc/{hoc.c => hoc.cpp} (96%) create mode 100755 src/oc/hoc_init.cpp rename src/oc/{hoc_oop.c => hoc_oop.cpp} (88%) rename src/oc/{hocedit.c => hocedit.cpp} (54%) delete mode 100755 src/oc/hocusr.c create mode 100755 src/oc/hocusr.cpp rename src/oc/{isaac64.c => isaac64.cpp} (98%) delete mode 100644 src/oc/isoc99.c create mode 100644 src/oc/isoc99.cpp create mode 100644 src/oc/isoc99.h delete mode 100755 src/oc/lineq.c create mode 100755 src/oc/lineq.cpp rename src/oc/{list.c => list.cpp} (92%) rename src/oc/{macprt.c => macprt.cpp} (97%) delete mode 100755 src/oc/math.c create mode 100755 src/oc/math.cpp rename src/oc/{mcran4.c => mcran4.cpp} (90%) delete mode 100755 src/oc/modlreg.c create mode 100755 src/oc/modlreg.cpp rename src/oc/{mswinprt.c => mswinprt.cpp} (97%) rename src/oc/{nocable.c => nocable.cpp} (96%) rename src/oc/{nonlin.c => nonlin.cpp} (99%) rename src/oc/{nrn_vsscanf.c => nrn_vsscanf.cpp} (99%) rename src/oc/{nrnfilewrap.c => nrnfilewrap.cpp} (98%) rename src/oc/{nrnisaac.c => nrnisaac.cpp} (100%) delete mode 100644 src/oc/nrnmpi_dynam.c create mode 100644 src/oc/nrnmpi_dynam.cpp delete mode 100644 src/oc/nrnmpi_dynam_stubs.c create mode 100644 src/oc/nrnmpi_dynam_stubs.cpp rename src/oc/{nrnran123.c => nrnran123.cpp} (75%) rename src/oc/{ocerf.c => ocerf.cpp} (95%) rename src/oc/{ockludge.c => ockludge.cpp} (100%) rename src/oc/{ocmain.c => ocmain.cpp} (95%) rename src/oc/{ocnoiv.c => ocnoiv.cpp} (88%) rename src/oc/{parallel.c => parallel.cpp} (52%) delete mode 100755 src/oc/plot.c create mode 100755 src/oc/plot.cpp rename src/oc/{plt.c => plt.cpp} (99%) delete mode 100755 src/oc/prmat.c create mode 100755 src/oc/prmat.cpp rename src/oc/{regexp.c => regexp.cpp} (97%) rename src/oc/{scoprand.c => scoprand.cpp} (93%) rename src/oc/{settext.c => settext.cpp} (100%) rename src/oc/{spinit.c => spinit.cpp} (83%) rename src/oc/{spinit1.c => spinit1.cpp} (88%) rename src/oc/{spinit2.c => spinit2.cpp} (53%) delete mode 100755 src/oc/subrows.c create mode 100755 src/oc/subrows.cpp rename src/oc/{symbol.c => symbol.cpp} (90%) rename src/oc/{system.c => system.cpp} (100%) rename src/oc/{termio.c => termio.cpp} (100%) rename src/oc/{version.c => version.cpp} (96%) rename src/oc/{x.c => x.cpp} (100%) rename src/oc/{xred.c => xred.cpp} (94%) rename src/sparse/{bksub.c => bksub.cpp} (100%) mode change 100755 => 100644 rename src/sparse/{getelm.c => getelm.cpp} (50%) mode change 100755 => 100644 rename src/sparse/{lineq.c => lineq.cpp} (100%) mode change 100755 => 100644 rename src/sparse/{prmat.c => prmat.cpp} (100%) mode change 100755 => 100644 rename src/sparse/{subrows.c => subrows.cpp} (100%) mode change 100755 => 100644 mode change 100755 => 100644 src/sparse13/cspalloc.c mode change 100755 => 100644 src/sparse13/cspbuild.c mode change 100755 => 100644 src/sparse13/cspfactor.c mode change 100755 => 100644 src/sparse13/cspoutput.c mode change 100755 => 100644 src/sparse13/cspsolve.c mode change 100755 => 100644 src/sparse13/csputils.c mode change 100755 => 100644 src/sparse13/spalloc.c mode change 100755 => 100644 src/sparse13/spbuild.c mode change 100755 => 100644 src/sparse13/spfactor.c mode change 100755 => 100644 src/sparse13/spoutput.c mode change 100755 => 100644 src/sparse13/spsolve.c mode change 100755 => 100644 src/sparse13/sputils.c diff --git a/.gitignore b/.gitignore index d7a73e4404..77a1e63aa2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,17 +3,28 @@ nmodlconf.h.in nrnconf.h.in build +.DS_Store +.eggs/ +.idea/ +CMakeFiles/ +Makefile +Makefile.in +.deps +x86_64 +__pycache__ +venv +virtualenv # These files are generated at build time # It would be a good idea to create them in the # build directory in the future. -src/modlunit/lex.c -src/modlunit/parse1.c +src/modlunit/lex.cpp +src/modlunit/parse1.cpp src/modlunit/parse1.h -src/nmodl/diffeq.c +src/nmodl/diffeq.cpp src/nmodl/diffeq.h -src/nmodl/lex.c -src/nmodl/parse1.c +src/nmodl/lex.cpp +src/nmodl/parse1.cpp src/nmodl/parse1.h src/nrnoc/apcount.c src/nrnoc/exp2syn.c @@ -35,5 +46,5 @@ src/nrnoc/stim.c src/nrnoc/svclmp.c src/nrnoc/syn.c src/nrnoc/vclmp.c -src/oc/parse.c +src/oc/parse.cpp src/oc/parse.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 572437fbd6..69dbff3ae9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,6 +217,10 @@ if(NRN_ENABLE_MPI) find_package(MPI REQUIRED) set(NRNMPI 1) set(PARANEURON 1) + # avoid linking to C++ bindings + add_definitions("-DMPI_NO_CPPBIND=1") + add_definitions("-DOMPI_SKIP_MPICXX=1") + add_definitions("-DMPICH_SKIP_MPICXX=1") else() set(NRNMPI 0) set(PARANEURON 0) @@ -366,7 +370,7 @@ if(READLINE_FOUND) # this part has to be prior to adding the nrniv subdirectory. execute_process(COMMAND grep -q rl_event_hook ${Readline_LIBRARY} RESULT_VARIABLE result) if(NOT result EQUAL 0) - # define for src/oc/hoc.c + # define for src/oc/hoc.cpp set(DEF_RL_GETC_FUNCTION use_rl_getc_function) endif() find_package(Curses QUIET) diff --git a/bin/nrniv_makefile.in b/bin/nrniv_makefile.in index fa013ec812..db673c80f2 100755 --- a/bin/nrniv_makefile.in +++ b/bin/nrniv_makefile.in @@ -92,7 +92,7 @@ NRNIVOBJS = $(libobjdir)/nrnmain.o $(libobjdir)/ivocmain.o $(libobjdir)/nvkludge $(bindir)/nocmodl $* $(COMPILE) -c $*.c -mod_func.o: mod_func.c +mod_func.o: mod_func.cpp $(COMPILE) -c $< special: $(MODOBJFILES) $(COBJFILES) mod_func.o diff --git a/bin/nrnivmodl.in b/bin/nrnivmodl.in index b310b9a265..bddddfd3e4 100755 --- a/bin/nrnivmodl.in +++ b/bin/nrnivmodl.in @@ -139,31 +139,38 @@ echo '#include #include "hocdec.h" extern int nrnmpi_myid; extern int nrn_nobanner_; -' > mod_func.c +#if defined(__cplusplus) +extern "C" { +#endif +' > mod_func.cpp for i in $bfiles ; do echo 'extern void _'$i'_reg(void);' -done >> mod_func.c +done >> mod_func.cpp echo ' void modl_reg(){ if (!nrn_nobanner_) if (nrnmpi_myid < 1) { fprintf(stderr, "Additional mechanisms from files'$newline'"); -' >> mod_func.c +' >> mod_func.cpp for i in $files do echo ' fprintf(stderr," '$i'.mod");' -done >>mod_func.c +done >>mod_func.cpp echo ' fprintf(stderr, "'$newline'"); - }' >>mod_func.c + }' >>mod_func.cpp for i in $bfiles; do echo ' _'$i'_reg();' MODOBJS="$MODOBJS $i.o" -done >> mod_func.c +done >> mod_func.cpp -echo "}" >> mod_func.c +echo "}" >> mod_func.cpp +echo ' +#if defined(__cplusplus) +} +#endif' >> mod_func.cpp if test -n "$cfiles" ; then COBJS=`echo "$cfiles" | sed 's/\.c/.o/g'` diff --git a/bin/nrnivmodl_makefile_cmake.in b/bin/nrnivmodl_makefile_cmake.in index 8028c9b752..c71df506f1 100644 --- a/bin/nrnivmodl_makefile_cmake.in +++ b/bin/nrnivmodl_makefile_cmake.in @@ -47,7 +47,7 @@ modc_files = $(addprefix $(MODC_DIR)/,$(addsuffix .c,$(mod_names))) mod_objs = $(addprefix $(OBJS_DIR)/,$(addsuffix .o,$(mod_names))) mod_func_o = $(OBJS_DIR)/mod_func.o -mod_func_c = $(MODC_DIR)/mod_func.c +mod_func_cpp = $(MODC_DIR)/mod_func.cpp special = $(OUTPUT)/special LIB_SUFFIX_ = $(if $(MECH_NAME),_$(MECH_NAME),) @@ -101,7 +101,7 @@ mech_lib_static: mod_func.o $(mod_objs) build_always @printf " => $(C_GREEN)LINKING$(C_RESET) static library $(mech_lib) Mod files: $(mod_files)\n" (cd .. ; ar cq ${mech_lib} $(mod_func_o) $(mod_objs);) -mod_func.o: mod_func.c +mod_func.o: mod_func.cpp @printf " -> $(C_GREEN)Compiling$(C_RESET) $<\n" $(COMPILE) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ -c $< -o $@ diff --git a/bin/nrnmech_makefile.in b/bin/nrnmech_makefile.in index da3de33ad5..ff9026d137 100755 --- a/bin/nrnmech_makefile.in +++ b/bin/nrnmech_makefile.in @@ -84,8 +84,8 @@ NRNIVOBJS = "$(libobjdir)/nrnmain.o" "$(libobjdir)/ivocmain.o" "$(libobjdir)/nvk "$(bindir)/nocmodl" $* $(LTCOMPILE) -c -o $@ $*.c -mod_func.lo: mod_func.c - $(LTCOMPILE) -c -o $@ $*.c +mod_func.lo: mod_func.cpp + $(LTCOMPILE) -c -o $@ $*.cpp libnrnmech_la_OBJECTS = $(MODOBJFILES) mod_func.lo $(COBJFILES) libnrnmech_la_LIBADD = $(NRNOCLIBS) $(NRNIVLIBS) diff --git a/bin/nrnoc_makefile.in b/bin/nrnoc_makefile.in index 03c9287be8..ca6b637ea9 100755 --- a/bin/nrnoc_makefile.in +++ b/bin/nrnoc_makefile.in @@ -76,7 +76,7 @@ NRNOCOBJS = $(libobjdir)/ocmain.o $(libobjdir)/nrnnoiv.o $(libobjdir)/ocnoiv.o $(bindir)/nocmodl $* $(COMPILE) -c $*.c -mod_func.o: mod_func.c +mod_func.o: mod_func.cpp $(COMPILE) -c $< special: $(MODOBJFILES) mod_func.o diff --git a/bin/nrnocmodl.in b/bin/nrnocmodl.in index 08840f0717..9df9fd8aef 100755 --- a/bin/nrnocmodl.in +++ b/bin/nrnocmodl.in @@ -43,22 +43,30 @@ fi echo '#include #include "hocdec.h" +#if defined(__cplusplus) +extern "C" +#endif modl_reg(){ NOT_PARALLEL_SUB(fprintf(stderr, "Additional mechanisms from files'$newline'");) -' > mod_func.c +' > mod_func.cpp for i in $files do - echo 'NOT_PARALLEL_SUB(fprintf(stderr," '$i'.mod");)' >>mod_func.c + echo 'NOT_PARALLEL_SUB(fprintf(stderr," '$i'.mod");)' >>mod_func.cpp done -echo 'NOT_PARALLEL_SUB(fprintf(stderr, "'$newline'");)' >>mod_func.c +echo 'NOT_PARALLEL_SUB(fprintf(stderr, "'$newline'");)' >>mod_func.cpp for i in $files do - echo _"$i"_reg"();" >> mod_func.c + echo _"$i"_reg"();" >> mod_func.cpp MODOBJS="$MODOBJS $i.o" done -echo "}" >> mod_func.c +echo "}" >> mod_func.cpp + +echo ' +#if defined(__cplusplus) +} +#endif' >> mod_func.cpp make -f $MAKEFILEDIR/nrnoc_makefile "MODOBJFILES=$MODOBJS" special && echo "Successfully created $MODSUBDIR/special" diff --git a/cmake/CompilerFlagsHelpers.cmake b/cmake/CompilerFlagsHelpers.cmake index 942c614ff4..6d6689f54b 100644 --- a/cmake/CompilerFlagsHelpers.cmake +++ b/cmake/CompilerFlagsHelpers.cmake @@ -63,6 +63,7 @@ foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST}) set(CMAKE_${COMPILER_LANGUAGE}_POSITION_INDEPENDENT "-fPIC") set(CMAKE_${COMPILER_LANGUAGE}_VECTORIZE "-ftree-vectorize") set(IGNORE_UNKNOWN_PRAGMA_FLAGS "-Wno-unknown-pragmas") + set(CMAKE_${COMPILER_LANGUAGE}_IGNORE_WARNINGS "-Wno-write-strings") if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_VERSION VERSION_GREATER "4.7.0") set(CMAKE_${COMPILER_LANGUAGE}_LINK_TIME_OPT "-flto") @@ -87,6 +88,7 @@ foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST}) set(CMAKE_${COMPILER_LANGUAGE}_VECTORIZE "") set(IGNORE_UNKNOWN_PRAGMA_FLAGS "-Wno-unknown-pragmas") set(CMAKE_${COMPILER_LANGUAGE}_GEN_NATIVE "-march=native") + set(CMAKE_${COMPILER_LANGUAGE}_IGNORE_WARNINGS "-Wno-deprecated-register -Wno-writable-strings") # rest of the world else() set(CMAKE_${COMPILER_LANGUAGE}_WARNING_ALL "-Wall") @@ -97,7 +99,9 @@ foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST}) set(CMAKE_${COMPILER_LANGUAGE}_STACK_PROTECTION "") set(CMAKE_${COMPILER_LANGUAGE}_POSITION_INDEPENDENT "-fPIC") set(CMAKE_${COMPILER_LANGUAGE}_VECTORIZE "") + set(CMAKE_${COMPILER_LANGUAGE}_IGNORE_WARNINGS "-Wno-deprecated-register -Wno-writable-strings") if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "PGI") + set(CMAKE_${COMPILER_LANGUAGE}_IGNORE_WARNINGS "") set(CMAKE_${COMPILER_LANGUAGE}_WARNING_ALL "") endif() endif() diff --git a/cmake/MacroHelper.cmake b/cmake/MacroHelper.cmake index adb2928fe6..5e144d4bc4 100644 --- a/cmake/MacroHelper.cmake +++ b/cmake/MacroHelper.cmake @@ -31,15 +31,15 @@ macro(nrn_check_dir_exists HEADER VARIABLE) if(${HAVE_HEADER}) # if header is found, create a code from template string(REPLACE "@dir_header@" ${HEADER} CONFTEST_DIR "${CONFTEST_DIR_TPL}") - file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/conftest.c ${CONFTEST_DIR}) + file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/conftest.cpp ${CONFTEST_DIR}) # try to compile - try_compile(RESULT_VAR ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/conftest.c) + try_compile(RESULT_VAR ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/conftest.cpp) if(${RESULT_VAR}) set(${VARIABLE} 1) else() set(${VARIABLE} 0) endif() - file(REMOVE "conftest.c") + file(REMOVE "conftest.cpp") endif() endmacro() @@ -59,13 +59,13 @@ macro(nrn_check_type_exists HEADER TYPE DEFAULT_TYPE VARIABLE) }") string(REPLACE "@header@" ${HEADER} CONFTEST_TYPE "${CONFTEST_TYPE_TPL}") string(REPLACE "@type@" ${TYPE} CONFTEST_TYPE "${CONFTEST_TYPE}") - file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/conftest.c ${CONFTEST_TYPE}) + file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/conftest.cpp ${CONFTEST_TYPE}) - try_compile(RESULT_VAR ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/conftest.c) + try_compile(RESULT_VAR ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/conftest.cpp) if(NOT ${RESULT_VAR}) set(${VARIABLE} ${DEFAULT_TYPE}) endif() - file(REMOVE "conftest.c") + file(REMOVE "conftest.cpp") endmacro() # ============================================================================= @@ -81,14 +81,14 @@ macro(nrn_check_signal_return_type VARIABLE) int main () { return *(signal (0, 0)) (0) == 1; }") - file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/conftest.c ${CONFTEST_RETSIGTYPE}) - try_compile(RESULT_VAR ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/conftest.c) + file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/conftest.cpp ${CONFTEST_RETSIGTYPE}) + try_compile(RESULT_VAR ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/conftest.cpp) if(RESULT_VAR) set(${VARIABLE} int) else() set(${VARIABLE} void) endif() - file(REMOVE "conftest.c") + file(REMOVE "conftest.cpp") endmacro() # ============================================================================= @@ -254,6 +254,7 @@ macro(nocmodl_mod_to_c modfile_basename) COMMAND ${CMAKE_COMMAND} -E env "MODLUNIT=${PROJECT_BINARY_DIR}/share/nrn/lib/nrnunits.lib" ${PROJECT_BINARY_DIR}/bin/nocmodl ${modfile_basename}.mod COMMAND sed "'s/_reg()/_reg_()/'" ${modfile_basename}.c > ${modfile_basename}.c.tmp +# COMMAND sed "'s/__cplusplus/__cminusminus/'" ${modfile_basename}.c.tmp > ${modfile_basename}.c.tmp2 COMMAND mv ${modfile_basename}.c.tmp ${modfile_basename}.c DEPENDS nocmodl ${modfile_basename}.mod WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/src/nrniv) diff --git a/cmake/NeuronFileLists.cmake b/cmake/NeuronFileLists.cmake index 251e075ad1..5747a0ec9c 100644 --- a/cmake/NeuronFileLists.cmake +++ b/cmake/NeuronFileLists.cmake @@ -12,6 +12,7 @@ set(HEADER_FILES_TO_INSTALL hocgetsym.h hoclist.h hocparse.h + isoc99.h ivstream.h md1redef.h md2redef.h @@ -51,79 +52,79 @@ set(NRN_HEADERS_INCLUDE_LIST) # ============================================================================= # Lists of random number related files # ============================================================================= -set(RAN_FILE_LIST isaac64.c mcran4.c nrnisaac.c nrnran123.c) +set(RAN_FILE_LIST isaac64.cpp mcran4.cpp nrnisaac.cpp nrnran123.cpp) # ============================================================================= # Files in oc directory # ============================================================================= set(OC_FILE_LIST ${RAN_FILE_LIST} - audit.c - axis.c - bksub.c - code2.c - cygwinprt.c - debug.c - fileio.c - fmenu.c - ftime.c - functabl.c - getelm.c - getsym.c - hoc.c - hocedit.c - isoc99.c - lineq.c - list.c - math.c - nonlin.c - nrnfilewrap.c - ocerf.c - parallel.c - parse.c - plot.c - plt.c - prmat.c - regexp.c - scoprand.c - settext.c - subrows.c - symbol.c - version.c - x.c - xred.c) + audit.cpp + axis.cpp + bksub.cpp + code2.cpp + cygwinprt.cpp + debug.cpp + fileio.cpp + fmenu.cpp + ftime.cpp + functabl.cpp + getelm.cpp + getsym.cpp + hoc.cpp + hocedit.cpp + isoc99.cpp + lineq.cpp + list.cpp + math.cpp + nonlin.cpp + nrnfilewrap.cpp + ocerf.cpp + parallel.cpp + parse.cpp + plot.cpp + plt.cpp + prmat.cpp + regexp.cpp + scoprand.cpp + settext.cpp + subrows.cpp + symbol.cpp + version.cpp + x.cpp + xred.cpp) # ============================================================================= # Files in nrnoc directory # ============================================================================= set(NRNOC_FILE_LIST - cabcode.c - capac.c - clamp.c - code.c - eion.c - extcelln.c - fadvance.c - fstim.c - hocprax.c - hocusr.c - hoc_init.c - hoc_oop.c - init.c - ldifus.c - method3.c - nrnnemo.c - nrntimeout.c - nrnversion.c + cabcode.cpp + capac.cpp + clamp.cpp + code.cpp + eion.cpp + extcelln.cpp + fadvance.cpp + fstim.cpp + hocprax.cpp + hocusr.cpp + hoc_init.cpp + hoc_oop.cpp + init.cpp + ldifus.cpp + method3.cpp + nrnnemo.cpp + nrntimeout.cpp + nrnversion.cpp nrnversion.h - passive0.c - point.c - psection.c - seclist.c - secref.c - solve.c - synapse.c - treeset.c) + passive0.cpp + point.cpp + psection.cpp + seclist.cpp + secref.cpp + solve.cpp + synapse.cpp + treeset.cpp) # ============================================================================= # Files in ivoc directory @@ -195,7 +196,7 @@ set(NRNIV_FILE_LIST bbslsrv2.cpp bbsrcli.cpp bbssrv.cpp - bgpmeminfo.c + bgpmeminfo.cpp cachevec.cpp classreg.cpp cvodeobj.cpp @@ -230,9 +231,9 @@ set(NRNIV_FILE_LIST nrnpy.cpp nrnrtime.cpp nrnste.cpp - nvector_nrnserial_ld.c - nvector_nrnthread.c - nvector_nrnthread_ld.c + nvector_nrnserial_ld.cpp + nvector_nrnthread.cpp + nvector_nrnthread_ld.cpp ocbbs.cpp occvode.cpp ocjump.cpp @@ -460,7 +461,7 @@ set(MEMACS_FILES_LIST window.c word.c) -set(NRNMPI_FILES_LIST nrnmpi.c bbsmpipack.c mpispike.c nrnrt.c) +set(NRNMPI_FILES_LIST nrnmpi.cpp bbsmpipack.cpp mpispike.cpp nrnrt.cpp) set(NRNGNU_FILES_LIST ACG.cpp @@ -497,8 +498,8 @@ set(NRNPYTHON_FILES_LIST rxd_extracellular.cpp rxd_intracellular.cpp rxd_vol.cpp - rxd_marching_cubes.c - rxd_llgramarea.c) + rxd_marching_cubes.cpp + rxd_llgramarea.cpp) # built-in mod files set(MODFILE_BASE_NAMES @@ -521,45 +522,45 @@ set(MODFILE_BASE_NAMES svclmp) set(MODLUNIT_FILES_LIST - parse1.c - lex.c - consist.c - declare.c - init.c - io.c - kinunit.c - list.c - model.c - nrnunit.c - passn.c - symbol.c - units.c - units1.c - version.c) + parse1.cpp + lex.cpp + consist.cpp + declare.cpp + init.cpp + io.cpp + kinunit.cpp + list.cpp + model.cpp + nrnunit.cpp + passn.cpp + symbol.cpp + units.cpp + units1.cpp + version.cpp) set(NMODL_FILES_LIST - parse1.c - diffeq.c - lex.c - consist.c - deriv.c - discrete.c - init.c - io.c - kinetic.c - list.c - modl.c - nocpout.c - noccout.c - parsact.c - netrec_discon.c - partial.c - sens.c - simultan.c - solve.c - symbol.c - units.c - version.c) + parse1.cpp + diffeq.cpp + lex.cpp + consist.cpp + deriv.cpp + discrete.cpp + init.cpp + io.cpp + kinetic.cpp + list.cpp + modl.cpp + nocpout.cpp + noccout.cpp + parsact.cpp + netrec_discon.cpp + partial.cpp + sens.cpp + simultan.cpp + solve.cpp + symbol.cpp + units.cpp + version.cpp) set(IVOS_FILES_LIST file.cpp @@ -593,7 +594,7 @@ nrn_create_file_list(NRN_NRNOC_SRC_FILES ${NRN_NRNOC_SRC_DIR} ${NRNOC_FILE_LIST} nrn_create_file_list(NRN_IVOC_SRC_FILES ${NRN_IVOC_SRC_DIR} ${IVOC_FILE_LIST}) nrn_create_file_list(NRN_NRNIV_SRC_FILES ${NRN_NRNIV_SRC_DIR} ${NRNIV_FILE_LIST}) nrn_create_file_list(NRN_PARALLEL_SRC_FILES ${PROJECT_SOURCE_DIR}/src/nrniv - nvector_nrnparallel_ld.c) + nvector_nrnparallel_ld.cpp) nrn_create_file_list(NRN_PARALLEL_SRC_FILES ${PROJECT_SOURCE_DIR}/src/sundials/shared nvector_parallel.c) nrn_create_file_list(NRN_MESCH_SRC_FILES ${PROJECT_SOURCE_DIR}/src/mesch ${MESCH_FILES_LIST}) @@ -608,7 +609,7 @@ nrn_create_file_list(NRN_NRNPYTHON_SRC_FILES ${PROJECT_SOURCE_DIR}/src/nrnpython ${NRNPYTHON_FILES_LIST}) nrn_create_file_list(NRN_MODFILE_BASE_NAMES ${PROJECT_SOURCE_DIR}/src/nrnoc ${MODFILE_BASE_NAMES}) nrn_create_file_list(NRN_BIN_SRC_FILES ${PROJECT_SOURCE_DIR}/src/ivoc/ nrnmain.cpp) -nrn_create_file_list(NRN_BIN_SRC_FILES ${PROJECT_SOURCE_DIR}/src/oc/ ockludge.c modlreg.c) +nrn_create_file_list(NRN_BIN_SRC_FILES ${PROJECT_SOURCE_DIR}/src/oc/ ockludge.cpp modlreg.cpp) nrn_create_file_list(NRN_MODLUNIT_SRC_FILES ${NRN_MODLUNIT_SRC_DIR} ${MODLUNIT_FILES_LIST}) nrn_create_file_list(NRN_NMODL_SRC_FILES ${NRN_NMODL_SRC_DIR} ${NMODL_FILES_LIST}) nrn_create_file_list(NRNMPI_DYNAMIC_INCLUDE_FILE ${PROJECT_SOURCE_DIR}/src/nrnmpi diff --git a/cmake/ReleaseDebugAutoFlags.cmake b/cmake/ReleaseDebugAutoFlags.cmake index e13a101cac..1df1fe115a 100644 --- a/cmake/ReleaseDebugAutoFlags.cmake +++ b/cmake/ReleaseDebugAutoFlags.cmake @@ -27,16 +27,16 @@ include(CompilerFlagsHelpers) # ~~~ set(CMAKE_C_FLAGS_DEBUG - "${CMAKE_C_DEBUGINFO_FLAGS} ${CMAKE_C_OPT_NONE} ${CMAKE_C_STACK_PROTECTION}") + "${CMAKE_C_DEBUGINFO_FLAGS} ${CMAKE_C_OPT_NONE} ${CMAKE_C_STACK_PROTECTION} ${CMAKE_C_IGNORE_WARNINGS}") set(CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_OPT_NONE} ${CMAKE_CXX_STACK_PROTECTION}") + "${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_OPT_NONE} ${CMAKE_CXX_STACK_PROTECTION} ${CMAKE_CXX_IGNORE_WARNINGS}") -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_OPT_NORMAL}") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_OPT_NORMAL}") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_OPT_NORMAL} ${CMAKE_C_IGNORE_WARNINGS}") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_OPT_NORMAL} ${CMAKE_CXX_IGNORE_WARNINGS}") -set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_DEBUGINFO_FLAGS} ${CMAKE_C_OPT_NORMAL}") -set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_OPT_NORMAL}") +set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_DEBUGINFO_FLAGS} ${CMAKE_C_OPT_NORMAL} ${CMAKE_C_IGNORE_WARNINGS}") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_OPT_NORMAL} ${CMAKE_CXX_IGNORE_WARNINGS}") -set(CMAKE_C_FLAGS_FAST "${CMAKE_C_OPT_FAST} ${CMAKE_C_LINK_TIME_OPT} ${CMAKE_C_GEN_NATIVE}") -set(CMAKE_CXX_FLAGS_FAST "${CMAKE_CXX_OPT_FAST} ${CMAKE_CXX_LINK_TIME_OPT} ${CMAKE_CXX_GEN_NATIVE}") +set(CMAKE_C_FLAGS_FAST "${CMAKE_C_OPT_FAST} ${CMAKE_C_LINK_TIME_OPT} ${CMAKE_C_GEN_NATIVE} ${CMAKE_C_IGNORE_WARNINGS}") +set(CMAKE_CXX_FLAGS_FAST "${CMAKE_CXX_OPT_FAST} ${CMAKE_CXX_LINK_TIME_OPT} ${CMAKE_CXX_GEN_NATIVE} ${CMAKE_CXX_IGNORE_WARNINGS}") # ~~~ diff --git a/setup.py b/setup.py index 7fba77ebcd..c9756bab78 100644 --- a/setup.py +++ b/setup.py @@ -317,8 +317,8 @@ def setup_package(): CyExtension( "neuron.rxd.geometry3d.surfaces", [ "share/lib/python/neuron/rxd/geometry3d/surfaces.pyx", - "src/nrnpython/rxd_marching_cubes.c", - "src/nrnpython/rxd_llgramarea.c" + "src/nrnpython/rxd_marching_cubes.cpp", + "src/nrnpython/rxd_llgramarea.cpp" ], include_dirs=include_dirs, **rxd_params diff --git a/share/lib/python/neuron/rxd/geometry3d/setup.py.in b/share/lib/python/neuron/rxd/geometry3d/setup.py.in index fbec4b65be..099fa126f7 100644 --- a/share/lib/python/neuron/rxd/geometry3d/setup.py.in +++ b/share/lib/python/neuron/rxd/geometry3d/setup.py.in @@ -74,7 +74,7 @@ else: extra_compile_args=extra_compile_args, include_dirs=include_dirs), Extension("neuron.rxd.geometry3d.surfaces", - sources=["surfaces.cpp", nrn_srcdir + "/src/nrnpython/rxd_marching_cubes.c", nrn_srcdir + "/src/nrnpython/rxd_llgramarea.c"], + sources=["surfaces.cpp", nrn_srcdir + "/src/nrnpython/rxd_marching_cubes.cpp", nrn_srcdir + "/src/nrnpython/rxd_llgramarea.cpp"], define_macros=define_macros, extra_compile_args=extra_compile_args, include_dirs=include_dirs)], diff --git a/share/lib/python/neuron/rxd/region.py b/share/lib/python/neuron/rxd/region.py index b673e2074c..8892f9ebea 100644 --- a/share/lib/python/neuron/rxd/region.py +++ b/share/lib/python/neuron/rxd/region.py @@ -355,7 +355,7 @@ def _do_init(self): self._secs1d = _sort_secs(self._secs1d) if self._secs3d and not(hasattr(self._geometry, 'volumes3d')): - raise RxDException('selected geometry (%r) does not support 3d mode' % self._geometry) + raise RxDException('selected geometry (%r) does not support 3d mode (no "volumes3d" attr)' % self._geometry) if self._secs3d: diff --git a/src/gnu/Complex.cpp b/src/gnu/Complex.cpp index 388bb0b4fa..e81535a762 100755 --- a/src/gnu/Complex.cpp +++ b/src/gnu/Complex.cpp @@ -37,7 +37,7 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. // error handling -extern "C" { extern void hoc_execerror(const char*, const char*); } +extern "C" void hoc_execerror(const char*, const char*); void default_Complex_error_handler(const char* msg) { diff --git a/src/gnu/d_vec.cpp b/src/gnu/d_vec.cpp index 24231d4d25..17040bae7d 100755 --- a/src/gnu/d_vec.cpp +++ b/src/gnu/d_vec.cpp @@ -38,7 +38,9 @@ int operator != (doubleVec& a, doubleVec& b) // error handling -extern "C" {extern void hoc_execerror(const char*, const char*);} +extern "C" { + extern void hoc_execerror(const char*, const char*); +} // extern "C" void default_doubleVec_error_handler(const char* msg) { diff --git a/src/ivoc/Makefile.am b/src/ivoc/Makefile.am index 2152b553c3..4d0720ebe2 100755 --- a/src/ivoc/Makefile.am +++ b/src/ivoc/Makefile.am @@ -68,7 +68,7 @@ noinst_HEADERS = apwindow.h axis.h bndedval.h cbwidget.h checkpnt.h \ ocglyph.h ocinput.h ocjump.h oclist.h ocmatrix.h ocobserv.h \ ocpicker.h ocpointer.h random1.h rect.h rubband.h scenepic.h \ scenevie.h symchoos.h symdir.h utility.h ivocvect.h xmenu.h \ - nrngsl.h nrngsl_hc_radix2.c nrngsl_real_radix2.c \ + nrngsl.h nrngsl_hc_radix2.cpp nrngsl_real_radix2.cpp \ grglyph.h nrnmutdec.h ocnotify.h ocptrvector.h bimap.hpp \ nrnsymdiritem.h diff --git a/src/ivoc/apwindow.cpp b/src/ivoc/apwindow.cpp index e9ef9ee457..e617c72273 100644 --- a/src/ivoc/apwindow.cpp +++ b/src/ivoc/apwindow.cpp @@ -37,17 +37,17 @@ declareActionCallback(PrintableWindow); implementActionCallback(PrintableWindow); -extern "C" { extern void single_event_run();} +extern void single_event_run(); extern void handle_old_focus(); #ifdef WIN32 #include -extern "C" { extern int iv_mere_dismiss;} +extern int iv_mere_dismiss; #endif #if MAC -extern "C" { extern void ivoc_dismiss_defer();} +extern void ivoc_dismiss_defer(); #endif // just because avoiding virtual resource @@ -234,15 +234,12 @@ const char* DismissableWindow::name() const { //printf("DismissableWindow::name %s\n", v.string()); return v.string(); } - #if defined(MINGW) -extern "C" { static const char* s_; static void setwindowtext(void* v) { HWND hw = (HWND)v; SetWindowText(hw, s_); } -} #endif void DismissableWindow::name(const char* s) { @@ -262,7 +259,7 @@ void DismissableWindow::name(const char* s) { #endif #if MAC Str255 st; - strncpy((char*)&st[1], s, 254); + strncpy(&st[1], s, 254); st[0] = strlen(s); WindowPtr theWin = Window::rep()->macWindow(); if (theWin) { diff --git a/src/ivoc/checkpnt.cpp b/src/ivoc/checkpnt.cpp index be77ea17e5..f016a2df7d 100644 --- a/src/ivoc/checkpnt.cpp +++ b/src/ivoc/checkpnt.cpp @@ -99,7 +99,6 @@ data depending on type. eg for VAR && NOTUSER it is #endif #include "checkpnt.h" -extern "C" { #include "redef.h" #include "hoclist.h" #include "parse.h" @@ -107,7 +106,6 @@ extern "C" { #include "equation.h" int hoc_readcheckpoint(char*); extern int hoc_resize_toplevel(int); -} static struct HocInst { Pfrv pi; @@ -375,12 +373,10 @@ bool Checkpoint::xdr(Object*& o) { #else -extern "C"{ void hoc_checkpoint(); int hoc_readcheckpoint(char*); void hoc_ret(); void hoc_pushx(double); -} diff --git a/src/ivoc/classreg.cpp b/src/ivoc/classreg.cpp index b61828960f..1430e25537 100755 --- a/src/ivoc/classreg.cpp +++ b/src/ivoc/classreg.cpp @@ -24,13 +24,11 @@ static void (*register_classes[])() = { ,0 }; -extern "C" { void hoc_class_registration(void) { for (int i=0; register_classes[i]; i++) { (*register_classes[i])(); } } -} /*-----------------------------------------------------*/ #if 0 diff --git a/src/ivoc/datapath.cpp b/src/ivoc/datapath.cpp index 9baef0c9bf..851f5dd85b 100644 --- a/src/ivoc/datapath.cpp +++ b/src/ivoc/datapath.cpp @@ -13,7 +13,7 @@ #include "ivocvect.h" #if !defined(CABLE) -// really belongs in vector.c but this is convenient since it will be +// really belongs in vector.cpp but this is convenient since it will be // present in ivoc but not in nrniv void nrn_vecsim_add(void*, bool) {printf("nrn_vecsym_add implemented in nrniv\n");} void nrn_vecsim_remove(void*) {printf("nrn_vecsym_remove implemented in nrniv\n");} @@ -24,22 +24,17 @@ void GraphVector::record_install(){} void GraphVector::record_uninstall(){} #endif // another hack so ivoc will have these names which nrniv gets elsewhere -extern "C" { int bbs_poll_; void bbs_done(){} void bbs_handle(){} void nrnbbs_context_wait(){} -} #ifdef WIN32 -extern "C" { void* dll_lookup(struct DLL*, const char*){return NULL;} struct DLL* dll_load(const char*){return NULL;} -} #endif #endif -extern "C" { #if CABLE #include "nrnoc2iv.h" #include "membfunc.h" @@ -51,7 +46,6 @@ extern "C" { extern Symlist* hoc_built_in_symlist; extern Symlist* hoc_top_level_symlist; extern Objectdata* hoc_top_level_data; -} /*static*/ class PathValue { public: diff --git a/src/ivoc/epsprint.cpp b/src/ivoc/epsprint.cpp index 60d414b7c5..bdd4d44c8b 100755 --- a/src/ivoc/epsprint.cpp +++ b/src/ivoc/epsprint.cpp @@ -4,7 +4,7 @@ #include #include "epsprint.h" -// ps_prolog copied from InterViews's printer.c +// ps_prolog copied from InterViews's printer.cpp static const char* ps_prolog= "\ save 20 dict begin\n\ \n\ diff --git a/src/ivoc/fourier.cpp b/src/ivoc/fourier.cpp index 8cd705e289..2b5d9edc8d 100755 --- a/src/ivoc/fourier.cpp +++ b/src/ivoc/fourier.cpp @@ -33,10 +33,10 @@ static inline double SQUARE(double a) { return a*a; } extern "C" { void hoc_execerror(const char*, const char*); extern void nrn_exit(int); -} +} // extern "C" -#include "nrngsl_real_radix2.c" -#include "nrngsl_hc_radix2.c" +#include "nrngsl_real_radix2.cpp" +#include "nrngsl_hc_radix2.cpp" void nrngsl_realft(double* data, unsigned long n, int direction) { if (direction == 1) { diff --git a/src/ivoc/gifimage.cpp b/src/ivoc/gifimage.cpp index d5a7690c29..ddd805b687 100644 --- a/src/ivoc/gifimage.cpp +++ b/src/ivoc/gifimage.cpp @@ -8,7 +8,6 @@ #include #include "oc2iv.h" -extern "C" { #define byte unsigned char #define True 1 @@ -30,7 +29,6 @@ PICINFO* pinfo_; static int LoadGIF(const char* fname, PICINFO*); -} // extern "C" Image* gif_image(const char* filename) { Image* image; @@ -43,12 +41,11 @@ Image* gif_image(const char* filename) { return image; } -extern "C" { /* - * xvgif.c - GIF loading code for 'xv'. Based strongly on... + * xvgif.cpp - GIF loading code for 'xv'. Based strongly on... * - * gif2ras.c - Converts from a Compuserve GIF (tm) image to a Sun Raster image. + * gif2ras.cpp - Converts from a Compuserve GIF (tm) image to a Sun Raster image. * * Copyright (c) 1988, 1989 by Patrick J. Naughton * @@ -808,6 +805,5 @@ static void gifWarning(const char* st) } -} // extern "C" #endif diff --git a/src/ivoc/graph.cpp b/src/ivoc/graph.cpp index 38d16fa5f5..f41e09b1b1 100644 --- a/src/ivoc/graph.cpp +++ b/src/ivoc/graph.cpp @@ -6,7 +6,7 @@ #include #include -extern "C" int hoc_return_type_code; +extern /*"C"*/ int hoc_return_type_code; #if HAVE_IV #include @@ -49,10 +49,8 @@ extern Image* gif_image(const char*); #include "classreg.h" #include "gui-redirect.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); #if HAVE_IV #define Graph_Crosshair_ "Crosshair Graph" @@ -1184,7 +1182,7 @@ IFGUI ENDGUI return (void*)g; #else - return (void*)0; + return nullptr; #endif /* HAVE_IV */ } static void gr_destruct(void* v) { @@ -1444,7 +1442,7 @@ picker()->add_menu("Erase Axis", new ActionCallback(Graph)(this, &Graph::erase_a extern "C" { extern void hoc_free_list(Symlist**); extern double* nrn_recalc_ptr(double*); -}; +} // extern "C"; Graph::~Graph() { //printf("~Graph\n"); @@ -1597,7 +1595,6 @@ void Graph::draw(Canvas* c, const Allocation& a) const { long i, cnt = line_list_.count(); //if (!extension_flushed_) { Scene::draw(c, a); -//} if (extension_flushed_) { for (i = 0; i < cnt; ++i) { line_list_.item(i)->extension()->draw(c, a); @@ -1930,7 +1927,7 @@ hoc_execerror(expr, "is invalid left hand side of assignment statement"); } } -extern "C" { extern int hoc_execerror_messages; } +extern int hoc_execerror_messages; void Graph::begin() { if (keep_lines_toggle_->test(TelltaleState::is_chosen)) { keep_lines(); diff --git a/src/ivoc/graphvec.cpp b/src/ivoc/graphvec.cpp index 817e8dddbc..fc296a95ee 100755 --- a/src/ivoc/graphvec.cpp +++ b/src/ivoc/graphvec.cpp @@ -10,10 +10,8 @@ #include "oc2iv.h" #include "ivocvect.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); Object** DataVec::new_vect(GLabel* gl) const { int i, cnt; diff --git a/src/ivoc/grglyph.cpp b/src/ivoc/grglyph.cpp index 186f812692..bc8ae2a889 100755 --- a/src/ivoc/grglyph.cpp +++ b/src/ivoc/grglyph.cpp @@ -25,10 +25,8 @@ class GrGlyph : public Resource { #include "gui-redirect.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); double gr_addglyph(void* v) { TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Graph.addglyph", v); diff --git a/src/ivoc/grmanip.cpp b/src/ivoc/grmanip.cpp index 0e8dbe36bd..69efbc9f11 100644 --- a/src/ivoc/grmanip.cpp +++ b/src/ivoc/grmanip.cpp @@ -25,7 +25,7 @@ #define LinePicker_event_ "Pick Graph" #define MoveLabelBand_press_ "MoveText Graph" -extern "C" {extern double hoc_cross_x_, hoc_cross_y_;} +extern double hoc_cross_x_, hoc_cross_y_; class LineRubberMarker : public Rubberband { public: diff --git a/src/ivoc/idraw.cpp b/src/ivoc/idraw.cpp index b034a2e514..ebc8d9059a 100644 --- a/src/ivoc/idraw.cpp +++ b/src/ivoc/idraw.cpp @@ -20,7 +20,7 @@ extern "C" { extern const char* expand_env_var(const char*); -} +} // extern "C" bool OcIdraw::closed_ = false; bool OcIdraw::curved_ = false; diff --git a/src/ivoc/ivoc.cpp b/src/ivoc/ivoc.cpp index 83d872fa31..e833e67545 100644 --- a/src/ivoc/ivoc.cpp +++ b/src/ivoc/ivoc.cpp @@ -8,10 +8,8 @@ #include "oc2iv.h" #include "ocfunc.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); #if HAVE_IV #include "utility.h" @@ -41,7 +39,6 @@ static nrn::tool::bimap* pdob; int nrn_err_dialog_active_; -extern "C" { void* (*nrnpy_save_thread)(); void (*nrnpy_restore_thread)(void*); @@ -51,7 +48,7 @@ void nrn_notify_freed(PF pf) { f_list = new FList; } f_list->append(pf); -// printf("appended to f_list in ivoc.c\n"); +// printf("appended to f_list in ivoc.cpp\n"); } void nrn_notify_when_void_freed(void* p, Observer* ob) { @@ -127,10 +124,9 @@ char* cxx_char_alloc(size_t sz) { return cp; } -} // end extern "C" #ifndef MINGW // actual implementation in ivocwin.cpp -extern "C" {void nrniv_bind_thread(void);} +void nrniv_bind_thread(void); void nrniv_bind_thread() { hoc_pushx(1.); hoc_ret(); @@ -171,7 +167,6 @@ ENDGUI * window from which oc was run. */ -extern "C" { extern void hoc_main1_init(const char* pname, const char** env); extern int hoc_oc(const char*); extern int hoc_interviews; @@ -192,18 +187,15 @@ extern "C" { extern int hoc_print_first_instance; void ivoc_style(); -} // because NEURON can no longer maintain its own copy of dialogs.cpp // we communicate with the InterViews version through a callback. -extern "C" { extern bool (*IVDialog_setAcceptInput)(bool); bool setAcceptInputCallback(bool); bool setAcceptInputCallback(bool b) { Oc oc; return oc.setAcceptInput(b); } -} void ivoc_style() { TRY_GUI_REDIRECT_DOUBLE("ivoc_style", NULL); @@ -264,11 +256,9 @@ static HandleStdin* hsd_; #if defined(WIN32) && !defined(CYGWIN) static HandleStdin* hsd_; -extern "C" { void winio_key_press() { hsd_->inputReady(1); } -} #endif @@ -456,9 +446,7 @@ void single_event_run() { } #ifdef MINGW -extern "C" { extern void nrniv_bind_call(void); -} #endif void hoc_notify_iv() { diff --git a/src/ivoc/ivoc.h b/src/ivoc/ivoc.h index e27481d3f3..a57a90b341 100644 --- a/src/ivoc/ivoc.h +++ b/src/ivoc/ivoc.h @@ -12,10 +12,8 @@ extern int nrn_err_dialog_active_; #if defined(MINGW) -extern "C" { extern bool nrn_is_gui_thread(); extern void nrn_gui_exec(void (*)(void*), void*); -} #endif class Observer; diff --git a/src/ivoc/ivocmac.cpp b/src/ivoc/ivocmac.cpp index a1260314a1..678a4a862a 100644 --- a/src/ivoc/ivocmac.cpp +++ b/src/ivoc/ivocmac.cpp @@ -22,7 +22,6 @@ typedef void (*NrnBBSCallback)(const char*); -extern "C"{ #if !defined(carbon) char * mktemp(char *){ @@ -54,7 +53,6 @@ void nrnbbs_wait(bool* pflag = (bool*)0){} bool is_mac_dll(FSSpec*); bool mac_open_dll(const char*, FSSpec*); #endif -} #if !carbon bool is_mac_dll(FSSpec* fs) { @@ -63,11 +61,9 @@ bool is_mac_dll(FSSpec* fs) { return finfo.fdType == 'shlb'; } -extern "C" { extern Symlist *hoc_symlist, *hoc_built_in_symlist; extern OSErr __path2fss(const char* name, FSSpec*); extern void hoc_nrn_load_dll(); -} static long fsspec2id(FSSpec* fs) { CInfoPBRec ci; @@ -119,7 +115,7 @@ bool mac_open_dll(const char* name, FSSpec* fs) { CFragSymbolClass symclass; myErr = GetIndSymbol(id, i, sname, &symaddr, &symclass); sname[sname[0]+1]='\0'; - if (strcmp((char*)(sname+1), "main") == 0) { + if (strcmp((sname+1), "main") == 0) { mainaddr = symaddr; } // printf("symbol %d name %s\n", i, sname+1); diff --git a/src/ivoc/ivocmain.cpp b/src/ivoc/ivocmain.cpp index 3fcab64699..1efcb30869 100644 --- a/src/ivoc/ivocmain.cpp +++ b/src/ivoc/ivocmain.cpp @@ -1,16 +1,12 @@ #include <../../nrnconf.h> #include <../nrnpython/nrnpython_config.h> -extern "C" { long hoc_nframe, hoc_nstack; -} #if !HAVE_IV #define Session void -extern "C" { - int hoc_main1(int, const char**, const char**); +int hoc_main1(int, const char**, const char**); void hoc_main1_init(const char*, const char**); -} #endif #include @@ -57,7 +53,7 @@ void iv_display_scale(float); #endif #if 1 -extern "C" { void pr_profile(); } +void pr_profile(); #define PR_PROFILE pr_profile(); #else #define PR_PROFILE /**/ @@ -119,8 +115,8 @@ static PropertyData properties[] = { {"*CBWidget_ncolor", "10"}, {"*CBWidget_nbrush", "10"}, {"*units_on_flag", "on"}, -{"*NFRAME", "0"}, // see src/oc/code.c for the default value -{"*NSTACK", "0"}, // see src/oc/code.c for the default value +{"*NFRAME", "0"}, // see src/oc/code.cpp for the default value +{"*NSTACK", "0"}, // see src/oc/code.cpp for the default value {"*Py_NoSiteFlag", "0"}, {"*python", "off"}, {"*nopython", "off"}, @@ -155,7 +151,6 @@ static OptionDesc options[] = { }; #endif // HAVE_IV -extern "C" { extern int hoc_obj_run(const char*, Object*); extern int nrn_istty_; extern char* nrn_version(int); @@ -171,7 +166,6 @@ extern "C" { extern void (*p_nrnpython_start)(int); char* nrnpy_pyexe; #endif -} /*****************************************************************************/ //exported initialized data so shared libraries can have assert pure-text @@ -187,13 +181,10 @@ extern void ivoc_cleanup(); static char* ocsmall_argv[] = {0, "difus.hoc"}; #endif #if defined(WIN32) && HAVE_IV -extern "C" { extern HWND hCurrWnd; -} #endif -extern "C" { extern void setneuronhome(const char*); extern const char* neuron_home; int hoc_xopen1(const char* filename, const char* rcs); @@ -201,7 +192,6 @@ extern "C" { extern double hoc_default_dll_loaded_; extern int hoc_print_first_instance; int nrnpy_nositeflag; -} #if !defined(WIN32) && !MAC && !defined(CYGWIN) void setneuronhome(const char*) { @@ -218,7 +208,6 @@ void penv() { } #endif -extern "C" { #if DARWIN || defined(__linux__) #include #include @@ -255,13 +244,11 @@ const char* path_prefix_to_libnrniv() { return path_prefix_to_libnrniv_; } #endif // DARWIN || defined(__linux__) -} // extern "C" #if MAC #include #include extern bool mac_load_dll(const char*); -extern "C" { void mac_open_doc(const char* s) { // only chdir and load dll on the first opendoc static bool done = false; @@ -283,17 +270,15 @@ void mac_open_doc(const char* s) { void mac_open_app(){ hoc_xopen1(":lib:hoc:macload.hoc", 0); } -} #endif #ifdef MAC #pragma export on #endif -extern "C" { - int ivocmain(int, const char**, const char**); - int ivocmain_session(int, const char**, const char**, int start_session); - int (*p_neosim_main)(int, const char**, const char**); +// int ivocmain(int, const char**, const char**); + int ivocmain_session(int, const char**, const char**, int start_session); + int (*p_neosim_main)(int, const char**, const char**); extern int nrn_global_argc; extern const char** nrn_global_argv; int always_false; @@ -303,7 +288,6 @@ extern "C" { extern void nrnmpi_stubs(); extern char* nrnmpi_load(int is_python); #endif -} // some things are defined in libraries earlier than they are used so... #include @@ -318,7 +302,7 @@ static void force_load() { #include static bool isdir(const char* p) { struct stat st; - bool b = stat((char*)p, &st) == 0 && S_ISDIR(st.st_mode); + bool b = stat(p, &st) == 0 && S_ISDIR(st.st_mode); //printf("isdir %s returns %d\n", p, b); return b; } @@ -426,7 +410,7 @@ void hoc_nrnmpi_init() { * \param env environment variable array as optionally found in main functions. * \return 0 on success, otherwise error code. */ -int ivocmain (int argc, const char** argv, const char** env) { +int ivocmain(int argc, const char** argv, const char** env) { return ivocmain_session(argc, argv, env, 1); @@ -455,7 +439,7 @@ int ivocmain (int argc, const char** argv, const char** env) { * either. * \return 0 on success, otherwise error code. */ -int ivocmain_session (int argc, const char** argv, const char** env, int start_session) { +int ivocmain_session(int argc, const char** argv, const char** env, int start_session) { // third arg should not be used as it might become invalid // after putenv or setenv. Instead, if necessary use // #include @@ -780,7 +764,7 @@ ENDGUI // but not different arguments. So the -dll is insufficient. // Therefore we check to see if it makes sense to load // a dll from the usual location. - // Actually this is done by default in src/nrnoc/init.c + // Actually this is done by default in src/nrnoc/init.cpp } #endif @@ -902,10 +886,11 @@ void ivoc_final_exit() { } extern "C" { - -extern void hoc_ret(), hoc_pushx(double); extern double *getarg(int i); extern int ifarg(int); +} // extern "C" + +extern void hoc_ret(), hoc_pushx(double); void hoc_single_event_run() { #if HAVE_IV @@ -923,5 +908,4 @@ ENDGUI int run_til_stdin() {return 1;} void hoc_notify_value(){} #endif -} diff --git a/src/ivoc/ivocrand.cpp b/src/ivoc/ivocrand.cpp index b9249220c2..28b4e5865d 100755 --- a/src/ivoc/ivocrand.cpp +++ b/src/ivoc/ivocrand.cpp @@ -40,7 +40,8 @@ #undef dmaxuint #define dmaxuint 4294967295. -extern "C" {void nrn_random_play(); } +extern "C" void nrn_random_play(); + class RandomPlay : public Observer, public Resource { public: RandomPlay(Rand*, double*); @@ -58,15 +59,15 @@ implementPtrList(RandomPlayList, RandomPlay) static RandomPlayList* random_play_list_; extern "C" { -double nrn_random_pick(Rand* r); +//double nrn_random_pick(Rand* r); void nrn_random_reset(Rand* r); -Rand* nrn_random_arg(int); +//Rand* nrn_random_arg(int); long nrn_get_random_sequence(Rand* r); void nrn_set_random_sequence(Rand* r, long seq); -int nrn_random_isran123(Rand* r, uint32_t* id1, uint32_t* id2, uint32_t* id3); -#include +//int nrn_random_isran123(Rand* r, uint32_t* id1, uint32_t* id2, uint32_t* id3); +} // extern "C" -} +#include class NrnRandom123 : public RNG { public: @@ -293,19 +294,19 @@ static double r_MCellRan4(void* r) { return (double)mcr->orig_; } -long nrn_get_random_sequence(Rand* r) { +extern "C" long nrn_get_random_sequence(Rand* r) { assert(r->type_ == 2); MCellRan4* mcr = (MCellRan4*)r->gen; return mcr->ihigh_; } -void nrn_set_random_sequence(Rand* r, long seq) { +extern "C" void nrn_set_random_sequence(Rand* r, long seq) { assert(r->type_ == 2); MCellRan4* mcr = (MCellRan4*)r->gen; mcr->ihigh_ = seq; } -int nrn_random_isran123(Rand* r, uint32_t* id1, uint32_t* id2, uint32_t* id3) { +extern "C" int nrn_random_isran123(Rand* r, uint32_t* id1, uint32_t* id2, uint32_t* id3) { if (r->type_ == 4) { NrnRandom123* nr = (NrnRandom123*)r->gen; nrnran123_getids3(nr->s_, id1, id2, id3); @@ -387,7 +388,7 @@ static double r_repick(void* r) return (*(x->rand))(); } -double nrn_random_pick(Rand* r) { +extern "C" double nrn_random_pick(Rand* r) { if (r) { return (*(r->rand))(); }else{ @@ -395,13 +396,13 @@ double nrn_random_pick(Rand* r) { } } -void nrn_random_reset(Rand* r) { +extern "C" void nrn_random_reset(Rand* r) { if(r) { r->gen->reset(); } } -Rand* nrn_random_arg(int i) { +extern "C" Rand* nrn_random_arg(int i) { Object* ob = *hoc_objgetarg(i); check_obj_type(ob, "Random"); Rand* r = (Rand*)(ob->u.this_pointer); @@ -580,7 +581,7 @@ static double r_play(void* r){ return 0.; } -void nrn_random_play() { +extern "C" void nrn_random_play() { long i, cnt = random_play_list_->count(); for (i=0; i < cnt; ++i) { random_play_list_->item(i)->play(); diff --git a/src/ivoc/ivocvect.cpp b/src/ivoc/ivocvect.cpp index 4884614ab6..03c7d54ca1 100644 --- a/src/ivoc/ivocvect.cpp +++ b/src/ivoc/ivocvect.cpp @@ -35,7 +35,7 @@ #endif #if defined(SVR4) -extern "C" {extern void exit(int status);}; +extern void exit(int status); #endif #include "classreg.h" @@ -47,10 +47,8 @@ extern "C" {extern void exit(int status);}; #include "gui-redirect.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); #ifndef PI #ifndef M_PI @@ -60,8 +58,8 @@ extern "C" { #endif #define BrainDamaged 0 //The Sun CC compiler but it doesn't hurt to leave it in #if BrainDamaged -#define FWrite(arg1,arg2,arg3,arg4) if (fwrite((char*)(arg1),arg2,arg3,arg4) != arg3) { hoc_execerror("fwrite error", 0); } -#define FRead(arg1,arg2,arg3,arg4) if (fread((char*)(arg1),arg2,arg3,arg4) != arg3) { hoc_execerror("fread error", 0); } +#define FWrite(arg1,arg2,arg3,arg4) if (fwrite((arg1),arg2,arg3,arg4) != arg3) { hoc_execerror("fwrite error", 0); } +#define FRead(arg1,arg2,arg3,arg4) if (fread((arg1),arg2,arg3,arg4) != arg3) { hoc_execerror("fread error", 0); } #else #define FWrite(arg1,arg2,arg3,arg4) if (fwrite(arg1,arg2,arg3,arg4) != arg3){} #define FRead(arg1,arg2,arg3,arg4) if (fread(arg1,arg2,arg3,arg4) != arg3) {} @@ -104,24 +102,24 @@ static double dmaxint_; #include "parse.h" #include "ocfile.h" -extern "C" { extern Object* hoc_thisobject; extern Symlist* hoc_top_level_symlist; -extern void nrn_exit(int); +extern "C" void nrn_exit(int); IvocVect* (*nrnpy_vec_from_python_p_)(void*); Object** (*nrnpy_vec_to_python_p_)(void*); Object** (*nrnpy_vec_as_numpy_helper_)(int, double*); -}; int cmpfcn(double a, double b) { return ((a) <= (b))? (((a) == (b))? 0 : -1) : 1; } -// math functions with error checking defined in oc/SRC/math.c +// math functions with error checking defined in oc/SRC/math.cpp +extern double hoc_Log(double x), hoc_Log10(double x), /*hoc_Exp(double x), */hoc_Sqrt(double x); +extern double hoc_scan(FILE*); + extern "C" { - extern double hoc_Log(double x), hoc_Log10(double x), hoc_Exp(double x), hoc_Sqrt(double x); - extern double hoc_scan(FILE*); -} + extern double hoc_Exp(double); +} // extern "C" static int narg() { int i=0; @@ -138,14 +136,15 @@ static int narg() { #define EPSILON 1e-9 extern "C" { - extern void notify_freed_val_array(double*, size_t); - extern void install_vector_method(const char* name, Pfrd_vp); - extern int vector_instance_px(void*, double**); - extern int vector_arg_px(int, double**); - extern int nrn_mlh_gsort (double* vec, int *base_ptr, int total_elems, doubleComparator cmp); -}; +extern void install_vector_method(const char* name, Pfrd_vp); +extern int vector_instance_px(void*, double**); +extern int nrn_mlh_gsort (double* vec, int *base_ptr, int total_elems, doubleComparator cmp); +} // extern "C" + +extern int vector_arg_px(int, double**); +extern void notify_freed_val_array(double*, size_t); -extern "C" int hoc_return_type_code; +extern /*"C"*/ int hoc_return_type_code; IvocVect::IvocVect(Object* o) : ParentVect(){obj_ = o; label_ = NULL; MUTCONSTRUCT(0)} IvocVect::IvocVect(int l, Object* o) : ParentVect(l){obj_ = o; label_ = NULL; MUTCONSTRUCT(0)} @@ -297,7 +296,7 @@ void vector_append(Vect* v, double x){ #ifdef WIN32 #if !defined(USEMATRIX) || USEMATRIX == 0 #include "../windll/dll.h" -extern "C" {extern char* neuron_home;} +extern char* neuron_home; void load_ocmatrix() { struct DLL* dll = NULL; @@ -339,15 +338,15 @@ void install_vector_method(const char* name, double (*f)(void*)) { #define PUBLIC_TYPE 1 s_meth->cpublic = PUBLIC_TYPE; } -} +} // extern "C" -int vector_instance_px(void* v, double** px) { +extern "C" int vector_instance_px(void* v, double** px) { Vect* x = (Vect*)v; *px = x->vec(); return x->capacity(); } -Vect* vector_arg(int i) { +extern "C" Vect* vector_arg(int i) { Object* ob = *hoc_objgetarg(i); if (!ob || ob->ctemplate != svec_->u.ctemplate) { check_obj_type(ob, "Vector"); @@ -1246,9 +1245,9 @@ static Object** v_smhist(void* v) { v1->fill(0.,0,size); for (i=0;i EPSILON) v1->elem(i) = ans[i]; - free((char*) series); - free((char*) gauss); - free((char*) ans); + free( series); + free( gauss); + free( ans); return v1->temp_objvar(); } @@ -2664,10 +2663,10 @@ Label3:; } for(i=0;iu.this_pointer; @@ -3859,7 +3856,7 @@ static inline void SWAP(int* A, int* B) smaller partition. This *guarantees* no more than log (n) stack size is needed! */ -int nrn_mlh_gsort (double* vec, int *base_ptr, int total_elems, doubleComparator cmp) +extern "C" int nrn_mlh_gsort (double* vec, int *base_ptr, int total_elems, doubleComparator cmp) { /* Stack node declarations used to store unfulfilled partition obligations. */ struct stack_node { int *lo; int *hi; }; diff --git a/src/ivoc/ivocvect.h b/src/ivoc/ivocvect.h index 89b31d749e..031eebfd0d 100644 --- a/src/ivoc/ivocvect.h +++ b/src/ivoc/ivocvect.h @@ -2,11 +2,10 @@ #define ivoc_vector_h // definition of vector classes from the gnu c++ class library -#include +#include #include #define ParentVect doubleAVec -#define Vect IvocVect struct Object; @@ -42,8 +41,7 @@ class IvocVect : public ParentVect { char* label_; MUTDEC }; - - +#define Vect IvocVect extern "C" { extern Vect* vector_new(int, Object*); // use this if possible extern Vect* vector_new0(); @@ -51,16 +49,26 @@ extern Vect* vector_new1(int); extern Vect* vector_new2(Vect*); extern void vector_delete(Vect*); extern int vector_buffer_size(Vect*); -extern int vector_capacity(Vect*); -extern void vector_resize(Vect*, int); extern Object** vector_temp_objvar(Vect*); -extern double* vector_vec(Vect*); extern Object** vector_pobj(Vect*); -extern Vect* vector_arg(int); + extern int is_vector_arg(int); extern char* vector_get_label(Vect*); extern void vector_set_label(Vect*, char*); +} // extern "C" + +#if defined(__cplusplus) +extern "C" { +#endif + +extern Vect* vector_arg(int); +extern double* vector_vec(Vect*); +extern int vector_capacity(Vect*); +extern void vector_resize(Vect*, int); + +#if defined(__cplusplus) } +#endif #endif diff --git a/src/ivoc/ivocwin.cpp b/src/ivoc/ivocwin.cpp index 629a30918a..29a6d9d8b5 100644 --- a/src/ivoc/ivocwin.cpp +++ b/src/ivoc/ivocwin.cpp @@ -36,10 +36,8 @@ // the link step needs liboc after libivoc but liboc refers to some // things in libivoc that wouldn't normally be linked because nothing // refers to them while libivoc is linking. So force them to link here -extern "C" { int ivoc_list_look(Object*, Object*, char*, int); void hoc_class_registration(); -} static void dummy() { ivoc_list_look(NULL, NULL, NULL, 0); hoc_class_registration(); @@ -69,11 +67,9 @@ void mswin_delete_object(void* v) { //--------------------------------------------------------- -extern "C" { void ivoc_win32_cleanup() { Oc::cleanup(); } -} void Oc::cleanup() { if (help_cursor_) { @@ -205,7 +201,6 @@ void IOHandler::childStatus(pid_t, int){} #ifdef MINGW #include -extern "C" { static int bind_tid_; void nrniv_bind_thread(void); extern int (*iv_bind_enqueue_)(void(*)(void*), void* w); @@ -264,13 +259,12 @@ void nrniv_bind_call() { pthread_mutex_unlock(mut_); } -} // end of extern "C" #endif // MINGW #endif //HAVE_IV -extern "C" void nrniv_bind_thread() { +void nrniv_bind_thread() { #if HAVE_IV IFGUI bind_tid_ = int(*hoc_getarg(1)); @@ -287,7 +281,7 @@ ENDGUI hoc_ret(); } -extern "C" int stdin_event_ready() { +int stdin_event_ready() { #if HAVE_IV IFGUI static DWORD main_threadid = -1; diff --git a/src/ivoc/macmain.cpp b/src/ivoc/macmain.cpp index 627d722e8d..7bb2a1a2ed 100755 --- a/src/ivoc/macmain.cpp +++ b/src/ivoc/macmain.cpp @@ -1,8 +1,7 @@ -extern "C" { #pragma import on -int ivocmain(int, char**, char**); +int ivocmain(int, const char**, const char**); #pragma import off -} +//} int main() { return ivocmain(0, 0, 0); diff --git a/src/ivoc/matrix.cpp b/src/ivoc/matrix.cpp index 86f590664b..e55381dd91 100644 --- a/src/ivoc/matrix.cpp +++ b/src/ivoc/matrix.cpp @@ -11,12 +11,11 @@ #define EPS hoc_epsilon static Symbol* smat_; -extern "C" int hoc_return_type_code; +extern /*"C"*/ int hoc_return_type_code; -extern "C" { - extern double hoc_scan(FILE*); - extern FILE* hoc_obj_file_arg(int i); - extern Object** hoc_temp_objptr(Object*); +extern double hoc_scan(FILE*); +extern "C" FILE* hoc_obj_file_arg(int i); +extern Object** hoc_temp_objptr(Object*); #if 0 extern void install_matrix_method(const char* name, double (*)(...)); @@ -28,7 +27,6 @@ extern "C" { extern MAT* matrix_full(void*); // hoc_execerror if void* not right type extern SPMAT* matrix_sparse(void*); #endif -} static void check_domain(int i, int j) { if (i > j || i < 0) { @@ -738,9 +736,7 @@ static void steer_x(void* v) { #if WIN32 && !USEMATRIX -extern "C" { void Matrix_reg(); -} #endif void Matrix_reg() { diff --git a/src/ivoc/mlinedit.cpp b/src/ivoc/mlinedit.cpp index 1b601ee7c8..cfe8eb5ab8 100644 --- a/src/ivoc/mlinedit.cpp +++ b/src/ivoc/mlinedit.cpp @@ -1,6 +1,6 @@ #include <../../nrnconf.h> -extern "C" int hoc_return_type_code; +extern /*"C"*/ int hoc_return_type_code; #include @@ -22,11 +22,9 @@ extern "C" int hoc_return_type_code; #include "gui-redirect.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); - extern char** (*nrnpy_gui_helper3_str_)(const char* name, Object* obj, int handle_strptr); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); +extern char** (*nrnpy_gui_helper3_str_)(const char* name, Object* obj, int handle_strptr); #if HAVE_IV class OcText : public Text { @@ -134,7 +132,7 @@ IFGUI return (void*)e; ENDGUI #endif /* HAVE_IV */ - return (void*)0; + return nullptr; } static void destruct(void* v) { diff --git a/src/ivoc/mymath.cpp b/src/ivoc/mymath.cpp index 8fc615b84f..7e144d165d 100644 --- a/src/ivoc/mymath.cpp +++ b/src/ivoc/mymath.cpp @@ -6,7 +6,7 @@ #include #include -extern "C" int hoc_return_type_code; +extern int hoc_return_type_code; static double distance_to_line(void*) { return MyMath::distance_to_line(*getarg(1), *getarg(2), @@ -24,7 +24,7 @@ static double inside(void*) { *getarg(5), *getarg(6)); } -extern "C" { int nrn_feround(int); } +int nrn_feround(int); // return last rounding mode and set to given mode if 1,2,3,4. // order is FE_DOWNWARD, FE_TONEAREST, FE_TOWARDZERO, FE_UPWARD #if defined(HAVE_FENV_H) && defined(HAVE_FESETROUND) diff --git a/src/ivoc/mymath.h b/src/ivoc/mymath.h index 6196e83468..cbf8541f0f 100644 --- a/src/ivoc/mymath.h +++ b/src/ivoc/mymath.h @@ -4,9 +4,7 @@ #include #include -extern "C" { -extern int nrn_isdouble(void*, double, double); -} +extern "C" int nrn_isdouble(double*, double, double); class Extension; diff --git a/src/ivoc/nrngsl_hc_radix2.c b/src/ivoc/nrngsl_hc_radix2.cpp similarity index 99% rename from src/ivoc/nrngsl_hc_radix2.c rename to src/ivoc/nrngsl_hc_radix2.cpp index 692fb546ec..61a79d30b1 100644 --- a/src/ivoc/nrngsl_hc_radix2.c +++ b/src/ivoc/nrngsl_hc_radix2.cpp @@ -1,4 +1,4 @@ -/* fft/hc_radix2.c +/* fft/hc_radix2.cpp * * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough * diff --git a/src/ivoc/nrngsl_real_radix2.c b/src/ivoc/nrngsl_real_radix2.cpp similarity index 98% rename from src/ivoc/nrngsl_real_radix2.c rename to src/ivoc/nrngsl_real_radix2.cpp index 23b609ca24..7618b33fd9 100644 --- a/src/ivoc/nrngsl_real_radix2.c +++ b/src/ivoc/nrngsl_real_radix2.cpp @@ -1,4 +1,4 @@ -/* fft/real_radix2.c +/* fft/real_radix2.cpp * * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough * @@ -19,7 +19,7 @@ /* Hines: for greater self-containment */ #include "nrngsl.h" -/* from gsl/fft/factorize.c */ +/* from gsl/fft/factorize.cpp */ static int fft_binary_logn (const size_t n) { @@ -43,7 +43,7 @@ fft_binary_logn (const size_t n) return binary_logn; } -/* from gsl/fft/bitreverse.c */ +/* from gsl/fft/bitreverse.cpp */ static int FUNCTION(fft_real,bitreverse_order) (BASE data[], const size_t stride, diff --git a/src/ivoc/nrnmain.cpp b/src/ivoc/nrnmain.cpp index e6a81a485a..52a36d5c34 100755 --- a/src/ivoc/nrnmain.cpp +++ b/src/ivoc/nrnmain.cpp @@ -4,22 +4,24 @@ #include "../nrncvode/nrnneosm.h" #include #include +#include "isoc99.h" -extern "C" { - int nrn_isdouble(double*, double, double); - int ivocmain(int, const char**, const char**); + extern "C" int nrn_isdouble(double*, double, double); + extern int ivocmain(int, const char**, const char**); extern int nrn_main_launch; extern int nrn_noauto_dlopen_nrnmech; #if NRNMPI_DYNAMICLOAD extern void nrnmpi_stubs(); extern char* nrnmpi_load(int is_python); #endif +#if NRNMPI +extern "C" void nrnmpi_init(int nrnmpi_under_nrncontrol, int* pargc, char*** pargv); +#endif #if BLUEGENE_CHECKPOINT void BGLCheckpointInit(char* chkptDirPath); // note: get the path from the environment variable BGL_CHKPT_DIR_PATH // otherwise from $HOME/checkpoint, otherwise $HOME #endif -} int main(int argc, char** argv, char** env) { nrn_isdouble(0,0,0); @@ -53,19 +55,17 @@ printf("argv[%d]=|%s|\n", i, argv[i]); nrnmpi_init(1, &argc, &argv); // may change argc and argv #endif #if BLUEGENE_CHECKPOINT - BGLCheckpointInit((char*)0); + BGLCheckpointInit(0); #endif errno = 0; return ivocmain(argc, (const char**)argv, (const char**)env); } #if USENCS -extern "C" { void nrn2ncs_outputevent(int, double){} -} #endif -// moving following to src/oc/ockludge.c since on +// moving following to src/oc/ockludge.cpp since on // Darwin Kernel Version 8.9.1 on apple i686 (and the newest config.guess // thinks it is a i386, but that is a different story) // including mpi.h gives some errors like: diff --git a/src/ivoc/nrnmutdec.h b/src/ivoc/nrnmutdec.h index d5b12140a5..1f1133a13f 100644 --- a/src/ivoc/nrnmutdec.h +++ b/src/ivoc/nrnmutdec.h @@ -18,7 +18,7 @@ #define MUTDESTRUCT {if (mut_){pthread_mutex_destroy(mut_); delete mut_; mut_ = (pthread_mutex_t*)0;}} #else #define MUTCONSTRUCT(mkmut) {if (mkmut) {mut_ = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(mut_, 0);}else{mut_ = 0;}} -#define MUTDESTRUCT {if (mut_){pthread_mutex_destroy(mut_); free((char*)mut_); mut_ = (pthread_mutex_t*)0;}} +#define MUTDESTRUCT {if (mut_){pthread_mutex_destroy(mut_); free(mut_); mut_ = (pthread_mutex_t*)0;}} #endif #define MUTLOCK {if (mut_) {pthread_mutex_lock(mut_);}} #define MUTUNLOCK {if (mut_) {pthread_mutex_unlock(mut_);}} diff --git a/src/ivoc/objcmd.cpp b/src/ivoc/objcmd.cpp index 56100fe41d..74607c5fff 100644 --- a/src/ivoc/objcmd.cpp +++ b/src/ivoc/objcmd.cpp @@ -13,13 +13,11 @@ #include "objcmd.h" #include "oc2iv.h" -extern "C" { extern Object* hoc_thisobject; int (*nrnpy_hoccommand_exec)(Object*); int (*nrnpy_hoccommand_exec_strret)(Object*, char*, int); void (*nrnpy_cmdtool)(Object*, int type, double x, double y, int kd); double (*nrnpy_func_call)(Object*, int, int*); -} HocCommand::HocCommand(const char* cmd) { init(cmd, hoc_thisobject); diff --git a/src/ivoc/oc2iv.cpp b/src/ivoc/oc2iv.cpp index be0bc7f401..6263a8002c 100644 --- a/src/ivoc/oc2iv.cpp +++ b/src/ivoc/oc2iv.cpp @@ -5,13 +5,11 @@ #include "oc2iv.h" #include "ocpointer.h" -extern "C" { #include "parse.h" extern Symlist* hoc_top_level_symlist; extern Objectdata *hoc_top_level_data; extern Object* hoc_thisobject; extern Symlist* hoc_symlist; -} char* Oc2IV::object_str(const char* name, Object* ob) { if (ob && ob->ctemplate->constructor) { @@ -69,7 +67,7 @@ void ParseTopLevel::save() { } } -extern "C" { extern int hoc_in_template; } +extern int hoc_in_template; void ParseTopLevel::restore() { if (restored_ == false) { diff --git a/src/ivoc/ocbox.cpp b/src/ivoc/ocbox.cpp index d1833be5a4..c707a40211 100644 --- a/src/ivoc/ocbox.cpp +++ b/src/ivoc/ocbox.cpp @@ -24,12 +24,10 @@ #include "gui-redirect.h" -extern "C" int hoc_return_type_code; +extern /*"C"*/ int hoc_return_type_code; -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -}; +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); #if HAVE_IV @@ -129,7 +127,7 @@ static void* vcons(Object*) { b->ref(); return (void*)b; #else - return (void*)0; + return nullptr; #endif /* HAVE_IV */ } @@ -143,7 +141,7 @@ static void* hcons(Object*) { b->ref(); return (void*)b; #else - return (void*)0; + return nullptr; #endif /* HAVE_IV */ } @@ -337,7 +335,7 @@ ENDGUI return 0.; } -extern "C" {const char* pwm_session_filename();} +const char* pwm_session_filename(); static double save(void* v) { TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.save", v); diff --git a/src/ivoc/ocdeck.cpp b/src/ivoc/ocdeck.cpp index d1e6c1d382..3898bb22b0 100644 --- a/src/ivoc/ocdeck.cpp +++ b/src/ivoc/ocdeck.cpp @@ -16,10 +16,8 @@ #include "classreg.h" #include "gui-redirect.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); #if HAVE_IV class SpecialPatch : public Patch { @@ -83,7 +81,7 @@ IFGUI ENDGUI return (void*)b; #else - return (void*)0; + return nullptr; #endif /* HAVE_IV */ } diff --git a/src/ivoc/ocfile.cpp b/src/ivoc/ocfile.cpp index a44e6fbc8d..3f2ec71b7d 100644 --- a/src/ivoc/ocfile.cpp +++ b/src/ivoc/ocfile.cpp @@ -9,7 +9,7 @@ #include #endif -extern "C" int hoc_return_type_code; +extern /*"C"*/ int hoc_return_type_code; #ifdef WIN32 #include @@ -39,10 +39,8 @@ extern "C" int hoc_return_type_code; #endif #include "gui-redirect.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); static Symbol* file_class_sym_; @@ -52,12 +50,10 @@ int ivoc_unlink(const char* s) { return unlink(s); } -extern "C" { #include "hocstr.h" - FILE* hoc_obj_file_arg(int i); -} +extern "C" FILE* hoc_obj_file_arg(int i); -FILE* hoc_obj_file_arg(int i) { +extern "C" FILE* hoc_obj_file_arg(int i) { Object* ob = *hoc_objgetarg(i); check_obj_type(ob, "File"); OcFile* f = (OcFile*)(ob->u.this_pointer); @@ -184,7 +180,7 @@ static double f_flush(void* v){ static const char** f_get_name(void* v){ OcFile* f = (OcFile*)v; char** ps = hoc_temp_charptr(); - *ps = (char*)f->get_name(); + *ps = (char*)f->get_name(); if (ifarg(1)) { hoc_assign_str(hoc_pgargstr(1), *ps); } @@ -254,7 +250,7 @@ static double f_vread(void* v){ OcFile* f = (OcFile*)v; size_t n = 1; if (ifarg(2)) n = int(chkarg(1, 1., 2.e18)); - char* x = (char*)hoc_pgetarg(ifarg(2)+1); + double* x = hoc_pgetarg(ifarg(2)+1); BinaryMode(f) return (double)fread(x,sizeof(double),n,f->file()); } diff --git a/src/ivoc/ochelp.cpp b/src/ivoc/ochelp.cpp index cf42563599..9a0283f9ac 100644 --- a/src/ivoc/ochelp.cpp +++ b/src/ivoc/ochelp.cpp @@ -29,17 +29,15 @@ static FILE* help_pipe; //#include "../uxnrnbbs/nrnbbs.h" #endif -extern "C" { -extern void ivoc_help(const char*); +//extern void ivoc_help(const char*); extern const char* hoc_current_xopen(); -}; declareList(CopyStringList, CopyString) implementList(CopyStringList, CopyString) static CopyStringList* filequeue; -void ivoc_help(const char* s) { +extern "C" void ivoc_help(const char* s) { #if 1 // printf("online help not currently working\n"); return; diff --git a/src/ivoc/ocjump.cpp b/src/ivoc/ocjump.cpp index 9dfe5f23ea..1d210597c6 100644 --- a/src/ivoc/ocjump.cpp +++ b/src/ivoc/ocjump.cpp @@ -13,7 +13,6 @@ #include "ivoc.h" #endif -extern "C" { extern Objectdata* hoc_top_level_data; extern Symlist* hoc_top_level_symlist; extern Symlist* hoc_symlist; @@ -21,7 +20,6 @@ extern Object* hoc_thisobject; extern void hoc_execute1(); extern bool hoc_valid_stmt(const char* stmt, Object* ob); extern int hoc_execerror_messages; -} static bool valid_stmt1(const char* stmt, Object* ob) { char* s = new char[strlen(stmt)+2]; @@ -168,9 +166,7 @@ void OcJumpImpl::ljmp() { OcJumpImpl* OcJumpImpl::oji_; -extern "C" { - void hoc_execute(Inst*); -} +void hoc_execute(Inst*); bool OcJumpImpl::execute(Inst* p) { begin(); @@ -221,27 +217,24 @@ void* OcJumpImpl::fpycall(void*(*f)(void*, void*), void* a, void* b) { return c; } -extern "C" { + extern void (*oc_jump_target_)(void); extern int hoc_intset; // extern int hoc_pipeflag; - - void oc_save_hoc_oop(Object**, Objectdata**, int**, int*, Symlist**); - void oc_restore_hoc_oop(Object**, Objectdata**, int**, int*, Symlist**); - - void oc_save_code(Inst**, Inst**, Datum**, OcFrame**, int*, int*, - Inst**, OcFrame**, Datum**, Symlist**, Inst**, int*); - void oc_restore_code(Inst**, Inst**, Datum**, OcFrame**, int*, int*, - Inst**, OcFrame**, Datum**, Symlist**, Inst**, int*); - +extern "C" { + void oc_save_hoc_oop(Object**, Objectdata**, int**, int*, Symlist**); + void oc_restore_hoc_oop(Object**, Objectdata**, int**, int*, Symlist**); + void oc_save_code(Inst **, Inst **, Datum **, OcFrame **, int *, int *, + Inst **, OcFrame **, Datum **, Symlist **, Inst **, int *); + void oc_restore_code(Inst **, Inst **, Datum **, OcFrame **, int *, int *, + Inst **, OcFrame **, Datum **, Symlist **, Inst **, int *); void oc_save_input_info(char**, int*, int*, NrnFILEWrap**); void oc_restore_input_info(char*, int, int, NrnFILEWrap*); - #if CABLE void oc_save_cabcode(int*, int*); void oc_restore_cabcode(int*, int*); #endif -} +} // extern "C" void OcJumpImpl::begin(){ // not complete but it is good for expressions and it can be improved diff --git a/src/ivoc/oclist.cpp b/src/ivoc/oclist.cpp index d5fb013115..2962718bf9 100644 --- a/src/ivoc/oclist.cpp +++ b/src/ivoc/oclist.cpp @@ -25,21 +25,18 @@ #include "gui-redirect.h" -extern "C" { #include "parse.h" extern Object** hoc_temp_objptr(Object*); extern Symlist* hoc_top_level_symlist; int ivoc_list_count(Object*); -Object* ivoc_list_item(Object*, int); -} +extern "C" Object* ivoc_list_item(Object*, int); -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -}; +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); + +extern /*"C"*/ int hoc_return_type_code; -extern "C" int hoc_return_type_code; void handle_old_focus(); #if HAVE_IV @@ -419,7 +416,7 @@ int ivoc_list_count(Object* olist) { OcList* list = (OcList*)olist->u.this_pointer; return list->count(); } -Object* ivoc_list_item(Object* olist, int i) { +extern "C" Object* ivoc_list_item(Object* olist, int i) { chk_list(olist); OcList* list = (OcList*)olist->u.this_pointer; if (i >= 0 && i < list->count()) { @@ -509,7 +506,6 @@ void OcList_reg() { list_class_sym_ = hoc_lookup("List"); } -extern "C" { extern bool hoc_objectpath_impl(Object* ob, Object* oblook, char* path, int depth); extern void hoc_path_prepend(char*, const char*, const char*); int ivoc_list_look(Object* ob, Object* oblook, char* path, int) { @@ -534,7 +530,6 @@ int ivoc_list_look(Object* ob, Object* oblook, char* path, int) { } return 0; } -} void OcList::create_browser(const char* name, const char* items, Object* pystract) { #if HAVE_IV @@ -547,7 +542,7 @@ void OcList::create_browser(const char* name, const char* items, Object* pystrac PrintableWindow* w = new StandardWindow(b_->standard_glyph()); b_->ocglyph(w); if (name) { - w->name((char*)name); + w->name(name); } w->map(); #endif @@ -564,7 +559,7 @@ void OcList::create_browser(const char* name, char** pstr, const char* action) { PrintableWindow* w = new StandardWindow(b_->standard_glyph()); b_->ocglyph(w); if (name) { - w->name((char*)name); + w->name(name); } w->map(); #endif diff --git a/src/ivoc/ocmatrix.cpp b/src/ivoc/ocmatrix.cpp index bddb1f1a71..76311f793c 100644 --- a/src/ivoc/ocmatrix.cpp +++ b/src/ivoc/ocmatrix.cpp @@ -16,8 +16,10 @@ extern "C" { #include "matrix2.h" #include "sparse.h" #include "sparse2.h" +extern MAT *m_get(int,int); +} // extern "C" + int nrn_matrix_dim(void*, int ); -} #include "ocmatrix.h" using std::vector; diff --git a/src/ivoc/ocmatrix.h b/src/ivoc/ocmatrix.h index a4b54795dc..c2f8723e07 100644 --- a/src/ivoc/ocmatrix.h +++ b/src/ivoc/ocmatrix.h @@ -73,9 +73,7 @@ class OcMatrix { int type_; }; -extern "C" { - extern Matrix* matrix_arg(int); -} +extern Matrix* matrix_arg(int); class OcFullMatrix : public OcMatrix { // type 1 public: diff --git a/src/ivoc/ocnoiv1.cpp b/src/ivoc/ocnoiv1.cpp index da7376b119..05849bb434 100755 --- a/src/ivoc/ocnoiv1.cpp +++ b/src/ivoc/ocnoiv1.cpp @@ -4,7 +4,6 @@ // things we DO NOT want -extern "C" { #include "hocdec.h" extern void hoc_ret(); @@ -174,5 +173,4 @@ void ivoc_style() { hoc_ret(); hoc_pushx(0.); } -} #endif diff --git a/src/ivoc/ocobserv.cpp b/src/ivoc/ocobserv.cpp index dff80e98ec..de4dbfa36b 100644 --- a/src/ivoc/ocobserv.cpp +++ b/src/ivoc/ocobserv.cpp @@ -4,7 +4,7 @@ extern "C" { extern void hoc_obj_disconnect(Object*); -} +} // extern "C" void hoc_obj_disconnect(Object* ob) { delete ((ObjObservable*)ob->observers); diff --git a/src/ivoc/ocobserv.h b/src/ivoc/ocobserv.h index cd04d9211a..2a6a02b4e6 100755 --- a/src/ivoc/ocobserv.h +++ b/src/ivoc/ocobserv.h @@ -31,7 +31,7 @@ class ObjObservable : public Observable { extern "C" { void hoc_template_notify(Object*, int message); -} +} // extern "C" class ClassObservable : public Observable { public: diff --git a/src/ivoc/ocpicker.cpp b/src/ivoc/ocpicker.cpp index 3fd9aba231..8536c78755 100644 --- a/src/ivoc/ocpicker.cpp +++ b/src/ivoc/ocpicker.cpp @@ -82,7 +82,7 @@ bool StandardPicker::pick(Canvas* c, Glyph* glyph, int depth, Hit& h) { return false; } -/* from /interviews/input.c */ +/* from /interviews/input.cpp */ void StandardPicker::event(const Event& e) { switch (e.type()) { case Event::down: diff --git a/src/ivoc/ocpointer.cpp b/src/ivoc/ocpointer.cpp index 03b1596c25..43eae37642 100644 --- a/src/ivoc/ocpointer.cpp +++ b/src/ivoc/ocpointer.cpp @@ -26,7 +26,7 @@ extern "C" { extern void hoc_free_list(Symlist**); extern Symbol* hoc_parse_stmt(const char*, Symlist**); extern void hoc_run_stmt(Symbol*); -} +} // extern "C" OcPointer::OcPointer(const char* st, double* d) : Observer() { sti_ = NULL; diff --git a/src/ivoc/ocptrvector.cpp b/src/ivoc/ocptrvector.cpp index 0416d87689..517221f74d 100644 --- a/src/ivoc/ocptrvector.cpp +++ b/src/ivoc/ocptrvector.cpp @@ -19,12 +19,11 @@ #include "graph.h" #endif #include "gui-redirect.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); + +extern /*"C"*/ int hoc_return_type_code; -extern "C" int hoc_return_type_code; static double dummy; static Symbol* pv_class_sym_; diff --git a/src/ivoc/octimer.cpp b/src/ivoc/octimer.cpp index 887d7e7add..31cfbe1ecc 100644 --- a/src/ivoc/octimer.cpp +++ b/src/ivoc/octimer.cpp @@ -97,7 +97,7 @@ static void* t_cons(Object*) { return new OcTimer(gargstr(1)); } #else - return (void*)0; + return nullptr; #endif /* HAVE_IV */ } static void t_destruct(void* v) { diff --git a/src/ivoc/pwman.cpp b/src/ivoc/pwman.cpp index e070c50f24..3b1d1e0872 100644 --- a/src/ivoc/pwman.cpp +++ b/src/ivoc/pwman.cpp @@ -2,7 +2,7 @@ #include "gui-redirect.h" extern char* ivoc_get_temp_file(); -extern "C" int hoc_return_type_code; +extern /*"C"*/ int hoc_return_type_code; #if HAVE_IV #if (MAC && !defined(carbon)) || defined(WIN32) @@ -31,16 +31,14 @@ extern "C" int hoc_return_type_code; #if HAVE_IV #include "utility.h" -extern "C" { - void single_event_run(); - extern char **hoc_strpop(); -} +void single_event_run(); +extern char **hoc_strpop(); #if defined(CYGWIN) #include void iv_display_scale(float); void iv_display_scale(Coord, Coord); // Make if fit into the screen -extern "C" {char* hoc_back2forward(char*);} +char* hoc_back2forward(char*); #endif #if defined(WIN32) && !defined(CYGWIN) @@ -50,10 +48,9 @@ void iv_display_scale(float); void iv_display_scale(Coord, Coord); // Make if fit into the screen #if defined(__MWERKS__) #include -extern "C"{ - extern char * mktemp(char *); - extern int unlink(const char *); -} +extern char * mktemp(char *); +extern int unlink(const char *); + #else //!__MWERKS__ #include #endif // __MWERKS__ @@ -63,19 +60,17 @@ extern "C"{ // but any existing trailing info remains! So be sure to unlink first. #undef IOS_OUT #define IOS_OUT (ios::out) -extern "C" {char* hoc_back2forward(char*);} +char* hoc_back2forward(char*); #else //!WIN32 #if MAC && !defined(carbon) #include #include #undef IOS_OUT #define IOS_OUT (ios::out | ios::trunc) -extern "C"{ - extern char * mktemp(char *); - extern int unlink(const char *); -} +extern char * mktemp(char *); +extern int unlink(const char *); #include -extern "C" {extern void debugfile(const char*, ...);} +extern void debugfile(const char*, ...); #else //!MAC #include #define Output output @@ -188,12 +183,10 @@ printf(" canvas %g %g %g %g\n", e.left(), e.bottom(), e.right(), e.top()); Coord x_, y_; }; -extern "C" { - extern double (*p_java2nrn_dmeth)(Object* ho, Symbol* method); - extern char** (*p_java2nrn_smeth)(Object* ho, Symbol* method); - const char* (*p_java2nrn_classname)(Object* ho); - bool (*p_java2nrn_identity)(Object* o1, Object* o2); -} +extern double (*p_java2nrn_dmeth)(Object* ho, Symbol* method); +extern char** (*p_java2nrn_smeth)(Object* ho, Symbol* method); +const char* (*p_java2nrn_classname)(Object* ho); +bool (*p_java2nrn_identity)(Object* o1, Object* o2); //just enough info to get a java window represented in the PWM. // The distinction is that window() is NULL for these. @@ -458,15 +451,13 @@ void PWMDismiss::execute() { #else //!HAVE_IV #if defined(CYGWIN) -extern "C" {char* hoc_back2forward(char*);} +char* hoc_back2forward(char*); #endif #endif //HAVE_IV -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); - extern char** (*nrnpy_gui_helper3_str_)(const char* name, Object* obj, int handle_strptr); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); +extern char** (*nrnpy_gui_helper3_str_)(const char* name, Object* obj, int handle_strptr); static void* pwman_cons(Object*) { TRY_GUI_REDIRECT_OBJ("PWManager", NULL); @@ -1439,7 +1430,6 @@ PrintableWindowManager::~PrintableWindowManager() { } } -extern "C" { void hoc_pwman_place() { TRY_GUI_REDIRECT_DOUBLE("pwman_place", NULL); #if HAVE_IV @@ -1493,7 +1483,6 @@ ENDGUI hoc_ret(); hoc_pushx(0.); } -} void PrintableWindowManager::xplace(int left, int top, bool m) { PrintableWindow* w = pwm_impl->window(); @@ -1966,7 +1955,7 @@ float yoff = pageheight*72/2/sfac - (e.top() + e.bottom() + 23.)/2.; } #ifdef WIN32 -extern "C" { extern bool hoc_copyfile(const char*, const char*);} +extern bool hoc_copyfile(const char*, const char*); #endif #if MACPRINT @@ -2694,7 +2683,7 @@ void PWMImpl::virt_screen() { VirtualWindow::makeVirtualWindow(); } -//grabbed from unidraw dialogs.c +//grabbed from unidraw dialogs.cpp static const char* DefaultPrintCmd () { #ifdef WIN32 Style* style = Session::instance()->style(); diff --git a/src/ivoc/strfun.cpp b/src/ivoc/strfun.cpp index 24c3adf86a..fa158e7815 100644 --- a/src/ivoc/strfun.cpp +++ b/src/ivoc/strfun.cpp @@ -15,13 +15,11 @@ #if HAVE_IV #include #endif -extern "C" { extern Objectdata* hoc_top_level_data; extern Symlist* hoc_built_in_symlist; extern int nrn_is_artificial(int); -} -extern "C" int hoc_return_type_code; +extern /*"C"*/ int hoc_return_type_code; inline unsigned long key_to_hash(String& s) {return s.hash();} implementTable(SymbolTable, String, Symbol*) @@ -98,7 +96,6 @@ static double l_is_name(void*) { } -extern "C" { extern void hoc_free_symspace(Symbol*); extern Object* hoc_newobj1(Symbol*, int); extern Symlist* hoc_top_level_symlist; @@ -116,7 +113,6 @@ extern void ivoc_free_alias(Object* ob) { if (a) delete a; } -} static double l_alias(void*) { char* name; @@ -364,7 +360,7 @@ Symbol* IvocAliases::lookup(const char* name){ Symbol* IvocAliases::install(const char* name){ Symbol* sp; sp = (Symbol*)emalloc(sizeof(Symbol)); - sp->name = (char*)emalloc(strlen(name)+1); + sp->name = static_cast(emalloc(strlen(name)+1)); strcpy(sp->name, name); sp->type = VARALIAS; sp->cpublic = 0; // cannot be 2 or cannot be freed diff --git a/src/ivoc/symchoos.cpp b/src/ivoc/symchoos.cpp index b408d71782..cac6d9d75d 100644 --- a/src/ivoc/symchoos.cpp +++ b/src/ivoc/symchoos.cpp @@ -23,7 +23,7 @@ * OF THIS SOFTWARE. */ -/* hacked by Michael Hines from filechooser.c */ +/* hacked by Michael Hines from filechooser.cpp */ /* * SymChooser -- select a name @@ -60,10 +60,8 @@ #include "classreg.h" #include "gui-redirect.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); #if HAVE_IV @@ -169,7 +167,7 @@ IFGUI ENDGUI return (void*)sc; #else - return (void*)0; + return nullptr; #endif /* HAVE_IV */ } static void sdestruct(void* v) { diff --git a/src/ivoc/symdir.cpp b/src/ivoc/symdir.cpp index 4f9a31c1cf..ec396acffc 100644 --- a/src/ivoc/symdir.cpp +++ b/src/ivoc/symdir.cpp @@ -12,7 +12,6 @@ #include "oc2iv.h" #endif -extern "C" { #if CABLE #include "membfunc.h" extern double* point_process_pointer(Point_process*, Symbol*, int); @@ -23,7 +22,6 @@ extern Symlist* hoc_symlist; extern Objectdata* hoc_top_level_data; extern Symlist* hoc_built_in_symlist, *hoc_top_level_symlist; extern int hoc_array_index(Symbol*, Objectdata*); -} #include "string.h" #include "symdir.h" diff --git a/src/ivoc/utility.cpp b/src/ivoc/utility.cpp index 0cbdf6db55..b65dcf0165 100644 --- a/src/ivoc/utility.cpp +++ b/src/ivoc/utility.cpp @@ -27,11 +27,9 @@ #include "oc2iv.h" #include "ivoc.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); - extern Object** (*nrnpy_gui_helper3_)(const char* name, Object* obj, int handle_strptr); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); +extern Object** (*nrnpy_gui_helper3_)(const char* name, Object* obj, int handle_strptr); bool oc_post_dialog(Dialog* d, Coord x, Coord y) { if (x != 400. || y != 400.) { @@ -286,7 +284,6 @@ FieldDialog* FieldDialog::field_dialog_instance(const char* str, Style* style, void FieldDialog::accept(FieldEditor*) { dismiss(true); } void FieldDialog::cancel(FieldEditor*) { dismiss(false); } -extern "C" { void hoc_boolean_dialog() { bool b = false; @@ -331,8 +328,6 @@ ENDGUI hoc_pushx(double(b)); } -} - /*static*/ class LabelChooserAction : public Action { public: diff --git a/src/ivoc/xdep.cpp b/src/ivoc/xdep.cpp index eb705494f3..503018f247 100644 --- a/src/ivoc/xdep.cpp +++ b/src/ivoc/xdep.cpp @@ -204,7 +204,6 @@ void get_position(XDisplay* dpy, XWindow window, int* rx, int* ry) //if (xoff != -999) { // *rx -= xoff; // *ry -= yoff; -//} } #endif diff --git a/src/ivoc/xmenu.cpp b/src/ivoc/xmenu.cpp index bf4533ed7c..0a9ccec5e7 100644 --- a/src/ivoc/xmenu.cpp +++ b/src/ivoc/xmenu.cpp @@ -4,20 +4,16 @@ #include #include "oc2iv.h" #include "classreg.h" -extern "C" { double (*nrnpy_guigetval)(Object*); void (*nrnpy_guisetval)(Object*, double); int (*nrnpy_guigetstr)(Object*, char**); -} #include "gui-redirect.h" -extern "C" { - Object** (*nrnpy_gui_helper_)(const char* name, Object* obj) = NULL; - double (*nrnpy_object_to_double_)(Object*) = NULL; - Object** (*nrnpy_gui_helper3_)(const char* name, Object* obj, int handle_strptr) = NULL; - char** (*nrnpy_gui_helper3_str_)(const char* name, Object* obj, int handle_strptr) = NULL; -}; +Object** (*nrnpy_gui_helper_)(const char* name, Object* obj) = NULL; +double (*nrnpy_object_to_double_)(Object*) = NULL; +Object** (*nrnpy_gui_helper3_)(const char* name, Object* obj, int handle_strptr) = NULL; +char** (*nrnpy_gui_helper3_str_)(const char* name, Object* obj, int handle_strptr) = NULL; #if HAVE_IV // to end of file except for a few small fragments. @@ -165,12 +161,11 @@ static String* xvalue_format; #define Editor_Default "DefaultValueEditor" #define Editor_Stepper "DefaultValueEditor" -extern "C" { extern int units_on_flag_; -extern Symbol* hoc_get_symbol(const char*); +extern "C" Symbol* hoc_get_symbol(const char*); extern Symbol* hoc_get_last_pointer_symbol(); -extern double* nrn_recalc_ptr(double*); +extern "C" double* nrn_recalc_ptr(double*); void hoc_notify_value() { Oc oc; oc.notify(); @@ -532,7 +527,6 @@ void hoc_xslider() { hoc_pushx(0.); } -} /* end extern "C" */ class HocButton : public Button { public: @@ -1466,9 +1460,7 @@ void HocLabel::write(ostream& o) { } #if 0 -extern "C" { extern void purify_watch_rw_4(char**); -} #endif //HocVarLabel diff --git a/src/ivoc/xmenu.h b/src/ivoc/xmenu.h index 83e9738ae6..c533181a6b 100644 --- a/src/ivoc/xmenu.h +++ b/src/ivoc/xmenu.h @@ -314,7 +314,7 @@ class HocDefaultValEditor : public HocValEditor { void def_change(float, float); Button* checkbox() { return checkbox_; } private: - Button* checkbox_; // not your normal checkbox. see xmenu.c + Button* checkbox_; // not your normal checkbox. see xmenu.cpp double deflt_; double most_recent_; HocValStepper* vs_; diff --git a/src/ivos/file.cpp b/src/ivos/file.cpp index be32b364b7..1d6e697684 100755 --- a/src/ivos/file.cpp +++ b/src/ivos/file.cpp @@ -70,7 +70,7 @@ #ifdef HAVE_SYS_MMAN_H extern "C" { #include -} +} // extern "C" #endif #ifdef WIN16 @@ -86,7 +86,7 @@ extern "C" { // These are the POSIX definitions. Hopefully they won't conflict. extern int _close(int); extern int _read(int, void*, unsigned int); -} +} // extern "C" #endif #if !defined(__GNUC__) || !defined (WIN32) && !defined (MAC) @@ -100,7 +100,7 @@ extern "C" { // These are the POSIX definitions. Hopefully they won't conflict. extern int close(int); extern int read(int, void*, unsigned int); -} +} // extern "C" #endif //#if defined(SGI) //#endif @@ -221,10 +221,10 @@ InputFile* InputFile::open(const String& name) { #ifndef MAC #if defined(WIN32) && !defined(__MWERKS__) && !defined(CYGWIN) - int fd = _open((char*)s->string(), O_RDONLY); + int fd = _open(s->string(), O_RDONLY); #else /* cast to workaround DEC C++ prototype bug */ - int fd = ::open((char*)s->string(), O_RDONLY); + int fd = ::open(s->string(), O_RDONLY); #endif if (fd < 0) { delete s; @@ -253,7 +253,7 @@ int InputFile::read(const char*& start) { len = (int)(i->limit_); } #if HAVE_SYS_MMAN_H // #if defined(SGI) || defined(__alpha) - i->map_ = (char*)mmap(0, len, PROT_READ, MAP_PRIVATE, i->fd_, i->pos_); + i->map_ = mmap(0, len, PROT_READ, MAP_PRIVATE, i->fd_, i->pos_); if ((long)(i->map_) == -1) { return -1; } @@ -297,9 +297,9 @@ int StdInput::read(const char*& start) { } #ifdef WIN32 - int nbytes = _read(i->fd_, (char*)i->buf_, i->limit_); + int nbytes = _read(i->fd_, i->buf_, i->limit_); #else - int nbytes = ::read(i->fd_, (char*)i->buf_, i->limit_); + int nbytes = ::read(i->fd_, i->buf_, i->limit_); #endif /* WIN32 */ if (nbytes > 0) { diff --git a/src/ivos/math.cpp b/src/ivos/math.cpp index acaae8c543..15a4ee669f 100755 --- a/src/ivos/math.cpp +++ b/src/ivos/math.cpp @@ -36,7 +36,7 @@ extern "C" { extern int abs(int); extern double fabs(double); -} +} // extern "C" #define myfabs ::fabs #endif diff --git a/src/ivos/regexp.cpp b/src/ivos/regexp.cpp index 65312afcba..b4cd860a0c 100644 --- a/src/ivos/regexp.cpp +++ b/src/ivos/regexp.cpp @@ -102,7 +102,7 @@ Regexp::~Regexp () { delete [] pattern_; } if (c_pattern) { - delete [] (char*)c_pattern; + delete [] c_pattern; } } @@ -430,7 +430,7 @@ regcomp(const char* exp) { regcode = r->program; regc(REGEXP_MAGIC); if (reg(0, &flags) == nil) { - delete [] (char*)r; + delete [] r; return(nil); } diff --git a/src/memacs/estruct.h b/src/memacs/estruct.h index 3acf2cb5b1..bbb537e835 100755 --- a/src/memacs/estruct.h +++ b/src/memacs/estruct.h @@ -287,7 +287,7 @@ typedef struct { int (*t_getchar)(); /* Get character from keyboard. */ int (*t_putchar)(); /* Put character to display. */ int (*t_flush)(); /* Flush output buffers. */ - int (*t_move)(); /* Move the cursor, origin 0. */ + int (*t_move)(int, int); /* Move the cursor, origin 0. */ int (*t_eeol)(); /* Erase to end of line. */ int (*t_eeop)(); /* Erase to end of page. */ int (*t_beep)(); /* Beep. */ diff --git a/src/mesch/matrix.h b/src/mesch/matrix.h index 98256af713..34965ec04c 100755 --- a/src/mesch/matrix.h +++ b/src/mesch/matrix.h @@ -39,6 +39,10 @@ Date Author Modification #define MATRIXH +#if defined(__cplusplus) +extern "C" { +#endif + #include "machine.h" #include "err.h" #include "meminfo.h" @@ -435,22 +439,22 @@ extern VEC *sv_mlt(double,VEC *,VEC *), /* out <- s.x */ *pxinv_vec(PERM *,VEC *,VEC *), /* out <- P^{-1}.x */ *v_mltadd(VEC *,VEC *,double,VEC *), /* out <- x + s.y */ #ifdef PROTOTYPES_IN_STRUCT - *v_map(double (*f)(double),VEC *,VEC *), + *v_map(double (*f)(double),VEC *,VEC *), /* out[i] <- f(x[i]) */ *_v_map(double (*f)(void *,double),void *,VEC *,VEC *), #else *v_map(double (*f)(),VEC *,VEC *), /* out[i] <- f(x[i]) */ *_v_map(double (*f)(),void *,VEC *,VEC *), #endif - *v_lincomb(int,VEC **,Real *,VEC *), + *v_lincomb(int,VEC **,Real *,VEC *), /* out <- sum_i s[i].x[i] */ *v_linlist(VEC *out,VEC *v1,double a1,...); /* out <- s1.x1 + s2.x2 + ... */ /* returns min_j x[j] (== x[i]) */ -extern double v_min(VEC *, int *), - /* returns max_j x[j] (== x[i]) */ - v_max(VEC *, int *), +extern double v_min(VEC *, int *), + /* returns max_j x[j] (== x[i]) */ + v_max(VEC *, int *), /* returns sum_i x[i] */ v_sum(VEC *); @@ -458,11 +462,11 @@ extern double v_min(VEC *, int *), extern VEC *v_star(VEC *, VEC *, VEC *), /* out[i] <- x[i] / y[i] */ *v_slash(VEC *, VEC *, VEC *), - /* sorts x, and sets order so that sorted x[i] = x[order[i]] */ + /* sorts x, and sets order so that sorted x[i] = x[order[i]] */ *v_sort(VEC *, PERM *); /* returns inner product starting at component i0 */ -extern double _in_prod(VEC *x,VEC *y,u_int i0), +extern double _in_prod(VEC *x,VEC *y,u_int i0), /* returns sum_{i=0}^{len-1} x[i].y[i] */ __ip__(Real *,Real *,int); @@ -489,7 +493,7 @@ extern double _v_norm1(), _v_norm2(), _v_norm_inf(), #else /* returns sum_i |x[i]/scale[i]| */ -extern double _v_norm1(VEC *x,VEC *scale), +extern double _v_norm1(VEC *x,VEC *scale), /* returns (scaled) Euclidean norm */ _v_norm2(VEC *x,VEC *scale), /* returns max_i |x[i]/scale[i]| */ @@ -529,8 +533,8 @@ extern MAT *sm_mlt(double s,MAT *A,MAT *out), /* out <- s.A */ *m_sub(MAT *A,MAT *B,MAT *out), /* out <- A - B */ *sub_mat(MAT *A,u_int,u_int,u_int,u_int,MAT *out), *m_transp(MAT *A,MAT *out), /* out <- A^T */ - /* out <- A + s.B */ - *ms_mltadd(MAT *A,MAT *B,double s,MAT *out); + /* out <- A + s.B */ + *ms_mltadd(MAT *A,MAT *B,double s,MAT *out); extern BAND *bd_transp(BAND *in, BAND *out); /* out <- A^T */ @@ -555,7 +559,7 @@ extern VEC *get_row(MAT *,u_int,VEC *), /* MACROS */ /* row i of A <- vec */ -#define set_row(mat,row,vec) _set_row(mat,row,vec,0) +#define set_row(mat,row,vec) _set_row(mat,row,vec,0) /* col j of A <- vec */ #define set_col(mat,col,vec) _set_col(mat,col,vec,0) @@ -678,6 +682,9 @@ int m_free_vars(); #endif +#if defined(__cplusplus) +} +#endif #endif diff --git a/src/mesch/matrix2.h b/src/mesch/matrix2.h index f8114c6bc0..ba12fa9fb0 100755 --- a/src/mesch/matrix2.h +++ b/src/mesch/matrix2.h @@ -32,6 +32,10 @@ #ifndef MATRIX2H #define MATRIX2H +#if defined(__cplusplus) +extern "C" { +#endif + #include "matrix.h" /* Unless otherwise specified, factorisation routines overwrite the @@ -92,14 +96,14 @@ extern MAT *BKPfactor(MAT *A,PERM *pivot,PERM *blocks), /* Cholesky factorisation of A (symmetric, positive definite) */ *CHfactor(MAT *A), - /* LU factorisation of A (with partial pivoting) */ + /* LU factorisation of A (with partial pivoting) */ *LUfactor(MAT *A,PERM *pivot), /* QR factorisation of A; need dim(diag) >= # rows of A */ *QRfactor(MAT *A,VEC *diag), /* QR factorisation of A with column pivoting */ *QRCPfactor(MAT *A,VEC *diag,PERM *pivot), /* L.D.L^T factorisation of A */ - *LDLfactor(MAT *A), + *LDLfactor(MAT *A), /* Hessenberg factorisation of A -- for schur() */ *Hfactor(MAT *A,VEC *diag1,VEC *diag2), /* modified Cholesky factorisation of A; @@ -225,5 +229,8 @@ void ifft(VEC *,VEC *); #endif +#if defined(__cplusplus) +} +#endif #endif diff --git a/src/modlunit/consist.c b/src/modlunit/consist.cpp similarity index 97% rename from src/modlunit/consist.c rename to src/modlunit/consist.cpp index 8c5d9ced52..01a068b9f1 100755 --- a/src/modlunit/consist.c +++ b/src/modlunit/consist.cpp @@ -49,7 +49,7 @@ void consistency() con("STEPPED", STEP1, 0); tu = s->usage; if ((tu & DEP) && (tu & FUNCT)) - diag(s->name, " used as both variable and function"); + diag(s->name, "used as both variable and function"); if ((t == 0) && tu) Fprintf(stderr, "Warning: %s undefined. (declared within VERBATIM?)\n", s->name); diff --git a/src/modlunit/declare.c b/src/modlunit/declare.cpp similarity index 83% rename from src/modlunit/declare.c rename to src/modlunit/declare.cpp index 979a57b46e..764263214a 100755 --- a/src/modlunit/declare.c +++ b/src/modlunit/declare.cpp @@ -14,12 +14,10 @@ char *indepunits = ""; /* subtype of variables using explicit declarations */ -static int promote(); -static int nprime(); +static int promote(Symbol*, long); +static int nprime(char*); -void declare(subtype, q, qa) - long subtype; - Item *q, *qa; +void declare(long subtype, Item* q, Item* qa) { Symbol *sym; @@ -53,24 +51,21 @@ void declare(subtype, q, qa) /*fprintf(stderr, "declared %s with subtype %ld\n", sym->name, sym->subtype);*/ } -static int promote(sym, sub) - Symbol *sym; - long sub; +static int promote(Symbol* sym, long sub) { /*ARGSUSED*/ diag("promotion not programmed yet", (char *)0); return 0; } -void declare_indep(sym) - Symbol *sym; +void declare_indep(Symbol* sym) { Item **qa; qa = ITMA(sym->info); if (!qa[7]) { /* no explicit SWEEP */ if (indepsym) { -diag("Only one independent variable can be defined", (char *) 0); +diag("Only one independent variable can be defined", (char *) 0); } indepsym = sym; if (ITMA(sym->info)[1]) { @@ -87,8 +82,7 @@ diag("Only one SWEEP declaration is allowed", (char *)0); } } -void define_value(q1, q2) - Item *q1, *q2; +void define_value(Item* q1, Item* q2) { Symbol *s; s = SYM(q1); @@ -107,8 +101,7 @@ void define_value(q1, q2) } /* fix up array info */ -void declare_array(s) - Symbol *s; +void declare_array(Symbol* s) { Item *q; @@ -121,9 +114,7 @@ void declare_array(s) } } -void decdim(s, q) - Symbol *s; - Item *q; +void decdim(Symbol* s, Item* q) { s->subtype |= ARRAY; if (q->itemtype == SYMBOL && SYM(q)->type == DEFINEDVAR) { @@ -135,13 +126,12 @@ void decdim(s, q) assert(0); } if (s->araydim < 1) { - diag(s->name, " Array index must be > 0"); + diag(s->name, "Array index must be > 0"); } } Item * -listtype(q) - Item *q; +listtype(Item* q) { static int i=0; @@ -167,7 +157,7 @@ listtype(q) void declare_implied() { - Symbol *sbase, *basestate(); + Symbol *sbase, *basestate(Symbol*); #if NRNUNIT if (!indepsym) { @@ -175,12 +165,12 @@ void declare_implied() Item* name, *units, *from, *to, *with, *num; save = intoken; intoken = newlist(); - name = putintoken("t", NAME, 0); - units = putintoken("ms", STRING, UNITS); - from = putintoken("0", INTEGER, INTEGER); - to = putintoken("1", INTEGER, INTEGER); - with = putintoken("WITH", NAME, 0); - num = putintoken("1", INTEGER, INTEGER); + name = putintoken( "t", NAME, 0); + units = putintoken( "ms", STRING, UNITS); + from = putintoken( "0", INTEGER, INTEGER); + to = putintoken( "1", INTEGER, INTEGER); + with = putintoken( "WITH", NAME, 0); + num = putintoken( "1", INTEGER, INTEGER); qa = itemarray(8, name, units, from, to, with, num, ITEM0, ITEM0); declare(INDEP, ITMA(qa)[0], qa); intoken = save; @@ -195,7 +185,7 @@ void declare_implied() sbase = basestate(s); if (s->type == PRIME) { if (!sbase) { -diag(s->name, " is used but its corresponding STATE is not declared"); +diag(s->name, "is used but its corresponding STATE is not declared"); } s->subtype = DEP; if (nprime(s->name) == 1) { @@ -215,8 +205,7 @@ Sprintf(buf, "%s/%s%d", decode_units(sbase), indepunits, nprime(s->name)); } Symbol * -basestate(s) /* base state symbol for state''' or state0 */ - Symbol *s; +basestate(Symbol* s) /* base state symbol for state''' or state0 */ { Symbol *base = SYM0; @@ -239,8 +228,7 @@ basestate(s) /* base state symbol for state''' or state0 */ #define index strchr #endif -static int nprime(s) - char *s; +static int nprime(char* s) { char *cp; @@ -248,8 +236,7 @@ static int nprime(s) return strlen(s) - (cp - s); } -void install_cfactor(qname, q1, q2) /* declare conversion factor */ - Item *qname, *q1, *q2; +void install_cfactor(Item* qname, Item* q1, Item* q2) /* declare conversion factor */ { declare(CNVFAC, qname, ITEM0); Unit_push(STR(q2)); diff --git a/src/modlunit/init.c b/src/modlunit/init.cpp similarity index 78% rename from src/modlunit/init.c rename to src/modlunit/init.cpp index 4892deb8fc..c270d4f594 100755 --- a/src/modlunit/init.c +++ b/src/modlunit/init.cpp @@ -38,11 +38,11 @@ static struct { /* Keywords */ "NONLINEAR", NONLINEAR, "DISCRETE", DISCRETE, "FUNCTION", FUNCTION1, - "FUNCTION_TABLE", FUNCTION_TABLE, + "FUNCTION_TABLE", FUNCTION_TABLE, "PROCEDURE", PROCEDURE, "PARTIAL", PARTIAL, "INT", INT, - "DEL2", DEL2, + "DEL2", DEL2, "DEL", DEL, "LOCAL", LOCAL, "METHOD", USING, @@ -61,55 +61,54 @@ static struct { /* Keywords */ "WHILE", WHILE, "START", START1, "DEFINE", DEFINE1, - "KINETIC", KINETIC, "CONSERVE", CONSERVE, - "PLOT", PLOT, - "VS", VS, - "LAG", LAG, - "RESET", RESET, - "MATCH", MATCH, - "MODEL_LEVEL", MODEL_LEVEL, /* inserted by merge */ - "SWEEP", SWEEP, - "FIRST", FIRST, - "LAST", LAST, - "COMPARTMENT", COMPARTMENT, - "LONGITUDINAL_DIFFUSION", LONGDIFUS, - "PUTQ", PUTQ, - "GETQ", GETQ, - "IFERROR", IFERROR, - "SOLVEFOR", SOLVEFOR, - "UNITS", UNITBLK, - "UNITSON", UNITSON, - "UNITSOFF", UNITSOFF, - "TABLE", TABLE, - "DEPEND", DEPEND, - "NEURON", NEURON, - "SUFFIX", SUFFIX, - "POINT_PROCESS", SUFFIX, - "ARTIFICIAL_CELL", SUFFIX, - "NONSPECIFIC_CURRENT", NONSPECIFIC, - "ELECTRODE_CURRENT", ELECTRODE_CURRENT, - "USEION", USEION, - "READ", READ, - "WRITE", WRITE, - "RANGE", RANGE, - "SECTION", SECTION, - "VALENCE", VALENCE, - "GLOBAL", GLOBAL, - "POINTER", POINTER, - "BBCOREPOINTER", POINTER, - "EXTERNAL", EXTERNAL, - "INCLUDE", INCLUDE1, - "CONSTRUCTOR", CONSTRUCTOR, - "DESTRUCTOR", DESTRUCTOR, - "NET_RECEIVE", NETRECEIVE, - "BEFORE", BEFORE, /* before NEURON sets up cy' = f(y,t) */ - "AFTER", AFTER, /* after NEURON solves cy' = f(y, t) */ - "WATCH", WATCH, - "FOR_NETCONS", FOR_NETCONS, - "THREADSAFE", THREADSAFE, - "PROTECT", PROTECT, + "PLOT", PLOT, + "VS", VS, + "LAG", LAG, + "RESET", RESET, + "MATCH", MATCH, + "MODEL_LEVEL", MODEL_LEVEL, /* inserted by merge */ + "SWEEP", SWEEP, + "FIRST", FIRST, + "LAST", LAST, + "COMPARTMENT", COMPARTMENT, + "LONGITUDINAL_DIFFUSION", LONGDIFUS, + "PUTQ", PUTQ, + "GETQ", GETQ, + "IFERROR", IFERROR, + "SOLVEFOR", SOLVEFOR, + "UNITS", UNITBLK, + "UNITSON", UNITSON, + "UNITSOFF", UNITSOFF, + "TABLE", TABLE, + "DEPEND", DEPEND, + "NEURON", NEURON, + "SUFFIX", SUFFIX, + "POINT_PROCESS", SUFFIX, + "ARTIFICIAL_CELL", SUFFIX, + "NONSPECIFIC_CURRENT", NONSPECIFIC, + "ELECTRODE_CURRENT", ELECTRODE_CURRENT, + "USEION", USEION, + "READ", READ, + "WRITE", WRITE, + "RANGE", RANGE, + "SECTION", SECTION, + "VALENCE", VALENCE, + "GLOBAL", GLOBAL, + "POINTER", POINTER, + "BBCOREPOINTER", POINTER, + "EXTERNAL", EXTERNAL, + "INCLUDE", INCLUDE1, + "CONSTRUCTOR", CONSTRUCTOR, + "DESTRUCTOR", DESTRUCTOR, + "NET_RECEIVE", NETRECEIVE, + "BEFORE", BEFORE, /* before NEURON sets up cy' = f(y,t) */ + "AFTER", AFTER, /* after NEURON solves cy' = f(y, t) */ + "WATCH", WATCH, + "FOR_NETCONS", FOR_NETCONS, + "THREADSAFE", THREADSAFE, + "PROTECT", PROTECT, 0, 0 }; @@ -138,20 +137,20 @@ static struct { /* numerical methods */ "euler", DERF | KINF, 0, "adeuler", DERF | KINF, 1, "heun", DERF | KINF, 0, - "adrunge", DERF | KINF, 1, + "adrunge", DERF | KINF, 1, "newton", NLINF, 0, "simplex", NLINF, 0, "simeq", LINF, 0, "seidel", LINF, 0, - "_advance", KINF, 0, - "sparse", KINF, 0, - "derivimplicit", DERF, 0, /* name hard wired in deriv.c */ - "cnexp", DERF, 0, + "_advance", KINF, 0, + "sparse", KINF, 0, + "derivimplicit", DERF, 0, /* name hard wired in deriv.c */ + "cnexp", DERF, 0, "clsoda", DERF | KINF, 0, /* Tolerance built in to scopgear.c */ - "after_cvode", 0, 0, - "cvode_t", 0, 0, - "cvode_t_v", 0, 0, + "after_cvode", 0, 0, + "cvode_t", 0, 0, + "cvode_t_v", 0, 0, 0, 0, 0 }; diff --git a/src/modlunit/io.c b/src/modlunit/io.cpp similarity index 91% rename from src/modlunit/io.c rename to src/modlunit/io.cpp index e2e86c2782..210c2c91d8 100755 --- a/src/modlunit/io.c +++ b/src/modlunit/io.cpp @@ -23,7 +23,7 @@ static int linenum = 0; static char inlinebuf[600], *inlinep = inlinebuf + 30, *ctp = inlinebuf + 30; static int file_stack_empty(); -char* Fgets(buf, size, f) char* buf; int size; FILE* f; { +char* Fgets(char* buf, int size, FILE* f){ char* p = buf; int c, i; for(i=0; i < size; ++ i) { @@ -80,8 +80,7 @@ Getc() return c; } -int unGetc(c) - int c; +int unGetc(int c) { if (c == EOF) return c; @@ -95,8 +94,7 @@ int unGetc(c) } char * -Gets(buf) - char *buf; +Gets(char* buf) { char *cp; int c; @@ -118,8 +116,7 @@ Gets(buf) } /* two arguments so we can pass a name to construct an error message. */ -void diag(s1, s2) - char *s1, *s2; +void diag(char* s1, char* s2) { char *cp; Item *q1, *q2, *q; @@ -184,45 +181,42 @@ void diag(s1, s2) exit(1); } -Symbol *_SYM(q, file, line) Item *q; char *file; int line; { +Symbol *_SYM(Item* q, char* file, int line){ if (!q || q->itemtype != SYMBOL) { internal_error(q, file, line); } return (Symbol *)((q)->element); } -char *_STR(q, file, line) Item *q; char *file; int line; { +char *_STR(Item* q, char* file, int line) { if (!q || q->itemtype != STRING) { internal_error(q, file, line); } return (char *)((q)->element); } -Item *_ITM(q, file, line) Item *q; char *file; int line; { +Item *_ITM(Item* q, char* file, int line) { if (!q || q->itemtype != ITEM) { internal_error(q, file, line); } return (Item *)((q)->element); } -Item **_ITMA(q, file, line) Item *q; char *file; int line; { +Item **_ITMA(Item* q, char* file, int line) { if (!q || q->itemtype != ITEMARRAY) { internal_error(q, file, line); } return (Item **)((q)->element); } -List *_LST(q, file, line) Item *q; char *file; int line; { +List *_LST(Item* q, char* file, int line) { if (!q || q->itemtype != LIST) { internal_error(q, file, line); } return (List *)((q)->element); } -void internal_error(q, file, line) - Item *q; - char *file; - int line; +void internal_error(Item* q, char* file, int line) { Fprintf(stderr, "Internal error in file \"%s\", line %d\n", file, line); Fprintf(stderr, "The offending item has the structure:\n"); @@ -241,8 +235,7 @@ typedef struct FileStackItem { static List* filestack; -static int getprefix(prefix, s) - char* prefix, *s; +static int getprefix(char* prefix, char* s) { char* cp; strcpy(prefix, s); @@ -255,9 +248,7 @@ static int getprefix(prefix, s) return (prefix[0] != '\0'); } -static FILE* include_open(fname, err) - char* fname; - int err; +static FILE* include_open(char* fname, int err) { FILE* f = (FILE*)0; FileStackItem* fsi; @@ -315,8 +306,7 @@ static FILE* include_open(fname, err) return f; } -void include_file(q) - Item* q; +void include_file(Item* q) { char fname[200]; FileStackItem* fsi; @@ -353,7 +343,7 @@ void pop_file_stack() { fclose(fin); fin = fsi->fp; strcpy(finname, fsi->finname); - free((char*)fsi); + free(fsi); } static int file_stack_empty() { diff --git a/src/modlunit/kinunit.c b/src/modlunit/kinunit.cpp similarity index 78% rename from src/modlunit/kinunit.c rename to src/modlunit/kinunit.cpp index f2854ea694..52746685b6 100755 --- a/src/modlunit/kinunit.c +++ b/src/modlunit/kinunit.cpp @@ -6,12 +6,10 @@ extern char *indepunits; static List *reactnames; -static void set_flux_units(); -static void react_unit_err(); +static void set_flux_units(unit*); +static void react_unit_err(char*, unit*); -void kinunits(type, pass) - Item *type; - int pass; +void kinunits(Item* type, int pass) { struct unit ux1, ux2, ur1, ur2, uflux; Item *q; @@ -44,7 +42,7 @@ Fprintf(stderr, "REACTION quantity units for %s is: %s\n", SYM(ITM(q))->name, un unit_pop(); Fprintf(stderr, "but the quantity units of the first term is: %s\n", unit_str()); diag("Inconsistent material quantity units\n", - "Need a correct COMPARTMENT statement"); + "Need a correct COMPARTMENT statement"); } } @@ -89,26 +87,23 @@ diag("Inconsistent flux units", (char *)0); freelist(&reactnames); } -static void set_flux_units(up) - struct unit *up; +static void set_flux_units(unit* up) { Symbol *s; Sprintf(buf, "%s", Unit_str(up)); - if ((s = lookup("f_flux")) == SYM0) { - s = install("f_flux", NAME); + if ((s = lookup( "f_flux")) == SYM0) { + s = install( "f_flux", NAME); } s->u.str = stralloc(buf, (char *)0); - if ((s = lookup("b_flux")) == SYM0) { - s = install("b_flux", NAME); + if ((s = lookup( "b_flux")) == SYM0) { + s = install( "b_flux", NAME); } s->u.str = stralloc(buf, (char *)0); } -static void react_unit_err(s, up) - char *s; - struct unit *up; +static void react_unit_err(char* s, unit* up) { Fprintf(stderr, "Flux units for this reaction: %s\n", Unit_str(up)); @@ -125,35 +120,32 @@ void clear_compartlist() { }} } -void unit_compartlist(q) - Item *q; +void unit_compartlist(Item* q) { char *ustr; ustr = (char *)(ITMA(SYM(q)->info)[6]); if (ustr) { - diag(SYM(q)->name, " already in previous COMPARTMENT"); + diag(SYM(q)->name, "already in previous COMPARTMENT"); } ITMA(SYM(q)->info)[6] = (Item *) stralloc(unit_str(), (char *)0); } -void unit_ldifuslist(q, flag) - Item *q; - int flag; +void unit_ldifuslist(Item* q, int flag) { char *ustr; unitonflag = flag; ustr = (char *)(ITMA(SYM(q)->info)[6]); if (!ustr) { - diag(SYM(q)->name, " not declared in previous COMPARTMENT"); + diag(SYM(q)->name, "not declared in previous COMPARTMENT"); } - Unit_push("micron4/ms"); + Unit_push( "micron4/ms"); if (!unit_cmp_exact()) { unit_pop(); -diag(unit_str(), " : relevant area * diffusion constant must\n be micron2 micron2/ms (1-21 m4/s)"); +diag(unit_str(), ": relevant area * diffusion constant must\n be micron2 micron2/ms (1-21 m4/s)"); } unit_pop(); - Unit_push("micron2"); + Unit_push( "micron2"); Unit_push(ustr); if (!unit_cmp_exact()) { diag(ustr, ": With LONGDITUDINAL_DIFFUSION the compartment \ @@ -164,8 +156,7 @@ volume\nmust be measured in micron3/micron (1-12 m2)"); unitonflag = 0; } -void consreact_push(q) - Item* q; +void consreact_push(Item* q) { char* ustr; unit_push(q); @@ -178,8 +169,7 @@ void consreact_push(q) } } -void ureactadd(q) - Item *q; +void ureactadd(Item* q) { if (!reactnames) { reactnames = newlist(); diff --git a/src/modlunit/lex.l b/src/modlunit/lex.l index 5bb81d5c5b..6bab5bbdeb 100755 --- a/src/modlunit/lex.l +++ b/src/modlunit/lex.l @@ -22,8 +22,8 @@ static char linebuf[512], *cp; int lexcontext; -extern int unput(); -extern int unGetc(); +extern int unput(int); +extern int unGetc(int); extern int Getc(); #define debug(arg1,arg2) /*printf("lex:arg1|%s|\n", arg2);*/ @@ -126,14 +126,14 @@ E [Ee][-+]?{D}+ [ \t]+ { putintoken(yytext, SPACE, SPACE);} -\r\n { putintoken("\n", NEWLINE, 0);} -\r { putintoken("\n", NEWLINE, 0);} +\r\n { putintoken( "\n", NEWLINE, 0);} +\r { putintoken( "\n", NEWLINE, 0);} \n { putintoken(yytext, NEWLINE, 0);} [:\?].* { putintoken(yytext, STRING, STUFF);} -\{ { yylval.qp = putintoken("{", 0, '{'); return yytext[0]; } -\} { yylval.qp = putintoken("}", 0, '}'); return yytext[0]; } +\{ { yylval.qp = putintoken( "{", 0, '{'); return yytext[0]; } +\} { yylval.qp = putintoken( "}", 0, '}'); return yytext[0]; } . { yylval.qp = putintoken(yytext, 0, yytext[0]); return yytext[0]; } ENDCOMMENT { @@ -213,11 +213,11 @@ int input() { } #endif -int unput(c) int c; { +int unput(int c) { return unGetc(c); } -int output(c) int c; { +int output(int c) { #if LINT IGNORE(c); #endif @@ -228,11 +228,11 @@ int output(c) int c; { int yywrap() { if (YYSTATE == to_eoverb) { diag("End of file while in VERBATIM mode.\n", - "Missing ENDVERBATIM?"); + "Missing ENDVERBATIM?"); } if (YYSTATE == to_eocom) { diag("End of file while in COMMENT mode.\n", - "Missing ENDCOMMENT?"); + "Missing ENDCOMMENT?"); } return 1; } diff --git a/src/modlunit/list.c b/src/modlunit/list.cpp similarity index 82% rename from src/modlunit/list.c rename to src/modlunit/list.cpp index 034463ffeb..13508512e6 100755 --- a/src/modlunit/list.c +++ b/src/modlunit/list.cpp @@ -58,8 +58,7 @@ newlist() return (List *)i; } -void freelist(plist) /*free the list but not the elements*/ - List **plist; +void freelist(List** plist) /*free the list but not the elements*/ { Item *i1, *i2; if (!(*plist)) { @@ -74,8 +73,7 @@ void freelist(plist) /*free the list but not the elements*/ } static Item * -linkitem(item) - Item *item; +linkitem(Item* item) { Item *i; @@ -87,33 +85,28 @@ linkitem(item) return i; } -Item *car(list) - List *list; +Item *car(List* list) { Item *q = (Item *)list; assert(q && q->itemtype == 0); return next(q); } -Item *next(item) - Item *item; +Item *next(Item* item) { assert(item->next->itemtype); /* never return the list item */ return item->next; } -Item *prev(item) - Item *item; +Item *prev(Item* item) { assert(item->prev->itemtype); /* never return the list item */ return item->prev; } Item * -insertstr(item, str) /* insert a copy of the string before item */ +insertstr(Item* item, char* str) /* insert a copy of the string before item */ /* a copy is made because strings are often assembled into a reusable buffer*/ - Item *item; - char *str; { Item *i; @@ -124,8 +117,7 @@ insertstr(item, str) /* insert a copy of the string before item */ } Item * -insertitem(item, itm) /* insert a item pointer before item */ - Item *item, *itm; +insertitem(Item* item, Item* itm) /* insert a item pointer before item */ { Item *i; @@ -136,10 +128,8 @@ insertitem(item, itm) /* insert a item pointer before item */ } Item * -insertsym(item, sym) /* insert a symbol before item */ +insertsym(Item* item, Symbol* sym) /* insert a symbol before item */ /* a copy is not made because we need the same symbol in different lists */ - Item *item; - Symbol *sym; { Item *i; @@ -150,47 +140,36 @@ insertsym(item, sym) /* insert a symbol before item */ } Item * -linsertstr(list, str) - List *list; - char *str; +linsertstr(List* list, char* str) { return insertstr(list->next, str); } Item * -lappendstr(list, str) - List *list; - char *str; +lappendstr(List* list, char* str) { return insertstr(list, str); } Item * -linsertsym(list, sym) - List *list; - Symbol *sym; +linsertsym(List* list, Symbol* sym) { return insertsym(list->next, sym); } Item * -lappendsym(list, sym) - List *list; - Symbol *sym; +lappendsym(List* list, Symbol* sym) { return insertsym(list, sym); } Item * -lappenditem(list, item) - List *list; - Item *item; +lappenditem(List* list, Item* item) { return insertitem(list, item); } -void delete(item) - Item *item; +void dlete(Item* item) { assert(item->itemtype); /* can't delete list */ item->next->prev = item->prev; @@ -202,15 +181,15 @@ static long mallocsize=0; static long mallocpieces=0; #if LINT -double *emalloc(n) unsigned n; { /* check return from malloc */ +double *emalloc(unsigned n) { /* check return from malloc */ assert(0); return (double *)0; } #else -char *emalloc(n) unsigned n; { /* check return from malloc */ +char *emalloc(unsigned n) { /* check return from malloc */ char *p; - p = malloc(n); + p = static_cast(malloc(n)); if (p == (char *)0) { memory_usage(); diag("out of memory", (char *)0); @@ -226,7 +205,7 @@ void memory_usage() { mallocsize, mallocpieces); } -char *stralloc(buf, rel) char *buf,*rel; { +char *stralloc(char* buf, char* rel) { /* allocate space, copy buf, and free rel */ char *s; s = (char *)emalloc((unsigned)(strlen(buf) + 1)); @@ -237,8 +216,7 @@ char *stralloc(buf, rel) char *buf,*rel; { return s; } -void deltokens(q1, q2) /* delete tokens from q1 to q2 */ - Item *q1, *q2; +void deltokens(Item* q1, Item* q2) /* delete tokens from q1 to q2 */ { /* It is a serious error if q2 precedes q1 */ Item *q; @@ -250,8 +228,7 @@ void deltokens(q1, q2) /* delete tokens from q1 to q2 */ } -void move(q1, q2, q3) /* move q1 to q2 and insert before q3*/ - Item *q1, *q2, *q3; +void move(Item* q1, Item* q2, Item* q3) /* move q1 to q2 and insert before q3*/ { /* it is a serious error if q2 precedes q1 */ assert(q1 && q2); @@ -265,16 +242,12 @@ void move(q1, q2, q3) /* move q1 to q2 and insert before q3*/ q2->next = q3; } -void movelist(q1, q2, s) /* move q1 to q2 from old list to end of list s*/ - Item *q1, *q2; - List *s; +void movelist(Item* q1, Item* q2, List* s) /* move q1 to q2 from old list to end of list s*/ { move(q1, q2, s); } -void replacstr(q, s) - Item *q; - char *s; +void replacstr(Item* q, char* s) { q->itemtype = STRING; q->element = (void *)stralloc(s, (char *)0); @@ -282,9 +255,7 @@ void replacstr(q, s) } Item * -putintoken(s, type, toktype) - char *s; - short type, toktype; +putintoken(char* s, short type, short toktype) { /* make sure a symbol exists for s and append to intoken list */ Symbol *sym; @@ -295,7 +266,7 @@ putintoken(s, type, toktype) Fprintf(stderr, "%s|", s); } if (s == (char *)0) - diag("internal error"," in putintoken"); + diag( "internal error", " in putintoken"); switch (type) { case STRING: @@ -374,16 +345,14 @@ makelist(va_alist) return ql; } -void append(ql, q) - Item *ql, *q; +void append(Item* ql, Item* q) { assert(ql->itemtype == LIST); IGNORE(insertitem((Item *)(LST(ql)), q)); } Item * -prepend(ql, q) - Item *ql, *q; +prepend(Item* ql, Item* q) { List *l; diff --git a/src/modlunit/model.c b/src/modlunit/model.cpp similarity index 93% rename from src/modlunit/model.c rename to src/modlunit/model.cpp index e21c28b4a9..95f9de03d7 100755 --- a/src/modlunit/model.c +++ b/src/modlunit/model.cpp @@ -48,16 +48,15 @@ Item *qlint; static char pgm_name[] = "model"; extern char *RCS_version; extern char *RCS_date; -static void openfiles(); -static void debug_item(); +static void openfiles(int, char**); +static void debug_item(Item* q, int indent, FILE* file); #if MAC #include #endif int -main(argc, argv) - int argc; - char *argv[]; { +main(int argc, char* argv[]) +{ /* * arg 1 is the prefix to the input file and output .c and .par * files @@ -135,9 +134,7 @@ main(argc, argv) return 0; } -static void openfiles(argc, argv) - int argc; - char *argv[]; +static void openfiles(int argc, char* argv[]) { char *cp, modprefix[NRN_BUFSIZE - 5]; if (argc > 1) { @@ -163,8 +160,7 @@ static void openfiles(argc, argv) } } -void printlist(list) - List *list; +void printlist(List* list) { Item *q; @@ -173,8 +169,7 @@ void printlist(list) } } -void printitems(q1, q2) - Item *q1, *q2; +void printitems(Item* q1, Item* q2) { Item *q; @@ -183,9 +178,7 @@ void printitems(q1, q2) } } -void printitem(q, fp) - Item *q; - FILE *fp; +void printitem(Item* q, FILE* fp) { switch (q->itemtype) { @@ -207,16 +200,12 @@ void printitem(q, fp) fflush(fp); } -void debugitem(q) - Item *q; +void debugitem(Item* q) { debug_item(q, 0, stderr); } -static void debug_item(q, indent, file) - Item *q; - int indent; - FILE *file; +static void debug_item(Item* q, int indent, FILE* file) { int i; List *list; diff --git a/src/modlunit/model.h b/src/modlunit/model.h index bf46e06bce..ee0c874ac0 100755 --- a/src/modlunit/model.h +++ b/src/modlunit/model.h @@ -78,16 +78,16 @@ typedef struct Symbol { * the item is */ #if DEBUG || 1 -extern Symbol *_SYM(); -extern char *_STR(); -extern Item *_ITM(); -extern Item **_ITMA(); /* array of item pointers */ -extern List *_LST(); -#define SYM(q) _SYM(q,__FILE__,__LINE__) -#define STR(q) _STR(q,__FILE__,__LINE__) -#define ITM(q) _ITM(q,__FILE__,__LINE__) -#define ITMA(q) _ITMA(q,__FILE__,__LINE__) -#define LST(q) _LST(q,__FILE__,__LINE__) +extern Symbol *_SYM(Item*, char*, int); +extern char *_STR(Item* q, char* file, int line); +extern Item *_ITM(Item* q, char* file, int line); +extern Item **_ITMA(Item* q, char* file, int line); /* array of item pointers */ +extern List *_LST(Item* q, char* file, int line); +#define SYM(q) _SYM(q,(char*)__FILE__,__LINE__) +#define STR(q) _STR(q,(char*)__FILE__,__LINE__) +#define ITM(q) _ITM(q,(char*)__FILE__,__LINE__) +#define ITMA(q) _ITMA(q,(char*)__FILE__,__LINE__) +#define LST(q) _LST(q,(char*)__FILE__,__LINE__) #else #define SYM(q) ((Symbol *)((q)->element)) #define STR(q) ((char *)((q)->element)) @@ -137,17 +137,17 @@ extern List *_LST(); #define EXPLICIT_DECL 01 /* usage field, variable occurs in input file */ #if LINT -extern double *emalloc(); /* lint thinks doubles align with anything*/ +extern double *emalloc(unsigned); /* lint thinks doubles align with anything*/ #else -extern char *emalloc(); /* malloc with out of space checking */ +extern char *emalloc(unsigned); /* malloc with out of space checking */ #endif -extern char - *stralloc(), /* copies string to new space */ - *inputline(), /* used only by parser to get title line */ - *inputtopar(), /* used only by parser to get units */ - *decode_units(), - *unit_str(), - *Gets(); /* used only in io.c to get string from fin. */ +extern char *stralloc(char*, char*); /* copies string to new space */ + +extern char *inputline(), /* used only by parser to get title line */ + *inputtopar(), /* used only by parser to get units */ + *decode_units(Symbol*), + *unit_str(), + *Gets(char*); /* used only in io.c to get string from fin. */ extern List #if HAVE_STDARG_H || MAC @@ -162,26 +162,29 @@ extern List *inputtext(); /* used by parser to get block text from * VERBATIM and COMMENT */ extern Item - *putintoken(), /* construct symbol and store input tokens */ - *insertstr(), /* before a known Item */ - *insertsym(), - *linsertstr(), /* prepend to list */ - *lappendstr(), /* append to list */ - *linsertsym(), - *lappendsym(), - *lappenditem(), + *putintoken(char *s, short type, short), /* construct symbol and store input tokens */ + *insertstr(Item* item, char* str), /* before a known Item */ + *insertsym(List* list, Symbol* sym), + *linsertstr(List* list, char* str), /* prepend to list */ + *lappendstr(List* list, char* str), /* append to list */ + *linsertsym(List* list, Symbol* sym), + *lappendsym(List* list, Symbol* sym), + *lappenditem(List* list, Item* item), *listtype(), - *next_parstok(), - *prev_parstok(), - *car(), - *next(), - *prev(); + *next_parstok(Item*), + *prev_parstok(Item*), + *car(List*), + *next(Item*), + *prev(Item*); + + + #include "modlunit.h" /* void functions */ extern Symbol - *install(), /* Install token in symbol table */ - *lookup(), /* lookup name in symbol table */ + *install(char*, int), /* Install token in symbol table */ + *lookup(char*), /* lookup name in symbol table */ *ifnew_constinstall(); /* new .var info only if * not already done. */ diff --git a/src/modlunit/modlunit.h b/src/modlunit/modlunit.h index d19489e92e..9d2fabe988 100644 --- a/src/modlunit/modlunit.h +++ b/src/modlunit/modlunit.h @@ -1,74 +1,76 @@ +struct unit; + +void Unit_cmp(); +void Unit_exponent(int); +void Unit_push(char*); +void append(Item* ql, Item* q); +void check_num(); +void clear_compartlist(); void consistency(); -void declare(); -void declare_indep(); -void define_value(); -void declare_array(); -void decdim(); +void consreact_push(Item*); +void debugitem(Item*); +void decdim(Symbol*, Item*); +void declare(long subtype, Item* q, Item* qa); +void declare_array(Symbol*); void declare_implied(); -void install_cfactor(); +void declare_indep(Symbol*); +void define_value(Item* q1, Item* q2); +void dlete(Item*); +void deltokens(Item* q1, Item* q2); +void diag(char*, char*); +void dimensionless(); +void freelist(List**); +void func_unit(Item* q1, Item* q2); +void ifcnvfac(Item*); +void include_file(Item*); void init(); -void diag(); -void internal_error(); -void include_file(); -void pop_file_stack(); -void kinunits(); -void clear_compartlist(); -void unit_compartlist(); -void unit_ldifuslist(); -void consreact_push(); -void ureactadd(); -void freelist(); -void delete(); -void deltokens(); +void install_cfactor(Item*, Item*, Item*); +void install_local(Item* q, Item* qdim); +void install_units(char*, char*); +void internal_error(Item* q, char* file, int line); +void kinunits(Item* type, int pass); void lex_start(); void lex_units(); -void move(); -void movelist(); void memory_usage(); -void replacstr(); -void append(); -void printlist(); -void printitems(); -void printitem(); -void debugitem(); -void nrn_unit_init(); +void modl_units(); +void move(Item* , Item* , Item* ); +void movelist(Item* q1, Item* q2, List* s); +void nrn_list(Item *, Item*); void nrn_unit_chk(); -void nrn_list(); -void nrn_use(); -void parsepass(); -void parse_restart(); -void pushlocal(); +void nrn_unit_init(); +void nrn_use(Item* q1, Item* q2, Item* q3); +void parse_restart(Item* q, int i); +void parsepass(int); +void pop_file_stack(); void poplocal(); -void install_local(); -void ifcnvfac(); -void unit_exponent(); -void unit_cmp(); -void print_unit_expr(); -void unit_logic(); -void unit_push(); -void unit_push_args(); -void unit_done_args(); -void unit_chk_arg(); -void func_unit(); -void unit_del(); -void unit_pop(); -void unit_swap(); -void unit_mag_mul(); +void print_unit_expr(int); +void printitem(Item* q, FILE* fp); +void printitems(Item* q1, Item* q2); +void printlist(List*); void punit(); -void ucopypop(); -void ucopypush(); -void Unit_push(); -void unit_push_num(); -void unitcheck(); -void install_units(); -void check_num(); -void unit_mul(); +void pushlocal(Item* q1, Item* qdim); +void replacstr(Item* q, char* s); +void symbol_init(); +void ucopypop(unit*); +void ucopypush(unit*); +void unit_chk_arg(Item* q1, Item* q2); +void unit_cmp(Item* q1, Item* q2, Item* q3); +void unit_compartlist(Item*); +void unit_del(int); void unit_div(); -void Unit_exponent(); -void Unit_cmp(); -void dimensionless(); +void unit_done_args(); +void unit_exponent(Item* y, Item* lastok); +void unit_init(); +void unit_ldifuslist(Item*, int); void unit_less(); +void unit_logic(int type, Item* q1, Item* q2, Item* q3); +void unit_mag_mul(double); +void unit_mul(); +void unit_pop(); +void unit_push(Item*); +void unit_push_args(Item*); +void unit_push_num(double); void unit_stk_clean(); -void modl_units(); -void unit_init(); -void symbol_init(); +void unit_swap(); +void unitcheck(char*); +void ureactadd(Item*); diff --git a/src/modlunit/nrnunit.c b/src/modlunit/nrnunit.cpp similarity index 84% rename from src/modlunit/nrnunit.c rename to src/modlunit/nrnunit.cpp index f707cabd76..f6e9bfb943 100755 --- a/src/modlunit/nrnunit.c +++ b/src/modlunit/nrnunit.cpp @@ -10,8 +10,8 @@ static int point_process = 0; static List *current, *concen, *potential; -static void unit_chk(); -static int iontype(); +static void unit_chk(char*, char*); +static int iontype(char*, char*); int breakpoint_local_seen_; int conductance_seen_; @@ -26,12 +26,12 @@ void nrn_unit_init() { void nrn_unit_chk() { Item *q; - unit_chk("v", "millivolt"); - unit_chk("t", "ms"); - unit_chk("dt", "ms"); + unit_chk("v", "millivolt"); + unit_chk("t", "ms"); + unit_chk("dt", "ms"); unit_chk("celsius", "degC"); - unit_chk("diam", "micron"); - unit_chk("area", "micron2"); + unit_chk("diam", "micron"); + unit_chk("area", "micron2"); if (breakpoint_local_seen_ == 0 || conductance_seen_ == 0) { ITERATE(q, current) { @@ -50,8 +50,7 @@ void nrn_unit_chk() { } } -static void unit_chk(name, unit) - char *name, *unit; +static void unit_chk(char* name, char* unit) { Symbol *s; @@ -69,8 +68,7 @@ Sprintf(buf, "%s must have the units, %s, instead of %s.\n", } } -void nrn_list(qtype, qlist) - Item *qtype, *qlist; +void nrn_list(Item* qtype, Item* qlist) { List **plist; Item *q; @@ -100,8 +98,7 @@ void nrn_list(qtype, qlist) } } -void nrn_use(qion, qreadlist, qwritelist) - Item *qion, *qreadlist, *qwritelist; +void nrn_use(Item* qion, Item* qreadlist, Item* qwritelist) { int i; List *l; @@ -133,8 +130,7 @@ void nrn_use(qion, qreadlist, qwritelist) } static -int iontype(s1, s2) /* returns index of variable in ion mechanism */ - char *s1, *s2; +int iontype(char* s1, char* s2) /* returns index of variable in ion mechanism */ { Sprintf(buf, "i%s", s2); if (strcmp(buf, s1) == 0) { diff --git a/src/modlunit/parse1.y b/src/modlunit/parse1.y index 2f5ddf3c6d..ed58f556bb 100755 --- a/src/modlunit/parse1.y +++ b/src/modlunit/parse1.y @@ -16,8 +16,8 @@ and a pointer to their declaration. All "used" names are marked with their usage for later error checking. */ -extern Symbol *checklocal(); -extern int next_intoken(); +extern Symbol *checklocal(Symbol*); +extern int next_intoken(Item**); extern Item *title; extern int declare_level; extern int parse_pass, restart_pass; @@ -35,7 +35,7 @@ extern int breakpoint_local_seen_; #define R1 IFR(1) static int yylex(); -static void yyerror(); +static void yyerror(char *); #if YYBISON #define myerr(arg) static int ierr=0;\ @@ -293,7 +293,7 @@ factordef: NAME '=' real Units Unit_push(STR($3)); Unit_push(STR($4)); unit_div(); dimensionless(); - Sprintf(buf, "%g", unit_mag()); + Sprintf(buf, "%g",unit_mag()); $$ = itemarray(3, $1, $4, lappendstr(misc, buf)); /*printf("%s has value %s and units (%s)\n", SYM($1)->name, buf, STR($5));*/ unit_pop(); @@ -503,7 +503,7 @@ expr: varname {P3{unit_push($1);}} | expr LE expr {P3{unit_logic(2, $1, $2, lastok);}} | expr EQ expr {P3{unit_logic(2, $1, $2, lastok);}} | expr NE expr {P3{unit_logic(2, $1, $2, lastok);}} - | NOT expr {P3{unit_pop(); Unit_push("");}} + | NOT expr {P3{unit_pop(); Unit_push( "");}} | '-' expr %prec UNARYMINUS | error {myerr("Illegal expression");} ; @@ -671,14 +671,14 @@ fornetcon: FOR_NETCONS '(' arglist ')' if (s1->u.str) { /* s2 must be nil or same */ if (s2->u.str) { if (strcmp(s1->u.str, s2->u.str) != 0) { - diag(s1->name, " in FOR_NETCONS arglist does not have same units as corresponding arg in NET_RECEIVE arglist"); + diag(s1->name, "in FOR_NETCONS arglist does not have same units as corresponding arg in NET_RECEIVE arglist"); } }else{ s2->u.str = s1->u.str; } }else{ /* s2 must be nil */ if (s2->u.str) { - diag(s1->name, " in FOR_NETCONS arglist does not have same units as corresponding arg in NET_RECEIVE arglist"); + diag(s1->name, "in FOR_NETCONS arglist does not have same units as corresponding arg in NET_RECEIVE arglist"); } } /*printf("|%s|%s| |%s|%s|\n", s1->name, s1->u.str, s2->name, s2->u.str);*/ @@ -788,10 +788,10 @@ reaction: REACTION react REACT1 react '(' expr ',' expr ')' | REACTION error {myerr("Illegal reaction syntax");} ; react: varname {P3{R1{ureactadd($1);} unit_push($1);}} - |INTEGER varname {P3{R1{ureactadd($2);} unit_push($2); Unit_push((char*)0); unit_exponent($1,$1);}} + |INTEGER varname {P3{R1{ureactadd($2);} unit_push($2); Unit_push(0); unit_exponent($1,$1);}} |react '+' varname {P3{R1{ureactadd($3);}unit_push($3); unit_mul();}} |react '+' INTEGER varname { - P3{R1{ureactadd($4);}unit_push($4); Unit_push((char*)0); unit_exponent($3,$3); unit_mul();} + P3{R1{ureactadd($4);}unit_push($4); Unit_push(0); unit_exponent($3,$3); unit_mul();} } ; lagstmt: LAG name BY NAME @@ -886,8 +886,7 @@ valence: /*nothing*/ %% /* end of grammar */ -static void yyerror(s) /* called for yacc syntax error */ - char *s; +static void yyerror(char* s) /* called for yacc syntax error */ { Fprintf(stderr, "%s:\n ", s); } @@ -895,13 +894,11 @@ static void yyerror(s) /* called for yacc syntax error */ static int yylex() {return next_intoken(&(yylval.qp));} #if !NRNUNIT -void nrn_list(q1, q2) - Item *q1, *q2; +void nrn_list(Item *q1, Item* q2) { /*ARGSUSED*/ } -void nrn_use(q1, q2, q3) - Item *q1, *q2, *q3; +void nrn_use(Item* q1, Item* q2, Item* q3) { /*ARGSUSED*/ } diff --git a/src/modlunit/passn.c b/src/modlunit/passn.cpp similarity index 90% rename from src/modlunit/passn.c rename to src/modlunit/passn.cpp index fdd4481422..606be4401e 100755 --- a/src/modlunit/passn.c +++ b/src/modlunit/passn.cpp @@ -18,8 +18,7 @@ int parse_pass=0; int restart_pass=0; extern int yylex(); -void parsepass(n) - int n; +void parsepass(int n) { unitonflag = 1; parse_pass = n; @@ -28,9 +27,7 @@ void parsepass(n) } } -void parse_restart(q, i) - Item *q; - int i; +void parse_restart(Item* q, int i) { if (i == restart_pass) { restart_pass = 0; @@ -43,8 +40,7 @@ void parse_restart(q, i) } } -int next_intoken(pitem) - Item **pitem; +int next_intoken(Item** pitem) { if (parse_pass == 1) { return yylex(); @@ -61,8 +57,7 @@ int next_intoken(pitem) } Item * -next_parstok(intok) - Item *intok; +next_parstok(Item* intok) { if (!intok) { return ITEM0; @@ -85,8 +80,7 @@ next_parstok(intok) } Item * -prev_parstok(intok) - Item *intok; +prev_parstok(Item* intok) { if (!intok) { return ITEM0; diff --git a/src/modlunit/symbol.c b/src/modlunit/symbol.cpp similarity index 91% rename from src/modlunit/symbol.c rename to src/modlunit/symbol.cpp index 1fecb7fcf4..d9a4a5e24f 100755 --- a/src/modlunit/symbol.c +++ b/src/modlunit/symbol.cpp @@ -19,8 +19,7 @@ void symbol_init() { } Symbol * -lookup(s) /* find s in symbol table */ - char *s; +lookup(char* s) /* find s in symbol table */ { Item *sp; @@ -33,8 +32,7 @@ lookup(s) /* find s in symbol table */ } Symbol * -checklocal(sym) - Symbol *sym; +checklocal(Symbol* sym) { Item *sp; List *sl; @@ -52,9 +50,7 @@ checklocal(sym) } Symbol * -install(s, t) /* install s in the list symbol table with type t*/ - char *s; - int t; +install(char* s, int t) /* install s in the list symbol table with type t*/ { Symbol *sp; List *sl; @@ -83,8 +79,7 @@ install(s, t) /* install s in the list symbol table with type t*/ return sp; } -void pushlocal(q1, qdim) - Item *q1, *qdim; +void pushlocal(Item* q1, Item* qdim) { Item * q; q = linsertsym(symlistlist, SYM0); /*the type is irrelevant*/ @@ -108,8 +103,7 @@ void poplocal() delete(symlistlist->next); } -void install_local(q, qdim) - Item *q, *qdim; +void install_local(Item* q, Item* qdim) { Symbol *s; diff --git a/src/modlunit/units.c b/src/modlunit/units.cpp similarity index 91% rename from src/modlunit/units.c rename to src/modlunit/units.cpp index 85db79e2a0..5210b871fa 100755 --- a/src/modlunit/units.c +++ b/src/modlunit/units.cpp @@ -43,8 +43,10 @@ int unitonflag = 1; static int UnitsOn = 0; -extern double fabs(); -extern void diag(); +extern "C" { +extern double fabs(double); +} // extern "C" +extern void diag(char*, char*); #define IFUNITS {if (!UnitsOn) return;} #define OUTTOLERANCE(arg1,arg2) (fabs(arg2/arg1 - 1.) > 1.e-5) @@ -76,17 +78,17 @@ static char *dfilealt = "../../share/lib/nrnunits.lib"SUFFIX; #endif #endif static char *unames[NDIM]; -static double getflt(); -static void fperr(); -static int lookup(); -static struct table *hash(); - -static void chkfperror(); -static void units(); -static int pu(); -static int convr(); -static void init(); -static int get(); +double getflt(); +void fperr(int); +int lookup(char* name, unit* up, int den, int c); +struct table *hash_table(char*); + +void chkfperror(); +void units(unit*); +int pu(int, int, int); +int convr(unit*); +void units_cpp_init(); //TODO - was this init() used somewhere else? avoiding duplicate symbol: nmold/init.cpp init() +int get(); extern void Unit_push(char*); @@ -141,8 +143,7 @@ static int dumpflg; static char *pc; -static int Getc(inp) - FILE *inp; +static int Getc(FILE* inp) { if (inp != stdin) { #if MAC @@ -185,6 +186,33 @@ static char* neuronhome() { #endif } + +static char *ucp; +char *Unit_str(unit* up) +{ + register struct unit *p; + register int f, i; + static char buf[256]; + + p = up; + sprintf(buf, "%g ", p->factor); + {int seee=0; for (ucp=buf; *ucp; ucp++) { + if (*ucp == 'e') seee=1; + if (seee) *ucp = ucp[1]; + } if (seee) ucp--;} + f = 0; + for(i=0; idim[i], i, f); + if(f&1) { + *ucp++ = '/'; + f = 0; + for(i=0; idim[i], i, f); + } + *ucp = '\0'; + return buf; +} + void unit_pop() { IFUNITS assert(usp >= unit_stack); @@ -211,13 +239,11 @@ void unit_swap() { /*exchange top two elements of stack*/ } } -double -unit_mag() { /* return unit magnitude that is on stack */ +double unit_mag() { /* return unit magnitude that is on stack */ return usp->factor; } -void unit_mag_mul(d) - double d; +void unit_mag_mul(double d) { usp->factor *= d; } @@ -229,8 +255,7 @@ void punit() { } } -void ucopypop(up) - struct unit *up; +void ucopypop(unit* up) { int i; for (i=0; iisnum = up->isnum; } -void Unit_push(string) - char *string; +void Unit_push(char* str) { IFUNITS assert(usp < unit_stack + (UNIT_STK_SIZE - 1)); ++usp; - pc = string; - if (string) { + pc = str; + if (str) { usp->isnum = 0; }else{ pc = ""; usp->isnum = 1; } convr(usp); -/*printf("unit_push %s\n", string); units(usp);*/ +/*printf("unit_push %s\n", str); units(usp);*/ } -void unit_push_num(d) - double d; +void unit_push_num(double d) { Unit_push(""); usp->factor = d; } -void unitcheck(s) - char *s; +void unitcheck(char* s) { Unit_push(s); unit_pop(); @@ -293,15 +314,14 @@ unit_str() { return s; } -static void install_units_help(s1, s2) /* define s1 as s2 */ - char *s1, *s2; +void install_units(char* s1, char* s2) /* define s1 as s2 */ { struct table *tp; int i; IFUNITS Unit_push(s2); - tp = hash(s1); + tp = hash_table(s1); if (tp->name) { printf("Redefinition of units (%s) to:", s1); units(usp); @@ -379,8 +399,7 @@ void unit_div() { unit_pop(); } -void Unit_exponent(val) - int val; +void Unit_exponent(int val) { /* multiply top of stack by val and leave on stack */ int i; @@ -423,7 +442,7 @@ unit_cmp_exact() { /* returns 1 if top two units on stack are same */ } /* ARGSUSED */ -static void print_unit_expr(i) int i; {} +static void print_unit_expr(int i) {} void Unit_cmp() { /*compares top two units on stack. If not conformable then @@ -456,7 +475,7 @@ if (unitonflag && up->dim[0] != 9 && usp->dim[0] != 9) { print_unit_expr(1); fprintf(stderr, "\nunits:"); units(up); -diag("The units of the previous two expressions are not conformable","\n"); +diag("The units of the previous two expressions are not conformable",(char*)"\n"); } } if (OUTTOLERANCE(up->factor, usp->factor)) { @@ -509,7 +528,7 @@ int unit_diff() { return 0; } -static void chkfperror() +void chkfperror() { if (fperrc) { diag("underflow or overflow in units calculation", (char *)0); @@ -644,7 +663,7 @@ fprintf(stderr, "Cant open units table in either of:\n%s\n", buf); diag(dfile, dfilealt); } signal(8, fperr); - init(); + units_cpp_init(); unit_stk_clean(); } @@ -670,7 +689,7 @@ char *argv[]; exit(1); } signal(8, fperr); - init(); + units_cpp_init(); loop: fperrc = 0; @@ -707,41 +726,12 @@ char *argv[]; } #endif -static void units(up) -struct unit *up; +void units(unit* up) { printf("\t%s\n", Unit_str(up)); } -static char *ucp; -char *Unit_str(up) -struct unit *up; -{ - register struct unit *p; - register int f, i; - static char buf[256]; - - p = up; - sprintf(buf, "%g ", p->factor); - {int seee=0; for (ucp=buf; *ucp; ucp++) { - if (*ucp == 'e') seee=1; - if (seee) *ucp = ucp[1]; - } if (seee) ucp--;} - f = 0; - for(i=0; idim[i], i, f); - if(f&1) { - *ucp++ = '/'; - f = 0; - for(i=0; idim[i], i, f); - } - *ucp = '\0'; - return buf; -} - -static int pu(u, i, f) - int u, i, f; +int pu(int u, int i, int f) { if(u > 0) { @@ -763,8 +753,7 @@ static int pu(u, i, f) return(0); } -static int convr(up) -struct unit *up; +int convr(unit* up) { register struct unit *p; register int c; @@ -815,10 +804,7 @@ struct unit *up; goto loop; } -static int lookup(name, up, den, c) -char *name; -struct unit *up; -int den, c; +int lookup(char* name, unit* up, int den, int c) { register struct unit *p; register struct table *q; @@ -829,7 +815,7 @@ int den, c; p = up; e = 1.0; loop: - q = hash(name); + q = hash_table(name); if(q->name) { l1: if(den) { @@ -873,8 +859,7 @@ int den, c; return(1); } -static int equal(s1, s2) -char *s1, *s2; +static int equal(char* s1, char* s2) { register char *c1, *c2; @@ -886,7 +871,7 @@ char *s1, *s2; return(0); } -static void init() +void units_cpp_init() { register char *cp; register struct table *tp, *lp; @@ -900,12 +885,12 @@ static void init() *cp++ = i+'a'; *cp++ = '*'; *cp++ = 0; - lp = hash(np); + lp = hash_table(np); lp->name = np; lp->factor = 1.0; lp->dim[i] = 1; } - lp = hash(""); + lp = hash_table(""); lp->name = cp-1; lp->factor = 1.0; @@ -974,7 +959,7 @@ static void init() goto l0; if(c == '\n') { *cp++ = 0; - tp = hash(np); + tp = hash_table(np); if(tp->name) goto redef; tp->name = np; @@ -986,7 +971,7 @@ static void init() } } *cp++ = 0; - lp = hash(np); + lp = hash_table(np); if(lp->name) goto redef; convr((struct unit *)lp); @@ -1014,8 +999,7 @@ static void init() goto l0; } -static double -getflt() +double getflt() { register int c, i, dp; double d, e; @@ -1071,7 +1055,7 @@ getflt() return(d); } -static int get() +int get() { register int c; @@ -1092,9 +1076,7 @@ static int get() return(c); } -static struct table * -hash(name) -char *name; +struct table * hash_table(char* name) { register struct table *tp; register char *np; @@ -1118,7 +1100,7 @@ char *name; goto l0; } -static void fperr(sig) int sig; +void fperr(int sig) { signal(8, fperr); diff --git a/src/modlunit/units.h b/src/modlunit/units.h index 009685f0c5..b8116030ee 100755 --- a/src/modlunit/units.h +++ b/src/modlunit/units.h @@ -10,6 +10,6 @@ struct unit int isnum; }; -extern char *Unit_str(); +extern char *Unit_str(unit*); extern int unit_diff(); extern int unit_cmp_exact(); diff --git a/src/modlunit/units1.c b/src/modlunit/units1.cpp similarity index 82% rename from src/modlunit/units1.c rename to src/modlunit/units1.cpp index c4081d4849..83898e4f50 100755 --- a/src/modlunit/units1.c +++ b/src/modlunit/units1.cpp @@ -4,15 +4,13 @@ #include "model.h" #include "parse1.h" -void unit_push(q) - Item *q; +void unit_push(Item* q) { Unit_push(decode_units(SYM(q))); } char * -decode_units(sym) - Symbol *sym; +decode_units(Symbol* sym) { if (sym->u.str) { return sym->u.str; @@ -23,8 +21,7 @@ decode_units(sym) return ""; } -void ifcnvfac(q3) /* '(' expr ')' */ - Item *q3; +void ifcnvfac(Item* q3) /* '(' expr ')' */ { Item *q1, *q2; double d; @@ -48,8 +45,7 @@ void ifcnvfac(q3) /* '(' expr ')' */ y can be any expression. If x has dimensions then y must be a positive integer and the units can be computed */ -void unit_exponent(y, lastok) /*x ^ y*/ - Item *y, *lastok; +void unit_exponent(Item* y, Item* lastok) /*x ^ y*/ { int i; double yval; @@ -60,19 +56,18 @@ void unit_exponent(y, lastok) /*x ^ y*/ assert(i == 1); if (yval - (double)((int)yval)) { unit_less(); - Unit_push(""); + Unit_push( ""); } else { Unit_exponent((int)yval); } }else{ unit_less(); - Unit_push(""); + Unit_push( ""); } } static Item *qexpr[3]; -void unit_cmp(q1, q2, q3) - Item *q1, *q2, *q3; +void unit_cmp(Item* q1, Item* q2, Item* q3) { qexpr[0] = q1; qexpr[1] = q2; @@ -80,8 +75,7 @@ void unit_cmp(q1, q2, q3) Unit_cmp(); } -void print_unit_expr(i) - int i; +void print_unit_expr(int i) { if (i==1) { if (qexpr[0]) { @@ -95,9 +89,7 @@ void print_unit_expr(i) } -void unit_logic(type, q1, q2, q3) - int type; - Item *q1, *q2, *q3; +void unit_logic(int type, Item* q1, Item* q2, Item* q3) { /* if type is 1 then it doesn't matter what the top two elements are: the result is dimensionless. @@ -111,14 +103,13 @@ void unit_logic(type, q1, q2, q3) unit_pop(); } unit_pop(); - Unit_push(""); + Unit_push( ""); } #define NLEVEL 10 /* 10 levels of call! */ static int argnumstk[NLEVEL], pargnum = -1; -void unit_push_args(q1) - Item *q1; +void unit_push_args(Item* q1) { List *larg; Item *q; @@ -150,8 +141,7 @@ void unit_done_args() pargnum--; } -void unit_chk_arg(q1, q2) - Item *q1, *q2; +void unit_chk_arg(Item* q1, Item* q2) { if (argnumstk[pargnum] > 0) { argnumstk[pargnum]--; @@ -164,10 +154,9 @@ void unit_chk_arg(q1, q2) } } -void func_unit(q1, q2) - Item *q1, *q2; +void func_unit(Item* q1, Item* q2) { - Symbol *s, *checklocal(); + Symbol *s, *checklocal(Symbol*); s = SYM(q1); s = checklocal(s); /* hidden with pushlocal */ @@ -179,18 +168,17 @@ void func_unit(q1, q2) } } -void unit_del(i) /* push 1/delta_x ^ i units */ - int i; +void unit_del(int i) /* push 1/delta_x ^ i units */ { Symbol *s; char *cp; - s = lookup("delta_x"); + s = lookup( "delta_x"); if(!s) { diag("delta_x not declared", (char *)0); } cp = decode_units(s); - Unit_push(""); + Unit_push( ""); while(i--) { Unit_push(cp); unit_div(); diff --git a/src/modlunit/version.c b/src/modlunit/version.cpp similarity index 100% rename from src/modlunit/version.c rename to src/modlunit/version.cpp diff --git a/src/mswin/extra/d2uenv.c b/src/mswin/extra/d2uenv.cpp similarity index 100% rename from src/mswin/extra/d2uenv.c rename to src/mswin/extra/d2uenv.cpp diff --git a/src/mswin/extra/d2upath.c b/src/mswin/extra/d2upath.cpp similarity index 96% rename from src/mswin/extra/d2upath.c rename to src/mswin/extra/d2upath.cpp index eb8e6ebf3b..a9c1b5421d 100644 --- a/src/mswin/extra/d2upath.c +++ b/src/mswin/extra/d2upath.cpp @@ -19,7 +19,7 @@ char* hoc_dos2cygdrivepath(const char* d, int cygdrive) { #if 0 u = new char[strlen(d) + 12]; #else - u = (char*)malloc(strlen(d) + 12); + u = malloc(strlen(d) + 12); assert(u); #endif i = j = 0; diff --git a/src/mswin/extra/splitnrn.c b/src/mswin/extra/splitnrn.cpp similarity index 96% rename from src/mswin/extra/splitnrn.c rename to src/mswin/extra/splitnrn.cpp index 456e1f9279..b39b440058 100755 --- a/src/mswin/extra/splitnrn.c +++ b/src/mswin/extra/splitnrn.cpp @@ -8,7 +8,7 @@ void main(int argc, char** argv) { long i, j, n, done; FILE* fi, *fo; char* buf; - buf = (char*)malloc(1024*16); + buf = malloc(1024*16); if (argc != 2) { printf("usage: splitnrn nrndisk2\n"); exit(1); diff --git a/src/mswin/extra/winmain.c b/src/mswin/extra/winmain.cpp similarity index 100% rename from src/mswin/extra/winmain.c rename to src/mswin/extra/winmain.cpp diff --git a/src/mswin/rdln/emacs_ke.c b/src/mswin/rdln/emacs_ke.cpp similarity index 99% rename from src/mswin/rdln/emacs_ke.c rename to src/mswin/rdln/emacs_ke.cpp index 37f93de9cb..3ba8e9caee 100755 --- a/src/mswin/rdln/emacs_ke.c +++ b/src/mswin/rdln/emacs_ke.cpp @@ -1,4 +1,4 @@ -/* emacs_keymap.c -- the keymap for emacs_mode in readline (). */ +/* emacs_keymap.cpp -- the keymap for emacs_mode in readline (). */ /* Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc. diff --git a/src/mswin/rdln/funmap.c b/src/mswin/rdln/funmap.cpp similarity index 99% rename from src/mswin/rdln/funmap.c rename to src/mswin/rdln/funmap.cpp index e0a3162523..15ae97f2ca 100755 --- a/src/mswin/rdln/funmap.c +++ b/src/mswin/rdln/funmap.cpp @@ -1,4 +1,4 @@ -/* funmap.c -- attach names to functions. */ +/* funmap.cpp -- attach names to functions. */ /* Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc. diff --git a/src/mswin/rdln/history.c b/src/mswin/rdln/history.cpp similarity index 99% rename from src/mswin/rdln/history.c rename to src/mswin/rdln/history.cpp index 66051004f6..53a5b5bb68 100755 --- a/src/mswin/rdln/history.c +++ b/src/mswin/rdln/history.cpp @@ -1,4 +1,4 @@ -/* History.c -- standalone history library */ +/* History.cpp -- standalone history library */ /* Copyright (C) 1989, 1991 Free Software Foundation, Inc. @@ -1712,6 +1712,6 @@ main () /* * Local variables: -* compile-command: "gcc -g -DTEST -o history history.c" +* compile-command: "gcc -g -DTEST -o history history.cpp" * end: */ diff --git a/src/mswin/rdln/keymaps.c b/src/mswin/rdln/keymaps.cpp similarity index 97% rename from src/mswin/rdln/keymaps.c rename to src/mswin/rdln/keymaps.cpp index f1afb3b0cd..e25d14d436 100755 --- a/src/mswin/rdln/keymaps.c +++ b/src/mswin/rdln/keymaps.cpp @@ -1,4 +1,4 @@ -/* keymaps.c -- Functions and keymaps for the GNU Readline library. */ +/* keymaps.cpp -- Functions and keymaps for the GNU Readline library. */ /* Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc. @@ -27,10 +27,10 @@ #include #include "readline.h" #include "keymaps.h" -#include "emacs_ke.c" +#include "emacs_ke.cpp" #ifdef VI_MODE -#include "vi_keymap.c" +#include "vi_keymap.cpp" #endif /* Remove these declarations when we have a complete libgnu.a. */ diff --git a/src/mswin/rdln/readline.c b/src/mswin/rdln/readline.cpp similarity index 99% rename from src/mswin/rdln/readline.c rename to src/mswin/rdln/readline.cpp index e77e9603a9..a6589e5a68 100755 --- a/src/mswin/rdln/readline.c +++ b/src/mswin/rdln/readline.cpp @@ -1,4 +1,4 @@ -/* readline.c -- a general facility for reading lines of input +/* readline.cpp -- a general facility for reading lines of input with emacs style editing and completion. */ /* Copyright 1987, 1989, 1991, 1992 Free Software Foundation, Inc. @@ -3289,7 +3289,7 @@ rl_insert (count, c) else { /* Inserting a single character. */ - string = (char*)alloca (2); + string = alloca (2); string[1] = '\0'; string[0] = c; rl_insert_text (string); @@ -6762,7 +6762,7 @@ main () /* * Local variables: - * compile-command: "gcc -g -traditional -I. -I.. -DTEST -o readline readline.c keymaps.o funmap.o history.o -ltermcap" + * compile-command: "gcc -g -traditional -I. -I.. -DTEST -o readline readline.cpp keymaps.o funmap.o history.o -ltermcap" * end: */ #if defined(__MWERKS__) diff --git a/src/mswin/wnrnbbs/ddeclnt.c b/src/mswin/wnrnbbs/ddeclnt.cpp similarity index 100% rename from src/mswin/wnrnbbs/ddeclnt.c rename to src/mswin/wnrnbbs/ddeclnt.cpp diff --git a/src/mswin/wnrnbbs/ddesrvr.c b/src/mswin/wnrnbbs/ddesrvr.cpp similarity index 99% rename from src/mswin/wnrnbbs/ddesrvr.c rename to src/mswin/wnrnbbs/ddesrvr.cpp index 837a636116..82e57d9273 100755 --- a/src/mswin/wnrnbbs/ddesrvr.c +++ b/src/mswin/wnrnbbs/ddesrvr.cpp @@ -2,7 +2,7 @@ /*************************************************************************** - Program Name DDESrvr.c + Program Name DDESrvr.cpp Purpose A simple DDE client application, which communicates to a DDE server using the new 3.1 api DDEML calls. diff --git a/src/mswin/wnrnbbs/nrnbbs.h b/src/mswin/wnrnbbs/nrnbbs.h index e3ec153384..c3b5ee9049 100644 --- a/src/mswin/wnrnbbs/nrnbbs.h +++ b/src/mswin/wnrnbbs/nrnbbs.h @@ -3,9 +3,6 @@ typedef void (*NrnBBSCallback)(const char*); -#if defined(__cplusplus) -extern "C" { -#endif bool nrnbbs_connect(); void nrnbbs_disconnect(); bool nrnbbs_connected(); @@ -35,7 +32,4 @@ int nrnbbs_count(); bool nrnbbs_query(long index); #endif -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/nmodl/consist.c b/src/nmodl/consist.cpp similarity index 100% rename from src/nmodl/consist.c rename to src/nmodl/consist.cpp diff --git a/src/nmodl/cout.c b/src/nmodl/cout.cpp similarity index 99% rename from src/nmodl/cout.c rename to src/nmodl/cout.cpp index c0729604b1..ff02b42130 100755 --- a/src/nmodl/cout.c +++ b/src/nmodl/cout.cpp @@ -223,8 +223,8 @@ List *procfunc, *initfunc, *modelfunc, *termfunc, *initlist, *firstlis #if NMODL List *nrnstate; -extern List *currents, *set_ion_variables(), *get_ion_variables(); -extern List *begin_dion_stmt(), *end_dion_stmt(); +extern List *currents, *set_ion_variables(int), *get_ion_variables(int); +extern List *begin_dion_stmt(), *end_dion_stmt(char*); #endif extern Symbol *indepsym; @@ -518,8 +518,7 @@ static void initstates() * type of a list element */ -void printlist(s) - List *s; +void printlist(List* s) { Item *q; int newline = 0, indent = 0, i; @@ -787,9 +786,7 @@ void c_out_vectorize() P("_first = 0;\n}\n"); } -void vectorize_substitute(q, str) - Item* q; - char* str; +void vectorize_substitute(Item* q, char* str) { if (!vectorize_replacements) { vectorize_replacements = newlist(); diff --git a/src/nmodl/deriv.c b/src/nmodl/deriv.cpp similarity index 94% rename from src/nmodl/deriv.c rename to src/nmodl/deriv.cpp index 3e5e9a47b3..6a432267a5 100755 --- a/src/nmodl/deriv.c +++ b/src/nmodl/deriv.cpp @@ -15,7 +15,7 @@ extern Symbol *indepsym; extern List *indeplist; extern int sens_parm, numlist; int dtsav_for_nrn_state; -static void copylist(); +void copylist(List*, Item*); List* massage_list_; List* netrec_cnexp; @@ -34,16 +34,12 @@ extern List* thread_cleanup_list; #if CVODE extern char* cvode_deriv(), *cvode_eqnrhs(); extern Item* cvode_cnexp_solve; -static void cvode_diffeq(); +void cvode_diffeq(Symbol* ds, Item* qbegin, Item* qend); static List* cvode_diffeq_list, *cvode_eqn; static int cvode_cnexp_possible; #endif -void solv_diffeq(qsol, fun, method, numeqn, listnum, steadystate, btype) - Item *qsol; - Symbol *fun, *method; - int numeqn, listnum, steadystate; - int btype; +void solv_diffeq(Item* qsol, Symbol* fun, Symbol* method, int numeqn, int listnum, int steadystate, int btype) { char *maxerr_str, dindepname[256]; char deriv1_advance[256], deriv2_advance[256]; @@ -89,9 +85,8 @@ if (deriv_imp_list) { /* make sure deriv block translation matches method */ } } if ((strcmp(method->name, Derivimplicit) == 0) ^ (found == 1)) { - diag("To use the derivimplicit method the SOLVE statement must\ - precede the DERIVATIVE block\n", -" and all SOLVEs using that block must use the derivimplicit method\n"); + diag("To use the derivimplicit method the SOLVE statement must precede the DERIVATIVE block\n", + " and all SOLVEs using that block must use the derivimplicit method\n"); } Sprintf(deriv1_advance, "_deriv%d_advance = 1;\n", listnum); Sprintf(deriv2_advance, "_deriv%d_advance = 0;\n", listnum); @@ -241,8 +236,7 @@ static Symbol *forderiv; /* base state */ static char base_units[256]; /*base state units */ static int indx, maxindx; /* current indx, and indx of dstate */ -static Symbol * init_forderiv(prime) - Symbol *prime; +static Symbol * init_forderiv(Symbol* prime) { char name[256]; double d1, d2; @@ -259,7 +253,7 @@ static Symbol * init_forderiv(prime) } forderiv = lookup(name); if (!forderiv || !(forderiv->subtype & STAT)) { - diag(name, " must be declared as a state variable"); + diag(name, "must be declared as a state variable"); } if (forderiv->araydim != prime->araydim) { Sprintf(buf, "%s and %s have different dimensions", @@ -271,8 +265,7 @@ static Symbol * init_forderiv(prime) return forderiv; } -static char *name_forderiv(i) - int i; +static char *name_forderiv(int i) { static char name[256]; @@ -288,8 +281,7 @@ static char *name_forderiv(i) /* Scop can handle 's so we put the prime style names into the .var file. We make use of the tools here to reconstruct the original prime name. */ -char *reprime(sym) - Symbol *sym; +char *reprime(Symbol* sym) { static char name[256]; int i; @@ -328,7 +320,7 @@ nrn_assert(snprintf(units, SB, "%s/%s^%d", base_units, STR(indeplist->prev), ind s->usage |= DEP; } if (s->araydim != forderiv->araydim) { - diag(s->name, " must have same dimension as associated state"); + diag(s->name, "must have same dimension as associated state"); } if (!(s->subtype & STAT)) {/* Dstate changes to state */ nrn_assert(snprintf(units, SB, "%s/%s^%d", base_units, STR(indeplist->prev), indx) < SB); @@ -393,8 +385,7 @@ nrn_assert(snprintf(units, SB, "%s/%s^%d", base_units, STR(indeplist->prev), ind message. */ -void add_deriv_imp_list(name) - char *name; +void add_deriv_imp_list(char* name) { if (!deriv_imp_list) { deriv_imp_list = newlist(); @@ -405,9 +396,7 @@ void add_deriv_imp_list(name) static List *deriv_used_list; /* left hand side derivatives of diffeqs */ static List *deriv_state_list; /* states of the derivative equations */ -void deriv_used(s, q1, q2) /* q1, q2 are begin and end tokens for expression */ - Symbol *s; - Item* q1, *q2; +void deriv_used(Symbol* s, Item* q1, Item* q2) /* q1, q2 are begin and end tokens for expression */ { if (!deriv_used_list) { deriv_used_list = newlist(); @@ -426,12 +415,11 @@ void deriv_used(s, q1, q2) /* q1, q2 are begin and end tokens for expression */ static int matchused = 0; /* set when MATCH seen */ /* args are --- derivblk: DERIVATIVE NAME stmtlist '}' */ -void massagederiv(q1, q2, q3, q4, sensused) - Item *q1, *q2, *q3, *q4; int sensused; +void massagederiv(Item* q1, Item* q2, Item* q3, Item* q4, int sensused) { int count = 0, deriv_implicit, solve_seen; char units[SB]; - Item *qs, *q, *mixed_eqns(); + Item *qs, *q, *mixed_eqns(Item* q2, Item* q3, Item* q4); Symbol *s, *derfun, *state; /* to allow verification that definition after SOLVE */ @@ -527,7 +515,7 @@ Sprintf(buf, "static int _slist%d[%d], _dlist%d[%d];\n", lappendstr(procfunc, "return _reset;\n}\n"); /* don't emit _ode_matsol if the user has defined cvodematsol */ - if (!lookup("cvodematsol")) { + if (!lookup( "cvodematsol")) { Item* qq; Item* qextra = q1->next->next->next->next; Sprintf(buf, "static int _ode_matsol%d", numlist); @@ -609,7 +597,7 @@ Sprintf(buf, "static int _slist%d[%d], _dlist%d[%d];\n", Sprintf(buf, "{int _id; for(_id=0; _id < %d; _id++) {\n\ if (_deriv%d_advance) {\n", count, numlist); Insertstr(q4, buf); - sp = install("D", STRING); + sp = install( "D", STRING); sp->araydim = count; /*this breaks SENS*/ q = insertsym(q4, sp); eqnqueue(q); @@ -657,8 +645,7 @@ List *match_bound; /* list of triples or quadruples. in match_bound must be equal to the number of differential equations */ /* we limit ourselves to one matched boundary problem per model */ -void matchinitial(q1) /* name */ - Item *q1; +void matchinitial(Item* q1) /* name */ { /* must be of form state0. Later we can check if state' is in fact used. Save the state symbol in the initialvalue matchlist */ @@ -678,13 +665,11 @@ void matchinitial(q1) /* name */ } } } - diag(s->name, " must be an initial state parameter"); + diag(s->name, "must be an initial state parameter"); return; } -void matchbound(q1, q2, q3, q4, q5, sindex) /* q1name q2'(' q3')' '=' q4exprq5 */ - Item *q1, *q2, *q3, *q4, *q5; - Symbol *sindex; +void matchbound(Item* q1, Item* q2, Item* q3, Item* q4, Item* q5, Symbol* sindex) /* q1name q2'(' q3')' '=' q4exprq5 */ { /* q1 must be a state */ Symbol *state; @@ -693,13 +678,13 @@ void matchbound(q1, q2, q3, q4, q5, sindex) /* q1name q2'(' q3')' '=' q4exprq5 * state = SYM(q1); if (!(state->subtype & STAT) && state->type != PRIME) { - diag(state->name, " is not a state"); + diag(state->name, "is not a state"); } if ((state->subtype & ARRAY) && !sindex) { - diag(state->name, " must have an index for the implicit loop"); + diag(state->name, "must have an index for the implicit loop"); } if (!(state->subtype & ARRAY) && sindex) { - diag(state->name, " is not an array"); + diag(state->name, "is not an array"); } Lappendsym(match_bound, state); @@ -719,7 +704,7 @@ void matchbound(q1, q2, q3, q4, q5, sindex) /* q1name q2'(' q3')' '=' q4exprq5 * } } -void checkmatch(blocktype) int blocktype; { +void checkmatch(int blocktype) { if (blocktype != DERIVATIVE) { diag("MATCH block can only be in DERIVATIVE block", (char *)0); } @@ -729,14 +714,13 @@ void checkmatch(blocktype) int blocktype; { } if (!indepsym) { diag("INDEPENDENT variable must be declared before MATCH", - " statement"); + "statement"); } match_bound = newlist(); match_init = newlist(); } -void matchmassage(nderiv) - int nderiv; +void matchmassage(int nderiv) { int count, nunknown, j; Item *q, *q1, *setup; @@ -792,12 +776,12 @@ void matchmassage(nderiv) s = SYM(q); ITERATE(q1, deriv_state_list) { if (SYM(q1) == s) { - delete(q1); + dlete(q1); break; } } if (!(s->subtype & STAT)) { - diag(s->name, " is not a state"); + diag(s->name, "is not a state"); } if (s->subtype & ARRAY) { count += s->araydim; @@ -823,7 +807,7 @@ Sprintf(buf, "error=shoot(%d, &(%s) - _p, _pmatch_time, _pmatch_value, _state_ma nunknown, indepsym->name, indepsym->name, indepsym->name); /*deltaindep may not be declared yet */ Lappendstr(procfunc, buf); - Lappendstr(procfunc,"\n initmodel(_p); _match_recurse = 1;\n}\n"); + Lappendstr(procfunc, "\n initmodel(_p); _match_recurse = 1;\n}\n"); Sprintf(buf, "for (_i=0; _i<%d; _i++) _p[_state_get[_i]] = _found_init[_i];", nunknown); Lappendstr(procfunc, buf); @@ -858,7 +842,7 @@ static double _match_time[%d], _match_value[%d], _found_init[%d];\n", ITERATE(q, match_bound) { s = SYM(q); if (!(s->subtype & STAT)) { - diag(s->name, " is not a state"); + diag(s->name, "is not a state"); } tmatch = LST(q = q->next); vmatch = LST(q = q->next); @@ -906,9 +890,7 @@ Sprintf(buf, ";\n _match_value[%d] = ", j); } -static void copylist(l, i) /* copy list l before item i */ - List *l; - Item *i; +void copylist(List* l, Item* i) /* copy list l before item i */ { Item *q; @@ -928,8 +910,7 @@ static void copylist(l, i) /* copy list l before item i */ } } -void copyitems(q1, q2, qdest) /* copy items before item */ - Item* q1, *q2, *qdest; +void copyitems(Item* q1, Item* q2, Item* qdest) /* copy items before item */ { Item* q; for (q = q2; q != q1; q = q->prev) { @@ -950,8 +931,8 @@ void copyitems(q1, q2, qdest) /* copy items before item */ } #if CVODE -static int cvode_linear_diffeq(ds, s, qbegin, qend) -Symbol*ds, *s; Item* qbegin, *qend; { +static int cvode_linear_diffeq(Symbol* ds, Symbol* s, Item* qbegin, Item* qend) +{ char* c; List* tlst; Item* q; @@ -988,7 +969,7 @@ Symbol*ds, *s; Item* qbegin, *qend; { } /* DState symbol, begin, and end of expression */ -static void cvode_diffeq(ds, qbegin, qend) Symbol* ds; Item* qbegin, *qend; { +void cvode_diffeq(Symbol* ds, Item* qbegin, Item* qend) { /* try first the assumption of linear. If not, then use numerical diff*/ Symbol* s; Item* q; @@ -1047,13 +1028,13 @@ the solvq item (1st of three). The 0=f(state) equations have already been solved and the rhs for each has been saved. So we know if the translation is possible. */ -int cvode_cnexp_success(q1, q2) Item* q1, *q2; { +int cvode_cnexp_success(Item* q1, Item* q2) { Item* q, *q3, *q4, *qeq; if ( cvode_cnexp_possible) { /* convert Method to nil and the type of the block to PROCEDURE */ SYM(cvode_cnexp_solve->next)->name = stralloc("cnexp", 0); - delete(deriv_imp_list->next); + dlete(deriv_imp_list->next); /* replace the Dstate = f(state) equations */ qeq = cvode_eqn->next; @@ -1085,7 +1066,7 @@ sprintf(buf," %s = %s + (1. - exp(dt*(%s)))*(%s - %s)", q2 = q2->next; for(q3=q1->prev->prev; q3 != q2; q3 = q4) { q4 = q3->next; - delete(q3); + dlete(q3); } } diff --git a/src/nmodl/diffeq.y b/src/nmodl/diffeq.y index 67fc26604c..ebab6aac28 100755 --- a/src/nmodl/diffeq.y +++ b/src/nmodl/diffeq.y @@ -14,7 +14,7 @@ /* every yy gets changed to diffeq_yy before compiling */ static int yylex(), yyparse(); -static void yyerror(); +void yyerror(char*); static int d_invalid, eq_invalid; static char lbuf[4][1000]; static Item* qexpr; /* yylex finds tokens here;*/ @@ -26,10 +26,10 @@ static List* result; #define b3 sprintf(lbuf[2], #define b4 sprintf(lbuf[3], -static void replace(), initbuf(), free4(); -static int zero(); -static char *expr(), *de(), *a(), *b(); -static List* list4(); +void replace(List*), initbuf(), free4(List*); +int zero(char*); +char *expr(List*), *de(List*), *a(List*), *b(List*); +List* list4(char *s1, char *s2, char *s3, char *s4); %} %union { @@ -154,28 +154,28 @@ arg: e { $$ = $1; initbuf(); ; %% -static int zero(cp) char* cp; { + int zero(char* cp) { return (strcmp(cp, "0.0") == 0) ? 1 : 0; } -static char* expr(lst) List* lst; { + char* expr(List* lst) { Item* q = lst->next; return STR(q); } -static char* de(lst) List* lst; { + char* de(List* lst) { Item* q = lst->next->next; return STR(q); } -static char* a(lst) List* lst; { + char* a(List* lst) { Item* q = lst->next->next->next; return STR(q); } -static char* b(lst) List* lst; { +char* b(List* lst) { Item* q = lst->next->next->next->next; return STR(q); } -static void replace(lst) List* lst; { +void replace(List* lst) { int i; Item* q = lst->next; for (i=0; i < 4; ++i) { @@ -190,14 +190,14 @@ lbuf[0], lbuf[1], lbuf[2], lbuf[3]); #endif } -static void initbuf() { +void initbuf() { int i; for (i=0; i < 4; ++i) { strcpy(lbuf[i], "0.0"); } } -static List* list4(s1, s2, s3, s4) char *s1, *s2, *s3, *s4; { +List* list4(char *s1, char *s2, char *s3, char *s4) { List* lst = newlist(); lappendstr(lst, s1); lappendstr(lst, s2); @@ -206,7 +206,7 @@ static List* list4(s1, s2, s3, s4) char *s1, *s2, *s3, *s4; { return lst; } -static void free4(lst) List* lst; { +void free4(List* lst) { Item* q; List* ls = lst; ITERATE(q, lst) { @@ -215,9 +215,9 @@ static void free4(lst) List* lst; { freelist(&ls); } -static void yyerror(s) char* s; { assert(0); } +void yyerror(char* s) { assert(0); } -static void fullname(buf) char* buf; { +static void fullname(char* buf) { /* handle case of name [...] with qexpr pointing to final item */ Item* q = qexpr; strcpy(buf, SYM(q)->name); @@ -299,7 +299,7 @@ fprintf(stderr, "|%s|\n", SYM(qexpr)->name); } /*----------- interface to outside world -------------*/ -void cvode_parse(s, e) Symbol* s; List* e; { +void cvode_parse(Symbol* s, List* e) { state = s; qexpr = e->next; yyparse(); diff --git a/src/nmodl/discrete.c b/src/nmodl/discrete.cpp similarity index 90% rename from src/nmodl/discrete.c rename to src/nmodl/discrete.cpp index 83961a916f..0cfe6a4e94 100755 --- a/src/nmodl/discrete.c +++ b/src/nmodl/discrete.cpp @@ -59,9 +59,7 @@ discrete.c,v #include "parse1.h" #include "symbol.h" -void disc_var_seen(q1, q2, q3, array) /*NAME '@' NUMBER --- array flag*/ - Item *q1, *q2, *q3; - int array; +void disc_var_seen(Item* q1, Item* q2, Item* q3, int array) /*NAME '@' NUMBER --- array flag*/ { Symbol *s; int num; @@ -73,26 +71,25 @@ void disc_var_seen(q1, q2, q3, array) /*NAME '@' NUMBER --- array flag*/ } num--; if (!(s->subtype & STAT)) { - diag(s->name, " must be a STATE for use as discrete variable"); + diag(s->name, "must be a STATE for use as discrete variable"); } if (array && !(s->subtype & ARRAY)) { - diag(s->name, " must be a scalar discrete variable"); + diag(s->name, "must be a scalar discrete variable"); } if (!array && (s->subtype & ARRAY)) { - diag(s->name, " must be an array discrete variable"); + diag(s->name, "must be an array discrete variable"); } if (s->discdim <= num) { s->discdim = num+1; } Sprintf(buf, "__%s", s->name); replacstr(q1, buf); - delete(q2); + dlete(q2); Sprintf(buf, "[%d]", num); replacstr(q3, buf); } -void massagediscblk(q1, q2, q3, q4) /*DISCRETE NAME stmtlist '}'*/ - Item *q1, *q2, *q3, *q4; +void massagediscblk(Item* q1, Item* q2, Item* q3, Item* q4) /*DISCRETE NAME stmtlist '}'*/ { int i; Symbol *s; diff --git a/src/nmodl/extdef5.h b/src/nmodl/extdef5.h index 850e79729d..fb3170b6b8 100755 --- a/src/nmodl/extdef5.h +++ b/src/nmodl/extdef5.h @@ -1,4 +1,4 @@ -"force", +(char*)"force", "deflate", "expfit", "derivs", diff --git a/src/nmodl/init.c b/src/nmodl/init.c deleted file mode 100755 index cfc2dd27a4..0000000000 --- a/src/nmodl/init.c +++ /dev/null @@ -1,254 +0,0 @@ -#include <../../nmodlconf.h> -/* /local/src/master/nrn/src/nmodl/init.c,v 4.5 1998/03/25 14:33:42 hines Exp */ - -#include "modl.h" -#include "parse1.h" - -extern List *firstlist; -extern List *syminorder; -Symbol *semi, *beginblk, *endblk; -List *intoken; -char buf[NRN_BUFSIZE]; /* volatile temporary buffer */ - -static struct { /* Keywords */ - char *name; - short kval; -} keywords[] = { - "VERBATIM", VERBATIM, - "COMMENT", COMMENT, - "TITLE", MODEL, - "CONSTANT", CONSTANT, - "PARAMETER", PARAMETER, - "INDEPENDENT", INDEPENDENT, - "ASSIGNED", DEPENDENT, - "INITIAL", INITIAL1, - "TERMINAL", TERMINAL, - "DERIVATIVE", DERIVATIVE, - "EQUATION", EQUATION, - "BREAKPOINT", BREAKPOINT, - "CONDUCTANCE", CONDUCTANCE, - "SOLVE", SOLVE, - "STATE", STATE, - "STEPPED", STEPPED, - "LINEAR", LINEAR, - "NONLINEAR", NONLINEAR, - "DISCRETE", DISCRETE, - "FUNCTION", FUNCTION1, - "FUNCTION_TABLE", FUNCTION_TABLE, - "PROCEDURE", PROCEDURE, - "PARTIAL", PARTIAL, - "INT", INT, - "DEL2", DEL2, - "DEL", DEL, - "LOCAL", LOCAL, - "METHOD", USING, - "STEADYSTATE", USING, - "SENS", SENS, - "STEP", STEP, - "WITH", WITH, - "FROM", FROM, - "FORALL", FORALL1, - "TO", TO, - "BY", BY, - "if", IF, - "else", ELSE, - "while", WHILE, - "START", START1, - "DEFINE", DEFINE1, - - "KINETIC", KINETIC, - "CONSERVE", CONSERVE, - "PLOT", PLOT, - "VS", VS, - "LAG", LAG, - "RESET", RESET, - "MATCH", MATCH, - "MODEL_LEVEL", MODEL_LEVEL, /* inserted by merge */ - "SWEEP", SWEEP, - "FIRST", FIRST, - "LAST", LAST, - "COMPARTMENT", COMPARTMENT, - "LONGITUDINAL_DIFFUSION", LONGDIFUS, - "PUTQ", PUTQ, - "GETQ", GETQ, - "IFERROR", IFERROR, - "SOLVEFOR", SOLVEFOR, - "UNITS", UNITS, - "UNITSON", UNITSON, - "UNITSOFF", UNITSOFF, - "TABLE", TABLE, - "DEPEND", DEPEND, - "NEURON", NEURON, - "SUFFIX", SUFFIX, - "POINT_PROCESS", SUFFIX, - "ARTIFICIAL_CELL", SUFFIX, - "NONSPECIFIC_CURRENT", NONSPECIFIC, - "ELECTRODE_CURRENT", ELECTRODE_CURRENT, - "SECTION", SECTION, - "RANGE", RANGE, - "USEION", USEION, - "READ", READ, - "WRITE", WRITE, - "VALENCE", VALENCE, - "CHARGE", VALENCE, - "GLOBAL", GLOBAL, - "POINTER", POINTER, - "BBCOREPOINTER", BBCOREPOINTER, - "EXTERNAL", EXTERNAL, - "INCLUDE", INCLUDE1, - "CONSTRUCTOR", CONSTRUCTOR, - "DESTRUCTOR", DESTRUCTOR, - "NET_RECEIVE", NETRECEIVE, - "BEFORE", BEFORE, /* before NEURON sets up cy' = f(y,t) */ - "AFTER", AFTER, /* after NEURON solves cy' = f(y, t) */ - "WATCH", WATCH, - "FOR_NETCONS", FOR_NETCONS, - "THREADSAFE", THREADSAFE, - "PROTECT", PROTECT, - "MUTEXLOCK", NRNMUTEXLOCK, - "MUTEXUNLOCK", NRNMUTEXUNLOCK, - "REPRESENTS", REPRESENTS, - 0, 0 -}; - -/* - * the following special output tokens are used to make the .c file barely - * readable - */ -static struct { /* special output tokens */ - char *name; - short subtype; - Symbol **p; -} special[] = { - ";", SEMI, &semi, - "{", BEGINBLK, &beginblk, - "}", ENDBLK, &endblk, - 0, 0, 0 -}; - -static struct { /* numerical methods */ - char *name; - long subtype; /* All the types that will work with this */ - short varstep; -} methods[] = { - "adams", DERF | KINF, 0, - "runge", DERF | KINF, 0, - "euler", DERF | KINF, 0, - "adeuler", DERF | KINF, 1, - "heun", DERF | KINF, 0, - "adrunge", DERF | KINF, 1, - "gear", DERF | KINF, 1, - "newton", NLINF, 0, - "simplex", NLINF, 0, - "simeq", LINF, 0, - "seidel", LINF, 0, - "_advance", KINF, 0, - "sparse", KINF, 0, - "derivimplicit", DERF, 0, /* name hard wired in deriv.c */ - "cnexp", DERF, 0, /* see solve.c */ - "clsoda", DERF | KINF, 1, /* Tolerance built in to -scopgear.c */ - "after_cvode", 0, 0, - "cvode_t", 0, 0, - "cvode_t_v", 0, 0, - 0, 0, 0 -}; - -static char *extdef[] = { /* external names that can be used as doubles - * without giving an error message */ -#include "extdef.h" - 0 -}; - -static char *extdef2[] = { /* external function names that can be used - * with array and function name arguments */ -#include "extdef2.h" - 0 -}; - -static char *extdef3[] = { /* function names that get two reset arguments - * added */ - "threshold", - "squarewave", - "sawtooth", - "revsawtooth", - "ramp", - "pulse", - "perpulse", - "step", - "perstep", - "stepforce", - "schedule", - 0 -}; - -static char *extdef4[] = { /* functions that need a first arg of NrnThread* */ - "at_time", - 0 -}; - -static char *extdef5[] = { /* the extdef names that are not threadsafe */ -#include "extdef5.h" - 0 -}; - -List *constructorfunc, *destructorfunc; - -void init() -{ - int i; - Symbol *s; - - symbol_init(); - for (i = 0; keywords[i].name; i++) { - s = install(keywords[i].name, keywords[i].kval); - s->subtype = KEYWORD; - } - for (i = 0; methods[i].name; i++) { - s = install(methods[i].name, METHOD); - s->subtype = methods[i].subtype; - s->u.i = methods[i].varstep; - } - for (i = 0; special[i].name; i++) { - s = install(special[i].name, SPECIAL); - *(special[i].p) = s; - s->subtype = special[i].subtype; - } - for (i = 0; extdef[i]; i++) { - s = install(extdef[i], NAME); - s->subtype = EXTDEF; - } - for (i = 0; extdef2[i]; i++) { - s = install(extdef2[i], NAME); - s->subtype = EXTDEF2; - } - for (i = 0; extdef3[i]; i++) { - s = lookup(extdef3[i]); - assert(s && (s->subtype & EXTDEF)); - s->subtype |= EXTDEF3; - } - for (i = 0; extdef4[i]; i++) { - s = lookup(extdef4[i]); - assert(s && (s->subtype & EXTDEF)); - s->subtype |= EXTDEF4; - } - for (i = 0; extdef5[i]; i++) { - s = lookup(extdef5[i]); - assert(s); - s->subtype |= EXTDEF5; - } - intoken = newlist(); - initfunc = newlist(); - modelfunc = newlist(); - termfunc = newlist(); - procfunc = newlist(); - initlist = newlist(); - firstlist = newlist(); - syminorder = newlist(); - plotlist = newlist(); - constructorfunc = newlist(); - destructorfunc = newlist(); -#if NMODL - nrninit(); -#endif -} diff --git a/src/nmodl/init.cpp b/src/nmodl/init.cpp new file mode 100755 index 0000000000..ae74764602 --- /dev/null +++ b/src/nmodl/init.cpp @@ -0,0 +1,252 @@ +#include <../../nmodlconf.h> +/* /local/src/master/nrn/src/nmodl/init.c,v 4.5 1998/03/25 14:33:42 hines Exp */ + +#include "modl.h" +#include "parse1.h" + +extern List *firstlist; +extern List *syminorder; +Symbol *semi, *beginblk, *endblk; +List *intoken; +char buf[NRN_BUFSIZE]; /* volatile temporary buffer */ + +static struct { /* Keywords */ + char *name; + short kval; +} keywords[] = { + "VERBATIM", VERBATIM, + "COMMENT", COMMENT, + "TITLE", MODEL, + "CONSTANT", CONSTANT, + "PARAMETER", PARAMETER, + "INDEPENDENT", INDEPENDENT, + "ASSIGNED", DEPENDENT, + "INITIAL", INITIAL1, + "TERMINAL", TERMINAL, + "DERIVATIVE", DERIVATIVE, + "EQUATION", EQUATION, + "BREAKPOINT", BREAKPOINT, + "CONDUCTANCE", CONDUCTANCE, + "SOLVE", SOLVE, + "STATE", STATE, + "STEPPED", STEPPED, + "LINEAR", LINEAR, + "NONLINEAR", NONLINEAR, + "DISCRETE", DISCRETE, + "FUNCTION", FUNCTION1, + "FUNCTION_TABLE", FUNCTION_TABLE, + "PROCEDURE", PROCEDURE, + "PARTIAL", PARTIAL, + "INT", INT, + "DEL2", DEL2, + "DEL", DEL, + "LOCAL", LOCAL, + "METHOD", USING, + "STEADYSTATE", USING, + "SENS", SENS, + "STEP", STEP, + "WITH", WITH, + "FROM", FROM, + "FORALL", FORALL1, + "TO", TO, + "BY", BY, + "if", IF, + "else", ELSE, + "while", WHILE, + "START", START1, + "DEFINE", DEFINE1, + "KINETIC", KINETIC, + "CONSERVE", CONSERVE, + "PLOT", PLOT, + "VS", VS, + "LAG", LAG, + "RESET", RESET, + "MATCH", MATCH, + "MODEL_LEVEL", MODEL_LEVEL, /* inserted by merge */ + "SWEEP", SWEEP, + "FIRST", FIRST, + "LAST", LAST, + "COMPARTMENT", COMPARTMENT, + "LONGITUDINAL_DIFFUSION", LONGDIFUS, + "PUTQ", PUTQ, + "GETQ", GETQ, + "IFERROR", IFERROR, + "SOLVEFOR", SOLVEFOR, + "UNITS", UNITS, + "UNITSON", UNITSON, + "UNITSOFF", UNITSOFF, + "TABLE", TABLE, + "DEPEND", DEPEND, + "NEURON", NEURON, + "SUFFIX", SUFFIX, + "POINT_PROCESS", SUFFIX, + "ARTIFICIAL_CELL", SUFFIX, + "NONSPECIFIC_CURRENT", NONSPECIFIC, + "ELECTRODE_CURRENT", ELECTRODE_CURRENT, + "SECTION", SECTION, + "RANGE", RANGE, + "USEION", USEION, + "READ", READ, + "WRITE", WRITE, + "VALENCE", VALENCE, + "CHARGE", VALENCE, + "GLOBAL", GLOBAL, + "POINTER", POINTER, + "BBCOREPOINTER", BBCOREPOINTER, + "EXTERNAL", EXTERNAL, + "INCLUDE", INCLUDE1, + "CONSTRUCTOR", CONSTRUCTOR, + "DESTRUCTOR", DESTRUCTOR, + "NET_RECEIVE", NETRECEIVE, + "BEFORE", BEFORE, /* before NEURON sets up cy' = f(y,t) */ + "AFTER", AFTER, /* after NEURON solves cy' = f(y, t) */ + "WATCH", WATCH, + "FOR_NETCONS", FOR_NETCONS, + "THREADSAFE", THREADSAFE, + "PROTECT", PROTECT, + "MUTEXLOCK", NRNMUTEXLOCK, + "MUTEXUNLOCK", NRNMUTEXUNLOCK, + "REPRESENTS", REPRESENTS, + 0, 0 +}; + +/* + * the following special output tokens are used to make the .c file barely + * readable + */ +static struct { /* special output tokens */ + char *name; + short subtype; + Symbol **p; +} special[] = { + ";", SEMI, &semi, + "{", BEGINBLK, &beginblk, + "}", ENDBLK, &endblk, + 0, 0, 0 +}; + +static struct { /* numerical methods */ + char *name; + long subtype; /* All the types that will work with this */ + short varstep; +} methods[] = { + "adams", DERF | KINF, 0, + "runge", DERF | KINF, 0, + "euler", DERF | KINF, 0, + "adeuler", DERF | KINF, 1, + "heun", DERF | KINF, 0, + "adrunge", DERF | KINF, 1, + "gear", DERF | KINF, 1, + "newton", NLINF, 0, + "simplex", NLINF, 0, + "simeq", LINF, 0, + "seidel", LINF, 0, + "_advance", KINF, 0, + "sparse", KINF, 0, + "derivimplicit", DERF, 0, /* name hard wired in deriv.c */ + "cnexp", DERF, 0, /* see solve.c */ + "clsoda", DERF | KINF, 1, /* Tolerance built in to scopgear.c */ + "after_cvode", 0, 0, + "cvode_t", 0, 0, + "cvode_t_v", 0, 0, + 0, 0, 0 +}; + +static char *extdef[] = { /* external names that can be used as doubles + * without giving an error message */ +#include "extdef.h" + 0 +}; + +static char *extdef2[] = { /* external function names that can be used + * with array and function name arguments */ +#include "extdef2.h" + 0 +}; + +static char *extdef3[] = { /* function names that get two reset arguments + * added */ + "threshold", + "squarewave", + "sawtooth", + "revsawtooth", + "ramp", + "pulse", + "perpulse", + "step", + "perstep", + "stepforce", + "schedule", + 0 +}; + +static char *extdef4[] = { /* functions that need a first arg of NrnThread* */ + "at_time", + 0 +}; + +static char *extdef5[] = { /* the extdef names that are not threadsafe */ +#include "extdef5.h" + 0 +}; + +List *constructorfunc, *destructorfunc; + +void init() +{ + int i; + Symbol *s; + + symbol_init(); + for (i = 0; keywords[i].name; i++) { + s = install(keywords[i].name, keywords[i].kval); + s->subtype = KEYWORD; + } + for (i = 0; methods[i].name; i++) { + s = install(methods[i].name, METHOD); + s->subtype = methods[i].subtype; + s->u.i = methods[i].varstep; + } + for (i = 0; special[i].name; i++) { + s = install(special[i].name, SPECIAL); + *(special[i].p) = s; + s->subtype = special[i].subtype; + } + for (i = 0; extdef[i]; i++) { + s = install(extdef[i], NAME); + s->subtype = EXTDEF; + } + for (i = 0; extdef2[i]; i++) { + s = install(extdef2[i], NAME); + s->subtype = EXTDEF2; + } + for (i = 0; extdef3[i]; i++) { + s = lookup(extdef3[i]); + assert(s && (s->subtype & EXTDEF)); + s->subtype |= EXTDEF3; + } + for (i = 0; extdef4[i]; i++) { + s = lookup(extdef4[i]); + assert(s && (s->subtype & EXTDEF)); + s->subtype |= EXTDEF4; + } + for (i = 0; extdef5[i]; i++) { + s = lookup(extdef5[i]); + assert(s); + s->subtype |= EXTDEF5; + } + intoken = newlist(); + initfunc = newlist(); + modelfunc = newlist(); + termfunc = newlist(); + procfunc = newlist(); + initlist = newlist(); + firstlist = newlist(); + syminorder = newlist(); + plotlist = newlist(); + constructorfunc = newlist(); + destructorfunc = newlist(); +#if NMODL + nrninit(); +#endif +} diff --git a/src/nmodl/io.c b/src/nmodl/io.cpp similarity index 92% rename from src/nmodl/io.c rename to src/nmodl/io.cpp index fe06997227..3cb0a53c08 100755 --- a/src/nmodl/io.c +++ b/src/nmodl/io.cpp @@ -10,7 +10,7 @@ #undef METHOD #include "parse1.h" -static int isend(); +int isend(char*, char*); static void pop_file_stack(); static int file_stack_empty(); int in_comment_; @@ -45,8 +45,7 @@ char *inputline() static int linenum = 0; -void inblock(s) - char *s; +void inblock(char* s) { /* copy input verbatim to intoken up to END*s * error if we get the whole input */ char *cp; @@ -58,7 +57,7 @@ void inblock(s) cp = Gets(buf); if (cp == (char *) 0) { linenum = l; - diag(s, " block goes to end of file"); + diag(s, "block goes to end of file"); } if (isend(s, buf)) { break; @@ -68,8 +67,7 @@ void inblock(s) } } -static int isend(s, buf) - char *s, *buf; +int isend(char* s, char* buf) { /* if first chars in buf form a keyword return 1 */ char *cp, word[256], *wp, test[256]; @@ -100,7 +98,7 @@ static int isend(s, buf) static char inlinebuf[2][NRN_BUFSIZE], *inlinep = inlinebuf[0] + 30, *ctp = inlinebuf[0] + 30; static int whichbuf; -char* Fgets(buf, size, f) char* buf; int size; FILE* f; { +char* Fgets(char* buf, int size, FILE* f) { char* p = buf; int c, i; for(i=0; i < size; ++ i) { @@ -168,8 +166,7 @@ int Getc() return c; } -int unGetc(c) - int c; +int unGetc(int c) { if (c == EOF) return c; @@ -182,8 +179,7 @@ int unGetc(c) return c; } -char *Gets(buf) - char *buf; +char *Gets(char* buf) { char *cp; int c; @@ -205,9 +201,8 @@ char *Gets(buf) } #if 0 /* not currently used */ -void unGets(buf) /* all this because we don't have an ENDBLOCK +void unGets(char* buf) /* all this because we don't have an ENDBLOCK * keyword */ - char *buf; { if (ctp != '\0') { /* can only be called after successful Gets */ Strcpy(inlinep, buf); @@ -235,8 +230,7 @@ char* current_line() { /* assumes we actually want the previous line */ } /* two arguments so we can pass a name to construct an error message. */ -void diag(s1, s2) - char *s1, *s2; +void diag(char* s1, char* s2) { char *cp; Fprintf(stderr, "%s", s1); @@ -274,8 +268,7 @@ static Symbol *symq[20], **symhead = symq, **symtail = symq; * meaningful models. It was this insanity which prompted us to allow use of * variables before declaration */ -void enquextern(sym) - Symbol *sym; +void enquextern(Symbol* sym) { *symtail++ = sym; } @@ -311,8 +304,7 @@ typedef struct FileStackItem { static List* filestack; -static int getprefix(prefix, s) - char* prefix, *s; +static int getprefix(char* prefix, char* s) { char* cp; strcpy(prefix, s); @@ -325,9 +317,7 @@ static int getprefix(prefix, s) return (prefix[0] != '\0'); } -static FILE* include_open(fname, err) - char* fname; - int err; +static FILE* include_open(char* fname, int err) { FILE* f = (FILE*)0; FileStackItem* fsi; @@ -341,7 +331,7 @@ static FILE* include_open(fname, err) } fsi = (FileStackItem*)(SYM(filestack->prev)); - buf = emalloc(NRN_BUFSIZE); + buf = static_cast(emalloc(NRN_BUFSIZE)); if (getprefix(buf, fsi->finname)) { strcat(buf, fname); f = fopen(buf, "r"); /* first try in directory of last file */ @@ -381,7 +371,7 @@ static FILE* include_open(fname, err) break; } } - buf2 = emalloc(strlen(dirs) + 2 + strlen(fname)); + buf2 = static_cast(emalloc(strlen(dirs) + 2 + strlen(fname))); strcpy(buf2, dirs); strcat(buf2, "/"); strcat(buf2, fname); @@ -400,8 +390,7 @@ static FILE* include_open(fname, err) return f; } -void include_file(q) - Item* q; +void include_file(Item* q) { char* pf = NULL; char fname[NRN_BUFSIZE]; @@ -448,13 +437,13 @@ static void pop_file_stack() { lappendstr(filetxtlist, buf); FileStackItem* fsi; fsi = (FileStackItem*)(SYM(filestack->prev)); - delete(filestack->prev); + dlete(filestack->prev); linenum = fsi->linenum; inlinep = fsi->inlinep; fclose(fin); fin = fsi->fp; strcpy(finname, fsi->finname); - free((char*)fsi); + free(fsi); } static int file_stack_empty() { diff --git a/src/nmodl/kinetic.c b/src/nmodl/kinetic.cpp similarity index 93% rename from src/nmodl/kinetic.c rename to src/nmodl/kinetic.cpp index 9a4931dc7d..f1eb435ec0 100755 --- a/src/nmodl/kinetic.c +++ b/src/nmodl/kinetic.cpp @@ -97,11 +97,11 @@ its info. */ extern int sens_parm; -static int genconservterms(); -static int number_states(); -static void kinlist(); -static void genderivterms(); -static void genmatterms(); +int genconservterms(int eqnum, Reaction* r, int fn, Rlist* rlst); +int number_states(Symbol* fun, Rlist** prlst, Rlist** pclst); +void kinlist(Symbol* fun, Rlist* rlst); +void genderivterms(Reaction* r, int type, int n); +void genmatterms(Reaction* r, int fn); #define MAXKINBLK 20 static int nstate_[MAXKINBLK]; @@ -117,13 +117,12 @@ static char* instance_loop() { #endif static int sparse_declared_[10]; -static int sparsedeclared(i) int i; { +static int sparsedeclared(int i) { assert(i < 10); return sparse_declared_[i]++; } -char *qconcat(q1, q2) /* return names as single string */ - Item *q1, *q2; +char *qconcat(Item* q1, Item* q2) /* return names as single string */ { char *cp, *ovrfl, *cs, *n; cp = buf; ovrfl = buf+400; @@ -151,8 +150,7 @@ char *qconcat(q1, q2) /* return names as single string */ return stralloc(buf, (char *)0); } -void reactname(q1, lastok, q2) /* NAME [] INTEGER q2 may be null*/ - Item *q1, *lastok, *q2; +void reactname(Item* q1, Item* lastok, Item* q2) /* NAME [] INTEGER q2 may be null*/ { /* put on right hand side */ Symbol *s, *s1; Rterm *rnext; @@ -169,7 +167,7 @@ void reactname(q1, lastok, q2) /* NAME [] INTEGER q2 may be null*/ s->used++; rterm->isstate = 1; } else if (!(s->subtype & (DEP | nmodlCONST | PARM | INDEP | STEP1 | STAT)) ) { -diag(s->name, " must be a STATE, CONSTANT, ASSIGNED, STEPPED, or INDEPENDENT"); +diag(s->name, "must be a STATE, CONSTANT, ASSIGNED, STEPPED, or INDEPENDENT"); } if (q2) { rterm->num = atoi(STR(q2)); @@ -198,8 +196,7 @@ void leftreact() /* current reaction list is for left hand side */ rterm = (Rterm *)0; } -void massagereaction(qREACTION, qREACT1, qlpar, qcomma, qrpar) - Item *qREACTION, *qREACT1, *qlpar, *qcomma, *qrpar; +void massagereaction(Item* qREACTION, Item* qREACT1, Item* qlpar, Item* qcomma, Item* qrpar) { Reaction *r1; @@ -221,8 +218,7 @@ void massagereaction(qREACTION, qREACT1, qlpar, qcomma, qrpar) rterm = (Rterm *)0; } -void flux(qREACTION, qdir, qlast) - Item *qREACTION, *qdir, *qlast; +void flux(Item* qREACTION, Item* qdir, Item* qlast) { Reaction *r1; @@ -297,9 +293,7 @@ ITERATE(q1, ldifuslist) { we therefore loop through all the rterms and mark only those */ -void massagekinetic(q1, q2, q3, q4, sensused) /*KINETIC NAME stmtlist '}'*/ - Item *q1, *q2, *q3,*q4; - int sensused; +void massagekinetic(Item* q1, Item* q2, Item* q3, Item* q4, int sensused) /*KINETIC NAME stmtlist '}'*/ { int count = 0, i, order, ncons; Item *q, *qs, *afterbrace; @@ -494,8 +488,7 @@ rlist->capacity[SYM(q1)->used - 1] = stralloc(buf1, (char *)0); } #if Glass -void fixrlst(rlst) - Rlist *rlst; +void fixrlst(Rlist* rlst) { if(rlst->position->prev->itemtype==STRING && !strcmp(rlst->position->prev->element.str,"error =")) { @@ -506,9 +499,7 @@ void fixrlst(rlst) static int ncons; /* the number of conservation equations */ -void kinetic_intmethod(fun, meth) - Symbol *fun; - char* meth; +void kinetic_intmethod(Symbol* fun, char* meth) { /*derivative form*/ Reaction *r1; @@ -547,10 +538,7 @@ Insertstr(rlst->endbrace, buf); kinlist(fun, rlst); } -static void genderivterms(r, type, n) - Reaction *r; - int type; /* 0 derivative, 1 implicit */ - int n; /* function number, needed only for implicit */ +void genderivterms(Reaction* r, int type, int n) { Symbol *s; Item *q; @@ -626,10 +614,7 @@ for (j=0; j<2; j++) { Insertstr(q, "\n"); /* REACTION comment left in */ } -void genfluxterm(r, type, n) - Reaction *r; - int type; - int n; +void genfluxterm(Reaction* r, int type, int n) { Symbol *s; Rterm *rt; @@ -638,12 +623,12 @@ void genfluxterm(r, type, n) q = r->position; rt = r->rterm[0]; if (!(rt->isstate)) { - diag(rt->sym->name, " must be (solved) STATE in flux reaction"); + diag(rt->sym->name, "must be (solved) STATE in flux reaction"); } Sprintf(buf, "D%s", rt->sym->name); s = lookup(buf); if (rt->sym->varnum < ncons) - diag(rt->sym->name, " is conserved and has a flux"); + diag(rt->sym->name, "is conserved and has a flux"); /* the right hand side */ Insertstr(q, "f_flux = b_flux = 0.;\n"); if (type) { @@ -694,9 +679,7 @@ void genfluxterm(r, type, n) } static int linmat; /* 1 if linear */ -void kinetic_implicit(fun, dt, mname) - Symbol *fun; - char *dt, *mname; /* mname is _advance or sparse */ +void kinetic_implicit(Symbol* fun, char* dt, char* mname) { /*implicit equations _slist are state(t+dt) _dlist are Dstate(t)*/ Item *q; @@ -750,7 +733,7 @@ void kinetic_implicit(fun, dt, mname) } if (rlst->sens_parm) { diag(" SENS unimplemented for default kinetic integration", - " method"); + "method"); } /*goes near beginning of block. Before first reaction is not adequate since the first reaction may be within a while loop */ @@ -933,9 +916,7 @@ Insertstr(rlst->position, "}"); } /* end of NOT_CVODE_FLAG */ } -static void genmatterms(r, fn) - Reaction *r; - int fn; /*function number, numlist*/ +void genmatterms(Reaction* r, int fn) { Symbol *s, *s1; Item *q; @@ -1016,8 +997,7 @@ static void genmatterms(r, fn) /* REACTION comment left in */ } -void massageconserve(q1, q3, q5) /* CONSERVE react '=' expr */ - Item *q1, *q3, *q5; +void massageconserve(Item* q1, Item* q3, Item* q5) /* CONSERVE react '=' expr */ { /* the list of states is in rterm at this time with the first at the end */ Reaction *r1; @@ -1047,10 +1027,7 @@ void massageconserve(q1, q3, q5) /* CONSERVE react '=' expr */ rterm = (Rterm *)0; } -static int genconservterms(eqnum, r, fn, rlst) - Reaction *r; - int eqnum, fn; /*function number*/ - Rlist *rlst; +int genconservterms(int eqnum, Reaction* r, int fn, Rlist* rlst) { Item *q; Rterm *rt, *rtdiag; @@ -1113,9 +1090,7 @@ diag(rt->sym->name, ": only (solved) STATE are allowed in CONSERVE equations."); return eqnum; } -static int number_states(fun, prlst, pclst) - Symbol *fun; - Rlist **prlst, **pclst; +int number_states(Symbol* fun, Rlist** prlst, Rlist** pclst) { /* reaction list has the symorder and this info is put back in sym->varnum*/ /* also index of symorder goes into sym->used */ @@ -1128,7 +1103,7 @@ static int number_states(fun, prlst, pclst) for (rlst = rlist; rlst && (rlst->sym != fun); rlst = rlst->rlistnext) clst = clst->rlistnext; if (rlst == (Rlist *)0) { - diag(fun->name, " doesn't exist"); + diag(fun->name, "doesn't exist"); } *prlst = rlst; *pclst = clst; @@ -1151,9 +1126,7 @@ static int number_states(fun, prlst, pclst) return istate; } -static void kinlist(fun, rlst) - Symbol *fun; - Rlist *rlst; +void kinlist(Symbol* fun, Rlist* rlst) { int i; Symbol *s; @@ -1217,12 +1190,10 @@ if (vectorize){ } /* for now we only check CONSERVE and COMPARTMENT */ -void check_block(standard, actual, mes) - int standard, actual; - char *mes; +void check_block(int standard, int actual, char* mes) { if (standard != actual) { - diag(mes, " not allowed in this kind of block"); + diag(mes, "not allowed in this kind of block"); } } @@ -1231,7 +1202,7 @@ compart: COMPARTMENT NAME ',' expr '{' namelist '}' {massagecompart($4, $5, $7, SYM($2));} | COMPARTMENT expr '{' namelist '}' {massagecompart($2, $3, $5, SYM0);} - | COMPARTMENT error {myerr("Correct syntax is: \ + | COMPARTMENT error {myerr( "Correct syntax is: \ COMPARTMENT index, expr { vectorstates }\n\ COMPARTMENT expr { scalarstates }");} ; @@ -1248,9 +1219,7 @@ COMPARTMENT index, expr { vectorstates }\n\ compartlist is a list of triples of item pointers which holds the info for massagekinetic. */ -void massagecompart(qexp, qb1, qb2, indx) - Item *qexp, *qb1, *qb2; - Symbol *indx; +void massagecompart(Item* qexp, Item* qb1, Item* qb2, Symbol* indx) { Item *q, *qs; @@ -1274,7 +1243,7 @@ void massagecompart(qexp, qb1, qb2, indx) for (q = qb1->next; q != qb2; q = qs) { qs = q->next; if (!(SYM(q)->subtype & STAT) && in_solvefor(SYM(q))) { - delete(q); + dlete(q); #if 0 diag(SYM(q)->name, "must be a (solved) STATE in a COMPARTMENT statement"); #endif @@ -1288,9 +1257,7 @@ diag(SYM(q)->name, "must be a (solved) STATE in a COMPARTMENT statement"); Lappenditem(compartlist, qb2); } -void massageldifus(qexp, qb1, qb2, indx) - Item *qexp, *qb1, *qb2; - Symbol *indx; +void massageldifus(Item* qexp, Item* qb1, Item* qb2, Symbol* indx) { Item *q, *qs, *q1; Symbol* s, *s2; @@ -1320,7 +1287,7 @@ void massageldifus(qexp, qb1, qb2, indx) s = SYM(q); s2 = SYM0; if (!(s->subtype & STAT) && in_solvefor(s)) { - delete(q); + dlete(q); diag(SYM(q)->name, "must be a (solved) STATE in a LONGITUDINAL_DIFFUSION statement"); } lappendsym(ldifuslist, s); @@ -1355,8 +1322,7 @@ diag(SYM(q)->name, "must be a (solved) STATE in a LONGITUDINAL_DIFFUSION stateme static List* kvect; -void kin_vect1(q1, q2, q4) - Item *q1, *q2, *q4; +void kin_vect1(Item* q1, Item* q2, Item* q4) { if (!kvect) { kvect = newlist(); @@ -1380,11 +1346,10 @@ void kin_vect2() { } -void kin_vect3(q1, q2, q4) - Item *q1, *q2, *q4; +void kin_vect3(Item* q1, Item* q2, Item* q4) { Symbol* fun; - Item *q, *first, *last, *insertitem(); + Item *q, *first, *last, *insertitem(Item* item, Item* itm); fun = SYM(q2); last = insertstr(q4->next, "\n"); first = insertstr(last, "\n/*copy of previous function */\n"); @@ -1429,8 +1394,7 @@ void see_ostmt() { #endif } -void see_astmt(q1, q2) - Item *q1, *q2; +void see_astmt(Item* q1, Item* q2) { #if 0 && VECTORIZE Item* q; @@ -1445,7 +1409,7 @@ void see_astmt(q1, q2) #endif } -void vectorize_if_else_stmt(blocktype) int blocktype; { +void vectorize_if_else_stmt(int blocktype) { #if 0 && VECTORIZE if (blocktype == KINETIC && vectorize) { vectorize = 0; @@ -1467,13 +1431,13 @@ prn(cvode_sbegin, cvode_send); while (ITM(q) != q2) { assert(q2 != cvode_send); /* past the list */ q2 = q2->next; - delete(q2->prev); + dlete(q2->prev); } q2 = q2->next; } } -void prn(q1,q2) Item *q1, *q2; { +void prn(Item* q1, Item* q2) { Item* qq, *q; for (qq = q1; qq != q2; qq=qq->next) { if (qq->itemtype == ITEM) { @@ -1499,10 +1463,7 @@ break; } } -void cvode_kinetic(qsol, fun, numeqn, listnum) - Item* qsol; - Symbol* fun; - int numeqn, listnum; +void cvode_kinetic(Item* qsol, Symbol* fun, int numeqn, int listnum) { #if 1 Item* qn; @@ -1514,7 +1475,7 @@ void cvode_kinetic(qsol, fun, numeqn, listnum) if (done_list) for (q = done_list->next; q != done_list; q = qn) { qn = q->next; if (SYM(q) == fun) { - delete(q); + dlete(q); } } kinetic_intmethod(fun, "NEURON's CVode"); @@ -1568,11 +1529,11 @@ void cvode_kinetic(qsol, fun, numeqn, listnum) /* delete the statement */ while (q->itemtype != SYMBOL || SYM(q)->name[0] != ';') { qnext = q->next; - delete(q); + dlete(q); q = qnext; } qnext = q->next; - delete(q); + dlete(q); } } #endif @@ -1581,10 +1542,7 @@ void cvode_kinetic(qsol, fun, numeqn, listnum) #endif } -void single_channel(qsol, fun, numeqn, listnum) - Item* qsol; - Symbol* fun; - int numeqn, listnum; +void single_channel(Item* qsol, Symbol* fun, int numeqn, int listnum) { Rlist *rlst, *clst; int nstate, i; @@ -1683,11 +1641,11 @@ return; /* delete the statement */ while (q->itemtype != SYMBOL || SYM(q)->name[0] != ';') { qnext = q->next; - delete(q); + dlete(q); q = qnext; } qnext = q->next; - delete(q); + dlete(q); } } #endif diff --git a/src/nmodl/lex.l b/src/nmodl/lex.l index d758a8ec0c..eff6227656 100755 --- a/src/nmodl/lex.l +++ b/src/nmodl/lex.l @@ -23,10 +23,71 @@ int lexcontext = 0; extern int Getc(); -extern int unGetc(); -extern int unput(); +extern int unGetc(int); +extern int unput(int); +static int input(); +static int yyinput(); +//TODO - does this actually work? +int newinput() { + #ifdef __cplusplus + return yyinput(); + #else + return input (); + #endif +} + #define debug(arg1,arg2) /*printf("lex:arg1|%s|\n", arg2);*/ + +#ifndef FLEX_SCANNER +int input() +{ + int c; + c = Getc(); + if (c == EOF) { + c = 0; + } + return c; +} +#endif + + +int unput(int c) { + return unGetc(c); +} + + +int output(int c) { +#if LINT + IGNORE(c); +#endif + diag("internal error: ", "called output"); + return 0; +} + +extern "C" int yywrap() { + return 1; +} + +char * inputtopar() +{ /* returns string up to and not including + * next closing parenthesis */ + /* main usage is to read the units string */ + char *cp; + int c; + + cp = buf; + while ((c = newinput()) != ')' && c != '\n' && c != 0) { + *cp++ = c; + } + if (c != ')') + diag("Syntax error:", " no closing ')'"); + *cp = '\0'; + unput(c); + return stralloc(buf, (char *) 0); +} + + %} D [0-9] E [Ee][-+]?{D}+ @@ -52,7 +113,7 @@ E [Ee][-+]?{D}+ Sprintf(buf, "D%s", yytext); } /* determine if really a constant */ - if ((i = input()) == '0') { + if ((i = newinput()) == '0') { Strcat(buf, "0"); yylval.qp = putintoken(buf, NAME); return NAME; @@ -181,57 +242,10 @@ REPRESENTS { \?.* {/*ignore inline comments*/;} -\{ { yylval.qp = putintoken("{", 0); return yytext[0]; } -\} { yylval.qp = putintoken("}", 0); return yytext[0]; } +\{ { yylval.qp = putintoken( "{", 0); return yytext[0]; } +\} { yylval.qp = putintoken( "}", 0); return yytext[0]; } . { yylval.qp = putintoken(yytext, 0); return yytext[0]; } %% -#ifndef FLEX_SCANNER -int input() -{ - int c; - c = Getc(); - if (c == EOF) { - c = 0; - } - return c; -} -#endif - - -int unput(c) int c; { - return unGetc(c); -} - - -int output(c) int c; { -#if LINT - IGNORE(c); -#endif - diag("internal error: ", "called output"); - return 0; -} - -int yywrap() { - return 1; -} - -char * inputtopar() -{ /* returns string up to and not including - * next closing parenthesis */ - /* main usage is to read the units string */ - char *cp; - int c; - - cp = buf; - while ((c = input()) != ')' && c != '\n' && c != 0) { - *cp++ = c; - } - if (c != ')') - diag("Syntax error:", " no closing ')'"); - *cp = '\0'; - unput(c); - return stralloc(buf, (char *) 0); -} diff --git a/src/nmodl/list.c b/src/nmodl/list.cpp similarity index 78% rename from src/nmodl/list.c rename to src/nmodl/list.cpp index c05bb16805..e801304439 100755 --- a/src/nmodl/list.c +++ b/src/nmodl/list.cpp @@ -105,8 +105,7 @@ List *newlist() return (List *)i; } -void freelist(plist) /*free the list but not the elements*/ - List **plist; +void freelist(List** plist) /*free the list but not the elements*/ { Item *i1, *i2; if (!(*plist)) { @@ -120,8 +119,7 @@ void freelist(plist) /*free the list but not the elements*/ *plist = (List *)0; } -static Item *linkitem(item) - Item *item; +static Item *linkitem(Item *item) { Item *i; @@ -134,25 +132,21 @@ static Item *linkitem(item) } #if 0 /*currently unused*/ -Item *next(item) - Item *item; +Item *next( Item *item) { assert(item->next->element.lst); /* never return the list item */ return item->next; } -Item *prev(item) - Item *item; +Item *prev(Item *item) { assert(item->prev->element.lst); /* never return the list item */ return item->prev; } #endif -Item *insertstr(item, str) /* insert a copy of the string before item */ +Item *insertstr(Item* item, char* str) /* insert a copy of the string before item */ /* a copy is made because strings are often assembled into a reusable buffer*/ - Item *item; - char *str; { Item *i; @@ -162,8 +156,7 @@ Item *insertstr(item, str) /* insert a copy of the string before item */ return i; } -Item *insertitem(item, itm) /* insert a item pointer before item */ - Item *item, *itm; +Item *insertitem(Item* item, Item* itm) /* insert a item pointer before item */ { Item *i; @@ -173,9 +166,7 @@ Item *insertitem(item, itm) /* insert a item pointer before item */ return i; } -Item *insertlist(item, lst) /* insert a item pointer before item */ - Item *item; - List *lst; +Item *insertlist(Item* item, List* lst) /* insert a item pointer before item */ { Item *i; @@ -185,10 +176,8 @@ Item *insertlist(item, lst) /* insert a item pointer before item */ return i; } -Item *insertsym(item, sym) /* insert a symbol before item */ +Item *insertsym(Item* item, Symbol* sym) /* insert a symbol before item */ /* a copy is not made because we need the same symbol in different lists */ - Item *item; - Symbol *sym; { Item *i; @@ -198,49 +187,37 @@ Item *insertsym(item, sym) /* insert a symbol before item */ return i; } -Item *linsertstr(list, str) - List *list; - char *str; +Item *linsertstr(List* list, char* str) { return insertstr(list->next, str); } -Item *lappendstr(list, str) - List *list; - char *str; +Item *lappendstr(List* list, char* str) { return insertstr(list, str); } -Item *linsertsym(list, sym) - List *list; - Symbol *sym; +Item *linsertsym(List* list, Symbol* sym) { return insertsym(list->next, sym); } -Item *lappendsym(list, sym) - List *list; - Symbol *sym; +Item *lappendsym(List* list, Symbol* sym) { return insertsym(list, sym); } -Item *lappenditem(list, item) - List *list; - Item *item; +Item *lappenditem(List* list, Item* item) { return insertitem(list, item); } -Item *lappendlst(list, lst) - List *list, *lst; +Item *lappendlst(List* list, List* lst) { return insertlist(list, lst); } -void delete(item) - Item *item; +void dlete(Item *item) { assert(item->itemtype); /* can't delete list */ item->next->prev = item->prev; @@ -248,23 +225,23 @@ void delete(item) Free(item); } -char *emalloc(n) unsigned n; { /* check return from malloc */ +char *emalloc(unsigned n) { /* check return from malloc */ char *p; - p = malloc(n); + p = static_cast(malloc(n)); if (p == (char *)0) { diag("out of memory", (char *)0); } return p; } -char *stralloc(buf, rel) char *buf,*rel; { +char *stralloc(char* buf, char* rel) { /* allocate space, copy buf, and free rel */ char *s; if (buf) { - s = emalloc((unsigned)(strlen(buf) + 1)); + s = static_cast(emalloc((unsigned)(strlen(buf) + 1))); Strcpy(s, buf); }else{ - s = emalloc(1); + s = static_cast(emalloc(1)); s[0] = '\0'; } if (rel) { @@ -273,21 +250,19 @@ char *stralloc(buf, rel) char *buf,*rel; { return s; } -void deltokens(q1, q2) /* delete tokens from q1 to q2 */ - Item *q1, *q2; +void deltokens(Item* q1, Item* q2) /* delete tokens from q1 to q2 */ { /* It is a serious error if q2 precedes q1 */ Item *q; for (q = q1; q != q2;) { q = q->next; - delete(q->prev); + dlete(q->prev); } - delete(q2); + dlete(q2); } -void move(q1, q2, q3) /* move q1 to q2 and insert before q3*/ - Item *q1, *q2, *q3; +void move(Item* q1, Item* q2, Item* q3) /* move q1 to q2 and insert before q3*/ { /* it is a serious error if q2 precedes q1 */ assert(q1 && q2); @@ -301,31 +276,25 @@ void move(q1, q2, q3) /* move q1 to q2 and insert before q3*/ q2->next = q3; } -void movelist(q1, q2, s) /* move q1 to q2 from old list to end of list s*/ - Item *q1, *q2; - List *s; +void movelist(Item* q1, Item* q2, List* s) /* move q1 to q2 from old list to end of list s*/ { move(q1, q2, s); } -void replacstr(q, s) - Item *q; - char *s; +void replacstr(Item* q, char* s) { q->itemtype = STRING; q->element.str = stralloc(s, (char *)0); } -Item *putintoken(s, type) - char *s; - short type; +Item *putintoken(char *s, short type) { /* make sure a symbol exists for s and append to intoken list */ Symbol *sym; if (s == (char *)0) - diag("internal error"," in putintoken"); + diag("internal error", " in putintoken"); switch (type) { case STRING: diff --git a/src/nmodl/modl.c b/src/nmodl/modl.cpp similarity index 92% rename from src/nmodl/modl.c rename to src/nmodl/modl.cpp index ff08e9ef99..c610c8c8c8 100755 --- a/src/nmodl/modl.c +++ b/src/nmodl/modl.cpp @@ -31,7 +31,7 @@ * allowed which gives the complete input filename. The first argument * still gives the prefix of the .c and .var files. */ - + /* the first arg may also be a file.mod (containing the .mod suffix)*/ #if MAC #include @@ -77,11 +77,10 @@ extern int usederivstatearray; static char pgm_name[] = "nmodl"; extern char *RCS_version; extern char *RCS_date; -static void openfiles(); +void openfiles(int argc, char* argv[]); -int main(argc, argv) - int argc; - char *argv[]; { +int main(int argc, char* argv[]) +{ /* * arg 1 is the prefix to the input file and output .c and .par * files @@ -254,9 +253,7 @@ fprintf(stderr, "The %s.c file may be manually edited to fix these errors.\n", m return 0; } -static void openfiles(argc, argv) - int argc; - char *argv[]; +void openfiles(int argc, char* argv[]) { char s[NRN_BUFSIZE]; char *cp; @@ -303,3 +300,22 @@ static void openfiles(argc, argv) } #endif } + +static std::string str_replace(std::string str, const std::string& search_str, const std::string& replace_str) +{ + if (search_str.empty()) { + return str; + } + + size_t pos; + while ( (pos = str.find(search_str)) != std::string::npos ) { + str.replace(pos, search_str.size(), replace_str); + } + + return str; +} + +void verbatim_adjust(char* q) { + const std::string repl = str_replace(q, "u.template", "u.ctemplate"); + Fprintf(fcout, "%s", repl.c_str()); +} \ No newline at end of file diff --git a/src/nmodl/modl.h b/src/nmodl/modl.h index 8a2d9d8021..23145c9f85 100755 --- a/src/nmodl/modl.h +++ b/src/nmodl/modl.h @@ -216,11 +216,11 @@ typedef struct Symbol { #define EXPLICIT_DECL 01 /* usage field, variable occurs in input file */ extern char - *emalloc(), /* malloc with out of space checking */ - *stralloc(), /* copies string to new space */ - *inputline(), /* used only by parser to get title line */ - *inputtopar(), /* used only by parser to get units */ - *Gets(); /* used only in io.c to get string from fin. */ + *emalloc(unsigned), /* malloc with out of space checking */ + *stralloc(char*, char*), /* copies string to new space */ + *inputline(), /* used only by parser to get title line */ + *inputtopar(), /* used only by parser to get units */ + *Gets(char*); /* used only in io.c to get string from fin. */ #if 0 #if __TURBOC__ || SYSV || NeXT || LINUX @@ -237,23 +237,23 @@ extern List *inputtext(); /* used by parser to get block text from * VERBATIM and COMMENT */ extern Item - *putintoken(), /* construct symbol and store input tokens */ - *insertstr(), /* before a known Item */ - *insertsym(), - *linsertstr(), /* prepend to list */ - *lappendstr(), /* append to list */ - *linsertsym(), - *lappendsym(), - *lappenditem(), - *lappendlst(), + *putintoken(char *s, short type), /* construct symbol and store input tokens */ + *insertstr(Item* item, char* str), /* before a known Item */ + *insertsym(List* list, Symbol* sym), + *linsertstr(List* list, char* str), /* prepend to list */ + *lappendstr(List* list, char* str), /* append to list */ + *linsertsym(List* list, Symbol* sym), + *lappendsym(List* list, Symbol* sym), + *lappenditem(List* list, Item* item), + *lappendlst(List* list, List* lst), *next(), /* not used but should be instead of q->next */ *prev(); extern Symbol - *install(), /* Install token in symbol table */ - *lookup(), /* lookup name in symbol table */ - *copylocal(), /* install LOCAL variable symbol */ - *ifnew_parminstall(); /* new .var info only if + *install(char*, int), /* Install token in symbol table */ + *lookup(char*), /* lookup name in symbol table */ + *copylocal(Symbol*), /* install LOCAL variable symbol */ + *ifnew_parminstall(char* name, char* num, char* units, char* limits); /* new .var info only if * not already done. */ #include "nmodlfunc.h" @@ -328,4 +328,6 @@ extern Item *qlint; #define Free(arg) free((void *)(arg)) #endif + +void verbatim_adjust(char* q); /** @} */ // end of hoc_functions diff --git a/src/nmodl/netrec_discon.c b/src/nmodl/netrec_discon.cpp similarity index 100% rename from src/nmodl/netrec_discon.c rename to src/nmodl/netrec_discon.cpp diff --git a/src/nmodl/nmodlfunc.h b/src/nmodl/nmodlfunc.h index af1fa8b2da..97d70b73d7 100644 --- a/src/nmodl/nmodlfunc.h +++ b/src/nmodl/nmodlfunc.h @@ -1,136 +1,138 @@ -int in_solvefor(); -int cvode_cnexp_success(); +struct Rlist; +struct Reaction; -void cvode_parse(); -void Unit_push(); +int in_solvefor(Symbol*); +int cvode_cnexp_success(Item* q1, Item* q2); + +void cvode_parse(Symbol* s, List* e); +void Unit_push(char*); void unit_pop(); void unit_div(); -void install_units(); +void install_units(char* s1, char* s2); void modl_units(); -void vectorize_if_else_stmt(); +void vectorize_if_else_stmt(int); void consistency(); void c_out(const char* prefix); -void printlist(); -void c_out_vectorize(); -void vectorize_substitute(); +void printlist(List*); +void c_out_vectorize(const char*); +void vectorize_substitute(Item* q, char* str); void vectorize_do_substitute(); -void solv_diffeq(); -void add_deriv_imp_list(); -void deriv_used(); -void massagederiv(); -void matchinitial(); -void matchbound(); -void checkmatch(); -void matchmassage(); -void copyitems(); -void disc_var_seen(); -void massagediscblk(); +void solv_diffeq(Item* qsol, Symbol* fun, Symbol* method, int numeqn, int listnum, int steadystate, int btype); +void add_deriv_imp_list(char*); +void deriv_used(Symbol* s, Item* q1, Item* q2); +void massagederiv(Item* q1, Item* q2, Item* q3, Item* q4, int sensused); +void matchinitial(Item*); +void matchbound(Item* q1, Item* q2, Item* q3, Item* q4, Item* q5, Symbol* sindex); +void checkmatch(int); +void matchmassage(int); +void copyitems(Item* q1, Item* q2, Item* qdest); +void disc_var_seen(Item* q1, Item* q2, Item* q3, int array); +void massagediscblk(Item* q1, Item* q2, Item* q3, Item* q4); void init_disc_vars(); void init(); -void inblock(); -void unGets(); -void diag(); -void enquextern(); -void include_file(); -void reactname(); +void inblock(char*); +void unGets(char*); +void diag(char*, char*); +void enquextern(Symbol*); +void include_file(Item*); +void reactname(Item* q1, Item* lastok, Item* q2); void leftreact(); -void massagereaction(); -void flux(); -void massagekinetic(); -void fixrlst(); -void kinetic_intmethod(); -void genfluxterm(); -void kinetic_implicit(); -void massageconserve(); -void check_block(); -void massagecompart(); -void massageldifus(); -void kin_vect1(); +void massagereaction(Item* qREACTION, Item* qREACT1, Item* qlpar, Item* qcomma, Item* qrpar); +void flux(Item* qREACTION, Item* qdir, Item* qlast); +void massagekinetic(Item* q1, Item* q2, Item* q3, Item* q4, int sensused); +void fixrlst(Rlist*); +void kinetic_intmethod(Symbol* fun, char* meth); +void genfluxterm(Reaction* r, int type, int n); +void kinetic_implicit(Symbol* fun, char* dt, char* mname); +void massageconserve(Item* q1, Item* q3, Item* q5); +void check_block(int standard, int actual, char* mes); +void massagecompart(Item* qexp, Item* qb1, Item* qb2, Symbol* indx); +void massageldifus(Item* qexp, Item* qb1, Item* qb2, Symbol* indx); +void kin_vect1(Item* q1, Item* q2, Item* q4); void kin_vect2(); -void kin_vect3(); +void kin_vect3(Item* q1, Item* q2, Item* q4); void ostmt_start(); -void see_astmt(); +void see_astmt(Item* q1, Item* q2); void see_ostmt(); -void prn(); -void cvode_kinetic(); -void single_channel(); -void freelist(); -void delete(); -void deltokens(); -void move(); -void movelist(); -void replacstr(); +void prn(Item* q1, Item* q2); +void cvode_kinetic(Item* qsol, Symbol* fun, int numeqn, int listnum); +void single_channel(Item* qsol, Symbol* fun, int numeqn, int listnum); +void freelist(List**); +void dlete(Item*); +void deltokens(Item*, Item*); +void move(Item* q1, Item* q2, Item* q3); +void movelist(Item* q1, Item* q2, List* s); +void replacstr(Item* q, char* s); void c_out(); -void printitem(); -void debugprintitem(); -void printlist(); +void printitem(Item*); +void debugprintitem(Item*); void c_out_vectorize(); -void vectorize_substitute(); +void vectorize_substitute(Item* q, char* str); void vectorize_do_substitute(); void nrninit(); void parout(); -void warn_ignore(); +void warn_ignore(Symbol*); void ldifusreg(); -void decode_ustr(); +void decode_ustr(Symbol* sym, double* pg1, double* pg2, char* s); void units_reg(); -void nrn_list(); -void bablk(); -void nrn_use(); -void nrn_var_assigned(); -void slist_data(); -void out_nt_ml_frag(); +void nrn_list(Item*, Item*); +void bablk(int ba, int type, Item* q1, Item* q2); +void nrn_use(Item* q1, Item* q2, Item* q3, Item* q4); +void nrn_var_assigned(Symbol*); +void slist_data(Symbol* s, int indx, int findx) ; +void out_nt_ml_frag(List*); void cvode_emit_interface(); void cvode_proced_emit(); -void cvode_interface(); +void cvode_interface(Symbol* fun, int num, int neq); void cvode_valid(); -void cvode_rw_cur(); -void net_receive(); -void net_init(); -void fornetcon(); +void cvode_rw_cur(char*); +void net_receive(Item* qarg, Item* qp1, Item* qp2, Item* qstmt, Item* qend); +void net_init(Item* qinit, Item* qp2); +void fornetcon(Item* keyword, Item* par1, Item* args, Item* par2, Item* stmt, Item* qend); void chk_thread_safe(); -void threadsafe_seen(); -void explicit_decl(); -void parm_array_install(); -void parminstall(); -void steppedinstall(); -void indepinstall(); -void depinstall(); -void statdefault(); -void vectorize_scan_for_func(); -void defarg(); -void lag_stmt(); -void queue_stmt(); -void add_reset_args(); -void add_nrnthread_arg(); +void threadsafe_seen(Item* q1, Item* q2); +void explicit_decl(int level, Item* q); +void parm_array_install(Symbol* n, char* num, char* units, char* limits, int index); +void parminstall(Symbol* n, char* num, char* units, char* limits); +void steppedinstall(Symbol* n, Item* q1, Item* q2, char* units); +void indepinstall(Symbol* n, char* from, char* to, char* with, Item* qstart, char* units, int scop); +void depinstall(int type, Symbol* n, int index, char* from, char* to, char* units, Item* qs, int makeconst, char* abstol); +void statdefault(Symbol* n, int index, char* units, Item* qs, int makeconst); +void vectorize_scan_for_func(Item* q1, Item* q2); +void defarg(Item* q1, Item* q2); +void lag_stmt(Item* q1, int blocktype); +void queue_stmt(Item* q1, Item* q2); +void add_reset_args(Item*); +void add_nrnthread_arg(Item*); void check_tables(); -void table_massage(); -void hocfunchack(); -void hocfunc(); -void vectorize_use_func(); -void function_table(); -void watchstmt(); -void threadsafe(); -void nrnmutex(); -void solv_partial(); -void partial_eqn(); -void massagepartial(); -void partial_bndry(); -void sensparm(); -void add_sens_statelist(); -void sensmassage(); -void sens_nonlin_out(); -void solv_nonlin(); -void solv_lineq(); -void eqnqueue(); -void massagenonlin(); -void init_linblk(); -void init_lineq(); -void lin_state_term(); -void linterm(); -void massage_linblk(); -void solvequeue(); +void table_massage(List* tablist, Item* qtype, Item* qname, List* arglist); +void hocfunchack(Symbol* n, Item* qpar1, Item* qpar2, int hack); +void hocfunc(Symbol* n, Item* qpar1, Item* qpar2); +void vectorize_use_func(Item* qname, Item* qpar1, Item* qexpr, Item* qpar2, int blocktype); +void function_table(Symbol* s, Item* qpar1, Item* qpar2, Item* qb1, Item* qb2); +void watchstmt(Item* par1, Item* dir, Item* par2, Item* flag, int blocktype); +void threadsafe(char*); +void nrnmutex(int, Item*); +void solv_partial(Item* qsol, Symbol* fun); +void partial_eqn(Item* q2, Item* q4, Item* q8, Item* q11); +void massagepartial(Item* q1, Item* q2, Item* q3, Item* q6); +void partial_bndry(int type, Item* qvar, Item* qfirstlast, Item* qexpr, Item* qlast); +void sensparm(Item*); +void add_sens_statelist(Symbol*); +void sensmassage(int type, Item* qfun, int fn); +void sens_nonlin_out(Item* q, Symbol* fun); +void solv_nonlin(Item* qsol, Symbol* fun, Symbol* method, int numeqn, int listnum); +void solv_lineq(Item* qsol, Symbol* fun, Symbol* method, int numeqn, int listnum); +void eqnqueue(Item*); +void massagenonlin(Item* q1, Item* q2, Item* q3, Item* q4, int sensused); +void init_linblk(Item*); +void init_lineq(Item*); +void lin_state_term(Item* q1, Item* q2); +void linterm(Item* q1, Item* q2, int pstate, int sign); +void massage_linblk(Item* q1, Item* q2, Item* q3, Item* q4, int sensused); +void solvequeue(Item* q1, Item* q2, int blocktype, Item* qerr); void solvhandler(); -void save_dt(); +void save_dt(Item*); void symbol_init(); void pushlocal(); void poplocal(); diff --git a/src/nmodl/noccout.c b/src/nmodl/noccout.cpp similarity index 98% rename from src/nmodl/noccout.c rename to src/nmodl/noccout.cpp index c3606aceee..90f6fc0a8c 100755 --- a/src/nmodl/noccout.c +++ b/src/nmodl/noccout.cpp @@ -15,8 +15,8 @@ List *procfunc, *initfunc, *modelfunc, *termfunc, *initlist, *firstlis #if NMODL List *nrnstate; -extern List *currents, *set_ion_variables(), *get_ion_variables(); -extern List *begin_dion_stmt(), *end_dion_stmt(); +extern List *currents, *set_ion_variables(int), *get_ion_variables(int); +extern List *begin_dion_stmt(), *end_dion_stmt(char*); extern List* conductance_; static void conductance_cout(); #endif @@ -513,7 +513,7 @@ static void initstates() static int newline, indent; -void printitem(q) Item* q; { +void printitem(Item* q) { if (q->itemtype == SYMBOL) { if (SYM(q)->type == SPECIAL) { switch (SYM(q)->subtype) { @@ -533,7 +533,7 @@ void printitem(q) Item* q; { } Fprintf(fcout, " %s", SYM(q)->name); } else if (q->itemtype == VERBATIM) { - Fprintf(fcout, "%s", STR(q)); + verbatim_adjust(STR(q)); } else if (q->itemtype == ITEM) { printitem(ITM(q)); }else { @@ -541,7 +541,7 @@ void printitem(q) Item* q; { } } -void debugprintitem(q) Item* q; { +void debugprintitem(Item* q) { if (q->itemtype == SYMBOL) { printf("SYM %s\n", SYM(q)->name); } else if (q->itemtype == VERBATIM) { @@ -573,8 +573,7 @@ char* items_as_string(Item* q1, Item* q2) { return strdup(buf); } -void printlist(s) - List *s; +void printlist(List* s) { Item *q; int i; @@ -922,12 +921,10 @@ diag("current can only be LOCAL in a BREAKPOINT if CONDUCTANCE statements are us P(" if (!_first) return;\n"); printlist(initlist); P("_first = 0;\n}\n"); - P("\n#if defined(__cplusplus)\n} /* extern \"C\" */\n#endif\n"); + //P("\n#if defined(__cplusplus)\n} /* extern \"C\" */\n#endif\n"); // TODO - can this be removed? } -void vectorize_substitute(q, str) - Item* q; - char* str; +void vectorize_substitute(Item* q, char* str) { if (!vectorize_replacements) { vectorize_replacements = newlist(); @@ -994,7 +991,7 @@ static void conductance_cout() { ITERATE(q, m) { if (q->itemtype == SYMBOL) { if (strcmp(SYM(q)->name, "{") == 0) { - delete(q); + dlete(q); break; } } @@ -1003,7 +1000,7 @@ static void conductance_cout() { for (q = m->prev; q != m; q = q->prev) { if (q->itemtype == SYMBOL) { if (strcmp(SYM(q)->name, "}") == 0) { - delete(q); + dlete(q); break; } } diff --git a/src/nmodl/nocpout.c b/src/nmodl/nocpout.cpp similarity index 94% rename from src/nmodl/nocpout.c rename to src/nmodl/nocpout.cpp index e964df5b6f..ca8cf6264e 100755 --- a/src/nmodl/nocpout.c +++ b/src/nmodl/nocpout.cpp @@ -129,11 +129,12 @@ List *thread_mem_init_list; List* toplocal_; extern int protect_; extern int protect_include_; -extern List *set_ion_variables(), *get_ion_variables(); +extern List *set_ion_variables(int), *get_ion_variables(int); extern int netrec_need_v; -static int decode_limits(); -static int decode_tolerance(); + int decode_limits(Symbol* sym, double* pg1, double* pg2); + int decode_tolerance(Symbol* sym, double* pg1); + /* NEURON block information */ List *currents; @@ -154,13 +155,13 @@ static int diamdec = 0; /*1 if diam is declared*/ static int areadec = 0; static int use_bbcorepointer = 0; -static void defs_h(); -static int iontype(); -static void nrndeclare(); -static void del_range(); -static void declare_p(); -static int iondef(); -static void ion_promote(); + void defs_h(Symbol*); + int iontype(char* s1, char* s2); +void nrndeclare(); +void del_range(List*); +void declare_p(); + int iondef(int*); + void ion_promote(Item*); static int ppvar_cnt; static List* ppvar_semantics_; static void ppvar_semantics(int, const char*); @@ -213,7 +214,7 @@ void nrninit() { useion = newlist(); nrnpointers = newlist(); using_default_indep = 0; - indepinstall(install("t", NAME), "0", "1", "100", (Item*)0, "ms", 0); + indepinstall(install( "t", NAME), "0", "1", "100", (Item*)0, "ms", 0); using_default_indep = 1; debugging_ = 1; thread_cleanup_list = newlist(); @@ -339,7 +340,7 @@ fprintf(stderr, "Notice: ARTIFICIAL_CELL models that would require thread specif declare_p(); ioncount = iondef(&pointercount); /* first is _nd_area if point process */ Lappendstr(defs_list, "\n#if MAC\n#if !defined(v)\n#define v _mlhv\n#endif\n#if !defined(h)\n#define h _mlhh\n#endif\n#endif\n"); - Lappendstr(defs_list, "\n#if defined(__cplusplus)\nextern \"C\" {\n#endif\n"); +// Lappendstr(defs_list, "\n#if defined(__cplusplus)\nextern \"C\" {\n#endif\n"); //TODO - can this be removed? otherwise rely on dirty fix: __cminusminus Lappendstr(defs_list, "static int hoc_nrnpointerindex = "); if (pointercount) { q = nrnpointers->next; @@ -382,9 +383,9 @@ fprintf(stderr, "Notice: ARTIFICIAL_CELL models that would require thread specif s = SYM(q); if (s->subtype & (FUNCT | PROCED) && s->name[0] != '_') { if (point_process) { -Sprintf(buf, "static double _hoc_%s();\n", s->name); + Sprintf(buf, "static double _hoc_%s();\n", s->name); }else{ -Sprintf(buf, "static void _hoc_%s(void);\n", s->name); + Sprintf(buf, "static void _hoc_%s(void);\n", s->name); } Lappendstr(defs_list, buf); } @@ -400,7 +401,7 @@ extern Memb_func* memb_func;\n\ " ); if (nmodl_text) { - Lappendstr(defs_list,"\n" + Lappendstr(defs_list, "\n" "#define NMODL_TEXT 1\n" "#if NMODL_TEXT\n" "static const char* nmodl_file_text;\n" @@ -415,15 +416,15 @@ extern Memb_func* memb_func;\n\ if (point_process) { Lappendstr(defs_list, "extern Prop* nrn_point_prop_;\n"); Lappendstr(defs_list, "static int _pointtype;\n"); - Lappendstr(defs_list, "static void* _hoc_create_pnt(_ho) Object* _ho; { void* create_point_process();\n"); + Lappendstr(defs_list, "static void* _hoc_create_pnt(Object* _ho) { void* create_point_process(int, Object*);\n"); Lappendstr(defs_list, "return create_point_process(_pointtype, _ho);\n}\n"); - Lappendstr(defs_list, "static void _hoc_destroy_pnt();\n"); - Lappendstr(defs_list, "static double _hoc_loc_pnt(_vptr) void* _vptr; {double loc_point_process();\n"); + Lappendstr(defs_list, "static void _hoc_destroy_pnt(void*);\n"); + Lappendstr(defs_list, "static double _hoc_loc_pnt(void* _vptr) {double loc_point_process(int, void*);\n"); Lappendstr(defs_list, "return loc_point_process(_pointtype, _vptr);\n}\n"); - Lappendstr(defs_list, "static double _hoc_has_loc(_vptr) void* _vptr; {double has_loc_point();\n"); + Lappendstr(defs_list, "static double _hoc_has_loc(void* _vptr) {double has_loc_point(void*);\n"); Lappendstr(defs_list, "return has_loc_point(_vptr);\n}\n"); - Lappendstr(defs_list, "static double _hoc_get_loc_pnt(_vptr)void* _vptr; {\n"); - Lappendstr(defs_list, "double get_loc_point_process(); return (get_loc_point_process(_vptr));\n}\n"); + Lappendstr(defs_list, "static double _hoc_get_loc_pnt(void* _vptr) {\n"); + Lappendstr(defs_list, "double get_loc_point_process(void*); return (get_loc_point_process(_vptr));\n}\n"); } /* function to set up _p and _ppvar */ Lappendstr(defs_list, "extern void _nrn_setdata_reg(int, void(*)(Prop*));\n"); @@ -455,9 +456,9 @@ extern Memb_func* memb_func;\n\ /* functions */ Lappendstr(defs_list, "/* connect user functions to hoc names */\n"); - Lappendstr(defs_list,"static VoidFunc hoc_intfunc[] = {\n"); + Lappendstr(defs_list, "static VoidFunc hoc_intfunc[] = {\n"); if (point_process) { - Lappendstr(defs_list,"0,0\n};\n"); + Lappendstr(defs_list, "0,0\n};\n"); Lappendstr(defs_list, "static Member_func _member_func[] = {\n"); Sprintf(buf, "\"loc\", _hoc_loc_pnt,\n"); Lappendstr(defs_list, buf); @@ -657,7 +658,7 @@ diag("No statics allowed for thread safe models:", s->name); } } Lappendstr(defs_list, "/* connect global user variables to hoc */\n"); - Lappendstr(defs_list,"static DoubScal hoc_scdoub[] = {\n"); + Lappendstr(defs_list, "static DoubScal hoc_scdoub[] = {\n"); ITERATE(q, syminorder) { s = SYM(q); if (s->nrntype & NRNGLOBAL && !(s->subtype & ARRAY)) { @@ -668,7 +669,7 @@ diag("No statics allowed for thread safe models:", s->name); Lappendstr(defs_list, "0,0\n};\n"); /* double vectors */ - Lappendstr(defs_list,"static DoubVec hoc_vdoub[] = {\n"); + Lappendstr(defs_list, "static DoubVec hoc_vdoub[] = {\n"); ITERATE(q, syminorder) { s = SYM(q); if (s->nrntype & NRNGLOBAL && (s->subtype & ARRAY)) { @@ -720,7 +721,7 @@ diag("No statics allowed for thread safe models:", s->name); ppvar_cnt += 1; } if (point_process) { - Lappendstr(defs_list, "static void _hoc_destroy_pnt(_vptr) void* _vptr; {\n"); + Lappendstr(defs_list, "static void _hoc_destroy_pnt(void* _vptr) {\n"); if (watch_seen_ || for_netcons_) { Lappendstr(defs_list, " Prop* _prop = ((Point_process*)_vptr)->_prop;\n"); } @@ -859,10 +860,10 @@ Sprintf(buf, " _p = nrn_prop_data_alloc(_mechtype, %d, _prop);\n", parraycount); Sprintf(buf, " _ppvar = nrn_prop_datum_alloc(_mechtype, %d, _prop);\n", ppvar_cnt); Lappendstr(defs_list, buf); if (point_process) { - Lappendstr(defs_list," }\n"); + Lappendstr(defs_list, " }\n"); } Lappendstr(defs_list, "\t_prop->dparam = _ppvar;\n"); - Lappendstr(defs_list,"\t/*connect ionic variables to this model*/\n"); + Lappendstr(defs_list, "\t/*connect ionic variables to this model*/\n"); } if (diamdec) { Sprintf(buf, "prop_ion = need_memb(_morphology_sym);\n"); @@ -1131,9 +1132,9 @@ extern void _cvode_abstol( Symbol**, double*, int);\n\n\ #if CVODE if (cvode_emit) { - Lappendstr(defs_list,"\ + Lappendstr(defs_list, "\ hoc_register_cvode(_mechtype, _ode_count, _ode_map, _ode_spec, _ode_matsol);\n"); - Lappendstr(defs_list,"\ + Lappendstr(defs_list, "\ hoc_register_tolerance(_mechtype, _hoc_state_tol, &_atollist);\n"); if (ion_synonym) { Lappendstr(defs_list, " hoc_register_synonym(_mechtype, _ode_synonym);\n"); @@ -1196,13 +1197,13 @@ if (_nd->_extnode) {\n\ lst = get_ion_variables(0); if (lst->next != lst->prev) { move(lst->next, lst->prev, ITM(q)); - freelist(lst); + freelist(&lst); //TODO - check this List** } q = q->next; lst = set_ion_variables(0); if (lst->next != lst->prev) { move(lst->next, lst->prev, ITM(q)); - freelist(lst); + freelist(&lst); //TODO - check this List** } q = q->next; sprintf(buf, "\thoc_reg_ba(_mechtype, _ba%d, %s);\n", i, STR(q)); @@ -1275,7 +1276,7 @@ static void _destructor(Prop* _prop) {\n\ } } -void warn_ignore(s) Symbol* s; { +void warn_ignore(Symbol* s) { int b; double d1, d2; b = 0; @@ -1369,9 +1370,7 @@ sprintf(buf, " (*_f)(_mechtype, _difcoef%d, &_difspace%d, 0, ", n, n); lappendstr(procfunc, "}\n"); } -static int decode_limits(sym, pg1, pg2) - Symbol *sym; - double *pg1, *pg2; +int decode_limits(Symbol* sym, double* pg1, double* pg2) { int i; double d1; @@ -1396,9 +1395,7 @@ static int decode_limits(sym, pg1, pg2) return 0; } -static int decode_tolerance(sym, pg1) - Symbol *sym; - double *pg1; +int decode_tolerance(Symbol* sym, double* pg1) { int i; double d1; @@ -1422,10 +1419,7 @@ static int decode_tolerance(sym, pg1) return 0; } -void decode_ustr(sym, pg1, pg2, s) /* decode sym->u.str */ - Symbol *sym; - char *s; - double *pg1, *pg2; +void decode_ustr(Symbol* sym, double* pg1, double* pg2, char* s) /* decode sym->u.str */ { int i, n; char *cp, *cp1; @@ -1524,8 +1518,7 @@ void units_reg() { Lappendstr(defs_list, "0,0\n};\n"); } -static void var_count(s) - Symbol *s; +static void var_count(Symbol* s) { defs_h(s); s->used = varcount++; @@ -1537,8 +1530,7 @@ static void var_count(s) } } -static void defs_h(s) - Symbol *s; +void defs_h(Symbol* s) { Item *q; @@ -1553,8 +1545,7 @@ static void defs_h(s) } -void nrn_list(q1, q2) - Item *q1, *q2; +void nrn_list(Item* q1, Item* q2) { List **plist = (List **)0; Item *q; @@ -1627,9 +1618,7 @@ threadsafe("Use of BBCOREPOINTER is not thread safe."); } } -void bablk(ba, type, q1, q2) - int ba, type; - Item *q1, *q2; +void bablk(int ba, int type, Item* q1, Item* q2) { Item* qb, *qv, *q; qb = insertstr(q1->prev->prev, "/*"); @@ -1667,8 +1656,7 @@ int ion_declared(Symbol* s) { return used; } -void nrn_use(q1, q2, q3, q4) - Item *q1, *q2, *q3, *q4; +void nrn_use(Item* q1, Item* q2, Item* q3, Item* q4) { int used, i; Item *q, *qr, *qw; @@ -1730,8 +1718,7 @@ void nrn_use(q1, q2, q3, q4) } } -static int iontype(s1, s2) /* returns index of variable in ion mechanism */ - char *s1, *s2; +int iontype(char* s1, char* s2) /* returns index of variable in ion mechanism */ { Sprintf(buf, "i%s", s2); if (strcmp(buf, s1) == 0) { @@ -1754,8 +1741,7 @@ static int iontype(s1, s2) /* returns index of variable in ion mechanism */ return -1; } -static Symbol *ifnew_install(name) - char *name; +static Symbol *ifnew_install(char* name) { Symbol *s; @@ -1766,19 +1752,19 @@ static Symbol *ifnew_install(name) return s; } -static void nrndeclare() { +void nrndeclare() { Symbol *s; Item *q; - s=lookup("diam"); if (s) { + s=lookup( "diam"); if (s) { if (s->nrntype & (NRNRANGE|NRNGLOBAL)) { -diag(s->name, " cannot be a RANGE or GLOBAL variable for this mechanism"); +diag(s->name, "cannot be a RANGE or GLOBAL variable for this mechanism"); } s->nrntype |= NRNNOTP|NRNPRANGEIN; diamdec=1; } - s=lookup("area"); if (s) { + s=lookup( "area"); if (s) { if (s->nrntype & (NRNRANGE|NRNGLOBAL)) { -diag(s->name, " cannot be a RANGE or GLOBAL variable for this mechanism"); +diag(s->name, "cannot be a RANGE or GLOBAL variable for this mechanism"); } s->nrntype |= NRNNOTP|NRNPRANGEIN; areadec=1; } @@ -1798,9 +1784,9 @@ diag(s->name, " cannot be a RANGE or GLOBAL variable for this mechanism"); s->nrntype |= NRNEXTRN | NRNNOTP; vectorize_substitute(lappendstr(defs_list, "\n#define t nrn_threads->_t\n#define dt nrn_threads->_dt\n"), "\n#define t _nt->_t\n#define dt _nt->_dt\n"); - s=lookup("usetable"); if (s) { s->nrntype |= NRNGLOBAL | NRNNOTP;} - s=lookup("celsius");if(s){s->nrntype |= NRNEXTRN | NRNNOTP;} - s=lookup("celcius"); if (s) diag("celcius should be spelled celsius", + s=lookup( "usetable"); if (s) { s->nrntype |= NRNGLOBAL | NRNNOTP;} + s=lookup( "celsius");if(s){s->nrntype |= NRNEXTRN | NRNNOTP;} + s=lookup( "celcius"); if (s) diag("celcius should be spelled celsius", (char *)0); ITERATE(q, syminorder) { @@ -1833,8 +1819,7 @@ diag(s->name, " cannot be a RANGE or GLOBAL variable for this mechanism"); del_range(rangedep); } -static void del_range(range) - List *range; +void del_range(List* range) { Item *q, *q1; Symbol *s; @@ -1843,13 +1828,13 @@ static void del_range(range) q1 = q->next; s = SYM(q); if (s->nrntype & (NRNPRANGEIN | NRNPRANGEOUT)) { - delete(q); + dlete(q); } } } -static void declare_p() { +void declare_p() { Item *q; Symbol* s; @@ -1886,8 +1871,8 @@ static void declare_p() { } } -List *set_ion_variables(block) - int block; /* 0 means equation block , 2 means initial block */ +List *set_ion_variables(int block) +/* 0 means equation block , 2 means initial block */ { /*ARGSUSED*/ Item *q, *q1, *qconc; @@ -1952,8 +1937,8 @@ Sprintf(buf, " _ion_%s = %s;\n", SYM(q1)->name, SYM(q1)->name); return l; } -List *get_ion_variables(block) - int block; /* 0 means equation block */ +List *get_ion_variables(int block) +/* 0 means equation block */ /* 2 means ode_spec and ode_matsol blocks */ { /*ARGSUSED*/ @@ -1993,7 +1978,7 @@ Fprintf(stderr, "WARNING: WRITE %s with it a STATE may not be translated correct return l; } -static int iondef(p_pointercount) int *p_pointercount; { +int iondef(int* p_pointercount) { int ioncount, it, need_style; Item *q, *q1, *q2; Symbol *sion; @@ -2122,7 +2107,7 @@ Sprintf(buf, "#define _ion_di%sdv\t*_ppvar[%d]._pval\n", sion->name, ioncount); void ppvar_semantics(int i, const char* name) { Item* q; if (!ppvar_semantics_) { ppvar_semantics_ = newlist(); } - q = Lappendstr(ppvar_semantics_, name); + q = Lappendstr(ppvar_semantics_, const_cast(name)); //TODO - ugly but ok for now q->itemtype = (short)i; } @@ -2152,8 +2137,7 @@ List *begin_dion_stmt() return l; } -List *end_dion_stmt(strdel) - char *strdel; +List *end_dion_stmt(char* strdel) { Item *q, *q1; static List *l; @@ -2182,8 +2166,7 @@ Sprintf(buf, " _ion_di%sdv += (_di%s - %s)/%s", return l; } -static void ion_promote(qion) - Item* qion; +void ion_promote(Item* qion) { Item* q; char* in; @@ -2223,7 +2206,7 @@ static void ion_promote(qion) #define NRNFIX(arg) if (strcmp(n, arg) == 0) e=1; -void nrn_var_assigned(s) Symbol* s; { +void nrn_var_assigned(Symbol* s){ int e; char* n; if (s->assigned_to_ == 0) { @@ -2240,7 +2223,7 @@ void nrn_var_assigned(s) Symbol* s; { NRNFIX("dt"); NRNFIX("celsius"); if (e) { -diag(s->name, " is a special NEURON variable that should not be\n assigned a value\ +diag(s->name, "is a special NEURON variable that should not be\n assigned a value\ in a model description file\n"); } } @@ -2251,7 +2234,7 @@ static int cvode_valid_, using_cvode; static int cvode_num_, cvode_neq_; static Symbol* cvode_fun_; -void slist_data(s, indx, findx) Symbol* s; int indx, findx; { +void slist_data(Symbol* s, int indx, int findx) { /* format: number of pairs, followed by findx, indx pairs */ int* pi; int i, n; @@ -2276,11 +2259,11 @@ void slist_data(s, indx, findx) Symbol* s; int indx, findx; { } } -int slist_search(n, s) int n; Symbol* s; { +int slist_search(int n, Symbol* s) { int i, *pi; pi = s->slist_info_; if (pi == (int*)0) { - diag(s->name, " not really a STATE; Ie. No differential equation for it.\n"); + diag(s->name, "not really a STATE; Ie. No differential equation for it.\n"); } assert(pi); for (i=0; i < pi[0]; ++i) { @@ -2354,7 +2337,7 @@ printf("|%s||%s||%s|\n",STR(q3), s, buf); } } if (b == 0) { -diag(SYM(q1)->name, " is WRITE but is not a STATE and has no assignment statement"); +diag(SYM(q1)->name, "is WRITE but is not a STATE and has no assignment statement"); } } } @@ -2430,7 +2413,7 @@ static void _ode_map(int _ieq, double** _pv, double** _pvdot, double* _pp, Datum /* need to take care of case where a state is an ion concentration. Replace the _pp pointer with a pointer to the actual ion model's concentration */ cvode_conc_map(); - Lappendstr(procfunc, "}\n"); + Lappendstr(procfunc, "}\n"); if (ion_synonym) { Lappendstr(defs_list, "static void _ode_synonym(int, double**, Datum**);\n"); Lappendstr(procfunc, "\ @@ -2501,7 +2484,7 @@ static void _ode_map(int _ieq, double** _pv, doubl** _pvdot, double* _pp){}\n"); static void _ode_matsol(Node* _nd, double* _pp, Datum* _ppd){}\n"); } -void cvode_interface(fun, num, neq) Symbol* fun; int num, neq; { +void cvode_interface(Symbol* fun, int num, int neq) { /* if only one then allowed and emit */ cvode_valid_ = 1; cvode_not_allowed = (using_cvode++) ? 1 : 0; @@ -2529,7 +2512,7 @@ void cvode_valid() { cvode_valid_ = 0; } -void cvode_rw_cur(b) char* b; { +void cvode_rw_cur(char* b) { /* if a current is READ and WRITE then call the correct _ode_spec since it may compute some aspect of the current */ Item* q, *q1; @@ -2558,8 +2541,7 @@ sprintf(b, "if (_nt->_vcv) { _ode_spec%d(); }\n", cvode_num_); } #endif -void net_receive(qarg, qp1, qp2, qstmt, qend) - Item* qarg, *qp1, *qp2, *qstmt, *qend; +void net_receive(Item* qarg, Item* qp1, Item* qp2, Item* qstmt, Item* qend) { Item* q, *q1; Symbol* s; @@ -2607,7 +2589,7 @@ void net_receive(qarg, qp1, qp2, qstmt, qend) called between integrator steps and before a re_init But no need to do so if it is not used. */ - Symbol* vsym = lookup("v"); + Symbol* vsym = lookup( "v"); netrec_need_v = 1; for (q = qstmt; q != qend; q = q->next) { if (q->itemtype == SYMBOL && SYM(q) == vsym) { @@ -2629,7 +2611,7 @@ void net_receive(qarg, qp1, qp2, qstmt, qend) continue; } if ((s->nrntype & IONCONC) == 0) { -diag(s->name, " :only concentrations can be mentioned in a NET_RECEIVE block"); +diag(s->name, ":only concentrations can be mentioned in a NET_RECEIVE block"); } /* distinct only */ for (j=0; j < nion; ++j) { @@ -2665,8 +2647,7 @@ diag("too many ions mentioned in NET_RECEIVE block (limit 10", (char*)0); } } -void net_init(qinit, qp2) - Item* qinit, *qp2; +void net_init(Item* qinit, Item* qp2) { /* qinit=INITIAL { stmtlist qp2=} */ replacstr(qinit, "\nstatic void _net_init(Point_process* _pnt, double* _args, double _lflag)"); @@ -2684,8 +2665,7 @@ void net_init(qinit, qp2) net_init_q2_ = qp2; } -void fornetcon(keyword, par1, args, par2, stmt, qend) - Item* keyword, *par1, *args, *par2, *stmt, *qend; +void fornetcon(Item* keyword, Item* par1, Item* args, Item* par2, Item* stmt, Item* qend) { Item* q, *q1; Symbol* s; @@ -2752,7 +2732,7 @@ void conductance_hint(int blocktype, Item* q1, Item* q2) { if (q2 != q1->next) { Symbol* s = SYM(q2); if (!ion_declared(s)) { - diag(s->name, " not declared as USEION in NEURON block"); + diag(s->name, "not declared as USEION in NEURON block"); } lappendsym(conductance_, s); }else{ diff --git a/src/nmodl/parsact.c b/src/nmodl/parsact.cpp similarity index 91% rename from src/nmodl/parsact.c rename to src/nmodl/parsact.cpp index 16fe8fd69a..58173a3e5b 100755 --- a/src/nmodl/parsact.c +++ b/src/nmodl/parsact.cpp @@ -30,14 +30,12 @@ extern int artificial_cell; extern int vectorize; extern int assert_threadsafe; -static int type_change(); +int type_change(Symbol* sym, int level); static long previous_subtype; /* subtype at the sym->level */ static char *previous_str; /* u.str on last install */ -void explicit_decl(level, q) - int level; - Item *q; +void explicit_decl(int level, Item* q) { /* used to be inside parse1.y without the lastvars condition Without the condition it served two purposes. @@ -101,7 +99,7 @@ void explicit_decl(level, q) }else if (level > sym->level) { /* old one takes precedence */ sym->u.str = previous_str; }else if (strcmp(sym->u.str, previous_str) != 0) { /* not identical */ - diag(sym->name, " has different values at same level"); + diag(sym->name, "has different values at same level"); } } @@ -109,9 +107,7 @@ void explicit_decl(level, q) one producing a message. Notice that multiple declarations at level 0 are caught as errors in the function above. */ -static int type_change(sym, level) /*return 1 if type change, 0 otherwise*/ - Symbol *sym; - int level; +int type_change(Symbol* sym, int level) /*return 1 if type change, 0 otherwise*/ { long s, d, c; @@ -146,10 +142,7 @@ Fprintf(stderr, "Notice: %s is promoted from a PARAMETER to an ASSIGNED\n", sym- return 1; } -void parm_array_install(n, num, units, limits, index) - Symbol *n; - char *num, *units, *limits; - int index; +void parm_array_install(Symbol* n, char* num, char* units, char* limits, int index) { char buf[NRN_BUFSIZE]; @@ -164,9 +157,7 @@ void parm_array_install(n, num, units, limits, index) n->u.str = stralloc(buf, (char *) 0); } -void parminstall(n, num, units, limits) - Symbol *n; - char *num, *units, *limits; +void parminstall(Symbol* n, char* num, char* units, char* limits) { char buf[NRN_BUFSIZE]; @@ -182,8 +173,7 @@ void parminstall(n, num, units, limits) /* often we want to install a parameter by default but only if the user hasn't declared it herself. */ -Symbol *ifnew_parminstall(name, num, units, limits) - char *name, *num, *units, *limits; +Symbol *ifnew_parminstall(char* name, char* num, char* units, char* limits) { Symbol *s; @@ -198,16 +188,13 @@ Symbol *ifnew_parminstall(name, num, units, limits) if (!(s->subtype & (PARM | STEP1))) { /* special case is scop_indep can be a PARM but not indepsym */ if (scop_indep == indepsym || s != scop_indep) { - diag(s->name, " can't be declared a parameter by default"); + diag(s->name, "can't be declared a parameter by default"); } } return s; } -void steppedinstall(n, q1, q2, units) - Symbol *n; - Item *q1, *q2; - char *units; +void steppedinstall(Symbol* n, Item* q1, Item* q2, char* units) { int i; @@ -247,11 +234,7 @@ static char *indepunits = ""; int using_default_indep; #endif -void indepinstall(n, from, to, with, qstart, units, scop) - Symbol *n; - char *from, *to, *with, *units; - Item *qstart; /* ITEM0 if not present */ - int scop; /*1 if declaring the scop independent*/ +void indepinstall(Symbol* n, char* from, char* to, char* with, Item* qstart, char* units, int scop) { char buf[NRN_BUFSIZE]; @@ -310,18 +293,14 @@ diag("Only one independent variable can be defined", (char *) 0); * However Dname will not appear in the .var file unless it is used -- see * parout.c. */ -void depinstall(type, n, index, from, to, units, qs, makeconst, abstol) - int type, index, makeconst; - Symbol *n; - char *from, *to, *units, *abstol; - Item *qs; +void depinstall(int type, Symbol* n, int index, char* from, char* to, char* units, Item* qs, int makeconst, char* abstol) { char buf[NRN_BUFSIZE], *pstr; int c; if (!type && strlen(abstol)>0) { printf("abstol = |%s|\n", abstol); - diag(n, "tolerance can be specified only for a STATE"); + diag(n->name, "tolerance can be specified only for a STATE"); } pstr = n->u.str; /* make it work even if recursive */ if (n->u.str == (char *) 0) @@ -349,17 +328,13 @@ void depinstall(type, n, index, from, to, units, qs, makeconst, abstol) previous_str = pstr; } -void statdefault(n, index, units, qs, makeconst) - Symbol *n; - int index, makeconst; - char *units; - Item *qs; +void statdefault(Symbol* n, int index, char* units, Item* qs, int makeconst) { char nam[256], *un; Symbol *s; if (n->type != NAME && n->type != PRIME) { - diag(n->name, " can't be a STATE"); + diag(n->name, "can't be a STATE"); } if (makeconst) { Sprintf(nam, "%s0", n->name); @@ -419,8 +394,7 @@ void vectorize_scan_for_func(Item* q1, Item* q2) { } } -void defarg(q1, q2) /* copy arg list and define as doubles */ - Item *q1, *q2; +void defarg(Item* q1, Item* q2) /* copy arg list and define as doubles */ { Item *q3, *q; @@ -440,35 +414,33 @@ void defarg(q1, q2) /* copy arg list and define as doubles */ #endif } -void lag_stmt(q1, blocktype) /* LAG name1 BY name2 */ - Item *q1; - int blocktype; +void lag_stmt(Item* q1, int blocktype) /* LAG name1 BY name2 */ { Symbol *name1, *name2, *lagval; /*ARGSUSED*/ /* parse */ name1 = SYM(q1->next); - delete(q1->next); - delete(q1->next); + dlete(q1->next); + dlete(q1->next); name2 = SYM(q1->next); - delete(q1->next); + dlete(q1->next); name1->usage |= DEP; name2->usage |= DEP; /* check */ if (!indepsym) { diag("INDEPENDENT variable must be declared to process", - " the LAG statement"); + "the LAG statement"); } if (!(name1->subtype & (DEP | STAT))) { - diag(name1->name, " not a STATE or DEPENDENT variable"); + diag(name1->name, "not a STATE or DEPENDENT variable"); } if (!(name2->subtype & (PARM | nmodlCONST))) { - diag(name2->name, " not a CONSTANT or PARAMETER"); + diag(name2->name, "not a CONSTANT or PARAMETER"); } Sprintf(buf, "lag_%s_%s", name1->name, name2->name); if (lookup(buf)) { - diag(buf, " already in use"); + diag(buf, "already in use"); } /* create */ lagval = install(buf, NAME); @@ -492,8 +464,7 @@ void lag_stmt(q1, blocktype) /* LAG name1 BY name2 */ replacstr(q1, buf); } -void queue_stmt(q1, q2) - Item *q1, *q2; +void queue_stmt(Item* q1, Item* q2) { Symbol *s; static int first=1; @@ -511,7 +482,7 @@ void queue_stmt(q1, q2) s = SYM(q2); s->usage |= DEP; if (!(s->subtype)) { - diag(s->name, " not declared"); + diag(s->name, "not declared"); } if (s->subtype & ARRAY) { Sprintf(buf, "%s, %d);\n", s->name, s->araydim); @@ -521,8 +492,7 @@ void queue_stmt(q1, q2) replacstr(q2, buf); } -void add_reset_args(q) - Item *q; +void add_reset_args(Item* q) { static int reset_fun_cnt=0; @@ -533,8 +503,7 @@ void add_reset_args(q) Lappendstr(firstlist, buf); } -void add_nrnthread_arg(q) - Item *q; +void add_nrnthread_arg(Item* q) { vectorize_substitute(insertstr(q->next, "nrn_threads,"), "_nt,"); } @@ -600,9 +569,7 @@ int check_tables_threads(List* p) { return 0; } -void table_massage(tablist, qtype, qname, arglist) - List *tablist, *arglist; - Item *qtype, *qname; +void table_massage(List* tablist, Item* qtype, Item* qname, List* arglist) { Symbol *fsym, *s, *arg=0; char* fname; @@ -623,7 +590,7 @@ void table_massage(tablist, qtype, qname, arglist) depend = LST(q = q->next); type = SYM(qtype)->type; - ifnew_parminstall("usetable", "1", "", "0 1"); + ifnew_parminstall( "usetable", "1", "", "0 1"); if (!check_table_statements) { check_table_statements = newlist(); } @@ -813,7 +780,7 @@ Sprintf(buf, " _t_%s[_i] = %s;\n", s->name, s->name); if (type != FUNCTION1) { Lappendstr(procfunc, "return 0;\n"); } - Lappendstr(procfunc, "}\n\n"); /* end of new function */ + Lappendstr(procfunc, "}\n\n"); /* end of new function */ /* _n_name function for table lookup with no checking */ if (type == FUNCTION1) { @@ -929,7 +896,7 @@ s->name, s->name, s->name, s->name); Lappendstr(procfunc, buf); } } - Lappendstr(procfunc, "}\n\n"); /* end of new function */ + Lappendstr(procfunc, "}\n\n"); /* end of new function */ /* table declaration */ ITERATE(q, table) { @@ -1024,9 +991,7 @@ void hocfunchack(Symbol* n, Item* qpar1, Item* qpar2, int hack) #endif } -void hocfunc(n, qpar1, qpar2) /*interface between modl and hoc for proc and func */ - Item *qpar1, *qpar2; - Symbol *n; +void hocfunc(Symbol* n, Item* qpar1, Item* qpar2) /*interface between modl and hoc for proc and func */ { /* Hack prevents FUNCTION_TABLE bug of 'double table_name()' extra args replacing the double in 'double name(...) */ @@ -1035,9 +1000,7 @@ void hocfunc(n, qpar1, qpar2) /*interface between modl and hoc for proc and func #if VECTORIZE /* ARGSUSED */ -void vectorize_use_func(qname, qpar1, qexpr, qpar2, blocktype) - Item* qname, *qpar1, *qexpr, *qpar2; - int blocktype; +void vectorize_use_func(Item* qname, Item* qpar1, Item* qexpr, Item* qpar2, int blocktype) { Item* q; if (SYM(qname)->subtype & EXTDEF) { @@ -1091,7 +1054,7 @@ diag("net_send allowed only in INITIAL and NET_RECEIVE blocks", (char*)0); if (blocktype == NETRECEIVE) { Insertstr(qpar1->next, "_pnt,"); }else{ -diag("net_event", " only allowed in NET_RECEIVE block"); +diag("net_event", "only allowed in NET_RECEIVE block"); } }else if (strcmp(SYM(qname)->name, "net_move") == 0) { if (artificial_cell) { @@ -1100,7 +1063,7 @@ diag("net_event", " only allowed in NET_RECEIVE block"); if (blocktype == NETRECEIVE) { Insertstr(qpar1->next, "_tqitem, _pnt,"); }else{ -diag("net_move", " only allowed in NET_RECEIVE block"); +diag("net_move", "only allowed in NET_RECEIVE block"); } } return; @@ -1124,9 +1087,7 @@ diag("net_move", " only allowed in NET_RECEIVE block"); #endif -void function_table(s, qpar1, qpar2, qb1, qb2) /* s ( ... ) { ... } */ - Symbol* s; - Item *qpar1, *qpar2, *qb1, *qb2; +void function_table(Symbol* s, Item* qpar1, Item* qpar2, Item* qb1, Item* qb2) /* s ( ... ) { ... } */ { Symbol* t; int i; @@ -1171,8 +1132,7 @@ void function_table(s, qpar1, qpar2, qb1, qb2) /* s ( ... ) { ... } */ hocfunchack(t, q1, q2, 1); } -void watchstmt(par1, dir, par2, flag, blocktype )Item *par1, *dir, *par2, *flag; - int blocktype; +void watchstmt(Item* par1, Item* dir, Item* par2, Item* flag, int blocktype ) { if (!watch_seen_) { ++watch_seen_; @@ -1183,7 +1143,7 @@ void watchstmt(par1, dir, par2, flag, blocktype )Item *par1, *dir, *par2, *flag; sprintf(buf, "\nstatic double _watch%d_cond(_pnt) Point_process* _pnt; {\n", watch_seen_); lappendstr(procfunc, buf); - vectorize_substitute(lappendstr(procfunc, ""),"\tdouble* _p; Datum* _ppvar; Datum* _thread; _NrnThread* _nt;\n\t_thread= (Datum*)0; _nt = (_NrnThread*)_pnt->_vnt;\n"); + vectorize_substitute(lappendstr(procfunc, ""),(char*)"\tdouble* _p; Datum* _ppvar; Datum* _thread; _NrnThread* _nt;\n\t_thread= (Datum*)0; _nt = (_NrnThread*)_pnt->_vnt;\n"); sprintf(buf, "\t_p = _pnt->_prop->param; _ppvar = _pnt->_prop->dparam;\n\tv = NODEV(_pnt->node);\n return "); lappendstr(procfunc, buf); movelist(par1, par2, procfunc); diff --git a/src/nmodl/parse1.y b/src/nmodl/parse1.y index 5c8ef4da0d..84fd8643bb 100755 --- a/src/nmodl/parse1.y +++ b/src/nmodl/parse1.y @@ -25,7 +25,7 @@ #define ldebug(arg1, arg2) qdebug(arg1, arg2->next) extern int yylex(), yyparse(); -static void yyerror(); +void yyerror(char*); #if YYBISON #define myerr(arg) static int ierr=0;\ @@ -193,10 +193,10 @@ define1: DEFINE1 NAME INTEGER sp->u.str = STR($3); sp->type = DEFINEDVAR; deltokens($1, $3);} - | DEFINE1 error {myerr("syntax: DEFINE name integer");} + | DEFINE1 error {myerr( "syntax: DEFINE name integer");} ; Name: NAME - { Symbol *checklocal(); + { Symbol *checklocal(Symbol*); SYM($1) = checklocal(SYM($1)); /* it was a bug when this was done to the lookahead token in lex */ } @@ -229,7 +229,7 @@ units: /*nothing*/ {$$ = stralloc("", (char *)0);} ; unit: '(' {$$ = inputtopar();} /*string*/ ')' /*does not include parentheses*/ - {$$ = $2; delete($1); delete($3);} + {$$ = $2; dlete($1); dlete($3);} ; uniton: UNITSON {replacstr($1, "");} | UNITSOFF {replacstr($1, "");} @@ -263,7 +263,7 @@ number: NUMBER {lastok = $1;} /* replace the string with -string and discard '-'*/ { Sprintf(buf, "-%s", STR($2)); STR($2) = stralloc(buf, STR($2)); $$ = $2; - delete($1); lastok = $2; + dlete($1); lastok = $2; } ; NUMBER: integer | REAL @@ -409,7 +409,7 @@ locallist: LOCAL Insertstr(lastok->next, ";\n"); possible_local_current(blocktype, toplocal1_); } - | LOCAL error {myerr("Illegal LOCAL declaration");} + | LOCAL error {myerr( "Illegal LOCAL declaration");} ; locallist1: NAME locoptarray /* locals are placed in a stack of symbol lists and given @@ -490,7 +490,7 @@ ostmt: fromstmt | NRNMUTEXLOCK { nrnmutex(1,$1); } | NRNMUTEXUNLOCK { nrnmutex(0,$1); } | error - {myerr("Illegal statement");} + {myerr( "Illegal statement");} ; astmt: asgn /* ';' is added when relevant */ @@ -536,14 +536,14 @@ asgn: varname '=' expr Insertstr($2, " -("); replacstr($3, ") + "); if (nstate == 0) -{yyerror("previous equation contains no state variables"); YYERROR;} +{yyerror( "previous equation contains no state variables"); YYERROR;} eqnqueue($1); } | lineqn leftlinexpr '=' linexpr { inequation = 0; - delete($3); + dlete($3); if (nstate == 0) -{yyerror("previous equation contains no state variables"); YYERROR;} +{yyerror( "previous equation contains no state variables"); YYERROR;} } ; varname: name @@ -551,7 +551,7 @@ varname: name {lastok = $1; if (!extdef2){SYM($1)->usage |= DEP;} if (SYM($1)->subtype & ARRAY && !extdef2) - {myerr("variable needs an index");} + {myerr( "variable needs an index");} if (inequation && (SYM($1)->subtype & STAT) && in_solvefor(SYM($1))) { SYM($1)->used++; nstate++; pstate++; tstate++; @@ -568,7 +568,7 @@ varname: name } SYM($1)->usage |= DEP; if ((SYM($1)->subtype & ARRAY) == 0) - {myerr("variable is not an array");} + {myerr( "variable is not an array");} if (inequation && (SYM($1)->subtype & STAT) && in_solvefor(SYM($1))) { SYM($1)->used++; nstate++; pstate++; tstate++; @@ -609,7 +609,7 @@ intexpr: Name lastok = $4; replacstr($1, " (int)"); } - | error {myerr("Illegal integer expression");} + | error {myerr( "Illegal integer expression");} ; expr: varname | real units @@ -632,7 +632,7 @@ expr: varname | expr NE expr {replacstr($2, " !=");} | NOT expr {replacstr($1, " !");} | '-' expr %prec UNARYMINUS - | error {myerr("Illegal expression");} + | error {myerr( "Illegal expression");} ; nonlineqn: NONLIN1 {inequation = 1; nstate = 0;} ; @@ -647,13 +647,13 @@ linexpr: primary /* put terms in a list */ {linterm($1, lastok, pstate, leftside); pstate = 0;} | '-' primary - {delete($1); + {dlete($1); linterm($2, lastok, pstate, -leftside); pstate = 0;} | linexpr '+' primary - {delete($2); + {dlete($2); linterm($3, lastok, pstate, leftside); pstate = 0;} | linexpr '-' primary - {delete($2); + {dlete($2); linterm($3, lastok, pstate, -leftside); pstate = 0;} ; primary: term @@ -733,7 +733,7 @@ fromstmt: FROM NAME {pushlocal(); SYM($2) = copylocal(SYM($2)); Insertstr($10, "}"); } |FROM error { -myerr("FROM intvar = intexpr TO intexpr BY intexpr { statements }");} +myerr( "FROM intvar = intexpr TO intexpr BY intexpr { statements }");} ; opinc: /*nothing*/ {$$ = ITEM0;} | BY intexpr @@ -758,7 +758,7 @@ diag("FORALL range is undefined since no arrays used", " within the statement"); Insertstr($5, "}"); } |FORALL1 error { -myerr("FORALL intvar { statements }");} +myerr( "FORALL intvar { statements }");} ; whilestmt: WHILE '(' expr ')' stmtlist '}' ; @@ -909,9 +909,9 @@ netrecblk: NETRECEIVE '(' arglist ')' nr_argcnt_ = argcnt_; /* add flag arg */ if ($3 == LIST0) { -diag("NET_RECEIVE block"," must have at least one argument"); +diag("NET_RECEIVE block",(char*)" must have at least one argument"); } - Lappendsym($3, copylocal(install("flag", NAME))); + Lappendsym($3, copylocal(install( "flag", NAME))); } stmtlist '}' { @@ -922,7 +922,7 @@ diag("NET_RECEIVE block"," must have at least one argument"); #endif poplocal(); freelist(&$3); } - | NETRECEIVE error { myerr("syntax: NET_RECEIVE ( weight ) {stmtlist}");} + | NETRECEIVE error { myerr( "syntax: NET_RECEIVE ( weight ) {stmtlist}");} ; initstmt: INITIAL1 stmtlist '}' { @@ -937,7 +937,7 @@ solveblk: SOLVE NAME ifsolerr { solvequeue($2, ITEM0, blocktype, $3); } | SOLVE NAME USING METHOD ifsolerr { solvequeue($2, $4, blocktype, $5); } - | SOLVE error { myerr("Illegal SOLVE statement");} + | SOLVE error { myerr( "Illegal SOLVE statement");} ; ifsolerr: /*nothing*/ { $$ = ITEM0; } @@ -953,11 +953,11 @@ solvefor: /*nothing*/ ; solvefor1: SOLVEFOR NAME { solveforlist = newlist(); Lappendsym(solveforlist, SYM($2)); - delete($1); delete($2); + dlete($1); dlete($2); } | solvefor1 ',' NAME - { Lappendsym(solveforlist, SYM($3)); delete($2); delete($3);} - | SOLVEFOR error { myerr("Syntax: SOLVEFOR name, name, ...");} + { Lappendsym(solveforlist, SYM($3)); dlete($2); dlete($3);} + | SOLVEFOR error { myerr( "Syntax: SOLVEFOR name, name, ...");} ; brkptblk: BREAKPOINT stmtlist '}' /* move it all to modelfunc */ @@ -974,13 +974,13 @@ bablk: BREAKPOINT stmtlist '}' {bablk(blocktype, INITIAL1, $2, $3);} | STEP stmtlist '}' {bablk(blocktype, STEP, $2, $3);} - | error {myerr("[BEFORE AFTER] [BREAKPOINT SOLVE INITIAL STEP] { stmt }");} + | error {myerr( "[BEFORE AFTER] [BREAKPOINT SOLVE INITIAL STEP] { stmt }");} ; watchstmt: WATCH watch1 - {$$ = $2; delete($1);} + {$$ = $2; dlete($1);} | watchstmt ',' watch1 - {delete($2);} - | WATCH error {myerr("WATCH (expr > expr) flag");} + {dlete($2);} + | WATCH error {myerr( "WATCH (expr > expr) flag");} ; watch1: '(' aexpr watchdir aexpr ')' real {watchstmt($1, $3, $5, $6, blocktype); $$=$6;} @@ -998,7 +998,7 @@ fornetcon: FOR_NETCONS '(' arglist ')' { } stmtlist '}' {fornetcon($1, $2, $3, $4, $6, $7); $$ = $7; } - | FOR_NETCONS error { myerr("syntax: FOR_NETCONS(args,like,netreceive) { stmtlist}");} + | FOR_NETCONS error { myerr( "syntax: FOR_NETCONS(args,like,netreceive) { stmtlist}");} ; aexpr: varname | real units @@ -1012,19 +1012,19 @@ aexpr: varname { $$ = insertstr($1, "pow("); replacstr($2, ","); lastok = insertstr(lastok->next, ")"); } | '-' aexpr %prec UNARYMINUS - | error {myerr("Illegal expression");} + | error {myerr( "Illegal expression");} ; sens: SENS senslist /* sensused flag is true */ { sensused = 1; - delete($1); + dlete($1); } - |SENS error {myerr("syntax is SENS var1, var2, var3, etc");} + |SENS error {myerr( "syntax is SENS var1, var2, var3, etc");} ; senslist: varname /* put in list. Used when enclosing block is massaged */ - { sensparm($1); delete($1);} + { sensparm($1); dlete($1);} | senslist ',' varname { sensparm($3); deltokens($2, $3);} ; @@ -1033,7 +1033,7 @@ conserve: CONSERVE {extdef2 = 0; } react '=' expr {/* react originally designed for reactions and is unchanged*/ extdef2 = 0; massageconserve($1, $4, lastok);} - | CONSERVE error {myerr("Illegal CONSERVE syntax");} + | CONSERVE error {myerr( "Illegal CONSERVE syntax");} ; compart: COMPARTMENT NAME ',' {pushlocal(); SYM($2) = copylocal(SYM($2));} @@ -1065,7 +1065,7 @@ reaction: REACTION react REACT1 {leftreact();} react '(' expr ',' expr ')' {flux($1, $3, $7);} | REACTION react '-' GT '(' expr ')' {flux($1, $3, $7);} - | REACTION error {myerr("Illegal reaction syntax");} + | REACTION error {myerr( "Illegal reaction syntax");} ; react: varname {reactname($1, lastok, ITEM0);} |integer varname {reactname($2, lastok, $1);} @@ -1074,7 +1074,7 @@ react: varname {reactname($1, lastok, ITEM0);} ; lagstmt: LAG name BY NAME {lag_stmt($1, blocktype);} - | LAG error {myerr("Lag syntax is: LAG name BY const");} + | LAG error {myerr( "Lag syntax is: LAG name BY const");} ; queuestmt: PUTQ name {queue_stmt($1, $2);} | GETQ name {queue_stmt($1, $2);} @@ -1095,7 +1095,7 @@ match: name } } | error - {myerr("MATCH syntax is state0 or state(expr)=expr or\ + {myerr( "MATCH syntax is state0 or state(expr)=expr or\ state[i](expr(i)) = expr(i)");} ; matchname: name @@ -1115,7 +1115,7 @@ unitbody: /*nothing*/ ; unitdef: unit '=' unit {install_units($1, $3);} - | unit error {myerr("Unit definition syntax: (units) = (units)");} + | unit error {myerr( "Unit definition syntax: (units) = (units)");} ; factordef: NAME '=' real unit { SYM($1)->subtype |= nmodlCONST; @@ -1135,7 +1135,7 @@ factordef: NAME '=' real unit nrnunit_dynamic_str(buf, SYM($1)->name, $3, $6); Lappendstr(firstlist, buf); } - | error {myerr("Unit factor syntax: examples:\n\ + | error {myerr( "Unit factor syntax: examples:\n\ foot2inch = (foot) -> (inch)\n\ F = 96520 (coulomb)\n\ R = (k-mole) (joule/degC)"); @@ -1166,7 +1166,7 @@ tablestmt: TABLE tablst dependlst FROM expr TO expr WITH INTEGER Lappendlst(table_list, $3); deltokens($1, $9); } - | TABLE error { myerr("syntax: TABLE [list] [DEPEND list] FROM expr TO expr WITH integer");} + | TABLE error { myerr( "syntax: TABLE [list] [DEPEND list] FROM expr TO expr WITH integer");} ; tablst: /*Nothing*/ {$$ = LIST0;} @@ -1216,16 +1216,16 @@ nrnuse: USEION NAME READ nrnlist valence optontology |USEION NAME READ nrnlist WRITE nrnlist valence optontology {nrn_use($2, $4, $6, $7);} |USEION error - {myerr("syntax is: USEION ion READ list WRITE list REPRESENTS curie");} + {myerr( "syntax is: USEION ion READ list WRITE list REPRESENTS curie");} ; optontology: { $$ = NULL; } | REPRESENTS ONTOLOGY_ID { $$ = $2; } nrnlist: NAME | nrnlist ',' NAME - { delete($2); $$ = $3;} + { dlete($2); $$ = $3;} | error - {myerr("syntax is: keyword name , name, ..., name");} + {myerr( "syntax is: keyword name , name, ..., name");} ; optnrnlist: /*nothing*/ {$$ = NULL;} @@ -1239,12 +1239,11 @@ valence: /*nothing*/ /* replace the string with -string and discard '-'*/ { Sprintf(buf, "-%s", STR($3)); STR($3) = stralloc(buf, STR($3)); $$ = $3; - delete($2); lastok = $3; + dlete($2); lastok = $3; } ; %% -void yyerror(s) /* called for yacc syntax error */ - char *s; +void yyerror(char* s) /* called for yacc syntax error */ { Fprintf(stderr, "%s:\n ", s); } diff --git a/src/nmodl/partial.c b/src/nmodl/partial.cpp similarity index 90% rename from src/nmodl/partial.c rename to src/nmodl/partial.cpp index e2f0b095e9..698a22ad00 100755 --- a/src/nmodl/partial.c +++ b/src/nmodl/partial.cpp @@ -81,17 +81,15 @@ static Symbol *pv[4]; /* DV, F, V, G */ static Item *partialcolon; static List *parinfo; /* DV, F, V, G, ~ with ident */ -void solv_partial(qsol, fun) - Item *qsol; - Symbol *fun; +void solv_partial(Item* qsol, Symbol* fun) { int i, ident; Item *q; Symbol *dspace; - if ((dspace = lookup("delta_x")) == SYM0) { - dspace = install("delta_x", NAME); - parminstall(dspace, "1", ""); + if ((dspace = lookup( "delta_x")) == SYM0) { + dspace = install( "delta_x", NAME); + parminstall(dspace, "1", "", ""); } Sprintf(buf, "%s();\n", fun->name); replacstr(qsol, buf); @@ -114,8 +112,7 @@ Sprintf(buf, "if (error=crank(%d, %s, %s, %s, delta_%s, %s, %s, _pbound%d, &_par } } -void partial_eqn(q2, q4, q8, q11) /*V' F V G*/ - Item *q2, *q4, *q8, *q11; +void partial_eqn(Item* q2, Item* q4, Item* q8, Item* q11) /*V' F V G*/ { int i, dim; Item *q; @@ -144,14 +141,14 @@ diag("Two partial equations for same state: ", SYM(q8)->name); dim = pv[2]->araydim; if (!(pv[2]->subtype & STAT)){ - diag(pv[2]->name, " is not a STATE"); + diag(pv[2]->name, "is not a STATE"); } if (strcmp(pv[2]->name, pv[0]->name + 1)) { diag(pv[2]->name, "' must be the time derivative"); } for (i=0; i<4; i++) { if (!(pv[i]->subtype & ARRAY) || (pv[i]->araydim != dim)) { - diag(pv[i]->name, " dimension differs from STATE var"); + diag(pv[i]->name, "dimension differs from STATE var"); } } replacstr(q2->prev, "\n/*where partial call goes*/\n"); @@ -164,8 +161,7 @@ static List *bnd[4]; /* for each condition consisting of symbol, list of tokens for expression in the order DEL y[0] DEL y[N] y[0] y[N]*/ -void massagepartial(q1, q2, q3, q6) /*PARTIAL NAME stmtlist '}'*/ - Item *q1, *q2, *q3, *q6; +void massagepartial(Item* q1, Item* q2, Item* q3, Item* q6) /*PARTIAL NAME stmtlist '}'*/ { int i, ident; @@ -178,8 +174,8 @@ void massagepartial(q1, q2, q3, q6) /*PARTIAL NAME stmtlist '}'*/ } if (!pv[0]) { diag( -"within the PARTIAL block must occur at least one equation with the syntax ---\n", -"~ V' = F*DEL2(V) + G\n"); + "within the PARTIAL block must occur at least one equation with the syntax ---\n", + "~ V' = F*DEL2(V) + G\n"); } if (!bndinfo) { @@ -210,7 +206,7 @@ diag("Duplicate boundary condition for ", s->name); if (bnd[i]) { /* Neumann */ if (bnd[i+2]) { /* and also dirichlet */ diag("Neumann and Dirichlet conditions", - " specified on same side"); + "specified on same side"); } } else { /* Neumann not specified */ if (!bnd[i+2]) { /* neither is dirichlet */ @@ -260,9 +256,7 @@ diag("Duplicate boundary condition for ", s->name); /* ~ optionalDEL var[index] = expr */ /* type 0 Dirichlet (no DEL), type 1 Neumann (with DEL) */ -void partial_bndry(type, qvar, qfirstlast, qexpr, qlast) - int type; - Item *qvar, *qfirstlast, *qexpr, *qlast; +void partial_bndry(int type, Item* qvar, Item* qfirstlast, Item* qexpr, Item* qlast) { int indx; Item *q; diff --git a/src/nmodl/sens.c b/src/nmodl/sens.cpp similarity index 97% rename from src/nmodl/sens.c rename to src/nmodl/sens.cpp index 2cb4cec684..afcbe7705a 100755 --- a/src/nmodl/sens.c +++ b/src/nmodl/sens.cpp @@ -103,8 +103,7 @@ static List *parmlist; extern Symbol *indepsym; int sens_parm = 0; -void sensparm(qparm) - Item *qparm; +void sensparm(Item* qparm) { if (!parmlist) parmlist = newlist(); @@ -112,17 +111,14 @@ void sensparm(qparm) sens_parm++; } -void add_sens_statelist(s) - Symbol *s; +void add_sens_statelist(Symbol* s) { if (!statelist) statelist = newlist(); Lappendsym(statelist, s); } -void sensmassage(type, qfun, fn) - int type, fn; - Item *qfun; +void sensmassage(int type, Item* qfun, int fn) { /*qfun is the list symbol for the name of the derivative block. It has a count of the number of state variables used. A copy of this symbol @@ -157,7 +153,7 @@ there is a linearsens call and we must be sure to keep proper state order */ oldfun = SYM(qfun); Sprintf(buf, "S_%s", oldfun->name); if (lookup(buf)) { - diag(buf, " is user defined and cant be used for SENS"); + diag(buf, "is user defined and cant be used for SENS"); } /*this is a time bomb*/ newfun = install(buf, oldfun->type); @@ -338,9 +334,7 @@ fn, j + nstate*i, sname, fn, j + nstate*i, dname); sens_parm = 0; } -void sens_nonlin_out(q, fun) - Item *q; - Symbol *fun; +void sens_nonlin_out(Item* q, Symbol* fun) { /* find fun in the sensinfo list and insert its statements before q */ diff --git a/src/nmodl/simultan.c b/src/nmodl/simultan.cpp similarity index 89% rename from src/nmodl/simultan.c rename to src/nmodl/simultan.cpp index 87d80e78e0..889c7dce28 100755 --- a/src/nmodl/simultan.c +++ b/src/nmodl/simultan.cpp @@ -7,12 +7,9 @@ extern int sens_parm; extern int numlist; static List *eqnq; -static int nonlin_common(); +int nonlin_common(Item*, int); -void solv_nonlin(qsol, fun, method, numeqn, listnum) - Item *qsol; - Symbol *fun, *method; - int numeqn, listnum; +void solv_nonlin(Item* qsol, Symbol* fun, Symbol* method, int numeqn, int listnum) { Sprintf(buf, "%s(%d,_slist%d, _p, %s, _dlist%d);\n", method->name, numeqn, listnum, fun->name, listnum); @@ -23,10 +20,7 @@ void solv_nonlin(qsol, fun, method, numeqn, listnum) sens_nonlin_out(qsol->next, fun); } -void solv_lineq(qsol, fun, method, numeqn, listnum) - Item *qsol; - Symbol *fun, *method; - int numeqn, listnum; +void solv_lineq(Item* qsol, Symbol* fun, Symbol* method, int numeqn, int listnum) { Sprintf(buf, " 0; %s();\n error = %s(%d, _coef%d, _p, _slist%d);\n", fun->name, method->name, numeqn, listnum, listnum); @@ -34,8 +28,7 @@ void solv_lineq(qsol, fun, method, numeqn, listnum) sens_nonlin_out(qsol->next, fun); } -void eqnqueue(q1) - Item *q1; +void eqnqueue(Item* q1) { Item *lq; @@ -53,9 +46,7 @@ static void freeqnqueue() } /* args are --- nonlinblk: NONLINEAR NAME stmtlist '}' */ -void massagenonlin(q1, q2, q3, q4, sensused) - Item *q1, *q2, *q3, *q4; - int sensused; +void massagenonlin(Item* q1, Item* q2, Item* q3, Item* q4, int sensused) { /* declare a special _counte variable to number the equations. before each equation we increment it by 1 during run time. This @@ -81,9 +72,7 @@ gives us a current equation number */ } } -static int nonlin_common(q4, sensused) /* used by massagenonlin() and mixed_eqns() */ - Item *q4; - int sensused; +int nonlin_common(Item* q4, int sensused) /* used by massagenonlin() and mixed_eqns() */ { Item *lq, *qs, *q; int i, counts = 0, counte = 0, using_array; @@ -135,7 +124,7 @@ static int nonlin_common(q4, sensused) /* used by massagenonlin() and mixed_eqns if (!using_array) { if(counte != counts) { Sprintf(buf ,"Number of equations, %d, does not equal number, %d", counte, counts); - diag(buf, " of states used"); + diag(buf, "of states used"); } } else { #if 1 /* can give message when running */ @@ -158,8 +147,7 @@ numlist, counts*(1 + sens_parm)); return counts; } -Item *mixed_eqns(q2, q3, q4) /* name, '{', '}' */ - Item *q2, *q3, *q4; +Item *mixed_eqns(Item* q2, Item* q3, Item* q4) /* name, '{', '}' */ { int counts; Item *qret; @@ -205,8 +193,7 @@ static int nstate = 0; static Symbol *linblk; static Symbol *statsym; -void init_linblk(q) /* NAME */ - Item *q; +void init_linblk(Item* q) /* NAME */ { using_array = 0; nlineq = -1; @@ -215,8 +202,7 @@ void init_linblk(q) /* NAME */ numlist++; } -void init_lineq(q1) /* the colon */ - Item *q1; +void init_lineq(Item* q1) /* the colon */ { if (strcmp(SYM(q1)->name, "~+") == 0) { replacstr(q1, ""); @@ -228,10 +214,9 @@ void init_lineq(q1) /* the colon */ static char *indexstr; /* set in lin_state_term, used in linterm */ -void lin_state_term(q1, q2) /* term last*/ - Item *q1, *q2; +void lin_state_term(Item* q1, Item* q2) /* term last*/ { - char *qconcat(); /* but puts extra ) at end */ + char *qconcat(Item*, Item*); /* but puts extra ) at end */ statsym = SYM(q1); replacstr(q1, "1.0"); @@ -256,9 +241,7 @@ void lin_state_term(q1, q2) /* term last*/ } } -void linterm(q1, q2, pstate, sign) /*primary, last ,, */ - Item *q1, *q2; - int pstate, sign; +void linterm(Item* q1, Item* q2, int pstate, int sign) /*primary, last ,, */ { char *signstr; @@ -289,9 +272,7 @@ void linterm(q1, q2, pstate, sign) /*primary, last ,, */ Insertstr(q2->next, ";\n"); } -void massage_linblk(q1, q2, q3, q4, sensused) /* LINEAR NAME stmtlist '}' */ - Item *q1, *q2, *q3, *q4; - int sensused; +void massage_linblk(Item* q1, Item* q2, Item* q3, Item* q4, int sensused) /* LINEAR NAME stmtlist '}' */ { Item *qs; Symbol *s; @@ -301,7 +282,7 @@ void massage_linblk(q1, q2, q3, q4, sensused) /* LINEAR NAME stmtlist '}' */ assert(q2); #endif if (++nlineq == 0) { - diag(linblk->name, " has no equations"); + diag(linblk->name, "has no equations"); } Sprintf(buf, "static void %s();\n", SYM(q2)->name); Linsertstr(procfunc, buf); @@ -374,8 +355,7 @@ Sprintf(buf, "if(_counte != %d) printf( \"Number of equations, %%d,\ List *solveforlist = (List *)0; -int in_solvefor(s) - Symbol *s; +int in_solvefor(Symbol* s) { Item *q; diff --git a/src/nmodl/solve.c b/src/nmodl/solve.cpp similarity index 96% rename from src/nmodl/solve.c rename to src/nmodl/solve.cpp index 17131cb3a3..d7db173f89 100755 --- a/src/nmodl/solve.c +++ b/src/nmodl/solve.cpp @@ -27,8 +27,8 @@ Symbol* cvode_nrn_cur_solve_; Symbol* cvode_nrn_current_solve_; #endif -static void whileloop(); -static void check_ss_consist(); +void whileloop(Item*, long, int); +void check_ss_consist(Item*); /* Need list of solve statements. We impress the general list structure to handle it. The element is a pointer to an @@ -37,12 +37,10 @@ item which is the first item in the statement sequence in another list. static List *solvq; /* list of the solve statement locations */ int numlist = 0; /* number of slist's */ -void solvequeue(q1, q2, blocktype, qerr) /*solve NAME=q1 [using METHOD=q2]*/ +void solvequeue(Item* q1, Item* q2, int blocktype, Item* qerr) /*solve NAME=q1 [using METHOD=q2]*/ /* q2 = 0 means method wasn't there */ /* qerr in ITEM0 or else the closing brace of an IFERROR stmt */ - Item *q1, *q2, *qerr; - int blocktype; { /* the solvq list is organized in groups of an item element followed by the method symbol( null if default to be used) */ @@ -103,13 +101,13 @@ diag("The SOLVE statement must be before the DERIVATIVE block for ", SYM(lq)->na cvode_cnexp_solve = lq; #endif } - delete(q2->prev); - delete(q2); + dlete(q2->prev); + dlete(q2); }else{ qtemp = q1->next; Lappendsym(solvq, SYM0); } - delete(q1->prev); + dlete(q1->prev); /* handle the error statement */ /* put one in if it isn't already there */ @@ -194,7 +192,7 @@ void solvhandler() case DERF: if (method == SYM0) { - method = lookup("adrunge"); + method = lookup( "adrunge"); } if (btype == BREAKPOINT && !steadystate) { /* derivatives recalculated after while loop */ @@ -215,7 +213,7 @@ fprintf(stderr, "Notice: %s is not thread safe. Complain to Hines\n", method->na break; case KINF: if (method == SYM0) { - method = lookup("_advance"); + method = lookup( "_advance"); } if (btype == BREAKPOINT && (method->subtype & DERF)) { #if VECTORIZE @@ -246,7 +244,7 @@ fprintf(stderr, "Notice: NONLINEAR is not thread safe.\n"); vectorize = 0; #endif if (method == SYM0) { - method = lookup("newton"); + method = lookup( "newton"); } solv_nonlin(qsol, fun, method, numeqn, listnum); break; @@ -256,7 +254,7 @@ fprintf(stderr, "Notice: LINEAR is not thread safe.\n"); vectorize = 0; #endif if (method == SYM0) { - method = lookup("simeq"); + method = lookup( "simeq"); } solv_lineq(qsol, fun, method, numeqn, listnum); break; @@ -351,8 +349,7 @@ fprintf(stderr, "Notice: SOLVE with ERROR is not thread safe.\n"); } } -void save_dt(q) /* save and restore the value of indepvar */ - Item *q; +void save_dt(Item* q) /* save and restore the value of indepvar */ { /*ARGSUSED*/ #if 0 /* integrators no longer increment time */ @@ -371,10 +368,7 @@ void save_dt(q) /* save and restore the value of indepvar */ char *saveindep = ""; -static void whileloop(qsol, type, ss) - Item *qsol; - long type; - int ss; +void whileloop(Item* qsol, long type, int ss) { /* no solve statement except this is allowed to change the indepvar. Time passed to integrators @@ -397,9 +391,9 @@ which is trapped in scop */ case DISCRETE: if (firstderf) { /* time dependent process so create a deltastep */ double d[3]; -#ifndef NeXT - double atof(); -#endif +//#ifndef NeXT +// double atof(); +//#endif int i; Item *q; char sval[256]; @@ -522,8 +516,7 @@ if (type == DERF) { invoke same integrator (default is advance) and DERIVATIVE blocks whenever solved must invoke the derivimplicit method. */ -static void check_ss_consist(qchk) - Item *qchk; +void check_ss_consist(Item* qchk) { Item *q; Symbol *fun, *method; diff --git a/src/nmodl/symbol.c b/src/nmodl/symbol.cpp similarity index 88% rename from src/nmodl/symbol.c rename to src/nmodl/symbol.cpp index 8a692fdb38..4229e1093f 100755 --- a/src/nmodl/symbol.c +++ b/src/nmodl/symbol.cpp @@ -17,8 +17,7 @@ void symbol_init() { } } -Symbol *lookup(s) /* find s in symbol table */ - char *s; +Symbol *lookup(char* s) /* find s in symbol table */ { Item *sp; @@ -30,8 +29,7 @@ Symbol *lookup(s) /* find s in symbol table */ return SYM0; /* 0 ==> not found */ } -Symbol *checklocal(sym) - Symbol *sym; +Symbol *checklocal(Symbol* sym) { Item *sp; List *sl; @@ -48,9 +46,7 @@ Symbol *checklocal(sym) return sym; } -Symbol *install(s, t) /* install s in the list symbol table with type t*/ - char *s; - int t; +Symbol *install(char* s, int t) /* install s in the list symbol table with type t*/ { Symbol *sp; List *sl; @@ -103,13 +99,12 @@ void poplocal() /* a lot of storage leakage here for symbols we are guaranteed sl = LST(symlistlist->next); for (i = sl->next; i != sl; i = j) { j = i->next; - delete(i); + dlete(i); } - delete(symlistlist->next); + dlete(symlistlist->next); } -Symbol *copylocal(s) - Symbol *s; +Symbol *copylocal(Symbol* s) { if (s->name[0] == '_') { Sprintf(buf, "%s", s->name); diff --git a/src/nmodl/units.c b/src/nmodl/units.cpp similarity index 82% rename from src/nmodl/units.c rename to src/nmodl/units.cpp index ce3d553024..698fb51f60 100755 --- a/src/nmodl/units.c +++ b/src/nmodl/units.cpp @@ -3,4 +3,4 @@ * Automake doesn't deal well with sources that live in other directories. * This is a quick and dirty workaround. */ -#include "../modlunit/units.c" +#include "../modlunit/units.cpp" diff --git a/src/nmodl/version.c b/src/nmodl/version.cpp similarity index 100% rename from src/nmodl/version.c rename to src/nmodl/version.cpp diff --git a/src/nrncvode/Makefile.am b/src/nrncvode/Makefile.am index 6d25eda079..828000b8c0 100755 --- a/src/nrncvode/Makefile.am +++ b/src/nrncvode/Makefile.am @@ -6,5 +6,5 @@ EXTRA_DIST = cvodeobj.cpp cvodeobj.h cvodestb.cpp \ hocevent.cpp \ tqueue.h vrecitem.h nrndaspk.h nrndaspk.cpp netcon.h \ bbtqueue.h bbtqueue.cpp rbtqueue.h rbtqueue.cpp \ - sptqueue.h sptqueue.cpp sptree.h spaux.c sptree.c spdaveb.c \ + sptqueue.h sptqueue.cpp sptree.h spaux.cpp sptree.cpp spdaveb.cpp \ sptbinq.h sptbinq.cpp diff --git a/src/nrncvode/cvodeobj.cpp b/src/nrncvode/cvodeobj.cpp index 679dbf2460..8fbfeeb9ac 100644 --- a/src/nrncvode/cvodeobj.cpp +++ b/src/nrncvode/cvodeobj.cpp @@ -4,13 +4,11 @@ #include "nrnmpi.h" -extern "C" { -void cvode_fadvance(); +extern "C" void cvode_fadvance(); void cvode_finitialize(); extern void (*nrn_multisplit_setup_)(); -} -extern "C" int hoc_return_type_code; +extern /*"C"*/ int hoc_return_type_code; #include #include @@ -49,7 +47,6 @@ static MUTDEC #include "ida/ida.h" #include "nonvintblock.h" -extern "C" { extern double dt, t; #define nt_dt nrn_threads->_dt #define nt_t nrn_threads->_t @@ -60,25 +57,26 @@ extern int nrn_modeltype(); extern int nrn_use_selfqueue_; extern int use_cachevec; extern void nrn_cachevec(int); -extern Point_process* ob2pntproc(Object*); +extern "C" Point_process* ob2pntproc(Object*); extern void (*nrnthread_v_transfer_)(NrnThread*); extern void (*nrnmpi_v_transfer_)(); extern int cvode_active_; extern NetCvode* net_cvode_instance; extern short* nrn_is_artificial_; -extern int structure_change_cnt; -extern int diam_change_cnt; +extern "C" int structure_change_cnt; +extern "C" int diam_change_cnt; #if USENCS extern void nrn2ncs_netcons(); #endif //USENCS #if PARANEURON +extern "C" { extern N_Vector N_VNew_Parallel(int comm, long int local_length, long int global_length); extern N_Vector N_VNew_NrnParallelLD(int comm, long int local_length, long int global_length); +} // extern "C" #endif -} extern bool nrn_use_fifo_queue_; #if BBTQ == 5 @@ -147,9 +145,7 @@ static double queue_mode(void* v) { return 0.; } -extern "C" { void nrn_extra_scatter_gather(int direction, int tid); -} static double re_init(void* v) { if (cvode_active_) { @@ -175,10 +171,8 @@ static double nrn_atol(void* v) { } return d->atol(); } -extern "C" { - extern Symbol* hoc_get_last_pointer_symbol(); - extern void hoc_symbol_tolerance(Symbol*, double); -} +extern Symbol* hoc_get_last_pointer_symbol(); +extern void hoc_symbol_tolerance(Symbol*, double); static double abstol(void* v) { NetCvode* d = (NetCvode*)v; @@ -524,10 +518,8 @@ static double nrn_diam_change_count(void* v) { return double(diam_change_cnt); } -extern "C" { int (*nrnpy_pysame)(Object*, Object*); extern int (*nrnpy_hoccommand_exec)(Object*); -} declarePtrList(ExtraScatterList, Object) implementPtrList(ExtraScatterList, Object) @@ -1021,7 +1013,7 @@ void Cvode::minstep(double x) { CVodeSetMinStep(mem_, x); }else{ // CVodeSetMinStep requires x > 0 but - // HMIN_DEFAULT is ZERO in cvodes.c + // HMIN_DEFAULT is ZERO in cvodes.cpp ((CVodeMem)mem_)->cv_hmin = 0.; } } @@ -1234,7 +1226,7 @@ int Cvode::interpolate(double tout) { //if (initialize_) { //printf("Cvode_%p::interpolate assert error when initialize_ is true.\n t_=%g tout=%g tout-t_ = %g\n", this, t_, tout, tout-t_); //} - assert(initialize_ == false); // or state discontinuity can be lost +assert(initialize_ == false); // or state discontinuity can be lost //printf("interpolate t_=%g tout=%g delta t_-tout=%g\n", t_, tout, t_-tout); #if 1 if (tout < t0_) { diff --git a/src/nrncvode/cvodestb.cpp b/src/nrncvode/cvodestb.cpp index 51016bd938..6f800b8327 100644 --- a/src/nrncvode/cvodestb.cpp +++ b/src/nrncvode/cvodestb.cpp @@ -12,23 +12,22 @@ class Cvode; #endif -extern "C" { -void cvode_fadvance(double); +extern "C" void cvode_fadvance(double); void cvode_finitialize(double t0); void nrncvode_set_t(double); -bool at_time(NrnThread*, double); +extern "C" bool at_time(NrnThread*, double); extern double dt, t; #define nt_t nrn_threads->_t #define nt_dt nrn_threads->_dt -extern void nrn_random_play(); +extern "C" void nrn_random_play(); extern int cvode_active_; extern int nrn_use_daspk_; NetCvode* net_cvode_instance; void deliver_net_events(NrnThread*); void nrn_deliver_events(NrnThread*); -void clear_event_queue(); +extern "C" void clear_event_queue(); void init_net_events(); void nrn_record_init(); void nrn_play_init(); @@ -36,7 +35,6 @@ void fixed_record_continuous(NrnThread* nt); void fixed_play_continuous(NrnThread* nt); void nrn_solver_prepare(); static void check_thresh(NrnThread*); -} // for fixed step thread void deliver_net_events(NrnThread* nt) { @@ -56,7 +54,7 @@ void nrn_deliver_events(NrnThread* nt) { nt->_t = tsav; } -void clear_event_queue() { +extern "C" void clear_event_queue() { if (net_cvode_instance) { net_cvode_instance->clear_events(); } @@ -98,11 +96,12 @@ void nrn_solver_prepare() { } } -void cvode_fadvance(double tstop) { // tstop = -1 means single step +extern "C" int v_structure_change; + +extern "C" void cvode_fadvance(double tstop) { // tstop = -1 means single step #if USECVODE int err; extern int tree_changed; - extern int v_structure_change; extern int diam_changed; if (net_cvode_instance) { if (tree_changed || v_structure_change || diam_changed) { @@ -128,7 +127,7 @@ void cvode_finitialize(double t0){ #endif } -bool at_time(NrnThread* nt, double te) { +extern "C" bool at_time(NrnThread* nt, double te) { #if USECVODE if (cvode_active_ && nt->_vcv) { return ((Cvode*)nt->_vcv)->at_time(te, nt); diff --git a/src/nrncvode/cvtrset.cpp b/src/nrncvode/cvtrset.cpp index 81d48a0210..133da8664e 100755 --- a/src/nrncvode/cvtrset.cpp +++ b/src/nrncvode/cvtrset.cpp @@ -1,4 +1,4 @@ -#include <../../nrnconf.h> +#include "nrnconf.h" #include #include #include @@ -8,14 +8,12 @@ #include "nonvintblock.h" typedef int (*Pfridot)(...); -extern "C" { #include "membfunc.h" #include "neuron.h" extern int diam_changed; extern int tree_changed; -} void Cvode::rhs(NrnThread* _nt) { int i; diff --git a/src/nrncvode/hocevent.cpp b/src/nrncvode/hocevent.cpp index 4ae572661d..dba421ba8c 100755 --- a/src/nrncvode/hocevent.cpp +++ b/src/nrncvode/hocevent.cpp @@ -4,9 +4,7 @@ #include #include -extern "C" { extern int cvode_active_; -} declarePool(HocEventPool, HocEvent) implementPool(HocEventPool, HocEvent) diff --git a/src/nrncvode/netcon.h b/src/nrncvode/netcon.h index 47a7e8a7f8..0a98beb8a5 100644 --- a/src/nrncvode/netcon.h +++ b/src/nrncvode/netcon.h @@ -370,8 +370,6 @@ class NetParEvent : public DiscreteEvent { int ithread_; // for pr() }; -extern "C" { extern PreSyn* nrn_gid2outputpresyn(int gid); -} #endif diff --git a/src/nrncvode/netcvode.cpp b/src/nrncvode/netcvode.cpp index 5340639a6f..9eda3c0bb0 100644 --- a/src/nrncvode/netcvode.cpp +++ b/src/nrncvode/netcvode.cpp @@ -59,11 +59,12 @@ typedef void (*ReceiveFunc)(Point_process*, double*, double); // needs to be fired to execute the NET_RECEIVE block. //#define POINT_RECEIVE(type, tar, w, f) ns->point_receive(type, tar, w, f) -extern "C" { #include "membfunc.h" extern void single_event_run(); extern void setup_topology(), v_setup_vectors(); -extern int structure_change_cnt, v_structure_change, tree_changed, nrn_matrix_cnt_; +extern "C" int structure_change_cnt; +extern int v_structure_change; +extern int tree_changed, nrn_matrix_cnt_; extern int diam_changed; extern int nrn_errno_check(int); extern void nrn_ba(NrnThread*, int); @@ -83,21 +84,21 @@ extern ReceiveFunc* pnt_receive_init; extern short* pnt_receive_size; extern short* nrn_is_artificial_; // should be bool but not using that type in c extern short* nrn_artcell_qindex_; -void net_send(void**, double*, Point_process*, double, double); -void net_move(void**, Point_process*, double); -void artcell_net_send(void**, double*, Point_process*, double, double); -void artcell_net_move(void**, Point_process*, double); +extern "C" void net_send(void**, double*, Point_process*, double, double); +extern "C" void net_move(void**, Point_process*, double); +//void artcell_net_send(void**, double*, Point_process*, double, double); +//void artcell_net_move(void**, Point_process*, double); int nrn_use_selfqueue_; void nrn_pending_selfqueue(double tt, NrnThread*); static void all_pending_selfqueue(double tt); static void* pending_selfqueue(NrnThread*); -void net_event(Point_process*, double); -void _nrn_watch_activate(Datum*, double (*)(Point_process*), int, Point_process*, int, double); -void _nrn_free_watch(Datum*, int, int); +//void net_event(Point_process*, double); +extern "C" void _nrn_watch_activate(Datum*, double (*)(Point_process*), int, Point_process*, int, double); +extern "C" void _nrn_free_watch(Datum*, int, int); extern int hoc_araypt(Symbol*, int); extern int hoc_stacktype(); -extern Point_process* ob2pntproc(Object*); -extern Point_process* ob2pntproc_0(Object*); +extern "C" Point_process* ob2pntproc(Object*); +extern "C" Point_process* ob2pntproc_0(Object*); void nrn_use_daspk(int); extern int nrn_use_daspk_; int linmod_extra_eqn_count(); @@ -109,25 +110,25 @@ extern hoc_Item* net_cvode_instance_psl(); extern PlayRecList* net_cvode_instance_prl(); extern void nrn_update_ps2nt(); extern void nrn_use_busywait(int); -extern double* nrn_recalc_ptr(double*); +extern "C" double* nrn_recalc_ptr(double*); void* nrn_interthread_enqueue(NrnThread*); extern void (*nrnthread_v_transfer_)(NrnThread*); Object* (*nrnpy_seg_from_sec_x)(Section*, double); -void nrnthread_get_trajectory_requests(int tid, int& bsize, int& n_pr, void**& vpr, int& n_trajec, int*& types, int*& indices, double**& pvars, double**& varrays); -void nrnthread_trajectory_values(int tid, int n_pr, void** vpr, double t); -void nrnthread_trajectory_return(int tid, int n_pr, int vecsz, void** vpr, double t); +extern "C" void nrnthread_get_trajectory_requests(int tid, int& bsize, int& n_pr, void**& vpr, int& n_trajec, int*& types, int*& indices, double**& pvars, double**& varrays); +extern "C" void nrnthread_trajectory_values(int tid, int n_pr, void** vpr, double t); +extern "C" void nrnthread_trajectory_return(int tid, int n_pr, int vecsz, void** vpr, double t); bool nrn_trajectory_request_per_time_step_ = false; #if NRN_MUSIC extern void nrnmusic_injectlist(void*, double); #endif -extern "C" int hoc_return_type_code; +extern /*"C"*/ int hoc_return_type_code; extern int nrn_fornetcon_cnt_; extern int* nrn_fornetcon_index_; extern int* nrn_fornetcon_type_; void _nrn_free_fornetcon(void**); -int _nrn_netcon_args(void*, double***); +//int _nrn_netcon_args(void*, double***); // for use in mod files double nrn_netcon_get_delay(NetCon* nc) { return nc->delay_; } @@ -136,7 +137,7 @@ int nrn_netcon_weight(NetCon* nc, double** pw) { *pw = nc->weight_; return nc->cnt_; } -double nrn_event_queue_stats(double* stats) { +extern "C" double nrn_event_queue_stats(double* stats) { #if COLLECT_TQueue_STATISTICS net_cvode_instance_event_queue(nrn_threads)->spike_stat(stats); return (stats[0]-stats[2]); @@ -236,7 +237,6 @@ void nrn2ncs_netcons(); #if NRNMPI extern void nrn2ncs_outputevent(int netcon_output_index, double firetime); #endif -}; //extern "C" #if BGPDMA extern void bgp_dma_send(PreSyn*, double t); @@ -2285,7 +2285,7 @@ int Cvode::handle_step(NetCvode* ns, double te) { return err; } -void net_move(void** v, Point_process* pnt, double tt) { +extern "C" void net_move(void** v, Point_process* pnt, double tt) { if (!(*v)) { hoc_execerror( "No event with flag=1 for net_move in ", hoc_object_name(pnt->ob)); } @@ -2302,7 +2302,7 @@ void net_move(void** v, Point_process* pnt, double tt) { net_cvode_instance->move_event(q, tt, PP2NT(pnt)); } -void artcell_net_move(void** v, Point_process* pnt, double tt) { +extern "C" void artcell_net_move(void** v, Point_process* pnt, double tt) { if (nrn_use_selfqueue_) { if (!(*v)) { hoc_execerror( "No event with flag=1 for net_move in ", hoc_object_name(pnt->ob)); @@ -2357,7 +2357,7 @@ void NetCvode::remove_event(TQItem* q, int tid) { // for threads, revised net_send to use absolute time (in the // mod file we add the thread time when we call it). -void net_send(void** v, double* weight, Point_process* pnt, double td, double flag) { +extern "C" void net_send(void** v, double* weight, Point_process* pnt, double td, double flag) { STATISTICS(SelfEvent::selfevent_send_); NrnThread* nt = PP2NT(pnt); NetCvodeThreadData& p = net_cvode_instance->p[nt->id]; @@ -2392,7 +2392,7 @@ void net_send(void** v, double* weight, Point_process* pnt, double td, double fl //printf("net_send %g %s %g %p\n", td, hoc_object_name(pnt->ob), flag, *v); } -void artcell_net_send(void** v, double* weight, Point_process* pnt, double td, double flag) { +extern "C" void artcell_net_send(void** v, double* weight, Point_process* pnt, double td, double flag) { if (nrn_use_selfqueue_ && flag == 1.0) { STATISTICS(SelfEvent::selfevent_send_); NrnThread* nt = PP2NT(pnt); @@ -2426,7 +2426,7 @@ void artcell_net_send(void** v, double* weight, Point_process* pnt, double td, d } } -void net_event(Point_process* pnt, double time) { +extern "C" void net_event(Point_process* pnt, double time) { STATISTICS(net_event_cnt_); PreSyn* ps = (PreSyn*)pnt->presyn_; if (ps) { @@ -2448,7 +2448,7 @@ void net_event(Point_process* pnt, double time) { } } -void _nrn_watch_activate(Datum* d, double (*c)(Point_process*), int i, Point_process* pnt, int r, double flag) { +extern "C" void _nrn_watch_activate(Datum* d, double (*c)(Point_process*), int i, Point_process* pnt, int r, double flag) { // printf("_nrn_cond_activate %s flag=%g first return = %g\n", hoc_object_name(pnt->ob), flag, c(pnt)); if (!d->_pvoid) { d->_pvoid = (void*)new WatchList(); @@ -2474,7 +2474,7 @@ void _nrn_watch_activate(Datum* d, double (*c)(Point_process*), int i, Point_pro wc->activate(flag); } -void _nrn_free_watch(Datum* d, int offset, int n) { +extern "C" void _nrn_free_watch(Datum* d, int offset, int n) { int i; int nn = offset + n; if (d[offset]._pvoid) { @@ -4044,14 +4044,14 @@ ForNetConsInfo* fnc = (ForNetConsInfo*)pnt->prop->dparam[t2i[pnt->prop->type]]._ delete [] t2i; } -int _nrn_netcon_args(void* v, double*** argslist) { +extern "C" int _nrn_netcon_args(void* v, double*** argslist) { ForNetConsInfo* fnc = (ForNetConsInfo*)v; assert(fnc); *argslist = fnc->argslist; return fnc->size; } -void _nrn_free_fornetcon(void** v) { +extern "C" void _nrn_free_fornetcon(void** v) { ForNetConsInfo* fnc = (ForNetConsInfo*)(*v); if (fnc) { if (fnc->argslist) { @@ -4062,12 +4062,10 @@ void _nrn_free_fornetcon(void** v) { } } -extern "C" { void record_init_clear(const TQItem* q, int) { DiscreteEvent* d = (DiscreteEvent*)q->data_; d->frecord_init((TQItem*)q); } -}; void NetCvode::record_init() { int i, cnt = prl_->count(); diff --git a/src/nrncvode/nrndaspk.cpp b/src/nrncvode/nrndaspk.cpp index 4b2a25ef53..65d329af8e 100755 --- a/src/nrncvode/nrndaspk.cpp +++ b/src/nrncvode/nrndaspk.cpp @@ -7,9 +7,7 @@ #include #include #include -extern "C" { #include "spmatrix.h" -} #include "nrnoc2iv.h" #include "cvodeobj.h" #include "nrndaspk.h" @@ -29,7 +27,6 @@ static int solve_state_; double Daspk::dteps_; -extern "C" { extern void nrndae_dkres(double*, double*, double*); extern void nrndae_dkpsol(double); @@ -37,10 +34,12 @@ extern void nrn_rhs(NrnThread*); extern void nrn_lhs(NrnThread*); extern void nrn_solve(NrnThread*); void nrn_daspk_init_step(double, double, int); -// this is private in ida.c but we want to check if our initialization +// this is private in ida.cpp but we want to check if our initialization // is good. Unfortunately ewt is set on the first call to solve which // is too late for us. +extern "C" { extern booleantype IDAEwtSet(IDAMem IDA_mem, N_Vector ycur); +} // extern "C" //extern double t, dt; #define nt_dt nrn_threads->_dt @@ -67,7 +66,6 @@ static int msolve(IDAMem mem, N_Vector b, N_Vector ycur, N_Vector ypcur, static int mfree(IDAMem); -} // at least in DARWIN the following is already declared so avoid conflict @@ -494,7 +492,7 @@ for (i=0; i < z.nvsize_; ++i) { printf(" %d %g %g %g\n", i, y[i], yprime[i], delta[i]); } #endif - // the cap nodes : see nrnoc/capac.c for location of cm, etc. + // the cap nodes : see nrnoc/capac.cpp for location of cm, etc. // these are not in same order as for cvode but are in // spmatrix order mixed with nocap nodes and extracellular // therefore we use the Node.eqn_index to calculate the delta index. @@ -536,7 +534,7 @@ for (i=0; i < z.nvsize_; ++i) { } } } - // See nrnoc/excelln.c for location of cx. + // See nrnoc/excelln.cpp for location of cx. if (z.cmlext_) { Memb_list* ml = z.cmlext_->ml; int n = ml->nodecount; @@ -638,7 +636,7 @@ printf("\n"); scatter_ydot(b, _nt->id); #if 0 printf("before nrn_solve matrix cj=%g\n", cj); -spPrint((char*)sp13mat_, 1,1,1); +spPrint(sp13mat_, 1,1,1); printf("before nrn_solve actual_rhs=\n"); for (i=0; i < z.neq_v_; ++i) { printf("%d %g\n", i+1, actual_rhs[i+1]); @@ -647,7 +645,7 @@ for (i=0; i < z.neq_v_; ++i) { daspk_nrn_solve(_nt); // not the cvode one #if 0 //printf("after nrn_solve matrix\n"); -//spPrint((char*)sp13mat_, 1,1,1); +//spPrint(sp13mat_, 1,1,1); printf("after nrn_solve actual_rhs=\n"); for (i=0; i < neq_v_; ++i) { printf("%d %g\n", i+1, actual_rhs[i+1]); diff --git a/src/nrncvode/occvode.cpp b/src/nrncvode/occvode.cpp index bbf12df2cc..faff8ead3a 100644 --- a/src/nrncvode/occvode.cpp +++ b/src/nrncvode/occvode.cpp @@ -12,7 +12,6 @@ #include "membfunc.h" #include "nonvintblock.h" typedef int (*Pfridot)(...); -extern "C" { extern void setup_topology(), v_setup_vectors(); extern void nrn_mul_capacity(NrnThread*, Memb_list*); extern void nrn_div_capacity(NrnThread*, Memb_list*); @@ -47,7 +46,6 @@ extern void nrn_multisplit_adjust_rhs(NrnThread*); #if PARANEURON extern void (*nrn_multisplit_solve_)(); #endif -}; static Symbol* vsym; // for absolute tolerance #define SETUP 1 @@ -58,7 +56,7 @@ J=df/dy. The NEURON fixed step method sets up C*dv/dt = F(v) by first calculating F(v) and storing it on the right hand side of -the matrix equation ( see src/nrnoc/treeset.c nrn_rhs() ). +the matrix equation ( see src/nrnoc/treeset.cpp nrn_rhs() ). It then sets up the left hand side of the matrix equation using nrn_set_cj(1./dt); setup1_tree_matrix(); setup2_tree_matrix(); to form @@ -451,9 +449,7 @@ double* Cvode::n_vector_data(N_Vector v, int tid) { return N_VGetArrayPointer(v); } -extern "C" { extern void nrn_extra_scatter_gather(int, int); -} void Cvode::scatter_y(double* y, int tid){ int i; @@ -690,7 +686,7 @@ void Cvode::fun_thread_transfer_part2(double* ydot, NrnThread* nt){ } #endif before_after(z.before_breakpoint_, nt); - rhs(nt); // similar to nrn_rhs in treeset.c + rhs(nt); // similar to nrn_rhs in treeset.cpp #if PARANEURON if (nrn_multisplit_solve_) { // non-zero area nodes need an adjustment nrn_multisplit_adjust_rhs(nt); @@ -749,7 +745,7 @@ void Cvode::fun_thread_ms_part4(double* ydot, NrnThread* nt) { CvodeThreadData& z = ctd_[nt->id]; if (z.nvsize_ == 0) { return; } before_after(z.before_breakpoint_, nt); - rhs(nt); // similar to nrn_rhs in treeset.c + rhs(nt); // similar to nrn_rhs in treeset.cpp nrn_multisplit_adjust_rhs(nt); do_ode(nt); // divide by cm and compute capacity current @@ -918,7 +914,7 @@ static void* nonode_thread(NrnThread* nt) { return 0; } void Cvode::do_nonode(NrnThread* _nt) { // all the hacked integrators, etc, in SOLVE procedure -//almost a verbatim copy of nonvint in fadvance.c +//almost a verbatim copy of nonvint in fadvance.cpp if (!_nt) { if (nrn_nthread > 1) { nonode_cv = this; diff --git a/src/nrncvode/spaux.c b/src/nrncvode/spaux.cpp similarity index 98% rename from src/nrncvode/spaux.c rename to src/nrncvode/spaux.cpp index 434c2def18..4efa44e146 100755 --- a/src/nrncvode/spaux.c +++ b/src/nrncvode/spaux.cpp @@ -1,5 +1,5 @@ /* - spaux.c: This code implements the following operations on an event-set + spaux.cpp: This code implements the following operations on an event-set or priority-queue implemented using splay trees: n = sphead( q ) n is the head item in q (not removed). @@ -13,7 +13,7 @@ SPBLK *); q is an event-set (type SPTREE *), The type definitions for these are taken from file sptree.h. All of these operations rest on basic - splay tree operations from file sptree.c. + splay tree operations from file sptree.cpp. The basic splay tree algorithms were originally presented in: diff --git a/src/nrncvode/spdaveb.c b/src/nrncvode/spdaveb.cpp similarity index 99% rename from src/nrncvode/spdaveb.c rename to src/nrncvode/spdaveb.cpp index 0880341bd0..79fea57542 100755 --- a/src/nrncvode/spdaveb.c +++ b/src/nrncvode/spdaveb.cpp @@ -1,5 +1,5 @@ /* - * spdaveb.c -- daveb's new splay tree functions. + * spdaveb.cpp -- daveb's new splay tree functions. * * The functions in this file provide an interface that is nearly * the same as the hash library I swiped from mkmf, allowing diff --git a/src/nrncvode/spt2queue.cpp b/src/nrncvode/spt2queue.cpp index b63db65c8d..79d96310c8 100644 --- a/src/nrncvode/spt2queue.cpp +++ b/src/nrncvode/spt2queue.cpp @@ -255,7 +255,7 @@ double TQueue::q2least_t() { return 1e50; // must be larger than any possible t } -#include -#include -#include +#include +#include +#include diff --git a/src/nrncvode/sptbinq.cpp b/src/nrncvode/sptbinq.cpp index b7eff5367e..b7c5269fc0 100644 --- a/src/nrncvode/sptbinq.cpp +++ b/src/nrncvode/sptbinq.cpp @@ -23,10 +23,8 @@ of struct _spblk, we are really using TQItem #define key t_ #include -extern "C" { //extern double dt; #define nt_dt nrn_threads->_dt -} void (*nrn_binq_enqueue_error_handler)(double, TQItem*); @@ -387,7 +385,7 @@ void BinQ::remove(TQItem* q) { } } -#include -#include -#include +#include +#include +#include diff --git a/src/nrncvode/sptfifoq.cpp b/src/nrncvode/sptfifoq.cpp index 024aa40b5b..c4af2a2dec 100644 --- a/src/nrncvode/sptfifoq.cpp +++ b/src/nrncvode/sptfifoq.cpp @@ -302,7 +302,7 @@ TQItem* FifoQ::next(TQItem* q) { return q->right_; } -#include -#include -#include +#include +#include +#include diff --git a/src/nrncvode/sptqueue.cpp b/src/nrncvode/sptqueue.cpp index 429ea12634..3190112e85 100644 --- a/src/nrncvode/sptqueue.cpp +++ b/src/nrncvode/sptqueue.cpp @@ -234,7 +234,7 @@ TQItem* TQueue::find(double t) { return(q); } -#include -#include -#include +#include +#include +#include diff --git a/src/nrncvode/sptree.c b/src/nrncvode/sptree.cpp similarity index 99% rename from src/nrncvode/sptree.c rename to src/nrncvode/sptree.cpp index 7400d59648..21be66dde5 100755 --- a/src/nrncvode/sptree.c +++ b/src/nrncvode/sptree.cpp @@ -1,6 +1,6 @@ /* * - * sptree.c: The following code implements the basic operations on + * sptree.cpp: The following code implements the basic operations on * an event-set or priority-queue implemented using splay trees: * Hines changed to void spinit(SPTREE**) for use with TQueue. diff --git a/src/nrncvode/sptree.h b/src/nrncvode/sptree.h index 4fc81e9360..8274530024 100755 --- a/src/nrncvode/sptree.h +++ b/src/nrncvode/sptree.h @@ -75,7 +75,7 @@ typedef struct SPTREE #define spfprev sptq_spfprev #define spstats sptq_spstats -/* sptree.c */ +/* sptree.cpp */ extern void spinit(SPTREE*); /* init tree */ extern int spempty(SPTREE*); /* is tree empty? */ extern SPBLK * spenq(SPBLK*, SPTREE*); /* insert item into the tree */ @@ -83,7 +83,7 @@ extern SPBLK * spdeq(SPBLK**); /* return and remove lowest item in subtree */ extern SPBLK * spenqprior(SPBLK*, SPTREE*);/* insert before items with same key */ extern void splay(SPBLK*, SPTREE*); /* reorganize tree */ -/* spaux.c */ +/* spaux.cpp */ extern SPBLK * sphead(SPTREE*); /* return first node in tree */ extern void spdelete(SPBLK*, SPTREE*); /* delete node from tree */ extern SPBLK * spnext(SPBLK*, SPTREE*); /* return next node in tree */ @@ -91,7 +91,7 @@ extern SPBLK * spprev(SPBLK*, SPTREE*); /* return previous node in tree */ extern SPBLK * spenqbefore(SPBLK*, SPBLK*, SPTREE*); /* enqueue before existing node */ extern SPBLK * spenqafter(SPBLK*, SPBLK*, SPTREE*); /* enqueue after existing node */ -/* spdaveb.c */ +/* spdaveb.cpp */ extern SPBLK * splookup(double, SPTREE*); /* find key in a tree */ /*extern SPBLK * spinstall(double, void*, SPTREE*);*/ /* enter an item, allocating or replacing */ extern SPBLK * sptail(SPTREE*); /* find end of a tree */ diff --git a/src/nrniv/CMakeLists.txt b/src/nrniv/CMakeLists.txt index ccd28e35d8..1abfe892a7 100644 --- a/src/nrniv/CMakeLists.txt +++ b/src/nrniv/CMakeLists.txt @@ -15,9 +15,9 @@ # ============================================================================= # Build modlunit : Mod file units checker # ============================================================================= -flex_target(modlunitlexer ${NRN_MODLUNIT_SRC_DIR}/lex.l ${NRN_MODLUNIT_SRC_DIR}/lex.c) +flex_target(modlunitlexer ${NRN_MODLUNIT_SRC_DIR}/lex.l ${NRN_MODLUNIT_SRC_DIR}/lex.cpp) -bison_target(modlunitparser ${NRN_MODLUNIT_SRC_DIR}/parse1.y ${NRN_MODLUNIT_SRC_DIR}/parse1.c +bison_target(modlunitparser ${NRN_MODLUNIT_SRC_DIR}/parse1.y ${NRN_MODLUNIT_SRC_DIR}/parse1.cpp DEFINES_FILE ${NRN_MODLUNIT_SRC_DIR}/parse1.h) set_property( @@ -30,12 +30,12 @@ add_executable(modlunit ${NRN_MODLUNIT_SRC_FILES}) # ============================================================================= # Build nocmodl : source-to-source compiler for NMODL # ============================================================================= -flex_target(nocmodllexer ${NRN_NMODL_SRC_DIR}/lex.l ${NRN_NMODL_SRC_DIR}/lex.c) +flex_target(nocmodllexer ${NRN_NMODL_SRC_DIR}/lex.l ${NRN_NMODL_SRC_DIR}/lex.cpp) -bison_target(nocmodlparser ${NRN_NMODL_SRC_DIR}/parse1.y ${NRN_NMODL_SRC_DIR}/parse1.c DEFINES_FILE +bison_target(nocmodlparser ${NRN_NMODL_SRC_DIR}/parse1.y ${NRN_NMODL_SRC_DIR}/parse1.cpp DEFINES_FILE ${NRN_NMODL_SRC_DIR}/parse1.h) -bison_target(nocmodlparser ${NRN_NMODL_SRC_DIR}/diffeq.y ${NRN_NMODL_SRC_DIR}/diffeq.c DEFINES_FILE +bison_target(nocmodlparser ${NRN_NMODL_SRC_DIR}/diffeq.y ${NRN_NMODL_SRC_DIR}/diffeq.cpp DEFINES_FILE ${NRN_NMODL_SRC_DIR}/diffeq.h) set_property( @@ -59,7 +59,7 @@ set_source_files_properties(${NRN_MODFILE_C} PROPERTIES GENERATED TRUE) # ============================================================================= # Bison parser for HOC interpreter # ============================================================================= -bison_target(ocparser ${NRN_OC_SRC_DIR}/parse.y ${NRN_OC_SRC_DIR}/parse.c DEFINES_FILE +bison_target(ocparser ${NRN_OC_SRC_DIR}/parse.y ${NRN_OC_SRC_DIR}/parse.cpp DEFINES_FILE ${NRN_OC_SRC_DIR}/parse.h) # ============================================================================= @@ -83,7 +83,7 @@ if(NRN_ENABLE_MPI) endif() if(NRN_ENABLE_MPI_DYNAMIC) - list(APPEND NRN_NRNIV_LIB_SRC_FILES ${PROJECT_SOURCE_DIR}/src/nrnmpi/nrnmpi_dynam.c) + list(APPEND NRN_NRNIV_LIB_SRC_FILES ${PROJECT_SOURCE_DIR}/src/nrnmpi/nrnmpi_dynam.cpp) else() list(APPEND NRN_NRNIV_LIB_SRC_FILES ${NRN_NRNMPI_SRC_FILES}) endif() @@ -146,7 +146,7 @@ add_custom_target( add_custom_command(OUTPUT ${NRN_NRNOC_SRC_DIR}/nrnversion.h DEPENDS nrnversion_h) -# avoid error with nvector_serial.c for #include <../../../nrnconf.h> +# avoid error with nvector_serial.cpp for #include <../../../nrnconf.h> file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/src/sundials/shared) # generate hocusr.h @@ -180,13 +180,13 @@ set_property( PROPERTY COMPILE_DEFINITIONS OOP=1 HOC=1 INTERVIEWS=1) set_property( - SOURCE ${NRN_NRNOC_SRC_DIR}/code.c ${NRN_NRNOC_SRC_DIR}/hoc_init.c ${NRN_NRNOC_SRC_DIR}/hoc_oop.c + SOURCE ${NRN_NRNOC_SRC_DIR}/code.cpp ${NRN_NRNOC_SRC_DIR}/hoc_init.cpp ${NRN_NRNOC_SRC_DIR}/hoc_oop.cpp APPEND PROPERTY COMPILE_DEFINITIONS CABLE=1) set_property( SOURCE ${PROJECT_SOURCE_DIR}/src/nrniv/nrnpy.cpp - ${PROJECT_SOURCE_DIR}/src/nrnmpi/nrnmpi_dynam.c + ${PROJECT_SOURCE_DIR}/src/nrnmpi/nrnmpi_dynam.cpp ${PROJECT_SOURCE_DIR}/src/nrnpython/nrnpython.cpp APPEND PROPERTY COMPILE_DEFINITIONS NRNCMAKE) @@ -218,14 +218,14 @@ set_property( if(DEF_RL_GETC_FUNCTION) set_property( - SOURCE ${NRN_OC_SRC_DIR}/hoc.c + SOURCE ${NRN_OC_SRC_DIR}/hoc.cpp APPEND PROPERTY COMPILE_DEFINITIONS ${DEF_RL_GETC_FUNCTION}) endif() if(NRN_USE_BACKWARD) set_property( - SOURCE ${NRN_OC_SRC_DIR}/hoc.c + SOURCE ${NRN_OC_SRC_DIR}/hoc.cpp APPEND PROPERTY COMPILE_DEFINITIONS USE_BACKWARD=1) set_property( @@ -234,21 +234,21 @@ if(NRN_USE_BACKWARD) PROPERTY COMPILE_DEFINITIONS USE_BACKWARD=1) endif() -set_source_files_properties(${NRN_NRNOC_SRC_DIR}/code.c PROPERTIES OBJECT_DEPENDS +set_source_files_properties(${NRN_NRNOC_SRC_DIR}/code.cpp PROPERTIES OBJECT_DEPENDS ${NRN_OC_SRC_DIR}/parse.h) -set_source_files_properties(${NRN_NRNOC_SRC_DIR}/nrnversion.c PROPERTIES OBJECT_DEPENDS +set_source_files_properties(${NRN_NRNOC_SRC_DIR}/nrnversion.cpp PROPERTIES OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/nrnoc/nrnversion.h) -set_source_files_properties(${NRN_OC_SRC_DIR}/hocusr.c PROPERTIES OBJECT_DEPENDS +set_source_files_properties(${NRN_OC_SRC_DIR}/hocusr.cpp PROPERTIES OBJECT_DEPENDS ${PROJECT_BINARY_DIR}/src/nrnoc/hocusr.h) if(NRN_ENABLE_MPI_DYNAMIC) - set_source_files_properties(${PROJECT_SOURCE_DIR}/src/nrnmpi/nrnmpi_dynam.c PROPERTIES + set_source_files_properties(${PROJECT_SOURCE_DIR}/src/nrnmpi/nrnmpi_dynam.cpp PROPERTIES OBJECT_DEPENDS ${NRNMPI_DYNAMIC_INCLUDE_FILE}) - set_source_files_properties(${PROJECT_SOURCE_DIR}/src/nrnmpi/nrnmpi.c PROPERTIES OBJECT_DEPENDS + set_source_files_properties(${PROJECT_SOURCE_DIR}/src/nrnmpi/nrnmpi.cpp PROPERTIES OBJECT_DEPENDS ${NRNMPI_DYNAMIC_INCLUDE_FILE}) - set_source_files_properties(${PROJECT_SOURCE_DIR}/src/nrnmpi/bbsmpipack.c PROPERTIES + set_source_files_properties(${PROJECT_SOURCE_DIR}/src/nrnmpi/bbsmpipack.cpp PROPERTIES OBJECT_DEPENDS ${NRNMPI_DYNAMIC_INCLUDE_FILE}) endif() @@ -335,7 +335,7 @@ if(IV_ENABLE_X11_DYNAMIC) # ~~~ set_property( SOURCE ${PROJECT_SOURCE_DIR}/src/ivoc/ivocmain.cpp ${PROJECT_SOURCE_DIR}/src/pwman/xdep.cpp - ${PROJECT_SOURCE_DIR}/src/ivoc/xdep.cpp ${PROJECT_SOURCE_DIR}/src/oc/x.c + ${PROJECT_SOURCE_DIR}/src/ivoc/xdep.cpp ${PROJECT_SOURCE_DIR}/src/oc/x.cpp APPEND PROPERTY COMPILE_DEFINITIONS IVX11_DYNAM) if((NOT IV_ENABLE_SHARED) AND IV_LIB_DIR) diff --git a/src/nrniv/Makefile.am b/src/nrniv/Makefile.am index 4b6a9e75f2..35f8a1c160 100755 --- a/src/nrniv/Makefile.am +++ b/src/nrniv/Makefile.am @@ -5,7 +5,7 @@ lib_LTLIBRARIES = libnrniv.la bin_PROGRAMS = nrniv nsrc=$(top_srcdir)/src -PARSRC = nvector_nrnparallel_ld.c +PARSRC = nvector_nrnparallel_ld.cpp PARINC = nvector_nrnparallel_ld.h if BUILD_PARANEURON @@ -70,7 +70,7 @@ cygexe = endif endif -## These are all the .c files that need to be compiled to make libnrniv.la. +## These are all the .cpp files that need to be compiled to make libnrniv.la. libnrniv_la_SOURCES = nrnmenu.cpp shape.cpp classreg.cpp rotate3d.cpp \ datapath.cpp symdir.cpp spaceplt.cpp shapeplt.cpp ppshape.cpp \ @@ -82,9 +82,9 @@ libnrniv_la_SOURCES = nrnmenu.cpp shape.cpp classreg.cpp rotate3d.cpp \ bbsrcli.cpp bbsdirect.cpp bbslsrv2.cpp bbssrv.cpp \ linmod.cpp linmod1.cpp cachevec.cpp \ kschan.cpp kssingle.cpp nonlinz.cpp finithnd.cpp nrnste.cpp \ - nrnrtime.cpp nvector_nrnthread.c nrnpy.cpp prcellstate.cpp \ - nvector_nrnthread_ld.c nvector_nrnserial_ld.c \ - $(PARSRC1) bgpmeminfo.c \ + nrnrtime.cpp nvector_nrnthread.cpp nrnpy.cpp prcellstate.cpp \ + nvector_nrnthread_ld.cpp nvector_nrnserial_ld.cpp \ + $(PARSRC1) bgpmeminfo.cpp \ netpar.cpp partrans.cpp splitcell.cpp multisplit.cpp \ bbsavestate.cpp nrncore_write.cpp pysecname2sec.cpp \ nrndae.cpp matrixmap.cpp geometry3d.cpp \ @@ -163,7 +163,7 @@ noinst_HEADERS = ndatclas.h nrnclass.h nrnmenu.h nrnoc2iv.h ppshape.h \ kschan.h kssingle.h nonlinz.h nrnhash.h \ nvector_nrnthread_ld.h nvector_nrnserial_ld.h \ $(PARINC1) \ - bgpdma.cpp bgpdmasetup.cpp bgpmeminfo.c \ + bgpdma.cpp bgpdmasetup.cpp bgpmeminfo.cpp \ multisplitcontrol.h nvector_nrnthread.h \ bbsavestate.h nrncore_write.h nrnsection_mapping.h\ nrnmusic.cpp nrndae.h matrixmap.h \ diff --git a/src/nrniv/bbsavestate.cpp b/src/nrniv/bbsavestate.cpp index b3dc95e50f..e5ff041747 100644 --- a/src/nrniv/bbsavestate.cpp +++ b/src/nrniv/bbsavestate.cpp @@ -134,7 +134,7 @@ For example FUNCTION bbsavestate() { bbsavestate = 0 VERBATIM - double *xdir, *xval, *hoc_pgetarg(); + double *xdir, *xval; // , *hoc_pgetarg(); xdir = hoc_pgetarg(1); if (*xdir == -1.) { *xdir = 2; return 0.0; } xval = hoc_pgetarg(2); @@ -194,7 +194,6 @@ static void bbss_early(double td, TQItem* tq); typedef void (*ReceiveFunc)(Point_process*, double*, double); -extern "C" { #include "membfunc.h" extern int section_count; extern void nrn_shape_update(); @@ -203,17 +202,19 @@ extern Section** secorder; extern ReceiveFunc* pnt_receive; extern NetCvode* net_cvode_instance; extern TQueue* net_cvode_instance_event_queue(NrnThread*); -extern void clear_event_queue(); +extern "C" void clear_event_queue(); extern cTemplate** nrn_pnt_template_; extern hoc_Item* net_cvode_instance_psl(); extern PlayRecList* net_cvode_instance_prl(); extern void nrn_netcon_event(NetCon*, double); -extern void net_send(void**, double*, Point_process*, double, double); extern double t; typedef void (*PFIO)(int, Object*); extern void nrn_gidout_iter(PFIO); extern short* nrn_is_artificial_; +extern "C" { +extern void net_send(void**, double*, Point_process*, double, double); extern void nrn_fake_fire(int gid, double firetime, int fake_out); +} // extern "C" extern Object* nrn_gid2obj(int gid); extern PreSyn* nrn_gid2presyn(int gid); extern int nrn_gid_exists(int gid); @@ -262,7 +263,7 @@ static void nrnmpi_dbl_allgatherv(double* s, double* r, int* n, int* dspl) { extern int use_bgpdma_; #endif -extern Point_process* ob2pntproc(Object*); +extern "C" Point_process* ob2pntproc(Object*); extern void nrn_play_init(); extern Symlist* hoc_built_in_symlist; @@ -295,7 +296,7 @@ static void bbss_queuecheck(); // process. -void* bbss_buffer_counts(int* len, int** gids, int** sizes, int* global_size); +extern "C" void* bbss_buffer_counts(int* len, int** gids, int** sizes, int* global_size); // First call to return the information needed to make the other // calls. Returns a pointer used by the other methods. // Caller is reponsible for freeing (using free() and not delete []) @@ -313,20 +314,20 @@ void* bbss_buffer_counts(int* len, int** gids, int** sizes, int* global_size); // of the number of concatenated buffers for each base gid. // Global_size will only be non_zero for host 0. -void bbss_save_global(void* bbss, char* buffer, int sz); +extern "C" void bbss_save_global(void* bbss, char* buffer, int sz); // call only on host 0 with a buffer of size equal to the // global_size returned from the bbss_buffer_counts call on host 0 // sz is the size of the buffer (for error checking only, buffer+sz is // out of bounds) -void bbss_restore_global(void* bbss, char* buffer, int sz); +extern "C" void bbss_restore_global(void* bbss, char* buffer, int sz); // call on all hosts with the buffer contents returned from the call // to bbss_save_global // This must be called prior to any calls to bbss_restore // sz is the size of the buffer (error checking only) // This also does some other important restore initializations. -void bbss_save(void* bbss, int gid, char* buffer, int sz); +extern "C" void bbss_save(void* bbss, int gid, char* buffer, int sz); // Call this for each item of the gids from bbss_buffer_counts along with // a buffer of size from the corresponding sizes array. The buffer will // be filled in with savestate information. The gid may be the same on @@ -334,23 +335,22 @@ void bbss_save(void* bbss, int gid, char* buffer, int sz); // concatentate buffers at some point to allow calling of bbss_restore // sz is the size of the buffer (error checking only) -void bbss_restore(void* bbss, int gid, int npiece, char* buffer, int sz); +extern "C" void bbss_restore(void* bbss, int gid, int npiece, char* buffer, int sz); // Call this for each item of the gids from bbss_buffer_counts, the // number of buffers that were concatenated for the gid, and the // concatenated buffer (the concatenated buffer does NOT contain npiece // as the first value in the char* buffer pointer) // sz is the size of the buffer (error checking only) -void bbss_save_done(void* bbss); +extern "C" void bbss_save_done(void* bbss); // At the end of the save process, call this to cleanup. // when this call returns, bbss will be invalid. -void bbss_restore_done(void* bbss); +extern "C" void bbss_restore_done(void* bbss); // At the end of the restore process, call this to do // some extra setting up and cleanup. // when this call returns, bbss will be invalid. -}; // 0 no debug, 1 print to stdout, 2 read/write to IO file @@ -694,7 +694,7 @@ static int ignored(Prop* p) { return 0; } -void* bbss_buffer_counts(int* len, int** gids, int** sizes, int* global_size) { +extern "C" void* bbss_buffer_counts(int* len, int** gids, int** sizes, int* global_size) { usebin_ = 1; BBSaveState* ss = new BBSaveState(); *global_size = 0; @@ -707,13 +707,13 @@ void* bbss_buffer_counts(int* len, int** gids, int** sizes, int* global_size) { *len = ss->counts(gids, sizes); return ss; } -void bbss_save_global(void* bbss, char* buffer, int sz) { // call only on host 0 +extern "C" void bbss_save_global(void* bbss, char* buffer, int sz) { // call only on host 0 usebin_ = 1; BBSS_IO* io = new BBSS_BufferOut(buffer, sz); io->d(1, nrn_threads->_t); delete io; } -void bbss_restore_global(void* bbss, char* buffer, int sz) { // call on all hosts +extern "C" void bbss_restore_global(void* bbss, char* buffer, int sz) { // call on all hosts usebin_ = 1; BBSS_IO* io = new BBSS_BufferIn(buffer, sz); io->d(1, nrn_threads->_t); @@ -730,7 +730,7 @@ void bbss_restore_global(void* bbss, char* buffer, int sz) { // call on all host nrn_binq_enqueue_error_handler = bbss_early; } } -void bbss_save(void* bbss, int gid, char* buffer, int sz) { +extern "C" void bbss_save(void* bbss, int gid, char* buffer, int sz) { usebin_ = 1; BBSaveState* ss = (BBSaveState*) bbss; BBSS_IO* io = new BBSS_BufferOut(buffer, sz); @@ -738,7 +738,7 @@ void bbss_save(void* bbss, int gid, char* buffer, int sz) { ss->gidobj(gid); delete io; } -void bbss_restore(void* bbss, int gid, int ngroup, char* buffer, int sz) { +extern "C" void bbss_restore(void* bbss, int gid, int ngroup, char* buffer, int sz) { usebin_ = 1; BBSaveState* ss = (BBSaveState*) bbss; BBSS_IO* io = new BBSS_BufferIn(buffer, sz); @@ -749,7 +749,7 @@ void bbss_restore(void* bbss, int gid, int ngroup, char* buffer, int sz) { } delete io; } -void bbss_save_done(void* bbss) { +extern "C" void bbss_save_done(void* bbss) { BBSaveState* ss = (BBSaveState*) bbss; delete ss; } @@ -789,7 +789,7 @@ printf("%d type=%d\n", nrnmpi_myid, type); delete tq_removal_list; } -void bbss_restore_done(void* bbss) { +extern "C" void bbss_restore_done(void* bbss) { if (bbss) { BBSaveState* ss = (BBSaveState*) bbss; delete ss; @@ -910,7 +910,7 @@ static double restore_test_bin(void* v) { //assumes whole cells fclose(f); //if (sz != sizes[i]) { // printf("%d note sz=%d size=%d\n", nrnmpi_myid, sz, sizes[i]); - //} + //} buf = new char[sz]; sprintf(fname, "binbufin/%d.%d", gids[i], sz); @@ -1010,7 +1010,7 @@ static void ssi_def() { ssi[im].callback = hoc_table_lookup("bbsavestate", ts->symtable); //if (ssi[im].callback) { // printf("callback %s.%s\n", ts->sym->name, ssi[im].callback->name); - //} + //} }else{ // check for callback named bbsavestate in a density mechanism char name[256]; @@ -1018,8 +1018,8 @@ static void ssi_def() { ssi[im].callback = hoc_table_lookup(name, hoc_built_in_symlist); //if (ssi[im].callback) { // printf("callback %s\n", ssi[im].callback->name); - //} - } + //} + } delete np; } } @@ -1593,7 +1593,7 @@ void BBSaveState::cell(Object* c) { f->s(buf); if (!is_point_process(c)) { // must be cell object if (f->type() != BBSS_IO::IN) { // writing, counting - // from forall_section in cabcode.c + // from forall_section in cabcode.cpp // count, and iterate from first to last hoc_Item* qsec, *first, *last; qsec = c->secelm_; diff --git a/src/nrniv/bgpdma.cpp b/src/nrniv/bgpdma.cpp index 46d2d3b0d6..47ade40e24 100644 --- a/src/nrniv/bgpdma.cpp +++ b/src/nrniv/bgpdma.cpp @@ -32,9 +32,10 @@ extern "C" { extern IvocVect* vector_arg(int); extern void vector_resize(IvocVect*, int); +} // extern "C" extern void (*nrntimeout_call)(); -} + // The initial idea behind TWOPHASE is to avoid the large overhead of // initiating a send of the up to 10k list of target hosts when a cell fires. @@ -416,11 +417,9 @@ void BGP_ReceiveBuffer::phase2send() { #define NSEND 10 #if BGPDMA > 1 -extern "C" { extern void getMemSize(long long *mem); extern void getUsedMem(long long *mem); extern void getFreeMem(long long *mem); -} #endif @@ -612,12 +611,10 @@ double nrn_bgp_receive_time(int type) { // and others return rt; } -extern "C" { extern void nrnmpi_bgp_comm(); extern void nrnmpi_bgp_multisend(NRNMPI_Spike*, int, int*); extern int nrnmpi_bgp_single_advance(NRNMPI_Spike*); extern int nrnmpi_bgp_conserve(int nsend, int nrecv); -} static void bgp_dma_init() { for (int i = 0; i < n_bgp_interval; ++i) { diff --git a/src/nrniv/bgpdmasetup.cpp b/src/nrniv/bgpdmasetup.cpp index 539866e243..052047ea64 100644 --- a/src/nrniv/bgpdmasetup.cpp +++ b/src/nrniv/bgpdmasetup.cpp @@ -133,7 +133,9 @@ static void all2allv_helper(int* scnt, int* sdispl, int*& rcnt, int*& rdispl) { } #define all2allv_perf 1 -extern "C" {extern unsigned long long nrn_mallinfo(int);} +extern "C" { + extern unsigned long long nrn_mallinfo(int); +} // extern "C" //input s, scnt, sdispl ; output, newly allocated r, rcnt, rdispl static void all2allv_int(int* s, int* scnt, int* sdispl, int*& r, int*& rcnt, int*& rdispl, const char* dmes) { #if all2allv_perf diff --git a/src/nrniv/bgpmeminfo.c b/src/nrniv/bgpmeminfo.cpp similarity index 99% rename from src/nrniv/bgpmeminfo.c rename to src/nrniv/bgpmeminfo.cpp index 89f5a5d881..623f57f923 100644 --- a/src/nrniv/bgpmeminfo.c +++ b/src/nrniv/bgpmeminfo.cpp @@ -4,7 +4,7 @@ for an unknown reason now causes a bug in the functionality of pc.cell . */ -/* from curl -k -O https://wiki.alcf.anl.gov/images/8/8d/Meminfo.c */ +/* from curl -k -O https://wiki.alcf.anl.gov/images/8/8d/Meminfo.cpp */ /* compile with -I/bgsys/drivers/ppcfloor/arch/include */ #undef STR diff --git a/src/nrniv/cachevec.cpp b/src/nrniv/cachevec.cpp index b3f5bf8373..17d7acdb44 100644 --- a/src/nrniv/cachevec.cpp +++ b/src/nrniv/cachevec.cpp @@ -20,11 +20,9 @@ #include #include -extern "C" { void nrniv_recalc_ptrs(); -extern double* nrn_recalc_ptr(double*); +extern "C" double* nrn_recalc_ptr(double*); extern NetCvode* net_cvode_instance; -} extern void nrn_linmod_update_ptrs(void*); extern void nrn_partrans_update_ptrs(); diff --git a/src/nrniv/cxprop.cpp b/src/nrniv/cxprop.cpp index e200ee1af5..8c406ec0a0 100644 --- a/src/nrniv/cxprop.cpp +++ b/src/nrniv/cxprop.cpp @@ -16,24 +16,22 @@ greater cache efficiency #include #include -extern "C" { extern void nrn_mk_prop_pools(int); extern void nrn_cache_prop_realloc(); extern int nrn_is_ion(int); -void nrn_update_ion_pointer(Symbol* sion, Datum* dp, int id, int ip); +//void nrn_update_ion_pointer(Symbol* sion, Datum* dp, int id, int ip); #if EXTRACELLULAR void nrn_extcell_update_param(); #endif extern void nrn_recalc_ptrs(double*(*)(double*)); static double* recalc_ptr(double*); -void* nrn_pool_create(long count, int itemsize); -void nrn_pool_delete(void* pool); -void* nrn_pool_alloc(void* pool); -void nrn_pool_free(void* pool, void* item); -void nrn_pool_freeall(void* pool); +//void* nrn_pool_create(long count, int itemsize); +//void nrn_pool_delete(void* pool); +//void* nrn_pool_alloc(void* pool); +//void nrn_pool_free(void* pool, void* item); +//void nrn_pool_freeall(void* pool); -} declareArrayPool(CharArrayPool, char) implementArrayPool(CharArrayPool, char) @@ -259,7 +257,7 @@ void nrn_mk_prop_pools(int n) { mk_prop_pools(n); } -double* nrn_prop_data_alloc(int type, int count, Prop* p) { +extern "C" double* nrn_prop_data_alloc(int type, int count, Prop* p) { if (!dblpools_[type]) { dblpools_[type] = new DoubleArrayPool(APSIZE, count); } @@ -270,7 +268,7 @@ double* nrn_prop_data_alloc(int type, int count, Prop* p) { return pd; } -Datum* nrn_prop_datum_alloc(int type, int count, Prop* p) { +extern "C" Datum* nrn_prop_datum_alloc(int type, int count, Prop* p) { int i; Datum* ppd; if (!datumpools_[type]) { @@ -284,14 +282,14 @@ Datum* nrn_prop_datum_alloc(int type, int count, Prop* p) { return ppd; } -void nrn_prop_data_free(int type, double* pd) { +extern "C" void nrn_prop_data_free(int type, double* pd) { //if (type > 1) printf("nrn_prop_data_free %d %s %p\n", type, memb_func[type].sym->name, pd); if (pd) { dblpools_[type]->hpfree(pd); } } -void nrn_prop_datum_free(int type, Datum* ppd) { +extern "C" void nrn_prop_datum_free(int type, Datum* ppd) { //if (type > 1) printf("nrn_prop_datum_free %d %s %p\n", type, memb_func[type].sym->name, ppd); if (ppd) { datumpools_[type]->hpfree(ppd); @@ -554,7 +552,7 @@ static int in_place_data_realloc() { return status; } -void nrn_update_ion_pointer(Symbol* sion, Datum* dp, int id, int ip) { +extern "C" void nrn_update_ion_pointer(Symbol* sion, Datum* dp, int id, int ip) { int iontype = sion->subtype; DoubleArrayPool* np = dblpools_[iontype]; DoubleArrayPool* op = oldpools_[iontype]; @@ -650,23 +648,23 @@ nrn_assert(fprintf(f, "%d %d %ld\n", p->type, ml->nodecount++, p->_alloc_seq) > // for avoiding interthread cache line sharing // each thread needs its own pool instance -void* nrn_pool_create(long count, int itemsize) { +extern "C" void* nrn_pool_create(long count, int itemsize) { CharArrayPool* p = new CharArrayPool(count, itemsize); return (void*)p; } -void nrn_pool_delete(void* pool) { +extern "C" void nrn_pool_delete(void* pool) { CharArrayPool* p = (CharArrayPool*)pool; delete p; } -void* nrn_pool_alloc(void* pool) { +extern "C" void* nrn_pool_alloc(void* pool) { CharArrayPool* p = (CharArrayPool*)pool; return (void*)p->alloc(); } -void nrn_pool_free(void* pool, void* item) { +extern "C" void nrn_pool_free(void* pool, void* item) { CharArrayPool* p = (CharArrayPool*)pool; - p->hpfree((char*)item); + p->hpfree(static_cast(item)); } -void nrn_pool_freeall(void* pool) { +extern "C" void nrn_pool_freeall(void* pool) { CharArrayPool* p = (CharArrayPool*)pool; p->free_all(); } diff --git a/src/nrniv/finithnd.cpp b/src/nrniv/finithnd.cpp index 058179e786..cfe19fa645 100644 --- a/src/nrniv/finithnd.cpp +++ b/src/nrniv/finithnd.cpp @@ -32,9 +32,7 @@ class FInitialHandler { static FIHList* fihlist_[4]; }; -extern "C" { - void nrn_fihexec(int type); -} +void nrn_fihexec(int type); void nrn_fihexec(int type) { FIHList* fl = FInitialHandler::fihlist_[type]; if (fl) { diff --git a/src/nrniv/geometry3d.cpp b/src/nrniv/geometry3d.cpp index a5de870d82..2f2cdeade2 100644 --- a/src/nrniv/geometry3d.cpp +++ b/src/nrniv/geometry3d.cpp @@ -10,16 +10,14 @@ #include //#include -extern "C" { - int geometry3d_find_triangles(double value0, double value1, double value2, - double value3, double value4, double value5, - double value6, double value7, double x0, - double x1, double y0, double y1, double z0, - double z1, double* out, int offset); - - double geometry3d_llgramarea(double* p0, double* p1, double* p2) ; - double geometry3d_sum_area_of_triangles(double* tri_vec, int len); -} + int geometry3d_find_triangles(double value0, double value1, double value2, + double value3, double value4, double value5, + double value6, double value7, double x0, + double x1, double y0, double y1, double z0, + double z1, double* out, int offset); + + double geometry3d_llgramarea(double* p0, double* p1, double* p2) ; + double geometry3d_sum_area_of_triangles(double* tri_vec, int len); inline double max(double a, double b) { return a > b ? a : b; @@ -477,7 +475,6 @@ double geometry3d_Cylinder::signed_distance(double px, double py, double pz) { } } -extern "C" { void* geometry3d_new_Cylinder(double x0, double y0, double z0, double x1, double y1, double z1, double r) { return new geometry3d_Cylinder(x0, y0, z0, x1, y1, z1, r); } @@ -488,7 +485,6 @@ extern "C" { double geometry3d_Cylinder_signed_distance(void* ptr, double px, double py, double pz) { return ((geometry3d_Cylinder*) ptr) -> signed_distance(px, py, pz); } -} @@ -561,7 +557,6 @@ double geometry3d_Cone::signed_distance(double px, double py, double pz) { } -extern "C" { void* geometry3d_new_Cone(double x0, double y0, double z0, double r0, double x1, double y1, double z1, double r1) { return new geometry3d_Cone(x0, y0, z0, r0, x1, y1, z1, r1); } @@ -572,7 +567,6 @@ extern "C" { double geometry3d_Cone_signed_distance(void* ptr, double px, double py, double pz) { return ((geometry3d_Cone*) ptr) -> signed_distance(px, py, pz); } -} class geometry3d_Sphere { @@ -590,7 +584,6 @@ double geometry3d_Sphere::signed_distance(double px, double py, double pz) { return sqrt(pow(x - px, 2) + pow(y - py, 2) + pow(z - pz, 2)) - r; } -extern "C" { void* geometry3d_new_Sphere(double x, double y, double z, double r) { return new geometry3d_Sphere(x, y, z, r); } @@ -601,7 +594,6 @@ extern "C" { double geometry3d_Sphere_signed_distance(void* ptr, double px, double py, double pz) { return ((geometry3d_Sphere*) ptr) -> signed_distance(px, py, pz); } -} class geometry3d_Plane { public: @@ -620,7 +612,6 @@ double geometry3d_Plane::signed_distance(double px, double py, double pz) { return (nx * px + ny * py + nz * pz + d) * mul; } -extern "C" { void* geometry3d_new_Plane(double x, double y, double z, double nx, double ny, double nz) { return new geometry3d_Plane(x, y, z, nx, ny, nz); } @@ -631,10 +622,8 @@ extern "C" { double geometry3d_Plane_signed_distance(void* ptr, double px, double py, double pz) { return ((geometry3d_Plane*) ptr) -> signed_distance(px, py, pz); } -} /* -extern "C" { PyObject* nrnpy_pyCallObject(PyObject*, PyObject*); void print_numbers(PyObject *p) { diff --git a/src/nrniv/glinerec.cpp b/src/nrniv/glinerec.cpp index d2712c12c5..3cceea7e78 100644 --- a/src/nrniv/glinerec.cpp +++ b/src/nrniv/glinerec.cpp @@ -8,12 +8,10 @@ // point processes. // Note: cvode.simgraph_remove() deletes all the GLineRecord instances. -extern "C" { #include "hocparse.h" #include "code.h" #undef begin #undef add -} #include #include "nrnoc2iv.h" @@ -26,9 +24,7 @@ extern "C" { #include "glinerec.h" #include "ocjump.h" -extern "C" { extern NetCvode* net_cvode_instance; -}; class GLineRecordList; @@ -132,7 +128,7 @@ void GLineRecord::fill_pd() { // Execute the expr Inst by Inst but when rangepoint or // rangevareval are seen, execute a series of stack machine instructions // that give us the pointer to the range variable (see the implementation - // in nrn/src/nrnoc/cabcode.c) but leaving the stack as though the + // in nrn/src/nrnoc/cabcode.cpp) but leaving the stack as though the // original instruction was executed. assert(gl_->expr_); ObjectContext objc(gl_->obj_); diff --git a/src/nrniv/hocmech.cpp b/src/nrniv/hocmech.cpp index 813636547f..0ea095bbf1 100644 --- a/src/nrniv/hocmech.cpp +++ b/src/nrniv/hocmech.cpp @@ -5,14 +5,13 @@ #include "nrnoc2iv.h" #include "nrniv_mf.h" -extern "C" { #include "parse.h" extern int point_reg_helper(Symbol*); extern Object* hoc_newobj1(Symbol*, int); extern Symlist* hoc_symlist; extern void hoc_unlink_symbol(Symbol*, Symlist*); extern void hoc_link_symbol(Symbol*, Symlist*); -extern void hoc_free_list(Symlist**); +extern "C" void hoc_free_list(Symlist**); extern Datum* hoc_look_inside_stack(int, int); extern void nrn_loc_point_process(int, Point_process*, Section*, Node*); extern char* pnt_map; @@ -24,7 +23,6 @@ extern void make_mechanism(); extern void make_pointprocess(); extern void hoc_construct_point(Object*, int); extern Object* hoc_new_opoint(int); -} static Object* last_created_pp_ob_; static bool skip_; @@ -77,7 +75,7 @@ void hoc_construct_point(Object* ob, int narg) { } } -Point_process* ob2pntproc_0(Object* ob) { +extern "C" Point_process* ob2pntproc_0(Object* ob) { Point_process* pp; if (ob->ctemplate->steer) { pp = (Point_process*)ob->u.this_pointer; @@ -87,7 +85,7 @@ Point_process* ob2pntproc_0(Object* ob) { return pp; } -Point_process* ob2pntproc(Object* ob) { +extern "C" Point_process* ob2pntproc(Object* ob) { Point_process* pp = ob2pntproc_0(ob); if (!pp || !pp->prop) { hoc_execerror(hoc_object_name(ob),"point process not located in a section"); @@ -301,7 +299,7 @@ hoc_execerror("Can't make a template into a PointProcess when instances already // That is the one with the u.ppsym. // The only reason it needs to be in slist is to find the // mechanims type. And it needs to be LAST in that list. - // The only reason for the u.ppsym is for ndatclas.c and we + // The only reason for the u.ppsym is for ndatclas.cpp and we // need to fill those symbols with oboff. sp = hoc_table_lookup(classsym->name, slist); hoc_unlink_symbol(sp, slist); diff --git a/src/nrniv/impedanc.cpp b/src/nrniv/impedanc.cpp index 36abf44bc2..3c768e316a 100644 --- a/src/nrniv/impedanc.cpp +++ b/src/nrniv/impedanc.cpp @@ -170,15 +170,13 @@ inline Complex polar(double r, double t) #include "classreg.h" #include #include -extern "C" { #include "membfunc.h" extern void nrn_rhs(NrnThread*); extern void nrn_lhs(NrnThread*); extern int tree_changed; -extern int v_structure_change; +extern "C" int v_structure_change; extern void setup_topology(); extern void recalc_diam(); -} typedef void (*Pfrv4)(int, Node**, double**, Datum**); diff --git a/src/nrniv/kschan.cpp b/src/nrniv/kschan.cpp index bcdb719888..7aaeec7b5e 100644 --- a/src/nrniv/kschan.cpp +++ b/src/nrniv/kschan.cpp @@ -21,10 +21,9 @@ implementPtrList(KSChanList, KSChan) static KSChanList* channels; -extern "C" { extern char* hoc_symbol_units(Symbol*, const char*); extern void nrn_mk_table_check(); -} +extern spREAL *spGetElement(char*, int ,int); static Symbol* ksstate_sym; static Symbol* ksgate_sym; @@ -993,7 +992,7 @@ void KSChan::setname(const char* s) { if (cp) { int nbase = cp - sp->name; int n = nbase + strlen(suffix) + 2; - char* s1 = (char*)hoc_Emalloc(n); hoc_malchk(); + char* s1 = static_cast(hoc_Emalloc(n)); hoc_malchk(); strncpy(s1, sp->name, nbase); sprintf(s1 + nbase, "_%s", suffix); //printf("KSChan::setname change %s to %s\n", sp->name, s1); diff --git a/src/nrniv/kschan.h b/src/nrniv/kschan.h index aee7a18554..9de6a37f82 100644 --- a/src/nrniv/kschan.h +++ b/src/nrniv/kschan.h @@ -7,14 +7,10 @@ #include "ivocvect.h" #include "nrnunits_modern.h" -extern "C" { #include "spmatrix.h" -} -extern "C" { - //extern double dt; - extern double celsius; -} +//extern double dt; +extern double celsius; class KSState; class KSChan; diff --git a/src/nrniv/kssingle.cpp b/src/nrniv/kssingle.cpp index 4e24893569..bae65f28a0 100644 --- a/src/nrniv/kssingle.cpp +++ b/src/nrniv/kssingle.cpp @@ -128,9 +128,7 @@ // double* KSSingleNodeData.statepop_ which points into the prop->param. //---------------- -extern "C" { extern int cvode_active_; -} extern NetCvode* net_cvode_instance; double KSSingle::vres_; diff --git a/src/nrniv/kssingle.h b/src/nrniv/kssingle.h index c93b90752e..bc01bb3383 100644 --- a/src/nrniv/kssingle.h +++ b/src/nrniv/kssingle.h @@ -6,9 +6,7 @@ #include #include -extern "C" { #include -} class KSSingleTrans; class KSSingleState; diff --git a/src/nrniv/linmod.cpp b/src/nrniv/linmod.cpp index 099501979a..4405595b8b 100755 --- a/src/nrniv/linmod.cpp +++ b/src/nrniv/linmod.cpp @@ -25,9 +25,7 @@ #include #include "linmod.h" -extern "C" { - extern int (*nrnpy_hoccommand_exec)(Object*); -} +extern int (*nrnpy_hoccommand_exec)(Object*); LinearModelAddition::LinearModelAddition(Matrix* cmat, Matrix* gmat, diff --git a/src/nrniv/linmod1.cpp b/src/nrniv/linmod1.cpp index 153c4c7a4a..28d36100c3 100644 --- a/src/nrniv/linmod1.cpp +++ b/src/nrniv/linmod1.cpp @@ -9,9 +9,7 @@ #include "linmod.h" #include "nrnoc2iv.h" -extern "C" { -extern double* nrn_recalc_ptr(double*); -} +extern "C" double* nrn_recalc_ptr(double*); //hoc interface to a LinearModelAddition // remember that the policy for equation additions to the tree matrix is // cmat*y' + gmat*y = b and where the first nnode rows specify diff --git a/src/nrniv/matrixmap.cpp b/src/nrniv/matrixmap.cpp index 75e666cc75..d378e32527 100644 --- a/src/nrniv/matrixmap.cpp +++ b/src/nrniv/matrixmap.cpp @@ -3,9 +3,8 @@ #include using std::vector; -extern "C" { - #include "spmatrix.h" -} +#include "spmatrix.h" +extern spREAL *spGetElement(char*, int ,int); MatrixMap::MatrixMap(Matrix& mat) : m_(mat), plen_(0), ptree_(NULL), pm_(NULL) { diff --git a/src/nrniv/multisplit.cpp b/src/nrniv/multisplit.cpp index ab1246bdab..8666158115 100644 --- a/src/nrniv/multisplit.cpp +++ b/src/nrniv/multisplit.cpp @@ -10,7 +10,6 @@ #include #include -extern "C" { void nrnmpi_multisplit(Section*, double x, int sid, int backbone_style); int nrn_multisplit_active_; @@ -54,7 +53,6 @@ static void nrnmpi_wait(void**){} static void nrnmpi_barrier(){} static double nrnmpi_wtime() { return 0.0; } #endif -} class MultiSplit; class MultiSplitControl; @@ -1841,17 +1839,17 @@ void multisplit_solve() { void* nrn_multisplit_triang(NrnThread* nt){ msc_->mth_[nt->id].triang(nt); - return (void*)0; + return nullptr; } void* nrn_multisplit_reduce_solve(NrnThread* nt){ if (nt->id == 0) { msc_->reduce_solve(); } - return (void*)0; + return nullptr; } void* nrn_multisplit_bksub(NrnThread* nt){ msc_->mth_[nt->id].bksub(nt); - return (void*)0; + return nullptr; } void MultiSplitControl::solve() { @@ -2020,7 +2018,7 @@ void MultiSplitControl::matrix_exchange() { double wt = nrnmpi_wtime(); NrnThread* _nt; // the mpi strategy is copied from the - // cvode/examples_par/pvkxb.c exchange strategy + // cvode/examples_par/pvkxb.cpp exchange strategy #define EXCHANGE_ON 1 #if EXCHANGE_ON @@ -2061,7 +2059,6 @@ nrnmpi_myid, i, mt.displ_, mt.size_, mt.host_, tag); //if (nrnmpi_myid == 4) { printf("%d send to %d nnode=%d nnode_rt=%d size=%d tag=%d\n", nrnmpi_myid, mt.host_, mt.nnode_, mt.nnode_rt_, mt.size_, mt.tag_); -//} #endif #if 0 //if (nrnmpi_myid == 4) { @@ -2074,7 +2071,6 @@ nrnmpi_myid, mt.host_, 2*j, tbuf[2*j], 2*j+1, tbuf[2*j+1], mt.nodeindex_[j]); printf("%d send to %d offdiag tbuf[%d] = %g\n", nrnmpi_myid, mt.host_, jj, tbuf[jj]); } -//} #endif } @@ -2227,7 +2223,7 @@ void MultiSplitControl::matrix_exchange_nocap() { //copy of matrix_exchange() an double wt = nrnmpi_wtime(); NrnThread* _nt; // the mpi strategy is copied from the - // cvode/examples_par/pvkxb.c exchange strategy + // cvode/examples_par/pvkxb.cpp exchange strategy #define EXCHANGE_ON 1 #if EXCHANGE_ON @@ -2266,7 +2262,6 @@ nrnmpi_myid, i, mt.displ_, mt.size_, mt.host_, tag); //if (nrnmpi_myid == 4) { printf("%d send to %d nnode=%d nnode_rt=%d size=%d tag=%d\n", nrnmpi_myid, mt.host_, mt.nnode_, mt.nnode_rt_, mt.size_, mt.tag_); -//} #endif #if 0 //if (nrnmpi_myid == 4) { @@ -2279,7 +2274,6 @@ nrnmpi_myid, mt.host_, 2*j, tbuf[2*j], 2*j+1, tbuf[2*j+1], mt.nodeindex_[j]); printf("%d send to %d offdiag tbuf[%d] = %g\n", nrnmpi_myid, mt.host_, jj, tbuf[jj]); } -//} #endif } diff --git a/src/nrniv/ndatclas.cpp b/src/nrniv/ndatclas.cpp index 4e1d9e03c3..fe47212248 100644 --- a/src/nrniv/ndatclas.cpp +++ b/src/nrniv/ndatclas.cpp @@ -4,17 +4,12 @@ #include "nrnoc2iv.h" #include "classreg.h" -extern "C" { #include "membfunc.h" #include "parse.h" -} - -extern "C" { extern Prop* prop_alloc(Prop**, int, Node*); extern void single_prop_free(Prop*); extern Symlist* hoc_built_in_symlist; extern Symlist* hoc_top_level_symlist; -} //---------------------------------------------------- /* static */ class NrnPropertyImpl { diff --git a/src/nrniv/netpar.cpp b/src/nrniv/netpar.cpp index 47afd2f7be..655be1f995 100644 --- a/src/nrniv/netpar.cpp +++ b/src/nrniv/netpar.cpp @@ -43,18 +43,19 @@ static double t_exchange_; static double dt1_; // 1/dt static void alloc_space(); -extern "C" { extern NetCvode* net_cvode_instance; extern double t, dt; extern int cvode_active_; -extern Point_process* ob2pntproc(Object*); +extern "C" Point_process* ob2pntproc(Object*); extern int nrn_use_selfqueue_; extern void nrn_pending_selfqueue(double, NrnThread*); extern int vector_capacity(IvocVect*); //ivocvect.h conflicts with STL extern double* vector_vec(IvocVect*); extern Object* nrn_sec2cell(Section*); extern void ncs2nrn_integrate(double tstop); +extern "C" { extern void nrn_fake_fire(int gid, double firetime, int fake_out); +} // extern "C" int nrnmpi_spike_compress(int nspike, bool gid_compress, int xchng_meth); void nrn_cleanup_presyn(PreSyn*); int nrn_set_timeout(int); @@ -76,7 +77,7 @@ extern double nrnmpi_step_wait_; // barrier at beginning of spike exchange. * @param spikegidvec - vector of gids * @return 1 if CORENEURON shall drop writing `out.dat`; 0 otherwise */ -int nrnthread_all_spike_vectors_return(std::vector& spiketvec, std::vector& spikegidvec); +extern "C" int nrnthread_all_spike_vectors_return(std::vector& spiketvec, std::vector& spikegidvec); // BGPDMA can be 0,1,2,3,6,7 // (BGPDMA & 1) > 0 means multisend ISend allowed @@ -94,7 +95,6 @@ double nrn_bgp_receive_time(int) { return 0.; } extern void nrnmpi_split_clear(); #endif extern void nrnmpi_multisplit_clear(); -} static double set_mindelay(double maxdelay); @@ -102,7 +102,6 @@ static double set_mindelay(double maxdelay); #include "../nrnmpi/mpispike.h" -extern "C" { void nrn_timeout(int); void nrn_spike_exchange(NrnThread*); extern int nrnmpi_int_allmax(int); @@ -110,7 +109,6 @@ extern void nrnmpi_int_allgather(int*, int*, int); void nrn2ncs_outputevent(int netcon_output_index, double firetime); bool nrn_use_compress_; // global due to bbsavestate #define use_compress_ nrn_use_compress_ -} #ifdef USENCS extern int ncs_bgp_sending_info( int ** ); @@ -896,7 +894,7 @@ static void mk_localgid_rep() { // ensures that all the target cells, regardless of what rank they are on // will get the spike delivered and nobody gets it twice. -void nrn_fake_fire(int gid, double spiketime, int fake_out) { +extern "C" void nrn_fake_fire(int gid, double spiketime, int fake_out) { assert(gid2in_); PreSyn* ps; if (fake_out < 2 && gid2in_->find(gid, ps)) { @@ -1564,7 +1562,6 @@ void nrn_gidout_iter(PFIO callback) { } #include "nrncore_write.h" -extern "C" { extern int* nrn_prop_param_size_; extern int* pnt_receive_size; extern short* nrn_is_artificial_; @@ -1648,5 +1645,4 @@ void nrncore_netpar_cellgroups_helper(CellGroup* cgs) { delete [] gidcnt; } -} // extern "C" of nrnbbcore_write diff --git a/src/nrniv/nonlinz.cpp b/src/nrniv/nonlinz.cpp index 31a067d262..f6d88c8ce2 100644 --- a/src/nrniv/nonlinz.cpp +++ b/src/nrniv/nonlinz.cpp @@ -5,21 +5,18 @@ #include "nonlinz.h" #include "nrnoc2iv.h" #include "nrnmpi.h" -extern "C" { #include "cspmatrix.h" #include "membfunc.h" -} typedef int (*Pfridot)(...); -extern "C" { -extern int structure_change_cnt; +extern "C" int structure_change_cnt; extern void v_setup_vectors(); extern void nrn_rhs(NrnThread*); extern int nrndae_extra_eqn_count(); extern Symlist *hoc_built_in_symlist; extern void (*nrnthread_v_transfer_)(NrnThread*); -} +extern spREAL *spGetElement(char*, int ,int); extern void pargap_jacobi_rhs(double*, double*); extern void pargap_jacobi_setup(int mode); diff --git a/src/nrniv/nrncore_write.cpp b/src/nrniv/nrncore_write.cpp index f92bcb7759..279451d8f4 100644 --- a/src/nrniv/nrncore_write.cpp +++ b/src/nrniv/nrncore_write.cpp @@ -112,7 +112,6 @@ correctness has not been validated for cells without gids. extern NetCvode* net_cvode_instance; -extern "C" { // to end of file extern int* nrn_prop_dparam_size_; int* bbcore_dparam_size; // cvodeieq not present @@ -314,5 +313,3 @@ int nrncore_psolve(double tstop) { } #endif //!HAVE_DLFCN_H - -} // end of extern "C" diff --git a/src/nrniv/nrncore_write.h b/src/nrniv/nrncore_write.h index 70b17c988a..f19d87323f 100644 --- a/src/nrniv/nrncore_write.h +++ b/src/nrniv/nrncore_write.h @@ -3,9 +3,6 @@ #include "nrncore_write/data/cell_group.h" -#if defined(__cplusplus) -extern "C" { -#endif extern void nrncore_netpar_cellgroups_helper(CellGroup*); @@ -13,8 +10,5 @@ int nrncore_run(const char* arg); int nrncore_is_enabled(); int nrncore_psolve(double tstop); -#if defined(__cplusplus) -} -#endif #endif // nrncore_write_h diff --git a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp index 9ee0e34be2..ab933ed837 100644 --- a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp +++ b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp @@ -15,7 +15,6 @@ #include #endif -extern "C" { extern bbcore_write_t* nrn_bbcore_write_; extern short* nrn_is_artificial_; extern bool corenrn_direct; @@ -24,7 +23,6 @@ extern double nrn_ion_charge(Symbol*); extern CellGroup* cellgroups_; extern NetCvode* net_cvode_instance; extern char* pnt_map; -}; /** Populate function pointers by mapping function pointers for callback */ void map_coreneuron_callbacks(void* handle) { diff --git a/src/nrniv/nrncore_write/data/cell_group.cpp b/src/nrniv/nrncore_write/data/cell_group.cpp index 00972f03e9..9fda496521 100644 --- a/src/nrniv/nrncore_write/data/cell_group.cpp +++ b/src/nrniv/nrncore_write/data/cell_group.cpp @@ -5,7 +5,6 @@ #include "nrnmpi.h" #include "netcon.h" -extern "C" { extern short* nrn_is_artificial_; extern bool corenrn_direct; @@ -14,7 +13,6 @@ extern void nrncore_netpar_cellgroups_helper(CellGroup*); extern int nrn_has_net_event_cnt_; extern int* nrn_has_net_event_; extern short* nrn_is_artificial_; -} PVoid2Int CellGroup::artdata2index_; Deferred_Type2ArtData CellGroup::deferred_type2artdata_; diff --git a/src/nrniv/nrncore_write/data/cell_group.h b/src/nrniv/nrncore_write/data/cell_group.h index 473d9d641e..87ab41916b 100644 --- a/src/nrniv/nrncore_write/data/cell_group.h +++ b/src/nrniv/nrncore_write/data/cell_group.h @@ -12,11 +12,7 @@ class PreSyn; class NetCon; class NrnThread; -extern "C" { - - extern int nrn_dblpntr2nrncore(double*, NrnThread&, int& type, int& etype); - -} +extern "C" int nrn_dblpntr2nrncore(double*, NrnThread&, int& type, int& etype); typedef std::pair < int, Memb_list* > MlWithArtItem; typedef std::vector < MlWithArtItem > MlWithArt; diff --git a/src/nrniv/nrncore_write/io/nrncore_io.cpp b/src/nrniv/nrncore_write/io/nrncore_io.cpp index 6aa0551bf1..20e74c3dbc 100644 --- a/src/nrniv/nrncore_write/io/nrncore_io.cpp +++ b/src/nrniv/nrncore_write/io/nrncore_io.cpp @@ -15,13 +15,11 @@ #include #include "nrnsection_mapping.h" -extern "C" { extern short* nrn_is_artificial_; extern int* bbcore_dparam_size; extern bbcore_write_t* nrn_bbcore_write_; extern NetCvode* net_cvode_instance; extern void (*nrnthread_v_transfer_)(NrnThread*); -} int chkpnt; const char *bbcore_write_version = "1.3"; // globals.dat has _nrnunit_use_legacy_ diff --git a/src/nrniv/nrncore_write/io/nrncore_io.h b/src/nrniv/nrncore_write/io/nrncore_io.h index 5ac254a485..5e61a36740 100644 --- a/src/nrniv/nrncore_write/io/nrncore_io.h +++ b/src/nrniv/nrncore_write/io/nrncore_io.h @@ -19,7 +19,6 @@ inline T *begin_ptr(std::vector &v) { } -extern "C" { // to avoid incompatible dataset between neuron and coreneuron // add version string to the dataset files @@ -43,6 +42,5 @@ void nrnbbcore_vecplay_write(FILE *f, NrnThread &nt); void nrn_write_mapping_info(const char *path, int gid, NrnMappingInfo &minfo); -} #endif //NRN_NRNCORE_IO_H diff --git a/src/nrniv/nrncore_write/utils/nrncore_utils.cpp b/src/nrniv/nrncore_write/utils/nrncore_utils.cpp index 002b0787c5..05ac8c6d38 100644 --- a/src/nrniv/nrncore_write/utils/nrncore_utils.cpp +++ b/src/nrniv/nrncore_write/utils/nrncore_utils.cpp @@ -24,8 +24,6 @@ #define RTLD_NODELETE 0 #endif -extern "C" { - extern bool corenrn_direct; extern int diam_changed, v_structure_change, tree_changed; extern const char *bbcore_write_version; @@ -132,7 +130,7 @@ bool file_exist(const std::string& path) { // Requires cache_efficient mode. // Input double* and NrnThread. Output type and index. // type == 0 means could not determine index. -int nrn_dblpntr2nrncore(double* pd, NrnThread& nt, int& type, int& index) { +extern "C" int nrn_dblpntr2nrncore(double* pd, NrnThread& nt, int& type, int& index) { assert(use_cachevec); int nnode = nt.end; type = 0; @@ -272,4 +270,4 @@ void check_coreneuron_compatibility(void* handle) { } #endif //!HAVE_DLFCN_H -} + diff --git a/src/nrniv/nrncore_write/utils/nrncore_utils.h b/src/nrniv/nrncore_write/utils/nrncore_utils.h index 1b293487dd..38b7ba380a 100644 --- a/src/nrniv/nrncore_write/utils/nrncore_utils.h +++ b/src/nrniv/nrncore_write/utils/nrncore_utils.h @@ -2,7 +2,6 @@ #define NRN_NRNCORE_UTILS_H #include -extern "C" { class NrnThread; @@ -10,7 +9,7 @@ void model_ready(); int count_distinct(double *data, int len); extern void nrnbbcore_register_mapping(); bool file_exist(const std::string& path); -int nrn_dblpntr2nrncore(double* pd, NrnThread& nt, int& type, int& index); +extern "C" int nrn_dblpntr2nrncore(double* pd, NrnThread& nt, int& type, int& index); #if defined(HAVE_DLFCN_H) @@ -22,7 +21,6 @@ void check_coreneuron_compatibility(void* handle); #endif -} #endif //NRN_NRNCORE_UTILS_H diff --git a/src/nrniv/nrndae.cpp b/src/nrniv/nrndae.cpp index a16db7240f..81b20dfadc 100644 --- a/src/nrniv/nrndae.cpp +++ b/src/nrniv/nrndae.cpp @@ -3,22 +3,20 @@ #include "nrndae.h" #include "nrnoc2iv.h" -extern "C" { - extern void nrndae_alloc(); - extern int nrndae_extra_eqn_count(); - extern void nrndae_init(); - extern void nrndae_rhs(); // relative to c*dy/dt = -g*y + b - extern void nrndae_lhs(); - extern void nrndae_dkmap(double**, double**); - extern void nrndae_dkres(double*, double*, double*); - extern void nrndae_dkpsol(double); - extern void nrndae_update(); - extern void nrn_matrix_node_free(); - extern int cvode_active_; - extern int nrn_use_daspk_; - extern int secondorder; - extern int nrndae_list_is_empty(); -} +extern void nrndae_alloc(); +extern int nrndae_extra_eqn_count(); +extern void nrndae_init(); +extern void nrndae_rhs(); // relative to c*dy/dt = -g*y + b +extern void nrndae_lhs(); +extern void nrndae_dkmap(double**, double**); +extern void nrndae_dkres(double*, double*, double*); +extern void nrndae_dkpsol(double); +extern void nrndae_update(); +extern void nrn_matrix_node_free(); +extern int cvode_active_; +extern int nrn_use_daspk_; +extern int secondorder; +extern int nrndae_list_is_empty(); static NrnDAEPtrList nrndae_list; diff --git a/src/nrniv/nrnmenu.cpp b/src/nrniv/nrnmenu.cpp index 27916d351b..8588d223e6 100644 --- a/src/nrniv/nrnmenu.cpp +++ b/src/nrniv/nrnmenu.cpp @@ -14,22 +14,19 @@ #include "nrnmenu.h" #include "classreg.h" #include "gui-redirect.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); typedef void (*ReceiveFunc)(Point_process*, double*, double); -extern "C" int hoc_return_type_code; -extern "C" { +/*extern "C"*/ extern int hoc_return_type_code; // from nrnoc #include "membfunc.h" #include "parse.h" extern Symlist *hoc_built_in_symlist; extern Symbol **pointsym; extern double* point_process_pointer(Point_process*, Symbol*, int); -extern Point_process* ob2pntproc(Object*); +extern "C" Point_process* ob2pntproc(Object*); extern ReceiveFunc* pnt_receive; extern int nrn_has_net_event_cnt_; extern int* nrn_has_net_event_; @@ -49,7 +46,6 @@ void nrnpointmenu(); Object* (*nrnpy_callable_with_args)(Object*, int narg); int (*nrnpy_ob_is_seg)(Object*); -} #if HAVE_IV static void pnodemenu(Prop* p1, double, int type, const char* path, MechSelector* = NULL); @@ -89,7 +85,7 @@ ENDGUI } #ifdef ultrix -extern "C" { char *strstr(const char *, const char *); } +char *strstr(const char *, const char *); #endif static bool has_globals(const char* name) { @@ -1248,10 +1244,8 @@ const char* MechanismType::selected(){ int MechanismType::internal_type() { return mti_->type_[selected_item()]; } -extern "C" { extern void mech_insert1(Section*, int); extern void mech_uninsert1(Section*, Symbol*); -} void MechanismType::insert(Section* sec){ if (!mti_->is_point_) { mech_insert1(sec, memb_func[mti_->type_[selected_item()]].sym->subtype); @@ -1263,7 +1257,7 @@ void MechanismType::remove(Section* sec){ } } -extern "C" {extern Object* nrn_new_pointprocess(Symbol*);} +extern Object* nrn_new_pointprocess(Symbol*); void MechanismType::point_process(Object** o){ Symbol* sym = memb_func[mti_->type_[selected_item()]].sym; diff --git a/src/nrniv/nrnmusic.cpp b/src/nrniv/nrnmusic.cpp index a316f94b21..bcdfa03a4a 100644 --- a/src/nrniv/nrnmusic.cpp +++ b/src/nrniv/nrnmusic.cpp @@ -1,7 +1,6 @@ #define NO_PYTHON_H 1 #include <../neuronmusic/nrnmusic.h> -extern "C" { extern int nrnmusic; extern MPI_Comm nrnmusic_comm; @@ -15,7 +14,6 @@ void nrnmusic_spikehandle(void* vport, double tt, int gindex); extern Object* nrnpy_po2ho(PyObject*); extern PyObject* nrnpy_ho2po(Object*); extern Object* hoc_new_object(Symbol*, void*); -} MUSIC::Setup* nrnmusic_setup; MUSIC::Runtime* nrnmusic_runtime; diff --git a/src/nrniv/nrnoc2iv.h b/src/nrniv/nrnoc2iv.h index 0063e1d9cc..b77c91e5f0 100644 --- a/src/nrniv/nrnoc2iv.h +++ b/src/nrniv/nrnoc2iv.h @@ -4,9 +4,7 @@ #include "oc2iv.h" -extern "C" { #include "section.h" -} #include "ndatclas.h" diff --git a/src/nrniv/nrnpy.cpp b/src/nrniv/nrnpy.cpp index dae2f62e36..1d4e7988ce 100644 --- a/src/nrniv/nrnpy.cpp +++ b/src/nrniv/nrnpy.cpp @@ -13,7 +13,6 @@ #include "nonvintblock.h" #include "nrnmpi.h" -extern "C" { extern int nrn_nopython; extern int nrnpy_nositeflag; extern char* nrnpy_pyexe; @@ -25,7 +24,6 @@ static void (*p_nrnpython_real)(); static void (*p_nrnpython_reg_real)(); char* hoc_back2forward(char* s); char* hoc_forward2back(char* s); -} // following is undefined or else has the value of sys.api_version // at time of configure (using the python first in the PATH). @@ -41,21 +39,17 @@ char* hoc_forward2back(char* s); #define RTLD_NOW 0 #define RTLD_GLOBAL 0 #define RTLD_NOLOAD 0 -extern "C" { extern void* dlopen_noerr(const char* name, int mode); #define dlopen dlopen_noerr extern void* dlsym(void* handle, const char* name); extern int dlclose(void* handle); extern char* dlerror(); -} #else //#define _GNU_SOURCE #include #endif -extern "C" { extern char* neuron_home; -} #if NRNPYTHON_DYNAMICLOAD >= 20 && NRNPYTHON_DYNAMICLOAD < 30 @@ -84,11 +78,9 @@ static void* python_already_loaded(); static void* load_python(); static void load_nrnpython(int, const char*); #else //!defined(NRNPYTHON_DYNAMICLOAD) -extern "C" { -extern void nrnpython_start(int); -extern void nrnpython_reg_real(); -extern void nrnpython_real(); -} +extern "C" void nrnpython_start(int); +extern "C" void nrnpython_reg_real(); +extern "C" void nrnpython_real(); #endif //defined(NRNPYTHON_DYNAMICLOAD) char* nrnpy_pyhome; diff --git a/src/nrniv/nrnrtime.cpp b/src/nrniv/nrnrtime.cpp index 087c583b47..b44004e273 100644 --- a/src/nrniv/nrnrtime.cpp +++ b/src/nrniv/nrnrtime.cpp @@ -7,11 +7,9 @@ #include "nrnoc2iv.h" #include "parse.h" -extern "C" { - extern int stoprun; - extern double t; - extern void nrn_fixed_step(); -} +extern int stoprun; +extern double t; +extern void nrn_fixed_step(); class NrnRealTime { public: diff --git a/src/nrniv/nrnsection_mapping.h b/src/nrniv/nrnsection_mapping.h index e2b54c1be8..01b56f4fa8 100644 --- a/src/nrniv/nrnsection_mapping.h +++ b/src/nrniv/nrnsection_mapping.h @@ -138,8 +138,6 @@ struct NrnMappingInfo { } }; -#if defined(__cplusplus) -extern "C" void nrn_write_mapping_info(const char *, int, NrnMappingInfo&); -#endif +void nrn_write_mapping_info(const char *, int, NrnMappingInfo&); #endif // NRN_SECTION_MAPPING diff --git a/src/nrniv/nrnste.cpp b/src/nrniv/nrnste.cpp index 0ce6ab3cbb..7bcf7984ea 100644 --- a/src/nrniv/nrnste.cpp +++ b/src/nrniv/nrnste.cpp @@ -9,7 +9,7 @@ #include #include -extern "C" int hoc_return_type_code; +/*extern "C"*/ extern int hoc_return_type_code; static double ste_transition(void* v) { StateTransitionEvent* ste = (StateTransitionEvent*)v; diff --git a/src/nrniv/nvector_nrnparallel_ld.c b/src/nrniv/nvector_nrnparallel_ld.cpp similarity index 98% rename from src/nrniv/nvector_nrnparallel_ld.c rename to src/nrniv/nvector_nrnparallel_ld.cpp index 17497864d6..5fa866e46e 100644 --- a/src/nrniv/nvector_nrnparallel_ld.c +++ b/src/nrniv/nvector_nrnparallel_ld.cpp @@ -27,9 +27,9 @@ /* for NRNMPI_DYNAMICLOAD */ #include #if NRNMPI_DYNAMICLOAD -extern void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type); -extern void nrnmpi_longdbl_allreduce_vec(long double* src, long double* dest, int cnt, int type); -extern void nrnmpi_long_allreduce_vec(long* src, long* dest, int cnt, int type); +extern "C" void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type); +extern "C" void nrnmpi_longdbl_allreduce_vec(long double* src, long double* dest, int cnt, int type); +extern "C" void nrnmpi_long_allreduce_vec(long* src, long* dest, int cnt, int type); extern int nrnmpi_numprocs; #endif @@ -100,7 +100,7 @@ static void VScaleBy_NrnParallelLD(realtype a, N_Vector x); * Function to create a new parallel vector with empty data array */ -N_Vector N_VNewEmpty_NrnParallelLD(MPI_Comm comm, +N_Vector N_VNewEmpty_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length) { @@ -177,7 +177,7 @@ N_Vector N_VNewEmpty_NrnParallelLD(MPI_Comm comm, * Function to create a new parallel vector */ -N_Vector N_VNew_NrnParallelLD(MPI_Comm comm, +extern "C" N_Vector N_VNew_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length) { diff --git a/src/nrniv/nvector_nrnparallel_ld.h b/src/nrniv/nvector_nrnparallel_ld.h index 45f88b5ebb..eb82cd1795 100644 --- a/src/nrniv/nvector_nrnparallel_ld.h +++ b/src/nrniv/nvector_nrnparallel_ld.h @@ -8,8 +8,8 @@ Macros changed with sed 's/NV_\([A-Za-z_]*\)_P/NV_\1_P_LD/g' nvector_nrnparallel_ld.h >temp mv temp nvector_nrnparallel_ld.h -sed 's/NV_\([A-Za-z_]*\)_P/NV_\1_P_LD/g' nvector_nrnparallel_ld.c >temp -mv temp nvector_nrnparallel_ld.c +sed 's/NV_\([A-Za-z_]*\)_P/NV_\1_P_LD/g' nvector_nrnparallel_ld.cpp >temp +mv temp nvector_nrnparallel_ld.cpp */ /* @@ -63,9 +63,6 @@ mv temp nvector_nrnparallel_ld.c #ifndef _NVECTOR_NRNPARALLEL_LD_H #define _NVECTOR_NRNPARALLEL_LD_H -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif #include #if NRNMPI_DYNAMICLOAD @@ -222,7 +219,7 @@ typedef struct _N_VectorContent_NrnParallelLD *N_VectorContent_NrnParallelLD; * ----------------------------------------------------------------- */ -N_Vector N_VNew_NrnParallelLD(MPI_Comm comm, +extern "C" N_Vector N_VNew_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length); @@ -346,8 +343,5 @@ booleantype N_VInvTest_NrnParallelLD(N_Vector x, N_Vector z); booleantype N_VConstrMask_NrnParallelLD(N_Vector c, N_Vector x, N_Vector m); realtype N_VMinQuotient_NrnParallelLD(N_Vector num, N_Vector denom); -#ifdef __cplusplus -} -#endif #endif diff --git a/src/nrniv/nvector_nrnserial_ld.c b/src/nrniv/nvector_nrnserial_ld.cpp similarity index 100% rename from src/nrniv/nvector_nrnserial_ld.c rename to src/nrniv/nvector_nrnserial_ld.cpp diff --git a/src/nrniv/nvector_nrnserial_ld.h b/src/nrniv/nvector_nrnserial_ld.h index 24c1549357..1afa27e006 100755 --- a/src/nrniv/nvector_nrnserial_ld.h +++ b/src/nrniv/nvector_nrnserial_ld.h @@ -8,8 +8,8 @@ Macros changed with sed 's/NV_\([A-Za-z_]*\)_S/NV_\1_S_LD/g' nvector_nrnserial_ld.h >temp mv temp nvector_nrnserial_ld.h -sed 's/NV_\([A-Za-z_]*\)_S/NV_\1_S_LD/g' nvector_nrnserial_ld.c >temp -mv temp nvector_nrnserial_ld.c +sed 's/NV_\([A-Za-z_]*\)_S/NV_\1_S_LD/g' nvector_nrnserial_ld.cpp >temp +mv temp nvector_nrnserial_ld.cpp */ /* @@ -63,9 +63,6 @@ mv temp nvector_nrnserial_ld.c #ifndef _NVECTOR_NRNSERIAL_LD_H #define _NVECTOR_NRNSERIAL_LD_H -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif #include "nvector.h" #include "sundialstypes.h" @@ -284,8 +281,5 @@ booleantype N_VInvTest_NrnSerialLD(N_Vector x, N_Vector z); booleantype N_VConstrMask_NrnSerialLD(N_Vector c, N_Vector x, N_Vector m); realtype N_VMinQuotient_NrnSerialLD(N_Vector num, N_Vector denom); -#ifdef __cplusplus -} -#endif #endif diff --git a/src/nrniv/nvector_nrnthread.c b/src/nrniv/nvector_nrnthread.cpp similarity index 98% rename from src/nrniv/nvector_nrnthread.c rename to src/nrniv/nvector_nrnthread.cpp index a5dda90986..6eab9bf12a 100755 --- a/src/nrniv/nvector_nrnthread.c +++ b/src/nrniv/nvector_nrnthread.cpp @@ -448,7 +448,7 @@ void N_VSetArrayPointer_NrnThread(realtype *v_data, N_Vector v) static void* vlinearsum(NrnThread* nt) { int i = nt->id; N_VLinearSum_Serial(aarg, xarg(i), barg, yarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VLinearSum_NrnThread(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z) { @@ -461,7 +461,7 @@ mydebug("vlinearsum\n"); static void* vconst(NrnThread* nt) { int i = nt->id; N_VConst_Serial(carg, zarg(i)); - return (void*)0; + return nullptr; } void N_VConst_NrnThread(realtype c, N_Vector z) { @@ -473,7 +473,7 @@ mydebug("vconst\n"); static void* vprod(NrnThread* nt) { int i = nt->id; N_VProd_Serial(xarg(i), yarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VProd_NrnThread(N_Vector x, N_Vector y, N_Vector z) { @@ -485,7 +485,7 @@ mydebug("vprod\n"); static void* vdiv(NrnThread* nt) { int i = nt->id; N_VDiv_Serial(xarg(i), yarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VDiv_NrnThread(N_Vector x, N_Vector y, N_Vector z) { @@ -497,7 +497,7 @@ mydebug("vdiv\n"); static void* vscale(NrnThread* nt) { int i = nt->id; N_VScale_Serial(carg, xarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VScale_NrnThread(realtype c, N_Vector x, N_Vector z) { @@ -510,7 +510,7 @@ mydebug("vscale\n"); static void* vabs(NrnThread* nt) { int i = nt->id; N_VAbs_Serial(xarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VAbs_NrnThread(N_Vector x, N_Vector z) { @@ -522,7 +522,7 @@ mydebug("vabs\n"); static void* vinv(NrnThread* nt) { int i = nt->id; N_VInv_Serial(xarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VInv_NrnThread(N_Vector x, N_Vector z) { @@ -534,7 +534,7 @@ mydebug("vinv\n"); static void* vaddconst(NrnThread* nt) { int i = nt->id; N_VAddConst_Serial(xarg(i), barg, zarg(i)); - return (void*)0; + return nullptr; } void N_VAddConst_NrnThread(N_Vector x, realtype b, N_Vector z) { @@ -548,7 +548,7 @@ static void* vdotprod(NrnThread* nt) { int i = nt->id; s = N_VDotProd_Serial(xarg(i), yarg(i)); lockadd(s); - return (void*)0; + return nullptr; } realtype N_VDotProd_NrnThread(N_Vector x, N_Vector y) { @@ -564,7 +564,7 @@ static void* vmaxnorm(NrnThread* nt) { int i = nt->id; max = N_VMaxNorm_Serial(xarg(i)); lockmax(max); - return (void*)0; + return nullptr; } realtype N_VMaxNorm_NrnThread(N_Vector x) { @@ -598,7 +598,7 @@ static void* vwrmsnorm(NrnThread* nt) { int i = nt->id; s = vwrmsnorm_help(xarg(i), warg(i)); locklongdadd(s); - return (void*)0; + return nullptr; } realtype N_VWrmsNorm_NrnThread(N_Vector x, N_Vector w) { @@ -642,7 +642,7 @@ static void* vwrmsnormmask(NrnThread* nt) { int i = nt->id; s = vwrmsnormmask_help(xarg(i), warg(i), idarg(i)); lockadd(s); - return (void*)0; + return nullptr; } realtype N_VWrmsNormMask_NrnThread(N_Vector x, N_Vector w, N_Vector id) { @@ -662,7 +662,7 @@ static void* vmin(NrnThread* nt) { min = N_VMin_Serial(xarg(i)); lockmin(min); } - return (void*)0; + return nullptr; } realtype N_VMin_NrnThread(N_Vector x) { @@ -694,7 +694,7 @@ static void* vwl2norm(NrnThread* nt) { int i = nt->id; sum = N_VWL2Norm_helper(xarg(i), warg(i)); lockadd(sum); - return (void*)0; + return nullptr; } realtype N_VWL2Norm_NrnThread(N_Vector x, N_Vector w) { @@ -712,7 +712,7 @@ static void* vl1norm(NrnThread* nt) { int i = nt->id; sum = N_VL1Norm_Serial(xarg(i)); lockadd(sum); - return (void*)0; + return nullptr; } realtype N_VL1Norm_NrnThread(N_Vector x) { @@ -726,7 +726,7 @@ mydebug2("vl1norm %.20g\n", retval); static void* v1mask(NrnThread* nt) { int i = nt->id; N_VOneMask_Serial(xarg(i)); - return (void*)0; + return nullptr; } void N_VOneMask_NrnThread(N_Vector x) { @@ -737,7 +737,7 @@ void N_VOneMask_NrnThread(N_Vector x) static void* vcompare(NrnThread* nt) { int i = nt->id; N_VCompare_Serial(carg, xarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VCompare_NrnThread(realtype c, N_Vector x, N_Vector z) { @@ -751,7 +751,7 @@ static void* vinvtest(NrnThread* nt) { int i = nt->id; b = N_VInvTest_Serial(xarg(i), zarg(i)); if (!b) { lockfalse; } - return (void*)0; + return nullptr; } booleantype N_VInvTest_NrnThread(N_Vector x, N_Vector z) { @@ -767,7 +767,7 @@ static void* vconstrmask(NrnThread* nt) { int i = nt->id; b = N_VConstrMask_Serial(yarg(i), xarg(i), zarg(i)); if (!b) { lockfalse; } - return (void*)0; + return nullptr; } booleantype N_VConstrMask_NrnThread(N_Vector y, N_Vector x, N_Vector z) { @@ -783,7 +783,7 @@ static void* vminquotient(NrnThread* nt) { int i = nt->id; min = N_VMinQuotient_Serial(xarg(i), yarg(i)); lockmin(min); - return (void*)0; + return nullptr; } realtype N_VMinQuotient_NrnThread(N_Vector x, N_Vector y) /* num, denom */ { diff --git a/src/nrniv/nvector_nrnthread.h b/src/nrniv/nvector_nrnthread.h index c71339b83f..72f6091689 100755 --- a/src/nrniv/nvector_nrnthread.h +++ b/src/nrniv/nvector_nrnthread.h @@ -56,13 +56,12 @@ #ifndef _NVECTOR_NRNTHREAD_H #define _NVECTOR_NRNTHREAD_H -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif #include "nvector.h" #include "sundialstypes.h" +extern "C" { extern void N_VOneMask_Serial(N_Vector x); +} /* * ----------------------------------------------------------------- @@ -290,8 +289,5 @@ booleantype N_VInvTest_NrnThread(N_Vector x, N_Vector z); booleantype N_VConstrMask_NrnThread(N_Vector c, N_Vector x, N_Vector m); realtype N_VMinQuotient_NrnThread(N_Vector num, N_Vector denom); -#ifdef __cplusplus -} -#endif #endif diff --git a/src/nrniv/nvector_nrnthread_ld.c b/src/nrniv/nvector_nrnthread_ld.cpp similarity index 98% rename from src/nrniv/nvector_nrnthread_ld.c rename to src/nrniv/nvector_nrnthread_ld.cpp index 44af38a86b..5814eb8834 100755 --- a/src/nrniv/nvector_nrnthread_ld.c +++ b/src/nrniv/nvector_nrnthread_ld.cpp @@ -447,7 +447,7 @@ void N_VSetArrayPointer_NrnThreadLD(realtype *v_data, N_Vector v) static void* vlinearsum(NrnThread* nt) { int i = nt->id; N_VLinearSum_Serial(aarg, xarg(i), barg, yarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VLinearSum_NrnThreadLD(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z) { @@ -460,7 +460,7 @@ mydebug("vlinearsum\n"); static void* vconst(NrnThread* nt) { int i = nt->id; N_VConst_Serial(carg, zarg(i)); - return (void*)0; + return nullptr; } void N_VConst_NrnThreadLD(realtype c, N_Vector z) { @@ -472,7 +472,7 @@ mydebug("vconst\n"); static void* vprod(NrnThread* nt) { int i = nt->id; N_VProd_Serial(xarg(i), yarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VProd_NrnThreadLD(N_Vector x, N_Vector y, N_Vector z) { @@ -484,7 +484,7 @@ mydebug("vprod\n"); static void* vdiv(NrnThread* nt) { int i = nt->id; N_VDiv_Serial(xarg(i), yarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VDiv_NrnThreadLD(N_Vector x, N_Vector y, N_Vector z) { @@ -496,7 +496,7 @@ mydebug("vdiv\n"); static void* vscale(NrnThread* nt) { int i = nt->id; N_VScale_Serial(carg, xarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VScale_NrnThreadLD(realtype c, N_Vector x, N_Vector z) { @@ -509,7 +509,7 @@ mydebug("vscale\n"); static void* vabs(NrnThread* nt) { int i = nt->id; N_VAbs_Serial(xarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VAbs_NrnThreadLD(N_Vector x, N_Vector z) { @@ -521,7 +521,7 @@ mydebug("vabs\n"); static void* vinv(NrnThread* nt) { int i = nt->id; N_VInv_Serial(xarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VInv_NrnThreadLD(N_Vector x, N_Vector z) { @@ -533,7 +533,7 @@ mydebug("vinv\n"); static void* vaddconst(NrnThread* nt) { int i = nt->id; N_VAddConst_Serial(xarg(i), barg, zarg(i)); - return (void*)0; + return nullptr; } void N_VAddConst_NrnThreadLD(N_Vector x, realtype b, N_Vector z) { @@ -547,7 +547,7 @@ static void* vdotprod(NrnThread* nt) { int i = nt->id; s = N_VDotProd_Serial(xarg(i), yarg(i)); lockadd(s); - return (void*)0; + return nullptr; } realtype N_VDotProd_NrnThreadLD(N_Vector x, N_Vector y) { @@ -563,7 +563,7 @@ static void* vmaxnorm(NrnThread* nt) { int i = nt->id; max = N_VMaxNorm_Serial(xarg(i)); lockmax(max); - return (void*)0; + return nullptr; } realtype N_VMaxNorm_NrnThreadLD(N_Vector x) { @@ -597,7 +597,7 @@ static void* vwrmsnorm(NrnThread* nt) { int i = nt->id; s = vwrmsnorm_help(xarg(i), warg(i)); locklongdadd(s); - return (void*)0; + return nullptr; } realtype N_VWrmsNorm_NrnThreadLD(N_Vector x, N_Vector w) { @@ -641,7 +641,7 @@ static void* vwrmsnormmask(NrnThread* nt) { int i = nt->id; s = vwrmsnormmask_help(xarg(i), warg(i), idarg(i)); lockadd(s); - return (void*)0; + return nullptr; } realtype N_VWrmsNormMask_NrnThreadLD(N_Vector x, N_Vector w, N_Vector id) { @@ -661,7 +661,7 @@ static void* vmin(NrnThread* nt) { min = N_VMin_Serial(xarg(i)); lockmin(min); } - return (void*)0; + return nullptr; } realtype N_VMin_NrnThreadLD(N_Vector x) { @@ -693,7 +693,7 @@ static void* vwl2norm(NrnThread* nt) { int i = nt->id; sum = N_VWL2Norm_helper(xarg(i), warg(i)); lockadd(sum); - return (void*)0; + return nullptr; } realtype N_VWL2Norm_NrnThreadLD(N_Vector x, N_Vector w) { @@ -711,7 +711,7 @@ static void* vl1norm(NrnThread* nt) { int i = nt->id; sum = N_VL1Norm_Serial(xarg(i)); lockadd(sum); - return (void*)0; + return nullptr; } realtype N_VL1Norm_NrnThreadLD(N_Vector x) { @@ -725,7 +725,7 @@ mydebug2("vl1norm %.20g\n", retval); static void* v1mask(NrnThread* nt) { int i = nt->id; N_VOneMask_Serial(xarg(i)); - return (void*)0; + return nullptr; } void N_VOneMask_NrnThreadLD(N_Vector x) { @@ -736,7 +736,7 @@ void N_VOneMask_NrnThreadLD(N_Vector x) static void* vcompare(NrnThread* nt) { int i = nt->id; N_VCompare_Serial(carg, xarg(i), zarg(i)); - return (void*)0; + return nullptr; } void N_VCompare_NrnThreadLD(realtype c, N_Vector x, N_Vector z) { @@ -750,7 +750,7 @@ static void* vinvtest(NrnThread* nt) { int i = nt->id; b = N_VInvTest_Serial(xarg(i), zarg(i)); if (!b) { lockfalse; } - return (void*)0; + return nullptr; } booleantype N_VInvTest_NrnThreadLD(N_Vector x, N_Vector z) { @@ -766,7 +766,7 @@ static void* vconstrmask(NrnThread* nt) { int i = nt->id; b = N_VConstrMask_Serial(yarg(i), xarg(i), zarg(i)); if (!b) { lockfalse; } - return (void*)0; + return nullptr; } booleantype N_VConstrMask_NrnThreadLD(N_Vector y, N_Vector x, N_Vector z) { @@ -782,7 +782,7 @@ static void* vminquotient(NrnThread* nt) { int i = nt->id; min = N_VMinQuotient_Serial(xarg(i), yarg(i)); lockmin(min); - return (void*)0; + return nullptr; } realtype N_VMinQuotient_NrnThreadLD(N_Vector x, N_Vector y) /* num, denom */ { diff --git a/src/nrniv/nvector_nrnthread_ld.h b/src/nrniv/nvector_nrnthread_ld.h index a61af00016..fa770fe81c 100755 --- a/src/nrniv/nvector_nrnthread_ld.h +++ b/src/nrniv/nvector_nrnthread_ld.h @@ -6,8 +6,8 @@ */ /* Macros changed with -sed 's/NV_\([A-Za-z_]*\)_NT/NV_\1_NT_LD/g' nvector_nrnthread_ld.c > temp -mv temp nvector_nrnthread_ld.c +sed 's/NV_\([A-Za-z_]*\)_NT/NV_\1_NT_LD/g' nvector_nrnthread_ld.cpp > temp +mv temp nvector_nrnthread_ld.cpp sed 's/NV_\([A-Za-z_]*\)_NT/NV_\1_NT_LD/g' nvector_nrnthread_ld.h >temp mv temp nvector_nrnthread_ld.h */ @@ -62,13 +62,12 @@ mv temp nvector_nrnthread_ld.h #ifndef _NVECTOR_NRNTHREAD_LD_H #define _NVECTOR_NRNTHREAD_LD_H -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif #include "nvector.h" #include "sundialstypes.h" +extern "C" { extern void N_VOneMask_Serial(N_Vector x); +} /* * ----------------------------------------------------------------- @@ -296,8 +295,5 @@ booleantype N_VInvTest_NrnThreadLD(N_Vector x, N_Vector z); booleantype N_VConstrMask_NrnThreadLD(N_Vector c, N_Vector x, N_Vector m); realtype N_VMinQuotient_NrnThreadLD(N_Vector num, N_Vector denom); -#ifdef __cplusplus -} -#endif #endif diff --git a/src/nrniv/nvkludge.cpp b/src/nrniv/nvkludge.cpp index 82a0000d1a..be701b966a 100644 --- a/src/nrniv/nvkludge.cpp +++ b/src/nrniv/nvkludge.cpp @@ -13,22 +13,19 @@ #include "oc2iv.h" #include "scoplib_ansi.h" -extern "C" { extern double (*nrnpy_guigetval)(Object*); extern void (*nrnpy_guisetval)(Object*, double); extern int (*nrnpy_guigetstr)(Object*, char**); -} #if defined(CYGWIN) -extern "C" { extern int ncyg_fprintf(); -} #endif #if NRNMPI + +extern void nrn_timeout(int); extern "C" { - extern void nrn_timeout(int); extern double scop_random(); -} +} // extern "C" #endif extern void nrn_vecsim_add(void*, bool); diff --git a/src/nrniv/partrans.cpp b/src/nrniv/partrans.cpp index ea1e63459b..bf71bd2193 100644 --- a/src/nrniv/partrans.cpp +++ b/src/nrniv/partrans.cpp @@ -28,7 +28,6 @@ #if NRNLONGSGID #define sgid_t int64_t #if PARANEURON -extern "C" { extern void sgid_alltoallv(sgid_t* s, int* scnt, int* sdispl, sgid_t* r, int* rcnt, int* rdispl) { if (nrn_sparse_partrans > 0) @@ -38,12 +37,10 @@ extern "C" { nrnmpi_long_alltoallv(s, scnt, sdispl, r, rcnt, rdispl); } } -} #endif //PARANEURON #else // not NRNLONGSGID #define sgid_t int #if PARANEURON -extern "C" { extern void sgid_alltoallv(sgid_t* s, int* scnt, int* sdispl, sgid_t* r, int* rcnt, int* rdispl) { if (nrn_sparse_partrans > 0) @@ -53,11 +50,9 @@ extern "C" { nrnmpi_int_alltoallv(s, scnt, sdispl, r, rcnt, rdispl); } } -} #endif //PARANEURON #endif // not NRNLONGSGID -extern "C" { void nrnmpi_source_var(); void nrnmpi_target_var(); void nrnmpi_setup_transfer(); @@ -67,12 +62,12 @@ static void thread_transfer(NrnThread*); static void thread_vi_compute(NrnThread*); static void mk_ttd(); extern double t; -extern int v_structure_change; -extern int structure_change_cnt; +extern "C" int v_structure_change; +extern "C" int structure_change_cnt; extern int nrn_node_ptr_change_cnt_; -extern double* nrn_recalc_ptr(double*); +extern "C" double* nrn_recalc_ptr(double*); extern const char *bbcore_write_version; -// see lengthy comment in ../nrnoc/fadvance.c +// see lengthy comment in ../nrnoc/fadvance.cpp // nrnmpi_v_transfer requires existence of nrnthread_v_transfer even if there // is only one thread. // Thread 0 does the nrnmpi_v_transfer into incoming_src_buf. @@ -160,7 +155,6 @@ extern void nrnmpi_int_alltoallv(int*, int*, int*, int*, int*, int*); extern void nrnmpi_dbl_alltoallv(double*, int*, int*, double*, int*, int*); extern void nrnmpi_dbl_alltoallv_sparse(double*, int*, int*, double*, int*, int*); #endif -} struct TransferThreadData { int cnt; @@ -1041,9 +1035,7 @@ void pargap_jacobi_rhs(double* b, double* x) { } } -extern "C" { extern size_t nrnbbcore_gap_write(const char* path, int* group_ids); -} /* file format for /_gap.dat @@ -1099,8 +1091,8 @@ static void sidsort(int* sids, int cnt, int* indices); extern "C" { void get_partrans_setup_info(int tid, int& ntar, int& nsrc, - int& type, int& ix_vpre, int*& sid_target, int*& sid_src, int*& v_indices); -} +int& type, int& ix_vpre, int*& sid_target, int*& sid_src, int*& v_indices); +} // extern "C" void get_partrans_setup_info(int tid, int& ntar, int& nsrc, int& type, int& ix_vpre, int*& sid_target, int*& sid_src, int*& v_indices) { diff --git a/src/nrniv/ppshape.cpp b/src/nrniv/ppshape.cpp index 63dd1e9f15..9fa9432997 100644 --- a/src/nrniv/ppshape.cpp +++ b/src/nrniv/ppshape.cpp @@ -9,10 +9,8 @@ #endif //HAVE_IV #include "gui-redirect.h" -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); // ppshape registration diff --git a/src/nrniv/prcellstate.cpp b/src/nrniv/prcellstate.cpp index a401cc8f5a..316f3f1d6a 100644 --- a/src/nrniv/prcellstate.cpp +++ b/src/nrniv/prcellstate.cpp @@ -5,12 +5,11 @@ #include "netcon.h" #include "OS/table.h" #include "OS/list.h" +#include "neuron.h" #define precision 15 -extern "C" { void nrn_prcellstate(int gid, const char* filesuffix); -} declarePtrList(NetConList, NetCon) // NetCons in same order as Point_process implementPtrList(NetConList, NetCon) // and there may be several per pp. @@ -19,10 +18,6 @@ implementTable(PV2I, void*, int) static PV2I* pnt2index; // for deciding if NetCon is to be printed static int pntindex; // running count of printed point processes. -extern "C" -{ -#include "neuron.h" -} static void pr_memb(int type, Memb_list* ml, int* cellnodes, NrnThread& nt, FILE* f) { int header_printed = 0; @@ -194,3 +189,4 @@ void nrn_prcellstate(int gid, const char* suffix) { fclose(f); } + diff --git a/src/nrniv/pysecname2sec.cpp b/src/nrniv/pysecname2sec.cpp index 6bab92bc95..d25ca84ae9 100644 --- a/src/nrniv/pysecname2sec.cpp +++ b/src/nrniv/pysecname2sec.cpp @@ -4,9 +4,7 @@ #include #include -extern "C" { #include -} #include diff --git a/src/nrniv/savstate.cpp b/src/nrniv/savstate.cpp index 0831d33135..2f139f2984 100644 --- a/src/nrniv/savstate.cpp +++ b/src/nrniv/savstate.cpp @@ -13,7 +13,6 @@ typedef void (*ReceiveFunc)(Point_process*, double*, double); -extern "C" { #include "membfunc.h" extern int section_count; extern void nrn_shape_update(); @@ -21,13 +20,12 @@ extern Section** secorder; extern ReceiveFunc* pnt_receive; extern NetCvode* net_cvode_instance; extern TQueue* net_cvode_instance_event_queue(NrnThread*); -extern void clear_event_queue(); +extern "C" void clear_event_queue(); extern hoc_Item* net_cvode_instance_psl(); extern PlayRecList* net_cvode_instance_prl(); extern double t; extern short* nrn_is_artificial_; static void tqcallback(const TQItem* tq, int i); -}; #define ASSERTfgets(a,b,c) nrn_assert(fgets(a,b,c) != 0) #define ASSERTfread(a,b,c,d) nrn_assert(fread(a,b,c,d) == c) @@ -712,7 +710,7 @@ void SaveState::read(OcFile* ocf, bool close) { ocf->close(); hoc_execerror("Bad SaveState binary file", " Not version 6.0"); } - ASSERTfread((char*)&t_, sizeof(double), 1, f); + ASSERTfread(&t_, sizeof(double), 1, f); // fscanf(f, "%d %d\n", &nsec_, &nrootnode_); // on some os's fscanf leaves file pointer at wrong place for next fread // can check it with ftell(f) @@ -732,11 +730,11 @@ void SaveState::read(OcFile* ocf, bool close) { NodeState& ns = ss.ns[inode]; if (ns.nmemb) { ns.type = new int[ns.nmemb]; - ASSERTfread((char*)ns.type, sizeof(int), ns.nmemb, f); + ASSERTfread(ns.type, sizeof(int), ns.nmemb, f); } if (ns.nstate) { ns.state = new double[ns.nstate]; - ASSERTfread((char*)ns.state, sizeof(double), ns.nstate, f); + ASSERTfread(ns.state, sizeof(double), ns.nstate, f); } } if (ss.root) { @@ -744,11 +742,11 @@ void SaveState::read(OcFile* ocf, bool close) { NodeState& ns = *ss.root; if (ns.nmemb) { ns.type = new int[ns.nmemb]; - ASSERTfread((char*)ns.type, sizeof(int), ns.nmemb, f); + ASSERTfread(ns.type, sizeof(int), ns.nmemb, f); } if (ns.nstate) { ns.state = new double[ns.nstate]; - ASSERTfread((char*)ns.state, sizeof(double), ns.nstate, f); + ASSERTfread(ns.state, sizeof(double), ns.nstate, f); } } } @@ -764,7 +762,7 @@ void SaveState::read(OcFile* ocf, bool close) { assert(ns == nc * ssi[i].size); acell_[j].ncell = nc; acell_[j].state = new double[ns]; - ASSERTfread((char*)acell_[j].state, sizeof(double), ns, f); + ASSERTfread(acell_[j].state, sizeof(double), ns, f); ++j; } ASSERTfgets(buf, 20, f); @@ -788,7 +786,7 @@ void SaveState::write(OcFile* ocf, bool close) { BinaryMode(ocf) FILE* f = ocf->file(); fprintf(f, "SaveState binary file version 6.0\n"); - ASSERTfwrite((char*)&t_, sizeof(double), 1, f); + ASSERTfwrite(&t_, sizeof(double), 1, f); fprintf(f, "%d %d\n", nsec_, nroot_); fwrite_SecState(ss_, nsec_, f); for (int isec=0; isec < nsec_; ++isec) { @@ -797,20 +795,20 @@ void SaveState::write(OcFile* ocf, bool close) { for (int inode = 0; inode < ss.nnode; ++inode) { NodeState& ns = ss.ns[inode]; if (ns.nmemb){ - ASSERTfwrite((char*)ns.type, sizeof(int), ns.nmemb, f); + ASSERTfwrite(ns.type, sizeof(int), ns.nmemb, f); } if (ns.nstate) { - ASSERTfwrite((char*)ns.state, sizeof(double), ns.nstate, f); + ASSERTfwrite(ns.state, sizeof(double), ns.nstate, f); } } if (ss.root) { fwrite_NodeState(ss.root, 1, f); NodeState& ns = *ss.root; if (ns.nmemb){ - ASSERTfwrite((char*)ns.type, sizeof(int), ns.nmemb, f); + ASSERTfwrite(ns.type, sizeof(int), ns.nmemb, f); } if (ns.nstate) { - ASSERTfwrite((char*)ns.state, sizeof(double), ns.nstate, f); + ASSERTfwrite(ns.state, sizeof(double), ns.nstate, f); } } } @@ -818,7 +816,7 @@ void SaveState::write(OcFile* ocf, bool close) { for (int i=0, j=0; i < n_memb_func; ++i) if (nrn_is_artificial_[i]) { int sz = acell_[j].ncell * ssi[i].size; fprintf(f, "%d %d %d\n", acell_[j].type, acell_[j].ncell, sz); - ASSERTfwrite((char*)acell_[j].state, sizeof(double), sz, f); + ASSERTfwrite(acell_[j].state, sizeof(double), sz, f); ++j; } fprintf(f, "%d\n", nprs_); @@ -936,7 +934,7 @@ void SaveState::readnet(FILE* f) { sscanf(buf, "%d %d\n", &ncs_[i].object_index, &ncs_[i].nstate); if (ncs_[i].nstate) { ncs_[i].state = new double[ncs_[i].nstate]; - ASSERTfread((char*)ncs_[i].state, sizeof(double), ncs_[i].nstate, f); + ASSERTfread(ncs_[i].state, sizeof(double), ncs_[i].nstate, f); } } // PreSyn's @@ -944,7 +942,7 @@ void SaveState::readnet(FILE* f) { sscanf(buf, "%d\n", &npss_); if (npss_ != 0) { pss_ = new PreSynState[npss_]; - ASSERTfread((char*)pss_, sizeof(PreSynState), npss_, f); + ASSERTfread(pss_, sizeof(PreSynState), npss_, f); PreSyn* ps; i = 0; hoc_Item* q; @@ -962,7 +960,7 @@ void SaveState::readnet(FILE* f) { if (n) { tqs_->items = new DiscreteEvent*[n]; tqs_->tdeliver = new double[n]; - ASSERTfread((char*)tqs_->tdeliver, sizeof(double), n, f); + ASSERTfread(tqs_->tdeliver, sizeof(double), n, f); for (i=0; i < n; ++i) { DiscreteEvent* de = NULL; ASSERTfgets(buf, 200, f); @@ -1007,17 +1005,17 @@ void SaveState::writenet(FILE* f) { for (i=0; i < nncs_; ++i) { fprintf(f, "%d %d\n", ncs_[i].object_index, ncs_[i].nstate); if (ncs_[i].nstate) { - ASSERTfwrite((char*)ncs_[i].state, sizeof(double), ncs_[i].nstate, f); + ASSERTfwrite(ncs_[i].state, sizeof(double), ncs_[i].nstate, f); } } fprintf(f, "%d\n", npss_); if (npss_) { - ASSERTfwrite((char*)pss_, sizeof(PreSynState), npss_, f); + ASSERTfwrite(pss_, sizeof(PreSynState), npss_, f); } n = tqs_->nstate; fprintf(f, "%d\n", n); if (n) { - ASSERTfwrite((char*)tqs_->tdeliver, sizeof(double), n, f); + ASSERTfwrite(tqs_->tdeliver, sizeof(double), n, f); for (i=0; i < n; ++i) { tqs_->items[i]->savestate_write(f); } diff --git a/src/nrniv/secbrows.cpp b/src/nrniv/secbrows.cpp index 74a7155f0a..108c557817 100644 --- a/src/nrniv/secbrows.cpp +++ b/src/nrniv/secbrows.cpp @@ -16,12 +16,10 @@ #endif #include "nrnoc2iv.h" -extern "C" { #include "membfunc.h" - void (*nrnpy_call_python_with_section)(Object*, Section*) = NULL; - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +void (*nrnpy_call_python_with_section)(Object*, Section*) = NULL; +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); //----------------------------------------- static double sb_select(void* v) { diff --git a/src/nrniv/shape.cpp b/src/nrniv/shape.cpp index 8474fc6380..bb997b9570 100644 --- a/src/nrniv/shape.cpp +++ b/src/nrniv/shape.cpp @@ -43,17 +43,15 @@ #define Shape_Rotate_ "Rotate3D PlotShape" #define Shape_Style_ "ShapeStyle PlotShape" -extern "C" { - void nrn_define_shape(); - extern int nrn_shape_changed_; - extern int structure_change_cnt; - extern int section_count; - extern Section** secorder; - extern Point_process* ob2pntproc(Object*); - extern Point_process* ob2pntproc_0(Object*); - extern double* nrn_recalc_ptr(double*); - extern Object* (*nrnpy_seg_from_sec_x)(Section*, double); -} +void nrn_define_shape(); +extern int nrn_shape_changed_; +extern "C" int structure_change_cnt; +extern int section_count; +extern Section** secorder; +extern "C" Point_process* ob2pntproc(Object*); +extern "C" Point_process* ob2pntproc_0(Object*); +extern "C" double* nrn_recalc_ptr(double*); +extern Object* (*nrnpy_seg_from_sec_x)(Section*, double); #if BEVELJOIN static long beveljoin_ = 0; @@ -168,10 +166,8 @@ bool OcShapeHandler::event(Event&) { } #endif //HAVE_IV -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); // Shape class registration for oc static double sh_view(void* v) { diff --git a/src/nrniv/shapeplt.cpp b/src/nrniv/shapeplt.cpp index 25076ee7fd..3a08c727c2 100644 --- a/src/nrniv/shapeplt.cpp +++ b/src/nrniv/shapeplt.cpp @@ -38,17 +38,13 @@ #define ShapePlot_ "ShapePlot PlotShape" #define MoveText_ "MoveText PlotShape" -extern "C" { - extern Symlist* hoc_built_in_symlist; -} +extern Symlist* hoc_built_in_symlist; #endif // HAVE_IV -extern "C" { - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); - extern double (*nrnpy_object_to_double_)(Object*); - void* (*nrnpy_get_pyobj)(Object* obj) = 0; - void (*nrnpy_decref)(void* pyobj) = 0; -} +extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); +extern double (*nrnpy_object_to_double_)(Object*); +void* (*nrnpy_get_pyobj)(Object* obj) = 0; +void (*nrnpy_decref)(void* pyobj) = 0; // PlotShape class registration for oc static double sh_flush(void* v) { @@ -653,7 +649,7 @@ void ShapePlot::draw(Canvas* c, const Allocation& a) const { //will work on all x11 implementations. However, for WIN32, both cause //problems and thus the implementation of Canvas16::clip was changed to // not do an intersection and the "damage_all" below along with a change -// to the window.c paint function in which the damage area is reread before +// to the window.cpp paint function in which the damage area is reread before // the bit block transfer solves the problem. // At any rate this is fast only for the first view since the fast_draw's // only work once. diff --git a/src/nrniv/singlech.cpp b/src/nrniv/singlech.cpp index 47c08aaa36..2a77152087 100644 --- a/src/nrniv/singlech.cpp +++ b/src/nrniv/singlech.cpp @@ -6,18 +6,18 @@ #include "ocmatrix.h" #include "classreg.h" #include "singlech.h" -extern "C" { #include "membfunc.h" -} #include "random1.h" #include "NegExp.h" extern "C" { + +extern double exprand(double); // must be changed! + +} // extern "C" void hoc_reg_singlechan(int, void (*)(...)); void _singlechan_declare(void (*)(double, double*, Datum*), int*, int); void _nrn_single_react(int, int, double); -extern double exprand(double); // must be changed! -} /* encoded in the order of the rates and to_states below is the order @@ -88,7 +88,6 @@ void SingleChanState::rate(int to_state, double value) { ++n_; } -extern "C" { // bug in cray compiler. But it cant hurt. void hoc_reg_singlechan(int type, void (*f)(...)){ if (!infolist) { infolist = new SingleChanInfoList(); @@ -110,7 +109,6 @@ void _singlechan_declare(void (*f)(double, double*, Datum*), int* slist, int n) info->slist_ = slist; info->n_ = n; } -} void _nrn_single_react(int i, int j, double rate) { // printf("_nrn_single_react %d %d %g\n", i, j, rate); diff --git a/src/nrniv/spaceplt.cpp b/src/nrniv/spaceplt.cpp index c2f86a1690..1eac7ba9a2 100644 --- a/src/nrniv/spaceplt.cpp +++ b/src/nrniv/spaceplt.cpp @@ -18,14 +18,13 @@ #include "nrnoc2iv.h" #include "objcmd.h" -extern "C" { extern int nrn_multisplit_active_; extern int hoc_execerror_messages; extern int node_index(Section*, double); -extern int structure_change_cnt, nrn_shape_changed_; +extern "C" int structure_change_cnt; +extern int nrn_shape_changed_; extern int hoc_return_type_code; Object* (*nrnpy_rvp_rxd_to_callable)(Object*) = 0; -}; class SecPos { public: diff --git a/src/nrniv/splitcell.cpp b/src/nrniv/splitcell.cpp index 99dfecb92e..c7020c12bb 100644 --- a/src/nrniv/splitcell.cpp +++ b/src/nrniv/splitcell.cpp @@ -21,10 +21,9 @@ setting up and transfer of matrix information. Note that gid information about the subtrees is no longer required by this implementation. */ -extern "C" { void nrnmpi_splitcell_connect(int that_host); // that_host must be adjacent to nrnmpi_myid -extern int structure_change_cnt; +extern "C" int structure_change_cnt; #if PARANEURON void nrnmpi_split_clear(); @@ -33,7 +32,6 @@ extern void nrnmpi_send_doubles(double*, int cnt, int dest, int tag); extern void nrnmpi_recv_doubles(double*, int cnt, int src, int tag); extern double nrnmpi_splitcell_wait_; #endif -} #if PARANEURON static int change_cnt_; diff --git a/src/nrniv/vrecord.cpp b/src/nrniv/vrecord.cpp index 6e58879196..9ea3db720f 100644 --- a/src/nrniv/vrecord.cpp +++ b/src/nrniv/vrecord.cpp @@ -16,11 +16,9 @@ #include "netcvode.h" #include "cvodeobj.h" -extern "C" { extern double t; extern NetCvode* net_cvode_instance; -extern Point_process* ob2pntproc(Object*); -} +extern "C" Point_process* ob2pntproc(Object*); //Vector.play_remove() void nrn_vecsim_remove(void* v) { diff --git a/src/nrnjava/Makefile.am b/src/nrnjava/Makefile.am index b48503df03..b63919db28 100755 --- a/src/nrnjava/Makefile.am +++ b/src/nrnjava/Makefile.am @@ -3,7 +3,7 @@ SUBDIRS = neuron nrnccmb ## The list of libraries that we make from this directory. lib_LTLIBRARIES = libnrnjava.la -## These are all the .c files that need to be compiled to make libnrnjava.la. +## These are all the .cpp files that need to be compiled to make libnrnjava.la. libnrnjava_la_SOURCES = njvm.cpp nrnjava.cpp nrnjni.cpp pkginclude_HEADERS = njvm.h diff --git a/src/nrnjava/neuron/Neuron.java b/src/nrnjava/neuron/Neuron.java index f1cc2af7d2..1231b69278 100755 --- a/src/nrnjava/neuron/Neuron.java +++ b/src/nrnjava/neuron/Neuron.java @@ -426,7 +426,7 @@ static Object callMethod( Object o, int classID, int methodID, int overloaded) { // need to figure out which of the overloaded methods to use. if (overloaded != 0) { // actual value of overload is overloaded-1 due to trick - // used in src/oc/hoc_oop.c for s_varn. + // used in src/oc/hoc_oop.cpp for s_varn. System.out.println("don't know which of " + (overloaded-1) + " overloaded methods to use"); } MethodInfo mi = ci.getMethodInfo( methodID ); diff --git a/src/nrnjava/njvm.cpp b/src/nrnjava/njvm.cpp index f586506f30..25dcf4ded2 100644 --- a/src/nrnjava/njvm.cpp +++ b/src/nrnjava/njvm.cpp @@ -130,7 +130,7 @@ static int nj_load() { } #if USEJVM == 2 -// copied from /usr/j2se/src.jar : src/launcher/java.c +// copied from /usr/j2se/src.jar : src/launcher/java.cpp /* * Adds a new VM option with the given given name and value. */ @@ -163,7 +163,7 @@ AddOption(char *str, void *info) } #endif -// copied from /usr/j2se/src.jar : src/launcher/java.c +// copied from /usr/j2se/src.jar : src/launcher/java.cpp /* * Prints the version information from the java.version and other properties. */ @@ -248,7 +248,7 @@ static void initialize_jvm1() { args.classpath = classpath; //for (int i = 0; args.properties[i]; ++i) { //printf("properties |%s|\n", args.properties[i]); - //} + } // extern "C" //args.debugging = 1; //args.vfprintf = myvfprintf; printf("classpath |%s|\n", args.classpath); @@ -507,10 +507,10 @@ static jint nrn_GetDefaultJavaVMInitArgs(void* args) { myErr = GetIndSymbol(id, i, sname, &sa, &sc); sname[sname[0]+1] = '\0'; //printf("%d %s\n", i, sname+1); - if (strcmp((char*)(sname+1), "nrn2_GetDefaultJavaVMInitArgs") == 0) { + if (strcmp((sname+1), "nrn2_GetDefaultJavaVMInitArgs") == 0) { iaddr = (PIJVM)sa; } - if (strcmp((char*)(sname+1), "nrn2_CreateJavaVM") == 0) { + if (strcmp((sname+1), "nrn2_CreateJavaVM") == 0) { caddr = (PCJVM)sa; } } diff --git a/src/nrnjava/njvm.h b/src/nrnjava/njvm.h index bbb0d8f926..d2571cf5b6 100755 --- a/src/nrnjava/njvm.h +++ b/src/nrnjava/njvm.h @@ -4,16 +4,10 @@ #define jnisave JNIEnv* jesave = nrnjava_env; nrnjava_env = env; #define jnirestore nrnjava_env = jesave; -#if defined(__cplusplus) -extern "C" { -#endif extern JNIEnv* nrnjava_env; extern JNIEnv* nrnjava_root_env; -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/nrnjava/nrnccmb/NrnKSChan.java b/src/nrnjava/nrnccmb/NrnKSChan.java index 1583b30750..a6928685dc 100755 --- a/src/nrnjava/nrnccmb/NrnKSChan.java +++ b/src/nrnjava/nrnccmb/NrnKSChan.java @@ -145,7 +145,7 @@ private void structure(Object[] data) { //System.out.println("structure_ "); //for (i=0; i < st.length; ++i) { // System.out.println(i + " " +st[i]); -//} +} // extern "C" structure_.toHoc(st); ho_.dMethod("setstructure", new Object[]{structure_}); ho_.dMethod("setion", new Object[]{ @@ -217,7 +217,7 @@ public void sync_rates(HocObject h) { //System.out.println("sync_rates "); //for (int k=0; k < rat[j].length; ++k) { // System.out.println(k + " " +rat[j][k]); -//} +} // extern "C" } } ch_.setData(data); diff --git a/src/nrnjava/nrnjava.cpp b/src/nrnjava/nrnjava.cpp index 4e338cd211..ea442035cf 100644 --- a/src/nrnjava/nrnjava.cpp +++ b/src/nrnjava/nrnjava.cpp @@ -25,11 +25,12 @@ #include "parse.h" #include "njvm.h" - -extern "C" { + extern Symlist* hoc_top_level_symlist; -// Hooks in nrn-5.0.0/src/oc/hoc_oop.c for filling in cTemplate structure +extern "C" { + +// Hooks in nrn-5.0.0/src/oc/hoc_oop.cpp for filling in cTemplate structure extern void* (*p_java2nrn_cons)(Object*); /* returns pointer to java object */ extern void (*p_java2nrn_destruct)(void* opaque_java_object); extern double (*p_java2nrn_dmeth)(Object* ho, Symbol* method); diff --git a/src/nrnjava/nrnjni.cpp b/src/nrnjava/nrnjni.cpp index 6d669bd1f8..ae292ef31e 100755 --- a/src/nrnjava/nrnjni.cpp +++ b/src/nrnjava/nrnjni.cpp @@ -36,6 +36,8 @@ extern Symbol* nrn_vec_sym; void* nrnjava_pwm_listen(const char*, Object*); void nrnjava_pwm_event(size_t, int, int, int, int, int); +extern Symlist* hoc_top_level_symlist; + extern "C" { /** Create a hoc class from a java one @@ -45,7 +47,7 @@ Symbol* java2nrn_class(const char* classname, int classindex, const char* methods); extern double* hoc_varpointer; -extern Symlist* hoc_top_level_symlist; + extern Objectdata* hoc_top_level_data; double hoc_integer(double); Object* hoc_new_object(Symbol*, void*); diff --git a/src/nrnmpi/Makefile.am b/src/nrnmpi/Makefile.am index 0d7a8b7465..3688e3ffd5 100755 --- a/src/nrnmpi/Makefile.am +++ b/src/nrnmpi/Makefile.am @@ -4,7 +4,7 @@ nsrc=$(top_srcdir)/src includes = -I$(nsrc)/oc @NRN_REALTIME_INCLUDE@ -I@MUSIC_INCDIR@ AM_CFLAGS = @MINGW_CFLAG@ $(includes) -libnrnmpi_la_SOURCES = nrnmpi.c bbsmpipack.c mpispike.c nrnrt.c +libnrnmpi_la_SOURCES = nrnmpi.cpp bbsmpipack.cpp mpispike.cpp nrnrt.cpp CC = @MPICCnrnmpi@ @@ -28,4 +28,4 @@ endif libnrnmpi_la_LIBADD = @MUSIC_LIBLA@ $(NEED_RTLD_GLOBAL) EXTRA_DIST = nrnmpidec.h nrnmpi_impl.h mpispike.h notes_nrnrt \ - mkdynam.sh nrnmpi_dynam.c nrnmpi_dynam_stubs.c nrnmpi_def_cinc + mkdynam.sh nrnmpi_dynam.cpp nrnmpi_dynam_stubs.cpp nrnmpi_def_cinc diff --git a/src/nrnmpi/bbsmpipack.c b/src/nrnmpi/bbsmpipack.cpp similarity index 97% rename from src/nrnmpi/bbsmpipack.c rename to src/nrnmpi/bbsmpipack.cpp index 168c56c049..5c56939ecd 100755 --- a/src/nrnmpi/bbsmpipack.c +++ b/src/nrnmpi/bbsmpipack.cpp @@ -149,7 +149,7 @@ void nrnmpi_upkvec(int n, double* x, bbsmpibuf* r) { #if NRNMPI_DYNAMICLOAD /* for some unknown reason mpiexec -n 2 python3 test0.py gives load_nrnmpi: /home/hines/neuron/nrndynam/x86_64/lib/libnrnmpi.so: undefined symbol: cxx_char_alloc -So fill this in explicitly in nrnmpi_dynam.c +So fill this in explicitly in nrnmpi_dynam.cpp */ char* (*p_cxx_char_alloc)(int len); #endif @@ -186,7 +186,7 @@ static void resize(bbsmpibuf* r, int size) { int newsize; if (r->size < size) { newsize = (size/64)*64 + 128; - r->buf = hoc_Erealloc(r->buf, newsize); hoc_malchk(); + r->buf = static_cast(hoc_Erealloc(r->buf, newsize)); hoc_malchk(); r->size = newsize; } } @@ -272,13 +272,13 @@ void nrnmpi_pkstr(const char* s, bbsmpibuf* r) { int len; len = strlen(s); pack(&len, 1, my_MPI_INT, r, "pkstr length"); - pack((char*)s, len, my_MPI_CHAR, r, "pkstr string"); + pack(&s, len, my_MPI_CHAR, r, "pkstr string"); } void nrnmpi_pkpickle(const char* s, size_t size, bbsmpibuf* r) { int len = size; pack(&len, 1, my_MPI_INT, r, "pkpickle length"); - pack((char*)s, len, my_MPI_PICKLE, r, "pkpickle data"); + pack(&s, len, my_MPI_PICKLE, r, "pkpickle data"); } void nrnmpi_bbssend(int dest, int tag, bbsmpibuf* r) { @@ -393,7 +393,7 @@ printf("%d nrnmpi_newbuf %p\n", nrnmpi_myid_bbs, buf); #endif buf->buf = (char*)0; if (size > 0) { - buf->buf = (char*)hoc_Emalloc(size*sizeof(char)) ; hoc_malchk(); + buf->buf = static_cast(hoc_Emalloc(size*sizeof(char))) ; hoc_malchk(); } buf->size = size; buf->pkposition = 0; diff --git a/src/nrnmpi/mpispike.c b/src/nrnmpi/mpispike.cpp similarity index 98% rename from src/nrnmpi/mpispike.c rename to src/nrnmpi/mpispike.cpp index 2f475be203..0d684155e4 100644 --- a/src/nrnmpi/mpispike.c +++ b/src/nrnmpi/mpispike.cpp @@ -278,7 +278,7 @@ static int MPI_Alltoallv_sparse(void *sendbuf, int *sendcnts, int *sdispls, if(target >= nranks) continue; if(recvcnts[target] == 0) continue; - status = MPI_Irecv(((char*) recvbuf) + recv_elsize * rdispls[target], + status = MPI_Irecv((static_cast(recvbuf)) + recv_elsize * rdispls[target], recvcnts[target], recvtype, target, ALLTOALLV_SPARSE_TAG, comm, &requests[n_requests++]); assert(status == MPI_SUCCESS); @@ -292,7 +292,7 @@ static int MPI_Alltoallv_sparse(void *sendbuf, int *sendcnts, int *sdispls, int target = myrank ^ ngrp; if(target >= nranks) continue; if(sendcnts[target] == 0) continue; - status = MPI_Isend(((char*) sendbuf) + send_elsize * sdispls[target], + status = MPI_Isend((static_cast(sendbuf)) + send_elsize * sdispls[target], sendcnts[target], sendtype, target, ALLTOALLV_SPARSE_TAG, comm, &requests[n_requests++]); assert(status == MPI_SUCCESS); @@ -438,7 +438,7 @@ void nrnmpi_char_broadcast_world(char** pstr, int root) { if (nrnmpi_myid_world != root) { if (*pstr) { free(*pstr); *pstr = NULL; } if (sz) { - *pstr = (char*)hoc_Emalloc(sz*sizeof(char)); hoc_malchk(); + *pstr = static_cast(hoc_Emalloc(sz*sizeof(char))); hoc_malchk(); } } if (sz) { @@ -573,7 +573,7 @@ double nrnmpi_dbl_allreduce(double x, int type) { return result; } -void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type) { +extern "C" void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type) { int i; MPI_Op t; assert(src != dest); diff --git a/src/nrnmpi/mpispike.h b/src/nrnmpi/mpispike.h index e4e6b5c095..83b2446d71 100644 --- a/src/nrnmpi/mpispike.h +++ b/src/nrnmpi/mpispike.h @@ -13,9 +13,6 @@ typedef struct { } NRNMPI_Spikebuf; #endif -#if defined(__cplusplus) -extern "C" { -#endif #define icapacity_ nrnmpi_i_capacity_ #define spikeout_ nrnmpi_spikeout_ @@ -52,8 +49,5 @@ extern NRNMPI_Spikebuf* spbufout_; extern NRNMPI_Spikebuf* spbufin_; #endif -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/nrnmpi/nrnmpi.c b/src/nrnmpi/nrnmpi.cpp similarity index 99% rename from src/nrnmpi/nrnmpi.c rename to src/nrnmpi/nrnmpi.cpp index 0e8c89532f..16a5ea385c 100644 --- a/src/nrnmpi/nrnmpi.c +++ b/src/nrnmpi/nrnmpi.cpp @@ -55,7 +55,7 @@ static int nrnmpi_under_nrncontrol_; static int nrnmpi_is_setup_; #endif -void nrnmpi_init(int nrnmpi_under_nrncontrol, int* pargc, char*** pargv) { +extern "C" void nrnmpi_init(int nrnmpi_under_nrncontrol, int* pargc, char*** pargv) { #if NRNMPI int i, b, flag; if (nrnmpi_use) { diff --git a/src/nrnmpi/nrnmpi_dynam.c b/src/nrnmpi/nrnmpi_dynam.cpp similarity index 96% rename from src/nrnmpi/nrnmpi_dynam.c rename to src/nrnmpi/nrnmpi_dynam.cpp index ebf1f80a03..8d4345ae0a 100644 --- a/src/nrnmpi/nrnmpi_dynam.c +++ b/src/nrnmpi/nrnmpi_dynam.cpp @@ -23,7 +23,7 @@ extern char* dlerror(); #include "nrnmpi.h" -extern char* cxx_char_alloc(int); +extern char* cxx_char_alloc(size_t); #if DARWIN || defined(__linux__) extern const char* path_prefix_to_libnrniv(); @@ -31,9 +31,11 @@ extern const char* path_prefix_to_libnrniv(); #include "mpispike.h" #include "nrnmpi_def_cinc" /* nrnmpi global variables */ +extern "C" { #include "nrnmpi_dynam_cinc" /* autogenerated file */ +} #include "nrnmpi_dynam_wrappers.inc" /* autogenerated file */ -#include "nrnmpi_dynam_stubs.c" +#include "nrnmpi_dynam_stubs.cpp" static void* load_mpi(const char* name, char* mes) { int flag = RTLD_NOW | RTLD_GLOBAL; @@ -64,7 +66,7 @@ static void* load_nrnmpi(const char* name, char* mes) { *ftable[i].ppf = p; } { - char* (**p)(int) = (char* (**)(int))dlsym(handle, "p_cxx_char_alloc"); + char* (**p)(size_t) = (char* (**)(size_t))dlsym(handle, "p_cxx_char_alloc"); if (!p) { sprintf(mes+strlen(mes), "load_nrnmpi: %s\n", dlerror()); return 0; @@ -78,7 +80,7 @@ char* nrnmpi_load(int is_python) { int ismes=0; char* pmes; void* handle = NULL; - pmes = (char*)malloc(4096); + pmes = static_cast(malloc(4096)); assert(pmes); pmes[0]='\0'; #if DARWIN @@ -170,7 +172,7 @@ sprintf(pmes+strlen(pmes), "Is openmpi installed? If not in default location, ne /* safest to use full path for libnrnmpi... */ const char* prefix = path_prefix_to_libnrniv(); /* enough space for prefix + "libnrnmpi..." */ - char* lname = malloc(strlen(prefix) + 50); + char* lname = static_cast(malloc(strlen(prefix) + 50)); assert(lname); /* loaded but is it openmpi or mpich */ if (dlsym(handle, "ompi_mpi_init")) { /* it is openmpi */ diff --git a/src/nrnmpi/nrnmpi_dynam_stubs.c b/src/nrnmpi/nrnmpi_dynam_stubs.cpp similarity index 100% rename from src/nrnmpi/nrnmpi_dynam_stubs.c rename to src/nrnmpi/nrnmpi_dynam_stubs.cpp diff --git a/src/nrnmpi/nrnmpi_impl.h b/src/nrnmpi/nrnmpi_impl.h index 7114c63823..61084b66ad 100644 --- a/src/nrnmpi/nrnmpi_impl.h +++ b/src/nrnmpi/nrnmpi_impl.h @@ -3,9 +3,17 @@ #include +#if defined(__cplusplus) +extern "C" { +#endif + extern void* hoc_Emalloc(size_t size); -extern void* hoc_Erealloc(void* buf, size_t size); extern void hoc_malchk(); +extern void* hoc_Erealloc(void* buf, size_t size); + +#if defined(__cplusplus) +} +#endif extern MPI_Comm nrnmpi_world_comm; extern MPI_Comm nrnmpi_comm; diff --git a/src/nrnmpi/nrnmpidec.h b/src/nrnmpi/nrnmpidec.h index 12df8a5d05..2c44ddabf5 100755 --- a/src/nrnmpi/nrnmpidec.h +++ b/src/nrnmpi/nrnmpidec.h @@ -16,7 +16,7 @@ typedef long double longdbl; extern "C" { #endif -/* from bbsmpipack.c */ +/* from bbsmpipack.cpp */ typedef struct bbsmpibuf { char* buf; int size; @@ -54,7 +54,7 @@ extern void nrnmpi_bbssend(int dest, int tag, bbsmpibuf* r); extern int nrnmpi_bbsrecv(int source, bbsmpibuf* r); extern int nrnmpi_bbssendrecv(int dest, int tag, bbsmpibuf* s, bbsmpibuf* r); -/* from nrnmpi.c */ +/* from nrnmpi.cpp */ extern void nrnmpi_init(int nrnmpi_under_nrncontrol, int* pargc, char*** pargv); extern int nrnmpi_wrap_mpi_init(int* flag); extern double nrnmpi_wtime(); @@ -62,7 +62,8 @@ extern void nrnmpi_terminate(); extern void nrnmpi_abort(int errcode); extern void nrnmpi_subworld_size(int n); -/* from mpispike.c */ + +/* from mpispike.cpp */ extern void nrnmpi_spike_initialize(); extern int nrnmpi_spike_exchange(); extern int nrnmpi_spike_exchange_compressed(); @@ -104,9 +105,11 @@ extern void nrnmpi_postrecv_doubles(double* pd, int cnt, int src, int tag, void* extern void nrnmpi_wait(void** request); extern void nrnmpi_barrier(); extern double nrnmpi_dbl_allreduce(double x, int type); + extern void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type); extern void nrnmpi_longdbl_allreduce_vec(longdbl* src, longdbl* dest, int cnt, int type); extern void nrnmpi_long_allreduce_vec(long* src, long* dest, int cnt, int type); + extern void nrnmpi_dbl_allgather(double* s, double* r, int n); #if BGPDMA extern void nrnmpi_bgp_comm(); @@ -115,8 +118,10 @@ extern int nrnmpi_bgp_single_advance(NRNMPI_Spike* spk); extern int nrnmpi_bgp_conserve(int nsend, int nrecv); #endif + #if defined(__cplusplus) } #endif + #endif #endif diff --git a/src/nrnmpi/nrnrt.c b/src/nrnmpi/nrnrt.cpp similarity index 99% rename from src/nrnmpi/nrnrt.c rename to src/nrnmpi/nrnrt.cpp index 314bf4e1d1..d86377f3cb 100644 --- a/src/nrnmpi/nrnrt.c +++ b/src/nrnmpi/nrnrt.cpp @@ -90,7 +90,7 @@ static void* rtrun_fun(void* arg) { } rt_task_delete(rtrun_task_); ++end_; - return (void*)0; + return nullptr; } void nrn_maintask_init() { diff --git a/src/nrnoc/Makefile.am b/src/nrnoc/Makefile.am index 6f70cc62d8..e45088937b 100755 --- a/src/nrnoc/Makefile.am +++ b/src/nrnoc/Makefile.am @@ -1,7 +1,7 @@ ## The program that we make from this directory. bin_PROGRAMS = nrnoc -nrnoc_SOURCES = ocmain.c nrnnoiv.c ocnoiv.c cprop.c +nrnoc_SOURCES = ocmain.cpp nrnnoiv.cpp ocnoiv.cpp cprop.cpp if BUILD_NRNMPI_DYNAMIC nrnmpila = diff --git a/src/nrnoc/cabcode.c b/src/nrnoc/cabcode.cpp similarity index 96% rename from src/nrnoc/cabcode.c rename to src/nrnoc/cabcode.cpp index d42c4d663b..fbf6557fdd 100644 --- a/src/nrnoc/cabcode.c +++ b/src/nrnoc/cabcode.cpp @@ -1,5 +1,5 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/nrnoc/cabcode.c,v 1.37 1999/07/08 14:24:59 hines Exp */ +/* /local/src/master/nrn/src/nrnoc/cabcode.cpp,v 1.37 1999/07/08 14:24:59 hines Exp */ #define HOC_L_LIST 1 #include @@ -49,13 +49,13 @@ static int isecstack = 0; /* stack index */ */ static int skip_secstack_check = 0; -static int range_vec_indx(); +static int range_vec_indx(Symbol* s); int nrn_isecstack(void) { return isecstack; } -void nrn_secstack(i) int i; { +void nrn_secstack(int i) { if (skip_secstack_check) { return; } #if 1 if (isecstack > i) { @@ -94,7 +94,7 @@ void oc_restore_cabcode(int* a1, int* a2) section_object_seen = *a2; } -void nrn_pushsec(Section* sec) +extern "C" void nrn_pushsec(Section* sec) { isecstack++; if (isecstack >= NSECSTACK) { @@ -119,7 +119,7 @@ void nrn_pushsec(Section* sec) } } -void nrn_popsec(void) { +extern "C" void nrn_popsec(void) { if (isecstack > 0) { Section* sec = secstack[isecstack--]; if (!sec) { @@ -233,7 +233,7 @@ Object* nrn_sec2cell(Section* sec) { return o; } } - return (Object*)0; + return nullptr; } int nrn_sec2cell_equals(Section* sec, Object* obj) { @@ -264,10 +264,10 @@ static Section* new_section(Object* ob, Symbol* sym, int i){ if (ob) { prop->dparam[6].obj = ob; }else{ - prop->dparam[6].obj = (Object*)0; + prop->dparam[6].obj = nullptr; } #if USE_PYTHON - prop->dparam[PROP_PY_INDEX]._pvoid = (void*)0; + prop->dparam[PROP_PY_INDEX]._pvoid = nullptr; #endif nrn_pushsec(sec); d = (double)DEF_nseg; @@ -296,7 +296,8 @@ void new_sections(Object* ob, Symbol* sym, Item** pitm, int size){ } #if USE_PYTHON -Section* nrnpy_newsection(void* v) { +struct NPySecObj; +Section* nrnpy_newsection(NPySecObj* v) { Item* itm; Section* sec; sec = new_section((Object*)0, (Symbol*)0, 0); @@ -390,33 +391,32 @@ double nrn_ra(Section* sec) return sec->prop->dparam[7].val; } -void cab_alloc(Prop* p) { - Datum *pd; +void cab_alloc(Prop *p) { + Datum *pd; #if USE_PYTHON #define CAB_SIZE 11 #else #define CAB_SIZE 10 #endif - pd = nrn_prop_datum_alloc(CABLESECTION, CAB_SIZE, p); - pd[1].val = pd[3].val = 0.; - pd[2].val = DEF_L; - pd[4].val = DEF_rallbranch; - pd[7].val = DEF_Ra; - p->dparam = pd; - p->param_size = CAB_SIZE; /* this one is special since it refers to dparam */ + pd = nrn_prop_datum_alloc(CABLESECTION, CAB_SIZE, p); + pd[1].val = pd[3].val = 0.; + pd[2].val = DEF_L; + pd[4].val = DEF_rallbranch; + pd[7].val = DEF_Ra; + p->dparam = pd; + p->param_size = CAB_SIZE; /* this one is special since it refers to dparam */ } void morph_alloc(Prop* p) { - - double *pd; - pd = nrn_prop_data_alloc(MORPHOLOGY, 1, p); - pd[0] = DEF_diam; /* microns */ - diam_changed = 1; - p->param = pd; - p->param_size = 1; + double *pd; + pd = nrn_prop_data_alloc(MORPHOLOGY, 1, p); + pd[0] = DEF_diam; /* microns */ + diam_changed = 1; + p->param = pd; + p->param_size = 1; } - + double nrn_diameter(Node* nd) { Prop* p; @@ -431,7 +431,7 @@ void nrn_chk_section(Symbol* s) } } -Section* chk_access(void) +extern "C" Section* chk_access(void) { Section* sec = secstack[isecstack]; if (!sec || !sec->prop) { @@ -548,7 +548,7 @@ static void reverse_sibling_list(Section* sec) } pch = &sec->child; while(scnt--) { - Object** hoc_objpop(); +// Object** hoc_objpop(); ch = (Section*)hoc_objpop(); *pch = ch; pch = &ch->sibling; @@ -675,21 +675,22 @@ static Section* Sec_access(void) /* section symbol at pc */ if (!s) { return chk_access(); } - if (s->public == 2) { - s = s->u.sym; - odsav = hoc_objectdata_save(); - obsav = hoc_thisobject; - slsav = hoc_symlist; - hoc_objectdata = hoc_top_level_data; - hoc_thisobject = 0; - hoc_symlist = hoc_top_level_symlist; + + if (s->cpublic == 2) { + s = s->u.sym; + odsav = hoc_objectdata_save(); + obsav = hoc_thisobject; + slsav = hoc_symlist; + hoc_objectdata = hoc_top_level_data; + hoc_thisobject = 0; + hoc_symlist = hoc_top_level_symlist; } nrn_chk_section(s); itm = OPSECITM(s)[range_vec_indx(s)]; if (obsav) { - hoc_objectdata = hoc_objectdata_restore(odsav); - hoc_thisobject = obsav; - hoc_symlist = slsav; + hoc_objectdata = hoc_objectdata_restore(odsav); + hoc_thisobject = obsav; + hoc_symlist = slsav; } if (!itm) { hoc_execerror(s->name, ": section was deleted"); @@ -750,7 +751,7 @@ void* hoc_sec_internal_name2ptr(const char* s, int eflag) { /* syntax is __nrnsec_0xff... and need to verify that ff... is a pointer to a Section. To avoid invalid memory read errors, we changed - the section allocation/free in solve.c to use a SectionPool which + the section allocation/free in solve.cpp to use a SectionPool which allows checking to see if a void* is a possible Section* from the pool. */ @@ -1097,7 +1098,7 @@ Prop* nrn_mechanism_check(int type, Section* sec, int inode) return m; } -Prop* hoc_getdata_range(int type) +extern "C" Prop* hoc_getdata_range(int type) { int inode; Section *sec; @@ -1119,7 +1120,7 @@ static Datum* pdprop(Symbol* s, int indx, Section* sec, short inode) { void connectpointer(void) { /* pointer symbol at pc, target variable on stack, maybe range variable location on stack */ Datum *dat; - double *pd, *hoc_pxpop(); + double *pd;//, *hoc_pxpop(); double d; Symbol *s = (pc++)->sym; pd = hoc_pxpop(); @@ -1149,7 +1150,7 @@ void range_interpolate_single(void) /*symbol at pc, 2 values on stack*/ double x, y; Symbol* s; Section* sec; - double* pd, *nrn_rangepointer(); + double* pd; //, *nrn_rangepointer(); int op; s = (pc++)->sym; @@ -1448,7 +1449,7 @@ void rangevarevalpointer(void) /* symbol at pc, location on stack, return pointe void rangevareval(void) /* symbol at pc, location on stack, return value on stack */ { - double *pd, *hoc_pxpop(); + double *pd;//, *hoc_pxpop(); rangevarevalpointer(); pd = hoc_pxpop(); @@ -1656,7 +1657,7 @@ int nrn_at_beginning(Section* sec) static void nrn_rootnode_alloc(Section* sec) { Extnode* nde; - Node* nrn_node_construct1(); + extern Node* nrn_node_construct1(); sec->parentnode = nrn_node_construct1(); sec->parentnode->sec = sec; #if EXTRACELLULAR @@ -1780,7 +1781,7 @@ void setup_topology(void) const char* secname(Section* sec) /* name of section (for use in error messages) */ { - extern char* hoc_araystr(); +// extern char* hoc_araystr(); static char name[512]; Symbol *s; int indx; @@ -2009,12 +2010,12 @@ Node* node_ptr(Section* sec, double x, double* parea) { return nd; } -int nrn_get_mechtype(const char* mechname) { +extern "C" int nrn_get_mechtype(const char* mechname) { Symbol* s; s = hoc_lookup(mechname); assert(s); if (s->type == TEMPLATE) { - s = hoc_table_lookup(mechname, s->u.template->symtable); + s = hoc_table_lookup(mechname, s->u.ctemplate->symtable); assert(s && s->type == MECHANISM); } return s->subtype; @@ -2145,7 +2146,7 @@ static char* objectname(void) { void forall_section(void) { /*statement pointed to by pc - continuation pointed to by pc+1. template used is shortfor in code.c + continuation pointed to by pc+1. template used is shortfor in code.cpp of hoc system. */ /* if inside object then forall refers only to sections in the object */ @@ -2155,7 +2156,7 @@ void forall_section(void) { extern int hoc_returning; char buf[200]; char** s; - char** hoc_strpop(); +// char** hoc_strpop(); int istk; /* fast forall within an object asserts that the object sections @@ -2218,7 +2219,7 @@ void hoc_ifsec(void) { Inst *savepc = pc; char buf[200]; char** s; - char** hoc_strpop(); +// char** hoc_strpop(); extern int hoc_returning; s = hoc_strpop(); @@ -2280,7 +2281,7 @@ void sectionname(void) { void hoc_secname(void) { static char* buf = (char*)0; Section* sec = chk_access(); - if (!buf) { buf = (char*)emalloc(256*sizeof(char)); } + if (!buf) { buf = static_cast(emalloc(256*sizeof(char))); } if (ifarg(1) && chkarg(1, 0., 1.) == 0.) { strcpy(buf, secname(sec)); }else{ @@ -2415,7 +2416,7 @@ void assign_hoc_str(char* str, char* val, int global) Objectdata* obdsave = hoc_objectdata; /* save current dataspace */ if (!global && hoc_thisobject) { - sym = hoc_table_lookup(str, hoc_thisobject->template->symtable); + sym = hoc_table_lookup(str, hoc_thisobject->ctemplate->symtable); }else{ hoc_objectdata = hoc_top_level_data; sym = hoc_lookup(str); @@ -2436,11 +2437,11 @@ Section* nrn_section_exists(char* name, int indx, Object* cell) { Objectdata* obd; Item* itm; if (obj) { - sym = hoc_table_lookup(name, obj->template->symtable); + sym = hoc_table_lookup(name, obj->ctemplate->symtable); /* if external then back to top level */ - if (sym && sym->public == 2) { + if (sym && sym->cpublic == 2) { sym = sym->u.sym; - obj = (Object*)0; + obj = nullptr; } }else{ sym = hoc_table_lookup(name, hoc_top_level_symlist); @@ -2469,7 +2470,7 @@ void section_exists(void) { Object* obj; char *str, *cp, buf[100]; - obj = (Object*)0; + obj = nullptr; sec = (Section*)0; iarg = 1; str = gargstr(iarg++); diff --git a/src/nrnoc/cabvars.h b/src/nrnoc/cabvars.h index 0af087c8bf..9f3a2be659 100755 --- a/src/nrnoc/cabvars.h +++ b/src/nrnoc/cabvars.h @@ -1,71 +1,77 @@ /* /local/src/master/nrn/src/nrnoc/cabvars.h,v 1.5 1999/02/05 18:09:50 hines Exp */ +#ifndef NRN_CABVARS_H +#define NRN_CABVARS_H #define XMECH 0 + + static struct { /* USERPROPERTY */ char *name; short type; short index; } usrprop[] = { - "nseg", 0, 0, - "L", 1, 2, - "rallbranch", 1, 4, - "Ra", 1, 7, + "nseg", 0, 0, + "L", 1, 2, + "rallbranch", 1, 4, + "Ra", 1, 7, 0, 0, 0 }; -extern void capac_reg_(), passive0_reg_(), _passive_reg_(), +extern "C" { +void capac_reg_(), passive0_reg_(), _passive_reg_(), #if EXTRACELLULAR - extracell_reg_(), +extracell_reg_(), #endif - _stim_reg_(), - _syn_reg_(), - _expsyn_reg_(), - _exp2syn_reg_(), - _svclmp_reg_(), - _vclmp_reg_(), - _oclmp_reg_(), - _apcount_reg_(), - _netstim_reg_(), - _intfire1_reg_(), - _intfire2_reg_(), - _intfire4_reg_(), - _ppmark_reg_(), - _pattern_reg_(), + _stim_reg_(), + _syn_reg_(), + _expsyn_reg_(), + _exp2syn_reg_(), + _svclmp_reg_(), + _vclmp_reg_(), + _oclmp_reg_(), + _apcount_reg_(), + _netstim_reg_(), + _intfire1_reg_(), + _intfire2_reg_(), + _intfire4_reg_(), + _ppmark_reg_(), + _pattern_reg_(), #if XMECH - _xmech_reg_(), +_xmech_reg_(), #endif - _feature_reg_(), - _hh_reg_(); + _feature_reg_(), + _hh_reg_(); static Pfrv mechanism[] = { /* type will start at 3 */ - capac_reg_, - _passive_reg_, + capac_reg_, + _passive_reg_, #if EXTRACELLULAR - /* extracellular requires special handling and must be type 5 */ - extracell_reg_, + /* extracellular requires special handling and must be type 5 */ + extracell_reg_, #endif - passive0_reg_, /* twice as fast as model description? */ - _stim_reg_, - _syn_reg_, - _expsyn_reg_, - _exp2syn_reg_, - _svclmp_reg_, - _vclmp_reg_, - _oclmp_reg_, - _apcount_reg_, - _hh_reg_, - _feature_reg_, - _netstim_reg_, - _intfire1_reg_, - _intfire2_reg_, - _intfire4_reg_, - _ppmark_reg_, - _pattern_reg_, + passive0_reg_, /* twice as fast as model description? */ + _stim_reg_, + _syn_reg_, + _expsyn_reg_, + _exp2syn_reg_, + _svclmp_reg_, + _vclmp_reg_, + _oclmp_reg_, + _apcount_reg_, + _hh_reg_, + _feature_reg_, + _netstim_reg_, + _intfire1_reg_, + _intfire2_reg_, + _intfire4_reg_, + _ppmark_reg_, + _pattern_reg_, #if XMECH - _xmech_reg_, + _xmech_reg_, #endif - 0 + 0 }; +} // extern "C" static const char *morph_mech[] = { /* this is type 2 */ "0", "morphology", "diam", 0,0,0, @@ -74,9 +80,13 @@ static const char *morph_mech[] = { /* this is type 2 */ extern void cab_alloc(Prop*); extern void morph_alloc(Prop*); -extern Memb_func* memb_func; #if 0 first two memb_func NULL_CUR, NULL_ALLOC, NULL_STATE, NULL_INITIALIZE, (Pfri)0, 0, /*Unused*/ NULL_CUR, cab_alloc, NULL_STATE, NULL_INITIALIZE, (Pfri)0, 0, /*CABLESECTION*/ #endif + + +extern Memb_func* memb_func; + +#endif //NRN_CABVARS_H \ No newline at end of file diff --git a/src/nrnoc/capac.c b/src/nrnoc/capac.c deleted file mode 100755 index 89dcfd488e..0000000000 --- a/src/nrnoc/capac.c +++ /dev/null @@ -1,146 +0,0 @@ -#include <../../nrnconf.h> -/* /local/src/master/nrn/src/nrnoc/capac.c,v 1.6 1998/11/25 19:14:28 hines Exp */ - -#include "section.h" -#include "membdef.h" -#include "nrniv_mf.h" - -static const char *mechanism[] = { "0", "capacitance", "cm",0, "i_cap", 0,0 }; -static void cap_alloc(Prop*); -static void cap_init(NrnThread*, Memb_list*, int); - -#define nparm 2 - -void capac_reg_(void) { - int mechtype; - /* all methods deal with capacitance in special ways */ - register_mech(mechanism, cap_alloc, (Pvmi)0, (Pvmi)0, (Pvmi)0, cap_init, -1, 1); - mechtype = nrn_get_mechtype(mechanism[1]); - hoc_register_prop_size(mechtype, nparm, 0); -} - -#define cm vdata[i][0] -#define i_cap vdata[i][1] - -/* -cj is analogous to 1/dt for cvode and daspk -for fixed step second order it is 2/dt and -for pure implicit fixed step it is 1/dt -It used to be static but is now a thread data variable -*/ - -void nrn_cap_jacob(NrnThread* _nt, Memb_list* ml) { - int count = ml->nodecount; - Node **vnode = ml->nodelist; - double **vdata = ml->data; - int i; - double cfac = .001 * _nt->cj; -#if CACHEVEC - if (use_cachevec) { - int* ni = ml->nodeindices; - for (i=0; i < count; i++) { - VEC_D(ni[i]) += cfac*cm; - } - }else -#endif /* CACHEVEC */ - { - for (i=0; i < count; ++i) { - NODED(vnode[i]) += cfac*cm; - } - } -} - -static void cap_init(NrnThread* _nt, Memb_list* ml, int type ) { - int count = ml->nodecount; - double **vdata = ml->data; - int i; - for (i=0; i < count; ++i) { - i_cap = 0; - } -} - -void nrn_capacity_current(NrnThread* _nt, Memb_list* ml) { - int count = ml->nodecount; - Node **vnode = ml->nodelist; - double **vdata = ml->data; - int i; - double cfac = .001 * _nt->cj; - /* since rhs is dvm for a full or half implicit step */ - /* (nrn_update_2d() replaces dvi by dvi-dvx) */ - /* no need to distinguish secondorder */ -#if CACHEVEC - if (use_cachevec) { - int* ni = ml->nodeindices; - for (i=0; i < count; i++) { - i_cap = cfac*cm*VEC_RHS(ni[i]); - } - }else -#endif /* CACHEVEC */ - { - for (i=0; i < count; ++i) { - i_cap = cfac*cm*NODERHS(vnode[i]); - } - } -} - -#if CVODE -void nrn_mul_capacity(NrnThread* _nt, Memb_list* ml) { - int count = ml->nodecount; - Node **vnode = ml->nodelist; - double **vdata = ml->data; - int i; - double cfac = .001 * _nt->cj; -#if CACHEVEC - if (use_cachevec) { - int* ni = ml->nodeindices; - for (i=0; i < count; i++) { - VEC_RHS(ni[i]) *= cfac*cm; - } - }else -#endif /* CACHEVEC */ - { - for (i=0; i < count; ++i) { - NODERHS(vnode[i]) *= cfac*cm; - } - } -} - -void nrn_div_capacity(NrnThread* _nt, Memb_list* ml) { - int count = ml->nodecount; - Node **vnode = ml->nodelist; - double **vdata = ml->data; - int i; -#if CACHEVEC - if (use_cachevec) { - int* ni = ml->nodeindices; - for (i=0; i < count; i++) { - i_cap = VEC_RHS(ni[i]); - VEC_RHS(ni[i]) /= 1.e-3*cm; - } - }else -#endif /* CACHEVEC */ - { - for (i=0; i < count; ++i) { - i_cap = NODERHS(vnode[i]); - NODERHS(vnode[i]) /= 1.e-3*cm; - } - } - if (_nt->_nrn_fast_imem) { - double* p = _nt->_nrn_fast_imem->_nrn_sav_rhs; - for (i=0; i < count; ++i) { - p[vnode[i]->v_node_index] += i_cap; - } - } -} -#endif /*CVODE*/ - -/* the rest can be constructed automatically from the above info*/ - -static void cap_alloc(Prop* p) -{ - double *pd; - pd = nrn_prop_data_alloc(CAP, nparm, p); - pd[0] = DEF_cm; /*default capacitance/cm^2*/ - p->param = pd; - p->param_size = nparm; -} diff --git a/src/nrnoc/capac.cpp b/src/nrnoc/capac.cpp new file mode 100755 index 0000000000..482ac4248a --- /dev/null +++ b/src/nrnoc/capac.cpp @@ -0,0 +1,149 @@ +#include <../../nrnconf.h> +/* /local/src/master/nrn/src/nrnoc/capac.cpp,v 1.6 1998/11/25 19:14:28 hines Exp */ + +#include "section.h" +#include "membdef.h" +#include "nrniv_mf.h" + + +static const char *mechanism[] = {"0", "capacitance", "cm", 0, "i_cap", 0, 0}; +static void cap_alloc(Prop *); +static void cap_init(NrnThread *, Memb_list *, int); + +#define nparm 2 +extern "C" void capac_reg_(void) { + int mechtype; + /* all methods deal with capacitance in special ways */ + register_mech(mechanism, cap_alloc, (Pvmi) 0, (Pvmi) 0, (Pvmi) 0, cap_init, -1, 1); + mechtype = nrn_get_mechtype(mechanism[1]); + hoc_register_prop_size(mechtype, nparm, 0); +} + +#define cm vdata[i][0] +#define i_cap vdata[i][1] + +/* +cj is analogous to 1/dt for cvode and daspk +for fixed step second order it is 2/dt and +for pure implicit fixed step it is 1/dt +It used to be static but is now a thread data variable +*/ + +void nrn_cap_jacob(NrnThread *_nt, Memb_list *ml) { + int count = ml->nodecount; + Node **vnode = ml->nodelist; + double **vdata = ml->data; + int i; + double cfac = .001 * _nt->cj; +#if CACHEVEC + if (use_cachevec) { + int *ni = ml->nodeindices; + for (i = 0; i < count; i++) { + VEC_D(ni[i]) += cfac * cm; + } + } else +#endif /* CACHEVEC */ + { + for (i = 0; i < count; ++i) { + NODED(vnode[i]) += cfac * cm; + } + } +} + +static void cap_init(NrnThread *_nt, Memb_list *ml, int type) { + int count = ml->nodecount; + double **vdata = ml->data; + int i; + for (i = 0; i < count; ++i) { + i_cap = 0; + } +} + +void nrn_capacity_current(NrnThread *_nt, Memb_list *ml) { + int count = ml->nodecount; + Node **vnode = ml->nodelist; + double **vdata = ml->data; + int i; + double cfac = .001 * _nt->cj; + /* since rhs is dvm for a full or half implicit step */ + /* (nrn_update_2d() replaces dvi by dvi-dvx) */ + /* no need to distinguish secondorder */ +#if CACHEVEC + if (use_cachevec) { + int *ni = ml->nodeindices; + for (i = 0; i < count; i++) { + i_cap = cfac * cm * VEC_RHS(ni[i]); + } + } else +#endif /* CACHEVEC */ + { + for (i = 0; i < count; ++i) { + i_cap = cfac * cm * NODERHS(vnode[i]); + } + } +} + +#if CVODE + +void nrn_mul_capacity(NrnThread *_nt, Memb_list *ml) { + int count = ml->nodecount; + Node **vnode = ml->nodelist; + double **vdata = ml->data; + int i; + double cfac = .001 * _nt->cj; +#if CACHEVEC + if (use_cachevec) { + int *ni = ml->nodeindices; + for (i = 0; i < count; i++) { + VEC_RHS(ni[i]) *= cfac * cm; + } + } else +#endif /* CACHEVEC */ + { + for (i = 0; i < count; ++i) { + NODERHS(vnode[i]) *= cfac * cm; + } + } +} + +void nrn_div_capacity(NrnThread *_nt, Memb_list *ml) { + int count = ml->nodecount; + Node **vnode = ml->nodelist; + double **vdata = ml->data; + int i; +#if CACHEVEC + if (use_cachevec) { + int *ni = ml->nodeindices; + for (i = 0; i < count; i++) { + i_cap = VEC_RHS(ni[i]); + VEC_RHS(ni[i]) /= 1.e-3 * cm; + } + } else +#endif /* CACHEVEC */ + { + for (i = 0; i < count; ++i) { + i_cap = NODERHS(vnode[i]); + NODERHS(vnode[i]) /= 1.e-3 * cm; + } + } + if (_nt->_nrn_fast_imem) { + double *p = _nt->_nrn_fast_imem->_nrn_sav_rhs; + for (i = 0; i < count; ++i) { + p[vnode[i]->v_node_index] += i_cap; + } + } +} + +#endif /*CVODE*/ + +/* the rest can be constructed automatically from the above info*/ + +static void cap_alloc(Prop *p) { + double *pd; + pd = nrn_prop_data_alloc(CAP, nparm, p); + pd[0] = DEF_cm; /*default capacitance/cm^2*/ + p->param = pd; + p->param_size = nparm; +} + + diff --git a/src/nrnoc/clamp.c b/src/nrnoc/clamp.c deleted file mode 100644 index 8ebd0d14d6..0000000000 --- a/src/nrnoc/clamp.c +++ /dev/null @@ -1,216 +0,0 @@ -#include <../../nrnconf.h> -/* /local/src/master/nrn/src/nrnoc/clamp.c,v 1.2 1997/08/15 13:04:10 hines Exp */ - -/* modified from fstim.c */ -/* 4/9/2002 modified to conform to new treeset.c */ - -/* -fclamp(maxlevel, loc) - allocates space for maxlevel level changes all at location loc - previously existing clamp is released. - All clamp levels are initialized to clamp_resist series resistance. - and 0 duration. After the final level change the clamp is off. - -fclamp(i, duration, vc) - the maxlevel level changes concatenate. This function specifies - the magnitude and duration of the ith level. - -fclampv() - the value of the clamp potential at the global time t - -fclampi() - the clamp current at the global time t - -*/ - -#include -#include "neuron.h" -#include "section.h" -#include "nrniv_mf.h" - -static double loc; -static Node *pnd; -static Section* sec; -static double gtemp; -static int maxlevel = 0; /* size of clamp array */ -static double *duration, *vc, *tswitch; /* maxlevel of them */ -static int oldsw = 0; -static double clampval(); - -extern void clamp_prepare(); - -#define nt_t nrn_threads->_t - -void print_clamp() { - int i; - - if (maxlevel == 0) return; -#ifndef _OMPSS_ - Printf("%s fclamp(%d, %g) /* Second arg is location */\n\ -/* fclamp( #, duration(ms), magnitude(mV)) ; clamp_resist = %g */\n", secname(sec), - maxlevel, loc, clamp_resist); -#else -Printf("%s fclamp(%d, %g) /* Second arg is location */\nfclamp( #, duration(ms), magnitude(mV)) ; clamp_resist = %g */\n", secname(sec),maxlevel, loc, clamp_resist); -#endif - for (i=0; i 1) { - hoc_execerror("fsyn does not allow threads", ""); - } - /* two args are maxlevel, loc */ - /* three args are level, duration, vc */ - i = chkarg(1, 0., 10000.); - if (ifarg(3)) { - int num; - if (i >= maxlevel) { - hoc_execerror("level index out of range", (char *)0); - } - duration[i] = chkarg(2, 0., 1e21); - vc[i] = *getarg(3); - - tswitch[0] = -1e-9; - for (num = 0; num < maxlevel; num++) { - tswitch[num+1] = tswitch[num] + duration[num]; - } - oldsw = 0; - hoc_retpushx(tswitch[maxlevel-1]); - } else { - free_clamp(); - maxlevel = i; - if (maxlevel) { - duration = (double *)emalloc((unsigned)(maxlevel * sizeof(double))); - vc = (double *)emalloc((unsigned)(maxlevel * sizeof(double))); - tswitch = (double *)emalloc((unsigned)((maxlevel + 1) * sizeof(double))); - for (i = 0; iprop) { - pnd = node_ptr(sec, loc, &area); - }else{ - free_clamp(); - return; - } - if (clamp_resist <= 0) { - hoc_execerror("clamp_resist must be > 0 in megohms", (char *)0); - } -} - -void activclamp_rhs(void) { - double v; - if (!maxlevel) { - return; - } - v = clampval(); -#if EXTRACELLULAR - if (pnd->extnode) { - NODERHS(pnd) += gtemp*(v - NODEV(pnd) - pnd->extnode->v[0]); - }else{ - NODERHS(pnd) += gtemp*(v - NODEV(pnd)); - } - -#else - NODERHS(pnd) += gtemp*(v - NODEV(pnd)); -#endif -} - -void activclamp_lhs(void) { - double v; - if (!maxlevel) { - return; - } - NODED(pnd) += gtemp; -} - -static double clampval(void) { - gtemp = 1.e2/clamp_resist/NODEAREA(pnd); - for (;;) { -#if CVODE - at_time(nrn_threads, tswitch[oldsw]); -#endif - if (nt_t < tswitch[oldsw]) { - if (oldsw == 0) { - break; - } -#if CVODE -/* for cvode the other was inefficient since t is non-monotonic */ - --oldsw; -#else - oldsw = 0; -#endif - }else{ - if (nt_t < tswitch[oldsw + 1]) { - break; - } else { - if (++oldsw == maxlevel) { - --oldsw; - gtemp = 0.; - break; - } - } - } - } - return vc[oldsw]; -} diff --git a/src/nrnoc/clamp.cpp b/src/nrnoc/clamp.cpp new file mode 100644 index 0000000000..ae747e8e6f --- /dev/null +++ b/src/nrnoc/clamp.cpp @@ -0,0 +1,219 @@ +#include <../../nrnconf.h> +/* /local/src/master/nrn/src/nrnoc/clamp.cpp,v 1.2 1997/08/15 13:04:10 hines Exp */ + +/* modified from fstim.cpp */ +/* 4/9/2002 modified to conform to new treeset.cpp */ + +/* +fclamp(maxlevel, loc) + allocates space for maxlevel level changes all at location loc + previously existing clamp is released. + All clamp levels are initialized to clamp_resist series resistance. + and 0 duration. After the final level change the clamp is off. + +fclamp(i, duration, vc) + the maxlevel level changes concatenate. This function specifies + the magnitude and duration of the ith level. + +fclampv() + the value of the clamp potential at the global time t + +fclampi() + the clamp current at the global time t + +*/ + +#include +#include "neuron.h" +#include "section.h" +#include "nrniv_mf.h" + + +static double loc; +static Node *pnd; +static Section *sec; +static double gtemp; +static int maxlevel = 0; /* size of clamp array */ +static double *duration, *vc, *tswitch; /* maxlevel of them */ +static int oldsw = 0; + +static double clampval(); + +extern void clamp_prepare(); + +#define nt_t nrn_threads->_t + +void print_clamp() { + int i; + + if (maxlevel == 0) return; +#ifndef _OMPSS_ + Printf("%s fclamp(%d, %g) /* Second arg is location */\n\ +/* fclamp( #, duration(ms), magnitude(mV)) ; clamp_resist = %g */\n", secname(sec), + maxlevel, loc, clamp_resist); +#else + Printf("%s fclamp(%d, %g) /* Second arg is location */\nfclamp( #, duration(ms), magnitude(mV)) ; clamp_resist = %g */\n", secname(sec),maxlevel, loc, clamp_resist); +#endif + for (i = 0; i < maxlevel; i++) { + Printf(" fclamp(%2d,%13g,%14g)\n", i, duration[i], vc[i]); + } +} + +void fclampv(void) { + + if (maxlevel) { + hoc_retpushx(clampval()); + } else { + hoc_retpushx(0.); + } +} + +void fclampi(void) { + double v; + + if (maxlevel) { + v = clampval(); + if (gtemp) { + hoc_retpushx(-(NODEV(pnd) - v) / clamp_resist); + } else { + hoc_retpushx(0.); + } + } else { + hoc_retpushx(0.); + } +} + +static void free_clamp(void); + +void fclamp(void) { + int i; + + if (nrn_nthread > 1) { + hoc_execerror("fsyn does not allow threads", ""); + } + /* two args are maxlevel, loc */ + /* three args are level, duration, vc */ + i = chkarg(1, 0., 10000.); + if (ifarg(3)) { + int num; + if (i >= maxlevel) { + hoc_execerror("level index out of range", (char *) 0); + } + duration[i] = chkarg(2, 0., 1e21); + vc[i] = *getarg(3); + + tswitch[0] = -1e-9; + for (num = 0; num < maxlevel; num++) { + tswitch[num + 1] = tswitch[num] + duration[num]; + } + oldsw = 0; + hoc_retpushx(tswitch[maxlevel - 1]); + } else { + free_clamp(); + maxlevel = i; + if (maxlevel) { + duration = (double *) emalloc((unsigned) (maxlevel * sizeof(double))); + vc = (double *) emalloc((unsigned) (maxlevel * sizeof(double))); + tswitch = (double *) emalloc((unsigned) ((maxlevel + 1) * sizeof(double))); + for (i = 0; i < maxlevel; i++) { + duration[i] = 0.; + vc[i] = 0.; + tswitch[i] = -1e-9; + } + tswitch[maxlevel] = -1e-9; + loc = chkarg(2, 0., 1.); + sec = chk_access(); + section_ref(sec); + clamp_prepare(); + } + } + hoc_retpushx(0.); +} + +static void free_clamp(void) { + if (maxlevel) { + free((char *) duration); + free((char *) vc); + free((char *) tswitch); + maxlevel = 0; + section_unref(sec); + sec = 0; + } +} + +void clamp_prepare(void) /*fill in the section info*/ +{ +// Node *node_ptr(); + double area; + + if (!maxlevel) { + return; + } + if (sec->prop) { + pnd = node_ptr(sec, loc, &area); + } else { + free_clamp(); + return; + } + if (clamp_resist <= 0) { + hoc_execerror("clamp_resist must be > 0 in megohms", (char *) 0); + } +} + +void activclamp_rhs(void) { + double v; + if (!maxlevel) { + return; + } + v = clampval(); +#if EXTRACELLULAR + if (pnd->extnode) { + NODERHS(pnd) += gtemp * (v - NODEV(pnd) - pnd->extnode->v[0]); + } else { + NODERHS(pnd) += gtemp * (v - NODEV(pnd)); + } + +#else + NODERHS(pnd) += gtemp*(v - NODEV(pnd)); +#endif +} + +void activclamp_lhs(void) { + double v; + if (!maxlevel) { + return; + } + NODED(pnd) += gtemp; +} + +static double clampval(void) { + gtemp = 1.e2 / clamp_resist / NODEAREA(pnd); + for (;;) { +#if CVODE + at_time(nrn_threads, tswitch[oldsw]); +#endif + if (nt_t < tswitch[oldsw]) { + if (oldsw == 0) { + break; + } +#if CVODE +/* for cvode the other was inefficient since t is non-monotonic */ + --oldsw; +#else + oldsw = 0; +#endif + } else { + if (nt_t < tswitch[oldsw + 1]) { + break; + } else { + if (++oldsw == maxlevel) { + --oldsw; + gtemp = 0.; + break; + } + } + } + } + return vc[oldsw]; +} + diff --git a/src/nrnoc/hocusr.c b/src/nrnoc/code.cpp similarity index 85% rename from src/nrnoc/hocusr.c rename to src/nrnoc/code.cpp index 06b6a6b7c4..5774deeedc 100755 --- a/src/nrnoc/hocusr.c +++ b/src/nrnoc/code.cpp @@ -3,4 +3,4 @@ * Automake doesn't deal well with sources that live in other directories, so * this is a quick and dirty workaround. */ -#include "../oc/hocusr.c" +#include "../oc/code.cpp" diff --git a/src/nrnoc/cprop.c b/src/nrnoc/cprop.c deleted file mode 100644 index 48713ae8fe..0000000000 --- a/src/nrnoc/cprop.c +++ /dev/null @@ -1,41 +0,0 @@ -#include <../../nrnconf.h> - -/* -allocate and free property data and Datum arrays for nrnoc -the nrniv/cxprop.cpp version allows for the possibility of -greater cache efficiency -*/ - -#include -#include -#include - -void nrn_mk_prop_pools(int n) {} -void nrn_cache_prop_realloc() {} -int nrn_is_valid_section_ptr(void* v) { return 0; } - -double* nrn_prop_data_alloc(int type, int count, Prop* p) { - double* pd = (double*)hoc_Ecalloc(count, sizeof(double)); hoc_malchk(); - return pd; -} -Datum* nrn_prop_datum_alloc(int type, int count, Prop* p) { - Datum* ppd = (Datum*)hoc_Ecalloc(count, sizeof(Datum)); hoc_malchk(); - return ppd; -} -void nrn_prop_data_free(int type, double* pd) { - if (pd) { - free(pd); - } -} -void nrn_prop_datum_free(int type, Datum* ppd) { - if (ppd) { - free(ppd); - } -} -Section* nrn_section_alloc() { - return (Section *)emalloc(sizeof(Section)); -} -void nrn_section_free(Section* s) { - free(s); -} - diff --git a/src/nrnoc/cprop.cpp b/src/nrnoc/cprop.cpp new file mode 100644 index 0000000000..ef415cab6f --- /dev/null +++ b/src/nrnoc/cprop.cpp @@ -0,0 +1,52 @@ +#include <../../nrnconf.h> + +/* +allocate and free property data and Datum arrays for nrnoc +the nrniv/cxprop.cpp version allows for the possibility of +greater cache efficiency +*/ + +#include +#include +#include + + +void nrn_mk_prop_pools(int n) {} + +void nrn_cache_prop_realloc() {} + +int nrn_is_valid_section_ptr(void *v) { return 0; } + +extern "C" double *nrn_prop_data_alloc(int type, int count, Prop *p) { + double *pd = (double *) hoc_Ecalloc(count, sizeof(double)); + hoc_malchk(); + return pd; +} + +extern "C" Datum *nrn_prop_datum_alloc(int type, int count, Prop *p) { + Datum *ppd = (Datum *) hoc_Ecalloc(count, sizeof(Datum)); + hoc_malchk(); + return ppd; +} + +extern "C" void nrn_prop_data_free(int type, double *pd) { + if (pd) { + free(pd); + } +} + +extern "C" void nrn_prop_datum_free(int type, Datum *ppd) { + if (ppd) { + free(ppd); + } +} + +Section *nrn_section_alloc() { + return (Section *) emalloc(sizeof(Section)); +} + +void nrn_section_free(Section *s) { + free(s); +} + + diff --git a/src/nrnoc/eion.cpp b/src/nrnoc/eion.cpp new file mode 100644 index 0000000000..000150f911 --- /dev/null +++ b/src/nrnoc/eion.cpp @@ -0,0 +1,638 @@ +#include <../../nrnconf.h> +/* /local/src/master/nrn/src/nrnoc/eion.cpp,v 1.10 1998/02/26 16:42:50 hines Exp */ + +#include +#include "section.h" +#include "neuron.h" +#include "membfunc.h" +#include "parse.h" +#include "membdef.h" +#include "nrniv_mf.h" + + +#undef hoc_retpushx + +extern double chkarg(int, double low, double high); + +extern Section *nrn_noerr_access(); + +extern void hoc_register_prop_size(int, int, int); + +#define nparm 5 +static const char *mechanism[] = { /*just a template*/ + "0", + "na_ion", + "ena", "nao", "nai", 0, + "ina", "dina_dv_", 0, + 0 +}; +static DoubScal scdoub[] = { /* just a template*/ + "ci0_na_ion", 0, + "co0_na_ion", 0, + 0, 0 +}; + +static void ion_alloc(Prop *); + +static void ion_cur(NrnThread *, Memb_list *, int); + +static void ion_init(NrnThread *, Memb_list *, int); + +extern "C" double nrn_nernst(double, double, double), nrn_ghk(double, double, double, double); + +static int na_ion, k_ion, ca_ion; /* will get type for these special ions */ + +int nrn_is_ion(int type) { + return (memb_func[type].alloc == ion_alloc); +} + +static int ion_global_map_size; +static double **ion_global_map; +#define global_conci(type) ion_global_map[type][0] +#define global_conco(type) ion_global_map[type][1] +#define global_charge(type) ion_global_map[type][2] + +double nrn_ion_charge(Symbol *sym) { + return global_charge(sym->subtype); +} + +void ion_register(void) { + /* hoc level registration of ion name. Return -1 if name already + in use and not an ion; and the mechanism subtype otherwise. + */ + char *name; + char *buf; + Symbol *s; + Symlist *sav; + int fail; + fail = 0; + sav = hoc_symlist; + hoc_symlist = hoc_top_level_symlist; + name = gargstr(1); + buf = static_cast(emalloc(strlen(name) + 10)); + sprintf(buf, "%s_ion", name); + s = hoc_lookup(buf); + if (s && s->type == MECHANISM && memb_func[s->subtype].alloc == ion_alloc) { + hoc_symlist = sav; + free(buf); + hoc_retpushx((double) s->subtype); + return; + } + if (s) { fail = 1; } + sprintf(buf, "e%s", name); + if (hoc_lookup(buf)) { fail = 1; } + sprintf(buf, "%si", name); + if (hoc_lookup(buf)) { fail = 1; } + sprintf(buf, "%so", name); + if (hoc_lookup(buf)) { fail = 1; } + sprintf(buf, "i%s", name); + if (hoc_lookup(buf)) { fail = 1; } + sprintf(buf, "di%s_dv_", name); + if (hoc_lookup(buf)) { fail = 1; } + if (fail) { + hoc_symlist = sav; + free(buf); + hoc_retpushx(-1.); + return; + } + hoc_symlist = hoc_built_in_symlist; + ion_reg(name, *getarg(2)); + hoc_symlist = sav; + sprintf(buf, "%s_ion", name); + s = hoc_lookup(buf); + hoc_retpushx((double) s->subtype); + free(buf); +} + +void ion_charge(void) { + Symbol *s; + s = hoc_lookup(gargstr(1)); + if (!s || s->type != MECHANISM || memb_func[s->subtype].alloc != ion_alloc) { + hoc_execerror(gargstr(1), "is not an ion mechanism"); + } + hoc_retpushx(global_charge(s->subtype)); +} + +extern "C" { +void register_mech(const char **, Pvmp, Pvmi, Pvmi, Pvmi, Pvmi, int, int); + + +void ion_reg(const char *name, double valence) { + int i, mechtype; + Symbol *s; + char *buf[7]; + double val; +#define VAL_SENTINAL -10000. + + { + int n = 2 * strlen(name) + 10; /*name used twice in initialization name */ + for (i = 0; i < 7; ++i) { + buf[i] = static_cast(emalloc(n)); + } + } + Sprintf(buf[0], "%s_ion", name); + Sprintf(buf[1], "e%s", name); + Sprintf(buf[2], "%si", name); + Sprintf(buf[3], "%so", name); + Sprintf(buf[5], "i%s", name); + Sprintf(buf[6], "di%s_dv_", name); + for (i = 0; i < 7; i++) { + mechanism[i + 1] = buf[i]; + } + mechanism[5] = (char *) 0; /* buf[4] not used above */ + s = hoc_lookup(buf[0]); + if (!s || s->type != MECHANISM + || memb_func[s->subtype].alloc != ion_alloc) { + register_mech(mechanism, ion_alloc, ion_cur, nullptr, nullptr, ion_init, -1, 1); + hoc_symbol_limits(hoc_lookup(buf[2]), 1e-12, 1e9); + hoc_symbol_limits(hoc_lookup(buf[3]), 1e-12, 1e9); + hoc_symbol_units(hoc_lookup(buf[1]), "mV"); + hoc_symbol_units(hoc_lookup(buf[2]), "mM"); + hoc_symbol_units(hoc_lookup(buf[3]), "mM"); + hoc_symbol_units(hoc_lookup(buf[5]), "mA/cm2"); + hoc_symbol_units(hoc_lookup(buf[6]), "S/cm2"); + s = hoc_lookup(buf[0]); + mechtype = nrn_get_mechtype(mechanism[1]); + hoc_register_prop_size(mechtype, nparm, 1); + hoc_register_dparam_semantics(mechtype, 0, "iontype"); + nrn_writes_conc(mechtype, 1); + if (ion_global_map_size <= s->subtype) { + ion_global_map_size = s->subtype + 1; + ion_global_map = (double **) erealloc(ion_global_map, + sizeof(double *) * ion_global_map_size); + } + ion_global_map[s->subtype] = (double *) emalloc(3 * sizeof(double)); + Sprintf(buf[0], "%si0_%s", name, s->name); + scdoub[0].name = buf[0]; + scdoub[0].pdoub = ion_global_map[s->subtype]; + Sprintf(buf[1], "%so0_%s", name, s->name); + scdoub[1].name = buf[1]; + scdoub[1].pdoub = ion_global_map[s->subtype] + 1; + hoc_register_var(scdoub, (DoubVec *) 0, (VoidFunc *) 0); + hoc_symbol_units(hoc_lookup(scdoub[0].name), "mM"); + hoc_symbol_units(hoc_lookup(scdoub[1].name), "mM"); + if (strcmp("na", name) == 0) { + na_ion = s->subtype; + global_conci(s->subtype) = DEF_nai; + global_conco(s->subtype) = DEF_nao; + global_charge(s->subtype) = 1.; + } else if (strcmp("k", name) == 0) { + k_ion = s->subtype; + global_conci(s->subtype) = DEF_ki; + global_conco(s->subtype) = DEF_ko; + global_charge(s->subtype) = 1.; + } else if (strcmp("ca", name) == 0) { + ca_ion = s->subtype; + global_conci(s->subtype) = DEF_cai; + global_conco(s->subtype) = DEF_cao; + global_charge(s->subtype) = 2.; + } else { + global_conci(s->subtype) = DEF_ioni; + global_conco(s->subtype) = DEF_iono; + global_charge(s->subtype) = VAL_SENTINAL; + } + for (i = 0; i < 3; ++i) { /* used to be nrnocCONST */ + s->u.ppsym[i]->subtype = _AMBIGUOUS; + } + } + val = global_charge(s->subtype); + if (valence != VAL_SENTINAL && val != VAL_SENTINAL && valence != val) { + fprintf(stderr, "%s ion charge defined differently in\n\ +two USEION statements (%g and %g)\n", + s->name, valence, global_charge(s->subtype)); + nrn_exit(1); + } else if (valence == VAL_SENTINAL && val == VAL_SENTINAL) { + /* Not defined now but could be defined by + a subsequent ion_reg from another model. + The list of ion mechanisms will be checked + after all mod files have been dealt with to verify + that they all have a defined valence. + */ +#if 0 +#endif + } else if (valence != VAL_SENTINAL) { + global_charge(s->subtype) = valence; + } + for (i = 0; i < 7; ++i) { + free(buf[i]); + } +} +} // extern "C" + +void nrn_verify_ion_charge_defined() { + int i; + for (i = 3; i < n_memb_func; ++i) + if (nrn_is_ion(i)) { + if (global_charge(i) == VAL_SENTINAL) { + Symbol *s = memb_func[i].sym; + Fprintf(stderr, "%s USEION CHARGE (or VALENCE) must be defined in\n\ +at least one model using this ion\n", s->name); + nrn_exit(1); + } + } +} + +#if defined(LegacyFR) && LegacyFR == 1 +#define FARADAY 96485.309 +#define gasconstant 8.3134 +#else +#define FARADAY 96485.33289 +#define gasconstant 8.3144598 +#endif + +#define ktf (1000.*gasconstant*(celsius + 273.15)/FARADAY) + +double nrn_nernst(double ci, double co, double z) { +/*printf("nrn_nernst %g %g %g\n", ci, co, z);*/ + if (z == 0) { + return 0.; + } + if (ci <= 0.) { + return 1e6; + } else if (co <= 0.) { + return -1e6; + } else { + return ktf / z * log(co / ci); + } +} + +extern "C" void nrn_wrote_conc(Symbol *sym, double *pe, int it) { + if (it & 040) { + pe[0] = nrn_nernst(pe[1], pe[2], nrn_ion_charge(sym)); + } +} + +void nernst(void) { + double val = 0.0; + + if (hoc_is_str_arg(1)) { + Symbol *s = hoc_lookup(gargstr(1)); + if (s && ion_global_map[s->u.rng.type]) { + Section *sec = chk_access(); +// double* nrn_rangepointer(); + Symbol *ion = memb_func[s->u.rng.type].sym; + double z = global_charge(s->u.rng.type); + double *ci, *co, *e, x; + if (ifarg(2)) { + x = chkarg(2, 0., 1.); + } else { + x = .5; + } + ci = nrn_rangepointer(sec, ion->u.ppsym[1], x); + co = nrn_rangepointer(sec, ion->u.ppsym[2], x); + e = nrn_rangepointer(sec, ion->u.ppsym[0], x); + switch (s->u.rng.index) { + case 0: + val = nrn_nernst(*ci, *co, z); + hoc_retpushx(val); + return; + case 1: + val = *co * exp(-z / ktf * *e); + hoc_retpushx(val); + return; + case 2: + val = *ci * exp(z / ktf * *e); + hoc_retpushx(val); + return; + } + } + hoc_execerror(gargstr(1), " not a reversal potential or concentration"); + } else { + val = nrn_nernst(*getarg(1), *getarg(2), *getarg(3)); +/*printf("nernst=%g\n", val);*/ + } + hoc_retpushx(val); + return; +} + +static double efun(double x) { + if (fabs(x) < 1e-4) { + return 1. - x / 2.; + } else { + return x / (exp(x) - 1); + } +} + +extern "C" double nrn_ghk(double v, double ci, double co, double z) { + double eco, eci, temp; + temp = z * v / ktf; + eco = co * efun(temp); + eci = ci * efun(-temp); + return (.001) * z * FARADAY * (eci - eco); +} + +void ghk(void) { + double val = nrn_ghk(*getarg(1), *getarg(2), *getarg(3), *getarg(4)); + hoc_retpushx(val); +} + +#if VECTORIZE +#define erev pd[i][0] /* From Eion */ +#define conci pd[i][1] +#define conco pd[i][2] +#define cur pd[i][3] +#define dcurdv pd[i][4] + +/* + handle erev, conci, conc0 "in the right way" according to ion_style + default. See nrn/lib/help/nrnoc.help. +ion_style("name_ion", [c_style, e_style, einit, eadvance, cinit]) + + ica is assigned + eca is parameter but if conc exists then eca is assigned + if conc is nrnocCONST then eca calculated on finitialize + if conc is STATE then eca calculated on fadvance and conc finitialize + with global nai0, nao0 + + nernst(ci, co, charge) and ghk(v, ci, co, charge) available to hoc + and models. +*/ + +#define iontype ppd[i][0].i /* how _AMBIGUOUS is to be handled */ +/*the bitmap is +03 concentration unused, nrnocCONST, DEP, STATE +04 initialize concentrations +030 reversal potential unused, nrnocCONST, DEP, STATE +040 initialize reversal potential +0100 calc reversal during fadvance +0200 ci being written by a model +0400 co being written by a model +*/ + +#define charge global_charge(type) +#define conci0 global_conci(type) +#define conco0 global_conco(type) + +extern "C" double nrn_nernst_coef(int type) { + /* for computing jacobian element dconc'/dconc */ + return ktf / charge; +} + +/* +It is generally an error for two models to WRITE the same concentration +*/ +extern "C" void nrn_check_conc_write(Prop *p_ok, Prop *pion, int i) { + static long *chk_conc_, *ion_bit_, size_; + Prop *p; + int flag, j, k; + if (i == 1) { + flag = 0200; + } else { + flag = 0400; + } + /* an embarassing hack */ + /* up to 32 possible ions */ + /* continuously compute a bitmap that allows determination + of which models WRITE which ion concentrations */ + if (n_memb_func > size_) { + if (!chk_conc_) { + chk_conc_ = (long *) ecalloc(2 * n_memb_func, sizeof(long)); + ion_bit_ = (long *) ecalloc(n_memb_func, sizeof(long)); + } else { + chk_conc_ = (long *) erealloc(chk_conc_, 2 * n_memb_func * sizeof(long)); + ion_bit_ = (long *) erealloc(ion_bit_, n_memb_func * sizeof(long)); + for (j = size_; j < n_memb_func; ++j) { + chk_conc_[2 * j] = 0; + chk_conc_[2 * j + 1] = 0; + ion_bit_[j] = 0; + } + } + size_ = n_memb_func; + } + for (k = 0, j = 0; j < n_memb_func; ++j) { + if (nrn_is_ion(j)) { + ion_bit_[j] = (1 << k); + ++k; + assert(k < sizeof(long) * 8); + } + } + + chk_conc_[2 * p_ok->type + i] |= ion_bit_[pion->type]; + if (pion->dparam[0].i & flag) { + /* now comes the hard part. Is the possibility in fact actual.*/ + for (p = pion->next; p; p = p->next) { + if (p == p_ok) { + continue; + } + if (chk_conc_[2 * p->type + i] & ion_bit_[pion->type]) { + char buf[300]; + sprintf(buf, "%.*s%c is being written at the same location by %s and %s", + (int) strlen(memb_func[pion->type].sym->name) - 4, + memb_func[pion->type].sym->name, + ((i == 1) ? 'i' : 'o'), + memb_func[p_ok->type].sym->name, + memb_func[p->type].sym->name); + hoc_warning(buf, (char *) 0); + } + } + } + pion->dparam[0].i |= flag; +} + +void ion_style(void) { + Symbol *s; + int istyle, i, oldstyle; + Section *sec; + Prop *p; //, *nrn_mechanism(); + + s = hoc_lookup(gargstr(1)); + if (!s || s->type != MECHANISM || !nrn_is_ion(s->subtype)) { + hoc_execerror(gargstr(1), " is not an ion"); + } + + sec = chk_access(); + p = nrn_mechanism(s->subtype, sec->pnode[0]); + oldstyle = -1; + if (p) { + oldstyle = p->dparam[0].i; + } + + if (ifarg(2)) { + istyle = (int) chkarg(2, 0., 3.); /* c_style */ + istyle += 010 * (int) chkarg(3, 0., 3.); /* e_style */ + istyle += 040 * (int) chkarg(4, 0., 1.); /* einit */ + istyle += 0100 * (int) chkarg(5, 0., 1.); /* eadvance */ + istyle += 04 * (int) chkarg(6, 0., 1.); /* cinit*/ + +#if 0 /* global effect */ + { + int count; + Datum** ppd; + v_setup_vectors(); + count = memb_list[s->subtype].nodecount; + ppd = memb_list[s->subtype].pdata; + for (i=0; i < count; ++i) { + iontype = (iontype&(0200+0400)) + istyle; + } + } +#else /* currently accessed section */ + { + for (i = 0; i < sec->nnode; ++i) { + p = nrn_mechanism(s->subtype, sec->pnode[i]); + if (p) { + p->dparam[0].i &= (0200 + 0400); + p->dparam[0].i += istyle; + } + } + } +#endif + } + hoc_retpushx((double) oldstyle); +} + +int nrn_vartype(Symbol *sym) { + int i; + i = sym->subtype; + if (i == _AMBIGUOUS) { + Section *sec; + Prop *p; //, *nrn_mechanism(); + sec = nrn_noerr_access(); + if (!sec) { + return nrnocCONST; + } + p = nrn_mechanism(sym->u.rng.type, sec->pnode[0]); + if (p) { + int it = p->dparam[0].i; + if (sym->u.rng.index == 0) { /* erev */ + i = (it & 030) >> 3; /* unused, nrnocCONST, DEP, or STATE */ + } else { /* concentration */ + i = (it & 03); + } + } + } + return i; +} + +/* the ion mechanism it flag defines how _AMBIGUOUS is to be interpreted */ +extern "C" void nrn_promote(Prop *p, int conc, int rev) { + int oldconc, oldrev; + int *it = &p->dparam[0].i; + oldconc = (*it & 03); + oldrev = (*it & 030) >> 3; + /* precedence */ + if (oldconc < conc) { + oldconc = conc; + } + if (oldrev < rev) { + oldrev = rev; + } + /* promote type */ + if (oldconc > 0 && oldrev < 2) { + oldrev = 2; + } + *it &= ~0177; /* clear the bitmap */ + *it += oldconc + 010 * oldrev; + if (oldconc == 3) { /* if state then cinit */ + *it += 4; + if (oldrev == 2) { /* if not state (WRITE) then eadvance */ + *it += 0100; + } + } + if (oldconc > 0 && oldrev == 2) { /*einit*/ + *it += 040; + } +} + +/* Must be called prior to any channels which update the currents */ +static void ion_cur(NrnThread *nt, Memb_list *ml, int type) { + int count = ml->nodecount; + Node **vnode = ml->nodelist; + double **pd = ml->data; + Datum **ppd = ml->pdata; + int i; +/*printf("ion_cur %s\n", memb_func[type].sym->name);*/ +#if _CRAY +#pragma _CRI ivdep +#endif + for (i = 0; i < count; ++i) { + dcurdv = 0.; + cur = 0.; + if (iontype & 0100) { + erev = nrn_nernst(conci, conco, charge); + } + }; +} + +/* Must be called prior to other models which possibly also initialize + concentrations based on their own states +*/ +static void ion_init(NrnThread *nt, Memb_list *ml, int type) { + int count = ml->nodecount; + Node **vnode = ml->nodelist; + double **pd = ml->data; + Datum **ppd = ml->pdata; + int i; +/*printf("ion_init %s\n", memb_func[type].sym->name);*/ +#if _CRAY +#pragma _CRI ivdep +#endif + for (i = 0; i < count; ++i) { + if (iontype & 04) { + conci = conci0; + conco = conco0; + } + } +#if _CRAY +#pragma _CRI ivdep +#endif + for (i = 0; i < count; ++i) { + if (iontype & 040) { + erev = nrn_nernst(conci, conco, charge); + } + } +} + +static void ion_alloc(Prop *p) { + double *pd[1]; + int i = 0; + + pd[0] = nrn_prop_data_alloc(p->type, nparm, p); + p->param_size = nparm; + + cur = 0.; + dcurdv = 0.; + if (p->type == na_ion) { + erev = DEF_ena; + conci = DEF_nai; + conco = DEF_nao; + } else if (p->type == k_ion) { + erev = DEF_ek; + conci = DEF_ki; + conco = DEF_ko; + } else if (p->type == ca_ion) { + erev = DEF_eca; + conci = DEF_cai; + conco = DEF_cao; + } else { + erev = DEF_eion; + conci = DEF_ioni; + conco = DEF_iono; + } + p->param = pd[0]; + + p->dparam = nrn_prop_datum_alloc(p->type, 1, p); + p->dparam->i = 0; +} + +void second_order_cur(NrnThread *nt) { + extern int secondorder; + NrnThreadMembList *tml; + Memb_list *ml; + int j, i, i2; +#define c 3 +#define dc 4 + if (secondorder == 2) { + for (tml = nt->tml; tml; tml = tml->next) + if (memb_func[tml->index].alloc == ion_alloc) { + ml = tml->ml; + i2 = ml->nodecount; + for (i = 0; i < i2; ++i) { + ml->data[i][c] += ml->data[i][dc] + * (NODERHS(ml->nodelist[i])); + } + } + } +} + +#endif + diff --git a/src/nrnoc/extcelln.c b/src/nrnoc/extcelln.cpp similarity index 95% rename from src/nrnoc/extcelln.c rename to src/nrnoc/extcelln.cpp index 528ba71ef8..acd4458b6f 100755 --- a/src/nrnoc/extcelln.c +++ b/src/nrnoc/extcelln.cpp @@ -1,5 +1,5 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/nrnoc/extcell.c,v 1.4 1996/05/21 17:09:19 hines Exp */ +/* /local/src/master/nrn/src/nrnoc/extcell.cpp,v 1.4 1996/05/21 17:09:19 hines Exp */ #include #include @@ -7,12 +7,13 @@ #include "nrniv_mf.h" #include "hocassrt.h" + extern int cvode_active_; extern int nrn_use_daspk_; #if EXTRACELLULAR -/* the N index is a keyword in the following. See init.c for implementation.*/ +/* the N index is a keyword in the following. See init.cpp for implementation.*/ static const char *mechanism[] = { "0", "extracellular", @@ -31,12 +32,12 @@ static HocParmLimits limits[] = { }; static HocParmUnits units[] = { - "xraxial", "MOhm/cm", - "xg", "S/cm2", - "xc", "uF/cm2", - "e_extracellular", "mV", - "vext", "mV", - "i_membrane", "mA/cm2", + "xraxial", "MOhm/cm", + "xg", "S/cm2", + "xc", "uF/cm2", + "e_extracellular", "mV", + "vext", "mV", + "i_membrane", "mA/cm2", 0,0 }; @@ -56,16 +57,18 @@ static int _ode_count(int type) { return 0; } -void extracell_reg_(void) { - int i; - register_mech(mechanism, extcell_alloc, (Pvmi)0, (Pvmi)0, (Pvmi)0, - extcell_init, -1, 1); - i = nrn_get_mechtype(mechanism[1]); - hoc_register_cvode(i, _ode_count, 0,0,0); - hoc_register_limits(i, limits); - hoc_register_units(i, units); + +extern "C" void extracell_reg_(void) { + int i; + register_mech(mechanism, extcell_alloc, (Pvmi) 0, (Pvmi) 0, (Pvmi) 0, + extcell_init, -1, 1); + i = nrn_get_mechtype(mechanism[1]); + hoc_register_cvode(i, _ode_count, 0, 0, 0); + hoc_register_limits(i, limits); + hoc_register_units(i, units); } + /* solving is done with sparse13 */ /* interface between hoc and extcell */ @@ -79,7 +82,7 @@ void extracell_reg_(void) { #define sav_rhs pd[3 + 3*(nlayer)] #endif -/* based on update() in fadvance.c */ +/* based on update() in fadvance.cpp */ /* update has already been called so modify nd->v based on dvi we only need to update extracellular nodes and base the corresponding nd->v on dvm (dvm = dvi - dvx) @@ -248,7 +251,7 @@ void extcell_2d_alloc(Section* sec) } } -/* from treesetup.c */ +/* from treesetup.cpp */ void nrn_rhs_ext(NrnThread* _nt) { int i, j, cnt; @@ -395,7 +398,7 @@ void nrn_setup_ext(NrnThread* _nt) /*printnode("end setup_lhs");*/ } -/* based on treeset.c */ +/* based on treeset.cpp */ void ext_con_coef(void) /* setup a and b */ { int j,k; @@ -658,4 +661,6 @@ ndesave[i].rhs[j] -= ndesave[i].v[k]*ndesave[i].m[j][(nlayer)+k-j]; #endif #endif + #endif /*EXTRACELLULAR*/ + diff --git a/src/nrnoc/fadvance.c b/src/nrnoc/fadvance.cpp similarity index 68% rename from src/nrnoc/fadvance.c rename to src/nrnoc/fadvance.cpp index 8781dad8cd..837ade333e 100644 --- a/src/nrnoc/fadvance.c +++ b/src/nrnoc/fadvance.cpp @@ -13,6 +13,7 @@ #include "nrncvode.h" #include "spmatrix.h" + /* after an fadvance from t-dt to t, v is defined at t states that depend on v are defined at t+dt/2 @@ -40,13 +41,13 @@ ionic concentrations just like breakpoint and solve blocks. When the argument is present, v for all segments are set to that value. */ - + #if !defined(NRNMPI) || NRNMPI == 0 extern double nrnmpi_wtime(); #endif extern double* nrn_mech_wtime_; extern double t, dt; -extern double chkarg(); +extern double chkarg(int, double low, double high); extern void nrn_fixed_step(); extern void nrn_fixed_step_group(int); static void* nrn_fixed_step_thread(NrnThread*); @@ -80,7 +81,7 @@ static void update(NrnThread*); such as in netcvode.cpp in fornetcon_prepare */ extern short* nrn_is_artificial_; -extern Template** nrn_pnt_template_; +extern cTemplate** nrn_pnt_template_; #endif #if NRN_DAQ extern void nrn_daq_scanstart(); @@ -155,7 +156,7 @@ void (*nrnthread_vi_compute_)(NrnThread* nt); #endif #if VECTORIZE -extern int v_structure_change; +extern "C" int v_structure_change; #endif #if CVODE @@ -202,6 +203,48 @@ void fadvance(void) */ static void batch_out(), batch_open(), batch_close(); + +static FILE* batch_file; +static int batch_size; +static int batch_n; +static double** batch_var; + +static void batch_open(char* name, double tstop, double tstep, char* comment){ + if (batch_file) { + batch_close(); + } + if (!name) { + return; + } + batch_file = fopen(name, "w"); + if (!batch_file) { + hoc_execerror("Couldn't open batch file", name); + } + fprintf(batch_file, "%s\nbatch_run from t = %g to %g in steps of %g with dt = %g\n", comment, t, tstop, tstep, dt); + #if 0 + fprintf(batch_file, "variable names --\n"); + if (!batch_var) { + batch_var = hoc_newlist(); + } + count = 0; + ITERATE(q, batch_varname) { + fprintf(batch_file, "%s\n", STR(q)); + ++count; + } + if (count != batch_n) { + if (batch_var) { + free(batch_var); + } + batch_n = count; + batch_var = (double**)ecalloc(batch_n, sizeof(double*)); + } + count = 0; + ITERATE(q, batch_varname) { + batch_var[count++] = hoc_val_pointer(STR(q)); + } + #endif +} + void batch_run(void) /* avoid interpreter overhead */ { double tstop, tstep, tnext; @@ -277,7 +320,7 @@ static void* daspk_init_step_thread(NrnThread* nt) { if (_upd) { update(nt); } - return (void*)0; + return nullptr; } void nrn_daspk_init_step(double tt, double dteps, int upd){ @@ -323,7 +366,7 @@ void nrn_fixed_step() { } nrn_multithread_job(nrn_fixed_step_lastpart); } - //} +// } }else{ nrn_multithread_job(nrn_fixed_step_thread); /* if there is no nrnthread_v_transfer then there cannot be @@ -405,18 +448,18 @@ void* nrn_fixed_step_group_thread(NrnThread* nth) { if (nth->_stop_stepping) { if (nth->id == 0) { step_group_end = i + 1; } nth->_stop_stepping = 0; - return (void*)0; + return nullptr; } } if (nth->id == 0) { step_group_end = step_group_n; } - return (void*)0; + return nullptr; } void* nrn_fixed_step_thread(NrnThread* nth) { double wt; deliver_net_events(nth); wt = nrnmpi_wtime(); - nrn_random_play(nth); + nrn_random_play(/*nth*/); // TODO nrnthread fn? #if ELIMINATE_T_ROUNDOFF nth->nrn_ndt_ += .5; nth->_t = nrn_tbase_ + nth->nrn_ndt_ * nrn_dt_; @@ -436,7 +479,7 @@ void* nrn_fixed_step_thread(NrnThread* nth) { if (!nrnthread_v_transfer_) { nrn_fixed_step_lastpart(nth); } - return (void*)0; + return nullptr; } extern void nrn_extra_scatter_gather(int direction, int tid); @@ -466,7 +509,7 @@ void* nrn_fixed_step_lastpart(NrnThread* nth) { fixed_record_continuous(nth); CTADD nrn_deliver_events(nth) ; /* up to but not past texit */ - return (void*)0; + return nullptr; } /* nrn_fixed_step_thread is split into three pieces */ @@ -475,7 +518,7 @@ void* nrn_ms_treeset_through_triang(NrnThread* nth) { double wt; deliver_net_events(nth); wt = nrnmpi_wtime(); - nrn_random_play(nth); + nrn_random_play(/*nth*/); // TODO nrnthread fn? #if ELIMINATE_T_ROUNDOFF nth->nrn_ndt_ += .5; nth->_t = nrn_tbase_ + nth->nrn_ndt_ * nrn_dt_; @@ -486,11 +529,11 @@ void* nrn_ms_treeset_through_triang(NrnThread* nth) { setup_tree_matrix(nth); nrn_multisplit_triang(nth); CTADD - return (void*)0; + return nullptr; } void* nrn_ms_reduce_solve(NrnThread* nth) { nrn_multisplit_reduce_solve(nth); - return (void*)0; + return nullptr; } void* nrn_ms_bksub(NrnThread* nth) { CTBEGIN @@ -502,7 +545,7 @@ void* nrn_ms_bksub(NrnThread* nth) { if (!nrnthread_v_transfer_) { nrn_fixed_step_lastpart(nth); } - return (void*)0; + return nullptr; } void* nrn_ms_bksub_through_triang(NrnThread* nth) { nrn_ms_bksub(nth); @@ -511,10 +554,10 @@ void* nrn_ms_bksub_through_triang(NrnThread* nth) { if (nth == nrn_threads) { step_group_n = 1; } - return (void*)0; + return nullptr; } nrn_ms_treeset_through_triang(nth); - return (void*)0; + return nullptr; } #if NRN_REALTIME @@ -760,351 +803,310 @@ void verify_structure(void) { } void nrn_finitialize(int setv, double v) { - int iord, i; - NrnThread* _nt; - extern int _ninits; - extern short* nrn_is_artificial_; - ++_ninits; - - nrn_fihexec(3); /* model structure changes can be made */ - verify_structure(); + int iord, i; + NrnThread *_nt; + extern int _ninits; + extern short *nrn_is_artificial_; + ++_ninits; + + nrn_fihexec(3); /* model structure changes can be made */ + verify_structure(); #if ELIMINATE_T_ROUNDOFF - nrn_ndt_ = 0.; nrn_dt_ = dt; nrn_tbase_ = 0.; + nrn_ndt_ = 0.; nrn_dt_ = dt; nrn_tbase_ = 0.; #else - t = 0.; - dt2thread(-1.); + t = 0.; + dt2thread(-1.); #endif - if (cvode_active_) { - nrncvode_set_t(t); - } - nrn_thread_table_check(); - clear_event_queue(); - nrn_spike_exchange_init(); - nrn_random_play(_nt); + if (cvode_active_) { + nrncvode_set_t(t); + } + nrn_thread_table_check(); + clear_event_queue(); + nrn_spike_exchange_init(); + nrn_random_play(/*_nt*/); // TODO nrnthread fn? #if VECTORIZE - nrn_play_init(); /* Vector.play */ - for (i=0; i < nrn_nthread; ++i) { - nrn_deliver_events(nrn_threads + i); /* The play events at t=0 */ - } - if (setv) { + nrn_play_init(); /* Vector.play */ + for (i = 0; i < nrn_nthread; ++i) { + nrn_deliver_events(nrn_threads + i); /* The play events at t=0 */ + } + if (setv) { #if _CRAY #pragma _CRI ivdep #endif - FOR_THREADS(_nt) for (i=0; i < _nt->end; ++i) { - NODEV(_nt->_v_node[i]) = v; - } - } + FOR_THREADS(_nt) + for (i = 0; i < _nt->end; ++i) { + NODEV(_nt->_v_node[i]) = v; + } + } #if 1 || PARANEURON - if (nrnthread_vi_compute_) FOR_THREADS(_nt){ - (*nrnthread_vi_compute_)(_nt); - } - if (nrnmpi_v_transfer_) { - (nrnmpi_v_transfer_)(); - } - if (nrnthread_v_transfer_) FOR_THREADS(_nt){ - (*nrnthread_v_transfer_)(_nt); - } + if (nrnthread_vi_compute_) FOR_THREADS(_nt) + { + (*nrnthread_vi_compute_)(_nt); + } + if (nrnmpi_v_transfer_) { + (nrnmpi_v_transfer_)(); + } + if (nrnthread_v_transfer_) FOR_THREADS(_nt) + { + (*nrnthread_v_transfer_)(_nt); + } #endif - nrn_fihexec(0); /* after v is set but before INITIAL blocks are called*/ - for (i=0; i < nrn_nthread; ++i) { - nrn_ba(nrn_threads + i, BEFORE_INITIAL); - } + nrn_fihexec(0); /* after v is set but before INITIAL blocks are called*/ + for (i = 0; i < nrn_nthread; ++i) { + nrn_ba(nrn_threads + i, BEFORE_INITIAL); + } #if _CRAY - cray_node_init(); + cray_node_init(); #endif - /* the INITIAL blocks are ordered so that mechanisms that write - concentrations are after ions and before mechanisms that read - concentrations. - */ - /* the memblist list in NrnThread is already so ordered */ + /* the INITIAL blocks are ordered so that mechanisms that write + concentrations are after ions and before mechanisms that read + concentrations. + */ + /* the memblist list in NrnThread is already so ordered */ #if MULTICORE - for (i=0; i < nrn_nthread; ++i) { - NrnThread* nt = nrn_threads + i; - nrn_nonvint_block_init(nt->id); - NrnThreadMembList* tml; - for (tml = nt->tml; tml; tml = tml->next) { - Pvmi s = memb_func[tml->index].initialize; - if (s) { - (*s)(nt, tml->ml, tml->index); - } - } - } + for (i = 0; i < nrn_nthread; ++i) { + NrnThread *nt = nrn_threads + i; + nrn_nonvint_block_init(nt->id); + NrnThreadMembList *tml; + for (tml = nt->tml; tml; tml = tml->next) { + Pvmi s = memb_func[tml->index].initialize; + if (s) { + (*s)(nt, tml->ml, tml->index); + } + } + } #endif - for (iord=0; iord < n_memb_func; ++iord) { - i = memb_order_[iord]; - /* first clause due to MULTICORE */ - if (nrn_is_artificial_[i]) if (memb_func[i].initialize) { - Pvmi s = memb_func[i].initialize; + for (iord = 0; iord < n_memb_func; ++iord) { + i = memb_order_[iord]; + /* first clause due to MULTICORE */ + if (nrn_is_artificial_[i]) + if (memb_func[i].initialize) { + Pvmi s = memb_func[i].initialize; #if 0 - if (nrn_is_artificial_[i]) { - /* - I hope the space saving of the memb_list arrays is worth - doing this specifically. And if art cells are needed - in the memb_list anywhere else we will have do do something - similar to this. This gives up vectorization but this is only - initialization and all the other use of artcell should be - event driven. - */ - Prop* p; - hoc_Item* q; - hoc_List* list = nrn_pnt_template_[i]->olist; - ITERATE(q, list) { - Object* obj = OBJ(q); - Prop* p = ((Point_process*)obj->u.this_pointer)->prop; - (*s)((Node*)0, p->param, p->dparam); - } - }else if (memb_list[i].nodecount){ + if (nrn_is_artificial_[i]) { + /* + I hope the space saving of the memb_list arrays is worth + doing this specifically. And if art cells are needed + in the memb_list anywhere else we will have do do something + similar to this. This gives up vectorization but this is only + initialization and all the other use of artcell should be + event driven. + */ + Prop* p; + hoc_Item* q; + hoc_List* list = nrn_pnt_template_[i]->olist; + ITERATE(q, list) { + Object* obj = OBJ(q); + Prop* p = ((Point_process*)obj->u.this_pointer)->prop; + (*s)((Node*)0, p->param, p->dparam); + } + }else if (memb_list[i].nodecount){ #else - if (memb_list[i].nodecount){ + if (memb_list[i].nodecount) { #endif - (*s)(nrn_threads, memb_list + i, i); - } - if (errno) { - if (nrn_errno_check(i)) { -hoc_warning("errno set during call to INITIAL block", (char*)0); - } - } - } - } + (*s)(nrn_threads, memb_list + i, i); + } + if (errno) { + if (nrn_errno_check(i)) { + hoc_warning("errno set during call to INITIAL block", (char *) 0); + } + } + } + } #endif - if (use_sparse13) { - nrndae_init(); - } + if (use_sparse13) { + nrndae_init(); + } - init_net_events(); - for (i = 0; i < nrn_nthread; ++i) { - nrn_ba(nrn_threads + i, AFTER_INITIAL); - } - nrn_fihexec(1); /* after INITIAL blocks, before fcurrent*/ + init_net_events(); + for (i = 0; i < nrn_nthread; ++i) { + nrn_ba(nrn_threads + i, AFTER_INITIAL); + } + nrn_fihexec(1); /* after INITIAL blocks, before fcurrent*/ - for (i=0; i < nrn_nthread; ++i) { - nrn_deliver_events(nrn_threads + i); /* The INITIAL sent events at t=0 */ - } - if (cvode_active_) { - cvode_finitialize(t); - nrn_record_init(); - }else{ - state_discon_allowed_ = 0; - for (i=0; i < nrn_nthread; ++i) { - setup_tree_matrix(nrn_threads + i); - if (nrn_use_fast_imem) { - nrn_calc_fast_imem(nrn_threads + i); - } - } - state_discon_allowed_ = 1; + for (i = 0; i < nrn_nthread; ++i) { + nrn_deliver_events(nrn_threads + i); /* The INITIAL sent events at t=0 */ + } + if (cvode_active_) { + cvode_finitialize(t); + nrn_record_init(); + } else { + state_discon_allowed_ = 0; + for (i = 0; i < nrn_nthread; ++i) { + setup_tree_matrix(nrn_threads + i); + if (nrn_use_fast_imem) { + nrn_calc_fast_imem(nrn_threads + i); + } + } + state_discon_allowed_ = 1; #if 0 && NRN_DAQ - nrn_daq_ao(); - nrn_daq_scanstart(); - nrn_daq_ai(); + nrn_daq_ao(); + nrn_daq_scanstart(); + nrn_daq_ai(); #endif - nrn_record_init(); - for (i=0; i < nrn_nthread; ++i) { - fixed_record_continuous(nrn_threads + i); - } - } - for (i=0; i < nrn_nthread; ++i) { - nrn_deliver_events(nrn_threads + i); /* The record events at t=0 */ - } + nrn_record_init(); + for (i = 0; i < nrn_nthread; ++i) { + fixed_record_continuous(nrn_threads + i); + } + } + for (i = 0; i < nrn_nthread; ++i) { + nrn_deliver_events(nrn_threads + i); /* The record events at t=0 */ + } #if NRNMPI - nrn_spike_exchange(nrn_threads); + nrn_spike_exchange(nrn_threads); #endif - if (nrn_allthread_handle) { (*nrn_allthread_handle)(); } - - nrn_fihexec(2); /* just before return */ + if (nrn_allthread_handle) { (*nrn_allthread_handle)(); } + + nrn_fihexec(2); /* just before return */ } - + void finitialize(void) { - int setv; - double v = 0.0; - setv = 0; - if (ifarg(1)) { - v = *getarg(1); - setv = 1; - } - tstopunset; - nrn_finitialize(setv, v); - tstopunset; - hoc_retpushx(1.); + int setv; + double v = 0.0; + setv = 0; + if (ifarg(1)) { + v = *getarg(1); + setv = 1; + } + tstopunset; + nrn_finitialize(setv, v); + tstopunset; + hoc_retpushx(1.); } -static FILE* batch_file; -static int batch_size; -static int batch_n; -static double** batch_var; - -static void batch_open(name, tstop, tstep, comment) - char* name, *comment; - double tstop, tstep; -{ - if (batch_file) { - batch_close(); - } - if (!name) { - return; - } - batch_file = fopen(name, "w"); - if (!batch_file) { - hoc_execerror("Couldn't open batch file", name); - } - fprintf(batch_file, "%s\nbatch_run from t = %g to %g in steps of %g with dt = %g\n", - comment, t, tstop, tstep, dt); -#if 0 - fprintf(batch_file, "variable names --\n"); - if (!batch_var) { - batch_var = hoc_newlist(); - } - count = 0; - ITERATE(q, batch_varname) { - fprintf(batch_file, "%s\n", STR(q)); - ++count; - } - if (count != batch_n) { - if (batch_var) { - free(batch_var); - } - batch_n = count; - batch_var = (double**)ecalloc(batch_n, sizeof(double*)); - } - count = 0; - ITERATE(q, batch_varname) { - batch_var[count++] = hoc_val_pointer(STR(q)); - } -#endif -} static void batch_close() { - if (batch_file) { - fclose(batch_file); - batch_file = 0; - } + if (batch_file) { + fclose(batch_file); + batch_file = 0; + } } static void batch_out() { - if (batch_file) { - int i; - for (i =0; i < batch_n; ++i) { - fprintf(batch_file, " %g", *batch_var[i]); - } - fprintf(batch_file,"\n"); - } + if (batch_file) { + int i; + for (i = 0; i < batch_n; ++i) { + fprintf(batch_file, " %g", *batch_var[i]); + } + fprintf(batch_file, "\n"); + } } void batch_save(void) { - double* hoc_pgetarg(); - int i; - if (!ifarg(1)) { - batch_n = 0; - }else{ - for (i=1; ifarg(i); ++i) { - if ( batch_size <= batch_n){ - batch_size += 20; - batch_var = (double**)erealloc(batch_var, batch_size*sizeof(double*)); - } - batch_var[batch_n] = hoc_pgetarg(i); - ++batch_n; - } - } - hoc_retpushx(1.); +// double* hoc_pgetarg(); + int i; + if (!ifarg(1)) { + batch_n = 0; + } else { + for (i = 1; ifarg(i); ++i) { + if (batch_size <= batch_n) { + batch_size += 20; + batch_var = (double **) erealloc(batch_var, batch_size * sizeof(double *)); + } + batch_var[batch_n] = hoc_pgetarg(i); + ++batch_n; + } + } + hoc_retpushx(1.); } -void nrn_ba(NrnThread* nt, int bat){ - NrnThreadBAList* tbl; - int i; - for (tbl = nt->tbl[bat]; tbl; tbl = tbl->next) { - nrn_bamech_t f = tbl->bam->f; - int type = tbl->bam->type; - Memb_list* ml = tbl->ml; - for (i=0; i < ml->nodecount; ++i) { - (*f)(ml->nodelist[i], ml->data[i], ml->pdata[i], ml->_thread, nt); - } - } +void nrn_ba(NrnThread *nt, int bat) { + NrnThreadBAList *tbl; + int i; + for (tbl = nt->tbl[bat]; tbl; tbl = tbl->next) { + nrn_bamech_t f = tbl->bam->f; + int type = tbl->bam->type; + Memb_list *ml = tbl->ml; + for (i = 0; i < ml->nodecount; ++i) { + (*f)(ml->nodelist[i], ml->data[i], ml->pdata[i], ml->_thread, nt); + } + } } -typedef struct List_nonvint_block -{ - int (*func)(int method, int size, double* pd1, double* pd2, int tid); - struct List_nonvint_block *next; +typedef struct List_nonvint_block { + int (*func)(int method, int size, double *pd1, double *pd2, int tid); + + struct List_nonvint_block *next; } List_nonvint_block; /* a global list to store the nrn_nonvint_block functions */ -List_nonvint_block* nonvint_block_list = NULL; - -int nrn_nonvint_block_exe(int method, int size, double* pd1, double* pd2, int tid) { - /* execute all functions in nonvint_block_list and return the sum of the - * return values - */ - int rval, sum = 0; - List_nonvint_block* node; - - for(node = nonvint_block_list; node != NULL; node = node-> next) { - rval = (*(node->func))(method, size, pd1, pd2, tid); - if(rval == -1) { - hoc_execerror("nrn_nonvint_block error", 0); - } - else { - sum += rval; - } - if (method == NONVINT_ODE_COUNT) { - size += rval; - } - } - - return sum; +List_nonvint_block *nonvint_block_list = NULL; + +int nrn_nonvint_block_exe(int method, int size, double *pd1, double *pd2, int tid) { + /* execute all functions in nonvint_block_list and return the sum of the + * return values + */ + int rval, sum = 0; + List_nonvint_block *node; + + for (node = nonvint_block_list; node != NULL; node = node->next) { + rval = (*(node->func))(method, size, pd1, pd2, tid); + if (rval == -1) { + hoc_execerror("nrn_nonvint_block error", 0); + } else { + sum += rval; + } + if (method == NONVINT_ODE_COUNT) { + size += rval; + } + } + + return sum; } -int set_nonvint_block(int (*new_nrn_nonvint_block)(int method, int size, double* pd1, double* pd2, int tid)) { +extern "C" int set_nonvint_block(int (*new_nrn_nonvint_block)(int method, int size, double *pd1, double *pd2, int tid)) { - /* store new_nrn_nonvint_block functions in a list */ - List_nonvint_block* node = (List_nonvint_block*)malloc(sizeof(List_nonvint_block)); - node->func = new_nrn_nonvint_block; - node->next = NULL; + /* store new_nrn_nonvint_block functions in a list */ + List_nonvint_block *node = (List_nonvint_block *) malloc(sizeof(List_nonvint_block)); + node->func = new_nrn_nonvint_block; + node->next = NULL; - if(nonvint_block_list == NULL) { - nonvint_block_list = node; - } - else { - nonvint_block_list->next = node; - } - /* could this be set directly in nrn_nonvint_block_helper? */ - nrn_nonvint_block = &nrn_nonvint_block_exe; + if (nonvint_block_list == NULL) { + nonvint_block_list = node; + } else { + nonvint_block_list->next = node; + } + /* could this be set directly in nrn_nonvint_block_helper? */ + nrn_nonvint_block = &nrn_nonvint_block_exe; - return 0; + return 0; } -int nrn_nonvint_block_helper(int method, int size, double* pd1, double* pd2, int tid) { - int rval = (*nrn_nonvint_block)(method, size, pd1, pd2, tid); - if (rval == -1) { - hoc_execerror("nrn_nonvint_block error", 0); - } - return rval; +int nrn_nonvint_block_helper(int method, int size, double *pd1, double *pd2, int tid) { + int rval = (*nrn_nonvint_block)(method, size, pd1, pd2, tid); + if (rval == -1) { + hoc_execerror("nrn_nonvint_block error", 0); + } + return rval; } /* - Derived from scopmath/euler.c. Here because scopmath does not know + Derived from scopmath/euler.cpp. Here because scopmath does not know about NrnThread */ #include "nrniv_mf.h" + #undef SUCCESS #define SUCCESS 0 #define der_(arg) p[der[arg]] #define var_(arg) p[var[arg]] + /* ARGSUSED */ -int euler_thread(int neqn, int* var, int* der, double* p, - int (*func)(double*, Datum*, Datum*, NrnThread*), - Datum* ppvar, Datum* thread, NrnThread* nt) -{ +extern "C" int euler_thread(int neqn, int *var, int *der, double *p, + int (*func)(double *, Datum *, Datum *, NrnThread *), + Datum *ppvar, Datum *thread, NrnThread *nt) { int i; double dt = nt->_dt; /* Calculate the derivatives */ - (*func) (p, ppvar, thread, nt); - + (*func)(p, ppvar, thread, nt); + /* Update dependent variables --- note defines in euler above*/ for (i = 0; i < neqn; i++) var_(i) += dt * (der_(i)); - + return (SUCCESS); } diff --git a/src/nrnoc/fstim.c b/src/nrnoc/fstim.c deleted file mode 100644 index 9089c7a9a3..0000000000 --- a/src/nrnoc/fstim.c +++ /dev/null @@ -1,169 +0,0 @@ -#include <../../nrnconf.h> -/* /local/src/master/nrn/src/nrnoc/fstim.c,v 1.2 1997/08/15 13:04:11 hines Exp */ -/* copy of synapse.c modified to simulate current stimulus pulses */ -/* 4/9/2002 modified to conform to new treeset.c */ - -/* -fstim(maxnum) - allocates space for maxnum synapses. Space for - previously existing synapses is released. All synapses initialized to - 0 maximum conductance. - -fstim(i, loc, delay, duration, stim) - The ith current stimulus is injected at parameter `loc' - different current stimuli do not concatenate but can ride on top of - each other. delay refers to onset of stimulus relative to t=0 - delay and duration are in msec. - stim in namps. - -fstimi(i) - returns stimulus current for ith stimulus at the value of the - global time t. - -*/ - -#include -#include "neuron.h" -#include "section.h" -#include "nrniv_mf.h" - -typedef struct Stimulus { - double loc; /* parameter location (0--1) */ - double delay; /* value of t in msec for onset */ - double duration;/* turns off at t = delay + duration */ - double mag; /* magnitude in namps */ - double mag_seg; /* value added to rhs, depends on area of seg*/ - Node *pnd; /* segment location */ - Section* sec; -} Stimulus; - -static int maxstim = 0; /* size of stimulus array */ -static Stimulus *pstim; /* pointer to stimulus array */ -static void free_stim(void); -static void stim_record(int); - -#define nt_t nrn_threads->_t - -void print_stim() { - int i; - - if (maxstim == 0) return; - /*SUPPRESS 440*/ - Printf("fstim(%d)\n/* section fstim( #, loc, delay(ms), duration(ms), magnitude(namp)) */\n", maxstim); - for (i=0; i 1) { - hoc_execerror("fstim does not allow threads", ""); - } - i = chkarg(1, 0., 10000.); - if (ifarg(2)) { - if (i >= maxstim) { - hoc_execerror("index out of range", (char *)0); - } - pstim[i].loc = chkarg(2, 0., 1.); - pstim[i].delay = chkarg(3, 0., 1e21); - pstim[i].duration = chkarg(4, 0., 1e21); - pstim[i].mag = *getarg(5); - pstim[i].sec = chk_access(); - section_ref(pstim[i].sec); - stim_record(i); - } else { - free_stim(); - maxstim = i; - if (maxstim) { - pstim = (Stimulus *)emalloc((unsigned)(maxstim * sizeof(Stimulus))); - } - for (i = 0; iprop) { - pstim[i].pnd = node_ptr(sec, pstim[i].loc, &area); - pstim[i].mag_seg = 1.e2*pstim[i].mag / area; - }else{ - section_unref(sec); - pstim[i].sec = 0; - } - } -} - -void stim_prepare(void) { - int i; - - for (i=0; i pstim[i].delay + pstim[i].duration - 1e-9) { - return 0.0; - } - return pstim[i].mag_seg; -} - -void activstim_rhs(void) { - int i; - - for (i=0; i +/* /local/src/master/nrn/src/nrnoc/fstim.cpp,v 1.2 1997/08/15 13:04:11 hines Exp */ +/* copy of synapse.cpp modified to simulate current stimulus pulses */ +/* 4/9/2002 modified to conform to new treeset.cpp */ + +/* +fstim(maxnum) + allocates space for maxnum synapses. Space for + previously existing synapses is released. All synapses initialized to + 0 maximum conductance. + +fstim(i, loc, delay, duration, stim) + The ith current stimulus is injected at parameter `loc' + different current stimuli do not concatenate but can ride on top of + each other. delay refers to onset of stimulus relative to t=0 + delay and duration are in msec. + stim in namps. + +fstimi(i) + returns stimulus current for ith stimulus at the value of the + global time t. + +*/ + +#include +#include "neuron.h" +#include "section.h" +#include "nrniv_mf.h" + + +typedef struct Stimulus { + double loc; /* parameter location (0--1) */ + double delay; /* value of t in msec for onset */ + double duration;/* turns off at t = delay + duration */ + double mag; /* magnitude in namps */ + double mag_seg; /* value added to rhs, depends on area of seg*/ + Node *pnd; /* segment location */ + Section *sec; +} Stimulus; + +static int maxstim = 0; /* size of stimulus array */ +static Stimulus *pstim; /* pointer to stimulus array */ +static void free_stim(void); + +static void stim_record(int); + +#define nt_t nrn_threads->_t + +void print_stim() { + int i; + + if (maxstim == 0) return; + /*SUPPRESS 440*/ + Printf("fstim(%d)\n/* section fstim( #, loc, delay(ms), duration(ms), magnitude(namp)) */\n", maxstim); + for (i = 0; i < maxstim; i++) { + Printf("%-15s fstim(%2d,%4g,%10g,%13g,%16g)\n", + secname(pstim[i].sec), i, + pstim[i].loc, pstim[i].delay, pstim[i].duration, pstim[i].mag); + } +} + +static double stimulus(int i) { +#if CVODE + at_time(nrn_threads, pstim[i].delay); + at_time(nrn_threads, pstim[i].delay + pstim[i].duration); +#endif + if (nt_t < pstim[i].delay - 1e-9 + || nt_t > pstim[i].delay + pstim[i].duration - 1e-9) { + return 0.0; + } + return pstim[i].mag_seg; +} + +void fstimi(void) { + int i; + double cur; + + i = chkarg(1, 0., (double) (maxstim - 1)); + if ((cur = stimulus(i)) != 0.) { + cur = pstim[i].mag; + } + hoc_retpushx(cur); +} + +void fstim(void) { + int i; + + if (nrn_nthread > 1) { + hoc_execerror("fstim does not allow threads", ""); + } + i = chkarg(1, 0., 10000.); + if (ifarg(2)) { + if (i >= maxstim) { + hoc_execerror("index out of range", (char *) 0); + } + pstim[i].loc = chkarg(2, 0., 1.); + pstim[i].delay = chkarg(3, 0., 1e21); + pstim[i].duration = chkarg(4, 0., 1e21); + pstim[i].mag = *getarg(5); + pstim[i].sec = chk_access(); + section_ref(pstim[i].sec); + stim_record(i); + } else { + free_stim(); + maxstim = i; + if (maxstim) { + pstim = (Stimulus *) emalloc((unsigned) (maxstim * sizeof(Stimulus))); + } + for (i = 0; i < maxstim; i++) { + pstim[i].loc = 0; + pstim[i].mag = 0.; + pstim[i].delay = 1e20; + pstim[i].duration = 0.; + pstim[i].sec = 0; + stim_record(i); + } + } + hoc_retpushx(0.); +} + +static void free_stim(void) { + int i; + if (maxstim) { + for (i = 0; i < maxstim; ++i) { + if (pstim[i].sec) { + section_unref(pstim[i].sec); + } + } + free((char *) pstim); + maxstim = 0; + } +} + +static void stim_record(int i) /*fill in the section info*/ +{ +// Node *node_ptr(); + double area; + Section *sec; + + sec = pstim[i].sec; + if (sec) { + if (sec->prop) { + pstim[i].pnd = node_ptr(sec, pstim[i].loc, &area); + pstim[i].mag_seg = 1.e2 * pstim[i].mag / area; + } else { + section_unref(sec); + pstim[i].sec = 0; + } + } +} + +void stim_prepare(void) { + int i; + + for (i = 0; i < maxstim; i++) { + stim_record(i); + } +} + +void activstim_rhs(void) { + int i; + + for (i = 0; i < maxstim; i++) { + if (pstim[i].sec) { + NODERHS(pstim[i].pnd) += stimulus(i); + } + } +} + diff --git a/src/nrnoc/gui-redirect.h b/src/nrnoc/gui-redirect.h index 86415a1c8c..0bfb7ffd43 100644 --- a/src/nrnoc/gui-redirect.h +++ b/src/nrnoc/gui-redirect.h @@ -3,17 +3,11 @@ #include "hocdec.h" -#if defined(__cplusplus) -extern "C" { -#endif extern Object* nrn_get_gui_redirect_obj(); extern Object** (*nrnpy_gui_helper_)(const char*, Object*); extern double (*nrnpy_object_to_double_)(Object*); -#if defined(__cplusplus) -} -#endif #define TRY_GUI_REDIRECT_OBJ(name, obj) {\ Object** ngh_result;\ diff --git a/src/nrnoc/hh.mod b/src/nrnoc/hh.mod index 2fb3adb848..e5c16f6e93 100644 --- a/src/nrnoc/hh.mod +++ b/src/nrnoc/hh.mod @@ -29,7 +29,7 @@ NEURON { NONSPECIFIC_CURRENT il RANGE gnabar, gkbar, gl, el, gna, gk : `GLOBAL minf` will be replaced with `RANGE minf` if CoreNEURON enabled - GLOBAL minf, hinf, ninf, mtau, htau, ntau + RANGE minf, hinf, ninf, mtau, htau, ntau THREADSAFE : assigned GLOBALs will be per thread } @@ -93,7 +93,7 @@ PROCEDURE rates(v(mV)) { :Computes rate and other constants at current v. :Call once from HOC to initialize inf at resting v. LOCAL alpha, beta, sum, q10 : `TABLE minf` will be replaced with `:TABLE minf` if CoreNEURON enabled) - TABLE minf, mtau, hinf, htau, ninf, ntau DEPEND celsius FROM -100 TO 100 WITH 200 + :TABLE minf, mtau, hinf, htau, ninf, ntau DEPEND celsius FROM -100 TO 100 WITH 200 UNITSOFF q10 = 3^((celsius - 6.3)/10) diff --git a/src/nrnoc/hoc_init.cpp b/src/nrnoc/hoc_init.cpp new file mode 100755 index 0000000000..ff31a1dc87 --- /dev/null +++ b/src/nrnoc/hoc_init.cpp @@ -0,0 +1,6 @@ +#include <../../nrnconf.h> +/* + * Automake doesn't deal well with sources that live in other directories, so + * this is a quick and dirty workaround. + */ +#include "../oc/hoc_init.cpp" diff --git a/src/nrnoc/hoc_oop.cpp b/src/nrnoc/hoc_oop.cpp new file mode 100755 index 0000000000..7f91380ba9 --- /dev/null +++ b/src/nrnoc/hoc_oop.cpp @@ -0,0 +1,6 @@ +#include <../../nrnconf.h> +/* + * Automake doesn't deal well with sources that live in other directories, so + * this is a quick and dirty workaround. + */ +#include "../oc/hoc_oop.cpp" diff --git a/src/nrnoc/hocprax.c b/src/nrnoc/hocprax.cpp similarity index 84% rename from src/nrnoc/hocprax.c rename to src/nrnoc/hocprax.cpp index de75837edb..4027ecf145 100644 --- a/src/nrnoc/hocprax.c +++ b/src/nrnoc/hocprax.cpp @@ -2,7 +2,7 @@ /* Hoc interface to praxis. -See praxis.c in the scopmath library about +See praxis.cpp in the scopmath library about tolerance (t0), maxstepsize (h0), and printmode (prin). These are set with attr_praxis(t0, h0, prin) @@ -40,17 +40,27 @@ pval = pval_praxis(i, Vector) #include "hocdec.h" #include "parse.h" -extern int stoprun; -extern double praxis(), praxis_pval(), *praxis_paxis(), chkarg(); +#if defined(__cplusplus) +extern "C" { +#endif + +extern double praxis(...), praxis_pval(int), *praxis_paxis(int); extern int praxis_stop(int); -extern void vector_resize(void*, int); -extern double* vector_vec(void*); -extern void* vector_arg(int); -extern void* vector_new2(void* vec); -extern void vector_delete(void* vec); -extern int vector_capacity(void*); -extern Object** vector_pobj(void* v); +#if defined(__cplusplus) +} +#endif + +extern int stoprun; +extern double chkarg(int, double, double); + +extern void vector_resize(IvocVect*, int); +extern double* vector_vec(IvocVect*); +extern IvocVect* vector_arg(int); //TODO: IvocVect? +extern IvocVect* vector_new2(IvocVect* vec); +extern void vector_delete(IvocVect* vec); +extern int vector_capacity(IvocVect*); +extern Object** vector_pobj(IvocVect* v); extern int nrn_praxis_ran_index; extern Object** hoc_objgetarg(int); @@ -82,8 +92,8 @@ void stop_praxis(void) { static double minerr, *minarg; /* too bad this is not recursive */ void fit_praxis(void) { - extern Symbol* hoc_lookup(); - extern char* gargstr(); +// extern Symbol* hoc_lookup(char *); +// extern char* gargstr(); char* after_quad; int i; double err, fmin; @@ -127,9 +137,9 @@ void fit_praxis(void) { hoc_obj_ref(efun_py_); efun_py_arg_ = *vector_pobj(vector_arg(2)); hoc_obj_ref(efun_py_arg_); - vec_py_save_ = vector_new2(efun_py_arg_->u.this_pointer); - nvar_ = vector_capacity(vec_py_save_); - px = vector_vec(vec_py_save_); + vec_py_save_ = vector_new2(static_cast(efun_py_arg_->u.this_pointer)); + nvar_ = vector_capacity(static_cast(vec_py_save_)); + px = vector_vec(static_cast(vec_py_save_)); }else{ nvar_ = (int)chkarg(1, 0., 1e6); efun_sym_ = hoc_lookup(gargstr(2)); @@ -140,7 +150,7 @@ void fit_praxis(void) { } if (!hoc_is_pdouble_arg(3)) { - void* vec = vector_arg(3); + IvocVect* vec = vector_arg(3); if (vector_capacity(vec) != nvar_) { hoc_execerror("first arg not equal to size of Vector",0); } @@ -206,13 +216,13 @@ void fit_praxis(void) { vec_py_save = vec_py_save_save; if (efun_py_) { - double* px = vector_vec(efun_py_arg_->u.this_pointer); + double* px = vector_vec(static_cast(efun_py_arg_->u.this_pointer)); for (i=0; i < nvar_; ++i) { px[i] = minarg_[i]; } hoc_obj_unref(efun_py_); hoc_obj_unref(efun_py_arg_); - vector_delete(vec_py_save_); + vector_delete(static_cast(vec_py_save_)); } if (minarg_) { free(minarg_); @@ -220,7 +230,7 @@ void fit_praxis(void) { hoc_retpushx(err); } -void hoc_after_prax_quad(s) char* s; { +extern "C" void hoc_after_prax_quad(char* s) { efun(minarg, nvar); hoc_obj_run(s, hoc_thisobject); } @@ -248,7 +258,7 @@ void pval_praxis(void) { double *p1, *p2; p1 = praxis_paxis(i); if (!hoc_is_pdouble_arg(2)) { - void* vec = vector_arg(2); + IvocVect* vec = vector_arg(2); vector_resize(vec, nvar); p2 = vector_vec(vec); }else{ @@ -266,7 +276,7 @@ static double efun(double* v, int n) int i; double err; if (efun_py) { - double* px = vector_vec(efun_py_arg->u.this_pointer); + double* px = vector_vec(static_cast(efun_py_arg->u.this_pointer)); for (i=0; i < n; ++i) { px[i] = v[i]; } @@ -275,7 +285,7 @@ static double efun(double* v, int n) v[i] = px[i]; } }else{ - extern double hoc_call_func(); +// extern double hoc_call_func(); int i; hoc_pushx((double)n); hoc_pushpx(v); @@ -288,4 +298,5 @@ static double efun(double* v, int n) } } return err; -} +} + diff --git a/src/nrnoc/code.c b/src/nrnoc/hocusr.cpp similarity index 84% rename from src/nrnoc/code.c rename to src/nrnoc/hocusr.cpp index 8af7ec6847..aa5487efc9 100755 --- a/src/nrnoc/code.c +++ b/src/nrnoc/hocusr.cpp @@ -3,4 +3,4 @@ * Automake doesn't deal well with sources that live in other directories, so * this is a quick and dirty workaround. */ -#include "../oc/code.c" +#include "../oc/hocusr.cpp" diff --git a/src/nrnoc/hocusr.h b/src/nrnoc/hocusr.h new file mode 100644 index 0000000000..16b493f91f --- /dev/null +++ b/src/nrnoc/hocusr.h @@ -0,0 +1,186 @@ + +extern void node_data(), disconnect(); +extern void batch_run(), batch_save(); +extern void pt3dclear(), pt3dadd(), n3d(), x3d(), y3d(), z3d(), arc3d(), diam3d(); +extern void pt3dinsert(), pt3dremove(), pt3dchange(); +extern void define_shape(), pt3dconst(), pt3dstyle(); +extern void spine3d(), setSpineArea(), getSpineArea(); +extern void area(), ri(); +extern void initnrn(), nrnhoc_topology(), fadvance(), distance(), finitialize(); +extern void fstim(), fstimi(); +extern void ion_style(), ion_register(), ion_charge(), nernst(), ghk(); +extern void section_owner(); +extern void make_mechanism(), make_pointprocess(); +extern void nrnpython(); +extern void fsyn(), fsyng(), fsyni(); +extern void fclamp(), fclampi(), fclampv(), prstim(); +extern void fcurrent(), fmatrix(), frecord_init(); +extern void issection(), ismembrane(), sectionname(), psection(); +extern void pop_section(), push_section(), section_exists(); +extern void delete_section(); +extern int secondorder, diam_changed, nrn_shape_changed_, nrn_netrec_state_adjust, nrn_sparse_partrans; +extern double clamp_resist; +extern double celsius; +extern int stoprun; +extern void fit_praxis(), attr_praxis(), pval_praxis(), stop_praxis(); +extern void keep_nseg_parm(); +extern void nrnallsectionmenu(), nrnallpointmenu(), nrnsecmenu(); +extern void nrnglobalmechmenu(), nrnmechmenu(), nrnpointmenu(); +extern void this_section(), this_node(), parent_section(), parent_node(); +extern void parent_connection(), section_orientation(); + +/* Functions */ +static VoidFunc functions[] = { + +"node_data", node_data, +"disconnect", disconnect, +"batch_run", batch_run, +"batch_save", batch_save, +"pt3dclear", pt3dclear, +"pt3dadd", pt3dadd, +"n3d", n3d, +"x3d", x3d, +"y3d", y3d, +"z3d", z3d, +"arc3d", arc3d, +"diam3d", diam3d, +"pt3dinsert", pt3dinsert, +"pt3dremove", pt3dremove, +"pt3dchange", pt3dchange, +"define_shape", define_shape, +"pt3dconst", pt3dconst, +"pt3dstyle", pt3dstyle, +"spine3d", spine3d, +"setSpineArea", setSpineArea, +"getSpineArea", getSpineArea, +"area", area, +"ri", ri, +"initnrn", initnrn, +"topology", nrnhoc_topology, +"fadvance", fadvance, +"distance", distance, +"finitialize", finitialize, +"fstim", fstim, +"fstimi", fstimi, +"ion_style", ion_style, +"ion_register", ion_register, +"ion_charge", ion_charge, +"nernst", nernst, +"ghk", ghk, +"section_owner", section_owner, +"make_mechanism", make_mechanism, +"make_pointprocess", make_pointprocess, +"nrnpython", nrnpython, +"fsyn", fsyn, +"fsyng", fsyng, +"fsyni", fsyni, +"fclamp", fclamp, +"fclampi", fclampi, +"fclampv", fclampv, +"prstim", prstim, +"fcurrent", fcurrent, +"fmatrix", fmatrix, +"frecord_init", frecord_init, +"issection", issection, +"ismembrane", ismembrane, +"sectionname", sectionname, +"psection", psection, +"pop_section", pop_section, +"push_section", push_section, +"section_exists", section_exists, +"delete_section", delete_section, +"fit_praxis", fit_praxis, +"attr_praxis", attr_praxis, +"pval_praxis", pval_praxis, +"stop_praxis", stop_praxis, +"keep_nseg_parm", keep_nseg_parm, +"nrnallsectionmenu", nrnallsectionmenu, +"nrnallpointmenu", nrnallpointmenu, +"nrnsecmenu", nrnsecmenu, +"nrnglobalmechmenu", nrnglobalmechmenu, +"nrnmechmenu", nrnmechmenu, +"nrnpointmenu", nrnpointmenu, +"this_section", this_section, +"this_node", this_node, +"parent_section", parent_section, +"parent_node", parent_node, +"parent_connection", parent_connection, +"section_orientation", section_orientation, +0, 0 +}; + +static struct { /* Integer Scalars */ + const char *name; + int *pint; +} scint[] = { + +"secondorder", &secondorder, +"diam_changed", &diam_changed, +"nrn_shape_changed_", &nrn_shape_changed_, +"nrn_netrec_state_adjust", &nrn_netrec_state_adjust, +"nrn_sparse_partrans", &nrn_sparse_partrans, +"stoprun", &stoprun, +0, 0 +}; + +static struct { /* Vector integers */ + const char *name; + int *pint; + int index1; +} vint[] = { + +0,0 +}; + +static struct { /* Float Scalars */ + const char *name; + float *pfloat; +} scfloat[] = { + +0, 0 +}; + +static struct { /* Vector float */ + const char *name; + float *pfloat; + int index1; +} vfloat[] = { + +0,0,0 +}; + +/* Double Scalars */ +DoubScal scdoub[] = { + +"clamp_resist", &clamp_resist, +"celsius", &celsius, +0,0 +}; + +/* Vectors */ +DoubVec vdoub[] = { + +0, 0, 0 +}; + +static struct { /* Arrays */ + const char *name; + double *pdoub; + int index1; + int index2; +} ardoub[] = { + +0, 0, 0, 0 +}; + +static struct { /* triple dimensioned arrays */ + const char *name; + double *pdoub; + int index1; + int index2; + int index3; +} thredim[] = { + +0, 0, 0, 0, 0 +}; + diff --git a/src/nrnoc/init.c b/src/nrnoc/init.cpp similarity index 85% rename from src/nrnoc/init.c rename to src/nrnoc/init.cpp index a12b91cc33..c2a14aebea 100644 --- a/src/nrnoc/init.c +++ b/src/nrnoc/init.cpp @@ -1,16 +1,6 @@ #include <../../nrnconf.h> #include -extern char* nrn_version(); - -/* change this to correspond to the ../nmodl/nocpout nmodl_version_ string*/ -static char nmodl_version_[] = -"7.7.0"; - -static char banner[] = -"Duke, Yale, and the BlueBrain Project -- Copyright 1984-2019\n\ -See http://neuron.yale.edu/neuron/credits\n"; - # include #include #include @@ -24,6 +14,16 @@ See http://neuron.yale.edu/neuron/credits\n"; #include "membdef.h" #include "nrnmpi.h" + + +/* change this to correspond to the ../nmodl/nocpout nmodl_version_ string*/ +static char nmodl_version_[] = + "7.7.0"; + +static char banner[] = + "Duke, Yale, and the BlueBrain Project -- Copyright 1984-2019\n\ +See http://neuron.yale.edu/neuron/credits\n"; + #ifdef WIN32 #if defined(HAVE_DLFCN_H) && !defined(__MINGW32__) #include @@ -39,8 +39,8 @@ extern char* dlerror(); #endif // WIN32 #if defined(WIN32) || defined(NRNMECH_DLL_STYLE) -extern char* nrn_mech_dll; /* declared in hoc_init.c so ivocmain.cpp can see it */ -extern int nrn_noauto_dlopen_nrnmech; /* default 0 declared in hoc_init.c */ +extern char* nrn_mech_dll; /* declared in hoc_init.cpp so ivocmain.cpp can see it */ +extern int nrn_noauto_dlopen_nrnmech; /* default 0 declared in hoc_init.cpp */ #endif #if defined(WIN32) @@ -57,7 +57,7 @@ extern int nrn_noauto_dlopen_nrnmech; /* default 0 declared in hoc_init.c */ #if __GNUC__ < 4 #include "osxdlfcn.h" -#include "osxdlfcn.c" +#include "osxdlfcn.cpp" #else #include #endif // __GNUC__ @@ -102,32 +102,32 @@ extern int nrn_nobanner_; #include #include "fisher.h" double id_number; /* for rcs control, set in setup_id_info() */ -char login_name[20]; /* store user's login for sys.c & rcs.c */ +char login_name[20]; /* store user's login for sys.cpp & rcs.cpp */ char *pipe_filter = "more"; /* allow for running NEURON in emacs */ #endif static HocParmLimits _hoc_parm_limits[] = { - "Ra", 1e-6, 1e9, - "L", 1e-4, 1e20, - "diam", 1e-9, 1e9, - "cm", 0., 1e9, - "rallbranch", 1., 1e9, - "nseg", 1., 1e9, - "celsius", -273., 1e6, - "dt", 1e-9, 1e15, + "Ra", 1e-6, 1e9, + "L", 1e-4, 1e20, + "diam", 1e-9, 1e9, + "cm", 0., 1e9, + "rallbranch", 1., 1e9, + "nseg", 1., 1e9, + "celsius", -273., 1e6, + "dt", 1e-9, 1e15, 0, 0., 0. }; static HocParmUnits _hoc_parm_units[] = { - "Ra", "ohm-cm", - "L", "um", - "diam", "um", - "cm", "uF/cm2", - "celsius", "degC", - "dt", "ms", - "t", "ms", - "v", "mV", - "i_cap", "mA/cm2", + "Ra", "ohm-cm", + "L", "um", + "diam", "um", + "cm", "uF/cm2", + "celsius", "degC", + "dt", "ms", + "t", "ms", + "v", "mV", + "i_cap", "mA/cm2", 0, 0 }; @@ -143,7 +143,7 @@ Point_process** point_process; char* pnt_map; /* so prop_free can know its a point mech*/ BAMech** bamech_; -Template** nrn_pnt_template_; /* for finding artificial cells */ +cTemplate** nrn_pnt_template_; /* for finding artificial cells */ /* for synaptic events. */ pnt_receive_t* pnt_receive; pnt_receive_init_t* pnt_receive_init; @@ -158,21 +158,21 @@ int* nrn_dparam_ptr_start_; int* nrn_dparam_ptr_end_; typedef int (*bbcore_write_t)(void*, int, int*, double*, Datum*, Datum*, NrnThread*); bbcore_write_t* nrn_bbcore_write_; -void hoc_reg_bbcore_write(int type, bbcore_write_t f) { +extern "C" void hoc_reg_bbcore_write(int type, bbcore_write_t f) { nrn_bbcore_write_[type] = f; } const char** nrn_nmodl_text_; -void hoc_reg_nmodl_text(int type, const char* txt) { +extern "C" void hoc_reg_nmodl_text(int type, const char* txt) { nrn_nmodl_text_[type] = txt; } const char** nrn_nmodl_filename_; -void hoc_reg_nmodl_filename(int type, const char* filename) { +extern "C" void hoc_reg_nmodl_filename(int type, const char* filename) { nrn_nmodl_filename_[type] = filename; } -void add_nrn_has_net_event(type) int type; { +extern "C" void add_nrn_has_net_event(int type) { ++nrn_has_net_event_cnt_; nrn_has_net_event_ = (int*)erealloc(nrn_has_net_event_, nrn_has_net_event_cnt_*sizeof(int)); nrn_has_net_event_[nrn_has_net_event_cnt_ - 1] = type; @@ -183,7 +183,7 @@ int nrn_fornetcon_cnt_; /* how many models have a FOR_NETCONS statement */ int* nrn_fornetcon_type_; /* what are the type numbers */ int* nrn_fornetcon_index_; /* what is the index into the ppvar array */ -void add_nrn_fornetcons(int type, int indx) { +extern "C" void add_nrn_fornetcons(int type, int indx) { int i = nrn_fornetcon_cnt_++; nrn_fornetcon_type_ = (int*)erealloc(nrn_fornetcon_type_, (i+1)*sizeof(int)); nrn_fornetcon_index_ = (int*)erealloc(nrn_fornetcon_index_, (i+1)*sizeof(int)); @@ -195,7 +195,7 @@ void add_nrn_fornetcons(int type, int indx) { short* nrn_is_artificial_; short* nrn_artcell_qindex_; -void add_nrn_artcell(int type, int qi) { +extern "C" void add_nrn_artcell(int type, int qi) { nrn_is_artificial_[type] = 1; nrn_artcell_qindex_[type] = qi; } @@ -282,7 +282,7 @@ void hoc_nrn_load_dll(void) { } } -extern void nrn_threads_create(int); +extern void nrn_threads_create(int, int); static DoubScal scdoub[] = { "t", &t, @@ -297,9 +297,10 @@ void hoc_last_init(void) Symbol *s; hoc_register_var(scdoub, (DoubVec*)0, (VoidFunc*)0); - nrn_threads_create(1); + nrn_threads_create(1,0); //TODO - 2nd param? - if (nrnmpi_myid < 1) if (nrn_nobanner_ == 0) { + if (nrnmpi_myid < 1) if (nrn_nobanner_ == 0) { + extern char* nrn_version(int i); Fprintf(stderr, "%s\n", nrn_version(1)); Fprintf(stderr, "%s\n", banner); IGNORE(fflush(stderr)); @@ -309,9 +310,9 @@ void hoc_last_init(void) memb_list = (Memb_list*)ecalloc(memb_func_size_, sizeof(Memb_list)); pointsym = (Symbol**)ecalloc(memb_func_size_, sizeof(Symbol*)); point_process = (Point_process**)ecalloc(memb_func_size_, sizeof(Point_process*)); - pnt_map = (char*)ecalloc(memb_func_size_, sizeof(char)); + pnt_map = static_cast(ecalloc(memb_func_size_, sizeof(char))); memb_func[1].alloc = cab_alloc; - nrn_pnt_template_ = (Template**)ecalloc(memb_func_size_, sizeof(Template*)); + nrn_pnt_template_ = (cTemplate**)ecalloc(memb_func_size_, sizeof(cTemplate*)); pnt_receive = (pnt_receive_t*)ecalloc(memb_func_size_, sizeof(pnt_receive_t)); pnt_receive_init = (pnt_receive_init_t*)ecalloc(memb_func_size_, sizeof(pnt_receive_init_t)); pnt_receive_size = (short*)ecalloc(memb_func_size_, sizeof(short)); @@ -457,8 +458,8 @@ void nrn_register_mech_common( memb_list = (Memb_list*)erealloc(memb_list, memb_func_size_*sizeof(Memb_list)); pointsym = (Symbol**)erealloc(pointsym, memb_func_size_*sizeof(Symbol*)); point_process = (Point_process**)erealloc(point_process, memb_func_size_*sizeof(Point_process*)); - pnt_map = (char*)erealloc(pnt_map, memb_func_size_*sizeof(char)); - nrn_pnt_template_ = (Template**)erealloc(nrn_pnt_template_, memb_func_size_*sizeof(Template*)); + pnt_map = static_cast(erealloc(pnt_map, memb_func_size_*sizeof(char))); + nrn_pnt_template_ = (cTemplate**)erealloc(nrn_pnt_template_, memb_func_size_*sizeof(cTemplate*)); pnt_receive = (pnt_receive_t*)erealloc(pnt_receive, memb_func_size_*sizeof(pnt_receive_t)); pnt_receive_init = (pnt_receive_init_t*)erealloc(pnt_receive_init, memb_func_size_*sizeof(pnt_receive_init_t)); pnt_receive_size = (short*)erealloc(pnt_receive_size, memb_func_size_*sizeof(short)); @@ -476,7 +477,7 @@ void nrn_register_mech_common( pnt_map[j] = 0; point_process[j] = (Point_process*)0; pointsym[j] = (Symbol*)0; - nrn_pnt_template_[j] = (Template*)0; + nrn_pnt_template_[j] = (cTemplate*)0; pnt_receive[j] = (pnt_receive_t)0; pnt_receive_init[j] = (pnt_receive_init_t)0; pnt_receive_size[j] = 0; @@ -499,29 +500,29 @@ void nrn_register_mech_common( memb_func[type].alloc = alloc; memb_func[type].state = stat; memb_func[type].initialize = initialize; - memb_func[type].destructor = (void*)0; + memb_func[type].destructor = nullptr; #if VECTORIZE memb_func[type].vectorized = vectorized ? 1:0; memb_func[type].thread_size_ = vectorized ? (vectorized - 1) : 0; - memb_func[type].thread_mem_init_ = (void*)0; - memb_func[type].thread_cleanup_ = (void*)0; - memb_func[type].thread_table_check_ = (void*)0; - memb_func[type]._update_ion_pointers = (void*)0; + memb_func[type].thread_mem_init_ = nullptr; + memb_func[type].thread_cleanup_ = nullptr; + memb_func[type].thread_table_check_ = nullptr; + memb_func[type]._update_ion_pointers = nullptr; memb_func[type].is_point = 0; - memb_func[type].hoc_mech = (void*)0; - memb_func[type].setdata_ = (void*)0; + memb_func[type].hoc_mech = nullptr; + memb_func[type].setdata_ = nullptr; memb_func[type].dparam_semantics = (int*)0; memb_list[type].nodecount = 0; memb_list[type]._thread = (Datum*)0; memb_order_[type] = type; #endif #if CVODE - memb_func[type].ode_count = (void*)0; - memb_func[type].ode_map = (void*)0; - memb_func[type].ode_spec = (void*)0; - memb_func[type].ode_matsol = (void*)0; - memb_func[type].ode_synonym = (void*)0; - memb_func[type].singchan_ = (void*)0; + memb_func[type].ode_count = nullptr; + memb_func[type].ode_map = nullptr; + memb_func[type].ode_spec = nullptr; + memb_func[type].ode_matsol = nullptr; + memb_func[type].ode_synonym = nullptr; + memb_func[type].singchan_ = nullptr; #endif /* as of 5.2 nmodl translates so that the version string is the first string in m. This allows the neuron application @@ -613,7 +614,7 @@ IGNORE(fprintf(stderr, CHKmes, buf)); s2 = hoc_install(buf, RANGEVAR, 0.0, &hoc_symlist); s2->subtype = modltype; s2->u.rng.type = type; - s2->public = 1; + s2->cpublic = 1; if (modltype == NRNPOINTER) { /* not in p array */ s2->u.rng.index = nrnpointerindex; } else { @@ -644,7 +645,7 @@ IGNORE(fprintf(stderr, CHKmes, buf)); n_memb_func = type; } -void register_mech( +extern "C" void register_mech( const char **m, Pvmp alloc, Pvmi cur, @@ -662,7 +663,7 @@ void register_mech( } } -void nrn_writes_conc(int type, int unused) { +extern "C" void nrn_writes_conc(int type, int unused) { static int lastion = EXTRACELL+1; int i; for (i=n_memb_func - 2; i >= lastion; --i) { @@ -677,7 +678,7 @@ void nrn_writes_conc(int type, int unused) { } } -void hoc_register_prop_size(int type, int psize, int dpsize) { +extern "C" void hoc_register_prop_size(int type, int psize, int dpsize) { nrn_prop_param_size_[type] = psize; nrn_prop_dparam_size_[type] = dpsize; if (memb_func[type].dparam_semantics) { @@ -688,7 +689,7 @@ void hoc_register_prop_size(int type, int psize, int dpsize) { memb_func[type].dparam_semantics = (int*)ecalloc(dpsize, sizeof(int)); } } -void hoc_register_dparam_semantics(int type, int ix, const char* name) { +extern "C" void hoc_register_dparam_semantics(int type, int ix, const char* name) { /* only interested in area, iontype, cvode_ieq, netsend, pointer, pntproc, bbcorepointer, watch, diam, fornetcon, @@ -735,7 +736,7 @@ assert(0); } #if CVODE -void hoc_register_cvode( +extern "C" void hoc_register_cvode( int i, nrn_ode_count_t cnt, nrn_ode_map_t map, @@ -747,18 +748,18 @@ void hoc_register_cvode( memb_func[i].ode_spec = spec; memb_func[i].ode_matsol = matsol; } -void hoc_register_synonym(int i, void (*syn)(int, double**, Datum**)){ +extern "C" void hoc_register_synonym(int i, void (*syn)(int, double**, Datum**)){ memb_func[i].ode_synonym = syn; } #endif -void register_destructor(Pvmp d) { +extern "C" void register_destructor(Pvmp d) { memb_func[n_memb_func - 1].destructor = d; } int point_reg_helper(Symbol* s2) { pointsym[pointtype] = s2; - s2->public = 0; + s2->cpublic = 0; pnt_map[n_memb_func-1] = pointtype; memb_func[n_memb_func-1].is_point = 1; if (nrnpy_reg_mech_p_) { @@ -767,7 +768,17 @@ int point_reg_helper(Symbol* s2) { return pointtype++; } -int point_register_mech( +extern void class2oc(const char *, + void *(*cons)(Object *), + void (*destruct)(void *), + Member_func *, + int (*checkpoint)(void **), + Member_ret_obj_func *, + Member_ret_str_func * +); + + +extern "C" int point_register_mech( const char **m, Pvmp alloc, Pvmi cur, @@ -781,20 +792,19 @@ int point_register_mech( void (*destructor)(void*), Member_func* fmember ){ - extern void steer_point_process(); + extern void steer_point_process(void* v); Symlist* sl; Symbol* s, *s2; - void class2oc(); nrn_load_name_check(m[1]); - class2oc(m[1], constructor, destructor, fmember, (void*)0, (void*)0, (void*)0); + class2oc(m[1], constructor, destructor, fmember, nullptr, nullptr, nullptr); s = hoc_lookup(m[1]); sl = hoc_symlist; - hoc_symlist = s->u.template->symtable; - s->u.template->steer = steer_point_process; - s->u.template->is_point_ = pointtype; + hoc_symlist = s->u.ctemplate->symtable; + s->u.ctemplate->steer = steer_point_process; + s->u.ctemplate->is_point_ = pointtype; nrn_register_mech_common(m, alloc, cur, jacob, stat, initialize, nrnpointerindex, vectorized); - nrn_pnt_template_[n_memb_func-1] = s->u.template; + nrn_pnt_template_[n_memb_func-1] = s->u.ctemplate; s2 = hoc_lookup(m[1]); hoc_symlist = sl; return point_reg_helper(s2); @@ -812,34 +822,34 @@ double* makevector(int nrows) #endif int _ninits; -void _modl_cleanup(void){} +extern "C" void _modl_cleanup(void){} #if 1 -void _modl_set_dt(double newdt) { +extern "C" void _modl_set_dt(double newdt) { dt = newdt; nrn_threads->_dt = newdt; } -void _modl_set_dt_thread(double newdt, NrnThread* nt) { +extern "C" void _modl_set_dt_thread(double newdt, NrnThread* nt) { nt->_dt = newdt; } -double _modl_get_dt_thread(NrnThread* nt) { +extern "C" double _modl_get_dt_thread(NrnThread* nt) { return nt->_dt; } #endif -int nrn_pointing(double* pd) { +extern "C" int nrn_pointing(double* pd) { return pd ? 1 : 0; } int state_discon_flag_ = 0; -void state_discontinuity(int i, double* pd, double d) { +extern "C" void state_discontinuity(int i, double* pd, double d) { if (state_discon_allowed_ && state_discon_flag_ == 0) { *pd = d; /*printf("state_discontinuity t=%g pd=%lx d=%g\n", t, (long)pd, d);*/ } } -void hoc_register_limits(int type, HocParmLimits* limits) +extern "C" void hoc_register_limits(int type, HocParmLimits* limits) { int i; Symbol* sym; @@ -850,7 +860,7 @@ void hoc_register_limits(int type, HocParmLimits* limits) t = hoc_lookup(memb_func[type].sym->name); sym = hoc_table_lookup( limits[i].name, - t->u.template->symtable + t->u.ctemplate->symtable ); } if (!sym) { @@ -860,7 +870,7 @@ void hoc_register_limits(int type, HocParmLimits* limits) } } -void hoc_register_units(int type, HocParmUnits* units) +extern "C" void hoc_register_units(int type, HocParmUnits* units) { int i; Symbol* sym; @@ -871,7 +881,7 @@ void hoc_register_units(int type, HocParmUnits* units) t = hoc_lookup(memb_func[type].sym->name); sym = hoc_table_lookup( units[i].name, - t->u.template->symtable + t->u.ctemplate->symtable ); } if (!sym) { @@ -884,7 +894,7 @@ void hoc_register_units(int type, HocParmUnits* units) void hoc_reg_ba(int mt, nrn_bamech_t f, int type) { BAMech* bam; - switch (type) { /* see bablk in src/nmodl/nocpout.c */ + switch (type) { /* see bablk in src/nmodl/nocpout.cpp */ case 11: type = BEFORE_BREAKPOINT; break; case 22: type = AFTER_SOLVE; break; case 13: type = BEFORE_INITIAL; break; @@ -901,7 +911,7 @@ printf("before-after processing type %d for %s not implemented\n", type, memb_fu bamech_[type] = bam; } -void _cvode_abstol(Symbol** s, double* tol, int i) +extern "C" void _cvode_abstol(Symbol** s, double* tol, int i) { #if CVODE if (s && s[i]->extra) { @@ -914,7 +924,9 @@ void _cvode_abstol(Symbol** s, double* tol, int i) #endif } -void hoc_register_tolerance(int type, HocStateTolerance* tol, Symbol*** stol) +extern Node** node_construct(int); + +extern "C" void hoc_register_tolerance(int type, HocStateTolerance* tol, Symbol*** stol) { #if CVODE int i; @@ -926,7 +938,7 @@ void hoc_register_tolerance(int type, HocStateTolerance* tol, Symbol*** stol) t = hoc_lookup(memb_func[type].sym->name); sym = hoc_table_lookup( tol[i].name, - t->u.template->symtable + t->u.ctemplate->symtable ); }else{ sym = hoc_lookup(tol[i].name); @@ -939,7 +951,6 @@ void hoc_register_tolerance(int type, HocStateTolerance* tol, Symbol*** stol) double **pv; Node** pnode; Prop* p; - extern Node** node_construct(); int i, j, k, n, na, index=0; n = (*memb_func[type].ode_count)(type); @@ -988,7 +999,7 @@ p = prop_alloc(&(pnode[0]->prop), type, pnode[0]); /* this and any ions */ #endif } -void _nrn_thread_reg(int i, int cons, void(*f)(Datum*)) { +extern "C" void _nrn_thread_reg(int i, int cons, void(*f)(Datum*)) { if (cons == 1) { memb_func[i].thread_mem_init_ = f; }else if (cons == 0) { @@ -998,11 +1009,11 @@ void _nrn_thread_reg(int i, int cons, void(*f)(Datum*)) { } } -void _nrn_thread_table_reg(int i, void(*f)(double*, Datum*, Datum*, void*, int)) { +extern "C" void _nrn_thread_table_reg(int i, void(*f)(double*, Datum*, Datum*, void*, int)) { memb_func[i].thread_table_check_ = f; } -void _nrn_setdata_reg(int i, void(*call)(Prop*)) { +extern "C" void _nrn_setdata_reg(int i, void(*call)(Prop*)) { memb_func[i].setdata_ = call; } /* there is some question about the _extcall_thread variables, if any. */ @@ -1024,3 +1035,6 @@ void nrnunit_use_legacy() { } hoc_retpushx((double)_nrnunit_use_legacy_); } +//#if defined(__cplusplus) +//} +//#endif diff --git a/src/nrnoc/ldifus.c b/src/nrnoc/ldifus.cpp similarity index 98% rename from src/nrnoc/ldifus.c rename to src/nrnoc/ldifus.cpp index 80eec08e77..80c932d2c1 100755 --- a/src/nrnoc/ldifus.c +++ b/src/nrnoc/ldifus.cpp @@ -9,11 +9,12 @@ #include "nrniv_mf.h" #include "parse.h" + #define nt_t nrn_threads->_t #define nt_dt nrn_threads->_dt -extern int diam_change_cnt; -extern int structure_change_cnt; +extern "C" int diam_change_cnt; +extern "C" int structure_change_cnt; typedef struct LongDifus { int dchange; @@ -59,7 +60,7 @@ void mac_difusfunc(ldifusfunc2_t* f, int m, ldifusfunc3_t diffunc, void** v, int #endif -void nrn_tree_solve(double* a, double* d, double* b, double* rhs, int* pindex, int n) { +extern "C" void nrn_tree_solve(double* a, double* d, double* b, double* rhs, int* pindex, int n) { /* treesolver @@ -283,14 +284,14 @@ static void overall_setup(int m, ldifusfunc3_t diffunc, void** v, int ai, int si LongDifusThreadData** ppldtd = (LongDifusThreadData**)v; LongDifusThreadData* ldtd = *ppldtd; if (ldtd) { /* free the whole thing */ - free((char*)ldtd->ml); + free(ldtd->ml); for (i=0; i < ldtd->nthread; ++i) { if (ldtd->ldifus[i]) { longdifusfree(ldtd->ldifus + i); } } - free((char*)ldtd->ldifus); - free((char*)ldtd); + free(ldtd->ldifus); + free(ldtd); *ppldtd = (LongDifusThreadData*)0; } /* new overall space */ @@ -540,4 +541,3 @@ for (i=0; i < n; ++i) { double a,b; } } - diff --git a/src/nrnoc/membdef.h b/src/nrnoc/membdef.h index ea134e7646..ccb3a3bb03 100755 --- a/src/nrnoc/membdef.h +++ b/src/nrnoc/membdef.h @@ -29,7 +29,7 @@ #define SELF_CON_FLAG (int)2 /* Allow for self connections (fcon) */ #define CON_TYPE_FLAG (int)3 /* Stimulus type (fcon) */ -/* used by parameter dump when dump_flag == 1. (see pdump.c) */ +/* used by parameter dump when dump_flag == 1. (see pdump.cpp) */ #define LINE_LEN 78 /* line length */ #define IFSEC_INDENT 4 /* how far to indent ifsec */ #define MECH_INDENT 22 /* how far from begin of line to indent mechs */ diff --git a/src/nrnoc/membfunc.h b/src/nrnoc/membfunc.h index 3d4b38823d..56fdc796c6 100755 --- a/src/nrnoc/membfunc.h +++ b/src/nrnoc/membfunc.h @@ -5,6 +5,12 @@ extern "C" { #endif +extern void hoc_register_prop_size(int type, int psize, int dpsize); + +#if defined(__cplusplus) +} +#endif + #include "nrnoc_ml.h" typedef Datum *(*Pfrpdat)(); @@ -61,7 +67,7 @@ typedef struct Memb_func { #define nrnocCONST 1 #define DEP 2 -#define STATE 3 /*See init.c and cabvars.h for order of nrnocCONST, DEP, and STATE */ +#define STATE 3 /*See init.cpp and cabvars.h for order of nrnocCONST, DEP, and STATE */ #define BEFORE_INITIAL 0 #define AFTER_INITIAL 1 @@ -80,7 +86,6 @@ extern Memb_func* memb_func; extern int n_memb_func; extern int* nrn_prop_param_size_; extern int* nrn_prop_dparam_size_; -extern void hoc_register_prop_size(int type, int psize, int dpsize); #if VECTORIZE extern Memb_list* memb_list; @@ -94,8 +99,4 @@ pointers which connect variables from other mechanisms via the _ppval array. #define _AMBIGUOUS 5 -#if defined(__cplusplus) -} -#endif - #endif /* nrn_memb_func_h */ diff --git a/src/nrnoc/method3.c b/src/nrnoc/method3.cpp similarity index 98% rename from src/nrnoc/method3.c rename to src/nrnoc/method3.cpp index e4b8a0d6da..d0d1249e46 100644 --- a/src/nrnoc/method3.c +++ b/src/nrnoc/method3.cpp @@ -1,7 +1,7 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/nrnoc/method3.c,v 1.5 1999/07/08 14:25:03 hines Exp */ +/* /local/src/master/nrn/src/nrnoc/method3.cpp,v 1.5 1999/07/08 14:25:03 hines Exp */ /* -method3.c,v +method3.cpp,v * Revision 1.5 1999/07/08 14:25:03 hines * Uniformly use section_length(sec) instead of sec->prop->dparam[2].val * and make sure it never returns <= 0 @@ -44,7 +44,7 @@ method3.c,v * No need to set diam_changed when Ra changed. * * Revision 3.35 92/10/27 12:09:50 hines - * list.c list.h moved from nrnoc to oc + * list.cpp list.h moved from nrnoc to oc * * Revision 3.21 92/10/08 10:24:42 hines * third order correct with _method3 = 3 and when more than 1 segment @@ -90,12 +90,14 @@ method3.c,v * Initial revision * */ -/* started from version 3.5 of treeset.c */ +/* started from version 3.5 of treeset.cpp */ #include #include #include "section.h" + + #if METHOD3 && VECTORIZE #include "membfunc.h" #include "neuron.h" @@ -132,7 +134,7 @@ int spatial_method() { When properties are allocated to nodes or freed, v_structure_change is set to 1. This means that the mechanism vectors need to be re-determined. */ -extern int v_structure_change; +extern "C" int v_structure_change; extern int v_node_count; extern Node** v_node; extern Node** v_parent; @@ -395,4 +397,6 @@ method3_connection_coef() /* setup a and b */ } } + #endif + diff --git a/src/nrnoc/multicore.c b/src/nrnoc/multicore.cpp similarity index 89% rename from src/nrnoc/multicore.c rename to src/nrnoc/multicore.cpp index 387faea20a..b33a8f6e1c 100644 --- a/src/nrnoc/multicore.c +++ b/src/nrnoc/multicore.cpp @@ -1,9 +1,10 @@ -/* included by treeset.c */ +/* included by treeset.cpp */ /*#include <../../nrnconf.h>*/ /*#include */ #include #include + /* Now that threads have taken over the actual_v, v_node, etc, it might be a good time to regularize the method of freeing, allocating, and @@ -81,7 +82,7 @@ static unsigned long t1_[BS][BSIZE], *t_[BS]; #endif static void* nulljob(NrnThread* nt) { - return (void*)0; + return nullptr; } int nrn_inthread_; @@ -210,7 +211,7 @@ pthread_mutex_t* _nmodlmutex; static pthread_mutex_t nrn_malloc_mutex_; static pthread_mutex_t* _nrn_malloc_mutex; -void nrn_malloc_lock() { +extern "C" void nrn_malloc_lock() { if (_nrn_malloc_mutex) { pthread_mutex_lock(_nrn_malloc_mutex); #if use_malloc_hook @@ -219,7 +220,7 @@ void nrn_malloc_lock() { } } -void nrn_malloc_unlock() { +extern "C" void nrn_malloc_unlock() { if (_nrn_malloc_mutex) { #if use_malloc_hook nrn_malloc_protected_ = 0; @@ -260,7 +261,7 @@ static void wait_for_workers() { pthread_mutex_unlock(mut + i); } #else - pthread_join(slave_threads[i], (void*)0); + pthread_join(slave_threads[i], nullptr); #endif } } @@ -280,7 +281,7 @@ static void send_job_to_slave(int i, void* (*job)(NrnThread*)) { pthread_cond_signal(cond + i); pthread_mutex_unlock(mut + i); #else - pthread_create(slave_threads + i, (void*)0, (void*(*)(void*))job, (void*)(nrn_threads + i)); + pthread_create(slave_threads + i, nullptr, (void*(*)(void*))job, (void*)(nrn_threads + i)); #endif } @@ -319,7 +320,7 @@ static void* slave_main(void* arg) { (*my_wc->job)(nrn_threads + my_wc->thread_id); BENCHADD(a2) }else{ - return (void*)0; + return nullptr; } my_wc->flag = 0; pthread_cond_signal(my_cond); @@ -337,7 +338,7 @@ static void* slave_main(void* arg) { BENCHADD(a2) }else{ pthread_mutex_unlock(my_mut); - return (void*)0; + return nullptr; } pthread_mutex_lock(my_mut); my_wc->flag = 0; @@ -345,7 +346,7 @@ static void* slave_main(void* arg) { pthread_mutex_unlock(my_mut); } } - return (void*)0; + return nullptr; } static void threads_create_pthread(){ @@ -367,9 +368,9 @@ static void threads_create_pthread(){ for (i=1; i < nrn_nthread; ++i) { wc[i].flag = 0; wc[i].thread_id = i; - pthread_cond_init(cond + i, (void*)0); - pthread_mutex_init(mut + i, (void*)0); - pthread_create(slave_threads + i, (void*)0, slave_main, (void*)(wc+i)); + pthread_cond_init(cond + i, nullptr); + pthread_mutex_init(mut + i, nullptr); + pthread_create(slave_threads + i, nullptr, slave_main, (void*)(wc+i)); } #else slave_threads = (pthread_t *)emalloc(sizeof(pthread_t)*nrn_nthread); @@ -377,15 +378,15 @@ static void threads_create_pthread(){ if (!_interpreter_lock) { interpreter_locked = 0; _interpreter_lock = &interpreter_lock_; - pthread_mutex_init(_interpreter_lock, (void*)0); + pthread_mutex_init(_interpreter_lock, nullptr); } if (!_nmodlmutex) { _nmodlmutex = &nmodlmutex_; - pthread_mutex_init(_nmodlmutex, (void*)0); + pthread_mutex_init(_nmodlmutex, nullptr); } if (!_nrn_malloc_mutex) { _nrn_malloc_mutex = &nrn_malloc_mutex_; - pthread_mutex_init(_nrn_malloc_mutex, (void*)0); + pthread_mutex_init(_nrn_malloc_mutex, nullptr); } nrn_thread_parallel_ = 1; }else{ @@ -403,7 +404,7 @@ static void threads_free_pthread(){ wc[i].flag = -1; pthread_cond_signal(cond + i); pthread_mutex_unlock(mut + i); - pthread_join(slave_threads[i], (void*)0); + pthread_join(slave_threads[i], nullptr); pthread_cond_destroy(cond + i); pthread_mutex_destroy(mut + i); } @@ -438,8 +439,8 @@ static void threads_free_pthread(){ #else /* USE_PTHREAD */ -void nrn_malloc_lock() {} -void nrn_malloc_unlock() {} +extern "C" void nrn_malloc_lock() {} +extern "C" void nrn_malloc_unlock() {} static void threads_create_pthread(){ nrn_thread_parallel_ = 0; @@ -485,74 +486,75 @@ void nrn_thread_stat() { #endif /*BENCHMARKING*/ } + void nrn_threads_create(int n, int parallel) { - int i, j; - NrnThread* nt; - if (nrn_nthread != n) { + int i, j; + NrnThread *nt; + if (nrn_nthread != n) { /*printf("sizeof(NrnThread)=%d sizeof(Memb_list)=%d\n", sizeof(NrnThread), sizeof(Memb_list));*/ - threads_free_pthread(); - nrn_threads_free(); - for (i = 0; i < nrn_nthread; ++i) { - nt = nrn_threads + i; - if (nt->userpart) { - hoc_obj_unref(nt->userpart); - } - } - free((char*)nrn_threads); + threads_free_pthread(); + nrn_threads_free(); + for (i = 0; i < nrn_nthread; ++i) { + nt = nrn_threads + i; + if (nt->userpart) { + hoc_obj_unref(nt->userpart); + } + } + free((char *) nrn_threads); #if BENCHMARKING #endif - nrn_threads = (NrnThread*)0; - nrn_nthread = n; - if (n > 0) { - CACHELINE_ALLOC(nrn_threads, NrnThread, n); + nrn_threads = (NrnThread *) 0; + nrn_nthread = n; + if (n > 0) { + CACHELINE_ALLOC(nrn_threads, NrnThread, n); #if BENCHMARKING - for (i=0; i < BS; ++i) { - t_[i] = t1_[i]; - } + for (i=0; i < BS; ++i) { + t_[i] = t1_[i]; + } #endif - for (i=0; i < n; ++i) { - nt = nrn_threads + i; - nt->_t = 0.; - nt->_dt = -1e9; - nt->id = i; - nt->_stop_stepping = 0; - nt->tml = (NrnThreadMembList*)0; - nt->_ml_list = NULL; - nt->roots = (hoc_List*)0; - nt->userpart = 0; - nt->ncell = 0; - nt->end = 0; - for (j=0; j < BEFORE_AFTER_SIZE; ++j) { - nt->tbl[j] = (NrnThreadBAList*)0; - } - nt->_actual_rhs = 0; - nt->_actual_d = 0; - nt->_actual_a = 0; - nt->_actual_b = 0; - nt->_actual_v = 0; - nt->_actual_area = 0; - nt->_v_parent_index = 0; - nt->_v_node = 0; - nt->_v_parent = 0; - nt->_ecell_memb_list = 0; - nt->_ecell_child_cnt = 0; - nt->_ecell_children = NULL; - nt->_sp13mat = 0; - nt->_ctime = 0.0; - nt->_vcv = 0; - nt->_nrn_fast_imem = 0; - } - } - v_structure_change = 1; - diam_changed = 1; - } - if (nrn_thread_parallel_ != parallel) { - threads_free_pthread(); - if (parallel) { - threads_create_pthread(); - } - } - /*printf("nrn_threads_create %d %d\n", nrn_nthread, nrn_thread_parallel_);*/ + for (i = 0; i < n; ++i) { + nt = nrn_threads + i; + nt->_t = 0.; + nt->_dt = -1e9; + nt->id = i; + nt->_stop_stepping = 0; + nt->tml = (NrnThreadMembList *) 0; + nt->_ml_list = NULL; + nt->roots = (hoc_List *) 0; + nt->userpart = 0; + nt->ncell = 0; + nt->end = 0; + for (j = 0; j < BEFORE_AFTER_SIZE; ++j) { + nt->tbl[j] = (NrnThreadBAList *) 0; + } + nt->_actual_rhs = 0; + nt->_actual_d = 0; + nt->_actual_a = 0; + nt->_actual_b = 0; + nt->_actual_v = 0; + nt->_actual_area = 0; + nt->_v_parent_index = 0; + nt->_v_node = 0; + nt->_v_parent = 0; + nt->_ecell_memb_list = 0; + nt->_ecell_child_cnt = 0; + nt->_ecell_children = NULL; + nt->_sp13mat = 0; + nt->_ctime = 0.0; + nt->_vcv = 0; + nt->_nrn_fast_imem = 0; + } + } + v_structure_change = 1; + diam_changed = 1; + } + if (nrn_thread_parallel_ != parallel) { + threads_free_pthread(); + if (parallel) { + threads_create_pthread(); + } + } + /*printf("nrn_threads_create %d %d\n", nrn_nthread, nrn_thread_parallel_);*/ } /* @@ -588,7 +590,7 @@ static void fast_imem_alloc() { if (fast_imem_nthread_ != nrn_nthread) { fast_imem_free(); fast_imem_nthread_ = nrn_nthread; - fast_imem_size_ = ecalloc(nrn_nthread, sizeof(int)); + fast_imem_size_ = static_cast(ecalloc(nrn_nthread, sizeof(int))); fast_imem_ = (_nrn_Fast_Imem*)ecalloc(nrn_nthread, sizeof(_nrn_Fast_Imem)); } for (i=0; i < nrn_nthread; ++i) { @@ -1135,7 +1137,27 @@ void nrn_wait_for_threads() { #endif } -void nrn_thread_partition(); +void nrn_thread_partition(int it, Object* sl) { + NrnThread* nt; + assert(it >= 0 && it < nrn_nthread); + nt = nrn_threads + it; + if (nt->userpart == nullptr && nt->roots) { + hoc_l_freelist(&nt->roots); + } + if (sl) { + hoc_obj_ref(sl); + } + if (nt->userpart) { + hoc_obj_unref(nt->userpart); + nt->userpart = nullptr; + nt->roots = (hoc_List*)0; + } + if (sl) { + nt->userpart = sl; /* already reffed above */ + nt->roots = (hoc_List*)sl->u.this_pointer; + } + v_structure_change = 1; +} int nrn_user_partition() { int i, it, b, n; @@ -1145,9 +1167,9 @@ int nrn_user_partition() { Section* sec; NrnThread* nt; /* all one or all the other*/ - b = (nrn_threads[0].userpart != (Object*)0); + b = (nrn_threads[0].userpart != nullptr); for (it=1; it < nrn_nthread; ++it) { - if ((nrn_threads[it].userpart != (Object*)0) != b) { + if ((nrn_threads[it].userpart != nullptr) != b) { hoc_execerror("some threads have a user defined partition", "and some do not"); } } @@ -1161,7 +1183,7 @@ hoc_execerror("some threads have a user defined partition", "and some do not"); sec = hocSEC(qsec); if (!sec->prop) { for (i=0; i < nrn_nthread; ++i) { - nrn_thread_partition(i, (Object*)0); + nrn_thread_partition(i, nullptr); } return 0; } @@ -1199,28 +1221,6 @@ sprintf(buf, "The total number of cells, %d, is different than the number of use return 1; } -void nrn_thread_partition(int it, Object* sl) { - NrnThread* nt; - assert(it >= 0 && it < nrn_nthread); - nt = nrn_threads + it; - if (nt->userpart == (Object*)0 && nt->roots) { - hoc_l_freelist(&nt->roots); - } - if (sl) { - hoc_obj_ref(sl); - } - if (nt->userpart) { - hoc_obj_unref(nt->userpart); - nt->userpart = (Object*)0; - nt->roots = (hoc_List*)0; - } - if (sl) { - nt->userpart = sl; /* already reffed above */ - nt->roots = (hoc_List*)sl->u.this_pointer; - } - v_structure_change = 1; -} - void nrn_use_busywait(int b) { #if USE_PTHREAD if (allow_busywait_ && nrn_thread_parallel_) { @@ -1261,7 +1261,7 @@ static void* waste(void* v) { } /* hoping it is not optimized away */ waste_ = j; - return (void*)0; + return nullptr; } #define _nt_ 32 @@ -1272,10 +1272,10 @@ static double trial(int ip) { th = (pthread_t*)ecalloc(ip, sizeof(pthread_t)); t = nrn_timeus(); for (i=0; i < ip; ++i) { - pthread_create(th + i, (void*)0, waste, (void*)100000000); + pthread_create(th + i, nullptr, waste, (void*)100000000); } for (i=0; i < ip; ++i) { - pthread_join(th[i], (void*)0); + pthread_join(th[i], nullptr); } t = nrn_timeus() - t; free((char*)th); @@ -1302,3 +1302,4 @@ int nrn_how_many_processors() { return 1; #endif } + diff --git a/src/nrnoc/multicore.h b/src/nrnoc/multicore.h index 9fe13ecce3..299a3dca90 100644 --- a/src/nrnoc/multicore.h +++ b/src/nrnoc/multicore.h @@ -29,9 +29,6 @@ actual_v, etc. #include -#if defined(__cplusplus) -extern "C" { -#endif typedef struct NrnThreadMembList{ /* patterned after CvMembList in cvodeobj.h */ struct NrnThreadMembList* next; @@ -106,8 +103,5 @@ extern void nrn_thread_table_check(); #define FOR_THREADS(nt) for (nt = nrn_threads; nt < nrn_threads + nrn_nthread; ++nt) -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/nrnoc/multisplit.h b/src/nrnoc/multisplit.h index a7bc2441de..8bfc68eaa3 100644 --- a/src/nrnoc/multisplit.h +++ b/src/nrnoc/multisplit.h @@ -28,9 +28,6 @@ parent. One of the present parents may or may not be its classical parent. #endif /* end comment */ -#if defined(__cplusplus) -extern "C" { -#endif #if 1 || PARANEURON extern double* nrn_classicalNodeA(Node* n); @@ -42,8 +39,5 @@ extern double* nrn_classicalNodeB(Node* n); #define ClassicalNODEB(n) NODEB(n) #endif -#if defined(__cplusplus) -} -#endif #endif /* multisplit_h */ diff --git a/src/nrnoc/neuron.h b/src/nrnoc/neuron.h index 3e4ebabc56..758821927c 100755 --- a/src/nrnoc/neuron.h +++ b/src/nrnoc/neuron.h @@ -1,5 +1,6 @@ #include "options.h" + #if METHOD3 extern int spatial_method(); #endif @@ -7,6 +8,7 @@ extern int spatial_method(); #if NEMO extern int neuron2nemo(), nemo2neuron(); #endif + extern void node_data(), disconnect(); extern void batch_run(), batch_save(); extern void pt3dclear(), pt3dadd(), n3d(), x3d(), y3d(), z3d(), arc3d(), diam3d(); @@ -21,6 +23,7 @@ extern void section_owner(); /* returns object that created section */ extern void make_mechanism(), make_pointprocess(); extern void nrnpython(); extern void nrnunit_use_legacy(); + #if !SEJNOWSKI extern void fsyn(), fsyng(), fsyni(); #endif @@ -33,34 +36,29 @@ extern int secondorder, diam_changed, nrn_shape_changed_, nrn_netrec_state_adjus extern double clamp_resist; extern double celsius; extern int stoprun; - extern void fit_praxis(), attr_praxis(), pval_praxis(), stop_praxis(); #if KEEP_NSEG_PARM extern void keep_nseg_parm(); #endif - extern void nrnallsectionmenu(), nrnallpointmenu(), nrnsecmenu(); extern void nrnglobalmechmenu(), nrnmechmenu(), nrnpointmenu(); - extern void this_section(), this_node(), parent_section(), parent_node(); extern void parent_connection(), section_orientation(); - #if SEJNOWSKI -extern void fdefault(); /* for sej_menu.c */ -extern void dump_vars(); /* sej_default.c */ -extern void update_id_info(), params(), private_menu(); /* sej_menu.c */ -extern void save_run(), save_params(), flush(), file_exist(); /* sej_menu.c */ -extern void sassign(), dassign(), setup_id_info(), clean_dir();/* sej_menu.c */ -extern void ftime(), fseed(), fran(), rand(), norm(), pois(); /* sej_ransyn.c */ -extern void syn_reset(), fsyn(), fsyn_set(), fsyng(), fsyni(); /* sej_synapse.c */ -extern void con_reset(), fcon(), fcon_set(), fcong(), fconi(); /* sej_connect.c */ -extern void top2(), dump(), dump_all(); /* sej_dump.c */ - +extern void fdefault(); /* for sej_menu.cpp */ +extern void dump_vars(); /* sej_default.cpp */ +extern void update_id_info(), params(), private_menu(); /* sej_menu.cpp */ +extern void save_run(), save_params(), flush(), file_exist(); /* sej_menu.cpp */ +extern void sassign(), dassign(), setup_id_info(), clean_dir();/* sej_menu.cpp */ +extern void ftime(), fseed(), fran(), rand(), norm(), pois(); /* sej_ransyn.cpp */ +extern void syn_reset(), fsyn(), fsyn_set(), fsyng(), fsyni(); /* sej_synapse.cpp */ +extern void con_reset(), fcon(), fcon_set(), fcong(), fconi(); /* sej_connect.cpp */ +extern void top2(), dump(), dump_all(); /* sej_dump.cpp */ extern void ptest(); /* non-initialized variables */ double ic; -double id_number, param_number; /* for sej_menu.c */ +double id_number, param_number; /* for sej_menu.cpp */ /* initialized variables */ double stop_time, nsteps, vrest; @@ -71,14 +69,16 @@ double fig_flag, timer_flag, stim_flag, view_flag; #endif #if FISHER -extern void rcsdiff_file(), rcs_version(), rcs_co_file(); /* rcs.c */ -extern void rcs_ci_file(), rcs_view_file(); /* rcs.c */ -extern void add_version_entry(), save_output_file(); /* sys.c */ -extern void answer_yes(), file_exist(), dassign(), sassign(); /* sys.c */ -extern void setup_id_info(), update_id_info(); /* sys.c */ +extern void rcsdiff_file(), rcs_version(), rcs_co_file(); /* rcs.cpp */ +extern void rcs_ci_file(), rcs_view_file(); /* rcs.cpp */ +extern void add_version_entry(), save_output_file(); /* sys.cpp */ +extern void answer_yes(), file_exist(), dassign(), sassign(); /* sys.cpp */ +extern void setup_id_info(), update_id_info(); /* sys.cpp */ /* non-initialized variables */ #if !SEJNOWSKI -double id_number; /* sys.c */ +double id_number; /* sys.cpp */ #endif + #endif + diff --git a/src/nrnoc/nonvintblock.h b/src/nrnoc/nonvintblock.h index 151616d7f7..7d5bfb139a 100644 --- a/src/nrnoc/nonvintblock.h +++ b/src/nrnoc/nonvintblock.h @@ -1,9 +1,6 @@ #ifndef nonvintblock_h #define nonvintblock_h -#if defined(__cplusplus) -extern "C" { -#endif /* Interface for adding blocks of equations setup and solved in python @@ -21,7 +18,7 @@ The other uses can merely return 0. */ #if defined(nrnoc_fadvance_c) -/* define only in fadvance.c */ +/* define only in fadvance.cpp */ #define nonvintblock_extern /**/ #else /* declare everywhere else */ @@ -35,22 +32,22 @@ nonvintblock_extern int (*nrn_nonvint_block)(int method, int length, double* pd1 #define nonvint_block(method, size, pd1, pd2, tid) \ nrn_nonvint_block ? nrn_nonvint_block_helper(method, size, pd1, pd2, tid) : 0 -/* called near end of nrnoc/treeset.c:v_setup_vectors after structure_change_cnt is incremented. */ +/* called near end of nrnoc/treeset.cpp:v_setup_vectors after structure_change_cnt is incremented. */ #define nrn_nonvint_block_setup() nonvint_block(0, 0, 0, 0, 0) -/* called in nrnoc/fadvance.c:nrn_finitialize before mod file INITIAL blocks */ +/* called in nrnoc/fadvance.cpp:nrn_finitialize before mod file INITIAL blocks */ #define nrn_nonvint_block_init(tid) nonvint_block(1, 0, 0, 0, tid) -/* called at end of nrnoc/treeset.c:rhs and nrncvode/cvtrset.cpp:rhs */ +/* called at end of nrnoc/treeset.cpp:rhs and nrncvode/cvtrset.cpp:rhs */ #define nrn_nonvint_block_current(size, rhs, tid) nonvint_block(2, size, rhs, 0, tid) /*if any ionic membrane currents are generated, they subtract from NrnThread._actual_rhs*/ -/* called at end of nrnoc/treeset.c:lhs and nrncvode/cvtrset.cpp:lhs */ +/* called at end of nrnoc/treeset.cpp:lhs and nrncvode/cvtrset.cpp:lhs */ #define nrn_nonvint_block_conductance(size, d, tid) nonvint_block(3, size, d, 0, tid) /*if any ionic membrane currents are generated, di/dv adds to _actual_d */ -/* called at end of nrnoc/fadvance.c:nonvint */ +/* called at end of nrnoc/fadvance.cpp:nonvint */ #define nrn_nonvint_block_fixed_step_solve(tid) nonvint_block(4, 0, 0, 0, tid) /* returns the number of extra equations solved by cvode or ida */ @@ -74,8 +71,5 @@ nonvintblock_extern int (*nrn_nonvint_block)(int method, int length, double* pd1 /* multiply the existing values in y (cvode.atol()) with appropriate scale factors */ #define nrn_nonvint_block_ode_abstol(size, y, tid) nonvint_block(10, size, y, 0, tid) -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/nrnoc/nrn_ansi.h b/src/nrnoc/nrn_ansi.h index bc6c75ce89..2e8c7c9e35 100644 --- a/src/nrnoc/nrn_ansi.h +++ b/src/nrnoc/nrn_ansi.h @@ -3,6 +3,37 @@ #if defined(__cplusplus) extern "C" { +#endif + + //nocpout.cpp +extern void hoc_register_limits(int, HocParmLimits*); +extern void hoc_register_units(int, HocParmUnits*); +extern void hoc_register_dparam_semantics(int, int, const char*); +extern void add_nrn_fornetcons(int, int); +extern void hoc_register_tolerance(int, HocStateTolerance*, Symbol***); + +extern void oc_save_cabcode(int* a1, int* a2); +extern void oc_restore_cabcode(int* a1, int* a2); + +extern void modl_reg(void); + +// nrnmech stuff +extern void _nrn_free_fornetcon(void**); + + +// mod stuff +extern void _nrn_free_watch(Datum *, int, int); +extern void _nrn_watch_activate(Datum *, double(*)(Point_process *), int, Point_process *, int, double); +extern void hoc_reg_ba(int, nrn_bamech_t, int); +extern int nrn_pointing(double *); + +extern void nrn_pushsec(Section*); +extern void nrn_popsec(void); +extern Section* chk_access(void); + + +#if defined(__cplusplus) +} #endif extern int state_discon_allowed_; @@ -10,8 +41,6 @@ extern int section_object_seen; extern int nrn_isecstack(void); extern void nrn_secstack(int); -extern void oc_save_cabcode(int* a1, int* a2); -extern void oc_restore_cabcode(int* a1, int* a2); extern void new_sections(Object* ob, Symbol* sym, hoc_Item** pitm, int size); extern void cable_prop_assign(Symbol* sym, double* pd, int op); extern void nrn_parent_info(Section* s); @@ -44,9 +73,6 @@ extern void nrn_initcode(); extern int segment_limits(double*); extern void second_order_cur(NrnThread*); extern void hoc_register_dparam_size(int, int); -extern void hoc_register_limits(int, HocParmLimits*); -extern void hoc_register_units(int, HocParmUnits*); -extern void hoc_register_dparam_semantics(int, int, const char*); extern void setup_topology(void); extern int nrn_errno_check(int); extern void long_difus_solve(int method, NrnThread* nt); @@ -56,8 +82,7 @@ extern void ob_sec_access_push(hoc_Item*); extern void nrn_mk_prop_pools(int); extern void SectionList_reg(void); extern void SectionRef_reg(void); -extern void modl_reg(void); -extern void hoc_register_tolerance(int, HocStateTolerance*, Symbol***); + extern void hoc_symbol_tolerance(Symbol*, double); extern void node_destruct(Node**, int); extern void nrn_sec_ref(Section**, Section*); @@ -78,12 +103,7 @@ extern void nrn_multisplit_ptr_update(void); extern void nrn_cache_prop_realloc(); extern void nrn_use_daspk(int); extern void nrn_update_ps2nt(void); -extern void _nrn_free_fornetcon(void**); -extern void add_nrn_fornetcons(int, int); -extern void _nrn_free_watch(Datum*, int, int); -extern void _nrn_watch_activate(Datum*, double(*)(Point_process*), int, Point_process*, int, double); -extern void hoc_reg_ba(int, nrn_bamech_t, int); -extern int nrn_pointing(double*); + extern void activstim_rhs(void); extern void activclamp_rhs(void); @@ -99,9 +119,6 @@ extern void section_ref(Section*); extern void section_unref(Section*); extern const char* secname(Section*); extern const char* nrn_sec2pysecname(Section*); -extern void nrn_pushsec(Section*); -extern void nrn_popsec(void); -extern Section* chk_access(void); extern void nrn_rangeconst(Section*, Symbol*, double* value, int op); extern Prop* nrn_mechanism(int type, Node*); extern int nrn_exists(Symbol*, Node*); @@ -142,8 +159,4 @@ extern void stor_pt3d(Section*, double x, double y, double z, double d); extern int nrn_netrec_state_adjust; extern int nrn_sparse_partrans; -#if defined(__cplusplus) -} -#endif - #endif diff --git a/src/nrnoc/nrncvode.h b/src/nrnoc/nrncvode.h index 8415ea1a60..fce24a5e2d 100644 --- a/src/nrnoc/nrncvode.h +++ b/src/nrnoc/nrncvode.h @@ -1,23 +1,20 @@ #ifndef nrncvode_h #define nrncvode_h -#if defined(__cplusplus) -extern "C" { -#endif -extern void cvode_fadvance(double); +extern "C" void cvode_fadvance(double); extern void cvode_finitialize(double); extern void nrncvode_set_t(double); extern void deliver_net_events(NrnThread*); extern void nrn_deliver_events(NrnThread*); -extern void clear_event_queue(void); +extern "C" void clear_event_queue(void); extern void init_net_events(void); extern void nrn_record_init(void); extern void nrn_play_init(void); extern void fixed_record_continuous(NrnThread* nt); extern void fixed_play_continuous(NrnThread* nt); extern void nrn_solver_prepare(void); -extern void nrn_random_play(NrnThread*); +extern "C" void nrn_random_play(/*NrnThread**/); // TODO nrnthread fn? extern void nrn_daspk_init_step(double, double, int); extern void nrndae_init(void); extern void nrndae_update(void); @@ -26,8 +23,5 @@ extern void nrn_capacity_current(NrnThread* _nt, Memb_list* ml); extern void nrn_spike_exchange_init(void); extern void nrn_spike_exchange(NrnThread* nt); -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/nrnoc/nrndae_c.h b/src/nrnoc/nrndae_c.h index 7014278977..7c752f68a0 100644 --- a/src/nrnoc/nrndae_c.h +++ b/src/nrnoc/nrndae_c.h @@ -1,9 +1,6 @@ #ifndef nrndae_c_h #define nrndae_c_h -#if defined(__cplusplus) -extern "C" { -#endif extern void nrndae_alloc(void); extern int nrndae_extra_eqn_count(void); @@ -19,8 +16,5 @@ extern int nrndae_list_is_empty(void); extern int nrn_use_daspk_; -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/nrnoc/nrniv_mf.h b/src/nrnoc/nrniv_mf.h index 6d8ebda33f..357394f194 100644 --- a/src/nrnoc/nrniv_mf.h +++ b/src/nrnoc/nrniv_mf.h @@ -7,57 +7,27 @@ struct NrnThread; union Datum; -#if defined(__cplusplus) -extern "C" { -#endif - typedef double (*ldifusfunc3_t)(int, double*, Datum*, double*, double*, Datum*, NrnThread*); typedef void ldifusfunc2_t(int, ldifusfunc3_t, void**, int, int, int, NrnThread*); typedef void (*ldifusfunc_t)(ldifusfunc2_t, NrnThread*); typedef void (*pnt_receive_t)(Point_process*, double*, double); typedef void (*pnt_receive_init_t)(Point_process*, double*, double); -extern void register_mech(const char**, Pvmp, Pvmi, Pvmi, Pvmi, Pvmi, int, int); -extern int point_register_mech(const char**, Pvmp, Pvmi, Pvmi, Pvmi, Pvmi, int, int, - void*(*)(Object*), void(*)(void*), Member_func*); -extern void hoc_register_cvode(int, nrn_ode_count_t, nrn_ode_map_t, Pvmi, Pvmi); -extern void hoc_register_ldifus1(ldifusfunc_t); -extern int nrn_get_mechtype(const char*); -extern int v_structure_change; -extern void ion_reg(const char*, double); -extern Prop* need_memb(Symbol*); extern Prop* need_memb_cl(Symbol*,int*,int*); extern Prop* prop_alloc(Prop**, int, Node*); -extern void nrn_promote(Prop*, int, int); -extern void nrn_check_conc_write(Prop*, Prop*, int); -extern void nrn_writes_conc(int, int); -extern void nrn_wrote_conc(Symbol*, double*, int); + extern double nrn_ion_charge(Symbol*); -extern void nrn_update_ion_pointer(Symbol*, Datum*, int, int); -extern void* create_point_process(int, Object*); -extern void destroy_point_process(void*); -extern double has_loc_point(void*); -extern double get_loc_point_process(void*); -extern double loc_point_process(int, void*); -extern Prop* nrn_point_prop_; -extern Point_process* ob2pntproc(Object*); +#if defined(__cplusplus) +extern "C" { +#endif +extern Point_process *ob2pntproc(Object *); extern Point_process* ob2pntproc_0(Object*); -extern int at_time(NrnThread*, double); -extern void nrn_complain(double*); -extern int ifarg(int); -extern pnt_receive_t* pnt_receive; -extern pnt_receive_init_t* pnt_receive_init; -extern short* pnt_receive_size; -extern void add_nrn_artcell(int, int); -extern void add_nrn_has_net_event(int); -extern void set_seed(double); -extern void nrn_net_send(void**, double*, Point_process*, double, double); -extern void nrn_net_move(void**, Point_process*, double); -extern void nrn_net_event(Point_process*, double); -extern void artcell_net_send(void**, double*, Point_process*, double, double); -extern void artcell_net_move(void**, Point_process*, double); -extern void register_destructor(Pvmp); -extern void hoc_register_synonym(int, void(*)(int, double**, Datum**)); + + + + + + extern double* _getelm(int, int); extern double* _nrn_thread_getelm(void*, int, int); extern int sparse(void**, int, int*, int*, double*, double*, double, @@ -79,8 +49,55 @@ extern int _ss_derivimplicit(int, int, int*, int*, double*, double*, double, int(*)(), double**); extern int _ss_derivimplicit_thread(int, int*, int*, double*, int(*)(double*, union Datum*, union Datum*, struct NrnThread*), void*, void*, void*); + extern int euler_thread(int, int*, int*, double*, - int(*)(double*, union Datum*, union Datum*, struct NrnThread*), union Datum*, union Datum*, struct NrnThread*); + int(*)(double*, union Datum*, union Datum*, struct NrnThread*), union Datum*, union Datum*, struct NrnThread*); + +extern void register_mech(const char**, Pvmp, Pvmi, Pvmi, Pvmi, Pvmi, int, int); +extern int point_register_mech(const char**, Pvmp, Pvmi, Pvmi, Pvmi, Pvmi, int, int, + void*(*)(Object*), void(*)(void*), Member_func*); +extern int nrn_get_mechtype(const char*); +extern void nrn_writes_conc(int, int); +extern void add_nrn_has_net_event(int); +extern void hoc_register_cvode(int, nrn_ode_count_t, nrn_ode_map_t, Pvmi, Pvmi); +extern void hoc_register_synonym(int, void(*)(int, double**, Datum**)); +extern void register_destructor(Pvmp); +extern void ion_reg(const char*, double); +extern void nrn_promote(Prop*, int, int); +extern void add_nrn_artcell(int, int); +extern void hoc_register_ldifus1(ldifusfunc_t); +extern void nrn_check_conc_write(Prop*, Prop*, int); +extern void nrn_wrote_conc(Symbol*, double*, int); +extern void nrn_update_ion_pointer(Symbol*, Datum*, int, int); + +extern Prop* need_memb(Symbol*); + +extern void* create_point_process(int, Object*); +extern void destroy_point_process(void*); +extern double has_loc_point(void*); +extern double get_loc_point_process(void*); +extern double loc_point_process(int, void*); +extern Prop* nrn_point_prop_; + +extern int at_time(NrnThread*, double); + +extern void artcell_net_send(void**, double*, Point_process*, double, double); +extern void artcell_net_move(void**, Point_process*, double); + +extern int ifarg(int); + +extern void nrn_complain(double*); + +extern void set_seed(double); +extern int v_structure_change; + +//nrnmech stuff +extern pnt_receive_t* pnt_receive; +extern pnt_receive_init_t* pnt_receive_init; +extern short* pnt_receive_size; +extern void nrn_net_send(void**, double*, Point_process*, double, double); +extern void nrn_net_event(Point_process*, double); +extern void nrn_net_move(void**, Point_process*, double); #if defined(__cplusplus) } diff --git a/src/nrnoc/nrnnemo.c b/src/nrnoc/nrnnemo.c deleted file mode 100644 index 2fdfa18612..0000000000 --- a/src/nrnoc/nrnnemo.c +++ /dev/null @@ -1,238 +0,0 @@ -#include <../../nrnconf.h> - -#include "section.h" - -#define OBSOLETE 1 - -#if !OBSOLETE -#include "membfunc.h" -#include "hocassrt.h" - -/* basic loop taken from topology() in solve.c */ -static FILE *fin, *fmark, *fdat; -static int inode; -static dashes(), file_func(), dat_head(); -#define MAXMARKS 32 -static long *marksec; -static printline(); - -extern int section_count; -extern Section** secorder; -#endif - -void nemo2neuron(void) -{ - hoc_retpushx(1.0); -} - -void neuron2nemo(void) -{ -#if OBSOLETE - hoc_execerror("neuron2nemo:", "implementation is obsolete"); -#else - short i, isec, imark; - extern int tree_changed; - char name[50]; - - if (tree_changed) { - setup_topology(); - } - Sprintf(name, "in/%s", gargstr(1)); - if ((fin = fopen(name, "w")) == (FILE *)0) { - hoc_execerror("Can't write to ", name); - } - Sprintf(name, "mark/%s", gargstr(1)); - if ((fmark = fopen(name, "w")) == (FILE *)0) { - hoc_execerror("Can't write to ", name); - } - Sprintf(name, "dat/%s", gargstr(1)); - if ((fdat = fopen(name, "w")) == (FILE *)0) { - hoc_execerror("Can't write to ", name); - } - dat_head(); - - /* set up the mark for every section */ - imark = 1; - marksec = (long *)ecalloc(section_count, sizeof(long)); - for (i=1; i < section_count; i++) { - isec = i; - if (marksec[isec]) { - marksec[i] = marksec[isec]; - }else{ - if (imark < MAXMARKS) { - marksec[i] = 1L << (imark++); - file_func(secorder[isec]); - } - } - } - Fprintf(fin, "/* created by NEURON */\n"); - inode = 0; - for (i=0; ichild, 0, 0., (double)(i*100)); - dashes(v_node[i]->child, 0., (double)(i*100), 0., 1); - } - free((char *)marksec); - fclose(fin); - fclose(fmark); -#endif - hoc_retpushx(1.0); -} - -#if !OBSOLETE -static dashes(Section* sec, double x, double y, double theta, int leftend) -{ - Section* ch; - int i, nrall, irall; - double cos(), sin(), xx, yy, ttheta, dx; - - dx = section_length(sec)/((double)sec->nnode - 1); - nrall = (int) sec->prop->dparam[4].val; - for (irall=0; irall < nrall; irall++) { - xx = x; yy=y; - ttheta = theta + (double)(nrall - 2*irall - 1)/(double)nrall; - for (i=0; innode - 1; i++) { - xx += dx*cos(ttheta); - yy += dx*sin(ttheta); - printline(sec, i, xx, yy); - } - for (i=sec->nnode - 1; i>=0; i--) { - if ((ch = sec->pnode[i]->child) != (Section*)0) { - if (i == sec->nnode - 1) { - dashes(ch, xx, yy, ttheta, 0); - }else{ - dashes(ch, xx, yy, ttheta+.5, 0); - } - } - if (i < sec->nnode - 1) { - xx -= dx*cos(ttheta); - yy -= dx*sin(ttheta); - } - } - if (leftend) { - ttheta = 3.14159 - .5; - } - if ((ch = sec->sibling) != (Section*)0) { - dashes(ch, x, y, ttheta+.5, 0); - } - } -} - -static double diamval(Node* nd) -{ - Prop *p; - - for (p = nd->prop; p; p = p->next) { - if (p->type == MORPHOLOGY) { - break; - } - } - assert(p); - return p->param[0]; -} - -static void printline(Section* sec, int i, double x, double y) -{ - char type; - int nb; - Section* csec; - Node *nd; - double d; - - ++inode; - assert(sec->nnode > 1); - type = 'C'; - nd = sec->pnode[i]; - d = diamval(nd); - nb = 0; - for (csec = nd->child; csec; csec = csec->sibling) { - nb += (int)csec->prop->dparam[4].val; - } - if (i == sec->nnode - 2) { - ++i; - nd = sec->pnode[i]; - for (csec = nd->child; csec; csec = csec->sibling) { - nb += (int)csec->prop->dparam[4].val; - } - } - if (i < sec->nnode - 2) { - nb++; - } - if (nb>2) { /*many branches*/ - type = 'B'; - x -= .001; - while (nb>2) { - fwrite((char *)&marksec[sec->order], sizeof(long), 1, fmark); - Fprintf(fin, "%d\t%c\t%g\t%g\t0\t%g\n", - inode++, type, (x += .001), y, d); - --nb; - } - } else if ( nb == 2) { /*one branch*/ - type = 'B'; - } else if (nb == 0) { - type = 'T'; - } - fwrite((char *)&marksec[sec->order], sizeof(long), 1, fmark); - Fprintf(fin, "%d\t%c\t%g\t%g\t0\t%g\n", inode, type, x, y, d); -} - -/* modified from nemo.c */ -static void file_func(Section* sec) -{ - int active; - Node *nd; - Prop *p; - Symbol *s, *hoc_lookup(); - static int hhtype = 0; - - if (!hhtype) { - s = hoc_lookup("HH"); - hhtype = s->subtype; - } - nd = sec->pnode[0]; - - active = 0; - for (p = nd->prop; p; p = p->next) { - if (p->type == hhtype) { - active = 1; - } - } - - assert(sec->prop->dparam[0].sym); - fprintf(fdat,"%s\n",sec->prop->dparam[0].sym->name); - fprintf(fdat,"^area %g\n",1.); - fprintf(fdat,"^Rm %g\n",1.); - fprintf(fdat,"^active %d\n",active); - fprintf(fdat,"^synapse %d\n",0); - fprintf(fdat,"^Erev %g\n",0.); - fprintf(fdat,"^gback %g\n",0.); - fprintf(fdat,"^gsyn %g\n",0.); - fprintf(fdat,"^tstart %g\n",0.); - fprintf(fdat,"^twidth %g\n",0.); -} - -static void dat_head(void) -{ - double Ra = 35.4; - - fprintf(fdat,"freq\n"); - fprintf(fdat,"%d %g %g\n",4, 1., 1000.); - - fprintf(fdat,"tran\n"); - fprintf(fdat,"%g %g\n", .1, 10.); - - fprintf(fdat,"elec\n"); - fprintf(fdat,"%g %g %g\n",1000., 1.e-6, Ra); - - fprintf(fdat,"syn\n"); - fprintf(fdat,"%g %g\n",30., -15.); - - fprintf(fdat,"hh\n"); - fprintf(fdat,"%g %g %g %g %g %g\n",1.,1.,1.,1.,1.,1.); - - fprintf(fdat,"batt\n"); - fprintf(fdat,"%g %g\n",115., -12.); - - fprintf(fdat,"%10d\n",9999); -} - -#endif diff --git a/src/nrnoc/nrnnemo.cpp b/src/nrnoc/nrnnemo.cpp new file mode 100644 index 0000000000..7600014a5e --- /dev/null +++ b/src/nrnoc/nrnnemo.cpp @@ -0,0 +1,239 @@ +#include <../../nrnconf.h> + +#include "section.h" + + + +#define OBSOLETE 1 + +#if !OBSOLETE +#include "membfunc.h" +#include "hocassrt.h" + +/* basic loop taken from topology() in solve.cpp */ +static FILE *fin, *fmark, *fdat; +static int inode; +static dashes(), file_func(), dat_head(); +#define MAXMARKS 32 +static long *marksec; +static printline(); + +extern int section_count; +extern Section** secorder; +#endif + +void nemo2neuron(void) { + hoc_retpushx(1.0); +} + +void neuron2nemo(void) { +#if OBSOLETE + hoc_execerror("neuron2nemo:", "implementation is obsolete"); +#else + short i, isec, imark; + extern int tree_changed; + char name[50]; + + if (tree_changed) { + setup_topology(); + } + Sprintf(name, "in/%s", gargstr(1)); + if ((fin = fopen(name, "w")) == (FILE *)0) { + hoc_execerror("Can't write to ", name); + } + Sprintf(name, "mark/%s", gargstr(1)); + if ((fmark = fopen(name, "w")) == (FILE *)0) { + hoc_execerror("Can't write to ", name); + } + Sprintf(name, "dat/%s", gargstr(1)); + if ((fdat = fopen(name, "w")) == (FILE *)0) { + hoc_execerror("Can't write to ", name); + } + dat_head(); + + /* set up the mark for every section */ + imark = 1; + marksec = (long *)ecalloc(section_count, sizeof(long)); + for (i=1; i < section_count; i++) { + isec = i; + if (marksec[isec]) { + marksec[i] = marksec[isec]; + }else{ + if (imark < MAXMARKS) { + marksec[i] = 1L << (imark++); + file_func(secorder[isec]); + } + } + } + Fprintf(fin, "/* created by NEURON */\n"); + inode = 0; + for (i=0; ichild, 0, 0., (double)(i*100)); + dashes(v_node[i]->child, 0., (double)(i*100), 0., 1); + } + free((char *)marksec); + fclose(fin); + fclose(fmark); +#endif + hoc_retpushx(1.0); +} + +#if !OBSOLETE +static dashes(Section* sec, double x, double y, double theta, int leftend) +{ + Section* ch; + int i, nrall, irall; + double cos(), sin(), xx, yy, ttheta, dx; + + dx = section_length(sec)/((double)sec->nnode - 1); + nrall = (int) sec->prop->dparam[4].val; + for (irall=0; irall < nrall; irall++) { + xx = x; yy=y; + ttheta = theta + (double)(nrall - 2*irall - 1)/(double)nrall; + for (i=0; innode - 1; i++) { + xx += dx*cos(ttheta); + yy += dx*sin(ttheta); + printline(sec, i, xx, yy); + } + for (i=sec->nnode - 1; i>=0; i--) { + if ((ch = sec->pnode[i]->child) != (Section*)0) { + if (i == sec->nnode - 1) { + dashes(ch, xx, yy, ttheta, 0); + }else{ + dashes(ch, xx, yy, ttheta+.5, 0); + } + } + if (i < sec->nnode - 1) { + xx -= dx*cos(ttheta); + yy -= dx*sin(ttheta); + } + } + if (leftend) { + ttheta = 3.14159 - .5; + } + if ((ch = sec->sibling) != (Section*)0) { + dashes(ch, x, y, ttheta+.5, 0); + } + } +} + +static double diamval(Node* nd) +{ + Prop *p; + + for (p = nd->prop; p; p = p->next) { + if (p->type == MORPHOLOGY) { + break; + } + } + assert(p); + return p->param[0]; +} + +static void printline(Section* sec, int i, double x, double y) +{ + char type; + int nb; + Section* csec; + Node *nd; + double d; + + ++inode; + assert(sec->nnode > 1); + type = 'C'; + nd = sec->pnode[i]; + d = diamval(nd); + nb = 0; + for (csec = nd->child; csec; csec = csec->sibling) { + nb += (int)csec->prop->dparam[4].val; + } + if (i == sec->nnode - 2) { + ++i; + nd = sec->pnode[i]; + for (csec = nd->child; csec; csec = csec->sibling) { + nb += (int)csec->prop->dparam[4].val; + } + } + if (i < sec->nnode - 2) { + nb++; + } + if (nb>2) { /*many branches*/ + type = 'B'; + x -= .001; + while (nb>2) { + fwrite((char *)&marksec[sec->order], sizeof(long), 1, fmark); + Fprintf(fin, "%d\t%c\t%g\t%g\t0\t%g\n", + inode++, type, (x += .001), y, d); + --nb; + } + } else if ( nb == 2) { /*one branch*/ + type = 'B'; + } else if (nb == 0) { + type = 'T'; + } + fwrite((char *)&marksec[sec->order], sizeof(long), 1, fmark); + Fprintf(fin, "%d\t%c\t%g\t%g\t0\t%g\n", inode, type, x, y, d); +} + +/* modified from nemo.cpp */ +static void file_func(Section* sec) +{ + int active; + Node *nd; + Prop *p; + Symbol *s, *hoc_lookup(); + static int hhtype = 0; + + if (!hhtype) { + s = hoc_lookup("HH"); + hhtype = s->subtype; + } + nd = sec->pnode[0]; + + active = 0; + for (p = nd->prop; p; p = p->next) { + if (p->type == hhtype) { + active = 1; + } + } + + assert(sec->prop->dparam[0].sym); + fprintf(fdat,"%s\n",sec->prop->dparam[0].sym->name); + fprintf(fdat,"^area %g\n",1.); + fprintf(fdat,"^Rm %g\n",1.); + fprintf(fdat,"^active %d\n",active); + fprintf(fdat,"^synapse %d\n",0); + fprintf(fdat,"^Erev %g\n",0.); + fprintf(fdat,"^gback %g\n",0.); + fprintf(fdat,"^gsyn %g\n",0.); + fprintf(fdat,"^tstart %g\n",0.); + fprintf(fdat,"^twidth %g\n",0.); +} + +static void dat_head(void) +{ + double Ra = 35.4; + + fprintf(fdat,"freq\n"); + fprintf(fdat,"%d %g %g\n",4, 1., 1000.); + + fprintf(fdat,"tran\n"); + fprintf(fdat,"%g %g\n", .1, 10.); + + fprintf(fdat,"elec\n"); + fprintf(fdat,"%g %g %g\n",1000., 1.e-6, Ra); + + fprintf(fdat,"syn\n"); + fprintf(fdat,"%g %g\n",30., -15.); + + fprintf(fdat,"hh\n"); + fprintf(fdat,"%g %g %g %g %g %g\n",1.,1.,1.,1.,1.,1.); + + fprintf(fdat,"batt\n"); + fprintf(fdat,"%g %g\n",115., -12.); + + fprintf(fdat,"%10d\n",9999); +} + +#endif + diff --git a/src/nrnoc/nrnnoiv.c b/src/nrnoc/nrnnoiv.c deleted file mode 100644 index 16134b8f69..0000000000 --- a/src/nrnoc/nrnnoiv.c +++ /dev/null @@ -1,120 +0,0 @@ -#include <../../nrnconf.h> -#include -#include "nrnredef.h" -#include "section.h" -#include "nrnmpiuse.h" -#include "nrndae_c.h" -#include "gui-redirect.h" - -extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); -extern double (*nrnpy_object_to_double_)(Object*); - -#define hoc_retpushx hoc_retpushx - -/* stubs for nrnoc. The actual functions are for interviews menus */ -void nrnallsectionmenu(){TRY_GUI_REDIRECT_DOUBLE("nrnallsectionmenu", NULL); hoc_retpushx(0);} -void nrnallpointmenu(){TRY_GUI_REDIRECT_DOUBLE("nrnallpointmenu", NULL); hoc_retpushx(0);} -void nrnsecmenu(){TRY_GUI_REDIRECT_DOUBLE("nrnsecmenu", NULL); hoc_retpushx(0);} -void nrnglobalmechmenu(){TRY_GUI_REDIRECT_DOUBLE("nrnglobalmechmenu", NULL); hoc_retpushx(0);} -void nrnmechmenu(){hoc_retpushx(0);} -void nrnpointmenu(){TRY_GUI_REDIRECT_DOUBLE("nrnpointmenu", NULL); hoc_retpushx(0);} -void make_mechanism(){hoc_retpushx(0);} -void make_pointprocess(){hoc_retpushx(0);} -void nrnpython() {hoc_retpushx(0);} -Section* nrnpy_pysecname2sec(const char* name) { return NULL; } -void nrnpy_pysecname2sec_add(Section* sec) {} -void nrnpy_pysecname2sec_remove(Section* sec) {} -void nrn_prcellstate(int gid, const char* suffix){} -/*ARGSUSED*/ -void hoc_construct_point(Object* ob, int i){} -void nrn_random_play(){} -void* nrn_random_arg(i) int i; { return (void*)0; } -double nrn_random_pick(void* r) { return 0.; } -int nrn_random_isran123(void* r, uint32_t* id1, uint32_t* id2, uint32_t* id3){ return 0.; } -void hoc_new_opoint(){} -int special_pnt_call(Object* ob, Symbol* sym, int narg){return 0;} -void bbs_handle(){} - -void nrndae_alloc(void){} -int nrndae_extra_eqn_count(void){return 0;} -void nrndae_init(void){} -void nrndae_rhs(void){} -void nrndae_lhs(void){} -void nrndae_dkmap(double** pv, double** pvdot){} -void nrndae_dkres(double* y, double* yprime, double* delta){} -void nrndae_dkpsol(double unused){} -void nrndae_update(void){} -int nrndae_list_is_empty(void){return 0;} - -void nrn_solver_prepare(){} -void nrn_fihexec(i) int i;{} -void nrn_deliver_events(tt) double tt;{} -void nrn_record_init(){} -void nrn_play_init(){} -void fixed_record_continuous(){} -void fixed_play_continuous(){} -void nrniv_recalc_ptrs(){} -void nrn_recalc_ptrvector(){} -void nrn_extra_scatter_gather(int direction, int tid) {} -void nrn_update_ion_pointer(int type, Datum* d, int i, int j) {} -void nrn_update_ps2nt(){} - -int at_time(NrnThread* nt, double te) { - double x = te - 1e-11; - if (x > (nt->_t - nt->_dt) && x <= nt->_t) { - return 1; - }else{ - return 0; - } -} - -void net_event(){hoc_execerror("net_event only available in nrniv", (char*)0);} -void net_send(){hoc_execerror("net_send only available in nrniv", (char*)0);} -void artcell_net_send(){hoc_execerror("net_send only available in nrniv", (char*)0);} -void net_move(){hoc_execerror("net_move only available in nrniv", (char*)0);} -void artcell_net_move(){hoc_execerror("net_move only available in nrniv", (char*)0);} -void nrn_use_daspk(i) int i; { } - -#if CVODE -void cvode_fadvance(t)double t;{} -void cvode_finitialize(double t0){} -void nrncvode_set_t(double tt) {} -void cvode_event(x) double x;{} -void clear_event_queue(){} -void init_net_events(){} -void deliver_net_events(){} -void hoc_reg_singlechan(){} -void _singlechan_declare(){} -void _nrn_single_react(){} -#endif - -#if defined(CYGWIN) -void* dll_lookup(s) char* s; {return 0;} -void* dll_load(v, s) void* v; char* s; {return 0;} -#endif - -void nrn_spike_exchange_init(){} -void nrn_spike_exchange(NrnThread* nt){} -void nrn_fake_fire(i,x,j)int i, j; double x;{} -void nrn_daq_ao() {} -void nrn_daq_ai() {} -void nrn_daq_scanstart(){} - -void nrn_multisplit_ptr_update(){} -void nrn_multisplit_bksub(){assert(0);} -void nrn_multisplit_reduce_solve(){assert(0);} -void nrn_multisplit_triang(){assert(0);} -#if 1 || PARANEURON -double* nrn_classicalNodeA(Node* n) {return (double*)0;} -double* nrn_classicalNodeB(Node* n) {return (double*)0;} -#endif -void* nrn_pool_create(long count, int itemsize){assert(0); return (void*)0;} -void nrn_pool_delete(void* pool){assert(0);} -void nrn_pool_freeall(void* pool){assert(0);} -void* nrn_pool_alloc(void* pool){assert(0); return (void*)0;} - -#if NRN_MUSIC -void nrnmusic_init(int* parg, char*** pargv){} -void nrnmusic_terminate(){} -#endif - diff --git a/src/nrnoc/nrnnoiv.cpp b/src/nrnoc/nrnnoiv.cpp new file mode 100644 index 0000000000..d89bc215a4 --- /dev/null +++ b/src/nrnoc/nrnnoiv.cpp @@ -0,0 +1,237 @@ +#include <../../nrnconf.h> +#include +#include "nrnredef.h" +#include "section.h" +#include "nrnmpiuse.h" +#include "nrndae_c.h" +#include "gui-redirect.h" + + +extern Object **(*nrnpy_gui_helper_)(const char *name, Object *obj); + +extern double (*nrnpy_object_to_double_)(Object *); + +#define hoc_retpushx hoc_retpushx + +/* stubs for nrnoc. The actual functions are for interviews menus */ +void nrnallsectionmenu() { + TRY_GUI_REDIRECT_DOUBLE("nrnallsectionmenu", NULL); + hoc_retpushx(0); +} + +void nrnallpointmenu() { + TRY_GUI_REDIRECT_DOUBLE("nrnallpointmenu", NULL); + hoc_retpushx(0); +} + +void nrnsecmenu() { + TRY_GUI_REDIRECT_DOUBLE("nrnsecmenu", NULL); + hoc_retpushx(0); +} + +void nrnglobalmechmenu() { + TRY_GUI_REDIRECT_DOUBLE("nrnglobalmechmenu", NULL); + hoc_retpushx(0); +} + +void nrnmechmenu() { hoc_retpushx(0); } + +void nrnpointmenu() { + TRY_GUI_REDIRECT_DOUBLE("nrnpointmenu", NULL); + hoc_retpushx(0); +} + +void make_mechanism() { hoc_retpushx(0); } + +void make_pointprocess() { hoc_retpushx(0); } + +void nrnpython() { hoc_retpushx(0); } + +Section *nrnpy_pysecname2sec(const char *name) { return NULL; } + +void nrnpy_pysecname2sec_add(Section *sec) {} + +void nrnpy_pysecname2sec_remove(Section *sec) {} + +void nrn_prcellstate(int gid, const char *suffix) {} + +/*ARGSUSED*/ +void hoc_construct_point(Object *ob, int i) {} + +extern "C" void nrn_random_play() {} + +extern "C" void *nrn_random_arg(int i) +{ +return nullptr; } + +extern "C" double nrn_random_pick(void *r) { return 0.; } + +extern "C" int nrn_random_isran123(void *r, uint32_t *id1, uint32_t *id2, uint32_t *id3) { return 0.; } + +void hoc_new_opoint() {} + +int special_pnt_call(Object *ob, Symbol *sym, int narg) { return 0; } + +void bbs_handle() {} + +void nrndae_alloc(void) {} + +int nrndae_extra_eqn_count(void) { return 0; } + +void nrndae_init(void) {} + +void nrndae_rhs(void) {} + +void nrndae_lhs(void) {} + +void nrndae_dkmap(double **pv, double **pvdot) {} + +void nrndae_dkres(double *y, double *yprime, double *delta) {} + +void nrndae_dkpsol(double unused) {} + +void nrndae_update(void) {} + +int nrndae_list_is_empty(void) { return 0; } + +void nrn_solver_prepare() {} + +void nrn_fihexec(i) +int i; +{ +} + +void nrn_deliver_events(tt) + +double tt; +{ +} + +void nrn_record_init() {} + +void nrn_play_init() {} + +void fixed_record_continuous() {} + +void fixed_play_continuous() {} + +void nrniv_recalc_ptrs() {} + +void nrn_recalc_ptrvector() {} + +void nrn_extra_scatter_gather(int direction, int tid) {} + +void nrn_update_ion_pointer(int type, Datum *d, int i, int j) {} + +void nrn_update_ps2nt() {} + +extern "C" int at_time(NrnThread *nt, double te) { + double x = te - 1e-11; + if (x > (nt->_t - nt->_dt) && x <= nt->_t) { + return 1; + } else { + return 0; + } +} + +extern "C" void net_event() { hoc_execerror("net_event only available in nrniv", (char *) 0); } + +extern "C" void net_send() { hoc_execerror("net_send only available in nrniv", (char *) 0); } + +void artcell_net_send() { hoc_execerror("net_send only available in nrniv", (char *) 0); } + +extern "C" void net_move() { hoc_execerror("net_move only available in nrniv", (char *) 0); } + +extern "C" void artcell_net_move() { hoc_execerror("net_move only available in nrniv", (char *) 0); } + +void nrn_use_daspk(i) +int i; +{ +} + +#if CVODE + +void cvode_fadvance(t) + +double t; +{ +} + +void cvode_finitialize(double t0) {} + +void nrncvode_set_t(double tt) {} + +void cvode_event(x) + +double x; +{ +} + +extern "C" void clear_event_queue() {} + +void init_net_events() {} + +void deliver_net_events() {} + +void hoc_reg_singlechan() {} + +void _singlechan_declare() {} + +void _nrn_single_react() {} + +#endif + +#if defined(CYGWIN) +void* dll_lookup(s) char* s; {return 0;} +void* dll_load(v, s) void* v; char* s; {return 0;} +#endif + +void nrn_spike_exchange_init() {} + +void nrn_spike_exchange(NrnThread *nt) {} + +extern "C" void nrn_fake_fire(int i, double x, int j) +{ +} + +void nrn_daq_ao() {} + +void nrn_daq_ai() {} + +void nrn_daq_scanstart() {} + +void nrn_multisplit_ptr_update() {} + +void nrn_multisplit_bksub() { assert(0); } + +void nrn_multisplit_reduce_solve() { assert(0); } + +void nrn_multisplit_triang() { assert(0); } + +#if 1 || PARANEURON + +double *nrn_classicalNodeA(Node *n) { return (double *) 0; } + +double *nrn_classicalNodeB(Node *n) { return (double *) 0; } + +#endif + +void *nrn_pool_create(long count, int itemsize) { + assert(0); + return nullptr; +} + +void nrn_pool_delete(void *pool) { assert(0); } + +void nrn_pool_freeall(void *pool) { assert(0); } + +void *nrn_pool_alloc(void *pool) { + assert(0); + return nullptr; +} + +#if NRN_MUSIC +void nrnmusic_init(int* parg, char*** pargv){} +void nrnmusic_terminate(){} +#endif + diff --git a/src/nrnoc/nrntimeout.c b/src/nrnoc/nrntimeout.c deleted file mode 100644 index 9d9da9f1f6..0000000000 --- a/src/nrnoc/nrntimeout.c +++ /dev/null @@ -1,83 +0,0 @@ -#include <../../nrnconf.h> -#include -#if NRNMPI -#if defined(HAVE_SETITIMER) && defined(HAVE_SIGACTION) - -#include -#include -#include -#include - -void (*nrntimeout_call)(); -static double told; -static struct itimerval value; -#if !defined(BLUEGENE) -static struct sigaction act, oact; -#endif - -#define NRNTIMEOUT_DEBUG 0 -#if NRNTIMEOUT_DEBUG -extern double nrn_time(); -static old_nrn_time; -#endif - -static void timed_out(int sig) { -#if NRNTIMEOUT_DEBUG -double z = nrn_time(); -printf("timed_out(%d) wall_elapse=%g told=%g t=%g\n", sig, z-old_nrn_time, told, nrn_threads->_t); -old_nrn_time = z; -#endif - if (nrn_threads->_t == told) { /* nothing has been accomplished since last signal*/ - printf("nrn_timeout t=%g\n", nrn_threads->_t); - if (nrntimeout_call) { - (*nrntimeout_call)(); - } - nrnmpi_abort(0); - } - told = nrn_threads->_t; -} - -void nrn_timeout(int seconds) { - if (nrnmpi_myid != 0) { return; } -#if NRNTIMEOUT_DEBUG -printf("nrn_timeout(%d) t=%g\n", seconds, nrn_threads->_t); -old_nrn_time = nrn_time(); -#endif -#if BLUEGENE - if (seconds) { - told = nrn_threads->_t; - signal(SIGALRM, timed_out); - }else{ - signal(SIGALRM, SIG_DFL); - } -#else - if (seconds) { - told = nrn_threads->_t; - act.sa_handler = timed_out; - act.sa_flags = SA_RESTART; - if(sigaction(SIGALRM, &act, &oact)) { - printf("sigaction failed\n"); - nrnmpi_abort(0); - } - }else{ - sigaction(SIGALRM, &oact, (struct sigaction*)0); - } -#endif - value.it_interval.tv_sec = seconds; - value.it_interval.tv_usec = 0; - value.it_value.tv_sec = seconds; - value.it_value.tv_usec = 0; - if(setitimer(ITIMER_REAL, &value, (struct itimerval*)0)) { - printf("setitimer failed\n"); - nrnmpi_abort(0); - } - -} - -#else - -void nrn_timeout(int seconds) { } - -#endif /* not HAVE_SETITIMER */ - -#endif /*NRNMPI*/ diff --git a/src/nrnoc/nrntimeout.cpp b/src/nrnoc/nrntimeout.cpp new file mode 100644 index 0000000000..f7f1289b18 --- /dev/null +++ b/src/nrnoc/nrntimeout.cpp @@ -0,0 +1,86 @@ +#include <../../nrnconf.h> +#include + + +#if NRNMPI +#if defined(HAVE_SETITIMER) && defined(HAVE_SIGACTION) + +#include +#include +#include +#include + +void (*nrntimeout_call)(); +static double told; +static struct itimerval value; +#if !defined(BLUEGENE) +static struct sigaction act, oact; +#endif + +#define NRNTIMEOUT_DEBUG 0 +#if NRNTIMEOUT_DEBUG +extern double nrn_time(); +static old_nrn_time; +#endif + +static void timed_out(int sig) { +#if NRNTIMEOUT_DEBUG +double z = nrn_time(); +printf("timed_out(%d) wall_elapse=%g told=%g t=%g\n", sig, z-old_nrn_time, told, nrn_threads->_t); +old_nrn_time = z; +#endif + if (nrn_threads->_t == told) { /* nothing has been accomplished since last signal*/ + printf("nrn_timeout t=%g\n", nrn_threads->_t); + if (nrntimeout_call) { + (*nrntimeout_call)(); + } + nrnmpi_abort(0); + } + told = nrn_threads->_t; +} + +void nrn_timeout(int seconds) { + if (nrnmpi_myid != 0) { return; } +#if NRNTIMEOUT_DEBUG +printf("nrn_timeout(%d) t=%g\n", seconds, nrn_threads->_t); +old_nrn_time = nrn_time(); +#endif +#if BLUEGENE + if (seconds) { + told = nrn_threads->_t; + signal(SIGALRM, timed_out); + }else{ + signal(SIGALRM, SIG_DFL); + } +#else + if (seconds) { + told = nrn_threads->_t; + act.sa_handler = timed_out; + act.sa_flags = SA_RESTART; + if(sigaction(SIGALRM, &act, &oact)) { + printf("sigaction failed\n"); + nrnmpi_abort(0); + } + }else{ + sigaction(SIGALRM, &oact, (struct sigaction*)0); + } +#endif + value.it_interval.tv_sec = seconds; + value.it_interval.tv_usec = 0; + value.it_value.tv_sec = seconds; + value.it_value.tv_usec = 0; + if(setitimer(ITIMER_REAL, &value, (struct itimerval*)0)) { + printf("setitimer failed\n"); + nrnmpi_abort(0); + } + +} + +#else + +void nrn_timeout(int seconds) { } + +#endif /* not HAVE_SETITIMER */ + +#endif /*NRNMPI*/ + diff --git a/src/nrnoc/nrnversion.c b/src/nrnoc/nrnversion.c deleted file mode 100755 index b316fc7759..0000000000 --- a/src/nrnoc/nrnversion.c +++ /dev/null @@ -1,82 +0,0 @@ -#include <../../nrnconf.h> -#include -#include -#include -#include -#include -#include -#include "nrnassrt.h" - -extern int nrn_global_argc; -extern char** nrn_global_argv; - -extern int nrn_main_launch; /* 1 if nrniv, 2 if python, 0 if unknownn */ - -static char buf[1024]; -static char* sarg = 0; -static char configargs[] = NRN_CONFIG_ARGS; - -#if !defined(GIT_BRANCH) -#define GIT_DATE "2018-08-24" -#define GIT_BRANCH "unknown" -#define GIT_CHANGESET "d3ead4a+" -#define GIT_DESCRIBE "7.6.2-2-gd3ead4a+" -#endif - -char* nrn_version(int i) { - char head[1024]; - char *cp; - int b; - buf[0] = '\0'; - if (strncmp(GIT_BRANCH, "Release", 7) == 0) - { - sprintf(head, "%s (%s)", GIT_BRANCH, GIT_CHANGESET); - }else{ - sprintf(head, "VERSION %s %s (%s)", - GIT_DESCRIBE, - GIT_BRANCH, - GIT_CHANGESET); - } - if (i == 0) - { - sprintf(buf, "%s", PACKAGE_VERSION); - }else if (i == 2) { - sprintf(buf, "%s", head); - }else if (i == 3) { - sprintf(buf, "%s", GIT_CHANGESET); - }else if (i == 4) { - sprintf(buf, "%s", GIT_DATE); - }else if (i == 5) { - sprintf(buf, "%s", GIT_DESCRIBE); - }else if (i == 6) { - return configargs; - }else if (i == 7) { - int j, size; - if (!sarg) - { - char* c; - int size = 0; - for (j=0; j < nrn_global_argc; ++j) - { - size += strlen(nrn_global_argv[j]) + 1; - } - sarg = (char*)calloc(size+1, sizeof(char)); - c = sarg; - for (j=0; j < nrn_global_argc; ++j) - { - sprintf(c, "%s%s", j?" ":"", nrn_global_argv[j]); - c = c + strlen(c); - } - } - return sarg; - }else if (i == 8) { - sprintf(buf, "%s", NRNHOST); - }else if (i == 9) { - sprintf(buf, "%d", nrn_main_launch); - }else{ - nrn_assert(snprintf(buf, 1024, "NEURON -- %s %s", head, GIT_DATE) < 1024); - } - - return buf; -} - diff --git a/src/nrnoc/nrnversion.cpp b/src/nrnoc/nrnversion.cpp new file mode 100755 index 0000000000..2e0a922f37 --- /dev/null +++ b/src/nrnoc/nrnversion.cpp @@ -0,0 +1,79 @@ +#include <../../nrnconf.h> +#include +#include +#include +#include +#include +#include +#include "nrnassrt.h" + + +extern int nrn_global_argc; +extern char** nrn_global_argv; + +extern int nrn_main_launch; /* 1 if nrniv, 2 if python, 0 if unknownn */ + +static char buf[1024]; +static char* sarg = 0; +static char configargs[] = NRN_CONFIG_ARGS; + +#if !defined(GIT_BRANCH) +#define GIT_DATE "2018-08-24" +#define GIT_BRANCH "unknown" +#define GIT_CHANGESET "d3ead4a+" +#define GIT_DESCRIBE "7.6.2-2-gd3ead4a+" +#endif + +char *nrn_version(int i) { + char head[1024]; + char *cp; + int b; + buf[0] = '\0'; + if (strncmp(GIT_BRANCH, "Release", 7) == 0) { + sprintf(head, "%s (%s)", GIT_BRANCH, GIT_CHANGESET); + } else { + sprintf(head, "VERSION %s %s (%s)", + GIT_DESCRIBE, + GIT_BRANCH, + GIT_CHANGESET); + } + if (i == 0) { + sprintf(buf, "%s", PACKAGE_VERSION); + } else if (i == 2) { + sprintf(buf, "%s", head); + } else if (i == 3) { + sprintf(buf, "%s", GIT_CHANGESET); + } else if (i == 4) { + sprintf(buf, "%s", GIT_DATE); + } else if (i == 5) { + sprintf(buf, "%s", GIT_DESCRIBE); + } else if (i == 6) { + return configargs; + } else if (i == 7) { + int j, size; + if (!sarg) { + char *c; + int size = 0; + for (j = 0; j < nrn_global_argc; ++j) { + size += strlen(nrn_global_argv[j]) + 1; + } + sarg = (char *) calloc(size + 1, sizeof(char)); + c = sarg; + for (j = 0; j < nrn_global_argc; ++j) { + sprintf(c, "%s%s", j ? " " : "", nrn_global_argv[j]); + c = c + strlen(c); + } + } + return sarg; + } else if (i == 8) { + sprintf(buf, "%s", NRNHOST); + } else if (i == 9) { + sprintf(buf, "%d", nrn_main_launch); + } else { + nrn_assert(snprintf(buf, 1024, "NEURON -- %s %s", head, GIT_DATE) < 1024); + } + + return buf; +} + + diff --git a/src/nrnoc/ocmain.c b/src/nrnoc/ocmain.c deleted file mode 100755 index b61caa44e8..0000000000 --- a/src/nrnoc/ocmain.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <../../nrnconf.h> -/* - * Automake doesn't deal well with sources that live in other directories, so - * this is a quick and dirty workaround. - */ -#include "../oc/ocmain.c" diff --git a/src/nrnoc/hoc_init.c b/src/nrnoc/ocmain.cpp similarity index 84% rename from src/nrnoc/hoc_init.c rename to src/nrnoc/ocmain.cpp index 1a20e299d6..835ec39a22 100755 --- a/src/nrnoc/hoc_init.c +++ b/src/nrnoc/ocmain.cpp @@ -3,4 +3,4 @@ * Automake doesn't deal well with sources that live in other directories, so * this is a quick and dirty workaround. */ -#include "../oc/hoc_init.c" +#include "../oc/ocmain.cpp" diff --git a/src/nrnoc/ocnoiv.c b/src/nrnoc/ocnoiv.c deleted file mode 100755 index 789f9e2377..0000000000 --- a/src/nrnoc/ocnoiv.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <../../nrnconf.h> -/* - * Automake doesn't deal well with sources that live in other directories, so - * this is a quick and dirty workaround. - */ -#include "../oc/ocnoiv.c" diff --git a/src/nrnoc/hoc_oop.c b/src/nrnoc/ocnoiv.cpp similarity index 84% rename from src/nrnoc/hoc_oop.c rename to src/nrnoc/ocnoiv.cpp index 941ef6684f..359538e3fa 100755 --- a/src/nrnoc/hoc_oop.c +++ b/src/nrnoc/ocnoiv.cpp @@ -3,4 +3,4 @@ * Automake doesn't deal well with sources that live in other directories, so * this is a quick and dirty workaround. */ -#include "../oc/hoc_oop.c" +#include "../oc/ocnoiv.cpp" diff --git a/src/nrnoc/osxdlfcn.c b/src/nrnoc/osxdlfcn.c deleted file mode 100755 index 698234fef0..0000000000 --- a/src/nrnoc/osxdlfcn.c +++ /dev/null @@ -1,239 +0,0 @@ -/* -Copyright (c) 2002 Peter O'Gorman - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - - -/* Just to prove that it isn't that hard to add Mac calls to your code :) - This works with pretty much everything, including kde3 xemacs and the gimp, - I'd guess that it'd work in at least 95% of cases, use this as your starting - point, rather than the mess that is dlfcn.c, assuming that your code does not - require ref counting or symbol lookups in dependent libraries -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "osxdlfcn.h" - -#define ERR_STR_LEN 256 -static void *dlsymIntern(void *handle, const char *symbol); -static const char *error(int setget, const char *str, ...); - - - -/* Set and get the error string for use by dlerror */ -static const char *error(int setget, const char *str, ...) -{ - static char errstr[ERR_STR_LEN]; - static int err_filled = 0; - const char *retval; - NSLinkEditErrors ler; - int lerno; - const char *dylderrstr; - const char *file; - va_list arg; - if (setget <= 0) - { - va_start(arg, str); - strncpy(errstr, "dlsimple: ", ERR_STR_LEN); - vsnprintf(errstr + 10, ERR_STR_LEN - 10, str, arg); - va_end(arg); - /* We prefer to use the dyld error string if getset is 1*/ - if (setget == 0) { - NSLinkEditError(&ler, &lerno, &file, &dylderrstr); - fprintf(stderr,"dyld: %s\n",dylderrstr); - if (dylderrstr && strlen(dylderrstr)) - strncpy(errstr,dylderrstr,ERR_STR_LEN); - } - err_filled = 1; - retval = NULL; - } - else - { - if (!err_filled) - retval = NULL; - else - retval = errstr; - err_filled = 0; - } - return retval; -} - -/* dlopen */ -void *dlopen(const char *path, int mode) -{ - void *module = 0; - NSObjectFileImage ofi = 0; - NSObjectFileImageReturnCode ofirc; - static int (*make_private_module_public) (NSModule module) = 0; - unsigned int flags = NSLINKMODULE_OPTION_RETURN_ON_ERROR | NSLINKMODULE_OPTION_PRIVATE; - - /* If we got no path, the app wants the global namespace, use -1 as the marker - in this case */ - if (!path) - return (void *)-1; - - /* Create the object file image, works for things linked with the -bundle arg to ld */ - ofirc = NSCreateObjectFileImageFromFile(path, &ofi); - switch (ofirc) - { - case NSObjectFileImageSuccess: - /* It was okay, so use NSLinkModule to link in the image */ - if (!(mode & RTLD_LAZY)) flags += NSLINKMODULE_OPTION_BINDNOW; - module = NSLinkModule(ofi, path,flags); - /* Don't forget to destroy the object file image, unless you like leaks */ - NSDestroyObjectFileImage(ofi); - /* If the mode was global, then change the module, this avoids - multiply defined symbol errors to first load private then make - global. Silly, isn't it. */ - if ((mode & RTLD_GLOBAL)) - { - if (!make_private_module_public) - { - _dyld_func_lookup("__dyld_NSMakePrivateModulePublic", - (unsigned long *)&make_private_module_public); - } - make_private_module_public(module); - } - break; - case NSObjectFileImageInappropriateFile: - /* It may have been a dynamic library rather than a bundle, try to load it */ - module = (void *)NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR); - break; - case NSObjectFileImageFailure: - error(0,"Object file setup failure : \"%s\"", path); - return 0; - case NSObjectFileImageArch: - error(0,"No object for this architecture : \"%s\"", path); - return 0; - case NSObjectFileImageFormat: - error(0,"Bad object file format : \"%s\"", path); - return 0; - case NSObjectFileImageAccess: - error(0,"Can't read object file : \"%s\"", path); - return 0; - } - if (!module) - error(0, "Can not open \"%s\"", path); - return module; -} - -/* dlsymIntern is used by dlsym to find the symbol */ -void *dlsymIntern(void *handle, const char *symbol) -{ - NSSymbol *nssym = 0; - /* If the handle is -1, if is the app global context */ - if (handle == (void *)-1) - { - /* Global context, use NSLookupAndBindSymbol */ - if (NSIsSymbolNameDefined(symbol)) - { - nssym = NSLookupAndBindSymbol(symbol); - } - - } - /* Now see if the handle is a struch mach_header* or not, use NSLookupSymbol in image - for libraries, and NSLookupSymbolInModule for bundles */ - else - { - /* Check for both possible magic numbers depending on x86/ppc byte order */ - if ((((struct mach_header *)handle)->magic == MH_MAGIC) || - (((struct mach_header *)handle)->magic == MH_CIGAM)) - { - if (NSIsSymbolNameDefinedInImage((struct mach_header *)handle, symbol)) - { - nssym = NSLookupSymbolInImage((struct mach_header *)handle, - symbol, - NSLOOKUPSYMBOLINIMAGE_OPTION_BIND - | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); - } - - } - else - { - nssym = NSLookupSymbolInModule(handle, symbol); - } - } - if (!nssym) - { - error(0, "Symbol \"%s\" Not found", symbol); - return NULL; - } - return NSAddressOfSymbol(nssym); -} - -const char *dlerror(void) -{ - return error(1, (char *)NULL); -} - -int dlclose(void *handle) -{ - if ((((struct mach_header *)handle)->magic == MH_MAGIC) || - (((struct mach_header *)handle)->magic == MH_CIGAM)) - { - error(-1, "Can't remove dynamic libraries on darwin"); - return 0; - } - if (!NSUnLinkModule(handle, 0)) - { - error(0, "unable to unlink module %s", NSNameOfModule(handle)); - return 1; - } - return 0; -} - - -/* dlsym, prepend the underscore and call dlsymIntern */ -void *dlsym(void *handle, const char *symbol) -{ - static char undersym[257]; /* Saves calls to malloc(3) */ - int sym_len = strlen(symbol); - void *value = NULL; - char *malloc_sym = NULL; - - if (sym_len < 256) - { - snprintf(undersym, 256, "_%s", symbol); - value = dlsymIntern(handle, undersym); - } - else - { - malloc_sym = malloc(sym_len + 2); - if (malloc_sym) - { - sprintf(malloc_sym, "_%s", symbol); - value = dlsymIntern(handle, malloc_sym); - free(malloc_sym); - } - else - { - error(-1, "Unable to allocate memory"); - } - } - return value; -} diff --git a/src/nrnoc/osxdlfcn.cpp b/src/nrnoc/osxdlfcn.cpp new file mode 100755 index 0000000000..0ebcf9172d --- /dev/null +++ b/src/nrnoc/osxdlfcn.cpp @@ -0,0 +1,214 @@ +/* +Copyright (c) 2002 Peter O'Gorman + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + + +/* Just to prove that it isn't that hard to add Mac calls to your code :) + This works with pretty much everything, including kde3 xemacs and the gimp, + I'd guess that it'd work in at least 95% of cases, use this as your starting + point, rather than the mess that is dlfcn.cpp, assuming that your code does not + require ref counting or symbol lookups in dependent libraries +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "osxdlfcn.h" + + +#define ERR_STR_LEN 256 + +static void *dlsymIntern(void *handle, const char *symbol); + +static const char *error(int setget, const char *str, ...); + + +/* Set and get the error string for use by dlerror */ +static const char *error(int setget, const char *str, ...) { + static char errstr[ERR_STR_LEN]; + static int err_filled = 0; + const char *retval; + NSLinkEditErrors ler; + int lerno; + const char *dylderrstr; + const char *file; + va_list arg; + if (setget <= 0) { + va_start(arg, str); + strncpy(errstr, "dlsimple: ", ERR_STR_LEN); + vsnprintf(errstr + 10, ERR_STR_LEN - 10, str, arg); + va_end(arg); + /* We prefer to use the dyld error string if getset is 1*/ + if (setget == 0) { + NSLinkEditError(&ler, &lerno, &file, &dylderrstr); + fprintf(stderr, "dyld: %s\n", dylderrstr); + if (dylderrstr && strlen(dylderrstr)) + strncpy(errstr, dylderrstr, ERR_STR_LEN); + } + err_filled = 1; + retval = NULL; + } else { + if (!err_filled) + retval = NULL; + else + retval = errstr; + err_filled = 0; + } + return retval; +} + +/* dlopen */ +void *dlopen(const char *path, int mode) { + void *module = 0; + NSObjectFileImage ofi = 0; + NSObjectFileImageReturnCode ofirc; + static int (*make_private_module_public)(NSModule module) = 0; + unsigned int flags = NSLINKMODULE_OPTION_RETURN_ON_ERROR | NSLINKMODULE_OPTION_PRIVATE; + + /* If we got no path, the app wants the global namespace, use -1 as the marker + in this case */ + if (!path) + return (void *) -1; + + /* Create the object file image, works for things linked with the -bundle arg to ld */ + ofirc = NSCreateObjectFileImageFromFile(path, &ofi); + switch (ofirc) { + case NSObjectFileImageSuccess: + /* It was okay, so use NSLinkModule to link in the image */ + if (!(mode & RTLD_LAZY)) flags += NSLINKMODULE_OPTION_BINDNOW; + module = NSLinkModule(ofi, path, flags); + /* Don't forget to destroy the object file image, unless you like leaks */ + NSDestroyObjectFileImage(ofi); + /* If the mode was global, then change the module, this avoids + multiply defined symbol errors to first load private then make + global. Silly, isn't it. */ + if ((mode & RTLD_GLOBAL)) { + if (!make_private_module_public) { + _dyld_func_lookup("__dyld_NSMakePrivateModulePublic", + (unsigned long *) &make_private_module_public); + } + make_private_module_public(module); + } + break; + case NSObjectFileImageInappropriateFile: + /* It may have been a dynamic library rather than a bundle, try to load it */ + module = (void *) NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR); + break; + case NSObjectFileImageFailure: + error(0, "Object file setup failure : \"%s\"", path); + return 0; + case NSObjectFileImageArch: + error(0, "No object for this architecture : \"%s\"", path); + return 0; + case NSObjectFileImageFormat: + error(0, "Bad object file format : \"%s\"", path); + return 0; + case NSObjectFileImageAccess: + error(0, "Can't read object file : \"%s\"", path); + return 0; + } + if (!module) + error(0, "Can not open \"%s\"", path); + return module; +} + +/* dlsymIntern is used by dlsym to find the symbol */ +void *dlsymIntern(void *handle, const char *symbol) { + NSSymbol *nssym = 0; + /* If the handle is -1, if is the app global context */ + if (handle == (void *) -1) { + /* Global context, use NSLookupAndBindSymbol */ + if (NSIsSymbolNameDefined(symbol)) { + nssym = NSLookupAndBindSymbol(symbol); + } + + } + /* Now see if the handle is a struch mach_header* or not, use NSLookupSymbol in image + for libraries, and NSLookupSymbolInModule for bundles */ + else { + /* Check for both possible magic numbers depending on x86/ppc byte order */ + if ((((struct mach_header *) handle)->magic == MH_MAGIC) || + (((struct mach_header *) handle)->magic == MH_CIGAM)) { + if (NSIsSymbolNameDefinedInImage((struct mach_header *) handle, symbol)) { + nssym = NSLookupSymbolInImage((struct mach_header *) handle, + symbol, + NSLOOKUPSYMBOLINIMAGE_OPTION_BIND + | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); + } + + } else { + nssym = NSLookupSymbolInModule(handle, symbol); + } + } + if (!nssym) { + error(0, "Symbol \"%s\" Not found", symbol); + return NULL; + } + return NSAddressOfSymbol(nssym); +} + +const char *dlerror(void) { + return error(1, (char *) NULL); +} + +int dlclose(void *handle) { + if ((((struct mach_header *) handle)->magic == MH_MAGIC) || + (((struct mach_header *) handle)->magic == MH_CIGAM)) { + error(-1, "Can't remove dynamic libraries on darwin"); + return 0; + } + if (!NSUnLinkModule(handle, 0)) { + error(0, "unable to unlink module %s", NSNameOfModule(handle)); + return 1; + } + return 0; +} + + +/* dlsym, prepend the underscore and call dlsymIntern */ +void *dlsym(void *handle, const char *symbol) { + static char undersym[257]; /* Saves calls to malloc(3) */ + int sym_len = strlen(symbol); + void *value = NULL; + char *malloc_sym = NULL; + + if (sym_len < 256) { + snprintf(undersym, 256, "_%s", symbol); + value = dlsymIntern(handle, undersym); + } else { + malloc_sym = malloc(sym_len + 2); + if (malloc_sym) { + sprintf(malloc_sym, "_%s", symbol); + value = dlsymIntern(handle, malloc_sym); + free(malloc_sym); + } else { + error(-1, "Unable to allocate memory"); + } + } + return value; +} + diff --git a/src/nrnoc/osxdlfcn.h b/src/nrnoc/osxdlfcn.h index 40dfd05782..6a38680ca3 100755 --- a/src/nrnoc/osxdlfcn.h +++ b/src/nrnoc/osxdlfcn.h @@ -71,7 +71,7 @@ extern int dladdr(const void * dl_restrict, Dl_info * dl_restrict); #define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */ #ifdef __cplusplus -} +} // extern "C" #endif #endif /* _DLFCN_H_ */ diff --git a/src/nrnoc/passive0.c b/src/nrnoc/passive0.cpp similarity index 79% rename from src/nrnoc/passive0.c rename to src/nrnoc/passive0.cpp index 2f50276b5e..c7cc960918 100755 --- a/src/nrnoc/passive0.c +++ b/src/nrnoc/passive0.cpp @@ -1,10 +1,12 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/nrnoc/passive0.c,v 1.2 1997/03/13 14:18:02 hines Exp */ +/* /local/src/master/nrn/src/nrnoc/passive0.cpp,v 1.2 1997/03/13 14:18:02 hines Exp */ #include "section.h" #include "membdef.h" #include "nrniv_mf.h" + + #define nparm 2 static const char *mechanism[] = { "0", "fastpas", "g_fastpas", "e_fastpas", 0,0,0 @@ -13,11 +15,11 @@ static void pas_alloc(Prop* p); static void pas_cur(NrnThread* nt, Memb_list* ml, int type); static void pas_jacob(NrnThread* nt, Memb_list* ml, int type); -void passive0_reg_(void) { - int mechtype; - register_mech(mechanism, pas_alloc, pas_cur, pas_jacob, (Pvmi)0, (Pvmi)0, -1, 1); - mechtype = nrn_get_mechtype(mechanism[1]); - hoc_register_prop_size(mechtype, nparm, 0); +extern "C" void passive0_reg_(void) { + int mechtype; + register_mech(mechanism, pas_alloc, pas_cur, pas_jacob, (Pvmi) 0, (Pvmi) 0, -1, 1); + mechtype = nrn_get_mechtype(mechanism[1]); + hoc_register_prop_size(mechtype, nparm, 0); } #define g vdata[i][0] @@ -67,3 +69,4 @@ static void pas_alloc(Prop* p) pd[1] = DEF_e; p->param = pd; } + diff --git a/src/nrnoc/point.c b/src/nrnoc/point.cpp similarity index 86% rename from src/nrnoc/point.c rename to src/nrnoc/point.cpp index 000311fa3b..77ed6d6f41 100755 --- a/src/nrnoc/point.c +++ b/src/nrnoc/point.cpp @@ -1,5 +1,5 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/nrnoc/point.c,v 1.13 1999/03/23 16:12:09 hines Exp */ +/* /local/src/master/nrn/src/nrnoc/point.cpp,v 1.13 1999/03/23 16:12:09 hines Exp */ /* modl description via modlreg calls point_register_mech() and saves the pointtype as later argument to create and loc */ @@ -9,24 +9,27 @@ saves the pointtype as later argument to create and loc */ #include "membfunc.h" #include "parse.h" + extern char* pnt_map; extern Symbol** pointsym; /*list of variable symbols in s->u.ppsym[k] with number in s->s_varn */ extern short* nrn_is_artificial_; -extern double loc_point_process(); -extern Prop* prop_alloc(); +extern "C" { +extern double loc_point_process(int, void *); +} // extern "C" +extern Prop* prop_alloc(Prop**, int, Node*); static int cppp_semaphore = 0; /* connect point process pointer semaphore */ static double** cppp_pointer; -static void free_one_point(); +static void free_one_point(Point_process* pnt); static void create_artcell_prop(Point_process* pnt, short type); Prop* nrn_point_prop_; void (*nrnpy_o2loc_p_)(Object*, Section**, double*); void (*nrnpy_o2loc2_p_)(Object*, Section**, double*); -void* create_point_process(int pointtype, Object* ho) +extern "C" void* create_point_process(int pointtype, Object* ho) { Point_process* pp; pp = (Point_process*)emalloc(sizeof(Point_process)); @@ -42,7 +45,7 @@ void* create_point_process(int pointtype, Object* ho) create_artcell_prop(pp, pointsym[pointtype]->subtype); return pp; } - if (ho && ho->template->steer && ifarg(1)) { + if (ho && ho->ctemplate->steer && ifarg(1)) { loc_point_process(pointtype, (void*)pp); } return (void*)pp; @@ -51,10 +54,11 @@ void* create_point_process(int pointtype, Object* ho) Object* nrn_new_pointprocess(Symbol* sym) { void* v; - Object* hoc_new_object(), *hoc_new_opoint(); + extern Object* hoc_new_object(Symbol*, void*); + extern Object* hoc_new_opoint(int); //, *hoc_new_opoint(); Object* ob; extern Symlist* hoc_built_in_symlist; - Symbol* hoc_table_lookup(); +// Symbol* hoc_table_lookup(char *); int pointtype; assert(sym->type == MECHANISM && memb_func[sym->subtype].is_point); pointtype = pnt_map[sym->subtype]; @@ -62,7 +66,7 @@ Object* nrn_new_pointprocess(Symbol* sym) ob = hoc_new_opoint(sym->subtype); }else{ hoc_push_frame(sym, 0); - v = create_point_process(pointtype, (Object*)0); + v = create_point_process(pointtype, nullptr); hoc_pop_frame(); sym = hoc_table_lookup(sym->name, hoc_built_in_symlist); ob = hoc_new_object(sym, v); @@ -71,19 +75,20 @@ Object* nrn_new_pointprocess(Symbol* sym) return ob; } -void destroy_point_process(void* v) +extern "C" void destroy_point_process(void* v) { Point_process* pp = (Point_process*)v; free_one_point(pp); - free((char*)pp); + free(pp); } void nrn_loc_point_process(int pointtype, Point_process* pnt, Section* sec, Node* node) { - extern Prop *prop_alloc_disallow(), *prop_alloc(); + extern Prop* prop_alloc_disallow(Prop** pp, short type, Node* nd); + extern Prop* prop_alloc(Prop**, int, Node*); extern Section* nrn_pnt_sec_for_need_; Prop* p; - double x, nrn_arc_position(); + double x; //, nrn_arc_position(); assert(!nrn_is_artificial_[pointsym[pointtype]->subtype]); x = nrn_arc_position(sec, node); @@ -130,7 +135,7 @@ void nrn_loc_point_process(int pointtype, Point_process* pnt, Section* sec, Node if (pnt->ob->observers) { hoc_obj_notify(pnt->ob); } - if (pnt->ob->template->observers) { + if (pnt->ob->ctemplate->observers) { hoc_template_notify(pnt->ob, 2); } } @@ -146,7 +151,7 @@ static void create_artcell_prop(Point_process* pnt, short type) { if (pnt->ob->observers) { hoc_obj_notify(pnt->ob); } - if (pnt->ob->template->observers) { + if (pnt->ob->ctemplate->observers) { hoc_template_notify(pnt->ob, 2); } } @@ -213,15 +218,12 @@ void nrn_seg_or_x_arg2(int iarg, Section** psec, double* px) { } } -double loc_point_process(int pointtype, void* v) +extern "C" double loc_point_process(int pointtype, void* v) { - extern int hoc_is_double_arg(); - extern double chkarg(); - extern Object** hoc_objgetarg(); Point_process* pnt = (Point_process*)v; double x; Section *sec; - Node *node, *node_exact(); + Node *node; //, *node_exact(); if (nrn_is_artificial_[pointsym[pointtype]->subtype]) { hoc_execerror("ARTIFICIAL_CELLs are not located in a section", (char*)0); @@ -232,12 +234,12 @@ double loc_point_process(int pointtype, void* v) return x; } -double get_loc_point_process(void* v) +extern "C" double get_loc_point_process(void* v) { #if METHOD3 extern int _method3; #endif - double x, nrn_arc_position(); + double x; //, nrn_arc_position(); Point_process *pnt = (Point_process*)v; Section* sec; @@ -253,7 +255,7 @@ double get_loc_point_process(void* v) return x; } -double has_loc_point(void* v) +extern "C" double has_loc_point(void* v) { Point_process *pnt = (Point_process*)v; return (pnt->sec != 0); @@ -296,9 +298,9 @@ double* point_process_pointer(Point_process* pnt, Symbol* sym, int index) return pd; } -void steer_point_process(void* v) /* put the right double pointer on the stack */ +extern "C" void steer_point_process(void* v) /* put the right double pointer on the stack */ { - Symbol* sym, *hoc_spop(); + Symbol* sym; //, *hoc_spop(); int index; Point_process *pnt = (Point_process*)v; sym = hoc_spop(); @@ -315,7 +317,7 @@ void nrn_cppp(void) { } void connect_point_process_pointer(void) { - double* hoc_pxpop(); +// double* hoc_pxpop(); if (cppp_semaphore != 2) { cppp_semaphore = 0; hoc_execerror("not a point process pointer", (char*)0); @@ -325,6 +327,10 @@ void connect_point_process_pointer(void) { hoc_nopop(); } +#if VECTORIZE +extern "C" int v_structure_change; +#endif + static void free_one_point(Point_process* pnt) /* must unlink from node property list also */ { Prop *p, *p1; @@ -345,7 +351,7 @@ static void free_one_point(Point_process* pnt) /* must unlink from node property } } #if VECTORIZE - { extern int v_structure_change; + { v_structure_change = 1; } #endif @@ -359,7 +365,7 @@ static void free_one_point(Point_process* pnt) /* must unlink from node property if (p->dparam) { nrn_prop_datum_free(p->type, p->dparam); } - free((char*)p); + free(p); pnt->prop = (Prop *)0; pnt->node = (Node *)0; if (pnt->sec) {section_unref(pnt->sec);} @@ -376,7 +382,7 @@ void clear_point_process_struct(Prop* p) /* called from prop_free */ if (pnt->ob->observers) { hoc_obj_notify(pnt->ob); } - if (pnt->ob->template->observers) { + if (pnt->ob->ctemplate->observers) { hoc_template_notify(pnt->ob, 2); } } @@ -391,14 +397,15 @@ void clear_point_process_struct(Prop* p) /* called from prop_free */ if (p->dparam) { nrn_prop_datum_free(p->type, p->dparam); } - free((char*)p); + free(p); } } int is_point_process(Object* ob) { if (ob) { - return ob->template->is_point_ != 0; + return ob->ctemplate->is_point_ != 0; } return 0; } + diff --git a/src/nrnoc/psection.c b/src/nrnoc/psection.cpp similarity index 93% rename from src/nrnoc/psection.c rename to src/nrnoc/psection.cpp index 4e796ee7ef..9938ae27b8 100644 --- a/src/nrnoc/psection.c +++ b/src/nrnoc/psection.cpp @@ -5,6 +5,7 @@ #include "parse.h" #include "membfunc.h" + static void pnode(Prop*); void psection(void) @@ -71,11 +72,11 @@ extern void print_stim(void); extern void print_clamp(void); extern void print_syn(void); -void prstim(void) -{ - print_stim(); - print_clamp(); - print_syn(); - hoc_retpushx(1.); +void prstim(void) { + print_stim(); + print_clamp(); + print_syn(); + hoc_retpushx(1.); } + diff --git a/src/nrnoc/seclist.c b/src/nrnoc/seclist.cpp similarity index 91% rename from src/nrnoc/seclist.c rename to src/nrnoc/seclist.cpp index d9d5067fa4..f18af95d01 100755 --- a/src/nrnoc/seclist.c +++ b/src/nrnoc/seclist.cpp @@ -162,7 +162,7 @@ static double seclist_remove(void* v) sl = (List*)v; i = 0; #if USE_PYTHON - if (!ifarg(1) || (*hoc_objgetarg(1))->template->sym == nrnpy_pyobj_sym_) { + if (!ifarg(1) || (*hoc_objgetarg(1))->ctemplate->sym == nrnpy_pyobj_sym_) { #else if (!ifarg(1)) { #endif @@ -267,10 +267,19 @@ static Member_func members[] = { 0,0 }; + +extern void class2oc(const char *, + void *(*cons)(Object *), + void (*destruct)(void *), + Member_func *, + int (*checkpoint)(void **), + Member_ret_obj_func *, + Member_ret_str_func *); + + void SectionList_reg(void) { - void class2oc(); /* printf("SectionList_reg\n");*/ - class2oc("SectionList", constructor, destructor, members, (void*)0, (void*)0, (void*)0); + class2oc("SectionList", constructor, destructor, members, nullptr, nullptr, nullptr); } #define relative(pc) (pc + (pc)->i) @@ -280,8 +289,8 @@ static void check(Object* ob) { if (!ob) { hoc_execerror("nil object is not a SectionList", (char*)0); } - if (ob->template->constructor != constructor) { - hoc_execerror(ob->template->sym->name, " is not a SectionList"); + if (ob->ctemplate->constructor != constructor) { + hoc_execerror(ob->ctemplate->sym->name, " is not a SectionList"); } } @@ -363,4 +372,3 @@ void hoc_ifseclist(void) { pc = relative(savepc+1); } } - diff --git a/src/nrnoc/secref.c b/src/nrnoc/secref.cpp similarity index 89% rename from src/nrnoc/secref.c rename to src/nrnoc/secref.cpp index ec92b638a5..ed84ca2345 100755 --- a/src/nrnoc/secref.c +++ b/src/nrnoc/secref.cpp @@ -79,12 +79,14 @@ static double s_unname(void* v) { return 1.; } +extern "C" Object* ivoc_list_item(Object*, int); + static double s_rename(void* v) { - extern Object* hoc_thisobject, **hoc_objgetarg(); +// extern Object* hoc_thisobject, **hoc_objgetarg(); extern Objectdata* hoc_top_level_data; - extern Symbol* hoc_table_lookup(); +// extern Symbol* hoc_table_lookup(); extern Symlist* hoc_top_level_symlist; - extern Object* ivoc_list_item(); + char* name; Section* sec; Symbol* sym; @@ -157,7 +159,7 @@ static double s_rename(void* v) { pitm[index] = qsec; sec->prop->dparam[0].sym = sym; sec->prop->dparam[5].i = index; - sec->prop->dparam[6].obj = (Object*)0; + sec->prop->dparam[6].obj = nullptr; OPSECITM(sym)[0] = qsec; }else{ for (i=0; i < size; ++i) { @@ -172,7 +174,7 @@ static double s_rename(void* v) { qsec = sec->prop->dparam[8].itm; sec->prop->dparam[0].sym = sym; sec->prop->dparam[5].i = i; - sec->prop->dparam[6].obj = (Object*)0; + sec->prop->dparam[6].obj = nullptr; OPSECITM(sym)[i] = qsec; } } @@ -348,31 +350,43 @@ if (nrn_inpython_) { return s; } + + + +extern void class2oc(const char *, + void *(*cons)(Object *), + void (*destruct)(void *), + Member_func *, + int (*checkpoint)(void **), + Member_ret_obj_func *, + Member_ret_str_func * +); + + void SectionRef_reg(void) { - Symbol* s, *sr, *hoc_table_lookup(); - extern void class2oc(); - - class2oc("SectionRef", cons, destruct, members, (void*)0, (void*)0, (void*)0); + Symbol* s, *sr; //, *hoc_table_lookup(); + + class2oc("SectionRef", cons, destruct, members, nullptr, nullptr, nullptr); /* now make the sec variable an actual SECTIONREF */ sr = hoc_lookup("SectionRef"); - s = hoc_table_lookup("sec", sr->u.template->symtable); + s = hoc_table_lookup("sec", sr->u.ctemplate->symtable); s->type = SECTIONREF; nrn_sec_sym = s; - s = hoc_table_lookup("parent", sr->u.template->symtable); + s = hoc_table_lookup("parent", sr->u.ctemplate->symtable); s->type = SECTIONREF; nrn_parent_sym = s; - s = hoc_table_lookup("trueparent", sr->u.template->symtable); + s = hoc_table_lookup("trueparent", sr->u.ctemplate->symtable); s->type = SECTIONREF; nrn_trueparent_sym = s; - s = hoc_table_lookup("root", sr->u.template->symtable); + s = hoc_table_lookup("root", sr->u.ctemplate->symtable); s->type = SECTIONREF; nrn_root_sym = s; - s = hoc_table_lookup("child", sr->u.template->symtable); + s = hoc_table_lookup("child", sr->u.ctemplate->symtable); s->type = SECTIONREF; nrn_child_sym = s; s->arayinfo = (Arrayinfo*)emalloc(sizeof(Arrayinfo));; s->arayinfo->refcount = 1; - s->arayinfo->a_varn = (void*)0; + s->arayinfo->a_varn = nullptr; s->arayinfo->nsub = 1; s->arayinfo->sub[0] = 0; } diff --git a/src/nrnoc/section.h b/src/nrnoc/section.h index ff0d22eccc..a0abbe8235 100755 --- a/src/nrnoc/section.h +++ b/src/nrnoc/section.h @@ -24,9 +24,6 @@ d and rhs is calculated from the property list. */ -#if defined(__cplusplus) -extern "C" { -#endif #include "nrnredef.h" #include "options.h" @@ -100,7 +97,7 @@ typedef struct Info3Val { /* storage to help build matrix efficiently */ #endif /* if any double is added after area then think about changing -the notify_free_val parameter in node_free in solve.c +the notify_free_val parameter in node_free in solve.cpp */ #define NODED(n) (*((n)->_d)) @@ -135,12 +132,12 @@ extern int cvode_active_; typedef struct Node { #if CACHEVEC == 0 double _v; /* membrane potential */ - double _area; /* area in um^2 but see treesetup.c */ + double _area; /* area in um^2 but see treesetup.cpp */ double _a; /* effect of node in parent equation */ double _b; /* effect of parent in node equation */ #else /* CACHEVEC */ double *_v; /* membrane potential */ - double _area; /* area in um^2 but see treesetup.c */ + double _area; /* area in um^2 but see treesetup.cpp */ double _rinv; /* conductance uS from node to parent */ double _v_temp; /* vile necessity til actual_v allocated */ #endif /* CACHEVEC */ @@ -189,7 +186,7 @@ typedef struct Node { #define nlayer (EXTRACELLULAR) /* first (0) layer is extracellular next to membrane */ /* changing nlayer here means you have to change the explicit numbers -nlayer-1 in the mechanism structure in extcell.c +nlayer-1 in the mechanism structure in extcell.cpp */ typedef struct Extnode { double *param; /* points to extracellular parameter vector */ @@ -229,10 +226,21 @@ typedef struct Prop { Object* ob; /* nil if normal property, otherwise the object containing the data*/ } Prop; +#if defined(__cplusplus) +extern "C" { +#endif + extern double* nrn_prop_data_alloc(int type, int count, Prop* p); extern Datum* nrn_prop_datum_alloc(int type, int count, Prop* p); extern void nrn_prop_data_free(int type, double* pd); extern void nrn_prop_datum_free(int type, Datum* ppd); +extern Section* chk_access(); +extern double nrn_ghk(double, double, double, double); + + +#if defined(__cplusplus) +} +#endif /* a point process is computed just like regular mechanisms. Ie it appears in the property list whose type specifies which allocation, current, and @@ -299,11 +307,9 @@ typedef struct Eqnblock { extern int nrn_global_ncell; /* note that for multiple threads all the rootnodes are no longer contiguous */ extern hoc_List* section_list; /* Where the Sections live */ -extern Section* chk_access(); extern Section *sec_alloc(); /* Allocates a single section */ extern void node_alloc(Section*, short); /* Allocates node vectors in a section*/ extern double section_length(Section*), nrn_diameter(Node*); -extern double nrn_ghk(double, double, double, double); extern Node* nrn_parent_node(Node*); extern Section* nrn_section_alloc(); extern void nrn_section_free(Section*); @@ -327,9 +333,6 @@ extern int stoprun; /* of any hoc call for integration and before returning to hoc */ -#if defined(__cplusplus) -} -#endif #include "nrn_ansi.h" diff --git a/src/nrnoc/solve.c b/src/nrnoc/solve.cpp similarity index 96% rename from src/nrnoc/solve.c rename to src/nrnoc/solve.cpp index ac82385cca..200f2d181d 100644 --- a/src/nrnoc/solve.c +++ b/src/nrnoc/solve.cpp @@ -1,7 +1,7 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/nrnoc/solve.c,v 1.15 1999/07/12 14:34:13 hines Exp */ +/* /local/src/master/nrn/src/nrnoc/solve.cpp,v 1.15 1999/07/12 14:34:13 hines Exp */ -/* solve.c 15-Dec-88 */ +/* solve.cpp 15-Dec-88 */ /* The data structures in section.h were developed primarily for the needs of solving and setting up the matrix equations reasonably efficiently in @@ -60,6 +60,8 @@ node.v + extnode.v[0] #include "membfunc.h" #include "spmatrix.h" + + extern int tree_changed; static void node_free(); static void triang(NrnThread*), bksub(NrnThread*); @@ -220,9 +222,9 @@ double topol_distance(Section* sec1, Node* node1, Section* sec2, Node* node2, static Section *origin_sec; void distance(void) { - double d, d_origin, chkarg(); + double d, d_origin; //, chkarg(); int mode; - Node* node, *node_exact(); + Node* node;//, *node_exact(); Section *sec; static Node* origin_node; Node* my_origin_node; @@ -298,7 +300,7 @@ static void dashes(Section* sec, int offset, int first) int i, scnt; Section* ch; char direc[30]; - extern double nrn_section_orientation(); +// extern double nrn_section_orientation(); i = (int)nrn_section_orientation(sec); sprintf(direc, "(%d-%d)", i, 1-i); @@ -318,7 +320,7 @@ static void dashes(Section* sec, int offset, int first) hoc_pushobj((Object**)ch); } while(scnt--) { - Object** hoc_objpop(); +// Object** hoc_objpop(); ch = (Section*)hoc_objpop(); i = node_index_exact(sec, nrn_connection_position(ch)); Printf(" "); @@ -455,8 +457,8 @@ void nrn_clear_mark(void) { sec->volatile_mark = 0; } } -short nrn_increment_mark(sec) Section* sec; { return sec->volatile_mark++;} -short nrn_value_mark(sec) Section* sec; { return sec->volatile_mark;} +short nrn_increment_mark(Section* sec) { return sec->volatile_mark++;} +short nrn_value_mark(Section* sec) { return sec->volatile_mark;} /* allocate space for sections (but no nodes) */ /* returns pointer to Section */ @@ -488,6 +490,23 @@ Section* sec_alloc(void) return sec; } +/* free a node vector for one section */ +static void node_free(Section* sec) +{ + Node **pnd; + + pnd = sec->pnode; + if (!pnd) { + sec->nnode = 0; + } + if (sec->nnode == 0) { + return; + } + node_destruct(sec->pnode, sec->nnode); + sec->pnode = (Node **)0; + sec->nnode = 0; +} + static void section_unlink(Section* sec); /* free everything about sections */ void sec_free(hoc_Item* secitem) @@ -525,7 +544,7 @@ void sec_free(hoc_Item* secitem) sec->pt3d_bsize = 0; } if (sec->logical_connection) { - free((char*)sec->logical_connection); + free(sec->logical_connection); sec->logical_connection = (Pt3d*)0; } #endif @@ -607,7 +626,7 @@ Node* nrn_node_construct1(void) { Node** ndp; ndp = node_construct(1); nd = ndp[0]; - free((char*)ndp); + free(ndp); return nd; } @@ -639,7 +658,7 @@ void nrn_node_destruct1(Node* nd) { free((char *)nd->extnode); } #endif - free((char*)nd); + free(nd); } void node_destruct(Node** pnode, int n) @@ -661,7 +680,8 @@ extern int keep_nseg_parm_; static Node* node_clone(Node* nd1) { Node* nd2; - Prop* p1, *p2, *prop_alloc(); + Prop* p1, *p2; + extern Prop* prop_alloc(Prop**, int, Node*);//, *prop_alloc(); int i, imax; nd2 = (Node *)ecalloc(1, sizeof(Node)); #if CACHEVEC @@ -815,23 +835,6 @@ void node_alloc(Section* sec, short nseg) } } -/* free a node vector for one section */ -static void node_free(Section* sec) -{ - Node **pnd; - - pnd = sec->pnode; - if (!pnd) { - sec->nnode = 0; - } - if (sec->nnode == 0) { - return; - } - node_destruct(sec->pnode, sec->nnode); - sec->pnode = (Node **)0; - sec->nnode = 0; -} - void section_order(void) /* create a section order consistent */ /* with connection info */ { @@ -891,3 +894,4 @@ hoc_execerror("A loop exists involving section", secname(sec)); } assert(order == section_count); } + diff --git a/src/nrnoc/synapse.c b/src/nrnoc/synapse.c deleted file mode 100644 index 3599cc28df..0000000000 --- a/src/nrnoc/synapse.c +++ /dev/null @@ -1,227 +0,0 @@ -#include <../../nrnconf.h> -/* /local/src/master/nrn/src/nrnoc/synapse.c,v 1.2 1997/08/15 13:04:13 hines Exp */ -/* modified from fstim.c */ - -/* -fsyn(maxnum) - allocates space for maxnum synapses. Space for - previously existing synapses is released. All synapses initialized to - 0 maximum conductance. - -fsyn(i, loc, delay, tau, gmax, erev) - The ith synapse is injected at parameter `loc' - different synapses do not concatenate but can ride on top of - each other. delay refers to onset of synapse relative to t=0 - delay and duration are in msec. - stim in namps. - - a synaptic current defined by - i = g * (v - erev) i(nanoamps), g(microsiemens); - where - g = 0 for t < delay and - g = gmax * (t - delay)/tau * exp(-(t - delay - tau)/tau) - for t > onset - this has the property that the maximum value is gmax and occurs at - t = delay + tau. - -fsyni(i) - returns synaptic current for ith synapse at the value of the - global time t in units of nanoamps. - -fsyng(i) - returns synaptic conductance for ith synapse at the value of the - global time t. - -*/ - -#include -#include "neuron.h" -#include "section.h" -#include "nrniv_mf.h" - -#define nt_t nrn_threads->_t - -/* impress the stimulus code to do synapses */ -typedef struct Stimulus { - double loc; /* parameter location (0--1) */ - double delay; /* value of t in msec for onset */ - double duration;/* turns off at t = delay + duration */ - double mag; /* conductance in microsiemens */ - double erev; - double mag_seg; /* value added to rhs, depends on area of seg*/ - double g; /* holds conductance when current calculated */ - Node *pnd; /* segment location */ - Section* sec; -} Stimulus; - -static int maxstim = 0; /* size of stimulus array */ -static Stimulus *pstim; /* pointer to stimulus array */ -static void free_syn(void); -static void stim_record(int); - -void print_syn(void) { - int i; - - if (maxstim == 0) return; - /*SUPPRESS 440*/ - Printf("fsyn(%d)\n/* section fsyn( #, loc, delay(ms), tau(ms), conduct(uS), erev(mV)) */\n", maxstim); - for (i=0; i 1) { - hoc_execerror("fsyn does not allow threads", ""); - } - i = chkarg(1, 0., 10000.); - if (ifarg(2)) { - if (i >= maxstim) { - hoc_execerror("index out of range", (char *)0); - } - pstim[i].loc = chkarg(2, 0., 1.); - pstim[i].delay = chkarg(3, 0., 1e21); - pstim[i].duration = chkarg(4, 0., 1e21); - pstim[i].mag = *getarg(5); - pstim[i].erev = *getarg(6); - pstim[i].sec = chk_access(); - section_ref(pstim[i].sec); - stim_record(i); - } else { - free_syn(); - maxstim = i; - if (maxstim) { - pstim = (Stimulus *)emalloc((unsigned)(maxstim * sizeof(Stimulus))); - } - for (i = 0; iprop) { - pstim[i].pnd = node_ptr(sec, pstim[i].loc, &area); - pstim[i].mag_seg = 1.e2*pstim[i].mag / area; - }else{ - section_unref(sec); - pstim[i].sec = 0; - } - } -} - -void synapse_prepare(void) { - int i; - - for (i=0; i 0.0 && x < 10.0) { - return x * exp(-x + 1.0); - } - return 0.0; -} - -void activsynapse_rhs(void) { - - int i; - for (i=0; i +/* /local/src/master/nrn/src/nrnoc/synapse.cpp,v 1.2 1997/08/15 13:04:13 hines Exp */ +/* modified from fstim.cpp */ + +/* +fsyn(maxnum) + allocates space for maxnum synapses. Space for + previously existing synapses is released. All synapses initialized to + 0 maximum conductance. + +fsyn(i, loc, delay, tau, gmax, erev) + The ith synapse is injected at parameter `loc' + different synapses do not concatenate but can ride on top of + each other. delay refers to onset of synapse relative to t=0 + delay and duration are in msec. + stim in namps. + + a synaptic current defined by + i = g * (v - erev) i(nanoamps), g(microsiemens); + where + g = 0 for t < delay and + g = gmax * (t - delay)/tau * exp(-(t - delay - tau)/tau) + for t > onset + this has the property that the maximum value is gmax and occurs at + t = delay + tau. + +fsyni(i) + returns synaptic current for ith synapse at the value of the + global time t in units of nanoamps. + +fsyng(i) + returns synaptic conductance for ith synapse at the value of the + global time t. + +*/ + +#include +#include "neuron.h" +#include "section.h" +#include "nrniv_mf.h" +#include + + + +#define nt_t nrn_threads->_t + +/* impress the stimulus code to do synapses */ +typedef struct Stimulus { + double loc; /* parameter location (0--1) */ + double delay; /* value of t in msec for onset */ + double duration;/* turns off at t = delay + duration */ + double mag; /* conductance in microsiemens */ + double erev; + double mag_seg; /* value added to rhs, depends on area of seg*/ + double g; /* holds conductance when current calculated */ + Node *pnd; /* segment location */ + Section *sec; +} Stimulus; + +static int maxstim = 0; /* size of stimulus array */ +static Stimulus *pstim; /* pointer to stimulus array */ +static void free_syn(void); + +static void stim_record(int); + +void print_syn(void) { + int i; + + if (maxstim == 0) return; + /*SUPPRESS 440*/ + Printf("fsyn(%d)\n/* section fsyn( #, loc, delay(ms), tau(ms), conduct(uS), erev(mV)) */\n", maxstim); + for (i = 0; i < maxstim; i++) { + Printf("%-15s fsyn(%2d,%4g,%10g,%8g,%14g,%9g)\n", + secname(pstim[i].sec), i, + pstim[i].loc, pstim[i].delay, pstim[i].duration, pstim[i].mag, + pstim[i].erev); + } +} + +static double alpha(double x) { + + if (x > 0.0 && x < 10.0) { + return x * exp(-x + 1.0); + } + return 0.0; +} + + +static double stimulus(int i) { + double x, g; + + if ((g = pstim[i].mag_seg) == 0.0) { + pstim[i].g = 0.0; + return 0.0; + } +#if CVODE + at_time(nrn_threads, pstim[i].delay); +#endif + x = (nt_t - pstim[i].delay) / pstim[i].duration; + pstim[i].g = g * alpha(x); + return pstim[i].g * (NODEV(pstim[i].pnd) - pstim[i].erev); +} + +void fsyni(void) { + int i; + double cur; + + i = chkarg(1, 0., (double) (maxstim - 1)); + if ((cur = stimulus(i)) != 0.) { + cur *= pstim[i].mag / pstim[i].mag_seg; + } + hoc_retpushx(cur); +} + +void fsyng(void) { + int i; + double g = 0.0; + + i = chkarg(1, 0., (double) (maxstim - 1)); + IGNORE(stimulus(i)); + g = pstim[i].g; + if (g != 0.) { + g *= pstim[i].mag / pstim[i].mag_seg; + } + hoc_retpushx(g); +} + +void fsyn(void) { + int i; + + if (nrn_nthread > 1) { + hoc_execerror("fsyn does not allow threads", ""); + } + i = chkarg(1, 0., 10000.); + if (ifarg(2)) { + if (i >= maxstim) { + hoc_execerror("index out of range", (char *) 0); + } + pstim[i].loc = chkarg(2, 0., 1.); + pstim[i].delay = chkarg(3, 0., 1e21); + pstim[i].duration = chkarg(4, 0., 1e21); + pstim[i].mag = *getarg(5); + pstim[i].erev = *getarg(6); + pstim[i].sec = chk_access(); + section_ref(pstim[i].sec); + stim_record(i); + } else { + free_syn(); + maxstim = i; + if (maxstim) { + pstim = (Stimulus *) emalloc((unsigned) (maxstim * sizeof(Stimulus))); + } + for (i = 0; i < maxstim; i++) { + pstim[i].loc = 0; + pstim[i].mag = 0.; + pstim[i].delay = 1e20; + pstim[i].duration = 0.; + pstim[i].erev = 0.; + pstim[i].sec = 0; + stim_record(i); + } + } + hoc_retpushx(0.); +} + +static void free_syn(void) { + int i; + if (maxstim) { + for (i = 0; i < maxstim; ++i) { + if (pstim[i].sec) { + section_unref(pstim[i].sec); + } + } + free((char *) pstim); + maxstim = 0; + } +} + +static void stim_record(int i) /*fill in the section info*/ +{ +// Node *node_ptr(); + double area; + Section *sec; + + sec = pstim[i].sec; + if (sec) { + if (sec->prop) { + pstim[i].pnd = node_ptr(sec, pstim[i].loc, &area); + pstim[i].mag_seg = 1.e2 * pstim[i].mag / area; + } else { + section_unref(sec); + pstim[i].sec = 0; + } + } +} + +void synapse_prepare(void) { + int i; + + for (i = 0; i < maxstim; i++) { + stim_record(i); + } +} + +void activsynapse_rhs(void) { + + int i; + for (i = 0; i < maxstim; i++) { + if (pstim[i].sec) { + NODERHS(pstim[i].pnd) -= stimulus(i); + } + } +} + +void activsynapse_lhs() { + + int i; + + for (i = 0; i < maxstim; i++) { + if (pstim[i].sec) { + NODED(pstim[i].pnd) += pstim[i].g; + } + } +} + diff --git a/src/nrnoc/treeset.c b/src/nrnoc/treeset.cpp similarity index 95% rename from src/nrnoc/treeset.c rename to src/nrnoc/treeset.cpp index 8b4c872677..33aa17cf02 100644 --- a/src/nrnoc/treeset.c +++ b/src/nrnoc/treeset.cpp @@ -1,5 +1,5 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/nrnoc/treeset.c,v 1.39 1999/07/08 14:25:07 hines Exp */ +/* /local/src/master/nrn/src/nrnoc/treeset.cpp,v 1.39 1999/07/08 14:25:07 hines Exp */ #include #if HAVE_STDLIB_H @@ -17,6 +17,9 @@ #include "nonvintblock.h" #include "nrndae_c.h" + +extern spREAL *spGetElement(char*, int ,int); + #if CVODE extern int cvode_active_; #endif @@ -26,8 +29,8 @@ double* nrn_mech_wtime_; extern int diam_changed; extern int tree_changed; -extern double chkarg(); -extern double nrn_ra(); +extern double chkarg(int, double low, double high); +extern double nrn_ra(Section*); #if !defined(NRNMPI) || NRNMPI == 0 extern double nrnmpi_wtime(); #endif @@ -42,6 +45,9 @@ void (*nrn_multisplit_setup_)(); #endif #if CACHEVEC + + + /* a, b, d and rhs are, from now on, all stored in extra arrays, to improve * cache efficiency in nrn_lhs() and nrn_rhs(). Formerly, three levels of * indirection were necessary for accessing these elements, leading to lots @@ -66,9 +72,11 @@ int nrn_use_daspk_ = 0; When properties are allocated to nodes or freed, v_structure_change is set to 1. This means that the mechanism vectors need to be re-determined. */ +extern "C" { int v_structure_change; int structure_change_cnt; int diam_change_cnt; +} // extern "C" int nrn_node_ptr_change_cnt_; #endif @@ -76,7 +84,7 @@ extern int section_count; extern Section** secorder; #if 1 /* if 0 then handled directly to save space : see finitialize*/ extern short* nrn_is_artificial_; -extern Template** nrn_pnt_template_; +extern cTemplate** nrn_pnt_template_; #endif /* @@ -211,12 +219,12 @@ and add them to the matrix equation. Thus the passive channel, i=g*(v - e), is a transmembrane current (convention is positive outward) and the mechanism adds g to the diagonal element of the matrix and subtracts i - g*v from the right hand side. -(see nrn_cur of passive.c) It does NOT add anything to the extracellular +(see nrn_cur of passive.cpp) It does NOT add anything to the extracellular current balance row. An electrode current (convention positive current increases the internal potential) such as a voltage clamp with small resistance, is=g*(vc - (v+vext)) -(see nrn_cur of svclmp.c) +(see nrn_cur of svclmp.cpp) subtracts -g from the matrix diagonal (since dis/dvi = -g) and adds i - g*(v+vext) to the right hand side. In the presence of an extracellular mechanism, such electrode @@ -596,7 +604,7 @@ void* setup_tree_matrix(NrnThread* _nt){ nrn_lhs(_nt); nrn_nonvint_block_current(_nt->end, _nt->_actual_rhs, _nt->id); nrn_nonvint_block_conductance(_nt->end, _nt->_actual_d, _nt->id); - return (void*)0; + return nullptr; } /* membrane mechanisms needed by other mechanisms (such as Eion by HH) @@ -611,11 +619,13 @@ static int disallow_needmemb = 0; /* point processes cannot use need_memb Section* nrn_pnt_sec_for_need_; -Prop* need_memb(Symbol* sym) +extern Prop *prop_alloc(Prop **, int, Node *);//, *prop_alloc(); + + +extern "C" Prop* need_memb(Symbol* sym) { int type; - Prop *mprev, *m, *prop_alloc(); - + Prop *mprev, *m; if (disallow_needmemb) { fprintf(stderr, "You can not locate a point process at\n\ position 0 or 1 if it needs an ion\n"); @@ -657,84 +667,85 @@ Prop* need_memb(Symbol* sym) } return m; } - + + + Node* nrn_alloc_node_; /* needed by models that use area */ -Prop* prop_alloc(Prop** pp, int type, Node* nd) { +Prop *prop_alloc(Prop **pp, int type, Node *nd) { /* link in new property at head of list */ /* returning *Prop because allocation may */ /* cause other properties to be linked ahead */ /* some models need the node (to find area) */ - Prop *p; + Prop *p; - if (nd) { - nrn_alloc_node_ = nd; - } + if (nd) { + nrn_alloc_node_ = nd; + } #if VECTORIZE - v_structure_change = 1; + v_structure_change = 1; #endif - current_prop_list = pp; - p = (Prop *)emalloc(sizeof(Prop)); - p->type = type; - p->next = *pp; - p->ob = (Object*)0; - p->_alloc_seq = -1; - *pp = p; - assert(memb_func[type].alloc); - p->dparam = (Datum *)0; - p->param = (double *)0; - p->param_size = 0; - (memb_func[type].alloc)(p); - return p; -} - -Prop* prop_alloc_disallow(Prop** pp, short type, Node* nd) -{ - Prop *p; - disallow_needmemb = 1; - p = prop_alloc(pp, type, nd); - disallow_needmemb = 0; - return p; -} - -void prop_free(Prop** pp) /* free an entire property list */ + current_prop_list = pp; + p = (Prop *) emalloc(sizeof(Prop)); + p->type = type; + p->next = *pp; + p->ob = nullptr; + p->_alloc_seq = -1; + *pp = p; + assert(memb_func[type].alloc); + p->dparam = (Datum *) 0; + p->param = (double *) 0; + p->param_size = 0; + (memb_func[type].alloc)(p); + return p; +} + +Prop *prop_alloc_disallow(Prop **pp, short type, Node *nd) { + Prop *p; + disallow_needmemb = 1; + p = prop_alloc(pp, type, nd); + disallow_needmemb = 0; + return p; +} + +void prop_free(Prop **pp) /* free an entire property list */ { - Prop *p, *pn; - p = *pp; - *pp = (Prop *)0; - while (p) { - pn = p->next; - single_prop_free(p); - p = pn; - } + Prop *p, *pn; + p = *pp; + *pp = (Prop *) 0; + while (p) { + pn = p->next; + single_prop_free(p); + p = pn; + } } -void single_prop_free(Prop* p) -{ - extern char* pnt_map; +void single_prop_free(Prop *p) { + extern char *pnt_map; #if VECTORIZE - v_structure_change = 1; + v_structure_change = 1; #endif - if (pnt_map[p->type]) { - clear_point_process_struct(p); - return; - } - if (p->param) { - notify_freed_val_array(p->param, p->param_size); - nrn_prop_data_free(p->type, p->param); - } - if (p->dparam) { - if (p->type == CABLESECTION) { - notify_freed_val_array(&p->dparam[2].val, 6); - } - nrn_prop_datum_free(p->type, p->dparam); - } - if (p->ob) { - hoc_obj_unref(p->ob); - } - free((char *)p); + if (pnt_map[p->type]) { + clear_point_process_struct(p); + return; + } + if (p->param) { + notify_freed_val_array(p->param, p->param_size); + nrn_prop_data_free(p->type, p->param); + } + if (p->dparam) { + if (p->type == CABLESECTION) { + notify_freed_val_array(&p->dparam[2].val, 6); + } + nrn_prop_datum_free(p->type, p->dparam); + } + if (p->ob) { + hoc_obj_unref(p->ob); + } + free((char *) p); } + /* For now there is always one more node in a section than there are segments */ /* except in section 0 in which all nodes serve as x=0 to connecting @@ -928,7 +939,7 @@ void recalc_diam(void) { void area(void) { /* returns area (um^2) of segment containing x */ double x; Section *sec; - Node *node_ptr(); +// Node *node_ptr(); x = *getarg(1); if (x == 0. || x == 1.) { hoc_retpushx(0.); @@ -945,7 +956,7 @@ void area(void) { /* returns area (um^2) of segment containing x */ void ri(void) { /* returns resistance (Mohm) between center of segment containing x and the center of the parent segment */ double area; - Node *np, *node_ptr(); + Node *np; //, *node_ptr(); np = node_ptr(chk_access(), *getarg(1), &area); if (NODERINV(np)) { hoc_retpushx(1./NODERINV(np)); /* Megohms */ @@ -969,7 +980,7 @@ void pt3dconst(void) { void nrn_pt3dstyle0(Section* sec) { if (sec->logical_connection) { - free((char*)sec->logical_connection); + free(sec->logical_connection); sec->logical_connection = (Pt3d*)0; ++nrn_shape_changed_; diam_changed = 1; @@ -1009,7 +1020,7 @@ void pt3dstyle(void) { if (hoc_is_pdouble_arg(2)) { Pt3d* p = sec->logical_connection; if (p) { - double* px, *hoc_pgetarg(); + double* px; // , *hoc_pgetarg(); px = hoc_pgetarg(2); *px = p->x; px = hoc_pgetarg(3); *px = p->y; px = hoc_pgetarg(4); *px = p->z; @@ -1388,11 +1399,11 @@ static void nrn_translate_shape(Section* sec, float x, float y, float z) void nrn_define_shape(void) { static int changed_; int i, j; - Section* sec, *psec, *ch, *nrn_trueparent(); + Section* sec, *psec, *ch; //, *nrn_trueparent(); float x, y, z, dz, x1, y1; float nch, ich=0.0, angle; double arc, len; - double nrn_connection_position(); +// double nrn_connection_position(); if (changed_ == nrn_shape_changed_ && !diam_changed && !tree_changed) { return; } @@ -1595,7 +1606,7 @@ static double diam_from_list(Section* sec, int inode, Prop* p, double rparent) #endif /*DIAMLIST*/ -#include "multicore.c" +#include "multicore.cpp" #if VECTORIZE void v_setup_vectors(void) { @@ -1622,15 +1633,15 @@ void v_setup_vectors(void) { if (nrn_is_artificial_[i] && memb_func[i].initialize) { if (memb_list[i].nodecount) { memb_list[i].nodecount = 0; - free((char*)memb_list[i].nodelist); + free(memb_list[i].nodelist); #if CACHEVEC free((void *)memb_list[i].nodeindices); #endif /* CACHEVEC */ if (memb_func[i].hoc_mech) { - free((char*)memb_list[i].prop); + free(memb_list[i].prop); }else{ - free((char*)memb_list[i].data); - free((char*)memb_list[i].pdata); + free(memb_list[i].data); + free(memb_list[i].pdata); } } } @@ -1638,7 +1649,7 @@ void v_setup_vectors(void) { #if 1 /* see finitialize */ /* and count the artificial cells */ for (i=0; i < n_memb_func; ++i) if (nrn_is_artificial_[i] && memb_func[i].initialize) { - Template* tmp = nrn_pnt_template_[i]; + cTemplate* tmp = nrn_pnt_template_[i]; memb_list[i].nodecount = tmp->count; } #endif @@ -1707,7 +1718,7 @@ void v_setup_vectors(void) { hoc_Item* q; hoc_List* list; int j, nti; - Template* tmp = nrn_pnt_template_[i]; + cTemplate* tmp = nrn_pnt_template_[i]; memb_list[i].nodecount = tmp->count; nti = 0; j = 0; @@ -1854,7 +1865,7 @@ void node_data(void) { #endif -void nrn_complain(double* pp) { +extern "C" void nrn_complain(double* pp) { /* print location for this param on the standard error */ Node* nd; hoc_Item* qsec; @@ -1880,20 +1891,20 @@ void nrn_matrix_node_free(void) { NrnThread* nt; FOR_THREADS(nt) { if (nt->_actual_rhs) { - free((char*)nt->_actual_rhs); + free(nt->_actual_rhs); nt->_actual_rhs = (double*)0; } if (nt->_actual_d) { - free((char*)nt->_actual_d); + free(nt->_actual_d); nt->_actual_d = (double*)0; } #if CACHEVEC if (nt->_actual_a) { - free((char*)nt->_actual_a); + free(nt->_actual_a); nt->_actual_a = (double*)0; } if (nt->_actual_b) { - free((char*)nt->_actual_b); + free(nt->_actual_b); nt->_actual_b = (double*)0; } /* because actual_v and actual_area have pointers to them from many @@ -1911,7 +1922,7 @@ void nrn_matrix_node_free(void) { /* 0 means no model, 1 means ODE, 2 means DAE */ int nrn_modeltype(void) { NrnThread* nt; - static Template* lm = (Template*)0; + static cTemplate* lm = (cTemplate*)0; int type; v_setup_vectors(); @@ -2133,7 +2144,7 @@ void nrn_old_thread_save(void) { static double* (*recalc_ptr_)(double*); -double* nrn_recalc_ptr(double* old) { +extern "C" double* nrn_recalc_ptr(double* old) { if (recalc_ptr_) { return (*recalc_ptr_)(old); } if (!recalc_ptr_old_vp_) { return old; } if (nrn_isdouble(old, 0.0, (double)recalc_cnt_)) { @@ -2145,7 +2156,7 @@ double* nrn_recalc_ptr(double* old) { return old; } -void nrn_register_recalc_ptr_callback(Pfrv f) { +extern "C" void nrn_register_recalc_ptr_callback(Pfrv f) { if (n_recalc_ptr_callback >= 20) { Printf("More than 20 recalc_ptr_callback functions\n"); exit(1); @@ -2165,7 +2176,7 @@ void nrn_recalc_ptrs(double*(*r)(double*)) { for (i=0; i < n_recalc_ptr_callback; ++i) { (*recalc_ptr_callback[i])(); } - recalc_ptr_ = (void*)0; + recalc_ptr_ = nullptr; } void nrn_recalc_node_ptrs(void) { @@ -2221,7 +2232,7 @@ void nrn_recalc_node_ptrs(void) { } } - nrn_recalc_ptrs((void*)0); + nrn_recalc_ptrs(nullptr); /* now that all the pointers are updated we update the NODEV */ ii = 0; @@ -2230,18 +2241,18 @@ void nrn_recalc_node_ptrs(void) { nd->_v = recalc_ptr_new_vp_[ii]; ++ii; } - free((char*)recalc_ptr_old_vp_); - free((char*)recalc_ptr_new_vp_); + free(recalc_ptr_old_vp_); + free(recalc_ptr_new_vp_); recalc_ptr_old_vp_ = (double**)0; recalc_ptr_new_vp_ = (double**)0; /* and free the old thread arrays if new ones were allocated */ for (i = 0; i < n_old_thread_; ++i) { if (old_actual_v_[i]) hoc_free_val_array(old_actual_v_[i], old_actual_v_size_[i]); - if (old_actual_area_[i]) free((char*)old_actual_area_[i]); + if (old_actual_area_[i]) free(old_actual_area_[i]); } - free((char*)old_actual_v_size_); - free((char*)old_actual_v_); - free((char*)old_actual_area_); + free(old_actual_v_size_); + free(old_actual_v_); + free(old_actual_area_); old_actual_v_size_ = 0; old_actual_v_ = 0; old_actual_area_ = 0; @@ -2253,3 +2264,4 @@ void nrn_recalc_node_ptrs(void) { } #endif /* CACHEVEC */ + diff --git a/src/nrnpython/CMakeLists.txt b/src/nrnpython/CMakeLists.txt index 298f923f0c..4d0d3a7e60 100644 --- a/src/nrnpython/CMakeLists.txt +++ b/src/nrnpython/CMakeLists.txt @@ -88,7 +88,7 @@ else() endif() # rxdmath libraries (always build) -add_library(rxdmath SHARED ${CMAKE_CURRENT_SOURCE_DIR}/rxdmath.c) +add_library(rxdmath SHARED ${CMAKE_CURRENT_SOURCE_DIR}/rxdmath.cpp) install(TARGETS rxdmath DESTINATION ${NRN_INSTALL_SHARE_LIB_DIR}) # ============================================================================= diff --git a/src/nrnpython/Makefile.am b/src/nrnpython/Makefile.am index 1bf86d8cf8..b83d70b77f 100755 --- a/src/nrnpython/Makefile.am +++ b/src/nrnpython/Makefile.am @@ -23,9 +23,9 @@ endif endif libnrnpython@npy_pyver10@_la_SOURCES = nrnpython.cpp nrnpy_hoc.cpp nrnpy_nrn.cpp \ - nrnpy_p2h.cpp grids.cpp rxd.cpp rxd_extracellular.cpp rxd_intracellular.cpp rxd_vol.cpp rxd_marching_cubes.c rxd_llgramarea.c $(EXTEND) + nrnpy_p2h.cpp grids.cpp rxd.cpp rxd_extracellular.cpp rxd_intracellular.cpp rxd_vol.cpp rxd_marching_cubes.cpp rxd_llgramarea.cpp $(EXTEND) -librxdmath_la_SOURCES = rxdmath.c $(EXTEND) +librxdmath_la_SOURCES = rxdmath.cpp $(EXTEND) noinst_HEADERS = nrnpython.h nrnwrap_Python.h nrnpy_reg.h \ nrnpy_hoc_2.h nrnpy_hoc_3.h \ diff --git a/src/nrnpython/grids.cpp b/src/nrnpython/grids.cpp index 6619b6fdbe..2a0cd66c0d 100644 --- a/src/nrnpython/grids.cpp +++ b/src/nrnpython/grids.cpp @@ -192,7 +192,7 @@ ECS_Grid_node::ECS_Grid_node(PyHocObject* my_states, int my_num_states_x, // Insert a Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids /* returns the grid number TODO: change this to returning the pointer */ -int ECS_insert(int grid_list_index, PyHocObject* my_states, int my_num_states_x, +extern "C" int ECS_insert(int grid_list_index, PyHocObject* my_states, int my_num_states_x, int my_num_states_y, int my_num_states_z, double my_dc_x, double my_dc_y, double my_dc_z, double my_dx, double my_dy, double my_dz, PyHocObject* my_alpha, PyHocObject* my_lambda, int bc, double bc_value, @@ -351,7 +351,7 @@ ICS_Grid_node::ICS_Grid_node(PyHocObject* my_states, long num_nodes, long* neigh // Insert a Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids /* returns the grid number TODO: change this to returning the pointer */ -int ICS_insert(int grid_list_index, PyHocObject* my_states, long num_nodes, long* neighbors, +extern "C" int ICS_insert(int grid_list_index, PyHocObject* my_states, long num_nodes, long* neighbors, long* x_line_defs, long x_lines_length, long* y_line_defs, long y_lines_length, long* z_line_defs, long z_lines_length, double* dcs, double dx, bool is_diffusable, double atolscale, double* ics_alphas) { @@ -372,7 +372,7 @@ int ICS_insert_inhom(int grid_list_index, PyHocObject* my_states, long num_nodes } -int set_diffusion(int grid_list_index, int grid_id, double* dc, int length) +extern "C" int set_diffusion(int grid_list_index, int grid_id, double* dc, int length) { int id = 0; diff --git a/src/nrnpython/grids.h b/src/nrnpython/grids.h index 83272ece70..5263cd6fb3 100644 --- a/src/nrnpython/grids.h +++ b/src/nrnpython/grids.h @@ -363,7 +363,7 @@ void make_dt_ptr(PyHocObject* my_dt_ptr); //void free_Grid(Grid_node *grid); // Insert a Grid_node "new_Grid" into the list located at grid_list_index in Parallel_grids -extern "C" int ECS_insert(int grid_list_index, PyHocObject* my_states, int my_num_states_x, +extern "C" int ECS_insert(int grid_list_index, PyHocObject* my_states, int my_num_states_x, int my_num_states_y, int my_num_states_z, double my_dc_x, double my_dc_y, double my_dc_z, double my_dx, double my_dy, double my_dz, PyHocObject* my_alpha, PyHocObject* my_lambda, int, double, double); diff --git a/src/nrnpython/hoccontext.h b/src/nrnpython/hoccontext.h index 65b005d588..669ad6bb2f 100644 --- a/src/nrnpython/hoccontext.h +++ b/src/nrnpython/hoccontext.h @@ -1,7 +1,6 @@ #ifndef hoccontext_h #define hoccontext_h -extern "C" { extern Object* hoc_thisobject; extern Objectdata* hoc_top_level_data; @@ -40,5 +39,4 @@ static void hc_restore_(HocContext* hc) { hoc_objectdata = hc->obd; hoc_symlist = hc->sl; } -} #endif diff --git a/src/nrnpython/inithoc.cpp b/src/nrnpython/inithoc.cpp index 8a5674bbe9..f87a3ae102 100644 --- a/src/nrnpython/inithoc.cpp +++ b/src/nrnpython/inithoc.cpp @@ -16,7 +16,12 @@ #define NRNPYTHON_DYNAMICLOAD PY_MAJOR_VERSION #endif -extern "C" { + +extern int nrn_is_python_extension; +extern int nrn_nobanner_; +extern int ivocmain(int, const char**, const char**); +extern int nrn_main_launch; + // int nrn_global_argc; extern char** nrn_global_argv; @@ -44,10 +49,6 @@ extern int nrnpy_site_problem; #define HOCMOD(a, b) a #endif -extern int nrn_is_python_extension; -extern int nrn_nobanner_; -extern int ivocmain(int, char**, char**); -extern int nrn_main_launch; #ifdef NRNMPI @@ -64,7 +65,7 @@ static int argc_nompi = 1; static pthread_t main_thread_; #endif -static void nrnpython_finalize() { +void nrnpython_finalize() { #if USE_PTHREAD pthread_t now = pthread_self(); if (pthread_equal(main_thread_, now)) { @@ -101,9 +102,9 @@ void HOCMOD(inithoc, NRNPYTHON_DYNAMICLOAD)() { #else // ! defined __MINGW32__ #if PY_MAJOR_VERSION >= 3 -PyObject* PyInit_hoc() { +extern "C" PyObject* PyInit_hoc() { #else //!PY_MAJOR_VERSION >= 3 -void inithoc() { +extern "C" void inithoc() { #endif //!PY_MAJOR_VERSION >= 3 #endif // ! defined __MINGW32__ @@ -256,7 +257,7 @@ void inithoc() { } nrn_main_launch = 2; - ivocmain(argc, argv, env); + ivocmain(argc, (const char**)argv, (const char**)env); // nrnpy_augment_path(); #if NRNPYTHON_DYNAMICLOAD nrnpy_site_problem = 0; @@ -269,6 +270,6 @@ void inithoc() { } #if !defined(CYGWIN) -void modl_reg() {} +extern "C" void modl_reg() {} #endif // !defined(CYGWIN) -} +// diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index 3dadb9deed..1e10486a58 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -38,7 +38,6 @@ typedef struct { PyObject* cell_; } NPySecObj; -extern "C" { #include "parse.h" extern void (*nrnpy_sectionlist_helper_)(void*, Object*); @@ -48,7 +47,7 @@ extern char** (*nrnpy_gui_helper3_str_)(const char*, Object*, int); extern double (*nrnpy_object_to_double_)(Object*); extern void* (*nrnpy_get_pyobj)(Object* obj); extern void (*nrnpy_decref)(void* pyobj); -void lvappendsec_and_ref(void* sl, Section* sec); +extern void lvappendsec_and_ref(void* sl, Section* sec); extern Section* nrn_noerr_access(); extern void hoc_pushs(Symbol*); extern double* hoc_evalpointer(); @@ -91,19 +90,20 @@ extern IvocVect* (*nrnpy_vec_from_python_p_)(void*); extern Object** (*nrnpy_vec_to_python_p_)(void*); extern Object** (*nrnpy_vec_as_numpy_helper_)(int, double*); extern Object* (*nrnpy_rvp_rxd_to_callable)(Object*); -int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*)); // called by ctypes. -int nrnpy_set_gui_callback(PyObject*); +extern "C" int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*)); // called by ctypes. +extern "C" int nrnpy_set_gui_callback(PyObject*); extern double** nrnpy_setpointer_helper(PyObject*, PyObject*); extern Symbol* ivoc_alias_lookup(const char* name, Object* ob); -extern int nrn_netcon_weight(void*, double**); +class NetCon; +extern int nrn_netcon_weight(NetCon*, double**); extern int nrn_matrix_dim(void*, int); extern NPySecObj* newpysechelp(Section* sec); extern PyObject* pmech_types; // Python map for name to Mechanism extern PyObject* rangevars_; // Python map for name to Symbol -extern "C" int hoc_max_builtin_class_id; -extern "C" int hoc_return_type_code; +extern /*"C"*/ int hoc_max_builtin_class_id; +extern /*"C"*/ int hoc_return_type_code; static cTemplate* hoc_vec_template_; static cTemplate* hoc_list_template_; @@ -131,9 +131,7 @@ static const char* hocobj_docstring = "class neuron.hoc.HocObject - Hoc Object wrapper"; #if 1 -} #include -extern "C" { #else extern Object* hoc_thisobject; #define HocTopContextSet \ @@ -742,7 +740,7 @@ static PyObject* hocobj_call(PyHocObject* self, PyObject* args, for (int i = 0; i < n; ++i) { PyObject* key = PyList_GetItem(keys, i); PyObject* value = PyDict_GetItem(kwrds, key); - printf("%s %s\n", PyString_AsString(key), PyString_AsString(PyObject_Str(value))); + printf("%s %s\n", PyUnicode_AsUTF8(key), PyUnicode_AsUTF8(PyObject_Str(value))); } #endif section = PyDict_GetItemString(kwrds, "sec"); @@ -776,7 +774,7 @@ static PyObject* hocobj_call(PyHocObject* self, PyObject* args, result = (PyObject*)oj->fpycall(fcall, (void*)self, (void*)args); delete oj; if (result == NULL) { - PyErr_SetString(PyExc_RuntimeError, "hoc error"); + PyErr_SetString(PyExc_RuntimeError, "hocobj_call error"); } } else { result = (PyObject*)fcall((void*)self, (void*)args); @@ -886,7 +884,7 @@ static void eval_component(PyHocObject* po, int ix) { --po->nindex_; } -PyObject* nrn_hocobj_ptr(double* pd) { +extern "C" PyObject* nrn_hocobj_ptr(double* pd) { PyObject* result = hocobj_new(hocobject_type, 0, 0); PyHocObject* po = (PyHocObject*)result; po->type_ = PyHoc::HocScalarPtr; @@ -1517,7 +1515,7 @@ static int araylen(Arrayinfo* a, PyHocObject* po) { n = vector_capacity((IvocVect*)po->ho_->u.this_pointer); } else if (po->sym_ == sym_netcon_weight) { double* w; - n = nrn_netcon_weight(po->ho_->u.this_pointer, &w); + n = nrn_netcon_weight(static_cast(po->ho_->u.this_pointer), &w); } else if (po->sym_ == nrn_child_sym) { n = nrn_secref_nchild((Section*)po->ho_->u.this_pointer); } else if (po->sym_ == sym_mat_x) { @@ -2260,7 +2258,7 @@ static char* double_array_interface(PyObject* po, long& stride) { } Py_DECREF(ai); } - return (char*)data; + return static_cast(data); } static IvocVect* nrnpy_vec_from_python(void* v) { @@ -2322,12 +2320,12 @@ static IvocVect* nrnpy_vec_from_python(void* v) { } static PyObject* (*vec_as_numpy)(int, double*); -int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*)) { +extern "C" int nrnpy_set_vec_as_numpy(PyObject* (*p)(int, double*)) { vec_as_numpy = p; return 0; } -int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, PyObject* plotshape_plot0, PyObject* get_mech_object_0) { +extern "C" int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, PyObject* plotshape_plot0, PyObject* get_mech_object_0) { rvp_plot = rvp_plot0; plotshape_plot = plotshape_plot0; get_mech_object_ = get_mech_object_0; @@ -2335,7 +2333,7 @@ int nrnpy_set_toplevel_callbacks(PyObject* rvp_plot0, PyObject* plotshape_plot0, } static PyObject* gui_callback=NULL; -int nrnpy_set_gui_callback(PyObject* new_gui_callback) { +extern "C" int nrnpy_set_gui_callback(PyObject* new_gui_callback) { gui_callback = new_gui_callback; return 0; } @@ -2558,7 +2556,7 @@ static Object* rvp_rxd_to_callable_(Object* obj) { } -PyObject* get_plotshape_data(PyObject* sp) { +extern "C" PyObject* get_plotshape_data(PyObject* sp) { PyHocObject* pho = (PyHocObject*) sp; ShapePlotInterface* spi; if (!is_obj_type(pho->ho_, "PlotShape")) { @@ -2720,7 +2718,7 @@ static PyObject* hocpickle_setstate(PyObject* self, PyObject* args) { BYTESWAP(x[i], double) } } - memcpy((char*)vector_vec(vec), datastr, len); + memcpy(vector_vec(vec), datastr, len); Py_DECREF(rawdata); Py_INCREF(Py_None); return Py_None; @@ -2790,12 +2788,12 @@ static void add2topdict(PyObject* dict) { static PyObject* nrnpy_vec_math = NULL; -int nrnpy_vec_math_register(PyObject* callback) { +extern "C" int nrnpy_vec_math_register(PyObject* callback) { nrnpy_vec_math = callback; return 0; } -int nrnpy_rvp_pyobj_callback_register(PyObject* callback) { +extern "C" int nrnpy_rvp_pyobj_callback_register(PyObject* callback) { nrnpy_rvp_pyobj_callback = callback; return 0; } @@ -3101,4 +3099,3 @@ myPyMODINIT_FUNC nrnpy_hoc() { return; #endif } -} // end of extern c diff --git a/src/nrnpython/nrnpy_nrn.cpp b/src/nrnpython/nrnpy_nrn.cpp index 6045426016..2a7f24628b 100644 --- a/src/nrnpython/nrnpy_nrn.cpp +++ b/src/nrnpython/nrnpy_nrn.cpp @@ -8,7 +8,6 @@ #define M_PI (3.14159265358979323846) #endif -extern "C" { #include #include extern void nrn_pt3dremove(Section* sec, int i0); @@ -102,7 +101,7 @@ extern void nrn_length_change(Section*, double); extern int diam_changed; extern void mech_insert1(Section*, int); extern void mech_uninsert1(Section*, Symbol*); -extern PyObject* nrn_hocobj_ptr(double*); +extern "C" PyObject* nrn_hocobj_ptr(double*); extern int nrn_is_hocobj_ptr(PyObject*, double*&); extern PyObject* nrnpy_forall(PyObject* self, PyObject* args); extern Object* nrnpy_po2ho(PyObject*); @@ -2467,4 +2466,3 @@ void nrnpy_unreg_mech(int type) { // not implemented but needed when KSChan name changed. } -} // end of extern c diff --git a/src/nrnpython/nrnpy_p2h.cpp b/src/nrnpython/nrnpy_p2h.cpp index 46bfa0f8fa..8eab363118 100644 --- a/src/nrnpython/nrnpy_p2h.cpp +++ b/src/nrnpython/nrnpy_p2h.cpp @@ -8,7 +8,6 @@ #include #include "nrnpy_utils.h" -extern "C" { #include "parse.h" extern void hoc_nopop(); extern void hoc_pop_defer(); @@ -52,7 +51,7 @@ typedef struct { } NPySecObj; extern NPySecObj* newpysechelp(Section* sec); extern void (*nrnpy_call_python_with_section)(Object*, Section*); -void nrnpython_reg_real(); +extern "C" void nrnpython_reg_real(); PyObject* nrnpy_ho2po(Object*); void nrnpy_decref_defer(PyObject*); PyObject* nrnpy_pyCallObject(PyObject*, PyObject*); @@ -81,7 +80,6 @@ static hoc_List* dlist; extern int nrnpy_site_problem; extern int* nrnpy_site_problem_p; #endif -} class Py2Nrn { public: @@ -112,7 +110,7 @@ static void call_python_with_section(Object* pyact, Section* sec) { } -void nrnpython_reg_real() { +extern "C" void nrnpython_reg_real() { //printf("nrnpython_reg_real()\n"); class2oc("PythonObject", p_cons, p_destruct, p_members, NULL, NULL, NULL); Symbol* s = hoc_lookup("PythonObject"); @@ -377,7 +375,7 @@ void nrnpy_decref_defer(PyObject* po) { } #if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 3) -// copied from /Modules/_ctypes/_ctypes.c +// copied from /Modules/_ctypes/_ctypes.cpp static PyObject* PyTuple_Pack(int n, ...) { int i; PyObject* o; diff --git a/src/nrnpython/nrnpy_reg.h b/src/nrnpython/nrnpy_reg.h index 8c72a11a43..73f0ccc4cd 100644 --- a/src/nrnpython/nrnpy_reg.h +++ b/src/nrnpython/nrnpy_reg.h @@ -1,6 +1,4 @@ -extern "C" { extern myPyMODINIT_FUNC nrnpy_hoc(); extern myPyMODINIT_FUNC nrnpy_nrn(); static myPyMODINIT_FUNC (*nrnpy_reg_[])() = {nrnpy_hoc, nrnpy_nrn, 0}; -} diff --git a/src/nrnpython/nrnpython.cpp b/src/nrnpython/nrnpython.cpp index a04ae7992a..aaccd6604f 100644 --- a/src/nrnpython/nrnpython.cpp +++ b/src/nrnpython/nrnpython.cpp @@ -11,10 +11,9 @@ #include #include // bool isDirExist(const std::string& path); -extern "C" { #include -void nrnpython_real(); -void nrnpython_start(int); +extern "C" void nrnpython_real(); +extern "C" void nrnpython_start(int); extern int hoc_get_line(); extern HocStr* hoc_cbufstr; extern int nrnpy_nositeflag; @@ -35,7 +34,6 @@ static char* nrnpython_getline(FILE*, FILE*, char*); #else static char* nrnpython_getline(char*); #endif -extern void rl_stuff_char(int); extern int nrn_global_argc; extern char** nrn_global_argv; void nrnpy_augment_path(); @@ -46,7 +44,10 @@ extern char** nrn_global_argv; #if NRNPYTHON_DYNAMICLOAD int nrnpy_site_problem; #endif -} + +extern "C" { +extern void rl_stuff_char(int); +} // extern "C" void nrnpy_augment_path() { static int augmented = 0; @@ -104,7 +105,7 @@ int nrnpy_pyrun(const char* fname) { the C runtime that this DLL uses. Using PyFile_AsFile is a work-around... */ - PyObject* pfo = PyFile_FromString((char*)fname, (char*)"r"); + PyObject* pfo = PyFile_FromString(fname, (char*)"r"); if (pfo == NULL) { PyErr_Print(); PyErr_Clear(); @@ -151,7 +152,7 @@ static void del_wcargv(int argc) { static void copy_argv_wcargv(int argc, char** argv) { del_wcargv(argc); - // basically a copy of code from Modules/python.c + // basically a copy of code from Modules/python.cpp wcargv = (wchar_t**)PyMem_Malloc(sizeof(wchar_t*) * argc); if (!wcargv) { fprintf(stderr, "out of memory\n"); @@ -196,7 +197,7 @@ static wchar_t* mywstrdup(char* s) { } #endif -void nrnpython_start(int b) { +extern "C" void nrnpython_start(int b) { #if USE_PYTHON static int started = 0; //printf("nrnpython_start %d started=%d\n", b, started); @@ -285,7 +286,7 @@ void nrnpython_start(int b) { #endif } -void nrnpython_real() { +extern "C" void nrnpython_real() { int retval = 0; #if USE_PYTHON HocTopContextSet @@ -314,9 +315,9 @@ static char* nrnpython_getline(char* prompt) { size_t n = strlen(hoc_cbufstr->buf) + 1; hoc_ctp = hoc_cbufstr->buf + n - 1; #if (PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 4) - char* p = (char*)PyMem_RawMalloc(n); + char* p = static_cast(PyMem_RawMalloc(n)); #else - char* p = (char*)PyMem_MALLOC(n); + char* p = static_cast(PyMem_MALLOC(n)); #endif if (p == 0) { return 0; @@ -325,9 +326,9 @@ static char* nrnpython_getline(char* prompt) { return p; } else if (r == EOF) { #if (PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 4) - char* p = (char*)PyMem_RawMalloc(2); + char* p = static_cast(PyMem_RawMalloc(2)); #else - char* p = (char*)PyMem_MALLOC(2); + char* p = static_cast(PyMem_MALLOC(2)); #endif if (p == 0) { return 0; diff --git a/src/nrnpython/nrnpython.h b/src/nrnpython/nrnpython.h index 15563a0f38..f84ab72f7c 100644 --- a/src/nrnpython/nrnpython.h +++ b/src/nrnpython/nrnpython.h @@ -47,9 +47,6 @@ #define PyInt_FromLong PyLong_FromLong #endif -#if defined(__cplusplus) -extern "C" { -#endif extern PyObject* nrnpy_hoc_pop(); extern int nrnpy_numbercheck(PyObject*); @@ -60,8 +57,5 @@ extern int nrnpy_numbercheck(PyObject*); #define castptr2long (long) #endif -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/nrnpython/nrnpython_config.h.in b/src/nrnpython/nrnpython_config.h.in index f91ad2b15d..ee179e6a70 100755 --- a/src/nrnpython/nrnpython_config.h.in +++ b/src/nrnpython/nrnpython_config.h.in @@ -1,5 +1,5 @@ #ifndef H_nrnpython_config_included -#define H_nrnpython_config_included 1 +#define H_nrnpython_config_included // 1 /* Define if Python available */ #undef USE_PYTHON /* Define to sys.api_version if dynamic loading desired */ diff --git a/src/nrnpython/rxd.h b/src/nrnpython/rxd.h index 412806d16c..71893fb093 100644 --- a/src/nrnpython/rxd.h +++ b/src/nrnpython/rxd.h @@ -1,7 +1,7 @@ -extern "C"{ +extern "C" { #include #include -} +} // extern "C" /*borrowed from Meschach Version 1.2b*/ #define v_get_val(x,i) ((x)->ve[(i)]) #define m_get_val(A,i,j) ((A)->me[(i)][(j)]) diff --git a/src/nrnpython/rxd_extracellular.cpp b/src/nrnpython/rxd_extracellular.cpp index 52050fa278..5ad1446dcb 100644 --- a/src/nrnpython/rxd_extracellular.cpp +++ b/src/nrnpython/rxd_extracellular.cpp @@ -667,7 +667,7 @@ void _fadvance_fixed_step_3D(void) { scatter_concentrations(); } -void scatter_concentrations(void) { +extern "C" void scatter_concentrations(void) { /* transfer concentrations to classic NEURON */ Grid_node* grid; diff --git a/src/nrnpython/rxd_intracellular.cpp b/src/nrnpython/rxd_intracellular.cpp index 5fdff038d8..125e8ec5d5 100644 --- a/src/nrnpython/rxd_intracellular.cpp +++ b/src/nrnpython/rxd_intracellular.cpp @@ -4,9 +4,7 @@ #include #include "grids.h" #include "rxd.h" -extern "C" { - #include -} +#include #include #include #include diff --git a/src/nrnpython/rxd_llgramarea.c b/src/nrnpython/rxd_llgramarea.cpp similarity index 82% rename from src/nrnpython/rxd_llgramarea.c rename to src/nrnpython/rxd_llgramarea.cpp index 86dd7462f9..a711957655 100644 --- a/src/nrnpython/rxd_llgramarea.c +++ b/src/nrnpython/rxd_llgramarea.cpp @@ -1,6 +1,6 @@ #include -double llgramarea(double* p0, double* p1, double* p2) { +extern "C" double llgramarea(double* p0, double* p1, double* p2) { /* setup the vectors */ double a[] = {p0[0] - p1[0], p0[1] - p1[1], p0[2] - p1[2]}; double b[] = {p0[0] - p2[0], p0[1] - p2[1], p0[2] - p2[2]}; @@ -13,7 +13,7 @@ double llgramarea(double* p0, double* p1, double* p2) { } -double llpipedfromoriginvolume(double* p0, double* p1, double* p2) { +extern "C" double llpipedfromoriginvolume(double* p0, double* p1, double* p2) { /* take the cross-product */ double cpx = p1[1] * p2[2] - p1[2] * p2[1]; double cpy = p1[2] * p2[0] - p1[0] * p2[2]; diff --git a/src/nrnpython/rxd_marching_cubes.c b/src/nrnpython/rxd_marching_cubes.cpp similarity index 98% rename from src/nrnpython/rxd_marching_cubes.c rename to src/nrnpython/rxd_marching_cubes.cpp index 444e432014..36f83690c0 100644 --- a/src/nrnpython/rxd_marching_cubes.c +++ b/src/nrnpython/rxd_marching_cubes.cpp @@ -338,7 +338,7 @@ void vi(double* p1, double* p2, double v1, double v2, double* out) { out[2] = p1[2] + mu * (p2[2] - p1[2]); } -int find_triangles(double value0, double value1, double value2, double value3, double value4, double value5, double value6, double value7, double x0, double x1, double y0, double y1, double z0, double z1, double* out) { +extern "C" int find_triangles(double value0, double value1, double value2, double value3, double value4, double value5, double value6, double value7, double x0, double x1, double y0, double y1, double z0, double z1, double* out) { double position[8][3] = {{x0, y0, z0}, {x1, y0, z0}, {x1, y1, z0}, diff --git a/src/nrnpython/rxdmath.c b/src/nrnpython/rxdmath.cpp similarity index 100% rename from src/nrnpython/rxdmath.c rename to src/nrnpython/rxdmath.cpp diff --git a/src/nrnpython/setup.py.in b/src/nrnpython/setup.py.in index 4fdb124276..a858e7bcaa 100644 --- a/src/nrnpython/setup.py.in +++ b/src/nrnpython/setup.py.in @@ -217,7 +217,7 @@ if not using_cmake and build_rx3d: define_macros = define_macros, include_dirs=include_dirs), Extension("neuron.rxd.geometry3d.surfaces", - sources=[build_path + "surfaces.cpp", nrn_srcdir + "/src/nrnpython/rxd_marching_cubes.c", nrn_srcdir + "/src/nrnpython/rxd_llgramarea.c"], + sources=[build_path + "surfaces.cpp", nrn_srcdir + "/src/nrnpython/rxd_marching_cubes.cpp", nrn_srcdir + "/src/nrnpython/rxd_llgramarea.cpp"], define_macros = define_macros, extra_compile_args = extra_compile_args, include_dirs=include_dirs)] diff --git a/src/oc/Makefile.am b/src/oc/Makefile.am index 20a2c82f9c..04eaa5bba3 100755 --- a/src/oc/Makefile.am +++ b/src/oc/Makefile.am @@ -7,35 +7,35 @@ includes = -I$(nsrc) -I$(nsrc)/memacs -I$(nsrc)/sparse -I$(nsrc)/nrnmpi -I$(nsrc AM_CPPFLAGS = -DOOP=1 -DINTERVIEWS=1 -DHOC=1 $(includes) AM_CFLAGS = @MINGW_CFLAG@ -RanFiles = isaac64.c mcran4.c nrnisaac.c nrnran123.c +RanFiles = isaac64.cpp mcran4.cpp nrnisaac.cpp nrnran123.cpp if BUILD_NRNMPI_DYNAMIC nrnmpila = -nrnmpidynam = nrnmpi_dynam.c +nrnmpidynam = nrnmpi_dynam.cpp else nrnmpila = ../nrnmpi/libnrnmpi.la nrnmpidynam = endif -liboc_la_SOURCES = parse.y bksub.c getelm.c lineq.c subrows.c prmat.c \ - code2.c debug.c ocerf.c fileio.c ftime.c \ - getsym.c hoc.c hocedit.c math.c nonlin.c \ - list.c regexp.c audit.c symbol.c \ - version.c xred.c parallel.c functabl.c plot.c plt.c axis.c \ - settext.c x.c fmenu.c termio.c isoc99.c $(nrnmpidynam)\ - scoprand.c $(RanFiles) cygwinprt.c nrnfilewrap.c +liboc_la_SOURCES = parse.y bksub.cpp getelm.cpp lineq.cpp subrows.cpp prmat.cpp \ + code2.cpp debug.cpp ocerf.cpp fileio.cpp ftime.cpp \ + getsym.cpp hoc.cpp hocedit.cpp math.cpp nonlin.cpp \ + list.cpp regexp.cpp audit.cpp symbol.cpp \ + version.cpp xred.cpp parallel.cpp functabl.cpp plot.cpp plt.cpp axis.cpp \ + settext.cpp x.cpp termio.cpp isoc99.cpp $(nrnmpidynam)\ + scoprand.cpp $(RanFiles) cygwinprt.cpp nrnfilewrap.cpp ## MAC OS X does not allow multiple definitions in separate dyld files ## therefore we create a separate library for the oc objects that ## should appear in oc and ivoc but not nrnoc and nrniv -## modlreg.c is another special case since it should be missing only +## modlreg.cpp is another special case since it should be missing only ## in a special so we will put it explicitly into nrnoc and nrniv -libocxt_la_SOURCES = code.c hoc_init.c hoc_oop.c \ - spinit.c spinit1.c spinit2.c +libocxt_la_SOURCES = code.cpp hoc_init.cpp hoc_oop.cpp \ + spinit.cpp spinit1.cpp spinit2.cpp AM_YFLAGS = -d -EXTRA_DIST = mk_hocusr_h.py hocusr.c macprt.c mswinprt.c system.c \ +EXTRA_DIST = mk_hocusr_h.py hocusr.cpp macprt.cpp mswinprt.cpp system.cpp \ $(nrnmpidynam) if BUILD_MINGW @@ -46,9 +46,9 @@ endif bin_PROGRAMS = oc -## modlreg.c is here because the newer libtool no longer +## modlreg.cpp is here because the newer libtool no longer ## always makes a .o link to the .lo file -oc_SOURCES = ocmain.c ocnoiv.c nocable.c modlreg.c ockludge.c +oc_SOURCES = ocmain.cpp ocnoiv.cpp nocable.cpp modlreg.cpp ockludge.cpp oc_LDADD = libocxt.la liboc.la \ $(nrnmpila) \ @@ -68,7 +68,7 @@ pkginclude_HEADERS = hoc.h hoclist.h hocdec.h hocassrt.h nrnisaac.h \ ## to be installed: noinst_HEADERS = code.h equation.h hocmodl.h hocstr.h \ profile.h redef.h parse.h mcran4.h nrnmpi.h nrnrt.h isaac64.h \ - nrnfilewrap.h nrn_vsscanf.c classreg.h + nrnfilewrap.h nrn_vsscanf.cpp classreg.h ## files that depend on the existence of parse.h ## this allows parallel make -j to work at the beginning when parse.h diff --git a/src/oc/audit.c b/src/oc/audit.cpp similarity index 98% rename from src/oc/audit.c rename to src/oc/audit.cpp index 230f93406d..a792b8c8c6 100755 --- a/src/oc/audit.c +++ b/src/oc/audit.cpp @@ -5,6 +5,7 @@ #include #include "hocassrt.h" + static int doaudit; static FILE* faudit; static FILE* audit_pipe; @@ -158,8 +159,8 @@ void hoc_audit_from_emacs(const char *bufname, const char *filname) char fname[200]; char s[256]; FILE* f; - extern char* hoc_pipegets(); - static int n=0; + char* hoc_pipegets(char* cbuf, int nc); + static int n=0; if (!doaudit) { return; diff --git a/src/oc/axis.c b/src/oc/axis.cpp similarity index 98% rename from src/oc/axis.c rename to src/oc/axis.cpp index 5e62b2cc19..a36690f3aa 100755 --- a/src/oc/axis.c +++ b/src/oc/axis.cpp @@ -1,7 +1,7 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/axis.c,v 1.2 1999/01/04 13:04:55 hines Exp */ +/* /local/src/master/nrn/src/oc/axis.cpp,v 1.2 1999/01/04 13:04:55 hines Exp */ /* -axis.c,v +axis.cpp,v * Revision 1.2 1999/01/04 13:04:55 hines * fabs now from include math.h * @@ -19,7 +19,7 @@ axis.c,v * non numbers. * * Revision 1.8 92/10/14 10:07:55 hines - * move oc specific stuff out of axis.c and into code2.c + * move oc specific stuff out of axis.cpp and into code2.cpp * new argument function hoc_pgetarg checks for double pointer on stack * and returns it. * hoc_val_pointer(string) returns a pointer to the variable resulting @@ -79,7 +79,7 @@ axis.c,v * try to get dos and unix together again in one RCS directory * * Revision 3.93 90/08/09 09:19:21 hines - * axis.c placement of labels slightly lowered to look good with FIG + * axis.cpp placement of labels slightly lowered to look good with FIG * * Revision 3.83 90/07/25 10:39:56 hines * almost lint free on sparc 1+ under sunos 4.1 @@ -136,6 +136,8 @@ axis.c,v #include #include "hoc.h" #include "gui-redirect.h" + + extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); extern double (*nrnpy_object_to_double_)(Object*); @@ -661,3 +663,5 @@ static void do_setup(void) { } initialized = 1; } + + diff --git a/src/oc/bksub.c b/src/oc/bksub.c deleted file mode 100755 index 152c7b9300..0000000000 --- a/src/oc/bksub.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <../../nrnconf.h> -/* - * Automake doesn't deal well with sources that live in other directories, so - * this is a quick and dirty workaround. - */ -#include "../sparse/bksub.c" diff --git a/src/oc/bksub.cpp b/src/oc/bksub.cpp new file mode 100755 index 0000000000..a6e317c151 --- /dev/null +++ b/src/oc/bksub.cpp @@ -0,0 +1,6 @@ +#include <../../nrnconf.h> +/* + * Automake doesn't deal well with sources that live in other directories, so + * this is a quick and dirty workaround. + */ +#include "../sparse/bksub.cpp" diff --git a/src/oc/classreg.h b/src/oc/classreg.h index acafa50e75..1c1417b485 100644 --- a/src/oc/classreg.h +++ b/src/oc/classreg.h @@ -5,9 +5,6 @@ #include #include -#if defined(__cplusplus) -extern "C" { -#endif extern void class2oc(const char*, void* (*cons)(Object*), @@ -18,8 +15,5 @@ extern void class2oc(const char*, Member_ret_str_func* ); -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/oc/code.cpp b/src/oc/code.cpp new file mode 100755 index 0000000000..49f82752f9 --- /dev/null +++ b/src/oc/code.cpp @@ -0,0 +1,2668 @@ +#include <../../nrnconf.h> +/* /local/src/master/nrn/src/oc/code.cpp,v 1.37 1999/07/03 14:20:21 hines Exp */ + +#if defined(__GO32__) +#include +#endif + +#include +#include "hoc.h" +#include "code.h" +#include "hocstr.h" +#include "parse.h" +#include "ocfunc.h" +#include "ocmisc.h" +#include "hocparse.h" +#include "equation.h" +#include +#include +#include +#include +#include "nrnfilewrap.h" + + + +#if CABLE +#include "options.h" +#include "section.h" + + + +int bbs_poll_; +extern void bbs_handle(void); +#define BBSPOLL if (--bbs_poll_ == 0) { bbs_handle(); } + +int nrn_isecstack(); +#else +#define BBSPOLL /**/ +#endif + +extern void debugzz(Inst*); +int hoc_return_type_code = 0; /* flag for allowing integers (1) and booleans (2) to be recognized as such */ + +# define STACKCHK if (stackp >= stacklast) \ + execerror("Stack too deep.", "Increase with -NSTACK stacksize option"); + +int tstkchk_actual(int i, int j) { + int k, l; + char *s[2]; + if (i != j) { + for (k = 0, l = i; k < 2; k++, l = j) { + switch (l) { + case NUMBER: + s[k] = (char *) "(double)"; + break; + case STRING: + s[k] = (char *) "(char *)"; + break; + case OBJECTVAR: + s[k] = (char *) "(Object **)"; + break; + case USERINT: + s[k] = (char *) "(int)"; + break; + case SYMBOL: + s[k] = (char *) "(Symbol)"; + break; + case VAR: + s[k] = (char *) "(double *)"; + break; + case OBJECTTMP: /* would use OBJECT if it existed */ + s[k] = (char *) "(Object *)"; + break; + case STKOBJ_UNREF:/* hoc_stkobj_unref allready called */ + s[k] = (char *) "(Object * already unreffed on stack)"; + break; + default: + s[k] = (char *) "(Unknown)"; + break; + } + } + fprintf(stderr, "bad stack access: expecting %s; really %s\n", s[1], s[0]); + execerror("interpreter stack type error", (char *) 0); + } + return 0; +} + +#define USEMACROS 1 + +/* warning! tstkchk(i,j) when i!=j will call execerror and error recovery + now uses stackp to recover OBJECTTMP resources. So it must be the case that + stackp - stack is an even number (since stack item, itemtype values + use a pair of stack locations). This invalidates the previous pop idiom + tstkchk((--stackp)->i, type), (--stackp)->val)) since if tstkchk calls + execerror without returning, stackp is no longer consistent since the + second decrement no longer takes place. + + Furthermore, tstkchk(i,j) should be called prior to actually popping the + stack so that the execerror will properly unref the otherwise unexpected + possible OBJECTTMP. +*/ + +#if USEMACROS +/* warning! tstkchk is a macro that uses each arg twice. So error if + the arg in the call has side effects. Eg avoid args like --stackp +*/ +#define tstkchk(i, j) (((i)!=(j))?tstkchk_actual(i,j):0) +#define pushxm(d) ((stackp++)->val = (d));((stackp++)->i = NUMBER) +#define pushsm(d) ((stackp++)->sym = (d));((stackp++)->i = SYMBOL) +#define nopopm() (stackp -= 2) /*provision at use made to deal with OBJECTTMP*/ +#define xpopm() (tstkchk(stackp[-1].i, NUMBER), nopopm(), stackp->val) +#define spopm() (tstkchk(stackp[-1].i, SYMBOL), nopopm(), stackp->sym) +#else +#define pushxm(d) pushx(d) +#define pushsm(d) pushs(d) +#define xpopm() xpop() +#define spopm() spop() +#define nopopm() nopop() +#define tstkchk(i,j) tstkchk_actual(i,j) +#endif + +#define EPS hoc_epsilon + +#define NSTACK 1000 /* default size */ +#define nstack hoc_nstack + +// TODO - ugly but workable for now +namespace std { +#define stack stlstack +} + +static Datum *stack; /* the stack */ +static Datum *stackp; /* next free spot on stack */ +static Datum *stacklast; /* last stack element */ + +#define NPROG 50000 +Inst *prog; /* the machine */ +Inst *progp; /* next free spot for code generation */ +Inst *pc; /* program counter during execution */ +Inst *progbase; /* start of current subprogram */ +Inst *prog_parse_recover; /* start after parse error */ +int hoc_returning; /* 1 if return stmt seen, 2 if break, 3 if continue */ +/* 4 if stop */ +typedef struct Frame { /* proc/func call stack frame */ + Symbol *sp; /* symbol table entry */ + Inst *retpc; /* where to resume after return */ + Datum *argn; /* n-th argument on stack */ + int nargs; /* number of arguments */ + Inst *iter_stmt_begin; /* Iterator statement starts here */ + Object *iter_stmt_ob; /* context of Iterator statement */ + Object *ob; /* for stack frame debug message */ +} Frame; +#define NFRAME 512 /* default size */ +#define nframe hoc_nframe +static Frame *frame, *fp, *framelast; /* first, frame pointer, last */ + +/* temporary object references come from this pool. This allows the +stack to be aware if it is storing a temporary. We are trying to +solve problems of objrefs on the stack changing the object they point +to and also a failure of garbage collection since temporary objrefs have +not, in the past, been reffed or unreffed. +The first problem is easily solved without much efficiency loss +by having the stack store the object pointer instead of the objref pointer. + +Garbage collection is implemented by reffing any object that is placed +on the stack via hoc_push_object (and thus borrows the use of the +type OBJECTTMP) It is then the responsibility of everything that +pops an object to determine whether the object should be unreffed. +This is also done on error recovery and when the stack frame is popped. +I hate the efficiency loss but it is not as bad as it could be +since most popping occurs when the stack frame is popped and in this +case it is faster to check for OBJECTTMP than if the returned Object** +is from the pool. +*/ +#define DEBUG_GARBAGE 1 +#define TOBJ_POOL_SIZE 50 +static Object **hoc_temp_obj_pool_; +static int obj_pool_index_; +static int tobj_count; /* how many stack pushes of OBJECTTMP have been reffed*/ + +/* +Here is the old comment on the function when it was in hoc_oop.cpp. + +At this time we are dealing uniformly with object variables and cannot +deal cleanly with objects. Eventually it may be possible to put an +object pointer on the stack but not now. Try to avoid using "functions +which return new objects" as arguments to other functions. If this is +done then it may happen that when the stack pointer is finally used it +may point to a different object than when it was put on the stack. +Things are safe when a temp_objvar is finally removed from the stack. +Memory leakage will occur if a temp_objvar is passed as an arg but never +assigned to a full fledged object variable. ie its reference count is 0 +but unref will never be called on it. +The danger is illustrated with + proc p(obj.func_returning_object()) { // $o1 is on the stack + print $o1 // correct object + for i=0,100 { + o = obj.func_returning_different_object() + print i, $o1 //when i=50 $o1 will be different + } + } +In this case one should first assign $o1 to another object variable +and then use that object variable exclusively instead of $o1. +This also prevent leakage of the object pointed to by $o1. + +If this ever becomes a problem then it is not too difficult to +implement objects on the stack with garbage collection. +*/ + +Object **hoc_temp_objptr(Object *obj) { + Object **tobj; + obj_pool_index_ = (obj_pool_index_ + 1) % TOBJ_POOL_SIZE; + tobj = hoc_temp_obj_pool_ + obj_pool_index_; + *tobj = obj; + return tobj; +} + +/* should be called after finished with pointer from a popobj */ + +void hoc_tobj_unref(Object **p) { + if (p >= hoc_temp_obj_pool_ && p < hoc_temp_obj_pool_ + TOBJ_POOL_SIZE) { + --tobj_count; + hoc_obj_unref(*p); + } +} + +/* +vec.cpp.x[0] used freed memory because the temporary vector was unreffed +after the x pointer was put on the stack but before it was evaluated. +The hoc_pop_defer replaces the nopop in in hoc_object_component handling +of a cplus steer method (which pushes a double pointer). The corresponding +hoc_unref_defer takes place in hoc_object_eval after evaluating +the pointer. This should take care of the most common (itself very rare) +problem. However it still would not in general +take care of the purposeless passing +of &vec.cpp.x[0] as an argument to a function since intervening pop_defer/unref_defer +pairs could take place. +*/ +static Object *unref_defer_; + +void hoc_unref_defer(void) { + if (unref_defer_) { +#if 0 + printf("hoc_unref_defer %s %d\n", hoc_object_name(unref_defer_), unref_defer_->refcount); +#endif + hoc_obj_unref(unref_defer_); + unref_defer_ = nullptr; + } +} + +void hoc_pop_defer(void) { + Object *obj; + if (unref_defer_) { +#if 0 + printf("hoc_pop_defer unrefs %s %d\n", hoc_object_name(unref_defer_), unref_defer_->refcount); +#endif + hoc_unref_defer(); + } + if (stackp <= stack) + execerror("stack underflow", (char *) 0); + if (stackp[-1].i == OBJECTTMP) { + unref_defer_ = stackp[-2].obj; + if (unref_defer_) { + ++unref_defer_->refcount; + } +#if 0 + printf("hoc_pop_defer %s %d\n", hoc_object_name(unref_defer_), unref_defer_->refcount); +#endif + } + hoc_nopop(); +} + +/* should be called on each OBJECTTMP on the stack after adjusting the +stack pointer downward */ + +void hoc_stkobj_unref(Object *o, int stkindex) { + if (stack[stkindex + 1].i == OBJECTTMP) { + --tobj_count; + hoc_obj_unref(o); + stack[stkindex + 1].i = STKOBJ_UNREF; + } +} + +/* check the args of the frame and unref any of type OBJECTTMP */ + +static void frameobj_clean(Frame *f) { + Datum *s; + int i, narg; + if (f->nargs == 0) { + return; + } + s = f->argn + 2; + for (i = f->nargs - 1; i >= 0; --i) { + s -= 2; + if (s[1].i == OBJECTTMP) { + hoc_stkobj_unref(s->obj, (int) (s - stack)); + } + } +} + +/* unref items on the stack frame associated with localobj in case of error */ +static void frame_objauto_recover_on_err(Frame *ff) { /* only on error */ + Frame *f; + for (f = fp; f > ff; --f) { + int i; + Symbol *sp = f->sp; + /* argn is the nargs argument on the stack. Stack items come in pairs + so stack increments are always multiples of 2. + Here, stkp is the last+1 localobj slot pair on the stack. + */ + Datum *stkp = f->argn + 2 + sp->u.u_proc->nauto * 2; + for (i = sp->u.u_proc->nobjauto; i > 0; --i) { + Object *ob = stkp[-2 * i].obj; + hoc_obj_unref(ob); + /* Note that these AUTOOBJECT stack locations have an itemtype that + are left over from the previous stack usage of that location. + Regardless of that itemtype (e.g. OBJECTTMP), these did NOT + increment tobj_count so we need to guarantee that the subsequent + stack_obtmp_recover_on_err does not inadvertently free it again + by setting the itemtype to a non OBJECTTMP value. I hope this is + the only place where stack space was used in which no item type + was specified. + We are doing this here which happens rarely to avoid having to + set them when the stack obj pointers are zeroed. + */ + stkp[-2 * i + 1].i = 0; + } + } +} + +static void stack_obtmp_recover_on_err(int tcnt) { + if (tobj_count > tcnt) { + Datum *stkp; + /* stackp - 2 because stackp is next available stack slot and + stack item,itemtype takes up two slots. + */ + for (stkp = stackp - 2; stkp >= stack; stkp -= 2) { + if (stkp[1].i == OBJECTTMP) { + hoc_stkobj_unref(stkp->obj, (int) (stkp - stack)); + if (tobj_count == tcnt) { + return; + } + } else if (stkp[1].i == STKOBJ_UNREF) { + printf("OBJECTTMP at stack index %ld already unreffed\n", stkp - stack); + } + } + } +} + +void hoc_init_space(void) /* create space for stack and code */ +{ + if (nframe == 0) { + nframe = NFRAME; + } + if (nstack == 0) { + nstack = NSTACK; + } + stackp = stack = (Datum *) emalloc(sizeof(Datum) * nstack); + stacklast = stack + nstack; + progp = progbase = prog = (Inst *) emalloc(sizeof(Inst) * NPROG); + fp = frame = (Frame *) emalloc(sizeof(Frame) * nframe); + framelast = frame + nframe; + hoc_temp_obj_pool_ = (Object **) emalloc(sizeof(Object *) * TOBJ_POOL_SIZE); +} + +#define MAXINITFCNS 10 +static int maxinitfcns; +static Pfrv initfcns[MAXINITFCNS]; + +void hoc_prstack(void) { + int i; + Datum *s; + Printf("interpreter stack: %ld \n", (stackp - stack) / 2); + for (i = 0, s = stackp - 1; s > stack; --s, ++i) { + if (i > 10) { + Printf("...\n"); + break; + } + Printf("%d stacktype=%d\n", i, s->i); + --s; + } +} + +void hoc_on_init_register(Pfrv pf) { + /* modules that may have to be cleaned up after an execerror */ + if (maxinitfcns < MAXINITFCNS) { + initfcns[maxinitfcns++] = pf; + } else { + fprintf(stderr, "increase definition for MAXINITFCNS\n"); + nrn_exit(1); + } +} + +void initcode(void) /* initialize for code generation */ +{ + int i; + errno = 0; + if (hoc_errno_count > 5) { + fprintf(stderr, "errno set %d times on last execution\n", hoc_errno_count); + } + hoc_errno_count = 0; + prog_parse_recover = progbase = prog; + progp = progbase; + hoc_unref_defer(); + + frame_objauto_recover_on_err(frame); + if (tobj_count) { + stack_obtmp_recover_on_err(0); +#if DEBUG_GARBAGE + if (tobj_count) { + printf("initcode failed with %d left\n", tobj_count); + } +#endif + tobj_count = 0; + } + stackp = stack; + fp = frame; + free_list(&p_symlist); + hoc_returning = 0; + do_equation = 0; + for (i = 0; i < maxinitfcns; ++i) { + (*initfcns[i])(); + } +#if CABLE + nrn_initcode(); /* special requirements for NEURON */ +#endif +} + + +static Frame *rframe; +static Datum *rstack; +static const char *parsestr; + +extern "C" void oc_save_code( + Inst **a1, + Inst **a2, + Datum **a3, + Frame **a4, + int *a5, + int *a6, + Inst **a7, + Frame **a8, + Datum **a9, + Symlist **a10, + Inst **a11, + int *a12 +) { + *a1 = progbase; + *a2 = progp; + *a3 = stackp; + *a4 = fp; + *a5 = hoc_returning; + *a6 = do_equation; + *a7 = pc; + *a8 = rframe; + *a9 = rstack; + *a10 = p_symlist; + *a11 = prog_parse_recover; + *a12 = tobj_count; +} + +extern "C" void oc_restore_code( + Inst **a1, + Inst **a2, + Datum **a3, + Frame **a4, + int *a5, + int *a6, + Inst **a7, + Frame **a8, + Datum **a9, + Symlist **a10, + Inst **a11, + int *a12 +) { + progbase = *a1; + progp = *a2; + frame_objauto_recover_on_err(*a4); + if (tobj_count > *a12) { + stack_obtmp_recover_on_err(*a12); +#if DEBUG_GARBAGE + if (tobj_count != *a12) { + printf("oc_restore_code tobj_count=%d should be %d\n", tobj_count, *a12); + } +#endif + } + stackp = *a3; + fp = *a4; + hoc_returning = *a5; + do_equation = *a6; + pc = *a7; + rframe = *a8; + rstack = *a9; + p_symlist = *a10; + prog_parse_recover = *a11; +} + +int hoc_strgets_need(void) { + return strlen(parsestr); +} + +char *hoc_strgets(char *cbuf, int nc) {/* getc for a string, used by parser */ + strncpy(cbuf, parsestr, nc); + if (*parsestr == '\0') { + return (char *) 0; + } else { + return cbuf; + } +} + +static void rinitcode(void) /* initialize for recursive code generation */ +{ + errno = 0; + hoc_errno_count = 0; + prog_parse_recover = progbase; + progp = progbase; + stackp = rstack; + fp = rframe; + free_list(&p_symlist); + if (hoc_returning != 4) { /* if stop not seen */ + hoc_returning = 0; + } + do_equation = 0; +} + +int hoc_ParseExec(int yystart) { + /* can recursively parse and execute what is in cbuf. + may parse single tokens. called from hoc_oc(str). + All these parse and execute routines should be combined into + a single method robust method. The pipeflag method has become + encrusted with too many irrelevant mechanisms. There is no longer + anything sacred about the cbuf. The only requiremnent is to tell + the get line function where to get its string. + */ + int yret; + + Frame *sframe, *sfp; + Inst *sprogbase, *sprogp, *spc, *sprog_parse_recover; + Datum *sstackp, *sstack; + Symlist *sp_symlist; + + if (yystart) { + sframe = rframe; + sfp = fp; + sprogbase = progbase; + sprogp = progp; + spc = pc, + sprog_parse_recover = prog_parse_recover; + sstackp = stackp; + sstack = rstack; + sp_symlist = p_symlist; + rframe = fp; + rstack = stackp; + progbase = progp; + p_symlist = (Symlist *) 0; + } + + if (yystart) { + rinitcode(); + } + if (hoc_in_yyparse) { + hoc_execerror("Cannot reenter parser.", + "Maybe you were in the middle of a direct command."); + } + yret = yyparse(); + switch (yret) { + case 1: + execute(progbase); + rinitcode(); + break; + case -3 : + hoc_execerror("incomplete statement parse not allowed\n", (char *) 0); + default: + break; + } + if (yystart) { + rframe = sframe; + fp = sfp; + progbase = sprogbase; + progp = sprogp; + pc = spc; + prog_parse_recover = sprog_parse_recover; + stackp = sstackp; + rstack = sstack; + p_symlist = sp_symlist; + } + + return yret; +} + +int hoc_xopen_run(Symbol *sp, const char *str) { /*recursively parse and execute for xopen*/ +/* if sp != 0 then parse string and save code */ +/* without executing. Note str must be a 'list'*/ + int n = 0; + Frame *sframe = rframe, *sfp = fp; + Inst *sprogbase = progbase, *sprogp = progp, *spc = pc, + *sprog_parse_recover = prog_parse_recover; + Datum *sstackp = stackp, *sstack = rstack; + Symlist *sp_symlist = p_symlist; + rframe = fp; + rstack = stackp; + progbase = progp; + p_symlist = (Symlist *) 0; + + if (sp == (Symbol *) 0) { + for (rinitcode(); hoc_yyparse(); rinitcode()) + execute(progbase); + } else { + int savpipeflag; + rinitcode(); + savpipeflag = hoc_pipeflag; + hoc_pipeflag = 2; + parsestr = str; + if (!hoc_yyparse()) { + execerror("Nothing to parse", (char *) 0); + } + n = (int) (progp - progbase); + hoc_pipeflag = savpipeflag; + hoc_define(sp); + rinitcode(); + } + rframe = sframe; + fp = sfp; + progbase = sprogbase; + progp = sprogp; + pc = spc; + prog_parse_recover = sprog_parse_recover; + stackp = sstackp; + rstack = sstack; + p_symlist = sp_symlist; + return n; +} + +#define HOC_TEMP_CHARPTR_SIZE 128 +static char *stmp[HOC_TEMP_CHARPTR_SIZE]; +static int istmp = 0; + +char **hoc_temp_charptr(void) { + istmp = (istmp + 1) % HOC_TEMP_CHARPTR_SIZE; + return stmp + istmp; +} + +int hoc_is_temp_charptr(char **cpp) { + if (cpp >= stmp && cpp < stmp + HOC_TEMP_CHARPTR_SIZE) { + return 1; + } + return 0; +} + +int hoc_stack_type(void) { + return stackp[-1].i; +} + +void pushx(double d) { /* push double onto stack */ + STACKCHK + (stackp++)->val = d; + (stackp++)->i = NUMBER; +} + +void hoc_pushobj(Object **d) { /* push pointer to object pointer onto stack */ + STACKCHK + if (d >= hoc_temp_obj_pool_ && d < (hoc_temp_obj_pool_ + TOBJ_POOL_SIZE)) { + hoc_push_object(*d); + return; + } + (stackp++)->pobj = d; + (stackp++)->i = OBJECTVAR; +} + +void hoc_push_object(Object *d) { /* push pointer to object onto stack */ + STACKCHK + (stackp++)->obj = d; + (stackp++)->i = OBJECTTMP; /* would use OBJECT if it existed */ + hoc_obj_ref(d); + ++tobj_count; +} + +void hoc_pushstr(char **d) { /* push pointer to string pointer onto stack */ + STACKCHK + (stackp++)->pstr = d; + (stackp++)->i = STRING; +} + +void hoc_push_string(void) { /* code for pushing a symbols string */ + Objectdata *odsav; + Object *obsav = 0; + Symlist *slsav; + Symbol *s; + s = (pc++)->sym; + if (!s) { + hoc_pushstr((char **) 0); + return; + } + if (s->type == CSTRING) { + hoc_pushstr(&(s->u.cstr)); + } else { + if (s->cpublic == 2) { + s = s->u.sym; + odsav = hoc_objectdata_save(); + obsav = hoc_thisobject; + slsav = hoc_symlist; + hoc_objectdata = hoc_top_level_data; + hoc_thisobject = 0; + hoc_symlist = hoc_top_level_symlist; + } + hoc_pushstr(OPSTR(s)); + if (obsav) { + hoc_objectdata = hoc_objectdata_restore(odsav); + hoc_thisobject = obsav; + hoc_symlist = slsav; + } + } +} + +void hoc_pushpx(double *d) { /* push double pointer onto stack */ + STACKCHK + (stackp++)->pval = d; + (stackp++)->i = VAR; +} + +void pushs(Symbol *d) { /* push symbol pointer onto stack */ + STACKCHK + (stackp++)->sym = d; + (stackp++)->i = SYMBOL; +} + +void pushi(int d) { /* push integer onto stack */ + STACKCHK + (stackp++)->i = d; + (stackp++)->i = USERINT; +} + +int hoc_stacktype(void) { + if (stackp <= stack) { + execerror("stack empty", (char *) 0); + } + return (stackp - 1)->i; +} + +int hoc_argtype(int narg) { /* type of nth arg */ + if (narg > fp->nargs) + execerror(fp->sp->name, "not enough arguments"); + return (fp->argn[(narg - fp->nargs) * 2 + 1].i); +} + +int hoc_is_double_arg(int narg) { + return (hoc_argtype(narg) == NUMBER); +} + +int hoc_is_pdouble_arg(int narg) { + return (hoc_argtype(narg) == VAR); +} + +int hoc_is_str_arg(int narg) { + return (hoc_argtype(narg) == STRING); +} + +int hoc_is_object_arg(int narg) { + int type = hoc_argtype(narg); + return (type == OBJECTVAR || type == OBJECTTMP); +} + +extern "C" int hoc_is_tempobj_arg(int narg) { + return (hoc_argtype(narg) == OBJECTTMP); +} + +Datum *hoc_look_inside_stack(int i, int type) {/* stack pointer at depth i; i=0 is top */ + tstkchk((stackp - 2 * i - 1)->i, type); + return stackp - 2 * (i + 1); +} + +Object *hoc_obj_look_inside_stack(int i) { /* stack pointer at depth i; i=0 is top */ + Datum *d = stackp - 2 * i - 2; + int type = d[1].i; + if (type == OBJECTTMP) { + return d[0].obj; + } + tstkchk(type, OBJECTVAR); + return *(d[0].pobj); +} + +int hoc_obj_look_inside_stack_index(int i) { + return (int) ((stackp - 2 * i - 2) - stack); +} + +int hoc_inside_stacktype(int i) { /* 0 is top */ + return (stackp - 2 * i - 1)->i; +} + +double xpop(void) { /* pop double and return top elem from stack */ + if (stackp <= stack) + execerror("stack underflow", (char *) 0); + tstkchk(stackp[-1].i, NUMBER); + stackp -= 2; + return stackp->val; +} + +#if 0 +void pstack(void) { + char* hoc_object_name(); + Datum* d; + int i; + for (d=stackp; d > stack;) { + i = (--d)->i; + --d; + switch(i) { + case NUMBER: + printf("(double)\n"); + break; + case STRING: + printf("(char *)\n"); + break; + case OBJECTVAR: + printf("(Object **) %s\n", hoc_object_name(*(d->pobj))); + break; + case USERINT: + printf("(int)\n"); + break; + case SYMBOL: + printf("(Symbol) %s\n", d->sym); + break; + case VAR: + printf("(double *)\n"); + break; + case OBJECTTMP: /* would use OBJECT if it existed */ + printf("(Object *) %s\n", hoc_object_name(d->obj)); + break; + case STKOBJ_UNREF: /* hoc_stkobj_ref already called */ + printf("(Object * already unreffed by hoc_stkobj_ref at stkindex %ld. Following name print may cause a crash if already freed.\n", d - stack); + printf(" %s\n", hoc_object_name(d->obj)); + break; + default: + printf("(Unknown)\n"); + break; + } + } +} +#endif + +double *hoc_pxpop(void) {/* pop double pointer and return top elem from stack */ + if (stackp <= stack) + execerror("stack underflow", (char *) 0); + tstkchk(stackp[-1].i, VAR); + stackp -= 2; + return stackp->pval; +} + +Symbol *spop(void) {/* pop symbol pointer and return top elem from stack */ + if (stackp <= stack) + execerror("stack underflow", (char *) 0); + tstkchk(stackp[-1].i, SYMBOL); + stackp -= 2; + return stackp->sym; +} + +/* +When using objpop, after dealing with the pointer, one should call + hoc_tobj_unref(pobj) in order to prevent memory leakage since + the object may have been reffed when it was pushed on the stack +*/ + +Object **hoc_objpop(void) {/* pop pointer to object pointer and return top elem from stack */ + if (stackp <= stack) + execerror("stack underflow", (char *) 0); + stackp -= 2; + if (stackp[1].i == OBJECTTMP) { + return hoc_temp_objptr(stackp->obj); + } + tstkchk(stackp[1].i, OBJECTVAR); /* safe because cannot be OBJECTTMP */ + return stackp->pobj; +} + +Object *hoc_pop_object(void) {/* pop object and return top elem from stack */ + if (stackp <= stack) + execerror("stack underflow", (char *) 0); + tstkchk(stackp[-1].i, OBJECTTMP); + stackp -= 2; + return stackp->obj; +} + +char **hoc_strpop(void) { /* pop pointer to string pointer and return top elem from stack */ + if (stackp <= stack) + execerror("stack underflow", (char *) 0); + tstkchk(stackp[-1].i, STRING); + stackp -= 2; + return stackp->pstr; +} + +int ipop(void) {/* pop symbol pointer and return top elem from stack */ + if (stackp <= stack) + execerror("stack underflow", (char *) 0); + tstkchk(stackp[-1].i, USERINT); + stackp -= 2; + return stackp->i; +} + +void nopop(void) {/* just pop the stack without returning anything */ + if (stackp <= stack) + execerror("stack underflow", (char *) 0); + stackp -= 2; + if (stackp[1].i == OBJECTTMP) { + hoc_stkobj_unref(stackp->obj, (int) (stackp - stack)); + } +} + +void constpush(void) /* push constant onto stack */ +{ + pushxm(*((pc++)->sym)->u.pnum); +} + +void pushzero(void) /* push zero onto stack */ +{ + pushxm(0.); +} + +void varpush(void) /* push variable onto stack */ +{ + pushsm((pc++)->sym); +} + +# define relative(pc) (pc + (pc)->i) + +void forcode(void) { + double d; + Inst *savepc = pc; /* loop body */ + int isec; + +#if CABLE + isec = nrn_isecstack(); +#endif + execute(savepc + 3); /* condition */ + d = xpopm(); + while (d) { + execute(relative(savepc)); /* body */ +#if CABLE + if (hoc_returning) {nrn_secstack(isec);} +#endif + if (hoc_returning == 1 || hoc_returning == 4) /* return or stop */ + break; + else if (hoc_returning == 2) /* break */ + { + hoc_returning = 0; + break; + } else /* continue */ + hoc_returning = 0; + if ((savepc + 2)->i) /* diff between while and for */ + execute(relative(savepc + 2)); /* increment */ + execute(savepc + 3); + d = xpopm(); + } + if (!hoc_returning) + pc = relative(savepc + 1); /* next statement */ +} + +void shortfor(void) { + Inst *savepc = pc; + double begin, end, *pval = 0; + Symbol *sym; + int isec; + + end = xpopm() + EPS; + begin = xpopm(); + sym = spopm(); + + switch (sym->type) { + case UNDEF: + hoc_execerror(sym->name, "undefined variable"); + case VAR: + if (!ISARRAY(sym)) { + if (sym->subtype == USERINT) { + execerror("integer iteration variable", sym->name); + } else if (sym->subtype == USERDOUBLE) { + pval = sym->u.pval; + } else { + pval = OPVAL(sym); + } + break; + } else { + if (sym->subtype == USERINT) + execerror("integer iteration variable", sym->name); + else if (sym->subtype == USERDOUBLE) + pval = sym->u.pval + araypt(sym, SYMBOL); + else + pval = OPVAL(sym) + araypt(sym, OBJECTVAR); + } + break; + case AUTO: + pval = &(fp->argn[sym->u.u_auto * 2].val); + break; + default: + execerror("for loop non-variable", sym->name); + } +#if CABLE + isec = nrn_isecstack(); +#endif + for (*pval = begin; *pval <= end; *pval += 1.) { + execute(relative(savepc)); +#if CABLE + if (hoc_returning) {nrn_secstack(isec);} +#endif + if (hoc_returning == 1 || hoc_returning == 4) { + break; + } else if (hoc_returning == 2) { + hoc_returning = 0; + break; + } else { + hoc_returning = 0; + } + } + if (!hoc_returning) + pc = relative(savepc + 1); +} + +void hoc_iterator(void) { + /* pc is ITERATOR symbol, argcount, stmtbegin, stmtend */ + /* for testing execute stmt once */ + Symbol *sym; + int argcount; + Inst *stmtbegin, *stmtend; + + sym = (pc++)->sym; + argcount = (pc++)->i; + stmtbegin = relative(pc); + stmtend = relative(pc + 1);; + hoc_iterator_object(sym, argcount, stmtbegin, stmtend, hoc_thisobject); +} + +void hoc_iterator_object( + Symbol *sym, + int argcount, + Inst *beginpc, + Inst *endpc, + Object *ob +) { + int i; + fp++; + if (fp >= framelast) { + fp--; + execerror(sym->name, "call nested too deeply, increase with -NFRAME framesize option"); + } + fp->sp = sym; + fp->nargs = argcount; + fp->retpc = endpc; + fp->argn = stackp - 2; + stackp += sym->u.u_proc->nauto * 2; + /* clear the autoobject pointers */ + for (i = sym->u.u_proc->nobjauto; i > 0; --i) { + stackp[-2 * i].obj = nullptr; + } + fp->iter_stmt_begin = beginpc; + fp->iter_stmt_ob = ob; + fp->ob = ob; + STACKCHK + execute(sym->u.u_proc->defn.in); + nopop(); /* 0.0 from the procret() */ + if (hoc_returning != 4) { + hoc_returning = 0; + } +} + +void hoc_iterator_stmt(void) { + Inst *pcsav; + Object *ob; + Object *obsav; + Objectdata *obdsav; + Symlist *slsav; + int isec; + Frame *iter_f = fp; /* iterator frame */ + Frame *ef = fp - 1; /* iterator statement frame */ + fp++; /* execution frame */ + + fp->sp = iter_f->sp; + fp->ob = iter_f->ob; + if (ef != frame) { + /*SUPPRESS 26*/ + fp->argn = ef->argn; + fp->nargs = ef->nargs; + } else { /* top. only for stack trace */ + fp->argn = 0; + fp->nargs = 0; + } + + ob = iter_f->iter_stmt_ob; + obsav = hoc_thisobject; + obdsav = hoc_objectdata_save(); + slsav = hoc_symlist; + hoc_thisobject = ob; + if (ob) { + hoc_objectdata = ob->u.dataspace; + hoc_symlist = ob->ctemplate->symtable; + } else { + hoc_objectdata = hoc_top_level_data; + hoc_symlist = hoc_top_level_symlist; + } + + pcsav = pc; +#if CABLE + isec = nrn_isecstack(); +#endif + execute(iter_f->iter_stmt_begin); + pc = pcsav; + hoc_objectdata = hoc_objectdata_restore(obdsav); + hoc_thisobject = obsav; + hoc_symlist = slsav; + --fp; +#if CABLE + if (hoc_returning) {nrn_secstack(isec);} +#endif + switch (hoc_returning) { + case 1: /* return means not only return from iter but return from + the procedure containing the iter statement */ + hoc_execerror("return from within an iterator statement not allowed.", + "Set a flag and use break."); + case 2: /* break means return from iter */ + procret(); + break; + case 3: /* continue means go on from iter as though nothing happened*/ + hoc_returning = 0; + break; + } + +} + +static void for_segment2(Symbol *sym, int mode) { + /* symbol on stack; statement pointed to by pc + continuation pointed to by pc+1. template used is shortfor in code.cpp + of hoc system. + */ + +#if CABLE + int i, imax; + Inst *savepc = pc; + double *pval=0, dx; + int isec; +#if METHOD3 + extern int _method3; +#endif + + switch (sym->type) { + case UNDEF: + hoc_execerror(sym->name, "undefined variable"); + case VAR: +if (!ISARRAY(sym)) { + if (sym->subtype == USERINT) + execerror("integer iteration variable", sym->name); + else if (sym->subtype == USERDOUBLE) + pval = sym->u.pval; + else + pval = OPVAL(sym); + break; +} else { + if (sym->subtype == USERINT) + execerror("integer iteration variable", sym->name); + else if (sym->subtype == USERDOUBLE) + pval = sym->u.pval + araypt(sym, SYMBOL); + else + pval = OPVAL(sym) + araypt(sym, OBJECTVAR); +} + break; + case AUTO: + pval = &(fp->argn[sym->u.u_auto*2].val); + break; + default: + execerror("for loop non-variable", sym->name); + } + imax = segment_limits(&dx); +#if METHOD3 + if (_method3) { + for (i=0, *pval=0; i <= imax; i++) { + if (mode == 0 && (i == imax || i == 0)) { continue; } + if (i == imax) { + *pval = 1.; + } else { + *pval = i * dx; + } + execute(relative(savepc)); + if (hoc_returning == 1 || hoc_returning == 4) { + break; + }else if (hoc_returning == 2) { + hoc_returning = 0; + break; + }else{ + hoc_returning = 0; + } + } + }else +#endif + { + if (mode == 0) { + i = 1; + *pval = dx/2.; + }else{ + i = 0; + *pval = 0.; + } +#if CABLE + isec = nrn_isecstack(); +#endif + for (; i <= imax; i++) { + if (i == imax) { + if (mode == 0) { continue; } + *pval = 1.; + } + execute(relative(savepc)); +#if CABLE + if (hoc_returning) {nrn_secstack(isec);} +#endif + if (hoc_returning == 1 || hoc_returning == 4) { + break; + }else if (hoc_returning == 2) { + hoc_returning = 0; + break; + }else{ + hoc_returning = 0; + } + if (i == 0) { + *pval += dx/2.; + } + else if (i < imax) { + *pval += dx; + } + } + } + if (!hoc_returning) + pc =relative(savepc+1); +#else + execerror("for (var) {stmt} syntax only allowed in CABLE", (char *) 0); +#endif +} + +void for_segment(void) { + for_segment2(spopm(), 1); +} + +void for_segment1(void) { + Symbol *sym; + double d; + int mode; + d = xpopm(); + sym = spopm(); + mode = (fabs(d) < EPS) ? 0 : 1; + for_segment2(sym, mode); +} + +void ifcode(void) { + double d; + Inst *savepc = pc; /* then part */ + + execute(savepc + 3); /* condition */ + d = xpopm(); + if (d) + execute(relative(savepc)); + else if ((savepc + 1)->i) /* else part? */ + execute(relative(savepc + 1)); + if (!hoc_returning) + pc = relative(savepc + 2); /* next stmt */ +} + +void Break(void) /* break statement */ +{ + hoc_returning = 2; +} + +void Continue(void) /* continue statement */ +{ + hoc_returning = 3; +} + +void Stop(void) /* stop statement */ +{ + hoc_returning = 4; +} + +void hoc_define(Symbol *sp) { /* put func/proc in symbol table */ + Inst *inst, *newinst; + + if (sp->u.u_proc->defn.in != STOP) + free((char *) sp->u.u_proc->defn.in); + free_list(&(sp->u.u_proc->list)); + sp->u.u_proc->list = p_symlist; + p_symlist = (Symlist *) 0; + sp->u.u_proc->size = (unsigned) (progp - progbase); + sp->u.u_proc->defn.in = (Inst *) emalloc((unsigned) (progp - progbase) * sizeof(Inst)); + newinst = sp->u.u_proc->defn.in; + for (inst = progbase; inst != progp;) + *newinst++ = *inst++; + progp = progbase; /* next code starts here */ +} + +void frame_debug(void) /* print the call sequence on an execerror */ +{ + Frame *f; + int i, j; + char id[10]; + + if (nrnmpi_numprocs_world > 1) { + sprintf(id, "%d ", nrnmpi_myid_world); + } else { + id[0] = '\0'; + } + for (i = 5, f = fp; f != frame && --i; f = f - 1) { /* print only to depth of 5 */ + for (j = i; j; j--) { + Fprintf(stderr, " "); + } + if (f->ob) { + Fprintf(stderr, "%s%s.%s(", id, hoc_object_name(f->ob), f->sp->name); + } else { + Fprintf(stderr, "%s%s(", id, f->sp->name); + } + for (j = 1; j <= f->nargs;) { + switch (f->argn[(j - f->nargs) * 2 + 1].i) { + case NUMBER: + Fprintf(stderr, "%g", f->argn[(j - f->nargs) * 2].val); + break; + case STRING: { + char *s = *f->argn[(j - f->nargs) * 2].pstr; + if (strlen(s) > 15) { + Fprintf(stderr, "\"%.10s...\"", s); + } else { + Fprintf(stderr, "\"%s\"", s); + } + } + break; + case OBJECTVAR: + Fprintf(stderr, "%s", hoc_object_name(*f->argn[(j - f->nargs) * 2].pobj)); + break; + default: + Fprintf(stderr, "..."); + break; + } + if (++j <= f->nargs) { + Fprintf(stderr, ", "); + } + } + Fprintf(stderr, ")\n"); + } + if (i <= 0) { + Fprintf(stderr, "and others\n"); + } +} + +void push_frame(Symbol *sp, int narg) { /* helpful for explicit function calls */ + if (++fp >= framelast) { + --fp; + execerror(sp->name, "call nested too deeply, increase with -NFRAME framesize option"); + } + fp->sp = sp; + fp->nargs = narg; + fp->argn = stackp - 2; /* last argument */ + fp->ob = hoc_thisobject; +} + +void pop_frame(void) { + int i; + frameobj_clean(fp); + for (i = 0; i < fp->nargs; i++) + nopopm(); /* pop arguments */ + --fp; +} + +void call(void) /* call a function */ +{ + int i, isec; + Symbol *sp = pc[0].sym; /* symbol table entry */ + /* for function */ + if (++fp >= framelast) { + --fp; + execerror(sp->name, "call nested too deeply, increase with -NFRAME framesize option"); + } + fp->sp = sp; + fp->nargs = pc[1].i; + fp->retpc = pc + 2; + fp->ob = hoc_thisobject; + /*SUPPRESS 26*/ + fp->argn = stackp - 2; /* last argument */ + BBSPOLL +#if CABLE + isec = nrn_isecstack(); +#endif + if (sp->type == FUN_BLTIN || sp->type == OBJECTFUNC || sp->type == STRINGFUNC) { + stackp += sp->u.u_proc->nauto * 2; /* Offset stack for auto space */ + STACKCHK + (*(sp->u.u_proc->defn.pf))(); + if (hoc_errno_check()) { + hoc_warning("errno set during call of", sp->name); + } + } else if ((sp->type == FUNCTION || sp->type == PROCEDURE || sp->type == HOCOBJFUNCTION) + && sp->u.u_proc->defn.in != STOP) { + stackp += sp->u.u_proc->nauto * 2; /* Offset stack for auto space */ + STACKCHK + /* clear the autoobject pointers. */ + for (i = sp->u.u_proc->nobjauto; i > 0; --i) { + stackp[-2 * i].obj = nullptr; + } + if (sp->cpublic == 2) { + Objectdata *odsav = hoc_objectdata_save(); + Object *obsav = hoc_thisobject; + Symlist *slsav = hoc_symlist; + + hoc_objectdata = hoc_top_level_data; + hoc_thisobject = 0; + hoc_symlist = hoc_top_level_symlist; + + execute(sp->u.u_proc->defn.in); + + hoc_objectdata = hoc_objectdata_restore(odsav); + hoc_thisobject = obsav; + hoc_symlist = slsav; + } else { + execute(sp->u.u_proc->defn.in); + } + /* the autoobject pointers were unreffed at the ret() */ + + } else { + execerror(sp->name, "undefined function"); + } +#if CABLE + if (hoc_returning) {nrn_secstack(isec);} +#endif + if (hoc_returning != 4) { /*if not stopping */ + hoc_returning = 0; + } +} + +void hoc_fake_call(Symbol *s) { + /*fake it so c code can call functions that ret() */ + /* but these functions better not ask for any arguments */ + /* don't forget a double is left on the stack and returning = 1 */ + /* use the symbol for the function as the argument, only requirement + which is always true is that it has no local variables pushed on + the stack so nauto=0 and nobjauto=0 */ + ++fp; + fp->sp = s; + fp->nargs = 0; + fp->retpc = pc; + fp->ob = 0; +} + +double hoc_call_func(Symbol *s, int narg) { + /* call the symbol as a function, The args better be pushed on the stack + first arg first. */ + if (s->type == BLTIN) { + return (*(s->u.ptr))(xpop()); + } else { + Inst *pcsav; + Inst fc[4]; + fc[0].pf = hoc_call; + fc[1].sym = s; + fc[2].i = narg; + fc[3].in = STOP; + + pcsav = hoc_pc; + hoc_execute(fc); + hoc_pc = pcsav; + return hoc_xpop(); + } +} + +void hoc_ret(void) { /* common return from func, proc, or iterator */ + int i; + /* unref all the auto object pointers */ + for (i = fp->sp->u.u_proc->nobjauto; i > 0; --i) { + hoc_obj_unref(stackp[-2 * i].obj); + } + stackp -= fp->sp->u.u_proc->nauto * 2; /* Pop off the autos */ + frameobj_clean(fp); + for (i = 0; i < fp->nargs; i++) + nopopm(); /* pop arguments */ + pc = (Inst *) fp->retpc; + --fp; + hoc_returning = 1; +} + +void funcret(void) /* return from a function */ +{ + double d; + if (fp->sp->type != FUNCTION) + execerror(fp->sp->name, "(proc or iterator) returns value"); + d = xpopm(); /* preserve function return value */ + ret(); + pushxm(d); +} + +void procret(void) /* return from a procedure */ +{ + if (fp->sp->type == FUNCTION) + execerror(fp->sp->name, + "(func) returns no value"); + if (fp->sp->type == HOCOBJFUNCTION) + execerror(fp->sp->name, + "(obfunc) returns no value"); + ret(); + pushxm(0.); /*will be popped immediately; necessary because caller + may have compiled it as a function*/ +} + +void hocobjret(void) /* return from a hoc level obfunc */ +{ + Object **d; + if (fp->sp->type != HOCOBJFUNCTION) + execerror(fp->sp->name, "objfunc returns objref"); + d = hoc_objpop(); /* preserve function return value */ + if (*d) { (*d)->refcount++; } + ret(); + /*make a temp and ref it in case autoobj returned since ret would + have unreffed it*/ + hoc_push_object(*d); + + if (*d) { (*d)->refcount--; } + hoc_tobj_unref(d); +} + +void hoc_Numarg(void) { + int narg; + Frame *f = fp - 1; + if (f == frame) { + narg = 0; + } else { + narg = f->nargs; + } + ret(); + pushxm((double) narg); +} + +void hoc_Argtype(void) { + int narg, iarg, type, itype = 0; + Frame *f = fp - 1; + if (f == frame) { + execerror("argtype can only be called in a func or proc", 0); + } + iarg = (int) chkarg(1, -1000., 100000.); + if (iarg > f->nargs || iarg < 1) { + itype = -1; + } else { + type = (f->argn[(iarg - f->nargs) * 2 + 1].i); + switch (type) { + case NUMBER: + itype = 0; + break; + case OBJECTVAR: + case OBJECTTMP: + itype = 1; + break; + case STRING: + itype = 2; + break; + case VAR: + itype = 3; + break; + } + } + ret(); + pushxm((double) itype); +} + +extern "C" int ifarg(int narg) { /* true if there is an nth argument */ + if (narg > fp->nargs) + return 0; + return 1; +} + +Object **hoc_objgetarg(int narg) {/* return pointer to nth argument */ + Datum *d; + if (narg > fp->nargs) + execerror(fp->sp->name, "not enough arguments"); + d = fp->argn + (narg - fp->nargs) * 2; + if (d[1].i == OBJECTTMP) { + return hoc_temp_objptr(d[0].obj); + } + tstkchk(d[1].i, OBJECTVAR); + return d[0].pobj; +} + +char **hoc_pgargstr(int narg) { /* return pointer to nth argument */ + char **cpp = NULL; + Symbol *sym; + int type; + if (narg > fp->nargs) + execerror(fp->sp->name, "not enough arguments"); + type = fp->argn[(narg - fp->nargs) * 2 + 1].i; + if (type == STRING) { + cpp = fp->argn[(narg - fp->nargs) * 2].pstr; + } else if (type != SYMBOL) { + execerror("Expecting string argument", (char *) 0); + } else { + sym = fp->argn[(narg - fp->nargs) * 2].sym; + if (sym->type == CSTRING) { + cpp = &sym->u.cstr; + } else if (sym->type == STRING) { + cpp = OPSTR(sym); + } else { + execerror("Expecting string argument", (char *) 0); + } + } + return cpp; +} + +double *hoc_pgetarg(int narg) { /* return pointer to nth argument */ + if (narg > fp->nargs) + execerror(fp->sp->name, "not enough arguments"); + tstkchk(fp->argn[(narg - fp->nargs) * 2 + 1].i, VAR); + return fp->argn[(narg - fp->nargs) * 2].pval; +} + +extern "C" double *getarg(int narg) { /* return pointer to nth argument */ + if (narg > fp->nargs) + execerror(fp->sp->name, "not enough arguments"); +#if 1 + tstkchk(fp->argn[(narg - fp->nargs) * 2 + 1].i, NUMBER); +#endif + return &fp->argn[(narg - fp->nargs) * 2].val; +} + +int hoc_argindex(void) { + int j; + j = (int) xpopm(); + if (j < 1) { + hoc_execerror("arg index i < 1", 0); + } + return j; +} + +void arg(void) /* push argument onto stack */ +{ + int i; + i = (pc++)->i; + if (i == 0) { + i = hoc_argindex(); + } + pushxm(*getarg(i)); +} + +void hoc_stringarg(void) /* push string arg onto stack */ +{ + int i; + i = (pc++)->i; + if (i == 0) { + i = hoc_argindex(); + } + hoc_pushstr(hoc_pgargstr(i)); +} + +double hoc_opasgn(int op, double dest, double src) { + switch (op) { + case '+': + return dest + src; + case '*': + return dest * src; + case '-': + return dest - src; + case '/': + if (src == 0.) { + hoc_execerror("Divide by 0", (char *) 0); + } + return dest / src; + default: + return src; + } +} + +void argassign(void) /* store top of stack in argument */ +{ + double d; + int i, op; + i = (pc++)->i; + if (i == 0) { + i = hoc_argindex(); + } + op = (pc++)->i; + d = xpopm(); + if (op) { + d = hoc_opasgn(op, *getarg(i), d); + } + pushxm(d); /* leave value on stack */ + *getarg(i) = d; +} + +void hoc_argrefasgn(void) { + double d, *pd; + int i, j, op; + i = (pc++)->i; + j = (pc++)->i; + if (i == 0) { + i = hoc_argindex(); + } + op = (pc++)->i; + d = xpopm(); + if (j) { + j = (int) (xpopm() + EPS); + } + pd = hoc_pgetarg(i); + if (op) { + d = hoc_opasgn(op, pd[j], d); + } + pushxm(d); /* leave value on stack */ + pd[j] = d; +} + +void hoc_argref(void) { + int i, j; + double *pd; + i = (pc++)->i; + j = (pc++)->i; + if (i == 0) { + i = hoc_argindex(); + } + pd = hoc_pgetarg(i); + if (j) { + j = (int) (xpopm() + EPS); + } + pushxm(pd[j]); +} + + +void hoc_argrefarg(void) { + double *pd; + int i; + i = (pc++)->i; + if (i == 0) { + i = hoc_argindex(); + } + pd = hoc_pgetarg(i); + hoc_pushpx(pd); +} + +void bltin(void) /* evaluate built-in on top of stack */ +{ + double d; + d = xpopm(); + d = (*((pc++)->sym->u.ptr))(d); + pushxm(d); +} + +extern "C" Symbol *hoc_get_symbol(const char *var) { + Symlist *sl = (Symlist *) 0; + Symbol *prc, *sym; + Inst *last; + prc = hoc_parse_stmt(var, &sl); + hoc_run_stmt(prc); + + last = (Inst *) prc->u.u_proc->defn.in + prc->u.u_proc->size - 1; + if (last[-2].pf == eval) { + sym = last[-3].sym; + } else if (last[-3].pf == rangepoint || last[-3].pf == rangevareval) { + sym = last[-2].sym; + } else if (last[-4].pf == hoc_object_eval) { + sym = last[-10].sym; + } else { + sym = (Symbol *) 0; + } + free_list(&sl); + return sym; +} + +Symbol *hoc_get_last_pointer_symbol(void) {/* hard to imagine a kludgier function*/ + Symbol *sym = (Symbol *) 0; + Inst *pcv; + int istop = 0; + for (pcv = pc; pcv; --pcv) { + if (pcv->pf == hoc_ob_pointer) { + if (pcv[-2].sym) { + sym = pcv[-2].sym; /* e.g. &ExpSyn[0].A */ + } else { + sym = pcv[-6].sym; /* e.g. & Cell[0].soma.v(.5) */ + } + break; + } else if (pcv->pf == hoc_evalpointer) { + sym = pcv[-1].sym; + break; + } else if (pcv->pf == rangevarevalpointer) { + sym = pcv[1].sym; + break; + } else if (pcv->in == STOP) { +/* hopefully only got here from python. Give up on second STOP*/ + if (istop++ == 1) { + break; + } + } + } + return sym; +} + +void hoc_autoobject(void) { /* AUTOOBJ symbol at pc+1. */ + /* pointer to object pointer left on stack */ + int i; + Symbol *obs; + Object **obp; +#if PDEBUG + printf("code for hoc_autoobject()\n"); +#endif + obs = (pc++)->sym; + hoc_pushobj(&(fp->argn[obs->u.u_auto * 2].obj)); +} + +void eval(void) /* evaluate variable on stack */ +{ + Objectdata *odsav; + Object *obsav = 0; + Symlist *slsav; + double d = 0.0; + extern double cable_prop_eval(Symbol *); + Symbol *sym; + sym = spopm(); + if (sym->cpublic == 2) { + sym = sym->u.sym; + odsav = hoc_objectdata_save(); + obsav = hoc_thisobject; + slsav = hoc_symlist; + hoc_objectdata = hoc_top_level_data; + hoc_thisobject = 0; + hoc_symlist = hoc_top_level_symlist; + } + switch (sym->type) { + case UNDEF: + execerror("undefined variable", sym->name); + case VAR: + if (!ISARRAY(sym)) { + if (do_equation && sym->s_varn > 0 + && hoc_access[sym->s_varn] == 0) { + hoc_access[sym->s_varn] = var_access; + var_access = sym->s_varn; + } + switch (sym->subtype) { + case USERDOUBLE: + d = *(sym->u.pval); + break; + case USERINT: + d = (double) (*(sym->u.pvalint)); + break; +#if CABLE + case USERPROPERTY: + d = cable_prop_eval(sym); + break; +#endif + case USERFLOAT: + d = (double) (*(sym->u.pvalfloat)); + break; + default: + d = *(OPVAL(sym)); + break; + } + } else { + switch (sym->subtype) { + case USERDOUBLE: + d = (sym->u.pval)[araypt(sym, SYMBOL)]; + break; + case USERINT: + d = (sym->u.pvalint)[araypt(sym, SYMBOL)]; + break; + case USERFLOAT: + d = (sym->u.pvalfloat)[araypt(sym, SYMBOL)]; + break; +#if NEMO + case NEMONODE: + hoc_eval_nemonode(sym, xpopm(), &d); + break; + case NEMOAREA: + hoc_eval_nemoarea(sym, xpopm(), &d); + break; +#endif /*NEMO*/ + default: + d = (OPVAL(sym))[araypt(sym, OBJECTVAR)]; + break; + } + } + break; + case AUTO: + d = fp->argn[sym->u.u_auto * 2].val; + break; + default: + execerror("attempt to evaluate a non-variable", sym->name); + } + + if (obsav) { + hoc_objectdata = hoc_objectdata_restore(odsav); + hoc_thisobject = obsav; + hoc_symlist = slsav; + } + pushxm(d); +} + +void hoc_evalpointer(void) /* leave pointer to variable on stack */ +{ + Objectdata *odsav; + Object *obsav = 0; + Symlist *slsav; + double *d = 0; + //*cable_prop_eval_pointer(); + Symbol *sym; + sym = spopm(); + if (sym->cpublic == 2) { + sym = sym->u.sym; + odsav = hoc_objectdata_save(); + obsav = hoc_thisobject; + slsav = hoc_symlist; + hoc_objectdata = hoc_top_level_data; + hoc_thisobject = 0; + hoc_symlist = hoc_top_level_symlist; + } + switch (sym->type) { + case UNDEF: + execerror("undefined variable", sym->name); + case VAR: + if (!ISARRAY(sym)) { + switch (sym->subtype) { + case USERDOUBLE: + d = sym->u.pval; + break; + case USERINT: + case USERFLOAT: + execerror("can use pointer only to doubles", sym->name); + break; +#if CABLE + case USERPROPERTY: + d = cable_prop_eval_pointer(sym); + break; +#endif + default: + d = OPVAL(sym); + break; + } + } else { + switch (sym->subtype) { + case USERDOUBLE: + d = sym->u.pval + araypt(sym, SYMBOL); + break; + case USERINT: + case USERFLOAT: +#if NEMO + case NEMONODE: + case NEMOAREA: +#endif /*NEMO*/ + execerror("can use pointer only to doubles", sym->name); + break; + default: + d = OPVAL(sym) + araypt(sym, OBJECTVAR); + break; + } + } + break; + case AUTO: +#if 0 + execerror("can't use pointer to local variable", sym->name); +#else + d = &(fp->argn[sym->u.u_auto * 2].val); +#endif + break; + default: + execerror("attempt to evaluate pointer to a non-variable", sym->name); + } + if (obsav) { + hoc_objectdata = hoc_objectdata_restore(odsav); + hoc_thisobject = obsav; + hoc_symlist = slsav; + } + hoc_pushpx(d); +} + +void add(void) /* add top two elems on stack */ +{ + double d1, d2; + d2 = xpopm(); + d1 = xpopm(); + d1 += d2; + pushxm(d1); +} + +void hoc_sub(void) /* subtract top two elems on stack */ +{ + double d1, d2; + d2 = xpopm(); + d1 = xpopm(); + d1 -= d2; + pushxm(d1); +} + +void mul(void) /* multiply top two elems on stack */ +{ + double d1, d2; + d2 = xpopm(); + d1 = xpopm(); + d1 *= d2; + pushxm(d1); +} + +#if _CRAY +/* + try to do integer division, so that if x is an exact multiple of y + then we really get an integer as the result. + Algorithm: find n such that tx = x * 10^n and ty = y * 10^n are both + integral. If tx/ty leaves no remainder, then tx/ty is the correct + answer and is stored in iptr, intdiv returns true. Otherwise a + floating point division can be done, intdiv returns false. +*/ + +static int intdiv(double x, double y, int* iptr) { + long ix, iy, iz; + int done = 0; + while (!done) + { + if (fabs(x) > (1<<62) || fabs(y) > (1<<62)) + return 0; /* out of range of integers */ + if (x == (long) x && y == (long) y) + done = 1; + else + { + x *= (long double) 10; + y *= (long double) 10; + } + } + ix = (long) x; + iy = (long) y; + iz = ix/iy; + if (ix == iz*iy) + { /* no remainder */ + *iptr = (int) iz; + return 1; + } + return 0; +} +#endif + +void hoc_div(void) /* divide top two elems on stack */ +{ + double d1, d2; + d2 = xpopm(); + if (d2 == 0.0) + execerror("division by zero", (char *) 0); + d1 = xpopm(); +#if _CRAY + { + int i; + if (intdiv(d1, d2, &i)) + d1 = (int) i; /* result is an integer */ + else + d1 = d1/d2; /* result is not an integer */ + } +#else + d1 /= d2; +#endif + pushxm(d1); +} + +void hoc_cyclic(void) /* the modulus function */ +{ + double d1, d2; + double r, q; + d2 = xpopm(); + if (d2 <= 0.) + execerror("a%b, b<=0", (char *) 0); + d1 = xpopm(); + r = d1; + if (r >= d2) { + q = floor(d1 / d2); + r = d1 - q * d2; + } else if (r <= -d2) { + q = floor(-d1 / d2); + r = d1 + q * d2; + } + if (r > d2) { + r = r - d2; + } + if (r < 0.) { + r = r + d2; + } + + pushxm(r); +} + +void negate(void) /* negate top element on stack */ +{ + double d; + d = xpopm(); + pushxm(-d); +} + +void gt(void) { + double d1, d2; + d2 = xpopm(); + d1 = xpopm(); + d1 = (double) (d1 > d2 + EPS); + pushxm(d1); +} + +void lt(void) { + double d1, d2; + d2 = xpopm(); + d1 = xpopm(); + d1 = (double) (d1 < d2 - EPS); + pushxm(d1); +} + +void ge(void) { + double d1, d2; + d2 = xpopm(); + d1 = xpopm(); + d1 = (double) (d1 >= d2 - EPS); + pushxm(d1); +} + +void le(void) { + double d1, d2; + d2 = xpopm(); + d1 = xpopm(); + d1 = (double) (d1 <= d2 + EPS); + pushxm(d1); +} + +void eq(void) { + int t1, t2; + double d1 = 0.0, d2; + t1 = (stackp - 1)->i; + t2 = (stackp - 3)->i; + switch (t2) { + case NUMBER: + tstkchk(t1, t2); + d2 = xpopm(); + d1 = xpopm(); + d1 = (double) (d1 <= d2 + EPS && d1 >= d2 - EPS); + break; + case STRING: + d1 = (double) (strcmp(*hoc_strpop(), *hoc_strpop()) == 0); + break; + case OBJECTTMP: + case OBJECTVAR: { + Object **o1, **o2; + o1 = hoc_objpop(); + o2 = hoc_objpop(); + d1 = (double) (*o1 == *o2); + hoc_tobj_unref(o1); + hoc_tobj_unref(o2); + } + break; + default: + hoc_execerror("don't know how to compare these types", (char *) 0); + } + pushxm(d1); +} + +void ne(void) { + int t1, t2; + double d1 = 0.0, d2; + t1 = (stackp - 1)->i; + t2 = (stackp - 3)->i; + switch (t1) { + case NUMBER: + tstkchk(t1, t2); + d2 = xpopm(); + d1 = xpopm(); + d1 = (double) (d1 < d2 - EPS || d1 > d2 + EPS); + break; + case STRING: + d1 = (double) (strcmp(*hoc_strpop(), *hoc_strpop()) != 0); + break; + case OBJECTTMP: + case OBJECTVAR: { + Object **o1, **o2; + o1 = hoc_objpop(); + o2 = hoc_objpop(); + d1 = (double) (*o1 != *o2); + hoc_tobj_unref(o1); + hoc_tobj_unref(o2); + } + break; + default: + hoc_execerror("don't know how to compare these types", (char *) 0); + } + pushxm(d1); +} + +void hoc_and(void) { + double d1, d2; + d2 = xpopm(); + d1 = xpopm(); + d1 = (double) (d1 != 0.0 && d2 != 0.0); + pushxm(d1); +} + +void hoc_or(void) { + double d1, d2; + d2 = xpopm(); + d1 = xpopm(); + d1 = (double) (d1 != 0.0 || d2 != 0.0); + pushxm(d1); +} + +void hoc_not(void) { + double d; + d = xpopm(); + d = (double) (d == 0.0); + pushxm(d); +} + +void power(void) /* arg1 raised to arg2 */ +{ + double d1, d2; +// extern double Pow(); + d2 = xpopm(); + d1 = xpopm(); + d1 = Pow(d1, d2); + pushxm(d1); +} + +void assign(void) /* assign result of execute to top symbol */ +{ + Objectdata *odsav; + Object *obsav = 0; + Symlist *slsav; + int op; + Symbol *sym; + double d2; + op = (pc++)->i; + sym = spopm(); + if (sym->cpublic == 2) { + sym = sym->u.sym; + odsav = hoc_objectdata_save(); + obsav = hoc_thisobject; + slsav = hoc_symlist; + hoc_objectdata = hoc_top_level_data; + hoc_thisobject = 0; + hoc_symlist = hoc_top_level_symlist; + } + d2 = xpopm(); + switch (sym->type) { + case UNDEF: + hoc_execerror(sym->name, "undefined variable"); + case VAR: + if (!ISARRAY(sym)) { + switch (sym->subtype) { + case USERDOUBLE: + if (op) { + d2 = hoc_opasgn(op, *(sym->u.pval), d2); + } + *(sym->u.pval) = d2; + break; + case USERINT: + if (op) { + d2 = hoc_opasgn(op, (double) (*(sym->u.pvalint)), d2); + } + *(sym->u.pvalint) = (int) (d2 + EPS); + break; +#if CABLE + case USERPROPERTY: + cable_prop_assign(sym, &d2, op); + break; +#endif + case USERFLOAT: + if (op) { + d2 = hoc_opasgn(op, (double) (*(sym->u.pvalfloat)), d2); + } + *(sym->u.pvalfloat) = (float) (d2); + break; + default: + if (op) { + d2 = hoc_opasgn(op, *(OPVAL(sym)), d2); + } + *(OPVAL(sym)) = d2; + break; + } + } else { + int ind; + switch (sym->subtype) { + case USERDOUBLE: + ind = araypt(sym, SYMBOL); + if (op) { + d2 = hoc_opasgn(op, (sym->u.pval)[ind], d2); + } + (sym->u.pval)[ind] = d2; + break; + case USERINT: + ind = araypt(sym, SYMBOL); + if (op) { + d2 = hoc_opasgn(op, (double) ((sym->u.pvalint)[ind]), d2); + } + (sym->u.pvalint)[ind] = (int) (d2 + EPS); + break; + case USERFLOAT: + ind = araypt(sym, SYMBOL); + if (op) { + d2 = hoc_opasgn(op, (double) ((sym->u.pvalfloat)[ind]), d2); + } + (sym->u.pvalfloat)[ind] = (float) d2; + break; +#if NEMO + case NEMONODE: + hoc_asgn_nemonode(sym, xpopm(), &d2, op); + break; + case NEMOAREA: + hoc_asgn_nemoarea(sym, xpopm(), &d2, op); + break; +#endif /*NEMO*/ + default: + ind = araypt(sym, OBJECTVAR); + if (op) { + d2 = hoc_opasgn(op, (OPVAL(sym))[ind], d2); + } + (OPVAL(sym))[ind] = d2; + break; + } + } + break; + case AUTO: + if (op) { + d2 = hoc_opasgn(op, fp->argn[sym->u.u_auto * 2].val, d2); + } + fp->argn[sym->u.u_auto * 2].val = d2; + break; + default: + execerror("assignment to non-variable", sym->name); + } + if (obsav) { + hoc_objectdata = hoc_objectdata_restore(odsav); + hoc_thisobject = obsav; + hoc_symlist = slsav; + } + pushxm(d2); +} + +void hoc_assign_str(char **cpp, const char *buf) { + char *s = *cpp; + *cpp = (char *) emalloc((unsigned) (strlen(buf) + 1)); + Strcpy(*cpp, buf); + if (s) { + hoc_free_string(s); + } +} + +void assstr(void) { /* assign string on top to stack - 1 */ + char **ps1, **ps2; + + ps1 = hoc_strpop(); + ps2 = hoc_strpop(); + hoc_assign_str(ps2, *ps1); +} + +char *hoc_araystr(Symbol *sym, int index, Objectdata *obd) { /* returns array string for multiple dimensions */ + static char name[100]; + char *cp = name + 100; + char buf[20]; + int i, n, j, n1; + + *--cp = '\0'; + if (ISARRAY(sym)) { + Arrayinfo *a; + if (sym->subtype == 0) { + a = obd[sym->u.oboff + 1].arayinfo; + } else { + a = sym->arayinfo; + } + for (i = a->nsub - 1; i >= 0; --i) { + n = a->sub[i]; + j = index % n; + index /= n; + Sprintf(buf, "%d", j); + n1 = strlen(buf); + assert(n1 + 2 < cp - name); + *--cp = ']'; + for (j = n1 - 1; j >= 0; --j) { + *--cp = buf[j]; + } + *--cp = '['; + } + } + return cp; +} + +int hoc_array_index(Symbol *sp, Objectdata *od) { /* subs must be in reverse order on stack */ + int i; + if (ISARRAY(sp)) { + if (sp->subtype == 0) { + Objectdata *sav = hoc_objectdata; + hoc_objectdata = od; + i = araypt(sp, OBJECTVAR); + hoc_objectdata = sav; + } else { + i = araypt(sp, 0); + } + } else { + i = 0; + } + return i; +} + +int araypt(Symbol *sp, int type) { /* return subscript - subs in reverse order on stack */ + int i, total, varn; + int d; + register Arrayinfo *aray; + if (type == OBJECTVAR) { + aray = OPARINFO(sp); + } else { + aray = sp->arayinfo; + } + + total = 0; + for (i = 0; i < aray->nsub; i++) { + tstkchk((stackp - 2 * (aray->nsub - i) + 1)->i, NUMBER); + d = (int) ((stackp - 2 * (aray->nsub - i))->val + EPS); + if (d < 0 || d >= aray->sub[i]) + execerror("subscript out of range", sp->name); + total = total * (aray->sub[i]) + d; + } + for (i = 0; i < aray->nsub; i++) + nopopm(); + if (do_equation && sp->s_varn != 0 + && (varn = (aray->a_varn)[total]) != 0 && hoc_access[varn] == 0) { + hoc_access[varn] = var_access; + var_access = varn; + } + return total; +} + +/* obsolete */ +#if CABLE && 0 +int nrnpnt_araypt(Symbol* sp, int pi) { + int i, total; + int d; + register Arrayinfo *aray = sp->arayinfo; + /* the difference is that the first index is for a neuron point + process vector, and the remaining incices are normal vector indices. + the return value is the parameter index and the first + index is returned in pi. return is 0 if not a vector or if element 0. + */ + total = 0; + for (i = 0; i < aray->nsub; i++) + { + tstkchk((stackp - 2*(aray->nsub - i) + 1)->i, NUMBER); + d = (int)((stackp - 2*(aray->nsub - i))->val + EPS); + if (d < 0 || d >= aray->sub[i]) + execerror("subscript out of range", sp->name); + total = total * (aray->sub[i]) + d; + if (i == 0) { + *pi = total; + total = 0; + } + } + for (i = 0; i< aray->nsub; i++) + nopopm(); + return total; +} +#endif + +void print(void) /* pop top value from stack, print it */ +{ +#if defined(__GO32__) + extern int egagrph; + if (egagrph) { + char buf[50]; + sprintf(buf, "\t"); + grx_output_some_chars(buf, strlen(buf)); + prexpr(); + grx_output_some_chars("\n", 1); + }else +#endif + { + nrnpy_pr("\t"); + prexpr(); + nrnpy_pr("\n"); + } +} + +void prexpr(void) /* print numeric value */ +{ + static HocStr *s; +// char *hoc_object_name(); + char *ss; +#if CABLE + extern char* secaccessname(); +#endif + Object **pob; + + if (!s) s = hocstr_create(256); + switch (hoc_stacktype()) { + case NUMBER: + Sprintf(s->buf, "%.8g ", xpopm()); + break; + case STRING: + ss = *(hoc_strpop()); + hocstr_resize(s, strlen(ss) + 1); + Sprintf(s->buf, "%s ", ss); + break; + case OBJECTTMP: + case OBJECTVAR: + pob = hoc_objpop(); + Sprintf(s->buf, "%s ", hoc_object_name(*pob)); + hoc_tobj_unref(pob); + break; +#if 0 && CABLE + case SECTION: + Sprintf(s->buf, "%s ", secaccessname()); + break; +#endif + default: + hoc_execerror("Don't know how to print this type\n", 0); + } + plprint(s->buf); + +} + +void prstr(void) /* print string value */ +{ + static HocStr *s; + char **cpp; + if (!s) s = hocstr_create(256); + cpp = hoc_strpop(); + hocstr_resize(s, strlen(*cpp) + 10); + Sprintf(s->buf, "%s", *cpp); + plprint(s->buf); +} + +/*-----------------------------------------------------------------*/ +void hoc_delete_symbol(void) +/* Added 15-JUN-90 by JCW. This routine deletes a +"defined-on-the-fly" variable from the symbol +list. */ +/* modified greatly by Hines. Very unsafe in general. */ +{ +#if 1 + /*---- local variables -----*/ + Symbol *doomed, + *sp; + /*---- start function ------*/ + + /* copy address of the symbol that will be deleted */ + doomed = (pc++)->sym; + +#endif +/* hoc_execerror("delete_symbol doesn't work right now.", (char *)0);*/ +#if 1 + if (doomed->type == UNDEF) + fprintf(stderr, "%s: no such variable\n", doomed->name); + else if (doomed->defined_on_the_fly == 0) + fprintf(stderr, "%s: can't be deleted\n", doomed->name); + else { + extern void hoc_free_symspace(Symbol*); + hoc_free_symspace(doomed); + } +#endif +} + +/*----------------------------------------------------------*/ + +void hoc_newline(void) /* print newline */ +{ + plprint("\n"); +} + +void varread(void) /* read into variable */ +{ + double d = 0.0; + extern NrnFILEWrap *fin; + Symbol *var = (pc++)->sym; + + assert(var->cpublic != 2); + if (!((var->type == VAR || var->type == UNDEF) && !ISARRAY(var) + && var->subtype == NOTUSER + ) + ) { + execerror(var->name, "is not a scalar variable"); + } + Again: + switch (nrn_fw_fscanf(fin, "%lf", OPVAL(var))) { + case EOF: + if (moreinput()) + goto Again; + d = *(OPVAL(var)) = 0.0; + break; + case 0: + execerror("non-number read into", var->name); + break; + default: + d = 1.0; + break; + } + var->type = VAR; + pushxm(d); +} + + +static Inst *codechk(void) { + if (progp >= prog + NPROG - 1) + execerror("procedure too big", (char *) 0); + if (zzdebug) { + debugzz(progp); + } + return progp++; +} + +Inst *Code(Pfrv f) { /* install one instruction or operand */ + progp->pf = f; + return codechk(); +} + +Inst *codei(int f) { + progp->pf = NULL;/* zero high order bits to avoid debugzz problem */ + progp->i = f; + return codechk(); +} + +Inst *hoc_codeptr(void *vp) { + progp->ptr = vp; + return codechk(); +} + +void codesym(Symbol *f) { + progp->sym = f; + IGNORE(codechk()); +} + +void codein(Inst *f) { + progp->in = f; + IGNORE(codechk()); +} + +void insertcode(Inst *begin, Inst *end, Pfrv f) { + Inst *i; + for (i = end - 1; i != begin; i--) { + *i = *(i - 1); + } + begin->pf = f; + + if (zzdebug) { + Inst *p; + printf("insert code: what follows is the entire code so far\n"); + for (p = prog; p < progp; ++p) { + debugzz(p); + } + printf("end of insert code debugging\n"); + } +} + +#if defined(DOS) || defined(__GO32__) || defined (WIN32) || (MAC && !defined(DARWIN)) +static int ntimes; +#endif + +void execute(Inst *p) /* run the machine */ +{ + Inst *pcsav; + + BBSPOLL + for (pc = p; pc->in != STOP && !hoc_returning;) { +#if defined(DOS) + if (++ntimes > 10) { + ntimes = 0; +#if 0 + kbhit(); /* DOS can't capture interrupt when number crunching*/ +#endif + } +#endif +#if defined(__GO32__) || (defined(WIN32) && !defined(CYGWIN)) + if (++ntimes > 10) { + ntimes = 0; + hoc_check_intupt(1); + } +#endif +#if MAC && !defined(DARWIN) + /* there is significant overhead here */ + if (++ntimes > 100) { + ntimes = 0; + hoc_check_intupt(1); + } +#endif + if (intset) + execerror("interrupted", (char *) 0); + /* (*((pc++)->pf))(); DEC 5000 increments pc after the return!*/ + pcsav = pc++; + (*((pcsav)->pf))(); + } +} + diff --git a/src/oc/code.h b/src/oc/code.h index a9373c3f02..90495ddbd5 100755 --- a/src/oc/code.h +++ b/src/oc/code.h @@ -3,14 +3,28 @@ #include "redef.h" -extern void eval(void), add(void), hoc_sub(void), mul(void), hoc_div(void), hoc_cyclic(void), negate(void), power(void); +#if defined(__cplusplus) +extern "C" { +#endif + +extern void nopop(void); +extern void edit(void); + +#if defined(__cplusplus) +} +#endif + + + +extern void eval(void); +extern void add(void), hoc_sub(void), mul(void), hoc_div(void), hoc_cyclic(void), negate(void), power(void); extern void assign(void), bltin(void), varpush(void), constpush(void), print(void), varread(void); -extern void nopop(void), prexpr(void), prstr(void), assstr(void), pushzero(void); +extern void prexpr(void), prstr(void), assstr(void), pushzero(void); extern void gt(void), lt(void), eq(void), ge(void), le(void), ne(void), hoc_and(void), hoc_or(void), hoc_not(void); extern void ifcode(void), forcode(void), shortfor(void), call(void), arg(void), argassign(void); extern void hoc_argrefasgn(void), hoc_argref(void), hoc_iterator(void), hoc_iterator_stmt(void); extern void funcret(void), procret(void), Break(void), Continue(void), Stop(void); -extern void debug(void), edit(void), hoc_evalpointer(void); +extern void debug(void), hoc_evalpointer(void); extern void hoc_newline(void), hoc_delete_symbol(void), hoc_stringarg(void), hoc_push_string(void); extern void hoc_parallel_begin(void), hoc_parallel_end(void), hoc_argrefarg(void); extern void hoc_arayinstal(void); @@ -40,4 +54,5 @@ extern void simpleconnectsection(void), range_interpolate_single(void); extern void hoc_sec_internal_push(void); /* END NEWCABLE*/ + #endif diff --git a/src/oc/code2.c b/src/oc/code2.cpp similarity index 90% rename from src/oc/code2.c rename to src/oc/code2.cpp index 5b0e07b8cd..8d2bff3e9f 100755 --- a/src/oc/code2.c +++ b/src/oc/code2.cpp @@ -1,27 +1,30 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/code2.c,v 1.12 1999/06/08 17:48:26 hines Exp */ +/* /local/src/master/nrn/src/oc/code2.cpp,v 1.12 1999/06/08 17:48:26 hines Exp */ -#include "hoc.h" +#include "hoc.h" #include "hocstr.h" -#include "parse.h" -#include "hocparse.h" -#include +#include "parse.h" +#include "hocparse.h" +#include #include #include #include -#include +#include #include "nrnfilewrap.h" +#include + + int units_on_flag_; extern char **gargv; extern int gargc; -extern double chkarg(); +extern double chkarg(int, double low, double high); extern Symlist* hoc_built_in_symlist; extern Symlist* hoc_top_level_symlist; -extern Symbol *hoc_table_lookup(); +extern Symbol *hoc_table_lookup(const char*, Symlist*); -extern char **hoc_pgargstr(); +extern char **hoc_pgargstr(int); float* hoc_sym_domain(Symbol* sym) { if (sym && sym->extra) { @@ -43,7 +46,7 @@ HocSymExtension* hoc_var_extra(const char* name) { Symbol* hoc_name2sym(const char* name) { char* buf, *cp; Symbol* sym; - buf = emalloc(strlen(name)+1); + buf = static_cast(emalloc(strlen(name)+1)); strcpy(buf, name); for (cp = buf; *cp; ++cp) { if (*cp == '.') { @@ -60,7 +63,7 @@ Symbol* hoc_name2sym(const char* name) { free(buf); return sym; }else if (sym && sym->type == TEMPLATE && *cp != '\0') { - sym = hoc_table_lookup(cp, sym->u.template->symtable); + sym = hoc_table_lookup(cp, sym->u.ctemplate->symtable); if (sym) { free(buf); return sym; @@ -71,8 +74,9 @@ Symbol* hoc_name2sym(const char* name) { } void hoc_Symbol_limits(void) { - Symbol* sym, *hoc_get_last_pointer_symbol(); - double* hoc_pgetarg(); + Symbol* sym; + extern Symbol* hoc_get_last_pointer_symbol();//, *hoc_get_last_pointer_symbol(); +// double* hoc_pgetarg(); if (hoc_is_str_arg(1)) { char* name = gargstr(1); @@ -130,7 +134,7 @@ char* hoc_symbol_units(Symbol* sym, const char* units) { sym->extra->units = (char*)0; } sym_extra_alloc(sym); - sym->extra->units = (char*)emalloc(strlen(units)+1); + sym->extra->units = static_cast(emalloc(strlen(units)+1)); strcpy(sym->extra->units, units); } if (sym->extra && sym->extra->units) { @@ -141,10 +145,11 @@ char* hoc_symbol_units(Symbol* sym, const char* units) { } void hoc_Symbol_units(void) { - Symbol* sym, *hoc_get_last_pointer_symbol(); - double* hoc_pgetarg(); - int hoc_is_str_arg(); - char** hoc_temp_charptr(); + Symbol* sym; + extern Symbol* hoc_get_last_pointer_symbol(); //, *hoc_get_last_pointer_symbol(); + extern double* hoc_pgetarg(int); +// int hoc_is_str_arg(); +// char** hoc_temp_charptr(); char** units = hoc_temp_charptr(); if (hoc_is_double_arg(1)) { @@ -189,7 +194,7 @@ char* neuronhome_forward(void) { extern char* hoc_back2forward(); extern void hoc_forward2back(); if (!buf) { - buf = emalloc(strlen(neuron_home)+1); + buf = static_cast(emalloc(strlen(neuron_home)+1)); strcpy(buf, neuron_home); } hoc_back2forward(buf); @@ -244,10 +249,10 @@ void hoc_sscanf(void) { static int hoc_vsscanf(const char* buf) { /* assumes arg2 format string from hoc as well as remaining args */ - char *pf, *format, errbuf[100], **hoc_pgargstr(); + char *pf, *format, errbuf[100]; //, **hoc_pgargstr(); void* arglist[20]; int n=0, iarg, i, islong, convert, sawnum; - double* hoc_pgetarg(); + extern double* hoc_pgetarg(int); struct { union { double d; @@ -260,7 +265,7 @@ static int hoc_vsscanf(const char* buf) { int type; } arg[20]; for (i=0; i < 20; ++i) { - arglist[i] = (void*)0; + arglist[i] = nullptr; } format = gargstr(2); iarg = 0; @@ -338,7 +343,7 @@ static int hoc_vsscanf(const char* buf) { goto bad_specifier; } arg[iarg].type = 's'; - arg[iarg].u.s = (char*)emalloc(strlen(buf) + 1); + arg[iarg].u.s = static_cast(emalloc(strlen(buf) + 1)); arglist[iarg] = (void*)arg[iarg].u.s; break; case 'c': @@ -346,7 +351,7 @@ static int hoc_vsscanf(const char* buf) { goto bad_specifier; } arg[iarg].type = 'c'; - arglist[iarg] = (void*)&arg[iarg].u.c; + arglist[iarg] = (void*)&arg[iarg].u.c; break; default: goto bad_specifier; @@ -448,7 +453,7 @@ void System(void) static char stdoutfile[]="/systmp.tmp"; #endif double d; - int system(); +// int system(); FILE *fp; if (hoc_plttext && !strchr(gargstr(1), '>')) { @@ -503,7 +508,7 @@ hoc_execerror("Internal error in System(): can't open", stdoutfile); void Xred(void) /* read with prompt string and default and limits */ { double d; - double xred(); +// double xred(); d = xred(gargstr(1), *getarg(2), *getarg(3), *getarg(4)); ret(); @@ -514,12 +519,12 @@ static struct { /* symbol types */ char *name; short t_type; } type_sym[] = { - "Builtins", BLTIN, - "Other Builtins", FUN_BLTIN, - "Functions", FUNCTION, - "Procedures", PROCEDURE, - "Undefined", UNDEF, - "Scalars", VAR, + "Builtins", BLTIN, + "Other Builtins", FUN_BLTIN, + "Functions", FUNCTION, + "Procedures", PROCEDURE, + "Undefined", UNDEF, + "Scalars", VAR, 0, 0 }; @@ -607,7 +612,8 @@ if(ISARRAY(sp)){ double chkarg(int arg, double low, double high) /* argument checking for user functions */ { - double *getarg(), val; +// double *getarg(),; + double val; val = *getarg(arg); if (val > high || val < low) { @@ -658,12 +664,12 @@ void hoc_run_stmt(Symbol* sym) { hoc_execute(sym->u.u_proc->defn.in); hoc_pc = pcsav; } +extern Symlist* hoc_top_level_symlist; -Symbol* hoc_parse_stmt(const char* str, Symlist** psymlist) { +extern "C" Symbol* hoc_parse_stmt(const char* str, Symlist** psymlist) { Symbol* sp; char s[BUFSIZ]; - extern Symlist* hoc_top_level_symlist; - + if (!psymlist) { psymlist = &hoc_top_level_symlist; } @@ -689,7 +695,7 @@ Symbol* hoc_parse_stmt(const char* str, Symlist** psymlist) { extern double* hoc_varpointer; void hoc_pointer(void) { - double* hoc_pgetarg(); + extern double* hoc_pgetarg(int); hoc_varpointer = hoc_pgetarg(1); ret(); pushx(1.); @@ -741,3 +747,4 @@ void hoc_name_declared(void) { ret(); pushx((double)x); } + diff --git a/src/oc/cygwinprt.c b/src/oc/cygwinprt.cpp similarity index 95% rename from src/oc/cygwinprt.c rename to src/oc/cygwinprt.cpp index 9b97c07571..719869e5fd 100755 --- a/src/oc/cygwinprt.c +++ b/src/oc/cygwinprt.cpp @@ -4,13 +4,13 @@ #if defined(CYGWIN) || defined(MINGW) #if !defined(__MINGW32__) -#include "system.c" +#include "system.cpp" #define my_off64_t loff_t #else #define my_off64_t off64_t #endif -#include "mswinprt.c" +#include "mswinprt.cpp" my_off64_t lseek64(int fd, my_off64_t offset, int whence) { fprintf(stderr, "called lseek64\n"); diff --git a/src/oc/debug.c b/src/oc/debug.cpp similarity index 98% rename from src/oc/debug.c rename to src/oc/debug.cpp index f907731884..00a0d8c8f2 100755 --- a/src/oc/debug.c +++ b/src/oc/debug.cpp @@ -1,5 +1,5 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/debug.c,v 1.7 1996/04/09 16:39:14 hines Exp */ +/* /local/src/master/nrn/src/oc/debug.cpp,v 1.7 1996/04/09 16:39:14 hines Exp */ #include "hoc.h" #include "code.h" #include "equation.h" diff --git a/src/oc/equation.h b/src/oc/equation.h index ce82f1651d..f239a54124 100755 --- a/src/oc/equation.h +++ b/src/oc/equation.h @@ -36,7 +36,11 @@ NEURON 5.3 2002/06/04 * */ + + extern int do_equation; /* switch for determining access to dep vars */ extern int *hoc_access; /* links to next accessed variables */ extern int var_access; /* variable number as pointer into access array */ extern void eqn_name(void), eqn_init(void), eqn_lhs(void), eqn_rhs(void), dep_make(void); + + diff --git a/src/oc/fileio.c b/src/oc/fileio.cpp similarity index 95% rename from src/oc/fileio.c rename to src/oc/fileio.cpp index cc5dda318f..259013a9f8 100755 --- a/src/oc/fileio.c +++ b/src/oc/fileio.cpp @@ -1,20 +1,23 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/fileio.c,v 1.34 1999/09/14 13:11:46 hines Exp */ +/* /local/src/master/nrn/src/oc/fileio.cpp,v 1.34 1999/09/14 13:11:46 hines Exp */ #include #include -#include -#include +#include +#include #include "hoc.h" -#include "ocmisc.h" -#include "hocstr.h" +#include "ocmisc.h" +#include "hocstr.h" #include "hoclist.h" #include "parse.h" -#include "hocparse.h" +#include "hocparse.h" #include #include #include "nrnfilewrap.h" -#include "nrnjava.h" +#include "nrnjava.h" + + + extern jmp_buf begin; extern char* neuron_home; @@ -141,7 +144,7 @@ void wopen(void) /* open file for writing */ pushx(d); } -const char* expand_env_var(const char* s) { +extern "C" const char* expand_env_var(const char* s) { static HocStr* hs; const char* cp1; char* cp2; @@ -237,7 +240,7 @@ int hoc_xopen1(const char* name, const char* rcs) /* read and execute a hoc prog if (rcs[0] != '\0') { int sz = 2*(strlen(rcs) + strlen(name)) + 20; free(fname); - fname = emalloc(sz); + fname = static_cast(emalloc(sz)); Sprintf(fname, "co -p%s %s > %s-%s", rcs, name, name, rcs); ERRCHK(if (system(fname) != 0) { @@ -286,7 +289,7 @@ int hoc_xopen1(const char* name, const char* rcs) /* read and execute a hoc prog nrn_assert((savname = strdup(hoc_xopen_file_))); if (strlen(fname) >= hoc_xopen_file_size_) { hoc_xopen_file_size_ = strlen(fname) + 100; - hoc_xopen_file_ = erealloc(hoc_xopen_file_, hoc_xopen_file_size_); + hoc_xopen_file_ = static_cast(erealloc(hoc_xopen_file_, hoc_xopen_file_size_)); } strcpy(hoc_xopen_file_, fname); if (fin) { @@ -448,7 +451,7 @@ void hoc_sprint1(char** ppbuf, int argn) { /* convert args to right type for con /* argn is argument number where format is */ static HocStr* hs; char *pbuf, *pfmt, *pfrag, frag[120]; - int n, convflag, lflag, didit, hoc_argtype(); + int n, convflag, lflag, didit; //, hoc_argtype(); char *fmt, *cp; if (!hs) { hs = hocstr_create(512); } @@ -500,8 +503,8 @@ void hoc_sprint1(char** ppbuf, int argn) { /* convert args to right type for con case 's': if (hoc_is_object_arg(argn)) { - char* hoc_object_name(); - Object** hoc_objgetarg(); +// char* hoc_object_name(); +// Object** hoc_objgetarg(); cp = hoc_object_name(*hoc_objgetarg(argn)); }else{ cp = gargstr(argn); @@ -819,7 +822,7 @@ void hoc_getcwd(void) { int len; static char* buf; if (!buf) { - buf = emalloc(hoc_load_file_size_); + buf = static_cast(emalloc(hoc_load_file_size_)); } if (!getcwd(buf, hoc_load_file_size_)) { hoc_execerror("getcwd failed. Perhaps the path length is > hoc_load_file_size_", (char*)0); @@ -873,7 +876,7 @@ int nrn_is_python_extension; static int (*nrnpy_pr_stdoe_callback)(int, char*); static int (*nrnpy_pass_callback)(); -void nrnpy_set_pr_etal(int (*cbpr_stdoe)(int, char*), int (*cbpass)()) { +extern "C" void nrnpy_set_pr_etal(int (*cbpr_stdoe)(int, char*), int (*cbpass)()) { if (nrn_is_python_extension) { nrnpy_pr_stdoe_callback = cbpr_stdoe; nrnpy_pass_callback = cbpass; @@ -897,6 +900,13 @@ static int vnrnpy_pr_stdoe(FILE* stream, const char *fmt, va_list ap) { /* Determine required size */ va_list apc; +#ifndef va_copy +#if defined(__GNUC__) || defined(__clang__) +#define va_copy(dest, src) __builtin_va_copy(dest, src) +#else +#define va_copy(dest, src) (dest = src) +#endif +#endif va_copy(apc, ap); size = vsnprintf(p, size, fmt, apc); va_end(apc); @@ -905,7 +915,7 @@ static int vnrnpy_pr_stdoe(FILE* stream, const char *fmt, va_list ap) { return 0; size++; /* For '\0' */ - p = malloc(size); + p = static_cast(malloc(size)); if (p == NULL) return 0; diff --git a/src/oc/fmenu.c b/src/oc/fmenu.cpp similarity index 86% rename from src/oc/fmenu.c rename to src/oc/fmenu.cpp index 49a4b9b861..00011950b5 100755 --- a/src/oc/fmenu.c +++ b/src/oc/fmenu.cpp @@ -233,79 +233,77 @@ static void menu_manager(int nmenu) { current_menu = previous; } -void hoc_fmenu(void){ - int imenu, flag, i, narg; +void hoc_fmenu(void) { + int imenu, flag, i, narg; #ifdef WIN32 - hoc_execerror("fmenu not available under mswindows.", "Use xpanel series"); + hoc_execerror("fmenu not available under mswindows.", "Use xpanel series"); #endif - imenu = *getarg(1); - if (!ifarg(2)) { /* navigate the menu */ - chk(imenu); - menu_manager(imenu); - Ret(0.); - return ; - } - flag = *getarg(2); - narg = 2; - switch(flag) - { - case -1: - if (current_menu != -1) { - diag("can't destroy current menu"); - } - if (maxmenus) { - for (i = 0; isymmin = *getarg(narg=narg+1); - menuslast[imenu]->symmax = *getarg(narg=narg+1); - } - break; - case 2: - while (ifarg(narg=narg+1)) { - char *prompt, *command; - prompt = gargstr(narg); - command = gargstr(narg=narg+1); - appendaction(imenu, prompt, command); - } - break; - case 3: - while (ifarg(narg=narg+1)) { - appendvar(imenu, gargstr(narg), gargstr(narg+1)); - menuslast[imenu]->symmin = *getarg(narg=narg+2); - menuslast[imenu]->symmax = *getarg(narg=narg+1); - } - break; - default: - diag("illegal argument flag"); - break; - } - Ret (0.); + imenu = *getarg(1); + if (!ifarg(2)) { /* navigate the menu */ + chk(imenu); + menu_manager(imenu); + Ret(0.); + return; + } + flag = *getarg(2); + narg = 2; + switch (flag) { + case -1: + if (current_menu != -1) { + diag("can't destroy current menu"); + } + if (maxmenus) { + for (i = 0; i < maxmenus; i++) { + destroy(i); + } + free((char *) menusfirst); + free((char *) menuslast); + } + maxmenus = 0; + menusfirst = (Menuitem **) emalloc((unsigned) (imenu * sizeof(Menuitem *))); + menuslast = (Menuitem **) emalloc((unsigned) (imenu * sizeof(Menuitem *))); + menuscurrent = (Menuitem **) emalloc((unsigned) (imenu * sizeof(Menuitem *))); + + maxmenus = imenu; + for (i = 0; i < maxmenus; i++) { + menusfirst[i] = menuslast[i] = menuscurrent[i] + = (Menuitem *) 0; + } + break; + case 0: chk(imenu); + if (current_menu == imenu) { + diag(" can't destroy current menu"); + } + destroy(imenu); + appendaction(imenu, "Exit", "stop"); + break; + case 1: + while (ifarg(narg = narg + 1)) { + appendvar(imenu, gargstr(narg), (char *) 0); + menuslast[imenu]->symmin = *getarg(narg = narg + 1); + menuslast[imenu]->symmax = *getarg(narg = narg + 1); + } + break; + case 2: + while (ifarg(narg = narg + 1)) { + char *prompt, *command; + prompt = gargstr(narg); + command = gargstr(narg = narg + 1); + appendaction(imenu, prompt, command); + } + break; + case 3: + while (ifarg(narg = narg + 1)) { + appendvar(imenu, gargstr(narg), gargstr(narg + 1)); + menuslast[imenu]->symmin = *getarg(narg = narg + 2); + menuslast[imenu]->symmax = *getarg(narg = narg + 1); + } + break; + default: + diag("illegal argument flag"); + break; + } + Ret (0.); } static void xcursor(int r, int c){ @@ -508,7 +506,7 @@ static char *navigate(int imenu) { return "plt(-5)"; #else (*emacs_term.t_close)(); - return "plt(-3)"; + return (char *)"plt(-3)"; #endif } if(key == 0) { /* arrow key pressed */ @@ -725,13 +723,14 @@ static void undisplay(int imenu) { } void hoc_menu_cleanup(void) { - current_menu = -1; + current_menu = -1; #if DOS || G32 #else - if (!first) { - (*emacs_term.t_close)(); - } + if (!first) { + (*emacs_term.t_close)(); + } #endif } + #endif /*OCSMALL*/ diff --git a/src/oc/ftime.c b/src/oc/ftime.cpp similarity index 63% rename from src/oc/ftime.c rename to src/oc/ftime.cpp index 51420d0a5f..24e3c3e838 100755 --- a/src/oc/ftime.c +++ b/src/oc/ftime.cpp @@ -29,33 +29,35 @@ double nrn_time(void) return ((double)time(&start_time)); #endif } -void hoc_startsw(void) -{ - Ret(nrn_time()); + + + +void hoc_startsw(void) { + Ret(nrn_time()); } -void hoc_stopsw(void) -{ +void hoc_stopsw(void) { #if defined(HAVE_GETTIMEOFDAY) - double y; - int ms10; - struct timeval x; - gettimeofday(&x, (struct timezone*)0); - ms10 = x.tv_usec/10000; - y = (double)(x.tv_sec) + (double)ms10/100.; - Ret(y - start_time); - start_time = y; + double y; + int ms10; + struct timeval x; + gettimeofday(&x, (struct timezone*)0); + ms10 = x.tv_usec/10000; + y = (double)(x.tv_sec) + (double)ms10/100.; + Ret(y - start_time); + start_time = y; #else - if (start_time==0) { - Printf("Must use startsw() first.\n"); - Ret(0.); - } else { - time(&stop_time); - Ret((double)(stop_time - start_time)); - } + if (start_time == 0) { + Printf("Must use startsw() first.\n"); + Ret(0.); + } else { + time(&stop_time); + Ret((double) (stop_time - start_time)); + } #endif } + double nrn_timeus(void) { #if defined(HAVE_GETTIMEOFDAY) diff --git a/src/oc/functabl.c b/src/oc/functabl.cpp similarity index 100% rename from src/oc/functabl.c rename to src/oc/functabl.cpp diff --git a/src/oc/getelm.c b/src/oc/getelm.c deleted file mode 100755 index 74b814e127..0000000000 --- a/src/oc/getelm.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <../../nrnconf.h> -/* - * Automake doesn't deal well with sources that live in other directories, so - * this is a quick and dirty workaround. - */ -#include "../sparse/getelm.c" diff --git a/src/oc/getelm.cpp b/src/oc/getelm.cpp new file mode 100755 index 0000000000..2e3eee3530 --- /dev/null +++ b/src/oc/getelm.cpp @@ -0,0 +1,6 @@ +#include <../../nrnconf.h> +/* + * Automake doesn't deal well with sources that live in other directories, so + * this is a quick and dirty workaround. + */ +#include "../sparse/getelm.cpp" diff --git a/src/oc/getsym.c b/src/oc/getsym.cpp similarity index 97% rename from src/oc/getsym.c rename to src/oc/getsym.cpp index 2bd5216c1b..f587a95da4 100755 --- a/src/oc/getsym.c +++ b/src/oc/getsym.cpp @@ -1,7 +1,7 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/getsym.c,v 1.2 1996/02/16 16:19:26 hines Exp */ +/* /local/src/master/nrn/src/oc/getsym.cpp,v 1.2 1996/02/16 16:19:26 hines Exp */ /* -getsym.c,v +getsym.cpp,v * Revision 1.2 1996/02/16 16:19:26 hines * OCSMALL used to throw out things not needed by teaching programs * diff --git a/src/oc/hoc.c b/src/oc/hoc.cpp similarity index 96% rename from src/oc/hoc.c rename to src/oc/hoc.cpp index 9646b9a790..b8a2893856 100755 --- a/src/oc/hoc.c +++ b/src/oc/hoc.cpp @@ -22,6 +22,7 @@ #endif #include "../nrniv/backtrace_utils.h" + /* for eliminating "ignoreing return value" warnings. */ int nrnignore; @@ -31,7 +32,7 @@ char** nrn_global_argv; #if defined(USE_PYTHON) int use_python_interpreter = 0; -void (*p_nrnpython_start)(); +void (*p_nrnpython_start)(int); void (*p_nrnpython_finalize)(); #endif int nrn_inpython_; @@ -114,8 +115,8 @@ void pr_profile(void) { } } #else -void start_profile(i) int i; {} -void add_profile(i) int i; {} +void start_profile(int i) {} +void add_profile(int i) {} void pr_profile(void) {} #endif @@ -123,11 +124,6 @@ void pr_profile(void) {} #define READLINE 0 #endif -#if defined(WITHOUT_MEMACS) -#undef READLINE -#define READLINE 0 -#endif - #if OCSMALL #define READLINE 0 #endif @@ -137,9 +133,11 @@ void pr_profile(void) {} #endif #if READLINE -extern char* readline(const char* prompt); +extern "C" { +extern char *readline(const char *prompt); extern void rl_deprep_terminal(void); -extern void add_history(const char*); +extern void add_history(const char *); +} #endif int nrn_nobanner_; @@ -215,7 +213,7 @@ static int Getc(NrnFILEWrap* fp); static void unGetc(int c, NrnFILEWrap* fp); static int backslash(int c); -void nrn_exit(i) int i; { +extern "C" void nrn_exit(int i) { #if defined(WIN32) printf("NEURON exiting abnormally, press return to quit\n"); fgetc(stdin); @@ -245,7 +243,7 @@ static RETSIGTYPE retreat_handler(int sig) /* catch interrupt */ } void hoc_retreat(void) { - hoc_obj_run("linda_retreat()\n", (Object*)0); + hoc_obj_run("linda_retreat()\n", nullptr); exit(0); } @@ -655,7 +653,7 @@ value of oc_run() */ static int debug_message_; void hoc_show_errmess_always(void) { - double x, chkarg(); + double x; //, chkarg(); x = chkarg(1, 0., 1.); debug_message_ = (int)x; ret(); @@ -668,7 +666,7 @@ int hoc_execerror_messages; setjmp.h of typedef int jmp_buf[_JBLEN]; */ -void (*oc_jump_target_)(); /* see ivoc/SRC/ocjump.c */ +void (*oc_jump_target_)(); /* see ivoc/SRC/ocjump.cpp */ int yystart; @@ -728,7 +726,7 @@ void hoc_execerror_mes(const char* s, const char* t, int prnt){ /* recover from longjmp(begin, 1); } -void hoc_execerror(const char* s, const char* t)/* recover from run-time error */ +extern "C" void hoc_execerror(const char* s, const char* t)/* recover from run-time error */ { hoc_execerror_mes(s, t, hoc_execerror_messages); } @@ -869,7 +867,7 @@ void hoc_main1_init(const char* pname, const char** envp) if (!hoc_xopen_file_) { hoc_xopen_file_size_ = 200; - hoc_xopen_file_ = emalloc(hoc_xopen_file_size_); + hoc_xopen_file_ = static_cast(emalloc(hoc_xopen_file_size_)); } hoc_xopen_file_[0] = '\0'; @@ -925,7 +923,7 @@ HocStr* hocstr_create(size_t size) { HocStr* hs; hs = (HocStr*)emalloc(sizeof(HocStr)); hs->size = size; - hs->buf = emalloc(size + 1); + hs->buf = static_cast(emalloc(size + 1)); return hs; } @@ -943,7 +941,7 @@ void hocstr_delete(HocStr* hs) { void hocstr_resize(HocStr* hs, size_t n) { if (hs->size < n) { /*printf("hocstr_resize to %d\n", n);*/ - hs->buf = erealloc(hs->buf, n+1); + hs->buf = static_cast(erealloc(hs->buf, n+1)); hs->size = n; } } @@ -1003,8 +1001,8 @@ int hoc_main1(int argc, const char** argv, const char** envp) /* hoc6 */ } if (argc > 1 && argv[1][0] != '-') { /* first file may be a checkpoint file */ - extern int hoc_readcheckpoint(); - switch (hoc_readcheckpoint(argv[1])) { + extern int hoc_readcheckpoint(char *); + switch (hoc_readcheckpoint(const_cast(argv[1]))) { case 1: ++gargv; --gargc; @@ -1026,7 +1024,7 @@ int hoc_main1(int argc, const char** argv, const char** envp) /* hoc6 */ static const char *stdinonly[] = { "-" }; #else static char *stdinonly[1]; - stdinonly[0] = (char*)emalloc(2*sizeof(char)); + stdinonly[0] = static_cast(emalloc(2*sizeof(char))); strcpy(stdinonly[0], "-"); #endif @@ -1105,7 +1103,7 @@ printf("Discarding input til Dialog is closed.\n"); read(fileno(stdin), &c, 1); continue; } - //} + } // extern "C" #endif i = getch(); //printf("see %d %c\n", i, i); @@ -1127,8 +1125,7 @@ void hoc_final_exit(void) { #endif bbs_done(); hoc_audit_from_final_exit(); - hoc_edit_quit(); - + /* Don't close the plots for the sub-processes when they finish, by default they are then closed when the master process ends */ NOT_PARALLEL_SUB(hoc_close_plot();) @@ -1147,7 +1144,7 @@ void hoc_final_exit(void) { #ifdef WIN32 hoc_win32_cleanup(); #else - buf = malloc(strlen(neuron_home) + 30); + buf = static_cast(malloc(strlen(neuron_home) + 30)); if (buf) { sprintf(buf, "%s/lib/cleanup %d", neuron_home, hoc_pid()); if (system(buf)) {;} /* ignore return value */ @@ -1188,7 +1185,7 @@ static const char* double_at2space(const char* infile) { if (!replace) { return infile; } - buf = (char*)emalloc(strlen(infile) + 1); + buf = static_cast(emalloc(strlen(infile) + 1)); for (cp1=infile, cp2=buf; *cp1; ++cp1, ++cp2) { if (*cp1 == '@' && cp1[1] == '@') { *cp2 = ' '; @@ -1336,7 +1333,7 @@ hoc_menu_cleanup(); if (infile) { if (strlen(infile) >= hoc_xopen_file_size_) { hoc_xopen_file_size_ = strlen(infile) + 100; - hoc_xopen_file_ = erealloc(hoc_xopen_file_, hoc_xopen_file_size_); + hoc_xopen_file_ = static_cast(erealloc(hoc_xopen_file_, hoc_xopen_file_size_)); } strcpy(hoc_xopen_file_, infile); } @@ -1353,7 +1350,7 @@ void hoc_run(void) { } #endif -typedef RETSIGTYPE (*SignalType)(); +typedef RETSIGTYPE (*SignalType)(int); static SignalType signals[4]; @@ -1396,7 +1393,7 @@ static void hoc_run1(void) /* execute until EOF */ } hoc_execerror_messages = 1; if (pipeflag == 1) { /*at this location multiple emacs errors */ - hoc_pipeflush(); /* don't eat up stack space */ +// hoc_pipeflush(); /* don't eat up stack space */ }else{ pipeflag=0; } @@ -1438,7 +1435,7 @@ static void hoc_run1(void) /* execute until EOF */ with statements which take too much time to execute or block waiting for input. With regard to long executing statements, at least in xview it is possible to run the event loop from the execute loop at - intervals in code.c or else to run the event loop once via a hoc command. + intervals in code.cpp or else to run the event loop once via a hoc command. Where do we go in case of an hoc_execerror. We have to go to the beginning of hoc. But just maybe that is here. However hoc_oc may be called @@ -1468,13 +1465,13 @@ static void nrn_inputbuf_getline(void) { } // used by ocjump.cpp -void oc_save_input_info(const char** i1, int* i2, int* i3, NrnFILEWrap** i4) { +extern "C" void oc_save_input_info(const char** i1, int* i2, int* i3, NrnFILEWrap** i4) { *i1 = nrn_inputbufptr; *i2 = pipeflag; *i3 = lineno; *i4 = fin; } -void oc_restore_input_info(const char* i1, int i2, int i3, NrnFILEWrap* i4) { +extern "C" void oc_restore_input_info(const char* i1, int i2, int i3, NrnFILEWrap* i4) { nrn_inputbufptr = i1; pipeflag = i2; lineno = i3; @@ -1639,11 +1636,7 @@ int hoc_yyparse(void) { i = yyparse(); hoc_in_yyparse = 0; switch (i) { - case 'e': - i = '\n'; - hoc_edit(); - break; - case -3 : /* need more input */ + case -3 : /* need more input */ hoc_in_yyparse = 1; i = '\n'; break; @@ -1662,11 +1655,6 @@ int hoc_yyparse(void) { #define INTERVIEWS 1 #endif -#if defined(WITHOUT_MEMACS) -#undef INTERVIEWS -#define INTERVIEWS 0 -#endif - int hoc_interviews = 0; #if INTERVIEWS extern int run_til_stdin(); /* runs the interviews event loop. Returns 1 @@ -1868,7 +1856,7 @@ int hoc_get_line(void){ /* supports re-entry. fill cbuf with next line */ #else int hoc_get_line(void){ /* supports re-entry. fill cbuf with next line */ - char *hoc_pipegets(); + extern char* hoc_pipegets(char* cbuf, int nc); if (*ctp) { hoc_execerror("Internal error:", "Not finished with previous input line"); } @@ -1929,7 +1917,7 @@ ENDGUI hocstr_resize(hoc_cbufstr, n+100); ctp = cbuf = hoc_cbufstr->buf; } - strcpy((char*)cbuf, line); + strcpy(cbuf, line); cbuf[n] = '\n'; cbuf[n+1] = '\0'; if (line && *line) { @@ -1996,3 +1984,4 @@ void hoc_check_intupt(int intupt) { } } #endif + diff --git a/src/oc/hoc_init.cpp b/src/oc/hoc_init.cpp new file mode 100755 index 0000000000..bcbcd158d3 --- /dev/null +++ b/src/oc/hoc_init.cpp @@ -0,0 +1,397 @@ +#include <../../nrnconf.h> +/* /local/src/master/nrn/src/oc/hoc_init.cpp,v 1.25 1999/11/08 17:48:58 hines Exp */ + +#include "hoc.h" +#include "parse.h" +#include +#include "equation.h" + +#include "ocfunc.h" + + +extern void hoc_nrnmpi_init(); + +#if PVM +extern int numprocs(), myproc(), psync(); +#endif +#if 0 +extern int hoc_co(); +#endif +#if DOS || defined(WIN32) /*|| defined(MAC)*/ +extern double erf(), erfc(); /* supplied by unix */ +#endif +#if defined(WIN32) +extern void hoc_winio_show(int b); +#endif + +#if MAC +static double Fabs(x) double x; { return (x>0.) ? x : -x; } +static double Erf(x) double x; { return erf(x); } +static double Erfc(x) double x; { return erfc(x); } +#endif + +static struct { /* Keywords */ + char *name; + int kval; +} keywords[] = { + "proc", parsePROC, + "func", FUNC, + "obfunc", HOCOBJFUNC, + "return", RETURN, + "break", BREAK, + "continue", CONTINUE, + "stop", STOPSTMT, + "if", IF, + "else", ELSE, + "while", WHILE, + "for", FOR, + "print", PRINT, + "delete", parseDELETE, + "read", READ, + "debug", DEBUG, + "double", parseDOUBLE, + "em", EDIT, + "depvar", DEPENDENT, + "eqn", EQUATION, + "local", LOCAL, + "localobj", LOCALOBJ, + "strdef", STRDEF, + "parallel", PARALLEL, + "help", HELP, + "iterator", ITERKEYWORD, + "iterator_statement", ITERSTMT, +#if CABLE + "create", SECTIONKEYWORD, + "connect", CONNECTKEYWORD, + "setpointer", SETPOINTERKEYWORD, + "access", ACCESSKEYWORD, + "insert", INSERTKEYWORD, + "uninsert", UNINSERTKEYWORD, + "forall", FORALL, + "ifsec", IFSEC, + "forsec", FORSEC, +#endif /*CABLE*/ +#if OOP + "begintemplate", BEGINTEMPLATE, + "endtemplate", ENDTEMPLATE, + "objectvar", OBJVARDECL, + "objref", OBJVARDECL, + "public", PUBLICDECL, + "external", EXTERNALDECL, + "new", NEW, +#endif + 0, 0 +}; +static struct { /* Constants */ + char *name; + double cval; +} consts[] = { + "PI", 3.14159265358979323846, + "E", 2.71828182845904523536, + "GAMMA",0.57721566490153286060, /* Euler */ + "DEG", 57.29577951308232087680, /* deg/radian */ + "PHI", 1.61803398874989484820, /* golden ratio */ +#if defined(LegacyFR) && LegacyFR == 1 + "FARADAY", 96485.309, /*coulombs/mole*/ + "R", 8.31441, /*molar gas constant, joules/mole/deg-K*/ +#else + /* Nov, 2017, from https://physics.nist.gov/cuu/Constants/index.html */ + /* also see FARADAY and gasconstant in ../nrnoc/eion.cpp */ + "FARADAY", 96485.33289, /*coulombs/mole*/ + "R", 8.3144598, /*molar gas constant, joules/mole/deg-K*/ +#endif + 0, 0 +}; + +static struct { /* Built-ins */ + char *name; + double (*func)(double); +} builtins[] = { + "sin", sin, + "cos", cos, + "atan", atan, + "tanh", tanh, + "log", Log, /* checks argument */ + "log10", Log10, /* checks argument */ + "exp", hoc1_Exp, /* checks argument */ + "sqrt", Sqrt, /* checks argument */ + "int", integer, +#if MAC + "abs", Fabs, + "erf", Erf, + "erfc", Erfc, +#else + "abs", fabs, + "erf", erf, + "erfc", erfc, +#endif + 0, 0 +}; +static struct { /* Builtin functions with multiple or variable args */ + char *name; + void (*fun_blt)(void); +} fun_bltin[] = { + "atan2", hoc_atan2, + "system", hoc_System, + "prmat", hoc_Prmat, + "solve", hoc_solve, + "eqinit", hoc_eqinit, + "plt", hoc_Plt, + "axis", hoc_axis, + "plot", hoc_Plot, + "plotx", hoc_plotx, + "ploty", hoc_ploty, + "regraph", hoc_regraph, + "symbols", hoc_symbols, + "printf", hoc_PRintf, + "xred", hoc_Xred, + "sred", hoc_Sred, + "ropen", hoc_ropen, + "wopen", hoc_wopen, + "xopen", hoc_xopen, + "hoc_stdout",hoc_stdout, + "chdir", hoc_Chdir, + "fprint", hoc_Fprint, + "fscan", hoc_Fscan, + "sscanf", hoc_sscanf, + "sprint", hoc_Sprint, + "graph", hoc_Graph, + "graphmode", hoc_Graphmode, + "fmenu", hoc_fmenu, + "lw", hoc_Lw, + "getstr", hoc_Getstr, + "strcmp", hoc_Strcmp, + "setcolor", hoc_Setcolor, + "startsw", hoc_startsw, + "stopsw", hoc_stopsw, + "object_id", hoc_object_id, + "allobjectvars", hoc_allobjectvars, + "allobjects", hoc_allobjects, + "xpanel", hoc_xpanel, + "xbutton", hoc_xbutton, + "xcheckbox", hoc_xcheckbox, + "xstatebutton", hoc_xstatebutton, + "xlabel", hoc_xlabel, + "xmenu", hoc_xmenu, + "xvalue", hoc_xvalue, + "xpvalue", hoc_xpvalue, + "xradiobutton", hoc_xradiobutton, + "xfixedvalue", hoc_xfixedvalue, + "xvarlabel", hoc_xvarlabel, + "xslider", hoc_xslider, + "boolean_dialog", hoc_boolean_dialog, + "continue_dialog", hoc_continue_dialog, + "string_dialog", hoc_string_dialog, + "doEvents", hoc_single_event_run, + "doNotify", hoc_notify_iv, + "nrniv_bind_thread", nrniv_bind_thread, + "ivoc_style", ivoc_style, + "numarg", hoc_Numarg, + "argtype", hoc_Argtype, + "hoc_pointer_", hoc_pointer, /* for internal use */ + "nrn_mallinfo", hoc_mallinfo, + "execute", hoc_exec_cmd, + "execute1", hoc_execute1, + "load_proc", hoc_load_proc, + "load_func", hoc_load_func, + "load_template", hoc_load_template, + "load_file", hoc_load_file, + "load_java", hoc_load_java, + "unix_mac_pc", hoc_unix_mac_pc, + "show_winio", hoc_show_winio, + "nrn_load_dll", hoc_nrn_load_dll, + "machine_name", hoc_machine_name, + "saveaudit", hoc_Saveaudit, + "retrieveaudit", hoc_Retrieveaudit, + "coredump_on_error", hoc_coredump_on_error, + "checkpoint", hoc_checkpoint, + "quit", hoc_quit, + "object_push", hoc_object_push, + "object_pop", hoc_object_pop, + "pwman_place", hoc_pwman_place, + "save_session", hoc_save_session, + "print_session", hoc_print_session, + "show_errmess_always", hoc_show_errmess_always, + "execerror", hoc_Execerror, + "variable_domain", hoc_Symbol_limits, + "name_declared", hoc_name_declared, + "use_mcell_ran4", hoc_usemcran4, + "mcell_ran4", hoc_mcran4, + "mcell_ran4_init", hoc_mcran4init, + "nrn_feenableexcept", nrn_feenableexcept, + "nrnmpi_init", hoc_nrnmpi_init, +#if PVM + "numprocs", numprocs, + "myproc", myproc, + "psync", psync, +#endif +#if DOS + "settext", hoc_settext, +#endif +#if defined(WIN32) + "WinExec", hoc_win_exec, +#endif + 0, 0 +}; + +static struct { /* functions that return a string */ + char *name; + void (*strfun_blt)(void); +} strfun_bltin[] = { + "secname", hoc_secname, + "units", hoc_Symbol_units, + "neuronhome", hoc_neuronhome, + "getcwd", hoc_getcwd, + "nrnversion", hoc_nrnversion, + 0, 0 +}; + +static struct { /* functions that return an object */ + char *name; + void (*objfun_blt)(void); +} objfun_bltin[] = { + "object_pushed", hoc_object_pushed, + 0, 0 +}; + +double hoc_epsilon = 1.e-11; +double hoc_ac_; /*known to the interpreter to evaluate expressions with hoc_oc() */ +double* hoc_varpointer; /* executing hoc_pointer(&var) will put the address of + the variable in this location */ + +double hoc_cross_x_, hoc_cross_y_; /* For Graph class in ivoc */ +double hoc_default_dll_loaded_; + +char* neuron_home; +char* nrn_mech_dll; /* but actually only for NEURON mswin and linux */ +int nrn_noauto_dlopen_nrnmech; /* 0 except when binary special. */ +int use_mcell_ran4_; +int nrn_xopen_broadcast_; + +void hoc_init(void) /* install constants and built-ins table */ +{ + int i; + Symbol *s; + + use_mcell_ran4_ = 0; + nrn_xopen_broadcast_ = 255; + extern void hoc_init_space(void); + hoc_init_space(); + for (i = 0; keywords[i].name; i++) + IGNORE(install(keywords[i].name, keywords[i].kval, 0.0, &symlist)); + for (i = 0; consts[i].name; i++) { + s = install(consts[i].name, UNDEF, consts[i].cval, &symlist); + s->type = VAR; + s->u.pval = &consts[i].cval; + s->subtype = USERDOUBLE; + } + for (i = 0; builtins[i].name; i++) + { + s = install(builtins[i].name, BLTIN, 0.0, &symlist); + s->u.ptr = builtins[i].func; + } + for (i = 0; fun_bltin[i].name; i++) + { + s = install(fun_bltin[i].name, FUN_BLTIN, 0.0, &symlist); + s->u.u_proc->defn.pf = fun_bltin[i].fun_blt; + s->u.u_proc->nauto = 0; + s->u.u_proc->nobjauto = 0; + } + for (i = 0; strfun_bltin[i].name; i++) + { + s = install(strfun_bltin[i].name, FUN_BLTIN, 0.0, &symlist); + s->type = STRINGFUNC; + s->u.u_proc->defn.pf = strfun_bltin[i].strfun_blt; + s->u.u_proc->nauto = 0; + s->u.u_proc->nobjauto = 0; + } + for (i = 0; objfun_bltin[i].name; i++) + { + s = install(objfun_bltin[i].name, FUN_BLTIN, 0.0, &symlist); + s->type = OBJECTFUNC; + s->u.u_proc->defn.pf = objfun_bltin[i].objfun_blt; + s->u.u_proc->nauto = 0; + } + /* hoc_ac_ is a way to evaluate an expression using the interpreter */ + hoc_install_var("hoc_ac_", &hoc_ac_); + hoc_install_var("float_epsilon", &hoc_epsilon); + hoc_install_var("hoc_cross_x_", &hoc_cross_x_); + hoc_install_var("hoc_cross_y_", &hoc_cross_y_); + hoc_install_var("default_dll_loaded_", &hoc_default_dll_loaded_); + + s = install("xopen_broadcast_", UNDEF, 0.0, &hoc_symlist); + s->type = VAR; + s->subtype = USERINT; + s->u.pvalint = &nrn_xopen_broadcast_; + + /* initialize pointers ( why doesn't Vax do this?) */ + hoc_access = (int *)0; + spinit(); +#if OOP + hoc_class_registration(); + hoc_built_in_symlist = symlist; + symlist = (Symlist *)0; + /* start symlist and top level the same list */ + hoc_top_level_symlist = symlist = (Symlist *)emalloc(sizeof(Symlist)); + symlist->first = symlist->last = (Symbol *)0; + hoc_install_hoc_obj(); +#endif +} + +void hoc_unix_mac_pc(void) { + hoc_ret(); +#if defined(DARWIN) + hoc_pushx(4.); +#else +#if MAC + hoc_pushx(2.); +#else +#if defined(WIN32) + hoc_pushx(3.); +#else + hoc_pushx(1.); +#endif +#endif +#endif +} +void hoc_show_winio(void) { + int b; + b = (int)chkarg(1, 0., 1.); +#if MAC + hoc_sioux_show(b); +#endif +#if defined(WIN32) + hoc_winio_show(b); +#endif + hoc_ret(); + hoc_pushx(0.); +} + +int nrn_main_launch; + +void hoc_nrnversion(void) { + extern char* nrn_version(int); + static char* p; + int i; + i = 1; + if (ifarg(1)) { + i = (int)chkarg(1, 0., 20.); + } + hoc_ret(); + p = nrn_version(i); + hoc_pushstr(&p); +} + +void hoc_Execerror(void) { + char* c2 = (char*)0; + if (ifarg(2)) { + c2 = gargstr(2); + } + if (ifarg(1)) { + hoc_execerror(gargstr(1), c2); + }else{ + hoc_execerror_mes(c2, c2, 0); + } + /* never get here */ +} +// diff --git a/src/oc/hoc_oop.c b/src/oc/hoc_oop.cpp similarity index 88% rename from src/oc/hoc_oop.c rename to src/oc/hoc_oop.cpp index f6a9f0f1c6..2502adef01 100755 --- a/src/oc/hoc_oop.c +++ b/src/oc/hoc_oop.cpp @@ -11,6 +11,8 @@ #include "nrnfilewrap.h" #include + + #define PDEBUG 0 #define JAVA2NRN 1 @@ -35,14 +37,14 @@ void (*nrnpy_hpoasgn)(Object* o, int type); #include "nrniv_mf.h" int section_object_seen; struct Section* nrn_sec_pop(); -double* nrn_rangepointer(); +double* nrn_rangepointer(Section*, Symbol*, double x); static int connect_obsec_; #endif #define PUBLIC_TYPE 1 #define EXTERNAL_TYPE 2 static void call_constructor(Object*, Symbol*, int); -static void free_objectdata(Objectdata*, Template*); +static void free_objectdata(Objectdata*, cTemplate*); int hoc_print_first_instance = 1; @@ -56,7 +58,7 @@ void hoc_install_hoc_obj(void) { Symbol* s = hoc_install("_pysec", OBJECTVAR, 0.0, &hoc_top_level_symlist); hoc_install_object_data_index(s); hoc_objectdata[s->u.oboff].pobj = pobj = (Object**)emalloc(sizeof(Object*)); - pobj[0] = (Object*)0; + pobj[0] = nullptr; hoc_oc("objref hoc_obj_[2]\n"); hoc_obj_ = hoc_lookup("hoc_obj_"); @@ -67,7 +69,7 @@ Object* hoc_obj_get(int i) { if (p) { return p[i]; }else{ - return (Object*)0; + return nullptr; } } @@ -78,10 +80,10 @@ void hoc_obj_set(int i, Object* obj) { p[i] = obj; } -char* hoc_object_name(Object* ob) { +extern "C" char* hoc_object_name(Object* ob) { static char s[100]; if (ob) { - Sprintf(s, "%s[%d]", ob->template->sym->name, ob->index); + Sprintf(s, "%s[%d]", ob->ctemplate->sym->name, ob->index); }else{ Sprintf(s, "NULLobject"); } @@ -160,7 +162,7 @@ void hoc_obvar_declare(Symbol* sym, int type, int pmes) { if (sym->type != UNDEF) { return; } -assert(sym->public != 2); +assert(sym->cpublic != 2); if (pmes && hoc_symlist == hoc_top_level_symlist) { int b = 0; #if USE_NRNFILEWRAP @@ -187,7 +189,7 @@ assert(sym->public != 2); break; #if CABLE case SECTION: - OPSECITM(sym) = (struct Item**)0; + OPSECITM(sym) = nullptr; //TODO: whaa? (struct Item**)0; break; #endif default: @@ -239,7 +241,7 @@ static int obj_stack_loc; void hoc_object_push(void) { Object* ob = *hoc_objgetarg(1); - if (ob->template->constructor) { + if (ob->ctemplate->constructor) { hoc_execerror("Can't do object_push for built-in class", 0); } if (obj_stack_loc >= OBJ_STACK_SIZE) { @@ -249,7 +251,7 @@ void hoc_object_push(void) { obj_stack_[obj_stack_loc] = ob; hoc_thisobject = ob; if (ob) { - hoc_symlist = ob->template->symtable; + hoc_symlist = ob->ctemplate->symtable; hoc_objectdata = ob->u.dataspace; }else{ hoc_symlist = hoc_top_level_symlist; @@ -272,11 +274,11 @@ void hoc_object_pop(void) { if (obj_stack_loc < 1) { hoc_execerror("object context stack underflow", 0); } - obj_stack_[obj_stack_loc] = (Object*)0; + obj_stack_[obj_stack_loc] = nullptr; ob = obj_stack_[--obj_stack_loc]; hoc_thisobject = ob; if (ob) { - hoc_symlist = ob->template->symtable; + hoc_symlist = ob->ctemplate->symtable; hoc_objectdata = ob->u.dataspace; }else{ hoc_symlist = hoc_top_level_symlist; @@ -329,12 +331,12 @@ int hoc_obj_run(const char* cmd, Object* ob) { osloc = obj_stack_loc; if (ob) { - if (ob->template->constructor) { + if (ob->ctemplate->constructor) { hoc_execerror("Can't execute in a built-in class context", 0); } hoc_thisobject = ob; hoc_objectdata = ob->u.dataspace; - hoc_symlist = ob->template->symtable; + hoc_symlist = ob->ctemplate->symtable; }else{ hoc_thisobject = 0; hoc_objectdata = hoc_top_level_data; @@ -385,7 +387,7 @@ void hoc_exec_cmd(void) { /* execute string from top level or within an object c /* call a function within the context of an object. Args must be on stack */ double hoc_call_objfunc(Symbol* s, int narg, Object* ob) { - double d, hoc_call_func(); + double d; //, hoc_call_func(); Object* objsave; Objectdata* obdsave; Symlist* slsave; @@ -396,7 +398,7 @@ double hoc_call_objfunc(Symbol* s, int narg, Object* ob) { if (ob) { hoc_thisobject = ob; hoc_objectdata = ob->u.dataspace; - hoc_symlist = ob->template->symtable; + hoc_symlist = ob->ctemplate->symtable; }else{ hoc_thisobject = 0; hoc_objectdata = hoc_top_level_data; @@ -417,7 +419,7 @@ void hoc_oop_initaftererror(void) { templatestackp = templatestack; icntobjectdata = icnttoplevel; hoc_objectdata = hoc_top_level_data; - hoc_thisobject = (Object*)0; + hoc_thisobject = nullptr; obj_stack_loc = 0; hoc_in_template = 0; #if CABLE @@ -425,9 +427,10 @@ void hoc_oop_initaftererror(void) { #endif } -void oc_save_hoc_oop( +extern "C" void oc_save_hoc_oop( Object* *a1, Objectdata* *a2, + int **a3, // TODO a3 was missing int *a4, Symlist* *a5 ){ @@ -442,7 +445,7 @@ void oc_save_hoc_oop( *a5 = hoc_symlist; } -void oc_restore_hoc_oop( +extern "C" void oc_restore_hoc_oop( Object* *a1, Objectdata* *a2, int *a4, @@ -467,13 +470,13 @@ Object* hoc_new_object(Symbol* symtemp, void* v) { ob->recurse = 0; ob->unref_recurse_cnt = 0; ob->refcount = 1; /* so template notify will not delete */ - ob->observers = (void*)0; - ob->template = symtemp->u.template; - ob->aliases = (void*)0; - ob->itm_me = hoc_l_lappendobj(ob->template->olist, ob); + ob->observers = nullptr; + ob->ctemplate = symtemp->u.ctemplate; + ob->aliases = nullptr; + ob->itm_me = hoc_l_lappendobj(ob->ctemplate->olist, ob); ob->secelm_ = (hoc_Item*)0; - ob->template->count++; - ob->index = ob->template->index++; + ob->ctemplate->count++; + ob->index = ob->ctemplate->index++; if (symtemp->subtype & (CPLUSOBJECT | JAVAOBJECT)) { ob->u.this_pointer = v; if (v) { @@ -521,15 +524,15 @@ Object* hoc_newobj1(Symbol* sym, int narg) { Symbol *s; int i, total; - ob = hoc_new_object(sym, (void*)0); + ob = hoc_new_object(sym, nullptr); ob->refcount = 1; hoc_newobj1_err_ = ob; /* allow unref if execerror before return */ if (sym->subtype & (CPLUSOBJECT | JAVAOBJECT)) { call_constructor(ob, sym, narg); }else{ - ob->u.dataspace = obd = (Objectdata *)ecalloc(ob->template->dataspace_size, sizeof(Objectdata)); - for (s = ob->template->symtable->first; s; s = s->next) { - if (s->public != 2) { + ob->u.dataspace = obd = (Objectdata *)ecalloc(ob->ctemplate->dataspace_size, sizeof(Objectdata)); + for (s = ob->ctemplate->symtable->first; s; s = s->next) { + if (s->cpublic != 2) { switch (s->type) { case VAR: if ((obd[s->u.oboff + 1].arayinfo = s->arayinfo) != (Arrayinfo*)0) { @@ -566,18 +569,18 @@ Object* hoc_newobj1(Symbol* sym, int narg) { ++s->arayinfo->refcount; } total = hoc_total_array_data(s, obd); - obd[s->u.oboff].psecitm = (struct Item **)emalloc(total*sizeof(struct Item*)); + obd[s->u.oboff].psecitm = (hoc_Item **)emalloc(total*sizeof(hoc_Item*)); new_sections(ob, s, obd[s->u.oboff].psecitm, total); break; #endif } } } - if (ob->template->is_point_) { + if (ob->ctemplate->is_point_) { hoc_construct_point(ob, narg); } - if (ob->template->init) { - call_ob_proc(ob, ob->template->init, narg); + if (ob->ctemplate->init) { + call_ob_proc(ob, ob->ctemplate->init, narg); }else{ for (i=0; i < narg; ++i) { hoc_nopop(); @@ -648,7 +651,7 @@ static void call_constructor( pcsav = pc; push_frame(sym, narg); - ob->u.this_pointer = (ob->template->constructor)(ob); + ob->u.this_pointer = (ob->ctemplate->constructor)(ob); pop_frame(); pc = pcsav; @@ -679,7 +682,7 @@ void call_ob_proc(Object *ob, Symbol *sym, int narg){ obsav = hoc_thisobject; pcsav = pc; - if (ob->template->sym->subtype & CPLUSOBJECT) { + if (ob->ctemplate->sym->subtype & CPLUSOBJECT) { hoc_thisobject = ob; gui_redirect_obj_ = ob; push_frame(sym, narg); @@ -703,7 +706,7 @@ void call_ob_proc(Object *ob, Symbol *sym, int narg){ hoc_pushx(x); } #if JAVA2NRN - }else if (ob->template->sym->subtype & JAVAOBJECT) { + }else if (ob->ctemplate->sym->subtype & JAVAOBJECT) { hoc_thisobject = ob; push_frame(sym, narg); hoc_thisobject = obsav; @@ -727,7 +730,7 @@ void call_ob_proc(Object *ob, Symbol *sym, int narg){ } #endif /*JAVA2NRN*/ #if CABLE - }else if (ob->template->is_point_ && special_pnt_call(ob, sym, narg)) { + }else if (ob->ctemplate->is_point_ && special_pnt_call(ob, sym, narg)) { ;/*empty since special_pnt_call did the work for get_loc, has_loc, and loc*/ #endif }else{ @@ -738,7 +741,7 @@ void call_ob_proc(Object *ob, Symbol *sym, int narg){ hoc_objectdata = ob->u.dataspace; hoc_thisobject = ob; - hoc_symlist = ob->template->symtable; + hoc_symlist = ob->ctemplate->symtable; execute(callcode); if (sym->type == PROCEDURE) { hoc_nopop(); @@ -768,7 +771,7 @@ static void call_ob_iter(Object *ob, Symbol *sym, int narg){ hoc_objectdata = ob->u.dataspace; hoc_thisobject = ob; - hoc_symlist = ob->template->symtable; + hoc_symlist = ob->ctemplate->symtable; stmtobj = hoc_look_inside_stack(narg+1, OBJECTTMP)->obj; stmtbegin = pc + pc->i; @@ -799,7 +802,7 @@ void hoc_objvardecl(void) {/* symbol at pc+1, number of indices at pc+2 */ for (i=0; iu.oboff].pobj); + free(hoc_objectdata[sym->u.oboff].pobj); hoc_freearay(sym); }else{ sym->type = OBJECTVAR; @@ -838,7 +841,7 @@ void hoc_objectvar(void) { /* object variable symbol at pc+1. */ printf("code for hoc_objectvar()\n"); #endif obs = (pc++)->sym; - if (obs->public == 2) { + if (obs->cpublic == 2) { obs = obs->u.sym; odsav = hoc_objectdata_save(); obsav = hoc_thisobject; @@ -863,7 +866,7 @@ void hoc_objectvar(void) { /* object variable symbol at pc+1. */ void hoc_objectarg(void) { /* object arg index at pc+1. */ /* pointer to correct object left on stack */ int i; - Object **obp, **hoc_objgetarg(); + Object **obp; //, **hoc_objgetarg(); #if PDEBUG printf("code for hoc_objectarg()\n"); #endif @@ -878,8 +881,8 @@ void hoc_objectarg(void) { /* object arg index at pc+1. */ void hoc_constobject(void) { /* template at pc, index at pc+1, objpointer left on stack*/ char buf[200]; Object *obj; - Item* q; - Template* t = (pc++)->sym->u.template; + hoc_Item* q; + cTemplate* t = (pc++)->sym->u.ctemplate; int index = (int)hoc_xpop(); ITERATE (q, t->olist) { obj = OBJ(q); @@ -897,8 +900,8 @@ void hoc_constobject(void) { /* template at pc, index at pc+1, objpointer left o Object* hoc_name2obj(const char* name, int index) { char buf[200]; Object *obj; - Item* q; - Template* t; + hoc_Item* q; + cTemplate* t; Symbol* sym; sym = hoc_table_lookup(name, hoc_top_level_symlist); if (!sym) { @@ -907,7 +910,7 @@ Object* hoc_name2obj(const char* name, int index) { if (!sym || sym->type != TEMPLATE) { hoc_execerror(name, "is not a template"); } - t = sym->u.template; + t = sym->u.ctemplate; ITERATE (q, t->olist) { obj = OBJ(q); if (obj->index == index) { @@ -916,11 +919,11 @@ Object* hoc_name2obj(const char* name, int index) { break; } } - return (Object*)0; + return nullptr; } void hoc_object_id(void) { - Object *ob, **hoc_objgetarg(); + Object *ob;//, **hoc_objgetarg(); ob = *(hoc_objgetarg(1)); if (ifarg(2) && chkarg(2, 0., 1.) == 1.) { @@ -1016,7 +1019,7 @@ hoc_execerror("[...](...) syntax only allowed for array range variables:", sym0- obp = hoc_obj_look_inside_stack(nindex); if (obp) { #if USE_PYTHON - if (obp->template->sym == nrnpy_pyobj_sym_) { + if (obp->ctemplate->sym == nrnpy_pyobj_sym_) { if (isfunc & 2) { /* this is the final left hand side of an assignment to the method of a PythonObject @@ -1039,18 +1042,18 @@ hoc_execerror("Cannot assign to a PythonObject function call:", sym0->name); return; } #endif - if (obp->template->id == *ptid) { + if (obp->ctemplate->id == *ptid) { sym = *psym; }else{ if (obp->aliases == 0 || (sym = ivoc_alias_lookup(sym0->name, obp)) == 0) { /* lookup only has to be done once if the name is not an alias and the ptid of the object is still the same. */ - sym = hoc_table_lookup(sym0->name, obp->template->symtable); - if (!sym || sym->public != PUBLIC_TYPE) { -fprintf(stderr, "%s not a public member of %s\n", sym0->name, obp->template->sym->name); -hoc_execerror(obp->template->sym->name, sym0->name); + sym = hoc_table_lookup(sym0->name, obp->ctemplate->symtable); + if (!sym || sym->cpublic != PUBLIC_TYPE) { +fprintf(stderr, "%s not a public member of %s\n", sym0->name, obp->ctemplate->sym->name); +hoc_execerror(obp->ctemplate->sym->name, sym0->name); } - *ptid = obp->template->id; + *ptid = obp->ctemplate->id; *psym = sym; } } @@ -1060,7 +1063,7 @@ hoc_execerror(obp->template->sym->name, sym0->name); psav = hoc_objectdata_save(); obsav = hoc_thisobject; - cplus = (obp->template->sym->subtype & (CPLUSOBJECT | JAVAOBJECT)); + cplus = (obp->ctemplate->sym->subtype & (CPLUSOBJECT | JAVAOBJECT)); if (!cplus) { /* c++ classes don't have a hoc dataspace */ hoc_objectdata = obp->u.dataspace; hoc_thisobject = obp; @@ -1085,7 +1088,7 @@ hoc_execerror(obp->template->sym->name, sym0->name); } } hoc_pushs(sym); - (*obp->template->steer)(obp->u.this_pointer); + (*obp->ctemplate->steer)(obp->u.this_pointer); pd = hoc_pxpop(); /* cannot pop a temporary object til after the pd is used in case (e.g. Vector.x) the pointer is a field in the object @@ -1150,7 +1153,8 @@ hoc_execerror(obp->template->sym->name, sym0->name); #if CABLE case SECTIONREF: { extern Symbol* nrn_sec_sym; - Section* sec, *nrn_sectionref_steer(); + Section* sec; + extern Section* nrn_sectionref_steer(Section* sec, Symbol* sym, int* pnindex); //, *nrn_sectionref_steer(); section_object_seen = 1; sec = (Section*)obp->u.this_pointer; if (sym != nrn_sec_sym) { @@ -1229,7 +1233,7 @@ hoc_execerror(sym->name, ":ITERATOR can only be used in a for statement"); } } hoc_pushs(sym); - (*obp->template->steer)(obp->u.this_pointer); + (*obp->ctemplate->steer)(obp->u.this_pointer); pd = hoc_pxpop(); hoc_pop_defer(); hoc_pushpx(pd); @@ -1268,7 +1272,7 @@ void hoc_object_eval(void) { #if CABLE Datum* d = hoc_look_inside_stack(0, SYMBOL); if (d->sym->type == RANGEVAR) { - double* nrn_rangepointer(); +// double* nrn_rangepointer(); Symbol* sym = hoc_spop(); int narg = hoc_ipop(); struct Section* sec = nrn_sec_pop(); @@ -1280,7 +1284,7 @@ void hoc_object_eval(void) { } hoc_pushx(*(nrn_rangepointer(sec, sym, x))); }else if (d->sym->type == VAR && d->sym->subtype == USERPROPERTY) { - double cable_prop_eval(); + extern double cable_prop_eval(Symbol *); hoc_pushx(cable_prop_eval(hoc_spop())); } #endif @@ -1299,7 +1303,7 @@ void hoc_ob_pointer(void) { #if CABLE Datum* d = hoc_look_inside_stack(0, SYMBOL); if (d->sym->type == RANGEVAR) { - double* nrn_rangepointer(); +// double* nrn_rangepointer(Symbol *); Symbol* sym = hoc_spop(); int nindex = hoc_ipop(); struct Section* sec = nrn_sec_pop(); @@ -1311,7 +1315,7 @@ void hoc_ob_pointer(void) { } hoc_pushpx(nrn_rangepointer(sec, sym, x)); }else if (d->sym->type == VAR && d->sym->subtype == USERPROPERTY) { - double* cable_prop_eval_pointer(); +// double* cable_prop_eval_pointer(); hoc_pushpx(cable_prop_eval_pointer(hoc_spop())); }else{ hoc_execerror("Not a double pointer", 0); @@ -1415,7 +1419,7 @@ void hoc_object_asgn(void) { Object* o; int stkindex = hoc_obj_look_inside_stack_index(1); o = hoc_obj_look_inside_stack(1); - assert(o->template->sym == nrnpy_pyobj_sym_); + assert(o->ctemplate->sym == nrnpy_pyobj_sym_); if (op) { hoc_execerror("Invalid assignment operator for PythonObject", (char*)0); } @@ -1461,21 +1465,22 @@ void hoc_begintemplate(Symbol* t1) { type = t->type; if (type == TEMPLATE) { hoc_execerror(t->name, ": a template cannot be redefined"); + extern void hoc_free_symspace(Symbol*); hoc_free_symspace(t); }else if (type != UNDEF) { hoc_execerror(t->name, "already used as something besides template"); } - t->u.template = (Template *)emalloc(sizeof(Template)); + t->u.ctemplate = (cTemplate *)emalloc(sizeof(cTemplate)); t->type = TEMPLATE; - t->u.template->sym = t; - t->u.template->symtable = (Symlist *)0; - t->u.template->dataspace_size = 0; - t->u.template->constructor = 0; - t->u.template->destructor = 0; - t->u.template->is_point_ = 0; - t->u.template->steer = 0; - t->u.template->checkpoint = 0; - t->u.template->id = ++template_id; + t->u.ctemplate->sym = t; + t->u.ctemplate->symtable = (Symlist *)0; + t->u.ctemplate->dataspace_size = 0; + t->u.ctemplate->constructor = 0; + t->u.ctemplate->destructor = 0; + t->u.ctemplate->is_point_ = 0; + t->u.ctemplate->steer = 0; + t->u.ctemplate->checkpoint = 0; + t->u.ctemplate->id = ++template_id; pushtemplatei(icntobjectdata); pushtemplateodata(hoc_objectdata); pushtemplatei(hoc_in_template); @@ -1484,8 +1489,8 @@ void hoc_begintemplate(Symbol* t1) { pushtemplatesym(t); hoc_in_template = 1; hoc_objectdata = (Objectdata *)0; - hoc_thisobject = (Object*)0; - hoc_symlist = t->u.template->symtable; + hoc_thisobject = nullptr; + hoc_symlist = t->u.ctemplate->symtable; } void hoc_endtemplate(Symbol* t) { @@ -1497,24 +1502,24 @@ void hoc_endtemplate(Symbol* t) { if (strcmp(ts->name, t->name) != 0) { hoc_execerror(t->name, "- end template mismatched with begin"); } - ts->u.template->dataspace_size = icntobjectdata; - ts->u.template->symtable = hoc_symlist; - ts->u.template->count = 0; - ts->u.template->index = 0; - ts->u.template->olist = hoc_l_newlist(); - ts->u.template->observers = (void*)0; + ts->u.ctemplate->dataspace_size = icntobjectdata; + ts->u.ctemplate->symtable = hoc_symlist; + ts->u.ctemplate->count = 0; + ts->u.ctemplate->index = 0; + ts->u.ctemplate->olist = hoc_l_newlist(); + ts->u.ctemplate->observers = nullptr; hoc_symlist = (poptemplate())->symlist; - free_objectdata(hoc_objectdata, ts->u.template); + free_objectdata(hoc_objectdata, ts->u.ctemplate); hoc_thisobject = (poptemplate())->o; hoc_in_template = (poptemplate())->i; hoc_objectdata = (poptemplate())->odata; icntobjectdata = (poptemplate())->i; -ts->u.template->init = s = hoc_table_lookup("init", ts->u.template->symtable); +ts->u.ctemplate->init = s = hoc_table_lookup("init", ts->u.ctemplate->symtable); if (s && s->type != PROCEDURE) { hoc_execerror("'init' can only be used as the initialization procedure for new objects", (char *)0); } -ts->u.template->unref = s = hoc_table_lookup("unref", ts->u.template->symtable); +ts->u.ctemplate->unref = s = hoc_table_lookup("unref", ts->u.ctemplate->symtable); if (s && s->type != PROCEDURE) { hoc_execerror("'unref' can only be used as the callback procedure when the reference count is decremented", (char *)0); @@ -1532,7 +1537,7 @@ void class2oc( ){ extern int hoc_main1_inited_; Symbol* tsym, *s; - Template* t; + cTemplate* t; int i; if (hoc_lookup(name)) { @@ -1541,7 +1546,7 @@ void class2oc( tsym = hoc_install(name, UNDEF, 0.0, &hoc_symlist); tsym->subtype = CPLUSOBJECT; hoc_begintemplate(tsym); - t = tsym->u.template; + t = tsym->u.ctemplate; if (!hoc_main1_inited_ && t->id > hoc_max_builtin_class_id) { hoc_max_builtin_class_id = t->id; } @@ -1574,7 +1579,7 @@ Symbol* java2nrn_class( const char* meth ){ Symbol* tsym, *s; - Template* t; + cTemplate* t; int i, mid; const char* cp; char mname[256], signature[256], *cn, *buf; @@ -1586,7 +1591,7 @@ Symbol* java2nrn_class( printf("class %s methods:\n", tsym->name); tsym->subtype = JAVAOBJECT; hoc_begintemplate(tsym); - t = tsym->u.template; + t = tsym->u.ctemplate; t->id = -(id + 1); /* all others incremented from 1, must not be 0 */ t->constructor = p_java2nrn_cons; t->destructor = p_java2nrn_destruct; @@ -1713,11 +1718,11 @@ printf("%s derived from overloaded %s already exists\n", mname, s->name); if (s->name) { free(s->name); } - free((char*)s); + free(s); } hoc_endtemplate(tsym); i = 0; - for (s = tsym->u.template->symtable->first; s; s = s->next) { + for (s = tsym->u.ctemplate->symtable->first; s; s = s->next) { i += strlen(s->name) + 1; if (i >= 80) { printf("\n"); i = strlen(s->name) + 1; } printf(" %s", s->name); @@ -1751,7 +1756,7 @@ void hoc_add_publiclist(Symbol* s) { hoc_execerror("Not in a template\n", 0); } ss = hoc_decl(s); - ss->public = PUBLIC_TYPE; + ss->cpublic = PUBLIC_TYPE; } void hoc_external_var(Symbol* s) { @@ -1759,10 +1764,10 @@ void hoc_external_var(Symbol* s) { if (templatestackp == templatestack) { hoc_execerror("Not in a template\n", 0); } - if (s->public == PUBLIC_TYPE) { + if (s->cpublic == PUBLIC_TYPE) { hoc_execerror(s->name, "can't be public and external"); } - s->public = EXTERNAL_TYPE; + s->cpublic = EXTERNAL_TYPE; s0 = hoc_table_lookup(s->name, hoc_top_level_symlist); if (!s0) { hoc_execerror(s->name, "not declared at the top level"); @@ -1777,7 +1782,7 @@ void hoc_external_var(Symbol* s) { s->u.u_proc = s0->u.u_proc; break; case TEMPLATE: - s->u.template = s0->u.template; + s->u.ctemplate = s0->u.ctemplate; break; case STRING: case OBJECTVAR: @@ -1815,7 +1820,7 @@ void hoc_ob_check(int type) { } } -void hoc_free_allobjects(Template *template, Symlist *sl, Objectdata *data) { +void hoc_free_allobjects(cTemplate *ctemplate, Symlist *sl, Objectdata *data) { /* look in all object variables that point to objects with this template and null them */ Symbol *s; @@ -1823,24 +1828,24 @@ void hoc_free_allobjects(Template *template, Symlist *sl, Objectdata *data) { Object **obp; if (sl) for (s = sl->first; s; s = s->next) { - if (s->type == OBJECTVAR && s->public != 2) { + if (s->type == OBJECTVAR && s->cpublic != 2) { total = hoc_total_array_data(s, data); for (i=0; iu.oboff].pobj + i; if (*obp) { #if 1 - if ((*obp)->template == template) { + if ((*obp)->ctemplate == ctemplate) { hoc_dec_refcount(obp); }else if (s->subtype != CPLUSOBJECT) { /* descend to look for more */ -hoc_free_allobjects(template, (*obp)->template->symtable, (*obp)->u.dataspace); +hoc_free_allobjects(ctemplate, (*obp)->ctemplate->symtable, (*obp)->u.dataspace); } #else if (s->subtype != CPLUSOBJECT) { /* descend to look for more */ -hoc_free_allobjects(template, (*obp)->template->symtable, (*obp)->u.dataspace); +hoc_free_allobjects(ctemplate, (*obp)->ctemplate->symtable, (*obp)->u.dataspace); } - if ((*obp)->template == template) { + if ((*obp)->ctemplate == ctemplate) { hoc_dec_refcount(obp); } #endif @@ -1876,21 +1881,21 @@ int objectpath(Object* ob, Object* oblook, char* path, int depth) { } if (oblook) { if (depth++ > 5) { - hoc_warning("objectpath depth > 4 for", oblook->template->sym->name); + hoc_warning("objectpath depth > 4 for", oblook->ctemplate->sym->name); return 0; } - if (oblook->template->constructor) { + if (oblook->ctemplate->constructor) { return ivoc_list_look(ob, oblook, path, depth); }else{ od = oblook->u.dataspace; - sl = oblook->template->symtable; + sl = oblook->ctemplate->symtable; } }else{ od = hoc_top_level_data; sl = hoc_top_level_symlist; } if (sl) for (s = sl->first; s; s = s->next) { - if (s->type == OBJECTVAR && s->public != 2) { + if (s->type == OBJECTVAR && s->cpublic != 2) { total = hoc_total_array_data(s, od); for (i=0; iu.oboff].pobj + i; @@ -1907,12 +1912,12 @@ int objectpath(Object* ob, Object* oblook, char* path, int depth) { char* hoc_object_pathname(Object* ob) { static char path[512]; path[0] = '\0'; - if (objectpath(ob, (Object*)0, path, 0)) { + if (objectpath(ob, nullptr, path, 0)) { return path; }else{ #if 0 hoc_warning("Couldn't find a pathname to the object pointer", - ob->template->sym->name); + ob->ctemplate->sym->name); return (char*)0; #else return hoc_object_name(ob); @@ -1948,11 +1953,11 @@ void hoc_obj_unref(Object* obj){ printf("unreffing %s with refcount %d\n", hoc_object_name(obj), obj->refcount); #endif --obj->refcount; - if (obj->template->unref) { + if (obj->ctemplate->unref) { int i = obj->refcount; pushx((double)i); ++obj->unref_recurse_cnt; - call_ob_proc(obj, obj->template->unref, 1); + call_ob_proc(obj, obj->ctemplate->unref, 1); --obj->unref_recurse_cnt; } if (obj->refcount <= 0 && obj->unref_recurse_cnt == 0) { @@ -1963,22 +1968,22 @@ printf("unreffing %s with refcount %d\n", hoc_object_name(obj), obj->refcount); hoc_obj_disconnect(obj); } hoc_l_delete(obj->itm_me); - if (obj->template->observers) { + if (obj->ctemplate->observers) { hoc_template_notify(obj, 0); } - if (obj->template->sym->subtype & (CPLUSOBJECT | JAVAOBJECT)) { - (obj->template->destructor)(obj->u.this_pointer); + if (obj->ctemplate->sym->subtype & (CPLUSOBJECT | JAVAOBJECT)) { + (obj->ctemplate->destructor)(obj->u.this_pointer); }else{ obsav = hoc_thisobject; hoc_thisobject = obj; - free_objectdata(obj->u.dataspace, obj->template); + free_objectdata(obj->u.dataspace, obj->ctemplate); obj->u.dataspace = (Objectdata *)0; hoc_thisobject = obsav; } - if (--obj->template->count <= 0) { - obj->template->index = 0; + if (--obj->ctemplate->count <= 0) { + obj->ctemplate->index = 0; } - obj->template = (Template *)0; + obj->ctemplate = (cTemplate *)0; /* for testing purposes we don't free the object in order to make sure no object variable ever uses a freed object */ #if 1 @@ -1987,7 +1992,7 @@ printf("unreffing %s with refcount %d\n", hoc_object_name(obj), obj->refcount); } } -static void free_objectdata(Objectdata *od, Template *template){ +static void free_objectdata(Objectdata *od, cTemplate *ctemplate){ Symbol *s; int i, total; Objectdata *psav; @@ -1995,8 +2000,8 @@ static void free_objectdata(Objectdata *od, Template *template){ psav = hoc_objectdata; hoc_objectdata = od; - if (template->symtable) for (s=template->symtable->first; s; s=s->next) { - if (s->public != 2) { + if (ctemplate->symtable) for (s=ctemplate->symtable->first; s; s=s->next) { + if (s->cpublic != 2) { switch (s->type) { case VAR: /*printf("free_objectdata %s\n", s->name);*/ @@ -2016,16 +2021,16 @@ static void free_objectdata(Objectdata *od, Template *template){ } } free_arrayinfo(OPARINFO(s)); - free((char*)objp); + free(objp); break; #if CABLE case SECTION: total = hoc_total_array(s); for (i = 0; i < total; ++i) { - extern void sec_free(); +// extern void sec_free(); sec_free(*(OPSECITM(s) + i)); } - free((char*)OPSECITM(s)); + free(OPSECITM(s)); free_arrayinfo(OPARINFO(s)); break; #endif @@ -2033,8 +2038,8 @@ static void free_objectdata(Objectdata *od, Template *template){ } } #if CABLE - if (template->is_point_) { - void* v = od[template->dataspace_size-1]._pvoid; + if (ctemplate->is_point_) { + void* v = od[ctemplate->dataspace_size-1]._pvoid; if (v) { /* printf("Free point process\n");*/ destroy_point_process(v); @@ -2072,13 +2077,13 @@ void hoc_allobjects(void) { void hoc_allobjects1(Symlist* sl, int nspace) { Symbol* s; - Template* t; + cTemplate* t; Object* o; - Item* q; + hoc_Item* q; int i; if (sl) for (s = sl->first; s; s = s->next) { if (s->type == TEMPLATE) { - t = s->u.template; + t = s->u.ctemplate; ITERATE(q, t->olist) { o = OBJ(q); for (i=0; i < nspace; ++i) { @@ -2092,12 +2097,12 @@ Printf("%s with %d refs\n", hoc_object_name(o), o->refcount); } void hoc_allobjects2(Symbol* s, int nspace) { - Template* t; + cTemplate* t; Object* o; - Item* q; + hoc_Item* q; int i; if (s && s->type == TEMPLATE) { - t = s->u.template; + t = s->u.ctemplate; ITERATE(q, t->olist) { o = OBJ(q); for (i=0; i < nspace; ++i) { @@ -2124,7 +2129,7 @@ static void hoc_list_allobjref(Symlist *sl, Objectdata *data, int depth) { Object **obp; if (sl) for (s = sl->first; s; s = s->next) { - if (s->type == OBJECTVAR && s->public != 2) { + if (s->type == OBJECTVAR && s->cpublic != 2) { total = hoc_total_array_data(s, data); for (i=0; iu.oboff].pobj + i; @@ -2143,7 +2148,7 @@ Printf("obp %s[%d] -> %s with %d refs.\n", ) { /* descend to look for more */ (*obp)->recurse = 1; -hoc_list_allobjref((*obp)->template->symtable, (*obp)->u.dataspace, depth+1); +hoc_list_allobjref((*obp)->ctemplate->symtable, (*obp)->u.dataspace, depth+1); (*obp)->recurse = 0; } } @@ -2151,24 +2156,25 @@ hoc_list_allobjref((*obp)->template->symtable, (*obp)->u.dataspace, depth+1); } } -void check_obj_type(Object* obj, const char* typename) { +void check_obj_type(Object* obj, const char* type_name) { char buf[100]; - if (!obj || strcmp(obj->template->sym->name, typename) != 0) { + if (!obj || strcmp(obj->ctemplate->sym->name, type_name) != 0) { if (obj) { sprintf(buf, "object type is %s instead of", - obj->template->sym->name); + obj->ctemplate->sym->name); }else{ sprintf(buf, "object type is nil instead of"); } - hoc_execerror(buf, typename); + hoc_execerror(buf, type_name); } } -int is_obj_type(Object* obj, const char* typename) { - if (obj && strcmp(obj->template->sym->name, typename) == 0) { +int is_obj_type(Object* obj, const char* type_name) { + if (obj && strcmp(obj->ctemplate->sym->name, type_name) == 0) { return 1; }else{ return 0; } } + diff --git a/src/oc/hocassrt.h b/src/oc/hocassrt.h index cfa0a1e822..93ef4581a4 100755 --- a/src/oc/hocassrt.h +++ b/src/oc/hocassrt.h @@ -8,13 +8,18 @@ # ifndef stderr # include # endif + #if defined(__cplusplus) extern "C" { #endif + extern void hoc_execerror(const char*, const char*); + #if defined(__cplusplus) } #endif + + #if defined(__STDC__) # define assert(ex) {if (!(ex)){fprintf(stderr,"Assertion failed: file %s, line %d\n", __FILE__,__LINE__);hoc_execerror(#ex, (char *)0);}} #else diff --git a/src/oc/hocdec.h b/src/oc/hocdec.h index b865d40e90..733a09ca1b 100644 --- a/src/oc/hocdec.h +++ b/src/oc/hocdec.h @@ -4,9 +4,6 @@ #define INCLUDEHOCH 1 #define OOP 1 -#if defined(__cplusplus) -extern "C" { -#endif #include #include "nrnapi.h" @@ -120,11 +117,11 @@ typedef struct Symbol { /* symbol table entry */ char *name; short type; short subtype; /* Flag for user integers */ -#if defined(__cplusplus) +//#if defined(__cplusplus) short cpublic; /* flag set public variable */ -#else - short public; /* flag set public variable */ -#endif +//#else +// short public; /* flag set public variable */ +//#endif short defined_on_the_fly;/* moved here because otherwize gcc and borland do not align the same way */ union { int oboff; /* offset into object data pointer space */ @@ -139,18 +136,18 @@ typedef struct Symbol { /* symbol table entry */ int *pvalint; /* User defined integers */ float *pvalfloat; /* User defined floats */ int u_auto; /* stack offset # for AUTO variable */ - double (*ptr)(); /* if BLTIN */ + double (*ptr)(double); /* if BLTIN */ //TODO: double as parameter? Proc *u_proc; struct { short type; /* Membrane type to find Prop */ int index; /* prop->param[index] */ }rng; HocStruct Symbol **ppsym; /* Pointer to symbol pointer array */ -#if defined(__cplusplus) +//#if defined(__cplusplus) HocStruct cTemplate *ctemplate; -#else - HocStruct Template *template; -#endif +//#else +// HocStruct cTemplate *template; +//#endif HocStruct Symbol* sym; /* for external */ } u; unsigned s_varn; /* dependent variable number - 0 means indep */ @@ -182,15 +179,15 @@ typedef union Datum { /* interpreter stack type */ char **pstr; HocStruct hoc_Item* itm; hoc_List* lst; - void* _pvoid; /* not used on stack, see nrnoc/point.c */ + void* _pvoid; /* not used on stack, see nrnoc/point.cpp */ } Datum; #if OOP -#if defined(__cplusplus) +//#if defined(__cplusplus) typedef struct cTemplate { -#else -typedef struct Template { -#endif +//#else +//typedef struct Template { +//#endif Symbol *sym; Symlist *symtable; int dataspace_size; @@ -206,11 +203,11 @@ typedef struct Template { void (*destructor)(void*); void (*steer)(void*); /* normally nil */ int (*checkpoint)(void**); -#if defined(__cplusplus) +//#if defined(__cplusplus) } cTemplate; -#else -} Template; -#endif +//#else +//} +//#endif typedef union Objectdata{ double *pval; /* pointer to array of doubles, usually just 1 */ @@ -232,7 +229,7 @@ typedef struct Object { #if defined(__cplusplus) cTemplate *ctemplate; #else - Template *template; + cTemplate *template; #endif void* aliases; /* more convenient names for e.g. Vector or List elements dynamically created by this object*/ HocStruct hoc_Item* itm_me;/* this object in the template list */ @@ -276,10 +273,19 @@ typedef struct { /* units for symbol values */ #include "oc_ansi.h" +#if defined(__cplusplus) +extern "C" { +#endif + extern void* emalloc(size_t n); extern void* ecalloc(size_t n, size_t size); extern void* erealloc(void* ptr, size_t n); +#if defined(__cplusplus) +} +#endif + + extern Inst *hoc_progp, *hoc_progbase, *hoc_prog, *hoc_prog_parse_recover; extern Inst *hoc_pc; @@ -356,8 +362,5 @@ int node_num; int mytid; #endif -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/oc/hocedit.c b/src/oc/hocedit.cpp similarity index 54% rename from src/oc/hocedit.c rename to src/oc/hocedit.cpp index d84d338134..248e1ea9f0 100755 --- a/src/oc/hocedit.c +++ b/src/oc/hocedit.cpp @@ -29,32 +29,32 @@ hocedit.c,v * * Revision 1.1 91/10/11 11:12:07 hines * Initial revision - * + * * Revision 4.43 91/10/01 11:34:24 hines * gather console input at one place in preparation for adding * emacs like command line editing. Hoc input now reads entire line. - * + * * Revision 4.37 91/08/13 19:50:49 hines * can now use em after window size is changed. - * + * * Revision 3.108 90/10/24 09:44:12 hines * saber warnings gone - * + * * Revision 3.83 90/07/25 10:40:25 hines * almost lint free on sparc 1+ under sunos 4.1 - * + * * Revision 3.4 89/07/12 10:27:18 mlh * Lint free - * + * * Revision 3.3 89/07/10 15:46:16 mlh * Lint pass1 is silent. Inst structure changed to union. - * + * * Revision 2.0 89/07/07 11:31:46 mlh * Preparation for newcable - * + * * Revision 1.1 89/07/07 11:16:25 mlh * Initial revision - * + * */ /* example to show how microemacs can be embedded in a larger program */ @@ -64,8 +64,9 @@ hocedit.c,v #include #include + #if MAC - #define OCSMALL 1 +#define OCSMALL 1 #endif #if defined(WITHOUT_MEMACS) @@ -76,10 +77,11 @@ hocedit.c,v #if !OCSMALL #include "estruct.h" - -extern int emacs_main(int n, char** cpp); +extern "C" { +extern int emacs_main(int n, char **cpp); extern int emacs_refresh(int i, int j); extern int emacs_vtinit(void); +} // extern "C" #define IGNORE(arg) arg #define Fprintf fprintf @@ -96,7 +98,7 @@ static int called = 0; static LINE *lp, *lhead; static short cnt; -static char *argv[] = { "embedded", (char *)0}; +static char *argv[] = { "embedded", nullptr}; #endif /* !OCSMALL */ @@ -104,129 +106,131 @@ void hoc_edit(void) { #if !OCSMALL #if DOS || defined(__GO32__) /*must erase screen if in graphics mode*/ - extern int egagrph; + extern int egagrph; if (egagrph) { plt(-3,0.,0.); } #endif - if (hoc_retrieving_audit()) { - hoc_emacs_from_audit(); - return; - } - if (setjmp(emacs_begin)) { - return; - } - if (!called) { - called = 1; - emacs_main(1, argv); - } else { - emacs_vtinit(); - emacs_refresh(0, 1); - emacs_main(-1, argv); - } + if (hoc_retrieving_audit()) { + hoc_emacs_from_audit(); + return; + } + if (setjmp(emacs_begin)) { + return; + } + if (!called) { + called = 1; + emacs_main(1, argv); + } else { + emacs_vtinit(); + emacs_refresh(0, 1); + emacs_main(-1, argv); + } #endif } void hoc_edit_quit(void) { #if !OCSMALL - char s[2]; - if (called) { - argv[0] = s; - argv[0][0] = 'Z' & 037; - rewind(stdin); /* else continuous EOF */ - hoc_edit(); - } + char s[2]; + if (called) { + argv[0] = s; + argv[0][0] = 'Z' & 037; + rewind(stdin); /* else continuous EOF */ + hoc_edit(); + } #endif } -int emacs_exit(int status) { +extern "C" int emacs_exit(int status) { #if !OCSMALL - if (status) { - Fprintf(stderr, "emacs--status = %d\n", status); - hoc_pipeflag = 0; - hoc_execerror("Error in emacs return", (char *)0); - } - - if (status == 0) { - lhead = emacs_curbp->b_linep; - lp = lforw(lhead); - cnt = 0; - hoc_pipeflag = 1; - hoc_lineno = 0; - hoc_audit_from_emacs(emacs_curbp->b_bname, emacs_curbp->b_fname); - lp = lforw(lhead); - cnt = 0; - } - longjmp(emacs_begin, 1); + if (status) { + Fprintf(stderr, "emacs--status = %d\n", status); + hoc_pipeflag = 0; + hoc_execerror("Error in emacs return", (char *)0); + } + + if (status == 0) { + lhead = emacs_curbp->b_linep; + lp = lforw(lhead); + cnt = 0; + hoc_pipeflag = 1; + hoc_lineno = 0; + hoc_audit_from_emacs(emacs_curbp->b_bname, emacs_curbp->b_fname); + lp = lforw(lhead); + cnt = 0; + } + longjmp(emacs_begin, 1); #endif - return 0; + return 0; } #if !OCSMALL - static LINE *lastlp; +static LINE *lastlp; #endif void hoc_pipeflush(void) { #if !OCSMALL -if (hoc_pipeflag == 1) { - extern int hoc_ictp; - if (ired("\nReenter emacs", 1, 0, 1)) { - emacs_curwp->w_dotp = lback(lp); - if (hoc_ictp < llength(lback(lp))) { - emacs_curwp->w_doto = hoc_ictp; - }else{ - emacs_curwp->w_doto = llength(lback(lp))-1; - } - IGNORE(emacs_refresh(1, 1)); /* recenters "." in current window */ - hoc_edit(); - } else { - cnt = 0; - lp = lastlp = lhead; - } -} + if (hoc_pipeflag == 1) { + extern int hoc_ictp; + if (ired("\nReenter emacs", 1, 0, 1)) { + emacs_curwp->w_dotp = lback(lp); + if (hoc_ictp < llength(lback(lp))) { + emacs_curwp->w_doto = hoc_ictp; + }else{ + emacs_curwp->w_doto = llength(lback(lp))-1; + } + IGNORE(emacs_refresh(1, 1)); /* recenters "." in current window */ + hoc_edit(); + } else { + cnt = 0; + lp = lastlp = lhead; + } + } #endif } size_t hoc_pipegets_need(void) { - int hoc_strgets_need(); +// int hoc_strgets_need(); #if !OCSMALL - if (hoc_pipeflag == 1) { - if (lp == lhead) { - return 0; - }else{ - return llength(lp); - } - }else{ - return hoc_strgets_need(); - } + if (hoc_pipeflag == 1) { + if (lp == lhead) { + return 0; + }else{ + return llength(lp); + } + }else{ + return hoc_strgets_need(); + } #else - return hoc_strgets_need(); + return hoc_strgets_need(); #endif } char* hoc_pipegets(char* cbuf, int nc) { - char *hoc_strgets(), *cp=cbuf; - - nc--; + char *cp = cbuf; + + nc--; #if !OCSMALL -if (hoc_pipeflag == 1) { - if (lp == lhead) { - cnt = 0; - return (char *)0; - } - for (cnt=0; cnt < llength(lp) && cnt < nc; cnt++) { - *cp++ = lgetc(lp, cnt); - } - *cp++ = '\n'; - *cp = '\0'; - lp = lforw(lp); - return cbuf; -}else{ + if (hoc_pipeflag == 1) { + if (lp == lhead) { + cnt = 0; + return (char *) 0; + } + for (cnt = 0; cnt < llength(lp) && cnt < nc; cnt++) { + *cp++ = lgetc(lp, cnt); + } + *cp++ = '\n'; + *cp = '\0'; + lp = lforw(lp); + return cbuf; + } else { #else -{ + { #endif - return hoc_strgets(cbuf, nc); -} + return hoc_strgets(cbuf, nc); + } } + + diff --git a/src/oc/hoclist.h b/src/oc/hoclist.h index 768109adbf..d7caf04b32 100755 --- a/src/oc/hoclist.h +++ b/src/oc/hoclist.h @@ -74,52 +74,43 @@ typedef struct hoc_Item { /* * An item type, STRING is also used as an item type */ +// -#ifdef __cplusplus -extern "C" { -#endif - -extern char* hoc_l_stralloc(const char*, char* release); -extern hoc_List* hoc_l_newlist(); -extern hoc_Item* hoc_l_insertstr(hoc_Item*, const char*); -extern hoc_Item* hoc_l_insertsym(hoc_Item*, struct Symbol*); -extern hoc_Item* hoc_l_insertitem(hoc_Item*, hoc_Item*); -extern hoc_Item* hoc_l_insertlist(hoc_Item*, hoc_List*); -extern hoc_Item* hoc_l_insertsec(hoc_Item*, struct Section*); -extern hoc_Item* hoc_l_insertvoid(hoc_Item*, void*); - -extern hoc_Item* hoc_l_linsertstr(hoc_List*, const char*); -extern hoc_Item* hoc_l_linsertsym(hoc_List*, struct Symbol*); +extern char *hoc_l_stralloc(const char *, char *release); +extern hoc_List *hoc_l_newlist(); +extern hoc_Item *hoc_l_insertstr(hoc_Item *, const char *); +extern hoc_Item *hoc_l_insertsym(hoc_Item *, struct Symbol *); +extern hoc_Item *hoc_l_insertitem(hoc_Item *, hoc_Item *); +extern hoc_Item *hoc_l_insertlist(hoc_Item *, hoc_List *); +extern hoc_Item *hoc_l_insertsec(hoc_Item *, struct Section *); +extern hoc_Item *hoc_l_insertvoid(hoc_Item *, void *); +extern hoc_Item *hoc_l_linsertstr(hoc_List *, const char *); +extern hoc_Item *hoc_l_linsertsym(hoc_List *, struct Symbol *); +extern hoc_Item *hoc_l_lappendstr(hoc_List *, const char *); +extern hoc_Item *hoc_l_lappendsym(hoc_List *, struct Symbol *); +extern hoc_Item *hoc_l_lappenditem(hoc_List *, hoc_Item *); +extern hoc_Item *hoc_l_lappendlst(hoc_List *, hoc_List *); +extern hoc_Item *hoc_l_lappendsec(hoc_List *, struct Section *); +extern hoc_Item *hoc_l_lappendvoid(hoc_List *, void *); +extern hoc_Item *hoc_l_lappendobj(hoc_List *, struct Object *); +extern void hoc_l_freelist(hoc_List **); +extern hoc_Item *hoc_l_next(hoc_Item *); +extern hoc_Item *hoc_l_prev(hoc_Item *); +extern void hoc_l_delete(hoc_Item *); +extern void hoc_l_move(hoc_Item *, hoc_Item *, hoc_Item *); +extern void hoc_l_movelist(hoc_Item *, hoc_Item *, hoc_List *); +extern void hoc_l_replacstr(hoc_Item *, const char *); -extern hoc_Item* hoc_l_lappendstr(hoc_List*, const char*); -extern hoc_Item* hoc_l_lappendsym(hoc_List*, struct Symbol*); -extern hoc_Item* hoc_l_lappenditem(hoc_List*, hoc_Item*); -extern hoc_Item* hoc_l_lappendlst(hoc_List*, hoc_List*); -extern hoc_Item* hoc_l_lappendsec(hoc_List*, struct Section*); -extern hoc_Item* hoc_l_lappendvoid(hoc_List*, void*); -extern hoc_Item* hoc_l_lappendobj(hoc_List*, struct Object*); +#define Insertstr insertstr +#define Insertsym insertsym +#define Insertsec insertsec +#define Linsertsym linsertsym +#define Linsertstr linsertstr +#define Lappendsym lappendsym +#define Lappendstr lappendstr +#define Lappenditem lappenditem +#define Lappendlst lappendlst +#define Lappendsec lappendsec -extern void hoc_l_freelist(hoc_List**); -extern hoc_Item* hoc_l_next(hoc_Item*); -extern hoc_Item* hoc_l_prev(hoc_Item*); -extern void hoc_l_delete(hoc_Item*); -extern void hoc_l_move(hoc_Item*, hoc_Item*, hoc_Item*); -extern void hoc_l_movelist(hoc_Item*, hoc_Item*, hoc_List*); -extern void hoc_l_replacstr(hoc_Item*, const char*); - -#define Insertstr insertstr -#define Insertsym insertsym -#define Insertsec insertsec -#define Linsertsym linsertsym -#define Linsertstr linsertstr -#define Lappendsym lappendsym -#define Lappendstr lappendstr -#define Lappenditem lappenditem -#define Lappendlst lappendlst -#define Lappendsec lappendsec - -#ifdef __cplusplus -} -#endif #endif diff --git a/src/oc/hocparse.h b/src/oc/hocparse.h index 07f7ea2d09..6483013170 100644 --- a/src/oc/hocparse.h +++ b/src/oc/hocparse.h @@ -3,9 +3,6 @@ #include "hoc.h" -#if defined(__cplusplus) -extern "C" { -#endif /* do not know why this is not in parse.h */ extern int yyparse(void); @@ -17,9 +14,7 @@ extern int hoc_yyparse(void); extern void hoc_define(Symbol*); extern void hoc_iterator_object(Symbol*, int, Inst*, Inst*, Object*); extern int hoc_zzdebug; -extern void hoc_debugzz(Inst*); extern int hoc_moreinput(void); -extern void hoc_free_symspace(Symbol*); extern Symlist* hoc_p_symlist; extern void hoc_defnonly(const char*); extern Symbol* hoc_decl(Symbol*); @@ -43,8 +38,5 @@ extern void hoc_help(void); extern char* hoc_strgets(char*, int); extern int hoc_strgets_need(void); -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/oc/hocstr.h b/src/oc/hocstr.h index d29b8a0682..9a34286c0e 100755 --- a/src/oc/hocstr.h +++ b/src/oc/hocstr.h @@ -3,6 +3,8 @@ #include /* too many time char* buf overruns its storage */ + + typedef struct HocStr { char* buf; size_t size; @@ -14,5 +16,5 @@ extern void hocstr_delete(HocStr*); void hocstr_resize(HocStr*, size_t); void hocstr_copy(HocStr*, const char*); -#endif +#endif diff --git a/src/oc/hocusr.c b/src/oc/hocusr.c deleted file mode 100755 index 33bf6fa152..0000000000 --- a/src/oc/hocusr.c +++ /dev/null @@ -1,166 +0,0 @@ -#include <../../nrnconf.h> - -/* version 7.2.1 2-jan-89 */ -#include -#include -#include "hocdec.h" -#include "parse.h" -#if 1 -#include "hocusr.h" -#endif - -# define CHECK(name) nrn_load_name_check(name) - -static char CHKmes[] = "The user defined name, %s, already exists.\n"; - -Symlist* nrn_load_dll_called_; - -/* Return 0 if nrn_load_dll_called_ == NULL, otherwise recover and return 1. - If 1 is returned, then can recover with a hoc_execerror. -*/ -int nrn_load_dll_recover_error() { - if (nrn_load_dll_called_) { - /* recoverable error for nrn_load_dll interpreter call */ - hoc_built_in_symlist = hoc_symlist; - hoc_symlist = nrn_load_dll_called_; - nrn_load_dll_called_ = (Symlist*)0; - return 1; - } - return 0; -} - -void nrn_load_name_check(const char* name) { - if (hoc_lookup(name) != (Symbol *)0) { - if (nrn_load_dll_recover_error()) { - hoc_execerror("The user defined name already exists:", name); - }else{ - fprintf(stderr, CHKmes, name); - nrn_exit(1); - } - } -} - - -static void arayinstal(Symbol* sp, int nsub, int sub1, int sub2, int sub3); - -void hoc_spinit(void) /* install user variables and functions */ -{ - int i; - Symbol *s; - - hoc_register_var(scdoub, vdoub, function); - for (i = 0; scint[i].name; i++) - { - CHECK(scint[i].name); - s = hoc_install(scint[i].name, UNDEF, 0.0, &hoc_symlist); - s->type = VAR; - s->u.pvalint = scint[i].pint; - s->subtype = USERINT; - } - for (i = 0; scfloat[i].name; i++) - { - CHECK(scfloat[i].name); - s = hoc_install(scfloat[i].name, UNDEF, 0.0, &hoc_symlist); - s->type = VAR; - s->u.pvalfloat = scfloat[i].pfloat; - s->subtype = USERFLOAT; - } - for (i = 0; vint[i].name; i++) - { - CHECK(vint[i].name); - s = hoc_install(vint[i].name, UNDEF, 0.0, &hoc_symlist); - s->type = VAR; - arayinstal(s, 1, vint[i].index1, 0, 0); - s->u.pvalint = vint[i].pint; - s->subtype = USERINT; - } - for (i = 0; vfloat[i].name; i++) - { - CHECK(vfloat[i].name); - s = hoc_install(vfloat[i].name, UNDEF, 0.0, &hoc_symlist); - s->type = VAR; - arayinstal(s, 1, vfloat[i].index1, 0, 0); - s->u.pvalfloat = vfloat[i].pfloat; - s->subtype = USERFLOAT; - } - for (i = 0; ardoub[i].name; i++) - { - CHECK(ardoub[i].name); - s = hoc_install(ardoub[i].name, UNDEF, 0.0, &hoc_symlist); - s->type = VAR; - arayinstal(s, 2, ardoub[i].index1, ardoub[i].index2, 0); - s->u.pval = ardoub[i].pdoub; - s->subtype = USERDOUBLE; - } - for (i = 0; thredim[i].name; i++) - { - CHECK(thredim[i].name); - s = hoc_install(thredim[i].name, UNDEF, 0.0, &hoc_symlist); - s->type = VAR; - arayinstal(s, 3, thredim[i].index1, thredim[i].index2, - thredim[i].index3); - s->u.pval = thredim[i].pdoub; - s->subtype = USERDOUBLE; - } - for (i = 0; function[i].name; i++) - { - if (!strncmp(function[i].name, "init", 4)) - { - hoc_fake_call(hoc_lookup(function[i].name)); - (*function[i].func)(); - continue; - } - } - hoc_last_init(); -} - -void hoc_register_var(DoubScal *scdoub, DoubVec *vdoub, VoidFunc *function) { - int i; - Symbol *s; - - if (scdoub) for (i = 0; scdoub[i].name; i++) - { - CHECK(scdoub[i].name); - s = hoc_install(scdoub[i].name, UNDEF, 0.0, &hoc_symlist); - s->type = VAR; - s->u.pval = scdoub[i].pdoub; - s->subtype = USERDOUBLE; - } - if (vdoub) for (i = 0; vdoub[i].name; i++) - { - CHECK(vdoub[i].name); - s = hoc_install(vdoub[i].name, UNDEF, 0.0, &hoc_symlist); - s->type = VAR; - arayinstal(s, 1, vdoub[i].index1, 0, 0); - s->u.pval = vdoub[i].pdoub; - s->subtype = USERDOUBLE; - } - if (function) for (i = 0; function[i].name; i++) - { - CHECK(function[i].name); - s=hoc_install(function[i].name, FUN_BLTIN, 0.0, &hoc_symlist); - s->u.u_proc->defn.pf = function[i].func; - s->u.u_proc->nauto = 0; - s->u.u_proc->nobjauto = 0; - } -} - -/* set up arayinfo */ -static void arayinstal(Symbol* sp, int nsub, int sub1, int sub2, int sub3) { - sp->type = VAR; - sp->s_varn = 0; - sp->arayinfo = (Arrayinfo *) emalloc( - (unsigned)(sizeof(Arrayinfo)+nsub*sizeof(int))); - sp->arayinfo->a_varn = (unsigned *) 0; - sp->arayinfo->nsub = nsub; - sp->arayinfo->sub[0] = sub1; - if (nsub > 1) - sp->arayinfo->sub[1] = sub2; - if (nsub > 2) - sp->arayinfo->sub[2] = sub3; -} - -void hoc_retpushx(double x) { /* utility return for user functions */ - hoc_ret(); - hoc_pushx(x); -} diff --git a/src/oc/hocusr.cpp b/src/oc/hocusr.cpp new file mode 100755 index 0000000000..e6a4ae3bef --- /dev/null +++ b/src/oc/hocusr.cpp @@ -0,0 +1,160 @@ +#include <../../nrnconf.h> + +/* version 7.2.1 2-jan-89 */ +#include +#include +#include "hocdec.h" +#include "parse.h" +#if 1 +#include "hocusr.h" +#endif + +# define CHECK(name) nrn_load_name_check(name) + + +static char CHKmes[] = "The user defined name, %s, already exists.\n"; + +Symlist *nrn_load_dll_called_; + +/* Return 0 if nrn_load_dll_called_ == NULL, otherwise recover and return 1. + If 1 is returned, then can recover with a hoc_execerror. +*/ +int nrn_load_dll_recover_error() { + if (nrn_load_dll_called_) { + /* recoverable error for nrn_load_dll interpreter call */ + hoc_built_in_symlist = hoc_symlist; + hoc_symlist = nrn_load_dll_called_; + nrn_load_dll_called_ = (Symlist *) 0; + return 1; + } + return 0; +} + +void nrn_load_name_check(const char *name) { + if (hoc_lookup(name) != (Symbol *) 0) { + if (nrn_load_dll_recover_error()) { + hoc_execerror("The user defined name already exists:", name); + } else { + fprintf(stderr, CHKmes, name); + nrn_exit(1); + } + } +} + + +static void arayinstal(Symbol *sp, int nsub, int sub1, int sub2, int sub3); + +void hoc_spinit(void) /* install user variables and functions */ +{ + int i; + Symbol *s; + + hoc_register_var(scdoub, vdoub, functions); + for (i = 0; scint[i].name; i++) { + CHECK(scint[i].name); + s = hoc_install(scint[i].name, UNDEF, 0.0, &hoc_symlist); + s->type = VAR; + s->u.pvalint = scint[i].pint; + s->subtype = USERINT; + } + for (i = 0; scfloat[i].name; i++) { + CHECK(scfloat[i].name); + s = hoc_install(scfloat[i].name, UNDEF, 0.0, &hoc_symlist); + s->type = VAR; + s->u.pvalfloat = scfloat[i].pfloat; + s->subtype = USERFLOAT; + } + for (i = 0; vint[i].name; i++) { + CHECK(vint[i].name); + s = hoc_install(vint[i].name, UNDEF, 0.0, &hoc_symlist); + s->type = VAR; + arayinstal(s, 1, vint[i].index1, 0, 0); + s->u.pvalint = vint[i].pint; + s->subtype = USERINT; + } + for (i = 0; vfloat[i].name; i++) { + CHECK(vfloat[i].name); + s = hoc_install(vfloat[i].name, UNDEF, 0.0, &hoc_symlist); + s->type = VAR; + arayinstal(s, 1, vfloat[i].index1, 0, 0); + s->u.pvalfloat = vfloat[i].pfloat; + s->subtype = USERFLOAT; + } + for (i = 0; ardoub[i].name; i++) { + CHECK(ardoub[i].name); + s = hoc_install(ardoub[i].name, UNDEF, 0.0, &hoc_symlist); + s->type = VAR; + arayinstal(s, 2, ardoub[i].index1, ardoub[i].index2, 0); + s->u.pval = ardoub[i].pdoub; + s->subtype = USERDOUBLE; + } + for (i = 0; thredim[i].name; i++) { + CHECK(thredim[i].name); + s = hoc_install(thredim[i].name, UNDEF, 0.0, &hoc_symlist); + s->type = VAR; + arayinstal(s, 3, thredim[i].index1, thredim[i].index2, + thredim[i].index3); + s->u.pval = thredim[i].pdoub; + s->subtype = USERDOUBLE; + } + for (i = 0; functions[i].name; i++) { + if (!strncmp(functions[i].name, "init", 4)) { + hoc_fake_call(hoc_lookup(functions[i].name)); + (*functions[i].func)(); + continue; + } + } + hoc_last_init(); +} + +void hoc_register_var(DoubScal *scdoub, DoubVec *vdoub, VoidFunc *fn) { + int i; + Symbol *s; + + if (scdoub) + for (i = 0; scdoub[i].name; i++) { + CHECK(scdoub[i].name); + s = hoc_install(scdoub[i].name, UNDEF, 0.0, &hoc_symlist); + s->type = VAR; + s->u.pval = scdoub[i].pdoub; + s->subtype = USERDOUBLE; + } + if (vdoub) + for (i = 0; vdoub[i].name; i++) { + CHECK(vdoub[i].name); + s = hoc_install(vdoub[i].name, UNDEF, 0.0, &hoc_symlist); + s->type = VAR; + arayinstal(s, 1, vdoub[i].index1, 0, 0); + s->u.pval = vdoub[i].pdoub; + s->subtype = USERDOUBLE; + } + if (fn) + for (i = 0; fn[i].name; i++) { + CHECK(fn[i].name); + s = hoc_install(fn[i].name, FUN_BLTIN, 0.0, &hoc_symlist); + s->u.u_proc->defn.pf = fn[i].func; + s->u.u_proc->nauto = 0; + s->u.u_proc->nobjauto = 0; + } +} + +/* set up arayinfo */ +static void arayinstal(Symbol *sp, int nsub, int sub1, int sub2, int sub3) { + sp->type = VAR; + sp->s_varn = 0; + sp->arayinfo = (Arrayinfo *) emalloc( + (unsigned) (sizeof(Arrayinfo) + nsub * sizeof(int))); + sp->arayinfo->a_varn = (unsigned *) 0; + sp->arayinfo->nsub = nsub; + sp->arayinfo->sub[0] = sub1; + if (nsub > 1) + sp->arayinfo->sub[1] = sub2; + if (nsub > 2) + sp->arayinfo->sub[2] = sub3; +} + +extern "C" void hoc_retpushx(double x) { /* utility return for user functions */ + hoc_ret(); + hoc_pushx(x); +} + diff --git a/src/oc/isaac64.c b/src/oc/isaac64.cpp similarity index 98% rename from src/oc/isaac64.c rename to src/oc/isaac64.cpp index cff0ad032c..bf78cd72e3 100644 --- a/src/oc/isaac64.c +++ b/src/oc/isaac64.cpp @@ -5,7 +5,7 @@ /* ------------------------------------------------------------------------------ -isaac64.c: A Fast cryptographic random number generator +isaac64.cpp: A Fast cryptographic random number generator for 32-bit and 64-bit machines. By Bob Jenkins, 1996. Public Domain. diff --git a/src/oc/isoc99.c b/src/oc/isoc99.c deleted file mode 100644 index 2f2ead2dfd..0000000000 --- a/src/oc/isoc99.c +++ /dev/null @@ -1,22 +0,0 @@ -#define _ISOC99_SOURCE -#include -#include -/* trying to safely determine if a pointer is a pointer to a double where the -double value would be in a specific range without causing floating exceptions -Of course this founders in general on the dereferencing of invalid memory -so it can only be used when pd is valid over sizeof(double). -*/ -int nrn_isdouble(void* pd, double min, double max) { - int i; - if (!pd) { return 0; } -#if defined(fpclassify) - i = fpclassify(*((double*)pd)); - if (i == FP_NORMAL || i == FP_ZERO) { - return *((double*)pd) >= min && *((double*)pd) <= max; - }else{ - return 0; - } -#else - return *((double*)pd) >= min && *((double*)pd) <= max; -#endif -} diff --git a/src/oc/isoc99.cpp b/src/oc/isoc99.cpp new file mode 100644 index 0000000000..6244f0edb9 --- /dev/null +++ b/src/oc/isoc99.cpp @@ -0,0 +1,26 @@ +#define _ISOC99_SOURCE +#include +#include +#include "isoc99.h" +/* trying to safely determine if a pointer is a pointer to a double where the +double value would be in a specific range without causing floating exceptions +Of course this founders in general on the dereferencing of invalid memory +so it can only be used when pd is valid over sizeof(double). +*/ + + +extern "C" int nrn_isdouble(double *pd, double min, double max) { + int i; + if (!pd) { return 0; } +#if defined(fpclassify) + i = fpclassify(*((double*)pd)); + if (i == FP_NORMAL || i == FP_ZERO) { + return *((double*)pd) >= min && *((double*)pd) <= max; + }else{ + return 0; + } +#else + return *((double *) pd) >= min && *((double *) pd) <= max; +#endif +} +// diff --git a/src/oc/isoc99.h b/src/oc/isoc99.h new file mode 100644 index 0000000000..cd07f30e1b --- /dev/null +++ b/src/oc/isoc99.h @@ -0,0 +1,6 @@ +#ifndef NRN_ISOC99_H +#define NRN_ISOC99_H + +extern "C" int nrn_isdouble(double *pd, double min, double max); + +#endif // NRN_ISOC99_H \ No newline at end of file diff --git a/src/oc/lineq.c b/src/oc/lineq.c deleted file mode 100755 index 14e13db409..0000000000 --- a/src/oc/lineq.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <../../nrnconf.h> -/* - * Automake doesn't deal well with sources that live in other directories, so - * this is a quick and dirty workaround. - */ -#include "../sparse/lineq.c" diff --git a/src/oc/lineq.cpp b/src/oc/lineq.cpp new file mode 100755 index 0000000000..c66b044b39 --- /dev/null +++ b/src/oc/lineq.cpp @@ -0,0 +1,6 @@ +#include <../../nrnconf.h> +/* + * Automake doesn't deal well with sources that live in other directories, so + * this is a quick and dirty workaround. + */ +#include "../sparse/lineq.cpp" diff --git a/src/oc/list.c b/src/oc/list.cpp similarity index 92% rename from src/oc/list.c rename to src/oc/list.cpp index 3f33177c41..2cdd5cb52c 100755 --- a/src/oc/list.c +++ b/src/oc/list.cpp @@ -118,7 +118,7 @@ Item* insertlist(Item* item, List* lst) { return i; } -Item* insertsym(Item* item, struct Symbol* sym) { +Item* insertsym(Item* item, Symbol* sym) { /* insert a symbol before item */ /* a copy is not made because we need the same symbol in different lists */ Item *i; @@ -129,7 +129,7 @@ Item* insertsym(Item* item, struct Symbol* sym) { return i; } -Item* insertsec(Item* item, struct Section* sec) { +Item* insertsec(Item* item, Section* sec) { /* insert a section before item */ Item *i; @@ -139,7 +139,7 @@ Item* insertsec(Item* item, struct Section* sec) { return i; } -Item* insertobj(Item* item, struct Object* obj) { +Item* insertobj(Item* item, Object* obj) { /* insert a object before item */ Item *i; @@ -167,11 +167,11 @@ Item* lappendstr(List* list, const char* str) { return insertstr(list, str); } -Item* linsertsym(List* list, struct Symbol* sym) { +Item* linsertsym(List* list, Symbol* sym) { return insertsym(list->next, sym); } -Item* lappendsym(List* list, struct Symbol* sym) { +Item* lappendsym(List* list, Symbol* sym) { return insertsym(list, sym); } @@ -183,11 +183,11 @@ Item* lappendlst(List* list, List* lst) { return insertlist(list, lst); } -Item* lappendsec(List* list, struct Section* sec) { +Item* lappendsec(List* list, Section* sec) { return insertsec(list, sec); } -Item* lappendobj(List* list, struct Object* obj) { +Item* lappendobj(List* list, Object* obj) { return insertobj(list, obj); } @@ -205,7 +205,7 @@ void delete(Item* item) { char* stralloc(const char* buf, char* rel) { /* allocate space, copy buf, and free rel */ char *s; - s = (char*)emalloc((unsigned)(strlen(buf) + 1)); + s = static_cast(emalloc((unsigned)(strlen(buf) + 1))); Strcpy(s, buf); if (rel) { Free(rel); diff --git a/src/oc/macprt.c b/src/oc/macprt.cpp similarity index 97% rename from src/oc/macprt.c rename to src/oc/macprt.cpp index c02eb415bb..f8996ed60e 100755 --- a/src/oc/macprt.c +++ b/src/oc/macprt.cpp @@ -7,6 +7,8 @@ #include "hoc.h" #include "gui-redirect.h" + + extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); extern double (*nrnpy_object_to_double_)(Object*); @@ -48,7 +50,7 @@ void setneuronhome(const char* p) { err = PBGetCatInfoSync(&myPB); if (err==noErr) { dirName[dirName[0]+1]='\0'; - strcpy(prePath, (char*)&dirName[1]); + strcpy(prePath, &dirName[1]); strcat(prePath, ":"); strcat(prePath, fullPath); strcpy(fullPath, prePath); @@ -133,7 +135,7 @@ hoc_Lw(){ret(); pushx(0.);} hoc_settext(){TRY_GUI_REDIRECT_DOUBLE("settext", NULL);ret(); pushx(0.);} hoc_Plot(){TRY_GUI_REDIRECT_DOUBLE("plot", NULL); ret();pushx(0.);} hoc_axis(){TRY_GUI_REDIRECT_DOUBLE("axis", NULL); ret();pushx(0.);} -hoc_fmenu() {ret();pushx(0.);} + //int gethostname() {printf("no gethostname\n");} @@ -145,4 +147,3 @@ hoc_menu_cleanup() { initplot() {} - diff --git a/src/oc/math.c b/src/oc/math.c deleted file mode 100755 index 58d0d5044c..0000000000 --- a/src/oc/math.c +++ /dev/null @@ -1,183 +0,0 @@ -#include <../../nrnconf.h> -/* a fake change */ -/* /local/src/master/nrn/src/oc/math.c,v 1.6 1999/07/16 13:43:10 hines Exp */ - -#include -#include -#include -#include "nrnmpiuse.h" -#include "ocfunc.h" -# include "hoc.h" - -#define EPS hoc_epsilon -#define MAXERRCOUNT 5 -int hoc_errno_count; - -#if _CRAY -#define log logl -#define log10 log10l -#define exp expl -#define sqrt sqrtl -#define pow powl -#endif - -static double errcheck(double, const char*); - -void hoc_atan2(void) { - double d; - d = atan2(*hoc_getarg(1), *hoc_getarg(2)); - hoc_ret(); - hoc_pushx(d); -} - -double Log(double x) -{ - return errcheck(log(x), "log"); -} - -double Log10(double x) -{ - return errcheck(log10(x), "log10"); -} - -/* used by nmodl and other c, c++ code */ -double hoc_Exp(double x) -{ - if (x < -700.) { - return 0.; - }else if (x > 700) { - errno = ERANGE; - if (++hoc_errno_count < MAXERRCOUNT) { - fprintf(stderr, "exp(%g) out of range, returning exp(700)\n", x); - } - if (hoc_errno_count == MAXERRCOUNT) { - fprintf(stderr, "No more errno warnings during this execution\n"); - } - return exp(700.); - } - return exp(x); -} - -/* used by interpreter */ -double hoc1_Exp(double x) -{ - if (x < -700.) { - return 0.; - }else if (x > 700) { - errno = ERANGE; - return errcheck(exp(700.), "exp"); - } - return errcheck(exp(x), "exp"); -} - -double Sqrt(double x) -{ - return errcheck(sqrt(x), "sqrt"); -} - -double Pow(double x, double y) -{ - return errcheck(pow(x, y), "exponentiation"); -} - -double integer(double x) -{ - if (x < 0) { - return (double)(long)(x - EPS); - }else{ - return (double)(long)(x + EPS); - } -} - -double errcheck(double d, const char* s) /* check result of library call */ -{ - if (errno == EDOM) - { - errno = 0; - hoc_execerror(s, "argument out of domain"); - } - else if (errno == ERANGE) - { - errno = 0; -#if 0 - hoc_execerror(s, "result out of range"); -#else - if (++hoc_errno_count > MAXERRCOUNT) { - }else{ - hoc_warning(s, "result out of range"); - if (hoc_errno_count == MAXERRCOUNT) { -fprintf(stderr, "No more errno warnings during this execution\n"); - } - } -#endif - } - return d; -} - -int hoc_errno_check(void) { - int ierr; -#if LINDA - static parallel_eagain = 0; -#endif - -#if 1 - errno = 0; - return 0; -#else - if (errno) { - if (errno == EAGAIN) { - /* Ubiquitous on many systems and it seems not to matter */ - errno = 0; - return 0; - } -#if BLUEGENE - if (errno == ENOSYS) { - errno = 0; - return 0; - } -#endif -#if !defined(MAC) || defined(DARWIN) - if (errno == ENOENT) { - errno = 0; - return 0; - } -#endif - if (++hoc_errno_count > MAXERRCOUNT) { - errno = 0; - return 0; - } -#if defined(CYGWIN) - if (errno == EBUSY) { - errno = 0; - return 0; - } -#endif - switch (errno) { - case EDOM: -fprintf(stderr, "A math function was called with argument out of domain\n"); - break; - case ERANGE: -fprintf(stderr, "A math function was called that returned an out of range value\n"); - break; -#if LINDA -/* regularly set by eval() and perhaps other linda commands */ - case EAGAIN: - if (parallel_eagain++ == 0) { - perror("oc"); -fprintf(stderr, "oc: This error occurs often from LINDA and thus will not be further reported.\n"); - } - break; -#endif - default: - perror("oc"); - break; - } - if (hoc_errno_count == MAXERRCOUNT) { -fprintf(stderr, "No more errno warnings during this execution\n"); - } - } - ierr = errno; - errno = 0; - return ierr; -#endif -} diff --git a/src/oc/math.cpp b/src/oc/math.cpp new file mode 100755 index 0000000000..ac59d7c124 --- /dev/null +++ b/src/oc/math.cpp @@ -0,0 +1,176 @@ +#include <../../nrnconf.h> +/* a fake change */ +/* /local/src/master/nrn/src/oc/math.cpp,v 1.6 1999/07/16 13:43:10 hines Exp */ + +#include +#include +#include +#include "nrnmpiuse.h" +#include "ocfunc.h" +# include "hoc.h" + + +#define EPS hoc_epsilon +#define MAXERRCOUNT 5 + +int hoc_errno_count; + +#if _CRAY +#define log logl +#define log10 log10l +#define exp expl +#define sqrt sqrtl +#define pow powl +#endif + +static double errcheck(double, const char *); + +void hoc_atan2(void) { + double d; + d = atan2(*hoc_getarg(1), *hoc_getarg(2)); + hoc_ret(); + hoc_pushx(d); +} + +double Log(double x) { + return errcheck(log(x), "log"); +} + +double Log10(double x) { + return errcheck(log10(x), "log10"); +} + +/* used by nmodl and other c, c++ code */ +extern "C" double hoc_Exp(double x) { + if (x < -700.) { + return 0.; + } else if (x > 700) { + errno = ERANGE; + if (++hoc_errno_count < MAXERRCOUNT) { + fprintf(stderr, "exp(%g) out of range, returning exp(700)\n", x); + } + if (hoc_errno_count == MAXERRCOUNT) { + fprintf(stderr, "No more errno warnings during this execution\n"); + } + return exp(700.); + } + return exp(x); +} + +/* used by interpreter */ +double hoc1_Exp(double x) { + if (x < -700.) { + return 0.; + } else if (x > 700) { + errno = ERANGE; + return errcheck(exp(700.), "exp"); + } + return errcheck(exp(x), "exp"); +} + +double Sqrt(double x) { + return errcheck(sqrt(x), "sqrt"); +} + +double Pow(double x, double y) { + return errcheck(pow(x, y), "exponentiation"); +} + +double integer(double x) { + if (x < 0) { + return (double) (long) (x - EPS); + } else { + return (double) (long) (x + EPS); + } +} + +double errcheck(double d, const char *s) /* check result of library call */ +{ + if (errno == EDOM) { + errno = 0; + hoc_execerror(s, "argument out of domain"); + } else if (errno == ERANGE) { + errno = 0; +#if 0 + hoc_execerror(s, "result out of range"); +#else + if (++hoc_errno_count > MAXERRCOUNT) { + } else { + hoc_warning(s, "result out of range"); + if (hoc_errno_count == MAXERRCOUNT) { + fprintf(stderr, "No more errno warnings during this execution\n"); + } + } +#endif + } + return d; +} + +int hoc_errno_check(void) { + int ierr; +#if LINDA + static parallel_eagain = 0; +#endif + +#if 1 + errno = 0; + return 0; +#else + if (errno) { + if (errno == EAGAIN) { + /* Ubiquitous on many systems and it seems not to matter */ + errno = 0; + return 0; + } +#if BLUEGENE + if (errno == ENOSYS) { + errno = 0; + return 0; + } +#endif +#if !defined(MAC) || defined(DARWIN) + if (errno == ENOENT) { + errno = 0; + return 0; + } +#endif + if (++hoc_errno_count > MAXERRCOUNT) { + errno = 0; + return 0; + } +#if defined(CYGWIN) + if (errno == EBUSY) { + errno = 0; + return 0; + } +#endif + switch (errno) { + case EDOM: +fprintf(stderr, "A math function was called with argument out of domain\n"); + break; + case ERANGE: +fprintf(stderr, "A math function was called that returned an out of range value\n"); + break; +#if LINDA +/* regularly set by eval() and perhaps other linda commands */ + case EAGAIN: + if (parallel_eagain++ == 0) { + perror("oc"); +fprintf(stderr, "oc: This error occurs often from LINDA and thus will not be further reported.\n"); + } + break; +#endif + default: + perror("oc"); + break; + } + if (hoc_errno_count == MAXERRCOUNT) { +fprintf(stderr, "No more errno warnings during this execution\n"); + } + } + ierr = errno; + errno = 0; + return ierr; +#endif +} + diff --git a/src/oc/mcran4.c b/src/oc/mcran4.cpp similarity index 90% rename from src/oc/mcran4.c rename to src/oc/mcran4.cpp index 09e8dd76ad..e89c1ee6c7 100755 --- a/src/oc/mcran4.c +++ b/src/oc/mcran4.cpp @@ -1,20 +1,20 @@ /* The copyrighted code from Numerical Recipes Software has been removed -and replaced by an independent implementation found in the random.c file +and replaced by an independent implementation found in the random.cpp file in function Ranint4 from http://www.inference.phy.cam.ac.uk/bayesys/BayesSys.tar.gz by John Skilling http://www.inference.phy.cam.ac.uk/bayesys/ The code fragment was further modified by Michael Hines to change prototypes and produce output identical to the old version. This code is now -placed under the General GNU Public License, version 2. The random.c file +placed under the General GNU Public License, version 2. The random.cpp file contained the header: //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -// Filename: random.c +// Filename: random.cpp // // Purpose: Random utility procedures for BayeSys3. // -// History: Random.c 17 Nov 1994 - 13 Sep 2003 +// History: Random.cpp 17 Nov 1994 - 13 Sep 2003 // // Acknowledgments: // "Numerical Recipes", Press et al, for ideas @@ -50,28 +50,29 @@ contained the header: static uint32_t lowindex = 0; -void mcell_ran4_init(uint32_t low) { +extern "C" void mcell_ran4_init(uint32_t low) { lowindex = low; } -double mcell_ran4(uint32_t *high, double *x, unsigned int n, double range) { +extern "C" double mcell_ran4(uint32_t *high, double *x, unsigned int n, double range) { int i; for (i=0;i #endif +#if defined(__cplusplus) +extern "C" { +#endif + extern void mcell_ran4_init(uint32_t); extern double mcell_ran4(uint32_t *idx1, double *x, unsigned int n, double range); extern double mcell_ran4a(uint32_t* idx1); @@ -13,6 +17,10 @@ extern uint32_t mcell_iran4(uint32_t* idx1); extern double nrnRan4dbl(uint32_t* idx1, uint32_t idx2); extern uint32_t nrnRan4int(uint32_t* idx1, uint32_t idx2); +#if defined(__cplusplus) +} +#endif + #endif /* diff --git a/src/oc/modlreg.c b/src/oc/modlreg.c deleted file mode 100755 index f7dd699aee..0000000000 --- a/src/oc/modlreg.c +++ /dev/null @@ -1,3 +0,0 @@ -#include <../../nrnconf.h> -void modl_reg(void){} /* dummy modl registration: see hocusr.c */ - diff --git a/src/oc/modlreg.cpp b/src/oc/modlreg.cpp new file mode 100755 index 0000000000..64e8db215f --- /dev/null +++ b/src/oc/modlreg.cpp @@ -0,0 +1,12 @@ +#include <../../nrnconf.h> + +#if defined(__cplusplus) +extern "C" { +#endif + +void modl_reg(void) {} /* dummy modl registration: see hocusr.cpp */ + +#if defined(__cplusplus) +} +#endif + diff --git a/src/oc/mswinprt.c b/src/oc/mswinprt.cpp similarity index 97% rename from src/oc/mswinprt.c rename to src/oc/mswinprt.cpp index 8989f062a5..59f3215612 100755 --- a/src/oc/mswinprt.c +++ b/src/oc/mswinprt.cpp @@ -13,9 +13,11 @@ #include #include #include "hoc.h" -#include "../mswin/extra/d2upath.c" +#include "../mswin/extra/d2upath.cpp" #include "gui-redirect.h" + + extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); extern double (*nrnpy_object_to_double_)(Object*); @@ -55,7 +57,7 @@ void setneuronhome(p) char* p; { // printf("setneuronhome |%s|\n", buf); for (j=strlen(buf); j >= 0 && buf[j] != '\\'; --j) {;} buf[j] = '\0'; // /bin gone - neuron_home_dos = emalloc(strlen(buf) + 1); + neuron_home_dos = static_cast(emalloc(strlen(buf) + 1)); strcpy(neuron_home_dos, buf); neuron_home = hoc_dos2unixpath(buf); return; @@ -92,7 +94,7 @@ void setneuronhome(p) char* p; { }else{ printf("\n"); } - s = emalloc(strlen(buf1)+1); + s = static_cast(emalloc(strlen(buf1)+1)); strcpy(s, buf1); i = putenv(s); // arg must be global // printf("putenv of %s returned %d\n", s, i); @@ -260,7 +262,7 @@ char* dos_neuronhome() { char* nrnhome, *cp; if (!dnrnhome) { nrnhome = getenv("NEURONHOME"); - dnrnhome = (char*)emalloc(strlen(nrnhome) + 1); + dnrnhome = static_cast(emalloc(strlen(nrnhome) + 1)); strcpy(dnrnhome, nrnhome); for (cp = dnrnhome; *cp; ++cp) { if (*cp == '/') { @@ -378,13 +380,6 @@ void hoc_Lw(){ret(); pushx(0.);} //plt(int mode, double x, double y) {} -#if 0 -hoc_menu_cleanup() { -#if OCSMALL - ShowWindow(hCurrWnd, SW_SHOW); -#endif -} -#endif //initplot() {} #if 0 diff --git a/src/oc/nocable.c b/src/oc/nocable.cpp similarity index 96% rename from src/oc/nocable.c rename to src/oc/nocable.cpp index c00c1956fe..12bc31e0a7 100755 --- a/src/oc/nocable.c +++ b/src/oc/nocable.cpp @@ -8,6 +8,8 @@ void nrn_fixed_step(void){} void nrn_fake_step(void) {} #endif + + int stoprun; void clear_sectionlist(void) {} void add_section(void) {} @@ -59,10 +61,12 @@ char *nrn_branch_name; char *nrn_tree_version; char *nrn_version_changeset; char *nrn_version_date; -double* nrn_recalc_ptr(double* pd) { return pd; } +extern "C" double* nrn_recalc_ptr(double* pd) { return pd; } void nrn_hoc_lock(void) {} void nrn_hoc_unlock(void) {} + + #include "nrnmpiuse.h" #if NRN_MUSIC void nrnmusic_init(int* parg, char*** pargv){} diff --git a/src/oc/nonlin.c b/src/oc/nonlin.cpp similarity index 99% rename from src/oc/nonlin.c rename to src/oc/nonlin.cpp index 8b7789185a..e091e420b9 100755 --- a/src/oc/nonlin.c +++ b/src/oc/nonlin.cpp @@ -8,9 +8,14 @@ #include "lineq.h" #include "code.h" + + + int do_equation; /* switch for determining access to dep vars */ int *hoc_access; /* links to next accessed variables */ int var_access; /* variable number as pointer into access array */ + + static double **varble; /* pointer to symbol values */ typedef struct elm *Elm; @@ -305,7 +310,7 @@ void solve(void) struct elm *el2; for (el = rowst[i]; el != (struct elm *)0; el = el2) { el2 = el->c_right; - free((char*)el); + free(el); } rowst[i] = colst[i] = (struct elm *)0; } @@ -315,3 +320,4 @@ void solve(void) ret(); pushx(sum); } + diff --git a/src/oc/nrn_vsscanf.c b/src/oc/nrn_vsscanf.cpp similarity index 99% rename from src/oc/nrn_vsscanf.c rename to src/oc/nrn_vsscanf.cpp index 022f9b7fb5..65dfaf28bc 100644 --- a/src/oc/nrn_vsscanf.c +++ b/src/oc/nrn_vsscanf.cpp @@ -1,5 +1,5 @@ /* modified for use for NrnFILEWrap */ -/* now included by nrnfilewrap.c */ +/* now included by nrnfilewrap.cpp */ /* * libslack - http://libslack.org/ * diff --git a/src/oc/nrnassrt.h b/src/oc/nrnassrt.h index d6e3db842f..237913b045 100644 --- a/src/oc/nrnassrt.h +++ b/src/oc/nrnassrt.h @@ -14,7 +14,9 @@ has side effects which need to be executed regardles of NDEBUG. #if defined(__cplusplus) extern "C" { #endif + extern void hoc_execerror(const char*, const char*); + #if defined(__cplusplus) } #endif diff --git a/src/oc/nrnfilewrap.c b/src/oc/nrnfilewrap.cpp similarity index 98% rename from src/oc/nrnfilewrap.c rename to src/oc/nrnfilewrap.cpp index f58238c64b..fc3a2ae41c 100644 --- a/src/oc/nrnfilewrap.c +++ b/src/oc/nrnfilewrap.cpp @@ -194,7 +194,7 @@ NrnFILEWrap* nrn_fw_read(const char* path, const char* mode){ } } if (isz > 0) { - nrnmpi_char_broadcast((char*)buf, isz, 0); + nrnmpi_char_broadcast(buf, isz, 0); } } if (isz >= 0) { @@ -206,6 +206,6 @@ NrnFILEWrap* nrn_fw_read(const char* path, const char* mode){ return fw; } -#include "nrn_vsscanf.c" +#include "nrn_vsscanf.cpp" #endif /* USE_NRNFILEWRAP */ diff --git a/src/oc/nrnfilewrap.h b/src/oc/nrnfilewrap.h index 345d25e588..023d814dae 100644 --- a/src/oc/nrnfilewrap.h +++ b/src/oc/nrnfilewrap.h @@ -10,9 +10,6 @@ #define USE_NRNFILEWRAP 0 #endif -#if defined(__cplusplus) -extern "C" { -#endif #include "hocstr.h" @@ -56,8 +53,5 @@ extern char* fgets_unlimited(HocStr* s, NrnFILEWrap* f); extern NrnFILEWrap* hoc_fin; -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/oc/nrnisaac.c b/src/oc/nrnisaac.cpp similarity index 100% rename from src/oc/nrnisaac.c rename to src/oc/nrnisaac.cpp diff --git a/src/oc/nrnisaac.h b/src/oc/nrnisaac.h index 0535cdf651..caaa7f07fe 100644 --- a/src/oc/nrnisaac.h +++ b/src/oc/nrnisaac.h @@ -1,14 +1,11 @@ #ifndef nrnisaac_h #define nrnisaac_h -#include "nrnconf.h" +#include <../../nrnconf.h> #if defined(HAVE_STDINT_H) #include #endif -#if defined(__cplusplus) -extern "C" { -#endif void* nrnisaac_new(void); void nrnisaac_delete(void* rng); @@ -16,8 +13,5 @@ void nrnisaac_init(void* rng, unsigned long int seed); double nrnisaac_dbl_pick(void* rng); uint32_t nrnisaac_uint32_pick(void* rng); -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/oc/nrnjava.h b/src/oc/nrnjava.h index a14af6a160..c5a12bac15 100644 --- a/src/oc/nrnjava.h +++ b/src/oc/nrnjava.h @@ -1,9 +1,6 @@ #ifndef nrnjava_h #define nrnjava_h -#if defined(__cplusplus) -#extern "C" { -#endif extern void* (*p_java2nrn_cons)(Object*); extern void (*p_java2nrn_destruct)(void* opaque_java_object); @@ -14,8 +11,5 @@ extern const char* (*p_java2nrn_classname)(Object* ho); extern Symbol* java2nrn_class(const char* classname, int classindex, const char* methods); extern int (*p_hoc_load_java)(void); -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/oc/nrnmpi.h b/src/oc/nrnmpi.h index 23a6cb0889..85da5d1e98 100755 --- a/src/oc/nrnmpi.h +++ b/src/oc/nrnmpi.h @@ -21,16 +21,10 @@ typedef struct { #if NRNMPI -#if defined(__cplusplus) -extern "C" { -#endif extern int nrnmpi_use; /* NEURON does MPI init and terminate?*/ extern int nrn_cannot_use_threads_and_mpi; /* 0 if required <= provided from MPI_Init_thread */ -#if defined(__cplusplus) -} -#endif /*c++*/ #include "nrnmpidec.h" diff --git a/src/oc/nrnmpi_dynam.c b/src/oc/nrnmpi_dynam.c deleted file mode 100644 index 4fe45c5bf4..0000000000 --- a/src/oc/nrnmpi_dynam.c +++ /dev/null @@ -1 +0,0 @@ -#include "../nrnmpi/nrnmpi_dynam.c" diff --git a/src/oc/nrnmpi_dynam.cpp b/src/oc/nrnmpi_dynam.cpp new file mode 100644 index 0000000000..ba5014fb36 --- /dev/null +++ b/src/oc/nrnmpi_dynam.cpp @@ -0,0 +1 @@ +#include "../nrnmpi/nrnmpi_dynam.cpp" diff --git a/src/oc/nrnmpi_dynam_stubs.c b/src/oc/nrnmpi_dynam_stubs.c deleted file mode 100644 index 39cc7510ed..0000000000 --- a/src/oc/nrnmpi_dynam_stubs.c +++ /dev/null @@ -1 +0,0 @@ -#include "../nrnmpi/nrnmpi_dynam_stubs.c" diff --git a/src/oc/nrnmpi_dynam_stubs.cpp b/src/oc/nrnmpi_dynam_stubs.cpp new file mode 100644 index 0000000000..72034f9e51 --- /dev/null +++ b/src/oc/nrnmpi_dynam_stubs.cpp @@ -0,0 +1 @@ +#include "../nrnmpi/nrnmpi_dynam_stubs.cpp" diff --git a/src/oc/nrnran123.c b/src/oc/nrnran123.cpp similarity index 75% rename from src/oc/nrnran123.c rename to src/oc/nrnran123.cpp index 3f86b0742b..31abb308ef 100644 --- a/src/oc/nrnran123.c +++ b/src/oc/nrnran123.cpp @@ -25,10 +25,10 @@ uint32_t nrnran123_get_globalindex() { return k.v[0]; } -nrnran123_State* nrnran123_newstream(uint32_t id1, uint32_t id2) { +extern "C" nrnran123_State* nrnran123_newstream(uint32_t id1, uint32_t id2) { return nrnran123_newstream3(id1, id2, 0); } -nrnran123_State* nrnran123_newstream3(uint32_t id1, uint32_t id2, uint32_t id3) { +extern "C" nrnran123_State* nrnran123_newstream3(uint32_t id1, uint32_t id2, uint32_t id3) { nrnran123_State* s; s = (nrnran123_State*)ecalloc(sizeof(nrnran123_State), 1); s->c.v[1] = id3; @@ -38,16 +38,16 @@ nrnran123_State* nrnran123_newstream3(uint32_t id1, uint32_t id2, uint32_t id3) return s; } -void nrnran123_deletestream(nrnran123_State* s) { +extern "C" void nrnran123_deletestream(nrnran123_State* s) { free(s); } -void nrnran123_getseq(nrnran123_State* s, uint32_t* seq, char* which) { +extern "C" void nrnran123_getseq(nrnran123_State* s, uint32_t* seq, char* which) { *seq = s->c.v[0]; *which = s->which_; } -void nrnran123_setseq(nrnran123_State* s, uint32_t seq, char which) { +extern "C" void nrnran123_setseq(nrnran123_State* s, uint32_t seq, char which) { if (which > 3 || which < 0) { s->which_ = 0; }else{ @@ -57,18 +57,18 @@ void nrnran123_setseq(nrnran123_State* s, uint32_t seq, char which) { s->r = philox4x32(s->c, k); } -void nrnran123_getids(nrnran123_State* s, uint32_t* id1, uint32_t* id2) { +extern "C" void nrnran123_getids(nrnran123_State* s, uint32_t* id1, uint32_t* id2) { *id1 = s->c.v[2]; *id2 = s->c.v[3]; } -void nrnran123_getids3(nrnran123_State* s, uint32_t* id1, uint32_t* id2, uint32_t* id3) { +extern "C" void nrnran123_getids3(nrnran123_State* s, uint32_t* id1, uint32_t* id2, uint32_t* id3) { *id3 = s->c.v[1]; *id1 = s->c.v[2]; *id2 = s->c.v[3]; } -uint32_t nrnran123_ipick(nrnran123_State* s) { +extern "C" uint32_t nrnran123_ipick(nrnran123_State* s) { uint32_t rval; char which = s->which_; assert (which < 4); @@ -82,11 +82,11 @@ uint32_t nrnran123_ipick(nrnran123_State* s) { return rval; } -double nrnran123_dblpick(nrnran123_State* s) { +extern "C" double nrnran123_dblpick(nrnran123_State* s) { return nrnran123_uint2dbl(nrnran123_ipick(s)); } -double nrnran123_negexp(nrnran123_State* s) { +extern "C" double nrnran123_negexp(nrnran123_State* s) { /* min 2.3283064e-10 to max 22.18071 */ return -log(nrnran123_dblpick(s)); } diff --git a/src/oc/nrnran123.h b/src/oc/nrnran123.h index f986c8ab0f..326413f89b 100644 --- a/src/oc/nrnran123.h +++ b/src/oc/nrnran123.h @@ -25,9 +25,6 @@ of the full distribution available from #include -#if defined(__cplusplus) -extern "C" { -#endif typedef struct nrnran123_State nrnran123_State; @@ -41,6 +38,10 @@ extern void nrnran123_set_globalindex(uint32_t gix); extern uint32_t nrnran123_get_globalindex(); /* minimal data stream */ +#if defined(__cplusplus) +extern "C" { +#endif + extern nrnran123_State* nrnran123_newstream(uint32_t id1, uint32_t id2); extern nrnran123_State* nrnran123_newstream3(uint32_t id1, uint32_t id2 , uint32_t id3); extern void nrnran123_deletestream(nrnran123_State*); @@ -48,11 +49,16 @@ extern void nrnran123_getseq(nrnran123_State*, uint32_t* seq, char* which); extern void nrnran123_setseq(nrnran123_State*, uint32_t seq, char which); extern void nrnran123_getids(nrnran123_State*, uint32_t* id1, uint32_t* id2); extern void nrnran123_getids3(nrnran123_State*, uint32_t* id1, uint32_t* id2, uint32_t* id3); + +extern double nrnran123_negexp(nrnran123_State*); /* mean 1.0 */ extern uint32_t nrnran123_ipick(nrnran123_State*); /* uniform 0 to 2^32-1 */ extern double nrnran123_dblpick(nrnran123_State*); /* uniform open interval (0,1)*/ - /* nrnran123_dblpick minimum value is 2.3283064e-10 and max value is 1-min */ -extern double nrnran123_negexp(nrnran123_State*); /* mean 1.0 */ - /* nrnran123_negexp min value is 2.3283064e-10, max is 22.18071 */ +/* nrnran123_dblpick minimum value is 2.3283064e-10 and max value is 1-min */ + +/* nrnran123_negexp min value is 2.3283064e-10, max is 22.18071 */ +#if defined(__cplusplus) +} +#endif extern double nrnran123_normal(nrnran123_State*); /* mean 0.0, std 1.0 */ /* more fundamental (stateless) (though the global index is still used) */ @@ -60,8 +66,5 @@ extern nrnran123_array4x32 nrnran123_iran(uint32_t seq, uint32_t id1, uint32_t i extern nrnran123_array4x32 nrnran123_iran3(uint32_t seq, uint32_t id1, uint32_t id2, uint32_t id3); extern double nrnran123_uint2dbl(uint32_t); -#if defined(__cplusplus) -} -#endif #endif diff --git a/src/oc/nrnrt.h b/src/oc/nrnrt.h index b73e583869..c3e80ce375 100755 --- a/src/oc/nrnrt.h +++ b/src/oc/nrnrt.h @@ -3,9 +3,6 @@ #include "nrnrtuse.h" #if NRN_REALTIME -#if defined(__cplusplus) -extern "C" { -#endif void nrn_setscheduler(); void nrn_maintask_init(); @@ -17,9 +14,6 @@ extern int nrn_realtime_; extern double nrn_rtstep_time_; extern int nrnrt_overrun_; -#if defined(__cplusplus) -} -#endif /*c++*/ #endif /* NRN_REALTIME */ #if NRN_6229 diff --git a/src/oc/oc_ansi.h b/src/oc/oc_ansi.h index 6741a255f5..4e761bc0b4 100644 --- a/src/oc/oc_ansi.h +++ b/src/oc/oc_ansi.h @@ -1,6 +1,8 @@ #ifndef oc_ansi_h #define oc_ansi_h +#include + /** * \dir @@ -20,12 +22,55 @@ * @{ */ + +#if defined(__cplusplus) +//#include "ivocvect.h" +class IvocVect; +#else +#define IvocVect void +#endif + #if defined(__cplusplus) extern "C" { +#endif + + // nocpout.cpp +extern void hoc_register_var(DoubScal*, DoubVec*, VoidFunc*); +extern void ivoc_help(const char*); + +extern Symbol* hoc_lookup(const char*); + +extern void* hoc_Ecalloc(size_t nmemb, size_t size); +extern void* hoc_Emalloc(size_t size); +extern void hoc_malchk(void); + +extern void hoc_execerror(const char*, const char*); +extern char* hoc_object_name(Object*); +extern void hoc_retpushx(double); + +extern double* getarg(int); +extern int ifarg(int); + +extern int vector_instance_px(void*, double**); +extern void install_vector_method(const char*, double(*)(void*)); + +extern IvocVect* vector_arg(int); +extern int vector_arg_px(int i, double** p); +extern double* vector_vec(IvocVect*); +extern int vector_capacity(IvocVect*); +extern void vector_resize(IvocVect*, int); + +#if defined(__cplusplus) +} #endif extern int nrnignore; +#if defined(__cplusplus) +extern "C" { +#endif + + /** * \brief Brief explanation of hoc_obj_run * @@ -40,11 +85,11 @@ extern int hoc_is_str_arg(int); extern int hoc_is_object_arg(int); extern char* gargstr(int); extern char** hoc_pgargstr(int); -extern double* getarg(int); + extern double* hoc_pgetarg(int); extern Object** hoc_objgetarg(int); extern Object* hoc_name2obj(const char* name, int index); -extern int ifarg(int); + extern char** hoc_temp_charptr(void); extern int hoc_is_temp_charptr(char** cpp); extern void hoc_assign_str(char** pstr, const char* buf); @@ -54,13 +99,13 @@ extern double hoc_call_objfunc(Symbol*, int narg, Object*); /* call a fuction wi extern double hoc_ac_; extern double hoc_epsilon; extern int nrn_inpython_; -extern int stoprun; + extern int hoc_color; extern int hoc_set_color(int); extern void hoc_plt(int, double, double); extern void hoc_plprint(const char*); extern void hoc_ret(void); /* but need to push before returning */ -extern void hoc_retpushx(double); + extern void hoc_pushx(double); extern void hoc_pushstr(char**); extern void hoc_pushobj(Object**); @@ -76,11 +121,10 @@ extern Object* hoc_pop_object(void); extern char** hoc_strpop(void); extern int hoc_ipop(void); extern void hoc_nopop(void); -extern void hoc_execerror(const char*, const char*); + extern void hoc_execerror_mes(const char*, const char*, int); extern void hoc_warning(const char*, const char*); extern double* hoc_val_pointer(const char*); -extern Symbol* hoc_lookup(const char*); extern Symbol* hoc_table_lookup(const char*, Symlist*); extern Symbol* hoc_install(const char*, int, double, Symlist**); extern Objectdata* hoc_objectdata; @@ -90,7 +134,7 @@ extern int hoc_obj_look_inside_stack_index(int); extern void hoc_stkobj_unref(Object*, int stkindex); extern size_t hoc_total_array_data(Symbol*, Objectdata*); extern char* hoc_araystr(Symbol*, int, Objectdata*); -extern char* hoc_object_name(Object*); + extern char* hoc_object_pathname(Object*); extern const char* expand_env_var(const char*); extern void check_obj_type(Object*, const char*); @@ -107,13 +151,11 @@ extern Object* hoc_obj_get(int i); extern void hoc_obj_set(int i, Object*); extern void nrn_hoc_lock(void); extern void nrn_hoc_unlock(void); -extern void* hoc_Emalloc(size_t size); -extern void* hoc_Ecalloc(size_t nmemb, size_t size); + extern void* hoc_Erealloc(void* ptr, size_t size); -extern void hoc_malchk(void); + extern void* nrn_cacheline_alloc(void** memptr, size_t size); extern void* nrn_cacheline_calloc(void** memptr, size_t nmemb, size_t size); -extern char* cxx_char_alloc(size_t size); extern void nrn_exit(int); extern void hoc_free_list(Symlist**); extern int hoc_errno_check(void); @@ -127,9 +169,7 @@ extern int hoc_xopen_run(Symbol*, const char*); extern void hoc_symbol_limits(Symbol*, float, float); extern void sym_extra_alloc(Symbol*); extern int hoc_chdir(const char* path); -extern void hoc_register_var(DoubScal*, DoubVec*, VoidFunc*); -extern int nrn_isdouble(void*, double, double); -extern int hoc_main1(int, const char**, const char**); + extern void hoc_final_exit(); extern void hoc_sprint1(char**, int); extern double hoc_scan(FILE*); @@ -145,28 +185,19 @@ extern void* hoc_pysec_name2ptr(const char* s, int eflag); extern void* nrn_parsing_pysec_; extern int _nrnunit_use_legacy_; /* 1:legacy, 0:modern (default) */ -#if defined(__cplusplus) -class IvocVect; -#else -#define IvocVect void -#endif extern void vector_append(IvocVect*, double); -extern int vector_arg_px(int, double**); -extern int vector_instance_px(void*, double**); -extern void install_vector_method(const char*, double(*)(void*)); extern IvocVect* vector_new(int, Object*); /*use this if possible*/ extern IvocVect* vector_new0(); extern IvocVect* vector_new1(int); extern IvocVect* vector_new2(IvocVect*); extern void vector_delete(IvocVect*); extern int vector_buffer_size(IvocVect*); -extern int vector_capacity(IvocVect*); -extern void vector_resize(IvocVect*, int); + extern Object** vector_temp_objvar(IvocVect*); -extern double* vector_vec(IvocVect*); extern Object** vector_pobj(IvocVect*); -extern IvocVect* vector_arg(int); + extern int is_vector_arg(int); + extern char* vector_get_label(IvocVect*); extern void vector_set_label(IvocVect*, char*); @@ -204,7 +235,6 @@ extern void hoc_edit_quit(void); extern size_t hoc_pipegets_need(void); extern void ivoc_cleanup(void); extern void ivoc_final_exit(void); -extern void ivoc_help(const char*); extern int hoc_oc(const char*); extern void hoc_pipeflush(void); extern void hoc_initcode(void); @@ -244,18 +274,23 @@ extern int nrnpy_pr(const char* fmt, ...); extern int Fprintf(FILE*, const char* fmt, ...); extern void nrnpy_pass(); -#if defined (__cplusplus) +//#if defined (__cplusplus) extern void hoc_free_allobjects(cTemplate*, Symlist*, Objectdata*); -#else -extern void hoc_free_allobjects(Template*, Symlist*, Objectdata*); -#endif +//#else +//extern void hoc_free_allobjects(cTemplate*, Symlist*, Objectdata*); +//#endif extern int nrn_is_cable(void); +extern int nrn_isdouble(double*, double, double); #if defined(__cplusplus) } #endif +extern int hoc_main1(int, const char**, const char**); +extern char* cxx_char_alloc(size_t size); +extern int stoprun; + #endif /** @} */ // end of hoc_functions diff --git a/src/oc/ocerf.c b/src/oc/ocerf.cpp similarity index 95% rename from src/oc/ocerf.c rename to src/oc/ocerf.cpp index f857f6c8d8..75c7785bfa 100755 --- a/src/oc/ocerf.c +++ b/src/oc/ocerf.cpp @@ -4,7 +4,7 @@ #if DOS || defined(__GO32__) || defined(WIN32) /*|| defined(MAC)*/ /****************************************************************************** * - * File: erf.c + * File: erf.cpp * * Copyright (c) 1988, 1989, 1990 * Duke University @@ -13,7 +13,7 @@ #ifndef LINT static char RCSid[] = - "erf.c,v 1.5 1997/11/24 16:21:37 hines Exp" ; + "erf.cpp,v 1.5 1997/11/24 16:21:37 hines Exp" ; #endif /************************************************************ diff --git a/src/oc/ocfunc.h b/src/oc/ocfunc.h index 77220fc847..82495d3f96 100644 --- a/src/oc/ocfunc.h +++ b/src/oc/ocfunc.h @@ -1,9 +1,6 @@ #ifndef ocfunc_h #define ocfunc_h -#if defined(__cplusplus) -extern "C" { -#endif extern double hoc_Log(double), hoc_Log10(double), hoc1_Exp(double), hoc_Sqrt(double), hoc_integer(double); extern double hoc_Pow(double, double); @@ -11,7 +8,7 @@ extern void hoc_System(void), hoc_Prmat(void), hoc_solve(void), hoc_eqinit(void) extern void hoc_symbols(void), hoc_PRintf(void), hoc_Xred(void), hoc_Sred(void); extern void hoc_ropen(void), hoc_wopen(void), hoc_xopen(void), hoc_Fscan(void), hoc_Fprint(void); extern void hoc_Graph(void), hoc_Graphmode(void), hoc_Plot(void), hoc_axis(void), hoc_Sprint(void); -extern void hoc_fmenu(void), hoc_Getstr(void), hoc_Strcmp(void); +extern void hoc_fmenu(void), hoc_Getstr(void), hoc_Strcmp(void); extern void hoc_Lw(void), hoc_machine_name(void), hoc_Saveaudit(void), hoc_Retrieveaudit(void); extern void hoc_plotx(void), hoc_ploty(void), hoc_regraph(void); extern void hoc_startsw(void), hoc_stopsw(void), hoc_object_id(void); @@ -45,9 +42,7 @@ extern void hoc_settext(void); #if defined(WIN32) extern void hoc_win_exec(); #endif -#if defined(__cplusplus) -} -#endif + #endif diff --git a/src/oc/ockludge.c b/src/oc/ockludge.cpp similarity index 100% rename from src/oc/ockludge.c rename to src/oc/ockludge.cpp diff --git a/src/oc/ocmain.c b/src/oc/ocmain.cpp similarity index 95% rename from src/oc/ocmain.c rename to src/oc/ocmain.cpp index f90be21089..9f925898ea 100755 --- a/src/oc/ocmain.c +++ b/src/oc/ocmain.cpp @@ -1,5 +1,5 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/ocmain.c,v 1.7 1997/07/29 20:23:33 hines Exp */ +/* /local/src/master/nrn/src/oc/ocmain.cpp,v 1.7 1997/07/29 20:23:33 hines Exp */ #include #include @@ -60,7 +60,7 @@ real_main(int argc, const char** argv, const char**envp) { int main(int argc, const char** argv, const char** envp) { #endif int err; - nrn_isdouble((void*)0, 0., 0.); + nrn_isdouble(nullptr, 0., 0.); #if MAC int our_argc = 1; char *our_argv[1]; diff --git a/src/oc/ocmisc.h b/src/oc/ocmisc.h index 91d6e1497f..6881314b85 100644 --- a/src/oc/ocmisc.h +++ b/src/oc/ocmisc.h @@ -1,6 +1,7 @@ #ifndef ocmisc_h #define ocmisc_h + extern long hoc_nstack; extern long hoc_nframe; extern int hoc_errno_count; @@ -8,4 +9,6 @@ extern int hoc_pipeflag; extern int hoc_in_yyparse; extern int hoc_intset; + + #endif diff --git a/src/oc/ocnoiv.c b/src/oc/ocnoiv.cpp similarity index 88% rename from src/oc/ocnoiv.c rename to src/oc/ocnoiv.cpp index 094170286b..2f5cdbf3f9 100755 --- a/src/oc/ocnoiv.c +++ b/src/oc/ocnoiv.cpp @@ -2,6 +2,7 @@ #include "hoc.h" #include "ocfunc.h" + /*ARGSUSED*/ void notify_freed(void* p) { } @@ -78,30 +79,30 @@ void hoc_template_notify(Object* ob, int create) {} int hoc_readcheckpoint(char* f) { return 0; } /*ARGSUSED*/ -int vector_arg_px(int i, double** p) { +extern "C" int vector_arg_px(int i, double** p) { hoc_execerror("implemented in ivoc library", "vector_arg_px"); return 0; } int vector_capacity(void* v) {return 0;} -void install_vector_method(const char* name, Pfrd_vp f) {} -int vector_instance_px(void* vv, double** px){return 0;} +extern "C" void install_vector_method(const char* name, Pfrd_vp f) {} +extern "C" int vector_instance_px(void* vv, double** px){return 0;} void vector_resize(v, n) void* v; int n; { hoc_execerror("implemented in ivoc library", "vector_resize"); } void vector_append(void* vv, double x) {} void vector_delete(void* v) {} -void* vector_arg(int i) { return (void*)0;} -void* vector_new2(void* v) { return (void*)0;} +void* vector_arg(int i) { return nullptr;} +void* vector_new2(void* v) { return nullptr;} Object** vector_pobj(void* v) { return (Object**)0;} double* vector_vec(void* v) { hoc_execerror("implemented in ivoc library", "vector_vec"); return (double*)0; } -Object* ivoc_list_item(Object* list, int item) { +extern "C" Object* ivoc_list_item(Object* list, int item) { hoc_execerror("implemented in ivoc library", "ivoc_list_item"); - return (Object*)0; + return nullptr; } int ivoc_list_count(list) Object* list; { return 0; } void bbs_done(void){} @@ -116,4 +117,4 @@ int stdin_event_ready(void) {} void nrnbbs_context_wait(void) {} void ivoc_final_exit(void) {} -char* cxx_char_alloc(size_t len) { return (char*)hoc_Emalloc(len); } +char* cxx_char_alloc(size_t len) { return hoc_Emalloc(len); } diff --git a/src/oc/parallel.c b/src/oc/parallel.cpp similarity index 52% rename from src/oc/parallel.c rename to src/oc/parallel.cpp index 027554baca..ecfa6d867e 100755 --- a/src/oc/parallel.c +++ b/src/oc/parallel.cpp @@ -1,5 +1,5 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/parallel.c,v 1.5 1997/03/13 14:18:17 hines Exp */ +/* /local/src/master/nrn/src/oc/parallel.cpp,v 1.5 1997/03/13 14:18:17 hines Exp */ #if MAC #define OCSMALL 1 #define WIN32 1 @@ -28,133 +28,136 @@ static int sargv=0, senvp=0; #endif /*!OCSMALL*/ int parallel_sub=0; -int parallel_val; /* for use with parallel neuron (see hoc.c) */ +int parallel_val; /* for use with parallel neuron (see hoc.cpp) */ /* stack has final, initial, symbol and should contain these on exit in order to execute the following shortfor */ + + void hoc_parallel_begin(void) { #if !OCSMALL - Symbol *sym; - double first, last; - char *method, *getenv(); - int parallel_hoc_main(); - int i, j; - - - last = xpop(); - first = xpop(); - sym = spop(); - pushs(sym); - - method = getenv("NEURON_PARALLEL_METHOD"); - if (!method) { - pushx(first); - pushx(last); - return; - } - if (parallel_seen++) { - hoc_warning("Only one parallel loop per batch run allowed.", - "This loop is being executed serially"); - pushx(first); - pushx(last); - return; - } - - if (!parallel_sub) { /* if 0 then master */ - /* the master instance executes the following portion of the loop */ - for (i = ((int)first)+1; i <= (int)last; i++) { - char buf[10], *pnt = parallel_argv; - - /* increment pnt to "00000" */ - for (j = 0; j < 2; j++) { - /*EMPTY*/ - while (*pnt++); - } - - /* replace "00000" with actual value */ - sprintf(buf, "%5d", i); - strcpy(pnt, buf); - - /* farm-out all but the first instance of the loop */ + Symbol *sym; + double first, last; + char *method; //, *getenv(); +// int parallel_hoc_main(); + int i, j; + + + last = xpop(); + first = xpop(); + sym = spop(); + pushs(sym); + + method = getenv("NEURON_PARALLEL_METHOD"); + if (!method) { + pushx(first); + pushx(last); + return; + } + if (parallel_seen++) { + hoc_warning("Only one parallel loop per batch run allowed.", + "This loop is being executed serially"); + pushx(first); + pushx(last); + return; + } + + if (!parallel_sub) { /* if 0 then master */ + /* the master instance executes the following portion of the loop */ + for (i = ((int) first) + 1; i <= (int) last; i++) { + char buf[10], *pnt = parallel_argv; + + /* increment pnt to "00000" */ + for (j = 0; j < 2; j++) { + /*EMPTY*/ + while (*pnt++); + } + + /* replace "00000" with actual value */ + sprintf(buf, "%5d", i); + strcpy(pnt, buf); + + /* farm-out all but the first instance of the loop */ #if LINDA - /* place arguments for eval() into tuple space, Linda - doesn't seem to want to let the fxn in an eval take - arrays as args */ - __linda_out("parallel sargs", sargv, senvp); - __linda_out("parallel args", parallel_argv:sargv, parallel_envp:senvp); - __linda_eval("parallel run", parallel_hoc_main(i), i); + /* place arguments for eval() into tuple space, Linda + doesn't seem to want to let the fxn in an eval take + arrays as args */ + __linda_out("parallel sargs", sargv, senvp); + __linda_out("parallel args", parallel_argv:sargv, parallel_envp:senvp); + __linda_eval("parallel run", parallel_hoc_main(i), i); #endif - } - + } + #if LINDA - /* do first pass though loop on master node (first to first) */ - pushx(first); - pushx(first); + /* do first pass though loop on master node (first to first) */ + pushx(first); + pushx(first); #else - /* run in serial if not LINDA */ - pushx(first); - pushx(last); + /* run in serial if not LINDA */ + pushx(first); + pushx(last); #endif - /* block until all instances of loop have finished */ + /* block until all instances of loop have finished */ #if LINDA - i = (int)last - (int)first; - while (i-- > 0) { - int err_val, err_num; - - __linda_in("parallel run", ?err_val, ?err_num); - /* could test err_val != 0 but currently will always equal 0 */ - } + i = (int)last - (int)first; + while (i-- > 0) { + int err_val, err_num; + + __linda_in("parallel run", ?err_val, ?err_num); + /* could test err_val != 0 but currently will always equal 0 */ + } #endif - /* assign value of symbol to last+1 as would be upon exiting a serial loop */ - if (!ISARRAY(sym)) { - if (sym->subtype == USERDOUBLE) { - pval = sym->u.pval; - } else { - pval = OPVAL(sym); - } - } else { - if (sym->subtype == USERDOUBLE) { - pval = sym->u.pval + araypt(sym, SYMBOL); - } else { - pval = OPVAL(sym) + araypt(sym, OBJECTVAR); - } - } - end_val = last + 1; + /* assign value of symbol to last+1 as would be upon exiting a serial loop */ + if (!ISARRAY(sym)) { + if (sym->subtype == USERDOUBLE) { + pval = sym->u.pval; + } else { + pval = OPVAL(sym); + } + } else { + if (sym->subtype == USERDOUBLE) { + pval = sym->u.pval + araypt(sym, SYMBOL); + } else { + pval = OPVAL(sym) + araypt(sym, OBJECTVAR); + } + } + end_val = last + 1; - } else { - /* the subsidiary instances do remaining contiguous blocks of the loop */ + } else { + /* the subsidiary instances do remaining contiguous blocks of the loop */ - /* only do "parallel_val" pass though loop */ - pushx((double)parallel_val); - pushx((double)parallel_val); + /* only do "parallel_val" pass though loop */ + pushx((double) parallel_val); + pushx((double) parallel_val); - } + } #endif } void hoc_parallel_end(void) { #if !OCSMALL - /* need to exit after for-loop for all sub-processes */ - if (parallel_sub) { - hoc_final_exit(); + /* need to exit after for-loop for all sub-processes */ + if (parallel_sub) { + hoc_final_exit(); #if LINDA - lexit(0); + lexit(0); #else - exit(0); + exit(0); #endif - } else { - /* assign loop counter the proper end value */ - *pval = end_val; - } + } else { + /* assign loop counter the proper end value */ + *pval = end_val; + } #endif } + int parallel_hoc_main(int i) { #if !OCSMALL /*ARGSUSED*/ @@ -162,8 +165,8 @@ int parallel_hoc_main(int i) { const char* pnt; char *targv, *tenvp; int j, _largc; - _largv = emalloc(NUM_ARGS*sizeof(char*)); - _lenvp = emalloc(NUM_ARGS*sizeof(char*)); + _largv = static_cast(emalloc(NUM_ARGS*sizeof(char*))); + _lenvp = static_cast(emalloc(NUM_ARGS*sizeof(char*))); #if LINDA char name[20]; @@ -172,8 +175,8 @@ int parallel_hoc_main(int i) { __linda_in("parallel sargs", ?sargv, ?senvp); #endif - targv = emalloc(sargv); - tenvp = emalloc(senvp); + targv = static_cast(emalloc(sargv)); + tenvp = static_cast(emalloc(senvp)); /* pointers need to point to memory that will be filled by __linda_in() */ #if LINDA __linda_in("parallel args", ?targv:, ?tenvp:); @@ -218,7 +221,7 @@ void save_parallel_argv(int argc, const char** argv) { sargv = (sargv + 1) * sizeof(char); /* malloc blocks of memory */ - parallel_argv = emalloc(sargv); + parallel_argv = static_cast(emalloc(sargv)); #if 0 /* place the strings into the memory block separated by '\0' */ @@ -268,7 +271,7 @@ void save_parallel_envp(void) { senvp = (senvp + 1) * sizeof(char); /* malloc blocks of memory */ - parallel_envp = emalloc(senvp); + parallel_envp = static_cast(emalloc(senvp)); /* place the strings into the memory block separated by '\0' */ pnt = parallel_envp; diff --git a/src/oc/plot.c b/src/oc/plot.c deleted file mode 100755 index d0d1e2ab5f..0000000000 --- a/src/oc/plot.c +++ /dev/null @@ -1,1205 +0,0 @@ -#include <../../nrnconf.h> -#include "hoc.h" - -/*LINTLIBRARY*/ -#undef IGNORE -#if LINT -#define IGNORE(arg) {if(arg);} -#else -#define IGNORE(arg) arg -#endif - -#if GRX -#include -#include "hoc.h" -#define __TURBOC__ -#endif - -#if defined(useNeXTstep) || defined(__TURBOC__) || defined(__linux__) -#ifndef NRNOC_X11 -#define NRNOC_X11 0 -#endif -#endif - -#define FIG 1 /* 12/8/88 add fig style output , replaces hpflag*/ -#define TEK 1 -#define HP 1 -/* but not VT125 */ -#define CODRAW 1 - -#if CODRAW -static void Codraw_plt(int, double, double); -static void Codraw_preamble(void); -#endif - -#if HP -static void hplot(int, double, double); -#endif - -#if FIG -static void Fig_preamble(void); -static void Fig_plt(int, double, double); -void Fig_file(const char*, int); -#endif - -#if TEK -static void tplot(int, double, double); -#endif - -#include -#include - -#if defined(__MINGW32__) -extern char** _environ; -#else /*!__MINGW32__*/ - -#if HAVE_UNISTD_H -#include -#if !defined(__APPLE__) -extern char** environ; -#else /* __APPLE */ -#include -#endif /* __APPLE__ */ -#endif /* HAVE_UNISTD_H */ - -#endif /*!__MINGW32__*/ - -#if DOS -#include -#include -#endif -#if defined(GRX) -#define DOS 1 -#endif - -static int console = 1; /* 1 plotting to console graphics */ -static int hardplot; /* 1 hp style 2 fig style 3 coplot*/ -static int graphdev; -static int hpflag; /* hp plotter switch */ -int hoc_plttext; /* text can be printed to hpdev */ -#define text hoc_plttext -static FILE *gdev; /* system call stdout not directed to here */ -static FILE *hpdev; /* hp, or fig style file */ -static FILE *cdev; /* console device */ - -#define SSUN 1 -#define VT 2 -#define SEL 3 -#define TEK4014 4 -#define ADM 5 -#define NX 6 - -#define US 037 -#define GS 035 -#define CAN 030 -#define EM 031 -#define FS 034 -#define ESC 033 -#define ETX 03 - -static char vt100[] = "TERM=vt125"; -static char adm3a[] = "TERM=adm3a"; -static char ssun[] = "TERM=sun"; -static char tek4014[] = "TERM=4014"; -static char ncsa[] = "NEURON=ncsa"; -int hoc_color = 15; -static double xlast, ylast; - -#if NRNOC_X11 -extern void x11_put_text(const char*), x11_close_window(void), x11_setcolor(int); -extern void x11_coord(), x11_vector(), x11_point(), x11_move(), x11flush(); -extern void x11_clear(), x11_cleararea(), x11_open_window(), x11_fast(); -static void hoc_x11plot(int, double, double); -#endif - -#if NeXTstep -extern void NeXT_put_text(), NeXT_close_window(), NeXT_setcolor(); -extern void NeXT_coord(), NeXT_vector(), NeXT_point(), NeXT_move(), NeXTflush(); -extern void NeXT_clear(), NeXT_cleararea(), NeXT_open_window(), NeXT_fast(); -#endif - -static void hard_text_preamble(); - -#if defined(__TURBOC__) -int egagrph = 0; /* global because need to erase on quit if in graphics - mode */ -static int graphmode = 0; -static double xres=640., yres=350.; -static tplt(); - -void *_graphgetmem(unsigned size) { - char *p; - p= hoc_Emalloc(size), hoc_malchk() ; - return p; -} - -static void Initplot(void) { -#if !defined(__GO32__) - registerfarbgidriver(EGAVGA_driver_far); - registerfarbgidriver(CGA_driver_far); - registerfarbgidriver(Herc_driver_far); - registerfarbgifont(triplex_font_far); -#endif - - graphdev = DETECT; - initgraph(&graphdev, &graphmode,"c:\\bc\\bgi"); - {int err; - graphdev=1; - err = graphresult(); - if (err != grOk) { -hoc_execerror("Error in initializing graphics adaptor\n", (char *)0); - } - xres = (double)(getmaxx()+1); - yres = (double)(getmaxy()+1); - grx_txt_clear(); - return; - } - if (graphdev > 0) { - xres = (double)(getmaxx()+1); - yres = (double)(getmaxy()+1); - restorecrtmode(); - } else { -hoc_execerror("Error in initializing graphics adaptor\n", (char *)0); - } -} -#endif - -void plprint(const char* s) -{ -#if DOS - extern int newstyle; - extern unsigned text_style, text_size, text_orient; -#endif - char buf[128]; - - if (text && s[strlen(s) - 1] == '\n') { - IGNORE(strcpy(buf, s)); - s = buf; - buf[strlen(s)-1] = '\0'; - } - - if (console && text) { -#if DOS - if (egagrph == 2) { - if (newstyle) { - settextstyle(text_style,text_orient,text_size); - newstyle = 0; - } - outtext(s); - }else{ - IGNORE(fprintf(cdev, "%s", s)); - } -#else -#if SUNCORE - hoc_pl_sunplot(s); -#else -#if NRNOC_X11 - x11_put_text(s); -#else -#if NeXTstep - if (graphdev == NX) - NeXT_put_text(s); -#else - - IGNORE(fprintf(cdev, "%s", s)); - IGNORE(fflush(cdev)); -#endif -#endif -#endif -#endif - - } else if (!text) { -#if GRX - if (egagrph) { - hoc_outtext(s); - }else -#endif - { -#if 0 - IGNORE(fprintf(stdout, "%s", s)); -#else - nrnpy_pr("%s", s); -#endif - } - } - if (hardplot && hpdev && text && strlen(s)) { - hard_text_preamble(); - IGNORE(fprintf(hpdev, "%s", s)); - IGNORE(fflush(hpdev)); - } - if (text && s == buf) { - plt(1, xlast, ylast-20); - plt(-2, 0.,0.); - } -} - -#if GRX -static int trcur; -static GrTextRegion* gtr; -#define GRXCOL 80 -#define GRXROW 5 -void grx_move(int r, int c){ - r = r%GRXROW; - c = c%GRXCOL; - trcur = c + r*GRXCOL; -} -void grx_rel_move(int new){ - trcur = ((int)(trcur/GRXCOL))*GRXCOL + new; -} -void grx_output_some_chars(const char* string, int count) { - if (string[count] == '\0') { - hoc_outtext(string); - }else{ - hoc_outtext("non-terminated string\n"); - } -} -void grx_delete_chars(int count) { - int i; - int j = trcur; - for (i=0; i < count; ++i) { - gtr->txr_buffer[j++] = ' '; - } - GrDumpTextRegion(gtr); -} -grx_insert_some_chars(string, count) char* string; int count; { - int i, j; - i = trcur + count; - j = trcur + count; - while(i >= trcur) { - gtr->txr_buffer[j--] = gtr->txr_buffer[i--]; - } - i = trcur; - grx_output_some_chars(string, count); - trcur = i; -} -grx_backspace(count) int count; { - while (count--) { - trcur--; - } -} -grx_clear_to_eol() { - int j = trcur; - do { - gtr->txr_buffer[j] = ' '; - }while ((++j)%GRXCOL); - GrDumpTextRegion(gtr); -} - -grx_force_text() { - int i; - for (i=0; i < GRXCOL*GRXROW; ++i) { - gtr->txr_backup[i] = '\0'; - } - GrDumpTextRegion(gtr); -} - -grx_txt_clear() { - int i; - if (!gtr) { - gtr = (GrTextRegion*)emalloc(sizeof(GrTextRegion)); - gtr->txr_font = (GrFont*)0; - gtr->txr_buffer = (char*)ecalloc(GRXCOL*GRXROW, sizeof(char)); - gtr->txr_backup = (char*)ecalloc(GRXCOL*GRXROW, sizeof(char)); - gtr->txr_xpos = 0; - gtr->txr_ypos = 0; - gtr->txr_width = GRXCOL; - gtr->txr_height = GRXROW; - gtr->txr_lineoffset = GRXCOL; - gtr->txr_fgcolor.v = 7; - gtr->txr_bgcolor.v = 0; - gtr->txr_chrtype = GR_BYTE_TEXT; - } - for (i=0; i < GRXCOL*GRXROW; ++i) { - gtr->txr_buffer[i] = ' '; - } - trcur = 0; - GrDumpTextRegion(gtr); -} - -hoc_outtext(s) char* s; { - int i; - char* cp; - int ch; - if (!egagrph) { - return; - } - if (! gtr) { - grx_txt_clear(); - } - - for (cp = s; *cp; ++cp) { - ch = *cp; - if (*cp == '\n' || trcur >= GRXROW*GRXCOL) { - char* c1, *c2; - int j; - for (i=1; i < GRXROW; ++i) { - c1 = gtr->txr_buffer + (i-1)*GRXCOL; - c2 = gtr->txr_buffer + (i)*GRXCOL; - for (j =0; j < GRXCOL; ++j) { - c1[j] = c2[j]; - } - } - for (i=0; i < GRXCOL; ++i) { - c2[i] = ' '; - } - trcur = (GRXROW-1)*GRXCOL; - continue; - } - if (ch == '\t') { - ch = ' '; - } - gtr->txr_buffer[trcur++] = ch; - } - GrDumpTextRegion(gtr); -} -#endif - -void initplot(void) -{ -#if !defined(__MINGW32__) /* to end of function */ - int i; -#if defined (__APPLE__) - char** environ=(*_NSGetEnviron()); -#endif -#if defined(__TURBOC__) - graphdev = 0; -#else -#if NeXTstep - graphdev = NX; -#else - graphdev = SSUN; - for (i = 0; environ[i] != NULL; i++) - { - if (strcmp(environ[i], vt100) == 0) - graphdev = VT; - if (strcmp(environ[i], ssun) == 0) - graphdev = SSUN; - if (strcmp(environ[i], adm3a) == 0) - graphdev = ADM; - if (strcmp(environ[i], tek4014) == 0) - graphdev = TEK4014; - if (strcmp(environ[i], ncsa) == 0) - graphdev = TEK4014; - } -#endif /*!NeXTstep*/ -#endif /*!__TURBOC__*/ - hpdev = (FILE *)0; - cdev = gdev = stdout; -#if SUNCORE - if (graphdev == SSUN) { - hoc_open_sunplot(environ); -#else -#if NeXTstep - /*EMPTY*/ - if (graphdev == SSUN) { -#else -#if NRNOC_X11 - /*EMPTY*/ - if (graphdev == SSUN) { -#else - if (graphdev == SSUN) { -/* - if (graphdev == SSUN &&(cdev = fopen("/dev/ttyp4", "w")) == (FILE *)0) { - IGNORE(fprintf(stderr, "Can't open /dev/ttyp4 for TEK\n")); - cdev = stdout; -*/ -#endif /*NRNOC_X11*/ -#endif /*NeXTstep*/ -#endif /*SUNCORE*/ - } else { - if (graphdev == TEK4014) { - cdev = gdev = stdout; - } - } -#endif /*!__MINGW32__*/ -} - -void hoc_close_plot(void) { -#if DOS - if (egagrph) plt(-3,0.,0.); -#else -#if SUNCORE - hoc_close_sunplot(); -#else -#if NRNOC_X11 - x11_close_window(); -#else -#if NeXTstep - NeXT_close_window(); -#endif -#endif -#endif -#endif -} - -void plt(int mode, double x, double y) -{ - if (x < 0.) x = 0.; - if (x > 1000.) x = 1000.; - if (y < 0.) y = 0.; - if (y > 780.) y = 780.; - if (mode >= 0) { - xlast = x; ylast = y; - } - if (console) { -#if defined(__TURBOC__) - if(graphdev > 0) { - tplt(mode, x, y); - } else if (graphdev == 0) { - Initplot(); - tplt(mode, x, y); - } -#else - switch (graphdev) - { - case SSUN: -#if SUNCORE - hoc_sunplot(&text, mode, x, y); - break; -#else -#if NRNOC_X11 - hoc_x11plot(mode,x,y); - break; -#else -#if NeXTstep - break; - case NX: - hoc_NeXTplot(mode,x,y); - break; -#endif -#endif -#endif -#if TEK - case ADM: - case SEL: - case TEK4014: - tplot(mode, x, y); - break; -#endif -#if VT125 - case VT: - vtplot(mode, x, y); - break; -#endif - } -#endif - } -#if HP - if (hardplot == 1) { - hplot(mode, x, y); - } -#endif -#if FIG - if (hardplot == 2) { - Fig_plt(mode, x, y); - } -#endif -#if CODRAW - if (hardplot == 3) { - Codraw_plt(mode, x, y); - } -#endif - if (hardplot && hpdev) { - IGNORE(fflush(hpdev)); - } - if (console && cdev) { - IGNORE(fflush(cdev)); - } -} - -#if TEK -#define XHOME 0 -#define YHOME 770 - -static void tplot(int mode, double x, double y) -{ - unsigned ix, iy; - int hx,hy,ly,lx; - - if (graphdev == SEL) - { - IGNORE(putc(ESC, cdev)); - IGNORE(putc('1', cdev)); - } - if (mode < 0) { - switch (mode) - { - default: - case -1: /* home cursor */ - switch (graphdev) - { - case ADM: /* to adm3a alpha mode */ - IGNORE(putc(US, cdev)); - IGNORE(putc(CAN, cdev)); - break; - case TEK4014: - default: - IGNORE(putc(GS, cdev)); - hy = ( ((YHOME & 01777) >> 5) + 32); - ly = ( (YHOME & 037) + 96); - hx = ( ((XHOME & 01777) >> 5) + 32); - lx = ( (XHOME & 037) + 64); - IGNORE(fprintf(cdev, "%c%c%c%c", hy, ly, hx, lx)); - IGNORE(putc(US, cdev)); - break; - } - text = 0; - return; - - case -2: /* to 4010 alpha mode */ - IGNORE(putc(GS, cdev)); - IGNORE(putc(US, cdev)); - text = 1; - return; - - case -3: /* erase, and go to alpha on ADM */ - switch (graphdev) - { - case ADM: - IGNORE(putc(GS, cdev)); - IGNORE(putc(EM, cdev)); - IGNORE(putc(US, cdev)); - IGNORE(putc(CAN, cdev)); - break; - case TEK4014: - default: - IGNORE(putc(ESC, cdev)); - IGNORE(putc(014, cdev)); - break; - } - text = 0; - return; - } - } - switch (mode) - { - case 0: /* enter point mode */ - /*IGNORE(putc(FS, cdev)); - break;*/ /* no point mode on pure 4014 so plot vector of 0 length*/ - case 1: /* enter vector mode */ - IGNORE(putc(GS, cdev)); - break; - } - iy = y; - ix = x; - hy = ( ((iy & 01777) >> 5) + 32); - ly = ( (iy & 037) + 96); - hx = ( ((ix & 01777) >> 5) + 32); - lx = ( (ix & 037) + 64); - IGNORE(fprintf(cdev, "%c%c%c%c", hy, ly, hx, lx)); - if (mode == 0) { - IGNORE(fprintf(cdev, "%c%c%c%c", hy, ly, hx, lx)); - } - return; -} -#endif /*TEK*/ - -#if FIG || HP || CODRAW - -static char hardplot_filename[100]; -void hardplot_file(const char* s) -{ - if (hpdev) { - IGNORE(fclose(hpdev)); - } - hpdev = (FILE *)0; - hpflag = 0; - hardplot = 0; - gdev = stdout; - if (s) { - hpdev = fopen(s, "w"); - if (hpdev) { - strncpy(hardplot_filename, s, 99); - hpflag = 1; - gdev = hpdev; - }else{ -IGNORE(fprintf(stderr, "Can't open %s for hardplot output\n", s)); - } - }else{ - hardplot_filename[0]='\0'; - } -} - -void Fig_file(const char* s, int dev) -{ - plt(-1, 0., 0.); - hardplot_file(s); - if (!hpdev) return; - hardplot = dev; -#if FIG - if (hardplot == 2) { - Fig_preamble(); - } -#endif -#if CODRAW - if (hardplot == 3) { - Codraw_preamble(); - } -#endif -} -#endif - -static char fig_text_preamble[100]; -static void hard_text_preamble(void) { - if (hardplot == 2) { - IGNORE(fprintf(hpdev, "%s", fig_text_preamble)); - fig_text_preamble[0] = '\0'; - } -} - -#if FIG -static void Fig_preamble(void) { - static char fig_preamble[] = "#FIG 1.4\n80 2\n"; - - if (!hpdev) return; - IGNORE(fprintf(hpdev,"%s", fig_preamble)); -} - -#define HIRES 1 -void Fig_plt(int mode, double x, double y) -{ -#define SCX(x) ((int)(x*.8)) -#define SCY(y) (600-(int)(y*.8)) -#if HIRES -#define SCXD(x) ((x*.8)) -#define SCYD(y) (7.5*80.-(y*.8)) -#endif -#undef TEXT -#define TEXT 1 -#define LINE1 2 -#define LINE2 3 - static short state=0; - static double oldx, oldy; - static char - text_preamble[] = "4 0 0 16 0 0 0 0.000 1 16 40 ", - text_postamble[]="\1\n", -#if HIRES - line_preamble[]="7 1 0 1 0 0 0 0 0.000 0 0\n", -#else - line_preamble[]="2 1 0 1 0 0 0 0 0.000 0 0\n", -#endif - line_postamble[]=" 9999 9999\n"; - - - - if (!hpdev) return; - - if (state == TEXT) - { - if (!fig_text_preamble[0]) { - IGNORE(fprintf(hpdev, "%s", text_postamble)); - } - state = 0; - text = 0; - } - - if (mode < 0) { - if (state == LINE2) { - IGNORE(fprintf(hpdev, "%s", line_postamble)); - } - text = 0; - state = 0; - if (mode == -2) { - IGNORE(sprintf(fig_text_preamble, "%s %d %d ", - text_preamble, SCX(oldx), SCY(oldy))); - state = TEXT; - text = 1; - return; - } - if (mode == -3) { -#if 0 - IGNORE(fseek(hpdev, 0L, 0)); - Fig_preamble(); -#else - Fig_file(hardplot_filename,2); -#endif - } - }else { - switch (mode) - { - case 0: - break; - case 1: - if (state == LINE2) { - IGNORE(fprintf(hpdev, "%s", line_postamble)); - } - state = LINE1; - break; - default: - if (state == LINE1) { -#if HIRES - IGNORE(fprintf(hpdev, "%s %.1f %.1f\n", line_preamble, - SCXD(oldx), SCYD(oldy))); -#else - IGNORE(fprintf(hpdev, "%s %d %d\n", line_preamble, - SCX(oldx), SCY(oldy))); -#endif - state = LINE2; - } -#if HIRES - IGNORE(fprintf(hpdev, " %.1f %.1f\n", SCXD(x), SCYD(y))); -#else - IGNORE(fprintf(hpdev, " %d %d\n", SCX(x), SCY(y))); -#endif - break; - } - oldx=x; oldy=y; - } -} - -#endif /*FIG*/ - -#if HP -void hplot(int mode, double x, double y) -{ - static short hpflag=0; - static short txt = 0; - - if (!hpdev) return; - if (hpflag == 0) { - hpflag = 1; -IGNORE(fprintf(hpdev, "%c.Y%c.I81;;17:%c.N;19:SC 0,1023,0,780;SP 1;", - ESC, ESC, ESC)); - } - - if (txt == 1) - { - IGNORE(fprintf(hpdev, "%c;", ETX)); - txt = 0; - text = 0; - } - if (mode < 0) - switch (mode) - { - case -2: - IGNORE(fprintf(hpdev, "LB")); - txt = 1; - text=1; - return; - - case -3: - txt=0; - text = 0; - hpflag=0; - IGNORE(fseek(hpdev, 0L, 0)); - return; - default: - IGNORE(fprintf(hpdev, "PU;SP;%c.Z", ESC)); - txt = 0; - text = 0; - hpflag = 0; - return; - } - switch (mode) - { - case 0: - IGNORE(fprintf(hpdev, "PU %8.2f,%8.2f;PD;", x, y)); - return; - case 1: - IGNORE(fprintf(hpdev, "PU %8.2f,%8.2f;", x, y)); - return; - default: - IGNORE(fprintf(hpdev, "PD %8.2f,%8.2f;", x, y)); - return; - } -} -#endif /*HP*/ - -/* not modified for new method */ -#if VT125 -void vtplot(int mode, double x, double y) -{ - static short vtgrph = 0; - int vtx, vty; - - if (mode < 0) - { - IGNORE(fprintf(gdev, "%c\\%c", ESC, ESC)); - switch (mode) - { - default: - case -1: /* vt125 alpha mode */ - break; - - case -2: /* graphics text mode */ - IGNORE(fprintf(gdev, "P1pt\'")); - vtgrph = 2; - return; - - case -3: /* erase graphics */ - IGNORE(fprintf(gdev, "P1pS(E)")); - break; - - case -4: /* erase text */ - IGNORE(fprintf(gdev, "[2J")); - break; - - case -5: /* switch to HP plotter */ - IGNORE(fprintf(gdev, "%c\\%c[5i", ESC, ESC)); /* esc and open port */ - vtgrph = 0; - hplot(-5, 0., 0.); - return; - } - IGNORE(fprintf(gdev, "%c\\", ESC)); - vtgrph = 0; - return; - } - - if (vtgrph == 2) - { - IGNORE(fprintf(gdev, "%c\\", ESC)); - vtgrph = 0; - } - if (vtgrph == 0) - { - IGNORE(fprintf(gdev, "%cP1p", ESC)); - vtgrph = 1; - } - vtx = (int) ((767./1023.)*x); - vty = (int) (479. - (479/779.)*y); - if (mode >= 2) - { - IGNORE(fprintf(gdev, "v[%d,%d]", vtx, vty)); - return; - } - IGNORE(fprintf(gdev, "p[%d,%d]", vtx, vty)); - if (mode == 0) - IGNORE(fprintf(gdev, "v[]")); - return; -} -#endif /*VT*/ - -int set_color(int c) -{ - if (c >= 0 || c < 128) { - hoc_color = c; - } -#if defined(__TURBOC__) - if (egagrph) { - setcolor(hoc_color); - } -#else -#if SUNCORE - set_line_index(c); - set_text_index(c); -#else -#if NRNOC_X11 - x11_setcolor(c); -#else -#if NeXTstep - NeXT_setcolor(c); -#endif -#endif -#endif -#endif - return (int) hoc_color; -} - -#if defined(__TURBOC__) -#define UN unsigned int - -static void tplt(int mode, double x, double y) -{ -#if DOS - extern int newstyle; -#endif - int ix, iy; - - if (egagrph == 0) - { - setgraphmode(graphmode); - setcolor(hoc_color); - egagrph = 1; -#if DOS - newstyle = 1; -#endif - } - - if (mode < 0) - { - text = 0; - switch (mode) - { - default: - case -1: - if (egagrph) { - egagrph=1; - } - cursor(0,0); - break; - - case -2: /* graphics text mode */ - egagrph=2; - text = 1; - return; - - case -3: /* erase graphics */ - restorecrtmode(); - egagrph = 0; - break; -#if GRX - case -4: - grx_txt_clear(); - break; - case -5: - GrClearScreen(0); - grx_force_text(); - break; - } -#endif - return; - } - - ix = ((xres -1.)/1023.)*x; - iy = (yres-1.) - ((yres-1.)/779.)*y; - - if (mode >= 2) - { - lineto(ix, iy); - } - if (mode == 1) { - moveto(ix, iy); - } - if (mode == 0) - { - moveto(ix, iy); - lineto(ix, iy); - } - return; -} - -void cursor(int r, int c) { -#if !defined(__GO32__) - int ax, dx; - ax = 2*256; - dx = (r&255)*256 + c&255; - _AX = ax; - _BX = 0; - _DX = dx; - geninterrupt(0x10); -#endif -} -#endif - -#if CODRAW - -#define CODRAW_MAXPOINT 200 -static int codraw_npoint = 0; -static float *codraw_pointx, *codraw_pointy; -static void codraw_line(); - -void Codraw_preamble() { - static char codraw_preamble[] = "SW(1,0,8,0,8);\nST(1);\nSG(0.1);\n\ -SF(1,'HELVET-L');\nSF(2,'HELVET');\nSF(3,'CENTURY');\nSF(4,'SCRIPT');\n\ -SF(5,'GREEK');\nSP(1);\nLT(1);LW(1);LC(15);LD(50);\nTF(1);TW(1);TS(0);TC(15);\ -TL(1);TV(4);TA(0);TH(0.2);\n"; - - if (!hpdev) return; - IGNORE(fprintf(hpdev,"%s", codraw_preamble)); - codraw_npoint = 0; - if (!codraw_pointy) { - codraw_pointx = (float *)hoc_Emalloc(CODRAW_MAXPOINT*sizeof(float)); - codraw_pointy = (float *)hoc_Emalloc(CODRAW_MAXPOINT*sizeof(float)); - hoc_malchk(); - } -} - -void Codraw_plt(mode, x, y) - int mode; - double x, y; -{ -#undef SCXD -#undef SCYD -#define SCXD(x) ((x*.008)) -#define SCYD(y) ((y*.008)) -#undef TEXT -#undef LINE1 -#undef LINE2 -#define TEXT 1 -#define LINE1 2 -#define LINE2 3 - static short state=0; - static double oldx, oldy; - - if (!hpdev) return; - - if (state == TEXT) - { - IGNORE(fprintf(hpdev, "');\n")); - state = 0; - text = 0; - } - - if (mode < 0) { - if (state == LINE2) { - codraw_line(); - } - text = 0; - state = 0; - if (mode == -2) { - IGNORE(fprintf(hpdev, "TT(%.2f,%.2f,'", - SCXD(oldx), SCYD(oldy))); - state = TEXT; - text = 1; - return; - } - if (mode == -3) { - IGNORE(fseek(hpdev, 0L, 0)); - Codraw_preamble(); - } - }else { - switch (mode) - { - case 0: - break; - case 1: - if (state == LINE2) { - codraw_line(); - } - state = LINE1; - break; - default: - if (state == LINE1) { - codraw_npoint = 1; - codraw_pointx[0] = oldx; - codraw_pointy[0] = oldy; - state = LINE2; - } - codraw_pointx[codraw_npoint] = x; - codraw_pointy[codraw_npoint] = y; - if (++codraw_npoint == CODRAW_MAXPOINT) { - codraw_line(); - } - break; - } - oldx=x; oldy=y; - } -} - -static void codraw_line() { - int i; - - if (codraw_npoint < 2) { - codraw_npoint = 0; - return; - } - IGNORE(fprintf(hpdev, "LL(%d", codraw_npoint)); - for (i=0; i= 0) { - x11_coord(x, y); - } - if (mode > 1) { - x11_vector(); - }else { - switch (mode) { - case 0: - x11_point(); - break; - case 1: - x11_move(); - break; - case -1: - text = 0; - x11flush(); - break; - case -2: - text = 1; - break; - case -3: - x11_clear(); - break; - case -4: - x11_coord(x, y); - x11_cleararea(); - break; - case -5: - x11_fast(1); - break; - case -6: - x11_fast(0); - } - } -} -#endif /*NRNOC_X11*/ - -#if NeXTstep -/* extern char *getenv(); */ -static -hoc_NeXTplot(mode, x, y) - int mode; - double x, y; -{ - extern int NeXT_init_done; - - if (!NeXT_init_done) { - NeXT_open_window(); - } - - if (mode >= 0) { - NeXT_coord(x, y); - } - if (mode > 1) { - NeXT_vector(); - }else { - switch (mode) { - case 0: - NeXT_point(); - break; - case 1: - NeXT_move(); - break; - case -1: - text = 0; - NeXTflush(); - break; - case -2: - text = 1; - break; - case -3: - NeXT_clear(); - break; - case -4: - NeXT_coord(x, y); - NeXT_cleararea(); - break; - case -5: - NeXT_fast(1); - break; - case -6: - NeXT_fast(0); - break; - case -7: - NeXT_fast(-1); - break; - } - } -} -#endif /*NeXTstep*/ - diff --git a/src/oc/plot.cpp b/src/oc/plot.cpp new file mode 100755 index 0000000000..d9dada956b --- /dev/null +++ b/src/oc/plot.cpp @@ -0,0 +1,1195 @@ +#include <../../nrnconf.h> +#include "hoc.h" + + +/*LINTLIBRARY*/ +#undef IGNORE +#if LINT +#define IGNORE(arg) {if(arg);} +#else +#define IGNORE(arg) arg +#endif + +#if GRX +#include +#include "hoc.h" +#define __TURBOC__ +#endif + +#if defined(useNeXTstep) || defined(__TURBOC__) || defined(__linux__) +#ifndef NRNOC_X11 +#define NRNOC_X11 0 +#endif +#endif + +#define FIG 1 /* 12/8/88 add fig style output , replaces hpflag*/ +#define TEK 1 +#define HP 1 +/* but not VT125 */ +#define CODRAW 1 + +#if CODRAW +static void Codraw_plt(int, double, double); +static void Codraw_preamble(void); +#endif + +#if HP +static void hplot(int, double, double); +#endif + +#if FIG +static void Fig_preamble(void); +static void Fig_plt(int, double, double); +void Fig_file(const char*, int); +#endif + +#if TEK +static void tplot(int, double, double); +#endif + +#include +#include + +#if defined(__MINGW32__) +extern char** _environ; +#else /*!__MINGW32__*/ + +#if HAVE_UNISTD_H +#include +#if !defined(__APPLE__) +extern char** environ; +#else /* __APPLE */ +#include +#endif /* __APPLE__ */ +#endif /* HAVE_UNISTD_H */ + +#endif /*!__MINGW32__*/ + +#if DOS +#include +#include +#endif +#if defined(GRX) +#define DOS 1 +#endif + +static int console = 1; /* 1 plotting to console graphics */ +static int hardplot; /* 1 hp style 2 fig style 3 coplot*/ +static int graphdev; +static int hpflag; /* hp plotter switch */ +int hoc_plttext; /* text can be printed to hpdev */ +#define text hoc_plttext +static FILE *gdev; /* system call stdout not directed to here */ +static FILE *hpdev; /* hp, or fig style file */ +static FILE *cdev; /* console device */ + +#define SSUN 1 +#define VT 2 +#define SEL 3 +#define TEK4014 4 +#define ADM 5 +#define NX 6 + +#define US 037 +#define GS 035 +#define CAN 030 +#define EM 031 +#define FS 034 +#define ESC 033 +#define ETX 03 + +static char vt100[] = "TERM=vt125"; +static char adm3a[] = "TERM=adm3a"; +static char ssun[] = "TERM=sun"; +static char tek4014[] = "TERM=4014"; +static char ncsa[] = "NEURON=ncsa"; +int hoc_color = 15; +static double xlast, ylast; + +#if NRNOC_X11 +extern void x11_put_text(const char*), x11_close_window(void), x11_setcolor(int); +extern void x11_coord(double, double), x11_vector(), x11_point(), x11_move(), x11flush(); +extern void x11_clear(), x11_cleararea(), x11_open_window(), x11_fast(int); +static void hoc_x11plot(int, double, double); +#endif + +#if NeXTstep +extern void NeXT_put_text(), NeXT_close_window(), NeXT_setcolor(); +extern void NeXT_coord(), NeXT_vector(), NeXT_point(), NeXT_move(), NeXTflush(); +extern void NeXT_clear(), NeXT_cleararea(), NeXT_open_window(), NeXT_fast(); +#endif + +static void hard_text_preamble(); + +#if defined(__TURBOC__) +int egagrph = 0; /* global because need to erase on quit if in graphics + mode */ +static int graphmode = 0; +static double xres=640., yres=350.; +static tplt(); + +void *_graphgetmem(unsigned size) { + char *p; + p= hoc_Emalloc(size), hoc_malchk() ; + return p; +} + +static void Initplot(void) { +#if !defined(__GO32__) + registerfarbgidriver(EGAVGA_driver_far); + registerfarbgidriver(CGA_driver_far); + registerfarbgidriver(Herc_driver_far); + registerfarbgifont(triplex_font_far); +#endif + + graphdev = DETECT; + initgraph(&graphdev, &graphmode,"c:\\bc\\bgi"); + {int err; + graphdev=1; + err = graphresult(); + if (err != grOk) { +hoc_execerror("Error in initializing graphics adaptor\n", (char *)0); + } + xres = (double)(getmaxx()+1); + yres = (double)(getmaxy()+1); + grx_txt_clear(); + return; + } + if (graphdev > 0) { + xres = (double)(getmaxx()+1); + yres = (double)(getmaxy()+1); + restorecrtmode(); + } else { +hoc_execerror("Error in initializing graphics adaptor\n", (char *)0); + } +} +#endif + +void plprint(const char* s) +{ +#if DOS + extern int newstyle; + extern unsigned text_style, text_size, text_orient; +#endif + char buf[128]; + + if (text && s[strlen(s) - 1] == '\n') { + IGNORE(strcpy(buf, s)); + s = buf; + buf[strlen(s)-1] = '\0'; + } + + if (console && text) { +#if DOS + if (egagrph == 2) { + if (newstyle) { + settextstyle(text_style,text_orient,text_size); + newstyle = 0; + } + outtext(s); + }else{ + IGNORE(fprintf(cdev, "%s", s)); + } +#else +#if SUNCORE + hoc_pl_sunplot(s); +#else +#if NRNOC_X11 + x11_put_text(s); +#else +#if NeXTstep + if (graphdev == NX) + NeXT_put_text(s); +#else + + IGNORE(fprintf(cdev, "%s", s)); + IGNORE(fflush(cdev)); +#endif +#endif +#endif +#endif + + } else if (!text) { +#if GRX + if (egagrph) { + hoc_outtext(s); + }else +#endif + { +#if 0 + IGNORE(fprintf(stdout, "%s", s)); +#else + nrnpy_pr("%s", s); +#endif + } + } + if (hardplot && hpdev && text && strlen(s)) { + hard_text_preamble(); + IGNORE(fprintf(hpdev, "%s", s)); + IGNORE(fflush(hpdev)); + } + if (text && s == buf) { + plt(1, xlast, ylast-20); + plt(-2, 0.,0.); + } +} + +#if GRX +static int trcur; +static GrTextRegion* gtr; +#define GRXCOL 80 +#define GRXROW 5 +void grx_move(int r, int c){ + r = r%GRXROW; + c = c%GRXCOL; + trcur = c + r*GRXCOL; +} +void grx_rel_move(int new){ + trcur = ((int)(trcur/GRXCOL))*GRXCOL + new; +} +void grx_output_some_chars(const char* string, int count) { + if (string[count] == '\0') { + hoc_outtext(string); + }else{ + hoc_outtext("non-terminated string\n"); + } +} +void grx_delete_chars(int count) { + int i; + int j = trcur; + for (i=0; i < count; ++i) { + gtr->txr_buffer[j++] = ' '; + } + GrDumpTextRegion(gtr); +} +grx_insert_some_chars(string, count) char* string; int count; { + int i, j; + i = trcur + count; + j = trcur + count; + while(i >= trcur) { + gtr->txr_buffer[j--] = gtr->txr_buffer[i--]; + } + i = trcur; + grx_output_some_chars(string, count); + trcur = i; +} +grx_backspace(count) int count; { + while (count--) { + trcur--; + } +} +grx_clear_to_eol() { + int j = trcur; + do { + gtr->txr_buffer[j] = ' '; + }while ((++j)%GRXCOL); + GrDumpTextRegion(gtr); +} + +grx_force_text() { + int i; + for (i=0; i < GRXCOL*GRXROW; ++i) { + gtr->txr_backup[i] = '\0'; + } + GrDumpTextRegion(gtr); +} + +grx_txt_clear() { + int i; + if (!gtr) { + gtr = (GrTextRegion*)emalloc(sizeof(GrTextRegion)); + gtr->txr_font = (GrFont*)0; + gtr->txr_buffer = ecalloc(GRXCOL*GRXROW, sizeof(char)); + gtr->txr_backup = ecalloc(GRXCOL*GRXROW, sizeof(char)); + gtr->txr_xpos = 0; + gtr->txr_ypos = 0; + gtr->txr_width = GRXCOL; + gtr->txr_height = GRXROW; + gtr->txr_lineoffset = GRXCOL; + gtr->txr_fgcolor.v = 7; + gtr->txr_bgcolor.v = 0; + gtr->txr_chrtype = GR_BYTE_TEXT; + } + for (i=0; i < GRXCOL*GRXROW; ++i) { + gtr->txr_buffer[i] = ' '; + } + trcur = 0; + GrDumpTextRegion(gtr); +} + +hoc_outtext(s) char* s; { + int i; + char* cp; + int ch; + if (!egagrph) { + return; + } + if (! gtr) { + grx_txt_clear(); + } + + for (cp = s; *cp; ++cp) { + ch = *cp; + if (*cp == '\n' || trcur >= GRXROW*GRXCOL) { + char* c1, *c2; + int j; + for (i=1; i < GRXROW; ++i) { + c1 = gtr->txr_buffer + (i-1)*GRXCOL; + c2 = gtr->txr_buffer + (i)*GRXCOL; + for (j =0; j < GRXCOL; ++j) { + c1[j] = c2[j]; + } + } + for (i=0; i < GRXCOL; ++i) { + c2[i] = ' '; + } + trcur = (GRXROW-1)*GRXCOL; + continue; + } + if (ch == '\t') { + ch = ' '; + } + gtr->txr_buffer[trcur++] = ch; + } + GrDumpTextRegion(gtr); +} +#endif + +void initplot(void) +{ +#if !defined(__MINGW32__) /* to end of function */ + int i; +#if defined (__APPLE__) + char** environ=(*_NSGetEnviron()); +#endif +#if defined(__TURBOC__) + graphdev = 0; +#else +#if NeXTstep + graphdev = NX; +#else + graphdev = SSUN; + for (i = 0; environ[i] != NULL; i++) + { + if (strcmp(environ[i], vt100) == 0) + graphdev = VT; + if (strcmp(environ[i], ssun) == 0) + graphdev = SSUN; + if (strcmp(environ[i], adm3a) == 0) + graphdev = ADM; + if (strcmp(environ[i], tek4014) == 0) + graphdev = TEK4014; + if (strcmp(environ[i], ncsa) == 0) + graphdev = TEK4014; + } +#endif /*!NeXTstep*/ +#endif /*!__TURBOC__*/ + hpdev = (FILE *)0; + cdev = gdev = stdout; +#if SUNCORE + if (graphdev == SSUN) { + hoc_open_sunplot(environ); +#else +#if NeXTstep + /*EMPTY*/ + if (graphdev == SSUN) { +#else +#if NRNOC_X11 + /*EMPTY*/ + if (graphdev == SSUN) { +#else + if (graphdev == SSUN) { +/* + if (graphdev == SSUN &&(cdev = fopen("/dev/ttyp4", "w")) == (FILE *)0) { + IGNORE(fprintf(stderr, "Can't open /dev/ttyp4 for TEK\n")); + cdev = stdout; +*/ +#endif /*NRNOC_X11*/ +#endif /*NeXTstep*/ +#endif /*SUNCORE*/ + } else { + if (graphdev == TEK4014) { + cdev = gdev = stdout; + } + } +#endif /*!__MINGW32__*/ +} + +void hoc_close_plot(void) { +#if DOS + if (egagrph) plt(-3,0.,0.); +#else +#if SUNCORE + hoc_close_sunplot(); +#else +#if NRNOC_X11 + x11_close_window(); +#else +#if NeXTstep + NeXT_close_window(); +#endif +#endif +#endif +#endif +} + +void plt(int mode, double x, double y) { + if (x < 0.) x = 0.; + if (x > 1000.) x = 1000.; + if (y < 0.) y = 0.; + if (y > 780.) y = 780.; + if (mode >= 0) { + xlast = x; + ylast = y; + } + if (console) { +#if defined(__TURBOC__) + if(graphdev > 0) { + tplt(mode, x, y); + } else if (graphdev == 0) { + Initplot(); + tplt(mode, x, y); + } +#else + switch (graphdev) { + case SSUN: +#if SUNCORE + hoc_sunplot(&text, mode, x, y); + break; +#else +#if NRNOC_X11 + hoc_x11plot(mode,x,y); + break; +#else +#if NeXTstep + break; + case NX: + hoc_NeXTplot(mode,x,y); + break; +#endif +#endif +#endif +#if TEK + case ADM: + case SEL: + case TEK4014: + tplot(mode, x, y); + break; +#endif +#if VT125 + case VT: + vtplot(mode, x, y); + break; +#endif + } +#endif + } +#if HP + if (hardplot == 1) { + hplot(mode, x, y); + } +#endif +#if FIG + if (hardplot == 2) { + Fig_plt(mode, x, y); + } +#endif +#if CODRAW + if (hardplot == 3) { + Codraw_plt(mode, x, y); + } +#endif + if (hardplot && hpdev) { + IGNORE(fflush(hpdev)); + } + if (console && cdev) { + IGNORE(fflush(cdev)); + } +} + +#if TEK +#define XHOME 0 +#define YHOME 770 + +static void tplot(int mode, double x, double y) { + unsigned ix, iy; + int hx, hy, ly, lx; + + if (graphdev == SEL) { + IGNORE(putc(ESC, cdev)); + IGNORE(putc('1', cdev)); + } + if (mode < 0) { + switch (mode) { + default: + case -1: /* home cursor */ + switch (graphdev) { + case ADM: /* to adm3a alpha mode */ + IGNORE(putc(US, cdev)); + IGNORE(putc(CAN, cdev)); + break; + case TEK4014: + default: + IGNORE(putc(GS, cdev)); + hy = (((YHOME & 01777) >> 5) + 32); + ly = ((YHOME & 037) + 96); + hx = (((XHOME & 01777) >> 5) + 32); + lx = ((XHOME & 037) + 64); + IGNORE(fprintf(cdev, "%c%c%c%c", hy, ly, hx, lx)); + IGNORE(putc(US, cdev)); + break; + } + text = 0; + return; + + case -2: /* to 4010 alpha mode */ + IGNORE(putc(GS, cdev)); + IGNORE(putc(US, cdev)); + text = 1; + return; + + case -3: /* erase, and go to alpha on ADM */ + switch (graphdev) { + case ADM: + IGNORE(putc(GS, cdev)); + IGNORE(putc(EM, cdev)); + IGNORE(putc(US, cdev)); + IGNORE(putc(CAN, cdev)); + break; + case TEK4014: + default: + IGNORE(putc(ESC, cdev)); + IGNORE(putc(014, cdev)); + break; + } + text = 0; + return; + } + } + switch (mode) { + case 0: /* enter point mode */ + /*IGNORE(putc(FS, cdev)); + break;*/ /* no point mode on pure 4014 so plot vector of 0 length*/ + case 1: /* enter vector mode */ + IGNORE(putc(GS, cdev)); + break; + } + iy = y; + ix = x; + hy = (((iy & 01777) >> 5) + 32); + ly = ((iy & 037) + 96); + hx = (((ix & 01777) >> 5) + 32); + lx = ((ix & 037) + 64); + IGNORE(fprintf(cdev, "%c%c%c%c", hy, ly, hx, lx)); + if (mode == 0) { + IGNORE(fprintf(cdev, "%c%c%c%c", hy, ly, hx, lx)); + } + return; +} + +#endif /*TEK*/ + +#if FIG || HP || CODRAW + +static char hardplot_filename[100]; + +void hardplot_file(const char *s) { + if (hpdev) { + IGNORE(fclose(hpdev)); + } + hpdev = (FILE *) 0; + hpflag = 0; + hardplot = 0; + gdev = stdout; + if (s) { + hpdev = fopen(s, "w"); + if (hpdev) { + strncpy(hardplot_filename, s, 99); + hpflag = 1; + gdev = hpdev; + } else { + IGNORE(fprintf(stderr, "Can't open %s for hardplot output\n", s)); + } + } else { + hardplot_filename[0] = '\0'; + } +} + +void Fig_file(const char *s, int dev) { + plt(-1, 0., 0.); + hardplot_file(s); + if (!hpdev) return; + hardplot = dev; +#if FIG + if (hardplot == 2) { + Fig_preamble(); + } +#endif +#if CODRAW + if (hardplot == 3) { + Codraw_preamble(); + } +#endif +} + +#endif + +static char fig_text_preamble[100]; + +static void hard_text_preamble(void) { + if (hardplot == 2) { + IGNORE(fprintf(hpdev, "%s", fig_text_preamble)); + fig_text_preamble[0] = '\0'; + } +} + +#if FIG + +static void Fig_preamble(void) { + static char fig_preamble[] = "#FIG 1.4\n80 2\n"; + + if (!hpdev) return; + IGNORE(fprintf(hpdev, "%s", fig_preamble)); +} + +#define HIRES 1 + +void Fig_plt(int mode, double x, double y) { +#define SCX(x) ((int)(x*.8)) +#define SCY(y) (600-(int)(y*.8)) +#if HIRES +#define SCXD(x) ((x*.8)) +#define SCYD(y) (7.5*80.-(y*.8)) +#endif +#undef TEXT +#define TEXT 1 +#define LINE1 2 +#define LINE2 3 + static short state = 0; + static double oldx, oldy; + static char + text_preamble[] = "4 0 0 16 0 0 0 0.000 1 16 40 ", + text_postamble[] = "\1\n", +#if HIRES + line_preamble[] = "7 1 0 1 0 0 0 0 0.000 0 0\n", +#else + line_preamble[]="2 1 0 1 0 0 0 0 0.000 0 0\n", +#endif + line_postamble[] = " 9999 9999\n"; + + + if (!hpdev) return; + + if (state == TEXT) { + if (!fig_text_preamble[0]) { + IGNORE(fprintf(hpdev, "%s", text_postamble)); + } + state = 0; + text = 0; + } + + if (mode < 0) { + if (state == LINE2) { + IGNORE(fprintf(hpdev, "%s", line_postamble)); + } + text = 0; + state = 0; + if (mode == -2) { + IGNORE(sprintf(fig_text_preamble, "%s %d %d ", + text_preamble, SCX(oldx), SCY(oldy))); + state = TEXT; + text = 1; + return; + } + if (mode == -3) { +#if 0 + IGNORE(fseek(hpdev, 0L, 0)); + Fig_preamble(); +#else + Fig_file(hardplot_filename, 2); +#endif + } + } else { + switch (mode) { + case 0: + break; + case 1: + if (state == LINE2) { + IGNORE(fprintf(hpdev, "%s", line_postamble)); + } + state = LINE1; + break; + default: + if (state == LINE1) { +#if HIRES + IGNORE(fprintf(hpdev, "%s %.1f %.1f\n", line_preamble, + SCXD(oldx), SCYD(oldy))); +#else + IGNORE(fprintf(hpdev, "%s %d %d\n", line_preamble, + SCX(oldx), SCY(oldy))); +#endif + state = LINE2; + } +#if HIRES + IGNORE(fprintf(hpdev, " %.1f %.1f\n", SCXD(x), SCYD(y))); +#else + IGNORE(fprintf(hpdev, " %d %d\n", SCX(x), SCY(y))); +#endif + break; + } + oldx = x; + oldy = y; + } +} + +#endif /*FIG*/ + +#if HP + +void hplot(int mode, double x, double y) { + static short hpflag = 0; + static short txt = 0; + + if (!hpdev) return; + if (hpflag == 0) { + hpflag = 1; + IGNORE(fprintf(hpdev, "%c.Y%c.I81;;17:%c.N;19:SC 0,1023,0,780;SP 1;", + ESC, ESC, ESC)); + } + + if (txt == 1) { + IGNORE(fprintf(hpdev, "%c;", ETX)); + txt = 0; + text = 0; + } + if (mode < 0) + switch (mode) { + case -2: + IGNORE(fprintf(hpdev, "LB")); + txt = 1; + text = 1; + return; + + case -3: + txt = 0; + text = 0; + hpflag = 0; + IGNORE(fseek(hpdev, 0L, 0)); + return; + default: + IGNORE(fprintf(hpdev, "PU;SP;%c.Z", ESC)); + txt = 0; + text = 0; + hpflag = 0; + return; + } + switch (mode) { + case 0: + IGNORE(fprintf(hpdev, "PU %8.2f,%8.2f;PD;", x, y)); + return; + case 1: + IGNORE(fprintf(hpdev, "PU %8.2f,%8.2f;", x, y)); + return; + default: + IGNORE(fprintf(hpdev, "PD %8.2f,%8.2f;", x, y)); + return; + } +} + +#endif /*HP*/ + +/* not modified for new method */ +#if VT125 +void vtplot(int mode, double x, double y) +{ + static short vtgrph = 0; + int vtx, vty; + + if (mode < 0) + { + IGNORE(fprintf(gdev, "%c\\%c", ESC, ESC)); + switch (mode) + { + default: + case -1: /* vt125 alpha mode */ + break; + + case -2: /* graphics text mode */ + IGNORE(fprintf(gdev, "P1pt\'")); + vtgrph = 2; + return; + + case -3: /* erase graphics */ + IGNORE(fprintf(gdev, "P1pS(E)")); + break; + + case -4: /* erase text */ + IGNORE(fprintf(gdev, "[2J")); + break; + + case -5: /* switch to HP plotter */ + IGNORE(fprintf(gdev, "%c\\%c[5i", ESC, ESC)); /* esc and open port */ + vtgrph = 0; + hplot(-5, 0., 0.); + return; + } + IGNORE(fprintf(gdev, "%c\\", ESC)); + vtgrph = 0; + return; + } + + if (vtgrph == 2) + { + IGNORE(fprintf(gdev, "%c\\", ESC)); + vtgrph = 0; + } + if (vtgrph == 0) + { + IGNORE(fprintf(gdev, "%cP1p", ESC)); + vtgrph = 1; + } + vtx = (int) ((767./1023.)*x); + vty = (int) (479. - (479/779.)*y); + if (mode >= 2) + { + IGNORE(fprintf(gdev, "v[%d,%d]", vtx, vty)); + return; + } + IGNORE(fprintf(gdev, "p[%d,%d]", vtx, vty)); + if (mode == 0) + IGNORE(fprintf(gdev, "v[]")); + return; +} +#endif /*VT*/ + +int set_color(int c) { + if (c >= 0 || c < 128) { + hoc_color = c; + } +#if defined(__TURBOC__) + if (egagrph) { + setcolor(hoc_color); + } +#else +#if SUNCORE + set_line_index(c); + set_text_index(c); +#else +#if NRNOC_X11 + x11_setcolor(c); +#else +#if NeXTstep + NeXT_setcolor(c); +#endif +#endif +#endif +#endif + return (int) hoc_color; +} + +#if defined(__TURBOC__) +#define UN unsigned int + +static void tplt(int mode, double x, double y) +{ +#if DOS + extern int newstyle; +#endif + int ix, iy; + + if (egagrph == 0) + { + setgraphmode(graphmode); + setcolor(hoc_color); + egagrph = 1; +#if DOS + newstyle = 1; +#endif + } + + if (mode < 0) + { + text = 0; + switch (mode) + { + default: + case -1: + if (egagrph) { + egagrph=1; + } + cursor(0,0); + break; + + case -2: /* graphics text mode */ + egagrph=2; + text = 1; + return; + + case -3: /* erase graphics */ + restorecrtmode(); + egagrph = 0; + break; +#if GRX + case -4: + grx_txt_clear(); + break; + case -5: + GrClearScreen(0); + grx_force_text(); + break; + } +#endif + return; + } + + ix = ((xres -1.)/1023.)*x; + iy = (yres-1.) - ((yres-1.)/779.)*y; + + if (mode >= 2) + { + lineto(ix, iy); + } + if (mode == 1) { + moveto(ix, iy); + } + if (mode == 0) + { + moveto(ix, iy); + lineto(ix, iy); + } + return; +} + +void cursor(int r, int c) { +#if !defined(__GO32__) + int ax, dx; + ax = 2*256; + dx = (r&255)*256 + c&255; + _AX = ax; + _BX = 0; + _DX = dx; + geninterrupt(0x10); +#endif +} +#endif + +#if CODRAW + +#define CODRAW_MAXPOINT 200 +static int codraw_npoint = 0; +static float *codraw_pointx, *codraw_pointy; + +static void codraw_line(); + +void Codraw_preamble() { + static char codraw_preamble[] = "SW(1,0,8,0,8);\nST(1);\nSG(0.1);\n\ +SF(1,'HELVET-L');\nSF(2,'HELVET');\nSF(3,'CENTURY');\nSF(4,'SCRIPT');\n\ +SF(5,'GREEK');\nSP(1);\nLT(1);LW(1);LC(15);LD(50);\nTF(1);TW(1);TS(0);TC(15);\ +TL(1);TV(4);TA(0);TH(0.2);\n"; + + if (!hpdev) return; + IGNORE(fprintf(hpdev, "%s", codraw_preamble)); + codraw_npoint = 0; + if (!codraw_pointy) { + codraw_pointx = (float *) hoc_Emalloc(CODRAW_MAXPOINT * sizeof(float)); + codraw_pointy = (float *) hoc_Emalloc(CODRAW_MAXPOINT * sizeof(float)); + hoc_malchk(); + } +} + +void Codraw_plt(int mode, double x, double y) { +#undef SCXD +#undef SCYD +#define SCXD(x) ((x*.008)) +#define SCYD(y) ((y*.008)) +#undef TEXT +#undef LINE1 +#undef LINE2 +#define TEXT 1 +#define LINE1 2 +#define LINE2 3 + static short state = 0; + static double oldx, oldy; + + if (!hpdev) return; + + if (state == TEXT) { + IGNORE(fprintf(hpdev, "');\n")); + state = 0; + text = 0; + } + + if (mode < 0) { + if (state == LINE2) { + codraw_line(); + } + text = 0; + state = 0; + if (mode == -2) { + IGNORE(fprintf(hpdev, "TT(%.2f,%.2f,'", + SCXD(oldx), SCYD(oldy))); + state = TEXT; + text = 1; + return; + } + if (mode == -3) { + IGNORE(fseek(hpdev, 0L, 0)); + Codraw_preamble(); + } + } else { + switch (mode) { + case 0: + break; + case 1: + if (state == LINE2) { + codraw_line(); + } + state = LINE1; + break; + default: + if (state == LINE1) { + codraw_npoint = 1; + codraw_pointx[0] = oldx; + codraw_pointy[0] = oldy; + state = LINE2; + } + codraw_pointx[codraw_npoint] = x; + codraw_pointy[codraw_npoint] = y; + if (++codraw_npoint == CODRAW_MAXPOINT) { + codraw_line(); + } + break; + } + oldx = x; + oldy = y; + } +} + +static void codraw_line() { + int i; + + if (codraw_npoint < 2) { + codraw_npoint = 0; + return; + } + IGNORE(fprintf(hpdev, "LL(%d", codraw_npoint)); + for (i = 0; i < codraw_npoint; i++) { + if (((i + 1) % 8) == 0) { + IGNORE(fprintf(hpdev, "\n")); + } + IGNORE(fprintf(hpdev, ",%.2f,%.2f", SCXD(codraw_pointx[i]), + SCYD(codraw_pointy[i]))); + } + IGNORE(fprintf(hpdev, ");\n")); + if (codraw_npoint == CODRAW_MAXPOINT) { + codraw_npoint = 1; + codraw_pointx[0] = codraw_pointx[CODRAW_MAXPOINT - 1]; + codraw_pointy[0] = codraw_pointy[CODRAW_MAXPOINT - 1]; + } else { + codraw_npoint = 0; + } +} + +#endif + +#if NRNOC_X11 +extern char *getenv(); +static void hoc_x11plot(int mode, double x, double y) +{ + extern int x11_init_done; + + if (!x11_init_done) { + x11_open_window(); + } + + if (mode >= 0) { + x11_coord(x, y); + } + if (mode > 1) { + x11_vector(); + }else { + switch (mode) { + case 0: + x11_point(); + break; + case 1: + x11_move(); + break; + case -1: + text = 0; + x11flush(); + break; + case -2: + text = 1; + break; + case -3: + x11_clear(); + break; + case -4: + x11_coord(x, y); + x11_cleararea(); + break; + case -5: + x11_fast(1); + break; + case -6: + x11_fast(0); + } + } +} +#endif /*NRNOC_X11*/ + +#if NeXTstep +/* extern char *getenv(); */ +static +hoc_NeXTplot(mode, x, y) + int mode; + double x, y; +{ + extern int NeXT_init_done; + + if (!NeXT_init_done) { + NeXT_open_window(); + } + + if (mode >= 0) { + NeXT_coord(x, y); + } + if (mode > 1) { + NeXT_vector(); + }else { + switch (mode) { + case 0: + NeXT_point(); + break; + case 1: + NeXT_move(); + break; + case -1: + text = 0; + NeXTflush(); + break; + case -2: + text = 1; + break; + case -3: + NeXT_clear(); + break; + case -4: + NeXT_coord(x, y); + NeXT_cleararea(); + break; + case -5: + NeXT_fast(1); + break; + case -6: + NeXT_fast(0); + break; + case -7: + NeXT_fast(-1); + break; + } + } +} +#endif /*NeXTstep*/ + diff --git a/src/oc/plt.c b/src/oc/plt.cpp similarity index 99% rename from src/oc/plt.c rename to src/oc/plt.cpp index dc6f0454b7..a343c94e03 100755 --- a/src/oc/plt.c +++ b/src/oc/plt.cpp @@ -5,6 +5,8 @@ */ #include "hoc.h" #include "gui-redirect.h" + + extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); extern double (*nrnpy_object_to_double_)(Object*); @@ -70,4 +72,5 @@ void hoc_Lw(void) pushx(0.); } + #endif /*!defined(CYGWIN)*/ diff --git a/src/oc/prmat.c b/src/oc/prmat.c deleted file mode 100755 index ebaadb4465..0000000000 --- a/src/oc/prmat.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <../../nrnconf.h> -/* - * Automake doesn't deal well with sources that live in other directories, so - * this is a quick and dirty workaround. - */ -#include "../sparse/prmat.c" diff --git a/src/oc/prmat.cpp b/src/oc/prmat.cpp new file mode 100755 index 0000000000..9ef6221a06 --- /dev/null +++ b/src/oc/prmat.cpp @@ -0,0 +1,6 @@ +#include <../../nrnconf.h> +/* + * Automake doesn't deal well with sources that live in other directories, so + * this is a quick and dirty workaround. + */ +#include "../sparse/prmat.cpp" diff --git a/src/oc/profile.h b/src/oc/profile.h index ecbc2113e3..481e5d4613 100755 --- a/src/oc/profile.h +++ b/src/oc/profile.h @@ -1,13 +1,7 @@ #ifndef profile_h -#ifdef __cplusplus -extern "C" { -#endif extern void start_profile(int); extern void add_profile(int); -#ifdef __cplusplus -} -#endif #if defined(PROFILE) && PROFILE > 0 #define PSTART(i) start_profile(i); diff --git a/src/oc/redef.h b/src/oc/redef.h index 27971c5e74..d84eebf400 100755 --- a/src/oc/redef.h +++ b/src/oc/redef.h @@ -3,6 +3,9 @@ #ifndef hoc_redef_h #define hoc_redef_h + + + # define Break hoc_Break # define Continue hoc_Continue # define Exp hoc_Exp @@ -137,4 +140,5 @@ # define xopen hoc_xopen # define zzdebug hoc_zzdebug + #endif diff --git a/src/oc/regexp.c b/src/oc/regexp.cpp similarity index 97% rename from src/oc/regexp.c rename to src/oc/regexp.cpp index bbb37aa953..6c94b93c95 100755 --- a/src/oc/regexp.c +++ b/src/oc/regexp.cpp @@ -1,7 +1,7 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/regexp.c,v 1.1.1.1 1994/10/12 17:22:13 hines Exp */ +/* /local/src/master/nrn/src/oc/regexp.cpp,v 1.1.1.1 1994/10/12 17:22:13 hines Exp */ /* -regexp.c,v +regexp.cpp,v * Revision 1.1.1.1 1994/10/12 17:22:13 hines * NEURON 3.0 distribution * @@ -26,7 +26,7 @@ regexp.c,v * * Revision 3.58 90/05/17 16:30:52 jamie * changed global functions to start with hoc_ - * moved regexp.c from project 'neuron' to 'hoc' + * moved regexp.cpp from project 'neuron' to 'hoc' * * Revision 1.25 89/08/31 10:28:46 mlh * regular expressions for issection() @@ -36,7 +36,7 @@ regexp.c,v * eliminate \( * * Revision 1.2 89/08/31 09:22:17 mlh - * works as in e.c and lint free + * works as in e.cpp and lint free * * Revision 1.1 89/08/31 08:24:59 mlh * Initial revision @@ -44,7 +44,7 @@ regexp.c,v */ /* regular expression match for section names - grabbed prototype from e.c + grabbed prototype from e.cpp Use by first compiling the search string with hoc_regexp_compile(pattern) Then checking target strings one at a time with hoc_regexp_search(target) */ diff --git a/src/oc/scoplib_ansi.h b/src/oc/scoplib_ansi.h index 5fbee00988..66b537929d 100644 --- a/src/oc/scoplib_ansi.h +++ b/src/oc/scoplib_ansi.h @@ -1,5 +1,6 @@ #ifndef scoplib_ansi_h #define scoplib_ansi_h + #if defined(__cplusplus) extern "C" { #endif @@ -131,4 +132,5 @@ double scop_erf(double); /* (x) */ #if defined(__cplusplus) } #endif + #endif diff --git a/src/oc/scoprand.c b/src/oc/scoprand.cpp similarity index 93% rename from src/oc/scoprand.c rename to src/oc/scoprand.cpp index 11c2846f49..8541d811a3 100755 --- a/src/oc/scoprand.c +++ b/src/oc/scoprand.cpp @@ -9,7 +9,7 @@ other in nrnmech.dll. /****************************************************************************** * - * File: random.c + * File: random.cpp * * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 * Duke University @@ -18,7 +18,7 @@ other in nrnmech.dll. #ifndef LINT static char RCSid[] = - "random.c,v 1.4 1999/01/04 12:46:49 hines Exp" ; + "random.cpp,v 1.4 1999/01/04 12:46:49 hines Exp" ; #endif #include @@ -55,7 +55,7 @@ static uint32_t value = 1; * *--------------------------------------------------------------------------- */ -double scop_random(void) +extern "C" double scop_random(void) { extern int use_mcell_ran4_; if (use_mcell_ran4_) { @@ -94,7 +94,7 @@ double scop_random(void) * */ -void set_seed(double seed) +extern "C" void set_seed(double seed) { value = (uint32_t)seed; } diff --git a/src/oc/settext.c b/src/oc/settext.cpp similarity index 100% rename from src/oc/settext.c rename to src/oc/settext.cpp diff --git a/src/oc/spinit.c b/src/oc/spinit.cpp similarity index 83% rename from src/oc/spinit.c rename to src/oc/spinit.cpp index a5582750d5..770525eb9f 100755 --- a/src/oc/spinit.c +++ b/src/oc/spinit.cpp @@ -1,7 +1,7 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/spinit.c,v 1.1.1.1 1994/10/12 17:22:14 hines Exp */ +/* /local/src/master/nrn/src/oc/spinit.cpp,v 1.1.1.1 1994/10/12 17:22:14 hines Exp */ /* -spinit.c,v +spinit.cpp,v * Revision 1.1.1.1 1994/10/12 17:22:14 hines * NEURON 3.0 distribution * @@ -17,7 +17,7 @@ spinit.c,v * hoc_returning. * This was done so init... could be called both from hoc_spinit and from * hoc. - * last function called by hoc_spinit in hocusr.c is hoc_last_init() + * last function called by hoc_spinit in hocusr.cpp is hoc_last_init() * * Revision 1.1 91/10/11 11:12:18 hines * Initial revision diff --git a/src/oc/spinit1.c b/src/oc/spinit1.cpp similarity index 88% rename from src/oc/spinit1.c rename to src/oc/spinit1.cpp index f477aedf88..2ae3b1c3c5 100755 --- a/src/oc/spinit1.c +++ b/src/oc/spinit1.cpp @@ -1,3 +1,3 @@ #include <../../nrnconf.h> -void hoc_last_init(void) {} /* called at end of hoc_spinit in hocusr.c */ +void hoc_last_init(void) {} /* called at end of hoc_spinit in hocusr.cpp */ diff --git a/src/oc/spinit2.c b/src/oc/spinit2.cpp similarity index 53% rename from src/oc/spinit2.c rename to src/oc/spinit2.cpp index d62beae865..db8c594c02 100755 --- a/src/oc/spinit2.c +++ b/src/oc/spinit2.cpp @@ -3,9 +3,9 @@ #include #include "hocdec.h" -void _modl_set_dt(newdt) double newdt; { +extern "C" void _modl_set_dt(double newdt){ /*ARGSUSED*/ - printf("ssimplic.c :: _modl_set_dt can't be called\n"); + printf("ssimplic.cpp :: _modl_set_dt can't be called\n"); nrn_exit(1); } diff --git a/src/oc/subrows.c b/src/oc/subrows.c deleted file mode 100755 index 22b3ea4c6a..0000000000 --- a/src/oc/subrows.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <../../nrnconf.h> -/* - * Automake doesn't deal well with sources that live in other directories, so - * this is a quick and dirty workaround. - */ -#include "../sparse/subrows.c" diff --git a/src/oc/subrows.cpp b/src/oc/subrows.cpp new file mode 100755 index 0000000000..48f7076d49 --- /dev/null +++ b/src/oc/subrows.cpp @@ -0,0 +1,6 @@ +#include <../../nrnconf.h> +/* + * Automake doesn't deal well with sources that live in other directories, so + * this is a quick and dirty workaround. + */ +#include "../sparse/subrows.cpp" diff --git a/src/oc/symbol.c b/src/oc/symbol.cpp similarity index 90% rename from src/oc/symbol.c rename to src/oc/symbol.cpp index a98e7f0e70..d865929b28 100755 --- a/src/oc/symbol.c +++ b/src/oc/symbol.cpp @@ -1,5 +1,5 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/symbol.c,v 1.9 1999/02/25 18:01:58 hines Exp */ +/* /local/src/master/nrn/src/oc/symbol.cpp,v 1.9 1999/02/25 18:01:58 hines Exp */ /* version 7.2.1 2-jan-89 */ #if HAVE_POSIX_MEMALIGN @@ -105,7 +105,7 @@ Symbol* install( /* install s in the list symbol table */ sp->type = t; sp->subtype = NOTUSER; sp->defined_on_the_fly = 0; - sp->public = 0; + sp->cpublic = 0; sp->s_varn = 0; sp->arayinfo = (Arrayinfo *)0; sp->extra = (HocSymExtension*)0; @@ -187,14 +187,14 @@ void hoc_link_symbol(Symbol* sp, Symlist* list) { static int emalloc_error=0; -void hoc_malchk(void) { +extern "C" void hoc_malchk(void) { if (emalloc_error) { emalloc_error = 0; execerror("out of memory", (char *) 0); } } -void* hoc_Emalloc(size_t n) { /* check return from malloc */ +extern "C" void* hoc_Emalloc(size_t n) { /* check return from malloc */ void *p; p = malloc(n); @@ -209,11 +209,11 @@ void* emalloc(size_t n) { return p; } -void* hoc_Ecalloc(size_t n, size_t size) { /* check return from calloc */ +extern "C" void* hoc_Ecalloc(size_t n, size_t size) { /* check return from calloc */ void *p; if (n == 0) { - return (void*)0; + return nullptr; } p = calloc(n, size); if (p == 0) @@ -221,7 +221,7 @@ void* hoc_Ecalloc(size_t n, size_t size) { /* check return from calloc */ return p; } -void* ecalloc(size_t n, size_t size) { +extern "C" void* ecalloc(size_t n, size_t size) { void* p = hoc_Ecalloc(n, size); if (emalloc_error) { hoc_malchk(); } return p; @@ -267,14 +267,14 @@ void* hoc_Erealloc(void* ptr, size_t size) {/* check return from realloc */ return p; } -void* erealloc(void* ptr, size_t size) { +extern "C" void* erealloc(void* ptr, size_t size) { void* p = hoc_Erealloc(ptr, size); if (emalloc_error) { hoc_malchk(); } return p; } void hoc_free_symspace(Symbol* s1) { /* frees symbol space. Marks it UNDEF */ - if (s1 && s1->public != 2) { + if (s1 && s1->cpublic != 2) { switch (s1->type) { case UNDEF: @@ -302,12 +302,12 @@ void hoc_free_symspace(Symbol* s1) { /* frees symbol space. Marks it UNDEF */ case AUTOOBJ: break; case TEMPLATE: -hoc_free_allobjects(s1->u.template, hoc_top_level_symlist, hoc_top_level_data); - free_list(&(s1->u.template->symtable)); - {hoc_List* l = s1->u.template->olist; +hoc_free_allobjects(s1->u.ctemplate, hoc_top_level_symlist, hoc_top_level_data); + free_list(&(s1->u.ctemplate->symtable)); + {hoc_List* l = s1->u.ctemplate->olist; if (l->next == l) { - hoc_l_freelist(&s1->u.template->olist); - free(s1->u.template); + hoc_l_freelist(&s1->u.ctemplate->olist); + free(s1->u.ctemplate); }else{ hoc_warning("didn't free all objects created with the old template:", s1->name); } @@ -343,7 +343,7 @@ Fprintf(stderr, "In free_symspace may not free all of %s of type=%d\n", s1->name } if (s1->extra) { if (s1->extra->parmlimits) { - free((char*)s1->extra->parmlimits); + free(s1->extra->parmlimits); } if (s1->extra->units) { free(s1->extra->units); @@ -406,7 +406,7 @@ void hoc_free_pstring(char** p) { } } -unsigned long long nrn_mallinfo(int item) { +extern "C" unsigned long long nrn_mallinfo(int item) { #if BLUEGENEQ /* BLUEGENE-Q ------------------------------------------------ */ uint64_t heap = 0; @@ -451,13 +451,14 @@ unsigned long long nrn_mallinfo(int item) { } int hoc_mallinfo(void) { - int i; - unsigned long long x; - extern double chkarg(int, double, double); - i = (int)chkarg(1, 0., 10.); - x = nrn_mallinfo(i); - hoc_ret(); - pushx((double)x); - return 0; + int i; + unsigned long long x; + extern double chkarg(int, double, double); + i = (int) chkarg(1, 0., 10.); + x = nrn_mallinfo(i); + hoc_ret(); + pushx((double) x); + return 0; } + diff --git a/src/oc/system.c b/src/oc/system.cpp similarity index 100% rename from src/oc/system.c rename to src/oc/system.cpp diff --git a/src/oc/termio.c b/src/oc/termio.cpp similarity index 100% rename from src/oc/termio.c rename to src/oc/termio.cpp diff --git a/src/oc/version.c b/src/oc/version.cpp similarity index 96% rename from src/oc/version.c rename to src/oc/version.cpp index f6dbee641d..9989ab871c 100755 --- a/src/oc/version.c +++ b/src/oc/version.cpp @@ -63,7 +63,7 @@ NEURON 5.3 2002/06/04 * * Revision 2.108 1994/08/05 14:16:14 hines * show_errmess_always() - * errno not defined from include file in hoc.c + * errno not defined from include file in hoc.cpp * NullArgument replaces null arguments in Imakefile * * Revision 2.107 1994/07/30 17:33:51 hines @@ -95,7 +95,7 @@ NEURON 5.3 2002/06/04 * allow recursive calls to interpreter even in case of hoc_execerror. * * Revision 2.99 1994/06/17 13:00:35 hines - * a number of things fixed while looking at the test coverage of hoc.c + * a number of things fixed while looking at the test coverage of hoc.cpp * mostly just to allow coverage. * CBUFSIZE is larger than 256 * array index computed with double arithmetic. @@ -172,7 +172,7 @@ NEURON 5.3 2002/06/04 * PI, E, etc are now userdoubles and are available within objects. * * Revision 2.81 1994/04/27 11:21:31 hines - * support for ivoc/SRC/checkpoint.c + * support for ivoc/SRC/checkpoint.cpp * usage is checkpoint("filename") * then ivoc filename ... * so far only for oc @@ -217,7 +217,7 @@ NEURON 5.3 2002/06/04 * help word word ... in ivoc tickles the help system * * Revision 2.69 1994/02/10 19:41:06 hines - * set term=vt125 replaces vt100 in plot.c since that is a common term + * set term=vt125 replaces vt100 in plot.cpp since that is a common term * even in a window system * * Revision 2.68 1994/01/21 18:14:31 hines @@ -348,7 +348,7 @@ NEURON 5.3 2002/06/04 * * Revision 2.31 93/03/05 08:42:20 hines * some slight performance improvements by avoidin hoc_lookup for objects - * and use stack macros in code.c + * and use stack macros in code.cpp * * Revision 2.30 93/03/02 08:30:12 hines * parallization of shortfor loop as in @@ -392,7 +392,7 @@ NEURON 5.3 2002/06/04 * get METHOD3 from options.h * * Revision 2.17 93/01/23 13:40:47 hines - * don't inlclude stdio.h twice in ytab.c + * don't inlclude stdio.h twice in ytab.cpp * * Revision 2.16 93/01/22 17:34:29 hines * ocmodl, ivmodl working both for shared and static libraries @@ -471,7 +471,7 @@ NEURON 5.3 2002/06/04 * can turn off error messages temporarily * * Revision 1.124 92/11/16 11:20:23 hines - * error in x.c message when color doesn't exist + * error in x.cpp message when color doesn't exist * xlabel("string") * * Revision 1.123 92/11/13 16:09:20 hines @@ -486,7 +486,7 @@ NEURON 5.3 2002/06/04 * * Revision 1.120 92/11/10 07:38:37 hines * char* expand_env_var(char*) expands all the $(...) in the string. - * moved from ivoc/main.c to here so oc can use it too. + * moved from ivoc/main.cpp to here so oc can use it too. * xopen("...") now allows environment variables * * Revision 1.119 92/11/09 17:14:28 hines @@ -509,7 +509,7 @@ NEURON 5.3 2002/06/04 * *getarg() now checks to make sure it is returning a number * * Revision 1.113 92/10/27 12:08:18 hines - * list.c hoclist.h moved from nrnoc to oc + * list.cpp hoclist.h moved from nrnoc to oc * all templates maintain a list of their objects * * Revision 1.112 92/10/27 09:17:48 hines @@ -526,11 +526,11 @@ NEURON 5.3 2002/06/04 * error in stub for xpvalue() * * Revision 1.108 92/10/24 10:17:49 hines - * botched last checkin for symbol.c. notifies interviews when hoc_free_val.. + * botched last checkin for symbol.cpp. notifies interviews when hoc_free_val.. * called * * Revision 1.107 92/10/24 10:16:35 hines - * noiv.c is place to put function stubs that only make sense with interviews + * noiv.cpp is place to put function stubs that only make sense with interviews * whenever any VAR is freed it should be done with hoc_free_val... which * will notify the interviews objects that hold pointers to variables. * @@ -545,7 +545,7 @@ NEURON 5.3 2002/06/04 * * Revision 1.104 92/10/22 12:33:21 hines * for debugging there is a list of all objects (#define OBLIST 1) - * that can be printed. This list is turned off in hoc_oop.c + * that can be printed. This list is turned off in hoc_oop.cpp * * Revision 1.103 92/10/22 09:49:17 hines * ob.sec syntax must always do a poptypestack at end. @@ -571,7 +571,7 @@ NEURON 5.3 2002/06/04 * hoc_argtype(i) returns the type of the ith arg. * * Revision 1.98 92/10/14 10:10:25 hines - * move oc specific stuff out of axis.c and into code2.c + * move oc specific stuff out of axis.cpp and into code2.cpp * new argument function hoc_pgetarg checks for double pointer on stack * and returns it. * hoc_val_pointer(string) returns a pointer to the variable resulting @@ -701,12 +701,12 @@ NEURON 5.3 2002/06/04 * hoc_returning. * This was done so init... could be called both from hoc_spinit and from * hoc. - * last function called by hoc_spinit in hocusr.c is hoc_last_init() + * last function called by hoc_spinit in hocusr.cpp is hoc_last_init() * * Revision 1.70 92/08/12 10:45:42 hines * Changes of sejnowski lab. also gets sred from hoc. Major addition is - * a new x.c which is modified for screen updating following an expose - * event. This is in x_sejnowski.c and will compile to x.o when + * a new x.cpp which is modified for screen updating following an expose + * event. This is in x_sejnowski.cpp and will compile to x.o when * Sejnowski is defined as 1 in Imakefile (don't forget imknrn -a when * changed and delete old x.o) * Does not contain get_default on this checkin @@ -755,7 +755,7 @@ NEURON 5.3 2002/06/04 * * * Revision 1.59 92/07/31 14:34:57 hines - * avoid saber warning with hoc_xpop not declared double in nocable.c + * avoid saber warning with hoc_xpop not declared double in nocable.cpp * * Revision 1.58 92/07/31 14:17:04 hines * better handling of errno as in hoc @@ -788,7 +788,7 @@ NEURON 5.3 2002/06/04 * ecalloc returns 0 when requesting 0 space. (now matches hoc) * * Revision 1.51 92/07/31 08:33:45 hines - * failed to checkin code2.c when chkarg got moved there + * failed to checkin code2.cpp when chkarg got moved there * * Revision 1.50 92/07/31 08:32:16 hines * C interface objects see the top level symbol table @@ -797,7 +797,7 @@ NEURON 5.3 2002/06/04 * remove the old newgraph stuff * * Revision 1.48 92/07/07 09:50:05 hines - * chkarg moved to code2.c so always available + * chkarg moved to code2.cpp so always available * * Revision 1.47 92/07/06 16:13:38 hines * good start with interfacing c++ objects so they are callable from oc @@ -841,7 +841,7 @@ NEURON 5.3 2002/06/04 * doEvents() will execute InterViews events if any. * * Revision 1.37 92/03/11 13:56:13 hines - * hoc.c inadvertently checked in last time with sigsegvec removed + * hoc.cpp inadvertently checked in last time with sigsegvec removed * * Revision 1.36 92/03/11 13:53:56 hines * all parse errors now hoc_execerror @@ -901,7 +901,7 @@ NEURON 5.3 2002/06/04 * Ready now to make oc event driven. * * Revision 1.21 92/01/30 11:05:12 hines - * leave out an xflush in x.c so doesn't hang. error in cable part of code.c + * leave out an xflush in x.cpp so doesn't hang. error in cable part of code.cpp * found by codecenter. "if (a=b) instead of if(a == b)" * Imakefile invokes ObjectOrientedHoc * @@ -947,7 +947,7 @@ NEURON 5.3 2002/06/04 * Revision 1.9 91/10/24 16:22:11 hines * can call object functions and procedures. Object arrays not working yet. * object_id(obj) is used for tests. - * STKDEBUG turned on in code.c in which every element also carries a type. + * STKDEBUG turned on in code.cpp in which every element also carries a type. * * Revision 1.8 91/10/22 15:47:17 hines * objects and components. can assign, evaluate, and print. diff --git a/src/oc/x.c b/src/oc/x.cpp similarity index 100% rename from src/oc/x.c rename to src/oc/x.cpp diff --git a/src/oc/xred.c b/src/oc/xred.cpp similarity index 94% rename from src/oc/xred.c rename to src/oc/xred.cpp index 30d9f5e181..2c9b077478 100755 --- a/src/oc/xred.c +++ b/src/oc/xred.cpp @@ -1,7 +1,7 @@ #include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/xred.c,v 1.3 1996/02/16 16:19:33 hines Exp */ +/* /local/src/master/nrn/src/oc/xred.cpp,v 1.3 1996/02/16 16:19:33 hines Exp */ /* -xred.c,v +xred.cpp,v * Revision 1.3 1996/02/16 16:19:33 hines * OCSMALL used to throw out things not needed by teaching programs * @@ -24,8 +24,8 @@ xred.c,v * * Revision 1.2 92/08/12 10:45:40 hines * Changes of sejnowski lab. also gets sred from hoc. Major addition is - * a new x.c which is modified for screen updating following an expose - * event. This is in x_sejnowski.c and will compile to x.o when + * a new x.cpp which is modified for screen updating following an expose + * event. This is in x_sejnowski.cpp and will compile to x.o when * Sejnowski is defined as 1 in Imakefile (don't forget imknrn -a when * changed and delete old x.o) * Does not contain get_default on this checkin @@ -50,6 +50,7 @@ xred.c,v #include "hoc.h" + /* input a n integer in range > min and < max */ int ired(const char* prompt, int defalt, int min, int max) { @@ -98,7 +99,7 @@ return 0.; } -/* hoc_Sred.c SW Jaslove March 23, 1992 +/* hoc_Sred.cpp SW Jaslove March 23, 1992 This is the hoc interface for the sred() function, which follows. */ @@ -118,7 +119,7 @@ void hoc_Sred(void) { } #if !OCSMALL -/* sred.c SW Jaslove March 23, 1992 +/* sred.cpp SW Jaslove March 23, 1992 n = sred(prompt,default,charlist) Outputs a prompt and inputs a string which MUST be a member of charlist. If default exists: default is returned if user types RETURN key only. @@ -193,3 +194,4 @@ strstr(cs, ct) } #endif #endif + diff --git a/src/parallel/Makefile.am b/src/parallel/Makefile.am index c0a22bcf0a..08bca26c1e 100755 --- a/src/parallel/Makefile.am +++ b/src/parallel/Makefile.am @@ -1,4 +1,4 @@ -# This makefile does nothing except to copy some .c and .h files into +# This makefile does nothing except to copy some .cpp and .h files into # the distribution tar file. EXTRA_DIST = bbs.cpp bbs.h bbsdirect.h bbsimpl.h \ diff --git a/src/parallel/bbs.cpp b/src/parallel/bbs.cpp index c7985fb234..eea464d974 100644 --- a/src/parallel/bbs.cpp +++ b/src/parallel/bbs.cpp @@ -20,10 +20,8 @@ static struct tms tmsbuf, tms_start_; static clock_t starttime; #endif -extern "C" { - extern int nrn_global_argc; - extern char** nrn_global_argv; -}; +extern int nrn_global_argc; +extern char** nrn_global_argv; bool BBSImpl::is_master_ = false; bool BBSImpl::started_ = false; @@ -280,7 +278,7 @@ void BBS::pkpickle(const char* s, size_t n) { // value of this call is the id of the task that computed the return. #endif -// BBSImpl::execute_helper() in ocbbs.c +// BBSImpl::execute_helper() in ocbbs.cpp void BBSImpl::execute(int id) { // assumes a "_todo" message in receive buffer ++etaskcnt; diff --git a/src/parallel/bbsclimpi.cpp b/src/parallel/bbsclimpi.cpp index 2975e5a658..3c73a37bdc 100644 --- a/src/parallel/bbsclimpi.cpp +++ b/src/parallel/bbsclimpi.cpp @@ -13,9 +13,7 @@ #include "bbsrcli.h" #include "bbssrv.h" -extern "C" { extern void nrnmpi_int_broadcast(int*, int, int); -} #define debug 0 diff --git a/src/parallel/bbsdirectmpi.cpp b/src/parallel/bbsdirectmpi.cpp index a127a89a17..996446de26 100644 --- a/src/parallel/bbsdirectmpi.cpp +++ b/src/parallel/bbsdirectmpi.cpp @@ -12,9 +12,7 @@ #include "bbssrv2mpi.h" #include "bbssrv.h" -extern "C" { extern void nrnmpi_int_broadcast(int*, int, int); -} #if defined(HAVE_STL) #if defined(HAVE_SSTREAM) // the standard ... diff --git a/src/parallel/bbsimpl.h b/src/parallel/bbsimpl.h index 16585f3338..11fcf17f92 100644 --- a/src/parallel/bbsimpl.h +++ b/src/parallel/bbsimpl.h @@ -62,7 +62,7 @@ class BBSImpl { static int debug_; static bool master_works_; protected: - char* execute_helper(size_t*, int id, bool exec=true); // involves hoc specific details in ocbbs.c + char* execute_helper(size_t*, int id, bool exec=true); // involves hoc specific details in ocbbs.cpp void subworld_worker_execute(); //shadows execute_helper. ie. each of // the nrnmpi_myid_bbs workers (and master) need to execute // the same thing on each of the subworld processes diff --git a/src/parallel/bbslsrv.cpp b/src/parallel/bbslsrv.cpp index 1628ea715b..65b7f24bbd 100644 --- a/src/parallel/bbslsrv.cpp +++ b/src/parallel/bbslsrv.cpp @@ -103,7 +103,9 @@ class MessageList {}; class WorkList {}; class ReadyList{}; class ResultList{}; -extern "C" { extern void hoc_execerror(const char*, const char*);} +extern "C" { + extern void hoc_execerror(const char*, const char*); +} // extern "C" static void nostl() { hoc_execerror("BBSLocalServer not working", "Compiled without STL"); } diff --git a/src/parallel/bbslsrv2.h b/src/parallel/bbslsrv2.h index 0eb3af384b..65b05fd0d8 100644 --- a/src/parallel/bbslsrv2.h +++ b/src/parallel/bbslsrv2.h @@ -3,9 +3,7 @@ #include -extern "C" { - void bbs_handle(); -} +void bbs_handle(); class BBSDirectServer { public: diff --git a/src/parallel/bbssrv2mpi.cpp b/src/parallel/bbssrv2mpi.cpp index 7ae2b565a3..27a2ce3585 100644 --- a/src/parallel/bbssrv2mpi.cpp +++ b/src/parallel/bbssrv2mpi.cpp @@ -10,9 +10,7 @@ #include "bbsimpl.h" #include "hocdec.h" //Printf -extern "C" { - void nrnbbs_context_wait(); -}; +void nrnbbs_context_wait(); BBSDirectServer* BBSDirectServer::server_; diff --git a/src/parallel/bbssrv2mpi.h b/src/parallel/bbssrv2mpi.h index fcc1bd39ba..5df994d784 100644 --- a/src/parallel/bbssrv2mpi.h +++ b/src/parallel/bbssrv2mpi.h @@ -12,9 +12,7 @@ class MpiLookingToDoList; class MpiResultList; struct bbsmpibuf; -extern "C" { - void bbs_handle(); -} +void bbs_handle(); class BBSDirectServer { public: diff --git a/src/parallel/bbssrvmpi.cpp b/src/parallel/bbssrvmpi.cpp index c71c9cb2d8..8bb1d5de5d 100755 --- a/src/parallel/bbssrvmpi.cpp +++ b/src/parallel/bbssrvmpi.cpp @@ -10,11 +10,9 @@ #define debug 0 #define POLLCNT 300 -extern "C" { - extern int bbs_poll_; - void bbs_handle(); - extern double hoc_cross_x_; -} +extern int bbs_poll_; +void bbs_handle(); +extern double hoc_cross_x_; static int bbs_poll_cnt_; static int bbs_msg_cnt_; @@ -208,8 +206,6 @@ printf("unknown message\n"); nrnmpi_unref(recv); } #else -extern "C" { void bbs_handle(){} -} #endif //NRNMPI diff --git a/src/parallel/ocbbs.cpp b/src/parallel/ocbbs.cpp index 7e52d379d7..42611dd57c 100644 --- a/src/parallel/ocbbs.cpp +++ b/src/parallel/ocbbs.cpp @@ -17,9 +17,8 @@ #undef MD #define MD 2147483647. -extern "C" int hoc_return_type_code; +extern int hoc_return_type_code; -extern "C" { extern int vector_arg_px(int, double**); Symbol* hoc_which_template(Symbol*); void bbs_done(); @@ -46,6 +45,7 @@ extern "C" { double nrnmpi_splitcell_wait_; #endif #if NRNMPI +extern "C" { void nrnmpi_barrier(); double nrnmpi_dbl_allreduce(double, int); void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type); @@ -57,6 +57,7 @@ extern "C" { void nrnmpi_char_broadcast(char*, int, int); void nrnmpi_dbl_broadcast(double*, int, int); extern void nrnmpi_subworld_size(int n); +} // extern "C" #else static void nrnmpi_int_broadcast(int*, int, int){} static void nrnmpi_char_broadcast(char*, int, int){} @@ -75,7 +76,6 @@ extern "C" { extern bool nrn_trajectory_request_per_time_step_; extern int nrncore_is_enabled(); extern int nrncore_psolve(double tstop); -} class OcBBS : public BBS , public Resource { public: diff --git a/src/parallel/subworld.cpp b/src/parallel/subworld.cpp index fc869699de..9790bc0ac1 100644 --- a/src/parallel/subworld.cpp +++ b/src/parallel/subworld.cpp @@ -4,7 +4,7 @@ void BBSImpl::subworld_worker_execute() { // execute the same thing that execute_worker is executing. This // is done for all the nrnmpi_myid_bbs == -1 workers associated with // the specific nrnmpi_myid == 0 with nrnmpi_myid_bbs >= 0. - // All the nrnmpi/mpispike.c functions can be used since the + // All the nrnmpi/mpispike.cpp functions can be used since the // proper communicators for a subworld are used by those functions. // The broadcast functions are particularly useful and those are // how execute_worker passes messages into here. diff --git a/src/scopmath/newton_struct.h b/src/scopmath/newton_struct.h index d5b1ad63f0..12f26c3d0e 100644 --- a/src/scopmath/newton_struct.h +++ b/src/scopmath/newton_struct.h @@ -1,5 +1,7 @@ #ifndef newton_struct_h #define newton_struct_h + +#include /* avoid incessant alloc/free memory */ typedef struct NewtonSpace { int n; @@ -14,7 +16,7 @@ typedef struct NewtonSpace { typedef int (*FUN)(double*, void*, void*, void*); -extern void* hoc_Emalloc(unsigned long); +extern void* hoc_Emalloc(size_t); extern void hoc_malchk(); #define emalloc(arg) hoc_Emalloc(arg); hoc_malchk() extern int freevector(); diff --git a/src/scopmath/newton_thread.c b/src/scopmath/newton_thread.c index 6eb16dcc3b..47bc8686a3 100755 --- a/src/scopmath/newton_thread.c +++ b/src/scopmath/newton_thread.c @@ -256,5 +256,5 @@ void nrn_destroy_newtonspace(NewtonSpace* ns) { freevector(ns->high_value); freevector(ns->low_value); freevector(ns->rowmax); - free ((char*) ns); + free ( ns); } diff --git a/src/scopmath/praxis.c b/src/scopmath/praxis.c index a76059fdb7..779fc7d17f 100644 --- a/src/scopmath/praxis.c +++ b/src/scopmath/praxis.c @@ -86,7 +86,7 @@ static doublereal* d_, *d_hoc; static int praxstep = 0; /* if n returns after n iterations of main loop */ -double praxis_pval(i) int i; { +double praxis_pval(int i) { if (d_hoc) { if (i >= q_hoc->size || i < 0) { hoc_execerror("arg out of range", (char*)0); @@ -97,7 +97,7 @@ double praxis_pval(i) int i; { } return 0.; } -double* praxis_paxis(i) int i; { +double* praxis_paxis(int i) { if (q_hoc) { if (i >= q_hoc->size || i < 0) { hoc_execerror("arg out of range", (char*)0); diff --git a/src/scopmath/simeq.c b/src/scopmath/simeq.c index e554d08492..81b2926ece 100755 --- a/src/scopmath/simeq.c +++ b/src/scopmath/simeq.c @@ -56,7 +56,7 @@ double *coef[], soln[]; /* Create and initialize permutation vector */ if (np < n) { if (perm) { - free((char*)perm); + free(perm); } perm = (int *) malloc((unsigned) (n * sizeof(int))); np = n; diff --git a/src/sparse/bksub.c b/src/sparse/bksub.cpp old mode 100755 new mode 100644 similarity index 100% rename from src/sparse/bksub.c rename to src/sparse/bksub.cpp diff --git a/src/sparse/getelm.c b/src/sparse/getelm.cpp old mode 100755 new mode 100644 similarity index 50% rename from src/sparse/getelm.c rename to src/sparse/getelm.cpp index 6d3670c787..85e1518b06 --- a/src/sparse/getelm.c +++ b/src/sparse/getelm.cpp @@ -8,7 +8,7 @@ struct elm* getelm(struct elm* el, unsigned row, unsigned col) /* return pointer to row col element maintaining order in rows */ { - register struct elm *new; + struct elm *new_elem; if (el == ELM0) el = rowst[row]; @@ -24,34 +24,34 @@ struct elm* getelm(struct elm* el, unsigned row, unsigned col) return(el); } - if ( (new = (struct elm *)malloc(sizeof(struct elm))) == + if ( (new_elem = (struct elm *)malloc(sizeof(struct elm))) == (struct elm *)0) diag("out of space for elements"); - new->row = row; - new->col = col; - new->value = 0.; + new_elem->row = row; + new_elem->col = col; + new_elem->value = 0.; { - new->r_up = ELM0; /* place new element first in column list */ - new->r_down = colst[col]; - if (colst[col] != ELM0) - colst[col]->r_up = new; - colst[col] = new; + new_elem->r_up = ELM0; /* place new element first in column list */ + new_elem->r_down = colst[col]; + if (colst[col] != ELM0) + colst[col]->r_up = new_elem; + colst[col] = new_elem; } if (el == ELM0) /* the new elm belongs at the beginning */ { /* of the row list */ - new->c_left = ELM0; - new->c_right = rowst[row]; + new_elem->c_left = ELM0; + new_elem->c_right = rowst[row]; if (rowst[row] != ELM0) - rowst[row]->c_left = new; - rowst[row] = new; + rowst[row]->c_left = new_elem; + rowst[row] = new_elem; } else /* the new elm belongs after el */ { - new->c_left = el; - new->c_right = el->c_right; - el->c_right = new; - if (new->c_right != ELM0) - new->c_right->c_left = new; + new_elem->c_left = el; + new_elem->c_right = el->c_right; + el->c_right = new_elem; + if (new_elem->c_right != ELM0) + new_elem->c_right->c_left = new_elem; } - return(new); + return(new_elem); } diff --git a/src/sparse/lineq.c b/src/sparse/lineq.cpp old mode 100755 new mode 100644 similarity index 100% rename from src/sparse/lineq.c rename to src/sparse/lineq.cpp diff --git a/src/sparse/prmat.c b/src/sparse/prmat.cpp old mode 100755 new mode 100644 similarity index 100% rename from src/sparse/prmat.c rename to src/sparse/prmat.cpp diff --git a/src/sparse/subrows.c b/src/sparse/subrows.cpp old mode 100755 new mode 100644 similarity index 100% rename from src/sparse/subrows.c rename to src/sparse/subrows.cpp diff --git a/src/sparse13/cspalloc.c b/src/sparse13/cspalloc.c old mode 100755 new mode 100644 diff --git a/src/sparse13/cspbuild.c b/src/sparse13/cspbuild.c old mode 100755 new mode 100644 diff --git a/src/sparse13/cspfactor.c b/src/sparse13/cspfactor.c old mode 100755 new mode 100644 diff --git a/src/sparse13/cspoutput.c b/src/sparse13/cspoutput.c old mode 100755 new mode 100644 diff --git a/src/sparse13/cspsolve.c b/src/sparse13/cspsolve.c old mode 100755 new mode 100644 diff --git a/src/sparse13/csputils.c b/src/sparse13/csputils.c old mode 100755 new mode 100644 diff --git a/src/sparse13/spalloc.c b/src/sparse13/spalloc.c old mode 100755 new mode 100644 diff --git a/src/sparse13/spbuild.c b/src/sparse13/spbuild.c old mode 100755 new mode 100644 diff --git a/src/sparse13/spfactor.c b/src/sparse13/spfactor.c old mode 100755 new mode 100644 diff --git a/src/sparse13/spmatrix.h b/src/sparse13/spmatrix.h index a22fddf629..c4267d3f9f 100755 --- a/src/sparse13/spmatrix.h +++ b/src/sparse13/spmatrix.h @@ -50,7 +50,9 @@ #include "spconfig.h" - +#ifdef __cplusplus +extern "C" { +#endif @@ -338,7 +340,7 @@ extern int spFileStats(); extern int spFileVector(); extern int spFillinCount(); extern int spGetAdmittance(); -extern spREAL *spGetElement(); +extern spREAL *spGetElement(char*, int, int); extern char *spGetInitInfo(); extern int spGetOnes(); extern int spGetQuad(); @@ -364,4 +366,8 @@ extern void spStripFills(); extern void spWhereSingular(); #endif /* defined(__STDC__) */ -#endif /* spOKAY */ +#ifdef __cplusplus +} +#endif + +#endif /* spOKAY */ \ No newline at end of file diff --git a/src/sparse13/spoutput.c b/src/sparse13/spoutput.c old mode 100755 new mode 100644 diff --git a/src/sparse13/spsolve.c b/src/sparse13/spsolve.c old mode 100755 new mode 100644 diff --git a/src/sparse13/sputils.c b/src/sparse13/sputils.c old mode 100755 new mode 100644 diff --git a/src/sundials/shared/nvector_parallel.c b/src/sundials/shared/nvector_parallel.c index 19c3c05c01..420e1637bc 100755 --- a/src/sundials/shared/nvector_parallel.c +++ b/src/sundials/shared/nvector_parallel.c @@ -22,8 +22,8 @@ /* for NRNMPI_DYNAMICLOAD */ #include #if NRNMPI_DYNAMICLOAD -extern void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type); -extern void nrnmpi_long_allreduce_vec(long* src, long* dest, int cnt, int type); +extern /*"C"*/ void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type); +extern /*"C"*/ void nrnmpi_long_allreduce_vec(long* src, long* dest, int cnt, int type); extern int nrnmpi_numprocs; #endif diff --git a/src/sundials/shared/nvector_parallel.h b/src/sundials/shared/nvector_parallel.h index 4c60f5965e..9e0ccc688f 100755 --- a/src/sundials/shared/nvector_parallel.h +++ b/src/sundials/shared/nvector_parallel.h @@ -49,11 +49,6 @@ #ifndef _NVECTOR_PARALLEL_H #define _NVECTOR_PARALLEL_H -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -#include #if NRNMPI_DYNAMICLOAD #define MPI_DOUBLE double #define MPI_LONG long @@ -62,6 +57,10 @@ extern "C" { #include #endif +#if defined(__cplusplus) +extern "C" { +#endif + #include "nvector.h" #include "sundialstypes.h" @@ -332,8 +331,8 @@ booleantype N_VInvTest_Parallel(N_Vector x, N_Vector z); booleantype N_VConstrMask_Parallel(N_Vector c, N_Vector x, N_Vector m); realtype N_VMinQuotient_Parallel(N_Vector num, N_Vector denom); -#ifdef __cplusplus -} +#if defined(__cplusplus) +} // extern "C" #endif #endif diff --git a/src/uxnrnbbs/nrnbbs.cpp b/src/uxnrnbbs/nrnbbs.cpp index 41f133df6f..ee0ff6fe8a 100644 --- a/src/uxnrnbbs/nrnbbs.cpp +++ b/src/uxnrnbbs/nrnbbs.cpp @@ -13,7 +13,7 @@ #include #include -//extern "C" { extern int mkdir(const char*, int); } +extern "C" { extern int mkdir(const char*, int); } #include #include diff --git a/src/uxnrnbbs/nrnbbs.h b/src/uxnrnbbs/nrnbbs.h index 1fd6d50bf2..ef69be54f8 100644 --- a/src/uxnrnbbs/nrnbbs.h +++ b/src/uxnrnbbs/nrnbbs.h @@ -3,9 +3,6 @@ typedef void (*NrnBBSCallback)(const char*); -#if defined(__cplusplus) -extern "C" { -#endif bool nrnbbs_connect(); void nrnbbs_disconnect(); bool nrnbbs_connected(); @@ -35,7 +32,4 @@ int nrnbbs_count(); bool nrnbbs_query(long index); #endif -#if defined(__cplusplus) -} -#endif #endif diff --git a/test/unit_tests/oc/hoc_interpreter.cpp b/test/unit_tests/oc/hoc_interpreter.cpp index 081d5cbe7f..78fc703e10 100644 --- a/test/unit_tests/oc/hoc_interpreter.cpp +++ b/test/unit_tests/oc/hoc_interpreter.cpp @@ -1,10 +1,10 @@ #include -extern "C" { +//extern "C" { #include #include #include -} +//} // extern "C TEST_CASE("Test hoc interpreter", "[Neuron][hoc_interpreter]") { hoc_init_space(); diff --git a/test/unit_tests/unit_test.cpp b/test/unit_tests/unit_test.cpp index 12145d8dbb..5da8ce51f5 100644 --- a/test/unit_tests/unit_test.cpp +++ b/test/unit_tests/unit_test.cpp @@ -2,7 +2,7 @@ #include -extern "C" { +//extern "C" { #include #include #include @@ -10,11 +10,11 @@ extern "C" { extern void nrn_threads_create(int, int); extern void nrn_threads_free(); -extern int ivocmain_session(int, char**, char**, int); +extern int ivocmain_session(int, const char**, const char**, int); extern int nrn_main_launch; extern int nrn_nobanner_; -} +//} // extern "C" /// Needed for compilation void modl_reg() { } @@ -31,7 +31,7 @@ int main( int argc, char* argv[] ) { const char* argv_nompi[] = {"NEURON", "-nogui"}; nrn_nobanner_ = 1; - ivocmain_session(argc_nompi, (char **) &argv_nompi, NULL, 0); + ivocmain_session(argc_nompi, argv_nompi, NULL, 0); #undef run int result = Catch::Session().run( argc, argv ); #define run hoc_run From 8e871a0068eed6b516cbf00ec076d5ab288add64 Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Mon, 12 Oct 2020 16:41:23 +0200 Subject: [PATCH 02/17] autotools cpp update autotools cpp update: linux --- .gitignore | 8 +- docs/dev/HOCInterpreter/HOCInterpreter.md | 4 +- src/ivoc/checkpnt.cpp | 2 +- src/ivoc/datapath.cpp | 2 +- src/ivoc/ivocvect.cpp | 2 +- src/ivoc/matrix.cpp | 2 +- src/ivoc/oc2iv.cpp | 2 +- src/ivoc/oclist.cpp | 2 +- src/ivoc/ocpointer.cpp | 2 +- src/ivoc/strfun.cpp | 2 +- src/ivoc/symchoos.cpp | 2 +- src/ivoc/symdir.cpp | 2 +- src/ivoc/xmenu.cpp | 2 +- src/memacs/redef.h | 3 +- src/memacs/termio.c | 2 +- src/modlunit/Makefile.am | 17 +- src/modlunit/consist.cpp | 2 +- src/modlunit/declare.cpp | 2 +- src/modlunit/init.cpp | 6 +- src/modlunit/io.cpp | 2 +- src/modlunit/kinunit.cpp | 2 +- src/modlunit/{lex.l => lex.lpp} | 2 +- src/modlunit/list.cpp | 2 +- src/modlunit/model.cpp | 2 +- src/modlunit/model.h | 2 +- src/modlunit/modlunit.h | 4 +- src/modlunit/nrnunit.cpp | 2 +- src/modlunit/{parse1.y => parse1.ypp} | 4 +- src/modlunit/passn.cpp | 2 +- src/modlunit/symbol.cpp | 2 +- src/modlunit/units1.cpp | 2 +- src/nmodl/Makefile.am | 19 +- src/nmodl/consist.cpp | 2 +- src/nmodl/cout.cpp | 4 +- src/nmodl/deriv.cpp | 4 +- src/nmodl/{diffeq.y => diffeq.ypp} | 0 src/nmodl/discrete.cpp | 2 +- src/nmodl/init.cpp | 2 +- src/nmodl/io.cpp | 2 +- src/nmodl/kinetic.cpp | 2 +- src/nmodl/{lex.l => lex.lpp} | 4 +- src/nmodl/list.cpp | 2 +- src/nmodl/modl.h | 2 +- src/nmodl/netrec_discon.cpp | 2 +- src/nmodl/nmodlfunc.h | 4 +- src/nmodl/noccout.cpp | 2 +- src/nmodl/nocpout.cpp | 2 +- src/nmodl/parsact.cpp | 6 +- src/nmodl/{parse1.y => parse1.ypp} | 2 +- src/nmodl/partial.cpp | 2 +- src/nmodl/sens.cpp | 2 +- src/nmodl/simultan.cpp | 2 +- src/nmodl/solve.cpp | 2 +- src/nmodl/symbol.cpp | 2 +- src/nmodl/version.cpp | 4 +- src/nrncvode/netcvode.cpp | 2 +- src/nrniv/CMakeLists.txt | 22 +- src/nrniv/cachevec.cpp | 2 +- src/nrniv/hocmech.cpp | 2 +- src/nrniv/kschan.cpp | 2 +- src/nrniv/ndatclas.cpp | 2 +- src/nrniv/nrncore_write.cpp | 2 +- .../callbacks/nrncore_callbacks.cpp | 2 +- src/nrniv/nrncore_write/data/cell_group.cpp | 2 +- .../nrncore_write/utils/nrncore_utils.cpp | 2 +- src/nrniv/nrnmenu.cpp | 2 +- src/nrniv/nrnrtime.cpp | 2 +- src/nrniv/pysecname2sec.cpp | 2 +- src/nrniv/shape.cpp | 2 +- src/nrniv/shapeplt.cpp | 2 +- src/nrnjava/nrnjava.cpp | 2 +- src/nrnjava/nrnjni.cpp | 2 +- src/nrnmpi/Makefile.am | 6 +- src/nrnmpi/nrnmpi_impl.h | 6 +- src/nrnoc/Makefile.am | 16 +- src/nrnoc/cabcode.cpp | 2 +- src/nrnoc/eion.cpp | 2 +- src/nrnoc/hocprax.cpp | 2 +- src/nrnoc/hocusr.h | 1 - src/nrnoc/init.cpp | 2 +- src/nrnoc/ldifus.cpp | 2 +- src/nrnoc/method3.cpp | 2 +- src/nrnoc/nrnnoiv.cpp | 44 +- src/nrnoc/point.cpp | 2 +- src/nrnoc/psection.cpp | 2 +- src/nrnoc/seclist.cpp | 2 +- src/nrnoc/secref.cpp | 2 +- src/nrnoc/treeset.cpp | 2 +- src/nrnpython/nrnpy_hoc.cpp | 2 +- src/nrnpython/nrnpy_nrn.cpp | 2 +- src/nrnpython/nrnpy_p2h.cpp | 2 +- src/nrnpython/rxdmath.cpp | 10 +- src/oc/Makefile.am | 22 +- src/oc/code.cpp | 34 +- src/oc/code2.cpp | 2 +- src/oc/fileio.cpp | 2 +- src/oc/getsym.cpp | 2 +- src/oc/hoc.cpp | 4 +- src/oc/hoc_init.cpp | 2 +- src/oc/hoc_oop.cpp | 2 +- src/oc/hocmodl.h | 2 +- src/oc/hocparse.h | 2 +- src/oc/hocusr.cpp | 4 +- src/oc/list.cpp | 2 +- src/oc/mk_hocusr_h.py | 2 +- src/oc/nonlin.cpp | 2 +- src/oc/oc_ansi.h | 3 +- src/oc/ocmain.cpp | 2 +- src/oc/ocnoiv.cpp | 53 +- src/oc/parallel.cpp | 2 +- src/oc/{parse.y => parse.ypp} | 0 src/oc/spinit.cpp | 2 +- src/oc/symbol.cpp | 2 +- src/oc/version.cpp | 2 +- src/parallel/ocbbs.cpp | 2 +- src/readline/history.c | 7 +- src/readline/readline.c | 6352 +++++++++-------- 117 files changed, 3449 insertions(+), 3398 deletions(-) rename src/modlunit/{lex.l => lex.lpp} (99%) rename src/modlunit/{parse1.y => parse1.ypp} (99%) rename src/nmodl/{diffeq.y => diffeq.ypp} (100%) rename src/nmodl/{lex.l => lex.lpp} (98%) rename src/nmodl/{parse1.y => parse1.ypp} (99%) rename src/oc/{parse.y => parse.ypp} (100%) diff --git a/.gitignore b/.gitignore index 77a1e63aa2..e3aed50ce7 100644 --- a/.gitignore +++ b/.gitignore @@ -14,18 +14,20 @@ x86_64 __pycache__ venv virtualenv +*.o +*.lo # These files are generated at build time # It would be a good idea to create them in the # build directory in the future. src/modlunit/lex.cpp src/modlunit/parse1.cpp -src/modlunit/parse1.h +src/modlunit/parse1.hpp src/nmodl/diffeq.cpp src/nmodl/diffeq.h src/nmodl/lex.cpp src/nmodl/parse1.cpp -src/nmodl/parse1.h +src/nmodl/parse1.hpp src/nrnoc/apcount.c src/nrnoc/exp2syn.c src/nrnoc/expsyn.c @@ -47,4 +49,4 @@ src/nrnoc/svclmp.c src/nrnoc/syn.c src/nrnoc/vclmp.c src/oc/parse.cpp -src/oc/parse.h +src/oc/parse.hpp diff --git a/docs/dev/HOCInterpreter/HOCInterpreter.md b/docs/dev/HOCInterpreter/HOCInterpreter.md index 8f758cd5b4..3db3eb3f9d 100644 --- a/docs/dev/HOCInterpreter/HOCInterpreter.md +++ b/docs/dev/HOCInterpreter/HOCInterpreter.md @@ -62,7 +62,7 @@ This will call '**ivocmain\_session()**' with parameter **'start\_session'** set With respect to the HOC grammar we have: -* **'src/oc/parse.y' →** HOC language is defined thanks to **bison/yacc;** this file holds actual HOC grammar +* **'src/oc/parse.ypp' →** HOC language is defined thanks to **bison/yacc;** this file holds actual HOC grammar The grammar consists of token definitions, left-right precedence setup, grammar rules (i.e. expressions like assignments) and actions; these actions represent code blocks triggered when rules have been recognised. @@ -355,7 +355,7 @@ When a function (or even a procedure) is called we have: ![](images/58791210.png) -How does this map to _**parse.y**_ grammar? Corresponding part is : +How does this map to _**parse.ypp**_ grammar? Corresponding part is : expr: diff --git a/src/ivoc/checkpnt.cpp b/src/ivoc/checkpnt.cpp index f016a2df7d..e25d779e23 100644 --- a/src/ivoc/checkpnt.cpp +++ b/src/ivoc/checkpnt.cpp @@ -101,7 +101,7 @@ data depending on type. eg for VAR && NOTUSER it is #include "redef.h" #include "hoclist.h" -#include "parse.h" +#include "parse.hpp" #include "code.h" #include "equation.h" int hoc_readcheckpoint(char*); diff --git a/src/ivoc/datapath.cpp b/src/ivoc/datapath.cpp index 851f5dd85b..2c67112a62 100644 --- a/src/ivoc/datapath.cpp +++ b/src/ivoc/datapath.cpp @@ -42,7 +42,7 @@ struct DLL* dll_load(const char*){return NULL;} #include "oc2iv.h" #endif -#include "parse.h" +#include "parse.hpp" extern Symlist* hoc_built_in_symlist; extern Symlist* hoc_top_level_symlist; extern Objectdata* hoc_top_level_data; diff --git a/src/ivoc/ivocvect.cpp b/src/ivoc/ivocvect.cpp index 03c7d54ca1..eaa56881f9 100644 --- a/src/ivoc/ivocvect.cpp +++ b/src/ivoc/ivocvect.cpp @@ -99,7 +99,7 @@ static double dmaxint_; #include "utility.h" #endif #include "oc2iv.h" -#include "parse.h" +#include "parse.hpp" #include "ocfile.h" extern Object* hoc_thisobject; diff --git a/src/ivoc/matrix.cpp b/src/ivoc/matrix.cpp index e55381dd91..678a64184d 100644 --- a/src/ivoc/matrix.cpp +++ b/src/ivoc/matrix.cpp @@ -5,7 +5,7 @@ #include #include "ocmatrix.h" #include "oc2iv.h" -#include "parse.h" +#include "parse.hpp" #include "ivocvect.h" #define EPS hoc_epsilon diff --git a/src/ivoc/oc2iv.cpp b/src/ivoc/oc2iv.cpp index 6263a8002c..074b2e0445 100644 --- a/src/ivoc/oc2iv.cpp +++ b/src/ivoc/oc2iv.cpp @@ -5,7 +5,7 @@ #include "oc2iv.h" #include "ocpointer.h" -#include "parse.h" +#include "parse.hpp" extern Symlist* hoc_top_level_symlist; extern Objectdata *hoc_top_level_data; extern Object* hoc_thisobject; diff --git a/src/ivoc/oclist.cpp b/src/ivoc/oclist.cpp index 2962718bf9..6b66a0021f 100644 --- a/src/ivoc/oclist.cpp +++ b/src/ivoc/oclist.cpp @@ -25,7 +25,7 @@ #include "gui-redirect.h" -#include "parse.h" +#include "parse.hpp" extern Object** hoc_temp_objptr(Object*); extern Symlist* hoc_top_level_symlist; int ivoc_list_count(Object*); diff --git a/src/ivoc/ocpointer.cpp b/src/ivoc/ocpointer.cpp index 43eae37642..693f83ce84 100644 --- a/src/ivoc/ocpointer.cpp +++ b/src/ivoc/ocpointer.cpp @@ -15,7 +15,7 @@ #include "classreg.h" #include "oc2iv.h" #include "ocpointer.h" -#include "parse.h" +#include "parse.hpp" #include "ocnotify.h" #if HAVE_IV diff --git a/src/ivoc/strfun.cpp b/src/ivoc/strfun.cpp index fa158e7815..8e56af0160 100644 --- a/src/ivoc/strfun.cpp +++ b/src/ivoc/strfun.cpp @@ -9,7 +9,7 @@ // for alias #include #include -#include +#include // for references #include #if HAVE_IV diff --git a/src/ivoc/symchoos.cpp b/src/ivoc/symchoos.cpp index cac6d9d75d..a5444329fc 100644 --- a/src/ivoc/symchoos.cpp +++ b/src/ivoc/symchoos.cpp @@ -54,7 +54,7 @@ #include "symdir.h" #include "oc2iv.h" -#include "parse.h" +#include "parse.hpp" #include "ivoc.h" #endif /* HAVE_IV */ diff --git a/src/ivoc/symdir.cpp b/src/ivoc/symdir.cpp index ec396acffc..68d509e027 100644 --- a/src/ivoc/symdir.cpp +++ b/src/ivoc/symdir.cpp @@ -16,7 +16,7 @@ #include "membfunc.h" extern double* point_process_pointer(Point_process*, Symbol*, int); #endif -#include "parse.h" +#include "parse.hpp" #include "hoclist.h" extern Symlist* hoc_symlist; extern Objectdata* hoc_top_level_data; diff --git a/src/ivoc/xmenu.cpp b/src/ivoc/xmenu.cpp index 0a9ccec5e7..a990263a49 100644 --- a/src/ivoc/xmenu.cpp +++ b/src/ivoc/xmenu.cpp @@ -47,7 +47,7 @@ char** (*nrnpy_gui_helper3_str_)(const char* name, Object* obj, int handle_strpt #include "ivoc.h" #include "bndedval.h" #include "objcmd.h" -#include "parse.h" +#include "parse.hpp" #include "utility.h" #include "scenepic.h" diff --git a/src/memacs/redef.h b/src/memacs/redef.h index 47b0cf4b16..4cd96afc07 100755 --- a/src/memacs/redef.h +++ b/src/memacs/redef.h @@ -13,8 +13,7 @@ redef.h,v */ /*Publics by module*/ - -#define exit emacs_exit +#define exit(int) emacs_exit(int) /*ANSI size = 250*/ #define ansibeep emacs_ansibeep diff --git a/src/memacs/termio.c b/src/memacs/termio.c index 34358c0076..980b9d4d8f 100755 --- a/src/memacs/termio.c +++ b/src/memacs/termio.c @@ -102,7 +102,7 @@ int nxtchar = -1; /* character held from type ahead */ struct sgttyb ostate; /* saved tty state */ struct sgttyb nstate; /* values for editor mode */ struct tchars otchars; /* Saved terminal special character set */ -struct tchars ntchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; +struct tchars ntchars = { (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff }; /* A lot of nothing */ #ifndef HAVE_STTY /* os x 4 and gcc 4.0.0 do define this */ diff --git a/src/modlunit/Makefile.am b/src/modlunit/Makefile.am index 88c10563d1..1d992d41c7 100755 --- a/src/modlunit/Makefile.am +++ b/src/modlunit/Makefile.am @@ -1,11 +1,11 @@ bin_PROGRAMS = modlunit -modlunit_SOURCES = parse1.y lex.l consist.c declare.c init.c io.c \ - kinunit.c list.c model.c nrnunit.c passn.c symbol.c units.c \ - units1.c version.c +modlunit_SOURCES = parse1.ypp lex.lpp consist.cpp declare.cpp init.cpp io.cpp \ + kinunit.cpp list.cpp model.cpp nrnunit.cpp passn.cpp symbol.cpp units.cpp \ + units1.cpp version.cpp ## The list of .h files that are needed in the distribution. -noinst_HEADERS = extargs.h extdef.h model.h symbol.h units.h parse1.h \ +noinst_HEADERS = extargs.h extdef.h model.h symbol.h units.h parse1.hpp \ macmunit.h modlunit.h ## for building a dos version @@ -13,10 +13,11 @@ EXTRA_DIST = modlunit.mak carbonmunit.h AM_YFLAGS = -d -AM_CPPFLAGS = -DNRNUNIT=1 +IV_INCLUDES = @IV_INCLUDE@ $(X_CFLAGS) +AM_CPPFLAGS = -DNRNUNIT=1 $(IV_INCLUDES) -## files that depend on the existence of parse1.h -## this allows parallel make -j to work at the beginning when parse1.h +## files that depend on the existence of parse1.hpp +## this allows parallel make -j to work at the beginning when parse1.hpp ## does not exist and dependencies have not yet been determined consist.o declare.o init.o io.o kinunit.o lex.o list.o model.o \ -nrnunit.o passn.o symbol.o units1.o : parse1.h +nrnunit.o passn.o symbol.o units1.o : parse1.hpp diff --git a/src/modlunit/consist.cpp b/src/modlunit/consist.cpp index 01a068b9f1..5544c5e99a 100755 --- a/src/modlunit/consist.cpp +++ b/src/modlunit/consist.cpp @@ -7,7 +7,7 @@ * bad style) to work. */ #include "model.h" -#include "parse1.h" +#include "parse1.hpp" #include "symbol.h" extern Item **scop_indep; diff --git a/src/modlunit/declare.cpp b/src/modlunit/declare.cpp index 764263214a..781a94aab4 100755 --- a/src/modlunit/declare.cpp +++ b/src/modlunit/declare.cpp @@ -1,7 +1,7 @@ #include <../../nmodlconf.h> #include #include "model.h" -#include "parse1.h" +#include "parse1.hpp" #include "symbol.h" #ifdef HAVE_STRINGS_H #include diff --git a/src/modlunit/init.cpp b/src/modlunit/init.cpp index c270d4f594..542bb96ab3 100755 --- a/src/modlunit/init.cpp +++ b/src/modlunit/init.cpp @@ -2,7 +2,7 @@ /* /local/src/master/nrn/src/modlunit/init.c,v 1.9 1998/03/25 14:33:55 hines Exp */ #include "model.h" -#include "parse1.h" +#include "parse1.hpp" extern int unitonflag; List *initlist, *initfunc, *firstlist, *termfunc, *modelfunc; @@ -17,9 +17,9 @@ static struct { /* Keywords */ short kval; } keywords[] = { "VERBATIM", VERBATIM, - "ENDVERBATIM", END_VERBATIM, /* explicit in lex.l */ + "ENDVERBATIM", END_VERBATIM, /* explicit in lex.lpp */ "COMMENT", COMMENT, - "ENDCOMMENT", END_COMMENT, /* explicit in lex.l */ + "ENDCOMMENT", END_COMMENT, /* explicit in lex.lpp */ "TITLE", TITLE, "CONSTANT", CONSTANT, "PARAMETER", PARAMETER, diff --git a/src/modlunit/io.cpp b/src/modlunit/io.cpp index 210c2c91d8..463d0b1603 100755 --- a/src/modlunit/io.cpp +++ b/src/modlunit/io.cpp @@ -9,7 +9,7 @@ #include #endif #undef METHOD -#include "parse1.h" +#include "parse1.hpp" Item *lastok; /*should be last token accepted by parser that gives successful reduction */ diff --git a/src/modlunit/kinunit.cpp b/src/modlunit/kinunit.cpp index 52746685b6..6a121f14a6 100755 --- a/src/modlunit/kinunit.cpp +++ b/src/modlunit/kinunit.cpp @@ -2,7 +2,7 @@ #include "model.h" #include "symbol.h" #include "units.h" -#include "parse1.h" +#include "parse1.hpp" extern char *indepunits; static List *reactnames; diff --git a/src/modlunit/lex.l b/src/modlunit/lex.lpp similarity index 99% rename from src/modlunit/lex.l rename to src/modlunit/lex.lpp index 6bab5bbdeb..d027f76699 100755 --- a/src/modlunit/lex.l +++ b/src/modlunit/lex.lpp @@ -17,7 +17,7 @@ #include <../../nmodlconf.h> #include "model.h" -#include "parse1.h" +#include "parse1.hpp" static char linebuf[512], *cp; int lexcontext; diff --git a/src/modlunit/list.cpp b/src/modlunit/list.cpp index 13508512e6..9fb89c2fd3 100755 --- a/src/modlunit/list.cpp +++ b/src/modlunit/list.cpp @@ -31,7 +31,7 @@ following function calls. #include #include "model.h" -#include "parse1.h" +#include "parse1.hpp" #define DEBUG 0 #if DEBUG diff --git a/src/modlunit/model.cpp b/src/modlunit/model.cpp index 95f9de03d7..615f706f15 100755 --- a/src/modlunit/model.cpp +++ b/src/modlunit/model.cpp @@ -25,7 +25,7 @@ */ #include "model.h" -#include "parse1.h" +#include "parse1.hpp" extern int yyparse(); diff --git a/src/modlunit/model.h b/src/modlunit/model.h index ee0c874ac0..ad44abeb93 100755 --- a/src/modlunit/model.h +++ b/src/modlunit/model.h @@ -31,7 +31,7 @@ saved and much greater clarity could be attained if each type had its own sub stucture. Currently many of the structure elements serve very different purposes depending on the type. The following is a list of the current element usage: - type token number from parse1.y + type token number from parse1.ypp subtype see definitions below u.i integration method - flag for variable step equation block - function number for generating variables diff --git a/src/modlunit/modlunit.h b/src/modlunit/modlunit.h index 9d2fabe988..37b8522d9c 100644 --- a/src/modlunit/modlunit.h +++ b/src/modlunit/modlunit.h @@ -51,8 +51,8 @@ void punit(); void pushlocal(Item* q1, Item* qdim); void replacstr(Item* q, char* s); void symbol_init(); -void ucopypop(unit*); -void ucopypush(unit*); +void ucopypop(struct unit*); +void ucopypush(struct unit*); void unit_chk_arg(Item* q1, Item* q2); void unit_cmp(Item* q1, Item* q2, Item* q3); void unit_compartlist(Item*); diff --git a/src/modlunit/nrnunit.cpp b/src/modlunit/nrnunit.cpp index f6e9bfb943..4ce680938f 100755 --- a/src/modlunit/nrnunit.cpp +++ b/src/modlunit/nrnunit.cpp @@ -1,7 +1,7 @@ #include <../../nmodlconf.h> #include "model.h" #include "units.h" -#include "parse1.h" +#include "parse1.hpp" #define IONCUR 0 #define IONEREV 1 diff --git a/src/modlunit/parse1.y b/src/modlunit/parse1.ypp similarity index 99% rename from src/modlunit/parse1.y rename to src/modlunit/parse1.ypp index ed58f556bb..ed282e3f1b 100755 --- a/src/modlunit/parse1.y +++ b/src/modlunit/parse1.ypp @@ -289,7 +289,7 @@ unitdef: Units '=' Units factordef: NAME '=' real Units {P1{$$ = itemarray(3, $1, $4, $3); declare(UFACTOR, $1, $$);}} | NAME '=' Units Units - {P1{Item *q; double d, unit_mag(); + {P1{Item *q; double d; extern double unit_mag(); Unit_push(STR($3)); Unit_push(STR($4)); unit_div(); dimensionless(); @@ -300,7 +300,7 @@ factordef: NAME '=' real Units declare(UFACTOR, $1, $$); }} | NAME '=' Units '-' GT Units - {P1{ Item *q; double unit_mag(); + {P1{ Item *q; extern double unit_mag(); Unit_push(STR($3)); Unit_push(STR($6)); unit_div(); q = lappendstr(misc, unit_str()); dimensionless(); diff --git a/src/modlunit/passn.cpp b/src/modlunit/passn.cpp index 606be4401e..19eee54be0 100755 --- a/src/modlunit/passn.cpp +++ b/src/modlunit/passn.cpp @@ -4,7 +4,7 @@ /* Returns parse tokens in same order that lexical analyzer did */ #include "model.h" -#include "parse1.h" +#include "parse1.hpp" #define DEBUG 0 #if DEBUG diff --git a/src/modlunit/symbol.cpp b/src/modlunit/symbol.cpp index d9a4a5e24f..7c5e494907 100755 --- a/src/modlunit/symbol.cpp +++ b/src/modlunit/symbol.cpp @@ -2,7 +2,7 @@ /* /local/src/master/nrn/src/modlunit/symbol.c,v 1.1.1.1 1994/10/12 17:22:50 hines Exp */ #include "model.h" -#include "parse1.h" +#include "parse1.hpp" #include "symbol.h" List *symlist[128]; /* symbol table: linked list diff --git a/src/modlunit/units1.cpp b/src/modlunit/units1.cpp index 83898e4f50..5dd4af53be 100755 --- a/src/modlunit/units1.cpp +++ b/src/modlunit/units1.cpp @@ -2,7 +2,7 @@ /* /local/src/master/nrn/src/modlunit/units1.c,v 1.1.1.1 1994/10/12 17:22:51 hines Exp */ /* Just a connection to units.c so that file doesn't need to include modl.h */ #include "model.h" -#include "parse1.h" +#include "parse1.hpp" void unit_push(Item* q) { diff --git a/src/nmodl/Makefile.am b/src/nmodl/Makefile.am index e891d56a1b..532e519744 100755 --- a/src/nmodl/Makefile.am +++ b/src/nmodl/Makefile.am @@ -5,27 +5,28 @@ bin_PROGRAMS = nocmodl -nocmodl_SOURCES = parse1.y diffeq.y lex.l consist.c deriv.c discrete.c \ - init.c io.c kinetic.c list.c modl.c nocpout.c noccout.c parsact.c \ - netrec_discon.c \ - partial.c sens.c simultan.c solve.c symbol.c units.c version.c +nocmodl_SOURCES = parse1.ypp diffeq.ypp lex.lpp consist.cpp deriv.cpp discrete.cpp \ + init.cpp io.cpp kinetic.cpp list.cpp modl.cpp nocpout.cpp noccout.cpp parsact.cpp \ + netrec_discon.cpp \ + partial.cpp sens.cpp simultan.cpp solve.cpp symbol.cpp units.cpp version.cpp nsrc=$(top_srcdir)/src -includes = -I$(nsrc)/src/modlunit +IV_INCLUDES = @IV_INCLUDE@ $(X_CFLAGS) +includes = -I$(nsrc)/src/modlunit $(IV_INCLUDES) AM_CPPFLAGS = -DNRN_DYNAMIC_UNITS=1 -DNMODL=1 -DNOCMODL=1 -DCVODE=1 -DVECTORIZE=1 $(includes) -EXTRA_DIST = cout.c lex.c nmodl.mak +EXTRA_DIST = cout.cpp lex.cpp nmodl.mak AM_YFLAGS = -d ## The list of .h files that are needed in the distribution. -noinst_HEADERS = extdef.h extdef2.h extdef5.h modl.h symbol.h parse1.h \ +noinst_HEADERS = extdef.h extdef2.h extdef5.h modl.h symbol.h parse1.hpp \ difeqdef.h macnmodl.h carbonnmodl.h nmodlfunc.h -## files that depend on the existence of parse1.h or diffeq.h (none do) +## files that depend on the existence of parse1.hpp or diffeq.hpp (none do) ## this allows parallel make -j to work at the beginning when those ## do not exist and dependencies have not yet been determined consist.o cout.o deriv.o discrete.o init.o io.o kinetic.o lex.o \ list.o noccout.o nocpout.o parsact.o partial.o sens.o simultan.o \ -solve.o symbol.o netrec_discon.o: parse1.h +solve.o symbol.o netrec_discon.o: parse1.hpp diff --git a/src/nmodl/consist.cpp b/src/nmodl/consist.cpp index 3c859c7e10..3f8f81c3e3 100755 --- a/src/nmodl/consist.cpp +++ b/src/nmodl/consist.cpp @@ -6,7 +6,7 @@ * bad style) to work in some circumstances. */ #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" #include "symbol.h" extern Symbol *scop_indep; diff --git a/src/nmodl/cout.cpp b/src/nmodl/cout.cpp index ff02b42130..f5ccc6c1f1 100755 --- a/src/nmodl/cout.cpp +++ b/src/nmodl/cout.cpp @@ -110,7 +110,7 @@ cout.c,v * file and set to 0 on entry to a derivative or kinetic block. * * Revision 9.41 90/10/30 08:36:37 hines - * saber warning free except for ytab.c and lex.c + * saber warning free except for ytab.c and lex.cpp * * Revision 9.40 90/10/30 08:06:00 hines * nmodl: Passive.mod working with index vectors. No longer copying @@ -214,7 +214,7 @@ cout.c,v /* print the .c file from the lists */ #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" #include "symbol.h" #define P(arg) fputs(arg, fcout) diff --git a/src/nmodl/deriv.cpp b/src/nmodl/deriv.cpp index 6a432267a5..d7c072b7d2 100755 --- a/src/nmodl/deriv.cpp +++ b/src/nmodl/deriv.cpp @@ -5,7 +5,7 @@ #include "../oc/nrnassrt.h" #include #undef METHOD -#include "parse1.h" +#include "parse1.hpp" static List *deriv_imp_list; /* list of derivative blocks that were translated in form suitable for the derivimplicit method */ @@ -186,7 +186,7 @@ Note that we had to use Dx0 since x'0 is illegal. Also Dx0 has a value of -10. Implementation : - In parse1.y we see that asgn: varname '=' expr and that + In parse1.ypp we see that asgn: varname '=' expr and that varname gets marked if it is type PRIME. With respect to higher order derivatives, therefore, only the highest order actually used in the equations in that block diff --git a/src/nmodl/diffeq.y b/src/nmodl/diffeq.ypp similarity index 100% rename from src/nmodl/diffeq.y rename to src/nmodl/diffeq.ypp diff --git a/src/nmodl/discrete.cpp b/src/nmodl/discrete.cpp index 0cfe6a4e94..3797bed3d7 100755 --- a/src/nmodl/discrete.cpp +++ b/src/nmodl/discrete.cpp @@ -56,7 +56,7 @@ discrete.c,v #include #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" #include "symbol.h" void disc_var_seen(Item* q1, Item* q2, Item* q3, int array) /*NAME '@' NUMBER --- array flag*/ diff --git a/src/nmodl/init.cpp b/src/nmodl/init.cpp index ae74764602..5fdbdde660 100755 --- a/src/nmodl/init.cpp +++ b/src/nmodl/init.cpp @@ -2,7 +2,7 @@ /* /local/src/master/nrn/src/nmodl/init.c,v 4.5 1998/03/25 14:33:42 hines Exp */ #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" extern List *firstlist; extern List *syminorder; diff --git a/src/nmodl/io.cpp b/src/nmodl/io.cpp index 3cb0a53c08..6497869ee3 100755 --- a/src/nmodl/io.cpp +++ b/src/nmodl/io.cpp @@ -8,7 +8,7 @@ #include #endif #undef METHOD -#include "parse1.h" +#include "parse1.hpp" int isend(char*, char*); static void pop_file_stack(); diff --git a/src/nmodl/kinetic.cpp b/src/nmodl/kinetic.cpp index f1eb435ec0..58148157c5 100755 --- a/src/nmodl/kinetic.cpp +++ b/src/nmodl/kinetic.cpp @@ -16,7 +16,7 @@ order. Here is the C code from a kinetic block: #include #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" #include "symbol.h" extern int numlist; extern int thread_data_index; diff --git a/src/nmodl/lex.l b/src/nmodl/lex.lpp similarity index 98% rename from src/nmodl/lex.l rename to src/nmodl/lex.lpp index eff6227656..2cde58bac4 100755 --- a/src/nmodl/lex.l +++ b/src/nmodl/lex.lpp @@ -1,5 +1,5 @@ %{ -/* /local/src/master/nrn/src/nmodl/lex.l,v 4.2 1997/11/05 17:59:02 hines Exp */ +/* /local/src/master/nrn/src/nmodl/lex.lpp,v 4.2 1997/11/05 17:59:02 hines Exp */ #include <../../nmodlconf.h> @@ -19,7 +19,7 @@ #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" int lexcontext = 0; extern int Getc(); diff --git a/src/nmodl/list.cpp b/src/nmodl/list.cpp index e801304439..71d3d5e98a 100755 --- a/src/nmodl/list.cpp +++ b/src/nmodl/list.cpp @@ -87,7 +87,7 @@ following function calls. #include #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" static Item *newitem() { diff --git a/src/nmodl/modl.h b/src/nmodl/modl.h index 23145c9f85..5b1f947fd0 100755 --- a/src/nmodl/modl.h +++ b/src/nmodl/modl.h @@ -116,7 +116,7 @@ saved and much greater clarity could be attained if each type had its own sub stucture. Currently many of the structure elements serve very different purposes depending on the type. The following is a list of the current element usage: - type token number from parse1.y + type token number from parse1.ypp subtype see definitions below u.i integration method - flag for variable step equation block - function number for generating variables diff --git a/src/nmodl/netrec_discon.cpp b/src/nmodl/netrec_discon.cpp index 7140583882..7abaf18c30 100644 --- a/src/nmodl/netrec_discon.cpp +++ b/src/nmodl/netrec_discon.cpp @@ -56,7 +56,7 @@ that only dsi/dt that is affected by sj will change si. #include #include #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" extern int vectorize; extern int cvode_not_allowed; diff --git a/src/nmodl/nmodlfunc.h b/src/nmodl/nmodlfunc.h index 97d70b73d7..01c4260f2c 100644 --- a/src/nmodl/nmodlfunc.h +++ b/src/nmodl/nmodlfunc.h @@ -40,9 +40,9 @@ void leftreact(); void massagereaction(Item* qREACTION, Item* qREACT1, Item* qlpar, Item* qcomma, Item* qrpar); void flux(Item* qREACTION, Item* qdir, Item* qlast); void massagekinetic(Item* q1, Item* q2, Item* q3, Item* q4, int sensused); -void fixrlst(Rlist*); +void fixrlst(struct Rlist*); void kinetic_intmethod(Symbol* fun, char* meth); -void genfluxterm(Reaction* r, int type, int n); +void genfluxterm(struct Reaction* r, int type, int n); void kinetic_implicit(Symbol* fun, char* dt, char* mname); void massageconserve(Item* q1, Item* q3, Item* q5); void check_block(int standard, int actual, char* mes); diff --git a/src/nmodl/noccout.cpp b/src/nmodl/noccout.cpp index 90f6fc0a8c..d36c0d9d6d 100755 --- a/src/nmodl/noccout.cpp +++ b/src/nmodl/noccout.cpp @@ -2,7 +2,7 @@ /* print the .c file from the lists */ #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" #include "symbol.h" #define CACHEVEC 1 diff --git a/src/nmodl/nocpout.cpp b/src/nmodl/nocpout.cpp index ca8cf6264e..cbb9e5e340 100755 --- a/src/nmodl/nocpout.cpp +++ b/src/nmodl/nocpout.cpp @@ -64,7 +64,7 @@ directly by hoc. #define GLOBFUNCT 1 #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" #include #include #define GETWD(buf) getcwd(buf, NRN_BUFSIZE) diff --git a/src/nmodl/parsact.cpp b/src/nmodl/parsact.cpp index 58173a3e5b..8358ce8cf3 100755 --- a/src/nmodl/parsact.cpp +++ b/src/nmodl/parsact.cpp @@ -1,13 +1,13 @@ #include <../../nmodlconf.h> /* - * some parse actions to reduce size of parse.y the installation routines can + * some parse actions to reduce size of parse.ypp the installation routines can * also be used, e.g. in sens to automattically construct variables */ #include #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" Symbol *scop_indep; /* independent used by SCoP */ Symbol *indepsym; /* only one independent variable */ @@ -37,7 +37,7 @@ static char *previous_str; /* u.str on last install */ void explicit_decl(int level, Item* q) { - /* used to be inside parse1.y without the lastvars condition + /* used to be inside parse1.ypp without the lastvars condition Without the condition it served two purposes. 1) variables explicitly declared were so marked so that they would appear first in the .var file. Unmarked variables diff --git a/src/nmodl/parse1.y b/src/nmodl/parse1.ypp similarity index 99% rename from src/nmodl/parse1.y rename to src/nmodl/parse1.ypp index 84fd8643bb..9ad57d1909 100755 --- a/src/nmodl/parse1.y +++ b/src/nmodl/parse1.ypp @@ -1,5 +1,5 @@ %{ -/* /local/src/master/nrn/src/nmodl/parse1.y,v 4.11 1999/03/24 18:34:08 hines Exp */ +/* /local/src/master/nrn/src/nmodl/parse1.ypp,v 4.11 1999/03/24 18:34:08 hines Exp */ #include <../../nmodlconf.h> #include "modl.h" diff --git a/src/nmodl/partial.cpp b/src/nmodl/partial.cpp index 698a22ad00..14b57bb11e 100755 --- a/src/nmodl/partial.cpp +++ b/src/nmodl/partial.cpp @@ -71,7 +71,7 @@ partial.c,v */ #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" #include "symbol.h" extern Symbol *indepsym; diff --git a/src/nmodl/sens.cpp b/src/nmodl/sens.cpp index afcbe7705a..6b601630a1 100755 --- a/src/nmodl/sens.cpp +++ b/src/nmodl/sens.cpp @@ -89,7 +89,7 @@ sens.c,v */ #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" static List *sensinfo; /* list of pairs: first is the block symbol where the SENS statement appeared. The second is diff --git a/src/nmodl/simultan.cpp b/src/nmodl/simultan.cpp index 889c7dce28..37497636d5 100755 --- a/src/nmodl/simultan.cpp +++ b/src/nmodl/simultan.cpp @@ -1,6 +1,6 @@ #include <../../nmodlconf.h> #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" #include "symbol.h" extern int sens_parm; diff --git a/src/nmodl/solve.cpp b/src/nmodl/solve.cpp index d7db173f89..13b73cb416 100755 --- a/src/nmodl/solve.cpp +++ b/src/nmodl/solve.cpp @@ -2,7 +2,7 @@ /* /local/src/master/nrn/src/nmodl/solve.c,v 4.4 1998/08/20 21:07:34 hines Exp */ #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" #include "symbol.h" /* make it an error if 2 solve statements are called on a single call to diff --git a/src/nmodl/symbol.cpp b/src/nmodl/symbol.cpp index 4229e1093f..cbacf7af52 100755 --- a/src/nmodl/symbol.cpp +++ b/src/nmodl/symbol.cpp @@ -1,7 +1,7 @@ #include <../../nmodlconf.h> #include "modl.h" -#include "parse1.h" +#include "parse1.hpp" #include "symbol.h" List *symlist[128]; /* symbol table: linked list diff --git a/src/nmodl/version.cpp b/src/nmodl/version.cpp index ad96f3dace..a32f73d39a 100755 --- a/src/nmodl/version.cpp +++ b/src/nmodl/version.cpp @@ -647,7 +647,7 @@ NEURON 5.3 2002/06/04 * file and set to 0 on entry to a derivative or kinetic block. * * Revision 9.44 90/10/30 10:25:16 hines - * modl: saber warning free except for ytab.c and lex.c + * modl: saber warning free except for ytab.c and lex.cpp * * Revision 9.43 90/10/30 10:21:30 hines * ytab.o was not placed in proper directory @@ -656,7 +656,7 @@ NEURON 5.3 2002/06/04 * hmodl saber warning free and test.mod works * * Revision 9.41 90/10/30 08:37:13 hines - * saber warning free except for ytab.c and lex.c + * saber warning free except for ytab.c and lex.cpp * * Revision 9.40 90/10/30 08:07:07 hines * nmodl: Passive.mod working with index vectors. No longer copying diff --git a/src/nrncvode/netcvode.cpp b/src/nrncvode/netcvode.cpp index 9eda3c0bb0..24bd5a2736 100644 --- a/src/nrncvode/netcvode.cpp +++ b/src/nrncvode/netcvode.cpp @@ -15,7 +15,7 @@ #include #include "classreg.h" #include "nrnoc2iv.h" -#include "parse.h" +#include "parse.hpp" #include "cvodeobj.h" #include "hoclist.h" #include "pool.h" diff --git a/src/nrniv/CMakeLists.txt b/src/nrniv/CMakeLists.txt index 1abfe892a7..3a771dc2f5 100644 --- a/src/nrniv/CMakeLists.txt +++ b/src/nrniv/CMakeLists.txt @@ -15,10 +15,10 @@ # ============================================================================= # Build modlunit : Mod file units checker # ============================================================================= -flex_target(modlunitlexer ${NRN_MODLUNIT_SRC_DIR}/lex.l ${NRN_MODLUNIT_SRC_DIR}/lex.cpp) +flex_target(modlunitlexer ${NRN_MODLUNIT_SRC_DIR}/lex.lpp ${NRN_MODLUNIT_SRC_DIR}/lex.cpp) -bison_target(modlunitparser ${NRN_MODLUNIT_SRC_DIR}/parse1.y ${NRN_MODLUNIT_SRC_DIR}/parse1.cpp - DEFINES_FILE ${NRN_MODLUNIT_SRC_DIR}/parse1.h) +bison_target(modlunitparser ${NRN_MODLUNIT_SRC_DIR}/parse1.ypp ${NRN_MODLUNIT_SRC_DIR}/parse1.cpp + DEFINES_FILE ${NRN_MODLUNIT_SRC_DIR}/parse1.hpp) set_property( SOURCE ${NRN_MODLUNIT_SRC_FILES} @@ -30,13 +30,13 @@ add_executable(modlunit ${NRN_MODLUNIT_SRC_FILES}) # ============================================================================= # Build nocmodl : source-to-source compiler for NMODL # ============================================================================= -flex_target(nocmodllexer ${NRN_NMODL_SRC_DIR}/lex.l ${NRN_NMODL_SRC_DIR}/lex.cpp) +flex_target(nocmodllexer ${NRN_NMODL_SRC_DIR}/lex.lpp ${NRN_NMODL_SRC_DIR}/lex.cpp) -bison_target(nocmodlparser ${NRN_NMODL_SRC_DIR}/parse1.y ${NRN_NMODL_SRC_DIR}/parse1.cpp DEFINES_FILE - ${NRN_NMODL_SRC_DIR}/parse1.h) +bison_target(nocmodlparser ${NRN_NMODL_SRC_DIR}/parse1.ypp ${NRN_NMODL_SRC_DIR}/parse1.cpp DEFINES_FILE + ${NRN_NMODL_SRC_DIR}/parse1.hpp) -bison_target(nocmodlparser ${NRN_NMODL_SRC_DIR}/diffeq.y ${NRN_NMODL_SRC_DIR}/diffeq.cpp DEFINES_FILE - ${NRN_NMODL_SRC_DIR}/diffeq.h) +bison_target(nocmodlparser ${NRN_NMODL_SRC_DIR}/diffeq.ypp ${NRN_NMODL_SRC_DIR}/diffeq.cpp DEFINES_FILE + ${NRN_NMODL_SRC_DIR}/diffeq.hpp) set_property( SOURCE ${NRN_NMODL_SRC_FILES} @@ -59,8 +59,8 @@ set_source_files_properties(${NRN_MODFILE_C} PROPERTIES GENERATED TRUE) # ============================================================================= # Bison parser for HOC interpreter # ============================================================================= -bison_target(ocparser ${NRN_OC_SRC_DIR}/parse.y ${NRN_OC_SRC_DIR}/parse.cpp DEFINES_FILE - ${NRN_OC_SRC_DIR}/parse.h) +bison_target(ocparser ${NRN_OC_SRC_DIR}/parse.ypp ${NRN_OC_SRC_DIR}/parse.cpp DEFINES_FILE + ${NRN_OC_SRC_DIR}/parse.hpp) # ============================================================================= # Source code lists @@ -235,7 +235,7 @@ if(NRN_USE_BACKWARD) endif() set_source_files_properties(${NRN_NRNOC_SRC_DIR}/code.cpp PROPERTIES OBJECT_DEPENDS - ${NRN_OC_SRC_DIR}/parse.h) + ${NRN_OC_SRC_DIR}/parse.hpp) set_source_files_properties(${NRN_NRNOC_SRC_DIR}/nrnversion.cpp PROPERTIES OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/src/nrnoc/nrnversion.h) diff --git a/src/nrniv/cachevec.cpp b/src/nrniv/cachevec.cpp index 17d7acdb44..433809ecb7 100644 --- a/src/nrniv/cachevec.cpp +++ b/src/nrniv/cachevec.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/nrniv/hocmech.cpp b/src/nrniv/hocmech.cpp index 0ea095bbf1..ea2dbc3025 100644 --- a/src/nrniv/hocmech.cpp +++ b/src/nrniv/hocmech.cpp @@ -5,7 +5,7 @@ #include "nrnoc2iv.h" #include "nrniv_mf.h" -#include "parse.h" +#include "parse.hpp" extern int point_reg_helper(Symbol*); extern Object* hoc_newobj1(Symbol*, int); extern Symlist* hoc_symlist; diff --git a/src/nrniv/kschan.cpp b/src/nrniv/kschan.cpp index 7aaeec7b5e..28997fd68c 100644 --- a/src/nrniv/kschan.cpp +++ b/src/nrniv/kschan.cpp @@ -7,7 +7,7 @@ #include "classreg.h" #include "kschan.h" #include "kssingle.h" -#include "parse.h" +#include "parse.hpp" #include "nrniv_mf.h" #define NSingleIndex 0 diff --git a/src/nrniv/ndatclas.cpp b/src/nrniv/ndatclas.cpp index fe47212248..4d4fb6ecc8 100644 --- a/src/nrniv/ndatclas.cpp +++ b/src/nrniv/ndatclas.cpp @@ -5,7 +5,7 @@ #include "classreg.h" #include "membfunc.h" -#include "parse.h" +#include "parse.hpp" extern Prop* prop_alloc(Prop**, int, Node*); extern void single_prop_free(Prop*); extern Symlist* hoc_built_in_symlist; diff --git a/src/nrniv/nrncore_write.cpp b/src/nrniv/nrncore_write.cpp index 279451d8f4..e01b576ddf 100644 --- a/src/nrniv/nrncore_write.cpp +++ b/src/nrniv/nrncore_write.cpp @@ -92,7 +92,7 @@ correctness has not been validated for cells without gids. #include #include "section.h" -#include "parse.h" +#include "parse.hpp" #include "nrnmpi.h" #include "netcon.h" diff --git a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp index ab933ed837..248c4cd7d8 100644 --- a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp +++ b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp @@ -6,7 +6,7 @@ #include "hocdec.h" #include "nrncore_write/data/cell_group.h" #include "nrncore_write/io/nrncore_io.h" -#include "parse.h" +#include "parse.hpp" #include "nrnran123.h" // globalindex written to globals. #include "netcvode.h" // for nrnbbcore_vecplay_write #include "vrecitem.h" // for nrnbbcore_vecplay_write diff --git a/src/nrniv/nrncore_write/data/cell_group.cpp b/src/nrniv/nrncore_write/data/cell_group.cpp index 9fda496521..47d105d3fd 100644 --- a/src/nrniv/nrncore_write/data/cell_group.cpp +++ b/src/nrniv/nrncore_write/data/cell_group.cpp @@ -1,7 +1,7 @@ #include "cell_group.h" #include "nrnran123.h" // globalindex written to globals.dat #include "section.h" -#include "parse.h" +#include "parse.hpp" #include "nrnmpi.h" #include "netcon.h" diff --git a/src/nrniv/nrncore_write/utils/nrncore_utils.cpp b/src/nrniv/nrncore_write/utils/nrncore_utils.cpp index 05ac8c6d38..7df272e69d 100644 --- a/src/nrniv/nrncore_write/utils/nrncore_utils.cpp +++ b/src/nrniv/nrncore_write/utils/nrncore_utils.cpp @@ -8,7 +8,7 @@ #include "hocdec.h" #include "nrnsection_mapping.h" #include "vrecitem.h" // for nrnbbcore_vecplay_write -#include "parse.h" +#include "parse.hpp" #include #include #include diff --git a/src/nrniv/nrnmenu.cpp b/src/nrniv/nrnmenu.cpp index 8588d223e6..75cb857d0f 100644 --- a/src/nrniv/nrnmenu.cpp +++ b/src/nrniv/nrnmenu.cpp @@ -22,7 +22,7 @@ typedef void (*ReceiveFunc)(Point_process*, double*, double); /*extern "C"*/ extern int hoc_return_type_code; // from nrnoc #include "membfunc.h" -#include "parse.h" +#include "parse.hpp" extern Symlist *hoc_built_in_symlist; extern Symbol **pointsym; extern double* point_process_pointer(Point_process*, Symbol*, int); diff --git a/src/nrniv/nrnrtime.cpp b/src/nrniv/nrnrtime.cpp index b44004e273..febe8a9975 100644 --- a/src/nrniv/nrnrtime.cpp +++ b/src/nrniv/nrnrtime.cpp @@ -5,7 +5,7 @@ #include #include "classreg.h" #include "nrnoc2iv.h" -#include "parse.h" +#include "parse.hpp" extern int stoprun; extern double t; diff --git a/src/nrniv/pysecname2sec.cpp b/src/nrniv/pysecname2sec.cpp index d25ca84ae9..33bbf4a59b 100644 --- a/src/nrniv/pysecname2sec.cpp +++ b/src/nrniv/pysecname2sec.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include diff --git a/src/nrniv/shape.cpp b/src/nrniv/shape.cpp index bb997b9570..31c19d6c95 100644 --- a/src/nrniv/shape.cpp +++ b/src/nrniv/shape.cpp @@ -36,7 +36,7 @@ #include "idraw.h" #include "hocmark.h" #include "ocobserv.h" -#include "parse.h" +#include "parse.hpp" #include "ivoc.h" #define Shape_Section_ "Section PlotShape" diff --git a/src/nrniv/shapeplt.cpp b/src/nrniv/shapeplt.cpp index 3a08c727c2..bd9d083e77 100644 --- a/src/nrniv/shapeplt.cpp +++ b/src/nrniv/shapeplt.cpp @@ -26,7 +26,7 @@ #include "rubband.h" #include "symchoos.h" #include "symdir.h" -#include "parse.h" +#include "parse.hpp" #include "utility.h" #include "objcmd.h" #include "idraw.h" diff --git a/src/nrnjava/nrnjava.cpp b/src/nrnjava/nrnjava.cpp index ea442035cf..6f95274936 100644 --- a/src/nrnjava/nrnjava.cpp +++ b/src/nrnjava/nrnjava.cpp @@ -22,7 +22,7 @@ #include "classreg.h" #include "nrnoc2iv.h" -#include "parse.h" +#include "parse.hpp" #include "njvm.h" diff --git a/src/nrnjava/nrnjni.cpp b/src/nrnjava/nrnjni.cpp index ae292ef31e..3e6268e272 100755 --- a/src/nrnjava/nrnjni.cpp +++ b/src/nrnjava/nrnjni.cpp @@ -10,7 +10,7 @@ C implementations of Java native methods #include "ivoc.h" #include "nrnoc2iv.h" -#include "parse.h" +#include "parse.hpp" #include "ivocvect.h" #include "neuron_Neuron.h" // generated JNI Header file diff --git a/src/nrnmpi/Makefile.am b/src/nrnmpi/Makefile.am index 3688e3ffd5..135a192fc9 100755 --- a/src/nrnmpi/Makefile.am +++ b/src/nrnmpi/Makefile.am @@ -1,12 +1,12 @@ lib_LTLIBRARIES = libnrnmpi.la nsrc=$(top_srcdir)/src -includes = -I$(nsrc)/oc @NRN_REALTIME_INCLUDE@ -I@MUSIC_INCDIR@ -AM_CFLAGS = @MINGW_CFLAG@ $(includes) +includes = -I$(nsrc)/oc @NRN_REALTIME_INCLUDE@ -I@MUSIC_INCDIR@ -I$(nsrc)/ivos +AM_CPPFLAGS = $(includes) libnrnmpi_la_SOURCES = nrnmpi.cpp bbsmpipack.cpp mpispike.cpp nrnrt.cpp -CC = @MPICCnrnmpi@ +CXX = @MPICCnrnmpi@ if BUILD_NRNMPI_DYNAMIC diff --git a/src/nrnmpi/nrnmpi_impl.h b/src/nrnmpi/nrnmpi_impl.h index 61084b66ad..544cbe7cac 100644 --- a/src/nrnmpi/nrnmpi_impl.h +++ b/src/nrnmpi/nrnmpi_impl.h @@ -11,11 +11,11 @@ extern void* hoc_Emalloc(size_t size); extern void hoc_malchk(); extern void* hoc_Erealloc(void* buf, size_t size); +extern MPI_Comm nrnmpi_world_comm; +extern MPI_Comm nrnmpi_comm; + #if defined(__cplusplus) } #endif -extern MPI_Comm nrnmpi_world_comm; -extern MPI_Comm nrnmpi_comm; - #endif diff --git a/src/nrnoc/Makefile.am b/src/nrnoc/Makefile.am index e45088937b..0a7bc19f23 100755 --- a/src/nrnoc/Makefile.am +++ b/src/nrnoc/Makefile.am @@ -28,11 +28,13 @@ MODFILES_C = hh.c feature.c passive.c stim.c syn.c \ netstim.c intfire1.c intfire2.c intfire4.c \ expsyn.c exp2syn.c ppmark.c pattern.c -libnrnoc_la_SOURCES = $(MODFILES_C) cabcode.c capac.c clamp.c eion.c \ - extcelln.c fadvance.c fstim.c init.c nrnnemo.c point.c \ - psection.c solve.c synapse.c treeset.c hoc_init.c code.c hoc_oop.c \ - seclist.c method3.c hocprax.c secref.c ldifus.c hocusr.c nrnversion.c \ - nrnversion.h nrntimeout.c passive0.c +libnrnoc_la_SOURCES = $(MODFILES_C) cabcode.cpp capac.cpp clamp.cpp eion.cpp \ + extcelln.cpp fadvance.cpp fstim.cpp init.cpp nrnnemo.cpp point.cpp \ + psection.cpp solve.cpp synapse.cpp treeset.cpp hoc_init.cpp code.cpp hoc_oop.cpp \ + seclist.cpp method3.cpp hocprax.cpp secref.cpp ldifus.cpp hocusr.cpp nrnversion.cpp \ + nrnversion.h nrntimeout.cpp passive0.cpp + +libnrnoc_la_LIBADD = -lpthread ## ## The list of .c files which are actually built during the build procedure. @@ -50,7 +52,7 @@ PTHREAD_CFLAGS=@PTHREAD_CFLAGS@ PTHREAD_LIBS=@PTHREAD_LIBS@ AM_CFLAGS = @MINGW_CFLAG@ $(PTHREAD_CFLAGS) nsrc=$(top_srcdir)/src -includes = -I$(top_builddir)/src/oc -I$(nsrc)/oc -I$(nsrc)/scopmath -I$(nsrc)/sparse13 -I$(nsrc)/nrnmpi +includes = -I$(top_builddir)/src/oc -I$(nsrc)/oc -I$(nsrc)/scopmath -I$(nsrc)/sparse13 -I$(nsrc)/nrnmpi -I$(nsrc)/ivos AM_CPPFLAGS = -DCABLE=1 -DOOP=1 $(includes) NMODL = ../nmodl/nocmodl NRNUNITSLIB = $(top_builddir)/share/lib/nrnunits.lib @@ -109,7 +111,7 @@ pkginclude_HEADERS = neuron.h md1redef.h md2redef.h section.h nrnoc_ml.h \ ## Header files that need to be included in the distribution but not installed: noinst_HEADERS = hocusr.h \ - osxdlfcn.h osxdlfcn.c multicore.c \ + osxdlfcn.h osxdlfcn.cpp multicore.cpp \ nonvintblock.h nrndae_c.h ## We have to play a trick on automake to get it to install the .o files in diff --git a/src/nrnoc/cabcode.cpp b/src/nrnoc/cabcode.cpp index fbf6557fdd..e56f93a971 100644 --- a/src/nrnoc/cabcode.cpp +++ b/src/nrnoc/cabcode.cpp @@ -9,7 +9,7 @@ #include "section.h" #include "nrniv_mf.h" #include "membfunc.h" -#include "parse.h" +#include "parse.hpp" #include "hocparse.h" #include "membdef.h" diff --git a/src/nrnoc/eion.cpp b/src/nrnoc/eion.cpp index 000150f911..78ae598ad3 100644 --- a/src/nrnoc/eion.cpp +++ b/src/nrnoc/eion.cpp @@ -5,7 +5,7 @@ #include "section.h" #include "neuron.h" #include "membfunc.h" -#include "parse.h" +#include "parse.hpp" #include "membdef.h" #include "nrniv_mf.h" diff --git a/src/nrnoc/hocprax.cpp b/src/nrnoc/hocprax.cpp index 4027ecf145..254315314f 100644 --- a/src/nrnoc/hocprax.cpp +++ b/src/nrnoc/hocprax.cpp @@ -38,7 +38,7 @@ pval = pval_praxis(i, Vector) #include #include "hocdec.h" -#include "parse.h" +#include "parse.hpp" #if defined(__cplusplus) extern "C" { diff --git a/src/nrnoc/hocusr.h b/src/nrnoc/hocusr.h index 16b493f91f..70aaddb7db 100644 --- a/src/nrnoc/hocusr.h +++ b/src/nrnoc/hocusr.h @@ -1,4 +1,3 @@ - extern void node_data(), disconnect(); extern void batch_run(), batch_save(); extern void pt3dclear(), pt3dadd(), n3d(), x3d(), y3d(), z3d(), arc3d(), diam3d(); diff --git a/src/nrnoc/init.cpp b/src/nrnoc/init.cpp index c2a14aebea..3b4f0094e9 100644 --- a/src/nrnoc/init.cpp +++ b/src/nrnoc/init.cpp @@ -7,7 +7,7 @@ #include #include #include "section.h" -#include "parse.h" +#include "parse.hpp" #include "nrniv_mf.h" #include "cabvars.h" #include "neuron.h" diff --git a/src/nrnoc/ldifus.cpp b/src/nrnoc/ldifus.cpp index 80c932d2c1..c612eb4bac 100755 --- a/src/nrnoc/ldifus.cpp +++ b/src/nrnoc/ldifus.cpp @@ -7,7 +7,7 @@ #include "membfunc.h" #include "neuron.h" #include "nrniv_mf.h" -#include "parse.h" +#include "parse.hpp" #define nt_t nrn_threads->_t diff --git a/src/nrnoc/method3.cpp b/src/nrnoc/method3.cpp index d0d1249e46..76a90d33de 100644 --- a/src/nrnoc/method3.cpp +++ b/src/nrnoc/method3.cpp @@ -101,7 +101,7 @@ method3.cpp,v #if METHOD3 && VECTORIZE #include "membfunc.h" #include "neuron.h" -#include "parse.h" +#include "parse.hpp" extern int diam_changed; extern int tree_changed; diff --git a/src/nrnoc/nrnnoiv.cpp b/src/nrnoc/nrnnoiv.cpp index d89bc215a4..e529eef910 100644 --- a/src/nrnoc/nrnnoiv.cpp +++ b/src/nrnoc/nrnnoiv.cpp @@ -68,7 +68,7 @@ extern "C" double nrn_random_pick(void *r) { return 0.; } extern "C" int nrn_random_isran123(void *r, uint32_t *id1, uint32_t *id2, uint32_t *id3) { return 0.; } -void hoc_new_opoint() {} +void hoc_new_opoint(int) {} int special_pnt_call(Object *ob, Symbol *sym, int narg) { return 0; } @@ -96,14 +96,11 @@ int nrndae_list_is_empty(void) { return 0; } void nrn_solver_prepare() {} -void nrn_fihexec(i) -int i; +void nrn_fihexec(int i) { } -void nrn_deliver_events(tt) - -double tt; +void nrn_deliver_events(NrnThread*) { } @@ -111,9 +108,9 @@ void nrn_record_init() {} void nrn_play_init() {} -void fixed_record_continuous() {} +void fixed_record_continuous(NrnThread*) {} -void fixed_play_continuous() {} +void fixed_play_continuous(NrnThread*) {} void nrniv_recalc_ptrs() {} @@ -121,7 +118,7 @@ void nrn_recalc_ptrvector() {} void nrn_extra_scatter_gather(int direction, int tid) {} -void nrn_update_ion_pointer(int type, Datum *d, int i, int j) {} +extern "C" void nrn_update_ion_pointer(int type, Datum *d, int i, int j) {} void nrn_update_ps2nt() {} @@ -138,22 +135,19 @@ extern "C" void net_event() { hoc_execerror("net_event only available in nrniv", extern "C" void net_send() { hoc_execerror("net_send only available in nrniv", (char *) 0); } -void artcell_net_send() { hoc_execerror("net_send only available in nrniv", (char *) 0); } +extern "C" void artcell_net_send() { hoc_execerror("net_send only available in nrniv", (char *) 0); } extern "C" void net_move() { hoc_execerror("net_move only available in nrniv", (char *) 0); } extern "C" void artcell_net_move() { hoc_execerror("net_move only available in nrniv", (char *) 0); } -void nrn_use_daspk(i) -int i; +void nrn_use_daspk(int i) { } #if CVODE -void cvode_fadvance(t) - -double t; +extern "C" void cvode_fadvance(double t) { } @@ -161,9 +155,7 @@ void cvode_finitialize(double t0) {} void nrncvode_set_t(double tt) {} -void cvode_event(x) - -double x; +void cvode_event(double x) { } @@ -171,7 +163,7 @@ extern "C" void clear_event_queue() {} void init_net_events() {} -void deliver_net_events() {} +void deliver_net_events(NrnThread*) {} void hoc_reg_singlechan() {} @@ -182,8 +174,8 @@ void _nrn_single_react() {} #endif #if defined(CYGWIN) -void* dll_lookup(s) char* s; {return 0;} -void* dll_load(v, s) void* v; char* s; {return 0;} +void* dll_lookup(char* s) {return 0;} +void* dll_load(char* v, char* s) {return 0;} #endif void nrn_spike_exchange_init() {} @@ -202,11 +194,11 @@ void nrn_daq_scanstart() {} void nrn_multisplit_ptr_update() {} -void nrn_multisplit_bksub() { assert(0); } +void nrn_multisplit_bksub(NrnThread*) { assert(0); } -void nrn_multisplit_reduce_solve() { assert(0); } +void nrn_multisplit_reduce_solve(NrnThread*) { assert(0); } -void nrn_multisplit_triang() { assert(0); } +void nrn_multisplit_triang(NrnThread*) { assert(0); } #if 1 || PARANEURON @@ -216,6 +208,8 @@ double *nrn_classicalNodeB(Node *n) { return (double *) 0; } #endif +extern "C" { + void *nrn_pool_create(long count, int itemsize) { assert(0); return nullptr; @@ -230,6 +224,8 @@ void *nrn_pool_alloc(void *pool) { return nullptr; } +} + #if NRN_MUSIC void nrnmusic_init(int* parg, char*** pargv){} void nrnmusic_terminate(){} diff --git a/src/nrnoc/point.cpp b/src/nrnoc/point.cpp index 77ed6d6f41..c732af8027 100755 --- a/src/nrnoc/point.cpp +++ b/src/nrnoc/point.cpp @@ -7,7 +7,7 @@ saves the pointtype as later argument to create and loc */ #include #include "section.h" #include "membfunc.h" -#include "parse.h" +#include "parse.hpp" extern char* pnt_map; diff --git a/src/nrnoc/psection.cpp b/src/nrnoc/psection.cpp index 9938ae27b8..7963aa6403 100644 --- a/src/nrnoc/psection.cpp +++ b/src/nrnoc/psection.cpp @@ -2,7 +2,7 @@ #include #include "section.h" -#include "parse.h" +#include "parse.hpp" #include "membfunc.h" diff --git a/src/nrnoc/seclist.cpp b/src/nrnoc/seclist.cpp index f18af95d01..457f6a822a 100755 --- a/src/nrnoc/seclist.cpp +++ b/src/nrnoc/seclist.cpp @@ -3,7 +3,7 @@ #include #include "section.h" #include "neuron.h" -#include "parse.h" +#include "parse.hpp" #include "hocparse.h" #include "code.h" #include "hoc_membf.h" diff --git a/src/nrnoc/secref.cpp b/src/nrnoc/secref.cpp index ed84ca2345..a2e96de21d 100755 --- a/src/nrnoc/secref.cpp +++ b/src/nrnoc/secref.cpp @@ -17,7 +17,7 @@ access s1.sec // soma becomes the default section #include #include "section.h" -#include "parse.h" +#include "parse.hpp" #include "hoc_membf.h" extern int hoc_return_type_code; diff --git a/src/nrnoc/treeset.cpp b/src/nrnoc/treeset.cpp index 33aa17cf02..672789eb41 100644 --- a/src/nrnoc/treeset.cpp +++ b/src/nrnoc/treeset.cpp @@ -10,7 +10,7 @@ #include "section.h" #include "membfunc.h" #include "neuron.h" -#include "parse.h" +#include "parse.hpp" #include "nrnmpi.h" #include "multisplit.h" #include "spmatrix.h" diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index 1e10486a58..3ec73f1e4a 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -39,7 +39,7 @@ typedef struct { } NPySecObj; -#include "parse.h" +#include "parse.hpp" extern void (*nrnpy_sectionlist_helper_)(void*, Object*); extern Object** (*nrnpy_gui_helper_)(const char*, Object*); extern Object** (*nrnpy_gui_helper3_)(const char*, Object*, int); diff --git a/src/nrnpython/nrnpy_nrn.cpp b/src/nrnpython/nrnpy_nrn.cpp index 2a7f24628b..7276309fc6 100644 --- a/src/nrnpython/nrnpy_nrn.cpp +++ b/src/nrnpython/nrnpy_nrn.cpp @@ -9,7 +9,7 @@ #endif #include -#include +#include extern void nrn_pt3dremove(Section* sec, int i0); extern void nrn_pt3dinsert(Section* sec, int i0, double x, double y, double z, double d); extern void nrn_pt3dclear(Section* sec, int req); diff --git a/src/nrnpython/nrnpy_p2h.cpp b/src/nrnpython/nrnpy_p2h.cpp index 8eab363118..e163af0c44 100644 --- a/src/nrnpython/nrnpy_p2h.cpp +++ b/src/nrnpython/nrnpy_p2h.cpp @@ -8,7 +8,7 @@ #include #include "nrnpy_utils.h" -#include "parse.h" +#include "parse.hpp" extern void hoc_nopop(); extern void hoc_pop_defer(); extern Object* hoc_new_object(Symbol*, void*); diff --git a/src/nrnpython/rxdmath.cpp b/src/nrnpython/rxdmath.cpp index 139fb219f0..eeaf05f28a 100644 --- a/src/nrnpython/rxdmath.cpp +++ b/src/nrnpython/rxdmath.cpp @@ -4,29 +4,29 @@ * names and arguments match the wrappers used in rxdmath.py */ -double factorial(const double x) +extern "C" double factorial(const double x) { return tgamma(x+1.); } -double degrees(const double radians) +extern "C" double degrees(const double radians) { return radians * (180. / M_PI); } -void radians(const double degrees, double *radians) +extern "C" void radians(const double degrees, double *radians) { *radians = degrees * (M_PI / 180.); } -double log1p(const double x) +extern "C" double log1p(const double x) { return log(x+1.); } -double vtrap(const double x, const double y) +extern "C" double vtrap(const double x, const double y) { if(fabs(x/y) < 1e-6) { diff --git a/src/oc/Makefile.am b/src/oc/Makefile.am index 04eaa5bba3..6129eada76 100755 --- a/src/oc/Makefile.am +++ b/src/oc/Makefile.am @@ -2,10 +2,10 @@ lib_LTLIBRARIES = liboc.la libocxt.la nsrc=$(top_srcdir)/src -includes = -I$(nsrc) -I$(nsrc)/memacs -I$(nsrc)/sparse -I$(nsrc)/nrnmpi -I$(nsrc)/nrnoc $(X_CFLAGS) +IV_INCLUDES = @IV_INCLUDE@ $(X_CFLAGS) +includes = -I$(nsrc) -I$(nsrc)/memacs -I$(nsrc)/sparse -I$(nsrc)/nrnmpi -I$(nsrc)/nrnoc $(IV_INCLUDES) AM_CPPFLAGS = -DOOP=1 -DINTERVIEWS=1 -DHOC=1 $(includes) -AM_CFLAGS = @MINGW_CFLAG@ RanFiles = isaac64.cpp mcran4.cpp nrnisaac.cpp nrnran123.cpp @@ -17,10 +17,10 @@ nrnmpila = ../nrnmpi/libnrnmpi.la nrnmpidynam = endif -liboc_la_SOURCES = parse.y bksub.cpp getelm.cpp lineq.cpp subrows.cpp prmat.cpp \ +liboc_la_SOURCES = parse.ypp bksub.cpp getelm.cpp lineq.cpp subrows.cpp prmat.cpp \ code2.cpp debug.cpp ocerf.cpp fileio.cpp ftime.cpp \ getsym.cpp hoc.cpp hocedit.cpp math.cpp nonlin.cpp \ - list.cpp regexp.cpp audit.cpp symbol.cpp \ + list.cpp regexp.cpp audit.cpp symbol.cpp fmenu.cpp \ version.cpp xred.cpp parallel.cpp functabl.cpp plot.cpp plt.cpp axis.cpp \ settext.cpp x.cpp termio.cpp isoc99.cpp $(nrnmpidynam)\ scoprand.cpp $(RanFiles) cygwinprt.cpp nrnfilewrap.cpp @@ -67,20 +67,20 @@ pkginclude_HEADERS = hoc.h hoclist.h hocdec.h hocassrt.h nrnisaac.h \ ## Header files that need to be copied into the distribution but do not need ## to be installed: noinst_HEADERS = code.h equation.h hocmodl.h hocstr.h \ - profile.h redef.h parse.h mcran4.h nrnmpi.h nrnrt.h isaac64.h \ + profile.h redef.h parse.hpp mcran4.h nrnmpi.h nrnrt.h isaac64.h \ nrnfilewrap.h nrn_vsscanf.cpp classreg.h -## files that depend on the existence of parse.h -## this allows parallel make -j to work at the beginning when parse.h +## files that depend on the existence of parse.hpp +## this allows parallel make -j to work at the beginning when parse.hpp ## does not exist and dependencies have not yet been determined ## I am not sure whether both .lo and .o lists are necessary. -## Also, oc/parse.h is included in files in the nrnoc, ivoc, and -## nrniv directories so we hope that parse.h is created before +## Also, oc/parse.hpp is included in files in the nrnoc, ivoc, and +## nrniv directories so we hope that parse.hpp is created before ## make -v gets into those. code2.lo code.lo fileio.lo getsym.lo hoc.lo hoc_init.lo hoc_oop.lo \ -list.lo nonlin.lo parallel.lo symbol.lo: parse.h +list.lo nonlin.lo parallel.lo symbol.lo: parse.hpp code2.o code.o fileio.o getsym.o hoc.o hoc_init.o hoc_oop.o \ -list.o nonlin.o parallel.o symbol.o: parse.h +list.o nonlin.o parallel.o symbol.o: parse.hpp diff --git a/src/oc/code.cpp b/src/oc/code.cpp index 49f82752f9..61434c8dca 100755 --- a/src/oc/code.cpp +++ b/src/oc/code.cpp @@ -9,7 +9,7 @@ #include "hoc.h" #include "code.h" #include "hocstr.h" -#include "parse.h" +#include "parse.hpp" #include "ocfunc.h" #include "ocmisc.h" #include "hocparse.h" @@ -308,21 +308,23 @@ static void frame_objauto_recover_on_err(Frame *ff) { /* only on error */ Here, stkp is the last+1 localobj slot pair on the stack. */ Datum *stkp = f->argn + 2 + sp->u.u_proc->nauto * 2; - for (i = sp->u.u_proc->nobjauto; i > 0; --i) { - Object *ob = stkp[-2 * i].obj; - hoc_obj_unref(ob); - /* Note that these AUTOOBJECT stack locations have an itemtype that - are left over from the previous stack usage of that location. - Regardless of that itemtype (e.g. OBJECTTMP), these did NOT - increment tobj_count so we need to guarantee that the subsequent - stack_obtmp_recover_on_err does not inadvertently free it again - by setting the itemtype to a non OBJECTTMP value. I hope this is - the only place where stack space was used in which no item type - was specified. - We are doing this here which happens rarely to avoid having to - set them when the stack obj pointers are zeroed. - */ - stkp[-2 * i + 1].i = 0; + if(sp->u.u_proc != 0) { + for (i = sp->u.u_proc->nobjauto; i > 0; --i) { + Object *ob = stkp[-2 * i].obj; + hoc_obj_unref(ob); + /* Note that these AUTOOBJECT stack locations have an itemtype that + are left over from the previous stack usage of that location. + Regardless of that itemtype (e.g. OBJECTTMP), these did NOT + increment tobj_count so we need to guarantee that the subsequent + stack_obtmp_recover_on_err does not inadvertently free it again + by setting the itemtype to a non OBJECTTMP value. I hope this is + the only place where stack space was used in which no item type + was specified. + We are doing this here which happens rarely to avoid having to + set them when the stack obj pointers are zeroed. + */ + stkp[-2 * i + 1].i = 0; + } } } } diff --git a/src/oc/code2.cpp b/src/oc/code2.cpp index 8d2bff3e9f..999b7ca7a7 100755 --- a/src/oc/code2.cpp +++ b/src/oc/code2.cpp @@ -3,7 +3,7 @@ #include "hoc.h" #include "hocstr.h" -#include "parse.h" +#include "parse.hpp" #include "hocparse.h" #include #include diff --git a/src/oc/fileio.cpp b/src/oc/fileio.cpp index 259013a9f8..186f03769b 100755 --- a/src/oc/fileio.cpp +++ b/src/oc/fileio.cpp @@ -9,7 +9,7 @@ #include "ocmisc.h" #include "hocstr.h" #include "hoclist.h" -#include "parse.h" +#include "parse.hpp" #include "hocparse.h" #include #include diff --git a/src/oc/getsym.cpp b/src/oc/getsym.cpp index f587a95da4..1826e7d8a1 100755 --- a/src/oc/getsym.cpp +++ b/src/oc/getsym.cpp @@ -63,7 +63,7 @@ getsym.cpp,v #else #include "hocgetsym.h" -#include "parse.h" +#include "parse.hpp" #include "hocparse.h" #include "code.h" diff --git a/src/oc/hoc.cpp b/src/oc/hoc.cpp index b8a2893856..a5c5935736 100755 --- a/src/oc/hoc.cpp +++ b/src/oc/hoc.cpp @@ -9,7 +9,7 @@ #include #include #include -#include "parse.h" +#include "parse.hpp" #include "hocparse.h" #include "ocfunc.h" #include "ocmisc.h" @@ -396,7 +396,7 @@ int yylex(void) /* hoc6 */ void* nrn_parsing_pysec_ is 1 to signal the beginning of parsing and as a sub-dictionary pointer in case the first level __psec.name[int] is the name of a cell. - On error or success in parse.y, nrn_parsing_pysec_ is + On error or success in parse.ypp, nrn_parsing_pysec_ is set back to NULL. */ if (strcmp(sbuf, "_pysec") == 0) { diff --git a/src/oc/hoc_init.cpp b/src/oc/hoc_init.cpp index bcbcd158d3..722fa0910c 100755 --- a/src/oc/hoc_init.cpp +++ b/src/oc/hoc_init.cpp @@ -2,7 +2,7 @@ /* /local/src/master/nrn/src/oc/hoc_init.cpp,v 1.25 1999/11/08 17:48:58 hines Exp */ #include "hoc.h" -#include "parse.h" +#include "parse.hpp" #include #include "equation.h" diff --git a/src/oc/hoc_oop.cpp b/src/oc/hoc_oop.cpp index 2502adef01..b640523aa0 100755 --- a/src/oc/hoc_oop.cpp +++ b/src/oc/hoc_oop.cpp @@ -2,7 +2,7 @@ #include #include #include "hocstr.h" -#include "parse.h" +#include "parse.hpp" #include "hocparse.h" #include "code.h" #include "hocassrt.h" diff --git a/src/oc/hocmodl.h b/src/oc/hocmodl.h index 214597e941..73d2256d98 100755 --- a/src/oc/hocmodl.h +++ b/src/oc/hocmodl.h @@ -1,7 +1,7 @@ extern void hoc_model(), hoc_initmodel(), hoc_terminal(), hoc_prconst(); extern int *hoc_pindepindex; -static VoidFunc function[] = { +static VoidFunc functions[] = { "model", hoc_model, "initmodel", hoc_initmodel, "terminal", hoc_terminal, diff --git a/src/oc/hocparse.h b/src/oc/hocparse.h index 6483013170..f681f7cba2 100644 --- a/src/oc/hocparse.h +++ b/src/oc/hocparse.h @@ -4,7 +4,7 @@ #include "hoc.h" -/* do not know why this is not in parse.h */ +/* do not know why this is not in parse.hpp */ extern int yyparse(void); extern int yylex(void); diff --git a/src/oc/hocusr.cpp b/src/oc/hocusr.cpp index e6a4ae3bef..f392f9f299 100755 --- a/src/oc/hocusr.cpp +++ b/src/oc/hocusr.cpp @@ -4,7 +4,7 @@ #include #include #include "hocdec.h" -#include "parse.h" +#include "parse.hpp" #if 1 #include "hocusr.h" #endif @@ -44,7 +44,7 @@ void nrn_load_name_check(const char *name) { static void arayinstal(Symbol *sp, int nsub, int sub1, int sub2, int sub3); -void hoc_spinit(void) /* install user variables and functions */ +extern "C" void hoc_spinit(void) /* install user variables and functions */ { int i; Symbol *s; diff --git a/src/oc/list.cpp b/src/oc/list.cpp index 2cdd5cb52c..971bf9633a 100755 --- a/src/oc/list.cpp +++ b/src/oc/list.cpp @@ -33,7 +33,7 @@ following function calls. #include #include "hoclist.h" #include "hocdec.h" -#include "parse.h" +#include "parse.hpp" #define Free free diff --git a/src/oc/mk_hocusr_h.py b/src/oc/mk_hocusr_h.py index 1cd0ccb0da..e16f0132be 100644 --- a/src/oc/mk_hocusr_h.py +++ b/src/oc/mk_hocusr_h.py @@ -59,7 +59,7 @@ def process(type, names): print(''' /* Functions */ -static VoidFunc function[] = { +static VoidFunc functions[] = { ''') for i in voidfun: diff --git a/src/oc/nonlin.cpp b/src/oc/nonlin.cpp index e091e420b9..4f0a6f17f2 100755 --- a/src/oc/nonlin.cpp +++ b/src/oc/nonlin.cpp @@ -2,7 +2,7 @@ #include #include #include "hoc.h" -#include "parse.h" +#include "parse.hpp" #include "hocparse.h" #include "equation.h" #include "lineq.h" diff --git a/src/oc/oc_ansi.h b/src/oc/oc_ansi.h index 4e761bc0b4..e998b2f866 100644 --- a/src/oc/oc_ansi.h +++ b/src/oc/oc_ansi.h @@ -228,7 +228,7 @@ extern void hoc_audit_from_emacs(const char*, const char*); extern int hoc_retrieving_audit (void); extern int hoc_retrieve_audit (int id); extern int hoc_saveaudit (void); -extern void bbs_done(void); + extern void hoc_close_plot(void); extern void hoc_edit(void); extern void hoc_edit_quit(void); @@ -287,6 +287,7 @@ extern int nrn_isdouble(double*, double, double); } #endif +extern void bbs_done(void); extern int hoc_main1(int, const char**, const char**); extern char* cxx_char_alloc(size_t size); extern int stoprun; diff --git a/src/oc/ocmain.cpp b/src/oc/ocmain.cpp index 9f925898ea..5359b199c6 100755 --- a/src/oc/ocmain.cpp +++ b/src/oc/ocmain.cpp @@ -36,7 +36,7 @@ static void setnrnhome(const char* arg) { if (!neuron_home) { #if defined(HAVE_PUTENV) static char* buffer; - buffer = malloc(strlen(NEURON_DATA_DIR) + 12); + buffer = static_cast(malloc(strlen(NEURON_DATA_DIR) + 12)); sprintf(buffer, "NEURONHOME=%s", NEURON_DATA_DIR); putenv(buffer); neuron_home = NEURON_DATA_DIR; diff --git a/src/oc/ocnoiv.cpp b/src/oc/ocnoiv.cpp index 2f5cdbf3f9..fa151b132e 100755 --- a/src/oc/ocnoiv.cpp +++ b/src/oc/ocnoiv.cpp @@ -59,6 +59,12 @@ const char* path_prefix_to_libnrniv() { return NULL; } #endif #if !defined(SOME_IV) +#if defined(__cplusplus) +class IvocVect; +#else +#define IvocVect void +#endif +extern "C" { /*ARGSUSED*/ int ivoc_list_look(Object* ob, Object* oblook, char* path, int depth) { @@ -76,35 +82,38 @@ void hoc_template_notify(Object* ob, int create) {} #endif /*ARGSUSED*/ -int hoc_readcheckpoint(char* f) { return 0; } - -/*ARGSUSED*/ -extern "C" int vector_arg_px(int i, double** p) { +extern int vector_arg_px(int i, double** p) { hoc_execerror("implemented in ivoc library", "vector_arg_px"); return 0; } -int vector_capacity(void* v) {return 0;} -extern "C" void install_vector_method(const char* name, Pfrd_vp f) {} -extern "C" int vector_instance_px(void* vv, double** px){return 0;} -void vector_resize(v, n) void* v; int n; { +int vector_capacity(IvocVect* v) {return 0;} +void install_vector_method(const char* name, Pfrd_vp f) {} + int vector_instance_px(void* vv, double** px){return 0;} +void vector_resize(IvocVect* v, int n) { hoc_execerror("implemented in ivoc library", "vector_resize"); } -void vector_append(void* vv, double x) {} -void vector_delete(void* v) {} - -void* vector_arg(int i) { return nullptr;} -void* vector_new2(void* v) { return nullptr;} -Object** vector_pobj(void* v) { return (Object**)0;} -double* vector_vec(void* v) { - hoc_execerror("implemented in ivoc library", "vector_vec"); - return (double*)0; +void vector_append(IvocVect* vv, double x) {} +void vector_delete(IvocVect* v) {} + +IvocVect *vector_arg(int i) { return nullptr; } +IvocVect *vector_new2(IvocVect *v) { return nullptr; } +Object **vector_pobj(IvocVect *v) { return (Object **) 0; } +double *vector_vec(IvocVect *v) { + hoc_execerror("implemented in ivoc library", "vector_vec"); + return (double *) 0; } -extern "C" Object* ivoc_list_item(Object* list, int item) { - hoc_execerror("implemented in ivoc library", "ivoc_list_item"); - return nullptr; +Object *ivoc_list_item(Object *list, int item) { + hoc_execerror("implemented in ivoc library", "ivoc_list_item"); + return nullptr; +} +int ivoc_list_count(Object *list) { return 0; } +#if defined(__cplusplus) } -int ivoc_list_count(list) Object* list; { return 0; } +#endif +/*ARGSUSED*/ +int hoc_readcheckpoint(char* f) { return 0; } + void bbs_done(void){} Symbol* ivoc_alias_lookup(const char* name, Object* ob) {return (Symbol*)0;} @@ -117,4 +126,4 @@ int stdin_event_ready(void) {} void nrnbbs_context_wait(void) {} void ivoc_final_exit(void) {} -char* cxx_char_alloc(size_t len) { return hoc_Emalloc(len); } +char* cxx_char_alloc(size_t len) { return static_cast(hoc_Emalloc(len)); } diff --git a/src/oc/parallel.cpp b/src/oc/parallel.cpp index ecfa6d867e..4f91fa5a7b 100755 --- a/src/oc/parallel.cpp +++ b/src/oc/parallel.cpp @@ -14,7 +14,7 @@ #include #endif #include "hoc.h" -#include "parse.h" /* OBJECTVAR */ +#include "parse.hpp" /* OBJECTVAR */ static int parallel_seen; diff --git a/src/oc/parse.y b/src/oc/parse.ypp similarity index 100% rename from src/oc/parse.y rename to src/oc/parse.ypp diff --git a/src/oc/spinit.cpp b/src/oc/spinit.cpp index 770525eb9f..949336b227 100755 --- a/src/oc/spinit.cpp +++ b/src/oc/spinit.cpp @@ -31,6 +31,6 @@ spinit.cpp,v */ -void hoc_spinit(void) /* Dummy special init */ +extern "C" void hoc_spinit(void) /* Dummy special init */ { } diff --git a/src/oc/symbol.cpp b/src/oc/symbol.cpp index d865929b28..c56d18762e 100755 --- a/src/oc/symbol.cpp +++ b/src/oc/symbol.cpp @@ -16,7 +16,7 @@ #include #include #include "hoc.h" -#include "parse.h" +#include "parse.hpp" #include "hoclist.h" #if MAC #undef HAVE_MALLOC_H diff --git a/src/oc/version.cpp b/src/oc/version.cpp index 9989ab871c..5a92d2d490 100755 --- a/src/oc/version.cpp +++ b/src/oc/version.cpp @@ -715,7 +715,7 @@ NEURON 5.3 2002/06/04 * FARADAY and R (molar gas constant) added as built-in constants. * * Revision 1.68 92/08/10 16:00:05 hines - * forgot to checkin parse.y last time + * forgot to checkin parse.ypp last time * * Revision 1.67 92/08/10 15:59:38 hines * lists of sections with seclistdef ,,, diff --git a/src/parallel/ocbbs.cpp b/src/parallel/ocbbs.cpp index 42611dd57c..137d72b645 100644 --- a/src/parallel/ocbbs.cpp +++ b/src/parallel/ocbbs.cpp @@ -8,7 +8,7 @@ #include "bbs.h" #include "bbsimpl.h" #include "ivocvect.h" -#include "parse.h" +#include "parse.hpp" #include "section.h" #include "membfunc.h" #include diff --git a/src/readline/history.c b/src/readline/history.c index e05645f82a..17e782454e 100755 --- a/src/readline/history.c +++ b/src/readline/history.c @@ -81,6 +81,9 @@ static char *xmalloc (), *xrealloc (); #define member(c, s) ((c) ? index ((s), (c)) : 0) #endif +extern close(); +extern write(); +extern read(); /* **************************************************************** */ /* */ /* History Functions */ @@ -789,8 +792,8 @@ get_history_event (string, caller_index, delimiting_quote) which = (history_length + history_base) - which; get_which: - if (entry = history_get (which)) - return (entry->line); + if ((entry = history_get (which))) + return (entry->line); return ((char *)NULL); } diff --git a/src/readline/readline.c b/src/readline/readline.c index 3622a38fe4..20da564a6c 100755 --- a/src/readline/readline.c +++ b/src/readline/readline.c @@ -88,7 +88,7 @@ static char *xmalloc (), *xrealloc (); extern char* rindex(); static char *strindex (); static int next_macro_key (); -static with_macro_input (); +static int with_macro_input (); static int substring_member_of_array (); @@ -217,7 +217,7 @@ char *index (); static void update_line (char *old, char *new, int current_line); static void output_character_function (); static void delete_chars (); -static insert_some_chars (); +static int insert_some_chars (); #ifdef VOID_SIGHANDLER #define sighandler void @@ -236,7 +236,6 @@ typedef sighandler SigHandler (); /* If on, then readline handles signals in a way that doesn't screw. */ #define HANDLE_SIGNALS - /* **************************************************************** */ /* */ /* Line editing input utility */ @@ -354,1022 +353,828 @@ static int stricmp (), strnicmp(); /* Non-zero means to save keys that we dispatch on in a kbd macro. */ static int defining_kbd_macro = 0; - + + +void rl_dispatch (int key, Keymap map); +void rl_digit_loop (); +void move_vert (int to); +void init_terminal_io (char *terminal_name); + + + /* **************************************************************** */ /* */ -/* Top Level Functions */ +/* History Utilities */ /* */ /* **************************************************************** */ -/* Read a line of input. Prompt with PROMPT. A NULL PROMPT means - none. A return value of NULL means that EOF was encountered. */ -char * -readline (prompt) - char *prompt; -{ - char *readline_internal (); - char *value; - - rl_prompt = prompt; +/* We already have a history library, and that is what we use to control + the history features of readline. However, this is our local interface + to the history mechanism. */ - /* If we are at EOF return a NULL string. */ - if (rl_pending_input == EOF) - { - rl_pending_input = 0; - return ((char *)NULL); - } +/* While we are editing the history, this is the saved + version of the original line. */ +HIST_ENTRY *saved_line_for_history = (HIST_ENTRY *)NULL; - rl_initialize (); - rl_prep_terminal (); +/* Set the history pointer back to the last entry in the history. */ +void start_using_history () +{ + using_history (); + if (saved_line_for_history) + free_history_entry (saved_line_for_history); -#ifdef HANDLE_SIGNALS - rl_set_signals (); -#endif + saved_line_for_history = (HIST_ENTRY *)NULL; +} - value = readline_internal (); - rl_deprep_terminal (); +/* Free the contents (and containing structure) of a HIST_ENTRY. */ +void free_history_entry (entry) + HIST_ENTRY *entry; +{ + if (!entry) return; + if (entry->line) + free (entry->line); + free (entry); +} -#ifdef HANDLE_SIGNALS - rl_clear_signals (); -#endif +/* Perhaps put back the current line if it has changed. */ +void maybe_replace_line () +{ + HIST_ENTRY *temp = current_history (); - return (value); + /* If the current line has changed, save the changes. */ + if (temp && ((UNDO_LIST *)(temp->data) != rl_undo_list)) { + temp = replace_history_entry (where_history (), the_line, rl_undo_list); + free (temp->line); + free (temp); + } } -void rl_dispatch (int key, Keymap map); -void rl_digit_loop (); -void move_vert (int to); -void init_terminal_io (char *terminal_name); +/* Put back the saved_line_for_history if there is one. */ +void maybe_unsave_line () +{ + if (saved_line_for_history) { + strcpy (the_line, saved_line_for_history->line); + rl_undo_list = (UNDO_LIST *)saved_line_for_history->data; + free_history_entry (saved_line_for_history); + saved_line_for_history = (HIST_ENTRY *)NULL; + rl_end = rl_point = strlen (the_line); + } else { + ding (); + } +} -/* Read a line of input from the global rl_instream, doing output on - the global rl_outstream. - If rl_prompt is non-null, then that is our prompt. */ -char * -readline_internal () +/* Save the current line in saved_line_for_history. */ +void maybe_save_line () { - int lastc, c, eof_found; + if (!saved_line_for_history) { + saved_line_for_history = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY)); + saved_line_for_history->line = savestring (the_line); + saved_line_for_history->data = (char *)rl_undo_list; + } +} - in_stream = rl_instream; out_stream = rl_outstream; - lastc = eof_found = 0; - if (rl_startup_hook) - (*rl_startup_hook) (); - if (!readline_echoing_p) - { - if (rl_prompt) - { - fprintf (out_stream, "%s", rl_prompt); - fflush (out_stream); - } - } - else +/* **************************************************************** */ +/* */ +/* Binding keys */ +/* */ +/* **************************************************************** */ + + +/* Bind KEY to FUNCTION. Returns non-zero if KEY is out of range. */ +int +rl_bind_key (key, function) + int key; + Function *function; +{ + if (key < 0) + return (key); + + if (key > 127 && key < 256) { - rl_on_new_line (); - rl_redisplay (); -#ifdef VI_MODE - if (rl_editing_mode == vi_mode) - rl_vi_insertion_mode (); -#endif /* VI_MODE */ + if (keymap[ESC].type == ISKMAP) + { + Keymap escmap = (Keymap)keymap[ESC].function; + + key -= 128; + escmap[key].type = ISFUNC; + escmap[key].function = function; + return (0); + } + return (key); } - while (!rl_done) - { - int lk = last_command_was_kill; - int code; - code = setjmp (readline_top_level); + keymap[key].type = ISFUNC; + keymap[key].function = function; + return (0); +} - if (code) - rl_redisplay (); +/* rl_add_defun (char *name, Function *function, int key) + Add NAME to the list of named functions. Make FUNCTION + be the function that gets called. + If KEY is not -1, then bind it. */ +int rl_add_defun (name, function, key) +char *name; +Function *function; +int key; +{ +if (key != -1) +rl_bind_key (key, function); +extern void rl_add_funmap_entry(char*, Function*); +rl_add_funmap_entry (name, function); +} - if (!rl_pending_input) - { - /* Then initialize the argument and number of keys read. */ - rl_init_argument (); - rl_key_sequence_length = 0; - } - c = rl_read_key (); +/* Bind KEY to FUNCTION in MAP. Returns non-zero in case of invalid + KEY. */ +int +rl_bind_key_in_map (key, function, map) + int key; + Function *function; + Keymap map; +{ + int result; + Keymap oldmap = keymap; - /* EOF typed to a non-blank line is a . */ - if (c == EOF && rl_end) - c = NEWLINE; + keymap = map; + result = rl_bind_key (key, function); + keymap = oldmap; + return (result); +} - /* The character eof_char typed to blank line, and not as the - previous character is interpreted as EOF. */ - if (((c == eof_char && lastc != c) || c == EOF) && !rl_end) - { - eof_found = 1; - break; - } +/* Make KEY do nothing in the currently selected keymap. + Returns non-zero in case of error. */ +int +rl_unbind_key (key) + int key; +{ + return (rl_bind_key (key, (Function *)NULL)); +} - lastc = c; - rl_dispatch (c, keymap); +/* Make KEY do nothing in MAP. + Returns non-zero in case of error. */ +int +rl_unbind_key_in_map (key, map) + int key; + Keymap map; +{ + return (rl_bind_key_in_map (key, (Function *)NULL, map)); +} - /* If there was no change in last_command_was_kill, then no kill - has taken place. Note that if input is pending we are reading - a prefix command, so nothing has changed yet. */ - if (!rl_pending_input) - { - if (lk == last_command_was_kill) - last_command_was_kill = 0; - } +/* Bind the key sequence represented by the string KEYSEQ to + FUNCTION. This makes new keymaps as necessary. The initial + place to do bindings is in MAP. */ +void rl_set_key (keyseq, function, map) +char *keyseq; +Function *function; +Keymap map; +{ +rl_generic_bind (ISFUNC, keyseq, function, map); +} -#ifdef VI_MODE - /* In vi mode, when you exit insert mode, the cursor moves back - over the previous character. We explicitly check for that here. */ - if (rl_editing_mode == vi_mode && keymap == vi_movement_keymap) - rl_vi_check (); -#endif - if (!rl_done) - rl_redisplay (); - } +/* Translate the ASCII representation of SEQ, stuffing the + values into ARRAY, an array of characters. LEN gets the + final length of ARRAY. Return non-zero if there was an + error parsing SEQ. */ +int rl_translate_keyseq (seq, array, len) +char *seq, *array; +int *len; +{ +register int i, c, l = 0; - /* Restore the original of this history line, iff the line that we - are editing was originally in the history, AND the line has changed. */ - { - HIST_ENTRY *entry = current_history (); +for (i = 0; (c = seq[i]); i++) +{ +if (c == '\\') +{ +c = seq[++i]; - if (entry && rl_undo_list) - { - char *temp = savestring (the_line); - rl_revert_line (); - entry = replace_history_entry (where_history (), the_line, - (HIST_ENTRY *)NULL); - free_history_entry (entry); +if (!c) +break; - strcpy (the_line, temp); - free (temp); - } - } +if (((c == 'C' || c == 'M') && seq[i + 1] == '-') || +(c == 'e')) +{ +/* Handle special case of backwards define. */ +if (strncmp (&seq[i], "C-\\M-", 5) == 0) +{ +array[l++] = ESC; +i += 5; +array[l++] = CTRL (to_upper (seq[i])); +if (!seq[i]) +i--; +continue; +} - /* At any rate, it is highly likely that this line has an undo list. Get - rid of it now. */ - if (rl_undo_list) - free_undo_list (); +switch (c) +{ +case 'M': +i++; +array[l++] = ESC; +break; - if (eof_found) - return (char *)NULL; - else - return (savestring (the_line)); +case 'C': +i += 2; +array[l++] = CTRL (to_upper (seq[i])); +break; + +case 'e': +array[l++] = ESC; } - -/* **************************************************************** */ -/* */ -/* Signal Handling */ -/* */ -/* **************************************************************** */ +continue; +} +} +array[l++] = c; +} -#ifdef SIGWINCH -static SigHandler *old_sigwinch = (SigHandler *)NULL; +*len = l; +array[l] = '\0'; +return (0); +} -#if SVR4 -static void -rl_handle_sigwinch (sig) - int sig; -#else -static sighandler -rl_handle_sigwinch (sig, code, scp) - int sig, code; - struct sigcontext *scp; -#endif +/* Bind the key sequence represented by the string KEYSEQ to + the string of characters MACRO. This makes new keymaps as + necessary. The initial place to do bindings is in MAP. */ +void rl_macro_bind (keyseq, macro, map) + char *keyseq, *macro; + Keymap map; { - char *term = rl_terminal_name, *getenv (); + char *macro_keys = (char *)xmalloc (2 * (strlen (macro))); + int macro_keys_len; - if (readline_echoing_p) + if (rl_translate_keyseq (macro, macro_keys, ¯o_keys_len)) { - if (!term) - term = getenv ("TERM"); - if (!term) - term = "dumb"; - rl_reset_terminal (term); -#ifdef NEVER - crlf (); - rl_forced_update_display (); -#endif + free (macro_keys); + return; } + rl_generic_bind (ISMACR, keyseq, macro_keys, map); +} - if (old_sigwinch && - old_sigwinch != (SigHandler *)SIG_IGN && - old_sigwinch != (SigHandler *)SIG_DFL) -#if SVR4 - (*old_sigwinch)(sig); -#else - (*old_sigwinch)(sig, code, scp); -#endif -} -#endif /* SIGWINCH */ +/* Bind the key sequence represented by the string KEYSEQ to + the arbitrary pointer DATA. TYPE says what kind of data is + pointed to by DATA, right now this can be a function (ISFUNC), + a macro (ISMACR), or a keymap (ISKMAP). This makes new keymaps + as necessary. The initial place to do bindings is in MAP. */ +void rl_generic_bind (type, keyseq, data, map) + int type; + char *keyseq, *data; + Keymap map; +{ + char *keys; + int keys_len; + register int i; -#ifdef HANDLE_SIGNALS -/* Interrupt handling. */ -static SigHandler *old_int = (SigHandler *)NULL, - *old_tstp = (SigHandler *)NULL, - *old_ttou = (SigHandler *)NULL, - *old_ttin = (SigHandler *)NULL, - *old_cont = (SigHandler *)NULL; + /* If no keys to bind to, exit right away. */ + if (!keyseq || !*keyseq) + { + if (type == ISMACR) + free (data); + return; + } -/* Handle an interrupt character. */ -#if SVR4 -static void -rl_signal_handler (sig) - int sig; -#else -static sighandler -rl_signal_handler (sig, code, scp) - int sig, code; - struct sigcontext *scp; -#endif -{ + keys = (char *)Alloca (1 + (2 * strlen (keyseq))); -#if !defined (HAVE_BSD_SIGNALS) || defined (hpux) - /* Since the signal will not be blocked while we are in the signal - handler, ignore it until rl_clear_signals resets the catcher. */ - if (sig == SIGINT) - signal (sig, SIG_IGN); -#endif /* !HAVE_BSD_SIGNALS || hpux */ + /* Translate the ASCII representation of KEYSEQ into an array + of characters. Stuff the characters into ARRAY, and the + length of ARRAY into LENGTH. */ + if (rl_translate_keyseq (keyseq, keys, &keys_len)) + { +#if NO_ALLOCA + free (keys); +#endif + return; + } - switch (sig) + /* Bind keys, making new keymaps as necessary. */ + for (i = 0; i < keys_len; i++) { - case SIGINT: - free_undo_list (); - rl_clear_message (); - rl_init_argument (); + if (i + 1 < keys_len) + { + if (map[keys[i]].type != ISKMAP) + { + if (map[i].type == ISMACR) + free ((char *)map[i].function); -#ifdef SIGTSTP - case SIGTSTP: - case SIGTTOU: - case SIGTTIN: + map[keys[i]].type = ISKMAP; + map[keys[i]].function = (Function *)rl_make_bare_keymap (); + } + map = (Keymap)map[keys[i]].function; + } + else + { + if (map[keys[i]].type == ISMACR) + free ((char *)map[keys[i]].function); + + map[keys[i]].function = (Function *)data; + map[keys[i]].type = type; + } + } +#if NO_ALLOCA + free (keys); #endif +} - rl_clean_up_for_exit (); - rl_deprep_terminal (); - rl_clear_signals (); - rl_pending_input = 0; - kill (getpid (), sig); +/* Return a pointer to the function that STRING represents. + If STRING doesn't have a matching function, then a NULL pointer + is returned. */ +Function * +rl_named_function (string) + char *string; +{ + register int i; -#if defined (_POSIX_VERSION) - { - sigset_t set; + for (i = 0; funmap[i]; i++) + if (stricmp (funmap[i]->name, string) == 0) + return (funmap[i]->function); + return ((Function *)NULL); +} - sigemptyset (&set); - sigprocmask (SIG_SETMASK, &set, (sigset_t *)NULL); - } -#else -#if defined (HAVE_BSD_SIGNALS) - sigsetmask (0); -#endif /* HAVE_BSD_SIGNALS */ -#endif /* _POSIX_VERSION */ +/* The last key bindings file read. */ +static char *last_readline_init_file = "~/.inputrc"; + +/* Do key bindings from a file. If FILENAME is NULL it defaults + to `~/.inputrc'. If the file existed and could be opened and + read, 0 is returned, otherwise errno is returned. */ +int +rl_read_init_file (filename) + char *filename; +{ + register int i; + char *buffer, *openname, *line, *end; + struct stat finfo; + long size; + int file; - rl_prep_terminal (); - rl_set_signals (); + /* Default the filename. */ + if (!filename) + filename = last_readline_init_file; + char* tilde_expand (); + openname = tilde_expand (filename); + if ((stat (openname, &finfo) < 0) || + (file = open (openname, O_RDONLY, 0666)) < 0) + { + free (openname); + return (errno); } -} + else + free (openname); -rl_set_signals () -{ - old_int = (SigHandler *)signal (SIGINT, rl_signal_handler); - if (old_int == (SigHandler *)SIG_IGN) - signal (SIGINT, SIG_IGN); + last_readline_init_file = filename; + /* on mac os x 10.3.2 with upgrades, gcc 3.3, G5, and st_size is an int64, any expression + such as finfo.st_size + 2 always is 0. This means a 0 size memory request which later on + generates an EXC_BAD_ACCESS during malloc. The following line works around that error. + */ + size = (long)finfo.st_size; -#ifdef SIGTSTP - old_tstp = (SigHandler *)signal (SIGTSTP, rl_signal_handler); - if (old_tstp == (SigHandler *)SIG_IGN) - signal (SIGTSTP, SIG_IGN); -#endif -#ifdef SIGTTOU - old_ttou = (SigHandler *)signal (SIGTTOU, rl_signal_handler); - old_ttin = (SigHandler *)signal (SIGTTIN, rl_signal_handler); + /* Read the file into BUFFER. */ + buffer = (char *)xmalloc (size + 1); + i = read (file, buffer, size); + close (file); - if (old_tstp == (SigHandler *)SIG_IGN) + if (i != size) + return (errno); + + /* Loop over the lines in the file. Lines that start with `#' are + comments; all other lines are commands for readline initialization. */ + line = buffer; + end = buffer + size; + while (line < end) { - signal (SIGTTOU, SIG_IGN); - signal (SIGTTIN, SIG_IGN); - } -#endif + /* Find the end of this line. */ + for (i = 0; line + i != end && line[i] != '\n'; i++); -#ifdef SIGWINCH - old_sigwinch = (SigHandler *)signal (SIGWINCH, rl_handle_sigwinch); -#endif + /* Mark end of line. */ + line[i] = '\0'; + + /* If the line is not a comment, then parse it. */ + if (*line != '#') + rl_parse_and_bind (line); + + /* Move to the next line. */ + line += i + 1; + } + return (0); } -rl_clear_signals () +/* Re-read the current keybindings file. */ +rl_re_read_init_file (count, ignore) +int count, ignore; { - signal (SIGINT, old_int); - -#ifdef SIGTSTP - signal (SIGTSTP, old_tstp); -#endif +rl_read_init_file ((char *)NULL); +} -#ifdef SIGTTOU - signal (SIGTTOU, old_ttou); - signal (SIGTTIN, old_ttin); -#endif -#ifdef SIGWINCH - signal (SIGWINCH, old_sigwinch); -#endif -} -#endif /* HANDLE_SIGNALS */ - /* **************************************************************** */ /* */ -/* Character Input Buffering */ +/* Initializations */ /* */ /* **************************************************************** */ +extern int ioctl(); +/* If this system allows us to look at the values of the regular + input editing characters, then bind them to their readline + equivalents. */ +void readline_default_bindings () +{ -/* If the terminal was in xoff state when we got to it, then xon_char - contains the character that is supposed to start it again. */ -static int xon_char, xoff_state; -static int pop_index = 0, push_index = 0, ibuffer_len = 511; -static unsigned char ibuffer[512]; +#ifdef NEW_TTY_DRIVER + struct sgttyb ttybuff; + int tty = fileno (rl_instream); -/* Non-null means it is a pointer to a function to run while waiting for - character input. */ -Function *rl_event_hook = (Function *)NULL; + if (ioctl (tty, TIOCGETP, &ttybuff) != -1) + { + int erase = ttybuff.sg_erase, kill = ttybuff.sg_kill; -#define any_typein (push_index != pop_index) + if (erase != -1 && keymap[erase].type == ISFUNC) + keymap[erase].function = rl_rubout; -/* Add KEY to the buffer of characters to be read. */ -rl_stuff_char (key) - int key; -{ - if (key == EOF) - { - key = NEWLINE; - rl_pending_input = EOF; + if (kill != -1 && keymap[kill].type == ISFUNC) + keymap[kill].function = rl_unix_line_discard; } - ibuffer[push_index++] = key; - if (push_index >= ibuffer_len) - push_index = 0; -} -/* Return the amount of space available in the - buffer for stuffing characters. */ -int -ibuffer_space () -{ - if (pop_index > push_index) - return (pop_index - push_index); - else - return (ibuffer_len - (push_index - pop_index)); -} +#ifdef TIOCGLTC + { + struct ltchars lt; -/* Get a key from the buffer of characters to be read. - Return the key in KEY. - Result is KEY if there was a key, or 0 if there wasn't. */ -int -rl_get_char (key) - int *key; -{ - if (push_index == pop_index) - return (0); + if (ioctl (tty, TIOCGLTC, <) != -1) + { + int erase = lt.t_werasc, nextc = lt.t_lnextc; - *key = ibuffer[pop_index++]; + if (erase != -1 && keymap[erase].type == ISFUNC) + keymap[erase].function = rl_unix_word_rubout; - if (pop_index >= ibuffer_len) - pop_index = 0; + if (nextc != -1 && keymap[nextc].type == ISFUNC) + keymap[nextc].function = rl_quoted_insert; + } + } +#endif /* TIOCGLTC */ +#else /* not NEW_TTY_DRIVER */ - return (1); -} + #if defined (_POSIX_VERSION) + struct termios ttybuff; +#else + struct termio ttybuff; +#endif /* POSIX */ + int tty = fileno (rl_instream); -/* Stuff KEY into the *front* of the input buffer. - Returns non-zero if successful, zero if there is - no space left in the buffer. */ -int -rl_unget_char (key) - int key; -{ - if (ibuffer_space ()) +#if defined (_POSIX_VERSION) + if (tcgetattr (tty, &ttybuff) != -1) +#else + if (ioctl (tty, TCGETA, &ttybuff) != -1) +#endif /* POSIX */ { - pop_index--; - if (pop_index < 0) - pop_index = ibuffer_len - 1; - ibuffer[pop_index] = key; - return (1); + int erase = ttybuff.c_cc[VERASE]; + int kill = ttybuff.c_cc[VKILL]; + + if (erase != -1 && keymap[(unsigned char)erase].type == ISFUNC) + keymap[(unsigned char)erase].function = rl_rubout; + + if (kill != -1 && keymap[(unsigned char)kill].type == ISFUNC) + keymap[(unsigned char)kill].function = rl_unix_line_discard; } - return (0); +#endif /* NEW_TTY_DRIVER */ } -/* If a character is available to be read, then read it - and stuff it into IBUFFER. Otherwise, just return. */ -void rl_gather_tyi () +/* Initialize the entire state of the world. */ +void readline_initialize_everything () { - int tty = fileno (in_stream); - register int tem, result = -1; - long chars_avail; - char input; + char* getenv(); + rl_instream = stdin; + rl_outstream = stdout; + /* Find out if we are running in Emacs. */ + running_in_emacs = getenv ("EMACS"); -#if 0 && defined(FIONREAD) - result = ioctl (tty, FIONREAD, &chars_avail); -#endif + /* Allocate data structures. */ + if (!rl_line_buffer) + rl_line_buffer = + (char *)xmalloc (rl_line_buffer_len = DEFAULT_BUFFER_SIZE); - if (result == -1) - { - fcntl (tty, F_SETFL, O_NDELAY); - chars_avail = read (tty, &input, 1); - fcntl (tty, F_SETFL, 0); - if (chars_avail == -1 && errno == EAGAIN) - return; - } + /* Initialize the terminal interface. */ + init_terminal_io ((char *)NULL); - /* If there's nothing available, don't waste time trying to read - something. */ - if (chars_avail == 0) - return; + /* Bind tty characters to readline functions. */ + readline_default_bindings (); - tem = ibuffer_space (); + /* Initialize the function names. */ + extern void rl_initialize_funmap(); + rl_initialize_funmap (); - if (chars_avail > tem) - chars_avail = tem; -#if __alpha -/* I think there is a bug in the dec alpha cc compiler since with -chars_avail = 1 and tem=512 it still executes the body of the if above. -*/ -chars_avail = 1; -#endif - /* One cannot read all of the available input. I can only read a single - character at a time, or else programs which require input can be - thwarted. If the buffer is larger than one character, I lose. - Damn! */ - if (tem < ibuffer_len) - chars_avail = 0; + /* Read in the init file. */ + rl_read_init_file ((char *)NULL); - if (result != -1) - { - while (chars_avail--) - rl_stuff_char (rl_getc (in_stream)); - } - else + /* If the completion parser's default word break characters haven't + been set yet, then do so now. */ { - if (chars_avail) - rl_stuff_char (input); + extern char *rl_completer_word_break_characters; + extern char *rl_basic_word_break_characters; + + if (rl_completer_word_break_characters == (char *)NULL) + rl_completer_word_break_characters = rl_basic_word_break_characters; } } -/* Read a key, including pending input. */ -int -rl_read_key () +extern rl_on_new_line(); +/* Initliaze readline (and terminal if not already). */ +void rl_initialize () { - int c; - - rl_key_sequence_length++; + extern char *rl_display_prompt; - if (rl_pending_input) + /* If we have never been called before, initialize the + terminal and data structures. */ + if (!rl_initialized) { - c = rl_pending_input; - rl_pending_input = 0; + readline_initialize_everything (); + rl_initialized++; } - else - { - /* If input is coming from a macro, then use that. */ - if (c = next_macro_key ()) - return (c); - /* If the user has an event function, then call it periodically. */ - if (rl_event_hook) - { -#if defined(CYGWIN) - int cnt=0; -#endif - while (rl_event_hook && !rl_get_char (&c)) - { - (*rl_event_hook) (); - rl_gather_tyi (); -#if defined(CYGWIN) -/* when the rxvt is closed, then the symptom is that input -is perpetually ready from the HandleStdin::inputReady but there -are no characters. Apparently there is no direct test there that -stdin is no longer available (errno, F_GETFL, F_GETFD do not change) -so this kludge is used. -*/ - if (++cnt > 1000) { -#if 0 - debugfile("cnt=%d\n", cnt); -#endif - rl_stuff_char(eof_char); - break; - } -#endif - } - } - else - { - if (!rl_get_char (&c)) - c = rl_getc (in_stream); - } - } + /* Initalize the current line information. */ + rl_point = rl_end = 0; + the_line = rl_line_buffer; + the_line[0] = 0; -#ifdef NEVER /* This breaks supdup to 4.0.3c machines. */ -#ifdef TIOCSTART - /* Ugh. But I can't think of a better way. */ - if (xoff_state && c == xon_char) + /* We aren't done yet. We haven't even gotten started yet! */ + rl_done = 0; + + /* Tell the history routines what is going on. */ + start_using_history (); + + /* Make the display buffer match the state of the line. */ { - ioctl (fileno (in_stream), TIOCSTART, 0); - xoff_state = 0; - return (rl_read_key ()); + extern char *rl_display_prompt; + extern int forced_display; + rl_on_new_line (); + + rl_display_prompt = rl_prompt ? rl_prompt : ""; + forced_display = 1; } -#endif /* TIOCSTART */ -#endif - return (c); -} + /* No such function typed yet. */ + rl_last_func = (Function *)NULL; -/* I'm beginning to hate the declaration rules for various compilers. */ -static void add_macro_char (); + /* Parsing of key-bindings begins in an enabled state. */ + parsing_conditionalized_out = 0; +} -/* Do the command associated with KEY in MAP. - If the associated command is really a keymap, then read - another key, and dispatch into that map. */ -void rl_dispatch (key, map) - register int key; - Keymap map; -{ - if (defining_kbd_macro) - add_macro_char (key); - if (key > 127 && key < 256) - { - if (map[ESC].type == ISKMAP) - { - map = (Keymap)map[ESC].function; - key -= 128; - rl_dispatch (key, map); - } - else - ding (); - return; - } +/* **************************************************************** */ +/* */ +/* Terminal and Termcap */ +/* */ +/* **************************************************************** */ - switch (map[key].type) - { - case ISFUNC: - { - Function *func = map[key].function; +extern int tgetnum(); +extern int tgetent(); +extern int tputs(); - if (func != (Function *)NULL) - { - /* Special case rl_do_lowercase_version (). */ - if (func == rl_do_lowercase_version) - { - rl_dispatch (to_lower (key), map); - return; - } +static char *term_buffer = (char *)NULL; +static char *term_string_buffer = (char *)NULL; - (*map[key].function)(rl_numeric_arg * arg_sign, key); +/* Non-zero means this terminal can't really do anything. */ +int dumb_term = 0; - /* If we have input pending, then the last command was a prefix - command. Don't change the state of rl_last_func. Otherwise, - remember the last command executed in this variable. */ - if (!rl_pending_input) - rl_last_func = map[key].function; - } - else - { - rl_abort (); - return; - } - } - break; +/* Some strings to control terminal actions. These are output by tputs (). */ +char *term_goto, *term_clreol, *term_cr, *term_clrpag, *term_backspace; - case ISKMAP: - if (map[key].function != (Function *)NULL) - { - int newkey; +int screenwidth, screenheight; - rl_key_sequence_length++; - newkey = rl_read_key (); - rl_dispatch (newkey, (Keymap)map[key].function); - } - else - { - rl_abort (); - return; - } - break; +/* Non-zero if we determine that the terminal can do character insertion. */ +int terminal_can_insert = 0; - case ISMACR: - if (map[key].function != (Function *)NULL) - { - char *macro = savestring ((char *)map[key].function); +/* How to insert characters. */ +char *term_im, *term_ei, *term_ic, *term_ip, *term_IC; - with_macro_input (macro); - return; - } - break; - } +/* How to delete characters. */ +char *term_dc, *term_DC; + +#ifdef HACK_TERMCAP_MOTION +char *term_forward_char; +#endif /* HACK_TERMCAP_MOTION */ + +/* How to go up a line. */ +char *term_up; + +/* A visible bell, if the terminal can be made to flash the screen. */ +char *visible_bell; + +/* Re-initialize the terminal considering that the TERM/TERMCAP variable + has changed. */ +rl_reset_terminal (terminal_name) +char *terminal_name; +{ +init_terminal_io (terminal_name); } - -/* **************************************************************** */ -/* */ -/* Hacking Keyboard Macros */ -/* */ -/* **************************************************************** */ +void init_terminal_io (terminal_name) + char *terminal_name; +{ + char* getenv(); + char *term = (terminal_name? terminal_name : getenv ("TERM")); + char *tgetstr (), *buffer; +#ifdef TIOCGWINSZ + struct winsize window_size; +#endif + int tty; -/* The currently executing macro string. If this is non-zero, - then it is a malloc ()'ed string where input is coming from. */ -static char *executing_macro = (char *)NULL; + if (!term_string_buffer) + term_string_buffer = (char *)xmalloc (2048); -/* The offset in the above string to the next character to be read. */ -static int executing_macro_index = 0; + if (!term_buffer) + term_buffer = (char *)xmalloc (2048); -/* The current macro string being built. Characters get stuffed - in here by add_macro_char (). */ -static char *current_macro = (char *)NULL; + buffer = term_string_buffer; -/* The size of the buffer allocated to current_macro. */ -static int current_macro_size = 0; + term_clrpag = term_cr = term_clreol = (char *)NULL; -/* The index at which characters are being added to current_macro. */ -static int current_macro_index = 0; + if (!term) + term = "dumb"; -/* A structure used to save nested macro strings. - It is a linked list of string/index for each saved macro. */ -struct saved_macro { - struct saved_macro *next; - char *string; - int index; -}; +#if defined(CYGWIN) + /* some machines. eg. windows 98 se. hang for up to 30 seconds when +HOME=/ because terminfo is looked for in $HOME/.terminfo and the // +is a network call. So if TERMINFO is not an environment variable +and term=xterm we set it to neuronhome/lib and get neuronhome/lib/x/xterm +*/ + if (!getenv("TERMINFO") && strcmp(term, "xterm") == 0) { + extern char* neuron_home; + extern char* hoc_back2forward(); + sprintf(term_buffer, "TERMINFO=%s/lib", hoc_back2forward(neuron_home)); + putenv(term_buffer); + } +#endif -/* The list of saved macros. */ -struct saved_macro *macro_list = (struct saved_macro *)NULL; + if (tgetent (term_buffer, term) < 0) + { + dumb_term = 1; + return; + } -/* Forward declarations of static functions. Thank you C. */ -static void push_executing_macro (), pop_executing_macro (); + tgetstr ("pc", &buffer); -/* This one has to be declared earlier in the file. */ -/* static void add_macro_char (); */ + term_backspace = tgetstr ("le", &buffer); -/* Set up to read subsequent input from STRING. - STRING is free ()'ed when we are done with it. */ -static -with_macro_input (string) - char *string; -{ - push_executing_macro (); - executing_macro = string; - executing_macro_index = 0; -} + term_cr = tgetstr ("cr", &buffer); + term_clreol = tgetstr ("ce", &buffer); + term_clrpag = tgetstr ("cl", &buffer); -/* Return the next character available from a macro, or 0 if - there are no macro characters. */ -static int -next_macro_key () -{ - if (!executing_macro) - return (0); + if (!term_cr) + term_cr = "\r"; + +#ifdef HACK_TERMCAP_MOTION + term_forward_char = tgetstr ("nd", &buffer); +#endif /* HACK_TERMCAP_MOTION */ + + if (rl_instream) + tty = fileno (rl_instream); + else + tty = 0; + + screenwidth = screenheight = 0; +#ifdef TIOCGWINSZ + if (ioctl (tty, TIOCGWINSZ, &window_size) == 0) + { + screenwidth = (int) window_size.ws_col; + screenheight = (int) window_size.ws_row; + } +#endif - if (!executing_macro[executing_macro_index]) + if (screenwidth <= 0 || screenheight <= 0) { - pop_executing_macro (); - return (next_macro_key ()); + screenwidth = tgetnum ("co"); + screenheight = tgetnum ("li"); } - return (executing_macro[executing_macro_index++]); + screenwidth--; + + if (screenwidth <= 0) + screenwidth = 79; + + if (screenheight <= 0) + screenheight = 24; + + term_im = tgetstr ("im", &buffer); + term_ei = tgetstr ("ei", &buffer); + term_IC = tgetstr ("IC", &buffer); + term_ic = tgetstr ("ic", &buffer); + + /* "An application program can assume that the terminal can do + character insertion if *any one of* the capabilities `IC', + `im', `ic' or `ip' is provided." But we can't do anything if + only `ip' is provided, so... */ + terminal_can_insert = (term_IC || term_im || term_ic); + + term_up = tgetstr ("up", &buffer); + term_dc = tgetstr ("dc", &buffer); + term_DC = tgetstr ("DC", &buffer); + + visible_bell = tgetstr ("vb", &buffer); } -/* Save the currently executing macro on a stack of saved macros. */ +/* A function for the use of tputs () */ static void -push_executing_macro () +output_character_function (c) + int c; { - struct saved_macro *saver; - - saver = (struct saved_macro *)xmalloc (sizeof (struct saved_macro)); - saver->next = macro_list; - saver->index = executing_macro_index; - saver->string = executing_macro; - - macro_list = saver; + putc (c, out_stream); } -/* Discard the current macro, replacing it with the one - on the top of the stack of saved macros. */ +/* Write COUNT characters from STRING to the output stream. */ static void -pop_executing_macro () +output_some_chars (string, count) + char *string; + int count; { - if (executing_macro) - free (executing_macro); + fwrite (string, 1, count, out_stream); +} - executing_macro = (char *)NULL; - executing_macro_index = 0; +/* Delete COUNT characters from the display line. */ +static void +delete_chars (count) + int count; +{ + if (count > screenwidth) + return; - if (macro_list) + if (term_DC && *term_DC) { - struct saved_macro *disposer = macro_list; - executing_macro = macro_list->string; - executing_macro_index = macro_list->index; - macro_list = macro_list->next; - free (disposer); + char *tgoto (), *buffer; + buffer = tgoto (term_DC, 0, count); + tputs (buffer, 1, output_character_function); + } + else + { + if (term_dc && *term_dc) + while (count--) + tputs (term_dc, 1, output_character_function); } } -/* Add a character to the macro being built. */ -static void -add_macro_char (c) - int c; +/* Insert COUNT characters from STRING to the output stream. */ +static +insert_some_chars (string, count) +char *string; +int count; { - if (current_macro_index + 1 >= current_macro_size) + /* If IC is defined, then we do not have to "enter" insert mode. */ + if (term_IC) { - if (!current_macro) - current_macro = (char *)xmalloc (current_macro_size = 25); - else - current_macro = - (char *)xrealloc (current_macro, current_macro_size += 25); + char *tgoto (), *buffer; + buffer = tgoto (term_IC, 0, count); + tputs (buffer, 1, output_character_function); + output_some_chars (string, count); } + else + { + register int i; - current_macro[current_macro_index++] = c; - current_macro[current_macro_index] = '\0'; -} + /* If we have to turn on insert-mode, then do so. */ + if (term_im && *term_im) + tputs (term_im, 1, output_character_function); -/* Begin defining a keyboard macro. - Keystrokes are recorded as they are executed. - End the definition with rl_end_kbd_macro (). - If a numeric argument was explicitly typed, then append this - definition to the end of the existing macro, and start by - re-executing the existing macro. */ -rl_start_kbd_macro (ignore1, ignore2) - int ignore1, ignore2; -{ - if (defining_kbd_macro) - rl_abort (); + /* If there is a special command for inserting characters, then + use that first to open up the space. */ + if (term_ic && *term_ic) + { + for (i = count; i--; ) + tputs (term_ic, 1, output_character_function); + } - if (rl_explicit_arg) - { - if (current_macro) - with_macro_input (savestring (current_macro)); - } - else - current_macro_index = 0; + /* Print the text. */ + output_some_chars (string, count); - defining_kbd_macro = 1; + /* If there is a string to turn off insert mode, we had best use + it now. */ + if (term_ei && *term_ei) + tputs (term_ei, 1, output_character_function); + } } -/* Stop defining a keyboard macro. - A numeric argument says to execute the macro right now, - that many times, counting the definition as the first time. */ -rl_end_kbd_macro (count, ignore) - int count, ignore; +/* Move the cursor back. */ +backspace (count) +int count; { - if (!defining_kbd_macro) - rl_abort (); - - current_macro_index -= (rl_key_sequence_length - 1); - current_macro[current_macro_index] = '\0'; - - defining_kbd_macro = 0; + register int i; - rl_call_last_kbd_macro (--count, 0); + if (term_backspace) + for (i = 0; i < count; i++) + tputs (term_backspace, 1, output_character_function); + else + for (i = 0; i < count; i++) + putc ('\b', out_stream); } -/* Execute the most recently defined keyboard macro. - COUNT says how many times to execute it. */ -rl_call_last_kbd_macro (count, ignore) - int count, ignore; +/* Move to the start of the next line. */ +crlf () { - if (!current_macro) - rl_abort (); - - while (count--) - with_macro_input (savestring (current_macro)); + tputs (term_cr, 1, output_character_function); + putc ('\n', out_stream); } - -/* **************************************************************** */ -/* */ -/* Initializations */ -/* */ -/* **************************************************************** */ - -/* Initliaze readline (and terminal if not already). */ -rl_initialize () -{ - extern char *rl_display_prompt; - - /* If we have never been called before, initialize the - terminal and data structures. */ - if (!rl_initialized) - { - readline_initialize_everything (); - rl_initialized++; - } - - /* Initalize the current line information. */ - rl_point = rl_end = 0; - the_line = rl_line_buffer; - the_line[0] = 0; - - /* We aren't done yet. We haven't even gotten started yet! */ - rl_done = 0; - - /* Tell the history routines what is going on. */ - start_using_history (); - - /* Make the display buffer match the state of the line. */ - { - extern char *rl_display_prompt; - extern int forced_display; - - rl_on_new_line (); - - rl_display_prompt = rl_prompt ? rl_prompt : ""; - forced_display = 1; - } - - /* No such function typed yet. */ - rl_last_func = (Function *)NULL; - - /* Parsing of key-bindings begins in an enabled state. */ - parsing_conditionalized_out = 0; -} - -/* Initialize the entire state of the world. */ -readline_initialize_everything () -{ - char* getenv(); - rl_instream = stdin; - rl_outstream = stdout; - /* Find out if we are running in Emacs. */ - running_in_emacs = getenv ("EMACS"); - - /* Allocate data structures. */ - if (!rl_line_buffer) - rl_line_buffer = - (char *)xmalloc (rl_line_buffer_len = DEFAULT_BUFFER_SIZE); - - /* Initialize the terminal interface. */ - init_terminal_io ((char *)NULL); - - /* Bind tty characters to readline functions. */ - readline_default_bindings (); - - /* Initialize the function names. */ - rl_initialize_funmap (); - - /* Read in the init file. */ - rl_read_init_file ((char *)NULL); - - /* If the completion parser's default word break characters haven't - been set yet, then do so now. */ - { - extern char *rl_completer_word_break_characters; - extern char *rl_basic_word_break_characters; - - if (rl_completer_word_break_characters == (char *)NULL) - rl_completer_word_break_characters = rl_basic_word_break_characters; - } -} - -/* If this system allows us to look at the values of the regular - input editing characters, then bind them to their readline - equivalents. */ -readline_default_bindings () -{ - -#ifdef NEW_TTY_DRIVER - struct sgttyb ttybuff; - int tty = fileno (rl_instream); - - if (ioctl (tty, TIOCGETP, &ttybuff) != -1) - { - int erase = ttybuff.sg_erase, kill = ttybuff.sg_kill; - - if (erase != -1 && keymap[erase].type == ISFUNC) - keymap[erase].function = rl_rubout; - - if (kill != -1 && keymap[kill].type == ISFUNC) - keymap[kill].function = rl_unix_line_discard; - } - -#ifdef TIOCGLTC - { - struct ltchars lt; - - if (ioctl (tty, TIOCGLTC, <) != -1) - { - int erase = lt.t_werasc, nextc = lt.t_lnextc; - - if (erase != -1 && keymap[erase].type == ISFUNC) - keymap[erase].function = rl_unix_word_rubout; - - if (nextc != -1 && keymap[nextc].type == ISFUNC) - keymap[nextc].function = rl_quoted_insert; - } - } -#endif /* TIOCGLTC */ -#else /* not NEW_TTY_DRIVER */ - -#if defined (_POSIX_VERSION) - struct termios ttybuff; -#else - struct termio ttybuff; -#endif /* POSIX */ - int tty = fileno (rl_instream); - -#if defined (_POSIX_VERSION) - if (tcgetattr (tty, &ttybuff) != -1) -#else - if (ioctl (tty, TCGETA, &ttybuff) != -1) -#endif /* POSIX */ - { - int erase = ttybuff.c_cc[VERASE]; - int kill = ttybuff.c_cc[VKILL]; - - if (erase != -1 && keymap[(unsigned char)erase].type == ISFUNC) - keymap[(unsigned char)erase].function = rl_rubout; - - if (kill != -1 && keymap[(unsigned char)kill].type == ISFUNC) - keymap[(unsigned char)kill].function = rl_unix_line_discard; - } -#endif /* NEW_TTY_DRIVER */ -} - - -/* **************************************************************** */ -/* */ -/* Numeric Arguments */ -/* */ -/* **************************************************************** */ - -/* Handle C-u style numeric args, as well as M--, and M-digits. */ - -/* Add the current digit to the argument in progress. */ -rl_digit_argument (ignore, key) - int ignore, key; -{ - rl_pending_input = key; - rl_digit_loop (); -} - -/* What to do when you abort reading an argument. */ -rl_discard_argument () -{ - ding (); - rl_clear_message (); - rl_init_argument (); -} - -/* Create a default argument. */ -rl_init_argument () -{ - rl_numeric_arg = arg_sign = 1; - rl_explicit_arg = 0; -} - -/* C-u, universal argument. Multiply the current argument by 4. - Read a key. If the key has nothing to do with arguments, then - dispatch on it. If the key is the abort character then abort. */ -rl_universal_argument () -{ - rl_numeric_arg *= 4; - rl_digit_loop (); -} - -void rl_digit_loop () -{ - int key, c; - while (1) - { - rl_message ("(arg: %d) ", arg_sign * rl_numeric_arg); - key = c = rl_read_key (); - - if (keymap[c].type == ISFUNC && - keymap[c].function == rl_universal_argument) - { - rl_numeric_arg *= 4; - continue; - } - c = UNMETA (c); - if (numeric (c)) - { - if (rl_explicit_arg) - rl_numeric_arg = (rl_numeric_arg * 10) + (c - '0'); - else - rl_numeric_arg = (c - '0'); - rl_explicit_arg = 1; - } - else - { - if (c == '-' && !rl_explicit_arg) - { - rl_numeric_arg = 1; - arg_sign = -1; - } - else - { - rl_clear_message (); - rl_dispatch (key, keymap); - return; - } - } - } -} - - + + /* **************************************************************** */ /* */ /* Display stuff */ @@ -1458,211 +1263,235 @@ static void output_some_chars (); static void output_character_function (); static int compare_strings (); + +/* Clear to the end of the line. COUNT is the minimum + number of character spaces to clear, */ +clear_to_eol (count) +int count; +{ + if (term_clreol) + { + tputs (term_clreol, 1, output_character_function); + } + else + { + register int i; + + /* Do one more character space. */ + count++; + + for (i = 0; i < count; i++) + putc (' ', out_stream); + + backspace (count); + } +} + /* Basic redisplay algorithm. */ void rl_redisplay () { - register int in, out, c, linenum; - register char *line = invisible_line; - char *prompt_this_line; - int c_pos = 0; - int inv_botlin = 0; /* Number of lines in newly drawn buffer. */ + register int in, out, c, linenum; + register char *line = invisible_line; + char *prompt_this_line; + int c_pos = 0; + int inv_botlin = 0; /* Number of lines in newly drawn buffer. */ - extern int readline_echoing_p; + extern int readline_echoing_p; - if (!readline_echoing_p) - return; + if (!readline_echoing_p) + return; - if (!rl_display_prompt) - rl_display_prompt = ""; + if (!rl_display_prompt) + rl_display_prompt = ""; - if (!invisible_line) + if (!invisible_line) { - visible_line = (char *)xmalloc (line_size); - invisible_line = (char *)xmalloc (line_size); - line = invisible_line; - for (in = 0; in < line_size; in++) - { - visible_line[in] = 0; - invisible_line[in] = 1; - } - rl_on_new_line (); + visible_line = (char *)xmalloc (line_size); + invisible_line = (char *)xmalloc (line_size); + line = invisible_line; + for (in = 0; in < line_size; in++) + { + visible_line[in] = 0; + invisible_line[in] = 1; + } + rl_on_new_line (); } - /* Draw the line into the buffer. */ - c_pos = -1; + /* Draw the line into the buffer. */ + c_pos = -1; - /* Mark the line as modified or not. We only do this for history - lines. */ - out = 0; - if (mark_modified_lines && current_history () && rl_undo_list) + /* Mark the line as modified or not. We only do this for history + lines. */ + out = 0; + if (mark_modified_lines && current_history () && rl_undo_list) { - line[out++] = '*'; - line[out] = '\0'; + line[out++] = '*'; + line[out] = '\0'; } - /* If someone thought that the redisplay was handled, but the currently - visible line has a different modification state than the one about - to become visible, then correct the callers misconception. */ - if (visible_line[0] != invisible_line[0]) - rl_display_fixed = 0; + /* If someone thought that the redisplay was handled, but the currently + visible line has a different modification state than the one about + to become visible, then correct the callers misconception. */ + if (visible_line[0] != invisible_line[0]) + rl_display_fixed = 0; - prompt_this_line = rindex (rl_display_prompt, '\n'); - if (!prompt_this_line) - prompt_this_line = rl_display_prompt; - else + prompt_this_line = rindex (rl_display_prompt, '\n'); + if (!prompt_this_line) + prompt_this_line = rl_display_prompt; + else { - prompt_this_line++; - if (forced_display) - output_some_chars (rl_display_prompt, - prompt_this_line - rl_display_prompt); + prompt_this_line++; + if (forced_display) + output_some_chars (rl_display_prompt, + prompt_this_line - rl_display_prompt); } - strncpy (line + out, prompt_this_line, strlen (prompt_this_line)); - out += strlen (prompt_this_line); - line[out] = '\0'; + strncpy (line + out, prompt_this_line, strlen (prompt_this_line)); + out += strlen (prompt_this_line); + line[out] = '\0'; - for (in = 0; in < rl_end; in++) + for (in = 0; in < rl_end; in++) { - c = the_line[in]; + c = the_line[in]; - if (out + 1 >= line_size) - { - line_size *= 2; - visible_line = (char *)xrealloc (visible_line, line_size); - invisible_line = (char *)xrealloc (invisible_line, line_size); - line = invisible_line; - } + if (out + 1 >= line_size) + { + line_size *= 2; + visible_line = (char *)xrealloc (visible_line, line_size); + invisible_line = (char *)xrealloc (invisible_line, line_size); + line = invisible_line; + } - if (in == rl_point) - c_pos = out; + if (in == rl_point) + c_pos = out; - if (c > 127) - { - line[out++] = 'M'; - line[out++] = '-'; - line[out++] = c - 128; - } + if (c > 127) + { + line[out++] = 'M'; + line[out++] = '-'; + line[out++] = c - 128; + } #define DISPLAY_TABS #ifdef DISPLAY_TABS - else if (c == '\t') - { - register int newout = (out | (int)7) + 1; - while (out < newout) - line[out++] = ' '; - } + else if (c == '\t') + { + register int newout = (out | (int)7) + 1; + while (out < newout) + line[out++] = ' '; + } #endif - else if (c < 32) - { - line[out++] = 'C'; - line[out++] = '-'; - line[out++] = c + 64; - } - else - line[out++] = c; - } - line[out] = '\0'; - if (c_pos < 0) - c_pos = out; - - /* PWP: now is when things get a bit hairy. The visible and invisible - line buffers are really multiple lines, which would wrap every - (screenwidth - 1) characters. Go through each in turn, finding - the changed region and updating it. The line order is top to bottom. */ - - /* If we can move the cursor up and down, then use multiple lines, - otherwise, let long lines display in a single terminal line, and - horizontally scroll it. */ - - if (!horizontal_scroll_mode && term_up && *term_up) - { - int total_screen_chars = (screenwidth * screenheight); - - if (!rl_display_fixed || forced_display) - { - forced_display = 0; - - /* If we have more than a screenful of material to display, then - only display a screenful. We should display the last screen, - not the first. I'll fix this in a minute. */ - if (out >= total_screen_chars) - out = total_screen_chars - 1; - - /* Number of screen lines to display. */ - inv_botlin = out / screenwidth; - - /* For each line in the buffer, do the updating display. */ - for (linenum = 0; linenum <= inv_botlin; linenum++) - update_line (linenum > vis_botlin ? "" - : &visible_line[linenum * screenwidth], - &invisible_line[linenum * screenwidth], - linenum); - - /* We may have deleted some lines. If so, clear the left over - blank ones at the bottom out. */ - if (vis_botlin > inv_botlin) - { - char *tt; - for (; linenum <= vis_botlin; linenum++) - { - tt = &visible_line[linenum * screenwidth]; - move_vert (linenum); - move_cursor_relative (0, tt); - clear_to_eol ((linenum == vis_botlin)? - strlen (tt) : screenwidth); - } - } - vis_botlin = inv_botlin; - - /* Move the cursor where it should be. */ - move_vert (c_pos / screenwidth); - move_cursor_relative (c_pos % screenwidth, - &invisible_line[(c_pos / screenwidth) * screenwidth]); - } + else if (c < 32) + { + line[out++] = 'C'; + line[out++] = '-'; + line[out++] = c + 64; + } + else + line[out++] = c; + } + line[out] = '\0'; + if (c_pos < 0) + c_pos = out; + + /* PWP: now is when things get a bit hairy. The visible and invisible + line buffers are really multiple lines, which would wrap every + (screenwidth - 1) characters. Go through each in turn, finding + the changed region and updating it. The line order is top to bottom. */ + + /* If we can move the cursor up and down, then use multiple lines, + otherwise, let long lines display in a single terminal line, and + horizontally scroll it. */ + + if (!horizontal_scroll_mode && term_up && *term_up) + { + int total_screen_chars = (screenwidth * screenheight); + + if (!rl_display_fixed || forced_display) + { + forced_display = 0; + + /* If we have more than a screenful of material to display, then + only display a screenful. We should display the last screen, + not the first. I'll fix this in a minute. */ + if (out >= total_screen_chars) + out = total_screen_chars - 1; + + /* Number of screen lines to display. */ + inv_botlin = out / screenwidth; + + /* For each line in the buffer, do the updating display. */ + for (linenum = 0; linenum <= inv_botlin; linenum++) + update_line (linenum > vis_botlin ? "" + : &visible_line[linenum * screenwidth], + &invisible_line[linenum * screenwidth], + linenum); + + /* We may have deleted some lines. If so, clear the left over + blank ones at the bottom out. */ + if (vis_botlin > inv_botlin) + { + char *tt; + for (; linenum <= vis_botlin; linenum++) + { + tt = &visible_line[linenum * screenwidth]; + move_vert (linenum); + move_cursor_relative (0, tt); + clear_to_eol ((linenum == vis_botlin)? + strlen (tt) : screenwidth); + } + } + vis_botlin = inv_botlin; + + /* Move the cursor where it should be. */ + move_vert (c_pos / screenwidth); + move_cursor_relative (c_pos % screenwidth, + &invisible_line[(c_pos / screenwidth) * screenwidth]); + } + } + else /* Do horizontal scrolling. */ + { + int lmargin; + + /* Always at top line. */ + last_v_pos = 0; + + /* If the display position of the cursor would be off the edge + of the screen, start the display of this line at an offset that + leaves the cursor on the screen. */ + if (c_pos - last_lmargin > screenwidth - 2) + lmargin = (c_pos / (screenwidth / 3) - 2) * (screenwidth / 3); + else if (c_pos - last_lmargin < 1) + lmargin = ((c_pos - 1) / (screenwidth / 3)) * (screenwidth / 3); + else + lmargin = last_lmargin; + + /* If the first character on the screen isn't the first character + in the display line, indicate this with a special character. */ + if (lmargin > 0) + line[lmargin] = '<'; + + if (lmargin + screenwidth < out) + line[lmargin + screenwidth - 1] = '>'; + + if (!rl_display_fixed || forced_display || lmargin != last_lmargin) + { + forced_display = 0; + update_line (&visible_line[last_lmargin], + &invisible_line[lmargin], 0); + + move_cursor_relative (c_pos - lmargin, &invisible_line[lmargin]); + last_lmargin = lmargin; + } + } + + fflush (out_stream); + /* Swap visible and non-visible lines. */ + { + char *temp = visible_line; + visible_line = invisible_line; + invisible_line = temp; + rl_display_fixed = 0; } - else /* Do horizontal scrolling. */ - { - int lmargin; - - /* Always at top line. */ - last_v_pos = 0; - - /* If the display position of the cursor would be off the edge - of the screen, start the display of this line at an offset that - leaves the cursor on the screen. */ - if (c_pos - last_lmargin > screenwidth - 2) - lmargin = (c_pos / (screenwidth / 3) - 2) * (screenwidth / 3); - else if (c_pos - last_lmargin < 1) - lmargin = ((c_pos - 1) / (screenwidth / 3)) * (screenwidth / 3); - else - lmargin = last_lmargin; - - /* If the first character on the screen isn't the first character - in the display line, indicate this with a special character. */ - if (lmargin > 0) - line[lmargin] = '<'; - - if (lmargin + screenwidth < out) - line[lmargin + screenwidth - 1] = '>'; - - if (!rl_display_fixed || forced_display || lmargin != last_lmargin) - { - forced_display = 0; - update_line (&visible_line[last_lmargin], - &invisible_line[lmargin], 0); - - move_cursor_relative (c_pos - lmargin, &invisible_line[lmargin]); - last_lmargin = lmargin; - } - } - - fflush (out_stream); - /* Swap visible and non-visible lines. */ - { - char *temp = visible_line; - visible_line = invisible_line; - invisible_line = temp; - rl_display_fixed = 0; - } } /* PWP: update_line() is based on finding the middle difference of each @@ -1683,120 +1512,120 @@ new: eddie> Oh, my little buggy says to me, as lurgid as Could be made even smarter, but this works well enough */ static void update_line (old, new, current_line) - register char *old, *new; - int current_line; -{ - register char *ofd, *ols, *oe, *nfd, *nls, *ne; - int lendiff, wsatend; - - /* Find first difference. */ - for (ofd = old, nfd = new; - (ofd - old < screenwidth) && *ofd && (*ofd == *nfd); - ofd++, nfd++) - ; - - /* Move to the end of the screen line. */ - for (oe = ofd; ((oe - old) < screenwidth) && *oe; oe++); - for (ne = nfd; ((ne - new) < screenwidth) && *ne; ne++); - - /* If no difference, continue to next line. */ - if (ofd == oe && nfd == ne) - return; - - wsatend = 1; /* flag for trailing whitespace */ - ols = oe - 1; /* find last same */ - nls = ne - 1; - while ((ols > ofd) && (nls > nfd) && (*ols == *nls)) - { - if (*ols != ' ') - wsatend = 0; - ols--; - nls--; - } - - if (wsatend) - { - ols = oe; - nls = ne; - } - else if (*ols != *nls) - { - if (*ols) /* don't step past the NUL */ - ols++; - if (*nls) - nls++; - } - - move_vert (current_line); - move_cursor_relative (ofd - old, old); - - /* if (len (new) > len (old)) */ - lendiff = (nls - nfd) - (ols - ofd); - - /* Insert (diff(len(old),len(new)) ch */ - if (lendiff > 0) - { - if (terminal_can_insert) - { - extern char *term_IC; - - /* Sometimes it is cheaper to print the characters rather than - use the terminal's capabilities. */ - if ((2 * (ne - nfd)) < lendiff && !term_IC) - { - output_some_chars (nfd, (ne - nfd)); - last_c_pos += (ne - nfd); - } - else - { - if (*ols) - { - insert_some_chars (nfd, lendiff); - last_c_pos += lendiff; - } - else - { - /* At the end of a line the characters do not have to - be "inserted". They can just be placed on the screen. */ - output_some_chars (nfd, lendiff); - last_c_pos += lendiff; - } - /* Copy (new) chars to screen from first diff to last match. */ - if (((nls - nfd) - lendiff) > 0) - { - output_some_chars (&nfd[lendiff], ((nls - nfd) - lendiff)); - last_c_pos += ((nls - nfd) - lendiff); - } - } - } - else - { /* cannot insert chars, write to EOL */ - output_some_chars (nfd, (ne - nfd)); - last_c_pos += (ne - nfd); - } - } - else /* Delete characters from line. */ - { - /* If possible and inexpensive to use terminal deletion, then do so. */ - if (term_dc && (2 * (ne - nfd)) >= (-lendiff)) - { - if (lendiff) - delete_chars (-lendiff); /* delete (diff) characters */ - - /* Copy (new) chars to screen from first diff to last match */ - if ((nls - nfd) > 0) - { - output_some_chars (nfd, (nls - nfd)); - last_c_pos += (nls - nfd); - } - } - /* Otherwise, print over the existing material. */ - else - { - output_some_chars (nfd, (ne - nfd)); - last_c_pos += (ne - nfd); - clear_to_eol ((oe - old) - (ne - new)); - } + register char *old, *new; + int current_line; +{ + register char *ofd, *ols, *oe, *nfd, *nls, *ne; + int lendiff, wsatend; + + /* Find first difference. */ + for (ofd = old, nfd = new; + (ofd - old < screenwidth) && *ofd && (*ofd == *nfd); + ofd++, nfd++) + ; + + /* Move to the end of the screen line. */ + for (oe = ofd; ((oe - old) < screenwidth) && *oe; oe++); + for (ne = nfd; ((ne - new) < screenwidth) && *ne; ne++); + + /* If no difference, continue to next line. */ + if (ofd == oe && nfd == ne) + return; + + wsatend = 1; /* flag for trailing whitespace */ + ols = oe - 1; /* find last same */ + nls = ne - 1; + while ((ols > ofd) && (nls > nfd) && (*ols == *nls)) + { + if (*ols != ' ') + wsatend = 0; + ols--; + nls--; + } + + if (wsatend) + { + ols = oe; + nls = ne; + } + else if (*ols != *nls) + { + if (*ols) /* don't step past the NUL */ + ols++; + if (*nls) + nls++; + } + + move_vert (current_line); + move_cursor_relative (ofd - old, old); + + /* if (len (new) > len (old)) */ + lendiff = (nls - nfd) - (ols - ofd); + + /* Insert (diff(len(old),len(new)) ch */ + if (lendiff > 0) + { + if (terminal_can_insert) + { + extern char *term_IC; + + /* Sometimes it is cheaper to print the characters rather than + use the terminal's capabilities. */ + if ((2 * (ne - nfd)) < lendiff && !term_IC) + { + output_some_chars (nfd, (ne - nfd)); + last_c_pos += (ne - nfd); + } + else + { + if (*ols) + { + insert_some_chars (nfd, lendiff); + last_c_pos += lendiff; + } + else + { + /* At the end of a line the characters do not have to + be "inserted". They can just be placed on the screen. */ + output_some_chars (nfd, lendiff); + last_c_pos += lendiff; + } + /* Copy (new) chars to screen from first diff to last match. */ + if (((nls - nfd) - lendiff) > 0) + { + output_some_chars (&nfd[lendiff], ((nls - nfd) - lendiff)); + last_c_pos += ((nls - nfd) - lendiff); + } + } + } + else + { /* cannot insert chars, write to EOL */ + output_some_chars (nfd, (ne - nfd)); + last_c_pos += (ne - nfd); + } + } + else /* Delete characters from line. */ + { + /* If possible and inexpensive to use terminal deletion, then do so. */ + if (term_dc && (2 * (ne - nfd)) >= (-lendiff)) + { + if (lendiff) + delete_chars (-lendiff); /* delete (diff) characters */ + + /* Copy (new) chars to screen from first diff to last match */ + if ((nls - nfd) > 0) + { + output_some_chars (nfd, (nls - nfd)); + last_c_pos += (nls - nfd); + } + } + /* Otherwise, print over the existing material. */ + else + { + output_some_chars (nfd, (ne - nfd)); + last_c_pos += (ne - nfd); + clear_to_eol ((oe - old) - (ne - new)); + } } } @@ -1804,25 +1633,25 @@ update_line (old, new, current_line) new (empty) line. */ rl_on_new_line () { - if (visible_line) - visible_line[0] = '\0'; + if (visible_line) + visible_line[0] = '\0'; - last_c_pos = last_v_pos = 0; - vis_botlin = last_lmargin = 0; + last_c_pos = last_v_pos = 0; + vis_botlin = last_lmargin = 0; } /* Actually update the display, period. */ rl_forced_update_display () { - if (visible_line) + if (visible_line) { - register char *temp = visible_line; + register char *temp = visible_line; - while (*temp) *temp++ = '\0'; + while (*temp) *temp++ = '\0'; } - rl_on_new_line (); - forced_display++; - rl_redisplay (); + rl_on_new_line (); + forced_display++; + rl_redisplay (); } /* Move the cursor from last_c_pos to NEW, which are buffer indices. @@ -1830,34 +1659,34 @@ rl_forced_update_display () the movement is being done. */ static void move_cursor_relative (new, data) - int new; - char *data; + int new; + char *data; { - register int i; + register int i; - /* It may be faster to output a CR, and then move forwards instead - of moving backwards. */ - if (new + 1 < last_c_pos - new) + /* It may be faster to output a CR, and then move forwards instead + of moving backwards. */ + if (new + 1 < last_c_pos - new) { - tputs (term_cr, 1, output_character_function); - last_c_pos = 0; + tputs (term_cr, 1, output_character_function); + last_c_pos = 0; } - if (last_c_pos == new) return; + if (last_c_pos == new) return; - if (last_c_pos < new) + if (last_c_pos < new) { - /* Move the cursor forward. We do it by printing the command - to move the cursor forward if there is one, else print that - portion of the output buffer again. Which is cheaper? */ + /* Move the cursor forward. We do it by printing the command + to move the cursor forward if there is one, else print that + portion of the output buffer again. Which is cheaper? */ - /* The above comment is left here for posterity. It is faster - to print one character (non-control) than to print a control - sequence telling the terminal to move forward one character. - That kind of control is for people who don't know what the - data is underneath the cursor. */ + /* The above comment is left here for posterity. It is faster + to print one character (non-control) than to print a control + sequence telling the terminal to move forward one character. + That kind of control is for people who don't know what the + data is underneath the cursor. */ #ifdef HACK_TERMCAP_MOTION - extern char *term_forward_char; + extern char *term_forward_char; if (term_forward_char) for (i = last_c_pos; i < new; i++) @@ -1866,82 +1695,82 @@ move_cursor_relative (new, data) for (i = last_c_pos; i < new; i++) putc (data[i], out_stream); #else - for (i = last_c_pos; i < new; i++) - putc (data[i], out_stream); + for (i = last_c_pos; i < new; i++) + putc (data[i], out_stream); #endif /* HACK_TERMCAP_MOTION */ } - else - backspace (last_c_pos - new); - last_c_pos = new; + else + backspace (last_c_pos - new); + last_c_pos = new; } /* PWP: move the cursor up or down. */ void move_vert (to) - int to; + int to; { - void output_character_function (); - register int delta, i; + void output_character_function (); + register int delta, i; - if (last_v_pos == to) return; + if (last_v_pos == to) return; - if (to > screenheight) - return; + if (to > screenheight) + return; - if ((delta = to - last_v_pos) > 0) + if ((delta = to - last_v_pos) > 0) { - for (i = 0; i < delta; i++) - putc ('\n', out_stream); - tputs (term_cr, 1, output_character_function); - last_c_pos = 0; /* because crlf() will do \r\n */ + for (i = 0; i < delta; i++) + putc ('\n', out_stream); + tputs (term_cr, 1, output_character_function); + last_c_pos = 0; /* because crlf() will do \r\n */ } - else + else { /* delta < 0 */ - if (term_up && *term_up) - for (i = 0; i < -delta; i++) - tputs (term_up, 1, output_character_function); + if (term_up && *term_up) + for (i = 0; i < -delta; i++) + tputs (term_up, 1, output_character_function); } - last_v_pos = to; /* now to is here */ + last_v_pos = to; /* now to is here */ } /* Physically print C on out_stream. This is for functions which know how to optimize the display. */ rl_show_char (c) - int c; +int c; { - if (c > 127) - { - fprintf (out_stream, "M-"); - c -= 128; - } +if (c > 127) +{ +fprintf (out_stream, "M-"); +c -= 128; +} #ifdef DISPLAY_TABS - if (c < 32 && c != '\t') +if (c < 32 && c != '\t') #else - if (c < 32) +if (c < 32) #endif - { +{ - c += 64; - } +c += 64; +} - putc (c, out_stream); - fflush (out_stream); +putc (c, out_stream); +fflush (out_stream); } #ifdef DISPLAY_TABS int rl_character_len (c, pos) - register int c, pos; + register int c, pos; { - if (c < ' ' || c > 126) + if (c < ' ' || c > 126) { - if (c == '\t') - return (((pos | (int)7) + 1) - pos); - else - return (3); + if (c == '\t') + return (((pos | (int)7) + 1) - pos); + else + return (3); } - else - return (1); + else + return (1); } #else int @@ -1958,293 +1787,1472 @@ rl_character_len (c) /* How to print things in the "echo-area". The prompt is treated as a mini-modeline. */ rl_message (string, arg1, arg2) - char *string; +char *string; { - sprintf (msg_buf, string, arg1, arg2); - rl_display_prompt = msg_buf; - rl_redisplay (); +sprintf (msg_buf, string, arg1, arg2); +rl_display_prompt = msg_buf; +rl_redisplay (); } /* How to clear things from the "echo-area". */ rl_clear_message () { - rl_display_prompt = rl_prompt; - rl_redisplay (); + rl_display_prompt = rl_prompt; + rl_redisplay (); } - -/* **************************************************************** */ + + + /* **************************************************************** */ /* */ -/* Terminal and Termcap */ +/* USG (System V) Support */ /* */ /* **************************************************************** */ -static char *term_buffer = (char *)NULL; -static char *term_string_buffer = (char *)NULL; - -/* Non-zero means this terminal can't really do anything. */ -int dumb_term = 0; +/* When compiling and running in the `Posix' environment, Ultrix does + not restart system calls, so this needs to do it. */ +int +rl_getc (stream) + FILE *stream; +{ + int result; + unsigned char c; -/* Some strings to control terminal actions. These are output by tputs (). */ -char *term_goto, *term_clreol, *term_cr, *term_clrpag, *term_backspace; + while (1) + { + result = read (fileno (stream), &c, sizeof (char)); -int screenwidth, screenheight; + if (result == sizeof (char)) + return (c); -/* Non-zero if we determine that the terminal can do character insertion. */ -int terminal_can_insert = 0; + if (errno != EINTR) + return (EOF); + } +} -/* How to insert characters. */ -char *term_im, *term_ei, *term_ic, *term_ip, *term_IC; +/* **************************************************************** */ +/* */ +/* Character Input Buffering */ +/* */ +/* **************************************************************** */ -/* How to delete characters. */ -char *term_dc, *term_DC; +/* If the terminal was in xoff state when we got to it, then xon_char + contains the character that is supposed to start it again. */ +static int xon_char, xoff_state; +static int pop_index = 0, push_index = 0, ibuffer_len = 511; +static unsigned char ibuffer[512]; -#ifdef HACK_TERMCAP_MOTION -char *term_forward_char; -#endif /* HACK_TERMCAP_MOTION */ +/* Non-null means it is a pointer to a function to run while waiting for + character input. */ +Function *rl_event_hook = (Function *)NULL; -/* How to go up a line. */ -char *term_up; +#define any_typein (push_index != pop_index) -/* A visible bell, if the terminal can be made to flash the screen. */ -char *visible_bell; +/* Add KEY to the buffer of characters to be read. */ +rl_stuff_char (key) +int key; +{ +if (key == EOF) +{ +key = NEWLINE; +rl_pending_input = EOF; +} +ibuffer[push_index++] = key; +if (push_index >= ibuffer_len) +push_index = 0; +} -/* Re-initialize the terminal considering that the TERM/TERMCAP variable - has changed. */ -rl_reset_terminal (terminal_name) - char *terminal_name; +/* Return the amount of space available in the + buffer for stuffing characters. */ +int +ibuffer_space () { - init_terminal_io (terminal_name); + if (pop_index > push_index) + return (pop_index - push_index); + else + return (ibuffer_len - (push_index - pop_index)); } -void init_terminal_io (terminal_name) - char *terminal_name; +/* Get a key from the buffer of characters to be read. + Return the key in KEY. + Result is KEY if there was a key, or 0 if there wasn't. */ +int +rl_get_char (key) + int *key; { - char* getenv(); - char *term = (terminal_name? terminal_name : getenv ("TERM")); - char *tgetstr (), *buffer; -#ifdef TIOCGWINSZ - struct winsize window_size; -#endif - int tty; + if (push_index == pop_index) + return (0); - if (!term_string_buffer) - term_string_buffer = (char *)xmalloc (2048); + *key = ibuffer[pop_index++]; - if (!term_buffer) - term_buffer = (char *)xmalloc (2048); + if (pop_index >= ibuffer_len) + pop_index = 0; - buffer = term_string_buffer; + return (1); +} - term_clrpag = term_cr = term_clreol = (char *)NULL; +/* Stuff KEY into the *front* of the input buffer. + Returns non-zero if successful, zero if there is + no space left in the buffer. */ +int +rl_unget_char (key) + int key; +{ + if (ibuffer_space ()) + { + pop_index--; + if (pop_index < 0) + pop_index = ibuffer_len - 1; + ibuffer[pop_index] = key; + return (1); + } + return (0); +} - if (!term) - term = "dumb"; +/* If a character is available to be read, then read it + and stuff it into IBUFFER. Otherwise, just return. */ +void rl_gather_tyi () +{ + int tty = fileno (in_stream); + register int tem, result = -1; + long chars_avail; + char input; -#if defined(CYGWIN) -/* some machines. eg. windows 98 se. hang for up to 30 seconds when -HOME=/ because terminfo is looked for in $HOME/.terminfo and the // -is a network call. So if TERMINFO is not an environment variable -and term=xterm we set it to neuronhome/lib and get neuronhome/lib/x/xterm -*/ - if (!getenv("TERMINFO") && strcmp(term, "xterm") == 0) { - extern char* neuron_home; - extern char* hoc_back2forward(); - sprintf(term_buffer, "TERMINFO=%s/lib", hoc_back2forward(neuron_home)); - putenv(term_buffer); - } +#if 0 && defined(FIONREAD) + result = ioctl (tty, FIONREAD, &chars_avail); #endif - if (tgetent (term_buffer, term) < 0) + if (result == -1) { - dumb_term = 1; - return; + fcntl (tty, F_SETFL, O_NDELAY); + chars_avail = read (tty, &input, 1); + fcntl (tty, F_SETFL, 0); + if (chars_avail == -1 && errno == EAGAIN) + return; } - tgetstr ("pc", &buffer); + /* If there's nothing available, don't waste time trying to read + something. */ + if (chars_avail == 0) + return; - term_backspace = tgetstr ("le", &buffer); + tem = ibuffer_space (); - term_cr = tgetstr ("cr", &buffer); - term_clreol = tgetstr ("ce", &buffer); - term_clrpag = tgetstr ("cl", &buffer); + if (chars_avail > tem) + chars_avail = tem; +#if __alpha + /* I think there is a bug in the dec alpha cc compiler since with +chars_avail = 1 and tem=512 it still executes the body of the if above. +*/ +chars_avail = 1; +#endif + /* One cannot read all of the available input. I can only read a single + character at a time, or else programs which require input can be + thwarted. If the buffer is larger than one character, I lose. + Damn! */ + if (tem < ibuffer_len) + chars_avail = 0; + + if (result != -1) + { + while (chars_avail--) + rl_stuff_char (rl_getc (in_stream)); + } + else + { + if (chars_avail) + rl_stuff_char (input); + } +} - if (!term_cr) - term_cr = "\r"; +/* Read a key, including pending input. */ +int +rl_read_key () +{ + int c; -#ifdef HACK_TERMCAP_MOTION - term_forward_char = tgetstr ("nd", &buffer); -#endif /* HACK_TERMCAP_MOTION */ + rl_key_sequence_length++; - if (rl_instream) - tty = fileno (rl_instream); - else - tty = 0; - - screenwidth = screenheight = 0; -#ifdef TIOCGWINSZ - if (ioctl (tty, TIOCGWINSZ, &window_size) == 0) + if (rl_pending_input) { - screenwidth = (int) window_size.ws_col; - screenheight = (int) window_size.ws_row; + c = rl_pending_input; + rl_pending_input = 0; } + else + { + /* If input is coming from a macro, then use that. */ + if (c = next_macro_key ()) + return (c); + + /* If the user has an event function, then call it periodically. */ + if (rl_event_hook) + { +#if defined(CYGWIN) + int cnt=0; +#endif + while (rl_event_hook && !rl_get_char (&c)) + { + (*rl_event_hook) (); + rl_gather_tyi (); +#if defined(CYGWIN) + /* when the rxvt is closed, then the symptom is that input +is perpetually ready from the HandleStdin::inputReady but there +are no characters. Apparently there is no direct test there that +stdin is no longer available (errno, F_GETFL, F_GETFD do not change) +so this kludge is used. +*/ + if (++cnt > 1000) { +#if 0 + debugfile("cnt=%d\n", cnt); +#endif + rl_stuff_char(eof_char); + break; + } #endif + } + } + else + { + if (!rl_get_char (&c)) + c = rl_getc (in_stream); + } + } - if (screenwidth <= 0 || screenheight <= 0) +#ifdef NEVER /* This breaks supdup to 4.0.3c machines. */ + #ifdef TIOCSTART + /* Ugh. But I can't think of a better way. */ + if (xoff_state && c == xon_char) { - screenwidth = tgetnum ("co"); - screenheight = tgetnum ("li"); + ioctl (fileno (in_stream), TIOCSTART, 0); + xoff_state = 0; + return (rl_read_key ()); } +#endif /* TIOCSTART */ +#endif + + return (c); +} - screenwidth--; +/* I'm beginning to hate the declaration rules for various compilers. */ +static void add_macro_char (); - if (screenwidth <= 0) - screenwidth = 79; +/* Do the command associated with KEY in MAP. + If the associated command is really a keymap, then read + another key, and dispatch into that map. */ +void rl_dispatch (key, map) + register int key; + Keymap map; +{ + + if (defining_kbd_macro) + add_macro_char (key); + + if (key > 127 && key < 256) + { + if (map[ESC].type == ISKMAP) + { + map = (Keymap)map[ESC].function; + key -= 128; + rl_dispatch (key, map); + } + else + ding (); + return; + } + + switch (map[key].type) + { + case ISFUNC: + { + Function *func = map[key].function; + + if (func != (Function *)NULL) + { + /* Special case rl_do_lowercase_version (). */ + if (func == rl_do_lowercase_version) + { + rl_dispatch (to_lower (key), map); + return; + } + + (*map[key].function)(rl_numeric_arg * arg_sign, key); + + /* If we have input pending, then the last command was a prefix + command. Don't change the state of rl_last_func. Otherwise, + remember the last command executed in this variable. */ + if (!rl_pending_input) + rl_last_func = map[key].function; + } + else + { + rl_abort (); + return; + } + } + break; + + case ISKMAP: + if (map[key].function != (Function *)NULL) + { + int newkey; + + rl_key_sequence_length++; + newkey = rl_read_key (); + rl_dispatch (newkey, (Keymap)map[key].function); + } + else + { + rl_abort (); + return; + } + break; + + case ISMACR: + if (map[key].function != (Function *)NULL) + { + char *macro = savestring ((char *)map[key].function); + + with_macro_input (macro); + return; + } + break; + } +} - if (screenheight <= 0) - screenheight = 24; - term_im = tgetstr ("im", &buffer); - term_ei = tgetstr ("ei", &buffer); - term_IC = tgetstr ("IC", &buffer); - term_ic = tgetstr ("ic", &buffer); - /* "An application program can assume that the terminal can do - character insertion if *any one of* the capabilities `IC', - `im', `ic' or `ip' is provided." But we can't do anything if - only `ip' is provided, so... */ - terminal_can_insert = (term_IC || term_im || term_ic); + +/* **************************************************************** */ +/* */ +/* Hacking Keyboard Macros */ +/* */ +/* **************************************************************** */ - term_up = tgetstr ("up", &buffer); - term_dc = tgetstr ("dc", &buffer); - term_DC = tgetstr ("DC", &buffer); +/* The currently executing macro string. If this is non-zero, + then it is a malloc ()'ed string where input is coming from. */ +static char *executing_macro = (char *)NULL; - visible_bell = tgetstr ("vb", &buffer); -} +/* The offset in the above string to the next character to be read. */ +static int executing_macro_index = 0; -/* A function for the use of tputs () */ +/* The current macro string being built. Characters get stuffed + in here by add_macro_char (). */ +static char *current_macro = (char *)NULL; + +/* The size of the buffer allocated to current_macro. */ +static int current_macro_size = 0; + +/* The index at which characters are being added to current_macro. */ +static int current_macro_index = 0; + +/* A structure used to save nested macro strings. + It is a linked list of string/index for each saved macro. */ +struct saved_macro { + struct saved_macro *next; + char *string; + int index; +}; + +/* The list of saved macros. */ +struct saved_macro *macro_list = (struct saved_macro *)NULL; + +/* Forward declarations of static functions. Thank you C. */ +static void push_executing_macro (); +static void pop_executing_macro (); + +/* This one has to be declared earlier in the file. */ +/* static void add_macro_char (); */ + +/* Save the currently executing macro on a stack of saved macros. */ static void -output_character_function (c) - int c; +push_executing_macro () { - putc (c, out_stream); + struct saved_macro *saver; + + saver = (struct saved_macro *)xmalloc (sizeof (struct saved_macro)); + saver->next = macro_list; + saver->index = executing_macro_index; + saver->string = executing_macro; + + macro_list = saver; } -/* Write COUNT characters from STRING to the output stream. */ +/* Discard the current macro, replacing it with the one + on the top of the stack of saved macros. */ static void -output_some_chars (string, count) - char *string; - int count; +pop_executing_macro () { - fwrite (string, 1, count, out_stream); + if (executing_macro) + free (executing_macro); + + executing_macro = (char *)NULL; + executing_macro_index = 0; + + if (macro_list) + { + struct saved_macro *disposer = macro_list; + executing_macro = macro_list->string; + executing_macro_index = macro_list->index; + macro_list = macro_list->next; + free (disposer); + } } -/* Delete COUNT characters from the display line. */ -static void -delete_chars (count) - int count; -{ - if (count > screenwidth) - return; - if (term_DC && *term_DC) +/* Return the next character available from a macro, or 0 if + there are no macro characters. */ +static int +next_macro_key () +{ + if (!executing_macro) + return (0); + + if (!executing_macro[executing_macro_index]) + { + pop_executing_macro (); + return (next_macro_key ()); + } + + return (executing_macro[executing_macro_index++]); +} + +/* Add a character to the macro being built. */ +static void +add_macro_char (c) + int c; +{ + if (current_macro_index + 1 >= current_macro_size) + { + if (!current_macro) + current_macro = (char *)xmalloc (current_macro_size = 25); + else + current_macro = + (char *)xrealloc (current_macro, current_macro_size += 25); + } + + current_macro[current_macro_index++] = c; + current_macro[current_macro_index] = '\0'; +} + + +/* Set up to read subsequent input from STRING. + STRING is free ()'ed when we are done with it. */ +static +with_macro_input (string) + char *string; +{ + push_executing_macro (); + executing_macro = string; + executing_macro_index = 0; +} + +/* Begin defining a keyboard macro. + Keystrokes are recorded as they are executed. + End the definition with rl_end_kbd_macro (). + If a numeric argument was explicitly typed, then append this + definition to the end of the existing macro, and start by + re-executing the existing macro. */ +rl_start_kbd_macro (ignore1, ignore2) + int ignore1, ignore2; +{ + if (defining_kbd_macro) + rl_abort (); + + if (rl_explicit_arg) + { + if (current_macro) + with_macro_input (savestring (current_macro)); + } + else + current_macro_index = 0; + + defining_kbd_macro = 1; +} + +/* Stop defining a keyboard macro. + A numeric argument says to execute the macro right now, + that many times, counting the definition as the first time. */ +rl_end_kbd_macro (count, ignore) + int count, ignore; +{ + if (!defining_kbd_macro) + rl_abort (); + + current_macro_index -= (rl_key_sequence_length - 1); + current_macro[current_macro_index] = '\0'; + + defining_kbd_macro = 0; + + rl_call_last_kbd_macro (--count, 0); +} + +/* Execute the most recently defined keyboard macro. + COUNT says how many times to execute it. */ +rl_call_last_kbd_macro (count, ignore) + int count, ignore; +{ + if (!current_macro) + rl_abort (); + + while (count--) + with_macro_input (savestring (current_macro)); +} + + +/* **************************************************************** */ +/* */ +/* Numeric Arguments */ +/* */ +/* **************************************************************** */ + +/* Handle C-u style numeric args, as well as M--, and M-digits. */ + +/* Add the current digit to the argument in progress. */ +rl_digit_argument (ignore, key) +int ignore, key; +{ + rl_pending_input = key; + rl_digit_loop (); +} + + +/* Create a default argument. */ +rl_init_argument () +{ + rl_numeric_arg = arg_sign = 1; + rl_explicit_arg = 0; +} + +/* C-u, universal argument. Multiply the current argument by 4. + Read a key. If the key has nothing to do with arguments, then + dispatch on it. If the key is the abort character then abort. */ +rl_universal_argument () +{ + rl_numeric_arg *= 4; + rl_digit_loop (); +} + +/* What to do when you abort reading an argument. */ +rl_discard_argument () +{ + ding (); + rl_clear_message (); + rl_init_argument (); +} + +extern numeric(); + +void rl_digit_loop () +{ + int key, c; + while (1) + { + rl_message ("(arg: %d) ", arg_sign * rl_numeric_arg); + key = c = rl_read_key (); + + if (keymap[c].type == ISFUNC && + keymap[c].function == rl_universal_argument) + { + rl_numeric_arg *= 4; + continue; + } + c = UNMETA (c); + if (numeric (c)) + { + if (rl_explicit_arg) + rl_numeric_arg = (rl_numeric_arg * 10) + (c - '0'); + else + rl_numeric_arg = (c - '0'); + rl_explicit_arg = 1; + } + else + { + if (c == '-' && !rl_explicit_arg) + { + rl_numeric_arg = 1; + arg_sign = -1; + } + else + { + rl_clear_message (); + rl_dispatch (key, keymap); + return; + } + } + } +} + + + +/* **************************************************************** */ +/* */ +/* Utility Functions */ +/* */ +/* **************************************************************** */ + +/* Return 0 if C is not a member of the class of characters that belong + in words, or 1 if it is. */ + +int allow_pathname_alphabetic_chars = 0; +char *pathname_alphabetic_chars = "/-_=~.#$"; + +int +alphabetic (c) + int c; +{ + if (pure_alphabetic (c) || (numeric (c))) + return (1); + + if (allow_pathname_alphabetic_chars) + return (rindex (pathname_alphabetic_chars, c) != (char*)0); + else + return (0); +} + +/* Return non-zero if C is a numeric character. */ +int +numeric (c) + int c; +{ + return (c >= '0' && c <= '9'); +} + +/* Ring the terminal bell. */ +int +ding () +{ + if (readline_echoing_p) + { + if (prefer_visible_bell && visible_bell) + tputs (visible_bell, 1, output_character_function); + else + { + fprintf (stderr, "\007"); + fflush (stderr); + } + } + return (-1); +} + +/* How to abort things. */ +rl_abort () +{ + ding (); + rl_clear_message (); + rl_init_argument (); + rl_pending_input = 0; + + defining_kbd_macro = 0; + while (executing_macro) + pop_executing_macro (); + + rl_last_func = (Function *)NULL; + longjmp (readline_top_level, 1); +} + +/* Return a copy of the string between FROM and TO. + FROM is inclusive, TO is not. */ +#if defined (sun) /* Yes, that's right, some crufty function in sunview is + called rl_copy (). */ +static +#endif +char * +rl_copy (from, to) + int from, to; +{ + register int length; + char *copy; + + /* Fix it if the caller is confused. */ + if (from > to) { + int t = from; + from = to; + to = t; + } + + length = to - from; + copy = (char *)xmalloc (1 + length); + strncpy (copy, the_line + from, length); + copy[length] = '\0'; + return (copy); +} + + +/* **************************************************************** */ +/* */ +/* Undo, and Undoing */ +/* */ +/* **************************************************************** */ + +/* Non-zero tells rl_delete_text and rl_insert_text to not add to + the undo list. */ +int doing_an_undo = 0; + +/* The current undo list for THE_LINE. */ +UNDO_LIST *rl_undo_list = (UNDO_LIST *)NULL; + +/* Remember how to undo something. Concatenate some undos if that + seems right. */ +rl_add_undo (what, start, end, text) +enum undo_code what; +int start, end; +char *text; +{ +UNDO_LIST *temp = (UNDO_LIST *)xmalloc (sizeof (UNDO_LIST)); +temp->what = what; +temp->start = start; +temp->end = end; +temp->text = text; +temp->next = rl_undo_list; +rl_undo_list = temp; +} + +/* Free the existing undo list. */ +free_undo_list () +{ + while (rl_undo_list) { + UNDO_LIST *release = rl_undo_list; + rl_undo_list = rl_undo_list->next; + + if (release->what == UNDO_DELETE) + free (release->text); + + free (release); + } +} +rl_insert_text(); +rl_delete_text(); +/* Undo the next thing in the list. Return 0 if there + is nothing to undo, or non-zero if there was. */ +int +rl_do_undo () +{ + UNDO_LIST *release; + int waiting_for_begin = 0; + + undo_thing: + if (!rl_undo_list) + return (0); + + doing_an_undo = 1; + + switch (rl_undo_list->what) { + + /* Undoing deletes means inserting some text. */ + case UNDO_DELETE: + rl_point = rl_undo_list->start; + rl_insert_text (rl_undo_list->text); + free (rl_undo_list->text); + break; + + /* Undoing inserts means deleting some text. */ + case UNDO_INSERT: + rl_delete_text (rl_undo_list->start, rl_undo_list->end); + rl_point = rl_undo_list->start; + break; + + /* Undoing an END means undoing everything 'til we get to + a BEGIN. */ + case UNDO_END: + waiting_for_begin++; + break; + + /* Undoing a BEGIN means that we are done with this group. */ + case UNDO_BEGIN: + if (waiting_for_begin) + waiting_for_begin--; + else + abort (); + break; + } + + doing_an_undo = 0; + + release = rl_undo_list; + rl_undo_list = rl_undo_list->next; + free (release); + + if (waiting_for_begin) + goto undo_thing; + + return (1); +} + +/* Begin a group. Subsequent undos are undone as an atomic operation. */ +rl_begin_undo_group () +{ + rl_add_undo (UNDO_BEGIN, 0, 0, 0); +} + +/* End an undo group started with rl_begin_undo_group (). */ +rl_end_undo_group () +{ + rl_add_undo (UNDO_END, 0, 0, 0); +} + +/* Save an undo entry for the text from START to END. */ +rl_modifying (start, end) +int start, end; { +if (start > end) +{ +int t = start; +start = end; +end = t; +} + +if (start != end) +{ +char *temp = rl_copy (start, end); +rl_begin_undo_group (); +rl_add_undo (UNDO_DELETE, start, end, temp); +rl_add_undo (UNDO_INSERT, start, end, (char *)NULL); +rl_end_undo_group (); +} +} + +/* Revert the current line to its previous state. */ +rl_revert_line () +{ + if (!rl_undo_list) ding (); + else { + while (rl_undo_list) + rl_do_undo (); + } +} + +/* Do some undoing of things that were done. */ +void rl_undo_command (count) +{ + if (count < 0) return; /* Nothing to do. */ + + while (count) + { + if (rl_do_undo ()) + { + count--; + } + else + { + ding (); + break; + } + } +} + + +/* **************************************************************** */ +/* */ +/* Insert and Delete */ +/* */ +/* **************************************************************** */ + +/* Insert a string of text into the line at point. This is the only + way that you should do insertion. rl_insert () calls this + function. */ +rl_insert_text (string) +char *string; +{ + extern int doing_an_undo; + register int i, l = strlen (string); + while (rl_end + l >= rl_line_buffer_len) + { + rl_line_buffer = + (char *)xrealloc (rl_line_buffer, + rl_line_buffer_len += DEFAULT_BUFFER_SIZE); + the_line = rl_line_buffer; + } + + for (i = rl_end; i >= rl_point; i--) + the_line[i + l] = the_line[i]; + strncpy (the_line + rl_point, string, l); + + /* Remember how to undo this if we aren't undoing something. */ + if (!doing_an_undo) + { + /* If possible and desirable, concatenate the undos. */ + if ((strlen (string) == 1) && + rl_undo_list && + (rl_undo_list->what == UNDO_INSERT) && + (rl_undo_list->end == rl_point) && + (rl_undo_list->end - rl_undo_list->start < 20)) + rl_undo_list->end++; + else + rl_add_undo (UNDO_INSERT, rl_point, rl_point + l, (char *)NULL); + } + rl_point += l; + rl_end += l; + the_line[rl_end] = '\0'; +} + +/* Delete the string between FROM and TO. FROM is + inclusive, TO is not. */ +rl_delete_text (from, to) +int from, to; +{ + extern int doing_an_undo; + register char *text; + + /* Fix it if the caller is confused. */ + if (from > to) + { + int t = from; + from = to; + to = t; + } + text = rl_copy (from, to); + strncpy (the_line + from, the_line + to, rl_end - to); + + /* Remember how to undo this delete. */ + if (!doing_an_undo) + rl_add_undo (UNDO_DELETE, from, to, text); + else + free (text); + + rl_end -= (to - from); + the_line[rl_end] = '\0'; +} + + +/* **************************************************************** */ +/* */ +/* Text commands */ +/* */ +/* **************************************************************** */ + +/* Insert the character C at the current location, moving point forward. */ +void rl_insert (count, c) + int count, c; +{ + register int i; + char *string; + + if (count <= 0) + return; + + /* If we can optimize, then do it. But don't let people crash + readline because of extra large arguments. */ + if (count > 1 && count < 1024) + { + string = (char *)Alloca (1 + count); + + for (i = 0; i < count; i++) + string[i] = c; + + string[i] = '\0'; + rl_insert_text (string); +#if NO_ALLOCA + free(string); +#endif + return; + } + + if (count > 1024) + { + int decreaser; + + string = (char *)Alloca (1024 + 1); + + for (i = 0; i < 1024; i++) + string[i] = c; + + while (count) + { + decreaser = (count > 1024 ? 1024 : count); + string[decreaser] = '\0'; + rl_insert_text (string); + count -= decreaser; + } + return; + } + + /* We are inserting a single character. + If there is pending input, then make a string of all of the + pending characters that are bound to rl_insert, and insert + them all. */ + if (any_typein) + { + int key = 0, t; + + i = 0; + string = (char *)Alloca (ibuffer_len + 1); + string[i++] = c; + + while ((t = rl_get_char (&key)) && + (keymap[key].type == ISFUNC && + keymap[key].function == rl_insert)) + string[i++] = key; + + if (t) + rl_unget_char (key); + + string[i] = '\0'; + rl_insert_text (string); + return; + } + else + { + /* Inserting a single character. */ + string = (char *)Alloca (2); + + string[1] = '\0'; + string[0] = c; + rl_insert_text (string); + } +#if NO_ALLOCA + free(string); +#endif +} + +/* Insert the next typed character verbatim. */ +rl_quoted_insert (count) +int count; +{ +int c = rl_read_key (); +rl_insert (count, c); +} + +/* Insert a tab character. */ +rl_tab_insert (count) +int count; +{ +rl_insert (count, '\t'); +} + +/* What to do when a NEWLINE is pressed. We accept the whole line. + KEY is the key that invoked this command. I guess it could have + meaning in the future. */ +rl_newline (count, key) +int count, key; +{ + +rl_done = 1; + +#ifdef VI_MODE +{ + extern int vi_doing_insert; + if (vi_doing_insert) + { + rl_end_undo_group (); + vi_doing_insert = 0; + } + } +#endif /* VI_MODE */ + +if (readline_echoing_p) +{ +move_vert (vis_botlin); +vis_botlin = 0; +crlf (); +fflush (out_stream); +rl_display_fixed++; +} +} + +rl_clean_up_for_exit () +{ + if (readline_echoing_p) + { + move_vert (vis_botlin); + vis_botlin = 0; + fflush (out_stream); + rl_restart_output (); + } +} + +/* What to do for some uppercase characters, like meta characters, + and some characters appearing in emacs_ctlx_keymap. This function + is just a stub, you bind keys to it and the code in rl_dispatch () + is special cased. */ +rl_do_lowercase_version (ignore1, ignore2) +int ignore1, ignore2; +{ +} + +/* Rubout the character behind point. */ +void rl_rubout (count) + int count; +{ + if (count < 0) + { + rl_delete (-count); + return; + } + + if (!rl_point) + { + ding (); + return; + } + + if (count > 1) + { + int orig_point = rl_point; + rl_backward (count); + rl_kill_text (orig_point, rl_point); + } + else + { + int c = the_line[--rl_point]; + rl_delete_text (rl_point, rl_point + 1); + + if (rl_point == rl_end && alphabetic (c) && last_c_pos) + { + backspace (1); + putc (' ', out_stream); + backspace (1); + last_c_pos--; + visible_line[last_c_pos] = '\0'; + rl_display_fixed++; + } + } +} + +/* Delete the character under the cursor. Given a numeric argument, + kill that many characters instead. */ +void rl_delete (count, invoking_key) + int count, invoking_key; +{ + if (count < 0) + { + rl_rubout (-count); + return; + } + + if (rl_point == rl_end) + { + ding (); + return; + } + + if (count > 1) + { + int orig_point = rl_point; + rl_forward (count); + rl_kill_text (orig_point, rl_point); + rl_point = orig_point; + } + else + rl_delete_text (rl_point, rl_point + 1); +} + + + +/* **************************************************************** */ +/* */ +/* Signal Handling */ +/* */ +/* **************************************************************** */ + +#ifdef SIGWINCH +static SigHandler *old_sigwinch = (SigHandler *)NULL; + +#if SVR4 +static void +rl_handle_sigwinch (sig) + int sig; +#else +static sighandler +rl_handle_sigwinch (sig, code, scp) + int sig, code; + struct sigcontext *scp; +#endif +{ + char *term = rl_terminal_name, *getenv (); + + if (readline_echoing_p) + { + if (!term) + term = getenv ("TERM"); + if (!term) + term = "dumb"; + rl_reset_terminal (term); +#ifdef NEVER + crlf (); + rl_forced_update_display (); +#endif + } + + if (old_sigwinch && + old_sigwinch != (SigHandler *)SIG_IGN && + old_sigwinch != (SigHandler *)SIG_DFL) +#if SVR4 + (*old_sigwinch)(sig); +#else + (*old_sigwinch)(sig, code, scp); +#endif +} +#endif /* SIGWINCH */ + +#ifdef HANDLE_SIGNALS +/* Interrupt handling. */ +static SigHandler *old_int = (SigHandler *)NULL, + *old_tstp = (SigHandler *)NULL, + *old_ttou = (SigHandler *)NULL, + *old_ttin = (SigHandler *)NULL, + *old_cont = (SigHandler *)NULL; + +void rl_clear_signals () +{ + signal (SIGINT, old_int); + +#ifdef SIGTSTP + signal (SIGTSTP, old_tstp); +#endif + +#ifdef SIGTTOU + signal (SIGTTOU, old_ttou); + signal (SIGTTIN, old_ttin); +#endif + +#ifdef SIGWINCH + signal (SIGWINCH, old_sigwinch); +#endif +} + +/* Handle an interrupt character. */ +#if SVR4 +static void +rl_signal_handler (sig) + int sig; +#else +static sighandler +rl_signal_handler (sig, code, scp) + int sig, code; + struct sigcontext *scp; +#endif +{ + +#if !defined (HAVE_BSD_SIGNALS) || defined (hpux) + /* Since the signal will not be blocked while we are in the signal + handler, ignore it until rl_clear_signals resets the catcher. */ + if (sig == SIGINT) + signal (sig, SIG_IGN); +#endif /* !HAVE_BSD_SIGNALS || hpux */ + + switch (sig) + { + case SIGINT: + free_undo_list (); + rl_clear_message (); + rl_init_argument (); + +#ifdef SIGTSTP + case SIGTSTP: + case SIGTTOU: + case SIGTTIN: +#endif + + rl_clean_up_for_exit (); + rl_deprep_terminal (); + rl_clear_signals (); + rl_pending_input = 0; + + kill (getpid (), sig); + +#if defined (_POSIX_VERSION) + { + sigset_t set; + + sigemptyset (&set); + sigprocmask (SIG_SETMASK, &set, (sigset_t *)NULL); + } +#else +#if defined (HAVE_BSD_SIGNALS) + sigsetmask (0); +#endif /* HAVE_BSD_SIGNALS */ +#endif /* _POSIX_VERSION */ + + rl_prep_terminal (); + void rl_set_signals(); + rl_set_signals (); + } +} + +void rl_set_signals () +{ + old_int = (SigHandler *)signal (SIGINT, rl_signal_handler); + if (old_int == (SigHandler *)SIG_IGN) + signal (SIGINT, SIG_IGN); + +#ifdef SIGTSTP + old_tstp = (SigHandler *)signal (SIGTSTP, rl_signal_handler); + if (old_tstp == (SigHandler *)SIG_IGN) + signal (SIGTSTP, SIG_IGN); +#endif +#ifdef SIGTTOU + old_ttou = (SigHandler *)signal (SIGTTOU, rl_signal_handler); + old_ttin = (SigHandler *)signal (SIGTTIN, rl_signal_handler); + + if (old_tstp == (SigHandler *)SIG_IGN) + { + signal (SIGTTOU, SIG_IGN); + signal (SIGTTIN, SIG_IGN); + } +#endif + +#ifdef SIGWINCH + old_sigwinch = (SigHandler *)signal (SIGWINCH, rl_handle_sigwinch); +#endif +} + +#endif /* HANDLE_SIGNALS */ + + + +/* **************************************************************** */ +/* */ +/* Top Level Functions */ +/* */ +/* **************************************************************** */ + +/* Read a line of input. Prompt with PROMPT. A NULL PROMPT means + none. A return value of NULL means that EOF was encountered. */ +char * +readline (prompt) + char *prompt; +{ + char *readline_internal (); + char *value; + + rl_prompt = prompt; + + /* If we are at EOF return a NULL string. */ + if (rl_pending_input == EOF) + { + rl_pending_input = 0; + return ((char *)NULL); + } + + rl_initialize (); + rl_prep_terminal (); + +#ifdef HANDLE_SIGNALS + rl_set_signals (); +#endif + + value = readline_internal (); + rl_deprep_terminal (); + +#ifdef HANDLE_SIGNALS + rl_clear_signals (); +#endif + + return (value); +} + +/* Read a line of input from the global rl_instream, doing output on + the global rl_outstream. + If rl_prompt is non-null, then that is our prompt. */ +char * +readline_internal () +{ + int lastc, c, eof_found; + + in_stream = rl_instream; out_stream = rl_outstream; + lastc = eof_found = 0; + + if (rl_startup_hook) + (*rl_startup_hook) (); + + if (!readline_echoing_p) { - char *tgoto (), *buffer; - buffer = tgoto (term_DC, 0, count); - tputs (buffer, 1, output_character_function); + if (rl_prompt) + { + fprintf (out_stream, "%s", rl_prompt); + fflush (out_stream); + } } else { - if (term_dc && *term_dc) - while (count--) - tputs (term_dc, 1, output_character_function); + rl_on_new_line (); + rl_redisplay (); +#ifdef VI_MODE + if (rl_editing_mode == vi_mode) + rl_vi_insertion_mode (); +#endif /* VI_MODE */ } -} -/* Insert COUNT characters from STRING to the output stream. */ -static -insert_some_chars (string, count) - char *string; - int count; -{ - /* If IC is defined, then we do not have to "enter" insert mode. */ - if (term_IC) - { - char *tgoto (), *buffer; - buffer = tgoto (term_IC, 0, count); - tputs (buffer, 1, output_character_function); - output_some_chars (string, count); - } - else + while (!rl_done) { - register int i; + int lk = last_command_was_kill; + int code; + code = setjmp (readline_top_level); - /* If we have to turn on insert-mode, then do so. */ - if (term_im && *term_im) - tputs (term_im, 1, output_character_function); + if (code) + rl_redisplay (); - /* If there is a special command for inserting characters, then - use that first to open up the space. */ - if (term_ic && *term_ic) + if (!rl_pending_input) { - for (i = count; i--; ) - tputs (term_ic, 1, output_character_function); + /* Then initialize the argument and number of keys read. */ + rl_init_argument (); + rl_key_sequence_length = 0; } - /* Print the text. */ - output_some_chars (string, count); + c = rl_read_key (); - /* If there is a string to turn off insert mode, we had best use - it now. */ - if (term_ei && *term_ei) - tputs (term_ei, 1, output_character_function); - } -} + /* EOF typed to a non-blank line is a . */ + if (c == EOF && rl_end) + c = NEWLINE; -/* Move the cursor back. */ -backspace (count) - int count; -{ - register int i; + /* The character eof_char typed to blank line, and not as the + previous character is interpreted as EOF. */ + if (((c == eof_char && lastc != c) || c == EOF) && !rl_end) + { + eof_found = 1; + break; + } - if (term_backspace) - for (i = 0; i < count; i++) - tputs (term_backspace, 1, output_character_function); - else - for (i = 0; i < count; i++) - putc ('\b', out_stream); -} + lastc = c; + rl_dispatch (c, keymap); -/* Move to the start of the next line. */ -crlf () -{ - tputs (term_cr, 1, output_character_function); - putc ('\n', out_stream); -} + /* If there was no change in last_command_was_kill, then no kill + has taken place. Note that if input is pending we are reading + a prefix command, so nothing has changed yet. */ + if (!rl_pending_input) + { + if (lk == last_command_was_kill) + last_command_was_kill = 0; + } -/* Clear to the end of the line. COUNT is the minimum - number of character spaces to clear, */ -clear_to_eol (count) - int count; -{ - if (term_clreol) - { - tputs (term_clreol, 1, output_character_function); +#ifdef VI_MODE + /* In vi mode, when you exit insert mode, the cursor moves back + over the previous character. We explicitly check for that here. */ + if (rl_editing_mode == vi_mode && keymap == vi_movement_keymap) + rl_vi_check (); +#endif + + if (!rl_done) + rl_redisplay (); } - else - { - register int i; - /* Do one more character space. */ - count++; + /* Restore the original of this history line, iff the line that we + are editing was originally in the history, AND the line has changed. */ + { + HIST_ENTRY *entry = current_history (); + + if (entry && rl_undo_list) + { + char *temp = savestring (the_line); + rl_revert_line (); + entry = replace_history_entry (where_history (), the_line, + (HIST_ENTRY *)NULL); + free_history_entry (entry); + + strcpy (the_line, temp); + free (temp); + } + } - for (i = 0; i < count; i++) - putc (' ', out_stream); + /* At any rate, it is highly likely that this line has an undo list. Get + rid of it now. */ + if (rl_undo_list) + free_undo_list (); - backspace (count); - } + if (eof_found) + return (char *)NULL; + else + return (savestring (the_line)); } - /* **************************************************************** */ /* */ /* Saving and Restoring the TTY */ @@ -2461,251 +3469,86 @@ void rl_prep_terminal () tio.c_lflag |= ISIG; /* shouldn't be needed, but... */ #endif - tio.c_cc[VMIN] = 1; - tio.c_cc[VTIME] = 0; - - /* Turn off characters that we need on Posix systems with job control, - just to be sure. This includes ^Y and ^V. This should not really - be necessary. */ -#if defined (_POSIX_VERSION) && defined (_POSIX_JOB_CONTROL) - -#if !defined (_POSIX_VDISABLE) -#define _POSIX_VDISABLE 0 -#endif /* POSIX_VDISABLE */ - -#if defined (VLNEXT) - tio.c_cc[VLNEXT] = _POSIX_VDISABLE; -#endif - -#if defined (VDSUSP) - tio.c_cc[VDSUSP] = _POSIX_VDISABLE; -#endif - -#endif /* POSIX && JOB_CONTROL */ - -#if defined (_POSIX_VERSION) - tcsetattr (tty, TCSADRAIN, &tio); - tcflow (tty, TCOON); /* Simulate a ^Q. */ -#else - ioctl (tty, TCSETAW, &tio); - ioctl (tty, TCXONC, 1); /* Simulate a ^Q. */ -#endif /* POSIX */ - -#if defined (_POSIX_VERSION) - sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL); -#else -# if defined (HAVE_BSD_SIGNALS) - sigsetmask (oldmask); -# endif /* HAVE_BSD_SIGNALS */ -#endif /* POSIX */ - terminal_prepped = 1; -} - -void rl_deprep_terminal () -{ - int tty; - - /* If we are on a Posix system, block the delivery of SIGINT for a while. */ -#if defined (_POSIX_VERSION) - sigset_t set, oset; - if (!terminal_prepped) return; - sigemptyset (&set); - sigaddset (&set, SIGINT); - sigprocmask (SIG_BLOCK, &set, &oset); -#else - int oldmask; - if (!terminal_prepped) return; -# if defined (HAVE_BSD_SIGNALS) - oldmask = sigblock (sigmask (SIGINT)); -# endif /* HAVE_BSD_SIGNALS */ -#endif /* POSIX */ - - tty = fileno (rl_instream); -#if defined (_POSIX_VERSION) - tcsetattr (tty, TCSADRAIN, &otio); - tcflow (tty, TCOON); /* Simulate a ^Q. */ -#else - ioctl (tty, TCSETAW, &otio); - ioctl (tty, TCXONC, 1); /* Simulate a ^Q. */ -#endif /* POSIX */ - -#if defined (_POSIX_VERSION) - sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL); -#else -# if defined (HAVE_BSD_SIGNALS) - sigsetmask (oldmask); -# endif /* HAVE_BSD_SIGNALS */ -#endif /* POSIX */ - terminal_prepped = 0; -} -#endif /* NEW_TTY_DRIVER */ - - -/* **************************************************************** */ -/* */ -/* Utility Functions */ -/* */ -/* **************************************************************** */ - -/* Return 0 if C is not a member of the class of characters that belong - in words, or 1 if it is. */ - -int allow_pathname_alphabetic_chars = 0; -char *pathname_alphabetic_chars = "/-_=~.#$"; - -int -alphabetic (c) - int c; -{ - if (pure_alphabetic (c) || (numeric (c))) - return (1); - - if (allow_pathname_alphabetic_chars) - return (rindex (pathname_alphabetic_chars, c) != (char*)0); - else - return (0); -} - -/* Return non-zero if C is a numeric character. */ -int -numeric (c) - int c; -{ - return (c >= '0' && c <= '9'); -} - -/* Ring the terminal bell. */ -int -ding () -{ - if (readline_echoing_p) - { - if (prefer_visible_bell && visible_bell) - tputs (visible_bell, 1, output_character_function); - else - { - fprintf (stderr, "\007"); - fflush (stderr); - } - } - return (-1); -} - -/* How to abort things. */ -rl_abort () -{ - ding (); - rl_clear_message (); - rl_init_argument (); - rl_pending_input = 0; - - defining_kbd_macro = 0; - while (executing_macro) - pop_executing_macro (); - - rl_last_func = (Function *)NULL; - longjmp (readline_top_level, 1); -} - -/* Return a copy of the string between FROM and TO. - FROM is inclusive, TO is not. */ -#if defined (sun) /* Yes, that's right, some crufty function in sunview is - called rl_copy (). */ -static -#endif -char * -rl_copy (from, to) - int from, to; -{ - register int length; - char *copy; + tio.c_cc[VMIN] = 1; + tio.c_cc[VTIME] = 0; - /* Fix it if the caller is confused. */ - if (from > to) { - int t = from; - from = to; - to = t; - } + /* Turn off characters that we need on Posix systems with job control, + just to be sure. This includes ^Y and ^V. This should not really + be necessary. */ +#if defined (_POSIX_VERSION) && defined (_POSIX_JOB_CONTROL) - length = to - from; - copy = (char *)xmalloc (1 + length); - strncpy (copy, the_line + from, length); - copy[length] = '\0'; - return (copy); -} +#if !defined (_POSIX_VDISABLE) +#define _POSIX_VDISABLE 0 +#endif /* POSIX_VDISABLE */ - -/* **************************************************************** */ -/* */ -/* Insert and Delete */ -/* */ -/* **************************************************************** */ +#if defined (VLNEXT) + tio.c_cc[VLNEXT] = _POSIX_VDISABLE; +#endif -/* Insert a string of text into the line at point. This is the only - way that you should do insertion. rl_insert () calls this - function. */ -rl_insert_text (string) - char *string; -{ - extern int doing_an_undo; - register int i, l = strlen (string); - while (rl_end + l >= rl_line_buffer_len) - { - rl_line_buffer = - (char *)xrealloc (rl_line_buffer, - rl_line_buffer_len += DEFAULT_BUFFER_SIZE); - the_line = rl_line_buffer; - } +#if defined (VDSUSP) + tio.c_cc[VDSUSP] = _POSIX_VDISABLE; +#endif + +#endif /* POSIX && JOB_CONTROL */ - for (i = rl_end; i >= rl_point; i--) - the_line[i + l] = the_line[i]; - strncpy (the_line + rl_point, string, l); +#if defined (_POSIX_VERSION) + tcsetattr (tty, TCSADRAIN, &tio); + tcflow (tty, TCOON); /* Simulate a ^Q. */ +#else + ioctl (tty, TCSETAW, &tio); + ioctl (tty, TCXONC, 1); /* Simulate a ^Q. */ +#endif /* POSIX */ - /* Remember how to undo this if we aren't undoing something. */ - if (!doing_an_undo) - { - /* If possible and desirable, concatenate the undos. */ - if ((strlen (string) == 1) && - rl_undo_list && - (rl_undo_list->what == UNDO_INSERT) && - (rl_undo_list->end == rl_point) && - (rl_undo_list->end - rl_undo_list->start < 20)) - rl_undo_list->end++; - else - rl_add_undo (UNDO_INSERT, rl_point, rl_point + l, (char *)NULL); - } - rl_point += l; - rl_end += l; - the_line[rl_end] = '\0'; +#if defined (_POSIX_VERSION) + sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL); +#else +# if defined (HAVE_BSD_SIGNALS) + sigsetmask (oldmask); +# endif /* HAVE_BSD_SIGNALS */ +#endif /* POSIX */ + terminal_prepped = 1; } -/* Delete the string between FROM and TO. FROM is - inclusive, TO is not. */ -rl_delete_text (from, to) - int from, to; +void rl_deprep_terminal () { - extern int doing_an_undo; - register char *text; + int tty; - /* Fix it if the caller is confused. */ - if (from > to) - { - int t = from; - from = to; - to = t; - } - text = rl_copy (from, to); - strncpy (the_line + from, the_line + to, rl_end - to); + /* If we are on a Posix system, block the delivery of SIGINT for a while. */ +#if defined (_POSIX_VERSION) + sigset_t set, oset; + if (!terminal_prepped) return; + sigemptyset (&set); + sigaddset (&set, SIGINT); + sigprocmask (SIG_BLOCK, &set, &oset); +#else + int oldmask; + if (!terminal_prepped) return; +# if defined (HAVE_BSD_SIGNALS) + oldmask = sigblock (sigmask (SIGINT)); +# endif /* HAVE_BSD_SIGNALS */ +#endif /* POSIX */ - /* Remember how to undo this delete. */ - if (!doing_an_undo) - rl_add_undo (UNDO_DELETE, from, to, text); - else - free (text); + tty = fileno (rl_instream); +#if defined (_POSIX_VERSION) + tcsetattr (tty, TCSADRAIN, &otio); + tcflow (tty, TCOON); /* Simulate a ^Q. */ +#else + ioctl (tty, TCSETAW, &otio); + ioctl (tty, TCXONC, 1); /* Simulate a ^Q. */ +#endif /* POSIX */ - rl_end -= (to - from); - the_line[rl_end] = '\0'; +#if defined (_POSIX_VERSION) + sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL); +#else +# if defined (HAVE_BSD_SIGNALS) + sigsetmask (oldmask); +# endif /* HAVE_BSD_SIGNALS */ +#endif /* POSIX */ + terminal_prepped = 0; } +#endif /* NEW_TTY_DRIVER */ + + /* **************************************************************** */ @@ -2864,310 +3707,86 @@ void rl_backward_word (count) c = the_line[rl_point - 1]; if (alphabetic (c)) break; } - } - - while (rl_point) - { - c = the_line[rl_point - 1]; - if (!alphabetic (c)) - break; - else --rl_point; - } - --count; - } -} - -/* Clear the current line. Numeric argument to C-l does this. */ -void rl_refresh_line () -{ - int curr_line = last_c_pos / screenwidth; - extern char *term_clreol; - - move_vert(curr_line); - move_cursor_relative (0, the_line); /* XXX is this right */ - - if (term_clreol) - tputs (term_clreol, 1, output_character_function); - - rl_forced_update_display (); - rl_display_fixed = 1; -} - -/* C-l typed to a line without quoting clears the screen, and then reprints - the prompt and the current input line. Given a numeric arg, redraw only - the current line. */ -void rl_clear_screen () -{ - extern char *term_clrpag; - - if (rl_explicit_arg) - { - rl_refresh_line (); - return; - } - - if (term_clrpag) - tputs (term_clrpag, 1, output_character_function); - else - crlf (); - - rl_forced_update_display (); - rl_display_fixed = 1; -} - -void rl_arrow_keys(count,c) - int count,c; -{ - int ch = rl_read_key(); - - switch(ch) { - case 'a': - case 'A': - rl_get_previous_history(count); - return; - case 'b': - case 'B': - rl_get_next_history(count); - return; - case 'c': - case 'C': - rl_forward(count); - return; - case 'd': - case 'D': - rl_backward(count); - return; - default: - ding(); - return; - } -} - - -/* **************************************************************** */ -/* */ -/* Text commands */ -/* */ -/* **************************************************************** */ - -/* Insert the character C at the current location, moving point forward. */ -void rl_insert (count, c) - int count, c; -{ - register int i; - char *string; - - if (count <= 0) - return; - - /* If we can optimize, then do it. But don't let people crash - readline because of extra large arguments. */ - if (count > 1 && count < 1024) - { - string = (char *)Alloca (1 + count); - - for (i = 0; i < count; i++) - string[i] = c; - - string[i] = '\0'; - rl_insert_text (string); -#if NO_ALLOCA - free(string); -#endif - return; - } - - if (count > 1024) - { - int decreaser; - - string = (char *)Alloca (1024 + 1); - - for (i = 0; i < 1024; i++) - string[i] = c; - - while (count) - { - decreaser = (count > 1024 ? 1024 : count); - string[decreaser] = '\0'; - rl_insert_text (string); - count -= decreaser; - } - return; - } - - /* We are inserting a single character. - If there is pending input, then make a string of all of the - pending characters that are bound to rl_insert, and insert - them all. */ - if (any_typein) - { - int key = 0, t; - - i = 0; - string = (char *)Alloca (ibuffer_len + 1); - string[i++] = c; - - while ((t = rl_get_char (&key)) && - (keymap[key].type == ISFUNC && - keymap[key].function == rl_insert)) - string[i++] = key; - - if (t) - rl_unget_char (key); - - string[i] = '\0'; - rl_insert_text (string); - return; - } - else - { - /* Inserting a single character. */ - string = (char *)Alloca (2); - - string[1] = '\0'; - string[0] = c; - rl_insert_text (string); - } -#if NO_ALLOCA - free(string); -#endif -} - -/* Insert the next typed character verbatim. */ -rl_quoted_insert (count) - int count; -{ - int c = rl_read_key (); - rl_insert (count, c); -} - -/* Insert a tab character. */ -rl_tab_insert (count) - int count; -{ - rl_insert (count, '\t'); -} - -/* What to do when a NEWLINE is pressed. We accept the whole line. - KEY is the key that invoked this command. I guess it could have - meaning in the future. */ -rl_newline (count, key) - int count, key; -{ - - rl_done = 1; - -#ifdef VI_MODE - { - extern int vi_doing_insert; - if (vi_doing_insert) - { - rl_end_undo_group (); - vi_doing_insert = 0; - } - } -#endif /* VI_MODE */ - - if (readline_echoing_p) - { - move_vert (vis_botlin); - vis_botlin = 0; - crlf (); - fflush (out_stream); - rl_display_fixed++; - } -} + } -rl_clean_up_for_exit () -{ - if (readline_echoing_p) - { - move_vert (vis_botlin); - vis_botlin = 0; - fflush (out_stream); - rl_restart_output (); + while (rl_point) + { + c = the_line[rl_point - 1]; + if (!alphabetic (c)) + break; + else --rl_point; + } + --count; } } -/* What to do for some uppercase characters, like meta characters, - and some characters appearing in emacs_ctlx_keymap. This function - is just a stub, you bind keys to it and the code in rl_dispatch () - is special cased. */ -rl_do_lowercase_version (ignore1, ignore2) - int ignore1, ignore2; +/* Clear the current line. Numeric argument to C-l does this. */ +void rl_refresh_line () { + int curr_line = last_c_pos / screenwidth; + extern char *term_clreol; + + move_vert(curr_line); + move_cursor_relative (0, the_line); /* XXX is this right */ + + if (term_clreol) + tputs (term_clreol, 1, output_character_function); + + rl_forced_update_display (); + rl_display_fixed = 1; } -/* Rubout the character behind point. */ -void rl_rubout (count) - int count; +/* C-l typed to a line without quoting clears the screen, and then reprints + the prompt and the current input line. Given a numeric arg, redraw only + the current line. */ +void rl_clear_screen () { - if (count < 0) - { - rl_delete (-count); - return; - } + extern char *term_clrpag; - if (!rl_point) + if (rl_explicit_arg) { - ding (); + rl_refresh_line (); return; } - if (count > 1) - { - int orig_point = rl_point; - rl_backward (count); - rl_kill_text (orig_point, rl_point); - } + if (term_clrpag) + tputs (term_clrpag, 1, output_character_function); else - { - int c = the_line[--rl_point]; - rl_delete_text (rl_point, rl_point + 1); + crlf (); - if (rl_point == rl_end && alphabetic (c) && last_c_pos) - { - backspace (1); - putc (' ', out_stream); - backspace (1); - last_c_pos--; - visible_line[last_c_pos] = '\0'; - rl_display_fixed++; - } - } + rl_forced_update_display (); + rl_display_fixed = 1; } -/* Delete the character under the cursor. Given a numeric argument, - kill that many characters instead. */ -void rl_delete (count, invoking_key) - int count, invoking_key; +void rl_arrow_keys(count,c) + int count,c; { - if (count < 0) - { - rl_rubout (-count); - return; - } + int ch = rl_read_key(); - if (rl_point == rl_end) - { - ding (); + switch(ch) { + case 'a': + case 'A': + rl_get_previous_history(count); return; - } - - if (count > 1) - { - int orig_point = rl_point; - rl_forward (count); - rl_kill_text (orig_point, rl_point); - rl_point = orig_point; - } - else - rl_delete_text (rl_point, rl_point + 1); + case 'b': + case 'B': + rl_get_next_history(count); + return; + case 'c': + case 'C': + rl_forward(count); + return; + case 'd': + case 'D': + rl_backward(count); + return; + default: + ding(); + return; + } } - -/* **************************************************************** */ + /* **************************************************************** */ /* */ /* Kill commands */ /* */ @@ -3228,6 +3847,63 @@ rl_unix_line_discard () #define DownCase 2 #define CapCase 3 + +/* The meaty function. + Change the case of COUNT words, performing OP on them. + OP is one of UpCase, DownCase, or CapCase. + If a negative argument is given, leave point where it started, + otherwise, leave it where it moves to. */ +rl_change_case (int count, int op) +{ + register int start = rl_point, end; + int state = 0; + + rl_forward_word (count); + end = rl_point; + + if (count < 0) + { + int temp = start; + start = end; + end = temp; + } + + /* We are going to modify some text, so let's prepare to undo it. */ + rl_modifying (start, end); + + for (; start < end; start++) + { + switch (op) + { + case UpCase: + the_line[start] = to_upper (the_line[start]); + break; + + case DownCase: + the_line[start] = to_lower (the_line[start]); + break; + + case CapCase: + if (state == 0) + { + the_line[start] = to_upper (the_line[start]); + state = 1; + } + else + { + the_line[start] = to_lower (the_line[start]); + } + if (!pure_alphabetic (the_line[start])) + state = 0; + break; + + default: + abort (); + } + } + rl_point = end; +} + /* Uppercase the word at point. */ rl_upcase_word (count) int count; @@ -3249,62 +3925,6 @@ rl_capitalize_word (count) rl_change_case (count, CapCase); } -/* The meaty function. - Change the case of COUNT words, performing OP on them. - OP is one of UpCase, DownCase, or CapCase. - If a negative argument is given, leave point where it started, - otherwise, leave it where it moves to. */ -rl_change_case (count, op) - int count, op; -{ - register int start = rl_point, end; - int state = 0; - - rl_forward_word (count); - end = rl_point; - - if (count < 0) - { - int temp = start; - start = end; - end = temp; - } - - /* We are going to modify some text, so let's prepare to undo it. */ - rl_modifying (start, end); - - for (; start < end; start++) - { - switch (op) - { - case UpCase: - the_line[start] = to_upper (the_line[start]); - break; - - case DownCase: - the_line[start] = to_lower (the_line[start]); - break; - - case CapCase: - if (state == 0) - { - the_line[start] = to_upper (the_line[start]); - state = 1; - } - else - { - the_line[start] = to_lower (the_line[start]); - } - if (!pure_alphabetic (the_line[start])) - state = 0; - break; - - default: - abort (); - } - } - rl_point = end; -} /* **************************************************************** */ /* */ @@ -3446,34 +4066,16 @@ Function *rl_completion_entry_function = (Function *)NULL; array of strings returned. */ PFunction *rl_attempted_completion_function = (PFunction *)NULL; -/* Complete the word at or before point. You have supplied the function - that does the initial simple matching selection algorithm (see - completion_matches ()). The default is to do filename completion. */ -rl_complete (ignore, invoking_key) - int ignore, invoking_key; -{ - if (rl_last_func == rl_complete) - rl_complete_internal ('?'); - else - rl_complete_internal (TAB); -} - -/* List the possible completions. See description of rl_complete (). */ -rl_possible_completions () -{ - rl_complete_internal ('?'); -} - /* The user must press "y" or "n". Non-zero return means "y" pressed. */ get_y_or_n () { - int c; - loop: - c = rl_read_key (); - if (c == 'y' || c == 'Y') return (1); - if (c == 'n' || c == 'N') return (0); - if (c == ABORT_CHAR) rl_abort (); - ding (); goto loop; + int c; + loop: + c = rl_read_key (); + if (c == 'y' || c == 'Y') return (1); + if (c == 'n' || c == 'N') return (0); + if (c == ABORT_CHAR) rl_abort (); + ding (); goto loop; } /* Up to this many items will be displayed in response to a @@ -3488,399 +4090,419 @@ char *rl_basic_word_break_characters = " \t\n\"\\'`@$><="; /* The list of characters that signal a break between words for rl_complete_internal. The default list is the contents of - rl_basic_word_break_characters. */ -char *rl_completer_word_break_characters = (char *)NULL; - -/* List of characters that are word break characters, but should be left - in TEXT when it is passed to the completion function. The shell uses - this to help determine what kind of completing to do. */ -char *rl_special_prefixes = (char *)NULL; - -/* If non-zero, then disallow duplicates in the matches. */ -int rl_ignore_completion_duplicates = 1; - -/* Non-zero means that the results of the matches are to be treated - as filenames. This is ALWAYS zero on entry, and can only be changed - within a completion entry finder function. */ -int rl_filename_completion_desired = 0; - -/* This function, if defined, is called by the completer when real - filename completion is done, after all the matching names have been - generated. It is passed a (char**) known as matches in the code below. - It consists of a NULL-terminated array of pointers to potential - matching strings. The 1st element (matches[0]) is the maximal - substring that is common to all matches. This function can re-arrange - the list of matches as required, but all elements of the array must be - free()'d if they are deleted. The main intent of this function is - to implement FIGNORE a la SunOS csh. */ -Function *rl_ignore_some_completions_function = (Function *)NULL; - -/* Complete the word at or before point. - WHAT_TO_DO says what to do with the completion. - `?' means list the possible completions. - TAB means do standard completion. - `*' means insert all of the possible completions. */ -rl_complete_internal (what_to_do) - int what_to_do; -{ - char *filename_completion_function (); - char **completion_matches (), **matches; - Function *our_func; - int start, end, delimiter = 0; - char *text; - - if (rl_completion_entry_function) - our_func = rl_completion_entry_function; - else - our_func = (int (*)())filename_completion_function; - - /* Only the completion entry function can change this. */ - rl_filename_completion_desired = 0; - - /* We now look backwards for the start of a filename/variable word. */ - end = rl_point; - - if (rl_point) - { - while (--rl_point && - !rindex (rl_completer_word_break_characters, the_line[rl_point])); - - /* If we are at a word break, then advance past it. */ - if (rindex (rl_completer_word_break_characters, (the_line[rl_point]))) - { - /* If the character that caused the word break was a quoting - character, then remember it as the delimiter. */ - if (rindex ("\"'", the_line[rl_point]) && (end - rl_point) > 1) - delimiter = the_line[rl_point]; - - /* If the character isn't needed to determine something special - about what kind of completion to perform, then advance past it. */ - - if (!rl_special_prefixes || - !rindex (rl_special_prefixes, the_line[rl_point])) - rl_point++; - } - } - - start = rl_point; - rl_point = end; - text = rl_copy (start, end); - - /* If the user wants to TRY to complete, but then wants to give - up and use the default completion function, they set the - variable rl_attempted_completion_function. */ - if (rl_attempted_completion_function) - { - matches = - (char **)(*rl_attempted_completion_function) (text, start, end); - - if (matches) - { - our_func = (Function *)NULL; - goto after_usual_completion; - } - } - - matches = completion_matches (text, our_func); - - after_usual_completion: - free (text); - - if (!matches) - ding (); - else - { - register int i; - - some_matches: - - /* It seems to me that in all the cases we handle we would like - to ignore duplicate possiblilities. Scan for the text to - insert being identical to the other completions. */ - if (rl_ignore_completion_duplicates) - { - char *lowest_common; - int j, newlen = 0; - - /* Sort the items. */ - /* It is safe to sort this array, because the lowest common - denominator found in matches[0] will remain in place. */ - for (i = 0; matches[i]; i++); - qsort (matches, i, sizeof (char *), compare_strings); - - /* Remember the lowest common denominator for it may be unique. */ - lowest_common = savestring (matches[0]); - - for (i = 0; matches[i + 1]; i++) - { - if (strcmp (matches[i], matches[i + 1]) == 0) - { - free (matches[i]); - matches[i] = (char *)-1; - } - else - newlen++; - } - - /* We have marked all the dead slots with (char *)-1. - Copy all the non-dead entries into a new array. */ - { - char **temp_array = - (char **)malloc ((3 + newlen) * sizeof (char *)); - - for (i = 1, j = 1; matches[i]; i++) - { - if (matches[i] != (char *)-1) - temp_array[j++] = matches[i]; - } - - temp_array[j] = (char *)NULL; - - if (matches[0] != (char *)-1) - free (matches[0]); - - free (matches); - - matches = temp_array; - } - - /* Place the lowest common denominator back in [0]. */ - matches[0] = lowest_common; - - /* If there is one string left, and it is identical to the - lowest common denominator, then the LCD is the string to - insert. */ - if (j == 2 && strcmp (matches[0], matches[1]) == 0) - { - free (matches[1]); - matches[1] = (char *)NULL; - } - } - - switch (what_to_do) - { - case TAB: - /* If we are matching filenames, then here is our chance to - do clever processing by re-examining the list. Call the - ignore function with the array as a parameter. It can - munge the array, deleting matches as it desires */ - if (rl_ignore_some_completions_function && - our_func == (int (*)())filename_completion_function) - (void)(*rl_ignore_some_completions_function)(matches); - - if (matches[0]) - { - rl_delete_text (start, rl_point); - rl_point = start; - rl_insert_text (matches[0]); - } - - /* If there are more matches, ring the bell to indicate. - If this was the only match, and we are hacking files, - check the file to see if it was a directory. If so, - add a '/' to the name. If not, and we are at the end - of the line, then add a space. */ - if (matches[1]) - { - ding (); /* There are other matches remaining. */ - } - else - { - char temp_string[2]; + rl_basic_word_break_characters. */ +char *rl_completer_word_break_characters = (char *)NULL; - temp_string[0] = delimiter ? delimiter : ' '; - temp_string[1] = '\0'; +/* List of characters that are word break characters, but should be left + in TEXT when it is passed to the completion function. The shell uses + this to help determine what kind of completing to do. */ +char *rl_special_prefixes = (char *)NULL; - if (rl_filename_completion_desired) - { - struct stat finfo; - char *tilde_expand (); - char *filename = tilde_expand (matches[0]); +/* If non-zero, then disallow duplicates in the matches. */ +int rl_ignore_completion_duplicates = 1; - if ((stat (filename, &finfo) == 0) && - ((finfo.st_mode & S_IFMT) == S_IFDIR)) - { - if (the_line[rl_point] != '/') - rl_insert_text ("/"); - } - else - { - if (rl_point == rl_end) - rl_insert_text (temp_string); - } - free (filename); - } - else - { - if (rl_point == rl_end) - rl_insert_text (temp_string); - } - } - break; +/* Non-zero means that the results of the matches are to be treated + as filenames. This is ALWAYS zero on entry, and can only be changed + within a completion entry finder function. */ +int rl_filename_completion_desired = 0; - case '*': - { - int i = 1; +/* This function, if defined, is called by the completer when real + filename completion is done, after all the matching names have been + generated. It is passed a (char**) known as matches in the code below. + It consists of a NULL-terminated array of pointers to potential + matching strings. The 1st element (matches[0]) is the maximal + substring that is common to all matches. This function can re-arrange + the list of matches as required, but all elements of the array must be + free()'d if they are deleted. The main intent of this function is + to implement FIGNORE a la SunOS csh. */ +Function *rl_ignore_some_completions_function = (Function *)NULL; - rl_delete_text (start, rl_point); - rl_point = start; - rl_begin_undo_group (); - if (matches[1]) - { - while (matches[i]) - { - rl_insert_text (matches[i++]); - rl_insert_text (" "); - } - } - else - { - rl_insert_text (matches[0]); - rl_insert_text (" "); - } - rl_end_undo_group (); - } - break; - case '?': - { - int len, count, limit, max = 0; - int j, k, l; +/* Complete the word at or before point. + WHAT_TO_DO says what to do with the completion. + `?' means list the possible completions. + TAB means do standard completion. + `*' means insert all of the possible completions. */ +rl_complete_internal (int what_to_do) +{ + char *filename_completion_function (); + char **completion_matches (), **matches; + Function *our_func; + int start, end, delimiter = 0; + char *text; - /* Handle simple case first. What if there is only one answer? */ - if (!matches[1]) - { - char *temp; - - if (rl_filename_completion_desired) - temp = rindex (matches[0], '/'); - else - temp = (char *)NULL; - - if (!temp) - temp = matches[0]; - else - temp++; - - crlf (); - fprintf (out_stream, "%s", temp); - crlf (); - goto restart; - } + if (rl_completion_entry_function) + our_func = rl_completion_entry_function; + else + our_func = (int (*)())filename_completion_function; - /* There is more than one answer. Find out how many there are, - and find out what the maximum printed length of a single entry - is. */ - for (i = 1; matches[i]; i++) - { - char *temp = (char *)NULL; - - /* If we are hacking filenames, then only count the characters - after the last slash in the pathname. */ - if (rl_filename_completion_desired) - temp = rindex (matches[i], '/'); - else - temp = (char *)NULL; - - if (!temp) - temp = matches[i]; - else - temp++; - - if (strlen (temp) > max) - max = strlen (temp); - } + /* Only the completion entry function can change this. */ + rl_filename_completion_desired = 0; - len = i; + /* We now look backwards for the start of a filename/variable word. */ + end = rl_point; - /* If there are many items, then ask the user if she - really wants to see them all. */ - if (len >= rl_completion_query_items) - { - crlf (); - fprintf (out_stream, - "There are %d possibilities. Do you really", len); - crlf (); - fprintf (out_stream, "wish to see them all? (y or n)"); - fflush (out_stream); - if (!get_y_or_n ()) - { - crlf (); - goto restart; - } - } - /* How many items of MAX length can we fit in the screen window? */ - max += 2; - limit = screenwidth / max; - if (limit != 1 && (limit * max == screenwidth)) - limit--; + if (rl_point) + { + while (--rl_point && + !rindex (rl_completer_word_break_characters, the_line[rl_point])); - /* Avoid a possible floating exception. If max > screenwidth, - limit will be 0 and a divide-by-zero fault will result. */ - if (limit == 0) - limit = 1; + /* If we are at a word break, then advance past it. */ + if (rindex (rl_completer_word_break_characters, (the_line[rl_point]))) + { + /* If the character that caused the word break was a quoting + character, then remember it as the delimiter. */ + if (rindex ("\"'", the_line[rl_point]) && (end - rl_point) > 1) + delimiter = the_line[rl_point]; - /* How many iterations of the printing loop? */ - count = (len + (limit - 1)) / limit; + /* If the character isn't needed to determine something special + about what kind of completion to perform, then advance past it. */ - /* Watch out for special case. If LEN is less than LIMIT, then - just do the inner printing loop. */ - if (len < limit) count = 1; + if (!rl_special_prefixes || + !rindex (rl_special_prefixes, the_line[rl_point])) + rl_point++; + } + } - /* Sort the items if they are not already sorted. */ - if (!rl_ignore_completion_duplicates) - qsort (matches, len, sizeof (char *), compare_strings); + start = rl_point; + rl_point = end; + text = rl_copy (start, end); - /* Print the sorted items, up-and-down alphabetically, like - ls might. */ - crlf (); + /* If the user wants to TRY to complete, but then wants to give + up and use the default completion function, they set the + variable rl_attempted_completion_function. */ + if (rl_attempted_completion_function) + { + matches = + (char **)(*rl_attempted_completion_function) (text, start, end); - for (i = 1; i < count + 1; i++) - { - for (j = 0, l = i; j < limit; j++) - { - if (l > len || !matches[l]) - { - break; - } - else - { - char *temp = (char *)NULL; + if (matches) + { + our_func = (Function *)NULL; + goto after_usual_completion; + } + } - if (rl_filename_completion_desired) - temp = rindex (matches[l], '/'); - else - temp = (char *)NULL; + matches = completion_matches (text, our_func); - if (!temp) - temp = matches[l]; - else - temp++; - - fprintf (out_stream, "%s", temp); - for (k = 0; k < max - strlen (temp); k++) - putc (' ', out_stream); - } - l += count; - } - crlf (); - } - restart: + after_usual_completion: + free (text); - rl_on_new_line (); - } - break; + if (!matches) + ding (); + else + { + register int i; + + some_matches: + + /* It seems to me that in all the cases we handle we would like + to ignore duplicate possiblilities. Scan for the text to + insert being identical to the other completions. */ + if (rl_ignore_completion_duplicates) + { + char *lowest_common; + int j, newlen = 0; + + /* Sort the items. */ + /* It is safe to sort this array, because the lowest common + denominator found in matches[0] will remain in place. */ + for (i = 0; matches[i]; i++); + qsort (matches, i, sizeof (char *), compare_strings); + + /* Remember the lowest common denominator for it may be unique. */ + lowest_common = savestring (matches[0]); + + for (i = 0; matches[i + 1]; i++) + { + if (strcmp (matches[i], matches[i + 1]) == 0) + { + free (matches[i]); + matches[i] = (char *)-1; + } + else + newlen++; + } + + /* We have marked all the dead slots with (char *)-1. + Copy all the non-dead entries into a new array. */ + { + char **temp_array = + (char **)malloc ((3 + newlen) * sizeof (char *)); + + for (i = 1, j = 1; matches[i]; i++) + { + if (matches[i] != (char *)-1) + temp_array[j++] = matches[i]; + } + + temp_array[j] = (char *)NULL; + + if (matches[0] != (char *)-1) + free (matches[0]); + + free (matches); + + matches = temp_array; + } + + /* Place the lowest common denominator back in [0]. */ + matches[0] = lowest_common; + + /* If there is one string left, and it is identical to the + lowest common denominator, then the LCD is the string to + insert. */ + if (j == 2 && strcmp (matches[0], matches[1]) == 0) + { + free (matches[1]); + matches[1] = (char *)NULL; + } + } + + switch (what_to_do) + { + case TAB: + /* If we are matching filenames, then here is our chance to + do clever processing by re-examining the list. Call the + ignore function with the array as a parameter. It can + munge the array, deleting matches as it desires */ + if (rl_ignore_some_completions_function && + our_func == (int (*)())filename_completion_function) + (void)(*rl_ignore_some_completions_function)(matches); + + if (matches[0]) + { + rl_delete_text (start, rl_point); + rl_point = start; + rl_insert_text (matches[0]); + } + + /* If there are more matches, ring the bell to indicate. + If this was the only match, and we are hacking files, + check the file to see if it was a directory. If so, + add a '/' to the name. If not, and we are at the end + of the line, then add a space. */ + if (matches[1]) + { + ding (); /* There are other matches remaining. */ + } + else + { + char temp_string[2]; + + temp_string[0] = delimiter ? delimiter : ' '; + temp_string[1] = '\0'; + + if (rl_filename_completion_desired) + { + struct stat finfo; + char *tilde_expand (); + char *filename = tilde_expand (matches[0]); + + if ((stat (filename, &finfo) == 0) && + ((finfo.st_mode & S_IFMT) == S_IFDIR)) + { + if (the_line[rl_point] != '/') + rl_insert_text ("/"); + } + else + { + if (rl_point == rl_end) + rl_insert_text (temp_string); + } + free (filename); + } + else + { + if (rl_point == rl_end) + rl_insert_text (temp_string); + } + } + break; + + case '*': + { + int i = 1; + + rl_delete_text (start, rl_point); + rl_point = start; + rl_begin_undo_group (); + if (matches[1]) + { + while (matches[i]) + { + rl_insert_text (matches[i++]); + rl_insert_text (" "); + } + } + else + { + rl_insert_text (matches[0]); + rl_insert_text (" "); + } + rl_end_undo_group (); + } + break; + + case '?': + { + int len, count, limit, max = 0; + int j, k, l; + + /* Handle simple case first. What if there is only one answer? */ + if (!matches[1]) + { + char *temp; + + if (rl_filename_completion_desired) + temp = rindex (matches[0], '/'); + else + temp = (char *)NULL; + + if (!temp) + temp = matches[0]; + else + temp++; + + crlf (); + fprintf (out_stream, "%s", temp); + crlf (); + goto restart; + } + + /* There is more than one answer. Find out how many there are, + and find out what the maximum printed length of a single entry + is. */ + for (i = 1; matches[i]; i++) + { + char *temp = (char *)NULL; + + /* If we are hacking filenames, then only count the characters + after the last slash in the pathname. */ + if (rl_filename_completion_desired) + temp = rindex (matches[i], '/'); + else + temp = (char *)NULL; + + if (!temp) + temp = matches[i]; + else + temp++; + + if (strlen (temp) > max) + max = strlen (temp); + } + + len = i; + + /* If there are many items, then ask the user if she + really wants to see them all. */ + if (len >= rl_completion_query_items) + { + crlf (); + fprintf (out_stream, + "There are %d possibilities. Do you really", len); + crlf (); + fprintf (out_stream, "wish to see them all? (y or n)"); + fflush (out_stream); + if (!get_y_or_n ()) + { + crlf (); + goto restart; + } + } + /* How many items of MAX length can we fit in the screen window? */ + max += 2; + limit = screenwidth / max; + if (limit != 1 && (limit * max == screenwidth)) + limit--; + + /* Avoid a possible floating exception. If max > screenwidth, + limit will be 0 and a divide-by-zero fault will result. */ + if (limit == 0) + limit = 1; + + /* How many iterations of the printing loop? */ + count = (len + (limit - 1)) / limit; + + /* Watch out for special case. If LEN is less than LIMIT, then + just do the inner printing loop. */ + if (len < limit) count = 1; + + /* Sort the items if they are not already sorted. */ + if (!rl_ignore_completion_duplicates) + qsort (matches, len, sizeof (char *), compare_strings); + + /* Print the sorted items, up-and-down alphabetically, like + ls might. */ + crlf (); + + for (i = 1; i < count + 1; i++) + { + for (j = 0, l = i; j < limit; j++) + { + if (l > len || !matches[l]) + { + break; + } + else + { + char *temp = (char *)NULL; + + if (rl_filename_completion_desired) + temp = rindex (matches[l], '/'); + else + temp = (char *)NULL; + + if (!temp) + temp = matches[l]; + else + temp++; + + fprintf (out_stream, "%s", temp); + for (k = 0; k < max - strlen (temp); k++) + putc (' ', out_stream); + } + l += count; + } + crlf (); + } + restart: + + rl_on_new_line (); + } + break; + + default: + abort (); + } + + for (i = 0; matches[i]; i++) + free (matches[i]); + free (matches); + } +} - default: - abort (); - } - for (i = 0; matches[i]; i++) - free (matches[i]); - free (matches); - } +/* Complete the word at or before point. You have supplied the function + that does the initial simple matching selection algorithm (see + completion_matches ()). The default is to do filename completion. */ +rl_complete (ignore, invoking_key) +int ignore, invoking_key; +{ +if (rl_last_func == rl_complete) +rl_complete_internal ('?'); +else +rl_complete_internal (TAB); } +/* List the possible completions. See description of rl_complete (). */ +rl_possible_completions () +{ + rl_complete_internal ('?'); +} + + /* Stupid comparison routine for qsort () ing strings. */ static int compare_strings (s1, s2) @@ -4009,269 +4631,36 @@ tilde_expand (filename) + strlen (&dirname[i])); strcpy (temp_name, expansion); strcat (temp_name, &dirname[i]); - free (expansion); - goto return_name; - } - } - /* - * We shouldn't report errors. - */ - } - else - { - temp_name = (char *)Alloca (1 + strlen (user_entry->pw_dir) - + strlen (&dirname[i])); - strcpy (temp_name, user_entry->pw_dir); - strcat (temp_name, &dirname[i]); - return_name: - free (dirname); - dirname = savestring (temp_name); -#if NO_ALLOCA - free(temp_name); -#endif - } - endpwent (); -#if NO_ALLOCA - free(username); -#endif - } - } - return (dirname); -} - - -/* **************************************************************** */ -/* */ -/* Undo, and Undoing */ -/* */ -/* **************************************************************** */ - -/* Non-zero tells rl_delete_text and rl_insert_text to not add to - the undo list. */ -int doing_an_undo = 0; - -/* The current undo list for THE_LINE. */ -UNDO_LIST *rl_undo_list = (UNDO_LIST *)NULL; - -/* Remember how to undo something. Concatenate some undos if that - seems right. */ -rl_add_undo (what, start, end, text) - enum undo_code what; - int start, end; - char *text; -{ - UNDO_LIST *temp = (UNDO_LIST *)xmalloc (sizeof (UNDO_LIST)); - temp->what = what; - temp->start = start; - temp->end = end; - temp->text = text; - temp->next = rl_undo_list; - rl_undo_list = temp; -} - -/* Free the existing undo list. */ -free_undo_list () -{ - while (rl_undo_list) { - UNDO_LIST *release = rl_undo_list; - rl_undo_list = rl_undo_list->next; - - if (release->what == UNDO_DELETE) - free (release->text); - - free (release); - } -} - -/* Undo the next thing in the list. Return 0 if there - is nothing to undo, or non-zero if there was. */ -int -rl_do_undo () -{ - UNDO_LIST *release; - int waiting_for_begin = 0; - -undo_thing: - if (!rl_undo_list) - return (0); - - doing_an_undo = 1; - - switch (rl_undo_list->what) { - - /* Undoing deletes means inserting some text. */ - case UNDO_DELETE: - rl_point = rl_undo_list->start; - rl_insert_text (rl_undo_list->text); - free (rl_undo_list->text); - break; - - /* Undoing inserts means deleting some text. */ - case UNDO_INSERT: - rl_delete_text (rl_undo_list->start, rl_undo_list->end); - rl_point = rl_undo_list->start; - break; - - /* Undoing an END means undoing everything 'til we get to - a BEGIN. */ - case UNDO_END: - waiting_for_begin++; - break; - - /* Undoing a BEGIN means that we are done with this group. */ - case UNDO_BEGIN: - if (waiting_for_begin) - waiting_for_begin--; - else - abort (); - break; - } - - doing_an_undo = 0; - - release = rl_undo_list; - rl_undo_list = rl_undo_list->next; - free (release); - - if (waiting_for_begin) - goto undo_thing; - - return (1); -} - -/* Begin a group. Subsequent undos are undone as an atomic operation. */ -rl_begin_undo_group () -{ - rl_add_undo (UNDO_BEGIN, 0, 0, 0); -} - -/* End an undo group started with rl_begin_undo_group (). */ -rl_end_undo_group () -{ - rl_add_undo (UNDO_END, 0, 0, 0); -} - -/* Save an undo entry for the text from START to END. */ -rl_modifying (start, end) - int start, end; -{ - if (start > end) - { - int t = start; - start = end; - end = t; - } - - if (start != end) - { - char *temp = rl_copy (start, end); - rl_begin_undo_group (); - rl_add_undo (UNDO_DELETE, start, end, temp); - rl_add_undo (UNDO_INSERT, start, end, (char *)NULL); - rl_end_undo_group (); - } -} - -/* Revert the current line to its previous state. */ -rl_revert_line () -{ - if (!rl_undo_list) ding (); - else { - while (rl_undo_list) - rl_do_undo (); - } -} - -/* Do some undoing of things that were done. */ -void rl_undo_command (count) -{ - if (count < 0) return; /* Nothing to do. */ - - while (count) - { - if (rl_do_undo ()) - { - count--; - } - else - { - ding (); - break; - } - } -} - -/* **************************************************************** */ -/* */ -/* History Utilities */ -/* */ -/* **************************************************************** */ - -/* We already have a history library, and that is what we use to control - the history features of readline. However, this is our local interface - to the history mechanism. */ - -/* While we are editing the history, this is the saved - version of the original line. */ -HIST_ENTRY *saved_line_for_history = (HIST_ENTRY *)NULL; - -/* Set the history pointer back to the last entry in the history. */ -start_using_history () -{ - using_history (); - if (saved_line_for_history) - free_history_entry (saved_line_for_history); - - saved_line_for_history = (HIST_ENTRY *)NULL; -} - -/* Free the contents (and containing structure) of a HIST_ENTRY. */ -void free_history_entry (entry) - HIST_ENTRY *entry; -{ - if (!entry) return; - if (entry->line) - free (entry->line); - free (entry); -} - -/* Perhaps put back the current line if it has changed. */ -maybe_replace_line () -{ - HIST_ENTRY *temp = current_history (); - - /* If the current line has changed, save the changes. */ - if (temp && ((UNDO_LIST *)(temp->data) != rl_undo_list)) { - temp = replace_history_entry (where_history (), the_line, rl_undo_list); - free (temp->line); - free (temp); - } -} - -/* Put back the saved_line_for_history if there is one. */ -maybe_unsave_line () -{ - if (saved_line_for_history) { - strcpy (the_line, saved_line_for_history->line); - rl_undo_list = (UNDO_LIST *)saved_line_for_history->data; - free_history_entry (saved_line_for_history); - saved_line_for_history = (HIST_ENTRY *)NULL; - rl_end = rl_point = strlen (the_line); - } else { - ding (); - } -} - -/* Save the current line in saved_line_for_history. */ -maybe_save_line () -{ - if (!saved_line_for_history) { - saved_line_for_history = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY)); - saved_line_for_history->line = savestring (the_line); - saved_line_for_history->data = (char *)rl_undo_list; - } + free (expansion); + goto return_name; + } + } + /* + * We shouldn't report errors. + */ + } + else + { + temp_name = (char *)Alloca (1 + strlen (user_entry->pw_dir) + + strlen (&dirname[i])); + strcpy (temp_name, user_entry->pw_dir); + strcat (temp_name, &dirname[i]); + return_name: + free (dirname); + dirname = savestring (temp_name); +#if NO_ALLOCA + free(temp_name); +#endif + } + endpwent (); +#if NO_ALLOCA + free(username); +#endif + } + } + return (dirname); } - + /* **************************************************************** */ /* */ @@ -4451,6 +4840,13 @@ rl_display_search (search_string, reverse_p, where) #endif } +/* Make C be the next command to be executed. */ +rl_execute_next (c) +int c; +{ + rl_pending_input = c; +} + /* Search through the history looking for an interactively typed string. This is analogous to i-search. We start the search in the current line. DIRECTION is which direction to search; > 0 means forward, < 0 means @@ -4712,12 +5108,6 @@ void rl_search_history (direction, invoking_key) #endif } -/* Make C be the next command to be executed. */ -rl_execute_next (c) - int c; -{ - rl_pending_input = c; -} /* **************************************************************** */ /* */ @@ -5150,420 +5540,93 @@ filename_completion_function (text, state) if (temp) { - strcpy (filename, ++temp); - *temp = '\0'; - } - else - strcpy (dirname, "."); - - /* We aren't done yet. We also support the "~user" syntax. */ - - /* Save the version of the directory that the user typed. */ - users_dirname = savestring (dirname); - { - char *tilde_expand (), *temp_dirname = tilde_expand (dirname); - free (dirname); - dirname = temp_dirname; - - if (rl_symbolic_link_hook) - (*rl_symbolic_link_hook) (&dirname); - } - directory = opendir (dirname); - filename_len = strlen (filename); - - rl_filename_completion_desired = 1; - } - - /* At this point we should entertain the possibility of hacking wildcarded - filenames, like /usr/man*\/te. If the directory name contains - globbing characters, then build an array of directories to glob on, and - glob on the first one. */ - - /* Now that we have some state, we can read the directory. */ - - while (directory && (entry = readdir (directory))) - { - /* Special case for no filename. - All entries except "." and ".." match. */ - if (!filename_len) - { - if ((strcmp (entry->d_name, ".") != 0) && - (strcmp (entry->d_name, "..") != 0)) - break; - } - else - { - /* Otherwise, if these match upto the length of filename, then - it is a match. */ -#if defined(LINUX) || defined(CYGWIN) - if ((strlen(entry->d_name) >= filename_len) && -#else - if (((int)entry->d_namlen >= filename_len) && -#endif - (strncmp (filename, entry->d_name, filename_len) == 0)) - { - break; - } - } - } - - if (!entry) - { - if (directory) - { - closedir (directory); - directory = (DIR *)NULL; - } - return (char *)NULL; - } - else - { - char *temp; - - if (dirname && (strcmp (dirname, ".") != 0)) - { - temp = (char *)xmalloc (1 + strlen (users_dirname) -#if defined(LINUX) || defined(CYGWIN) - + strlen(entry->d_name)); -#else - + entry->d_namlen); -#endif - strcpy (temp, users_dirname); - strcat (temp, entry->d_name); - } - else - { - temp = (savestring (entry->d_name)); - } - return (temp); - } -} - - -/* **************************************************************** */ -/* */ -/* Binding keys */ -/* */ -/* **************************************************************** */ - -/* rl_add_defun (char *name, Function *function, int key) - Add NAME to the list of named functions. Make FUNCTION - be the function that gets called. - If KEY is not -1, then bind it. */ -rl_add_defun (name, function, key) - char *name; - Function *function; - int key; -{ - if (key != -1) - rl_bind_key (key, function); - rl_add_funmap_entry (name, function); -} - -/* Bind KEY to FUNCTION. Returns non-zero if KEY is out of range. */ -int -rl_bind_key (key, function) - int key; - Function *function; -{ - if (key < 0) - return (key); - - if (key > 127 && key < 256) - { - if (keymap[ESC].type == ISKMAP) - { - Keymap escmap = (Keymap)keymap[ESC].function; - - key -= 128; - escmap[key].type = ISFUNC; - escmap[key].function = function; - return (0); - } - return (key); - } - - keymap[key].type = ISFUNC; - keymap[key].function = function; - return (0); -} - -/* Bind KEY to FUNCTION in MAP. Returns non-zero in case of invalid - KEY. */ -int -rl_bind_key_in_map (key, function, map) - int key; - Function *function; - Keymap map; -{ - int result; - Keymap oldmap = keymap; - - keymap = map; - result = rl_bind_key (key, function); - keymap = oldmap; - return (result); -} - -/* Make KEY do nothing in the currently selected keymap. - Returns non-zero in case of error. */ -int -rl_unbind_key (key) - int key; -{ - return (rl_bind_key (key, (Function *)NULL)); -} - -/* Make KEY do nothing in MAP. - Returns non-zero in case of error. */ -int -rl_unbind_key_in_map (key, map) - int key; - Keymap map; -{ - return (rl_bind_key_in_map (key, (Function *)NULL, map)); -} - -/* Bind the key sequence represented by the string KEYSEQ to - FUNCTION. This makes new keymaps as necessary. The initial - place to do bindings is in MAP. */ -rl_set_key (keyseq, function, map) - char *keyseq; - Function *function; - Keymap map; -{ - rl_generic_bind (ISFUNC, keyseq, function, map); -} - -/* Bind the key sequence represented by the string KEYSEQ to - the string of characters MACRO. This makes new keymaps as - necessary. The initial place to do bindings is in MAP. */ -void rl_macro_bind (keyseq, macro, map) - char *keyseq, *macro; - Keymap map; -{ - char *macro_keys = (char *)xmalloc (2 * (strlen (macro))); - int macro_keys_len; - - if (rl_translate_keyseq (macro, macro_keys, ¯o_keys_len)) - { - free (macro_keys); - return; - } - rl_generic_bind (ISMACR, keyseq, macro_keys, map); -} - -/* Bind the key sequence represented by the string KEYSEQ to - the arbitrary pointer DATA. TYPE says what kind of data is - pointed to by DATA, right now this can be a function (ISFUNC), - a macro (ISMACR), or a keymap (ISKMAP). This makes new keymaps - as necessary. The initial place to do bindings is in MAP. */ -void rl_generic_bind (type, keyseq, data, map) - int type; - char *keyseq, *data; - Keymap map; -{ - char *keys; - int keys_len; - register int i; - - /* If no keys to bind to, exit right away. */ - if (!keyseq || !*keyseq) - { - if (type == ISMACR) - free (data); - return; - } - - keys = (char *)Alloca (1 + (2 * strlen (keyseq))); - - /* Translate the ASCII representation of KEYSEQ into an array - of characters. Stuff the characters into ARRAY, and the - length of ARRAY into LENGTH. */ - if (rl_translate_keyseq (keyseq, keys, &keys_len)) - { -#if NO_ALLOCA - free (keys); -#endif - return; - } - - /* Bind keys, making new keymaps as necessary. */ - for (i = 0; i < keys_len; i++) - { - if (i + 1 < keys_len) - { - if (map[keys[i]].type != ISKMAP) - { - if (map[i].type == ISMACR) - free ((char *)map[i].function); - - map[keys[i]].type = ISKMAP; - map[keys[i]].function = (Function *)rl_make_bare_keymap (); - } - map = (Keymap)map[keys[i]].function; - } - else - { - if (map[keys[i]].type == ISMACR) - free ((char *)map[keys[i]].function); - - map[keys[i]].function = (Function *)data; - map[keys[i]].type = type; - } - } -#if NO_ALLOCA - free (keys); -#endif -} - -/* Translate the ASCII representation of SEQ, stuffing the - values into ARRAY, an array of characters. LEN gets the - final length of ARRAY. Return non-zero if there was an - error parsing SEQ. */ -rl_translate_keyseq (seq, array, len) - char *seq, *array; - int *len; -{ - register int i, c, l = 0; - - for (i = 0; c = seq[i]; i++) - { - if (c == '\\') - { - c = seq[++i]; - - if (!c) - break; - - if (((c == 'C' || c == 'M') && seq[i + 1] == '-') || - (c == 'e')) - { - /* Handle special case of backwards define. */ - if (strncmp (&seq[i], "C-\\M-", 5) == 0) - { - array[l++] = ESC; - i += 5; - array[l++] = CTRL (to_upper (seq[i])); - if (!seq[i]) - i--; - continue; - } - - switch (c) - { - case 'M': - i++; - array[l++] = ESC; - break; - - case 'C': - i += 2; - array[l++] = CTRL (to_upper (seq[i])); - break; - - case 'e': - array[l++] = ESC; - } - - continue; - } + strcpy (filename, ++temp); + *temp = '\0'; } - array[l++] = c; - } + else + strcpy (dirname, "."); - *len = l; - array[l] = '\0'; - return (0); -} + /* We aren't done yet. We also support the "~user" syntax. */ -/* Return a pointer to the function that STRING represents. - If STRING doesn't have a matching function, then a NULL pointer - is returned. */ -Function * -rl_named_function (string) - char *string; -{ - register int i; + /* Save the version of the directory that the user typed. */ + users_dirname = savestring (dirname); + { + char *tilde_expand (), *temp_dirname = tilde_expand (dirname); + free (dirname); + dirname = temp_dirname; - for (i = 0; funmap[i]; i++) - if (stricmp (funmap[i]->name, string) == 0) - return (funmap[i]->function); - return ((Function *)NULL); -} + if (rl_symbolic_link_hook) + (*rl_symbolic_link_hook) (&dirname); + } + directory = opendir (dirname); + filename_len = strlen (filename); -/* The last key bindings file read. */ -static char *last_readline_init_file = "~/.inputrc"; + rl_filename_completion_desired = 1; + } -/* Re-read the current keybindings file. */ -rl_re_read_init_file (count, ignore) - int count, ignore; -{ - rl_read_init_file ((char *)NULL); -} + /* At this point we should entertain the possibility of hacking wildcarded + filenames, like /usr/man*\/te. If the directory name contains + globbing characters, then build an array of directories to glob on, and + glob on the first one. */ -/* Do key bindings from a file. If FILENAME is NULL it defaults - to `~/.inputrc'. If the file existed and could be opened and - read, 0 is returned, otherwise errno is returned. */ -int -rl_read_init_file (filename) - char *filename; -{ - register int i; - char *buffer, *openname, *line, *end; - struct stat finfo; - long size; - int file; + /* Now that we have some state, we can read the directory. */ - /* Default the filename. */ - if (!filename) - filename = last_readline_init_file; + while (directory && (entry = readdir (directory))) + { + /* Special case for no filename. + All entries except "." and ".." match. */ + if (!filename_len) + { + if ((strcmp (entry->d_name, ".") != 0) && + (strcmp (entry->d_name, "..") != 0)) + break; + } + else + { + /* Otherwise, if these match upto the length of filename, then + it is a match. */ +#if defined(LINUX) || defined(CYGWIN) + if ((strlen(entry->d_name) >= filename_len) && +#else + if (((int)entry->d_namlen >= filename_len) && +#endif + (strncmp (filename, entry->d_name, filename_len) == 0)) + { + break; + } + } + } - openname = tilde_expand (filename); - if ((stat (openname, &finfo) < 0) || - (file = open (openname, O_RDONLY, 0666)) < 0) + if (!entry) { - free (openname); - return (errno); + if (directory) + { + closedir (directory); + directory = (DIR *)NULL; + } + return (char *)NULL; } else - free (openname); - - last_readline_init_file = filename; - /* on mac os x 10.3.2 with upgrades, gcc 3.3, G5, and st_size is an int64, any expression - such as finfo.st_size + 2 always is 0. This means a 0 size memory request which later on - generates an EXC_BAD_ACCESS during malloc. The following line works around that error. - */ - size = (long)finfo.st_size; - - /* Read the file into BUFFER. */ - buffer = (char *)xmalloc (size + 1); - i = read (file, buffer, size); - close (file); - - if (i != size) - return (errno); - - /* Loop over the lines in the file. Lines that start with `#' are - comments; all other lines are commands for readline initialization. */ - line = buffer; - end = buffer + size; - while (line < end) { - /* Find the end of this line. */ - for (i = 0; line + i != end && line[i] != '\n'; i++); - - /* Mark end of line. */ - line[i] = '\0'; - - /* If the line is not a comment, then parse it. */ - if (*line != '#') - rl_parse_and_bind (line); + char *temp; - /* Move to the next line. */ - line += i + 1; + if (dirname && (strcmp (dirname, ".") != 0)) + { + temp = (char *)xmalloc (1 + strlen (users_dirname) +#if defined(LINUX) || defined(CYGWIN) + + strlen(entry->d_name)); +#else + + entry->d_namlen); +#endif + strcpy (temp, users_dirname); + strcat (temp, entry->d_name); + } + else + { + temp = (savestring (entry->d_name)); + } + return (temp); } - return (0); } /* **************************************************************** */ @@ -5704,6 +5767,86 @@ handle_parser_directive (statement) return (1); } + +/* Return the character which matches NAME. + For example, `Space' returns ' '. */ + +typedef struct { + char *name; + int value; +} assoc_list; + +assoc_list name_key_alist[] = { + { "Space", ' ' }, + { "SPC", ' ' }, + { "Rubout", 0x7f }, + { "DEL", 0x7f }, + { "Tab", 0x09 }, + { "Newline", '\n' }, + { "Return", '\r' }, + { "RET", '\r' }, + { "LFD", '\n' }, + { "Escape", '\033' }, + { "ESC", '\033' }, + + { (char *)0x0, 0 } +}; + +int +glean_key_from_name (name) + char *name; +{ + register int i; + + for (i = 0; name_key_alist[i].name; i++) + if (stricmp (name, name_key_alist[i].name) == 0) + return (name_key_alist[i].value); + + return (*name); +} + + +rl_variable_bind (name, value) + char *name, *value; +{ + if (stricmp (name, "editing-mode") == 0) + { + if (strnicmp (value, "vi", 2) == 0) + { +#ifdef VI_MODE + keymap = vi_insertion_keymap; + rl_editing_mode = vi_mode; +#endif /* VI_MODE */ + } + else if (strnicmp (value, "emacs", 5) == 0) + { + keymap = emacs_standard_keymap; + rl_editing_mode = emacs_mode; + } + } + else if (stricmp (name, "horizontal-scroll-mode") == 0) + { + if (!*value || stricmp (value, "On") == 0) + horizontal_scroll_mode = 1; + else + horizontal_scroll_mode = 0; + } + else if (stricmp (name, "mark-modified-lines") == 0) + { + if (!*value || stricmp (value, "On") == 0) + mark_modified_lines = 1; + else + mark_modified_lines = 0; + } + else if (stricmp (name, "prefer-visible-bell") == 0) + { + if (!*value || stricmp (value, "On") == 0) + prefer_visible_bell = 1; + else + prefer_visible_bell = 0; + } +} + /* Read the binding command from STRING and perform it. A key binding command looks like: Keyname: function-name\0, a variable binding command looks like: set variable value. @@ -5735,7 +5878,7 @@ void rl_parse_and_bind (string) advance to after the matching close quote. */ if (*string == '"') { - for (i = 1; c = string[i]; i++) + for (i = 1; (c = string[i]); i++) { if (c == '"' && string[i - 1] != '\\') break; @@ -5863,85 +6006,6 @@ void rl_parse_and_bind (string) rl_bind_key (key, rl_named_function (funname)); } -rl_variable_bind (name, value) - char *name, *value; -{ - if (stricmp (name, "editing-mode") == 0) - { - if (strnicmp (value, "vi", 2) == 0) - { -#ifdef VI_MODE - keymap = vi_insertion_keymap; - rl_editing_mode = vi_mode; -#endif /* VI_MODE */ - } - else if (strnicmp (value, "emacs", 5) == 0) - { - keymap = emacs_standard_keymap; - rl_editing_mode = emacs_mode; - } - } - else if (stricmp (name, "horizontal-scroll-mode") == 0) - { - if (!*value || stricmp (value, "On") == 0) - horizontal_scroll_mode = 1; - else - horizontal_scroll_mode = 0; - } - else if (stricmp (name, "mark-modified-lines") == 0) - { - if (!*value || stricmp (value, "On") == 0) - mark_modified_lines = 1; - else - mark_modified_lines = 0; - } - else if (stricmp (name, "prefer-visible-bell") == 0) - { - if (!*value || stricmp (value, "On") == 0) - prefer_visible_bell = 1; - else - prefer_visible_bell = 0; - } -} - -/* Return the character which matches NAME. - For example, `Space' returns ' '. */ - -typedef struct { - char *name; - int value; -} assoc_list; - -assoc_list name_key_alist[] = { - { "Space", ' ' }, - { "SPC", ' ' }, - { "Rubout", 0x7f }, - { "DEL", 0x7f }, - { "Tab", 0x09 }, - { "Newline", '\n' }, - { "Return", '\r' }, - { "RET", '\r' }, - { "LFD", '\n' }, - { "Escape", '\033' }, - { "ESC", '\033' }, - - { (char *)0x0, 0 } -}; - -int -glean_key_from_name (name) - char *name; -{ - register int i; - - for (i = 0; name_key_alist[i].name; i++) - if (stricmp (name, name_key_alist[i].name) == 0) - return (name_key_alist[i].value); - - return (*name); -} - - /* **************************************************************** */ /* */ /* String Utility Functions */ @@ -6015,35 +6079,7 @@ strindex (s1, s2) return ((char *)NULL); } - -/* **************************************************************** */ -/* */ -/* USG (System V) Support */ -/* */ -/* **************************************************************** */ - -/* When compiling and running in the `Posix' environment, Ultrix does - not restart system calls, so this needs to do it. */ -int -rl_getc (stream) - FILE *stream; -{ - int result; - unsigned char c; - - while (1) - { - result = read (fileno (stream), &c, sizeof (char)); - - if (result == sizeof (char)) - return (c); - - if (errno != EINTR) - return (EOF); - } -} - -#ifdef STATIC_MALLOC + #ifdef STATIC_MALLOC /* **************************************************************** */ /* */ From 2597d500ad2c56c573078f47c2305c956b41e96d Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Sat, 17 Oct 2020 00:43:22 +0200 Subject: [PATCH 03/17] windows cpp update --- src/ivoc/ivocmain.cpp | 2 +- src/ivoc/pwman.cpp | 6 +++--- src/modlunit/units.cpp | 2 +- src/mswin/extra/Makefile.am | 4 ++-- src/mswin/extra/d2upath.cpp | 2 +- src/mswin/extra/mos2nrn.cpp | 2 +- src/mswin/extra/neuron.cpp | 2 +- src/nrniv/nrncore_write.cpp | 14 ++++++++++++++ .../nrncore_write/callbacks/nrncore_callbacks.cpp | 13 +++++++++++++ src/nrniv/nrncore_write/utils/nrncore_utils.cpp | 15 +++++++++++++++ src/nrniv/nrnpy.cpp | 4 +++- src/nrnjava/njvm.cpp | 2 +- src/nrnmpi/nrnmpi_dynam.cpp | 2 ++ src/nrnoc/init.cpp | 4 +++- src/nrnoc/osxdlfcn.cpp | 8 ++++---- src/nrnpython/inithoc.cpp | 4 ++-- src/nrnpython/nrnpython.cpp | 2 +- src/nrnpython/rxdmath.cpp | 3 +++ src/oc/code2.cpp | 4 ++-- src/oc/cygwinprt.cpp | 3 ++- src/oc/fileio.cpp | 4 ++-- src/oc/hoc.cpp | 6 +----- src/oc/macprt.cpp | 2 +- src/oc/mswinprt.cpp | 8 ++++---- src/readline/readline.c | 2 +- 25 files changed, 84 insertions(+), 36 deletions(-) diff --git a/src/ivoc/ivocmain.cpp b/src/ivoc/ivocmain.cpp index 1efcb30869..6e50190197 100644 --- a/src/ivoc/ivocmain.cpp +++ b/src/ivoc/ivocmain.cpp @@ -194,7 +194,7 @@ extern HWND hCurrWnd; int nrnpy_nositeflag; #if !defined(WIN32) && !MAC && !defined(CYGWIN) -void setneuronhome(const char*) { +extern void setneuronhome(const char*) { neuron_home = getenv("NEURONHOME"); } #endif diff --git a/src/ivoc/pwman.cpp b/src/ivoc/pwman.cpp index 3b1d1e0872..35e9dde68b 100644 --- a/src/ivoc/pwman.cpp +++ b/src/ivoc/pwman.cpp @@ -38,7 +38,7 @@ extern char **hoc_strpop(); #include void iv_display_scale(float); void iv_display_scale(Coord, Coord); // Make if fit into the screen -char* hoc_back2forward(char*); +extern "C" char* hoc_back2forward(char*); #endif #if defined(WIN32) && !defined(CYGWIN) @@ -60,7 +60,7 @@ extern int unlink(const char *); // but any existing trailing info remains! So be sure to unlink first. #undef IOS_OUT #define IOS_OUT (ios::out) -char* hoc_back2forward(char*); +extern "C" char* hoc_back2forward(char*); #else //!WIN32 #if MAC && !defined(carbon) #include @@ -451,7 +451,7 @@ void PWMDismiss::execute() { #else //!HAVE_IV #if defined(CYGWIN) -char* hoc_back2forward(char*); +extern "C" char* hoc_back2forward(char*); #endif #endif //HAVE_IV diff --git a/src/modlunit/units.cpp b/src/modlunit/units.cpp index 5210b871fa..4558b5680a 100755 --- a/src/modlunit/units.cpp +++ b/src/modlunit/units.cpp @@ -35,7 +35,7 @@ #endif #if defined(CYGWIN) -#include "../mswin/extra/d2upath.c" +#include "../mswin/extra/d2upath.cpp" #endif #if defined(WIN32) #include diff --git a/src/mswin/extra/Makefile.am b/src/mswin/extra/Makefile.am index ef6c1ac296..f0899cb851 100755 --- a/src/mswin/extra/Makefile.am +++ b/src/mswin/extra/Makefile.am @@ -1,5 +1,5 @@ EXTRA_DIST = d2uenv.c mos2nrn.cpp rundemo.cpp \ - dllhead.cpp splitnrn.c \ + dllhead.cpp splitnrn.cpp \ bbstest.cpp hel2mos.cpp ms1.cpp winmain.c \ - neuron.cpp d2upath.c nrnbinstr.cpp + neuron.cpp d2upath.cpp nrnbinstr.cpp diff --git a/src/mswin/extra/d2upath.cpp b/src/mswin/extra/d2upath.cpp index a9c1b5421d..dff9d1c731 100644 --- a/src/mswin/extra/d2upath.cpp +++ b/src/mswin/extra/d2upath.cpp @@ -19,7 +19,7 @@ char* hoc_dos2cygdrivepath(const char* d, int cygdrive) { #if 0 u = new char[strlen(d) + 12]; #else - u = malloc(strlen(d) + 12); + u = static_cast(malloc(strlen(d) + 12)); assert(u); #endif i = j = 0; diff --git a/src/mswin/extra/mos2nrn.cpp b/src/mswin/extra/mos2nrn.cpp index 1b114abe8d..6f34452b44 100755 --- a/src/mswin/extra/mos2nrn.cpp +++ b/src/mswin/extra/mos2nrn.cpp @@ -5,7 +5,7 @@ #include #include -#include "d2upath.c" +#include "d2upath.cpp" char* nrnhome; char* nh; diff --git a/src/mswin/extra/neuron.cpp b/src/mswin/extra/neuron.cpp index 4512cdb85e..489b3d25d2 100755 --- a/src/mswin/extra/neuron.cpp +++ b/src/mswin/extra/neuron.cpp @@ -9,7 +9,7 @@ #include #include -#include "d2upath.c" +#include "d2upath.cpp" char* nrnhome; char* nh; diff --git a/src/nrniv/nrncore_write.cpp b/src/nrniv/nrncore_write.cpp index e01b576ddf..95a50b8778 100644 --- a/src/nrniv/nrncore_write.cpp +++ b/src/nrniv/nrncore_write.cpp @@ -105,9 +105,23 @@ correctness has not been validated for cells without gids. #include "nrncore_write/callbacks/nrncore_callbacks.h" #include + +#ifdef MINGW +#define RTLD_NOW 0 +#define RTLD_GLOBAL 0 +#define RTLD_NOLOAD 0 +extern "C" { +extern void* dlopen_noerr(const char* name, int mode); +#define dlopen dlopen_noerr +extern void* dlsym(void* handle, const char* name); +extern int dlclose(void* handle); +extern char* dlerror(); +} +#else #if defined(HAVE_DLFCN_H) #include #endif +#endif extern NetCvode* net_cvode_instance; diff --git a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp index 248c4cd7d8..aeb68bb7d3 100644 --- a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp +++ b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp @@ -11,9 +11,22 @@ #include "netcvode.h" // for nrnbbcore_vecplay_write #include "vrecitem.h" // for nrnbbcore_vecplay_write +#ifdef MINGW +#define RTLD_NOW 0 +#define RTLD_GLOBAL 0 +#define RTLD_NOLOAD 0 +extern "C" { +extern void* dlopen_noerr(const char* name, int mode); +#define dlopen dlopen_noerr +extern void* dlsym(void* handle, const char* name); +extern int dlclose(void* handle); +extern char* dlerror(); +} +#else #if defined(HAVE_DLFCN_H) #include #endif +#endif extern bbcore_write_t* nrn_bbcore_write_; extern short* nrn_is_artificial_; diff --git a/src/nrniv/nrncore_write/utils/nrncore_utils.cpp b/src/nrniv/nrncore_write/utils/nrncore_utils.cpp index 7df272e69d..47f68c989e 100644 --- a/src/nrniv/nrncore_write/utils/nrncore_utils.cpp +++ b/src/nrniv/nrncore_write/utils/nrncore_utils.cpp @@ -14,9 +14,24 @@ #include #include + +#ifdef MINGW +#define RTLD_NOW 0 +#define RTLD_GLOBAL 0 +#define RTLD_NOLOAD 0 +#define RTLD_NODELETE 0 +extern "C" { +extern void* dlopen_noerr(const char* name, int mode); +#define dlopen dlopen_noerr +extern void* dlsym(void* handle, const char* name); +extern int dlclose(void* handle); +extern char* dlerror(); +} +#else #if defined(HAVE_DLFCN_H) #include #endif +#endif // RTLD_NODELETE is used with dlopen // if not defined it's safe to define as 0 diff --git a/src/nrniv/nrnpy.cpp b/src/nrniv/nrnpy.cpp index 1d4e7988ce..5d89b88b69 100644 --- a/src/nrniv/nrnpy.cpp +++ b/src/nrniv/nrnpy.cpp @@ -22,7 +22,7 @@ extern void (*p_nrnpython_start)(int); void nrnpython(); static void (*p_nrnpython_real)(); static void (*p_nrnpython_reg_real)(); -char* hoc_back2forward(char* s); +extern "C" char* hoc_back2forward(char* s); char* hoc_forward2back(char* s); // following is undefined or else has the value of sys.api_version @@ -39,11 +39,13 @@ char* hoc_forward2back(char* s); #define RTLD_NOW 0 #define RTLD_GLOBAL 0 #define RTLD_NOLOAD 0 +extern "C" { extern void* dlopen_noerr(const char* name, int mode); #define dlopen dlopen_noerr extern void* dlsym(void* handle, const char* name); extern int dlclose(void* handle); extern char* dlerror(); +} #else //#define _GNU_SOURCE #include diff --git a/src/nrnjava/njvm.cpp b/src/nrnjava/njvm.cpp index 25dcf4ded2..9bfb972a6c 100644 --- a/src/nrnjava/njvm.cpp +++ b/src/nrnjava/njvm.cpp @@ -69,7 +69,7 @@ extern void* (*p_java2nrn_cons)(Object*); #define _WIN32 #endif #ifdef _WIN32 -char* hoc_back2forward(char*); +extern "C" char* hoc_back2forward(char*); jint nrn_CreateJavaVM(JavaVM **pvm, void **penv, void *args); #endif #if MAC diff --git a/src/nrnmpi/nrnmpi_dynam.cpp b/src/nrnmpi/nrnmpi_dynam.cpp index 8d4345ae0a..23621bad83 100644 --- a/src/nrnmpi/nrnmpi_dynam.cpp +++ b/src/nrnmpi/nrnmpi_dynam.cpp @@ -12,11 +12,13 @@ #define RTLD_NOW 0 #define RTLD_GLOBAL 0 #define RTLD_NOLOAD 0 +extern "C" { extern void* dlopen_noerr(const char* name, int mode); #define dlopen dlopen_noerr extern void* dlsym(void* handle, const char* name); extern int dlclose(void* handle); extern char* dlerror(); +} #else #include #endif diff --git a/src/nrnoc/init.cpp b/src/nrnoc/init.cpp index 3b4f0094e9..0f95517a87 100644 --- a/src/nrnoc/init.cpp +++ b/src/nrnoc/init.cpp @@ -25,14 +25,16 @@ static char banner[] = See http://neuron.yale.edu/neuron/credits\n"; #ifdef WIN32 -#if defined(HAVE_DLFCN_H) && !defined(__MINGW32__) +#if defined(HAVE_DLFCN_H) && !defined(MINGW) #include #else #define RTLD_NOW 0 +extern "C" { extern void* dlopen(const char* name, int mode); extern void* dlsym(void* handle, char* name); extern int dlclose(void* handle); extern char* dlerror(); +} #endif /*#include "../mswin/windll/dll.h"*/ /*static struct DLL* dll;*/ diff --git a/src/nrnoc/osxdlfcn.cpp b/src/nrnoc/osxdlfcn.cpp index 0ebcf9172d..56c0a7ec6a 100755 --- a/src/nrnoc/osxdlfcn.cpp +++ b/src/nrnoc/osxdlfcn.cpp @@ -82,7 +82,7 @@ static const char *error(int setget, const char *str, ...) { } /* dlopen */ -void *dlopen(const char *path, int mode) { +extern "C" void *dlopen(const char *path, int mode) { void *module = 0; NSObjectFileImage ofi = 0; NSObjectFileImageReturnCode ofirc; @@ -171,11 +171,11 @@ void *dlsymIntern(void *handle, const char *symbol) { return NSAddressOfSymbol(nssym); } -const char *dlerror(void) { +extern "C" const char *dlerror(void) { return error(1, (char *) NULL); } -int dlclose(void *handle) { +extern "C" int dlclose(void *handle) { if ((((struct mach_header *) handle)->magic == MH_MAGIC) || (((struct mach_header *) handle)->magic == MH_CIGAM)) { error(-1, "Can't remove dynamic libraries on darwin"); @@ -190,7 +190,7 @@ int dlclose(void *handle) { /* dlsym, prepend the underscore and call dlsymIntern */ -void *dlsym(void *handle, const char *symbol) { +extern "C" void *dlsym(void *handle, const char *symbol) { static char undersym[257]; /* Saves calls to malloc(3) */ int sym_len = strlen(symbol); void *value = NULL; diff --git a/src/nrnpython/inithoc.cpp b/src/nrnpython/inithoc.cpp index f87a3ae102..fd4e8ed5ed 100644 --- a/src/nrnpython/inithoc.cpp +++ b/src/nrnpython/inithoc.cpp @@ -94,9 +94,9 @@ static char* env[] = {0}; // It is conceivable that this strategy will work for linux and mac as well, // but for now setup.py names them differently anyway. #if PY_MAJOR_VERSION >= 3 -PyObject* HOCMOD(PyInit_hoc, NRNPYTHON_DYNAMICLOAD)() { +extern "C" PyObject* HOCMOD(PyInit_hoc, NRNPYTHON_DYNAMICLOAD)() { #else //!PY_MAJOR_VERSION >= 3 -void HOCMOD(inithoc, NRNPYTHON_DYNAMICLOAD)() { +extern "C" void HOCMOD(inithoc, NRNPYTHON_DYNAMICLOAD)() { #endif //!PY_MAJOR_VERSION >= 3 #else // ! defined __MINGW32__ diff --git a/src/nrnpython/nrnpython.cpp b/src/nrnpython/nrnpython.cpp index aaccd6604f..42c0ee4cf4 100644 --- a/src/nrnpython/nrnpython.cpp +++ b/src/nrnpython/nrnpython.cpp @@ -105,7 +105,7 @@ int nrnpy_pyrun(const char* fname) { the C runtime that this DLL uses. Using PyFile_AsFile is a work-around... */ - PyObject* pfo = PyFile_FromString(fname, (char*)"r"); + PyObject* pfo = PyFile_FromString((char*)fname, (char*)"r"); if (pfo == NULL) { PyErr_Print(); PyErr_Clear(); diff --git a/src/nrnpython/rxdmath.cpp b/src/nrnpython/rxdmath.cpp index eeaf05f28a..c7d5cbe1a9 100644 --- a/src/nrnpython/rxdmath.cpp +++ b/src/nrnpython/rxdmath.cpp @@ -1,4 +1,7 @@ #include +#ifndef M_PI +#define M_PI (3.14159265358979323846) +#endif /*Some functions supported by numpy that aren't included in math.h * names and arguments match the wrappers used in rxdmath.py diff --git a/src/oc/code2.cpp b/src/oc/code2.cpp index 999b7ca7a7..0b8b171dca 100755 --- a/src/oc/code2.cpp +++ b/src/oc/code2.cpp @@ -187,11 +187,11 @@ hoc_execerror("Cannot find the symbol associated with the pointer when called fr hoc_pushstr(units); } +extern "C" char* hoc_back2forward(char*); char* neuronhome_forward(void) { extern char* neuron_home; #if defined(WIN32) static char* buf; - extern char* hoc_back2forward(); extern void hoc_forward2back(); if (!buf) { buf = static_cast(emalloc(strlen(neuron_home)+1)); @@ -205,12 +205,12 @@ char* neuronhome_forward(void) { } char *neuron_home_dos; +extern void setneuronhome(const char*); void hoc_neuronhome(void) { extern char* neuron_home; #if defined(WIN32)||defined(CYGWIN) if (ifarg(1) && (int)chkarg(1, 0., 1.) == 1) { if (!neuron_home_dos) { - extern void setneuronhome(const char*); setneuronhome(NULL); } hoc_ret(); diff --git a/src/oc/cygwinprt.cpp b/src/oc/cygwinprt.cpp index 719869e5fd..0518275bfc 100755 --- a/src/oc/cygwinprt.cpp +++ b/src/oc/cygwinprt.cpp @@ -19,7 +19,7 @@ my_off64_t lseek64(int fd, my_off64_t offset, int whence) { /* mingw does not have dlfcn.h */ #if !defined(HAVE_DLFCN_H) || defined(__MINGW32__) - +extern "C" { void* dlopen(const char *name, int mode) { void *ret; /* handle for the named library */ @@ -48,6 +48,7 @@ static char* dler_=""; char* dlerror() { return dler_; } +} #endif /* HAVE_DLFCN_H */ #endif diff --git a/src/oc/fileio.cpp b/src/oc/fileio.cpp index 186f03769b..c582fed821 100755 --- a/src/oc/fileio.cpp +++ b/src/oc/fileio.cpp @@ -817,7 +817,7 @@ static int hoc_Load_file(int always, const char* name) { return b; } - +extern "C" char* hoc_back2forward(char*); void hoc_getcwd(void) { int len; static char* buf; @@ -828,7 +828,7 @@ void hoc_getcwd(void) { hoc_execerror("getcwd failed. Perhaps the path length is > hoc_load_file_size_", (char*)0); } #if defined(WIN32) -{extern char* hoc_back2forward(); +{ strcpy(buf, hoc_back2forward(buf)); } #endif diff --git a/src/oc/hoc.cpp b/src/oc/hoc.cpp index a5c5935736..a7ef0031a8 100755 --- a/src/oc/hoc.cpp +++ b/src/oc/hoc.cpp @@ -1043,9 +1043,6 @@ int hoc_main1(int argc, const char** argv, const char** envp) /* hoc6 */ hoc_run1(); return 0; } -#if defined(WIN32) && HAVE_IV -extern void ivcleanup(); -#endif #if carbon #include @@ -1087,7 +1084,7 @@ static pthread_mutex_t inputMutex_; static pthread_cond_t inputCond_; static int inputReadyFlag_; static int inputReadyVal_; -extern int getch(); +extern "C" int getch(); void* inputReadyThread(void* input) { int i, j; @@ -1130,7 +1127,6 @@ void hoc_final_exit(void) { by default they are then closed when the master process ends */ NOT_PARALLEL_SUB(hoc_close_plot();) #if defined(WIN32) && HAVE_IV - ivcleanup(); #ifndef CYGWIN if (winio_exists()) { winio_closeall(); diff --git a/src/oc/macprt.cpp b/src/oc/macprt.cpp index f8996ed60e..b7d152d656 100755 --- a/src/oc/macprt.cpp +++ b/src/oc/macprt.cpp @@ -31,7 +31,7 @@ int oc_print_from_dll(char* buf) { /* interchange \n and \r !*/ } /* jijun 4/22/97, 4/23/97 */ -void setneuronhome(const char* p) { +extern void setneuronhome(const char* p) { CInfoPBRec myPB; short vRefNum; long dirID; diff --git a/src/oc/mswinprt.cpp b/src/oc/mswinprt.cpp index 59f3215612..fb9ad71ad3 100755 --- a/src/oc/mswinprt.cpp +++ b/src/oc/mswinprt.cpp @@ -36,7 +36,7 @@ extern int bad_install_ok; int bad_install_ok; #endif // HAVE_IV extern FILE* hoc_redir_stdout; -void setneuronhome(p) char* p; { +void setneuronhome(const char* p) { // if the program lives in .../bin/neuron.exe // and .../lib exists then use ... as the // NEURONHOME @@ -109,7 +109,7 @@ void setneuronhome(p) char* p; { void HandleOutput(char* s) { printf("%s", s); } -static long exception_filter(p) LPEXCEPTION_POINTERS p; { +static long exception_filter(LPEXCEPTION_POINTERS p) { // hoc_execerror("unhandled exception", ""); // return EXCEPTION_CONTINUE_EXECUTION; static int n = 0; @@ -137,7 +137,7 @@ BOOL hoc_copyfile(const char* src, const char* dest) { static FILE* dll_stdio_[] = {(FILE*)0x0, (FILE*)0x20, (FILE*)0x40}; -void nrn_mswindll_stdio(i,o,e) FILE* i, *o, *e; { +void nrn_mswindll_stdio(FILE* i, FILE* o, FILE* e) { if (o != dll_stdio_[1]) { printf("nrn_mswindll_stdio stdio in dll = %p but expected %p\n", o, dll_stdio_[1]); } @@ -190,7 +190,7 @@ void hoc_forward2back(char* s) { } } -char* hoc_back2forward(char* s) { +extern "C" char* hoc_back2forward(char* s) { char* cp = s; while(*cp) { if (*cp == '\\') { diff --git a/src/readline/readline.c b/src/readline/readline.c index 20da564a6c..959696bc0f 100755 --- a/src/readline/readline.c +++ b/src/readline/readline.c @@ -1000,7 +1000,7 @@ and term=xterm we set it to neuronhome/lib and get neuronhome/lib/x/xterm */ if (!getenv("TERMINFO") && strcmp(term, "xterm") == 0) { extern char* neuron_home; - extern char* hoc_back2forward(); + extern char* hoc_back2forward(char*); sprintf(term_buffer, "TERMINFO=%s/lib", hoc_back2forward(neuron_home)); putenv(term_buffer); } From a5d30c135d6f115acd0fee8fa551d82b476569fe Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Thu, 22 Oct 2020 19:12:18 +0200 Subject: [PATCH 04/17] fix after dynamic units rebase --- cmake/MacroHelper.cmake | 1 - src/modlunit/units.cpp | 18 +- src/nrnoc/eion.c | 619 -------- src/nrnoc/eion.cpp | 14 +- src/nrnoc/hocusr.h | 3 +- src/nrnpython/Makefile.am | 2 +- src/nrnpython/nrnpy_hoc.cpp | 4 +- src/oc/code.c | 2691 ----------------------------------- src/oc/code.cpp | 224 +-- src/oc/hoc_init.c | 420 ------ src/oc/hoc_init.cpp | 45 +- src/oc/hocedit.cpp | 2 +- src/oc/oc_ansi.h | 4 +- 13 files changed, 180 insertions(+), 3867 deletions(-) delete mode 100644 src/nrnoc/eion.c delete mode 100755 src/oc/code.c delete mode 100755 src/oc/hoc_init.c diff --git a/cmake/MacroHelper.cmake b/cmake/MacroHelper.cmake index 5e144d4bc4..6a692a6bde 100644 --- a/cmake/MacroHelper.cmake +++ b/cmake/MacroHelper.cmake @@ -254,7 +254,6 @@ macro(nocmodl_mod_to_c modfile_basename) COMMAND ${CMAKE_COMMAND} -E env "MODLUNIT=${PROJECT_BINARY_DIR}/share/nrn/lib/nrnunits.lib" ${PROJECT_BINARY_DIR}/bin/nocmodl ${modfile_basename}.mod COMMAND sed "'s/_reg()/_reg_()/'" ${modfile_basename}.c > ${modfile_basename}.c.tmp -# COMMAND sed "'s/__cplusplus/__cminusminus/'" ${modfile_basename}.c.tmp > ${modfile_basename}.c.tmp2 COMMAND mv ${modfile_basename}.c.tmp ${modfile_basename}.c DEPENDS nocmodl ${modfile_basename}.mod WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/src/nrniv) diff --git a/src/modlunit/units.cpp b/src/modlunit/units.cpp index 4558b5680a..597d681ff3 100755 --- a/src/modlunit/units.cpp +++ b/src/modlunit/units.cpp @@ -60,21 +60,21 @@ extern void diag(char*, char*); /* if MODLUNIT environment variable not set then look in the following places*/ #if MAC -static char *dfile = ":lib:nrnunits.lib"SUFFIX; +static char *dfile = ":lib:nrnunits.lib" SUFFIX; #else #if defined(NEURON_DATA_DIR) -static char *dfile = NEURON_DATA_DIR"/lib/nrnunits.lib"SUFFIX; +static char *dfile = NEURON_DATA_DIR "/lib/nrnunits.lib" SUFFIX; #else static char *dfile = "/usr/lib/units"; #endif #endif #if defined(__TURBOC__) || defined(__GO32__) -static char *dfilealt = "/nrn/lib/nrnunits.lib"SUFFIX; +static char *dfilealt = "/nrn/lib/nrnunits.lib" SUFFIX; #else #if MAC -static char *dfilealt = "::lib:nrnunits.lib"SUFFIX; +static char *dfilealt = "::lib:nrnunits.lib" SUFFIX; #else -static char *dfilealt = "../../share/lib/nrnunits.lib"SUFFIX; +static char *dfilealt = "../../share/lib/nrnunits.lib" SUFFIX; #endif #endif static char *unames[NDIM]; @@ -314,7 +314,7 @@ unit_str() { return s; } -void install_units(char* s1, char* s2) /* define s1 as s2 */ +static void install_units_help(char* s1, char* s2) /* define s1 as s2 */ { struct table *tp; int i; @@ -637,9 +637,9 @@ diag("Bad MODLUNIT environment variable. Cant open:", buf); if (s) { if (strncmp(s, "/cygdrive/", 10) == 0) { /* /cygdrive/x/... to c:/... */ - sprintf(buf, "%c:%s/lib/nrnunits.lib"SUFFIX, s[10], s+11); + sprintf(buf, "%c:%s/lib/nrnunits.lib" SUFFIX, s[10], s+11); }else{ - sprintf(buf, "%s/lib/nrnunits.lib"SUFFIX, s); + sprintf(buf, "%s/lib/nrnunits.lib" SUFFIX, s); } inpfile = fopen(buf, "r"); free(s); @@ -650,7 +650,7 @@ diag("Bad MODLUNIT environment variable. Cant open:", buf); if ((inpfile = fopen(dfilealt, "r")) == (FILE *)0) { s = neuronhome(); if (s) { - sprintf(buf, "%s/lib/nrnunits.lib"SUFFIX, s); + sprintf(buf, "%s/lib/nrnunits.lib" SUFFIX, s); inpfile = fopen(buf, "r"); } } diff --git a/src/nrnoc/eion.c b/src/nrnoc/eion.c deleted file mode 100644 index a6b00246ab..0000000000 --- a/src/nrnoc/eion.c +++ /dev/null @@ -1,619 +0,0 @@ -#include <../../nrnconf.h> -/* /local/src/master/nrn/src/nrnoc/eion.c,v 1.10 1998/02/26 16:42:50 hines Exp */ - -#include -#include "section.h" -#include "neuron.h" -#include "membfunc.h" -#include "parse.h" -#include "membdef.h" -#include "nrniv_mf.h" -#include "nrnunits_modern.h" -#undef hoc_retpushx - -extern double chkarg(); -extern Section* nrn_noerr_access(); -extern void hoc_register_prop_size(int, int, int); - -#define nparm 5 -static const char *mechanism[] = { /*just a template*/ - "0", - "na_ion", - "ena", "nao", "nai", 0, - "ina", "dina_dv_", 0, - 0 -}; -static DoubScal scdoub[] = { /* just a template*/ - "ci0_na_ion", 0, - "co0_na_ion", 0, - 0, 0 -}; - -static void ion_alloc(Prop*); -static void ion_cur(NrnThread*, Memb_list*, int); -static void ion_init(NrnThread*, Memb_list*, int); -double nrn_nernst(double, double, double), nrn_ghk(double, double, double, double); -static int na_ion, k_ion, ca_ion; /* will get type for these special ions */ - -int -nrn_is_ion(type) - int type; -{ - return (memb_func[type].alloc == ion_alloc); -} - -static int ion_global_map_size; -static double** ion_global_map; -#define global_conci(type) ion_global_map[type][0] -#define global_conco(type) ion_global_map[type][1] -#define global_charge(type) ion_global_map[type][2] - -double nrn_ion_charge(Symbol* sym) { - return global_charge(sym->subtype); -} - -void ion_register(void) { - /* hoc level registration of ion name. Return -1 if name already - in use and not an ion; and the mechanism subtype otherwise. - */ - char* name; - char* buf; - Symbol *s; - Symlist* sav; - int fail; - fail = 0; - sav = hoc_symlist; - hoc_symlist = hoc_top_level_symlist; - name = gargstr(1); - buf = emalloc(strlen(name) + 10); - sprintf(buf, "%s_ion", name); - s = hoc_lookup(buf); - if (s && s->type == MECHANISM && memb_func[s->subtype].alloc == ion_alloc) { - hoc_symlist = sav; - free(buf); - hoc_retpushx((double)s->subtype); return; - } - if (s) { fail = 1; } - sprintf(buf, "e%s", name); if (hoc_lookup(buf)) { fail = 1; } - sprintf(buf, "%si", name); if (hoc_lookup(buf)) { fail = 1; } - sprintf(buf, "%so", name); if (hoc_lookup(buf)) { fail = 1; } - sprintf(buf, "i%s", name); if (hoc_lookup(buf)) { fail = 1; } - sprintf(buf, "di%s_dv_", name); if (hoc_lookup(buf)) { fail = 1; } - if (fail) { - hoc_symlist = sav; - free(buf); - hoc_retpushx(-1.); return; - } - hoc_symlist = hoc_built_in_symlist; - ion_reg(name, *getarg(2)); - hoc_symlist = sav; - sprintf(buf, "%s_ion", name); - s = hoc_lookup(buf); - hoc_retpushx((double)s->subtype); - free(buf); -} - -void ion_charge(void) { - Symbol* s; - s = hoc_lookup(gargstr(1)); - if (!s || s->type != MECHANISM || memb_func[s->subtype].alloc != ion_alloc) { - hoc_execerror(gargstr(1), "is not an ion mechanism"); - } - hoc_retpushx(global_charge(s->subtype)); -} - -void ion_reg(const char* name, double valence) -{ - int i, mechtype; - Symbol *s; - char* buf[7]; - double val; -#define VAL_SENTINAL -10000. - - {int n = 2*strlen(name) + 10; /*name used twice in initialization name */ - for (i=0; i < 7; ++i) { - buf[i] = emalloc(n); - } - } - Sprintf(buf[0], "%s_ion", name); - Sprintf(buf[1], "e%s", name); - Sprintf(buf[2], "%si", name); - Sprintf(buf[3], "%so", name); - Sprintf(buf[5], "i%s", name); - Sprintf(buf[6], "di%s_dv_", name); - for (i=0; i<7; i++) { - mechanism[i+1] = buf[i]; - } - mechanism[5] = (char *)0; /* buf[4] not used above */ - s = hoc_lookup(buf[0]); - if (!s || s->type != MECHANISM - || memb_func[s->subtype].alloc != ion_alloc) { - register_mech(mechanism, ion_alloc, ion_cur, (void*)0, (void*)0, ion_init, -1, 1); - hoc_symbol_limits(hoc_lookup(buf[2]), 1e-12, 1e9); - hoc_symbol_limits(hoc_lookup(buf[3]), 1e-12, 1e9); - hoc_symbol_units(hoc_lookup(buf[1]), "mV"); - hoc_symbol_units(hoc_lookup(buf[2]), "mM"); - hoc_symbol_units(hoc_lookup(buf[3]), "mM"); - hoc_symbol_units(hoc_lookup(buf[5]), "mA/cm2"); - hoc_symbol_units(hoc_lookup(buf[6]), "S/cm2"); - s = hoc_lookup(buf[0]); - mechtype = nrn_get_mechtype(mechanism[1]); - hoc_register_prop_size(mechtype, nparm, 1 ); - hoc_register_dparam_semantics(mechtype, 0, "iontype"); - nrn_writes_conc(mechtype, 1); - if (ion_global_map_size <= s->subtype) { - ion_global_map_size = s->subtype + 1; - ion_global_map = (double**)erealloc(ion_global_map, - sizeof(double*)*ion_global_map_size); - } - ion_global_map[s->subtype] = (double*)emalloc(3*sizeof(double)); - Sprintf(buf[0], "%si0_%s", name, s->name); - scdoub[0].name = buf[0]; - scdoub[0].pdoub = ion_global_map[s->subtype]; - Sprintf(buf[1], "%so0_%s", name, s->name); - scdoub[1].name = buf[1]; - scdoub[1].pdoub = ion_global_map[s->subtype] + 1; - hoc_register_var(scdoub, (DoubVec*)0, (VoidFunc*)0); - hoc_symbol_units(hoc_lookup(scdoub[0].name), "mM"); - hoc_symbol_units(hoc_lookup(scdoub[1].name), "mM"); - if (strcmp("na", name) == 0) { - na_ion = s->subtype; - global_conci(s->subtype) = DEF_nai; - global_conco(s->subtype) = DEF_nao; - global_charge(s->subtype) = 1.; - }else if (strcmp("k", name) == 0) { - k_ion = s->subtype; - global_conci(s->subtype) = DEF_ki; - global_conco(s->subtype) = DEF_ko; - global_charge(s->subtype) = 1.; - }else if (strcmp("ca", name) == 0) { - ca_ion = s->subtype; - global_conci(s->subtype) = DEF_cai; - global_conco(s->subtype) = DEF_cao; - global_charge(s->subtype) = 2.; - }else{ - global_conci(s->subtype) = DEF_ioni; - global_conco(s->subtype) = DEF_iono; - global_charge(s->subtype) = VAL_SENTINAL; - } - for (i=0; i < 3; ++i) { /* used to be nrnocCONST */ - s->u.ppsym[i]->subtype = _AMBIGUOUS; - } - } - val = global_charge(s->subtype); - if (valence != VAL_SENTINAL && val != VAL_SENTINAL && valence != val) { - fprintf(stderr, "%s ion charge defined differently in\n\ -two USEION statements (%g and %g)\n", - s->name, valence, global_charge(s->subtype)); - nrn_exit(1); - }else if (valence == VAL_SENTINAL && val == VAL_SENTINAL) { - /* Not defined now but could be defined by - a subsequent ion_reg from another model. - The list of ion mechanisms will be checked - after all mod files have been dealt with to verify - that they all have a defined valence. - */ -#if 0 -#endif - }else if (valence != VAL_SENTINAL) { - global_charge(s->subtype) = valence; - } - for (i=0; i < 7; ++i) { - free(buf[i]); - } -} - -void nrn_verify_ion_charge_defined() { - int i; - for (i = 3; i < n_memb_func; ++i ) if (nrn_is_ion(i)) { - if (global_charge(i) == VAL_SENTINAL) { - Symbol* s = memb_func[i].sym; - Fprintf(stderr, "%s USEION CHARGE (or VALENCE) must be defined in\n\ -at least one model using this ion\n", s->name); - nrn_exit(1); - } - } -} - -#define FARADAY _faraday_[_nrnunit_use_legacy_] -static double _faraday_[2] = {_faraday_codata2018, 96485.309}; -#define gasconstant _gasconstant_[_nrnunit_use_legacy_] -static double _gasconstant_[2] = {_gasconstant_codata2018, 8.3134}; - -#define ktf (1000.*gasconstant*(celsius + 273.15)/FARADAY) -double nrn_nernst(ci, co, z) double z, ci, co; { -/*printf("nrn_nernst %g %g %g\n", ci, co, z);*/ - if (z == 0) { - return 0.; - } - if (ci <= 0.) { - return 1e6; - }else if (co <= 0.) { - return -1e6; - }else{ - return ktf/z*log(co/ci); - } -} - -void nrn_wrote_conc(sym, pe, it) Symbol* sym; double* pe; int it; { - if (it & 040) { - pe[0] = nrn_nernst(pe[1], pe[2], nrn_ion_charge(sym)); - } -} - -void nernst(void) { - double val=0.0; - - if (hoc_is_str_arg(1)) { - Symbol* s = hoc_lookup(gargstr(1)); - if (s && ion_global_map[s->u.rng.type]) { - Section* sec = chk_access(); - double* nrn_rangepointer(); - Symbol* ion = memb_func[s->u.rng.type].sym; - double z = global_charge(s->u.rng.type); - double *ci, *co, *e, x; - if (ifarg(2)) { - x = chkarg(2, 0., 1.); - }else{ - x = .5; - } - ci = nrn_rangepointer(sec, ion->u.ppsym[1] , x); - co = nrn_rangepointer(sec, ion->u.ppsym[2], x); - e = nrn_rangepointer(sec, ion->u.ppsym[0], x); - switch (s->u.rng.index) { - case 0: - val = nrn_nernst(*ci, *co, z); - hoc_retpushx(val); - return; - case 1: - val = *co*exp(-z/ktf* *e); - hoc_retpushx(val); - return; - case 2: - val = *ci*exp(z/ktf* *e); - hoc_retpushx(val); - return; - } - } - hoc_execerror(gargstr(1), " not a reversal potential or concentration"); - }else{ - val = nrn_nernst(*getarg(1), *getarg(2), *getarg(3)); -/*printf("nernst=%g\n", val);*/ - } - hoc_retpushx(val); - return; -} - -static double efun(x) double x; { - if (fabs(x) < 1e-4) { - return 1. - x/2.; - }else{ - return x/(exp(x) - 1); - } -} - -double nrn_ghk(v, ci, co, z) double v, ci, co, z; { - double eco, eci, temp; - temp = z*v/ktf; - eco = co*efun(temp); - eci = ci*efun(-temp); - return (.001)*z*FARADAY*(eci - eco); -} -void ghk(void) { - double val = nrn_ghk(*getarg(1), *getarg(2), *getarg(3), *getarg(4)); - hoc_retpushx(val); -} -#if VECTORIZE -#define erev pd[i][0] /* From Eion */ -#define conci pd[i][1] -#define conco pd[i][2] -#define cur pd[i][3] -#define dcurdv pd[i][4] - -/* - handle erev, conci, conc0 "in the right way" according to ion_style - default. See nrn/lib/help/nrnoc.help. -ion_style("name_ion", [c_style, e_style, einit, eadvance, cinit]) - - ica is assigned - eca is parameter but if conc exists then eca is assigned - if conc is nrnocCONST then eca calculated on finitialize - if conc is STATE then eca calculated on fadvance and conc finitialize - with global nai0, nao0 - - nernst(ci, co, charge) and ghk(v, ci, co, charge) available to hoc - and models. -*/ - -#define iontype ppd[i][0].i /* how _AMBIGUOUS is to be handled */ -/*the bitmap is -03 concentration unused, nrnocCONST, DEP, STATE -04 initialize concentrations -030 reversal potential unused, nrnocCONST, DEP, STATE -040 initialize reversal potential -0100 calc reversal during fadvance -0200 ci being written by a model -0400 co being written by a model -*/ - -#define charge global_charge(type) -#define conci0 global_conci(type) -#define conco0 global_conco(type) - -double nrn_nernst_coef(type) int type; { - /* for computing jacobian element dconc'/dconc */ - return ktf/charge; -} - -/* -It is generally an error for two models to WRITE the same concentration -*/ -void nrn_check_conc_write(p_ok, pion, i) Prop* p_ok, *pion; int i; { - static long *chk_conc_, *ion_bit_, size_; - Prop* p; - int flag, j, k; - if (i == 1) { - flag = 0200; - }else{ - flag = 0400; - } - /* an embarassing hack */ - /* up to 32 possible ions */ - /* continuously compute a bitmap that allows determination - of which models WRITE which ion concentrations */ - if (n_memb_func > size_){ - if (!chk_conc_) { - chk_conc_ = (long*)ecalloc(2*n_memb_func, sizeof(long)); - ion_bit_ = (long*)ecalloc(n_memb_func, sizeof(long)); - }else{ - chk_conc_ = (long*)erealloc(chk_conc_, 2*n_memb_func*sizeof(long)); - ion_bit_ = (long*)erealloc(ion_bit_, n_memb_func*sizeof(long)); - for (j = size_; j < n_memb_func; ++j) { - chk_conc_[2*j] = 0; - chk_conc_[2*j+1] = 0; - ion_bit_[j] = 0; - } - } - size_ = n_memb_func; - } - for (k=0, j=0; j < n_memb_func; ++j) { - if (nrn_is_ion(j)) { - ion_bit_[j] = (1<type + i] |= ion_bit_[pion->type]; - if (pion->dparam[0].i & flag) { - /* now comes the hard part. Is the possibility in fact actual.*/ - for (p = pion->next; p; p = p->next) { - if (p == p_ok) { - continue; - } - if (chk_conc_[2*p->type + i] & ion_bit_[pion->type]) { - char buf[300]; -sprintf(buf, "%.*s%c is being written at the same location by %s and %s", - (int)strlen(memb_func[pion->type].sym->name)-4, - memb_func[pion->type].sym->name, - ((i == 1)? 'i' : 'o'), - memb_func[p_ok->type].sym->name, - memb_func[p->type].sym->name); - hoc_warning(buf, (char*)0); - } - } - } - pion->dparam[0].i |= flag; -} - -void ion_style(void) { - Symbol* s; - int istyle, i, oldstyle; - Section* sec; - Prop* p, *nrn_mechanism(); - - s = hoc_lookup(gargstr(1)); - if (!s || s->type != MECHANISM || !nrn_is_ion(s->subtype)) { - hoc_execerror(gargstr(1), " is not an ion"); - } - - sec = chk_access(); - p = nrn_mechanism(s->subtype, sec->pnode[0]); - oldstyle = -1; - if (p) { - oldstyle = p->dparam[0].i; - } - - if (ifarg(2)) { - istyle = (int)chkarg(2, 0., 3.); /* c_style */ - istyle += 010*(int)chkarg(3, 0., 3.); /* e_style */ - istyle += 040*(int)chkarg(4, 0., 1.); /* einit */ - istyle += 0100*(int)chkarg(5, 0., 1.); /* eadvance */ - istyle += 04*(int)chkarg(6, 0., 1.); /* cinit*/ - -#if 0 /* global effect */ - { - int count; - Datum** ppd; - v_setup_vectors(); - count = memb_list[s->subtype].nodecount; - ppd = memb_list[s->subtype].pdata; - for (i=0; i < count; ++i) { - iontype = (iontype&(0200+0400)) + istyle; - } - } -#else /* currently accessed section */ - { - for (i=0; i < sec->nnode; ++i) { - p = nrn_mechanism(s->subtype, sec->pnode[i]); - if (p) { - p->dparam[0].i &= (0200+0400); - p->dparam[0].i += istyle; - } - } - } -#endif - } - hoc_retpushx((double)oldstyle); -} - -int nrn_vartype(sym) Symbol* sym; { - int i; - i = sym->subtype; - if (i == _AMBIGUOUS) { - Section* sec; - Prop* p, *nrn_mechanism(); - sec = nrn_noerr_access(); - if (!sec) { - return nrnocCONST; - } - p = nrn_mechanism(sym->u.rng.type, sec->pnode[0]); - if (p) { - int it = p->dparam[0].i; - if (sym->u.rng.index == 0) { /* erev */ - i = (it & 030)>>3; /* unused, nrnocCONST, DEP, or STATE */ - }else{ /* concentration */ - i = (it & 03); - } - } - } - return i; -} - -/* the ion mechanism it flag defines how _AMBIGUOUS is to be interpreted */ -void nrn_promote(p, conc, rev) - Prop* p; - int conc, rev; -{ - int oldconc, oldrev; - int* it = &p->dparam[0].i; - oldconc = (*it & 03); - oldrev = (*it & 030)>>3; - /* precedence */ - if (oldconc < conc) { - oldconc = conc; - } - if (oldrev < rev) { - oldrev = rev; - } - /* promote type */ - if (oldconc > 0 && oldrev < 2) { - oldrev = 2; - } - *it &= ~0177; /* clear the bitmap */ - *it += oldconc + 010*oldrev; - if (oldconc == 3) { /* if state then cinit */ - *it += 4; - if (oldrev == 2) { /* if not state (WRITE) then eadvance */ - *it += 0100; - } - } - if (oldconc > 0 && oldrev == 2) { /*einit*/ - *it += 040; - } -} - -/* Must be called prior to any channels which update the currents */ -static void ion_cur(NrnThread* nt, Memb_list* ml, int type) { - int count = ml->nodecount; - Node** vnode = ml->nodelist; - double **pd = ml->data; - Datum **ppd = ml->pdata; - int i; -/*printf("ion_cur %s\n", memb_func[type].sym->name);*/ -#if _CRAY -#pragma _CRI ivdep -#endif - for (i=0; i < count; ++i) { - dcurdv = 0.; - cur = 0.; - if (iontype & 0100) { - erev = nrn_nernst(conci, conco, charge); - } - }; -} - -/* Must be called prior to other models which possibly also initialize - concentrations based on their own states -*/ -static void ion_init(NrnThread* nt, Memb_list* ml, int type) { - int count = ml->nodecount; - Node** vnode = ml->nodelist; - double **pd = ml->data; - Datum **ppd = ml->pdata; - int i; -/*printf("ion_init %s\n", memb_func[type].sym->name);*/ -#if _CRAY -#pragma _CRI ivdep -#endif - for (i=0; i < count; ++i) { - if (iontype & 04) { - conci = conci0; - conco = conco0; - } - } -#if _CRAY -#pragma _CRI ivdep -#endif - for (i=0; i < count; ++i) { - if (iontype & 040) { - erev = nrn_nernst(conci, conco, charge); - } - } -} - -static void ion_alloc(p) - Prop *p; -{ - double *pd[1]; - int i=0; - - pd[0] = nrn_prop_data_alloc(p->type, nparm, p); - p->param_size = nparm; - - cur = 0.; - dcurdv = 0.; - if (p->type == na_ion) { - erev = DEF_ena; - conci = DEF_nai; - conco = DEF_nao; - }else if (p->type == k_ion) { - erev = DEF_ek; - conci = DEF_ki; - conco = DEF_ko; - }else if (p->type == ca_ion) { - erev = DEF_eca; - conci = DEF_cai; - conco = DEF_cao; - }else{ - erev = DEF_eion; - conci = DEF_ioni; - conco = DEF_iono; - } - p->param = pd[0]; - - p->dparam = nrn_prop_datum_alloc(p->type, 1, p); - p->dparam->i = 0; -} - -void second_order_cur(NrnThread* nt) { - extern int secondorder; - NrnThreadMembList* tml; - Memb_list* ml; - int j, i, i2; -#define c 3 -#define dc 4 - if (secondorder == 2) { - for (tml = nt->tml; tml; tml = tml->next) if (memb_func[tml->index].alloc == ion_alloc) { - ml = tml->ml; - i2 = ml->nodecount; - for (i = 0; i < i2; ++i) { - ml->data[i][c] += ml->data[i][dc] - * ( NODERHS(ml->nodelist[i]) ) - ; - } - } - } -} - -#endif diff --git a/src/nrnoc/eion.cpp b/src/nrnoc/eion.cpp index 78ae598ad3..bffe31e6e4 100644 --- a/src/nrnoc/eion.cpp +++ b/src/nrnoc/eion.cpp @@ -8,7 +8,7 @@ #include "parse.hpp" #include "membdef.h" #include "nrniv_mf.h" - +#include "nrnunits_modern.h" #undef hoc_retpushx @@ -232,16 +232,12 @@ at least one model using this ion\n", s->name); } } -#if defined(LegacyFR) && LegacyFR == 1 -#define FARADAY 96485.309 -#define gasconstant 8.3134 -#else -#define FARADAY 96485.33289 -#define gasconstant 8.3144598 -#endif +#define FARADAY _faraday_[_nrnunit_use_legacy_] +static double _faraday_[2] = {_faraday_codata2018, 96485.309}; +#define gasconstant _gasconstant_[_nrnunit_use_legacy_] +static double _gasconstant_[2] = {_gasconstant_codata2018, 8.3134}; #define ktf (1000.*gasconstant*(celsius + 273.15)/FARADAY) - double nrn_nernst(double ci, double co, double z) { /*printf("nrn_nernst %g %g %g\n", ci, co, z);*/ if (z == 0) { diff --git a/src/nrnoc/hocusr.h b/src/nrnoc/hocusr.h index 70aaddb7db..cbb8b6f6d0 100644 --- a/src/nrnoc/hocusr.h +++ b/src/nrnoc/hocusr.h @@ -27,7 +27,7 @@ extern void nrnallsectionmenu(), nrnallpointmenu(), nrnsecmenu(); extern void nrnglobalmechmenu(), nrnmechmenu(), nrnpointmenu(); extern void this_section(), this_node(), parent_section(), parent_node(); extern void parent_connection(), section_orientation(); - +extern void nrnunit_use_legacy(); /* Functions */ static VoidFunc functions[] = { @@ -105,6 +105,7 @@ static VoidFunc functions[] = { "parent_node", parent_node, "parent_connection", parent_connection, "section_orientation", section_orientation, +"nrnunit_use_legacy", nrnunit_use_legacy, 0, 0 }; diff --git a/src/nrnpython/Makefile.am b/src/nrnpython/Makefile.am index b83d70b77f..5b05517708 100755 --- a/src/nrnpython/Makefile.am +++ b/src/nrnpython/Makefile.am @@ -7,7 +7,7 @@ DEFS = @DEFS@ @NRNPYTHON_DEFINES@ NRNPYTHON_INCLUDES = @npy_NRNPYTHON_INCLUDES@ IV_INCLUDES = @IV_INCLUDE@ $(X_CFLAGS) includes = -I. -I$(nsrc)/nrniv -I$(nsrc)/ivoc -I$(nsrc)/nrnoc -I$(nsrc)/oc -I$(nsrc)/nrnmpi -I$(nsrc)/gnu -I$(nsrc)/mesch $(NRNPYTHON_INCLUDES) $(IV_INCLUDES) -AM_CPPFLAGS = -DOOP=1 -DCABLE=1 -DUSECVODE=1 -DUSEMATRIX=1 -DUSEBBS=1 $(includes) +AM_CPPFLAGS = -DNRNUNIT=1 -DOOP=1 -DCABLE=1 -DUSECVODE=1 -DUSEMATRIX=1 -DUSEBBS=1 $(includes) AM_CXXFLAGS = @MINGW_CFLAG@ if BUILD_NRNPYTHON diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index 3ec73f1e4a..0369af33d9 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -2018,7 +2018,7 @@ static PyObject* mkref(PyObject* self, PyObject* args) { } static PyObject* cpp2refstr(char** cpp) { - // If cpp is from a hoc_temp_charptr (see src/oc/code.c) then create a + // If cpp is from a hoc_temp_charptr (see src/oc/code.cpp) then create a // HocRefStr and copy *cpp. Otherwise, assume it is from a hoc strdef // or a HocRefStr which is persistent over the life time of this returned // PyObject so that it is safe to create a HocRefPStr such that @@ -2718,7 +2718,7 @@ static PyObject* hocpickle_setstate(PyObject* self, PyObject* args) { BYTESWAP(x[i], double) } } - memcpy(vector_vec(vec), datastr, len); + memcpy((char*)vector_vec(vec), datastr, len); Py_DECREF(rawdata); Py_INCREF(Py_None); return Py_None; diff --git a/src/oc/code.c b/src/oc/code.c deleted file mode 100755 index 719636b2a0..0000000000 --- a/src/oc/code.c +++ /dev/null @@ -1,2691 +0,0 @@ -#include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/code.c,v 1.37 1999/07/03 14:20:21 hines Exp */ - -#if defined(__GO32__) -#include -#endif - -#include -#include "hoc.h" -#include "code.h" -#include "hocstr.h" -#include "parse.h" -#include "ocfunc.h" -#include "ocmisc.h" -#include "hocparse.h" -#include "equation.h" -#include -#include -#include -#include -#include "nrnfilewrap.h" -#if CABLE -#include "options.h" -#include "section.h" - -int bbs_poll_; -extern void bbs_handle(void); -#define BBSPOLL if (--bbs_poll_ == 0) { bbs_handle(); } - -int nrn_isecstack(); -#else -#define BBSPOLL /**/ -#endif - -int hoc_return_type_code = 0; /* flag for allowing integers (1) and booleans (2) to be recognized as such */ - -# define STACKCHK if (stackp >= stacklast) \ - execerror("Stack too deep.", "Increase with -NSTACK stacksize option"); - -int tstkchk_actual(int i, int j) { - int k, l; - char *s[2]; - if (i != j) { - for (k =0, l=i; k<2; k++, l=j) { - switch (l) { - case NUMBER: - s[k] = "(double)"; - break; - case STRING: - s[k] = "(char *)"; - break; - case OBJECTVAR: - s[k] = "(Object **)"; - break; - case USERINT: - s[k] = "(int)"; - break; - case SYMBOL: - s[k] = "(Symbol)"; - break; - case VAR: - s[k] = "(double *)"; - break; - case OBJECTTMP: /* would use OBJECT if it existed */ - s[k] = "(Object *)"; - break; - case STKOBJ_UNREF:/* hoc_stkobj_unref allready called */ - s[k] = "(Object * already unreffed on stack)"; - break; - default: - s[k] = "(Unknown)"; - break; - } - } - fprintf(stderr, "bad stack access: expecting %s; really %s\n", s[1], s[0]); - execerror("interpreter stack type error", (char *)0); - } - return 0; -} - -#define USEMACROS 1 - -/* warning! tstkchk(i,j) when i!=j will call execerror and error recovery - now uses stackp to recover OBJECTTMP resources. So it must be the case that - stackp - stack is an even number (since stack item, itemtype values - use a pair of stack locations). This invalidates the previous pop idiom - tstkchk((--stackp)->i, type), (--stackp)->val)) since if tstkchk calls - execerror without returning, stackp is no longer consistent since the - second decrement no longer takes place. - - Furthermore, tstkchk(i,j) should be called prior to actually popping the - stack so that the execerror will properly unref the otherwise unexpected - possible OBJECTTMP. -*/ - -#if USEMACROS -/* warning! tstkchk is a macro that uses each arg twice. So error if - the arg in the call has side effects. Eg avoid args like --stackp -*/ -#define tstkchk(i,j) (((i)!=(j))?tstkchk_actual(i,j):0) -#define pushxm(d) ((stackp++)->val = (d));((stackp++)->i = NUMBER) -#define pushsm(d) ((stackp++)->sym = (d));((stackp++)->i = SYMBOL) -#define nopopm() (stackp -= 2) /*provision at use made to deal with OBJECTTMP*/ -#define xpopm() (tstkchk(stackp[-1].i, NUMBER), nopopm(), stackp->val) -#define spopm() (tstkchk(stackp[-1].i, SYMBOL), nopopm(), stackp->sym) -#else -#define pushxm(d) pushx(d) -#define pushsm(d) pushs(d) -#define xpopm() xpop() -#define spopm() spop() -#define nopopm() nopop() -#define tstkchk(i,j) tstkchk_actual(i,j) -#endif - -#define EPS hoc_epsilon - -#define NSTACK 1000 /* default size */ -#define nstack hoc_nstack -static Datum *stack; /* the stack */ -static Datum *stackp; /* next free spot on stack */ -static Datum *stacklast; /* last stack element */ - -#define NPROG 50000 -Inst *prog; /* the machine */ -Inst *progp; /* next free spot for code generation */ -Inst *pc; /* program counter during execution */ -Inst *progbase; /* start of current subprogram */ -Inst *prog_parse_recover; /* start after parse error */ -int hoc_returning; /* 1 if return stmt seen, 2 if break, 3 if continue */ - /* 4 if stop */ -typedef struct Frame { /* proc/func call stack frame */ - Symbol *sp; /* symbol table entry */ - Inst *retpc; /* where to resume after return */ - Datum *argn; /* n-th argument on stack */ - int nargs; /* number of arguments */ - Inst *iter_stmt_begin; /* Iterator statement starts here */ - Object *iter_stmt_ob; /* context of Iterator statement */ - Object *ob; /* for stack frame debug message */ -} Frame; -#define NFRAME 512 /* default size */ -#define nframe hoc_nframe -static Frame *frame, *fp, *framelast; /* first, frame pointer, last */ - -/* temporary object references come from this pool. This allows the -stack to be aware if it is storing a temporary. We are trying to -solve problems of objrefs on the stack changing the object they point -to and also a failure of garbage collection since temporary objrefs have -not, in the past, been reffed or unreffed. -The first problem is easily solved without much efficiency loss -by having the stack store the object pointer instead of the objref pointer. - -Garbage collection is implemented by reffing any object that is placed -on the stack via hoc_push_object (and thus borrows the use of the -type OBJECTTMP) It is then the responsibility of everything that -pops an object to determine whether the object should be unreffed. -This is also done on error recovery and when the stack frame is popped. -I hate the efficiency loss but it is not as bad as it could be -since most popping occurs when the stack frame is popped and in this -case it is faster to check for OBJECTTMP than if the returned Object** -is from the pool. -*/ -#define DEBUG_GARBAGE 1 -#define TOBJ_POOL_SIZE 50 -static Object** hoc_temp_obj_pool_; -static int obj_pool_index_; -static int tobj_count; /* how many stack pushes of OBJECTTMP have been reffed*/ - -/* -Here is the old comment on the function when it was in hoc_oop.c. - -At this time we are dealing uniformly with object variables and cannot -deal cleanly with objects. Eventually it may be possible to put an -object pointer on the stack but not now. Try to avoid using "functions -which return new objects" as arguments to other functions. If this is -done then it may happen that when the stack pointer is finally used it -may point to a different object than when it was put on the stack. -Things are safe when a temp_objvar is finally removed from the stack. -Memory leakage will occur if a temp_objvar is passed as an arg but never -assigned to a full fledged object variable. ie its reference count is 0 -but unref will never be called on it. -The danger is illustrated with - proc p(obj.func_returning_object()) { // $o1 is on the stack - print $o1 // correct object - for i=0,100 { - o = obj.func_returning_different_object() - print i, $o1 //when i=50 $o1 will be different - } - } -In this case one should first assign $o1 to another object variable -and then use that object variable exclusively instead of $o1. -This also prevent leakage of the object pointed to by $o1. - -If this ever becomes a problem then it is not too difficult to -implement objects on the stack with garbage collection. -*/ - -Object** hoc_temp_objptr(obj) Object* obj; { - Object** tobj; - obj_pool_index_ = (obj_pool_index_ + 1)%TOBJ_POOL_SIZE; - tobj = hoc_temp_obj_pool_ + obj_pool_index_; - *tobj = obj; - return tobj; -} - -/* should be called after finished with pointer from a popobj */ - -void hoc_tobj_unref(Object** p) { - if (p >= hoc_temp_obj_pool_ && p < hoc_temp_obj_pool_ + TOBJ_POOL_SIZE) { - --tobj_count; - hoc_obj_unref(*p); - } -} - -/* -vec.c.x[0] used freed memory because the temporary vector was unreffed -after the x pointer was put on the stack but before it was evaluated. -The hoc_pop_defer replaces the nopop in in hoc_object_component handling -of a cplus steer method (which pushes a double pointer). The corresponding -hoc_unref_defer takes place in hoc_object_eval after evaluating -the pointer. This should take care of the most common (itself very rare) -problem. However it still would not in general -take care of the purposeless passing -of &vec.c.x[0] as an argument to a function since intervening pop_defer/unref_defer -pairs could take place. -*/ -static Object* unref_defer_; -void hoc_unref_defer(void) { - if (unref_defer_) { -#if 0 - printf("hoc_unref_defer %s %d\n", hoc_object_name(unref_defer_), unref_defer_->refcount); -#endif - hoc_obj_unref(unref_defer_); - unref_defer_ = (Object*)0; - } -} -void hoc_pop_defer(void) { - Object* obj; - if (unref_defer_) { -#if 0 - printf("hoc_pop_defer unrefs %s %d\n", hoc_object_name(unref_defer_), unref_defer_->refcount); -#endif - hoc_unref_defer(); - } - if (stackp <= stack) - execerror("stack underflow", (char *) 0); - if (stackp[-1].i == OBJECTTMP) { - unref_defer_ = stackp[-2].obj; - if (unref_defer_) { - ++unref_defer_->refcount; - } -#if 0 -printf("hoc_pop_defer %s %d\n", hoc_object_name(unref_defer_), unref_defer_->refcount); -#endif - } - hoc_nopop(); -} - -/* should be called on each OBJECTTMP on the stack after adjusting the -stack pointer downward */ - -void hoc_stkobj_unref(Object* o, int stkindex) { - if (stack[stkindex+1].i == OBJECTTMP) { - --tobj_count; - hoc_obj_unref(o); - stack[stkindex+1].i = STKOBJ_UNREF; - } -} - -/* check the args of the frame and unref any of type OBJECTTMP */ - -static void frameobj_clean(Frame* f) { - Datum* s; - int i, narg; - if (f->nargs == 0) { - return; - } - s = f->argn + 2; - for (i=f->nargs-1; i >= 0; --i) { - s -= 2; - if (s[1].i == OBJECTTMP) { - hoc_stkobj_unref(s->obj, (int)(s - stack)); - } - } -} - -/* unref items on the stack frame associated with localobj in case of error */ -static void frame_objauto_recover_on_err(Frame* ff) { /* only on error */ - Frame* f; - for (f = fp; f > ff; --f) { - int i; - Symbol* sp = f->sp; - /* argn is the nargs argument on the stack. Stack items come in pairs - so stack increments are always multiples of 2. - Here, stkp is the last+1 localobj slot pair on the stack. - */ - Datum* stkp = f->argn + 2 + sp->u.u_proc->nauto*2; - for (i = sp->u.u_proc->nobjauto; i > 0; --i) { - Object* ob = stkp[-2*i].obj; - hoc_obj_unref(ob); - /* Note that these AUTOOBJECT stack locations have an itemtype that - are left over from the previous stack usage of that location. - Regardless of that itemtype (e.g. OBJECTTMP), these did NOT - increment tobj_count so we need to guarantee that the subsequent - stack_obtmp_recover_on_err does not inadvertently free it again - by setting the itemtype to a non OBJECTTMP value. I hope this is - the only place where stack space was used in which no item type - was specified. - We are doing this here which happens rarely to avoid having to - set them when the stack obj pointers are zeroed. - */ - stkp[-2*i + 1].i = 0; - } - } -} - -static void stack_obtmp_recover_on_err(int tcnt) { - if (tobj_count > tcnt) { - Datum* stkp; - /* stackp - 2 because stackp is next available stack slot and - stack item,itemtype takes up two slots. - */ - for (stkp = stackp - 2; stkp >= stack; stkp -= 2) { - if (stkp[1].i == OBJECTTMP) { - hoc_stkobj_unref(stkp->obj, (int)(stkp - stack)); - if (tobj_count == tcnt) { - return; - } - }else if (stkp[1].i == STKOBJ_UNREF) { - printf("OBJECTTMP at stack index %ld already unreffed\n", stkp - stack); - } - } - } -} - -void hoc_init_space(void) /* create space for stack and code */ -{ - if (nframe == 0) { - nframe = NFRAME; - } - if (nstack == 0) { - nstack = NSTACK; - } - stackp = stack = (Datum *)emalloc(sizeof(Datum)*nstack); - stacklast = stack + nstack; - progp = progbase = prog = (Inst *)emalloc(sizeof(Inst)*NPROG); - fp = frame = (Frame *)emalloc(sizeof(Frame)*nframe); - framelast = frame + nframe; - hoc_temp_obj_pool_ = (Object**)emalloc(sizeof(Object*)*TOBJ_POOL_SIZE); -} - -#define MAXINITFCNS 10 -static int maxinitfcns; -static Pfrv initfcns[MAXINITFCNS]; - -void hoc_prstack(void) { - int i; - Datum* s; - Printf("interpreter stack: %ld \n", (stackp - stack)/2); - for (i=0, s = stackp - 1; s > stack; --s, ++i) { - if (i > 10) { - Printf("...\n"); - break; - } - Printf("%d stacktype=%d\n", i, s->i); - --s; - } -} - -void hoc_on_init_register(Pfrv pf) -{ - /* modules that may have to be cleaned up after an execerror */ - if (maxinitfcns < MAXINITFCNS) { - initfcns[maxinitfcns++] = pf; - }else{ - fprintf(stderr, "increase definition for MAXINITFCNS\n"); - nrn_exit(1); - } -} - -void initcode(void) /* initialize for code generation */ -{ - int i; - errno = 0; - if (hoc_errno_count > 5) { -fprintf(stderr, "errno set %d times on last execution\n", hoc_errno_count); - } - hoc_errno_count = 0; - prog_parse_recover = progbase = prog; - progp = progbase; - hoc_unref_defer(); - - frame_objauto_recover_on_err(frame); -if (tobj_count) { - stack_obtmp_recover_on_err(0); -#if DEBUG_GARBAGE - if (tobj_count) { - printf("initcode failed with %d left\n", tobj_count); - } -#endif - tobj_count = 0; -} - stackp = stack; - fp = frame; - free_list(&p_symlist); - hoc_returning = 0; - do_equation = 0; - for (i=0; i < maxinitfcns; ++i) { - (*initfcns[i])(); - } -#if CABLE - nrn_initcode(); /* special requirements for NEURON */ -#endif -} - - -static Frame *rframe; -static Datum *rstack; -static const char *parsestr; - -void oc_save_code( - Inst* *a1, - Inst* *a2, - Datum* *a3, - Frame* *a4, - int *a5, - int *a6, - Inst* *a7, - Frame* *a8, - Datum* *a9, - Symlist* *a10, - Inst* *a11, - int *a12 -){ - *a1 = progbase; - *a2 = progp; - *a3 = stackp; - *a4 = fp; - *a5 = hoc_returning; - *a6 = do_equation; - *a7 = pc; - *a8 = rframe; - *a9 = rstack; - *a10 = p_symlist; - *a11 = prog_parse_recover; - *a12 = tobj_count; -} - -void oc_restore_code( - Inst* *a1, - Inst* *a2, - Datum* *a3, - Frame* *a4, - int *a5, - int *a6, - Inst* *a7, - Frame* *a8, - Datum* *a9, - Symlist* *a10, - Inst* *a11, - int *a12 -){ - progbase = *a1; - progp = *a2; - frame_objauto_recover_on_err(*a4); - if (tobj_count > *a12) { - stack_obtmp_recover_on_err(*a12); -#if DEBUG_GARBAGE -if (tobj_count != *a12) { - printf("oc_restore_code tobj_count=%d should be %d\n", tobj_count, *a12); -} -#endif - } - stackp = *a3; - fp = *a4; - hoc_returning = *a5; - do_equation = *a6; - pc = *a7; - rframe = *a8; - rstack = *a9; - p_symlist = *a10; - prog_parse_recover = *a11; -} - -int hoc_strgets_need(void) { - return strlen(parsestr); -} - -char* hoc_strgets(char* cbuf, int nc) {/* getc for a string, used by parser */ - strncpy(cbuf, parsestr, nc); - if (*parsestr == '\0') { - return (char *)0; - }else{ - return cbuf; - } -} - -static void rinitcode(void) /* initialize for recursive code generation */ -{ - errno = 0; - hoc_errno_count = 0; - prog_parse_recover = progbase; - progp = progbase; - stackp = rstack; - fp = rframe; - free_list(&p_symlist); - if (hoc_returning != 4) { /* if stop not seen */ - hoc_returning = 0; - } - do_equation = 0; -} - -int hoc_ParseExec(int yystart) { - /* can recursively parse and execute what is in cbuf. - may parse single tokens. called from hoc_oc(str). - All these parse and execute routines should be combined into - a single method robust method. The pipeflag method has become - encrusted with too many irrelevant mechanisms. There is no longer - anything sacred about the cbuf. The only requiremnent is to tell - the get line function where to get its string. - */ - int yret; - - Frame *sframe, *sfp; - Inst *sprogbase, *sprogp, *spc, *sprog_parse_recover; - Datum *sstackp, *sstack; - Symlist *sp_symlist; - - if (yystart) { - sframe=rframe;sfp=fp; - sprogbase=progbase; sprogp=progp; spc=pc, - sprog_parse_recover=prog_parse_recover; - sstackp=stackp; sstack=rstack; - sp_symlist=p_symlist; - rframe = fp; - rstack = stackp; - progbase = progp; - p_symlist = (Symlist *)0; - } - - if (yystart) { - rinitcode(); - } - if (hoc_in_yyparse) { - hoc_execerror("Cannot reenter parser.", - "Maybe you were in the middle of a direct command."); - } - yret = yyparse(); - switch (yret) { - case 1: - execute(progbase); - rinitcode(); - break; - case 'e': - hoc_edit(); - for (rinitcode(); hoc_yyparse(); rinitcode()) { - execute(progbase); - } - break; - case -3 : - hoc_execerror("incomplete statement parse not allowed\n", (char*)0); - default: - break; - } - if (yystart) { - rframe=sframe; fp=sfp; - progbase=sprogbase; progp=sprogp; pc=spc; - prog_parse_recover=sprog_parse_recover; - stackp=sstackp; rstack=sstack; p_symlist=sp_symlist; - } - - return yret; -} - -int hoc_xopen_run(Symbol* sp, const char* str) { /*recursively parse and execute for xopen*/ -/* if sp != 0 then parse string and save code */ -/* without executing. Note str must be a 'list'*/ - int n=0; - Frame *sframe=rframe, *sfp=fp; - Inst *sprogbase=progbase, *sprogp=progp, *spc=pc, - *sprog_parse_recover=prog_parse_recover; - Datum *sstackp=stackp, *sstack=rstack; - Symlist *sp_symlist=p_symlist; - rframe = fp; - rstack = stackp; - progbase = progp; - p_symlist = (Symlist *)0; - - if (sp == (Symbol *)0) { - for (rinitcode(); hoc_yyparse(); rinitcode()) - execute(progbase); - }else{ int savpipeflag; - rinitcode(); - savpipeflag = hoc_pipeflag; - hoc_pipeflag = 2; - parsestr=str; - if(!hoc_yyparse()) { - execerror("Nothing to parse", (char *)0); - } - n = (int)(progp-progbase); - hoc_pipeflag = savpipeflag; - hoc_define(sp); - rinitcode(); - } - rframe=sframe; fp=sfp; - progbase=sprogbase; progp=sprogp; pc=spc; - prog_parse_recover=sprog_parse_recover; - stackp=sstackp; rstack=sstack; p_symlist=sp_symlist; - return n; -} - -#define HOC_TEMP_CHARPTR_SIZE 128 -static char* stmp[HOC_TEMP_CHARPTR_SIZE]; -static int istmp = 0; -char** hoc_temp_charptr(void) { - istmp = (istmp+1)%HOC_TEMP_CHARPTR_SIZE; - return stmp+istmp; -} - -int hoc_is_temp_charptr(char** cpp) { - if (cpp >= stmp && cpp < stmp + HOC_TEMP_CHARPTR_SIZE) { - return 1; - } - return 0; -} - -int hoc_stack_type(void) { - return stackp[-1].i; -} - -void pushx(double d) { /* push double onto stack */ - STACKCHK - (stackp++)->val = d; - (stackp++)->i = NUMBER; -} - -void hoc_pushobj(Object** d) { /* push pointer to object pointer onto stack */ - STACKCHK - if (d >= hoc_temp_obj_pool_ && d < (hoc_temp_obj_pool_ + TOBJ_POOL_SIZE)) { - hoc_push_object(*d); - return; - } - (stackp++)->pobj = d; - (stackp++)->i = OBJECTVAR; -} - -void hoc_push_object(Object* d) { /* push pointer to object onto stack */ - STACKCHK - (stackp++)->obj = d; - (stackp++)->i = OBJECTTMP; /* would use OBJECT if it existed */ - hoc_obj_ref(d); - ++tobj_count; -} - -void hoc_pushstr(char** d) { /* push pointer to string pointer onto stack */ - STACKCHK - (stackp++)->pstr = d; - (stackp++)->i = STRING; -} - -void hoc_push_string(void) { /* code for pushing a symbols string */ - Objectdata* odsav; - Object* obsav = 0; - Symlist* slsav; - Symbol *s; - s = (pc++)->sym; - if (!s) { - hoc_pushstr((char**) 0); - return; - } - if (s->type == CSTRING) { - hoc_pushstr(&(s->u.cstr)); - }else{ - if (s->public == 2) { - s = s->u.sym; - odsav = hoc_objectdata_save(); - obsav = hoc_thisobject; - slsav = hoc_symlist; - hoc_objectdata = hoc_top_level_data; - hoc_thisobject = 0; - hoc_symlist = hoc_top_level_symlist; - } - hoc_pushstr(OPSTR(s)); - if (obsav) { - hoc_objectdata = hoc_objectdata_restore(odsav); - hoc_thisobject = obsav; - hoc_symlist = slsav; - } - } -} - -void hoc_pushpx(double* d) { /* push double pointer onto stack */ - STACKCHK - (stackp++)->pval = d; - (stackp++)->i = VAR; -} - -void pushs(Symbol* d) { /* push symbol pointer onto stack */ - STACKCHK - (stackp++)->sym = d; - (stackp++)->i = SYMBOL; -} -void pushi(int d) { /* push integer onto stack */ - STACKCHK - (stackp++)->i = d; - (stackp++)->i = USERINT; -} - -int hoc_stacktype(void) { - if (stackp <= stack) { - execerror("stack empty", (char*)0); - } - return (stackp - 1)->i; -} - -int hoc_argtype(int narg) { /* type of nth arg */ - if (narg > fp->nargs) - execerror(fp->sp->name, "not enough arguments"); - return(fp->argn[(narg - fp->nargs)*2 + 1].i); -} - -int hoc_is_double_arg(int narg) { - return (hoc_argtype(narg) == NUMBER); -} - -int hoc_is_pdouble_arg(int narg) { - return (hoc_argtype(narg) == VAR); -} - -int hoc_is_str_arg(narg) int narg; { - return (hoc_argtype(narg) == STRING); -} - -int hoc_is_object_arg(int narg) { - int type = hoc_argtype(narg); - return (type == OBJECTVAR || type == OBJECTTMP); -} - -int hoc_is_tempobj_arg(int narg) { - return (hoc_argtype(narg) == OBJECTTMP); -} - -Datum* hoc_look_inside_stack(int i, int type) {/* stack pointer at depth i; i=0 is top */ - tstkchk((stackp - 2*i - 1)->i, type); - return stackp - 2*(i + 1); -} - -Object* hoc_obj_look_inside_stack(int i) { /* stack pointer at depth i; i=0 is top */ - Datum* d = stackp - 2*i - 2; - int type = d[1].i; - if (type == OBJECTTMP) { - return d[0].obj; - } - tstkchk(type, OBJECTVAR); - return *(d[0].pobj); -} - -int hoc_obj_look_inside_stack_index(int i) { - return (int)((stackp - 2*i - 2) - stack); -} - -int hoc_inside_stacktype(int i) { /* 0 is top */ - return (stackp - 2*i - 1)->i; -} - -double xpop(void) { /* pop double and return top elem from stack */ - if (stackp <= stack) - execerror("stack underflow", (char *) 0); - tstkchk(stackp[-1].i, NUMBER); - stackp -= 2; - return stackp->val; -} - -#if 0 -void pstack(void) { - char* hoc_object_name(); - Datum* d; - int i; - for (d=stackp; d > stack;) { - i = (--d)->i; - --d; - switch(i) { - case NUMBER: - printf("(double)\n"); - break; - case STRING: - printf("(char *)\n"); - break; - case OBJECTVAR: - printf("(Object **) %s\n", hoc_object_name(*(d->pobj))); - break; - case USERINT: - printf("(int)\n"); - break; - case SYMBOL: - printf("(Symbol) %s\n", d->sym); - break; - case VAR: - printf("(double *)\n"); - break; - case OBJECTTMP: /* would use OBJECT if it existed */ - printf("(Object *) %s\n", hoc_object_name(d->obj)); - break; - case STKOBJ_UNREF: /* hoc_stkobj_ref already called */ - printf("(Object * already unreffed by hoc_stkobj_ref at stkindex %ld. Following name print may cause a crash if already freed.\n", d - stack); - printf(" %s\n", hoc_object_name(d->obj)); - break; - default: - printf("(Unknown)\n"); - break; - } - } -} -#endif - -double* hoc_pxpop(void) {/* pop double pointer and return top elem from stack */ - if (stackp <= stack) - execerror("stack underflow", (char *) 0); - tstkchk(stackp[-1].i, VAR); - stackp -= 2; - return stackp->pval; -} - -Symbol* spop(void) {/* pop symbol pointer and return top elem from stack */ - if (stackp <= stack) - execerror("stack underflow", (char *) 0); - tstkchk(stackp[-1].i, SYMBOL); - stackp -= 2; - return stackp->sym; -} - -/* -When using objpop, after dealing with the pointer, one should call - hoc_tobj_unref(pobj) in order to prevent memory leakage since - the object may have been reffed when it was pushed on the stack -*/ - -Object** hoc_objpop(void) {/* pop pointer to object pointer and return top elem from stack */ - if (stackp <= stack) - execerror("stack underflow", (char *) 0); - stackp -= 2; - if (stackp[1].i == OBJECTTMP) { - return hoc_temp_objptr(stackp->obj); - } - tstkchk(stackp[1].i, OBJECTVAR); /* safe because cannot be OBJECTTMP */ - return stackp->pobj; -} - -Object* hoc_pop_object(void ) {/* pop object and return top elem from stack */ - if (stackp <= stack) - execerror("stack underflow", (char *) 0); - tstkchk(stackp[-1].i, OBJECTTMP); - stackp -= 2; - return stackp->obj; -} - -char** hoc_strpop(void) { /* pop pointer to string pointer and return top elem from stack */ - if (stackp <= stack) - execerror("stack underflow", (char *) 0); - tstkchk(stackp[-1].i, STRING); - stackp -= 2; - return stackp->pstr; -} - -int ipop(void) {/* pop symbol pointer and return top elem from stack */ - if (stackp <= stack) - execerror("stack underflow", (char *) 0); - tstkchk(stackp[-1].i, USERINT); - stackp -= 2; - return stackp->i; -} - -void nopop(void) {/* just pop the stack without returning anything */ - if (stackp <= stack) - execerror("stack underflow", (char *) 0); - stackp -= 2; - if (stackp[1].i == OBJECTTMP) { - hoc_stkobj_unref(stackp->obj, (int)(stackp - stack)); - } -} - -void constpush(void) /* push constant onto stack */ -{ - pushxm(*((pc++)->sym)->u.pnum); -} - -void pushzero(void) /* push zero onto stack */ -{ - pushxm(0.); -} - -void varpush(void) /* push variable onto stack */ -{ - pushsm((pc++)->sym); -} - -# define relative(pc) (pc + (pc)->i) - -void forcode(void) -{ - double d; - Inst *savepc = pc; /* loop body */ - int isec; - -#if CABLE - isec = nrn_isecstack(); -#endif - execute(savepc+3); /* condition */ - d = xpopm(); - while (d) - { - execute(relative(savepc)); /* body */ -#if CABLE - if (hoc_returning) {nrn_secstack(isec);} -#endif - if (hoc_returning == 1 || hoc_returning == 4) /* return or stop */ - break; - else if (hoc_returning == 2) /* break */ - { - hoc_returning = 0; - break; - } - else /* continue */ - hoc_returning = 0; - if ((savepc+2)->i) /* diff between while and for */ - execute(relative(savepc+2)); /* increment */ - execute(savepc+3); - d = xpopm(); - } - if (!hoc_returning) - pc = relative(savepc+1); /* next statement */ -} - -static void warn_assign_dynam_unit(const char* name) { - static int first = 1; - if (first) { - char mes[100]; - first = 0; - sprintf(mes, "Assignment to %s physical constant %s", - _nrnunit_use_legacy_ ? "legacy" : "modern", - name); - hoc_warning(mes, NULL); - } -} - -void shortfor(void) -{ - Inst *savepc = pc; - double begin, end, *pval=0; - Symbol *sym; - int isec; - - end = xpopm() + EPS; - begin = xpopm(); - sym = spopm(); - - switch (sym->type) { - case UNDEF: - hoc_execerror(sym->name, "undefined variable"); - case VAR: -if (!ISARRAY(sym)) { - if (sym->subtype == USERINT) { - execerror("integer iteration variable", sym->name); - }else if (sym->subtype == USERDOUBLE) { - pval = sym->u.pval; - }else if (sym->subtype == DYNAMICUNITS) { - pval = sym->u.pval + _nrnunit_use_legacy_; - warn_assign_dynam_unit(sym->name); - }else{ - pval = OPVAL(sym); - } - break; -} else { - if (sym->subtype == USERINT) - execerror("integer iteration variable", sym->name); - else if (sym->subtype == USERDOUBLE) - pval = sym->u.pval + araypt(sym, SYMBOL); - else - pval = OPVAL(sym) + araypt(sym, OBJECTVAR); -} - break; - case AUTO: - pval = &(fp->argn[sym->u.u_auto*2].val); - break; - default: - execerror("for loop non-variable", sym->name); - } -#if CABLE - isec = nrn_isecstack(); -#endif - for (*pval = begin; *pval<=end; *pval += 1.) { - execute(relative(savepc)); -#if CABLE - if (hoc_returning) {nrn_secstack(isec);} -#endif - if (hoc_returning == 1 || hoc_returning == 4) { - break; - }else if (hoc_returning == 2) { - hoc_returning = 0; - break; - }else{ - hoc_returning = 0; - } - } - if (!hoc_returning) - pc =relative(savepc+1); -} - -void hoc_iterator(void) { - /* pc is ITERATOR symbol, argcount, stmtbegin, stmtend */ - /* for testing execute stmt once */ - Symbol* sym; - int argcount; - Inst* stmtbegin, *stmtend; - - sym = (pc++)->sym; - argcount = (pc++)->i; - stmtbegin = relative(pc); - stmtend = relative(pc+1);; - hoc_iterator_object(sym, argcount, stmtbegin, stmtend, hoc_thisobject); -} - -void hoc_iterator_object( - Symbol* sym, - int argcount, - Inst* beginpc, - Inst* endpc, - Object* ob -){ - int i; - fp++; - if (fp >= framelast) { - fp--; - execerror(sym->name, "call nested too deeply, increase with -NFRAME framesize option"); - } - fp->sp = sym; - fp->nargs = argcount; - fp->retpc = endpc; - fp->argn = stackp - 2; - stackp += sym->u.u_proc->nauto * 2; - /* clear the autoobject pointers */ - for (i = sym->u.u_proc->nobjauto; i > 0; --i) { - stackp[-2*i].obj = (Object*)0; - } - fp->iter_stmt_begin = beginpc; - fp->iter_stmt_ob = ob; - fp->ob = ob; - STACKCHK - execute(sym->u.u_proc->defn.in); - nopop(); /* 0.0 from the procret() */ - if (hoc_returning != 4) { - hoc_returning = 0; - } -} - -void hoc_iterator_stmt(void) { - Inst* pcsav; - Object* ob; - Object* obsav; - Objectdata* obdsav; - Symlist* slsav; - int isec; - Frame* iter_f = fp; /* iterator frame */ - Frame* ef = fp - 1; /* iterator statement frame */ - fp++; /* execution frame */ - - fp->sp = iter_f->sp; - fp->ob = iter_f->ob; - if (ef != frame) { - /*SUPPRESS 26*/ - fp->argn = ef->argn; - fp->nargs = ef->nargs; - }else{ /* top. only for stack trace */ - fp->argn = 0; - fp->nargs = 0; - } - - ob = iter_f->iter_stmt_ob; - obsav = hoc_thisobject; - obdsav = hoc_objectdata_save(); - slsav = hoc_symlist; - hoc_thisobject = ob; - if (ob) { - hoc_objectdata = ob->u.dataspace; - hoc_symlist = ob->template->symtable; - }else{ - hoc_objectdata = hoc_top_level_data; - hoc_symlist = hoc_top_level_symlist; - } - - pcsav = pc; -#if CABLE - isec = nrn_isecstack(); -#endif - execute(iter_f->iter_stmt_begin); - pc = pcsav; - hoc_objectdata = hoc_objectdata_restore(obdsav); - hoc_thisobject = obsav; - hoc_symlist = slsav; - --fp; -#if CABLE - if (hoc_returning) {nrn_secstack(isec);} -#endif - switch (hoc_returning) { - case 1: /* return means not only return from iter but return from - the procedure containing the iter statement */ -hoc_execerror("return from within an iterator statement not allowed.", -"Set a flag and use break."); - case 2: /* break means return from iter */ - procret(); - break; - case 3: /* continue means go on from iter as though nothing happened*/ - hoc_returning = 0; - break; - } - -} - -static void for_segment2(Symbol* sym, int mode) { - /* symbol on stack; statement pointed to by pc - continuation pointed to by pc+1. template used is shortfor in code.c - of hoc system. - */ - -#if CABLE - int i, imax; - Inst *savepc = pc; - double *pval=0, dx; - int isec; -#if METHOD3 - extern int _method3; -#endif - - switch (sym->type) { - case UNDEF: - hoc_execerror(sym->name, "undefined variable"); - case VAR: -if (!ISARRAY(sym)) { - if (sym->subtype == USERINT) { - execerror("integer iteration variable", sym->name); - }else if (sym->subtype == USERDOUBLE){ - pval = sym->u.pval; - }else if (sym->subtype == DYNAMICUNITS) { - pval = sym->u.pval + _nrnunit_use_legacy_; - warn_assign_dynam_unit(sym->name); - }else{ - pval = OPVAL(sym); - } - break; -} else { - if (sym->subtype == USERINT) - execerror("integer iteration variable", sym->name); - else if (sym->subtype == USERDOUBLE) - pval = sym->u.pval + araypt(sym, SYMBOL); - else - pval = OPVAL(sym) + araypt(sym, OBJECTVAR); -} - break; - case AUTO: - pval = &(fp->argn[sym->u.u_auto*2].val); - break; - default: - execerror("for loop non-variable", sym->name); - } - imax = segment_limits(&dx); -#if METHOD3 - if (_method3) { - for (i=0, *pval=0; i <= imax; i++) { - if (mode == 0 && (i == imax || i == 0)) { continue; } - if (i == imax) { - *pval = 1.; - } else { - *pval = i * dx; - } - execute(relative(savepc)); - if (hoc_returning == 1 || hoc_returning == 4) { - break; - }else if (hoc_returning == 2) { - hoc_returning = 0; - break; - }else{ - hoc_returning = 0; - } - } - }else -#endif - { - if (mode == 0) { - i = 1; - *pval = dx/2.; - }else{ - i = 0; - *pval = 0.; - } -#if CABLE - isec = nrn_isecstack(); -#endif - for (; i <= imax; i++) { - if (i == imax) { - if (mode == 0) { continue; } - *pval = 1.; - } - execute(relative(savepc)); -#if CABLE - if (hoc_returning) {nrn_secstack(isec);} -#endif - if (hoc_returning == 1 || hoc_returning == 4) { - break; - }else if (hoc_returning == 2) { - hoc_returning = 0; - break; - }else{ - hoc_returning = 0; - } - if (i == 0) { - *pval += dx/2.; - } - else if (i < imax) { - *pval += dx; - } - } - } - if (!hoc_returning) - pc =relative(savepc+1); -#else - execerror("for (var) {stmt} syntax only allowed in CABLE", (char *)0); -#endif -} - -void for_segment(void) { - for_segment2(spopm(), 1); -} - -void for_segment1(void) { - Symbol* sym; - double d; - int mode; - d = xpopm(); - sym = spopm(); - mode = (fabs(d)< EPS) ? 0 : 1; - for_segment2(sym, mode); -} - -void ifcode(void) -{ - double d; - Inst *savepc = pc; /* then part */ - - execute(savepc+3); /* condition */ - d = xpopm(); - if (d) - execute(relative(savepc)); - else if ((savepc+1)->i) /* else part? */ - execute(relative(savepc+1)); - if (!hoc_returning) - pc = relative(savepc+2); /* next stmt */ -} - -void Break(void) /* break statement */ -{ - hoc_returning = 2; -} - -void Continue(void) /* continue statement */ -{ - hoc_returning = 3; -} - -void Stop(void) /* stop statement */ -{ - hoc_returning = 4; -} - -void hoc_define(Symbol* sp) { /* put func/proc in symbol table */ - Inst *inst, *newinst; - - if (sp->u.u_proc->defn.in != STOP) - free((char *) sp->u.u_proc->defn.in); - free_list(&(sp->u.u_proc->list)); - sp->u.u_proc->list = p_symlist; - p_symlist = (Symlist *)0; - sp->u.u_proc->size =(unsigned)(progp - progbase); - sp->u.u_proc->defn.in = (Inst *) emalloc((unsigned)(progp-progbase)*sizeof(Inst)); - newinst = sp->u.u_proc->defn.in; - for (inst = progbase; inst != progp; ) - *newinst++ = *inst++; - progp = progbase; /* next code starts here */ -} - -void frame_debug(void) /* print the call sequence on an execerror */ -{ - Frame *f; - int i, j; - char id[10]; - - if (nrnmpi_numprocs_world > 1) { - sprintf(id, "%d ", nrnmpi_myid_world); - }else{ - id[0]='\0'; - } - for (i=5, f=fp; f != frame && --i; f=f-1) { /* print only to depth of 5 */ - for (j=i; j; j--) { - Fprintf(stderr, " "); - } - if (f->ob) { - Fprintf(stderr, "%s%s.%s(", id, hoc_object_name(f->ob), f->sp->name); - }else{ - Fprintf(stderr, "%s%s(", id, f->sp->name); - } - for (j=1; j<=f->nargs;) { - switch(f->argn[(j - f->nargs)*2 + 1].i) { - case NUMBER: - Fprintf(stderr, "%g", f->argn[(j - f->nargs)*2].val); - break; - case STRING: - { - char* s = *f->argn[(j - f->nargs)*2].pstr; - if(strlen(s) > 15) { - Fprintf(stderr, "\"%.10s...\"", s); - }else{ - Fprintf(stderr, "\"%s\"", s); - } - } - break; - case OBJECTVAR: -Fprintf(stderr, "%s", hoc_object_name(*f->argn[(j - f->nargs)*2].pobj)); - break; - default: - Fprintf(stderr, "..."); - break; - } - if (++j <= f->nargs) { - Fprintf(stderr, ", "); - } - } - Fprintf(stderr, ")\n"); - } - if (i <= 0) { - Fprintf(stderr, "and others\n"); - } -} - -void push_frame(Symbol* sp, int narg) { /* helpful for explicit function calls */ - if (++fp >= framelast) { - --fp; - execerror(sp->name, "call nested too deeply, increase with -NFRAME framesize option"); - } - fp->sp = sp; - fp->nargs = narg; - fp->argn = stackp - 2; /* last argument */ - fp->ob = hoc_thisobject; -} - -void pop_frame(void) { - int i; - frameobj_clean(fp); - for (i = 0; i < fp->nargs; i++) - nopopm(); /* pop arguments */ - --fp; -} - -void call(void) /* call a function */ -{ - int i, isec; - Symbol *sp = pc[0].sym; /* symbol table entry */ - /* for function */ - if (++fp >= framelast) { - --fp; - execerror(sp->name, "call nested too deeply, increase with -NFRAME framesize option"); - } - fp->sp = sp; - fp->nargs = pc[1].i; - fp->retpc = pc + 2; - fp->ob = hoc_thisobject; - /*SUPPRESS 26*/ - fp->argn = stackp - 2; /* last argument */ - BBSPOLL -#if CABLE - isec = nrn_isecstack(); -#endif - if (sp->type == FUN_BLTIN || sp->type == OBJECTFUNC || sp->type == STRINGFUNC) { - stackp += sp->u.u_proc->nauto * 2; /* Offset stack for auto space */ - STACKCHK - (*(sp->u.u_proc->defn.pf))(); - if (hoc_errno_check()) { - hoc_warning("errno set during call of", sp->name); - } - } else if ((sp->type == FUNCTION || sp->type == PROCEDURE || sp->type == HOCOBJFUNCTION) - && sp->u.u_proc->defn.in != STOP) { - stackp += sp->u.u_proc->nauto * 2; /* Offset stack for auto space */ - STACKCHK - /* clear the autoobject pointers. */ - for (i = sp->u.u_proc->nobjauto; i > 0; --i) { - stackp[-2*i].obj = (Object*)0; - } - if (sp->public == 2) { - Objectdata* odsav = hoc_objectdata_save(); - Object* obsav = hoc_thisobject; - Symlist* slsav = hoc_symlist; - - hoc_objectdata = hoc_top_level_data; - hoc_thisobject = 0; - hoc_symlist = hoc_top_level_symlist; - - execute(sp->u.u_proc->defn.in); - - hoc_objectdata = hoc_objectdata_restore(odsav); - hoc_thisobject = obsav; - hoc_symlist = slsav; - }else{ - execute(sp->u.u_proc->defn.in); - } - /* the autoobject pointers were unreffed at the ret() */ - - } else { - execerror(sp->name, "undefined function"); - } -#if CABLE - if (hoc_returning) {nrn_secstack(isec);} -#endif - if (hoc_returning != 4) { /*if not stopping */ - hoc_returning = 0; - } -} - -void hoc_fake_call(Symbol* s) { - /*fake it so c code can call functions that ret() */ - /* but these functions better not ask for any arguments */ - /* don't forget a double is left on the stack and returning = 1 */ - /* use the symbol for the function as the argument, only requirement - which is always true is that it has no local variables pushed on - the stack so nauto=0 and nobjauto=0 */ - ++fp; - fp->sp = s; - fp->nargs = 0; - fp->retpc = pc; - fp->ob = 0; -} - -double hoc_call_func(Symbol* s, int narg) { - /* call the symbol as a function, The args better be pushed on the stack - first arg first. */ - if (s->type == BLTIN) { - return (*(s->u.ptr))(xpop()); - }else{ - Inst* pcsav; - Inst fc[4]; - fc[0].pf = hoc_call; - fc[1].sym = s; - fc[2].i = narg; - fc[3].in = STOP; - - pcsav = hoc_pc; - hoc_execute(fc); - hoc_pc = pcsav; - return hoc_xpop(); - } -} - -void hoc_ret(void) { /* common return from func, proc, or iterator */ - int i; - /* unref all the auto object pointers */ - for (i = fp->sp->u.u_proc->nobjauto; i > 0; --i) { - hoc_obj_unref(stackp[-2*i].obj); - } - stackp -= fp->sp->u.u_proc->nauto * 2; /* Pop off the autos */ - frameobj_clean(fp); - for (i = 0; i < fp->nargs; i++) - nopopm(); /* pop arguments */ - pc = (Inst *)fp->retpc; - --fp; - hoc_returning = 1; -} - -void funcret(void) /* return from a function */ -{ - double d; - if (fp->sp->type != FUNCTION) - execerror(fp->sp->name, "(proc or iterator) returns value"); - d = xpopm(); /* preserve function return value */ - ret(); - pushxm(d); -} - -void procret(void) /* return from a procedure */ -{ - if (fp->sp->type == FUNCTION) - execerror(fp->sp->name, - "(func) returns no value"); - if (fp->sp->type == HOCOBJFUNCTION) - execerror(fp->sp->name, - "(obfunc) returns no value"); - ret(); - pushxm(0.); /*will be popped immediately; necessary because caller - may have compiled it as a function*/ -} - -void hocobjret(void) /* return from a hoc level obfunc */ -{ - Object** d; - if (fp->sp->type != HOCOBJFUNCTION) - execerror(fp->sp->name, "objfunc returns objref"); - d = hoc_objpop(); /* preserve function return value */ - if (*d) { (*d)->refcount++;} - ret(); - /*make a temp and ref it in case autoobj returned since ret would - have unreffed it*/ - hoc_push_object(*d); - - if (*d) { (*d)->refcount--;} - hoc_tobj_unref(d); -} - -void hoc_Numarg(void) -{ - int narg; - Frame* f = fp - 1; - if (f == frame) { - narg = 0; - }else{ - narg = f->nargs; - } - ret(); - pushxm((double)narg); -} - -void hoc_Argtype(void) -{ - int narg, iarg, type, itype=0; - Frame* f = fp - 1; - if (f == frame) { - execerror("argtype can only be called in a func or proc", 0); - } - iarg = (int)chkarg(1, -1000., 100000.); - if (iarg > f->nargs || iarg < 1) { - itype = -1; - }else{ - type = (f->argn[(iarg - f->nargs)*2 + 1].i); - switch (type) { - case NUMBER: itype = 0; break; - case OBJECTVAR: - case OBJECTTMP: itype = 1; break; - case STRING: itype = 2; break; - case VAR: itype = 3; break; - } - } - ret(); - pushxm((double)itype); -} - -int ifarg(int narg) { /* true if there is an nth argument */ - if (narg > fp->nargs) - return 0; - return 1; -} - -Object** hoc_objgetarg(int narg) {/* return pointer to nth argument */ - Datum* d; - if (narg > fp->nargs) - execerror(fp->sp->name, "not enough arguments"); - d = fp->argn + (narg - fp->nargs)*2; - if (d[1].i == OBJECTTMP) { - return hoc_temp_objptr(d[0].obj); - } - tstkchk(d[1].i, OBJECTVAR); - return d[0].pobj; -} - -char** hoc_pgargstr(int narg) { /* return pointer to nth argument */ - char ** cpp = NULL; - Symbol *sym; - int type; - if (narg > fp->nargs) - execerror(fp->sp->name, "not enough arguments"); - type = fp->argn[(narg - fp->nargs)*2 + 1].i; - if (type == STRING) { - cpp = fp->argn[(narg - fp->nargs)*2].pstr; - }else if (type != SYMBOL) { - execerror("Expecting string argument", (char *)0); - }else{ - sym = fp->argn[(narg - fp->nargs)*2].sym; - if (sym->type == CSTRING) { - cpp = &sym->u.cstr; - }else if (sym->type == STRING) { - cpp = OPSTR(sym); - }else{ - execerror("Expecting string argument", (char *)0); - } - } - return cpp; -} - -double* hoc_pgetarg(int narg) { /* return pointer to nth argument */ - if (narg > fp->nargs) - execerror(fp->sp->name, "not enough arguments"); - tstkchk(fp->argn[(narg - fp->nargs)*2 + 1].i, VAR); - return fp->argn[(narg - fp->nargs)*2].pval; -} - -double* getarg(int narg) { /* return pointer to nth argument */ - if (narg > fp->nargs) - execerror(fp->sp->name, "not enough arguments"); -#if 1 - tstkchk(fp->argn[(narg - fp->nargs)*2 + 1].i, NUMBER); -#endif - return &fp->argn[(narg - fp->nargs)*2].val; -} - -int hoc_argindex(void) { - int j; - j = (int)xpopm(); - if (j < 1) { - hoc_execerror("arg index i < 1", 0); - } - return j; -} - -void arg(void) /* push argument onto stack */ -{ - int i; - i = (pc++)->i; - if (i == 0) { - i = hoc_argindex(); - } - pushxm( *getarg(i)); -} - -void hoc_stringarg(void) /* push string arg onto stack */ -{ - int i; - i = (pc++)->i; - if (i == 0) { - i = hoc_argindex(); - } - hoc_pushstr(hoc_pgargstr(i)); -} - -double hoc_opasgn(int op, double dest, double src) { - switch (op) { - case '+': - return dest + src; - case '*': - return dest * src; - case '-': - return dest - src; - case '/': - if (src == 0.) { - hoc_execerror("Divide by 0", (char*)0); - } - return dest / src; - default: - return src; - } -} -void argassign(void) /* store top of stack in argument */ -{ - double d; - int i, op; - i = (pc++)->i; - if (i == 0) { - i = hoc_argindex(); - } - op = (pc++)->i; - d = xpopm(); - if (op) { - d = hoc_opasgn(op, *getarg(i), d); - } - pushxm(d); /* leave value on stack */ - *getarg(i) = d; -} - -void hoc_argrefasgn(void) { - double d, *pd; - int i, j, op; - i = (pc++)->i; - j = (pc++)->i; - if (i == 0) { - i = hoc_argindex(); - } - op = (pc++)->i; - d = xpopm(); - if (j) { - j = (int)(xpopm() + EPS); - } - pd = hoc_pgetarg(i); - if (op) { - d = hoc_opasgn(op, pd[j], d); - } - pushxm(d); /* leave value on stack */ - pd[j] = d; -} - -void hoc_argref(void) { - int i, j; - double* pd; - i = (pc++)->i; - j = (pc++)->i; - if (i == 0) { - i = hoc_argindex(); - } - pd = hoc_pgetarg(i); - if (j) { - j = (int)(xpopm() + EPS); - } - pushxm(pd[j]); -} - -void hoc_argrefarg(void) { - double* pd; - int i; - i = (pc++)->i; - if (i == 0) { - i = hoc_argindex(); - } - pd = hoc_pgetarg(i); - hoc_pushpx(pd); -} - -void bltin(void) /* evaluate built-in on top of stack */ -{ - double d; - d = xpopm(); - d = (*((pc++)->sym->u.ptr))(d); - pushxm(d); -} - -Symbol* hoc_get_symbol(const char* var) { - Symlist *sl = (Symlist *)0; - Symbol *prc, *sym; - Inst* last; - prc = hoc_parse_stmt(var, &sl); - hoc_run_stmt(prc); - - last = (Inst*)prc->u.u_proc->defn.in + prc->u.u_proc->size - 1; - if (last[-2].pf == eval) { - sym = last[-3].sym; - }else if (last[-3].pf == rangepoint || last[-3].pf == rangevareval) { - sym = last[-2].sym; - }else if (last[-4].pf == hoc_object_eval) { - sym = last[-10].sym; - }else{ - sym = (Symbol*)0; - } - free_list(&sl); - return sym; -} - -Symbol* hoc_get_last_pointer_symbol(void) {/* hard to imagine a kludgier function*/ - Symbol* sym = (Symbol*)0; - Inst* pcv; - int istop=0; - for (pcv = pc; pcv; --pcv) { - if (pcv->pf == hoc_ob_pointer) { - if (pcv[-2].sym) { - sym = pcv[-2].sym; /* e.g. &ExpSyn[0].A */ - }else{ - sym = pcv[-6].sym; /* e.g. & Cell[0].soma.v(.5) */ - } - break; - }else if (pcv->pf == hoc_evalpointer) { - sym = pcv[-1].sym; - break; - }else if (pcv->pf == rangevarevalpointer) { - sym = pcv[1].sym; - break; - }else if (pcv->in == STOP) { -/* hopefully only got here from python. Give up on second STOP*/ - if (istop++ == 1) { - break; - } - } - } - return sym; -} - -void hoc_autoobject(void) { /* AUTOOBJ symbol at pc+1. */ - /* pointer to object pointer left on stack */ - int i; - Symbol *obs; - Object **obp; -#if PDEBUG - printf("code for hoc_autoobject()\n"); -#endif - obs = (pc++)->sym; - hoc_pushobj(&(fp->argn[obs->u.u_auto*2].obj)); -} - -void eval(void) /* evaluate variable on stack */ -{ - Objectdata* odsav; - Object* obsav = 0; - Symlist* slsav; - double d=0.0, cable_prop_eval(); - Symbol *sym; - sym = spopm(); - if (sym->public == 2) { - sym = sym->u.sym; - odsav = hoc_objectdata_save(); - obsav = hoc_thisobject; - slsav = hoc_symlist; - hoc_objectdata = hoc_top_level_data; - hoc_thisobject = 0; - hoc_symlist = hoc_top_level_symlist; - } - switch (sym->type) - { - case UNDEF: - execerror("undefined variable", sym->name); - case VAR: -if (!ISARRAY(sym)) { - if (do_equation && sym->s_varn > 0 - && hoc_access[sym->s_varn] == 0) - { - hoc_access[sym->s_varn] = var_access; - var_access = sym->s_varn; - } - switch (sym->subtype) { - case USERDOUBLE: - d = *(sym->u.pval); - break; - case USERINT: - d = (double)(*(sym->u.pvalint)); - break; - case DYNAMICUNITS: - d = sym->u.pval[_nrnunit_use_legacy_]; - break; -#if CABLE - case USERPROPERTY: - d = cable_prop_eval(sym); - break; -#endif - case USERFLOAT: - d = (double)(*(sym->u.pvalfloat)); - break; - default: - d = *(OPVAL(sym)); - break; - } -}else { - switch (sym->subtype) { - case USERDOUBLE: - d = (sym->u.pval)[araypt(sym, SYMBOL)]; - break; - case USERINT: - d = (sym->u.pvalint)[araypt(sym, SYMBOL)]; - break; - case USERFLOAT: - d = (sym->u.pvalfloat)[araypt(sym, SYMBOL)]; - break; -#if NEMO - case NEMONODE: - hoc_eval_nemonode(sym, xpopm(), &d); - break; - case NEMOAREA: - hoc_eval_nemoarea(sym, xpopm(), &d); - break; -#endif /*NEMO*/ - default: - d = (OPVAL(sym))[araypt(sym, OBJECTVAR)]; - break; - } -} - break; - case AUTO: - d = fp->argn[sym->u.u_auto*2].val; - break; - default: - execerror("attempt to evaluate a non-variable", sym->name); - } - - if (obsav) { - hoc_objectdata = hoc_objectdata_restore(odsav); - hoc_thisobject = obsav; - hoc_symlist = slsav; - } - pushxm(d); -} - -void hoc_evalpointer(void) /* leave pointer to variable on stack */ -{ - Objectdata* odsav; - Object* obsav = 0; - Symlist* slsav; - double *d=0, *cable_prop_eval_pointer(); - Symbol *sym; - sym = spopm(); - if (sym->public == 2) { - sym = sym->u.sym; - odsav = hoc_objectdata_save(); - obsav = hoc_thisobject; - slsav = hoc_symlist; - hoc_objectdata = hoc_top_level_data; - hoc_thisobject = 0; - hoc_symlist = hoc_top_level_symlist; - } - switch (sym->type) - { - case UNDEF: - execerror("undefined variable", sym->name); - case VAR: -if (!ISARRAY(sym)) { - switch (sym->subtype) { - case USERDOUBLE: - d = sym->u.pval; - break; - case USERINT: - case USERFLOAT: - execerror("can use pointer only to doubles", sym->name); - break; - case DYNAMICUNITS: - d = sym->u.pval + _nrnunit_use_legacy_; - break; -#if CABLE - case USERPROPERTY: - d = cable_prop_eval_pointer(sym); - break; -#endif - default: - d = OPVAL(sym); - break; - } -}else { - switch (sym->subtype) { - case USERDOUBLE: - d = sym->u.pval + araypt(sym, SYMBOL); - break; - case USERINT: - case USERFLOAT: -#if NEMO - case NEMONODE: - case NEMOAREA: -#endif /*NEMO*/ - execerror("can use pointer only to doubles", sym->name); - break; - default: - d = OPVAL(sym) + araypt(sym, OBJECTVAR); - break; - } -} - break; - case AUTO: -#if 0 - execerror("can't use pointer to local variable", sym->name); -#else - d = &(fp->argn[sym->u.u_auto*2].val); -#endif - break; - default: - execerror("attempt to evaluate pointer to a non-variable", sym->name); - } - if (obsav) { - hoc_objectdata = hoc_objectdata_restore(odsav); - hoc_thisobject = obsav; - hoc_symlist = slsav; - } - hoc_pushpx(d); -} - -void add(void) /* add top two elems on stack */ -{ - double d1, d2; - d2 = xpopm(); - d1 = xpopm(); - d1 += d2; - pushxm(d1); -} - -void hoc_sub(void) /* subtract top two elems on stack */ -{ - double d1, d2; - d2 = xpopm(); - d1 = xpopm(); - d1 -= d2; - pushxm(d1); -} - -void mul(void) /* multiply top two elems on stack */ -{ - double d1, d2; - d2 = xpopm(); - d1 = xpopm(); - d1 *= d2; - pushxm(d1); -} - -#if _CRAY -/* - try to do integer division, so that if x is an exact multiple of y - then we really get an integer as the result. - Algorithm: find n such that tx = x * 10^n and ty = y * 10^n are both - integral. If tx/ty leaves no remainder, then tx/ty is the correct - answer and is stored in iptr, intdiv returns true. Otherwise a - floating point division can be done, intdiv returns false. -*/ - -static int intdiv(double x, double y, int* iptr) { - long ix, iy, iz; - int done = 0; - while (!done) - { - if (fabs(x) > (1<<62) || fabs(y) > (1<<62)) - return 0; /* out of range of integers */ - if (x == (long) x && y == (long) y) - done = 1; - else - { - x *= (long double) 10; - y *= (long double) 10; - } - } - ix = (long) x; - iy = (long) y; - iz = ix/iy; - if (ix == iz*iy) - { /* no remainder */ - *iptr = (int) iz; - return 1; - } - return 0; -} -#endif - -void hoc_div(void) /* divide top two elems on stack */ -{ - double d1, d2; - d2 = xpopm(); - if (d2 == 0.0) - execerror("division by zero", (char *) 0); - d1 = xpopm(); -#if _CRAY - { - int i; - if (intdiv(d1, d2, &i)) - d1 = (int) i; /* result is an integer */ - else - d1 = d1/d2; /* result is not an integer */ - } -#else - d1 /= d2; -#endif - pushxm(d1); -} - -void hoc_cyclic(void) /* the modulus function */ -{ - double d1, d2; - double r, q; - d2 = xpopm(); - if (d2 <= 0.) - execerror("a%b, b<=0", (char *) 0); - d1 = xpopm(); - r = d1; - if ( r >= d2) { - q = floor(d1/d2); - r = d1 - q*d2; - } - else if ( r <= -d2) { - q = floor(-d1/d2); - r = d1 + q*d2; - } - if (r > d2) { - r = r - d2; - } - if (r < 0.) { - r = r + d2; - } - - pushxm(r); -} - -void negate(void) /* negate top element on stack */ -{ - double d; - d = xpopm(); - pushxm(-d); -} - -void gt(void) -{ - double d1, d2; - d2 = xpopm(); - d1 = xpopm(); - d1 = (double)(d1 > d2 + EPS); - pushxm(d1); -} - -void lt(void) -{ - double d1, d2; - d2 = xpopm(); - d1 = xpopm(); - d1 = (double)(d1 < d2 - EPS); - pushxm(d1); -} - -void ge(void) -{ - double d1, d2; - d2 = xpopm(); - d1 = xpopm(); - d1 = (double)(d1 >= d2 - EPS); - pushxm(d1); -} - -void le(void) -{ - double d1, d2; - d2 = xpopm(); - d1 = xpopm(); - d1 = (double)(d1 <= d2 + EPS); - pushxm(d1); -} - -void eq(void) -{ - int t1, t2; - double d1=0.0, d2; - t1 = (stackp-1)->i; - t2 = (stackp-3)->i; - switch (t2) { - case NUMBER: - tstkchk(t1, t2); - d2 = xpopm(); - d1 = xpopm(); - d1 = (double)(d1 <= d2 + EPS && d1 >= d2 - EPS); - break; - case STRING: - d1 = (double)(strcmp(*hoc_strpop(), *hoc_strpop()) == 0); - break; - case OBJECTTMP: - case OBJECTVAR: - { Object** o1, **o2; - o1 = hoc_objpop(); - o2 = hoc_objpop(); - d1 = (double)(*o1 == *o2); - hoc_tobj_unref(o1); - hoc_tobj_unref(o2); - } - break; - default: - hoc_execerror("don't know how to compare these types", (char*)0); - } - pushxm(d1); -} - -void ne(void) -{ - int t1, t2; - double d1=0.0, d2; - t1 = (stackp-1)->i; - t2 = (stackp-3)->i; - switch (t1) { - case NUMBER: - tstkchk(t1, t2); - d2 = xpopm(); - d1 = xpopm(); - d1 = (double)(d1 < d2 - EPS || d1 > d2 + EPS); - break; - case STRING: - d1 = (double)(strcmp(*hoc_strpop(), *hoc_strpop()) != 0); - break; - case OBJECTTMP: - case OBJECTVAR: - { Object** o1, **o2; - o1 = hoc_objpop(); - o2 = hoc_objpop(); - d1 = (double)(*o1 != *o2); - hoc_tobj_unref(o1); - hoc_tobj_unref(o2); - } - break; - default: - hoc_execerror("don't know how to compare these types", (char*)0); - } - pushxm(d1); -} - -void hoc_and(void) -{ - double d1, d2; - d2 = xpopm(); - d1 = xpopm(); - d1 = (double)(d1 != 0.0 && d2 != 0.0); - pushxm(d1); -} - -void hoc_or(void) -{ - double d1, d2; - d2 = xpopm(); - d1 = xpopm(); - d1 = (double)(d1 != 0.0 || d2 != 0.0); - pushxm(d1); -} - -void hoc_not(void) -{ - double d; - d = xpopm(); - d = (double)(d == 0.0); - pushxm(d); -} - -void power(void) /* arg1 raised to arg2 */ -{ - double d1, d2; - extern double Pow(); - d2 = xpopm(); - d1 = xpopm(); - d1 = Pow(d1, d2); - pushxm(d1); -} - -void assign(void) /* assign result of execute to top symbol */ -{ - Objectdata* odsav; - Object* obsav = 0; - Symlist* slsav; - int op; - Symbol *sym; - double d2; - op = (pc++)->i; - sym = spopm(); - if (sym->public == 2) { - sym = sym->u.sym; - odsav = hoc_objectdata_save(); - obsav = hoc_thisobject; - slsav = hoc_symlist; - hoc_objectdata = hoc_top_level_data; - hoc_thisobject = 0; - hoc_symlist = hoc_top_level_symlist; - } - d2 = xpopm(); - switch (sym->type) - { - case UNDEF: - hoc_execerror(sym->name, "undefined variable"); - case VAR: -if(!ISARRAY(sym)) { - switch (sym->subtype) { - case USERDOUBLE: - if (op) { - d2 = hoc_opasgn(op, *(sym->u.pval), d2); - } - *(sym->u.pval) = d2; - break; - case USERINT: - if (op) { - d2 = hoc_opasgn(op, (double)(*(sym->u.pvalint)), d2); - } - *(sym->u.pvalint) = (int)(d2 + EPS); - break; -#if CABLE - case USERPROPERTY: - cable_prop_assign(sym, &d2, op); - break; -#endif - case USERFLOAT: - if (op) { - d2 = hoc_opasgn(op, (double)(*(sym->u.pvalfloat)), d2); - } - *(sym->u.pvalfloat) = (float)(d2); - break; - case DYNAMICUNITS: - if (op) { - d2 = hoc_opasgn(op, sym->u.pval[_nrnunit_use_legacy_], d2); - } - sym->u.pval[_nrnunit_use_legacy_] = (float)(d2); - warn_assign_dynam_unit(sym->name); - break; - default: - if (op) { - d2 = hoc_opasgn(op, *(OPVAL(sym)), d2); - } - *(OPVAL(sym)) = d2; - break; - } -}else { - int ind; - switch (sym->subtype) { - case USERDOUBLE: - ind = araypt(sym, SYMBOL); - if (op) { - d2 = hoc_opasgn(op, (sym->u.pval)[ind], d2); - } - (sym->u.pval)[ind] = d2; - break; - case USERINT: - ind = araypt(sym, SYMBOL); - if (op) { - d2 = hoc_opasgn(op, (double)((sym->u.pvalint)[ind]), d2); - } - (sym->u.pvalint)[ind] = (int)(d2 + EPS); - break; - case USERFLOAT: - ind = araypt(sym, SYMBOL); - if (op) { - d2 = hoc_opasgn(op, (double)((sym->u.pvalfloat)[ind]), d2); - } - (sym->u.pvalfloat)[ind] = (float)d2; - break; -#if NEMO - case NEMONODE: - hoc_asgn_nemonode(sym, xpopm(), &d2, op); - break; - case NEMOAREA: - hoc_asgn_nemoarea(sym, xpopm(), &d2, op); - break; -#endif /*NEMO*/ - default: - ind = araypt(sym, OBJECTVAR); - if (op) { - d2 = hoc_opasgn(op, (OPVAL(sym))[ind], d2); - } - (OPVAL(sym))[ind] = d2; - break; - } -} - break; - case AUTO: - if (op) { - d2 = hoc_opasgn(op, fp->argn[sym->u.u_auto*2].val, d2); - } - fp->argn[sym->u.u_auto*2].val = d2; - break; - default: - execerror("assignment to non-variable", sym->name); - } - if (obsav) { - hoc_objectdata = hoc_objectdata_restore(odsav); - hoc_thisobject = obsav; - hoc_symlist = slsav; - } - pushxm(d2); -} - -void hoc_assign_str(char** cpp, const char* buf) { - char* s = *cpp; - *cpp = (char *)emalloc((unsigned)(strlen(buf) + 1)); - Strcpy(*cpp, buf); - if (s) { - hoc_free_string(s); - } -} - -void assstr(void) { /* assign string on top to stack - 1 */ - char **ps1, **ps2; - - ps1 = hoc_strpop(); - ps2 = hoc_strpop(); - hoc_assign_str(ps2, *ps1); -} - -char* hoc_araystr(Symbol* sym, int index, Objectdata* obd) { /* returns array string for multiple dimensions */ - static char name[100]; - char *cp = name+100; - char buf[20]; - int i, n, j, n1; - - *--cp = '\0'; - if (ISARRAY(sym)) { - Arrayinfo* a; - if (sym->subtype == 0) { - a = obd[sym->u.oboff + 1].arayinfo; - }else{ - a = sym->arayinfo; - } - for (i = a->nsub - 1; i >= 0; --i) { - n = a->sub[i]; - j = index%n; - index /= n; - Sprintf(buf, "%d", j); - n1 = strlen(buf); - assert(n1 + 2 < cp - name); - *--cp = ']'; - for (j = n1-1; j >=0; --j) { - *--cp = buf[j]; - } - *--cp = '['; - } - } - return cp; -} - -int hoc_array_index(Symbol* sp, Objectdata* od) { /* subs must be in reverse order on stack */ - int i; - if (ISARRAY(sp)) { - if (sp->subtype == 0) { - Objectdata* sav = hoc_objectdata; - hoc_objectdata = od; - i = araypt(sp, OBJECTVAR); - hoc_objectdata = sav; - }else{ - i = araypt(sp, 0); - } - }else{ - i= 0; - } - return i; -} - -int araypt(Symbol* sp, int type) { /* return subscript - subs in reverse order on stack */ - int i, total, varn; - int d; - register Arrayinfo *aray; - if (type == OBJECTVAR) { - aray = OPARINFO(sp); - }else{ - aray = sp->arayinfo; - } - - total = 0; - for (i = 0; i < aray->nsub; i++) - { - tstkchk((stackp - 2*(aray->nsub - i) + 1)->i, NUMBER); - d = (int)((stackp - 2*(aray->nsub - i))->val + EPS); - if (d < 0 || d >= aray->sub[i]) - execerror("subscript out of range", sp->name); - total = total * (aray->sub[i]) + d; - } - for (i = 0; i< aray->nsub; i++) - nopopm(); - if (do_equation && sp->s_varn != 0 - && (varn = (aray->a_varn)[total]) != 0 && hoc_access[varn] == 0) - { - hoc_access[varn] = var_access; - var_access = varn; - } - return total; -} - -/* obsolete */ -#if CABLE && 0 -int nrnpnt_araypt(Symbol* sp, int pi) { - int i, total; - int d; - register Arrayinfo *aray = sp->arayinfo; - /* the difference is that the first index is for a neuron point - process vector, and the remaining incices are normal vector indices. - the return value is the parameter index and the first - index is returned in pi. return is 0 if not a vector or if element 0. - */ - total = 0; - for (i = 0; i < aray->nsub; i++) - { - tstkchk((stackp - 2*(aray->nsub - i) + 1)->i, NUMBER); - d = (int)((stackp - 2*(aray->nsub - i))->val + EPS); - if (d < 0 || d >= aray->sub[i]) - execerror("subscript out of range", sp->name); - total = total * (aray->sub[i]) + d; - if (i == 0) { - *pi = total; - total = 0; - } - } - for (i = 0; i< aray->nsub; i++) - nopopm(); - return total; -} -#endif - -void print(void) /* pop top value from stack, print it */ -{ -#if defined(__GO32__) - extern int egagrph; - if (egagrph) { - char buf[50]; - sprintf(buf, "\t"); - grx_output_some_chars(buf, strlen(buf)); - prexpr(); - grx_output_some_chars("\n", 1); - }else -#endif - { - nrnpy_pr("\t"); - prexpr(); - nrnpy_pr("\n"); - } -} - -void prexpr(void) /* print numeric value */ -{ - static HocStr* s; - char *hoc_object_name(); - char * ss; -#if CABLE - char* secaccessname(); -#endif - Object** pob; - - if (!s) s = hocstr_create(256); - switch (hoc_stacktype()) { - case NUMBER: - Sprintf(s->buf, "%.8g ", xpopm()); - break; - case STRING: - ss = *(hoc_strpop()); - hocstr_resize(s, strlen(ss) + 1); - Sprintf(s->buf, "%s ", ss); - break; - case OBJECTTMP: - case OBJECTVAR: - pob = hoc_objpop(); - Sprintf(s->buf, "%s ", hoc_object_name(*pob)); - hoc_tobj_unref(pob); - break; -#if 0 && CABLE - case SECTION: - Sprintf(s->buf, "%s ", secaccessname()); - break; -#endif - default: - hoc_execerror("Don't know how to print this type\n", 0); - } - plprint(s->buf); - -} - -void prstr(void) /* print string value */ -{ - static HocStr* s; - char **cpp; - if (!s) s = hocstr_create(256); - cpp = hoc_strpop(); - hocstr_resize(s, strlen(*cpp)+10); - Sprintf(s->buf, "%s", *cpp); - plprint(s->buf); -} - -/*-----------------------------------------------------------------*/ -void hoc_delete_symbol(void) - /* Added 15-JUN-90 by JCW. This routine deletes a - "defined-on-the-fly" variable from the symbol - list. */ - /* modified greatly by Hines. Very unsafe in general. */ -{ -#if 1 - /*---- local variables -----*/ - Symbol * doomed, - * sp; - /*---- start function ------*/ - - /* copy address of the symbol that will be deleted */ - doomed = (pc++)->sym; - -#endif -/* hoc_execerror("delete_symbol doesn't work right now.", (char *)0);*/ -#if 1 - if (doomed->type == UNDEF) - fprintf(stderr, "%s: no such variable\n", doomed->name); - else if (doomed->defined_on_the_fly == 0) - fprintf(stderr, "%s: can't be deleted\n", doomed->name); - else { - hoc_free_symspace(doomed); - } -#endif -} -/*----------------------------------------------------------*/ - -void hoc_newline(void) /* print newline */ -{ - plprint("\n"); -} - -void varread(void) /* read into variable */ -{ - double d=0.0; - extern NrnFILEWrap *fin; - Symbol *var = (pc++)->sym; - - assert(var->public != 2); - if (! ((var->type == VAR || var->type == UNDEF) && !ISARRAY(var) - && var->subtype == NOTUSER - ) - ) { - execerror(var->name, "is not a scalar variable"); - } - Again: - switch (nrn_fw_fscanf(fin, "%lf", OPVAL(var))) - { - case EOF: - if (moreinput()) - goto Again; - d = *(OPVAL(var)) = 0.0; - break; - case 0: - execerror("non-number read into", var->name); - break; - default: - d = 1.0; - break; - } - var->type = VAR; - pushxm(d); -} - - -static Inst* codechk(void) { - if (progp >= prog+NPROG-1) - execerror("procedure too big", (char *) 0); - if (zzdebug) - debugzz(progp); - return progp++; -} - -Inst* Code(Pfrv f) { /* install one instruction or operand */ - progp->pf = f; - return codechk(); -} - -Inst* codei(int f) -{ - progp->pf = NULL;/* zero high order bits to avoid debugzz problem */ - progp->i = f; - return codechk(); -} - -Inst* hoc_codeptr(void* vp) -{ - progp->ptr = vp; - return codechk(); -} - -void codesym(Symbol* f) -{ - progp->sym = f; - IGNORE(codechk()); -} - -void codein(Inst* f) -{ - progp->in = f; - IGNORE(codechk()); -} - -void insertcode(Inst* begin, Inst* end, Pfrv f) -{ - Inst *i; - for (i = end - 1; i != begin; i--) { - *i = *(i - 1); - } - begin->pf = f; - - if(zzdebug) { - Inst* p; - printf("insert code: what follows is the entire code so far\n"); - for (p = prog; p < progp; ++p) { - debugzz(p); - } - printf("end of insert code debugging\n"); - } -} - -#if defined(DOS) || defined(__GO32__) || defined (WIN32) || (MAC && !defined(DARWIN)) -static int ntimes; -#endif - -void execute(Inst* p) /* run the machine */ -{ - Inst *pcsav; - - BBSPOLL - for (pc = p; pc->in != STOP && !hoc_returning; ) - { -#if defined(DOS) - if (++ntimes > 10) { - ntimes = 0; -#if 0 - kbhit(); /* DOS can't capture interrupt when number crunching*/ -#endif - } -#endif -#if defined(__GO32__) || (defined(WIN32) && !defined(CYGWIN)) - if (++ntimes > 10) { - ntimes = 0; - hoc_check_intupt(1); - } -#endif -#if MAC && !defined(DARWIN) - /* there is significant overhead here */ - if (++ntimes > 100) { - ntimes = 0; - hoc_check_intupt(1); - } -#endif - if (intset) - execerror("interrupted", (char *)0); - /* (*((pc++)->pf))(); DEC 5000 increments pc after the return!*/ - pcsav = pc++; - (*((pcsav)->pf))(); - } -} diff --git a/src/oc/code.cpp b/src/oc/code.cpp index 61434c8dca..9707ac7c01 100755 --- a/src/oc/code.cpp +++ b/src/oc/code.cpp @@ -243,7 +243,7 @@ void hoc_unref_defer(void) { printf("hoc_unref_defer %s %d\n", hoc_object_name(unref_defer_), unref_defer_->refcount); #endif hoc_obj_unref(unref_defer_); - unref_defer_ = nullptr; + unref_defer_ = (Object*)0; } } @@ -540,51 +540,48 @@ int hoc_ParseExec(int yystart) { Datum *sstackp, *sstack; Symlist *sp_symlist; - if (yystart) { - sframe = rframe; - sfp = fp; - sprogbase = progbase; - sprogp = progp; - spc = pc, - sprog_parse_recover = prog_parse_recover; - sstackp = stackp; - sstack = rstack; - sp_symlist = p_symlist; - rframe = fp; - rstack = stackp; - progbase = progp; - p_symlist = (Symlist *) 0; - } - - if (yystart) { - rinitcode(); - } - if (hoc_in_yyparse) { - hoc_execerror("Cannot reenter parser.", - "Maybe you were in the middle of a direct command."); - } - yret = yyparse(); - switch (yret) { - case 1: - execute(progbase); - rinitcode(); - break; - case -3 : - hoc_execerror("incomplete statement parse not allowed\n", (char *) 0); - default: - break; - } - if (yystart) { - rframe = sframe; - fp = sfp; - progbase = sprogbase; - progp = sprogp; - pc = spc; - prog_parse_recover = sprog_parse_recover; - stackp = sstackp; - rstack = sstack; - p_symlist = sp_symlist; - } + if (yystart) { + sframe=rframe;sfp=fp; + sprogbase=progbase; sprogp=progp; spc=pc, + sprog_parse_recover=prog_parse_recover; + sstackp=stackp; sstack=rstack; + sp_symlist=p_symlist; + rframe = fp; + rstack = stackp; + progbase = progp; + p_symlist = (Symlist *)0; + } + + if (yystart) { + rinitcode(); + } + if (hoc_in_yyparse) { + hoc_execerror("Cannot reenter parser.", + "Maybe you were in the middle of a direct command."); + } + yret = yyparse(); + switch (yret) { + case 1: + execute(progbase); + rinitcode(); + break; + case 'e': + hoc_edit(); + for (rinitcode(); hoc_yyparse(); rinitcode()) { + execute(progbase); + } + break; + case -3 : + hoc_execerror("incomplete statement parse not allowed\n", (char*)0); + default: + break; + } + if (yystart) { + rframe=sframe; fp=sfp; + progbase=sprogbase; progp=sprogp; pc=spc; + prog_parse_recover=sprog_parse_recover; + stackp=sstackp; rstack=sstack; p_symlist=sp_symlist; + } return yret; } @@ -592,44 +589,38 @@ int hoc_ParseExec(int yystart) { int hoc_xopen_run(Symbol *sp, const char *str) { /*recursively parse and execute for xopen*/ /* if sp != 0 then parse string and save code */ /* without executing. Note str must be a 'list'*/ - int n = 0; - Frame *sframe = rframe, *sfp = fp; - Inst *sprogbase = progbase, *sprogp = progp, *spc = pc, - *sprog_parse_recover = prog_parse_recover; - Datum *sstackp = stackp, *sstack = rstack; - Symlist *sp_symlist = p_symlist; - rframe = fp; - rstack = stackp; - progbase = progp; - p_symlist = (Symlist *) 0; - - if (sp == (Symbol *) 0) { - for (rinitcode(); hoc_yyparse(); rinitcode()) - execute(progbase); - } else { - int savpipeflag; - rinitcode(); - savpipeflag = hoc_pipeflag; - hoc_pipeflag = 2; - parsestr = str; - if (!hoc_yyparse()) { - execerror("Nothing to parse", (char *) 0); - } - n = (int) (progp - progbase); - hoc_pipeflag = savpipeflag; - hoc_define(sp); - rinitcode(); - } - rframe = sframe; - fp = sfp; - progbase = sprogbase; - progp = sprogp; - pc = spc; - prog_parse_recover = sprog_parse_recover; - stackp = sstackp; - rstack = sstack; - p_symlist = sp_symlist; - return n; + int n=0; + Frame *sframe=rframe, *sfp=fp; + Inst *sprogbase=progbase, *sprogp=progp, *spc=pc, + *sprog_parse_recover=prog_parse_recover; + Datum *sstackp=stackp, *sstack=rstack; + Symlist *sp_symlist=p_symlist; + rframe = fp; + rstack = stackp; + progbase = progp; + p_symlist = (Symlist *)0; + + if (sp == (Symbol *)0) { + for (rinitcode(); hoc_yyparse(); rinitcode()) + execute(progbase); + }else{ int savpipeflag; + rinitcode(); + savpipeflag = hoc_pipeflag; + hoc_pipeflag = 2; + parsestr=str; + if(!hoc_yyparse()) { + execerror("Nothing to parse", (char *)0); + } + n = (int)(progp-progbase); + hoc_pipeflag = savpipeflag; + hoc_define(sp); + rinitcode(); + } + rframe=sframe; fp=sfp; + progbase=sprogbase; progp=sprogp; pc=spc; + prog_parse_recover=sprog_parse_recover; + stackp=sstackp; rstack=sstack; p_symlist=sp_symlist; + return n; } #define HOC_TEMP_CHARPTR_SIZE 128 @@ -953,6 +944,18 @@ void forcode(void) { pc = relative(savepc + 1); /* next statement */ } +static void warn_assign_dynam_unit(const char* name) { + static int first = 1; + if (first) { + char mes[100]; + first = 0; + sprintf(mes, "Assignment to %s physical constant %s", + _nrnunit_use_legacy_ ? "legacy" : "modern", + name); + hoc_warning(mes, NULL); + } +} + void shortfor(void) { Inst *savepc = pc; double begin, end, *pval = 0; @@ -972,6 +975,9 @@ void shortfor(void) { execerror("integer iteration variable", sym->name); } else if (sym->subtype == USERDOUBLE) { pval = sym->u.pval; + }else if (sym->subtype == DYNAMICUNITS) { + pval = sym->u.pval + _nrnunit_use_legacy_; + warn_assign_dynam_unit(sym->name); } else { pval = OPVAL(sym); } @@ -1046,7 +1052,7 @@ void hoc_iterator_object( stackp += sym->u.u_proc->nauto * 2; /* clear the autoobject pointers */ for (i = sym->u.u_proc->nobjauto; i > 0; --i) { - stackp[-2 * i].obj = nullptr; + stackp[-2*i].obj = (Object*)0; } fp->iter_stmt_begin = beginpc; fp->iter_stmt_ob = ob; @@ -1142,12 +1148,16 @@ static void for_segment2(Symbol *sym, int mode) { hoc_execerror(sym->name, "undefined variable"); case VAR: if (!ISARRAY(sym)) { - if (sym->subtype == USERINT) + if (sym->subtype == USERINT) { execerror("integer iteration variable", sym->name); - else if (sym->subtype == USERDOUBLE) + }else if (sym->subtype == USERDOUBLE){ pval = sym->u.pval; - else + }else if (sym->subtype == DYNAMICUNITS) { + pval = sym->u.pval + _nrnunit_use_legacy_; + warn_assign_dynam_unit(sym->name); + }else{ pval = OPVAL(sym); + } break; } else { if (sym->subtype == USERINT) @@ -1391,7 +1401,7 @@ void call(void) /* call a function */ STACKCHK /* clear the autoobject pointers. */ for (i = sp->u.u_proc->nobjauto; i > 0; --i) { - stackp[-2 * i].obj = nullptr; + stackp[-2*i].obj = (Object*)0; } if (sp->cpublic == 2) { Objectdata *odsav = hoc_objectdata_save(); @@ -1828,6 +1838,9 @@ void eval(void) /* evaluate variable on stack */ case USERINT: d = (double) (*(sym->u.pvalint)); break; + case DYNAMICUNITS: + d = sym->u.pval[_nrnunit_use_legacy_]; + break; #if CABLE case USERPROPERTY: d = cable_prop_eval(sym); @@ -1911,6 +1924,9 @@ void hoc_evalpointer(void) /* leave pointer to variable on stack */ case USERFLOAT: execerror("can use pointer only to doubles", sym->name); break; + case DYNAMICUNITS: + d = sym->u.pval + _nrnunit_use_legacy_; + break; #if CABLE case USERPROPERTY: d = cable_prop_eval_pointer(sym); @@ -2123,14 +2139,14 @@ void eq(void) { d1 = (double) (strcmp(*hoc_strpop(), *hoc_strpop()) == 0); break; case OBJECTTMP: - case OBJECTVAR: { - Object **o1, **o2; - o1 = hoc_objpop(); - o2 = hoc_objpop(); - d1 = (double) (*o1 == *o2); - hoc_tobj_unref(o1); - hoc_tobj_unref(o2); - } + case OBJECTVAR: + { Object** o1, **o2; + o1 = hoc_objpop(); + o2 = hoc_objpop(); + d1 = (double) (*o1 == *o2); + hoc_tobj_unref(o1); + hoc_tobj_unref(o2); + } break; default: hoc_execerror("don't know how to compare these types", (char *) 0); @@ -2154,8 +2170,8 @@ void ne(void) { d1 = (double) (strcmp(*hoc_strpop(), *hoc_strpop()) != 0); break; case OBJECTTMP: - case OBJECTVAR: { - Object **o1, **o2; + case OBJECTVAR: + { Object** o1, **o2; o1 = hoc_objpop(); o2 = hoc_objpop(); d1 = (double) (*o1 != *o2); @@ -2250,6 +2266,13 @@ void assign(void) /* assign result of execute to top symbol */ d2 = hoc_opasgn(op, (double) (*(sym->u.pvalfloat)), d2); } *(sym->u.pvalfloat) = (float) (d2); + break; + case DYNAMICUNITS: + if (op) { + d2 = hoc_opasgn(op, sym->u.pval[_nrnunit_use_legacy_], d2); + } + sym->u.pval[_nrnunit_use_legacy_] = (float)(d2); + warn_assign_dynam_unit(sym->name); break; default: if (op) { @@ -2580,9 +2603,8 @@ void varread(void) /* read into variable */ static Inst *codechk(void) { if (progp >= prog + NPROG - 1) execerror("procedure too big", (char *) 0); - if (zzdebug) { + if (zzdebug) debugzz(progp); - } return progp++; } diff --git a/src/oc/hoc_init.c b/src/oc/hoc_init.c deleted file mode 100755 index 7a8b6f3925..0000000000 --- a/src/oc/hoc_init.c +++ /dev/null @@ -1,420 +0,0 @@ -#include <../../nrnconf.h> -/* /local/src/master/nrn/src/oc/hoc_init.c,v 1.25 1999/11/08 17:48:58 hines Exp */ - -#include "hoc.h" -#include "parse.h" -#include -#include "equation.h" -#include "nrnunits_modern.h" - -#include "ocfunc.h" -extern void hoc_nrnmpi_init(); - -#if PVM -extern int numprocs(), myproc(), psync(); -#endif -#if 0 -extern int hoc_co(); -#endif -#if DOS || defined(WIN32) /*|| defined(MAC)*/ -extern double erf(), erfc(); /* supplied by unix */ -#endif -#if defined(WIN32) -extern void hoc_winio_show(int b); -#endif - -#if MAC -static double Fabs(x) double x; { return (x>0.) ? x : -x; } -static double Erf(x) double x; { return erf(x); } -static double Erfc(x) double x; { return erfc(x); } -#endif - -static struct { /* Keywords */ - char *name; - int kval; -} keywords[] = { - "proc", parsePROC, - "func", FUNC, - "obfunc", HOCOBJFUNC, - "return", RETURN, - "break", BREAK, - "continue", CONTINUE, - "stop", STOPSTMT, - "if", IF, - "else", ELSE, - "while", WHILE, - "for", FOR, - "print", PRINT, - "delete", parseDELETE, - "read", READ, - "debug", DEBUG, - "double", parseDOUBLE, - "em", EDIT, - "depvar", DEPENDENT, - "eqn", EQUATION, - "local", LOCAL, - "localobj", LOCALOBJ, - "strdef", STRDEF, - "parallel", PARALLEL, - "help", HELP, - "iterator", ITERKEYWORD, - "iterator_statement", ITERSTMT, -#if CABLE - "create", SECTIONKEYWORD, - "connect", CONNECTKEYWORD, - "setpointer", SETPOINTERKEYWORD, - "access", ACCESSKEYWORD, - "insert", INSERTKEYWORD, - "uninsert", UNINSERTKEYWORD, - "forall", FORALL, - "ifsec", IFSEC, - "forsec", FORSEC, -#endif /*CABLE*/ -#if OOP - "begintemplate", BEGINTEMPLATE, - "endtemplate", ENDTEMPLATE, - "objectvar", OBJVARDECL, - "objref", OBJVARDECL, - "public", PUBLICDECL, - "external", EXTERNALDECL, - "new", NEW, -#endif - 0, 0 -}; -static struct { /* Constants */ - char *name; - double cval; -} consts[] = { - "PI", 3.14159265358979323846, - "E", 2.71828182845904523536, - "GAMMA",0.57721566490153286060, /* Euler */ - "DEG", 57.29577951308232087680, /* deg/radian */ - "PHI", 1.61803398874989484820, /* golden ratio */ - 0, 0 -}; - -/* Nov, 2017, from https://physics.nist.gov/cuu/Constants/index.html */ -/* also see FARADAY and gasconstant in ../nrnoc/eion.c */ -static struct { /* Modern, Legacy units constants */ - char *name; - double cval[2]; -} uconsts[] = { - "FARADAY", {_faraday_codata2018, 96485.309}, /*coulombs/mole*/ - "R", {_gasconstant_codata2018, 8.31441}, /*molar gas constant, joules/mole/deg-K*/ - "Avogadro_constant", {_avogadro_number_codata2018, 6.02214129e23}, /* note that the legacy value in nrnunits.lib.in is 6.022169+23 */ - 0, {0., 0.} -}; - -static struct { /* Built-ins */ - char *name; - double (*func)(); -} builtins[] = { - "sin", sin, - "cos", cos, - "atan", atan, - "tanh", tanh, - "log", Log, /* checks argument */ - "log10",Log10, /* checks argument */ - "exp", hoc1_Exp, /* checks argument */ - "sqrt", Sqrt, /* checks argument */ - "int", integer, -#if MAC - "abs", Fabs, - "erf", Erf, - "erfc", Erfc, -#else - "abs", fabs, - "erf", erf, - "erfc", erfc, -#endif - 0, 0 -}; -static struct { /* Builtin functions with multiple or variable args */ - char *name; - void (*fun_blt)(void); -} fun_bltin[] = { - "atan2", hoc_atan2, - "system", hoc_System, - "prmat", hoc_Prmat, - "solve", hoc_solve, - "eqinit", hoc_eqinit, - "plt", hoc_Plt, - "axis", hoc_axis, - "plot", hoc_Plot, - "plotx", hoc_plotx, - "ploty", hoc_ploty, - "regraph", hoc_regraph, - "symbols", hoc_symbols, - "printf", hoc_PRintf, - "xred", hoc_Xred, - "sred", hoc_Sred, - "ropen", hoc_ropen, - "wopen", hoc_wopen, - "xopen", hoc_xopen, - "hoc_stdout", hoc_stdout, - "chdir", hoc_Chdir, - "fprint", hoc_Fprint, - "fscan", hoc_Fscan, - "sscanf", hoc_sscanf, - "sprint", hoc_Sprint, - "graph", hoc_Graph, - "graphmode", hoc_Graphmode, - "fmenu", hoc_fmenu, - "lw", hoc_Lw, - "getstr", hoc_Getstr, - "strcmp", hoc_Strcmp, - "setcolor", hoc_Setcolor, - "startsw", hoc_startsw, - "stopsw", hoc_stopsw, - "object_id", hoc_object_id, - "allobjectvars", hoc_allobjectvars, - "allobjects", hoc_allobjects, - "xpanel", hoc_xpanel, - "xbutton", hoc_xbutton, - "xcheckbox", hoc_xcheckbox, - "xstatebutton", hoc_xstatebutton, - "xlabel", hoc_xlabel, - "xmenu", hoc_xmenu, - "xvalue", hoc_xvalue, - "xpvalue", hoc_xpvalue, - "xradiobutton", hoc_xradiobutton, - "xfixedvalue", hoc_xfixedvalue, - "xvarlabel", hoc_xvarlabel, - "xslider", hoc_xslider, - "boolean_dialog", hoc_boolean_dialog, - "continue_dialog", hoc_continue_dialog, - "string_dialog", hoc_string_dialog, - "doEvents", hoc_single_event_run, - "doNotify", hoc_notify_iv, - "nrniv_bind_thread", nrniv_bind_thread, - "ivoc_style", ivoc_style, - "numarg", hoc_Numarg, - "argtype", hoc_Argtype, - "hoc_pointer_", hoc_pointer, /* for internal use */ - "nrn_mallinfo", hoc_mallinfo, - "execute", hoc_exec_cmd, - "execute1", hoc_execute1, - "load_proc", hoc_load_proc, - "load_func", hoc_load_func, - "load_template", hoc_load_template, - "load_file", hoc_load_file, - "load_java", hoc_load_java, - "unix_mac_pc", hoc_unix_mac_pc, - "show_winio", hoc_show_winio, - "nrn_load_dll", hoc_nrn_load_dll, - "machine_name", hoc_machine_name, - "saveaudit", hoc_Saveaudit, - "retrieveaudit", hoc_Retrieveaudit, - "coredump_on_error", hoc_coredump_on_error, - "checkpoint", hoc_checkpoint, - "quit", hoc_quit, - "object_push", hoc_object_push, - "object_pop", hoc_object_pop, - "pwman_place", hoc_pwman_place, - "save_session", hoc_save_session, - "print_session", hoc_print_session, - "show_errmess_always", hoc_show_errmess_always, - "execerror", hoc_Execerror, - "variable_domain", hoc_Symbol_limits, - "name_declared", hoc_name_declared, - "use_mcell_ran4", hoc_usemcran4, - "mcell_ran4", hoc_mcran4, - "mcell_ran4_init", hoc_mcran4init, - "nrn_feenableexcept", nrn_feenableexcept, - "nrnmpi_init", hoc_nrnmpi_init, -#if PVM - "numprocs", numprocs, - "myproc", myproc, - "psync", psync, -#endif -#if DOS - "settext", hoc_settext, -#endif -#if defined(WIN32) - "WinExec", hoc_win_exec, -#endif - 0, 0 -}; - -static struct { /* functions that return a string */ - char *name; - void (*strfun_blt)(void); -} strfun_bltin[] = { - "secname", hoc_secname, - "units", hoc_Symbol_units, - "neuronhome", hoc_neuronhome, - "getcwd", hoc_getcwd, - "nrnversion", hoc_nrnversion, - 0, 0 -}; - -static struct { /* functions that return an object */ - char *name; - void (*objfun_blt)(void); -} objfun_bltin[] = { - "object_pushed", hoc_object_pushed, - 0, 0 -}; - -double hoc_epsilon = 1.e-11; -double hoc_ac_; /*known to the interpreter to evaluate expressions with hoc_oc() */ -double* hoc_varpointer; /* executing hoc_pointer(&var) will put the address of - the variable in this location */ - -double hoc_cross_x_, hoc_cross_y_; /* For Graph class in ivoc */ -double hoc_default_dll_loaded_; - -char* neuron_home; -char* nrn_mech_dll; /* but actually only for NEURON mswin and linux */ -int nrn_noauto_dlopen_nrnmech; /* 0 except when binary special. */ -int use_mcell_ran4_; -int nrn_xopen_broadcast_; -int _nrnunit_use_legacy_; /* allow dynamic switching between legacy and modern units */ - -void hoc_init(void) /* install constants and built-ins table */ -{ - int i; - Symbol *s; - -#if defined(DYNAMIC_UNITS_USE_LEGACY_DEFAULT) - _nrnunit_use_legacy_ = 1; /* legacy as default */ -#else - _nrnunit_use_legacy_ = 0; /* new units as default */ -#endif - { /* but check the environment variable if it exists */ - const char* envvar = getenv("NRNUNIT_USE_LEGACY"); - if (envvar) { - if (strcmp(envvar, "1") == 0) { - _nrnunit_use_legacy_ = 1; - }else if (strcmp(envvar, "0") == 0) { - _nrnunit_use_legacy_ = 0; - } - } - } - - use_mcell_ran4_ = 0; - nrn_xopen_broadcast_ = 255; - hoc_init_space(); - for (i = 0; keywords[i].name; i++) - IGNORE(install(keywords[i].name, keywords[i].kval, 0.0, &symlist)); - for (i = 0; consts[i].name; i++) { - s = install(consts[i].name, UNDEF, consts[i].cval, &symlist); - s->type = VAR; - s->u.pval = &consts[i].cval; - s->subtype = USERDOUBLE; - } - for (i = 0; uconsts[i].name; i++) { - s = install(uconsts[i].name, UNDEF, uconsts[i].cval[0], &symlist); - s->type = VAR; - s->u.pval = &uconsts[i].cval[0]; - s->subtype = DYNAMICUNITS; - } - for (i = 0; builtins[i].name; i++) - { - s = install(builtins[i].name, BLTIN, 0.0, &symlist); - s->u.ptr = builtins[i].func; - } - for (i = 0; fun_bltin[i].name; i++) - { - s = install(fun_bltin[i].name, FUN_BLTIN, 0.0, &symlist); - s->u.u_proc->defn.pf = fun_bltin[i].fun_blt; - s->u.u_proc->nauto = 0; - s->u.u_proc->nobjauto = 0; - } - for (i = 0; strfun_bltin[i].name; i++) - { - s = install(strfun_bltin[i].name, FUN_BLTIN, 0.0, &symlist); - s->type = STRINGFUNC; - s->u.u_proc->defn.pf = strfun_bltin[i].strfun_blt; - s->u.u_proc->nauto = 0; - s->u.u_proc->nobjauto = 0; - } - for (i = 0; objfun_bltin[i].name; i++) - { - s = install(objfun_bltin[i].name, FUN_BLTIN, 0.0, &symlist); - s->type = OBJECTFUNC; - s->u.u_proc->defn.pf = objfun_bltin[i].objfun_blt; - s->u.u_proc->nauto = 0; - } - /* hoc_ac_ is a way to evaluate an expression using the interpreter */ - hoc_install_var("hoc_ac_", &hoc_ac_); - hoc_install_var("float_epsilon", &hoc_epsilon); - hoc_install_var("hoc_cross_x_", &hoc_cross_x_); - hoc_install_var("hoc_cross_y_", &hoc_cross_y_); - hoc_install_var("default_dll_loaded_", &hoc_default_dll_loaded_); - - s = install("xopen_broadcast_", UNDEF, 0.0, &hoc_symlist); - s->type = VAR; - s->subtype = USERINT; - s->u.pvalint = &nrn_xopen_broadcast_; - - /* initialize pointers ( why doesn't Vax do this?) */ - hoc_access = (int *)0; - spinit(); -#if OOP - hoc_class_registration(); - hoc_built_in_symlist = symlist; - symlist = (Symlist *)0; - /* start symlist and top level the same list */ - hoc_top_level_symlist = symlist = (Symlist *)emalloc(sizeof(Symlist)); - symlist->first = symlist->last = (Symbol *)0; - hoc_install_hoc_obj(); -#endif -} - -void hoc_unix_mac_pc(void) { - hoc_ret(); -#if defined(DARWIN) - hoc_pushx(4.); -#else -#if MAC - hoc_pushx(2.); -#else -#if defined(WIN32) - hoc_pushx(3.); -#else - hoc_pushx(1.); -#endif -#endif -#endif -} -void hoc_show_winio(void) { - int b; - b = (int)chkarg(1, 0., 1.); -#if MAC - hoc_sioux_show(b); -#endif -#if defined(WIN32) - hoc_winio_show(b); -#endif - hoc_ret(); - hoc_pushx(0.); -} - -int nrn_main_launch; - -void hoc_nrnversion(void) { - extern char* nrn_version(); - static char* p; - int i; - i = 1; - if (ifarg(1)) { - i = (int)chkarg(1, 0., 20.); - } - hoc_ret(); - p = nrn_version(i); - hoc_pushstr(&p); -} - -void hoc_Execerror(void) { - char* c2 = (char*)0; - if (ifarg(2)) { - c2 = gargstr(2); - } - if (ifarg(1)) { - hoc_execerror(gargstr(1), c2); - }else{ - hoc_execerror_mes(c2, c2, 0); - } - /* never get here */ -} diff --git a/src/oc/hoc_init.cpp b/src/oc/hoc_init.cpp index 722fa0910c..d4f54b2834 100755 --- a/src/oc/hoc_init.cpp +++ b/src/oc/hoc_init.cpp @@ -5,6 +5,7 @@ #include "parse.hpp" #include #include "equation.h" +#include "nrnunits_modern.h" #include "ocfunc.h" @@ -91,18 +92,21 @@ static struct { /* Constants */ "GAMMA",0.57721566490153286060, /* Euler */ "DEG", 57.29577951308232087680, /* deg/radian */ "PHI", 1.61803398874989484820, /* golden ratio */ -#if defined(LegacyFR) && LegacyFR == 1 - "FARADAY", 96485.309, /*coulombs/mole*/ - "R", 8.31441, /*molar gas constant, joules/mole/deg-K*/ -#else - /* Nov, 2017, from https://physics.nist.gov/cuu/Constants/index.html */ - /* also see FARADAY and gasconstant in ../nrnoc/eion.cpp */ - "FARADAY", 96485.33289, /*coulombs/mole*/ - "R", 8.3144598, /*molar gas constant, joules/mole/deg-K*/ -#endif 0, 0 }; + /* Nov, 2017, from https://physics.nist.gov/cuu/Constants/index.html */ +/* also see FARADAY and gasconstant in ../nrnoc/eion.c */ +static struct { /* Modern, Legacy units constants */ + char *name; + double cval[2]; +} uconsts[] = { + "FARADAY", {_faraday_codata2018, 96485.309}, /*coulombs/mole*/ + "R", {_gasconstant_codata2018, 8.31441}, /*molar gas constant, joules/mole/deg-K*/ + "Avogadro_constant", {_avogadro_number_codata2018, 6.02214129e23}, /* note that the legacy value in nrnunits.lib.in is 6.022169+23 */ + 0, {0., 0.} +}; + static struct { /* Built-ins */ char *name; double (*func)(double); @@ -267,12 +271,29 @@ char* nrn_mech_dll; /* but actually only for NEURON mswin and linux */ int nrn_noauto_dlopen_nrnmech; /* 0 except when binary special. */ int use_mcell_ran4_; int nrn_xopen_broadcast_; +int _nrnunit_use_legacy_; /* allow dynamic switching between legacy and modern units */ void hoc_init(void) /* install constants and built-ins table */ { int i; Symbol *s; +#if defined(DYNAMIC_UNITS_USE_LEGACY_DEFAULT) + _nrnunit_use_legacy_ = 1; /* legacy as default */ +#else + _nrnunit_use_legacy_ = 0; /* new units as default */ +#endif + { /* but check the environment variable if it exists */ + const char* envvar = getenv("NRNUNIT_USE_LEGACY"); + if (envvar) { + if (strcmp(envvar, "1") == 0) { + _nrnunit_use_legacy_ = 1; + }else if (strcmp(envvar, "0") == 0) { + _nrnunit_use_legacy_ = 0; + } + } + } + use_mcell_ran4_ = 0; nrn_xopen_broadcast_ = 255; extern void hoc_init_space(void); @@ -285,6 +306,12 @@ void hoc_init(void) /* install constants and built-ins table */ s->u.pval = &consts[i].cval; s->subtype = USERDOUBLE; } + for (i = 0; uconsts[i].name; i++) { + s = install(uconsts[i].name, UNDEF, uconsts[i].cval[0], &symlist); + s->type = VAR; + s->u.pval = &uconsts[i].cval[0]; + s->subtype = DYNAMICUNITS; + } for (i = 0; builtins[i].name; i++) { s = install(builtins[i].name, BLTIN, 0.0, &symlist); diff --git a/src/oc/hocedit.cpp b/src/oc/hocedit.cpp index 248e1ea9f0..2ace3a34c5 100755 --- a/src/oc/hocedit.cpp +++ b/src/oc/hocedit.cpp @@ -6,7 +6,7 @@ hocedit.c,v * Revision 1.6 1999/07/03 14:20:24 hines * no limit on input string size or execute strings. * (although an execute string could overrun the program buffer if - * it generates more than NPROG instructions, see code.c) + * it generates more than NPROG instructions, see code.cpp) * * Revision 1.5 1997/03/21 21:28:33 hines * syntax errors now give correct file and line number message diff --git a/src/oc/oc_ansi.h b/src/oc/oc_ansi.h index e998b2f866..24c01b8c6a 100644 --- a/src/oc/oc_ansi.h +++ b/src/oc/oc_ansi.h @@ -1,8 +1,6 @@ #ifndef oc_ansi_h #define oc_ansi_h -#include - /** * \dir @@ -183,7 +181,6 @@ extern void hoc_spec_table(void** pfunctable, int n); extern void* hoc_sec_internal_name2ptr(const char* s, int eflag); extern void* hoc_pysec_name2ptr(const char* s, int eflag); extern void* nrn_parsing_pysec_; -extern int _nrnunit_use_legacy_; /* 1:legacy, 0:modern (default) */ extern void vector_append(IvocVect*, double); extern IvocVect* vector_new(int, Object*); /*use this if possible*/ @@ -287,6 +284,7 @@ extern int nrn_isdouble(double*, double, double); } #endif +extern int _nrnunit_use_legacy_; /* 1:legacy, 0:modern (default) */ extern void bbs_done(void); extern int hoc_main1(int, const char**, const char**); extern char* cxx_char_alloc(size_t size); From adca6dce3493fdcafad329495e14168e098f9456 Mon Sep 17 00:00:00 2001 From: Pramod Kumbhar Date: Wed, 28 Oct 2020 20:54:25 +0100 Subject: [PATCH 05/17] Revert accidental changed to hh.mod --- src/nrnoc/hh.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nrnoc/hh.mod b/src/nrnoc/hh.mod index e5c16f6e93..2fb3adb848 100644 --- a/src/nrnoc/hh.mod +++ b/src/nrnoc/hh.mod @@ -29,7 +29,7 @@ NEURON { NONSPECIFIC_CURRENT il RANGE gnabar, gkbar, gl, el, gna, gk : `GLOBAL minf` will be replaced with `RANGE minf` if CoreNEURON enabled - RANGE minf, hinf, ninf, mtau, htau, ntau + GLOBAL minf, hinf, ninf, mtau, htau, ntau THREADSAFE : assigned GLOBALs will be per thread } @@ -93,7 +93,7 @@ PROCEDURE rates(v(mV)) { :Computes rate and other constants at current v. :Call once from HOC to initialize inf at resting v. LOCAL alpha, beta, sum, q10 : `TABLE minf` will be replaced with `:TABLE minf` if CoreNEURON enabled) - :TABLE minf, mtau, hinf, htau, ninf, ntau DEPEND celsius FROM -100 TO 100 WITH 200 + TABLE minf, mtau, hinf, htau, ninf, ntau DEPEND celsius FROM -100 TO 100 WITH 200 UNITSOFF q10 = 3^((celsius - 6.3)/10) From 5bfa3cc033eb0bd5c8979cd13283016432023f82 Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Thu, 29 Oct 2020 11:30:38 +0100 Subject: [PATCH 06/17] CR --- m4/withmpi.m4 | 3 + src/gnu/d_vec.cpp | 4 +- src/ivoc/graph.cpp | 5 +- src/ivoc/ivocmain.cpp | 4 +- src/ivoc/ivocrand.cpp | 6 +- src/ivoc/ivocvect.cpp | 18 +++--- src/ivoc/macmain.cpp | 1 - src/ivoc/matrix.cpp | 2 +- src/ivoc/mlinedit.cpp | 2 +- src/ivoc/nrnmutdec.h | 2 +- src/ivoc/ocbox.cpp | 2 +- src/ivoc/ocfile.cpp | 6 +- src/ivoc/ochelp.cpp | 1 - src/ivoc/oclist.cpp | 2 +- src/ivoc/ocptrvector.cpp | 2 +- src/ivoc/pwman.cpp | 2 +- src/ivoc/strfun.cpp | 2 +- src/modlunit/declare.cpp | 12 ++-- src/modlunit/init.cpp | 9 ++- src/modlunit/kinunit.cpp | 12 ++-- src/modlunit/lex.lpp | 8 +-- src/modlunit/list.cpp | 4 +- src/modlunit/modlunit.h | 2 +- src/modlunit/nrnunit.cpp | 10 +-- src/modlunit/parse1.ypp | 2 +- src/modlunit/units.cpp | 2 +- src/modlunit/units1.cpp | 10 +-- src/nmodl/deriv.cpp | 10 +-- src/nmodl/discrete.cpp | 2 +- src/nmodl/extdef5.h | 2 +- src/nmodl/io.cpp | 2 +- src/nmodl/kinetic.cpp | 18 +++--- src/nmodl/lex.lpp | 4 +- src/nmodl/list.cpp | 6 +- src/nmodl/modl.cpp | 2 +- src/nmodl/nmodlfunc.h | 2 +- src/nmodl/noccout.cpp | 4 +- src/nmodl/nocpout.cpp | 20 +++--- src/nmodl/parsact.cpp | 8 +-- src/nmodl/parse1.ypp | 86 +++++++++++++------------- src/nmodl/partial.cpp | 4 +- src/nmodl/solve.cpp | 17 +++-- src/nmodl/symbol.cpp | 4 +- src/nrncvode/cvodeobj.cpp | 2 +- src/nrncvode/netcvode.cpp | 8 +-- src/nrniv/cxprop.cpp | 9 +-- src/nrniv/multisplit.cpp | 4 ++ src/nrniv/nrnmenu.cpp | 2 +- src/nrniv/nrnste.cpp | 2 +- src/nrnjava/nrnccmb/NrnKSChan.java | 4 +- src/nrnmpi/Makefile.am | 3 +- src/nrnmpi/bbsmpipack.cpp | 4 +- src/nrnoc/cabcode.cpp | 10 +-- src/nrnoc/clamp.cpp | 1 - src/nrnoc/eion.cpp | 7 +-- src/nrnoc/fadvance.cpp | 9 ++- src/nrnoc/fstim.cpp | 1 - src/nrnoc/hocprax.cpp | 5 +- src/nrnoc/nrncvode.h | 2 +- src/nrnoc/nrniv_mf.h | 6 -- src/nrnoc/passive0.cpp | 2 - src/nrnoc/point.cpp | 8 +-- src/nrnoc/secref.cpp | 4 +- src/nrnoc/solve.cpp | 12 ++-- src/nrnoc/synapse.cpp | 1 - src/nrnoc/treeset.cpp | 8 +-- src/nrnpython/Makefile.am | 2 +- src/nrnpython/inithoc.cpp | 1 - src/nrnpython/nrnpy_hoc.cpp | 4 +- src/nrnpython/nrnpy_p2h.cpp | 2 +- src/nrnpython/nrnpython.cpp | 2 +- src/nrnpython/nrnpython_config.h.in | 2 +- src/nrnpython/rxd.cpp | 4 -- src/nrnpython/rxd.h | 6 +- src/nrnpython/rxd_extracellular.cpp | 2 - src/nrnpython/rxd_intracellular.cpp | 2 - src/oc/code.cpp | 2 - src/oc/code2.cpp | 11 +--- src/oc/fileio.cpp | 2 - src/oc/hoc.cpp | 14 +++-- src/oc/hoc_oop.cpp | 41 ++++++------ src/oc/hocdec.h | 4 ++ src/oc/hocedit.cpp | 1 - src/oc/hoclist.h | 1 - src/oc/oc_ansi.h | 6 -- src/oc/ocmisc.h | 3 - src/oc/parallel.cpp | 3 +- src/oc/plt.cpp | 3 - src/oc/redef.h | 4 -- src/parallel/bbslsrv.cpp | 4 +- src/sundials/shared/nvector_parallel.c | 4 +- src/uxnrnbbs/nrnbbs.cpp | 1 - test/unit_tests/oc/hoc_interpreter.cpp | 2 - test/unit_tests/unit_test.cpp | 2 - 94 files changed, 248 insertions(+), 327 deletions(-) diff --git a/m4/withmpi.m4 b/m4/withmpi.m4 index 0c887f04bb..b27c58b56d 100755 --- a/m4/withmpi.m4 +++ b/m4/withmpi.m4 @@ -1,6 +1,7 @@ AC_DEFUN([AC_NRN_WITH_MPI],[ MPICCnrnmpi=$CC +MPICXXnrnmpi=$CXX AC_ARG_WITH(mpi, AC_HELP_STRING([--with-mpi],[Also compile the parallel code in src/sundials/shared]) @@ -32,6 +33,7 @@ dnl AC_SUBST(LIBTOOL) MPICXX="$CXX" fi MPICCnrnmpi=$MPICC + MPICXXnrnmpi=$MPICXX LIBTOOLTAG='--tag=CC' dnl AC_SUBST(CC) dnl AC_SUBST(CXX) @@ -189,6 +191,7 @@ AC_SUBST(METISOBJADD) AC_SUBST(METISLIBADD) AC_SUBST(METISLIB) AC_SUBST(MPICCnrnmpi) +AC_SUBST(MPICXXnrnmpi) ])dnl end of AC_NRN_WITH_METIS diff --git a/src/gnu/d_vec.cpp b/src/gnu/d_vec.cpp index 17040bae7d..f7f1cf4d5e 100755 --- a/src/gnu/d_vec.cpp +++ b/src/gnu/d_vec.cpp @@ -38,9 +38,7 @@ int operator != (doubleVec& a, doubleVec& b) // error handling -extern "C" { - extern void hoc_execerror(const char*, const char*); -} // extern "C" +extern "C" void hoc_execerror(const char*, const char*); void default_doubleVec_error_handler(const char* msg) { diff --git a/src/ivoc/graph.cpp b/src/ivoc/graph.cpp index f41e09b1b1..11ae95a69b 100644 --- a/src/ivoc/graph.cpp +++ b/src/ivoc/graph.cpp @@ -6,7 +6,7 @@ #include #include -extern /*"C"*/ int hoc_return_type_code; +extern int hoc_return_type_code; #if HAVE_IV #include @@ -1182,7 +1182,7 @@ IFGUI ENDGUI return (void*)g; #else - return nullptr; + return (void*)0; #endif /* HAVE_IV */ } static void gr_destruct(void* v) { @@ -1595,6 +1595,7 @@ void Graph::draw(Canvas* c, const Allocation& a) const { long i, cnt = line_list_.count(); //if (!extension_flushed_) { Scene::draw(c, a); +//} if (extension_flushed_) { for (i = 0; i < cnt; ++i) { line_list_.item(i)->extension()->draw(c, a); diff --git a/src/ivoc/ivocmain.cpp b/src/ivoc/ivocmain.cpp index 6e50190197..41fa9019b2 100644 --- a/src/ivoc/ivocmain.cpp +++ b/src/ivoc/ivocmain.cpp @@ -6,7 +6,7 @@ long hoc_nframe, hoc_nstack; #if !HAVE_IV #define Session void int hoc_main1(int, const char**, const char**); - void hoc_main1_init(const char*, const char**); +void hoc_main1_init(const char*, const char**); #endif #include @@ -276,7 +276,7 @@ void mac_open_app(){ #pragma export on #endif -// int ivocmain(int, const char**, const char**); + int ivocmain(int, const char**, const char**); int ivocmain_session(int, const char**, const char**, int start_session); int (*p_neosim_main)(int, const char**, const char**); extern int nrn_global_argc; diff --git a/src/ivoc/ivocrand.cpp b/src/ivoc/ivocrand.cpp index 28b4e5865d..8d268fc0f9 100755 --- a/src/ivoc/ivocrand.cpp +++ b/src/ivoc/ivocrand.cpp @@ -59,12 +59,12 @@ implementPtrList(RandomPlayList, RandomPlay) static RandomPlayList* random_play_list_; extern "C" { -//double nrn_random_pick(Rand* r); +double nrn_random_pick(Rand* r); void nrn_random_reset(Rand* r); -//Rand* nrn_random_arg(int); +Rand* nrn_random_arg(int); long nrn_get_random_sequence(Rand* r); void nrn_set_random_sequence(Rand* r, long seq); -//int nrn_random_isran123(Rand* r, uint32_t* id1, uint32_t* id2, uint32_t* id3); +int nrn_random_isran123(Rand* r, uint32_t* id1, uint32_t* id2, uint32_t* id3); } // extern "C" #include diff --git a/src/ivoc/ivocvect.cpp b/src/ivoc/ivocvect.cpp index eaa56881f9..d535dddc40 100644 --- a/src/ivoc/ivocvect.cpp +++ b/src/ivoc/ivocvect.cpp @@ -144,7 +144,7 @@ extern int nrn_mlh_gsort (double* vec, int *base_ptr, int total_elems, doubleCom extern int vector_arg_px(int, double**); extern void notify_freed_val_array(double*, size_t); -extern /*"C"*/ int hoc_return_type_code; +extern int hoc_return_type_code; IvocVect::IvocVect(Object* o) : ParentVect(){obj_ = o; label_ = NULL; MUTCONSTRUCT(0)} IvocVect::IvocVect(int l, Object* o) : ParentVect(l){obj_ = o; label_ = NULL; MUTCONSTRUCT(0)} @@ -1245,9 +1245,9 @@ static Object** v_smhist(void* v) { v1->fill(0.,0,size); for (i=0;i EPSILON) v1->elem(i) = ans[i]; - free( series); - free( gauss); - free( ans); + free(series); + free(gauss); + free(ans); return v1->temp_objvar(); } @@ -2663,11 +2663,11 @@ Label3:; } for(i=0;i -extern /*"C"*/ int hoc_return_type_code; +extern int hoc_return_type_code; #include diff --git a/src/ivoc/nrnmutdec.h b/src/ivoc/nrnmutdec.h index 1f1133a13f..ce28825a89 100644 --- a/src/ivoc/nrnmutdec.h +++ b/src/ivoc/nrnmutdec.h @@ -18,7 +18,7 @@ #define MUTDESTRUCT {if (mut_){pthread_mutex_destroy(mut_); delete mut_; mut_ = (pthread_mutex_t*)0;}} #else #define MUTCONSTRUCT(mkmut) {if (mkmut) {mut_ = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(mut_, 0);}else{mut_ = 0;}} -#define MUTDESTRUCT {if (mut_){pthread_mutex_destroy(mut_); free(mut_); mut_ = (pthread_mutex_t*)0;}} +#define MUTDESTRUCT {if (mut_){pthread_mutex_destroy(mut_); free(mut_); mut_ = NULL;}} #endif #define MUTLOCK {if (mut_) {pthread_mutex_lock(mut_);}} #define MUTUNLOCK {if (mut_) {pthread_mutex_unlock(mut_);}} diff --git a/src/ivoc/ocbox.cpp b/src/ivoc/ocbox.cpp index c707a40211..3fb5f4edf3 100644 --- a/src/ivoc/ocbox.cpp +++ b/src/ivoc/ocbox.cpp @@ -24,7 +24,7 @@ #include "gui-redirect.h" -extern /*"C"*/ int hoc_return_type_code; +extern int hoc_return_type_code; extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); extern double (*nrnpy_object_to_double_)(Object*); diff --git a/src/ivoc/ocfile.cpp b/src/ivoc/ocfile.cpp index 3f2ec71b7d..6a2f1b09d8 100644 --- a/src/ivoc/ocfile.cpp +++ b/src/ivoc/ocfile.cpp @@ -9,7 +9,7 @@ #include #endif -extern /*"C"*/ int hoc_return_type_code; +extern int hoc_return_type_code; #ifdef WIN32 #include @@ -180,7 +180,7 @@ static double f_flush(void* v){ static const char** f_get_name(void* v){ OcFile* f = (OcFile*)v; char** ps = hoc_temp_charptr(); - *ps = (char*)f->get_name(); + *ps = (char*)f->get_name(); if (ifarg(1)) { hoc_assign_str(hoc_pgargstr(1), *ps); } @@ -250,7 +250,7 @@ static double f_vread(void* v){ OcFile* f = (OcFile*)v; size_t n = 1; if (ifarg(2)) n = int(chkarg(1, 1., 2.e18)); - double* x = hoc_pgetarg(ifarg(2)+1); + char* x = (char*)hoc_pgetarg(ifarg(2)+1); BinaryMode(f) return (double)fread(x,sizeof(double),n,f->file()); } diff --git a/src/ivoc/ochelp.cpp b/src/ivoc/ochelp.cpp index 9a0283f9ac..6e0d7e3dd6 100644 --- a/src/ivoc/ochelp.cpp +++ b/src/ivoc/ochelp.cpp @@ -29,7 +29,6 @@ static FILE* help_pipe; //#include "../uxnrnbbs/nrnbbs.h" #endif -//extern void ivoc_help(const char*); extern const char* hoc_current_xopen(); declareList(CopyStringList, CopyString) diff --git a/src/ivoc/oclist.cpp b/src/ivoc/oclist.cpp index 6b66a0021f..5133de10cd 100644 --- a/src/ivoc/oclist.cpp +++ b/src/ivoc/oclist.cpp @@ -35,7 +35,7 @@ extern "C" Object* ivoc_list_item(Object*, int); extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); extern double (*nrnpy_object_to_double_)(Object*); -extern /*"C"*/ int hoc_return_type_code; +extern int hoc_return_type_code; void handle_old_focus(); diff --git a/src/ivoc/ocptrvector.cpp b/src/ivoc/ocptrvector.cpp index 517221f74d..84a018638d 100644 --- a/src/ivoc/ocptrvector.cpp +++ b/src/ivoc/ocptrvector.cpp @@ -22,7 +22,7 @@ extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); extern double (*nrnpy_object_to_double_)(Object*); -extern /*"C"*/ int hoc_return_type_code; +extern int hoc_return_type_code; static double dummy; diff --git a/src/ivoc/pwman.cpp b/src/ivoc/pwman.cpp index 35e9dde68b..b7b96feed3 100644 --- a/src/ivoc/pwman.cpp +++ b/src/ivoc/pwman.cpp @@ -2,7 +2,7 @@ #include "gui-redirect.h" extern char* ivoc_get_temp_file(); -extern /*"C"*/ int hoc_return_type_code; +extern int hoc_return_type_code; #if HAVE_IV #if (MAC && !defined(carbon)) || defined(WIN32) diff --git a/src/ivoc/strfun.cpp b/src/ivoc/strfun.cpp index 8e56af0160..3aacf9561d 100644 --- a/src/ivoc/strfun.cpp +++ b/src/ivoc/strfun.cpp @@ -19,7 +19,7 @@ extern Objectdata* hoc_top_level_data; extern Symlist* hoc_built_in_symlist; extern int nrn_is_artificial(int); -extern /*"C"*/ int hoc_return_type_code; +extern int hoc_return_type_code; inline unsigned long key_to_hash(String& s) {return s.hash();} implementTable(SymbolTable, String, Symbol*) diff --git a/src/modlunit/declare.cpp b/src/modlunit/declare.cpp index 781a94aab4..de2aec7a87 100755 --- a/src/modlunit/declare.cpp +++ b/src/modlunit/declare.cpp @@ -165,12 +165,12 @@ void declare_implied() Item* name, *units, *from, *to, *with, *num; save = intoken; intoken = newlist(); - name = putintoken( "t", NAME, 0); - units = putintoken( "ms", STRING, UNITS); - from = putintoken( "0", INTEGER, INTEGER); - to = putintoken( "1", INTEGER, INTEGER); - with = putintoken( "WITH", NAME, 0); - num = putintoken( "1", INTEGER, INTEGER); + name = putintoken("t", NAME, 0); + units = putintoken("ms", STRING, UNITS); + from = putintoken("0", INTEGER, INTEGER); + to = putintoken("1", INTEGER, INTEGER); + with = putintoken("WITH", NAME, 0); + num = putintoken("1", INTEGER, INTEGER); qa = itemarray(8, name, units, from, to, with, num, ITEM0, ITEM0); declare(INDEP, ITMA(qa)[0], qa); intoken = save; diff --git a/src/modlunit/init.cpp b/src/modlunit/init.cpp index 542bb96ab3..8fa27528f0 100755 --- a/src/modlunit/init.cpp +++ b/src/modlunit/init.cpp @@ -146,11 +146,10 @@ static struct { /* numerical methods */ "sparse", KINF, 0, "derivimplicit", DERF, 0, /* name hard wired in deriv.c */ "cnexp", DERF, 0, - "clsoda", DERF | KINF, 0, /* Tolerance built in to -scopgear.c */ - "after_cvode", 0, 0, - "cvode_t", 0, 0, - "cvode_t_v", 0, 0, + "clsoda", DERF | KINF, 0, /* Tolerance built in to scopgear.c */ + "after_cvode", 0, 0, + "cvode_t", 0, 0, + "cvode_t_v", 0, 0, 0, 0, 0 }; diff --git a/src/modlunit/kinunit.cpp b/src/modlunit/kinunit.cpp index 6a121f14a6..f82c040419 100755 --- a/src/modlunit/kinunit.cpp +++ b/src/modlunit/kinunit.cpp @@ -92,12 +92,12 @@ static void set_flux_units(unit* up) Symbol *s; Sprintf(buf, "%s", Unit_str(up)); - if ((s = lookup( "f_flux")) == SYM0) { - s = install( "f_flux", NAME); + if ((s = lookup("f_flux")) == SYM0) { + s = install("f_flux", NAME); } s->u.str = stralloc(buf, (char *)0); - if ((s = lookup( "b_flux")) == SYM0) { - s = install( "b_flux", NAME); + if ((s = lookup("b_flux")) == SYM0) { + s = install("b_flux", NAME); } s->u.str = stralloc(buf, (char *)0); @@ -139,13 +139,13 @@ void unit_ldifuslist(Item* q, int flag) if (!ustr) { diag(SYM(q)->name, "not declared in previous COMPARTMENT"); } - Unit_push( "micron4/ms"); + Unit_push("micron4/ms"); if (!unit_cmp_exact()) { unit_pop(); diag(unit_str(), ": relevant area * diffusion constant must\n be micron2 micron2/ms (1-21 m4/s)"); } unit_pop(); - Unit_push( "micron2"); + Unit_push("micron2"); Unit_push(ustr); if (!unit_cmp_exact()) { diag(ustr, ": With LONGDITUDINAL_DIFFUSION the compartment \ diff --git a/src/modlunit/lex.lpp b/src/modlunit/lex.lpp index d027f76699..ca70af2f9c 100755 --- a/src/modlunit/lex.lpp +++ b/src/modlunit/lex.lpp @@ -126,14 +126,14 @@ E [Ee][-+]?{D}+ [ \t]+ { putintoken(yytext, SPACE, SPACE);} -\r\n { putintoken( "\n", NEWLINE, 0);} -\r { putintoken( "\n", NEWLINE, 0);} +\r\n { putintoken("\n", NEWLINE, 0);} +\r { putintoken("\n", NEWLINE, 0);} \n { putintoken(yytext, NEWLINE, 0);} [:\?].* { putintoken(yytext, STRING, STUFF);} -\{ { yylval.qp = putintoken( "{", 0, '{'); return yytext[0]; } -\} { yylval.qp = putintoken( "}", 0, '}'); return yytext[0]; } +\{ { yylval.qp = putintoken("{", 0, '{'); return yytext[0]; } +\} { yylval.qp = putintoken("}", 0, '}'); return yytext[0]; } . { yylval.qp = putintoken(yytext, 0, yytext[0]); return yytext[0]; } ENDCOMMENT { diff --git a/src/modlunit/list.cpp b/src/modlunit/list.cpp index 9fb89c2fd3..0ccce823dc 100755 --- a/src/modlunit/list.cpp +++ b/src/modlunit/list.cpp @@ -169,7 +169,7 @@ lappenditem(List* list, Item* item) return insertitem(list, item); } -void dlete(Item* item) +void remove(Item* item) { assert(item->itemtype); /* can't delete list */ item->next->prev = item->prev; @@ -266,7 +266,7 @@ putintoken(char* s, short type, short toktype) Fprintf(stderr, "%s|", s); } if (s == (char *)0) - diag( "internal error", " in putintoken"); + diag("internal error", " in putintoken"); switch (type) { case STRING: diff --git a/src/modlunit/modlunit.h b/src/modlunit/modlunit.h index 37b8522d9c..7beaa4953c 100644 --- a/src/modlunit/modlunit.h +++ b/src/modlunit/modlunit.h @@ -15,7 +15,7 @@ void declare_array(Symbol*); void declare_implied(); void declare_indep(Symbol*); void define_value(Item* q1, Item* q2); -void dlete(Item*); +void remove(Item *item); void deltokens(Item* q1, Item* q2); void diag(char*, char*); void dimensionless(); diff --git a/src/modlunit/nrnunit.cpp b/src/modlunit/nrnunit.cpp index 4ce680938f..012bd9229e 100755 --- a/src/modlunit/nrnunit.cpp +++ b/src/modlunit/nrnunit.cpp @@ -26,12 +26,12 @@ void nrn_unit_init() { void nrn_unit_chk() { Item *q; - unit_chk("v", "millivolt"); - unit_chk("t", "ms"); - unit_chk("dt", "ms"); + unit_chk("v", "millivolt"); + unit_chk("t", "ms"); + unit_chk("dt", "ms"); unit_chk("celsius", "degC"); - unit_chk("diam", "micron"); - unit_chk("area", "micron2"); + unit_chk("diam", "micron"); + unit_chk("area", "micron2"); if (breakpoint_local_seen_ == 0 || conductance_seen_ == 0) { ITERATE(q, current) { diff --git a/src/modlunit/parse1.ypp b/src/modlunit/parse1.ypp index ed282e3f1b..0ababfc278 100755 --- a/src/modlunit/parse1.ypp +++ b/src/modlunit/parse1.ypp @@ -503,7 +503,7 @@ expr: varname {P3{unit_push($1);}} | expr LE expr {P3{unit_logic(2, $1, $2, lastok);}} | expr EQ expr {P3{unit_logic(2, $1, $2, lastok);}} | expr NE expr {P3{unit_logic(2, $1, $2, lastok);}} - | NOT expr {P3{unit_pop(); Unit_push( "");}} + | NOT expr {P3{unit_pop(); Unit_push("");}} | '-' expr %prec UNARYMINUS | error {myerr("Illegal expression");} ; diff --git a/src/modlunit/units.cpp b/src/modlunit/units.cpp index 597d681ff3..7a9d793c89 100755 --- a/src/modlunit/units.cpp +++ b/src/modlunit/units.cpp @@ -87,7 +87,7 @@ void chkfperror(); void units(unit*); int pu(int, int, int); int convr(unit*); -void units_cpp_init(); //TODO - was this init() used somewhere else? avoiding duplicate symbol: nmold/init.cpp init() +void units_cpp_init(); int get(); extern void Unit_push(char*); diff --git a/src/modlunit/units1.cpp b/src/modlunit/units1.cpp index 5dd4af53be..0774d4c090 100755 --- a/src/modlunit/units1.cpp +++ b/src/modlunit/units1.cpp @@ -56,13 +56,13 @@ void unit_exponent(Item* y, Item* lastok) /*x ^ y*/ assert(i == 1); if (yval - (double)((int)yval)) { unit_less(); - Unit_push( ""); + Unit_push(""); } else { Unit_exponent((int)yval); } }else{ unit_less(); - Unit_push( ""); + Unit_push(""); } } @@ -103,7 +103,7 @@ void unit_logic(int type, Item* q1, Item* q2, Item* q3) unit_pop(); } unit_pop(); - Unit_push( ""); + Unit_push(""); } #define NLEVEL 10 /* 10 levels of call! */ @@ -173,12 +173,12 @@ void unit_del(int i) /* push 1/delta_x ^ i units */ Symbol *s; char *cp; - s = lookup( "delta_x"); + s = lookup("delta_x"); if(!s) { diag("delta_x not declared", (char *)0); } cp = decode_units(s); - Unit_push( ""); + Unit_push(""); while(i--) { Unit_push(cp); unit_div(); diff --git a/src/nmodl/deriv.cpp b/src/nmodl/deriv.cpp index d7c072b7d2..2806b45382 100755 --- a/src/nmodl/deriv.cpp +++ b/src/nmodl/deriv.cpp @@ -515,7 +515,7 @@ Sprintf(buf, "static int _slist%d[%d], _dlist%d[%d];\n", lappendstr(procfunc, "return _reset;\n}\n"); /* don't emit _ode_matsol if the user has defined cvodematsol */ - if (!lookup( "cvodematsol")) { + if (!lookup("cvodematsol")) { Item* qq; Item* qextra = q1->next->next->next->next; Sprintf(buf, "static int _ode_matsol%d", numlist); @@ -597,7 +597,7 @@ Sprintf(buf, "static int _slist%d[%d], _dlist%d[%d];\n", Sprintf(buf, "{int _id; for(_id=0; _id < %d; _id++) {\n\ if (_deriv%d_advance) {\n", count, numlist); Insertstr(q4, buf); - sp = install( "D", STRING); + sp = install("D", STRING); sp->araydim = count; /*this breaks SENS*/ q = insertsym(q4, sp); eqnqueue(q); @@ -776,7 +776,7 @@ void matchmassage(int nderiv) s = SYM(q); ITERATE(q1, deriv_state_list) { if (SYM(q1) == s) { - dlete(q1); + remove(q1); break; } } @@ -1034,7 +1034,7 @@ int cvode_cnexp_success(Item* q1, Item* q2) { /* convert Method to nil and the type of the block to PROCEDURE */ SYM(cvode_cnexp_solve->next)->name = stralloc("cnexp", 0); - dlete(deriv_imp_list->next); + remove(deriv_imp_list->next); /* replace the Dstate = f(state) equations */ qeq = cvode_eqn->next; @@ -1066,7 +1066,7 @@ sprintf(buf," %s = %s + (1. - exp(dt*(%s)))*(%s - %s)", q2 = q2->next; for(q3=q1->prev->prev; q3 != q2; q3 = q4) { q4 = q3->next; - dlete(q3); + remove(q3); } } diff --git a/src/nmodl/discrete.cpp b/src/nmodl/discrete.cpp index 3797bed3d7..037c8d39cd 100755 --- a/src/nmodl/discrete.cpp +++ b/src/nmodl/discrete.cpp @@ -84,7 +84,7 @@ void disc_var_seen(Item* q1, Item* q2, Item* q3, int array) /*NAME '@' NUMBER -- } Sprintf(buf, "__%s", s->name); replacstr(q1, buf); - dlete(q2); + remove(q2); Sprintf(buf, "[%d]", num); replacstr(q3, buf); } diff --git a/src/nmodl/extdef5.h b/src/nmodl/extdef5.h index fb3170b6b8..850e79729d 100755 --- a/src/nmodl/extdef5.h +++ b/src/nmodl/extdef5.h @@ -1,4 +1,4 @@ -(char*)"force", +"force", "deflate", "expfit", "derivs", diff --git a/src/nmodl/io.cpp b/src/nmodl/io.cpp index 6497869ee3..9b42bc62a8 100755 --- a/src/nmodl/io.cpp +++ b/src/nmodl/io.cpp @@ -437,7 +437,7 @@ static void pop_file_stack() { lappendstr(filetxtlist, buf); FileStackItem* fsi; fsi = (FileStackItem*)(SYM(filestack->prev)); - dlete(filestack->prev); + remove(filestack->prev); linenum = fsi->linenum; inlinep = fsi->inlinep; fclose(fin); diff --git a/src/nmodl/kinetic.cpp b/src/nmodl/kinetic.cpp index 58148157c5..95415aa941 100755 --- a/src/nmodl/kinetic.cpp +++ b/src/nmodl/kinetic.cpp @@ -1202,7 +1202,7 @@ compart: COMPARTMENT NAME ',' expr '{' namelist '}' {massagecompart($4, $5, $7, SYM($2));} | COMPARTMENT expr '{' namelist '}' {massagecompart($2, $3, $5, SYM0);} - | COMPARTMENT error {myerr( "Correct syntax is: \ + | COMPARTMENT error {myerr("Correct syntax is: \ COMPARTMENT index, expr { vectorstates }\n\ COMPARTMENT expr { scalarstates }");} ; @@ -1243,7 +1243,7 @@ void massagecompart(Item* qexp, Item* qb1, Item* qb2, Symbol* indx) for (q = qb1->next; q != qb2; q = qs) { qs = q->next; if (!(SYM(q)->subtype & STAT) && in_solvefor(SYM(q))) { - dlete(q); + remove(q); #if 0 diag(SYM(q)->name, "must be a (solved) STATE in a COMPARTMENT statement"); #endif @@ -1287,7 +1287,7 @@ void massageldifus(Item* qexp, Item* qb1, Item* qb2, Symbol* indx) s = SYM(q); s2 = SYM0; if (!(s->subtype & STAT) && in_solvefor(s)) { - dlete(q); + remove(q); diag(SYM(q)->name, "must be a (solved) STATE in a LONGITUDINAL_DIFFUSION statement"); } lappendsym(ldifuslist, s); @@ -1431,7 +1431,7 @@ prn(cvode_sbegin, cvode_send); while (ITM(q) != q2) { assert(q2 != cvode_send); /* past the list */ q2 = q2->next; - dlete(q2->prev); + remove(q2->prev); } q2 = q2->next; } @@ -1475,7 +1475,7 @@ void cvode_kinetic(Item* qsol, Symbol* fun, int numeqn, int listnum) if (done_list) for (q = done_list->next; q != done_list; q = qn) { qn = q->next; if (SYM(q) == fun) { - dlete(q); + remove(q); } } kinetic_intmethod(fun, "NEURON's CVode"); @@ -1529,11 +1529,11 @@ void cvode_kinetic(Item* qsol, Symbol* fun, int numeqn, int listnum) /* delete the statement */ while (q->itemtype != SYMBOL || SYM(q)->name[0] != ';') { qnext = q->next; - dlete(q); + remove(q); q = qnext; } qnext = q->next; - dlete(q); + remove(q); } } #endif @@ -1641,11 +1641,11 @@ return; /* delete the statement */ while (q->itemtype != SYMBOL || SYM(q)->name[0] != ';') { qnext = q->next; - dlete(q); + remove(q); q = qnext; } qnext = q->next; - dlete(q); + remove(q); } } #endif diff --git a/src/nmodl/lex.lpp b/src/nmodl/lex.lpp index 2cde58bac4..b57905cd22 100755 --- a/src/nmodl/lex.lpp +++ b/src/nmodl/lex.lpp @@ -242,8 +242,8 @@ REPRESENTS { \?.* {/*ignore inline comments*/;} -\{ { yylval.qp = putintoken( "{", 0); return yytext[0]; } -\} { yylval.qp = putintoken( "}", 0); return yytext[0]; } +\{ { yylval.qp = putintoken("{", 0); return yytext[0]; } +\} { yylval.qp = putintoken("}", 0); return yytext[0]; } . { yylval.qp = putintoken(yytext, 0); return yytext[0]; } %% diff --git a/src/nmodl/list.cpp b/src/nmodl/list.cpp index 71d3d5e98a..c963dce25d 100755 --- a/src/nmodl/list.cpp +++ b/src/nmodl/list.cpp @@ -217,7 +217,7 @@ Item *lappendlst(List* list, List* lst) return insertlist(list, lst); } -void dlete(Item *item) +void remove(Item *item) { assert(item->itemtype); /* can't delete list */ item->next->prev = item->prev; @@ -256,9 +256,9 @@ void deltokens(Item* q1, Item* q2) /* delete tokens from q1 to q2 */ Item *q; for (q = q1; q != q2;) { q = q->next; - dlete(q->prev); + remove(q->prev); } - dlete(q2); + remove(q2); } diff --git a/src/nmodl/modl.cpp b/src/nmodl/modl.cpp index c610c8c8c8..cbfe1418fa 100755 --- a/src/nmodl/modl.cpp +++ b/src/nmodl/modl.cpp @@ -317,5 +317,5 @@ static std::string str_replace(std::string str, const std::string& search_str, c void verbatim_adjust(char* q) { const std::string repl = str_replace(q, "u.template", "u.ctemplate"); - Fprintf(fcout, "%s", repl.c_str()); + Fprintf(fcout, "%s\n", repl.c_str()); } \ No newline at end of file diff --git a/src/nmodl/nmodlfunc.h b/src/nmodl/nmodlfunc.h index 01c4260f2c..60bbe73fd9 100644 --- a/src/nmodl/nmodlfunc.h +++ b/src/nmodl/nmodlfunc.h @@ -58,7 +58,7 @@ void prn(Item* q1, Item* q2); void cvode_kinetic(Item* qsol, Symbol* fun, int numeqn, int listnum); void single_channel(Item* qsol, Symbol* fun, int numeqn, int listnum); void freelist(List**); -void dlete(Item*); +void remove(Item*); void deltokens(Item*, Item*); void move(Item* q1, Item* q2, Item* q3); void movelist(Item* q1, Item* q2, List* s); diff --git a/src/nmodl/noccout.cpp b/src/nmodl/noccout.cpp index d36c0d9d6d..d4e0bde654 100755 --- a/src/nmodl/noccout.cpp +++ b/src/nmodl/noccout.cpp @@ -991,7 +991,7 @@ static void conductance_cout() { ITERATE(q, m) { if (q->itemtype == SYMBOL) { if (strcmp(SYM(q)->name, "{") == 0) { - dlete(q); + remove(q); break; } } @@ -1000,7 +1000,7 @@ static void conductance_cout() { for (q = m->prev; q != m; q = q->prev) { if (q->itemtype == SYMBOL) { if (strcmp(SYM(q)->name, "}") == 0) { - dlete(q); + remove(q); break; } } diff --git a/src/nmodl/nocpout.cpp b/src/nmodl/nocpout.cpp index cbb9e5e340..3ae9fdd4ef 100755 --- a/src/nmodl/nocpout.cpp +++ b/src/nmodl/nocpout.cpp @@ -214,7 +214,7 @@ void nrninit() { useion = newlist(); nrnpointers = newlist(); using_default_indep = 0; - indepinstall(install( "t", NAME), "0", "1", "100", (Item*)0, "ms", 0); + indepinstall(install("t", NAME), "0", "1", "100", (Item*)0, "ms", 0); using_default_indep = 1; debugging_ = 1; thread_cleanup_list = newlist(); @@ -1197,13 +1197,13 @@ if (_nd->_extnode) {\n\ lst = get_ion_variables(0); if (lst->next != lst->prev) { move(lst->next, lst->prev, ITM(q)); - freelist(&lst); //TODO - check this List** + freelist((List**)lst); } q = q->next; lst = set_ion_variables(0); if (lst->next != lst->prev) { move(lst->next, lst->prev, ITM(q)); - freelist(&lst); //TODO - check this List** + freelist((List**)lst); } q = q->next; sprintf(buf, "\thoc_reg_ba(_mechtype, _ba%d, %s);\n", i, STR(q)); @@ -1756,13 +1756,13 @@ void nrndeclare() { Symbol *s; Item *q; - s=lookup( "diam"); if (s) { + s=lookup("diam"); if (s) { if (s->nrntype & (NRNRANGE|NRNGLOBAL)) { diag(s->name, "cannot be a RANGE or GLOBAL variable for this mechanism"); } s->nrntype |= NRNNOTP|NRNPRANGEIN; diamdec=1; } - s=lookup( "area"); if (s) { + s=lookup("area"); if (s) { if (s->nrntype & (NRNRANGE|NRNGLOBAL)) { diag(s->name, "cannot be a RANGE or GLOBAL variable for this mechanism"); } @@ -1784,9 +1784,9 @@ diag(s->name, "cannot be a RANGE or GLOBAL variable for this mechanism"); s->nrntype |= NRNEXTRN | NRNNOTP; vectorize_substitute(lappendstr(defs_list, "\n#define t nrn_threads->_t\n#define dt nrn_threads->_dt\n"), "\n#define t _nt->_t\n#define dt _nt->_dt\n"); - s=lookup( "usetable"); if (s) { s->nrntype |= NRNGLOBAL | NRNNOTP;} - s=lookup( "celsius");if(s){s->nrntype |= NRNEXTRN | NRNNOTP;} - s=lookup( "celcius"); if (s) diag("celcius should be spelled celsius", + s=lookup("usetable"); if (s) { s->nrntype |= NRNGLOBAL | NRNNOTP;} + s=lookup("celsius");if(s){s->nrntype |= NRNEXTRN | NRNNOTP;} + s=lookup("celcius"); if (s) diag("celcius should be spelled celsius", (char *)0); ITERATE(q, syminorder) { @@ -1828,7 +1828,7 @@ void del_range(List* range) q1 = q->next; s = SYM(q); if (s->nrntype & (NRNPRANGEIN | NRNPRANGEOUT)) { - dlete(q); + remove(q); } } } @@ -2589,7 +2589,7 @@ void net_receive(Item* qarg, Item* qp1, Item* qp2, Item* qstmt, Item* qend) called between integrator steps and before a re_init But no need to do so if it is not used. */ - Symbol* vsym = lookup( "v"); + Symbol* vsym = lookup("v"); netrec_need_v = 1; for (q = qstmt; q != qend; q = q->next) { if (q->itemtype == SYMBOL && SYM(q) == vsym) { diff --git a/src/nmodl/parsact.cpp b/src/nmodl/parsact.cpp index 8358ce8cf3..0d7ba8e4d6 100755 --- a/src/nmodl/parsact.cpp +++ b/src/nmodl/parsact.cpp @@ -421,10 +421,10 @@ void lag_stmt(Item* q1, int blocktype) /* LAG name1 BY name2 */ /*ARGSUSED*/ /* parse */ name1 = SYM(q1->next); - dlete(q1->next); - dlete(q1->next); + remove(q1->next); + remove(q1->next); name2 = SYM(q1->next); - dlete(q1->next); + remove(q1->next); name1->usage |= DEP; name2->usage |= DEP; /* check */ @@ -590,7 +590,7 @@ void table_massage(List* tablist, Item* qtype, Item* qname, List* arglist) depend = LST(q = q->next); type = SYM(qtype)->type; - ifnew_parminstall( "usetable", "1", "", "0 1"); + ifnew_parminstall("usetable", "1", "", "0 1"); if (!check_table_statements) { check_table_statements = newlist(); } diff --git a/src/nmodl/parse1.ypp b/src/nmodl/parse1.ypp index 9ad57d1909..b764ccd772 100755 --- a/src/nmodl/parse1.ypp +++ b/src/nmodl/parse1.ypp @@ -193,7 +193,7 @@ define1: DEFINE1 NAME INTEGER sp->u.str = STR($3); sp->type = DEFINEDVAR; deltokens($1, $3);} - | DEFINE1 error {myerr( "syntax: DEFINE name integer");} + | DEFINE1 error {myerr("syntax: DEFINE name integer");} ; Name: NAME { Symbol *checklocal(Symbol*); @@ -229,7 +229,7 @@ units: /*nothing*/ {$$ = stralloc("", (char *)0);} ; unit: '(' {$$ = inputtopar();} /*string*/ ')' /*does not include parentheses*/ - {$$ = $2; dlete($1); dlete($3);} + {$$ = $2; remove($1); remove($3);} ; uniton: UNITSON {replacstr($1, "");} | UNITSOFF {replacstr($1, "");} @@ -263,7 +263,7 @@ number: NUMBER {lastok = $1;} /* replace the string with -string and discard '-'*/ { Sprintf(buf, "-%s", STR($2)); STR($2) = stralloc(buf, STR($2)); $$ = $2; - dlete($1); lastok = $2; + remove($1); lastok = $2; } ; NUMBER: integer | REAL @@ -409,7 +409,7 @@ locallist: LOCAL Insertstr(lastok->next, ";\n"); possible_local_current(blocktype, toplocal1_); } - | LOCAL error {myerr( "Illegal LOCAL declaration");} + | LOCAL error {myerr("Illegal LOCAL declaration");} ; locallist1: NAME locoptarray /* locals are placed in a stack of symbol lists and given @@ -490,7 +490,7 @@ ostmt: fromstmt | NRNMUTEXLOCK { nrnmutex(1,$1); } | NRNMUTEXUNLOCK { nrnmutex(0,$1); } | error - {myerr( "Illegal statement");} + {myerr("Illegal statement");} ; astmt: asgn /* ';' is added when relevant */ @@ -536,14 +536,14 @@ asgn: varname '=' expr Insertstr($2, " -("); replacstr($3, ") + "); if (nstate == 0) -{yyerror( "previous equation contains no state variables"); YYERROR;} +{yyerror("previous equation contains no state variables"); YYERROR;} eqnqueue($1); } | lineqn leftlinexpr '=' linexpr { inequation = 0; - dlete($3); + remove($3); if (nstate == 0) -{yyerror( "previous equation contains no state variables"); YYERROR;} +{yyerror("previous equation contains no state variables"); YYERROR;} } ; varname: name @@ -551,7 +551,7 @@ varname: name {lastok = $1; if (!extdef2){SYM($1)->usage |= DEP;} if (SYM($1)->subtype & ARRAY && !extdef2) - {myerr( "variable needs an index");} + {myerr("variable needs an index");} if (inequation && (SYM($1)->subtype & STAT) && in_solvefor(SYM($1))) { SYM($1)->used++; nstate++; pstate++; tstate++; @@ -568,7 +568,7 @@ varname: name } SYM($1)->usage |= DEP; if ((SYM($1)->subtype & ARRAY) == 0) - {myerr( "variable is not an array");} + {myerr("variable is not an array");} if (inequation && (SYM($1)->subtype & STAT) && in_solvefor(SYM($1))) { SYM($1)->used++; nstate++; pstate++; tstate++; @@ -609,7 +609,7 @@ intexpr: Name lastok = $4; replacstr($1, " (int)"); } - | error {myerr( "Illegal integer expression");} + | error {myerr("Illegal integer expression");} ; expr: varname | real units @@ -632,7 +632,7 @@ expr: varname | expr NE expr {replacstr($2, " !=");} | NOT expr {replacstr($1, " !");} | '-' expr %prec UNARYMINUS - | error {myerr( "Illegal expression");} + | error {myerr("Illegal expression");} ; nonlineqn: NONLIN1 {inequation = 1; nstate = 0;} ; @@ -647,13 +647,13 @@ linexpr: primary /* put terms in a list */ {linterm($1, lastok, pstate, leftside); pstate = 0;} | '-' primary - {dlete($1); + {remove($1); linterm($2, lastok, pstate, -leftside); pstate = 0;} | linexpr '+' primary - {dlete($2); + {remove($2); linterm($3, lastok, pstate, leftside); pstate = 0;} | linexpr '-' primary - {dlete($2); + {remove($2); linterm($3, lastok, pstate, -leftside); pstate = 0;} ; primary: term @@ -733,7 +733,7 @@ fromstmt: FROM NAME {pushlocal(); SYM($2) = copylocal(SYM($2)); Insertstr($10, "}"); } |FROM error { -myerr( "FROM intvar = intexpr TO intexpr BY intexpr { statements }");} +myerr("FROM intvar = intexpr TO intexpr BY intexpr { statements }");} ; opinc: /*nothing*/ {$$ = ITEM0;} | BY intexpr @@ -758,7 +758,7 @@ diag("FORALL range is undefined since no arrays used", " within the statement"); Insertstr($5, "}"); } |FORALL1 error { -myerr( "FORALL intvar { statements }");} +myerr("FORALL intvar { statements }");} ; whilestmt: WHILE '(' expr ')' stmtlist '}' ; @@ -911,7 +911,7 @@ netrecblk: NETRECEIVE '(' arglist ')' if ($3 == LIST0) { diag("NET_RECEIVE block",(char*)" must have at least one argument"); } - Lappendsym($3, copylocal(install( "flag", NAME))); + Lappendsym($3, copylocal(install("flag", NAME))); } stmtlist '}' { @@ -922,7 +922,7 @@ diag("NET_RECEIVE block",(char*)" must have at least one argument"); #endif poplocal(); freelist(&$3); } - | NETRECEIVE error { myerr( "syntax: NET_RECEIVE ( weight ) {stmtlist}");} + | NETRECEIVE error { myerr("syntax: NET_RECEIVE ( weight ) {stmtlist}");} ; initstmt: INITIAL1 stmtlist '}' { @@ -937,7 +937,7 @@ solveblk: SOLVE NAME ifsolerr { solvequeue($2, ITEM0, blocktype, $3); } | SOLVE NAME USING METHOD ifsolerr { solvequeue($2, $4, blocktype, $5); } - | SOLVE error { myerr( "Illegal SOLVE statement");} + | SOLVE error { myerr("Illegal SOLVE statement");} ; ifsolerr: /*nothing*/ { $$ = ITEM0; } @@ -953,11 +953,11 @@ solvefor: /*nothing*/ ; solvefor1: SOLVEFOR NAME { solveforlist = newlist(); Lappendsym(solveforlist, SYM($2)); - dlete($1); dlete($2); + remove($1); remove($2); } | solvefor1 ',' NAME - { Lappendsym(solveforlist, SYM($3)); dlete($2); dlete($3);} - | SOLVEFOR error { myerr( "Syntax: SOLVEFOR name, name, ...");} + { Lappendsym(solveforlist, SYM($3)); remove($2); remove($3);} + | SOLVEFOR error { myerr("Syntax: SOLVEFOR name, name, ...");} ; brkptblk: BREAKPOINT stmtlist '}' /* move it all to modelfunc */ @@ -974,13 +974,13 @@ bablk: BREAKPOINT stmtlist '}' {bablk(blocktype, INITIAL1, $2, $3);} | STEP stmtlist '}' {bablk(blocktype, STEP, $2, $3);} - | error {myerr( "[BEFORE AFTER] [BREAKPOINT SOLVE INITIAL STEP] { stmt }");} + | error {myerr("[BEFORE AFTER] [BREAKPOINT SOLVE INITIAL STEP] { stmt }");} ; watchstmt: WATCH watch1 - {$$ = $2; dlete($1);} + {$$ = $2; remove($1);} | watchstmt ',' watch1 - {dlete($2);} - | WATCH error {myerr( "WATCH (expr > expr) flag");} + {remove($2);} + | WATCH error {myerr("WATCH (expr > expr) flag");} ; watch1: '(' aexpr watchdir aexpr ')' real {watchstmt($1, $3, $5, $6, blocktype); $$=$6;} @@ -998,7 +998,7 @@ fornetcon: FOR_NETCONS '(' arglist ')' { } stmtlist '}' {fornetcon($1, $2, $3, $4, $6, $7); $$ = $7; } - | FOR_NETCONS error { myerr( "syntax: FOR_NETCONS(args,like,netreceive) { stmtlist}");} + | FOR_NETCONS error { myerr("syntax: FOR_NETCONS(args,like,netreceive) { stmtlist}");} ; aexpr: varname | real units @@ -1012,19 +1012,19 @@ aexpr: varname { $$ = insertstr($1, "pow("); replacstr($2, ","); lastok = insertstr(lastok->next, ")"); } | '-' aexpr %prec UNARYMINUS - | error {myerr( "Illegal expression");} + | error {myerr("Illegal expression");} ; sens: SENS senslist /* sensused flag is true */ { sensused = 1; - dlete($1); + remove($1); } - |SENS error {myerr( "syntax is SENS var1, var2, var3, etc");} + |SENS error {myerr("syntax is SENS var1, var2, var3, etc");} ; senslist: varname /* put in list. Used when enclosing block is massaged */ - { sensparm($1); dlete($1);} + { sensparm($1); remove($1);} | senslist ',' varname { sensparm($3); deltokens($2, $3);} ; @@ -1033,7 +1033,7 @@ conserve: CONSERVE {extdef2 = 0; } react '=' expr {/* react originally designed for reactions and is unchanged*/ extdef2 = 0; massageconserve($1, $4, lastok);} - | CONSERVE error {myerr( "Illegal CONSERVE syntax");} + | CONSERVE error {myerr("Illegal CONSERVE syntax");} ; compart: COMPARTMENT NAME ',' {pushlocal(); SYM($2) = copylocal(SYM($2));} @@ -1065,7 +1065,7 @@ reaction: REACTION react REACT1 {leftreact();} react '(' expr ',' expr ')' {flux($1, $3, $7);} | REACTION react '-' GT '(' expr ')' {flux($1, $3, $7);} - | REACTION error {myerr( "Illegal reaction syntax");} + | REACTION error {myerr("Illegal reaction syntax");} ; react: varname {reactname($1, lastok, ITEM0);} |integer varname {reactname($2, lastok, $1);} @@ -1074,7 +1074,7 @@ react: varname {reactname($1, lastok, ITEM0);} ; lagstmt: LAG name BY NAME {lag_stmt($1, blocktype);} - | LAG error {myerr( "Lag syntax is: LAG name BY const");} + | LAG error {myerr("Lag syntax is: LAG name BY const");} ; queuestmt: PUTQ name {queue_stmt($1, $2);} | GETQ name {queue_stmt($1, $2);} @@ -1095,7 +1095,7 @@ match: name } } | error - {myerr( "MATCH syntax is state0 or state(expr)=expr or\ + {myerr("MATCH syntax is state0 or state(expr)=expr or\ state[i](expr(i)) = expr(i)");} ; matchname: name @@ -1115,7 +1115,7 @@ unitbody: /*nothing*/ ; unitdef: unit '=' unit {install_units($1, $3);} - | unit error {myerr( "Unit definition syntax: (units) = (units)");} + | unit error {myerr("Unit definition syntax: (units) = (units)");} ; factordef: NAME '=' real unit { SYM($1)->subtype |= nmodlCONST; @@ -1135,7 +1135,7 @@ factordef: NAME '=' real unit nrnunit_dynamic_str(buf, SYM($1)->name, $3, $6); Lappendstr(firstlist, buf); } - | error {myerr( "Unit factor syntax: examples:\n\ + | error {myerr("Unit factor syntax: examples:\n\ foot2inch = (foot) -> (inch)\n\ F = 96520 (coulomb)\n\ R = (k-mole) (joule/degC)"); @@ -1166,7 +1166,7 @@ tablestmt: TABLE tablst dependlst FROM expr TO expr WITH INTEGER Lappendlst(table_list, $3); deltokens($1, $9); } - | TABLE error { myerr( "syntax: TABLE [list] [DEPEND list] FROM expr TO expr WITH integer");} + | TABLE error { myerr("syntax: TABLE [list] [DEPEND list] FROM expr TO expr WITH integer");} ; tablst: /*Nothing*/ {$$ = LIST0;} @@ -1216,16 +1216,16 @@ nrnuse: USEION NAME READ nrnlist valence optontology |USEION NAME READ nrnlist WRITE nrnlist valence optontology {nrn_use($2, $4, $6, $7);} |USEION error - {myerr( "syntax is: USEION ion READ list WRITE list REPRESENTS curie");} + {myerr("syntax is: USEION ion READ list WRITE list REPRESENTS curie");} ; optontology: { $$ = NULL; } | REPRESENTS ONTOLOGY_ID { $$ = $2; } nrnlist: NAME | nrnlist ',' NAME - { dlete($2); $$ = $3;} + { remove($2); $$ = $3;} | error - {myerr( "syntax is: keyword name , name, ..., name");} + {myerr("syntax is: keyword name , name, ..., name");} ; optnrnlist: /*nothing*/ {$$ = NULL;} @@ -1239,7 +1239,7 @@ valence: /*nothing*/ /* replace the string with -string and discard '-'*/ { Sprintf(buf, "-%s", STR($3)); STR($3) = stralloc(buf, STR($3)); $$ = $3; - dlete($2); lastok = $3; + remove($2); lastok = $3; } ; %% diff --git a/src/nmodl/partial.cpp b/src/nmodl/partial.cpp index 14b57bb11e..44b2f90cb2 100755 --- a/src/nmodl/partial.cpp +++ b/src/nmodl/partial.cpp @@ -87,8 +87,8 @@ void solv_partial(Item* qsol, Symbol* fun) Item *q; Symbol *dspace; - if ((dspace = lookup( "delta_x")) == SYM0) { - dspace = install( "delta_x", NAME); + if ((dspace = lookup("delta_x")) == SYM0) { + dspace = install("delta_x", NAME); parminstall(dspace, "1", "", ""); } Sprintf(buf, "%s();\n", fun->name); diff --git a/src/nmodl/solve.cpp b/src/nmodl/solve.cpp index 13b73cb416..afb19dd9ff 100755 --- a/src/nmodl/solve.cpp +++ b/src/nmodl/solve.cpp @@ -101,13 +101,13 @@ diag("The SOLVE statement must be before the DERIVATIVE block for ", SYM(lq)->na cvode_cnexp_solve = lq; #endif } - dlete(q2->prev); - dlete(q2); + remove(q2->prev); + remove(q2); }else{ qtemp = q1->next; Lappendsym(solvq, SYM0); } - dlete(q1->prev); + remove(q1->prev); /* handle the error statement */ /* put one in if it isn't already there */ @@ -192,7 +192,7 @@ void solvhandler() case DERF: if (method == SYM0) { - method = lookup( "adrunge"); + method = lookup("adrunge"); } if (btype == BREAKPOINT && !steadystate) { /* derivatives recalculated after while loop */ @@ -213,7 +213,7 @@ fprintf(stderr, "Notice: %s is not thread safe. Complain to Hines\n", method->na break; case KINF: if (method == SYM0) { - method = lookup( "_advance"); + method = lookup("_advance"); } if (btype == BREAKPOINT && (method->subtype & DERF)) { #if VECTORIZE @@ -244,7 +244,7 @@ fprintf(stderr, "Notice: NONLINEAR is not thread safe.\n"); vectorize = 0; #endif if (method == SYM0) { - method = lookup( "newton"); + method = lookup("newton"); } solv_nonlin(qsol, fun, method, numeqn, listnum); break; @@ -254,7 +254,7 @@ fprintf(stderr, "Notice: LINEAR is not thread safe.\n"); vectorize = 0; #endif if (method == SYM0) { - method = lookup( "simeq"); + method = lookup("simeq"); } solv_lineq(qsol, fun, method, numeqn, listnum); break; @@ -391,9 +391,6 @@ which is trapped in scop */ case DISCRETE: if (firstderf) { /* time dependent process so create a deltastep */ double d[3]; -//#ifndef NeXT -// double atof(); -//#endif int i; Item *q; char sval[256]; diff --git a/src/nmodl/symbol.cpp b/src/nmodl/symbol.cpp index cbacf7af52..27bff15b8f 100755 --- a/src/nmodl/symbol.cpp +++ b/src/nmodl/symbol.cpp @@ -99,9 +99,9 @@ void poplocal() /* a lot of storage leakage here for symbols we are guaranteed sl = LST(symlistlist->next); for (i = sl->next; i != sl; i = j) { j = i->next; - dlete(i); + remove(i); } - dlete(symlistlist->next); + remove(symlistlist->next); } Symbol *copylocal(Symbol* s) diff --git a/src/nrncvode/cvodeobj.cpp b/src/nrncvode/cvodeobj.cpp index 8fbfeeb9ac..56f00e3dfd 100644 --- a/src/nrncvode/cvodeobj.cpp +++ b/src/nrncvode/cvodeobj.cpp @@ -8,7 +8,7 @@ extern "C" void cvode_fadvance(); void cvode_finitialize(); extern void (*nrn_multisplit_setup_)(); -extern /*"C"*/ int hoc_return_type_code; +extern int hoc_return_type_code; #include #include diff --git a/src/nrncvode/netcvode.cpp b/src/nrncvode/netcvode.cpp index 24bd5a2736..bb378af941 100644 --- a/src/nrncvode/netcvode.cpp +++ b/src/nrncvode/netcvode.cpp @@ -86,13 +86,13 @@ extern short* nrn_is_artificial_; // should be bool but not using that type in c extern short* nrn_artcell_qindex_; extern "C" void net_send(void**, double*, Point_process*, double, double); extern "C" void net_move(void**, Point_process*, double); -//void artcell_net_send(void**, double*, Point_process*, double, double); -//void artcell_net_move(void**, Point_process*, double); +extern "C" void artcell_net_send(void**, double*, Point_process*, double, double); +extern "C" void artcell_net_move(void**, Point_process*, double); int nrn_use_selfqueue_; void nrn_pending_selfqueue(double tt, NrnThread*); static void all_pending_selfqueue(double tt); static void* pending_selfqueue(NrnThread*); -//void net_event(Point_process*, double); +extern "C" void net_event(Point_process*, double); extern "C" void _nrn_watch_activate(Datum*, double (*)(Point_process*), int, Point_process*, int, double); extern "C" void _nrn_free_watch(Datum*, int, int); extern int hoc_araypt(Symbol*, int); @@ -122,7 +122,7 @@ bool nrn_trajectory_request_per_time_step_ = false; extern void nrnmusic_injectlist(void*, double); #endif -extern /*"C"*/ int hoc_return_type_code; +extern int hoc_return_type_code; extern int nrn_fornetcon_cnt_; extern int* nrn_fornetcon_index_; diff --git a/src/nrniv/cxprop.cpp b/src/nrniv/cxprop.cpp index 8c406ec0a0..c99fe8c2eb 100644 --- a/src/nrniv/cxprop.cpp +++ b/src/nrniv/cxprop.cpp @@ -19,19 +19,12 @@ greater cache efficiency extern void nrn_mk_prop_pools(int); extern void nrn_cache_prop_realloc(); extern int nrn_is_ion(int); -//void nrn_update_ion_pointer(Symbol* sion, Datum* dp, int id, int ip); #if EXTRACELLULAR -void nrn_extcell_update_param(); +extern void nrn_extcell_update_param(); #endif extern void nrn_recalc_ptrs(double*(*)(double*)); static double* recalc_ptr(double*); -//void* nrn_pool_create(long count, int itemsize); -//void nrn_pool_delete(void* pool); -//void* nrn_pool_alloc(void* pool); -//void nrn_pool_free(void* pool, void* item); -//void nrn_pool_freeall(void* pool); - declareArrayPool(CharArrayPool, char) implementArrayPool(CharArrayPool, char) diff --git a/src/nrniv/multisplit.cpp b/src/nrniv/multisplit.cpp index 8666158115..fd0b7e9495 100644 --- a/src/nrniv/multisplit.cpp +++ b/src/nrniv/multisplit.cpp @@ -2059,6 +2059,7 @@ nrnmpi_myid, i, mt.displ_, mt.size_, mt.host_, tag); //if (nrnmpi_myid == 4) { printf("%d send to %d nnode=%d nnode_rt=%d size=%d tag=%d\n", nrnmpi_myid, mt.host_, mt.nnode_, mt.nnode_rt_, mt.size_, mt.tag_); +//} #endif #if 0 //if (nrnmpi_myid == 4) { @@ -2071,6 +2072,7 @@ nrnmpi_myid, mt.host_, 2*j, tbuf[2*j], 2*j+1, tbuf[2*j+1], mt.nodeindex_[j]); printf("%d send to %d offdiag tbuf[%d] = %g\n", nrnmpi_myid, mt.host_, jj, tbuf[jj]); } +//) #endif } @@ -2262,6 +2264,7 @@ nrnmpi_myid, i, mt.displ_, mt.size_, mt.host_, tag); //if (nrnmpi_myid == 4) { printf("%d send to %d nnode=%d nnode_rt=%d size=%d tag=%d\n", nrnmpi_myid, mt.host_, mt.nnode_, mt.nnode_rt_, mt.size_, mt.tag_); +//} #endif #if 0 //if (nrnmpi_myid == 4) { @@ -2274,6 +2277,7 @@ nrnmpi_myid, mt.host_, 2*j, tbuf[2*j], 2*j+1, tbuf[2*j+1], mt.nodeindex_[j]); printf("%d send to %d offdiag tbuf[%d] = %g\n", nrnmpi_myid, mt.host_, jj, tbuf[jj]); } +//} #endif } diff --git a/src/nrniv/nrnmenu.cpp b/src/nrniv/nrnmenu.cpp index 75cb857d0f..160de6d202 100644 --- a/src/nrniv/nrnmenu.cpp +++ b/src/nrniv/nrnmenu.cpp @@ -19,7 +19,7 @@ extern double (*nrnpy_object_to_double_)(Object*); typedef void (*ReceiveFunc)(Point_process*, double*, double); -/*extern "C"*/ extern int hoc_return_type_code; +extern int hoc_return_type_code; // from nrnoc #include "membfunc.h" #include "parse.hpp" diff --git a/src/nrniv/nrnste.cpp b/src/nrniv/nrnste.cpp index 7bcf7984ea..81a140c571 100644 --- a/src/nrniv/nrnste.cpp +++ b/src/nrniv/nrnste.cpp @@ -9,7 +9,7 @@ #include #include -/*extern "C"*/ extern int hoc_return_type_code; +extern int hoc_return_type_code; static double ste_transition(void* v) { StateTransitionEvent* ste = (StateTransitionEvent*)v; diff --git a/src/nrnjava/nrnccmb/NrnKSChan.java b/src/nrnjava/nrnccmb/NrnKSChan.java index a6928685dc..1583b30750 100755 --- a/src/nrnjava/nrnccmb/NrnKSChan.java +++ b/src/nrnjava/nrnccmb/NrnKSChan.java @@ -145,7 +145,7 @@ private void structure(Object[] data) { //System.out.println("structure_ "); //for (i=0; i < st.length; ++i) { // System.out.println(i + " " +st[i]); -} // extern "C" +//} structure_.toHoc(st); ho_.dMethod("setstructure", new Object[]{structure_}); ho_.dMethod("setion", new Object[]{ @@ -217,7 +217,7 @@ public void sync_rates(HocObject h) { //System.out.println("sync_rates "); //for (int k=0; k < rat[j].length; ++k) { // System.out.println(k + " " +rat[j][k]); -} // extern "C" +//} } } ch_.setData(data); diff --git a/src/nrnmpi/Makefile.am b/src/nrnmpi/Makefile.am index 135a192fc9..3e80e170ec 100755 --- a/src/nrnmpi/Makefile.am +++ b/src/nrnmpi/Makefile.am @@ -6,7 +6,8 @@ AM_CPPFLAGS = $(includes) libnrnmpi_la_SOURCES = nrnmpi.cpp bbsmpipack.cpp mpispike.cpp nrnrt.cpp -CXX = @MPICCnrnmpi@ +CC = @MPICCnrnmpi@ +CXX = @MPICXXnrnmpi@ if BUILD_NRNMPI_DYNAMIC diff --git a/src/nrnmpi/bbsmpipack.cpp b/src/nrnmpi/bbsmpipack.cpp index 5c56939ecd..90b4d66152 100755 --- a/src/nrnmpi/bbsmpipack.cpp +++ b/src/nrnmpi/bbsmpipack.cpp @@ -272,13 +272,13 @@ void nrnmpi_pkstr(const char* s, bbsmpibuf* r) { int len; len = strlen(s); pack(&len, 1, my_MPI_INT, r, "pkstr length"); - pack(&s, len, my_MPI_CHAR, r, "pkstr string"); + pack((char*)s, len, my_MPI_CHAR, r, "pkstr string"); } void nrnmpi_pkpickle(const char* s, size_t size, bbsmpibuf* r) { int len = size; pack(&len, 1, my_MPI_INT, r, "pkpickle length"); - pack(&s, len, my_MPI_PICKLE, r, "pkpickle data"); + pack((char*)s, len, my_MPI_PICKLE, r, "pkpickle data"); } void nrnmpi_bbssend(int dest, int tag, bbsmpibuf* r) { diff --git a/src/nrnoc/cabcode.cpp b/src/nrnoc/cabcode.cpp index e56f93a971..46d7b7f5d5 100644 --- a/src/nrnoc/cabcode.cpp +++ b/src/nrnoc/cabcode.cpp @@ -548,7 +548,6 @@ static void reverse_sibling_list(Section* sec) } pch = &sec->child; while(scnt--) { -// Object** hoc_objpop(); ch = (Section*)hoc_objpop(); *pch = ch; pch = &ch->sibling; @@ -1120,7 +1119,7 @@ static Datum* pdprop(Symbol* s, int indx, Section* sec, short inode) { void connectpointer(void) { /* pointer symbol at pc, target variable on stack, maybe range variable location on stack */ Datum *dat; - double *pd;//, *hoc_pxpop(); + double *pd; double d; Symbol *s = (pc++)->sym; pd = hoc_pxpop(); @@ -1150,7 +1149,7 @@ void range_interpolate_single(void) /*symbol at pc, 2 values on stack*/ double x, y; Symbol* s; Section* sec; - double* pd; //, *nrn_rangepointer(); + double* pd; int op; s = (pc++)->sym; @@ -1449,7 +1448,7 @@ void rangevarevalpointer(void) /* symbol at pc, location on stack, return pointe void rangevareval(void) /* symbol at pc, location on stack, return value on stack */ { - double *pd;//, *hoc_pxpop(); + double *pd; rangevarevalpointer(); pd = hoc_pxpop(); @@ -1781,7 +1780,6 @@ void setup_topology(void) const char* secname(Section* sec) /* name of section (for use in error messages) */ { -// extern char* hoc_araystr(); static char name[512]; Symbol *s; int indx; @@ -2156,7 +2154,6 @@ void forall_section(void) { extern int hoc_returning; char buf[200]; char** s; -// char** hoc_strpop(); int istk; /* fast forall within an object asserts that the object sections @@ -2219,7 +2216,6 @@ void hoc_ifsec(void) { Inst *savepc = pc; char buf[200]; char** s; -// char** hoc_strpop(); extern int hoc_returning; s = hoc_strpop(); diff --git a/src/nrnoc/clamp.cpp b/src/nrnoc/clamp.cpp index ae747e8e6f..2ca46ca4b5 100644 --- a/src/nrnoc/clamp.cpp +++ b/src/nrnoc/clamp.cpp @@ -143,7 +143,6 @@ static void free_clamp(void) { void clamp_prepare(void) /*fill in the section info*/ { -// Node *node_ptr(); double area; if (!maxlevel) { diff --git a/src/nrnoc/eion.cpp b/src/nrnoc/eion.cpp index bffe31e6e4..66126a5aed 100644 --- a/src/nrnoc/eion.cpp +++ b/src/nrnoc/eion.cpp @@ -208,8 +208,6 @@ two USEION statements (%g and %g)\n", after all mod files have been dealt with to verify that they all have a defined valence. */ -#if 0 -#endif } else if (valence != VAL_SENTINAL) { global_charge(s->subtype) = valence; } @@ -265,7 +263,6 @@ void nernst(void) { Symbol *s = hoc_lookup(gargstr(1)); if (s && ion_global_map[s->u.rng.type]) { Section *sec = chk_access(); -// double* nrn_rangepointer(); Symbol *ion = memb_func[s->u.rng.type].sym; double z = global_charge(s->u.rng.type); double *ci, *co, *e, x; @@ -429,7 +426,7 @@ void ion_style(void) { Symbol *s; int istyle, i, oldstyle; Section *sec; - Prop *p; //, *nrn_mechanism(); + Prop *p; s = hoc_lookup(gargstr(1)); if (!s || s->type != MECHANISM || !nrn_is_ion(s->subtype)) { @@ -481,7 +478,7 @@ int nrn_vartype(Symbol *sym) { i = sym->subtype; if (i == _AMBIGUOUS) { Section *sec; - Prop *p; //, *nrn_mechanism(); + Prop *p; sec = nrn_noerr_access(); if (!sec) { return nrnocCONST; diff --git a/src/nrnoc/fadvance.cpp b/src/nrnoc/fadvance.cpp index 837ade333e..de03d2fed6 100644 --- a/src/nrnoc/fadvance.cpp +++ b/src/nrnoc/fadvance.cpp @@ -366,7 +366,7 @@ void nrn_fixed_step() { } nrn_multithread_job(nrn_fixed_step_lastpart); } -// } + //} }else{ nrn_multithread_job(nrn_fixed_step_thread); /* if there is no nrnthread_v_transfer then there cannot be @@ -459,7 +459,7 @@ void* nrn_fixed_step_thread(NrnThread* nth) { double wt; deliver_net_events(nth); wt = nrnmpi_wtime(); - nrn_random_play(/*nth*/); // TODO nrnthread fn? + nrn_random_play(); #if ELIMINATE_T_ROUNDOFF nth->nrn_ndt_ += .5; nth->_t = nrn_tbase_ + nth->nrn_ndt_ * nrn_dt_; @@ -518,7 +518,7 @@ void* nrn_ms_treeset_through_triang(NrnThread* nth) { double wt; deliver_net_events(nth); wt = nrnmpi_wtime(); - nrn_random_play(/*nth*/); // TODO nrnthread fn? + nrn_random_play(); #if ELIMINATE_T_ROUNDOFF nth->nrn_ndt_ += .5; nth->_t = nrn_tbase_ + nth->nrn_ndt_ * nrn_dt_; @@ -823,7 +823,7 @@ void nrn_finitialize(int setv, double v) { nrn_thread_table_check(); clear_event_queue(); nrn_spike_exchange_init(); - nrn_random_play(/*_nt*/); // TODO nrnthread fn? + nrn_random_play(); #if VECTORIZE nrn_play_init(); /* Vector.play */ for (i = 0; i < nrn_nthread; ++i) { @@ -993,7 +993,6 @@ static void batch_out() { } void batch_save(void) { -// double* hoc_pgetarg(); int i; if (!ifarg(1)) { batch_n = 0; diff --git a/src/nrnoc/fstim.cpp b/src/nrnoc/fstim.cpp index 4fbbe84656..4e8a6d7c45 100644 --- a/src/nrnoc/fstim.cpp +++ b/src/nrnoc/fstim.cpp @@ -133,7 +133,6 @@ static void free_stim(void) { static void stim_record(int i) /*fill in the section info*/ { -// Node *node_ptr(); double area; Section *sec; diff --git a/src/nrnoc/hocprax.cpp b/src/nrnoc/hocprax.cpp index 254315314f..a353a494bd 100644 --- a/src/nrnoc/hocprax.cpp +++ b/src/nrnoc/hocprax.cpp @@ -92,9 +92,7 @@ void stop_praxis(void) { static double minerr, *minarg; /* too bad this is not recursive */ void fit_praxis(void) { -// extern Symbol* hoc_lookup(char *); -// extern char* gargstr(); - char* after_quad; + char* after_quad; int i; double err, fmin; double* px; @@ -285,7 +283,6 @@ static double efun(double* v, int n) v[i] = px[i]; } }else{ -// extern double hoc_call_func(); int i; hoc_pushx((double)n); hoc_pushpx(v); diff --git a/src/nrnoc/nrncvode.h b/src/nrnoc/nrncvode.h index fce24a5e2d..e96394969b 100644 --- a/src/nrnoc/nrncvode.h +++ b/src/nrnoc/nrncvode.h @@ -14,7 +14,7 @@ extern void nrn_play_init(void); extern void fixed_record_continuous(NrnThread* nt); extern void fixed_play_continuous(NrnThread* nt); extern void nrn_solver_prepare(void); -extern "C" void nrn_random_play(/*NrnThread**/); // TODO nrnthread fn? +extern "C" void nrn_random_play(); extern void nrn_daspk_init_step(double, double, int); extern void nrndae_init(void); extern void nrndae_update(void); diff --git a/src/nrnoc/nrniv_mf.h b/src/nrnoc/nrniv_mf.h index 357394f194..c45eaffe5a 100644 --- a/src/nrnoc/nrniv_mf.h +++ b/src/nrnoc/nrniv_mf.h @@ -22,12 +22,6 @@ extern "C" { #endif extern Point_process *ob2pntproc(Object *); extern Point_process* ob2pntproc_0(Object*); - - - - - - extern double* _getelm(int, int); extern double* _nrn_thread_getelm(void*, int, int); extern int sparse(void**, int, int*, int*, double*, double*, double, diff --git a/src/nrnoc/passive0.cpp b/src/nrnoc/passive0.cpp index c7cc960918..30d1919062 100755 --- a/src/nrnoc/passive0.cpp +++ b/src/nrnoc/passive0.cpp @@ -5,8 +5,6 @@ #include "membdef.h" #include "nrniv_mf.h" - - #define nparm 2 static const char *mechanism[] = { "0", "fastpas", "g_fastpas", "e_fastpas", 0,0,0 diff --git a/src/nrnoc/point.cpp b/src/nrnoc/point.cpp index c732af8027..053da711cc 100755 --- a/src/nrnoc/point.cpp +++ b/src/nrnoc/point.cpp @@ -55,10 +55,9 @@ Object* nrn_new_pointprocess(Symbol* sym) { void* v; extern Object* hoc_new_object(Symbol*, void*); - extern Object* hoc_new_opoint(int); //, *hoc_new_opoint(); + extern Object* hoc_new_opoint(int); Object* ob; extern Symlist* hoc_built_in_symlist; -// Symbol* hoc_table_lookup(char *); int pointtype; assert(sym->type == MECHANISM && memb_func[sym->subtype].is_point); pointtype = pnt_map[sym->subtype]; @@ -223,7 +222,7 @@ extern "C" double loc_point_process(int pointtype, void* v) Point_process* pnt = (Point_process*)v; double x; Section *sec; - Node *node; //, *node_exact(); + Node *node; if (nrn_is_artificial_[pointsym[pointtype]->subtype]) { hoc_execerror("ARTIFICIAL_CELLs are not located in a section", (char*)0); @@ -300,7 +299,7 @@ double* point_process_pointer(Point_process* pnt, Symbol* sym, int index) extern "C" void steer_point_process(void* v) /* put the right double pointer on the stack */ { - Symbol* sym; //, *hoc_spop(); + Symbol* sym; int index; Point_process *pnt = (Point_process*)v; sym = hoc_spop(); @@ -317,7 +316,6 @@ void nrn_cppp(void) { } void connect_point_process_pointer(void) { -// double* hoc_pxpop(); if (cppp_semaphore != 2) { cppp_semaphore = 0; hoc_execerror("not a point process pointer", (char*)0); diff --git a/src/nrnoc/secref.cpp b/src/nrnoc/secref.cpp index a2e96de21d..baf280818d 100755 --- a/src/nrnoc/secref.cpp +++ b/src/nrnoc/secref.cpp @@ -82,9 +82,7 @@ static double s_unname(void* v) { extern "C" Object* ivoc_list_item(Object*, int); static double s_rename(void* v) { -// extern Object* hoc_thisobject, **hoc_objgetarg(); extern Objectdata* hoc_top_level_data; -// extern Symbol* hoc_table_lookup(); extern Symlist* hoc_top_level_symlist; char* name; @@ -364,7 +362,7 @@ extern void class2oc(const char *, void SectionRef_reg(void) { - Symbol* s, *sr; //, *hoc_table_lookup(); + Symbol* s, *sr; class2oc("SectionRef", cons, destruct, members, nullptr, nullptr, nullptr); /* now make the sec variable an actual SECTIONREF */ diff --git a/src/nrnoc/solve.cpp b/src/nrnoc/solve.cpp index 200f2d181d..ccaf57084e 100644 --- a/src/nrnoc/solve.cpp +++ b/src/nrnoc/solve.cpp @@ -60,8 +60,6 @@ node.v + extnode.v[0] #include "membfunc.h" #include "spmatrix.h" - - extern int tree_changed; static void node_free(); static void triang(NrnThread*), bksub(NrnThread*); @@ -222,9 +220,9 @@ double topol_distance(Section* sec1, Node* node1, Section* sec2, Node* node2, static Section *origin_sec; void distance(void) { - double d, d_origin; //, chkarg(); + double d, d_origin; int mode; - Node* node;//, *node_exact(); + Node* node; Section *sec; static Node* origin_node; Node* my_origin_node; @@ -300,8 +298,7 @@ static void dashes(Section* sec, int offset, int first) int i, scnt; Section* ch; char direc[30]; -// extern double nrn_section_orientation(); - + i = (int)nrn_section_orientation(sec); sprintf(direc, "(%d-%d)", i, 1-i); for (i=0; i #include "grids.h" #include "rxd.h" -extern "C" { - #include -} -#include #include <../nrnoc/section.h> #include <../nrnoc/nrn_ansi.h> #include <../nrnoc/multicore.h> diff --git a/src/nrnpython/rxd.h b/src/nrnpython/rxd.h index 71893fb093..4ead33c781 100644 --- a/src/nrnpython/rxd.h +++ b/src/nrnpython/rxd.h @@ -1,7 +1,5 @@ -extern "C" { - #include - #include -} // extern "C" +#include +#include /*borrowed from Meschach Version 1.2b*/ #define v_get_val(x,i) ((x)->ve[(i)]) #define m_get_val(A,i,j) ((A)->me[(i)][(j)]) diff --git a/src/nrnpython/rxd_extracellular.cpp b/src/nrnpython/rxd_extracellular.cpp index 5ad1446dcb..0d55c2f5f0 100644 --- a/src/nrnpython/rxd_extracellular.cpp +++ b/src/nrnpython/rxd_extracellular.cpp @@ -4,8 +4,6 @@ #include #include "grids.h" #include "rxd.h" -#include -#include #include #include diff --git a/src/nrnpython/rxd_intracellular.cpp b/src/nrnpython/rxd_intracellular.cpp index 125e8ec5d5..d02a8625e1 100644 --- a/src/nrnpython/rxd_intracellular.cpp +++ b/src/nrnpython/rxd_intracellular.cpp @@ -4,8 +4,6 @@ #include #include "grids.h" #include "rxd.h" -#include -#include #include #include diff --git a/src/oc/code.cpp b/src/oc/code.cpp index 9707ac7c01..717540ef6b 100755 --- a/src/oc/code.cpp +++ b/src/oc/code.cpp @@ -2211,7 +2211,6 @@ void hoc_not(void) { void power(void) /* arg1 raised to arg2 */ { double d1, d2; -// extern double Pow(); d2 = xpopm(); d1 = xpopm(); d1 = Pow(d1, d2); @@ -2485,7 +2484,6 @@ void print(void) /* pop top value from stack, print it */ void prexpr(void) /* print numeric value */ { static HocStr *s; -// char *hoc_object_name(); char *ss; #if CABLE extern char* secaccessname(); diff --git a/src/oc/code2.cpp b/src/oc/code2.cpp index 0b8b171dca..bc778e17a7 100755 --- a/src/oc/code2.cpp +++ b/src/oc/code2.cpp @@ -75,8 +75,7 @@ Symbol* hoc_name2sym(const char* name) { void hoc_Symbol_limits(void) { Symbol* sym; - extern Symbol* hoc_get_last_pointer_symbol();//, *hoc_get_last_pointer_symbol(); -// double* hoc_pgetarg(); + extern Symbol* hoc_get_last_pointer_symbol(); if (hoc_is_str_arg(1)) { char* name = gargstr(1); @@ -146,10 +145,8 @@ char* hoc_symbol_units(Symbol* sym, const char* units) { void hoc_Symbol_units(void) { Symbol* sym; - extern Symbol* hoc_get_last_pointer_symbol(); //, *hoc_get_last_pointer_symbol(); + extern Symbol* hoc_get_last_pointer_symbol(); extern double* hoc_pgetarg(int); -// int hoc_is_str_arg(); -// char** hoc_temp_charptr(); char** units = hoc_temp_charptr(); if (hoc_is_double_arg(1)) { @@ -249,7 +246,7 @@ void hoc_sscanf(void) { static int hoc_vsscanf(const char* buf) { /* assumes arg2 format string from hoc as well as remaining args */ - char *pf, *format, errbuf[100]; //, **hoc_pgargstr(); + char *pf, *format, errbuf[100]; void* arglist[20]; int n=0, iarg, i, islong, convert, sawnum; extern double* hoc_pgetarg(int); @@ -453,7 +450,6 @@ void System(void) static char stdoutfile[]="/systmp.tmp"; #endif double d; -// int system(); FILE *fp; if (hoc_plttext && !strchr(gargstr(1), '>')) { @@ -508,7 +504,6 @@ hoc_execerror("Internal error in System(): can't open", stdoutfile); void Xred(void) /* read with prompt string and default and limits */ { double d; -// double xred(); d = xred(gargstr(1), *getarg(2), *getarg(3), *getarg(4)); ret(); diff --git a/src/oc/fileio.cpp b/src/oc/fileio.cpp index c582fed821..10d843ee40 100755 --- a/src/oc/fileio.cpp +++ b/src/oc/fileio.cpp @@ -503,8 +503,6 @@ void hoc_sprint1(char** ppbuf, int argn) { /* convert args to right type for con case 's': if (hoc_is_object_arg(argn)) { -// char* hoc_object_name(); -// Object** hoc_objgetarg(); cp = hoc_object_name(*hoc_objgetarg(argn)); }else{ cp = gargstr(argn); diff --git a/src/oc/hoc.cpp b/src/oc/hoc.cpp index a7ef0031a8..6c83f05eed 100755 --- a/src/oc/hoc.cpp +++ b/src/oc/hoc.cpp @@ -653,7 +653,7 @@ value of oc_run() */ static int debug_message_; void hoc_show_errmess_always(void) { - double x; //, chkarg(); + double x; x = chkarg(1, 0., 1.); debug_message_ = (int)x; ret(); @@ -764,11 +764,11 @@ void print_bt() { // parsed elements from stacktrace line: size_t funcname_size = 256; // symbol stores the symbol at which the signal was invoked - char* symbol = malloc(sizeof(char)*funcname_size); + char* symbol = static_cast(malloc(sizeof(char)*funcname_size)); // the function name where the signal was invoked - char* funcname = malloc(sizeof(char)*funcname_size); + char* funcname = static_cast(malloc(sizeof(char)*funcname_size)); // offset stores the relative address from the function where the signal was invoked - char* offset = malloc(sizeof(char)*10); + char* offset = static_cast(malloc(sizeof(char)*10)); // the memory address of the function void* addr = NULL; // get void*'s for maximum last 16 entries on the stack @@ -1389,7 +1389,7 @@ static void hoc_run1(void) /* execute until EOF */ } hoc_execerror_messages = 1; if (pipeflag == 1) { /*at this location multiple emacs errors */ -// hoc_pipeflush(); /* don't eat up stack space */ + hoc_pipeflush(); /* don't eat up stack space */ }else{ pipeflag=0; } @@ -1632,6 +1632,10 @@ int hoc_yyparse(void) { i = yyparse(); hoc_in_yyparse = 0; switch (i) { + case 'e': + i = '\n'; + hoc_edit(); + break; case -3 : /* need more input */ hoc_in_yyparse = 1; i = '\n'; diff --git a/src/oc/hoc_oop.cpp b/src/oc/hoc_oop.cpp index b640523aa0..f36fcba5d4 100755 --- a/src/oc/hoc_oop.cpp +++ b/src/oc/hoc_oop.cpp @@ -866,7 +866,7 @@ void hoc_objectvar(void) { /* object variable symbol at pc+1. */ void hoc_objectarg(void) { /* object arg index at pc+1. */ /* pointer to correct object left on stack */ int i; - Object **obp; //, **hoc_objgetarg(); + Object **obp; #if PDEBUG printf("code for hoc_objectarg()\n"); #endif @@ -923,7 +923,7 @@ Object* hoc_name2obj(const char* name, int index) { } void hoc_object_id(void) { - Object *ob;//, **hoc_objgetarg(); + Object *ob; ob = *(hoc_objgetarg(1)); if (ifarg(2) && chkarg(2, 0., 1.) == 1.) { @@ -1046,15 +1046,15 @@ hoc_execerror("Cannot assign to a PythonObject function call:", sym0->name); sym = *psym; }else{ if (obp->aliases == 0 || (sym = ivoc_alias_lookup(sym0->name, obp)) == 0) { - /* lookup only has to be done once if the name is not an alias - and the ptid of the object is still the same. */ - sym = hoc_table_lookup(sym0->name, obp->ctemplate->symtable); - if (!sym || sym->cpublic != PUBLIC_TYPE) { -fprintf(stderr, "%s not a public member of %s\n", sym0->name, obp->ctemplate->sym->name); -hoc_execerror(obp->ctemplate->sym->name, sym0->name); - } - *ptid = obp->ctemplate->id; - *psym = sym; + /* lookup only has to be done once if the name is not an alias + and the ptid of the object is still the same. */ + sym = hoc_table_lookup(sym0->name, obp->ctemplate->symtable); + if (!sym || sym->cpublic != PUBLIC_TYPE) { + fprintf(stderr, "%s not a public member of %s\n", sym0->name, obp->ctemplate->sym->name); + hoc_execerror(obp->ctemplate->sym->name, sym0->name); + } + *ptid = obp->ctemplate->id; + *psym = sym; } } }else{ @@ -1154,7 +1154,7 @@ hoc_execerror(obp->ctemplate->sym->name, sym0->name); case SECTIONREF: { extern Symbol* nrn_sec_sym; Section* sec; - extern Section* nrn_sectionref_steer(Section* sec, Symbol* sym, int* pnindex); //, *nrn_sectionref_steer(); + extern Section* nrn_sectionref_steer(Section* sec, Symbol* sym, int* pnindex); section_object_seen = 1; sec = (Section*)obp->u.this_pointer; if (sym != nrn_sec_sym) { @@ -1272,7 +1272,6 @@ void hoc_object_eval(void) { #if CABLE Datum* d = hoc_look_inside_stack(0, SYMBOL); if (d->sym->type == RANGEVAR) { -// double* nrn_rangepointer(); Symbol* sym = hoc_spop(); int narg = hoc_ipop(); struct Section* sec = nrn_sec_pop(); @@ -1315,7 +1314,6 @@ void hoc_ob_pointer(void) { } hoc_pushpx(nrn_rangepointer(sec, sym, x)); }else if (d->sym->type == VAR && d->sym->subtype == USERPROPERTY) { -// double* cable_prop_eval_pointer(); hoc_pushpx(cable_prop_eval_pointer(hoc_spop())); }else{ hoc_execerror("Not a double pointer", 0); @@ -1514,15 +1512,15 @@ void hoc_endtemplate(Symbol* t) { hoc_in_template = (poptemplate())->i; hoc_objectdata = (poptemplate())->odata; icntobjectdata = (poptemplate())->i; -ts->u.ctemplate->init = s = hoc_table_lookup("init", ts->u.ctemplate->symtable); + ts->u.ctemplate->init = s = hoc_table_lookup("init", ts->u.ctemplate->symtable); if (s && s->type != PROCEDURE) { -hoc_execerror("'init' can only be used as the initialization procedure for new objects", - (char *)0); + hoc_execerror("'init' can only be used as the initialization procedure for new objects", + nullptr); } -ts->u.ctemplate->unref = s = hoc_table_lookup("unref", ts->u.ctemplate->symtable); + ts->u.ctemplate->unref = s = hoc_table_lookup("unref", ts->u.ctemplate->symtable); if (s && s->type != PROCEDURE) { -hoc_execerror("'unref' can only be used as the callback procedure when the reference count is decremented", - (char *)0); + hoc_execerror("'unref' can only be used as the callback procedure when the reference count is decremented", + nullptr); } } @@ -1983,7 +1981,7 @@ printf("unreffing %s with refcount %d\n", hoc_object_name(obj), obj->refcount); if (--obj->ctemplate->count <= 0) { obj->ctemplate->index = 0; } - obj->ctemplate = (cTemplate *)0; + obj->ctemplate = nullptr; /* for testing purposes we don't free the object in order to make sure no object variable ever uses a freed object */ #if 1 @@ -2027,7 +2025,6 @@ static void free_objectdata(Objectdata *od, cTemplate *ctemplate){ case SECTION: total = hoc_total_array(s); for (i = 0; i < total; ++i) { -// extern void sec_free(); sec_free(*(OPSECITM(s) + i)); } free(OPSECITM(s)); diff --git a/src/oc/hocdec.h b/src/oc/hocdec.h index 733a09ca1b..7d961c7e72 100644 --- a/src/oc/hocdec.h +++ b/src/oc/hocdec.h @@ -117,6 +117,10 @@ typedef struct Symbol { /* symbol table entry */ char *name; short type; short subtype; /* Flag for user integers */ +/** + * Note: `public` is a reserved keyword. Keeping following __cplusplus comments a bit longer + * for future reference, with upcoming work for NMODL + eventual mod files to support cpp. + */ //#if defined(__cplusplus) short cpublic; /* flag set public variable */ //#else diff --git a/src/oc/hocedit.cpp b/src/oc/hocedit.cpp index 2ace3a34c5..4553218b08 100755 --- a/src/oc/hocedit.cpp +++ b/src/oc/hocedit.cpp @@ -192,7 +192,6 @@ void hoc_pipeflush(void) } size_t hoc_pipegets_need(void) { -// int hoc_strgets_need(); #if !OCSMALL if (hoc_pipeflag == 1) { if (lp == lhead) { diff --git a/src/oc/hoclist.h b/src/oc/hoclist.h index d7caf04b32..43c9d9da2b 100755 --- a/src/oc/hoclist.h +++ b/src/oc/hoclist.h @@ -74,7 +74,6 @@ typedef struct hoc_Item { /* * An item type, STRING is also used as an item type */ -// extern char *hoc_l_stralloc(const char *, char *release); extern hoc_List *hoc_l_newlist(); diff --git a/src/oc/oc_ansi.h b/src/oc/oc_ansi.h index 24c01b8c6a..019e63b3c0 100644 --- a/src/oc/oc_ansi.h +++ b/src/oc/oc_ansi.h @@ -270,13 +270,7 @@ extern int hoc_sred(const char*, char*, char*); extern int nrnpy_pr(const char* fmt, ...); extern int Fprintf(FILE*, const char* fmt, ...); extern void nrnpy_pass(); - -//#if defined (__cplusplus) extern void hoc_free_allobjects(cTemplate*, Symlist*, Objectdata*); -//#else -//extern void hoc_free_allobjects(cTemplate*, Symlist*, Objectdata*); -//#endif - extern int nrn_is_cable(void); extern int nrn_isdouble(double*, double, double); diff --git a/src/oc/ocmisc.h b/src/oc/ocmisc.h index 6881314b85..91d6e1497f 100644 --- a/src/oc/ocmisc.h +++ b/src/oc/ocmisc.h @@ -1,7 +1,6 @@ #ifndef ocmisc_h #define ocmisc_h - extern long hoc_nstack; extern long hoc_nframe; extern int hoc_errno_count; @@ -9,6 +8,4 @@ extern int hoc_pipeflag; extern int hoc_in_yyparse; extern int hoc_intset; - - #endif diff --git a/src/oc/parallel.cpp b/src/oc/parallel.cpp index 4f91fa5a7b..c15a53a708 100755 --- a/src/oc/parallel.cpp +++ b/src/oc/parallel.cpp @@ -41,8 +41,7 @@ void hoc_parallel_begin(void) { #if !OCSMALL Symbol *sym; double first, last; - char *method; //, *getenv(); -// int parallel_hoc_main(); + char *method; int i, j; diff --git a/src/oc/plt.cpp b/src/oc/plt.cpp index a343c94e03..dc6f0454b7 100755 --- a/src/oc/plt.cpp +++ b/src/oc/plt.cpp @@ -5,8 +5,6 @@ */ #include "hoc.h" #include "gui-redirect.h" - - extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); extern double (*nrnpy_object_to_double_)(Object*); @@ -72,5 +70,4 @@ void hoc_Lw(void) pushx(0.); } - #endif /*!defined(CYGWIN)*/ diff --git a/src/oc/redef.h b/src/oc/redef.h index d84eebf400..27971c5e74 100755 --- a/src/oc/redef.h +++ b/src/oc/redef.h @@ -3,9 +3,6 @@ #ifndef hoc_redef_h #define hoc_redef_h - - - # define Break hoc_Break # define Continue hoc_Continue # define Exp hoc_Exp @@ -140,5 +137,4 @@ # define xopen hoc_xopen # define zzdebug hoc_zzdebug - #endif diff --git a/src/parallel/bbslsrv.cpp b/src/parallel/bbslsrv.cpp index 65b7f24bbd..b2d52e4cad 100644 --- a/src/parallel/bbslsrv.cpp +++ b/src/parallel/bbslsrv.cpp @@ -103,9 +103,7 @@ class MessageList {}; class WorkList {}; class ReadyList{}; class ResultList{}; -extern "C" { - extern void hoc_execerror(const char*, const char*); -} // extern "C" +extern "C" void hoc_execerror(const char*, const char*); static void nostl() { hoc_execerror("BBSLocalServer not working", "Compiled without STL"); } diff --git a/src/sundials/shared/nvector_parallel.c b/src/sundials/shared/nvector_parallel.c index 420e1637bc..19c3c05c01 100755 --- a/src/sundials/shared/nvector_parallel.c +++ b/src/sundials/shared/nvector_parallel.c @@ -22,8 +22,8 @@ /* for NRNMPI_DYNAMICLOAD */ #include #if NRNMPI_DYNAMICLOAD -extern /*"C"*/ void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type); -extern /*"C"*/ void nrnmpi_long_allreduce_vec(long* src, long* dest, int cnt, int type); +extern void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type); +extern void nrnmpi_long_allreduce_vec(long* src, long* dest, int cnt, int type); extern int nrnmpi_numprocs; #endif diff --git a/src/uxnrnbbs/nrnbbs.cpp b/src/uxnrnbbs/nrnbbs.cpp index ee0ff6fe8a..340c38fdd7 100644 --- a/src/uxnrnbbs/nrnbbs.cpp +++ b/src/uxnrnbbs/nrnbbs.cpp @@ -13,7 +13,6 @@ #include #include -extern "C" { extern int mkdir(const char*, int); } #include #include diff --git a/test/unit_tests/oc/hoc_interpreter.cpp b/test/unit_tests/oc/hoc_interpreter.cpp index 78fc703e10..55c49e08c6 100644 --- a/test/unit_tests/oc/hoc_interpreter.cpp +++ b/test/unit_tests/oc/hoc_interpreter.cpp @@ -1,10 +1,8 @@ #include -//extern "C" { #include #include #include -//} // extern "C TEST_CASE("Test hoc interpreter", "[Neuron][hoc_interpreter]") { hoc_init_space(); diff --git a/test/unit_tests/unit_test.cpp b/test/unit_tests/unit_test.cpp index 5da8ce51f5..17fa148fc5 100644 --- a/test/unit_tests/unit_test.cpp +++ b/test/unit_tests/unit_test.cpp @@ -2,7 +2,6 @@ #include -//extern "C" { #include #include #include @@ -14,7 +13,6 @@ extern int ivocmain_session(int, const char**, const char**, int); extern int nrn_main_launch; extern int nrn_nobanner_; -//} // extern "C" /// Needed for compilation void modl_reg() { } From 93948771167cca7b0b4ed33a16b090273feb6949 Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Mon, 9 Nov 2020 16:52:02 +0100 Subject: [PATCH 07/17] fix segfault + more extern "C" --- src/nrnoc/cabcode.cpp | 4 ++-- src/nrnoc/init.cpp | 2 +- src/nrnoc/nrn_ansi.h | 7 +++---- src/oc/hoc_oop.cpp | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/nrnoc/cabcode.cpp b/src/nrnoc/cabcode.cpp index 46d7b7f5d5..7fdd9e8e66 100644 --- a/src/nrnoc/cabcode.cpp +++ b/src/nrnoc/cabcode.cpp @@ -1070,7 +1070,7 @@ static int range_vec_indx(Symbol* s) return indx; } -Prop* nrn_mechanism(int type, Node* nd) /* returns property for mechanism at the node */ +extern "C" Prop* nrn_mechanism(int type, Node* nd) /* returns property for mechanism at the node */ { Prop *m; for (m = nd->prop; m; m = m->next) { @@ -1947,7 +1947,7 @@ int segment_limits(double* pdx) #undef PI #define PI 3.14159265358979323846 -Node* node_exact(Section* sec, double x) +extern "C" Node* node_exact(Section* sec, double x) { /* like node_index but give proper node when x is 0 or 1 as well as in between diff --git a/src/nrnoc/init.cpp b/src/nrnoc/init.cpp index 0f95517a87..6444534f20 100644 --- a/src/nrnoc/init.cpp +++ b/src/nrnoc/init.cpp @@ -1019,7 +1019,7 @@ extern "C" void _nrn_setdata_reg(int i, void(*call)(Prop*)) { memb_func[i].setdata_ = call; } /* there is some question about the _extcall_thread variables, if any. */ -double nrn_call_mech_func(Symbol* s, int narg, Prop* p, int type) { +extern "C" double nrn_call_mech_func(Symbol* s, int narg, Prop* p, int type) { double x; extern double hoc_call_func(Symbol*, int); void (*call)(Prop*) = memb_func[type].setdata_; diff --git a/src/nrnoc/nrn_ansi.h b/src/nrnoc/nrn_ansi.h index 2e8c7c9e35..7e4acf0af2 100644 --- a/src/nrnoc/nrn_ansi.h +++ b/src/nrnoc/nrn_ansi.h @@ -19,7 +19,8 @@ extern void modl_reg(void); // nrnmech stuff extern void _nrn_free_fornetcon(void**); - +extern double nrn_call_mech_func(Symbol*, int narg, Prop*, int type); +extern Prop* nrn_mechanism(int type, Node*); // mod stuff extern void _nrn_free_watch(Datum *, int, int); @@ -31,6 +32,7 @@ extern void nrn_pushsec(Section*); extern void nrn_popsec(void); extern Section* chk_access(void); +extern Node* node_exact(Section*, double); #if defined(__cplusplus) } @@ -120,14 +122,12 @@ extern void section_unref(Section*); extern const char* secname(Section*); extern const char* nrn_sec2pysecname(Section*); extern void nrn_rangeconst(Section*, Symbol*, double* value, int op); -extern Prop* nrn_mechanism(int type, Node*); extern int nrn_exists(Symbol*, Node*); extern double* nrn_rangepointer(Section*, Symbol*, double x); extern double* cable_prop_eval_pointer(Symbol*); // section on stack will be popped extern char* hoc_section_pathname(Section*); extern double nrn_arc_position(Section*, Node*); extern double node_dist(Section*, Node*); // distance of node to parent position -extern Node* node_exact(Section*, double); extern double nrn_section_orientation(Section*); extern double nrn_connection_position(Section*); extern Section* nrn_trueparent(Section*); @@ -139,7 +139,6 @@ extern short nrn_value_mark(Section*); extern int is_point_process(Object*); extern int nrn_vartype(Symbol*); // nrnocCONST, DEP, STATE extern void recalc_diam(void); -extern double nrn_call_mech_func(Symbol*, int narg, Prop*, int type); extern Prop* nrn_mechanism_check(int type, Section* sec, int inode); extern int nrn_use_fast_imem; extern void nrn_fast_imem_alloc(); diff --git a/src/oc/hoc_oop.cpp b/src/oc/hoc_oop.cpp index f36fcba5d4..947987ede1 100755 --- a/src/oc/hoc_oop.cpp +++ b/src/oc/hoc_oop.cpp @@ -430,7 +430,7 @@ void hoc_oop_initaftererror(void) { extern "C" void oc_save_hoc_oop( Object* *a1, Objectdata* *a2, - int **a3, // TODO a3 was missing + // a3 is missing, do not add it int *a4, Symlist* *a5 ){ From b4e11ecb7417c6b33b32f84647757951d3537f00 Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Mon, 9 Nov 2020 17:17:24 +0100 Subject: [PATCH 08/17] more CR --- src/ivoc/xdep.cpp | 1 + src/nrnjava/njvm.cpp | 2 +- src/nrnoc/point.cpp | 4 ++-- src/oc/hoc_init.cpp | 1 - src/oc/hoc_oop.cpp | 1 - src/oc/oc_ansi.h | 1 - 6 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ivoc/xdep.cpp b/src/ivoc/xdep.cpp index 503018f247..eb705494f3 100644 --- a/src/ivoc/xdep.cpp +++ b/src/ivoc/xdep.cpp @@ -204,6 +204,7 @@ void get_position(XDisplay* dpy, XWindow window, int* rx, int* ry) //if (xoff != -999) { // *rx -= xoff; // *ry -= yoff; +//} } #endif diff --git a/src/nrnjava/njvm.cpp b/src/nrnjava/njvm.cpp index 9bfb972a6c..0efd94dacd 100644 --- a/src/nrnjava/njvm.cpp +++ b/src/nrnjava/njvm.cpp @@ -248,7 +248,7 @@ static void initialize_jvm1() { args.classpath = classpath; //for (int i = 0; args.properties[i]; ++i) { //printf("properties |%s|\n", args.properties[i]); - } // extern "C" + //} //args.debugging = 1; //args.vfprintf = myvfprintf; printf("classpath |%s|\n", args.classpath); diff --git a/src/nrnoc/point.cpp b/src/nrnoc/point.cpp index 053da711cc..d30b66a7f4 100755 --- a/src/nrnoc/point.cpp +++ b/src/nrnoc/point.cpp @@ -87,7 +87,7 @@ void nrn_loc_point_process(int pointtype, Point_process* pnt, Section* sec, Node extern Prop* prop_alloc(Prop**, int, Node*); extern Section* nrn_pnt_sec_for_need_; Prop* p; - double x; //, nrn_arc_position(); + double x; assert(!nrn_is_artificial_[pointsym[pointtype]->subtype]); x = nrn_arc_position(sec, node); @@ -238,7 +238,7 @@ extern "C" double get_loc_point_process(void* v) #if METHOD3 extern int _method3; #endif - double x; //, nrn_arc_position(); + double x; Point_process *pnt = (Point_process*)v; Section* sec; diff --git a/src/oc/hoc_init.cpp b/src/oc/hoc_init.cpp index d4f54b2834..149270d204 100755 --- a/src/oc/hoc_init.cpp +++ b/src/oc/hoc_init.cpp @@ -421,4 +421,3 @@ void hoc_Execerror(void) { } /* never get here */ } -// diff --git a/src/oc/hoc_oop.cpp b/src/oc/hoc_oop.cpp index 947987ede1..0090679ab4 100755 --- a/src/oc/hoc_oop.cpp +++ b/src/oc/hoc_oop.cpp @@ -1302,7 +1302,6 @@ void hoc_ob_pointer(void) { #if CABLE Datum* d = hoc_look_inside_stack(0, SYMBOL); if (d->sym->type == RANGEVAR) { -// double* nrn_rangepointer(Symbol *); Symbol* sym = hoc_spop(); int nindex = hoc_ipop(); struct Section* sec = nrn_sec_pop(); diff --git a/src/oc/oc_ansi.h b/src/oc/oc_ansi.h index 019e63b3c0..c9c6751836 100644 --- a/src/oc/oc_ansi.h +++ b/src/oc/oc_ansi.h @@ -22,7 +22,6 @@ #if defined(__cplusplus) -//#include "ivocvect.h" class IvocVect; #else #define IvocVect void From 343cb07885f46bbb22fc4d2a63561cc0698ef23c Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Tue, 10 Nov 2020 10:34:37 +0100 Subject: [PATCH 09/17] fix modlunit --- src/modlunit/io.cpp | 2 +- src/modlunit/list.cpp | 4 ++-- src/modlunit/symbol.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modlunit/io.cpp b/src/modlunit/io.cpp index 463d0b1603..a74d8c6d55 100755 --- a/src/modlunit/io.cpp +++ b/src/modlunit/io.cpp @@ -337,7 +337,7 @@ void include_file(Item* q) void pop_file_stack() { FileStackItem* fsi; fsi = (FileStackItem*)(SYM(filestack->prev)); - delete(filestack->prev); + remove(filestack->prev); linenum = fsi->linenum; inlinep = fsi->inlinep; fclose(fin); diff --git a/src/modlunit/list.cpp b/src/modlunit/list.cpp index 0ccce823dc..c8cfcd4daa 100755 --- a/src/modlunit/list.cpp +++ b/src/modlunit/list.cpp @@ -222,9 +222,9 @@ void deltokens(Item* q1, Item* q2) /* delete tokens from q1 to q2 */ Item *q; for (q = q1; q != q2;) { q = q->next; - delete(q->prev); + remove(q->prev); } - delete(q2); + remove(q2); } diff --git a/src/modlunit/symbol.cpp b/src/modlunit/symbol.cpp index 7c5e494907..b5a00094e3 100755 --- a/src/modlunit/symbol.cpp +++ b/src/modlunit/symbol.cpp @@ -98,9 +98,9 @@ void poplocal() sl = (List *)symlistlist->next->element; for (i = sl->next; i != sl; i = j) { j = i->next; - delete(i); + remove(i); } - delete(symlistlist->next); + remove(symlistlist->next); } void install_local(Item* q, Item* qdim) From b936e6f2f2a2c9daeacf50f8f08227bf410cb0de Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Thu, 21 Jan 2021 16:43:35 +0100 Subject: [PATCH 10/17] hocusr.h accidentally committed --- .gitignore | 1 + src/nrnoc/hocusr.h | 186 --------------------------------------------- 2 files changed, 1 insertion(+), 186 deletions(-) delete mode 100644 src/nrnoc/hocusr.h diff --git a/.gitignore b/.gitignore index e3aed50ce7..daf0bc1cdb 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ src/nrnoc/expsyn.c src/nrnoc/feature.c src/nrnoc/hh.c src/nrnoc/hh.mod.orig +src/nrnoc/hocusr.h src/nrnoc/intfire1.c src/nrnoc/intfire2.c src/nrnoc/intfire4.c diff --git a/src/nrnoc/hocusr.h b/src/nrnoc/hocusr.h deleted file mode 100644 index cbb8b6f6d0..0000000000 --- a/src/nrnoc/hocusr.h +++ /dev/null @@ -1,186 +0,0 @@ -extern void node_data(), disconnect(); -extern void batch_run(), batch_save(); -extern void pt3dclear(), pt3dadd(), n3d(), x3d(), y3d(), z3d(), arc3d(), diam3d(); -extern void pt3dinsert(), pt3dremove(), pt3dchange(); -extern void define_shape(), pt3dconst(), pt3dstyle(); -extern void spine3d(), setSpineArea(), getSpineArea(); -extern void area(), ri(); -extern void initnrn(), nrnhoc_topology(), fadvance(), distance(), finitialize(); -extern void fstim(), fstimi(); -extern void ion_style(), ion_register(), ion_charge(), nernst(), ghk(); -extern void section_owner(); -extern void make_mechanism(), make_pointprocess(); -extern void nrnpython(); -extern void fsyn(), fsyng(), fsyni(); -extern void fclamp(), fclampi(), fclampv(), prstim(); -extern void fcurrent(), fmatrix(), frecord_init(); -extern void issection(), ismembrane(), sectionname(), psection(); -extern void pop_section(), push_section(), section_exists(); -extern void delete_section(); -extern int secondorder, diam_changed, nrn_shape_changed_, nrn_netrec_state_adjust, nrn_sparse_partrans; -extern double clamp_resist; -extern double celsius; -extern int stoprun; -extern void fit_praxis(), attr_praxis(), pval_praxis(), stop_praxis(); -extern void keep_nseg_parm(); -extern void nrnallsectionmenu(), nrnallpointmenu(), nrnsecmenu(); -extern void nrnglobalmechmenu(), nrnmechmenu(), nrnpointmenu(); -extern void this_section(), this_node(), parent_section(), parent_node(); -extern void parent_connection(), section_orientation(); -extern void nrnunit_use_legacy(); -/* Functions */ -static VoidFunc functions[] = { - -"node_data", node_data, -"disconnect", disconnect, -"batch_run", batch_run, -"batch_save", batch_save, -"pt3dclear", pt3dclear, -"pt3dadd", pt3dadd, -"n3d", n3d, -"x3d", x3d, -"y3d", y3d, -"z3d", z3d, -"arc3d", arc3d, -"diam3d", diam3d, -"pt3dinsert", pt3dinsert, -"pt3dremove", pt3dremove, -"pt3dchange", pt3dchange, -"define_shape", define_shape, -"pt3dconst", pt3dconst, -"pt3dstyle", pt3dstyle, -"spine3d", spine3d, -"setSpineArea", setSpineArea, -"getSpineArea", getSpineArea, -"area", area, -"ri", ri, -"initnrn", initnrn, -"topology", nrnhoc_topology, -"fadvance", fadvance, -"distance", distance, -"finitialize", finitialize, -"fstim", fstim, -"fstimi", fstimi, -"ion_style", ion_style, -"ion_register", ion_register, -"ion_charge", ion_charge, -"nernst", nernst, -"ghk", ghk, -"section_owner", section_owner, -"make_mechanism", make_mechanism, -"make_pointprocess", make_pointprocess, -"nrnpython", nrnpython, -"fsyn", fsyn, -"fsyng", fsyng, -"fsyni", fsyni, -"fclamp", fclamp, -"fclampi", fclampi, -"fclampv", fclampv, -"prstim", prstim, -"fcurrent", fcurrent, -"fmatrix", fmatrix, -"frecord_init", frecord_init, -"issection", issection, -"ismembrane", ismembrane, -"sectionname", sectionname, -"psection", psection, -"pop_section", pop_section, -"push_section", push_section, -"section_exists", section_exists, -"delete_section", delete_section, -"fit_praxis", fit_praxis, -"attr_praxis", attr_praxis, -"pval_praxis", pval_praxis, -"stop_praxis", stop_praxis, -"keep_nseg_parm", keep_nseg_parm, -"nrnallsectionmenu", nrnallsectionmenu, -"nrnallpointmenu", nrnallpointmenu, -"nrnsecmenu", nrnsecmenu, -"nrnglobalmechmenu", nrnglobalmechmenu, -"nrnmechmenu", nrnmechmenu, -"nrnpointmenu", nrnpointmenu, -"this_section", this_section, -"this_node", this_node, -"parent_section", parent_section, -"parent_node", parent_node, -"parent_connection", parent_connection, -"section_orientation", section_orientation, -"nrnunit_use_legacy", nrnunit_use_legacy, -0, 0 -}; - -static struct { /* Integer Scalars */ - const char *name; - int *pint; -} scint[] = { - -"secondorder", &secondorder, -"diam_changed", &diam_changed, -"nrn_shape_changed_", &nrn_shape_changed_, -"nrn_netrec_state_adjust", &nrn_netrec_state_adjust, -"nrn_sparse_partrans", &nrn_sparse_partrans, -"stoprun", &stoprun, -0, 0 -}; - -static struct { /* Vector integers */ - const char *name; - int *pint; - int index1; -} vint[] = { - -0,0 -}; - -static struct { /* Float Scalars */ - const char *name; - float *pfloat; -} scfloat[] = { - -0, 0 -}; - -static struct { /* Vector float */ - const char *name; - float *pfloat; - int index1; -} vfloat[] = { - -0,0,0 -}; - -/* Double Scalars */ -DoubScal scdoub[] = { - -"clamp_resist", &clamp_resist, -"celsius", &celsius, -0,0 -}; - -/* Vectors */ -DoubVec vdoub[] = { - -0, 0, 0 -}; - -static struct { /* Arrays */ - const char *name; - double *pdoub; - int index1; - int index2; -} ardoub[] = { - -0, 0, 0, 0 -}; - -static struct { /* triple dimensioned arrays */ - const char *name; - double *pdoub; - int index1; - int index2; - int index3; -} thredim[] = { - -0, 0, 0, 0, 0 -}; - From 865a15fd1bfc0572182e36836e4c1ba3639788a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandru=20S=C4=83vulescu?= Date: Sat, 30 Jan 2021 11:12:01 +0100 Subject: [PATCH 11/17] init.cpp TODO - nrn_threads_create single thread --- src/nrnoc/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrnoc/init.cpp b/src/nrnoc/init.cpp index 1f99d9bbf6..1c38d90061 100644 --- a/src/nrnoc/init.cpp +++ b/src/nrnoc/init.cpp @@ -291,7 +291,7 @@ void hoc_last_init(void) Symbol *s; hoc_register_var(scdoub, (DoubVec*)0, (VoidFunc*)0); - nrn_threads_create(1,0); //TODO - 2nd param? + nrn_threads_create(1, 0); // single thread if (nrnmpi_myid < 1) if (nrn_nobanner_ == 0) { extern char* nrn_version(int i); From dc62f2f09289f221282c35a417cee0ebd4dd0cb8 Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Tue, 2 Feb 2021 16:39:03 +0100 Subject: [PATCH 12/17] rollback CR requested change - #951 --- src/nmodl/modl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nmodl/modl.cpp b/src/nmodl/modl.cpp index 6bf7a3e33f..bd61945da3 100755 --- a/src/nmodl/modl.cpp +++ b/src/nmodl/modl.cpp @@ -360,5 +360,5 @@ static std::string str_replace(std::string str, const std::string& search_str, c void verbatim_adjust(char* q) { const std::string repl = str_replace(q, "u.template", "u.ctemplate"); - Fprintf(fcout, "%s\n", repl.c_str()); + Fprintf(fcout, "%s", repl.c_str()); } From 68e28a7a9915d6dc052bf048f4f7a5de79206daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandru=20S=C4=83vulescu?= Date: Tue, 2 Feb 2021 22:01:26 +0100 Subject: [PATCH 13/17] CR: no ignore flags for other compilers --- cmake/CompilerFlagsHelpers.cmake | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmake/CompilerFlagsHelpers.cmake b/cmake/CompilerFlagsHelpers.cmake index 6d6689f54b..f7e0508eae 100644 --- a/cmake/CompilerFlagsHelpers.cmake +++ b/cmake/CompilerFlagsHelpers.cmake @@ -99,9 +99,7 @@ foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST}) set(CMAKE_${COMPILER_LANGUAGE}_STACK_PROTECTION "") set(CMAKE_${COMPILER_LANGUAGE}_POSITION_INDEPENDENT "-fPIC") set(CMAKE_${COMPILER_LANGUAGE}_VECTORIZE "") - set(CMAKE_${COMPILER_LANGUAGE}_IGNORE_WARNINGS "-Wno-deprecated-register -Wno-writable-strings") if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "PGI") - set(CMAKE_${COMPILER_LANGUAGE}_IGNORE_WARNINGS "") set(CMAKE_${COMPILER_LANGUAGE}_WARNING_ALL "") endif() endif() From cb593f9e950af10cf7fe284f8186f974fcef9bcd Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Wed, 3 Feb 2021 12:00:27 +0100 Subject: [PATCH 14/17] CR updates --- src/mswin/extra/splitnrn.cpp | 2 +- src/mswin/rdln/readline.cpp | 2 +- src/nmodl/lex.lpp | 1 - src/nmodl/modl.cpp | 2 ++ src/nmodl/noccout.cpp | 2 +- src/nmodl/nocpout.cpp | 2 +- src/nrnoc/init.cpp | 3 --- src/nrnoc/treeset.cpp | 2 +- src/oc/mcran4.cpp | 2 +- 9 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/mswin/extra/splitnrn.cpp b/src/mswin/extra/splitnrn.cpp index b39b440058..456e1f9279 100755 --- a/src/mswin/extra/splitnrn.cpp +++ b/src/mswin/extra/splitnrn.cpp @@ -8,7 +8,7 @@ void main(int argc, char** argv) { long i, j, n, done; FILE* fi, *fo; char* buf; - buf = malloc(1024*16); + buf = (char*)malloc(1024*16); if (argc != 2) { printf("usage: splitnrn nrndisk2\n"); exit(1); diff --git a/src/mswin/rdln/readline.cpp b/src/mswin/rdln/readline.cpp index a6589e5a68..0d647354e0 100755 --- a/src/mswin/rdln/readline.cpp +++ b/src/mswin/rdln/readline.cpp @@ -3289,7 +3289,7 @@ rl_insert (count, c) else { /* Inserting a single character. */ - string = alloca (2); + string = (char*)alloca (2); string[1] = '\0'; string[0] = c; rl_insert_text (string); diff --git a/src/nmodl/lex.lpp b/src/nmodl/lex.lpp index b57905cd22..1b673ed30d 100755 --- a/src/nmodl/lex.lpp +++ b/src/nmodl/lex.lpp @@ -27,7 +27,6 @@ extern int unGetc(int); extern int unput(int); static int input(); static int yyinput(); -//TODO - does this actually work? int newinput() { #ifdef __cplusplus return yyinput(); diff --git a/src/nmodl/modl.cpp b/src/nmodl/modl.cpp index bd61945da3..0da8b458b2 100755 --- a/src/nmodl/modl.cpp +++ b/src/nmodl/modl.cpp @@ -358,7 +358,9 @@ static std::string str_replace(std::string str, const std::string& search_str, c return str; } +// Post-adjustments for VERBATIM blocks (i.e make them compatible with CPP). void verbatim_adjust(char* q) { + // template is a reserved CPP keyword const std::string repl = str_replace(q, "u.template", "u.ctemplate"); Fprintf(fcout, "%s", repl.c_str()); } diff --git a/src/nmodl/noccout.cpp b/src/nmodl/noccout.cpp index 47cc2123c9..ddddb53fe8 100755 --- a/src/nmodl/noccout.cpp +++ b/src/nmodl/noccout.cpp @@ -921,7 +921,7 @@ diag("current can only be LOCAL in a BREAKPOINT if CONDUCTANCE statements are us P(" if (!_first) return;\n"); printlist(initlist); P("_first = 0;\n}\n"); - //P("\n#if defined(__cplusplus)\n} /* extern \"C\" */\n#endif\n"); // TODO - can this be removed? + P("\n#if defined(__cplusplus)\n} /* extern \"C\" */\n#endif\n"); } void vectorize_substitute(Item* q, char* str) diff --git a/src/nmodl/nocpout.cpp b/src/nmodl/nocpout.cpp index 22370155fa..30095753b0 100755 --- a/src/nmodl/nocpout.cpp +++ b/src/nmodl/nocpout.cpp @@ -340,7 +340,7 @@ fprintf(stderr, "Notice: ARTIFICIAL_CELL models that would require thread specif declare_p(); ioncount = iondef(&pointercount); /* first is _nd_area if point process */ Lappendstr(defs_list, "\n#if MAC\n#if !defined(v)\n#define v _mlhv\n#endif\n#if !defined(h)\n#define h _mlhh\n#endif\n#endif\n"); -// Lappendstr(defs_list, "\n#if defined(__cplusplus)\nextern \"C\" {\n#endif\n"); //TODO - can this be removed? otherwise rely on dirty fix: __cminusminus + Lappendstr(defs_list, "\n#if defined(__cplusplus)\nextern \"C\" {\n#endif\n"); Lappendstr(defs_list, "static int hoc_nrnpointerindex = "); if (pointercount) { q = nrnpointers->next; diff --git a/src/nrnoc/init.cpp b/src/nrnoc/init.cpp index 1c38d90061..b61d9eaeba 100644 --- a/src/nrnoc/init.cpp +++ b/src/nrnoc/init.cpp @@ -1019,6 +1019,3 @@ void nrnunit_use_legacy() { } hoc_retpushx((double)_nrnunit_use_legacy_); } -//#if defined(__cplusplus) -//} -//#endif diff --git a/src/nrnoc/treeset.cpp b/src/nrnoc/treeset.cpp index c2262dfa6f..25cf7dbc93 100644 --- a/src/nrnoc/treeset.cpp +++ b/src/nrnoc/treeset.cpp @@ -1020,7 +1020,7 @@ void pt3dstyle(void) { if (hoc_is_pdouble_arg(2)) { Pt3d* p = sec->logical_connection; if (p) { - double* px; // , *hoc_pgetarg(); + double* px; px = hoc_pgetarg(2); *px = p->x; px = hoc_pgetarg(3); *px = p->y; px = hoc_pgetarg(4); *px = p->z; diff --git a/src/oc/mcran4.cpp b/src/oc/mcran4.cpp index e89c1ee6c7..3568b10cf0 100755 --- a/src/oc/mcran4.cpp +++ b/src/oc/mcran4.cpp @@ -69,7 +69,7 @@ extern "C" uint32_t mcell_iran4(uint32_t *high){ } /* Hoc interface */ -extern double chkarg(); // , *hoc_pgetarg(); +extern double chkarg(); extern int use_mcell_ran4_; From e7a16fc38f3bb86ca3fcf2264f2b9da58669639f Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Wed, 3 Feb 2021 14:38:55 +0100 Subject: [PATCH 15/17] CR - one last Windows thingy --- src/nrnoc/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrnoc/init.cpp b/src/nrnoc/init.cpp index b61d9eaeba..cabb9cd27c 100644 --- a/src/nrnoc/init.cpp +++ b/src/nrnoc/init.cpp @@ -25,7 +25,7 @@ static char banner[] = See http://neuron.yale.edu/neuron/credits\n"; #ifdef WIN32 -#if defined(HAVE_DLFCN_H) && !defined(MINGW) +#if defined(HAVE_DLFCN_H) && !defined(__MINGW32__) #include #else #define RTLD_NOW 0 From a1966e2f1a7e04e7eeb8ce2078576fd9b10966c9 Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Wed, 3 Feb 2021 14:56:57 +0100 Subject: [PATCH 16/17] ignore warnings for Clang compilers --- cmake/CompilerFlagsHelpers.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/CompilerFlagsHelpers.cmake b/cmake/CompilerFlagsHelpers.cmake index f7e0508eae..d5888bcb77 100644 --- a/cmake/CompilerFlagsHelpers.cmake +++ b/cmake/CompilerFlagsHelpers.cmake @@ -102,5 +102,8 @@ foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST}) if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "PGI") set(CMAKE_${COMPILER_LANGUAGE}_WARNING_ALL "") endif() + if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID MATCHES "Clang|AppleClang") + set(CMAKE_${COMPILER_LANGUAGE}_IGNORE_WARNINGS "-Wno-deprecated-register -Wno-writable-strings") + endif() endif() endforeach() From e717d1e780449953ac42ec4b303227e49b81341f Mon Sep 17 00:00:00 2001 From: Alexandru Savulescu Date: Wed, 3 Feb 2021 15:16:57 +0100 Subject: [PATCH 17/17] rxd: nrn_shape_update must be extern "C" now --- src/ivoc/ivoc.cpp | 2 +- src/ivoc/ocnoiv1.cpp | 2 +- src/nrniv/bbsavestate.cpp | 2 +- src/nrniv/savstate.cpp | 2 +- src/nrnoc/treeset.cpp | 2 +- src/oc/nocable.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ivoc/ivoc.cpp b/src/ivoc/ivoc.cpp index e833e67545..7271244d54 100644 --- a/src/ivoc/ivoc.cpp +++ b/src/ivoc/ivoc.cpp @@ -177,7 +177,7 @@ ENDGUI extern void hoc_pushx(double); extern FILE* hoc_fin; extern void ivoc_cleanup(); - extern void nrn_shape_update(); + extern "C" void nrn_shape_update(); extern int bbs_poll_; extern void bbs_handle(); diff --git a/src/ivoc/ocnoiv1.cpp b/src/ivoc/ocnoiv1.cpp index 05849bb434..e29c37e8ac 100755 --- a/src/ivoc/ocnoiv1.cpp +++ b/src/ivoc/ocnoiv1.cpp @@ -8,7 +8,7 @@ extern void hoc_ret(); extern void hoc_pushx(double); -extern void nrn_shape_update(); +extern "C" void nrn_shape_update(); extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj); extern Object** (*nrnpy_gui_helper3_)(const char* name, Object* obj, int handle_strptr); extern double (*nrnpy_object_to_double_)(Object*); diff --git a/src/nrniv/bbsavestate.cpp b/src/nrniv/bbsavestate.cpp index e5ff041747..c9818d1573 100644 --- a/src/nrniv/bbsavestate.cpp +++ b/src/nrniv/bbsavestate.cpp @@ -196,7 +196,7 @@ typedef void (*ReceiveFunc)(Point_process*, double*, double); #include "membfunc.h" extern int section_count; -extern void nrn_shape_update(); +extern "C" void nrn_shape_update(); extern Section* nrn_section_exists(char* name, int index, Object* cell); extern Section** secorder; extern ReceiveFunc* pnt_receive; diff --git a/src/nrniv/savstate.cpp b/src/nrniv/savstate.cpp index 2f139f2984..a1105243bc 100644 --- a/src/nrniv/savstate.cpp +++ b/src/nrniv/savstate.cpp @@ -15,7 +15,7 @@ typedef void (*ReceiveFunc)(Point_process*, double*, double); #include "membfunc.h" extern int section_count; -extern void nrn_shape_update(); +extern "C" void nrn_shape_update(); extern Section** secorder; extern ReceiveFunc* pnt_receive; extern NetCvode* net_cvode_instance; diff --git a/src/nrnoc/treeset.cpp b/src/nrnoc/treeset.cpp index 25cf7dbc93..b99230171b 100644 --- a/src/nrnoc/treeset.cpp +++ b/src/nrnoc/treeset.cpp @@ -900,7 +900,7 @@ void connection_coef(void) /* setup a and b */ #endif } -void nrn_shape_update(void) { +extern "C" void nrn_shape_update(void) { static int updating; if (section_list->next == section_list) { return; diff --git a/src/oc/nocable.cpp b/src/oc/nocable.cpp index 12bc31e0a7..ce5b6116b5 100755 --- a/src/oc/nocable.cpp +++ b/src/oc/nocable.cpp @@ -54,7 +54,7 @@ void hoc_secname(void) { hoc_pushstr(&pdummystring); } void hoc_construct_point(Object *ob, int i) {} -void nrn_shape_update(void) {} +extern "C" void nrn_shape_update(void) {} char *nrn_version(int i) {static char* s = "not NEURON"; return s;} char *nrn_minor_version; char *nrn_branch_name;