home *** CD-ROM | disk | FTP | other *** search
/ Hot Shareware 35 / hot35.iso / ficheros / LC / SIMPWN93.ZIP / SIMPWIN.ZIP / READOC92.C < prev    next >
C/C++ Source or Header  |  1997-09-12  |  15KB  |  740 lines

  1. /* simpwin9 copyright 1995 - 1997 by bruce r. o'banion */
  2.  
  3. # include <dos.h>
  4. # include <string.h>
  5. # include <stdio.h>
  6. # include <bios.h>
  7. # include <stdlib.h>
  8. # include <conio.h>
  9. # include <mem.h>
  10. # include <dir.h>
  11.  
  12.  
  13. # include "simpwn92.h"
  14. # include "skdef92.h"
  15. # include "mouse92.h"
  16.  
  17.  
  18. # define MAIN_WIN 1
  19. # define DIREC_WIN 2
  20. # define ENTER_WIN 3
  21. # define DESK_WIN 4
  22. # define QUIT_WIN 5
  23.  
  24. int mou_switch;
  25. char file_name[256];
  26. int display_switch = 1;
  27. int file_loaded = 0;
  28. int dev_error;
  29. unsigned char *read_buff;
  30.  
  31. int main_menu(void);
  32. int readocs(void);
  33. int printdocs(void);
  34. int get_file(void);
  35. int quit(void);
  36. int help_screen(char *file_name);
  37. int print_char(unsigned char prn_char);
  38. int read_directory(char *buff,int num_file,char *directory);
  39. int print_string_func(unsigned char *print_string);
  40.  
  41. void main(void)
  42. {
  43.     int i,j,k;
  44.  
  45.     system("cls");
  46.     hide_cursor();
  47.     if((read_buff = (char*)malloc(256)) == NULL)
  48.     {
  49.         cprintf("Not enough memory!");
  50.         exit(1);
  51.     }
  52.     if(init_window(7,4,"") == 1)
  53.     {
  54.         cprintf("Unable to install simple windows");
  55.         free(read_buff);
  56.         exit(1);
  57.     }
  58.     if(mouinstalled() != 0)
  59.     {
  60.         moureset();
  61.         mouhide();
  62.         mousetposition(1,1);
  63.         mou_switch = 1;
  64.         simp_window(30,10,50,12,1,0,14,4,0,0,0,0,0);
  65.         write_window(3,2,"Mouse Installed !");
  66.         delay(1000);
  67.     }
  68.     else
  69.     {
  70.         simp_window(23,10,57,12,1,0,14,4,0,0,0,0,0);
  71.         write_window(3,2,"NO mouse driver installed");
  72.         delay(1000);
  73.     }
  74.     k= 3;
  75.     for(i = 0;i < 13;i++)
  76.     {
  77.         for(j = k - 3;j < k;j++)
  78.         {
  79.             simp_window(40 - j,13 - i,40 + j,13 + i,1,0,14,4,1,0,0,0,0);
  80.         }
  81.         k = k + 3;
  82.     }
  83.     simp_window(1,1,80,25,1,0,14,4,1,0,0,0,0);
  84.     write_window(35,25," HIT ANY KEY ");
  85.     read_text("readoc92.scr",2);
  86.     save_screen(1);
  87.     moucursortype(0x01);
  88.     moushow();
  89.     while(main_menu())
  90.     {
  91.     }
  92.     uninit_window();
  93.     show_cursor();
  94.     free(read_buff);
  95.     system("cls");
  96. }
  97.  
  98. int main_menu(void)
  99. {
  100.     int pick,choice,i = 0,old_i = 9,mousex = 0,mousey = 0;
  101.     char lable[4][13] = {"File","Read","Print","eXit"};
  102.  
  103.     if(display_switch)
  104.     {
  105.         load_screen(1);
  106.         popup_window(MAIN_WIN,5,3,51,5,2,2,14,6,1,8,0,0,0);
  107.         write_window(3,2,"File        Read         Print         eXit");
  108.         save_screen(2);
  109.     }
  110.     else
  111.     {
  112.         load_screen(2);
  113.     }
  114.  
  115.     display_switch = 0;
  116.     textcolor(0);
  117.     write_window(3,2,"F");
  118.     write_window(15,2,"R");
  119.     write_window(28,2,"P");
  120.     write_window(43,2,"X");
  121.     save_screen(0);
  122.     i = 0;
  123.     moushow();
  124.     for(;;)
  125.     {
  126.         choice = 0;
  127.         if(mouposition(&mousex,&mousey))
  128.         {
  129.             if(mousey == 4)
  130.             {
  131.                 if((mousex > 5) & (mousex < 11))
  132.                 {
  133.                     i = 0;
  134.                 }
  135.                 else if((mousex > 17) & (mousex < 24))
  136.                 {
  137.                     i = 1;
  138.                 }
  139.                 else if((mousex > 30) & (mousex < 39))
  140.                 {
  141.                     i = 2;
  142.                 }
  143.                 else if((mousex > 44) & (mousex < 50))
  144.                 {
  145.                     i = 3;
  146.                 }
  147.             }
  148.         }
  149.         if(bioskey(1) | (mou_switch == 0))
  150.         {
  151.             switch(bioskey(0))
  152.             {
  153.                 case ESC : choice = 6; break;
  154.                 case CURSOR_RIGHT : i = i + 1; break;
  155.                 case CURSOR_LEFT : i = i - 1; break;
  156.                 case ENTER : choice = 1; break;
  157.                 case ALT_F : choice = 2; break;
  158.                 case ALT_R : choice = 3; break;
  159.                 case ALT_X : choice = 5; break;
  160.                 case ALT_P : choice = 4; break;
  161.                 case F1 : switch(i)
  162.                             {
  163.                         case 0 : help_screen("help0.txt"); break;
  164.                         case 1 : help_screen("help1.txt"); break;
  165.                         case 2 : help_screen("help2.txt"); break;
  166.                         case 3 : help_screen("help3.txt"); break;
  167.                             }
  168.                             break;
  169.             }
  170.         }
  171.         if(i < 0)
  172.         {
  173.             i = 0;
  174.         }
  175.         if(i > 3)
  176.         {
  177.             i = 3;
  178.         }
  179.         if(old_i != i)
  180.         {
  181.             mouhide();
  182.             old_i = i;
  183.             load_screen(0);
  184.             switch(i)
  185.             {
  186.                 case 0 : simp_window(6,4,11,4,0,2,0,4,1,8,0,0,0); break;
  187.                 case 1 : simp_window(18,4,24,4,0,2,0,4,1,8,0,0,0); break;
  188.                 case 2 : simp_window(31,4,39,4,0,2,0,4,1,8,0,0,0); break;
  189.                 case 3 : simp_window(45,4,50,4,0,2,0,4,1,8,0,0,0); break;
  190.             }
  191.             write_window(2,1,"%s",lable[i]);
  192.             moushow();
  193.         }
  194.         if(moubuttonpressed(LEFTBUTTON))
  195.         {
  196.             if(mousey == 4)
  197.             {
  198.                 if(((mousex > 5) & (mousex < 11)) |
  199.                     ((mousex > 17) & (mousex < 24)) |
  200.                     ((mousex > 30) & (mousex < 39)) |
  201.                     ((mousex > 44) & (mousex < 50)))
  202.                 {
  203.                     choice = 1;
  204.                 }
  205.             }
  206.         }
  207.         if(choice != 0)
  208.         {
  209.             break;
  210.         }
  211.     }
  212.     mouhide();
  213.     load_screen(0);
  214.     if(choice == 1)
  215.     {
  216.         choice = i + 2;
  217.     }
  218.     pick = 1;
  219.     switch(choice)
  220.     {
  221.         case 2 : get_file(); break;
  222.         case 3 : readocs(); break;
  223.         case 4 : printdocs(); break;
  224.         case 6 :
  225.         case 5 : pick = quit(); break;
  226.     }
  227.     return(pick);
  228. }
  229.  
  230. int get_file(void)
  231. {
  232.     char *directory;
  233.     int i,j,num_files2 = 0;
  234.     int mousex = 0,mousey = 0,oldi = 80,oldj = 80,choice,pick;
  235.     int max_x,max_y,file_num = 0;
  236.     char *file_pt;
  237.     char temp_name[256];
  238.  
  239.     strcpy(temp_name,file_name);
  240.     if((directory = (char*)malloc(13 * 70)) == NULL)
  241.     {
  242.         popup_window(ENTER_WIN,5,10,75,12,1,2,14,4,1,8,0,0,0);
  243.         write_window(3,2,"NOT enough memory!");
  244.         bioskey(0);
  245.         unpopup_window(ENTER_WIN);
  246.         return(1);
  247.     }
  248.     memset(directory,0,13 * 70);
  249.     strcpy(file_name,"*.doc");
  250.     popup_window(ENTER_WIN,5,10,75,12,1,2,0,7,1,8,0,0,0);
  251.     write_window(3,2,"Enter file name: ");
  252.     show_cursor();
  253.     if(get_string(file_name,"                                                           ",
  254.                     "***********************************************************",
  255.                                 20,2,1,1) != 0)
  256.     {
  257.         hide_cursor();
  258.         unpopup_window(ENTER_WIN);
  259.         strcpy(file_name,temp_name);
  260.         return(1);;
  261.     }
  262.     hide_cursor();
  263.     if((strstr(file_name,"*") != NULL) | (strstr(file_name,"?") != NULL))
  264.     {
  265.         if(read_directory(directory,70,file_name) == 1)
  266.         {
  267.             clear_window(0);
  268.             write_window(3,2,"NO FILE FOUND");
  269.             bioskey(0);
  270.             unpopup_window(ENTER_WIN);
  271.             return(1);
  272.         }
  273.         unpopup_window(ENTER_WIN);
  274.         popup_window(DIREC_WIN,4,5,76,20,1,2,0,7,1,8,0,0,0);
  275.         for(i = 0;i < 5;i++)
  276.         {
  277.             for(j = 0;j < 14;j++)
  278.             {
  279.                 if(strcmp(&directory[(j * 13) + (i * 182)],"") != 0)
  280.                 {
  281.                     file_num++;
  282.                 }
  283.                 else
  284.                 {
  285.                     i = 5;
  286.                     break;
  287.                 }
  288.                 write_window((i * 14) + 3,j + 2,"%s ",&directory[(j * 13) + (i * 182)]);
  289.             }
  290.         }
  291.         max_x = ((file_num / 14) * 14) + 19;
  292.         max_y = (file_num - ((file_num / 14) * 14) + 6);
  293.         save_screen(0);
  294.         i = 0;
  295.         j = 0;
  296.         moushow();
  297.         for(;;)
  298.         {
  299.             choice = 0;
  300.             if(mouposition(&mousex,&mousey))
  301.             {
  302.                 if((mousex > 5) & (mousex < 18))
  303.                 {
  304.                     j = 0;
  305.                 }
  306.                 if((mousex > 19) & (mousex < 32))
  307.                 {
  308.                     j = 1;
  309.                 }
  310.                 if((mousex > 33) & (mousex < 46))
  311.                 {
  312.                     j = 2;
  313.                 }
  314.                 if((mousex > 47) & (mousex < 60))
  315.                 {
  316.                     j = 3;
  317.                 }
  318.                 if((mousex > 61) & (mousex < 74))
  319.                 {
  320.                     j = 4;
  321.                 }
  322.                 i = mousey - 6;
  323.             }
  324.             if(bioskey(1) | (mou_switch == 0))
  325.             {
  326.                 switch(bioskey(0))
  327.                 {
  328.                     case ESC : choice = 2; break;
  329.                     case CURSOR_UP : i = i - 1; break;
  330.                     case CURSOR_DN : i = i + 1; break;
  331.                     case CURSOR_RIGHT : j = j + 1; break;
  332.                     case CURSOR_LEFT : j = j - 1; break;
  333.                     case ENTER : choice = 1; break;
  334.                     case F1 : help_screen("help4.txt"); break;
  335.                 }
  336.             }
  337.             if(i < 0)
  338.             {
  339.                 i = 0;
  340.             }
  341.             else if(i > 13)
  342.             {
  343.                 i = 13;
  344.             }
  345.             else if(j < 0)
  346.             {
  347.                 j = 0;
  348.             }
  349.             else if(j > 4)
  350.             {
  351.                 j = 4;
  352.             }
  353.             if(((j * 14) + i) > file_num - 1)
  354.             {
  355.                 if((file_num - 57) >= 0)
  356.                 {
  357.                     j = 4;
  358.                     i = file_num - 57;
  359.                 }
  360.                 else
  361.                 {
  362.                     if((file_num - 43) >= 0)
  363.                     {
  364.                         j = 3;
  365.                         i = file_num - 43;
  366.                     }
  367.                     else
  368.                     {
  369.                         if((file_num - 29) >= 0)
  370.                         {
  371.                             j = 2;
  372.                             i = file_num - 29;
  373.                         }
  374.                         else
  375.                         {
  376.                             if((file_num - 15) >= 0)
  377.                             {
  378.                                 j = 1;
  379.                                 i = file_num - 15;
  380.                             }
  381.                             else
  382.                             {
  383.                                 j = 0;
  384.                                 i = file_num - 1;
  385.                             }
  386.                         }
  387.                     }
  388.                 }
  389.             }
  390.             if((oldi != i) | (oldj != j))
  391.             {
  392.                 mouhide();
  393.                 load_screen(0);
  394.                 oldi = i;
  395.                 oldj = j;
  396.                 simp_window(5 + (j * 14),i + 6,18 + (j * 14),i + 6,0,2,0,4,1,8,0,0,0);
  397.                 write_window(2,1,"%s",&directory[(j * 182) + (i * 13)]);
  398.                 moushow();
  399.             }
  400.             if(moubuttonpressed(LEFTBUTTON))
  401.             {
  402.                 if((mousex < (max_x - 14)) & (mousey > 5) & (mousey < 20))
  403.                 {
  404.                     choice = 1;
  405.                 }
  406.                 else
  407.                 {
  408.                     if((mousex < max_x) & (mousey > 5) & (mousey < max_y))
  409.                     {
  410.                         choice = 1;
  411.                     }
  412.                     else
  413.                     {
  414.                         choice = 2;
  415.                     }
  416.                 }
  417.             }
  418.             if(choice != 0)
  419.             {
  420.                 break;
  421.             }
  422.         }
  423.         if(choice == 1)
  424.         {
  425.             num_files2 = (j * 14) + i;
  426.             if((file_pt = strrchr(file_name,'\\')) != NULL)
  427.             {
  428.                 file_pt[1] = '';
  429.                 strcat(file_name,&directory[num_files2 * 13]);
  430.             }
  431.             else
  432.             {
  433.                 if((file_pt = strrchr(file_name,':')) != NULL)
  434.                 {
  435.                     file_pt[1] = '';
  436.                     strcat(file_name,&directory[num_files2 * 13]);
  437.                 }
  438.                 else
  439.                 {
  440.                     strcpy(file_name,&directory[num_files2 * 13]);
  441.                 }
  442.             }
  443.             file_loaded = 1;
  444.         }
  445.         if(choice == 80)
  446.         {
  447.             strcpy(file_name,temp_name);
  448.             pick = 1;
  449.         }
  450.     }
  451.     unpopup_window(DIREC_WIN);
  452.     free(directory);
  453.     return(pick);
  454. }
  455.  
  456. int help_screen(char *file_name)
  457. {
  458.     popup_window(DESK_WIN,1,1,80,25,1,0,14,1,0,0,0,0,0);
  459.     write_window(35,25," HIT ANY KEY ");
  460.     read_text(file_name,2);
  461.     unpopup_window(DESK_WIN);
  462.     return(0);
  463.  
  464. }
  465.  
  466. int readocs(void)
  467. {
  468.     if(file_loaded == 0)
  469.     {
  470.         get_file();
  471.     }
  472.     popup_window(DESK_WIN,1,1,80,25,1,0,14,1,0,0,0,0,0);
  473.     write_window(33,25," PgUp/PgDn ESC ");
  474.     write_window((80 - strlen(file_name)) / 2,1," %s ",file_name);
  475.     read_text(file_name,1);
  476.     unpopup_window(DESK_WIN);
  477.     return(0);
  478. }
  479.  
  480. int printdocs(void)
  481. {
  482.     unsigned long int start_byte = 0L;
  483.     int y,page_num = 1,i;
  484.     unsigned char page_string[80];
  485.     unsigned char page_number[10];
  486.     unsigned char page_num_string[30];
  487.     unsigned char print_page_string[80];
  488.     unsigned char print_line[5];
  489.     unsigned char print_string[90];
  490.     unsigned char *temp_point;
  491.     int error;
  492.  
  493.     if(file_loaded == 0)
  494.     {
  495.         get_file();
  496.     }
  497.     popup_window(6,20,10,52,12,2,2,14,4,1,8,0,0,0);
  498.     if(print_char(0x0c) != 0)
  499.     {
  500.         write_window(3,2,"Printer error hit a key!");
  501.         bioskey(0);
  502.         unpopup_window(6);
  503.     }
  504.     write_window(3,2,"Align paper and hit any key.");
  505.     bioskey(0);
  506.     clear_window(0);
  507.     write_window(3,2,"  Printing!  Hit ESC to quit");
  508.     y = 1;
  509.     for(i = 0;i < (((71 - strlen(file_name)) / 2) + 9);i++)
  510.     {
  511.         page_string[i] = 0x20;
  512.     }
  513.     page_string[i] = 0x00;
  514.     strcat(page_string,file_name);
  515.     strcat(page_string," \r\n");
  516.     print_line[0] = '\r';
  517.     print_line[1] = '\n';
  518.     print_line[2] = 0x00;
  519.     while((error = read_file(read_buff,file_name,256,start_byte)) < 1)
  520.     {
  521.         if(read_buff[0] == 0x00)
  522.         {
  523.             break;
  524.         }
  525.         if(error > 0)
  526.         {
  527.             break;
  528.         }
  529.         else
  530.         {
  531.             error = 0;
  532.         }
  533.         temp_point = strchr(read_buff,'\n');
  534.         temp_point[1] = 0x00;
  535.         start_byte = start_byte + strlen(read_buff);
  536.         if(strlen(read_buff) > 70)
  537.         {
  538.             read_buff[70] = '\r';
  539.             read_buff[71] = '\n';
  540.             read_buff[72] = 0x00;
  541.         }
  542.         memset(print_string,0x20,20);
  543.         print_string[8] = 0x00;
  544.         strcat(print_string,read_buff);
  545.         if(y == 1)
  546.         {
  547.             if((error = print_string_func(page_string)) != 0)
  548.             {
  549.                 break;
  550.             }
  551.             else
  552.             {
  553.                 y++;
  554.                 if((error = print_string_func(print_line)) != 0)
  555.                 {
  556.                     break;
  557.                 }
  558.                 y++;
  559.             }
  560.         }
  561.         if(y < 59)
  562.         {
  563.             if((error =print_string_func(print_string)) != 0)
  564.             {
  565.                 break;
  566.             }
  567.             y++;
  568.         }
  569.         if(y == 59)
  570.         {
  571.             strcpy(page_num_string,"Page: ");
  572.             itoa(page_num,page_number,10);
  573.             strcat(page_num_string,page_number);
  574.             memset(print_page_string,0x20,80);
  575.             print_page_string[(71 - strlen(page_num_string)) / 2] = 0x00;
  576.             strcat(print_page_string,page_num_string);
  577.             strcat(print_page_string," \r\n");
  578.             if((error = print_string_func(print_line)) != 0)
  579.             {
  580.                 break;
  581.             }
  582.             if((error = print_string_func(print_page_string)) != 0)
  583.             {
  584.                 break;
  585.             }
  586.             if((error = print_char(0x0c)) != 0)
  587.             {
  588.                 break;
  589.             }
  590.             y = 1;
  591.             page_num++;
  592.         }
  593.         memset(read_buff,0,256);
  594.     }
  595.     if(error < 1)
  596.     {
  597.         if(y < 59)
  598.         {
  599.             memset(print_page_string,0x20,80);
  600.             strcpy(page_num_string,"Page: ");
  601.             itoa(page_num,page_number,10);
  602.             strcat(page_num_string,page_number);
  603.             print_page_string[(71 - strlen(page_num_string)) / 2] = 0x00;
  604.             strcat(print_page_string,page_num_string);
  605.             strcat(print_page_string," \r\n");
  606.             while(y < 60)
  607.             {
  608.                 if((error = print_string_func(print_line)) != 0)
  609.                 {
  610.                     break;
  611.                 }
  612.                 y++;
  613.             }
  614.             if(error == 0)
  615.             {
  616.                 error = print_string_func(print_page_string);
  617.             }
  618.         }
  619.     }
  620.     if(error > 0)
  621.     {
  622.         clear_window(0);
  623.         write_window(3,2,"Printer Error !");
  624.         bioskey(0);
  625.     }
  626.     unpopup_window(6);
  627.     return(0);
  628.  
  629. }
  630.  
  631. int quit(void)
  632. {
  633.     char choice[2];
  634.  
  635.     popup_window(QUIT_WIN,32,10,47,12,2,2,15,4,1,8,0,0,0);
  636.     write_window(3,2,"Quit Y/N ?");
  637.     strcpy(choice,"Y");
  638.     show_cursor();
  639.     if(get_string(choice," ","Y",14,2,1,1) == 0)
  640.     {
  641.         strupr(choice);
  642.         if(strcmp(choice,"Y") == 0)
  643.         {
  644.             unpopup_window(QUIT_WIN);
  645.             hide_cursor();
  646.             return(0);
  647.         }
  648.     }
  649.     unpopup_window(QUIT_WIN);
  650.     hide_cursor();
  651.     return(1);
  652. }
  653.  
  654. int print_char(unsigned char prn_char)
  655. {
  656.     int prn_stat;
  657.     unsigned long int i;
  658.  
  659.     dev_error = 0;
  660.     i = 0;
  661.     while(((prn_stat = biosprint(2,0,0)) &0x80) != 0x80)
  662.     {
  663.         if(i == 10000000L)
  664.         {
  665.             dev_error = 3;
  666.         }
  667.         if(((prn_stat & 0x01) == 0x01) | ((prn_stat & 0x08) == 0x08) |
  668.             ((prn_stat & 0x20) == 0x20))
  669.         {
  670.             return(prn_stat);
  671.         }
  672.         if(dev_error != 0)
  673.         {
  674.             return(dev_error);
  675.         }
  676.         i = i + 1;
  677.     }
  678.     i = 0;
  679.     while(((prn_stat = biosprint(0,prn_char,0)) & 0x10) != 0x10)
  680.     {
  681.         if(i == 10000000L)
  682.         {
  683.             dev_error = 3;
  684.         }
  685.         if(((prn_stat & 0x01) == 0x01) | ((prn_stat & 0x08) == 0x08) |
  686.             ((prn_stat & 0x20) == 0x20))
  687.         {
  688.             return(prn_stat);
  689.         }
  690.         if(dev_error != 0)
  691.         {
  692.             return(dev_error);
  693.         }
  694.         i = i + 1;
  695.     }
  696.     return(0);
  697. }
  698.  
  699. int read_directory(char *buff,int num_file,char *directory)
  700. {
  701.     int i;
  702.     char far *data;
  703.     struct ffblk dir_data;
  704.  
  705.  
  706.     data = getdta();
  707.     dev_error = 0;
  708.     if(findfirst(directory,&dir_data,FA_RDONLY) != 0)
  709.     {
  710.         return(1);
  711.     }
  712.     strcpy(buff,dir_data.ff_name);
  713.     buff = buff + 13;
  714.     for(i = 1;i < num_file;i++)
  715.     {
  716.         if(findnext(&dir_data) != 0)
  717.         {
  718.             break;
  719.         }
  720.         strcpy(buff,dir_data.ff_name);
  721.         buff = buff + 13;
  722.     }
  723.     setdta(data);
  724.     return(0);
  725. }
  726.  
  727. int print_string_func(unsigned char *print_string)
  728. {
  729.     int i;
  730.     int error;
  731.  
  732.     for(i = 0;i < strlen(print_string);i++)
  733.     {
  734.         if((error = print_char(print_string[i])) != 0)
  735.         {
  736.             break;
  737.         }
  738.     }
  739.     return(error);
  740. }