FAUST compiler  0.9.9.6b8
names.cpp
Go to the documentation of this file.
00001 /************************************************************************
00002  ************************************************************************
00003     FAUST compiler
00004     Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
00005     ---------------------------------------------------------------------
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  ************************************************************************
00020  ************************************************************************/
00021 
00022 
00030 #include "ppsig.hh"
00031 #include "names.hh"
00032 #include "property.hh"
00033 #include "ppsig.hh"
00034 #include "doc_Text.hh"
00035 #include "Text.hh"
00036 #include <assert.h>
00037 
00038 
00039 // History
00040 // 2009/09/08 : get/setDefNameProperty
00041 
00042 
00043 extern int gMaxNameSize;
00044 
00045 
00052 Tree DEFNAMEPROPERTY = tree(symbol("DEFNAMEPROPERTY"));
00053 
00054 void setDefNameProperty(Tree t, Tree id)
00055 {
00056     //cerr << "setDefNameProperty : " << *id << " FOR " << t << "#" << boxpp(t) << endl;
00057     setProperty(t, DEFNAMEPROPERTY, id);
00058 }
00059 
00060 void setDefNameProperty(Tree t, const string& name)
00061 {
00062     //cerr << "setDefNameProperty : " << name << " FOR " << t << "#" << boxpp(t) << endl;
00063     int     n = name.size();
00064     int     m = (gMaxNameSize>1023) ? 1023 : gMaxNameSize;
00065     if (n > m) {
00066         // the name is too long we reduce it to 2/3 of maxsize
00067         char    buf[1024];
00068         int i = 0;
00069         // copy first third
00070         for (; i < m/3; i++) { buf[i] = name[i]; }
00071         // add ...
00072         buf[i++] = '.';
00073         buf[i++] = '.';
00074         buf[i++] = '.';
00075         // copy last third
00076         for (int c = n-m/3; c<n; c++, i++) { buf[i] = name[c]; }
00077         buf[i] = 0;
00078         setProperty(t, DEFNAMEPROPERTY, tree(buf));
00079     } else {
00080         setProperty(t, DEFNAMEPROPERTY, tree(name.c_str()));
00081     }
00082 
00083 }
00084 
00085 bool getDefNameProperty(Tree t, Tree& id)
00086 {
00087     //cerr << "getDefNameProperty of : " << t << endl;
00088     return getProperty(t, DEFNAMEPROPERTY, id);
00089 }
00090 
00091 
00097 string defName2NickName (const string& defname)
00098 {
00099     return defname;
00100 }
00101 
00102 Tree NICKNAMEPROPERTY = tree(symbol("NICKNAMEPROPERTY"));
00103 
00104 
00108 void setSigNickname(Tree t, const string& id)
00109 {
00110     Tree    s,d;
00111     if (isSigFixDelay(t,s,d) && isZero(d)) {
00112         setProperty(s, NICKNAMEPROPERTY, tree(id));
00113     } else {
00114         setProperty(t, NICKNAMEPROPERTY, tree(id));
00115     }
00116 }
00117 
00118 
00122 bool getSigNickname(Tree t, Tree& id)
00123 {
00124     bool r = getProperty(t, NICKNAMEPROPERTY, id);
00125     return r;
00126 }
00127 
00128 
00129 
00134 void setSigListNickName (Tree  lsig, const string& nickname)
00135 {
00136     assert(isList(lsig));
00137     
00138     if (isNil(tl(lsig))) {
00139         setSigNickname(hd(lsig), nickname);
00140     } else {
00141         int     i=0;
00142         while (!isNil(lsig)) {
00143             setSigNickname(hd(lsig), subst("$0_$1", nickname, T(++i)));
00144             lsig = tl(lsig);
00145         }
00146     }
00147 }
00148 
00149 
00150 
00151