Here is my code:
/*
* main.c
*
* Created on: 15 Oct 2010
* Author: mohit
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/dir.h>
#include <sys/unistd.h>
void print_usage();
int main(int argc, char *argv[])
{
int i;
char *directory;
char *name;
//Iterate through command line arguments
for (i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--directory"))
{
memcpy(directory, argv[i + 1], sizeof (argv[i + 1]));
continue;
}
else if (!strcmp(argv[i], "-n") || !strcmp(argv[i], "--name"))
{
memcpy(name, argv[i + 1], sizeof (argv[i + 1]));
continue;
}
}
if (!name)
{
perror("\n\nIncorrect Usage! Name was not provided!\n\n");
print_usage();
}
if (directory)
chdir(directory);
printf("\nCreating %s.theme directory...\n", name);
mkdir(strcat(name, ".theme"), "a+rw");
printf("Created %s.theme...\n", name);
printf("Entering %s.theme...\n", name);
chdir(strcat(name, ".theme"));
printf("Creating Icons directory...\n");
mkdir("Icons", "a+rw");
printf("Created Icons...\n");
printf("Creating Bundles directory...\n");
mkdir("Bundles", "a+rw");
printf("Created Bundles...\n");
printf("Creating UIImages directory...\n");
mkdir("UIImages", "a+rw");
printf("Created UIImages...\n");
printf("Creating Folder directory...\n");
mkdir("Folder", "a+rw");
printf("Created Folder...\n");
return 0;
}
void print_usage()
{
printf("\n\nUsage: wbt-create [--directory directory] --name theme_name\n");
printf("\n\n\t wbt-create [-d directory] -n theme_name\n");
}