rospack_backcompat.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008, Willow Garage, Inc., Morgan Quigley
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
29 #include "rospack/rospack.h"
30 #include "rospack_cmdline.h"
31 
32 #include <boost/algorithm/string.hpp>
33 #include <string.h>
34 #include <stdio.h>
35 #include <errno.h>
36 
37 namespace rospack
38 {
39 
40 int
41 ROSPack::run(int argc, char** argv)
42 {
43  // allow caching of results between calls (of same process)
44  static rospack::Rospack rp;
45  output_.clear();
46  bool success = rospack::rospack_run(argc, argv, rp, output_);
47  if(!success)
48  {
49  fprintf(stderr, "[librospack]: error while executing command\n");
50  return 1;
51  }
52  return 0;
53 }
54 
55 int
56 ROSPack::run(const std::string& cmd)
57 {
58  // Callers of this method don't make 'rospack' argv[0].
59  std::string full_cmd = std::string("rospack ") + cmd;
60 
61  int argc;
62  char** argv;
63  std::vector<std::string> full_cmd_split;
64  boost::split(full_cmd_split, full_cmd,
65  boost::is_any_of(" "),
66  boost::token_compress_on);
67  argc = full_cmd_split.size();
68  argv = new char*[argc];
69  int i = 0;
70  for(std::vector<std::string>::const_iterator it = full_cmd_split.begin();
71  it != full_cmd_split.end();
72  ++it)
73  {
74  argv[i] = new char[it->size()+1];
75  memset(argv[i], 0, it->size()+1);
76  memcpy(argv[i], it->c_str(), it->size());
77  i++;
78  }
79 
80  int ret = run(argc, argv);
81 
82  for(int i=0; i<argc; i++)
83  delete[] argv[i];
84  delete[] argv;
85 
86  return ret;
87 }
88 
89 } // namespace rospack
rospack_cmdline.h
rospack::Rospack
Package crawler. Create one of these to operate on a package tree. Call public methods inherited from...
Definition: rospack.h:560
rospack.h
rospack::rospack_run
bool rospack_run(int argc, char **argv, rospack::Rosstackage &rp, std::string &output)
Definition: rospack_cmdline.cpp:49
rospack_backcompat.h
rospack
Definition: rospack.h:123
rospack::ROSPack::run
int run(int argc, char **argv)
Run rospack with the given arguments. Call getOutput() to get the result.
Definition: rospack_backcompat.cpp:41
rospack::ROSPack::output_
std::string output_
Definition: rospack_backcompat.h:45


rospack
Author(s): Brian Gerkey, Morgan Quigley, Dirk Thomas
autogenerated on Wed Mar 2 2022 00:54:50