home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 November / PCO_1198.ISO / filesbbs / os2 / fn127os2.arj / FN127OS2.ZIP / fn127os2 / src / spans.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-25  |  2.3 KB  |  76 lines

  1. /*
  2.  # $Id: spans.c,v 1.5 1998/03/10 14:11:25 fbm Exp fbm $
  3.  # Copyright (C) 1997,1998 Farrell McKay
  4.  # All rights reserved.
  5.  #
  6.  # This file is part of the Fortify distribution, a toolkit for
  7.  # upgrading the cryptographic strength of the Netscape Navigator
  8.  # web browser, authored by Farrell McKay.
  9.  #
  10.  # This toolkit is provided to the recipient under the
  11.  # following terms and conditions:-
  12.  #   1.  This copyright notice must not be removed or modified.
  13.  #   2.  This toolkit may not be reproduced or included in any commercial
  14.  #       media distribution, or commercial publication (for example CD-ROM,
  15.  #       disk, book, magazine, journal) without first obtaining the author's
  16.  #       express permission.
  17.  #   3.  This toolkit, or any component of this toolkit, may not be
  18.  #       commercially resold, redeveloped, rewritten, enhanced or otherwise
  19.  #       used as the basis for commercial venture, without first obtaining
  20.  #       the author's express permission.
  21.  #   4.  Subject to the above conditions being observed (1-3), this toolkit
  22.  #       may be freely reproduced or redistributed.
  23.  #   5.  This software is provided "as-is", without express or implied
  24.  #       warranty.  In no event shall the author be liable for any direct,
  25.  #       indirect or consequential damages however caused.
  26.  #   6.  Subject to the above conditions being observed (1-5),
  27.  #       this toolkit may be used at no cost to the recipient.
  28.  #
  29.  # Farrell McKay
  30.  # Wayfarer Systems Pty Ltd        contact@fortify.net
  31.  */
  32.  
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. #include <unistd.h>
  36.  
  37. int
  38. do_spans(char *span, int (*handler)(), void *p1, void *p2, void *p3)
  39. {
  40.         int                     rtn = 0;
  41.     long            start = 0;
  42.     long            stop = -1;
  43.  
  44.     if (span == NULL || *span == '\0')
  45.         span = "0-";
  46.     while (span && *span && rtn == 0) {
  47.         start = strtol(span, &span, 0);
  48.  
  49.         if (*span == '\0')
  50.             stop = start;
  51.         else if (*span == ',')
  52.             stop = start;
  53.         else if (*span == '-' || *span == ':') {
  54.             stop = (*span == ':')? start: 0;
  55.             span++;
  56.             if (*span == '\0' || *span == ',')
  57.                 stop = -1;
  58.             else {
  59.                 stop += strtol(span, &span, 0);
  60.             }
  61.         }
  62.         if (*span == ',')
  63.             span++;
  64.  
  65.         if (start < 0 || (stop < start && stop >= 0)) {
  66.             fprintf(stderr, "Warning, bad range ignored: %ld to %ld\n",
  67.                 start, stop
  68.             );
  69.         }
  70.         else {
  71.             rtn = (*handler)(start, stop, p1, p2, p3);
  72.         }
  73.     }
  74.         return rtn;
  75. }
  76.