Skip to content

Instantly share code, notes, and snippets.

@mattdenner
Created February 27, 2010 16:50
Show Gist options
  • Save mattdenner/316815 to your computer and use it in GitHub Desktop.
Save mattdenner/316815 to your computer and use it in GitHub Desktop.
/*
* Do a path search. The variable path (passed by reference) should be
* set to the start of the path before the first call; padvance will update
* this value as it proceeds. Successive calls to padvance will return
* the possible path expansions in sequence. If an option (indicated by
* a percent sign) appears in the path entry then the global variable
* pathopt will be set to point to it; otherwise pathopt will be set to
* NULL.
*/
const char *pathopt;
char *
padvance(const char **path, const char *name)
{
const char *p;
char *q;
const char *start;
size_t len;
if (*path == NULL)
return NULL;
start = *path;
for (p = start ; *p && *p != ':' && *p != '%' ; p++);
len = p - start + strlen(name) + 2; /* "2" is for '/' and '\0' */
while (stackblocksize() < len)
growstackblock();
q = stackblock();
if (p != start) {
memcpy(q, start, p - start);
q += p - start;
*q++ = '/';
}
strcpy(q, name);
pathopt = NULL;
if (*p == '%') {
pathopt = ++p;
while (*p && *p != ':') p++;
}
if (*p == ':')
*path = p + 1;
else
*path = NULL;
return stalloc(len);
}
$ rake metrics:all
(in /home/matt/brute_force_capatcha)
saikuro --filter_cyclo 0 --warn_cyclo 5 --error_cyclo 7 --output_directory tmp/metric_fu/scratch/saikuro --formater text --input_directory "lib" --cyclo
sh: saikuro: not found
Saikuro failed with exit status: 127
matt $ echo $PATH
/home/matt/.rvm/rubies/ruby-1.8.7-p249/bin:/home/matt/.rvm/gems/ruby-1.8.7-p249%image/bin:/home/matt/.rvm/gems/ruby-1.8.7-p249%global/bin:/home/matt/.rvm/bin:/home/matt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/gems/1.8/bin:~/bin
matt $ which saikuro
/home/matt/.rvm/gems/ruby-1.8.7-p249%global/bin/saikuro
matt $ saikuro --filter_cyclo 0 --warn_cyclo 5 --error_cyclo 7 --output_directory tmp/metric_fu/scratch/saikuro --formater text --input_directory "lib" --cyclo
Parsing lib/live_sets_us/mini_magick_ext.rb
Parsing lib/live_sets_us/content_downloader.rb
Parsing lib/live_sets_us/template_image_extractor.rb
Parsing lib/live_sets_us/processor.rb
Parsing lib/live_sets_us.rb
matt $ which sh
/bin/sh
matt $ ls -l /bin/sh
lrwxrwxrwx 1 root root 9 2010-02-28 12:03 /bin/sh -> /bin/dash
matt $ sh
$ export PATH=/home/matt/.rvm/rubies/ruby-1.8.7-p249/bin:/home/matt/.rvm/gems/ruby-1.8.7-p249%image/bin:/home/matt/.rvm/gems/ruby-1.8.7-p249%global/bin:/home/matt/.rvm/bin:/home/matt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/gems/1.8/bin:~/bin
$ echo $PATH
/home/matt/.rvm/rubies/ruby-1.8.7-p249/bin:/home/matt/.rvm/gems/ruby-1.8.7-p249%image/bin:/home/matt/.rvm/gems/ruby-1.8.7-p249%global/bin:/home/matt/.rvm/bin:/home/matt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/gems/1.8/bin:~/bin
$ which saikuro
/home/matt/.rvm/gems/ruby-1.8.7-p249%global/bin/saikuro
$ saikuro
sh: saikuro: not found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment