home *** CD-ROM | disk | FTP | other *** search
- #include "LPR.H"
- #include "lprProtos.H"
- #include <Traps.H>
- #include "TCPStream.H"
-
-
- Boolean TrapAvailable(LongWord trap);
- void ReadPreferences(void);
- void WritePreferences(void);
-
- void Fatal(integer errNo);
- void GetParameters(void);
-
- integer EnumerateFiles(integer wdRef, integer *anIndex, AppFile *file);
-
- static Boolean init_it = FALSE;
-
-
- /************************************************************************
- ************************************************************************/
- void Initialise()
- {
- integer i;
- WindowPtr WhichWindow;
- SysEnvRec envir;
-
- MaxApplZone();
-
- for (i = 0; i < 16; i++)
- MoreMasters();
-
- ShowCursor();
- InitGraf((Ptr)&thePort);
- ShowCursor();
- InitFonts();
- ShowCursor();
- FlushEvents(everyEvent, 0);
- ShowCursor();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs((ProcPtr) NIL);
-
- haveWaitEvnt = TrapAvailable(_WaitNextEvent);
- SysEnvirons(1, &envir); /* look for at least 128K ROMS */
- if (envir.machineType < 0) Fatal(eWrongROM);
-
- cursRgn = NewRgn();
-
- InitCursor();
- ShowCursor();
- GetWMgrPort(&WhichWindow);
- SetPort(WhichWindow);
- screenRect = WhichWindow->portRect;
- RectRgn(cursRgn, &screenRect);
- screenRect.top += MBarHeight;
-
- ShowCursor();
-
- ReadPreferences();
-
- GetParameters();
-
- ExitToShell();
- }
-
-
- static Boolean textFlag, folderFlag;
- static integer wdRefNum;
-
-
- /************************************************************************
- ************************************************************************/
- pascal integer dlgHook(integer item, DialogPtr dial);
- pascal integer dlgHook(integer item, DialogPtr dial)
- {
- switch (item)
- {
- case 11 :
- item = 1;
- folderFlag = TRUE;
- break;
- case 12 :
- ToggleDialCtlVal(dial, item);
- textFlag = GetDialCtlVal(dial, item);
- item = 101;
- break;
- }
- return item;
- }
-
-
- /************************************************************************
- ************************************************************************/
- pascal Boolean fileFilter(ParmBlkPtr file);
- pascal Boolean fileFilter(ParmBlkPtr file)
- {
- wdRefNum = file->fileParam.ioVRefNum;
-
- if (file->fileParam.ioFlAttrib & 0x10)
- return TRUE;
-
- if (textFlag && (file->fileParam.ioFlFndrInfo.fdType != 'TEXT'))
- return TRUE;
-
- return FALSE; /* show this file */
- }
-
-
-
- /************************************************************************
- in SegLoad.H
-
- struct AppFile {
- short vRefNum;
- OSType fType;
- short versNum; //versNum in high byte
- Str255 fName;
- };
-
- typedef struct AppFile AppFile;
- ************************************************************************/
- static void GetParameters()
- {
- integer count, message, i, index = 1;
- AppFile aFile;
- SFReply reply;
- Boolean sfd = FALSE;
- Point where = { 80, 80 };
- SFTypeList types;
-
- CountAppFiles(&message, &count);
-
- if (!count)
- {
- textFlag = FALSE;
- folderFlag = FALSE;
- SFPGetFile(where,
- "\pSelect Files To Print :",
- fileFilter /* file filter */,
- 0,
- types,
- dlgHook /* dlgHook */,
- &reply,
- 130,
- NIL /* filterProc */ );
-
- sfd = TRUE;
- if (!reply.good)
- Fatal(eNoFiles);
-
- BlockMove(reply.fName, aFile.fName, reply.fName[0]+1);
- aFile.vRefNum = reply.vRefNum;
- aFile.fType = reply.fType;
- count = 1;
- }
-
- doAbout(init_it);
-
- if (!sfd)
- GetAppFiles(1, &aFile);
- else if (folderFlag && EnumerateFiles(reply.vRefNum, &index, &aFile) == 0)
- Fatal(eNoFiles);
-
- if ( StartJob(aFile.fName) ) /* setup failed */
- {
- SysBeep(5);
- ExitTCPS();
- SysBeep(5);
- Exit();
- }
-
- if (!sfd)
- {
- for (i = 1; i <= count; i++)
- {
- GetAppFiles(i, &aFile);
-
- if ( LPR(aFile.fName, aFile.vRefNum, aFile.fType == 'TEXT') )
- {
- SysBeep(5);
- EndJob();
- return; /* something went wrong, drop out now */
- }
- }
- }
- else if (folderFlag)
- {
- index = 1;
- while (EnumerateFiles(reply.vRefNum, &index, &aFile) != 0)
- {
- if ( LPR(aFile.fName, aFile.vRefNum, aFile.fType == 'TEXT') )
- {
- SysBeep(5);
- EndJob();
- return; /* something went wrong, drop out now */
- }
- }
- }
- else
- {
- if ( LPR(aFile.fName, aFile.vRefNum, aFile.fType == 'TEXT') )
- {
- SysBeep(5);
- EndJob();
- return; /* something went wrong, drop out now */
- }
- }
-
- SendCtlFile();
- EndJob();
- }
-
- /************************************************************************
- ************************************************************************/
- /* Used whenever a fatal error happens */
- static void Fatal(integer error)
- {
- AlertUser(error);
- ExitToShell();
- }
-
- /************************************************************************
- ************************************************************************/
- static StringPtr PrefsName = "\pLPR_Prefs";
-
- /************************************************************************
- ************************************************************************/
- void ReadPreferences()
- {
- integer wdRef, rRef;
- LongInt wdID;
- integer vol;
- Handle tmpH, versH;
- integer *tmp, id;
- ResType type;
-
-
- /* now read the prefs file */
- GetWDir(&wdRef, &wdID, &vol);
- SetPrefsFolder();
-
- /* we are in the preferences folder */
- if ((rRef = OpenResFile((StringPtr)PrefsName)) == -1)
- {
- init_it = TRUE;
- WritePreferences();
- }
- else
- {
- if (tmpH = GetResource('Pref', 0))
- {
- HLock(tmpH);
- tmp = (integer*)(*tmpH);
- job_number = tmp[0];
- HUnlock(tmpH);
- }
- else
- init_it = TRUE;
-
- if (tmpH = GetResource('STR ', 256))
- {
- HLock(tmpH);
- BlockMove((StringPtr)*tmpH, my_user, GetHandleSize(tmpH));
- HUnlock(tmpH);
- }
- else if ( tmpH = GetResource('STR ', -16096) )
- { /* get chooser name */
- HLock(tmpH);
- BlockMove((StringPtr)*tmpH, my_user, GetHandleSize(tmpH));
- HUnlock(tmpH);
- ReleaseResource(tmpH);
- init_it = TRUE;
- }
- else
- {
- init_it = TRUE;
- my_user[0] = 0;
- }
-
- if (tmpH = GetResource('STR ', 257))
- {
- HLock(tmpH);
- BlockMove((StringPtr)*tmpH, my_host, GetHandleSize(tmpH));
- HUnlock(tmpH);
- }
- else
- {
- init_it = TRUE;
- my_host[0] = 0;
- }
-
- if (tmpH = GetResource('STR ', 258))
- {
- HLock(tmpH);
- BlockMove((StringPtr)*tmpH, prt_name, GetHandleSize(tmpH));
- HUnlock(tmpH);
- }
- else
- {
- init_it = TRUE;
- BlockMove("\plp", prt_name, 3);
- }
-
- if (tmpH = GetResource('STR ', 259))
- {
- HLock(tmpH);
- BlockMove((StringPtr)*tmpH, prt_server, GetHandleSize(tmpH));
- HUnlock(tmpH);
- }
- else
- {
- init_it = TRUE;
- prt_server[0] = 0;
- }
-
- CloseResFile(rRef);
- WritePreferences(); /* updated values */
- }
-
- SetWDir(wdRef, wdID, vol);
-
- }
-
-
- /************************************************************************
- ************************************************************************/
- void WritePreferences()
- {
- integer wdRef, rRef;
- LongInt wdID;
- integer vol;
- Handle tmpH, versH;
- integer *tmp, id;
-
- /* now read the prefs file */
- GetWDir(&wdRef, &wdID, &vol);
- SetPrefsFolder();
-
- /* we are in the preferences folder */
- if ((rRef = OpenResFile((StringPtr)PrefsName)) == -1)
- {
- Create((StringPtr)PrefsName, 0, 'Lpr ', 'Pref');
- CreateResFile((StringPtr)PrefsName);
- if ( (rRef = OpenResFile((StringPtr)PrefsName)) != -1 )
- AddResource(NewHandle(0), 'Pref', 0, NIL);
- }
- if (rRef != -1)
- {
- tmpH = GetResource('Pref', 0); /* the screen prefs */
- if (!tmpH)
- AddResource(tmpH = NewHandle(0), 'Pref', 0, NIL);
- if (tmpH)
- {
- if ( GetHandleSize(tmpH) < (2*sizeof(integer)) )
- SetHandleSize(tmpH, 2*sizeof(integer));
- HLock(tmpH);
- tmp = (integer*)(*tmpH);
- tmp[0] = job_number+1;
- HUnlock(tmpH);
- ChangedResource(tmpH);
- WriteResource(tmpH);
- }
-
- tmpH = GetResource('STR ', 256);
- if (!tmpH)
- AddResource(tmpH = NewHandle(0), 'STR ', 256, NIL);
- if (tmpH)
- {
- SetHandleSize(tmpH, my_user[0]+1);
- HLock(tmpH);
- BlockMove(my_user, *tmpH, my_user[0]+1);
- HUnlock(tmpH);
- ChangedResource(tmpH);
- WriteResource(tmpH);
- }
-
- tmpH = GetResource('STR ', 257);
- if (!tmpH)
- AddResource(tmpH = NewHandle(0), 'STR ', 257, NIL);
- if (tmpH)
- {
- SetHandleSize(tmpH, my_host[0]+1);
- HLock(tmpH);
- BlockMove(my_host, *tmpH, my_host[0]+1);
- HUnlock(tmpH);
- ChangedResource(tmpH);
- WriteResource(tmpH);
- }
-
- tmpH = GetResource('STR ', 258);
- if (!tmpH)
- AddResource(tmpH = NewHandle(0), 'STR ', 258, NIL);
- if (tmpH)
- {
- SetHandleSize(tmpH, prt_name[0]+1);
- HLock(tmpH);
- BlockMove(prt_name, *tmpH, prt_name[0]+1);
- HUnlock(tmpH);
- ChangedResource(tmpH);
- WriteResource(tmpH);
- }
-
- tmpH = GetResource('STR ', 259);
- if (!tmpH)
- AddResource(tmpH = NewHandle(0), 'STR ', 259, NIL);
- if (tmpH)
- {
- SetHandleSize(tmpH, prt_server[0]+1);
- HLock(tmpH);
- BlockMove(prt_server, *tmpH, prt_server[0]+1);
- HUnlock(tmpH);
- ChangedResource(tmpH);
- WriteResource(tmpH);
- }
-
- CloseResFile(rRef);
- }
-
- SetWDir(wdRef, wdID, vol);
- }
-
- /************************************************************************
- ************************************************************************/
- integer EnumerateFiles(integer wdRef, integer *anIndex, AppFile *file)
- {
- CInfoPBRec myCIPB;
- integer retVal = FALSE, osVal, fRef,
- index = 1;
-
- if (anIndex) index = *anIndex;
-
- myCIPB.dirInfo.ioVRefNum = wdRef;
- myCIPB.dirInfo.ioNamePtr = file->fName;
- myCIPB.dirInfo.ioFDirIndex = index++;
- myCIPB.dirInfo.ioDrDirID = 0;
- file->fName[0]=0;
-
- /* get info about object with this name */
- while ( ! PBGetCatInfo(&myCIPB, FALSE) )
- {
- if ( !(myCIPB.dirInfo.ioFlAttrib & 0x10) )
- { /* it's not a directory */
- if (anIndex) *anIndex = index;
- file->vRefNum = wdRef;
- file->fType = myCIPB.hFileInfo.ioFlFndrInfo.fdType;
- file->versNum = myCIPB.hFileInfo.ioFVersNum << 8; /*versNum in high byte*/
-
- if (textFlag)
- {
- if (myCIPB.hFileInfo.ioFlFndrInfo.fdType == 'TEXT')
- return -1;
- }
- else
- return -1;
- }
-
- myCIPB.dirInfo.ioFDirIndex = index++;
- myCIPB.dirInfo.ioDrDirID = 0;
- file->fName[0] = 0;
- }
-
- return 0;
- }
-