コード例 #1
0
ファイル: astree.c プロジェクト: mtnash/oc
int handlefunction(astree node, FILE* outfile){
    astree type = node->first;
    astree ident = node->first->first;
    astree param = node->first->next->first;
    bitset_t newattrs = bitlookup(type->symbol); 
    node->attrs = newattrs;
    cstring funcname = peek_stringtable(ident->lexinfo);

    sym_noderef lookup = search_sym_table(ident,gident_tbl);
    if (lookup != NULL){
        if (lookup->attributes & ATTR_PROTOTYPE){
            //found previous func declaration, it's a prototype
            if (lookup->attributes == ((newattrs | ATTR_PROTOTYPE))){
                if(paramcheck(param,lookup->nextparam,funcname)){
                    return 1;
                }
            } else {
                print_attributes(stdout,(ATTR_PROTOTYPE + ATTR_BOOL));
                eprintf("\n");
                print_attributes(stdout,(newattrs|ATTR_PROTOTYPE));
                eprintf("\n");
                //func declaration does not match prototype's type
                eprintf(
            "prototype's type does not match function declaration %s\n",
                        funcname);
            }
        } else {
            //found previous func declaration, it's not a prototype
            eprintf(
            "redeclaring function %s at line %d\n",
            peek_stringtable(ident->lexinfo),ident->linenr-1);
            eprintf(
            "(previously declared at line %d)\n",lookup->linenr-1);
            return 1;
        }
    } else {
        ident->attrs = ATTR_FUNCTION | bitlookup(type->symbol);
        sym_noderef temp = intern_sym_table(ident,gident_tbl,outfile);
        push_block(gblock_stk);
        for(;param != NULL; param = param->next){
            param->first->attrs = bitlookup(param->symbol) | ATTR_PARAM;
            param->first->blocknr = gblock_stk->top->blocknr;
            temp->nextparam = 
            intern_sym_table(param->first,gident_tbl,outfile);
            temp = temp->nextparam;
        }
        pop_idents(gident_tbl,gblock_stk->top->blocknr);
        pop_block(gblock_stk);
    }
    return 0;
}
コード例 #2
0
  // This method is called while executing the raw bytecodes, so none of
  // the adjustments that BytecodeStream performs applies.
  void trace(methodHandle method, address bcp, uintptr_t tos, uintptr_t tos2) {
    MutexLocker ml(BytecodeTrace_lock);
    ResourceMark rm;
    if (_current_method != method()) {
      // Note 1: This code will not work as expected with true MT/MP.
      //         Need an explicit lock or a different solution.
      tty->cr();
      tty->print("[%d] ", (int) Thread::current()->osthread()->thread_id());
      method->print_name(tty);
      tty->cr();
      _current_method = method();
    }
    Bytecodes::Code code;
    if (is_wide()) {
      // bcp wasn't advanced if previous bytecode was _wide.
      code = Bytecodes::cast(*(bcp+1));
    } else {
      code = Bytecodes::cast(*bcp);
    }
    int bci = bcp - method->code_base();
    tty->print("[%d] ", (int) Thread::current()->osthread()->thread_id());
    if (Verbose) {
      tty->print("%8d  %4d  " INTPTR_FORMAT " " INTPTR_FORMAT " %s", 
	   BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
    } else {
      tty->print("%8d  %4d  %s", 
	   BytecodeCounter::counter_value(), bci, Bytecodes::name(code));
    }
    _next_pc = is_wide() ? bcp+2 : bcp+1;
    print_attributes(code, bci);
    // Set is_wide for the next one, since the caller of this doesn't skip
    // the next bytecode.
    _is_wide = (code == Bytecodes::_wide);
  }
コード例 #3
0
/***********************************************************************//**
 * @brief Print model information
 *
 * @param[in] chatter Chattiness (defaults to NORMAL).
 * @return String containing model information.
 ***************************************************************************/
std::string GCOMModelDRBFitting::print(const GChatter& chatter) const
{
    // Initialise result string
    std::string result;

    // Continue only if chatter is not silent
    if (chatter != SILENT) {

        // Append header
        result.append("=== GCOMModelDRBFitting ===");

        // Append attributes
        result.append("\n"+print_attributes());

        // Append node summary
        result.append("\n"+gammalib::parformat("Number of nodes"));
        result.append(gammalib::str(m_phibars.size()));
        result.append("\n"+gammalib::parformat("Number of parameters"));
        result.append(gammalib::str(size()));
        for (int i = 0; i < size(); ++i) {
            result.append("\n"+m_pars[i]->print(chatter));
        }

    } // endif: chatter was not silent

    // Return result
    return result;
}
コード例 #4
0
ファイル: rapidxml_print.hpp プロジェクト: OxfordSKA/OSKAR
        inline OutIt print_element_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
        {
            assert(node->type() == node_element);

            // Print element name and attributes, if any
            if (!(flags & print_no_indenting)) {
                //out = fill_chars(out, indent, Ch('\t'));
                out = fill_chars(out, indent, Ch(' '));
                out = fill_chars(out, indent, Ch(' '));
            }
            *out = Ch('<'), ++out;
            out = copy_chars(node->name(), node->name() + node->name_size(), out);
            out = print_attributes(out, node);
            
            // If node is childless
            if (node->value_size() == 0 && !node->first_node())
            {
                // Print childless node tag ending
                *out = Ch('/'), ++out;
                *out = Ch('>'), ++out;
            }
            else
            {
                // Print normal node tag ending
                *out = Ch('>'), ++out;

                // Test if node contains a single data node only (and no other nodes)
                xml_node<Ch> *child = node->first_node();
                if (!child)
                {
                    // If node has no children, only print its value without indenting
                    out = copy_and_expand_chars(node->value(), node->value() + node->value_size(), Ch(0), out);
                }
                else if (child->next_sibling() == 0 && child->type() == node_data)
                {
                    // If node has a sole data child, only print its value without indenting
                    out = copy_and_expand_chars(child->value(), child->value() + child->value_size(), Ch(0), out);
                }
                else
                {
                    // Print all children with full indenting
                    if (!(flags & print_no_indenting))
                        *out = Ch('\n'), ++out;
                    out = print_children(out, node, flags, indent + 1);
                    if (!(flags & print_no_indenting)) {
                        //out = fill_chars(out, indent, Ch('\t'));
                        out = fill_chars(out, indent, Ch(' '));
                        out = fill_chars(out, indent, Ch(' '));
                    }
                }

                // Print node end
                *out = Ch('<'), ++out;
                *out = Ch('/'), ++out;
                out = copy_chars(node->name(), node->name() + node->name_size(), out);
                *out = Ch('>'), ++out;
            }
            return out;
        }
コード例 #5
0
ファイル: dldiscover.cpp プロジェクト: G4GUO/datvexpress_gui
int		old_main (int argc, char** argv)
{
	IDeckLinkIterator*		deckLinkIterator;
	IDeckLink*				deckLink;
	int						numDevices = 0;
	HRESULT					result;
	
	// Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
	deckLinkIterator = CreateDeckLinkIteratorInstance();
	if (deckLinkIterator == NULL)
	{
		fprintf(stderr, "A DeckLink iterator could not be created.  The DeckLink drivers may not be installed.\n");
		return 1;
	}
	
	// Enumerate all cards in this system
	while (deckLinkIterator->Next(&deckLink) == S_OK)
	{
		char *		deviceNameString = NULL;
		
		// Increment the total number of DeckLink cards found
		numDevices++;
		if (numDevices > 1)
			printf("\n\n");
		
		// *** Print the model name of the DeckLink card
		result = deckLink->GetModelName((const char **) &deviceNameString);
		if (result == S_OK)
		{
			printf("=============== %s ===============\n\n", deviceNameString);
			free(deviceNameString);
		}

		print_attributes(deckLink);
		
		// ** List the video output display modes supported by the card
		print_output_modes(deckLink);
		
		// ** List the video input display modes supported by the card
		print_input_modes(deckLink);
		
		// ** List the input and output capabilities of the card
		print_capabilities(deckLink);
		
		// Release the IDeckLink instance when we've finished with it to prevent leaks
		deckLink->Release();
	}
	
	deckLinkIterator->Release();

	// If no DeckLink cards were found in the system, inform the user
	if (numDevices == 0)
		printf("No Blackmagic Design devices were found.\n");
	printf("\n");
	
	return 0;
}
コード例 #6
0
ファイル: print.c プロジェクト: steved/skirmish
void print_unit(unit *unit) {
  printf("type %d, state %s, vector (%f, %f, %f)\n", 
      unit->type, 
      ((state *)unit->state->value)->name, 
      x(unit->position), 
      y(unit->position),
      z(unit->position));
  printf("\t");
  print_attributes(unit->attributes);
  printf("\t");
  print_weapons(unit->weapons);
}
コード例 #7
0
vector<ofVideoDevice> ofxBlackmagicGrabber::listDevices() {
	IDeckLinkIterator*		deckLinkIterator;
	IDeckLink*				deckLink;
	int						numDevices = 0;
	HRESULT					result;
	
	vector<ofVideoDevice> devices;

	// Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
	deckLinkIterator = CreateDeckLinkIteratorInstance();
	if (deckLinkIterator == NULL){
		ofLogError(LOG_NAME) <<  "A DeckLink iterator could not be created.  The DeckLink drivers may not be installed.";
	}

	// Enumerate all cards in this system
	while (deckLinkIterator->Next(&deckLink) == S_OK){
		CFStringRef deviceNameString;

		// Increment the total number of DeckLink cards found
		numDevices++;
		if (numDevices > 1)
			printf("\n\n");

		// *** Print the model name of the DeckLink card
		result = deckLink->GetModelName(&deviceNameString);
		if (result == S_OK)
		{
			printf("=============== %s ===============\n\n", deviceNameString);
//			free(deviceNameString);
		}

		print_attributes(deckLink);

		// ** List the video output display modes supported by the card
		print_output_modes(deckLink);

		// ** List the input and output capabilities of the card
		print_capabilities(deckLink);

		// Release the IDeckLink instance when we've finished with it to prevent leaks
		deckLink->Release();
	}

	deckLinkIterator->Release();

	// If no DeckLink cards were found in the system, inform the user
	if (numDevices == 0)
		ofLogError(LOG_NAME) <<  "No Blackmagic Design devices were found.";

	return devices;
}
コード例 #8
0
ファイル: GModelSky.cpp プロジェクト: rbuehler/gammalib
/***********************************************************************//**
 * @brief Print model information
 ***************************************************************************/
std::string GModelSky::print_model(void) const
{
    // Initialise result string
    std::string result;

    // Determine number of parameters per type
    int n_spatial  = (m_spatial  != NULL) ? m_spatial->size()  : 0;
    int n_spectral = (m_spectral != NULL) ? m_spectral->size() : 0;
    int n_temporal = (m_temporal != NULL) ? m_temporal->size() : 0;

    // Append attributes
    result.append(print_attributes());

    // Append model type
    result.append("\n"+parformat("Model type"));
    if (n_spatial > 0) {
        result.append("\""+spatial()->type()+"\"");
        if (n_spectral > 0 || n_temporal > 0) {
            result.append(" * ");
        }
    }
    if (n_spectral > 0) {
        result.append("\""+spectral()->type()+"\"");
        if (n_temporal > 0) {
            result.append(" * ");
        }
    }
    if (n_temporal > 0) {
        result.append("\""+temporal()->type()+"\"");
    }

    // Append parameters
    result.append("\n"+parformat("Number of parameters")+str(size()));
    result.append("\n"+parformat("Number of spatial par's")+str(n_spatial));
    for (int i = 0; i < n_spatial; ++i) {
        result.append("\n"+(*spatial())[i].print());
    }
    result.append("\n"+parformat("Number of spectral par's")+str(n_spectral));
    for (int i = 0; i < n_spectral; ++i) {
        result.append("\n"+(*spectral())[i].print());
    }
    result.append("\n"+parformat("Number of temporal par's")+str(n_temporal));
    for (int i = 0; i < n_temporal; ++i) {
        result.append("\n"+(*temporal())[i].print());
    }

    // Return result
    return result;
}
コード例 #9
0
ファイル: softp11.c プロジェクト: heimdal/heimdal
CK_RV
C_FindObjectsInit(CK_SESSION_HANDLE hSession,
		  CK_ATTRIBUTE_PTR pTemplate,
		  CK_ULONG ulCount)
{
    struct session_state *state;

    st_logf("FindObjectsInit\n");

    INIT_CONTEXT();

    VERIFY_SESSION_HANDLE(hSession, &state);

    if (state->find.next_object != -1) {
	application_error("application didn't do C_FindObjectsFinal\n");
	find_object_final(state);
    }
    if (ulCount) {
	CK_ULONG i;

	print_attributes(pTemplate, ulCount);

	state->find.attributes =
	    calloc(1, ulCount * sizeof(state->find.attributes[0]));
	if (state->find.attributes == NULL)
	    return CKR_DEVICE_MEMORY;
	for (i = 0; i < ulCount; i++) {
	    state->find.attributes[i].pValue =
		malloc(pTemplate[i].ulValueLen);
	    if (state->find.attributes[i].pValue == NULL) {
		find_object_final(state);
		return CKR_DEVICE_MEMORY;
	    }
	    memcpy(state->find.attributes[i].pValue,
		   pTemplate[i].pValue, pTemplate[i].ulValueLen);
	    state->find.attributes[i].type = pTemplate[i].type;
	    state->find.attributes[i].ulValueLen = pTemplate[i].ulValueLen;
	}
	state->find.num_attributes = ulCount;
	state->find.next_object = 0;
    } else {
	st_logf("find all objects\n");
	state->find.attributes = NULL;
	state->find.num_attributes = 0;
	state->find.next_object = 0;
    }

    return CKR_OK;
}
コード例 #10
0
ファイル: scew_print.c プロジェクト: aconchillo/scew
static void
print_element (scew_element *element, unsigned int indent)
{
  XML_Char const *contents = NULL;
  scew_list *list = NULL;

  if (element == NULL)
    {
      return;
    }

  /* Prints the starting element tag with its attributes. */
  print_indent (indent);
  scew_printf (_XT("<%s"), scew_element_name (element));
  print_attributes (element);
  scew_printf (_XT(">"));

  contents = scew_element_contents (element);

  if (contents == NULL)
    {
      scew_printf (_XT("\n"));
    }

  /**
   * Call print_element function again for each child of the current
   * element.
   */
  list = scew_element_children (element);
  while (list != NULL)
    {
      scew_element *child = scew_list_data (list);
      print_element (child, indent + 1);
      list = scew_list_next (list);
    }

  /* Prints element's content. */
  if (contents != NULL)
    {
      scew_printf (_XT("%s"), contents);
    }
  else
    {
      print_indent (indent);
    }

  /* Prints the closing element tag. */
  scew_printf (_XT("</%s>\n"), scew_element_name (element));
}
コード例 #11
0
/***********************************************************************//**
 * @brief Print CTA cube background model information
 *
 * @param[in] chatter Chattiness (defaults to NORMAL).
 * @return String containing CTA cube background model information.
 ***************************************************************************/
std::string GCTAModelCubeBackground::print(const GChatter& chatter) const
{
    // Initialise result string
    std::string result;

    // Continue only if chatter is not silent
    if (chatter != SILENT) {

        // Append header
        result.append("=== GCTAModelCubeBackground ===");

        // Determine number of parameters per type
        int n_spectral = (spectral() != NULL) ? spectral()->size() : 0;
        int n_temporal = (temporal() != NULL) ? temporal()->size() : 0;

        // Append attributes
        result.append("\n"+print_attributes());

        // Append model type
        result.append("\n"+gammalib::parformat("Model type"));
        if (n_spectral > 0) {
            result.append("\""+spectral()->type()+"\"");
            if (n_temporal > 0) {
                result.append(" * ");
            }
        }
        if (n_temporal > 0) {
            result.append("\""+temporal()->type()+"\"");
        }

        // Append parameters
        result.append("\n"+gammalib::parformat("Number of parameters") +
                      gammalib::str(size()));
        result.append("\n"+gammalib::parformat("Number of spectral par's") +
                      gammalib::str(n_spectral));
        for (int i = 0; i < n_spectral; ++i) {
            result.append("\n"+(*spectral())[i].print());
        }
        result.append("\n"+gammalib::parformat("Number of temporal par's") +
                      gammalib::str(n_temporal));
        for (int i = 0; i < n_temporal; ++i) {
            result.append("\n"+(*temporal())[i].print());
        }

    } // endif: chatter was not silent

    // Return result
    return result;
}
コード例 #12
0
ostream &auth_attr_addr::print(ostream &os, uint32 level, const uint32 indent, const char *name ) const {
	os << setw(level*indent) << "";

	if ( name )
	  os << name <<  " = ";

	os << "[" << ie_name << ": xtype = "<<(int)x_type<<", subtype = "<<(int)sub_type<<", attribute_body : { \n";
	os << setw((level+1)*indent) << "";

	print_attributes(os);
	
	os <<"\n"<<setw(level*indent) << "";	 
	os << "}]";

	return os;	
}
コード例 #13
0
void print_ClassFile(ClassFile* class_file_ptr){
    printf("\n\nMagic: %.8x\n\n", class_file_ptr->magic);
	printf("Minor Version: %.4x\n", class_file_ptr->minor_version);
	printf("Major Version: %.4x\n\n", class_file_ptr->major_version);
    
    printConstantPoolTable(class_file_ptr->constant_pool_count, class_file_ptr->constant_pool);

    print_interface(class_file_ptr->interfaces, class_file_ptr->interfaces_count, class_file_ptr->constant_pool);

    printField(class_file_ptr->constant_pool, class_file_ptr->fields, class_file_ptr->fields_count);

    print_Methods(class_file_ptr, class_file_ptr->constant_pool);

    print_attributes(class_file_ptr->attributes, class_file_ptr->attributes_count, class_file_ptr->constant_pool);

    
}
コード例 #14
0
void dump_inst(const xed_inst_t* p) {
    unsigned int j;
    printf("%s ", xed_iclass_enum_t2str(xed_inst_iclass(p)));
    printf("%s ", xed_iform_enum_t2str(xed_inst_iform_enum(p)));
    printf("%s ", xed_category_enum_t2str(xed_inst_category(p)));
    printf("%s ", xed_extension_enum_t2str(xed_inst_extension(p)));
    printf("%s ", xed_isa_set_enum_t2str(xed_inst_isa_set(p)));
    print_attributes(p);
    printf("%2u ", xed_inst_noperands(p));
    printf("\n");
    for(j=0;j<xed_inst_noperands(p);j++) {
        printf("\t%u ", j);
        dump_operand(xed_inst_operand(p,j));
        printf("\n");
    }

}
コード例 #15
0
  void trace(methodOop method, address bcp, uintptr_t tos, uintptr_t tos2) {
#ifndef PRODUCT
    MutexLocker ml(BytecodeTrace_lock);
    if (_current_method != method) {
      // Note 1: This code will not work as expected with true MT/MP.
      //         Need an explicit lock or a different solution.
      ResourceMark rm;
      tty->cr();
      tty->print("[%d] ", (int) Thread::current()->osthread()->thread_id());
      method->print_name(tty);
      tty->cr();
      _current_method = method;
    }
    if (Verbose) {
      const char* format;
      switch (Bytecodes::length_at(bcp)) {
        case  1: format = "%x  %02x         "    ; break;
        case  2: format = "%x  %02x %02x      "  ; break;
        case  3: format = "%x  %02x %02x %02x   "; break;
        default: format = "%x  %02x %02x %02x .."; break;
      }
      tty->print(format, bcp, *bcp, *(bcp+1), *(bcp+2));
    }
    Bytecodes::Code code;
    if (_previous_bytecode == Bytecodes::_wide) {
      code = Bytecodes::cast(*(bcp+1));
    } else {
      code = Bytecodes::cast(*bcp);
    }
    int bci = bcp - method->code_base();
    const char* format = _previous_bytecode == Bytecodes::_wide ? Bytecodes::wide_format(code) : Bytecodes::format(code);
    tty->print("[%d] ", (int) Thread::current()->osthread()->thread_id());
    if (Verbose) {
      tty->print("%8d  %4d  0x%016lx 0x%016lx %s", 
	   BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
    } else {
      tty->print("%8d  %4d  %s", 
	   BytecodeCounter::counter_value(), bci, Bytecodes::name(code));
    }
    print_attributes(bcp, bci, format);
    tty->cr();
    _previous_bytecode = code;
#endif
  }
コード例 #16
0
 // Used for methodOop::print_codes().  The input bcp comes from
 // BytecodeStream, which will skip wide bytecodes.
 void trace(methodHandle method, address bcp, outputStream* st) {
   _current_method = method();
   ResourceMark rm;
   Bytecodes::Code code = Bytecodes::code_at(bcp);
   // Set is_wide
   _is_wide = (code == Bytecodes::_wide);
   if (is_wide()) {
     code = Bytecodes::code_at(bcp+1);
   }
   int bci = bcp - method->code_base();
   // Print bytecode index and name
   if (is_wide()) {
     st->print("%d %s_w", bci, Bytecodes::name(code));
   } else {
     st->print("%d %s", bci, Bytecodes::name(code));
   }
   _next_pc = is_wide() ? bcp+2 : bcp+1;
   print_attributes(code, bci, st);
   bytecode_epilog(bci, st);
 }
コード例 #17
0
ファイル: rapidxml_print.hpp プロジェクト: gjianw217/DLPRobot
        inline OutIt print_declaration_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
        {
            // Print declaration start
            if (!(flags & print_no_indenting))
                out = fill_chars(out, indent, Ch('\t'));
            *out = Ch('<'), ++out;
            *out = Ch('?'), ++out;
            *out = Ch('x'), ++out;
            *out = Ch('m'), ++out;
            *out = Ch('l'), ++out;

            // Print attributes
            out = print_attributes(out, node, flags);

            // Print declaration end
            *out = Ch('?'), ++out;
            *out = Ch('>'), ++out;

            return out;
        }
コード例 #18
0
ファイル: attributes.copy.c プロジェクト: edishuman/asg5
int main (void) {
   printf ("Number of bits in a bitset = %lu\n",
           CHAR_BIT * sizeof (bitset_t));
   for (bitset_t set = 0xF; set < 1L << 32; set <<= 4) {
      printf ("bitset 0x%016lX =", set);
      print_attributes (set);
      printf ("\n");
   }
   
    printf("\nmy own\n");
    
    bitset_t temp1 = 1 << ATTR_INDEX_INT;
    temp1 |= 1 << ATTR_INDEX_CONST;
    
    bitset_t temp2 = 1 << ATTR_INDEX_CHAR;
    temp2 |= 1 << ATTR_INDEX_CONST;
    
   
   
    return EXIT_SUCCESS;
}
コード例 #19
0
 // This method is called while executing the raw bytecodes, so none of
 // the adjustments that BytecodeStream performs applies.
 void trace(methodHandle method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) {
   ResourceMark rm;
   if (_current_method != method()) {
     // Note 1: This code will not work as expected with true MT/MP.
     //         Need an explicit lock or a different solution.
     // It is possible for this block to be skipped, if a garbage
     // _current_method pointer happens to have the same bits as
     // the incoming method.  We could lose a line of trace output.
     // This is acceptable in a debug-only feature.
     st->cr();
     st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
     method->print_name(st);
     st->cr();
     _current_method = method();
   }
   Bytecodes::Code code;
   if (is_wide()) {
     // bcp wasn't advanced if previous bytecode was _wide.
     code = Bytecodes::code_at(method(), bcp+1);
   } else {
     code = Bytecodes::code_at(method(), bcp);
   }
   _code = code;
    int bci = bcp - method->code_base();
   st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
   if (Verbose) {
     st->print("%8d  %4d  " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
          BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
   } else {
     st->print("%8d  %4d  %s",
          BytecodeCounter::counter_value(), bci, Bytecodes::name(code));
   }
   _next_pc = is_wide() ? bcp+2 : bcp+1;
   print_attributes(bci);
   // Set is_wide for the next one, since the caller of this doesn't skip
   // the next bytecode.
   _is_wide = (code == Bytecodes::_wide);
   _code = Bytecodes::_illegal;
 }
コード例 #20
0
static void print_session(sdp_printer_t *p, sdp_session_t const *sdp)
{
  p->pr_ok = 1;

  if (p->pr_ok && sdp->sdp_version)
    print_version(p, sdp->sdp_version);
  if (p->pr_ok && sdp->sdp_origin)
    print_origin(p, sdp->sdp_origin);
  if (p->pr_ok && sdp->sdp_subject)
    print_subject(p, sdp->sdp_subject);
  if (p->pr_ok && sdp->sdp_information)
    print_information(p, sdp->sdp_information);
  if (p->pr_ok && sdp->sdp_uri)
    print_uri(p, sdp->sdp_uri);
  if (p->pr_ok && sdp->sdp_emails)
    print_emails(p, sdp->sdp_emails);
  if (p->pr_ok && sdp->sdp_phones)
    print_phones(p, sdp->sdp_phones);
  if (p->pr_ok && sdp->sdp_connection)
    print_connection(p, sdp->sdp_connection);
  if (p->pr_ok && sdp->sdp_bandwidths)
    print_bandwidths(p, sdp->sdp_bandwidths);
  if (p->pr_ok)
    print_time(p, sdp->sdp_time);
  if (p->pr_ok && sdp->sdp_time) {
    if (p->pr_ok && sdp->sdp_time->t_repeat)
      print_repeat(p, sdp->sdp_time->t_repeat);
    if (p->pr_ok && sdp->sdp_time->t_zone)
      print_zone(p, sdp->sdp_time->t_zone);
  }
  if (p->pr_ok && sdp->sdp_key)
    print_key(p, sdp->sdp_key);
  if (p->pr_ok && sdp->sdp_charset)
    print_charset(p, sdp->sdp_charset);
  if (p->pr_ok && sdp->sdp_attributes)
    print_attributes(p, sdp->sdp_attributes);
  if (p->pr_ok && sdp->sdp_media)
    print_media(p, sdp, sdp->sdp_media);
}
コード例 #21
0
static char *print_script(widechar *buffer, int length) {
  static char script[BUFSIZE];
  int i = 0;
  int j = 0;
  int action = 0;
  while (i < length) {
    switch (buffer[i]) {
      case pass_first:
      case pass_last:
      case pass_not:
      case pass_startReplace:
      case pass_endReplace:
      case pass_search:
      case pass_copy:
      case pass_omit:
        append_char(script, &j, buffer[i++]);
        break;
      case pass_lookback:
        append_char(script, &j, buffer[i++]);
	if (buffer[i] > 1)
	  append_string(script, &j, print_number(buffer[i++]));
        break;
      case pass_string:
        append_char(script, &j, buffer[i]);
        append_string(script, &j, print_chars(&buffer[i+2], buffer[i+1]));
        append_char(script, &j, buffer[i]);
        i += (2 + buffer[i+1]);
        break;
      case pass_dots:
        append_char(script, &j, buffer[i++]);
        append_string(script, &j, print_dots(&buffer[i+1], buffer[i]));
        i += (1 + buffer[i]);
        break;
      case pass_eq:
      case pass_lt:
      case pass_gt:
      case pass_lteq:
      case pass_gteq:
        append_char(script, &j, '#');
        append_string(script, &j, print_number(buffer[i+1]));
        append_char(script, &j, buffer[i]);
        append_string(script, &j, print_number(buffer[i+2]));
        i += 3;
        break;
      case pass_hyphen:
      case pass_plus:
        append_char(script, &j, '#');
        append_string(script, &j, print_number(buffer[i+1]));
        append_char(script, &j, buffer[i]);
        i += 2;
        break;
      case pass_attributes:
        append_char(script, &j, buffer[i]);
        append_string(script, &j, print_attributes(buffer[i+1] << 16 | buffer[i+2]));
        i += 3;
        if (buffer[i] == 1 && buffer[i+1] == 1) {}
        else if (buffer[i] == 1 && buffer[i+1] == 0xffff)
          append_char(script, &j, pass_until);
        else if (buffer[i] == buffer[i+1])
          append_string(script, &j, print_number(buffer[i]));
        else {
          append_string(script, &j, print_number(buffer[i]));
          append_char(script, &j, '-');
          append_string(script, &j, print_number(buffer[i+1])); }
        i += 2;
        break;
      case pass_endTest:
        append_char(script, &j, '\t');
        action = 1;
        i++;
        break;
      case pass_swap:
      case pass_groupstart:
      case pass_groupend:
      case pass_groupreplace:
        /* TBD */
      default:
        i++;
        break; }}
  script[j] = 0;
  return script;
}
コード例 #22
0
static void print_media(sdp_printer_t *p,
			sdp_session_t const *sdp,
			sdp_media_t const *m)
{
  char const *media, *proto;
  sdp_rtpmap_t *rm;

  sdp_mode_t session_mode = sdp_sendrecv;

  if (!p->pr_mode_manual)
    session_mode = sdp_attribute_mode(sdp->sdp_attributes, sdp_sendrecv);

  for (;m ; m = m->m_next) {
    switch (m->m_type) {
    case sdp_media_audio:       media = "audio"; break;
    case sdp_media_video:       media = "video"; break;
    case sdp_media_application: media = "application"; break;
    case sdp_media_data:        media = "data"; break;
    case sdp_media_control:     media = "control"; break;
    case sdp_media_message:     media = "message"; break;
    case sdp_media_image  :     media = "image"; break;
    default:                    media = m->m_type_name;
    }

    switch (m->m_proto) {
    case sdp_proto_tcp:   proto = "tcp"; break;
    case sdp_proto_udp:   proto = "udp"; break;
    case sdp_proto_rtp:   proto = "RTP/AVP"; break;
    case sdp_proto_srtp:  proto = "RTP/SAVP"; break;
    case sdp_proto_udptl: proto = "udptl"; break;
    case sdp_proto_msrp:  proto = "TCP/MSRP"; break;
    case sdp_proto_msrps:  proto = "TCP/TLS/MSRP"; break;
    case sdp_proto_tls:   proto = "tls"; break;
    default:              proto = m->m_proto_name; break;
    }

    if (m->m_number_of_ports <= 1)
      sdp_printf(p, "m=%s %u %s", media, m->m_port, proto);
    else
      sdp_printf(p, "m=%s %u/%u %s",
		 media, m->m_port, m->m_number_of_ports, proto);

    if (m->m_rtpmaps) {
      for (rm = m->m_rtpmaps; rm; rm = rm->rm_next) {
	if (rm->rm_any)
	  sdp_printf(p, " *");
	else
	  sdp_printf(p, " %u", (unsigned)rm->rm_pt);
      }
    }
    else if (m->m_format) {
      sdp_list_t *l = m->m_format;
      for (; l; l = l->l_next)
	sdp_printf(p, " %s", l->l_text);
    }
    else {
      sdp_printf(p, " 19");      /* SDP syntax requires at least one format.
				    19 is used by nobody, right?. */
    }


    sdp_printf(p, CRLF);

    if (m->m_information)
      print_information(p, m->m_information);
    if (m->m_connections)
#ifdef nomore
    if (m->m_connections != sdp->sdp_connection)
#endif
      print_connection_list(p, m->m_connections);
    if (m->m_bandwidths)
      print_bandwidths(p, m->m_bandwidths);
    if (m->m_key)
      print_key(p, m->m_key);

    for (rm = m->m_rtpmaps; rm; rm = rm->rm_next) {
      if (!rm->rm_predef || p->pr_all_rtpmaps)
	sdp_printf(p, "a=rtpmap:%u %s/%lu%s%s" CRLF,
		   rm->rm_pt, rm->rm_encoding, rm->rm_rate,
		   rm->rm_params ? "/" : "",
		   rm->rm_params ? rm->rm_params : "");
      if (rm->rm_fmtp)
	sdp_printf(p, "a=fmtp:%u %s" CRLF,
		   rm->rm_pt, rm->rm_fmtp);
    }

    if (!p->pr_mode_manual && !m->m_rejected &&
	(m->m_mode != (unsigned int)session_mode || p->pr_mode_always)) {
      switch (m->m_mode) {
      case sdp_inactive:
	sdp_printf(p, "a=inactive" CRLF);
	break;
      case sdp_sendonly:
	sdp_printf(p, "a=sendonly" CRLF);
	break;
      case sdp_recvonly:
	sdp_printf(p, "a=recvonly" CRLF);
	break;
      case sdp_sendrecv:
	sdp_printf(p, "a=sendrecv" CRLF);
	break;
      default:
	break;
      }
    }

    if (p->pr_mode_manual)
      print_attributes(p, m->m_attributes);
    else
      print_attributes_without_mode(p, m->m_attributes);
  }
}
コード例 #23
0
void print_attributes (attribute_info *attributes, u2 attr_count, cp_info *pool) {
    u2 counter = 0;
    
    printf("\n*****Attributes*****\n\n");
    
    while (counter < attr_count) {
        switch (attributes[counter].tag) {
            case 0:
                printf("------------------------------------------------\n");
                printf("[%d] ConstantValue\n", counter);
                printf("\tAttribute name index: cp_info #%d\n",attributes[counter].attribute_name_index);
                printf("\tAttribute length: %d\n",attributes[counter].attribute_length);

                break;
            case 1:
                printf("------------------------------------------------\n");
                printf("[%d] Code\n", counter);
                printf("\tAttribute name index: cp_info #%d\n",attributes[counter].attribute_name_index);
                printf("\tAttribute length: %d\n",attributes[counter].attribute_length);
                printf("Info:\n");
                printf("\tMaximum stack depth:\t %d\n",attributes[counter].info.Code_attribute.max_stack);
                printf("\tMaximum local variable:\t %d\n",attributes[counter].info.Code_attribute.max_locals);
                printf("\tCode length:\t %d\n",attributes[counter].info.Code_attribute.code_length);
                //opcodes
                for(int i = 0; i < attributes[counter].info.Code_attribute.code_length; i++){
                    switch( attributes[counter].info.Code_attribute.code[i] ){
                        case op_nop: 
                        	printf("%s\n", opcodes_str_names[op_nop]);
                        	break;
                        case op_aconst_null: 
                        	printf("%s\n", opcodes_str_names[op_aconst_null]);
                        	break;
                        case op_iconst_m1: 
                        	printf("%s\n", opcodes_str_names[op_iconst_m1]);
                        	break;
                        case op_iconst_0: 
                        	printf("%s\n", opcodes_str_names[op_iconst_0]);
                        	break;
                        case op_iconst_1: 
                        	printf("%s\n", opcodes_str_names[op_iconst_1]);
                        	break;
                        case op_iconst_2: 
                        	printf("%s\n", opcodes_str_names[op_iconst_2]);
                        	break;
                        case op_iconst_3: 
                        	printf("%s\n", opcodes_str_names[op_iconst_3]);
                        	break;
                        case op_iconst_4: 
                        	printf("%s\n", opcodes_str_names[op_iconst_4]);
                        	break;
                        case op_iconst_5: 
                        	printf("%s\n", opcodes_str_names[op_iconst_5]);
                        	break;
                        case op_lconst_0: 
                        	printf("%s\n", opcodes_str_names[op_lconst_0]);
                        	break;
                        case op_lconst_1: 
                        	printf("%s\n", opcodes_str_names[op_lconst_1]);
                        	break;
                        case op_fconst_0: 
                        	printf("%s\n", opcodes_str_names[op_fconst_0]);
                        	break;
                        case op_fconst_1: 
                        	printf("%s\n", opcodes_str_names[op_fconst_1]);
                        	break;
                        case op_fconst_2: 
                        	printf("%s\n", opcodes_str_names[op_fconst_2]);
                        	break;
                        case op_dconst_0: 
                        	printf("%s\n", opcodes_str_names[op_dconst_0]);
                        	break;
                        case op_dconst_1: 
                        	printf("%s\n", opcodes_str_names[op_dconst_1]);
                        	break;
                        case op_bipush: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_bipush]);
                        	break;
                        case op_sipush: 
                            i+= 2;
                        	printf("%s\n", opcodes_str_names[op_sipush]);
                        	break;
                        case op_ldc: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_ldc]);
                        	break;
                        case op_ldc_w: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_ldc_w]);
                        	break;
                        case op_ldc2_w: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_ldc2_w]);
                        	break;
                        case op_iload: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_iload]);
                        	break;
                        case op_lload: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_lload]);
                        	break;
                        case op_fload: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_fload]);
                        	break;
                        case op_dload: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_dload]);
                        	break;
                        case op_aload: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_aload]);
                        	break;
                        case op_iload_0: 
                        	printf("%s\n", opcodes_str_names[op_iload_0]);
                        	break;
                        case op_iload_1: 
                        	printf("%s\n", opcodes_str_names[op_iload_1]);
                        	break;
                        case op_iload_2: 
                        	printf("%s\n", opcodes_str_names[op_iload_2]);
                        	break;
                        case op_iload_3: 
                        	printf("%s\n", opcodes_str_names[op_iload_3]);
                        	break;
                        case op_lload_0: 
                        	printf("%s\n", opcodes_str_names[op_lload_0]);
                        	break;
                        case op_lload_1: 
                        	printf("%s\n", opcodes_str_names[op_lload_1]);
                        	break;
                        case op_lload_2: 
                        	printf("%s\n", opcodes_str_names[op_lload_2]);
                        	break;
                        case op_lload_3: 
                        	printf("%s\n", opcodes_str_names[op_lload_3]);
                        	break;
                        case op_fload_0: 
                        	printf("%s\n", opcodes_str_names[op_fload_0]);
                        	break;
                        case op_fload_1: 
                        	printf("%s\n", opcodes_str_names[op_fload_1]);
                        	break;
                        case op_fload_2: 
                        	printf("%s\n", opcodes_str_names[op_fload_2]);
                        	break;
                        case op_fload_3: 
                        	printf("%s\n", opcodes_str_names[op_fload_3]);
                        	break;
                        case op_dload_0: 
                        	printf("%s\n", opcodes_str_names[op_dload_0]);
                        	break;
                        case op_dload_1: 
                        	printf("%s\n", opcodes_str_names[op_dload_1]);
                        	break;
                        case op_dload_2: 
                        	printf("%s\n", opcodes_str_names[op_dload_2]);
                        	break;
                        case op_dload_3: 
                        	printf("%s\n", opcodes_str_names[op_dload_3]);
                        	break;
                        case op_aload_0: 
                        	printf("%s\n", opcodes_str_names[op_aload_0]);
                        	break;
                        case op_aload_1: 
                        	printf("%s\n", opcodes_str_names[op_aload_1]);
                        	break;
                        case op_aload_2: 
                        	printf("%s\n", opcodes_str_names[op_aload_2]);
                        	break;
                        case op_aload_3: 
                        	printf("%s\n", opcodes_str_names[op_aload_3]);
                        	break;
                        case op_iaload: 
                        	printf("%s\n", opcodes_str_names[op_iaload]);
                        	break;
                        case op_laload: 
                        	printf("%s\n", opcodes_str_names[op_laload]);
                        	break;
                        case op_faload: 
                        	printf("%s\n", opcodes_str_names[op_faload]);
                        	break;
                        case op_daload: 
                        	printf("%s\n", opcodes_str_names[op_daload]);
                        	break;
                        case op_aaload: 
                        	printf("%s\n", opcodes_str_names[op_aaload]);
                        	break;
                        case op_baload: 
                        	printf("%s\n", opcodes_str_names[op_baload]);
                        	break;
                        case op_caload: 
                        	printf("%s\n", opcodes_str_names[op_caload]);
                        	break;
                        case op_saload: 
                        	printf("%s\n", opcodes_str_names[op_saload]);
                        	break;
                        case op_istore: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_istore]);
                        	break;
                        case op_lstore: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_lstore]);
                        	break;
                        case op_fstore: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_fstore]);
                        	break;
                        case op_dstore: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_dstore]);
                        	break;
                        case op_astore: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_astore]);
                        	break;
                        case op_istore_0: 
                        	printf("%s\n", opcodes_str_names[op_istore_0]);
                        	break;
                        case op_istore_1: 
                        	printf("%s\n", opcodes_str_names[op_istore_1]);
                        	break;
                        case op_istore_2: 
                        	printf("%s\n", opcodes_str_names[op_istore_2]);
                        	break;
                        case op_istore_3: 
                        	printf("%s\n", opcodes_str_names[op_istore_3]);
                        	break;
                        case op_lstore_0: 
                        	printf("%s\n", opcodes_str_names[op_lstore_0]);
                        	break;
                        case op_lstore_1: 
                        	printf("%s\n", opcodes_str_names[op_lstore_1]);
                        	break;
                        case op_lstore_2: 
                        	printf("%s\n", opcodes_str_names[op_lstore_2]);
                        	break;
                        case op_lstore_3: 
                        	printf("%s\n", opcodes_str_names[op_lstore_3]);
                        	break;
                        case op_fstore_0: 
                        	printf("%s\n", opcodes_str_names[op_fstore_0]);
                        	break;
                        case op_fstore_1: 
                        	printf("%s\n", opcodes_str_names[op_fstore_1]);
                        	break;
                        case op_fstore_2: 
                        	printf("%s\n", opcodes_str_names[op_fstore_2]);
                        	break;
                        case op_fstore_3: 
                        	printf("%s\n", opcodes_str_names[op_fstore_3]);
                        	break;
                        case op_dstore_0: 
                        	printf("%s\n", opcodes_str_names[op_dstore_0]);
                        	break;
                        case op_dstore_1: 
                        	printf("%s\n", opcodes_str_names[op_dstore_1]);
                        	break;
                        case op_dstore_2: 
                        	printf("%s\n", opcodes_str_names[op_dstore_2]);
                        	break;
                        case op_dstore_3: 
                        	printf("%s\n", opcodes_str_names[op_dstore_3]);
                        	break;
                        case op_astore_0: 
                        	printf("%s\n", opcodes_str_names[op_astore_0]);
                        	break;
                        case op_astore_1: 
                        	printf("%s\n", opcodes_str_names[op_astore_1]);
                        	break;
                        case op_astore_2: 
                        	printf("%s\n", opcodes_str_names[op_astore_2]);
                        	break;
                        case op_astore_3: 
                        	printf("%s\n", opcodes_str_names[op_astore_3]);
                        	break;
                        case op_iastore: 
                        	printf("%s\n", opcodes_str_names[op_iastore]);
                        	break;
                        case op_lastore: 
                        	printf("%s\n", opcodes_str_names[op_lastore]);
                        	break;
                        case op_fastore: 
                        	printf("%s\n", opcodes_str_names[op_fastore]);
                        	break;
                        case op_dastore: 
                        	printf("%s\n", opcodes_str_names[op_dastore]);
                        	break;
                        case op_aastore: 
                        	printf("%s\n", opcodes_str_names[op_aastore]);
                        	break;
                        case op_bastore: 
                        	printf("%s\n", opcodes_str_names[op_bastore]);
                        	break;
                        case op_castore: 
                        	printf("%s\n", opcodes_str_names[op_castore]);
                        	break;
                        case op_sastore: 
                        	printf("%s\n", opcodes_str_names[op_sastore]);
                        	break;
                        case op_pop: 
                        	printf("%s\n", opcodes_str_names[op_pop]);
                        	break;
                        case op_pop2: 
                        	printf("%s\n", opcodes_str_names[op_pop2]);
                        	break;
                        case op_dup: 
                        	printf("%s\n", opcodes_str_names[op_dup]);
                        	break;
                        case op_dup_x1: 
                        	printf("%s\n", opcodes_str_names[op_dup_x1]);
                        	break;
                        case op_dup_x2: 
                        	printf("%s\n", opcodes_str_names[op_dup_x2]);
                        	break;
                        case op_dup2: 
                        	printf("%s\n", opcodes_str_names[op_dup2]);
                        	break;
                        case op_dup2_x1: 
                        	printf("%s\n", opcodes_str_names[op_dup2_x1]);
                        	break;
                        case op_dup2_x2: 
                        	printf("%s\n", opcodes_str_names[op_dup2_x2]);
                        	break;
                        case op_swap: 
                        	printf("%s\n", opcodes_str_names[op_swap]);
                        	break;
                        case op_iadd: 
                        	printf("%s\n", opcodes_str_names[op_iadd]);
                        	break;
                        case op_ladd: 
                        	printf("%s\n", opcodes_str_names[op_ladd]);
                        	break;
                        case op_fadd: 
                        	printf("%s\n", opcodes_str_names[op_fadd]);
                        	break;
                        case op_dadd: 
                        	printf("%s\n", opcodes_str_names[op_dadd]);
                        	break;
                        case op_isub: 
                        	printf("%s\n", opcodes_str_names[op_isub]);
                        	break;
                        case op_lsub: 
                        	printf("%s\n", opcodes_str_names[op_lsub]);
                        	break;
                        case op_fsub: 
                        	printf("%s\n", opcodes_str_names[op_fsub]);
                        	break;
                        case op_dsub: 
                        	printf("%s\n", opcodes_str_names[op_dsub]);
                        	break;
                        case op_imul: 
                        	printf("%s\n", opcodes_str_names[op_imul]);
                        	break;
                        case op_lmul: 
                        	printf("%s\n", opcodes_str_names[op_lmul]);
                        	break;
                        case op_fmul: 
                        	printf("%s\n", opcodes_str_names[op_fmul]);
                        	break;
                        case op_dmul: 
                        	printf("%s\n", opcodes_str_names[op_dmul]);
                        	break;
                        case op_idiv: 
                        	printf("%s\n", opcodes_str_names[op_idiv]);
                        	break;
                        case op_ldiv: 
                        	printf("%s\n", opcodes_str_names[op_ldiv]);
                        	break;
                        case op_fdiv: 
                        	printf("%s\n", opcodes_str_names[op_fdiv]);
                        	break;
                        case op_ddiv: 
                        	printf("%s\n", opcodes_str_names[op_ddiv]);
                        	break;
                        case op_irem: 
                        	printf("%s\n", opcodes_str_names[op_irem]);
                        	break;
                        case op_lrem: 
                        	printf("%s\n", opcodes_str_names[op_lrem]);
                        	break;
                        case op_frem: 
                        	printf("%s\n", opcodes_str_names[op_frem]);
                        	break;
                        case op_drem: 
                        	printf("%s\n", opcodes_str_names[op_drem]);
                        	break;
                        case op_ineg: 
                        	printf("%s\n", opcodes_str_names[op_ineg]);
                        	break;
                        case op_lneg: 
                        	printf("%s\n", opcodes_str_names[op_lneg]);
                        	break;
                        case op_fneg: 
                        	printf("%s\n", opcodes_str_names[op_fneg]);
                        	break;
                        case op_dneg: 
                        	printf("%s\n", opcodes_str_names[op_dneg]);
                        	break;
                        case op_ishl: 
                        	printf("%s\n", opcodes_str_names[op_ishl]);
                        	break;
                        case op_lshl: 
                        	printf("%s\n", opcodes_str_names[op_lshl]);
                        	break;
                        case op_ishr: 
                        	printf("%s\n", opcodes_str_names[op_ishr]);
                        	break;
                        case op_lshr: 
                        	printf("%s\n", opcodes_str_names[op_lshr]);
                        	break;
                        case op_iushr: 
                        	printf("%s\n", opcodes_str_names[op_iushr]);
                        	break;
                        case op_lushr: 
                        	printf("%s\n", opcodes_str_names[op_lushr]);
                        	break;
                        case op_iand: 
                        	printf("%s\n", opcodes_str_names[op_iand]);
                        	break;
                        case op_land: 
                        	printf("%s\n", opcodes_str_names[op_land]);
                        	break;
                        case op_ior: 
                        	printf("%s\n", opcodes_str_names[op_ior]);
                        	break;
                        case op_lor: 
                        	printf("%s\n", opcodes_str_names[op_lor]);
                        	break;
                        case op_ixor: 
                        	printf("%s\n", opcodes_str_names[op_ixor]);
                        	break;
                        case op_lxor: 
                        	printf("%s\n", opcodes_str_names[op_lxor]);
                        	break;
                        case op_iinc: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_iinc]);
                        	break;
                        case op_i2l: 
                        	printf("%s\n", opcodes_str_names[op_i2l]);
                        	break;
                        case op_i2f: 
                        	printf("%s\n", opcodes_str_names[op_i2f]);
                        	break;
                        case op_i2d: 
                        	printf("%s\n", opcodes_str_names[op_i2d]);
                        	break;
                        case op_l2i: 
                        	printf("%s\n", opcodes_str_names[op_l2i]);
                        	break;
                        case op_l2f: 
                        	printf("%s\n", opcodes_str_names[op_l2f]);
                        	break;
                        case op_l2d: 
                        	printf("%s\n", opcodes_str_names[op_l2d]);
                        	break;
                        case op_f2i: 
                        	printf("%s\n", opcodes_str_names[op_f2i]);
                        	break;
                        case op_f2l: 
                        	printf("%s\n", opcodes_str_names[op_f2l]);
                        	break;
                        case op_f2d: 
                        	printf("%s\n", opcodes_str_names[op_f2d]);
                        	break;
                        case op_d2i: 
                        	printf("%s\n", opcodes_str_names[op_d2i]);
                        	break;
                        case op_d2l: 
                        	printf("%s\n", opcodes_str_names[op_d2l]);
                        	break;
                        case op_d2f: 
                        	printf("%s\n", opcodes_str_names[op_d2f]);
                        	break;
                        case op_i2b: 
                        	printf("%s\n", opcodes_str_names[op_i2b]);
                        	break;
                        case op_i2c: 
                        	printf("%s\n", opcodes_str_names[op_i2c]);
                        	break;
                        case op_i2s: 
                        	printf("%s\n", opcodes_str_names[op_i2s]);
                        	break;
                        case op_lcmp: 
                        	printf("%s\n", opcodes_str_names[op_lcmp]);
                        	break;
                        case op_fcmpl: 
                        	printf("%s\n", opcodes_str_names[op_fcmpl]);
                        	break;
                        case op_fcmpg: 
                        	printf("%s\n", opcodes_str_names[op_fcmpg]);
                        	break;
                        case op_dcmpl: 
                        	printf("%s\n", opcodes_str_names[op_dcmpl]);
                        	break;
                        case op_dcmpg: 
                        	printf("%s\n", opcodes_str_names[op_dcmpg]);
                        	break;
                        case op_ifeq: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_ifeq]);
                        	break;
                        case op_ifne: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_ifne]);
                        	break;
                        case op_iflt: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_iflt]);
                        	break;
                        case op_ifge: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_ifge]);
                        	break;
                        case op_ifgt: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_ifgt]);
                        	break;
                        case op_ifle: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_ifle]);
                        	break;
                        case op_if_icmpeq: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_if_icmpeq]);
                        	break;
                        case op_if_icmpne: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_if_icmpne]);
                        	break;
                        case op_if_icmplt: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_if_icmplt]);
                        	break;
                        case op_if_icmpge: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_if_icmpge]);
                        	break;
                        case op_if_icmpgt: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_if_icmpgt]);
                        	break;
                        case op_if_icmple: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_if_icmple]);
                        	break;
                        case op_if_acmpeq: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_if_acmpeq]);
                        	break;
                        case op_if_acmpne: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_if_acmpne]);
                        	break;
                        case op_goto: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_goto]);
                        	break;
                        case op_jsr: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_jsr]);
                        	break;
                        case op_ret: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_ret]);
                        	break;
                        case op_tableswitch: 
                        	printf("%s\n", opcodes_str_names[op_tableswitch]);
                        	break;
                        case op_lookupswitch: 
                        	printf("%s\n", opcodes_str_names[op_lookupswitch]);
                        	break;
                        case op_ireturn: 
                        	printf("%s\n", opcodes_str_names[op_ireturn]);
                        	break;
                        case op_lreturn: 
                        	printf("%s\n", opcodes_str_names[op_lreturn]);
                        	break;
                        case op_freturn: 
                        	printf("%s\n", opcodes_str_names[op_freturn]);
                        	break;
                        case op_dreturn: 
                        	printf("%s\n", opcodes_str_names[op_dreturn]);
                        	break;
                        case op_areturn: 
                        	printf("%s\n", opcodes_str_names[op_areturn]);
                        	break;
                        case op_return: 
                        	printf("%s\n", opcodes_str_names[op_return]);
                        	break;
                        case op_getstatic: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_getstatic]);
                        	break;
                        case op_putstatic: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_putstatic]);
                        	break;
                        case op_getfield: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_getfield]);
                        	break;
                        case op_putfield: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_putfield]);
                        	break;
                        case op_invokevirtual: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_invokevirtual]);
                        	break;
                        case op_invokespecial: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_invokespecial]);
                        	break;
                        case op_invokestatic: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_invokestatic]);
                        	break;
                        case op_invokeinterface: 
                            i+=4;
                        	printf("%s\n", opcodes_str_names[op_invokeinterface]);
                        	break;
                        case op_new: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_new]);
                        	break;
                        case op_newarray: 
                            i++;
                        	printf("%s\n", opcodes_str_names[op_newarray]);
                        	break;
                        case op_anewarray: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_anewarray]);
                        	break;
                        case op_arraylength: 
                        	printf("%s\n", opcodes_str_names[op_arraylength]);
                        	break;
                        case op_athrow: 
                        	printf("%s\n", opcodes_str_names[op_athrow]);
                        	break;
                        case op_checkcast: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_checkcast]);
                        	break;
                        case op_instanceof: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_instanceof]);
                        	break;
                        case op_monitorenter: 
                        	printf("%s\n", opcodes_str_names[op_monitorenter]);
                        	break;
                        case op_monitorexit: 
                        	printf("%s\n", opcodes_str_names[op_monitorexit]);
                        	break;
                        case op_wide: 
                        	printf("%s\n", opcodes_str_names[op_wide]);
                        	break;
                        case op_multianewarray: 
                            i+=3;
                        	printf("%s\n", opcodes_str_names[op_multianewarray]);
                        	break;
                        case op_ifnull: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_ifnull]);
                        	break;
                        case op_ifnonnull: 
                            i+=2;
                        	printf("%s\n", opcodes_str_names[op_ifnonnull]);
                        	break;
                        case op_goto_w: 
                            i+=4;
                        	printf("%s\n", opcodes_str_names[op_goto_w]);
                        	break;
                        case op_jsr_w: 
                            i+=4;
                        	printf("%s\n", opcodes_str_names[op_jsr_w]);
                        	break;
                        case op_breakpoint: 
                        	printf("%s\n", opcodes_str_names[op_breakpoint]);
                        	break;
                        default:
                            printf("opcode desconhecido\n");
                    }
                } 
                print_attributes(attributes[counter].info.Code_attribute.attribute, attributes[counter].info.Code_attribute.attribute_count, pool);

                break;
            case 2:
                printf("------------------------------------------------\n");
                printf("[%d] Exceptions\n", counter);
                printf("\tAttribute name index: cp_info #%d\n",attributes[counter].attribute_name_index);
                printf("\tAttribute length: %d\n",attributes[counter].attribute_length);

                break;
            case 3:
                printf("------------------------------------------------\n");
                printf("[%d] InnerClasses\n", counter);
                printf("\tAttribute name index: cp_info #%d\n",attributes[counter].attribute_name_index);
                printf("\tAttribute length: %d\n",attributes[counter].attribute_length);

                break;
            case 4:
                printf("------------------------------------------------\n");
                printf("[%d] Synthetic\n", counter);
                printf("\tAttribute name index: cp_info #%d\n",attributes[counter].attribute_name_index);
                printf("\tAttribute length: %d\n",attributes[counter].attribute_length);
                break;
            case 5:
                printf("------------------------------------------------\n");
                printf("[%d] SourceFile\n",counter);
                printf("\tAttribute name index:\t cp_info #%d\n",attributes[counter].attribute_name_index);
                printf("\tAttribute length:\t %d\n",attributes[counter].attribute_length);
                printf("Info:\n");
                printf("\tSource File name index:\t cp_info #%d\t <%s>\n",attributes[counter].info.SourceFile_attribute.sourcefile_index, pool[attributes[counter].info.SourceFile_attribute.sourcefile_index -1].info.CONSTANT_Utf8_info.bytes);
                printf("------------------------------------------------\n");
                break;
            case 6:
                printf("------------------------------------------------\n");
                printf("[%d] LineNumberTable\n", counter);
                printf("\tAttribute name index: cp_info #%d\n",attributes[counter].attribute_name_index);
                printf("\tAttribute length: %d\n",attributes[counter].attribute_length);

                break;
            case 7:
                printf("------------------------------------------------\n");
                printf("[%d] LocalVariableTable\n", counter);
                printf("\tAttribute name index: cp_info #%d\n",attributes[counter].attribute_name_index);
                printf("\tAttribute length: %d\n",attributes[counter].attribute_length);

                break;
            case 8:
                printf("------------------------------------------------\n");
                printf("[%d] Deprecated\n", counter);
                printf("\tAttribute name index: cp_info #%d\n",attributes[counter].attribute_name_index);
                printf("\tAttribute length: %d\n",attributes[counter].attribute_length);

                
                break;
        }
        printf("\n\n");
        ++counter;
    }
}
コード例 #24
0
// Imprime os Metodos
void print_Methods(ClassFile *classFileVar, cp_info *pool) {
    
     printf("\n*****Methods*****\n\n");
    
    for (int i = 0; i < classFileVar->methods_count; i++) {
        char methodFlags[150] = "";
        printf("------------------------------------------------\n");
        printf("[%d] %s\n",i,pool[classFileVar->methods[i].name_index -1].info.CONSTANT_Utf8_info.bytes);
        printf("\tName:\t\t cp_info #%d\t <%s>\n",classFileVar->methods[i].name_index,pool[classFileVar->methods[i].name_index -1].info.CONSTANT_Utf8_info.bytes);
        
        
        if(classFileVar->methods[i].access_flags & ACC_PUBLIC) {
            //printf("public ");
            //strcat(methodFlags,"ACC_PUBLIC");
            strcat(methodFlags,"public");
        }
        if(classFileVar->methods[i].access_flags & ACC_PRIVATE) {
            //printf("private ");
            //if(methodFlags != "")
            if (!strcmp(methodFlags,"") == 0)
                strcat(methodFlags," ");
            //strcat(methodFlags,"ACC_PRIVATE");
            strcat(methodFlags,"private");
        }
        if(classFileVar->methods[i].access_flags & ACC_PROTECTED) {
            //printf("protected ");
            //if(methodFlags != "")
            if (!strcmp(methodFlags,"") == 0)
                strcat(methodFlags," ");
            //strcat(methodFlags,"ACC_PROTECTED");
            strcat(methodFlags,"protected");
        }
        if(classFileVar->methods[i].access_flags & ACC_STATIC) {
            //printf("static ");
            //if(methodFlags != "")
            if (!strcmp(methodFlags,"") == 0)
                strcat(methodFlags," ");
            //strcat(methodFlags,"ACC_STATIC");
            strcat(methodFlags,"static");
        }
        if(classFileVar->methods[i].access_flags & ACC_FINAL) {
            //printf("final ");
            //if(methodFlags != "")
            if (!strcmp(methodFlags,"") == 0)
                strcat(methodFlags," ");
            //strcat(methodFlags,"ACC_FINAL");
            strcat(methodFlags,"final");
        }
        if(classFileVar->methods[i].access_flags & ACC_SYNCHRONIZED) {
            //printf("synchronized ");
            //if(methodFlags != "")
            if (!strcmp(methodFlags,"") == 0)
                strcat(methodFlags," ");
            //strcat(methodFlags,"ACC_SYNCHRONIZED");
            strcat(methodFlags,"synchronized");
        }
        if(classFileVar->methods[i].access_flags & ACC_NATIVE) {
            //printf("native ");
            //if(methodFlags != "")
            if (!strcmp(methodFlags,"") == 0)
                strcat(methodFlags," ");
            //strcat(methodFlags,"ACC_NATIVE");
            strcat(methodFlags,"native");
        }
        if(classFileVar->methods[i].access_flags & ACC_ABSTRACT) {
            //printf("abstract ");
            //if(methodFlags != "")
            if (!strcmp(methodFlags,"") == 0)
                strcat(methodFlags," ");
            //strcat(methodFlags,"ACC_ABSTRACT");
            strcat(methodFlags,"abstract");
        }
        if(classFileVar->methods[i].access_flags & ACC_STRICT) {
            //printf("strict ");
            //if(methodFlags != "")
            if (!strcmp(methodFlags,"") == 0)
                strcat(methodFlags," ");
            //strcat(methodFlags,"ACC_STRICT");
            strcat(methodFlags,"strict");
        }
        /* TODO: fazer parse do descriptor para achar retorno e parametros
         B byte
         C char
         D double
         F float
         I int
         J long
         L<classname>; reference
         S short
         Z boolean
         [ reference
         */
        
        printf("\tDescriptor:\t cp_info #%d\t <%s>\n",classFileVar->methods[i].descriptor_index,pool[classFileVar->methods[i].descriptor_index -1].info.CONSTANT_Utf8_info.bytes);  //TODO: colocar funcao para recuperar valor da constant_pool
        printf("\tAccess flags:\t 0x%.4x\t\t [%s]\n",classFileVar->methods[i].access_flags,methodFlags);
        
        //printf("%d\n",classFileVar->methods[i].attribute[0].attribute_name_index);
        //getchar();
        //printf("%d\n",classFileVar->methods[i].attribute[0].info.Code_attribute.attribute[0].attribute_name_index);
        //getchar();
        print_attributes(classFileVar->methods[i].attribute, classFileVar->methods[i].attributes_count, pool);
        printf("------------------------------------------------\n");
    }
    printf("\n\n");
}
コード例 #25
0
ファイル: codadd-xmlschema.c プロジェクト: OkoSanto/coda
static void print_xml_element(FILE *f, coda_type *type)
{
    coda_type_class type_class;
    long num_record_fields;
    long i;

    coda_type_get_class(type, &type_class);
    assert(type_class == coda_record_class);

    fprintf(f, "<xs:complexType><xs:sequence>");
    coda_type_get_num_record_fields(type, &num_record_fields);
    for (i = 0; i < num_record_fields; i++)
    {
        coda_type_class field_type_class;
        coda_type *field_type;
        const char *real_name;
        coda_format format;

        coda_type_get_record_field_real_name(type, i, &real_name);
        coda_type_get_record_field_type(type, i, &field_type);
        coda_type_get_class(field_type, &field_type_class);
        coda_type_get_format(field_type, &format);
        fprintf(f, "<xs:element name=\"%s\"", real_name);
        if (field_type_class == coda_array_class && format == coda_format_xml)
        {
            fprintf(f, " minOccurs=\"0\" maxOccurs=\"unbounded\"");
            coda_type_get_array_base_type(field_type, &field_type);
            coda_type_get_class(field_type, &field_type_class);
            coda_type_get_format(field_type, &format);
        }
        if (field_type_class == coda_special_class)
        {
            coda_type_get_special_base_type(field_type, &field_type);
            coda_type_get_class(field_type, &field_type_class);
            coda_type_get_format(field_type, &format);
        }
        if (field_type_class == coda_record_class)
        {
            fprintf(f, ">");
            print_xml_element(f, field_type);
        }
        else
        {
            const char *xsdtype;
            int has_attributes;

            switch (field_type_class)
            {
                case coda_array_class:
                    assert(format != coda_format_xml);
                    xsdtype = "string";
                    break;
                case coda_integer_class:
                    xsdtype = "integer";
                    break;
                case coda_real_class:
                    xsdtype = "float";
                    break;
                case coda_text_class:
                    xsdtype = "string";
                    break;
                default:
                    assert(0);
                    exit(1);
            }
            coda_type_has_attributes(field_type, &has_attributes);
            if (has_attributes)
            {
                fprintf(f, ">");
                fprintf(f, "<xs:complexType>");
                fprintf(f, "<xs:simpleContent>");
                fprintf(f, "<xs:extension base=\"xs:%s\">", xsdtype);
                print_attributes(f, field_type);
                fprintf(f, "</xs:extension>");
                fprintf(f, "</xs:simpleContent>");
                fprintf(f, "</xs:complexType>");
            }
            else
            {
                fprintf(f, " type=\"xs:%s\">", xsdtype);
            }
        }
        fprintf(f, "</xs:element>");
    }
    fprintf(f, "</xs:sequence>");
    print_attributes(f, type);
    fprintf(f, "</xs:complexType>");
}
コード例 #26
0
int					/* O - Exit status */
main(int  argc,				/* I - Number of command-line arguments */
     char *argv[])			/* I - Command-line arguments */
{
  int		i;			/* Looping var */
  ipp_t		*msg;			/* Event message from scheduler */
  ipp_state_t	state;			/* IPP event state */
  char		*subject,		/* Subject for notification message */
		*text;			/* Text for notification message */
  cups_lang_t	*lang;			/* Language info */
  char		temp[1024];		/* Temporary string */
  int		templen;		/* Length of temporary string */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
  struct sigaction action;		/* POSIX sigaction data */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */


 /*
  * Don't buffer stderr...
  */

  setbuf(stderr, NULL);

 /*
  * Ignore SIGPIPE signals...
  */

#ifdef HAVE_SIGSET
  sigset(SIGPIPE, SIG_IGN);
#elif defined(HAVE_SIGACTION)
  memset(&action, 0, sizeof(action));
  action.sa_handler = SIG_IGN;
  sigaction(SIGPIPE, &action, NULL);
#else
  signal(SIGPIPE, SIG_IGN);
#endif /* HAVE_SIGSET */

 /*
  * Validate command-line options...
  */

  if (argc != 3)
  {
    fputs("Usage: mailto mailto:[email protected] notify-user-data\n", stderr);
    return (1);
  }

  if (strncmp(argv[1], "mailto:", 7))
  {
    fprintf(stderr, "ERROR: Bad recipient \"%s\"!\n", argv[1]);
    return (1);
  }

  fprintf(stderr, "DEBUG: argc=%d\n", argc);
  for (i = 0; i < argc; i ++)
    fprintf(stderr, "DEBUG: argv[%d]=\"%s\"\n", i, argv[i]);

 /*
  * Load configuration data...
  */

  if ((lang = cupsLangDefault()) == NULL)
    return (1);

  if (!load_configuration())
    return (1);

 /*
  * Get the reply-to address...
  */

  templen = sizeof(temp);
  httpDecode64_2(temp, &templen, argv[2]);

  if (!strncmp(temp, "mailto:", 7))
    strlcpy(mailtoReplyTo, temp + 7, sizeof(mailtoReplyTo));
  else if (temp[0])
    fprintf(stderr, "WARNING: Bad notify-user-data value (%d bytes) ignored!\n",
            templen);

 /*
  * Loop forever until we run out of events...
  */

  for (;;)
  {
   /*
    * Get the next event...
    */

    msg = ippNew();
    while ((state = ippReadFile(0, msg)) != IPP_DATA)
    {
      if (state <= IPP_IDLE)
        break;
    }

    fprintf(stderr, "DEBUG: state=%d\n", state);

    if (state == IPP_ERROR)
      fputs("DEBUG: ippReadFile() returned IPP_ERROR!\n", stderr);

    if (state <= IPP_IDLE)
    {
     /*
      * Out of messages, free memory and then exit...
      */

      ippDelete(msg);
      return (0);
    }

   /*
    * Get the subject and text for the message, then email it...
    */

    subject = cupsNotifySubject(lang, msg);
    text    = cupsNotifyText(lang, msg);

    fprintf(stderr, "DEBUG: subject=\"%s\"\n", subject);
    fprintf(stderr, "DEBUG: text=\"%s\"\n", text);

    if (subject && text)
      email_message(argv[1] + 7, subject, text);
    else
    {
      fputs("ERROR: Missing attributes in event notification!\n", stderr);
      print_attributes(msg, 4);
    }

   /*
    * Free the memory used for this event...
    */

    if (subject)
      free(subject);

    if (text)
      free(text);

    ippDelete(msg);
  }
}
コード例 #27
0
ファイル: cattributes.c プロジェクト: CansenJIANG/igraph
int main() {
  
  igraph_t g, g2;
  FILE *ifile;
  igraph_vector_t gtypes, vtypes, etypes;
  igraph_strvector_t gnames, vnames, enames;
  long int i;
  igraph_vector_t y;
  igraph_strvector_t id;
  char str[20];

  /* turn on attribute handling */
  igraph_i_set_attribute_table(&igraph_cattribute_table);
  
  ifile=fopen("LINKS.NET", "r");
  if (ifile==0) {
    return 10;
  }
  igraph_read_graph_pajek(&g, ifile);
  fclose(ifile);

  igraph_vector_init(&gtypes, 0);
  igraph_vector_init(&vtypes, 0);
  igraph_vector_init(&etypes, 0);
  igraph_strvector_init(&gnames, 0);
  igraph_strvector_init(&vnames, 0);
  igraph_strvector_init(&enames, 0);
  
  igraph_cattribute_list(&g, &gnames, &gtypes, &vnames, &vtypes, 
			 &enames, &etypes);
  
  /* List attribute names and types */
  printf("Graph attributes: ");
  for (i=0; i<igraph_strvector_size(&gnames); i++) {
    printf("%s (%i) ", STR(gnames, i), (int)VECTOR(gtypes)[i]);
  }
  printf("\n");
  printf("Vertex attributes: ");
  for (i=0; i<igraph_strvector_size(&vnames); i++) {
    printf("%s (%i) ", STR(vnames, i), (int)VECTOR(vtypes)[i]);
  }
  printf("\n");
  printf("Edge attributes: ");
  for (i=0; i<igraph_strvector_size(&enames); i++) {
    printf("%s (%i) ", STR(enames, i), (int)VECTOR(etypes)[i]);
  }
  printf("\n");

  print_attributes(&g);

  /* Copying a graph */
  igraph_copy(&g2, &g);
  print_attributes(&g2);
  igraph_destroy(&g2);
  
  /* Adding vertices */
  igraph_add_vertices(&g, 3, 0);
  print_attributes(&g);

  /* Adding edges */
  igraph_add_edge(&g, 1, 1);
  igraph_add_edge(&g, 2, 5);
  igraph_add_edge(&g, 3, 6);
  print_attributes(&g);

  /* Deleting vertices */
  igraph_delete_vertices(&g, igraph_vss_1(1));
  igraph_delete_vertices(&g, igraph_vss_1(4));
  print_attributes(&g);

  /* Deleting edges */
  igraph_delete_edges(&g, igraph_ess_1(igraph_ecount(&g)-1));
  igraph_delete_edges(&g, igraph_ess_1(0));
  print_attributes(&g);

  /* Set graph attributes */
  SETGAN(&g, "id", 10);
  if (GAN(&g, "id") != 10) {
    return 11;
  }
  SETGAS(&g, "name", "toy");
  if (strcmp(GAS(&g, "name"), "toy")) {
    return 12;
  }
  
  /* Delete graph attributes */
  DELGA(&g, "id");
  DELGA(&g, "name");
  igraph_cattribute_list(&g, &gnames, 0,0,0,0,0);
  if (igraph_strvector_size(&gnames) != 0) {
    return 14;
  }  

  /* Delete vertex attributes */
  DELVA(&g, "x");
  DELVA(&g, "shape");
  DELVA(&g, "xfact");
  DELVA(&g, "yfact");
  igraph_cattribute_list(&g, 0,0, &vnames, 0,0,0);  
  if (igraph_strvector_size(&vnames) != 2) {
    return 15;
  }
  
  /* Delete edge attributes */
  igraph_cattribute_list(&g, 0,0,0,0,&enames,0);
  i=igraph_strvector_size(&enames);
  DELEA(&g, "hook1");
  DELEA(&g, "hook2"); 
  DELEA(&g, "label");
  igraph_cattribute_list(&g, 0,0,0,0,&enames,0);
  if (igraph_strvector_size(&enames) != i-3) {
    return 16;
  }
  
  /* Set vertex attributes */
  SETVAN(&g, "y", 0, -1);
  SETVAN(&g, "y", 1, 2.1);
  if (VAN(&g, "y", 0) != -1 || 
      VAN(&g, "y", 1) != 2.1) {
    return 17;
  }
  SETVAS(&g, "id", 0, "foo");
  SETVAS(&g, "id", 1, "bar");
  if (strcmp(VAS(&g, "id", 0), "foo") ||
      strcmp(VAS(&g, "id", 1), "bar")) {
    return 18;
  }

  /* Set edge attributes */
  SETEAN(&g, "weight", 2, 100.0);
  SETEAN(&g, "weight", 0, -100.1);
  if (EAN(&g, "weight", 2) != 100.0 ||
      EAN(&g, "weight", 0) != -100.1) {
    return 19;
  }
  SETEAS(&g, "color", 2, "RED");
  SETEAS(&g, "color", 0, "Blue");
  if (strcmp(EAS(&g, "color", 2), "RED") ||
      strcmp(EAS(&g, "color", 0), "Blue")) {
    return 20;
  }      

  /* Set vector attributes as vector */
  igraph_vector_init(&y, igraph_vcount(&g));
  igraph_vector_fill(&y, 1.23);
  SETVANV(&g, "y", &y);
  igraph_vector_destroy(&y);
  for (i=0; i<igraph_vcount(&g); i++) {    
    if (VAN(&g, "y", i) != 1.23) {
      return 21;
    }
  }
  igraph_vector_init_seq(&y, 0, igraph_vcount(&g)-1);
  SETVANV(&g, "foobar", &y);
  igraph_vector_destroy(&y);
  for (i=0; i<igraph_vcount(&g); i++) {
    if (VAN(&g, "foobar", i) != i) {
      return 22;
    }
  }  
  
  igraph_strvector_init(&id, igraph_vcount(&g));
  for (i=0; i<igraph_vcount(&g); i++) {
    snprintf(str, sizeof(str)-1, "%li", i);
    igraph_strvector_set(&id, i, str);
  }
  SETVASV(&g, "foo", &id);
  igraph_strvector_destroy(&id);
  for (i=0; i<igraph_vcount(&g); i++) {
    printf("%s ", VAS(&g, "foo", i));
  }
  printf("\n");
  igraph_strvector_init(&id, igraph_vcount(&g));
  for (i=0; i<igraph_vcount(&g); i++) {
    snprintf(str, sizeof(str)-1, "%li", i);
    igraph_strvector_set(&id, i, str);
  }
  SETVASV(&g, "id", &id);
  igraph_strvector_destroy(&id);
  for (i=0; i<igraph_vcount(&g); i++) {
    printf("%s ", VAS(&g, "id", i));
  }
  printf("\n");  
  
  /* Set edge attributes as vector */
  igraph_vector_init(&y, igraph_ecount(&g));
  igraph_vector_fill(&y, 12.3);
  SETEANV(&g, "weight", &y);
  igraph_vector_destroy(&y);
  for (i=0; i<igraph_ecount(&g); i++) {    
    if (EAN(&g, "weight", i) != 12.3) {
      return 23;
    }
  }
  igraph_vector_init_seq(&y, 0, igraph_ecount(&g)-1);
  SETEANV(&g, "foobar", &y);
  igraph_vector_destroy(&y);
  for (i=0; i<igraph_ecount(&g); i++) {
    if (VAN(&g, "foobar", i) != i) {
      return 24;
    }
  }  
  
  igraph_strvector_init(&id, igraph_ecount(&g));
  for (i=0; i<igraph_ecount(&g); i++) {
    snprintf(str, sizeof(str)-1, "%li", i);
    igraph_strvector_set(&id, i, str);
  }
  SETEASV(&g, "foo", &id);
  igraph_strvector_destroy(&id);
  for (i=0; i<igraph_ecount(&g); i++) {
    printf("%s ", EAS(&g, "foo", i));
  }
  printf("\n");
  igraph_strvector_init(&id, igraph_ecount(&g));
  for (i=0; i<igraph_ecount(&g); i++) {
    snprintf(str, sizeof(str)-1, "%li", i);
    igraph_strvector_set(&id, i, str);
  }
  SETEASV(&g, "color", &id);
  igraph_strvector_destroy(&id);
  for (i=0; i<igraph_ecount(&g); i++) {
    printf("%s ", EAS(&g, "color", i));
  }
  printf("\n");    

  /* Delete all remaining attributes */
  DELALL(&g);
  igraph_cattribute_list(&g, &gnames, &gtypes, &vnames, &vtypes, &enames, &etypes);
  if (igraph_strvector_size(&gnames) != 0 ||
      igraph_strvector_size(&vnames) != 0 ||
      igraph_strvector_size(&enames) != 0) {
    return 25;
  }

  /* Destroy */
  igraph_vector_destroy(&gtypes);
  igraph_vector_destroy(&vtypes);
  igraph_vector_destroy(&etypes);  
  igraph_strvector_destroy(&gnames);
  igraph_strvector_destroy(&vnames);
  igraph_strvector_destroy(&enames);

  igraph_destroy(&g);

  return 0;
}
コード例 #28
0
ファイル: testipp.c プロジェクト: lanceit/cups
void
print_attributes(ipp_t *ipp,		/* I - IPP request */
                 int   indent)		/* I - Indentation */
{
  int			i;		/* Looping var */
  ipp_tag_t		group;		/* Current group */
  ipp_attribute_t	*attr;		/* Current attribute */
  _ipp_value_t		*val;		/* Current value */
  static const char * const tags[] =	/* Value/group tag strings */
			{
			  "reserved-00",
			  "operation-attributes-tag",
			  "job-attributes-tag",
			  "end-of-attributes-tag",
			  "printer-attributes-tag",
			  "unsupported-attributes-tag",
			  "subscription-attributes-tag",
			  "event-attributes-tag",
			  "reserved-08",
			  "reserved-09",
			  "reserved-0A",
			  "reserved-0B",
			  "reserved-0C",
			  "reserved-0D",
			  "reserved-0E",
			  "reserved-0F",
			  "unsupported",
			  "default",
			  "unknown",
			  "no-value",
			  "reserved-14",
			  "not-settable",
			  "delete-attr",
			  "admin-define",
			  "reserved-18",
			  "reserved-19",
			  "reserved-1A",
			  "reserved-1B",
			  "reserved-1C",
			  "reserved-1D",
			  "reserved-1E",
			  "reserved-1F",
			  "reserved-20",
			  "integer",
			  "boolean",
			  "enum",
			  "reserved-24",
			  "reserved-25",
			  "reserved-26",
			  "reserved-27",
			  "reserved-28",
			  "reserved-29",
			  "reserved-2a",
			  "reserved-2b",
			  "reserved-2c",
			  "reserved-2d",
			  "reserved-2e",
			  "reserved-2f",
			  "octetString",
			  "dateTime",
			  "resolution",
			  "rangeOfInteger",
			  "begCollection",
			  "textWithLanguage",
			  "nameWithLanguage",
			  "endCollection",
			  "reserved-38",
			  "reserved-39",
			  "reserved-3a",
			  "reserved-3b",
			  "reserved-3c",
			  "reserved-3d",
			  "reserved-3e",
			  "reserved-3f",
			  "reserved-40",
			  "textWithoutLanguage",
			  "nameWithoutLanguage",
			  "reserved-43",
			  "keyword",
			  "uri",
			  "uriScheme",
			  "charset",
			  "naturalLanguage",
			  "mimeMediaType",
			  "memberName"
			};


  for (group = IPP_TAG_ZERO, attr = ipp->attrs; attr; attr = attr->next)
  {
    if (!attr->name && indent == 4)
    {
      group = IPP_TAG_ZERO;
      putchar('\n');
      continue;
    }

    if (group != attr->group_tag)
    {
      group = attr->group_tag;

      printf("\n%*s%s:\n\n", indent - 4, "", tags[group]);
    }

    printf("%*s%s (", indent, "", attr->name ? attr->name : "(null)");
    if (attr->num_values > 1)
      printf("1setOf ");
    printf("%s):", tags[attr->value_tag]);

    switch (attr->value_tag)
    {
      case IPP_TAG_ENUM :
      case IPP_TAG_INTEGER :
          for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
	    printf(" %d", val->integer);
          putchar('\n');
          break;

      case IPP_TAG_BOOLEAN :
          for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
	    printf(" %s", val->boolean ? "true" : "false");
          putchar('\n');
          break;

      case IPP_TAG_RANGE :
          for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
	    printf(" %d-%d", val->range.lower, val->range.upper);
          putchar('\n');
          break;

      case IPP_TAG_DATE :
          {
	    char	vstring[256];	/* Formatted time */

	    for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
	      printf(" (%s)", _cupsStrDate(vstring, sizeof(vstring), ippDateToTime(val->date)));
          }
          putchar('\n');
          break;

      case IPP_TAG_RESOLUTION :
          for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
	    printf(" %dx%d%s", val->resolution.xres, val->resolution.yres,
	           val->resolution.units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
          putchar('\n');
          break;

      case IPP_TAG_STRING :
      case IPP_TAG_TEXTLANG :
      case IPP_TAG_NAMELANG :
      case IPP_TAG_TEXT :
      case IPP_TAG_NAME :
      case IPP_TAG_KEYWORD :
      case IPP_TAG_URI :
      case IPP_TAG_URISCHEME :
      case IPP_TAG_CHARSET :
      case IPP_TAG_LANGUAGE :
      case IPP_TAG_MIMETYPE :
          for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
	    printf(" \"%s\"", val->string.text);
          putchar('\n');
          break;

      case IPP_TAG_BEGIN_COLLECTION :
          putchar('\n');

          for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
	  {
	    if (i)
	      putchar('\n');
	    print_attributes(val->collection, indent + 4);
	  }
          break;

      default :
          printf("UNKNOWN (%d values)\n", attr->num_values);
          break;
    }
  }
}
コード例 #29
0
ファイル: testipp.c プロジェクト: lanceit/cups
int				/* O - Exit status */
main(int  argc,			/* I - Number of command-line arguments */
     char *argv[])		/* I - Command-line arguments */
{
  _ippdata_t	data;		/* IPP buffer */
  ipp_uchar_t	buffer[8192];	/* Write buffer data */
  ipp_t		*cols[2],	/* Collections */
		*size;		/* media-size collection */
  ipp_t		*request;	/* Request */
  ipp_attribute_t *media_col,	/* media-col attribute */
		*media_size,	/* media-size attribute */
		*attr;		/* Other attribute */
  ipp_state_t	state;		/* State */
  size_t	length;		/* Length of data */
  cups_file_t	*fp;		/* File pointer */
  size_t	i;		/* Looping var */
  int		status;		/* Status of tests (0 = success, 1 = fail) */
#ifdef DEBUG
  const char	*name;		/* Option name */
#endif /* DEBUG */


  status = 0;

  if (argc == 1)
  {
   /*
    * Test request generation code...
    */

    printf("Create Sample Request: ");

    request = ippNew();
    request->request.op.version[0]   = 0x01;
    request->request.op.version[1]   = 0x01;
    request->request.op.operation_id = IPP_OP_PRINT_JOB;
    request->request.op.request_id   = 1;

    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
        	 "attributes-charset", NULL, "utf-8");
    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
        	 "attributes-natural-language", NULL, "en");
    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
        	 "printer-uri", NULL, "ipp://localhost/printers/foo");

    cols[0] = ippNew();
    size    = ippNew();
    ippAddInteger(size, IPP_TAG_ZERO, IPP_TAG_INTEGER, "x-dimension", 21590);
    ippAddInteger(size, IPP_TAG_ZERO, IPP_TAG_INTEGER, "y-dimension", 27940);
    ippAddCollection(cols[0], IPP_TAG_JOB, "media-size", size);
    ippDelete(size);
    ippAddString(cols[0], IPP_TAG_JOB, IPP_TAG_KEYWORD, "media-color", NULL,
                 "blue");
    ippAddString(cols[0], IPP_TAG_JOB, IPP_TAG_KEYWORD, "media-type", NULL,
                 "plain");

    cols[1] = ippNew();
    size    = ippNew();
    ippAddInteger(size, IPP_TAG_ZERO, IPP_TAG_INTEGER, "x-dimension", 21000);
    ippAddInteger(size, IPP_TAG_ZERO, IPP_TAG_INTEGER, "y-dimension", 29700);
    ippAddCollection(cols[1], IPP_TAG_JOB, "media-size", size);
    ippDelete(size);
    ippAddString(cols[1], IPP_TAG_JOB, IPP_TAG_KEYWORD, "media-color", NULL,
                 "plaid");
    ippAddString(cols[1], IPP_TAG_JOB, IPP_TAG_KEYWORD, "media-type", NULL,
		 "glossy");

    ippAddCollections(request, IPP_TAG_JOB, "media-col", 2,
                      (const ipp_t **)cols);
    ippDelete(cols[0]);
    ippDelete(cols[1]);

    length = ippLength(request);
    if (length != sizeof(collection))
    {
      printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
             (int)length, (int)sizeof(collection));
      status = 1;
    }
    else
      puts("PASS");

   /*
    * Write test #1...
    */

    printf("Write Sample to Memory: ");

    data.wused   = 0;
    data.wsize   = sizeof(buffer);
    data.wbuffer = buffer;

    while ((state = ippWriteIO(&data, (ipp_iocb_t)write_cb, 1, NULL,
                               request)) != IPP_STATE_DATA)
      if (state == IPP_STATE_ERROR)
	break;

    if (state != IPP_STATE_DATA)
    {
      printf("FAIL - %d bytes written.\n", (int)data.wused);
      status = 1;
    }
    else if (data.wused != sizeof(collection))
    {
      printf("FAIL - wrote %d bytes, expected %d bytes!\n", (int)data.wused,
             (int)sizeof(collection));
      hex_dump("Bytes Written", data.wbuffer, data.wused);
      hex_dump("Baseline", collection, sizeof(collection));
      status = 1;
    }
    else if (memcmp(data.wbuffer, collection, data.wused))
    {
      for (i = 0; i < data.wused; i ++)
        if (data.wbuffer[i] != collection[i])
	  break;

      printf("FAIL - output does not match baseline at 0x%04x!\n", (unsigned)i);
      hex_dump("Bytes Written", data.wbuffer, data.wused);
      hex_dump("Baseline", collection, sizeof(collection));
      status = 1;
    }
    else
      puts("PASS");

    ippDelete(request);

   /*
    * Read the data back in and confirm...
    */

    printf("Read Sample from Memory: ");

    request     = ippNew();
    data.rpos = 0;

    while ((state = ippReadIO(&data, (ipp_iocb_t)read_cb, 1, NULL,
                              request)) != IPP_STATE_DATA)
      if (state == IPP_STATE_ERROR)
	break;

    length = ippLength(request);

    if (state != IPP_STATE_DATA)
    {
      printf("FAIL - %d bytes read.\n", (int)data.rpos);
      status = 1;
    }
    else if (data.rpos != data.wused)
    {
      printf("FAIL - read %d bytes, expected %d bytes!\n", (int)data.rpos,
             (int)data.wused);
      print_attributes(request, 8);
      status = 1;
    }
    else if (length != sizeof(collection))
    {
      printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
             (int)length, (int)sizeof(collection));
      print_attributes(request, 8);
      status = 1;
    }
    else
      puts("PASS");

    fputs("ippFindAttribute(media-col): ", stdout);
    if ((media_col = ippFindAttribute(request, "media-col",
                                      IPP_TAG_BEGIN_COLLECTION)) == NULL)
    {
      if ((media_col = ippFindAttribute(request, "media-col",
                                        IPP_TAG_ZERO)) == NULL)
        puts("FAIL (not found)");
      else
        printf("FAIL (wrong type - %s)\n", ippTagString(media_col->value_tag));

      status = 1;
    }
    else if (media_col->num_values != 2)
    {
      printf("FAIL (wrong count - %d)\n", media_col->num_values);
      status = 1;
    }
    else
      puts("PASS");

    if (media_col)
    {
      fputs("ippFindAttribute(media-size 1): ", stdout);
      if ((media_size = ippFindAttribute(media_col->values[0].collection,
					 "media-size",
					 IPP_TAG_BEGIN_COLLECTION)) == NULL)
      {
	if ((media_size = ippFindAttribute(media_col->values[0].collection,
					   "media-col",
					   IPP_TAG_ZERO)) == NULL)
	  puts("FAIL (not found)");
	else
	  printf("FAIL (wrong type - %s)\n",
	         ippTagString(media_size->value_tag));

	status = 1;
      }
      else
      {
	if ((attr = ippFindAttribute(media_size->values[0].collection,
				     "x-dimension", IPP_TAG_INTEGER)) == NULL)
	{
	  if ((attr = ippFindAttribute(media_size->values[0].collection,
				       "x-dimension", IPP_TAG_ZERO)) == NULL)
	    puts("FAIL (missing x-dimension)");
	  else
	    printf("FAIL (wrong type for x-dimension - %s)\n",
		   ippTagString(attr->value_tag));

	  status = 1;
	}
	else if (attr->values[0].integer != 21590)
	{
	  printf("FAIL (wrong value for x-dimension - %d)\n",
		 attr->values[0].integer);
	  status = 1;
	}
	else if ((attr = ippFindAttribute(media_size->values[0].collection,
					  "y-dimension",
					  IPP_TAG_INTEGER)) == NULL)
	{
	  if ((attr = ippFindAttribute(media_size->values[0].collection,
				       "y-dimension", IPP_TAG_ZERO)) == NULL)
	    puts("FAIL (missing y-dimension)");
	  else
	    printf("FAIL (wrong type for y-dimension - %s)\n",
		   ippTagString(attr->value_tag));

	  status = 1;
	}
	else if (attr->values[0].integer != 27940)
	{
	  printf("FAIL (wrong value for y-dimension - %d)\n",
		 attr->values[0].integer);
	  status = 1;
	}
	else
	  puts("PASS");
      }

      fputs("ippFindAttribute(media-size 2): ", stdout);
      if ((media_size = ippFindAttribute(media_col->values[1].collection,
					 "media-size",
					 IPP_TAG_BEGIN_COLLECTION)) == NULL)
      {
	if ((media_size = ippFindAttribute(media_col->values[1].collection,
					   "media-col",
					   IPP_TAG_ZERO)) == NULL)
	  puts("FAIL (not found)");
	else
	  printf("FAIL (wrong type - %s)\n",
	         ippTagString(media_size->value_tag));

	status = 1;
      }
      else
      {
	if ((attr = ippFindAttribute(media_size->values[0].collection,
				     "x-dimension",
				     IPP_TAG_INTEGER)) == NULL)
	{
	  if ((attr = ippFindAttribute(media_size->values[0].collection,
				       "x-dimension", IPP_TAG_ZERO)) == NULL)
	    puts("FAIL (missing x-dimension)");
	  else
	    printf("FAIL (wrong type for x-dimension - %s)\n",
		   ippTagString(attr->value_tag));

	  status = 1;
	}
	else if (attr->values[0].integer != 21000)
	{
	  printf("FAIL (wrong value for x-dimension - %d)\n",
		 attr->values[0].integer);
	  status = 1;
	}
	else if ((attr = ippFindAttribute(media_size->values[0].collection,
					  "y-dimension",
					  IPP_TAG_INTEGER)) == NULL)
	{
	  if ((attr = ippFindAttribute(media_size->values[0].collection,
				       "y-dimension", IPP_TAG_ZERO)) == NULL)
	    puts("FAIL (missing y-dimension)");
	  else
	    printf("FAIL (wrong type for y-dimension - %s)\n",
		   ippTagString(attr->value_tag));

	  status = 1;
	}
	else if (attr->values[0].integer != 29700)
	{
	  printf("FAIL (wrong value for y-dimension - %d)\n",
		 attr->values[0].integer);
	  status = 1;
	}
	else
	  puts("PASS");
      }
    }

   /*
    * Test hierarchical find...
    */

    fputs("ippFindAttribute(media-col/media-size/x-dimension): ", stdout);
    if ((attr = ippFindAttribute(request, "media-col/media-size/x-dimension", IPP_TAG_INTEGER)) != NULL)
    {
      if (ippGetInteger(attr, 0) != 21590)
      {
        printf("FAIL (wrong value for x-dimension - %d)\n", ippGetInteger(attr, 0));
        status = 1;
      }
      else
        puts("PASS");
    }
    else
    {
      puts("FAIL (not found)");
      status = 1;
    }

    fputs("ippFindNextAttribute(media-col/media-size/x-dimension): ", stdout);
    if ((attr = ippFindNextAttribute(request, "media-col/media-size/x-dimension", IPP_TAG_INTEGER)) != NULL)
    {
      if (ippGetInteger(attr, 0) != 21000)
      {
        printf("FAIL (wrong value for x-dimension - %d)\n", ippGetInteger(attr, 0));
        status = 1;
      }
      else
        puts("PASS");
    }
    else
    {
      puts("FAIL (not found)");
      status = 1;
    }

    fputs("ippFindNextAttribute(media-col/media-size/x-dimension) again: ", stdout);
    if ((attr = ippFindNextAttribute(request, "media-col/media-size/x-dimension", IPP_TAG_INTEGER)) != NULL)
    {
      printf("FAIL (got %d, expected nothing)\n", ippGetInteger(attr, 0));
      status = 1;
    }
    else
      puts("PASS");

    ippDelete(request);

   /*
    * Read the mixed data and confirm we converted everything to rangeOfInteger
    * values...
    */

    printf("Read Mixed integer/rangeOfInteger from Memory: ");

    request = ippNew();
    data.rpos    = 0;
    data.wused   = sizeof(mixed);
    data.wsize   = sizeof(mixed);
    data.wbuffer = mixed;

    while ((state = ippReadIO(&data, (ipp_iocb_t)read_cb, 1, NULL,
                              request)) != IPP_STATE_DATA)
      if (state == IPP_STATE_ERROR)
	break;

    length = ippLength(request);

    if (state != IPP_STATE_DATA)
    {
      printf("FAIL - %d bytes read.\n", (int)data.rpos);
      status = 1;
    }
    else if (data.rpos != sizeof(mixed))
    {
      printf("FAIL - read %d bytes, expected %d bytes!\n", (int)data.rpos,
             (int)sizeof(mixed));
      print_attributes(request, 8);
      status = 1;
    }
    else if (length != (sizeof(mixed) + 4))
    {
      printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
             (int)length, (int)sizeof(mixed) + 4);
      print_attributes(request, 8);
      status = 1;
    }
    else
      puts("PASS");

    fputs("ippFindAttribute(notify-lease-duration-supported): ", stdout);
    if ((attr = ippFindAttribute(request, "notify-lease-duration-supported",
                                 IPP_TAG_ZERO)) == NULL)
    {
      puts("FAIL (not found)");
      status = 1;
    }
    else if (attr->value_tag != IPP_TAG_RANGE)
    {
      printf("FAIL (wrong type - %s)\n", ippTagString(attr->value_tag));
      status = 1;
    }
    else if (attr->num_values != 2)
    {
      printf("FAIL (wrong count - %d)\n", attr->num_values);
      status = 1;
    }
    else if (attr->values[0].range.lower != 1 ||
             attr->values[0].range.upper != 1 ||
             attr->values[1].range.lower != 16 ||
             attr->values[1].range.upper != 32)
    {
      printf("FAIL (wrong values - %d,%d and %d,%d)\n",
             attr->values[0].range.lower,
             attr->values[0].range.upper,
             attr->values[1].range.lower,
             attr->values[1].range.upper);
      status = 1;
    }
    else
      puts("PASS");

    ippDelete(request);

