Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* u,h,j,k zum aendern der Position des Felds, x,y,a,s, zum aendern der Groesse,
- n um das Element einzufuegen (es wird eine HTML-Tabelle generiert), anschliessend
- enthaltenen Text eintippen. q zum Speichern in Datei posdata
- das #define unten auskommentieren und es generiert das andere Programm.
- Im selben Verzeichnis liest es posdata und man kann die Ausgabe direkt in eine
- zu erzeugende HTML-Datei leiten.
- Beim Editor Konsolenfenster groΓ stellen (so 62x42).
- Tabellen scheinen eine Moeglichkeit zu sein. Ansonsten ist die Formatierung mehr
- als vertrackt oder unmoeglich.
- */
- #define COMPILE_EDITOR
- #ifdef COMPILE_EDITOR
- #include <stdio.h>
- #include <fcntl.h>
- #include <stdlib.h>
- struct
- {
- int x,y,xdim,ydim;
- }boxes[100];
- unsigned char htmltext[200*100];
- int generate(int n)
- {
- unsigned char generatestring[200];
- if ( boxes[n].xdim==0||boxes[n].ydim==0) return 0;
- printf("(F) zum Fortfahren");
- if ( toupper(getch())!='F') return 0;
- unsigned char x[5],y[5];
- unsigned char contentstring[32];
- printf("\nBitte Text eingeben:");
- gets(contentstring);
- itoa(boxes[n].xdim*10,x,10);
- itoa(boxes[n].ydim*10,y,10);
- strcpy(generatestring,"<table align=left height="),
- strcat(generatestring,x),strcat(generatestring," width="),
- strcat(generatestring,y),strcat(generatestring,">");
- strcat(generatestring,contentstring),strcat(generatestring,"</table>");
- strcpy(&(htmltext[200*n]),generatestring);
- return 1;
- }
- signed int boxptr=0;
- int main(void)
- {
- enum
- {
- up,down,left,right,grewx,grewy
- }LASTSTEP;
- unsigned char screen[60][40],collide[60][40];
- int x,y;
- int n=0;
- y=0;
- while ( y<40 )
- {
- x=0;
- while ( x<60 ) screen[x][y]=collide[x][y]=0,x++; y++;
- }
- boxes[n].x=boxes[n].y=boxes[n].xdim=boxes[n].ydim=0;
- while (1)
- {
- if ( kbhit())
- {
- switch(getch())
- {
- case 'x': if ( boxes[boxptr].xdim<15&&boxes[boxptr].x+boxes[boxptr].xdim<60)
- boxes[boxptr].xdim++; LASTSTEP=grewx; break;
- case 'y':if ( boxes[boxptr].ydim<15&&boxes[boxptr].y+boxes[boxptr].ydim<39)
- boxes[boxptr].ydim++; LASTSTEP=grewy;break;
- case 's': if ( boxes[boxptr].xdim>0)
- boxes[boxptr].xdim--; break;
- case 'a': if ( boxes[boxptr].ydim>0)
- boxes[boxptr].ydim--; break;
- case 'u': if ( boxes[boxptr].y>0)
- boxes[boxptr].y--; LASTSTEP=up;break;
- case 'j': if ( boxes[boxptr].y+boxes[boxptr].ydim<39)
- boxes[boxptr].y++;LASTSTEP=down; break;
- case 'h': if ( boxes[boxptr].x>0)
- boxes[boxptr].x--; LASTSTEP=left;break;
- case 'k': if ( boxes[boxptr].x+boxes[boxptr].xdim<59)
- boxes[boxptr].x++; LASTSTEP=right;break;
- case 'n': if(generate(boxptr)==1) {
- boxptr++; boxes[n].x=boxes[n].y=boxes [n].xdim=boxes[n].ydim=0; }
- break;
- case 'q': goto writeout;
- }
- }
- y=0;
- while ( y<40 )
- {
- x=0;
- while ( x<60 ) screen[x][y]=' ',collide[x][y]=255,x++;
- y++;
- }
- screen[boxes[boxptr].x][boxes[boxptr].y]='X';
- n=0;
- while ( n < boxptr+1)
- {
- if ( n==boxptr&&boxes[n].xdim==0&&boxes[n].ydim==0)break;
- int dimc_x,dimc_y;
- dimc_y=boxes[n].ydim;
- while ( dimc_y>=0)
- {
- dimc_x=boxes[n].xdim;
- while ( dimc_x >= 0 )
- {
- if ( collide[boxes[n].x+dimc_x][boxes[n].y+dimc_y]==255||collide[boxes[n].x+dimc_x][boxes[n].y+dimc_y]==n)
- screen[boxes[n].x+dimc_x][boxes[n].y+dimc_y]=177,
- collide[boxes[n].x+dimc_x][boxes[n].y+dimc_y]=n;
- else
- {
- printf("\a");
- switch(LASTSTEP)
- {
- case up: boxes[n].y++;break;
- case down:boxes[n].y--;break;
- case left:boxes[n].x++;break;
- case right:boxes[n].x--;break;
- case grewx: boxes[n].xdim--; break;
- case grewy: boxes[n].ydim--; break;
- }
- dimc_x=0;
- dimc_y=boxes[n].ydim+1;
- goto repeat;
- }
- dimc_x--;
- }
- repeat:
- dimc_y--;
- }
- n++;
- }
- system("cls");
- y=0;
- while ( y < 40)
- {
- x=0;
- while ( x<60) printf("%c%c%c%c",screen[x][y],screen[x+1][y],screen[x+2][y],screen[x+3][y]),x+=4;
- printf("\n");
- y++;
- }
- }
- writeout:
- (0);
- FILE *output=fopen("posdata","wb");
- fwrite(boxes, sizeof(boxes),1,output);
- fwrite(htmltext, sizeof(htmltext),1,output);
- fwrite(&boxptr,sizeof(signed int),1,output);
- fclose(output);
- }
- #else
- #include <stdio.h>
- #include <fcntl.h>
- #define XSPACING 1
- #define YSPACING 2
- struct
- {
- int x,y,xdim,ydim;
- }boxes[100],swap;
- unsigned char htmltext[200*100], htmlswap[200];
- signed int boxc=0;
- void sort_boxes(int num)
- {
- int n=0,n2=0;
- n=0;
- while ( n<num-1)
- {
- n2=num-1;
- while ( n2>n)
- {
- if ( boxes[n2].x+boxes[n2].y*60 < boxes[n2-1].x+boxes[n2-1].y*60 )
- {
- swap.x=boxes[n2].x;
- swap.y=boxes[n2].y;
- swap.xdim=boxes[n2].xdim;
- swap.ydim=boxes[n2].ydim;
- strcpy(htmlswap,&(htmltext[n2*200]));
- boxes[n2].x=boxes[n2-1].x;
- boxes[n2].y=boxes[n2-1].y;
- boxes[n2].xdim=boxes[n2-1].xdim;
- boxes[n2].ydim=boxes[n2-1].ydim;
- strcpy(&(htmltext[n2*200]),&(htmltext[(n2-1)*200]));
- boxes[n2-1].x=swap.x;
- boxes[n2-1].y=swap.y;
- boxes[n2-1].xdim=swap.xdim;
- boxes[n2-1].ydim=swap.ydim;
- strcpy(&(htmltext[(n2-1)*200]),htmlswap);
- }
- n2--;
- }
- n++;
- }
- }
- int main(void)
- {
- int x_off=0,y_off=0;
- int old_x=0,old_y=0;
- FILE *input=fopen("posdata","rb");
- fread(boxes, sizeof(boxes),1/*sizeof(boxes[0]),boxc+1*/,input);
- fread(htmltext, sizeof(htmltext),1/*sizeof(boxes[0]),boxc+1*/,input);
- fread(&boxc,sizeof(signed int),1,input);
- fclose(input);
- int n=0;
- sort_boxes(boxc);
- printf("<html>\n<body>\n");
- n=0;
- int x=0,y=0;
- y=0;
- while (y<40)
- {
- x=0;
- while(x<60)
- {
- if ( x==boxes[n].x&& y==boxes[n].y)
- {
- while ( (y+y_off-old_y)/YSPACING >0)old_y+=YSPACING,printf("<br>\n",YSPACING);
- while ( (x+x_off-old_x)/XSPACING >0)old_x+=XSPACING,printf(" ",XSPACING);
- printf("%s",&htmltext[200*n]);
- old_x=boxes[n].x,old_y=boxes[n].y;
- x_off+=x-old_x-boxes[n].xdim%XSPACING;
- y_off+=y-old_y-boxes[n].ydim%YSPACING;
- n++; if ( n==boxc+1) goto end;
- }
- x++;
- }
- old_x=0;
- x_off=0;
- printf("<br>"); old_y+=YSPACING;
- y++;
- }
- end: printf("</body></html>");
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement