IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28129


Ignore:
Timestamp:
May 26, 2010, 4:53:35 PM (16 years ago)
Author:
eugene
Message:

auto-timeout on visualization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/extras/pmVisual.c

    r25754 r28129  
    8686
    8787
     88// ask the user to continue or not.  give up after 2 seconds.
     89// XXX add option to turn on/off timeouts?
    8890bool pmVisualAskUser(bool *plotFlag)
    8991{
     92    struct timeval timeout;
     93    fd_set fdSet;
     94    int status;
     95
    9096    char key[10];
    9197    if (plotFlag) {
    92         fprintf (stdout, "[c]ontinue? [s]kip the rest of these plots? [a]bort all visual plots? (c) ");
     98        fprintf (stderr, "[p]ause? [c]ontinue? [s]kip the rest of these plots? [a]bort all visual plots? (c) ");
    9399    } else {
    94         fprintf (stdout, "[c]ontinue? [a]bort all visual plots? (c) ");
    95     }
    96     if (!fgets(key, 8, stdin)) {
    97         psWarning("Unable to read option");
    98     }
    99     if (plotFlag && (key[0] == 's')) {
    100         *plotFlag = false;
    101     }
    102     if (key[0] == 'a') {
    103         isVisual = false;
     100        fprintf (stderr, "[p]ause? [c]ontinue? [a]bort all visual plots? (c) ");
     101    }
     102
     103    /* Wait up to 1.0 second for a response, then continue */
     104    timeout.tv_sec = 2;
     105    timeout.tv_usec = 0;
     106
     107    FD_ZERO (&fdSet);
     108    FD_SET (STDIN_FILENO, &fdSet);
     109
     110    status = select (1, &fdSet, NULL, NULL, &timeout);
     111    if (status <= 0) {
     112        fprintf (stderr, "\n");
     113        return true; // if no data, give up
     114    }
     115
     116    while (true) {
     117        if (!fgets(key, 8, stdin)) {
     118            psWarning("Unable to read option");
     119        }
     120        switch (key[0]) {
     121          case 's':
     122            if (plotFlag) *plotFlag = false;
     123            *plotFlag = false;
     124            return true;
     125          case 'a':
     126            isVisual = false;
     127            return true;
     128          case 'c':
     129          case '\n':
     130            return true;
     131          default:
     132            break;
     133        }
     134       
     135        if (plotFlag) {
     136            fprintf (stderr, "[c]ontinue? [s]kip the rest of these plots? [a]bort all visual plots? (c) ");
     137        } else {
     138            fprintf (stderr, "[c]ontinue? [a]bort all visual plots? (c) ");
     139        }
    104140    }
    105141    return true;
Note: See TracChangeset for help on using the changeset viewer.