123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- #define _GETOPT_H
- #include <stdio.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <errno.h>
- #include "../tools/getoptv.h"
- #include "../tools/putoptv.h"
- #include "../tools/version.h"
- #include "../tools/number.h"
- #include "../tools/flags.h"
- #include "../tools/memory.h"
- #include "../tools/files.h"
- #include "../tools/error.h"
- #include "../ram/sdram.h"
- #ifndef MAKEFILE
- #include "../tools/getoptv.c"
- #include "../tools/putoptv.c"
- #include "../tools/version.c"
- #include "../tools/error.c"
- #include "../tools/checksum32.c"
- #include "../tools/todigit.c"
- #include "../tools/hexencode.c"
- #endif
- int main (int argc, char const * argv [])
- {
- static char const * optv [] =
- {
- "qv",
- "file [file] [...]",
- "convert ASCII SDRAM configuration files (DM) to binary (toolkit) format",
- "q\tquiet mode",
- "v\tverbose mode",
- (char const *) (0)
- };
- struct config_ram config_ram;
- char string [(sizeof (config_ram) << 1) + 1];
- uint32_t checksum;
- flag_t flags = (flag_t)(0);
- signed state = 1;
- signed fd;
- signed c;
- optind = 1;
- while ((c = getoptv (argc, argv, optv)) != -1)
- {
- switch ((char) (c))
- {
- case 'q':
- _setbits (flags, SDRAM_SILENCE);
- break;
- case 'v':
- _setbits (flags, SDRAM_VERBOSE);
- break;
- default:
- break;
- }
- }
- argc -= optind;
- argv += optind;
- while ((argc-- > 0) && (* argv != (char const *)(0)))
- {
- #if 0
- char const * pathname;
- char const * filename;
- char const * extender;
- for (pathname = filename = * argv; *pathname; pathname++)
- {
- if ((*pathname == '/') || (*pathname == '\\'))
- {
- filename = pathname + 1;
- }
- }
- for (pathname = extender = filename; *pathname; pathname++)
- {
- if (*pathname == '.')
- {
- extender = pathname;
- }
- }
- if (extender == filename)
- {
- extender = pathname;
- }
- #endif
- if ((fd = open (* argv, O_BINARY|O_RDONLY)) == -1)
- {
- error (0, errno, "can't open %s for input", * argv);
- state = 1;
- }
- else if (read (fd, &string, sizeof (string)) < (ssize_t) (sizeof (string) - 1))
- {
- error (0, errno, "can't read %s", * argv);
- state = 1;
- }
- else
- {
- close (fd);
- if (hexencode ((uint8_t *) (&config_ram), sizeof (config_ram), string) == sizeof (config_ram))
- {
- error (1, errno, "%s is suspect", * argv);
- }
- checksum = checksum32 (&config_ram, sizeof (config_ram), 0);
- if ((fd = open (* argv, O_BINARY|O_CREAT|O_RDWR|O_TRUNC, FILE_FILEMODE)) == -1)
- {
- error (1, errno, "can't open %s for output", * argv);
- }
- write (fd, &config_ram, sizeof (config_ram));
- write (fd, &checksum, sizeof (checksum));
- }
- close (fd);
- argv++;
- }
- return (state);
- }
|