| 1 |
|
|---|
| 2 | /********************************************************************\
|
|---|
| 3 |
|
|---|
| 4 | Name: ConsoleCommand.cc
|
|---|
| 5 |
|
|---|
| 6 | Created by: Sebastian Commichau, March 2008
|
|---|
| 7 | commichau@phys.ethz.ch
|
|---|
| 8 |
|
|---|
| 9 | Actions: Handle console input
|
|---|
| 10 |
|
|---|
| 11 | \********************************************************************/
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | #include "ConsoleCommand.h"
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | void ConsoleCommand(ProcessIO *m) {
|
|---|
| 18 |
|
|---|
| 19 | siginterrupt(SIGUSR1, true);
|
|---|
| 20 |
|
|---|
| 21 | char comline[MAX_COM_SIZE];
|
|---|
| 22 |
|
|---|
| 23 | char str[MAX_COM_SIZE];
|
|---|
| 24 | char *c;
|
|---|
| 25 |
|
|---|
| 26 | do {
|
|---|
| 27 |
|
|---|
| 28 | fprintf(stdout,m->status->Prompt);
|
|---|
| 29 | c = fgets(comline, MAX_COM_SIZE, stdin);
|
|---|
| 30 |
|
|---|
| 31 | m->status->Pc = comline;
|
|---|
| 32 | sprintf(str,"Test in ConsoleCommand: %s",m->status->Pc);
|
|---|
| 33 | printf(str);
|
|---|
| 34 | /*
|
|---|
| 35 | if (strlen(m->status->Pc) < 2 ) // Ignore commands with only '\n'
|
|---|
| 36 | continue;
|
|---|
| 37 | m->status->Pc[strlen(m->status->Pc)-1]='\0'; // Remove '\n'
|
|---|
| 38 | */
|
|---|
| 39 | //if(m->status->Pc[0]=='.') { // Shell command
|
|---|
| 40 | // system(&(m->status->Pc[1]));
|
|---|
| 41 | // continue;
|
|---|
| 42 | //}
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | sprintf(str,"USER> %s",m->status->Pc);
|
|---|
| 46 | m->log->LogWrite(str);
|
|---|
| 47 |
|
|---|
| 48 | ParseInput(m->status->Pc,&(m->status->NParam),m->status->Param);
|
|---|
| 49 |
|
|---|
| 50 | pthread_mutex_lock(&m->control_mutex);
|
|---|
| 51 |
|
|---|
| 52 | if (m->CommandControl()==0)
|
|---|
| 53 | pthread_cond_broadcast(&m->control_cond);
|
|---|
| 54 |
|
|---|
| 55 | pthread_mutex_unlock(&m->control_mutex);
|
|---|
| 56 |
|
|---|
| 57 | } while ((c != NULL) && (!m->status->Exit));
|
|---|
| 58 |
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|