"Fossies" - the Fresh Open Source Software Archive

Member "cook-2.34/cook/builtin/strip.c" (25 Sep 2010, 1916 Bytes) of package /linux/misc/old/cook-2.34.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 "strip.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  *      cook - file construction tool
    3  *      Copyright (C) 1994, 1997-1999, 2006-2008 Peter Miller
    4  *
    5  *      This program is free software; you can redistribute it and/or modify
    6  *      it under the terms of the GNU General Public License as published by
    7  *      the Free Software Foundation; either version 3 of the License, or
    8  *      (at your option) any later version.
    9  *
   10  *      This program is distributed in the hope that it will be useful,
   11  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  *      GNU General Public License for more details.
   14  *
   15  *      You should have received a copy of the GNU General Public License
   16  *      along with this program. If not, see
   17  *      <http://www.gnu.org/licenses/>.
   18  */
   19 
   20 #include <common/ac/ctype.h>
   21 
   22 #include <cook/builtin/strip.h>
   23 #include <common/str_list.h>
   24 #include <common/stracc.h>
   25 
   26 
   27 static string_ty *
   28 strip(string_ty *s)
   29 {
   30     static stracc   sa;
   31     char            *sp;
   32     int             space;
   33 
   34     sa_open(&sa);
   35     sp = s->str_text;
   36     while (*sp && isspace(*sp))
   37         ++sp;
   38     space = 0;
   39     while (*sp)
   40     {
   41         if (isspace(*sp))
   42             space = 1;
   43         else
   44         {
   45             if (space)
   46                 sa_char(&sa, ' ');
   47             sa_char(&sa, *sp);
   48             space = 0;
   49         }
   50         ++sp;
   51     }
   52     return sa_close(&sa);
   53 }
   54 
   55 
   56 static int
   57 interpret(string_list_ty *result, const string_list_ty *arg,
   58     const struct expr_position_ty *pp, const struct opcode_context_ty *ocp)
   59 {
   60     size_t          j;
   61     string_ty       *s;
   62 
   63     (void)pp;
   64     (void)ocp;
   65     for (j = 1; j < arg->nstrings; ++j)
   66     {
   67         s = strip(arg->string[j]);
   68         string_list_append(result, s);
   69         str_free(s);
   70     }
   71     return 0;
   72 }
   73 
   74 
   75 builtin_ty builtin_strip =
   76 {
   77     "strip",
   78     interpret,
   79     interpret,                  /* script */
   80 };