Example #1
0
int JUCEApplication::main (int argc, const char* argv[])
{
    JUCE_AUTORELEASEPOOL

   #if JUCE_MAC
    initialiseNSApplication();
   #endif

   #if ! JUCE_WINDOWS
    jassert (createInstance != nullptr);
    juce_Argv0 = argv[0];
   #endif

   #if JUCE_IOS
    return juce_iOSMain (argc, argv);
   #else
    String cmd;
    for (int i = 1; i < argc; ++i)
    {
        String arg (argv[i]);
        if (arg.containsChar (' ') && ! arg.isQuotedString())
            arg = arg.quoted ('"');

        cmd << arg << ' ';
    }

    return JUCEApplication::main (cmd);
   #endif
}
Example #2
0
    void paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected) override
    {
        if (rowIsSelected)
            g.fillAll (Colours::deepskyblue);

        if (JuceDemoTypeBase* type = JuceDemoTypeBase::getDemoTypeList() [rowNumber])
        {
            String name (type->name.trimCharactersAtStart ("0123456789").trimStart());

            AttributedString a;
            a.setJustification (Justification::centredLeft);

            String category;

            if (name.containsChar (':'))
            {
                category = name.upToFirstOccurrenceOf (":", true, false);
                name = name.fromFirstOccurrenceOf (":", false, false).trim();

                if (height > 20)
                    category << "\n";
                else
                    category << " ";
            }

            if (category.isNotEmpty())
                a.append (category, Font (10.0f), Colour::greyLevel (0.5f));

            a.append (name, Font (13.0f), Colours::white.withAlpha (0.9f));

            a.draw (g, Rectangle<int> (width + 10, height).reduced (6, 0).toFloat());
        }
    }
void UnityProjectBuilder::updateBuildDirectories()
{
    if (buildDir.isEmpty())
        return;
    
    ValueTree exportsTree (project.getChildWithName (Ids::exportFormats));
    
    if (! exportsTree.isValid())
        return;
    
    const int numExports = exportsTree.getNumChildren();
    
    for (int i = 0; i < numExports; ++i)
    {
        ValueTree exporter (exportsTree.getChild (i));
        
        if (exporter.hasProperty (Ids::targetFolderProp))
        {
            logOutput ("Updating exporter " + exporter.getType().toString());
            const String oldTarget (exporter.getProperty (Ids::targetFolderProp).toString());
            String newTarget (buildDir);
            
            if (oldTarget.containsChar ('/'))
                 newTarget << oldTarget.fromLastOccurrenceOf ("/", true, false);
                
            exporter.setProperty (Ids::targetFolderProp, newTarget, nullptr);
        }
    }
}
Example #4
0
//==============================================================================
bool URL::isProbablyAWebsiteURL (const String& possibleURL)
{
    static const char* validProtocols[] = { "http:", "ftp:", "https:" };

    for (auto* protocol : validProtocols)
        if (possibleURL.startsWithIgnoreCase (protocol))
            return true;

    if (possibleURL.containsChar ('@')
        || possibleURL.containsChar (' '))
        return false;

    const String topLevelDomain (possibleURL.upToFirstOccurrenceOf ("/", false, false)
                                 .fromLastOccurrenceOf (".", false, false));

    return topLevelDomain.isNotEmpty() && topLevelDomain.length() <= 3;
}
Example #5
0
    String floatLiteral (double value, int numDecPlaces)
    {
        String s (value, numDecPlaces);

        if (s.containsChar ('.'))
            s << 'f';
        else
            s << ".0f";

        return s;
    }
