/* This program is free software. It comes without any warranty, to
 * the extent permitted by applicable law. You can redistribute it
 * and/or modify it under the terms of the Do What The Fuck You Want
 * To Public License, Version 2, as published by Sam Hocevar. See
 * http://sam.zoy.org/wtfpl/COPYING for more details. */ 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main (int argc, char *argv[])
{
    if(argc <= 1)
    {
        printf("Type %s -h for help.\n", argv[0]);
        return 0;
    }
    if(argc >= 2)
    {
        if((!strcmp(argv[1], "-h"))
        || (!strcmp(argv[1], "-help"))
        || (!strcmp(argv[1], "-?")))
        {
            printf("my_del v0.1 by Cafe-Alpha.\n");
            printf("Delete specified files, even if their pathes contain slashes instead of backslashes.\n");
            printf("Usage : %s [-verbose] <file1> <file2> ...\n", argv[0]);
            return 0;
        }
    }

    int verbose = 0;
    int i;

    // Parse arguments
    for(i=1; i<argc; i++)
    {
        if(argv[i][0] == '-')
        { /* Parameter */
            if(!strcmp(argv[i], "-verbose"))
            {
                verbose = 1;
            }
        }
        else
        { /* File to delete. */
            char* file = argv[i];
            if(verbose)
            {
                printf("Delete file \"%s\" ...", file);
            }
            int ret = unlink(file);
            if(verbose)
            {
                if(ret == 0)
                {
                    printf(" Delete success !\n");
                }
                else
                {
                    printf(" Delete failed ! ret = %d, errno = %d.\n", ret, errno);
                }
            }
        }
    }

    return 0;
}



