test

This is a discussion on test within the A Brief History of Cprogramming.com forums, part of the Community Boards category; please work.. apLEWORAasdasdf ' damn wrinkly unplanned asdfwasd Code: /* main.c - main file for csyntax. this program highlights c/c++ ...

  1. #1
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435

    test

    please work.. apLEWORAasdasdf
    '
    damn wrinkly unplanned asdfwasd
    Code:
    /* main.c - main file for csyntax. this program highlights c/c++ sourcecode with vB codes */
    #include <stdio.h>
    #include <ctype.h>
    
    #define COMMENT		"<COLOR=RED>"
    #define PP			"<COLOR=GREEN>"
    #define STRING		"<COLOR=BLUE>"
    
    #define uint		unsigned int
    #define uchar		unsigned char
    
    /* main program: let the garbled bag of hell mess begin */
    int main()
    {
    	uchar c,t; uint in_quote, in_squote, in_pp, ccomment, cppcomment, in_boardtag;
    
    	/* init the vars */
    	in_quote	= 0;
    	in_squote	= 0;
    	in_pp		= 0;
    	in_boardtag = 0;
    	ccomment	= 0;
    	cppcomment	= 0;
    
    	printf("<CODE>");
    
    	/* start main input loop */
    	while(!feof(stdin))
    	{
    		c = fgetc(stdin);
    
    		/* prevent EOF char from appearing */
    		if(c == EOF)
    			break;
    
    		/* prepare to highlight */
    		switch (c)
    		{
    			/* work *sob* WORK!! please... ignore escape/control codes, whatever they are*/
    			case '\\':
    				t = fgetc(stdin);
    
    				fputc(c, stdout);
    				fputc(t, stdout);
    				break;
    
    			/* make the board shut up */
    			case '<':
    				t = fgetc(stdin);
    
    				if(!isdigit(t))
    				{
    					fputc('<', stdout);
    					in_boardtag = 1;
    				} else fputc(c, stdout);
    
    				ungetc(t, stdin);
    				break;
    
    
    			/* make the replacement on both ends */
    			case '>':
    				if(in_boardtag == 1)
    					c = '>';
    				fputc(c, stdout);
    				break;
    
    			/* check for the end of c-style comments */
    			case '*':
    				t = fgetc(stdin);
    
    				if(in_quote != 1)
    				{
    					if(t == '/' && ccomment == 1)
    					{
    						fputc(c, stdout);
    						fputc(t, stdout);
    						printf("</COLOR>");
    						ccomment = 0;
    					} else {
    						fputc(c, stdout);
    						ungetc(t, stdin);
    					};
    				};
    
    				break;
    
    			/* check for the start of c++ and c style comments */
    			case '/':
    				t = fgetc(stdin);
    				if(in_quote != 1)
    				{
    					if(ccomment != 1)
    					{
    						if(t == '/')
    						{
    							printf(COMMENT);
    							cppcomment = 1;
    						} else
    						if(t == '*')
    						{
    							printf(COMMENT);
    							ccomment = 1;
    						};
    					};
    				};
    
    				fputc(c, stdout);
    				ungetc(t, stdin);
    				break;
    
    			/* check for preprocessing directives */
    			case '#':
    				if(in_quote != 1 && in_squote != 1 && ccomment != 1 && cppcomment != 1)
    				{
    					printf(PP);
    					in_pp = 1;
    				};
    
    				fputc(c, stdout);
    				break;
    
    			/* check for string constants */
    			case '\"':
    				if(in_pp != 1 && ccomment != 1 && cppcomment != 1 && in_squote != 1)
    				{
    					if(in_quote == 0)
    					{
    						printf(STRING);
    						fputc(c, stdout);
    						in_quote = 1;
    					} else {
    						fputc(c, stdout);
    						printf("</COLOR>");
    						in_quote = 0;
    					};
    				} else fputc(c, stdout);
    				break;
    
    			/* check for small string constants */
    			case '\'':
    				if(in_pp != 1 && ccomment != 1 && cppcomment != 1 && in_quote != 1)
    				{
    					if(in_squote != 1)
    					{
    						printf(STRING);
    						fputc(c, stdout);
    						in_squote = 1;
    					} else {
    						fputc(c, stdout);
    						printf("</COLOR>");
    						in_squote = 0;
    					};
    				}; break;
    
    			/* pop any colors that should end at a newline */
    			case '\n':
    				if(cppcomment == 1)
    				{
    					printf("</COLOR>");
    					cppcomment = 0;
    				};
    
    				if(in_pp == 1)
    				{
    					printf("</COLOR>");
    					in_pp = 0;
    				};
    
    				fputc(c, stdout);
    				break;
    
    			default:
    				fputc(c, stdout);
    		};
    	};
    
    	printf("</CODE>");
    	return 0;
    };
    Ahah! It sort of works!
    .sect signature

  2. #2
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435

    somehow

    that was not worth the trouble. have to make a new one, nicer and planned... with keyword highlighting.
    .sect signature

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    www.sunlightd.com offers a nice source highlighter, though you'll have to change it a bit.

    BTW, do you really use red comments?!
    - lmov

  4. #4
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    Code:
    I wonder if the colors will compile. Cool, this must be VS.NET and C# source code.
    I compile code with:
    Visual Studio.NET beta2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Integer Emulation
    By Elysia in forum C++ Programming
    Replies: 31
    Last Post: 03-18-2008, 02:03 PM
  2. undefined reference
    By 3saul in forum Linux Programming
    Replies: 12
    Last Post: 08-23-2006, 06:28 PM
  3. C++ Operator Overloading help
    By Bartosz in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2005, 01:55 PM
  4. MSVC Template Constructor/Assignment Errors
    By LuckY in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 03:57 PM
  5. Why is my program freezing?
    By ShadowMetis in forum Windows Programming
    Replies: 8
    Last Post: 08-20-2004, 04:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21