"Fossies" - the Fresh Open Source Software Archive

Member "authforce-0.9.9/src/extract.c" (13 May 2007, 3054 Bytes) of package /linux/www/old/authforce-0.9.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "extract.c" see the Fossies "Dox" file reference documentation.

    1 /* $Id: extract.c,v 1.2 2001/02/13 22:54:53 kapheine Exp $ */
    2 
    3 /* Copyright (C) 1987-1999 Free Software Foundation, Inc.
    4 
    5    This file is part of GNU Bash, the Bourne Again SHell.
    6 
    7    Bash is free software; you can redistribute it and/or modify it under
    8    the terms of the GNU General Public License as published by the Free
    9    Software Foundation; either version 2, or (at your option) any later
   10    version.
   11 
   12    Bash is distributed in the hope that it will be useful, but WITHOUT ANY
   13    WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   15    for more details.
   16 
   17    You should have received a copy of the GNU General Public License along
   18    with Bash; see the file COPYING.  If not, write to the Free Software
   19    Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
   20 #include <config.h>
   21 #include <stdio.h>
   22 #include <string.h>
   23 #include <malloc.h>
   24 #ifdef MEMWATCH
   25 #include "memwatch.h"
   26 #endif /* MEMWATCH */
   27 #include "extern.h"
   28 
   29 static char *sub_string(char *string, int start, int end);
   30 /* note: this function was extracted, with the following changes, from 
   31  * general.c, a part of bash-2.04. the above license is the original license
   32  * of general.c and all of bash-2.04
   33  *
   34  * changes: xmalloc changed to malloc, changed function declaration
   35  */
   36 
   37 /* Given a string containing units of information separated by colons,
   38    return the next one pointed to by (P_INDEX), or NULL if there are no more.
   39    Advance (P_INDEX) to the character after the colon. */
   40 char *extract_colon_unit(char *string, int *p_index)
   41 {
   42   int i, start, len;
   43   char *value;
   44 
   45   if (string == 0)
   46     return (string);
   47 
   48   len = strlen (string);
   49   if (*p_index >= len)
   50     return ((char *)NULL);
   51 
   52   i = *p_index;
   53 
   54   /* Each call to this routine leaves the index pointing at a colon if
   55      there is more to the path.  If I is > 0, then increment past the
   56      `:'.  If I is 0, then the path has a leading colon.  Trailing colons
   57      are handled OK by the `else' part of the if statement; an empty
   58      string is returned in that case. */
   59   if (i && string[i] == ':')
   60     i++;
   61 
   62   for (start = i; string[i] && string[i] != ':'; i++)
   63     ;
   64 
   65   *p_index = i;
   66 
   67   if (i == start)
   68     {
   69       if (string[i])
   70     (*p_index)++;
   71       /* Return "" in the case of a trailing `:'. */
   72       value = (char*)malloc_w(1);
   73       value[0] = '\0';
   74     }
   75   else
   76     value = sub_string(string, start, i);
   77 
   78   return (value);
   79 }
   80 
   81 /* note: this function was extracted, with the following changes, from
   82  * subst.c, a part of bash-2.04. the above license is the original license
   83  * of subst.c and all of bash-2.04 
   84  *
   85  * changes: xmalloc changed to malloc, changed function declaration
   86  */
   87 
   88 /* Cons a new string from STRING starting at START and ending at END,
   89    not including END. */
   90 static char *sub_string(char *string, int start, int end) {
   91     register int len;
   92     register char *result;
   93 
   94     len = end - start;
   95     result = malloc (len + 1);
   96     strncpy (result, string + start, len);
   97     result[len] = '\0';
   98     return (result);
   99 }