home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / DSP.ARJ / DSP.C next >
Text File  |  1995-02-22  |  5KB  |  183 lines

  1.  
  2. #include "stdio.h"
  3. #include "stdlib.h"
  4. #include "conio.h"
  5.  int e_line,start_page,tln;
  6.  char filename[22],line[600],lnn;
  7.  
  8. void error(int code);
  9. void set_screen();
  10. void continue_print();
  11. void single_print();
  12.  
  13.  main()
  14.  {     FILE *fs,*ft;
  15.   int ln,s_c=1;
  16.     char es_line[3],s_page[4],s_c1[2];
  17.     set_screen();
  18.        window(1,8,79,20);
  19.        textbackground(BLUE);
  20.        textcolor(CYAN);
  21.        clrscr();
  22.     while(1)
  23.      { gotoxy(20,2);cprintf("Enter Source File:");
  24.       gets(filename);
  25.        if((fs=fopen(filename,"rt"))!=NULL)
  26.          break;
  27.        error(1);
  28.       }
  29.    if((ft=fopen("c:print.doc","wt"))==NULL)
  30.       {error(2);
  31.       exit(1);  }
  32.    ln=1;
  33.    while(fgets(line,512,fs)!=NULL)
  34.      {if(fprintf(ft,"%-6d%s",ln++,line)==EOF)
  35.         {error(3);
  36.          fclose(fs);
  37.      exit(1);
  38.         }
  39.       gotoxy(35,4);cprintf("Total lines: %d",ln-1);
  40.       tln=ln-1;
  41.      }
  42.     fclose(fs);fclose(ft);
  43.     gotoxy(20,6);cprintf("Every page lines (default 55):");
  44.     gets(es_line);
  45.     e_line=atoi(es_line);
  46.     if(e_line==0) e_line=55;
  47.     gotoxy(20,7);cprintf("Start page number (default 1):");
  48.     gets(s_page);
  49.     start_page=atoi(s_page);
  50.     if(start_page==0) start_page=1;
  51.     gotoxy(20,8);cprintf("Print line number (y/n) (default yes):");
  52.     ln=getchar();
  53.     if(ln=='')
  54.     ln='y';
  55.     gotoxy(15,9);cprintf("Please print mode (1:continue paper 2:single paper):");
  56.     gets(s_c1);
  57.     s_c=atoi(s_c1);
  58.     if(s_c==0) s_c=1;
  59.     fprintf(stdprn,"%c%c",0x1b,0x40);
  60.     fprintf(stdprn,"%c%c%c",0x1b,0x43,66);
  61.      if(s_c==1)
  62.       continue_print() ;
  63.      else
  64.        single_print();
  65.  
  66.     system("del print.doc");
  67.     }
  68.  
  69.   void set_screen()
  70.   {
  71.       textbackground(BLUE);
  72.        clrscr();
  73.        window(10,2,70,6);
  74.        textbackground(LIGHTGREEN);
  75.        textcolor(YELLOW);
  76.        clrscr();
  77.        gotoxy(23,2);     cprintf("Double Side Print");
  78.        gotoxy(18,3);cprintf("===========================");
  79.        gotoxy(5,4);cprintf("Computer Centre of Main Sub-branches at SONG YUAN City");
  80.        window(5,22,75,24);
  81.        textbackground(RED);
  82.        textcolor(YELLOW);
  83.        clrscr();
  84.  }
  85.    void error(int code)
  86.    {
  87.        window(5,22,75,24);
  88.        textbackground(RED);
  89.        textcolor(YELLOW);
  90.        clrscr();
  91.        gotoxy(20,2);
  92.        switch(code)
  93.         {case 1:cprintf("Cannot open source file");
  94.                 break;
  95.          case 2:cprintf("Cannot create file");
  96.                 break;
  97.          case 3:cprintf("Cannot write to print file");
  98.                 break;
  99.         }
  100.        window(1,8,79,20);
  101.        textbackground(BLUE);
  102.        textcolor(CYAN);
  103.  
  104.    }
  105.  
  106.   void continue_print()
  107.     {  FILE *ft;
  108.       int i,j,k,page,ln;
  109.      if(lnn=='y'||lnn=='Y')
  110.        ft=fopen("print.doc","rt");
  111.      else
  112.        ft=fopen(filename,"rt");
  113.      page=0;ln=0;
  114.       for(i=1;i<=2;i++)
  115.         {rewind(ft);
  116.          ln=0;
  117.          while(!feof(ft))
  118.            {if((ln/e_line)==page)
  119.         {fprintf(stdprn,"                          │╠╨≥├√: %s             │╠╨≥╫▄╨╨╩²: %d \n",filename,tln);
  120.          fprintf(stdprn,"⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ\n");
  121.              for(j=0;j<e_line;j++)
  122.                {if(fgets(line,512,ft)==NULL)
  123.                   {for(k=j;k<e_line;k++)
  124.                      fprintf(stdprn,"%c%c",0x0d,0x0a);
  125.                   break;
  126.                   }
  127.                 fprintf(stdprn,"%s",line);
  128.                 ln++;
  129.                }
  130.          fprintf(stdprn,"\n==========================================╡┌ %d ╥│====================================\n",page+start_page);
  131.              fprintf(stdprn,"                                                                 ╦╔╘¡╜¿╔Φ╥°╨╨╡τ╦π┐╞\n");
  132.              page+=2;
  133.              fprintf(stdprn,"%c",0x0c);
  134.             }
  135.             else
  136.              { for(j=0;j<e_line;j++)
  137.                   {if(fgets(line,512,ft)==NULL)
  138.                      break;
  139.                    ln++;
  140.                   }
  141.              }
  142.       } /*end while */
  143.      if(ln<e_line) break;
  144.     page=1;
  145.     if (i==1)
  146.    { gotoxy(12,12);cprintf("Please turn over the paper ,then press any key to continue");
  147.     getch();}
  148.    }   /*end for*/
  149.    fclose(ft);
  150.    }
  151.  
  152.  
  153.  
  154.    void single_print()
  155.  
  156.     {  FILE *ft;
  157.        int page,j,k;
  158.        if(lnn=='y'||lnn=='Y')
  159.       ft=fopen("print.doc","rt");
  160.        else
  161.       ft=fopen(filename,"rt");
  162.          page=0;
  163.          while(!eof(ft))
  164.       {fprintf(stdprn,"                          │╠╨≥├√: %s              │╠╨≥╫▄╨╨╩²: %d \n",filename,tln);
  165.        fprintf(stdprn,"⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ⌐Ñ\n");
  166.              for(j=0;j<e_line;j++)
  167.                {if(fgets(line,512,ft)==NULL)
  168.                   {for(k=j;k<e_line;k++)
  169.                      fprintf(stdprn,"%c%c",0x0d,0x0a);
  170.                   break;
  171.                   }
  172.                 fprintf(stdprn,"%s",line);
  173.                }
  174.                 page++;
  175.          fprintf(stdprn,"==========================================╡┌ %d ╥│====================================================",page+start_page);
  176.          fprintf(stdprn,"                                                       ╦╔╘¡╜¿╔Φ╥°╨╨╡τ╦π┐╞");
  177.          gotoxy(12,12);cprintf("Please turn over the paper ,then press any key to continue");
  178.             getch();
  179.        }
  180.        fclose(ft);
  181.     }
  182.  
  183.