Exemplo n.º 1
0
void main()
{
    char prefix[50],ch,str[50],operand1[50],operand2[50],oper_ator[2];
    int i=0,k=0,opndcnt=0;
    clrscr();
    printf("\t\t\t * Prefix to Postfix *");
    printf("\n\nEnter the Prefix Expression : ");
    gets(prefix);

    while((ch=prefix[i++])!='\0')
    {
	if(isalnum(ch))
	{
	    str[0]=ch;
	    str[1]='\0';
	    pushd(str);
	    operand_count++;
	    if(operand_count>=2)
	    {
		strcpy(operand2,popd());
		strcpy(operand1,popd());
		strcpy(str,operand1);
		strcat(str,operand2);
		ch=popr();
		oper_ator[0]=ch;
		oper_ator[1]='\0';
		strcat(str,oper_ator);
		pushd(str);
		operand_count-=1;
	    }
	}
	else
	{
	    pushr(ch);
	    /* operator followed by single operand*/
	    if(operand_count==1)
	    operand_count=0;
	}
    }

    if(!empty(topd))
    {
	strcpy(operand2,popd());
	strcpy(operand1,popd());
	strcpy(str,operand1);
	strcat(str,operand2);
	ch=popr();
	oper_ator[0]=ch;
	oper_ator[1]='\0';
	strcat(str,oper_ator);
	pushd(str);
    }
    printf("The Postfix Expression is : ");
    puts(opnds[topd]);
getch();
}
Exemplo n.º 2
0
int run_cmd(int argc, char **argv) {
	if (strcmp(argv[0],"echo")==0) {
			return echo(argc,argv);
	} else if (strcmp(argv[0],"cd")==0 || strcmp(argv[0],"chdir")==0) {
			return cd(argc,argv);
	} else if (strcmp(argv[0],"exit")==0) {
			fprintf(stderr,"exit\n");
			exit(0);
			return 0;
	} else if (strcmp(argv[0],"exec")==0) {
			return exec(argc,argv);
	} else if (strcmp(argv[0],"pushd")==0) {
			return pushd(argc,argv);
	} else if (strcmp(argv[0],"popd")==0) {
			return popd(argc,argv);
	} else if (strcmp(argv[0],"dirs")==0) {
			return dirs(argc,argv);
	} else if (strcmp(argv[0],"help")==0) {
			return help(argc,argv);
	} else if (strcmp(argv[0],"exitc")==0) {
			return exitc(argc,argv);
	} else if (strcmp(argv[0],"pwd")==0) {
			return pwd(argc,argv);
	} else if (strcmp(argv[0],"setpipe")==0) {
			return setpipe(argc,argv);
	} else if (strcmp(argv[0],"runpipe")==0) {
			return runpipe(argc,argv);
	} else {
			return run(argc,argv);
	}
}
Exemplo n.º 3
0
int
rotate_stack(int n)
{
	stack_entry_t *new_stack;
	size_t i;

	if(n == 0)
		return 0;

	if(pushd() != 0)
		return -1;

	new_stack = reallocarray(NULL, stack_size, sizeof(*stack));
	if(new_stack == NULL)
		return -1;

	for(i = 0U; i < stack_top; ++i)
	{
		new_stack[(i + n)%stack_top] = stack[i];
	}

	free(stack);
	stack = new_stack;
	return popd();
}
Exemplo n.º 4
0
int serv_enable(char *arg)
{
	char corr[40];
	char link[80];
	char path[80];

	if (!arg || !arg[0])
		return serv_list(NULL);

	if (!strstr(arg, ".conf")) {
		snprintf(corr, sizeof(corr), "%s.conf", arg);
		arg = corr;
	}

	pushd(FINIT_RCSD);
	snprintf(path, sizeof(path), "available/%s", arg);
	if (!fexist(path))
		errx(1, "Cannot find %s", path);

	snprintf(link, sizeof(link), "%s/%s", FINIT_RCSD, arg);
	if (fexist(link))
		errx(1, "%s already exists", link);

	return symlink(path, link) != 0;
}
Exemplo n.º 5
0
/* stack operator
**nest**  
> Creates a fresh stack with current TOS on it. Saves current dstack onto
> rstack.
*/
bvm_cache *nest(bvm_cache *this_bvm){ // nest#

    mword *nest_body = dstack_get(this_bvm,0);
//    mword *new_stack = dstack_get(this_bvm,1);
    mword *save_TOS = dstack_get(this_bvm,1);

    popd(this_bvm);
    popd(this_bvm);

    mword *save_dstack = (mword*)icar(this_bvm->dstack_ptr);
    mword *save_ustack = (mword*)icar(this_bvm->ustack_ptr);

    clear(this_bvm); // clear the stack

    //rgive(this_bvm, new_stack);
    pushd(this_bvm, save_TOS, IMMORTAL);

    mword *nest_return = (mword*)icdr(icar(this_bvm->code_ptr));

    mword *nest_rstack_entry = consa2(this_bvm, save_dstack,
                                    consa2(this_bvm, save_ustack,
                                        consa2(this_bvm, nest_return, nil)));

    pushr(this_bvm, nest_rstack_entry, _hash8(C2B("/babel/tag/nest")));

    this_bvm->code_ptr = consa2(this_bvm, nest_body,nil);

    icar(this_bvm->advance_type) = BVM_CONTINUE;

    return this_bvm;    

}
Exemplo n.º 6
0
int
swap_dirs(void)
{
	stack_entry_t item;

	if(stack_top == 0)
		return -1;

	item = stack[--stack_top];

	if(pushd() != 0)
	{
		free_entry(&item);
		return -1;
	}

	if(change_directory(&lwin, item.lpane_dir) >= 0)
		load_dir_list(&lwin, 0);

	if(change_directory(&rwin, item.rpane_dir) >= 0)
		load_dir_list(&rwin, 0);

	fview_cursor_redraw(curr_view);
	refresh_view_win(other_view);

	free_entry(&item);
	return 0;
}
Exemplo n.º 7
0
int serv_touch(char *arg)
{
	char corr[40];

	if (!arg || !arg[0])
		return serv_list(NULL);

	if (!strstr(arg, ".conf")) {
		snprintf(corr, sizeof(corr), "%s.conf", arg);
		arg = corr;
	}

	pushd(FINIT_RCSD);
	if (!fexist(arg)) {
		popd();
		if (!strstr(arg, "finit.conf"))
			errx(1, "Service %s is not enabled", arg);
		arg = FINIT_CONF;
	}

	/* libite:touch() follows symlinks */
	if (utimensat(AT_FDCWD, arg, NULL, AT_SYMLINK_NOFOLLOW))
		err(1, "Failed marking %s for reload", arg);

	return 0;
}
Exemplo n.º 8
0
/* stack operator
**take**  
> Takes TOS items from the stack and puts them into a list. 
> If TOS == -1, the entire stack is taken.  
*/
bvm_cache *take(bvm_cache *this_bvm){ // take#

    int count = (int)icar(dstack_get(this_bvm,0));
    popd(this_bvm);

    mword *result = nil;
    mword *list_entry;
    mword *temp;
    int i;

    if(count == -1){
//        while(!is_nil(this_bvm->dstack_ptr)){
        while(!dstack_empty(this_bvm)){
            list_entry = dstack_get(this_bvm,0);
            result = consa2(this_bvm, list_entry, result);
            popd(this_bvm);
        }
    }
    else{
        for(i=0;i<count;i++){
            list_entry = dstack_get(this_bvm,0);
            result = consa2(this_bvm, list_entry, result);
            popd(this_bvm);
        }
    }
    
    pushd(this_bvm, result, IMMORTAL);

    return this_bvm;

}
Exemplo n.º 9
0
void rgive(bvm_cache *this_bvm, mword *list){ // rgive#

    if(is_nil(list))
        return;

    pushd(this_bvm, (mword*)car(list), IMMORTAL);

    rgive(this_bvm,(mword*)cdr(list));

}
Exemplo n.º 10
0
/* stack operator
**depth**  
> Places the depth of the stack on TOS. To gather up the entire stack
> into a list:  
>  
> depth take  
*/
bvm_cache *depth(bvm_cache *this_bvm){ // depth#

    mword *result = _new2va( this_bvm, 1);

    *result = _len((mword*)icar(this_bvm->dstack_ptr));

    pushd(this_bvm, result, IMMORTAL);

    return this_bvm;

}
Exemplo n.º 11
0
/* stack operator
**up** (->)  
> Undoes down  
*/
bvm_cache *up(bvm_cache *this_bvm){ // up#

    if(is_nil(this_bvm->ustack_ptr)) // FIXME: Wrong
        return this_bvm;

    pushd(this_bvm, ustack_get(this_bvm,0), IMMORTAL);
    popu(this_bvm);

    return this_bvm;

}
Exemplo n.º 12
0
//big ass switchy thingy
int find_and_exec(const char * command_name, const char * parameters){
  int ret;
  if(command_name == NULL){
    return 0;
  }
  else if(strcmp(command_name,"pwd") == 0){
    return pwd();
  }
  else if(strcmp(command_name,"cd") == 0){
    return cd(parameters);
  }
  else if(strcmp(command_name,"echo") == 0){
    return echo(parameters);
  }
  else if(strcmp(command_name,"pushd") == 0){
    return pushd(parameters);
  }
  else if(strcmp(command_name,"popd") == 0){
    return popd();
  }
  else if(strcmp(command_name,"exit") == 0){
    exitc(parameters);
  }
  else if(strcmp(command_name,"set") == 0){
    printf("Did you mean export? If you are looking for windows try your walls\n");
    return 0;
  }
  else if(strcmp(command_name,"history") == 0){
    print_stack_lines(history);
    return 0;
  }
  else if(strcmp(command_name,"unsetenv") == 0){
    return unsetenv(parameters);
  }
  else {
    int pid = fork();
    if(pid == -1){return 1;}
    else if(pid == 0){
      if(parameters == NULL) {
        execlp(command_name,command_name,NULL);
      }
      else {
        execvp(command_name,split_spaces_cmd(command_name,parameters));
      }
    }
    else {
      wait(&ret);
      return ret;
    }
  }
  return 0;
}
Exemplo n.º 13
0
static void rmfiles (char *prefix)
{
#ifdef _WIN32
    /* Win32 doesn't have POSIX dirent functions.  */
    WIN32_FIND_DATA ffd;
    HANDLE hnd;
    int go_on;
    string temp = concat (prefix, "*");
    string directory = xdirname (prefix);

    pushd (directory);
    hnd = FindFirstFile(temp, &ffd);
    go_on = (hnd != INVALID_HANDLE_VALUE);
    while (go_on) {
        /* FIXME: can this remove read-only files also, like rm -f does?  */
        DeleteFile(ffd.cFileName);
        go_on = (FindNextFile(hnd, &ffd) == TRUE);
    }
    FindClose(hnd);
    free(temp);
    popd ();
#else  /* not _WIN32 */
    DIR *dp;
    struct dirent *de;
    int temp_len = strlen (prefix);
    string directory = "./";
    const_string base = xbasename (prefix);

    /* Copy the directory part of PREFIX with the trailing slash, if any.  */
    if (base != prefix)
    {
        directory = (string) xmalloc (base - prefix + 1);
        directory[0] = '\0';
        strncat (directory, prefix, base - prefix);
    }

    /* Find matching files and delete them.  */
    if ((dp = opendir (directory)) != 0) {
        while ((de = readdir (dp)) != 0)
        {
            string found = concat (directory, de->d_name);

            if (FILESTRNCASEEQ (found, prefix, temp_len))
                /* On POSIX-compliant systems, including DJGPP, this will also
                   remove read-only files and empty directories, like rm -f does.  */
                if (remove (found))
                    perror (found);
            free (found);
        }
    }
#endif /* not _WIN32 */
}
Exemplo n.º 14
0
static void do_list(const char *heading, const char *path)
{
	int num;
	int prev;
	int width;
 	char buf[screen_cols];
	size_t i, len;
	glob_t gl;

	pushd(path);
	if (glob("*.conf", 0, NULL, &gl)) {
		chdir(cwd);
		return;
	}

	if (gl.gl_pathc <= 0)
		goto done;

	memset(buf, 0, sizeof(buf));
	snprintf(buf, sizeof(buf), "%s :: %s ", heading, path);
	len = strlen(buf);
	for (size_t i = len; i < (sizeof(buf) - 1); i++)
		buf[i] = '-';
	printf("\e[1m%s\e[0m\n", buf);

	width = calc_width(gl.gl_pathv, gl.gl_pathc);
	if (width <= 0)
		goto done;

	num = (screen_cols - 2) / width;
	if ((num - 1) * 2 + num * width > screen_cols)
		num--;

	prev = 0;
	for (i = 0; i < gl.gl_pathc; i++) {
		if (i > 0 && !(i % num)) {
			puts("");
			prev = 0;
		}

		if (prev)
			printf("  ");
		printf("%-*s", width, gl.gl_pathv[i]);
		prev++;
	}
	puts("\n");

done:
	globfree(&gl);
	popd();
}
Exemplo n.º 15
0
/* Executes a builtin command, redirecting input and output as appropriate.
 * and output as appropriate. As with all exec_XXX() functions, assumes that
 * the parent has forked if necessary, but unlike the others, returns the status
 * of the command executed.
 *
 * @simple = CMD to be executed
 *
 * Returns: Status of command executed
 */
