Пример #1
0
// command to display message
int commandScanMessage(const char *pBuffer, command_param_t *pCommandParameter, void *pData)
{
  const char * message = commandMatch(pBuffer, pCommandParameter->command);

  printf("MESSAGE\n");
  printf("Message:   %s\n", message);
  return 1;
}
// Look up the prefix of a value, returning its type code.
// If there is no match, return Unknown.  If the prefix has an
// associated slot, then activate the slot.  The "command"
// indicates the context of the lookup so that a prefix with the
// "mayBeCommand" flag set will not result in slot invocation.
QPrefixMatcher::Type QPrefixMatcher::lookup
        ( const QString& value, const QString& command ) const
{
    QPrefixMatcherNode *current = root->children;
    QPrefixMatcherNode *best = 0;
    int bestPosn = 0;
    int posn;
    ushort ch;

    // Bail out if the tree is currently empty.
    if ( !current )
        return QPrefixMatcher::Unknown;

    // Scan the string for a suitable prefix match.  We try to find
    // the longest such match so that "+CXYZ: W" will override "+CXYZ:".
    posn = 0;
    while ( posn < value.length() ) {
        ch = value[posn++].unicode();
        if ( ch >= 'a' && ch <= 'z' )
            ch = ch - 'a' + 'A';
        while ( current != 0 && current->ch != ch ) {
            current = current->next;
        }
        if ( !current ) {
            break;
        }
        if ( current->marker ) {
            best = current;
            bestPosn = posn;
        }
        current = current->children;
    }

    // Did we find something that matched?
    if ( best ) {
        if ( !best->mayBeCommand ||
             !commandMatch( value.left( bestPosn ), command ) ) {
            // Invoke the target slots associated with this match.
            QPrefixMatcherTarget *t = best->targets;
            void *a[2];
            while ( t != 0 ) {
                a[0] = (void *)0;
                a[1] = (void *)&value;
                if ( t->target ) {
                    t->target->qt_metacall( QMetaObject::InvokeMetaMethod,
                                            t->index, a );
                }
                t = t->next;
            }
            return best->type;
        } else if ( best->type != QPrefixMatcher::Notification ) {
            return best->type;
        }
    }

    // If we get here, we were unable to find a match.
    return QPrefixMatcher::Unknown;
}
Пример #3
0
// tests a single command for a match
// the callback function is called if there is a match
int commandEntryProcess(const char *pBuffer, command_param_t *pCommandParameter)
{
  if (commandMatch(pBuffer, pCommandParameter->command))
  {
    return pCommandParameter->callback(pBuffer, pCommandParameter, pCommandParameter->data);
  }
  // else
  return 0;
}
Пример #4
0
// command to exit program
int commandScanDone(const char *pBuffer, command_param_t *pCommandParameter, void *pData)
{
  void **      dataParameter = (void **)pData;
  char *       message       = dataParameter[0];
  int *        exitCode      = dataParameter[1];
  int *        done          = dataParameter[2];
  const char * scanBuffer    = commandMatch(pBuffer, pCommandParameter->command);
  int          result        = commandScan(scanBuffer, "%d/%s", exitCode, message);
  *done = 1;
  //printf("DONE\n");
  //printf("Message:   %s\n",  message);
  //printf("Exit Code: %d\n", *exitCode);
  //exit(*exitCode);
  return result;
}