home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $Source: WB_2.1:homes/rkr/prog/sercli/src/RCS/misc.c,v $
- ** $Author: rkr $
- ** $Revision: 1.5 $
- ** $Locker: rkr $
- ** $State: Exp $
- ** $Date: 1993/06/16 23:27:57 $
- **
- */
-
- #include <exec/io.h>
- #include <clib/exec_protos.h>
-
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- #include "defs.h"
- #include "ser_supp.h"
- #include "misc.h"
-
-
-
- /*
- ** Borrowed from Mike Oliphant's usenet posting...(and renamed)
- **
- ** This will safely abort IO requests pending...
- **
- ** Unlike the regular AbortIO(), and the NiceAbort() from Mike,
- ** SafeAbortIO() can even 'abort' an IO request that hasn't been sent
- ** yet...this makes it convenient for general cleanup.
- **
- */
- void SafeAbortIO (IO_Request *ior)
- {
- Forbid ();
- {
- if (!CheckIO (ior) )
- {
- AbortIO (ior);
- WaitIO (ior);
- }
- }
- Permit ();
- }
-
-
-
- /*
- ** A bit like fgets(), EXCEPT:
- ** does not preserve the end-of-line
- ** malloc()s the line (and free()s the previous line, if need be).
- **
- */
- char *get_line (FILE *file)
- {
- static char *line = 0;
- int c;
- int count;
- long start_pos;
-
- if (line)
- {
- free (line);
- line = 0;
- }
-
- start_pos = ftell (file);
- count = 0;
- do
- {
- ++count;
- c = fgetc (file);
- }
- while ( (c != '\n') && (c != EOF) );
-
- if ( (c != EOF) || (count != 1) )
- {
- line = malloc (count);
- fseek (file, start_pos, SEEK_SET);
- fread (line, 1, count, file);
- line [count - 1] = 0;
- }
- return (line);
- }
-
-
- /*
- ** Stub function for some function call-backs. E.g.,
- ** onbreak (do_nothing);
- **
- */
- int do_nothing (void)
- {
- return (0);
- }
-
-
-
- /*
- ** I _think_ this came from the remcli.c that came with fifo:.
- **
- ** I don't know if it's generally legal to use {.ln_Type} as a flag. I
- ** need to check out remcli.c, as this may've been a peculiarity of the
- ** fifo handling of messages, rather than something profound. It
- ** certainly looks odd.
- **
- ** (Could just test the effects of ReplyMsg() in general...)
- **
- */
- void WaitMsg (Message *msg)
- {
- while (msg->mn_Node.ln_Type == NT_MESSAGE)
- Wait (1 << msg->mn_ReplyPort->mp_SigBit);
-
- Forbid ();
- {
- Remove (&msg->mn_Node);
- }
- Permit ();
- }
-
-