Exemplo n.º 1
0
//Here we update the stats
void updateStats(std::istringstream& iss, stats *GCODE_stats, vector3D *currentLocation) {

	vector3D previousLocation = GCODE_stats->currentLocation;

	GCODE_stats->currentLocation = *currentLocation;
    GCODE_stats->movementLinesCount++;

	std::string s;
	iss >> s;
	if (scanString(s, "F", NULL)) {
		GCODE_stats->currentFeedRate = scanFloat(s, "F");
	}

	float currentExtrudedLength = 0.f;

	iss >> s;
	if (scanString(s, "E", NULL) || scanString(s, "A", NULL)) {

		if (scanString(s, "E", NULL))
			currentExtrudedLength = scanFloat(s, "E");
		else
			currentExtrudedLength = scanFloat(s, "A");

		GCODE_stats->extruding = (currentExtrudedLength > GCODE_stats->currentExtrudedLengthToolA);
		if (GCODE_stats->extruding) {
			//Real life test
			GCODE_stats->currentExtrudedLengthToolA = currentExtrudedLength;
		}
		GCODE_stats->usingToolB = false;
	} else if (scanString(s, "B", NULL)) {
		currentExtrudedLength = scanFloat(s, "B");
		GCODE_stats->extruding = (currentExtrudedLength > GCODE_stats->currentExtrudedLengthToolB);
		if (GCODE_stats->extruding) {
			// Real life test
			GCODE_stats->currentExtrudedLengthToolB = currentExtrudedLength;
		}
		GCODE_stats->usingToolB = true;
	}

	vector3D* travelVector = new vector3D(GCODE_stats->currentLocation.x, GCODE_stats->currentLocation.y, GCODE_stats->currentLocation.z);
	travelVector->minus(previousLocation);
    float longestDistanceToMove = max(fabs(travelVector->x), fabs(travelVector->y)); // mm
	//printf("%f\n", longestDistanceToMove);
	float cartesianDistance = travelVector->getLength();

	// == Calculating time taken to move or extrude ==
    if (GCODE_stats->extruding){
        
        // Extrusion in progress, let's calculate the time taken
        // NSLog(@"Extruding %f  > %f", currentExtrudedLength, previousExtrudedLength);
        GCODE_stats->totalExtrudedDistance += cartesianDistance; // mm
        GCODE_stats->totalExtrudedTime += (longestDistanceToMove / (GCODE_stats->currentFeedRate *  __averageAccelerationEfficiencyWhenExtruding)); // min
    } else {
        
        // We're only travelling, let's calculate the time taken
        // NSLog(@"Travelling");
        GCODE_stats->totalTravelledDistance += cartesianDistance; // mm
        GCODE_stats->totalTravelledTime += (longestDistanceToMove / (GCODE_stats->currentFeedRate * __averageAccelerationEfficiencyWhenTravelling)); // min
    }
}
Exemplo n.º 2
0
/**
 *  Extract a single group record from the database
 */
