コード例 #1
0
int accept_tcmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{
	FILE *fp = (FILE*)arg;

	if (n->nlmsg_type == RTM_NEWTFILTER || n->nlmsg_type == RTM_DELTFILTER) {
		print_filter(who, n, arg);
		return 0;
	}
	if (n->nlmsg_type == RTM_NEWTCLASS || n->nlmsg_type == RTM_DELTCLASS) {
		print_class(who, n, arg);
		return 0;
	}
	if (n->nlmsg_type == RTM_NEWQDISC || n->nlmsg_type == RTM_DELQDISC) {
		print_qdisc(who, n, arg);
		return 0;
	}
	if (n->nlmsg_type == RTM_GETACTION || n->nlmsg_type == RTM_NEWACTION ||
	    n->nlmsg_type == RTM_DELACTION) {
		print_action(who, n, arg);
		return 0;
	}
	if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP &&
	    n->nlmsg_type != NLMSG_DONE) {
		fprintf(fp, "Unknown message: length %08d type %08x flags %08x\n",
			n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
	}
	return 0;
}
コード例 #2
0
ファイル: debug-print.c プロジェクト: h2oota/opendylan
void print_object (STREAM stream, D instance, BOOL escape_p, int print_depth) {
  enum dylan_type_enum type = dylan_type(instance);
  switch (type) {
    case integer_type:
      print_integer(stream, instance, escape_p, print_depth); break;
    case character_type:
      print_character(stream, instance, escape_p, print_depth); break;
    case float_type:
      print_float (stream, instance, escape_p, print_depth); break;
    case dylan_boolean_type:
      print_boolean(stream, instance, escape_p, print_depth); break;
    case string_type:
      print_string (stream, instance, escape_p, print_depth); break;
    case vector_type:
      print_vector(stream, instance, escape_p, print_depth); break;
    case pair_type:
      print_pair(stream, instance, escape_p, print_depth); break;
    case empty_list_type:
      print_empty_list(stream, instance, escape_p, print_depth); break;
    case symbol_type:
      print_symbol(stream, instance, escape_p, print_depth); break;
    case simple_condition_type:
      print_simple_condition(stream, instance, escape_p, print_depth); break;
    case class_type:
      print_class(stream, instance, escape_p, print_depth); break;
    case function_type:
      print_function(stream, instance, escape_p, print_depth); break;
    case unknown_type:
      format(stream, "?%lx", instance); break;
    default:
      print_user_defined(stream, instance, escape_p, print_depth); break;
  }
}
コード例 #3
0
void print_modhelp_tree(pntree *ctree){
	if(ctree->left != NULL){
		print_modhelp_tree(ctree->left);
		free(ctree->left);
		ctree->left = 0;
	}
	print_class(ctree->oclass);
	if(ctree->right != NULL){
		print_modhelp_tree(ctree->right);
		free(ctree->right);
		ctree->right = 0;
	}
}
コード例 #4
0
void print_egraph_root_classes(FILE *f, egraph_t *egraph) {
  uint32_t i, n;
  int_hset_t roots;

  init_int_hset(&roots, 0);
  collect_root_classes(egraph, &roots);

  n = roots.nelems;
  for (i=0; i<n; i++) {
    print_class(f, egraph, roots.data[i]);
  }

  delete_int_hset(&roots);
}
コード例 #5
0
ファイル: backend_print.c プロジェクト: buccella/mofc
static void print_class(FILE * f,class_entry * ce)
{
  /* postfix processing - recursive */
  if ( ce -> class_parent) {
    print_class( f, ce -> class_parent); 
  }	
  fprintf(f,"Class %s ",ce -> class_id);
  print_class_attrs(f,ce);
  print_parent_chain(f,ce);
  fprintf(f,"{\n");
  print_qualifier_chain(f,ce -> class_quals);
  print_property_chain(f,ce -> class_props);
  print_method_chain(f,ce -> class_methods);
  fprintf(f,"}\n");
}
コード例 #6
0
static void print_infered_classes(test_bench_t *bench) {
  ipart_t partition;
  int32_t *v;
  uint32_t i, n;

  init_int_partition(&partition, 0, &bench->equeue, prop_hash_var, prop_same_class);
  collect_propagated_classes(&bench->equeue, &partition);

  n = int_partition_nclasses(&partition);
  for (i=0; i<n; i++) {
    v = partition.classes[i];
    printf("  class[%"PRIu32"]: ", i);
    print_class(v);
    printf("\n");
  }
  printf("\n");

  delete_int_partition(&partition);
}
コード例 #7
0
/*
 print_header
     Descr: Affiche à l'ecran la structure header initialisée par read_header
     Param:
         - header: Structure Ehdr correspondant au ELF header à afficher
 */
