home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / UTILITY / TYPEW.ZIP / TYPEW.C < prev    next >
Text File  |  1994-04-22  |  4KB  |  194 lines

  1. /*
  2.  * This program is a MS-DOS TYPE command replacement (sorta) to display
  3.  * text files with embeded WWIV Heart Codes with the appropriate colors.
  4.  *
  5.  * Version 0 -=- Charles R. Grosvenor Jr. -=- February 12, 1994
  6.  */
  7.  
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <stdarg.h>
  11. #include <conio.h>
  12. #include <string.h>
  13. #include <io.h>
  14. #include <fcntl.h>
  15.  
  16. char *format( char *fmt, ... );        /* format multiple parameters into     */
  17.                        /* a single string                     */
  18. void myputs(char *string, int count);
  19. int pausekey(void);
  20. int check_exist(char *s);
  21. int print_file(char *print_filename);
  22.  
  23. char *format( char *fmt, ... )
  24. /*
  25.  * Purpose : Format a list of parameters into a single string
  26.  *
  27.  * Revision: Level 0 -=- Dan Walters
  28.  */
  29. {
  30.   va_list v;
  31.   static char s[512];
  32.  
  33.   va_start( v, fmt );
  34.   vsprintf( s, fmt, v );
  35.   va_end( v );
  36.   return( s );
  37. }
  38.  
  39. int check_exist(char *s)
  40. {
  41.   int f;
  42.  
  43.   f=open(s,O_RDONLY | O_BINARY);
  44.   if (f>0)
  45.   {
  46.     close(f);
  47.     return(1);
  48.   }
  49.   else
  50.     return(0);
  51. }
  52.  
  53.  
  54.  
  55. int pausekey(void)
  56. /* Name       : pausekey
  57. /* Dependicies: none
  58. /* Purpose    : IF a SPACE is hit, returns a 1, otherwise a 0 is returned
  59. /* Revision   : October 17, 1993 -=- Charles R. Grosvenor Jr. -=- Level 0
  60.  
  61.  */
  62.  
  63. {
  64.   int return_value=0;
  65.  
  66.   myputs("0[1PAUSE0, 2SPACE TO ABORT0, 1any other key continues0]",0);
  67.   if (getch()==' ')
  68.   {
  69.     return_value=1;
  70.   }
  71.   cprintf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
  72.   myputs("                                                ",0);
  73.   cprintf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
  74.   return(return_value);
  75. }
  76.  
  77. void myputs(char *string, int count)
  78.  
  79. /* display a string with embedded color codes */
  80.  
  81. {
  82.   int loop=0, actual_loop=0;
  83.  
  84.   while ( (string[loop]!='\0') && ( (actual_loop<=count) || (count<=0) ) )
  85.   { if (string[loop]=='')
  86.     {
  87.       loop++;
  88.       switch(string[loop])
  89.       {
  90.     case '0' : textattr(WHITE + (BLACK<<4)); break;
  91.     case '1' : textattr(LIGHTCYAN + (BLACK<<4)); break;
  92.     case '2' : textattr(YELLOW + (BLACK<<4)); break;
  93.     case '3' : textattr(LIGHTMAGENTA + (BLACK<<4)); break;
  94.     case '4' : textattr(WHITE +  (BLUE<<4)); break;
  95.     case '5' : textattr(GREEN + (BLACK<<4)); break;
  96.     case '6' : textattr(RED + (BLACK<<4) + BLINK); break;
  97.     case '7' : textattr(BLUE + (BLACK<<4)); break;
  98.     default  : textattr(WHITE + (BLACK<<4)); break;
  99.       }
  100.       loop++;
  101.     }
  102.     else if (string[loop]=='\t')
  103.     {
  104.       cprintf("     ");
  105.       loop++;
  106.       actual_loop+=5;
  107.     }
  108.     else {
  109.       cprintf("%c",string[loop]);
  110.       loop++;
  111.       actual_loop++;
  112.     }
  113.   }
  114. }
  115.  
  116. int print_file(char *print_filename)
  117. /* Name       : print_file
  118. /* Dependicies: myputs, pauskey
  119. /* Purpose    : Display a heart code embeded text file, pausing every 22
  120.  *              lines or so.
  121. /* Revision   : October 17, 1993 -=- Charles R. Grosvenor Jr. -=- Level 0
  122.  
  123.  */
  124.  
  125. {
  126.   FILE *print_file;
  127.   char print_line[241];
  128.   int line_count=0, stop_file=0;
  129.  
  130.   if (check_exist(print_filename))
  131.   {
  132.     if ((print_file=fopen(print_filename, "r")) == NULL)
  133.     {
  134.       myputs("6Unable to open output file for display0\r\n\r\n",0);
  135.     }
  136.     else
  137.     {
  138.       line_count=0;
  139.       while ( (!feof(print_file)) && (!stop_file) )
  140.       {
  141.     fgets(print_line,240,print_file);
  142.     if (print_line[strlen(print_line)-1]=='\n')
  143.     {
  144.       strcat(print_line, "\r");
  145.     }
  146.     myputs(print_line,0);
  147.     line_count++;
  148.     if (line_count>22)
  149.     {
  150.       if (pausekey())
  151.       {
  152.         stop_file=1;
  153.       }
  154.       else
  155.       {
  156.         line_count=0;
  157.       }
  158.     }
  159.       }
  160.       fclose(print_file);
  161.     }
  162.     return(0);
  163.   }
  164.   else
  165.   {
  166.     return(1);
  167.   }
  168. }
  169.  
  170. void main(int argc, char **argv)
  171. {
  172.   while (argc)
  173.   {
  174.     if (argv[argc])
  175.     {
  176.       myputs(format("\r\n1Displaying File0:2 %s0\n\r\n\r",argv[argc]),0);
  177.       if (check_exist(argv[argc]))
  178.       {
  179.     print_file(argv[argc--]);
  180.       }
  181.       else
  182.       {
  183.     myputs("6That file was not able to be displayed0\n\r",0);
  184.     argc--;
  185.       }
  186.     }
  187.     else
  188.     {
  189.       argc--;
  190.     }
  191.   }
  192.   myputs("\r\n1All specified files displayed0\r\n",0);
  193. }
  194.