Subversion Repositories HelenOS

Rev

Rev 3311 | Rev 3346 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3311 post 1
/* Automatically generated by mknewcmd on Wed Aug 13 15:41:09 PHT 2008
3277 post 2
 * This is machine generated output. The author of mknewcmd claims no
3
 * copyright over the contents of this file. Where legally permitted, the
4
 * contents herein are donated to the public domain.
5
 *
6
 * You should apply any license and copyright that you wish to this file,
7
 * replacing this header in its entirety. */
8
 
9
#include <stdio.h>
10
#include <stdlib.h>
3319 post 11
#include <getopt.h>
12
 
3311 post 13
#include "config.h"
14
#include "util.h"
15
#include "errors.h"
3277 post 16
#include "entry.h"
17
#include "cat.h"
18
#include "cmds.h"
19
 
20
static char *cmdname = "cat";
21
 
3319 post 22
static struct option long_options[] = {
23
    { "help",       no_argument,        0,  'h' },
24
    { "version",    no_argument,        0,  'v' },
25
    { "file",       required_argument,  0,  'f' },
26
    { 0, 0, 0, 0 }
27
};
28
 
3277 post 29
/* Dispays help for cat in various levels */
30
void * help_cmd_cat(unsigned int level)
31
{
32
    printf("This is the %s help for '%s'.\n",
33
        level ? EXT_HELP : SHORT_HELP, cmdname);
3311 post 34
    return CMD_VOID;
3277 post 35
}
36
 
37
/* Main entry point for cat, accepts an array of arguments */
38
int * cmd_cat(char **argv)
39
{
40
    unsigned int argc;
41
    unsigned int i;
3319 post 42
    int c, opt_ind;
3277 post 43
 
44
    /* Count the arguments */
45
    for (argc = 0; argv[argc] != NULL; argc ++);
46
 
47
    printf("%s %s\n", TEST_ANNOUNCE, cmdname);
3319 post 48
    printf("%d arguments passed to %s\n", argc - 1, cmdname);
3277 post 49
 
50
    for (i = 1; i < argc; i++)
51
        printf("[%d] -> %s\n", i, argv[i]);
52
 
3319 post 53
    for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
54
        c = getopt_long(argc, argv, "f:hv", long_options, &opt_ind);
55
        switch (c) {
56
        case 'h':
57
            help_cmd_cat(HELP_SHORT);
58
            break;
59
        case 'v':
60
            printf("I have no version, sorry.\n");
61
            break;
62
        case 'f':
63
            printf("File : %s\n", optarg);
64
            break;
65
        }
66
    }
67
 
68
    printf("argc = %d, optind = %d\n", argc, optind);
69
 
3311 post 70
    return CMD_SUCCESS;
3277 post 71
}
72