[comp.sys.amiga.tech] Opening dos.library in C

a464@mindlink.UUCP (Bruce Dawson) (04/11/90)

> peraue@cs.vu.nl writes:
> 
> Msg-ID: <6287@star.cs.vu.nl>
> Posted: 11 Apr 90 12:16:19 GMT
> 
> Org.  : Fac. Wiskunde & Informatica, VU, Amsterdam
> Person: Raue Paul Erik
> 
> Since no-one seemed to be able to supply me with a glue routine for the
> requester-library for Aztec C5.0, I tried writing my own file-requester....
>      _______       _______    _______
> +-----------------+--------------------+
>     / ___  /\     / _____/\  / ___  /\  | peraue@cs.vu.nl | Quote by
> DD.Linder |
>    / /\_/ /_/___ / /\____\/ / /\_/ / /
> +-----------------+--------------------+
>   / _____//____// ____/\   / __  _/ /   | real programmers don't document
> code |
>  / /\____\\____/ /\___\/_ / /\_\ \\/    | if it was hard to write, it should
> |
> /_/ /         /______//_//_/ /  \_\     | be hard to read. |
> \_\/          \______\\_\\_\/    \_\ +--------------------------------------+


     The source to the req.library glue code should be included in the
distribution package.  So, you should be able to reassemble for Aztec 5.0.  If
not, it is certainly far easier to roll your own glue code than to write a
whole new file requester.  Here is a bit of glue code for the file requester
and purge files functions (note - these glue code fragments trash A6.  Aztec
3.6 allowed this, but I don't know about Lattice or Aztec 5.0).

_FileRequest
      MOVE.L  4(SP),A0
      MOVE.L  _ReqBase,A6
      JSR     _LVOFileRequest(A6)
      RTS

_PurgeFiles
      MOVE.L  4(SP),A0
      MOVE.L  _ReqBase,A6
      JSR     _LVOFileRequest(A6)
      RTS

     I hope this helps.  If you need any more help, e-mail me.

.Bruce Dawson, one of the req.library authors.

peraue@cs.vu.nl (Raue Paul Erik) (04/11/90)

Since no-one seemed to be able to supply me with a glue routine for the
requester-library for Aztec C5.0, I tried writing my own file-requester....
Just one little problem... When I try to open the dos.library it the machine
crashes.... Does anyone know how to open the dos.library in C, I tried every
example in the book, and they don't seem to work.... When I try it in Assembly
it works fine, just the C routine that crashes....

Can anyone send me a working program using the dos.library?

My eternal gratitude, Paul-Erik Raue

P.S.: Please E-Mail as well as posting, I may not be able to read this news-
      group in the next few days, so the articles (RE: Opening dos.libr* )
      have probably expired by the time I get to reading this again...
      Thanx again....

     _______       _______    _______   +-----------------+--------------------+
    / ___  /\     / _____/\  / ___  /\  | peraue@cs.vu.nl | Quote by DD.Linder |
   / /\_/ /_/___ / /\____\/ / /\_/ / /  +-----------------+--------------------+
  / _____//____// ____/\   / __  _/ /   | real programmers don't document code |
 / /\____\\____/ /\___\/_ / /\_\ \\/    | if it was hard to write, it should   |
/_/ /         /______//_//_/ /  \_\     | be hard to read.                     |
\_\/          \______\\_\\_\/    \_\    +--------------------------------------+

lphillips@lpami.wimsey.bc.ca (Larry Phillips) (04/11/90)

In <205@mtiame.oz>, jep@mtiame.oz (Jesper Peterson) writes:
>The dos.library is opened for you by the C startup code, so just leap
>straight into your dos calls. Apart from it being a bad idea, I don't know
>if opening a library twice will cause the machine to crash.

You can open a library (in general), as many times as you want. It is done all
the time, in that many programs can be opening the same libraries. Opening it
twice within one program is only wasteful of time. Of course if you do have a
need to open a library twice, for some reason, you should definitely close it
twice, too.

-larry

--
Entomology bugs me.
+-----------------------------------------------------------------------+ 
|   //   Larry Phillips                                                 |
| \X/    lphillips@lpami.wimsey.bc.ca -or- uunet!van-bc!lpami!lphillips |
|        COMPUSERVE: 76703,4322  -or-  76703.4322@compuserve.com        |
+-----------------------------------------------------------------------+

jep@mtiame.oz (Jesper Peterson) (04/12/90)

In article <6287@star.cs.vu.nl> peraue@cs.vu.nl (Raue Paul Erik) writes:
>Just one little problem... When I try to open the dos.library it the machine
>crashes.... Does anyone know how to open the dos.library in C, I tried every

>Can anyone send me a working program using the dos.library?

The dos.library is opened for you by the C startup code, so just leap
straight into your dos calls. Apart from it being a bad idea, I don't know
if opening a library twice will cause the machine to crash.

Jesper.
-- 
ACSnet: jep@mtiame.mtia.oz                 "This lottery is my bathroom."
UUCP:	...!uunet!munnari!mtiame.oz!jep       - Peg (Married with Children)
PHONE: (03) 699-1022

vilkas@ultima.cs.uts.oz (Peter Sumskas) (04/12/90)

peraue@cs.vu.nl (Raue Paul Erik) writes:

>Since no-one seemed to be able to supply me with a glue routine for the
>requester-library for Aztec C5.0, I tried writing my own file-requester....
>Just one little problem... When I try to open the dos.library it the machine
>crashes.... Does anyone know how to open the dos.library in C, I tried every
>example in the book, and they don't seem to work.... When I try it in Assembly
>it works fine, just the C routine that crashes....

>Can anyone send me a working program using the dos.library?

Aztec C opens the dos.library to begin with so that it can do the printf's, etc.The reason why it might be crashing is perhaps that you may be redefining 
DosBase. 

Hope that solves your problem. 

                           Regards, Peter Sumskas.

deven@rpi.edu (Deven T. Corzine) (04/12/90)

In article <6287@star.cs.vu.nl> peraue@cs.vu.nl (Raue Paul Erik) writes:

peraue> Just one little problem... When I try to open the dos.library
peraue> it the machine crashes....

peraue> Can anyone send me a working program using the dos.library?

On 12 Apr 90 01:07:13 GMT, jep@mtiame.oz (Jesper Peterson) said:

Jesper> The dos.library is opened for you by the C startup code, so
Jesper> just leap straight into your dos calls.

Unless, of course, you're not linking with startup code...

Jesper> Apart from it being a bad idea, I don't know if opening a
Jesper> library twice will cause the machine to crash.

Bad idea??  Better to open the library twice than not at all.  Cause a
crash?  If it does, it's not due to opening it twice.  The entire
purpose of the runtime libraries is to be shared by various tasks, and
all OpenLibrary() (normally) does if the library is already loaded and
initialized is to update a usage count in the Library structure.

When you CloseLibrary(), this count is decremented, and the library
might also be expunged if usecount is zero and a delayed expunge was
pending.  The library doesn't care who opens it or how many times.
Apart from initialization, multiple opens are like multiple layers of
Forbid() or Disable() calls -- they nest, but have no other effect.
So, opening a library twice will NOT cause a crash, but attempting to
use a library without opening it likely WILL.  (exec.library being an
exception -- if exec.library is toast, so are you, so forget it.)

Deven
-- 
Deven T. Corzine        Internet:  deven@rpi.edu, shadow@pawl.rpi.edu
Snail:  2151 12th St. Apt. 4, Troy, NY 12180   Phone:  (518) 274-0327
Bitnet:  deven@rpitsmts, userfxb6@rpitsmts     UUCP:  uunet!rpi!deven
Simple things should be simple and complex things should be possible.

S.J.Raybould@fulcrum.bt.co.uk (Simon Raybould) (04/12/90)

In article <205@mtiame.oz> jep@mtiame.oz (Jesper Peterson) writes:
>In article <6287@star.cs.vu.nl> peraue@cs.vu.nl (Raue Paul Erik) writes:
>>Can anyone send me a working program using the dos.library?
>
>The dos.library is opened for you by the C startup code, so just leap
>
>Jesper.

But pressumably, he's not using the startup code else he wouldn't be asking
this question.. Would he ??




+-=-=-=-=-=-=-=-=-=-=-=-=-=-=+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
|   British Telecom Fulcrum  | name : Simon John Raybould   {^.^}   |
|   Fordrough Lane           | path : sie@fulcrum.bt.co.uk   \~/    |
|   Birmingham               +-----------+--------------------------|
|   B9 5LD                   |   //      | AMIGA B2000HD 3MB 8088BB |
|   ENGLAND                  | \X/AMIGA  | Lattice C V5.05          |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=+=-=-=-=-=-=+=-=-=-=-=-=-=-=-=-=-=-=-=-+

S.J.Raybould@fulcrum.bt.co.uk (Simon Raybould) (04/12/90)

In article <17697@ultima.cs.uts.oz> vilkas@ultima.cs.uts.oz (Peter Sumskas) writes:
>peraue@cs.vu.nl (Raue Paul Erik) writes:
>
>Aztec C opens the dos.library to begin with so that it can do the printf's
>

No it dosn't, its done by the startup code, What if he doesn't want to use
the startup code, which is obviously the case??

you should define 'DosBase' as a global.
Note th euppercase D and B.
then call DosBase = OpenLibrary("dos.library",..); e.t.c.

That should do the trick, I havn't tried it but I will.




+-=-=-=-=-=-=-=-=-=-=-=-=-=-=+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
|   British Telecom Fulcrum  | name : Simon John Raybould   {^.^}   |
|   Fordrough Lane           | path : sie@fulcrum.bt.co.uk   \~/    |
|   Birmingham               +-----------+--------------------------|
|   B9 5LD                   |   //      | AMIGA B2000HD 3MB 8088BB |
|   ENGLAND                  | \X/AMIGA  | Lattice C V5.05          |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=+=-=-=-=-=-=+=-=-=-=-=-=-=-=-=-=-=-=-=-+

riley@batcomputer.tn.cornell.edu (Daniel S. Riley) (04/14/90)

In article <DEVEN.90Apr12045600@netserv2.rpi.edu> deven@rpi.edu (Deven T. Corzine) writes:
>Jesper> Apart from it being a bad idea, I don't know if opening a
>Jesper> library twice will cause the machine to crash.
>
>Bad idea??  Better to open the library twice than not at all.  Cause a
>crash?  If it does, it's not due to opening it twice.

Two (obvious) things you don't want to do when you might be opening a
library twice:

1)  Don't zero the library base after the inner CloseLibrary()...clearing
    the pointer will either screw up the outer CloseLibrary() (maybe
    crashing your Amiga), or you'll end up with the library permanently
    opened.

2)  Don't make any typos.  If you set DOSBase = OpenLibrary("ods.library",0);,
    you effectively zero DOSBase for that process, and your next attempt
    at any sort of io will crash (including printing the error message
    telling the user that dos.library couldn't be opened).

See, I said they were obvious...guess I'm just feeling obvious today.

-Dan Riley (riley@tcgould.tn.cornell.edu, cornell!batcomputer!riley)
-Wilson Lab, Cornell University