neocities.h

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

upload.c (1165B)


      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 != 2) {
     24         /* ./dir/file is valid
     25            ./some-utf8-character/file is valid
     26            ./dir/some-utf8-character is invalid
     27 
     28            by libcurl design, it will default to
     29            sendfile
     30 
     31            after the last /, filename should be [a-zA-Z\.]+
     32          */
     33 
     34         fprintf(stderr, "Usage: %s filename\n\n", argv[0]);
     35         exit(200);              // no enum member share this number
     36     }
     37 
     38     if ((err = neocities_global_init()) != 0)
     39         return err;
     40 
     41     if ((err = neocities_api_ex(APIKEY, upload, argv[1], &res)) != 0
     42         || res.result == -1) {
     43         neocities_print_error_message(err);
     44         if (res.type == -1)     // reserved for errors
     45             neocities_print_error_message_api(res.data.error.type);
     46         return err;
     47     }
     48     //neocities_destroy(&res);
     49 
     50     curl_global_cleanup();
     51 
     52     return 0;
     53 }