Skip to content

Commit

Permalink
Merge pull request #54 from lachlanA/master
Browse files Browse the repository at this point in the history
Add version command.
  • Loading branch information
vdudouyt committed Jan 9, 2017
2 parents c2dc8a5 + ecebec9 commit 7eac1cf
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions main.c
Expand Up @@ -22,6 +22,10 @@ extern int opterr;
extern int optreset;
#endif

#define VERSION_RELASE_DATE "20170116"
#define VERSION "1.0"
#define VERSION_NOTES ""

programmer_t pgms[] = {
{ "stlink",
0x0483, // USB vid
Expand Down Expand Up @@ -58,10 +62,18 @@ void print_help_and_exit(const char *name, bool err) {
fprintf(stream, "\t-r <filename> Read data from device to file\n");
fprintf(stream, "\t-w <filename> Write data from file to device\n");
fprintf(stream, "\t-v <filename> Verify data in device against file\n");
fprintf(stream, "\t-V Print Date(YearMomthDay-Version) and Version format is IE: 20171204-1.0\n");
fprintf(stream, "\t-u Unlock. Reset option bytes to factory default to remove write protection.\n");
exit(-err);
}

void print_version_and_exit( bool err) {
FILE *stream = err ? stderr : stdout;
fprintf(stream, "%s-%s\n%s",VERSION_RELASE_DATE, VERSION, VERSION_NOTES );
exit(-err);
}


void spawn_error(const char *msg) {
fprintf(stderr, "%s\n", msg);
exit(-1);
Expand Down Expand Up @@ -144,7 +156,7 @@ int main(int argc, char **argv) {
int i;
programmer_t *pgm = NULL;
const stm8_device_t *part = NULL;
while((c = getopt (argc, argv, "r:w:v:nc:p:s:b:lu")) != (char)-1) {
while((c = getopt (argc, argv, "r:w:v:nc:p:s:b:luV")) != (char)-1) {
switch(c) {
case 'c':
pgm_specified = true;
Expand Down Expand Up @@ -174,7 +186,7 @@ int main(int argc, char **argv) {
action = VERIFY;
strcpy(filename, optarg);
break;
case 'u':
case 'u':
action = UNLOCK;
start = 0x4800;
memtype = OPT;
Expand Down Expand Up @@ -202,8 +214,11 @@ int main(int argc, char **argv) {
bytes_count = atoi(optarg);
bytes_count_specified = true;
break;
case 'V':
print_version_and_exit( (bool)0);
break;
case '?':
print_help_and_exit(argv[0], false);
print_help_and_exit(argv[0], false);
default:
print_help_and_exit(argv[0], true);
}
Expand Down

0 comments on commit 7eac1cf

Please sign in to comment.