The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6fcc22a1f8
commit
516036631c
1508 changed files with 125983 additions and 44037 deletions
64
SWIG/Source/Swig/fragment.c
Normal file
64
SWIG/Source/Swig/fragment.c
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* fragment.c
|
||||
*
|
||||
* This file manages named code fragments. Code fragments are typically
|
||||
* used to hold helper-code that may or may not be included in the wrapper
|
||||
* file (depending on what features are actually used in the interface).
|
||||
*
|
||||
* By using fragments, it's possible to greatly reduce the amount of
|
||||
* wrapper code and to generate cleaner wrapper files.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char cvsroot_fragment_c[] = "$Header$";
|
||||
|
||||
#include "swig.h"
|
||||
|
||||
static Hash *fragments = 0;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_fragment_register()
|
||||
*
|
||||
* Add a fragment.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_fragment_register(String *name, String *section, String *code) {
|
||||
String *ccode;
|
||||
if (!fragments) {
|
||||
fragments = NewHash();
|
||||
}
|
||||
ccode = Copy(code);
|
||||
Setmeta(ccode,"section",Copy(section));
|
||||
Setattr(fragments,Copy(name),ccode);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_fragment_emit()
|
||||
*
|
||||
* Emit a fragment
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_fragment_emit(String *name) {
|
||||
String *code;
|
||||
if (!fragments) return;
|
||||
|
||||
code = Getattr(fragments,name);
|
||||
if (code) {
|
||||
String *section = Getmeta(code,"section");
|
||||
if (section) {
|
||||
File *f = Swig_filebyname(section);
|
||||
if (!f) {
|
||||
Swig_error(Getfile(code),Getline(code),"Bad section '%s' for code fragment '%s'\n", section,name);
|
||||
} else {
|
||||
Printf(f,"%s\n",code);
|
||||
}
|
||||
}
|
||||
Delattr(fragments,name);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue