示例#1
0
    bool Scanner::scanToken (Parser& parser)
    {
        switch (mPutback)
        {
            case Putback_Special:

                mPutback = Putback_None;
                return parser.parseSpecial (mPutbackCode, mPutbackLoc, *this);

            case Putback_Integer:

                mPutback = Putback_None;
                return parser.parseInt (mPutbackInteger, mPutbackLoc, *this);

            case Putback_Float:

                mPutback = Putback_None;
                return parser.parseFloat (mPutbackFloat, mPutbackLoc, *this);

            case Putback_Name:

                mPutback = Putback_None;
                return parser.parseName (mPutbackName, mPutbackLoc, *this);

            case Putback_Keyword:

                mPutback = Putback_None;
                return parser.parseKeyword (mPutbackCode, mPutbackLoc, *this);

            case Putback_None:

                break;
        }

        char c;

        if (!get (c))
        {
            parser.parseEOF (*this);
            return false;
        }
        else if (c==';')
        {
            while (get (c))
            {
                if (c=='\n')
                {
                    putback (c);
                    break;
                }
            }

            mLoc.mLiteral.clear();

            return true;
        }
        else if (isWhitespace (c))
        {
            mLoc.mLiteral.clear();
            return true;
        }
        else if (std::isdigit (c))
        {
            bool cont = false;

            if (scanInt (c, parser, cont))
            {
                mLoc.mLiteral.clear();
                return cont;
            }
        }
        else if (std::isalpha (c) || c=='_' || c=='"')
        {
            bool cont = false;

            if (scanName (c, parser, cont))
            {
                mLoc.mLiteral.clear();
                return cont;
            }
        }
        else if (c==13) // linux compatibility hack
        {
            return true;
        }
        else
        {
            bool cont = false;

            if (scanSpecial (c, parser, cont))
            {
                mLoc.mLiteral.clear();
                return cont;
            }
        }

        TokenLoc loc (mLoc);
        mLoc.mLiteral.clear();

        mErrorHandler.error ("syntax error", loc);
        throw SourceException();
    }