Example #6
0
//==============================================================================
KeyPress KeyPress::createFromDescription (const String& desc)
{
    int modifiers = 0;

    for (int i = 0; i < numElementsInArray (KeyPressHelpers::modifierNames); ++i)
        if (desc.containsWholeWordIgnoreCase (KeyPressHelpers::modifierNames[i].name))
            modifiers |= KeyPressHelpers::modifierNames[i].flag;

    int key = 0;

    for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
    {
        if (desc.containsWholeWordIgnoreCase (String (KeyPressHelpers::translations[i].name)))
        {
            key = KeyPressHelpers::translations[i].code;
            break;
        }
    }

    if (key == 0)
        key = KeyPressHelpers::getNumpadKeyCode (desc);

    if (key == 0)
    {
        // see if it's a function key..
        if (! desc.containsChar ('#')) // avoid mistaking hex-codes like "#f1"
        {
            for (int i = 1; i <= 35; ++i)
            {
                if (desc.containsWholeWordIgnoreCase ("f" + String (i)))
                {
                    if (i <= 16)        key = F1Key + i - 1;
                    else if (i <= 24)   key = F17Key + i - 17;
                    else if (i <= 35)   key = F25Key + i - 25;
                }
            }
        }

        if (key == 0)
        {
            // give up and use the hex code..
            auto hexCode = desc.fromFirstOccurrenceOf ("#", false, false)
                               .retainCharacters ("0123456789abcdefABCDEF")
                               .getHexValue32();

            if (hexCode > 0)
                key = hexCode;
            else
                key = (int) CharacterFunctions::toUpperCase (desc.getLastCharacter());
        }
    }

    return KeyPress (key, ModifierKeys (modifiers), 0);
}
Example #7
0
RSAKey::RSAKey (const String& s)
{
    if (s.containsChar (','))
    {
        part1.parseString (s.upToFirstOccurrenceOf (",", false, false), 16);
        part2.parseString (s.fromFirstOccurrenceOf (",", false, false), 16);
    }
    else
    {
        // the string needs to be two hex numbers, comma-separated..
        jassertfalse;
    }
}
Example #8
0
String addQuotesIfContainsSpaces (const String& text)
{
    return (text.containsChar (' ') && ! text.isQuotedString()) ? text.quoted() : text;
}
Example #9
0
//==============================================================================
String File::parseAbsolutePath (const String& p)
{
    if (p.isEmpty())
        return String::empty;

#if JUCE_WINDOWS
    // Windows..
    String path (p.replaceCharacter ('/', '\\'));

    if (path.startsWithChar (separator))
    {
        if (path[1] != separator)
        {
            /*  When you supply a raw string to the File object constructor, it must be an absolute path.
                If you're trying to parse a string that may be either a relative path or an absolute path,
                you MUST provide a context against which the partial path can be evaluated - you can do
                this by simply using File::getChildFile() instead of the File constructor. E.g. saying
                "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
                path if that's what was supplied, or would evaluate a partial path relative to the CWD.
            */
            jassertfalse;

            path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
        }
    }
    else if (! path.containsChar (':'))
    {
        /*  When you supply a raw string to the File object constructor, it must be an absolute path.
            If you're trying to parse a string that may be either a relative path or an absolute path,
            you MUST provide a context against which the partial path can be evaluated - you can do
            this by simply using File::getChildFile() instead of the File constructor. E.g. saying
            "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
            path if that's what was supplied, or would evaluate a partial path relative to the CWD.
        */
        jassertfalse;

        return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
    }
#else
    // Mac or Linux..

    // Yes, I know it's legal for a unix pathname to contain a backslash, but this assertion is here
    // to catch anyone who's trying to run code that was written on Windows with hard-coded path names.
    // If that's why you've ended up here, use File::getChildFile() to build your paths instead.
    jassert ((! p.containsChar ('\\')) || (p.indexOfChar ('/') >= 0 && p.indexOfChar ('/') < p.indexOfChar ('\\')));

    String path (p);

    if (path.startsWithChar ('~'))
    {
        if (path[1] == separator || path[1] == 0)
        {
            // expand a name of the form "~/abc"
            path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
                    + path.substring (1);
        }
        else
        {
            // expand a name of type "~dave/abc"
            const String userName (path.substring (1).upToFirstOccurrenceOf ("/", false, false));

            if (struct passwd* const pw = getpwnam (userName.toUTF8()))
                path = addTrailingSeparator (pw->pw_dir) + path.fromFirstOccurrenceOf ("/", false, false);
        }
    }
    else if (! path.startsWithChar (separator))
    {
       #if JUCE_DEBUG || JUCE_LOG_ASSERTIONS
        if (! (path.startsWith ("./") || path.startsWith ("../")))
        {
            /*  When you supply a raw string to the File object constructor, it must be an absolute path.
                If you're trying to parse a string that may be either a relative path or an absolute path,
                you MUST provide a context against which the partial path can be evaluated - you can do
                this by simply using File::getChildFile() instead of the File constructor. E.g. saying
                "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
                path if that's what was supplied, or would evaluate a partial path relative to the CWD.
            */
            jassertfalse;

           #if JUCE_LOG_ASSERTIONS
            Logger::writeToLog ("Illegal absolute path: " + path);
           #endif
        }
       #endif

        return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
    }
#endif

    while (path.endsWithChar (separator) && path != separatorString) // careful not to turn a single "/" into an empty string.
        path = path.dropLastCharacters (1);

    return path;
}
Example #10
0
  bool parseFile (const File& rootFolder,
    const File& newTargetFile,
    OutputStream& dest,
    const File& file,
    StringArray& alreadyIncludedFiles,
    const StringArray& includesToIgnore,
    const StringArray& wildcards,
    int level,
    bool stripCommentBlocks)
  {
    // Make sure the file exists

    if (! file.exists())
    {
      std::cout << "  !! ERROR - file doesn't exist!";
      return false;
    }

    // Load the entire file as an array of individual lines.

    StringArray lines;
    lines.addLines (file.loadFileAsString());

    // Make sure there is something in the file.

    if (lines.size() == 0)
    {
      std::cout << "  !! ERROR - input file was empty: " << file.getFullPathName();
      return false;
    }

    // Produce some descriptive progress.

    if (m_verbose)
    {
      if (level == 0)
        std::cout << "  Processing \"" << file.getFileName () << "\"\n";
      else
        std::cout << "  Inlining " << String::repeatedString (" ", level - 1)
                  << "\"" << file.getFileName () << "\"\n";
    }

    bool lastLineWasBlank = true;

    for (int i = 0; i < lines.size(); ++i)
    {
      String line (lines[i]);
      String trimmed (line.trimStart());

      if ((level != 0) && trimmed.startsWith ("//================================================================"))
        line = String::empty;

      std::string s (line.toUTF8 ());

      if (m_remapTable.processLine (s))
      {
        line = String::empty;
      }
      else
      {
        ParsedInclude parsedInclude = parseInclude (line, trimmed);

        if (parsedInclude.isIncludeLine)
        {
          const File targetFile = findInclude (file, parsedInclude.filename);

          if (targetFile.exists())
          {
            if (matchesWildcard (parsedInclude.filename.replaceCharacter ('\\', '/'))
              && ! includesToIgnore.contains (targetFile.getFileName()))
            {
              String fileNamePart = File (parsedInclude.filename).getFileName ();
              RemapTable::iterator remapTo = m_remapTable.find (std::string (fileNamePart.toUTF8 ()));
              if (level != 0 && remapTo != m_remapTable.end ())
              {
                line = "#include \"";
                line << String(remapTo->second.c_str ()) << "\"" << newLine;

                findAllFilesIncludedIn (targetFile, alreadyIncludedFiles);
              }
              else if (line.containsIgnoreCase("SKIP_AMALGAMATOR_INCLUDE"))
              {
              }
              else if (line.containsIgnoreCase ("FORCE_AMALGAMATOR_INCLUDE")
                || ! alreadyIncludedFiles.contains (targetFile.getFullPathName()))
              {
                if (parsedInclude.preventReinclude)
                {
                  alreadyIncludedFiles.add (targetFile.getFullPathName());
                }
                else if (parsedInclude.forceReinclude)
                {
                }
                else if (! canFileBeReincluded (targetFile))
                {
                  alreadyIncludedFiles.add (targetFile.getFullPathName());
                }

                dest << newLine << "/*** Start of inlined file: " << targetFile.getFileName() << " ***/" << newLine;

                if (! parseFile (rootFolder, newTargetFile,
                  dest, targetFile, alreadyIncludedFiles, includesToIgnore,
                  wildcards, level + 1, stripCommentBlocks))
                {
                  return false;
                }

                dest << "/*** End of inlined file: " << targetFile.getFileName() << " ***/" << newLine << newLine;

                line = parsedInclude.lineAfterInclude;
              }
              else
              {
                line = String::empty;
              }
            }
            else
            {
              line = parsedInclude.lineUpToEndOfInclude.upToFirstOccurrenceOf ("\"", true, false)
                + targetFile.getRelativePathFrom (newTargetFile.getParentDirectory())
                .replaceCharacter ('\\', '/')
                + "\""
                + parsedInclude.lineAfterInclude;
            }
          }
        }
      }

      if ((stripCommentBlocks || i == 0) && trimmed.startsWith ("/*") && (i > 10 || level != 0))
      {
        int originalI = i;
        String originalLine = line;

        for (;;)
        {
          int end = line.indexOf ("*/");

          if (end >= 0)
          {
            line = line.substring (end + 2);

            // If our comment appeared just before an assertion, leave it in, as it
            // might be useful..
            if (lines [i + 1].contains ("assert")
              || lines [i + 2].contains ("assert"))
            {
              i = originalI;
              line = originalLine;
            }

            break;
          }

          line = lines [++i];

          if (i >= lines.size())
            break;
        }

        line = line.trimEnd();
        if (line.isEmpty())
          continue;
      }

      line = line.trimEnd();

      {
        // Turn initial spaces into tabs..
        int numIntialSpaces = 0;
        int len = line.length();
        while (numIntialSpaces < len && line [numIntialSpaces] == ' ')
          ++numIntialSpaces;

        if (numIntialSpaces > 0)
        {
          int tabSize = 4;
          int numTabs = numIntialSpaces / tabSize;
          line = String::repeatedString ("\t", numTabs) + line.substring (numTabs * tabSize);
        }

  #if 0
        if (! line.containsChar ('"'))
        {
          // turn large areas of spaces into tabs - this will mess up alignment a bit, but
          // it's only the amalgamated file, so doesn't matter...
          line = line.replace ("        ", "\t", false);
          line = line.replace ("    ", "\t", false);
        }
  #endif
      }

      if (line.isNotEmpty() || ! lastLineWasBlank)
        dest << line << newLine;

      lastLineWasBlank = line.isEmpty();
    }

    return true;
  }