home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 337_01 / makehelp.c < prev    next >
C/C++ Source or Header  |  1991-01-14  |  4KB  |  168 lines

  1. /* Copyright (c) James L. Pinson 1990,1991  */
  2.  
  3. /**********************   MAKEHELP.C   ***************************/
  4.  
  5. /*
  6. link with :
  7. hlp_menu.c
  8. hlp_io.c
  9. */
  10.  
  11. #include "mydef.h"
  12. #include "help.h"
  13. #include <stdio.h>
  14.  
  15. struct hlp help;
  16.  
  17.  
  18. int start(void)      /* start is the entry point */
  19. {
  20. extern struct hlp help;
  21. extern struct screen_structure scr;
  22. extern struct window_structure w[];
  23.  
  24. cls();
  25.  get_name(help.filename);       /* select a filename */
  26.  if(help.filename[0]=='\0'){    /* if none selected */
  27.   win_delete_top();
  28.   cls();
  29.   print(1,1,"A file must be selected.");
  30.   exit();
  31.  }
  32.  
  33.   /* make the three windows */
  34.  help.edit=  win_make(2,3,help.width,help.height,STD_FRAME,
  35.                      "Edit: Then 'Esc' ",scr.normal,scr.normal);
  36.  help.menu=  win_make(1,1,80,1,NO_FRAME,"",scr.inverse,scr.inverse);
  37.    cursor(NO_CURSOR);
  38.  help.status= win_make(1,25,80,1,NO_FRAME,"",scr.inverse,
  39.                        scr.inverse);
  40.    cursor(NO_CURSOR);
  41.   main_menu();    /* call the first menu */
  42.  
  43. /* clean up to exit */
  44.   win_delete (help.edit);
  45.   win_delete (help.menu);
  46.   win_delete (help.status);
  47.  
  48. return (0);
  49. }
  50.  
  51. /* this function allows editing of the help window */
  52.  
  53. void edit(int x, int y)
  54. {
  55. extern struct screen_structure scr;
  56. extern struct window_structure w[];
  57.  
  58. char string[2];
  59. char ch,ext;
  60.  
  61.  scr.current=win_what_attr(help.edit);
  62.  ch= 0;
  63.     while(ch != ESCAPE) {       /* read while key not 'Esc' */
  64.      ch=0;ext=0;
  65.      get_key(&ch,&ext);
  66.  
  67.       /* break while{} loop if PgUp or PgDn */
  68.       if(ext==PGUP || ext==PGDN) break;  
  69.  
  70.        if(ch  > 31){                /* if character */
  71.         string[0]=ch;string[1]='\0';/* build a string */
  72.         print_here(string);         /* put on screen */
  73.        x++;                         /* increment cursor location */
  74.       }
  75.       else{
  76.         switch (ext){              /* if cursor key */
  77.          case UP:y-- ;break;       /* act accordingly*/
  78.          case DOWN:y++ ;break;
  79.          case LEFT:x-- ;break;
  80.          case RIGHT:x++ ;break;
  81.          case HOME:x=1 ;break;
  82.          case END:x=scr.right-scr.left+1;break;
  83.         }
  84.      } /* end else */
  85.        if (ch==BACKSPACE)x--;
  86.        if(ch==RETURN){
  87.          x=1;
  88.          y++;
  89.        }
  90.  
  91.        /* the following code adjusts the cursor within the window */
  92.  
  93.        if(scr.left+x-1<scr.left){  /* too far left */
  94.           x=scr.right-scr.left+1;
  95.           y--;
  96.         }
  97.  
  98.        if(scr.left+x-1>scr.right){x=1;y++;};    /* goto next line */
  99.        if(scr.top+y-1<scr.top)y=scr.bottom-scr.top+1;
  100.        if(scr.top+y-1>scr.bottom)y=1;
  101.  
  102.          if (ch=='\b') print(x,y," ");
  103.          gotoxy(x,y);
  104.  
  105.    } /* end while ch!=27 */
  106.  
  107.    x=1;y=1;
  108.    gotoxy(x,y);
  109. }
  110.  
  111. /* this function creates an input screen for entry
  112.    of new help screen sizes */
  113.  
  114. int get_size()
  115. {
  116. char width[3]="";
  117. char height[3]="";
  118. int in_window;
  119. int return_code;
  120.  
  121. struct in_struc in_scrn[3]= {
  122.  
  123. /*
  124. X   Y  Label name          Ptr   Length  Label-color  Field color */
  125.  
  126. 1,  3, "Width  (10-78): ", NULL, 2,      WHITE,BLACK, BLACK,WHITE,
  127. 1,  4, "Height (5-23):  ", NULL, 2,      WHITE,BLACK, BLACK,WHITE,
  128. 0   /* terminator */
  129. };
  130.        in_scrn[0].ptr =width;
  131.        in_scrn[1].ptr =height;
  132.  
  133.   cls();
  134.   in_window= win_make(1,1,78,5,STD_FRAME,"",scr.normal,scr.normal);
  135.  
  136.   print(1,1,"PLEASE ENTER HELP SCREEN SIZE:");
  137.   return_code = input(in_scrn);
  138.   if(return_code==ESCAPE)
  139.      return(return_code);
  140.   else{
  141.        help.width=atoi(width);       /* convert to integer */
  142.        help.height=atoi(height);
  143.       }
  144.   win_delete(in_window);
  145.   return(0);
  146. }
  147.  
  148.  
  149. /* val_field() is used by input routine to check validity of data */
  150.  
  151. int val_field( char *string,int length,int field_number)
  152. {
  153. int value;
  154.  
  155.  /* in this demo "length" is not used */
  156.  
  157.  int age;
  158.  
  159.  switch (field_number){
  160.   case 0: value=atoi(string);         /* convert string to integer */
  161.           if (value <10 || value >78) return(REDO);
  162.            break;
  163.   case 1: value=atoi(string);         /* convert string to integer */
  164.           if (value <5 || value >23) return(REDO);
  165.  }
  166. return (OK);
  167. }
  168.