Exemplo n.º 1
0
 void
addfunc_ASL(const char *fname, ufunc *f, int ftype, int nargs, void *funcinfo, AmplExports *ae)
{
	register func_info *fi;
	ASL *asl = (ASL*)ae->asl;
	if (ftype && ftype != 1) {
#ifndef COMPLAIN_AT_BAD_FTYPE
		if (ftype < 0 || ftype > 6)
#endif
		{
		fprintf(Stderr, "function %s: ftype = %d; expected 0 or 1\n",
			fname, ftype);
		exit(1);
		}
#ifndef COMPLAIN_AT_BAD_FTYPE
		return;
#endif
		}
	if ((fi = func_lookup(asl, fname, 1))) {
		n_added++;
		fi->funcp = f;
		fi->ftype = ftype;
		fi->nargs = nargs;
		fi->funcinfo = funcinfo;
		if (!funcsfirst)
			funcsfirst = fi;
		else
			funcslast->fnext = fi;
		funcslast = fi;
		fi->fnext = 0;
		}
	}
Exemplo n.º 2
0
int main (int argc, char *argv[])
{
    flux_t h = NULL;
    int ch;
    char *cmd;
    func_t *f;
    opt_t opt = {
        .fanout = 1024,
        .nodeset = NULL,
    };

    log_init ("flux-module");

    if (argc < 2)
        usage ();
    cmd = argv[1];
    argc--;
    argv++;

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'h': /* --help */
                usage ();
                break;
            case 'r': /* --rank=[nodeset|all] */
                if (opt.nodeset)
                    free (opt.nodeset);
                opt.nodeset = xstrdup (optarg);
                break;
            case 'd': /* --direct */
                opt.direct = true;
                break;
            case 'f': /* --fanout */
                opt.fanout = strtoul (optarg, NULL, 10);
                break;
            default:
                usage ();
                break;
        }
    }
    opt.argc = argc - optind;
    opt.argv = argv + optind;

    if (!(f = func_lookup (cmd)))
        msg_exit ("unknown function '%s'", cmd);

    if (strcmp (cmd, "info") != 0) {
        if (!(h = flux_open (NULL, 0)))
            err_exit ("flux_open");
        if (!opt.nodeset) {
            opt.nodeset = xasprintf ("%d", flux_rank (h));
        } else if (!strcmp (opt.nodeset, "all") && flux_size (h) == 1) {
            free (opt.nodeset);
            opt.nodeset= xasprintf ("%d", flux_rank (h));
        } else if (!strcmp (opt.nodeset, "all")) {
            free (opt.nodeset);
            opt.nodeset = xasprintf ("[0-%d]", flux_size (h) - 1);
        }
    }

    f->fun (h, opt);

    if (opt.nodeset)
        free (opt.nodeset);
    if (h)
        flux_close (h);

    log_fini ();
    return 0;
}

char *sha1 (const char *path)
{
    zfile_t *zf = zfile_new (NULL, path);
    char *digest = NULL;
    if (zf)
        digest = xstrdup (zfile_digest (zf));
    zfile_destroy (&zf);
    return digest;
}