home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 10
/
AU_CD10.iso
/
Archived
/
Updates
/
Flash
/
writeflash
/
!MakeFlash
/
c
/
main
< prev
next >
Wrap
Text File
|
2000-04-25
|
2KB
|
107 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <ctype.h>
//
#include "proto.h"
#include "main.h"
#include "bucket.h"
#include "parser.h"
#include "preprocess.h"
#include "evaluate.h"
#ifdef RISCOS
#include "os.h"
#endif
int debug_print_lines;
void usage() {
fprintf(stderr, "writeflash 0.09\n");
fprintf(stderr, "syntax: writeflash [switches] <infile> [<outfile>]\n");
fprintf(stderr, "switches: -pl print lines\n");
exit(-1);
}
int main(int argc, char *argv[]) {
U8 *buffer;
U32 size;
int arg;
if ((argc < 2) || (argc > 4)) usage();
// default arguments/switches
debug_print_lines = 0;
// next unused argument
arg = 1;
while (argv[arg][0] == '-') {
if (strcmp(argv[arg], "-pl") == 0) {
debug_print_lines = 1;
}
arg++;
}
init_evaluator();
if (arg == argc) {
fprintf(stderr, "Too few arguments\n");
usage();
}
// load/preprocess the input file
if (preprocessor(argv[arg])) exit(0);
arg++;
if (parse_file()) {
printf("failed to parse file\n");
exit(0);
}
if (init_bucket(NULL, 0)) {
fprintf(stderr, "Failed to initialise buffer\n");
exit(0);
}
if (write_flash_file()) {
fprintf(stderr, "Failed to create file\n");
}
if (close_bucket(&buffer, &size)) {
fprintf(stderr, "Failed to read output buffer\n");
exit(0);
}
buffer[4] = size & 255;
buffer[5] = (size>> 8) & 255;
buffer[6] = (size>>16) & 255;
buffer[7] = (size>>24) & 255;
if (arg == argc) {
U32 i;
for (i = 0; i < size; i++)
#ifdef RISCOS
xos_writec(buffer[i]);
#else
printf("%c", buffer[i];
#endif
} else {
FILE *fh;
fh = fopen(argv[arg], "wb");
if (!fh) {
fprintf(stderr, "Failed to open file %s\n", argv[arg]);
exit(0);
}
fwrite(buffer, 1, size, fh);
fclose(fh);
}
}