SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. const int long long;
  4. const int N = 2e5;
  5. void creat_archive(char* name_arc, int count, char* filelochek[]){
  6.     int i;
  7.     FILE* file_arc = fopen(name_arc, "wb");
  8.     FILE* file;
  9.     int name_size[N];
  10.     for (i = 5; i < count; i++){
  11.         file = fopen(filelochek[i], "rb");
  12.         if (file == NULL)
  13.             continue;
  14.         fseek(file, 0, SEEK_END);
  15.         name_size[i - 5] = ftell(file);
  16.         fseek(file, 0, SEEK_SET);
  17.         fclose(file);
  18.     }
  19.     for (i = 0; i < count - 5; i++)
  20.         fprintf(file_arc, "<%s:%llu>", filelochek[i + 5], name_size[i]);
  21.         fprintf(file_arc, "\n");
  22.     for (i = 5; i < count; i++){
  23.         file = fopen(filelochek[i], "rb");
  24.         if (file == NULL){
  25.             printf("file not added");
  26.         } else{
  27.             printf("file added");}
  28.         fclose(file);}
  29. }
  30. void extract_archive(char* name_arc){
  31.      int now_time = 0;
  32.      int first_time = 0;
  33.      int size;
  34.      int file_read;
  35.     FILE* file_arc = fopen(name_arc, "rb");
  36.     FILE* file;
  37.     char name_of_file[N];
  38.     while ((file_read = getc(file_arc)) != EOF) { //пока не пустой
  39.         first_time++;
  40.         if (file_read == '\n'){
  41.             break;}
  42.     }
  43.     fseek(file_arc, 0, SEEK_SET);
  44.     while (fscanf(file_arc, "<%s:%llu>", name_of_file, &size) != 0){
  45.         file = fopen(name_of_file, "wb");
  46.         if (file == NULL)
  47.             break;
  48.         now_time = ftell(file_arc);
  49.         fseek(file_arc, first_time, SEEK_SET);
  50.         first_time += size;\
  51.         while (size-- > 0)
  52.             putc((file_read = getc(file_arc)), file);
  53.         fseek(file_arc, now_time, SEEK_SET);
  54.         fclose(file); }
  55.     printf("unzipping");
  56. }
  57. void list_archive(char* name_arc){
  58.     FILE* file_arc = fopen(name_arc, "rb");
  59.     char name_of_file[N];
  60.     int read = 0;
  61.     int file_read;
  62.     int i;
  63.     printf("File list_archive:\n");
  64.     while ((file_read = getc(file_arc)) != EOF) {
  65.         if (file_read == ':'){
  66.             read = 0;
  67.             printf("\t%s\n", name_of_file);
  68.         }
  69.         if (read){
  70.             name_of_file[i] = file_read;
  71.             i++;
  72.         }
  73.         if (file_read == '<'){
  74.             read = 1;
  75.             i = 0;
  76.         }
  77.     }
  78.     fclose(file_arc); }
  79. int main(int argc, char* argv[]){
  80.     FILE* file_arc;
  81.     char* name_arc;
  82.     for (int i = 0; i < argc; i++){
  83.         if(!strcmp("--file", argv[i])){
  84.             name_arc = argv[i + 1];}
  85.         if(!strcmp("--creat", argv[i])){
  86.             creat_archive(name_arc, argc, argv);}
  87.         if(!strcmp("--extract", argv[i])){
  88.             extract_archive(name_arc);}
  89.         if(!strcmp("--list", argv[i])){
  90.             list_archive(name_arc);
  91.         }
  92.     }
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top