1 // Prototypes (also known as "forward declarations") of subroutine
2 // functions in this file
3 LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam,
4 LPARAM lParam);
5 S_32 ProcessMessages(void);
6 S_32 keycheck(void);
7 S_32 WorkAreaInit(void);
8 S_32 IndexToPrime(U_32 *dp);
9 U_32 Divide(struct scratchpad *sp, S_32 bits);
10 U_08 PseudoRandomize(U_08 uc);
11 S_32 KeyToPrimes(void);
12 S_32 AffectFiles(void); // uses struct affect *afflist declared below
13 /* For those who want to know what that section is all about, note
14 that the compiler processes a source-code file like this one from
15 start to finish, sequentially. The compiler will complain if it
16 encounters any phrase that it cannot recognize, and such phrases
17 include the names of subroutine functions, if they are specified/
18 declared/defined in the file AFTER any usage of them. Since usage
19 usually occurs in the "main" part of the program, one solution is
20 to place all the subroutine functions/definitions near the start of
21 the file, so that they are guaranteed to precede any usage of them.
22 However, when there are many subroutines, someone who is editing
23 such a file often has to hunt for the start of the main program,
24 and there is an aura of untidiness about doing things that way.
25 These prototypes are an alternative, a promise to the compiler that
26 those functions will be found later on in the file. Thus the main
27 program can be located near the start of the file's executable
28 code, and subroutine functions can be located in their logical
29 place, at the rear.
30 */
31
32
33 /*
34 Global Variables. Programmers encounter many discussions regarding
35 these things. In a really long program (multiple files) it may be
36 best to put them all in a structure, and have just one global
37 structure-pointer, with space for the structure malloc()'d. Most of
38 the "static" variables in this program would probably get moved into
39 such a structure (they are essentially global, anyway). However,
40 constant dereferencing of a structure, to get at the variables, slows
41 a program down. This program needs to run as fast as possible --
42 which is why there are relatively few sub-functions (with associated
43 overhead in calling them frequently, not to mention stack-spasms as
44 space for local variables is constantly created/destroyed). Still,
45 discussions continue, and the oldest-fashion way was chosen here.
46 */
47 struct W_F_D wfd;
48 HWND hwnd;
49 FILE *dskfil, *prmfil;
50 HFONT hfont1, hfont2;
51 HANDLE hPriorF, fil1, fil2;
52 HINSTANCE previnst;
53 LPSTR szParams;
54 RECT rect;
55 char eraser[100] = " "
56 " "
57 " ",
58 keynam[] = " "
59 " ", ch,
60 keyfile[50], tmpstr[800], tadone[60], prm[50],
61 del1, doit, proceed, *p, *q;
62 U_08 *ucMemBlk1, *ucMemBlk2, *ucMemBlk3, *ucMemBlk4, *ucp1,
63 *ucp4, *by, bt, ModType[5], ModData[5];
64 U_08 skpd[7] = {1, 2, 3, 5, 7, 11, 13};
65 /* The table below is thoroughly explained in both the PRMPRESS.C and
66 PIKPRIME.C files. Here it is used to decompress the data in the
67 COMPRESS.PRM file. */
68 U_08 tbl[5761] =
69 {16, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6,
70 4, 6, 8, 4, 2, 4, 2, 4, 14, 4, 6, 2, 10, 2, 6, 6,
71 4, 6, 6, 2, 10, 2, 4, 2, 12, 12, 4, 2, 4, 6, 2, 10,
72 6, 6, 6, 2, 6, 4, 2, 6, 4, 14, 4, 2, 4, 6, 8, 6,
73 10, 2, 4, 6, 2, 6, 6, 6, 4, 6, 2, 6, 4, 8, 10, 2,
74 10, 2, 4, 2, 4, 6, 8, 4, 2, 4, 12, 8, 4, 2, 6, 4,
75 6, 12, 2, 4, 2, 12, 6, 4, 6, 6, 6, 2, 6, 10, 2, 4,
76 6, 2, 6, 6, 4, 2, 10, 2, 10, 2, 4, 6, 6, 2, 6, 6,
77 4, 6, 8, 6, 4, 2, 6, 4, 6, 8, 4, 2, 6, 4, 8, 6,
78 4, 8, 4, 6, 8, 10, 2, 10, 2, 6, 4, 2, 4, 2, 10, 2,
79 10, 2, 4, 2, 4, 14, 4, 2, 4, 6, 6, 2, 6, 4, 8, 10,
80 8, 4, 2, 4, 6, 8, 6, 4, 6, 6, 6, 2, 6, 6, 4, 2,
81 4, 6, 2, 10, 2, 4, 2, 10, 2, 10, 2, 6, 4, 8, 6, 4,
82 2, 4, 6, 6, 8, 4, 2, 6, 10, 8, 4, 2, 6, 4, 8, 10,
83 6, 2, 4, 8, 6, 6, 4, 2, 4, 6, 2, 6, 4, 6, 2, 10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2, 4, 8, 6, 4, 2,
412 4, 12, 2, 6, 4, 12, 6, 8, 4, 2, 4, 2, 4, 8, 6, 10,
413 6, 6, 2, 12, 4, 2, 4, 6, 2, 6, 4, 2, 4, 2, 12, 10,
414 2, 6, 4, 6, 2, 6, 4, 2, 4, 6, 6, 8, 4, 2, 6, 10,
415 8, 4, 6, 2, 4, 8, 10, 6, 2, 4, 8, 6, 6, 4, 2, 4,
416 6, 8, 4, 6, 2, 10, 2, 10, 2, 4, 2, 10, 2, 6, 4, 2,
417 4, 6, 6, 2, 6, 6, 6, 4, 6, 8, 6, 4, 2, 4, 8, 10,
418 8, 4, 6, 2, 6, 6, 4, 2, 4, 14, 4, 2, 4, 2, 10, 2,
419 10, 2, 4, 2, 4, 6, 2, 10, 2, 10, 8, 6, 4, 8, 4, 6,
420 8, 4, 6, 2, 4, 8, 6, 4, 6, 2, 4, 6, 8, 6, 4, 6,
421 6, 2, 6, 6, 4, 2, 10, 2, 10, 2, 4, 6, 6, 2, 6, 4,
422 2, 10, 6, 2, 6, 6, 6, 4, 6, 12, 2, 4, 2, 12, 6, 4,
423 6, 2, 4, 8, 12, 4, 2, 4, 8, 6, 4, 2, 4, 2, 10, 2,
424 10, 8, 4, 6, 2, 6, 4, 6, 6, 6, 2, 6, 4, 2, 10, 6,
425 8, 6, 4, 2, 4, 14, 4, 6, 2, 4, 6, 2, 6, 6, 6, 10,
426 2, 6, 4, 2, 4, 12, 12, 2, 4, 2, 10, 2, 6, 6, 4, 6,
427 6, 2, 10, 2, 6, 4, 14, 4, 2, 4, 2, 4, 8, 6, 4, 6,
428 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4, 2, 16, 2,
429 0};
430 S_16 *qp;
431 S_32 NeedInfo, params, fpb, i, j, L, huminp, mastnum,
432 *lim, affnum = 1, affcou, status=0, WhichWay[2],
433 WorkSize, prmbar;
434 U_32 *ip, *is, *it;
435 size_t fetched, big;
436 struct affect *afflist = NULL, *affitem, *affprev, **affwalk;
437 struct scratchpad *LoadMaster, *ModCounter, *TypeSetter,
438 *RandomSkip, *WorkRegion;
439 // Note: size_t is a typedef like U_32, and happens to be the
440 // same as U_32.
441
442
443
444 //////////////////////////////////////////////////////////////////////
445 // BEGIN: WinMain is the primary/required starting point of any
446 // Windows program
447 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
448 LPSTR szCmdLine, int iCmdShow)
449 { static char szAppName[] = "Cryption";
450 MSG msg;
451 WNDCLASS wndclass;
452
453 previnst = hPrevInstance; // Save to global to eliminate compiler
454 // warning
455 ucMemBlk1 = malloc(1100000); // Buffer for file input, modification,
456 // and output
457 ucMemBlk2 = malloc(525000); // main work area, 65536 scratchpads,
458 // 8 bytes each
459 ucMemBlk3 = malloc(600000); // For the Index to the compressed-
460 // primes data file
461 ucMemBlk4 = malloc(4200000); // For sorting up to 65536 4-byte
462 // numbers, quickly
463 if((ucMemBlk1 == NULL) || (ucMemBlk2 == NULL) ||
464 (ucMemBlk3 == NULL) || (ucMemBlk4 == NULL))
465 { if(ucMemBlk1)
466 free(ucMemBlk1);
467 if(ucMemBlk2)
468 free(ucMemBlk2);
469 if(ucMemBlk3)
470 free(ucMemBlk2);
471 if(ucMemBlk4)
472 free(ucMemBlk2);
473 MessageBox(NULL, "NOT ENOUGH MEMORY!", "ERROR",
474 MB_OK | MB_ICONSTOP);
475 exit(CRP_ERR_OM); // exit code 1: Out of Memory
476 }
477 // Next critical step: ensure data file and index are available
478 fetched = GetLogicalDrives();// Bitmap of available drives
479 // 1=A, 2=B, 4=C, 8=D, etc, 0=fail
480 ch = 'C'; // here and below (i=4) skip Drive A and Drive B
481 for(big=4; big; big<<=1) // Loop quits when bit shifted off end
482 // and i becomes Zero
483 { if((fetched & big) == big)
484 { sprintf(tmpstr, "%c:\\PRIMES\\COMPRESS.PRM", ch);
485 prmfil = fopen(tmpstr, "rb");
486 if(prmfil != NULL)
487 { fpb = 0; // initialize file-position-byte
488 sprintf(tmpstr, "%c:\\PRIMES\\CMPRMDEX.QNT", ch);
489 dskfil = fopen(tmpstr, "rb");
490 break; // Quit for() loop regardless of existence of file,
491 // because have other file
492 } } // Otherwise continue loop; assume compressed-prime file
493 // does not exist here; try next drive
494 ch++; // 'D, 'E', etc
495 }
496 if((prmfil == NULL) || (dskfil == NULL))
497 { MessageBox(NULL, "Files COMPRESS.PRM and CMPRMDEX.QNT are not\n"
498 "both available in a \\PRIMES directory.",
499 "ERROR", MB_OK | MB_ICONSTOP);
500 exit(CRP_ERR_OF); // using exit code 2: Opening File
501 }
502 fread(ucMemBlk1, 2, 143023, dskfil); // Load entire primes-data-
503 // Index file
504 fclose(dskfil); // close the file
505 lim = (S_32 *)(ucMemBlk1 + 286046);
506 ip = (U_32 *)ucMemBlk3; // initialize Index pointer
507 i = 0;
508 for(qp=(S_16 *)ucMemBlk1; qp<(S_16 *)lim; )
509 { i += *qp++; // accumulate number of primes in this indexed block
510 *ip++ = i; // save the accumulations for later binary search
511 }
512 /*It might be noted that the preceding calculations using the Index
513 data file (and future calcs using the compressed Primes data file)
514 are not subject to the Endian controversy. This is because it is
515 expected that the algorithms in PRMPRESS.C would have been compiled
516 and executed to generate the files on the same computers that are
517 going to use those files. A problem is likely if, say, a Little
518 Endian machine was used to generate the files, and a Big Endian
519 machine was given a COPY of those files. But that's not likely,
520 mostly because you now know about it and can avoid it.
521 */
522
523 // Next up: Set four special scratchpads used to Control
524 LoadMaster = (struct scratchpad *)(&ucMemBlk2[0]); // the
525 ModCounter = (struct scratchpad *)(&ucMemBlk2[8]); // CRYPTION
526 TypeSetter = (struct scratchpad *)(&ucMemBlk2[16]); // algorithm
527 RandomSkip = (struct scratchpad *)(&ucMemBlk2[24]);
528 WorkRegion = (struct scratchpad *)(&ucMemBlk2[32]); // Begin 64K
529 // scratchpads, array-accessed
530 // Those prior five lines are a way of telling the compiler that the
531 // simple unorgainzed block of memory allocated for the ucMemBlk2
532 // pointer (half-a-million bytes +) is going to be accessed as if it
533 // was a huge array of scratchpad structures (each of which occupies
534 // 8 bytes). The first four are special-purpose scratchpads that
535 // deserve their own names, which will control major aspects of the
536 // CRYPTION process, as described elsewhere in this file.
537 // "WorkRegion" is the name by which thousands of other scratchpads
538 // can be accessed (specific examples are WorkRegion[15] and
539 // WorkRegion[3749]) in that memory-block. One of the best features
540 // of the C programming language is something called "pointer
541 // arithmetic". Those references like "ucMemBlk2[24]" are
542 // specifying particular numbers of bytes from the start of the
543 // memory block, simply because ucMemBlk2 was declared as a "char"
544 // pointer, and "char" variables occupy one byte each. However,
545 // since WorkRegion (and the others) are pointers to 8-byte
546 // scratchpad structures, the compiler automatically knows to put
547 // WorkRegion[193] 8 bytes after WorkRegion[192]. Thus while
548 // WorkRegion[0] is located at ucMemBlk2[32], WorkRegion[1] is
549 // located at ucMemBlk2[40], and WorkRegion[2] is located at
550 // ucMemBlk2[48], and so on, for 65536 WorkRegion scratchpads, and
551 // for 524288 bytes of memory in ucMemBlk2.
552 tadone[0] = '\0';
553 NeedInfo = 63; // Binary 00111111 --flag-bits that will be cleared
554 // as info verified
555 keyfile[0] = '\0';
556 del1 = 'N'; // default Don't Delete the Key File
557 afflist = affitem = NULL;
558 affwalk = &afflist; // get address of linked-list first-item pointer
559 // (currently NULL)
560 affcou = 0; // initialize count of items on linked list
561 doit = ' ';
562 proceed = ' ';
563 szParams = szCmdLine; // prepare to process parameters
564 for(params=0; szParams[params]; params++) // Use this loop to find
565 // length of param-string,
566 szParams[params] = (char)toupper(szParams[params]); // ensuring
567 // uppercase
568 //NOTE: Parsing stops at any failure point, or at NULL-terminator.
569 // Insufficient acceptable parameters will result (later) in waiting
570 // for human input.
571 huminp = 1;// Assume missing or faulty params, so human input needed
572 if(params) // if any length of parameter-info
573 { ch = szParams[0];// Windows ensures first character is not a space
574 if(ch == '"')// Validate required quotation mark for Key File Name
575 { p = ++szParams;//Skip the open-quote and save start of File Name
576 q = strchr(p, '"'); // look for the required close-quote
577 if(q) // result of seeking must not be NULL
578 { L = (int)(uli(q) - uli(p));//compute length of drive\path\name
579 if(L && (L < 49)) //Key File Name must exist and not
580 // be too long
581 { strncpy(keyfile, p, L);// copy the stuff between quote marks
582 keyfile[L] = '\0'; // strncpy does not terminate string,
583 // so do it
584 szParams += L; // Skip filename (pointer now at close-quote
585 while(' ' == (ch = *(++szParams))); // 1-line loop: skip
586 // current character and spaces
587 if(ch == 'D') // check for optional 'D'
588 { del1 = 'Y'; // Set flag to delete Key File after
589 // successful operation
590 while(' ' == (ch = *(++szParams))); // Same 1-line loop as
591 // above; skip spaces
592 } // If optional 'D' wasn't there, no problem continuing
593 do // BEGIN LOOP TO PARSE 4 PARAMS FOR EACH FILE TO AFFECT
594 { if(isdigit(ch)) // A skip number is now required
595 { huminp = 1; // More params to process, assume
596 // will need human input to fix
597 affprev = affitem; // Save current item as
598 // about-to-be-previous
599 *affwalk = malloc(sizeof(struct affect)); // reserve
600 // some memory (sets 2 pointers)
601 if(!*affwalk) // if failed
602 { while(afflist) // while an item on this list exists
603 { affitem = afflist; // save the current item
604 afflist = afflist->next; // Get at a possible next
605 // item (may be NULL)
606 free(affitem); // delete current item
607 }
608 MessageBox(NULL, "NOT ENOUGH MEMORY!", "ERROR",
609 MB_OK | MB_ICONSTOP);
610 free(ucMemBlk1);
611 free(ucMemBlk2);
612 free(ucMemBlk3);
613 free(ucMemBlk4);
614 exit(CRP_ERR_OM); // exit code 1: Out of Memory
615 }// Program-flow passes this point only after successful
616 // memory allocation
617 affcou++; // count number of items on this linked list
618 affitem = *affwalk;// get easy pointer to this list item
619 affitem->prev = affprev;//set link to prior item on list
620 afflist->prev = affitem; // Set FIRST-item link to last
621 // (current) item on list
622 affprev = affitem->prev;// Refetch pointer, but at FIRST
623 // sets to NON-NULL
624 affitem->next = NULL; // Ensure new structure doesn't
625 // point anywhere
626 affwalk = &(affitem->next); // Get address of linklist
627 // pointer for next loop
628 affitem->dotloc = -1; // Initialize in case no file
629 // extension
630 affitem->kill = 'E'; // Initialize to Error in case loop
631 // quits early
632 i = 0; // initialize a number
633 do // can do this at least once since ch is a digit
634 { i = i * 10 + (ch - '0'); // Accumulate Skip Number;
635 // convert digit's CHARACTER-CODE
636 } while(isdigit(ch = *(++szParams)) && (i <= 999999));
637 //NOTE if i==999999,
638 // then next loop makes i nearly ten million
639 affitem->skipno = i; // save the skip number
640 if((ch == ' ') || isdigit(ch)) // Did digit loop end at
641 // a space or digit?
642 while((' ' == (ch = *(++szParams))) || isdigit(ch));
643 // skip spaces or excess digits
644 if((ch != 'D') && (ch != 'E')) // Did that loop end at
645 // required algorithm code?
646 break; // end affwalk loop if not
647 affitem->algo = ch; // save the algorithm code
648 while(' ' == (ch = *(++szParams)));//Skip any/all spaces
649 // that follow it
650 if(ch != '"') // Should now be at required quoted
651 // file name
652 break; // end affwalk loop if not
653 p = ++szParams; // Skip the open-quote and
654 // save start of File Name
655 q = strchr(p, '"'); // look for the required close-quote
656 if(q == NULL) // if wasn't there
657 break; // end affwalk loop
658 L = (int)(uli(q) - uli(p)); // Compute length of
659 // drive\path\name
660 if((L < 1) || (L > 48)) // Key File Name must exist and
661 // not be too long
662 break; // end affwalk loop
663 q = affitem->pathname; // Get easy pointer to the copied
664 // pathfile string
665 strncpy(q, p, L); // Copy the stuff between quote marks
666 q[L] = '\0'; // terminate the string
667 for(i=L-1; i>=0; i--) // Walk backward through the
668 // filename
669 { ch = q[i];
670 if((ch == '\\') || (ch == ':'))
671 break; // found marker before filename
672 // quit looping regardless of finding extension
673 if((ch == '.') && (affitem->dotloc == -1))
674 { affitem->dotloc = (S_16)i; // Save location of
675 // first-found extension-marker
676 break; // no need to continue for() loop
677 } }
678 if(((i == -1) && (L > 44)) || // MUST HAVE ROOM IN FILE
679 // NAME STRING TO EITHER
680 ((48 - i) < 4)) // REPLACE EXTENSION WITH,
681 // OR ADD, .CRP
682 break; // end affwalk loop
683 szParams += L; // Skip filename (pointer now at
684 // close-quote
685 while(' ' == (ch = *(++szParams)));//Skip any/all spaces
686 // that follow it
687 if(!ch || (ch == ' ') || isdigit(ch))// String ended, or
688 // have space or digit?
689 affitem->kill = 'N'; // Default to NO KILL;
690 // valid option is missing
691 else if(ch != 'D')//anything else MUST be a D for delete
692 break; // keep the Error-marker and quit affwalk loop
693 else
694 affitem->kill = 'Y'; // have a D, so set YES KILL
695 if(ch && !isdigit(ch)) // if D or space
696 while(' ' == (ch = *(++szParams))); // Skip it and
697 // any/all following spaces
698 huminp = 0; // Params accepted -- no human
699 // input needed to fix
700 } // note huminp reset to 1 if another file-to-affect
701 else
702 break; // nondigit where a digit was required
703 } while(*szParams); // need at least one to-affect file
704 } } } } // continue parsing the parameter-string
705 affitem = affprev = afflist; // Set pointers to start of linked list
706 // (if exists)
707 affwalk = &afflist; // and this one, too
708
709 if(!huminp) // so far no errors requiring human input?
710 doit = 'A'; // prepare for automatic-acceptance processing
711
712
713 // DONE PROCESSING PARAMETERS; TIME TO DO ORDINARY WINDOWS STUFF
714
715 // Prepare a couple of fixed fonts,
716 // only differece is that one is underlined
717 hfont1 = CreateFont(0, 7, 0, 0, 0, 0, 0, 0, ANSI_CHARSET,
718 OUT_DEFAULT_PRECIS, CLIP_CHARACTER_PRECIS,
719 DEFAULT_QUALITY, (FIXED_PITCH | FF_MODERN),
720 "SimpleFixed"); // NO UNDERLINE
721 hfont2 = CreateFont(0, 7, 0, 0, 0, 0, 1, 0, ANSI_CHARSET,
722 OUT_DEFAULT_PRECIS, CLIP_CHARACTER_PRECIS,
723 DEFAULT_QUALITY, (FIXED_PITCH | FF_MODERN),
724 "SimpleFixUN"); // UNDERLINED
725 /* (Copied from Language Reference)
726 CreateFont
727 (int nHeight, // logical height of font (0=default)
728 int nWidth, // logical average character width
729 // (0=default, using 7)
730 int nEscapement, // angle of escapement (0=default)
731 int nOrientation, // base-line orientation angle(0=default)
732 int fnWeight, // font weight (0=default)
733 DWORD fdwItalic, // italic attribute flag (0=False)
734 DWORD fdwUnderline, // underline attribute flag (0=False)
735 DWORD fdwStrikeOut, // strikeout attribute flag (0=False)
736 DWORD fdwCharSet, // character set identifier, using
737 // ANSI_CHARSET
738 DWORD fdwOutputPrecision,// output precision, using default
739 DWORD fdwClipPrecision, // clipping precision, using SOME
740 DWORD fdwQuality, // output quality, using default
741 DWORD fdwPitchAndFamily, // pitch and family,
742 // using Fixed and no 'serif"
743 LPCTSTR lpszFace); // address of typeface name string
744 */
745
746 // FINALLY READY TO CREATE A WINDOW FOR THIS PROGRAM
747 //wndclass.Size = sizeof(wndclass);
748 wndclass.style = CS_HREDRAW | CS_VREDRAW;
749 wndclass.lpfnWndProc = WndProc;
750 wndclass.cbClsExtra = 0;
751 wndclass.cbWndExtra = 0;
752 wndclass.hInstance = hInstance;
753 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
754 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
755 wndclass.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
756 wndclass.lpszMenuName = NULL;
757 wndclass.lpszClassName = szAppName;
758 //wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);// NOT USED
759 RegisterClass(&wndclass);
760 hwnd = CreateWindow(szAppName, "PRIMARY CRYPTION",
761 WS_CAPTION | WS_VISIBLE,
762 5, 5,
763 575, 280,
764 NULL, NULL, hInstance, NULL);
765 ShowWindow(hwnd, iCmdShow);
766 UpdateWindow(hwnd);
767 // Main Windows Program Loop; ends when the Quit message returns zero
768 for(;;)
769 { if(GetMessage(&msg, NULL, 0, 0))
770 { TranslateMessage(&msg);
771 DispatchMessage(&msg);
772 }
773 else
774 break; // GetMessage pulled a WM_QUIT and returned zero; exit!
775 }
776 // Windows programming is like a dance; the Operating System is
777 // willing to spend time executing your program-code as long as you
778 // let it take the "lead". WINDOWS interacts with the user, and
779 // Windows will pass messages to your program, telling it what the
780 // user wants. This tends to make your program a collection of
781 // disconnected blocks of code, each block waiting for the user to
782 // tell Windows to pass a message to it, to do its thing. On the
783 // other hand, as long as Windows knows that your program is doing a
784 // GetMessage()/TranslateMessage()/DispatchMessage() loop, it doesn't
785 // matter WHERE your program does it. (See the ProcessMessages()
786 // subroutine later on in the file.) This means your program can do
787 // stuff without always waiting for Windows to give the go-ahead, and
788 // in fact the original author of the CRYPTION program once used such
789 // a trick to make a large, developed-for-a-decade, multi-megabyte
790 // pure-DOS program (the kind that wants total control of all
791 // operations of the computer) co-exist with the Windows paradigm, AS
792 // IF it had become an ordinary Windows program. (Well, there was
793 // more to it than just that trick, but 90%+ of the original code did
794 // not need to be modified.)
795
796
797 // BEGIN ORGANIZED EXIT PROCESS
798 // CLEAN UP ALL ALLOCATED MEMORY
799 free(ucMemBlk1); // file I/O buffer
800 free(ucMemBlk2); // workspace
801 free(ucMemBlk3); // prime-search/index table
802 free(ucMemBlk4); // sorting are when preparing Index
803 // To clean up the linked list, we use the starting "anchor" and
804 while(afflist) // walk the list: while an item on this list exists
805 { affitem = afflist; // save the current item
806 afflist = afflist->next; // get a possible next item (may be NULL)
807 free(affitem); // delete current item
808 }
809 if(prmfil != NULL)
810 fclose(prmfil); // close the file
811 system("DEL .\\TMP*.CRP"); // Clean up after any
812 // abort-while-affecting-files
813 return(msg.wParam); // CRYPTION.EXE program terminates here
814 }; // PERSONAL PREFERENCE QUIRK of original author: The return
815 // statement in C is not a function, and so the value returned,
816 // msg.wParam here, does not need to be surrounded by parentheses.
817 // However, the return statement is LIKE a function-call -- such
818 // as system() or free() above, where parentheses are mandatory --
819 // in the sense that return can transmit a value elsewhere.
820 // Thus, mostly for the sake of "aesthetic consistency" does the
821 // original author prefer to associate parentheses with any return
822 // statement that transmits a value. The compiler does not care,
823 // and in some cases, such as when a complicated expression must be
824 // evaluated to produce the return-value, parentheses often make
825 // sense for that reason alone, to clarify something to the
826 // compiler (or another human). So using parentheses generally for
827 // aesthetics means being consistent with the special case, also.
|