Esempio n. 1
0
static void parseComment(tBuffer *buf)
{
	char *p;
	bool match = false;

	if (buf->commentStart != NULL)
	{
		p = skipPunct(buf->commentStart,buf->ptr);
		
		/* look for todos */
		if (strncasecmp(p,"todo",4) == 0)
		{
			match = true;
			p += 4;
		}
		else if (strncasecmp(p,"fixme",5) == 0)
		{
			match = true;
			p += 5;
		}
		else if (strncasecmp(p,"fix-me",6) == 0)
		{
			match = true;
			p += 6;
		}

		if (match)
		{
			addString(&(buf->todos),
				skipPunct(p, buf->ptr),
				trimComment(buf->ptr, p));
		}
		else 
		{ /* look for notes */
			if (strncasecmp(p,"note",4) == 0)
			{
				match = true;
				p += 4;
			}
			else if (strncasecmp(p,"nb",2) == 0)
			{
				match = true;
				p += 2;
			}
			if (match)
			{
				addString(&(buf->notes),
					skipPunct(p, buf->ptr),
					trimComment(buf->ptr, p));
			}
		}

		
		buf->commentStart = NULL;
	}
}
Esempio n. 2
0
void delayCmd(char *cmd){
  char *arg;
  int i;
  if(cmd[0] == ';'){
    arg = trim(&(cmd[8]));
  }else{
    arg = trim(&(cmd[7]));
  }
  trimComment(arg);
  i = atoi(arg);
  printf("Delay %d\n", i);
  usleep(i * 1000);
}
Esempio n. 3
0
void sliceCmd(SliceMngr *sm, char *base, char *cmd){
  char *arg;
  char pngname[255];
  int i;
  arg = trim(&(cmd[8]));
  trimComment(arg);
  if(strcmp("Blank", arg) == 0){
    sm->blankScreen();
    printf("Blank Screen\n");
    return;
  }
  i = atoi(arg);
  sprintf(pngname, "%s%04d.png", base,i);
  printf("%s\n", pngname);
  sm->loadSlice(pngname);
  sm->sliceScreen();
}
Esempio n. 4
0
/**
	@internal

	@brief Process an existing file comment.
	
	If the file starts with a comment, this routine is
	called to process and output it. Mostly it just strips
	any extraneous punctuation (like rows of astrisks),
	injects the boilerplate, and wraps it with the right
	markers to make it a Doxygen comment block.

	@param[in,out] 	buf 	the tBuffer to process
*/
static void processFileComment(tBuffer *buf)
{
	char *s, *e;

	/* trim off any punctuation and whitespace */
	s = buf->data;
	e = buf->ptr;
	s = skipComment(s,e);
	e = trimComment(e,s);

	/* emit the original comment */
	fprintf(buf->file, "/**\n\t");
	dumpBlock(buf, s, e);
	fprintf(buf->file, "\n");

	/* emit boilerplate, if any */
	processBoilerplate(buf);

	fprintf(buf->file, "\n*/\n");
}
Esempio n. 5
0
/**
	@internal

	@brief Processes the function's original comment (if any)
	
	This function just trims the original comment, or
	generates a placeholder if there wasn't one.
	
	@note	If you have an pre-existing comment formatting
			convention and want	to automatically convert it,
			this is the place to do it.

	@param[in,out] 	buf 	the tBuffer to process
*/
static void processDescription(tBuffer *buf)
{
	char *s, *e;

	if (buf->description.count > 0)
	{
		/* trim off any punctuation and whitespace */
		s = buf->description.start;
		e = buf->description.end;
		s = skipComment(s,e);
		e = trimComment(e,s);

		if ( s == e)
		{
			 /* there's nothing left after trimming, thus
				it's an empty comment! so we change our
				mind, and generate a placeholder after all */
			buf->description.count = 0;
		}
		else
		{
			/*>>>
				detect and convert any pre-existing
				comment	formatting convention here
			<<<*/
				
			/* emit the original comment */
			dumpBlock(buf, s, e);
		}
	}
	if (buf->description.count == 0)
	{
		/* inject a placeholder */
		fprintf(buf->file, "Brief description needed.");
		fprintf(buf->file, "\n\n\tFollowed by a more complete description.");
	}
	fprintf(buf->file, "\n");
}
Esempio n. 6
0
bool CharacterSurface_load(CharacterSurface * cs, char * file)
{
	FILE * configFile   = NULL;
	char * buffer       = calloc(sizeof(char) * 255, sizeof(char));
	char * orig_buffer  = buffer;
	int    lineLen      = 0;
	char * charFilename = NULL;

	char        * currentAssetImage = NULL;
	SDL_Surface * assetImageSurface = NULL;

	char * key  = NULL;
	char * val  = NULL;
	char * posX = NULL;
	char * posY = NULL;

	SDL_Rect blitRect;

	bool inOptions = false;

	if(cs == NULL) return false;

	charFilename = calloc(sizeof(char) * (strlen(file)  + CHARACTER_DIR_LEN + 1), sizeof(char));
	sprintf(charFilename, "%s/%s", CHARACTER_DIR, file);
	configFile = fopen(charFilename, "r");
	if(configFile == NULL)
	{
		fprintf(stderr, "Unable to open %s : ", file);
		perror(NULL);
		free(charFilename);
		return false;
	}
	else
	{
		while(fgets(buffer, 255, configFile) != NULL)
		{
			trim(&buffer);

			if(buffer[0] != '#' && buffer[0] != '\0')
			{
				trimComment(&buffer);
				lineLen = strlen(buffer);

				if(buffer[0] == '[' && buffer[lineLen - 1] == ']')
				{
					// Extract zone name
					buffer[lineLen - 1] = '\0';
					buffer = buffer + 1;

					if(strcmp(buffer, "options") == 0)
					{
						inOptions = true;
					}
					else
					{
						inOptions = false;
						if(cs->size.h == 0 || cs->size.w == 0)
						{
							fprintf(stderr, "Error: parsing character '%s' : start tiles without set tile size.\n", file);
							return false;
						}

						blitRect.h = cs->size.h;
						blitRect.w = cs->size.w;

						if(currentAssetImage != NULL)
							free(currentAssetImage);

						currentAssetImage = calloc(sizeof(char) * (lineLen + CHARACTER_DIR_LEN + 1), sizeof(char));
						sprintf(currentAssetImage, "%s/%s", CHARACTER_DIR, buffer);

						if(assetImageSurface != NULL)
							SDL_FreeSurface(assetImageSurface);

						assetImageSurface = IMG_Load(currentAssetImage);
						if(assetImageSurface == NULL)
						{
							fprintf(stderr, "Error: parsing character '%s' : can't load file %s ; %s\n", file, currentAssetImage, IMG_GetError());
							return false;
						}

						SDL_SetColorKey(assetImageSurface, SDL_TRUE, SDL_MapRGB(assetImageSurface->format, 0, 0, 0));
					}
				}
				else if(inOptions)
				{
					key = buffer;
					val = cut(key, '=');
					trim(&key);
					trim(&val);

					     if(strcmp(key, "height") == 0) cs->size.h = atoi(val);
					else if(strcmp(key, "width")  == 0) cs->size.w = atoi(val);
					else fprintf(stderr, "Warning: parsing character '%s' : unknow option '%s = %s'\n", file, key, val);
				}
				else
				{
					key = buffer;
					val = cut(key, '=');
					trim(&key);
					trim(&val);

					// Extract position
					posX = val;
					posY = cut(val, ',');
					trim(&posX);
					trim(&posY);

					blitRect.x = atoi(posX);
					blitRect.y = atoi(posY);

					/*
					 * Right assets
					 */
					if(strcmp(key, "right.default") == 0)
					{
						cs->def_r = SDL_CreateRGBSurface(0, cs->size.w, cs->size.h, 32, RMASK, GMASK, BMASK, AMASK);
						SDL_BlitSurface(assetImageSurface, &blitRect, cs->def_r, NULL);
					}
					else if(strcmp(key, "right.jump") == 0)
					{
						cs->jump_r = SDL_CreateRGBSurface(0, cs->size.w, cs->size.h, 32, RMASK, GMASK, BMASK, AMASK);
						SDL_BlitSurface(assetImageSurface, &blitRect, cs->jump_r, NULL);
					}
					else if(strcmp(key, "right.walk") == 0)
					{
						cs->walk_r = SDL_CreateRGBSurface(0, cs->size.w, cs->size.h, 32, RMASK, GMASK, BMASK, AMASK);
						SDL_BlitSurface(assetImageSurface, &blitRect, cs->walk_r, NULL);
					}
					else if(strcmp(key, "right.slide") == 0)
					{
						cs->slide_r = SDL_CreateRGBSurface(0, cs->size.w, cs->size.h, 32, RMASK, GMASK, BMASK, AMASK);
						SDL_BlitSurface(assetImageSurface, &blitRect, cs->slide_r, NULL);
					}
					else if(strcmp(key, "right.crawl1") == 0)
					{
						cs->crawl1_r = SDL_CreateRGBSurface(0, cs->size.w, cs->size.h, 32, RMASK, GMASK, BMASK, AMASK);
						SDL_BlitSurface(assetImageSurface, &blitRect, cs->crawl1_r, NULL);
					}
					else if(strcmp(key, "right.crawl2") == 0)
					{
						cs->crawl2_r = SDL_CreateRGBSurface(0, cs->size.w, cs->size.h, 32, RMASK, GMASK, BMASK, AMASK);
						SDL_BlitSurface(assetImageSurface, &blitRect, cs->crawl2_r, NULL);
					}
					/*
					 * Left assets
					 */
					else if(strcmp(key, "left.default") == 0)
					{
						cs->def_l = SDL_CreateRGBSurface(0, cs->size.w, cs->size.h, 32, RMASK, GMASK, BMASK, AMASK);
						SDL_BlitSurface(assetImageSurface, &blitRect, cs->def_l, NULL);
					}
					else if(strcmp(key, "left.jump") == 0)
					{
						cs->jump_l = SDL_CreateRGBSurface(0, cs->size.w, cs->size.h, 32, RMASK, GMASK, BMASK, AMASK);
						SDL_BlitSurface(assetImageSurface, &blitRect, cs->jump_l, NULL);
					}
					else if(strcmp(key, "left.walk") == 0)
					{
						cs->walk_l = SDL_CreateRGBSurface(0, cs->size.w, cs->size.h, 32, RMASK, GMASK, BMASK, AMASK);
						SDL_BlitSurface(assetImageSurface, &blitRect, cs->walk_l, NULL);
					}
					else if(strcmp(key, "left.slide") == 0)
					{
						cs->slide_l = SDL_CreateRGBSurface(0, cs->size.w, cs->size.h, 32, RMASK, GMASK, BMASK, AMASK);
						SDL_BlitSurface(assetImageSurface, &blitRect, cs->slide_l, NULL);
					}
					else if(strcmp(key, "left.crawl1") == 0)
					{
						cs->crawl1_l = SDL_CreateRGBSurface(0, cs->size.w, cs->size.h, 32, RMASK, GMASK, BMASK, AMASK);
						SDL_BlitSurface(assetImageSurface, &blitRect, cs->crawl1_l, NULL);
					}
					else if(strcmp(key, "left.crawl2") == 0)
					{
						cs->crawl2_l = SDL_CreateRGBSurface(0, cs->size.w, cs->size.h, 32, RMASK, GMASK, BMASK, AMASK);
						SDL_BlitSurface(assetImageSurface, &blitRect, cs->crawl2_l, NULL);
					}
					else fprintf(stderr, "Warning: parsing character '%s' : unknow state '%s'\n", file, key);
				}
			}
		}
	}

	if(cs->def_r    == NULL) fprintf(stderr, "Warning: character '%s', no right.default surface loaded\n", file);
	if(cs->jump_r   == NULL) fprintf(stderr, "Warning: character '%s', no right.jump surface loaded\n", file);
	if(cs->walk_r   == NULL) fprintf(stderr, "Warning: character '%s', no right.walk surface loaded\n", file);
	if(cs->slide_r  == NULL) fprintf(stderr, "Warning: character '%s', no right.slide surface loaded\n", file);
	if(cs->crawl1_r == NULL) fprintf(stderr, "Warning: character '%s', no right.crawl1 surface loaded\n", file);
	if(cs->crawl2_r == NULL) fprintf(stderr, "Warning: character '%s', no right.crawl2 surface loaded\n", file);

	if(cs->def_l    == NULL) fprintf(stderr, "Warning: character '%s', no left.default surface loaded\n", file);
	if(cs->jump_l   == NULL) fprintf(stderr, "Warning: character '%s', no left.jump surface loaded\n", file);
	if(cs->walk_l   == NULL) fprintf(stderr, "Warning: character '%s', no left.walk surface loaded\n", file);
	if(cs->slide_l  == NULL) fprintf(stderr, "Warning: character '%s', no left.slide surface loaded\n", file);
	if(cs->crawl1_l == NULL) fprintf(stderr, "Warning: character '%s', no left.crawl1 surface loaded\n", file);
	if(cs->crawl2_l == NULL) fprintf(stderr, "Warning: character '%s', no left.crawl2 surface loaded\n", file);

	cs->loaded = true;

	if(assetImageSurface != NULL)
		SDL_FreeSurface(assetImageSurface);

	if(currentAssetImage != NULL)
		free(currentAssetImage);

	free(charFilename);
	free(orig_buffer);
	fclose(configFile);
	return true;
}
Esempio n. 7
0
int main(int argc, char **argv){
  FILE *fp;
  int mt;
  char cmd[255];
  char base[255];
  char wrcmd[255];
  char *tmp;
  lcd *l;
  dirmngr *dm;
  dentry slfile;
  struct termios orig;
  struct termios raw;
  SliceMngr *sm;
  l = new lcd(1);
  dm = new dirmngr();
  slfile = lrc_menu(l,dm);

  if(slfile.valid == 1){
    l->setColor(2);
    printf("gcode: %s\n", slfile.path);
  }else{
    exit(1);
  }
  strcpy(slfile.path, "/models/huntress_final.slice/huntress_final.gcode");
  strcpybase(base,slfile.path, '.');
  fp = fopen(slfile.path, "r");

  mt = open(argv[1], O_RDWR);
  if(!isatty(mt)){
    printf("not a tty\n");
    return -1;
  }
  if(tcgetattr(mt, &orig) < 0){
    printf("Could not get attr\n");
    return -1;
  }
  raw = orig;
  raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);

  /* output modes - clear giving: no post processing such as NL to CR+NL */
  raw.c_oflag &= ~(OPOST);

  /* control modes - set 8 bit chars */
  raw.c_cflag |= (CS8);

  /* local modes - clear giving: echoing off, canonical off (no erase with      
     backspace, ^U,...),  no extended functions, no signal chars (^Z,^C) */
  raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);

  /* control chars - set return condition: min number of bytes and timer */
  raw.c_cc[VMIN] = 5; raw.c_cc[VTIME] = 8; /* after 5 bytes or .8 seconds       
                                              after first byte seen      */
  raw.c_cc[VMIN] = 0; raw.c_cc[VTIME] = 0; /* immediate - anything       */
  raw.c_cc[VMIN] = 2; raw.c_cc[VTIME] = 0; /* after two bytes, no timer  */
  raw.c_cc[VMIN] = 0; raw.c_cc[VTIME] = 8; /* after a byte or .8 seconds */

  cfsetspeed(&raw, B9600);
  if(tcsetattr(mt, TCSAFLUSH, &raw) < 0){
    printf("Could not set speed\n");
    return -1;
  }

  sm = new SliceMngr();
  while(fgets(cmd, 255, fp) != NULL){
    //trimComment(cmd);
    tmp = trim(cmd);
    switch(process(tmp)){
    case 0:
      if( trimComment(tmp) != 0){      
	tmp = trim(tmp);
	sprintf(wrcmd, "%s\r\n", tmp);
	if(write(mt, wrcmd, strlen(wrcmd))!=strlen(wrcmd)){
	  printf("write did not complete\n");
	}
	printf("Motor cmd: #%s#, %d\n", tmp, strlen(tmp));
      }
      break;
    case 1:
      sliceCmd(sm, base, tmp);
      break;
    case 2:
      delayCmd(tmp);
      break;
    }
  }
  tcsetattr(mt, TCSAFLUSH, &orig);
  close(mt);
  delete sm;
  fclose(fp);
}
Esempio n. 8
0
void LatexLexer::styleText(int start,int end)
{
    // Ajouter support verbatim
    // Colorier les erreurs de syntaxe
    if (!editor())
        return;

    char *lineChars = new char[end - start+1];
    editor()->SendScintilla(QsciScintilla::SCI_GETTEXTRANGE, start, end, lineChars);
    QString source = QString(lineChars);
    free(lineChars);

    startStyling(start,0xFF);
    QStringList list=source.split('\n');
    int lineIndex=editor()->SendScintilla(QsciScintilla::SCI_LINEFROMPOSITION, start);

    int style=Default,nextStyle=Default;
    if(lineIndex>0){
        int pos = editor()->SendScintilla(QsciScintilla::SCI_GETLINEENDPOSITION, lineIndex-1 );
        if(pos>0){
            int s = editor()->SendScintilla(QsciScintilla::SCI_GETSTYLEAT, pos);
            if(s==MathInline || s==MathDisplay || s==Environment){
                style=s;
                nextStyle=s;
            }
        }
    }

    int level=QsciScintilla::SC_FOLDLEVELBASE;
    if(lineIndex>0){
        QString previousLine = getLine(lineIndex-1);
        level=(editor()->SendScintilla(QsciScintilla::SCI_GETFOLDLEVEL,lineIndex-1)&QsciScintilla::SC_FOLDLEVELNUMBERMASK)+getDiffLevel(previousLine);
    }

    int nbCharsToStyle;
    int styleBeforeMathDisplay=Default,styleBeforeMathInline=Default,styleInBrace=Default,styleBeforeBrace=Default;
    for (int i = 0; i < list.size(); i++) {
        QString line=list.at(i);
        int lineLength=line.size();
        if(style!=MathInline && style!=MathDisplay && style!=Environment){
            style=Default;
            nextStyle=Default;
        }
        int j=0;
        while(j<lineLength){
            QString l=line.mid(j);
            if(l.startsWith("\\%")){
                nbCharsToStyle=2;
                nextStyle=style;
                style=Command;
            }
            else if(l.startsWith("%")){
                nbCharsToStyle=lineLength-j;
                style=Comment;
                nextStyle=Comment;
            }
            else if(l.startsWith("\\[")){
                nbCharsToStyle=2;
                styleBeforeMathDisplay=style;
                style=Command;
                nextStyle=MathDisplay;
            }
            else if(l.startsWith("\\]")){
                nbCharsToStyle=2;
                style=Command;
                nextStyle=styleBeforeMathDisplay;
            }
            else if(l.startsWith("\\(")){
                nbCharsToStyle=2;
                styleBeforeMathInline=style;
                style=Command;
                nextStyle=MathInline;
            }
            else if(l.startsWith("\\)")){
                nbCharsToStyle=2;
                style=Command;
                nextStyle=styleBeforeMathInline;
            }
            else if(l.startsWith("\\$") || l.startsWith("\\{") || l.startsWith("\\}")){
                nbCharsToStyle=2;
                nextStyle=style;
                style=Command;
            }
            else if(l.startsWith("\\")){
                nbCharsToStyle=1;
                nextStyle=style;
                while(nbCharsToStyle<l.size() && l.at(nbCharsToStyle).isLetter()){
                    nbCharsToStyle++;
                }
                QString s=l.left(nbCharsToStyle);
                if(s=="\\begin" || s=="\\end"){
                    styleInBrace=Environment;
                }
                else if(s=="\\part"){
                    styleInBrace=Part;
                }
                else if(s=="\\chapter"){
                    styleInBrace=Chapter;
                }
                else if(s=="\\section"){
                    styleInBrace=Section;
                }
                else if(s=="\\subsection"){
                    styleInBrace=SubSection;
                }
                else if(s=="\\subsubsection"){
                    styleInBrace=SubSubSection;
                }
                else if(s=="\\paragraph"){
                    styleInBrace=Paragraph;
                }
                else if(s=="\\subparagraph"){
                    styleInBrace=SubParagraph;
                }
                style=Command;
            }
            else if(l.startsWith("$")){
                nbCharsToStyle=1;
                if(style==MathInline){
                    nextStyle=styleBeforeMathInline;
                }
                else{
                    styleBeforeMathInline=style;
                    nextStyle=MathInline;
                }
                style=SpecialChar;
            }
            else if(l.at(0).isDigit()){
                bool isNumber=true;
                nbCharsToStyle=1;
                nextStyle=style;
                while(isNumber && nbCharsToStyle<l.size()){
                    nbCharsToStyle++;
                    l.left(nbCharsToStyle).toFloat(&isNumber);
                }
                if(!isNumber){
                    nbCharsToStyle--;
                }
                style=Digit;
            }
            else if(l.startsWith("(")||l.startsWith(")")||l.startsWith("[")||l.startsWith("]")||l.startsWith("&")||l.startsWith("#")){
                nbCharsToStyle=1;
                nextStyle=style;
                style=SpecialChar;
            }
            else if(l.startsWith("{")){
                nbCharsToStyle=1;
                styleBeforeBrace=style;
                nextStyle=styleInBrace;
                style=SpecialChar;
            }
            else if(l.startsWith("}")){
                nbCharsToStyle=1;
                nextStyle=styleBeforeBrace;
                style=SpecialChar;
                styleInBrace=Default;
            }
            else{
                nbCharsToStyle=1;
                if(l.at(0)!=' '){
                    styleInBrace=style;
                }
            }
            setStyling(nbCharsToStyle,defaultStyle(style));
            style=nextStyle;
            j+=nbCharsToStyle;

        }
        setStyling(1,defaultStyle(style));


        QString s=trimComment(line);
        if(s.contains("\\part")){
            level=2000;

        }
        else if(s.contains("\\chapter")){
            level=2001;

        }
        else if(s.contains("\\section")){
            level=2002;

        }
        else if(s.contains("\\subsection")){
            level=2003;

        }
        else if(s.contains("\\subsubsection")){
            level=2004;

        }
        else if(s.contains("\\paragraph")){
            level=2005;

        }
        else if(s.contains("\\subparagraph")){
            level=2006;

        }
        if(isHeaderLine(s)){
            editor()->SendScintilla(QsciScintilla::SCI_SETFOLDLEVEL,lineIndex,level|QsciScintilla::SC_FOLDLEVELHEADERFLAG);
        }
        /*
        else if(line.trimmed().isEmpty()){
            editor()->SendScintilla(QsciScintilla::SCI_SETFOLDLEVEL,lineIndex,level|QsciScintilla::SC_FOLDLEVELWHITEFLAG);
        }
        */
        else{
            editor()->SendScintilla(QsciScintilla::SCI_SETFOLDLEVEL,lineIndex,level);

        }
        level+=getDiffLevel(s);

        lineIndex++;
    }
}