示例#2
0
extern "C" int simple_sscanf(const char* input, const char* format, ...) {
	va_list ap;
	int result = 0;
	const char* next = input;

	va_start(ap, format);

	while (*format) {
		if (*format == '%') {
			format++;
			int max = 0;
			while (isdigit(*format)) {
				max = (max * 10) + (*format - '0');
				format++;
			}

			bool err = false;
			switch (*format++) {
			case 'c':
				err = scanChar(&next, &ap);
				break;
			case 'd':
			case 'u':
				err = scanInt(&next, &ap, max);
				break;
			case 'x':
				err = scanHex(&next, &ap);
				break;
			case 's':
				err = scanString(&next, &ap);
				break;
			case '[':
				// assume %[^c]
				if ('^' != *format) {
					err = true;
				}	else {
					format++;
					if (*format && *(format+1) == ']') {
						err = scanStringUntil(&next, &ap, *format);
						format += 2;
					}	else {
						err = true;
					}
				}
				break;
			default:
				err = true;
				break;
			}

			if (err) {
				break;
			}	else {
				result++;
			}
		}	else if (*format++ != *next++) {
			// match input
			break;
		}
	}
	 
	va_end(ap);
	return result;
}
示例#3
0
int main(int argc, char *argv[])
{

	char mdesc[2][MAXLEN] = {"#Motordescription (text)",""};
	char pdesc[2][MAXLEN] = {"#Propellerdescription (text)",""};
	char psdesc[2][MAXLEN] = {"#size [in] (eg. 8x4)",""};
	char wbdesc[2][MAXLEN] = {"#weight battery [kg]",""};
	char wrvdesc[2][MAXLEN] = {"#weight receiver + voltmeter [kg]",""};
	char wmspdesc[2][MAXLEN] = {"#weight motor + speedcontroller + propeller [kg]",""};
	char wcdesc[2][MAXLEN] = {"#weight camera [kg]",""};
	char wfdesc[2][MAXLEN] = {"#weight fuselage (center piece) [kg]",""};
	char wadesc[2][MAXLEN] = {"#weight arms [kg]",""};
	char wtdesc[2][MAXLEN] = {"#weight tilt mechanism + servo [kg]",""};
	char again[MAXLEN];
	double bsize;
	double I;
	double m[7];
	double mges;
	int n;
	int nmax;

	if (argc < 2) {
		fprintf(stderr, "Fehlender Dateiname! Aufruf des Programms:\ncopter.exe data.txt\n");
		exit(1);
	}


	readFile(argv[1], mdesc[0], mdesc[1]);

	readFile(argv[1], pdesc[0], pdesc[1]);

	readFile(argv[1], psdesc[0], psdesc[1]);

	readFile(argv[1], wbdesc[0], wbdesc[1]);
	m[0] = readValue(wbdesc[1]);

	readFile(argv[1], wrvdesc[0], wrvdesc[1]);
	m[1] = readValue(wrvdesc[1]);

	readFile(argv[1], wmspdesc[0], wmspdesc[1]);
	m[2] = readValue(wmspdesc[1]);

	readFile(argv[1], wcdesc[0], wcdesc[1]);
	m[3] = readValue(wcdesc[1]);

	readFile(argv[1], wfdesc[0], wfdesc[1]);
	m[4] = readValue(wfdesc[1]);

	readFile(argv[1], wadesc[0], wadesc[1]);
	m[5] = readValue(wadesc[1]);

	readFile(argv[1], wtdesc[0], wtdesc[1]);
	m[6] = readValue(wtdesc[1]);


	while(1) {
		nmax = scanInt("\nMaximale Motorenanzahl: ");
		bsize = scanDouble("Akkukapazitaet [mAh]:");
		printf("\n");		
			printf("Anzahl | I(ges) | m(ges) | Schwebeflugdauer\n");			
			printf("-------------------------------------------\n");
		for ( n = 1; n <= nmax; n++ ) {
			if ( (n % 2) != 0) {

				mges = m[0] + m[1] + n * (m[2] + m[5]) + m[3] + m[4] + 1 * m[6];
			}
			else {

				mges = m[0] + m[1] + n * (m[2] + m[5]) + m[3] + m[4] + 0 * m[6];
			}	

			I = copter_funktion(1,argv[1], mges/n);

			printf("%6d |%6.1lfA |%6.0lfg |\t%5.1lfmin\n", n, I*n,  mges*1000, ((0.8 * (bsize / 1000)) / (I*n) ) * 60 );			
		};

		scanString("\nNochmal? (j/n) : ", again, MAXLEN);
		if (strcasecmp(again, "n") == 0)
			exit(1);
	}

	return 0;
}
示例#4
0
//Here we parse the gocde
void parseGCode(HWND hWnd, HINSTANCE g_hInst, char *filePath) {

    std::string line;

	std::ifstream gcodeFile;
	gcodeFile.open(filePath);

	//Get number of lines in the file
	//int numLines = std::count(std::istreambuf_iterator<char>(gcodeFile), 
	//						  std::istreambuf_iterator<char>(), '\n');
	//wchar_t szMessage[300];
	//StringCchPrintf(szMessage, ARRAYSIZE(szMessage), L"%d lines", numLines);
	//MessageBox(hWnd, szMessage, L"Error", MB_OK);

	//Reset cursor file position
	//gcodeFile.seekg(0, ios::beg);

	CSplash splash1(TEXT(""), RGB(128, 128, 128), g_hInst);
	splash1.ShowSplash();

	if (hWnd) {
		if (gcodeFile.is_open()) {
			//MessageBox(hWnd, L"File Opened !", L"Error", MB_OK);
		}
	} else {
		printf("File Opened\n");
	}

	printf("Parsing GCode File\n");

	initStatistics();

	vector3D cornerLow(0.f, 0.f, 0.f);
	vector3D cornerHigh(0.f, 0.f, 0.f);
	float extrusionWidth = 0.f;

	vector3D currentLocation(0.f,0.f,0.f);
    vector3D highCorner(-FLT_MAX,-FLT_MAX,-FLT_MAX);
    vector3D lowCorner(FLT_MAX,FLT_MAX,FLT_MAX);

    while (getline(gcodeFile, line))
    {

        float oldZ = currentLocation.z;

		//std::istringstream *iss = new std::istringstream(line.c_str());
		std::istringstream iss(line.c_str());

        // Is this a new Layer ?
        if (isNewLayer(iss, &currentLocation)) {
            statistics.layersCount++;
            
            // If height has not been found yet
            if (statistics.layerHeight == 0.0){
                
                float theoreticalHeight = floor((currentLocation.z - oldZ)*100)/100;
                
                if (theoreticalHeight > 0 && theoreticalHeight < 1){ // We assume that a layer is less than 1mm thick
                    statistics.layerHeight = theoreticalHeight;
                }
            }
        } else {
			iss = std::istringstream(line.c_str());
		}

		std::string s;
		iss >> s;
		std::string command;
		bool commandFound = scanCharactersFromSet(s, "GMT0123456789", command);


		if (!commandFound) {
            continue;
        }

		if(command == "M104" || command == "M109" || command == "G10") {
			//printf("M104 M109 G10\n");
			// M104: Set Extruder Temperature
            // Set the temperature of the current extruder and return control to the host immediately
            // (i.e. before that temperature has been reached by the extruder). See also M109 that does the same but waits.
            // /!\ This is deprecated because temperatures should be set using the G10 and T commands.
                
            // G10
            // Example: G10 P3 X17.8 Y-19.3 Z0.0 R140 S205
            // This sets the offset for extrude head 3 (from the P3) to the X and Y values specified.
            // The R value is the standby temperature in oC that will be used for the tool, and the S value is its operating temperature.

            // Makerware puts the temperature first, skip it
			iss >> s;
			if (scanString(s, "S", NULL)) {
                scanInt(s, "S");
            }
			// Extract the tool index
			iss >> s;
            if (scanString(s, "P", NULL) || scanString(s, "T", NULL)) {
                int toolIndex;
				if (scanString(s, "P", NULL))
					toolIndex = scanInt(s, "P");
				else
					toolIndex = scanInt(s, "T");
                    
                bool previouslyUsingToolB = statistics.usingToolB;
                statistics.usingToolB = (toolIndex >= 1);
                    
                if (statistics.usingToolB == !previouslyUsingToolB) {
                    statistics.dualExtrusion = true;
                }
            }
		} else if(command == "G1") {