/*
A sample rifplugin for use with ribs generated by RenderMan
Studio. RMS beauty pass ribs, such as,
    perspShape_Final.0001.rib
will have a structured comment (near line 21) such as,
    ##rifcontrol insert begin -rif RLFInjector -rifend
Use this rif to strip the comment. 
*/
#include "RifPlugin.h"
#include <string>
  
class StripRifControl : public RifPlugin {
    public:
             StripRifControl();
    virtual ~StripRifControl() { }    
    virtual RifFilter &GetFilter() { return m_filter; }
    
    private:
        RifFilter       m_filter;
        static RtVoid    archiverecord(RtToken type, char* format, va_list vap);
    };
  
RifPlugin *RifPluginManufacture(int argc, char **argv) {
    return new StripRifControl();
    }
    
// Constructor
StripRifControl::StripRifControl() {
    m_filter.VArchiveRecord = archiverecord;  // install our custom callback
    m_filter.Filtering = RifFilter::k_Continue;
    }
  
RtVoid StripRifControl::archiverecord(RtToken type, char* format, va_list vlist) {
    char buffer[512];
    vsnprintf(buffer, 512, format, vlist);
    if(type == RI_STRUCTURE || strcmp(type, RI_STRUCTURE) == 0)
        if(strncmp(buffer, RI_RIFCONTROL, 10) == 0)
            return;
    RiArchiveRecord(type, format, buffer);
    }