int main(int ac, char *av[])
{
	if(ac == 1)
	{
		flag = NONOPTION ;	
		do_ls(".");
	}
	else
	{
		if(strcmp("-R", av[1]) == 0 )
		{
			flag = OPTION ;	
			printf("-R Option \n");
			do_ls(".");
		}
		else
		{	
			while(--ac){
				flag = INSERTPATH;
				printf("Directory : %s\n",*av);
				chdir(*av);
				do_ls(".");
			}
		}
	}
}
示例#2
0
文件: list.c 项目: sunshineMaria/test
int main(int argc, char **argv)

{

  if (argc == 1)

  { 

    do_ls( "." );

  }

  else

  { 

    while ( --argc )

    {

      printf("%s:\n", *++argv );

      chdir(*argv); //切换到指定目录后再显示该目录的内容

      do_ls( *argv );

      chdir(""); //再回到当前工作目录来

    }

  }

  return 0;

}
示例#3
0
文件: ls2.c 项目: orange8637/c
/*主函数*/
int main(int ac, char **av)
{
		/*捕获程序选项*/
		const char* const short_optiones = "l";
		const struct option long_options[] = { {"long list", 0, NULL, "l"} };
		int opt;
		while((opt = getopt_long(ac, av, "l", long_options, NULL)) != -1)
		{
			switch(opt)
			{
				case 'l':
					longlist = 1;
					break;
				default:
					break;
			}
		}
		int i;
		/*对程序参数处理*/
		for(i = optind; i < ac; i++)
		{
			printf("%s:\n", av[i]);
			do_ls(av[i]);
		}
		/*程序没有参数时默认显示当前目录*/
		if(ac == 1 || i == optind)
			do_ls(".");
	return 0;
}
示例#4
0
int main(int argc, char *argv[])
{
    int next_option;
    /* A string listing valid short options letters.  */
    const char* const short_options = "l";
    /* An array describing valid long options. */
    const struct option long_options[] = {
        {"l",0,NULL,'l'},
        {NULL,0,NULL,0}   /* Required at end of array.  */
    };
    
    int opt_count = 0,i = 0,j = 0;
              
    do {
        next_option = getopt_long(argc,argv,short_options,
                                  long_options, NULL);
        switch (next_option)
        {
            case 'l':   /* -l */
                if (argc == 2)
                    do_ls(".",1);
                else
                    while (--argc){
                        if ((*++argv)[0] == '-')
                            continue;
                        printf("%s:\n",*argv);
                        do_ls(*argv,1);
                        if (argc > 1)
                            printf("\n");
                    }
                opt_count++;
                break;
            case -1:    /* Done with options.  */
                if (opt_count > 0)
                    break;
                if (argc == 1)
                    do_ls(".",0);
                else
                {
                    while (--argc){
                        if ((*++argv)[0] == '-')
                            continue;
                        printf("%s:\n",*argv);
                        do_ls(*argv,0);
                        if (argc > 1)
                            printf("\n");
                    }
                }
                break;
            default:    /* Something else: unexpected.  */
                abort ();
        };
    }
    while (next_option != -1);
    return 0;
}
示例#5
0
文件: ls1.c 项目: Og192/CPro
int main(int argc, char *argv[])
{
	if(argc == 1)
		do_ls(".");
	else
		while(--argc){
			printf("%s:\n", *++argv);
			do_ls(*argv);
		}
}
示例#6
0
文件: ls2.c 项目: Yokoloki/Books
int main(int ac, char *av[]){
    if(ac == 1)
        do_ls(".");
    else{
        while(--ac){
            printf("%s:\n", *(++av));
            do_ls(*av);
        }
    }
}
main(int ac, char *av[])
{
if(ac==1) do_ls(".", non_rec);
else if (ac==2 && strcmp(av[1],"-R")==0){
do_ls(".", rec);
}
else{
while(--ac) do_ls(*++av, non_rec);
}
}
示例#8
0
int main(int ac, char *av[])
{
	if (ac == 1)
		do_ls(".");
	else
		while(--ac){
			printf("%s:\n", * ++av);
			do_ls(*av);
		}
	return 0;
}
void main(int ac, char *av[])
{

  if (ac == 1)
     do_ls(".");
  else
     while (--ac) {
       printf("%s\n", * ++av);
       do_ls(*av);
     }
}
示例#10
0
文件: ls2.c 项目: acgtyrant/UULP
int main(int argc, char *argv[]) {
  if (argc == 1) {
    do_ls(".");
  }
  else {
    while (--argc) {
      printf("%s:\n", *++argv);
      do_ls(*argv);
    }
  }
  return EXIT_SUCCESS;
}
示例#11
0
文件: ls5.c 项目: zyfforlinux/code
int main(int argc,char *argv[])
{
	if(argc == 1)
		do_ls(".");
	else
/*
 *依次遍历每一个参数,打印目录下的所有文件
 */
		while(--argc){
			printf("%s:\n",*++argv);
			do_ls(*argv);
		}
}
示例#12
0
文件: hometask.c 项目: ImHantu/dzOS
int main(int ac, char *av[])
{
    mkdir("directory", 0777);
    printf("Files in Directory are:\n");
    if (ac==1)
        do_ls(".");
    else
        while (--ac)
        {
            printf("%s:\n", *++av);
            do_ls( *av);
        }
    return 0;
}
示例#13
0
int main(int argc, const char* argv[])
{
    if (argc == 1) {
        do_ls(".");
    } else {
        while (--argc)
        {
            printf("%s:\n", *++argv);
            do_ls(*argv);
        }
    }

    return 0;
}
void main(int ac, char* av[])
{
        if(ac == 1)
                do_ls(".");
        else if(ac == 2)
        {
                if(((strcmp("-R", av[1])) == 0)){
                        rels(".");
                }
        }
        else
                while( --ac){
                printf("%s:\n", * ++av);
                do_ls(*av);
                }
}
示例#15
0
文件: child.c 项目: bailili/learngit
void recv_request(int newfd)
{
	char buf[2048];
	int ret;
	while(1)
	{
		bzero(buf,sizeof(buf));
		ret=recv(newfd,buf,sizeof(buf),0);
		if(ret==0)
		{
			break;
		}
		if(strncmp("cd",buf,2)==0)
		{
			do_cd(newfd,buf);
	}else if(strncmp("ls",buf,2)==0)
	{
		do_ls(newfd,buf);
	}else if(strncmp("puts",buf,4)==0)
	{
		do_puts(newfd);
	}else if(strncmp("gets",buf,4)==0)
	{
		do_gets(newfd,buf);
	}else if(strncmp("remove",buf,6)==0)
	{
		do_remove(newfd,buf);
	}else if(strncmp("pwd",buf,3)==0)
	{
		do_pwd(newfd,buf);
	}else{
		continue;
	}
	}
}
void do_ls(char dirname[], int check_rec)
{
printf("%s:\n", dirname);
DIR *dir_ptr;
struct dirent *direntp;
if((dir_ptr = opendir(dirname)) == NULL )
fprintf(stderr, "ls1: cannot open %s\n", dirname);
else
{
while((direntp = readdir(dir_ptr))!=NULL)
dostat(direntp->d_name,dirname);
closedir(dir_ptr);
printf("\n");

if(check_rec)
{
dir_ptr = opendir(dirname);
while((direntp = readdir(dir_ptr)) != NULL)
{
char sub_dir[255];
struct stat info;
if(strcmp(direntp->d_name,".") == 0 || strcmp(direntp->d_name,"..") == 0) continue;
sprintf(sub_dir, "%s/%s", dirname, direntp->d_name);
stat(sub_dir, &info);
if(S_ISDIR(info.st_mode)) do_ls(sub_dir, rec);
}
closedir(dir_ptr);
}
}
}
示例#17
0
int main(int argc, char **argv)
{
    int rc = 0;
    char *fn, *sfn;

    INITIALIZE_UTILITY("dasdls");

    /* Display program info message */
    display_version (stderr, "Hercules DASD list program ", FALSE);

    if (argc < 2) {
        fprintf(stderr, "Usage: dasdls dasd_image [sf=shadow-file-name]...\n");
        exit(2);
    }

    /*
     * If your version of Hercules doesn't have support in its
     * dasdutil.c for turning off verbose messages, then remove
     * the following line but you'll have to live with chatty
     * progress output on stdout.
     */
    set_verbose_util(0);

    while (*++argv)
    {
        fn = *argv;
        if (*(argv+1) && strlen (*(argv+1)) > 3 && !memcmp(*(argv+1), "sf=", 3))
            sfn = *++argv;
        else sfn = NULL;
        if (do_ls(fn, sfn))
            rc = 1;
    }

    return rc;
}
示例#18
0
static void
do_cmd(int client, char *buf)
{
    char *cp = buf+strlen(buf)-1;
    while ((*cp == '\n') || (*cp == '\r')) {
        *cp-- = '\0';  // Remove trailing terminators
    }
    printf("Command: %s\n", buf);
    if (strncmp(buf, "ls", 2) == 0) {
        do_ls(client, buf);
    } else
    if (strncmp(buf, "show_all", 8) == 0) {
        do_show_all(client, buf);
    } else
    if (strncmp(buf, "show", 4) == 0) {
        do_show(client, buf);
    } else
    if (strncmp(buf, "time", 4) == 0) {
        do_time(client, buf);
    } else
    if (strncmp(buf, "get", 3) == 0) {
        do_get(client, buf);
    } else
    if (strncmp(buf, "rm", 2) == 0) {
        do_rm(client, buf);
    } else
    {
        fdprintf(client, "Unknown command: %s\n", buf);
    }
}
示例#19
0
文件: ls.c 项目: iceout/uup
int main(int argc, char *argv[])
{
    const char* optstring = "al";
    char *pwd;
    int opt = 0;
    int ind = 0;
    while ((opt = getopt(argc, argv, optstring)) != -1){
        switch (opt) {
            case 'a':
                lsa = 1;
                printf("lsa = true\n");
                break;
            case 'l':
                lsl = 1;
                printf("lsl = true\n");
                break;
            case '?':
            default:
                printf("???\n");
                break;
        }
    }
    ind = optind;
    if (ind < argc) {
        while (ind < argc) {
            printf("ind == %d\n", ind);
            do_ls(*(argv+ind));
            ind++;
            if (ind != argc) {
                printf("\n");
            }
        }
    }
    else {
        do_ls(".");
    }
    /*if (argc == 1) {
        do_ls(".");
    }
    else {
        while (--argc) {
            printf("%s:\n", * ++argv);
            do_ls(*argv);
        }
    }*/
    return 0;
}
示例#20
0
int main(int argc, char *argv[])
{
     //如果没有参数,则默认列出当前目录
     if (argc == 1)
     {
	  do_ls(".");
     }
     else
     {
	  while (--argc)
	  {
	       printf("%s:\n", *(++argv));
	       do_ls(*argv);
	  }
     }
     return 0;
}
示例#21
0
文件: fs.c 项目: 565407548/micro_os
void task_fs(){
#ifdef DEBUG_FS
    printl("in task_fs\n");
#endif
    init_fs();
    MESSAGE message;
    memset(&message,0,sizeof(message));
    while(TRUE){
        send_receive(RECEIVE,ANY,&message);
        
        int source_pid=message.source_pid;
        int fd;
	
        switch(message.type){
        case INFO_FS_CREATE:
            message.res_bool=do_create(&message);
            break;
        case INFO_FS_UNLINK:
            message.res_bool=do_unlink(&message);
            break;
        case INFO_FS_LS:
            message.res_int=do_ls(&message);
            break;
        case INFO_FS_OPEN:
            fd=do_open(&message);
            message.fd=fd;
            break;
        case INFO_FS_READ:
            do_read(&message);
            break;
        case INFO_FS_WRITE:
            do_write(&message);
            break;
        case INFO_FS_SEEK:
            do_seek(&message);
            break;
        case INFO_FS_CLOSE:
            message.res_int=do_close(&message);
            break;
        default:
            printl("\n\n\nunknown message type:%d\n",message.type);
            assert(FALSE,"unknown message type!");
        }
        if(message.type!=INFO_SUSPEND_PROCESS){
            send_receive(SEND,source_pid,&message);
        }else{
            printl("inof_suspend_process\n");
        }
    }
#ifndef _FS_H_
#define _FS_H_
    
#endif /* _FS_H_ */
    while(1)
        ;
    spin("never here");
}
示例#22
0
文件: main.c 项目: IC15BHR/myfind
/**
 * @brief checks the entry using subfunctions based on params, if passed, prints it
 *
 * @param path the path to be processed
 * @param params the parsed parameters
 * @param attr the entry attributes from lstat
 *
 * @returns EXIT_SUCCESS, EXIT_FAILURE
 */
