pax_global_header00006660000000000000000000000064120067057670014524gustar00rootroot0000000000000052 comment=36b0a3af174e204c8d0a7a993ad467cd7be39bca aha-0.4.6.1/000077500000000000000000000000001200670576700124235ustar00rootroot00000000000000aha-0.4.6.1/CHANGELOG000066400000000000000000000010471200670576700136370ustar00rootroot00000000000000- Honor common compiler and linker flags Version 0.4.6: - Added Feature for not creating a header e.g. for already existing HTML-files (thanks to Nicolas Zagulajew) Version 0.4.5: - Added Feature for word wrap (thanks to Jussi Leinonen) Version 0.4.4: - Fixed Bug: Command \e24m (underline off) didn't work - Fixed Bug: Command \e7m (inverted) didn't work - Fixed Bug: Command \e27m (inverted off) didn't work Version 0.4.3: - new option "--title" for an alternative title in the html file - Fixed Bug 624233 (typo in manpage -color -> --color) aha-0.4.6.1/Makefile000066400000000000000000000001411200670576700140570ustar00rootroot00000000000000all: aha aha: aha.c gcc -std=c99 $(CFLAGS) $(LDFLAGS) $(CPPFLAGS) aha.c -o aha clean: rm aha aha-0.4.6.1/README000066400000000000000000000003131200670576700133000ustar00rootroot00000000000000aha === Ansi HTML Adapter To compile just type :make To "install" aha move it to your bin-Directory or create a package by yourself. :-P All files are subjects to the LGPL or the MPL. (Dual licensed). aha-0.4.6.1/aha.1000066400000000000000000000036121200670576700132400ustar00rootroot00000000000000.TH aha 1 "August 3, 2012" "" "Ansi HTML Adapter" .SH NAME aha - Ansi HTML Adapter .SH SYNOPSIS \fBaha\fP [\fIoptions\fP] [\-f \fIfile\fP] .SH DESCRIPTION .B aha takes SGR-colored Input and prints W3C conform HTML-Code. .br .B aha reads the Input from a file or stdin and writes HTML-Code to stdout. .SH OPTIONS .TP \fB\-\-help , \-h , \-?\fP A help like this .TP \fB\-\-black , \-b\fP Black Background and white "standard color" .TP \fB\-\-pink , \-p\fP Pink Background .TP \fB\-\-iso X , \-i X Uses ISO 8859-X instead of utf-8. X must be 1..16 .TP \fB\-\-title X , \-t X Gives the html output the title \"X\" instead of stdin or the filename .TP \fB\-\-line\-fix , \-l Uses a fix for inputs using control sequences to change the cursor position like htop. It's a hot fix, it may not work with any program like htop. (See \fBEXAMPLE\fP) .TP \fB\-\-word\-wrap , \-w Wrap long lines in the html file. This works with CSS3 supporting browsers as well as many older ones. .TP \fB\-\-no\-header , \-n Don't include header into generated HTML, useful for inclusion in full HTML files. .SH EXAMPLE .TP \fBaha\fP \-\-help | \fBaha\fP \-\-black \-\-title "the awesome aha help"> aha\-help.htm Creates an HTML file with the help of aha with black background .TP \fBcolordiff\fP oldfile.c newfile.c | \fBaha\fP > colordiff.htm Creates an HTML file with a colorful diff-output of two files "oldfile.c" and "newfile.c" with white background .TP \fBls\fP \-\-color=always | \fBaha\fP \-\-pink > ls.htm Creates an HTML file with a colorful ls-output with pink background. .TP \fBecho\fP q | \fBhtop\fP | \fBaha\fP \-\-black \-\-line\-fix > htop.htm Creates an HTML file with the output of htop. You have to use \fB\-\-line\-fix\fP due the other new-line-commands htop uses. .SH AUTHOR Copyleft Alexander Matthes aka Ziz 2012 .br zizsdl@googlemail.com .SH SEE ALSO https://github.com/theZiz/aha http://ziz.delphigl.com/tool_aha.php aha-0.4.6.1/aha.c000066400000000000000000000374031200670576700133270ustar00rootroot00000000000000/* The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Alternatively, the contents of this file may be used under the terms of the GNU Lesser General Public license (the "LGPL License"), in which case the provisions of LGPL License are applicable instead of those above. For feedback and questions about my Files and Projects please mail me, Alexander Matthes (Ziz) , zizsdl_at_googlemail.com */ #define AHA_VERSION "0.4.6.1" #include #include #include int future=0; int future_char=0; int getNextChar(register FILE* fp) { int c; if (future) { future=0; return future_char; } if ((c = fgetc(fp)) != EOF) return c; fprintf(stderr,"Unknown Error in File Parsing!\n"); exit(1); } int getFutureChar(register FILE* fp) { int c; if (future) return future_char; if ((c = fgetc(fp)) != EOF) { future=1; future_char=c; return c; } fprintf(stderr,"Unknown Error in File Parsing!\n"); exit(1); } typedef struct selem *pelem; typedef struct selem { unsigned char digit[8]; unsigned char digitcount; pelem next; } telem; pelem parseInsert(char* s) { pelem firstelem=NULL; pelem momelem=NULL; unsigned char digit[8]; unsigned char digitcount=0; int pos=0; for (pos=0;pos<1024;pos++) { if (s[pos]=='[') continue; if (s[pos]==';' || s[pos]==0) { if (digitcount<=0) { digit[0]=0; digitcount=1; } pelem newelem=(pelem)malloc(sizeof(telem)); for (unsigned char a=0;a<8;a++) newelem->digit[a]=digit[a]; newelem->digitcount=digitcount; newelem->next=NULL; if (momelem==NULL) firstelem=newelem; else momelem->next=newelem; momelem=newelem; digitcount=0; memset(digit,0,8); if (s[pos]==0) break; } else if (digitcount<8) { digit[digitcount]=s[pos]-'0'; digitcount++; } } return firstelem; } void deleteParse(pelem elem) { while (elem!=NULL) { pelem temp=elem->next; free(elem); elem=temp; } } int main(int argc,char* args[]) { char* filename=NULL; register FILE *fp = stdin; int colorshema=0; //0:normal, 1:black, 2:pink int iso=-1; //utf8 char htop_fix=0; char line_break=0; char* title=NULL; char word_wrap=0; char no_header=0; //Searching Parameters for (int p = 1;p [\033[4m-f file\033[0m]\n"); printf(" \033[1maha\033[0m (\033[4m--help\033[0m|\033[4m-h\033[0m|\033[4m-?\033[0m)\n"); printf("\033[1maha\033[0m reads the Input from a file or stdin and writes HTML-Code to stdout\n"); printf("\033[4moptions\033[0m: --black, -b: \033[1;30m\033[1;47mBlack\033[0m Background and \033[1;37mWhite\033[0m \"standard color\"\n"); printf(" --pink, -p: \033[1;35mPink\033[0m Background\n"); printf(" --iso X, -i X: Uses ISO 8859-X instead of utf-8. X must be 1..16\n"); printf(" --title X, -t X: Gives the html output the title \"X\" instead of \"stdin\"\n"); printf(" or the filename\n"); printf(" --line-fix, -l: Uses a fix for inputs using control sequences to\n"); printf(" change the cursor position like htop. It's a hot fix,\n"); printf(" it may not work with any program like htop. Example:\n"); printf(" \033[1mecho\033[0m q | \033[1mhtop\033[0m | \033[1maha\033[0m -l > htop.htm\n"); printf(" --word-wrap, -w: Wrap long lines in the html file. This works with\n"); printf(" CSS3 supporting browsers as well as many older ones.\n"); printf(" --no-header, -n: Don't include header into generated HTML,\n"); printf(" useful for inclusion in full HTML files.\n"); printf("Example: \033[1maha\033[0m --help | \033[1maha\033[0m --black > aha-help.htm\n"); printf(" Writes this help text to the file aha-help.htm\n\n"); printf("Copyleft \033[1;32mAlexander Matthes\033[0m aka \033[4mZiz\033[0m 2012\n"); printf(" \033[5;36mzizsdl@googlemail.com\033[0m\n"); printf(" \033[5;36mhttp://ziz.delphigl.com/tool_aha.php\033[0m\n"); printf("This application is subject to the \033[1;34mMPL\033[0m or \033[1;34mLGPL\033[0m.\n"); return 0; } else if ((strcmp(args[p],(char*)"--version")==0) || (strcmp(args[p],(char*)"-v")==0)) { printf("\033[1;31mAnsi Html Adapter\033[0m Version "AHA_VERSION"\n"); return 0; } else if ((strcmp(args[p],"--title")==0) || (strcmp(args[p],"-t")==0)) { if (p+1>=argc) { fprintf(stderr,"No title given!\n"); return 0; } title=args[p+1]; p++; } else if ((strcmp(args[p],"--line-fix")==0) || (strcmp(args[p],"-l")==0)) { htop_fix=1; } else if ((strcmp(args[p],"--no-header")==0) || (strcmp(args[p],"-n")==0)) { no_header=1; } else if ((strcmp(args[p],"--word-wrap")==0) || (strcmp(args[p],"-w")==0)) word_wrap=1; else if ((strcmp(args[p],"--black")==0) || (strcmp(args[p],"-b")==0)) colorshema=1; else if ((strcmp(args[p],"--pink")==0) || (strcmp(args[p],"-p")==0)) colorshema=2; else if ((strcmp(args[p],"--iso")==0) || (strcmp(args[p],"-i")==0)) { if (p+1>=argc) { fprintf(stderr,"No ISO code given!\n"); return 0; } iso = atoi(args[p+1]); if (iso<1 || iso>16) { fprintf(stderr,"not a valid ISO code: ISO 8859-%s\n",args[p+1]); return 0; } p++; } else if (strcmp(args[p],"-f")==0) { if (p+1>=argc) { fprintf(stderr,"no file to read given after \"-f\"!\n"); return 0; } fp = fopen(args[p+1],"r"); if (fp==NULL) { fprintf(stderr,"file \"%s\" not found!\n",args[p+1]); return 0; } p++; filename=args[p]; } else { fprintf(stderr,"Unknown parameter \"%s\"\n",args[p]); return 0; } } if (no_header == 0) { //Header: if (iso<0) printf("\n\n"); else printf("\n",iso); printf("\n"); printf("\n"); printf("\n\n"); if (title) printf("%s\n",title); else { if (filename==NULL) printf("stdin\n"); else printf("%s\n",filename); } if (word_wrap) { printf("\n"); } printf("\n"); switch (colorshema) { case 1: printf("\n"); break; case 2: printf("\n"); break; default: printf("\n"); } //Standardwerte: //printf("
"); printf("
\n");
	}

	//Begin of Convertion
	unsigned int c;
	int fc = -1; //Standard Foreground Color //IRC-Color+8
	int bc = -1; //Standard Background Color //IRC-Color+8
	int ul = 0; //Not underlined
	int bo = 0; //Not bold
	int bl = 0; //No Blinking
	int ofc,obc,oul,obo,obl; //old values
	int line=0;
	int momline=0;
	int newline=-1;
	int temp;
	while ((c=fgetc(fp)) != EOF)
	{
		if ((c=='\033'))
		{
			//Saving old values
			ofc=fc;
			obc=bc;
			oul=ul;
			obo=bo;
			obl=bl;
			//Searching the end (a letter) and safe the insert:
			c='0';
			char buffer[1024];
			int counter=0;
			while ((c<'A') || ((c>'Z') && (c<'a')) || (c>'z'))
			{
				c=getNextChar(fp);
				buffer[counter]=c;
				if (c=='>') //end of htop
					break;
				counter++;
				if (counter>1022)
					break;
			}
			buffer[counter-1]=0;
			pelem elem;
			switch (c)
			{
				case 'm': 
					//printf("\n%s\n",buffer); //DEBUG
					elem=parseInsert(buffer);
					pelem momelem=elem;
					while (momelem!=NULL)
					{
						//jump over zeros
						int mompos=0;
						while (momposdigitcount && momelem->digit[mompos]==0)
							mompos++;
						if (mompos==momelem->digitcount) //only zeros => delete all
						{
							bo=0;ul=0;bl=0;fc=-1;bc=-1;
						}
						else
						{
							switch (momelem->digit[mompos])
							{
								case 1: bo=1; break;
								case 2: if (mompos+1digitcount) 
												switch (momelem->digit[mompos+1])
												{
													case 1: //Reset blink and bold
														bo=0;
														bl=0;
														break;
													case 4: //Reset underline
														ul=0;
														break;
														case 7: //Reset Inverted
														temp = bc;
														if (fc == -1 || fc == 9)
														{
															if (colorshema!=1)
																bc = 0;
															else
																bc = 7;
														}
														else
															bc = fc;
														if (temp == -1 || temp == 9)
														{
															if (colorshema!=1)
																fc = 7;
															else
																fc = 0;
														}
														else
															fc = temp;
														break;
												}
												break;
						case 3: if (mompos+1digitcount)
											fc=momelem->digit[mompos+1];
										break;
						case 4: if (mompos+1==momelem->digitcount)
											ul=1;
										else
											bc=momelem->digit[mompos+1];
										break;
						case 5: bl=1; break;
						case 7: //TODO: Inverse
										temp = bc;
										if (fc == -1 || fc == 9)
										{
											if (colorshema!=1)
												bc = 0;
											else
												bc = 7;
										}
										else
											bc = fc;
										if (temp == -1 || temp == 9)
										{
											if (colorshema!=1)
												fc = 7;
											else
												fc = 0;
										}
										else
											fc = temp;
										break;
							}
						}
						momelem=momelem->next;
					}
					deleteParse(elem);
				break;
				case 'H': 
					if (htop_fix) //a lil dirty ...
					{
						elem=parseInsert(buffer);
						pelem second=elem->next;
						if (second==NULL)
							second=elem;
						newline=second->digit[0]-1;
						if (second->digitcount>1)
							newline=(newline+1)*10+second->digit[1]-1;
						if (second->digitcount>2)
							newline=(newline+1)*10+second->digit[2]-1;
						deleteParse(elem);
						if (newline");
				if ((fc!=-1) || (bc!=-1) || (ul!=0) || (bo!=0) || (bl!=0))
				{
					printf("");
				}
			}			
		}
		else
		if (c==13 && htop_fix)
		{
			for (;line<80;line++)
				printf(" ");
			line=0;
			momline++;
			printf("\n");
		}
		else if (c!=8)
		{
			line++;
			if (line_break)
			{
				printf("\n");
				line=0;
				line_break=0;
				momline++;
			}
			if (newline>=0)
			{
				while (newline>line)
				{
					printf(" ");
					line++;
				}
				newline=-1;
			}
			switch (c)
			{
				case '&':	printf("&"); break;
				case '\"': printf("""); break;
				case '<':	printf("<"); break;
				case '>':	printf(">"); break;
				case '\n':case 13: momline++;
									 line=0;
				default:	 printf("%c",c);
			}
			if (iso>0) //only at ISOS
				if ((c & 128)==128) //first bit set => there must be followbytes
				{
					int bits=2;
					if ((c & 32)==32)
						bits++;
					if ((c & 16)==16)
						bits++;
					for (int meow=1;meow\n");
	
	if (no_header == 0)
	{
		printf("
\n"); printf("\n"); printf("\n"); } if (fp!=stdin) fclose(fp); return 0; }