CHG: Syntax suger

This commit is contained in:
iceman1001 2016-01-20 17:45:42 +01:00
commit 87b28d31a1

View file

@ -48,6 +48,7 @@ void SendCommand(UsbCommand *c) {
Not good.../holiman Not good.../holiman
**/ **/
while(txcmd_pending); while(txcmd_pending);
txcmd = *c; txcmd = *c;
txcmd_pending = true; txcmd_pending = true;
} }
@ -70,17 +71,19 @@ static void *uart_receiver(void *targ) {
size_t cmd_count; size_t cmd_count;
while (arg->run) { while (arg->run) {
rxlen = sizeof(UsbCommand); rxlen = sizeof(UsbCommand);
if (uart_receive(sp, prx, &rxlen)) { if (uart_receive(sp, prx, &rxlen)) {
prx += rxlen; prx += rxlen;
if (((prx-rx) % sizeof(UsbCommand)) != 0) { if (((prx-rx) % sizeof(UsbCommand)) != 0)
continue; continue;
}
cmd_count = (prx-rx) / sizeof(UsbCommand); cmd_count = (prx-rx) / sizeof(UsbCommand);
for (size_t i = 0; i < cmd_count; i++) { for (size_t i = 0; i < cmd_count; i++)
UsbCommandReceived((UsbCommand*)( rx + ( i * sizeof(UsbCommand)))); UsbCommandReceived((UsbCommand*)( rx + ( i * sizeof(UsbCommand))));
}
} }
prx = rx; prx = rx;
@ -110,13 +113,13 @@ static void *main_loop(void *targ) {
} }
FILE *script_file = NULL; FILE *script_file = NULL;
char script_cmd_buf[256]; // iceman, needs lua script the same file_path_buffer as the rest char script_cmd_buf[256] = {0x00}; // iceman, needs lua script the same file_path_buffer as the rest
if (arg->script_cmds_file) { if (arg->script_cmds_file) {
script_file = fopen(arg->script_cmds_file, "r"); script_file = fopen(arg->script_cmds_file, "r");
if (script_file) {
if (script_file)
printf("using 'scripting' commands file %s\n", arg->script_cmds_file); printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
}
} }
read_history(".history"); read_history(".history");
@ -132,10 +135,13 @@ static void *main_loop(void *targ) {
} else { } else {
char *nl; char *nl;
nl = strrchr(script_cmd_buf, '\r'); nl = strrchr(script_cmd_buf, '\r');
if (nl) *nl = '\0'; if (nl)
*nl = '\0';
nl = strrchr(script_cmd_buf, '\n'); nl = strrchr(script_cmd_buf, '\n');
if (nl) *nl = '\0';
if (nl)
*nl = '\0';
if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL) { if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL) {
memset(cmd, 0, strlen(script_cmd_buf)); memset(cmd, 0, strlen(script_cmd_buf));
@ -143,9 +149,7 @@ static void *main_loop(void *targ) {
printf("%s\n", cmd); printf("%s\n", cmd);
} }
} }
} } else {
if (!script_file) {
cmd = readline(PROXPROMPT); cmd = readline(PROXPROMPT);
} }
@ -157,10 +161,11 @@ static void *main_loop(void *targ) {
if (cmd[0] != 0x00) { if (cmd[0] != 0x00) {
int ret = CommandReceived(cmd); int ret = CommandReceived(cmd);
add_history(cmd); add_history(cmd);
if (ret == 99) { // exit or quit
// exit or quit
if (ret == 99)
break; break;
} }
}
free(cmd); free(cmd);
} else { } else {
printf("\n"); printf("\n");
@ -222,6 +227,7 @@ int main(int argc, char* argv[]) {
.usb_present = 0, .usb_present = 0,
.script_cmds_file = NULL .script_cmds_file = NULL
}; };
pthread_t main_loop_threat; pthread_t main_loop_threat;
@ -250,9 +256,10 @@ int main(int argc, char* argv[]) {
printf("Output will be flushed after every print.\n"); printf("Output will be flushed after every print.\n");
flushAfterWrite = 1; flushAfterWrite = 1;
} }
else else {
marg.script_cmds_file = argv[2]; marg.script_cmds_file = argv[2];
} }
}
// create a mutex to avoid interlacing print commands from our different threads // create a mutex to avoid interlacing print commands from our different threads
pthread_mutex_init(&print_lock, NULL); pthread_mutex_init(&print_lock, NULL);
@ -265,9 +272,8 @@ int main(int argc, char* argv[]) {
pthread_join(main_loop_threat, NULL); pthread_join(main_loop_threat, NULL);
// Clean up the port // Clean up the port
if (offline == 0) { if (offline == 0)
uart_close(sp); uart_close(sp);
}
// clean up mutex // clean up mutex
pthread_mutex_destroy(&print_lock); pthread_mutex_destroy(&print_lock);