neocities.h

a C library for interacting with Neocities' API
git clone https://github.com/tanguyandreani/neocities.h
Log | Files | Refs | README | LICENSE

list.c (1402B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 #include <curl/curl.h>
      6 #include <json.h>
      7 
      8 #include "dtparser.h"
      9 
     10 #include "neocities.h"
     11 #include "print_error_msg.h"
     12 
     13 #include "apikey.h"
     14 
     15 int main(int argc, char *argv[])
     16 {
     17     neocities_res res;
     18 
     19     int i, err;
     20 
     21     char date[33] = { 0 };
     22 
     23     if (argc != 1 && argc != 2) {
     24         fprintf(stderr, "Usage: %s [path] \n", argv[0]);
     25         exit(200);              // no enum member share this number
     26     }
     27 
     28     if ((err = neocities_global_init()) != 0)
     29         return err;
     30 
     31     if ((err =
     32          neocities_api_ex(APIKEY, list, (argc == 2) ? argv[1] : "",
     33                           &res)) != 0 || res.result == -1) {
     34         neocities_print_error_message(err);
     35         if (res.type == -1)     // reserved for errors
     36             neocities_print_error_message(res.data.error.type);
     37         else
     38             neocities_destroy(&res);
     39         return err;
     40     }
     41 
     42 #define has_blanks(s) \
     43     strchr(s, ' ') != NULL
     44 
     45     for (i = 0; i < res.data.list.length; i++) {
     46         if (has_blanks(res.data.list.files[i].path))
     47             printf("'%s'", res.data.list.files[i].path);
     48         else
     49             printf("%s", res.data.list.files[i].path);
     50         if (res.data.list.files[i].is_directory == 1)
     51             putchar('/');
     52         putchar('\n');
     53     }
     54 
     55 #undef has_blanks
     56 
     57     neocities_destroy(&res);
     58 
     59     curl_global_cleanup();
     60 
     61     return 0;
     62 }