Esempio n. 1
1
int
main(int argc, char *argv[], void *extra)
{
	register int n;
	register char *cp;
	char *delim  = "#";
	int width = 80;

	NoP(argc);
	NoP(extra);
	error_info.id = "banner";
	while (n = optget(argv, usage)) switch (n)
	{
	case 'd':
		delim = opt_info.arg;
		break;
	case 'w':
		width = opt_info.num; 
		break;
	case ':':
		error(2, "%s", opt_info.arg);
		break;
	case '?':
		error(ERROR_usage(2), "%s", opt_info.arg);
		break;
	}
	argv += opt_info.index;
	if(error_info.errors || !*argv)
		error(ERROR_usage(2), "%s", optusage((char*)0));
	sfset(sfstdout,SF_LINE,0);
	while(cp = *argv++)
		banner(cp,delim,width);
	exit(0);
}
Esempio n. 2
0
int	b_return(register int n, register char *argv[],Shbltin_t *context)
{
	register char *arg;
	register Shell_t *shp = context->shp;
	struct checkpt *pp = (struct checkpt*)shp->jmplist;
	const char *options = (**argv=='r'?sh_optreturn:sh_optexit);
	while((n = optget(argv,options))) switch(n)
	{
	    case ':':
		if(!strmatch(argv[opt_info.index],"[+-]+([0-9])"))
			errormsg(SH_DICT,2, "%s", opt_info.arg);
		goto done;
	    case '?':
		errormsg(SH_DICT,ERROR_usage(0), "%s", opt_info.arg);
		return(2);
	}
done:
	if(error_info.errors)
		errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
	pp->mode = (**argv=='e'?SH_JMPEXIT:SH_JMPFUN);
	argv += opt_info.index;
	n = (((arg= *argv)?(int)strtol(arg, (char**)0, 10):shp->oldexit));
	if(n<0 || n==256 || n > SH_EXITMASK+shp->gd->sigmax)
			n &= ((unsigned int)n)&SH_EXITMASK;
	/* return outside of function, dotscript and profile is exit */
	if(shp->fn_depth==0 && shp->dot_depth==0 && !sh_isstate(shp,SH_PROFILE))
		pp->mode = SH_JMPEXIT;
	sh_exit(shp,shp->savexit=n);
	return(1);
}
Esempio n. 3
0
main(int argc, char** argv)
{
	register int	c;
	struct mam*	mp;

	NoP(argc);
	error_info.id = "mamtst";
	while (c = optget(argv, "d#[debug]")) switch (c)
	{
	case 'd':
		error_info.trace = -opt_info.num;
		break;
	case '?':
		error(ERROR_USAGE|4, opt_info.arg);
		break;
	case ':':
		error(2, opt_info.arg);
		break;
	}
	if (error_info.errors) error(ERROR_USAGE|4, "%s", optusage(NiL));
	if (!(mp = mamalloc()))
		error(3, "cannot initialize");
	if (mamscan(mp, NiL) < 0)
		error(3, "invalid input");
	dumpproc(mp->main);
	exit(error_info.errors != 0);
}
Esempio n. 4
0
File: LOG.c Progetto: molmol178/cv
int main(int argc, char *argv[])
{
  image input, output;
  char *input_name;
  char *output_name;
  double sigma;

  OPTION_SETUP(option);

  if (argc == 1) optusage(1);
  if (optspecified("help")) optmanual(1);

  input_name  = optvalue("input");
  output_name = optvalue("output");
  sigma = optvaluefloat("sigma");

  input = Image.createFromFilename("INPUT", input_name);
  output  = Image.create("LOG");

  if (input == 0)
    {
      fprintf(stderr, "output:can't open file %s\n", input_name);
      exit(-1);
    }

  LOG_filter(output, input, sigma);
  Image.save(output, output_name, "LOG");

  Image.destroy(input);
  Image.destroy(output);

  return 0;
}
Esempio n. 5
0
int	b_break(register int n, register char *argv[],Shbltin_t *context)
{
	char *arg;
	register int cont= **argv=='c';
	register Shell_t *shp = context->shp;
	while((n = optget(argv,cont?sh_optcont:sh_optbreak))) switch(n)
	{
	    case ':':
		errormsg(SH_DICT,2, "%s", opt_info.arg);
		break;
	    case '?':
		errormsg(SH_DICT,ERROR_usage(0), "%s", opt_info.arg);
		return(2);
	}
	if(error_info.errors)
		errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
	argv += opt_info.index;
	n=1;
	if(arg= *argv)
	{
		n = (int)strtol(arg,&arg,10);
		if(n<=0 || *arg)
			errormsg(SH_DICT,ERROR_exit(1),e_nolabels,*argv);
	}
	if(shp->st.loopcnt)
	{
		shp->st.execbrk = shp->st.breakcnt = n;
		if(shp->st.breakcnt > shp->st.loopcnt)
			shp->st.breakcnt = shp->st.loopcnt;
		if(cont)
			shp->st.breakcnt = -shp->st.breakcnt;
	}
	return(0);
}
Esempio n. 6
0
int    b_exec(int argc,char *argv[], void *extra)
{
	struct login logdata;
	register int n;
	logdata.clear = 0;
	logdata.arg0 = 0;
	logdata.sh = ((Shbltin_t*)extra)->shp;
        logdata.sh->st.ioset = 0;
	while (n = optget(argv, sh_optexec)) switch (n)
	{
	    case 'a':
		logdata.arg0 = opt_info.arg;
		argc = 0;
		break;
	    case 'c':
		logdata.clear=1;
		break;
	    case ':':
		errormsg(SH_DICT,2, "%s", opt_info.arg);
		break;
	    case '?':
		errormsg(SH_DICT,ERROR_usage(0), "%s", opt_info.arg);
		return(2);
	}
	argv += opt_info.index;
	if(error_info.errors)
		errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
	if(*argv)
                B_login(0,argv,(void*)&logdata);
	return(0);
}
Esempio n. 7
0
int
b_sync(int argc, char** argv, Shbltin_t* context)
{
	cmdinit(argc, argv, context, ERROR_CATALOG, 0);
	for (;;)
	{
		switch (optget(argv, usage))
		{
		case ':':
			error(2, "%s", opt_info.arg);
			break;
		case '?':
			error(ERROR_usage(2), "%s", opt_info.arg);
			break;
		}
		break;
	}
	argv += opt_info.index;
	if (error_info.errors || *argv)
		error(ERROR_usage(2), "%s", optusage(NiL));
#if _lib_sync
	sync();
#else
	error(ERROR_usage(2), "failed -- the native system does not provide a sync(2) call");
#endif
	return 0;
}
Esempio n. 8
0
File: misc.c Progetto: att/ast
int b_let(int argc, char *argv[], Shbltin_t *context) {
    int r;
    char *arg;
    Shell_t *shp = context->shp;
    UNUSED(argc);

    while ((r = optget(argv, sh_optlet))) {
        switch (r) {
            case ':': {
                errormsg(SH_DICT, 2, "%s", opt_info.arg);
                break;
            }
            case '?': {
                errormsg(SH_DICT, ERROR_usage(2), "%s", opt_info.arg);
                __builtin_unreachable();
            }
            default: { break; }
        }
    }

    argv += opt_info.index;
    if (error_info.errors || !*argv) {
        errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
        __builtin_unreachable();
    }
    while ((arg = *argv++)) r = !sh_arith(shp, arg);
    return r;
}
Esempio n. 9
0
int
b_logname(int argc, char** argv, void* context)
{
	register char*	logname;

	cmdinit(argc, argv, context, ERROR_CATALOG, 0);
	for (;;)
	{
		switch (optget(argv, usage))
		{
		case ':':
			error(2, "%s", opt_info.arg);
			continue;
		case '?':
			error(ERROR_usage(2), "%s", opt_info.arg);
			continue;
		}
		break;
	}
	if (error_info.errors)
		error(ERROR_usage(2), "%s", optusage(NiL));
	if (!(logname = getlogin()))
		logname = fmtuid(getuid());
	sfputr(sfstdout, logname, '\n');
	return 0;
}
Esempio n. 10
0
File: ldd.c Progetto: braincat/uwin
int b_ldd(int argc, char** argv)
{
	int		n;
	char*		cp;

	SetErrorMode(SEM_NOGPFAULTERRORBOX);
	cmdinit(argc, argv, 0, 0, 0);
	for (;;)
	{
		switch (optget(argv, usage))
		{
		case '?':
			error(ERROR_usage(2), "%s", opt_info.arg);
			continue;
		case ':':
			error(2, "%s", opt_info.arg);
			continue;
		}
		break;
	}
	argv += opt_info.index;
	argc -= opt_info.index;
	if (error_info.errors || !*argv)
		error(ERROR_usage(2), "%s", optusage((char*)0));
	n = 0;
	while (cp = *argv++)
	{
		if (argc > 1)
			sfprintf(sfstdout, "%s:\n", cp);
		if (doldd(cp) < 0)
			n = 1;
	}
	return n;
}
Esempio n. 11
0
File: misc.c Progetto: att/ast
//
// Builtin `wait`.
//
int b_wait(int n, char *argv[], Shbltin_t *context) {
    Shell_t *shp = context->shp;
    while ((n = optget(argv, sh_optwait))) {
        switch (n) {
            case ':': {
                errormsg(SH_DICT, 2, "%s", opt_info.arg);
                break;
            }
            case '?': {
                errormsg(SH_DICT, ERROR_usage(2), "%s", opt_info.arg);
                __builtin_unreachable();
            }
            default: { break; }
        }
    }

    if (error_info.errors) {
        errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
        __builtin_unreachable();
    }

    argv += opt_info.index;
    job_bwait(argv);
    return shp->exitval;
}
Esempio n. 12
0
File: misc.c Progetto: att/ast
//
// Builtin `shift`.
//
int b_shift(int n, char *argv[], Shbltin_t *context) {
    char *arg;
    Shell_t *shp = context->shp;
    while ((n = optget(argv, sh_optshift))) {
        switch (n) {
            case ':': {
                errormsg(SH_DICT, 2, "%s", opt_info.arg);
                break;
            }
            case '?': {
                errormsg(SH_DICT, ERROR_usage(0), "%s", opt_info.arg);
                return 2;
            }
            default: { break; }
        }
    }

    if (error_info.errors) {
        errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
        __builtin_unreachable();
    }

    argv += opt_info.index;
    n = ((arg = *argv) ? (int)sh_arith(shp, arg) : 1);
    if (n < 0 || shp->st.dolc < n) {
        errormsg(SH_DICT, ERROR_exit(1), e_number, arg);
        __builtin_unreachable();
    } else {
        shp->st.dolv += n;
        shp->st.dolc -= n;
    }
    return 0;
}
Esempio n. 13
0
File: misc.c Progetto: att/ast
int b_eval(int argc, char *argv[], Shbltin_t *context) {
    int r;
    Shell_t *shp = context->shp;
    UNUSED(argc);

    while ((r = optget(argv, sh_opteval))) {
        switch (r) {
            case ':': {
                errormsg(SH_DICT, 2, "%s", opt_info.arg);
                break;
            }
            case '?': {
                errormsg(SH_DICT, ERROR_usage(0), "%s", opt_info.arg);
                return 2;
            }
            default: { break; }
        }
    }

    if (error_info.errors) {
        errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
        __builtin_unreachable();
    }
    argv += opt_info.index;
    if (*argv && **argv) {
        sh_offstate(shp, SH_MONITOR);
        sh_eval(shp, sh_sfeval((const char **)argv), 0);
    }
    return shp->exitval;
}
Esempio n. 14
0
int
main(int argc, char** argv)
{
	register char*		s;
	register Sfio_t*	sp;

	unsigned long		n;
	int			summary = 0;
	unsigned long		total = 0;
	int			trailer;

	NoP(argc);
	error_info.id = "ncsl";
	for (;;)
	{
		switch (optget(argv, usage))
		{
		case 0:
			break;
		case 's':
			summary = 1;
			continue;
		case '?':
			error(ERROR_USAGE|4, "%s", opt_info.arg);
			continue;
		case ':':
			error(2, "%s", opt_info.arg);
			continue;
		}
		break;
	}
	argv += opt_info.index;
	if (error_info.errors)
		error(ERROR_USAGE|4, "%s", optusage(NiL));
	if (*argv)
	{
		trailer = *(argv + 1) != 0;
		while (s = *argv++)
		{
			if (!(sp = sfopen(NiL, s, "r")))
				error(2, "%s: cannot open for reading", s);
			else
			{
				n = ncsl(sp);
				sfclose(sp);
				if (!summary)
					sfprintf(sfstdout, "%s: %lu\n", s, n);
				total += n;
			}
		}
		if (summary || trailer)
			sfprintf(sfstdout, "%lu\n", total);
	}
	else
		sfprintf(sfstdout, "%d\n", ncsl(sfstdin));
	return error_info.errors != 0;
}
Esempio n. 15
0
int
b_comm(int argc, char *argv[], Shbltin_t* context)
{
	register int mode = C_FILE1|C_FILE2|C_COMMON;
	register char *cp;
	Sfio_t *f1, *f2;

	cmdinit(argc, argv, context, ERROR_CATALOG, 0);
	for (;;)
	{
		switch (optget(argv, usage))
		{
 		case '1':
			mode &= ~C_FILE1;
			continue;
		case '2':
			mode &= ~C_FILE2;
			continue;
		case '3':
			mode &= ~C_COMMON;
			continue;
		case ':':
			error(2, "%s",opt_info.arg);
			break;
		case '?':
			error(ERROR_usage(2), "%s",opt_info.arg);
			break;
		}
		break;
	}
	argv += opt_info.index;
	argc -= opt_info.index;
	if(error_info.errors || argc!=2)
		error(ERROR_usage(2),"%s",optusage(NiL));
	cp = *argv++;
	if(streq(cp,"-"))
		f1 = sfstdin;
	else if(!(f1 = sfopen(NiL, cp,"r")))
		error(ERROR_system(1),"%s: cannot open",cp);
	cp = *argv;
	if(streq(cp,"-"))
		f2 = sfstdin;
	else if(!(f2 = sfopen(NiL, cp,"r")))
		error(ERROR_system(1),"%s: cannot open",cp);
	if(mode)
	{
		if(comm(f1,f2,sfstdout,mode) < 0)
			error(ERROR_system(1)," write error");
	}
	else if(f1==sfstdin || f2==sfstdin)
		sfseek(sfstdin,(Sfoff_t)0,SEEK_END);
	if(f1!=sfstdin)
		sfclose(f1);
	if(f2!=sfstdin)
		sfclose(f2);
	return error_info.errors;
}
Esempio n. 16
0
int
main(int argc, char** argv)
{
	Css_t*		css;
	Cssfd_t*	fp;
	Connection_t*	con;
	char*		e;
	State_t		state;

	NoP(argc);
	error_info.id = "css";
	memset(&state, 0, sizeof(state));
	state.disc.version = CSS_VERSION;
	state.disc.flags = CSS_DAEMON|CSS_ERROR|CSS_INTERRUPT;
	state.disc.acceptf = acceptf;
	state.disc.actionf = actionf;
	state.disc.errorf = errorf;
	state.disc.exceptf = exceptf;
	for (;;)
	{
		switch (optget(argv, usage))
		{
		case 't':
			state.disc.timeout = strelapsed(opt_info.arg, &e, 1);
			if (*e)
				error(3, "%s: invalid timeout value", opt_info.arg);
			state.disc.flags |= CSS_DORMANT;
			continue;
		case '?':
			error(ERROR_USAGE|4, "%s", opt_info.arg);
			continue;
		case ':':
			error(2, "%s", opt_info.arg);
			continue;
		}
		break;
	}
	argv += opt_info.index;
	if (!argv[0] || !argv[1])
		error(ERROR_USAGE|4, "%s", optusage(NiL));
	if (!(state.tmp = sfstropen()))
		error(ERROR_SYSTEM|3, "out of space [tmp stream]");
	if (!(state.proc = procopen(argv[1], argv + 1, NiL, NiL, PROC_READ|PROC_WRITE)))
		error(ERROR_SYSTEM|3, "%s: cannot execute", argv[1]);
	if (!(css = cssopen(argv[0], &state.disc)))
		return 1;
	if (!(fp = cssfd(css, state.proc->rfd, CS_POLL_READ)))
		error(ERROR_SYSTEM|3, "%s: cannot poll output", argv[1]);
	if (!(con = newof(0, Connection_t, 1, 0)))
		error(ERROR_SYSTEM|3, "out of space");
	fp->data = con;
	con->service = 1;
	csspoll(CS_NEVER, 0);
	return 1;
}
Esempio n. 17
0
/*========================================================================*
 * メイン
 *========================================================================*/
