示例#1
0
 void	loadmod_free(t_loadmod *t)
 {
   list_all(t->module_list, module_list);
   list_free(&(t->module_list));
   dlclose(t->handle);
   list_all(t->file_list, list);
   list_free(&(t->file_list));
   free(t);
 }
示例#2
0
int list(int argc, char *argv[])
{

	printf("list cmd\n");
	list_all();
	return 0;
}
示例#3
0
void list_all(char *mydir, int space)
{
    DIR* dir;
    struct dirent* str;
    int i;
    dir = opendir(mydir);   
    while((str = readdir(dir)) != NULL)
    {
        for (i = 0; i < space; ++i)
            printf("-");
        printf("%s\n", str->d_name);
        
        strcpy(path, mydir);
        strcat(path, str->d_name);
        strcat(path, "/");
        
        stat(path, &s);
        if( s.st_mode & S_IFDIR )               //it's a directory
        {
        	if(str->d_name[0] != '.')
            	list_all(path, space + 2);
        }
        else if( s.st_mode & S_IFREG )          //it's a file
        {
//            printf("file\n");
        }
        else                                    //something else
        {}
    }
}
示例#4
0
void sort_by_age(void)
{
    qsort(students, num, sizeof(link), cmp_age);
    list_all();

    return;
}
示例#5
0
int
main (int argc, char **argv)
{
  int index;
  mu_msgset_t msgset;
  mu_mailbox_t mbox;
  mu_url_t url;
  struct mark_closure clos;
  
  MU_APP_INIT_NLS ();
  mh_argp_init ();
  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
		 opt_handler, NULL, &index);

  mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
  mu_mailbox_get_url (mbox, &url);
  mbox_dir = mu_url_to_string (url);
  if (memcmp (mbox_dir, "mh:", 3) == 0)
    mbox_dir += 3;
	
  argc -= index;
  argv += index;
  mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
  
  clos.mbox = mbox;
  clos.msgset = msgset;
  //FIXME: msgset operates on UIDs but there's no way to inform it about that.
  switch (action)
    {
    case ARG_ADD:
      if (!seq_list)
	{
	  mu_error (_("--add requires at least one --sequence argument"));
	  return 1;
	}
      mu_list_foreach (seq_list, action_add, (void *) &clos);
      mh_global_save_state ();
      break;
      
    case ARG_DELETE:
      if (!seq_list)
	{
	  mu_error (_("--delete requires at least one --sequence argument"));
	  return 1;
	}
      mu_list_foreach (seq_list, action_delete, (void *) &clos);
      mh_global_save_state ();
      break;
      
    case ARG_LIST:
      if (!seq_list)
	list_all (mbox);
      else
	mu_list_foreach (seq_list, action_list, &clos);
      break;
    }
  mu_mailbox_close (mbox);
  mu_mailbox_destroy (&mbox);
  return 0;
}
示例#6
0
  static t_res		init_module_list(void *data_list, void *data)
  {
    char		*filename;
    t_loadmod		*t;
    t_module		*mod;
    loadmod_call	create;

    filename = data_list;
    t = data;
#ifdef DEBUG
    printf("*** init module [%s]\n", filename);
#endif /* !DEBUG */
    if ((t->handle = dlopen(filename, RTLD_NOW)) == NULL)
      {
#ifdef DEBUG
	perror(dlerror());
#endif /* !DEBUG */
	return (R_CONTINUE);
      }
    if ((create = (loadmod_call)dlsym(t->handle, "call")) == NULL)
      {
	dlclose(t->handle);
	return (R_CONTINUE);
      }
    mod = new_module();
    create(mod);
    if (list_all(mod->comp_version_list, check_version) == R_FOUND)
      if (mod->load_fct != NULL && (*(mod->load_fct))() >= 0)
	{
	  list_push(&(t->module_list), (void*)mod);
	  return (R_CONTINUE);
	}
    free(mod);
    return (R_CONTINUE);
  }
示例#7
0
  static t_res	module_list(void *data_list)
  {
    t_module	*t;

    t = data_list;
#ifdef DEBUG
    printf("*** free module [%s]\n", t->name);
#endif /* !DEBUG */
    if (t->unload_fct != NULL)
      (*(t->unload_fct))();
    list_all(t->hook_list, list);
    list_free(&(t->hook_list));
    list_all(t->comp_version_list, list);
    list_free(&(t->comp_version_list));
    return (list(data_list));
  }
示例#8
0
文件: keylist.c 项目: BridgeNY/purdue
void
secret_key_list( STRLIST list )
{
    if( !list )
	list_all(1);
    else  /* List by user id */
	list_one( list, 1 );
}
示例#9
0
文件: keylist.c 项目: BridgeNY/purdue
/****************
 * List the keys
 * If list is NULL, all available keys are listed
 */
