home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / c_source.arj / IIBCLIB.C next >
Encoding:
C/C++ Source or Header  |  1990-08-08  |  77.2 KB  |  3,048 lines

  1. #include <iibclib.h>
  2. #include <iibdb.h>
  3.  
  4. static char emp[] = "Press any key to continue";
  5.  
  6. int scroll( int direction,
  7.             int rulh,
  8.             int culh,
  9.             int rbrh,
  10.             int cbrh,
  11.             int scrl_lines,
  12.             int attrib)
  13.  
  14. {
  15.   union REGS inregs;
  16.  
  17.   inregs.h.ah = (unsigned char) direction;
  18.   inregs.h.al = (unsigned char) scrl_lines;
  19.   inregs.h.ch = (unsigned char)(rulh-1);
  20.   inregs.h.cl = (unsigned char)(culh-1);
  21.   inregs.h.dh = (unsigned char)(rbrh-1);
  22.   inregs.h.dl = (unsigned char)(cbrh-1);
  23.   inregs.h.bh = (unsigned char)(attrib);
  24.  
  25.   int86(0x10,&inregs,&inregs);
  26.  
  27.   return(0);
  28.  
  29. } /* end scroll */
  30. /*---------------------------------------------------------------------------*/
  31.  
  32.  
  33. void print_message(char *message,
  34.                    int rulh,
  35.                    int culh)
  36.  
  37. {
  38.   int m_length;
  39.  
  40.   m_length = strlen(message);
  41.   _settextwindow(rulh,culh,rulh,80-culh+1);
  42.   _clearscreen(_GWINDOW);
  43.   _settextposition(1,2);
  44.   _outtext(message);
  45.   _settextposition(1,culh + m_length + 3);
  46.   _outtext(emp);
  47.   my_wait();
  48.   _clearscreen(_GWINDOW);
  49. } /* end print_message */
  50. /*---------------------------------------------------------------------------*/
  51.  
  52.  
  53. void frame(int rulh,
  54.            int culh,
  55.            int rows,
  56.            int columns,
  57.            int frground,
  58.            long bkground)
  59.  
  60. {
  61.   int i;
  62.   int rbrh;
  63.   int cbrh;
  64.   char frame_char[2];
  65.  
  66.   frame_char[0] = '\0';
  67.   frame_char[1] = '\0';
  68.  
  69.   _settextcolor(frground);
  70.   _setbkcolor(bkground);
  71.   _settextwindow(1,1,25,80);
  72.  
  73.   rbrh = rulh + rows - 1;
  74.   cbrh = culh + columns - 1;
  75.  
  76.   frame_char[0] = '═';
  77.   for (i=culh+1;i<=cbrh;i++ )
  78.   {
  79.     _settextposition(rulh,i);
  80.     _outtext(frame_char);
  81.     _settextposition(rbrh,i);
  82.     _outtext(frame_char);
  83.   } /* endfor */
  84.  
  85.   frame_char[0] = '║';
  86.   for (i=rulh+1; i<rbrh; i++)
  87.   {
  88.     _settextposition(i,culh);
  89.     _outtext(frame_char);
  90.     _settextposition(i,cbrh);
  91.     _outtext(frame_char);
  92.   } /* endfor */
  93.  
  94.   frame_char[0] = '╔';
  95.   _settextposition(rulh,culh);
  96.   _outtext(frame_char);
  97.  
  98.   frame_char[0] = '╚';
  99.   _settextposition(rbrh,culh);
  100.   _outtext(frame_char);
  101.  
  102.   frame_char[0] = '╗';
  103.   _settextposition(rulh,cbrh);
  104.   _outtext(frame_char);
  105.  
  106.   frame_char[0] = '╝';
  107.   _settextposition(rbrh,cbrh);
  108.   _outtext(frame_char);
  109. } /* end frame */
  110. /*---------------------------------------------------------------------------*/
  111.  
  112.  
  113. void show_option(int row,
  114.                  int col,
  115.                  char *message,
  116.                  char justify_flag,
  117.                  int frgrd_clr,
  118.                  long bkgrd_clr)
  119.  
  120. {
  121.   _wrapon(_GWRAPOFF);
  122.   switch (justify_flag)
  123.   {
  124.     case 'l':
  125.     case 'L':
  126.       _settextwindow(row,col,row,col+strlen(message)-1);
  127.       break;
  128.     case 'c':
  129.     case 'C':
  130.       _settextwindow(row,col-strlen(message)/2,row,col+strlen(message)/2);
  131.       break;
  132.     case 'r':
  133.     case 'R':
  134.       _settextwindow(row,col-strlen(message)+1,row,col);
  135.       break;
  136.     default :
  137.       _settextposition(1,1);
  138.   } /* endswitch */
  139.   _settextcolor(frgrd_clr);
  140.   _setbkcolor(bkgrd_clr);
  141.   _settextposition(1,1);
  142.   _outtext(message);
  143.   _settextcolor(env.frgrd[0]);
  144.   _setbkcolor(env.bkgrd[0]);
  145.   _settextwindow(1,1,25,80);
  146. } /* end show_option */
  147. /*---------------------------------------------------------------------------*/
  148.  
  149.  
  150. char box_message(int bell_flag,
  151.                  int shadow_flag,
  152.                  char *message1,
  153.                  char *message2,
  154.                  char *message3)
  155.  
  156. {
  157.   char choice;
  158.  
  159.   if (bell_flag)
  160.   {
  161.     putchar(BELL);
  162.   } /* endif */
  163.   if (shadow_flag)
  164.   {
  165.     _setbkcolor(0L);
  166.     _settextwindow(11,12,16,72);
  167.     _clearscreen(_GWINDOW);
  168.   } /* endif */
  169.   _settextcolor(15);
  170.   _setbkcolor(4L);
  171.   _settextwindow(10,10,15,70);
  172.   _clearscreen(_GWINDOW);
  173.   _settextposition(2,2);
  174.   _outtext(message1);
  175.   _settextposition(3,2);
  176.   _outtext(message2);
  177.   _settextposition(4,2);
  178.   _outtext(message3);
  179.   choice = (char)getch();
  180.   _settextcolor(env.frgrd[0]);
  181.   _setbkcolor(env.bkgrd[0]);
  182.   _settextwindow(1,1,25,80);
  183.   _clearscreen(_GWINDOW);
  184.   return(choice);
  185. } /* end box_message */
  186. /*---------------------------------------------------------------------------*/
  187.  
  188.  
  189. void display_message(char *message)
  190.  
  191. {
  192.  
  193.   _settextcolor(env.frgrd[0]);
  194.   _setbkcolor(env.bkgrd[0]);
  195.   _settextwindow(1,1,25,80);
  196.   _clearscreen(_GWINDOW);
  197.   _setbkcolor(0L);
  198.   _settextwindow(11,12,16,72);
  199.   _clearscreen(_GWINDOW);
  200.   _settextcolor(env.frgrd[5]);
  201.   _setbkcolor(env.bkgrd[5]);
  202.   _settextwindow(10,10,15,70);
  203.   _clearscreen(_GWINDOW);
  204.   _settextposition(3,2);
  205.   _outtext(message);
  206.   _settextcolor(env.frgrd[0]);
  207.   _setbkcolor(env.bkgrd[0]);
  208. } /* end display_message */
  209. /* ------------------------------------------------------------------ */
  210.  
  211.  
  212. int set_cursor_off()
  213.  
  214. {
  215.   union REGS inregs;
  216.  
  217.   inregs.h.ah = 1;
  218.   inregs.h.ch = 32;
  219.   inregs.h.cl = 0;
  220.  
  221.   int86(0x10,&inregs,&inregs);
  222.  
  223.   return(0);
  224.  
  225. } /* end set_cursor_off */
  226. /* ------------------------------------------------------------------ */
  227.  
  228.  
  229. int set_cursor_on(int start_line,
  230.                   int end_line)
  231.  
  232. {
  233.   union REGS inregs;
  234.  
  235.   inregs.h.ah = 1;
  236.   inregs.h.ch = (unsigned char)start_line;
  237.   inregs.h.cl = (unsigned char)end_line;
  238.  
  239.   int86(0x10,&inregs,&inregs);
  240.  
  241.   return(0);
  242.  
  243. } /* end set_cursor_on */
  244. /* ------------------------------------------------------------------ */
  245.  
  246. void my_wait()
  247.  
  248. {
  249.   while (!kbhit())
  250.   {
  251.     ;
  252.   } /* endwhile */
  253.   getche();
  254. }  /* end my_wait() */
  255. /*---------------------------------------------------------------------------*/
  256.  
  257.  
  258. int get_string( int frame_flag,
  259.                 char *field,
  260.                 int new_or_old,
  261.                 int all_upper,
  262.                 int  rulh,
  263.                 int culh,
  264.                 int length)
  265.  
  266. {
  267.   char temp_buf[80];
  268.   char input = '\0';
  269.   int i;
  270.   int quit = 0;
  271.   int clean_flag = 1;
  272.   int t_changed = 0;
  273.   int insert_flag = 0;
  274.   int goon = 1;
  275.   int cur_pos = 0;
  276.   int input_count = 0;
  277.   int r_code;
  278.  
  279.   _settextcolor(env.frgrd[5]);
  280.   _setbkcolor(env.bkgrd[5]);
  281.  
  282.   if (frame_flag)
  283.   {
  284.     _settextwindow(rulh,culh,rulh,culh+length+1);
  285.     _wrapon(_GWRAPOFF);
  286.     _clearscreen(_GWINDOW);
  287.     _settextposition(1,1);
  288.     _outtext("[");
  289.     _settextposition(1,length+2);
  290.     _outtext("]");
  291.     _settextwindow(rulh,culh+1,rulh,culh+length);
  292.   }
  293.   else
  294.   {
  295.     _settextwindow(rulh,culh,rulh,culh+length-1);
  296.     _wrapon(_GWRAPOFF);
  297.     _clearscreen(_GWINDOW);
  298.   } /* endif */
  299.  
  300.   if (new_or_old == OLD)
  301.   {
  302.     input_count = cur_pos = strlen(field);
  303.   }
  304.   else
  305.   {
  306.     field[0] = '\0';
  307.   } /* endif */
  308.  
  309.   do
  310.   {
  311.     if (frame_flag)
  312.     {
  313.       _settextwindow(rulh,culh+1,rulh,culh+length);
  314.       _clearscreen(_GWINDOW);
  315.       _settextwindow(rulh,culh+1,rulh,culh+length+2);
  316.       _settextposition(1,1);
  317.     }
  318.     else
  319.     {
  320.       _settextwindow(rulh,culh,rulh,culh+length-1);
  321.       _clearscreen(_GWINDOW);
  322.       _settextwindow(rulh,culh,rulh,culh+length);
  323.       _settextposition(1,1);
  324.     } /* endif */
  325.     _outtext(field);
  326.     _settextposition(1,cur_pos + 1);
  327.     clean_flag = 0;
  328.     t_changed = 0;
  329.  
  330.     input = (char)getch();
  331.  
  332.     if (input == '\0')
  333.     {
  334.       input = (char)getch();
  335.       switch (input)
  336.       {
  337.         case INS_KEY:
  338.           if (insert_flag)
  339.           {
  340.             show_option(25,80,"INSERT = OFF",'R',env.frgrd[2],env.bkgrd[2]);
  341.             insert_flag = 0;
  342.           }
  343.           else
  344.           {
  345.             show_option(25,80,"INSERT = ON ",'R',env.frgrd[2],env.bkgrd[2]);
  346.             insert_flag = 1;
  347.           } /* endif */
  348.           _settextwindow(rulh,culh+1,rulh,culh+length);
  349.           _settextcolor(env.frgrd[5]);
  350.           _setbkcolor(env.bkgrd[5]);
  351.           break;
  352.         case UP_ARROW:
  353.           putchar(BELL);
  354.           break;
  355.         case DOWN_ARROW:
  356.           putchar(BELL);
  357.           break;
  358.         case HOME:
  359.           cur_pos= 0;
  360.           break;
  361.         case END:
  362.           cur_pos=input_count;
  363.           break;
  364.         case LEFT_ARROW:
  365.           if (cur_pos > 0)
  366.           {
  367.             cur_pos--;
  368.           }
  369.           else
  370.           {
  371.             putchar(BELL);
  372.           } /* endif */
  373.           break;
  374.         case RIGHT_ARROW:
  375.           if (cur_pos < input_count)
  376.           {
  377.             cur_pos++;
  378.           }
  379.           else
  380.           {
  381.             putchar(BELL);
  382.           } /* endif */
  383.           break;
  384.         case DEL_KEY:
  385.           if (input_count == 0 || cur_pos == input_count)
  386.           {
  387.             putchar(BELL);
  388.           }
  389.           else
  390.           {
  391.             strcpy(temp_buf,field);
  392.             for (i=0; i < cur_pos - 1; i++)
  393.             {
  394.               field[i] = temp_buf[i];
  395.             } /* endfor */
  396.             for (i = cur_pos; i < input_count; i++)
  397.             {
  398.               field[i] = temp_buf[i+1];
  399.             } /* endfor */
  400.             input_count--;
  401.             t_changed++;
  402.             field[input_count] = '\0';
  403.           } /* endif */
  404.           break;
  405.         case F1:
  406.           field[input_count] = '\0';
  407.           quit = 1;
  408.           r_code = strlen(field);
  409.           break;
  410.         default :
  411.           putchar(BELL);
  412.           break;
  413.       } /* endswitch */
  414.     }
  415.     else
  416.     {
  417.       if (input == '\033')
  418.       {
  419.         field[0] = '\0';
  420.         quit = 1;
  421.         r_code = -1;
  422.       }
  423.       else
  424.       {
  425.         if (input == '\015')
  426.         {
  427.           field[input_count] = '\0';
  428.           quit = 1;
  429.           r_code = strlen(field);
  430.         }
  431.         else
  432.         {
  433.           if (input == ',')
  434.           {
  435.             putchar(BELL);
  436.           }
  437.           else
  438.           {
  439.             if (input == '\b')
  440.             {
  441.               if (input_count == 0 || cur_pos == 0)
  442.               {
  443.                 putchar(BELL);
  444.               }
  445.               else
  446.               {
  447.                 if (cur_pos < input_count)
  448.                 {
  449.                   strcpy(temp_buf,field);
  450.                   for (i=0; i < cur_pos - 2; i++)
  451.                   {
  452.                     field[i] = temp_buf[i];
  453.                   } /* endfor */
  454.                   for (i = cur_pos - 1; i < input_count; i++)
  455.                   {
  456.                     field[i] = temp_buf[i+1];
  457.                   } /* endfor */
  458.                 } /* endif */
  459.                 cur_pos--;
  460.                 input_count--;
  461.                 t_changed++;
  462.                 field[input_count] = '\0';
  463.               } /* endif */
  464.             }
  465.             else
  466.             {
  467.               if (input_count < length)
  468.               {
  469.                 if (input_count == cur_pos)
  470.                 {
  471.                   if (all_upper)
  472.                   {
  473.                     field[input_count] = (char) toupper(input);
  474.                   }
  475.                   else
  476.                   {
  477.                     field[input_count] = input;
  478.                   } /* endif */
  479.                   field[input_count+1] = '\0';
  480.                   input_count++;
  481.                   cur_pos++;
  482.                   t_changed++;
  483.                 }
  484.                 else
  485.                 {
  486.                   if (insert_flag)
  487.                   {
  488.                     strcpy(temp_buf,field);
  489.                     for (i=0; i <= cur_pos - 1; i++)
  490.                     {
  491.                       field[i] = temp_buf[i];
  492.                     } /* endfor */
  493.                     if (all_upper)
  494.                     {
  495.                       field[cur_pos] = (char) toupper(input);
  496.                     }
  497.                     else
  498.                     {
  499.                       field[cur_pos] = input;
  500.                     } /* endif */
  501.                     for (i = cur_pos + 1; i <= input_count; i++)
  502.                     {
  503.                       field[i] = temp_buf[i-1];
  504.                     } /* endfor */
  505.                     input_count++;
  506.                     cur_pos++;
  507.                     field[input_count] = '\0';
  508.                     t_changed++;
  509.                   }
  510.                   else
  511.                   {
  512.                     putchar(BELL);
  513.                   } /* endif */
  514.                 } /* endif */
  515.               }
  516.               else
  517.               {
  518.                 putchar(BELL);
  519.               } /* endif */
  520.             } /* endif */
  521.           } /* endif */
  522.         } /* endif */
  523.       } /* endif */
  524.     } /* endif */
  525.   } while (!quit); /* enddo */
  526.  
  527.   _settextcolor(env.frgrd[0]);
  528.   _setbkcolor(env.bkgrd[0]);
  529.   _settextwindow(1,1,25,80);
  530.   return(r_code);
  531.  
  532. } /* end get_string */
  533. /* ------------------------------------------------------------------ */
  534.  
  535.  
  536. char yes_or_no(char *question,
  537.                int rulh,
  538.                int culh)
  539.  
  540. {
  541.   char temp;
  542.   int q_length;
  543.  
  544.   q_length = strlen(question);
  545.   _settextwindow(rulh,culh,rulh,q_length + 10);
  546.   _clearscreen(_GWINDOW);
  547.   _settextposition(1,2);
  548.   _outtext(question);
  549.   _settextposition(1,q_length);
  550.   _outtext(" (y/n) ?: ");
  551.   temp = (char)getchar();
  552.   if(temp == 'y'|| temp == 'Y' || temp == 'n'|| temp == 'N')
  553.   {
  554.     return((char)tolower((int)temp));
  555.   }
  556.   else
  557.   {
  558.     yes_or_no(question,rulh,culh);
  559.   } /* endif */
  560.  
  561. }  /* end yes_or_no() */
  562. /*---------------------------------------------------------------------------*/
  563.  
  564.  
  565. void jump_to_dos()
  566.  
  567. {
  568.   _clearscreen(_GWINDOW);
  569.   _settextposition(1,1);
  570.   _outtext("Do not load any new TSR (Terminate and Stay Resident) programs.\n");
  571.   _outtext("Type \'exit\' and press <RETURN> to return to this programs.\n");
  572.   _outtext(emp);
  573.   my_wait();
  574.   putenv("PROMPT=DOS SHELL (Type exit to return to program)$_$p$g");
  575.   _clearscreen(_GCLEARSCREEN);
  576.   system("command");
  577.  
  578. } /* end jump_to_dos */
  579. /*---------------------------------------------------------------------------*/
  580.  
  581.  
  582. int handler()
  583. {
  584.   signal(SIGINT, SIG_IGN);
  585.   signal(SIGINT,handler);
  586.   return(0);
  587. } /* end handler */
  588. /*---------------------------------------------------------------------------*/
  589.  
  590.  
  591. int get_menu_option(struct menu_line *my_line,
  592.                     int line_number,
  593.                     char *top_msg,
  594.                     char *bottom_msg,
  595.                     char *help_file,
  596.                     int  rulh,
  597.                     int culh)
  598.  
  599. {
  600.   int cur_line = 0;
  601.   int old_cur_line;
  602.   int cbrh = 0;
  603.   int rbrh = 0;
  604.  
  605.   unsigned int page_width = 0;
  606.   int i,j;
  607.   int quit =0;
  608.   int r_code = 0;
  609.  
  610.   char input;
  611.  
  612.   rbrh = rulh + line_number + 3;
  613.   for (i=0; i<line_number; i++)
  614.   {
  615.     if (cbrh < (int) strlen(my_line[i].line))
  616.     {
  617.       cbrh = strlen(my_line[i].line);
  618.     } /* endif */
  619.   } /* endfor */
  620.  
  621.   cbrh = culh + cbrh + 3;
  622.   cur_line = 1;
  623.   old_cur_line = 1;
  624.   page_width  = cbrh - culh - 1;
  625.  
  626.   frame(rulh,culh,rbrh - rulh + 1,page_width + 2,env.frgrd[2],env.bkgrd[2]);
  627.  
  628.   if (strlen(top_msg) < page_width)
  629.   {
  630.     show_option(rulh,(cbrh+culh)/2,top_msg,'C',env.frgrd[1],env.bkgrd[1]);
  631.   } /* endif */
  632.   if (strlen(bottom_msg) < page_width)
  633.   {
  634.     show_option(rbrh,(cbrh+culh)/2,bottom_msg,'C',env.frgrd[1],env.bkgrd[1]);
  635.   } /* endif */
  636.   _settextwindow(rulh + 1,culh + 1,rbrh - 1,cbrh - 1);
  637.   _settextcolor(env.frgrd[7]);
  638.   _setbkcolor(env.bkgrd[7]);
  639.   _clearscreen(_GWINDOW);
  640.   set_cursor_off();
  641.   _settextwindow(rulh + 2,culh + 2,rbrh - 2,cbrh - 2);
  642.   for (j=0 ; j < line_number; j++)
  643.   {
  644.     _settextcolor(env.frgrd[7]);
  645.     _setbkcolor(env.bkgrd[7]);
  646.     _settextposition(j+1,1);
  647.     _outtext(my_line[j].line);
  648.     _settextcolor(env.frgrd[7]);
  649.     _setbkcolor(env.bkgrd[7]);
  650.   } /* endfor */
  651.  
  652.   do
  653.   {
  654.  
  655.     time(&t_one);
  656.  
  657.     _settextwindow(rulh + 2,culh + 2,rbrh - 2,cbrh - 2);
  658.  
  659.     _settextcolor(env.frgrd[7]);
  660.     _setbkcolor(env.bkgrd[7]);
  661.     _settextposition(old_cur_line,1);
  662.     _outtext(my_line[old_cur_line-1].line);
  663.  
  664.     _settextcolor(env.frgrd[8]);
  665.     _setbkcolor(env.bkgrd[8]);
  666.     _settextposition(cur_line,1);
  667.     _outtext(my_line[cur_line-1].line);
  668.  
  669.     _settextcolor(env.frgrd[7]);
  670.     _setbkcolor(env.bkgrd[7]);
  671.  
  672.     while (!kbhit())
  673.     {
  674.       time(&t_two);
  675.       if (difftime(t_two,t_one) >= 1.00)
  676.       {
  677.         _strtime(time_buffer);
  678.         show_option(1,80,time_buffer,'R',env.frgrd[1],env.bkgrd[1]);
  679.         t_one = t_two;
  680.       } /* endif */
  681.     } /* endwhile */
  682.  
  683.     input = (char)getch();
  684.     if (input == '\0')
  685.     {
  686.       input = (char)getch();
  687.       switch (input)
  688.       {
  689.         case '\043':
  690.         case '\073':
  691.           if (help_file != NULL)
  692.           {
  693.             _setactivepage(1);
  694.             _setvisualpage(1);
  695.             _clearscreen(_GCLEARSCREEN);
  696.             if (show_small_file(help_file,0,help_file,NULL,NULL,1,1,25,80))
  697.             {
  698.                box_message(1,1,"Help file not present.",emp,NULL);
  699.             } /* endif */
  700.             _setactivepage(0);
  701.             _setvisualpage(0);
  702.             set_cursor_off();
  703.           } /* endif */
  704.           break;
  705.         case PAGE_UP:
  706.           old_cur_line = cur_line;
  707.           cur_line = 1;
  708.           break;
  709.         case UP_ARROW:
  710.           old_cur_line = cur_line;
  711.           cur_line--;
  712.           if (cur_line <= 0)
  713.           {
  714.             cur_line = line_number;
  715.           } /* endif */
  716.           break;
  717.         case PAGE_DOWN:
  718.           old_cur_line = cur_line;
  719.           cur_line = line_number;
  720.           break;
  721.         case DOWN_ARROW:
  722.           old_cur_line = cur_line;
  723.           cur_line++;
  724.           if (cur_line > line_number)
  725.           {
  726.             cur_line = 1;
  727.           } /* endif */
  728.           break;
  729.         case HOME:
  730.           old_cur_line = cur_line;
  731.           cur_line = 1;
  732.           break;
  733.         case END:
  734.           old_cur_line = cur_line;
  735.           cur_line = line_number;
  736.           break;
  737.         default :
  738.           break;
  739.       } /* endswitch */
  740.     }
  741.     else
  742.     {
  743.       if (isdigit(input) != 0)
  744.       {
  745.         old_cur_line = cur_line;
  746.         cur_line = (int)input - 48;
  747.         if (cur_line > line_number || cur_line < 0)
  748.         {
  749.           putchar(BELL);
  750.           cur_line = old_cur_line;
  751.         }
  752.         else
  753.         {
  754.           if (cur_line == 0)
  755.           {
  756.             cur_line = line_number;
  757.           } /* endif */
  758.           quit = 1;
  759.           r_code = cur_line;
  760.           break;
  761.         } /* endif */
  762.       }
  763.       else
  764.       {
  765.         switch (input)
  766.         {
  767.           case '\033':
  768.           case 'Q':
  769.           case 'q':
  770.             quit = 1;
  771.             r_code = -1;
  772.             break;
  773.           case '\015':
  774.             quit = 1;
  775.             r_code = cur_line;
  776.             break;
  777.           default :
  778.             break;
  779.         } /* endswitch */
  780.       } /* endif */
  781.     } /* endif */
  782.   } while (!quit); /* enddo */
  783.  
  784.   _settextwindow(1,1,25,80);
  785.   _settextcolor(env.frgrd[0]);
  786.   _setbkcolor(env.bkgrd[0]);
  787.   _clearscreen(_GWINDOW);
  788.  
  789.   set_cursor_on(7,7);
  790.   return(r_code);
  791.  
  792. } /* end get_menu_option */
  793. /*---------------------------------------------------------------------------*/
  794.  
  795.  
  796. int get_password(char *field,
  797.                  int all_upper,
  798.                  int rulh,
  799.                  int culh,
  800.                  int length)
  801.  
  802. {
  803.   char temp_buf[80];
  804.   char input = '\0';
  805.   int i,j;
  806.   int quit = 0;
  807.   int clean_flag = 1;
  808.   int t_changed = 0;
  809.   int insert_flag = 0;
  810.   int goon = 1;
  811.   int cur_pos = 0;
  812.   int input_count = 0;
  813.  
  814.   _settextcolor(env.frgrd[5]);
  815.   _setbkcolor(env.bkgrd[5]);
  816.  
  817.   _settextwindow(rulh,culh,rulh,culh+length+1);
  818.   _wrapon(_GWRAPOFF);
  819.   _clearscreen(_GWINDOW);
  820.   _settextposition(1,1);
  821.   _outtext("[");
  822.   _settextposition(1,length+2);
  823.   _outtext("]");
  824.   _settextwindow(rulh,culh+1,rulh,culh+length);
  825.  
  826.   do
  827.   {
  828.     _settextwindow(rulh,culh+1,rulh,culh+length);
  829.     _clearscreen(_GWINDOW);
  830.     _settextwindow(rulh,culh+1,rulh,culh+length+2);
  831.     for (j=0; j<input_count; j++)
  832.     {
  833.       _settextposition(1,j+1);
  834.       _outtext("*");
  835.     } /* endfor */
  836.     _settextposition(1,cur_pos + 1);
  837.     clean_flag = 0;
  838.     t_changed = 0;
  839.  
  840.     input = (char)getch();
  841.  
  842.     if (input == '\0')
  843.     {
  844.       input = (char)getch();
  845.       switch (input)
  846.       {
  847.         case INS_KEY:
  848.           if (insert_flag)
  849.           {
  850.             show_option(25,80,"INSERT = OFF",'R',env.frgrd[1],env.bkgrd[1]);
  851.             insert_flag = 0;
  852.           }
  853.           else
  854.           {
  855.             show_option(25,80,"INSERT = ON ",'R',env.frgrd[1],env.bkgrd[1]);
  856.             insert_flag = 1;
  857.           } /* endif */
  858.           _settextwindow(rulh,culh+1,rulh,culh+length);
  859.           _settextcolor(env.frgrd[5]);
  860.           _setbkcolor(env.bkgrd[5]);
  861.           break;
  862.         case UP_ARROW:
  863.           putchar(BELL);
  864.           break;
  865.         case DOWN_ARROW:
  866.           putchar(BELL);
  867.           break;
  868.         case HOME:
  869.           cur_pos= 0;
  870.           break;
  871.         case END:
  872.           cur_pos=input_count;
  873.           break;
  874.         case LEFT_ARROW:
  875.           if (cur_pos > 0)
  876.           {
  877.             cur_pos--;
  878.           }
  879.           else
  880.           {
  881.             putchar(BELL);
  882.           } /* endif */
  883.           break;
  884.         case RIGHT_ARROW:
  885.           if (cur_pos < input_count)
  886.           {
  887.             cur_pos++;
  888.           }
  889.           else
  890.           {
  891.             putchar(BELL);
  892.           } /* endif */
  893.           break;
  894.         case DEL_KEY:
  895.           if (input_count == 0 || cur_pos == input_count)
  896.           {
  897.             putchar(BELL);
  898.           }
  899.           else
  900.           {
  901.             strcpy(temp_buf,field);
  902.             for (i=0; i < cur_pos - 1; i++)
  903.             {
  904.               field[i] = temp_buf[i];
  905.             } /* endfor */
  906.             for (i = cur_pos; i < input_count; i++)
  907.             {
  908.               field[i] = temp_buf[i+1];
  909.             } /* endfor */
  910.             input_count--;
  911.             t_changed++;
  912.             field[input_count] = '\0';
  913.           } /* endif */
  914.           break;
  915.         default :
  916.           putchar(BELL);
  917.           break;
  918.       } /* endswitch */
  919.     }
  920.     else
  921.     {
  922.       if (input == '\033')
  923.       {
  924.         field[0] = '\0';
  925.         quit = 1;
  926.       }
  927.       else
  928.       {
  929.         if (input == '\015')
  930.         {
  931.           field[input_count] = '\0';
  932.           quit = 1;
  933.         }
  934.         else
  935.         {
  936.           if (input == '\b')
  937.           {
  938.             if (input_count == 0 || cur_pos == 0)
  939.             {
  940.               putchar(BELL);
  941.             }
  942.             else
  943.             {
  944.               if (cur_pos < input_count)
  945.               {
  946.                 strcpy(temp_buf,field);
  947.                 for (i=0; i < cur_pos - 2; i++)
  948.                 {
  949.                   field[i] = temp_buf[i];
  950.                 } /* endfor */
  951.                 for (i = cur_pos - 1; i < input_count; i++)
  952.                 {
  953.                   field[i] = temp_buf[i+1];
  954.                 } /* endfor */
  955.               } /* endif */
  956.               cur_pos--;
  957.               input_count--;
  958.               t_changed++;
  959.               field[input_count] = '\0';
  960.             } /* endif */
  961.           }
  962.           else
  963.           {
  964.             if (input_count < length)
  965.             {
  966.               if (input_count == cur_pos)
  967.               {
  968.                 if (all_upper)
  969.                 {
  970.                   field[input_count] = (char) toupper(input);
  971.                 }
  972.                 else
  973.                 {
  974.                   field[input_count] = input;
  975.                 } /* endif */
  976.                 field[input_count+1] = '\0';
  977.                 input_count++;
  978.                 cur_pos++;
  979.                 t_changed++;
  980.               }
  981.               else
  982.               {
  983.                 if (insert_flag)
  984.                 {
  985.                   strcpy(temp_buf,field);
  986.                   for (i=0; i <= cur_pos - 1; i++)
  987.                   {
  988.                     field[i] = temp_buf[i];
  989.                   } /* endfor */
  990.                   if (all_upper)
  991.                   {
  992.                     field[cur_pos] = (char) toupper(input);
  993.                   }
  994.                   else
  995.                   {
  996.                     field[cur_pos] = input;
  997.                   } /* endif */
  998.                   for (i = cur_pos + 1; i <= input_count; i++)
  999.                   {
  1000.                     field[i] = temp_buf[i-1];
  1001.                   } /* endfor */
  1002.                   input_count++;
  1003.                   cur_pos++;
  1004.                   field[input_count] = '\0';
  1005.                   t_changed++;
  1006.                 }
  1007.                 else
  1008.                 {
  1009.                   putchar(BELL);
  1010.                 } /* endif */
  1011.               } /* endif */
  1012.             }
  1013.             else
  1014.             {
  1015.               putchar(BELL);
  1016.             } /* endif */
  1017.           } /* endif */
  1018.         } /* endif */
  1019.       } /* endif */
  1020.     } /* endif */
  1021.   } while (!quit); /* enddo */
  1022.  
  1023.   _settextcolor(env.frgrd[0]);
  1024.   _setbkcolor(env.bkgrd[0]);
  1025.   _settextwindow(1,1,25,80);
  1026.   return(0);
  1027.  
  1028. } /* end get_password */
  1029. /*---------------------------------------------------------------------------*/
  1030.  
  1031.  
  1032. int show_small_file(char *file_name,int name_flag,
  1033.                     char *msg,char *r_title1,char *r_title2,
  1034.                     int rulh,int culh,int rbrh,int cbrh)
  1035.  
  1036. {
  1037.   int  in_file = 0;
  1038.   char bigbuff[257];
  1039.   int color_mask = 0;
  1040.  
  1041.   long file_length = 0L;
  1042.   long file_position = 0L;
  1043.  
  1044.   unsigned int max_line_length = 0;
  1045.  
  1046.   int i;
  1047.   int line_number = 1;
  1048.   int quit =0;
  1049.  
  1050.   struct long_file_line *my_line = NULL;
  1051.  
  1052.   my_line = (struct long_file_line  *)calloc(line_number,sizeof(struct long_file_line));
  1053.   if (my_line == NULL)
  1054.   {
  1055.     box_message(1,1,"Memory allocation error",emp,NULL);
  1056.     free(my_line);
  1057.     return(2);
  1058.   } /* endif */
  1059.  
  1060.   in_file = sopen(file_name,O_RDONLY|O_BINARY,SH_DENYNO);
  1061.   if (in_file == -1)
  1062.   {
  1063.     free(my_line);
  1064.     _settextcolor(env.frgrd[0]);
  1065.     _setbkcolor(env.bkgrd[0]);
  1066.     return(11);
  1067.   }
  1068.   else
  1069.   {
  1070.     display_message("Reading File. Please Wait !");
  1071.     file_length = filelength(in_file);
  1072.     file_position = lseek(in_file,file_position,SEEK_SET);
  1073.     while (file_position < file_length - 1)
  1074.     {
  1075.       bigbuff[0] = '\0';
  1076.       read(in_file,bigbuff,256);
  1077.       i = 0;
  1078.       while (bigbuff[i] != '\r')
  1079.       {
  1080.         my_line[line_number-1].line[i] = bigbuff[i];
  1081.         i++;
  1082.       } /* endwhile */
  1083.       my_line[line_number-1].line[i] = '\0';
  1084.       my_line[line_number-1].line[i+1] = '\0';
  1085.       if (max_line_length < strlen(my_line[line_number-1].line))
  1086.       {
  1087.         max_line_length = strlen(my_line[line_number-1].line);
  1088.       } /* endif */
  1089.       line_number++;
  1090.       my_line = (struct long_file_line  *)realloc(my_line,line_number*sizeof(struct long_file_line));
  1091.       if (my_line == NULL)
  1092.       {
  1093.         box_message(1,1,"Memory allocation error",emp,NULL);
  1094.         free(my_line);
  1095.         close(in_file);
  1096.         return(2);
  1097.       } /* endif */
  1098.       file_position = file_position + i + 2;
  1099.       file_position = lseek(in_file,file_position,SEEK_SET);
  1100.     } /* endwhile */
  1101.     close(in_file);
  1102.   } /* endif */
  1103.  
  1104.   line_number = line_number - 1;
  1105.   show_lines(file_name,name_flag,my_line,line_number,max_line_length,msg,r_title1,r_title2,rulh,culh,rbrh,cbrh);
  1106.  
  1107.   free(my_line);
  1108.  
  1109.   _settextcolor(env.frgrd[0]);
  1110.   _setbkcolor(env.bkgrd[0]);
  1111.  
  1112.   set_cursor_on(7,7);
  1113.   return(0);
  1114.  
  1115. } /* end show_small_file */
  1116. /* ------------------------------------------------------------------ */
  1117.  
  1118. int show_lines(char *file_name,int name_flag,
  1119.                struct long_file_line *lines,int number_of_lines,
  1120.                unsigned int max_line_length,
  1121.                char *msg,char *r_title1,char *r_title2,
  1122.                int rulh,int culh,int rbrh,int cbrh)
  1123. {
  1124.   int color_mask = 0;
  1125.   int page_length = 0;
  1126.   unsigned int page_width = 0;
  1127.   int i,j;
  1128.   int scrl_lines;
  1129.   int top_line = 0;
  1130.   int old_top = 0;
  1131.   int quit =0;
  1132.   int d_flag;
  1133.   int start;
  1134.   char screen_line[81];
  1135.   unsigned int start_col = 0;
  1136.   unsigned int old_start_col = 0;
  1137.  
  1138.   char title[78];
  1139.   char bottom_title[78];
  1140.   char input;
  1141.  
  1142.   strcpy(title,"[ ");
  1143.   strcat(title,msg);
  1144.   strcat(title," ]");
  1145.   strcpy(bottom_title,"Arrow Keys [PgUp] [PgDn] [Home] [End] = Move , P/p = print, [Esc] = quit");
  1146.  
  1147.   page_length = rbrh - rulh - 2;
  1148.  
  1149.   if (number_of_lines < page_length)
  1150.   {
  1151.     page_length = number_of_lines;
  1152.     rbrh = rulh + number_of_lines + 2;
  1153.   } /* endif */
  1154.  
  1155.   scrl_lines = page_length;
  1156.   start = 1;
  1157.   top_line = 0;
  1158.   d_flag = UP;
  1159.  
  1160.   page_width  = cbrh - culh - 1;
  1161.  
  1162.   _settextwindow(1,1,25,80);
  1163.   _settextcolor(env.frgrd[3]);
  1164.   _setbkcolor(env.bkgrd[3]);
  1165.   _clearscreen(_GWINDOW);
  1166.  
  1167.   frame(rulh,culh,rbrh - rulh,page_width + 2,env.frgrd[2],env.bkgrd[2]);
  1168.  
  1169.   if (strlen(title) < page_width)
  1170.   {
  1171.     show_option(rulh,40,title,'C',env.frgrd[1],env.bkgrd[1]);
  1172.   } /* endif */
  1173.  
  1174.   if (strlen(bottom_title) < page_width)
  1175.   {
  1176.     show_option(rbrh-1,40,bottom_title,'C',env.frgrd[1],env.bkgrd[1]);
  1177.   } /* endif */
  1178.  
  1179.   _settextwindow(rulh + 1,culh + 1,rbrh - 2,cbrh - 1);
  1180.   _settextcolor(env.frgrd[3]);
  1181.   _setbkcolor(env.bkgrd[3]);
  1182.   _clearscreen(_GWINDOW);
  1183.   set_cursor_off();
  1184.  
  1185.   color_mask = 16*(int)env.bkgrd[3] + env.frgrd[3];
  1186.  
  1187.   do
  1188.   {
  1189.     if (scrl_lines != 0)
  1190.     {
  1191.       scroll(d_flag,rulh + 1,culh + 1,rbrh - 2,cbrh - 1,scrl_lines,color_mask);
  1192.       for (j=0 ; j < scrl_lines; j++)
  1193.       {
  1194.         _settextposition(start+j,1);
  1195.         i = 0;
  1196.         screen_line[i] = '\0';
  1197.         while (start_col + i < strlen(lines[j+top_line+start-1].line))
  1198.         {
  1199.           screen_line[i] = lines[j+top_line+start-1].line[start_col + i];
  1200.           i++;
  1201.         } /* endwhile */
  1202.         screen_line[i] = '\0';
  1203.         _outtext(screen_line);
  1204.       } /* endfor */
  1205.     } /* endif */
  1206.  
  1207.     input = (char)getch();
  1208.     old_top = top_line;
  1209.     old_start_col = start_col;
  1210.     if (input == '\0')
  1211.     {
  1212.       input = (char)getch();
  1213.       switch (input)
  1214.       {
  1215.         case PAGE_UP:
  1216.           d_flag = DOWN;
  1217.           start  = 1;
  1218.           top_line -= page_length - 1;
  1219.           scrl_lines  = abs(old_top - top_line);
  1220.           if (top_line < 0)
  1221.           {
  1222.             top_line = 0;
  1223.             scrl_lines = page_length;
  1224.           } /* endif */
  1225.           if (top_line == old_top)
  1226.           {
  1227.             scrl_lines = 0;
  1228.           } /* endif */
  1229.           break;
  1230.         case UP_ARROW:
  1231.           d_flag = DOWN;
  1232.           start  = 1;
  1233.           top_line -= 1;
  1234.           if (top_line < 0)
  1235.           {
  1236.             top_line = 0;
  1237.           } /* endif */
  1238.           scrl_lines  = abs(old_top - top_line);
  1239.           break;
  1240.         case PAGE_DOWN:
  1241.           d_flag = UP;
  1242.           start  = 1;
  1243.           top_line += page_length ;
  1244.           scrl_lines  = abs(old_top - top_line);
  1245.           if (top_line > number_of_lines - page_length)
  1246.           {
  1247.             top_line = number_of_lines - page_length;
  1248.             scrl_lines = page_length;
  1249.           } /* endif */
  1250.           if (top_line == old_top)
  1251.           {
  1252.             scrl_lines = 0;
  1253.           } /* endif */
  1254.           break;
  1255.         case DOWN_ARROW:
  1256.           d_flag = UP;
  1257.           start  = page_length;
  1258.           top_line += 1;
  1259.           if (top_line > number_of_lines - page_length)
  1260.           {
  1261.             top_line = number_of_lines - page_length;
  1262.           } /* endif */
  1263.           scrl_lines  = abs(old_top - top_line);
  1264.           break;
  1265.         case LEFT_ARROW:
  1266.           d_flag = UP;
  1267.           scrl_lines = page_length;
  1268.           start  = 1;
  1269.           if (start_col > 0)
  1270.           {
  1271.             start_col = start_col -1;
  1272.           }
  1273.           else
  1274.           {
  1275.             start_col = 0;
  1276.           } /* endif */
  1277.           if (start_col == old_start_col)
  1278.           {
  1279.             scrl_lines = 0;
  1280.           } /* endif */
  1281.           break;
  1282.         case C_LEFT:
  1283.           d_flag = UP;
  1284.           scrl_lines = page_length;
  1285.           start  = 1;
  1286.           start_col = 0;
  1287.           if (start_col == old_start_col)
  1288.           {
  1289.             scrl_lines = 0;
  1290.           } /* endif */
  1291.           break;
  1292.         case RIGHT_ARROW:
  1293.           d_flag = UP;
  1294.           scrl_lines = page_length;
  1295.           start  = 1;
  1296.           if (max_line_length > page_width)
  1297.           {
  1298.             if (start_col < max_line_length - page_width)
  1299.             {
  1300.               start_col = start_col +1;
  1301.             }
  1302.             else
  1303.             {
  1304.               start_col = max_line_length - page_width;
  1305.             } /* endif */
  1306.           }
  1307.           else
  1308.           {
  1309.             start_col = 0;
  1310.           } /* endif */
  1311.           if (start_col == old_start_col)
  1312.           {
  1313.             scrl_lines = 0;
  1314.           } /* endif */
  1315.           break;
  1316.         case C_RIGHT:
  1317.           d_flag = UP;
  1318.           scrl_lines = page_length;
  1319.           start  = 1;
  1320.           if (max_line_length > page_width)
  1321.           {
  1322.             start_col = max_line_length - page_width;
  1323.           }
  1324.           else
  1325.           {
  1326.             start_col = 0;
  1327.           } /* endif */
  1328.           if (start_col == old_start_col)
  1329.           {
  1330.             scrl_lines = 0;
  1331.           } /* endif */
  1332.           break;
  1333.         case HOME:
  1334.           d_flag = DOWN;
  1335.           start  = 1;
  1336.           scrl_lines = page_length;
  1337.           top_line = 0;
  1338.           if (top_line == old_top && start_col == 0)
  1339.           {
  1340.             scrl_lines = 0;
  1341.           } /* endif */
  1342.           start_col = 0;
  1343.           break;
  1344.         case END:
  1345.           d_flag = UP;
  1346.           start = 1;
  1347.           scrl_lines = page_length;
  1348.           top_line = number_of_lines - page_length;
  1349.           if (top_line == old_top && start_col == 0)
  1350.           {
  1351.             scrl_lines = 0;
  1352.           } /* endif */
  1353.           start_col = 0;
  1354.           break;
  1355.         default :
  1356.           scrl_lines = 0;
  1357.           break;
  1358.       } /* endswitch */
  1359.     }
  1360.     else
  1361.     {
  1362.       switch (input)
  1363.       {
  1364.         case '\033':
  1365.           quit = 1;
  1366.           break;
  1367.         case 'p':
  1368.         case 'P':
  1369.           print_file(file_name,name_flag,r_title1,r_title2,max_line_length);
  1370.           quit = 1;
  1371.           break;
  1372.         default :
  1373.           scrl_lines = 0;
  1374.           break;
  1375.       } /* endswitch */
  1376.     } /* endif */
  1377.   } while (!quit); /* enddo */
  1378.  
  1379.   _settextcolor(env.frgrd[0]);
  1380.   _setbkcolor(env.bkgrd[0]);
  1381.   set_cursor_on(7,7);
  1382.   return(0);
  1383.  
  1384. } /* end show_lines */
  1385. /* ------------------------------------------------------------------ */
  1386.  
  1387. void read_setup_file(struct video_info *env)
  1388.  
  1389. {
  1390.   char user_field[21][61];
  1391.   int handle1;
  1392.   long f_position = 0L;
  1393.   long file_length = 0L;
  1394.   char bigbuff[151];
  1395.   char *filename;
  1396.  
  1397.   int counter = 0;
  1398.   int i,j,k;
  1399.  
  1400.   if ((filename = getenv("PDTSETUP")) == NULL)
  1401.   {
  1402.     filename = "setup.ini";
  1403.   } /* endif */
  1404.  
  1405.  
  1406.   handle1 = open(filename,O_RDONLY|O_BINARY,SH_DENYNO);
  1407.  
  1408.   if (handle1 == -1)
  1409.   {
  1410.     box_message(1,1,"cannot open setup file.",emp,NULL);
  1411.     exit(1);
  1412.   }
  1413.   else
  1414.   {
  1415.     file_length = filelength(handle1);
  1416.     f_position  = lseek(handle1,f_position,SEEK_SET);
  1417.     bigbuff[0] = '\0';
  1418.     read(handle1,bigbuff,(int)file_length);
  1419.     i = 0;
  1420.     while (bigbuff[i] != '\r')
  1421.     {
  1422.       i++;
  1423.     } /* endwhile */
  1424.     bigbuff[i] = '\0';
  1425.     j = 0;
  1426.     counter = 0;
  1427.     for (k=0; k <= i;k++)
  1428.     {
  1429.       if (bigbuff[k] == ','|| bigbuff[k] == '\0')
  1430.       {
  1431.         user_field[counter][j] = '\0';
  1432.         counter++;
  1433.         j = 0;
  1434.       }
  1435.       else
  1436.       {
  1437.         user_field[counter][j] = bigbuff[k];
  1438.         j++;
  1439.       } /* endif */
  1440.     } /* endfor */
  1441.     close(handle1);
  1442.   } /* endif */
  1443.   env->bkgrd[0] = atol(user_field[0]);
  1444.   env->frgrd[0] = atoi(user_field[1]);
  1445.   env->bkgrd[1] = atol(user_field[2]);
  1446.   env->frgrd[1] = atoi(user_field[3]);
  1447.   env->bkgrd[2] = atol(user_field[4]);
  1448.   env->frgrd[2] = atoi(user_field[5]);
  1449.   env->bkgrd[3] = atol(user_field[6]);
  1450.   env->frgrd[3] = atoi(user_field[7]);
  1451.   env->bkgrd[4] = atol(user_field[8]);
  1452.   env->frgrd[4] = atoi(user_field[9]);
  1453.   env->bkgrd[5] = atol(user_field[10]);
  1454.   env->frgrd[5] = atoi(user_field[11]);
  1455.   env->bkgrd[6] = atol(user_field[12]);
  1456.   env->frgrd[6] = atoi(user_field[13]);
  1457.   env->bkgrd[7] = atol(user_field[14]);
  1458.   env->frgrd[7] = atoi(user_field[15]);
  1459.   env->bkgrd[8] = atol(user_field[16]);
  1460.   env->frgrd[8] = atoi(user_field[17]);
  1461.   env->bkgrd[9] = atol(user_field[18]);
  1462.   env->frgrd[9] = atoi(user_field[19]);
  1463.   strcpy(env->plant,user_field[20]);
  1464. } /* end read_setup_file */
  1465. /*---------------------------------------------------------------------------*/
  1466.  
  1467.  
  1468. int verify_user(char *users_file,char *user_id,
  1469.                 char *password,
  1470.                 char *desired_access)
  1471.  
  1472. {
  1473.   int r_code = 0;
  1474.   int found_it = 0;
  1475.   int i,j,k;
  1476.   char bigbuff[80];
  1477.   char user_field[3][30];
  1478.  
  1479.   int handle1 = 0;
  1480.   long f_position = 0L;
  1481.   long file_length = 0L;
  1482.   int counter = 0;
  1483.  
  1484.   display_message("Verifying user id and password");
  1485.   _settextcolor(env.frgrd[0]);
  1486.   _setbkcolor(env.bkgrd[0]);
  1487.   handle1 = sopen(users_file,O_RDONLY|O_BINARY,SH_DENYNO);
  1488.  
  1489.   if (handle1 == -1)
  1490.   {
  1491.     box_message(1,1,"Could not open users database.",emp,NULL);
  1492.     r_code = -1;
  1493.   }
  1494.   else
  1495.   {
  1496.     file_length = filelength(handle1);
  1497.     f_position  = lseek(handle1,f_position,SEEK_SET);
  1498.     while (f_position < file_length - 1 && !found_it)
  1499.     {
  1500.       bigbuff[0] = '\0';
  1501.       read(handle1,bigbuff,80);
  1502.       i = 0;
  1503.       while (bigbuff[i] != '\r')
  1504.       {
  1505.         i++;
  1506.       } /* endwhile */
  1507.       bigbuff[i] = '\0';
  1508.       j = 0;
  1509.       counter = 0;
  1510.       for (k=0; k <= i;k++)
  1511.       {
  1512.         if (bigbuff[k] == ','|| bigbuff[k] == '\0')
  1513.         {
  1514.           user_field[counter][j] = '\0';
  1515.           counter++;
  1516.           j = 0;
  1517.         }
  1518.         else
  1519.         {
  1520.           if (bigbuff[k] != ' ')
  1521.           {
  1522.             user_field[counter][j] = bigbuff[k];
  1523.             j++;
  1524.           } /* endif */
  1525.         } /* endif */
  1526.       } /* endfor */
  1527.  
  1528.       if (strcmp(user_field[0],user_id) == 0 && strcmp(user_field[1],password) == 0)
  1529.       {
  1530.         if (strcmp(desired_access,"R") == 0)
  1531.         {
  1532.           found_it = 1;
  1533.           r_code = 1;
  1534.         }
  1535.         else
  1536.         {
  1537.           if (strcmp(user_field[2],desired_access) == 0)
  1538.           {
  1539.             found_it = 1;
  1540.             r_code = 1;
  1541.           }
  1542.           else
  1543.           {
  1544.             if (strcmp(desired_access,"W") == 0 && strcmp(user_field[2],"E") == 0)
  1545.             {
  1546.               found_it = 1;
  1547.               r_code = 1;
  1548.             }
  1549.             else
  1550.             {
  1551.               box_message(1,1,"Access level is not sufficient for this function.","Contact the help desk",emp);
  1552.               r_code = 0;
  1553.             } /* endif */
  1554.           } /* endif */
  1555.         } /* endif */
  1556.       }
  1557.       else
  1558.       {
  1559.         f_position = f_position + i + 2;
  1560.         f_position = lseek(handle1,f_position,SEEK_SET);
  1561.       } /* endif */
  1562.     } /* endwhile */
  1563.     close(handle1);
  1564.   } /* endif */
  1565.   return(r_code);
  1566. } /* end verify_user */
  1567. /*---------------------------------------------------------------------------*/
  1568.  
  1569.  
  1570. int print_file(char *file_name,
  1571.                int name_flag,
  1572.                char *r_title1,
  1573.                char *r_title2,
  1574.                int line_length)
  1575.  
  1576. {
  1577.  
  1578.   FILE *out_file = NULL;
  1579.   int  in_file = 0;
  1580.   char bigbuff[257];
  1581.  
  1582.   long file_length = 0L;
  1583.   long file_position = 0L;
  1584.  
  1585.   int i;
  1586.   int p_quit =0;
  1587.   int p_flag = 1;
  1588.   int go_on = 1;
  1589.   int start_pos = 0;
  1590.   int i1,i2;
  1591.   char line[257];
  1592.  
  1593.   char printer_kind;
  1594.  
  1595.   in_file = sopen(file_name,O_RDONLY|O_BINARY,SH_DENYNO);
  1596.   if (in_file == -1)
  1597.   {
  1598.     return(11);
  1599.   }
  1600.   else
  1601.   {
  1602.     out_file = fopen("prn","w");
  1603.     if (out_file == NULL)
  1604.     {
  1605.       box_message(1,1,"Could not open printer.",emp,NULL);
  1606.     }
  1607.     else
  1608.     {
  1609.       p_flag = 1;
  1610.       while (!p_quit)
  1611.       {
  1612.         printer_kind = box_message(0,1,"Press H for HP LASER JET.","Press I for IBM PRO PRINTER.","Esc to quit");
  1613.         switch (printer_kind)
  1614.         {
  1615.           case '\033':
  1616.             p_quit = 1;
  1617.             p_flag = 0;
  1618.             break;
  1619.           case 'H':
  1620.           case 'h':
  1621.             fprintf(out_file,"E");
  1622.             fprintf(out_file,"(10U");
  1623.             if (line_length > 75)
  1624.             {
  1625.               fprintf(out_file,"(s16.66H");
  1626.             } /* endif */
  1627.             fprintf(out_file,"&l8D");
  1628.             p_quit = 1;
  1629.             break;
  1630.           case 'I':
  1631.           case 'i':
  1632.             fprintf(out_file,"%c",18);
  1633.             fprintf(out_file,"%c%c",27,79);
  1634.             if (line_length > 75)
  1635.             {
  1636.               fprintf(out_file,"%c",15);
  1637.             } /* endif */
  1638.             fprintf(out_file,"%c%c%c",27,78,6);
  1639.             p_quit = 1;
  1640.             break;
  1641.           default :
  1642.             ;
  1643.         } /* endswitch */
  1644.       } /* endwhile */
  1645.       if (p_flag)
  1646.       {
  1647.         _setbkcolor(0L);
  1648.         _settextwindow(11,12,16,72);
  1649.         _clearscreen(_GWINDOW);
  1650.         _settextcolor(env.frgrd[5]);
  1651.         _setbkcolor(env.bkgrd[5]);
  1652.         _settextwindow(10,10,15,70);
  1653.         _clearscreen(_GWINDOW);
  1654.         _settextposition(3,2);
  1655.         _outtext("File is being sent to the printer.");
  1656.         fprintf(out_file,"\n\n");
  1657.         if (r_title1 != NULL)
  1658.         {
  1659.           fprintf(out_file,"\t\t\t%s\n",r_title1);
  1660.         } /* endif */
  1661.         if (r_title2 != NULL)
  1662.         {
  1663.           fprintf(out_file,"\t\t\t%s\n",r_title2);
  1664.         } /* endif */
  1665.         if (name_flag)
  1666.         {
  1667.           fprintf(out_file,"\t File name: %s",file_name);
  1668.           fprintf(out_file,"\n\n");
  1669.         } /* endif */
  1670.         file_length = filelength(in_file);
  1671.         file_position = lseek(in_file,file_position,SEEK_SET);
  1672.         while (file_position < file_length - 1)
  1673.         {
  1674.           bigbuff[0] = '\0';
  1675.           read(in_file,bigbuff,256);
  1676.           i = 0;
  1677.           while (bigbuff[i] != '\r')
  1678.           {
  1679.             i++;
  1680.           } /* endwhile */
  1681.           bigbuff[i] = '\n';
  1682.           bigbuff[i+1] = '\0';
  1683.           file_position = file_position + i + 2;
  1684.           file_position = lseek(in_file,file_position,SEEK_SET);
  1685.           start_pos = 0;
  1686.           go_on = 1;
  1687.           while (go_on)
  1688.           {
  1689.             for (i1=0; i1<=line_length; i1++)
  1690.             {
  1691.               if (bigbuff[start_pos+i1] == '\n')
  1692.               {
  1693.                 go_on = 0;
  1694.                 line[i1] = bigbuff[start_pos+i1];
  1695.                 line[i1+1] = '\0';
  1696.                 i1 = line_length;
  1697.               }
  1698.               else
  1699.               {
  1700.                 line[i1] = bigbuff[start_pos+i1];
  1701.                 line[i1+1] = '\0';
  1702.               } /* endif */
  1703.             } /* endfor */
  1704.             for (i2=0; i2<line_length; i2++)
  1705.             {
  1706.               if (line[line_length - i2] == ',' || !go_on)
  1707.               {
  1708.                 line[line_length - i2 + 1] = '\0';
  1709.                 if (line[line_length - i2] == ',')
  1710.                 {
  1711.                   line[line_length - i2 + 1] = '\n';
  1712.                 } /* endif */
  1713.                 line[line_length - i2 + 2] = '\0';
  1714.                 i2 = line_length;
  1715.               } /* endif */
  1716.             } /* endfor */
  1717.             start_pos = start_pos + strlen(line) - 1;
  1718.             fprintf(out_file,"\t%s",line);
  1719.           } /* endwhile */
  1720.         } /* endwhile */
  1721.         close(in_file);
  1722.  
  1723.         fprintf(out_file,"\f");
  1724.         if (printer_kind == 'H' || printer_kind == 'h')
  1725.         {
  1726.           fprintf(out_file,"E");
  1727.         }
  1728.         else
  1729.         {
  1730.           fprintf(out_file,"%c",18);
  1731.           fprintf(out_file,"%c%c",27,79);
  1732.         } /* endif */
  1733.         fflush(out_file);
  1734.         fclose(out_file);
  1735.       } /* endif */
  1736.     } /* endif */
  1737.     close(in_file);
  1738.   } /* endif */
  1739.   _settextcolor(env.frgrd[0]);
  1740.   _setbkcolor(env.bkgrd[0]);
  1741.   return(0);
  1742. } /* end print_file */
  1743. /*---------------------------------------------------------------------------*/
  1744.  
  1745.  
  1746. int file_sort(char *file_name,
  1747.               int rec_length,
  1748.               int sort_field)
  1749.  
  1750. {
  1751.   int file_handle = 0;
  1752.   long file_length = 0L;
  1753.   long rec_count;
  1754.  
  1755.   file_handle = sopen(file_name,O_RDWR|O_BINARY,SH_DENYNO);
  1756.   if (file_handle == -1)
  1757.   {
  1758.     return(11);
  1759.   }
  1760.   else
  1761.   {
  1762.     display_message("Sorting be patient !");
  1763.     file_length = filelength(file_handle);
  1764.     if (file_length != 0)
  1765.     {
  1766.       rec_count = file_length/(rec_length + 2);
  1767.       fsort(file_handle,0L,rec_count-1,sort_field,rec_length);
  1768.     } /* endif */
  1769.   } /* endif */
  1770.   close(file_handle);
  1771.  
  1772. } /* end file_sort */
  1773. /*---------------------------------------------------------------------------*/
  1774.  
  1775.  
  1776. void fsort(int file_handle,
  1777.            long top,
  1778.            long bottom,
  1779.            int sort_field,
  1780.            int rec_length)
  1781.  
  1782. {
  1783.   key_field[0] = '\0';
  1784.   mid_field[0] = '\0';
  1785.   top_field[0] = '\0';
  1786.   bot_field[0] = '\0';
  1787.  
  1788.   li = top;
  1789.   lj = bottom;
  1790.  
  1791.   get_key_field(file_handle,(long)(li+lj)/2,rec_length,sort_field,key_field);
  1792.   strcpy(mid_field,key_field);
  1793.  
  1794.   do
  1795.   {
  1796.     loop1 = 1;
  1797.     loop2 = 1;
  1798.     while (loop1)
  1799.     {
  1800.       get_key_field(file_handle,li,rec_length,sort_field,key_field);
  1801.       strcpy(top_field,key_field);
  1802.       if (strcmp(top_field,mid_field) < 0 && li < bottom)
  1803.       {
  1804.         li++;
  1805.       }
  1806.       else
  1807.       {
  1808.         loop1 = 0;
  1809.       } /* endif */
  1810.     } /* endwhile */
  1811.     while (loop2)
  1812.     {
  1813.       get_key_field(file_handle,lj,rec_length,sort_field,key_field);
  1814.       strcpy(bot_field,key_field);
  1815.       if (strcmp(bot_field,mid_field) > 0 && lj > top)
  1816.       {
  1817.         lj--;
  1818.       }
  1819.       else
  1820.       {
  1821.         loop2 = 0;
  1822.       } /* endif */
  1823.     } /* endwhile */
  1824.     if (li<=lj)
  1825.     {
  1826.       swap_records(file_handle,li,lj,rec_length);
  1827.       li++;
  1828.       lj--;
  1829.     } /* endif */
  1830.   } while (li <= lj); /* enddo */
  1831.  
  1832.   if (top < lj)
  1833.   {
  1834.     fsort(file_handle,top,lj,sort_field,rec_length);
  1835.   } /* endif */
  1836.  
  1837.   if (li < bottom)
  1838.   {
  1839.     fsort(file_handle,li,bottom,sort_field,rec_length);
  1840.   } /* endif */
  1841. } /* end fsort */
  1842. /*---------------------------------------------------------------------------*/
  1843.  
  1844.  
  1845. void get_key_field(int file_handle,
  1846.                    long rec_num,
  1847.                    int rec_length,
  1848.                    int sort_field,
  1849.                    char *key_field)
  1850.  
  1851. {
  1852.   char bigbuff[256];
  1853.   char user_field[15][61];
  1854.   int j,k,counter;
  1855.  
  1856.   bigbuff[0] = '\0';
  1857.   lseek(file_handle,rec_num*(rec_length+2),SEEK_SET);
  1858.   read(file_handle,bigbuff,rec_length + 2);
  1859.   bigbuff[rec_length + 2] = '\0';
  1860.   j = 0;
  1861.   counter = 0;
  1862.   for (k=0; k <= rec_length + 2;k++)
  1863.   {
  1864.     if (bigbuff[k] == ','|| bigbuff[k] == '\0')
  1865.     {
  1866.       user_field[counter][j] = '\0';
  1867.       counter++;
  1868.       j = 0;
  1869.     }
  1870.     else
  1871.     {
  1872.       user_field[counter][j] = bigbuff[k];
  1873.       j++;
  1874.     } /* endif */
  1875.   } /* endfor */
  1876.   strcpy(key_field,user_field[sort_field]);
  1877. } /* end get_key_field */
  1878. /*---------------------------------------------------------------------------*/
  1879.  
  1880.  
  1881. void swap_records(int file_handle,
  1882.                   long i,
  1883.                   long j,
  1884.                   int rec_length)
  1885.  
  1886. {
  1887.   char bigbuff1[256];
  1888.   char bigbuff2[256];
  1889.  
  1890.   bigbuff1[0] = '\0';
  1891.   lseek(file_handle,i*(rec_length+2),SEEK_SET);
  1892.   read(file_handle,bigbuff1,rec_length + 2);
  1893.   bigbuff1[rec_length + 2] = '\0';
  1894.  
  1895.   bigbuff2[0] = '\0';
  1896.   lseek(file_handle,j*(rec_length+2),SEEK_SET);
  1897.   read(file_handle,bigbuff2,rec_length + 2);
  1898.   bigbuff2[rec_length + 2] = '\0';
  1899.  
  1900.   lseek(file_handle,j*(rec_length+2),SEEK_SET);
  1901.   write(file_handle,bigbuff1,rec_length + 2);
  1902.  
  1903.   lseek(file_handle,i*(rec_length+2),SEEK_SET);
  1904.   write(file_handle,bigbuff2,rec_length + 2);
  1905. } /* swap_records */
  1906. /*---------------------------------------------------------------------------*/
  1907.  
  1908.  
  1909. int show_file(char *file_name,int name_flag,int rec_length,
  1910.               char *msg,char *r_title1,char *r_title2,
  1911.               int rulh,int culh,int rbrh,int cbrh)
  1912. {
  1913.   int  in_file = 0;
  1914.   char bigbuff[256];
  1915.   int color_mask = 0;
  1916.  
  1917.   long file_length = 0L;
  1918.   long file_position = 0L;
  1919.  
  1920.   int page_length = 0;
  1921.   int line_number = 0;
  1922.   int page_width = 0;
  1923.   int i,j;
  1924.   int top_line = 0;
  1925.   int old_top = 0;
  1926.   int quit =0;
  1927.   int d_flag;
  1928.   int scrl_lines;
  1929.   int start;
  1930.   int p_flag=1;
  1931.   int p_quit=0;
  1932.   char screen_line[81];
  1933.   int start_col = 0;
  1934.   int old_start_col = 0;
  1935.   int max_line_length = 0;
  1936.   long file_lines = 0;
  1937.  
  1938.   char title[78];
  1939.   char bottom_title[78];
  1940.   char input;
  1941.  
  1942.   struct long_file_line huge *my_line = NULL;
  1943.   max_line_length = rec_length;
  1944.  
  1945.   strcpy(title,"[ ");
  1946.   strcat(title,msg);
  1947.   strcat(title," ]");
  1948.  
  1949.   in_file = sopen(file_name,O_RDONLY|O_BINARY,SH_DENYNO);
  1950.   if (in_file == -1)
  1951.   {
  1952.     _settextcolor(env.frgrd[0]);
  1953.     _setbkcolor(env.bkgrd[0]);
  1954.     return(11);
  1955.   }
  1956.   else
  1957.   {
  1958.     display_message("Reading File.  Please Wait !");
  1959.     file_length = filelength(in_file);
  1960.     file_position = lseek(in_file,file_position,SEEK_SET);
  1961.  
  1962.     file_lines = file_length/(rec_length + 2);
  1963.     if (file_lines > 512)
  1964.     {
  1965.       file_lines = 1024;
  1966.     } /* endif */
  1967.  
  1968.     my_line = (struct long_file_line huge *)halloc(file_lines,sizeof(struct long_file_line));
  1969.     if (my_line == NULL)
  1970.     {
  1971.       box_message(1,1,"Memory allocation error",emp,NULL);
  1972.       close(in_file);
  1973.       return(2);
  1974.     } /* endif */
  1975.     while (file_position < file_length - 1)
  1976.     {
  1977.       bigbuff[0] = '\0';
  1978.       read(in_file,bigbuff,255);
  1979.       i = 0;
  1980.       while (bigbuff[i] != '\r')
  1981.       {
  1982.         my_line[line_number].line[i] = bigbuff[i];
  1983.         i++;
  1984.       } /* endwhile */
  1985.       my_line[line_number].line[i] = '\0';
  1986.       my_line[line_number].line[i+1] = '\0';
  1987.       line_number++;
  1988.       file_position = file_position + i + 2;
  1989.       file_position = lseek(in_file,file_position,SEEK_SET);
  1990.     } /* endwhile */
  1991.     close(in_file);
  1992.   } /* endif */
  1993.  
  1994.   page_length = rbrh - rulh - 2;
  1995.  
  1996.   if (line_number < page_length)
  1997.   {
  1998.     page_length = line_number;
  1999.     rbrh = rulh + line_number + 2;
  2000.   } /* endif */
  2001.  
  2002.   scrl_lines = page_length;
  2003.   start = 1;
  2004.   top_line = 0;
  2005.   d_flag = UP;
  2006.  
  2007.   page_width  = cbrh - culh - 1;
  2008.  
  2009.   _settextwindow(1,1,25,80);
  2010.   _settextcolor(env.frgrd[3]);
  2011.   _setbkcolor(env.bkgrd[3]);
  2012.   _clearscreen(_GWINDOW);
  2013.   frame(rulh,culh,rbrh - rulh,page_width + 2,env.frgrd[2],env.bkgrd[2]);
  2014.   strcpy(bottom_title,"Arrow Keys [PgUp] [PgDn] [Home] [End] = Move , P/p = print, [Esc] = quit");
  2015.   show_option(1,40,title,'C',env.frgrd[1],env.bkgrd[1]);
  2016.   show_option(25,40,bottom_title,'C',env.frgrd[1],env.bkgrd[1]);
  2017.  
  2018.   _settextwindow(rulh + 1,culh + 1,rbrh - 2,cbrh - 1);
  2019.   _settextcolor(env.frgrd[3]);
  2020.   _setbkcolor(env.bkgrd[3]);
  2021.   _clearscreen(_GWINDOW);
  2022.   set_cursor_off();
  2023.  
  2024.   color_mask = 16*(int)env.bkgrd[3] + env.frgrd[3];
  2025.  
  2026.   do
  2027.   {
  2028.     if (scrl_lines != 0)
  2029.     {
  2030.       scroll(d_flag,rulh + 1,culh + 1,rbrh - 2,cbrh - 1,scrl_lines,color_mask);
  2031.       for (j=0 ; j < scrl_lines; j++)
  2032.       {
  2033.         _settextposition(start+j,1);
  2034.         i = 0;
  2035.         screen_line[i] = '\0';
  2036.         while (start_col + i < max_line_length)
  2037.         {
  2038.           screen_line[i] = my_line[j+top_line+start-1].line[start_col + i];
  2039.           i++;
  2040.         } /* endwhile */
  2041.         screen_line[i] = '\0';
  2042.         _outtext(screen_line);
  2043.       } /* endfor */
  2044.     } /* endif */
  2045.  
  2046.     input = (char)getch();
  2047.     old_top = top_line;
  2048.     old_start_col = start_col;
  2049.     if (input == '\0')
  2050.     {
  2051.       input = (char)getch();
  2052.       switch (input)
  2053.       {
  2054.         case PAGE_UP:
  2055.           d_flag = DOWN;
  2056.           start  = 1;
  2057.           top_line -= page_length - 1;
  2058.           scrl_lines  = abs(old_top - top_line);
  2059.           if (top_line < 0)
  2060.           {
  2061.             top_line = 0;
  2062.             scrl_lines = page_length;
  2063.           } /* endif */
  2064.           if (top_line == old_top)
  2065.           {
  2066.             scrl_lines = 0;
  2067.           } /* endif */
  2068.           break;
  2069.         case UP_ARROW:
  2070.           d_flag = DOWN;
  2071.           start  = 1;
  2072.           top_line -= 1;
  2073.           if (top_line < 0)
  2074.           {
  2075.             top_line = 0;
  2076.           } /* endif */
  2077.           scrl_lines  = abs(old_top - top_line);
  2078.           break;
  2079.         case PAGE_DOWN:
  2080.           d_flag = UP;
  2081.           start  = 1;
  2082.           top_line += page_length ;
  2083.           scrl_lines  = abs(old_top - top_line);
  2084.           if (top_line > line_number - page_length)
  2085.           {
  2086.             top_line = line_number - page_length;
  2087.             scrl_lines = page_length;
  2088.           } /* endif */
  2089.           if (top_line == old_top)
  2090.           {
  2091.             scrl_lines = 0;
  2092.           } /* endif */
  2093.           break;
  2094.         case DOWN_ARROW:
  2095.           d_flag = UP;
  2096.           start  = page_length;
  2097.           top_line += 1;
  2098.           if (top_line > line_number - page_length)
  2099.           {
  2100.             top_line = line_number - page_length;
  2101.           } /* endif */
  2102.           scrl_lines  = abs(old_top - top_line);
  2103.           break;
  2104.         case LEFT_ARROW:
  2105.           d_flag = UP;
  2106.           scrl_lines = page_length;
  2107.           start  = 1;
  2108.           if (start_col > 0)
  2109.           {
  2110.             start_col = start_col -1;
  2111.           }
  2112.           else
  2113.           {
  2114.             start_col = 0;
  2115.           } /* endif */
  2116.           if (start_col == old_start_col)
  2117.           {
  2118.             scrl_lines = 0;
  2119.           } /* endif */
  2120.           break;
  2121.         case C_LEFT:
  2122.           d_flag = UP;
  2123.           scrl_lines = page_length;
  2124.           start  = 1;
  2125.           start_col = 0;
  2126.           if (start_col == old_start_col)
  2127.           {
  2128.             scrl_lines = 0;
  2129.           } /* endif */
  2130.           break;
  2131.         case RIGHT_ARROW:
  2132.           d_flag = UP;
  2133.           scrl_lines = page_length;
  2134.           start  = 1;
  2135.           if (max_line_length > page_width)
  2136.           {
  2137.             if (start_col < max_line_length - page_width)
  2138.             {
  2139.               start_col = start_col +1;
  2140.             }
  2141.             else
  2142.             {
  2143.               start_col = max_line_length - page_width;
  2144.             } /* endif */
  2145.           }
  2146.           else
  2147.           {
  2148.             start_col = 0;
  2149.           } /* endif */
  2150.           if (start_col == old_start_col)
  2151.           {
  2152.             scrl_lines = 0;
  2153.           } /* endif */
  2154.           break;
  2155.         case C_RIGHT:
  2156.           d_flag = UP;
  2157.           scrl_lines = page_length;
  2158.           start  = 1;
  2159.           if (max_line_length > page_width)
  2160.           {
  2161.             start_col = max_line_length - page_width;
  2162.           }
  2163.           else
  2164.           {
  2165.             start_col = 0;
  2166.           } /* endif */
  2167.           if (start_col == old_start_col)
  2168.           {
  2169.             scrl_lines = 0;
  2170.           } /* endif */
  2171.           break;
  2172.         case HOME:
  2173.           d_flag = DOWN;
  2174.           start  = 1;
  2175.           scrl_lines = page_length;
  2176.           top_line = 0;
  2177.           if (top_line == old_top && start_col == 0)
  2178.           {
  2179.             scrl_lines = 0;
  2180.           } /* endif */
  2181.           start_col = 0;
  2182.           break;
  2183.         case END:
  2184.           d_flag = UP;
  2185.           start = 1;
  2186.           scrl_lines = page_length;
  2187.           top_line = line_number - page_length;
  2188.           if (top_line == old_top && start_col == 0)
  2189.           {
  2190.             scrl_lines = 0;
  2191.           } /* endif */
  2192.           start_col = 0;
  2193.           break;
  2194.         default :
  2195.           scrl_lines = 0;
  2196.           break;
  2197.       } /* endswitch */
  2198.     }
  2199.     else
  2200.     {
  2201.       switch (input)
  2202.       {
  2203.         case '\033':
  2204.           quit = 1;
  2205.           break;
  2206.         case 'p':
  2207.         case 'P':
  2208.           print_file(file_name,name_flag,r_title1,r_title2,max_line_length);
  2209.           quit = 1;
  2210.           break;
  2211.         default :
  2212.           scrl_lines = 0;
  2213.           break;
  2214.       } /* endswitch */
  2215.     } /* endif */
  2216.   } while (!quit); /* enddo */
  2217.  
  2218.   hfree(my_line);
  2219.   _settextcolor(env.frgrd[0]);
  2220.   _setbkcolor(env.bkgrd[0]);
  2221.   set_cursor_on(7,7);
  2222.   return(0);
  2223. } /* end show_file */
  2224. /*---------------------------------------------------------------------------*/
  2225.  
  2226.  
  2227. int compress(char *f_name,char *old_name,int size)
  2228.  
  2229. {
  2230.  
  2231.   int handle1,handle2;
  2232.   char tmp_name[9];
  2233.   char bigbuff[257];
  2234.   char temp[257];
  2235.   int i;
  2236.   long file_length = 0L;
  2237.   long f_position = 0L;
  2238.   int r_counter = 0;
  2239.  
  2240.   strcpy(tmp_name,"IIXXXXXX");
  2241.   if (mktemp(tmp_name) == NULL )
  2242.   {
  2243.     box_message(1,1,"Could not create temp name in compress.",
  2244.                 "Contact The Help Desk",emp);
  2245.   }
  2246.   else
  2247.   {
  2248.     handle1 = sopen(f_name,O_RDONLY|O_BINARY,SH_DENYNO);
  2249.     handle2 = open(tmp_name,O_CREAT|O_RDWR,S_IWRITE);
  2250.  
  2251.     if (handle1 == -1)
  2252.     {
  2253.       return(-1);
  2254.     }
  2255.     else
  2256.     {
  2257.       file_length = filelength(handle1);
  2258.       if (file_length > size)
  2259.       {
  2260.         display_message("Compressing File.  Please Wait !");
  2261.         f_position = lseek(handle1,f_position,SEEK_SET);
  2262.         while (f_position < file_length - 1)
  2263.         {
  2264.           if (locking(handle1,LK_LOCK,256L) != -1)
  2265.           {
  2266.             read(handle1,bigbuff,256);
  2267.             lseek(handle1,f_position,SEEK_SET);
  2268.             locking(handle1,LK_UNLCK,256L);
  2269.             i = 0;
  2270.             while (bigbuff[i] != '\r')
  2271.             {
  2272.               temp[i] = bigbuff[i];
  2273.               i++;
  2274.             } /* endwhile */
  2275.             temp[i] = '\n';
  2276.             if (temp[0] != '#' && temp[8] != '#')
  2277.             {
  2278.               write(handle2,temp,i+1);
  2279.             } /* endif */
  2280.             f_position = f_position + i + 2;
  2281.             f_position = lseek(handle1,f_position,SEEK_SET);
  2282.           }
  2283.           else
  2284.           {
  2285.             box_message(1,1,"Compress 2265: Locking Failed.",emp,NULL);
  2286.             close(handle1);
  2287.             close(handle2);
  2288.             return(11);
  2289.           } /* endif */
  2290.         } /* endwhile */
  2291.  
  2292.         close(handle1);
  2293.         close(handle2);
  2294.  
  2295.         if (access(old_name,02) == 0)
  2296.         {
  2297.           remove(old_name);
  2298.         } /* endif */
  2299.         else
  2300.         {
  2301.           if (errno == EACCES)
  2302.           {
  2303.             chmod(old_name,S_IREAD|S_IWRITE);
  2304.             remove(old_name);
  2305.           } /* endif */
  2306.         } /* endif */
  2307.  
  2308.         r_counter = 0;
  2309.         while (r_counter < 50)
  2310.         {
  2311.           if (rename(f_name,old_name) != 0)
  2312.           {
  2313.             r_counter++;
  2314.           }
  2315.           else
  2316.           {
  2317.             rename(tmp_name,f_name);
  2318.             return(0);
  2319.           } /* endif */
  2320.         } /* endwhile */
  2321.         if (r_counter >= 50)
  2322.         {
  2323.           remove(tmp_name);
  2324.           return(12);
  2325.         } /* endif */
  2326.       } /* endif */
  2327.     } /* endif */
  2328.   } /* endif */
  2329. } /* end compress */
  2330. /*---------------------------------------------------------------------------*/
  2331.  
  2332.  
  2333. int obtain_string( int frame_flag,
  2334.                 char *field,
  2335.                 int new_or_old,
  2336.                 int all_upper,
  2337.                 int  rulh,
  2338.                 int culh,
  2339.                 int length,
  2340.                 struct list_info *list,
  2341.                 int list_count,
  2342.                 char *msg,
  2343.                 int return_field,
  2344.                 char *comp_str)
  2345.  
  2346. {
  2347.   char temp_buf[80];
  2348.   char input = '\0';
  2349.   int i;
  2350.   int quit = 0;
  2351.   int clean_flag = 1;
  2352.   int t_changed = 0;
  2353.   int insert_flag = 0;
  2354.   int goon = 1;
  2355.   int cur_pos = 0;
  2356.   int input_count = 0;
  2357.   int r_code;
  2358.  
  2359.   _settextwindow(1,1,25,80);
  2360.   _settextcolor(env.frgrd[5]);
  2361.   _setbkcolor(env.bkgrd[5]);
  2362.  
  2363.   if (frame_flag)
  2364.   {
  2365.  
  2366.     _settextwindow(rulh,culh,rulh,culh+length+1);
  2367.     _wrapon(_GWRAPOFF);
  2368.     _clearscreen(_GWINDOW);
  2369.     _settextposition(1,1);
  2370.     _outtext("[");
  2371.     _settextposition(1,length+2);
  2372.     _outtext("]");
  2373.     _settextwindow(rulh,culh+1,rulh,culh+length);
  2374.   }
  2375.   else
  2376.   {
  2377.     _settextwindow(rulh,culh,rulh,culh+length-1);
  2378.     _wrapon(_GWRAPOFF);
  2379.     _clearscreen(_GWINDOW);
  2380.   } /* endif */
  2381.  
  2382.   if (new_or_old == OLD)
  2383.   {
  2384.     input_count = cur_pos = strlen(field);
  2385.   }
  2386.   else
  2387.   {
  2388.     field[0] = '\0';
  2389.   } /* endif */
  2390.  
  2391.   do
  2392.   {
  2393.     if (frame_flag)
  2394.     {
  2395.       _settextwindow(rulh,culh+1,rulh,culh+length);
  2396.       _clearscreen(_GWINDOW);
  2397.       _settextwindow(rulh,culh+1,rulh,culh+length+2);
  2398.       _settextposition(1,1);
  2399.     }
  2400.     else
  2401.     {
  2402.       _settextwindow(rulh,culh,rulh,culh+length-1);
  2403.       _clearscreen(_GWINDOW);
  2404.       _settextwindow(rulh,culh,rulh,culh+length);
  2405.       _settextposition(1,1);
  2406.     } /* endif */
  2407.     _outtext(field);
  2408.     _settextposition(1,cur_pos + 1);
  2409.     clean_flag = 0;
  2410.     t_changed = 0;
  2411.  
  2412.     input = (char)getch();
  2413.  
  2414.     if (input == '\0')
  2415.     {
  2416.       input = (char)getch();
  2417.       switch (input)
  2418.       {
  2419.         case INS_KEY:
  2420.           if (insert_flag)
  2421.           {
  2422.             show_option(25,80,"INSERT = OFF",'R',env.frgrd[2],env.bkgrd[2]);
  2423.             insert_flag = 0;
  2424.           }
  2425.           else
  2426.           {
  2427.             show_option(25,80,"INSERT = ON ",'R',env.frgrd[2],env.bkgrd[2]);
  2428.             insert_flag = 1;
  2429.           } /* endif */
  2430.           _settextwindow(rulh,culh+1,rulh,culh+length);
  2431.           _settextcolor(env.frgrd[5]);
  2432.           _setbkcolor(env.bkgrd[5]);
  2433.           break;
  2434.         case UP_ARROW:
  2435.           putchar(BELL);
  2436.           break;
  2437.         case DOWN_ARROW:
  2438.           putchar(BELL);
  2439.           break;
  2440.         case HOME:
  2441.           cur_pos= 0;
  2442.           break;
  2443.         case END:
  2444.           cur_pos=input_count;
  2445.           break;
  2446.         case LEFT_ARROW:
  2447.           if (cur_pos > 0)
  2448.           {
  2449.             cur_pos--;
  2450.           }
  2451.           else
  2452.           {
  2453.             putchar(BELL);
  2454.           } /* endif */
  2455.           break;
  2456.         case RIGHT_ARROW:
  2457.           if (cur_pos < input_count)
  2458.           {
  2459.             cur_pos++;
  2460.           }
  2461.           else
  2462.           {
  2463.             putchar(BELL);
  2464.           } /* endif */
  2465.           break;
  2466.         case DEL_KEY:
  2467.           if (input_count == 0 || cur_pos == input_count)
  2468.           {
  2469.             putchar(BELL);
  2470.           }
  2471.           else
  2472.           {
  2473.             strcpy(temp_buf,field);
  2474.             for (i=0; i < cur_pos - 1; i++)
  2475.             {
  2476.               field[i] = temp_buf[i];
  2477.             } /* endfor */
  2478.             for (i = cur_pos; i < input_count; i++)
  2479.             {
  2480.               field[i] = temp_buf[i+1];
  2481.             } /* endfor */
  2482.             input_count--;
  2483.             t_changed++;
  2484.             field[input_count] = '\0';
  2485.           } /* endif */
  2486.           break;
  2487.         case F1:
  2488.           if (list_count)
  2489.           {
  2490.             _setvisualpage(1);
  2491.             _setactivepage(1);
  2492.             _settextcolor(env.frgrd[0]);
  2493.             _setbkcolor(env.bkgrd[0]);
  2494.             _clearscreen(_GCLEARSCREEN);
  2495.             display_message("Getting List. Please wait");
  2496.             temp_buf[0] = '\0';
  2497.             if (field[0] == ' ')
  2498.             {
  2499.               field[0] = '\0';
  2500.             } /* endif */
  2501.             t_changed = list_field(list,
  2502.                                   list_count,
  2503.                                   msg,
  2504.                                   return_field,
  2505.                                   temp_buf,
  2506.                                   2,1,24,80,
  2507.                                   comp_str);
  2508.             _setactivepage(0);
  2509.             _setvisualpage(0);
  2510.             _settextcolor(env.frgrd[5]);
  2511.             _setbkcolor(env.bkgrd[5]);
  2512.             _settextwindow(1,1,25,80);
  2513.             if (t_changed)
  2514.             {
  2515.                strcpy(field,temp_buf);
  2516.                input_count = strlen(temp_buf);
  2517.                cur_pos = strlen(temp_buf);
  2518.                if (frame_flag)
  2519.                {
  2520.                  _settextwindow(rulh,culh,rulh,culh+length+1);
  2521.                  _wrapon(_GWRAPOFF);
  2522.                  _clearscreen(_GWINDOW);
  2523.                  _settextposition(1,1);
  2524.                  _outtext("[");
  2525.                  _settextposition(1,length+2);
  2526.                  _outtext("]");
  2527.                  _settextwindow(rulh,culh+1,rulh,culh+length);
  2528.                }
  2529.                else
  2530.                {
  2531.                  _settextwindow(rulh,culh,rulh,culh+length-1);
  2532.                  _wrapon(_GWRAPOFF);
  2533.                  _clearscreen(_GWINDOW);
  2534.                } /* endif */
  2535.                _settextposition(1,1);
  2536.                _outtext(field);
  2537.                _settextposition(1,cur_pos);
  2538.             } /* endif */
  2539.           }
  2540.           else
  2541.           {
  2542.             putchar(BELL);
  2543.           } /* endif */
  2544.           break;
  2545.         default :
  2546.           putchar(BELL);
  2547.           break;
  2548.       } /* endswitch */
  2549.     }
  2550.     else
  2551.     {
  2552.       if (input == '\033')
  2553.       {
  2554.         field[0] = '\0';
  2555.         quit = 1;
  2556.         r_code = -1;
  2557.       }
  2558.       else
  2559.       {
  2560.         if (input == '\015')
  2561.         {
  2562.           field[input_count] = '\0';
  2563.           quit = 1;
  2564.           r_code = strlen(field);
  2565.         }
  2566.         else
  2567.         {
  2568.           if (input == ',')
  2569.           {
  2570.             putchar(BELL);
  2571.           }
  2572.           else
  2573.           {
  2574.             if (input == '\b')
  2575.             {
  2576.               if (input_count == 0 || cur_pos == 0)
  2577.               {
  2578.                 putchar(BELL);
  2579.               }
  2580.               else
  2581.               {
  2582.                 if (cur_pos < input_count)
  2583.                 {
  2584.                   strcpy(temp_buf,field);
  2585.                   for (i=0; i < cur_pos - 2; i++)
  2586.                   {
  2587.                     field[i] = temp_buf[i];
  2588.                   } /* endfor */
  2589.                   for (i = cur_pos - 1; i < input_count; i++)
  2590.                   {
  2591.                     field[i] = temp_buf[i+1];
  2592.                   } /* endfor */
  2593.                 } /* endif */
  2594.                 cur_pos--;
  2595.                 input_count--;
  2596.                 t_changed++;
  2597.                 field[input_count] = '\0';
  2598.               } /* endif */
  2599.             }
  2600.             else
  2601.             {
  2602.               if (input_count < length)
  2603.               {
  2604.                 if (input_count == cur_pos)
  2605.                 {
  2606.                   if (all_upper)
  2607.                   {
  2608.                     field[input_count] = (char) toupper(input);
  2609.                   }
  2610.                   else
  2611.                   {
  2612.                     field[input_count] = input;
  2613.                   } /* endif */
  2614.                   field[input_count+1] = '\0';
  2615.                   input_count++;
  2616.                   cur_pos++;
  2617.                   t_changed++;
  2618.                 }
  2619.                 else
  2620.                 {
  2621.                   if (insert_flag)
  2622.                   {
  2623.                     strcpy(temp_buf,field);
  2624.                     for (i=0; i <= cur_pos - 1; i++)
  2625.                     {
  2626.                       field[i] = temp_buf[i];
  2627.                     } /* endfor */
  2628.                     if (all_upper)
  2629.                     {
  2630.                       field[cur_pos] = (char) toupper(input);
  2631.                     }
  2632.                     else
  2633.                     {
  2634.                       field[cur_pos] = input;
  2635.                     } /* endif */
  2636.                     for (i = cur_pos + 1; i <= input_count; i++)
  2637.                     {
  2638.                       field[i] = temp_buf[i-1];
  2639.                     } /* endfor */
  2640.                     input_count++;
  2641.                     cur_pos++;
  2642.                     field[input_count] = '\0';
  2643.                     t_changed++;
  2644.                   }
  2645.                   else
  2646.                   {
  2647.                     putchar(BELL);
  2648.                   } /* endif */
  2649.                 } /* endif */
  2650.               }
  2651.               else
  2652.               {
  2653.                 putchar(BELL);
  2654.               } /* endif */
  2655.             } /* endif */
  2656.           } /* endif */
  2657.         } /* endif */
  2658.       } /* endif */
  2659.     } /* endif */
  2660.   } while (!quit); /* enddo */
  2661.  
  2662.   _settextcolor(env.frgrd[0]);
  2663.   _setbkcolor(env.bkgrd[0]);
  2664.   _settextwindow(1,1,25,80);
  2665.   return(r_code);
  2666.  
  2667. } /* end obtain_string */
  2668. /*---------------------------------------------------------------------------*/
  2669.  
  2670.  
  2671. int list_field(struct list_info *list,
  2672.                int list_count,
  2673.                char *msg,
  2674.                int  return_field,
  2675.                char *line_buff,
  2676.                int rulh,int culh,int rbrh,int cbrh,
  2677.                char *comp_str)
  2678.  
  2679. {
  2680.  
  2681.   char user_field[15][61];
  2682.   int  counter = 0;
  2683.   int k;
  2684.   struct file_line *my_line;
  2685.   char choice1;
  2686.   int line_number = 1;
  2687.   int i,j;
  2688.   int r_code;
  2689.   int page_length = 0;
  2690.   int page_width = 0;
  2691.   int top_line = 0;
  2692.   int old_top = 0;
  2693.   int quit =0;
  2694.   int d_flag;
  2695.   int start;
  2696.   int in_len = 39;
  2697.   int show_flag = 0;
  2698.  
  2699.   int scrl_lines = 0;
  2700.   int cur_line = 1;
  2701.   int old_cur_line = 1;
  2702.  
  2703.   int color_mask = 0;
  2704.  
  2705.   my_line = (struct file_line *)calloc(line_number,sizeof(struct file_line));
  2706.   if (my_line == NULL)
  2707.   {
  2708.     box_message(1,1,"Memory allocation error",emp,NULL);
  2709.     set_cursor_on(7,7);
  2710.     return(2);
  2711.   } /* endif */
  2712.  
  2713.   display_message("Reading List. Please wait.");
  2714.   for (i=0; i<list_count-1; i++)
  2715.   {
  2716.     if (comp_str[0] == '\0')
  2717.     {
  2718.       show_flag = 1;
  2719.       strcpy(my_line[line_number-1].line,list[i].id);
  2720.       strcat(my_line[line_number-1].line,"│");
  2721.       strcat(my_line[line_number-1].line,list[i].name);
  2722.       line_number++;
  2723.       my_line = (struct file_line *)realloc(my_line,line_number*sizeof(struct file_line));
  2724.       if (my_line == NULL)
  2725.       {
  2726.         box_message(1,1,"Memory allocation error",emp,NULL);
  2727.         set_cursor_on(7,7);
  2728.         return(2);
  2729.       } /* endif */
  2730.     }
  2731.     else
  2732.     {
  2733.       if (strncmp(list[i].name,comp_str,strlen(comp_str)) == 0)
  2734.       {
  2735.         show_flag = 1;
  2736.         strcpy(my_line[line_number-1].line,list[i].id);
  2737.         strcat(my_line[line_number-1].line,"│");
  2738.         strcat(my_line[line_number-1].line,list[i].name);
  2739.         line_number++;
  2740.         my_line = (struct file_line *)realloc(my_line,line_number*sizeof(struct file_line));
  2741.         if (my_line == NULL)
  2742.         {
  2743.           box_message(1,1,"Memory allocation error",emp,NULL);
  2744.           set_cursor_on(7,7);
  2745.           return(2);
  2746.         } /* endif */
  2747.       } /* endif */
  2748.     } /* endif */
  2749.   } /* endfor */
  2750.  
  2751.   if (show_flag)
  2752.   {
  2753.     line_number = line_number - 1;
  2754.     page_length = rbrh - rulh - 1;
  2755.  
  2756.     if (line_number < page_length)
  2757.     {
  2758.       page_length = line_number;
  2759.       rbrh = rulh + line_number + 1;
  2760.     } /* endif */
  2761.  
  2762.     scrl_lines = page_length;
  2763.     cur_line = 1;
  2764.     old_cur_line = 1;
  2765.     start = 1;
  2766.     top_line = 0;
  2767.     d_flag = UP;
  2768.  
  2769.     page_width  = cbrh - culh - 1;
  2770.  
  2771.     color_mask = 16*(int)env.bkgrd[3] + env.frgrd[3];
  2772.  
  2773.     _settextwindow(1,1,25,80);
  2774.     _clearscreen(_GWINDOW);
  2775.     frame(rulh,culh,rbrh - rulh + 1,page_width + 2,env.frgrd[2],env.bkgrd[2]);
  2776.     _settextcolor(env.frgrd[0]);
  2777.     _setbkcolor(env.bkgrd[0]);
  2778.     show_option(1,40,msg,'C',env.frgrd[1],env.bkgrd[1]);
  2779.     show_option(25,40,"Use   PgUp PgDn Home End to highlight selection, F10 = Select, Esc =  quit",'C',env.frgrd[1],env.bkgrd[1]);
  2780.     _settextwindow(rulh + 1,culh + 1,rbrh - 1,cbrh - 1);
  2781.     _clearscreen(_GWINDOW);
  2782.     _settextcolor(env.frgrd[3]);
  2783.     _setbkcolor(env.bkgrd[3]);
  2784.  
  2785.     do
  2786.     {
  2787.  
  2788.       if (scrl_lines != 0)
  2789.       {
  2790.         scroll(d_flag,rulh + 1,culh + 1,rbrh - 1,cbrh - 1,scrl_lines,color_mask);
  2791.         for (j=0 ; j < scrl_lines; j++)
  2792.         {
  2793.           _settextposition(start+j,1);
  2794.           _outtext(my_line[j+top_line+start-1].line);
  2795.         } /* endfor */
  2796.       } /* endif */
  2797.  
  2798.       _settextcolor(env.frgrd[3]);
  2799.       _settextposition(old_cur_line,1);
  2800.       _outtext(my_line[top_line+old_cur_line-1].line);
  2801.       _settextcolor(env.frgrd[1]);
  2802.       _settextposition(cur_line,1);
  2803.       _outtext(my_line[top_line+cur_line-1].line);
  2804.       _settextcolor(env.frgrd[3]);
  2805.       _settextposition(cur_line,1);
  2806.  
  2807.       strcpy(line_buff,my_line[top_line+cur_line-1].line);
  2808.  
  2809.       choice1 = (char)getch();
  2810.       old_top = top_line;
  2811.       if (choice1 == '\0')
  2812.       {
  2813.         choice1 = (char)getch();
  2814.         switch (choice1)
  2815.         {
  2816.           case PAGE_UP:
  2817.             d_flag = DOWN;
  2818.             if (old_top > 0)
  2819.             {
  2820.               start  = 1;
  2821.               top_line -= page_length - 1;
  2822.               if (top_line < 0)
  2823.               {
  2824.                 top_line = 0;
  2825.               } /* endif */
  2826.               scrl_lines = page_length;
  2827.               old_cur_line = cur_line;
  2828.               cur_line = 1;
  2829.             }
  2830.             else
  2831.             {
  2832.               scrl_lines = 0;
  2833.               if (cur_line == 1)
  2834.               {
  2835.                 putchar(BELL);
  2836.               }
  2837.               else
  2838.               {
  2839.                 old_cur_line = cur_line;
  2840.                 cur_line = 1;
  2841.               } /* endif */
  2842.             } /* endif */
  2843.             break;
  2844.           case UP_ARROW:
  2845.             d_flag = DOWN;
  2846.             if (cur_line == 1)
  2847.             {
  2848.               start  = 1;
  2849.               old_cur_line = cur_line + 1;
  2850.               top_line -= 1;
  2851.               if (top_line < 0)
  2852.               {
  2853.                 top_line = 0;
  2854.                 putchar(BELL);
  2855.               } /* endif */
  2856.             }
  2857.             else
  2858.             {
  2859.               old_cur_line = cur_line;
  2860.               cur_line--;
  2861.             } /* endif */
  2862.             scrl_lines  = abs(old_top - top_line);
  2863.             break;
  2864.           case PAGE_DOWN:
  2865.             d_flag = UP;
  2866.             if (old_top < line_number - page_length)
  2867.             {
  2868.               start  = 1;
  2869.               top_line += page_length - 1;
  2870.               if (top_line > line_number - page_length)
  2871.               {
  2872.                 top_line = line_number - page_length;
  2873.               } /* endif */
  2874.               scrl_lines = page_length;
  2875.               old_cur_line = cur_line;
  2876.               cur_line = page_length;
  2877.             }
  2878.             else
  2879.             {
  2880.               scrl_lines = 0;
  2881.               if (cur_line == page_length)
  2882.               {
  2883.                 putchar(BELL);
  2884.               }
  2885.               else
  2886.               {
  2887.                 old_cur_line = cur_line;
  2888.                 cur_line = page_length;
  2889.               } /* endif */
  2890.             } /* endif */
  2891.             break;
  2892.           case DOWN_ARROW:
  2893.             d_flag = UP;
  2894.             if (cur_line == page_length)
  2895.             {
  2896.               old_cur_line = cur_line-1;
  2897.               start  = page_length;
  2898.               top_line += 1;
  2899.               if (top_line > line_number - page_length)
  2900.               {
  2901.                 top_line = line_number - page_length;
  2902.                 putchar(BELL);
  2903.               } /* endif */
  2904.             }
  2905.             else
  2906.             {
  2907.               old_cur_line = cur_line;
  2908.               cur_line++;
  2909.             } /* endif */
  2910.             scrl_lines  = abs(old_top - top_line);
  2911.             break;
  2912.           case HOME:
  2913.             d_flag = DOWN;
  2914.             if (top_line > 0)
  2915.             {
  2916.               start  = 1;
  2917.               scrl_lines = page_length;
  2918.               top_line = 0;
  2919.               old_cur_line = cur_line;
  2920.               cur_line = 1;
  2921.             }
  2922.             else
  2923.             {
  2924.               scrl_lines = 0;
  2925.               if (cur_line == 1)
  2926.               {
  2927.                 putchar(BELL);
  2928.               }
  2929.               else
  2930.               {
  2931.                 old_cur_line = cur_line;
  2932.                 cur_line =1;
  2933.               } /* endif */
  2934.             } /* endif */
  2935.             break;
  2936.           case END:
  2937.             d_flag = UP;
  2938.             if (old_top < line_number - page_length)
  2939.             {
  2940.               start = 1;
  2941.               scrl_lines = page_length;
  2942.               top_line = line_number - page_length;
  2943.               if (top_line == old_top)
  2944.               {
  2945.                 scrl_lines = 0;
  2946.               } /* endif */
  2947.               old_cur_line = cur_line;
  2948.               cur_line = page_length;
  2949.             }
  2950.             else
  2951.             {
  2952.               scrl_lines = 0;
  2953.               if (cur_line == page_length)
  2954.               {
  2955.                 putchar(BELL);
  2956.               }
  2957.               else
  2958.               {
  2959.                 old_cur_line = cur_line;
  2960.                 cur_line = page_length;
  2961.               } /* endif */
  2962.             } /* endif */
  2963.             break;
  2964.           case F10:
  2965.             quit = 1;
  2966.             r_code = cur_line;
  2967.             counter = 0;
  2968.             j = 0;
  2969.             for (k=0; k <= in_len;k++)
  2970.             {
  2971.               if (line_buff[k] == '│'|| line_buff[k] == '\0')
  2972.               {
  2973.                 user_field[counter][j] = '\0';
  2974.                 counter++;
  2975.                 j = 0;
  2976.               }
  2977.               else
  2978.               {
  2979.                 user_field[counter][j] = line_buff[k];
  2980.                 j++;
  2981.               } /* endif */
  2982.             } /* endfor */
  2983.             strcpy(line_buff,user_field[return_field - 1]);
  2984.             break;
  2985.           default :
  2986.             break;
  2987.         } /* endswitch */
  2988.       }
  2989.       else
  2990.       {
  2991.         switch (choice1)
  2992.         {
  2993.           case '\033':
  2994.             quit = 1;
  2995.             r_code = 0;
  2996.             break;
  2997.           case '\015':
  2998.             d_flag = UP;
  2999.             if (cur_line == page_length)
  3000.             {
  3001.               start  = page_length;
  3002.               top_line += 1;
  3003.               if (top_line > line_number - page_length)
  3004.               {
  3005.                 top_line = line_number - page_length;
  3006.                 putchar(BELL);
  3007.               } /* endif */
  3008.             }
  3009.             else
  3010.             {
  3011.               old_cur_line = cur_line;
  3012.               cur_line++;
  3013.             } /* endif */
  3014.             scrl_lines  = abs(old_top - top_line);
  3015.             break;
  3016.           default :
  3017.             break;
  3018.         } /* endswitch */
  3019.       } /* endif */
  3020.     } while (!quit); /* enddo */
  3021.   } /* endif */
  3022.   free(my_line);
  3023.   set_cursor_on(7,7);
  3024.   return(r_code);
  3025. } /* end list_field */
  3026. /* ------------------------------------------------------------------ */
  3027.  
  3028.  
  3029. void do_titles(int fg_color,
  3030.                char *c_name,
  3031.                char *p_name,
  3032.                char *proj_name,
  3033.                char *d_buff,
  3034.                long bk_color)
  3035.  
  3036. {
  3037.  
  3038.   _settextcolor(fg_color);
  3039.   _setbkcolor(bk_color);
  3040.   _settextwindow(1,1,25,80);
  3041.   _clearscreen(_GWINDOW);
  3042.  
  3043.   show_option(1,40,c_name,'C',env.frgrd[1],env.bkgrd[1]);
  3044.   show_option(2,40,p_name,'C',env.frgrd[1],env.bkgrd[1]);
  3045.   show_option(3,40,proj_name,'C',env.frgrd[1],env.bkgrd[1]);
  3046.   show_option(1,1,d_buff,'L',env.frgrd[1],env.bkgrd[1]);
  3047. }  /* end do_titles */
  3048.