#ifdef DEBUG
   /*
    * Test that private option array is sorted...
    */

    fputs("_ippCheckOptions: ", stdout);
    if ((name = _ippCheckOptions()) == NULL)
      puts("PASS");
    else
    {
      printf("FAIL (\"%s\" out of order)\n", name);
      status = 1;
    }
#endif /* DEBUG */

   /*
    * Test _ippFindOption() private API...
    */

    fputs("_ippFindOption(\"printer-type\"): ", stdout);
    if (_ippFindOption("printer-type"))
      puts("PASS");
    else
    {
      puts("FAIL");
      status = 1;
    }

   /*
    * Summarize...
    */

    putchar('\n');

    if (status)
      puts("Core IPP tests failed.");
    else
      puts("Core IPP tests passed.");
  }
  else
  {
   /*
    * Read IPP files...
    */

    for (i = 1; i < (size_t)argc; i ++)
    {
      if ((fp = cupsFileOpen(argv[i], "r")) == NULL)
      {
	printf("Unable to open \"%s\" - %s\n", argv[i], strerror(errno));
	status = 1;
	continue;
      }

      request = ippNew();
      while ((state = ippReadIO(fp, (ipp_iocb_t)cupsFileRead, 1, NULL,
                                request)) == IPP_STATE_ATTRIBUTE);

      if (state != IPP_STATE_DATA)
      {
	printf("Error reading IPP message from \"%s\"!\n", argv[i]);
	status = 1;
      }
      else
      {
	printf("\n%s:\n", argv[i]);
	print_attributes(request, 4);
      }

      ippDelete(request);
      cupsFileClose(fp);
    }
  }

  return (status);
}
コード例 #30
0
int
main(int  argc,				/* I - Number of command-line arguments */
     char *argv[])			/* I - Command-line arguments */
{
  int		i;			/* Looping var */
  const char	*uri;			/* URI to use */
  int		num_events;		/* Number of events */
  const char	*events[100];		/* Events */
  int		subscription_id,	/* notify-subscription-id */
		sequence_number,	/* notify-sequence-number */
		interval;		/* Interval between polls */
  http_t	*http;			/* HTTP connection */
  ipp_t		*request,		/* IPP request */
		*response;		/* IPP response */
  ipp_attribute_t *attr;		/* Current attribute */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
  struct sigaction action;		/* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */


 /*
  * Parse command-line...
  */

  num_events = 0;
  uri        = NULL;

  for (i = 1; i < argc; i ++)
    if (!strcmp(argv[i], "-E"))
      cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
    else if (!strcmp(argv[i], "-e"))
    {
      i ++;
      if (i >= argc || num_events >= 100)
        usage();

      events[num_events] = argv[i];
      num_events ++;
    }
    else if (!strcmp(argv[i], "-h"))
    {
      i ++;
      if (i >= argc)
        usage();

      cupsSetServer(argv[i]);
    }
    else if (uri || strncmp(argv[i], "ipp://", 6))
      usage();
    else
      uri = argv[i];

  if (!uri)
    usage();

  if (num_events == 0)
  {
    events[0]  = "all";
    num_events = 1;
  }

 /*
  * Connect to the server...
  */

  if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
                                 cupsEncryption())) == NULL)
  {
    perror(cupsServer());
    return (1);
  }

 /*
  * Catch CTRL-C and SIGTERM...
  */

