Example #1
0
void
pcl::console::print_value (const char *format, ...)
{
  //if (!isVerbosityLevelEnabled (L_ALWAYS)) return;

  change_text_color (stdout, TT_RESET, TT_CYAN);
  va_list ap;

  va_start (ap, format);
  vfprintf (stdout, format, ap);
  va_end (ap);
  
  reset_text_color (stdout);
}
Example #2
0
void
pcl::console::print_warn (FILE *stream, const char *format, ...)
{
  if (!isVerbosityLevelEnabled (L_WARN)) return;

  change_text_color (stream, TT_BRIGHT, TT_YELLOW);
  va_list ap;

  va_start (ap, format);
  vfprintf (stream, format, ap);
  va_end (ap);
  
  reset_text_color (stream);
}
Example #3
0
void
pcl::console::print_error (const char *format, ...)
{
  if (!isVerbosityLevelEnabled (L_ERROR)) return;

  change_text_color (stderr, TT_BRIGHT, TT_RED);
  va_list ap;

  va_start (ap, format);
  vfprintf (stderr, format, ap);
  va_end (ap);
  
  reset_text_color (stderr);
}
Example #4
0
void
pcl::console::print_highlight (FILE *stream, const char *format, ...)
{
  //if (!isVerbosityLevelEnabled (L_ALWAYS)) return;

  change_text_color (stream, TT_BRIGHT, TT_GREEN);
  fprintf (stream, "> ");
  reset_text_color (stream);

  va_list ap;

  va_start (ap, format);
  vfprintf (stream, format, ap);
  va_end (ap);
}
Example #5
0
static int
do_ncc(char *cppfile, char *nccfile, int is_tmpfile) {
	static int		inits_done;
	int			fildes;
	FILE			*input;
	FILE			*fd;
	char			*p;
	static struct timeval	tv;
	static int		timing_init;
	static int		timing_lex;
	static int		timing_analysis;
	static int		timing_gen;
	struct stat		sbuf;

	if (timeflag) {
		/* Time initialization stuff */
		start_timer(&tv);
	}
	/* Generate in CWD */
	if ((p = strrchr(nccfile, '/')) != NULL) {
		nccfile = p+1;
	}

	generated_asm_file = nccfile;
	atexit(remove_garbage);
	if (inits_done == 0) {
		init_keylookup();
		init_oplookup();
		inits_done = 1;
	}
	toklist = NULL;
	funclist = NULL;

	if (!write_fcat_flag) {
		input = fopen(cppfile, "r");
		if (input == NULL) {
			perror(cppfile);
			return EXIT_FAILURE;
		}
		if (generated_cpp_file == cppfile) {
			/*
			 * 20141123: What we just opened is a preprocessor
			 * output file. It can now be removed. This should
			 * fix a longstanding problem with stale .cpp files
			 * left in /var/tmp
			 */
			(void) remove(generated_cpp_file);
		}
	}
	
	if (dump_macros_flag) {
		char	buf[1024];

		while (fgets(buf, sizeof buf, input) != NULL) {
			printf("%s", buf);
		}
		return 0;
	}

	if (write_fcat_flag) {
		fd = NULL;
	} else {
		(void) unlink(nccfile); /* trash stale .asm file */

		if ((fildes = open(nccfile, O_CREAT | O_EXCL | O_RDWR, S_IRWXU))
			== -1) {
			perror(nccfile);
			if (is_tmpfile) remove(cppfile);
			return EXIT_FAILURE;
		}
		if ((fd = fdopen(fildes, "r+")) == NULL) {
			perror(nccfile);
			REM_EXIT(cppfile, nccfile);
			return EXIT_FAILURE;
		}
	}

	/*
	 * It is important to initialize the backend before doing
	 * lexical analysis because architecture and ABI information
	 * are needed
	 */
	if (init_backend(fd, &global_scope) != 0) {
		REM_EXIT(cppfile, nccfile);
	}

#if USE_ZONE_ALLOCATOR
	zalloc_create();
	zalloc_init(Z_CONTROL, sizeof(struct control), 1, 0);
	/*
	 * 10/20/09: Disable label memory reclaimation for now. This is
	 * needed since the switch label changes were made, or else the
	 * ctrl->labels (ctrl_to_icode() for TOK_KEY_SWITCH) list will
	 * end up containing a member that links to itself.
	 */
	zalloc_init(Z_LABEL, sizeof(struct label), 1, 1);
	zalloc_init(Z_EXPR, sizeof(struct expr), 1, 0);  /* XXX doesn't work */
	zalloc_init(Z_INITIALIZER, sizeof(struct initializer), 1, 1);
	zalloc_init(Z_STATEMENT, sizeof(struct statement), 1, 1);
	zalloc_init(Z_FUNCTION, sizeof(struct function), 1, 1);
	zalloc_init(Z_ICODE_INSTR, sizeof(struct icode_instr), 1, 0);
	zalloc_init(Z_ICODE_LIST, sizeof(struct icode_list), 1, 0);
	zalloc_init(Z_VREG, sizeof(struct vreg), 1, 0);
	zalloc_init(Z_STACK_BLOCK, sizeof(struct stack_block), 1, 0);
	zalloc_init(Z_S_EXPR, sizeof(struct s_expr), 1, 0);
	zalloc_init(Z_FCALL_DATA, sizeof(struct fcall_data), 1, 0);
/*	zalloc_init(Z_IDENTIFIER, sizeof(struct control), 1);*/
#if FAST_SYMBOL_LOOKUP
	zalloc_init(Z_FASTSYMHASH, sizeof(struct fast_sym_hash_entry), 1, 0);
#endif

	zalloc_init(Z_CEXPR_BUF, 16, 1, 1); /* XXX */

#endif


	if (write_fcat_flag) {
		/*
		 * 07/27/09: Parse function catalog and write index file.
		 * We do this here because there are various parser
		 * initializations which shouldn't be missed
		 */
		if (is_tmpfile) (void) remove(cppfile);
		(void) remove(nccfile);
	
		return fcat_write_index_file("fcatalog.idx", "fcatalog");
	}

	if (stat(INSTALLDIR "/nwcc/lib/fcatalog.idx", &sbuf) == 0) {
		(void) fcat_open_index_file(INSTALLDIR "/nwcc/lib/fcatalog.idx");
	} else {
		(void) fcat_open_index_file("fcatalog.idx");
	}

	if (timeflag) {
		timing_init = stop_timer(&tv);
		start_timer(&tv);
	}

	if (lex_nwcc(create_input_file(input)) != 0) {
		REM_EXIT(cppfile, nccfile);
	}

	if (timeflag) {
		timing_lex = stop_timer(&tv);
		start_timer(&tv);
	}
		

#if XLATE_IMMEDIATELY
	/* Prepare .asm file for code generation */
	backend->gen_prepare_output();
#endif
	
	/* Now compile all code */
	if (analyze(NULL) != 0) {
		REM_EXIT(cppfile, nccfile);
	}
	
#if XLATE_IMMEDIATELY
	if (!errors) {
		/* Finish code generation */
		backend->gen_finish_output();
	}
#endif

	if (timeflag) {
		timing_analysis = stop_timer(&tv);
		start_timer(&tv);
	}

#if ! XLATE_IMMEDIATELY
	/*
	 * All code has been parsed and translated to icode, and can now
	 * be written as a whole .asm file in one step
	 */
	if (errors || backend->generate_program() != 0) {
		;
	}
#endif

	if (timeflag) {
		timing_gen = stop_timer(&tv);
	}

	/* destroy_toklist(&toklist); */

	if (!using_ucpp) {	/* ucpp already closes the file in free_lexer_state() apparently */
		fclose(input);
	}
	if (is_tmpfile) {
		if (!save_bad_translation_unit_flag) {
			remove(cppfile);
		}
	}

	if (color_flag) {
		reset_text_color();
	}

	(void) fprintf(stderr, "%s - %u error(s), %u warning(s)\n",
		cppfile, (unsigned)errors, (unsigned)warnings);

	if (timeflag) {
		int	timing_total = timing_cpp + timing_init + timing_lex +
				timing_analysis + timing_gen;

#define RESULT(x) x / 1000000.0, (float)x / timing_total * 100
		(void) fprintf(stderr, "=== Timing of nwcc1 ===\n");
		(void) fprintf(stderr, "   Preprocessing:   %f sec  "
			"(%f%% of total)\n", RESULT(timing_cpp));
		(void) fprintf(stderr, "   Initialization:  %f sec  "
			"(%f%% of total)\n", RESULT(timing_init));
		(void) fprintf(stderr, "   Lexing:          %f sec  "
			"(%f%% of total)\n", RESULT(timing_lex));
		(void) fprintf(stderr, "   Parsing+icode:   %f sec  "
			"(%f%% of total)\n", RESULT(timing_analysis));
		(void) fprintf(stderr, "   Emission:        %f sec  "
			"(%f%% of total)\n", RESULT(timing_gen));
	}
	
	if (errors) {
		remove(nccfile);
		return EXIT_FAILURE;
	}
	return 0;
}
Example #6
0
File: Sinfo.c Project: AZed/cdo
void *Sinfo(void *argument)
{
  enum {func_generic, func_param, func_name, func_code};
  int operatorID;
  int operfunc, lensemble;
  int indf;
  int varID;
  int gridsize = 0;
  int gridID, zaxisID, code, tabnum, param;
  int vdate, vtime;
  int nvars, ntsteps;
  int levelsize;
  int tsteptype, taxisID;
  char tmpname[CDI_MAX_NAME];
  char varname[CDI_MAX_NAME];
  char paramstr[32];
  char vdatestr[32], vtimestr[32];
  const char *modelptr, *instptr;
  int streamID = 0;
  int vlistID;
  int datatype;
  char pstr[4];

  cdoInitialize(argument);

  cdoOperatorAdd("sinfo",   func_generic, 0, NULL);
  cdoOperatorAdd("sinfop",  func_param,   0, NULL);
  cdoOperatorAdd("sinfon",  func_name,    0, NULL);
  cdoOperatorAdd("sinfoc",  func_code,    0, NULL);
  cdoOperatorAdd("seinfo",  func_generic, 1, NULL);
  cdoOperatorAdd("seinfop", func_param,   1, NULL);
  cdoOperatorAdd("seinfon", func_name,    1, NULL);
  cdoOperatorAdd("seinfoc", func_code,    1, NULL);

  operatorID = cdoOperatorID();

  operfunc  = cdoOperatorF1(operatorID);
  lensemble = cdoOperatorF2(operatorID);

  for ( indf = 0; indf < cdoStreamCnt(); indf++ )
    {
      streamID = streamOpenRead(cdoStreamName(indf));

      vlistID = streamInqVlist(streamID);

      set_text_color(stdout, BRIGHT, BLACK);
      fprintf(stdout, "   File format");
      reset_text_color(stdout);
      fprintf(stdout, " : ");
      printFiletype(streamID, vlistID);

      set_text_color(stdout, BRIGHT, BLACK);
      if ( lensemble )
	fprintf(stdout, "%6d : Institut Source   Ttype    Einfo Levels Num    Points Num Dtype : ",  -(indf+1));
      else
	fprintf(stdout, "%6d : Institut Source   Ttype    Levels Num    Points Num Dtype : ",  -(indf+1));

      if      ( operfunc == func_name ) fprintf(stdout, "Parameter name");
      else if ( operfunc == func_code ) fprintf(stdout, "Table Code");
      else                              fprintf(stdout, "Parameter ID");

      if ( cdoVerbose ) fprintf(stdout, " : Extra" );              
      reset_text_color(stdout);
      fprintf(stdout, "\n" );              

      nvars = vlistNvars(vlistID);

      for ( varID = 0; varID < nvars; varID++ )
	{
	  param   = vlistInqVarParam(vlistID, varID);
	  code    = vlistInqVarCode(vlistID, varID);
	  tabnum  = tableInqNum(vlistInqVarTable(vlistID, varID));
	  gridID  = vlistInqVarGrid(vlistID, varID);
	  zaxisID = vlistInqVarZaxis(vlistID, varID);

	  set_text_color(stdout, BRIGHT, BLACK);
	  fprintf(stdout, "%6d", varID+1);
	  reset_text_color(stdout);
	  set_text_color(stdout, RESET, BLACK);
	  fprintf(stdout, " : ");
	  reset_text_color(stdout);
	      
	  set_text_color(stdout, RESET, BLUE);
	  /* institute info */
	  instptr = institutInqNamePtr(vlistInqVarInstitut(vlistID, varID));
	  strcpy(tmpname, "unknown");
	  if ( instptr ) strncpy(tmpname, instptr, CDI_MAX_NAME);
	  limit_string_length(tmpname, CDI_MAX_NAME);
	  fprintf(stdout, "%-8s ", tmpname);

	  /* source info */
	  modelptr = modelInqNamePtr(vlistInqVarModel(vlistID, varID));
	  strcpy(tmpname, "unknown");
	  if ( modelptr ) strncpy(tmpname, modelptr, CDI_MAX_NAME);
	  limit_string_length(tmpname, CDI_MAX_NAME);
	  fprintf(stdout, "%-8s ", tmpname);

	  /* tsteptype */
	  tsteptype = vlistInqVarTsteptype(vlistID, varID);
	  if      ( tsteptype == TSTEP_CONSTANT ) fprintf(stdout, "%-8s ", "constant");
	  else if ( tsteptype == TSTEP_INSTANT  ) fprintf(stdout, "%-8s ", "instant");
	  else if ( tsteptype == TSTEP_INSTANT2 ) fprintf(stdout, "%-8s ", "instant");
	  else if ( tsteptype == TSTEP_INSTANT3 ) fprintf(stdout, "%-8s ", "instant");
	  else if ( tsteptype == TSTEP_MIN      ) fprintf(stdout, "%-8s ", "min");
	  else if ( tsteptype == TSTEP_MAX      ) fprintf(stdout, "%-8s ", "max");
	  else if ( tsteptype == TSTEP_AVG      ) fprintf(stdout, "%-8s ", "avg");
	  else if ( tsteptype == TSTEP_ACCUM    ) fprintf(stdout, "%-8s ", "accum");
	  else if ( tsteptype == TSTEP_RANGE    ) fprintf(stdout, "%-8s ", "range");
	  else if ( tsteptype == TSTEP_DIFF     ) fprintf(stdout, "%-8s ", "diff");
	  else                                    fprintf(stdout, "%-8s ", "unknown");

	  /* ensemble information */
	  if ( lensemble )
	    {
	      int ensID, ensCount, forecast_type;
	      if ( vlistInqVarEnsemble(vlistID, varID, &ensID, &ensCount, &forecast_type) )
		fprintf(stdout, "%2d/%-2d ", ensID, ensCount);
	      else
		fprintf(stdout, "--/-- ");
	    }

	  /* layer info */
	  levelsize = zaxisInqSize(zaxisID);
	  fprintf(stdout, "%6d ", levelsize);
	  fprintf(stdout, "%3d ", vlistZaxisIndex(vlistID, zaxisID) + 1);

	  /* grid info */
	  gridsize = gridInqSize(gridID);
	  fprintf(stdout, "%9d ", gridsize);
	  fprintf(stdout, "%3d ", vlistGridIndex(vlistID, gridID) + 1);

	  /* datatype */
	  datatype = vlistInqVarDatatype(vlistID, varID);
	  datatype2str(datatype, pstr);

	  fprintf(stdout, " %-3s", pstr);

	  if ( vlistInqVarCompType(vlistID, varID) == COMPRESS_NONE )
	    fprintf(stdout, "  ");
	  else
	    fprintf(stdout, "z ");

	  reset_text_color(stdout);
	      
	  set_text_color(stdout, RESET, BLACK);
	  fprintf(stdout, ": ");
	  reset_text_color(stdout);

	  /* parameter info */
	  cdiParamToString(param, paramstr, sizeof(paramstr));

	  if ( operfunc == func_name ) vlistInqVarName(vlistID, varID, varname);

	  set_text_color(stdout, BRIGHT, GREEN);
	  if ( operfunc == func_name )
	    fprintf(stdout, "%-14s", varname);
	  else if ( operfunc == func_code )
	    fprintf(stdout, "%4d %4d   ", tabnum, code);
	  else
	    fprintf(stdout, "%-14s", paramstr);
	  reset_text_color(stdout);

	  if ( cdoVerbose )
	    {
	      char varextra[CDI_MAX_NAME];
	      vlistInqVarExtra(vlistID, varID, varextra);
	      fprintf(stdout, " : %s", varextra );              
	    }

	  fprintf(stdout, "\n");
	}

      set_text_color(stdout, BRIGHT, BLACK);
      fprintf(stdout, "   Grid coordinates");
      reset_text_color(stdout);
      fprintf(stdout, " :\n");

      printGridInfo(vlistID);

      set_text_color(stdout, BRIGHT, BLACK);
      fprintf(stdout, "   Vertical coordinates");
      reset_text_color(stdout);
      fprintf(stdout, " :\n");

      printZaxisInfo(vlistID);

      taxisID = vlistInqTaxis(vlistID);
      ntsteps = vlistNtsteps(vlistID);

      if ( ntsteps != 0 )
	{
	  set_text_color(stdout, BRIGHT, BLACK);
	  fprintf(stdout, "   Time coordinate");
	  reset_text_color(stdout);
	  if ( ntsteps == CDI_UNDEFID )
	    fprintf(stdout, " :  unlimited steps\n");
	  else
	    fprintf(stdout, " :  %d step%s\n", ntsteps, ntsteps == 1 ? "" : "s");

	  if ( taxisID != CDI_UNDEFID )
	    {
	      if ( taxisInqType(taxisID) != TAXIS_ABSOLUTE )
		{
		  vdate = taxisInqRdate(taxisID);
		  vtime = taxisInqRtime(taxisID);

		  date2str(vdate, vdatestr, sizeof(vdatestr));
		  time2str(vtime, vtimestr, sizeof(vtimestr));

		  fprintf(stdout, "     RefTime = %s %s", vdatestr, vtimestr);
		      
		  int tunits = taxisInqTunit(taxisID);
		  if ( tunits != CDI_UNDEFID )  fprintf(stdout, "  Units = %s", tunit2str(tunits));
	      
		  int calendar = taxisInqCalendar(taxisID);
		  if ( calendar != CDI_UNDEFID )  fprintf(stdout, "  Calendar = %s", calendar2str(calendar));

		  if ( taxisHasBounds(taxisID) )
		    fprintf(stdout, "  Bounds = true");

		  fprintf(stdout, "\n");

		  if ( taxisInqType(taxisID) == TAXIS_FORECAST )
		    {
		      vdate = taxisInqFdate(taxisID);
		      vtime = taxisInqFtime(taxisID);

		      date2str(vdate, vdatestr, sizeof(vdatestr));
		      time2str(vtime, vtimestr, sizeof(vtimestr));

		      fprintf(stdout, "     ForecastRefTime = %s %s", vdatestr, vtimestr);
		      fprintf(stdout, "\n");
		    }
		}
	    }

	  fprintf(stdout, "  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss\n");

	  set_text_color(stdout, RESET, MAGENTA);

	  printTimesteps(streamID, taxisID, cdoVerbose);

	  reset_text_color(stdout);
	  fprintf(stdout, "\n");
	}

      streamClose(streamID);
    }

  cdoFinish();

  return (0);
}