home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / pgmutl / val_link.arc / LKSLIDES.ARC / SLCOMP.C < prev    next >
Text File  |  1989-02-18  |  6KB  |  163 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <mem.h>
  4. #include <conio.h>
  5. #include <string.h>
  6. #include "langext.h"
  7. /*+-------------------------------------------------------------------------+
  8.   |                                                                         |
  9.   |                                Constants                                |
  10.   |                                                                         |
  11.   +-------------------------------------------------------------------------+*/
  12. #define COLUMNS_PER_ROW                80
  13. #define COLUMNS_PER_TITLE              60
  14. #define MAX_LINE_SIZE                  1024
  15. #define ROWS_PER_PAGE                  24
  16. /*+-------------------------------------------------------------------------+
  17.   |                                                                         |
  18.   |                                 Types                                   |
  19.   |                                                                         |
  20.   +-------------------------------------------------------------------------+*/
  21. Type char                              line_type[COLUMNS_PER_ROW];
  22. Type line_type                         page_type[ROWS_PER_PAGE];
  23. Structure slide_struct
  24.  BeginStructure
  25.   char                                 title[COLUMNS_PER_TITLE];
  26.   page_type                            screen;
  27.  EndStructure;
  28. Type Structure slide_struct            slide_type;
  29. /*+-------------------------------------------------------------------------+
  30.   |                                                                         |
  31.   |                               Prototypes                                |
  32.   |                                                                         |
  33.   +-------------------------------------------------------------------------+*/
  34. char
  35.       *next_line                       (void);
  36. void
  37.        main                            (bit_16 argc, char *argv[]);
  38. /*+-------------------------------------------------------------------------+
  39.   |                                                                         |
  40.   |                            Global Variables                             |
  41.   |                                                                         |
  42.   +-------------------------------------------------------------------------+*/
  43. char                                   line[MAX_LINE_SIZE];
  44. bit_16                                 line_count;
  45. bit_16                                 line_length;
  46. slide_type                             slide;
  47. bit_16                                 slide_count;
  48. FILE                                  *slide_input_file;
  49. FILE                                  *slide_output_file;
  50. /*+-------------------------------------------------------------------------+
  51.   |                                                                         |
  52.   |                                main                                     |
  53.   |                                                                         |
  54.   +-------------------------------------------------------------------------+*/
  55. void main(bit_16 argc, char *argv[])
  56. BeginDeclarations
  57. char                                  *text;
  58. EndDeclarations
  59. BeginCode
  60.  clrscr();
  61.  If argc IsNot 3
  62.   Then
  63.    printf("Usage:\n");
  64.    printf("\n");
  65.    printf("  SLCOMP infile outfile\n");
  66.    printf("\n");
  67.    printf("    Where \"infile\" is the slide input created by an editor\n");
  68.    printf("    and \"outfile\" is the compiled output filename suitable\n");
  69.    printf("    for viewing by the SLSHOW program.\n");
  70.    exit(1);
  71.   EndIf;
  72.  slide_input_file = fopen(argv[1], "rt");
  73.  If slide_input_file IsNull
  74.   Then
  75.    printf("Could not open file \"%s\" for input.\n", argv[1]);
  76.    printf("\n");
  77.    exit(4);
  78.   EndIf;
  79.  slide_output_file = fopen(argv[2], "wb");
  80.  If slide_output_file IsNull
  81.   Then
  82.    printf("Could not open file \"%s\" for output.\n", argv[2]);
  83.    printf("\n");
  84.    exit(4);
  85.   EndIf;
  86.  text = next_line();
  87.  If (text IsNull) OrIf (text[0] IsNot '\f')
  88.   Then
  89.    clrscr();
  90.    printf("Error:  Slide set does not start with a title.\n");
  91.    printf("\n");
  92.    exit(4);
  93.   EndIf;
  94.  While text[0] Is '\f'
  95.   BeginWhile
  96.    slide_count++;
  97.    setmem(Addr(slide), sizeof(slide_type), ' ');
  98.    text = Addr(line[1]);
  99.    line_length--;
  100.    If line_length Exceeds COLUMNS_PER_TITLE
  101.     Then
  102.      line_length = COLUMNS_PER_TITLE;
  103.     EndIf;
  104.    text[line_length] = '\000';
  105.    memmove(slide.title, text, line_length);
  106.    printf("Slide:  %u,  Title:  \"%s\"\n", slide_count, text);
  107.    line_count = 0;
  108.    text = next_line();
  109.    While (text IsNotNull) AndIf (text[0] IsNot '\f')
  110.     BeginWhile
  111.      line_count++;
  112.      If line_count Is ROWS_PER_PAGE+1
  113.       Then
  114.        printf("  Warning:  Slide exceeds %u lines.\n", ROWS_PER_PAGE);
  115.       EndIf;
  116.      If line_count NotGreaterThan ROWS_PER_PAGE
  117.       Then
  118.        If line_length Exceeds COLUMNS_PER_ROW
  119.         Then
  120.          printf("  Warning:  Line %u exceeds %u characters.\n",
  121.                 line_count, COLUMNS_PER_ROW);
  122.          line_length = COLUMNS_PER_ROW;
  123.         EndIf;
  124.        memmove(slide.screen[line_count-1], text, line_length);
  125.       EndIf;
  126.      text = next_line();
  127.     EndWhile;
  128.    fwrite(Addr(slide), sizeof(slide_type), 1, slide_output_file);
  129.   EndWhile;
  130.  printf("\n");
  131.  fclose(slide_input_file);
  132.  fclose(slide_output_file);
  133.  exit(0);
  134. EndCode
  135. /*+-------------------------------------------------------------------------+
  136.   |                                                                         |
  137.   |                               next_line                                 |
  138.   |                                                                         |
  139.   +-------------------------------------------------------------------------+*/
  140. char *next_line()
  141. BeginDeclarations
  142. char                                  *text;
  143. EndDeclarations
  144. BeginCode
  145.  text = fgets(line, MAX_LINE_SIZE, slide_input_file);
  146.  If text IsNull
  147.   Then
  148.    line_length = 0;
  149.    return(text);
  150.   EndIf;
  151.  line_length = Bit_16(strlen(line));
  152.  If line[--line_length] IsNot '\n'
  153.   Then
  154.    printf("Error:  A line exceeds %u characters.\n", MAX_LINE_SIZE);
  155.    exit(4);
  156.   EndIf;
  157.  line[line_length] = '\000';
  158.  return(text);
  159. EndCode
  160.  
  161.  
  162.  
  163.