diff options
Diffstat (limited to 'various/neoup')
-rw-r--r-- | various/neoup/config.h | 3 | ||||
-rw-r--r-- | various/neoup/makefile | 15 | ||||
-rw-r--r-- | various/neoup/neoup.c | 120 | ||||
-rw-r--r-- | various/neoup/readme | 29 |
4 files changed, 167 insertions, 0 deletions
diff --git a/various/neoup/config.h b/various/neoup/config.h new file mode 100644 index 0000000..522807e --- /dev/null +++ b/various/neoup/config.h @@ -0,0 +1,3 @@ +char *username = "username"; +char *password = "password"; +char *url = "\"https://neocities.org/api/upload\""; diff --git a/various/neoup/makefile b/various/neoup/makefile new file mode 100644 index 0000000..84d5ea7 --- /dev/null +++ b/various/neoup/makefile @@ -0,0 +1,15 @@ +CC = gcc +CFLAGS = -std=c89 -g -Wall -fdiagnostics-color=never +#CC = tcc +#CFLAGS = -Wall -g +LDFLAGS = +all: neoup + +.c: + $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $< $(DLL) $(ICON) +clean: + rm -f neoup +install: all + cp neoup $(HOME)/bin +uninstall: + rm $(HOME)/bin/neoup diff --git a/various/neoup/neoup.c b/various/neoup/neoup.c new file mode 100644 index 0000000..0415954 --- /dev/null +++ b/various/neoup/neoup.c @@ -0,0 +1,120 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <dirent.h> +#include <unistd.h> +#include "config.h" + +#define MAXPATH 1024 +#define MAXCMD 4096 + +int +upfile(char *name, char *rdir) +{ + char *cmd = calloc(MAXCMD, sizeof(char)); + snprintf(cmd, MAXCMD, "curl -u %s:%s -F \"%s/%s=@%s\" %s", + username, password, rdir, name, name, url); + + printf("%s%s\n", rdir, name); + /*printf("\t%s\n", cmd);*/ + system(cmd); + + free(cmd); + return 0; +} + +int +updir(DIR *dirp, char *rdir, char *dir) +{ + DIR *nestdirp; + struct dirent *dp; + char *name = calloc(MAXPATH, sizeof(char)); + while ((dp = readdir(dirp)) != NULL) { + if (strcmp(".", dp->d_name) == 0 + || strcmp("..", dp->d_name) == 0) + continue; + if (strcmp(".", dir) != 0) { + strcpy(name, dir); + if (name[strlen(name) - 1] != '/') + strcat(name, "/"); + strcat(name, dp->d_name); + } + else + strcpy(name, dp->d_name); + nestdirp = opendir(name); + if (nestdirp == NULL) + upfile(name, rdir); + else if (nestdirp != NULL) { + updir(nestdirp, rdir, name); + } + } + + free(name); + closedir(dirp); + return 0; +} + +/* Upload to a neocities directory a local file or directory. */ +int +main(int argc, char **argv) +{ + char *rdir; + rdir = calloc(MAXPATH, sizeof(char)); + char *local; + local = calloc(MAXPATH, sizeof(char)); + /* In case getcwd is more appropriate than simply '.'. + char *dir = calloc(MAXPATH, sizeof(char)); + getcwd(dir, MAXPATH * sizeof(char));*/ + local[0] = '.'; + int i; + for (i = 1; i < argc; ++i) { + if (strcmp(argv[i], "-r") == 0) { + if (i < argc - 1) { + ++i; + rdir = argv[i]; + } + else { + puts("Supply a directory" + " name after -r"); + return 1; + } + } else if (strcmp(argv[i], "-f") == 0) { + if (i < argc - 1) { + ++i; + local = argv[i]; + } + else { + puts("Supply a file or directory" + " name after -f"); + return 2; + } + } + else { + puts(argv[i]); + printf("%s [-r neocities directory]" + " [-f local file or directory]\n", + argv[0]); + return -1; + } + } + int tmp = strlen(rdir) - 1; + if (rdir[tmp] == '/' && tmp > 0) + rdir[tmp] = '\0'; + /*if (rdir[0] == '\0') + printf("%s ", "/"); + else + printf("%s ", rdir); + printf("%s\n", local);*/ + + DIR *dirp = opendir(local); + if (dirp != NULL) { + updir(dirp, rdir, local); + } else if (access(local, R_OK) == 0) { + upfile(local, rdir); + } else { + printf("I can't open this!\n"); + return 3; + } + + return 0; +} diff --git a/various/neoup/readme b/various/neoup/readme new file mode 100644 index 0000000..992928b --- /dev/null +++ b/various/neoup/readme @@ -0,0 +1,29 @@ +The files provided here allow for generating a program that, when specified +with valid credentials at compilation time, may be used to upload to a file +or directory to a neocities site. The provided makefile's defaults are suitable +for a usual mingw installation, and the commented-out alternatives are suitable +for a usual Unix C89 compiler. In order to make this program work, fill in +valid neocities log-in information in "config.h", compile by means of "make", +and then run the program, that which has the following input syntax: + + neoup [-r neocities directory] [-d local file or directory] + +Should a local file be supplied, it will be uploaded. +Should a local directory be supplied, it and its contents will be uploaded. +If none is specified, the current local directory's contents are uploaded. +Should a neocities directory be specified, all uploads will be placed in that +directory on the neocities site, relative to the starting directory. +If none is specified, all uploads are placed in the starting directory. + +On Windows, mingw is the only build dependency that doesn't commonly come with +the operating system. +On Unix, there are no unusual build dependencies. +On Windows, all of the run-time dependencies are already installed. +On Unix, "curl" may need to be installed, depending on who distributes your +operating system. + +Should there be an issue, message me. + + kaa@disroot.org + +This author places their work distributed here in the Public Domain. |