I do not need any more than the 3 default FCBs, so... what gives?
Code: Select all
/**
* nget
*/
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "network.h"
#define READ 4
#define NO_TRANSLATION 0
#define RETRY_COUNT 128
#define CONNECTED 2
void get_url(char *c)
{
cprintf("URL: ");
cgets(c);
}
void get_filename(char *c)
{
cprintf("DEST FILENAME: ");
cgets(c);
}
bool did_we_connect(void)
{
bool retries = RETRY_COUNT;
// Wait until connection established
while (retries > 0)
{
if (network_statusbyte() & CONNECTED)
{
cprintf("CONNECTED!\n");
return true;
}
else
retries--;
}
if (retries == 0)
{
cprintf("COULD NOT OPEN NET CONNECTION.\n");
return false;
}
}
void get(char *u, char *f)
{
FILE *fp = fopen(f,"w");
unsigned long total = 0;
if (fp == NULL)
{
cprintf("COULD NOT OPEN DEST FILE %s - ABORTING\n",f);
fclose(fp);
exit(1);
}
network_open(u,READ,NO_TRANSLATION);
if (!did_we_connect())
goto bye;
while (1)
{
char buf[1024];
unsigned short l = network_read(buf,sizeof(buf));
if (fwrite(buf,sizeof(char),l,fp) != l)
{
cprintf("COULD NOT WRITE TO DEST FILE. ABORTING.\n");
goto bye;
}
total += l;
cprintf("%u\n",total);
if (!(network_statusbyte() & CONNECTED))
{
cprintf("DONE.\n");
break;
}
}
bye:
network_close();
fclose(fp);
}
void main(void)
{
char url[256];
char filename[16];
memset(url,0,sizeof(url));
memset(filename,0,sizeof(filename));
while (url[0]==0x00) { get_url(url); }
while (filename[0]==0x00) { get_filename(filename); }
get(url,filename);
}