home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Boxer / MacBoxer / SimpleAlert.c < prev   
Encoding:
C/C++ Source or Header  |  2000-06-23  |  2.2 KB  |  133 lines

  1. /*
  2.  *  C Toolbox Stationery
  3.  *  by Josef W. Wankerl
  4.  *  04/11/00
  5.  */
  6.  
  7. #include <Dialogs.h>
  8. #include <Fonts.h>
  9. #include <MacWindows.h>
  10. #include <Menus.h>
  11. #include <QuickDraw.h>
  12. #include <TextEdit.h>
  13. #include <string.h>
  14. #include <stdio.h>
  15.  
  16. enum
  17. {
  18.     kAlertID = 128
  19. };
  20.  
  21. static void Initialize(void)
  22. {
  23.     InitGraf(&qd.thePort);
  24.     InitFonts();
  25.     InitWindows();
  26.     InitMenus();
  27.     TEInit();
  28.     InitDialogs(nil);
  29.     InitCursor();
  30. }
  31.     StandardFileReply reply;
  32.  
  33. #define htonl(x) x
  34. #define htons(x) x
  35.  
  36. void main(void)
  37. {
  38.  
  39.  
  40.   unsigned long cofst;
  41.  char bbuf[5000], nbuf[32];
  42.   unsigned short xshort;
  43.   unsigned long xlong, xid;
  44.   long bbuflen;
  45.   int  maxsect;
  46.   char argv[2][80];
  47.   FILE *outfd, *fd;
  48.   
  49.       Initialize();
  50.     
  51. StandardGetFile(NULL,0,NULL,&reply);
  52.  
  53. strcpy(argv[1],(char *) reply.sfFile.name);
  54.   strcpy(bbuf, argv[1]);
  55.   strcat(bbuf, ".pdb");
  56.   if (!(outfd = fopen(bbuf, "w")))
  57.     exit(-1);
  58.  
  59.   strcpy(bbuf, "DBLK");
  60.   bbuf[5] = 0;
  61.   bbuf[6] = 0x10;
  62.   bbuf[7] = 0;
  63.  
  64.   memset(nbuf, 0, 32);
  65.   strncpy(nbuf, argv[1], 32);
  66.   fwrite(nbuf,1,32,outfd);
  67.  
  68.  
  69.   memset(nbuf, 0, 4);
  70.   nbuf[1] = 0x88;
  71.   nbuf[3] = 1;
  72.   fwrite( nbuf, 1,4,outfd);
  73.  
  74.   xlong = time(NULL) + ((66 * 365 + 17) * 24 * 3600UL);
  75.   xlong = htonl(xlong);
  76.   
  77.  
  78.   fwrite(&xlong,1,4,outfd);
  79.    fwrite(&xlong,1,4,outfd);
  80.     fwrite(&xlong,1,4,outfd);
  81.   
  82.   memset(nbuf, 0, 12);
  83.   fwrite(nbuf,1,12,outfd);
  84.  
  85.  
  86.   fwrite("DATA", 1,4,outfd);
  87.   fwrite( "BRWS",1, 4,outfd);
  88.  
  89.   nbuf[0] = 0x28;
  90.   fwrite(nbuf, 1,8,outfd);
  91.  
  92.   fd = fopen(argv[1],  "r");
  93.   xlong = fseek(fd, 0, SEEK_END);
  94.   fseek(fd, 0, SEEK_SET);
  95.  
  96.   maxsect = xlong / 4096 + 1;
  97.   xshort = htons(maxsect);
  98.   fwrite( &xshort, 1,2,outfd);
  99.  
  100.   cofst = 80 + 8 * maxsect;
  101.  
  102.   xid = 0x40000000UL + (rand() & 0x7fffffUL);
  103.   for (;;) {
  104.  
  105.     bbuflen = fread( &bbuf[8],1, 4096,fd);
  106.  
  107.     if (bbuflen <= 0)
  108.       break;
  109.  
  110.     xlong = htonl(cofst);
  111.   fwrite(&xlong,1,4,outfd);
  112.  
  113.     xlong = htonl(xid++);
  114.  
  115.  fwrite(&xlong,1,4,outfd);
  116.     xlong = fseek(outfd, 0, SEEK_CUR);
  117.     fseek(outfd, cofst, SEEK_SET);
  118.     fwrite(bbuf, 1,bbuflen + 8,outfd);
  119.     fseek(outfd, xlong, SEEK_SET);
  120.     cofst += bbuflen + 8;
  121.  
  122.     if (bbuflen != 4096)
  123.       break;
  124.   }
  125.  
  126.   fclose(fd);
  127.  
  128.  
  129.   xshort = 0;
  130.   fwrite( &xshort, 1,2,outfd);
  131.     fclose(outfd);
  132.  
  133. }