Ejemplo n.º 1
0
static int
cmd_source(int argc, char **argv)
{
	char *file;
	int rv;

	if (argc < 2) {
			printf("No filename\n");
		return CMD_USAGE;
	}

	file = argv[1];
	rv=command_file(file);
	if (rv == CMD_FAILED) {
			printf("Couldn't read %s\n", file);
	}

	return rv;
}
Ejemplo n.º 2
0
/* start a cli with <name> as a prompt, and optionally run the <initscript> file */
void
enter_cli(const char *name, const char *initscript)
{
	global_logfp = NULL;
	//progname = name;	//we use the supplied *name instead.

	readline_init();
	set_init();

	if (initscript != NULL) {
		int rv=command_file(initscript);
		switch (rv) {
			case CMD_OK:
				/* script was succesful, start a normal CLI afterwards */
				break;
			case CMD_FAILED:
				printf("Problem with file %s\n", initscript);
				// fallthrough, yes
			default:
			case CMD_EXIT:
				set_close();
				return;
		}
	} else {
		/* print banner only if running without an initscript */
		printf("%s: %s version %s\n", name, projname, PACKAGE_VERSION);
		printf("%s: Type HELP for a list of commands\n", name);
		printf("%s: Type SCAN to start ODBII Scan\n", name);
		printf("%s: Then use MONITOR to monitor real-time data\n", name);
		printf("%s: **** IMPORTANT : this is beta software ! Use at your own risk.\n", name);
		printf("%s: **** Remember, \"debug all -1\" displays all debugging info.\n", name);
	}

	if (rc_file() != CMD_EXIT) {
		printf("\n");
		/* And go start CLI */
		instream = stdin;
		(void)do_cli(root_cmd_table, name, 0, NULL);
	}
	set_close();

}
Ejemplo n.º 3
0
bool c_preprocess_visual_studio(
  const std::string &file,
  std::ostream &outstream,
  message_handlert &message_handler)
{
  // check extension
  if(is_dot_i_file(file))
    return c_preprocess_none(file, outstream, message_handler);

  message_streamt message_stream(message_handler);

  // use Visual Studio's CL
  
  std::string stderr_file=get_temporary_file("tmp.stderr", "");
  std::string command_file_name=get_temporary_file("tmp.cl-cmd", "");

  {
    std::ofstream command_file(command_file_name.c_str());

    // This marks the file as UTF-8, which Visual Studio
    // understands.
    command_file << char(0xef) << char(0xbb) << char(0xbf);
  
    command_file << "/nologo" << "\n";
    command_file << "/E" << "\n";
    command_file << "/D__CPROVER__" << "\n";
    command_file << "/D__WORDSIZE=" << config.ansi_c.pointer_width << "\n";

    if(config.ansi_c.pointer_width==64)
    {
      command_file << "\"/D__PTRDIFF_TYPE__=long long int\""  << "\n";
      // yes, both _WIN32 and _WIN64 get defined
      command_file << "/D_WIN64" << "\n";
    }
    else
    {
      command_file << "/D__PTRDIFF_TYPE__=int" << "\n";
      command_file << "/U_WIN64" << "\n";
    }

    if(config.ansi_c.char_is_unsigned)
      command_file << "/J" << "\n"; // This causes _CHAR_UNSIGNED to be defined

    // Standard Defines, ANSI9899 6.10.8
    command_file << "/D__STDC_VERSION__=199901L" << "\n";
    command_file << "/D__STDC_IEC_559__=1" << "\n";
    command_file << "/D__STDC_IEC_559_COMPLEX__=1" << "\n";
    command_file << "/D__STDC_ISO_10646__=1" << "\n";
  
    for(std::list<std::string>::const_iterator
        it=config.ansi_c.defines.begin();
        it!=config.ansi_c.defines.end();
        it++)
      command_file << "/D" << shell_quote(*it) << "\n";

    for(std::list<std::string>::const_iterator
        it=config.ansi_c.include_paths.begin();
        it!=config.ansi_c.include_paths.end();
        it++)
      command_file << "/I" << shell_quote(*it) << "\n";

       for(std::list<std::string>::const_iterator
               it=config.ansi_c.include_files.begin();
               it!=config.ansi_c.include_files.end();
               it++)
         command_file << "/FI" << shell_quote(*it) << "\n";

    // Finally, the file to be preprocessed
    // (this is already in UTF-8).
    command_file << shell_quote(file) << "\n";
  }
  
  std::string tmpi=get_temporary_file("tmp.cl", "");
  
  std::string command="CL @\""+command_file_name+"\"";
  command+=" > \""+tmpi+"\"";
  command+=" 2> \""+stderr_file+"\"";

  // _popen isn't very reliable on WIN32
  // that's why we use system()
  int result=system(command.c_str());

  FILE *stream=fopen(tmpi.c_str(), "r");

  if(stream==NULL)
  {
    unlink(tmpi.c_str());
    unlink(stderr_file.c_str());
    unlink(command_file_name.c_str());
    message_stream.error("CL Preprocessing failed (fopen failed)");
    return true;
  }

  {
    int ch;
    while((ch=fgetc(stream))!=EOF)
      outstream << (unsigned char)ch;
  }

  fclose(stream);
  unlink(tmpi.c_str());
  unlink(command_file_name.c_str());

  // errors/warnings
  {
    std::ifstream stderr_stream(stderr_file.c_str());
    char ch;
    while(stderr_stream.read(&ch, 1))
      message_stream.str << ch;
  }

  unlink(stderr_file.c_str());

  if(result!=0)
  {
    message_stream.error_parse(1);
    message_stream.error("CL Preprocessing failed");
    return true;
  }
  else
    message_stream.error_parse(2);  

  return false;
}
Ejemplo n.º 4
0
//rc_file : returns CMD_OK or CMD_EXIT only.
static int
rc_file(void)
{
	int rv;
	//this loads either a $home/.<progname>.rc or ./<progname>.ini (in order of preference)
	//to load general settings.

	/*
	 * "." files don't play that well on some systems.
	 * USE_RCFILE is not defined by default.
	 */

#ifdef USE_RCFILE
	char *rchomeinit;
	char *homedir;
	homedir = getenv("HOME");
	FILE *newrcfile;

	if (homedir) {
		/* we add "/." and "rc" ... 4 characters */
		if (diag_malloc(&rchomeinit, strlen(homedir) + strlen(progname) + 5)) {
			diag_iseterr(DIAG_ERR_NOMEM);
			return CMD_OK;
		}
		strcpy(rchomeinit, homedir);
		strcat(rchomeinit, "/.");
		strcat(rchomeinit, projname);
		strcat(rchomeinit, "rc");

		rv=command_file(rchomeinit);
		if (rv == CMD_FAILED) {
			fprintf(stderr, FLFMT "Could not load rc file %s; ", FL, rchomeinit);
			newrcfile=fopen(rchomeinit,"a");
			if (newrcfile) {
				//create the file if it didn't exist
				fprintf(newrcfile, "\n#empty rcfile auto created by %s\n",progname);
				fclose(newrcfile);
				fprintf(stderr, "empty file created.\n");
				free(rchomeinit);
				return CMD_OK;
			} else {
				//could not create empty rcfile
				fprintf(stderr, "could not create empty file %s.", rchomeinit);
				free(rchomeinit);
				return CMD_OK;
			}
		} else {
			//command_file was at least partly successful (rc file exists)
			printf("%s: Settings loaded from %s\n",progname,rchomeinit);
			free(rchomeinit);
			return CMD_OK;
		}

	}	//if (homedir)
#endif


#ifdef USE_INIFILE
	char * inihomeinit;
	if (diag_malloc(&inihomeinit, strlen(progname) + strlen(".ini") + 1)) {
		diag_iseterr(DIAG_ERR_NOMEM);
		return CMD_OK;
	}

	strcpy(inihomeinit, progname);
	strcat(inihomeinit, ".ini");

	rv=command_file(inihomeinit);
	if (rv == CMD_FAILED) {
		fprintf(stderr, FLFMT "Problem with %s, no configuration loaded\n", FL, inihomeinit);
		free(inihomeinit);
		return CMD_OK;
	}
	printf("%s: Settings loaded from %s\n", progname, inihomeinit);
	free(inihomeinit);
#endif
	return rv;	//could be CMD_EXIT

}