int exec_builtin(CMD* simple)
{
    // Keep track of old stdin, stdout, stderr for after execution of built-in
    int old_stdin = dup(0);
    int old_stdout = dup(1);
    int old_stderr = dup(2);
    // Failures for built-in commands to redirect should not cause the command
    // to abort, but it should set ? appropriately
    int redirect_status = 0;
    if (simple->fromFile && redirect_input(simple) < 0) redirect_status = errno;
    if (simple->toFile && redirect_output(simple) < 0) {
        int fd_devnull = open("/dev/null", O_WRONLY);
        dup2(fd_devnull, 1);
        if (ISREDERR(simple->toType)) dup2(fd_devnull, 2);
        close(fd_devnull);
        redirect_status = errno;
    }

    char* cmd_name = simple->argv[0];

    int builtin_status = 0;
    if (!strcmp(cmd_name, "cd")) {
        builtin_status = cd(simple->argc, simple->argv);
    } else if (!strcmp(cmd_name, "pushd")) {
        builtin_status =  pushd(simple->argc, simple->argv);
    } else if (!strcmp(cmd_name, "popd")) {
        builtin_status =  popd(simple->argc, simple->argv);
    } else {
        builtin_status = 1;
    }
    dup2(old_stdin, 0);
    close(old_stdin);
    dup2(old_stdout, 1);
    close(old_stdout);
    dup2(old_stderr, 2);
    close(old_stderr);
    return builtin_status ? builtin_status : redirect_status;
}
Exemplo n.º 16
0
    fputc('\n', stderr);
    va_end(ptr);
    exit(1);
}


