368 fflush(stdout); |
366 fflush(stdout); |
369 } |
367 } |
370 |
368 |
371 void VSExplorer::set(const QString &name, const QString &value) |
369 void VSExplorer::set(const QString &name, const QString &value) |
372 { |
370 { |
373 if('/' == *name.constData()) |
371 if (name.startsWith(QLatin1Char('/'))) |
374 prov.setValue(name, value); |
372 prov.setValue(name, value); |
375 else if(pwd.path().endsWith("/")) |
373 else if (pwd.path().endsWith(QLatin1Char('/'))) |
376 prov.setValue(pwd.path() + name, value); |
374 prov.setValue(pwd.path() + name, value); |
377 else |
375 else |
378 prov.setValue(pwd.path() + "/" + name, value); |
376 prov.setValue(pwd.path() + QLatin1Char('/') + name, value); |
379 } |
377 } |
380 |
378 |
381 void VSExplorer::clear(const QString &name) |
379 void VSExplorer::clear(const QString &name) |
382 { |
380 { |
383 if('/' == *name.constData()) |
381 if (name.startsWith(QLatin1Char('/'))) |
384 prov.resetValue(name); |
382 prov.resetValue(name); |
385 else if(pwd.path().endsWith("/")) |
383 else if (pwd.path().endsWith(QLatin1Char('/'))) |
386 prov.resetValue(pwd.path() + name); |
384 prov.resetValue(pwd.path() + name); |
387 else |
385 else |
388 prov.resetValue(pwd.path() + "/" + name); |
386 prov.resetValue(pwd.path() + QLatin1Char('/') + name); |
389 } |
387 } |
390 |
388 |
391 void VSExplorer::processLine(const QString &line) |
389 void VSExplorer::processLine(const QString &line) |
392 { |
390 { |
393 QStringList cmds = line.trimmed().split(' '); |
391 QStringList cmds = line.trimmed().split(QLatin1Char(' ')); |
394 |
392 |
395 if(cmds.isEmpty()) { |
393 if(cmds.isEmpty()) { |
396 return; |
394 return; |
397 } |
395 } |
398 |
396 |
399 const QString & cmd = cmds.at(0); |
397 const QString & cmd = cmds.at(0); |
400 if(cmd == "ls" && 1 == cmds.count()) { |
398 if (cmd.isEmpty()) { |
|
399 |
|
400 } else if (cmd == QLatin1String("ls") && 1 == cmds.count()) { |
401 ls(); |
401 ls(); |
402 } else if(cmd == "dump") { |
402 } else if (cmd == QLatin1String("dump")) { |
403 dump(); |
403 dump(); |
404 } else if(cmd == "pwd") { |
404 } else if (cmd == QLatin1String("pwd")) { |
405 pwdCmd(); |
405 pwdCmd(); |
406 } else if(cmd == "ls" && 2 <= cmds.count()) { |
406 } else if (cmd == QLatin1String("ls") && 2 <= cmds.count()) { |
407 QStringList newCmds = cmds; |
407 QStringList newCmds = cmds; |
408 newCmds.removeFirst(); |
408 newCmds.removeFirst(); |
409 bool lsAll = false; |
409 bool lsAll = false; |
410 if(newCmds.first() == "-a") { |
410 if (newCmds.first() == QLatin1String("-a")) { |
411 lsAll = true; |
411 lsAll = true; |
412 newCmds.removeFirst(); |
412 newCmds.removeFirst(); |
413 } |
413 } |
414 QString newPath = newCmds.join(" "); |
414 QString newPath = newCmds.join(QLatin1String(" ")); |
415 if(newPath.startsWith("\"") && newPath.endsWith("\"")) { |
415 if (newPath.startsWith(QLatin1Char('"')) && newPath.endsWith(QLatin1Char('"'))) { |
416 newPath = newPath.mid(1); |
416 newPath = newPath.mid(1); |
417 newPath = newPath.left(newPath.length() - 1); |
417 newPath = newPath.left(newPath.length() - 1); |
418 } |
418 } |
419 if(newPath.isEmpty()) { |
419 if(newPath.isEmpty()) { |
420 ls(pwd.path().toAscii(), lsAll); |
420 ls(pwd.path(), lsAll); |
421 } else if(newPath.startsWith("/")) { |
421 } else if (newPath.startsWith(QLatin1Char('/'))) { |
422 ls(newPath.toAscii(), lsAll); |
422 ls(newPath, lsAll); |
423 } else { |
423 } else { |
424 QString oldPath = pwd.path(); |
424 QString oldPath = pwd.path(); |
425 if(!oldPath.endsWith("/")) |
425 if (!oldPath.endsWith(QLatin1Char('/'))) |
426 oldPath.append("/"); |
426 oldPath.append(QLatin1Char('/')); |
427 oldPath.append(newPath); |
427 oldPath.append(newPath); |
428 oldPath = QDir::cleanPath(oldPath); |
428 oldPath = QDir::cleanPath(oldPath); |
429 ls(oldPath.toAscii(), lsAll); |
429 ls(oldPath, lsAll); |
430 } |
430 } |
431 |
431 |
432 } else if(cmd == "cd" && 2 <= cmds.count()) { |
432 } else if (cmd == QLatin1String("cd") && 2 <= cmds.count()) { |
433 QStringList newCmds = cmds; |
433 QStringList newCmds = cmds; |
434 newCmds.removeFirst(); |
434 newCmds.removeFirst(); |
435 QString newPath = newCmds.join(" "); |
435 QString newPath = newCmds.join(QLatin1String(" ")); |
436 if(newPath.startsWith("\"") && newPath.endsWith("\"")) { |
436 if (newPath.startsWith(QLatin1Char('"')) && newPath.endsWith(QLatin1Char('"'))) { |
437 newPath = newPath.mid(1); |
437 newPath = newPath.mid(1); |
438 newPath = newPath.left(newPath.length() - 1); |
438 newPath = newPath.left(newPath.length() - 1); |
439 } |
439 } |
440 if(newPath.startsWith("/")) { |
440 if (newPath.startsWith(QLatin1Char('/'))) { |
441 pwd.setPath(newPath); |
441 pwd.setPath(newPath); |
442 } else { |
442 } else { |
443 QString oldPath = pwd.path(); |
443 QString oldPath = pwd.path(); |
444 if(!oldPath.endsWith("/")) |
444 if (!oldPath.endsWith(QLatin1Char('/'))) |
445 oldPath.append("/"); |
445 oldPath.append(QLatin1Char('/')); |
446 oldPath.append(newPath); |
446 oldPath.append(newPath); |
447 oldPath = QDir::cleanPath(oldPath); |
447 oldPath = QDir::cleanPath(oldPath); |
448 pwd.setPath(oldPath); |
448 pwd.setPath(oldPath); |
449 } |
449 } |
450 } else if(cmd == "unwatch" && 2 <= cmds.count()) { |
450 } else if (cmd == QLatin1String("unwatch") && 2 <= cmds.count()) { |
451 QStringList newCmds = cmds; |
451 QStringList newCmds = cmds; |
452 newCmds.removeFirst(); |
452 newCmds.removeFirst(); |
453 QString newPath = newCmds.join(" "); |
453 QString newPath = newCmds.join(QLatin1String(" ")); |
454 QString finalPath; |
454 QString finalPath; |
455 if(newPath.startsWith("\"") && newPath.endsWith("\"")) { |
455 if (newPath.startsWith(QLatin1Char('"')) && newPath.endsWith(QLatin1Char('"'))) { |
456 newPath = newPath.mid(1); |
456 newPath = newPath.mid(1); |
457 newPath = newPath.left(newPath.length() - 1); |
457 newPath = newPath.left(newPath.length() - 1); |
458 } |
458 } |
459 if(newPath.startsWith("/")) { |
459 if (newPath.startsWith(QLatin1Char('/'))) { |
460 finalPath = QValueSpaceSubscriber(newPath).path(); |
460 finalPath = QValueSpaceSubscriber(newPath).path(); |
461 } else { |
461 } else { |
462 QString oldPath = pwd.path(); |
462 QString oldPath = pwd.path(); |
463 if(!oldPath.endsWith("/")) |
463 if (!oldPath.endsWith(QLatin1Char('/'))) |
464 oldPath.append("/"); |
464 oldPath.append(QLatin1Char('/')); |
465 oldPath.append(newPath); |
465 oldPath.append(newPath); |
466 oldPath = QDir::cleanPath(oldPath); |
466 oldPath = QDir::cleanPath(oldPath); |
467 finalPath = QValueSpaceSubscriber(oldPath).path(); |
467 finalPath = QValueSpaceSubscriber(oldPath).path(); |
468 } |
468 } |
469 unwatch(finalPath.toUtf8()); |
469 unwatch(finalPath); |
470 } else if(cmd == "watch" && 2 <= cmds.count()) { |
470 } else if (cmd == QLatin1String("watch") && 2 <= cmds.count()) { |
471 QStringList newCmds = cmds; |
471 QStringList newCmds = cmds; |
472 newCmds.removeFirst(); |
472 newCmds.removeFirst(); |
473 QString newPath = newCmds.join(" "); |
473 QString newPath = newCmds.join(QLatin1String(" ")); |
474 QString finalPath; |
474 QString finalPath; |
475 if(newPath.startsWith("\"") && newPath.endsWith("\"")) { |
475 if (newPath.startsWith(QLatin1Char('"')) && newPath.endsWith(QLatin1Char('"'))) { |
476 newPath = newPath.mid(1); |
476 newPath = newPath.mid(1); |
477 newPath = newPath.left(newPath.length() - 1); |
477 newPath = newPath.left(newPath.length() - 1); |
478 } |
478 } |
479 if(newPath.startsWith("/")) { |
479 if (newPath.startsWith(QLatin1Char('/'))) { |
480 finalPath = QValueSpaceSubscriber(newPath).path(); |
480 finalPath = QValueSpaceSubscriber(newPath).path(); |
481 } else { |
481 } else { |
482 QString oldPath = pwd.path(); |
482 QString oldPath = pwd.path(); |
483 if(!oldPath.endsWith("/")) |
483 if (!oldPath.endsWith(QLatin1Char('/'))) |
484 oldPath.append("/"); |
484 oldPath.append(QLatin1Char('/')); |
485 oldPath.append(newPath); |
485 oldPath.append(newPath); |
486 oldPath = QDir::cleanPath(oldPath); |
486 oldPath = QDir::cleanPath(oldPath); |
487 finalPath = QValueSpaceSubscriber(oldPath).path(); |
487 finalPath = QValueSpaceSubscriber(oldPath).path(); |
488 } |
488 } |
489 watch(finalPath.toUtf8()); |
489 watch(finalPath); |
490 } else if(cmd == "set" && 3 == cmds.count()) { |
490 } else if (cmd == QLatin1String("set") && 3 == cmds.count()) { |
491 set(cmds.at(1).trimmed(), cmds.at(2).trimmed()); |
491 set(cmds.at(1).trimmed(), cmds.at(2).trimmed()); |
492 } else if(cmd == "clear" && 2 == cmds.count()) { |
492 } else if (cmd == QLatin1String("clear") && 2 == cmds.count()) { |
493 clear(cmds.at(1).trimmed()); |
493 clear(cmds.at(1).trimmed()); |
494 } else if((cmd == "subscribe" || cmd == "sub") && 1 == cmds.count()) { |
494 } else if ((cmd == QLatin1String("subscribe") || cmd == QLatin1String("sub")) && |
|
495 1 == cmds.count()) { |
495 subscribe(); |
496 subscribe(); |
496 } else if((cmd == "unsubscribe" || cmd == "unsub") && 1 == cmds.count()) { |
497 } else if ((cmd == QLatin1String("unsubscribe") || cmd == QLatin1String("unsub")) && |
|
498 1 == cmds.count()) { |
497 unsubscribe(); |
499 unsubscribe(); |
498 } else if((cmd == "?" || cmd == "help") && 1 == cmds.count()) { |
500 } else if ((cmd == QLatin1String("?") || cmd == QLatin1String("help")) && 1 == cmds.count()) { |
499 printHelp(); |
501 printHelp(); |
500 } else if((cmd == "quit" || cmd == "exit") && 1 == cmds.count()) { |
502 } else if ((cmd == QLatin1String("quit") || cmd == QLatin1String("exit")) && |
|
503 1 == cmds.count()) { |
501 quit(); |
504 quit(); |
502 } else if((cmd == "suppress") && 1 == cmds.count()) { |
505 } else if (cmd == QLatin1String("suppress") && 1 == cmds.count()) { |
503 suppress(); |
506 suppress(); |
504 } else if((cmd == "watchers") && 1 == cmds.count()) { |
507 } else if (cmd == QLatin1String("watchers") && 1 == cmds.count()) { |
505 listwatchers(); |
508 listwatchers(); |
506 } else if((cmd == "subscriptions") && 1 == cmds.count()) { |
509 } else if (cmd == QLatin1String("subscriptions") && 1 == cmds.count()) { |
507 subscriptions(); |
510 subscriptions(); |
508 } else if(cmd.isEmpty()) { |
|
509 } else { |
511 } else { |
510 printError(); |
512 printError(); |
511 } |
513 } |
512 } |
514 } |
513 |
515 |