示例#1
0
文件: sort.c 项目: jeromekelleher/gqt
int sort(int argc, char **argv)
{
    if (argc < 2) return sort_help();

    int c;
    char *in, *out;
    uint32_t num_fields, num_records;
    int i_is_set = 0, 
        o_is_set = 0; 

    while ((c = getopt (argc, argv, "hi:o:")) != -1) {
        switch (c) {
            case 'i':
                i_is_set = 1;
                in = optarg;
                break;
            case 'o':
                o_is_set = 1;
                out = optarg;
                break;
            case 'h':
                sort_help();
                return 1;
            case '?':
                if ( (optopt == 'i') || 
                     (optopt == 'o') )
                    fprintf (stderr, "Option -%c requires an argument.\n",
                            optopt);
                else if (isprint (optopt))
                    fprintf (stderr, "Unknown option `-%c'.\n", optopt);
                else
                fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
            default:
                sort_help();
                return 1;
        }
    }

    char *type = argv[0];

    if (i_is_set == 0) {
        printf("Input file is not set\n");
        return sort_help();
    } 
    if (o_is_set == 0) {
        printf("Output file is not set\n");
        return sort_help();
    }

    if (strcmp(type, "plt-field-freq") == 0)  return plt_field_freq(in, out);

    return 1;
}
示例#2
0
文件: glue.c 项目: Oxyoptia/x3270
/* Disply command-line help. */
void
cmdline_help (bool as_action)
{
    unsigned i;
    
    sort_help();
    for (i = 0; i < sorted_help_count; i++) {
	char *h = sorted_help[i].help_opts;
	char *ht;
	char *hx = NULL;
	char *star;

	if (sorted_help[i].type == OPT_XRM &&
		h != NULL && (star = strchr(h, '*')) != NULL) {
	    ht = hx = xs_buffer("%.*s%s%s", (int)(star - h), h, app,
		    star + 1);
	} else {
	    ht = h;
	}

	if (as_action) {
	    action_output("  %s%s%s",
		    sorted_help[i].name,
		    ht? " ": "",
		    ht? ht: "");
	    action_output("    %s", sorted_help[i].help_text);
	} else {
	    fprintf(stderr, "  %s%s%s\n     %s\n",
		    sorted_help[i].name,
		    ht? " ": "",
		    ht? ht: "",
		    sorted_help[i].help_text);
	}
	if (hx != NULL) {
	    Free(hx);
	}
    }
}