void print_header(Elf32_Ehdr header)
{
    print_e_ident(header);                   // Magic
    print_class(header);                     // Class
    print_data(header);                      // Data
    print_version(header);                   // Version
    print_os_abi(header);                    // OS_ABI
    print_abi_version(header);               // ABI version
    print_type(header);                      // Type
    print_machine(header);                   // Machine
    print_e_version(header);                 // Version
    print_entry(header);                     // Entry
    print_start_prog_headers(header);        // Start of program headers
    print_start_section_headers(header);     // Start of section headers
    print_flags(header);                     // Flags
    print_header_size(header);               // Header size
    print_program_headers_size(header);      // Program headers size
    print_program_headers_number(header);    // Program headers number
    print_section_headers_size(header);      // Section headers size
    print_section_headers_number(header);    // Section headers number
    print_section_header_strtab_ndx(header); // Section header string table index
}
コード例 #8
0
ファイル: backend_print.c プロジェクト: buccella/mofc
int backend_print(class_chain * cls_chain, class_chain * inst_chain, qual_chain * qual_chain, 
			const char * out_file, const char * out_dir,
			const char * ns, unsigned options, const char * extraopts)
{
  FILE * outfile = fopen(out_file,"w");
  if (outfile == NULL) {
    fprintf(stderr,"Failed to open %s\n",out_file);
    return 1;
  }
  
  FILE * qualfile;
  char qual_file[3000];
	
  strcpy(qual_file, out_dir);
  strcat(qual_file, "/");
  strcat(qual_file, ns);
  strcat(qual_file, "/");  
  strcat(qual_file, "qualifiers");
  qualfile = fopen(qual_file, "w");
  if (qualfile == NULL) {
    fprintf(stderr,"Failed to open %s\n",qual_file);
    return 1;
  }  
  
  while (cls_chain && cls_chain->class_item) {
    print_class(outfile, cls_chain->class_item);
    cls_chain = cls_chain -> class_next;
  }
  while (inst_chain && inst_chain->class_item) {
  	print_instance(out_dir, ns, inst_chain->class_item);
    inst_chain = inst_chain -> class_next;
  }
  while (qual_chain && qual_chain->qual_qual) {
  	print_qualifier(qualfile, qual_chain->qual_qual);
    qual_chain = qual_chain -> qual_next;
  }
  fclose(outfile);
  return 0;
}
コード例 #9
0
ファイル: heapInspection.cpp プロジェクト: shelan/jdk9-mirror
void KlassHierarchy::print_class_hierarchy(outputStream* st, bool print_interfaces,
                                           bool print_subclasses, char* classname) {
  ResourceMark rm;
  Stack <KlassInfoEntry*, mtClass> class_stack;
  GrowableArray<KlassInfoEntry*> elements;

  // Add all classes to the KlassInfoTable, which allows for quick lookup.
  // A KlassInfoEntry will be created for each class.
  KlassInfoTable cit(true);
  if (cit.allocation_failed()) {
    st->print_cr("ERROR: Ran out of C-heap; hierarchy not generated");
    return;
  }

  // Add all created KlassInfoEntry instances to the elements array for easy
  // iteration, and to allow each KlassInfoEntry instance to have a unique index.
  HierarchyClosure hc(&elements);
  cit.iterate(&hc);

  for(int i = 0; i < elements.length(); i++) {
    KlassInfoEntry* cie = elements.at(i);
    const InstanceKlass* k = (InstanceKlass*)cie->klass();
    Klass* super = ((InstanceKlass*)k)->java_super();

    // Set the index for the class.
    cie->set_index(i + 1);

    // Add the class to the subclass array of its superclass.
    if (super != NULL) {
      KlassInfoEntry* super_cie = cit.lookup(super);
      assert(super_cie != NULL, "could not lookup superclass");
      super_cie->add_subclass(cie);
    }
  }

  // Set the do_print flag for each class that should be printed.
  for(int i = 0; i < elements.length(); i++) {
    KlassInfoEntry* cie = elements.at(i);
    if (classname == NULL) {
      // We are printing all classes.
      cie->set_do_print(true);
    } else {
      // We are only printing the hierarchy of a specific class.
      if (strcmp(classname, cie->klass()->external_name()) == 0) {
        KlassHierarchy::set_do_print_for_class_hierarchy(cie, &cit, print_subclasses);
      }
    }
  }

  // Now we do a depth first traversal of the class hierachry. The class_stack will
  // maintain the list of classes we still need to process. Start things off
  // by priming it with java.lang.Object.
  KlassInfoEntry* jlo_cie = cit.lookup(SystemDictionary::Object_klass());
  assert(jlo_cie != NULL, "could not lookup java.lang.Object");
  class_stack.push(jlo_cie);

  // Repeatedly pop the top item off the stack, print its class info,
  // and push all of its subclasses on to the stack. Do this until there
  // are no classes left on the stack.
  while (!class_stack.is_empty()) {
    KlassInfoEntry* curr_cie = class_stack.pop();
    if (curr_cie->do_print()) {
      print_class(st, curr_cie, print_interfaces);
      if (curr_cie->subclasses() != NULL) {
        // Current class has subclasses, so push all of them onto the stack.
        for (int i = 0; i < curr_cie->subclasses()->length(); i++) {
          KlassInfoEntry* cie = curr_cie->subclasses()->at(i);
          if (cie->do_print()) {
            class_stack.push(cie);
          }
        }
      }
    }
  }

  st->flush();
}
コード例 #10
0
ファイル: peg.c プロジェクト: ctelfer/catlib
static void print_node(struct peg_grammar *peg, int i, int seq,
		       int depth, FILE *out)
{
	int j;
	int aggregate;
	char sbuf[256];
	struct peg_node *pn;

	if ( i < 0 || i >= peg->max_nodes )
		return;

	pn = NODE(peg, i);
	switch ( pn->pn_type ) {
	case PEG_DEFINITION:
		fprintf(out, "%s <-\n", NODE(peg, pn->pd_id)->pi_name.data);
		fprintf(out, "%s", indent(sbuf, sizeof(sbuf), 1));
		print_node(peg, pn->pd_expr, 0, 1, out);
		fprintf(out, "\n");
		break;

	case PEG_SEQUENCE:
		if ( seq > 0 ) {
			fprintf(out, "\n");
			fprintf(out, "%s", indent(sbuf, sizeof(sbuf), depth));
			fprintf(out, "/ ");
		}
		print_node(peg, pn->ps_pri, seq, depth + 1, out);
		print_node(peg, pn->pn_next, seq + 1, depth, out);
		break;

	case PEG_PRIMARY:
		aggregate = 0;
		if ( seq == 0 &&
		     (NODE(peg, pn->pp_match)->pn_type == PEG_SEQUENCE) )
			aggregate = 1;
		fprintf(out, "%s", (pn->pp_prefix == PEG_ATTR_NONE) ? "" :
		                   (pn->pp_prefix == PEG_ATTR_AND) ? "&" :
		                   (pn->pp_prefix == PEG_ATTR_NOT) ? "!" :
				   "BAD_PREFIX!");
		if ( aggregate )
			fprintf(out, "( ");
		print_node(peg, pn->pp_match, seq, depth, out);
		if ( aggregate )
			fprintf(out, " )");
		fprintf(out, "%s", (pn->pp_suffix == PEG_ATTR_NONE) ? " " :
		                   (pn->pp_suffix== PEG_ATTR_QUESTION) ? "? " :
		                   (pn->pp_suffix == PEG_ATTR_STAR) ? "* " :
		                   (pn->pp_suffix == PEG_ATTR_PLUS) ? "+ " :
				   "BAD_SUFFIX!");
		if ( pn->pp_action != PEG_ACT_NONE ) {
			if ( pn->pp_action == PEG_ACT_CODE ) {
				fprintf(out, "\n");
				fprintf(out, "%s",
					indent(sbuf, sizeof(sbuf), depth));
				fprintf(out, "CODE BLOCK:\n");
				fprintf(out, "%s", indent(sbuf, sizeof(sbuf),
					depth));
				fprintf(out, "%s", pn->pp_code.data);
			} else {
				fprintf(out, "(action_id: %s) ",
					pn->pp_label.data);
			}
		}
		print_node(peg, pn->pn_next, seq, depth, out);
		break;
		
	case PEG_IDENTIFIER:
		fprintf(out, "%s ", pn->pi_name.data);
		break;

	case PEG_LITERAL:
		fprintf(out, "'");
		for ( j = 0; j < pn->pl_value.len; ++j )
			printchar(out, pn->pl_value.data[j]);
		fprintf(out, "' ");
		break;

	case PEG_CLASS:
		print_class(out, pn);
		break;
	}
}
コード例 #11
0
/** Load and process the command-line arguments
	@return a STATUS value

	Arguments are processed immediately as they are seen.  This means that
	models are loaded when they are encountered, and in relation to the
	other flags.  Thus
	@code
	gridlabd --warn model1 --warn model2
	@endcode
	will load \p model1 with warnings on, and \p model2 with warnings off.
 **/
