Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include "point_list.h"
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int main(int argc, char *argv[]) {
  7.  
  8.     (void)argc;
  9.  
  10.     intrusive_list list;
  11.     intrusive_list* l = &list;
  12.     init_list(l);
  13.  
  14.     char *loadfmt = argv[1];
  15.     char *infile = argv[2];
  16.    
  17.     FILE *fin = fopen(infile, "r");
  18.  
  19.     if (strcmp(loadfmt, "loadtext") == 0) {
  20.         readtext(&list, fin);
  21.     }
  22.     else {
  23.         readbin(&list, fin);
  24.     }
  25.  
  26.     fclose(fin);
  27.  
  28.     char *action = argv[3];
  29.     if (strcmp(action, "savetext") == 0) {
  30.         char *outfile = argv[4];
  31.         FILE *fout = fopen(outfile, "w");
  32.         apply(&list, printtext, fout);
  33.         fclose(fout);
  34.     }
  35.     if (strcmp(action, "savebin") == 0) {
  36.         char *outfile = argv[4];
  37.         FILE *fout = fopen(outfile, "w");
  38.         apply(&list, printbin, fout);
  39.         fclose(fout);
  40.     }
  41.     if (strcmp(action, "print") == 0) {
  42.         char *fmt = argv[4];
  43.         apply(&list, print, fmt);
  44.     }
  45.     if (strcmp(action, "count") == 0) {
  46.         int counter = 0;
  47.         apply(&list, count, &counter);
  48.         printf("%d", counter);
  49.     }
  50.  
  51.     remove_all_points(l);
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement