home *** CD-ROM | disk | FTP | other *** search
- 18-Jun-88 14:47:49-MDT,5021;000000000000
- Return-Path: <u-lchoqu%sunset@cs.utah.edu>
- Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:47:43 MDT
- Received: by cs.utah.edu (5.54/utah-2.0-cs)
- id AA22714; Sat, 18 Jun 88 14:47:46 MDT
- Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
- id AA24839; Sat, 18 Jun 88 14:47:43 MDT
- Date: Sat, 18 Jun 88 14:47:43 MDT
- From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
- Message-Id: <8806182047.AA24839@sunset.utah.edu>
- To: rthum@simtel20.arpa
- Subject: append.c
-
- /* append.c -- by Mark^Zimmermann, 19871019-....
- *
- * This little effort lets you append chosen text files together ...
- * pick the first file, and then subsequent choices from the
- * StdFiles dialog are tacked onto the end of it ... designed
- * to help save time and space relative to DivJoin, etc. programs
- * which copy all files as they are joined together.
- *
- * Written in Lightspeed C ...
- * Please send improvements and suggestions to me:
- * science(at)NEMS.ARPA;
- * [75066,2044] on CompuServe;
- * Mark^Zimmermann, 9511 Gwyndale Dr., Silver Spring, MD 20910, USA;
- * telephone 301-565-2166.
- *
- * Thank you! ^z
- */
-
- /* I don't know if all of these #includes are necessary.... */
-
- #include <QuickDraw.h>
- #include <MacTypes.h>
- #include <FontMgr.h>
- #include <WindowMgr.h>
- #include <MenuMgr.h>
- #include <TextEdit.h>
- #include <DialogMgr.h>
- #include <EventMgr.h>
- #include <DeskMgr.h>
- #include <FileMgr.h>
- #include <ToolboxUtil.h>
- #include <ControlMgr.h>
- #include "StdFilePkg.h"
-
- /* prototypes for my functions ... I do love prototypes! */
-
- void main (void);
- void appendFile (int refNum0, Str255 *fnX, int vRefX);
- int GetFileZ (Str255 *fn, int *vRef);
- void pStrCopy (char *p1, char *p2);
- void giveUp (void);
-
- /* set up buffer of size 25,600 bytes (= 512 * 50) for copying through;
- * ZBUFSIZ must be an integer, < 32768
- */
- #define ZBUFSIZ 25600
-
- char buf[ZBUFSIZ];
-
- /* set up a little window to give info to the user...very static
- */
- WindowRecord w_record;
- WindowPtr info_window;
- Str255 string;
-
- /* main routine to initialize everything under the sun (is all this
- * really necessary?) and then get the names of the files to join ... if
- * they open ok, start joining them, and quit when the user chooses
- * "Cancel"....
- */
-
- void main()
- {
- Str255 fn0, fnX;
- int vRef0, vRefX, refNum0, i;
-
- InitGraf (&thePort);
- InitFonts ();
- FlushEvents (everyEvent, 0);
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs (0L);
- InitCursor ();
- MaxApplZone ();
-
- info_window = GetNewWindow (128, &w_record, (WindowPtr) - 1L);
- ShowWindow (info_window);
- SetPort (info_window);
- TextFont (0);
- for (i = 1; i <= 3; ++i)
- {
- MoveTo (4, 15 * i - 5);
- GetIndString (&string, 128, i);
- DrawString (&string);
- }
-
- if (GetFileZ (&fn0, &vRef0))
- {
- if (FSOpen (&fn0, vRef0, &refNum0) != noErr)
- giveUp ();
- while (GetFileZ (&fnX, &vRefX))
- appendFile (refNum0, &fnX, vRefX);
- FSClose (refNum0);
- }
- }
-
-
- /* routine to append the contents of file X to file 0....
- */
-
- void appendFile (refNum0, fnXp, vRefX)
- int refNum0, vRefX;
- Str255 *fnXp;
- {
- int refNumX, err;
- long count;
-
- if (FSOpen (fnXp, vRefX, &refNumX) != noErr)
- giveUp ();
- if (SetFPos (refNumX, fsFromStart, 0L) != noErr)
- giveUp ();
- if (SetFPos (refNum0, fsFromLEOF, 0L) != noErr)
- giveUp ();
- for (;;)
- {
- count = ZBUFSIZ;
- err = FSRead (refNumX, &count, buf);
- if (err != noErr && err != eofErr)
- giveUp ();
- if (count == 0)
- break;
- if (FSWrite (refNum0, &count, buf) != noErr)
- giveUp ();
- }
- FSClose (refNumX);
- return;
- }
-
-
- /* following variables and routine do the standard files dialog
- * to get the name of the file use ... cribbed from the MiniEdit
- * example that comes with LSC....
- */
-
- static Point SFGwhere = { 90, 82 };
- static SFReply reply;
-
- int GetFileZ (fnp, vRefp)
- Str255 *fnp;
- int *vRefp;
- {
- SFTypeList myTypes;
-
- myTypes[0]='TEXT';
- SFGetFile( SFGwhere, "\p", 0L, 1, myTypes, 0L, &reply);
- if (reply.good)
- {
- pStrCopy( (char *)reply.fName, (char *)fnp);
- *vRefp = reply.vRefNum;
- return(1);
- }
- else return(0);
- }
-
-
- /* routine to copy a pascal string from one place to another.... used in
- * above Standard Files routine....
- */
-
- void pStrCopy( p1, p2 )
- register char *p1, *p2;
- {
- register int len;
-
- len = *p2++ = *p1++;
- while (--len>=0)
- *p2++=*p1++;
- return;
- }
-
-
-
- /* routine to give up with a beep if an error occurs during opening the
- * file or fixing it....
- */
-
- void giveUp ()
- {
- SysBeep (10);
- ExitToShell ();
- }
-
- ==========
- append 9.rsrc
- ????CTLZ
-
-
- TYPE WIND
- ,128
- Information
- 30 12 72 500
- Visible NoGoAway
- 1
- 0
-
-
- TYPE STR#
- ,128
- 3
- Greetings, Program! Welcome to 'Append' by Mark^Zimmermann.
- Pick a text file, then choose others to be appended to the end of it...
- Choose 'Cancel' to quit. v.1 - 19871019
-
-
- ==========
-