int do_file(char *path, params_t *params, struct stat attr) {
  int printed = 0;

  do {
    /* ### FB: Mit ENUM Feld könnte hier ein switch genutzt werden und für mehr Übersicht sorgen. */
    /* filtering */
    if (params->type) {
      if (do_type(params->type, attr) != EXIT_SUCCESS) {
        return EXIT_SUCCESS; /* the entry didn't pass the check, do not print it */
      }
    }
    if (params->nouser) {
      if (do_nouser(attr) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    if (params->user) {
      if (do_user(params->userid, attr) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    if (params->name) {
      if (do_name(path, params->name) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    if (params->path) {
      if (do_path(path, params->path) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    /* printing */
    if (params->print) {
      if (do_print(path) != EXIT_SUCCESS) {
        return EXIT_FAILURE; /* a fatal error occurred */
      }
      printed = 1;
    }
    if (params->ls) {
      if (do_ls(path, attr) != EXIT_SUCCESS) {
        return EXIT_FAILURE;
      }
      printed = 1;
    }

    params = params->next;
  } while (params);

  if (printed == 0) {
    if (do_print(path) != EXIT_SUCCESS) {
      return EXIT_FAILURE;
    }
  }

  return EXIT_SUCCESS;
}
示例#23
0
文件: ls.c 项目: Lihaoyang1992/CS631
int
main(int argc, char **argv)
{
	if (argc > 2) {
		fprintf(stderr, "usage: %s dir_name\n", argv[0]);
		exit(1);
	}

	if (argc == 1) {
		do_ls(".");
	} else {
		while (--argc) {
			printf("%s:\n", * ++argv);
			do_ls(*argv);
		}
	}

	return 0;
}
示例#24
0
文件: main.c 项目: amq/myfind
/**
 * @brief checks the entry using subfunctions based on params, if passed, prints it
 *
 * @param path the path to be processed
 * @param params the parsed parameters
 * @param attr the entry attributes from lstat
 *
 * @returns EXIT_SUCCESS, EXIT_FAILURE
 */
int do_file(char *path, params_t *params, struct stat attr) {
  int printed = 0;

  do {
    /* filtering */
    if (params->type) {
      if (do_type(params->type, attr) != EXIT_SUCCESS) {
        return EXIT_SUCCESS; /* the entry didn't pass the check, do not print it */
      }
    }
    if (params->nouser) {
      if (do_nouser(attr) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    if (params->user) {
      if (do_user(params->userid, attr) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    if (params->name) {
      if (do_name(path, params->name) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    if (params->path) {
      if (do_path(path, params->path) != EXIT_SUCCESS) {
        return EXIT_SUCCESS;
      }
    }
    /* printing */
    if (params->print) {
      if (do_print(path) != EXIT_SUCCESS) {
        return EXIT_FAILURE; /* a fatal error occurred */
      }
      printed = 1;
    }
    if (params->ls) {
      if (do_ls(path, attr) != EXIT_SUCCESS) {
        return EXIT_FAILURE;
      }
      printed = 1;
    }

    params = params->next;
  } while (params);

  if (printed == 0) {
    if (do_print(path) != EXIT_SUCCESS) {
      return EXIT_FAILURE;
    }
  }

  return EXIT_SUCCESS;
}
示例#25
0
文件: ls.c 项目: Goryudyuma/OS3
int main(int argc, char *argv[]) {
	int i;
	if (argc < 2) {
		fprintf(stderr, "%s: no arguments\n", argv[0]);
		exit(1);
	}
	for (i = 1; i < argc; i++) {
		do_ls(argv[i]);
	}
	exit(0);
}
示例#26
0
文件: ls.c 项目: usqcd-software/aff
static int 
do_ls_keylist(struct AffReader_s *r, const char *name, const char *list_fname)
{
    FILE *list = NULL;
    if(0 == strcmp(list_fname, "-")) {
        list = stdin;
        if (ferror(list)) {
            fprintf(stderr, "%s: bad stdin stream\n", __func__);
            return 1;
        }
    }
    else {
        if (NULL == (list = fopen(list_fname, "r"))) {
            fprintf(stderr, "%s: cannot open %s\n", __func__, list_fname);
            return 1;
        }
    }
    char buf[16384], *fargv[1];
    int num;
    while (NULL != fgets(buf, sizeof(buf), list)) {
        if ('\n' != buf[strlen(buf)-1]) {
            fprintf(stderr, "%s: line too long, skipping\n", __func__);
            while (NULL != fgets(buf, sizeof(buf), list))
                if ('\n' == buf[strlen(buf)-1])
                    break;
            continue;
        }
        num = split_farg( buf, 1, fargv );
        if (num < 0) {
            fprintf(stderr, "%s: unexpected result of split_farg; exiting\n",
                    __func__);
            goto errclean_r;
        }
        if (num == 0)
            continue;
        if (do_ls(r, name, fargv[0])) {
            fprintf(stderr, "%s: [%s]: %s\n", __func__, fargv[0],
                    aff_reader_errstr(r));
            goto errclean_r;
        }
    }
    
    fclose(list);
    return 0;
    
errclean_r:
    fclose(list);
    return 1;
}
示例#27
0
文件: ls1.c 项目: benbee/Learning
int main(int argc, char *argv[])
{
    struct node *file_list;
    struct node *p;
    int max_item_len;

    struct winsize w;
    ioctl(0, TIOCGWINSZ, &w);

    LINE_LEN = w.ws_col;
    printf("Line Length: %d\n", LINE_LEN);

    file_list = init_list();
    file_list->next = NULL;

    printf("argc: %d\n", argc);
    handle_argv(argc, argv);

    printf("a_flag: %d\nr_flag: %d\n", a_flag, r_flag);

    if (argc == 1) {
        do_ls(".", file_list);
    } else {
        while (--argc) {
            printf("%s\n", *++argv);
            if (*argv[0] != '-') {
                do_ls(*argv, file_list);
            }
        }
    }

    //print_list(file_list);
    //printf("Max item length: %d", get_item_max_len(file_list));
    free_list(file_list);
    return 0;
}
示例#28
0
void client_handle(psession_t ps)
{

	socket_t fd_client = ps -> sess_sfd ;
	int cmd_len = 0 ;
	int recv_ret ;
	while(1 )
	{
		bzero(ps -> sess_buf, BUF_SIZE);
		recv_ret = recv(fd_client, &cmd_len, sizeof(int),0);
		if(cmd_len == 0 || recv_ret == 0)
		{
			printf("client exit !\n");
			close(ps ->sess_sfd);
			free(ps);
			exit(1);
		}
		recvn(fd_client, ps->sess_buf, cmd_len);
		if(strncmp("cd", ps ->sess_buf, 2) == 0)
		{
			do_cd(ps);
		}else if(strncmp("ls", ps ->sess_buf, 2) == 0)
		{
			do_ls(ps);
		}else if( strncmp("puts", ps ->sess_buf, 4)== 0)
		{
			do_puts(ps);
		}else if( strncmp("gets", ps ->sess_buf, 4)== 0)
		{
			do_gets(ps);

		}else if( strncmp("remove", ps ->sess_buf, 6)== 0)
		{
			do_remove(ps);

		}else if(strncmp("pwd", ps ->sess_buf, 3) == 0) 
		{
			do_pwd(ps);

		}else 
		{
			continue ;
		}


	}
}
示例#29
0
/* ------------------------------------------------------ *
   process_rq( char *rq, int fd )
   do what the request asks for and write reply to fd 
   handles request in a new process
   rq is HTTP command:  GET /foo/bar.html HTTP/1.0
   ------------------------------------------------------ */
process_rq( char *rq, int fd)
{
	char	cmd[BUFSIZ], arg[BUFSIZ];

	if ( sscanf(rq, "%s%s", cmd, arg) != 2 )
		return;
	sanitize(arg);
	printf("sanitized version is %s\n", arg);

	if ( strcmp(cmd,"GET") != 0 )
		not_implemented();
	else if ( built_in(arg, fd) )
		;
	else if ( not_exist( arg ) )
		do_404(arg, fd);
	else if ( isadir( arg ) )
		do_ls( arg, fd );
	else
		do_cat( arg, fd );
}
示例#30
0
文件: webserv.c 项目: acgtyrant/UULP
extern void process_rq(char *request, int sock_fd) {
  char cmd[BUFSIZ], arg[BUFSIZ];
  strcpy(arg, "./");
  sscanf(request, "%s %s", cmd, arg + 2);

  if (fork() != 0)
    return ;

  if (strcmp(cmd, "GET") != 0) {
    cannot_do(sock_fd);
  } else if (not_exist(arg)) {
    do_404(arg, sock_fd);
  } else if (is_dir(arg)) {
    do_ls(arg, sock_fd);
  } else if (ends_in_cgi(arg)) {
    do_exec(arg, sock_fd);
  } else {
    do_cat(arg, sock_fd);
  }
}