Exemple #1
0
void SetLineNumber(TSourceLoc line, TSourceLoc& outLine)
{
	outLine.file = NULL;
	outLine.line = line.line;
	
	if (line.file && line.file[0])
	{
		// GLSL does not permit quoted strings in #line directives
		
		if(line.file[0] == '"')
		{
			TString stripped(line.file + 1);
			size_t len = stripped.size();
			if(stripped[len - 1] == '"')
			{
				stripped.resize(len - 1);
			}
			
			outLine.file = NewPoolTString(stripped.c_str())->c_str();
		}
		else
		{
			outLine.file = NewPoolTString(line.file)->c_str();
		}
	}
}
Exemple #2
0
	// Find and execute the given command.
	static CBM::IOErrorMessage execute(const QString& cmdString, Interface& iface)
	{
		QString params, stripped(cmdString);
		// Strip of trailing whitespace (in fact, CR for e.g. OPEN 1,8,15,"I:" which generates a CR.
		while(stripped.endsWith(QChar('\r')) or stripped.endsWith(QChar(' ')))
			stripped.chop(1);
		Command* dosCmd = find(stripped, params);
		if(0 not_eq dosCmd)
			return dosCmd->process(params, iface);

		return CBM::ErrCommandNotFound;
	} // execute
Exemple #3
0
int QgsSpinBox::valueFromText( const QString &text ) const
{
  if ( !mExpressionsEnabled )
  {
    return QSpinBox::valueFromText( text );
  }

  QString trimmedText = stripped( text );
  if ( trimmedText.isEmpty() )
  {
    return mShowClearButton ? clearValue() : value();
  }

  return std::round( QgsExpression::evaluateToDouble( trimmedText, value() ) );
}
Exemple #4
0
void DigitView::slotZoomChange(const QString &zoom)
{
  QString stripped(zoom);

  if (stripped.right(1) == QString("%"))
    stripped.remove(stripped.length() - 1, 1);

  m_zoom = stripped.toInt();

  double scale = (double) m_zoom / 100.0;
  QMatrix ms;
  ms.scale(scale, scale);
  setWorldMatrix(ms);

  updateContents();
}
Exemple #5
0
void FontImporter::handlePage(std::stringstream & stream, FontFace * font, const std::string & filename)
{
    const std::string path = iozeug::FilePath(filename).directoryPath();
    extractKeyValuePairs(stream, [this, font, &path](const std::string & key, const std::string & value) {
        if (key == "file")
        {
            std::string filename = stripped(value, { '"', '\r' });

            font->setGlyphTexture(m_resourceManager.load<globjects::Texture>(path + "/" + filename));
        }
        else if (key == "id")
        {
            // nothing for now
        }
    });
}
Exemple #6
0
static void display_filename (unsigned long linenum, char status,
			      const char *filename, const char *patchname)
{
	if (mode == mode_list && !file_matches ())
		/* This is lsdiff --files=... and this file is not to be
		 * listed. */
		return;

	if (print_patchnames)
		printf ("%s:", patchname);
	if (numbering)
		printf ("%lu\t", linenum);
	if (number_files)
		printf ("File #%-3lu\t", filecount);
	if (show_status)
		printf ("%c ", status);
	if (prefix_to_add)
		fputs (prefix_to_add, stdout);
	puts (stripped (filename, strip_components));
}
// BTRTODO: Support arrays!?
MaterialParameters* ProcessedCustomMaterial::allocMaterialParameters()
{
   MaterialParameters* ret = Parent::allocMaterialParameters();
   // See if any of the dynamic fields match up with shader constants we have.
   SimFieldDictionary* fields = mMaterial->getFieldDictionary();
   if (!fields || fields->getNumFields() == 0)
      return ret;

   const Vector<GFXShaderConstDesc>& consts = ret->getShaderConstDesc();
   for (U32 i = 0; i < consts.size(); i++)
   {
      // strip the dollar sign from the front.
      String stripped(consts[i].name);
      stripped.erase(0, 1);      

      SimFieldDictionary::Entry* field = fields->findDynamicField(stripped);      
      if (field)
      {
         MaterialParameterHandle* handle = getMaterialParameterHandle(consts[i].name);
         switch (consts[i].constType)
         {
         case GFXSCT_Float :
            setMaterialParameter<F32>(ret, handle, field->value);
            break;
         case GFXSCT_Float2: 
            setMaterialParameter<Point2F>(ret, handle, field->value);
            break;            
         case GFXSCT_Float3: 
            setMaterialParameter<Point3F>(ret, handle, field->value);
            break;            
         case GFXSCT_Float4: 
            setMaterialParameter<Point4F>(ret, handle, field->value);
            break;            
         case GFXSCT_Float2x2:                         
         case GFXSCT_Float3x3: 
            setMatrixParameter(ret, handle, field->value, consts[i].constType);
            break;
         case GFXSCT_Float4x4: 
            setMaterialParameter<MatrixF>(ret, handle, field->value);
            break;            
         case GFXSCT_Int: 
            setMaterialParameter<S32>(ret, handle, field->value);
            break;
         case GFXSCT_Int2: 
            setMaterialParameter<Point2I>(ret, handle, field->value);
            break;
         case GFXSCT_Int3: 
            setMaterialParameter<Point3I>(ret, handle, field->value);
            break;
         case GFXSCT_Int4: 
            setMaterialParameter<Point4I>(ret, handle, field->value);
            break;
         // Do we want to ignore these?
         case GFXSCT_Sampler:
         case GFXSCT_SamplerCube:
         default:
            break;
         }
      }
   }
   return ret;
}
/*!
  \param points Series of data points
  \return Curve points
*/
QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const
{
    QStack<Line> stack;
    stack.reserve( 500 );

    const QPointF *p = points.data();
    const int nPoints = points.size();

    QVector<bool> usePoint( nPoints, false );

    double distToSegment;

    stack.push( Line( 0, nPoints - 1 ) );

    while ( !stack.isEmpty() )
    {
        const Line r = stack.pop();

        // initialize line segment
        const double vecX = p[r.to].x() - p[r.from].x();
        const double vecY = p[r.to].y() - p[r.from].y();

        const double vecLength = qSqrt( vecX * vecX + vecY * vecY );

        const double unitVecX = ( vecLength != 0.0 ) ? vecX / vecLength : 0.0;
        const double unitVecY = ( vecLength != 0.0 ) ? vecY / vecLength : 0.0;

        double maxDist = 0.0;
        int nVertexIndexMaxDistance = r.from + 1;
        for ( int i = r.from + 1; i < r.to; i++ )
        {
            //compare to anchor
            const double fromVecX = p[i].x() - p[r.from].x();
            const double fromVecY = p[i].y() - p[r.from].y();
            const double fromVecLength =
                qSqrt( fromVecX * fromVecX + fromVecY * fromVecY );

            if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 )
            {
                distToSegment = fromVecLength;
            }
            if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 )
            {
                distToSegment = fromVecLength;
            }
            else
            {
                const double toVecX = p[i].x() - p[r.to].x();
                const double toVecY = p[i].y() - p[r.to].y();
                const double toVecLength = qSqrt( toVecX * toVecX + toVecY * toVecY );
                const double s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY );
                if ( s < 0.0 )
                    distToSegment = toVecLength;
                else
                {
                    distToSegment = qSqrt( qFabs( toVecLength * toVecLength - s * s ) );
                }
            }

            if ( maxDist < distToSegment )
            {
                maxDist = distToSegment;
                nVertexIndexMaxDistance = i;
            }
        }
        if ( maxDist <= d_data->tolerance )
        {
            usePoint[r.from] = true;
            usePoint[r.to] = true;
        }
        else
        {
            stack.push( Line( r.from, nVertexIndexMaxDistance ) );
            stack.push( Line( nVertexIndexMaxDistance, r.to ) );
        }
    }

    int cnt = 0;

    QPolygonF stripped( nPoints );
    for ( int i = 0; i < nPoints; i++ )
    {
        if ( usePoint[i] )
            stripped[cnt++] = p[i];
    }
    stripped.resize( cnt );
    return stripped;
}
// ======================================================================
void ListHookedKeyboard::Item::apply(const Params_KeyboardEventCallBack& params) {
  if (params.key >= KeyCode::VK__BEGIN__) {
    // Invalid keycode
    IOLOG_ERROR("ListHookedKeyboard::Item::apply invalid key:%d eventType:%d\n", params.key.get(), params.eventType.get());
    return;
  }
  if (params.eventType == EventType::MODIFY && !params.key.isModifier()) {
    // Invalid modifierkeycode
    IOLOG_ERROR("ListHookedKeyboard::Item::apply invalid modifierkey:%08x\n", params.key.get());
    return;
  }

  // ------------------------------------------------------------
  KeyboardEventCallback callback = orig_keyboardEventAction_;
  if (!callback) return;

  OSObject* target = orig_keyboardEventTarget_;
  if (!target) return;

  OSObject* sender = OSDynamicCast(OSObject, device_);
  if (!sender) return;

  const AbsoluteTime& ts = CommonData::getcurrent_ts();
  OSObject* refcon = nullptr;

  // ----------------------------------------
  // Send an UpdateEventFlags event if needed. (Send before KeyboardEvent when EventType::DOWN)
  bool needUpdateEventFlagsEvent = false;
  if (params.flags.isOn(ModifierFlag::NUMPAD)) {
    needUpdateEventFlagsEvent = true;
  }

  if (needUpdateEventFlagsEvent && params.eventType == EventType::DOWN) {
    Params_UpdateEventFlagsCallback p(params.flags);
    apply(p);
  }

  // ----------------------------------------
  Params_KeyboardEventCallBack::log(false, params.eventType, params.flags, params.key, params.keyboardType, params.repeat);
  {
    // We need to unlock the global lock while we are calling the callback function.
    //
    // When Sticky Keys (in Universal Access) is activated,
    // Apple driver calls EventInputQueue::push_* recursively.
    //
    // If we don't unlock the global lock, deadlock is occured.
    GlobalLock::ScopedUnlock lk;
    callback(target, params.eventType.get(), params.flags.get(), params.key.get(),
             params.charCode.get(), params.charSet.get(), params.origCharCode.get(), params.origCharSet.get(),
             params.keyboardType.get(), params.repeat, ts, sender, refcon);
  }

  // ----------------------------------------
  // Send an UpdateEventFlags event if needed. (Send after KeyboardEvent when EventType::UP)
  if (needUpdateEventFlagsEvent && params.eventType == EventType::UP) {
    Flags stripped(params.flags);
    stripped.stripNUMPAD();

    Params_UpdateEventFlagsCallback p(stripped);
    apply(p);
  }

  // ----------------------------------------
  // The CapsLock LED is not designed to turn it on/off frequently.
  // So, we have to use the timer to call a setAlphaLock function at appropriate frequency.
  enum {
    CAPSLOCK_LED_DELAY_MS = 5,
  };
  setcapslock_timer_.setTimeoutMS(CAPSLOCK_LED_DELAY_MS, false);
}
Exemple #10
0
static int filterdiff (FILE *f, const char *patchname)
{
	static unsigned long linenum = 1;
	char *names[2];
	char *header[MAX_HEADERS] = { NULL, NULL };
        unsigned int num_headers = 0;
	char *line = NULL;
	size_t linelen = 0;
	char *p;
	const char *p_stripped;
	int match;
	int i;

	if (getline (&line, &linelen, f) == -1)
		return 0;

	for (;;) {
		char status = '!';
		unsigned long start_linenum;
		int orig_file_exists, new_file_exists;
		int is_context = -1;
		int result;
		int (*do_diff) (FILE *, char **, unsigned int,
                                int, char **, size_t *,
				unsigned long *, unsigned long,
				char, const char *, const char *,
				int *, int *);

		orig_file_exists = 0; // shut gcc up

		// Search for start of patch ("diff ", or "--- " for
		// unified diff, "*** " for context).
		for (;;) {
                        if (!strncmp (line, "diff ", 5))
                                break;

			if (!strncmp (line, "--- ", 4)) {
				is_context = 0;
				break;
			}

			if (!strncmp (line, "*** ", 4)) {
				is_context = 1;
				break;
			}

			/* Show non-diff lines if excluding, or if
			 * in verbose mode, and if --clean isn't specified. */
			if (mode == mode_filter && (pat_exclude || verbose)
				&& !clean_comments)
				fputs (line, stdout);

			if (getline (&line, &linelen, f) == -1)
				goto eof;
			linenum++;
		}

		start_linenum = linenum;
		header[0] = xstrdup (line);
                num_headers = 1;

                if (is_context == -1) {
                        int valid_extended = 1;
                        for (;;) {
                                if (getline (&line, &linelen, f) == -1)
                                        goto eof;
                                linenum++;

                                if (!strncmp (line, "diff ", 5)) {
                                        header[num_headers++] = xstrdup (line);
                                        break;
                                }

                                if (!strncmp (line, "--- ", 4))
                                        is_context = 0;
                                else if (!strncmp (line, "*** ", 4))
                                        is_context = 1;
                                else if (strncmp (line, "old mode ", 9) &&
                                    strncmp (line, "new mode ", 9) &&
                                    strncmp (line, "deleted file mode ", 18) &&
                                    strncmp (line, "new file mode ", 15) &&
                                    strncmp (line, "copy from ", 10) &&
                                    strncmp (line, "copy to ", 8) &&
                                    strncmp (line, "rename from ", 12) &&
                                    strncmp (line, "rename to ", 10) &&
                                    strncmp (line, "similarity index ", 17) &&
                                    strncmp (line, "dissimilarity index ", 20) &&
                                    strncmp (line, "index ", 6))
                                        valid_extended = 0;

                                if (!valid_extended)
                                        break;

                                /* Drop excess header lines */
                                if (num_headers >= MAX_HEADERS - 2)
                                        free (header[--num_headers]);

                                header[num_headers++] = xstrdup (line);

                                if (is_context != -1)
                                        break;
                        }

                        if (!valid_extended)
                                goto flush_continue;
                }

                if (is_context == -1) {
                        /* We don't yet do anything with diffs with
                         * zero hunks. */
                        unsigned int i = 0;
                flush_continue:
                        if (mode == mode_filter && (pat_exclude || verbose)
                            && !clean_comments) {
                                for (i = 0; i < num_headers; i++)
                                        fputs (header[i], stdout);
                        }
                        for (i = 0; i < num_headers; i++) {
                                free (header[i]);
                                header[i] = NULL;
                        }
                        num_headers = 0;
                        continue;
                }

		names[0] = filename_from_header (line + 4);
		if (mode != mode_filter && show_status)
			orig_file_exists = file_exists (names[0], line + 4 +
							strlen (names[0]));

		if (getline (&line, &linelen, f) == -1) {
			/* Show non-diff lines if excluding, or if
			 * in verbose mode, and if --clean isn't specified. */
			if (mode == mode_filter && (pat_exclude || verbose)
				&& !clean_comments)
				fputs (header[0], stdout);
			free (names[0]);
			goto eof;
		}
		linenum++;

		if (strncmp (line, is_context ? "--- " : "+++ ", 4)) {
			/* Show non-diff lines if excluding, or if
			 * in verbose mode, and if --clean isn't specified. */
			free (names[0]);
                        goto flush_continue;
		}

		filecount++;
		header[num_headers++] = xstrdup (line);
		names[1] = filename_from_header (line + 4);

		if (mode != mode_filter && show_status)
			new_file_exists = file_exists (names[1], line + 4 +
						       strlen (names[1]));

		// Decide whether this matches this pattern.
		p = best_name (2, names);
		p_stripped = stripped (p, ignore_components);

		match = !patlist_match(pat_exclude, p_stripped);
		if (match && pat_include != NULL)
			match = patlist_match(pat_include, p_stripped);

		// print if it matches.
		if (match && !show_status && mode == mode_list)
			display_filename (start_linenum, status,
					  p, patchname);

		if (is_context)
			do_diff = do_context;
		else
			do_diff = do_unified;

		result = do_diff (f, header, num_headers,
                                  match, &line,
				  &linelen, &linenum,
				  start_linenum, status, p, patchname,
				  &orig_file_exists, &new_file_exists);

		// print if it matches.
		if (match && show_status && mode == mode_list) {
			if (!orig_file_exists)
				status = '+';
			else if (!new_file_exists)
				status = '-';

			display_filename (start_linenum, status,
					  p, patchname);
		}

		switch (result) {
		case EOF:
			free (names[0]);
			free (names[1]);
			goto eof;
		case 1:
			goto next_diff;
		}

	next_diff:
		for (i = 0; i < 2; i++)
			free (names[i]);
                for (i = 0; i < num_headers; i++) {
			free (header[i]);
			header[i] = NULL;
		}
                num_headers = 0;
	}

 eof:
	for (i = 0; i < num_headers; i++)
		if (header[i])
			free (header[i]);

	if (line)
		free (line);

	return 0;
}
Exemple #11
0
static int output_header_line (const char *line)
{
	char *fn;

	if (strncmp (line, "diff", 4) == 0 && isspace (line[4])) {
		size_t		args = 0;
		const char	*end = line + 5, *begin = end, *ws = end;
		printf ("%.5s", line);
		while (*end != 0) {
			if (isspace (*begin))
				begin = end;
			if (isspace (*end)) {
				if (*begin == '-') {
					if (isspace (begin[1]))
						++args;
					printf ("%.*s", (int)(end - ws), ws);
				} else {
					printf ("%.*s", (int)(begin - ws), ws);
					if (args == 0 && old_prefix_to_add)
						fputs (old_prefix_to_add,
						       stdout);
					if (args == 1 && new_prefix_to_add)
						fputs (new_prefix_to_add,
						       stdout);
					++args;
					fn = xstrndup (begin, end - begin);
					fputs (stripped (fn,
							 strip_components),
					       stdout);
					free (fn);
				}
				ws = begin = end;
			}
			++end;
		}
		printf ("%.*s", (int)(end - ws), ws);
	} else if (strncmp (line, "---", 3) == 0 ||
		   strncmp (line, "+++", 3) == 0) {

		int h = strcspn (line + 4, "\t\n");
		fwrite (line, 1, 4, stdout);

		if (prefix_to_add)
			fputs (prefix_to_add, stdout);
		else {
			if (old_prefix_to_add && strncmp (line, "---", 3) == 0)
				fputs (old_prefix_to_add, stdout);
			if (new_prefix_to_add && strncmp (line, "+++", 3) == 0)
				fputs (new_prefix_to_add, stdout);
		}

		fn = xstrndup (line + 4, h);
		fputs (stripped (fn, strip_components), stdout);
		if (removing_timestamp)
			putchar ('\n');
		else
			fputs (line + 4 + h, stdout);

		free (fn);
	} else
		fputs (line, stdout);
	return 0;
}
void SkCommandLineFlags::Parse(int argc, char** argv) {
    // Only allow calling this function once.
    static bool gOnce;
    if (gOnce) {
        SkDebugf("Parse should only be called once at the beginning of main!\n");
        SkASSERT(false);
        return;
    }
    gOnce = true;

    bool helpPrinted = false;
    // Loop over argv, starting with 1, since the first is just the name of the program.
    for (int i = 1; i < argc; i++) {
        if (0 == strcmp("-h", argv[i]) || 0 == strcmp("--help", argv[i])) {
            // Print help message.
            SkTDArray<const char*> helpFlags;
            for (int j = i + 1; j < argc; j++) {
                if (SkStrStartsWith(argv[j], '-')) {
                    break;
                }
                helpFlags.append(1, &argv[j]);
            }
            if (0 == helpFlags.count()) {
                // Only print general help message if help for specific flags is not requested.
                SkDebugf("%s\n%s\n", argv[0], gUsage.c_str());
            }
            SkDebugf("Flags:\n");
            SkFlagInfo* flag = SkCommandLineFlags::gHead;
            while (flag != NULL) {
                // If no flags followed --help, print them all
                bool printFlag = 0 == helpFlags.count();
                if (!printFlag) {
                    for (int k = 0; k < helpFlags.count(); k++) {
                        if (flag->name().equals(helpFlags[k]) ||
                            flag->shortName().equals(helpFlags[k])) {
                            printFlag = true;
                            helpFlags.remove(k);
                            break;
                        }
                    }
                }
                if (printFlag) {
                    print_help_for_flag(flag);
                }
                flag = flag->next();
            }
            if (helpFlags.count() > 0) {
                SkDebugf("Requested help for unrecognized flags:\n");
                for (int k = 0; k < helpFlags.count(); k++) {
                    SkDebugf("\t--%s\n", helpFlags[k]);
                }
            }
            helpPrinted = true;
        }
        if (!helpPrinted) {
            bool flagMatched = false;
            SkFlagInfo* flag = gHead;
            while (flag != NULL) {
                if (flag->match(argv[i])) {
                    flagMatched = true;
                    switch (flag->getFlagType()) {
                        case SkFlagInfo::kBool_FlagType:
                            // Can be handled by match, above, but can also be set by the next
                            // string.
                            if (i+1 < argc && !SkStrStartsWith(argv[i+1], '-')) {
                                i++;
                                bool value;
                                if (parse_bool_arg(argv[i], &value)) {
                                    flag->setBool(value);
                                }
                            }
                            break;
                        case SkFlagInfo::kString_FlagType:
                            flag->resetStrings();
                            // Add all arguments until another flag is reached.
                            while (i+1 < argc && !SkStrStartsWith(argv[i+1], '-')) {
                                i++;
                                flag->append(argv[i]);
                            }
                            break;
                        case SkFlagInfo::kInt_FlagType:
                            i++;
                            flag->setInt(atoi(argv[i]));
                            break;
                        case SkFlagInfo::kDouble_FlagType:
                            i++;
                            flag->setDouble(atof(argv[i]));
                            break;
                        default:
                            SkDEBUGFAIL("Invalid flag type");
                    }
                    break;
                }
                flag = flag->next();
            }
            if (!flagMatched) {
                SkString stripped(argv[i]);
                while (stripped.startsWith('-')) {
                    stripped.remove(0, 1);
                }
                if (!FLAGS_undefok.contains(stripped.c_str())) {
                    SkDebugf("Got unknown flag \"%s\". Exiting.\n", argv[i]);
                    exit(-1);
                }
            }
        }
    }
    // Since all of the flags have been set, release the memory used by each
    // flag. FLAGS_x can still be used after this.
    SkFlagInfo* flag = gHead;
    gHead = NULL;
    while (flag != NULL) {
        SkFlagInfo* next = flag->next();
        SkDELETE(flag);
        flag = next;
    }
    if (helpPrinted) {
        exit(0);
    }
}