/* open_template() -- start at the current directory and work up,
 *                    looking for the deepest nested template. 
 *                    Stop looking when we reach $root or /
 */
FILE *
open_template(char *template)
{
    char *cwd;
    int szcwd;
    HERE here = pushd(".");
    FILE *ret;

    if ( here == NOT_HERE )
	fail("cannot access the current directory");

    szcwd = root ? 1 + strlen(root) : 2;

    if ( (cwd = malloc(szcwd)) == 0 )
	return 0;

    while ( !(ret = fopen(template, "r")) ) {
	if ( getcwd(cwd, szcwd) == 0 ) {
	    if ( errno == ERANGE )
		goto up;
	    break;
Exemplo n.º 17
0
int main(int argc, char *argv[])
{
  int i;
  int retval = 0;

  kpse_set_progname(argv[0]);
  progname = xstrdup(program_invocation_short_name);

#ifdef _WIN32
  SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler, TRUE);
#else
# ifdef SIGHUP
  signal (SIGHUP, sigint_handler);
# endif
# ifdef SIGINT
  signal (SIGINT, sigint_handler);
# endif
# ifdef SIGQUIT
  signal (SIGQUIT, sigint_handler);
# endif
# ifdef SIGEMT
  signal (SIGEMT, sigint_handler);
# endif
# ifdef SIGPIPE
  signal (SIGPIPE, sigint_handler);
# endif
# ifdef SIGTERM
  signal (SIGTERM, sigint_handler);
# endif
#endif

  if (strlen(progname) > 4 && FILESTRNCASEEQ(progname + strlen(progname) - 4, ".exe", 4)) {
    *(progname + strlen(progname) - 4) = '\0';
  }
  is_ht = FILESTRCASEEQ(progname, "ht");

  argv = parse_arguments(&argc, argv);

#if 0
  fprintf(stderr, "%s:\n", progname);
  for (i = 1; i < argc; i++) 
    fprintf(stderr, "\t argv[%d] = %s\n", i, argv[i]);
  fprintf(stderr, "\nconfig(%d,%d) = ", math, dtd);
  for (i = 0; i < 3; i++)
    fprintf(stderr, "%s ", stdcfg[math][dtd][i]);
  fprintf(stderr, "\n");
#endif
  
  texargs = (force ? "--interaction=nonstopmode" : "");

  if (TESTZ(argv[1])) {
    fprintf(stderr, "%s: error, no file specified.\n", progname);
    exit(1);
  }

  texsrc = xstrdup(argv[1]);

#if 0
  /* Rely on latex / kpathsea to find the right source file. */
  if ((strlen(texsrc) < 4)
      || _strnicmp(texsrc + strlen(texsrc) - 4, ".tex", 4) != 0) {
    texsrc = concat(texsrc, ".tex");
  }
#endif

  texfile = xstrdup(texsrc);

  if ((strlen(texfile) >= 4) 
      && _strnicmp(texfile + strlen(texfile) - 4, ".tex", 4) == 0) {
    *(texfile + strlen(texfile) - 4) = '\0';
  }

  if (TESTZ(output_name)) {
    output_name = xstrdup(texfile);
  }
  else {
    if ((strlen(output_name) >= 4) 
	&& _strnicmp(output_name + strlen(output_name) - 4, ".tex", 4) == 0) {
      *(output_name + strlen(output_name) - 4) = '\0';
    }
    texargs = concat3(texargs, " --jobname=", output_name);
  }

#if 0
  // copy the original name to output name if needed
  if (TESTNZ(output_dir)) {
    texfile = concat3(output_dir, "\\", output_name);
  }
  else if (TESTNZ(output_name)) {
    texfile = xstrdup(output_name);
  }
  else 
    texfile = NULL;

  if (texfile) {
    unixtodos_filename(texfile);
    
    if (dry_run) {
      fprintf(stderr, "%s: copying %s to %s\n", progname, texsrc, texfile);
    }
    else {
      if (CopyFile(texsrc, texfile, false) == 0) {
	fprintf(stderr, "%s: failed to copy %s to %s (Error %d)\n",
		progname, texsrc, texfile, GetLastError());
      }
    }
    free(texfile);
  }

  texfile = xstrdup(output_name);

  if (TESTNZ(output_dir)) {
    pushd(output_dir);
    xputenv("KPSE_DOT", cwd);
    xputenv("TEXINPUTS", concatn(cwd, "/", output_dir, ";", NULL));
    if (dry_run) {
      fprintf(stderr, "%s: changing directory to %s\n", progname, output_dir);
      fprintf(stderr, "%s: setting KPSE_DOT to %s\n", progname, cwd);
    }
  }
#endif
  if (is_ht) {
    retval = ht(argc, argv);
  }
  else if (FILESTRCASEEQ(progname, "httex")) {
    retval = ht_engine(runstr_tex, argc, argv);
  }
  else if (FILESTRCASEEQ(progname, "htlatex")) {
    retval = ht_engine(runstr_latex, argc, argv);
  }
  else if (FILESTRCASEEQ(progname, "httexi")) {
    retval = ht_engine(runstr_texi, argc, argv);
  }
  else {
    fprintf(stderr, "%s: %s is unknown, aborting.\n", argv[0], progname);
    retval = 1;
  }

  if (opt_index) {
    /* copy dest_dir/output_name.html to dest_dir/index.html */
    char *destfile = output_name;
    char *indexfile = "index.html";

    if (TESTNZ(output_dir)) {
      destfile = concat3(output_dir, "\\", output_name);
      indexfile = concat(output_dir, "\\index.html");
    }

    if ((strlen(destfile) < 5) 
	|| _strnicmp(destfile + strlen(destfile) - 5, ".html", 5) != 0) {
      destfile = concat(destfile, ".html");
    }
    
    if (CopyFile(destfile, indexfile, false) == 0) {
      fprintf(stderr, "%s: failed to copy %s to %s (Error %d)\n",
	      progname, destfile, indexfile, GetLastError());
    }
  }

  mt_exit(retval);

  /* Not Reached */
  return retval;
}