Esempio n. 1
0
int bb_rmdir(const char *path)
{
    int retstat = 0;

    log_msg("bb_rmdir(path=\"%s\")\n",
	    path);

    retstat = myrmdir(path);

    if (retstat < 0)
	retstat = bb_error("bb_rmdir rmdir");

    return retstat;
}
Esempio n. 2
0
void myrmdir(char *dn)
{
 DIR *rd;
 struct dirent *tf;

 chdir(dn);
 rd=opendir(".");
 while((tf=readdir(rd))!=NULL) 
 {
  if(tf->d_name[0]!='.') 
   {
    if((tf->d_attr & _A_SUBDIR)==0) remove(tf->d_name);
    else
    {
     myrmdir(tf->d_name);
    }
   }
 }
 closedir(rd);
 chdir("..");
 rmdir(dn);
}
Esempio n. 3
0
void tr_process(long long n)
{
 FILE *tr,*fp;
 int tt;
 char s,*p;
 int cp,sz;

 sprintf(ftn,"%018Ld",n);
 tr=fopen(ftn,"rb");
 fread(&tt,sizeof(tt),1,tr);
 p=fn1; do{ fread(&s,1,1,tr); *p=s; p++;} while(s!=0);
 if(tt==TR_RENAME) 
  { 
   p=fn2; do{ fread(&s,1,1,tr); *p=s; p++;} while(s!=0); fclose(tr);
   rename(fn1,fn2); remove(ftn); return;
  }
 if(tt==TR_DELETE) 
  {
   fclose(tr); p=getcwd(NULL,0); myrmdir(fn1); chdir(p); remove(ftn); return;
  }
 if(tt==TR_UPDATE || tt==TR_CPOINT) 
  {
   cp=ftell(tr); fseek(tr,0,SEEK_END); sz=ftell(tr)-cp-2; fseek(tr,cp,SEEK_SET);
   fp=fopen(fn1,"wb");
    while(sz>4096) { fread(fn2,4096,1,tr); fwrite(fn2,4096,1,fp); sz-=4096; }
    if(sz>0) { fread(fn2,sz,1,tr); fwrite(fn2,sz,1,fp); }
   fclose(fp); fclose(tr); remove(ftn); return;
  }
 if(tt==TR_CREATE)
  { 
   mkdir(fn1); p=fn1; do{ fread(&s,1,1,tr); *p=s; p++;} while(s!=0);
   cp=ftell(tr); fseek(tr,0,SEEK_END); sz=ftell(tr)-cp-2; fseek(tr,cp,SEEK_SET);
   fp=fopen(fn1,"wb");
    while(sz>4096) { fread(fn2,4096,1,tr); fwrite(fn2,4096,1,fp); sz-=4096; }
    if(sz>0) { fread(fn2,sz,1,tr); fwrite(fn2,sz,1,fp); }
   fclose(fp); fclose(tr); remove(ftn); return;
  }
}
Esempio n. 4
0
main(int argc, char *argv[ ])
{
       //*Lab 5 CODE
  char *tok;
  char cmdArgs[2][MAX] = {'\0'};
  char cwd[128];
  int cmdCount = 0;
       //LAB 5 CODE*
  char temp[MAX];

  int n;
  char line[MAX], ans[MAX];

       //*Lab 5 CODE
  getcwd(cwd, 128);   // get CWD pathname
       // Lab 5 CODE*
  printf("cwd: %s\n", cwd);

  if (argc < 3){
     printf("Usage : client ServerName ServerPort\n");
     exit(1);
  }

  client_init(argv);
  // sock <---> server
  printf("********  processing loop  *********\n");
  while (1){
    //printf("input two numbers to add : ");
    //bzero(line, MAX);                // zero out line[ ]

          // *LAB 5 CODE
    cmdCount = 0;
    strcpy(cmdArgs[0],"");
    strcpy(cmdArgs[1],"");
    
    printf("Input a command: ");    
          // LAB 5 CODE*

    fgets(line, MAX, stdin);         // get a line (end with \n) from stdin
    //printf("line: %s\n", line);
    line[strlen(line)-1] = 0;        // kill \n at end
    //printf("line[0]: %c\n", line[0]);
    //if(line[0]==0)                  // exit if NULL line
       //{exit(0);}

         // *Lab 5 CODE
    strcpy(temp, line);
    //printf("temp: %s\n", temp);
    
    tok = strtok(line, " ");
    cmdCount++;
    //printf("temp: %s\n", temp);
    //printf("cmdArgs[0] = %s\n", cmdArgs[0]);
    //printf("cmdCount: %d\n", cmdCount);
    while(tok != NULL)
    {
      strcpy(cmdArgs[cmdCount-1], tok);
      tok = strtok(NULL, " ");
      cmdCount++;
      //printf("cmdCount: %d\n", cmdCount);
    }
    //printf("cmdCount: %d\n", cmdCount);
    //printf("line: %s\n", line);
    //printf("cmdArgs[0] = %s\n", cmdArgs[0]);
    if(strcmp(cmdArgs[0], "lcat") == 0) 
    {
      if(strcmp(cmdArgs[1],"") != 0) {mycat(cmdArgs[1]);}
      else {printf("ERROR: pathname not given");}
    }
    else if (strcmp(cmdArgs[0], "lpwd") == 0) 
    {
      mypwd(cwd);
    }
    else if (strcmp(cmdArgs[0], "lls") == 0) 
    {
      printf("args: %s\n", cmdArgs[1]);
      if(strcmp(cmdArgs[1],"") != 0) {myls(cmdArgs[1]);}
      else 
      {
        printf("cwd: %s\n", cwd);
        myls(cwd);
      }
    }
    else if (strcmp(cmdArgs[0], "lcd") == 0) 
    {
      if(strcmp(cmdArgs[1],"") != 0) {mycd(cmdArgs[1]);}
      else {mycd(cwd);}
    }
    else if (strcmp(cmdArgs[0], "lmkdir") == 0) 
    {
      if(strcmp(cmdArgs[1],"") != 0) {mymkdir(cmdArgs[1]);}
      else {printf("ERROR: pathname not given");}
    }
    else if (strcmp(cmdArgs[0], "lrmdir") == 0) 
    {
      if(strcmp(cmdArgs[1],"") != 0) {myrmdir(cmdArgs[1]);}
      else {printf("ERROR: pathname not given");}
    }
    else if (strcmp(cmdArgs[0], "lrm") == 0) 
    {
      if(strcmp(cmdArgs[1],"") != 0) {myrm(cmdArgs[1]);}
      else {printf("ERROR: pathname not given");}
    }
    else if (strcmp(cmdArgs[0], "get") == 0) 
    {
      if(strcmp(cmdArgs[1],"") != 0) {mycp(cmdArgs[1], cwd);}
      else {printf("ERROR: pathname not given");}
    }
    else if (strcmp(cmdArgs[0], "quit") == 0) 
    {
      printf("Goodbye!\n");
      return 0;
    }
    else // Not a local command, work with the sever
    {
      // Send command to server
      n = write(server_sock, temp, MAX);
      printf("client: wrote n=%d bytes; line=(%s)\n", n, temp);
      // Send command pathname
      //n = write(server_sock, cmdArgs[0], MAX);
      //printf("client: wrote n=%d bytes; line=(%s)\n", n, line);

      // Now read the Reply and Results in from the Server...

      //REPLY
      //n = read(server_sock, ans, MAX);
      //printf("client: read  n=%d bytes; echo=(%s)\n",n, ans);

      //RESULTS
      //n = read(server_sock, ans, MAX);
      //printf("client: read  n=%d bytes; echo=(%s)\n",n, ans);

      readData(ans);
    }
         // Lab 5 CODE*

    //
    // Send ENTIRE line to server
    //n = write(server_sock, line, MAX);
    //printf("client: wrote n=%d bytes; line=(%s)\n", n, line);

    // Read a line from sock and show it
    //n = read(server_sock, ans, MAX);
    //printf("client: read  n=%d bytes; echo=(%s)\n",n, ans);
  }
}
int callInternal(command* C, char* homeDir)
{
	if (C->argc == 0)
		return 0;
	else if (strcmp(C->argv[0],"exit") == 0)
		return 1;
	else if (strcmp(C->argv[0],"mycat") == 0)
	{
		if (C->argc == 2)
			mycat(C->argv[1]);
		else if (C->argc == 1)
			printf("Argument missing\n");
		else if (C->argc > 2)
			printf("Incorrect usage of mycat\n");
	}
	else if (strcmp(C->argv[0],"mycp") == 0)
	{
		if (C->argc == 3)
			mycp(C->argv[1],C->argv[2]);
		else if (C->argc == 2)
			printf("Destination needed\n");
		else if (C->argc == 1)
			printf("Source & destination needed\n");
		else
			printf("Incorrect usage of mycp\n");
	}
	else if (strcmp(C->argv[0],"mypwd") == 0)
	{
		if (C->argc > 1)
			printf("Incorrect usage of mypwd\n");
		else
		{		
			char* pwd = mypwd();
			printf("%s\n",pwd);
			free(pwd);
		}
	}
	else if (strcmp(C->argv[0],"mymkdir") == 0)
	{
		if (C->argc < 2)
			printf("missing argument\n");
		else if (C->argc > 2)
			printf("Incorrect usage of mymkdir\n");
		else
			mymkdir(C->argv[1]);
	}
	else if (strcmp(C->argv[0],"myrmdir") == 0)
	{
		if (C->argc < 2)
			printf("missing argument\n");
		else if (C->argc > 2)
			printf("Incorrect usage of mymkdir\n");
		else
			myrmdir(C->argv[1]);	
	}
	else if (strcmp(C->argv[0],"mycd") == 0)
	{
		if (C->argc >2)
			printf("Incorrect usage of mycd\n");
		else if (C->argc == 2)
			mycd(C->argv[1]);
		else
			mycd(homeDir);
	}
	else if (strcmp(C->argv[0],"myls") == 0)
	{
		if (C->argc == 1)
			myls(NULL,0);
		else if (C->argc == 2)
			if (strcmp(C->argv[1],"-l") == 0)
				myls(NULL,1);
			else
				myls(C->argv[1],0);
		else if (C->argc == 3)
			if (strcmp(C->argv[1],"-l") == 0)
				myls(C->argv[2],1);
			else
			printf("Incorrect usage of myls\n");
		else
			printf("Incorrect usage of myls\n");
	}
	else if (strcmp(C->argv[0],"myrm") == 0)
	{
		if (C->argc == 2)
			myrm(C->argv[1]);
		else if (C->argc == 1)
			printf("missing argument\n");
		else
			printf("Incorrect usage of myrm\n");
	}
	else
		printf("command not found: %s\n",C->argv[0]);
	return 0;
}
Esempio n. 6
0
int main(int argc, char** argv)
{
	int count=0, i=0, cmp, j, valid=0;
	char key[MAX];
	
	//run the shell till user inputs 'quit' or Ctrl-C
	while(strcmp(cmdline, "quit") != 0)
	{
		count = 0;
		
		//our shell's prompt
		printf("afreen@myShell $ ");
		//get command line input
		gets(cmdline);
		
		//tokenize the CL input delimited by " " using strtok() into args
		args[count++] = strtok(cmdline, " ");
		
		//tokenize the entire string till the next token encountered
		//does not have a NULL pointer
		while((args[count++] = strtok(NULL, " ")));
		count--;		//no of arguments (argc)
		
		//if user wants to clear screen
		if(strcmp(args[0], "clear") == 0)
		{
			myclear();
		}
		
		//checking for the input command
		strcpy(key, args[0]);
		for(i=0; i<18; i++)	//look through our check array for command
		{
		  if(strcmp(check[i], key) == 0)
		  {
		      valid = -1;
		      switch(i)
		      {
		        case 0:   mycat(count, args);
		                  break;
		        
		        case 1:   mycd(count, args);
		                  break;
          
		        case 2:   mycp(count, args);
		                  break;
		         
		        case 3:   mydate(count, args);
		                  break;
		          
		        case 4:   myhead(count, args);
		                  break;
		                  
		        case 5:   myls(count, args);
		                  break;
		                  
		        case 6:   myll(count, args);
		                  break;
		                  
		        case 7:   myln(count, args);
		                  break;
		                  
		        case 8:   myld(count, args);
		                  break;
		                  
		        case 9:   mymkdir(count, args);
		                  break;
		                  
		        case 10:  mymv(count, args);
		                  break;
		                  
		        case 11:  mypwd(count, args);
		                  break;
		                  
		        case 12:  myrm(count, args);
		                  break;
		                  
		        case 13:  myrmdir(count, args);
		                  break;
		                  
		        case 14:  mytail(count, args);
		                  break;
		                  
		        case 15:  mytime(count, args);
		                  break;
		                  
		        case 16:  mytouch(count, args);
		                  break;
		                  
		        case 17:  myuname(count, args);
		                  break;
		                  		        
		        default: printf("%s: Command not found\n", key);
		    		  break;
		      }	
		      break;  
		  }
		}
		
		
  	}
  	return 0;
}