home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp / src / devs / netinfo / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-19  |  1.7 KB  |  83 lines

  1. /*
  2.  * misc.c
  3.  *
  4.  * Author: ppessi <Pekka.Pessi@hut.fi>
  5.  *
  6.  * Copyright © 1993 AmiTCP/IP Group, <AmiTCP-group@hut.fi>
  7.  *                  Helsinki University of Technology, Finland.
  8.  *
  9.  * Created      : Sat Jan 15 07:38:07 1994 ppessi
  10.  * Last modified: Mon Jan 17 13:24:05 1994 ppessi
  11.  *
  12.  */
  13.  
  14. #include "base.h"
  15.  
  16. /*
  17.  * Free nodes of a list (they should all be allocated with AllocVec())
  18.  */
  19. void FreeListVec(BASE, struct List *list)
  20. {
  21.   struct Node *entry, *next;
  22.  
  23.   for (entry = list->lh_Head;
  24.        next = entry->ln_Succ;
  25.        entry = next)
  26.     Remove(entry), FreeVec(entry), entry = NULL;
  27. }
  28.  
  29. /*
  30.  * Ensure that a node is in list
  31.  * return node if it is, NULL otherwise
  32.  */
  33. struct Node *FindNode(struct List *list, struct Node *node)
  34. {
  35.   struct Node *entry, *next;
  36.  
  37.   for (entry = list->lh_Head;
  38.        next = entry->ln_Succ;
  39.        entry = next) 
  40.     if (entry == node) {
  41.       return node;
  42.     }
  43.  
  44.   return NULL;
  45. }
  46.  
  47. /*
  48.  * Get next token from string *stringp, where tokens are nonempty
  49.  * strings separated by characters from delim.  
  50.  *
  51.  * Writes NULs into the string at *stringp to end tokens.
  52.  * delim need not remain constant from call to call.
  53.  * On return, *stringp points past the last NUL written (if there might
  54.  * be further tokens), or is NULL (if there are definitely no more tokens).
  55.  *
  56.  * If *stringp is NULL, strtoken returns NULL.
  57.  */
  58. char *strsep(register char **stringp, register const char *delim)
  59. {
  60.   register char *s;
  61.   register const char *spanp;
  62.   register int c, sc;
  63.   char *tok;
  64.  
  65.   if ((s = *stringp) == NULL)
  66.     return (NULL);
  67.   for (tok = s;;) {
  68.     c = *s++;
  69.     spanp = delim;
  70.     do {
  71.       if ((sc = *spanp++) == c) {
  72.     if (c == 0)
  73.       s = NULL;
  74.     else
  75.       s[-1] = 0;
  76.     *stringp = s;
  77.     return (tok);
  78.       }
  79.     } while (sc != 0);
  80.   }
  81. }
  82.  
  83.