-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextConverter.c
More file actions
2679 lines (2404 loc) · 68.5 KB
/
TextConverter.c
File metadata and controls
2679 lines (2404 loc) · 68.5 KB
1
// ANSI includes#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <math.h>// Unix include#include <unix.h>#include <StandardFile.h>// Mac Traps includes#include <Files.h>#include <Folders.h>#include <Controls.h>#include <Windows.h>#include <Quickdraw.h>#include <BDC.h>#include <ToolUtils.h>#include <Menus.h>#include <Events.h>#include <Dialogs.h>#include <OSUtils.h>// Program defines#define NIL_POINTER 0L#define MOVE_TO_FRONT (WindowPtr)-1L#define MIN_SLEEP 0L#define NIL_MOUSE_REGION 0L#define DRAG_THRESHOLD 30#define WNE_TRAP_NUM 0x60#define UNIMPL_TRAP_NUM 0x9F#define ABOUT_ITEM 1#define NOT_A_NORMAL_MENU -1#define PIXEL_FOR_TOP_LINE 1// Global variablesFILE *into, *through, *temp, *tempPref;Boolean gDone, gWNEImplemented;char name[256], theChar, *thisSuf = ".lcf", getRefSuf[256];ControlHandle aControl, aControl2, aControl3, aControl4, aControlIs, aControlSuf, aControlChar;ControlHandle whichCtl;Cursor watchCurs;DialogPtr myDialog;EventRecord gTheEvent;FInfo fileInfoGet, fileInfoSet;Handle iHandle;int id, achar, isClosed, hasMenu = 1, whatAutoNum, whatt, whatIsCode;int is1, is2, isAutoOn, chosen, notDefYet;int gPopUpItem = 1, gPopUpLabelWidth, dialogDone;int isWin, isDos, isMac;int itemOnOff1, itemOnOff2, itemOnOff3 = 1, itemOnOff4 = 1;int rad = 1, radPre;int check1, check2, check3 = 1, check4 = 1, check1Pre, check2Pre, check3Pre, check4Pre;long theChoice, refCon, fileLengthChar, menuChoice;long macP, winP, dosP, latP, elseP;MenuHandle gAppleMenu, gFileMenu, gPopUpMenu;Point where, myPointer, pointer, myPoint, popUpUpperLeft, cPoint;Rect gPopUpRect, gLabelRect, gDragRect;Rect iRect, iRect1, iRect2, iRect3, iRect4, iRect5, iRect6, iRect7, r;SFReply reply, replyFold;SFTypeList typeList;short rc, thePart, theControl, itemHit, iType, defVRefNum, wdRefNum;Str255 fileLength, thatItemText, cursedSuf = "\p.lcf", custTypeStr, startSufStr;struct stat statRecord;WindowPtr gWindow, gWindowInfo, gWindowAuto, gWindowChar, whichWindow;// Prototypesvoid SetPrefRadioButton( DialogPtr prefDialogPtr, short buttonItemNum,Boolean setFlag );void SetPrefRadioButtonTrio( DialogPtr prefDialogPtr, short item );void SetPrefCheckBox1( DialogPtr prefDialogPtr, short buttonItemNum );void SetPrefCheckBox2( DialogPtr prefDialogPtr, short buttonItemNum );void SetPrefCheckBox3( DialogPtr prefDialogPtr, short buttonItemNum );void SetPrefCheckBox4( DialogPtr prefDialogPtr, short buttonItemNum );pascal short myDlgProc (short theItem, DialogPtr theDialog);pascal short myDlgProc ( short theItem, DialogPtr theFolderDialog ){ if ( theItem == 14 ) { rc = OpenWD( replyFold.vRefNum, CurDirStore, 0, &wdRefNum ); CloseDialog( theFolderDialog ); DoAutoFold(); rc = CloseWD( wdRefNum ); } return theItem;}/********************************************* main **********************************************/main(){ Str255 iStr; InitGraf(&thePort); // Standard Toolbox initialization InitFonts(); FlushEvents( everyEvent, 0 ); InitWindows(); TEInit(); InitDialogs(nil); InitCursor(); // if( hasMenu == 1 ) // Premiere functions MenuBarInit(); // Initializes menu bar only once! if( notDefYet == 0 ) { GetVol( 0, &defVRefNum ); // Gets the application's volume refnum GetPrefs(); // Gets preferences vars meanings from file radPre = rad; // Make temporal variables equal to prefvrs check1Pre = check1; check2Pre = check2; check3Pre = check3; check4Pre = check4; if( check2 == 1 ) { thisSuf = ""; strcat( thisSuf, getRefSuf ); } notDefYet = 1; // Do not do all above ones more } SetUpDragRect(); // whatIsCode = 0; // Give all appropriate meanings to vars hasMenu = 0; isClosed = 0; is1 = 0; typeList[0] = 'TEXT'; // if( chosen == 0 ) // Check weather to open OD at startup { if( check3 == 1 ) goto openDialog; else DoClosed(); } // openDialog: chosen = 1; if( rad == 1 ) // Weather show only 'TEXT' files SFPGetFile( where, "\p", 0, 1, typeList, 0, &reply, 1000, 0 ); if( rad == 2 ) // Weather show all file types SFPGetFile( where, "\p", 0, -1, 0, 0, &reply, 1000, 0 ); if( reply.good == TRUE ) // Is 'Convert' pressed? { rc = SetVol( 0, reply.vRefNum ); // Makes the file's volume current rc = GetFInfo( reply.fName, 0, &fileInfoGet ); // Gets file info if( rc != 0 ) // Any problem? { NumToString( rc, iStr ); ParamText( "\pAn error has just occurred. Index: ", iStr, "\p. Can't proceed", "\p" ); StopAlert( 128, 0 ); main(); } if( ( temp = fopen( "Temp", "w" ) ) == NULL ) { ParamText( "\pThis disk may be full or locked.", "\p Try copying your file to another disk", "\p", "\p" ); StopAlert( 128, 0 ); fclose( temp ); main(); } // PtoCstr( reply.fName ); // Converts Str255-str file name into C-str fprintf( temp, "%s", reply.fName ); // Writes C-str file name into file & read fclose( temp ); temp = fopen( "Temp", "r" ); fgets( name, 32, temp ); fclose( temp ); remove( "Temp" ); // if( strlen( name ) == 31 ) // Any problem? { ParamText( "\pThis file name contains 31 bytes.", "\p Sorry, but I can't edit it", "\p", "\p" ); StopAlert( 128, 0 ); main(); } // if( isAutoOn != 0 ) // Auto mode is on { if( ( strlen( name ) + strlen( thisSuf ) ) >= 32 ) { ParamText( "\pYou should change the suffix of file, ", "\pit contains more bytes than permitted", "\p", "\p" ); StopAlert( 128, 0 ); main(); } if( strlen( thisSuf ) == 0 ) { ParamText( "\pYou should define the file suffix: now it contains no bytes. ", "\pI can't convert file without suffix", "\p", "\p" ); StopAlert( 128, 0 ); DoAuto(); } } // else // Auto mode is off { // Any problem? if( ( strlen( name ) + strlen( thisSuf ) ) >= 32 ) { ParamText( "\pYou should change the suffix of file, ", "\pit contains more bytes than permitted", "\p", "\p" ); CautionAlert( 128, 0 ); WindowInit(); } } if( ( into = fopen( name, "r" ) ) == NULL ) { ParamText( "\pCan't open file you requested", "\p (-36).", 0, 0 ); StopAlert( 128, 0 ); fclose( into ); main(); } // if( isAutoOn == 0 ) // Goto main window because Auto mode off WindowInit(); // else // Automatically convert chosen file { DoWatchCurs(); switch( whatAutoNum ) { case 1: WinToMac(); break; case 2: MacToWin(); break; case 3: DosToMac(); break; case 4: MacToDos(); break; case 5: WinToDos(); break; case 6: DosToWin(); break; case 7: UnixToMac(); break; case 8: MacToUnix(); break; } } } // else // Is 'Close' pressed? DoClosed(); //}/********************************************* DoWatchCurs **********************************************/DoWatchCurs(){ CursHandle myCurs; myCurs = GetCursor( watchCursor ); watchCurs = **myCurs; SetCursor( &watchCurs );}/********************************************* WindowInit **********************************************/WindowInit() // Initialization of main window{ Rect controlRect; Rect controlRect2; Rect controlRect3; long refCon2, refCon3; gWindow = GetNewWindow( 128, NIL_POINTER, MOVE_TO_FRONT ); ShowWindow( gWindow ); SetPort( gWindow ); SetRect( &controlRect, 135, 80, 210, 100 ); aControl = NewControl( gWindow, &controlRect, "\pQuit", TRUE, 0, 0, 0, pushButProc, refCon ); SetRect( &controlRect2, 135, 5, 210, 25 ); aControl2 = NewControl( gWindow, &controlRect2, "\pOther file", TRUE, 0, 0, 0, pushButProc, refCon2 ); SetRect( &controlRect3, 135, 30, 210, 50 ); aControl3 = NewControl( gWindow, &controlRect3, "\pInfo", TRUE, 0, 0, 0, pushButProc, refCon3 ); SetRect( &controlRect3, 135, 55, 210, 75 ); aControl4 = NewControl( gWindow, &controlRect3, "\pSuffix", TRUE, 0, 0, 0, pushButProc, refCon3 ); MainLoop(); // Ready!}/********************************************* Redraw **********************************************/Redraw() // Redraw routine for main window{ MoveTo( 10, 57 ); // Continue to draw DrawText( "Choose mode...", 0, 16 ); DrawControls( gWindow ); MoveTo( 127, 0 ); // Draw separate line Line( 0, 150 ); MoveTo( 129, 0 ); Line( 0, 150 ); // SetRect( &r, 7, 43, 122, 62 ); // Draw pop-up box and its shadow FrameRect( &r ); MoveTo( 10, 62 ); LineTo( 122, 62 ); LineTo( 122, 46 ); PenSize( 1, 1 ); MoveTo( 105, 50 ); Line( 10, 0 ); Line( -5, 5 ); Line( -5, -5 ); PenSize( 1, 1 ); //}/********************************************* MainLoop **********************************************/MainLoop() // Loop all events in main window{ gDone = FALSE; gWNEImplemented = (NGetTrapAddress(WNE_TRAP_NUM, ToolTrap) != NGetTrapAddress(UNIMPL_TRAP_NUM, ToolTrap)); while(gDone == FALSE) { HandleEvent(); } //}/********************************************* HandleEvent **********************************************/HandleEvent() // What events have just occurred in main?{ int int1; int int2; int int3; if( gWNEImplemented ) // Initialize an event WaitNextEvent(everyEvent, &gTheEvent, MIN_SLEEP, NIL_MOUSE_REGION); else { SystemTask(); GetNextEvent(everyEvent, &gTheEvent); } // switch( gTheEvent.what ) // And now name event... { case nullEvent: break; case mouseDown: HandleInterface(); break; case keyDown: case autoKey: theChar = gTheEvent.message & charCodeMask; if((gTheEvent.modifiers & cmdKey) != 0) HandleMenuChoice(MenuKey(theChar)); break; case updateEvt: BeginUpdate((WindowPtr)gTheEvent.message); EndUpdate((WindowPtr)gTheEvent.message); Redraw(); break; } //}/********************************************* HandleInterface **********************************************/HandleInterface() // Where the user has clicked mouse?{ GetMouse( &pointer ); SetPt( &myPointer, pointer.h, pointer.v ); SetRect( &r, 7, 43, 122, 62 ); if( PtInRect( myPointer, &r ) == TRUE) { HandlePopUps( 7, 43, 122, 62, 128, 1 ); } else HandleMouseDown();}/********************************************* HandlePopUps **********************************************/HandlePopUps( left, top, right, bottom, myID, choice ) // Initialize, draw and check pop-ups{ PopUpMenuInit( myID ); DrawPopUp( left, top, right, bottom ); InvertRect(&gLabelRect); popUpUpperLeft.v = gPopUpRect.top + PIXEL_FOR_TOP_LINE; popUpUpperLeft.h = gPopUpRect.left; LocalToGlobal(&popUpUpperLeft); theChoice = PopUpMenuSelect(gPopUpMenu, popUpUpperLeft.v, popUpUpperLeft.h, gPopUpItem); InvertRect(&gLabelRect); if(LoWord(theChoice) > 0) { gPopUpItem = LoWord(theChoice); SetPopUpChoice( choice ); }}/********************************************* PopUpMenuInit **********************************************/PopUpMenuInit( myID ){ Handle myMenuBar; gPopUpMenu = GetMenu( myID ); InsertMenu(gPopUpMenu, NOT_A_NORMAL_MENU); gPopUpLabelWidth = StringWidth((**gPopUpMenu).menuData);}/********************************************* DrawPopUp **********************************************/DrawPopUp( left, top, right, bottom ){ SetRect( &gPopUpRect, left, top, right, bottom );}/********************************************* DoNameSufCheck **********************************************/DoNameSufCheck() // Weather suffix is fit for file name{ if( ( strlen( name ) + strlen( thisSuf ) ) >= 32 ) { CloseWindow( gWindow ); ParamText( "\pYou should change the suffix of file, ", "\pit contains more bytes than permitted", "\p", "\p" ); StopAlert( 128, 0 ); WindowInit(); } if( strlen( thisSuf ) == 0 ) { CloseWindow( gWindow ); ParamText( "\pYou should define the file suffix: now it contains no bytes. ", "\pI can't convert file without suffix", "\p", "\p" ); StopAlert( 128, 0 ); WindowInit(); }}/********************************************* SetPopUpChoice **********************************************/SetPopUpChoice( myInterfaceNum ) // What pop-up menu item is chosen?{ BackColor( 33 ); // Play with fonts and colors ForeColor( 30 ); TextFont( 2 ); TextFace( 0 ); TextSize( 17 ); // if( myInterfaceNum == 1 ) // Well... { DoNameSufCheck(); SetWTitle( gWindow, "\pNow converting file" ); DoWatchCurs(); switch( gPopUpItem ) { case 1: // First item of pop-up menu is chosen... whatt = 1; WinToMac(); break; case 2: whatt = 2; MacToWin(); break; case 4: whatt = 3; DosToMac(); break; case 5: whatt = 4; MacToDos(); break; case 7: whatt = 5; WinToDos(); break; case 8: whatt = 6; DosToWin(); break; case 10: whatt = 7; UnixToMac(); break; case 11: whatt = 8; MacToUnix(); break; } }}/********************************************* HandleMouseDown **********************************************/HandleMouseDown() // And what about mouse?{ GetMouse( &cPoint ); thePart = FindWindow(gTheEvent.where, &whichWindow); theControl = FindControl( cPoint, gWindow, &whichCtl ); switch( thePart ) { case inMenuBar: menuChoice = MenuSelect(gTheEvent.where); HandleMenuChoice(menuChoice); break; case inSysWindow: SystemClick(&gTheEvent, whichWindow); break; case inDrag: DragWindow(whichWindow, gTheEvent.where, &gDragRect); break; case inGoAway: if( TrackGoAway( gWindow, gTheEvent.where ) == TRUE ) { gDone = TRUE; } break; case inContent: break; } // if( theControl == 10 ) // User clicked one of the buttons in main? { if( TrackControl( whichCtl, cPoint, 0 ) != 0 ) { if( TrackControl( aControl, cPoint, 0 ) != 0 ) { CloseWindow( gWindow ); DoSavePrefs(); ExitToShell(); } else { if( TrackControl( aControl2, cPoint, 0 ) != 0 ) { is1 = 1; CloseWindow( gWindow ); main(); } else { if( TrackControl( aControl3, cPoint, 0 ) != 0 ) { is1 = 1; DoInfo(); } else { if( TrackControl( aControl4, cPoint, 0 ) != 0 ) { is1 = 1; DoSuffix(); } else HandleEvent(); } } } } // else // ...No! MainLoop(); // }}/********************************************* DoSuffix **********************************************/DoSuffix() // Change the current suffix{ CloseWindow( gWindow ); // Closes the main window myDialog = GetNewDialog( 132, 0, MOVE_TO_FRONT ); // Show the Suffix dialog dialogDone = FALSE; ShowWindow( myDialog ); // GetDItem( myDialog, 3, &iType, &iHandle, &iRect ); // Takes the handle of 4th item in the DLOG SetIText( iHandle, CtoPstr( thisSuf ) ); // Writes the current suffix into handle SelIText( myDialog, 3, 0, 32767 ); // Selects all the text while( dialogDone != TRUE ) { ModalDialog( 0, &itemHit ); switch( itemHit ) // What button pressed? { case 1: // If 'Ok' is pressed GetIText( iHandle, cursedSuf ); // Gets text from handle SelIText( myDialog, 3, 0, 32767 ); // Selects handle contents thisSuf = PtoCstr( cursedSuf ); // Do 'thisSuf' equivalently to cursedSuf CloseDialog( myDialog ); // Closes the dialog window WindowInit(); // Shows the main window break; } // }}/********************************************* DoInfo **********************************************/DoInfo() // Show file info to user{ int myIntErr; DisableItem( gFileMenu, 2 ); // Disables some File menu items DisableItem( gFileMenu, 3 ); DisableItem( gFileMenu, 1 ); DisableItem( gFileMenu, 5 ); DisableItem( gFileMenu, 6 ); DisableItem( gFileMenu, 7 ); DisableItem( gFileMenu, 4 ); // myIntErr = open( name, 0 ); // Opens the file with Unix-lib function fstat( myIntErr, &statRecord ); // Gets info struct for that file close( myIntErr ); // Closes the file with Unix-lib function CloseWindow( gWindow ); // Closes main window WindowInitInfo(); // Shows Info window}/********************************************* WindowInitInfo **********************************************/WindowInitInfo() // Draw the File Info window on the screen{ Rect controlRectChar; DoWatchCurs(); // Set cursor to 'watch' gWindowInfo = GetNewWindow( 129, NIL_POINTER, MOVE_TO_FRONT ); ShowWindow( gWindowInfo ); SetPort( gWindowInfo ); // ...Open Info Window SetRect( &controlRectChar, 150, 105, 270, 125 ); // Setting Chart control aControlChar = NewControl( gWindowInfo, &controlRectChar, "\pChart", TRUE, 0, 0, 0, pushButProc, refCon ); InitCursor(); // Set cursor to plain 'arrow' MainLoopInfo(); // Info event loop}/********************************************* Redraw2 **********************************************/Redraw2(){ char *forBadName; struct tm *date; char *dateChar; temp = fopen( "Temp", "w" ); // Length fprintf( temp, "%ld", statRecord.st_size ); fclose( temp ); temp = fopen( "Temp", "r" ); fscanf( temp, "%ld", &fileLengthChar ); NumToString( fileLengthChar, fileLength ); fclose( temp ); MoveTo( 10, 40 ); DrawString( "\pFile length (bytes):" ); MoveTo( 150, 40 ); ForeColor( 205 ); DrawString( fileLength ); ForeColor( 33 ); remove( "Temp" ); // date = localtime( &statRecord.st_ctime ); // Creation dateChar = asctime( date ); MoveTo( 10, 60 ); DrawString( "\pCreation date:" ); MoveTo( 150, 60 ); ForeColor( 205 ); DrawText( dateChar, 0, 24 ); ForeColor( 33 ); // date = localtime( &statRecord.st_mtime ); // Modification dateChar = asctime( date ); MoveTo( 10, 80 ); DrawString( "\pModification date:" ); MoveTo( 150, 80 ); ForeColor( 205 ); DrawText( dateChar, 0, 24 ); ForeColor( 33 ); // MoveTo( 10, 20 ); // Name DrawString( "\pFile name:" ); MoveTo( 150, 20 ); ForeColor( 205 ); forBadName = name; DrawText( forBadName, 0, strlen( forBadName ) ); ForeColor( 33 ); // MoveTo( 10, 120 ); // Creation environment DrawString( "\pFile was created in:" ); DrawControls( gWindowInfo ); // MoveTo( 10, 100 ); // Current suffix DrawString( "\pCurrent suffix:" ); MoveTo( 150, 100 ); ForeColor( redColor ); DrawString( "\p\"" ); if( strlen( thisSuf ) >= 16 ) { DrawText( thisSuf, 0, 15 ); DrawString( "\p..." ); } else DrawText( thisSuf, 0, strlen( thisSuf ) ); DrawString( "\p\"" ); if( ( strlen( name ) + strlen( thisSuf ) ) >= 32 ) { DrawString( "\p (!)" ); } else DrawString( "\p " ); if( strlen( thisSuf ) == 0 ) { DrawString( "\p (!-Null Suffix)" ); } else DrawString( "\p " ); // ForeColor( blackColor ); // Returns black color as default in GrafP}/********************************************* MainLoopInfo **********************************************/MainLoopInfo(){ gDone = FALSE; gWNEImplemented = (NGetTrapAddress(WNE_TRAP_NUM, ToolTrap) != NGetTrapAddress(UNIMPL_TRAP_NUM, ToolTrap)); while(gDone == FALSE) { HandleEventInfo(); }}/********************************************* HandleEventInfo **********************************************/HandleEventInfo(){ int int1; int int2; int int3; if(gWNEImplemented) WaitNextEvent(everyEvent, &gTheEvent, MIN_SLEEP, NIL_MOUSE_REGION); else { SystemTask(); GetNextEvent(everyEvent, &gTheEvent); } switch( gTheEvent.what ) { case nullEvent: break; case mouseDown: HandleInterfaceInfo(); break; case keyDown: case autoKey: theChar = gTheEvent.message & charCodeMask; if((gTheEvent.modifiers & cmdKey) != 0) HandleMenuChoice(MenuKey(theChar)); break; case updateEvt: BeginUpdate((WindowPtr)gTheEvent.message); EndUpdate((WindowPtr)gTheEvent.message); Redraw2(); break; }}/********************************************* HandleInterfaceInfo **********************************************/HandleInterfaceInfo(){ GetMouse( &cPoint ); thePart = FindWindow(gTheEvent.where, &whichWindow); theControl = FindControl( cPoint, gWindowInfo, &whichCtl ); switch( thePart ) { case inMenuBar: menuChoice = MenuSelect(gTheEvent.where); HandleMenuChoice(menuChoice); break; case inSysWindow: SystemClick(&gTheEvent, whichWindow); break; case inDrag: DragWindow(whichWindow, gTheEvent.where, &gDragRect); break; case inGoAway: if( TrackGoAway( gWindowInfo, gTheEvent.where ) == TRUE ) { CloseWindow( gWindowInfo ); EnableItem( gFileMenu, 3 ); EnableItem( gFileMenu, 4 ); EnableItem( gFileMenu, 5 ); WindowInit(); } break; case inContent: break; } if( theControl == 10 ) // User clicked one of the buttons in Info? { if( TrackControl( whichCtl, cPoint, 0 ) != 0 ) if( TrackControl( aControlChar, cPoint, 0 ) != 0 ) DoCharCodes(); }}/********************************************* WinToMac **********************************************/WinToMac(){ // Loading files rewind( into ); strcat( name, thisSuf ); through = fopen( name, "w" ); if( check4 == 1 ) { fileInfoSet.fdCreator = fileInfoGet.fdCreator; fileInfoSet.fdType = fileInfoGet.fdType; } else { fileInfoSet.fdCreator = 'ttxt'; fileInfoSet.fdType = 'TEXT'; } SetFInfo( CtoPstr( name ), 0, &fileInfoSet ); while( ( id = fgetc( into ) ) != EOF ) { if( ( id >= 192 ) && ( id <= 223 ) ) { achar = id - 64; fputc( achar, through ); } else { if( id == 255 ) fputc( 223, through ); else fputc( id, through ); } } fclose( into ); fclose( through ); InitCursor(); if( isAutoOn == 0 ) AtTheEnd(); else { DoAfterAfto(); main(); }}/********************************************* MacToWin **********************************************/MacToWin(){ // Loading files rewind( into ); strcat( name, thisSuf ); through = fopen( name, "wb" ); if( check4 == 1 ) { fileInfoSet.fdCreator = fileInfoGet.fdCreator; fileInfoSet.fdType = fileInfoGet.fdType; } else { fileInfoSet.fdCreator = 'ttxt'; fileInfoSet.fdType = 'TEXT'; } SetFInfo( CtoPstr( name ), 0, &fileInfoSet ); while( ( id = fgetc( into ) ) != EOF ) { if( ( id >= 128 ) && ( id <= 159 ) ) { achar = id + 64; fputc( achar, through ); } else { if( id == 223 ) fputc( 255, through ); else { if( id == 209 ) fputc( 45, through ); else fputc( id, through ); } } } fclose( into ); fclose( through ); InitCursor(); if( isAutoOn == 0 ) AtTheEnd(); else { DoAfterAfto(); main(); }}/********************************************* DosToMac **********************************************/DosToMac(){ // Loading files rewind( into ); strcat( name, thisSuf ); through = fopen( name, "w" ); if( check4 == 1 ) { fileInfoSet.fdCreator = fileInfoGet.fdCreator; fileInfoSet.fdType = fileInfoGet.fdType; } else { fileInfoSet.fdCreator = 'ttxt'; fileInfoSet.fdType = 'TEXT'; } SetFInfo( CtoPstr( name ), 0, &fileInfoSet ); while( ( id = fgetc( into ) ) != EOF ) { if( ( id >= 160 ) && ( id <= 175 ) ) { achar = id + 64; fputc( achar, through ); } else { if( ( id >= 224 ) && ( id <= 238 ) ) { achar = id + 16; fputc( achar, through ); } else { if( id == 239 ) fputc( 223, through ); else fputc( id, through ); } } } fclose( into ); fclose( through ); InitCursor(); if( isAutoOn == 0 ) AtTheEnd(); else { DoAfterAfto(); main(); }}/********************************************* MacToDos **********************************************/MacToDos(){ // Loading files rewind( into ); strcat( name, thisSuf ); through = fopen( name, "wb" ); if( check4 == 1 ) { fileInfoSet.fdCreator = fileInfoGet.fdCreator; fileInfoSet.fdType = fileInfoGet.fdType; } else { fileInfoSet.fdCreator = 'ttxt'; fileInfoSet.fdType = 'TEXT'; } SetFInfo( CtoPstr( name ), 0, &fileInfoSet ); while( ( id = fgetc( into ) ) != EOF ) { if( ( id >= 224 ) && ( id <= 239 ) ) { achar = id - 64; fputc( achar, through ); } else { if( ( id >= 240 ) && ( id <= 254 ) ) { achar = id - 16; fputc( achar, through ); } else { if( id == 223 ) fputc( 239, through ); else { if( id == 209 ) fputc( 45, through ); else fputc( id, through ); } } } } fclose( into ); fclose( through ); InitCursor(); if( isAutoOn == 0 ) AtTheEnd(); else { DoAfterAfto(); main(); }}/********************************************* DosToWin **********************************************/DosToWin(){ // Loading files rewind( into ); strcat( name, thisSuf ); through = fopen( name, "wb" ); if( check4 == 1 ) { fileInfoSet.fdCreator = fileInfoGet.fdCreator; fileInfoSet.fdType = fileInfoGet.fdType; } else { fileInfoSet.fdCreator = 'ttxt'; fileInfoSet.fdType = 'TEXT'; } SetFInfo( CtoPstr( name ), 0, &fileInfoSet ); while( ( id = fgetc( into ) ) != EOF ) { if( ( id >= 128 ) && ( id <= 159 ) ) { achar = id + 64; fputc( achar, through ); } else { if( ( id >= 160 ) && ( id <= 175 ) ) { achar = id + 64; fputc( achar, through ); } else { if( ( id >= 224 ) && ( id <= 239 ) ) { achar = id + 16; fputc( achar, through ); } else fputc( id, through ); } } } fclose( into ); fclose( through ); InitCursor(); if( isAutoOn == 0 ) AtTheEnd(); else { DoAfterAfto(); main(); }}/********************************************* WinToDos **********************************************/WinToDos(){ // Loading files rewind( into ); strcat( name, thisSuf ); through = fopen( name, "wb" ); if( check4 == 1 ) { fileInfoSet.fdCreator = fileInfoGet.fdCreator; fileInfoSet.fdType = fileInfoGet.fdType; } else { fileInfoSet.fdCreator = 'ttxt'; fileInfoSet.fdType = 'TEXT'; } SetFInfo( CtoPstr( name ), 0, &fileInfoSet ); while( ( id = fgetc( into ) ) != EOF ) { if( ( id >= 192 ) && ( id <= 223 ) ) { achar = id - 64; fputc( achar, through ); } else { if( ( id >= 224 ) && ( id <= 239 ) ) { achar = id - 64; fputc( achar, through ); } else { if( ( id >= 240 ) && ( id <= 255 ) ) { achar = id - 16; fputc( achar, through ); } else fputc( id, through ); } } } fclose( into ); fclose( through ); InitCursor(); if( isAutoOn == 0 ) AtTheEnd(); else { DoAfterAfto(); main(); }}/********************************************* UnixToMac **********************************************/UnixToMac(){ // Loading files rewind( into ); strcat( name, thisSuf ); through = fopen( name, "w" ); if( check4 == 1 ) { fileInfoSet.fdCreator = fileInfoGet.fdCreator; fileInfoSet.fdType = fileInfoGet.fdType; } else { fileInfoSet.fdCreator = 'ttxt'; fileInfoSet.fdType = 'TEXT'; } SetFInfo( CtoPstr( name ), 0, &fileInfoSet ); while( ( id = fgetc( into ) ) != EOF ) { if( ( id >= 203 ) && ( id <= 208 ) ) { achar = id + 31; fputc( achar, through ); } else if( ( id >= 210 ) && ( id <= 213 ) ) { achar = id + 30; fputc( achar, through ); } else if( ( id >= 234 ) && ( id <= 240 ) ) { achar = id - 97; fputc( achar, through ); } else if( ( id >= 242 ) && ( id <= 245 ) ) { achar = id - 98; fputc( achar, through ); } else { switch( id ) { case 193: fputc( 224, through ); break; case 194: fputc( 225, through ); break; case 215: fputc( 226, through ); break; case 199: fputc( 227, through ); break; case 196: fputc( 228, through ); break; case 197: fputc( 229, through ); break; case 214: fputc( 230, through ); break; case 218: fputc( 231, through ); break; case 201: fputc( 232, through ); break; case 198: fputc( 244, through ); break; case 200: fputc( 245, through ); break; case 195: fputc( 246, through ); break; case 222: fputc( 247, through ); break; case 219: fputc( 248, through ); break; case 221: fputc( 249, through ); break; case 223: fputc( 250, through ); break; case 217: fputc( 251, through ); break; case 216: fputc( 252, through ); break; case 220: fputc( 253, through ); break; case 192: fputc( 254, through ); break; case 209: fputc( 223, through ); break; case 225: fputc( 128, through ); break; case 226: fputc( 129, through ); break; case 247: fputc( 130, through ); break; case 231: fputc( 131, through ); break; case 228: fputc( 132, through ); break; case 229: fputc( 133, through ); break; case 246: fputc( 134, through ); break; case 250: fputc( 135, through ); break; case 233: fputc( 136, through ); break; case 230: fputc( 148, through ); break; case 232: fputc( 149, through ); break; case 227: fputc( 150, through ); break; case 254: fputc( 151, through ); break; case 251: fputc( 152, through ); break; case 253: fputc( 153, through ); break; case 255: fputc( 154, through ); break; case 249: fputc( 155, through ); break; case 248: fputc( 156, through ); break; case 252: fputc( 157, through ); break; case 224: fputc( 158, through ); break; case 241: fputc( 159, through ); break; case 145: fputc( 209, through ); break; default: fputc( id, through ); break; } } } fclose( into ); fclose( through ); InitCursor(); if( isAutoOn == 0 ) AtTheEnd(); else { DoAfterAfto(); main(); }}/********************************************* MacToUnix **********************************************/MacToUnix(){ // Loading files rewind( into ); strcat( name, thisSuf ); through = fopen( name, "wb" ); if( check4 == 1 ) { fileInfoSet.fdCreator = fileInfoGet.fdCreator; fileInfoSet.fdType = fileInfoGet.fdType; } else { fileInfoSet.fdCreator = 'ttxt'; fileInfoSet.fdType = 'TEXT'; } SetFInfo( CtoPstr( name ), 0, &fileInfoSet ); while( ( id = fgetc( into ) ) != EOF ) { if( ( id >= 234 ) && ( id <= 239 ) ) { achar = id - 31; fputc( achar, through ); } else if( ( id >= 240 ) && ( id <= 243 ) ) { achar = id - 30; fputc( achar, through ); } else if( ( id >= 137 ) && ( id <= 143 ) ) { achar = id + 97; fputc( achar, through ); } else if( ( id >= 144 ) && ( id <= 147 ) ) { achar = id + 98; fputc( achar, through ); } else { switch( id ) { case 224: fputc( 193, through ); break; case 225: fputc( 194, through ); break; case 226: fputc( 215, through ); break; case 227: fputc( 199, through ); break; case 228: fputc( 196, through ); break; case 229: fputc( 197, through ); break; case 230: fputc( 214, through ); break; case 231: fputc( 218, through ); break; case 232: fputc( 201, through ); break; case 244: fputc( 198, through ); break; case 245: fputc( 200, through ); break; case 246: fputc( 195, through ); break; case 247: fputc( 222, through ); break; case 248: fputc( 219, through ); break; case 249: fputc( 221, through ); break; case 250: fputc( 223, through ); break; case 251: fputc( 217, through ); break; case 252: fputc( 216, through ); break; case 253: fputc( 220, through ); break; case 254: fputc( 192, through ); break; case 223: fputc( 209, through ); break; case 128: fputc( 225, through ); break; case 129: fputc( 226, through ); break; case 130: fputc( 247, through ); break; case 131: fputc( 231, through ); break; case 132: fputc( 228, through ); break; case 133: fputc( 229, through ); break; case 134: fputc( 246, through ); break; case 135: fputc( 250, through ); break; case 136: fputc( 233, through ); break; case 148: fputc( 230, through ); break; case 149: fputc( 232, through ); break; case 150: fputc( 227, through ); break; case 151: fputc( 254, through ); break; case 152: fputc( 251, through ); break; case 153: fputc( 253, through ); break; case 154: fputc( 255, through ); break; case 155: fputc( 249, through ); break; case 156: fputc( 248, through ); break; case 157: fputc( 252, through ); break; case 158: fputc( 224, through ); break; case 159: fputc( 241, through ); break; case 209: fputc( 45, through ); break; default: fputc( id, through ); break; } } } fclose( into ); fclose( through ); InitCursor(); if( isAutoOn == 0 ) AtTheEnd(); else { DoAfterAfto(); main(); }}/********************************************* DoAfterAfto **********************************************/DoAfterAfto(){ char *whatDel; temp = fopen( "Temporary", "w" ); fprintf( temp, "%s", reply.fName ); fclose( temp ); temp = fopen( "Temporary", "r" ); fgets( whatDel, 256, temp ); fclose( temp ); remove( "Temporary" ); if( check1 == 1 ) remove( whatDel );}/********************************************* AtTheEnd **********************************************/AtTheEnd(){ char *whatDel; InitCursor(); CloseWindow( gWindow ); switch( whatt ) { case 1: ParamText( "\pWindows", "\pMacintosh", 0, 0 ); break; case 2: ParamText( "\pMacintosh", "\pWindows", 0, 0 ); break; case 3: ParamText( "\pDOS", "\pMacintosh", 0, 0 ); break; case 4: ParamText( "\pMacintosh", "\pDOS", 0, 0 ); break; case 5: ParamText( "\pWindows", "\pDOS", 0, 0 ); break; case 6: ParamText( "\pDOS", "\pWindows", 0, 0 ); break; case 7: ParamText( "\pUNIX", "\pMacintosh", 0, 0 ); break; case 8: ParamText( "\pMacintosh", "\pUNIX", 0, 0 ); break; } myDialog = GetNewDialog( 129, 0, MOVE_TO_FRONT ); dialogDone = FALSE; ShowWindow( myDialog ); temp = fopen( "Temporary", "w" ); fprintf( temp, "%s", reply.fName ); fclose( temp ); temp = fopen( "Temporary", "r" ); fgets( whatDel, 256, temp ); fclose( temp ); if( check1 == 1 ) remove( whatDel ); remove( "Temporary" ); while( dialogDone != TRUE ) { ModalDialog( 0, &itemHit ); switch( itemHit ) { case 1: DoSavePrefs(); ExitToShell(); break; case 2: CloseDialog( myDialog ); main(); break; } }}/********************************************* MenuBarInit **********************************************/MenuBarInit(){ Handle myMenuBar; myMenuBar = GetNewMBar(128); SetMenuBar(myMenuBar); gAppleMenu = GetMHandle(129); gFileMenu = GetMHandle(130); if( is1 == 0 ) AddResMenu(gAppleMenu, 'DRVR'); DrawMenuBar();}/********************************************* HandleMenuChoice **********************************************/HandleMenuChoice(menuChoice)long menuChoice;{ int theMenu; int theItem; if( menuChoice != 0 ) { theMenu = HiWord(menuChoice); theItem = LoWord(menuChoice); switch( theMenu ) { case 129: HandleAppleChoice(theItem); break; case 130: HandleFileChoice(theItem); break; } HilightMenu(0); }}/********************************************* HandleAppleChoice **********************************************/HandleAppleChoice(theItem)int theItem;{ Str255 accName; int accNumber; short itemNumber; DialogPtr AboutDialog; switch( theItem ) { case ABOUT_ITEM: ParamText( "\pConvertips Pro. Copyright 1997-1998 Leonid Belikov. All Rights Reserved.", "\p", "\p", "\p" ); NoteAlert( 128, 0 ); break; default: GetItem(gAppleMenu, theItem, accName); accNumber = OpenDeskAcc(accName); break; }}/********************************************* HandleFileChoice **********************************************/HandleFileChoice(theItem)int theItem;{ Str255 accName; int accNumber; short itemNumber; DialogPtr AboutDialog; switch( theItem ) { case 1: is1 = 1; chosen = 1; EnableItem( gFileMenu, 3 ); EnableItem( gFileMenu, 4 ); EnableItem( gFileMenu, 5 ); DisableItem( gFileMenu, 1 ); DisableItem( gFileMenu, 2 ); DisableItem( gFileMenu, 6 ); DisableItem( gFileMenu, 7 ); main(); break; case 2: is1 = 1; DoConvertFolder(); break; case 3: is1 = 1; CloseWindow( gWindow ); main(); break; case 4: is1 = 1; DoInfo(); break; case 5: is1 = 1; DoSuffix(); break; case 6: is1 = 1; DoAuto(); break; case 7: is1 = 1; DoPrefs(); break; case 9: DoSavePrefs(); ExitToShell(); break; }}/********************************************* DoClosed **********************************************/DoClosed(){ isClosed = 1; is1 = 0; DisableItem( gFileMenu, 3 ); DisableItem( gFileMenu, 4 ); DisableItem( gFileMenu, 5 ); EnableItem( gFileMenu, 1 ); EnableItem( gFileMenu, 2 ); EnableItem( gFileMenu, 6 ); EnableItem( gFileMenu, 7 ); gDone = FALSE; gWNEImplemented = (NGetTrapAddress(WNE_TRAP_NUM, ToolTrap) != NGetTrapAddress(UNIMPL_TRAP_NUM, ToolTrap)); while(gDone == FALSE) { HandleEventClosed(); }}/********************************************* HandleEventClosed **********************************************/HandleEventClosed(){ int int1; int int2; int int3; if(gWNEImplemented) WaitNextEvent(everyEvent, &gTheEvent, MIN_SLEEP, NIL_MOUSE_REGION); else { SystemTask(); GetNextEvent(everyEvent, &gTheEvent); } switch( gTheEvent.what ) { case nullEvent: break; case mouseDown: HandleInterfaceClosed(); break; case keyDown: case autoKey: theChar = gTheEvent.message & charCodeMask; if((gTheEvent.modifiers & cmdKey) != 0) HandleMenuChoice(MenuKey(theChar)); break; case updateEvt: BeginUpdate((WindowPtr)gTheEvent.message); EndUpdate((WindowPtr)gTheEvent.message); Redraw(); break; }}/********************************************* HandleInterfaceClosed **********************************************/HandleInterfaceClosed(){ GetMouse( &cPoint ); thePart = FindWindow(gTheEvent.where, &whichWindow); theControl = FindControl( cPoint, gWindow, &whichCtl ); switch( thePart ) { case inMenuBar: menuChoice = MenuSelect(gTheEvent.where); HandleMenuChoice(menuChoice); break; case inSysWindow: SystemClick(&gTheEvent, whichWindow); break; case inDrag: break; case inGoAway: break; case inContent: break; }}/********************************************* DoAuto **********************************************/DoAuto(){ Rect controlRectSuf; Rect controlRectIs; isClosed = 0; DisableItem( gFileMenu, 1 ); DisableItem( gFileMenu, 2 ); DisableItem( gFileMenu, 3 ); DisableItem( gFileMenu, 4 ); DisableItem( gFileMenu, 5 ); DisableItem( gFileMenu, 6 ); DisableItem( gFileMenu, 7 ); gWindowAuto = GetNewWindow( 130, NIL_POINTER, MOVE_TO_FRONT ); ShowWindow( gWindowAuto ); SetPort( gWindowAuto ); MoveTo( 10, 20 ); DrawString( "\pChoose auto mode:" ); MoveTo( 10, 40 ); DrawString( "\pSwitch:" ); MoveTo( 10, 60 ); DrawString( "\pSuffix:" ); MoveTo( 15, 80 ); ForeColor( redColor ); DrawString( "\p\"" ); if( strlen( thisSuf ) >= 10 ) { DrawText( thisSuf, 0, 9 ); DrawString( "\p..." ); } else DrawText( thisSuf, 0, strlen( thisSuf ) ); DrawString( "\p\"" ); if( strlen( thisSuf ) == 0 ) { DrawString( "\p (!-Null Suffix)" ); } else DrawString( "\p " ); ForeColor( blackColor ); SetRect( &controlRectIs, 130, 30, 270, 45 ); aControlIs = NewControl( gWindowAuto, &controlRectIs, "\pOn", TRUE, 0, 0, 1, checkBoxProc, refCon ); SetRect( &controlRectSuf, 130, 50, 200, 70 ); aControlSuf = NewControl( gWindowAuto, &controlRectSuf, "\pChange", TRUE, 0, 0, 1, pushButProc, refCon ); if( whatAutoNum != 0 ) { MoveTo( 135, 19 ); DrawString( thatItemText ); } else { MoveTo( 135, 19 ); DrawString( "\pNot chosen" ); } if( isAutoOn != 0 ) SetCtlValue( aControlIs, 1 ); else SetCtlValue( aControlIs, 0 ); SetRect( &r, 130, 5, 270, 25 ); // Draw pop-up box and its shadow FrameRect( &r ); MoveTo( 133, 25 ); LineTo( 270, 25 ); LineTo( 270, 8 ); PenSize( 1, 1 ); MoveTo( 250, 12 ); Line( 10, 0 ); Line( -5, 5 ); Line( -5, -5 ); // MainLoopAuto(); // Ready!}/********************************************* MainLoopAuto **********************************************/MainLoopAuto(){ gDone = FALSE; gWNEImplemented = (NGetTrapAddress(WNE_TRAP_NUM, ToolTrap) != NGetTrapAddress(UNIMPL_TRAP_NUM, ToolTrap)); while(gDone == FALSE) { HandleEventAuto(); }}/********************************************* HandleEventAuto **********************************************/HandleEventAuto(){ int int1; int int2; int int3; if(gWNEImplemented) WaitNextEvent(everyEvent, &gTheEvent, MIN_SLEEP, NIL_MOUSE_REGION); else { SystemTask(); GetNextEvent(everyEvent, &gTheEvent); } switch( gTheEvent.what ) { case nullEvent: break; case mouseDown: HandleInterfaceAuto(); break; case keyDown: case autoKey: theChar = gTheEvent.message & charCodeMask; if((gTheEvent.modifiers & cmdKey) != 0) HandleMenuChoice(MenuKey(theChar)); break; case updateEvt: BeginUpdate((WindowPtr)gTheEvent.message); EndUpdate((WindowPtr)gTheEvent.message); Redraw3(); break; }}/********************************************* Redraw3 **********************************************/Redraw3(){ isClosed = 0; MoveTo( 10, 20 ); DrawString( "\pChoose auto mode:" ); MoveTo( 10, 40 ); DrawString( "\pSwitch:" ); MoveTo( 10, 60 ); DrawString( "\pSuffix:" ); MoveTo( 15, 80 ); ForeColor( redColor ); DrawString( "\p\"" ); if( strlen( thisSuf ) >= 10 ) { DrawText( thisSuf, 0, 9 ); DrawString( "\p..." ); } else DrawText( thisSuf, 0, strlen( thisSuf ) ); DrawString( "\p\"" ); if( strlen( thisSuf ) == 0 ) { DrawString( "\p (!-Null Suffix)" ); } else DrawString( "\p " ); ForeColor( blackColor ); DrawControls( gWindowAuto ); if( whatAutoNum != 0 ) { MoveTo( 135, 19 ); DrawString( thatItemText ); } else { MoveTo( 135, 19 ); DrawString( "\pNot chosen" ); } if( isAutoOn != 0 ) SetCtlValue( aControlIs, 1 ); else SetCtlValue( aControlIs, 0 ); SetRect( &r, 130, 5, 270, 25 ); // Draw pop-up box and its shadow FrameRect( &r ); MoveTo( 133, 25 ); LineTo( 270, 25 ); LineTo( 270, 8 ); PenSize( 1, 1 ); MoveTo( 250, 12 ); Line( 10, 0 ); Line( -5, 5 ); Line( -5, -5 ); //}/********************************************* HandleInterfaceAuto **********************************************/HandleInterfaceAuto(){ GetMouse( &pointer ); SetPt( &myPointer, pointer.h, pointer.v ); SetRect( &r, 130, 5, 270, 25 ); if( PtInRect( myPointer, &r ) == TRUE ) HandlePopUpsAuto( 130, 5, 270, 25, 128, 1 ); else HandleMouseDownAuto();}/********************************************* HandlePopUpsAuto **********************************************/HandlePopUpsAuto( left, top, right, bottom, myID, choice ){ PopUpMenuInitAuto( myID ); DrawPopUpAuto( left, top, right, bottom ); InvertRect(&gLabelRect); popUpUpperLeft.v = gPopUpRect.top + PIXEL_FOR_TOP_LINE; popUpUpperLeft.h = gPopUpRect.left; LocalToGlobal(&popUpUpperLeft); theChoice = PopUpMenuSelect(gPopUpMenu, popUpUpperLeft.v, popUpUpperLeft.h, gPopUpItem); InvertRect(&gLabelRect); if(LoWord(theChoice) > 0) { gPopUpItem = LoWord(theChoice); SetPopUpChoiceAuto( choice ); }}/********************************************* PopUpMenuInitAuto **********************************************/PopUpMenuInitAuto( myID ){ Handle myMenuBar; gPopUpMenu = GetMenu( myID ); InsertMenu(gPopUpMenu, NOT_A_NORMAL_MENU); gPopUpLabelWidth = StringWidth((**gPopUpMenu).menuData);}/********************************************* DrawPopUpAuto **********************************************/DrawPopUpAuto( left, top, right, bottom ){ SetRect( &gPopUpRect, left, top, right, bottom );}/********************************************* SetPopUpChoiceAuto **********************************************/SetPopUpChoiceAuto( myInterfaceNum ){ Rect eraseRect; if( myInterfaceNum == 1 ) { SetRect( &eraseRect, 131, 6, 249, 24 ); EraseRect( &eraseRect ); GetItem( gPopUpMenu, gPopUpItem, thatItemText ); MoveTo( 135, 19 ); DrawString( thatItemText ); switch( gPopUpItem ) { case 1: whatAutoNum = 1; break; case 2: whatAutoNum = 2; break; case 4: whatAutoNum = 3; break; case 5: whatAutoNum = 4; break; case 7: whatAutoNum = 5; break; case 8: whatAutoNum = 6; break; case 10: whatAutoNum = 7; break; case 11: whatAutoNum = 8; break; } }}/********************************************* HandleMouseDownAuto **********************************************/HandleMouseDownAuto(){ WindowPtr whichWindow; short thePart; short i; long theChoice; Point myPoint; Point popUpUpperLeft; GetMouse( &cPoint ); thePart = FindWindow(gTheEvent.where, &whichWindow); theControl = FindControl( cPoint, gWindowAuto, &whichCtl ); switch( thePart ) { case inMenuBar: menuChoice = MenuSelect(gTheEvent.where); HandleMenuChoice(menuChoice); break; case inSysWindow: SystemClick(&gTheEvent, whichWindow); break; case inDrag: DragWindow(whichWindow, gTheEvent.where, &gDragRect); break; case inGoAway: if( TrackGoAway( gWindowAuto, gTheEvent.where ) == TRUE ) { if( isAutoOn != 0 ) { if( whatAutoNum == 0 ) { ParamText( "\pChoose the auto mode before continue...", "\p ", 0, 0 ); StopAlert( 128, 0 ); } else { EnableItem( gFileMenu, 1 ); EnableItem( gFileMenu, 2 ); EnableItem( gFileMenu, 7 ); EnableItem( gFileMenu, 6 ); CloseWindow( gWindowAuto ); DoClosed(); } } else { EnableItem( gFileMenu, 1 ); EnableItem( gFileMenu, 2 ); EnableItem( gFileMenu, 7 ); EnableItem( gFileMenu, 6 ); CloseWindow( gWindowAuto ); DoClosed(); } } break; case inContent: break; } if( theControl == 11 ) { if( TrackControl( whichCtl, cPoint, 0 ) != 0 ) { if( TrackControl( aControlIs, cPoint, 0 ) != 0 ) { if( isAutoOn == 0 ) { SetCtlValue( aControlIs, 1 ); isAutoOn = 1; } else { SetCtlValue( aControlIs, 0 ); isAutoOn = 0; } } } else MainLoopAuto(); } if( theControl == 10 ) { if( TrackControl( whichCtl, cPoint, 0 ) != 0 ) { if( TrackControl( aControlSuf, cPoint, 0 ) != 0 ) { DoSufAuto(); } } else MainLoopAuto(); }}/********************************************* DoSufAuto **********************************************/DoSufAuto(){ CloseWindow( gWindowAuto ); // Closes the Auto window myDialog = GetNewDialog( 132, 0, MOVE_TO_FRONT ); // Show the Suffix dialog dialogDone = FALSE; ShowWindow( myDialog ); // GetDItem( myDialog, 3, &iType, &iHandle, &iRect ); // Takes the handle of 4th item in the DLOG SetIText( iHandle, CtoPstr( thisSuf ) ); // Writes the current suffix into handle SelIText( myDialog, 3, 0, 32767 ); // Selects all the text while( dialogDone != TRUE ) { ModalDialog( 0, &itemHit ); switch( itemHit ) // What button pressed? { case 1: // If 'Ok' is pressed GetIText( iHandle, cursedSuf ); // Gets text from handle SelIText( myDialog, 3, 0, 32767 ); // Selects handle contents thisSuf = PtoCstr( cursedSuf ); // Do 'thisSuf' equivalently to cursedSuf CloseDialog( myDialog ); // Closes the dialog window DoAuto(); // Shows the main window break; } // }}/********************************************* SetUpDragRect **********************************************/SetUpDragRect() // What rect belongs to dragged window?{ gDragRect = screenBits.bounds; gDragRect.left += DRAG_THRESHOLD; gDragRect.right -= DRAG_THRESHOLD; gDragRect.bottom -= DRAG_THRESHOLD;}/********************************************* DoPrefs **********************************************/DoPrefs() // Open Prefs dialog and setup saved prefs{ int myFor; short iType1, iType2, iType3, iType4, iType5, iType6; Handle iPH1, iPH2, iPH3, iPH4, iPH5, iPH6; check1Pre = check1; check2Pre = check2; check3Pre = check3; check4Pre = check4; myDialog = GetNewDialog( 2000, 0, MOVE_TO_FRONT ); dialogDone = FALSE; ShowWindow( myDialog ); GetDItem( myDialog, 3, &iType1, &iPH1, &iRect1 ); GetDItem( myDialog, 4, &iType2, &iPH2, &iRect2 ); GetDItem( myDialog, 6, &iType3, &iPH3, &iRect3 ); GetDItem( myDialog, 7, &iType4, &iPH4, &iRect4 ); GetDItem( myDialog, 13, &iType5, &iPH5, &iRect5 ); GetDItem( myDialog, 14, &iType6, &iPH6, &iRect6 ); for( myFor = 1; myFor <= 2; myFor++ ) { if( rad == myFor ) SetPrefRadioButtonTrio( myDialog, ( myFor + 2 ) ); } if( check1 == 1 ) { itemOnOff1 = 1; SetCtlValue( (ControlHandle) iPH3, 1 ); } if( check2 == 1 ) { itemOnOff2 = 1; SetCtlValue( (ControlHandle) iPH4, 1 ); } if( check3 == 1 ) { itemOnOff3 = 1; SetCtlValue( (ControlHandle) iPH5, 1 ); } if( check4 == 1 ) { itemOnOff4 = 1; SetCtlValue( (ControlHandle) iPH6, 1 ); } if( check3 == 0 ) { itemOnOff3 = 0; SetCtlValue( (ControlHandle) iPH5, 0 ); } if( check4 == 0 ) { itemOnOff4 = 0; SetCtlValue( (ControlHandle) iPH6, 0 ); } while( dialogDone != TRUE ) { ModalDialog( 0, &itemHit ); switch( itemHit ) { case 1: rad = radPre; check1 = check1Pre; check2 = check2Pre; check3 = check3Pre; check4 = check4Pre; DoSavePrefs(); GetPrefs(); dialogDone = TRUE; CloseDialog( myDialog ); DoClosed(); break; case 2: radPre = rad; check1Pre = check1; check2Pre = check2; check3Pre = check3; check4Pre = check4; dialogDone = TRUE; CloseDialog( myDialog ); DoClosed(); break; case 3: SetPrefRadioButtonTrio( myDialog, 3 ); radPre = 1; break; case 4: SetPrefRadioButtonTrio( myDialog, 4 ); radPre = 2; break; case 6: itemOnOff1 += 1; SetPrefCheckBox1( myDialog, 6 ); break; case 7: itemOnOff2 += 1; SetPrefCheckBox2( myDialog, 7 ); break; case 13: itemOnOff3 += 1; SetPrefCheckBox3( myDialog, 13 ); break; case 14: itemOnOff4 += 1; SetPrefCheckBox4( myDialog, 14 ); break; } }}/********************************************* SetPrefRadioButtonTrio **********************************************/void SetPrefRadioButtonTrio( DialogPtr prefDialogPtr, short item ){ SetPrefRadioButton( prefDialogPtr, 3, (item == 3) ); SetPrefRadioButton( prefDialogPtr, 4, (item == 4) );}/********************************************* SetPrefRadioButton **********************************************/void SetPrefRadioButton( DialogPtr prefDialogPtr, short buttonItemNum, Boolean setFlag ){ short itemType; Handle itemHandle; Rect itemRect; GetDItem( prefDialogPtr, buttonItemNum, &itemType, &itemHandle, &itemRect ); SetCtlValue( (ControlHandle) itemHandle, (setFlag ? 1 : 0) );}/********************************************* SetPrefCheckBox1 **********************************************/void SetPrefCheckBox1( DialogPtr prefDialogPtr, short buttonItemNum ){ short itemType; Handle itemHandle; Rect itemRect; GetDItem( prefDialogPtr, buttonItemNum, &itemType, &itemHandle, &itemRect ); if( itemOnOff1 == 1 ) { check1Pre = 1; SetCtlValue( (ControlHandle) itemHandle, 1 ); } else { SetCtlValue( (ControlHandle) itemHandle, 0 ); check1Pre = 0; itemOnOff1 = 0; }}/********************************************* SetPrefCheckBox2 **********************************************/void SetPrefCheckBox2( DialogPtr prefDialogPtr, short buttonItemNum ){ short itemType; Handle itemHandle; Rect itemRect; GetDItem( prefDialogPtr, buttonItemNum, &itemType, &itemHandle, &itemRect ); if( itemOnOff2 == 1 ) { check2Pre = 1; SetCtlValue( (ControlHandle) itemHandle, 1 ); } else { SetCtlValue( (ControlHandle) itemHandle, 0 ); check2Pre = 0; itemOnOff2 = 0; }}/********************************************* SetPrefCheckBox3 **********************************************/void SetPrefCheckBox3( DialogPtr prefDialogPtr, short buttonItemNum ){ short itemType; Handle itemHandle; Rect itemRect; GetDItem( prefDialogPtr, buttonItemNum, &itemType, &itemHandle, &itemRect ); if( itemOnOff3 == 1 ) { check3Pre = 1; SetCtlValue( (ControlHandle) itemHandle, 1 ); } else { SetCtlValue( (ControlHandle) itemHandle, 0 ); check3Pre = 0; itemOnOff3 = 0; }}/********************************************* SetPrefCheckBox4 **********************************************/void SetPrefCheckBox4( DialogPtr prefDialogPtr, short buttonItemNum ){ short itemType; Handle itemHandle; Rect itemRect; GetDItem( prefDialogPtr, buttonItemNum, &itemType, &itemHandle, &itemRect ); if( itemOnOff4 == 1 ) { check4Pre = 1; SetCtlValue( (ControlHandle) itemHandle, 1 ); } else { SetCtlValue( (ControlHandle) itemHandle, 0 ); check4Pre = 0; itemOnOff4 = 0; }}/********************************************* DoSavePrefs **********************************************/DoSavePrefs() // Save prefs setup in prefs dialog{ FILE *tempPref; FInfo prefFInfo; short prefVRefNum; OSErr myError; prefFInfo.fdType = 'CpFL'; // Needed Finder flags' operations prefFInfo.fdCreator = 'LECP'; prefFInfo.fdFlags = 0; // myError = SetVol( 0, defVRefNum ); // Sets default volume tempPref = fopen( "Convertips Prefs", "wb" ); // Opens prefs file fprintf( tempPref, "%d%d%d%d%d%s", rad, check1, check2, check3, check4, thisSuf ); fclose( tempPref ); // Closes prefs file myError = SetFInfo( "\pConvertips Prefs", 0, &prefFInfo ); // Set Finder flags myError = SetVol( 0, reply.vRefNum ); //}/********************************************* GetPrefs **********************************************/GetPrefs() // Gets already saved preferences{ FILE *tempPref; int myFor = -1; int forgetIt; int h[4]; OSErr myError; myError = SetVol( 0, defVRefNum ); // If there's no prefs file - create it! if( ( tempPref = fopen( "Convertips Prefs", "r" ) ) == NULL ) DoSavePrefs(); else { forgetIt = fgetc( tempPref ); // Radio group rad = forgetIt - 48; forgetIt = fgetc( tempPref ); // Delete original file? check1 = forgetIt - 48; forgetIt = fgetc( tempPref ); // Current suffix is default check2 = forgetIt - 48; forgetIt = fgetc( tempPref ); // Show open dlg at startup check3 = forgetIt - 48; forgetIt = fgetc( tempPref ); // Original's flags're the converted's too check4 = forgetIt - 48; fgets( getRefSuf, 256, tempPref ); // Saved suffix fclose( tempPref ); myError = SetVol( 0, reply.vRefNum ); }}/********************************************* DoCharCodes **********************************************/DoCharCodes() // Window which shows char codes in a file{ DisableItem( gFileMenu, 2 ); // Disables some File menu items DisableItem( gFileMenu, 3 ); DisableItem( gFileMenu, 1 ); DisableItem( gFileMenu, 5 ); DisableItem( gFileMenu, 6 ); DisableItem( gFileMenu, 7 ); DisableItem( gFileMenu, 4 ); // CloseWindow( gWindowInfo ); gWindowChar = GetNewWindow( 131, NIL_POINTER, MOVE_TO_FRONT ); ShowWindow( gWindowChar ); SetPort( gWindowChar ); CountChar(); MainLoopChar();}/********************************************* CountChar **********************************************/CountChar() // Detects which char codes're in the file{ int getCharCode; int whatCharIs; winP = 0; macP = 0; dosP = 0; latP = 0; elseP = 0; while( !feof( into ) ) { getCharCode = fgetc( into ); if( ( ( getCharCode >= 192 ) && ( getCharCode <= 223 ) ) || ( getCharCode == 255 ) || ( getCharCode == 45 ) ) winP++; else { if( ( ( getCharCode >= 128 ) && ( getCharCode <= 159 ) ) || ( getCharCode == 209 ) || ( getCharCode == 223 ) ) macP++; else { if( ( ( getCharCode >= 160 ) && ( getCharCode <= 175 ) ) || ( ( getCharCode >= 224 ) && ( getCharCode <= 238 ) ) || ( getCharCode == 239 ) ) dosP++; else { if( ( ( getCharCode >= 65 ) && ( getCharCode <= 90 ) ) || ( ( getCharCode >= 97 ) && ( getCharCode <= 122 ) ) ) latP++; else elseP++; } } } } rewind( into ); while( !feof( into ) ) { whatCharIs = fgetc( into ); if( whatCharIs == 223 ) { isMac = 1; isWin = 0; isDos = 0; } else { if( whatCharIs == 160 ) { isMac = 0; isWin = 0; isDos = 1; } else { if( whatCharIs == 255 ) { isMac = 0; isWin = 1; isDos = 0; } } } } if( isMac == 1 ) whatIsCode = 1; if( isWin == 1 ) whatIsCode = 2; if( isDos == 1 ) whatIsCode = 3; isMac = 0; isWin = 0; isDos = 0; rewind( into );}/********************************************* RedrawChar **********************************************/RedrawChar() // Update event - redraw Char window{ Str255 iS; TextFace( underline | italic ); MoveTo( 100, 20 ); DrawString( "\pEach Char Code" ); MoveTo( 341, 20 ); DrawString( "\pOS" ); TextFace( 0 ); MoveTo( 10, 50 ); DrawString( "\pMac: " ); NumToString( macP, iS ); DrawString( iS ); MoveTo( 10, 70 ); DrawString( "\pWin: " ); NumToString( winP, iS ); DrawString( iS ); MoveTo( 10, 90 ); DrawString( "\pDOS: " ); NumToString( dosP, iS ); DrawString( iS ); MoveTo( 10, 110 ); DrawString( "\pLatin: " ); NumToString( latP, iS ); DrawString( iS ); MoveTo( 10, 130 ); DrawString( "\pOther: " ); NumToString( elseP, iS ); DrawString( iS ); CountPercentage( winP, 55, 70 ); CountPercentage( latP, 95, 110 ); CountPercentage( dosP, 75, 90 ); CountPercentage( macP, 35, 50 ); CountPercentage( elseP, 115, 130 ); MoveTo( 150, 55 ); Line( 0, 20 ); MoveTo( 150, 95 ); Line( 0, 20 ); MoveTo( 150, 75 ); Line( 0, 20 ); MoveTo( 150, 35 ); Line( 0, 20 ); MoveTo( 150, 115 ); Line( 0, 20 ); MoveTo( 300, 0 ); Line( 0, 160 ); MoveTo( 298, 0 ); Line( 0, 160 ); WhatCodeIsDom();}/********************************************* CountPercentage **********************************************/CountPercentage( long whatP, int v1, int v2 ) // Char in per cents{ Str255 iS; Rect chartRect; float midFloat; Pattern myPat; midFloat = ( whatP * 100 ) / fileLengthChar; SetRect( &chartRect, 150, v1, 150+floor( midFloat ), v2 ); GetIndPattern( myPat, sysPatListID, 1 ); ForeColor( blueColor ); FillRect( &chartRect, myPat ); MoveTo( 150+floor( midFloat )+5, v2-2 ); NumToString( floor( midFloat ), iS ); DrawString( iS ); DrawChar( '%' ); ForeColor( blackColor );}/********************************************* WhatCodeIsDom **********************************************/WhatCodeIsDom() // What char code is in the file?{ Rect cD1, cD2, cD3, cD4; Pattern myPat; GetIndPattern( myPat, sysPatListID, 1 ); SetRect( &cD1, 345, 40, 355, 50 ); FrameOval( &cD1 ); SetRect( &cD2, 345, 60, 355, 70 ); FrameOval( &cD2 ); SetRect( &cD3, 345, 80, 355, 90 ); FrameOval( &cD3 ); SetRect( &cD4, 345, 100, 355, 110 ); FrameOval( &cD4 ); ForeColor( redColor ); if( whatIsCode == 1 ) FillOval( &cD1, myPat ); if( whatIsCode == 2 ) FillOval( &cD2, myPat ); if( whatIsCode == 3 ) FillOval( &cD3, myPat ); if( latP != 0 ) FillOval( &cD4, myPat ); ForeColor( blackColor );}/********************************************* MainLoopChar **********************************************/MainLoopChar() // Event loop in Char window{ gDone = FALSE; gWNEImplemented = (NGetTrapAddress(WNE_TRAP_NUM, ToolTrap) != NGetTrapAddress(UNIMPL_TRAP_NUM, ToolTrap)); while(gDone == FALSE) { HandleEventChar(); }}/********************************************* HandleEventChar **********************************************/HandleEventChar(){ int int1; int int2; int int3; if(gWNEImplemented) WaitNextEvent(everyEvent, &gTheEvent, MIN_SLEEP, NIL_MOUSE_REGION); else { SystemTask(); GetNextEvent(everyEvent, &gTheEvent); } switch( gTheEvent.what ) { case nullEvent: break; case mouseDown: HandleInterfaceChar(); break; case keyDown: case autoKey: theChar = gTheEvent.message & charCodeMask; if((gTheEvent.modifiers & cmdKey) != 0) HandleMenuChoice(MenuKey(theChar)); break; case updateEvt: BeginUpdate((WindowPtr)gTheEvent.message); EndUpdate((WindowPtr)gTheEvent.message); RedrawChar(); break; }}/********************************************* HandleInterfaceChar **********************************************/HandleInterfaceChar(){ GetMouse( &cPoint ); thePart = FindWindow(gTheEvent.where, &whichWindow); switch( thePart ) { case inMenuBar: menuChoice = MenuSelect(gTheEvent.where); HandleMenuChoice(menuChoice); break; case inSysWindow: SystemClick(&gTheEvent, whichWindow); break; case inDrag: DragWindow(whichWindow, gTheEvent.where, &gDragRect); break; case inGoAway: if( TrackGoAway( gWindowChar, gTheEvent.where ) == TRUE ) { CloseWindow( gWindowChar ); WindowInitInfo(); } break; case inContent: break; }}/********************************************* DoConvertFolder **********************************************/DoConvertFolder() // Convert a folder{ typeList[0] = 'fold'; SFPGetFile( where, "\p", 0, 1, typeList, myDlgProc, &replyFold, 1001, 0 );}/********************************************* DoAutoFold **********************************************/DoAutoFold() // Do you really want to convert a folder?{ WDPBRec volRec; Str255 dirFullName; rc = SetVol( dirFullName, wdRefNum ); rc = PBHGetVol( &volRec, FALSE ); ParamText( "\p", "\p", "\p", "\p" ); myDialog = GetNewDialog( 3000, 0, MOVE_TO_FRONT ); // Show the Folder dialog dialogDone = FALSE; ShowWindow( myDialog ); // while( dialogDone != TRUE ) { ModalDialog( 0, &itemHit ); switch( itemHit ) // What button pressed? { case 1: CloseDialog( myDialog ); DoClosed(); case 2: CloseDialog( myDialog ); DoClosed(); } }}/********************************************* DoListFiles **********************************************/DoListFiles() // Takes names of all files in the folder{ FILE *temporal; temporal = fopen( "CV TempFileList", "w" ); fclose( temporal );}