Example #1
0
void do_mv()
{
    if(!src[0])  scanf("%s %s",src,dest);
    strcpy(rmfile,src);
    errno=0;
    do_cp();
    if(errno==0)     do_rm();
    _clear(src);  _clear(dest);
    _clear(rmfile);
}
int
main (int argc, char **argv)
{
	int exit = 0;
	char *buffer = g_new (char, 1024) ;
	GIOChannel *ioc;
	guint watch_id = 0;
	GOptionContext *ctx = NULL;
	GError *error = NULL;

	/* default to interactive on a terminal */
	interactive = isatty (0);

	ctx = g_option_context_new("test-vfs");
	g_option_context_add_main_entries(ctx, options, NULL);

	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
		g_printerr("main: %s\n", error->message);

		g_error_free(error);
		g_option_context_free(ctx);
		return 1;
	}

	g_option_context_free(ctx);

	files = g_hash_table_new (g_str_hash, g_str_equal);

	if (noninteractive)
		interactive = FALSE;

	if (interactive)
		vfserr = stderr;
	else
		vfserr = stdout;

	if (!mate_vfs_init ()) {
		fprintf (vfserr, "Cannot initialize mate-vfs.\n");
		return 1;
	}
	mate_vfs_module_callback_push
		(MATE_VFS_MODULE_CALLBACK_AUTHENTICATION,
		 authentication_callback, NULL, NULL);

	if (argc == 1)
		cur_dir = g_get_current_dir ();
	else
		cur_dir = g_strdup(argv[1]);

	if (cur_dir && !G_IS_DIR_SEPARATOR (cur_dir [strlen (cur_dir) - 1]))
		cur_dir = g_strconcat (cur_dir, G_DIR_SEPARATOR_S, NULL);

	if (interactive == TRUE) {
		main_loop = g_main_loop_new (NULL, TRUE);
		ioc = g_io_channel_unix_new (0 /* stdin */);
		g_io_channel_set_encoding (ioc, NULL, NULL);
		g_io_channel_set_buffered (ioc, FALSE);
		watch_id = g_io_add_watch (ioc,
					   G_IO_IN | G_IO_HUP | G_IO_ERR,
					   callback, buffer);
		g_io_channel_unref (ioc);
	}

	while (!exit) {
		char *ptr;

		if (interactive) {
			fprintf (stdout,"\n%s > ", cur_dir);
			fflush (stdout);

			strcpy (buffer, "");
			g_main_loop_run (main_loop);
		} else {
			/* In non-interactive mode we just do this evil
			 * thingie */
			buffer[0] = '\0';
			fgets (buffer, 1023, stdin);
			if (!buffer [0]) {
				exit = 1;
				continue;
			}
		}

		if (!buffer || buffer [0] == '#')
			continue;

		arg_data = g_strsplit (g_strchomp (buffer), delim, -1);
		arg_cur  = 0;
		if ((!arg_data || !arg_data[0]) && interactive) continue;
		if (!interactive)
			printf ("Command : '%s'\n", arg_data [0]);
		ptr = arg_data[arg_cur++];
		if (!ptr)
			continue;

		if (g_ascii_strcasecmp (ptr, "ls") == 0)
			do_ls ();
		else if (g_ascii_strcasecmp (ptr, "cd") == 0)
			do_cd ();
		else if (g_ascii_strcasecmp (ptr, "dump") == 0)
			do_dump ();
		else if (g_ascii_strcasecmp (ptr, "type") == 0 ||
			 g_ascii_strcasecmp (ptr, "cat") == 0)
			do_cat ();
		else if (g_ascii_strcasecmp (ptr, "cp") == 0)
			do_cp ();
		else if (g_ascii_strcasecmp (ptr, "rm") == 0)
			do_rm ();
		else if (g_ascii_strcasecmp (ptr, "mkdir") == 0)
			do_mkdir ();
		else if (g_ascii_strcasecmp (ptr, "rmdir") == 0)
			do_rmdir ();
		else if (g_ascii_strcasecmp (ptr, "mv") == 0)
			do_mv ();
		else if (g_ascii_strcasecmp (ptr, "info") == 0 ||
			 g_ascii_strcasecmp (ptr, "stat") == 0)
			do_info ();
		else if (g_ascii_strcasecmp (ptr, "findtrash") == 0)
			do_findtrash ();
		else if (g_ascii_strcasecmp (ptr, "ssl") == 0)
			do_ssl ();
		else if (g_ascii_strcasecmp (ptr, "sync") == 0)
			fprintf (vfserr, "a shell is like a boat, it lists or syncs (RMS)\n");
		else if (g_ascii_strcasecmp (ptr,"help") == 0 ||
			 g_ascii_strcasecmp (ptr,"?")    == 0 ||
			 g_ascii_strcasecmp (ptr,"info") == 0 ||
			 g_ascii_strcasecmp (ptr,"man")  == 0)
			list_commands ();
		else if (g_ascii_strcasecmp (ptr,"exit") == 0 ||
			 g_ascii_strcasecmp (ptr,"quit") == 0 ||
			 g_ascii_strcasecmp (ptr,"q")    == 0 ||
			 g_ascii_strcasecmp (ptr,"bye") == 0)
			exit = 1;

		/* File ops */
		else if (g_ascii_strcasecmp (ptr, "open") == 0)
			do_open ();
		else if (g_ascii_strcasecmp (ptr, "create") == 0)
			do_create ();
		else if (g_ascii_strcasecmp (ptr, "close") == 0)
			do_close ();
		else if (g_ascii_strcasecmp (ptr, "handleinfo") == 0)
			do_handleinfo ();
		else if (g_ascii_strcasecmp (ptr, "read") == 0)
			do_read ();
		else if (g_ascii_strcasecmp (ptr, "seek") == 0)
			do_seek ();
		
		else
			fprintf (vfserr, "Unknown command '%s'", ptr);

		g_strfreev (arg_data);
		arg_data = NULL;
	}

	if (interactive) {
		g_source_remove (watch_id);
		g_main_loop_unref (main_loop);
		main_loop = NULL;
	}

	g_free (buffer);
	g_free (cur_dir);

	close_files ();

	return 0;
}
Example #3
0
void runProcess( Proc *proc, pid_t pgid, int fg, int inputFile, int outputFile, int errorFile)
{
    // wrzucenie procesu do grupy procesow i danie przekazanie grupy terminalowu jezeli jest to stosowne
    // utowrzenie grupy lub dolaczenie do juz istniejacej
    pid_t pid = getpid();

    if( pgid == 0 )
        pgid = pid;

    setpgid(pid, pgid);

    // jesli w foreground to oddajemy terminal dla grupy procesow
    if(fg == 1)
    {
        tcsetpgrp( shellTerminal, pgid );
    }

    struct sigaction act;
    act.sa_handler = SIG_DFL;  /* set up signal handler */
    act.sa_flags = 0;

    // kiedy shell przejmuje kontrole, powinien ignorowac ponizsze sygnaly, zeby samemu sie przypadkowo nie killnac
    sigaction(SIGINT, &act, NULL);
    // powrot do ustawien domyslnych (przez nasz shell te sygnaly byly ignorowane)
    sigaction(SIGINT, &act, NULL);
    sigaction(SIGQUIT, &act, NULL);
    sigaction(SIGCHLD, &act, NULL);
    sigaction(SIGTSTP, &act, NULL);
    sigaction(SIGTTIN, &act, NULL);
    sigaction(SIGTTOU, &act, NULL);

    // ustawienie standardowego I/O dla nowego procesu
    // jesli wyjscia sa inne niz standardowe to zamieniamy je - przekierowanie wyjscia
    if(inputFile != STDIN_FILENO)
    {
        dup2(inputFile, STDIN_FILENO);
        close(inputFile);
    }

    if(outputFile != STDOUT_FILENO)
    {
        dup2(outputFile, STDOUT_FILENO);
        close(outputFile);
    }

    if(errorFile != STDERR_FILENO)
    {
        dup2(errorFile, STDERR_FILENO);
        close(errorFile);
    }   if(strcmp(proc->argv[0], "pwd") == 0)
    {
        do_pwd();
    }
    else if(strcmp(proc->argv[0], "cd") == 0)
    {
        do_cd(proc->argv[1]);
    }
    else if(strcmp(proc->argv[0], "ls") == 0)
    {
        do_ls(proc->argv[1]);
    }
    else if(strcmp(proc->argv[0], "mkdir") == 0)
    {
        do_mkdir(proc->argv[1]);
    }
    else if(strcmp(proc->argv[0], "rmdir") == 0)
    {
        do_rmdir(proc->argv[1]);
    }
    else if(strcmp(proc->argv[0], "touch") == 0)
    {
        do_touch(proc->argv[1]);
    }
    else if(strcmp(proc->argv[0], "rm") == 0)
    {
        do_rm(proc->argv[1]);
    }
    else if(strcmp(proc->argv[0], "cp") == 0)
    {
        do_cp(proc->argv[1], proc->argv[2]);
    }
    else if(strcmp(proc->argv[0], "echo") == 0)
    {
        do_echo(proc->argv[1]);
    }
	else 
		run(proc->argv[0], proc->argv);
    //execvp(proc->argv[0], proc->argv);
    // nie powinien wykonac exit'a przy poprawnym wykonaniu
    //exit(-1);
}
Example #4
0
void CommandParser::executeCommand(int cmd){
	switch(cmd){
		case WRI  :  toAbsolute(first_arg);
					 do_wri(first_arg);     break;
		case LIST :  toAbsolute(first_arg);
					 do_list(first_arg);        break;
		case SHOW :  toAbsolute(first_arg);
					 do_show(first_arg);    break;
		case APP  :  toAbsolute(first_arg);
					 do_app(first_arg);        break;
		case CD   :  do_cd();               break;
		case HELP :  if (strlen(first_arg) == 0)
						do_helpd();
					 else
						do_help(first_arg);
					 break;
		case MKFS :  do_mkfs();             break;
		case REN  :  toAbsolute(first_arg);
					 do_ren(first_arg , second_arg);
					 break;
		case FINFO:  toAbsolute(first_arg);
					 do_info(first_arg);
					 break;
		case LINK :  toAbsolute(first_arg);
					 toAbsolute(second_arg);
					 do_link(first_arg , second_arg);
					 break;
		case QUIT :  do_quit();break;
		case CP   :  toAbsolute(first_arg);
					 toAbsolute(second_arg);
					 do_cp(first_arg , second_arg);
					 break;
		case LOAD :  do_load();
					 break;
		case ULOAD:     do_uload();
					 break;
		case RF   :  toAbsolute(first_arg);
					 do_rf(first_arg);
					 break;
		case RMD  :  toAbsolute(first_arg);
					 do_rmd(first_arg);
					 break;
		case MKD  :  toAbsolute(first_arg);
					 do_mkd(first_arg);
					 break;
		case CHOWN : toAbsolute(first_arg);
					 do_chown(first_arg,second_arg);
					 break ;
		case CHPERM : toAbsolute(first_arg);
					  do_chperm(first_arg,second_arg);
					  break;
		case ADDUSER :
					  do_adduser() ;
					  break;
		case CLS     :
					  clrscr();
					  break;
		case REBOOT  :
					 //
					  break;
		default:
					 if ( strlen(command) )
						 vd_puts("Invalid Command\n");
	}
}