int main(int argc, char *argv[])
{
    char *name_of_input;
    char *name_of_label;
    image input, label;
    float times;

    OPTION_SETUP(option);
    if (optspecified("help")) optmanual(1);
    if (argc == 1) optusage(1);

    /* オプションの読みとり */
    name_of_input = optvalue("input");
    name_of_label = optvalue("label");
    times = optvaluefloat("times");

    /* 原画像の読み込み */
    input = Image.createFromFilename("Input", name_of_input);
    if (input == 0)
    {
        fprintf(stderr, "cannot open file %s\n", name_of_input);
        exit(-1);
    }
    /* 型チェック */
    if ((__TYPE(input) != Short) && (__TYPE(input) != UChar))
    {
        fprintf(stderr, "wrong image type of the image %s\n", name_of_input);
        exit(-1);
    }

    label = Image.createFromFilename("Label", name_of_label);
    if (label == 0)
    {
        fprintf(stderr, "cannot open file %s\n", name_of_label);
        exit(-1);
    }
    /* 型チェック */
    if ((__TYPE(label) != Short) && (__TYPE(label) != UChar))
    {
        fprintf(stderr, "wrong image type of the image %s\n", name_of_label);
        exit(-1);
    }

    /* エッジ特徴を求める */
    fprintf(stderr, "画像の比較…\n");
    if (__TYPE(input) == UChar)
        image__compare_uchar(input, label, times);
    else
        image__compare_short(input, label);

    Image.destroy(input);
    Image.destroy(label);

    return 0;
}
Esempio n. 18
0
int b_unixpath(int argc, char *argv[], void *context)
{
	int		flags = UWIN_W2U;
	int		quote = 0;
	int		n;
	char*		cp;
	const char*	dp;
	char		buff[PATH_MAX+1];

	NoP(argc);
#if _AST_VERSION >= 20060701L
	cmdinit(argc, argv, context, NULL, 0);
#else
	cmdinit(argv, context, NULL, 0);
#endif
	while (n = optget(argv, usage)) switch (n)
	{
	case 'a':
		flags |= UWIN_U2W;
		break;
	case 'q':
		quote = 1;
		break;
	case ':':
		error(2, "%s", opt_info.arg);
		break;
	case '?':
		error(ERROR_usage(2), "%s", opt_info.arg);
		break;
	}
	argv += opt_info.index;
	if(!*argv || error_info.errors)
		error(ERROR_usage(2),"%s",optusage(NiL));
	while(cp = *argv++)
	{
		uwin_pathmap(cp, buff, sizeof(buff), flags);
		if(quote) 
		{
			for(dp=special;*dp;dp++)
			{
				if(strchr(buff, *dp))
					break;
			}
			if(*dp)
			{
				sfprintf(sfstdout,"'%s'\n",buff);
				continue;
			}
		}
		sfprintf(sfstdout,"%s\n",buff);
	}
	return(0);
}
Esempio n. 19
0
int main(int argc, char** argv)
{
	int			status;
	pid_t			pid;
	struct spawndata	proc;
	char			cmd[PATH_MAX];
	char			*name;
	int			fd;

	if(name=strrchr(argv[0],'/'))
		name++;
	else
		name = argv[0];
	error_info.id = name;
	memset(&proc, 0, sizeof(proc));
	proc.flags |= UWIN_TRACE_CALL|UWIN_TRACE_TIME;
	if((fd=open("/etc/traceflags",O_RDONLY))>=0)
	{
		if((status=read(fd,cmd,4))>0)
		{
			while(--status>=0)
			{
				if(cmd[status]=='c')
					proc.flags |= UWIN_TRACE_COUNT;
				else if(cmd[status]=='v')
					proc.flags |= UWIN_TRACE_VERBOSE;
				else if(cmd[status]=='i')
					proc.flags |= UWIN_TRACE_INHERIT;
			}
		}
		close(fd);
	}
	else
		proc.flags |= UWIN_TRACE_VERBOSE|UWIN_TRACE_INHERIT|UWIN_TRACE_COUNT;
	sfsprintf(cmd,sizeof(cmd),LOGDIR "trace/%s.log",name);
	if ((proc.trace = open(cmd, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0)
		error(ERROR_SYSTEM|3, "%s: cannot write", opt_info.arg);
	fcntl(proc.trace, F_SETFD, FD_CLOEXEC);
	if (error_info.errors || !argv[0])
		error(ERROR_USAGE|4, optusage(NiL));
	sfsprintf(cmd,sizeof(cmd),LOGDIR "trace/%s",name);
	if(access(cmd,X_OK)!=0)
		error(ERROR_SYSTEM|ERROR_NOENT, "%s: not found", cmd);
	if (!(proc.flags & (UWIN_TRACE_COUNT|UWIN_TRACE_CALL)))
		proc.flags |= UWIN_TRACE_CALL;
	if ((pid = uwin_spawn(cmd, argv, NiL, &proc)) < 0)
		error(ERROR_SYSTEM|ERROR_NOEXEC, "%s: cannot run", cmd);
	while (waitpid(pid, &status, 0) == -1)
		if (errno != EINTR)
			exit(EXIT_NOEXEC);
	return(WEXITSTATUS(status));
}
Esempio n. 20
0
int
main(int argc, char** argv)
{
    char*		s;
    char*		t;
    Jcl_t*		jcl;
    Map_t*		p;
    int		c;
    State_t		state;

    error_info.id = "jcl";
    memset(&state, 0, sizeof(state));
    jclinit(&state.disc, errorf);
    state.disc.usage = usage;
    state.disc.optsetf = optset;
    if (jcl = jclopen(NiL, NiL, JCL_EXEC|JCL_JOB|JCL_RECURSE|JCL_STANDARD|JCL_SCOPE, &state.disc))
    {
        while ((c = optget(argv, usage)) && optset(jcl, c, &state.disc));
        argv += opt_info.index;
        if (error_info.errors)
            error(ERROR_USAGE|4, "%s", optusage(NiL));
        while (jclsym(jcl, *argv, NiL, JCL_SYM_READONLY))
            argv++;
        c = 0;
        while (p = state.map)
        {
            state.map = state.map->next;
            if (jclmap(jcl, p->arg, &state.disc))
                return 1;
            c |= p->map;
            free(p);
        }
        if (!c && jclmap(jcl, NiL, &state.disc))
            return 1;
        if (state.resolve)
        {
            while (s = *argv++)
                if (t = jclpath(jcl, s))
                    sfprintf(sfstdout, "%s\n", t);
                else
                    error(2, "%s: cannot resolve", s);
        }
        else
        {
            jcl->step->command = *argv;
            while (!jclrun(jcl) && jcl->step->command && (jcl->step->command = *++argv));
        }
    }
    if (!(c = jclclose(jcl)) && error_info.errors)
        c = 1;
    return c;
}
Esempio n. 21
0
int
main(int argc, char** argv)
{
	char*		e;
	State_t		state;

	NoP(argc);
	error_info.id = "mbb";
	memset(&state, 0, sizeof(state));
	state.disc.version = CSS_VERSION;
	state.disc.flags = CSS_DAEMON|CSS_ERROR|CSS_INTERRUPT|CSS_LOG;
	state.disc.acceptf = acceptf;
	state.disc.actionf = actionf;
	state.disc.errorf = errorf;
	state.disc.exceptf = exceptf;
	for (;;)
	{
		switch (optget(argv, usage))
		{
		case 'b':
			state.backlog = opt_info.num;
			continue;
		case 'd':
			error_info.trace = -opt_info.num;
			continue;
		case 't':
			state.disc.timeout = strelapsed(opt_info.arg, &e, 1);
			if (*e)
				error(3, "%s: invalid timeout value", opt_info.arg);
			state.disc.flags |= CSS_DORMANT;
			continue;
		case '?':
			error(ERROR_USAGE|4, "%s", opt_info.arg);
			continue;
		case ':':
			error(2, "%s", opt_info.arg);
			continue;
		}
		break;
	}
	argv += opt_info.index;
	if (!argv[0] || argv[1])
		error(ERROR_USAGE|4, "%s", optusage(NiL));
	if (!(state.tmp = sfstropen()))
		error(ERROR_SYSTEM|3, "out of space [tmp stream]");
	if (!cssopen(argv[0], &state.disc))
		return 1;
	umask(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
	csspoll(CS_NEVER, 0);
	return 1;
}
Esempio n. 22
0
int    b_dot_cmd(register int n,char *argv[],void* extra)
{
	register char *script;
	register Namval_t *np;
	register int jmpval;
	register Shell_t *shp = ((Shbltin_t*)extra)->shp;
	struct sh_scoped savst, *prevscope = shp->st.self;
	char *filename=0;
	int	fd;
	struct dolnod   *argsave=0, *saveargfor;
	struct checkpt buff;
	Sfio_t *iop=0;
	short level;
	while (n = optget(argv,sh_optdot)) switch (n)
	{
	    case ':':
		errormsg(SH_DICT,2, "%s", opt_info.arg);
		break;
	    case '?':
		errormsg(SH_DICT,ERROR_usage(0), "%s",opt_info.arg);
		return(2);
	}
	argv += opt_info.index;
	script = *argv;
	if(error_info.errors || !script)
		errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
	if(shp->dot_depth+1 > DOTMAX)
		errormsg(SH_DICT,ERROR_exit(1),e_toodeep,script);
	if(!(np=shp->posix_fun))
	{
		/* check for KornShell style function first */
		np = nv_search(script,shp->fun_tree,0);
		if(np && is_afunction(np) && !nv_isattr(np,NV_FPOSIX))
		{
			if(!np->nvalue.ip)
			{
				path_search(script,NIL(Pathcomp_t**),0);
				if(np->nvalue.ip)
				{
					if(nv_isattr(np,NV_FPOSIX))
						np = 0;
				}
				else
					errormsg(SH_DICT,ERROR_exit(1),e_found,script);
			}
		}
Esempio n. 23
0
int
b_mkfifo(int argc, char *argv[], void* context)
{
	register char*	arg;
	register mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
	register mode_t	mask = 0;
	register int	mflag = 0;

	cmdinit(argc, argv, context, ERROR_CATALOG, 0);
	for (;;)
	{
		switch (optget(argv, usage))
		{
		case 'm':
			mflag = 1;
			mode = strperm(arg = opt_info.arg, &opt_info.arg, mode);
			if (*opt_info.arg)
				error(ERROR_exit(0), "%s: invalid mode", arg);
			continue;
		case ':':
			error(2, "%s", opt_info.arg);
			break;
		case '?':
			error(ERROR_usage(2), "%s", opt_info.arg);
			break;
		}
		break;
	}
	argv += opt_info.index;
	if (error_info.errors || !*argv)
		error(ERROR_usage(2), "%s", optusage(NiL));
	mask = umask(0);
	if (!mflag)
	{
		mode &= ~mask;
		umask(mask);
		mask = 0;
	}
	while (arg = *argv++)
		if (mkfifo(arg, mode) < 0)
			error(ERROR_system(0), "%s:", arg);
	if (mask)
		umask(mask);
	return error_info.errors != 0;
}
Esempio n. 24
0
int
b_expr(int argc, char** argv, Shbltin_t* context)
{
	State_t	state;
	Node_t	node;
	int	n;

	cmdinit(argc, argv, context, ERROR_CATALOG, 0);
	state.standard = !!conformance(0, 0);
#if 0
	if (state.standard)
		state.arglist = argv+1;
	else
#endif
	{
		while (n=optget(argv, usage))
		{
			/*
			 * NOTE: this loop ignores all but literal -- and -?
			 *	 out of kindness for obsolescent usage
			 *	 (and is ok with the standard) but strict
			 *	 getopt conformance would give usage for all
			 *	 unknown - options
			 */
			if(n=='?')
				error(ERROR_usage(2), "%s", opt_info.arg);
			if (opt_info.option[1] != '?')
				break;
			error(ERROR_usage(2), "%s", opt_info.arg);
		}
		if (error_info.errors)
			error(ERROR_usage(2),"%s",optusage((char*)0));
		state.arglist = argv+opt_info.index;
	}
	if (expr_or(&state, &node))
		error(ERROR_exit(2),"syntax error");
	if (node.type&T_STR)
	{
		if (*node.str)
			sfprintf(sfstdout,"%s\n",node.str);
	}
	else
		sfprintf(sfstdout,"%d\n",node.num);
	return numeric(&node)?node.num==0:*node.str==0;
}
Esempio n. 25
0
int
main(int argc, char** argv)
{
	char*		s;
	char*		t;
	pid_t		pid;
	ssize_t		n;
	ssize_t		(*dump)(pid_t, void*, const char*, char*, size_t) = uwin_stack_process;
	char*		sep = "\n\t";
	char		buf[16*1024];

	NoP(argc);
	error_info.id = "dumpstack";
	for (;;)
	{
		switch (optget(argv, usage))
		{
		case 's':
			sep = opt_info.arg;
			continue;
		case 't':
			dump = uwin_stack_thread;
			continue;
		case '?':
			error(ERROR_USAGE|4, "%s", opt_info.arg);
			break;
		case ':':
			error(2, "%s", opt_info.arg);
			break;
		}
		break;
	}
	argv += opt_info.index;
	if (error_info.errors || !(s = *argv++) || *argv)
		error(ERROR_USAGE|4, "%s", optusage(NiL));
	if (!(pid = strtol(s, &t, 0)) || *t)
		error(3, "%s: pid argument expected", s);
	if ((n = (*dump)(pid, 0, sep, buf, sizeof(buf))) < 0)
		error(ERROR_SYSTEM|3, "%d: call stack dump failed", pid);
	if (write(1, buf, n) != n)
		error(ERROR_SYSTEM|3, "write to standard output failed");
	return error_info.errors != 0;
}
Esempio n. 26
0
File: misc.c Progetto: att/ast
//
// Builtin `bg`.
//
int b_bg(int n, char *argv[], Shbltin_t *context) {
    int flag = **argv;
    Shell_t *shp = context->shp;
    const char *optstr = sh_optbg;
    if (*argv[0] == 'f') {
        optstr = sh_optfg;
    } else if (*argv[0] == 'd') {
        optstr = sh_optdisown;
    }

    while ((n = optget(argv, optstr))) {
        switch (n) {
            case ':': {
                errormsg(SH_DICT, 2, "%s", opt_info.arg);
                break;
            }
            case '?': {
                errormsg(SH_DICT, ERROR_usage(2), "%s", opt_info.arg);
                __builtin_unreachable();
            }
            default: { break; }
        }
    }
    if (error_info.errors) {
        errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
        __builtin_unreachable();
    }

    argv += opt_info.index;
    if (!sh_isoption(shp, SH_MONITOR) || !job.jobcontrol) {
        if (sh_isstate(shp, SH_INTERACTIVE)) {
            errormsg(SH_DICT, ERROR_exit(1), e_no_jctl);
            __builtin_unreachable();
        }
        return 1;
    }
    if (flag == 'd' && *argv == 0) argv = NULL;
    if (job_walk(shp, sfstdout, job_switch, flag, argv)) {
        errormsg(SH_DICT, ERROR_exit(1), e_no_job);
        __builtin_unreachable();
    }
    return shp->exitval;
}
Esempio n. 27
0
File: misc.c Progetto: att/ast
//
// Builtin `jobs`.
//
int b_jobs(int n, char *argv[], Shbltin_t *context) {
    int flag = 0;
    Shell_t *shp = context->shp;
    while ((n = optget(argv, sh_optjobs))) {
        switch (n) {
            case 'l': {
                flag = JOB_LFLAG;
                break;
            }
            case 'n': {
                flag = JOB_NFLAG;
                break;
            }
            case 'p': {
                flag = JOB_PFLAG;
                break;
            }
            case ':': {
                errormsg(SH_DICT, 2, "%s", opt_info.arg);
                break;
            }
            case '?': {
                errormsg(SH_DICT, ERROR_usage(2), "%s", opt_info.arg);
                __builtin_unreachable();
            }
            default: { break; }
        }
    }

    argv += opt_info.index;
    if (error_info.errors) {
        errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
        __builtin_unreachable();
    }

    if (*argv == 0) argv = NULL;
    if (job_walk(shp, sfstdout, job_list, flag, argv)) {
        errormsg(SH_DICT, ERROR_exit(1), e_no_job);
        __builtin_unreachable();
    }
    job_wait((pid_t)0);
    return shp->exitval;
}
Esempio n. 28
0
int
b_dirname(int argc, char** argv, Shbltin_t* context)
{
	int	mode = 0;
	char	buf[PATH_MAX];

	cmdinit(argc, argv, context, ERROR_CATALOG, 0);
	for (;;)
	{
		switch (optget(argv, usage))
		{
		case 'f':
			mode |= PATH_REGULAR;
			continue;
		case 'r':
			mode &= ~PATH_REGULAR;
			mode |= PATH_READ;
			continue;
		case 'x':
			mode |= PATH_EXECUTE;
			continue;
		case ':':
			error(2, "%s", opt_info.arg);
			break;
		case '?':
			error(ERROR_usage(2), "%s", opt_info.arg);
			break;
		}
		break;
	}
	argv += opt_info.index;
	argc -= opt_info.index;
	if(error_info.errors || argc != 1)
		error(ERROR_usage(2),"%s", optusage(NiL));
	if(!mode)
		l_dirname(sfstdout,argv[0]);
	else if(pathpath(argv[0], "", mode, buf, sizeof(buf)))
		sfputr(sfstdout, buf, '\n');
	else
		error(1|ERROR_WARNING, "%s: relative path not found", argv[0]);
	return 0;
}
Esempio n. 29
0
int
main(int argc, char** argv)
{
	register char*		s;
	register Sfio_t*	sp;

	NoP(argc);
	error_info.id = "nocom";
	for (;;)
	{
		switch (optget(argv, usage))
		{
		case '?':
			error(ERROR_USAGE|4, "%s", opt_info.arg);
			break;
		case ':':
			error(2, "%s", opt_info.arg);
			break;
		}
		break;
	}
	argv += opt_info.index;
	if (error_info.errors)
		error(ERROR_USAGE|4, "%s", optusage(NiL));
	if (!*argv)
	{
		if (nocomment(sfstdin, sfstdout) < 0)
			error(ERROR_SYSTEM|2, "write error");
	}
	else while (s = *argv++)
	{
		if (!(sp = sfopen(NiL, s, "r")))
			error(ERROR_SYSTEM|2, "%s: cannot read", s);
		else
		{
			if (nocomment(sp, sfstdout) < 0)
				error(ERROR_SYSTEM|2, "%s: write error", s);
			sfclose(sp);
		}
	}
	return error_info.errors != 0;
}
Esempio n. 30
0
int
main(int argc, char** argv)
{
	register char*		s;
	register Sfio_t*	ip;

	NoP(argc);
	error_info.id = "html2db";
	for (;;)
	{
		switch (optget(argv, usage))
		{
		case '?':
			error(ERROR_USAGE|4, "%s", opt_info.arg);
			continue;
		case ':':
			error(2, "%s", opt_info.arg);
			continue;
		}
		break;
	}
	argv += opt_info.index;
	if (error_info.errors)
		error(ERROR_USAGE|4, "%s", optusage(NiL));
	do
	{
		if (!(s = *argv) || streq(s, "-") || streq(s, "/dev/stdin") || streq(s, "/dev/fd/0"))
		{
			s = "/dev/stdin";
			ip = sfstdin;
		}
		else if (!(ip = sfopen(NiL, s, "r")))
		{
			error(ERROR_SYSTEM|2, "%s: cannot read", s);
			continue;
		}
		flatten(s, ip, sfstdout);
		if (ip != sfstdin)
			sfclose(ip);
	} while (*argv++);
	return error_info.errors != 0;
}