int _libcsupport_scangr(
  FILE *fp,
  struct group *grp,
  char *buffer,
  size_t bufsize
)
{
  int grgid;
  char *grmem, *cp;
  int memcount;

  if (!scanString(fp, &grp->gr_name, &buffer, &bufsize, 0)
   || !scanString(fp, &grp->gr_passwd, &buffer, &bufsize, 0)
   || !scanInt(fp, &grgid)
   || !scanString(fp, &grmem, &buffer, &bufsize, 1))
    return 0;
  grp->gr_gid = grgid;

  /*
   * Determine number of members
   */
  if (grmem[0] == '\0') {
    memcount = 0;
  } else {
    for (cp = grmem, memcount = 1 ; *cp != 0 ; cp++) {
      if(*cp == ',')
        memcount++;
    }
  }

  /*
   * Hack to produce (hopefully) a suitably-aligned array of pointers
   */
  if (bufsize < (((memcount+1)*sizeof(char *)) + 15))
    return 0;
  grp->gr_mem = (char **)(((uintptr_t)buffer + 15) & ~15);

  /*
   * Fill in pointer array
   */
  if (grmem[0] == '\0') {
    memcount = 0;
  } else {
    grp->gr_mem[0] = grmem;
    for (cp = grmem, memcount = 1 ; *cp != 0 ; cp++) {
      if(*cp == ',') {
        *cp = '\0';
        grp->gr_mem[memcount++] = cp + 1;
      }
    }
  }

  grp->gr_mem[memcount] = NULL;
  return 1;
}
int main (int argc, char **argv) { 
   options opts;
   prog_name = basename (argv[0]);
   int check = 1;
   scan_options(argc, argv, &opts);
   if(opts.print_debug == true) check = 2;
   if(argc == check){
      scanString();
      print_nodes(head, &opts);
   }
   return exit_status;
}
Exemplo n.º 4
0
//Get the location in of the gcode X Y Z
void updateLocation(std::istringstream& iss, vector3D *currentLocation) {
	std::string s;
	float value;

	iss >> s;
	if (scanString(s, "X", NULL)) {
		value = scanFloat(s, "X");
		currentLocation->x = value;
		//printf("%f ", value);
	}
	iss >> s;
	if (scanString(s, "Y", NULL)) {
		value = scanFloat(s, "Y");
		currentLocation->y = value;
		//printf("%f ", value);
	}
	iss >> s;
	if (scanString(s, "Z", NULL)) {
		value = scanFloat(s, "Z");
		currentLocation->z = value;
		//printf("%f ", value);
	}
}
Exemplo n.º 5
0
// assume called when tokenEnd on close quote of name
bool JsonScanner::thisValue(char type) {
    restoreString();
    char *at = skipWhite(tokenEnd + 1);
    if(*at == ':') {
        at = skipWhite(at + 1);
        if(*at == type) {
            if(type == STRING_TYPE) {
                return scanString(at);
            }
            else { // array
                tokenStart = at;
                return true;
            }
        }
    }

    return false;
}
Exemplo n.º 6
0
bool JsonScanner::nextName(char *at) {
    restoreString();
    while(*at) {
        if(*at == '"') {
            if(scanString(at)) { // set tokenStart & tokenEnd
                at = skipWhite(tokenEnd + 1); // after closing quote
                if(*at == ':') {
                    return true;
                }
            }
            else {
                return false; // unterminated string encountered
            }
        }
        else {
            at++;
        }
    }

    return false;
}
Exemplo n.º 7
0
/*
 * Extract a single password record from the database
 */
int _libcsupport_scanpw(
  FILE *fp,
  struct passwd *pwd,
  char *buffer,
  size_t bufsize
)
{
  int pwuid, pwgid;

  if (!scanString(fp, &pwd->pw_name, &buffer, &bufsize, 0)
   || !scanString(fp, &pwd->pw_passwd, &buffer, &bufsize, 0)
   || !scanInt(fp, &pwuid)
   || !scanInt(fp, &pwgid)
   || !scanString(fp, &pwd->pw_comment, &buffer, &bufsize, 0)
   || !scanString(fp, &pwd->pw_gecos, &buffer, &bufsize, 0)
   || !scanString(fp, &pwd->pw_dir, &buffer, &bufsize, 0)
   || !scanString(fp, &pwd->pw_shell, &buffer, &bufsize, 1))
    return 0;
  pwd->pw_uid = pwuid;
  pwd->pw_gid = pwgid;
  return 1;
}
Exemplo n.º 8
0
std::string TokenScanner::nextToken() {
    if (savedTokens) {
        StringCell* cp = savedTokens;
        std::string token = cp->str;
        savedTokens = cp->link;
        delete cp;
        return token;
    }

    while (true) {
        if (ignoreWhitespaceFlag) {
            skipSpaces();
        }
        int ch = isp->get();
        if (ch == '/' && ignoreCommentsFlag) {
            ch = isp->get();
            if (ch == '/') {
                while (true) {
                    ch = isp->get();
                    if (ch == '\n' || ch == '\r' || ch == EOF) {
                        break;
                    }
                }
                continue;
            } else if (ch == '*') {
                int prev = EOF;
                while (true) {
                    ch = isp->get();
                    if (ch == EOF || (prev == '*' && ch == '/')) {
                        break;
                    }
                    prev = ch;
                }
                continue;
            }
            if (ch != EOF) {
                isp->unget();
            }
            ch = '/';
        }
        if (ch == EOF) {
            return "";
        }
        if ((ch == '"' || ch == '\'') && scanStringsFlag) {
            isp->unget();
            return scanString();
        }
        if (isdigit(ch) && scanNumbersFlag) {
            isp->unget();
            return scanNumber();
        }
        if (isWordCharacter(ch)) {
            isp->unget();
            return scanWord();
        }
        std::string op = std::string(1, ch);
        while (isOperatorPrefix(op)) {
            ch = isp->get();
            if (ch == EOF) {
                break;
            }
            op += ch;
        }
        while (op.length() > 1 && !isOperator(op)) {
            isp->unget();
            op.erase(op.length() - 1, 1);
        }
        return op;
    }
}
Exemplo n.º 9
0
/* Advances the parser one token, optionally skipping whitespace
 * (otherwise it is concatenated and returned as a single whitespace token).
 * Whitespace is needed to properly render function signatures. Unrecognized
 * token starts are stored literally, e.g. token may equal to a character '#'. */