void
public_key_list( STRLIST list )
{
    if( !list )
	list_all(0);
    else
	list_one( list, 0 );
}
示例#10
0
int main()
{   
    char mydir[100] = "E:/Wallpaper/";				//	It prints out all directories and files
    
    list_all(mydir, 0);  //getcwd(mydir, 100);
  
    return 0;
}
示例#11
0
文件: todo.c 项目: peterhgombos/todo
int main(int argc, char *argv[])
{
	int c;
	unsigned int iseed = (unsigned int)time(NULL);
	srand(iseed);

	if(argc == 1){
		list_all();
		return 0;
	}
	while (1)
	{
		static struct option long_options[] =
		{
			{"help",	no_argument,			NULL,	'h'},
			{"add",     	required_argument,		NULL,	'a'},
			{"show",	required_argument,		NULL,	's'},
			{"done",	required_argument,		NULL,	'd'},
			{"list",	required_argument,		NULL,	'l'},
			{0, 0, 0, 0}
		};
		int option_index = 0;
		c = getopt_long(argc, argv, "ha:s:d:l:", long_options, &option_index);

		if(c == -1)
			break;

		switch(c)
		{

			case 'h':
				help();
			break;

			case 'a':
				add_todo(optarg);
			break;

			case 's':
				list_id(optarg); //todo: fix better casting
			break;

			case 'd':
				remove_todo(optarg); // todo: fix better casting
			break;

			case 'l':
				search(optarg);
			break;
			
		}
	}
	return 0;
}
示例#12
0
int list(int argc, char *argv[])
{
    printf("list cmd\n");

    if(argc == 1)
        list_all();
    else
        list_name(argv[1]);

    return 0;
}
示例#13
0
static int tish_sysctl_cmd(char * argv[])
{
    char * arg = argv[1];
    int retval = 0;

    if (!strcmp(arg, "-a")) {
        list_all();
    } else {
        /* TODO do this correctly */
        /* We only support integer values by now */
        retval = getset_parm(arg);
    }

    return retval;
}
示例#14
0
文件: maildrop.c 项目: jturner/pop3d
static void
session_imsgev(struct imsgev *iev, int code, struct imsg *imsg)
{
	struct m_backend	*mb = iev->data;

	switch (code) {
	case IMSGEV_IMSG:
		switch (imsg->hdr.type) {
		case IMSG_MAILDROP_INIT:
			maildrop_init(iev, imsg, mb);
			break;
		case IMSG_MAILDROP_UPDATE:
			update(iev, imsg, mb);
			break;
		case IMSG_MAILDROP_RETR:
			retr(iev, imsg, mb);
			break;
		case IMSG_MAILDROP_DELE:
			dele(iev, imsg, mb);
			break;
		case IMSG_MAILDROP_RSET:
			rset(iev, imsg, mb);
			break;
		case IMSG_MAILDROP_LIST:
			list(iev, imsg, mb);
			break;
		case IMSG_MAILDROP_LISTALL:
			list_all(iev, imsg, mb);
			break;
		default:
			logit(LOG_DEBUG, "%s: unexpected imsg %u",
			    __func__, imsg->hdr.type);
			break;
		}
		break;
	case IMSGEV_EREAD:
	case IMSGEV_EWRITE:
	case IMSGEV_EIMSG:
		fatal("maildrop: imsgev read/write error");
		break;
	case IMSGEV_DONE:
		event_loopexit(NULL);
		break;
	}
}
示例#15
0
gfarm_error_t
paraccess_list(int opt_concurrency, int opt_udp_only,
	char *opt_architecture, char *opt_domainname, int opt_port,
	int opt_plain_order, int opt_sort_by_loadavg,
	int opt_use_metadb, int nhosts, char **hosts,
	gfarm_error_t (*request_op)(struct gfarm_host_info *,
	    struct gfarm_paraccess *),
	void (*callback_op)(struct output *))
{
	gfarm_error_t e, e_save;
	struct gfarm_paraccess *pa;

	if (opt_plain_order) /* i.e. don't sort */
		output_record = 0;
	else
		output_record = 1;

	output_callback = callback_op;

	e = gfarm_paraccess_alloc(opt_concurrency, !opt_udp_only, &pa);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: %s\n",
		    program_name, gfarm_error_string(e));
		exit(1);
	}

	if (nhosts == 0) {
		e_save = list_all(opt_architecture, opt_domainname,
			request_op, pa);
	} else if (opt_use_metadb) {
		e_save = list(nhosts, hosts, request_op, pa);
	} else {
		e_save = list_without_metadb(nhosts, hosts, opt_port,
		    request_op, pa);
	}
	e = gfarm_paraccess_free(pa);
	if (e_save == GFARM_ERR_NO_ERROR)
		e_save = e;

	if (!opt_plain_order)
		output_sort(opt_sort_by_loadavg ? output_cmp_by_loadavg :
		    output_cmp_by_name);

	return (e_save);
}
示例#16
0
int main(int argc, char **argv) {
    static bool show_series = false, show_all = false, use_cache = true;
    static int i_sid = 0;
    static char usage_str[] = "[SID[:PID]]";
    static struct opt_table opts[] = {
        OPT_WITH_ARG("--items-list|-i", opt_set_intval, NULL, &i_sid,
                "List episodes in a series. Requires a SID as a parameter."),
        OPT_WITHOUT_ARG("--series-list|-s", opt_set_bool, &show_series,
                "List the series available. The first element is the SID."),
        OPT_WITHOUT_ARG("--all|-a", opt_set_bool, &show_all,
                "List all items in all non-empty series."),
        OPT_WITHOUT_ARG("--force|-f", opt_set_invbool, &use_cache,
                "Force bypass the cached metadata."),
        OPT_WITHOUT_ARG("--help|-h", opt_usage_and_exit,
                usage_str, "Show this message."),
        OPT_ENDTABLE
    };
    opt_register_table(opts, NULL);
    if(!opt_parse(&argc, argv, opt_log_stderr)) {
        /* opt_parse will print an error to stderr. */
        exit(1);
    }
    if (!show_all && !show_series && !i_sid && (argc == 1)) {
        opt_usage_and_exit(usage_str);
    }

    struct iv_series *index;
    struct iv_config *config;
    int return_val = 0;
    cache_dir = xdg_user_dir_lookup_with_fallback("CACHE", "/tmp");
    if(NULL == (config = iviewiir_configure())) {
        fprintf(stderr, "Couldn't configure iviewiir, exiting\n");
        return 1;
    }
    int index_len = iviewiir_index(config, &index);
    if(0 >= index_len) {
        fprintf(stderr, "No items in index, exiting\n");
        return_val = 1;
        goto config_cleanup;
    }
    /* Check if they want everything listed */
    if(show_all) {
        list_all(config, index, index_len);
        return_val = 0;
        goto index_cleanup;
    }
    /* Check if they wanted a series list. */
    if(show_series) {
        int i;
        for(i=0; i<index_len; i++) {
            /* Heuristic to trim out empty series. */
            if((int)9e6 < index[i].id) {
                continue;
            }
            printf("%d - %s\n", index[i].id, index[i].title);
        }
        return_val = 0;
        goto index_cleanup;
    }
    /* Check if they want an episode list. */
    if(i_sid) {
        return_val = list_items(config, index, index_len, i_sid);
        goto index_cleanup;
    }
    /* If we've reached here and there are no arguments, print help message. */
    if (argc == 1) {
        opt_usage_and_exit(usage_str);
    }
    /* Otherwise, if they supplied a SID or SID:PID tuple, download the PID */
    int i = 1;
    while(i < argc) {
        if(NULL != strchr(argv[i], ':')) {
            // SID:PID
            const unsigned long sid = strtoul(strtok(argv[i], ":"), NULL, 10);
            const unsigned int pid = strtoul(strtok(NULL, ":"), NULL, 10);
            return_val += download_item(config, index, index_len, sid, pid);
        } else {
            // Check if it's a valid SID
            const unsigned int sid = strtoul(argv[i], NULL, 10);
            struct iv_episode *items;
            // Fetch episode lists for the SID
            debug("sid: %d\n", sid);
            int series_index;
            if(-1 == (series_index =
                        iv_find_series(sid, index, index_len, NULL))) {
                printf("No such series");
                return_val += 1;
                continue;
            }
            // Fetch items in series
            ssize_t items_len =
                iv_easy_series(config, &index[series_index], &items);
            if(1 > items_len) {
                printf("No items in series.\n");
                return_val += 1;
                continue;
            }
            for(i=0; i<items_len; i++) {
                return_val += download_item(config, index, index_len, sid,
                        items[i].id);
            }
            iv_destroy_series(items, items_len);
        }
        i++;
    }
index_cleanup:
    iv_destroy_index(index, index_len);
config_cleanup:
    iv_destroy_config(config);
    free(cache_dir);
    return return_val;
}
示例#17
0
void sort_name(void)
{
	qsort(st, num, sizeof(stu_t), cmp_name);
	list_all();
}
示例#18
0
int
main(int argc, char **argv)
{
	int argc_save = argc;
	char **argv_save = argv;
	gfarm_error_t e, e_save = GFARM_ERR_NO_ERROR;
	char opt_operation = '\0'; /* default operation */
	int opt_concurrency = DEFAULT_CONCURRENCY;
	int opt_alter_aliases = 0;
	char *opt_architecture = NULL;
	char *opt_domainname = NULL;
	long opt_ncpu = 0;
	int opt_port = 0, opt_flags = -1;
	int opt_plain_order = 0; /* i.e. do not sort */
	int opt_sort_by_loadavg = 0;
	int i, c, opt_use_metadb = 1;
	char *s;

	if (argc > 0)
		program_name = basename(argv[0]);
	while ((c = getopt(argc, argv, "AD:HLMPUa:cdf:ij:lmn:p:ruv?")) != -1) {
		switch (c) {
		case 'A':
			opt_alter_aliases = 1;
			break;
		case 'L':
			opt_sort_by_loadavg = 1;
			break;
		case 'M':
		case 'H':
		case 'R':
		case 'c':
		case 'd':
		case 'l':
		case 'm':
			if (opt_operation != '\0' && opt_operation != c)
				inconsistent_option(opt_operation, c);
			opt_operation = c;
			break;
		case 'a':
			opt_architecture = optarg;
			s = validate_architecture(opt_architecture);
			if (s != NULL) {
				fprintf(stderr, "%s: "
				    "invalid character '%c' in \"-a %s\"\n",
				    program_name, *s, opt_architecture);
				exit(1);
			}
			break;
		case 'D':
			opt_domainname = optarg;
			s = validate_hostname(opt_domainname);
			if (s != NULL) {
				fprintf(stderr, "%s: "
				    "invalid character '%c' in \"-a %s\"\n",
				    program_name, *s, opt_domainname);
				exit(1);
			}
			break;
		case 'i':
			opt_resolv_addr = resolv_addr_without_address_use;
			break;
		case 'j':
			opt_concurrency = parse_opt_long(optarg,
			    c, "<concurrency>");
			if (opt_concurrency <= 0) {
				fprintf(stderr, "%s: invalid value: -%c %d\n",
				    program_name, c, opt_concurrency);
				usage();
			}
			break;
		case 'f':
			opt_flags = parse_opt_long(optarg, c, "<flags>");
			break;
		case 'n':
			opt_ncpu = parse_opt_long(optarg, c, "<ncpu>");
			break;
		case 'p':
			opt_port = parse_opt_long(optarg, c, "<port>");
			break;
		case 'r':
			output_sort_reverse = 1;
			break;
		case 'U':
			opt_udp_only = 1;
			break;
		case 'u':
			opt_plain_order = 1;
			break;
		case 'v':
			opt_verbose = 1;
			break;
		case '?':
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	switch (opt_operation) {
	case OP_CREATE_ENTRY:
		if (opt_architecture == NULL) {
			fprintf(stderr, "%s: missing -a <architecture>\n",
			    program_name);
			usage();
		}
		if (opt_ncpu == 0)
			opt_ncpu = 1;
		if (opt_flags == -1)
			opt_flags = 0;
		/* opt_alter_aliases is meaningless, but allowed */
		break;
	case OP_REGISTER_DB:
	case OP_DELETE_ENTRY:
		if (opt_architecture != NULL)
			invalid_option('a');
		if (opt_domainname != NULL)
			invalid_option('D');
		/* fall through */
	case OP_NODENAME:
	case OP_LIST_GFSD_INFO:
	case OP_LIST_LONG:
	case OP_DUMP_METADB:
		if (opt_ncpu != 0)
			invalid_option('n');
		if (opt_alter_aliases)
			invalid_option('A');
		break;
	case OP_MODIFY_ENTRY:
		if (opt_domainname != NULL)
			invalid_option('D');
		break;
	default:
		;
	}

	for (i = 0; i < argc; i++) {
		s = validate_hostname(argv[i]);
		if (s != NULL) {
			fprintf(stderr, "%s: "
			    "invalid character '%c' in hostname \"%s\"\n",
			    program_name, *s, argv[i]);
			exit(1);
		}
	}

	e = gfarm_initialize(&argc_save, &argv_save);
	if (opt_operation == OP_LIST_GFSD_INFO && argc > 0 &&
	    opt_resolv_addr == resolv_addr_without_address_use) {
		/*
		 * An implicit feature to access gfsd directly
		 * without having working gfmd.
		 * e.g. gfhost -Hi <hostname>
		 *
		 * XXX	should describe this in the manual?
		 *	or use explicit and different option?
		 */
		opt_use_metadb = 0;
		opt_resolv_addr = resolv_addr_without_metadb;
	} else if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: %s\n", program_name,
		    gfarm_error_string(e));
		exit(1);
	}

	switch (opt_operation) {
	case OP_CREATE_ENTRY:
		if (argc > 0) {
			if (opt_port == 0) {
				fprintf(stderr, "%s: option -p <port> is "
				    "mandatory with -c\n", program_name);
				usage();
			}
			e_save = add_host(argv[0], opt_port, &argv[1],
			    opt_architecture, opt_ncpu, opt_flags);
			if (e_save != GFARM_ERR_NO_ERROR)
				fprintf(stderr, "%s: %s: %s\n", program_name,
				    argv[0], gfarm_error_string(e_save));
		}
		break;
	case OP_MODIFY_ENTRY:
		if (argc > 0) {
			e_save = gfarm_modify_host(argv[0], opt_port, &argv[1],
			    opt_architecture, opt_ncpu, opt_flags,
			    !opt_alter_aliases);
			if (e_save != GFARM_ERR_NO_ERROR)
				fprintf(stderr, "%s: %s: %s\n", program_name,
				    argv[0], gfarm_error_string(e_save));
		}
		break;
	case OP_DELETE_ENTRY:
		for (i = 0; i < argc; i++) {
			e = gfm_client_host_info_remove(gfarm_metadb_server,
			    argv[i]);
			if (e != GFARM_ERR_NO_ERROR) {
				fprintf(stderr, "%s: %s\n", argv[i],
				    gfarm_error_string(e));
				if (e_save == GFARM_ERR_NO_ERROR)
					e_save = e;
			}
		}
		break;
	case OP_REGISTER_DB:
		if (argc > 0) {
			fprintf(stderr, "%s: too many argument: %s\n",
			    program_name, argv[0]);
			exit(1);
		}
		e_save = register_db();
		break;
	case OP_LIST_GFSD_INFO:
		e = paraccess_list(opt_concurrency, opt_udp_only,
		    opt_architecture, opt_domainname, opt_port,
		    opt_plain_order, opt_sort_by_loadavg,
		    opt_use_metadb, argc, argv,
		    request_gfsd_info, callback_gfsd_info);
		break;
	case OP_NODENAME:
		e = paraccess_list(opt_concurrency, opt_udp_only,
		    opt_architecture, opt_domainname, opt_port,
		    opt_plain_order, opt_sort_by_loadavg,
		    opt_use_metadb, argc, argv,
		    request_nodename, callback_nodename);
		break;
	case OP_LIST_LONG:
		e = paraccess_list(opt_concurrency, opt_udp_only,
		    opt_architecture, opt_domainname, opt_port,
		    opt_plain_order, opt_sort_by_loadavg,
		    opt_use_metadb, argc, argv,
		    request_long_format, callback_long_format);
		break;
	case OP_DUMP_METADB:
		if (argc == 0) {
			e_save = list_all(opt_architecture, opt_domainname,
				print_host_info, NULL);
		} else {
			e_save = list(argc, argv, print_host_info, NULL);
		}
		break;
	}
	e = gfarm_terminate();
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: %s\n", program_name,
		    gfarm_error_string(e));
		exit(1);
	}
	exit(e_save == GFARM_ERR_NO_ERROR ? 0 : 1);
}
示例#19
0
文件: gfgroup.c 项目: ddk50/gfarm_v2
int
main(int argc, char *argv[])
{
	gfarm_error_t e;
	char op = OP_GROUPNAME, *groupname;
	int c;
	const char *path = ".";
	char *realpath = NULL;

	e = gfarm_initialize(&argc, &argv);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: gfarm_initialize: %s\n",
		    program_name, gfarm_error_string(e));
		exit(1);
	}

	while ((c = getopt(argc, argv, "P:cdlm?")) != -1) {
		switch (c) {
		case 'P':
			path = optarg;
			break;
		case OP_CREATE_GROUP:
		case OP_DELETE_GROUP:
		case OP_MODIFY_GROUP:
		case OP_LIST_LONG:
			op = c;
			break;
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (gfarm_realpath_by_gfarm2fs(path, &realpath) == GFARM_ERR_NO_ERROR)
		path = realpath;
	if ((e = gfm_client_connection_and_process_acquire_by_path(path,
	    &gfm_server)) != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: metadata server for \"%s\": %s\n",
		    program_name, path, gfarm_error_string(e));
		exit(1);
	}
	free(realpath);

	switch (op) {
	case OP_GROUPNAME:
	case OP_LIST_LONG:
		if (argc == 0)
			e = list_all(op);
		else
			e = list(op, argc, argv);
		break;
	case OP_CREATE_GROUP:
	case OP_MODIFY_GROUP:
		if (argc < 1)
			usage();
		groupname = *argv++;
		--argc;
		e = create_group(op, groupname, argc, argv);
		break;
	case OP_DELETE_GROUP:
		if (argc != 1)
			usage();
		e = delete_group(*argv);
		break;
	}
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: %s\n",
		    program_name, gfarm_error_string(e));
		exit(1);
	}

	gfm_client_connection_free(gfm_server);

	e = gfarm_terminate();
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: gfarm_terminate: %s\n",
		    program_name, gfarm_error_string(e));
		exit(1);
	}
	exit(0);
}
示例#20
0
int command(int argc,char **argv)
{
    if(argc<2)
    {
        printf("You must enter a command!\n");
        return 1;
    }
    else
    {
        //Handling drive aquisition
        if(strcmp(argv[1],"-dd")==0)
        {
            if(argc<3)
            {
                printf("You must enter a source for the drive dump\n");
                return 1;
            }
            else
            {
                if(argc<4)
                {
                    printf("You must enter a destination for the drive dump\n");
                    return 1;
                }
                else
                {
                    if(strcmp(argv[3],"/")==0)
                    {
                        printf("You have assigned %s as your destination, this is very dangerous....do you want to proceed?:(y,n) ",argv[3]);
                        char t=getchar();
                        if(t=='y')
                        {
                            if(argc>5)
                            {
                                data_dump(argv[2],argv[3],drive_bsize);
                                return 0;
                            }
                            else
                            {
                                data_dump(argv[2],argv[3],argv[4]);
                                return 0;
                            }
                        }
                        else
                            return 0;

                    }
                    if(argc<5)
                        data_dump(argv[2],argv[3],drive_bsize);
                    else
                        data_dump(argv[2],argv[3],argv[4]);
                }
            }
        }
//Sparse raw unallocated recovery
        else if(strcmp(argv[1],"-Rsau")==0)
        {
            if(argc<3)
            {
                printf("You must specify an image\n");
                return 1;
            }
            else if(argc<4)
            {
                printf("You must specify a keyword\n");
                return 1;
            }
            else
            {
                sparse_accurate_unalloc(argv[2],argv[3]);

            }
        }
//Handling help printing
        else if(strcmp(argv[1],"-h")==0 || strcmp(argv[1],"--help")==0)
        {
            help();
            return 0;
        }
//Validating files
        else if(strcmp(argv[1],"-v")==0)
        {
            if(argc<3)
            {
                printf("You must enter a filename\n");
                return 1;
            }
            else if(argc<4)
            {
                printf("You must enter a second filename\n");
                return 1;
            }
            else
            {
                checksum(argv[2],argv[3]);
                return 0;
            }
        }

//Handleing mounting the file systems read only.
        else if(strcmp(argv[1],"-mr")==0)
        {
            if(argc<3)
            {
                printf("You must enter a filesystem or device to mount\n");
                return 1;
            }
            else if(argc<4)
            {
                printf("You must specify a mount point\n");
                return 1;
            }
            else
                mount(argv[2],argv[3],1);
        }
//Handling mounting the filesystem with write support
        else if(strcmp(argv[1],"-m")==0)
        {
            if(argc<3)
            {
                printf("You must enter a filesystem or device to mount\n");
                return 1;
            }
            else if(argc<4)
            {
                printf("You must specify a mount point\n");
                return 1;
            }
            else
                mount(argv[2],argv[3],0);
        }

//ascii block searching(nothing else)
        else if(strcmp(argv[1],"-sb")==0)
        {
            if(argc<3)
            {
                printf("You must enter a filename\n");
                return 1;
            }
            else if(argc<4)
            {
                printf("You must enter a search string\n");
                return 1;
            }
            else
                ascii_block_search(argv[3],argv[2]);
        }
        //Handling controlled dumps
        else if(strcmp(argv[1],"-cd")==0)
        {
            if(argc<3)
            {
                printf("You must enter a source file\n");
                return 1;

            }
            else if(argc<4)
            {
                printf("You must enter a destination file\n");
                return 1;
            }
            else if(argc<5)
            {
                printf("You must enter a starting point in bytes\n");
                return 1;
            }
            else if(argc<6)
            {
                printf("You must enter an amount of times to collect the data\n");
                return 1;
            }
            else if(argc<7)
            {
                controlled_dump(argv[2],argv[3],drive_bsize,argv[5],argv[4]);
                return 0;
            }
            else
            {
                controlled_dump(argv[2],argv[3],argv[6],argv[5],argv[4]);
                return 0;
            }
        }
        //Spare search of unallocated space
        else if(strcmp(argv[1],"-Rsu")==0)
        {
            if(argc<3)
            {
                printf("You must specify an image or source\n");
                return 1;
            }
            else if(argc<4)
            {
                printf("You must enter a searchword\n");
                return 1;
            }
            else
            {
                sparse_unalloc(argv[2],argv[3]);
                return 0;
            }
        }
        //Recover all unallocated files
        else if(strcmp(argv[1],"-Ru")==0)
        {
            if(argc<3)
            {
                printf("You must specify an image or source\n");
                return 1;
            }
            else
            {
                all_unalloc(argv[2]);
                return 0;
            }
        }
        //Accurate recovery of all files in unallocated space
        else if(strcmp(argv[1],"-Rau")==0)
        {
            if(argc<3)
            {
                printf("You must specify an image or source\n");
                return 1;
            }
            else
            {
                accurate_all_unalloc(argv[2]);
                return 0;
            }

        }
        //Search for a specific filename in an image
        else if(strcmp(argv[1],"-s")==0)
        {
            if(argc<3)
            {
                printf("You must enter a source file\n");
                return 1;
            }
            else if(argc<4)
            {
                printf("You must enter a file to search for\n");
                return 1;
            }
            else
            {
                search_all(argv[2],argv[3]);
                return 0;
            }
        }

        //Listing all files in an image
        else if(strcmp(argv[1],"-l")==0)
        {
            if(argc<3)
            {
                printf("Enter a filesystem to scan\n");
                return 1;
            }
            else
            {
                list_all(argv[2]);
                return 0;
            }
        }
        //Sparse search
        else if(strcmp(argv[1],"-Rs")==0)
        {
            if(argc<3)
            {
                printf("You must specify an image\n");
                return 1;

            }
            else if(argc<4)
            {
                printf("You must specify a keyword\n");
                return 1;
            }
            else
            {
                sparse_all(argv[2],argv[3]);
                return 0;
            }
        }
        //Get all files in tact
        else if(strcmp(argv[1],"-R")==0)
        {
            if(argc<3)
            {
                printf("You must specify an image\n");
                return 1;
            }
            else
            {
                get_everything(argv[2]);
                return 0;
            }
        }
        else if(strcmp(argv[1],"-Ra")==0)
        {
            if(argc<3)
            {
                printf("You must specify an image\n");
            }
            else
            {
                accurate_all(argv[2]);
                return 0;
            }
        }
        //Recover a specific inode
        else if(strcmp(argv[1],"-Ri")==0)
        {
            if(argc<3)
            {
                printf("You must specify an image\n");
                return 1;
            }
            else if(argc<4)
            {
                printf("You must enter an inode\n");
                return 1;
            }
            else
            {
                accurate_recover_inode(argv[2],argv[3]);
                return 0;
            }

        }
        //Else
        else
        {
            printf("You have entered giberish, please attend to your errors\n");
            return 0;
        }

    }
}
示例#21
0
int main(int argc, char *argv[]) {
    int error = 0;
    char command[20];
    char args[10][10];
    int pid = 0;
    int psw = 0;
    int page_table = 0;
    int reg1 = 0;
    int reg2 = 0;
    int reg3 = 0;
    int group = 0;
    int regs[3];
    FILE *file;
	int priority = 0;
    if (argc == 1){
        file = stdin;
    }
    else if (argc == 2){
        file = fopen(argv[1], "r");
    }
    else{
        printf("Usage:\n./processmanager_test.o (to read from stdin)\n");
        printf("./processmanager_test.o <filename> (to read from filename)\n");
        exit(-1);
    }

    init(GROUP);


    while(1) {
        /*printf("***reading the file***\n");*/
        if (file == stdin) {
            printf("> ");
        }
        error = fscanf(file," %s", command);
        if (error == 1){
            /* printf("%s\n", line); */
            /* printf("%s\n", command); */

            if (!strcmp(command, "INIT")) {
                error = fscanf(file, " %s", args[0]);
                if (error == 1){
                    if (!strcmp(args[0], "GROUP")){
                        printf("\n***INIT command issued (%s)***\n", args[0]);
                        init(GROUP);
                    }
                    else if(!strcmp(args[0], "PRIORITY")){
                        printf("\n***INIT command issued (%s)***\n", args[0]);
                        init(PRIORITY);
                    }
                    else{
                        printf("Usage: INIT <GROUP | PRIORITY>\n");
                    }
                }
                else{
                    printf("Usage: INIT <GROUP | PRIORITY>\n");
                }

            }
            else if (!strcmp(command, "LIST")) {
                error = fscanf(file, " %s", args[0]);
                if (error == 1){
                    printf("\n***LISTING command issued (%s)***\n", args[0]);
                    if (!strcmp(args[0], "NEW")){
                        list_Q(NEW);
                    }
                    else if (!strcmp(args[0], "WAITING")){
                        list_Q(WAITING);
                    }
                    else if (!strcmp(args[0], "READY")){
                        list_ready();
                    }
                    else if (!strcmp(args[0], "TERMINATED")){
                        list_Q(TERMINATED);
                    }
                    else if (!strcmp(args[0], "RUNNING")){
                        list_Q(RUNNING);
                    }
                    else if (!strcmp(args[0], "ALL")){
                        list_all();
                    }
                    else if (!strcmp(args[0], "SCHED")){
                        list_sched();
                    }
                    else{
                        printf("Usage: LIST <NEW | WAITING | READY | TERMINATED | RUNNING | ALL | SCHED>\n");
                    }
                }
                else{
                    printf("Usage: LIST <NEW | WAITING | READY | TERMINATED | RUNNING | ALL | SCHED>\n");
                }
            }
            else if (!strcmp(command, "GO")){
                printf("\n***GO command issued***\n");
                error = go();
                if (error == ERROR_NO_READY_PROCESS){
                    printf("Could not GO: %s\n", error_to_string(error));
                }
                else if (error == ERROR_QUEUE_EMPTY ||
						error == ERROR_QUEUE_FULL ||
						error == ERROR_SWITCH_DEFAULT ||
						error == ERROR_PROCESS_NOT_EXIST){
                    printf("FATAL ERROR: %s\n", error_to_string(error));
                    exit(-1);
                }
            }
            else if (!strcmp(command, "UNWAIT")) {
                error = fscanf(file, " %d", &pid);
                if (error == 1){
                    printf("\n***UNWAIT command issued (PID: %d)***\n", pid);
                    error = unwait(pid);
                    if (error == ERROR_QUEUE_EMPTY){
                        printf("Could not UNWAIT: No waiting processes\n");
                    }
                    else if (error == ERROR_PROCESS_NOT_EXIST){
                        printf("Could not UNWAIT: PID does not exist in waiting queue\n");
                    }
                    else if (error == ERROR_QUEUE_FULL){
                        printf("FATAL ERROR: %s\n", error_to_string(error));
                        exit(-1);
                    }
                }
                else{
                    printf("Usage: UNWAIT <pid>\n");
                }
            }
			else if (!strcmp(command, "SET_PRIORITY")) {

				error = fscanf(file, " %d %d", &pid, &priority);
				if (error == 2){
					printf("\n***SET_PRIORITY command issued (PID: %d)***\n", pid);
					error = set_priority(pid, priority);
					if (error == ERROR_WRONG_SCHEDULER){
						printf("Could not SET_PRIORITY: Command only avaliable in Priority Scheduler\n");
					}
					else if (error == ERROR_PROCESS_NOT_EXIST){
						printf("Could not SET_PRIORITY: PID does not exist in ready queue\n");
					}
					else if (error == ERROR_INVALID_PARAMETER){
						printf("Could not SET_PRIORITY: Priority must be between 1 and %d\n", MAX_PRIORITY);
					}
				}
				else{
					printf("Usage: SET_PRIORITY <pid> <priority>\n");
				}

            }
            else if (!strcmp(command, "EOLIFE")) {
                printf("\n***EOLIFE command issued***\n");
                error = eolife();
                if (error == ERROR_QUEUE_EMPTY){
                    printf("Could not EOLIFE: No running processes\n");
                }
                else if (error == ERROR_QUEUE_FULL){
                    printf("FATAL ERROR: %s\n", error_to_string(error));
                    exit(-1);
                }
            }
            else if (!strcmp(command, "WAIT")) {
                printf("\n***WAIT command issued***\n");
                error = wait_();
                if (error == ERROR_QUEUE_EMPTY){
                    printf("Could not WAIT: No running processes\n");
                }
                else if (error == ERROR_QUEUE_FULL){
                    printf("FATAL ERROR: %s\n", error_to_string(error));
                    exit(-1);
                }
            }
            else if (!strcmp(command, "CREATE")) {
                /*Group Scheduler*/
                if (scheduler == GROUP){
                    error = fscanf(file, " %d %d %d %d %d %d", &psw, &page_table, &reg1, &reg2, &reg3, &group);
                    if (error == 6){
                        /* printf("pid: %d, psw: %d, page_table: %d, reg1: %d, reg2: %d, reg3: %d\n", pid, psw, page_table, reg1, reg2, reg3); */
                        regs[0] = reg1;
                        regs[1] = reg2;
                        regs[2] = reg3;

						error = create(psw, page_table, regs, group);
						if (error == ERROR_MAX_PROCESSES){
							printf("Could not CREATE: Maximum allowed processes reached\n");
						}
						else if (error == ERROR_GROUP_NOT_EXIST){
							printf("Could not CREATE: Invalid group number\n");
						}
						else if (error == ERROR_PROCESS_NOT_UNIQUE ||
						error == ERROR_QUEUE_FULL ||
						error == ERROR_QUEUE_EMPTY ||
						error == ERROR_QUEUE_FULL) {
							printf("FATAL ERROR: %s\n", error_to_string(error));
							exit(-1);
						}
						else if (error == ERROR_SUCCESS){
							printf("\n***CREATE command issued (PID: %d)***\n", (pid_counter - 1));
						}
					}
					else{
						printf("Usage: CREATE <psw> <page_table> <reg1> <reg2> <reg3> <group>\n");
					}
				}
				/*Priority Scheduler*/
				else{
					error = fscanf(file, " %d %d %d %d %d", &psw, &page_table, &reg1, &reg2, &reg3);
					if (error == 5){
						/* printf("pid: %d, psw: %d, page_table: %d, reg1: %d, reg2: %d, reg3: %d\n", pid, psw, page_table, reg1, reg2, reg3); */
						regs[0] = reg1;
						regs[1] = reg2;
						regs[2] = reg3;

						printf("\n***CREATE command issued (PID: %d)***\n", pid_counter);
						/*Priority scheduler defaults to group 0*/
						error = create(psw, page_table, regs, 0);
						if (error == ERROR_MAX_PROCESSES){
							printf("Could not CREATE: Maximum allowed processes reached\n");
						}
						else if (error == ERROR_PROCESS_NOT_UNIQUE ||
						error == ERROR_QUEUE_FULL ||
						error == ERROR_QUEUE_EMPTY ||
						error == ERROR_QUEUE_FULL ||
						error == ERROR_GROUP_NOT_EXIST) {
							printf("FATAL ERROR: %s\n", error_to_string(error));
							exit(-1);
						}
						else if (error == ERROR_SUCCESS){
							printf("\n***CREATE command issued (PID: %d)***\n", (pid_counter - 1));
						}
					}
					else{
						printf("Usage: CREATE <psw> <page_table> <reg1> <reg2> <reg3>\n");
					}
				}
            }
            else if (!strcmp(command, "EMPTY_TERM")){
                printf("\n***EMPTY_TERM command issued***\n");
                error = empty_term();
                if (error == ERROR_QUEUE_EMPTY){
                    printf("Could not EMPTY_TERM: No process in terminated queue\n");
                }
            }
            else if (!strcmp(command, "#")) {
                printf("\n################################################################################\n");
                printf("#");
                textcolor(BRIGHT, WHITE, BLACK);
                printf("%s\n", fgetstring(file));
                textcolor(RESET, -1, -1);
                printf("################################################################################\n");
            }
            else {
                printf("Unrecognized command: %s\n", command);
            }
        }
        else
            if (error == EOF) {
                printf("\n");
                break;
            }
    }

    fclose(file);

    return(0);
}
示例#22
0
/* 
 * Main                
 */
