removed rest of url in requests
This commit is contained in:
parent
94f0619222
commit
8efb9bbce7
2 changed files with 32 additions and 8 deletions
|
@ -29,7 +29,7 @@ Good to know! I can also give the ``-r`` flag to display the resolution if I so
|
||||||
What if I don't want my wife to find a photo of Peter Griffin on my laptop? Well, you can use a link instead::
|
What if I don't want my wife to find a photo of Peter Griffin on my laptop? Well, you can use a link instead::
|
||||||
|
|
||||||
$ uirc https://upload.wikimedia.org/wikipedia/en/c/c2/Peter_Griffin.png
|
$ uirc https://upload.wikimedia.org/wikipedia/en/c/c2/Peter_Griffin.png
|
||||||
https://upload.wikimedia.org/wikipedia/en/c/c2/Peter_Griffin.png > 1:1.45 (uneven)
|
Peter_Griffin.png > 1:1.45 (uneven)
|
||||||
|
|
||||||
There's also a help menu with the ``-h`` flag if you really need it.
|
There's also a help menu with the ``-h`` flag if you really need it.
|
||||||
|
|
||||||
|
|
38
uirc.c
38
uirc.c
|
@ -41,8 +41,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <stb/stb_image.h>
|
#include <stb/stb_image.h>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <curl/easy.h>
|
#include <curl/easy.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
const char *VERSION = "0.1.0";
|
const char *VERSION = "0.1.0";
|
||||||
|
int rFlag = 1;
|
||||||
|
|
||||||
int getBcf(int width, int height) {
|
int getBcf(int width, int height) {
|
||||||
int *widthFactors, *heightFactors;
|
int *widthFactors, *heightFactors;
|
||||||
|
@ -59,6 +61,10 @@ int getBcf(int width, int height) {
|
||||||
return bcf;
|
return bcf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char imgUrlName(char *url) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int readFile(char *file, int rFlag, int req, char* url) {
|
int readFile(char *file, int rFlag, int req, char* url) {
|
||||||
int width, height, channels, factor;
|
int width, height, channels, factor;
|
||||||
unsigned char *img = stbi_load(file, &width, &height, &channels, 0);
|
unsigned char *img = stbi_load(file, &width, &height, &channels, 0);
|
||||||
|
@ -66,8 +72,11 @@ int readFile(char *file, int rFlag, int req, char* url) {
|
||||||
if (req == 0) {
|
if (req == 0) {
|
||||||
printf("uirc: request failed (%s), trying local fs instead\n", url);
|
printf("uirc: request failed (%s), trying local fs instead\n", url);
|
||||||
return 4;
|
return 4;
|
||||||
|
} else if (access(file, F_OK) != 0) {
|
||||||
|
printf("uirc: %s: No such file or directory\n", file);
|
||||||
|
exit(6);
|
||||||
} else {
|
} else {
|
||||||
printf("uirc: could not open file %s\n", file);
|
printf("uirc: could not open file %s: %s\n", file, stbi_failure_reason());
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +87,18 @@ int readFile(char *file, int rFlag, int req, char* url) {
|
||||||
double huneven = ((float) width) / ((float) height);
|
double huneven = ((float) width) / ((float) height);
|
||||||
|
|
||||||
if (req == 0) {
|
if (req == 0) {
|
||||||
file = url;
|
char *token, *next = "";
|
||||||
|
|
||||||
|
token = strtok(url, "/");
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if (next == NULL) {
|
||||||
|
file = token;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
token = next;
|
||||||
|
next = strtok(NULL, "/");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (factor == 1) {
|
if (factor == 1) {
|
||||||
|
@ -107,8 +127,9 @@ int download(char *url) {
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
char outfilename[FILENAME_MAX] = "/tmp/uirc.tmp";
|
char outfilename[15] = "/tmp/uirc.tmp";
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
|
|
||||||
if (curl) {
|
if (curl) {
|
||||||
fp = fopen(outfilename,"wb");
|
fp = fopen(outfilename,"wb");
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||||
|
@ -118,12 +139,11 @@ int download(char *url) {
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
printf("ok\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// end of stack overflow snippet
|
// end of stack overflow snippet
|
||||||
|
|
||||||
int rFlag = 1;
|
|
||||||
|
|
||||||
int handleArg(char *arg) {
|
int handleArg(char *arg) {
|
||||||
int value, complete;
|
int value, complete;
|
||||||
char flag, *longFlag, *http, first, firstTwo[3], firstFour[5];
|
char flag, *longFlag, *http, first, firstTwo[3], firstFour[5];
|
||||||
|
@ -140,7 +160,7 @@ int handleArg(char *arg) {
|
||||||
"help:\n"
|
"help:\n"
|
||||||
"If you get stuck using uirc, you can read the manpage for uirc:\n\n"
|
"If you get stuck using uirc, you can read the manpage for uirc:\n\n"
|
||||||
|
|
||||||
"\t'man uirc'\n\n";
|
"\t'man uirc'\n";
|
||||||
|
|
||||||
first = arg[0];
|
first = arg[0];
|
||||||
|
|
||||||
|
@ -173,12 +193,16 @@ int handleArg(char *arg) {
|
||||||
exit(5);
|
exit(5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp("http", firstFour) == 0) {
|
if (strcmp("http", firstFour) == 0) {
|
||||||
|
printf("downloading \"%s\"...", arg);
|
||||||
|
fflush(stdout);
|
||||||
download(arg);
|
download(arg);
|
||||||
complete = readFile("/tmp/uirc.tmp", rFlag, 0, arg);
|
complete = readFile("/tmp/uirc.tmp", rFlag, 0, arg);
|
||||||
if (complete != 0)
|
if (complete != 0)
|
||||||
readFile(arg, rFlag, 1, "");
|
readFile(arg, rFlag, 1, "");
|
||||||
remove("/tmp/uirc.tmp");
|
else
|
||||||
|
remove("/tmp/uirc.tmp");
|
||||||
} else {
|
} else {
|
||||||
// if no more flags, run ratio calculations
|
// if no more flags, run ratio calculations
|
||||||
return readFile(arg, rFlag, 1, "");
|
return readFile(arg, rFlag, 1, "");
|
||||||
|
|
Loading…
Add table
Reference in a new issue