home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / SCREDIT2.ZIP / SCRDEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-02  |  13.3 KB  |  380 lines

  1. /*
  2. Read ScrEdit.Tut for a description of how to use this program.
  3. */
  4. #include <alloc.h>
  5. #include <stdio.h>
  6. #include <conio.h>
  7. #include <string.h>
  8. #include <ctype.h>
  9.  
  10. /*
  11. Before you can compile this program you must use the OPTION/DIRECTORIES/INCLUDE
  12.    and the OPTION/DIRECTORIES/LIBRARY to specifie the location on your system     files, you must also specifie the location of the library menu.
  13.    of SCREDIT.H and SCREDIT.C.
  14.  
  15.    Don't forget to specifie a the project files SCRDEMO.PRJ in the
  16.    PROJECT/PROJECT FILE menu. You must place the drive, path, and file name
  17.    in the project file:
  18.  
  19.    (COMPACT) Example: ScrDemo C:\Pascal\ScrEdit\ScrEdit.C
  20.    (LARGE or
  21.     HUGE)    Example: ScrDemo C:\Pascal\ScrEdit\ScrEdit.Lib
  22.  
  23. */
  24. #include "scredit.h"
  25.  
  26. #include "SCRDEMO.001"
  27. #include "SCRDEMO.002"
  28.  
  29. int Option,
  30.     Screen_Mode,
  31.     Cursor_Position;
  32.  
  33.  
  34. void Back_To_Turbo_C_Land()
  35. {
  36. char Response[11];
  37. Response[0] = 0;
  38.  
  39. textbackground(BLACK);
  40. textcolor     (YELLOW);
  41.  
  42. while (strcmp("RETURN",Response)!= 0)
  43.     {
  44.     clrscr();
  45.     cprintf("This is regular 'C' code now.\r\n\r\n");
  46.     cprintf("You can do anything now that you want to, use any \r\n");
  47.     cprintf("programming statement that you wish to.  When you \r\n");
  48.     cprintf("are ready to resume with Turbo ScrEdit just return \r\n");
  49.     cprintf("and the screen will be reloaded and you will resume \r\n");
  50.     cprintf("at the point where you left the screen.\r\n\r\n");
  51.     cprintf("Type 'RETURN' in upper case to end this example...");
  52.     Response[0]=6;
  53.     cscanf("%s",Response);
  54.     }
  55. textbackground(BLACK);
  56. textcolor     (GREEN);
  57. }
  58.  
  59. void ProcessScreen()
  60. {
  61. S_ShowStatus = 0;
  62. if  (Screen_Mode==1)
  63.     {
  64.     Cursor_Position = Demo_Screen_buf.OP;
  65.     switch (Cursor_Position){
  66.         case 0 : {S_Point = S_FirstField;break;}
  67.         case 1 : {S_Point = 1 ;break;}
  68.         case 2 : {S_Point = 4 ;break;}
  69.         case 3 : {S_Point = 11;break;}
  70.         case 4 : {S_Point = 8 ;break;}
  71.         }
  72.     }
  73.  
  74. if  (Screen_Mode == 2)
  75.     {
  76.     Cursor_Position = Demo_Screen_buf.OP;
  77.     S_Point ++;
  78.     switch (Cursor_Position){
  79.         case 0 :{S_Point = 0;
  80.                  break;
  81.                 }
  82.         case 1 :{if ((S_Point > 3)|| (S_Point < 1)) S_Point = 1;
  83.                  break;
  84.                 }
  85.         case 2 :{if ((S_Point > 9)||(S_Point < 4)) S_Point = 4;
  86.                  if (S_Point == 8) S_Point = 9;
  87.                  break;
  88.                 }
  89.         case 3 :{if ((S_Point > 12)||(S_Point < 11)) S_Point = 11;
  90.                  break;
  91.                 }
  92.         case 4 :{if ((S_Point > 10)||(S_Point < 8)) S_Point = 8;
  93.                  if (S_Point == 9) S_Point = 10;
  94.                  break;
  95.                 }
  96.         }
  97.     }
  98.  
  99. strcpy(S_Msg," <F1>=Initialize  <F2>=Return to Menu ");
  100.  
  101. switch (Screen_Mode){
  102.     case 2 : {S_ReadField()     ;break;}
  103.     case 1 : {S_ReadScreen()    ;break;}
  104.     }
  105.  
  106. if  (S_Fkey)
  107.     {
  108.     if  ((!S_Shift)&&(!S_Ctrl)&&(!S_Alt))
  109.         {
  110.         if  (S_F1)
  111.             {
  112.             Initialize_Demo_Screen_buf();
  113.             S_Point = S_FirstField;
  114.             strcpy(S_Msg,"Screen has been initialized.");
  115.             }
  116.         if  (S_F2)
  117.             S_LoadScreen("Demo_Menu");
  118.         }
  119.     }
  120. }
  121.  
  122.  
  123. void ScrDemo_Init()
  124. {
  125. S_OpenScreenFile("ScrDemo.SCR");
  126. Initialize_Demo_Menu_buf();
  127. Initialize_Demo_Screen_buf();
  128. Option       = 1;
  129. S_Sound      = 1;
  130. S_Cursor     = S_NORMAL;/* other options S_BLOCK, S_OFF */
  131.  
  132. textbackground(BLACK);
  133. textcolor     (GREEN);
  134.  
  135. S_LoadScreen("Demo_Menu");
  136. }
  137.  
  138.  
  139. void Read_Menu_Screen()
  140. {
  141. int X,Y,Z;
  142. S_ShowStatus = 1;
  143. while (!S_Esc)
  144.     {
  145.     memset(&Demo_Menu_buf,0,sizeof(Demo_Menu_buf));
  146.  
  147.     strcpy(Demo_Menu_buf.O1, "This Menu");
  148.     strcpy(Demo_Menu_buf.O2, "Using S_ReadScreen");
  149.     strcpy(Demo_Menu_buf.O3, "Using S_ReadField");
  150.     strcpy(Demo_Menu_buf.O4, "Using S_ReadKey");
  151.     strcpy(Demo_Menu_buf.O5, "Using S_NextKey");
  152.     strcpy(Demo_Menu_buf.O6, "Using Windows");
  153.     strcpy(Demo_Menu_buf.O7, "Using The Message Line");
  154.     strcpy(Demo_Menu_buf.O8 ,"Mixed ScrEdit");
  155.     strcpy(Demo_Menu_buf.O13,"Display remaining heap");
  156.  
  157.     if  (Option < 1) Option = 9;
  158.     if  (Option > 9) Option = 1;
  159.  
  160.     switch (Option) {
  161.        case 1  : {
  162.            strcpy(Demo_Menu_buf.P1,"==>");
  163.            strcpy(Demo_Menu_buf.M1,"To use this menu, have a listing of the");
  164.            strcpy(Demo_Menu_buf.M2,"file SCRDEMO.C with you and follow");
  165.            strcpy(Demo_Menu_buf.M3,"each of the examples through the 'C'");
  166.            strcpy(Demo_Menu_buf.M4,"code. This program is designed to help");
  167.            strcpy(Demo_Menu_buf.M5,"you understand how to implement Turbo");
  168.            strcpy(Demo_Menu_buf.M6,"ScrEdit procedures in your programs.");
  169.            break;
  170.            }
  171.        case 2  : {
  172.            strcpy(Demo_Menu_buf.P2,"==>");
  173.            strcpy(Demo_Menu_buf.M1,"S_ReadScreen - process an entire screen");
  174.            strcpy(Demo_Menu_buf.M2,"with one call. Control returns to your ");
  175.            strcpy(Demo_Menu_buf.M3,"program when ENTER, UP or DOWN arrows,");
  176.            strcpy(Demo_Menu_buf.M4,"HOME, END, PGUP, PGDN, INSERT, DEL, one");
  177.            strcpy(Demo_Menu_buf.M5,"the F keys, or any key is pressed in");
  178.            strcpy(Demo_Menu_buf.M6,"conjuction with ALT or CTRL keys.");
  179.            break;
  180.            }
  181.        case 3  : {
  182.            strcpy(Demo_Menu_buf.P3,"==>");
  183.            strcpy(Demo_Menu_buf.M1,"S_ReadField - Process a single screen");
  184.            strcpy(Demo_Menu_buf.M2,"field at a time. Control returns to");
  185.            strcpy(Demo_Menu_buf.M3,"your program when the cursor is moved");
  186.            strcpy(Demo_Menu_buf.M4,"off of the field with the left or right");
  187.            strcpy(Demo_Menu_buf.M5,"arrow keys, TAB key, or Any of the");
  188.            strcpy(Demo_Menu_buf.M6,"other keys listed with S_ReadScreen.");
  189.            break;
  190.            }
  191.        case 4  : {
  192.            strcpy(Demo_Menu_buf.P4,"==>");
  193.            strcpy(Demo_Menu_buf.M1,"S_ReadKey - This demonstrates how to");
  194.            strcpy(Demo_Menu_buf.M2,"display a message on the message line");
  195.            strcpy(Demo_Menu_buf.M3,"and accept a keystroke response from");
  196.            strcpy(Demo_Menu_buf.M4,"the user. The key pressed does not");
  197.            strcpy(Demo_Menu_buf.M5,"echo to the screen and will not be");
  198.            strcpy(Demo_Menu_buf.M6,"placed in any screen field.");
  199.            break;
  200.            }
  201.        case 5  : {
  202.            strcpy(Demo_Menu_buf.P5,"==>");
  203.            strcpy(Demo_Menu_buf.M1,"S_NextKey - This demonstrates how to");
  204.            strcpy(Demo_Menu_buf.M2,"read the next key pressed only. No");
  205.            strcpy(Demo_Menu_buf.M3,"message can be displayed. Turbo Scredit");
  206.            strcpy(Demo_Menu_buf.M4,"waits for the next key pressed and");
  207.            strcpy(Demo_Menu_buf.M5,"returns to your program.");
  208.            break;
  209.            }
  210.        case 6  : {
  211.            strcpy(Demo_Menu_buf.P6,"==>");
  212.            strcpy(Demo_Menu_buf.M1,"A method of using windows to display");
  213.            strcpy(Demo_Menu_buf.M2,"data on your screens and then restore");
  214.            strcpy(Demo_Menu_buf.M3,"the screen to its original state.");
  215.            break;
  216.            }
  217.        case 7  : {
  218.            strcpy(Demo_Menu_buf.P7,"==>");
  219.            strcpy(Demo_Menu_buf.M1,"Demonstrates several way of using");
  220.            strcpy(Demo_Menu_buf.M2,"the message line to communicate with");
  221.            strcpy(Demo_Menu_buf.M3,"the user of your program.");
  222.            break;
  223.            }
  224.        case 8  : {
  225.            strcpy(Demo_Menu_buf.P8,"==>");
  226.            strcpy(Demo_Menu_buf.M1,"This demonstrates how you can exit a");
  227.            strcpy(Demo_Menu_buf.M2,"procedure using a Turbo ScrEdit screen");
  228.            strcpy(Demo_Menu_buf.M3,"to use your language's standard input");
  229.            strcpy(Demo_Menu_buf.M4,"and output statements, and then resume");
  230.            strcpy(Demo_Menu_buf.M5,"using Turbo ScrEdit when you wish.");
  231.            break;
  232.            }
  233.        case 9 : {
  234.            strcpy(Demo_Menu_buf.P13,"==>");
  235.            strcpy(Demo_Menu_buf.M1,"Display the current remaining heap ");
  236.            strcpy(Demo_Menu_buf.M2,"and farheap memory that has not ");
  237.            strcpy(Demo_Menu_buf.M3,"been allocated.");
  238.            break;
  239.            }
  240.        }
  241.  
  242.  
  243.     S_ResetKeyFlags();
  244.     while ((!S_Esc)&&(!S_Enter)&&(!S_Fkey))
  245.         {
  246.         S_ReadKey();
  247.         if  ((S_Up)||(S_Down)||(S_Enter)||(S_Esc))
  248.             {
  249.             if  (S_Down) Option++;
  250.             if  (S_Up)   Option--;
  251.             if  (S_Enter)
  252.                 {
  253.                 if  (Option==1)
  254.                     strcpy(S_Msg,
  255.                        " Please read the text in the Option Description window.");
  256.                 if  (Option == 2)
  257.                     {
  258.                     Screen_Mode = 1;
  259.                     Initialize_Demo_Screen_buf();
  260.                     S_LoadScreen("Demo_Screen");
  261.                     while (!S_F2) ProcessScreen();
  262.                     }
  263.                 if  (Option == 3)
  264.                     {
  265.                     Screen_Mode = 2;
  266.                     Initialize_Demo_Screen_buf();
  267.                     S_LoadScreen("Demo_Screen");
  268.                     while (!S_F2) ProcessScreen();
  269.                     }
  270.                 if  (Option == 4)
  271.                     {
  272.                     strcpy(S_Msg,
  273.                            "Demo of S_READKEY - Press 'C' key to continue");
  274.                     do{
  275.                         S_ReadKey();
  276.                         strcpy(S_Msg,
  277.                                "OOPS!! wrong key - Press 'C' key to continue");
  278.                       } while ((S_Ch!='C')&&(S_Ch!='c'));
  279.  
  280.                     strcpy(S_Msg," 'C' has been pressed - You may continue");
  281.                     }
  282.                 if  (Option == 5)
  283.                     {
  284.                     for (X=1;X<7;X++){
  285.                         gotoxy(39,14+X);
  286.                         cprintf("                                         ");}
  287.                     gotoxy(39,17);
  288.                     cprintf(" << OKAY PRESS A SHIFT C to CONTINUE >>");
  289.                     do{
  290.                        S_NextKey();
  291.                        S_Ch = toupper(S_Ch);
  292.                       } while (!((S_Shift)&&(S_Ch=='C')));
  293.                     }
  294.                 if  (Option == 6)
  295.                     {
  296.                     textcolor(BLACK);
  297.                     Y = 1;
  298.                     for (X=1;X<5;X++)
  299.                         {
  300.                         textbackground(Y++);
  301.                         window(X*5,(X*2),(X*5)+40,(X*2)+10);
  302.                         clrscr();
  303.                         cprintf("This is window %d",X);
  304.                         }
  305.                     window(66,11,66,21);
  306.                     textbackground(BLUE);
  307.                     textcolor(CYAN);
  308.                     for (X=1;X<12;X++){
  309.                         cprintf("░");}
  310.                     window(26,21,67,21);
  311.                     gotoxy(1,X);
  312.                     cprintf("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
  313.                     window(25,10,65,20);
  314.                     clrscr();
  315.                     textcolor(WHITE);
  316.                     gotoxy(10,5);cprintf("<<< These are windows >>>");
  317.                     gotoxy(10,7);cprintf(" Press any key to Exit..");
  318.                     S_NextKey();
  319.                     window(1,1,80,25);
  320.                     textbackground(BLACK);
  321.                     textcolor(GREEN);
  322.                     S_LoadScreen("Demo_Menu");
  323.                     }
  324.                 if  (Option == 7)
  325.                     {
  326.                     strcpy(S_Msg,"Do You want to continue Y/N ");
  327.                     do{
  328.                       S_ReadKey();
  329.                       S_Ch = toupper(S_Ch);
  330.                       if  ((S_Ch=='Y')||(S_Ch=='N'))
  331.                           {
  332.                           if  (S_Ch=='N')
  333.                               strcpy(S_Msg," How about now..Do you want to continue? Y/N ");
  334.                           }
  335.                       else
  336.                           {
  337.                           if (S_Ch < 32) S_Ch = 32;
  338.                           strcpy(S_Msg,"< > Please respond with Y or N");
  339.                           S_Msg[1] = S_Ch;
  340.                           }
  341.                       }while (S_Ch!='Y');
  342.                     strcpy(S_Msg,"Ok you may continue");
  343.                     }
  344.                 if  (Option == 8)
  345.                     {
  346.                     Back_To_Turbo_C_Land();
  347.                     S_LoadScreen("Demo_Menu");
  348.                     }
  349.                 if  (Option == 9)
  350.                     {
  351.                     for (X=1;X<7;X++){
  352.                         gotoxy(39,14+X);
  353.                         cprintf("                                         ");}
  354.                     gotoxy(39,16);
  355.                     cprintf("coreleft    = %lu",(unsigned long)coreleft());
  356.                     gotoxy(39,17);
  357.                     cprintf("farcoreleft = %lu",(unsigned long)farcoreleft());
  358.                     S_NextKey();
  359.                     }
  360.                 S_ShowStatus = 1;
  361.                 S_ResetKeyFlags();
  362.                 }
  363.             }
  364.         else
  365.           strcpy(S_Msg," Only UP and DOWN arrows and ENTER and ESC are valid");
  366.         }
  367.     }
  368. }
  369.  
  370.  
  371.  
  372.  
  373. void main()
  374. {
  375. ScrDemo_Init();
  376. while (!S_Esc) Read_Menu_Screen();
  377. S_CloseScreenFile();
  378. gotoxy(1,24);
  379. }
  380.