IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 16, 2020, 1:54:47 PM (6 years ago)
Author:
tdeboer
Message:

revert to working Ohana build

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/lib.shell/multicommand.c

    r41161 r41340  
    6363
    6464  p = line;
    65   int Nline = strlen(line);
    66  
    6765  done = FALSE;
    6866  status = TRUE;
     
    7674    tmpline = strncreate (p, q - p);
    7775    stripwhite (tmpline);
    78     myAssert (tmpline, "oops");
     76    if (*tmpline) {
    7977
    80     // empty command, free and continue
    81     if (*tmpline == 0) {
    82       free (tmpline);
    83       if (q == line + Nline) {
    84         done = TRUE;
    85       } else {
    86         p = q + 1;
    87         myAssert (p - line <= Nline, "oops");
     78      if (bufferPending) {
     79        // flush old messages
     80        ExpectMessage (server, 0.2, &message);
     81        bufferPending = FALSE;
    8882      }
    89       continue;
    90     }
    9183
    92     if (bufferPending) {
    93       // flush old messages
    94       ExpectMessage (server, 0.2, &message);
    95       bufferPending = FALSE;
    96     }
     84      status = command (tmpline, &outline, verbose);
    9785
    98     // input tmpline is freed by command
    99     status = command (tmpline, &outline, verbose);
     86      if (status == -1) {
     87        if (server) {
     88          // send the command to the server instead
     89          if (!SendMessage (server, "%s", outline)) {
     90            switch (errno) {
     91              case EPIPE:
     92                gprint (GP_ERR, "server connection has died\n");
     93                exit (32);
     94              default:
     95                gprint (GP_ERR, "server is busy...32\n");
     96                bufferPending = TRUE;
     97                goto escape;
     98            }
     99          }
    100100
    101     if (status == -1) {
    102       if (server) {
    103         // send the command to the server instead
    104         if (!SendMessage (server, "%s", outline)) {
    105           switch (errno) {
    106             case EPIPE:
    107               gprint (GP_ERR, "server connection has died\n");
    108               exit (32);
    109             default:
    110               gprint (GP_ERR, "server is busy...32\n");
    111               bufferPending = TRUE;
    112               goto escape;
     101          // receive the command exit status
     102          if (ExpectMessage (server, MSG_TIMEOUT, &message)) {
     103            switch (errno) {
     104              case EPIPE:
     105                gprint (GP_ERR, "server connection has died\n");
     106                exit (33);
     107              default:
     108                gprint (GP_ERR, "server is busy...33\n");
     109                bufferPending = TRUE;
     110                goto escape;
     111            }
     112          } else {
     113            sscanf (message.buffer, "STATUS %d", &status);
    113114          }
    114         }
    115115
    116         // receive the command exit status
    117         if (ExpectMessage (server, MSG_TIMEOUT, &message)) {
    118           switch (errno) {
    119             case EPIPE:
    120               gprint (GP_ERR, "server connection has died\n");
    121               exit (33);
    122             default:
    123               gprint (GP_ERR, "server is busy...33\n");
    124               bufferPending = TRUE;
    125               goto escape;
     116          // receive the resulting stderr
     117          if (ExpectMessage (server, MSG_TIMEOUT, &message)) {
     118            switch (errno) {
     119              case EPIPE:
     120                gprint (GP_ERR, "server connection has died\n");
     121                exit (34);
     122              default:
     123                gprint (GP_ERR, "server is busy...34\n");
     124                bufferPending = TRUE;
     125                goto escape;
     126            }
     127          } else {
     128            gwrite (message.buffer, 1, message.Nbuffer, GP_ERR);
     129          }
     130
     131          // receive the resulting stdout
     132          if (ExpectMessage (server, MSG_TIMEOUT, &message)) {
     133            switch (errno) {
     134              case EPIPE:
     135                gprint (GP_ERR, "server connection has died\n");
     136                exit (35);
     137              default:
     138                gprint (GP_ERR, "server is busy...35\n");
     139                bufferPending = TRUE;
     140                goto escape;
     141            }
     142          } else {
     143            gwrite (message.buffer, 1, message.Nbuffer, GP_LOG);
    126144          }
    127145        } else {
    128           sscanf (message.buffer, "STATUS %d", &status);
    129         }
    130 
    131         // receive the resulting stderr
    132         if (ExpectMessage (server, MSG_TIMEOUT, &message)) {
    133           switch (errno) {
    134             case EPIPE:
    135               gprint (GP_ERR, "server connection has died\n");
    136               exit (34);
    137             default:
    138               gprint (GP_ERR, "server is busy...34\n");
    139               bufferPending = TRUE;
    140               goto escape;
    141           }
    142         } else {
    143           gwrite (message.buffer, 1, message.Nbuffer, GP_ERR);
    144         }
    145 
    146         // receive the resulting stdout
    147         if (ExpectMessage (server, MSG_TIMEOUT, &message)) {
    148           switch (errno) {
    149             case EPIPE:
    150               gprint (GP_ERR, "server connection has died\n");
    151               exit (35);
    152             default:
    153               gprint (GP_ERR, "server is busy...35\n");
    154               bufferPending = TRUE;
    155               goto escape;
    156           }
    157         } else {
    158           gwrite (message.buffer, 1, message.Nbuffer, GP_LOG);
    159         }
    160       } else {
    161         // if no server is defined, we treat an unknown command as an error
    162         status = FALSE;
    163       }
     146          // if no server is defined, we treat an unknown command as an error
     147          status = FALSE;
     148        }       
     149      }
     150    escape:
     151      if (outline != NULL) free (outline);
     152      if (!status && auto_break) done = TRUE;
    164153    }
    165   escape:
    166     if (outline != NULL) free (outline);
    167     if (!status && auto_break) done = TRUE;
    168 
    169154    p = q + 1;
    170155  }
Note: See TracChangeset for help on using the changeset viewer.