- if (arg->usb_present == 1) {
- rarg.run = 0;
- pthread_join(reader_thread, NULL);
- }
+ read_history(".history");
+ while(1)
+ {
+ // If there is a script file
+ if (script_file)
+ {
+ if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file))
+ {
+ fclose(script_file);
+ script_file = NULL;
+ }
+ else
+ {
+ char *nl;
+ nl = strrchr(script_cmd_buf, '\r');
+ if (nl) *nl = '\0';
+ nl = strrchr(script_cmd_buf, '\n');
+ if (nl) *nl = '\0';
+
+ if ((cmd = (char*) malloc(strlen(script_cmd_buf))) != NULL)
+ {
+ memset(cmd, 0, strlen(script_cmd_buf));
+ strcpy(cmd, script_cmd_buf);
+ printf("%s\n", cmd);
+ }
+ }
+ }
+
+ if (!script_file)
+ {
+ cmd = readline(PROXPROMPT);
+ }
+
+ if (cmd) {
+ while(cmd[strlen(cmd) - 1] == ' ')
+ cmd[strlen(cmd) - 1] = 0x00;
+
+ if (cmd[0] != 0x00) {
+ if (strncmp(cmd, "quit", 4) == 0) {
+ break;
+ }
+
+ CommandReceived(cmd);
+ add_history(cmd);
+ }
+ free(cmd);
+ } else {
+ printf("\n");
+ break;
+ }
+ }
+
+ write_history(".history");
+
+ if (arg->usb_present == 1) {
+ rarg.run = 0;
+ pthread_join(reader_thread, NULL);
+ }
+
+ if (script_file)
+ {
+ fclose(script_file);
+ script_file = NULL;
+ }