STATUS cmdarg_load(int argc, /**< the number of arguments in \p argv */
				   char *argv[]) /**< a list pointers to the argument string */
{
	int test_mod_num = 1;
	unsigned int pos=0;
	int i;
	char *pd1, *pd2;

	/* capture the execdir */
	strcpy(global_execname,argv[0]);
	strcpy(global_execdir,argv[0]);
	pd1 = strrchr(global_execdir,'/');
	pd2 = strrchr(global_execdir,'\\');
	if (pd1>pd2) *pd1='\0';
	else if (pd2>pd1) *pd2='\0';

	/* capture the command line */
	for (i=0; i<argc; i++)
	{
		if (pos<sizeof(global_command_line)-strlen(argv[i]))
			pos += sprintf(global_command_line+pos,"%s%s",pos>0?" ":"",argv[i]);
	}

	while (argv++,--argc>0)
	{
		if (strcmp(*argv,"--copyright")==0)
			legal_notice();
		else if (strcmp(*argv,"-w")==0 || strcmp(*argv,"--warn")==0)
			global_warn_mode=!global_warn_mode;
		else if (strcmp(*argv,"--bothstdout")==0)
			output_both_stdout();
		else if (strcmp(*argv,"-c")==0 || strcmp(*argv,"--check")==0)
			global_runchecks=!global_runchecks;
		else if (strcmp(*argv,"--debug")==0)
			global_debug_output=!global_debug_output;
		else if (strcmp(*argv,"--debugger")==0){
			global_debug_mode=1;
			global_debug_output=!global_debug_output;
		}
		else if (strcmp(*argv,"--dumpall")==0)
			global_dumpall=!global_dumpall;
		else if (strcmp(*argv,"-q")==0 || strcmp(*argv,"--quiet")==0)
			global_quiet_mode=!global_quiet_mode;
		else if (strcmp(*argv,"-v")==0 || strcmp(*argv,"--verbose")==0){
			global_verbose_mode=!global_verbose_mode;
		}
		else if (strcmp(*argv,"--profile")==0)
			global_profiler=!global_profiler;
		else if (strcmp(*argv,"--pause")==0)
			global_pauseatexit=!global_pauseatexit;
		else if (strcmp(*argv,"--compile")==0)
			global_compileonly = !global_compileonly;
		else if (strcmp(*argv,"--license")==0)
			legal_license();
		else if (strcmp(*argv,"--server_portnum")==0 || strcmp(*argv,"-P")==0)
		{
			if (argc-1>0)
				global_server_portnum = (argc--,atoi(*++argv));
			else
			{
				output_fatal("missing server port number");
				/*	TROUBLESHOOT
					The <b>-P</b> or <b>--server_portnum</b> command line directive
					was not followed by a valid number.  The correct syntax is
					<b>-P <i>number</i></b> or <b>--server_portnum <i>number</i></b>.
				 */
			}
		}
		else if (strcmp(*argv, "-V")==0 ||strcmp(*argv, "--version")==0)
		{
			char *buildinfo = strstr(BUILD,":");
			int build = buildinfo ? atoi(strstr(BUILD,":")+1) : 0;
			output_message("Revision major: %d", REV_MAJOR);
			output_message("Revision minor: %d", REV_MINOR);
			output_message("Patch number  : %d", REV_PATCH);
			output_message("Branch name   : %s", BRANCH);
			if (build>0)
				output_message("Build number  : %d", build);
			else
				output_message("Build number  : %s",
#ifdef WIN32
#ifdef _DEBUG
#ifdef _M_X64
			"WIN64-DEBUG"
#else
			"WIN32-DEBUG" 
#endif
#else
#ifdef _M_X64
			"WIN64-RELEASE"
#else
			"WIN32-RELEASE"
#endif
#endif
#else
			"DEV"
#endif		
			);
		}
		else if (strcmp(*argv,"--dsttest")==0)
			timestamp_test();
		else if (strcmp(*argv,"--randtest")==0)
			random_test();
		else if (strcmp(*argv,"--unitstest")==0)
			unit_test();
		else if (strcmp(*argv,"--scheduletest")==0)
			schedule_test();
		else if (strcmp(*argv,"--loadshapetest")==0)
			loadshape_test();
		else if (strcmp(*argv,"--endusetest")==0)
			enduse_test();
		else if (strcmp(*argv,"--xmlstrict")==0)
			global_xmlstrict = !global_xmlstrict;
		else if (strcmp(*argv,"--globaldump")==0)
		{
			global_dump();
			exit(0);
		}
		else if (strcmp(*argv,"--relax")==0)
			global_strictnames = FALSE;
		else if (strncmp(*argv,"--pidfile",9)==0)
		{
			char *filename = strchr(*argv,'=');
			if (filename==NULL)
				strcpy(global_pidfile,"gridlabd.pid");
			else
				strcpy(global_pidfile,filename+1);
		}
		else if (strncmp(*argv,"--kml",5)==0)
		{
			char *filename = strchr(*argv,'=');
			if (filename)
				strcpy(global_kmlfile,filename+1);
			else
				strcpy(global_kmlfile,"gridlabd.kml");
		}
		else if (strcmp(*argv, "--avlbalance") == 0){
			global_no_balance = !global_no_balance;
		}
		else if (strcmp(*argv,"--testall")==0){
			FILE *fd = NULL;
			if(*++argv != NULL)
				fd = fopen(*argv,"r");
			else {
				output_fatal("no filename for testall");
				/*	TROUBLESHOOT
					The --testall parameter was found on the command line, but
					if was not followed by a filename containing the test
					description file.
				*/
				return FAILED;
			}
			argc--;
			global_test_mode=TRUE;

			if(fd == NULL)
			{
				output_fatal("incorrect module list file name");
				/*	TROUBLESHOOT
					The --testall parameter was found on the command line, but
					if was not followed by a valid filename containing the test
					description file.
				*/
				return FAILED;
			}
			if(load_module_list(fd,&test_mod_num) == FAILED)
				return FAILED;
		}
		else if (strcmp(*argv,"--modhelp")==0)
		{
			if(argc-1 > 0){
				MODULE *mod = NULL;
				CLASS *oclass = NULL;
				argv++;
				argc--;
				if(strchr(argv[0], ':') == 0){ // no class
					mod = module_load(argv[0],0,NULL);
				} else {
					GLOBALVAR *var=NULL;
					char *cname;
					cname = strchr(argv[0], ':')+1;
					mod = module_load(strtok(argv[0],":"),0,NULL);
					oclass = class_get_class_from_classname(cname);
					if(oclass == NULL){
						output_fatal("Unable to find class '%s' in module '%s'", cname, argv[0]);
						/*	TROUBLESHOOT
							The <b>--modhelp</b> parameter was found on the command line, but
							if was followed by a class specification that isn't valid.
							Verify that the class exists in the module you specified.
						*/
						return FAILED;
					}

					/* dump module globals */
					printf("module %s {\n", mod->name);
					while ((var=global_getnext(var))!=NULL)
					{
						PROPERTY *prop = var->prop;
						char *proptype = class_get_property_typename(prop->ptype);
						if (strncmp(var->prop->name,mod->name,strlen(mod->name))!=0)
							continue;
						if (proptype!=NULL){
							if(prop->unit != NULL)
							{
								printf("\t%s %s[%s];", proptype, strrchr(prop->name,':')+1, prop->unit->name);
							}
							else if (prop->ptype==PT_set || prop->ptype==PT_enumeration)
							{
								KEYWORD *key;
								printf("\t%s {", proptype);
								for (key=prop->keywords; key!=NULL; key=key->next)
									printf("%s=%"FMT_INT64"u%s", key->name, (int64)key->value, key->next==NULL?"":", ");
								printf("} %s;", strrchr(prop->name,':')+1);
							} 
							else 
							{
								printf("\t%s %s;", proptype, strrchr(prop->name,':')+1);
							}
							if (prop->description!=NULL)
								printf(" // %s%s",prop->flags&PF_DEPRECATED?"(DEPRECATED) ":"",prop->description);
							printf("\n");
						}
					}
					printf("}\n");
				}
				if(mod == NULL){
					output_fatal("module %s is not found",*argv);
					/*	TROUBLESHOOT
						The <b>--modhelp</b> parameter was found on the command line, but
						if was followed by a module specification that isn't valid.
						Verify that the module exists in GridLAB-D's <b>lib</b> folder.
					*/
					return FAILED;
				}
				if(oclass != NULL)
				{
					print_class(oclass);
				}
				else
				{
					CLASS	*oclass;
					pntree	*ctree;
					/* lexographically sort all elements from class_get_first_class & oclass->next */

					oclass=class_get_first_class();
					ctree = (pntree *)malloc(sizeof(pntree));
					
					if(ctree == NULL){
						throw_exception("--modhelp: malloc failure");
						/* TROUBLESHOOT
							The memory allocation needed for module help to function has failed.  Try freeing up system memory and try again.
						 */
					}
					
					ctree->name = oclass->name;
					ctree->oclass = oclass;
					ctree->left = ctree->right = 0;
					
					for(; oclass != NULL; oclass = oclass->next){
						modhelp_alpha(&ctree, oclass);
						//print_class(oclass);
					}

					/* flatten tree */
					print_modhelp_tree(ctree);
				}
			}
		}
		else if (strcmp(*argv,"--modtest")==0)
		{
			if (argc-1>0)
			{
				MODULE *mod = module_load(argv[1],0,NULL);
				if (mod==NULL)
					output_fatal("module %s is not found",argv[1]);
					/*	TROUBLESHOOT
						The <b>--modtest</b> parameter was found on the command line, but
						if was followed by a module specification that isn't valid.
						Verify that the module exists in GridLAB-D's <b>lib</b> folder.
					*/
				else 
				{
					argv++;argc--;
					if (mod->test==NULL)
						output_fatal("module %s does not implement a test routine", argv[0]);
						/*	TROUBLESHOOT
							The <b>--modtest</b> parameter was found on the command line, but
							if was followed by a specification for a module that doesn't
							implement any test procedures.  See the <b>--libinfo</b> command
							line parameter for information on which procedures the
							module supports.
						*/
					else
					{
						output_test("*** modtest of %s beginning ***", argv[0]);
						mod->test(0,NULL);
						output_test("*** modtest of %s ended ***", argv[0]);
					}
				}			
			}
			else
			{
				output_fatal("definition is missing");
				/*	TROUBLESHOOT
					The <b>--modtest</b> parameter was found on the command line, but
					if was not followed by a module specification.  The correct
					syntax is <b>gridlabd --modtest <i>module_name</i></b>.
				*/
				return FAILED;
			}
		}
		else if (strcmp(*argv,"--test")==0){
			global_test_mode=TRUE;
			global_strictnames = FALSE;
			output_debug("disabling strict naming for tests");
			if (argc-1>0)
			{
				char mod_test[100];
				sprintf(mod_test,"mod_test%d=%s",test_mod_num++,*++argv);
				if (global_setvar(mod_test)==SUCCESS)
					argc--;
			}
			else
			{
				output_fatal("test module name is missing");
				/*	TROUBLESHOOT
					The <b>--test</b> parameter was found on the command line, but
					if was not followed by a module specification that is valid.
					The correct syntax is <b>gridlabd --test <i>module_name</i></b>.
				*/
				return FAILED;
			}

		}
		else if (strcmp(*argv,"-D")==0 || strcmp(*argv,"--define")==0)
		{
			if (argc-1>0)
			{
				bool namestate = global_strictnames;
				global_strictnames = FALSE;
				if (global_setvar(*++argv,NULL)==SUCCESS){
					argc--;
				}
				global_strictnames = namestate;
			}
			else
			{
				output_fatal("definition is missing");
				/* TROUBLESHOOT
					The <b>-D</b> or <b>--define</b> command line parameters was given, but
					it was not followed by a variable definition.  The correct syntax
					<b>-D </i>variable</i>=<i>value</i></b> or
					<b>--define </i>variable</i>=<i>value</i></b>
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"--globals")==0)
		{
			char *list[65536];
			int i, n=0;
			GLOBALVAR *var = NULL;

			/* load the list into the array */
			while ((var=global_getnext(var))!=NULL)
			{
				if (n<sizeof(list)/sizeof(list[0]))
					list[n++] = var->prop->name;
				else
				{
					output_fatal("--globals has insufficient buffer space to sort globals list");
					return FAILED;
				}
			}

			/* sort the array */
			qsort(list,n,sizeof(list[0]),compare);

			/* output sorted array */
			for (i=0; i<n; i++)
			{
				char buffer[1024];
				var = global_find(list[i]);
				printf("%s=%s;",var->prop->name,global_getvar(var->prop->name,buffer,sizeof(buffer))?buffer:"(error)");
				if (var->prop->description || var->prop->flags&PF_DEPRECATED)
					printf(" // %s%s", (var->prop->flags&PF_DEPRECATED)?"DEPRECATED ":"", var->prop->description?var->prop->description:"");
				printf("\n");
			}
		}
		else if (strcmp(*argv,"--redirect")==0)
		{
			if (argc-1>0)
			{
				char buffer[1024]; char *p;
				strcpy(buffer,*++argv); argc--;
				if (strcmp(buffer,"all")==0)
				{
					if (output_redirect("output",NULL)==NULL ||
						output_redirect("error",NULL)==NULL ||
						output_redirect("warning",NULL)==NULL ||
						output_redirect("debug",NULL)==NULL ||
						output_redirect("verbose",NULL)==NULL ||
						output_redirect("profile",NULL)==NULL ||
						output_redirect("progress",NULL)==NULL)
					{
						output_fatal("redirection of all failed");
						/* TROUBLESHOOT
							An attempt to close all standard stream from the
							command line using <b>--redirect all</b> has failed.
							One of the streams cannot be closed.  Try redirecting
							each stream separately until the problem stream is
							identified and the correct the problem with that stream.
						 */
						return FAILED;
					}
				}
				else if ((p=strchr(buffer,':'))!=NULL)
				{
					*p++='\0';
					if (output_redirect(buffer,p)==NULL)
					{
						output_fatal("redirection of %s to '%s' failed: %s",buffer,p, strerror(errno));
						/*	TROUBLESHOOT
							An attempt to redirect a standard stream from the 
							command line using <b>--redirect <i>stream</i>:<i>destination</i></b>
							has failed.  The message should provide an indication of why the
							attempt failed. The remedy will depend on the nature of the problem.
						 */
						return FAILED;
					}
				}
				else if (output_redirect(buffer,NULL)==NULL)
				{
						output_fatal("default redirection of %s failed: %s",buffer, strerror(errno));
						/*	TROUBLESHOOT
							An attempt to close a standard stream from the 
							command line using <b>--redirect <i>stream</i></b>
							has failed.  The message should provide an indication of why the
							attempt failed. The remedy will depend on the nature of the problem.
							
						 */
						return FAILED;
				}
			}
			else
			{
				output_fatal("redirection is missing");
				/*	TROUBLESHOOT
					A <b>--redirect</b> directive on the command line is missing
					its redirection specification.  The correct syntax is
					<b>--redirect <i>stream</i>[:<i>destination</i>]</b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"-L")==0 || strcmp(*argv,"--libinfo")==0)
		{
			if (argc-1>0)
			{	argc--;
				module_libinfo(*++argv);
				exit(0);
			}
			else
			{
				output_fatal("missing library name");
				/*	TROUBLESHOOT
					The <b>-L</b> or <b>--libinfo</b> command line directive
					was not followed by a module name.  The correct syntax is
					<b>-L <i>module_name</i></b> or <b>--libinfo <i>module_name</i></b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"-T")==0 || strcmp(*argv,"--threadcount")==0)
		{
			if (argc-1>0)
				global_threadcount = (argc--,atoi(*++argv));
			else
			{
				output_fatal("missing thread count");
				/*	TROUBLESHOOT
					The <b>-T</b> or <b>--threadcount</b> command line directive
					was not followed by a valid number.  The correct syntax is
					<b>-T <i>number</i></b> or <b>--threadcount <i>number</i></b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"-o")==0 || strcmp(*argv,"--output")==0)
		{
			if (argc-1>0)
				strcpy(global_savefile,(argc--,*++argv));
			else
			{
				output_fatal("missing output file");
				/* TROUBLESHOOT
					The <b>-o</b> or <b>--output</b> command line directive
					was not followed by a valid filename.  The correct syntax is
					<b>-o <i>file</i></b> or <b>--output <i>file</i></b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"-e")==0 || strcmp(*argv,"--environment")==0)
		{
			if (argc-1>0)
				strcpy(global_environment,(argc--,*++argv));
			else
			{
				output_fatal("environment not specified");
				/*	TROUBLESHOOT
					The <b>-e</b> or <b>--environment</b> command line directive
					was not followed by a valid environment specification.  The
					correct syntax is <b>-e <i>keyword</i></b> or <b>--environment <i>keyword</i></b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"--xmlencoding")==0)
		{
			if (argc-1>0)
			{
				global_xml_encoding = atoi(*++argv);
				argc--;
			}
			else
			{
				output_fatal("xml encoding not specified");
				/*	TROUBLESHOOT
					The <b>--xmlencoding</b> command line directive
					was not followed by a encoding specification.  The
					correct syntax is <b>--xmlencoding <i>keyword</i></b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"--xsd")==0)
		{
			if (argc-1>0)
			{
				argc--;
				exit(output_xsd(*++argv));
			}
			else
			{
				MODULE *mod;
				for (mod=module_get_first(); mod!=NULL; mod=mod->next)
					output_xsd(mod->name);
				return SUCCESS;
			}
		}
		else if (strcmp(*argv,"--xsl")==0)
		{
			if (argc-1>0)
			{
				char fname[1024];
				char *p_arg = *++argv;
				char n_args=1;
				char **p_args;
				argc--;
				while (*p_arg++!='\0') if (*p_arg==',')	n_args++;
				p_args = (char**)malloc(sizeof(char*)*n_args);
				p_arg = strtok(*argv,",");
				n_args=0;
				while (p_arg!=NULL)
				{
					p_args[n_args++] = p_arg;
					p_arg = strtok(NULL,",");
				}
				sprintf(fname,"gridlabd-%d_%d.xsl",global_version_major,global_version_minor);
				exit(output_xsl(fname,n_args,p_args));
			}
			else
			{
				output_fatal("module list not specified");
				/*	TROUBLESHOOT
					The <b>--xsl</b> command line directive
					was not followed by a validlist of modules.  The
					correct syntax is <b>--xsl <i>module1</i>[,<i>module2</i>[,...]]</b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"--stream")==0)
			global_streaming_io_enabled = !global_streaming_io_enabled;
		else if (strcmp(*argv,"--server")==0)
			strcpy(global_environment,"server");
		else if (strcmp(*argv,"-h")==0 || strcmp(*argv,"--help")==0)
		{
			printf("Syntax: gridlabd [OPTIONS ...] <file> ... \nOptions:\n"
				"  --avlbalance              toggles AVL tree balancing\n"
				"  -c|--check                toggles module checks after model loads\n"
				"  -D|--define <def>         defines a macro value\n"
				"  --debug                   toggles debug output (prints internal messages)\n"
				"  --debugger                toggles debugger mode (generates internal messages)\n"
				"  --dumpall                 toggles module data dump after run completes\n"
				"  -e|--environment <name>   specifies user environment (default none)\n"
				"  --license                 print license information\n"
				"  -L|--libinfo <module>     print module library information\n"
				"  -o|--output <file>        specifies model should be output after run\n"
				"  --profile                 toggles profilers\n"
				"  -q|--quiet                toggles quiet mode (suppresses startup banner)\n"
				"  --test                    toggles test mode (activate testing procedures)\n"
				"  -T|--threadcount <n>      specifies the number of processor threads to use\n"
				"  -v|--verbose              toggles verbose mode (active verbose messages)\n"
				"  -V|--version              prints the GridlabD version information\n"
				"  -w|--warn                 toggles warning mode (generates warning messages)\n"
				"  --xmlencoding <num>       set the XML encoding (8, 16, or 32)\n"
				"  --xmlstrict               toggles XML encoding to be strict\n"
				"  --xsd <module>[:<object>] prints the xsd of an object\n"
				"  --xsl <modlist>           prints the xsl for the modules listed\n"
				);
			exit(0);
		}
		else if (**argv!='-')
		{
			if (global_test_mode)
				output_warning("file '%s' ignored in test mode", *argv);
				/* TROUBLESHOOT
				   This warning is caused by an attempt to read an input file in self-test mode.  
				   The use of self-test model precludes reading model files.  Try running the system
				   in normal more or leaving off the model file name.
				 */
			else {
				if (!loadall(*argv))
					return FAILED;
				/* preserve name of first model only */
				if (strcmp(global_modelname,"")==0)
					strcpy(global_modelname,*argv);
			}
		}
		else
		{
			int n = module_cmdargs(argc,argv);
			if (n==0)
			{
				output_error("command line option '%s' is not recognized",*argv);
				/* TROUBLESHOOT
					The command line option given is not valid where it was found.
					Check the command line for correct syntax and order of options.
				 */
				return FAILED;
			}
		}
	}
	/*debug_traverse_tree(NULL);*/  /* for checking the name tree & getting a test file. -mh */
	return SUCCESS;
}
コード例 #12
0
ファイル: varlist.c プロジェクト: ngholka/mpi-tools
void list_pvars()
{
	int num,err,i,numvars;
	char *name, *desc;
	int bind,vc,verbos,ro,ct,at;
	MPI_Datatype dt;
	MPI_T_enum et;
	int maxnamelen=strlen("Variable");
	int maxdesclen=0;
	int prtlen;
	int namelen,desclen;


	/* Get number of variables */

	err=MPI_T_pvar_get_num(&num);
	CHECKERR("PVARNUM",err);
	printf("Found %i performance variables\n",num);


	/* Find string sizes */

	numvars=0;

	for (i=0; i<num; i++)
	{
		int namelen=0;
		int desclen=0;
		char fname[5];
		char fdesc[5];
		err=MPI_T_pvar_get_info(i,fname,&namelen,&verbos,&vc,&dt,&et,fdesc,&desclen,&bind,&ro,&ct,&at);
		if (namelen>maxnamelen) maxnamelen=namelen;
		if (desclen>maxdesclen) maxdesclen=desclen;
		if (verbos<=verbosity) numvars++;
	}

	printf("Found %i performance variables with verbosity <= ",numvars);
	print_verbosity_short(verbosity);
	printf("\n\n");


	/* Allocate string buffers */

	name=(char*)malloc(sizeof(char)*maxnamelen);
	CHECKERR("Malloc Name",name==NULL);
	desc=(char*)malloc(sizeof(char)*maxdesclen);
	CHECKERR("Malloc Desc",desc==NULL);

	/* Print header */

	prtlen=0;
	if (!longlist)
	{
		print_filled("Variable",maxnamelen,' ');
		printf(" ");
		prtlen=maxnamelen+1;
		printf("VRB  ");
		printf(" ");
		prtlen+=5+1;
		printf("Class  ");
		printf(" ");
		prtlen+=7+1;
		printf("Type  ");
		printf(" ");
		prtlen+=6+1;
		printf("Bind    ");
		printf(" ");
		prtlen+=8+1;
		printf("R/O");
		printf(" ");
		prtlen+=3+1;
		printf("CNT");
		printf(" ");
		prtlen+=3+1;
		printf("ATM");
		printf("\n");
		prtlen+=3;
		print_filled("",prtlen,'-');printf("\n");
	}


	/* Loop and print */

	for (i=0; i<num; i++)
	{
		namelen=maxnamelen;
		desclen=maxdesclen;
		err=MPI_T_pvar_get_info(i,name,&namelen,&verbos,&vc,&dt,&et,desc,&desclen,&bind,&ro,&ct,&at);
		CHECKERR("PVARINFO",err);
		if (verbos<=verbosity)
		{
			if (!longlist)
			{
				print_filled(name,maxnamelen,' ');
				printf(" ");
				print_verbosity_short(verbos);
				printf(" ");
				print_class(vc);
				printf(" ");
				print_type(dt);
				printf(" ");
				print_bind(bind);
				printf(" ");
				print_yesno(ro);
				printf(" ");
				print_yesno(ct);
				printf(" ");
				print_yesno(at);
				printf("\n");
			}
			else
			{
				print_filled("",SCREENLEN,'-');printf("\n");
				printf("Name: %s (",name); print_verbosity(verbos);printf(")\n");
				printf("Class: "); print_class(vc); printf("\n");
				printf("Type:  "); print_type(dt); printf("\n");
				printf("Bind:  "); print_bind(bind); printf("\n");
				printf("Attr.: ");
				printf("Readonly:");print_yesno(ro);printf(" ");
				printf("Cont.:");print_yesno(ct);printf(" ");
				printf("Atomic:");print_yesno(at);printf("\n\n");
				if (desc!=NULL)
					printf("%s\n\n",desc);
			}
		}
	}

	if (numvars>0)
	{
		if (!longlist)
		{
			print_filled("",prtlen,'-');printf("\n");
		}
		else
		{
			print_filled("",SCREENLEN,'-');printf("\n");
		}
	}


	/* free buffers */

	free(name);
	free(desc);
}