1: /*
   2: ** support.c
   3: **
   4: ** Author: Pr Emanuelsson <pell@lysator.liu.se>
   5: ** Hacked by: Peter Eriksson <pen@lysator.liu.se>
   6: */
   7: #include <stdio.h>
   8: #include <ctype.h>
   9: 
  10: #ifdef HAVE_ANSIHEADERS
  11: #  include <stdlib.h>
  12: #  include <string.h>
  13: #else
  14: #  define strchr(str, c) index(str, c)
  15: #endif
  16: 
  17: #define IN_LIBIDENT_SRC
  18: #include "ident.h"
  19: 
  20: 
  21: char *id_strdup __P1(char *, str)
  22: {
  23:     char *cp;
  24: 
  25:     cp = (char *) malloc(strlen(str)+1);
  26:     if (cp == NULL)
  27:     {
  28: #ifdef DEBUG
  29:     perror("libident: malloc");
  30: #endif
  31:         return NULL;
  32:     }
  33: 
  34:     strcpy(cp, str);
  35: 
  36:     return cp;
  37: }
  38: 
  39: 
  40: char *id_strtok __P3(char *, cp,
  41:               char *, cs,
  42:               char *, dc)
  43: {
  44:     static char *bp = 0;
  45: 
  46:     if (cp)
  47:     bp = cp;
  48: 
  49:     /*
  50:     ** No delimitor cs - return whole buffer and point at end
  51:     */
  52:     if (!cs)
  53:     {
  54:     while (*bp)
  55:         bp++;
  56:     return cs;
  57:     }
  58: 
  59:     /*
  60:     ** Skip leading spaces
  61:     */
  62:     while (isspace(*bp))
  63:     bp++;
  64: 
  65:     /*
  66:     ** No token found?
  67:     */
  68:     if (!*bp)
  69:     return 0;
  70: 
  71:     cp = bp;
  72:     while (*bp && !strchr(cs, *bp))
  73:     bp++;
  74: 
  75:     /*
  76:     ** Remove trailing spaces
  77:     */
  78:     *dc = *bp;
  79:     for (dc = bp-1; dc > cp && isspace(*dc); dc--)
  80:     ;
  81:     *++dc = '\0';
  82: 
  83:     bp++;
  84: 
  85:     return cp;
  86: }

Defined functions

__P1 defined in line 21; never used
__P3 defined in line 40; never used

Defined variables

id_strtok defined in line 40; used 8 times

Defined macros

IN_LIBIDENT_SRC defined in line 17; never used
strchr defined in line 14; used 1 times
  • in line 72
Last modified: 1995-11-23
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2991
Valid CSS Valid XHTML 1.0 Strict