home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / cshar_sl.sit < prev    next >
Encoding:
Text File  |  1988-06-20  |  8.2 KB  |  400 lines

  1. 18-Jun-88 14:42:50-MDT,8714;000000000000
  2. Return-Path: <u-lchoqu%sunset@cs.utah.edu>
  3. Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:42:38 MDT
  4. Received: by cs.utah.edu (5.54/utah-2.0-cs)
  5.     id AA22619; Sat, 18 Jun 88 14:42:32 MDT
  6. Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  7.     id AA24776; Sat, 18 Jun 88 14:42:29 MDT
  8. Date: Sat, 18 Jun 88 14:42:29 MDT
  9. From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  10. Message-Id: <8806182042.AA24776@sunset.utah.edu>
  11. To: rthum@simtel20.arpa
  12. Subject: Slide.c.shar
  13.  
  14. #! /bin/sh
  15. #
  16. # This is a shell archive.  Save this into a file, edit it
  17. # and delete all lines above this comment.  Then give this
  18. # file to sh by executing the command "sh file".  The files
  19. # will be extracted into the current directory owned by
  20. # you with default permissions.
  21. #
  22. # The files contained herein are:
  23. #
  24. #    5 Slide.c
  25. #    2 Slide.rc
  26. #    1 Makefile
  27. #
  28. echo 'Extracting Slide.c'
  29. if test -f Slide.c; then echo 'shar: will not overwrite Slide.c'; else
  30. cat << '________This_Is_The_END________' > Slide.c
  31. /* Simple slide showing program.
  32.  *
  33.  * Copyright (C) 1985, Stanford Univ. SUMEX project.
  34.  * May be used but not sold without permission.
  35.  */
  36.  
  37. /*
  38.  * history
  39.  * 02/05/85    croft    created.
  40.  */
  41.  
  42.  
  43. /*
  44.  *
  45.  * The slides that are used are MacPaint files.  Your drawing must be
  46.  * positioned in the upper left corner of the physical page image.
  47.  * The accompanying MacPaint file 'slide.blank' is a blank slide with
  48.  * tiny guide marks at the corners to show you this area.  It also
  49.  * contains a guide dot that you can use to align your first line of
  50.  * text.
  51.  *
  52.  * The slide order is determined by the file names.  Only one slide show
  53.  * can be stored per disk.  The file names have the form "NumberName",
  54.  * for example "1title", "2overview", "3goals", etc.  Only the number
  55.  * part of the file name determines the slide order.  You can use numbers
  56.  * as large as you like;  you can also use fractions to "insert" slides,
  57.  * e.g.: "1.2credits".
  58.  *
  59.  * The mouse can be used to sketch on the screen.  Spacebar advances
  60.  * to the next slide.  Backspace reverses.
  61.  */
  62.  
  63. #include "mac/quickdraw.h"
  64. #include "mac/osintf.h"
  65. #include "mac/toolintf.h"
  66.  
  67. int    pensz    =     2;
  68. GrafPort *myPort;
  69. int    wasevent,mouse;
  70. Point    p,pold;
  71. EventRecord er;
  72.  
  73. #define    NIL    0
  74.  
  75. #define    NFILES    64        /* number of files */
  76. #define    LFILES    32        /* length of file names */
  77.  
  78. char    *files;            /* pointer to array, files[NFILES][LFILES] */
  79. int    filescount;
  80. int    filesindex;
  81. VolumeParam    vp;
  82. FileParam    fp;
  83. char    fpname[LFILES];        /* output of PBGetFInfo */
  84.  
  85. main()
  86. {
  87.     struct QDVar QDVar;
  88.     GrafPort gp;
  89.  
  90.     QD = &QDVar;
  91.     InitGraf(&thePort);
  92.     InitCursor();
  93.     InitFonts();
  94.     InitWindows();
  95.     InitMenus();
  96.     TEInit();
  97.     InitDialogs((ProcPtr)NIL);
  98.     myPort = &gp;
  99.     OpenPort(myPort);
  100.     PenSize(pensz,pensz);
  101.     MoveTo(256,256);
  102.     files = NewPtr(NFILES*LFILES);
  103.     sortfiles();
  104.     showfile(0);
  105.  
  106.     for (;;) {
  107.         SystemTask();
  108.         wasevent = GetNextEvent(everyEvent, &er);
  109.         event();
  110.     }
  111. }
  112.  
  113.  
  114. event()        /* look for events */
  115. {
  116.     if (!wasevent)
  117.         goto out;
  118.     switch (er.what) {
  119.     case keyDown:
  120.     case autoKey:
  121.         switch (er.message & 0xff) {
  122.         case 'q':
  123.             ExitToShell();
  124.  
  125.         case ' ':
  126.             if (++filesindex >= filescount)
  127.                 ExitToShell();
  128.             showfile(filesindex);
  129.             break;
  130.  
  131.         case '\b':
  132.             if (--filesindex < 0)
  133.                 filesindex = 0;
  134.             showfile(filesindex);
  135.             break;
  136.                 
  137.         case 'f': pensz += 1;  goto setpen;
  138.         case 't': pensz -= 1;  goto setpen;
  139.         case 'F': pensz += 16;  goto setpen;
  140.         case 'T': pensz -= 16;  goto setpen;
  141.  
  142.         setpen:
  143.             PenSize(pensz,pensz);
  144.             break;
  145.  
  146.         case 'b':
  147.             PenPat(&QD->black);
  148.             break;
  149.  
  150.         case 'w':
  151.             PenPat(&QD->white);
  152.             break;
  153.  
  154.         case 'g':
  155.             PenPat(&QD->gray);
  156.             break;
  157.  
  158.         }
  159.         break;
  160.  
  161.     case mouseDown:
  162.         mouse = 1;
  163.         break;
  164.  
  165.     case mouseUp:
  166.         mouse = 0;
  167.         break;
  168.     }
  169. out:
  170.     GetMouse(&p);
  171.     if (!EqualPt(&p, &pold)) {
  172.         pold = p;
  173.         if (mouse)
  174.             LineTo(p.h,p.v);
  175.         else
  176.             MoveTo(p.h,p.v);
  177.     }
  178. }
  179.  
  180.  
  181. sortfiles()
  182. {
  183.     register i;
  184.     int compare();
  185.  
  186.     if (PBGetVInfo(&vp, 0) != noErr)
  187.         abort("no volinfo?");
  188.     fp.ioNamePtr = fpname;
  189.     for (i = 1 ; i <= vp.ioVNmFls ; i++) {
  190.         fp.ioFDirIndex = i;
  191.         if (PBGetFInfo(&fp, 0) != noErr)
  192.             abort("getfinfo error");
  193.         if (strncmp((char *)&fp.ioFlFndrInfo.fdType, "PNTG", 4) !=0 )
  194.             continue;
  195.         if (fpname[0] <= 0 || fpname[1] < '0' || fpname[1] > '9')
  196.             continue;
  197.         fpname[fpname[0]+1] = 0;
  198.         BlockMove(fpname, &files[LFILES*(filescount++)], LFILES);
  199.     }
  200.     if (filescount <= 0)
  201.         abort("can't find any numbered MacPaint files");
  202.     qsort(files, filescount, LFILES, compare);
  203. }
  204.  
  205.  
  206. convert(s)
  207.     char *s;
  208. {
  209.     register char *cp;
  210.     register i, w, sawfrac;
  211.  
  212.     i = w = sawfrac = 0;
  213.     for (cp = s + 1 ; *cp ; cp++) {
  214.         if (*cp == '.') {
  215.             w = i;
  216.             i = 0;
  217.             sawfrac++;
  218.             continue;
  219.         }
  220.         if (*cp < '0' || *cp > '9')
  221.             break;
  222.         i = (i * 10) + (*cp - '0');
  223.     }
  224.     if (sawfrac)
  225.         return ((w<<16) | i);
  226.     else
  227.         return (i<<16);
  228. }
  229.  
  230.  
  231. compare(a,b)
  232.     char *a,*b;
  233. {
  234.     int an,bn;
  235.  
  236.     an = convert(a);
  237.     bn = convert(b);
  238.     if (an == bn)
  239.         return (0);
  240.     if (an > bn)
  241.         return (1);
  242.     else
  243.         return (-1);
  244. }
  245.  
  246.  
  247. #define    srcBlocks    2
  248. #define    srcSize        512*srcBlocks
  249.  
  250. #define    SCREEN    0x7A700
  251. #define    SWIDE    512
  252. #define    SHI    342
  253. #define    PWIDE    576        /* MacPaint width */
  254.  
  255. showfile(i)
  256. {
  257.     char srcBuf[srcSize];
  258.     char lineBuf[PWIDE/8];
  259.     char *srcPtr,*dstPtr,*linePtr;
  260.     int rn, count;
  261.  
  262.     if (FSOpen(&files[i*LFILES+1], 0, &rn) != noErr)
  263.         abort("fsopen");
  264.     count = 512;
  265.     FSRead(rn, &count, srcBuf);    /* skip header */
  266.     count = srcSize;
  267.     FSRead(rn, &count, srcBuf);    /* prime buffer */
  268.     srcPtr = srcBuf;
  269.     HideCursor();
  270.     dstPtr = (char *)SCREEN;
  271.     for (i = 0 ; i < SHI-1 ; i++) {    /* read 341 lines */
  272.         linePtr = lineBuf;
  273.         UnPackBits(&srcPtr, &linePtr, PWIDE/8);
  274.         BlockMove(lineBuf, dstPtr, SWIDE/8);
  275.         dstPtr += (SWIDE/8);
  276.         if (srcPtr > (srcBuf + srcSize - 512)) {
  277.             BlockMove(&srcBuf[srcSize-512], &srcBuf[0], 512);
  278.             count = srcSize-512;
  279.             FSRead(rn, &count, &srcBuf[512]);
  280.             srcPtr = srcPtr - srcSize + 512;
  281.         }
  282.     }
  283.     FSClose(rn);
  284.     ShowCursor();
  285. }
  286.  
  287.  
  288. abort(s)
  289.     char *s;
  290. {
  291.     ParamText(s, "", "", "");
  292.     StopAlert(257, (ProcPtr)NIL);
  293.     ExitToShell();
  294. }
  295. ________This_Is_The_END________
  296. if test `wc -l < Slide.c` -ne 264; then
  297.     echo 'shar: Slide.c was damaged during transit'
  298.   echo '      (should have been 264 bytes)'
  299. fi
  300. fi        ; : end of overwriting check
  301. echo 'Extracting Slide.rc'
  302. if test -f Slide.rc; then echo 'shar: will not overwrite Slide.rc'; else
  303. cat << '________This_Is_The_END________' > Slide.rc
  304. * input for resource compiler
  305. *
  306.  
  307. slide.rsrc
  308.  
  309. Type CCOM = STR
  310.   ,0
  311. Slide Version 1.0 -- Feb 85
  312.  
  313. Type ICN# = HEXA
  314.   ,128(32)
  315. * little picture of the C
  316. 00000e00 00001000 00001000 00001000 00000e00 00e00000 1fbe001e f003f0e0
  317. 80001f80 00000000 00000000 00008000 0300803e 3cf0c3c0 c01ce000 0000f000
  318. 0000f800 00008000 0003fc00 0001f800 3fc0000e e0780078 000fffc0 00000000
  319. 00000000 00000000 1fc0007e 303c03c0 e007fe00 00000000 00000000 00000000
  320. * mask
  321. ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
  322. ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
  323. ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
  324. ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
  325.  
  326. Type FREF = HEXA
  327.   ,128(32)
  328. * APPL uses loc icon 0, no tagalongs
  329. 4150504c
  330. 0000
  331. 00
  332.  
  333. Type BNDL = HEXA
  334.   ,128(32)
  335. * owner CCOM 0
  336. 43434F4D0000
  337. * 2 types
  338. 0001
  339. * ICN#, 1 entry, loc 0 to glob 128
  340. 49434e230000
  341.  
  342. Type ALRT
  343.   ,257
  344.   60 81 180 431
  345.   258
  346.   5555
  347.  
  348. * DITL for the ALRT
  349. * First the ID (DITL,258), then the number of items which follow.
  350.  
  351. Type DITL
  352.  ,258
  353.   2
  354. * These buttons are 20 hi by 70 wide
  355.     BtnItem Enabled
  356.     90 13 110 83
  357. Abort
  358.  
  359.     StatText Disabled
  360.     10 60 70 350
  361. ^0^1^2^3
  362.  
  363. Type CODE
  364.   b.out,0
  365. ________This_Is_The_END________
  366. if test `wc -l < Slide.rc` -ne 61; then
  367.     echo 'shar: Slide.rc was damaged during transit'
  368.   echo '      (should have been 61 bytes)'
  369. fi
  370. fi        ; : end of overwriting check
  371. echo 'Extracting Makefile'
  372. if test -f Makefile; then echo 'shar: will not overwrite Makefile'; else
  373. cat << '________This_Is_The_END________' > Makefile
  374.  .SUFFIXES: .rsrc .b
  375.  
  376.  .c.b:
  377.     cc68 -z -c $<
  378.  
  379.  .s.b:
  380.     cc68 -c $<
  381.  
  382.  .b.rsrc:
  383.     cc68 -z -m $<
  384.     rmaker $*.rc
  385. #    tohex <$*.rsrc >$*.dl
  386.  
  387. all:    slide.rsrc
  388.  
  389. slide.rsrc: slide.b slide.rc
  390.  
  391. clean:
  392.     rm *.b *.rsrc b.out *.dl
  393. ________This_Is_The_END________
  394. if test `wc -l < Makefile` -ne 19; then
  395.     echo 'shar: Makefile was damaged during transit'
  396.   echo '      (should have been 19 bytes)'
  397. fi
  398. fi        ; : end of overwriting check
  399. exit 0
  400.