home *** CD-ROM | disk | FTP | other *** search
- /*
- * C Toolbox Stationery
- * by Josef W. Wankerl
- * 04/11/00
- */
-
- #include <Dialogs.h>
- #include <Fonts.h>
- #include <MacWindows.h>
- #include <Menus.h>
- #include <QuickDraw.h>
- #include <TextEdit.h>
- #include <string.h>
- #include <stdio.h>
-
- enum
- {
- kAlertID = 128
- };
-
- static void Initialize(void)
- {
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- }
- StandardFileReply reply;
-
- #define htonl(x) x
- #define htons(x) x
-
- void main(void)
- {
-
-
- unsigned long cofst;
- char bbuf[5000], nbuf[32];
- unsigned short xshort;
- unsigned long xlong, xid;
- long bbuflen;
- int maxsect;
- char argv[2][80];
- FILE *outfd, *fd;
-
- Initialize();
-
- StandardGetFile(NULL,0,NULL,&reply);
-
- strcpy(argv[1],(char *) reply.sfFile.name);
- strcpy(bbuf, argv[1]);
- strcat(bbuf, ".pdb");
- if (!(outfd = fopen(bbuf, "w")))
- exit(-1);
-
- strcpy(bbuf, "DBLK");
- bbuf[5] = 0;
- bbuf[6] = 0x10;
- bbuf[7] = 0;
-
- memset(nbuf, 0, 32);
- strncpy(nbuf, argv[1], 32);
- fwrite(nbuf,1,32,outfd);
-
-
- memset(nbuf, 0, 4);
- nbuf[1] = 0x88;
- nbuf[3] = 1;
- fwrite( nbuf, 1,4,outfd);
-
- xlong = time(NULL) + ((66 * 365 + 17) * 24 * 3600UL);
- xlong = htonl(xlong);
-
-
- fwrite(&xlong,1,4,outfd);
- fwrite(&xlong,1,4,outfd);
- fwrite(&xlong,1,4,outfd);
-
- memset(nbuf, 0, 12);
- fwrite(nbuf,1,12,outfd);
-
-
- fwrite("DATA", 1,4,outfd);
- fwrite( "BRWS",1, 4,outfd);
-
- nbuf[0] = 0x28;
- fwrite(nbuf, 1,8,outfd);
-
- fd = fopen(argv[1], "r");
- xlong = fseek(fd, 0, SEEK_END);
- fseek(fd, 0, SEEK_SET);
-
- maxsect = xlong / 4096 + 1;
- xshort = htons(maxsect);
- fwrite( &xshort, 1,2,outfd);
-
- cofst = 80 + 8 * maxsect;
-
- xid = 0x40000000UL + (rand() & 0x7fffffUL);
- for (;;) {
-
- bbuflen = fread( &bbuf[8],1, 4096,fd);
-
- if (bbuflen <= 0)
- break;
-
- xlong = htonl(cofst);
- fwrite(&xlong,1,4,outfd);
-
- xlong = htonl(xid++);
-
- fwrite(&xlong,1,4,outfd);
- xlong = fseek(outfd, 0, SEEK_CUR);
- fseek(outfd, cofst, SEEK_SET);
- fwrite(bbuf, 1,bbuflen + 8,outfd);
- fseek(outfd, xlong, SEEK_SET);
- cofst += bbuflen + 8;
-
- if (bbuflen != 4096)
- break;
- }
-
- fclose(fd);
-
-
- xshort = 0;
- fwrite( &xshort, 1,2,outfd);
- fclose(outfd);
-
- }