All pastes #736019 Raw Edit

Mine

public text v1 · immutable
·published 2007-10-14 02:12 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>

#include <string.h>
#include <dirent.h>

int printhelp() {
  printf("blah\n");
  return 1;
}

int listdir(char *filename, int options) {
  DIR *d;
  struct dirent *e;
  d = opendir(".");
  if (d==NULL) {
      fprintf(stderr,"cannot access %s: No such file or directory\n",filename);
      abort();
      return 1;
  }
  //oneshot flag, if ever implemented
  if(options == 0) {
    while ((e=readdir(d)) != NULL) {
      printf(":%d: %s\n",e->d_type,e->d_name);
    }
  }
  if(options == 1) {
    printhelp();   
  }
  if(options == 4) {
    while ((e=readdir(d)) != NULL) {
      //printf("%s\n",strcat("test","blah"));
      //printf("%s\n",strcat(bdir,e->d_name));
      if(e->d_type == 4) {
        //char *tmp;
        //listdir(strcat(bdir,e->d_name),4);
      }
    }
  }
  
  closedir(d);
  return 0;
}

int main(int argc, char **argv) {
  strcat("test","test");
  if(argc == 1) {
    listdir(".",4);
    return 1;
  }
  int i;
  const char flags[][255] = { "-h","-a","-R","-l","-t" };
  const int flagval[] = { 1,2,4,8,16 };
  const int NOFLAGS = 5;
  int options = 4;
  for(i=1;i<argc-1;i++) {
    int j;
    for(j = 0; j<NOFLAGS; j++) {
      if(strcmp(argv[i],flags[j]) == 0) {
        options = options | flagval[j];
        break;
      }
    }
    if(j == NOFLAGS) {
      printhelp();
      return 1;;
    }
  }
  return -1;
  listdir(argv[argc-1],options);
  
}