home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / utils / sercli.shr / sercli / src / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-16  |  2.1 KB  |  123 lines

  1. /*
  2. **  $Source: WB_2.1:homes/rkr/prog/sercli/src/RCS/misc.c,v $
  3. **  $Author: rkr $
  4. **  $Revision: 1.5 $
  5. **  $Locker: rkr $
  6. **  $State: Exp $
  7. **  $Date: 1993/06/16 23:27:57 $
  8. **
  9. */
  10.  
  11. #include <exec/io.h>
  12. #include <clib/exec_protos.h>
  13.  
  14. #include <ctype.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. #include "defs.h"
  19. #include "ser_supp.h"
  20. #include "misc.h"
  21.  
  22.  
  23.  
  24. /*
  25. **  Borrowed from Mike Oliphant's usenet posting...(and renamed)
  26. **
  27. **  This will safely abort IO requests pending...
  28. **
  29. **  Unlike the regular AbortIO(), and the NiceAbort() from Mike,
  30. **  SafeAbortIO() can even 'abort' an IO request that hasn't been sent
  31. **  yet...this makes it convenient for general cleanup.
  32. **
  33. */
  34. void SafeAbortIO (IO_Request *ior)
  35. {
  36.     Forbid ();
  37.     {
  38.     if (!CheckIO (ior) )
  39.     {
  40.         AbortIO (ior);
  41.         WaitIO (ior);
  42.     }
  43.     }
  44.     Permit ();
  45. }
  46.  
  47.  
  48.  
  49. /*
  50. **  A bit like fgets(), EXCEPT:
  51. **    does not preserve the end-of-line
  52. **    malloc()s the line (and free()s the previous line, if need be).
  53. **
  54. */
  55. char *get_line (FILE *file)
  56. {
  57.     static char *line = 0;
  58.     int c;
  59.     int count;
  60.     long start_pos;
  61.  
  62.     if (line)
  63.     {
  64.     free (line);
  65.     line = 0;
  66.     }
  67.  
  68.     start_pos = ftell (file);
  69.     count = 0;
  70.     do
  71.     {
  72.     ++count;
  73.     c = fgetc (file);
  74.     }
  75.     while ( (c != '\n') && (c != EOF) );
  76.  
  77.     if ( (c != EOF) || (count != 1) )
  78.     {
  79.     line = malloc (count);
  80.     fseek (file, start_pos, SEEK_SET);
  81.     fread (line, 1, count, file);
  82.     line [count - 1] = 0;
  83.     }
  84.     return (line);
  85. }
  86.  
  87.  
  88. /*
  89. **  Stub function for some function call-backs.  E.g.,
  90. **    onbreak (do_nothing);
  91. **
  92. */
  93. int do_nothing (void)
  94. {
  95.     return (0);
  96. }
  97.  
  98.  
  99.  
  100. /*
  101. **  I _think_ this came from the remcli.c that came with fifo:.
  102. **
  103. **  I don't know if it's generally legal to use {.ln_Type} as a flag.  I
  104. **  need to check out remcli.c, as this may've been a peculiarity of the
  105. **  fifo handling of messages, rather than something profound.    It
  106. **  certainly looks odd.
  107. **
  108. **  (Could just test the effects of ReplyMsg() in general...)
  109. **
  110. */
  111. void WaitMsg (Message *msg)
  112. {
  113.     while (msg->mn_Node.ln_Type == NT_MESSAGE)
  114.     Wait (1 << msg->mn_ReplyPort->mp_SigBit);
  115.  
  116.     Forbid ();
  117.     {
  118.     Remove (&msg->mn_Node);
  119.     }
  120.     Permit ();
  121. }
  122.  
  123.