예제 #1
0
int
main (int argc, char *argv[])
{
    if (argc != 3)
    {
        fprintf (stderr, "Usage %s word1 word2 \n\n delete link between two words\n", argv[0]);
		exit(4);
    }

    WORDS words;

    initialise (&words);
    if (read_all_files(words) == WORDS_SUCCESS)
    {
			entity *w[2]={NULL,NULL};
            if ((w[0]=find_word (words, argv[1])) == NULL)
            {
				fprintf(stderr,"Failed to find word \"%s\"\n",argv[1]);
                exit(2);
            }
            if ((w[1]=find_word (words, argv[2])) == NULL)
            {
				fprintf(stderr,"Failed to find word \"%s\"\n",argv[2]);
                exit(3);
            }

            if (delete_link(w[0],w[1]) == WORDS_SUCCESS ) 
                return 0;
    }
    return 1;
}
예제 #2
0
bool native_dir::delete_dir(bool recursive)
{
	if (recursive) {
		std::vector<std::string> all_files;
		read_all_files(all_files);
		for (unsigned i = 0; i < all_files.size(); i++) {
			native_file child_file(name + "/" + all_files[i]);
			if (!child_file.is_dir()) {
				bool ret = child_file.delete_file();
				if (!ret)
					return false;
			}
			else {
				native_dir child(child_file.get_name());
				bool ret = child.delete_dir(true);
				if (!ret)
					return false;
			}
		}
		int ret = rmdir(name.c_str());
		if (ret < 0)
			fprintf(stderr, "rm %s: %s\n", name.c_str(), strerror(errno));
		return ret == 0;
	}
	else {
		int ret = rmdir(name.c_str());
		if (ret < 0)
			fprintf(stderr, "rm %s: %s\n", name.c_str(), strerror(errno));
		return ret == 0;
	}
}
예제 #3
0
파일: main.c 프로젝트: lvchao0428/WZTY
/*
void read_file_after_encode(FileLink* fl)
{
   FileLink* p = fl->next;

   FILE* fp;

   int filenum = 1;
   while(p)
   {
	  char type[20];
	  int len = strlen(p->str);
	 // code_type_get(p->str, type);
	  char* filestr = (char*)malloc(sizeof(char)*(2*len));
	  printf("type:%s\n", p->type);
//	  printf("file:%d\t type:%s\n", filenum, type); 
	  if(strcmp(p->type, "utf-8") != 0 && p->str[0] != '\0')
	  {
		 printf("%d: checked, type:%s, len:%d\n", filenum, p->type, len);
		 code_convert(p->type, "utf-8", p->str, len, filestr, 2*len);
	  }
	  
	  char newfile[50];
	  sprintf(newfile, "./utf_html/%d.html", filenum);
	  printf("%s\b", newfile);
	  if((fp = fopen(newfile, "w")) == NULL)
	  {
		 perror("cannot open the file");
		 exit(-1);
	  }
	
	  if(p->str[0] == '\0' || strcmp(type, "utf-8") == 0)
	  {
		 fwrite(p->str, sizeof(char), strlen(p->str), fp);	 	 
	  }
	  else
	  {
		 printf("writeing\n");
		 fwrite(filestr, sizeof(char), strlen(filestr), fp);
	  }
	  fclose(fp);
	  printf("file:%d complete...\n", filenum);
	  filenum++;

	  p = p->next;
   }
}
*/
int main(int argc, char* argv[])
{


   read_all_files();
  /*
   if(argc < 2)
   {
	  printf("need 2 argv");
	  exit(-1);
   }
   */
 //  FileLink* fl = (FileLink*)malloc(sizeof(FileLink));
   //fl->next = NULL;
   /*
   char* filestr;
   char type[30];
   file_read_full(&filestr, argv[1]);
   code_type_get(filestr, type);
   printf("type is:%s str:%s\n", type, filestr);

   //read_file_after_encode(fl); 

   size_t len = strlen(filestr);
   size_t outlen = 2*len;
   char* outfile = (char*)malloc(sizeof(char)*outlen);
   code_convert(type, "utf-8", filestr, len, outfile, outlen);
   */
/*
   FILE* fp;
   if((fp = fopen("./test.html", "w")) == NULL)
   {
	  perror("failed to open the test html file");
	  exit(-1);
   }

   printf("len:%d\n", strlen(outfile));
   fwrite(outfile, sizeof(char), strlen(outfile), fp);
   fclose(fp);
   */
  // printf("out:%s\n", outfile);
   //   test_filelink(fl);
   return 0;
}