int main(int argc, char **argv) { int i, n; char *s; char *bad = NULL; int c; int width = 0, height = 0, bpp = 8, gray = 192, attributes = 0; char *name, *testname; GrFontHeader *hdr; FILE *f; char buffer[210]; GrEvent ev; int key; /* unfortunately not all systems support getopt() */ for(i = 1; i < argc; i++) { s = argv[i]; if(*s != '-' || ((c = *++s) == '\0') || *++s != '\0') break; if(c == '-') { i++; break; } if(++i == argc) { fprintf(stderr, "-%c: argument required\n", c); return(1); } if(sscanf(argv[i], "%d", &n) != 1 || n < 0) { fprintf(stderr, "%s: invalid argument\n", argv[i]); exit(1); } switch(c) { case 'x' : width = n; break; case 'y' : height = n; break; case 'b' : if((bpp = n) < 2 || bpp > 32) bad = "bpp"; break; case 'g' : if((gray = n) > 255) bad = "gray"; break; case 'X' : if((deltax = n) > 31) bad = "deltax"; break; case 'Y' : if((deltax = n) > 31) bad = "deltay"; break; case 'a' : if((attributes = n) > 3) bad = "attributes"; break; default : { fprintf(stderr, "-%c: invalid option\n", c); return(1); } } if(bad) { fprintf(stderr, "%d: %s out of range\n", n, bad); return(1); } } if(i == argc) { printf( "usage:\tfontdemo [-x WIDTH] [-y HEIGHT] [-b BPP] [-g COMPONENT]\n" "\t[-X DELTAX] [-Y DELTAY] [-a ATTRIBUTES] FONT [FILE...]\n" ); return(0); } name = argv[i++]; opt.txo_font = GrLoadFont(name); if(opt.txo_font == NULL && (testname = malloc(strlen(name) + 10)) != NULL) { /* try again, this is a test and the path can not been set yet */ #if defined(__MSDOS__) || defined(__WIN32__) sprintf( testname,"..\\fonts\\%s",name ); #else sprintf( testname,"../fonts/%s",name ); #endif opt.txo_font = GrLoadFont(testname); free(testname); } if(opt.txo_font == NULL) { fprintf(stderr, "%s: load error\n", name); return(1); } hdr = &opt.txo_font->h; if(height == 0) { if(width == 0) { switch(hdr->height) { case 8 : case 14 : height = 400; break; case 16 : height = 480; break; case 20 : height = 600; break; case 24 : height = 768; break; default : height = hdr->height < 20 ? 480 : 768; } } else height = width * 3 / 4; } if(width == 0) width = height == 400 ? 640 : height * 4 / 3; GrSetMode(GR_width_height_bpp_graphics, width, height, bpp); if(!gray || (opt.txo_fgcolor.v = GrAllocColor(gray, gray, gray)) == GrNOCOLOR) opt.txo_fgcolor.v = GrWhite(); if(attributes & 0x02) opt.txo_fgcolor.v |= GR_UNDERLINE_TEXT; opt.txo_bgcolor.v = GrBlack(); if(attributes & 0x01) revert(); opt.txo_chrtype = GR_BYTE_TEXT; opt.txo_direct = GR_TEXT_RIGHT; opt.txo_xalign = GR_ALIGN_LEFT; opt.txo_yalign = GR_ALIGN_TOP; sprintf(buffer, "Font name:%s %dx%d", hdr->name, GrCharWidth('A', &opt), GrCharHeight('A', &opt)); if (hdr->proportional) strcat(buffer, " proportional"); else strcat(buffer, " fixed"); gputs(buffer); sprintf(buffer, "Font family: %s", hdr->family); gputs(buffer); sprintf(buffer, "Min char, num chars: %d, %d", hdr->minchar,hdr->numchars); gputs(buffer); sprintf(buffer, "Screen res: %dx%d@%lu", GrSizeX(), GrSizeY(), (unsigned long) GrNumColors()); gputs(buffer); gnewl(); gputs("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"); gputs("the quick brown fox jumps over the lazy dog"); gnewl(); // if(hdr->minchar <= 0xC0 && hdr->minchar + hdr->numchars >= 0x100) { // gputs("������� ��� ���� ���� ��"); // gputs("������� ��� ���� ���� ��"); // gnewl(); // } /* ascii table, or to be precise, a full table of the current font */ opt.txo_chrtype = GR_WORD_TEXT; for(c = 0; c < hdr->numchars; c++) { gputc(hdr->minchar + c); if(c % 0x20 == 0x1F) gnewl(); } gnewl(); if(c % 0x20 != 0) gnewl(); opt.txo_chrtype = GR_BYTE_TEXT; while(i < argc) { name = argv[i++]; if((f = fopen(name, "r")) == NULL) { perror(name); return(1); } while((c = getc(f)) != EOF) if(c != '\n') gputc(c); else gnewl(); if(ferror(f) != 0 || fclose(f) != 0) { perror(name); return(1); } } /* enter and esc are < 0x100 and displayed 1:1 */ gputs("F1-new line F5-toggle reverse F7-toggle underline F10-exit"); gnewl(); GrEventInit(); while(1) { GrEventWait(&ev); if(ev.type == GREV_KEY) { key = ev.p1; if( key == GrKey_F10) break; if(key == GrKey_F1) gnewl(); else if(key == GrKey_F5) revert(); else if(key == GrKey_F7) opt.txo_fgcolor.v ^= GR_UNDERLINE_TEXT; else if(key < 0x100) gputc(key); } } GrEventUnInit(); GrUnloadFont(opt.txo_font); return(0); }
int main(int argc, char *argv[]) { int rc, i, uid, n, c, ch, t, mtbl, line, offset; FILE *fp; char filename[64], inbuf[128], name[NATIONNMLEN+1], *p, *u; struct stat st_buf; /* set directory */ if(argc > 1) if(chdir(argv[1]) == -1) { gmove(20,18); gprintf("Error Setting Directory %s\n", argv[1]); ggetch(); gend(); exit(1); } /* set up display */ ginit(); gmove(5, 10); gputs("WARTOOL 1.0 Game Editor for Solomoriah's WAR!"); gmove(6, 10); gputs("Copyright 1994, J. Christopher Gonnerman"); gmove(7, 10); gputs("All Rights Reserved."); /* load map file */ rc = loadmap(); if(rc != 0) { gmove(20,10); gprintf("Error Loading Map (%s)\n", errors[rc]); ggetch(); gend(); exit(1); } /* load game save */ rc = loadsave(); if(rc != 0) { gmove(20,10); gprintf("Error Loading Game Save (%s)\n", errors[rc]); ggetch(); gend(); exit(1); } /* execute master file */ gmove(20,10); gputs("Reading Master Commands... "); grefresh(); fp = fopen(MASTERFL, "r"); if(fp != NULL) { for(i = 0; fgets(inbuf, 128, fp) != NULL; i++) { rc = execpriv(inbuf); if(rc == 0) { if((i+1) % 10 == 0) { gmove(20,48); gprintf("%3d lines", i+1); grefresh(); } } else { gmove(20,10); gprintf("Master Cmd Failed, Line %d, Code %d ", i+1, rc); (void)ggetch(); gend(); exit(2); } } fclose(fp); } /* main loop */ gmove(20,10); gputs("Press Any Key to Begin... "); gclrline(); ggetch(); mainscreen(); toolmain(); unlink("game.bak"); if(rename("game.sav", "game.bak") == 0) fp = fopen("game.sav", "w"); else fp = fopen("game.sv!", "w"); savegame(fp); fclose(fp); /* clean up */ endwin(); exit(0); }