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
bool rospack_run(int argc, char **argv, rospack::Rosstackage &rp, std::string &output)
Package crawler. Create one of these to operate on a package tree. Call public methods inherited from...
Definition: rospack.h:560
int run(int argc, char **argv)
Run rospack with the given arguments. Call getOutput() to get the result.


rospack
Author(s): Brian Gerkey, Morgan Quigley, Dirk Thomas
autogenerated on Mon Feb 28 2022 23:32:59