static int advanceToken (lexerState *lexer, boolean skip_whitspace)
{
	boolean have_whitespace = FALSE;
	lexer->line = getSourceLineNumber();
	lexer->pos = getInputFilePosition();
	while (lexer->cur_c != EOF)
	{
		if (isWhitespace(lexer->cur_c))
		{
			scanWhitespace(lexer);
			have_whitespace = TRUE;
		}
		else if (lexer->cur_c == '/' && (lexer->next_c == '/' || lexer->next_c == '*'))
		{
			scanComments(lexer);
			have_whitespace = TRUE;
		}
		else
		{
			if (have_whitespace && !skip_whitspace)
				return lexer->cur_token = TOKEN_WHITESPACE;
			break;
		}
	}
	lexer->line = getSourceLineNumber();
	lexer->pos = getInputFilePosition();
	while (lexer->cur_c != EOF)
	{
		if (lexer->cur_c == '"')
		{
			scanString(lexer);
			return lexer->cur_token = TOKEN_STRING;
		}
		else if (lexer->cur_c == 'r' && (lexer->next_c == '#' || lexer->next_c == '"'))
		{
			scanRawString(lexer);
			return lexer->cur_token = TOKEN_STRING;
		}
		else if (lexer->cur_c == '\'')
		{
			scanCharacterOrLifetime(lexer);
			return lexer->cur_token = TOKEN_STRING;
		}
		else if (isIdentifierStart(lexer->cur_c))
		{
			scanIdentifier(lexer);
			return lexer->cur_token = TOKEN_IDENT;
		}
		/* These shift tokens aren't too important for tag-generation per se,
		 * but they confuse the skipUntil code which tracks the <> pairs. */
		else if (lexer->cur_c == '>' && lexer->next_c == '>')
		{
			advanceNChar(lexer, 2);
			return lexer->cur_token = TOKEN_RSHIFT;
		}
		else if (lexer->cur_c == '<' && lexer->next_c == '<')
		{
			advanceNChar(lexer, 2);
			return lexer->cur_token = TOKEN_LSHIFT;
		}
		else if (lexer->cur_c == '-' && lexer->next_c == '>')
		{
			advanceNChar(lexer, 2);
			return lexer->cur_token = TOKEN_RARROW;
		}
		else
		{
			int c = lexer->cur_c;
			advanceChar(lexer);
			return lexer->cur_token = c;
		}
	}
	return lexer->cur_token = TOKEN_EOF;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
void ResourcePool::addPath(const char *dirname, bool recursive)
{/* scan the buffer and recursively enter any directories found */
#ifndef WIN32
	pathList.insert(dirname);
	recList[dirname] = recursive;
	
	char initialpath[RESOURCEPOOL_MAX_PATH];
	
	getcwd(initialpath,RESOURCEPOOL_MAX_PATH);
	
	if (chdir(dirname) != 0)
	{
		Logger::log(LOG_ERROR,"Resource Pool: Unable to locate path: %s\n",dirname);
		return;
	}
	
	dirname = ".";
	
	int size;
	char *entries;
	char name[RESOURCEPOOL_MAX_PATH];
	char Path[RESOURCEPOOL_MAX_PATH];
	char *path;
	char oldpath[RESOURCEPOOL_MAX_PATH];
	char old[RESOURCEPOOL_MAX_PATH];
	
	FILE *filein;
	path=Path;
	size=getSize(dirname);
	entries=(char *)malloc(size);
	scanDir(dirname,entries);
	getcwd(Path,RESOURCEPOOL_MAX_PATH);
	strcpy(old,Path);
	
	while(scanString(name,entries)!=EOF)
	{
		
		/* store the path for use later */
		getcwd(Path,RESOURCEPOOL_MAX_PATH);
		
		if(name[0] != '.')
		{
			
			/* this is where the valid path variable can be found */
			//				if(!strcmp(Path,old))printf("PATH: %s\n",Path);
			strcpy(oldpath,Path);
			
			/* add the next entry to the path for testing */
			strcat(Path,RESOURCEPOOL_PATH_CHAR);
			strcat(Path,name);
			
			/* see if the entry is a file */
			/* here is where the valid filename associated with the path can be found */
			if(chdir(Path)==0)
			{	
				/* if the entry is a valid directory, go there */
				getcwd(path,RESOURCEPOOL_MAX_PATH);
				
				if (recursive)
				{
					/* start the recursive traversal */
					addPath(".",recursive);
				}
				
				/* restore the path */
				strcpy(Path,oldpath);
				chdir(Path);
				getcwd(path,RESOURCEPOOL_MAX_PATH);
			}
			else if((filein=fopen(Path,"r"))!=0)
			{
				//printf("PATH: %s, ",Path);
				//printf("NAME: %s\n",name);
				
				string nameStr = string(name);
				
				fclose(filein);
				
				fileMap[name].push_back(Path);
				
				string::size_type idx = nameStr.find_last_of ( '.' );

				if ( idx == string::npos )
				{
//					printf("No file extension\n");
				}
				else
				{
					string extStr = StringToLower(nameStr.substr(idx+1));
					
					extMap[extStr].push_back(Path);
//					printf("The file extension is %s \n",nameStr.substr(idx+1).c_str());
				}
			}
			
			/* set the sentinel variable for state changes */
			strcpy(old,Path);
			strcpy(Path,oldpath);
			chdir(Path);
			getcwd(path,RESOURCEPOOL_MAX_PATH);
		}
		
		entries=entries+strlen(name)+1;
	}
	
	chdir(initialpath);
	
	return;
#endif
}
Exemplo n.º 12
0
static bool ScanOptionsArg( const char * arg )
/********************************************/
{
    bool        contok;
    ExtraRes    *resfile;
    FRStrings   *frStrings;
    char        *temp=NULL;
    char        *p;
    char        *delims = ",";
    size_t      findlen = 0;
//    size_t      replen = 0;

    contok = true;

    switch( tolower( *arg ) ) {
    case '\0':
        RcError( ERR_NO_OPT_SPECIFIED );
        contok = false;
        break;
    case 'a':
        arg++;
        if( tolower( *arg ) == 'd' ) {
            CmdLineParms.GenAutoDep = TRUE;
        } else if( tolower( *arg ) == 'p' ) {
            arg++;
            if( *arg == '=' ) arg++;
            if( scanString( CmdLineParms.PrependString, arg, _MAX_PATH  ) ) {
                RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
            }
            CmdLineParms.Prepend = TRUE;
            break;
        } else {
            RcError( ERR_UNKNOWN_MULT_OPTION, arg - 1 );
            contok = FALSE;
        }
        break;
    case '3':
        arg++;
        switch( tolower( *arg ) ) {
        case '0':
            CmdLineParms.VersionStamp = VERSION_30_STAMP;
            break;
        case '1':
            CmdLineParms.VersionStamp = VERSION_31_STAMP;
            break;
        default:
            RcError( ERR_UNKNOWN_MULT_OPTION, arg - 1 );
            contok = FALSE;
            break;
        }
        break;
    case 'b':
        arg++;
        if( tolower( *arg ) == 't' ) {
            arg++;
            if( *arg == '=' ) arg++;
            if( stricmp( arg, "windows" ) == 0 || stricmp( arg, "win" ) == 0 ) {
                CmdLineParms.TargetOS = RC_TARGET_OS_WIN16;
            } else if( stricmp( arg, "nt" ) == 0 ) {
                CmdLineParms.TargetOS = RC_TARGET_OS_WIN32;
            } else if( stricmp( arg, "os2" ) == 0 ) {
                CmdLineParms.TargetOS = RC_TARGET_OS_OS2;
            } else {
                RcError( ERR_UNKNOWN_TARGET_OS, arg );
                contok = FALSE;
            }
        } else {
            RcError( ERR_UNKNOWN_MULT_OPTION, arg - 1 );
            contok = FALSE;
        }
        break;
    case 'c':
        arg++;
        if( *arg == '=' ) arg++;
        if( scanString( CmdLineParms.CodePageFile, arg, _MAX_PATH  ) ) {
            RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
        }
        break;
    case 'd':
        /* temporary until preprocessing done inline */
        /* -1 to get the '-' or '/' as well */
        /* the cast is so the argument won't be const */
        RcAddCPPArg( (char *)arg - 1 );
        break;
    case 'f':
        arg++;
        switch( tolower( *arg ) ) {
        case 'o':
            arg++;
            if( *arg == '=' ) arg++;
            if( scanString( CmdLineParms.OutResFileName, arg, _MAX_PATH  ) ) {
                RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
            }
            break;
        case 'r':
            arg++;
            if( *arg == '=' ) arg++;
            resfile = RcMemMalloc( sizeof( ExtraRes ) );
            if( scanString( resfile->name, arg, _MAX_PATH  ) ) {
                RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
                RcMemFree( resfile );
            } else {
                resfile->next = CmdLineParms.ExtraResFiles;
                CmdLineParms.ExtraResFiles = resfile;
            }
            break;
        case 'e':
            arg++;
            if( *arg == '=' ) arg++;
            if( scanString( CmdLineParms.OutExeFileName, arg, _MAX_PATH  ) ) {
                RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
            }
            break;
        default:
            RcError( ERR_UNKNOWN_MULT_OPTION, arg - 1 );
            contok = FALSE;
            break;
        }
        break;
    case 'g':
        arg++;
        if( *arg == '=' ) arg++;
        temp = RcMemMalloc( strlen( arg ) + 1 );
        if( scanString( temp, arg, _MAX_PATH  ) ) {
            RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
        }
        frStrings = RcMemMalloc( sizeof( FRStrings ) + strlen( arg ) + 2 );
        p = strtok( temp, delims );
        if( p != NULL ) {
            findlen = strlen( p );
            strcpy( frStrings->buf, p );
            frStrings->findString = frStrings->buf;
        } else {
            RcError( ERR_SYNTAX_STR, "/g=" );
            contok = FALSE;
        }
        p = strtok( NULL, delims );
        if( p != NULL ) {
//            replen = strlen( p );
            strcpy( &frStrings->buf[findlen+1], p );
            frStrings->replaceString = &frStrings->buf[findlen+1];
        } else {
            RcError( ERR_SYNTAX_STR, frStrings->findString  );
            contok = FALSE;
        }
        frStrings->next = CmdLineParms.FindReplaceStrings;
        CmdLineParms.FindReplaceStrings = frStrings;
        CmdLineParms.FindAndReplace = TRUE;
        RcMemFree( temp );
        break;
    case 'i':
        arg++;
        if( *arg == '=' )
            arg++;
        temp = RcMemMalloc( _MAX_PATH );
        if( scanString( temp, arg, _MAX_PATH  ) ) {
            RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
        }
        PP_AddIncludePath( temp );
        RcMemFree( temp );
        break;
    case 'o':
        CmdLineParms.PreprocessOnly = TRUE;
        break;
    case 's':
        arg++;
        switch( tolower( *arg ) ) {
        case '0':
            CmdLineParms.SegmentSorting = SEG_SORT_NONE;
            break;
        case '1':
            CmdLineParms.SegmentSorting = SEG_SORT_PRELOAD_ONLY;
            break;
        case '2':
            CmdLineParms.SegmentSorting = SEG_SORT_MANY;
            break;
        }
        break;
    case 'w':
        arg++;
        if( *arg == 'r' ) {
//          CmdLineParms.WritableRes = TRUE;
        }
        break;
#if defined(YYDEBUG) || defined(SCANDEBUG)
    case 'v':
        arg++;
        switch( tolower( *arg ) ) {
    #if defined(YYDEBUG)
        case '1':
            CmdLineParms.DebugParser = 1;
            break;
    #endif
    #if defined(YYDEBUG) && defined(SCANDEBUG)
        case '2':
            CmdLineParms.DebugParser = 1;
            CmdLineParms.DebugScanner = 1;
            break;
        case '3':
            CmdLineParms.DebugScanner = 1;
            break;
    #endif
    #if defined(SCANDEBUG)
        default:
            CmdLineParms.DebugScanner = 1;
            break;
    #endif
        }
        break;
#endif
    case 'x':
        arg++;
        if( tolower( *arg ) == 'b' ) {
            CmdLineParms.NoTargetDefine = TRUE;
        } else if( tolower( *arg ) == 'c' ) {
            CmdLineParms.IgnoreCWD = TRUE;
        } else {
            CmdLineParms.IgnoreINCLUDE = TRUE;
        }
        break;
    case 'z':
        arg++;
        switch( tolower( *arg ) ) {
        case 'm':
            CmdLineParms.MSResFormat = TRUE;
            break;
        case 'n':
            CmdLineParms.NoPreprocess = TRUE;
            break;
        /*
            Lead-byte and trail-byte ranges for code pages used in Far East
            editions of Windows 95.

                        Character           Code    Lead-Byte   Trail-Byte
        Language        Set Name            Page    Ranges      Ranges

        Chinese
        (Simplified)    GB 2312-80          CP 936  0xA1-0xFE   0xA1-0xFE

        Chinese
        (Traditional)   Big-5               CP 950  0x81-0xFE   0x40-0x7E
                                                                0xA1-0xFE

        Japanese        Shift-JIS (Japan
                        Industry Standard)  CP 932  0x81-0x9F   0x40-0xFC
                                                    0xE0-0xFC   (except 0x7F)

        Korean
        (Wansung)       KS C-5601-1987      CP 949  0x81-0xFE   0x41-0x5A
                                                                0x61-0x7A
                                                                0x81-0xFE

        Korean
        (Johab)         KS C-5601-1992      CP 1361 0x84-0xD3   0x41-0x7E
                                                    0xD8        0x81-0xFE
                                                    0xD9-0xDE   (Government
                                                    0xE0-0xF9   standard:
                                                                0x31-0x7E
                                                                0x41-0xFE)
        */
        case 'k':
            arg++;
            switch( tolower( *arg ) ) {
            case '1':
                SetMBRange( 0x81, 0xfe, 1 );
                CmdLineParms.MBCharSupport = DB_TRADITIONAL_CHINESE;
                break;
            case '2':
                SetMBRange( 0x81, 0xfe, 1 );
                CmdLineParms.MBCharSupport = DB_WANSUNG_KOREAN;
                break;
            case '3':
                SetMBRange( 0xA1, 0xfe, 1 );
                CmdLineParms.MBCharSupport = DB_SIMPLIFIED_CHINESE;
                break;
            case '0':
            case ' ':
            case '\0':
                SetMBRange( 0x81, 0x9f, 1 );
                SetMBRange( 0xe0, 0xfc, 1 );
                CmdLineParms.MBCharSupport = DB_KANJI;
                break;
            case 'u':
                if( arg[1] == '8' ) {
                    arg++;
                    SetMBRange( 0xc0, 0xdf, 1 );
                    SetMBRange( 0xe0, 0xef, 2 );
                    SetMBRange( 0xf0, 0xf7, 3 );
                    SetMBRange( 0xf8, 0xfb, 4 );
                    SetMBRange( 0xfc, 0xfd, 5 );
                    CmdLineParms.MBCharSupport = MB_UTF8;
                    break;
                }
                // fall down
            default:
                RcError( ERR_UNKNOWN_MULT_OPTION, arg - 2 );
                contok = FALSE;
                break;
            }
            break;
        default:
            RcError( ERR_UNKNOWN_MULT_OPTION, arg - 1 );
            contok = FALSE;
            break;
        }
        break;
    default:            /* option that could have others with it */
        contok = ScanMultiOptArg( arg ) && contok;
        break;
    }
    return( contok );
} /* ScanOptionsArg */
Exemplo n.º 13
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;
}
Exemplo n.º 14
0
static bool ScanOptionsArg( const char * arg )
/********************************************/
{
    bool        contok;
    size_t      len;

    contok = true;

    switch( tolower( *arg ) ) {
    case 'c':
        flags |= PPFLAG_KEEP_COMMENTS;
        break;
    case 'd':
        ++arg;
        defines = realloc( (void *)defines, ( numdefs + 1 ) * sizeof( char * ) );
        defines[numdefs++] = my_strdup( arg );
        break;
    case 'h':
        wcpp_quit( usageMsg, NULL );
        break;
    case 'i':
        {
            char    *p;

            ++arg;
            len = strlen( arg );
            p = malloc( len + 1 );
            scanString( p, arg, len );
            PP_IncludePathAdd( p );
            free( p );
        }
        break;
    case 'l':
        flags |= PPFLAG_EMIT_LINE;
        break;
    case 'o':
        ++arg;
        if( out_filename != NULL ) {
            free( out_filename );
        }
        len = strlen( arg );
        out_filename = malloc( len + 1 );
        scanString( out_filename, arg, len );
        break;
    case 'z':
        ++arg;
        if( tolower( arg[0] ) == 'k' ) {
            if( arg[1] == '0' && arg[2] == '\0' ) {
                flags |= PPFLAG_DB_KANJI;
                break;
            } else if( arg[1] == '1' && arg[2] == '\0' ) {
                flags |= PPFLAG_DB_CHINESE;
                break;
            } else if( arg[1] == '2' && arg[2] == '\0' ) {
                flags |= PPFLAG_DB_KOREAN;
                break;
            } else if( tolower( arg[1] ) == 'u' ) {
                if( arg[2] == '8' && arg[3] == '\0' ) {
                    flags |= PPFLAG_UTF8;
                    break;
                }
            }
        }
        // fall down
    default:
        wcpp_quit( usageMsg, "Incorrect option\n" );
        break;
    }
    return( contok );
} /* ScanOptionsArg */
Exemplo n.º 15
0
int main()
{
    char cmd_line[82];          // - command line
    char const * cmd;           // - scanner
    char code;                  // - current code
    IDEBool fatal_error;        // - fatality indicator
    IDEBool retn;               // - return code

    retn = OK;
    fatal_error = 0;
    _Verify( IDE_CUR_DLL_VER == IDEGetVersion(), "invalid DLL version" );
    IDEInitDLL( FAKE_HDL, &callbacks, &dll_info );
    puts( "\n" );
    for( ; ; ) {
        ConsoleReadPrefixed( cmd_line, sizeof( cmd_line ), "FAKEIDE>" );
        cmd = scanBlanks( cmd_line );
        code = *cmd;
        cmd = scanBlanks( cmd + 1 );
        switch( code ) {
          case '\0' :
            continue;
          case 'q' :
            break;
          case 's' :
            scanString( cmd, source_file );
            continue;
          case 't' :
            scanString( cmd, target_file );
            continue;
          case 'o' :
            scanString( cmd, options );
            continue;
          case 'c' :
            retn = IDERunYourSelf( FAKE_HDL, options, &fatal_error );
            continue;
          case 'r' :
            loadOptions();
            continue;
          case 'w' :
            saveOptions();
            continue;
          case '?' :
            puts( "" );
            fputs( "OPTIONS: " , stdout ); puts( options );
            fputs( "SOURCE:  " , stdout ); puts( source_file );
            fputs( "TARGET:  " , stdout ); puts( target_file );
            fputs( "RETURN:  " , stdout ); puts( fmtBool( retn ) );
            fputs( "FATAL:   " , stdout ); puts( fmtBool( fatal_error ) );
            dumpOptions();
            puts( "" );
            puts( "Enter 'h' for help" );
            puts( "" );
            continue;
          case 'h' :
            puts( "" );
            puts( "o options      [ set compiler options]" );
            puts( "s source file  [ set source file]" );
            puts( "t target file  [ set target file]" );
            puts( "c              [ do a compile]" );
            puts( "w              [ write current options ]" );
            puts( "r              [ read written options ]" );
            puts( "" );
            puts( "?              [ dump IDE data ]" );
            puts( "q              [ quit ]" );
            puts( "h              [ display this message ]" );
            puts( "" );
            continue;
          default :
            _Msg( "undecipherable crap entered" );
            continue;
        }
        break;
    }
    IDEFiniDLL( FAKE_HDL );
    return 0;
}
Exemplo n.º 16
0
int main( ) {
	FILE* inFile = fopen(	"file.in", "r" );
	if ( inFile == NULL ) {
		printf( "Error opening input file" );
		return 1;
	}
	int emmissionsNumber;
	scanDecimal( inFile, &emmissionsNumber );

	TVNodeType TVNodeListHead = NULL;
	int i;

	//Iterate for each emmission
	for( i = 0; i < emmissionsNumber; i++ ) {

		//Create the current emmission
		EmmissionType *emmission = ( EmmissionType* ) malloc( sizeof( EmmissionType ) );
		emmission->title = ( char* ) malloc( MAX_STRING_LENGTH * sizeof( char ));
		emmission->description = ( char* ) malloc( MAX_STRING_LENGTH * sizeof( char ));
		emmission->tvProducer = ( char* ) malloc( MAX_STRING_LENGTH * sizeof( char ));

		//Read emmission details
		scanDecimal( inFile, &( emmission->idNumber ) );
		scanString( inFile, emmission->title	 );
		scanString( inFile, emmission->description );
		scanString( inFile, emmission->tvProducer );
		scanDateTime( inFile, &( emmission->startTime ) );
		scanDateTime( inFile, &( emmission->endTime ) );

		int eventsNumber;
		scanDecimal( inFile, &eventsNumber );
		EventType eventListHead = NULL;
		EventType eventListTail = NULL;

		//Iterate for each event
		int j;
		for ( j = 0; j < eventsNumber; j++ ) {

			EventType currentEvent = ( EventType ) malloc( sizeof( struct Event ) );
			currentEvent->eventTitle = ( char* ) malloc( MAX_STRING_LENGTH * sizeof( char ));
			currentEvent->organizer = ( char* ) malloc( MAX_STRING_LENGTH * sizeof( char ));
			currentEvent->eventPlace = ( char* ) malloc( MAX_STRING_LENGTH * sizeof( char ));

			//Read event details
			scanString( inFile, currentEvent->eventTitle );
			scanString( inFile, currentEvent->organizer );
			scanDateTime( inFile, &( currentEvent->dt ) );
			scanString( inFile, currentEvent->eventPlace );
			scanDecimal( inFile, &( currentEvent->official ) );

			//Read sport details
			SportType *currentSport = ( SportType* ) malloc( sizeof( SportType ) );
			currentSport->name = ( char* ) malloc( MAX_STRING_LENGTH * sizeof( char ));
			currentSport->participant1 = ( char* ) malloc( MAX_STRING_LENGTH * sizeof( char ));
			currentSport->participant2 = ( char* ) malloc( MAX_STRING_LENGTH * sizeof( char ));
			scanString( inFile, currentSport->name );
			scanDecimal( inFile, &( currentSport->classical ) );
			scanDecimal( inFile, &( currentSport->individual ) );
			scanString( inFile, currentSport->participant1 );
			scanString( inFile, currentSport->participant2 );

			//Link the sport with the corresponding event
			currentEvent->sport = currentSport;
			addEventToList( &eventListHead, &eventListTail, currentEvent );

		}
		emmission->subjects = eventListHead;
		TVNodeType currentTVNode = ( TVNodeType ) malloc( sizeof( struct TVNodeStruct ) );
		currentTVNode->anEmmission = emmission;
		addTVNodeToList( &( TVNodeListHead ), currentTVNode );
	}

	TVNodeType resultListHead = NULL;
	printf( "Enter subject - keyword: ");
	char answer[ 100 ];
	scanf( "%s", answer );
	findEmmissionsByKwd( TVNodeListHead, &resultListHead, answer );
	printEmmissionsList( resultListHead );

	return 0;
}
Exemplo n.º 17
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") {