-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEANConstruct.c
1560 lines (1484 loc) · 30.9 KB
/
EANConstruct.c
1
#include <stdio.h> // Includes#include <stdlib.h>#include <string.h>#include <math.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 <Devices.h>#include <OSUtils.h> //#define NIL_POINTER 0L // Defines - constantes#define MOVE_TO_FRONT (WindowPtr)-1L#define REMOVE_ALL_EVENTS 0#define NIL_SOUND_CHANNEL 0L#define MIN_SLEEP 0L#define NIL_MOUSE_REGION 0L#define DRAG_THRESHOLD 30#define WNE_TRAP_NUM 0x60#define WNE_TRAP_NUM 0x60#define UNIMPL_TRAP_NUM 0x9F#define QUIT_ITEM 5#define ABOUT_ITEM 1#define MYMSG_RSCID 128#define DRAG_THRESHOLD 30#define TOP 25#define LEFT 12#define ABOUT_ITEM_ID 1#define NOT_A_NORMAL_MENU -1#define POPUP_LEFT 100#define POPUP_TOP 35#define POPUP_RIGHT 125#define POPUP_BOTTOM 52#define PIXEL_FOR_TOP_LINE 1 // // Variables of my applicationBoolean gDone, gWNEImplemented, dialogDone, aboutDialogDone; EventRecord gTheEvent;DialogPtr myDialog, aboutDialog;short iType, itemHit, aItemHit;Handle iHandle;Rect iRect;Str255 getNum;FILE *save, *buf;char *buffer;int num;WindowPtr gWindow;int storeNum[128], storeSign[128], i, numGet;int gT, whatNum=1, por, x, country, controlDigit, licence=0, whatEAN, eanA[12];Point cPoint;short thePart;WindowPtr whichWindow;Rect gDragRect; ///******************************************** main *****************************************/main() // Standard C/C++ main()-routine{ // At the beginning InitGraf(&thePort); // Standard Toolbox initialization InitFonts(); FlushEvents( everyEvent, 0 ); InitWindows(); TEInit(); InitDialogs(nil); InitCursor(); // SetUpDragRect(); // Sets the drag rect of main window ShowMyDialog(); // Shows the number-dialog WindowInit(); // Draws main window MainLoop(); // Event loop of main window}/**************************************** ShowMyDialog ************************************/ShowMyDialog() // Show dialog for entering EAN number{ myDialog = GetNewDialog( 128, 0, MOVE_TO_FRONT ); dialogDone = FALSE; ShowWindow( myDialog ); GetDItem( myDialog, 3, &iType, &iHandle, &iRect ); while( dialogDone != TRUE ) { ModalDialog( 0, &itemHit ); switch( itemHit ) { case 1: GetIText( iHandle, getNum ); save = fopen( "EAN Save", "w" ); fprintf( save, "%s", PtoCstr( getNum ) ); fclose( save ); CloseDialog( myDialog ); WindowInit(); break; case 2: ExitToShell(); break; case 5: DoAbout(); break; } }}/************************************** DoAbout **************************************/DoAbout(){ aboutDialog = GetNewDialog( 1000, 0, MOVE_TO_FRONT ); aboutDialogDone = FALSE; ShowWindow( aboutDialog ); while( aboutDialogDone != TRUE ) { ModalDialog( 0, &aItemHit ); switch( aItemHit ) { case 1: CloseDialog( aboutDialog ); aboutDialogDone = TRUE; break; } }}/***************************************** WindowInit *****************************************/WindowInit() // Here I say machine to draw window, etc.{ char *storeStr; whatEAN = 0; storeStr = '\0'; save = fopen( "EAN Save", "r" ); fscanf( save, "%s", storeStr ); rewind( save ); if( strlen( storeStr ) == 12 ) whatEAN = 1; else { if( strlen( storeStr ) == 13 ) whatEAN = 2; else { if( strlen( storeStr ) == 8 ) { numGet = getc( save ); storeSign[1] = numGet; storeNum[1] = numGet - 48; rewind( save ); if( storeNum[1] >= 3 ) whatEAN = 3; else { if( storeNum[1] == 0 ) whatEAN = 4; else { ParamText( "\pFor EAN-E, first digit cannot be smaller than 3. ", "\pFor EAN-EM, first digit should only be zero. ", "\pCheck your number", "\p" ); StopAlert( 129, 0 ); main(); } } } else { ParamText( "\pUnknown type of EAN. Try one more time, please.", "\p", "\p", "\p" ); StopAlert( 129, 0 ); main(); } } } gWindow = GetNewWindow( 128, NIL_POINTER, MOVE_TO_FRONT ); ShowWindow( gWindow ); SetPort( gWindow ); if( whatEAN == 1 ) SetWTitle( gWindow, "\pEAN-A" ); if( whatEAN == 2 ) SetWTitle( gWindow, "\pEAN-D" ); if( whatEAN == 3 ) SetWTitle( gWindow, "\pEAN-E" ); if( whatEAN == 4 ) SetWTitle( gWindow, "\pEAN-EM" ); if( whatEAN == 1 ) { numGet = getc( save ); storeSign[1] = numGet; storeNum[1] = numGet - 48; i = 2; while( ( numGet = getc( save ) ) != EOF ) { i++; storeSign[i] = numGet; storeNum[i] = numGet - 48; } if( storeNum[1] != 0 ) { ParamText( "\pFor EAN-A, first digit should only be zero. ", "\pCheck your number", "\p", "\p" ); StopAlert( 129, 0 ); CloseWindow( gWindow ); main(); } } if( whatEAN == 2 ) { i = 0; while( ( numGet = getc( save ) ) != EOF ) { i++; storeSign[i] = numGet; storeNum[i] = numGet - 48; } if( ( storeNum[1] >= 0 ) && ( storeNum[1] <= 2 ) ) { ParamText( "\pFor EAN-D, first digit cannot be smaller than 3. ", "\pCheck your number", "\p", "\p" ); StopAlert( 129, 0 ); CloseWindow( gWindow ); main(); } } if( whatEAN == 3 ) { i = 3; while( ( numGet = getc( save ) ) != EOF ) { i++; storeSign[i] = numGet; storeNum[i] = numGet - 48; } } if( whatEAN == 4 ) { i = 0; while( ( numGet = getc( save ) ) != EOF ) { i++; storeSign[i] = numGet; storeNum[i] = numGet - 48; } } fclose( save ); remove( "EAN Save" ); MainLoop();}/*********************************** DrawEAN **************************************/DrawEAN() // Draw EAN line by line{ //--------------------------------------------------------------------------------------------- // EAN-A //--------------------------------------------------------------------------------------------- if( whatEAN == 1 ) { MoveTo( 12, 101 ); TextSize( 9 ); DrawChar( storeSign[1] ); TextSize( 12 ); MoveTo( 22, 60 ); Line( 0, 38 ); MoveTo( 24, 60 ); Line( 0, 38 ); MoveTo( 28, 60 ); Line( 0, 38 ); MoveTo( 29, 60 ); Line( 0, 38 ); MoveTo( 31, 60 ); Line( 0, 38 ); MoveTo( 69, 60 ); Line( 0, 38 ); MoveTo( 71, 60 ); Line( 0, 38 ); MoveTo( 116, 60 ); Line( 0, 38 ); MoveTo( 118, 60 ); Line( 0, 38 ); TextSize( 9 ); MoveTo( 122, 101 ); DrawChar( storeSign[13] ); TextSize( 12 ); whatNum = 2; for( gT=0; gT<=4; gT++ ) { whatNum++; MoveTo( 32+gT*7, 101 ); DrawChar( storeSign[whatNum] ); } for( gT=0; gT<=4; gT++ ) { whatNum++; MoveTo( 73+gT*7, 101 ); DrawChar( storeSign[whatNum] ); } if( licence == 1 ) { MoveTo( 121, 100 ); DrawChar( '>' ); } for( por = 3; por <= 7; por++ ) Xfiles(); for( por = 8; por <= 12; por++ ) Yfiles(); por = 13; LastNum(); DrawInfo(); } //--------------------------------------------------------------------------------------------- // EAN-D //--------------------------------------------------------------------------------------------- if( whatEAN == 2 ) { MoveTo( 12, 101 ); DrawChar( storeSign[1] ); whatNum = 1; for( gT=0; gT<=5; gT++ ) { whatNum++; MoveTo( 25+gT*7, 101 ); DrawChar( storeSign[whatNum] ); } for( gT=0; gT<=5; gT++ ) { whatNum++; MoveTo( 73+gT*7, 101 ); DrawChar( storeSign[whatNum] ); } DrawInfo(); // Miscalenious MoveTo( 22, 60 ); Line( 0, 38 ); MoveTo( 24, 60 ); Line( 0, 38 ); MoveTo( 69, 60 ); Line( 0, 38 ); MoveTo( 71, 60 ); Line( 0, 38 ); MoveTo( 116, 60 ); Line( 0, 38 ); MoveTo( 118, 60 ); Line( 0, 38 ); if( licence == 1 ) { MoveTo( 121, 100 ); DrawChar( '>' ); } // Drawing last 6 EANs for( por=8; por<=13; por++ ) Yfiles(); // Drawing first 6 nums if( storeNum[1] == 3 ) { for( por=2; por<=7; por++ ) { if( por == 2 ) Xfiles(); if( por == 3 ) Xfiles(); if( por == 4 ) Zfiles(); if( por == 5 ) Zfiles(); if( por == 6 ) Zfiles(); if( por == 7 ) Xfiles(); } } if( storeNum[1] == 4 ) { for( por=2; por<=7; por++ ) { if( por == 2 ) Xfiles(); if( por == 3 ) Zfiles(); if( por == 4 ) Xfiles(); if( por == 5 ) Xfiles(); if( por == 6 ) Zfiles(); if( por == 7 ) Zfiles(); } } if( storeNum[1] == 5 ) { for( por=2; por<=7; por++ ) { if( por == 2 ) Xfiles(); if( por == 3 ) Zfiles(); if( por == 4 ) Zfiles(); if( por == 5 ) Xfiles(); if( por == 6 ) Xfiles(); if( por == 7 ) Zfiles(); } } if( storeNum[1] == 6 ) { for( por=2; por<=7; por++ ) { if( por == 2 ) Xfiles(); if( por == 3 ) Zfiles(); if( por == 4 ) Zfiles(); if( por == 5 ) Zfiles(); if( por == 6 ) Xfiles(); if( por == 7 ) Xfiles(); } } if( storeNum[1] == 7 ) { for( por=2; por<=7; por++ ) { if( por == 2 ) Xfiles(); if( por == 3 ) Zfiles(); if( por == 4 ) Xfiles(); if( por == 5 ) Zfiles(); if( por == 6 ) Xfiles(); if( por == 7 ) Zfiles(); } } if( storeNum[1] == 8 ) { for( por=2; por<=7; por++ ) { if( por == 2 ) Xfiles(); if( por == 3 ) Zfiles(); if( por == 4 ) Xfiles(); if( por == 5 ) Zfiles(); if( por == 6 ) Zfiles(); if( por == 7 ) Xfiles(); } } if( storeNum[1] == 9 ) { for( por=2; por<=7; por++ ) { if( por == 2 ) Xfiles(); if( por == 3 ) Zfiles(); if( por == 4 ) Zfiles(); if( por == 5 ) Xfiles(); if( por == 6 ) Zfiles(); if( por == 7 ) Xfiles(); } } } //--------------------------------------------------------------------------------------------- // EAN-E //--------------------------------------------------------------------------------------------- if( whatEAN == 3 ) { MoveTo( 36, 60 ); Line( 0, 38 ); MoveTo( 38, 60 ); Line( 0, 38 ); MoveTo( 69, 60 ); Line( 0, 38 ); MoveTo( 71, 60 ); Line( 0, 38 ); MoveTo( 102, 60 ); Line( 0, 38 ); MoveTo( 104, 60 ); Line( 0, 38 ); whatNum = 3; for( gT=0; gT<=3; gT++ ) { whatNum++; MoveTo( 39+gT*7, 101 ); DrawChar( storeSign[whatNum] ); } for( gT=0; gT<=3; gT++ ) { whatNum++; MoveTo( 73+gT*7, 101 ); DrawChar( storeSign[whatNum] ); } for( por = 4; por <= 7; por++ ) Xfiles(); for( por = 8; por <= 11; por++ ) Yfiles(); DrawInfo(); } //--------------------------------------------------------------------------------------------- // EAN-EM //--------------------------------------------------------------------------------------------- if( whatEAN == 4 ) { MoveTo( 12, 101 ); TextSize( 9 ); DrawChar( storeSign[1] ); TextSize( 12 ); MoveTo( 22, 60 ); Line( 0, 38 ); MoveTo( 24, 60 ); Line( 0, 38 ); whatNum = 1; for( gT=0; gT<=5; gT++ ) { whatNum++; MoveTo( 25+gT*7, 101 ); DrawChar( storeSign[whatNum] ); } MoveTo( 69, 60 ); Line( 0, 38 ); MoveTo( 71, 60 ); Line( 0, 38 ); TextSize( 9 ); MoveTo( 77, 101 ); DrawChar( storeSign[8] ); TextSize( 12 ); if( storeNum[8] == 0 ) for( por = 2; por <= 7; por++ ) { if( por == 7 ) Zfiles(); if( por == 2 ) Zfiles(); if( por == 3 ) Zfiles(); if( por == 4 ) Xfiles(); if( por == 5 ) Xfiles(); if( por == 6 ) Xfiles(); } if( storeNum[8] == 1 ) for( por = 2; por <= 7; por++ ) { if( por == 2 ) Zfiles(); if( por == 3 ) Zfiles(); if( por == 4 ) Xfiles(); if( por == 5 ) Zfiles(); if( por == 6 ) Xfiles(); if( por == 7 ) Xfiles(); } if( storeNum[8] == 2 ) for( por = 2; por <= 7; por++ ) { if( por == 2 ) Zfiles(); if( por == 3 ) Zfiles(); if( por == 4 ) Xfiles(); if( por == 5 ) Xfiles(); if( por == 6 ) Zfiles(); if( por == 7 ) Xfiles(); } if( storeNum[8] == 3 ) for( por = 2; por <= 7; por++ ) { if( por == 2 ) Zfiles(); if( por == 3 ) Zfiles(); if( por == 4 ) Xfiles(); if( por == 5 ) Xfiles(); if( por == 6 ) Xfiles(); if( por == 7 ) Zfiles(); } if( storeNum[8] == 4 ) for( por = 2; por <= 7; por++ ) { if( por == 2 ) Zfiles(); if( por == 3 ) Xfiles(); if( por == 4 ) Zfiles(); if( por == 5 ) Zfiles(); if( por == 6 ) Xfiles(); if( por == 7 ) Xfiles(); } if( storeNum[8] == 5 ) for( por = 2; por <= 7; por++ ) { if( por == 2 ) Zfiles(); if( por == 3 ) Xfiles(); if( por == 4 ) Xfiles(); if( por == 5 ) Zfiles(); if( por == 6 ) Zfiles(); if( por == 7 ) Xfiles(); } if( storeNum[8] == 6 ) for( por = 2; por <= 7; por++ ) { if( por == 2 ) Zfiles(); if( por == 3 ) Xfiles(); if( por == 4 ) Xfiles(); if( por == 5 ) Xfiles(); if( por == 6 ) Zfiles(); if( por == 7 ) Zfiles(); } if( storeNum[8] == 7 ) for( por = 2; por <= 7; por++ ) { if( por == 2 ) Zfiles(); if( por == 3 ) Xfiles(); if( por == 4 ) Zfiles(); if( por == 5 ) Xfiles(); if( por == 6 ) Zfiles(); if( por == 7 ) Xfiles(); } if( storeNum[8] == 8 ) for( por = 2; por <= 7; por++ ) { if( por == 2 ) Zfiles(); if( por == 3 ) Xfiles(); if( por == 4 ) Zfiles(); if( por == 5 ) Xfiles(); if( por == 6 ) Xfiles(); if( por == 7 ) Zfiles(); } if( storeNum[8] == 9 ) for( por = 2; por <= 7; por++ ) { if( por == 2 ) Zfiles(); if( por == 3 ) Xfiles(); if( por == 4 ) Xfiles(); if( por == 5 ) Zfiles(); if( por == 6 ) Xfiles(); if( por == 7 ) Zfiles(); } DrawInfo(); }}/************************************ Xfiles ***************************************/Xfiles() // The routine for X case of EAN{ if( ( storeNum[por] == 0 ) ) { x = 7*(por - 2); MoveTo( 28+x, 60 ); Line( 0, 30 ); MoveTo( 29+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 1 ) ) { x = 7*(por - 2); MoveTo( 27+x, 60 ); Line( 0, 30 ); MoveTo( 28+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 2 ) ) { x = 7*(por - 2); MoveTo( 27+x, 60 ); Line( 0, 30 ); MoveTo( 30+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 3 ) ) { x = 7*(por - 2); MoveTo( 26+x, 60 ); Line( 0, 30 ); MoveTo( 27+x, 60 ); Line( 0, 30 ); MoveTo( 28+x, 60 ); Line( 0, 30 ); MoveTo( 29+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 4 ) ) { x = 7*(por - 2); MoveTo( 26+x, 60 ); Line( 0, 30 ); MoveTo( 30+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 5 ) ) { x = 7*(por - 2); MoveTo( 26+x, 60 ); Line( 0, 30 ); MoveTo( 27+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 6 ) ) { x = 7*(por - 2); MoveTo( 26+x, 60 ); Line( 0, 30 ); MoveTo( 28+x, 60 ); Line( 0, 30 ); MoveTo( 29+x, 60 ); Line( 0, 30 ); MoveTo( 30+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 7 ) ) { x = 7*(por - 2); MoveTo( 26+x, 60 ); Line( 0, 30 ); MoveTo( 27+x, 60 ); Line( 0, 30 ); MoveTo( 28+x, 60 ); Line( 0, 30 ); MoveTo( 30+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 8 ) ) { x = 7*(por - 2); MoveTo( 26+x, 60 ); Line( 0, 30 ); MoveTo( 27+x, 60 ); Line( 0, 30 ); MoveTo( 29+x, 60 ); Line( 0, 30 ); MoveTo( 30+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 9 ) ) { x = 7*(por - 2); MoveTo( 28+x, 60 ); Line( 0, 30 ); MoveTo( 30+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); }}/************************************** Yfiles ****************************************/Yfiles(){ if( ( storeNum[por] == 0 ) ) { x = 7*(por - 8); MoveTo( 73+x, 60 ); Line( 0, 30 ); MoveTo( 74+x, 60 ); Line( 0, 30 ); MoveTo( 75+x, 60 ); Line( 0, 30 ); MoveTo( 78+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 1 ) ) { x = 7*(por - 8); MoveTo( 73+x, 60 ); Line( 0, 30 ); MoveTo( 74+x, 60 ); Line( 0, 30 ); MoveTo( 77+x, 60 ); Line( 0, 30 ); MoveTo( 78+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 2 ) ) { x = 7*(por - 8); MoveTo( 73+x, 60 ); Line( 0, 30 ); MoveTo( 74+x, 60 ); Line( 0, 30 ); MoveTo( 76+x, 60 ); Line( 0, 30 ); MoveTo( 77+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 3 ) ) { x = 7*(por - 8); MoveTo( 73+x, 60 ); Line( 0, 30 ); MoveTo( 78+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 4 ) ) { x = 7*(por - 8); MoveTo( 73+x, 60 ); Line( 0, 30 ); MoveTo( 75+x, 60 ); Line( 0, 30 ); MoveTo( 76+x, 60 ); Line( 0, 30 ); MoveTo( 77+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 5 ) ) { x = 7*(por - 8); MoveTo( 73+x, 60 ); Line( 0, 30 ); MoveTo( 76+x, 60 ); Line( 0, 30 ); MoveTo( 77+x, 60 ); Line( 0, 30 ); MoveTo( 78+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 6 ) ) { x = 7*(por - 8); MoveTo( 73+x, 60 ); Line( 0, 30 ); MoveTo( 75+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 7 ) ) { x = 7*(por - 8); MoveTo( 73+x, 60 ); Line( 0, 30 ); MoveTo( 77+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 8 ) ) { x = 7*(por - 8); MoveTo( 73+x, 60 ); Line( 0, 30 ); MoveTo( 76+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 9 ) ) { x = 7*(por - 8); MoveTo( 73+x, 60 ); Line( 0, 30 ); MoveTo( 74+x, 60 ); Line( 0, 30 ); MoveTo( 75+x, 60 ); Line( 0, 30 ); MoveTo( 77+x, 60 ); Line( 0, 30 ); }}/************************************* Zfiles ****************************************/Zfiles() // The routine for Z case of EAN{ if( ( storeNum[por] == 0 ) ) { x = 7*(por - 2); MoveTo( 26+x, 60 ); Line( 0, 30 ); MoveTo( 29+x, 60 ); Line( 0, 30 ); MoveTo( 30+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 1 ) ) { x = 7*(por - 2); MoveTo( 26+x, 60 ); Line( 0, 30 ); MoveTo( 27+x, 60 ); Line( 0, 30 ); MoveTo( 30+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 2 ) ) { x = 7*(por - 2); MoveTo( 27+x, 60 ); Line( 0, 30 ); MoveTo( 28+x, 60 ); Line( 0, 30 ); MoveTo( 30+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 3 ) ) { x = 7*(por - 2); MoveTo( 26+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 4 ) ) { x = 7*(por - 2); MoveTo( 27+x, 60 ); Line( 0, 30 ); MoveTo( 28+x, 60 ); Line( 0, 30 ); MoveTo( 29+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 5 ) ) { x = 7*(por - 2); MoveTo( 26+x, 60 ); Line( 0, 30 ); MoveTo( 27+x, 60 ); Line( 0, 30 ); MoveTo( 28+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 6 ) ) { x = 7*(por - 2); MoveTo( 29+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 7 ) ) { x = 7*(por - 2); MoveTo( 27+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 8 ) ) { x = 7*(por - 2); MoveTo( 28+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); } if( ( storeNum[por] == 9 ) ) { x = 7*(por - 2); MoveTo( 27+x, 60 ); Line( 0, 30 ); MoveTo( 29+x, 60 ); Line( 0, 30 ); MoveTo( 30+x, 60 ); Line( 0, 30 ); MoveTo( 31+x, 60 ); Line( 0, 30 ); }}/************************************** LastNum ****************************************/LastNum(){ if( ( storeNum[13] == 0 ) ) { x = 7*(por - 8); MoveTo( 74+x, 60 ); Line( 0, 38 ); MoveTo( 75+x, 60 ); Line( 0, 38 ); MoveTo( 76+x, 60 ); Line( 0, 38 ); MoveTo( 79+x, 60 ); Line( 0, 38 ); } if( ( storeNum[13] == 1 ) ) { x = 7*(por - 8); MoveTo( 74+x, 60 ); Line( 0, 38 ); MoveTo( 75+x, 60 ); Line( 0, 38 ); MoveTo( 78+x, 60 ); Line( 0, 38 ); MoveTo( 79+x, 60 ); Line( 0, 38 ); } if( ( storeNum[13] == 2 ) ) { x = 7*(por - 8); MoveTo( 74+x, 60 ); Line( 0, 38 ); MoveTo( 75+x, 60 ); Line( 0, 38 ); MoveTo( 77+x, 60 ); Line( 0, 38 ); MoveTo( 78+x, 60 ); Line( 0, 38 ); } if( ( storeNum[13] == 3 ) ) { x = 7*(por - 8); MoveTo( 74+x, 60 ); Line( 0, 38 ); MoveTo( 79+x, 60 ); Line( 0, 38 ); } if( ( storeNum[13] == 4 ) ) { x = 7*(por - 8); MoveTo( 74+x, 60 ); Line( 0, 38 ); MoveTo( 75+x, 60 ); Line( 0, 38 ); MoveTo( 77+x, 60 ); Line( 0, 38 ); MoveTo( 78+x, 60 ); Line( 0, 38 ); } if( ( storeNum[13] == 5 ) ) { x = 7*(por - 8); MoveTo( 74+x, 60 ); Line( 0, 38 ); MoveTo( 77+x, 60 ); Line( 0, 38 ); MoveTo( 78+x, 60 ); Line( 0, 38 ); MoveTo( 79+x, 60 ); Line( 0, 38 ); } if( ( storeNum[13] == 6 ) ) { x = 7*(por - 8); MoveTo( 74+x, 60 ); Line( 0, 38 ); MoveTo( 75+x, 60 ); Line( 0, 38 ); } if( ( storeNum[13] == 7 ) ) { x = 7*(por - 8); MoveTo( 74+x, 60 ); Line( 0, 38 ); MoveTo( 78+x, 60 ); Line( 0, 38 ); } if( ( storeNum[13] == 8 ) ) { x = 7*(por - 8); MoveTo( 74+x, 60 ); Line( 0, 38 ); MoveTo( 77+x, 60 ); Line( 0, 38 ); } if( ( storeNum[13] == 9 ) ) { x = 7*(por - 8); MoveTo( 74+x, 60 ); Line( 0, 38 ); MoveTo( 75+x, 60 ); Line( 0, 38 ); MoveTo( 76+x, 60 ); Line( 0, 38 ); MoveTo( 78+x, 60 ); Line( 0, 38 ); }}/************************************* DrawInfo *****************************************/DrawInfo() // Drawing information on EAN number{ MoveTo( 150, 0 ); // Miscalenious Line( 0, 200 ); MoveTo( 152, 0 ); Line( 0, 200 ); ForeColor( blueColor ); MoveTo( 170, 120 ); DrawString( "\pPress \'A\'" ); MoveTo( 170, 135 ); DrawString( "\pto enter another number" ); ForeColor( blackColor ); ForeColor( redColor ); // Country code MoveTo( 170, 30 ); DrawString( "\pCountry:" ); ForeColor( blackColor ); MoveTo( 170, 45 ); ///////////////////////////////////////////////////////// if( whatEAN == 1 ) // Duo digit codes country = storeNum[1]*10 + storeNum[3]; if( whatEAN == 2 ) country = storeNum[1]*10 + storeNum[2]; if( whatEAN == 3 ) country = storeNum[4]*10 + storeNum[5]; if( whatEAN == 4 ) country = storeNum[1]*10 + storeNum[2]; if( ( country >= 1 ) && ( country <= 9 ) ) DrawString( "\pUSA/Canada" ); if( ( country >= 30 ) && ( country <= 37 ) ) DrawString( "\pFrance" ); if( ( country >= 40 ) && ( country <= 44 ) ) DrawString( "\pGermany" ); if( country == 49 ) DrawString( "\pJapan" ); if( country == 50 ) DrawString( "\pGB & N. Ireland" ); if( country == 54 ) DrawString( "\pBelgium/Luxembourg" ); if( country == 57 ) DrawString( "\pDenmark" ); if( country == 64 ) DrawString( "\pFinland" ); if( country == 70 ) DrawString( "\pNorway" ); if( country == 73 ) DrawString( "\pSweden" ); if( country == 74 ) DrawString( "\pCentral America" ); if( country == 75 ) DrawString( "\pMexico/Venesuela" ); if( country == 76 ) DrawString( "\pSwitzerland" ); if( ( country >= 77 ) && ( country <= 78 ) ) DrawString( "\pLatin America" ); if( ( country >= 80 ) && ( country <= 83 ) ) DrawString( "\pItaly" ); if( country == 84 ) DrawString( "\pSpain" ); if( country == 87 ) DrawString( "\pNetherlands" ); if( country == 88 ) DrawString( "\pKorea" ); if( ( country >= 90 ) && ( country <= 91 ) ) DrawString( "\pAustria" ); if( country == 93 ) DrawString( "\pAustralia" ); if( country == 94 ) DrawString( "\pNew Zeland" ); ////////////////////////////////////////////////////////// if( whatEAN == 1 ) // Tri digit codes country = storeNum[1]*100 + storeNum[3]*10 + storeNum[4]; if( whatEAN == 2 ) country = storeNum[1]*100 + storeNum[2]*10 + storeNum[3]; if( whatEAN == 3 ) country = storeNum[4]*100 + storeNum[5]*10 + storeNum[6]; if( whatEAN == 4 ) country = storeNum[1]*100 + storeNum[2]*10 + storeNum[3]; if( country == 380 ) DrawString( "\pBulgaria" ); if( ( country >= 460 ) && ( country <= 469 ) ) DrawString( "\pRussia" ); if( country == 489 ) DrawString( "\pHong Kong" ); if( country == 520 ) DrawString( "\pGreece" ); if( country == 529 ) DrawString( "\pCyprus" ); if( country == 560 ) DrawString( "\pPortugal" ); if( country == 569 ) DrawString( "\pIceland" ); if( country == 590 ) DrawString( "\pPoland" ); if( country == 599 ) DrawString( "\pHungary" ); if( ( country >= 600 ) && ( country <= 611 ) ) DrawString( "\pSAR" ); if( country == 729 ) DrawString( "\pIsrael" ); if( country == 859 ) DrawString( "\pCzech Republic" ); if( country == 860 ) DrawString( "\pYugoslavia" ); if( country == 869 ) DrawString( "\pTurkey" ); ForeColor( redColor ); // Control digit MoveTo( 170, 75 ); DrawString( "\pControl digit (" ); if( ( whatEAN == 1 ) || ( whatEAN == 2 ) ) DrawChar( storeSign[13] ); if( whatEAN == 3 ) DrawChar( storeSign[11] ); if( whatEAN == 4 ) DrawChar( storeSign[8] ); DrawString( "\p): " ); ForeColor( blackColor ); if( whatEAN == 1 ) // For EAN-A only { controlDigit = ( ( storeNum[1] + storeNum[4] + storeNum[6] + storeNum[8] + storeNum[10] + + storeNum[12] )*3 + + ( storeNum[3] + storeNum[5] + storeNum[7] + storeNum[9] + + storeNum[11] ) ); controlDigit = controlDigit % 10; controlDigit = 10 - controlDigit; } if( whatEAN == 2 ) // For EAN-D only { controlDigit = ( ( storeNum[2] + storeNum[4] + storeNum[6] + storeNum[8] + storeNum[10] + + storeNum[12] )*3 + + ( storeNum[1] + storeNum[3] + storeNum[5] + storeNum[7] + storeNum[9] + + storeNum[11] ) ); controlDigit = controlDigit % 10; controlDigit = 10 - controlDigit; } if( whatEAN == 3 ) // For EAN-E only { controlDigit = ( ( storeNum[4] + storeNum[6] + storeNum[8] + storeNum[10] )*3 + + ( storeNum[5] + storeNum[7] + storeNum[9] ) ); controlDigit = controlDigit % 10; controlDigit = 10 - controlDigit; } if( whatEAN == 4 ) // For EAN-EM only { eanA[1] = 0; if( ( storeNum[7] >= 0 ) && ( storeNum[7] <= 2 ) ) { eanA[2] = storeNum[2]; eanA[3] = storeNum[3]; eanA[4] = storeNum[7]; eanA[5] = 0; eanA[6] = 0; eanA[7] = 0; eanA[8] = 0; eanA[9] = storeNum[4]; eanA[10] = storeNum[5]; eanA[11] = storeNum[6]; } if( storeNum[7] == 3 ) { eanA[2] = storeNum[2]; eanA[3] = storeNum[3]; eanA[4] = storeNum[4]; eanA[5] = 0; eanA[6] = 0; eanA[7] = 0; eanA[8] = 0; eanA[9] = 0; eanA[10] = storeNum[5]; eanA[11] = storeNum[6]; } if( storeNum[7] == 4 ) { eanA[2] = storeNum[2]; eanA[3] = storeNum[3]; eanA[4] = storeNum[4]; eanA[5] = storeNum[5]; eanA[6] = 0; eanA[7] = 0; eanA[8] = 0; eanA[9] = 0; eanA[10] = 0; eanA[11] = storeNum[6]; } if( ( storeNum[7] >= 5 ) && ( storeNum[7] <= 9 ) ) { eanA[2] = storeNum[2]; eanA[3] = storeNum[3]; eanA[4] = storeNum[4]; eanA[5] = storeNum[5]; eanA[6] = storeNum[6]; eanA[7] = 0; eanA[8] = 0; eanA[9] = 0; eanA[10] = 0; eanA[11] = storeNum[7]; } controlDigit = ( ( eanA[2] + eanA[4] + eanA[6] + eanA[8] + eanA[10] )*3 + + ( eanA[1] + eanA[3] + eanA[5] + eanA[7] + eanA[9] + + eanA[11] ) ); controlDigit = controlDigit % 10; controlDigit = 10 - controlDigit; } if( ( whatEAN == 1 ) || ( whatEAN == 2 ) ) { if( controlDigit == storeNum[13] ) DrawString( "\pOK" ); else DrawString( "\pBad" ); } if( whatEAN == 3 ) { if( controlDigit == storeNum[11] ) DrawString( "\pOK" ); else DrawString( "\pBad" ); } if( whatEAN == 4 ) { if( controlDigit == storeNum[8] ) DrawString( "\pOK" ); else DrawString( "\pBad" ); }}/*********************** 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 occured in main?{ char theChar; Rect erase; SetRect( &erase, 120, 85, 130, 102 ); 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: HandleMouseDown(); break; case keyDown: case autoKey: theChar = gTheEvent.message & charCodeMask; switch( theChar ) { case 'a': CloseWindow( gWindow ); main(); break; case 'A': CloseWindow( gWindow ); main(); break; case 'l': if( whatEAN == 2 ) { licence++; if( licence == 1 ) { MoveTo( 121, 100 ); DrawChar( '>' ); } else { EraseRect( &erase ); licence=0; } } break; case 'L': if( whatEAN == 2 ) { licence++; if( licence == 1 ) { MoveTo( 121, 100 ); DrawChar( '>' ); } else { EraseRect( &erase ); licence=0; } } break; } break; case updateEvt: BeginUpdate((WindowPtr)gTheEvent.message); EndUpdate((WindowPtr)gTheEvent.message); DrawEAN(); break; }}/***************************** HandleMouseDown *************************/HandleMouseDown() // Where had user clicked mouse?{ GetMouse( &cPoint ); thePart = FindWindow( gTheEvent.where, &whichWindow ); switch( thePart ) { case inMenuBar: break; case inSysWindow: SystemClick( &gTheEvent, whichWindow ); break; case inDrag: DragWindow( whichWindow, gTheEvent.where, &gDragRect ); break; case inGoAway: if( TrackGoAway( whichWindow, gTheEvent.where ) == TRUE ) { CloseWindow( whichWindow ); ExitToShell(); } break; case inContent: break; }}/********************** SetUpDragRect ******************************/SetUpDragRect() // What rect belongs to dragged window?{ gDragRect = screenBits.bounds; gDragRect.left += DRAG_THRESHOLD; gDragRect.right -= DRAG_THRESHOLD; gDragRect.bottom -= DRAG_THRESHOLD;}