Skip to content

Instantly share code, notes, and snippets.

@gcmurphy
Created April 24, 2012 04:36
Show Gist options
  • Save gcmurphy/2476467 to your computer and use it in GitHub Desktop.
Save gcmurphy/2476467 to your computer and use it in GitHub Desktop.
Java classpath maker. I don't think this is needed in Java > 6 or if you have proper manifest.
#include <stdio.h>
#include <stdlib.h>
#include <talloc.h>
#include <dirent.h>
#include <regex.h>
int main(int argc, char *argv[])
{
int arg;
regex_t pattern;
DIR *dir = NULL;
struct dirent *entry = NULL;
char *cp = NULL, *base = NULL;
if (argc <= 1){
fprintf(stderr, "Usage: %s <directory> [directories...]\n", argv[0]);
exit(1);
}
if (regcomp(&pattern, ".*\\.jar", 0)){
fprintf(stderr, "Error: Invalid regular expression\n");
exit(1);
}
for(arg = 1; arg < argc; ++arg){
dir = opendir(argv[arg]);
if (! dir){
perror("Error: ");
regfree(&pattern);
exit(1);
}
while((entry = readdir(dir)) != NULL){
if (! regexec(&pattern, entry->d_name, 0, NULL, 0)){
if (!cp){
cp = talloc_strdup(NULL, argv[arg]);
cp = talloc_asprintf_append(cp, "/%s", entry->d_name);
} else {
cp = talloc_asprintf_append(cp,
":%s/%s", argv[arg], entry->d_name);
}
}
}
closedir(dir);
dir = NULL;
if (cp){
printf("%s", cp);
talloc_free(cp);
cp = NULL;
}
if (arg+1 < argc)
printf(":");
}
regfree(&pattern);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment