/* * R : A Computer Language for Statistical Data Analysis * Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka * Copyright (C) 2001, 2006 The R Development Core Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street Fifth Floor, Boston, MA 02110-1301 USA * * * * Basic List Handling Features * * These remain here to show that R is truly descended from Lisp :-). * There is one real function "allnames" shich should probably be * elsewhere. */ #ifdef HAVE_CONFIG_H #include #endif #include "Defn.h" /* Utility functions moved to Rinlinedfuns.h */ /* The following code is used to recursive traverse a block */ /* of code and extract all the symbols present in that code. */ typedef struct { SEXP ans; int UniqueNames; int IncludeFunctions; int StoreValues; int ItemCounts; int MaxCount; } NameWalkData; static void namewalk(SEXP s, NameWalkData *d) { int i, j, n; SEXP name; switch(TYPEOF(s)) { case SYMSXP: name = PRINTNAME(s); /* skip blank symbols */ if(strlen(CHAR(name)) == 0) goto ignore; if(d->ItemCounts < d->MaxCount) { if(d->StoreValues) { if(d->UniqueNames) { for(j = 0 ; j < d->ItemCounts ; j++) { if(STRING_ELT(d->ans, j) == name) goto ignore; } } SET_STRING_ELT(d->ans, d->ItemCounts, name); } d->ItemCounts += 1; } ignore: break; case LANGSXP: if(!d->IncludeFunctions) s = CDR(s); while(s != R_NilValue) { namewalk(CAR(s), d); s = CDR(s); } break; case EXPRSXP: n = length(s); for(i=0 ; i