int
main(int argc, char **argv)
{
	SaErrorT 	rv = SA_OK;
	
	SaHpiVersionT	hpiVer;
	SaHpiSessionIdT sessionid;
	SaHpiResourceIdT resourceid = all_resources;

	int c;
	    
	printf("\n\n%s ver %s\n",argv[0],progver);
	while ( (c = getopt( argc, argv,"adrsiwcn:x?")) != EOF ) {
		switch(c) {
			case 'a': f_listall = 1; break;
			case 'c': f_ctrl    = 1; break;
			case 'd': f_rdr    = 1; break;
			case 'i': f_inv     = 1; break;
			case 'r': f_rpt     = 1; break;
			case 's': f_sensor  = 1; break; 
			case 'w': f_wdog  = 1; break; 
			case 'n':
				if (optarg)
					resourceid = atoi(optarg);
				else 
					resourceid = all_resources;
				break;
			case 'x': fdebug = 1; break;
			default:
				printf("\n\tUsage: %s [-option]\n\n", progname);
				printf("\t      (No Option) Display all rpts and rdrs\n");
				printf("\t           -a     Display all rpts and rdrs\n");
				printf("\t           -c     Display only controls\n");
				printf("\t           -d     Display rdr records\n");
				printf("\t           -i     Display only inventories\n");
				printf("\t           -r     Display only rpts\n");
				printf("\t           -s     Display only sensors\n");
				printf("\t           -w     Display only watchdog\n");				
				printf("\t           -n     Select particular resource id to display\n");
				printf("\t                  (Used with [-cdirs] options)\n");
				printf("\t           -x     Display debug messages\n");
				printf("\n\n\n\n");
				exit(1);
		}
	}
 
	if (argc == 1) f_listall = 1;

	/* 
	 * House keeping:
	 * 	-- get (check?) hpi implementation version
	 *      -- open hpi session	
	 */
	if (fdebug) printf("saHpiVersionGet\n");
	hpiVer = saHpiVersionGet();
	printf("Hpi Version %d Implemented.\n", hpiVer);

	if (fdebug) printf("saHpiSessionOpen\n");
        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL);
	if (rv != SA_OK) {
		printf("saHpiSessionOpen returns %s\n",oh_lookup_error(rv));
		exit(-1);
	}
	if (fdebug)
	       	printf("saHpiSessionOpen returns with SessionId %d\n", sessionid);

	/*
	 * Resource discovery
	 */
	if (fdebug) printf("saHpiDiscover\n");
	rv = saHpiDiscover(sessionid);
	if (rv != SA_OK) {
		printf("saHpiDiscover returns %s\n",oh_lookup_error(rv));
		exit(-1);
	}

	printf("Discovery done\n");
	if(f_listall) 
		list_all(sessionid);
	else {	
		if(f_rpt) list_rpt(sessionid,resourceid);
		if(f_rdr) list_rdr(sessionid,resourceid);
		if(f_sensor) list_sens(sessionid,resourceid);
		if(f_inv) list_inv(sessionid, resourceid); 
		if(f_ctrl) list_ctrl(sessionid, resourceid);
		if(f_wdog) list_wdog(sessionid, resourceid);
	}	

	rv = saHpiSessionClose(sessionid);
	
	exit(0);
}