#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
  sigset(SIGINT, sigterm_handler);
  sigset(SIGTERM, sigterm_handler);
#elif defined(HAVE_SIGACTION)
  memset(&action, 0, sizeof(action));

  sigemptyset(&action.sa_mask);
  action.sa_handler = sigterm_handler;
  sigaction(SIGINT, &action, NULL);
  sigaction(SIGTERM, &action, NULL);
#else
  signal(SIGINT, sigterm_handler);
  signal(SIGTERM, sigterm_handler);
#endif /* HAVE_SIGSET */

 /*
  * Create the subscription...
  */

  if (strstr(uri, "/jobs/"))
  {
    request = ippNewRequest(IPP_CREATE_JOB_SUBSCRIPTION);
    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
  }
  else
  {
    request = ippNewRequest(IPP_CREATE_PRINTER_SUBSCRIPTION);
    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
                 uri);
  }

  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
               NULL, cupsUser());

  ippAddStrings(request, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD, "notify-events",
                num_events, NULL, events);
  ippAddString(request, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
               "notify-pull-method", NULL, "ippget");

  response = cupsDoRequest(http, request, uri);
  if (cupsLastError() >= IPP_BAD_REQUEST)
  {
    fprintf(stderr, "Create-%s-Subscription: %s\n",
            strstr(uri, "/jobs") ? "Job" : "Printer", cupsLastErrorString());
    ippDelete(response);
    httpClose(http);
    return (1);
  }

  if ((attr = ippFindAttribute(response, "notify-subscription-id",
                               IPP_TAG_INTEGER)) == NULL)
  {
    fputs("ERROR: No notify-subscription-id in response!\n", stderr);
    ippDelete(response);
    httpClose(http);
    return (1);
  }

  subscription_id = attr->values[0].integer;

  printf("Create-%s-Subscription: notify-subscription-id=%d\n",
         strstr(uri, "/jobs/") ? "Job" : "Printer", subscription_id);

  ippDelete(response);

 /*
  * Monitor for events...
  */

  sequence_number = 0;

  while (!terminate)
  {
   /*
    * Get the current events...
    */

    printf("\nGet-Notifications(%d,%d):", subscription_id, sequence_number);
    fflush(stdout);

    request = ippNewRequest(IPP_GET_NOTIFICATIONS);

    if (strstr(uri, "/jobs/"))
      ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
    else
      ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
                   uri);

    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
                 "requesting-user-name", NULL, cupsUser());

    ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
                  "notify-subscription-ids", subscription_id);
    if (sequence_number)
      ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
                    "notify-sequence-numbers", sequence_number + 1);

    response = cupsDoRequest(http, request, uri);

    printf(" %s\n", ippErrorString(cupsLastError()));

    if (cupsLastError() >= IPP_BAD_REQUEST)
      fprintf(stderr, "Get-Notifications: %s\n", cupsLastErrorString());
    else if (response)
    {
      print_attributes(response, 0);

      for (attr = ippFindAttribute(response, "notify-sequence-number",
                                   IPP_TAG_INTEGER);
           attr;
	   attr = ippFindNextAttribute(response, "notify-sequence-number",
	                               IPP_TAG_INTEGER))
        if (attr->values[0].integer > sequence_number)
	  sequence_number = attr->values[0].integer;
    }

    if ((attr = ippFindAttribute(response, "notify-get-interval",
                                 IPP_TAG_INTEGER)) != NULL &&
        attr->values[0].integer > 0)
      interval = attr->values[0].integer;
    else
      interval = 5;

    ippDelete(response);
    sleep(interval);
  }

 /*
  * Cancel the subscription...
  */

  printf("\nCancel-Subscription:");
  fflush(stdout);

  request = ippNewRequest(IPP_CANCEL_SUBSCRIPTION);

  if (strstr(uri, "/jobs/"))
    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
  else
    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
                 uri);

  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
               NULL, cupsUser());

  ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
                "notify-subscription-id", subscription_id);

  ippDelete(cupsDoRequest(http, request, uri));

  printf(" %s\n", ippErrorString(cupsLastError()));

  if (cupsLastError() >= IPP_BAD_REQUEST)
    fprintf(stderr, "Cancel-Subscription: %s\n", cupsLastErrorString());

 /*
  * Close the connection and return...
  */

  httpClose(http);

  return (0);
}