mirror of
git://projects.qi-hardware.com/ben-scans.git
synced 2024-11-21 21:33:11 +02:00
Files can now be specified as HTTP/HTTPS URLs.
- solidify/face.c (read_face): moved code into new function read_file - solidify/face.c (read_face): added wrapper for cached wget of http: and https: URLs
This commit is contained in:
parent
6ac06aab7c
commit
b5a2d5d8ef
@ -1,7 +1,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "array.h"
|
||||
@ -9,7 +12,10 @@
|
||||
#include "face.h"
|
||||
|
||||
|
||||
struct face *read_face(const char *name)
|
||||
#define CACHE_DIR ".cache"
|
||||
|
||||
|
||||
static struct face *read_file(const char *name)
|
||||
{
|
||||
FILE *file;
|
||||
struct face *f;
|
||||
@ -68,3 +74,47 @@ struct face *read_face(const char *name)
|
||||
}
|
||||
|
||||
|
||||
struct face *read_face(const char *name)
|
||||
{
|
||||
const char *p;
|
||||
int cwd;
|
||||
struct face *face;
|
||||
|
||||
if (strncmp(name, "http:", 5) && strncmp(name, "https:", 6))
|
||||
return read_file(name);
|
||||
p = strrchr(name, '/');
|
||||
if (!p || !p[1]) {
|
||||
fprintf(stderr, "malformed URL: \"%s\"\n", name);
|
||||
exit(1);
|
||||
}
|
||||
cwd = open(".", O_RDONLY);
|
||||
if (cwd < 0) {
|
||||
perror(".");
|
||||
exit(1);
|
||||
}
|
||||
if (chdir(CACHE_DIR) < 0) {
|
||||
perror(CACHE_DIR);
|
||||
exit(1);
|
||||
}
|
||||
if (access(p+1, R_OK) < 0) {
|
||||
char tmp[1000]; /* @@@ enough */
|
||||
int res;
|
||||
|
||||
sprintf(tmp, "wget '%s'", name);
|
||||
res = system(tmp);
|
||||
if (res < 0) {
|
||||
perror("system");
|
||||
exit(1);
|
||||
}
|
||||
if (!WIFEXITED(res) || WEXITSTATUS(res)) {
|
||||
fprintf(stderr, "%s: status %d\n", tmp, res);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
face = read_file(p+1);
|
||||
if (fchdir(cwd) < 0) {
|
||||
perror("fchdir");
|
||||
exit(1);
|
||||
}
|
||||
return face;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user